Some refactorizations
This commit is contained in:
parent
bfb4dd6425
commit
2ba2a4e6ae
|
@ -68,7 +68,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Return the path names user gave to command line.
|
* Return the path names user gave to command line.
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> GetPathNames() const {
|
const std::vector<std::string>& GetPathNames() const {
|
||||||
return _pathnames;
|
return _pathnames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Return a list of paths user wants to ignore.
|
* Return a list of paths user wants to ignore.
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> GetIgnoredPaths() const {
|
const std::vector<std::string>& GetIgnoredPaths() const {
|
||||||
return _ignoredPaths;
|
return _ignoredPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
const char * extraVersion = cppcheck->extraVersion();
|
const char * extraVersion = cppcheck->extraVersion();
|
||||||
if (strlen(extraVersion) > 0)
|
if (strlen(extraVersion) > 0)
|
||||||
std::cout << "Cppcheck " << cppcheck->version() << " ("
|
std::cout << "Cppcheck " << cppcheck->version() << " ("
|
||||||
<< extraVersion << ")" << std::endl;
|
<< extraVersion << ')' << std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "Cppcheck " << cppcheck->version() << std::endl;
|
std::cout << "Cppcheck " << cppcheck->version() << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
else {
|
else {
|
||||||
// If the include path is not found, warn user and remove the
|
// If the include path is not found, warn user and remove the
|
||||||
// non-existing path from the list.
|
// non-existing path from the list.
|
||||||
std::cout << "cppcheck: warning: Couldn't find path given by -I '" + path + "'" << std::endl;
|
std::cout << "cppcheck: warning: Couldn't find path given by -I '" << path << '\'' << std::endl;
|
||||||
iter = _settings._includePaths.erase(iter);
|
iter = _settings._includePaths.erase(iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
ostr << "progress: "
|
ostr << "progress: "
|
||||||
<< stage
|
<< stage
|
||||||
<< " " << int(value) << "%";
|
<< ' ' << int(value) << '%';
|
||||||
if (_settings._verbose)
|
if (_settings._verbose)
|
||||||
ostr << " time=" << str.substr(11, 8);
|
ostr << " time=" << str.substr(11, 8);
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ void CppCheckExecutor::reportStatus(size_t fileindex, size_t filecount, long siz
|
||||||
{
|
{
|
||||||
if (filecount > 1) {
|
if (filecount > 1) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << fileindex << "/" << filecount
|
oss << fileindex << '/' << filecount
|
||||||
<< " files checked " <<
|
<< " files checked " <<
|
||||||
(sizetotal > 0 ? static_cast<long>(static_cast<long double>(sizedone) / sizetotal*100) : 0)
|
(sizetotal > 0 ? static_cast<long>(static_cast<long double>(sizedone) / sizetotal*100) : 0)
|
||||||
<< "% done";
|
<< "% done";
|
||||||
|
|
|
@ -277,7 +277,7 @@ std::string ErrorLogger::ErrorMessage::toString(bool verbose, const std::string
|
||||||
if (!_callStack.empty())
|
if (!_callStack.empty())
|
||||||
text << callStackToString(_callStack) << ": ";
|
text << callStackToString(_callStack) << ": ";
|
||||||
if (_severity != Severity::none)
|
if (_severity != Severity::none)
|
||||||
text << "(" << Severity::toString(_severity) << ") ";
|
text << '(' << Severity::toString(_severity) << ") ";
|
||||||
text << (verbose ? _verboseMessage : _shortMessage);
|
text << (verbose ? _verboseMessage : _shortMessage);
|
||||||
return text.str();
|
return text.str();
|
||||||
}
|
}
|
||||||
|
@ -316,10 +316,10 @@ std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMes
|
||||||
{
|
{
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = callStack.begin(); tok != callStack.end(); ++tok) {
|
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = callStack.begin(); tok != callStack.end(); ++tok) {
|
||||||
ostr << (tok == callStack.begin() ? "" : " -> ") << "[" << (*tok).getfile();
|
ostr << (tok == callStack.begin() ? "" : " -> ") << '[' << (*tok).getfile();
|
||||||
if ((*tok).line != 0)
|
if ((*tok).line != 0)
|
||||||
ostr << ":" << (*tok).line;
|
ostr << ':' << (*tok).line;
|
||||||
ostr << "]";
|
ostr << ']';
|
||||||
}
|
}
|
||||||
return ostr.str();
|
return ostr.str();
|
||||||
}
|
}
|
||||||
|
|
35
lib/path.cpp
35
lib/path.cpp
|
@ -80,7 +80,7 @@ std::string Path::simplifyPath(const char *originalPath)
|
||||||
if (subPath.length() > 0)
|
if (subPath.length() > 0)
|
||||||
pathParts.push_back(subPath);
|
pathParts.push_back(subPath);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < pathParts.size(); ++i) {
|
for (unsigned int i = 1; i < pathParts.size(); ++i) {
|
||||||
if (i > 1 && pathParts[i-2] != ".." && pathParts[i] == ".." && pathParts.size() > i + 1) {
|
if (i > 1 && pathParts[i-2] != ".." && pathParts[i] == ".." && pathParts.size() > i + 1) {
|
||||||
pathParts.erase(pathParts.begin() + static_cast<int>(i) + 1);
|
pathParts.erase(pathParts.begin() + static_cast<int>(i) + 1);
|
||||||
pathParts.erase(pathParts.begin() + static_cast<int>(i));
|
pathParts.erase(pathParts.begin() + static_cast<int>(i));
|
||||||
|
@ -90,7 +90,7 @@ std::string Path::simplifyPath(const char *originalPath)
|
||||||
} else if (i > 0 && pathParts[i] == ".") {
|
} else if (i > 0 && pathParts[i] == ".") {
|
||||||
pathParts.erase(pathParts.begin() + static_cast<int>(i));
|
pathParts.erase(pathParts.begin() + static_cast<int>(i));
|
||||||
i = 0;
|
i = 0;
|
||||||
} else if (pathParts[i] == "/" && i > 0 && pathParts[i-1] == "/") {
|
} else if (i > 0 && pathParts[i] == "/" && pathParts[i-1] == "/") {
|
||||||
pathParts.erase(pathParts.begin() + static_cast<int>(i) - 1);
|
pathParts.erase(pathParts.begin() + static_cast<int>(i) - 1);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
@ -158,11 +158,7 @@ bool Path::isC(const std::string &path)
|
||||||
{
|
{
|
||||||
// In unix, ".C" is concidered C++ file
|
// In unix, ".C" is concidered C++ file
|
||||||
const std::string extension = getFilenameExtension(path);
|
const std::string extension = getFilenameExtension(path);
|
||||||
if (extension == ".c") {
|
return(extension == ".c");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::isCPP(const std::string &path)
|
bool Path::isCPP(const std::string &path)
|
||||||
|
@ -178,40 +174,23 @@ bool Path::isCPP(const std::string &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// In unix, ".C" is concidered C++ file
|
// In unix, ".C" is concidered C++ file
|
||||||
if (getFilenameExtension(path) == ".C") {
|
return(getFilenameExtension(path) == ".C");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::isJava(const std::string &path)
|
bool Path::isJava(const std::string &path)
|
||||||
{
|
{
|
||||||
const std::string extension = getFilenameExtensionInLowerCase(path);
|
const std::string extension = getFilenameExtensionInLowerCase(path);
|
||||||
if (extension == ".java") {
|
return(extension == ".java");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::isCSharp(const std::string &path)
|
bool Path::isCSharp(const std::string &path)
|
||||||
{
|
{
|
||||||
const std::string extension = getFilenameExtensionInLowerCase(path);
|
const std::string extension = getFilenameExtensionInLowerCase(path);
|
||||||
if (extension == ".cs") {
|
return(extension == ".cs");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::acceptFile(const std::string &filename)
|
bool Path::acceptFile(const std::string &filename)
|
||||||
{
|
{
|
||||||
if (Path::isCPP(filename) ||
|
return(Path::isCPP(filename) || Path::isC(filename));
|
||||||
Path::isC(filename)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,21 +27,18 @@ class Token;
|
||||||
class givenACodeSampleToTokenize {
|
class givenACodeSampleToTokenize {
|
||||||
private:
|
private:
|
||||||
std::istringstream _sample;
|
std::istringstream _sample;
|
||||||
const Token* _tokens;
|
|
||||||
Settings _settings;
|
Settings _settings;
|
||||||
Tokenizer _tokenizer;
|
Tokenizer _tokenizer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
givenACodeSampleToTokenize(const std::string& sample)
|
givenACodeSampleToTokenize(const std::string& sample)
|
||||||
: _sample(sample)
|
: _sample(sample)
|
||||||
,_tokens(NULL) {
|
, _tokenizer(&_settings, 0) {
|
||||||
_tokenizer.setSettings(&_settings);
|
|
||||||
_tokenizer.tokenize(_sample, "test.cpp");
|
_tokenizer.tokenize(_sample, "test.cpp");
|
||||||
_tokens = _tokenizer.tokens();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token* tokens() const {
|
const Token* tokens() const {
|
||||||
return _tokens;
|
return _tokenizer.tokens();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue