diff options
Diffstat (limited to 'lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp')
-rw-r--r-- | lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp | 162 |
1 files changed, 69 insertions, 93 deletions
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp index 0b819948115..3c20b516c10 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp @@ -18,118 +18,94 @@ 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::Decl *decl) { + clang::DeclContext *decl_ctx = llvm::dyn_cast<clang::DeclContext>(decl); + + bool has_external_lexical_storage; + bool 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(); - + 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); - - 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>"); - } - + } + + 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 (const clang::Type *type) -{ - m_dump = clang::QualType(type, 0).getAsString(); -} +ASTDumper::ASTDumper(clang::DeclContext *decl_ctx) { + bool has_external_lexical_storage = decl_ctx->hasExternalLexicalStorage(); + bool has_external_visible_storage = decl_ctx->hasExternalVisibleStorage(); -ASTDumper::ASTDumper (clang::QualType type) -{ - m_dump = type.getAsString(); -} + 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>"); + } -ASTDumper::ASTDumper (lldb::opaque_compiler_type_t type) -{ - m_dump = clang::QualType::getFromOpaquePtr(type).getAsString(); + decl_ctx->setHasExternalLexicalStorage(has_external_lexical_storage); + decl_ctx->setHasExternalVisibleStorage(has_external_visible_storage); } -ASTDumper::ASTDumper (const CompilerType &compiler_type) -{ - m_dump = ClangUtil::GetQualType(compiler_type).getAsString(); +ASTDumper::ASTDumper(const clang::Type *type) { + m_dump = clang::QualType(type, 0).getAsString(); } +ASTDumper::ASTDumper(clang::QualType type) { m_dump = type.getAsString(); } -const char * -ASTDumper::GetCString() -{ - return m_dump.c_str(); +ASTDumper::ASTDumper(lldb::opaque_compiler_type_t type) { + m_dump = clang::QualType::getFromOpaquePtr(type).getAsString(); } -void ASTDumper::ToSTDERR() -{ - fprintf(stderr, "%s\n", m_dump.c_str()); +ASTDumper::ASTDumper(const CompilerType &compiler_type) { + m_dump = ClangUtil::GetQualType(compiler_type).getAsString(); } -void ASTDumper::ToLog(Log *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'); - } - +const char *ASTDumper::GetCString() { return m_dump.c_str(); } + +void ASTDumper::ToSTDERR() { fprintf(stderr, "%s\n", m_dump.c_str()); } + +void ASTDumper::ToLog(Log *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); - - free(alloc); + + *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()); +void ASTDumper::ToStream(lldb::StreamSP &stream) { + stream->PutCString(m_dump.c_str()); } |