Clang import; distinguish static variable
This commit is contained in:
parent
830f901206
commit
b1abcc06df
|
@ -1077,7 +1077,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
|
|||
Token *vartok = nullptr;
|
||||
if (!spelling.empty())
|
||||
vartok = child->addtoken(tokenList, spelling);
|
||||
scope.function->argumentList.push_back(Variable(vartok, child->getType(), i, AccessControl::Argument, nullptr, &scope));
|
||||
scope.function->argumentList.push_back(Variable(vartok, child->getType(), nullptr, i, AccessControl::Argument, nullptr, &scope));
|
||||
if (vartok) {
|
||||
const std::string addr = child->mExtTokens[0];
|
||||
mData->varDecl(addr, vartok, &scope.function->argumentList.back());
|
||||
|
@ -1127,6 +1127,9 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
|
|||
Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)
|
||||
{
|
||||
const std::string addr = mExtTokens.front();
|
||||
const Token *startToken = nullptr;
|
||||
if (std::find(mExtTokens.cbegin(), mExtTokens.cend(), "static") != mExtTokens.cend())
|
||||
startToken = addtoken(tokenList, "static");
|
||||
int typeIndex = mExtTokens.size() - 1;
|
||||
while (typeIndex > 1 && std::isalpha(mExtTokens[typeIndex][0]))
|
||||
typeIndex--;
|
||||
|
@ -1136,7 +1139,7 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList)
|
|||
Token *vartok1 = addtoken(tokenList, name);
|
||||
Scope *scope = const_cast<Scope *>(tokenList->back()->scope());
|
||||
const AccessControl accessControl = (scope->type == Scope::ScopeType::eGlobal) ? (AccessControl::Global) : (AccessControl::Local);
|
||||
scope->varlist.push_back(Variable(vartok1, type, 0, accessControl, nullptr, scope));
|
||||
scope->varlist.push_back(Variable(vartok1, type, startToken, 0, accessControl, nullptr, scope));
|
||||
mData->varDecl(addr, vartok1, &scope->varlist.back());
|
||||
if (mExtTokens.back() == "cinit") {
|
||||
Token *eq = addtoken(tokenList, "=");
|
||||
|
|
|
@ -1723,7 +1723,7 @@ void SymbolDatabase::clangSetVariables(const std::vector<const Variable *> &vari
|
|||
mVariableList = variableList;
|
||||
}
|
||||
|
||||
Variable::Variable(const Token *name_, const std::string &clangType,
|
||||
Variable::Variable(const Token *name_, const std::string &clangType, const Token *start,
|
||||
nonneg int index_, AccessControl access_, const Type *type_,
|
||||
const Scope *scope_)
|
||||
: mNameToken(name_),
|
||||
|
@ -1736,6 +1736,8 @@ Variable::Variable(const Token *name_, const std::string &clangType,
|
|||
mScope(scope_),
|
||||
mValueType(nullptr)
|
||||
{
|
||||
if (start && start->str() == "static")
|
||||
setFlag(fIsStatic, true);
|
||||
|
||||
std::string::size_type pos = clangType.find("[");
|
||||
if (pos != std::string::npos) {
|
||||
|
|
|
@ -237,7 +237,7 @@ public:
|
|||
evaluate(settings);
|
||||
}
|
||||
|
||||
Variable(const Token *name_, const std::string &clangType,
|
||||
Variable(const Token *name_, const std::string &clangType, const Token *start,
|
||||
nonneg int index_, AccessControl access_, const Type *type_,
|
||||
const Scope *scope_);
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
TEST_CASE(vardecl3);
|
||||
TEST_CASE(vardecl4);
|
||||
TEST_CASE(vardecl5);
|
||||
TEST_CASE(vardecl6);
|
||||
TEST_CASE(whileStmt1);
|
||||
TEST_CASE(whileStmt2);
|
||||
|
||||
|
@ -819,6 +820,12 @@ private:
|
|||
ASSERT_EQUALS("const char *const [] sys_errlist@1 ;", parse(clang));
|
||||
}
|
||||
|
||||
void vardecl6() {
|
||||
const char clang[] = "`-VarDecl 0x278e170 <1.c:1:1, col:16> col:12 x 'int' static cinit\n"
|
||||
" `-IntegerLiteral 0x278e220 <col:16> 'int' 3";
|
||||
ASSERT_EQUALS("static int x@1 = 3 ;", parse(clang));
|
||||
}
|
||||
|
||||
void whileStmt1() {
|
||||
const char clang[] = "`-FunctionDecl 0x3d45b18 <1.c:1:1, line:3:1> line:1:6 foo 'void ()'\n"
|
||||
" `-CompoundStmt 0x3d45c48 <col:12, line:3:1>\n"
|
||||
|
|
Loading…
Reference in New Issue