add column number to TokenList::addtoken (#2939)

This commit is contained in:
IOBYTE 2020-12-08 04:34:23 -05:00 committed by GitHub
parent bcc7945540
commit 6103da59be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 21 deletions

View File

@ -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());

View File

@ -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());

View File

@ -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%")) {

View File

@ -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());
}

View File

@ -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);