forked from OSchip/llvm-project
Simplify PreprocessorOptions, it doesn't need abstracted field access.
llvm-svn: 89047
This commit is contained in:
parent
4c4d643b6e
commit
d6ea9028e7
|
@ -23,6 +23,7 @@ class LangOptions;
|
|||
/// PreprocessorOptions - This class is used for passing the various options
|
||||
/// used in preprocessor initialization to InitializePreprocessor().
|
||||
class PreprocessorOptions {
|
||||
public:
|
||||
std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
|
||||
std::vector<std::string> Includes;
|
||||
std::vector<std::string> MacroIncludes;
|
||||
|
@ -43,61 +44,12 @@ class PreprocessorOptions {
|
|||
public:
|
||||
PreprocessorOptions() : UsePredefines(true) {}
|
||||
|
||||
bool getUsePredefines() const { return UsePredefines; }
|
||||
void setUsePredefines(bool Value) {
|
||||
UsePredefines = Value;
|
||||
}
|
||||
|
||||
const std::string &getImplicitPCHInclude() const {
|
||||
return ImplicitPCHInclude;
|
||||
}
|
||||
void setImplicitPCHInclude(llvm::StringRef Value) {
|
||||
assert((Value.empty() || ImplicitPTHInclude.empty()) &&
|
||||
"Cannot both implicit PCH and PTH includes!");
|
||||
ImplicitPCHInclude = Value;
|
||||
}
|
||||
|
||||
const std::string &getImplicitPTHInclude() const {
|
||||
return ImplicitPTHInclude;
|
||||
}
|
||||
void setImplicitPTHInclude(llvm::StringRef Value) {
|
||||
assert((ImplicitPCHInclude.empty() || Value.empty()) &&
|
||||
"Cannot both implicit PCH and PTH includes!");
|
||||
ImplicitPTHInclude = Value;
|
||||
}
|
||||
|
||||
const std::string &getTokenCache() const {
|
||||
return TokenCache;
|
||||
}
|
||||
void setTokenCache(llvm::StringRef Value) {
|
||||
TokenCache = Value;
|
||||
}
|
||||
|
||||
void addMacroDef(llvm::StringRef Name) {
|
||||
Macros.push_back(std::make_pair(Name, false));
|
||||
}
|
||||
void addMacroUndef(llvm::StringRef Name) {
|
||||
Macros.push_back(std::make_pair(Name, true));
|
||||
}
|
||||
void addInclude(llvm::StringRef Name) {
|
||||
Includes.push_back(Name);
|
||||
}
|
||||
void addMacroInclude(llvm::StringRef Name) {
|
||||
MacroIncludes.push_back(Name);
|
||||
}
|
||||
|
||||
typedef std::vector<std::pair<std::string,
|
||||
bool> >::const_iterator macro_iterator;
|
||||
macro_iterator macro_begin() const { return Macros.begin(); }
|
||||
macro_iterator macro_end() const { return Macros.end(); }
|
||||
|
||||
typedef std::vector<std::string>::const_iterator include_iterator;
|
||||
include_iterator include_begin() const { return Includes.begin(); }
|
||||
include_iterator include_end() const { return Includes.end(); }
|
||||
|
||||
typedef std::vector<std::string>::const_iterator imacro_iterator;
|
||||
imacro_iterator imacro_begin() const { return MacroIncludes.begin(); }
|
||||
imacro_iterator imacro_end() const { return MacroIncludes.end(); }
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
|
|
@ -167,8 +167,8 @@ CompilerInstance::createPreprocessor(Diagnostic &Diags,
|
|||
FileManager &FileMgr) {
|
||||
// Create a PTH manager if we are using some form of a token cache.
|
||||
PTHManager *PTHMgr = 0;
|
||||
if (!PPOpts.getTokenCache().empty())
|
||||
PTHMgr = PTHManager::Create(PPOpts.getTokenCache(), Diags);
|
||||
if (!PPOpts.TokenCache.empty())
|
||||
PTHMgr = PTHManager::Create(PPOpts.TokenCache, Diags);
|
||||
|
||||
// FIXME: Don't fail like this.
|
||||
if (Diags.hasErrorOccurred())
|
||||
|
|
|
@ -90,10 +90,10 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
|||
goto failure;
|
||||
|
||||
/// Use PCH?
|
||||
if (!CI.getPreprocessorOpts().getImplicitPCHInclude().empty()) {
|
||||
if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
|
||||
assert(hasPCHSupport() && "This action does not have PCH support!");
|
||||
CI.createPCHExternalASTSource(
|
||||
CI.getPreprocessorOpts().getImplicitPCHInclude());
|
||||
CI.getPreprocessorOpts().ImplicitPCHInclude);
|
||||
if (!CI.getASTContext().getExternalSource())
|
||||
goto failure;
|
||||
}
|
||||
|
|
|
@ -477,7 +477,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
|
|||
LineDirective, LineDirective+strlen(LineDirective));
|
||||
|
||||
// Install things like __POWERPC__, __GNUC__, etc into the macro table.
|
||||
if (InitOpts.getUsePredefines())
|
||||
if (InitOpts.UsePredefines)
|
||||
InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
|
||||
PredefineBuffer);
|
||||
|
||||
|
@ -488,27 +488,25 @@ void clang::InitializePreprocessor(Preprocessor &PP,
|
|||
LineDirective, LineDirective+strlen(LineDirective));
|
||||
|
||||
// Process #define's and #undef's in the order they are given.
|
||||
for (PreprocessorOptions::macro_iterator I = InitOpts.macro_begin(),
|
||||
E = InitOpts.macro_end(); I != E; ++I) {
|
||||
if (I->second) // isUndef
|
||||
UndefineBuiltinMacro(PredefineBuffer, I->first.c_str());
|
||||
for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
|
||||
if (InitOpts.Macros[i].second) // isUndef
|
||||
UndefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str());
|
||||
else
|
||||
DefineBuiltinMacro(PredefineBuffer, I->first.c_str());
|
||||
DefineBuiltinMacro(PredefineBuffer, InitOpts.Macros[i].first.c_str());
|
||||
}
|
||||
|
||||
// If -imacros are specified, include them now. These are processed before
|
||||
// any -include directives.
|
||||
for (PreprocessorOptions::imacro_iterator I = InitOpts.imacro_begin(),
|
||||
E = InitOpts.imacro_end(); I != E; ++I)
|
||||
AddImplicitIncludeMacros(PredefineBuffer, *I);
|
||||
for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
|
||||
AddImplicitIncludeMacros(PredefineBuffer, InitOpts.MacroIncludes[i]);
|
||||
|
||||
// Process -include directives.
|
||||
for (PreprocessorOptions::include_iterator I = InitOpts.include_begin(),
|
||||
E = InitOpts.include_end(); I != E; ++I) {
|
||||
if (*I == InitOpts.getImplicitPTHInclude())
|
||||
AddImplicitIncludePTH(PredefineBuffer, PP, *I);
|
||||
for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
|
||||
const std::string &Path = InitOpts.Includes[i];
|
||||
if (Path == InitOpts.ImplicitPTHInclude)
|
||||
AddImplicitIncludePTH(PredefineBuffer, PP, Path);
|
||||
else
|
||||
AddImplicitInclude(PredefineBuffer, *I);
|
||||
AddImplicitInclude(PredefineBuffer, Path);
|
||||
}
|
||||
|
||||
// Null terminate PredefinedBuffer and add it.
|
||||
|
|
|
@ -1008,8 +1008,8 @@ void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
|
|||
void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
|
||||
using namespace preprocessoroptions;
|
||||
|
||||
Opts.setImplicitPCHInclude(ImplicitIncludePCH);
|
||||
Opts.setImplicitPTHInclude(ImplicitIncludePTH);
|
||||
Opts.ImplicitPCHInclude = ImplicitIncludePCH;
|
||||
Opts.ImplicitPTHInclude = ImplicitIncludePTH;
|
||||
|
||||
// Select the token cache file, we don't support more than one currently so we
|
||||
// can't have both an implicit-pth and a token cache file.
|
||||
|
@ -1020,12 +1020,12 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
|
|||
exit(1);
|
||||
}
|
||||
if (TokenCache.getPosition())
|
||||
Opts.setTokenCache(TokenCache);
|
||||
Opts.TokenCache = TokenCache;
|
||||
else
|
||||
Opts.setTokenCache(ImplicitIncludePTH);
|
||||
Opts.TokenCache = ImplicitIncludePTH;
|
||||
|
||||
// Use predefines?
|
||||
Opts.setUsePredefines(!UndefMacros);
|
||||
Opts.UsePredefines = !UndefMacros;
|
||||
|
||||
// Add macros from the command line.
|
||||
unsigned d = 0, D = D_macros.size();
|
||||
|
@ -1040,7 +1040,7 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
|
|||
// 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]);
|
||||
Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]);
|
||||
|
||||
// Add the ordered list of -includes, sorting in the implicit include options
|
||||
// at the appropriate location.
|
||||
|
@ -1064,7 +1064,7 @@ void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
|
|||
llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
|
||||
|
||||
for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
|
||||
Opts.addInclude(*OrderedPaths[i].second);
|
||||
Opts.Includes.push_back(*OrderedPaths[i].second);
|
||||
}
|
||||
|
||||
void clang::InitializeLangOptions(LangOptions &Options,
|
||||
|
|
Loading…
Reference in New Issue