Several small refactorizations
This commit is contained in:
parent
7fc9fbc746
commit
cfac3b457d
|
@ -82,7 +82,7 @@ void FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, co
|
|||
const bool checkAllFilesInDir = (MyIsDirectory(cleanedPath) != FALSE);
|
||||
|
||||
if (checkAllFilesInDir) {
|
||||
char c = cleanedPath[ cleanedPath.size()-1 ];
|
||||
char c = cleanedPath.back();
|
||||
switch (c) {
|
||||
case '\\':
|
||||
searchPattern += '*';
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <cassert> // <- assert
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ void CheckSizeof::sizeofCalculation()
|
|||
if (tok->isExpandedMacro() && tok->previous()) {
|
||||
const Token *cast_end = (tok->previous()->str() == "(") ? tok->previous() : tok;
|
||||
if (Token::simpleMatch(cast_end->tokAt(-3), "( void )") ||
|
||||
Token::simpleMatch(cast_end->tokAt(-1), "static_cast<void>")) {
|
||||
Token::simpleMatch(cast_end->previous(), "static_cast<void>")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1554,7 +1554,7 @@ void CheckStl::readingEmptyStlContainer()
|
|||
if (var && !var->isArrayOrPointer() && !var->typeStartToken()->isStandardType()) {
|
||||
bool insert = false;
|
||||
if (var->nameToken() == tok && var->isLocal() && !var->isStatic()) { // Local variable declared
|
||||
insert = !Token::Match(tok->tokAt(1), "[(=]"); // Only if not initialized
|
||||
insert = !Token::Match(tok->next(), "[(=]"); // Only if not initialized
|
||||
} else if (Token::Match(tok, "%var% . clear ( ) ;")) {
|
||||
insert = true;
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ std::string Path::getRelativePath(const std::string& absolutePath, const std::ve
|
|||
if (absolutePath == *i || i->empty()) // Seems to be a file, or path is empty
|
||||
continue;
|
||||
|
||||
bool endsWithSep = (*i)[i->length()-1] == '/';
|
||||
bool endsWithSep = i->back() == '/';
|
||||
if (absolutePath.compare(0, i->length(), *i) == 0 && absolutePath[i->length() - (endsWithSep?1:0)] == '/') {
|
||||
std::string rest = absolutePath.substr(i->length() + (endsWithSep?0:1));
|
||||
return rest;
|
||||
|
|
|
@ -43,8 +43,8 @@ bool PathMatch::Match(const std::string &path) const
|
|||
std::transform(findpath.begin(), findpath.end(), findpath.begin(), ::tolower);
|
||||
|
||||
// Filtering directory name
|
||||
if (excludedPath[excludedPath.length() - 1] == '/') {
|
||||
if (findpath[findpath.length() - 1] != '/')
|
||||
if (excludedPath.back() == '/') {
|
||||
if (findpath.back() != '/')
|
||||
findpath = RemoveFilename(findpath);
|
||||
|
||||
if (excludedPath.length() > findpath.length())
|
||||
|
|
|
@ -1400,12 +1400,11 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
|
||||
// skip over qualification
|
||||
while (Token::simpleMatch(tok1, "::")) {
|
||||
if (Token::Match(tok1->tokAt(-1), "%name%"))
|
||||
tok1 = tok1->tokAt(-2);
|
||||
else if (tok1->strAt(-1) == ">" && tok1->linkAt(-1) && Token::Match(tok1->linkAt(-1)->previous(), "%name%"))
|
||||
tok1 = tok1->linkAt(-1)->tokAt(-2);
|
||||
else
|
||||
tok1 = tok1->tokAt(-1);
|
||||
tok1 = tok1->previous();
|
||||
if (Token::Match(tok1, "%name%"))
|
||||
tok1 = tok1->previous();
|
||||
else if (tok1 && tok1->str() == ">" && tok1->link() && Token::Match(tok1->link()->previous(), "%name%"))
|
||||
tok1 = tok1->link()->tokAt(-2);
|
||||
}
|
||||
|
||||
// skip over const, noexcept, throw and override specifiers
|
||||
|
@ -1428,7 +1427,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
if (!Token::Match(tok1, "{|}|;|public:|protected:|private:") && tok1) {
|
||||
// skip over pointers and references
|
||||
while (Token::Match(tok1, "[*&]"))
|
||||
tok1 = tok1->tokAt(-1);
|
||||
tok1 = tok1->previous();
|
||||
|
||||
// skip over template
|
||||
if (tok1 && tok1->str() == ">") {
|
||||
|
@ -1451,10 +1450,9 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
|
||||
// skip over qualification
|
||||
while (Token::simpleMatch(tok1, "::")) {
|
||||
if (Token::Match(tok1->tokAt(-1), "%name%"))
|
||||
tok1 = tok1->tokAt(-2);
|
||||
else
|
||||
tok1 = tok1->tokAt(-1);
|
||||
tok1 = tok1->previous();
|
||||
if (Token::Match(tok1, "%name%"))
|
||||
tok1 = tok1->previous();
|
||||
}
|
||||
|
||||
// skip over modifiers and other stuff
|
||||
|
@ -1497,7 +1495,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
|||
const Token* tok2 = tok->next()->link()->next()->link();
|
||||
if (Token::Match(tok2, ") const| ;|{|=") ||
|
||||
Token::Match(tok2, ") : ::| %name% (|::|<|{") ||
|
||||
Token::Match(tok->next()->link()->next()->link(), ") const| noexcept {|;|(")) {
|
||||
Token::Match(tok2, ") const| noexcept {|;|(")) {
|
||||
*funcStart = tok;
|
||||
*argStart = tok2->link();
|
||||
*declEnd = Token::findmatch(tok2->next(), "{|;");
|
||||
|
@ -4541,7 +4539,7 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
|
|||
if (tok->isNumber()) {
|
||||
if (MathLib::isFloat(tok->str())) {
|
||||
ValueType::Type type = ValueType::Type::DOUBLE;
|
||||
const char suffix = tok->str()[tok->str().size() - 1U];
|
||||
const char suffix = tok->str().back();
|
||||
if (suffix == 'f' || suffix == 'F')
|
||||
type = ValueType::Type::FLOAT;
|
||||
else if (suffix == 'L' || suffix == 'l')
|
||||
|
|
|
@ -1831,7 +1831,7 @@ void Tokenizer::combineOperators()
|
|||
Token::Match(tok, "private|protected|public|__published : !!:")) {
|
||||
bool simplify = false;
|
||||
unsigned int par = 0U;
|
||||
for (const Token *prev = tok->tokAt(-1); prev; prev = prev->previous()) {
|
||||
for (const Token *prev = tok->previous(); prev; prev = prev->previous()) {
|
||||
if (prev->str() == ")") {
|
||||
++par;
|
||||
} else if (prev->str() == "(") {
|
||||
|
@ -1847,7 +1847,7 @@ void Tokenizer::combineOperators()
|
|||
}
|
||||
if (prev->isName() && prev->isUpperCaseName())
|
||||
continue;
|
||||
if (prev->isName() && prev->str()[prev->str().size() - 1U] == ':')
|
||||
if (prev->isName() && prev->str().back() == ':')
|
||||
simplify = true;
|
||||
break;
|
||||
}
|
||||
|
@ -2635,7 +2635,7 @@ void Tokenizer::setVarIdPass1()
|
|||
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
|
||||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
|
||||
(tok->str() == "," && !scopeStack.top().isExecutable) ||
|
||||
(tok->isName() && tok->str().at(tok->str().length()-1U) == ':'))) {
|
||||
(tok->isName() && tok->str().back() == ':'))) {
|
||||
|
||||
// No variable declarations in sizeof
|
||||
if (Token::simpleMatch(tok->previous(), "sizeof (")) {
|
||||
|
@ -2649,7 +2649,7 @@ void Tokenizer::setVarIdPass1()
|
|||
const Token *tok2 = (tok->isName()) ? tok : tok->next();
|
||||
|
||||
// private: protected: public: etc
|
||||
while (tok2 && tok2->str()[tok2->str().size() - 1U] == ':') {
|
||||
while (tok2 && tok2->str().back() == ':') {
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
if (!tok2)
|
||||
|
@ -5659,7 +5659,7 @@ void Tokenizer::simplifyPlatformTypes()
|
|||
// skip when non-global namespace defined
|
||||
if (tok1 && tok1->tokType() == Token::eName)
|
||||
continue;
|
||||
tok = tok->tokAt(-1);
|
||||
tok = tok->previous();
|
||||
tok->deleteThis();
|
||||
}
|
||||
Token *typeToken;
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
TestLibrary() : TestFixture("TestLibrary") { }
|
||||
|
||||
private:
|
||||
Settings settings;
|
||||
|
||||
void run() {
|
||||
TEST_CASE(empty);
|
||||
|
@ -375,7 +376,6 @@ private:
|
|||
ASSERT_EQUALS(library.functions.size(), 1U);
|
||||
|
||||
{
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, nullptr);
|
||||
std::istringstream istr("CString str; str.Format();");
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
@ -383,7 +383,6 @@ private:
|
|||
}
|
||||
|
||||
{
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, nullptr);
|
||||
std::istringstream istr("HardDrive hd; hd.Format();");
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
@ -403,7 +402,6 @@ private:
|
|||
readLibrary(library, xmldata);
|
||||
|
||||
{
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, nullptr);
|
||||
std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };");
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
@ -411,7 +409,6 @@ private:
|
|||
}
|
||||
|
||||
{
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, nullptr);
|
||||
std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };");
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI(), &outputList);
|
||||
|
||||
if (errorLogger) {
|
||||
Settings settings;
|
||||
static Settings settings;
|
||||
Preprocessor p(settings, errorLogger);
|
||||
p.reportOutput(outputList, true);
|
||||
}
|
||||
|
@ -1923,7 +1923,6 @@ private:
|
|||
void predefine5() { // #3737, #5119 - automatically define __cplusplus
|
||||
// #3737...
|
||||
const char code[] = "#ifdef __cplusplus\n123\n#endif";
|
||||
Settings settings;
|
||||
ASSERT_EQUALS("", preprocessor0.getcode(code, "X=123", "test.c"));
|
||||
ASSERT_EQUALS("\n123", preprocessor0.getcode(code, "X=123", "test.cpp"));
|
||||
}
|
||||
|
@ -2146,12 +2145,10 @@ private:
|
|||
|
||||
|
||||
void validateCfg() {
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(settings, this);
|
||||
Preprocessor preprocessor(settings0, this);
|
||||
|
||||
std::list<simplecpp::MacroUsage> macroUsageList;
|
||||
std::vector<std::string> files;
|
||||
files.push_back("test.c");
|
||||
std::vector<std::string> files(1, "test.c");
|
||||
simplecpp::MacroUsage macroUsage(files);
|
||||
macroUsage.useLocation.fileIndex = 0;
|
||||
macroUsage.useLocation.line = 1;
|
||||
|
@ -2247,8 +2244,7 @@ private:
|
|||
" </directivelist>\n";
|
||||
|
||||
std::ostringstream ostr;
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(settings, this);
|
||||
Preprocessor preprocessor(settings0, this);
|
||||
preprocessor.getcode(filedata, "", "test.c");
|
||||
preprocessor.dump(ostr);
|
||||
ASSERT_EQUALS(dumpdata, ostr.str());
|
||||
|
@ -2275,8 +2271,7 @@ private:
|
|||
" </directivelist>\n";
|
||||
|
||||
std::ostringstream ostr;
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(settings, this);
|
||||
Preprocessor preprocessor(settings0, this);
|
||||
preprocessor.getcode(filedata, "", "test.c");
|
||||
preprocessor.dump(ostr);
|
||||
ASSERT_EQUALS(dumpdata, ostr.str());
|
||||
|
@ -2293,8 +2288,7 @@ private:
|
|||
" </directivelist>\n";
|
||||
|
||||
std::ostringstream ostr;
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(settings, this);
|
||||
Preprocessor preprocessor(settings0, this);
|
||||
preprocessor.getcode(filedata, "", "test.c");
|
||||
preprocessor.dump(ostr);
|
||||
ASSERT_EQUALS(dumpdata, ostr.str());
|
||||
|
|
Loading…
Reference in New Issue