Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #include "preprocessor.h" // Preprocessor
21 #include "utils.h"
22 #include "valueflow.h"
23 
24 #include <fstream>
25 #include <set>
26 
28 
30  : _enabled(0),
31  debug(false),
32  debugnormal(false),
33  debugwarnings(false),
34  dump(false),
35  exceptionHandling(false),
36  inconclusive(false),
37  jointSuppressionReport(false),
38  experimental(false),
39  quiet(false),
40  inlineSuppressions(false),
41  verbose(false),
42  force(false),
43  relativePaths(false),
44  xml(false), xml_version(1),
45  jobs(1),
46  loadAverage(0),
47  exitCode(0),
48  showtime(SHOWTIME_NONE),
49  preprocessOnly(false),
50  maxConfigs(12),
51  enforcedLang(None),
52  reportProgress(false),
53  checkConfiguration(false),
54  checkLibrary(false)
55 {
56 }
57 
58 std::string Settings::addEnabled(const std::string &str)
59 {
60  // Enable parameters may be comma separated...
61  if (str.find(',') != std::string::npos) {
62  std::string::size_type prevPos = 0;
63  std::string::size_type pos = 0;
64  while ((pos = str.find(',', pos)) != std::string::npos) {
65  if (pos == prevPos)
66  return std::string("cppcheck: --enable parameter is empty");
67  const std::string errmsg(addEnabled(str.substr(prevPos, pos - prevPos)));
68  if (!errmsg.empty())
69  return errmsg;
70  ++pos;
71  prevPos = pos;
72  }
73  if (prevPos >= str.length())
74  return std::string("cppcheck: --enable parameter is empty");
75  return addEnabled(str.substr(prevPos));
76  }
77 
78  if (str == "all") {
80  } else if (str == "warning") {
81  _enabled |= WARNING;
82  } else if (str == "style") {
83  _enabled |= STYLE;
84  } else if (str == "performance") {
86  } else if (str == "portability") {
88  } else if (str == "information") {
90  } else if (str == "unusedFunction") {
92  } else if (str == "missingInclude") {
94  }
95 #ifdef CHECK_INTERNAL
96  else if (str == "internal") {
97  _enabled |= INTERNAL;
98  }
99 #endif
100  else {
101  if (str.empty())
102  return std::string("cppcheck: --enable parameter is empty");
103  else
104  return std::string("cppcheck: there is no --enable parameter with the name '" + str + "'");
105  }
106 
107  return std::string();
108 }
109 
111 {
112  switch (severity) {
113  case Severity::none:
114  return true;
115  case Severity::error:
116  return true;
117  case Severity::warning:
118  return isEnabled(WARNING);
119  case Severity::style:
120  return isEnabled(STYLE);
122  return isEnabled(PERFORMANCE);
124  return isEnabled(PORTABILITY);
126  return isEnabled(INFORMATION);
127  case Severity::debug:
128  return false;
129  default:
130  return false;
131  }
132 }
133 
134 bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck) const
135 {
136  if (!isEnabled(Settings::WARNING) && (value->condition || value->defaultArg))
137  return false;
138  if (!inconclusive && (inconclusiveCheck || value->inconclusive))
139  return false;
140  return true;
141 }