From 468fe246192c3683360d1a6b1b333d85b8794f77 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 4 Nov 2009 21:13:02 +0000 Subject: [PATCH] Move -undef flag into PreprocessorInitOptions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86047 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/InitPreprocessor.h | 12 ++++++++++-- lib/Frontend/InitPreprocessor.cpp | 5 ++--- tools/clang-cc/clang-cc.cpp | 12 ++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/clang/Frontend/InitPreprocessor.h b/include/clang/Frontend/InitPreprocessor.h index b29ee2728a..bf27b19aa3 100644 --- a/include/clang/Frontend/InitPreprocessor.h +++ b/include/clang/Frontend/InitPreprocessor.h @@ -29,7 +29,16 @@ class PreprocessorInitOptions { std::vector > Includes; std::vector 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 diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index ec5c1061bb..3a54d1dca7 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -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 PredefineBuffer; const char *LineDirective = "# 1 \"\" 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); diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 671fc35d18..66aa19a5d3 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -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 -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 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(); -- 2.40.0