2011-02-02 07:43:26 +08:00
|
|
|
//===-- ASTDumper.cpp -------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2011-02-02 07:43:26 +08:00
|
|
|
#include "lldb/Expression/ASTDumper.h"
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
using namespace lldb_private;
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
ASTDumper::ASTDumper (clang::Decl *decl)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
clang::DeclContext *decl_ctx = llvm::dyn_cast<clang::DeclContext>(decl);
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
bool has_external_lexical_storage;
|
|
|
|
bool has_external_visible_storage;
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
if (decl_ctx)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
|
|
|
|
has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
|
|
|
|
decl_ctx->setHasExternalLexicalStorage(false);
|
|
|
|
decl_ctx->setHasExternalVisibleStorage(false);
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
llvm::raw_string_ostream os(m_dump);
|
|
|
|
decl->print (os);
|
|
|
|
os.flush();
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
if (decl_ctx)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
|
|
|
|
decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
ASTDumper::ASTDumper (clang::DeclContext *decl_ctx)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
bool has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage();
|
|
|
|
bool has_external_visible_storage = decl_ctx->hasExternalVisibleStorage();
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
decl_ctx->setHasExternalLexicalStorage(false);
|
|
|
|
decl_ctx->setHasExternalVisibleStorage(false);
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
if (clang::Decl *decl = llvm::dyn_cast<clang::Decl>(decl_ctx))
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
llvm::raw_string_ostream os(m_dump);
|
|
|
|
decl->print (os);
|
|
|
|
os.flush();
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
m_dump.assign("<DeclContext is not a Decl>");
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage);
|
|
|
|
decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage);
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-11-15 10:11:17 +08:00
|
|
|
ASTDumper::ASTDumper (const clang::Type *type)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
m_dump = clang::QualType(type, 0).getAsString();
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
ASTDumper::ASTDumper (clang::QualType type)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
m_dump = type.getAsString();
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
ASTDumper::ASTDumper (lldb::clang_type_t type)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
m_dump = clang::QualType::getFromOpaquePtr(type).getAsString();
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-20 08:47:21 +08:00
|
|
|
const char *
|
|
|
|
ASTDumper::GetCString()
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-20 08:47:21 +08:00
|
|
|
return m_dump.c_str();
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
void ASTDumper::ToSTDERR()
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
fprintf(stderr, "%s\n", m_dump.c_str());
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
void ASTDumper::ToLog(Log *log, const char *prefix)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
size_t len = m_dump.length() + 1;
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
char *alloc = (char*)malloc(len);
|
|
|
|
char *str = alloc;
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
memcpy(str, m_dump.c_str(), len);
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
char *end = NULL;
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
end = strchr(str, '\n');
|
2011-02-02 07:43:26 +08:00
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
while (end)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
*end = '\0';
|
|
|
|
|
|
|
|
log->Printf("%s%s", prefix, str);
|
|
|
|
|
|
|
|
*end = '\n';
|
|
|
|
|
|
|
|
str = end + 1;
|
|
|
|
end = strchr(str, '\n');
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
log->Printf("%s%s", prefix, str);
|
|
|
|
|
|
|
|
free(alloc);
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|
|
|
|
|
2011-10-19 00:46:55 +08:00
|
|
|
void ASTDumper::ToStream(lldb::StreamSP &stream)
|
2011-02-02 07:43:26 +08:00
|
|
|
{
|
2011-10-19 00:46:55 +08:00
|
|
|
stream->PutCString(m_dump.c_str());
|
2011-02-02 07:43:26 +08:00
|
|
|
}
|