AnalyzerOptions.cpp revision b9d4e5e3bb235f1149e99d3c833ff7cb3474c9f1
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
93bool AnalyzerOptions::shouldPruneNullReturnPaths() const {
94  if (!PruneNullReturnPaths.hasValue())
95    const_cast<llvm::Optional<bool> &>(PruneNullReturnPaths) =
96      getBooleanOption("suppress-null-return-paths", /*Default=*/true);
97
98  return *PruneNullReturnPaths;
99}
100
101int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const {
102  std::string OptStr = Config.lookup(Name);
103  if (OptStr.empty())
104    return DefaultVal;
105
106  int Res = DefaultVal;
107  assert(StringRef(OptStr).getAsInteger(10, Res) == false &&
108         "analyzer-config option should be numeric.");
109
110  return Res;
111}
112
113unsigned AnalyzerOptions::getAlwaysInlineSize() const {
114  if (!AlwaysInlineSize.hasValue()) {
115    unsigned DefaultSize = 3;
116    const_cast<Optional<unsigned> &>(AlwaysInlineSize) =
117      getOptionAsInteger("ipa-always-inline-size", DefaultSize);
118  }
119
120  return AlwaysInlineSize.getValue();
121}
122
123bool AnalyzerOptions::shouldSynthesizeBodies() const {
124  return getBooleanOption("faux-bodies", true);
125}
126