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"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Expression/ClangASTSource.h"
|
|
|
|
#include "lldb/Expression/ClangExpression.h"
|
|
|
|
#include "lldb/Expression/ClangExpressionDeclMap.h"
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
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)
|
|
|
|
{
|
2010-06-09 00:52:24 +08:00
|
|
|
// Tell Sema to ask us when looking into the translation unit's decl.
|
2010-10-16 06:48:33 +08:00
|
|
|
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
|
|
|
)
|
|
|
|
{
|
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_decl_map.GetImportInProgress())
|
|
|
|
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
|
|
|
|
|
|
|
// These aren't looked up like this.
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
return DeclContext::lookup_result();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
if (!m_decl_map.GetLookupsEnabled())
|
|
|
|
{
|
|
|
|
// 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] == '$')
|
|
|
|
{
|
2010-12-03 09:38:59 +08:00
|
|
|
m_decl_map.SetLookupsEnabled ();
|
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-12 08:12:34 +08:00
|
|
|
m_decl_map.FindExternalVisibleDecls(name_search_context, const_decl_name);
|
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
|
|
|
|
ClangASTSource::CompleteType (TagDecl *tag_decl)
|
|
|
|
{
|
2011-07-30 10:42:06 +08:00
|
|
|
m_decl_map.CompleteTagDecl (tag_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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClangASTSource::CompleteType (ObjCInterfaceDecl *objc_decl)
|
|
|
|
{
|
2011-07-30 10:42:06 +08:00
|
|
|
m_decl_map.CompleteObjCInterfaceDecl (objc_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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClangASTSource::MaterializeVisibleDecls(const DeclContext *DC)
|
2010-09-23 11:01:22 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// This is used to support iterating through an entire lexical context,
|
|
|
|
// which isn't something the debugger should ever need to do.
|
2011-07-30 10:42:06 +08:00
|
|
|
clang::ExternalLoadResult
|
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::FindExternalLexicalDecls
|
|
|
|
(
|
|
|
|
const DeclContext *DC,
|
|
|
|
bool (*isKindWeWant)(Decl::Kind),
|
|
|
|
llvm::SmallVectorImpl<Decl*> &Decls
|
|
|
|
)
|
|
|
|
{
|
2011-07-30 10:42:06 +08:00
|
|
|
return m_decl_map.FindExternalLexicalDecls (DC, isKindWeWant, Decls);
|
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
|
|
|
clang::ASTContext *
|
|
|
|
NameSearchContext::GetASTContext()
|
|
|
|
{
|
2010-10-16 06:48:33 +08:00
|
|
|
return &m_ast_source.m_ast_context;
|
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
|
|
|
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
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
clang::NamedDecl *Decl = VarDecl::Create(m_ast_source.m_ast_context,
|
|
|
|
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)
|
|
|
|
{
|
2010-10-16 06:48:33 +08:00
|
|
|
clang::FunctionDecl *func_decl = FunctionDecl::Create (m_ast_source.m_ast_context,
|
|
|
|
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-08 07:18:13 +08:00
|
|
|
parm_var_decls.push_back(ParmVarDecl::Create (m_ast_source.m_ast_context,
|
|
|
|
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-05-13 07:54:16 +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
|
2011-01-19 07:32:05 +08:00
|
|
|
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);
|
|
|
|
}
|