[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
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent ece8678417
commit cb8e75be85

@ -1 +1 @@
Subproject commit cc047c7fa7a4899c95320e4a5520b2d469040344 Subproject commit d636cbdcb7698111da50c85cc724d9740b78310b

@ -19,22 +19,14 @@ let add_predefined_objc_types tenv =
let add_predefined_types tenv = add_predefined_objc_types tenv let add_predefined_types tenv = add_predefined_objc_types tenv
let create_c_record_typename opt_type = let create_c_record_typename (tag_kind: Clang_ast_t.tag_kind) =
match opt_type with match tag_kind with
| `Type s | `TTK_Struct | `TTK_Interface | `TTK_Enum
-> ( -> Typ.Name.C.from_qual_name
let buf = Str.split (Str.regexp "[ \t]+") s in | `TTK_Union
match buf with -> Typ.Name.C.union_from_qual_name
| "struct" :: _ | `TTK_Class
-> Typ.Name.C.from_qual_name -> Typ.Name.Cpp.from_qual_name Typ.NoTemplate
| "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 get_class_template_name = function let get_class_template_name = function
| Clang_ast_t.ClassTemplateDecl (_, name_info, _) | Clang_ast_t.ClassTemplateDecl (_, name_info, _)
@ -109,9 +101,9 @@ let rec get_struct_fields tenv decl =
let open Clang_ast_t in let open Clang_ast_t in
let decl_list = let decl_list =
match decl with match decl with
| ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _)
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | CXXRecordDecl (_, _, _, decl_list, _, _, _, _)
| RecordDecl (_, _, _, _, decl_list, _, _) | RecordDecl (_, _, _, decl_list, _, _, _)
-> 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 = and get_record_friend_decl_type tenv definition_decl =
let open Clang_ast_t in let open Clang_ast_t in
match definition_decl with match definition_decl with
| ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _)
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | CXXRecordDecl (_, _, _, decl_list, _, _, _, _)
-> Option.map ~f:(qual_type_to_sil_type tenv) (get_translate_as_friend_decl decl_list) -> Option.map ~f:(qual_type_to_sil_type tenv) (get_translate_as_friend_decl decl_list)
| _ | _
-> None -> None
@ -178,8 +170,8 @@ and get_record_typename ?tenv decl =
let open Clang_ast_t in let open Clang_ast_t in
let linters_mode = match tenv with Some _ -> false | None -> true in let linters_mode = match tenv with Some _ -> false | None -> true in
match (decl, tenv) with match (decl, tenv) with
| RecordDecl (_, name_info, opt_type, _, _, _, _), _ | RecordDecl (_, name_info, _, _, _, tag_kind, _), _
-> CAst_utils.get_qualified_name ~linters_mode name_info |> create_c_record_typename opt_type -> CAst_utils.get_qualified_name ~linters_mode name_info |> create_c_record_typename tag_kind
| ClassTemplateSpecializationDecl (_, _, _, _, _, _, _, _, mangling, spec_info), Some tenv | ClassTemplateSpecializationDecl (_, _, _, _, _, _, _, _, mangling, spec_info), Some tenv
-> let tname = -> let tname =
match CAst_utils.get_decl spec_info.tsi_template_decl with 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 = and get_record_struct_type tenv definition_decl : Typ.desc =
let open Clang_ast_t in let open Clang_ast_t in
match definition_decl with match definition_decl with
| ClassTemplateSpecializationDecl (_, _, _, type_ptr, _, _, record_decl_info, _, _, _) | ClassTemplateSpecializationDecl (_, _, type_ptr, _, _, _, record_decl_info, _, _, _)
| CXXRecordDecl (_, _, _, type_ptr, _, _, record_decl_info, _) | CXXRecordDecl (_, _, type_ptr, _, _, _, record_decl_info, _)
| RecordDecl (_, _, _, type_ptr, _, _, record_decl_info) | RecordDecl (_, _, type_ptr, _, _, _, record_decl_info)
-> ( -> (
let sil_typename = get_record_typename ~tenv definition_decl in let sil_typename = get_record_typename ~tenv definition_decl in
let sil_desc = Typ.Tstruct sil_typename in let sil_desc = Typ.Tstruct sil_typename in

@ -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} = let name_of_typedef_type_info {Clang_ast_t.tti_decl_ptr} =
match get_decl tti_decl_ptr with match get_decl tti_decl_ptr with
| Some TypedefDecl (_, name_decl_info, _, _, _) | Some TypedefDecl (_, name_decl_info, _, _)
-> get_qualified_name name_decl_info -> get_qualified_name name_decl_info
| _ | _
-> QualifiedCppName.empty -> QualifiedCppName.empty
@ -422,16 +422,16 @@ let type_of_decl decl =
-> Some obj_c_method_decl_info.omdi_result_type.qt_type_ptr -> Some obj_c_method_decl_info.omdi_result_type.qt_type_ptr
| ObjCPropertyDecl (_, _, obj_c_property_decl_info) | ObjCPropertyDecl (_, _, obj_c_property_decl_info)
-> Some obj_c_property_decl_info.opdi_qual_type.qt_type_ptr -> Some obj_c_property_decl_info.opdi_qual_type.qt_type_ptr
| EnumDecl (_, _, _, type_ptr, _, _, _) | EnumDecl (_, _, type_ptr, _, _, _, _)
| RecordDecl (_, _, _, type_ptr, _, _, _) | RecordDecl (_, _, type_ptr, _, _, _, _)
| CXXRecordDecl (_, _, _, type_ptr, _, _, _, _) | CXXRecordDecl (_, _, type_ptr, _, _, _, _, _)
| ClassTemplateSpecializationDecl (_, _, _, type_ptr, _, _, _, _, _, _) | ClassTemplateSpecializationDecl (_, _, type_ptr, _, _, _, _, _, _, _)
| ClassTemplatePartialSpecializationDecl (_, _, _, type_ptr, _, _, _, _, _, _) | ClassTemplatePartialSpecializationDecl (_, _, type_ptr, _, _, _, _, _, _, _)
| TemplateTypeParmDecl (_, _, _, type_ptr) | TemplateTypeParmDecl (_, _, type_ptr)
| ObjCTypeParamDecl (_, _, _, type_ptr) | ObjCTypeParamDecl (_, _, type_ptr)
| TypeAliasDecl (_, _, _, type_ptr) | TypeAliasDecl (_, _, type_ptr)
| TypedefDecl (_, _, _, type_ptr, _) | TypedefDecl (_, _, type_ptr, _)
| UnresolvedUsingTypenameDecl (_, _, _, type_ptr) | UnresolvedUsingTypenameDecl (_, _, type_ptr)
-> Some type_ptr -> Some type_ptr
| BindingDecl (_, _, qual_type) | BindingDecl (_, _, qual_type)
| FieldDecl (_, _, qual_type, _) | FieldDecl (_, _, qual_type, _)
@ -462,9 +462,9 @@ let type_of_decl decl =
let get_record_fields decl = let get_record_fields decl =
let open Clang_ast_t in let open Clang_ast_t in
match decl with match decl with
| ClassTemplateSpecializationDecl (_, _, _, _, decl_list, _, _, _, _, _) | ClassTemplateSpecializationDecl (_, _, _, decl_list, _, _, _, _, _, _)
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | CXXRecordDecl (_, _, _, decl_list, _, _, _, _)
| RecordDecl (_, _, _, _, decl_list, _, _) | RecordDecl (_, _, _, decl_list, _, _, _)
-> List.filter ~f:(function FieldDecl _ -> true | _ -> false) decl_list -> List.filter ~f:(function FieldDecl _ -> true | _ -> false) decl_list
| _ | _
-> [] -> []

@ -46,7 +46,7 @@ let enum_decl decl =
-> () -> ()
in in
match decl with match decl with
| EnumDecl (_, _, _, type_ptr, decl_list, _, _) | EnumDecl (_, _, type_ptr, decl_list, _, _, _)
-> add_enum_constants_to_map (List.rev decl_list) ; -> add_enum_constants_to_map (List.rev decl_list) ;
let sil_desc = Typ.Tint Typ.IInt in let sil_desc = Typ.Tint Typ.IInt in
CAst_utils.update_sil_types_map type_ptr sil_desc ; sil_desc CAst_utils.update_sil_types_map type_ptr sil_desc ; sil_desc

@ -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 (* Note that C and C++ records are treated the same way
Skip translating implicit struct declarations, unless they have Skip translating implicit struct declarations, unless they have
full definition (which happens with C++ lambdas) *) full definition (which happens with C++ lambdas) *)
| ClassTemplateSpecializationDecl (di, _, _, _, decl_list, _, rdi, _, _, _) | ClassTemplateSpecializationDecl (di, _, _, decl_list, _, _, rdi, _, _, _)
| CXXRecordDecl (di, _, _, _, decl_list, _, rdi, _) | CXXRecordDecl (di, _, _, decl_list, _, _, rdi, _)
| RecordDecl (di, _, _, _, decl_list, _, rdi) | RecordDecl (di, _, _, decl_list, _, _, rdi)
when not di.di_is_implicit || rdi.rdi_is_complete_definition when not di.di_is_implicit || rdi.rdi_is_complete_definition
-> let is_method_decl decl = -> let is_method_decl decl =
match decl with match decl with

@ -724,7 +724,7 @@ let transition_via_parameter_name an name =
let transition_via_fields an = let transition_via_fields an =
let open Clang_ast_t in let open Clang_ast_t in
match an with 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 -> List.filter_map ~f:(fun d -> match d with FieldDecl _ -> Some (Decl d) | _ -> None) decls
| Stmt InitListExpr (_, stmts, _) | Stmt InitListExpr (_, stmts, _)
-> List.map ~f:(fun stmt -> Stmt stmt) stmts -> List.map ~f:(fun stmt -> Stmt stmt) stmts

Loading…
Cancel
Save