Skip to content

Commit 56939cb

Browse files
author
Greg Clayton
committed
TypeSystem is now a plugin interface and removed any "ClangASTContext &Class::GetClangASTContext()" functions.
This cleans up type systems to be more pluggable. Prior to this we had issues: - Module, SymbolFile, and many others has "ClangASTContext &GetClangASTContext()" functions. All have been switched over to use "TypeSystem *GetTypeSystemForLanguage()" - Cleaned up any places that were using the GetClangASTContext() functions to use TypeSystem - Cleaned up Module so that it no longer has dedicated type system member variables: lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module. lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module. Now we have a type system map: typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap; TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module - Many places in code were using ClangASTContext static functions to place with CompilerType objects and add modifiers (const, volatile, restrict) and to make typedefs, L and R value references and more. These have been made into CompilerType functions that are abstract: class CompilerType { ... //---------------------------------------------------------------------- // Return a new CompilerType that is a L value reference to this type if // this type is valid and the type system supports L value references, // else return an invalid type. //---------------------------------------------------------------------- CompilerType GetLValueReferenceType () const; //---------------------------------------------------------------------- // Return a new CompilerType that is a R value reference to this type if // this type is valid and the type system supports R value references, // else return an invalid type. //---------------------------------------------------------------------- CompilerType GetRValueReferenceType () const; //---------------------------------------------------------------------- // Return a new CompilerType adds a const modifier to this type if // this type is valid and the type system supports const modifiers, // else return an invalid type. //---------------------------------------------------------------------- CompilerType AddConstModifier () const; //---------------------------------------------------------------------- // Return a new CompilerType adds a volatile modifier to this type if // this type is valid and the type system supports volatile modifiers, // else return an invalid type. //---------------------------------------------------------------------- CompilerType AddVolatileModifier () const; //---------------------------------------------------------------------- // Return a new CompilerType adds a restrict modifier to this type if // this type is valid and the type system supports restrict modifiers, // else return an invalid type. //---------------------------------------------------------------------- CompilerType AddRestrictModifier () const; //---------------------------------------------------------------------- // Create a typedef to this type using "name" as the name of the typedef // this type is valid and the type system supports typedefs, else return // an invalid type. //---------------------------------------------------------------------- CompilerType CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const; }; Other changes include: - Removed "CompilerType TypeSystem::GetIntTypeFromBitSize(...)" and CompilerType TypeSystem::GetFloatTypeFromBitSize(...) and replaced it with "CompilerType TypeSystem::GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size);" - Fixed code in Type.h to not request the full type for a type for no good reason, just request the forward type and let the type expand as needed llvm-svn: 247953
1 parent 6a51dbd commit 56939cb

40 files changed

+844
-361
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,6 @@ class Module :
944944
bool
945945
GetIsDynamicLinkEditor ();
946946

947-
ClangASTContext &
948-
GetClangASTContext ();
949-
950947
TypeSystem *
951948
GetTypeSystemForLanguage (lldb::LanguageType language);
952949

@@ -1101,6 +1098,7 @@ class Module :
11011098
bool &match_name_after_lookup);
11021099

11031100
protected:
1101+
typedef std::map<lldb::LanguageType, lldb::TypeSystemSP> TypeSystemMap;
11041102
//------------------------------------------------------------------
11051103
// Member Variables
11061104
//------------------------------------------------------------------
@@ -1119,15 +1117,13 @@ class Module :
11191117
lldb::SymbolVendorUP m_symfile_ap; ///< A pointer to the symbol vendor for this module.
11201118
std::vector<lldb::SymbolVendorUP> m_old_symfiles; ///< If anyone calls Module::SetSymbolFileFileSpec() and changes the symbol file,
11211119
///< we need to keep all old symbol files around in case anyone has type references to them
1122-
lldb::ClangASTContextUP m_ast; ///< The Clang AST context for this module.
1123-
lldb::GoASTContextUP m_go_ast; ///< The Go AST context for this module.
1120+
TypeSystemMap m_type_system_map; ///< A map of any type systems associated with this module
11241121
PathMappingList m_source_mappings; ///< Module specific source remappings for when you have debug info for a module that doesn't match where the sources currently are
11251122
lldb::SectionListUP m_sections_ap; ///< Unified section list for module that is used by the ObjectFile and and ObjectFile instances for the debug info
11261123

11271124
std::atomic<bool> m_did_load_objfile;
11281125
std::atomic<bool> m_did_load_symbol_vendor;
11291126
std::atomic<bool> m_did_parse_uuid;
1130-
std::atomic<bool> m_did_init_ast;
11311127
mutable bool m_file_has_changed:1,
11321128
m_first_file_changed_log:1; /// See if the module was modified after it was initially opened.
11331129

lldb/include/lldb/Core/PluginManager.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,22 @@ class PluginManager
419419
static InstrumentationRuntimeCreateInstance
420420
GetInstrumentationRuntimeCreateCallbackForPluginName (const ConstString &name);
421421

422+
//------------------------------------------------------------------
423+
// TypeSystem
424+
//------------------------------------------------------------------
425+
static bool
426+
RegisterPlugin (const ConstString &name,
427+
const char *description,
428+
TypeSystemCreateInstance create_callback);
429+
430+
static bool
431+
UnregisterPlugin (TypeSystemCreateInstance create_callback);
432+
433+
static TypeSystemCreateInstance
434+
GetTypeSystemCreateCallbackAtIndex (uint32_t idx);
435+
436+
static TypeSystemCreateInstance
437+
GetTypeSystemCreateCallbackForPluginName (const ConstString &name);
422438

423439
//------------------------------------------------------------------
424440
// Some plug-ins might register a DebuggerInitializeCallback

lldb/include/lldb/Symbol/ClangASTContext.h

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,28 @@ class ClangASTContext : public TypeSystem
5555
ClangASTContext (const char *triple = NULL);
5656

5757
~ClangASTContext() override;
58-
58+
59+
//------------------------------------------------------------------
60+
// PluginInterface functions
61+
//------------------------------------------------------------------
62+
ConstString
63+
GetPluginName() override;
64+
65+
uint32_t
66+
GetPluginVersion() override;
67+
68+
static ConstString
69+
GetPluginNameStatic ();
70+
71+
static lldb::TypeSystemSP
72+
CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch);
73+
74+
static void
75+
Initialize ();
76+
77+
static void
78+
Terminate ();
79+
5980
static ClangASTContext*
6081
GetASTContext (clang::ASTContext* ast_ctx);
6182

@@ -153,7 +174,7 @@ class ClangASTContext : public TypeSystem
153174
//------------------------------------------------------------------
154175
CompilerType
155176
GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
156-
uint32_t bit_size);
177+
size_t bit_size) override;
157178

158179
static CompilerType
159180
GetBuiltinTypeForEncodingAndBitSize (clang::ASTContext *ast,
@@ -448,13 +469,7 @@ class ClangASTContext : public TypeSystem
448469
//------------------------------------------------------------------
449470
// Integer type functions
450471
//------------------------------------------------------------------
451-
452-
CompilerType
453-
GetIntTypeFromBitSize (size_t bit_size, bool is_signed) override
454-
{
455-
return GetIntTypeFromBitSize (getASTContext(), bit_size, is_signed);
456-
}
457-
472+
458473
static CompilerType
459474
GetIntTypeFromBitSize (clang::ASTContext *ast,
460475
size_t bit_size, bool is_signed);
@@ -471,12 +486,6 @@ class ClangASTContext : public TypeSystem
471486
//------------------------------------------------------------------
472487
// Floating point functions
473488
//------------------------------------------------------------------
474-
475-
CompilerType
476-
GetFloatTypeFromBitSize (size_t bit_size) override
477-
{
478-
return GetFloatTypeFromBitSize (getASTContext(), bit_size);
479-
}
480489

481490
static CompilerType
482491
GetFloatTypeFromBitSize (clang::ASTContext *ast,
@@ -673,7 +682,10 @@ class ClangASTContext : public TypeSystem
673682

674683
bool
675684
IsVoidType (void *type) override;
676-
685+
686+
bool
687+
SupportsLanguage (lldb::LanguageType language) override;
688+
677689
static bool
678690
GetCXXClassName (const CompilerType& type, std::string &class_name);
679691

@@ -710,15 +722,6 @@ class ClangASTContext : public TypeSystem
710722
// Creating related types
711723
//----------------------------------------------------------------------
712724

713-
static CompilerType
714-
AddConstModifier (const CompilerType& type);
715-
716-
static CompilerType
717-
AddRestrictModifier (const CompilerType& type);
718-
719-
static CompilerType
720-
AddVolatileModifier (const CompilerType& type);
721-
722725
// Using the current type, create a new typedef to that type using "typedef_name"
723726
// as the name and "decl_ctx" as the decl context.
724727
static CompilerType
@@ -752,9 +755,6 @@ class ClangASTContext : public TypeSystem
752755
TypeMemberFunctionImpl
753756
GetMemberFunctionAtIndex (void *type, size_t idx) override;
754757

755-
static CompilerType
756-
GetLValueReferenceType (const CompilerType& type);
757-
758758
CompilerType
759759
GetNonReferenceType (void *type) override;
760760

@@ -763,10 +763,25 @@ class ClangASTContext : public TypeSystem
763763

764764
CompilerType
765765
GetPointerType (void *type) override;
766-
767-
static CompilerType
768-
GetRValueReferenceType (const CompilerType& type);
769-
766+
767+
CompilerType
768+
GetLValueReferenceType (void *type) override;
769+
770+
CompilerType
771+
GetRValueReferenceType (void *type) override;
772+
773+
CompilerType
774+
AddConstModifier (void *type) override;
775+
776+
CompilerType
777+
AddVolatileModifier (void *type) override;
778+
779+
CompilerType
780+
AddRestrictModifier (void *type) override;
781+
782+
CompilerType
783+
CreateTypedef (void *type, const char *name, const CompilerDeclContext &decl_ctx) override;
784+
770785
// If the current object represents a typedef type, get the underlying type
771786
CompilerType
772787
GetTypedefedType (void *type) override;
@@ -804,7 +819,10 @@ class ClangASTContext : public TypeSystem
804819

805820
uint32_t
806821
GetNumChildren (void *type, bool omit_empty_base_classes) override;
807-
822+
823+
CompilerType
824+
GetBuiltinTypeByName (const ConstString &name) override;
825+
808826
lldb::BasicType
809827
GetBasicTypeEnumeration (void *type) override;
810828

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,75 @@ class CompilerType
272272
TypeMemberFunctionImpl
273273
GetMemberFunctionAtIndex (size_t idx);
274274

275+
//----------------------------------------------------------------------
276+
// If this type is a reference to a type (L value or R value reference),
277+
// return a new type with the reference removed, else return the current
278+
// type itself.
279+
//----------------------------------------------------------------------
275280
CompilerType
276281
GetNonReferenceType () const;
277282

283+
//----------------------------------------------------------------------
284+
// If this type is a pointer type, return the type that the pointer
285+
// points to, else return an invalid type.
286+
//----------------------------------------------------------------------
278287
CompilerType
279288
GetPointeeType () const;
280289

290+
//----------------------------------------------------------------------
291+
// Return a new CompilerType that is a pointer to this type
292+
//----------------------------------------------------------------------
281293
CompilerType
282294
GetPointerType () const;
283295

296+
//----------------------------------------------------------------------
297+
// Return a new CompilerType that is a L value reference to this type if
298+
// this type is valid and the type system supports L value references,
299+
// else return an invalid type.
300+
//----------------------------------------------------------------------
301+
CompilerType
302+
GetLValueReferenceType () const;
303+
304+
//----------------------------------------------------------------------
305+
// Return a new CompilerType that is a R value reference to this type if
306+
// this type is valid and the type system supports R value references,
307+
// else return an invalid type.
308+
//----------------------------------------------------------------------
309+
CompilerType
310+
GetRValueReferenceType () const;
311+
312+
//----------------------------------------------------------------------
313+
// Return a new CompilerType adds a const modifier to this type if
314+
// this type is valid and the type system supports const modifiers,
315+
// else return an invalid type.
316+
//----------------------------------------------------------------------
317+
CompilerType
318+
AddConstModifier () const;
319+
320+
//----------------------------------------------------------------------
321+
// Return a new CompilerType adds a volatile modifier to this type if
322+
// this type is valid and the type system supports volatile modifiers,
323+
// else return an invalid type.
324+
//----------------------------------------------------------------------
325+
CompilerType
326+
AddVolatileModifier () const;
327+
328+
//----------------------------------------------------------------------
329+
// Return a new CompilerType adds a restrict modifier to this type if
330+
// this type is valid and the type system supports restrict modifiers,
331+
// else return an invalid type.
332+
//----------------------------------------------------------------------
333+
CompilerType
334+
AddRestrictModifier () const;
335+
336+
//----------------------------------------------------------------------
337+
// Create a typedef to this type using "name" as the name of the typedef
338+
// this type is valid and the type system supports typedefs, else return
339+
// an invalid type.
340+
//----------------------------------------------------------------------
341+
CompilerType
342+
CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const;
343+
284344
// If the current object represents a typedef type, get the underlying type
285345
CompilerType
286346
GetTypedefedType () const;

lldb/include/lldb/Symbol/GoASTContext.h

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ class GoASTContext : public TypeSystem
2727
GoASTContext();
2828
~GoASTContext();
2929

30+
//------------------------------------------------------------------
31+
// PluginInterface functions
32+
//------------------------------------------------------------------
33+
ConstString
34+
GetPluginName() override;
35+
36+
uint32_t
37+
GetPluginVersion() override;
38+
39+
static ConstString
40+
GetPluginNameStatic ();
41+
42+
static lldb::TypeSystemSP
43+
CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch);
44+
45+
static void
46+
Initialize ();
47+
48+
static void
49+
Terminate ();
50+
51+
3052
DWARFASTParser *GetDWARFParser() override;
3153

3254
void
@@ -101,7 +123,7 @@ class GoASTContext : public TypeSystem
101123
CompilerType CreateBaseType(int go_kind, const ConstString &type_name_const_str, uint64_t byte_size);
102124

103125
// For interface, map, chan.
104-
CompilerType CreateTypedef(int kind, const ConstString &name, CompilerType impl);
126+
CompilerType CreateTypedefType(int kind, const ConstString &name, CompilerType impl);
105127

106128
CompilerType CreateVoidType(const ConstString &name);
107129
CompilerType CreateFunctionType(const lldb_private::ConstString &name, CompilerType *params, size_t params_count,
@@ -124,37 +146,39 @@ class GoASTContext : public TypeSystem
124146
static bool IsDirectIface(uint8_t kind);
125147
static bool IsPointerKind(uint8_t kind);
126148

127-
virtual bool IsArrayType(void *type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) override;
149+
bool IsArrayType(void *type, CompilerType *element_type, uint64_t *size, bool *is_incomplete) override;
128150

129-
virtual bool IsAggregateType(void *type) override;
151+
bool IsAggregateType(void *type) override;
130152

131-
virtual bool IsCharType(void *type) override;
153+
bool IsCharType(void *type) override;
132154

133-
virtual bool IsCompleteType(void *type) override;
155+
bool IsCompleteType(void *type) override;
134156

135-
virtual bool IsDefined(void *type) override;
157+
bool IsDefined(void *type) override;
136158

137-
virtual bool IsFloatingPointType(void *type, uint32_t &count, bool &is_complex) override;
159+
bool IsFloatingPointType(void *type, uint32_t &count, bool &is_complex) override;
138160

139-
virtual bool IsFunctionType(void *type, bool *is_variadic_ptr = NULL) override;
161+
bool IsFunctionType(void *type, bool *is_variadic_ptr = NULL) override;
140162

141-
virtual size_t GetNumberOfFunctionArguments(void *type) override;
163+
size_t GetNumberOfFunctionArguments(void *type) override;
142164

143-
virtual CompilerType GetFunctionArgumentAtIndex(void *type, const size_t index) override;
165+
CompilerType GetFunctionArgumentAtIndex(void *type, const size_t index) override;
144166

145-
virtual bool IsFunctionPointerType(void *type) override;
167+
bool IsFunctionPointerType(void *type) override;
146168

147-
virtual bool IsIntegerType(void *type, bool &is_signed) override;
169+
bool IsIntegerType(void *type, bool &is_signed) override;
148170

149-
virtual bool IsPossibleDynamicType(void *type,
171+
bool IsPossibleDynamicType(void *type,
150172
CompilerType *target_type, // Can pass NULL
151173
bool check_cplusplus, bool check_objc) override;
152174

153-
virtual bool IsPointerType(void *type, CompilerType *pointee_type = NULL) override;
175+
bool IsPointerType(void *type, CompilerType *pointee_type = NULL) override;
176+
177+
bool IsScalarType(void *type) override;
154178

155-
virtual bool IsScalarType(void *type) override;
179+
bool IsVoidType(void *type) override;
156180

157-
virtual bool IsVoidType(void *type) override;
181+
bool SupportsLanguage (lldb::LanguageType language) override;
158182

159183
//----------------------------------------------------------------------
160184
// Type Completion
@@ -217,9 +241,9 @@ class GoASTContext : public TypeSystem
217241
virtual uint32_t GetNumChildren(void *type, bool omit_empty_base_classes) override;
218242

219243
virtual lldb::BasicType GetBasicTypeEnumeration(void *type) override;
220-
virtual CompilerType GetIntTypeFromBitSize (size_t bit_size, bool is_signed) override;
221-
virtual CompilerType GetFloatTypeFromBitSize (size_t bit_size) override;
222244

245+
virtual CompilerType GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
246+
size_t bit_size) override;
223247

224248
virtual uint32_t GetNumFields(void *type) override;
225249

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ class SymbolFile :
147147
virtual size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
148148
uint32_t type_mask,
149149
lldb_private::TypeList &type_list) = 0;
150-
virtual ClangASTContext &
151-
GetClangASTContext ();
152150

153151
virtual lldb_private::TypeSystem *
154152
GetTypeSystemForLanguage (lldb::LanguageType language);

0 commit comments

Comments
 (0)