From 6103da59bee397d0912126742d815e5d69bb2501 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Tue, 8 Dec 2020 04:34:23 -0500 Subject: [PATCH] add column number to TokenList::addtoken (#2939) --- lib/clangimport.cpp | 3 +-- lib/symboldatabase.cpp | 14 +++++++------- lib/templatesimplifier.cpp | 12 ++++++------ lib/tokenlist.cpp | 10 ++++++---- lib/tokenlist.h | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 0e6ee48d1..4cc12ebe7 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -484,8 +484,7 @@ void clangimport::AstNode::setLocations(TokenList *tokenList, int file, int line Token *clangimport::AstNode::addtoken(TokenList *tokenList, const std::string &str, bool valueType) { const Scope *scope = getNestedInScope(tokenList); - tokenList->addtoken(str, mLine, mFile); - tokenList->back()->column(mCol); + tokenList->addtoken(str, mLine, mCol, mFile); tokenList->back()->scope(scope); if (valueType) setValueType(tokenList->back()); diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7dfa7e545..539b9b7bb 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1481,14 +1481,14 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() // In template arguments, there might not be AST // Determine size by using the "raw tokens" TokenList tokenList(mSettings); - tokenList.addtoken(";", 0, 0, false); + tokenList.addtoken(";", 0, 0, 0, false); bool fail = false; for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) { if (!tok->isName()) - tokenList.addtoken(tok->str(), 0, 0, false); + tokenList.addtoken(tok->str(), 0, 0, 0, false); else if (tok->hasKnownIntValue()) - tokenList.addtoken(std::to_string(tok->getKnownIntValue()), 0, 0, false); + tokenList.addtoken(std::to_string(tok->getKnownIntValue()), 0, 0, 0, false); else { fail = true; @@ -1499,7 +1499,7 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow() if (fail) continue; - tokenList.addtoken(";", 0, 0, false); + tokenList.addtoken(";", 0, 0, 0, false); for (Token *tok = tokenList.front(); tok;) { if (TemplateSimplifier::simplifyNumericCalculations(tok, false)) @@ -5860,11 +5860,11 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V do { std::string::size_type pos2 = type->str().find("::", pos1); if (pos2 == std::string::npos) { - typeTokens.addtoken(type->str().substr(pos1), 0, 0, false); + typeTokens.addtoken(type->str().substr(pos1), 0, 0, 0, false); break; } - typeTokens.addtoken(type->str().substr(pos1, pos2 - pos1), 0, 0, false); - typeTokens.addtoken("::", 0, 0, false); + typeTokens.addtoken(type->str().substr(pos1, pos2 - pos1), 0, 0, 0, false); + typeTokens.addtoken("::", 0, 0, 0, false); pos1 = pos2 + 2; } while (pos1 < type->str().size()); const Library::Container *container = settings->library.detectContainer(typeTokens.front()); diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index c3814f8f5..7f487f4a9 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1534,7 +1534,7 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c if (insert) mTokenList.back()->tokAt(offset)->insertToken(token, ""); else - mTokenList.addtoken(token, tok->linenr(), tok->fileIndex()); + mTokenList.addtoken(token, tok->linenr(), tok->column(), tok->fileIndex()); } start = end + 1; } @@ -1549,10 +1549,10 @@ void TemplateSimplifier::addNamespace(const TokenAndName &templateDeclaration, c mTokenList.back()->tokAt(offset)->insertToken("::", ""); } else { if (!inTemplate) - mTokenList.addtoken(templateDeclaration.scope().substr(start), tok->linenr(), tok->fileIndex()); + mTokenList.addtoken(templateDeclaration.scope().substr(start), tok->linenr(), tok->column(), tok->fileIndex()); else mTokenList.back()->str(mTokenList.back()->str() + templateDeclaration.scope().substr(start)); - mTokenList.addtoken("::", tok->linenr(), tok->fileIndex()); + mTokenList.addtoken("::", tok->linenr(), tok->column(), tok->fileIndex()); } } } @@ -1906,7 +1906,7 @@ void TemplateSimplifier::expandTemplate( if (copy) { if (!templateDeclaration.scope().empty() && tok5->strAt(-1) != "::") addNamespace(templateDeclaration, tok5); - mTokenList.addtoken(newName, tok5->linenr(), tok5->fileIndex()); + mTokenList.addtoken(newName, tok5->linenr(), tok5->column(), tok5->fileIndex()); tok5 = tok5->next()->findClosingBracket(); } else { tok5->str(newName); @@ -1992,7 +1992,7 @@ void TemplateSimplifier::expandTemplate( if (copy) { if (!templateDeclaration.scope().empty() && tok3->strAt(-1) != "::") addNamespace(templateDeclaration, tok3); - mTokenList.addtoken(newName, tok3->linenr(), tok3->fileIndex()); + mTokenList.addtoken(newName, tok3->linenr(), tok3->column(), tok3->fileIndex()); } while (tok3 && tok3->str() != "::") @@ -2204,7 +2204,7 @@ void TemplateSimplifier::expandTemplate( Token::createMutualLinks(brackets.top(), mTokenList.back()); if (tok3->strAt(1) == ";") { const Token * tokSemicolon = tok3->next(); - mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->fileIndex()); + mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->column(), tokSemicolon->fileIndex()); } brackets.pop(); if (brackets.empty() && !Token::Match(tok3, "} >|,|{|%cop%")) { diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 504ce5789..bfa601c87 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -187,7 +187,7 @@ void TokenList::deleteTokens(Token *tok) // add a token. //--------------------------------------------------------------------------- -void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg int fileno, bool split) +void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg int column, const nonneg int fileno, bool split) { if (str.empty()) return; @@ -198,11 +198,11 @@ void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg size_t end = 0; while ((end = str.find("##", begin)) != std::string::npos) { addtoken(str.substr(begin, end - begin), lineno, fileno, false); - addtoken("##", lineno, fileno, false); + addtoken("##", lineno, column, fileno, false); begin = end+2; } if (begin != 0) { - addtoken(str.substr(begin), lineno, fileno, false); + addtoken(str.substr(begin), lineno, column, fileno, false); return; } } @@ -216,6 +216,7 @@ void TokenList::addtoken(std::string str, const nonneg int lineno, const nonneg } mTokensFrontBack.back->linenr(lineno); + mTokensFrontBack.back->column(column); mTokensFrontBack.back->fileIndex(fileno); } @@ -237,7 +238,7 @@ void TokenList::addtoken(std::string str, const Token *locationTok) mTokensFrontBack.back->fileIndex(locationTok->fileIndex()); } -void TokenList::addtoken(const Token * tok, const nonneg int lineno, const nonneg int fileno) +void TokenList::addtoken(const Token * tok, const nonneg int lineno, const nonneg int column, const nonneg int fileno) { if (tok == nullptr) return; @@ -253,6 +254,7 @@ void TokenList::addtoken(const Token * tok, const nonneg int lineno, const nonne } mTokensFrontBack.back->linenr(lineno); + mTokensFrontBack.back->column(column); mTokensFrontBack.back->fileIndex(fileno); mTokensFrontBack.back->flags(tok->flags()); } diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 8a92a2d2e..44912298a 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -68,10 +68,10 @@ public: */ static void deleteTokens(Token *tok); - void addtoken(std::string str, const nonneg int lineno, const nonneg int fileno, bool split = false); + void addtoken(std::string str, const nonneg int lineno, const nonneg int column, const nonneg int fileno, bool split = false); void addtoken(std::string str, const Token *locationTok); - void addtoken(const Token *tok, const nonneg int lineno, const nonneg int fileno); + void addtoken(const Token *tok, const nonneg int lineno, const nonneg int column, const nonneg int fileno); void addtoken(const Token *tok, const Token *locationTok); void addtoken(const Token *tok);