Refactor clients of AnalyzerOptions::getBooleanOption() to have

an intermediate helper method to query and populate the Optional value.

llvm-svn: 165043
This commit is contained in:
Ted Kremenek 2012-10-02 20:42:16 +00:00
parent 24c20ec63a
commit 4924a0161b
2 changed files with 27 additions and 25 deletions

View File

@ -194,6 +194,10 @@ private:
/// If an option value is not provided, returns the given \p DefaultVal. /// If an option value is not provided, returns the given \p DefaultVal.
bool getBooleanOption(StringRef Name, bool DefaultVal); bool getBooleanOption(StringRef Name, bool DefaultVal);
/// Variant that accepts a Optional value to cache the result.
bool getBooleanOption(llvm::Optional<bool> &V, StringRef Name,
bool DefaultVal);
/// Interprets an option's string value as an integer value. /// Interprets an option's string value as an integer value.
int getOptionAsInteger(llvm::StringRef Name, int DefaultVal); int getOptionAsInteger(llvm::StringRef Name, int DefaultVal);

View File

@ -64,44 +64,42 @@ bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) {
.Default(DefaultVal); .Default(DefaultVal);
} }
bool AnalyzerOptions::getBooleanOption(llvm::Optional<bool> &V,
StringRef Name,
bool DefaultVal) {
if (!V.hasValue())
V = getBooleanOption(Name, DefaultVal);
return V.getValue();
}
bool AnalyzerOptions::includeTemporaryDtorsInCFG() { bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
if (!IncludeTemporaryDtorsInCFG.hasValue()) return getBooleanOption(IncludeTemporaryDtorsInCFG,
const_cast<llvm::Optional<bool> &>(IncludeTemporaryDtorsInCFG) = "cfg-temporary-dtors",
getBooleanOption("cfg-temporary-dtors", /*Default=*/false); /* Default = */ false);
return *IncludeTemporaryDtorsInCFG;
} }
bool AnalyzerOptions::mayInlineCXXStandardLibrary() { bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
if (!InlineCXXStandardLibrary.hasValue()) return getBooleanOption(InlineCXXStandardLibrary,
const_cast<llvm::Optional<bool> &>(InlineCXXStandardLibrary) = "c++-stdlib-inlining",
getBooleanOption("c++-stdlib-inlining", /*Default=*/true); /*Default=*/true);
return *InlineCXXStandardLibrary;
} }
bool AnalyzerOptions::mayInlineTemplateFunctions() { bool AnalyzerOptions::mayInlineTemplateFunctions() {
if (!InlineTemplateFunctions.hasValue()) return getBooleanOption(InlineTemplateFunctions,
const_cast<llvm::Optional<bool> &>(InlineTemplateFunctions) = "c++-template-inlining",
getBooleanOption("c++-template-inlining", /*Default=*/true); /*Default=*/true);
return *InlineTemplateFunctions;
} }
bool AnalyzerOptions::mayInlineObjCMethod() { bool AnalyzerOptions::mayInlineObjCMethod() {
if (!ObjCInliningMode.hasValue()) return getBooleanOption(ObjCInliningMode,
const_cast<llvm::Optional<bool> &>(ObjCInliningMode) = "objc-inlining",
getBooleanOption("objc-inlining", /*Default=*/true); /* Default = */ true);
return *ObjCInliningMode;
} }
bool AnalyzerOptions::shouldPruneNullReturnPaths() { bool AnalyzerOptions::shouldPruneNullReturnPaths() {
if (!PruneNullReturnPaths.hasValue()) return getBooleanOption(PruneNullReturnPaths,
const_cast<llvm::Optional<bool> &>(PruneNullReturnPaths) = "suppress-null-return-paths",
getBooleanOption("suppress-null-return-paths", /*Default=*/true); /* Default = */ true);
return *PruneNullReturnPaths;
} }
int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) { int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {