[cfe-commits] r88820 - in /cfe/trunk: include/clang/Frontend/FrontendOptions.h tools/clang-cc/Options.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Sat Nov 14 14:32:39 PST 2009


Author: ddunbar
Date: Sat Nov 14 16:32:38 2009
New Revision: 88820

URL: http://llvm.org/viewvc/llvm-project?rev=88820&view=rev
Log:
Move the program action enum to FrontendOptions.

--
ddunbar at giles:clang-cc (master)$ grep llvm::cl::opt clang-cc.cpp  # Woot
ddunbar at giles:clang-cc (master)$
--

Modified:
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/tools/clang-cc/Options.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=88820&r1=88819&r2=88820&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Sat Nov 14 16:32:38 2009
@@ -17,6 +17,39 @@
 
 namespace clang {
 
+namespace frontend {
+  enum ActionKind {
+    ASTDump,                ///< Parse ASTs and dump them.
+    ASTPrint,               ///< Parse ASTs and print them.
+    ASTPrintXML,            ///< Parse ASTs and print them in XML.
+    ASTView,                ///< Parse ASTs and view them in Graphviz.
+    DumpRawTokens,          ///< Dump out raw tokens.
+    DumpRecordLayouts,      ///< Dump record layout information.
+    DumpTokens,             ///< Dump out preprocessed tokens.
+    EmitAssembly,           ///< Emit a .s file.
+    EmitBC,                 ///< Emit a .bc file.
+    EmitHTML,               ///< Translate input source into HTML.
+    EmitLLVM,               ///< Emit a .ll file.
+    EmitLLVMOnly,           ///< Generate LLVM IR, but do not
+    FixIt,                  ///< Parse and apply any fixits to the source.
+    GeneratePCH,            ///< Generate pre-compiled header.
+    GeneratePTH,            ///< Generate pre-tokenized header.
+    HTMLTest,               ///< HTML displayer testing stuff.
+    InheritanceView,        ///< View C++ inheritance for a specified class.
+    ParseNoop,              ///< Parse with noop callbacks.
+    ParsePrintCallbacks,    ///< Parse and print each callback.
+    ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
+    PrintDeclContext,       ///< Print DeclContext and their Decls.
+    PrintPreprocessedInput, ///< -E mode.
+    RewriteBlocks,          ///< ObjC->C Rewriter for Blocks.
+    RewriteMacros,          ///< Expand macros but not #includes.
+    RewriteObjC,            ///< ObjC->C Rewriter.
+    RewriteTest,            ///< Rewriter playground
+    RunAnalysis,            ///< Run one or more source code analyses.
+    RunPreprocessorOnly     ///< Just lex, no output.
+  };
+}
+
 /// FrontendOptions - Options for controlling the behavior of the frontend.
 class FrontendOptions {
 public:
@@ -73,11 +106,15 @@
   /// If given, enable code completion at the provided location.
   ParsedSourceLocation CodeCompletionAt;
 
+  /// The frontend action to perform.
+  frontend::ActionKind ProgramAction;
+
 public:
   FrontendOptions() {
     DebugCodeCompletionPrinter = 0;
     DisableFree = 0;
     EmptyInputOnly = 0;
+    ProgramAction = frontend::ParseSyntaxOnly;
     RelocatablePCH = 0;
     ShowMacrosInCodeCompletion = 0;
     ShowStats = 0;

Modified: cfe/trunk/tools/clang-cc/Options.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/Options.cpp?rev=88820&r1=88819&r2=88820&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/Options.cpp (original)
+++ cfe/trunk/tools/clang-cc/Options.cpp Sat Nov 14 16:32:38 2009
@@ -303,6 +303,8 @@
 
 namespace frontendoptions {
 
+using namespace clang::frontend;
+
 static llvm::cl::opt<ParsedSourceLocation>
 CodeCompletionAt("code-completion-at",
                  llvm::cl::value_desc("file:line:column"),
@@ -381,6 +383,64 @@
  llvm::cl::value_desc("path"),
  llvm::cl::desc("Specify output file"));
 
+static llvm::cl::opt<ActionKind>
+ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
+           llvm::cl::init(ParseSyntaxOnly),
+           llvm::cl::values(
+             clEnumValN(RunPreprocessorOnly, "Eonly",
+                        "Just run preprocessor, no output (for timings)"),
+             clEnumValN(PrintPreprocessedInput, "E",
+                        "Run preprocessor, emit preprocessed file"),
+             clEnumValN(DumpRawTokens, "dump-raw-tokens",
+                        "Lex file in raw mode and dump raw tokens"),
+             clEnumValN(RunAnalysis, "analyze",
+                        "Run static analysis engine"),
+             clEnumValN(DumpTokens, "dump-tokens",
+                        "Run preprocessor, dump internal rep of tokens"),
+             clEnumValN(ParseNoop, "parse-noop",
+                        "Run parser with noop callbacks (for timings)"),
+             clEnumValN(ParseSyntaxOnly, "fsyntax-only",
+                        "Run parser and perform semantic analysis"),
+             clEnumValN(FixIt, "fixit",
+                        "Apply fix-it advice to the input source"),
+             clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
+                        "Run parser and print each callback invoked"),
+             clEnumValN(EmitHTML, "emit-html",
+                        "Output input source as HTML"),
+             clEnumValN(ASTPrint, "ast-print",
+                        "Build ASTs and then pretty-print them"),
+             clEnumValN(ASTPrintXML, "ast-print-xml",
+                        "Build ASTs and then print them in XML format"),
+             clEnumValN(ASTDump, "ast-dump",
+                        "Build ASTs and then debug dump them"),
+             clEnumValN(ASTView, "ast-view",
+                        "Build ASTs and view them with GraphViz"),
+             clEnumValN(PrintDeclContext, "print-decl-contexts",
+                        "Print DeclContexts and their Decls"),
+             clEnumValN(DumpRecordLayouts, "dump-record-layouts",
+                        "Dump record layout information"),
+             clEnumValN(GeneratePTH, "emit-pth",
+                        "Generate pre-tokenized header file"),
+             clEnumValN(GeneratePCH, "emit-pch",
+                        "Generate pre-compiled header file"),
+             clEnumValN(EmitAssembly, "S",
+                        "Emit native assembly code"),
+             clEnumValN(EmitLLVM, "emit-llvm",
+                        "Build ASTs then convert to LLVM, emit .ll file"),
+             clEnumValN(EmitBC, "emit-llvm-bc",
+                        "Build ASTs then convert to LLVM, emit .bc file"),
+             clEnumValN(EmitLLVMOnly, "emit-llvm-only",
+                        "Build ASTs and convert to LLVM, discarding output"),
+             clEnumValN(RewriteTest, "rewrite-test",
+                        "Rewriter playground"),
+             clEnumValN(RewriteObjC, "rewrite-objc",
+                        "Rewrite ObjC into C (code rewriter example)"),
+             clEnumValN(RewriteMacros, "rewrite-macros",
+                        "Expand macros without full preprocessing"),
+             clEnumValN(RewriteBlocks, "rewrite-blocks",
+                        "Rewrite Blocks to C"),
+             clEnumValEnd));
+
 static llvm::cl::opt<bool>
 RelocatablePCH("relocatable-pch",
                llvm::cl::desc("Whether to build a relocatable precompiled "
@@ -830,6 +890,7 @@
   Opts.DisableFree = DisableFree;
   Opts.EmptyInputOnly = EmptyInputOnly;
   Opts.FixItLocations = FixItAtLocations;
+  Opts.ProgramAction = ProgAction;
   Opts.OutputFile = OutputFile;
   Opts.RelocatablePCH = RelocatablePCH;
   Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=88820&r1=88819&r2=88820&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Sat Nov 14 16:32:38 2009
@@ -50,99 +50,6 @@
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
-// Frontend Actions
-//===----------------------------------------------------------------------===//
-
-enum ProgActions {
-  RewriteObjC,                  // ObjC->C Rewriter.
-  RewriteBlocks,                // ObjC->C Rewriter for Blocks.
-  RewriteMacros,                // Expand macros but not #includes.
-  RewriteTest,                  // Rewriter playground
-  HTMLTest,                     // HTML displayer testing stuff.
-  EmitAssembly,                 // Emit a .s file.
-  EmitLLVM,                     // Emit a .ll file.
-  EmitBC,                       // Emit a .bc file.
-  EmitLLVMOnly,                 // Generate LLVM IR, but do not
-  EmitHTML,                     // Translate input source into HTML.
-  ASTPrint,                     // Parse ASTs and print them.
-  ASTPrintXML,                  // Parse ASTs and print them in XML.
-  ASTDump,                      // Parse ASTs and dump them.
-  ASTView,                      // Parse ASTs and view them in Graphviz.
-  PrintDeclContext,             // Print DeclContext and their Decls.
-  DumpRecordLayouts,            // Dump record layout information.
-  ParsePrintCallbacks,          // Parse and print each callback.
-  ParseSyntaxOnly,              // Parse and perform semantic analysis.
-  FixIt,                        // Parse and apply any fixits to the source.
-  ParseNoop,                    // Parse with noop callbacks.
-  RunPreprocessorOnly,          // Just lex, no output.
-  PrintPreprocessedInput,       // -E mode.
-  DumpTokens,                   // Dump out preprocessed tokens.
-  DumpRawTokens,                // Dump out raw tokens.
-  RunAnalysis,                  // Run one or more source code analyses.
-  GeneratePTH,                  // Generate pre-tokenized header.
-  GeneratePCH,                  // Generate pre-compiled header.
-  InheritanceView               // View C++ inheritance for a specified class.
-};
-
-static llvm::cl::opt<ProgActions>
-ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
-           llvm::cl::init(ParseSyntaxOnly),
-           llvm::cl::values(
-             clEnumValN(RunPreprocessorOnly, "Eonly",
-                        "Just run preprocessor, no output (for timings)"),
-             clEnumValN(PrintPreprocessedInput, "E",
-                        "Run preprocessor, emit preprocessed file"),
-             clEnumValN(DumpRawTokens, "dump-raw-tokens",
-                        "Lex file in raw mode and dump raw tokens"),
-             clEnumValN(RunAnalysis, "analyze",
-                        "Run static analysis engine"),
-             clEnumValN(DumpTokens, "dump-tokens",
-                        "Run preprocessor, dump internal rep of tokens"),
-             clEnumValN(ParseNoop, "parse-noop",
-                        "Run parser with noop callbacks (for timings)"),
-             clEnumValN(ParseSyntaxOnly, "fsyntax-only",
-                        "Run parser and perform semantic analysis"),
-             clEnumValN(FixIt, "fixit",
-                        "Apply fix-it advice to the input source"),
-             clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
-                        "Run parser and print each callback invoked"),
-             clEnumValN(EmitHTML, "emit-html",
-                        "Output input source as HTML"),
-             clEnumValN(ASTPrint, "ast-print",
-                        "Build ASTs and then pretty-print them"),
-             clEnumValN(ASTPrintXML, "ast-print-xml",
-                        "Build ASTs and then print them in XML format"),
-             clEnumValN(ASTDump, "ast-dump",
-                        "Build ASTs and then debug dump them"),
-             clEnumValN(ASTView, "ast-view",
-                        "Build ASTs and view them with GraphViz"),
-             clEnumValN(PrintDeclContext, "print-decl-contexts",
-                        "Print DeclContexts and their Decls"),
-             clEnumValN(DumpRecordLayouts, "dump-record-layouts",
-                        "Dump record layout information"),
-             clEnumValN(GeneratePTH, "emit-pth",
-                        "Generate pre-tokenized header file"),
-             clEnumValN(GeneratePCH, "emit-pch",
-                        "Generate pre-compiled header file"),
-             clEnumValN(EmitAssembly, "S",
-                        "Emit native assembly code"),
-             clEnumValN(EmitLLVM, "emit-llvm",
-                        "Build ASTs then convert to LLVM, emit .ll file"),
-             clEnumValN(EmitBC, "emit-llvm-bc",
-                        "Build ASTs then convert to LLVM, emit .bc file"),
-             clEnumValN(EmitLLVMOnly, "emit-llvm-only",
-                        "Build ASTs and convert to LLVM, discarding output"),
-             clEnumValN(RewriteTest, "rewrite-test",
-                        "Rewriter playground"),
-             clEnumValN(RewriteObjC, "rewrite-objc",
-                        "Rewrite ObjC into C (code rewriter example)"),
-             clEnumValN(RewriteMacros, "rewrite-macros",
-                        "Expand macros without full preprocessing"),
-             clEnumValN(RewriteBlocks, "rewrite-blocks",
-                        "Rewrite Blocks to C"),
-             clEnumValEnd));
-
-//===----------------------------------------------------------------------===//
 // Utility Methods
 //===----------------------------------------------------------------------===//
 
@@ -174,8 +81,10 @@
 /// anything.
 llvm::Timer *ClangFrontendTimer = 0;
 
-static FrontendAction *CreateFrontendAction(ProgActions PA) {
-  switch (PA) {
+static FrontendAction *CreateFrontendAction(frontend::ActionKind AK) {
+  using namespace clang::frontend;
+
+  switch (AK) {
   default:                     return 0;
   case ASTDump:                return new ASTDumpAction();
   case ASTPrint:               return new ASTPrintAction();
@@ -344,9 +253,9 @@
 
   // Enforce certain implications.
   if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
-    ProgAction = InheritanceView;
+    Clang.getFrontendOpts().ProgramAction = frontend::InheritanceView;
   if (!Clang.getFrontendOpts().FixItLocations.empty())
-    ProgAction = FixIt;
+    Clang.getFrontendOpts().ProgramAction = frontend::FixIt;
 
   for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
     const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
@@ -370,7 +279,8 @@
       Clang.createPreprocessor();
     }
 
-    llvm::OwningPtr<FrontendAction> Act(CreateFrontendAction(ProgAction));
+    llvm::OwningPtr<FrontendAction> Act(
+      CreateFrontendAction(Clang.getFrontendOpts().ProgramAction));
     assert(Act && "Invalid program action!");
     Act->setCurrentTimer(ClangFrontendTimer);
     if (Act->BeginSourceFile(Clang, InFile, IsAST)) {





More information about the cfe-commits mailing list