Clang import: Fix Variable::isReference

This commit is contained in:
Daniel Marjamäki 2020-11-09 20:35:00 +01:00
parent 0ac4de2a5e
commit 970beaa79a
2 changed files with 15 additions and 1 deletions

View File

@ -1349,7 +1349,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, vartok1->previous(), 0, scope->defaultAccess(), recordType, scope)); scope->varlist.push_back(Variable(vartok1, unquote(type), startToken, vartok1->previous(), 0, scope->defaultAccess(), recordType, 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

@ -107,6 +107,7 @@ private:
TEST_CASE(symbolDatabaseFunction2); TEST_CASE(symbolDatabaseFunction2);
TEST_CASE(symbolDatabaseFunction3); TEST_CASE(symbolDatabaseFunction3);
TEST_CASE(symbolDatabaseFunctionConst); TEST_CASE(symbolDatabaseFunctionConst);
TEST_CASE(symbolDatabaseVariableRef);
TEST_CASE(symbolDatabaseNodeType1); TEST_CASE(symbolDatabaseNodeType1);
TEST_CASE(valueFlow1); TEST_CASE(valueFlow1);
@ -1058,6 +1059,19 @@ private:
ASSERT(func.isConst()); ASSERT(func.isConst());
} }
void symbolDatabaseVariableRef() {
const char clang[] = "`-FunctionDecl 0x1593df0 <3.cpp:1:1, line:4:1> line:1:6 foo 'void ()'\n"
" `-CompoundStmt 0x15940b0 <col:12, line:4:1>\n"
" |-DeclStmt 0x1593f58 <line:2:3, col:8>\n"
" | `-VarDecl 0x1593ef0 <col:3, col:7> col:7 used x 'int'\n"
" `-DeclStmt 0x1594098 <line:3:3, col:15>\n"
" `-VarDecl 0x1593fb8 <col:3, col:14> col:8 ref 'int &' cinit\n"
" `-DeclRefExpr 0x1594020 <col:14> 'int' lvalue Var 0x1593ef0 'x' 'int'";
GET_SYMBOL_DB(clang);
const Variable *refVar = db->variableList().back();
ASSERT(refVar->isReference());
}
void symbolDatabaseNodeType1() { void symbolDatabaseNodeType1() {
const char clang[] = "`-FunctionDecl 0x32438c0 <line:5:1, line:7:1> line:5:6 foo 'a::b (a::b)'\n" const char clang[] = "`-FunctionDecl 0x32438c0 <line:5:1, line:7:1> line:5:6 foo 'a::b (a::b)'\n"
" |-ParmVarDecl 0x32437b0 <col:10, col:15> col:15 used i 'a::b':'long'\n" " |-ParmVarDecl 0x32437b0 <col:10, col:15> col:15 used i 'a::b':'long'\n"