]> granicus.if.org Git - clang/commitdiff
clang-cc: Move InitializePreprocessorOptions to Options.cpp
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 06:10:03 +0000 (06:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 06:10:03 +0000 (06:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86811 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PreprocessorOptions.h
tools/clang-cc/Options.cpp
tools/clang-cc/Options.h
tools/clang-cc/clang-cc.cpp

index fc400faa108bfde69c94380b7d812897db793fed..b918a744a2ab6598daa0436eb130a2b150e92afc 100644 (file)
@@ -11,6 +11,7 @@
 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
 
 #include "llvm/ADT/StringRef.h"
+#include <cassert>
 #include <string>
 #include <vector>
 
@@ -71,7 +72,7 @@ public:
   void addInclude(llvm::StringRef Name) {
     Includes.push_back(Name);
   }
-  void addMacroInclude(const std::string &Name) {
+  void addMacroInclude(llvm::StringRef Name) {
     MacroIncludes.push_back(Name);
   }
 
index 4f06ff5a6fbd5a297a8036b720c9485545f67cff..8105875d22bfa481963bf0c7f15bf55a4ff9fe3c 100644 (file)
 
 #include "Options.h"
 #include "clang/Frontend/CompileOptions.h"
+#include "clang/Frontend/PCHReader.h"
+#include "clang/Frontend/PreprocessorOptions.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/CommandLine.h"
 #include <stdio.h>
@@ -82,6 +85,41 @@ TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
 
 }
 
+//===----------------------------------------------------------------------===//
+// General Preprocessor Options
+//===----------------------------------------------------------------------===//
+
+namespace preprocessoroptions {
+
+static llvm::cl::list<std::string>
+D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
+       llvm::cl::desc("Predefine the specified macro"));
+
+static llvm::cl::list<std::string>
+ImplicitIncludes("include", llvm::cl::value_desc("file"),
+                 llvm::cl::desc("Include file before parsing"));
+static llvm::cl::list<std::string>
+ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
+                      llvm::cl::desc("Include macros from file before parsing"));
+
+static llvm::cl::opt<std::string>
+ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
+                   llvm::cl::desc("Include precompiled header file"));
+
+static llvm::cl::opt<std::string>
+ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
+                   llvm::cl::desc("Include file before parsing"));
+
+static llvm::cl::list<std::string>
+U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
+         llvm::cl::desc("Undefine the specified macro"));
+
+static llvm::cl::opt<bool>
+UndefMacros("undef", llvm::cl::value_desc("macro"),
+            llvm::cl::desc("undef all system defines"));
+
+}
+
 //===----------------------------------------------------------------------===//
 // Option Object Construction
 //===----------------------------------------------------------------------===//
@@ -155,3 +193,52 @@ void clang::InitializeCompileOptions(CompileOptions &Opts,
 
   Opts.MergeAllConstants = !NoMergeConstants;
 }
+
+void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
+  using namespace preprocessoroptions;
+
+  Opts.setImplicitPCHInclude(ImplicitIncludePCH);
+  Opts.setImplicitPTHInclude(ImplicitIncludePTH);
+
+  // Use predefines?
+  Opts.setUsePredefines(!UndefMacros);
+
+  // Add macros from the command line.
+  unsigned d = 0, D = D_macros.size();
+  unsigned u = 0, U = U_macros.size();
+  while (d < D || u < U) {
+    if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
+      Opts.addMacroDef(D_macros[d++]);
+    else
+      Opts.addMacroUndef(U_macros[u++]);
+  }
+
+  // If -imacros are specified, include them now.  These are processed before
+  // any -include directives.
+  for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
+    Opts.addMacroInclude(ImplicitMacroIncludes[i]);
+
+  // Add the ordered list of -includes, sorting in the implicit include options
+  // at the appropriate location.
+  llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
+  std::string OriginalFile;
+
+  if (!ImplicitIncludePTH.empty())
+    OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
+                                          &ImplicitIncludePTH));
+  if (!ImplicitIncludePCH.empty()) {
+    OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
+    // FIXME: Don't fail like this.
+    if (OriginalFile.empty())
+      exit(1);
+    OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
+                                          &OriginalFile));
+  }
+  for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
+    OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
+                                          &ImplicitIncludes[i]));
+  llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
+
+  for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
+    Opts.addInclude(*OrderedPaths[i].second);
+}
index 088029f4adb2e06ce617b617bd828eba72a5936e..ac9e4a58f93bf59c2dd626db1f61112cfc24f186 100644 (file)
@@ -16,13 +16,18 @@ namespace clang {
 
 class CompileOptions;
 class LangOptions;
+class PreprocessorOptions;
 class TargetInfo;
 
+// FIXME: This can be sunk into InitializeCompileOptions now that that happens
+// before language initialization?
 void ComputeFeatureMap(TargetInfo &Target, llvm::StringMap<bool> &Features);
 
 void InitializeCompileOptions(CompileOptions &Opts,
                               const llvm::StringMap<bool> &Features);
 
+void InitializePreprocessorOptions(PreprocessorOptions &Opts);
+
 } // end namespace clang
 
 #endif
index 8bf02f748f71a86b8e7cf6475107038c44f13c94..cf1fde97c2ccb448c804c5463646f716bdb1ee41 100644 (file)
@@ -53,7 +53,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -882,32 +881,6 @@ static bool InitializeSourceManager(Preprocessor &PP,
 // Preprocessor Initialization
 //===----------------------------------------------------------------------===//
 
-static llvm::cl::opt<bool>
-UndefMacros("undef", llvm::cl::value_desc("macro"),
-            llvm::cl::desc("undef all system defines"));
-
-static llvm::cl::list<std::string>
-D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
-       llvm::cl::desc("Predefine the specified macro"));
-static llvm::cl::list<std::string>
-U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
-         llvm::cl::desc("Undefine the specified macro"));
-
-static llvm::cl::list<std::string>
-ImplicitIncludes("include", llvm::cl::value_desc("file"),
-                 llvm::cl::desc("Include file before parsing"));
-static llvm::cl::list<std::string>
-ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
-                      llvm::cl::desc("Include macros from file before parsing"));
-
-static llvm::cl::opt<std::string>
-ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
-                   llvm::cl::desc("Include precompiled header file"));
-
-static llvm::cl::opt<std::string>
-ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
-                   llvm::cl::desc("Include file before parsing"));
-
 static llvm::cl::opt<bool>
 RelocatablePCH("relocatable-pch",
                llvm::cl::desc("Whether to build a relocatable precompiled "
@@ -1087,57 +1060,6 @@ static void InitializeIncludePaths(HeaderSearchOptions &Opts,
   Opts.UseStandardIncludes = !nostdinc;
 }
 
-static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) {
-  InitOpts.setImplicitPCHInclude(ImplicitIncludePCH);
-  InitOpts.setImplicitPTHInclude(ImplicitIncludePTH);
-
-  // Use predefines?
-  InitOpts.setUsePredefines(!UndefMacros);
-
-  // Add macros from the command line.
-  unsigned d = 0, D = D_macros.size();
-  unsigned u = 0, U = U_macros.size();
-  while (d < D || u < U) {
-    if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
-      InitOpts.addMacroDef(D_macros[d++]);
-    else
-      InitOpts.addMacroUndef(U_macros[u++]);
-  }
-
-  // If -imacros are specified, include them now.  These are processed before
-  // any -include directives.
-  for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
-    InitOpts.addMacroInclude(ImplicitMacroIncludes[i]);
-
-  if (!ImplicitIncludePTH.empty() || !ImplicitIncludes.empty() ||
-      !ImplicitIncludePCH.empty()) {
-    // We want to add these paths to the predefines buffer in order, make a
-    // temporary vector to sort by their occurrence.
-    llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
-    std::string OriginalFile; // For use by -implicit-include-pch.
-
-    if (!ImplicitIncludePTH.empty())
-      OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
-                                            &ImplicitIncludePTH));
-    if (!ImplicitIncludePCH.empty()) {
-      OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
-      // FIXME: Don't fail like this.
-      if (OriginalFile.empty())
-        exit(1);
-      OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
-                                            &OriginalFile));
-    }
-    for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
-      OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
-                                            &ImplicitIncludes[i]));
-    llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
-
-    // Now that they are ordered by position, add to the predefines buffer.
-    for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
-      InitOpts.addInclude(*OrderedPaths[i].second);
-  }
-}
-
 //===----------------------------------------------------------------------===//
 // Preprocessor construction
 //===----------------------------------------------------------------------===//