Clang import: Fixed Variable::mTypeStartToken and Variable::mTypeEndToken for unnamed parameters

This commit is contained in:
Daniel Marjamäki 2020-11-02 20:58:43 +01:00
parent 488813d00f
commit e053066d8b
4 changed files with 14 additions and 10 deletions

View File

@ -1140,12 +1140,13 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
if (tokenList->back() != par1)
addtoken(tokenList, ",");
addTypeTokens(tokenList, child->mExtTokens.back());
const Token *typeEndToken = tokenList->back();
const std::string spelling = child->getSpelling();
Token *vartok = nullptr;
if (!spelling.empty())
vartok = child->addtoken(tokenList, spelling);
if (!prev) {
function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, i, AccessControl::Argument, nullptr, scope));
function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, typeEndToken, i, AccessControl::Argument, nullptr, scope));
if (vartok) {
const std::string addr = child->mExtTokens[0];
mData->varDecl(addr, vartok, &function->argumentList.back());
@ -1235,7 +1236,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)
}
Token *vartok1 = addtoken(tokenList, name);
Scope *scope = const_cast<Scope *>(tokenList->back()->scope());
scope->varlist.push_back(Variable(vartok1, type, startToken, 0, scope->defaultAccess(), nullptr, scope));
scope->varlist.push_back(Variable(vartok1, type, startToken, vartok1->previous(), 0, scope->defaultAccess(), nullptr, scope));
mData->varDecl(addr, vartok1, &scope->varlist.back());
if (mExtTokens.back() == "cinit" && !children.empty()) {
Token *eq = addtoken(tokenList, "=");

View File

@ -1821,12 +1821,12 @@ void SymbolDatabase::clangSetVariables(const std::vector<const Variable *> &vari
mVariableList = variableList;
}
Variable::Variable(const Token *name_, const std::string &clangType, const Token *start,
nonneg int index_, AccessControl access_, const Type *type_,
const Scope *scope_)
Variable::Variable(const Token *name_, const std::string &clangType, const Token *typeStart,
const Token *typeEnd, nonneg int index_, AccessControl access_,
const Type *type_, const Scope *scope_)
: mNameToken(name_),
mTypeStartToken(start),
mTypeEndToken(name_ ? name_->previous() : nullptr),
mTypeStartToken(typeStart),
mTypeEndToken(typeEnd),
mIndex(index_),
mAccess(access_),
mFlags(0),

View File

@ -236,9 +236,9 @@ public:
evaluate(settings);
}
Variable(const Token *name_, const std::string &clangType, const Token *start,
nonneg int index_, AccessControl access_, const Type *type_,
const Scope *scope_);
Variable(const Token *name_, const std::string &clangType, const Token *typeStart,
const Token *typeEnd, nonneg int index_, AccessControl access_,
const Type *type_, const Scope *scope_);
~Variable();

View File

@ -94,6 +94,9 @@ def test_symbol_database_3():
def test_symbol_database_4():
check_symbol_database('void f(const int x) {}')
def test_symbol_database_5():
check_symbol_database('void f(int);')
def test_symbol_database_operator():
check_symbol_database('struct Fred { void operator=(int x); };')