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
diff --git a/lldb/source/Symbol/GoASTContext.cpp b/lldb/source/Symbol/GoASTContext.cpp
index 2061ee9..2797f39 100644
--- a/lldb/source/Symbol/GoASTContext.cpp
+++ b/lldb/source/Symbol/GoASTContext.cpp
@@ -11,10 +11,13 @@
#include <utility>
#include <vector>
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
#include "lldb/Core/UniqueCStringMap.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/StringPrinter.h"
#include "lldb/Symbol/CompilerType.h"
+#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/GoASTContext.h"
#include "lldb/Symbol/Type.h"
@@ -295,6 +298,59 @@
{
}
+//------------------------------------------------------------------
+// PluginInterface functions
+//------------------------------------------------------------------
+
+ConstString
+GoASTContext::GetPluginNameStatic()
+{
+ return ConstString("go");
+}
+
+ConstString
+GoASTContext::GetPluginName()
+{
+ return GoASTContext::GetPluginNameStatic();
+}
+
+uint32_t
+GoASTContext::GetPluginVersion()
+{
+ return 1;
+}
+
+lldb::TypeSystemSP
+GoASTContext::CreateInstance (lldb::LanguageType language, const lldb_private::ArchSpec &arch)
+{
+ if (language == eLanguageTypeGo)
+ {
+ if (arch.IsValid())
+ {
+ std::shared_ptr<GoASTContext> go_ast_sp(new GoASTContext);
+ go_ast_sp->SetAddressByteSize(arch.GetAddressByteSize());
+ return go_ast_sp;
+ }
+ }
+ return lldb::TypeSystemSP();
+}
+
+
+void
+GoASTContext::Initialize()
+{
+ PluginManager::RegisterPlugin (GetPluginNameStatic(),
+ "AST context plug-in",
+ CreateInstance);
+}
+
+void
+GoASTContext::Terminate()
+{
+ PluginManager::UnregisterPlugin (CreateInstance);
+}
+
+
//----------------------------------------------------------------------
// Tests
//----------------------------------------------------------------------
@@ -548,6 +604,12 @@
return static_cast<GoType *>(type)->GetGoKind() == GoType::KIND_LLDB_VOID;
}
+bool
+GoASTContext::SupportsLanguage (lldb::LanguageType language)
+{
+ return language == eLanguageTypeGo;
+}
+
//----------------------------------------------------------------------
// Type Completion
//----------------------------------------------------------------------
@@ -829,11 +891,9 @@
return CompilerType();
}
-CompilerType GoASTContext::GetIntTypeFromBitSize (size_t bit_size, bool is_signed)
-{
- return CompilerType();
-}
-CompilerType GoASTContext::GetFloatTypeFromBitSize (size_t bit_size)
+CompilerType
+GoASTContext::GetBuiltinTypeForEncodingAndBitSize (lldb::Encoding encoding,
+ size_t bit_size)
{
return CompilerType();
}
@@ -1306,7 +1366,7 @@
}
CompilerType
-GoASTContext::CreateTypedef(int kind, const ConstString &name, CompilerType impl)
+GoASTContext::CreateTypedefType(int kind, const ConstString &name, CompilerType impl)
{
GoType *type = new GoElem(kind, name, impl);
(*m_types)[name].reset(type);