From 927653e8d8e35767f8bd52170cdaa12d53773da4 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 7 Jul 2015 11:38:43 -0100 Subject: [PATCH] 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']) --- .../clang-plugin/clang-plugin-version.config | 2 +- infer/src/clang/ast_expressions.ml | 18 +++++--- infer/src/clang/cAstProcessor.ml | 6 +-- infer/src/clang/cEnum_decl.ml | 3 +- infer/src/clang/cField_decl.ml | 5 ++- infer/src/clang/cFrontend.ml | 41 ++++++++++++------- infer/src/clang/cFrontend_utils.ml | 12 ++++-- infer/src/clang/cFrontend_utils.mli | 2 + infer/src/clang/cMethod_decl.ml | 9 ++-- infer/src/clang/cMethod_trans.ml | 3 +- infer/src/clang/cTrans.ml | 6 +-- infer/src/clang/cTrans_utils.ml | 5 ++- infer/src/clang/cTypes_decl.ml | 10 +++-- infer/src/clang/cVar_decl.ml | 16 ++++---- infer/src/clang/objcCategory_decl.ml | 2 +- infer/src/clang/objcInterface_decl.ml | 14 +++---- infer/src/clang/objcProperty_decl.ml | 29 +++++++------ 17 files changed, 111 insertions(+), 72 deletions(-) diff --git a/dependencies/clang-plugin/clang-plugin-version.config b/dependencies/clang-plugin/clang-plugin-version.config index 0dcfe7e12..ad2682ef2 100644 --- a/dependencies/clang-plugin/clang-plugin-version.config +++ b/dependencies/clang-plugin/clang-plugin-version.config @@ -1 +1 @@ -24e2b11a8802be69444a702b683c1be380570bae +8a70ebe9439ec6495330ebe9a90c45e8e8b6b3b7 diff --git a/infer/src/clang/ast_expressions.ml b/infer/src/clang/ast_expressions.ml index 51ea2cd0e..25fe3a3b1 100644 --- a/infer/src/clang/ast_expressions.ml +++ b/infer/src/clang/ast_expressions.ml @@ -159,9 +159,14 @@ let make_obj_c_message_expr_info_class selector 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 = { 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_qual_type = Some (qt) } @@ -171,7 +176,7 @@ let make_decl_ref name = let make_decl_ref_self qt = { 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_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 = { 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 - 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 = { @@ -278,7 +283,7 @@ let make_next_object_exp stmt_info item items = let var_decl_ref, var_type = match item with | 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 = { si_pointer = di.Clang_ast_t.di_pointer; 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 = try Utils.list_nth stmt_list (n + 1) 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) -> let qt = bei.Clang_ast_t.ei_qual_type 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 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 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 expr_info_call = { 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 let decl_ref = { dr_kind = `Var; - dr_name = Some block_name; + dr_name = Some block_name_info; dr_is_hidden = false; dr_qual_type = Some qt; } in diff --git a/infer/src/clang/cAstProcessor.ml b/infer/src/clang/cAstProcessor.ml index ef0727c47..38d021b8b 100644 --- a/infer/src/clang/cAstProcessor.ml +++ b/infer/src/clang/cAstProcessor.ml @@ -99,7 +99,7 @@ let pp_ast_decl fmt ast_decl = | FunctionDecl (decl_info, name, qt, fdecl_info) -> F.fprintf fmt "%sFunctionDecl %s %a@\n" prefix - name + name.Clang_ast_t.ni_name 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_parameters; @@ -107,10 +107,10 @@ let pp_ast_decl fmt ast_decl = | ObjCMethodDecl (decl_info, name, obj_c_method_decl_info) -> F.fprintf fmt "%sObjCMethodDecl %s %a@\n" prefix - name + name.Clang_ast_t.ni_name pp_source_range decl_info.di_source_range; 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" prefix pp_source_range decl_info.di_source_range; diff --git a/infer/src/clang/cEnum_decl.ml b/infer/src/clang/cEnum_decl.ml index 76651640a..95d20bc2c 100644 --- a/infer/src/clang/cEnum_decl.ml +++ b/infer/src/clang/cEnum_decl.ml @@ -44,7 +44,8 @@ let global_procdesc = ref (create_empty_procdesc ()) let rec get_enum_constants context decl_list v = 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 | None -> Printing.log_out "%s" (" ...Defining Enum Constant ("^name^", "^(string_of_int v)); (Mangled.from_string name, Sil.Cint (Sil.Int.of_int v)) diff --git a/infer/src/clang/cField_decl.ml b/infer/src/clang/cField_decl.ml index ea5542bb5..11ecf7837 100644 --- a/infer/src/clang/cField_decl.ml +++ b/infer/src/clang/cField_decl.ml @@ -29,7 +29,7 @@ let fields_superclass tenv interface_decl_info = match interface_decl_info.Clang_ast_t.otdi_super with | Some dr -> (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 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 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 *) (* ivar names will be added in the property list. *) Printing.log_out " ...Adding Instance Variable '%s' @." field_name; diff --git a/infer/src/clang/cFrontend.ml b/infer/src/clang/cFrontend.ml index 578861ada..c872754da 100644 --- a/infer/src/clang/cFrontend.ml +++ b/infer/src/clang/cFrontend.ml @@ -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 should_translate_enum = CLocation.should_translate_enum source_range in 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 - | 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 decl_info name opt_type typedef_decl_info (* 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) - | RecordDecl (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, 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 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 - | 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 = 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 - | 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 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 = ObjcCategory_decl.category_decl tenv name category_decl_info decl_list in 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 = 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 - | 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 = - 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 - | 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 -> + let name = name_info.Clang_ast_t.ni_name in CEnum_decl.enum_decl name tenv cfg cg namespace decl_list opt_type | LinkageSpecDecl(decl_info, decl_list, decl_context_info) -> Printing.log_out "ADDING: LinkageSpecDecl decl list\n"; list_iter (translate_one_declaration tenv cg cfg namespace) decl_list - | NamespaceDecl(decl_info, name, decl_list, decl_context_info, _) -> - let name = ns_suffix^name in + | NamespaceDecl(decl_info, name_info, decl_list, decl_context_info, _) -> + let name = ns_suffix^name_info.Clang_ast_t.ni_name in list_iter (translate_one_declaration tenv cg cfg (Some name)) decl_list | EmptyDecl _ -> 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 CLocation.update_curr_file info; 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) | _ -> () diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 1c2a088e1..c2fc6fb45 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -148,7 +148,7 @@ struct match property_impl_decl_info.Clang_ast_t.opidi_property_decl with | Some decl_ref -> (match decl_ref.Clang_ast_t.dr_name with - | Some n -> n + | Some n -> n.Clang_ast_t.ni_name | _ -> no_property_name) | None -> no_property_name @@ -207,12 +207,18 @@ struct attribute = `Copy | _ -> 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 = match attributes with | [] -> None | attr:: rest -> 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) let rec setter_attribute_opt attributes = @@ -220,7 +226,7 @@ struct | [] -> None | attr:: rest -> 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) (*TODO: take the attributes into account too. To be done after we get the attribute's arguments. *) diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index b8566884f..6ce7023f7 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -41,6 +41,8 @@ sig 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_attribute_compare : property_attribute -> property_attribute -> int diff --git a/infer/src/clang/cMethod_decl.ml b/infer/src/clang/cMethod_decl.ml index ebb330b85..a6ed6ef33 100644 --- a/infer/src/clang/cMethod_decl.ml +++ b/infer/src/clang/cMethod_decl.ml @@ -47,7 +47,8 @@ struct let get_parameters function_method_decl_info = let par_to_ms_par par = 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 "with pointer %s@." decl_info.Clang_ast_t.di_pointer; (name, CTypes.get_type qtype, var_decl_info.vdi_init_expr) @@ -96,8 +97,9 @@ struct | decl:: rest -> let rest_assume_calls = add_assume_not_null_calls rest attributes in (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 -> + 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 assume_call:: rest_assume_calls | _ -> rest_assume_calls) @@ -179,7 +181,8 @@ struct let rec process_one_method_decl tenv cg cfg curr_class namespace dec = 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 | ObjCPropertyImplDecl(decl_info, property_impl_decl_info) -> diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 81703eec9..a74200a0d 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -113,7 +113,8 @@ let captured_vars_from_block_info context cvl = (match cv.Clang_ast_t.bcv_variable with | Some dr -> (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 [] else (let procdesc_formals = Cfg.Procdesc.get_formals context.procdesc in diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index f7682bb7e..02062f195 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -204,7 +204,7 @@ struct 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; let name = (match decl_ref.Clang_ast_t.dr_name with - | Some s -> s + | Some s -> s.Clang_ast_t.ni_name | _ -> "") in stringLiteral_trans trans_state stmt_info expr_info name @@ -1427,7 +1427,7 @@ struct let exp_stmt = extract_stmt_from_singleton stmt_list "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 - | Some s -> s + | Some s -> s.Clang_ast_t.ni_name | _ -> assert false) in 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 exp_stmt = extract_stmt_from_singleton stmt_list "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 and unaryOperator_trans trans_state stmt_info expr_info stmt_list unary_operator_info = diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index 7531e3575..15f93f9b6 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -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 = match decl_ref_expr_info.Clang_ast_t.drti_decl_ref with | Some d -> (match d.Clang_ast_t.dr_name with - | Some n -> n + | Some n -> n.Clang_ast_t.ni_name | _ -> assert false) | _ -> L.err "FAILING WITH %s pointer=%s@.@." (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 | Some d -> (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 | None -> None | Some (dispatch_function, block_arg_pos) -> diff --git a/infer/src/clang/cTypes_decl.ml b/infer/src/clang/cTypes_decl.ml index 6141e612c..17b9d7169 100644 --- a/infer/src/clang/cTypes_decl.ml +++ b/infer/src/clang/cTypes_decl.ml @@ -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 = 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; let id = Ident.create_fieldname (Mangled.from_string name) 0 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*) | RecordDecl (decl_info, name, opt_type, decl_list, decl_context_info, record_decl_info) :: 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' | _ :: 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) && record_decl_info.Clang_ast_t.rdi_is_complete_definition then ( 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; true) else scan decls' @@ -272,7 +273,8 @@ and add_late_defined_typedef tenv namespace typename = let rec scan decls = match decls with | [] -> 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 | `Type t -> if (Mangled.to_string name) = name' then ( diff --git a/infer/src/clang/cVar_decl.ml b/infer/src/clang/cVar_decl.ml index b46aede5d..158f3702e 100644 --- a/infer/src/clang/cVar_decl.ml +++ b/infer/src/clang/cVar_decl.ml @@ -39,7 +39,8 @@ let rec lookup_ahead_for_vardecl context pointer var_name kind decl_list = match decl_list with | [] -> 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 *) - | 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 ( let tenv = CContext.get_tenv context in 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 = let do_one_decl decl = 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; + let name = name_info.Clang_ast_t.ni_name in let typ = get_var_type context.CContext.tenv name qual_type in (match var_decl_info.Clang_ast_t.vdi_storage_class with | 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 (CFrontend_utils.General_utils.is_static_var var_decl_info)) - | CXXRecordDecl(di, n', ot, dl, dci, rdi) - | RecordDecl(di, n', ot, dl, dci, rdi) -> + | CXXRecordDecl(di, n_info, 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 - 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 - | 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 - 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. *) Printing.log_out "WARNING: When collecting variables, passing from StaticAssertDecl '%s'. Skipped.\n" diff --git a/infer/src/clang/objcCategory_decl.ml b/infer/src/clang/objcCategory_decl.ml index 16955f1e6..bc3c6fcab 100644 --- a/infer/src/clang/objcCategory_decl.ml +++ b/infer/src/clang/objcCategory_decl.ml @@ -17,7 +17,7 @@ let noname_category class_name = let cat_class_decl dr = match dr.Clang_ast_t.dr_name with - | Some n -> n + | Some n -> n.Clang_ast_t.ni_name | _ -> assert false let get_class_from_category_decl category_decl_info = diff --git a/infer/src/clang/objcInterface_decl.ml b/infer/src/clang/objcInterface_decl.ml index b129c4756..57364a8d0 100644 --- a/infer/src/clang/objcInterface_decl.ml +++ b/infer/src/clang/objcInterface_decl.ml @@ -39,13 +39,13 @@ let is_pointer_to_objc_class tenv typ = let get_super_interface_decl otdi_super = 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 let get_protocols protocols = let protocol_names = list_map ( fun decl -> match decl.Clang_ast_t.dr_name with - | Some name -> name + | Some name -> name.Clang_ast_t.ni_name | None -> assert false ) protocols in protocol_names @@ -198,16 +198,16 @@ let lookup_late_defined_interface tenv cname = let rec scan decls = 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' - when (Mangled.from_string name) = cname -> + when (Mangled.from_string name_info.Clang_ast_t.ni_name) = cname -> 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' - 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 *) (* 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 scan !CFrontend_config.global_translation_unit_decls diff --git a/infer/src/clang/objcProperty_decl.ml b/infer/src/clang/objcProperty_decl.ml index f6f8eb8a6..9fa4fb888 100644 --- a/infer/src/clang/objcProperty_decl.ml +++ b/infer/src/clang/objcProperty_decl.ml @@ -164,7 +164,7 @@ let find_properties_class = Property.find_properties_class let get_ivarname_property pidi = match pidi.Clang_ast_t.opidi_ivar_decl with | Some dr -> (match dr.Clang_ast_t.dr_name with - | Some n -> n + | Some n -> n.Clang_ast_t.ni_name | _ -> assert false) | _ -> (* If ivar is not defined than we need to take the name of the property to define ivar*) 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', 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 - | 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 (* update property info with proper ivar name *) 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 () = ( match getter with - | Some (ObjCMethodDecl(di, name, mdi), _) -> + | Some (ObjCMethodDecl(di, name_info, mdi), _) -> 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 (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 mdi'= Ast_expressions.make_method_decl_info mdi body in + let method_decl = ObjCMethodDecl(di, name_info, mdi) in Property.replace_property (curr_class, prop_name) (qt, attributes, decl_info, - (getter_name, Some (ObjCMethodDecl(di, name, mdi), true)), (setter_name, setter), Some ivar_name); - [ObjCMethodDecl(dummy_info, name, mdi')] + (getter_name, Some (method_decl, true)), (setter_name, setter), Some ivar_name); + [ObjCMethodDecl(dummy_info, name_info, mdi')] else [] | _ -> []) in let make_setter () = match setter with - | Some (ObjCMethodDecl(di, name, mdi), _) -> - if should_generate_setter cfg class_name name attributes then + | Some (ObjCMethodDecl(di, name_info, mdi), _) -> + 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 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 let is_hidden = (match property_impl_decl_info.Clang_ast_t.opidi_ivar_decl with | 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) (qt, attributes, decl_info, (getter_name, getter), - (setter_name, Some (ObjCMethodDecl(di, name, mdi), true)), Some ivar_name); - [ObjCMethodDecl(dummy_info, name, mdi')] + (setter_name, Some (ObjCMethodDecl(di, name_info, mdi), true)), Some ivar_name); + [ObjCMethodDecl(dummy_info, name_info, mdi')] else [] | _ -> [] in 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 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); 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 meth_name = CMethod_trans.mk_procname_from_method class_name method_name in 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 *) (* 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 " 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;