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:
Chris Lattner 2009-11-03 19:50:27 +00:00
Родитель cf18465531
Коммит e6113de52d
5 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -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();