2010-07-17 02:28:27 +08:00
//===-- ClangASTSource.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-09 00:52:24 +08:00
# include "clang/AST/ASTContext.h"
2010-10-15 11:36:13 +08:00
# include "lldb/Core/Log.h"
2011-09-17 14:21:20 +08:00
# include "lldb/Core/Module.h"
2011-10-29 09:58:46 +08:00
# include "lldb/Core/ModuleList.h"
2011-10-29 10:28:18 +08:00
# include "lldb/Expression/ASTDumper.h"
2010-06-09 00:52:24 +08:00
# include "lldb/Expression/ClangASTSource.h"
# include "lldb/Expression/ClangExpression.h"
2011-10-29 09:58:46 +08:00
# include "lldb/Symbol/ClangNamespaceDecl.h"
# include "lldb/Symbol/SymbolVendor.h"
# include "lldb/Target/Target.h"
2010-06-09 00:52:24 +08:00
using namespace clang ;
using namespace lldb_private ;
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
ClangASTSource : : ~ ClangASTSource ( )
{
2011-11-29 08:42:02 +08:00
m_ast_importer - > ForgetDestination ( m_ast_context ) ;
ClangASTContext * scratch_clang_ast_context = m_target - > GetScratchClangASTContext ( ) ;
if ( ! scratch_clang_ast_context )
return ;
clang : : ASTContext * scratch_ast_context = scratch_clang_ast_context - > getASTContext ( ) ;
if ( ! scratch_ast_context )
return ;
if ( m_ast_context ! = scratch_ast_context )
m_ast_importer - > ForgetSource ( scratch_ast_context , m_ast_context ) ;
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
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
void
ClangASTSource : : StartTranslationUnit ( ASTConsumer * Consumer )
{
2011-10-29 07:38:38 +08:00
if ( ! m_ast_context )
return ;
m_ast_context - > getTranslationUnitDecl ( ) - > setHasExternalVisibleStorage ( ) ;
m_ast_context - > getTranslationUnitDecl ( ) - > setHasExternalLexicalStorage ( ) ;
2010-06-09 00:52:24 +08:00
}
// The core lookup interface.
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
DeclContext : : lookup_result
ClangASTSource : : FindExternalVisibleDeclsByName
2010-10-15 11:36:13 +08:00
(
const DeclContext * decl_ctx ,
2010-10-16 06:48:33 +08:00
DeclarationName clang_decl_name
2010-10-15 11:36:13 +08:00
)
{
2011-10-29 07:38:38 +08:00
if ( ! m_ast_context )
return SetNoExternalVisibleDeclsForName ( decl_ctx , clang_decl_name ) ;
if ( GetImportInProgress ( ) )
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 SetNoExternalVisibleDeclsForName ( decl_ctx , clang_decl_name ) ;
std : : string decl_name ( clang_decl_name . getAsString ( ) ) ;
// if (m_decl_map.DoingASTImport ())
// return DeclContext::lookup_result();
//
2010-10-16 06:48:33 +08:00
switch ( clang_decl_name . getNameKind ( ) ) {
2010-06-09 00:52:24 +08:00
// Normal identifiers.
case DeclarationName : : Identifier :
2010-10-16 06:48:33 +08:00
if ( clang_decl_name . getAsIdentifierInfo ( ) - > getBuiltinID ( ) ! = 0 )
return SetNoExternalVisibleDeclsForName ( decl_ctx , clang_decl_name ) ;
break ;
2010-06-09 00:52:24 +08:00
// Operator names. Not important for now.
case DeclarationName : : CXXOperatorName :
case DeclarationName : : CXXLiteralOperatorName :
return DeclContext : : lookup_result ( ) ;
// Using directives found in this context.
// Tell Sema we didn't find any or we'll end up getting asked a *lot*.
case DeclarationName : : CXXUsingDirective :
2010-10-16 06:48:33 +08:00
return SetNoExternalVisibleDeclsForName ( decl_ctx , clang_decl_name ) ;
2010-06-09 00:52:24 +08:00
case DeclarationName : : ObjCZeroArgSelector :
case DeclarationName : : ObjCOneArgSelector :
case DeclarationName : : ObjCMultiArgSelector :
2011-11-10 03:33:21 +08:00
{
llvm : : SmallVector < NamedDecl * , 1 > method_decls ;
2010-06-09 00:52:24 +08:00
2011-11-10 03:33:21 +08:00
NameSearchContext method_search_context ( * this , method_decls , clang_decl_name , decl_ctx ) ;
FindObjCMethodDecls ( method_search_context ) ;
return SetExternalVisibleDeclsForName ( decl_ctx , clang_decl_name , method_decls ) ;
}
2010-06-09 00:52:24 +08:00
// These aren't possible in the global context.
case DeclarationName : : CXXConstructorName :
case DeclarationName : : CXXDestructorName :
case DeclarationName : : CXXConversionFunctionName :
return DeclContext : : lookup_result ( ) ;
}
2010-10-15 11:36:13 +08:00
2011-10-29 07:38:38 +08:00
if ( ! GetLookupsEnabled ( ) )
2010-10-16 06:48:33 +08:00
{
// Wait until we see a '$' at the start of a name before we start doing
// any lookups so we can avoid lookup up all of the builtin types.
if ( ! decl_name . empty ( ) & & decl_name [ 0 ] = = ' $ ' )
{
2011-10-29 07:38:38 +08:00
SetLookupsEnabled ( true ) ;
2010-10-16 06:48:33 +08:00
}
else
{
return SetNoExternalVisibleDeclsForName ( decl_ctx , clang_decl_name ) ;
}
2010-10-15 11:36:13 +08:00
}
2010-10-16 06:48:33 +08:00
2010-11-13 12:18:24 +08:00
ConstString const_decl_name ( decl_name . c_str ( ) ) ;
2010-06-09 00:52:24 +08:00
2010-11-13 12:18:24 +08:00
const char * uniqued_const_decl_name = const_decl_name . GetCString ( ) ;
if ( m_active_lookups . find ( uniqued_const_decl_name ) ! = m_active_lookups . end ( ) )
{
// We are currently looking up this name...
return DeclContext : : lookup_result ( ) ;
}
m_active_lookups . insert ( uniqued_const_decl_name ) ;
2010-11-15 09:34:18 +08:00
// static uint32_t g_depth = 0;
// ++g_depth;
// printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
2010-11-13 12:18:24 +08:00
llvm : : SmallVector < NamedDecl * , 4 > name_decls ;
2010-10-16 06:48:33 +08:00
NameSearchContext name_search_context ( * this , name_decls , clang_decl_name , decl_ctx ) ;
2011-10-29 07:38:38 +08:00
FindExternalVisibleDecls ( name_search_context ) ;
2010-11-13 12:18:24 +08:00
DeclContext : : lookup_result result ( SetExternalVisibleDeclsForName ( decl_ctx , clang_decl_name , name_decls ) ) ;
2010-11-15 09:34:18 +08:00
// --g_depth;
2010-11-13 12:18:24 +08:00
m_active_lookups . erase ( uniqued_const_decl_name ) ;
return result ;
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
void
2011-10-29 07:38:38 +08:00
ClangASTSource : : CompleteType ( TagDecl * tag_decl )
2011-10-29 10:28:18 +08:00
{
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
if ( log )
{
2011-11-18 11:28:09 +08:00
log - > Printf ( " [CompleteTagDecl] on (ASTContext*)%p Completing a TagDecl named %s " , m_ast_context , tag_decl - > getName ( ) . str ( ) . c_str ( ) ) ;
2011-10-29 10:28:18 +08:00
log - > Printf ( " [CTD] Before: " ) ;
ASTDumper dumper ( ( Decl * ) tag_decl ) ;
dumper . ToLog ( log , " [CTD] " ) ;
}
m_ast_importer - > CompleteTagDecl ( tag_decl ) ;
if ( log )
{
log - > Printf ( " [CTD] After: " ) ;
ASTDumper dumper ( ( Decl * ) tag_decl ) ;
dumper . ToLog ( log , " [CTD] " ) ;
}
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
}
2011-10-29 07:38:38 +08:00
void
2011-10-29 10:28:18 +08:00
ClangASTSource : : CompleteType ( clang : : ObjCInterfaceDecl * interface_decl )
{
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
if ( log )
{
2011-11-18 11:28:09 +08:00
log - > Printf ( " [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing an ObjCInterfaceDecl named %s " , m_ast_context , interface_decl - > getName ( ) . str ( ) . c_str ( ) ) ;
2011-10-29 10:28:18 +08:00
log - > Printf ( " [COID] Before: " ) ;
ASTDumper dumper ( ( Decl * ) interface_decl ) ;
dumper . ToLog ( log , " [COID] " ) ;
}
m_ast_importer - > CompleteObjCInterfaceDecl ( interface_decl ) ;
if ( log )
{
log - > Printf ( " [COID] After: " ) ;
ASTDumper dumper ( ( Decl * ) interface_decl ) ;
dumper . ToLog ( log , " [COID] " ) ;
}
2010-09-23 11:01:22 +08:00
}
2011-07-30 10:42:06 +08:00
clang : : ExternalLoadResult
2011-10-29 10:28:18 +08:00
ClangASTSource : : FindExternalLexicalDecls ( const DeclContext * decl_context ,
bool ( * predicate ) ( Decl : : Kind ) ,
llvm : : SmallVectorImpl < Decl * > & decls )
{
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
const Decl * context_decl = dyn_cast < Decl > ( decl_context ) ;
if ( ! context_decl )
return ELR_Failure ;
static unsigned int invocation_id = 0 ;
unsigned int current_id = invocation_id + + ;
if ( log )
{
if ( const NamedDecl * context_named_decl = dyn_cast < NamedDecl > ( context_decl ) )
2011-11-18 11:28:09 +08:00
log - > Printf ( " FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate " ,
2011-10-29 10:28:18 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-10-29 10:28:18 +08:00
context_named_decl - > getNameAsString ( ) . c_str ( ) ,
2011-11-18 11:28:09 +08:00
context_decl - > getDeclKindName ( ) ,
context_decl ,
2011-10-29 10:28:18 +08:00
( predicate ? " non-null " : " null " ) ) ;
else if ( context_decl )
2011-11-18 11:28:09 +08:00
log - > Printf ( " FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate " ,
2011-10-29 10:28:18 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-10-29 10:28:18 +08:00
context_decl - > getDeclKindName ( ) ,
2011-11-18 11:28:09 +08:00
context_decl ,
2011-10-29 10:28:18 +08:00
( predicate ? " non-null " : " null " ) ) ;
else
2011-11-18 11:28:09 +08:00
log - > Printf ( " FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate " ,
2011-10-29 10:28:18 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-10-29 10:28:18 +08:00
( predicate ? " non-null " : " null " ) ) ;
}
Decl * original_decl = NULL ;
ASTContext * original_ctx = NULL ;
if ( ! m_ast_importer - > ResolveDeclOrigin ( context_decl , & original_decl , & original_ctx ) )
return ELR_Failure ;
if ( log )
{
log - > Printf ( " FELD[%u] Original decl: " , current_id ) ;
ASTDumper ( original_decl ) . ToLog ( log , " " ) ;
}
if ( TagDecl * original_tag_decl = dyn_cast < TagDecl > ( original_decl ) )
{
ExternalASTSource * external_source = original_ctx - > getExternalSource ( ) ;
if ( external_source )
external_source - > CompleteType ( original_tag_decl ) ;
}
DeclContext * original_decl_context = dyn_cast < DeclContext > ( original_decl ) ;
if ( ! original_decl_context )
return ELR_Failure ;
for ( TagDecl : : decl_iterator iter = original_decl_context - > decls_begin ( ) ;
iter ! = original_decl_context - > decls_end ( ) ;
+ + iter )
{
Decl * decl = * iter ;
if ( ! predicate | | predicate ( decl - > getKind ( ) ) )
{
if ( log )
{
ASTDumper ast_dumper ( decl ) ;
if ( const NamedDecl * context_named_decl = dyn_cast < NamedDecl > ( context_decl ) )
log - > Printf ( " FELD[%d] Adding [to %s] lexical decl %s " , current_id , context_named_decl - > getNameAsString ( ) . c_str ( ) , ast_dumper . GetCString ( ) ) ;
else
log - > Printf ( " FELD[%d] Adding lexical decl %s " , current_id , ast_dumper . GetCString ( ) ) ;
}
2011-11-17 02:20:47 +08:00
Decl * copied_decl = m_ast_importer - > CopyDecl ( m_ast_context , original_ctx , decl ) ;
2011-10-29 10:28:18 +08:00
decls . push_back ( copied_decl ) ;
}
}
return ELR_AlreadyLoaded ;
2010-06-09 00:52:24 +08:00
}
2011-10-30 03:50:43 +08:00
void
ClangASTSource : : FindExternalVisibleDecls ( NameSearchContext & context )
{
assert ( m_ast_context ) ;
const ConstString name ( context . m_decl_name . getAsString ( ) . c_str ( ) ) ;
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
static unsigned int invocation_id = 0 ;
unsigned int current_id = invocation_id + + ;
if ( log )
{
if ( ! context . m_decl_context )
2011-11-18 11:28:09 +08:00
log - > Printf ( " ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a NULL DeclContext " , current_id , m_ast_context , name . GetCString ( ) ) ;
2011-10-30 03:50:43 +08:00
else if ( const NamedDecl * context_named_decl = dyn_cast < NamedDecl > ( context . m_decl_context ) )
2011-11-18 11:28:09 +08:00
log - > Printf ( " ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in '%s' " , current_id , m_ast_context , name . GetCString ( ) , context_named_decl - > getNameAsString ( ) . c_str ( ) ) ;
2011-10-30 03:50:43 +08:00
else
2011-11-18 11:28:09 +08:00
log - > Printf ( " ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a '%s' " , current_id , m_ast_context , name . GetCString ( ) , context . m_decl_context - > getDeclKindName ( ) ) ;
2011-10-30 03:50:43 +08:00
}
context . m_namespace_map . reset ( new ClangASTImporter : : NamespaceMap ) ;
if ( const NamespaceDecl * namespace_context = dyn_cast < NamespaceDecl > ( context . m_decl_context ) )
{
ClangASTImporter : : NamespaceMapSP namespace_map = m_ast_importer - > GetNamespaceMap ( namespace_context ) ;
if ( log & & log - > GetVerbose ( ) )
log - > Printf ( " CAS::FEVD[%u] Inspecting namespace map %p (%d entries) " ,
current_id ,
namespace_map . get ( ) ,
( int ) namespace_map - > size ( ) ) ;
if ( ! namespace_map )
return ;
for ( ClangASTImporter : : NamespaceMap : : iterator i = namespace_map - > begin ( ) , e = namespace_map - > end ( ) ;
i ! = e ;
+ + i )
{
if ( log )
log - > Printf ( " CAS::FEVD[%u] Searching namespace %s in module %s " ,
current_id ,
i - > second . GetNamespaceDecl ( ) - > getNameAsString ( ) . c_str ( ) ,
i - > first - > GetFileSpec ( ) . GetFilename ( ) . GetCString ( ) ) ;
FindExternalVisibleDecls ( context ,
i - > first ,
i - > second ,
current_id ) ;
}
}
2011-11-16 05:50:18 +08:00
else if ( isa < ObjCInterfaceDecl > ( context . m_decl_context ) )
2011-11-15 10:11:17 +08:00
{
FindObjCPropertyDecls ( context ) ;
}
2011-10-30 03:50:43 +08:00
else if ( ! isa < TranslationUnitDecl > ( context . m_decl_context ) )
{
// we shouldn't be getting FindExternalVisibleDecls calls for these
return ;
}
else
{
ClangNamespaceDecl namespace_decl ;
if ( log )
log - > Printf ( " CAS::FEVD[%u] Searching the root namespace " , current_id ) ;
FindExternalVisibleDecls ( context ,
lldb : : ModuleSP ( ) ,
namespace_decl ,
current_id ) ;
}
if ( ! context . m_namespace_map - > empty ( ) )
{
if ( log & & log - > GetVerbose ( ) )
log - > Printf ( " CAS::FEVD[%u] Registering namespace map %p (%d entries) " ,
current_id ,
context . m_namespace_map . get ( ) ,
( int ) context . m_namespace_map - > size ( ) ) ;
NamespaceDecl * clang_namespace_decl = AddNamespace ( context , context . m_namespace_map ) ;
if ( clang_namespace_decl )
clang_namespace_decl - > setHasExternalVisibleStorage ( ) ;
}
}
void
ClangASTSource : : FindExternalVisibleDecls ( NameSearchContext & context ,
lldb : : ModuleSP module_sp ,
ClangNamespaceDecl & namespace_decl ,
unsigned int current_id )
{
assert ( m_ast_context ) ;
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
SymbolContextList sc_list ;
const ConstString name ( context . m_decl_name . getAsString ( ) . c_str ( ) ) ;
const char * name_unique_cstr = name . GetCString ( ) ;
if ( name_unique_cstr = = NULL )
return ;
// The ClangASTSource is not responsible for finding $-names.
if ( name_unique_cstr [ 0 ] = = ' $ ' )
return ;
if ( module_sp & & namespace_decl )
{
ClangNamespaceDecl found_namespace_decl ;
SymbolVendor * symbol_vendor = module_sp - > GetSymbolVendor ( ) ;
if ( symbol_vendor )
{
SymbolContext null_sc ;
found_namespace_decl = symbol_vendor - > FindNamespace ( null_sc , name , & namespace_decl ) ;
if ( found_namespace_decl )
{
context . m_namespace_map - > push_back ( std : : pair < lldb : : ModuleSP , ClangNamespaceDecl > ( module_sp , found_namespace_decl ) ) ;
if ( log )
log - > Printf ( " CAS::FEVD[%u] Found namespace %s in module %s " ,
current_id ,
name . GetCString ( ) ,
module_sp - > GetFileSpec ( ) . GetFilename ( ) . GetCString ( ) ) ;
}
}
}
else
{
ModuleList & images = m_target - > GetImages ( ) ;
for ( uint32_t i = 0 , e = images . GetSize ( ) ;
i ! = e ;
+ + i )
{
lldb : : ModuleSP image = images . GetModuleAtIndex ( i ) ;
if ( ! image )
continue ;
ClangNamespaceDecl found_namespace_decl ;
SymbolVendor * symbol_vendor = image - > GetSymbolVendor ( ) ;
if ( ! symbol_vendor )
continue ;
SymbolContext null_sc ;
found_namespace_decl = symbol_vendor - > FindNamespace ( null_sc , name , & namespace_decl ) ;
if ( found_namespace_decl )
{
context . m_namespace_map - > push_back ( std : : pair < lldb : : ModuleSP , ClangNamespaceDecl > ( image , found_namespace_decl ) ) ;
if ( log )
log - > Printf ( " CAS::FEVD[%u] Found namespace %s in module %s " ,
current_id ,
name . GetCString ( ) ,
image - > GetFileSpec ( ) . GetFilename ( ) . GetCString ( ) ) ;
}
}
}
static ConstString id_name ( " id " ) ;
2011-11-12 04:37:26 +08:00
static ConstString Class_name ( " Class " ) ;
2011-10-30 03:50:43 +08:00
do
{
TypeList types ;
SymbolContext null_sc ;
if ( module_sp & & namespace_decl )
module_sp - > FindTypes ( null_sc , name , & namespace_decl , true , 1 , types ) ;
2011-11-12 04:37:26 +08:00
else if ( name ! = id_name & & name ! = Class_name )
2011-10-30 03:50:43 +08:00
m_target - > GetImages ( ) . FindTypes ( null_sc , name , true , 1 , types ) ;
else
break ;
if ( types . GetSize ( ) )
{
lldb : : TypeSP type_sp = types . GetTypeAtIndex ( 0 ) ;
if ( log )
{
const char * name_string = type_sp - > GetName ( ) . GetCString ( ) ;
log - > Printf ( " CAS::FEVD[%u] Matching type found for \" %s \" : %s " ,
current_id ,
name . GetCString ( ) ,
( name_string ? name_string : " <anonymous> " ) ) ;
}
void * copied_type = GuardedCopyType ( m_ast_context , type_sp - > GetClangAST ( ) , type_sp - > GetClangFullType ( ) ) ;
context . AddTypeDecl ( copied_type ) ;
}
} while ( 0 ) ;
}
2011-11-10 03:33:21 +08:00
void
ClangASTSource : : FindObjCMethodDecls ( NameSearchContext & context )
{
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
2011-11-12 04:37:26 +08:00
static unsigned int invocation_id = 0 ;
unsigned int current_id = invocation_id + + ;
2011-11-10 03:33:21 +08:00
const DeclarationName & decl_name ( context . m_decl_name ) ;
const DeclContext * decl_ctx ( context . m_decl_context ) ;
const ObjCInterfaceDecl * interface_decl = dyn_cast < ObjCInterfaceDecl > ( decl_ctx ) ;
if ( ! interface_decl )
return ;
StreamString ss ;
if ( decl_name . isObjCZeroArgSelector ( ) )
{
ss . Printf ( " %s " , decl_name . getAsString ( ) . c_str ( ) ) ;
}
else if ( decl_name . isObjCOneArgSelector ( ) )
{
2011-11-15 02:29:46 +08:00
ss . Printf ( " %s " , decl_name . getAsString ( ) . c_str ( ) ) ;
2011-11-10 03:33:21 +08:00
}
else
{
clang : : Selector sel = decl_name . getObjCSelector ( ) ;
for ( unsigned i = 0 , e = sel . getNumArgs ( ) ;
i ! = e ;
+ + i )
{
llvm : : StringRef r = sel . getNameForSlot ( i ) ;
ss . Printf ( " %s: " , r . str ( ) . c_str ( ) ) ;
}
}
ss . Flush ( ) ;
2011-11-12 04:37:26 +08:00
ConstString selector_name ( ss . GetData ( ) ) ;
2011-11-10 03:33:21 +08:00
if ( log )
2011-11-18 11:28:09 +08:00
log - > Printf ( " ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s] " ,
current_id ,
m_ast_context ,
2011-11-12 04:37:26 +08:00
interface_decl - > getNameAsString ( ) . c_str ( ) ,
selector_name . AsCString ( ) ) ;
SymbolContextList sc_list ;
const bool include_symbols = false ;
const bool append = false ;
m_target - > GetImages ( ) . FindFunctions ( selector_name , lldb : : eFunctionNameTypeSelector , include_symbols , append , sc_list ) ;
for ( uint32_t i = 0 , e = sc_list . GetSize ( ) ;
i ! = e ;
+ + i )
{
SymbolContext sc ;
if ( ! sc_list . GetContextAtIndex ( i , sc ) )
continue ;
if ( ! sc . function )
continue ;
DeclContext * function_ctx = sc . function - > GetClangDeclContext ( ) ;
if ( ! function_ctx )
continue ;
ObjCMethodDecl * method_decl = dyn_cast < ObjCMethodDecl > ( function_ctx ) ;
if ( ! method_decl )
continue ;
ObjCInterfaceDecl * found_interface_decl = method_decl - > getClassInterface ( ) ;
if ( ! found_interface_decl )
continue ;
if ( found_interface_decl - > getName ( ) = = interface_decl - > getName ( ) )
{
2011-11-17 02:20:47 +08:00
Decl * copied_decl = m_ast_importer - > CopyDecl ( m_ast_context , & method_decl - > getASTContext ( ) , method_decl ) ;
2011-11-12 04:37:26 +08:00
if ( ! copied_decl )
continue ;
ObjCMethodDecl * copied_method_decl = dyn_cast < ObjCMethodDecl > ( copied_decl ) ;
if ( ! copied_method_decl )
continue ;
if ( log )
{
ASTDumper dumper ( ( Decl * ) copied_method_decl ) ;
log - > Printf ( " CAS::FOMD[%d] found %s " , current_id , dumper . GetCString ( ) ) ;
}
context . AddNamedDecl ( copied_method_decl ) ;
}
}
2011-11-10 03:33:21 +08:00
}
2011-11-15 10:11:17 +08:00
void
ClangASTSource : : FindObjCPropertyDecls ( NameSearchContext & context )
{
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
static unsigned int invocation_id = 0 ;
unsigned int current_id = invocation_id + + ;
const ObjCInterfaceDecl * iface_decl = cast < ObjCInterfaceDecl > ( context . m_decl_context ) ;
Decl * orig_decl ;
ASTContext * orig_ast_ctx ;
m_ast_importer - > ResolveDeclOrigin ( iface_decl , & orig_decl , & orig_ast_ctx ) ;
if ( ! orig_decl )
return ;
ObjCInterfaceDecl * orig_iface_decl = dyn_cast < ObjCInterfaceDecl > ( orig_decl ) ;
if ( ! orig_iface_decl )
return ;
if ( ! ClangASTContext : : GetCompleteDecl ( orig_ast_ctx , orig_iface_decl ) )
return ;
std : : string property_name_str = context . m_decl_name . getAsString ( ) ;
StringRef property_name ( property_name_str . c_str ( ) ) ;
ObjCPropertyDecl * property_decl = orig_iface_decl - > FindPropertyDeclaration ( & orig_ast_ctx - > Idents . get ( property_name ) ) ;
if ( log )
2011-11-18 11:28:09 +08:00
log - > Printf ( " ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s' " ,
2011-11-15 10:11:17 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-11-15 10:11:17 +08:00
iface_decl - > getNameAsString ( ) . c_str ( ) ,
property_name_str . c_str ( ) ) ;
if ( ! property_decl )
return ;
2011-11-17 02:20:47 +08:00
Decl * copied_decl = m_ast_importer - > CopyDecl ( m_ast_context , orig_ast_ctx , property_decl ) ;
2011-11-15 10:11:17 +08:00
if ( ! copied_decl )
return ;
ObjCPropertyDecl * copied_property_decl = dyn_cast < ObjCPropertyDecl > ( copied_decl ) ;
if ( ! copied_property_decl )
return ;
if ( log )
{
ASTDumper dumper ( ( Decl * ) copied_property_decl ) ;
log - > Printf ( " CAS::FOPD[%d] found %s " , current_id , dumper . GetCString ( ) ) ;
}
context . AddNamedDecl ( copied_property_decl ) ;
}
2011-10-29 09:58:46 +08:00
void
ClangASTSource : : CompleteNamespaceMap ( ClangASTImporter : : NamespaceMapSP & namespace_map ,
const ConstString & name ,
ClangASTImporter : : NamespaceMapSP & parent_map ) const
{
static unsigned int invocation_id = 0 ;
unsigned int current_id = invocation_id + + ;
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
if ( log )
{
if ( parent_map & & parent_map - > size ( ) )
2011-11-18 11:28:09 +08:00
log - > Printf ( " CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s " ,
2011-10-29 09:58:46 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-10-29 09:58:46 +08:00
name . GetCString ( ) ,
parent_map - > begin ( ) - > second . GetNamespaceDecl ( ) - > getDeclName ( ) . getAsString ( ) . c_str ( ) ) ;
else
2011-11-18 11:28:09 +08:00
log - > Printf ( " CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s " ,
2011-10-29 09:58:46 +08:00
current_id ,
2011-11-18 11:28:09 +08:00
m_ast_context ,
2011-10-29 09:58:46 +08:00
name . GetCString ( ) ) ;
}
if ( parent_map )
{
for ( ClangASTImporter : : NamespaceMap : : iterator i = parent_map - > begin ( ) , e = parent_map - > end ( ) ;
i ! = e ;
+ + i )
{
ClangNamespaceDecl found_namespace_decl ;
lldb : : ModuleSP module_sp = i - > first ;
ClangNamespaceDecl module_parent_namespace_decl = i - > second ;
SymbolVendor * symbol_vendor = module_sp - > GetSymbolVendor ( ) ;
if ( ! symbol_vendor )
continue ;
SymbolContext null_sc ;
found_namespace_decl = symbol_vendor - > FindNamespace ( null_sc , name , & module_parent_namespace_decl ) ;
if ( ! found_namespace_decl )
continue ;
namespace_map - > push_back ( std : : pair < lldb : : ModuleSP , ClangNamespaceDecl > ( module_sp , found_namespace_decl ) ) ;
if ( log )
log - > Printf ( " CMN[%u] Found namespace %s in module %s " ,
current_id ,
name . GetCString ( ) ,
module_sp - > GetFileSpec ( ) . GetFilename ( ) . GetCString ( ) ) ;
}
}
else
{
ModuleList & images = m_target - > GetImages ( ) ;
ClangNamespaceDecl null_namespace_decl ;
for ( uint32_t i = 0 , e = images . GetSize ( ) ;
i ! = e ;
+ + i )
{
lldb : : ModuleSP image = images . GetModuleAtIndex ( i ) ;
if ( ! image )
continue ;
ClangNamespaceDecl found_namespace_decl ;
SymbolVendor * symbol_vendor = image - > GetSymbolVendor ( ) ;
if ( ! symbol_vendor )
continue ;
SymbolContext null_sc ;
found_namespace_decl = symbol_vendor - > FindNamespace ( null_sc , name , & null_namespace_decl ) ;
if ( ! found_namespace_decl )
continue ;
namespace_map - > push_back ( std : : pair < lldb : : ModuleSP , ClangNamespaceDecl > ( image , found_namespace_decl ) ) ;
if ( log )
log - > Printf ( " CMN[%u] Found namespace %s in module %s " ,
current_id ,
name . GetCString ( ) ,
image - > GetFileSpec ( ) . GetFilename ( ) . GetCString ( ) ) ;
}
}
}
2011-10-29 10:28:18 +08:00
NamespaceDecl *
ClangASTSource : : AddNamespace ( NameSearchContext & context , ClangASTImporter : : NamespaceMapSP & namespace_decls )
{
if ( namespace_decls . empty ( ) )
return NULL ;
lldb : : LogSP log ( lldb_private : : GetLogIfAllCategoriesSet ( LIBLLDB_LOG_EXPRESSIONS ) ) ;
const ClangNamespaceDecl & namespace_decl = namespace_decls - > begin ( ) - > second ;
2011-11-17 02:20:47 +08:00
Decl * copied_decl = m_ast_importer - > CopyDecl ( m_ast_context , namespace_decl . GetASTContext ( ) , namespace_decl . GetNamespaceDecl ( ) ) ;
2011-10-29 10:28:18 +08:00
NamespaceDecl * copied_namespace_decl = dyn_cast < NamespaceDecl > ( copied_decl ) ;
m_ast_importer - > RegisterNamespaceMap ( copied_namespace_decl , namespace_decls ) ;
return dyn_cast < NamespaceDecl > ( copied_decl ) ;
}
2011-10-30 03:50:43 +08:00
void *
ClangASTSource : : GuardedCopyType ( ASTContext * dest_context ,
ASTContext * source_context ,
void * clang_type )
{
SetImportInProgress ( true ) ;
2011-11-17 02:20:47 +08:00
QualType ret_qual_type = m_ast_importer - > CopyType ( m_ast_context , source_context , QualType : : getFromOpaquePtr ( clang_type ) ) ;
2011-10-30 03:50:43 +08:00
void * ret = ret_qual_type . getAsOpaquePtr ( ) ;
SetImportInProgress ( false ) ;
return ret ;
}
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 : : NamedDecl *
NameSearchContext : : AddVarDecl ( void * type )
{
2010-10-16 06:48:33 +08:00
IdentifierInfo * ii = m_decl_name . getAsIdentifierInfo ( ) ;
2010-11-30 08:27:43 +08:00
assert ( type & & " Type for variable must be non-NULL! " ) ;
2010-09-15 05:59:34 +08:00
2011-10-29 07:38:38 +08:00
clang : : NamedDecl * Decl = VarDecl : : Create ( * m_ast_source . m_ast_context ,
2010-10-16 06:48:33 +08:00
const_cast < DeclContext * > ( m_decl_context ) ,
2010-06-09 00:52:24 +08:00
SourceLocation ( ) ,
2011-03-15 08:17:19 +08:00
SourceLocation ( ) ,
2010-09-15 05:59:34 +08:00
ii ,
2010-06-09 00:52:24 +08:00
QualType : : getFromOpaquePtr ( type ) ,
0 ,
2010-09-23 11:01:22 +08:00
SC_Static ,
SC_Static ) ;
2010-10-16 06:48:33 +08:00
m_decls . push_back ( Decl ) ;
2010-06-09 00:52:24 +08:00
return Decl ;
}
2010-06-23 07:46: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
clang : : NamedDecl *
NameSearchContext : : AddFunDecl ( void * type )
{
2011-10-29 07:38:38 +08:00
clang : : FunctionDecl * func_decl = FunctionDecl : : Create ( * m_ast_source . m_ast_context ,
2010-10-16 06:48:33 +08:00
const_cast < DeclContext * > ( m_decl_context ) ,
SourceLocation ( ) ,
2011-03-15 08:17:19 +08:00
SourceLocation ( ) ,
2010-10-16 06:48:33 +08:00
m_decl_name . getAsIdentifierInfo ( ) ,
QualType : : getFromOpaquePtr ( type ) ,
NULL ,
SC_Static ,
SC_Static ,
false ,
true ) ;
2010-06-23 07:46:24 +08:00
2010-08-13 07:45:38 +08:00
// We have to do more than just synthesize the FunctionDecl. We have to
// synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
// this, we raid the function's FunctionProtoType for types.
2010-10-16 06:48:33 +08:00
QualType qual_type ( QualType : : getFromOpaquePtr ( type ) ) ;
const FunctionProtoType * func_proto_type = qual_type - > getAs < FunctionProtoType > ( ) ;
2010-06-23 07:46:24 +08:00
2010-10-16 06:48:33 +08:00
if ( func_proto_type )
2010-06-24 02:58:10 +08:00
{
2010-10-16 06:48:33 +08:00
unsigned NumArgs = func_proto_type - > getNumArgs ( ) ;
2010-06-23 07:46:24 +08:00
unsigned ArgIndex ;
2011-10-08 07:18:13 +08:00
SmallVector < ParmVarDecl * , 5 > parm_var_decls ;
2010-06-23 07:46:24 +08:00
for ( ArgIndex = 0 ; ArgIndex < NumArgs ; + + ArgIndex )
{
2010-10-16 06:48:33 +08:00
QualType arg_qual_type ( func_proto_type - > getArgType ( ArgIndex ) ) ;
2010-06-23 07:46:24 +08:00
2011-10-29 07:38:38 +08:00
parm_var_decls . push_back ( ParmVarDecl : : Create ( * m_ast_source . m_ast_context ,
2011-10-08 07:18:13 +08:00
const_cast < DeclContext * > ( m_decl_context ) ,
SourceLocation ( ) ,
SourceLocation ( ) ,
NULL ,
arg_qual_type ,
NULL ,
SC_Static ,
SC_Static ,
NULL ) ) ;
2010-06-23 07:46:24 +08:00
}
2011-10-08 07:18:13 +08:00
func_decl - > setParams ( ArrayRef < ParmVarDecl * > ( parm_var_decls ) ) ;
2010-06-23 07:46:24 +08:00
}
2010-10-16 06:48:33 +08:00
m_decls . push_back ( func_decl ) ;
2010-06-23 07:46:24 +08:00
2010-10-16 06:48:33 +08:00
return func_decl ;
2010-06-23 07:46:24 +08:00
}
2010-07-27 08:55:47 +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
clang : : NamedDecl *
NameSearchContext : : AddGenericFunDecl ( )
2010-07-27 08:55:47 +08:00
{
2011-01-19 07:32:05 +08:00
FunctionProtoType : : ExtProtoInfo proto_info ;
proto_info . Variadic = true ;
2011-10-29 07:38:38 +08:00
QualType generic_function_type ( m_ast_source . m_ast_context - > getFunctionType ( m_ast_source . m_ast_context - > UnknownAnyTy , // result
NULL , // argument types
0 , // number of arguments
proto_info ) ) ;
2010-10-16 06:48:33 +08:00
2010-07-27 08:55:47 +08:00
return AddFunDecl ( generic_function_type . getAsOpaquePtr ( ) ) ;
}
2010-08-04 09:02:13 +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
clang : : NamedDecl *
NameSearchContext : : AddTypeDecl ( void * type )
2010-08-04 09:02:13 +08:00
{
2011-01-23 08:34:52 +08:00
if ( type )
2010-08-04 09:02:13 +08:00
{
2011-01-23 08:34:52 +08:00
QualType qual_type = QualType : : getFromOpaquePtr ( type ) ;
2011-01-27 12:42:51 +08:00
if ( const TagType * tag_type = dyn_cast < clang : : TagType > ( qual_type ) )
2011-01-23 08:34:52 +08:00
{
TagDecl * tag_decl = tag_type - > getDecl ( ) ;
m_decls . push_back ( tag_decl ) ;
return tag_decl ;
}
2011-01-27 12:42:51 +08:00
else if ( const ObjCObjectType * objc_object_type = dyn_cast < clang : : ObjCObjectType > ( qual_type ) )
2011-01-23 08:34:52 +08:00
{
ObjCInterfaceDecl * interface_decl = objc_object_type - > getInterface ( ) ;
m_decls . push_back ( ( NamedDecl * ) interface_decl ) ;
return ( NamedDecl * ) interface_decl ;
}
2010-08-04 09:02:13 +08:00
}
2011-01-23 08:34:52 +08:00
return NULL ;
2010-08-04 09:02:13 +08:00
}
2011-06-25 08:44:06 +08:00
void
NameSearchContext : : AddLookupResult ( clang : : DeclContextLookupConstResult result )
{
for ( clang : : NamedDecl * const * decl_iterator = result . first ;
decl_iterator ! = result . second ;
+ + decl_iterator )
m_decls . push_back ( * decl_iterator ) ;
}
void
NameSearchContext : : AddNamedDecl ( clang : : NamedDecl * decl )
{
m_decls . push_back ( decl ) ;
}