Files
llvm-project/lldb/source/Expression/ASTDumper.cpp
Sean Callanan d5c17edb04 Pulled in a new version of LLVM/Clang to solve a variety
of problems with Objective-C object completion.  To go
along with the LLVM/Clang-side fixes, we have a variety
of Objective-C improvements.

Fixes include:

- It is now possible to run expressions when stopped in
  an Objective-C class method and have "self" act just
  like "self" would act in the class method itself (i.e.,
  [self classMethod] works without casting the return
  type if debug info is present).  To accomplish this,
  the expression masquerades as a class method added by
  a category.

- Objective-C objects can now provide methods and
  properties and methods to Clang on demand (i.e., the
  ASTImporter sets hasExternalVisibleDecls on Objective-C
  interface objects).

- Objective-C built-in types, which had long been a bone
  of contention (should we be using "id"?  "id*"?), are
  now fetched correctly using accessor functions on
  ClangASTContext.  We inhibit searches for them in the
  debug information.

There are also a variety of logging fixes, and I made two
changes to the test suite:

- Enabled a test case for Objective-C properties in the
  current translation unit.

- Added a test case for calling Objective-C class methods
  when stopped in a class method.

llvm-svn: 144607
2011-11-15 02:11:17 +00:00

126 lines
3.0 KiB
C++

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