зеркало из https://github.com/microsoft/clang-1.git
Implement support for the -undef command line option, patch by
Roman Divacky! PR5363 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85932 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
cf18465531
Коммит
e6113de52d
|
@ -63,7 +63,8 @@ public:
|
|||
/// environment ready to process a single file. This returns true on error.
|
||||
///
|
||||
bool InitializePreprocessor(Preprocessor &PP,
|
||||
const PreprocessorInitOptions& InitOptions);
|
||||
const PreprocessorInitOptions& InitOptions,
|
||||
bool undef_macros);
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
|
|
|
@ -1015,6 +1015,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
II.getInputArg().renderAsInput(Args, CmdArgs);
|
||||
}
|
||||
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_undef);
|
||||
|
||||
const char *Exec =
|
||||
Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc"));
|
||||
Dest.addCommand(new Command(JA, Exec, CmdArgs));
|
||||
|
|
|
@ -443,7 +443,8 @@ 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) {
|
||||
const PreprocessorInitOptions &InitOpts,
|
||||
bool undef_macros) {
|
||||
std::vector<char> PredefineBuffer;
|
||||
|
||||
const char *LineDirective = "# 1 \"<built-in>\" 3\n";
|
||||
|
@ -451,8 +452,9 @@ bool clang::InitializePreprocessor(Preprocessor &PP,
|
|||
LineDirective, LineDirective+strlen(LineDirective));
|
||||
|
||||
// Install things like __POWERPC__, __GNUC__, etc into the macro table.
|
||||
InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
|
||||
PredefineBuffer);
|
||||
if (!undef_macros)
|
||||
InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
|
||||
PredefineBuffer);
|
||||
|
||||
// Add on the predefines from the driver. Wrap in a #line directive to report
|
||||
// that they come from the command line.
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// RUN: clang-cc -dM -undef -Dfoo=1 -E %s | FileCheck %s
|
||||
|
||||
// CHECK-NOT: #define __clang__
|
||||
// CHECK: #define foo 1
|
|
@ -932,6 +932,9 @@ static bool InitializeSourceManager(Preprocessor &PP,
|
|||
// -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"));
|
||||
|
||||
static llvm::cl::list<std::string>
|
||||
D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
|
||||
llvm::cl::desc("Predefine the specified macro"));
|
||||
|
@ -1243,7 +1246,7 @@ public:
|
|||
|
||||
PreprocessorInitOptions InitOpts;
|
||||
InitializePreprocessorInitOptions(InitOpts);
|
||||
if (InitializePreprocessor(*PP, InitOpts))
|
||||
if (InitializePreprocessor(*PP, InitOpts, undef_macros))
|
||||
return 0;
|
||||
|
||||
return PP.take();
|
||||
|
|
Загрузка…
Ссылка в новой задаче