]> granicus.if.org Git - clang/commitdiff
Move -undef flag into PreprocessorInitOptions
authorDaniel Dunbar <daniel@zuster.org>
Wed, 4 Nov 2009 21:13:02 +0000 (21:13 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 4 Nov 2009 21:13:02 +0000 (21:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86047 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/InitPreprocessor.h
lib/Frontend/InitPreprocessor.cpp
tools/clang-cc/clang-cc.cpp

index b29ee2728a8698551e1eca7b029f54e2f3b061a1..bf27b19aa3d7f14ee37b5b8b751efcc0e14d35e0 100644 (file)
@@ -29,7 +29,16 @@ class PreprocessorInitOptions {
   std::vector<std::pair<std::string, bool/*isPTH*/> > Includes;
   std::vector<std::string> MacroIncludes;
 
+  unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
+                              /// and target specific predefines.
+
 public:
+  PreprocessorInitOptions() : UsePredefines(true) {}
+
+  bool getUsePredefines() const { return UsePredefines; }
+  void setUsePredefines(bool Value) {
+    UsePredefines = Value;
+  }
 
   void addMacroDef(const std::string &Name) {
     Macros.push_back(std::make_pair(Name, false));
@@ -63,8 +72,7 @@ public:
 /// environment ready to process a single file. This returns true on error.
 ///
 bool InitializePreprocessor(Preprocessor &PP,
-                            const PreprocessorInitOptions& InitOptions,
-                            bool undef_macros);
+                            const PreprocessorInitOptions& InitOptions);
 
 } // end namespace clang
 
index ec5c1061bb938cc46153012f4777059ffcf0863d..3a54d1dca78096c3accf2e0be0a1aac309a3543d 100644 (file)
@@ -443,8 +443,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
 /// environment ready to process a single file. This returns true on error.
 ///
 bool clang::InitializePreprocessor(Preprocessor &PP,
-                                   const PreprocessorInitOptions &InitOpts,
-                                   bool undef_macros) {
+                                   const PreprocessorInitOptions &InitOpts) {
   std::vector<char> PredefineBuffer;
 
   const char *LineDirective = "# 1 \"<built-in>\" 3\n";
@@ -452,7 +451,7 @@ bool clang::InitializePreprocessor(Preprocessor &PP,
                          LineDirective, LineDirective+strlen(LineDirective));
 
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
-  if (!undef_macros)
+  if (InitOpts.getUsePredefines())
     InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
                                PredefineBuffer);
 
index 671fc35d182b95642be8da4d0d40c1907bec2a82..66aa19a5d314ef93381efd0066c676fd5d6bd56d 100644 (file)
@@ -933,12 +933,9 @@ static bool InitializeSourceManager(Preprocessor &PP,
 // Preprocessor Initialization
 //===----------------------------------------------------------------------===//
 
-// FIXME: Preprocessor builtins to support.
-//   -A...    - Play with #assertions
-//   -undef   - Undefine all predefined macros
-
 static llvm::cl::opt<bool>
-undef_macros("undef", llvm::cl::value_desc("macro"), llvm::cl::desc("undef all system defines"));
+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,
@@ -1137,6 +1134,9 @@ void InitializeIncludePaths(const char *Argv0, HeaderSearch &Headers,
 }
 
 void InitializePreprocessorInitOptions(PreprocessorInitOptions &InitOpts) {
+  // 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();
@@ -1251,7 +1251,7 @@ public:
 
     PreprocessorInitOptions InitOpts;
     InitializePreprocessorInitOptions(InitOpts);
-    if (InitializePreprocessor(*PP, InitOpts, undef_macros))
+    if (InitializePreprocessor(*PP, InitOpts))
       return 0;
 
     return PP.take();