MaskRay updated this revision to Diff 167842. MaskRay added a comment. Coverage/ast-printing.{c,cpp} contain other dumping tests. Don't delete them
Repository: rC Clang https://reviews.llvm.org/D52529 Files: include/clang/Driver/CC1Options.td include/clang/Frontend/ASTConsumers.h include/clang/Frontend/FrontendOptions.h lib/Frontend/ASTConsumers.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/FrontendActions.cpp lib/FrontendTool/ExecuteCompilerInvocation.cpp test/Coverage/ast-printing.c test/Coverage/ast-printing.cpp
Index: test/Coverage/ast-printing.cpp =================================================================== --- test/Coverage/ast-printing.cpp +++ test/Coverage/ast-printing.cpp @@ -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" Index: test/Coverage/ast-printing.c =================================================================== --- test/Coverage/ast-printing.c +++ test/Coverage/ast-printing.c @@ -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" Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp =================================================================== --- lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -90,7 +90,6 @@ return nullptr; } - case PrintDeclContext: return llvm::make_unique<DeclContextPrintAction>(); case PrintPreamble: return llvm::make_unique<PrintPreambleAction>(); case PrintPreprocessedInput: { if (CI.getPreprocessorOutputOpts().RewriteIncludes || Index: lib/Frontend/FrontendActions.cpp =================================================================== --- lib/Frontend/FrontendActions.cpp +++ lib/Frontend/FrontendActions.cpp @@ -91,12 +91,6 @@ 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; Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1468,8 +1468,6 @@ 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: @@ -2839,7 +2837,6 @@ case frontend::ModuleFileInfo: case frontend::VerifyPCH: case frontend::PluginAction: - case frontend::PrintDeclContext: case frontend::RewriteObjC: case frontend::RewriteTest: case frontend::RunAnalysis: Index: lib/Frontend/ASTConsumers.cpp =================================================================== --- lib/Frontend/ASTConsumers.cpp +++ lib/Frontend/ASTConsumers.cpp @@ -193,342 +193,3 @@ 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>(); -} Index: include/clang/Frontend/FrontendOptions.h =================================================================== --- include/clang/Frontend/FrontendOptions.h +++ include/clang/Frontend/FrontendOptions.h @@ -106,9 +106,6 @@ /// Run a plugin action, \see ActionName. PluginAction, - /// Print DeclContext and their Decls. - PrintDeclContext, - /// Print the "preamble" of the input file PrintPreamble, Index: include/clang/Frontend/ASTConsumers.h =================================================================== --- include/clang/Frontend/ASTConsumers.h +++ include/clang/Frontend/ASTConsumers.h @@ -50,10 +50,6 @@ // 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 Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -537,8 +537,6 @@ 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">,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits