1 //===-- AnalyzerOptions.cpp - Analysis Engine Options -----------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains special accessors for analyzer configuration options 11 // with string representations. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" 16 #include "llvm/ADT/StringSwitch.h" 17 18 using namespace clang; 19 20 bool 21 AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const { 22 if (IPAMode < Inlining) 23 return false; 24 25 if (!CXXMemberInliningMode) { 26 static const char *ModeKey = "c++-inlining"; 27 std::string ModeStr = Config.lookup(ModeKey); 28 29 CXXInlineableMemberKind &MutableMode = 30 const_cast<CXXInlineableMemberKind &>(CXXMemberInliningMode); 31 32 MutableMode = llvm::StringSwitch<CXXInlineableMemberKind>(ModeStr) 33 .Case("", CIMK_MemberFunctions) 34 .Case("constructors", CIMK_Constructors) 35 .Case("destructors", CIMK_Destructors) 36 .Case("none", CIMK_None) 37 .Case("methods", CIMK_MemberFunctions) 38 .Default(CXXInlineableMemberKind()); 39 40 if (!MutableMode) { 41 // FIXME: We should emit a warning here about an unknown inlining kind, 42 // but the AnalyzerOptions doesn't have access to a diagnostic engine. 43 MutableMode = CIMK_None; 44 } 45 } 46 47 return CXXMemberInliningMode >= K; 48 } 49 50 bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) const { 51 // FIXME: We should emit a warning here if the value is something other than 52 // "true", "false", or the empty string (meaning the default value), 53 // but the AnalyzerOptions doesn't have access to a diagnostic engine. 54 return llvm::StringSwitch<bool>(Config.lookup(Name)) 55 .Case("true", true) 56 .Case("false", false) 57 .Default(DefaultVal); 58 } 59 60 bool AnalyzerOptions::includeTemporaryDtorsInCFG() const { 61 if (!IncludeTemporaryDtorsInCFG.hasValue()) 62 const_cast<llvm::Optional<bool> &>(IncludeTemporaryDtorsInCFG) = 63 getBooleanOption("cfg-temporary-dtors", /*Default=*/false); 64 65 return *IncludeTemporaryDtorsInCFG; 66 } 67 68 bool AnalyzerOptions::mayInlineCXXStandardLibrary() const { 69 if (!InlineCXXStandardLibrary.hasValue()) 70 const_cast<llvm::Optional<bool> &>(InlineCXXStandardLibrary) = 71 getBooleanOption("c++-stdlib-inlining", /*Default=*/false); 72 73 return *InlineCXXStandardLibrary; 74 } 75 76 bool AnalyzerOptions::mayInlineTemplateFunctions() const { 77 if (!InlineTemplateFunctions.hasValue()) 78 const_cast<llvm::Optional<bool> &>(InlineTemplateFunctions) = 79 getBooleanOption("c++-template-inlining", /*Default=*/true); 80 81 return *InlineTemplateFunctions; 82 } 83