]> granicus.if.org Git - clang/commitdiff
Refactor clients of AnalyzerOptions::getBooleanOption() to have
authorTed Kremenek <kremenek@apple.com>
Tue, 2 Oct 2012 20:42:16 +0000 (20:42 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 2 Oct 2012 20:42:16 +0000 (20:42 +0000)
an intermediate helper method to query and populate the Optional value.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165043 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
lib/StaticAnalyzer/Core/AnalyzerOptions.cpp

index 091155ca60c867b7f2cee6c3d4047f4370e5a37f..4c11a675af716b3742cbe73422588610d2c717f1 100644 (file)
@@ -194,6 +194,10 @@ private:
   /// If an option value is not provided, returns the given \p 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.
   int getOptionAsInteger(llvm::StringRef Name, int DefaultVal);
 
index 6fbd2e1c6d138ec2dcc5eadf4053b1cc5168d655..2b957c419ac360b22d6a918a655ee8776ffb5306 100644 (file)
@@ -64,44 +64,42 @@ bool AnalyzerOptions::getBooleanOption(StringRef Name, bool 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() {
-  if (!IncludeTemporaryDtorsInCFG.hasValue())
-    const_cast<llvm::Optional<bool> &>(IncludeTemporaryDtorsInCFG) =
-      getBooleanOption("cfg-temporary-dtors", /*Default=*/false);
-  
-  return *IncludeTemporaryDtorsInCFG;
+  return getBooleanOption(IncludeTemporaryDtorsInCFG,
+                          "cfg-temporary-dtors",
+                          /* Default = */ false);
 }
 
 bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  if (!InlineCXXStandardLibrary.hasValue())
-    const_cast<llvm::Optional<bool> &>(InlineCXXStandardLibrary) =
-      getBooleanOption("c++-stdlib-inlining", /*Default=*/true);
-  
-  return *InlineCXXStandardLibrary;
+  return getBooleanOption(InlineCXXStandardLibrary,
+                          "c++-stdlib-inlining",
+                          /*Default=*/true);
 }
 
 bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  if (!InlineTemplateFunctions.hasValue())
-    const_cast<llvm::Optional<bool> &>(InlineTemplateFunctions) =
-      getBooleanOption("c++-template-inlining", /*Default=*/true);
-  
-  return *InlineTemplateFunctions;
+  return getBooleanOption(InlineTemplateFunctions,
+                          "c++-template-inlining",
+                          /*Default=*/true);
 }
 
 bool AnalyzerOptions::mayInlineObjCMethod() {
-  if (!ObjCInliningMode.hasValue())
-    const_cast<llvm::Optional<bool> &>(ObjCInliningMode) =
-      getBooleanOption("objc-inlining", /*Default=*/true);
-
-  return *ObjCInliningMode;
+  return getBooleanOption(ObjCInliningMode,
+                          "objc-inlining",
+                          /* Default = */ true);
 }
 
 bool AnalyzerOptions::shouldPruneNullReturnPaths() {
-  if (!PruneNullReturnPaths.hasValue())
-    const_cast<llvm::Optional<bool> &>(PruneNullReturnPaths) =
-      getBooleanOption("suppress-null-return-paths", /*Default=*/true);
-
-  return *PruneNullReturnPaths;
+  return getBooleanOption(PruneNullReturnPaths,
+                          "suppress-null-return-paths",
+                          /* Default = */ true);
 }
 
 int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {