From cb8e75be859af0d16a80b2adfe1f0d429c93d903 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 25 Sep 2017 05:49:47 -0700 Subject: [PATCH] [clang] do without unstructured type strings Summary: These get way too big in C++, and we only use the very first word of them, to tell apart class from struct from union... so sad, very bad. update-submodule: facebook-clang-plugins Reviewed By: mbouaziz Differential Revision: D5890594 fbshipit-source-id: 49e6284 --- facebook-clang-plugins | 2 +- infer/src/clang/CType_decl.ml | 44 +++++++++++++------------------ infer/src/clang/cAst_utils.ml | 28 ++++++++++---------- infer/src/clang/cEnum_decl.ml | 2 +- infer/src/clang/cFrontend_decl.ml | 6 ++--- infer/src/clang/cTL.ml | 2 +- 6 files changed, 38 insertions(+), 46 deletions(-) diff --git a/facebook-clang-plugins b/facebook-clang-plugins index cc047c7fa..d636cbdcb 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit cc047c7fa7a4899c95320e4a5520b2d469040344 +Subproject commit d636cbdcb7698111da50c85cc724d9740b78310b diff --git a/infer/src/clang/CType_decl.ml b/infer/src/clang/CType_decl.ml index 715063239..c99f89b54 100644 --- a/infer/src/clang/CType_decl.ml +++ b/infer/src/clang/CType_decl.ml @@ -19,22 +19,14 @@ let add_predefined_objc_types tenv = let add_predefined_types tenv = add_predefined_objc_types tenv -let create_c_record_typename opt_type = - match opt_type with - | `Type s - -> ( - let buf = Str.split (Str.regexp "[ \t]+") s in - match buf with - | "struct" :: _ - -> Typ.Name.C.from_qual_name - | "class" :: _ - -> Typ.Name.Cpp.from_qual_name Typ.NoTemplate - | "union" :: _ - -> Typ.Name.C.union_from_qual_name - | _ - -> Typ.Name.C.from_qual_name ) - | _ - -> assert false +let create_c_record_typename (tag_kind: Clang_ast_t.tag_kind) = + match tag_kind with + | `TTK_Struct | `TTK_Interface | `TTK_Enum + -> Typ.Name.C.from_qual_name + | `TTK_Union + -> Typ.Name.C.union_from_qual_name + | `TTK_Class + -> Typ.Name.Cpp.from_qual_name Typ.NoTemplate let get_class_template_name = function | Clang_ast_t.ClassTemplateDecl (_, name_info, _) @@ -109,9 +101,9 @@ let rec get_struct_fields tenv decl = let open Clang_ast_t in let decl_list = match decl with - | ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) - | CXXRecordDecl (_, _, _, _, decl_list, _, _, _) - | RecordDecl (_, _, _, _, decl_list, _, _) + | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _) + | CXXRecordDecl (_, _, _, decl_list, _, _, _, _) + | RecordDecl (_, _, _, decl_list, _, _, _) -> decl_list | _ -> [] @@ -148,8 +140,8 @@ and get_record_custom_type tenv definition_decl = and get_record_friend_decl_type tenv definition_decl = let open Clang_ast_t in match definition_decl with - | ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) - | CXXRecordDecl (_, _, _, _, decl_list, _, _, _) + | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _) + | CXXRecordDecl (_, _, _, decl_list, _, _, _, _) -> Option.map ~f:(qual_type_to_sil_type tenv) (get_translate_as_friend_decl decl_list) | _ -> None @@ -178,8 +170,8 @@ and get_record_typename ?tenv decl = let open Clang_ast_t in let linters_mode = match tenv with Some _ -> false | None -> true in match (decl, tenv) with - | RecordDecl (_, name_info, opt_type, _, _, _, _), _ - -> CAst_utils.get_qualified_name ~linters_mode name_info |> create_c_record_typename opt_type + | RecordDecl (_, name_info, _, _, _, tag_kind, _), _ + -> CAst_utils.get_qualified_name ~linters_mode name_info |> create_c_record_typename tag_kind | ClassTemplateSpecializationDecl (_, _, _, _, _, _, _, _, mangling, spec_info), Some tenv -> let tname = match CAst_utils.get_decl spec_info.tsi_template_decl with @@ -220,9 +212,9 @@ and get_superclass_list_cpp tenv decl = and get_record_struct_type tenv definition_decl : Typ.desc = let open Clang_ast_t in match definition_decl with - | ClassTemplateSpecializationDecl (_, _, _, type_ptr, _, _, record_decl_info, _, _, _) - | CXXRecordDecl (_, _, _, type_ptr, _, _, record_decl_info, _) - | RecordDecl (_, _, _, type_ptr, _, _, record_decl_info) + | ClassTemplateSpecializationDecl (_, _, type_ptr, _, _, _, record_decl_info, _, _, _) + | CXXRecordDecl (_, _, type_ptr, _, _, _, record_decl_info, _) + | RecordDecl (_, _, type_ptr, _, _, _, record_decl_info) -> ( let sil_typename = get_record_typename ~tenv definition_decl in let sil_desc = Typ.Tstruct sil_typename in diff --git a/infer/src/clang/cAst_utils.ml b/infer/src/clang/cAst_utils.ml index 74cb82ee2..4a3f30191 100644 --- a/infer/src/clang/cAst_utils.ml +++ b/infer/src/clang/cAst_utils.ml @@ -165,7 +165,7 @@ let sil_annot_of_type {Clang_ast_t.qt_type_ptr} = let name_of_typedef_type_info {Clang_ast_t.tti_decl_ptr} = match get_decl tti_decl_ptr with - | Some TypedefDecl (_, name_decl_info, _, _, _) + | Some TypedefDecl (_, name_decl_info, _, _) -> get_qualified_name name_decl_info | _ -> QualifiedCppName.empty @@ -422,16 +422,16 @@ let type_of_decl decl = -> Some obj_c_method_decl_info.omdi_result_type.qt_type_ptr | ObjCPropertyDecl (_, _, obj_c_property_decl_info) -> Some obj_c_property_decl_info.opdi_qual_type.qt_type_ptr - | EnumDecl (_, _, _, type_ptr, _, _, _) - | RecordDecl (_, _, _, type_ptr, _, _, _) - | CXXRecordDecl (_, _, _, type_ptr, _, _, _, _) - | ClassTemplateSpecializationDecl (_, _, _, type_ptr, _, _, _, _, _, _) - | ClassTemplatePartialSpecializationDecl (_, _, _, type_ptr, _, _, _, _, _, _) - | TemplateTypeParmDecl (_, _, _, type_ptr) - | ObjCTypeParamDecl (_, _, _, type_ptr) - | TypeAliasDecl (_, _, _, type_ptr) - | TypedefDecl (_, _, _, type_ptr, _) - | UnresolvedUsingTypenameDecl (_, _, _, type_ptr) + | EnumDecl (_, _, type_ptr, _, _, _, _) + | RecordDecl (_, _, type_ptr, _, _, _, _) + | CXXRecordDecl (_, _, type_ptr, _, _, _, _, _) + | ClassTemplateSpecializationDecl (_, _, type_ptr, _, _, _, _, _, _, _) + | ClassTemplatePartialSpecializationDecl (_, _, type_ptr, _, _, _, _, _, _, _) + | TemplateTypeParmDecl (_, _, type_ptr) + | ObjCTypeParamDecl (_, _, type_ptr) + | TypeAliasDecl (_, _, type_ptr) + | TypedefDecl (_, _, type_ptr, _) + | UnresolvedUsingTypenameDecl (_, _, type_ptr) -> Some type_ptr | BindingDecl (_, _, qual_type) | FieldDecl (_, _, qual_type, _) @@ -462,9 +462,9 @@ let type_of_decl decl = let get_record_fields decl = let open Clang_ast_t in match decl with - | ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) - | CXXRecordDecl (_, _, _, _, decl_list, _, _, _) - | RecordDecl (_, _, _, _, decl_list, _, _) + | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _) + | CXXRecordDecl (_, _, _, decl_list, _, _, _, _) + | RecordDecl (_, _, _, decl_list, _, _, _) -> List.filter ~f:(function FieldDecl _ -> true | _ -> false) decl_list | _ -> [] diff --git a/infer/src/clang/cEnum_decl.ml b/infer/src/clang/cEnum_decl.ml index 662fefbea..a50c4e68d 100644 --- a/infer/src/clang/cEnum_decl.ml +++ b/infer/src/clang/cEnum_decl.ml @@ -46,7 +46,7 @@ let enum_decl decl = -> () in match decl with - | EnumDecl (_, _, _, type_ptr, decl_list, _, _) + | EnumDecl (_, _, type_ptr, decl_list, _, _, _) -> add_enum_constants_to_map (List.rev decl_list) ; let sil_desc = Typ.Tint Typ.IInt in CAst_utils.update_sil_types_map type_ptr sil_desc ; sil_desc diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index 8857e6062..d07a344e7 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -310,9 +310,9 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron (* Note that C and C++ records are treated the same way Skip translating implicit struct declarations, unless they have full definition (which happens with C++ lambdas) *) - | ClassTemplateSpecializationDecl (di, _, _, _, decl_list, _, rdi, _, _, _) - | CXXRecordDecl (di, _, _, _, decl_list, _, rdi, _) - | RecordDecl (di, _, _, _, decl_list, _, rdi) + | ClassTemplateSpecializationDecl (di, _, _, decl_list, _, _, rdi, _, _, _) + | CXXRecordDecl (di, _, _, decl_list, _, _, rdi, _) + | RecordDecl (di, _, _, decl_list, _, _, rdi) when not di.di_is_implicit || rdi.rdi_is_complete_definition -> let is_method_decl decl = match decl with diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 87a0a352d..2d6fedd46 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -724,7 +724,7 @@ let transition_via_parameter_name an name = let transition_via_fields an = let open Clang_ast_t in match an with - | Decl RecordDecl (_, _, _, _, decls, _, _) | Decl CXXRecordDecl (_, _, _, _, decls, _, _, _) + | Decl RecordDecl (_, _, _, decls, _, _, _) | Decl CXXRecordDecl (_, _, _, decls, _, _, _, _) -> List.filter_map ~f:(fun d -> match d with FieldDecl _ -> Some (Decl d) | _ -> None) decls | Stmt InitListExpr (_, stmts, _) -> List.map ~f:(fun stmt -> Stmt stmt) stmts