Permalink
Browse files

Refactoring various issues in cmdlineparser, cppcheckexecutor, check6…

…4bit and tokenize.
  • Loading branch information...
1 parent 8cae17f commit f4703e026a5eeba18803f4addb17dfbb47d3f322 @PKEuS PKEuS committed with aggro80 Jan 1, 2012
Showing with 105 additions and 130 deletions.
  1. +17 −28 cli/cmdlineparser.cpp
  2. +12 −13 cli/cppcheckexecutor.cpp
  3. +1 −2 lib/check64bit.cpp
  4. +75 −87 lib/tokenize.cpp
View
@@ -172,8 +172,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// Filter errors
else if (strncmp(argv[i], "--suppressions-list=", 20) == 0) {
- std::string filename = argv[i];
- filename = filename.substr(20);
+ std::string filename = argv[i]+20;
std::ifstream f(filename.c_str());
if (!f.is_open()) {
std::string message("cppcheck: Couldn't open the file: \"");
@@ -191,8 +190,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// Filter errors
// This is deprecated, see --supressions-list above
- else if (strcmp(argv[i], "--suppressions") == 0 &&
- strlen(argv[i]) == 14) {
+ else if (strcmp(argv[i], "--suppressions") == 0) {
++i;
if (i >= argc) {
@@ -216,8 +214,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
else if (strncmp(argv[i], "--suppress=", 11) == 0) {
- std::string suppression = argv[i];
- suppression = suppression.substr(11);
+ std::string suppression = argv[i]+11;
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));
if (!errmsg.empty()) {
PrintMessage(errmsg);
@@ -243,8 +240,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// Define the XML file version (and enable XML output)
else if (strncmp(argv[i], "--xml-version=", 14) == 0) {
- std::string numberString(argv[i]);
- numberString = numberString.substr(14);
+ std::string numberString(argv[i]+14);
std::istringstream iss(numberString);
if (!(iss >> _settings->_xml_version)) {
@@ -282,16 +278,15 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
return false;
}
// when "style" is enabled, also enable "performance" and "portability"
- else if (strstr(argv[i]+9, "style")) {
+ if (_settings->isEnabled("style")) {
_settings->addEnabled("performance");
_settings->addEnabled("portability");
}
}
// --error-exitcode=1
else if (strncmp(argv[i], "--error-exitcode=", 17) == 0) {
- std::string temp = argv[i];
- temp = temp.substr(17);
+ std::string temp = argv[i]+17;
std::istringstream iss(temp);
if (!(iss >> _settings->_exitCode)) {
_settings->_exitCode = 0;
@@ -307,8 +302,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "-D define"
if (strcmp(argv[i], "-D") == 0) {
++i;
- if (i >= argc || strncmp(argv[i], "-", 1) == 0 ||
- strncmp(argv[i], "--", 2) == 0) {
+ if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-D' is missing.");
return false;
}
@@ -331,8 +325,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "-U undef"
if (strcmp(argv[i], "-U") == 0) {
++i;
- if (i >= argc || strncmp(argv[i], "-", 1) == 0 ||
- strncmp(argv[i], "--", 2) == 0) {
+ if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-U' is missing.");
return false;
}
@@ -354,7 +347,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "-I path/"
if (strcmp(argv[i], "-I") == 0) {
++i;
- if (i >= argc) {
+ if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-I' is missing.");
return false;
}
@@ -391,7 +384,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "-i path/"
if (strcmp(argv[i], "-i") == 0) {
++i;
- if (i >= argc) {
+ if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-i' is missing.");
return false;
}
@@ -442,11 +435,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
// "--template path/"
if (argv[i][10] == '=')
_settings->_outputFormat = argv[i] + 11;
- else {
+ else if ((i+1) < argc && argv[i+1][0] != '-') {
++i;
- _settings->_outputFormat = (argv[i] ? argv[i] : "");
- }
- if (_settings->_outputFormat.empty()) {
+ _settings->_outputFormat = argv[i];
+ } else {
PrintMessage("cppcheck: argument to '--template' is missing.");
return false;
}
@@ -460,14 +452,13 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
// Checking threads
- else if (strcmp(argv[i], "-j") == 0 ||
- strncmp(argv[i], "-j", 2) == 0) {
+ else if (strncmp(argv[i], "-j", 2) == 0) {
std::string numberString;
// "-j 3"
if (strcmp(argv[i], "-j") == 0) {
++i;
- if (i >= argc) {
+ if (i >= argc || argv[i][0] == '-') {
PrintMessage("cppcheck: argument to '-j' is missing.");
return false;
}
@@ -476,10 +467,8 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
}
// "-j3"
- else if (strncmp(argv[i], "-j", 2) == 0) {
- numberString = argv[i];
- numberString = numberString.substr(2);
- }
+ else
+ numberString = argv[i]+2;
std::istringstream iss(numberString);
if (!(iss >> _settings->_jobs)) {
View
@@ -105,32 +105,31 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
// Remove header files from the list of ignored files.
// Also output a warning for the user.
// TODO: Remove all unknown files? (use FileLister::acceptFile())
- bool warned = false;
+ bool warn = false;
std::vector<std::string> ignored = parser.GetIgnoredPaths();
- std::vector<std::string>::iterator iterIgnored = ignored.begin();
- for (size_t i = 0 ; i < ignored.size();) {
- const std::string extension = Path::getFilenameExtension(ignored[i]);
+ for (std::vector<std::string>::iterator i = ignored.begin(); i != ignored.end();) {
+ const std::string extension = Path::getFilenameExtension(*i);
if (extension == ".h" || extension == ".hpp") {
- ignored.erase(iterIgnored + i);
- if (!warned) {
- std::cout << "cppcheck: filename exclusion does not apply to header (.h and .hpp) files." << std::endl;
- std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
- warned = true; // Warn only once
- }
+ i = ignored.erase(i);
+ warn = true;
} else
++i;
}
+ if (warn) {
+ std::cout << "cppcheck: filename exclusion does not apply to header (.h and .hpp) files." << std::endl;
+ std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
+ }
PathMatch matcher(parser.GetIgnoredPaths());
- for (size_t i = 0 ; i < filenames.size();) {
+ for (std::vector<std::string>::iterator i = filenames.begin() ; i != filenames.end();) {
#if defined(_WIN32)
// For Windows we want case-insensitive path matching
const bool caseSensitive = false;
#else
const bool caseSensitive = true;
#endif
- if (matcher.Match(filenames[i], caseSensitive))
- filenames.erase(filenames.begin() + i);
+ if (matcher.Match(*i, caseSensitive))
+ i = filenames.erase(i);
else
++i;
}
View
@@ -33,8 +33,7 @@ namespace {
/** Is given variable a pointer or array? */
static bool isaddr(const Variable *var)
{
- const Token *nametok = var ? var->nameToken() : 0;
- return (var && (nametok->strAt(-2) == "*" || nametok->strAt(-1) == "*" || nametok->strAt(1) == "["));
+ return (var && (var->isPointer() || var->isArray()));
}
/** Is given variable an integer variable */
Oops, something went wrong.

0 comments on commit f4703e0

Please sign in to comment.