reduce: add more settings from cppcheck cli
This commit is contained in:
parent
982f63d58e
commit
bf8a786265
|
@ -1790,7 +1790,8 @@ void SymbolDatabase::printOut(const char *title) const
|
|||
}
|
||||
|
||||
for (std::list<Type>::const_iterator type = typeList.begin(); type != typeList.end(); ++type) {
|
||||
std::cout << "Type: " << type->name() << std::endl;
|
||||
std::cout << "Type: " << &(*type) << std::endl;
|
||||
std::cout << " name: " << type->name() << std::endl;
|
||||
std::cout << " classDef: " << _tokenizer->list.fileLine(type->classDef) << std::endl;
|
||||
std::cout << " classScope: " << type->classScope << std::endl;
|
||||
std::cout << " enclosingScope: " << type->enclosingScope << std::endl;
|
||||
|
@ -1805,13 +1806,13 @@ void SymbolDatabase::printOut(const char *title) const
|
|||
if (type->derivedFrom[i].isVirtual)
|
||||
std::cout << "Virtual ";
|
||||
|
||||
std::cout << (type->derivedFrom[i].access == Public ? " Public " :
|
||||
type->derivedFrom[i].access == Protected ? " Protected " :
|
||||
type->derivedFrom[i].access == Private ? " Private " :
|
||||
std::cout << (type->derivedFrom[i].access == Public ? " Public" :
|
||||
type->derivedFrom[i].access == Protected ? " Protected" :
|
||||
type->derivedFrom[i].access == Private ? " Private" :
|
||||
" Unknown");
|
||||
|
||||
if (type->derivedFrom[i].type)
|
||||
std::cout << type->derivedFrom[i].type;
|
||||
std::cout << " " << type->derivedFrom[i].type;
|
||||
else
|
||||
std::cout << " Unknown";
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ void Token::update_property_isStandardType()
|
|||
if (_str.size() < 3)
|
||||
return;
|
||||
|
||||
static const char * const stdtype[] = {"int", "char", "bool", "long", "short", "float", "double", "wchar_t", "size_t", 0};
|
||||
static const char * const stdtype[] = {"int", "char", "bool", "long", "short", "float", "double", "wchar_t", "size_t", "void", 0};
|
||||
for (int i = 0; stdtype[i]; i++) {
|
||||
if (_str == stdtype[i]) {
|
||||
_isStandardType = true;
|
||||
|
|
|
@ -8880,7 +8880,7 @@ void Tokenizer::simplifyAttribute()
|
|||
void Tokenizer::simplifyKeyword()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
while (Token::Match(tok, "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__")) {
|
||||
while (Token::Match(tok, "volatile|inline|_inline|__inline|__forceinline|register|__restrict|__restrict__")) {
|
||||
tok->deleteThis();
|
||||
}
|
||||
}
|
||||
|
@ -9731,24 +9731,29 @@ void Tokenizer::simplifyReturnStrncat()
|
|||
|
||||
void Tokenizer::printUnknownTypes()
|
||||
{
|
||||
std::set<std::string> unknowns;
|
||||
std::multimap<std::string, const Token *> unknowns;
|
||||
|
||||
for (unsigned int i = 1; i <= _varId; ++i) {
|
||||
const Variable *var = _symbolDatabase->getVariableFromVarId(i);
|
||||
|
||||
// is unknown type?
|
||||
if (var && !var->type() && !var->typeStartToken()->isStandardType()) {
|
||||
std::string name;
|
||||
std::string name;
|
||||
const Token * nameTok;
|
||||
|
||||
// single token type?
|
||||
if (var->typeStartToken() == var->typeEndToken())
|
||||
if (var->typeStartToken() == var->typeEndToken()) {
|
||||
name = var->typeStartToken()->str();
|
||||
nameTok = var->typeStartToken();
|
||||
}
|
||||
|
||||
// complicated type
|
||||
else {
|
||||
const Token *tok = var->typeStartToken();
|
||||
int level = 0;
|
||||
|
||||
nameTok = tok;
|
||||
|
||||
while (tok) {
|
||||
// skip pointer and reference part of type
|
||||
if (level == 0 && (tok->str() == "*" || tok->str() == "&"))
|
||||
|
@ -9772,23 +9777,29 @@ void Tokenizer::printUnknownTypes()
|
|||
}
|
||||
}
|
||||
|
||||
unknowns.insert(name);
|
||||
unknowns.insert(std::pair<std::string, const Token *>(name, nameTok));
|
||||
}
|
||||
}
|
||||
|
||||
if (!unknowns.empty()) {
|
||||
std::ostringstream ss;
|
||||
std::multimap<std::string, const Token *>::const_iterator it;
|
||||
std::string last;
|
||||
size_t count;
|
||||
|
||||
ss << unknowns.size() << " unknown types:" << std::endl;
|
||||
|
||||
std::set<std::string>::const_iterator it;
|
||||
std::size_t count = 1;
|
||||
|
||||
for (it = unknowns.begin(); it != unknowns.end(); ++it, ++count)
|
||||
ss << count << ": " << *it << std::endl;
|
||||
|
||||
if (_errorLogger)
|
||||
_errorLogger->reportOut(ss.str());
|
||||
for (it = unknowns.begin(); it != unknowns.end(); ++it) {
|
||||
// skip types is std namespace because they are not interesting
|
||||
if (it->first.find("std::") != 0) {
|
||||
if (it->first != last) {
|
||||
last = it->first;
|
||||
count = 1;
|
||||
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
|
||||
} else {
|
||||
if (count < 3) // limit same type to 3
|
||||
reportError(it->second, Severity::debug, "debug", "Unknown type \'" + it->first + "\'.");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,11 +28,7 @@
|
|||
|
||||
class ReduceSettings : public Settings {
|
||||
public:
|
||||
ReduceSettings() : filename(0), linenr(0), hang(false), maxtime(0) {
|
||||
addEnabled("all");
|
||||
inconclusive = true;
|
||||
_force = true;
|
||||
}
|
||||
ReduceSettings() : filename(0), linenr(0), hang(false), maxtime(0) { }
|
||||
|
||||
const char *filename;
|
||||
std::size_t linenr;
|
||||
|
@ -582,6 +578,8 @@ int main(int argc, char *argv[])
|
|||
bool print = false;
|
||||
ReduceSettings settings;
|
||||
settings.maxtime = 300; // default timeout = 5 minutes
|
||||
bool def = false;
|
||||
bool maxconfigs = false;
|
||||
|
||||
for (int i = 1, includePathIndex = 0; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--stdout") == 0)
|
||||
|
@ -590,11 +588,12 @@ int main(int argc, char *argv[])
|
|||
settings.hang = true;
|
||||
else if (strncmp(argv[i],"-D", 2) == 0) {
|
||||
if (!settings.userDefines.empty())
|
||||
settings.userDefines += " ";
|
||||
settings.userDefines += ";";
|
||||
if ((strcmp(argv[i], "-D") == 0) && (i+1<argc))
|
||||
settings.userDefines += argv[++i];
|
||||
else
|
||||
settings.userDefines += argv[i] + 2;
|
||||
def = true;
|
||||
} else if (std::strncmp(argv[i], "-I", 2) == 0) {
|
||||
std::string path;
|
||||
|
||||
|
@ -617,7 +616,7 @@ int main(int argc, char *argv[])
|
|||
settings.maxtime = std::atoi(argv[i] + 10);
|
||||
else if (strncmp(argv[i],"--cfg=",6)==0) {
|
||||
if (!settings.userDefines.empty())
|
||||
settings.userDefines += " ";
|
||||
settings.userDefines += ";";
|
||||
settings.userDefines += argv[i] + 6;
|
||||
} else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
|
||||
std::string platform(11+argv[i]);
|
||||
|
@ -638,7 +637,39 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
} else if (std::strcmp(argv[i], "--debug-warnings") == 0)
|
||||
settings.debugwarnings = true;
|
||||
else if (settings.filename==NULL && strchr(argv[i],'.'))
|
||||
else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0)
|
||||
settings._force = true;
|
||||
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
|
||||
std::string errmsg = settings.addEnabled(argv[i] + 9);
|
||||
if (!errmsg.empty()) {
|
||||
errmsg.erase(0, 11); // erase "cppcheck: " from message
|
||||
std::cerr << errmsg << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// when "style" is enabled, also enable "warning", "performance" and "portability"
|
||||
if (settings.isEnabled("style")) {
|
||||
settings.addEnabled("warning");
|
||||
settings.addEnabled("performance");
|
||||
settings.addEnabled("portability");
|
||||
}
|
||||
} else if (std::strcmp(argv[i], "--inconclusive") == 0)
|
||||
settings.inconclusive = true;
|
||||
else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) {
|
||||
settings._force = false;
|
||||
|
||||
std::istringstream iss(14+argv[i]);
|
||||
if (!(iss >> settings._maxConfigs)) {
|
||||
std::cerr << "argument to '--max-configs=' is not a number." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (settings._maxConfigs < 1) {
|
||||
std::cerr << "argument to '--max-configs=' must be greater than 0." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
maxconfigs = true;
|
||||
} else if (settings.filename==NULL && strchr(argv[i],'.'))
|
||||
settings.filename = argv[i];
|
||||
else if (settings.linenr == 0U && MathLib::isInt(argv[i]))
|
||||
settings.linenr = std::atoi(argv[i]);
|
||||
|
@ -648,9 +679,15 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (def && !settings._force && !maxconfigs)
|
||||
settings._maxConfigs = 1U;
|
||||
|
||||
if (settings._force)
|
||||
settings._maxConfigs = ~0U;
|
||||
|
||||
if ((!settings.hang && settings.linenr == 0U) || settings.filename == NULL) {
|
||||
std::cerr << "Syntax:" << std::endl
|
||||
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] filename [linenr]" << std::endl;
|
||||
<< argv[0] << " [--stdout] [--cfg=X] [--hang] [--maxtime=60] [-D define] [-I includepath] [--force] [--enable=<id>] [--inconclusive] [--debug-warnings] [--max-configs=<limit>] filename [linenr]" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue