AnalyzerOptions.cpp revision a43df9539644bf1c258e12710cd69d79b0b078cd
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 18using namespace clang; 19using namespace llvm; 20 21bool 22AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const { 23 if (IPAMode < Inlining) 24 return false; 25 26 if (!CXXMemberInliningMode) { 27 static const char *ModeKey = "c++-inlining"; 28 std::string ModeStr = Config.lookup(ModeKey); 29 30 CXXInlineableMemberKind &MutableMode = 31 const_cast<CXXInlineableMemberKind &>(CXXMemberInliningMode); 32 33 MutableMode = llvm::StringSwitch<CXXInlineableMemberKind>(ModeStr) 34 .Case("", CIMK_MemberFunctions) 35 .Case("constructors", CIMK_Constructors) 36 .Case("destructors", CIMK_Destructors) 37 .Case("none", CIMK_None) 38 .Case("methods", CIMK_MemberFunctions) 39 .Default(CXXInlineableMemberKind()); 40 41 if (!MutableMode) { 42 // FIXME: We should emit a warning here about an unknown inlining kind, 43 // but the AnalyzerOptions doesn't have access to a diagnostic engine. 44 MutableMode = CIMK_None; 45 } 46 } 47 48 return CXXMemberInliningMode >= K; 49} 50 51bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) const { 52 // FIXME: We should emit a warning here if the value is something other than 53 // "true", "false", or the empty string (meaning the default value), 54 // but the AnalyzerOptions doesn't have access to a diagnostic engine. 55 return llvm::StringSwitch<bool>(Config.lookup(Name)) 56 .Case("true", true) 57 .Case("false", false) 58 .Default(DefaultVal); 59} 60 61bool AnalyzerOptions::includeTemporaryDtorsInCFG() const { 62 if (!IncludeTemporaryDtorsInCFG.hasValue()) 63 const_cast<llvm::Optional<bool> &>(IncludeTemporaryDtorsInCFG) = 64 getBooleanOption("cfg-temporary-dtors", /*Default=*/false); 65 66 return *IncludeTemporaryDtorsInCFG; 67} 68 69bool AnalyzerOptions::mayInlineCXXStandardLibrary() const { 70 if (!InlineCXXStandardLibrary.hasValue()) 71 const_cast<llvm::Optional<bool> &>(InlineCXXStandardLibrary) = 72 getBooleanOption("c++-stdlib-inlining", /*Default=*/true); 73 74 return *InlineCXXStandardLibrary; 75} 76 77bool AnalyzerOptions::mayInlineTemplateFunctions() const { 78 if (!InlineTemplateFunctions.hasValue()) 79 const_cast<llvm::Optional<bool> &>(InlineTemplateFunctions) = 80 getBooleanOption("c++-template-inlining", /*Default=*/true); 81 82 return *InlineTemplateFunctions; 83} 84 85bool AnalyzerOptions::mayInlineObjCMethod() const { 86 if (!ObjCInliningMode.hasValue()) 87 const_cast<llvm::Optional<bool> &>(ObjCInliningMode) = 88 getBooleanOption("objc-inlining", /*Default=*/true); 89 90 return *ObjCInliningMode; 91} 92 93int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const { 94 std::string OptStr = Config.lookup(Name); 95 if (OptStr.empty()) 96 return DefaultVal; 97 98 int Res = DefaultVal; 99 assert(StringRef(OptStr).getAsInteger(10, Res) == false && 100 "analyzer-config option should be numeric."); 101 102 return Res; 103} 104 105unsigned AnalyzerOptions::getAlwaysInlineSize() const { 106 if (!AlwaysInlineSize.hasValue()) { 107 unsigned DefaultSize = 3; 108 const_cast<Optional<unsigned> &>(AlwaysInlineSize) = 109 getOptionAsInteger("ipa-always-inline-size", DefaultSize); 110 } 111 112 return AlwaysInlineSize.getValue(); 113} 114 115bool AnalyzerOptions::shouldSynthesizeBodies() const { 116 return getBooleanOption("faux-bodies", false); 117} 118