r343660 - [Frontend] Delete -print-decl-contexts

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 20:50:44 PDT 2018


Author: maskray
Date: Tue Oct  2 20:50:44 2018
New Revision: 343660

URL: http://llvm.org/viewvc/llvm-project?rev=343660&view=rev
Log:
[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

Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Frontend/ASTConsumers.h
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/lib/Frontend/ASTConsumers.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
    cfe/trunk/test/Coverage/ast-printing.c
    cfe/trunk/test/Coverage/ast-printing.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Oct  2 20:50:44 2018
@@ -540,8 +540,6 @@ def ast_dump_lookups : Flag<["-"], "ast-
   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">,

Modified: cfe/trunk/include/clang/Frontend/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTConsumers.h?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTConsumers.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTConsumers.h Tue Oct  2 20:50:44 2018
@@ -50,10 +50,6 @@ std::unique_ptr<ASTConsumer> CreateASTDe
 // 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

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Tue Oct  2 20:50:44 2018
@@ -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,
 

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Tue Oct  2 20:50:44 2018
@@ -193,342 +193,3 @@ void ASTViewer::HandleTopLevelSingleDecl
 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>();
-}

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Oct  2 20:50:44 2018
@@ -1469,8 +1469,6 @@ static InputKind ParseFrontendArgs(Front
       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
   case frontend::ModuleFileInfo:
   case frontend::VerifyPCH:
   case frontend::PluginAction:
-  case frontend::PrintDeclContext:
   case frontend::RewriteObjC:
   case frontend::RewriteTest:
   case frontend::RunAnalysis:

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Oct  2 20:50:44 2018
@@ -92,12 +92,6 @@ ASTViewAction::CreateASTConsumer(Compile
 }
 
 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;
   if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot))

Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Tue Oct  2 20:50:44 2018
@@ -90,7 +90,6 @@ CreateFrontendBaseAction(CompilerInstanc
     return nullptr;
   }
 
-  case PrintDeclContext:       return llvm::make_unique<DeclContextPrintAction>();
   case PrintPreamble:          return llvm::make_unique<PrintPreambleAction>();
   case PrintPreprocessedInput: {
     if (CI.getPreprocessorOutputOpts().RewriteIncludes ||

Modified: cfe/trunk/test/Coverage/ast-printing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.c?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/ast-printing.c (original)
+++ cfe/trunk/test/Coverage/ast-printing.c Tue Oct  2 20:50:44 2018
@@ -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"

Modified: cfe/trunk/test/Coverage/ast-printing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.cpp?rev=343660&r1=343659&r2=343660&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/ast-printing.cpp (original)
+++ cfe/trunk/test/Coverage/ast-printing.cpp Tue Oct  2 20:50:44 2018
@@ -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"




More information about the cfe-commits mailing list