Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
settings.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2016 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "settings.h"
20 
21 #include "valueflow.h"
22 
24 
26  : _enabled(0),
27  debug(false),
28  debugnormal(false),
29  debugwarnings(false),
30  dump(false),
31  exceptionHandling(false),
32  inconclusive(false),
33  jointSuppressionReport(false),
34  experimental(false),
35  quiet(false),
36  inlineSuppressions(false),
37  verbose(false),
38  force(false),
39  relativePaths(false),
40  xml(false), xml_version(2),
41  jobs(1),
42  loadAverage(0),
43  exitCode(0),
44  showtime(SHOWTIME_NONE),
45  preprocessOnly(false),
46  maxConfigs(12),
47  enforcedLang(None),
48  reportProgress(false),
49  checkConfiguration(false),
50  checkLibrary(false)
51 {
52 }
53 
54 std::string Settings::addEnabled(const std::string &str)
55 {
56  // Enable parameters may be comma separated...
57  if (str.find(',') != std::string::npos) {
58  std::string::size_type prevPos = 0;
59  std::string::size_type pos = 0;
60  while ((pos = str.find(',', pos)) != std::string::npos) {
61  if (pos == prevPos)
62  return std::string("cppcheck: --enable parameter is empty");
63  const std::string errmsg(addEnabled(str.substr(prevPos, pos - prevPos)));
64  if (!errmsg.empty())
65  return errmsg;
66  ++pos;
67  prevPos = pos;
68  }
69  if (prevPos >= str.length())
70  return std::string("cppcheck: --enable parameter is empty");
71  return addEnabled(str.substr(prevPos));
72  }
73 
74  if (str == "all") {
76  } else if (str == "warning") {
77  _enabled |= WARNING;
78  } else if (str == "style") {
79  _enabled |= STYLE;
80  } else if (str == "performance") {
82  } else if (str == "portability") {
84  } else if (str == "information") {
86  } else if (str == "unusedFunction") {
88  } else if (str == "missingInclude") {
90  }
91 #ifdef CHECK_INTERNAL
92  else if (str == "internal") {
93  _enabled |= INTERNAL;
94  }
95 #endif
96  else {
97  if (str.empty())
98  return std::string("cppcheck: --enable parameter is empty");
99  else
100  return std::string("cppcheck: there is no --enable parameter with the name '" + str + "'");
101  }
102 
103  return std::string();
104 }
105 
107 {
108  switch (severity) {
109  case Severity::none:
110  return true;
111  case Severity::error:
112  return true;
113  case Severity::warning:
114  return isEnabled(WARNING);
115  case Severity::style:
116  return isEnabled(STYLE);
118  return isEnabled(PERFORMANCE);
120  return isEnabled(PORTABILITY);
122  return isEnabled(INFORMATION);
123  case Severity::debug:
124  return false;
125  default:
126  return false;
127  }
128 }
129 
130 bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck) const
131 {
132  if (!isEnabled(Settings::WARNING) && (value->condition || value->defaultArg))
133  return false;
134  if (!inconclusive && (inconclusiveCheck || value->isInconclusive()))
135  return false;
136  return true;
137 }
bool inconclusive
Inconclusive checks.
Definition: settings.h:93
Programming error.
Definition: errorlogger.h:80
int _enabled
enable extra checks by id
Definition: settings.h:65
bool isInconclusive() const
Definition: valueflow.h:169
Style warning.
Definition: errorlogger.h:93
Performance warning.
Definition: errorlogger.h:99
Checking information.
Definition: errorlogger.h:114
static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &_settings)
bool isEnabled(EnabledGroup group) const
Returns true if given id is in the list of enabled extra checks (–enable)
Definition: settings.h:183
Settings()
Definition: settings.cpp:25
SeverityType
Message severities.
Definition: errorlogger.h:70
Portability warning.
Definition: errorlogger.h:107
Debug message.
Definition: errorlogger.h:119
const Token * condition
Condition that this value depends on.
Definition: valueflow.h:113
bool defaultArg
Is this value passed as default parameter to the function?
Definition: valueflow.h:124
No severity (default value).
Definition: errorlogger.h:74
std::string addEnabled(const std::string &str)
Enable extra checks by id.
Definition: settings.cpp:54
static bool _terminated
terminate checking
Definition: settings.h:68