Refactoring; Sort options alphabetically. Removed unused --check-diff functionality.

This commit is contained in:
Daniel Marjamäki 2020-04-26 10:20:56 +02:00
parent 47c998e52d
commit 6d7dd7400d
4 changed files with 585 additions and 666 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1756,23 +1756,6 @@ void ExprEngine::executeFunction(const Scope *functionScope, const Tokenizer *to
// TODO.. what about functions in headers?
return;
if (!settings->checkDiff.empty()) {
const std::string filename = tokenizer->list.getFiles().at(functionScope->bodyStart->fileIndex());
bool check = false;
for (const auto &diff: settings->checkDiff) {
if (diff.filename != filename)
continue;
if (diff.fromLine > functionScope->bodyEnd->linenr())
continue;
if (diff.toLine < functionScope->bodyStart->linenr())
continue;
check = true;
break;
}
if (!check)
return;
}
int symbolValueIndex = 0;
TrackExecution trackExecution;
Data data(&symbolValueIndex, tokenizer, settings, callbacks, &trackExecution);

View File

@ -31,17 +31,20 @@ const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
Settings::Settings()
: mEnabled(0),
addonPython("python"),
bugHunting(false),
checkAllConfigurations(true),
checkConfiguration(false),
checkLibrary(false),
checkHeaders(true),
checkLibrary(false),
checkUnusedTemplates(false),
clang(false),
clangTidy(false),
daca(false),
debugSimplified(false),
debugBugHunting(false),
debugnormal(false),
debugwarnings(false),
debugSimplified(false),
debugtemplate(false),
debugwarnings(false),
dump(false),
enforcedLang(None),
exceptionHandling(false),
@ -49,14 +52,11 @@ Settings::Settings()
experimental(false),
force(false),
inconclusive(false),
bugHunting(false),
debugBugHunting(false),
inlineSuppressions(false),
jobs(1),
jointSuppressionReport(false),
loadAverage(0),
maxConfigs(12),
checkAllConfigurations(true),
maxCtuDepth(2),
preprocessOnly(false),
quiet(false),
@ -153,39 +153,3 @@ bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck)
return false;
return true;
}
std::vector<Settings::Diff> Settings::loadDiffFile(std::istream &istr)
{
std::vector<Settings::Diff> ret;
std::string line;
std::string filename;
while (std::getline(istr, line)) {
if (line.compare(0, 11, "diff --git ") == 0) {
std::string::size_type pos = line.rfind(" b/");
if (pos == std::string::npos)
continue;
filename = line.substr(pos+3);
}
if (line.compare(0,4,"@@ -") == 0) {
std::string::size_type pos1 = line.find(" ",4);
if (pos1 == std::string::npos)
continue;
std::string::size_type pos2 = line.find(" ",pos1 + 1);
if (pos2 == std::string::npos || pos2 < pos1+3)
continue;
if (line[pos1+1] != '+')
continue;
std::string::size_type posComma = line.find(",", pos1);
if (posComma > pos2)
continue;
std::string line1 = line.substr(pos1 + 2, posComma - pos1 - 2);
std::string line2 = line.substr(posComma+1, pos2 - posComma - 1);
Diff diff;
diff.filename = filename;
diff.fromLine = std::atoi(line1.c_str());
diff.toLine = std::atoi(line1.c_str()) + std::atoi(line2.c_str());
ret.push_back(diff);
}
}
return ret;
}

View File

@ -79,11 +79,17 @@ public:
/** @brief Paths used as base for conversion to relative paths. */
std::vector<std::string> basePaths;
/** @brief Bug hunting */
bool bugHunting;
/** Filename for bug hunting report */
std::string bugHuntingReport;
/** @brief --cppcheck-build-dir */
std::string buildDir;
/** @brief --file-filter for analyzing special files */
std::string fileFilter;
/** @brief check all configurations (false if -D or --max-configs is used */
bool checkAllConfigurations;
/** Is the 'configuration checking' wanted? */
bool checkConfiguration;
@ -91,11 +97,17 @@ public:
/** Check for incomplete info in library files? */
bool checkLibrary;
/** @brief List of selected Visual Studio configurations that should be checks */
std::list<std::string> checkVsConfigs;
/**
* Check code in the headers, this is on by default but can
* be turned off to save CPU */
bool checkHeaders;
/** @brief check unknown function return values */
std::set<std::string> checkUnknownFunctionReturn;
/** Check unused/uninstantiated templates */
bool checkUnusedTemplates;
@ -111,18 +123,21 @@ public:
/** @brief Are we running from DACA script? */
bool daca;
/** @brief Is --debug-simplified given? */
bool debugSimplified;
/** @brief Debug bug hunting */
bool debugBugHunting;
/** @brief Is --debug-normal given? */
bool debugnormal;
/** @brief Is --debug-warnings given? */
bool debugwarnings;
/** @brief Is --debug-simplified given? */
bool debugSimplified;
/** @brief Is --debug-template given? */
bool debugtemplate;
/** @brief Is --debug-warnings given? */
bool debugwarnings;
/** @brief Is --dump given? */
bool dump;
std::string dumpFile;
@ -152,6 +167,9 @@ public:
*/
bool experimental;
/** @brief --file-filter for analyzing special files */
std::string fileFilter;
/** @brief Force checking the files with "too many" configurations (--force). */
bool force;
@ -159,77 +177,9 @@ public:
for finding include files inside source files. (-I) */
std::list<std::string> includePaths;
/** @brief List of selected Visual Studio configurations that should be checks */
std::list<std::string> checkVsConfigs;
/** @brief Inconclusive checks */
bool inconclusive;
/** Do not only check how interface is used. Also check that interface is safe. */
class CPPCHECKLIB SafeChecks {
public:
SafeChecks() : classes(false), externalFunctions(false), internalFunctions(false), externalVariables(false) {}
static const char XmlRootName[];
static const char XmlClasses[];
static const char XmlExternalFunctions[];
static const char XmlInternalFunctions[];
static const char XmlExternalVariables[];
void clear() {
classes = externalFunctions = internalFunctions = externalVariables = false;
}
/**
* Public interface of classes
* - public function parameters can have any value
* - public functions can be called in any order
* - public variables can have any value
*/
bool classes;
/**
* External functions
* - external functions can be called in any order
* - function parameters can have any values
*/
bool externalFunctions;
/**
* Experimental: assume that internal functions can be used in any way
* This is only available in the GUI.
*/
bool internalFunctions;
/**
* Global variables that can be modified outside the TU.
* - Such variable can have "any" value
*/
bool externalVariables;
};
SafeChecks safeChecks;
/** @brief Bug hunting */
bool bugHunting;
/** @brief Debug bug hunting */
bool debugBugHunting;
/** Filename for bug hunting report */
std::string bugHuntingReport;
/** @brief Check diff */
struct Diff {
std::string filename;
int fromLine;
int toLine;
};
std::vector<Diff> checkDiff;
/** @brief check unknown function return values */
std::set<std::string> checkUnknownFunctionReturn;
/** @brief Is --inline-suppr given? */
bool inlineSuppressions;
@ -255,9 +205,6 @@ public:
Default is 12. (--max-configs=N) */
unsigned int maxConfigs;
/** @brief --check all configurations */
bool checkAllConfigurations;
/** @brief --max-ctu-depth */
int maxCtuDepth;
@ -308,6 +255,51 @@ public:
*/
std::list<Rule> rules;
/** Do not only check how interface is used. Also check that interface is safe. */
class CPPCHECKLIB SafeChecks {
public:
SafeChecks() : classes(false), externalFunctions(false), internalFunctions(false), externalVariables(false) {}
static const char XmlRootName[];
static const char XmlClasses[];
static const char XmlExternalFunctions[];
static const char XmlInternalFunctions[];
static const char XmlExternalVariables[];
void clear() {
classes = externalFunctions = internalFunctions = externalVariables = false;
}
/**
* Public interface of classes
* - public function parameters can have any value
* - public functions can be called in any order
* - public variables can have any value
*/
bool classes;
/**
* External functions
* - external functions can be called in any order
* - function parameters can have any values
*/
bool externalFunctions;
/**
* Experimental: assume that internal functions can be used in any way
* This is only available in the GUI.
*/
bool internalFunctions;
/**
* Global variables that can be modified outside the TU.
* - Such variable can have "any" value
*/
bool externalVariables;
};
SafeChecks safeChecks;
/** @brief show timing information (--showtime=file|summary|top5) */
SHOWTIME_MODES showtime;
@ -390,8 +382,6 @@ public:
*/
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
static std::vector<Diff> loadDiffFile(std::istream &istr);
/** Is posix library specified? */
bool posix() const {
return std::find(libraries.begin(), libraries.end(), "posix") != libraries.end();