[cfe-commits] r165043 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp

Ted Kremenek kremenek at apple.com
Tue Oct 2 13:42:16 PDT 2012


Author: kremenek
Date: Tue Oct  2 15:42:16 2012
New Revision: 165043

URL: http://llvm.org/viewvc/llvm-project?rev=165043&view=rev
Log:
Refactor clients of AnalyzerOptions::getBooleanOption() to have
an intermediate helper method to query and populate the Optional value.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
    cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=165043&r1=165042&r2=165043&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Tue Oct  2 15:42:16 2012
@@ -194,6 +194,10 @@
   /// 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);
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=165043&r1=165042&r2=165043&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Tue Oct  2 15:42:16 2012
@@ -64,44 +64,42 @@
       .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) {





More information about the cfe-commits mailing list