Files
clang-p2996/lldb/source/Plugins/ExpressionParser/Clang/ASTDumper.cpp
Konrad Kleine 248a13057a [lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]

This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.

This is the command I ran and I to fix and format the code base:

```
run-clang-tidy.py \
	-header-filter='.*' \
	-checks='-*,modernize-use-nullptr' \
	-fix ~/dev/llvm-project/lldb/.* \
	-format \
	-style LLVM \
	-p ~/llvm-builds/debug-ninja-gcc
```

NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.

NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.

Reviewers: martong, espindola, shafik, #lldb, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits

Tags: #lldb, #llvm

Differential Revision: https://reviews.llvm.org/D61847

llvm-svn: 361484
2019-05-23 11:14:47 +00:00

109 lines
3.0 KiB
C++

//===-- ASTDumper.cpp -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "ASTDumper.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangUtil.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Utility/Log.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::opaque_compiler_type_t type) {
m_dump = clang::QualType::getFromOpaquePtr(type).getAsString();
}
ASTDumper::ASTDumper(const CompilerType &compiler_type) {
m_dump = ClangUtil::GetQualType(compiler_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(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 = nullptr;
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); }