2011-06-25 08:44:06 +08:00
|
|
|
//===-- ClangASTImporter.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Decl.h"
|
2011-07-30 10:42:06 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
2011-10-22 07:04:20 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2011-06-25 08:44:06 +08:00
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
|
|
|
#include "lldb/Symbol/ClangASTImporter.h"
|
2011-10-22 06:18:07 +08:00
|
|
|
#include "lldb/Symbol/ClangNamespaceDecl.h"
|
2011-06-25 08:44:06 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
clang::QualType
|
|
|
|
ClangASTImporter::CopyType (clang::ASTContext *src_ast,
|
|
|
|
clang::QualType type)
|
|
|
|
{
|
2011-07-07 02:55:08 +08:00
|
|
|
MinionSP minion_sp (GetMinion(src_ast, false));
|
2011-07-30 10:42:06 +08:00
|
|
|
|
2011-07-07 02:55:08 +08:00
|
|
|
if (minion_sp)
|
|
|
|
return minion_sp->Import(type);
|
2011-07-30 10:42:06 +08:00
|
|
|
|
2011-07-07 02:55:08 +08:00
|
|
|
return QualType();
|
2011-06-25 08:44:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
clang::Decl *
|
|
|
|
ClangASTImporter::CopyDecl (clang::ASTContext *src_ast,
|
|
|
|
clang::Decl *decl)
|
|
|
|
{
|
2011-07-07 02:55:08 +08:00
|
|
|
MinionSP minion_sp;
|
2011-06-25 08:44:06 +08:00
|
|
|
|
|
|
|
if (isa<clang::NamespaceDecl>(decl))
|
2011-07-07 02:55:08 +08:00
|
|
|
minion_sp = GetMinion(src_ast, true);
|
2011-06-25 08:44:06 +08:00
|
|
|
else
|
2011-07-07 02:55:08 +08:00
|
|
|
minion_sp = GetMinion(src_ast, false);
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-07 02:55:08 +08:00
|
|
|
if (minion_sp)
|
2011-11-05 06:46:46 +08:00
|
|
|
{
|
|
|
|
clang::Decl *result = minion_sp->Import(decl);
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
|
|
|
|
2011-11-05 08:08:12 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
|
|
|
|
log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s'", decl->getDeclKindName(), named_decl->getNameAsString().c_str());
|
|
|
|
else
|
|
|
|
log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s", decl->getDeclKindName());
|
|
|
|
}
|
2011-11-05 06:46:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-07-30 10:42:06 +08:00
|
|
|
|
2011-07-07 02:55:08 +08:00
|
|
|
return NULL;
|
2011-06-25 08:44:06 +08:00
|
|
|
}
|
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
void
|
|
|
|
ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
|
|
|
|
{
|
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
|
|
|
|
|
|
|
DeclOrigin decl_origin = GetDeclOrigin(decl);
|
|
|
|
|
|
|
|
if (!decl_origin.Valid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
|
|
|
|
|
|
|
|
if (minion_sp)
|
|
|
|
minion_sp->ImportDefinition(decl_origin.decl);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
|
2011-06-25 08:44:06 +08:00
|
|
|
{
|
2011-07-30 10:42:06 +08:00
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
|
|
|
|
|
|
|
DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
if (!decl_origin.Valid())
|
|
|
|
return;
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
|
|
|
|
return;
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
MinionSP minion_sp (GetMinion(decl_origin.ctx, false));
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-07 02:55:08 +08:00
|
|
|
if (minion_sp)
|
2011-07-30 10:42:06 +08:00
|
|
|
minion_sp->ImportDefinition(decl_origin.decl);
|
2011-06-25 08:44:06 +08:00
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
return;
|
2011-06-25 08:44:06 +08:00
|
|
|
}
|
2011-07-30 10:42:06 +08:00
|
|
|
|
2011-10-12 08:12:34 +08:00
|
|
|
void
|
|
|
|
ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
|
|
|
|
NamespaceMapSP &namespace_map)
|
|
|
|
{
|
|
|
|
m_namespace_maps[decl] = namespace_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangASTImporter::NamespaceMapSP
|
|
|
|
ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
|
|
|
|
{
|
|
|
|
NamespaceMetaMap::iterator iter = m_namespace_maps.find(decl);
|
|
|
|
|
|
|
|
if (iter != m_namespace_maps.end())
|
|
|
|
return iter->second;
|
|
|
|
else
|
|
|
|
return NamespaceMapSP();
|
|
|
|
}
|
|
|
|
|
2011-10-22 06:18:07 +08:00
|
|
|
void
|
|
|
|
ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
|
|
|
|
{
|
|
|
|
const DeclContext *parent_context = decl->getDeclContext();
|
|
|
|
const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
|
|
|
|
NamespaceMapSP parent_map;
|
|
|
|
|
|
|
|
if (parent_namespace)
|
|
|
|
parent_map = GetNamespaceMap(parent_namespace);
|
|
|
|
|
|
|
|
NamespaceMapSP new_map;
|
|
|
|
|
|
|
|
new_map.reset(new NamespaceMap);
|
|
|
|
|
|
|
|
if (m_map_completer)
|
|
|
|
{
|
|
|
|
std::string namespace_string = decl->getDeclName().getAsString();
|
|
|
|
|
|
|
|
m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterNamespaceMap (decl, new_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangASTImporter::NamespaceMapCompleter::~NamespaceMapCompleter ()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
clang::Decl
|
|
|
|
*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
|
|
|
|
{
|
|
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
|
|
|
|
|
|
|
m_master.m_origins[to] = DeclOrigin (m_source_ctx, from);
|
|
|
|
|
|
|
|
if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
|
|
|
|
{
|
|
|
|
TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
|
|
|
|
|
|
|
|
to_tag_decl->setHasExternalLexicalStorage();
|
2011-11-10 03:33:21 +08:00
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
if (log)
|
2011-11-10 03:33:21 +08:00
|
|
|
log->Printf(" [ClangASTImporter] Imported %p, a %s named %s%s%s [%s->%s]",
|
|
|
|
to,
|
|
|
|
((clang::Decl*)from_tag_decl)->getDeclKindName(),
|
2011-07-30 10:42:06 +08:00
|
|
|
from_tag_decl->getName().str().c_str(),
|
|
|
|
(to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
|
2011-11-10 03:33:21 +08:00
|
|
|
(to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
|
|
|
|
(from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
|
|
|
|
(to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
|
2011-07-30 10:42:06 +08:00
|
|
|
}
|
|
|
|
|
2011-10-22 06:18:07 +08:00
|
|
|
if (isa<NamespaceDecl>(from))
|
|
|
|
{
|
|
|
|
NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
|
|
|
|
|
|
|
|
m_master.BuildNamespaceMap(to_namespace_decl);
|
|
|
|
|
|
|
|
to_namespace_decl->setHasExternalVisibleStorage();
|
|
|
|
}
|
|
|
|
|
2011-07-30 10:42:06 +08:00
|
|
|
if (isa<ObjCInterfaceDecl>(from))
|
|
|
|
{
|
|
|
|
ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
|
|
|
|
|
2011-11-10 03:33:21 +08:00
|
|
|
to_interface_decl->setHasExternalVisibleStorage();
|
|
|
|
|
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
|
|
|
if (!to_interface_decl->isForwardDecl())
|
|
|
|
to_interface_decl->setExternallyCompleted();
|
2011-07-30 10:42:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return clang::ASTImporter::Imported(from, to);
|
2011-08-10 10:10:13 +08:00
|
|
|
}
|