Update facebook-clang-plugin

Summary:
This makes infer C frontend compatible
with new scheme for naming which has:
1. plain name (like 'fun')
2. qualified name (reversed list like ['fun', 'class', 'top_class', 'namespace'])
master
Andrzej Kotulski 10 years ago
parent 9c4a4a16f3
commit 927653e8d8

@ -1 +1 @@
24e2b11a8802be69444a702b683c1be380570bae 8a70ebe9439ec6495330ebe9a90c45e8e8b6b3b7

@ -159,9 +159,14 @@ let make_obj_c_message_expr_info_class selector qt =
omei_receiver_kind = `Class (create_qual_type qt); omei_receiver_kind = `Class (create_qual_type qt);
} }
let make_name_decl name = {
Clang_ast_t.ni_name = name;
Clang_ast_t.ni_qual_name = [name];
}
let make_general_decl_ref k name is_hidden qt = { let make_general_decl_ref k name is_hidden qt = {
Clang_ast_t.dr_kind = k; Clang_ast_t.dr_kind = k;
Clang_ast_t.dr_name = Some name; Clang_ast_t.dr_name = Some (make_name_decl name);
Clang_ast_t.dr_is_hidden = is_hidden ; Clang_ast_t.dr_is_hidden = is_hidden ;
Clang_ast_t.dr_qual_type = Some (qt) Clang_ast_t.dr_qual_type = Some (qt)
} }
@ -171,7 +176,7 @@ let make_decl_ref name =
let make_decl_ref_self qt = { let make_decl_ref_self qt = {
Clang_ast_t.dr_kind = `ImplicitParam; Clang_ast_t.dr_kind = `ImplicitParam;
Clang_ast_t.dr_name = Some "self"; Clang_ast_t.dr_name = Some (make_name_decl "self");
Clang_ast_t.dr_is_hidden = false ; Clang_ast_t.dr_is_hidden = false ;
Clang_ast_t.dr_qual_type = Some qt Clang_ast_t.dr_qual_type = Some qt
} }
@ -240,7 +245,7 @@ let make_objc_ivar_decl decl_info qt property_impl_decl_info =
let obj_c_ivar_decl_info = { let obj_c_ivar_decl_info = {
Clang_ast_t.ovdi_is_synthesize = true; (* NOTE: We set true here because we use this definition to synthesize the getter/setter*) Clang_ast_t.ovdi_is_synthesize = true; (* NOTE: We set true here because we use this definition to synthesize the getter/setter*)
Clang_ast_t.ovdi_access_control = `Private } in Clang_ast_t.ovdi_access_control = `Private } in
ObjCIvarDecl(decl_info, name, qt, field_decl_info, obj_c_ivar_decl_info) ObjCIvarDecl(decl_info, make_name_decl name, qt, field_decl_info, obj_c_ivar_decl_info)
let make_expr_info qt = let make_expr_info qt =
{ {
@ -278,7 +283,7 @@ let make_next_object_exp stmt_info item items =
let var_decl_ref, var_type = let var_decl_ref, var_type =
match item with match item with
| DeclStmt (stmt_info, _, [VarDecl(di, var_name, var_type, _)]) -> | DeclStmt (stmt_info, _, [VarDecl(di, var_name, var_type, _)]) ->
let decl_ref = make_general_decl_ref `Var var_name false var_type in let decl_ref = make_general_decl_ref `Var var_name.Clang_ast_t.ni_name false var_type in
let stmt_info_var = { let stmt_info_var = {
si_pointer = di.Clang_ast_t.di_pointer; si_pointer = di.Clang_ast_t.di_pointer;
si_source_range = di.Clang_ast_t.di_source_range si_source_range = di.Clang_ast_t.di_source_range
@ -305,6 +310,7 @@ let translate_dispatch_function block_name stmt_info stmt_list ei n =
let block_expr = let block_expr =
try Utils.list_nth stmt_list (n + 1) try Utils.list_nth stmt_list (n + 1)
with Not_found -> assert false in with Not_found -> assert false in
let block_name_info = make_name_decl block_name in
match block_expr with BlockExpr(bsi, bsl, bei, bd) -> match block_expr with BlockExpr(bsi, bsl, bei, bd) ->
let qt = bei.Clang_ast_t.ei_qual_type in let qt = bei.Clang_ast_t.ei_qual_type in
let cast_info = { cei_cast_kind = `BitCast; cei_base_path =[]} in let cast_info = { cei_cast_kind = `BitCast; cei_base_path =[]} in
@ -312,7 +318,7 @@ let translate_dispatch_function block_name stmt_info stmt_list ei n =
let decl_info = { empty_decl_info let decl_info = { empty_decl_info
with di_pointer = stmt_info.si_pointer; di_source_range = stmt_info.si_source_range } in with di_pointer = stmt_info.si_pointer; di_source_range = stmt_info.si_source_range } in
let var_decl_info = { empty_var_decl with vdi_init_expr = Some block_def } in let var_decl_info = { empty_var_decl with vdi_init_expr = Some block_def } in
let block_var_decl = VarDecl(decl_info, block_name, ei.ei_qual_type, var_decl_info) in let block_var_decl = VarDecl(decl_info, block_name_info, ei.ei_qual_type, var_decl_info) in
let decl_stmt = DeclStmt(stmt_info,[], [block_var_decl]) in let decl_stmt = DeclStmt(stmt_info,[], [block_var_decl]) in
let expr_info_call = { let expr_info_call = {
Clang_ast_t.ei_qual_type = create_void_type (); Clang_ast_t.ei_qual_type = create_void_type ();
@ -326,7 +332,7 @@ let translate_dispatch_function block_name stmt_info stmt_list ei n =
} in } in
let decl_ref = { let decl_ref = {
dr_kind = `Var; dr_kind = `Var;
dr_name = Some block_name; dr_name = Some block_name_info;
dr_is_hidden = false; dr_is_hidden = false;
dr_qual_type = Some qt; dr_qual_type = Some qt;
} in } in

@ -99,7 +99,7 @@ let pp_ast_decl fmt ast_decl =
| FunctionDecl (decl_info, name, qt, fdecl_info) -> | FunctionDecl (decl_info, name, qt, fdecl_info) ->
F.fprintf fmt "%sFunctionDecl %s %a@\n" F.fprintf fmt "%sFunctionDecl %s %a@\n"
prefix prefix
name name.Clang_ast_t.ni_name
pp_source_range decl_info.di_source_range; pp_source_range decl_info.di_source_range;
list_iter (dump_decl prefix1) fdecl_info.fdi_decls_in_prototype_scope; list_iter (dump_decl prefix1) fdecl_info.fdi_decls_in_prototype_scope;
list_iter (dump_decl prefix1) fdecl_info.fdi_parameters; list_iter (dump_decl prefix1) fdecl_info.fdi_parameters;
@ -107,10 +107,10 @@ let pp_ast_decl fmt ast_decl =
| ObjCMethodDecl (decl_info, name, obj_c_method_decl_info) -> | ObjCMethodDecl (decl_info, name, obj_c_method_decl_info) ->
F.fprintf fmt "%sObjCMethodDecl %s %a@\n" F.fprintf fmt "%sObjCMethodDecl %s %a@\n"
prefix prefix
name name.Clang_ast_t.ni_name
pp_source_range decl_info.di_source_range; pp_source_range decl_info.di_source_range;
Option.may (dump_stmt prefix1) obj_c_method_decl_info.omdi_body Option.may (dump_stmt prefix1) obj_c_method_decl_info.omdi_body
| VarDecl (decl_info, string, qual_type, var_decl_info) -> | VarDecl (decl_info, name, qual_type, var_decl_info) ->
F.fprintf fmt "%sVarDecl %a@\n" F.fprintf fmt "%sVarDecl %a@\n"
prefix prefix
pp_source_range decl_info.di_source_range; pp_source_range decl_info.di_source_range;

@ -44,7 +44,8 @@ let global_procdesc = ref (create_empty_procdesc ())
let rec get_enum_constants context decl_list v = let rec get_enum_constants context decl_list v =
match decl_list with match decl_list with
| [] -> [] | [] -> []
| EnumConstantDecl(decl_info, name, qual_type, enum_constant_decl_info) :: decl_list' -> | EnumConstantDecl(decl_info, name_info, qual_type, enum_constant_decl_info) :: decl_list' ->
let name = name_info.Clang_ast_t.ni_name in
(match enum_constant_decl_info.Clang_ast_t.ecdi_init_expr with (match enum_constant_decl_info.Clang_ast_t.ecdi_init_expr with
| None -> Printing.log_out "%s" (" ...Defining Enum Constant ("^name^", "^(string_of_int v)); | None -> Printing.log_out "%s" (" ...Defining Enum Constant ("^name^", "^(string_of_int v));
(Mangled.from_string name, Sil.Cint (Sil.Int.of_int v)) (Mangled.from_string name, Sil.Cint (Sil.Int.of_int v))

@ -29,7 +29,7 @@ let fields_superclass tenv interface_decl_info =
match interface_decl_info.Clang_ast_t.otdi_super with match interface_decl_info.Clang_ast_t.otdi_super with
| Some dr -> | Some dr ->
(match dr.Clang_ast_t.dr_name with (match dr.Clang_ast_t.dr_name with
| Some sc -> get_fields_super_classes tenv (CTypes.mk_classname sc) | Some sc -> get_fields_super_classes tenv (CTypes.mk_classname sc.Clang_ast_t.ni_name)
| _ -> []) | _ -> [])
| _ -> [] | _ -> []
@ -80,8 +80,9 @@ let rec get_fields tenv curr_class decl_list =
let class_name = CContext.get_curr_class_name curr_class in let class_name = CContext.get_curr_class_name curr_class in
match decl_list with match decl_list with
| [] -> [] | [] -> []
| ObjCIvarDecl(decl_info, field_name, qual_type, field_decl_info, obj_c_ivar_decl_info) :: decl_list' -> | ObjCIvarDecl(decl_info, name_info, qual_type, field_decl_info, obj_c_ivar_decl_info) :: decl_list' ->
let fields = get_fields tenv curr_class decl_list' in let fields = get_fields tenv curr_class decl_list' in
let field_name = name_info.Clang_ast_t.ni_name in
(* Doing a post visit here. Adding Ivar after all the declaration have been visited so that *) (* Doing a post visit here. Adding Ivar after all the declaration have been visited so that *)
(* ivar names will be added in the property list. *) (* ivar names will be added in the property list. *)
Printing.log_out " ...Adding Instance Variable '%s' @." field_name; Printing.log_out " ...Adding Instance Variable '%s' @." field_name;

@ -24,53 +24,63 @@ let rec translate_one_declaration tenv cg cfg namespace dec =
let source_range = info.Clang_ast_t.di_source_range in let source_range = info.Clang_ast_t.di_source_range in
let should_translate_enum = CLocation.should_translate_enum source_range in let should_translate_enum = CLocation.should_translate_enum source_range in
match dec with match dec with
| FunctionDecl(di, name, qt, fdecl_info) -> | FunctionDecl(di, name_info, qt, fdecl_info) ->
let name = name_info.Clang_ast_t.ni_name in
CMethod_declImpl.function_decl tenv cfg cg namespace false di name qt fdecl_info [] None CContext.ContextNoCls CMethod_declImpl.function_decl tenv cfg cg namespace false di name qt fdecl_info [] None CContext.ContextNoCls
| TypedefDecl (decl_info, name, opt_type, typedef_decl_info) -> | TypedefDecl (decl_info, name_info, opt_type, typedef_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
CTypes_decl.do_typedef_declaration tenv namespace CTypes_decl.do_typedef_declaration tenv namespace
decl_info name opt_type typedef_decl_info decl_info name opt_type typedef_decl_info
(* Currently C/C++ record decl treated in the same way *) (* Currently C/C++ record decl treated in the same way *)
| CXXRecordDecl (decl_info, record_name, opt_type, decl_list, decl_context_info, record_decl_info) | CXXRecordDecl (decl_info, name_info, opt_type, decl_list, decl_context_info, record_decl_info)
| RecordDecl (decl_info, record_name, opt_type, decl_list, decl_context_info, record_decl_info) -> | RecordDecl (decl_info, name_info, opt_type, decl_list, decl_context_info, record_decl_info) ->
let record_name = name_info.Clang_ast_t.ni_name in
CTypes_decl.do_record_declaration tenv namespace CTypes_decl.do_record_declaration tenv namespace
decl_info record_name opt_type decl_list decl_context_info record_decl_info decl_info record_name opt_type decl_list decl_context_info record_decl_info
| VarDecl(decl_info, name, t, _) -> | VarDecl(decl_info, name_info, t, _) ->
let name = name_info.Clang_ast_t.ni_name in
CVar_decl.global_var_decl tenv namespace decl_info name t CVar_decl.global_var_decl tenv namespace decl_info name t
| ObjCInterfaceDecl(decl_info, name, decl_list, decl_context_info, obj_c_interface_decl_info) -> | ObjCInterfaceDecl(decl_info, name_info, decl_list, decl_context_info, obj_c_interface_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
let curr_class = let curr_class =
ObjcInterface_decl.interface_declaration tenv name decl_list obj_c_interface_decl_info in ObjcInterface_decl.interface_declaration tenv name decl_list obj_c_interface_decl_info in
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list
| ObjCProtocolDecl(decl_info, name, decl_list, decl_context_info, obj_c_protocol_decl_info) -> | ObjCProtocolDecl(decl_info, name_info, decl_list, decl_context_info, obj_c_protocol_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
let curr_class = ObjcProtocol_decl.protocol_decl tenv name decl_list in let curr_class = ObjcProtocol_decl.protocol_decl tenv name decl_list in
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list
| ObjCCategoryDecl(decl_info, name, decl_list, decl_context_info, category_decl_info) -> | ObjCCategoryDecl(decl_info, name_info, decl_list, decl_context_info, category_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
let curr_class = let curr_class =
ObjcCategory_decl.category_decl tenv name category_decl_info decl_list in ObjcCategory_decl.category_decl tenv name category_decl_info decl_list in
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list
| ObjCCategoryImplDecl(decl_info, name, decl_list, decl_context_info, category_impl_info) -> | ObjCCategoryImplDecl(decl_info, name_info, decl_list, decl_context_info, category_impl_info) ->
let name = name_info.Clang_ast_t.ni_name in
let curr_class = let curr_class =
ObjcCategory_decl.category_impl_decl tenv name decl_info category_impl_info decl_list in ObjcCategory_decl.category_impl_decl tenv name decl_info category_impl_info decl_list in
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list
| ObjCImplementationDecl(decl_info, class_name, decl_list, decl_context_info, idi) -> | ObjCImplementationDecl(decl_info, name_info, decl_list, decl_context_info, idi) ->
let name = name_info.Clang_ast_t.ni_name in
let curr_class = let curr_class =
ObjcInterface_decl.interface_impl_declaration tenv class_name decl_list idi in ObjcInterface_decl.interface_impl_declaration tenv name decl_list idi in
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list
| EnumDecl(decl_info, name, opt_type, decl_list, decl_context_info, enum_decl_info) | EnumDecl(decl_info, name_info, opt_type, decl_list, decl_context_info, enum_decl_info)
when should_translate_enum -> when should_translate_enum ->
let name = name_info.Clang_ast_t.ni_name in
CEnum_decl.enum_decl name tenv cfg cg namespace decl_list opt_type CEnum_decl.enum_decl name tenv cfg cg namespace decl_list opt_type
| LinkageSpecDecl(decl_info, decl_list, decl_context_info) -> | LinkageSpecDecl(decl_info, decl_list, decl_context_info) ->
Printing.log_out "ADDING: LinkageSpecDecl decl list\n"; Printing.log_out "ADDING: LinkageSpecDecl decl list\n";
list_iter (translate_one_declaration tenv cg cfg namespace) decl_list list_iter (translate_one_declaration tenv cg cfg namespace) decl_list
| NamespaceDecl(decl_info, name, decl_list, decl_context_info, _) -> | NamespaceDecl(decl_info, name_info, decl_list, decl_context_info, _) ->
let name = ns_suffix^name in let name = ns_suffix^name_info.Clang_ast_t.ni_name in
list_iter (translate_one_declaration tenv cg cfg (Some name)) decl_list list_iter (translate_one_declaration tenv cg cfg (Some name)) decl_list
| EmptyDecl _ -> | EmptyDecl _ ->
Printing.log_out "Passing from EmptyDecl. Treated as skip\n"; Printing.log_out "Passing from EmptyDecl. Treated as skip\n";
@ -82,7 +92,8 @@ let preprocess_one_declaration tenv cg cfg dec =
let info = Clang_ast_proj.get_decl_tuple dec in let info = Clang_ast_proj.get_decl_tuple dec in
CLocation.update_curr_file info; CLocation.update_curr_file info;
match dec with match dec with
| FunctionDecl(di, name, qt, fdecl_info) -> | FunctionDecl(di, name_info, qt, fdecl_info) ->
let name = name_info.Clang_ast_t.ni_name in
ignore (CMethod_declImpl.create_function_signature di fdecl_info name qt false None) ignore (CMethod_declImpl.create_function_signature di fdecl_info name qt false None)
| _ -> () | _ -> ()

@ -148,7 +148,7 @@ struct
match property_impl_decl_info.Clang_ast_t.opidi_property_decl with match property_impl_decl_info.Clang_ast_t.opidi_property_decl with
| Some decl_ref -> | Some decl_ref ->
(match decl_ref.Clang_ast_t.dr_name with (match decl_ref.Clang_ast_t.dr_name with
| Some n -> n | Some n -> n.Clang_ast_t.ni_name
| _ -> no_property_name) | _ -> no_property_name)
| None -> no_property_name | None -> no_property_name
@ -207,12 +207,18 @@ struct
attribute = `Copy attribute = `Copy
| _ -> false | _ -> false
let name_opt_of_name_info_opt name_info_opt =
match name_info_opt with
| Some name_info -> Some name_info.Clang_ast_t.ni_name
| None -> None
let rec getter_attribute_opt attributes = let rec getter_attribute_opt attributes =
match attributes with match attributes with
| [] -> None | [] -> None
| attr:: rest -> | attr:: rest ->
match attr with match attr with
| `Getter getter -> getter.Clang_ast_t.dr_name | `Getter getter -> name_opt_of_name_info_opt getter.Clang_ast_t.dr_name
| _ -> (getter_attribute_opt rest) | _ -> (getter_attribute_opt rest)
let rec setter_attribute_opt attributes = let rec setter_attribute_opt attributes =
@ -220,7 +226,7 @@ struct
| [] -> None | [] -> None
| attr:: rest -> | attr:: rest ->
match attr with match attr with
| `Setter setter -> setter.Clang_ast_t.dr_name | `Setter setter -> name_opt_of_name_info_opt setter.Clang_ast_t.dr_name
| _ -> (setter_attribute_opt rest) | _ -> (setter_attribute_opt rest)
(*TODO: take the attributes into account too. To be done after we get the attribute's arguments. *) (*TODO: take the attributes into account too. To be done after we get the attribute's arguments. *)

@ -41,6 +41,8 @@ sig
val string_of_unary_operator_kind : Clang_ast_t.unary_operator_kind -> string val string_of_unary_operator_kind : Clang_ast_t.unary_operator_kind -> string
val name_opt_of_name_info_opt : Clang_ast_t.named_decl_info option -> string option
val property_name : Clang_ast_t.obj_c_property_impl_decl_info -> string val property_name : Clang_ast_t.obj_c_property_impl_decl_info -> string
val property_attribute_compare : property_attribute -> property_attribute -> int val property_attribute_compare : property_attribute -> property_attribute -> int

@ -47,7 +47,8 @@ struct
let get_parameters function_method_decl_info = let get_parameters function_method_decl_info =
let par_to_ms_par par = let par_to_ms_par par =
match par with match par with
| ParmVarDecl(decl_info, name, qtype, var_decl_info) -> | ParmVarDecl(decl_info, name_info, qtype, var_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
Printing.log_out "Adding param '%s' " name; Printing.log_out "Adding param '%s' " name;
Printing.log_out "with pointer %s@." decl_info.Clang_ast_t.di_pointer; Printing.log_out "with pointer %s@." decl_info.Clang_ast_t.di_pointer;
(name, CTypes.get_type qtype, var_decl_info.vdi_init_expr) (name, CTypes.get_type qtype, var_decl_info.vdi_init_expr)
@ -96,8 +97,9 @@ struct
| decl:: rest -> | decl:: rest ->
let rest_assume_calls = add_assume_not_null_calls rest attributes in let rest_assume_calls = add_assume_not_null_calls rest attributes in
(match decl with (match decl with
| ParmVarDecl(decl_info, name, qtype, var_decl_info) | ParmVarDecl(decl_info, name_info, qtype, var_decl_info)
when CFrontend_utils.Ast_utils.is_type_nonnull qtype attributes -> when CFrontend_utils.Ast_utils.is_type_nonnull qtype attributes ->
let name = name_info.Clang_ast_t.ni_name in
let assume_call = Ast_expressions.create_assume_not_null_call decl_info name qtype in let assume_call = Ast_expressions.create_assume_not_null_call decl_info name qtype in
assume_call:: rest_assume_calls assume_call:: rest_assume_calls
| _ -> rest_assume_calls) | _ -> rest_assume_calls)
@ -179,7 +181,8 @@ struct
let rec process_one_method_decl tenv cg cfg curr_class namespace dec = let rec process_one_method_decl tenv cg cfg curr_class namespace dec =
match dec with match dec with
| ObjCMethodDecl(decl_info, method_name, method_decl_info) -> | ObjCMethodDecl(decl_info, name_info, method_decl_info) ->
let method_name = name_info.Clang_ast_t.ni_name in
process_objc_method_decl tenv cg cfg namespace curr_class decl_info method_name method_decl_info process_objc_method_decl tenv cg cfg namespace curr_class decl_info method_name method_decl_info
| ObjCPropertyImplDecl(decl_info, property_impl_decl_info) -> | ObjCPropertyImplDecl(decl_info, property_impl_decl_info) ->

@ -113,7 +113,8 @@ let captured_vars_from_block_info context cvl =
(match cv.Clang_ast_t.bcv_variable with (match cv.Clang_ast_t.bcv_variable with
| Some dr -> | Some dr ->
(match dr.Clang_ast_t.dr_name, dr.Clang_ast_t.dr_qual_type with (match dr.Clang_ast_t.dr_name, dr.Clang_ast_t.dr_qual_type with
| Some n, _ -> | Some name_info, _ ->
let n = name_info.Clang_ast_t.ni_name in
if n = CFrontend_config.self && not context.is_instance then [] if n = CFrontend_config.self && not context.is_instance then []
else else
(let procdesc_formals = Cfg.Procdesc.get_formals context.procdesc in (let procdesc_formals = Cfg.Procdesc.get_formals context.procdesc in

@ -204,7 +204,7 @@ struct
let objCProtocolExpr_trans trans_state stmt_info expr_info decl_ref = let objCProtocolExpr_trans trans_state stmt_info expr_info decl_ref =
Printing.log_out "Passing from ObjCProtocolExpr '%s'\n" stmt_info.Clang_ast_t.si_pointer; Printing.log_out "Passing from ObjCProtocolExpr '%s'\n" stmt_info.Clang_ast_t.si_pointer;
let name = (match decl_ref.Clang_ast_t.dr_name with let name = (match decl_ref.Clang_ast_t.dr_name with
| Some s -> s | Some s -> s.Clang_ast_t.ni_name
| _ -> "") in | _ -> "") in
stringLiteral_trans trans_state stmt_info expr_info name stringLiteral_trans trans_state stmt_info expr_info name
@ -1427,7 +1427,7 @@ struct
let exp_stmt = extract_stmt_from_singleton stmt_list let exp_stmt = extract_stmt_from_singleton stmt_list
"WARNING: in MemberExpr there must be only one stmt defining its expression.\n" in "WARNING: in MemberExpr there must be only one stmt defining its expression.\n" in
let name_field = (match obj_c_ivar_ref_expr_info.Clang_ast_t.ovrei_decl_ref.Clang_ast_t.dr_name with let name_field = (match obj_c_ivar_ref_expr_info.Clang_ast_t.ovrei_decl_ref.Clang_ast_t.dr_name with
| Some s -> s | Some s -> s.Clang_ast_t.ni_name
| _ -> assert false) in | _ -> assert false) in
do_memb_ivar_ref_exp trans_state expr_info exp_stmt sil_loc name_field do_memb_ivar_ref_exp trans_state expr_info exp_stmt sil_loc name_field
@ -1436,7 +1436,7 @@ struct
let sil_loc = get_sil_location stmt_info trans_state.parent_line_number trans_state.context in let sil_loc = get_sil_location stmt_info trans_state.parent_line_number trans_state.context in
let exp_stmt = extract_stmt_from_singleton stmt_list let exp_stmt = extract_stmt_from_singleton stmt_list
"WARNING: in MemberExpr there must be only one stmt defining its expression.\n" in "WARNING: in MemberExpr there must be only one stmt defining its expression.\n" in
let name_field = member_expr_info.Clang_ast_t.mei_name in let name_field = member_expr_info.Clang_ast_t.mei_name.Clang_ast_t.ni_name in
do_memb_ivar_ref_exp trans_state expr_info exp_stmt sil_loc name_field do_memb_ivar_ref_exp trans_state expr_info exp_stmt sil_loc name_field
and unaryOperator_trans trans_state stmt_info expr_info stmt_list unary_operator_info = and unaryOperator_trans trans_state stmt_info expr_info stmt_list unary_operator_info =

@ -427,7 +427,7 @@ let fix_param_exps_mismatch params_stmt exps_param =
let get_name_decl_ref_exp_info decl_ref_expr_info si = let get_name_decl_ref_exp_info decl_ref_expr_info si =
match decl_ref_expr_info.Clang_ast_t.drti_decl_ref with match decl_ref_expr_info.Clang_ast_t.drti_decl_ref with
| Some d -> (match d.Clang_ast_t.dr_name with | Some d -> (match d.Clang_ast_t.dr_name with
| Some n -> n | Some n -> n.Clang_ast_t.ni_name
| _ -> assert false) | _ -> assert false)
| _ -> L.err "FAILING WITH %s pointer=%s@.@." | _ -> L.err "FAILING WITH %s pointer=%s@.@."
(Clang_ast_j.string_of_decl_ref_expr_info decl_ref_expr_info ) (Clang_ast_j.string_of_decl_ref_expr_info decl_ref_expr_info )
@ -646,7 +646,8 @@ let is_dispatch_function stmt_list =
| None -> None | None -> None
| Some d -> | Some d ->
(match d.Clang_ast_t.dr_kind, d.Clang_ast_t.dr_name with (match d.Clang_ast_t.dr_kind, d.Clang_ast_t.dr_name with
| `Function, Some s -> | `Function, Some name_info ->
let s = name_info.Clang_ast_t.ni_name in
(match (CTrans_models.is_dispatch_function_name s) with (match (CTrans_models.is_dispatch_function_name s) with
| None -> None | None -> None
| Some (dispatch_function, block_arg_pos) -> | Some (dispatch_function, block_arg_pos) ->

@ -178,7 +178,8 @@ and do_typedef_declaration tenv namespace decl_info name opt_type typedef_decl_i
and get_struct_fields tenv namespace decl_list = and get_struct_fields tenv namespace decl_list =
match decl_list with match decl_list with
| [] -> [] | [] -> []
| FieldDecl(decl_info, name, qual_type, field_decl_info):: decl_list' -> | FieldDecl(decl_info, name_info, qual_type, field_decl_info):: decl_list' ->
let name = name_info.Clang_ast_t.ni_name in
Printing.log_out " ...Defining field '%s'.\n" name; Printing.log_out " ...Defining field '%s'.\n" name;
let id = Ident.create_fieldname (Mangled.from_string name) 0 in let id = Ident.create_fieldname (Mangled.from_string name) 0 in
let typ = qual_type_to_sil_type tenv qual_type in let typ = qual_type_to_sil_type tenv qual_type in
@ -189,7 +190,7 @@ and get_struct_fields tenv namespace decl_list =
(* C++/C Records treated in the same way*) (* C++/C Records treated in the same way*)
| RecordDecl (decl_info, name, opt_type, decl_list, decl_context_info, record_decl_info) | RecordDecl (decl_info, name, opt_type, decl_list, decl_context_info, record_decl_info)
:: decl_list'-> :: decl_list'->
do_record_declaration tenv namespace decl_info name opt_type decl_list decl_context_info record_decl_info; do_record_declaration tenv namespace decl_info name.Clang_ast_t.ni_name opt_type decl_list decl_context_info record_decl_info;
get_struct_fields tenv namespace decl_list' get_struct_fields tenv namespace decl_list'
| _ :: decl_list' -> get_struct_fields tenv namespace decl_list' | _ :: decl_list' -> get_struct_fields tenv namespace decl_list'
@ -253,7 +254,7 @@ and add_late_defined_record tenv namespace typename =
Sil.typename_equal typename pot_union_type) && Sil.typename_equal typename pot_union_type) &&
record_decl_info.Clang_ast_t.rdi_is_complete_definition then ( record_decl_info.Clang_ast_t.rdi_is_complete_definition then (
Printing.log_out "!!!! Adding late-defined record '%s'\n" t; Printing.log_out "!!!! Adding late-defined record '%s'\n" t;
do_record_declaration tenv namespace decl_info record_name opt_type decl_list do_record_declaration tenv namespace decl_info record_name.Clang_ast_t.ni_name opt_type decl_list
decl_context_info record_decl_info; decl_context_info record_decl_info;
true) true)
else scan decls' else scan decls'
@ -272,7 +273,8 @@ and add_late_defined_typedef tenv namespace typename =
let rec scan decls = let rec scan decls =
match decls with match decls with
| [] -> false | [] -> false
| TypedefDecl (decl_info, name', opt_type, tdi) :: decls' -> | TypedefDecl (decl_info, name_info, opt_type, tdi) :: decls' ->
let name' = name_info.Clang_ast_t.ni_name in
(match opt_type with (match opt_type with
| `Type t -> | `Type t ->
if (Mangled.to_string name) = name' then ( if (Mangled.to_string name) = name' then (

@ -39,7 +39,8 @@ let rec lookup_ahead_for_vardecl context pointer var_name kind decl_list =
match decl_list with match decl_list with
| [] -> Printing.log_out " Failing when looking ahead for variable '%s'\n" var_name; | [] -> Printing.log_out " Failing when looking ahead for variable '%s'\n" var_name;
assert false (* nothing has been found ahead, maybe something bad in the AST *) assert false (* nothing has been found ahead, maybe something bad in the AST *)
| VarDecl(decl_info, var_name', t, _) :: rest when var_name = var_name' -> | VarDecl(decl_info, var_info, t, _) :: rest when var_name = var_info.Clang_ast_t.ni_name ->
let var_name' = var_info.Clang_ast_t.ni_name in
if global_to_be_added decl_info then ( if global_to_be_added decl_info then (
let tenv = CContext.get_tenv context in let tenv = CContext.get_tenv context in
Printing.log_out "ADDING (later-defined): VarDecl '%s' to global procdesc\n" var_name'; Printing.log_out "ADDING (later-defined): VarDecl '%s' to global procdesc\n" var_name';
@ -137,8 +138,9 @@ and get_fun_locals context (stmts : Clang_ast_t.stmt list) : unit =
and get_variables_decls context (decl_list : Clang_ast_t.decl list) : unit = and get_variables_decls context (decl_list : Clang_ast_t.decl list) : unit =
let do_one_decl decl = let do_one_decl decl =
match decl with match decl with
| VarDecl (decl_info, name, qual_type, var_decl_info) -> | VarDecl (decl_info, name_info, qual_type, var_decl_info) ->
Printing.log_out "Collecting variables, passing from VarDecl '%s'\n" decl_info.Clang_ast_t.di_pointer; Printing.log_out "Collecting variables, passing from VarDecl '%s'\n" decl_info.Clang_ast_t.di_pointer;
let name = name_info.Clang_ast_t.ni_name in
let typ = get_var_type context.CContext.tenv name qual_type in let typ = get_var_type context.CContext.tenv name qual_type in
(match var_decl_info.Clang_ast_t.vdi_storage_class with (match var_decl_info.Clang_ast_t.vdi_storage_class with
| Some "static" -> | Some "static" ->
@ -150,14 +152,14 @@ and get_variables_decls context (decl_list : Clang_ast_t.decl list) : unit =
| _ -> | _ ->
CContext.LocalVars.add_local_var context name typ decl_info.Clang_ast_t.di_pointer CContext.LocalVars.add_local_var context name typ decl_info.Clang_ast_t.di_pointer
(CFrontend_utils.General_utils.is_static_var var_decl_info)) (CFrontend_utils.General_utils.is_static_var var_decl_info))
| CXXRecordDecl(di, n', ot, dl, dci, rdi) | CXXRecordDecl(di, n_info, ot, dl, dci, rdi)
| RecordDecl(di, n', ot, dl, dci, rdi) -> | RecordDecl(di, n_info, ot, dl, dci, rdi) ->
let typ = CTypes_decl.get_declaration_type context.CContext.tenv context.CContext.namespace let typ = CTypes_decl.get_declaration_type context.CContext.tenv context.CContext.namespace
di n' ot dl dci rdi in di n_info.Clang_ast_t.ni_name ot dl dci rdi in
CTypes_decl.add_struct_to_tenv context.CContext.tenv typ CTypes_decl.add_struct_to_tenv context.CContext.tenv typ
| TypedefDecl (decl_info, name, opt_type, typedef_decl_info) -> | TypedefDecl (decl_info, name_info, opt_type, typedef_decl_info) ->
CTypes_decl.do_typedef_declaration context.CContext.tenv context.CContext.namespace CTypes_decl.do_typedef_declaration context.CContext.tenv context.CContext.namespace
decl_info name opt_type typedef_decl_info decl_info name_info.Clang_ast_t.ni_name opt_type typedef_decl_info
| StaticAssertDecl decl_info -> (* We do not treat Assertions. *) | StaticAssertDecl decl_info -> (* We do not treat Assertions. *)
Printing.log_out Printing.log_out
"WARNING: When collecting variables, passing from StaticAssertDecl '%s'. Skipped.\n" "WARNING: When collecting variables, passing from StaticAssertDecl '%s'. Skipped.\n"

@ -17,7 +17,7 @@ let noname_category class_name =
let cat_class_decl dr = let cat_class_decl dr =
match dr.Clang_ast_t.dr_name with match dr.Clang_ast_t.dr_name with
| Some n -> n | Some n -> n.Clang_ast_t.ni_name
| _ -> assert false | _ -> assert false
let get_class_from_category_decl category_decl_info = let get_class_from_category_decl category_decl_info =

@ -39,13 +39,13 @@ let is_pointer_to_objc_class tenv typ =
let get_super_interface_decl otdi_super = let get_super_interface_decl otdi_super =
match otdi_super with match otdi_super with
| Some dr -> dr.Clang_ast_t.dr_name | Some dr -> Ast_utils.name_opt_of_name_info_opt dr.Clang_ast_t.dr_name
| _ -> None | _ -> None
let get_protocols protocols = let get_protocols protocols =
let protocol_names = list_map ( let protocol_names = list_map (
fun decl -> match decl.Clang_ast_t.dr_name with fun decl -> match decl.Clang_ast_t.dr_name with
| Some name -> name | Some name -> name.Clang_ast_t.ni_name
| None -> assert false | None -> assert false
) protocols in ) protocols in
protocol_names protocol_names
@ -198,16 +198,16 @@ let lookup_late_defined_interface tenv cname =
let rec scan decls = let rec scan decls =
match decls with match decls with
| [] -> () | [] -> ()
| ObjCInterfaceDecl(decl_info, name, decl_list, decl_context_info, obj_c_interface_decl_info) | ObjCInterfaceDecl(decl_info, name_info, decl_list, decl_context_info, obj_c_interface_decl_info)
:: decls' :: decls'
when (Mangled.from_string name) = cname -> when (Mangled.from_string name_info.Clang_ast_t.ni_name) = cname ->
scan decls' scan decls'
| ObjCInterfaceDecl(decl_info, name, decl_list, decl_context_info, obj_c_interface_decl_info) | ObjCInterfaceDecl(decl_info, name_info, decl_list, decl_context_info, obj_c_interface_decl_info)
:: decls' :: decls'
when (Mangled.from_string name) = cname -> when (Mangled.from_string name_info.Clang_ast_t.ni_name) = cname ->
(* Assumption: here we assume that the first interface declaration with non empty set of fields is the *) (* Assumption: here we assume that the first interface declaration with non empty set of fields is the *)
(* correct one. So we stop. *) (* correct one. So we stop. *)
ignore (interface_declaration tenv name decl_list obj_c_interface_decl_info) ignore (interface_declaration tenv name_info.Clang_ast_t.ni_name decl_list obj_c_interface_decl_info)
| _:: decls' -> scan decls' in | _:: decls' -> scan decls' in
scan !CFrontend_config.global_translation_unit_decls scan !CFrontend_config.global_translation_unit_decls

@ -164,7 +164,7 @@ let find_properties_class = Property.find_properties_class
let get_ivarname_property pidi = let get_ivarname_property pidi =
match pidi.Clang_ast_t.opidi_ivar_decl with match pidi.Clang_ast_t.opidi_ivar_decl with
| Some dr -> (match dr.Clang_ast_t.dr_name with | Some dr -> (match dr.Clang_ast_t.dr_name with
| Some n -> n | Some n -> n.Clang_ast_t.ni_name
| _ -> assert false) | _ -> assert false)
| _ -> (* If ivar is not defined than we need to take the name of the property to define ivar*) | _ -> (* If ivar is not defined than we need to take the name of the property to define ivar*)
Ast_utils.property_name pidi Ast_utils.property_name pidi
@ -207,7 +207,7 @@ let prepare_dynamic_property curr_class decl_info property_impl_decl_info =
let qt = (try let qt = (try
let qt', atts, di, getter, setter, _ = Property.find_property curr_class pname in let qt', atts, di, getter, setter, _ = Property.find_property curr_class pname in
let ivar = (match property_impl_decl_info.Clang_ast_t.opidi_ivar_decl with let ivar = (match property_impl_decl_info.Clang_ast_t.opidi_ivar_decl with
| Some dr -> dr.Clang_ast_t.dr_name | Some dr -> Ast_utils.name_opt_of_name_info_opt dr.Clang_ast_t.dr_name
| None -> None) in | None -> None) in
(* update property info with proper ivar name *) (* update property info with proper ivar name *)
Property.replace_property (curr_class, pname) (qt', atts, di, getter, setter, ivar); Property.replace_property (curr_class, pname) (qt', atts, di, getter, setter, ivar);
@ -274,27 +274,28 @@ let make_getter_setter cfg curr_class decl_info property_impl_decl_info =
let make_getter () = let make_getter () =
( (
match getter with match getter with
| Some (ObjCMethodDecl(di, name, mdi), _) -> | Some (ObjCMethodDecl(di, name_info, mdi), _) ->
let dummy_info = Ast_expressions.dummy_decl_info di in let dummy_info = Ast_expressions.dummy_decl_info di in
if should_generate_getter cfg class_name name attributes then if should_generate_getter cfg class_name name_info.Clang_ast_t.ni_name attributes then
let deref_self_field = Ast_expressions.make_deref_self_field let deref_self_field = Ast_expressions.make_deref_self_field
(CContext.get_qt_curr_class curr_class) dummy_info mdi.Clang_ast_t.omdi_result_type ivar_name in (CContext.get_qt_curr_class curr_class) dummy_info mdi.Clang_ast_t.omdi_result_type ivar_name in
let body = ReturnStmt(Ast_expressions.make_stmt_info dummy_info, [deref_self_field]) in let body = ReturnStmt(Ast_expressions.make_stmt_info dummy_info, [deref_self_field]) in
let mdi'= Ast_expressions.make_method_decl_info mdi body in let mdi'= Ast_expressions.make_method_decl_info mdi body in
let method_decl = ObjCMethodDecl(di, name_info, mdi) in
Property.replace_property Property.replace_property
(curr_class, prop_name) (curr_class, prop_name)
(qt, attributes, decl_info, (qt, attributes, decl_info,
(getter_name, Some (ObjCMethodDecl(di, name, mdi), true)), (setter_name, setter), Some ivar_name); (getter_name, Some (method_decl, true)), (setter_name, setter), Some ivar_name);
[ObjCMethodDecl(dummy_info, name, mdi')] [ObjCMethodDecl(dummy_info, name_info, mdi')]
else [] else []
| _ -> []) in | _ -> []) in
let make_setter () = let make_setter () =
match setter with match setter with
| Some (ObjCMethodDecl(di, name, mdi), _) -> | Some (ObjCMethodDecl(di, name_info, mdi), _) ->
if should_generate_setter cfg class_name name attributes then if should_generate_setter cfg class_name name_info.Clang_ast_t.ni_name attributes then
let dummy_info = Ast_expressions.dummy_decl_info di in let dummy_info = Ast_expressions.dummy_decl_info di in
let param_name, qt_param = (match mdi.Clang_ast_t.omdi_parameters with let param_name, qt_param = (match mdi.Clang_ast_t.omdi_parameters with
| [ParmVarDecl(_, name, qt_param, _)] -> name, qt_param | [ParmVarDecl(_, name_info, qt_param, _)] -> name_info.Clang_ast_t.ni_name, qt_param
| _ -> assert false) in | _ -> assert false) in
let is_hidden = (match property_impl_decl_info.Clang_ast_t.opidi_ivar_decl with let is_hidden = (match property_impl_decl_info.Clang_ast_t.opidi_ivar_decl with
| Some dr -> dr.Clang_ast_t.dr_is_hidden | Some dr -> dr.Clang_ast_t.dr_is_hidden
@ -334,8 +335,8 @@ let make_getter_setter cfg curr_class decl_info property_impl_decl_info =
(curr_class, prop_name) (curr_class, prop_name)
(qt, attributes, decl_info, (qt, attributes, decl_info,
(getter_name, getter), (getter_name, getter),
(setter_name, Some (ObjCMethodDecl(di, name, mdi), true)), Some ivar_name); (setter_name, Some (ObjCMethodDecl(di, name_info, mdi), true)), Some ivar_name);
[ObjCMethodDecl(dummy_info, name, mdi')] [ObjCMethodDecl(dummy_info, name_info, mdi')]
else [] else []
| _ -> [] in | _ -> [] in
match property_impl_decl_info.Clang_ast_t.opidi_implementation with match property_impl_decl_info.Clang_ast_t.opidi_implementation with
@ -353,16 +354,18 @@ let rec get_methods curr_class decl_list =
let class_name = CContext.get_curr_class_name curr_class in let class_name = CContext.get_curr_class_name curr_class in
match decl_list with match decl_list with
| [] -> [] | [] -> []
| (ObjCMethodDecl(decl_info, method_name, method_decl_info) as d):: decl_list' -> | (ObjCMethodDecl(decl_info, name_info, method_decl_info) as d):: decl_list' ->
let method_name = name_info.Clang_ast_t.ni_name in
Printing.log_out " ...Adding Method '%s' \n" (class_name^"_"^method_name); Printing.log_out " ...Adding Method '%s' \n" (class_name^"_"^method_name);
let methods = get_methods curr_class decl_list' in let methods = get_methods curr_class decl_list' in
let _ = check_for_property curr_class method_name d method_decl_info.Clang_ast_t.omdi_body in let _ = check_for_property curr_class method_name d method_decl_info.Clang_ast_t.omdi_body in
let meth_name = CMethod_trans.mk_procname_from_method class_name method_name in let meth_name = CMethod_trans.mk_procname_from_method class_name method_name in
meth_name:: methods meth_name:: methods
| ObjCPropertyDecl(decl_info, pname, pdi):: decl_list' -> | ObjCPropertyDecl(decl_info, name_info, pdi):: decl_list' ->
(* Property declaration register the property on the property table to be *) (* Property declaration register the property on the property table to be *)
(* used later on in case getter and setters need to be synthesized by ObjCPropertyImplDecl *) (* used later on in case getter and setters need to be synthesized by ObjCPropertyImplDecl *)
let pname = name_info.Clang_ast_t.ni_name in
Printing.log_out " ...Adding Property Declaration '%s' " pname; Printing.log_out " ...Adding Property Declaration '%s' " pname;
Printing.log_out " pointer= '%s' \n" decl_info.Clang_ast_t.di_pointer; Printing.log_out " pointer= '%s' \n" decl_info.Clang_ast_t.di_pointer;
Property.add_property (curr_class, pname) pdi.opdi_qual_type pdi.opdi_property_attributes decl_info; Property.add_property (curr_class, pname) pdi.opdi_qual_type pdi.opdi_property_attributes decl_info;

Loading…
Cancel
Save