[Frontend] Delete -print-decl-contexts

Summary: Its job is covered by -ast-dump. The option is rarely used and lacks many AST nodes which will lead to llvm_unreachable() crash.

Reviewers: rsmith, arphaman

Reviewed By: rsmith

Subscribers: jfb, cfe-commits

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

llvm-svn: 343660
This commit is contained in:
Fangrui Song 2018-10-03 03:50:44 +00:00
parent 3d76d36059
commit 65ebd13f41
9 changed files with 0 additions and 360 deletions

View File

@ -540,8 +540,6 @@ def ast_dump_lookups : Flag<["-"], "ast-dump-lookups">,
HelpText<"Build ASTs and then debug dump their name lookup tables">;
def ast_view : Flag<["-"], "ast-view">,
HelpText<"Build ASTs and view them with GraphViz">;
def print_decl_contexts : Flag<["-"], "print-decl-contexts">,
HelpText<"Print DeclContexts and their Decls">;
def emit_module : Flag<["-"], "emit-module">,
HelpText<"Generate pre-compiled module file from a module map">;
def emit_module_interface : Flag<["-"], "emit-module-interface">,

View File

@ -50,10 +50,6 @@ std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister();
// function declarations to stderr.
std::unique_ptr<ASTConsumer> CreateASTViewer();
// DeclContext printer: prints out the DeclContext tree in human-readable form
// to stderr; this is intended for debugging.
std::unique_ptr<ASTConsumer> CreateDeclContextPrinter();
} // end clang namespace
#endif

View File

@ -106,9 +106,6 @@ enum ActionKind {
/// Run a plugin action, \see ActionName.
PluginAction,
/// Print DeclContext and their Decls.
PrintDeclContext,
/// Print the "preamble" of the input file
PrintPreamble,

View File

@ -193,342 +193,3 @@ void ASTViewer::HandleTopLevelSingleDecl(Decl *D) {
std::unique_ptr<ASTConsumer> clang::CreateASTViewer() {
return llvm::make_unique<ASTViewer>();
}
//===----------------------------------------------------------------------===//
/// DeclContextPrinter - Decl and DeclContext Visualization
namespace {
class DeclContextPrinter : public ASTConsumer {
raw_ostream& Out;
public:
DeclContextPrinter() : Out(llvm::errs()) {}
void HandleTranslationUnit(ASTContext &C) override {
PrintDeclContext(C.getTranslationUnitDecl(), 4);
}
void PrintDeclContext(const DeclContext* DC, unsigned Indentation);
};
} // end anonymous namespace
void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
unsigned Indentation) {
// Print DeclContext name.
switch (DC->getDeclKind()) {
case Decl::TranslationUnit:
Out << "[translation unit] " << DC;
break;
case Decl::Namespace: {
Out << "[namespace] ";
const NamespaceDecl* ND = cast<NamespaceDecl>(DC);
Out << *ND;
break;
}
case Decl::Enum: {
const EnumDecl* ED = cast<EnumDecl>(DC);
if (ED->isCompleteDefinition())
Out << "[enum] ";
else
Out << "<enum> ";
Out << *ED;
break;
}
case Decl::Record: {
const RecordDecl* RD = cast<RecordDecl>(DC);
if (RD->isCompleteDefinition())
Out << "[struct] ";
else
Out << "<struct> ";
Out << *RD;
break;
}
case Decl::CXXRecord: {
const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC);
if (RD->isCompleteDefinition())
Out << "[class] ";
else
Out << "<class> ";
Out << *RD << ' ' << DC;
break;
}
case Decl::ObjCMethod:
Out << "[objc method]";
break;
case Decl::ObjCInterface:
Out << "[objc interface]";
break;
case Decl::ObjCCategory:
Out << "[objc category]";
break;
case Decl::ObjCProtocol:
Out << "[objc protocol]";
break;
case Decl::ObjCImplementation:
Out << "[objc implementation]";
break;
case Decl::ObjCCategoryImpl:
Out << "[objc categoryimpl]";
break;
case Decl::LinkageSpec:
Out << "[linkage spec]";
break;
case Decl::Block:
Out << "[block]";
break;
case Decl::Function: {
const FunctionDecl* FD = cast<FunctionDecl>(DC);
if (FD->doesThisDeclarationHaveABody())
Out << "[function] ";
else
Out << "<function> ";
Out << *FD;
// Print the parameters.
Out << "(";
bool PrintComma = false;
for (auto I : FD->parameters()) {
if (PrintComma)
Out << ", ";
else
PrintComma = true;
Out << *I;
}
Out << ")";
break;
}
case Decl::CXXMethod: {
const CXXMethodDecl* D = cast<CXXMethodDecl>(DC);
if (D->isOutOfLine())
Out << "[c++ method] ";
else if (D->isImplicit())
Out << "(c++ method) ";
else
Out << "<c++ method> ";
Out << *D;
// Print the parameters.
Out << "(";
bool PrintComma = false;
for (ParmVarDecl *Parameter : D->parameters()) {
if (PrintComma)
Out << ", ";
else
PrintComma = true;
Out << *Parameter;
}
Out << ")";
// Check the semantic DeclContext.
const DeclContext* SemaDC = D->getDeclContext();
const DeclContext* LexicalDC = D->getLexicalDeclContext();
if (SemaDC != LexicalDC)
Out << " [[" << SemaDC << "]]";
break;
}
case Decl::CXXConstructor: {
const CXXConstructorDecl* D = cast<CXXConstructorDecl>(DC);
if (D->isOutOfLine())
Out << "[c++ ctor] ";
else if (D->isImplicit())
Out << "(c++ ctor) ";
else
Out << "<c++ ctor> ";
Out << *D;
// Print the parameters.
Out << "(";
bool PrintComma = false;
for (ParmVarDecl *Parameter : D->parameters()) {
if (PrintComma)
Out << ", ";
else
PrintComma = true;
Out << *Parameter;
}
Out << ")";
// Check the semantic DC.
const DeclContext* SemaDC = D->getDeclContext();
const DeclContext* LexicalDC = D->getLexicalDeclContext();
if (SemaDC != LexicalDC)
Out << " [[" << SemaDC << "]]";
break;
}
case Decl::CXXDestructor: {
const CXXDestructorDecl* D = cast<CXXDestructorDecl>(DC);
if (D->isOutOfLine())
Out << "[c++ dtor] ";
else if (D->isImplicit())
Out << "(c++ dtor) ";
else
Out << "<c++ dtor> ";
Out << *D;
// Check the semantic DC.
const DeclContext* SemaDC = D->getDeclContext();
const DeclContext* LexicalDC = D->getLexicalDeclContext();
if (SemaDC != LexicalDC)
Out << " [[" << SemaDC << "]]";
break;
}
case Decl::CXXConversion: {
const CXXConversionDecl* D = cast<CXXConversionDecl>(DC);
if (D->isOutOfLine())
Out << "[c++ conversion] ";
else if (D->isImplicit())
Out << "(c++ conversion) ";
else
Out << "<c++ conversion> ";
Out << *D;
// Check the semantic DC.
const DeclContext* SemaDC = D->getDeclContext();
const DeclContext* LexicalDC = D->getLexicalDeclContext();
if (SemaDC != LexicalDC)
Out << " [[" << SemaDC << "]]";
break;
}
case Decl::ClassTemplateSpecialization: {
const auto *CTSD = cast<ClassTemplateSpecializationDecl>(DC);
if (CTSD->isCompleteDefinition())
Out << "[class template specialization] ";
else
Out << "<class template specialization> ";
Out << *CTSD;
break;
}
case Decl::ClassTemplatePartialSpecialization: {
const auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl>(DC);
if (CTPSD->isCompleteDefinition())
Out << "[class template partial specialization] ";
else
Out << "<class template partial specialization> ";
Out << *CTPSD;
break;
}
default:
llvm_unreachable("a decl that inherits DeclContext isn't handled");
}
Out << "\n";
// Print decls in the DeclContext.
for (auto *I : DC->decls()) {
for (unsigned i = 0; i < Indentation; ++i)
Out << " ";
Decl::Kind DK = I->getKind();
switch (DK) {
case Decl::Namespace:
case Decl::Enum:
case Decl::Record:
case Decl::CXXRecord:
case Decl::ObjCMethod:
case Decl::ObjCInterface:
case Decl::ObjCCategory:
case Decl::ObjCProtocol:
case Decl::ObjCImplementation:
case Decl::ObjCCategoryImpl:
case Decl::LinkageSpec:
case Decl::Block:
case Decl::Function:
case Decl::CXXMethod:
case Decl::CXXConstructor:
case Decl::CXXDestructor:
case Decl::CXXConversion:
case Decl::ClassTemplateSpecialization:
case Decl::ClassTemplatePartialSpecialization: {
DeclContext* DC = cast<DeclContext>(I);
PrintDeclContext(DC, Indentation+2);
break;
}
case Decl::IndirectField:
Out << "<IndirectField> " << *cast<IndirectFieldDecl>(I) << '\n';
break;
case Decl::Label:
Out << "<Label> " << *cast<LabelDecl>(I) << '\n';
break;
case Decl::Field:
Out << "<field> " << *cast<FieldDecl>(I) << '\n';
break;
case Decl::Typedef:
case Decl::TypeAlias:
Out << "<typedef> " << *cast<TypedefNameDecl>(I) << '\n';
break;
case Decl::EnumConstant:
Out << "<enum constant> " << *cast<EnumConstantDecl>(I) << '\n';
break;
case Decl::Var:
Out << "<var> " << *cast<VarDecl>(I) << '\n';
break;
case Decl::ImplicitParam:
Out << "<implicit parameter> " << *cast<ImplicitParamDecl>(I) << '\n';
break;
case Decl::ParmVar:
Out << "<parameter> " << *cast<ParmVarDecl>(I) << '\n';
break;
case Decl::ObjCProperty:
Out << "<objc property> " << *cast<ObjCPropertyDecl>(I) << '\n';
break;
case Decl::FunctionTemplate:
Out << "<function template> " << *cast<FunctionTemplateDecl>(I) << '\n';
break;
case Decl::TypeAliasTemplate:
Out << "<type alias template> " << *cast<TypeAliasTemplateDecl>(I)
<< '\n';
break;
case Decl::FileScopeAsm:
Out << "<file-scope asm>\n";
break;
case Decl::UsingDirective:
Out << "<using directive>\n";
break;
case Decl::NamespaceAlias:
Out << "<namespace alias> " << *cast<NamespaceAliasDecl>(I) << '\n';
break;
case Decl::ClassTemplate:
Out << "<class template> " << *cast<ClassTemplateDecl>(I) << '\n';
break;
case Decl::OMPThreadPrivate: {
Out << "<omp threadprivate> " << '"' << I << "\"\n";
break;
}
case Decl::Friend: {
Out << "<friend>";
if (const NamedDecl *ND = cast<FriendDecl>(I)->getFriendDecl())
Out << ' ' << *ND;
Out << "\n";
break;
}
case Decl::Using:
Out << "<using> " << *cast<UsingDecl>(I) << "\n";
break;
case Decl::UsingShadow:
Out << "<using shadow> " << *cast<UsingShadowDecl>(I) << "\n";
break;
case Decl::UnresolvedUsingValue:
Out << "<unresolved using value> " << *cast<UnresolvedUsingValueDecl>(I)
<< "\n";
break;
case Decl::Empty:
Out << "<empty>\n";
break;
case Decl::AccessSpec:
Out << "<access specifier>\n";
break;
case Decl::VarTemplate:
Out << "<var template> " << *cast<VarTemplateDecl>(I) << "\n";
break;
case Decl::StaticAssert:
Out << "<static assert>\n";
break;
default:
Out << "DeclKind: " << DK << '"' << I << "\"\n";
llvm_unreachable("decl unhandled");
}
}
}
std::unique_ptr<ASTConsumer> clang::CreateDeclContextPrinter() {
return llvm::make_unique<DeclContextPrinter>();
}

View File

@ -1469,8 +1469,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.ProgramAction = frontend::ModuleFileInfo; break;
case OPT_verify_pch:
Opts.ProgramAction = frontend::VerifyPCH; break;
case OPT_print_decl_contexts:
Opts.ProgramAction = frontend::PrintDeclContext; break;
case OPT_print_preamble:
Opts.ProgramAction = frontend::PrintPreamble; break;
case OPT_E:
@ -2840,7 +2838,6 @@ static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
case frontend::ModuleFileInfo:
case frontend::VerifyPCH:
case frontend::PluginAction:
case frontend::PrintDeclContext:
case frontend::RewriteObjC:
case frontend::RewriteTest:
case frontend::RunAnalysis:

View File

@ -91,12 +91,6 @@ ASTViewAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
return CreateASTViewer();
}
std::unique_ptr<ASTConsumer>
DeclContextPrintAction::CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) {
return CreateDeclContextPrinter();
}
std::unique_ptr<ASTConsumer>
GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
std::string Sysroot;

View File

@ -90,7 +90,6 @@ CreateFrontendBaseAction(CompilerInstance &CI) {
return nullptr;
}
case PrintDeclContext: return llvm::make_unique<DeclContextPrintAction>();
case PrintPreamble: return llvm::make_unique<PrintPreambleAction>();
case PrintPreprocessedInput: {
if (CI.getPreprocessorOutputOpts().RewriteIncludes ||

View File

@ -4,6 +4,5 @@
// RUN: diff %t.1.c %t.2.c
// RUN: %clang_cc1 -ast-dump %s
// RUN: %clang_cc1 -ast-dump-all %s
// RUN: %clang_cc1 -print-decl-contexts %s
#include "c-language-features.inc"

View File

@ -4,7 +4,6 @@
// RUN: diff %t.1.cpp %t.2.cpp
// RUN: %clang_cc1 -std=c++14 -ast-dump %s
// RUN: %clang_cc1 -std=c++14 -ast-dump-all %s
// RUN: %clang_cc1 -std=c++14 -print-decl-contexts %s
// RUN: %clang_cc1 -std=c++14 -fdump-record-layouts %s
#include "cxx-language-features.inc"