mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
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
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "lldb/Core/Log.h"
|
||||
#include "lldb/Core/ModuleList.h"
|
||||
#include "lldb/Core/ModuleSpec.h"
|
||||
#include "lldb/Core/PluginManager.h"
|
||||
#include "lldb/Core/RegularExpression.h"
|
||||
#include "lldb/Core/Section.h"
|
||||
#include "lldb/Core/StreamString.h"
|
||||
@@ -23,17 +24,16 @@
|
||||
#include "lldb/Host/Symbols.h"
|
||||
#include "lldb/Interpreter/CommandInterpreter.h"
|
||||
#include "lldb/Interpreter/ScriptInterpreter.h"
|
||||
#include "lldb/Symbol/ClangASTContext.h"
|
||||
#include "lldb/Symbol/CompileUnit.h"
|
||||
#include "lldb/Symbol/GoASTContext.h"
|
||||
#include "lldb/Symbol/ObjectFile.h"
|
||||
#include "lldb/Symbol/SymbolContext.h"
|
||||
#include "lldb/Symbol/SymbolFile.h"
|
||||
#include "lldb/Symbol/SymbolVendor.h"
|
||||
#include "lldb/Symbol/TypeSystem.h"
|
||||
#include "lldb/Target/Language.h"
|
||||
#include "lldb/Target/Process.h"
|
||||
#include "lldb/Target/SectionLoadList.h"
|
||||
#include "lldb/Target/Target.h"
|
||||
#include "lldb/Symbol/SymbolFile.h"
|
||||
#include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
|
||||
#include "Plugins/Language/ObjC/ObjCLanguage.h"
|
||||
|
||||
@@ -148,14 +148,12 @@ Module::Module (const ModuleSpec &module_spec) :
|
||||
m_object_mod_time (),
|
||||
m_objfile_sp (),
|
||||
m_symfile_ap (),
|
||||
m_ast (new ClangASTContext),
|
||||
m_go_ast(),
|
||||
m_type_system_map(),
|
||||
m_source_mappings (),
|
||||
m_sections_ap(),
|
||||
m_did_load_objfile (false),
|
||||
m_did_load_symbol_vendor (false),
|
||||
m_did_parse_uuid (false),
|
||||
m_did_init_ast (false),
|
||||
m_file_has_changed (false),
|
||||
m_first_file_changed_log (false)
|
||||
{
|
||||
@@ -253,14 +251,12 @@ Module::Module(const FileSpec& file_spec,
|
||||
m_object_mod_time (),
|
||||
m_objfile_sp (),
|
||||
m_symfile_ap (),
|
||||
m_ast (new ClangASTContext),
|
||||
m_go_ast(),
|
||||
m_type_system_map(),
|
||||
m_source_mappings (),
|
||||
m_sections_ap(),
|
||||
m_did_load_objfile (false),
|
||||
m_did_load_symbol_vendor (false),
|
||||
m_did_parse_uuid (false),
|
||||
m_did_init_ast (false),
|
||||
m_file_has_changed (false),
|
||||
m_first_file_changed_log (false)
|
||||
{
|
||||
@@ -300,14 +296,12 @@ Module::Module () :
|
||||
m_object_mod_time (),
|
||||
m_objfile_sp (),
|
||||
m_symfile_ap (),
|
||||
m_ast (new ClangASTContext),
|
||||
m_go_ast(),
|
||||
m_type_system_map(),
|
||||
m_source_mappings (),
|
||||
m_sections_ap(),
|
||||
m_did_load_objfile (false),
|
||||
m_did_load_symbol_vendor (false),
|
||||
m_did_parse_uuid (false),
|
||||
m_did_init_ast (false),
|
||||
m_file_has_changed (false),
|
||||
m_first_file_changed_log (false)
|
||||
{
|
||||
@@ -424,64 +418,26 @@ Module::GetUUID()
|
||||
TypeSystem *
|
||||
Module::GetTypeSystemForLanguage (LanguageType language)
|
||||
{
|
||||
if (language == eLanguageTypeGo)
|
||||
{
|
||||
Mutex::Locker locker (m_mutex);
|
||||
if (!m_go_ast)
|
||||
{
|
||||
ObjectFile * objfile = GetObjectFile();
|
||||
ArchSpec object_arch;
|
||||
if (objfile && objfile->GetArchitecture(object_arch))
|
||||
{
|
||||
m_go_ast.reset(new GoASTContext);
|
||||
m_go_ast->SetAddressByteSize(object_arch.GetAddressByteSize());
|
||||
}
|
||||
}
|
||||
return m_go_ast.get();
|
||||
}
|
||||
else if (language != eLanguageTypeSwift)
|
||||
{
|
||||
// For now assume all languages except swift use the ClangASTContext for types
|
||||
return &GetClangASTContext();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
Mutex::Locker locker (m_mutex);
|
||||
TypeSystemMap::iterator pos = m_type_system_map.find(language);
|
||||
if (pos != m_type_system_map.end())
|
||||
return pos->second.get();
|
||||
|
||||
ClangASTContext &
|
||||
Module::GetClangASTContext ()
|
||||
{
|
||||
if (m_did_init_ast.load() == false)
|
||||
for (const auto &pair : m_type_system_map)
|
||||
{
|
||||
Mutex::Locker locker (m_mutex);
|
||||
if (m_did_init_ast.load() == false)
|
||||
if (pair.second && pair.second->SupportsLanguage(language))
|
||||
{
|
||||
ObjectFile * objfile = GetObjectFile();
|
||||
ArchSpec object_arch;
|
||||
if (objfile && objfile->GetArchitecture(object_arch))
|
||||
{
|
||||
m_did_init_ast = true;
|
||||
|
||||
// LLVM wants this to be set to iOS or MacOSX; if we're working on
|
||||
// a bare-boards type image, change the triple for llvm's benefit.
|
||||
if (object_arch.GetTriple().getVendor() == llvm::Triple::Apple
|
||||
&& object_arch.GetTriple().getOS() == llvm::Triple::UnknownOS)
|
||||
{
|
||||
if (object_arch.GetTriple().getArch() == llvm::Triple::arm ||
|
||||
object_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
|
||||
object_arch.GetTriple().getArch() == llvm::Triple::thumb)
|
||||
{
|
||||
object_arch.GetTriple().setOS(llvm::Triple::IOS);
|
||||
}
|
||||
else
|
||||
{
|
||||
object_arch.GetTriple().setOS(llvm::Triple::MacOSX);
|
||||
}
|
||||
}
|
||||
m_ast->SetArchitecture (object_arch);
|
||||
}
|
||||
// Add a new mapping for "language" to point to an already existing
|
||||
// TypeSystem that supports this language
|
||||
m_type_system_map[language] = pair.second;
|
||||
return pair.second.get();
|
||||
}
|
||||
}
|
||||
return *m_ast;
|
||||
|
||||
// Cache even if we get a shared pointer that contains null type system back
|
||||
lldb::TypeSystemSP type_system_sp = TypeSystem::CreateInstance (language, GetArchitecture());
|
||||
m_type_system_map[language] = type_system_sp;
|
||||
return type_system_sp.get();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user