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) if (tokenList->back() != par1)
addtoken(tokenList, ","); addtoken(tokenList, ",");
addTypeTokens(tokenList, child->mExtTokens.back()); addTypeTokens(tokenList, child->mExtTokens.back());
const Token *typeEndToken = tokenList->back();
const std::string spelling = child->getSpelling(); const std::string spelling = child->getSpelling();
Token *vartok = nullptr; Token *vartok = nullptr;
if (!spelling.empty()) if (!spelling.empty())
vartok = child->addtoken(tokenList, spelling); vartok = child->addtoken(tokenList, spelling);
if (!prev) { 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) { if (vartok) {
const std::string addr = child->mExtTokens[0]; const std::string addr = child->mExtTokens[0];
mData->varDecl(addr, vartok, &function->argumentList.back()); mData->varDecl(addr, vartok, &function->argumentList.back());
@ -1235,7 +1236,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)
} }
Token *vartok1 = addtoken(tokenList, name); Token *vartok1 = addtoken(tokenList, name);
Scope *scope = const_cast<Scope *>(tokenList->back()->scope()); 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()); mData->varDecl(addr, vartok1, &scope->varlist.back());
if (mExtTokens.back() == "cinit" && !children.empty()) { if (mExtTokens.back() == "cinit" && !children.empty()) {
Token *eq = addtoken(tokenList, "="); Token *eq = addtoken(tokenList, "=");

View File

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

View File

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

View File

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