Change the way nested structs are translated

Summary:
public
Reuse logic in cFrontend.ml to deal with nested structs. This allows to have less duplicated logic which will result
in less bugs.
As a bonus, it fixes the problem of nested template class (which wasn't be handled right).
And one random fix in c_type -> sil_type conversion (I'm amazed it worked before)

Reviewed By: dulmarod

Differential Revision: D2773687

fb-gh-sync-id: e312599
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-5
parent e27959f655
commit 0ae9b0e7a1

@ -96,14 +96,17 @@ let rec translate_one_declaration tenv cg cfg parent_dec dec =
| dec -> ());
match dec with
(* Currently C/C++ record decl treated in the same way *)
| ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _)
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _)
| RecordDecl (_, _, _, _, decl_list, _, _) ->
| ClassTemplateSpecializationDecl (decl_info, _, _, _, decl_list, _, _, _)
| CXXRecordDecl (decl_info, _, _, _, decl_list, _, _, _)
| RecordDecl (decl_info, _, _, _, decl_list, _, _) when not decl_info.di_is_implicit ->
let is_method_decl decl = match decl with
| CXXMethodDecl _ | CXXConstructorDecl _ | CXXDestructorDecl _ | FunctionTemplateDecl _ ->
true
| _ -> false in
let method_decls, no_method_decls = IList.partition is_method_decl decl_list in
IList.iter (translate_one_declaration tenv cg cfg dec) no_method_decls;
ignore (CTypes_decl.add_types_from_decl_to_tenv tenv dec);
let method_decls = CTypes_decl.get_method_decls dec decl_list in
let tranlate_method (parent, decl) =
translate_one_declaration tenv cg cfg parent decl in
IList.iter tranlate_method method_decls
IList.iter (translate_one_declaration tenv cg cfg dec) method_decls
| EnumDecl _ -> ignore (CEnum_decl.enum_decl dec)
| LinkageSpecDecl (decl_info, decl_list, decl_context_info) ->
Printing.log_out "ADDING: LinkageSpecDecl decl list\n";

@ -132,6 +132,7 @@ and decl_ptr_to_sil_type translate_decl tenv decl_ptr =
match Ast_utils.get_decl decl_ptr with
| Some (CXXRecordDecl _ as d)
| Some (RecordDecl _ as d)
| Some (ClassTemplateSpecializationDecl _ as d)
| Some (ObjCInterfaceDecl _ as d)
| Some (ObjCImplementationDecl _ as d)
| Some (ObjCProtocolDecl _ as d)

@ -99,20 +99,6 @@ let get_record_name_csu decl =
let get_record_name decl = snd (get_record_name_csu decl)
let get_method_decls parent decl_list =
let open Clang_ast_t in
let rec traverse_decl parent decl = match decl with
| CXXMethodDecl _ | CXXConstructorDecl _ | CXXDestructorDecl _ -> [(parent, decl)]
| FunctionTemplateDecl (_, _, template_decl_info) ->
let decl_list' = template_decl_info.Clang_ast_t.tdi_specializations in
traverse_decl_list parent decl_list'
| ClassTemplateSpecializationDecl (_, _, _, _, decl_list', _, _, _)
| CXXRecordDecl (_, _, _, _, decl_list', _, _, _)
| RecordDecl (_, _, _, _, decl_list', _, _) -> traverse_decl_list decl decl_list'
| _ -> []
and traverse_decl_list parent decl_list = IList.flatten (IList.map (traverse_decl parent) decl_list) in
traverse_decl_list parent decl_list
let get_class_methods tenv class_name decl_list =
let process_method_decl = function
| Clang_ast_t.CXXMethodDecl (decl_info, name_info, tp, function_decl_info, _)
@ -167,12 +153,6 @@ let rec get_struct_fields tenv decl =
let typ = type_ptr_to_sil_type tenv type_ptr in
let annotation_items = [] in (* For the moment we don't use them*)
[(id, typ, annotation_items)]
| ClassTemplateSpecializationDecl (decl_info, _, _, _, _, _, _, _)
| CXXRecordDecl (decl_info, _, _, _, _, _, _, _)
| RecordDecl (decl_info, _, _, _, _, _, _) ->
(* C++/C Records treated in the same way*)
if not decl_info.Clang_ast_t.di_is_implicit then
ignore (add_types_from_decl_to_tenv tenv decl); []
| _ -> [] in
let base_decls = get_superclass_decls decl in
let base_class_fields = IList.map (get_struct_fields tenv) base_decls in

@ -13,8 +13,6 @@ val add_struct_to_tenv : Sil.tenv -> Sil.typ -> unit
val get_record_name : Clang_ast_t.decl -> string
val get_method_decls : Clang_ast_t.decl -> Clang_ast_t.decl list -> (Clang_ast_t.decl * Clang_ast_t.decl) list
val add_types_from_decl_to_tenv : Sil.tenv -> Clang_ast_t.decl -> Sil.typ
(* Adds the predefined types objc_class which is a struct, *)

Loading…
Cancel
Save