2010-06-09 00:52:24 +08:00
//===-- ClangASTContext.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
2010-06-14 03:06:42 +08:00
# include "lldb/Symbol/ClangASTContext.h"
2010-06-09 00:52:24 +08:00
// C Includes
// C++ Includes
2015-02-03 10:05:44 +08:00
# include <mutex> // std::once
2010-06-09 00:52:24 +08:00
# include <string>
2015-10-09 07:07:53 +08:00
# include <vector>
2010-06-09 00:52:24 +08:00
// Other libraries and framework includes
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
// Clang headers like to use NDEBUG inside of them to enable/disable debug
2014-07-02 05:22:11 +08:00
// related features using "#ifndef NDEBUG" preprocessor blocks to do one thing
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
// or another. This is bad because it means that if clang was built in release
// mode, it assumes that you are building in release mode which is not always
// the case. You can end up with functions that are defined as empty in header
// files when NDEBUG is not defined, and this can cause link errors with the
// clang .a files that you have since you might be missing functions in the .a
// file. So we have to define NDEBUG when including clang headers to avoid any
// mismatches. This is covered by rdar://problem/8691220
2011-10-27 01:46:51 +08:00
# if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
# define LLDB_DEFINED_NDEBUG_FOR_CLANG
2010-07-09 02:16:16 +08:00
# define NDEBUG
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
// Need to include assert.h so it is as clang would expect it to be (disabled)
# include <assert.h>
# endif
2010-06-09 00:52:24 +08:00
# include "clang/AST/ASTContext.h"
# include "clang/AST/ASTImporter.h"
2012-12-04 02:29:55 +08:00
# include "clang/AST/Attr.h"
2010-06-09 00:52:24 +08:00
# include "clang/AST/CXXInheritance.h"
2010-07-23 02:30:50 +08:00
# include "clang/AST/DeclObjC.h"
2011-10-22 11:33:13 +08:00
# include "clang/AST/DeclTemplate.h"
2010-06-09 00:52:24 +08:00
# include "clang/AST/RecordLayout.h"
# include "clang/AST/Type.h"
2015-08-12 05:38:15 +08:00
# include "clang/AST/VTableBuilder.h"
2010-06-09 00:52:24 +08:00
# include "clang/Basic/Builtins.h"
2012-02-07 05:28:03 +08:00
# include "clang/Basic/Diagnostic.h"
2010-06-09 00:52:24 +08:00
# include "clang/Basic/FileManager.h"
2010-11-18 10:56:27 +08:00
# include "clang/Basic/FileSystemOptions.h"
2010-06-09 00:52:24 +08:00
# include "clang/Basic/SourceManager.h"
# include "clang/Basic/TargetInfo.h"
# include "clang/Basic/TargetOptions.h"
# include "clang/Frontend/FrontendOptions.h"
# include "clang/Frontend/LangStandard.h"
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
# ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
2010-07-09 02:16:16 +08:00
# undef NDEBUG
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
# undef LLDB_DEFINED_NDEBUG_FOR_CLANG
// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
# include <assert.h>
# endif
2010-06-09 00:52:24 +08:00
2015-08-12 05:38:15 +08:00
# include "llvm/Support/Signals.h"
2011-02-16 05:59:32 +08:00
# include "lldb/Core/ArchSpec.h"
2010-10-27 11:32:59 +08:00
# include "lldb/Core/Flags.h"
2010-10-29 02:19:36 +08:00
# include "lldb/Core/Log.h"
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
2015-09-18 06:23:34 +08:00
# include "lldb/Core/Module.h"
# include "lldb/Core/PluginManager.h"
2011-10-22 11:33:13 +08:00
# include "lldb/Core/RegularExpression.h"
2015-08-12 05:38:15 +08:00
# include "lldb/Core/StreamFile.h"
2014-09-17 01:28:40 +08:00
# include "lldb/Core/ThreadSafeDenseMap.h"
2013-07-12 06:46:58 +08:00
# include "lldb/Core/UniqueCStringMap.h"
2015-09-26 04:35:58 +08:00
# include "Plugins/ExpressionParser/Clang/ClangUserExpression.h"
# include "Plugins/ExpressionParser/Clang/ClangFunctionCaller.h"
# include "Plugins/ExpressionParser/Clang/ClangUtilityFunction.h"
2015-08-12 05:38:15 +08:00
# include "lldb/Symbol/ClangASTContext.h"
2015-08-19 06:32:36 +08:00
# include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
2011-12-03 11:15:28 +08:00
# include "lldb/Symbol/ClangExternalASTSourceCommon.h"
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
2015-09-18 06:23:34 +08:00
# include "lldb/Symbol/ObjectFile.h"
2015-08-28 09:01:03 +08:00
# include "lldb/Symbol/SymbolFile.h"
2011-10-26 09:06:27 +08:00
# include "lldb/Symbol/VerifyDecl.h"
2011-06-25 06:03:24 +08:00
# include "lldb/Target/ExecutionContext.h"
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
2015-09-18 06:23:34 +08:00
# include "lldb/Target/Language.h"
2011-06-25 06:03:24 +08:00
# include "lldb/Target/ObjCLanguageRuntime.h"
2015-09-16 05:13:50 +08:00
# include "lldb/Target/Process.h"
# include "lldb/Target/Target.h"
2011-06-25 06:03:24 +08:00
2015-08-28 09:01:03 +08:00
# include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
2010-06-14 03:06:42 +08:00
# include <stdio.h>
2013-07-12 07:36:31 +08:00
# include <mutex>
2010-08-05 09:57:25 +08:00
using namespace lldb ;
2010-06-09 00:52:24 +08:00
using namespace lldb_private ;
using namespace llvm ;
using namespace clang ;
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
2015-09-18 06:23:34 +08:00
namespace
{
static inline bool ClangASTContextSupportsLanguage ( lldb : : LanguageType language )
{
return language = = eLanguageTypeUnknown | | // Clang is the default type system
Language : : LanguageIsC ( language ) | |
Language : : LanguageIsCPlusPlus ( language ) | |
Language : : LanguageIsObjC ( language ) ;
}
}
2014-09-17 01:28:40 +08:00
typedef lldb_private : : ThreadSafeDenseMap < clang : : ASTContext * , ClangASTContext * > ClangASTMap ;
2014-08-20 05:46:37 +08:00
static ClangASTMap &
GetASTMap ( )
{
2014-09-17 01:28:40 +08:00
static ClangASTMap * g_map_ptr = nullptr ;
static std : : once_flag g_once_flag ;
std : : call_once ( g_once_flag , [ ] ( ) {
g_map_ptr = new ClangASTMap ( ) ; // leaked on purpose to avoid spins
} ) ;
return * g_map_ptr ;
2014-08-20 05:46:37 +08:00
}
2013-07-12 06:46:58 +08:00
clang : : AccessSpecifier
ClangASTContext : : ConvertAccessTypeToAccessSpecifier ( AccessType access )
2010-07-23 02:30:50 +08:00
{
switch ( access )
{
2010-08-05 09:57:25 +08:00
default : break ;
case eAccessNone : return AS_none ;
case eAccessPublic : return AS_public ;
case eAccessPrivate : return AS_private ;
case eAccessProtected : return AS_protected ;
2010-07-23 02:30:50 +08:00
}
return AS_none ;
}
2010-06-09 00:52:24 +08:00
static void
2015-03-31 18:21:50 +08:00
ParseLangArgs ( LangOptions & Opts , InputKind IK , const char * triple )
2010-06-09 00:52:24 +08:00
{
// FIXME: Cleanup per-file based stuff.
2014-07-02 05:22:11 +08:00
// Set some properties which depend solely on the input kind; it would be nice
2010-06-09 00:52:24 +08:00
// to move these to the language standard, and have the driver resolve the
// input kind + language standard.
2010-06-14 01:34:29 +08:00
if ( IK = = IK_Asm ) {
2010-06-09 00:52:24 +08:00
Opts . AsmPreprocessor = 1 ;
2010-06-14 01:34:29 +08:00
} else if ( IK = = IK_ObjC | |
IK = = IK_ObjCXX | |
IK = = IK_PreprocessedObjC | |
IK = = IK_PreprocessedObjCXX ) {
2010-06-09 00:52:24 +08:00
Opts . ObjC1 = Opts . ObjC2 = 1 ;
}
LangStandard : : Kind LangStd = LangStandard : : lang_unspecified ;
if ( LangStd = = LangStandard : : lang_unspecified ) {
// Based on the base language, pick one.
switch ( IK ) {
2010-06-14 01:34:29 +08:00
case IK_None :
case IK_AST :
2011-03-15 08:17:19 +08:00
case IK_LLVM_IR :
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
assert ( ! " Invalid input kind! " ) ;
2010-06-14 01:34:29 +08:00
case IK_OpenCL :
2010-06-09 00:52:24 +08:00
LangStd = LangStandard : : lang_opencl ;
break ;
2011-03-15 08:17:19 +08:00
case IK_CUDA :
2015-03-20 02:12:26 +08:00
case IK_PreprocessedCuda :
2011-03-15 08:17:19 +08:00
LangStd = LangStandard : : lang_cuda ;
break ;
2010-06-14 01:34:29 +08:00
case IK_Asm :
case IK_C :
case IK_PreprocessedC :
case IK_ObjC :
case IK_PreprocessedObjC :
2010-06-09 00:52:24 +08:00
LangStd = LangStandard : : lang_gnu99 ;
break ;
2010-06-14 01:34:29 +08:00
case IK_CXX :
case IK_PreprocessedCXX :
case IK_ObjCXX :
case IK_PreprocessedObjCXX :
2010-06-09 00:52:24 +08:00
LangStd = LangStandard : : lang_gnucxx98 ;
break ;
}
}
const LangStandard & Std = LangStandard : : getLangStandardForKind ( LangStd ) ;
2012-11-13 05:26:32 +08:00
Opts . LineComment = Std . hasLineComments ( ) ;
2010-06-09 00:52:24 +08:00
Opts . C99 = Std . isC99 ( ) ;
Opts . CPlusPlus = Std . isCPlusPlus ( ) ;
2013-01-02 20:55:00 +08:00
Opts . CPlusPlus11 = Std . isCPlusPlus11 ( ) ;
2010-06-09 00:52:24 +08:00
Opts . Digraphs = Std . hasDigraphs ( ) ;
Opts . GNUMode = Std . isGNUMode ( ) ;
Opts . GNUInline = ! Std . isC99 ( ) ;
Opts . HexFloats = Std . hasHexFloats ( ) ;
Opts . ImplicitInt = Std . hasImplicitInt ( ) ;
2013-01-10 10:37:22 +08:00
Opts . WChar = true ;
2010-06-09 00:52:24 +08:00
// OpenCL has some additional defaults.
if ( LangStd = = LangStandard : : lang_opencl ) {
Opts . OpenCL = 1 ;
Opts . AltiVec = 1 ;
Opts . CXXOperatorNames = 1 ;
Opts . LaxVectorConversions = 1 ;
}
// OpenCL and C++ both have bool, true, false keywords.
Opts . Bool = Opts . OpenCL | | Opts . CPlusPlus ;
// if (Opts.CPlusPlus)
// Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names);
//
// if (Args.hasArg(OPT_fobjc_gc_only))
// Opts.setGCMode(LangOptions::GCOnly);
// else if (Args.hasArg(OPT_fobjc_gc))
// Opts.setGCMode(LangOptions::HybridGC);
//
// if (Args.hasArg(OPT_print_ivar_layout))
// Opts.ObjCGCBitmapPrint = 1;
//
// if (Args.hasArg(OPT_faltivec))
// Opts.AltiVec = 1;
//
// if (Args.hasArg(OPT_pthread))
// Opts.POSIXThreads = 1;
//
// llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility,
// "default");
// if (Vis == "default")
2013-02-20 03:16:37 +08:00
Opts . setValueVisibilityMode ( DefaultVisibility ) ;
2010-06-09 00:52:24 +08:00
// else if (Vis == "hidden")
// Opts.setVisibilityMode(LangOptions::Hidden);
// else if (Vis == "protected")
// Opts.setVisibilityMode(LangOptions::Protected);
// else
// Diags.Report(diag::err_drv_invalid_value)
// << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis;
// Opts.OverflowChecking = Args.hasArg(OPT_ftrapv);
// Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
// is specified, or -std is set to a conforming mode.
Opts . Trigraphs = ! Opts . GNUMode ;
// if (Args.hasArg(OPT_trigraphs))
// Opts.Trigraphs = 1;
//
// Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
// OPT_fno_dollars_in_identifiers,
// !Opts.AsmPreprocessor);
// Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
// Opts.Microsoft = Args.hasArg(OPT_fms_extensions);
// Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
// if (Args.hasArg(OPT_fno_lax_vector_conversions))
// Opts.LaxVectorConversions = 0;
// Opts.Exceptions = Args.hasArg(OPT_fexceptions);
// Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
// Opts.Blocks = Args.hasArg(OPT_fblocks);
2015-03-31 18:21:50 +08:00
Opts . CharIsSigned = ArchSpec ( triple ) . CharIsSignedByDefault ( ) ;
2010-06-09 00:52:24 +08:00
// Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar);
// Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
// Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
// Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
// Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
// Opts.AccessControl = Args.hasArg(OPT_faccess_control);
// Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);
// Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno);
// Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99,
// Diags);
// Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime);
// Opts.ObjCConstantStringClass = getLastArgValue(Args,
// OPT_fconstant_string_class);
// Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi);
// Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior);
// Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
// Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
// Opts.Static = Args.hasArg(OPT_static_define);
Opts . OptimizeSize = 0 ;
// FIXME: Eliminate this dependency.
// unsigned Opt =
// Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags);
// Opts.Optimize = Opt != 0;
unsigned Opt = 0 ;
// This is the __NO_INLINE__ define, which just depends on things like the
// optimization level and -fno-inline, not actually whether the backend has
// inlining enabled.
//
// FIXME: This is affected by other options (-fno-inline).
2012-09-25 06:25:51 +08:00
Opts . NoInlineDefine = ! Opt ;
2010-06-09 00:52:24 +08:00
// unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags);
// switch (SSP) {
// default:
// Diags.Report(diag::err_drv_invalid_value)
// << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
// break;
// case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break;
// case 1: Opts.setStackProtectorMode(LangOptions::SSPOn); break;
// case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break;
// }
}
2010-07-02 09:29:13 +08:00
2015-09-09 02:15:05 +08:00
ClangASTContext : : ClangASTContext ( const char * target_triple ) :
TypeSystem ( TypeSystem : : eKindClang ) ,
2015-08-19 06:32:36 +08:00
m_target_triple ( ) ,
m_ast_ap ( ) ,
m_language_options_ap ( ) ,
m_source_manager_ap ( ) ,
m_diagnostics_engine_ap ( ) ,
m_target_options_rp ( ) ,
m_target_info_ap ( ) ,
m_identifier_table_ap ( ) ,
m_selector_table_ap ( ) ,
m_builtins_ap ( ) ,
2014-04-20 21:17:36 +08:00
m_callback_tag_decl ( nullptr ) ,
m_callback_objc_decl ( nullptr ) ,
m_callback_baton ( nullptr ) ,
2015-08-12 05:38:15 +08:00
m_pointer_byte_size ( 0 ) ,
2015-08-28 09:01:03 +08:00
m_ast_owned ( false )
2010-06-09 00:52:24 +08:00
{
if ( target_triple & & target_triple [ 0 ] )
2011-07-30 09:26:02 +08:00
SetTargetTriple ( target_triple ) ;
2010-06-09 00:52:24 +08:00
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
ClangASTContext : : ~ ClangASTContext ( )
{
2014-08-20 05:46:37 +08:00
if ( m_ast_ap . get ( ) )
{
2014-09-17 01:28:40 +08:00
GetASTMap ( ) . Erase ( m_ast_ap . get ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! m_ast_owned )
m_ast_ap . release ( ) ;
2014-08-20 05:46:37 +08:00
}
2010-06-09 00:52:24 +08:00
m_builtins_ap . reset ( ) ;
m_selector_table_ap . reset ( ) ;
m_identifier_table_ap . reset ( ) ;
m_target_info_ap . reset ( ) ;
2012-10-18 06:11:14 +08:00
m_target_options_rp . reset ( ) ;
2011-10-08 07:18:13 +08:00
m_diagnostics_engine_ap . reset ( ) ;
2010-06-09 00:52:24 +08:00
m_source_manager_ap . reset ( ) ;
m_language_options_ap . reset ( ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
m_ast_ap . reset ( ) ;
2010-06-09 00:52:24 +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
2015-09-18 06:23:34 +08:00
ConstString
ClangASTContext : : GetPluginNameStatic ( )
{
return ConstString ( " clang " ) ;
}
ConstString
ClangASTContext : : GetPluginName ( )
{
return ClangASTContext : : GetPluginNameStatic ( ) ;
}
uint32_t
ClangASTContext : : GetPluginVersion ( )
{
return 1 ;
}
lldb : : TypeSystemSP
2015-10-09 20:06:10 +08:00
ClangASTContext : : CreateInstance ( lldb : : LanguageType language ,
lldb_private : : Module * module ,
Target * target )
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
2015-09-18 06:23:34 +08:00
{
if ( ClangASTContextSupportsLanguage ( language ) )
{
2015-10-09 05:04:34 +08:00
ArchSpec arch ;
if ( module )
arch = module - > GetArchitecture ( ) ;
else if ( target )
arch = target - > GetArchitecture ( ) ;
if ( arch . IsValid ( ) )
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
2015-09-18 06:23:34 +08:00
{
2015-10-09 05:04:34 +08:00
ArchSpec fixed_arch = arch ;
// 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 ( fixed_arch . GetTriple ( ) . getVendor ( ) = = llvm : : Triple : : Apple & &
fixed_arch . GetTriple ( ) . getOS ( ) = = llvm : : Triple : : UnknownOS )
{
if ( fixed_arch . GetTriple ( ) . getArch ( ) = = llvm : : Triple : : arm | |
fixed_arch . GetTriple ( ) . getArch ( ) = = llvm : : Triple : : aarch64 | |
fixed_arch . GetTriple ( ) . getArch ( ) = = llvm : : Triple : : thumb )
{
fixed_arch . GetTriple ( ) . setOS ( llvm : : Triple : : IOS ) ;
}
else
{
fixed_arch . GetTriple ( ) . setOS ( llvm : : Triple : : MacOSX ) ;
}
}
if ( module )
{
std : : shared_ptr < ClangASTContext > ast_sp ( new ClangASTContext ) ;
if ( ast_sp )
{
ast_sp - > SetArchitecture ( fixed_arch ) ;
}
return ast_sp ;
}
else if ( target )
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
2015-09-18 06:23:34 +08:00
{
2015-10-09 05:04:34 +08:00
std : : shared_ptr < ClangASTContextForExpressions > ast_sp ( new ClangASTContextForExpressions ( * target ) ) ;
if ( ast_sp )
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
2015-09-18 06:23:34 +08:00
{
2015-10-09 05:04:34 +08:00
ast_sp - > SetArchitecture ( fixed_arch ) ;
ast_sp - > m_scratch_ast_source_ap . reset ( new ClangASTSource ( target - > shared_from_this ( ) ) ) ;
ast_sp - > m_scratch_ast_source_ap - > InstallASTContext ( ast_sp - > getASTContext ( ) ) ;
llvm : : IntrusiveRefCntPtr < clang : : ExternalASTSource > proxy_ast_source ( ast_sp - > m_scratch_ast_source_ap - > CreateProxy ( ) ) ;
ast_sp - > SetExternalSource ( proxy_ast_source ) ;
return ast_sp ;
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
2015-09-18 06:23:34 +08:00
}
}
}
}
return lldb : : TypeSystemSP ( ) ;
}
2015-10-09 07:07:53 +08:00
void
ClangASTContext : : EnumerateSupportedLanguages ( std : : set < lldb : : LanguageType > & languages_for_types , std : : set < lldb : : LanguageType > & languages_for_expressions )
{
static std : : vector < lldb : : LanguageType > s_supported_languages_for_types ( {
lldb : : eLanguageTypeC89 ,
lldb : : eLanguageTypeC ,
lldb : : eLanguageTypeC11 ,
lldb : : eLanguageTypeC_plus_plus ,
lldb : : eLanguageTypeC99 ,
lldb : : eLanguageTypeObjC ,
lldb : : eLanguageTypeObjC_plus_plus ,
lldb : : eLanguageTypeC_plus_plus_03 ,
lldb : : eLanguageTypeC_plus_plus_11 ,
lldb : : eLanguageTypeC11 ,
lldb : : eLanguageTypeC_plus_plus_14 } ) ;
static std : : vector < lldb : : LanguageType > s_supported_languages_for_expressions ( {
lldb : : eLanguageTypeC_plus_plus ,
lldb : : eLanguageTypeObjC_plus_plus ,
lldb : : eLanguageTypeC_plus_plus_03 ,
lldb : : eLanguageTypeC_plus_plus_11 ,
lldb : : eLanguageTypeC_plus_plus_14 } ) ;
languages_for_types . insert ( s_supported_languages_for_types . begin ( ) , s_supported_languages_for_types . end ( ) ) ;
languages_for_expressions . insert ( s_supported_languages_for_expressions . begin ( ) , s_supported_languages_for_expressions . end ( ) ) ;
}
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
2015-09-18 06:23:34 +08:00
void
ClangASTContext : : Initialize ( )
{
PluginManager : : RegisterPlugin ( GetPluginNameStatic ( ) ,
" clang base AST context plug-in " ,
2015-10-09 07:07:53 +08:00
CreateInstance ,
EnumerateSupportedLanguages ) ;
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
2015-09-18 06:23:34 +08:00
}
void
ClangASTContext : : Terminate ( )
{
PluginManager : : UnregisterPlugin ( CreateInstance ) ;
}
2010-06-09 00:52:24 +08:00
void
ClangASTContext : : Clear ( )
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
m_ast_ap . reset ( ) ;
2010-06-09 00:52:24 +08:00
m_language_options_ap . reset ( ) ;
m_source_manager_ap . reset ( ) ;
2011-10-08 07:18:13 +08:00
m_diagnostics_engine_ap . reset ( ) ;
2012-10-18 06:11:14 +08:00
m_target_options_rp . reset ( ) ;
2010-06-09 00:52:24 +08:00
m_target_info_ap . reset ( ) ;
m_identifier_table_ap . reset ( ) ;
m_selector_table_ap . reset ( ) ;
m_builtins_ap . reset ( ) ;
2013-07-12 06:46:58 +08:00
m_pointer_byte_size = 0 ;
2010-06-09 00:52:24 +08:00
}
const char *
ClangASTContext : : GetTargetTriple ( )
{
return m_target_triple . c_str ( ) ;
}
void
ClangASTContext : : SetTargetTriple ( const char * target_triple )
{
Clear ( ) ;
m_target_triple . assign ( target_triple ) ;
}
2011-02-16 05:59:32 +08:00
void
ClangASTContext : : SetArchitecture ( const ArchSpec & arch )
{
2011-07-30 09:26:02 +08:00
SetTargetTriple ( arch . GetTriple ( ) . str ( ) . c_str ( ) ) ;
2011-02-16 05:59:32 +08:00
}
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
bool
ClangASTContext : : HasExternalSource ( )
{
ASTContext * ast = getASTContext ( ) ;
if ( ast )
2014-04-20 21:17:36 +08:00
return ast - > getExternalSource ( ) ! = nullptr ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
return false ;
}
void
2014-02-28 01:18:23 +08:00
ClangASTContext : : SetExternalSource ( llvm : : IntrusiveRefCntPtr < ExternalASTSource > & ast_source_ap )
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
{
ASTContext * ast = getASTContext ( ) ;
if ( ast )
{
ast - > setExternalSource ( ast_source_ap ) ;
ast - > getTranslationUnitDecl ( ) - > setHasExternalLexicalStorage ( true ) ;
//ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true);
}
}
void
ClangASTContext : : RemoveExternalSource ( )
{
ASTContext * ast = getASTContext ( ) ;
if ( ast )
{
2014-02-28 01:18:23 +08:00
llvm : : IntrusiveRefCntPtr < ExternalASTSource > empty_ast_source_ap ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ast - > setExternalSource ( empty_ast_source_ap ) ;
ast - > getTranslationUnitDecl ( ) - > setHasExternalLexicalStorage ( false ) ;
//ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false);
}
}
2015-08-12 05:38:15 +08:00
void
ClangASTContext : : setASTContext ( clang : : ASTContext * ast_ctx )
{
if ( ! m_ast_owned ) {
m_ast_ap . release ( ) ;
}
m_ast_owned = false ;
m_ast_ap . reset ( ast_ctx ) ;
GetASTMap ( ) . Insert ( ast_ctx , this ) ;
}
2010-06-09 00:52:24 +08:00
ASTContext *
ClangASTContext : : getASTContext ( )
{
2014-04-20 21:17:36 +08:00
if ( m_ast_ap . get ( ) = = nullptr )
2010-06-09 00:52:24 +08:00
{
2015-08-12 05:38:15 +08:00
m_ast_owned = true ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
m_ast_ap . reset ( new ASTContext ( * getLanguageOptions ( ) ,
* getSourceManager ( ) ,
* getIdentifierTable ( ) ,
* getSelectorTable ( ) ,
2014-05-03 23:05:45 +08:00
* getBuiltinContext ( ) ) ) ;
2015-04-10 01:42:48 +08:00
m_ast_ap - > getDiagnostics ( ) . setClient ( getDiagnosticConsumer ( ) , false ) ;
2015-05-07 08:07:44 +08:00
// This can be NULL if we don't know anything about the architecture or if the
// target for an architecture isn't enabled in the llvm/clang that we built
TargetInfo * target_info = getTargetInfo ( ) ;
if ( target_info )
m_ast_ap - > InitBuiltinTypes ( * target_info ) ;
2010-12-11 08:08:56 +08:00
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( ( m_callback_tag_decl | | m_callback_objc_decl ) & & m_callback_baton )
{
m_ast_ap - > getTranslationUnitDecl ( ) - > setHasExternalLexicalStorage ( ) ;
//m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage();
}
2014-09-17 01:28:40 +08:00
GetASTMap ( ) . Insert ( m_ast_ap . get ( ) , this ) ;
2015-08-19 06:32:36 +08:00
llvm : : IntrusiveRefCntPtr < clang : : ExternalASTSource > ast_source_ap ( new ClangExternalASTSourceCallbacks ( ClangASTContext : : CompleteTagDecl ,
ClangASTContext : : CompleteObjCInterfaceDecl ,
nullptr ,
ClangASTContext : : LayoutRecordType ,
this ) ) ;
SetExternalSource ( ast_source_ap ) ;
2010-06-09 00:52:24 +08:00
}
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
return m_ast_ap . get ( ) ;
2010-06-09 00:52:24 +08:00
}
2014-08-20 05:46:37 +08:00
ClangASTContext *
ClangASTContext : : GetASTContext ( clang : : ASTContext * ast )
{
2014-09-17 01:28:40 +08:00
ClangASTContext * clang_ast = GetASTMap ( ) . Lookup ( ast ) ;
2014-08-20 05:46:37 +08:00
return clang_ast ;
}
2010-06-09 00:52:24 +08:00
Builtin : : Context *
ClangASTContext : : getBuiltinContext ( )
{
2014-04-20 21:17:36 +08:00
if ( m_builtins_ap . get ( ) = = nullptr )
2011-10-08 07:18:13 +08:00
m_builtins_ap . reset ( new Builtin : : Context ( ) ) ;
2010-06-09 00:52:24 +08:00
return m_builtins_ap . get ( ) ;
}
IdentifierTable *
ClangASTContext : : getIdentifierTable ( )
{
2014-04-20 21:17:36 +08:00
if ( m_identifier_table_ap . get ( ) = = nullptr )
m_identifier_table_ap . reset ( new IdentifierTable ( * ClangASTContext : : getLanguageOptions ( ) , nullptr ) ) ;
2010-06-09 00:52:24 +08:00
return m_identifier_table_ap . get ( ) ;
}
LangOptions *
ClangASTContext : : getLanguageOptions ( )
{
2014-04-20 21:17:36 +08:00
if ( m_language_options_ap . get ( ) = = nullptr )
2010-06-09 00:52:24 +08:00
{
m_language_options_ap . reset ( new LangOptions ( ) ) ;
2015-03-31 18:21:50 +08:00
ParseLangArgs ( * m_language_options_ap , IK_ObjCXX , GetTargetTriple ( ) ) ;
2010-06-14 01:34:29 +08:00
// InitializeLangOptions(*m_language_options_ap, IK_ObjCXX);
2010-06-09 00:52:24 +08:00
}
return m_language_options_ap . get ( ) ;
}
SelectorTable *
ClangASTContext : : getSelectorTable ( )
{
2014-04-20 21:17:36 +08:00
if ( m_selector_table_ap . get ( ) = = nullptr )
2010-06-09 00:52:24 +08:00
m_selector_table_ap . reset ( new SelectorTable ( ) ) ;
return m_selector_table_ap . get ( ) ;
}
2010-11-18 10:56:27 +08:00
clang : : FileManager *
ClangASTContext : : getFileManager ( )
{
2014-04-20 21:17:36 +08:00
if ( m_file_manager_ap . get ( ) = = nullptr )
2010-12-03 07:20:03 +08:00
{
clang : : FileSystemOptions file_system_options ;
m_file_manager_ap . reset ( new clang : : FileManager ( file_system_options ) ) ;
}
2010-11-18 10:56:27 +08:00
return m_file_manager_ap . get ( ) ;
}
2010-07-22 06:12:05 +08:00
clang : : SourceManager *
2010-06-09 00:52:24 +08:00
ClangASTContext : : getSourceManager ( )
{
2014-04-20 21:17:36 +08:00
if ( m_source_manager_ap . get ( ) = = nullptr )
2011-10-08 07:18:13 +08:00
m_source_manager_ap . reset ( new clang : : SourceManager ( * getDiagnosticsEngine ( ) , * getFileManager ( ) ) ) ;
2010-06-09 00:52:24 +08:00
return m_source_manager_ap . get ( ) ;
}
2011-10-08 07:18:13 +08:00
clang : : DiagnosticsEngine *
ClangASTContext : : getDiagnosticsEngine ( )
2010-06-09 00:52:24 +08:00
{
2014-04-20 21:17:36 +08:00
if ( m_diagnostics_engine_ap . get ( ) = = nullptr )
2010-11-20 05:46:54 +08:00
{
llvm : : IntrusiveRefCntPtr < DiagnosticIDs > diag_id_sp ( new DiagnosticIDs ( ) ) ;
2012-10-25 09:00:25 +08:00
m_diagnostics_engine_ap . reset ( new DiagnosticsEngine ( diag_id_sp , new DiagnosticOptions ( ) ) ) ;
2010-11-20 05:46:54 +08:00
}
2011-10-08 07:18:13 +08:00
return m_diagnostics_engine_ap . get ( ) ;
2010-06-09 00:52:24 +08:00
}
2011-10-08 07:18:13 +08:00
class NullDiagnosticConsumer : public DiagnosticConsumer
2010-12-11 08:08:56 +08:00
{
public :
2011-10-08 07:18:13 +08:00
NullDiagnosticConsumer ( )
2010-12-11 08:08:56 +08:00
{
m_log = lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ;
}
2011-10-08 07:18:13 +08:00
void HandleDiagnostic ( DiagnosticsEngine : : Level DiagLevel , const Diagnostic & info )
2010-12-11 08:08:56 +08:00
{
if ( m_log )
{
2012-02-04 16:49:35 +08:00
llvm : : SmallVector < char , 32 > diag_str ( 10 ) ;
2010-12-11 08:08:56 +08:00
info . FormatDiagnostic ( diag_str ) ;
diag_str . push_back ( ' \0 ' ) ;
m_log - > Printf ( " Compiler diagnostic: %s \n " , diag_str . data ( ) ) ;
}
}
2011-10-08 07:18:13 +08:00
DiagnosticConsumer * clone ( DiagnosticsEngine & Diags ) const
{
return new NullDiagnosticConsumer ( ) ;
}
2010-12-11 08:08:56 +08:00
private :
2013-03-28 07:08:40 +08:00
Log * m_log ;
2010-12-11 08:08:56 +08:00
} ;
2011-10-08 07:18:13 +08:00
DiagnosticConsumer *
ClangASTContext : : getDiagnosticConsumer ( )
2010-12-11 08:08:56 +08:00
{
2014-04-20 21:17:36 +08:00
if ( m_diagnostic_consumer_ap . get ( ) = = nullptr )
2011-10-08 07:18:13 +08:00
m_diagnostic_consumer_ap . reset ( new NullDiagnosticConsumer ) ;
2010-12-11 08:08:56 +08:00
2011-10-08 07:18:13 +08:00
return m_diagnostic_consumer_ap . get ( ) ;
2010-12-11 08:08:56 +08:00
}
2014-07-09 07:46:39 +08:00
std : : shared_ptr < TargetOptions > &
ClangASTContext : : getTargetOptions ( ) {
2014-07-05 11:06:05 +08:00
if ( m_target_options_rp . get ( ) = = nullptr & & ! m_target_triple . empty ( ) )
2010-06-09 00:52:24 +08:00
{
2014-07-06 13:36:57 +08:00
m_target_options_rp = std : : make_shared < TargetOptions > ( ) ;
2014-07-05 11:06:05 +08:00
if ( m_target_options_rp . get ( ) ! = nullptr )
2012-10-18 06:11:14 +08:00
m_target_options_rp - > Triple = m_target_triple ;
2010-06-09 00:52:24 +08:00
}
2014-07-06 13:36:57 +08:00
return m_target_options_rp ;
2010-06-09 00:52:24 +08:00
}
TargetInfo *
ClangASTContext : : getTargetInfo ( )
{
2012-05-08 09:45:38 +08:00
// target_triple should be something like "x86_64-apple-macosx"
2014-04-20 21:17:36 +08:00
if ( m_target_info_ap . get ( ) = = nullptr & & ! m_target_triple . empty ( ) )
2012-11-17 05:35:22 +08:00
m_target_info_ap . reset ( TargetInfo : : CreateTargetInfo ( * getDiagnosticsEngine ( ) , getTargetOptions ( ) ) ) ;
2010-06-09 00:52:24 +08:00
return m_target_info_ap . get ( ) ;
}
# pragma mark Basic Types
static inline bool
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
QualTypeMatchesBitSize ( const uint64_t bit_size , ASTContext * ast , QualType qual_type )
2010-06-09 00:52:24 +08:00
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
uint64_t qual_type_bit_size = ast - > getTypeSize ( qual_type ) ;
2010-06-09 00:52:24 +08:00
if ( qual_type_bit_size = = bit_size )
return true ;
return false ;
}
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
2015-09-18 06:23:34 +08:00
2015-08-12 06:53:00 +08:00
CompilerType
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
2015-09-18 06:23:34 +08:00
ClangASTContext : : GetBuiltinTypeForEncodingAndBitSize ( Encoding encoding , size_t bit_size )
2010-06-09 00:52:24 +08:00
{
2013-07-12 06:46:58 +08:00
return ClangASTContext : : GetBuiltinTypeForEncodingAndBitSize ( getASTContext ( ) , encoding , bit_size ) ;
2010-06-09 00:52:24 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ClangASTContext : : GetBuiltinTypeForEncodingAndBitSize ( ASTContext * ast , Encoding encoding , uint32_t bit_size )
2010-06-09 00:52:24 +08:00
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( ! ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-06-09 00:52:24 +08:00
switch ( encoding )
{
2010-08-05 09:57:25 +08:00
case eEncodingInvalid :
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > VoidPtrTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > VoidPtrTy ) ;
2010-06-09 00:52:24 +08:00
break ;
2010-08-05 09:57:25 +08:00
case eEncodingUint :
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedIntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedIntTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongLongTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedInt128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedInt128Ty ) ;
2010-06-09 00:52:24 +08:00
break ;
2010-08-05 09:57:25 +08:00
case eEncodingSint :
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > CharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > CharTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > ShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > ShortTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > IntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > IntTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongLongTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > Int128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Int128Ty ) ;
2010-06-09 00:52:24 +08:00
break ;
2010-08-05 09:57:25 +08:00
case eEncodingIEEE754 :
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > FloatTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > FloatTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > DoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > DoubleTy ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongDoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongDoubleTy ) ;
2010-06-09 00:52:24 +08:00
break ;
2010-08-05 09:57:25 +08:00
case eEncodingVector :
2012-03-07 09:12:24 +08:00
// Sanity check that bit_size is a multiple of 8's.
if ( bit_size & & ! ( bit_size & 0x7u ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getExtVectorType ( ast - > UnsignedCharTy , bit_size / 8 ) ) ;
2012-03-07 09:12:24 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2013-07-12 06:46:58 +08:00
}
lldb : : BasicType
ClangASTContext : : GetBasicTypeEnumeration ( const ConstString & name )
{
if ( name )
{
typedef UniqueCStringMap < lldb : : BasicType > TypeNameToBasicTypeMap ;
static TypeNameToBasicTypeMap g_type_map ;
static std : : once_flag g_once_flag ;
std : : call_once ( g_once_flag , [ ] ( ) {
// "void"
g_type_map . Append ( ConstString ( " void " ) . GetCString ( ) , eBasicTypeVoid ) ;
// "char"
g_type_map . Append ( ConstString ( " char " ) . GetCString ( ) , eBasicTypeChar ) ;
g_type_map . Append ( ConstString ( " signed char " ) . GetCString ( ) , eBasicTypeSignedChar ) ;
g_type_map . Append ( ConstString ( " unsigned char " ) . GetCString ( ) , eBasicTypeUnsignedChar ) ;
g_type_map . Append ( ConstString ( " wchar_t " ) . GetCString ( ) , eBasicTypeWChar ) ;
g_type_map . Append ( ConstString ( " signed wchar_t " ) . GetCString ( ) , eBasicTypeSignedWChar ) ;
g_type_map . Append ( ConstString ( " unsigned wchar_t " ) . GetCString ( ) , eBasicTypeUnsignedWChar ) ;
// "short"
g_type_map . Append ( ConstString ( " short " ) . GetCString ( ) , eBasicTypeShort ) ;
g_type_map . Append ( ConstString ( " short int " ) . GetCString ( ) , eBasicTypeShort ) ;
g_type_map . Append ( ConstString ( " unsigned short " ) . GetCString ( ) , eBasicTypeUnsignedShort ) ;
g_type_map . Append ( ConstString ( " unsigned short int " ) . GetCString ( ) , eBasicTypeUnsignedShort ) ;
// "int"
g_type_map . Append ( ConstString ( " int " ) . GetCString ( ) , eBasicTypeInt ) ;
g_type_map . Append ( ConstString ( " signed int " ) . GetCString ( ) , eBasicTypeInt ) ;
g_type_map . Append ( ConstString ( " unsigned int " ) . GetCString ( ) , eBasicTypeUnsignedInt ) ;
g_type_map . Append ( ConstString ( " unsigned " ) . GetCString ( ) , eBasicTypeUnsignedInt ) ;
// "long"
g_type_map . Append ( ConstString ( " long " ) . GetCString ( ) , eBasicTypeLong ) ;
g_type_map . Append ( ConstString ( " long int " ) . GetCString ( ) , eBasicTypeLong ) ;
g_type_map . Append ( ConstString ( " unsigned long " ) . GetCString ( ) , eBasicTypeUnsignedLong ) ;
g_type_map . Append ( ConstString ( " unsigned long int " ) . GetCString ( ) , eBasicTypeUnsignedLong ) ;
// "long long"
g_type_map . Append ( ConstString ( " long long " ) . GetCString ( ) , eBasicTypeLongLong ) ;
g_type_map . Append ( ConstString ( " long long int " ) . GetCString ( ) , eBasicTypeLongLong ) ;
g_type_map . Append ( ConstString ( " unsigned long long " ) . GetCString ( ) , eBasicTypeUnsignedLongLong ) ;
g_type_map . Append ( ConstString ( " unsigned long long int " ) . GetCString ( ) , eBasicTypeUnsignedLongLong ) ;
// "int128"
g_type_map . Append ( ConstString ( " __int128_t " ) . GetCString ( ) , eBasicTypeInt128 ) ;
g_type_map . Append ( ConstString ( " __uint128_t " ) . GetCString ( ) , eBasicTypeUnsignedInt128 ) ;
2014-07-02 05:22:11 +08:00
// Miscellaneous
2013-07-12 06:46:58 +08:00
g_type_map . Append ( ConstString ( " bool " ) . GetCString ( ) , eBasicTypeBool ) ;
g_type_map . Append ( ConstString ( " float " ) . GetCString ( ) , eBasicTypeFloat ) ;
g_type_map . Append ( ConstString ( " double " ) . GetCString ( ) , eBasicTypeDouble ) ;
g_type_map . Append ( ConstString ( " long double " ) . GetCString ( ) , eBasicTypeLongDouble ) ;
g_type_map . Append ( ConstString ( " id " ) . GetCString ( ) , eBasicTypeObjCID ) ;
g_type_map . Append ( ConstString ( " SEL " ) . GetCString ( ) , eBasicTypeObjCSel ) ;
g_type_map . Append ( ConstString ( " nullptr " ) . GetCString ( ) , eBasicTypeNullPtr ) ;
g_type_map . Sort ( ) ;
} ) ;
return g_type_map . Find ( name . GetCString ( ) , eBasicTypeInvalid ) ;
}
return eBasicTypeInvalid ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2013-07-12 06:46:58 +08:00
ClangASTContext : : GetBasicType ( ASTContext * ast , const ConstString & name )
{
if ( ast )
{
lldb : : BasicType basic_type = ClangASTContext : : GetBasicTypeEnumeration ( name ) ;
return ClangASTContext : : GetBasicType ( ast , basic_type ) ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2013-07-12 06:46:58 +08:00
}
uint32_t
ClangASTContext : : GetPointerByteSize ( )
{
if ( m_pointer_byte_size = = 0 )
2015-01-28 08:07:51 +08:00
m_pointer_byte_size = GetBasicType ( lldb : : eBasicTypeVoid ) . GetPointerType ( ) . GetByteSize ( nullptr ) ;
2013-07-12 06:46:58 +08:00
return m_pointer_byte_size ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2013-07-12 06:46:58 +08:00
ClangASTContext : : GetBasicType ( lldb : : BasicType basic_type )
{
return GetBasicType ( getASTContext ( ) , basic_type ) ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2013-07-12 06:46:58 +08:00
ClangASTContext : : GetBasicType ( ASTContext * ast , lldb : : BasicType basic_type )
{
if ( ast )
{
2015-09-23 08:18:24 +08:00
lldb : : opaque_compiler_type_t clang_type = nullptr ;
2013-07-12 06:46:58 +08:00
switch ( basic_type )
{
case eBasicTypeInvalid :
case eBasicTypeOther :
break ;
case eBasicTypeVoid :
clang_type = ast - > VoidTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeChar :
clang_type = ast - > CharTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeSignedChar :
clang_type = ast - > SignedCharTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedChar :
clang_type = ast - > UnsignedCharTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeWChar :
clang_type = ast - > getWCharType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeSignedWChar :
clang_type = ast - > getSignedWCharType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedWChar :
clang_type = ast - > getUnsignedWCharType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeChar16 :
clang_type = ast - > Char16Ty . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeChar32 :
clang_type = ast - > Char32Ty . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeShort :
clang_type = ast - > ShortTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedShort :
clang_type = ast - > UnsignedShortTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeInt :
clang_type = ast - > IntTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedInt :
clang_type = ast - > UnsignedIntTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeLong :
clang_type = ast - > LongTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedLong :
clang_type = ast - > UnsignedLongTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeLongLong :
clang_type = ast - > LongLongTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedLongLong :
clang_type = ast - > UnsignedLongLongTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeInt128 :
clang_type = ast - > Int128Ty . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeUnsignedInt128 :
clang_type = ast - > UnsignedInt128Ty . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeBool :
clang_type = ast - > BoolTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeHalf :
clang_type = ast - > HalfTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeFloat :
clang_type = ast - > FloatTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeDouble :
clang_type = ast - > DoubleTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeLongDouble :
clang_type = ast - > LongDoubleTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeFloatComplex :
clang_type = ast - > FloatComplexTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeDoubleComplex :
clang_type = ast - > DoubleComplexTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeLongDoubleComplex :
clang_type = ast - > LongDoubleComplexTy . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeObjCID :
clang_type = ast - > getObjCIdType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeObjCClass :
clang_type = ast - > getObjCClassType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeObjCSel :
clang_type = ast - > getObjCSelType ( ) . getAsOpaquePtr ( ) ;
break ;
case eBasicTypeNullPtr :
clang_type = ast - > NullPtrTy . getAsOpaquePtr ( ) ;
break ;
}
if ( clang_type )
2015-08-12 06:53:00 +08:00
return CompilerType ( GetASTContext ( ast ) , clang_type ) ;
2013-07-12 06:46:58 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-06-09 00:52:24 +08:00
}
2013-07-12 06:46:58 +08:00
2015-08-12 06:53:00 +08:00
CompilerType
2010-06-09 00:52:24 +08:00
ClangASTContext : : GetBuiltinTypeForDWARFEncodingAndBitSize ( const char * type_name , uint32_t dw_ate , uint32_t bit_size )
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ASTContext * ast = getASTContext ( ) ;
2012-04-03 09:10:10 +08:00
# define streq(a,b) strcmp(a,b) == 0
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( ast )
2010-06-09 00:52:24 +08:00
{
switch ( dw_ate )
{
2012-04-03 09:10:10 +08:00
default :
break ;
case DW_ATE_address :
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > VoidPtrTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > VoidPtrTy ) ;
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_boolean :
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > BoolTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > BoolTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedIntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedIntTy ) ;
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_lo_user :
// This has been seen to mean DW_AT_complex_integer
if ( type_name )
2010-06-09 00:52:24 +08:00
{
2012-04-03 09:10:10 +08:00
if ( : : strstr ( type_name , " complex " ) )
{
2015-08-12 06:53:00 +08:00
CompilerType complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ( " int " , DW_ATE_signed , bit_size / 2 ) ;
return CompilerType ( ast , ast - > getComplexType ( GetQualType ( complex_int_clang_type ) ) ) ;
2012-04-03 09:10:10 +08:00
}
2010-06-09 00:52:24 +08:00
}
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_complex_float :
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > FloatComplexTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > FloatComplexTy ) ;
2012-04-03 09:10:10 +08:00
else if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > DoubleComplexTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > DoubleComplexTy ) ;
2012-04-03 09:10:10 +08:00
else if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongDoubleComplexTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongDoubleComplexTy ) ;
2012-04-03 09:10:10 +08:00
else
2010-11-02 11:48:39 +08:00
{
2015-08-12 06:53:00 +08:00
CompilerType complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ( " float " , DW_ATE_float , bit_size / 2 ) ;
return CompilerType ( ast , ast - > getComplexType ( GetQualType ( complex_float_clang_type ) ) ) ;
2010-11-02 11:48:39 +08:00
}
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_float :
2014-11-18 03:39:20 +08:00
if ( streq ( type_name , " float " ) & & QualTypeMatchesBitSize ( bit_size , ast , ast - > FloatTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > FloatTy ) ;
2014-11-18 03:39:20 +08:00
if ( streq ( type_name , " double " ) & & QualTypeMatchesBitSize ( bit_size , ast , ast - > DoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > DoubleTy ) ;
2014-11-18 03:39:20 +08:00
if ( streq ( type_name , " long double " ) & & QualTypeMatchesBitSize ( bit_size , ast , ast - > LongDoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongDoubleTy ) ;
2015-07-22 08:16:02 +08:00
// Fall back to not requiring a name match
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > FloatTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > FloatTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > DoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > DoubleTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongDoubleTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongDoubleTy ) ;
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_signed :
if ( type_name )
2010-06-09 00:52:24 +08:00
{
2012-04-03 09:10:10 +08:00
if ( streq ( type_name , " wchar_t " ) & &
2015-04-01 17:48:02 +08:00
QualTypeMatchesBitSize ( bit_size , ast , ast - > WCharTy ) & &
2015-05-07 08:07:44 +08:00
( getTargetInfo ( ) & & TargetInfo : : isTypeSigned ( getTargetInfo ( ) - > getWCharType ( ) ) ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > WCharTy ) ;
2012-04-03 09:10:10 +08:00
if ( streq ( type_name , " void " ) & &
QualTypeMatchesBitSize ( bit_size , ast , ast - > VoidTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > VoidTy ) ;
2012-04-03 09:10:10 +08:00
if ( strstr ( type_name , " long long " ) & &
QualTypeMatchesBitSize ( bit_size , ast , ast - > LongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongLongTy ) ;
2012-04-03 09:10:10 +08:00
if ( strstr ( type_name , " long " ) & &
QualTypeMatchesBitSize ( bit_size , ast , ast - > LongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongTy ) ;
2012-04-03 09:10:10 +08:00
if ( strstr ( type_name , " short " ) & &
QualTypeMatchesBitSize ( bit_size , ast , ast - > ShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > ShortTy ) ;
2012-04-03 09:10:10 +08:00
if ( strstr ( type_name , " char " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > CharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > CharTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > SignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > SignedCharTy ) ;
2012-04-03 09:10:10 +08:00
}
if ( strstr ( type_name , " int " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > IntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > IntTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > Int128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Int128Ty ) ;
2012-04-03 09:10:10 +08:00
}
2011-02-10 07:39:34 +08:00
}
2012-04-03 09:10:10 +08:00
// We weren't able to match up a type name, just search by size
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > CharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > CharTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > ShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > ShortTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > IntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > IntTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > LongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongLongTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > Int128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Int128Ty ) ;
2012-04-03 09:10:10 +08:00
break ;
2015-03-31 18:21:50 +08:00
2012-04-03 09:10:10 +08:00
case DW_ATE_signed_char :
2015-03-31 18:21:50 +08:00
if ( ast - > getLangOpts ( ) . CharIsSigned & & type_name & & streq ( type_name , " char " ) )
2010-11-02 11:48:39 +08:00
{
2015-03-31 18:21:50 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > CharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > CharTy ) ;
2010-11-02 11:48:39 +08:00
}
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > SignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > SignedCharTy ) ;
2012-04-03 09:10:10 +08:00
break ;
2011-10-29 07:06:08 +08:00
2012-04-03 09:10:10 +08:00
case DW_ATE_unsigned :
if ( type_name )
2011-10-29 07:06:08 +08:00
{
2015-04-01 17:48:02 +08:00
if ( streq ( type_name , " wchar_t " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > WCharTy ) )
{
2015-05-07 08:07:44 +08:00
if ( ! ( getTargetInfo ( ) & & TargetInfo : : isTypeSigned ( getTargetInfo ( ) - > getWCharType ( ) ) ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > WCharTy ) ;
2015-04-01 17:48:02 +08:00
}
}
2012-04-03 09:10:10 +08:00
if ( strstr ( type_name , " long long " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongLongTy ) ;
2012-04-03 09:10:10 +08:00
}
else if ( strstr ( type_name , " long " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongTy ) ;
2012-04-03 09:10:10 +08:00
}
else if ( strstr ( type_name , " short " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
2012-04-03 09:10:10 +08:00
}
else if ( strstr ( type_name , " char " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
2012-04-03 09:10:10 +08:00
}
else if ( strstr ( type_name , " int " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedIntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedIntTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedInt128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedInt128Ty ) ;
2012-04-03 09:10:10 +08:00
}
2011-10-29 07:06:08 +08:00
}
2012-04-03 09:10:10 +08:00
// We weren't able to match up a type name, just search by size
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedIntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedIntTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedLongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongLongTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedInt128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedInt128Ty ) ;
2012-04-03 09:10:10 +08:00
break ;
2015-03-31 18:21:50 +08:00
2012-04-03 09:10:10 +08:00
case DW_ATE_unsigned_char :
2015-03-31 18:21:50 +08:00
if ( ! ast - > getLangOpts ( ) . CharIsSigned & & type_name & & streq ( type_name , " char " ) )
{
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > CharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > CharTy ) ;
2015-03-31 18:21:50 +08:00
}
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
2012-04-03 09:10:10 +08:00
if ( QualTypeMatchesBitSize ( bit_size , ast , ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
2012-04-03 09:10:10 +08:00
break ;
case DW_ATE_imaginary_float :
break ;
case DW_ATE_UTF :
if ( type_name )
2011-10-29 07:06:08 +08:00
{
2012-04-03 09:10:10 +08:00
if ( streq ( type_name , " char16_t " ) )
{
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Char16Ty ) ;
2012-04-03 09:10:10 +08:00
}
else if ( streq ( type_name , " char32_t " ) )
{
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Char32Ty ) ;
2012-04-03 09:10:10 +08:00
}
2011-10-29 07:06:08 +08:00
}
2012-04-03 09:10:10 +08:00
break ;
2010-06-09 00:52:24 +08:00
}
}
// This assert should fire for anything that we don't catch above so we know
// to fix any issues we run into.
2011-05-18 02:15:05 +08:00
if ( type_name )
{
2012-01-05 11:57:59 +08:00
Host : : SystemLog ( Host : : eSystemLogError , " error: need to add support for DW_TAG_base_type '%s' encoded with DW_ATE = 0x%x, bit_size = %u \n " , type_name , dw_ate , bit_size ) ;
2011-05-18 02:15:05 +08:00
}
else
{
2012-01-05 11:57:59 +08:00
Host : : SystemLog ( Host : : eSystemLogError , " error: need to add support for DW_TAG_base_type encoded with DW_ATE = 0x%x, bit_size = %u \n " , dw_ate , bit_size ) ;
2011-05-18 02:15:05 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-08-03 08:35:52 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2011-05-13 07:54:16 +08:00
ClangASTContext : : GetUnknownAnyType ( clang : : ASTContext * ast )
{
2013-07-12 06:46:58 +08:00
if ( ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnknownAnyTy ) ;
return CompilerType ( ) ;
2011-05-13 07:54:16 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2010-06-09 00:52:24 +08:00
ClangASTContext : : GetCStringType ( bool is_const )
{
2013-07-12 06:46:58 +08:00
ASTContext * ast = getASTContext ( ) ;
QualType char_type ( ast - > CharTy ) ;
2010-06-09 00:52:24 +08:00
if ( is_const )
char_type . addConst ( ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getPointerType ( char_type ) ) ;
2010-06-09 00:52:24 +08:00
}
2011-12-01 06:11:59 +08:00
clang : : DeclContext *
ClangASTContext : : GetTranslationUnitDecl ( clang : : ASTContext * ast )
{
return ast - > getTranslationUnitDecl ( ) ;
}
2010-11-13 11:52:47 +08:00
clang : : Decl *
2010-12-03 07:20:03 +08:00
ClangASTContext : : CopyDecl ( ASTContext * dst_ast ,
ASTContext * src_ast ,
2010-11-13 11:52:47 +08:00
clang : : Decl * source_decl )
2010-12-11 08:08:56 +08:00
{
2010-11-18 10:56:27 +08:00
FileSystemOptions file_system_options ;
2010-12-03 07:20:03 +08:00
FileManager file_manager ( file_system_options ) ;
ASTImporter importer ( * dst_ast , file_manager ,
2011-01-19 07:32:05 +08:00
* src_ast , file_manager ,
false ) ;
2010-11-13 11:52:47 +08:00
return importer . Import ( source_decl ) ;
}
2010-07-16 08:00:27 +08:00
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : AreTypesSame ( CompilerType type1 ,
CompilerType type2 ,
2012-03-27 07:03:23 +08:00
bool ignore_qualifiers )
2010-07-16 06:30:52 +08:00
{
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast_or_null < ClangASTContext > ( type1 . GetTypeSystem ( ) ) ;
if ( ! ast | | ast ! = type2 . GetTypeSystem ( ) )
2013-07-12 06:46:58 +08:00
return false ;
if ( type1 . GetOpaqueQualType ( ) = = type2 . GetOpaqueQualType ( ) )
2012-04-07 01:38:55 +08:00
return true ;
2015-08-12 05:38:15 +08:00
QualType type1_qual = GetQualType ( type1 ) ;
QualType type2_qual = GetQualType ( type2 ) ;
2012-02-18 10:01:03 +08:00
if ( ignore_qualifiers )
{
type1_qual = type1_qual . getUnqualifiedType ( ) ;
type2_qual = type2_qual . getUnqualifiedType ( ) ;
}
2015-09-09 02:15:05 +08:00
return ast - > getASTContext ( ) - > hasSameType ( type1_qual , type2_qual ) ;
2010-06-09 00:52:24 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2014-12-05 09:21:59 +08:00
ClangASTContext : : GetTypeForDecl ( clang : : NamedDecl * decl )
{
if ( clang : : ObjCInterfaceDecl * interface_decl = llvm : : dyn_cast < clang : : ObjCInterfaceDecl > ( decl ) )
return GetTypeForDecl ( interface_decl ) ;
if ( clang : : TagDecl * tag_decl = llvm : : dyn_cast < clang : : TagDecl > ( decl ) )
return GetTypeForDecl ( tag_decl ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2014-12-05 09:21:59 +08:00
}
2010-06-09 00:52:24 +08:00
2015-08-12 06:53:00 +08:00
CompilerType
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ClangASTContext : : GetTypeForDecl ( TagDecl * decl )
{
// No need to call the getASTContext() accessor (which can create the AST
// if it isn't created yet, because we can't have created a decl in this
// AST if our AST didn't already exist...
2014-12-05 09:21:59 +08:00
ASTContext * ast = & decl - > getASTContext ( ) ;
2013-07-12 06:46:58 +08:00
if ( ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getTagDeclType ( decl ) ) ;
return CompilerType ( ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ClangASTContext : : GetTypeForDecl ( ObjCInterfaceDecl * decl )
{
// No need to call the getASTContext() accessor (which can create the AST
// if it isn't created yet, because we can't have created a decl in this
// AST if our AST didn't already exist...
2014-12-05 09:21:59 +08:00
ASTContext * ast = & decl - > getASTContext ( ) ;
2013-07-12 06:46:58 +08:00
if ( ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getObjCInterfaceType ( decl ) ) ;
return CompilerType ( ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
}
2010-06-09 00:52:24 +08:00
# pragma mark Structure, Unions, Classes
2015-08-12 06:53:00 +08:00
CompilerType
2013-03-08 09:37:30 +08:00
ClangASTContext : : CreateRecordType ( DeclContext * decl_ctx ,
AccessType access_type ,
const char * name ,
int kind ,
LanguageType language ,
ClangASTMetadata * metadata )
2010-06-09 00:52:24 +08:00
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ASTContext * ast = getASTContext ( ) ;
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
2012-04-18 09:06:17 +08:00
2014-04-20 21:17:36 +08:00
if ( decl_ctx = = nullptr )
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
decl_ctx = ast - > getTranslationUnitDecl ( ) ;
2010-06-09 00:52:24 +08:00
2010-07-28 10:04:09 +08:00
2011-08-25 07:50:00 +08:00
if ( language = = eLanguageTypeObjC | | language = = eLanguageTypeObjC_plus_plus )
2010-07-28 10:04:09 +08:00
{
2010-10-11 10:25:34 +08:00
bool isForwardDecl = true ;
2010-07-28 10:04:09 +08:00
bool isInternal = false ;
2012-04-18 09:06:17 +08:00
return CreateObjCClass ( name , decl_ctx , isForwardDecl , isInternal , metadata ) ;
2010-07-28 10:04:09 +08:00
}
2010-06-09 00:52:24 +08:00
// NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and
// we will need to update this code. I was told to currently always use
// the CXXRecordDecl class since we often don't know from debug information
// if something is struct or a class, so we default to always use the more
// complete definition just in case.
2014-02-18 08:31:38 +08:00
bool is_anonymous = ( ! name ) | | ( ! name [ 0 ] ) ;
2011-10-22 11:33:13 +08:00
CXXRecordDecl * decl = CXXRecordDecl : : Create ( * ast ,
( TagDecl : : TagKind ) kind ,
decl_ctx ,
SourceLocation ( ) ,
SourceLocation ( ) ,
2014-04-20 21:17:36 +08:00
is_anonymous ? nullptr : & ast - > Idents . get ( name ) ) ;
2014-02-18 08:31:38 +08:00
if ( is_anonymous )
decl - > setAnonymousStructOrUnion ( true ) ;
2012-01-14 06:10:18 +08:00
2013-03-08 09:37:30 +08:00
if ( decl )
2011-10-26 11:31:36 +08:00
{
2013-03-08 09:37:30 +08:00
if ( metadata )
2013-03-27 09:48:02 +08:00
SetMetadata ( ast , decl , * metadata ) ;
2013-03-08 09:37:30 +08:00
2011-10-26 11:31:36 +08:00
if ( access_type ! = eAccessNone )
decl - > setAccess ( ConvertAccessTypeToAccessSpecifier ( access_type ) ) ;
2013-03-08 09:37:30 +08:00
if ( decl_ctx )
decl_ctx - > addDecl ( decl ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getTagDeclType ( decl ) ) ;
2011-10-26 11:31:36 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
}
2012-02-06 14:42:51 +08:00
static TemplateParameterList *
CreateTemplateParameterList ( ASTContext * ast ,
2012-09-25 06:25:51 +08:00
const ClangASTContext : : TemplateParameterInfos & template_param_infos ,
2012-02-06 14:42:51 +08:00
llvm : : SmallVector < NamedDecl * , 8 > & template_param_decls )
2011-10-22 11:33:13 +08:00
{
const bool parameter_pack = false ;
const bool is_typename = false ;
const unsigned depth = 0 ;
const size_t num_template_params = template_param_infos . GetSize ( ) ;
for ( size_t i = 0 ; i < num_template_params ; + + i )
{
const char * name = template_param_infos . names [ i ] ;
2013-04-24 06:38:02 +08:00
2014-04-20 21:17:36 +08:00
IdentifierInfo * identifier_info = nullptr ;
2013-04-24 06:38:02 +08:00
if ( name & & name [ 0 ] )
identifier_info = & ast - > Idents . get ( name ) ;
2012-09-25 06:25:51 +08:00
if ( template_param_infos . args [ i ] . getKind ( ) = = TemplateArgument : : Integral )
2011-10-22 11:33:13 +08:00
{
template_param_decls . push_back ( NonTypeTemplateParmDecl : : Create ( * ast ,
ast - > getTranslationUnitDecl ( ) , // Is this the right decl context?, SourceLocation StartLoc,
SourceLocation ( ) ,
SourceLocation ( ) ,
depth ,
i ,
2013-04-24 06:38:02 +08:00
identifier_info ,
2011-12-02 10:09:28 +08:00
template_param_infos . args [ i ] . getIntegralType ( ) ,
2011-10-22 11:33:13 +08:00
parameter_pack ,
2014-04-20 21:17:36 +08:00
nullptr ) ) ;
2012-02-06 14:42:51 +08:00
2011-10-22 11:33:13 +08:00
}
else
{
template_param_decls . push_back ( TemplateTypeParmDecl : : Create ( * ast ,
ast - > getTranslationUnitDecl ( ) , // Is this the right decl context?
SourceLocation ( ) ,
SourceLocation ( ) ,
depth ,
i ,
2013-04-24 06:38:02 +08:00
identifier_info ,
2011-10-22 11:33:13 +08:00
is_typename ,
parameter_pack ) ) ;
}
}
2012-02-06 14:42:51 +08:00
TemplateParameterList * template_param_list = TemplateParameterList : : Create ( * ast ,
SourceLocation ( ) ,
SourceLocation ( ) ,
& template_param_decls . front ( ) ,
template_param_decls . size ( ) ,
SourceLocation ( ) ) ;
return template_param_list ;
}
clang : : FunctionTemplateDecl *
ClangASTContext : : CreateFunctionTemplateDecl ( clang : : DeclContext * decl_ctx ,
clang : : FunctionDecl * func_decl ,
const char * name ,
const TemplateParameterInfos & template_param_infos )
{
// /// \brief Create a function template node.
ASTContext * ast = getASTContext ( ) ;
llvm : : SmallVector < NamedDecl * , 8 > template_param_decls ;
TemplateParameterList * template_param_list = CreateTemplateParameterList ( ast ,
template_param_infos ,
template_param_decls ) ;
FunctionTemplateDecl * func_tmpl_decl = FunctionTemplateDecl : : Create ( * ast ,
decl_ctx ,
func_decl - > getLocation ( ) ,
func_decl - > getDeclName ( ) ,
template_param_list ,
func_decl ) ;
for ( size_t i = 0 , template_param_decl_count = template_param_decls . size ( ) ;
i < template_param_decl_count ;
+ + i )
{
// TODO: verify which decl context we should put template_param_decls into..
template_param_decls [ i ] - > setDeclContext ( func_decl ) ;
}
return func_tmpl_decl ;
}
void
ClangASTContext : : CreateFunctionTemplateSpecializationInfo ( FunctionDecl * func_decl ,
clang : : FunctionTemplateDecl * func_tmpl_decl ,
const TemplateParameterInfos & infos )
{
TemplateArgumentList template_args ( TemplateArgumentList : : OnStack ,
infos . args . data ( ) ,
infos . args . size ( ) ) ;
func_decl - > setFunctionTemplateSpecialization ( func_tmpl_decl ,
& template_args ,
2014-04-20 21:17:36 +08:00
nullptr ) ;
2012-02-06 14:42:51 +08:00
}
ClassTemplateDecl *
ClangASTContext : : CreateClassTemplateDecl ( DeclContext * decl_ctx ,
lldb : : AccessType access_type ,
const char * class_name ,
int kind ,
const TemplateParameterInfos & template_param_infos )
{
ASTContext * ast = getASTContext ( ) ;
2011-10-22 11:33:13 +08:00
2014-04-20 21:17:36 +08:00
ClassTemplateDecl * class_template_decl = nullptr ;
if ( decl_ctx = = nullptr )
2012-02-06 14:42:51 +08:00
decl_ctx = ast - > getTranslationUnitDecl ( ) ;
IdentifierInfo & identifier_info = ast - > Idents . get ( class_name ) ;
DeclarationName decl_name ( & identifier_info ) ;
clang : : DeclContext : : lookup_result result = decl_ctx - > lookup ( decl_name ) ;
2012-12-22 05:34:42 +08:00
for ( NamedDecl * decl : result )
2012-02-06 14:42:51 +08:00
{
2012-12-22 05:34:42 +08:00
class_template_decl = dyn_cast < clang : : ClassTemplateDecl > ( decl ) ;
2012-02-06 14:42:51 +08:00
if ( class_template_decl )
return class_template_decl ;
}
llvm : : SmallVector < NamedDecl * , 8 > template_param_decls ;
2011-10-22 11:33:13 +08:00
2012-02-06 14:42:51 +08:00
TemplateParameterList * template_param_list = CreateTemplateParameterList ( ast ,
template_param_infos ,
template_param_decls ) ;
2011-10-22 11:33:13 +08:00
CXXRecordDecl * template_cxx_decl = CXXRecordDecl : : Create ( * ast ,
( TagDecl : : TagKind ) kind ,
decl_ctx , // What decl context do we use here? TU? The actual decl context?
SourceLocation ( ) ,
SourceLocation ( ) ,
& identifier_info ) ;
2011-12-02 10:09:28 +08:00
for ( size_t i = 0 , template_param_decl_count = template_param_decls . size ( ) ;
i < template_param_decl_count ;
+ + i )
{
template_param_decls [ i ] - > setDeclContext ( template_cxx_decl ) ;
}
2011-11-19 09:35:08 +08:00
// With templated classes, we say that a class is templated with
// specializations, but that the bare class has no functions.
2013-02-01 14:55:48 +08:00
//template_cxx_decl->startDefinition();
//template_cxx_decl->completeDefinition();
2011-11-19 09:35:08 +08:00
2011-10-22 11:33:13 +08:00
class_template_decl = ClassTemplateDecl : : Create ( * ast ,
decl_ctx , // What decl context do we use here? TU? The actual decl context?
SourceLocation ( ) ,
decl_name ,
template_param_list ,
template_cxx_decl ,
2014-04-20 21:17:36 +08:00
nullptr ) ;
2011-10-22 11:33:13 +08:00
if ( class_template_decl )
2011-10-26 09:06:27 +08:00
{
2011-10-26 11:31:36 +08:00
if ( access_type ! = eAccessNone )
class_template_decl - > setAccess ( ConvertAccessTypeToAccessSpecifier ( access_type ) ) ;
2012-02-04 16:49:35 +08:00
//if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx))
// CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl));
2011-10-22 11:33:13 +08:00
decl_ctx - > addDecl ( class_template_decl ) ;
2011-10-26 09:06:27 +08:00
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( class_template_decl ) ;
# endif
}
2011-10-22 11:33:13 +08:00
return class_template_decl ;
}
ClassTemplateSpecializationDecl *
ClangASTContext : : CreateClassTemplateSpecializationDecl ( DeclContext * decl_ctx ,
ClassTemplateDecl * class_template_decl ,
int kind ,
const TemplateParameterInfos & template_param_infos )
{
ASTContext * ast = getASTContext ( ) ;
ClassTemplateSpecializationDecl * class_template_specialization_decl = ClassTemplateSpecializationDecl : : Create ( * ast ,
( TagDecl : : TagKind ) kind ,
decl_ctx ,
SourceLocation ( ) ,
SourceLocation ( ) ,
class_template_decl ,
& template_param_infos . args . front ( ) ,
template_param_infos . args . size ( ) ,
2014-04-20 21:17:36 +08:00
nullptr ) ;
2011-10-22 11:33:13 +08:00
2013-02-01 14:55:48 +08:00
class_template_specialization_decl - > setSpecializationKind ( TSK_ExplicitSpecialization ) ;
2011-10-22 11:33:13 +08:00
return class_template_specialization_decl ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2011-10-22 11:33:13 +08:00
ClangASTContext : : CreateClassTemplateSpecializationType ( ClassTemplateSpecializationDecl * class_template_specialization_decl )
{
if ( class_template_specialization_decl )
{
ASTContext * ast = getASTContext ( ) ;
if ( ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getTagDeclType ( class_template_specialization_decl ) ) ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-06-09 00:52:24 +08:00
}
2011-06-19 11:43:27 +08:00
static inline bool
2011-10-15 09:15:07 +08:00
check_op_param ( uint32_t op_kind , bool unary , bool binary , uint32_t num_params )
2011-06-19 11:43:27 +08:00
{
2011-10-15 09:15:07 +08:00
// Special-case call since it can take any number of operands
if ( op_kind = = OO_Call )
return true ;
2014-07-02 05:22:11 +08:00
// The parameter count doesn't include "this"
2011-06-19 11:43:27 +08:00
if ( num_params = = 0 )
return unary ;
if ( num_params = = 1 )
return binary ;
2011-10-15 09:15:07 +08:00
else
2011-06-19 11:43:27 +08:00
return false ;
}
2011-11-01 06:50:57 +08:00
2011-06-19 11:43:27 +08:00
bool
ClangASTContext : : CheckOverloadedOperatorKindParameterCount ( uint32_t op_kind , uint32_t num_params )
{
2012-02-04 16:49:35 +08:00
switch ( op_kind )
{
default :
break ;
// C++ standard allows any number of arguments to new/delete
case OO_New :
case OO_Array_New :
case OO_Delete :
case OO_Array_Delete :
return true ;
}
2011-10-15 09:15:07 +08:00
# define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) case OO_##Name: return check_op_param (op_kind, Unary, Binary, num_params);
2011-06-19 11:43:27 +08:00
switch ( op_kind )
{
# include "clang/Basic/OperatorKinds.def"
default : break ;
}
return false ;
}
2013-07-12 06:46:58 +08:00
clang : : AccessSpecifier
ClangASTContext : : UnifyAccessSpecifiers ( clang : : AccessSpecifier lhs , clang : : AccessSpecifier rhs )
2010-09-17 10:58:26 +08:00
{
2013-07-12 06:46:58 +08:00
clang : : AccessSpecifier ret = lhs ;
2010-09-24 13:15:53 +08:00
2013-07-12 06:46:58 +08:00
// Make the access equal to the stricter of the field and the nested field's access
switch ( ret )
{
case clang : : AS_none :
break ;
case clang : : AS_private :
break ;
case clang : : AS_protected :
if ( rhs = = AS_private )
ret = AS_private ;
break ;
case clang : : AS_public :
ret = rhs ;
break ;
}
Removed the hacky "#define this ___clang_this" handler
for C++ classes. Replaced it with a less hacky approach:
- If an expression is defined in the context of a
method of class A, then that expression is wrapped as
___clang_class::___clang_expr(void*) { ... }
instead of ___clang_expr(void*) { ... }.
- ___clang_class is resolved as the type of the target
of the "this" pointer in the method the expression
is defined in.
- When reporting the type of ___clang_class, a method
with the signature ___clang_expr(void*) is added to
that class, so that Clang doesn't complain about a
method being defined without a corresponding
declaration.
- Whenever the expression gets called, "this" gets
looked up, type-checked, and then passed in as the
first argument.
This required the following changes:
- The ABIs were changed to support passing of the "this"
pointer as part of trivial calls.
- ThreadPlanCallFunction and ClangFunction were changed
to support passing of an optional "this" pointer.
- ClangUserExpression was extended to perform the
wrapping described above.
- ClangASTSource was changed to revert the changes
required by the hack.
- ClangExpressionParser, IRForTarget, and
ClangExpressionDeclMap were changed to handle
different manglings of ___clang_expr flexibly. This
meant no longer searching for a function called
___clang_expr, but rather looking for a function whose
name *contains* ___clang_expr.
- ClangExpressionParser and ClangExpressionDeclMap now
remember whether "this" is required, and know how to
look it up as necessary.
A few inheritance bugs remain, and I'm trying to resolve
these. But it is now possible to use "this" as well as
refer implicitly to member variables, when in the proper
context.
llvm-svn: 114384
2010-09-21 08:44:12 +08:00
2013-07-12 06:46:58 +08:00
return ret ;
}
2010-10-01 11:45:20 +08:00
2013-07-12 06:46:58 +08:00
bool
ClangASTContext : : FieldIsBitfield ( FieldDecl * field , uint32_t & bitfield_bit_size )
{
return FieldIsBitfield ( getASTContext ( ) , field , bitfield_bit_size ) ;
}
2010-06-09 00:52:24 +08:00
bool
ClangASTContext : : FieldIsBitfield
(
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ASTContext * ast ,
2010-06-09 00:52:24 +08:00
FieldDecl * field ,
uint32_t & bitfield_bit_size
)
{
2014-04-20 21:17:36 +08:00
if ( ast = = nullptr | | field = = nullptr )
2010-06-09 00:52:24 +08:00
return false ;
if ( field - > isBitField ( ) )
{
Expr * bit_width_expr = field - > getBitWidth ( ) ;
if ( bit_width_expr )
{
llvm : : APSInt bit_width_apsint ;
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
if ( bit_width_expr - > isIntegerConstantExpr ( bit_width_apsint , * ast ) )
2010-06-09 00:52:24 +08:00
{
bitfield_bit_size = bit_width_apsint . getLimitedValue ( UINT32_MAX ) ;
return true ;
}
}
}
return false ;
}
bool
ClangASTContext : : RecordHasFields ( const RecordDecl * record_decl )
{
2014-04-20 21:17:36 +08:00
if ( record_decl = = nullptr )
2010-06-09 00:52:24 +08:00
return false ;
if ( ! record_decl - > field_empty ( ) )
return true ;
// No fields, lets check this is a CXX record and check the base classes
const CXXRecordDecl * cxx_record_decl = dyn_cast < CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
const CXXRecordDecl * base_class_decl = cast < CXXRecordDecl > ( base_class - > getType ( ) - > getAs < RecordType > ( ) - > getDecl ( ) ) ;
if ( RecordHasFields ( base_class_decl ) )
return true ;
}
}
return false ;
}
2010-07-23 02:30:50 +08:00
# pragma mark Objective C Classes
2015-08-12 06:53:00 +08:00
CompilerType
2012-04-18 09:06:17 +08:00
ClangASTContext : : CreateObjCClass
2010-07-23 02:30:50 +08:00
(
const char * name ,
DeclContext * decl_ctx ,
bool isForwardDecl ,
2012-04-18 09:06:17 +08:00
bool isInternal ,
2012-10-27 10:54:13 +08:00
ClangASTMetadata * metadata
2010-07-23 02:30:50 +08:00
)
{
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ASTContext * ast = getASTContext ( ) ;
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
2010-07-23 02:30:50 +08:00
assert ( name & & name [ 0 ] ) ;
2014-04-20 21:17:36 +08:00
if ( decl_ctx = = nullptr )
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
decl_ctx = ast - > getTranslationUnitDecl ( ) ;
2010-07-23 02:30:50 +08:00
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
ObjCInterfaceDecl * decl = ObjCInterfaceDecl : : Create ( * ast ,
2010-07-23 02:30:50 +08:00
decl_ctx ,
SourceLocation ( ) ,
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
& ast - > Idents . get ( name ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
2015-07-07 18:11:16 +08:00
nullptr ,
2010-07-23 02:30:50 +08:00
SourceLocation ( ) ,
2012-02-04 16:49:35 +08:00
/*isForwardDecl,*/
2010-07-23 02:30:50 +08:00
isInternal ) ;
2010-07-28 10:04:09 +08:00
2012-10-27 10:54:13 +08:00
if ( decl & & metadata )
2013-03-27 09:48:02 +08:00
SetMetadata ( ast , decl , * metadata ) ;
2012-04-18 09:06:17 +08:00
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getObjCInterfaceType ( decl ) ) ;
2010-07-23 02:30:50 +08:00
}
2010-06-09 00:52:24 +08:00
2013-07-12 06:46:58 +08:00
static inline bool
BaseSpecifierIsEmpty ( const CXXBaseSpecifier * b )
{
return ClangASTContext : : RecordHasFields ( b - > getType ( ) - > getAsCXXRecordDecl ( ) ) = = false ;
}
uint32_t
ClangASTContext : : GetNumBaseClasses ( const CXXRecordDecl * cxx_record_decl , bool omit_empty_base_classes )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
uint32_t num_bases = 0 ;
if ( cxx_record_decl )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
if ( omit_empty_base_classes )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
// Skip empty base classes
if ( omit_empty_base_classes )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
if ( BaseSpecifierIsEmpty ( base_class ) )
continue ;
2010-07-23 02:30:50 +08:00
}
2013-07-12 06:46:58 +08:00
+ + num_bases ;
2010-07-23 02:30:50 +08:00
}
}
2013-07-12 06:46:58 +08:00
else
num_bases = cxx_record_decl - > getNumBases ( ) ;
2010-07-23 02:30:50 +08:00
}
2013-07-12 06:46:58 +08:00
return num_bases ;
2010-07-23 02:30:50 +08:00
}
2013-07-12 06:46:58 +08:00
# pragma mark Namespace Declarations
2010-07-23 02:30:50 +08:00
2013-07-12 06:46:58 +08:00
NamespaceDecl *
ClangASTContext : : GetUniqueNamespaceDeclaration ( const char * name , DeclContext * decl_ctx )
{
2014-04-20 21:17:36 +08:00
NamespaceDecl * namespace_decl = nullptr ;
2013-07-12 06:46:58 +08:00
ASTContext * ast = getASTContext ( ) ;
TranslationUnitDecl * translation_unit_decl = ast - > getTranslationUnitDecl ( ) ;
2014-04-20 21:17:36 +08:00
if ( decl_ctx = = nullptr )
2013-07-12 06:46:58 +08:00
decl_ctx = translation_unit_decl ;
2011-11-12 09:36:43 +08:00
2013-07-12 06:46:58 +08:00
if ( name )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
IdentifierInfo & identifier_info = ast - > Idents . get ( name ) ;
DeclarationName decl_name ( & identifier_info ) ;
clang : : DeclContext : : lookup_result result = decl_ctx - > lookup ( decl_name ) ;
for ( NamedDecl * decl : result )
2010-07-23 02:30:50 +08:00
{
2013-07-12 06:46:58 +08:00
namespace_decl = dyn_cast < clang : : NamespaceDecl > ( decl ) ;
if ( namespace_decl )
return namespace_decl ;
2011-11-12 09:36:43 +08:00
}
2010-07-28 10:04:09 +08:00
2013-07-12 06:46:58 +08:00
namespace_decl = NamespaceDecl : : Create ( * ast ,
decl_ctx ,
false ,
SourceLocation ( ) ,
SourceLocation ( ) ,
& identifier_info ,
2014-04-20 21:17:36 +08:00
nullptr ) ;
2010-07-28 10:04:09 +08:00
2013-07-12 06:46:58 +08:00
decl_ctx - > addDecl ( namespace_decl ) ;
2010-09-24 13:15:53 +08:00
}
2013-07-12 06:46:58 +08:00
else
2010-09-24 13:15:53 +08:00
{
2013-07-12 06:46:58 +08:00
if ( decl_ctx = = translation_unit_decl )
2010-09-24 13:15:53 +08:00
{
2013-07-12 06:46:58 +08:00
namespace_decl = translation_unit_decl - > getAnonymousNamespace ( ) ;
if ( namespace_decl )
return namespace_decl ;
namespace_decl = NamespaceDecl : : Create ( * ast ,
decl_ctx ,
false ,
2010-09-24 13:15:53 +08:00
SourceLocation ( ) ,
2011-03-15 08:17:19 +08:00
SourceLocation ( ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
nullptr ) ;
2013-07-12 06:46:58 +08:00
translation_unit_decl - > setAnonymousNamespace ( namespace_decl ) ;
translation_unit_decl - > addDecl ( namespace_decl ) ;
assert ( namespace_decl = = translation_unit_decl - > getAnonymousNamespace ( ) ) ;
2012-02-03 09:30:30 +08:00
}
2013-07-12 06:46:58 +08:00
else
2010-10-25 08:29:48 +08:00
{
2013-07-12 06:46:58 +08:00
NamespaceDecl * parent_namespace_decl = cast < NamespaceDecl > ( decl_ctx ) ;
if ( parent_namespace_decl )
2013-04-06 07:27:21 +08:00
{
2013-07-12 06:46:58 +08:00
namespace_decl = parent_namespace_decl - > getAnonymousNamespace ( ) ;
if ( namespace_decl )
return namespace_decl ;
namespace_decl = NamespaceDecl : : Create ( * ast ,
decl_ctx ,
false ,
SourceLocation ( ) ,
SourceLocation ( ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
nullptr ) ;
2013-07-12 06:46:58 +08:00
parent_namespace_decl - > setAnonymousNamespace ( namespace_decl ) ;
parent_namespace_decl - > addDecl ( namespace_decl ) ;
assert ( namespace_decl = = parent_namespace_decl - > getAnonymousNamespace ( ) ) ;
2013-04-06 07:27:21 +08:00
}
2013-07-12 06:46:58 +08:00
else
2013-04-06 07:27:21 +08:00
{
2013-07-12 06:46:58 +08:00
// BAD!!!
2013-04-06 07:27:21 +08:00
}
}
2010-06-09 00:52:24 +08:00
}
2011-10-26 09:06:27 +08:00
# ifdef LLDB_CONFIGURATION_DEBUG
2013-07-12 06:46:58 +08:00
VerifyDecl ( namespace_decl ) ;
# endif
return namespace_decl ;
2011-07-06 10:13:41 +08:00
}
2015-09-16 07:44:17 +08:00
clang : : BlockDecl *
ClangASTContext : : CreateBlockDeclaration ( clang : : DeclContext * ctx )
{
if ( ctx ! = nullptr )
{
clang : : BlockDecl * decl = clang : : BlockDecl : : Create ( * getASTContext ( ) , ctx , clang : : SourceLocation ( ) ) ;
ctx - > addDecl ( decl ) ;
return decl ;
}
return nullptr ;
}
2015-09-17 02:48:30 +08:00
clang : : DeclContext *
FindLCABetweenDecls ( clang : : DeclContext * left , clang : : DeclContext * right , clang : : DeclContext * root )
{
if ( root = = nullptr )
return nullptr ;
std : : set < clang : : DeclContext * > path_left ;
for ( clang : : DeclContext * d = left ; d ! = nullptr ; d = d - > getParent ( ) )
path_left . insert ( d ) ;
for ( clang : : DeclContext * d = right ; d ! = nullptr ; d = d - > getParent ( ) )
if ( path_left . find ( d ) ! = path_left . end ( ) )
return d ;
return nullptr ;
}
2015-09-16 07:44:17 +08:00
clang : : UsingDirectiveDecl *
ClangASTContext : : CreateUsingDirectiveDeclaration ( clang : : DeclContext * decl_ctx , clang : : NamespaceDecl * ns_decl )
{
if ( decl_ctx ! = nullptr & & ns_decl ! = nullptr )
{
2015-09-17 02:48:30 +08:00
clang : : TranslationUnitDecl * translation_unit = ( clang : : TranslationUnitDecl * ) GetTranslationUnitDecl ( getASTContext ( ) ) ;
2015-09-16 07:44:17 +08:00
clang : : UsingDirectiveDecl * using_decl = clang : : UsingDirectiveDecl : : Create ( * getASTContext ( ) ,
decl_ctx ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
clang : : NestedNameSpecifierLoc ( ) ,
clang : : SourceLocation ( ) ,
ns_decl ,
2015-09-17 02:48:30 +08:00
FindLCABetweenDecls ( decl_ctx , ns_decl , translation_unit ) ) ;
2015-09-16 07:44:17 +08:00
decl_ctx - > addDecl ( using_decl ) ;
return using_decl ;
}
return nullptr ;
}
clang : : UsingDecl *
ClangASTContext : : CreateUsingDeclaration ( clang : : DeclContext * current_decl_ctx , clang : : NamedDecl * target )
{
if ( current_decl_ctx ! = nullptr & & target ! = nullptr )
{
clang : : UsingDecl * using_decl = clang : : UsingDecl : : Create ( * getASTContext ( ) ,
current_decl_ctx ,
clang : : SourceLocation ( ) ,
clang : : NestedNameSpecifierLoc ( ) ,
clang : : DeclarationNameInfo ( ) ,
false ) ;
clang : : UsingShadowDecl * shadow_decl = clang : : UsingShadowDecl : : Create ( * getASTContext ( ) ,
current_decl_ctx ,
clang : : SourceLocation ( ) ,
using_decl ,
target ) ;
using_decl - > addShadowDecl ( shadow_decl ) ;
current_decl_ctx - > addDecl ( using_decl ) ;
return using_decl ;
}
return nullptr ;
}
clang : : VarDecl *
ClangASTContext : : CreateVariableDeclaration ( clang : : DeclContext * decl_context , const char * name , clang : : QualType type )
{
if ( decl_context ! = nullptr )
{
clang : : VarDecl * var_decl = clang : : VarDecl : : Create ( * getASTContext ( ) ,
decl_context ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
name & & name [ 0 ] ? & getASTContext ( ) - > Idents . getOwn ( name ) : nullptr ,
type ,
nullptr ,
clang : : SC_None ) ;
var_decl - > setAccess ( clang : : AS_public ) ;
decl_context - > addDecl ( var_decl ) ;
return var_decl ;
}
return nullptr ;
}
2013-07-12 06:46:58 +08:00
# pragma mark Function Types
2010-10-15 06:52:14 +08:00
2013-07-12 06:46:58 +08:00
FunctionDecl *
ClangASTContext : : CreateFunctionDeclaration ( DeclContext * decl_ctx ,
const char * name ,
2015-08-12 06:53:00 +08:00
const CompilerType & function_clang_type ,
2013-07-12 06:46:58 +08:00
int storage ,
bool is_inline )
2010-10-15 06:52:14 +08:00
{
2014-04-20 21:17:36 +08:00
FunctionDecl * func_decl = nullptr ;
2013-07-12 06:46:58 +08:00
ASTContext * ast = getASTContext ( ) ;
2014-04-20 21:17:36 +08:00
if ( decl_ctx = = nullptr )
2013-07-12 06:46:58 +08:00
decl_ctx = ast - > getTranslationUnitDecl ( ) ;
2010-10-15 06:52:14 +08:00
2013-07-12 06:46:58 +08:00
const bool hasWrittenPrototype = true ;
const bool isConstexprSpecified = false ;
2010-10-15 06:52:14 +08:00
2013-07-12 06:46:58 +08:00
if ( name & & name [ 0 ] )
2010-09-24 13:15:53 +08:00
{
2013-07-12 06:46:58 +08:00
func_decl = FunctionDecl : : Create ( * ast ,
decl_ctx ,
SourceLocation ( ) ,
SourceLocation ( ) ,
DeclarationName ( & ast - > Idents . get ( name ) ) ,
2015-08-12 05:38:15 +08:00
GetQualType ( function_clang_type ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
2014-11-01 07:20:13 +08:00
( clang : : StorageClass ) storage ,
2013-07-12 06:46:58 +08:00
is_inline ,
hasWrittenPrototype ,
isConstexprSpecified ) ;
2010-09-24 13:15:53 +08:00
}
2013-07-12 06:46:58 +08:00
else
2011-10-14 07:13:20 +08:00
{
2013-07-12 06:46:58 +08:00
func_decl = FunctionDecl : : Create ( * ast ,
decl_ctx ,
SourceLocation ( ) ,
SourceLocation ( ) ,
DeclarationName ( ) ,
2015-08-12 05:38:15 +08:00
GetQualType ( function_clang_type ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
2014-11-01 07:20:13 +08:00
( clang : : StorageClass ) storage ,
2013-07-12 06:46:58 +08:00
is_inline ,
hasWrittenPrototype ,
isConstexprSpecified ) ;
2011-10-14 07:13:20 +08:00
}
2013-07-12 06:46:58 +08:00
if ( func_decl )
decl_ctx - > addDecl ( func_decl ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( func_decl ) ;
# endif
return func_decl ;
2011-10-14 07:13:20 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2013-07-12 06:46:58 +08:00
ClangASTContext : : CreateFunctionType ( ASTContext * ast ,
2015-08-12 06:53:00 +08:00
const CompilerType & result_type ,
const CompilerType * args ,
2013-07-12 06:46:58 +08:00
unsigned num_args ,
bool is_variadic ,
unsigned type_quals )
2010-09-24 13:15:53 +08:00
{
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
2013-07-12 06:46:58 +08:00
std : : vector < QualType > qual_type_args ;
for ( unsigned i = 0 ; i < num_args ; + + i )
2015-08-12 05:38:15 +08:00
qual_type_args . push_back ( GetQualType ( args [ i ] ) ) ;
2010-09-24 13:15:53 +08:00
2013-07-12 06:46:58 +08:00
// TODO: Detect calling convention in DWARF?
FunctionProtoType : : ExtProtoInfo proto_info ;
proto_info . Variadic = is_variadic ;
2014-08-01 20:19:15 +08:00
proto_info . ExceptionSpec = EST_None ;
2013-07-12 06:46:58 +08:00
proto_info . TypeQuals = type_quals ;
proto_info . RefQualifier = RQ_None ;
2014-08-01 20:19:15 +08:00
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getFunctionType ( GetQualType ( result_type ) ,
2013-07-12 06:46:58 +08:00
qual_type_args ,
2015-08-12 05:38:15 +08:00
proto_info ) ) ;
2012-02-23 07:57:45 +08:00
}
2013-07-12 06:46:58 +08:00
ParmVarDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : CreateParameterDeclaration ( const char * name , const CompilerType & param_type , int storage )
2012-02-23 07:57:45 +08:00
{
2013-07-12 06:46:58 +08:00
ASTContext * ast = getASTContext ( ) ;
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
2013-07-12 06:46:58 +08:00
return ParmVarDecl : : Create ( * ast ,
ast - > getTranslationUnitDecl ( ) ,
SourceLocation ( ) ,
SourceLocation ( ) ,
2014-04-20 21:17:36 +08:00
name & & name [ 0 ] ? & ast - > Idents . get ( name ) : nullptr ,
2015-08-12 05:38:15 +08:00
GetQualType ( param_type ) ,
2014-04-20 21:17:36 +08:00
nullptr ,
2014-11-01 07:20:13 +08:00
( clang : : StorageClass ) storage ,
2014-04-20 21:17:36 +08:00
nullptr ) ;
2012-02-23 07:57:45 +08:00
}
2010-09-24 13:15:53 +08:00
2013-07-12 06:46:58 +08:00
void
ClangASTContext : : SetFunctionParameters ( FunctionDecl * function_decl , ParmVarDecl * * params , unsigned num_params )
2010-10-27 11:32:59 +08:00
{
2013-07-12 06:46:58 +08:00
if ( function_decl )
function_decl - > setParams ( ArrayRef < ParmVarDecl * > ( params , num_params ) ) ;
2010-10-27 11:32:59 +08:00
}
2010-06-09 00:52:24 +08:00
2010-10-27 11:32:59 +08:00
2013-07-12 06:46:58 +08:00
# pragma mark Array Types
2015-08-12 06:53:00 +08:00
CompilerType
ClangASTContext : : CreateArrayType ( const CompilerType & element_type ,
2013-07-12 06:46:58 +08:00
size_t element_count ,
bool is_vector )
{
if ( element_type . IsValid ( ) )
2010-06-09 00:52:24 +08:00
{
2013-07-12 06:46:58 +08:00
ASTContext * ast = getASTContext ( ) ;
2014-04-20 21:17:36 +08:00
assert ( ast ! = nullptr ) ;
2013-07-12 06:46:58 +08:00
if ( is_vector )
{
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getExtVectorType ( GetQualType ( element_type ) , element_count ) ) ;
2013-07-12 06:46:58 +08:00
}
else
2010-06-09 00:52:24 +08:00
{
2013-07-12 06:46:58 +08:00
llvm : : APInt ap_element_count ( 64 , element_count ) ;
if ( element_count = = 0 )
2010-06-09 00:52:24 +08:00
{
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getIncompleteArrayType ( GetQualType ( element_type ) ,
2013-07-12 06:46:58 +08:00
ArrayType : : Normal ,
2015-08-12 05:38:15 +08:00
0 ) ) ;
2010-06-09 00:52:24 +08:00
}
2010-10-27 11:32:59 +08:00
else
2010-06-09 00:52:24 +08:00
{
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getConstantArrayType ( GetQualType ( element_type ) ,
2013-07-12 06:46:58 +08:00
ap_element_count ,
ArrayType : : Normal ,
2015-08-12 05:38:15 +08:00
0 ) ) ;
2010-09-13 11:32:57 +08:00
}
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-09-13 11:32:57 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2014-10-30 07:08:02 +08:00
ClangASTContext : : GetOrCreateStructForIdentifier ( const ConstString & type_name ,
2015-08-12 06:53:00 +08:00
const std : : initializer_list < std : : pair < const char * , CompilerType > > & type_fields ,
2014-10-30 08:53:28 +08:00
bool packed )
2014-10-30 07:08:02 +08:00
{
2015-08-12 06:53:00 +08:00
CompilerType type ;
2014-10-30 07:08:02 +08:00
if ( ( type = GetTypeForIdentifier < clang : : CXXRecordDecl > ( type_name ) ) . IsValid ( ) )
return type ;
type = CreateRecordType ( nullptr , lldb : : eAccessPublic , type_name . GetCString ( ) , clang : : TTK_Struct , lldb : : eLanguageTypeC ) ;
2015-08-12 05:38:15 +08:00
StartTagDeclarationDefinition ( type ) ;
2014-10-30 07:08:02 +08:00
for ( const auto & field : type_fields )
2015-08-12 05:38:15 +08:00
AddFieldToRecordType ( type , field . first , field . second , lldb : : eAccessPublic , 0 ) ;
2014-10-30 08:53:28 +08:00
if ( packed )
2015-08-12 05:38:15 +08:00
SetIsPacked ( type ) ;
CompleteTagDeclarationDefinition ( type ) ;
2014-10-30 07:08:02 +08:00
return type ;
}
2013-05-03 02:54:54 +08:00
2013-07-12 06:46:58 +08:00
# pragma mark Enumeration Types
2010-09-13 11:32:57 +08:00
2015-08-12 06:53:00 +08:00
CompilerType
2015-08-12 05:38:15 +08:00
ClangASTContext : : CreateEnumerationType
2013-07-12 06:46:58 +08:00
(
2015-08-12 05:38:15 +08:00
const char * name ,
DeclContext * decl_ctx ,
const Declaration & decl ,
2015-08-12 06:53:00 +08:00
const CompilerType & integer_clang_type
2015-08-12 05:38:15 +08:00
)
2010-06-09 00:52:24 +08:00
{
2013-07-12 06:46:58 +08:00
// TODO: Do something intelligent with the Declaration object passed in
// like maybe filling in the SourceLocation with it...
ASTContext * ast = getASTContext ( ) ;
2015-08-12 05:38:15 +08:00
2013-07-12 06:46:58 +08:00
// TODO: ask about these...
2015-08-12 05:38:15 +08:00
// const bool IsScoped = false;
// const bool IsFixed = false;
2013-07-12 06:46:58 +08:00
EnumDecl * enum_decl = EnumDecl : : Create ( * ast ,
decl_ctx ,
SourceLocation ( ) ,
SourceLocation ( ) ,
2014-04-20 21:17:36 +08:00
name & & name [ 0 ] ? & ast - > Idents . get ( name ) : nullptr ,
nullptr ,
2013-07-12 06:46:58 +08:00
false , // IsScoped
false , // IsScopedUsingClassTag
false ) ; // IsFixed
2011-07-10 01:12:27 +08:00
2011-08-12 07:56:13 +08:00
2013-07-12 06:46:58 +08:00
if ( enum_decl )
2010-06-09 00:52:24 +08:00
{
2013-07-12 06:46:58 +08:00
// TODO: check if we should be setting the promotion type too?
2015-08-12 05:38:15 +08:00
enum_decl - > setIntegerType ( GetQualType ( integer_clang_type ) ) ;
2011-01-18 09:03:44 +08:00
2013-07-12 06:46:58 +08:00
enum_decl - > setAccess ( AS_public ) ; // TODO respect what's in the debug info
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > getTagDeclType ( enum_decl ) ) ;
2010-06-09 00:52:24 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2010-06-09 00:52:24 +08:00
}
// Disable this for now since I can't seem to get a nicely formatted float
// out of the APFloat class without just getting the float, double or quad
// and then using a formatted print on it which defeats the purpose. We ideally
// would like to get perfect string values for any kind of float semantics
// so we can support remote targets. The code below also requires a patch to
// llvm::APInt.
//bool
2015-09-23 08:18:24 +08:00
//ClangASTContext::ConvertFloatValueToString (ASTContext *ast, lldb::opaque_compiler_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str)
2010-06-09 00:52:24 +08:00
//{
// uint32_t count = 0;
// bool is_complex = false;
// if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex))
// {
// unsigned num_bytes_per_float = byte_size / count;
// unsigned num_bits_per_float = num_bytes_per_float * 8;
//
// float_str.clear();
// uint32_t i;
// for (i=0; i<count; i++)
// {
// APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order);
// bool is_ieee = false;
// APFloat ap_float(ap_int, is_ieee);
// char s[1024];
// unsigned int hex_digits = 0;
// bool upper_case = false;
//
// if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0)
// {
// if (i > 0)
// float_str.append(", ");
// float_str.append(s);
// if (i == 1 && is_complex)
// float_str.append(1, 'i');
// }
// }
// return !float_str.empty();
// }
// return false;
//}
2015-08-12 06:53:00 +08:00
CompilerType
2014-08-16 07:00:02 +08:00
ClangASTContext : : GetIntTypeFromBitSize ( clang : : ASTContext * ast ,
size_t bit_size , bool is_signed )
{
if ( ast )
{
if ( is_signed )
{
if ( bit_size = = ast - > getTypeSize ( ast - > SignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > SignedCharTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > ShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > ShortTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > IntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > IntTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > LongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > LongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > LongLongTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > Int128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > Int128Ty ) ;
2014-08-16 07:00:02 +08:00
}
else
{
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedCharTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedCharTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedShortTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedShortTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedIntTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedIntTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedLongLongTy ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedLongLongTy ) ;
2014-08-16 07:00:02 +08:00
if ( bit_size = = ast - > getTypeSize ( ast - > UnsignedInt128Ty ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ast , ast - > UnsignedInt128Ty ) ;
2014-08-16 07:00:02 +08:00
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2014-08-16 07:00:02 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2014-08-16 07:00:02 +08:00
ClangASTContext : : GetPointerSizedIntType ( clang : : ASTContext * ast , bool is_signed )
{
if ( ast )
return GetIntTypeFromBitSize ( ast , ast - > getTypeSize ( ast - > VoidPtrTy ) , is_signed ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2014-08-16 07:00:02 +08:00
}
2010-09-17 10:24:29 +08:00
2011-06-25 08:44:06 +08:00
bool
ClangASTContext : : GetCompleteDecl ( clang : : ASTContext * ast ,
clang : : Decl * decl )
{
if ( ! decl )
return false ;
ExternalASTSource * ast_source = ast - > getExternalSource ( ) ;
if ( ! ast_source )
return false ;
if ( clang : : TagDecl * tag_decl = llvm : : dyn_cast < clang : : TagDecl > ( decl ) )
{
2012-03-30 08:51:13 +08:00
if ( tag_decl - > isCompleteDefinition ( ) )
2011-06-25 08:44:06 +08:00
return true ;
if ( ! tag_decl - > hasExternalLexicalStorage ( ) )
return false ;
ast_source - > CompleteType ( tag_decl ) ;
return ! tag_decl - > getTypeForDecl ( ) - > isIncompleteType ( ) ;
}
else if ( clang : : ObjCInterfaceDecl * objc_interface_decl = llvm : : dyn_cast < clang : : ObjCInterfaceDecl > ( decl ) )
{
2012-02-04 16:49:35 +08:00
if ( objc_interface_decl - > getDefinition ( ) )
2011-06-25 08:44:06 +08:00
return true ;
if ( ! objc_interface_decl - > hasExternalLexicalStorage ( ) )
return false ;
ast_source - > CompleteType ( objc_interface_decl ) ;
2012-02-04 16:49:35 +08:00
return ! objc_interface_decl - > getTypeForDecl ( ) - > isIncompleteType ( ) ;
2011-06-25 08:44:06 +08:00
}
else
{
return false ;
}
}
2012-10-27 10:54:13 +08:00
void
2013-03-27 09:48:02 +08:00
ClangASTContext : : SetMetadataAsUserID ( const void * object ,
2012-10-27 10:54:13 +08:00
user_id_t user_id )
{
ClangASTMetadata meta_data ;
meta_data . SetUserID ( user_id ) ;
SetMetadata ( object , meta_data ) ;
}
2012-04-13 08:10:03 +08:00
void
ClangASTContext : : SetMetadata ( clang : : ASTContext * ast ,
2013-03-27 09:48:02 +08:00
const void * object ,
2012-10-27 10:54:13 +08:00
ClangASTMetadata & metadata )
2012-04-13 08:10:03 +08:00
{
ClangExternalASTSourceCommon * external_source =
2014-12-06 09:03:30 +08:00
ClangExternalASTSourceCommon : : Lookup ( ast - > getExternalSource ( ) ) ;
2012-04-13 08:10:03 +08:00
if ( external_source )
external_source - > SetMetadata ( object , metadata ) ;
}
2012-10-27 10:54:13 +08:00
ClangASTMetadata *
2012-04-13 08:10:03 +08:00
ClangASTContext : : GetMetadata ( clang : : ASTContext * ast ,
2013-03-27 09:48:02 +08:00
const void * object )
2012-04-13 08:10:03 +08:00
{
ClangExternalASTSourceCommon * external_source =
2014-12-06 09:03:30 +08:00
ClangExternalASTSourceCommon : : Lookup ( ast - > getExternalSource ( ) ) ;
2012-04-13 08:10:03 +08:00
if ( external_source & & external_source - > HasMetadata ( object ) )
return external_source - > GetMetadata ( object ) ;
else
2014-04-20 21:17:36 +08:00
return nullptr ;
2012-04-13 08:10:03 +08:00
}
2011-08-05 05:02:57 +08:00
clang : : DeclContext *
ClangASTContext : : GetAsDeclContext ( clang : : CXXMethodDecl * cxx_method_decl )
{
2011-08-19 14:19:25 +08:00
return llvm : : dyn_cast < clang : : DeclContext > ( cxx_method_decl ) ;
2011-08-05 05:02:57 +08:00
}
clang : : DeclContext *
ClangASTContext : : GetAsDeclContext ( clang : : ObjCMethodDecl * objc_method_decl )
{
2011-08-19 14:19:25 +08:00
return llvm : : dyn_cast < clang : : DeclContext > ( objc_method_decl ) ;
2011-08-05 05:02:57 +08:00
}
2015-08-12 05:38:15 +08:00
bool
ClangASTContext : : SetTagTypeKind ( clang : : QualType tag_qual_type , int kind ) const
{
const clang : : Type * clang_type = tag_qual_type . getTypePtr ( ) ;
if ( clang_type )
{
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( clang_type ) ;
if ( tag_type )
{
clang : : TagDecl * tag_decl = llvm : : dyn_cast < clang : : TagDecl > ( tag_type - > getDecl ( ) ) ;
if ( tag_decl )
{
tag_decl - > setTagKind ( ( clang : : TagDecl : : TagKind ) kind ) ;
return true ;
}
}
}
return false ;
}
bool
ClangASTContext : : SetDefaultAccessForRecordFields ( clang : : RecordDecl * record_decl ,
int default_accessibility ,
int * assigned_accessibilities ,
size_t num_assigned_accessibilities )
{
if ( record_decl )
{
uint32_t field_idx ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) , field_idx = 0 ;
field ! = field_end ;
+ + field , + + field_idx )
{
// If no accessibility was assigned, assign the correct one
if ( field_idx < num_assigned_accessibilities & & assigned_accessibilities [ field_idx ] = = clang : : AS_none )
field - > setAccess ( ( clang : : AccessSpecifier ) default_accessibility ) ;
}
return true ;
}
return false ;
}
2015-08-25 07:46:31 +08:00
clang : : DeclContext *
ClangASTContext : : GetDeclContextForType ( const CompilerType & type )
{
return GetDeclContextForType ( GetQualType ( type ) ) ;
}
2015-08-12 05:38:15 +08:00
clang : : DeclContext *
ClangASTContext : : GetDeclContextForType ( clang : : QualType type )
{
if ( type . isNull ( ) )
return nullptr ;
clang : : QualType qual_type = type . getCanonicalType ( ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : ObjCInterface : return llvm : : cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) - > getInterface ( ) ;
case clang : : Type : : ObjCObjectPointer : return GetDeclContextForType ( llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type . getTypePtr ( ) ) - > getPointeeType ( ) ) ;
case clang : : Type : : Record : return llvm : : cast < clang : : RecordType > ( qual_type ) - > getDecl ( ) ;
case clang : : Type : : Enum : return llvm : : cast < clang : : EnumType > ( qual_type ) - > getDecl ( ) ;
case clang : : Type : : Typedef : return GetDeclContextForType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) ;
case clang : : Type : : Elaborated : return GetDeclContextForType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) ;
case clang : : Type : : Paren : return GetDeclContextForType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) ;
2015-08-25 07:46:31 +08:00
default :
break ;
2015-08-12 05:38:15 +08:00
}
// No DeclContext in this type...
return nullptr ;
}
static bool
GetCompleteQualType ( clang : : ASTContext * ast , clang : : QualType qual_type , bool allow_completion = true )
{
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : ConstantArray :
case clang : : Type : : IncompleteArray :
case clang : : Type : : VariableArray :
{
const clang : : ArrayType * array_type = llvm : : dyn_cast < clang : : ArrayType > ( qual_type . getTypePtr ( ) ) ;
if ( array_type )
return GetCompleteQualType ( ast , array_type - > getElementType ( ) , allow_completion ) ;
}
break ;
case clang : : Type : : Record :
case clang : : Type : : Enum :
{
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( qual_type . getTypePtr ( ) ) ;
if ( tag_type )
{
clang : : TagDecl * tag_decl = tag_type - > getDecl ( ) ;
if ( tag_decl )
{
if ( tag_decl - > isCompleteDefinition ( ) )
return true ;
if ( ! allow_completion )
return false ;
if ( tag_decl - > hasExternalLexicalStorage ( ) )
{
if ( ast )
{
clang : : ExternalASTSource * external_ast_source = ast - > getExternalSource ( ) ;
if ( external_ast_source )
{
external_ast_source - > CompleteType ( tag_decl ) ;
return ! tag_type - > isIncompleteType ( ) ;
}
}
}
return false ;
}
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
// We currently can't complete objective C types through the newly added ASTContext
// because it only supports TagDecl objects right now...
if ( class_interface_decl )
{
if ( class_interface_decl - > getDefinition ( ) )
return true ;
if ( ! allow_completion )
return false ;
if ( class_interface_decl - > hasExternalLexicalStorage ( ) )
{
if ( ast )
{
clang : : ExternalASTSource * external_ast_source = ast - > getExternalSource ( ) ;
if ( external_ast_source )
{
external_ast_source - > CompleteType ( class_interface_decl ) ;
return ! objc_class_type - > isIncompleteType ( ) ;
}
}
}
return false ;
}
}
}
break ;
case clang : : Type : : Typedef :
return GetCompleteQualType ( ast , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) , allow_completion ) ;
case clang : : Type : : Elaborated :
return GetCompleteQualType ( ast , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) , allow_completion ) ;
case clang : : Type : : Paren :
return GetCompleteQualType ( ast , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) , allow_completion ) ;
default :
break ;
}
return true ;
}
static clang : : ObjCIvarDecl : : AccessControl
ConvertAccessTypeToObjCIvarAccessControl ( AccessType access )
{
switch ( access )
{
case eAccessNone : return clang : : ObjCIvarDecl : : None ;
case eAccessPublic : return clang : : ObjCIvarDecl : : Public ;
case eAccessPrivate : return clang : : ObjCIvarDecl : : Private ;
case eAccessProtected : return clang : : ObjCIvarDecl : : Protected ;
case eAccessPackage : return clang : : ObjCIvarDecl : : Package ;
}
return clang : : ObjCIvarDecl : : None ;
}
//----------------------------------------------------------------------
// Tests
//----------------------------------------------------------------------
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsAggregateType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : IncompleteArray :
case clang : : Type : : VariableArray :
case clang : : Type : : ConstantArray :
case clang : : Type : : ExtVector :
case clang : : Type : : Vector :
case clang : : Type : : Record :
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
return true ;
case clang : : Type : : Elaborated :
return IsAggregateType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ) ;
case clang : : Type : : Typedef :
return IsAggregateType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ) ;
case clang : : Type : : Paren :
return IsAggregateType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ) ;
default :
break ;
}
// The clang type does have a value
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsArrayType ( lldb : : opaque_compiler_type_t type ,
2015-08-12 06:53:00 +08:00
CompilerType * element_type_ptr ,
2015-08-12 05:38:15 +08:00
uint64_t * size ,
bool * is_incomplete )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
default :
break ;
2015-10-09 20:43:08 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : ConstantArray :
if ( element_type_ptr )
2015-08-25 07:46:31 +08:00
element_type_ptr - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ConstantArrayType > ( qual_type ) - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( size )
* size = llvm : : cast < clang : : ConstantArrayType > ( qual_type ) - > getSize ( ) . getLimitedValue ( ULLONG_MAX ) ;
2015-10-09 20:43:08 +08:00
if ( is_incomplete )
* is_incomplete = false ;
2015-08-12 05:38:15 +08:00
return true ;
2015-10-09 20:43:08 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : IncompleteArray :
if ( element_type_ptr )
2015-08-25 07:46:31 +08:00
element_type_ptr - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : IncompleteArrayType > ( qual_type ) - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( size )
* size = 0 ;
if ( is_incomplete )
* is_incomplete = true ;
return true ;
2015-10-09 20:43:08 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : VariableArray :
if ( element_type_ptr )
2015-08-25 07:46:31 +08:00
element_type_ptr - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : VariableArrayType > ( qual_type ) - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( size )
* size = 0 ;
2015-10-09 20:43:08 +08:00
if ( is_incomplete )
* is_incomplete = false ;
2015-08-12 05:38:15 +08:00
return true ;
2015-10-09 20:43:08 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : DependentSizedArray :
if ( element_type_ptr )
2015-08-25 07:46:31 +08:00
element_type_ptr - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : DependentSizedArrayType > ( qual_type ) - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( size )
* size = 0 ;
2015-10-09 20:43:08 +08:00
if ( is_incomplete )
* is_incomplete = false ;
2015-08-12 05:38:15 +08:00
return true ;
2015-10-09 20:43:08 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : Typedef :
return IsArrayType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ,
element_type_ptr ,
size ,
is_incomplete ) ;
case clang : : Type : : Elaborated :
return IsArrayType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ,
element_type_ptr ,
size ,
is_incomplete ) ;
case clang : : Type : : Paren :
return IsArrayType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ,
element_type_ptr ,
size ,
is_incomplete ) ;
}
if ( element_type_ptr )
element_type_ptr - > Clear ( ) ;
if ( size )
* size = 0 ;
if ( is_incomplete )
* is_incomplete = false ;
2015-09-16 08:00:16 +08:00
return false ;
2015-08-12 05:38:15 +08:00
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsVectorType ( lldb : : opaque_compiler_type_t type ,
2015-08-12 06:53:00 +08:00
CompilerType * element_type ,
2015-08-12 05:38:15 +08:00
uint64_t * size )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Vector :
{
const clang : : VectorType * vector_type = qual_type - > getAs < clang : : VectorType > ( ) ;
if ( vector_type )
{
if ( size )
* size = vector_type - > getNumElements ( ) ;
if ( element_type )
2015-08-12 06:53:00 +08:00
* element_type = CompilerType ( getASTContext ( ) , vector_type - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
return true ;
}
break ;
case clang : : Type : : ExtVector :
{
const clang : : ExtVectorType * ext_vector_type = qual_type - > getAs < clang : : ExtVectorType > ( ) ;
if ( ext_vector_type )
{
if ( size )
* size = ext_vector_type - > getNumElements ( ) ;
if ( element_type )
2015-08-12 06:53:00 +08:00
* element_type = CompilerType ( getASTContext ( ) , ext_vector_type - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
return true ;
}
default :
break ;
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsRuntimeGeneratedType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
clang : : DeclContext * decl_ctx = ClangASTContext : : GetASTContext ( getASTContext ( ) ) - > GetDeclContextForType ( GetQualType ( type ) ) ;
if ( ! decl_ctx )
return false ;
if ( ! llvm : : isa < clang : : ObjCInterfaceDecl > ( decl_ctx ) )
return false ;
clang : : ObjCInterfaceDecl * result_iface_decl = llvm : : dyn_cast < clang : : ObjCInterfaceDecl > ( decl_ctx ) ;
ClangASTMetadata * ast_metadata = ClangASTContext : : GetMetadata ( getASTContext ( ) , result_iface_decl ) ;
if ( ! ast_metadata )
return false ;
return ( ast_metadata - > GetISAPtr ( ) ! = 0 ) ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsCharType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
return GetQualType ( type ) . getUnqualifiedType ( ) - > isCharType ( ) ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsCompleteType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
const bool allow_completion = false ;
return GetCompleteQualType ( getASTContext ( ) , GetQualType ( type ) , allow_completion ) ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsConst ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
return GetQualType ( type ) . isConstQualified ( ) ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsCStringType ( lldb : : opaque_compiler_type_t type , uint32_t & length )
2015-08-12 05:38:15 +08:00
{
2015-08-12 06:53:00 +08:00
CompilerType pointee_or_element_clang_type ;
2015-08-12 05:38:15 +08:00
length = 0 ;
Flags type_flags ( GetTypeInfo ( type , & pointee_or_element_clang_type ) ) ;
if ( ! pointee_or_element_clang_type . IsValid ( ) )
return false ;
if ( type_flags . AnySet ( eTypeIsArray | eTypeIsPointer ) )
{
if ( pointee_or_element_clang_type . IsCharType ( ) )
{
if ( type_flags . Test ( eTypeIsArray ) )
{
// We know the size of the array and it could be a C string
// since it is an array of characters
length = llvm : : cast < clang : : ConstantArrayType > ( GetCanonicalQualType ( type ) . getTypePtr ( ) ) - > getSize ( ) . getLimitedValue ( ) ;
}
return true ;
}
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsFunctionType ( lldb : : opaque_compiler_type_t type , bool * is_variadic_ptr )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
if ( qual_type - > isFunctionType ( ) )
{
if ( is_variadic_ptr )
{
const clang : : FunctionProtoType * function_proto_type = llvm : : dyn_cast < clang : : FunctionProtoType > ( qual_type . getTypePtr ( ) ) ;
if ( function_proto_type )
* is_variadic_ptr = function_proto_type - > isVariadic ( ) ;
else
* is_variadic_ptr = false ;
}
return true ;
}
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
default :
break ;
case clang : : Type : : Typedef :
return IsFunctionType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , nullptr ) ;
case clang : : Type : : Elaborated :
return IsFunctionType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , nullptr ) ;
case clang : : Type : : Paren :
return IsFunctionType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , nullptr ) ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) ;
if ( reference_type )
return IsFunctionType ( reference_type - > getPointeeType ( ) . getAsOpaquePtr ( ) , nullptr ) ;
}
break ;
}
}
return false ;
}
// Used to detect "Homogeneous Floating-point Aggregates"
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsHomogeneousAggregate ( lldb : : opaque_compiler_type_t type , CompilerType * base_type_ptr )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return 0 ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
if ( cxx_record_decl - > getNumBases ( ) | |
cxx_record_decl - > isDynamicClass ( ) )
return 0 ;
}
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
if ( record_type )
{
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
if ( record_decl )
{
// We are looking for a structure that contains only floating point types
clang : : RecordDecl : : field_iterator field_pos , field_end = record_decl - > field_end ( ) ;
uint32_t num_fields = 0 ;
bool is_hva = false ;
bool is_hfa = false ;
clang : : QualType base_qual_type ;
for ( field_pos = record_decl - > field_begin ( ) ; field_pos ! = field_end ; + + field_pos )
{
clang : : QualType field_qual_type = field_pos - > getType ( ) ;
if ( field_qual_type - > isFloatingType ( ) )
{
if ( field_qual_type - > isComplexType ( ) )
return 0 ;
else
{
if ( num_fields = = 0 )
base_qual_type = field_qual_type ;
else
{
if ( is_hva )
return 0 ;
is_hfa = true ;
if ( field_qual_type . getTypePtr ( ) ! = base_qual_type . getTypePtr ( ) )
return 0 ;
}
}
}
else if ( field_qual_type - > isVectorType ( ) | | field_qual_type - > isExtVectorType ( ) )
{
const clang : : VectorType * array = field_qual_type . getTypePtr ( ) - > getAs < clang : : VectorType > ( ) ;
if ( array & & array - > getNumElements ( ) < = 4 )
{
if ( num_fields = = 0 )
base_qual_type = array - > getElementType ( ) ;
else
{
if ( is_hfa )
return 0 ;
is_hva = true ;
if ( field_qual_type . getTypePtr ( ) ! = base_qual_type . getTypePtr ( ) )
return 0 ;
}
}
else
return 0 ;
}
else
return 0 ;
+ + num_fields ;
}
if ( base_type_ptr )
2015-08-12 06:53:00 +08:00
* base_type_ptr = CompilerType ( getASTContext ( ) , base_qual_type ) ;
2015-08-12 05:38:15 +08:00
return num_fields ;
}
}
}
break ;
case clang : : Type : : Typedef :
return IsHomogeneousAggregate ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , base_type_ptr ) ;
case clang : : Type : : Elaborated :
return IsHomogeneousAggregate ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , base_type_ptr ) ;
default :
break ;
}
return 0 ;
}
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumberOfFunctionArguments ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : FunctionProtoType * func = llvm : : dyn_cast < clang : : FunctionProtoType > ( qual_type . getTypePtr ( ) ) ;
if ( func )
return func - > getNumParams ( ) ;
}
return 0 ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFunctionArgumentAtIndex ( lldb : : opaque_compiler_type_t type , const size_t index )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : FunctionProtoType * func = llvm : : dyn_cast < clang : : FunctionProtoType > ( qual_type . getTypePtr ( ) ) ;
if ( func )
{
if ( index < func - > getNumParams ( ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , func - > getParamType ( index ) ) ;
2015-08-12 05:38:15 +08:00
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsFunctionPointerType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
if ( qual_type - > isFunctionPointerType ( ) )
return true ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
default :
break ;
case clang : : Type : : Typedef :
return IsFunctionPointerType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ) ;
case clang : : Type : : Elaborated :
return IsFunctionPointerType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ) ;
case clang : : Type : : Paren :
return IsFunctionPointerType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ) ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) ;
if ( reference_type )
return IsFunctionPointerType ( reference_type - > getPointeeType ( ) . getAsOpaquePtr ( ) ) ;
}
break ;
}
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsIntegerType ( lldb : : opaque_compiler_type_t type , bool & is_signed )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : BuiltinType * builtin_type = llvm : : dyn_cast < clang : : BuiltinType > ( qual_type - > getCanonicalTypeInternal ( ) ) ;
if ( builtin_type )
{
if ( builtin_type - > isInteger ( ) )
{
is_signed = builtin_type - > isSignedInteger ( ) ;
return true ;
}
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsPointerType ( lldb : : opaque_compiler_type_t type , CompilerType * pointee_type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
default :
break ;
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
return true ;
}
return false ;
case clang : : Type : : ObjCObjectPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : BlockPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : BlockPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : Pointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : PointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : MemberPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : MemberPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : Typedef :
return IsPointerType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
case clang : : Type : : Elaborated :
return IsPointerType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
case clang : : Type : : Paren :
return IsPointerType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
default :
break ;
}
}
if ( pointee_type )
pointee_type - > Clear ( ) ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsPointerOrReferenceType ( lldb : : opaque_compiler_type_t type , CompilerType * pointee_type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
default :
break ;
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
return true ;
}
return false ;
case clang : : Type : : ObjCObjectPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : BlockPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : BlockPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : Pointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : PointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : MemberPointer :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : MemberPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : LValueReference :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : LValueReferenceType > ( qual_type ) - > desugar ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : RValueReference :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : RValueReferenceType > ( qual_type ) - > desugar ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
case clang : : Type : : Typedef :
return IsPointerOrReferenceType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
case clang : : Type : : Elaborated :
return IsPointerOrReferenceType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
case clang : : Type : : Paren :
return IsPointerOrReferenceType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , pointee_type ) ;
default :
break ;
}
}
if ( pointee_type )
pointee_type - > Clear ( ) ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsReferenceType ( lldb : : opaque_compiler_type_t type , CompilerType * pointee_type , bool * is_rvalue )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : LValueReference :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : LValueReferenceType > ( qual_type ) - > desugar ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( is_rvalue )
* is_rvalue = false ;
return true ;
case clang : : Type : : RValueReference :
if ( pointee_type )
2015-08-25 07:46:31 +08:00
pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : RValueReferenceType > ( qual_type ) - > desugar ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( is_rvalue )
* is_rvalue = true ;
return true ;
case clang : : Type : : Typedef :
return IsReferenceType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , pointee_type , is_rvalue ) ;
case clang : : Type : : Elaborated :
return IsReferenceType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , pointee_type , is_rvalue ) ;
case clang : : Type : : Paren :
return IsReferenceType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , pointee_type , is_rvalue ) ;
default :
break ;
}
}
if ( pointee_type )
pointee_type - > Clear ( ) ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsFloatingPointType ( lldb : : opaque_compiler_type_t type , uint32_t & count , bool & is_complex )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
if ( const clang : : BuiltinType * BT = llvm : : dyn_cast < clang : : BuiltinType > ( qual_type - > getCanonicalTypeInternal ( ) ) )
{
clang : : BuiltinType : : Kind kind = BT - > getKind ( ) ;
if ( kind > = clang : : BuiltinType : : Float & & kind < = clang : : BuiltinType : : LongDouble )
{
count = 1 ;
is_complex = false ;
return true ;
}
}
else if ( const clang : : ComplexType * CT = llvm : : dyn_cast < clang : : ComplexType > ( qual_type - > getCanonicalTypeInternal ( ) ) )
{
if ( IsFloatingPointType ( CT - > getElementType ( ) . getAsOpaquePtr ( ) , count , is_complex ) )
{
count = 2 ;
is_complex = true ;
return true ;
}
}
else if ( const clang : : VectorType * VT = llvm : : dyn_cast < clang : : VectorType > ( qual_type - > getCanonicalTypeInternal ( ) ) )
{
if ( IsFloatingPointType ( VT - > getElementType ( ) . getAsOpaquePtr ( ) , count , is_complex ) )
{
count = VT - > getNumElements ( ) ;
is_complex = false ;
return true ;
}
}
}
count = 0 ;
is_complex = false ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsDefined ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( qual_type . getTypePtr ( ) ) ;
if ( tag_type )
{
clang : : TagDecl * tag_decl = tag_type - > getDecl ( ) ;
if ( tag_decl )
return tag_decl - > isCompleteDefinition ( ) ;
return false ;
}
else
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
return class_interface_decl - > getDefinition ( ) ! = nullptr ;
return false ;
}
}
return true ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : IsObjCClassType ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : ObjCObjectPointerType * obj_pointer_type = llvm : : dyn_cast < clang : : ObjCObjectPointerType > ( qual_type ) ;
if ( obj_pointer_type )
return obj_pointer_type - > isObjCClassType ( ) ;
}
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : IsObjCObjectOrInterfaceType ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
2015-09-15 06:45:11 +08:00
if ( IsClangType ( type ) )
2015-08-12 05:38:15 +08:00
return GetCanonicalQualType ( type ) - > isObjCObjectOrInterfaceType ( ) ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsPolymorphicClass ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
if ( record_decl )
{
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
return cxx_record_decl - > isPolymorphic ( ) ;
}
}
break ;
default :
break ;
}
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsPossibleDynamicType ( lldb : : opaque_compiler_type_t type , CompilerType * dynamic_pointee_type ,
2015-08-12 05:38:15 +08:00
bool check_cplusplus ,
bool check_objc )
{
clang : : QualType pointee_qual_type ;
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
bool success = false ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
if ( check_objc & & llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) = = clang : : BuiltinType : : ObjCId )
{
if ( dynamic_pointee_type )
2015-08-25 07:46:31 +08:00
dynamic_pointee_type - > SetCompilerType ( this , type ) ;
2015-08-12 05:38:15 +08:00
return true ;
}
break ;
case clang : : Type : : ObjCObjectPointer :
if ( check_objc )
{
if ( dynamic_pointee_type )
2015-08-25 07:46:31 +08:00
dynamic_pointee_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return true ;
}
break ;
case clang : : Type : : Pointer :
pointee_qual_type = llvm : : cast < clang : : PointerType > ( qual_type ) - > getPointeeType ( ) ;
success = true ;
break ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
pointee_qual_type = llvm : : cast < clang : : ReferenceType > ( qual_type ) - > getPointeeType ( ) ;
success = true ;
break ;
case clang : : Type : : Typedef :
return IsPossibleDynamicType ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ,
dynamic_pointee_type ,
check_cplusplus ,
check_objc ) ;
case clang : : Type : : Elaborated :
return IsPossibleDynamicType ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ,
dynamic_pointee_type ,
check_cplusplus ,
check_objc ) ;
case clang : : Type : : Paren :
return IsPossibleDynamicType ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ,
dynamic_pointee_type ,
check_cplusplus ,
check_objc ) ;
default :
break ;
}
if ( success )
{
// Check to make sure what we are pointing too is a possible dynamic C++ type
// We currently accept any "void *" (in case we have a class that has been
// watered down to an opaque pointer) and virtual C++ classes.
const clang : : Type : : TypeClass pointee_type_class = pointee_qual_type . getCanonicalType ( ) - > getTypeClass ( ) ;
switch ( pointee_type_class )
{
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( pointee_qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : UnknownAny :
case clang : : BuiltinType : : Void :
if ( dynamic_pointee_type )
2015-08-25 07:46:31 +08:00
dynamic_pointee_type - > SetCompilerType ( getASTContext ( ) , pointee_qual_type ) ;
2015-08-12 05:38:15 +08:00
return true ;
2015-09-17 02:08:45 +08:00
default :
2015-08-12 05:38:15 +08:00
break ;
}
break ;
case clang : : Type : : Record :
if ( check_cplusplus )
{
clang : : CXXRecordDecl * cxx_record_decl = pointee_qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
bool is_complete = cxx_record_decl - > isCompleteDefinition ( ) ;
if ( is_complete )
success = cxx_record_decl - > isDynamicClass ( ) ;
else
{
ClangASTMetadata * metadata = ClangASTContext : : GetMetadata ( getASTContext ( ) , cxx_record_decl ) ;
if ( metadata )
success = metadata - > GetIsDynamicCXXType ( ) ;
else
{
2015-08-12 06:53:00 +08:00
is_complete = CompilerType ( getASTContext ( ) , pointee_qual_type ) . GetCompleteType ( ) ;
2015-08-12 05:38:15 +08:00
if ( is_complete )
success = cxx_record_decl - > isDynamicClass ( ) ;
else
success = false ;
}
}
if ( success )
{
if ( dynamic_pointee_type )
2015-08-25 07:46:31 +08:00
dynamic_pointee_type - > SetCompilerType ( getASTContext ( ) , pointee_qual_type ) ;
2015-08-12 05:38:15 +08:00
return true ;
}
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( check_objc )
{
if ( dynamic_pointee_type )
2015-08-25 07:46:31 +08:00
dynamic_pointee_type - > SetCompilerType ( getASTContext ( ) , pointee_qual_type ) ;
2015-08-12 05:38:15 +08:00
return true ;
}
break ;
default :
break ;
}
}
}
if ( dynamic_pointee_type )
dynamic_pointee_type - > Clear ( ) ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsScalarType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
return ( GetTypeInfo ( type , nullptr ) & eTypeIsScalar ) ! = 0 ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsTypedefType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
return GetQualType ( type ) - > getTypeClass ( ) = = clang : : Type : : Typedef ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsVoidType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
return GetCanonicalQualType ( type ) - > isVoidType ( ) ;
}
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
2015-09-18 06:23:34 +08:00
bool
ClangASTContext : : SupportsLanguage ( lldb : : LanguageType language )
{
return ClangASTContextSupportsLanguage ( language ) ;
}
2015-08-12 05:38:15 +08:00
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : GetCXXClassName ( const CompilerType & type , std : : string & class_name )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
2015-09-15 06:45:11 +08:00
if ( ! qual_type . isNull ( ) )
2015-08-12 05:38:15 +08:00
{
2015-09-15 06:45:11 +08:00
clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
class_name . assign ( cxx_record_decl - > getIdentifier ( ) - > getNameStart ( ) ) ;
return true ;
}
2015-08-12 05:38:15 +08:00
}
}
class_name . clear ( ) ;
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : IsCXXClassType ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
2015-09-15 06:45:11 +08:00
if ( ! qual_type . isNull ( ) & & qual_type - > getAsCXXRecordDecl ( ) ! = nullptr )
2015-08-12 05:38:15 +08:00
return true ;
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : IsBeingDefined ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( qual_type ) ;
if ( tag_type )
return tag_type - > isBeingDefined ( ) ;
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : IsObjCObjectPointerType ( const CompilerType & type , CompilerType * class_type_ptr )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
2015-09-15 06:45:11 +08:00
if ( ! qual_type . isNull ( ) & & qual_type - > isObjCObjectPointerType ( ) )
2015-08-12 05:38:15 +08:00
{
if ( class_type_ptr )
{
if ( ! qual_type - > isObjCClassType ( ) & &
! qual_type - > isObjCIdType ( ) )
{
const clang : : ObjCObjectPointerType * obj_pointer_type = llvm : : dyn_cast < clang : : ObjCObjectPointerType > ( qual_type ) ;
if ( obj_pointer_type = = nullptr )
class_type_ptr - > Clear ( ) ;
else
2015-08-25 07:46:31 +08:00
class_type_ptr - > SetCompilerType ( type . GetTypeSystem ( ) , clang : : QualType ( obj_pointer_type - > getInterfaceType ( ) , 0 ) . getAsOpaquePtr ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
return true ;
}
if ( class_type_ptr )
class_type_ptr - > Clear ( ) ;
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : GetObjCClassName ( const CompilerType & type , std : : string & class_name )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : ObjCObjectType * object_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type ) ;
if ( object_type )
{
const clang : : ObjCInterfaceDecl * interface = object_type - > getInterface ( ) ;
if ( interface )
{
class_name = interface - > getNameAsString ( ) ;
return true ;
}
}
return false ;
}
//----------------------------------------------------------------------
// Type Completion
//----------------------------------------------------------------------
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetCompleteType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
const bool allow_completion = true ;
return GetCompleteQualType ( getASTContext ( ) , GetQualType ( type ) , allow_completion ) ;
}
ConstString
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypeName ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
std : : string type_name ;
if ( type )
{
clang : : PrintingPolicy printing_policy ( getASTContext ( ) - > getPrintingPolicy ( ) ) ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
printing_policy . SuppressTagKeyword = true ;
printing_policy . LangOpts . WChar = true ;
const clang : : TypedefType * typedef_type = qual_type - > getAs < clang : : TypedefType > ( ) ;
if ( typedef_type )
{
const clang : : TypedefNameDecl * typedef_decl = typedef_type - > getDecl ( ) ;
type_name = typedef_decl - > getQualifiedNameAsString ( ) ;
}
else
{
type_name = qual_type . getAsString ( printing_policy ) ;
}
}
return ConstString ( type_name ) ;
}
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypeInfo ( lldb : : opaque_compiler_type_t type , CompilerType * pointee_or_element_clang_type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return 0 ;
if ( pointee_or_element_clang_type )
pointee_or_element_clang_type - > Clear ( ) ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
{
const clang : : BuiltinType * builtin_type = llvm : : dyn_cast < clang : : BuiltinType > ( qual_type - > getCanonicalTypeInternal ( ) ) ;
uint32_t builtin_type_flags = eTypeIsBuiltIn | eTypeHasValue ;
switch ( builtin_type - > getKind ( ) )
{
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , getASTContext ( ) - > ObjCBuiltinClassTy ) ;
2015-08-12 05:38:15 +08:00
builtin_type_flags | = eTypeIsPointer | eTypeIsObjC ;
break ;
case clang : : BuiltinType : : ObjCSel :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , getASTContext ( ) - > CharTy ) ;
2015-08-12 05:38:15 +08:00
builtin_type_flags | = eTypeIsPointer | eTypeIsObjC ;
break ;
case clang : : BuiltinType : : Bool :
case clang : : BuiltinType : : Char_U :
case clang : : BuiltinType : : UChar :
case clang : : BuiltinType : : WChar_U :
case clang : : BuiltinType : : Char16 :
case clang : : BuiltinType : : Char32 :
case clang : : BuiltinType : : UShort :
case clang : : BuiltinType : : UInt :
case clang : : BuiltinType : : ULong :
case clang : : BuiltinType : : ULongLong :
case clang : : BuiltinType : : UInt128 :
case clang : : BuiltinType : : Char_S :
case clang : : BuiltinType : : SChar :
case clang : : BuiltinType : : WChar_S :
case clang : : BuiltinType : : Short :
case clang : : BuiltinType : : Int :
case clang : : BuiltinType : : Long :
case clang : : BuiltinType : : LongLong :
case clang : : BuiltinType : : Int128 :
case clang : : BuiltinType : : Float :
case clang : : BuiltinType : : Double :
case clang : : BuiltinType : : LongDouble :
builtin_type_flags | = eTypeIsScalar ;
if ( builtin_type - > isInteger ( ) )
{
builtin_type_flags | = eTypeIsInteger ;
if ( builtin_type - > isSignedInteger ( ) )
builtin_type_flags | = eTypeIsSigned ;
}
else if ( builtin_type - > isFloatingPoint ( ) )
builtin_type_flags | = eTypeIsFloat ;
break ;
default :
break ;
}
return builtin_type_flags ;
}
case clang : : Type : : BlockPointer :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , qual_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock ;
case clang : : Type : : Complex :
{
uint32_t complex_type_flags = eTypeIsBuiltIn | eTypeHasValue | eTypeIsComplex ;
const clang : : ComplexType * complex_type = llvm : : dyn_cast < clang : : ComplexType > ( qual_type - > getCanonicalTypeInternal ( ) ) ;
if ( complex_type )
{
clang : : QualType complex_element_type ( complex_type - > getElementType ( ) ) ;
if ( complex_element_type - > isIntegerType ( ) )
complex_type_flags | = eTypeIsFloat ;
else if ( complex_element_type - > isFloatingType ( ) )
complex_type_flags | = eTypeIsInteger ;
}
return complex_type_flags ;
}
break ;
case clang : : Type : : ConstantArray :
case clang : : Type : : DependentSizedArray :
case clang : : Type : : IncompleteArray :
case clang : : Type : : VariableArray :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ArrayType > ( qual_type . getTypePtr ( ) ) - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeHasChildren | eTypeIsArray ;
case clang : : Type : : DependentName : return 0 ;
case clang : : Type : : DependentSizedExtVector : return eTypeHasChildren | eTypeIsVector ;
case clang : : Type : : DependentTemplateSpecialization : return eTypeIsTemplate ;
case clang : : Type : : Decltype : return 0 ;
case clang : : Type : : Enum :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : EnumType > ( qual_type ) - > getDecl ( ) - > getIntegerType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeIsEnumeration | eTypeHasValue ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetTypeInfo ( pointee_or_element_clang_type ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetTypeInfo ( pointee_or_element_clang_type ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : FunctionProto : return eTypeIsFuncPrototype | eTypeHasValue ;
case clang : : Type : : FunctionNoProto : return eTypeIsFuncPrototype | eTypeHasValue ;
case clang : : Type : : InjectedClassName : return 0 ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeHasChildren | eTypeIsReference | eTypeHasValue ;
case clang : : Type : : MemberPointer : return eTypeIsPointer | eTypeIsMember | eTypeHasValue ;
case clang : : Type : : ObjCObjectPointer :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , qual_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue ;
case clang : : Type : : ObjCObject : return eTypeHasChildren | eTypeIsObjC | eTypeIsClass ;
case clang : : Type : : ObjCInterface : return eTypeHasChildren | eTypeIsObjC | eTypeIsClass ;
case clang : : Type : : Pointer :
if ( pointee_or_element_clang_type )
2015-08-25 07:46:31 +08:00
pointee_or_element_clang_type - > SetCompilerType ( getASTContext ( ) , qual_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return eTypeHasChildren | eTypeIsPointer | eTypeHasValue ;
case clang : : Type : : Record :
if ( qual_type - > getAsCXXRecordDecl ( ) )
return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus ;
else
return eTypeHasChildren | eTypeIsStructUnion ;
break ;
case clang : : Type : : SubstTemplateTypeParm : return eTypeIsTemplate ;
case clang : : Type : : TemplateTypeParm : return eTypeIsTemplate ;
case clang : : Type : : TemplateSpecialization : return eTypeIsTemplate ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return eTypeIsTypedef | CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetTypeInfo ( pointee_or_element_clang_type ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : TypeOfExpr : return 0 ;
case clang : : Type : : TypeOf : return 0 ;
case clang : : Type : : UnresolvedUsing : return 0 ;
case clang : : Type : : ExtVector :
case clang : : Type : : Vector :
{
uint32_t vector_type_flags = eTypeHasChildren | eTypeIsVector ;
const clang : : VectorType * vector_type = llvm : : dyn_cast < clang : : VectorType > ( qual_type - > getCanonicalTypeInternal ( ) ) ;
if ( vector_type )
{
if ( vector_type - > isIntegerType ( ) )
vector_type_flags | = eTypeIsFloat ;
else if ( vector_type - > isFloatingType ( ) )
vector_type_flags | = eTypeIsInteger ;
}
return vector_type_flags ;
}
default : return 0 ;
}
return 0 ;
}
lldb : : LanguageType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetMinimumLanguage ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return lldb : : eLanguageTypeC ;
// If the type is a reference, then resolve it to what it refers to first:
clang : : QualType qual_type ( GetCanonicalQualType ( type ) . getNonReferenceType ( ) ) ;
if ( qual_type - > isAnyPointerType ( ) )
{
if ( qual_type - > isObjCObjectPointerType ( ) )
return lldb : : eLanguageTypeObjC ;
clang : : QualType pointee_type ( qual_type - > getPointeeType ( ) ) ;
if ( pointee_type - > getPointeeCXXRecordDecl ( ) ! = nullptr )
return lldb : : eLanguageTypeC_plus_plus ;
if ( pointee_type - > isObjCObjectOrInterfaceType ( ) )
return lldb : : eLanguageTypeObjC ;
if ( pointee_type - > isObjCClassType ( ) )
return lldb : : eLanguageTypeObjC ;
if ( pointee_type . getTypePtr ( ) = = getASTContext ( ) - > ObjCBuiltinIdTy . getTypePtr ( ) )
return lldb : : eLanguageTypeObjC ;
}
else
{
if ( qual_type - > isObjCObjectOrInterfaceType ( ) )
return lldb : : eLanguageTypeObjC ;
if ( qual_type - > getAsCXXRecordDecl ( ) )
return lldb : : eLanguageTypeC_plus_plus ;
switch ( qual_type - > getTypeClass ( ) )
{
default :
break ;
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
default :
case clang : : BuiltinType : : Void :
case clang : : BuiltinType : : Bool :
case clang : : BuiltinType : : Char_U :
case clang : : BuiltinType : : UChar :
case clang : : BuiltinType : : WChar_U :
case clang : : BuiltinType : : Char16 :
case clang : : BuiltinType : : Char32 :
case clang : : BuiltinType : : UShort :
case clang : : BuiltinType : : UInt :
case clang : : BuiltinType : : ULong :
case clang : : BuiltinType : : ULongLong :
case clang : : BuiltinType : : UInt128 :
case clang : : BuiltinType : : Char_S :
case clang : : BuiltinType : : SChar :
case clang : : BuiltinType : : WChar_S :
case clang : : BuiltinType : : Short :
case clang : : BuiltinType : : Int :
case clang : : BuiltinType : : Long :
case clang : : BuiltinType : : LongLong :
case clang : : BuiltinType : : Int128 :
case clang : : BuiltinType : : Float :
case clang : : BuiltinType : : Double :
case clang : : BuiltinType : : LongDouble :
break ;
case clang : : BuiltinType : : NullPtr :
return eLanguageTypeC_plus_plus ;
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
case clang : : BuiltinType : : ObjCSel :
return eLanguageTypeObjC ;
case clang : : BuiltinType : : Dependent :
case clang : : BuiltinType : : Overload :
case clang : : BuiltinType : : BoundMember :
case clang : : BuiltinType : : UnknownAny :
break ;
}
break ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetMinimumLanguage ( ) ;
2015-08-12 05:38:15 +08:00
}
}
return lldb : : eLanguageTypeC ;
}
lldb : : TypeClass
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypeClass ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return lldb : : eTypeClassInvalid ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) )
{
case clang : : Type : : UnaryTransform : break ;
case clang : : Type : : FunctionNoProto : return lldb : : eTypeClassFunction ;
case clang : : Type : : FunctionProto : return lldb : : eTypeClassFunction ;
case clang : : Type : : IncompleteArray : return lldb : : eTypeClassArray ;
case clang : : Type : : VariableArray : return lldb : : eTypeClassArray ;
case clang : : Type : : ConstantArray : return lldb : : eTypeClassArray ;
case clang : : Type : : DependentSizedArray : return lldb : : eTypeClassArray ;
case clang : : Type : : DependentSizedExtVector : return lldb : : eTypeClassVector ;
case clang : : Type : : ExtVector : return lldb : : eTypeClassVector ;
case clang : : Type : : Vector : return lldb : : eTypeClassVector ;
case clang : : Type : : Builtin : return lldb : : eTypeClassBuiltin ;
case clang : : Type : : ObjCObjectPointer : return lldb : : eTypeClassObjCObjectPointer ;
case clang : : Type : : BlockPointer : return lldb : : eTypeClassBlockPointer ;
case clang : : Type : : Pointer : return lldb : : eTypeClassPointer ;
case clang : : Type : : LValueReference : return lldb : : eTypeClassReference ;
case clang : : Type : : RValueReference : return lldb : : eTypeClassReference ;
case clang : : Type : : MemberPointer : return lldb : : eTypeClassMemberPointer ;
case clang : : Type : : Complex :
if ( qual_type - > isComplexType ( ) )
return lldb : : eTypeClassComplexFloat ;
else
return lldb : : eTypeClassComplexInteger ;
case clang : : Type : : ObjCObject : return lldb : : eTypeClassObjCObject ;
case clang : : Type : : ObjCInterface : return lldb : : eTypeClassObjCInterface ;
case clang : : Type : : Record :
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
if ( record_decl - > isUnion ( ) )
return lldb : : eTypeClassUnion ;
else if ( record_decl - > isStruct ( ) )
return lldb : : eTypeClassStruct ;
else
return lldb : : eTypeClassClass ;
}
break ;
case clang : : Type : : Enum : return lldb : : eTypeClassEnumeration ;
case clang : : Type : : Typedef : return lldb : : eTypeClassTypedef ;
case clang : : Type : : UnresolvedUsing : break ;
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetTypeClass ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetTypeClass ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Attributed : break ;
case clang : : Type : : TemplateTypeParm : break ;
case clang : : Type : : SubstTemplateTypeParm : break ;
case clang : : Type : : SubstTemplateTypeParmPack : break ;
case clang : : Type : : Auto : break ;
case clang : : Type : : InjectedClassName : break ;
case clang : : Type : : DependentName : break ;
case clang : : Type : : DependentTemplateSpecialization : break ;
case clang : : Type : : PackExpansion : break ;
case clang : : Type : : TypeOfExpr : break ;
case clang : : Type : : TypeOf : break ;
case clang : : Type : : Decltype : break ;
case clang : : Type : : TemplateSpecialization : break ;
case clang : : Type : : Atomic : break ;
// pointer type decayed from an array or function type.
case clang : : Type : : Decayed : break ;
case clang : : Type : : Adjusted : break ;
}
// We don't know hot to display this type...
return lldb : : eTypeClassOther ;
}
unsigned
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypeQualifiers ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
return GetQualType ( type ) . getQualifiers ( ) . getCVRQualifiers ( ) ;
return 0 ;
}
//----------------------------------------------------------------------
// Creating related types
//----------------------------------------------------------------------
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetArrayElementType ( lldb : : opaque_compiler_type_t type , uint64_t * stride )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type * array_eletype = qual_type . getTypePtr ( ) - > getArrayElementTypeNoTypeQual ( ) ;
if ( ! array_eletype )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
2015-08-12 06:53:00 +08:00
CompilerType element_type ( getASTContext ( ) , array_eletype - > getCanonicalTypeUnqualified ( ) ) ;
2015-08-12 05:38:15 +08:00
// TODO: the real stride will be >= this value.. find the real one!
if ( stride )
* stride = element_type . GetByteSize ( nullptr ) ;
return element_type ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetCanonicalType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , GetCanonicalQualType ( type ) ) ;
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
static clang : : QualType
GetFullyUnqualifiedType_Impl ( clang : : ASTContext * ast , clang : : QualType qual_type )
{
if ( qual_type - > isPointerType ( ) )
qual_type = ast - > getPointerType ( GetFullyUnqualifiedType_Impl ( ast , qual_type - > getPointeeType ( ) ) ) ;
else
qual_type = qual_type . getUnqualifiedType ( ) ;
qual_type . removeLocalConst ( ) ;
qual_type . removeLocalRestrict ( ) ;
qual_type . removeLocalVolatile ( ) ;
return qual_type ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFullyUnqualifiedType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , GetFullyUnqualifiedType_Impl ( getASTContext ( ) , GetQualType ( type ) ) ) ;
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
int
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFunctionArgumentCount ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
const clang : : FunctionProtoType * func = llvm : : dyn_cast < clang : : FunctionProtoType > ( GetCanonicalQualType ( type ) ) ;
if ( func )
return func - > getNumParams ( ) ;
}
return - 1 ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFunctionArgumentTypeAtIndex ( lldb : : opaque_compiler_type_t type , size_t idx )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
const clang : : FunctionProtoType * func = llvm : : dyn_cast < clang : : FunctionProtoType > ( GetCanonicalQualType ( type ) ) ;
if ( func )
{
const uint32_t num_args = func - > getNumParams ( ) ;
if ( idx < num_args )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , func - > getParamType ( idx ) ) ;
2015-08-12 05:38:15 +08:00
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFunctionReturnType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : FunctionProtoType * func = llvm : : dyn_cast < clang : : FunctionProtoType > ( qual_type . getTypePtr ( ) ) ;
if ( func )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , func - > getReturnType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumMemberFunctions ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
size_t num_functions = 0 ;
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) ) {
case clang : : Type : : Record :
if ( GetCompleteQualType ( getASTContext ( ) , qual_type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
num_functions = std : : distance ( cxx_record_decl - > method_begin ( ) , cxx_record_decl - > method_end ( ) ) ;
}
break ;
case clang : : Type : : ObjCObjectPointer :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectPointerType * objc_class_type = qual_type - > getAsObjCInterfacePointerType ( ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterfaceDecl ( ) ;
if ( class_interface_decl )
num_functions = std : : distance ( class_interface_decl - > meth_begin ( ) , class_interface_decl - > meth_end ( ) ) ;
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
num_functions = std : : distance ( class_interface_decl - > meth_begin ( ) , class_interface_decl - > meth_end ( ) ) ;
}
}
break ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetNumMemberFunctions ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetNumMemberFunctions ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetNumMemberFunctions ( ) ;
2015-08-12 05:38:15 +08:00
default :
break ;
}
}
return num_functions ;
}
TypeMemberFunctionImpl
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetMemberFunctionAtIndex ( lldb : : opaque_compiler_type_t type , size_t idx )
2015-08-12 05:38:15 +08:00
{
std : : string name ( " " ) ;
MemberFunctionKind kind ( MemberFunctionKind : : eMemberFunctionKindUnknown ) ;
2015-08-12 06:53:00 +08:00
CompilerType clang_type { } ;
2015-08-12 05:38:15 +08:00
clang : : ObjCMethodDecl * method_decl ( nullptr ) ;
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) ) {
case clang : : Type : : Record :
if ( GetCompleteQualType ( getASTContext ( ) , qual_type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
auto method_iter = cxx_record_decl - > method_begin ( ) ;
auto method_end = cxx_record_decl - > method_end ( ) ;
if ( idx < static_cast < size_t > ( std : : distance ( method_iter , method_end ) ) )
{
std : : advance ( method_iter , idx ) ;
auto method_decl = method_iter - > getCanonicalDecl ( ) ;
if ( method_decl )
{
if ( ! method_decl - > getName ( ) . empty ( ) )
name . assign ( method_decl - > getName ( ) . data ( ) ) ;
else
name . clear ( ) ;
if ( method_decl - > isStatic ( ) )
kind = lldb : : eMemberFunctionKindStaticMethod ;
else if ( llvm : : isa < clang : : CXXConstructorDecl > ( method_decl ) )
kind = lldb : : eMemberFunctionKindConstructor ;
else if ( llvm : : isa < clang : : CXXDestructorDecl > ( method_decl ) )
kind = lldb : : eMemberFunctionKindDestructor ;
else
kind = lldb : : eMemberFunctionKindInstanceMethod ;
2015-08-12 06:53:00 +08:00
clang_type = CompilerType ( getASTContext ( ) , method_decl - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectPointerType * objc_class_type = qual_type - > getAsObjCInterfacePointerType ( ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterfaceDecl ( ) ;
if ( class_interface_decl )
{
auto method_iter = class_interface_decl - > meth_begin ( ) ;
auto method_end = class_interface_decl - > meth_end ( ) ;
if ( idx < static_cast < size_t > ( std : : distance ( method_iter , method_end ) ) )
{
std : : advance ( method_iter , idx ) ;
method_decl = method_iter - > getCanonicalDecl ( ) ;
if ( method_decl )
{
name = method_decl - > getSelector ( ) . getAsString ( ) ;
if ( method_decl - > isClassMethod ( ) )
kind = lldb : : eMemberFunctionKindStaticMethod ;
else
kind = lldb : : eMemberFunctionKindInstanceMethod ;
}
}
}
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
auto method_iter = class_interface_decl - > meth_begin ( ) ;
auto method_end = class_interface_decl - > meth_end ( ) ;
if ( idx < static_cast < size_t > ( std : : distance ( method_iter , method_end ) ) )
{
std : : advance ( method_iter , idx ) ;
method_decl = method_iter - > getCanonicalDecl ( ) ;
if ( method_decl )
{
name = method_decl - > getSelector ( ) . getAsString ( ) ;
if ( method_decl - > isClassMethod ( ) )
kind = lldb : : eMemberFunctionKindStaticMethod ;
else
kind = lldb : : eMemberFunctionKindInstanceMethod ;
}
}
}
}
}
break ;
case clang : : Type : : Typedef :
return GetMemberFunctionAtIndex ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , idx ) ;
case clang : : Type : : Elaborated :
return GetMemberFunctionAtIndex ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , idx ) ;
case clang : : Type : : Paren :
return GetMemberFunctionAtIndex ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , idx ) ;
default :
break ;
}
}
if ( kind = = eMemberFunctionKindUnknown )
return TypeMemberFunctionImpl ( ) ;
if ( method_decl )
return TypeMemberFunctionImpl ( method_decl , name , kind ) ;
if ( type )
return TypeMemberFunctionImpl ( clang_type , name , kind ) ;
return TypeMemberFunctionImpl ( ) ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNonReferenceType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , GetQualType ( type ) . getNonReferenceType ( ) ) ;
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
ClangASTContext : : CreateTypedefType ( const CompilerType & type ,
2015-08-12 05:38:15 +08:00
const char * typedef_name ,
2015-08-25 07:46:31 +08:00
const CompilerDeclContext & compiler_decl_ctx )
2015-08-12 05:38:15 +08:00
{
if ( type & & typedef_name & & typedef_name [ 0 ] )
{
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
clang : : ASTContext * clang_ast = ast - > getASTContext ( ) ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
2015-08-25 07:46:31 +08:00
clang : : DeclContext * decl_ctx = ClangASTContext : : DeclContextGetAsDeclContext ( compiler_decl_ctx ) ;
2015-08-12 05:38:15 +08:00
if ( decl_ctx = = nullptr )
decl_ctx = ast - > getASTContext ( ) - > getTranslationUnitDecl ( ) ;
2015-08-25 07:46:31 +08:00
2015-08-12 05:38:15 +08:00
clang : : TypedefDecl * decl = clang : : TypedefDecl : : Create ( * clang_ast ,
decl_ctx ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
& clang_ast - > Idents . get ( typedef_name ) ,
clang_ast - > getTrivialTypeSourceInfo ( qual_type ) ) ;
decl - > setAccess ( clang : : AS_public ) ; // TODO respect proper access specifier
// Get a uniqued clang::QualType for the typedef decl type
2015-08-12 06:53:00 +08:00
return CompilerType ( clang_ast , clang_ast - > getTypedefType ( decl ) ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetPointeeType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , qual_type . getTypePtr ( ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetPointerType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , getASTContext ( ) - > getObjCObjectPointerType ( qual_type ) ) ;
2015-08-12 05:38:15 +08:00
default :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , getASTContext ( ) - > getPointerType ( qual_type ) ) ;
2015-08-12 05:38:15 +08:00
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +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
2015-09-18 06:23:34 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetLValueReferenceType ( lldb : : opaque_compiler_type_t type )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
return CompilerType ( this , getASTContext ( ) - > getLValueReferenceType ( GetQualType ( type ) ) . getAsOpaquePtr ( ) ) ;
else
return CompilerType ( ) ;
}
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetRValueReferenceType ( lldb : : opaque_compiler_type_t type )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
return CompilerType ( this , getASTContext ( ) - > getRValueReferenceType ( GetQualType ( type ) ) . getAsOpaquePtr ( ) ) ;
else
return CompilerType ( ) ;
}
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : AddConstModifier ( lldb : : opaque_compiler_type_t type )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
{
clang : : QualType result ( GetQualType ( type ) ) ;
result . addConst ( ) ;
return CompilerType ( this , result . getAsOpaquePtr ( ) ) ;
}
return CompilerType ( ) ;
}
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : AddVolatileModifier ( lldb : : opaque_compiler_type_t type )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
{
clang : : QualType result ( GetQualType ( type ) ) ;
result . addVolatile ( ) ;
return CompilerType ( this , result . getAsOpaquePtr ( ) ) ;
}
return CompilerType ( ) ;
}
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : AddRestrictModifier ( lldb : : opaque_compiler_type_t type )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
{
clang : : QualType result ( GetQualType ( type ) ) ;
result . addRestrict ( ) ;
return CompilerType ( this , result . getAsOpaquePtr ( ) ) ;
}
return CompilerType ( ) ;
}
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : CreateTypedef ( lldb : : opaque_compiler_type_t type , const char * typedef_name , const CompilerDeclContext & compiler_decl_ctx )
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
2015-09-18 06:23:34 +08:00
{
if ( type )
{
clang : : ASTContext * clang_ast = getASTContext ( ) ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
clang : : DeclContext * decl_ctx = ClangASTContext : : DeclContextGetAsDeclContext ( compiler_decl_ctx ) ;
if ( decl_ctx = = nullptr )
decl_ctx = getASTContext ( ) - > getTranslationUnitDecl ( ) ;
clang : : TypedefDecl * decl = clang : : TypedefDecl : : Create ( * clang_ast ,
decl_ctx ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
& clang_ast - > Idents . get ( typedef_name ) ,
clang_ast - > getTrivialTypeSourceInfo ( qual_type ) ) ;
decl - > setAccess ( clang : : AS_public ) ; // TODO respect proper access specifier
// Get a uniqued clang::QualType for the typedef decl type
return CompilerType ( this , clang_ast - > getTypedefType ( decl ) . getAsOpaquePtr ( ) ) ;
}
return CompilerType ( ) ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypedefedType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
const clang : : TypedefType * typedef_type = llvm : : dyn_cast < clang : : TypedefType > ( GetQualType ( type ) ) ;
if ( typedef_type )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , typedef_type - > getDecl ( ) - > getUnderlyingType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
ClangASTContext : : RemoveFastQualifiers ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
2015-09-15 06:45:11 +08:00
if ( IsClangType ( type ) )
2015-08-12 05:38:15 +08:00
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
qual_type . getQualifiers ( ) . removeFastQualifiers ( ) ;
2015-08-12 06:53:00 +08:00
return CompilerType ( type . GetTypeSystem ( ) , qual_type . getAsOpaquePtr ( ) ) ;
2015-08-12 05:38:15 +08:00
}
return type ;
}
//----------------------------------------------------------------------
// Create related types using the current type's AST
//----------------------------------------------------------------------
2015-08-12 06:53:00 +08:00
CompilerType
2015-08-25 07:46:31 +08:00
ClangASTContext : : GetBasicTypeFromAST ( lldb : : BasicType basic_type )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
return ClangASTContext : : GetBasicType ( getASTContext ( ) , basic_type ) ;
2015-08-12 05:38:15 +08:00
}
//----------------------------------------------------------------------
// Exploring the type
//----------------------------------------------------------------------
uint64_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetBitSize ( lldb : : opaque_compiler_type_t type , ExecutionContextScope * exe_scope )
2015-08-12 05:38:15 +08:00
{
if ( GetCompleteType ( type ) )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) )
{
case clang : : Type : : ObjCInterface :
case clang : : Type : : ObjCObject :
{
ExecutionContext exe_ctx ( exe_scope ) ;
Process * process = exe_ctx . GetProcessPtr ( ) ;
if ( process )
{
ObjCLanguageRuntime * objc_runtime = process - > GetObjCLanguageRuntime ( ) ;
if ( objc_runtime )
{
uint64_t bit_size = 0 ;
2015-08-12 06:53:00 +08:00
if ( objc_runtime - > GetTypeBitSize ( CompilerType ( getASTContext ( ) , qual_type ) , bit_size ) )
2015-08-12 05:38:15 +08:00
return bit_size ;
}
}
else
{
static bool g_printed = false ;
if ( ! g_printed )
{
StreamString s ;
2015-10-15 06:44:50 +08:00
DumpTypeDescription ( type , & s ) ;
2015-08-12 05:38:15 +08:00
llvm : : outs ( ) < < " warning: trying to determine the size of type " ;
llvm : : outs ( ) < < s . GetString ( ) < < " \n " ;
llvm : : outs ( ) < < " without a valid ExecutionContext. this is not reliable. please file a bug against LLDB. \n " ;
llvm : : outs ( ) < < " backtrace: \n " ;
llvm : : sys : : PrintStackTrace ( llvm : : outs ( ) ) ;
llvm : : outs ( ) < < " \n " ;
g_printed = true ;
}
}
}
// fallthrough
default :
const uint32_t bit_size = getASTContext ( ) - > getTypeSize ( qual_type ) ;
if ( bit_size = = 0 )
{
if ( qual_type - > isIncompleteArrayType ( ) )
return getASTContext ( ) - > getTypeSize ( qual_type - > getArrayElementTypeNoTypeQual ( ) - > getCanonicalTypeUnqualified ( ) ) ;
}
if ( qual_type - > isObjCObjectOrInterfaceType ( ) )
return bit_size + getASTContext ( ) - > getTypeSize ( getASTContext ( ) - > ObjCBuiltinClassTy ) ;
return bit_size ;
}
}
return 0 ;
}
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTypeBitAlign ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( GetCompleteType ( type ) )
return getASTContext ( ) - > getTypeAlign ( GetQualType ( type ) ) ;
return 0 ;
}
lldb : : Encoding
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetEncoding ( lldb : : opaque_compiler_type_t type , uint64_t & count )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return lldb : : eEncodingInvalid ;
count = 1 ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) )
{
case clang : : Type : : UnaryTransform :
break ;
case clang : : Type : : FunctionNoProto :
case clang : : Type : : FunctionProto :
break ;
case clang : : Type : : IncompleteArray :
case clang : : Type : : VariableArray :
break ;
case clang : : Type : : ConstantArray :
break ;
case clang : : Type : : ExtVector :
case clang : : Type : : Vector :
// TODO: Set this to more than one???
break ;
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : Void :
break ;
case clang : : BuiltinType : : Bool :
case clang : : BuiltinType : : Char_S :
case clang : : BuiltinType : : SChar :
case clang : : BuiltinType : : WChar_S :
case clang : : BuiltinType : : Char16 :
case clang : : BuiltinType : : Char32 :
case clang : : BuiltinType : : Short :
case clang : : BuiltinType : : Int :
case clang : : BuiltinType : : Long :
case clang : : BuiltinType : : LongLong :
case clang : : BuiltinType : : Int128 : return lldb : : eEncodingSint ;
case clang : : BuiltinType : : Char_U :
case clang : : BuiltinType : : UChar :
case clang : : BuiltinType : : WChar_U :
case clang : : BuiltinType : : UShort :
case clang : : BuiltinType : : UInt :
case clang : : BuiltinType : : ULong :
case clang : : BuiltinType : : ULongLong :
case clang : : BuiltinType : : UInt128 : return lldb : : eEncodingUint ;
case clang : : BuiltinType : : Float :
case clang : : BuiltinType : : Double :
case clang : : BuiltinType : : LongDouble : return lldb : : eEncodingIEEE754 ;
case clang : : BuiltinType : : ObjCClass :
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCSel : return lldb : : eEncodingUint ;
case clang : : BuiltinType : : NullPtr : return lldb : : eEncodingUint ;
case clang : : BuiltinType : : Kind : : ARCUnbridgedCast :
case clang : : BuiltinType : : Kind : : BoundMember :
case clang : : BuiltinType : : Kind : : BuiltinFn :
case clang : : BuiltinType : : Kind : : Dependent :
case clang : : BuiltinType : : Kind : : Half :
2015-09-24 02:32:34 +08:00
case clang : : BuiltinType : : Kind : : OCLClkEvent :
2015-08-12 05:38:15 +08:00
case clang : : BuiltinType : : Kind : : OCLEvent :
case clang : : BuiltinType : : Kind : : OCLImage1d :
case clang : : BuiltinType : : Kind : : OCLImage1dArray :
case clang : : BuiltinType : : Kind : : OCLImage1dBuffer :
case clang : : BuiltinType : : Kind : : OCLImage2d :
case clang : : BuiltinType : : Kind : : OCLImage2dArray :
2015-09-24 02:32:34 +08:00
case clang : : BuiltinType : : Kind : : OCLImage2dArrayDepth :
case clang : : BuiltinType : : Kind : : OCLImage2dArrayMSAA :
case clang : : BuiltinType : : Kind : : OCLImage2dArrayMSAADepth :
case clang : : BuiltinType : : Kind : : OCLImage2dDepth :
case clang : : BuiltinType : : Kind : : OCLImage2dMSAA :
case clang : : BuiltinType : : Kind : : OCLImage2dMSAADepth :
2015-08-12 05:38:15 +08:00
case clang : : BuiltinType : : Kind : : OCLImage3d :
2015-09-24 02:32:34 +08:00
case clang : : BuiltinType : : Kind : : OCLQueue :
case clang : : BuiltinType : : Kind : : OCLNDRange :
case clang : : BuiltinType : : Kind : : OCLReserveID :
2015-08-12 05:38:15 +08:00
case clang : : BuiltinType : : Kind : : OCLSampler :
2015-09-24 02:32:34 +08:00
case clang : : BuiltinType : : Kind : : OMPArraySection :
2015-08-12 05:38:15 +08:00
case clang : : BuiltinType : : Kind : : Overload :
case clang : : BuiltinType : : Kind : : PseudoObject :
case clang : : BuiltinType : : Kind : : UnknownAny :
break ;
}
break ;
// All pointer types are represented as unsigned integer encodings.
// We may nee to add a eEncodingPointer if we ever need to know the
// difference
case clang : : Type : : ObjCObjectPointer :
case clang : : Type : : BlockPointer :
case clang : : Type : : Pointer :
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
case clang : : Type : : MemberPointer : return lldb : : eEncodingUint ;
case clang : : Type : : Complex :
{
lldb : : Encoding encoding = lldb : : eEncodingIEEE754 ;
if ( qual_type - > isComplexType ( ) )
encoding = lldb : : eEncodingIEEE754 ;
else
{
const clang : : ComplexType * complex_type = qual_type - > getAsComplexIntegerType ( ) ;
if ( complex_type )
2015-08-12 06:53:00 +08:00
encoding = CompilerType ( getASTContext ( ) , complex_type - > getElementType ( ) ) . GetEncoding ( count ) ;
2015-08-12 05:38:15 +08:00
else
encoding = lldb : : eEncodingSint ;
}
count = 2 ;
return encoding ;
}
case clang : : Type : : ObjCInterface : break ;
case clang : : Type : : Record : break ;
case clang : : Type : : Enum : return lldb : : eEncodingSint ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetEncoding ( count ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetEncoding ( count ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetEncoding ( count ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : DependentSizedArray :
case clang : : Type : : DependentSizedExtVector :
case clang : : Type : : UnresolvedUsing :
case clang : : Type : : Attributed :
case clang : : Type : : TemplateTypeParm :
case clang : : Type : : SubstTemplateTypeParm :
case clang : : Type : : SubstTemplateTypeParmPack :
case clang : : Type : : Auto :
case clang : : Type : : InjectedClassName :
case clang : : Type : : DependentName :
case clang : : Type : : DependentTemplateSpecialization :
case clang : : Type : : PackExpansion :
case clang : : Type : : ObjCObject :
case clang : : Type : : TypeOfExpr :
case clang : : Type : : TypeOf :
case clang : : Type : : Decltype :
case clang : : Type : : TemplateSpecialization :
case clang : : Type : : Atomic :
case clang : : Type : : Adjusted :
break ;
// pointer type decayed from an array or function type.
case clang : : Type : : Decayed :
break ;
}
count = 0 ;
return lldb : : eEncodingInvalid ;
}
lldb : : Format
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFormat ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return lldb : : eFormatDefault ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) )
{
case clang : : Type : : UnaryTransform :
break ;
case clang : : Type : : FunctionNoProto :
case clang : : Type : : FunctionProto :
break ;
case clang : : Type : : IncompleteArray :
case clang : : Type : : VariableArray :
break ;
case clang : : Type : : ConstantArray :
return lldb : : eFormatVoid ; // no value
case clang : : Type : : ExtVector :
case clang : : Type : : Vector :
break ;
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
//default: assert(0 && "Unknown builtin type!");
case clang : : BuiltinType : : UnknownAny :
case clang : : BuiltinType : : Void :
case clang : : BuiltinType : : BoundMember :
break ;
case clang : : BuiltinType : : Bool : return lldb : : eFormatBoolean ;
case clang : : BuiltinType : : Char_S :
case clang : : BuiltinType : : SChar :
case clang : : BuiltinType : : WChar_S :
case clang : : BuiltinType : : Char_U :
case clang : : BuiltinType : : UChar :
case clang : : BuiltinType : : WChar_U : return lldb : : eFormatChar ;
case clang : : BuiltinType : : Char16 : return lldb : : eFormatUnicode16 ;
case clang : : BuiltinType : : Char32 : return lldb : : eFormatUnicode32 ;
case clang : : BuiltinType : : UShort : return lldb : : eFormatUnsigned ;
case clang : : BuiltinType : : Short : return lldb : : eFormatDecimal ;
case clang : : BuiltinType : : UInt : return lldb : : eFormatUnsigned ;
case clang : : BuiltinType : : Int : return lldb : : eFormatDecimal ;
case clang : : BuiltinType : : ULong : return lldb : : eFormatUnsigned ;
case clang : : BuiltinType : : Long : return lldb : : eFormatDecimal ;
case clang : : BuiltinType : : ULongLong : return lldb : : eFormatUnsigned ;
case clang : : BuiltinType : : LongLong : return lldb : : eFormatDecimal ;
case clang : : BuiltinType : : UInt128 : return lldb : : eFormatUnsigned ;
case clang : : BuiltinType : : Int128 : return lldb : : eFormatDecimal ;
case clang : : BuiltinType : : Float : return lldb : : eFormatFloat ;
case clang : : BuiltinType : : Double : return lldb : : eFormatFloat ;
case clang : : BuiltinType : : LongDouble : return lldb : : eFormatFloat ;
2015-09-17 02:08:45 +08:00
default :
2015-08-12 05:38:15 +08:00
return lldb : : eFormatHex ;
}
break ;
case clang : : Type : : ObjCObjectPointer : return lldb : : eFormatHex ;
case clang : : Type : : BlockPointer : return lldb : : eFormatHex ;
case clang : : Type : : Pointer : return lldb : : eFormatHex ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference : return lldb : : eFormatHex ;
case clang : : Type : : MemberPointer : break ;
case clang : : Type : : Complex :
{
if ( qual_type - > isComplexType ( ) )
return lldb : : eFormatComplex ;
else
return lldb : : eFormatComplexInteger ;
}
case clang : : Type : : ObjCInterface : break ;
case clang : : Type : : Record : break ;
case clang : : Type : : Enum : return lldb : : eFormatEnum ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetFormat ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Auto :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : AutoType > ( qual_type ) - > desugar ( ) ) . GetFormat ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetFormat ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetFormat ( ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : DependentSizedArray :
case clang : : Type : : DependentSizedExtVector :
case clang : : Type : : UnresolvedUsing :
case clang : : Type : : Attributed :
case clang : : Type : : TemplateTypeParm :
case clang : : Type : : SubstTemplateTypeParm :
case clang : : Type : : SubstTemplateTypeParmPack :
case clang : : Type : : InjectedClassName :
case clang : : Type : : DependentName :
case clang : : Type : : DependentTemplateSpecialization :
case clang : : Type : : PackExpansion :
case clang : : Type : : ObjCObject :
case clang : : Type : : TypeOfExpr :
case clang : : Type : : TypeOf :
case clang : : Type : : Decltype :
case clang : : Type : : TemplateSpecialization :
case clang : : Type : : Atomic :
case clang : : Type : : Adjusted :
break ;
// pointer type decayed from an array or function type.
case clang : : Type : : Decayed :
break ;
}
// We don't know hot to display this type...
return lldb : : eFormatBytes ;
}
static bool
ObjCDeclHasIVars ( clang : : ObjCInterfaceDecl * class_interface_decl , bool check_superclass )
{
while ( class_interface_decl )
{
if ( class_interface_decl - > ivar_size ( ) > 0 )
return true ;
if ( check_superclass )
class_interface_decl = class_interface_decl - > getSuperClass ( ) ;
else
break ;
}
return false ;
}
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumChildren ( lldb : : opaque_compiler_type_t type , bool omit_empty_base_classes )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return 0 ;
uint32_t num_children = 0 ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : ObjCId : // child is Class
case clang : : BuiltinType : : ObjCClass : // child is Class
num_children = 1 ;
break ;
default :
break ;
}
break ;
case clang : : Type : : Complex : return 0 ;
case clang : : Type : : Record :
if ( GetCompleteQualType ( getASTContext ( ) , qual_type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
if ( omit_empty_base_classes )
{
// Check each base classes to see if it or any of its
// base classes contain any fields. This can help
// limit the noise in variable views by not having to
// show base classes that contain no members.
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
const clang : : CXXRecordDecl * base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
// Skip empty base classes
if ( ClangASTContext : : RecordHasFields ( base_class_decl ) = = false )
continue ;
num_children + + ;
}
}
else
{
// Include all base classes
num_children + = cxx_record_decl - > getNumBases ( ) ;
}
}
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ; field ! = field_end ; + + field )
+ + num_children ;
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteQualType ( getASTContext ( ) , qual_type ) )
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
if ( superclass_interface_decl )
{
if ( omit_empty_base_classes )
{
if ( ObjCDeclHasIVars ( superclass_interface_decl , true ) )
+ + num_children ;
}
else
+ + num_children ;
}
num_children + = class_interface_decl - > ivar_size ( ) ;
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
{
const clang : : ObjCObjectPointerType * pointer_type = llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type . getTypePtr ( ) ) ;
clang : : QualType pointee_type = pointer_type - > getPointeeType ( ) ;
2015-08-12 06:53:00 +08:00
uint32_t num_pointee_children = CompilerType ( getASTContext ( ) , pointee_type ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
// If this type points to a simple type, then it has 1 child
if ( num_pointee_children = = 0 )
num_children = 1 ;
else
num_children = num_pointee_children ;
}
break ;
case clang : : Type : : Vector :
case clang : : Type : : ExtVector :
num_children = llvm : : cast < clang : : VectorType > ( qual_type . getTypePtr ( ) ) - > getNumElements ( ) ;
break ;
case clang : : Type : : ConstantArray :
num_children = llvm : : cast < clang : : ConstantArrayType > ( qual_type . getTypePtr ( ) ) - > getSize ( ) . getLimitedValue ( ) ;
break ;
case clang : : Type : : Pointer :
{
const clang : : PointerType * pointer_type = llvm : : cast < clang : : PointerType > ( qual_type . getTypePtr ( ) ) ;
clang : : QualType pointee_type ( pointer_type - > getPointeeType ( ) ) ;
2015-08-12 06:53:00 +08:00
uint32_t num_pointee_children = CompilerType ( getASTContext ( ) , pointee_type ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
if ( num_pointee_children = = 0 )
{
// We have a pointer to a pointee type that claims it has no children.
// We will want to look at
num_children = GetNumPointeeChildren ( pointee_type ) ;
}
else
num_children = num_pointee_children ;
}
break ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) ;
clang : : QualType pointee_type = reference_type - > getPointeeType ( ) ;
2015-08-12 06:53:00 +08:00
uint32_t num_pointee_children = CompilerType ( getASTContext ( ) , pointee_type ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
// If this type points to a simple type, then it has 1 child
if ( num_pointee_children = = 0 )
num_children = 1 ;
else
num_children = num_pointee_children ;
}
break ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
num_children = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
break ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
num_children = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
break ;
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
num_children = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetNumChildren ( omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
break ;
default :
break ;
}
return num_children ;
}
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
2015-09-18 06:23:34 +08:00
CompilerType
ClangASTContext : : GetBuiltinTypeByName ( const ConstString & name )
{
return GetBasicType ( GetBasicTypeEnumeration ( name ) ) ;
}
2015-08-12 05:38:15 +08:00
lldb : : BasicType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetBasicTypeEnumeration ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
if ( type_class = = clang : : Type : : Builtin )
{
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : Void : return eBasicTypeVoid ;
case clang : : BuiltinType : : Bool : return eBasicTypeBool ;
case clang : : BuiltinType : : Char_S : return eBasicTypeSignedChar ;
case clang : : BuiltinType : : Char_U : return eBasicTypeUnsignedChar ;
case clang : : BuiltinType : : Char16 : return eBasicTypeChar16 ;
case clang : : BuiltinType : : Char32 : return eBasicTypeChar32 ;
case clang : : BuiltinType : : UChar : return eBasicTypeUnsignedChar ;
case clang : : BuiltinType : : SChar : return eBasicTypeSignedChar ;
case clang : : BuiltinType : : WChar_S : return eBasicTypeSignedWChar ;
case clang : : BuiltinType : : WChar_U : return eBasicTypeUnsignedWChar ;
case clang : : BuiltinType : : Short : return eBasicTypeShort ;
case clang : : BuiltinType : : UShort : return eBasicTypeUnsignedShort ;
case clang : : BuiltinType : : Int : return eBasicTypeInt ;
case clang : : BuiltinType : : UInt : return eBasicTypeUnsignedInt ;
case clang : : BuiltinType : : Long : return eBasicTypeLong ;
case clang : : BuiltinType : : ULong : return eBasicTypeUnsignedLong ;
case clang : : BuiltinType : : LongLong : return eBasicTypeLongLong ;
case clang : : BuiltinType : : ULongLong : return eBasicTypeUnsignedLongLong ;
case clang : : BuiltinType : : Int128 : return eBasicTypeInt128 ;
case clang : : BuiltinType : : UInt128 : return eBasicTypeUnsignedInt128 ;
case clang : : BuiltinType : : Half : return eBasicTypeHalf ;
case clang : : BuiltinType : : Float : return eBasicTypeFloat ;
case clang : : BuiltinType : : Double : return eBasicTypeDouble ;
case clang : : BuiltinType : : LongDouble : return eBasicTypeLongDouble ;
case clang : : BuiltinType : : NullPtr : return eBasicTypeNullPtr ;
case clang : : BuiltinType : : ObjCId : return eBasicTypeObjCID ;
case clang : : BuiltinType : : ObjCClass : return eBasicTypeObjCClass ;
case clang : : BuiltinType : : ObjCSel : return eBasicTypeObjCSel ;
2015-09-17 02:08:45 +08:00
default :
2015-08-12 05:38:15 +08:00
return eBasicTypeOther ;
}
}
}
return eBasicTypeInvalid ;
}
2015-08-25 07:46:31 +08:00
void
2015-09-23 08:18:24 +08:00
ClangASTContext : : ForEachEnumerator ( lldb : : opaque_compiler_type_t type , std : : function < bool ( const CompilerType & integer_type , const ConstString & name , const llvm : : APSInt & value ) > const & callback )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : EnumType * enum_type = llvm : : dyn_cast < clang : : EnumType > ( GetCanonicalQualType ( type ) ) ;
if ( enum_type )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : EnumDecl * enum_decl = enum_type - > getDecl ( ) ;
if ( enum_decl )
{
CompilerType integer_type ( this , enum_decl - > getIntegerType ( ) . getAsOpaquePtr ( ) ) ;
2015-08-12 05:38:15 +08:00
2015-08-25 07:46:31 +08:00
clang : : EnumDecl : : enumerator_iterator enum_pos , enum_end_pos ;
for ( enum_pos = enum_decl - > enumerator_begin ( ) , enum_end_pos = enum_decl - > enumerator_end ( ) ; enum_pos ! = enum_end_pos ; + + enum_pos )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
ConstString name ( enum_pos - > getNameAsString ( ) . c_str ( ) ) ;
if ( ! callback ( integer_type , name , enum_pos - > getInitVal ( ) ) )
break ;
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
}
2015-08-12 05:38:15 +08:00
}
}
2015-08-25 07:46:31 +08:00
# pragma mark Aggregate Types
2015-08-12 05:38:15 +08:00
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumFields ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return 0 ;
uint32_t count = 0 ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : dyn_cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
if ( record_type )
{
clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
if ( record_decl )
{
uint32_t field_idx = 0 ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ; field ! = field_end ; + + field )
+ + field_idx ;
count = field_idx ;
}
}
}
break ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
count = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetNumFields ( ) ;
2015-08-12 05:38:15 +08:00
break ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
count = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetNumFields ( ) ;
2015-08-12 05:38:15 +08:00
break ;
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
count = CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetNumFields ( ) ;
2015-08-12 05:38:15 +08:00
break ;
case clang : : Type : : ObjCObjectPointer :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectPointerType * objc_class_type = qual_type - > getAsObjCInterfacePointerType ( ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterfaceDecl ( ) ;
if ( class_interface_decl )
count = class_interface_decl - > ivar_size ( ) ;
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
count = class_interface_decl - > ivar_size ( ) ;
}
}
break ;
default :
break ;
}
return count ;
}
2015-09-23 08:18:24 +08:00
static lldb : : opaque_compiler_type_t
2015-08-25 07:46:31 +08:00
GetObjCFieldAtIndex ( clang : : ASTContext * ast ,
clang : : ObjCInterfaceDecl * class_interface_decl ,
size_t idx ,
std : : string & name ,
uint64_t * bit_offset_ptr ,
uint32_t * bitfield_bit_size_ptr ,
bool * is_bitfield_ptr )
{
if ( class_interface_decl )
{
if ( idx < ( class_interface_decl - > ivar_size ( ) ) )
{
clang : : ObjCInterfaceDecl : : ivar_iterator ivar_pos , ivar_end = class_interface_decl - > ivar_end ( ) ;
uint32_t ivar_idx = 0 ;
for ( ivar_pos = class_interface_decl - > ivar_begin ( ) ; ivar_pos ! = ivar_end ; + + ivar_pos , + + ivar_idx )
{
if ( ivar_idx = = idx )
{
const clang : : ObjCIvarDecl * ivar_decl = * ivar_pos ;
clang : : QualType ivar_qual_type ( ivar_decl - > getType ( ) ) ;
name . assign ( ivar_decl - > getNameAsString ( ) ) ;
if ( bit_offset_ptr )
{
const clang : : ASTRecordLayout & interface_layout = ast - > getASTObjCInterfaceLayout ( class_interface_decl ) ;
* bit_offset_ptr = interface_layout . getFieldOffset ( ivar_idx ) ;
}
const bool is_bitfield = ivar_pos - > isBitField ( ) ;
if ( bitfield_bit_size_ptr )
{
* bitfield_bit_size_ptr = 0 ;
if ( is_bitfield & & ast )
{
clang : : Expr * bitfield_bit_size_expr = ivar_pos - > getBitWidth ( ) ;
llvm : : APSInt bitfield_apsint ;
if ( bitfield_bit_size_expr & & bitfield_bit_size_expr - > EvaluateAsInt ( bitfield_apsint , * ast ) )
{
* bitfield_bit_size_ptr = bitfield_apsint . getLimitedValue ( ) ;
}
}
}
if ( is_bitfield_ptr )
* is_bitfield_ptr = is_bitfield ;
return ivar_qual_type . getAsOpaquePtr ( ) ;
}
}
}
}
return nullptr ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetFieldAtIndex ( lldb : : opaque_compiler_type_t type , size_t idx ,
2015-08-25 07:46:31 +08:00
std : : string & name ,
uint64_t * bit_offset_ptr ,
uint32_t * bitfield_bit_size_ptr ,
bool * is_bitfield_ptr )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
2015-08-25 07:46:31 +08:00
if ( GetCompleteType ( type ) )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
uint32_t field_idx = 0 ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ; field ! = field_end ; + + field , + + field_idx )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
if ( idx = = field_idx )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
// Print the member type if requested
// Print the member name and equal sign
name . assign ( field - > getNameAsString ( ) ) ;
// Figure out the type byte size (field_type_info.first) and
// alignment (field_type_info.second) from the AST context.
if ( bit_offset_ptr )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : ASTRecordLayout & record_layout = getASTContext ( ) - > getASTRecordLayout ( record_decl ) ;
* bit_offset_ptr = record_layout . getFieldOffset ( field_idx ) ;
}
const bool is_bitfield = field - > isBitField ( ) ;
if ( bitfield_bit_size_ptr )
{
* bitfield_bit_size_ptr = 0 ;
if ( is_bitfield )
{
clang : : Expr * bitfield_bit_size_expr = field - > getBitWidth ( ) ;
llvm : : APSInt bitfield_apsint ;
if ( bitfield_bit_size_expr & & bitfield_bit_size_expr - > EvaluateAsInt ( bitfield_apsint , * getASTContext ( ) ) )
{
* bitfield_bit_size_ptr = bitfield_apsint . getLimitedValue ( ) ;
}
2015-08-12 05:38:15 +08:00
}
}
2015-08-25 07:46:31 +08:00
if ( is_bitfield_ptr )
* is_bitfield_ptr = is_bitfield ;
return CompilerType ( getASTContext ( ) , field - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
2015-08-25 07:46:31 +08:00
if ( GetCompleteType ( type ) )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : ObjCObjectPointerType * objc_class_type = qual_type - > getAsObjCInterfacePointerType ( ) ;
2015-08-12 05:38:15 +08:00
if ( objc_class_type )
{
2015-08-25 07:46:31 +08:00
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterfaceDecl ( ) ;
return CompilerType ( this , GetObjCFieldAtIndex ( getASTContext ( ) , class_interface_decl , idx , name , bit_offset_ptr , bitfield_bit_size_ptr , is_bitfield_ptr ) ) ;
2015-08-12 05:38:15 +08:00
}
}
break ;
2015-08-25 07:46:31 +08:00
case clang : : Type : : ObjCObject :
2015-08-12 05:38:15 +08:00
case clang : : Type : : ObjCInterface :
2015-08-25 07:46:31 +08:00
if ( GetCompleteType ( type ) )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
return CompilerType ( this , GetObjCFieldAtIndex ( getASTContext ( ) , class_interface_decl , idx , name , bit_offset_ptr , bitfield_bit_size_ptr , is_bitfield_ptr ) ) ;
2015-08-12 05:38:15 +08:00
}
}
break ;
case clang : : Type : : Typedef :
2015-08-25 07:46:31 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) .
GetFieldAtIndex ( idx ,
name ,
bit_offset_ptr ,
bitfield_bit_size_ptr ,
is_bitfield_ptr ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-25 07:46:31 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) .
GetFieldAtIndex ( idx ,
name ,
bit_offset_ptr ,
bitfield_bit_size_ptr ,
is_bitfield_ptr ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-25 07:46:31 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) .
GetFieldAtIndex ( idx ,
name ,
bit_offset_ptr ,
bitfield_bit_size_ptr ,
is_bitfield_ptr ) ;
2015-08-12 05:38:15 +08:00
default :
break ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumDirectBaseClasses ( lldb : : opaque_compiler_type_t type )
2015-08-25 07:46:31 +08:00
{
uint32_t count = 0 ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
count = cxx_record_decl - > getNumBases ( ) ;
}
break ;
case clang : : Type : : ObjCObjectPointer :
count = GetPointeeType ( type ) . GetNumDirectBaseClasses ( ) ;
break ;
case clang : : Type : : ObjCObject :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_class_type = qual_type - > getAsObjCQualifiedInterfaceType ( ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl & & class_interface_decl - > getSuperClass ( ) )
count = 1 ;
}
}
break ;
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
const clang : : ObjCInterfaceType * objc_interface_type = qual_type - > getAs < clang : : ObjCInterfaceType > ( ) ;
if ( objc_interface_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_interface_type - > getInterface ( ) ;
if ( class_interface_decl & & class_interface_decl - > getSuperClass ( ) )
count = 1 ;
}
}
break ;
case clang : : Type : : Typedef :
count = GetNumDirectBaseClasses ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ) ;
break ;
case clang : : Type : : Elaborated :
count = GetNumDirectBaseClasses ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ) ;
break ;
case clang : : Type : : Paren :
return GetNumDirectBaseClasses ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ) ;
default :
break ;
}
return count ;
}
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumVirtualBaseClasses ( lldb : : opaque_compiler_type_t type )
2015-08-25 07:46:31 +08:00
{
uint32_t count = 0 ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
count = cxx_record_decl - > getNumVBases ( ) ;
}
break ;
case clang : : Type : : Typedef :
count = GetNumVirtualBaseClasses ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) ) ;
break ;
case clang : : Type : : Elaborated :
count = GetNumVirtualBaseClasses ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) ) ;
break ;
case clang : : Type : : Paren :
count = GetNumVirtualBaseClasses ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) ) ;
break ;
default :
break ;
}
return count ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetDirectBaseClassAtIndex ( lldb : : opaque_compiler_type_t type , size_t idx , uint32_t * bit_offset_ptr )
2015-08-12 05:38:15 +08:00
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
2015-08-25 07:46:31 +08:00
if ( GetCompleteType ( type ) )
2015-08-12 05:38:15 +08:00
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
uint32_t curr_idx = 0 ;
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
2015-08-25 07:46:31 +08:00
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
2015-08-12 05:38:15 +08:00
base_class ! = base_class_end ;
+ + base_class , + + curr_idx )
{
if ( curr_idx = = idx )
{
if ( bit_offset_ptr )
{
2015-08-25 07:46:31 +08:00
const clang : : ASTRecordLayout & record_layout = getASTContext ( ) - > getASTRecordLayout ( cxx_record_decl ) ;
2015-08-12 05:38:15 +08:00
const clang : : CXXRecordDecl * base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
2015-08-25 07:46:31 +08:00
if ( base_class - > isVirtual ( ) )
* bit_offset_ptr = record_layout . getVBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
else
* bit_offset_ptr = record_layout . getBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
return CompilerType ( this , base_class - > getType ( ) . getAsOpaquePtr ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
}
}
break ;
2015-08-25 07:46:31 +08:00
case clang : : Type : : ObjCObjectPointer :
return GetPointeeType ( type ) . GetDirectBaseClassAtIndex ( idx , bit_offset_ptr ) ;
case clang : : Type : : ObjCObject :
if ( idx = = 0 & & GetCompleteType ( type ) )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : ObjCObjectType * objc_class_type = qual_type - > getAsObjCQualifiedInterfaceType ( ) ;
if ( objc_class_type )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
if ( superclass_interface_decl )
{
if ( bit_offset_ptr )
* bit_offset_ptr = 0 ;
return CompilerType ( getASTContext ( ) , getASTContext ( ) - > getObjCInterfaceType ( superclass_interface_decl ) ) ;
}
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
}
}
break ;
case clang : : Type : : ObjCInterface :
if ( idx = = 0 & & GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_interface_type = qual_type - > getAs < clang : : ObjCInterfaceType > ( ) ;
if ( objc_interface_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_interface_type - > getInterface ( ) ;
if ( class_interface_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
if ( superclass_interface_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
if ( bit_offset_ptr )
* bit_offset_ptr = 0 ;
return CompilerType ( getASTContext ( ) , getASTContext ( ) - > getObjCInterfaceType ( superclass_interface_decl ) ) ;
2015-08-12 05:38:15 +08:00
}
}
}
}
2015-08-25 07:46:31 +08:00
break ;
case clang : : Type : : Typedef :
return GetDirectBaseClassAtIndex ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
case clang : : Type : : Elaborated :
return GetDirectBaseClassAtIndex ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
case clang : : Type : : Paren :
return GetDirectBaseClassAtIndex ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
default :
break ;
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetVirtualBaseClassAtIndex ( lldb : : opaque_compiler_type_t type ,
2015-08-25 07:46:31 +08:00
size_t idx ,
uint32_t * bit_offset_ptr )
2015-08-12 05:38:15 +08:00
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
2015-08-25 07:46:31 +08:00
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
uint32_t curr_idx = 0 ;
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > vbases_begin ( ) , base_class_end = cxx_record_decl - > vbases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class , + + curr_idx )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
if ( curr_idx = = idx )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
if ( bit_offset_ptr )
2015-08-12 05:38:15 +08:00
{
2015-08-25 07:46:31 +08:00
const clang : : ASTRecordLayout & record_layout = getASTContext ( ) - > getASTRecordLayout ( cxx_record_decl ) ;
const clang : : CXXRecordDecl * base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
* bit_offset_ptr = record_layout . getVBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
2015-08-12 05:38:15 +08:00
}
2015-08-25 07:46:31 +08:00
return CompilerType ( this , base_class - > getType ( ) . getAsOpaquePtr ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
}
}
break ;
2015-08-25 07:46:31 +08:00
2015-08-12 05:38:15 +08:00
case clang : : Type : : Typedef :
2015-08-25 07:46:31 +08:00
return GetVirtualBaseClassAtIndex ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Elaborated :
2015-08-25 07:46:31 +08:00
return GetVirtualBaseClassAtIndex ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-25 07:46:31 +08:00
return GetVirtualBaseClassAtIndex ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , idx , bit_offset_ptr ) ;
2015-08-12 05:38:15 +08:00
default :
break ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-25 07:46:31 +08:00
2015-08-12 05:38:15 +08:00
}
// If a pointer to a pointee type (the clang_type arg) says that it has no
// children, then we either need to trust it, or override it and return a
// different result. For example, an "int *" has one child that is an integer,
// but a function pointer doesn't have any children. Likewise if a Record type
// claims it has no children, then there really is nothing to show.
uint32_t
ClangASTContext : : GetNumPointeeChildren ( clang : : QualType type )
{
if ( type . isNull ( ) )
return 0 ;
clang : : QualType qual_type ( type . getCanonicalType ( ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Builtin :
switch ( llvm : : cast < clang : : BuiltinType > ( qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : UnknownAny :
case clang : : BuiltinType : : Void :
case clang : : BuiltinType : : NullPtr :
case clang : : BuiltinType : : OCLEvent :
case clang : : BuiltinType : : OCLImage1d :
case clang : : BuiltinType : : OCLImage1dArray :
case clang : : BuiltinType : : OCLImage1dBuffer :
case clang : : BuiltinType : : OCLImage2d :
case clang : : BuiltinType : : OCLImage2dArray :
case clang : : BuiltinType : : OCLImage3d :
case clang : : BuiltinType : : OCLSampler :
return 0 ;
case clang : : BuiltinType : : Bool :
case clang : : BuiltinType : : Char_U :
case clang : : BuiltinType : : UChar :
case clang : : BuiltinType : : WChar_U :
case clang : : BuiltinType : : Char16 :
case clang : : BuiltinType : : Char32 :
case clang : : BuiltinType : : UShort :
case clang : : BuiltinType : : UInt :
case clang : : BuiltinType : : ULong :
case clang : : BuiltinType : : ULongLong :
case clang : : BuiltinType : : UInt128 :
case clang : : BuiltinType : : Char_S :
case clang : : BuiltinType : : SChar :
case clang : : BuiltinType : : WChar_S :
case clang : : BuiltinType : : Short :
case clang : : BuiltinType : : Int :
case clang : : BuiltinType : : Long :
case clang : : BuiltinType : : LongLong :
case clang : : BuiltinType : : Int128 :
case clang : : BuiltinType : : Float :
case clang : : BuiltinType : : Double :
case clang : : BuiltinType : : LongDouble :
case clang : : BuiltinType : : Dependent :
case clang : : BuiltinType : : Overload :
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
case clang : : BuiltinType : : ObjCSel :
case clang : : BuiltinType : : BoundMember :
case clang : : BuiltinType : : Half :
case clang : : BuiltinType : : ARCUnbridgedCast :
case clang : : BuiltinType : : PseudoObject :
case clang : : BuiltinType : : BuiltinFn :
2015-09-10 01:25:43 +08:00
case clang : : BuiltinType : : OMPArraySection :
2015-08-12 05:38:15 +08:00
return 1 ;
2015-09-17 02:08:45 +08:00
default :
return 0 ;
2015-08-12 05:38:15 +08:00
}
break ;
case clang : : Type : : Complex : return 1 ;
case clang : : Type : : Pointer : return 1 ;
case clang : : Type : : BlockPointer : return 0 ; // If block pointers don't have debug info, then no children for them
case clang : : Type : : LValueReference : return 1 ;
case clang : : Type : : RValueReference : return 1 ;
case clang : : Type : : MemberPointer : return 0 ;
case clang : : Type : : ConstantArray : return 0 ;
case clang : : Type : : IncompleteArray : return 0 ;
case clang : : Type : : VariableArray : return 0 ;
case clang : : Type : : DependentSizedArray : return 0 ;
case clang : : Type : : DependentSizedExtVector : return 0 ;
case clang : : Type : : Vector : return 0 ;
case clang : : Type : : ExtVector : return 0 ;
case clang : : Type : : FunctionProto : return 0 ; // When we function pointers, they have no children...
case clang : : Type : : FunctionNoProto : return 0 ; // When we function pointers, they have no children...
case clang : : Type : : UnresolvedUsing : return 0 ;
case clang : : Type : : Paren : return GetNumPointeeChildren ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) ;
case clang : : Type : : Typedef : return GetNumPointeeChildren ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) ;
case clang : : Type : : Elaborated : return GetNumPointeeChildren ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) ;
case clang : : Type : : TypeOfExpr : return 0 ;
case clang : : Type : : TypeOf : return 0 ;
case clang : : Type : : Decltype : return 0 ;
case clang : : Type : : Record : return 0 ;
case clang : : Type : : Enum : return 1 ;
case clang : : Type : : TemplateTypeParm : return 1 ;
case clang : : Type : : SubstTemplateTypeParm : return 1 ;
case clang : : Type : : TemplateSpecialization : return 1 ;
case clang : : Type : : InjectedClassName : return 0 ;
case clang : : Type : : DependentName : return 1 ;
case clang : : Type : : DependentTemplateSpecialization : return 1 ;
case clang : : Type : : ObjCObject : return 0 ;
case clang : : Type : : ObjCInterface : return 0 ;
case clang : : Type : : ObjCObjectPointer : return 1 ;
default :
break ;
}
return 0 ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetChildCompilerTypeAtIndex ( lldb : : opaque_compiler_type_t type ,
2015-09-22 00:48:48 +08:00
ExecutionContext * exe_ctx ,
size_t idx ,
bool transparent_pointers ,
bool omit_empty_base_classes ,
bool ignore_array_bounds ,
std : : string & child_name ,
uint32_t & child_byte_size ,
int32_t & child_byte_offset ,
uint32_t & child_bitfield_bit_size ,
uint32_t & child_bitfield_bit_offset ,
bool & child_is_base_class ,
bool & child_is_deref_of_parent ,
ValueObject * valobj )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
clang : : QualType parent_qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass parent_type_class = parent_qual_type - > getTypeClass ( ) ;
child_bitfield_bit_size = 0 ;
child_bitfield_bit_offset = 0 ;
child_is_base_class = false ;
const bool idx_is_valid = idx < GetNumChildren ( type , omit_empty_base_classes ) ;
uint32_t bit_offset ;
switch ( parent_type_class )
{
case clang : : Type : : Builtin :
if ( idx_is_valid )
{
switch ( llvm : : cast < clang : : BuiltinType > ( parent_qual_type ) - > getKind ( ) )
{
case clang : : BuiltinType : : ObjCId :
case clang : : BuiltinType : : ObjCClass :
child_name = " isa " ;
child_byte_size = getASTContext ( ) - > getTypeSize ( getASTContext ( ) - > ObjCBuiltinClassTy ) / CHAR_BIT ;
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , getASTContext ( ) - > ObjCBuiltinClassTy ) ;
2015-08-12 05:38:15 +08:00
default :
break ;
}
}
break ;
case clang : : Type : : Record :
if ( idx_is_valid & & GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( parent_qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
const clang : : ASTRecordLayout & record_layout = getASTContext ( ) - > getASTRecordLayout ( record_decl ) ;
uint32_t child_idx = 0 ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
// We might have base classes to print out first
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
const clang : : CXXRecordDecl * base_class_decl = nullptr ;
// Skip empty base classes
if ( omit_empty_base_classes )
{
base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
if ( ClangASTContext : : RecordHasFields ( base_class_decl ) = = false )
continue ;
}
if ( idx = = child_idx )
{
if ( base_class_decl = = nullptr )
base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
if ( base_class - > isVirtual ( ) )
{
bool handled = false ;
if ( valobj )
{
Error err ;
AddressType addr_type = eAddressTypeInvalid ;
lldb : : addr_t vtable_ptr_addr = valobj - > GetCPPVTableAddress ( addr_type ) ;
if ( vtable_ptr_addr ! = LLDB_INVALID_ADDRESS & & addr_type = = eAddressTypeLoad )
{
ExecutionContext exe_ctx ( valobj - > GetExecutionContextRef ( ) ) ;
Process * process = exe_ctx . GetProcessPtr ( ) ;
if ( process )
{
clang : : VTableContextBase * vtable_ctx = getASTContext ( ) - > getVTableContext ( ) ;
if ( vtable_ctx )
{
if ( vtable_ctx - > isMicrosoft ( ) )
{
clang : : MicrosoftVTableContext * msoft_vtable_ctx = static_cast < clang : : MicrosoftVTableContext * > ( vtable_ctx ) ;
if ( vtable_ptr_addr )
{
const lldb : : addr_t vbtable_ptr_addr = vtable_ptr_addr + record_layout . getVBPtrOffset ( ) . getQuantity ( ) ;
const lldb : : addr_t vbtable_ptr = process - > ReadPointerFromMemory ( vbtable_ptr_addr , err ) ;
if ( vbtable_ptr ! = LLDB_INVALID_ADDRESS )
{
// Get the index into the virtual base table. The index is the index in uint32_t from vbtable_ptr
const unsigned vbtable_index = msoft_vtable_ctx - > getVBTableIndex ( cxx_record_decl , base_class_decl ) ;
const lldb : : addr_t base_offset_addr = vbtable_ptr + vbtable_index * 4 ;
const uint32_t base_offset = process - > ReadUnsignedIntegerFromMemory ( base_offset_addr , 4 , UINT32_MAX , err ) ;
if ( base_offset ! = UINT32_MAX )
{
handled = true ;
bit_offset = base_offset * 8 ;
}
}
}
}
else
{
clang : : ItaniumVTableContext * itanium_vtable_ctx = static_cast < clang : : ItaniumVTableContext * > ( vtable_ctx ) ;
if ( vtable_ptr_addr )
{
const lldb : : addr_t vtable_ptr = process - > ReadPointerFromMemory ( vtable_ptr_addr , err ) ;
if ( vtable_ptr ! = LLDB_INVALID_ADDRESS )
{
clang : : CharUnits base_offset_offset = itanium_vtable_ctx - > getVirtualBaseOffsetOffset ( cxx_record_decl , base_class_decl ) ;
const lldb : : addr_t base_offset_addr = vtable_ptr + base_offset_offset . getQuantity ( ) ;
const uint32_t base_offset = process - > ReadUnsignedIntegerFromMemory ( base_offset_addr , 4 , UINT32_MAX , err ) ;
if ( base_offset ! = UINT32_MAX )
{
handled = true ;
bit_offset = base_offset * 8 ;
}
}
}
}
}
}
}
}
if ( ! handled )
bit_offset = record_layout . getVBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
}
else
bit_offset = record_layout . getBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
// Base classes should be a multiple of 8 bits in size
child_byte_offset = bit_offset / 8 ;
2015-08-12 06:53:00 +08:00
CompilerType base_class_clang_type ( getASTContext ( ) , base_class - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
child_name = base_class_clang_type . GetTypeName ( ) . AsCString ( " " ) ;
uint64_t base_class_clang_type_bit_size = base_class_clang_type . GetBitSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
// Base classes bit sizes should be a multiple of 8 bits in size
assert ( base_class_clang_type_bit_size % 8 = = 0 ) ;
child_byte_size = base_class_clang_type_bit_size / 8 ;
child_is_base_class = true ;
return base_class_clang_type ;
}
// We don't increment the child index in the for loop since we might
// be skipping empty base classes
+ + child_idx ;
}
}
// Make sure index is in range...
uint32_t field_idx = 0 ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ; field ! = field_end ; + + field , + + field_idx , + + child_idx )
{
if ( idx = = child_idx )
{
// Print the member type if requested
// Print the member name and equal sign
child_name . assign ( field - > getNameAsString ( ) . c_str ( ) ) ;
// Figure out the type byte size (field_type_info.first) and
// alignment (field_type_info.second) from the AST context.
2015-08-12 06:53:00 +08:00
CompilerType field_clang_type ( getASTContext ( ) , field - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
assert ( field_idx < record_layout . getFieldCount ( ) ) ;
child_byte_size = field_clang_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
// Figure out the field offset within the current struct/union/class type
bit_offset = record_layout . getFieldOffset ( field_idx ) ;
child_byte_offset = bit_offset / 8 ;
if ( ClangASTContext : : FieldIsBitfield ( getASTContext ( ) , * field , child_bitfield_bit_size ) )
child_bitfield_bit_offset = bit_offset % 8 ;
return field_clang_type ;
}
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( idx_is_valid & & GetCompleteType ( type ) )
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( parent_qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
uint32_t child_idx = 0 ;
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
const clang : : ASTRecordLayout & interface_layout = getASTContext ( ) - > getASTObjCInterfaceLayout ( class_interface_decl ) ;
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
if ( superclass_interface_decl )
{
if ( omit_empty_base_classes )
{
2015-08-12 06:53:00 +08:00
CompilerType base_class_clang_type ( getASTContext ( ) , getASTContext ( ) - > getObjCInterfaceType ( superclass_interface_decl ) ) ;
2015-08-12 05:38:15 +08:00
if ( base_class_clang_type . GetNumChildren ( omit_empty_base_classes ) > 0 )
{
if ( idx = = 0 )
{
clang : : QualType ivar_qual_type ( getASTContext ( ) - > getObjCInterfaceType ( superclass_interface_decl ) ) ;
child_name . assign ( superclass_interface_decl - > getNameAsString ( ) . c_str ( ) ) ;
clang : : TypeInfo ivar_type_info = getASTContext ( ) - > getTypeInfo ( ivar_qual_type . getTypePtr ( ) ) ;
child_byte_size = ivar_type_info . Width / 8 ;
child_byte_offset = 0 ;
child_is_base_class = true ;
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , ivar_qual_type ) ;
2015-08-12 05:38:15 +08:00
}
+ + child_idx ;
}
}
else
+ + child_idx ;
}
const uint32_t superclass_idx = child_idx ;
if ( idx < ( child_idx + class_interface_decl - > ivar_size ( ) ) )
{
clang : : ObjCInterfaceDecl : : ivar_iterator ivar_pos , ivar_end = class_interface_decl - > ivar_end ( ) ;
for ( ivar_pos = class_interface_decl - > ivar_begin ( ) ; ivar_pos ! = ivar_end ; + + ivar_pos )
{
if ( child_idx = = idx )
{
clang : : ObjCIvarDecl * ivar_decl = * ivar_pos ;
clang : : QualType ivar_qual_type ( ivar_decl - > getType ( ) ) ;
child_name . assign ( ivar_decl - > getNameAsString ( ) . c_str ( ) ) ;
clang : : TypeInfo ivar_type_info = getASTContext ( ) - > getTypeInfo ( ivar_qual_type . getTypePtr ( ) ) ;
child_byte_size = ivar_type_info . Width / 8 ;
// Figure out the field offset within the current struct/union/class type
// For ObjC objects, we can't trust the bit offset we get from the Clang AST, since
// that doesn't account for the space taken up by unbacked properties, or from
// the changing size of base classes that are newer than this class.
// So if we have a process around that we can ask about this object, do so.
child_byte_offset = LLDB_INVALID_IVAR_OFFSET ;
Process * process = nullptr ;
if ( exe_ctx )
process = exe_ctx - > GetProcessPtr ( ) ;
if ( process )
{
ObjCLanguageRuntime * objc_runtime = process - > GetObjCLanguageRuntime ( ) ;
if ( objc_runtime ! = nullptr )
{
2015-08-12 06:53:00 +08:00
CompilerType parent_ast_type ( getASTContext ( ) , parent_qual_type ) ;
2015-08-12 05:38:15 +08:00
child_byte_offset = objc_runtime - > GetByteOffsetForIvar ( parent_ast_type , ivar_decl - > getNameAsString ( ) . c_str ( ) ) ;
}
}
// Setting this to UINT32_MAX to make sure we don't compute it twice...
bit_offset = UINT32_MAX ;
if ( child_byte_offset = = static_cast < int32_t > ( LLDB_INVALID_IVAR_OFFSET ) )
{
bit_offset = interface_layout . getFieldOffset ( child_idx - superclass_idx ) ;
child_byte_offset = bit_offset / 8 ;
}
// Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset
// of a bitfield within its containing object. So regardless of where we get the byte
// offset from, we still need to get the bit offset for bitfields from the layout.
if ( ClangASTContext : : FieldIsBitfield ( getASTContext ( ) , ivar_decl , child_bitfield_bit_size ) )
{
if ( bit_offset = = UINT32_MAX )
bit_offset = interface_layout . getFieldOffset ( child_idx - superclass_idx ) ;
child_bitfield_bit_offset = bit_offset % 8 ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , ivar_qual_type ) ;
2015-08-12 05:38:15 +08:00
}
+ + child_idx ;
}
}
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
if ( idx_is_valid )
{
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( GetPointeeType ( type ) ) ;
2015-08-12 05:38:15 +08:00
if ( transparent_pointers & & pointee_clang_type . IsAggregateType ( ) )
{
child_is_deref_of_parent = false ;
bool tmp_child_is_deref_of_parent = false ;
2015-09-22 00:48:48 +08:00
return pointee_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
tmp_child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
else
{
child_is_deref_of_parent = true ;
const char * parent_name = valobj ? valobj - > GetName ( ) . GetCString ( ) : NULL ;
if ( parent_name )
{
child_name . assign ( 1 , ' * ' ) ;
child_name + = parent_name ;
}
// We have a pointer to an simple type
if ( idx = = 0 & & pointee_clang_type . GetCompleteType ( ) )
{
child_byte_size = pointee_clang_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
child_byte_offset = 0 ;
return pointee_clang_type ;
}
}
}
break ;
case clang : : Type : : Vector :
case clang : : Type : : ExtVector :
if ( idx_is_valid )
{
const clang : : VectorType * array = llvm : : cast < clang : : VectorType > ( parent_qual_type . getTypePtr ( ) ) ;
if ( array )
{
2015-08-12 06:53:00 +08:00
CompilerType element_type ( getASTContext ( ) , array - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( element_type . GetCompleteType ( ) )
{
char element_name [ 64 ] ;
: : snprintf ( element_name , sizeof ( element_name ) , " [% " PRIu64 " ] " , static_cast < uint64_t > ( idx ) ) ;
child_name . assign ( element_name ) ;
child_byte_size = element_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
child_byte_offset = ( int32_t ) idx * ( int32_t ) child_byte_size ;
return element_type ;
}
}
}
break ;
case clang : : Type : : ConstantArray :
case clang : : Type : : IncompleteArray :
if ( ignore_array_bounds | | idx_is_valid )
{
const clang : : ArrayType * array = GetQualType ( type ) - > getAsArrayTypeUnsafe ( ) ;
if ( array )
{
2015-08-12 06:53:00 +08:00
CompilerType element_type ( getASTContext ( ) , array - > getElementType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( element_type . GetCompleteType ( ) )
{
char element_name [ 64 ] ;
: : snprintf ( element_name , sizeof ( element_name ) , " [% " PRIu64 " ] " , static_cast < uint64_t > ( idx ) ) ;
child_name . assign ( element_name ) ;
child_byte_size = element_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
child_byte_offset = ( int32_t ) idx * ( int32_t ) child_byte_size ;
return element_type ;
}
}
}
break ;
case clang : : Type : : Pointer :
if ( idx_is_valid )
{
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( GetPointeeType ( type ) ) ;
2015-08-12 05:38:15 +08:00
// Don't dereference "void *" pointers
if ( pointee_clang_type . IsVoidType ( ) )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
if ( transparent_pointers & & pointee_clang_type . IsAggregateType ( ) )
{
child_is_deref_of_parent = false ;
bool tmp_child_is_deref_of_parent = false ;
2015-09-22 00:48:48 +08:00
return pointee_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
tmp_child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
else
{
child_is_deref_of_parent = true ;
const char * parent_name = valobj ? valobj - > GetName ( ) . GetCString ( ) : NULL ;
if ( parent_name )
{
child_name . assign ( 1 , ' * ' ) ;
child_name + = parent_name ;
}
// We have a pointer to an simple type
if ( idx = = 0 )
{
child_byte_size = pointee_clang_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
child_byte_offset = 0 ;
return pointee_clang_type ;
}
}
}
break ;
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
if ( idx_is_valid )
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( parent_qual_type . getTypePtr ( ) ) ;
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( getASTContext ( ) , reference_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( transparent_pointers & & pointee_clang_type . IsAggregateType ( ) )
{
child_is_deref_of_parent = false ;
bool tmp_child_is_deref_of_parent = false ;
2015-09-22 00:48:48 +08:00
return pointee_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
tmp_child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
else
{
const char * parent_name = valobj ? valobj - > GetName ( ) . GetCString ( ) : NULL ;
if ( parent_name )
{
child_name . assign ( 1 , ' & ' ) ;
child_name + = parent_name ;
}
// We have a pointer to an simple type
if ( idx = = 0 )
{
child_byte_size = pointee_clang_type . GetByteSize ( exe_ctx ? exe_ctx - > GetBestExecutionContextScope ( ) : NULL ) ;
child_byte_offset = 0 ;
return pointee_clang_type ;
}
}
}
break ;
case clang : : Type : : Typedef :
{
2015-08-12 06:53:00 +08:00
CompilerType typedefed_clang_type ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( parent_qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) ;
2015-09-22 00:48:48 +08:00
return typedefed_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
break ;
case clang : : Type : : Elaborated :
{
2015-08-12 06:53:00 +08:00
CompilerType elaborated_clang_type ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( parent_qual_type ) - > getNamedType ( ) ) ;
2015-09-22 00:48:48 +08:00
return elaborated_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
case clang : : Type : : Paren :
{
2015-08-12 06:53:00 +08:00
CompilerType paren_clang_type ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( parent_qual_type ) - > desugar ( ) ) ;
2015-09-22 00:48:48 +08:00
return paren_clang_type . GetChildCompilerTypeAtIndex ( exe_ctx ,
idx ,
transparent_pointers ,
omit_empty_base_classes ,
ignore_array_bounds ,
child_name ,
child_byte_size ,
child_byte_offset ,
child_bitfield_bit_size ,
child_bitfield_bit_offset ,
child_is_base_class ,
child_is_deref_of_parent ,
valobj ) ;
2015-08-12 05:38:15 +08:00
}
default :
break ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
static uint32_t
GetIndexForRecordBase
(
const clang : : RecordDecl * record_decl ,
const clang : : CXXBaseSpecifier * base_spec ,
bool omit_empty_base_classes
)
{
uint32_t child_idx = 0 ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
// const char *super_name = record_decl->getNameAsCString();
// const char *base_name = base_spec->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString();
// printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name);
//
if ( cxx_record_decl )
{
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
if ( omit_empty_base_classes )
{
if ( BaseSpecifierIsEmpty ( base_class ) )
continue ;
}
// printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name,
// child_idx,
// base_class->getType()->getAs<clang::RecordType>()->getDecl()->getNameAsCString());
//
//
if ( base_class = = base_spec )
return child_idx ;
+ + child_idx ;
}
}
return UINT32_MAX ;
}
static uint32_t
GetIndexForRecordChild ( const clang : : RecordDecl * record_decl ,
clang : : NamedDecl * canonical_decl ,
bool omit_empty_base_classes )
{
uint32_t child_idx = ClangASTContext : : GetNumBaseClasses ( llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ,
omit_empty_base_classes ) ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ;
field ! = field_end ;
+ + field , + + child_idx )
{
if ( field - > getCanonicalDecl ( ) = = canonical_decl )
return child_idx ;
}
return UINT32_MAX ;
}
// Look for a child member (doesn't include base classes, but it does include
// their members) in the type hierarchy. Returns an index path into "clang_type"
// on how to reach the appropriate member.
//
// class A
// {
// public:
// int m_a;
// int m_b;
// };
//
// class B
// {
// };
//
// class C :
// public B,
// public A
// {
// };
//
// If we have a clang type that describes "class C", and we wanted to looked
// "m_b" in it:
//
// With omit_empty_base_classes == false we would get an integer array back with:
// { 1, 1 }
// The first index 1 is the child index for "class A" within class C
// The second index 1 is the child index for "m_b" within class A
//
// With omit_empty_base_classes == true we would get an integer array back with:
// { 0, 1 }
// The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
// The second index 1 is the child index for "m_b" within class A
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetIndexOfChildMemberWithName ( lldb : : opaque_compiler_type_t type , const char * name ,
2015-08-12 05:38:15 +08:00
bool omit_empty_base_classes ,
std : : vector < uint32_t > & child_indexes )
{
if ( type & & name & & name [ 0 ] )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
uint32_t child_idx = 0 ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
// Try and find a field that matches NAME
clang : : RecordDecl : : field_iterator field , field_end ;
llvm : : StringRef name_sref ( name ) ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ;
field ! = field_end ;
+ + field , + + child_idx )
{
llvm : : StringRef field_name = field - > getName ( ) ;
if ( field_name . empty ( ) )
{
2015-08-12 06:53:00 +08:00
CompilerType field_type ( getASTContext ( ) , field - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
child_indexes . push_back ( child_idx ) ;
if ( field_type . GetIndexOfChildMemberWithName ( name , omit_empty_base_classes , child_indexes ) )
return child_indexes . size ( ) ;
child_indexes . pop_back ( ) ;
}
else if ( field_name . equals ( name_sref ) )
{
// We have to add on the number of base classes to this index!
child_indexes . push_back ( child_idx + ClangASTContext : : GetNumBaseClasses ( cxx_record_decl , omit_empty_base_classes ) ) ;
return child_indexes . size ( ) ;
}
}
if ( cxx_record_decl )
{
const clang : : RecordDecl * parent_record_decl = cxx_record_decl ;
//printf ("parent = %s\n", parent_record_decl->getNameAsCString());
//const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl();
// Didn't find things easily, lets let clang do its thang...
clang : : IdentifierInfo & ident_ref = getASTContext ( ) - > Idents . get ( name_sref ) ;
clang : : DeclarationName decl_name ( & ident_ref ) ;
clang : : CXXBasePaths paths ;
if ( cxx_record_decl - > lookupInBases ( [ decl_name ] ( const clang : : CXXBaseSpecifier * specifier , clang : : CXXBasePath & path ) {
return clang : : CXXRecordDecl : : FindOrdinaryMember ( specifier , path , decl_name ) ;
} ,
paths ) )
{
clang : : CXXBasePaths : : const_paths_iterator path , path_end = paths . end ( ) ;
for ( path = paths . begin ( ) ; path ! = path_end ; + + path )
{
const size_t num_path_elements = path - > size ( ) ;
for ( size_t e = 0 ; e < num_path_elements ; + + e )
{
clang : : CXXBasePathElement elem = ( * path ) [ e ] ;
child_idx = GetIndexForRecordBase ( parent_record_decl , elem . Base , omit_empty_base_classes ) ;
if ( child_idx = = UINT32_MAX )
{
child_indexes . clear ( ) ;
return 0 ;
}
else
{
child_indexes . push_back ( child_idx ) ;
parent_record_decl = llvm : : cast < clang : : RecordDecl > ( elem . Base - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
}
}
for ( clang : : NamedDecl * path_decl : path - > Decls )
{
child_idx = GetIndexForRecordChild ( parent_record_decl , path_decl , omit_empty_base_classes ) ;
if ( child_idx = = UINT32_MAX )
{
child_indexes . clear ( ) ;
return 0 ;
}
else
{
child_indexes . push_back ( child_idx ) ;
}
}
}
return child_indexes . size ( ) ;
}
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
llvm : : StringRef name_sref ( name ) ;
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
uint32_t child_idx = 0 ;
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
clang : : ObjCInterfaceDecl : : ivar_iterator ivar_pos , ivar_end = class_interface_decl - > ivar_end ( ) ;
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
for ( ivar_pos = class_interface_decl - > ivar_begin ( ) ; ivar_pos ! = ivar_end ; + + ivar_pos , + + child_idx )
{
const clang : : ObjCIvarDecl * ivar_decl = * ivar_pos ;
if ( ivar_decl - > getName ( ) . equals ( name_sref ) )
{
if ( ( ! omit_empty_base_classes & & superclass_interface_decl ) | |
( omit_empty_base_classes & & ObjCDeclHasIVars ( superclass_interface_decl , true ) ) )
+ + child_idx ;
child_indexes . push_back ( child_idx ) ;
return child_indexes . size ( ) ;
}
}
if ( superclass_interface_decl )
{
// The super class index is always zero for ObjC classes,
// so we push it onto the child indexes in case we find
// an ivar in our superclass...
child_indexes . push_back ( 0 ) ;
2015-08-12 06:53:00 +08:00
CompilerType superclass_clang_type ( getASTContext ( ) , getASTContext ( ) - > getObjCInterfaceType ( superclass_interface_decl ) ) ;
2015-08-12 05:38:15 +08:00
if ( superclass_clang_type . GetIndexOfChildMemberWithName ( name ,
omit_empty_base_classes ,
child_indexes ) )
{
// We did find an ivar in a superclass so just
// return the results!
return child_indexes . size ( ) ;
}
// We didn't find an ivar matching "name" in our
// superclass, pop the superclass zero index that
// we pushed on above.
child_indexes . pop_back ( ) ;
}
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
{
2015-08-12 06:53:00 +08:00
CompilerType objc_object_clang_type ( getASTContext ( ) , llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type . getTypePtr ( ) ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return objc_object_clang_type . GetIndexOfChildMemberWithName ( name ,
omit_empty_base_classes ,
child_indexes ) ;
}
break ;
case clang : : Type : : ConstantArray :
{
// const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
// const uint64_t element_count = array->getSize().getLimitedValue();
//
// if (idx < element_count)
// {
// std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
//
// char element_name[32];
// ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
//
// child_name.assign(element_name);
// assert(field_type_info.first % 8 == 0);
// child_byte_size = field_type_info.first / 8;
// child_byte_offset = idx * child_byte_size;
// return array->getElementType().getAsOpaquePtr();
// }
}
break ;
// case clang::Type::MemberPointerType:
// {
// MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
// clang::QualType pointee_type = mem_ptr_type->getPointeeType();
//
// if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
// {
// return GetIndexOfChildWithName (ast,
// mem_ptr_type->getPointeeType().getAsOpaquePtr(),
// name);
// }
// }
// break;
//
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) ;
clang : : QualType pointee_type ( reference_type - > getPointeeType ( ) ) ;
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( getASTContext ( ) , pointee_type ) ;
2015-08-12 05:38:15 +08:00
if ( pointee_clang_type . IsAggregateType ( ) )
{
return pointee_clang_type . GetIndexOfChildMemberWithName ( name ,
omit_empty_base_classes ,
child_indexes ) ;
}
}
break ;
case clang : : Type : : Pointer :
{
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( GetPointeeType ( type ) ) ;
2015-08-12 05:38:15 +08:00
if ( pointee_clang_type . IsAggregateType ( ) )
{
return pointee_clang_type . GetIndexOfChildMemberWithName ( name ,
omit_empty_base_classes ,
child_indexes ) ;
}
}
break ;
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetIndexOfChildMemberWithName ( name ,
2015-08-12 05:38:15 +08:00
omit_empty_base_classes ,
child_indexes ) ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetIndexOfChildMemberWithName ( name ,
2015-08-12 05:38:15 +08:00
omit_empty_base_classes ,
child_indexes ) ;
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetIndexOfChildMemberWithName ( name ,
2015-08-12 05:38:15 +08:00
omit_empty_base_classes ,
child_indexes ) ;
default :
break ;
}
}
return 0 ;
}
// Get the index of the child of "clang_type" whose name matches. This function
// doesn't descend into the children, but only looks one level deep and name
// matches can include base class names.
uint32_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetIndexOfChildWithName ( lldb : : opaque_compiler_type_t type , const char * name , bool omit_empty_base_classes )
2015-08-12 05:38:15 +08:00
{
if ( type & & name & & name [ 0 ] )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
uint32_t child_idx = 0 ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
// Skip empty base classes
clang : : CXXRecordDecl * base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
if ( omit_empty_base_classes & & ClangASTContext : : RecordHasFields ( base_class_decl ) = = false )
continue ;
2015-08-12 06:53:00 +08:00
CompilerType base_class_clang_type ( getASTContext ( ) , base_class - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
std : : string base_class_type_name ( base_class_clang_type . GetTypeName ( ) . AsCString ( " " ) ) ;
if ( base_class_type_name . compare ( name ) = = 0 )
return child_idx ;
+ + child_idx ;
}
}
// Try and find a field that matches NAME
clang : : RecordDecl : : field_iterator field , field_end ;
llvm : : StringRef name_sref ( name ) ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ;
field ! = field_end ;
+ + field , + + child_idx )
{
if ( field - > getName ( ) . equals ( name_sref ) )
return child_idx ;
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
if ( GetCompleteType ( type ) )
{
llvm : : StringRef name_sref ( name ) ;
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
uint32_t child_idx = 0 ;
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
clang : : ObjCInterfaceDecl : : ivar_iterator ivar_pos , ivar_end = class_interface_decl - > ivar_end ( ) ;
clang : : ObjCInterfaceDecl * superclass_interface_decl = class_interface_decl - > getSuperClass ( ) ;
for ( ivar_pos = class_interface_decl - > ivar_begin ( ) ; ivar_pos ! = ivar_end ; + + ivar_pos , + + child_idx )
{
const clang : : ObjCIvarDecl * ivar_decl = * ivar_pos ;
if ( ivar_decl - > getName ( ) . equals ( name_sref ) )
{
if ( ( ! omit_empty_base_classes & & superclass_interface_decl ) | |
( omit_empty_base_classes & & ObjCDeclHasIVars ( superclass_interface_decl , true ) ) )
+ + child_idx ;
return child_idx ;
}
}
if ( superclass_interface_decl )
{
if ( superclass_interface_decl - > getName ( ) . equals ( name_sref ) )
return 0 ;
}
}
}
}
break ;
case clang : : Type : : ObjCObjectPointer :
{
2015-08-12 06:53:00 +08:00
CompilerType pointee_clang_type ( getASTContext ( ) , llvm : : cast < clang : : ObjCObjectPointerType > ( qual_type . getTypePtr ( ) ) - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
return pointee_clang_type . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
}
break ;
case clang : : Type : : ConstantArray :
{
// const clang::ConstantArrayType *array = llvm::cast<clang::ConstantArrayType>(parent_qual_type.getTypePtr());
// const uint64_t element_count = array->getSize().getLimitedValue();
//
// if (idx < element_count)
// {
// std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType());
//
// char element_name[32];
// ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx);
//
// child_name.assign(element_name);
// assert(field_type_info.first % 8 == 0);
// child_byte_size = field_type_info.first / 8;
// child_byte_offset = idx * child_byte_size;
// return array->getElementType().getAsOpaquePtr();
// }
}
break ;
// case clang::Type::MemberPointerType:
// {
// MemberPointerType *mem_ptr_type = llvm::cast<MemberPointerType>(qual_type.getTypePtr());
// clang::QualType pointee_type = mem_ptr_type->getPointeeType();
//
// if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
// {
// return GetIndexOfChildWithName (ast,
// mem_ptr_type->getPointeeType().getAsOpaquePtr(),
// name);
// }
// }
// break;
//
case clang : : Type : : LValueReference :
case clang : : Type : : RValueReference :
{
const clang : : ReferenceType * reference_type = llvm : : cast < clang : : ReferenceType > ( qual_type . getTypePtr ( ) ) ;
2015-08-12 06:53:00 +08:00
CompilerType pointee_type ( getASTContext ( ) , reference_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( pointee_type . IsAggregateType ( ) )
{
return pointee_type . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
}
}
break ;
case clang : : Type : : Pointer :
{
const clang : : PointerType * pointer_type = llvm : : cast < clang : : PointerType > ( qual_type . getTypePtr ( ) ) ;
2015-08-12 06:53:00 +08:00
CompilerType pointee_type ( getASTContext ( ) , pointer_type - > getPointeeType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( pointee_type . IsAggregateType ( ) )
{
return pointee_type . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
}
else
{
// if (parent_name)
// {
// child_name.assign(1, '*');
// child_name += parent_name;
// }
//
// // We have a pointer to an simple type
// if (idx == 0)
// {
// std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type);
// assert(clang_type_info.first % 8 == 0);
// child_byte_size = clang_type_info.first / 8;
// child_byte_offset = 0;
// return pointee_type.getAsOpaquePtr();
// }
}
}
break ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
case clang : : Type : : Typedef :
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) . GetIndexOfChildWithName ( name , omit_empty_base_classes ) ;
2015-08-12 05:38:15 +08:00
default :
break ;
}
}
return UINT32_MAX ;
}
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetNumTemplateArguments ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return 0 ;
2015-08-13 08:24:24 +08:00
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
const clang : : ClassTemplateSpecializationDecl * template_decl = llvm : : dyn_cast < clang : : ClassTemplateSpecializationDecl > ( cxx_record_decl ) ;
if ( template_decl )
return template_decl - > getTemplateArgs ( ) . size ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-13 08:24:24 +08:00
}
break ;
case clang : : Type : : Typedef :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) ) . GetNumTemplateArguments ( ) ;
case clang : : Type : : Elaborated :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) ) . GetNumTemplateArguments ( ) ;
case clang : : Type : : Paren :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) ) . GetNumTemplateArguments ( ) ;
default :
break ;
2015-08-12 05:38:15 +08:00
}
2015-08-13 08:24:24 +08:00
2015-08-12 05:38:15 +08:00
return 0 ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetTemplateArgument ( lldb : : opaque_compiler_type_t type , size_t arg_idx , lldb : : TemplateArgumentKind & kind )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-13 08:24:24 +08:00
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
const clang : : ClassTemplateSpecializationDecl * template_decl = llvm : : dyn_cast < clang : : ClassTemplateSpecializationDecl > ( cxx_record_decl ) ;
if ( template_decl & & arg_idx < template_decl - > getTemplateArgs ( ) . size ( ) )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
const clang : : TemplateArgument & template_arg = template_decl - > getTemplateArgs ( ) [ arg_idx ] ;
switch ( template_arg . getKind ( ) )
2015-08-12 05:38:15 +08:00
{
2015-08-13 08:24:24 +08:00
case clang : : TemplateArgument : : Null :
kind = eTemplateArgumentKindNull ;
return CompilerType ( ) ;
case clang : : TemplateArgument : : Type :
kind = eTemplateArgumentKindType ;
return CompilerType ( getASTContext ( ) , template_arg . getAsType ( ) ) ;
case clang : : TemplateArgument : : Declaration :
kind = eTemplateArgumentKindDeclaration ;
return CompilerType ( ) ;
case clang : : TemplateArgument : : Integral :
kind = eTemplateArgumentKindIntegral ;
return CompilerType ( getASTContext ( ) , template_arg . getIntegralType ( ) ) ;
case clang : : TemplateArgument : : Template :
kind = eTemplateArgumentKindTemplate ;
return CompilerType ( ) ;
case clang : : TemplateArgument : : TemplateExpansion :
kind = eTemplateArgumentKindTemplateExpansion ;
return CompilerType ( ) ;
case clang : : TemplateArgument : : Expression :
kind = eTemplateArgumentKindExpression ;
return CompilerType ( ) ;
case clang : : TemplateArgument : : Pack :
kind = eTemplateArgumentKindPack ;
return CompilerType ( ) ;
default :
assert ( ! " Unhandled clang::TemplateArgument::ArgKind " ) ;
break ;
2015-08-12 05:38:15 +08:00
}
}
}
2015-08-13 08:24:24 +08:00
}
break ;
case clang : : Type : : Typedef :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ) ) . GetTemplateArgument ( arg_idx , kind ) ;
case clang : : Type : : Elaborated :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) ) . GetTemplateArgument ( arg_idx , kind ) ;
case clang : : Type : : Paren :
return ( CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) ) . GetTemplateArgument ( arg_idx , kind ) ;
default :
break ;
2015-08-12 05:38:15 +08:00
}
kind = eTemplateArgumentKindNull ;
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-09-23 09:39:46 +08:00
CompilerType
ClangASTContext : : GetTypeForFormatters ( void * type )
{
if ( type )
return RemoveFastQualifiers ( CompilerType ( this , type ) ) ;
return CompilerType ( ) ;
}
2015-08-12 05:38:15 +08:00
static bool
IsOperator ( const char * name , clang : : OverloadedOperatorKind & op_kind )
{
if ( name = = nullptr | | name [ 0 ] = = ' \0 ' )
return false ;
# define OPERATOR_PREFIX "operator"
# define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1)
const char * post_op_name = nullptr ;
bool no_space = true ;
if ( : : strncmp ( name , OPERATOR_PREFIX , OPERATOR_PREFIX_LENGTH ) )
return false ;
post_op_name = name + OPERATOR_PREFIX_LENGTH ;
if ( post_op_name [ 0 ] = = ' ' )
{
post_op_name + + ;
no_space = false ;
}
# undef OPERATOR_PREFIX
# undef OPERATOR_PREFIX_LENGTH
// This is an operator, set the overloaded operator kind to invalid
// in case this is a conversion operator...
op_kind = clang : : NUM_OVERLOADED_OPERATORS ;
switch ( post_op_name [ 0 ] )
{
default :
if ( no_space )
return false ;
break ;
case ' n ' :
if ( no_space )
return false ;
if ( strcmp ( post_op_name , " new " ) = = 0 )
op_kind = clang : : OO_New ;
else if ( strcmp ( post_op_name , " new[] " ) = = 0 )
op_kind = clang : : OO_Array_New ;
break ;
case ' d ' :
if ( no_space )
return false ;
if ( strcmp ( post_op_name , " delete " ) = = 0 )
op_kind = clang : : OO_Delete ;
else if ( strcmp ( post_op_name , " delete[] " ) = = 0 )
op_kind = clang : : OO_Array_Delete ;
break ;
case ' + ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Plus ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
if ( post_op_name [ 1 ] = = ' = ' )
op_kind = clang : : OO_PlusEqual ;
else if ( post_op_name [ 1 ] = = ' + ' )
op_kind = clang : : OO_PlusPlus ;
}
break ;
case ' - ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Minus ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
switch ( post_op_name [ 1 ] )
{
case ' = ' : op_kind = clang : : OO_MinusEqual ; break ;
case ' - ' : op_kind = clang : : OO_MinusMinus ; break ;
case ' > ' : op_kind = clang : : OO_Arrow ; break ;
}
}
else if ( post_op_name [ 3 ] = = ' \0 ' )
{
if ( post_op_name [ 2 ] = = ' * ' )
op_kind = clang : : OO_ArrowStar ; break ;
}
break ;
case ' * ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Star ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_StarEqual ;
break ;
case ' / ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Slash ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_SlashEqual ;
break ;
case ' % ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Percent ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_PercentEqual ;
break ;
case ' ^ ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Caret ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_CaretEqual ;
break ;
case ' & ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Amp ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
switch ( post_op_name [ 1 ] )
{
case ' = ' : op_kind = clang : : OO_AmpEqual ; break ;
case ' & ' : op_kind = clang : : OO_AmpAmp ; break ;
}
}
break ;
case ' | ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Pipe ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
switch ( post_op_name [ 1 ] )
{
case ' = ' : op_kind = clang : : OO_PipeEqual ; break ;
case ' | ' : op_kind = clang : : OO_PipePipe ; break ;
}
}
break ;
case ' ~ ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Tilde ;
break ;
case ' ! ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Exclaim ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_ExclaimEqual ;
break ;
case ' = ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Equal ;
else if ( post_op_name [ 1 ] = = ' = ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_EqualEqual ;
break ;
case ' < ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Less ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
switch ( post_op_name [ 1 ] )
{
case ' < ' : op_kind = clang : : OO_LessLess ; break ;
case ' = ' : op_kind = clang : : OO_LessEqual ; break ;
}
}
else if ( post_op_name [ 3 ] = = ' \0 ' )
{
if ( post_op_name [ 2 ] = = ' = ' )
op_kind = clang : : OO_LessLessEqual ;
}
break ;
case ' > ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Greater ;
else if ( post_op_name [ 2 ] = = ' \0 ' )
{
switch ( post_op_name [ 1 ] )
{
case ' > ' : op_kind = clang : : OO_GreaterGreater ; break ;
case ' = ' : op_kind = clang : : OO_GreaterEqual ; break ;
}
}
else if ( post_op_name [ 1 ] = = ' > ' & &
post_op_name [ 2 ] = = ' = ' & &
post_op_name [ 3 ] = = ' \0 ' )
{
op_kind = clang : : OO_GreaterGreaterEqual ;
}
break ;
case ' , ' :
if ( post_op_name [ 1 ] = = ' \0 ' )
op_kind = clang : : OO_Comma ;
break ;
case ' ( ' :
if ( post_op_name [ 1 ] = = ' ) ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_Call ;
break ;
case ' [ ' :
if ( post_op_name [ 1 ] = = ' ] ' & & post_op_name [ 2 ] = = ' \0 ' )
op_kind = clang : : OO_Subscript ;
break ;
}
return true ;
}
clang : : EnumDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : GetAsEnumDecl ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
const clang : : EnumType * enutype = llvm : : dyn_cast < clang : : EnumType > ( GetCanonicalQualType ( type ) ) ;
if ( enutype )
return enutype - > getDecl ( ) ;
return NULL ;
}
clang : : RecordDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : GetAsRecordDecl ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
const clang : : RecordType * record_type = llvm : : dyn_cast < clang : : RecordType > ( GetCanonicalQualType ( type ) ) ;
if ( record_type )
return record_type - > getDecl ( ) ;
return nullptr ;
}
clang : : CXXRecordDecl *
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetAsCXXRecordDecl ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
return GetCanonicalQualType ( type ) - > getAsCXXRecordDecl ( ) ;
}
clang : : ObjCInterfaceDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : GetAsObjCInterfaceDecl ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( GetCanonicalQualType ( type ) ) ;
if ( objc_class_type )
return objc_class_type - > getInterface ( ) ;
return nullptr ;
}
clang : : FieldDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : AddFieldToRecordType ( const CompilerType & type , const char * name ,
const CompilerType & field_clang_type ,
2015-08-12 05:38:15 +08:00
AccessType access ,
uint32_t bitfield_bit_size )
{
if ( ! type . IsValid ( ) | | ! field_clang_type . IsValid ( ) )
return nullptr ;
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast_or_null < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
return nullptr ;
clang : : ASTContext * clang_ast = ast - > getASTContext ( ) ;
clang : : FieldDecl * field = nullptr ;
clang : : Expr * bit_width = nullptr ;
if ( bitfield_bit_size ! = 0 )
{
llvm : : APInt bitfield_bit_size_apint ( clang_ast - > getTypeSize ( clang_ast - > IntTy ) , bitfield_bit_size ) ;
bit_width = new ( * clang_ast ) clang : : IntegerLiteral ( * clang_ast , bitfield_bit_size_apint , clang_ast - > IntTy , clang : : SourceLocation ( ) ) ;
}
clang : : RecordDecl * record_decl = ast - > GetAsRecordDecl ( type ) ;
if ( record_decl )
{
field = clang : : FieldDecl : : Create ( * clang_ast ,
record_decl ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
name ? & clang_ast - > Idents . get ( name ) : nullptr , // Identifier
GetQualType ( field_clang_type ) , // Field type
nullptr , // TInfo *
bit_width , // BitWidth
false , // Mutable
clang : : ICIS_NoInit ) ; // HasInit
if ( ! name )
{
// Determine whether this field corresponds to an anonymous
// struct or union.
if ( const clang : : TagType * TagT = field - > getType ( ) - > getAs < clang : : TagType > ( ) ) {
if ( clang : : RecordDecl * Rec = llvm : : dyn_cast < clang : : RecordDecl > ( TagT - > getDecl ( ) ) )
if ( ! Rec - > getDeclName ( ) ) {
Rec - > setAnonymousStructOrUnion ( true ) ;
field - > setImplicit ( ) ;
}
}
}
if ( field )
{
field - > setAccess ( ClangASTContext : : ConvertAccessTypeToAccessSpecifier ( access ) ) ;
record_decl - > addDecl ( field ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( field ) ;
# endif
}
}
else
{
clang : : ObjCInterfaceDecl * class_interface_decl = ast - > GetAsObjCInterfaceDecl ( type ) ;
if ( class_interface_decl )
{
const bool is_synthesized = false ;
field_clang_type . GetCompleteType ( ) ;
field = clang : : ObjCIvarDecl : : Create ( * clang_ast ,
class_interface_decl ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
name ? & clang_ast - > Idents . get ( name ) : nullptr , // Identifier
GetQualType ( field_clang_type ) , // Field type
nullptr , // TypeSourceInfo *
ConvertAccessTypeToObjCIvarAccessControl ( access ) ,
bit_width ,
is_synthesized ) ;
if ( field )
{
class_interface_decl - > addDecl ( field ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( field ) ;
# endif
}
}
}
return field ;
}
void
2015-08-12 06:53:00 +08:00
ClangASTContext : : BuildIndirectFields ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
2015-09-09 02:15:05 +08:00
if ( ! type )
return ;
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
return ;
clang : : RecordDecl * record_decl = ast - > GetAsRecordDecl ( type ) ;
if ( ! record_decl )
return ;
typedef llvm : : SmallVector < clang : : IndirectFieldDecl * , 1 > IndirectFieldVector ;
IndirectFieldVector indirect_fields ;
clang : : RecordDecl : : field_iterator field_pos ;
clang : : RecordDecl : : field_iterator field_end_pos = record_decl - > field_end ( ) ;
clang : : RecordDecl : : field_iterator last_field_pos = field_end_pos ;
for ( field_pos = record_decl - > field_begin ( ) ; field_pos ! = field_end_pos ; last_field_pos = field_pos + + )
{
if ( field_pos - > isAnonymousStructOrUnion ( ) )
{
clang : : QualType field_qual_type = field_pos - > getType ( ) ;
const clang : : RecordType * field_record_type = field_qual_type - > getAs < clang : : RecordType > ( ) ;
if ( ! field_record_type )
continue ;
clang : : RecordDecl * field_record_decl = field_record_type - > getDecl ( ) ;
if ( ! field_record_decl )
continue ;
for ( clang : : RecordDecl : : decl_iterator di = field_record_decl - > decls_begin ( ) , de = field_record_decl - > decls_end ( ) ;
di ! = de ;
+ + di )
{
if ( clang : : FieldDecl * nested_field_decl = llvm : : dyn_cast < clang : : FieldDecl > ( * di ) )
{
clang : : NamedDecl * * chain = new ( * ast - > getASTContext ( ) ) clang : : NamedDecl * [ 2 ] ;
chain [ 0 ] = * field_pos ;
chain [ 1 ] = nested_field_decl ;
clang : : IndirectFieldDecl * indirect_field = clang : : IndirectFieldDecl : : Create ( * ast - > getASTContext ( ) ,
record_decl ,
clang : : SourceLocation ( ) ,
nested_field_decl - > getIdentifier ( ) ,
nested_field_decl - > getType ( ) ,
chain ,
2 ) ;
indirect_field - > setImplicit ( ) ;
indirect_field - > setAccess ( ClangASTContext : : UnifyAccessSpecifiers ( field_pos - > getAccess ( ) ,
nested_field_decl - > getAccess ( ) ) ) ;
indirect_fields . push_back ( indirect_field ) ;
}
else if ( clang : : IndirectFieldDecl * nested_indirect_field_decl = llvm : : dyn_cast < clang : : IndirectFieldDecl > ( * di ) )
{
int nested_chain_size = nested_indirect_field_decl - > getChainingSize ( ) ;
clang : : NamedDecl * * chain = new ( * ast - > getASTContext ( ) ) clang : : NamedDecl * [ nested_chain_size + 1 ] ;
chain [ 0 ] = * field_pos ;
int chain_index = 1 ;
for ( clang : : IndirectFieldDecl : : chain_iterator nci = nested_indirect_field_decl - > chain_begin ( ) ,
nce = nested_indirect_field_decl - > chain_end ( ) ;
nci < nce ;
+ + nci )
{
chain [ chain_index ] = * nci ;
chain_index + + ;
}
clang : : IndirectFieldDecl * indirect_field = clang : : IndirectFieldDecl : : Create ( * ast - > getASTContext ( ) ,
record_decl ,
clang : : SourceLocation ( ) ,
nested_indirect_field_decl - > getIdentifier ( ) ,
nested_indirect_field_decl - > getType ( ) ,
chain ,
nested_chain_size + 1 ) ;
indirect_field - > setImplicit ( ) ;
indirect_field - > setAccess ( ClangASTContext : : UnifyAccessSpecifiers ( field_pos - > getAccess ( ) ,
nested_indirect_field_decl - > getAccess ( ) ) ) ;
indirect_fields . push_back ( indirect_field ) ;
}
}
}
}
// Check the last field to see if it has an incomplete array type as its
// last member and if it does, the tell the record decl about it
if ( last_field_pos ! = field_end_pos )
{
if ( last_field_pos - > getType ( ) - > isIncompleteArrayType ( ) )
record_decl - > hasFlexibleArrayMember ( ) ;
}
for ( IndirectFieldVector : : iterator ifi = indirect_fields . begin ( ) , ife = indirect_fields . end ( ) ;
ifi < ife ;
+ + ifi )
{
record_decl - > addDecl ( * ifi ) ;
}
}
void
2015-08-12 06:53:00 +08:00
ClangASTContext : : SetIsPacked ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
2015-09-09 02:15:05 +08:00
if ( type )
{
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
if ( ast )
{
clang : : RecordDecl * record_decl = GetAsRecordDecl ( type ) ;
2015-08-12 05:38:15 +08:00
2015-09-09 02:15:05 +08:00
if ( ! record_decl )
return ;
2015-08-12 05:38:15 +08:00
2015-09-09 02:15:05 +08:00
record_decl - > addAttr ( clang : : PackedAttr : : CreateImplicit ( * ast - > getASTContext ( ) ) ) ;
}
}
2015-08-12 05:38:15 +08:00
}
clang : : VarDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : AddVariableToRecordType ( const CompilerType & type , const char * name ,
const CompilerType & var_type ,
2015-08-12 05:38:15 +08:00
AccessType access )
{
clang : : VarDecl * var_decl = nullptr ;
if ( ! type . IsValid ( ) | | ! var_type . IsValid ( ) )
return nullptr ;
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
return nullptr ;
clang : : RecordDecl * record_decl = ast - > GetAsRecordDecl ( type ) ;
if ( record_decl )
{
var_decl = clang : : VarDecl : : Create ( * ast - > getASTContext ( ) , // ASTContext &
record_decl , // DeclContext *
clang : : SourceLocation ( ) , // clang::SourceLocation StartLoc
clang : : SourceLocation ( ) , // clang::SourceLocation IdLoc
name ? & ast - > getASTContext ( ) - > Idents . get ( name ) : nullptr , // clang::IdentifierInfo *
GetQualType ( var_type ) , // Variable clang::QualType
nullptr , // TypeSourceInfo *
clang : : SC_Static ) ; // StorageClass
if ( var_decl )
{
var_decl - > setAccess ( ClangASTContext : : ConvertAccessTypeToAccessSpecifier ( access ) ) ;
record_decl - > addDecl ( var_decl ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( var_decl ) ;
# endif
}
}
return var_decl ;
}
clang : : CXXMethodDecl *
2015-09-23 08:18:24 +08:00
ClangASTContext : : AddMethodToCXXRecordType ( lldb : : opaque_compiler_type_t type , const char * name ,
2015-08-12 06:53:00 +08:00
const CompilerType & method_clang_type ,
2015-08-12 05:38:15 +08:00
lldb : : AccessType access ,
bool is_virtual ,
bool is_static ,
bool is_inline ,
bool is_explicit ,
bool is_attr_used ,
bool is_artificial )
{
if ( ! type | | ! method_clang_type . IsValid ( ) | | name = = nullptr | | name [ 0 ] = = ' \0 ' )
return nullptr ;
clang : : QualType record_qual_type ( GetCanonicalQualType ( type ) ) ;
clang : : CXXRecordDecl * cxx_record_decl = record_qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl = = nullptr )
return nullptr ;
clang : : QualType method_qual_type ( GetQualType ( method_clang_type ) ) ;
clang : : CXXMethodDecl * cxx_method_decl = nullptr ;
clang : : DeclarationName decl_name ( & getASTContext ( ) - > Idents . get ( name ) ) ;
const clang : : FunctionType * function_type = llvm : : dyn_cast < clang : : FunctionType > ( method_qual_type . getTypePtr ( ) ) ;
if ( function_type = = nullptr )
return nullptr ;
const clang : : FunctionProtoType * method_function_prototype ( llvm : : dyn_cast < clang : : FunctionProtoType > ( function_type ) ) ;
if ( ! method_function_prototype )
return nullptr ;
unsigned int num_params = method_function_prototype - > getNumParams ( ) ;
clang : : CXXDestructorDecl * cxx_dtor_decl ( nullptr ) ;
clang : : CXXConstructorDecl * cxx_ctor_decl ( nullptr ) ;
if ( is_artificial )
return nullptr ; // skip everything artificial
if ( name [ 0 ] = = ' ~ ' )
{
cxx_dtor_decl = clang : : CXXDestructorDecl : : Create ( * getASTContext ( ) ,
cxx_record_decl ,
clang : : SourceLocation ( ) ,
clang : : DeclarationNameInfo ( getASTContext ( ) - > DeclarationNames . getCXXDestructorName ( getASTContext ( ) - > getCanonicalType ( record_qual_type ) ) , clang : : SourceLocation ( ) ) ,
method_qual_type ,
nullptr ,
is_inline ,
is_artificial ) ;
cxx_method_decl = cxx_dtor_decl ;
}
else if ( decl_name = = cxx_record_decl - > getDeclName ( ) )
{
cxx_ctor_decl = clang : : CXXConstructorDecl : : Create ( * getASTContext ( ) ,
cxx_record_decl ,
clang : : SourceLocation ( ) ,
clang : : DeclarationNameInfo ( getASTContext ( ) - > DeclarationNames . getCXXConstructorName ( getASTContext ( ) - > getCanonicalType ( record_qual_type ) ) , clang : : SourceLocation ( ) ) ,
method_qual_type ,
nullptr , // TypeSourceInfo *
is_explicit ,
is_inline ,
is_artificial ,
false /*is_constexpr*/ ) ;
cxx_method_decl = cxx_ctor_decl ;
}
else
{
clang : : StorageClass SC = is_static ? clang : : SC_Static : clang : : SC_None ;
clang : : OverloadedOperatorKind op_kind = clang : : NUM_OVERLOADED_OPERATORS ;
if ( IsOperator ( name , op_kind ) )
{
if ( op_kind ! = clang : : NUM_OVERLOADED_OPERATORS )
{
// Check the number of operator parameters. Sometimes we have
// seen bad DWARF that doesn't correctly describe operators and
// if we try to create a method and add it to the class, clang
// will assert and crash, so we need to make sure things are
// acceptable.
if ( ! ClangASTContext : : CheckOverloadedOperatorKindParameterCount ( op_kind , num_params ) )
return nullptr ;
cxx_method_decl = clang : : CXXMethodDecl : : Create ( * getASTContext ( ) ,
cxx_record_decl ,
clang : : SourceLocation ( ) ,
clang : : DeclarationNameInfo ( getASTContext ( ) - > DeclarationNames . getCXXOperatorName ( op_kind ) , clang : : SourceLocation ( ) ) ,
method_qual_type ,
nullptr , // TypeSourceInfo *
SC ,
is_inline ,
false /*is_constexpr*/ ,
clang : : SourceLocation ( ) ) ;
}
else if ( num_params = = 0 )
{
// Conversion operators don't take params...
cxx_method_decl = clang : : CXXConversionDecl : : Create ( * getASTContext ( ) ,
cxx_record_decl ,
clang : : SourceLocation ( ) ,
clang : : DeclarationNameInfo ( getASTContext ( ) - > DeclarationNames . getCXXConversionFunctionName ( getASTContext ( ) - > getCanonicalType ( function_type - > getReturnType ( ) ) ) , clang : : SourceLocation ( ) ) ,
method_qual_type ,
nullptr , // TypeSourceInfo *
is_inline ,
is_explicit ,
false /*is_constexpr*/ ,
clang : : SourceLocation ( ) ) ;
}
}
if ( cxx_method_decl = = nullptr )
{
cxx_method_decl = clang : : CXXMethodDecl : : Create ( * getASTContext ( ) ,
cxx_record_decl ,
clang : : SourceLocation ( ) ,
clang : : DeclarationNameInfo ( decl_name , clang : : SourceLocation ( ) ) ,
method_qual_type ,
nullptr , // TypeSourceInfo *
SC ,
is_inline ,
false /*is_constexpr*/ ,
clang : : SourceLocation ( ) ) ;
}
}
clang : : AccessSpecifier access_specifier = ClangASTContext : : ConvertAccessTypeToAccessSpecifier ( access ) ;
cxx_method_decl - > setAccess ( access_specifier ) ;
cxx_method_decl - > setVirtualAsWritten ( is_virtual ) ;
if ( is_attr_used )
cxx_method_decl - > addAttr ( clang : : UsedAttr : : CreateImplicit ( * getASTContext ( ) ) ) ;
// Populate the method decl with parameter decls
llvm : : SmallVector < clang : : ParmVarDecl * , 12 > params ;
for ( unsigned param_index = 0 ;
param_index < num_params ;
+ + param_index )
{
params . push_back ( clang : : ParmVarDecl : : Create ( * getASTContext ( ) ,
cxx_method_decl ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
nullptr , // anonymous
method_function_prototype - > getParamType ( param_index ) ,
nullptr ,
clang : : SC_None ,
nullptr ) ) ;
}
cxx_method_decl - > setParams ( llvm : : ArrayRef < clang : : ParmVarDecl * > ( params ) ) ;
cxx_record_decl - > addDecl ( cxx_method_decl ) ;
// Sometimes the debug info will mention a constructor (default/copy/move),
// destructor, or assignment operator (copy/move) but there won't be any
// version of this in the code. So we check if the function was artificially
// generated and if it is trivial and this lets the compiler/backend know
// that it can inline the IR for these when it needs to and we can avoid a
// "missing function" error when running expressions.
if ( is_artificial )
{
if ( cxx_ctor_decl & &
( ( cxx_ctor_decl - > isDefaultConstructor ( ) & & cxx_record_decl - > hasTrivialDefaultConstructor ( ) ) | |
( cxx_ctor_decl - > isCopyConstructor ( ) & & cxx_record_decl - > hasTrivialCopyConstructor ( ) ) | |
( cxx_ctor_decl - > isMoveConstructor ( ) & & cxx_record_decl - > hasTrivialMoveConstructor ( ) ) ) )
{
cxx_ctor_decl - > setDefaulted ( ) ;
cxx_ctor_decl - > setTrivial ( true ) ;
}
else if ( cxx_dtor_decl )
{
if ( cxx_record_decl - > hasTrivialDestructor ( ) )
{
cxx_dtor_decl - > setDefaulted ( ) ;
cxx_dtor_decl - > setTrivial ( true ) ;
}
}
else if ( ( cxx_method_decl - > isCopyAssignmentOperator ( ) & & cxx_record_decl - > hasTrivialCopyAssignment ( ) ) | |
( cxx_method_decl - > isMoveAssignmentOperator ( ) & & cxx_record_decl - > hasTrivialMoveAssignment ( ) ) )
{
cxx_method_decl - > setDefaulted ( ) ;
cxx_method_decl - > setTrivial ( true ) ;
}
}
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( cxx_method_decl ) ;
# endif
// printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic());
// printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate());
// printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD());
// printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty());
// printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract());
// printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor());
// printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor());
// printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment());
// printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor());
return cxx_method_decl ;
}
# pragma mark C++ Base Classes
clang : : CXXBaseSpecifier *
2015-09-23 08:18:24 +08:00
ClangASTContext : : CreateBaseClassSpecifier ( lldb : : opaque_compiler_type_t type , AccessType access , bool is_virtual , bool base_of_class )
2015-08-12 05:38:15 +08:00
{
if ( type )
return new clang : : CXXBaseSpecifier ( clang : : SourceRange ( ) ,
is_virtual ,
base_of_class ,
ClangASTContext : : ConvertAccessTypeToAccessSpecifier ( access ) ,
getASTContext ( ) - > getTrivialTypeSourceInfo ( GetQualType ( type ) ) ,
clang : : SourceLocation ( ) ) ;
return nullptr ;
}
void
ClangASTContext : : DeleteBaseClassSpecifiers ( clang : : CXXBaseSpecifier * * base_classes , unsigned num_base_classes )
{
for ( unsigned i = 0 ; i < num_base_classes ; + + i )
{
delete base_classes [ i ] ;
base_classes [ i ] = nullptr ;
}
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : SetBaseClassesForClassType ( lldb : : opaque_compiler_type_t type , clang : : CXXBaseSpecifier const * const * base_classes ,
2015-08-12 05:38:15 +08:00
unsigned num_base_classes )
{
if ( type )
{
clang : : CXXRecordDecl * cxx_record_decl = GetAsCXXRecordDecl ( type ) ;
if ( cxx_record_decl )
{
cxx_record_decl - > setBases ( base_classes , num_base_classes ) ;
return true ;
}
}
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : SetObjCSuperClass ( const CompilerType & type , const CompilerType & superclass_clang_type )
2015-08-12 05:38:15 +08:00
{
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast_or_null < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
return false ;
clang : : ASTContext * clang_ast = ast - > getASTContext ( ) ;
if ( type & & superclass_clang_type . IsValid ( ) & & superclass_clang_type . GetTypeSystem ( ) = = type . GetTypeSystem ( ) )
{
clang : : ObjCInterfaceDecl * class_interface_decl = GetAsObjCInterfaceDecl ( type ) ;
clang : : ObjCInterfaceDecl * super_interface_decl = GetAsObjCInterfaceDecl ( superclass_clang_type ) ;
if ( class_interface_decl & & super_interface_decl )
{
class_interface_decl - > setSuperClass ( clang_ast - > getTrivialTypeSourceInfo ( clang_ast - > getObjCInterfaceType ( super_interface_decl ) ) ) ;
return true ;
}
}
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : AddObjCClassProperty ( const CompilerType & type ,
2015-08-12 05:38:15 +08:00
const char * property_name ,
2015-08-12 06:53:00 +08:00
const CompilerType & property_clang_type ,
2015-08-12 05:38:15 +08:00
clang : : ObjCIvarDecl * ivar_decl ,
const char * property_setter_name ,
const char * property_getter_name ,
uint32_t property_attributes ,
ClangASTMetadata * metadata )
{
if ( ! type | | ! property_clang_type . IsValid ( ) | | property_name = = nullptr | | property_name [ 0 ] = = ' \0 ' )
return false ;
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
return false ;
clang : : ASTContext * clang_ast = ast - > getASTContext ( ) ;
clang : : ObjCInterfaceDecl * class_interface_decl = GetAsObjCInterfaceDecl ( type ) ;
if ( class_interface_decl )
{
2015-08-12 06:53:00 +08:00
CompilerType property_clang_type_to_access ;
2015-08-12 05:38:15 +08:00
if ( property_clang_type . IsValid ( ) )
property_clang_type_to_access = property_clang_type ;
else if ( ivar_decl )
2015-08-12 06:53:00 +08:00
property_clang_type_to_access = CompilerType ( clang_ast , ivar_decl - > getType ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( class_interface_decl & & property_clang_type_to_access . IsValid ( ) )
{
clang : : TypeSourceInfo * prop_type_source ;
if ( ivar_decl )
prop_type_source = clang_ast - > getTrivialTypeSourceInfo ( ivar_decl - > getType ( ) ) ;
else
prop_type_source = clang_ast - > getTrivialTypeSourceInfo ( GetQualType ( property_clang_type ) ) ;
clang : : ObjCPropertyDecl * property_decl = clang : : ObjCPropertyDecl : : Create ( * clang_ast ,
class_interface_decl ,
clang : : SourceLocation ( ) , // Source Location
& clang_ast - > Idents . get ( property_name ) ,
clang : : SourceLocation ( ) , //Source Location for AT
clang : : SourceLocation ( ) , //Source location for (
ivar_decl ? ivar_decl - > getType ( ) : ClangASTContext : : GetQualType ( property_clang_type ) ,
prop_type_source ) ;
if ( property_decl )
{
if ( metadata )
ClangASTContext : : SetMetadata ( clang_ast , property_decl , * metadata ) ;
class_interface_decl - > addDecl ( property_decl ) ;
clang : : Selector setter_sel , getter_sel ;
if ( property_setter_name ! = nullptr )
{
std : : string property_setter_no_colon ( property_setter_name , strlen ( property_setter_name ) - 1 ) ;
clang : : IdentifierInfo * setter_ident = & clang_ast - > Idents . get ( property_setter_no_colon . c_str ( ) ) ;
setter_sel = clang_ast - > Selectors . getSelector ( 1 , & setter_ident ) ;
}
else if ( ! ( property_attributes & DW_APPLE_PROPERTY_readonly ) )
{
std : : string setter_sel_string ( " set " ) ;
setter_sel_string . push_back ( : : toupper ( property_name [ 0 ] ) ) ;
setter_sel_string . append ( & property_name [ 1 ] ) ;
clang : : IdentifierInfo * setter_ident = & clang_ast - > Idents . get ( setter_sel_string . c_str ( ) ) ;
setter_sel = clang_ast - > Selectors . getSelector ( 1 , & setter_ident ) ;
}
property_decl - > setSetterName ( setter_sel ) ;
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_setter ) ;
if ( property_getter_name ! = nullptr )
{
clang : : IdentifierInfo * getter_ident = & clang_ast - > Idents . get ( property_getter_name ) ;
getter_sel = clang_ast - > Selectors . getSelector ( 0 , & getter_ident ) ;
}
else
{
clang : : IdentifierInfo * getter_ident = & clang_ast - > Idents . get ( property_name ) ;
getter_sel = clang_ast - > Selectors . getSelector ( 0 , & getter_ident ) ;
}
property_decl - > setGetterName ( getter_sel ) ;
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_getter ) ;
if ( ivar_decl )
property_decl - > setPropertyIvarDecl ( ivar_decl ) ;
if ( property_attributes & DW_APPLE_PROPERTY_readonly )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_readonly ) ;
if ( property_attributes & DW_APPLE_PROPERTY_readwrite )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_readwrite ) ;
if ( property_attributes & DW_APPLE_PROPERTY_assign )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_assign ) ;
if ( property_attributes & DW_APPLE_PROPERTY_retain )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_retain ) ;
if ( property_attributes & DW_APPLE_PROPERTY_copy )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_copy ) ;
if ( property_attributes & DW_APPLE_PROPERTY_nonatomic )
property_decl - > setPropertyAttributes ( clang : : ObjCPropertyDecl : : OBJC_PR_nonatomic ) ;
if ( ! getter_sel . isNull ( ) & & ! class_interface_decl - > lookupInstanceMethod ( getter_sel ) )
{
const bool isInstance = true ;
const bool isVariadic = false ;
const bool isSynthesized = false ;
const bool isImplicitlyDeclared = true ;
const bool isDefined = false ;
const clang : : ObjCMethodDecl : : ImplementationControl impControl = clang : : ObjCMethodDecl : : None ;
const bool HasRelatedResultType = false ;
clang : : ObjCMethodDecl * getter = clang : : ObjCMethodDecl : : Create ( * clang_ast ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
getter_sel ,
GetQualType ( property_clang_type_to_access ) ,
nullptr ,
class_interface_decl ,
isInstance ,
isVariadic ,
isSynthesized ,
isImplicitlyDeclared ,
isDefined ,
impControl ,
HasRelatedResultType ) ;
if ( getter & & metadata )
ClangASTContext : : SetMetadata ( clang_ast , getter , * metadata ) ;
if ( getter )
{
getter - > setMethodParams ( * clang_ast , llvm : : ArrayRef < clang : : ParmVarDecl * > ( ) , llvm : : ArrayRef < clang : : SourceLocation > ( ) ) ;
class_interface_decl - > addDecl ( getter ) ;
}
}
if ( ! setter_sel . isNull ( ) & & ! class_interface_decl - > lookupInstanceMethod ( setter_sel ) )
{
clang : : QualType result_type = clang_ast - > VoidTy ;
const bool isInstance = true ;
const bool isVariadic = false ;
const bool isSynthesized = false ;
const bool isImplicitlyDeclared = true ;
const bool isDefined = false ;
const clang : : ObjCMethodDecl : : ImplementationControl impControl = clang : : ObjCMethodDecl : : None ;
const bool HasRelatedResultType = false ;
clang : : ObjCMethodDecl * setter = clang : : ObjCMethodDecl : : Create ( * clang_ast ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
setter_sel ,
result_type ,
nullptr ,
class_interface_decl ,
isInstance ,
isVariadic ,
isSynthesized ,
isImplicitlyDeclared ,
isDefined ,
impControl ,
HasRelatedResultType ) ;
if ( setter & & metadata )
ClangASTContext : : SetMetadata ( clang_ast , setter , * metadata ) ;
llvm : : SmallVector < clang : : ParmVarDecl * , 1 > params ;
params . push_back ( clang : : ParmVarDecl : : Create ( * clang_ast ,
setter ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
nullptr , // anonymous
GetQualType ( property_clang_type_to_access ) ,
nullptr ,
clang : : SC_Auto ,
nullptr ) ) ;
if ( setter )
{
setter - > setMethodParams ( * clang_ast , llvm : : ArrayRef < clang : : ParmVarDecl * > ( params ) , llvm : : ArrayRef < clang : : SourceLocation > ( ) ) ;
class_interface_decl - > addDecl ( setter ) ;
}
}
return true ;
}
}
}
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : IsObjCClassTypeAndHasIVars ( const CompilerType & type , bool check_superclass )
2015-08-12 05:38:15 +08:00
{
clang : : ObjCInterfaceDecl * class_interface_decl = GetAsObjCInterfaceDecl ( type ) ;
if ( class_interface_decl )
return ObjCDeclHasIVars ( class_interface_decl , check_superclass ) ;
return false ;
}
clang : : ObjCMethodDecl *
2015-08-12 06:53:00 +08:00
ClangASTContext : : AddMethodToObjCObjectType ( const CompilerType & type ,
2015-09-23 08:18:24 +08:00
const char * name , // the full symbol name as seen in the symbol table (lldb::opaque_compiler_type_t type, "-[NString stringWithCString:]")
2015-08-12 06:53:00 +08:00
const CompilerType & method_clang_type ,
2015-08-12 05:38:15 +08:00
lldb : : AccessType access ,
bool is_artificial )
{
if ( ! type | | ! method_clang_type . IsValid ( ) )
return nullptr ;
clang : : ObjCInterfaceDecl * class_interface_decl = GetAsObjCInterfaceDecl ( type ) ;
if ( class_interface_decl = = nullptr )
return nullptr ;
2015-09-09 02:15:05 +08:00
ClangASTContext * lldb_ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
if ( lldb_ast = = nullptr )
return nullptr ;
clang : : ASTContext * ast = lldb_ast - > getASTContext ( ) ;
2015-08-12 05:38:15 +08:00
const char * selector_start = : : strchr ( name , ' ' ) ;
if ( selector_start = = nullptr )
return nullptr ;
selector_start + + ;
llvm : : SmallVector < clang : : IdentifierInfo * , 12 > selector_idents ;
size_t len = 0 ;
const char * start ;
//printf ("name = '%s'\n", name);
unsigned num_selectors_with_args = 0 ;
for ( start = selector_start ;
start & & * start ! = ' \0 ' & & * start ! = ' ] ' ;
start + = len )
{
len = : : strcspn ( start , " :] " ) ;
bool has_arg = ( start [ len ] = = ' : ' ) ;
if ( has_arg )
+ + num_selectors_with_args ;
selector_idents . push_back ( & ast - > Idents . get ( llvm : : StringRef ( start , len ) ) ) ;
if ( has_arg )
len + = 1 ;
}
if ( selector_idents . size ( ) = = 0 )
return nullptr ;
clang : : Selector method_selector = ast - > Selectors . getSelector ( num_selectors_with_args ? selector_idents . size ( ) : 0 ,
selector_idents . data ( ) ) ;
clang : : QualType method_qual_type ( GetQualType ( method_clang_type ) ) ;
// Populate the method decl with parameter decls
const clang : : Type * method_type ( method_qual_type . getTypePtr ( ) ) ;
if ( method_type = = nullptr )
return nullptr ;
const clang : : FunctionProtoType * method_function_prototype ( llvm : : dyn_cast < clang : : FunctionProtoType > ( method_type ) ) ;
if ( ! method_function_prototype )
return nullptr ;
bool is_variadic = false ;
bool is_synthesized = false ;
bool is_defined = false ;
clang : : ObjCMethodDecl : : ImplementationControl imp_control = clang : : ObjCMethodDecl : : None ;
const unsigned num_args = method_function_prototype - > getNumParams ( ) ;
if ( num_args ! = num_selectors_with_args )
return nullptr ; // some debug information is corrupt. We are not going to deal with it.
clang : : ObjCMethodDecl * objc_method_decl = clang : : ObjCMethodDecl : : Create ( * ast ,
clang : : SourceLocation ( ) , // beginLoc,
clang : : SourceLocation ( ) , // endLoc,
method_selector ,
method_function_prototype - > getReturnType ( ) ,
nullptr , // TypeSourceInfo *ResultTInfo,
ClangASTContext : : GetASTContext ( ast ) - > GetDeclContextForType ( GetQualType ( type ) ) ,
name [ 0 ] = = ' - ' ,
is_variadic ,
is_synthesized ,
true , // is_implicitly_declared; we force this to true because we don't have source locations
is_defined ,
imp_control ,
false /*has_related_result_type*/ ) ;
if ( objc_method_decl = = nullptr )
return nullptr ;
if ( num_args > 0 )
{
llvm : : SmallVector < clang : : ParmVarDecl * , 12 > params ;
for ( unsigned param_index = 0 ; param_index < num_args ; + + param_index )
{
params . push_back ( clang : : ParmVarDecl : : Create ( * ast ,
objc_method_decl ,
clang : : SourceLocation ( ) ,
clang : : SourceLocation ( ) ,
nullptr , // anonymous
method_function_prototype - > getParamType ( param_index ) ,
nullptr ,
clang : : SC_Auto ,
nullptr ) ) ;
}
objc_method_decl - > setMethodParams ( * ast , llvm : : ArrayRef < clang : : ParmVarDecl * > ( params ) , llvm : : ArrayRef < clang : : SourceLocation > ( ) ) ;
}
class_interface_decl - > addDecl ( objc_method_decl ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( objc_method_decl ) ;
# endif
return objc_method_decl ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : SetHasExternalStorage ( lldb : : opaque_compiler_type_t type , bool has_extern )
2015-08-12 05:38:15 +08:00
{
if ( ! type )
return false ;
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Record :
{
clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
cxx_record_decl - > setHasExternalLexicalStorage ( has_extern ) ;
cxx_record_decl - > setHasExternalVisibleStorage ( has_extern ) ;
return true ;
}
}
break ;
case clang : : Type : : Enum :
{
clang : : EnumDecl * enum_decl = llvm : : cast < clang : : EnumType > ( qual_type ) - > getDecl ( ) ;
if ( enum_decl )
{
enum_decl - > setHasExternalLexicalStorage ( has_extern ) ;
enum_decl - > setHasExternalVisibleStorage ( has_extern ) ;
return true ;
}
}
break ;
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
{
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
class_interface_decl - > setHasExternalLexicalStorage ( has_extern ) ;
class_interface_decl - > setHasExternalVisibleStorage ( has_extern ) ;
return true ;
}
}
}
break ;
case clang : : Type : : Typedef :
return SetHasExternalStorage ( llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) . getAsOpaquePtr ( ) , has_extern ) ;
case clang : : Type : : Elaborated :
return SetHasExternalStorage ( llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) . getAsOpaquePtr ( ) , has_extern ) ;
case clang : : Type : : Paren :
return SetHasExternalStorage ( llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) . getAsOpaquePtr ( ) , has_extern ) ;
default :
break ;
}
return false ;
}
# pragma mark TagDecl
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : StartTagDeclarationDefinition ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type * t = qual_type . getTypePtr ( ) ;
if ( t )
{
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( t ) ;
if ( tag_type )
{
clang : : TagDecl * tag_decl = tag_type - > getDecl ( ) ;
if ( tag_decl )
{
tag_decl - > startDefinition ( ) ;
return true ;
}
}
const clang : : ObjCObjectType * object_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( t ) ;
if ( object_type )
{
clang : : ObjCInterfaceDecl * interface_decl = object_type - > getInterface ( ) ;
if ( interface_decl )
{
interface_decl - > startDefinition ( ) ;
return true ;
}
}
}
}
return false ;
}
bool
2015-08-12 06:53:00 +08:00
ClangASTContext : : CompleteTagDeclarationDefinition ( const CompilerType & type )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
if ( qual_type . isNull ( ) )
return false ;
2015-09-09 02:15:05 +08:00
ClangASTContext * lldb_ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
if ( lldb_ast = = nullptr )
return false ;
clang : : ASTContext * ast = lldb_ast - > getASTContext ( ) ;
2015-08-12 05:38:15 +08:00
clang : : CXXRecordDecl * cxx_record_decl = qual_type - > getAsCXXRecordDecl ( ) ;
if ( cxx_record_decl )
{
cxx_record_decl - > completeDefinition ( ) ;
return true ;
}
const clang : : EnumType * enutype = llvm : : dyn_cast < clang : : EnumType > ( qual_type . getTypePtr ( ) ) ;
if ( enutype )
{
clang : : EnumDecl * enum_decl = enutype - > getDecl ( ) ;
if ( enum_decl )
{
/// TODO This really needs to be fixed.
unsigned NumPositiveBits = 1 ;
unsigned NumNegativeBits = 0 ;
clang : : QualType promotion_qual_type ;
// If the enum integer type is less than an integer in bit width,
// then we must promote it to an integer size.
if ( ast - > getTypeSize ( enum_decl - > getIntegerType ( ) ) < ast - > getTypeSize ( ast - > IntTy ) )
{
if ( enum_decl - > getIntegerType ( ) - > isSignedIntegerType ( ) )
promotion_qual_type = ast - > IntTy ;
else
promotion_qual_type = ast - > UnsignedIntTy ;
}
else
promotion_qual_type = enum_decl - > getIntegerType ( ) ;
enum_decl - > completeDefinition ( enum_decl - > getIntegerType ( ) , promotion_qual_type , NumPositiveBits , NumNegativeBits ) ;
return true ;
}
}
}
return false ;
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : AddEnumerationValueToEnumerationType ( lldb : : opaque_compiler_type_t type ,
2015-08-15 04:02:05 +08:00
const CompilerType & enumerator_clang_type ,
const Declaration & decl ,
const char * name ,
int64_t enum_value ,
uint32_t enum_value_bit_size )
2015-08-12 05:38:15 +08:00
{
if ( type & & enumerator_clang_type . IsValid ( ) & & name & & name [ 0 ] )
{
clang : : QualType enum_qual_type ( GetCanonicalQualType ( type ) ) ;
bool is_signed = false ;
enumerator_clang_type . IsIntegerType ( is_signed ) ;
const clang : : Type * clang_type = enum_qual_type . getTypePtr ( ) ;
if ( clang_type )
{
const clang : : EnumType * enutype = llvm : : dyn_cast < clang : : EnumType > ( clang_type ) ;
if ( enutype )
{
llvm : : APSInt enum_llvm_apsint ( enum_value_bit_size , is_signed ) ;
enum_llvm_apsint = enum_value ;
clang : : EnumConstantDecl * enumerator_decl =
clang : : EnumConstantDecl : : Create ( * getASTContext ( ) ,
enutype - > getDecl ( ) ,
clang : : SourceLocation ( ) ,
name ? & getASTContext ( ) - > Idents . get ( name ) : nullptr , // Identifier
GetQualType ( enumerator_clang_type ) ,
nullptr ,
enum_llvm_apsint ) ;
if ( enumerator_decl )
{
enutype - > getDecl ( ) - > addDecl ( enumerator_decl ) ;
# ifdef LLDB_CONFIGURATION_DEBUG
VerifyDecl ( enumerator_decl ) ;
# endif
return true ;
}
}
}
}
return false ;
}
2015-08-12 06:53:00 +08:00
CompilerType
2015-09-23 08:18:24 +08:00
ClangASTContext : : GetEnumerationIntegerType ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
clang : : QualType enum_qual_type ( GetCanonicalQualType ( type ) ) ;
const clang : : Type * clang_type = enum_qual_type . getTypePtr ( ) ;
if ( clang_type )
{
const clang : : EnumType * enutype = llvm : : dyn_cast < clang : : EnumType > ( clang_type ) ;
if ( enutype )
{
clang : : EnumDecl * enum_decl = enutype - > getDecl ( ) ;
if ( enum_decl )
2015-08-12 06:53:00 +08:00
return CompilerType ( getASTContext ( ) , enum_decl - > getIntegerType ( ) ) ;
2015-08-12 05:38:15 +08:00
}
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
2015-08-12 06:53:00 +08:00
CompilerType
ClangASTContext : : CreateMemberPointerType ( const CompilerType & type , const CompilerType & pointee_type )
2015-08-12 05:38:15 +08:00
{
if ( type & & pointee_type . IsValid ( ) & & type . GetTypeSystem ( ) = = pointee_type . GetTypeSystem ( ) )
{
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast < ClangASTContext > ( type . GetTypeSystem ( ) ) ;
2015-08-12 05:38:15 +08:00
if ( ! ast )
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
return CompilerType ( ast - > getASTContext ( ) ,
2015-08-12 05:38:15 +08:00
ast - > getASTContext ( ) - > getMemberPointerType ( GetQualType ( pointee_type ) ,
GetQualType ( type ) . getTypePtr ( ) ) ) ;
}
2015-08-12 06:53:00 +08:00
return CompilerType ( ) ;
2015-08-12 05:38:15 +08:00
}
size_t
2015-09-23 08:18:24 +08:00
ClangASTContext : : ConvertStringToFloatValue ( lldb : : opaque_compiler_type_t type , const char * s , uint8_t * dst , size_t dst_size )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetCanonicalQualType ( type ) ) ;
uint32_t count = 0 ;
bool is_complex = false ;
if ( IsFloatingPointType ( type , count , is_complex ) )
{
// TODO: handle complex and vector types
if ( count ! = 1 )
return false ;
llvm : : StringRef s_sref ( s ) ;
llvm : : APFloat ap_float ( getASTContext ( ) - > getFloatTypeSemantics ( qual_type ) , s_sref ) ;
const uint64_t bit_size = getASTContext ( ) - > getTypeSize ( qual_type ) ;
const uint64_t byte_size = bit_size / 8 ;
if ( dst_size > = byte_size )
{
if ( bit_size = = sizeof ( float ) * 8 )
{
float float32 = ap_float . convertToFloat ( ) ;
: : memcpy ( dst , & float32 , byte_size ) ;
return byte_size ;
}
else if ( bit_size > = 64 )
{
llvm : : APInt ap_int ( ap_float . bitcastToAPInt ( ) ) ;
: : memcpy ( dst , ap_int . getRawData ( ) , byte_size ) ;
return byte_size ;
}
}
}
}
return 0 ;
}
//----------------------------------------------------------------------
// Dumping types
//----------------------------------------------------------------------
# define DEPTH_INCREMENT 2
void
2015-09-23 08:18:24 +08:00
ClangASTContext : : DumpValue ( lldb : : opaque_compiler_type_t type , ExecutionContext * exe_ctx ,
2015-08-12 05:38:15 +08:00
Stream * s ,
lldb : : Format format ,
const lldb_private : : DataExtractor & data ,
lldb : : offset_t data_byte_offset ,
size_t data_byte_size ,
uint32_t bitfield_bit_size ,
uint32_t bitfield_bit_offset ,
bool show_types ,
bool show_summary ,
bool verbose ,
uint32_t depth )
{
if ( ! type )
return ;
clang : : QualType qual_type ( GetQualType ( type ) ) ;
switch ( qual_type - > getTypeClass ( ) )
{
case clang : : Type : : Record :
if ( GetCompleteType ( type ) )
{
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
assert ( record_decl ) ;
uint32_t field_bit_offset = 0 ;
uint32_t field_byte_offset = 0 ;
const clang : : ASTRecordLayout & record_layout = getASTContext ( ) - > getASTRecordLayout ( record_decl ) ;
uint32_t child_idx = 0 ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
{
// We might have base classes to print out first
clang : : CXXRecordDecl : : base_class_const_iterator base_class , base_class_end ;
for ( base_class = cxx_record_decl - > bases_begin ( ) , base_class_end = cxx_record_decl - > bases_end ( ) ;
base_class ! = base_class_end ;
+ + base_class )
{
const clang : : CXXRecordDecl * base_class_decl = llvm : : cast < clang : : CXXRecordDecl > ( base_class - > getType ( ) - > getAs < clang : : RecordType > ( ) - > getDecl ( ) ) ;
// Skip empty base classes
if ( verbose = = false & & ClangASTContext : : RecordHasFields ( base_class_decl ) = = false )
continue ;
if ( base_class - > isVirtual ( ) )
field_bit_offset = record_layout . getVBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
else
field_bit_offset = record_layout . getBaseClassOffset ( base_class_decl ) . getQuantity ( ) * 8 ;
field_byte_offset = field_bit_offset / 8 ;
assert ( field_bit_offset % 8 = = 0 ) ;
if ( child_idx = = 0 )
s - > PutChar ( ' { ' ) ;
else
s - > PutChar ( ' , ' ) ;
clang : : QualType base_class_qual_type = base_class - > getType ( ) ;
std : : string base_class_type_name ( base_class_qual_type . getAsString ( ) ) ;
// Indent and print the base class type name
s - > Printf ( " \n %*s%s " , depth + DEPTH_INCREMENT , " " , base_class_type_name . c_str ( ) ) ;
clang : : TypeInfo base_class_type_info = getASTContext ( ) - > getTypeInfo ( base_class_qual_type ) ;
// Dump the value of the member
2015-08-12 06:53:00 +08:00
CompilerType base_clang_type ( getASTContext ( ) , base_class_qual_type ) ;
2015-08-12 05:38:15 +08:00
base_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
base_clang_type . GetFormat ( ) , // The format with which to display the member
data , // Data buffer containing all bytes for this type
data_byte_offset + field_byte_offset , // Offset into "data" where to grab value from
base_class_type_info . Width / 8 , // Size of this type in bytes
0 , // Bitfield bit size
0 , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth + DEPTH_INCREMENT ) ; // Scope depth for any types that have children
+ + child_idx ;
}
}
uint32_t field_idx = 0 ;
clang : : RecordDecl : : field_iterator field , field_end ;
for ( field = record_decl - > field_begin ( ) , field_end = record_decl - > field_end ( ) ; field ! = field_end ; + + field , + + field_idx , + + child_idx )
{
// Print the starting squiggly bracket (if this is the
// first member) or comma (for member 2 and beyond) for
// the struct/union/class member.
if ( child_idx = = 0 )
s - > PutChar ( ' { ' ) ;
else
s - > PutChar ( ' , ' ) ;
// Indent
s - > Printf ( " \n %*s " , depth + DEPTH_INCREMENT , " " ) ;
clang : : QualType field_type = field - > getType ( ) ;
// Print the member type if requested
// Figure out the type byte size (field_type_info.first) and
// alignment (field_type_info.second) from the AST context.
clang : : TypeInfo field_type_info = getASTContext ( ) - > getTypeInfo ( field_type ) ;
assert ( field_idx < record_layout . getFieldCount ( ) ) ;
// Figure out the field offset within the current struct/union/class type
field_bit_offset = record_layout . getFieldOffset ( field_idx ) ;
field_byte_offset = field_bit_offset / 8 ;
uint32_t field_bitfield_bit_size = 0 ;
uint32_t field_bitfield_bit_offset = 0 ;
if ( ClangASTContext : : FieldIsBitfield ( getASTContext ( ) , * field , field_bitfield_bit_size ) )
field_bitfield_bit_offset = field_bit_offset % 8 ;
if ( show_types )
{
std : : string field_type_name ( field_type . getAsString ( ) ) ;
if ( field_bitfield_bit_size > 0 )
s - > Printf ( " (%s:%u) " , field_type_name . c_str ( ) , field_bitfield_bit_size ) ;
else
s - > Printf ( " (%s) " , field_type_name . c_str ( ) ) ;
}
// Print the member name and equal sign
s - > Printf ( " %s = " , field - > getNameAsString ( ) . c_str ( ) ) ;
// Dump the value of the member
2015-08-12 06:53:00 +08:00
CompilerType field_clang_type ( getASTContext ( ) , field_type ) ;
2015-08-12 05:38:15 +08:00
field_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
field_clang_type . GetFormat ( ) , // The format with which to display the member
data , // Data buffer containing all bytes for this type
data_byte_offset + field_byte_offset , // Offset into "data" where to grab value from
field_type_info . Width / 8 , // Size of this type in bytes
field_bitfield_bit_size , // Bitfield bit size
field_bitfield_bit_offset , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth + DEPTH_INCREMENT ) ; // Scope depth for any types that have children
}
// Indent the trailing squiggly bracket
if ( child_idx > 0 )
s - > Printf ( " \n %*s} " , depth , " " ) ;
}
return ;
case clang : : Type : : Enum :
if ( GetCompleteType ( type ) )
{
const clang : : EnumType * enutype = llvm : : cast < clang : : EnumType > ( qual_type . getTypePtr ( ) ) ;
const clang : : EnumDecl * enum_decl = enutype - > getDecl ( ) ;
assert ( enum_decl ) ;
clang : : EnumDecl : : enumerator_iterator enum_pos , enum_end_pos ;
lldb : : offset_t offset = data_byte_offset ;
const int64_t enum_value = data . GetMaxU64Bitfield ( & offset , data_byte_size , bitfield_bit_size , bitfield_bit_offset ) ;
for ( enum_pos = enum_decl - > enumerator_begin ( ) , enum_end_pos = enum_decl - > enumerator_end ( ) ; enum_pos ! = enum_end_pos ; + + enum_pos )
{
if ( enum_pos - > getInitVal ( ) = = enum_value )
{
s - > Printf ( " %s " , enum_pos - > getNameAsString ( ) . c_str ( ) ) ;
return ;
}
}
// If we have gotten here we didn't get find the enumerator in the
// enum decl, so just print the integer.
s - > Printf ( " % " PRIi64 , enum_value ) ;
}
return ;
case clang : : Type : : ConstantArray :
{
const clang : : ConstantArrayType * array = llvm : : cast < clang : : ConstantArrayType > ( qual_type . getTypePtr ( ) ) ;
bool is_array_of_characters = false ;
clang : : QualType element_qual_type = array - > getElementType ( ) ;
const clang : : Type * canonical_type = element_qual_type - > getCanonicalTypeInternal ( ) . getTypePtr ( ) ;
if ( canonical_type )
is_array_of_characters = canonical_type - > isCharType ( ) ;
const uint64_t element_count = array - > getSize ( ) . getLimitedValue ( ) ;
clang : : TypeInfo field_type_info = getASTContext ( ) - > getTypeInfo ( element_qual_type ) ;
uint32_t element_idx = 0 ;
uint32_t element_offset = 0 ;
uint64_t element_byte_size = field_type_info . Width / 8 ;
uint32_t element_stride = element_byte_size ;
if ( is_array_of_characters )
{
s - > PutChar ( ' " ' ) ;
data . Dump ( s , data_byte_offset , lldb : : eFormatChar , element_byte_size , element_count , UINT32_MAX , LLDB_INVALID_ADDRESS , 0 , 0 ) ;
s - > PutChar ( ' " ' ) ;
return ;
}
else
{
2015-08-12 06:53:00 +08:00
CompilerType element_clang_type ( getASTContext ( ) , element_qual_type ) ;
2015-08-12 05:38:15 +08:00
lldb : : Format element_format = element_clang_type . GetFormat ( ) ;
for ( element_idx = 0 ; element_idx < element_count ; + + element_idx )
{
// Print the starting squiggly bracket (if this is the
// first member) or comman (for member 2 and beyong) for
// the struct/union/class member.
if ( element_idx = = 0 )
s - > PutChar ( ' { ' ) ;
else
s - > PutChar ( ' , ' ) ;
// Indent and print the index
s - > Printf ( " \n %*s[%u] " , depth + DEPTH_INCREMENT , " " , element_idx ) ;
// Figure out the field offset within the current struct/union/class type
element_offset = element_idx * element_stride ;
// Dump the value of the member
element_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
element_format , // The format with which to display the element
data , // Data buffer containing all bytes for this type
data_byte_offset + element_offset , // Offset into "data" where to grab value from
element_byte_size , // Size of this type in bytes
0 , // Bitfield bit size
0 , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth + DEPTH_INCREMENT ) ; // Scope depth for any types that have children
}
// Indent the trailing squiggly bracket
if ( element_idx > 0 )
s - > Printf ( " \n %*s} " , depth , " " ) ;
}
}
return ;
case clang : : Type : : Typedef :
{
clang : : QualType typedef_qual_type = llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ;
2015-08-12 06:53:00 +08:00
CompilerType typedef_clang_type ( getASTContext ( ) , typedef_qual_type ) ;
2015-08-12 05:38:15 +08:00
lldb : : Format typedef_format = typedef_clang_type . GetFormat ( ) ;
clang : : TypeInfo typedef_type_info = getASTContext ( ) - > getTypeInfo ( typedef_qual_type ) ;
uint64_t typedef_byte_size = typedef_type_info . Width / 8 ;
return typedef_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
typedef_format , // The format with which to display the element
data , // Data buffer containing all bytes for this type
data_byte_offset , // Offset into "data" where to grab value from
typedef_byte_size , // Size of this type in bytes
bitfield_bit_size , // Bitfield bit size
bitfield_bit_offset , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth ) ; // Scope depth for any types that have children
}
break ;
case clang : : Type : : Elaborated :
{
clang : : QualType elaborated_qual_type = llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ;
2015-08-12 06:53:00 +08:00
CompilerType elaborated_clang_type ( getASTContext ( ) , elaborated_qual_type ) ;
2015-08-12 05:38:15 +08:00
lldb : : Format elaborated_format = elaborated_clang_type . GetFormat ( ) ;
clang : : TypeInfo elaborated_type_info = getASTContext ( ) - > getTypeInfo ( elaborated_qual_type ) ;
uint64_t elaborated_byte_size = elaborated_type_info . Width / 8 ;
return elaborated_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
elaborated_format , // The format with which to display the element
data , // Data buffer containing all bytes for this type
data_byte_offset , // Offset into "data" where to grab value from
elaborated_byte_size , // Size of this type in bytes
bitfield_bit_size , // Bitfield bit size
bitfield_bit_offset , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth ) ; // Scope depth for any types that have children
}
break ;
case clang : : Type : : Paren :
{
clang : : QualType desugar_qual_type = llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ;
2015-08-12 06:53:00 +08:00
CompilerType desugar_clang_type ( getASTContext ( ) , desugar_qual_type ) ;
2015-08-12 05:38:15 +08:00
lldb : : Format desugar_format = desugar_clang_type . GetFormat ( ) ;
clang : : TypeInfo desugar_type_info = getASTContext ( ) - > getTypeInfo ( desugar_qual_type ) ;
uint64_t desugar_byte_size = desugar_type_info . Width / 8 ;
return desugar_clang_type . DumpValue ( exe_ctx ,
s , // Stream to dump to
desugar_format , // The format with which to display the element
data , // Data buffer containing all bytes for this type
data_byte_offset , // Offset into "data" where to grab value from
desugar_byte_size , // Size of this type in bytes
bitfield_bit_size , // Bitfield bit size
bitfield_bit_offset , // Bitfield bit offset
show_types , // Boolean indicating if we should show the variable types
show_summary , // Boolean indicating if we should show a summary for the current type
verbose , // Verbose output?
depth ) ; // Scope depth for any types that have children
}
break ;
default :
// We are down to a scalar type that we just need to display.
data . Dump ( s ,
data_byte_offset ,
format ,
data_byte_size ,
1 ,
UINT32_MAX ,
LLDB_INVALID_ADDRESS ,
bitfield_bit_size ,
bitfield_bit_offset ) ;
if ( show_summary )
DumpSummary ( type , exe_ctx , s , data , data_byte_offset , data_byte_size ) ;
break ;
}
}
bool
2015-09-23 08:18:24 +08:00
ClangASTContext : : DumpTypeValue ( lldb : : opaque_compiler_type_t type , Stream * s ,
2015-08-12 05:38:15 +08:00
lldb : : Format format ,
const lldb_private : : DataExtractor & data ,
lldb : : offset_t byte_offset ,
size_t byte_size ,
uint32_t bitfield_bit_size ,
uint32_t bitfield_bit_offset ,
ExecutionContextScope * exe_scope )
{
if ( ! type )
return false ;
if ( IsAggregateType ( type ) )
{
return false ;
}
else
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : Typedef :
{
clang : : QualType typedef_qual_type = llvm : : cast < clang : : TypedefType > ( qual_type ) - > getDecl ( ) - > getUnderlyingType ( ) ;
2015-08-12 06:53:00 +08:00
CompilerType typedef_clang_type ( getASTContext ( ) , typedef_qual_type ) ;
2015-08-12 05:38:15 +08:00
if ( format = = eFormatDefault )
format = typedef_clang_type . GetFormat ( ) ;
clang : : TypeInfo typedef_type_info = getASTContext ( ) - > getTypeInfo ( typedef_qual_type ) ;
uint64_t typedef_byte_size = typedef_type_info . Width / 8 ;
return typedef_clang_type . DumpTypeValue ( s ,
format , // The format with which to display the element
data , // Data buffer containing all bytes for this type
byte_offset , // Offset into "data" where to grab value from
typedef_byte_size , // Size of this type in bytes
bitfield_bit_size , // Size in bits of a bitfield value, if zero don't treat as a bitfield
bitfield_bit_offset , // Offset in bits of a bitfield value if bitfield_bit_size != 0
exe_scope ) ;
}
break ;
case clang : : Type : : Enum :
// If our format is enum or default, show the enumeration value as
// its enumeration string value, else just display it as requested.
if ( ( format = = eFormatEnum | | format = = eFormatDefault ) & & GetCompleteType ( type ) )
{
const clang : : EnumType * enutype = llvm : : cast < clang : : EnumType > ( qual_type . getTypePtr ( ) ) ;
const clang : : EnumDecl * enum_decl = enutype - > getDecl ( ) ;
assert ( enum_decl ) ;
clang : : EnumDecl : : enumerator_iterator enum_pos , enum_end_pos ;
const bool is_signed = qual_type - > isSignedIntegerOrEnumerationType ( ) ;
lldb : : offset_t offset = byte_offset ;
if ( is_signed )
{
const int64_t enum_svalue = data . GetMaxS64Bitfield ( & offset , byte_size , bitfield_bit_size , bitfield_bit_offset ) ;
for ( enum_pos = enum_decl - > enumerator_begin ( ) , enum_end_pos = enum_decl - > enumerator_end ( ) ; enum_pos ! = enum_end_pos ; + + enum_pos )
{
if ( enum_pos - > getInitVal ( ) . getSExtValue ( ) = = enum_svalue )
{
s - > PutCString ( enum_pos - > getNameAsString ( ) . c_str ( ) ) ;
return true ;
}
}
// If we have gotten here we didn't get find the enumerator in the
// enum decl, so just print the integer.
s - > Printf ( " % " PRIi64 , enum_svalue ) ;
}
else
{
const uint64_t enum_uvalue = data . GetMaxU64Bitfield ( & offset , byte_size , bitfield_bit_size , bitfield_bit_offset ) ;
for ( enum_pos = enum_decl - > enumerator_begin ( ) , enum_end_pos = enum_decl - > enumerator_end ( ) ; enum_pos ! = enum_end_pos ; + + enum_pos )
{
if ( enum_pos - > getInitVal ( ) . getZExtValue ( ) = = enum_uvalue )
{
s - > PutCString ( enum_pos - > getNameAsString ( ) . c_str ( ) ) ;
return true ;
}
}
// If we have gotten here we didn't get find the enumerator in the
// enum decl, so just print the integer.
s - > Printf ( " % " PRIu64 , enum_uvalue ) ;
}
return true ;
}
// format was not enum, just fall through and dump the value as requested....
default :
// We are down to a scalar type that we just need to display.
{
uint32_t item_count = 1 ;
// A few formats, we might need to modify our size and count for depending
// on how we are trying to display the value...
switch ( format )
{
default :
case eFormatBoolean :
case eFormatBinary :
case eFormatComplex :
case eFormatCString : // NULL terminated C strings
case eFormatDecimal :
case eFormatEnum :
case eFormatHex :
case eFormatHexUppercase :
case eFormatFloat :
case eFormatOctal :
case eFormatOSType :
case eFormatUnsigned :
case eFormatPointer :
case eFormatVectorOfChar :
case eFormatVectorOfSInt8 :
case eFormatVectorOfUInt8 :
case eFormatVectorOfSInt16 :
case eFormatVectorOfUInt16 :
case eFormatVectorOfSInt32 :
case eFormatVectorOfUInt32 :
case eFormatVectorOfSInt64 :
case eFormatVectorOfUInt64 :
case eFormatVectorOfFloat32 :
case eFormatVectorOfFloat64 :
case eFormatVectorOfUInt128 :
break ;
case eFormatChar :
case eFormatCharPrintable :
case eFormatCharArray :
case eFormatBytes :
case eFormatBytesWithASCII :
item_count = byte_size ;
byte_size = 1 ;
break ;
case eFormatUnicode16 :
item_count = byte_size / 2 ;
byte_size = 2 ;
break ;
case eFormatUnicode32 :
item_count = byte_size / 4 ;
byte_size = 4 ;
break ;
}
return data . Dump ( s ,
byte_offset ,
format ,
byte_size ,
item_count ,
UINT32_MAX ,
LLDB_INVALID_ADDRESS ,
bitfield_bit_size ,
bitfield_bit_offset ,
exe_scope ) ;
}
break ;
}
}
return 0 ;
}
void
2015-09-23 08:18:24 +08:00
ClangASTContext : : DumpSummary ( lldb : : opaque_compiler_type_t type , ExecutionContext * exe_ctx ,
2015-08-12 05:38:15 +08:00
Stream * s ,
const lldb_private : : DataExtractor & data ,
lldb : : offset_t data_byte_offset ,
size_t data_byte_size )
{
uint32_t length = 0 ;
if ( IsCStringType ( type , length ) )
{
if ( exe_ctx )
{
Process * process = exe_ctx - > GetProcessPtr ( ) ;
if ( process )
{
lldb : : offset_t offset = data_byte_offset ;
lldb : : addr_t pointer_address = data . GetMaxU64 ( & offset , data_byte_size ) ;
std : : vector < uint8_t > buf ;
if ( length > 0 )
buf . resize ( length ) ;
else
buf . resize ( 256 ) ;
lldb_private : : DataExtractor cstr_data ( & buf . front ( ) , buf . size ( ) , process - > GetByteOrder ( ) , 4 ) ;
buf . back ( ) = ' \0 ' ;
size_t bytes_read ;
size_t total_cstr_len = 0 ;
Error error ;
while ( ( bytes_read = process - > ReadMemory ( pointer_address , & buf . front ( ) , buf . size ( ) , error ) ) > 0 )
{
const size_t len = strlen ( ( const char * ) & buf . front ( ) ) ;
if ( len = = 0 )
break ;
if ( total_cstr_len = = 0 )
s - > PutCString ( " \" " ) ;
cstr_data . Dump ( s , 0 , lldb : : eFormatChar , 1 , len , UINT32_MAX , LLDB_INVALID_ADDRESS , 0 , 0 ) ;
total_cstr_len + = len ;
if ( len < buf . size ( ) )
break ;
pointer_address + = total_cstr_len ;
}
if ( total_cstr_len > 0 )
s - > PutChar ( ' " ' ) ;
}
}
}
}
void
2015-09-23 08:18:24 +08:00
ClangASTContext : : DumpTypeDescription ( lldb : : opaque_compiler_type_t type )
2015-08-12 05:38:15 +08:00
{
StreamFile s ( stdout , false ) ;
2015-10-15 06:44:50 +08:00
DumpTypeDescription ( type , & s ) ;
2015-08-12 05:38:15 +08:00
ClangASTMetadata * metadata = ClangASTContext : : GetMetadata ( getASTContext ( ) , type ) ;
if ( metadata )
{
metadata - > Dump ( & s ) ;
}
}
void
2015-09-23 08:18:24 +08:00
ClangASTContext : : DumpTypeDescription ( lldb : : opaque_compiler_type_t type , Stream * s )
2015-08-12 05:38:15 +08:00
{
if ( type )
{
clang : : QualType qual_type ( GetQualType ( type ) ) ;
llvm : : SmallVector < char , 1024 > buf ;
llvm : : raw_svector_ostream llvm_ostrm ( buf ) ;
const clang : : Type : : TypeClass type_class = qual_type - > getTypeClass ( ) ;
switch ( type_class )
{
case clang : : Type : : ObjCObject :
case clang : : Type : : ObjCInterface :
{
GetCompleteType ( type ) ;
const clang : : ObjCObjectType * objc_class_type = llvm : : dyn_cast < clang : : ObjCObjectType > ( qual_type . getTypePtr ( ) ) ;
assert ( objc_class_type ) ;
if ( objc_class_type )
{
clang : : ObjCInterfaceDecl * class_interface_decl = objc_class_type - > getInterface ( ) ;
if ( class_interface_decl )
{
clang : : PrintingPolicy policy = getASTContext ( ) - > getPrintingPolicy ( ) ;
class_interface_decl - > print ( llvm_ostrm , policy , s - > GetIndentLevel ( ) ) ;
}
}
}
break ;
case clang : : Type : : Typedef :
{
const clang : : TypedefType * typedef_type = qual_type - > getAs < clang : : TypedefType > ( ) ;
if ( typedef_type )
{
const clang : : TypedefNameDecl * typedef_decl = typedef_type - > getDecl ( ) ;
std : : string clang_typedef_name ( typedef_decl - > getQualifiedNameAsString ( ) ) ;
if ( ! clang_typedef_name . empty ( ) )
{
s - > PutCString ( " typedef " ) ;
s - > PutCString ( clang_typedef_name . c_str ( ) ) ;
}
}
}
break ;
case clang : : Type : : Elaborated :
2015-08-12 06:53:00 +08:00
CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ElaboratedType > ( qual_type ) - > getNamedType ( ) ) . DumpTypeDescription ( s ) ;
2015-08-12 05:38:15 +08:00
return ;
case clang : : Type : : Paren :
2015-08-12 06:53:00 +08:00
CompilerType ( getASTContext ( ) , llvm : : cast < clang : : ParenType > ( qual_type ) - > desugar ( ) ) . DumpTypeDescription ( s ) ;
2015-08-12 05:38:15 +08:00
return ;
case clang : : Type : : Record :
{
GetCompleteType ( type ) ;
const clang : : RecordType * record_type = llvm : : cast < clang : : RecordType > ( qual_type . getTypePtr ( ) ) ;
const clang : : RecordDecl * record_decl = record_type - > getDecl ( ) ;
const clang : : CXXRecordDecl * cxx_record_decl = llvm : : dyn_cast < clang : : CXXRecordDecl > ( record_decl ) ;
if ( cxx_record_decl )
cxx_record_decl - > print ( llvm_ostrm , getASTContext ( ) - > getPrintingPolicy ( ) , s - > GetIndentLevel ( ) ) ;
else
record_decl - > print ( llvm_ostrm , getASTContext ( ) - > getPrintingPolicy ( ) , s - > GetIndentLevel ( ) ) ;
}
break ;
default :
{
const clang : : TagType * tag_type = llvm : : dyn_cast < clang : : TagType > ( qual_type . getTypePtr ( ) ) ;
if ( tag_type )
{
clang : : TagDecl * tag_decl = tag_type - > getDecl ( ) ;
if ( tag_decl )
tag_decl - > print ( llvm_ostrm , 0 ) ;
}
else
{
std : : string clang_type_name ( qual_type . getAsString ( ) ) ;
if ( ! clang_type_name . empty ( ) )
s - > PutCString ( clang_type_name . c_str ( ) ) ;
}
}
}
if ( buf . size ( ) > 0 )
{
s - > Write ( buf . data ( ) , buf . size ( ) ) ;
}
}
}
2015-08-15 04:02:05 +08:00
clang : : ClassTemplateDecl *
2015-08-27 06:57:51 +08:00
ClangASTContext : : ParseClassTemplateDecl ( clang : : DeclContext * decl_ctx ,
2015-08-15 04:02:05 +08:00
lldb : : AccessType access_type ,
const char * parent_name ,
int tag_decl_kind ,
const ClangASTContext : : TemplateParameterInfos & template_param_infos )
{
if ( template_param_infos . IsValid ( ) )
{
std : : string template_basename ( parent_name ) ;
template_basename . erase ( template_basename . find ( ' < ' ) ) ;
return CreateClassTemplateDecl ( decl_ctx ,
access_type ,
template_basename . c_str ( ) ,
tag_decl_kind ,
template_param_infos ) ;
}
return NULL ;
}
2015-08-19 06:32:36 +08:00
void
ClangASTContext : : CompleteTagDecl ( void * baton , clang : : TagDecl * decl )
{
ClangASTContext * ast = ( ClangASTContext * ) baton ;
SymbolFile * sym_file = ast - > GetSymbolFile ( ) ;
if ( sym_file )
{
CompilerType clang_type = GetTypeForDecl ( decl ) ;
if ( clang_type )
sym_file - > CompleteType ( clang_type ) ;
}
}
void
ClangASTContext : : CompleteObjCInterfaceDecl ( void * baton , clang : : ObjCInterfaceDecl * decl )
{
ClangASTContext * ast = ( ClangASTContext * ) baton ;
SymbolFile * sym_file = ast - > GetSymbolFile ( ) ;
if ( sym_file )
{
CompilerType clang_type = GetTypeForDecl ( decl ) ;
if ( clang_type )
sym_file - > CompleteType ( clang_type ) ;
}
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
DWARFASTParser *
ClangASTContext : : GetDWARFParser ( )
{
if ( ! m_dwarf_ast_parser_ap )
m_dwarf_ast_parser_ap . reset ( new DWARFASTParserClang ( * this ) ) ;
return m_dwarf_ast_parser_ap . get ( ) ;
}
2015-08-15 04:02:05 +08:00
bool
2015-08-19 06:32:36 +08:00
ClangASTContext : : LayoutRecordType ( void * baton ,
2015-08-15 04:02:05 +08:00
const clang : : RecordDecl * record_decl ,
uint64_t & bit_size ,
uint64_t & alignment ,
llvm : : DenseMap < const clang : : FieldDecl * , uint64_t > & field_offsets ,
llvm : : DenseMap < const clang : : CXXRecordDecl * , clang : : CharUnits > & base_offsets ,
llvm : : DenseMap < const clang : : CXXRecordDecl * , clang : : CharUnits > & vbase_offsets )
{
2015-08-19 06:32:36 +08:00
ClangASTContext * ast = ( ClangASTContext * ) baton ;
2015-08-28 09:01:03 +08:00
DWARFASTParserClang * dwarf_ast_parser = ( DWARFASTParserClang * ) ast - > GetDWARFParser ( ) ;
return dwarf_ast_parser - > LayoutRecordType ( record_decl , bit_size , alignment , field_offsets , base_offsets , vbase_offsets ) ;
2015-08-15 04:02:05 +08:00
}
2015-09-16 07:44:17 +08:00
//----------------------------------------------------------------------
// CompilerDecl override functions
//----------------------------------------------------------------------
lldb : : VariableSP
ClangASTContext : : DeclGetVariable ( void * opaque_decl )
{
if ( llvm : : dyn_cast < clang : : VarDecl > ( ( clang : : Decl * ) opaque_decl ) )
{
auto decl_search_it = m_decl_objects . find ( opaque_decl ) ;
if ( decl_search_it ! = m_decl_objects . end ( ) )
return std : : static_pointer_cast < Variable > ( decl_search_it - > second ) ;
}
return VariableSP ( ) ;
}
void
ClangASTContext : : DeclLinkToObject ( void * opaque_decl , std : : shared_ptr < void > object )
{
if ( m_decl_objects . find ( opaque_decl ) = = m_decl_objects . end ( ) )
m_decl_objects . insert ( std : : make_pair ( opaque_decl , object ) ) ;
}
ConstString
ClangASTContext : : DeclGetName ( void * opaque_decl )
{
if ( opaque_decl )
{
clang : : NamedDecl * nd = llvm : : dyn_cast < NamedDecl > ( ( clang : : Decl * ) opaque_decl ) ;
if ( nd ! = nullptr )
return ConstString ( nd - > getName ( ) ) ;
}
return ConstString ( ) ;
}
2015-08-28 09:01:03 +08:00
//----------------------------------------------------------------------
// CompilerDeclContext functions
//----------------------------------------------------------------------
2015-08-15 04:02:05 +08:00
2015-09-16 07:44:17 +08:00
std : : vector < void * >
ClangASTContext : : DeclContextFindDeclByName ( void * opaque_decl_ctx , ConstString name )
{
std : : vector < void * > found_decls ;
if ( opaque_decl_ctx )
{
DeclContext * root_decl_ctx = ( DeclContext * ) opaque_decl_ctx ;
std : : set < DeclContext * > searched ;
std : : multimap < DeclContext * , DeclContext * > search_queue ;
2015-09-17 02:48:30 +08:00
SymbolFile * symbol_file = GetSymbolFile ( ) ;
2015-09-16 07:44:17 +08:00
for ( clang : : DeclContext * decl_context = root_decl_ctx ; decl_context ! = nullptr & & found_decls . empty ( ) ; decl_context = decl_context - > getParent ( ) )
{
search_queue . insert ( std : : make_pair ( decl_context , decl_context ) ) ;
for ( auto it = search_queue . find ( decl_context ) ; it ! = search_queue . end ( ) ; it + + )
{
searched . insert ( it - > second ) ;
2015-09-17 02:48:30 +08:00
symbol_file - > ParseDeclsForContext ( CompilerDeclContext ( this , it - > second ) ) ;
2015-09-16 07:44:17 +08:00
for ( clang : : Decl * child : it - > second - > decls ( ) )
{
2015-09-17 02:48:30 +08:00
if ( clang : : UsingDirectiveDecl * ud = llvm : : dyn_cast < clang : : UsingDirectiveDecl > ( child ) )
2015-09-16 07:44:17 +08:00
{
clang : : DeclContext * from = ud - > getCommonAncestor ( ) ;
if ( searched . find ( ud - > getNominatedNamespace ( ) ) = = searched . end ( ) )
search_queue . insert ( std : : make_pair ( from , ud - > getNominatedNamespace ( ) ) ) ;
}
else if ( clang : : UsingDecl * ud = llvm : : dyn_cast < clang : : UsingDecl > ( child ) )
{
for ( clang : : UsingShadowDecl * usd : ud - > shadows ( ) )
{
clang : : Decl * target = usd - > getTargetDecl ( ) ;
if ( clang : : NamedDecl * nd = llvm : : dyn_cast < clang : : NamedDecl > ( target ) )
{
IdentifierInfo * ii = nd - > getIdentifier ( ) ;
if ( ii ! = nullptr & & ii - > getName ( ) . equals ( name . AsCString ( nullptr ) ) )
found_decls . push_back ( nd ) ;
}
}
}
2015-09-17 02:48:30 +08:00
else if ( clang : : NamedDecl * nd = llvm : : dyn_cast < clang : : NamedDecl > ( child ) )
{
IdentifierInfo * ii = nd - > getIdentifier ( ) ;
if ( ii ! = nullptr & & ii - > getName ( ) . equals ( name . AsCString ( nullptr ) ) )
found_decls . push_back ( nd ) ;
}
2015-09-16 07:44:17 +08:00
}
}
}
}
return found_decls ;
}
2015-08-28 09:01:03 +08:00
bool
ClangASTContext : : DeclContextIsStructUnionOrClass ( void * opaque_decl_ctx )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
if ( opaque_decl_ctx )
return ( ( clang : : DeclContext * ) opaque_decl_ctx ) - > isRecord ( ) ;
else
return false ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
ConstString
ClangASTContext : : DeclContextGetName ( void * opaque_decl_ctx )
{
if ( opaque_decl_ctx )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
clang : : NamedDecl * named_decl = llvm : : dyn_cast < clang : : NamedDecl > ( ( clang : : DeclContext * ) opaque_decl_ctx ) ;
if ( named_decl )
return ConstString ( named_decl - > getName ( ) ) ;
2015-08-15 04:02:05 +08:00
}
2015-08-28 09:01:03 +08:00
return ConstString ( ) ;
2015-08-15 04:02:05 +08:00
}
2015-08-28 09:01:03 +08:00
bool
ClangASTContext : : DeclContextIsClassMethod ( void * opaque_decl_ctx ,
lldb : : LanguageType * language_ptr ,
bool * is_instance_method_ptr ,
ConstString * language_object_name_ptr )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
if ( opaque_decl_ctx )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
clang : : DeclContext * decl_ctx = ( clang : : DeclContext * ) opaque_decl_ctx ;
if ( ObjCMethodDecl * objc_method = llvm : : dyn_cast < clang : : ObjCMethodDecl > ( decl_ctx ) )
{
if ( is_instance_method_ptr )
* is_instance_method_ptr = objc_method - > isInstanceMethod ( ) ;
if ( language_ptr )
* language_ptr = eLanguageTypeObjC ;
if ( language_object_name_ptr )
language_object_name_ptr - > SetCString ( " self " ) ;
return true ;
}
else if ( CXXMethodDecl * cxx_method = llvm : : dyn_cast < clang : : CXXMethodDecl > ( decl_ctx ) )
{
if ( is_instance_method_ptr )
* is_instance_method_ptr = cxx_method - > isInstance ( ) ;
if ( language_ptr )
* language_ptr = eLanguageTypeC_plus_plus ;
if ( language_object_name_ptr )
language_object_name_ptr - > SetCString ( " this " ) ;
return true ;
2015-08-15 04:02:05 +08:00
}
2015-08-28 09:01:03 +08:00
else if ( clang : : FunctionDecl * function_decl = llvm : : dyn_cast < clang : : FunctionDecl > ( decl_ctx ) )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
ClangASTMetadata * metadata = GetMetadata ( & decl_ctx - > getParentASTContext ( ) , function_decl ) ;
if ( metadata & & metadata - > HasObjectPtr ( ) )
{
if ( is_instance_method_ptr )
* is_instance_method_ptr = true ;
if ( language_ptr )
* language_ptr = eLanguageTypeObjC ;
if ( language_object_name_ptr )
language_object_name_ptr - > SetCString ( metadata - > GetObjectPtrName ( ) ) ;
return true ;
}
2015-08-15 04:02:05 +08:00
}
}
2015-08-28 09:01:03 +08:00
return false ;
2015-08-15 04:02:05 +08:00
}
2015-08-28 02:09:44 +08:00
clang : : DeclContext *
2015-08-28 09:01:03 +08:00
ClangASTContext : : DeclContextGetAsDeclContext ( const CompilerDeclContext & dc )
2015-08-28 02:09:44 +08:00
{
2015-08-28 09:01:03 +08:00
if ( dc . IsClang ( ) )
return ( clang : : DeclContext * ) dc . GetOpaqueDeclContext ( ) ;
2015-08-28 02:09:44 +08:00
return nullptr ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
ObjCMethodDecl *
ClangASTContext : : DeclContextGetAsObjCMethodDecl ( const CompilerDeclContext & dc )
2015-08-27 06:57:51 +08:00
{
2015-08-28 09:01:03 +08:00
if ( dc . IsClang ( ) )
return llvm : : dyn_cast < clang : : ObjCMethodDecl > ( ( clang : : DeclContext * ) dc . GetOpaqueDeclContext ( ) ) ;
return nullptr ;
2015-08-27 06:57:51 +08:00
}
2015-08-28 09:01:03 +08:00
CXXMethodDecl *
ClangASTContext : : DeclContextGetAsCXXMethodDecl ( const CompilerDeclContext & dc )
2015-08-15 04:02:05 +08:00
{
2015-08-28 09:01:03 +08:00
if ( dc . IsClang ( ) )
return llvm : : dyn_cast < clang : : CXXMethodDecl > ( ( clang : : DeclContext * ) dc . GetOpaqueDeclContext ( ) ) ;
return nullptr ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
clang : : FunctionDecl *
ClangASTContext : : DeclContextGetAsFunctionDecl ( const CompilerDeclContext & dc )
{
if ( dc . IsClang ( ) )
return llvm : : dyn_cast < clang : : FunctionDecl > ( ( clang : : DeclContext * ) dc . GetOpaqueDeclContext ( ) ) ;
return nullptr ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
clang : : NamespaceDecl *
ClangASTContext : : DeclContextGetAsNamespaceDecl ( const CompilerDeclContext & dc )
{
if ( dc . IsClang ( ) )
return llvm : : dyn_cast < clang : : NamespaceDecl > ( ( clang : : DeclContext * ) dc . GetOpaqueDeclContext ( ) ) ;
return nullptr ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
ClangASTMetadata *
ClangASTContext : : DeclContextGetMetaData ( const CompilerDeclContext & dc , const void * object )
{
clang : : ASTContext * ast = DeclContextGetClangASTContext ( dc ) ;
if ( ast )
return ClangASTContext : : GetMetadata ( ast , object ) ;
return nullptr ;
}
2015-08-15 04:02:05 +08:00
2015-08-28 09:01:03 +08:00
clang : : ASTContext *
ClangASTContext : : DeclContextGetClangASTContext ( const CompilerDeclContext & dc )
{
2015-09-09 02:15:05 +08:00
ClangASTContext * ast = llvm : : dyn_cast_or_null < ClangASTContext > ( dc . GetTypeSystem ( ) ) ;
if ( ast )
return ast - > getASTContext ( ) ;
2015-08-28 09:01:03 +08:00
return nullptr ;
2015-08-15 04:02:05 +08:00
}
2015-09-16 05:13:50 +08:00
ClangASTContextForExpressions : : ClangASTContextForExpressions ( Target & target ) :
ClangASTContext ( target . GetArchitecture ( ) . GetTriple ( ) . getTriple ( ) . c_str ( ) ) ,
2015-10-01 03:57:57 +08:00
m_target_wp ( target . shared_from_this ( ) ) ,
m_persistent_variables ( new ClangPersistentVariables )
2015-09-16 05:13:50 +08:00
{
}
UserExpression *
ClangASTContextForExpressions : : GetUserExpression ( const char * expr ,
const char * expr_prefix ,
lldb : : LanguageType language ,
2015-11-03 10:11:24 +08:00
Expression : : ResultType desired_type ,
const EvaluateExpressionOptions & options )
2015-09-16 05:13:50 +08:00
{
TargetSP target_sp = m_target_wp . lock ( ) ;
if ( ! target_sp )
return nullptr ;
2015-11-03 10:11:24 +08:00
return new ClangUserExpression ( * target_sp . get ( ) , expr , expr_prefix , language , desired_type , options ) ;
2015-09-16 05:13:50 +08:00
}
FunctionCaller *
ClangASTContextForExpressions : : GetFunctionCaller ( const CompilerType & return_type ,
const Address & function_address ,
const ValueList & arg_value_list ,
const char * name )
{
TargetSP target_sp = m_target_wp . lock ( ) ;
if ( ! target_sp )
return nullptr ;
Process * process = target_sp - > GetProcessSP ( ) . get ( ) ;
if ( ! process )
return nullptr ;
return new ClangFunctionCaller ( * process , return_type , function_address , arg_value_list , name ) ;
}
UtilityFunction *
ClangASTContextForExpressions : : GetUtilityFunction ( const char * text ,
const char * name )
{
2015-10-01 03:57:57 +08:00
TargetSP target_sp = m_target_wp . lock ( ) ;
2015-09-16 05:13:50 +08:00
if ( ! target_sp )
return nullptr ;
return new ClangUtilityFunction ( * target_sp . get ( ) , text , name ) ;
}
2015-10-01 03:57:57 +08:00
PersistentExpressionState *
ClangASTContextForExpressions : : GetPersistentExpressionState ( )
{
return m_persistent_variables . get ( ) ;
}