Clang import; handle {} that is not a scope better

This commit is contained in:
Daniel Marjamäki 2020-01-13 13:16:02 +01:00
parent 066e43cce3
commit a17ded3862
1 changed files with 5 additions and 1 deletions

View File

@ -179,6 +179,8 @@ namespace clangimport {
return ret; return ret;
} }
// "}" tokens that are not end-of-scope
std::set<Token *> mNotScope;
private: private:
void notFound(const std::string &addr) { void notFound(const std::string &addr) {
auto it = mNotFound.find(addr); auto it = mNotFound.find(addr);
@ -217,6 +219,7 @@ namespace clangimport {
createTokens(tokenList); createTokens(tokenList);
if (nodeType == VarDecl || nodeType == RecordDecl || nodeType == TypedefDecl) if (nodeType == VarDecl || nodeType == RecordDecl || nodeType == TypedefDecl)
addtoken(tokenList, ";"); addtoken(tokenList, ";");
mData->mNotScope.clear();
} }
private: private:
Token *createTokens(TokenList *tokenList); Token *createTokens(TokenList *tokenList);
@ -388,7 +391,7 @@ const Scope *clangimport::AstNode::getNestedInScope(TokenList *tokenList)
{ {
if (!tokenList->back()) if (!tokenList->back())
return &mData->mSymbolDatabase->scopeList.front(); return &mData->mSymbolDatabase->scopeList.front();
if (tokenList->back()->str() == "}" && !tokenList->back()->link()->astParent()) if (tokenList->back()->str() == "}" && mData->mNotScope.find(tokenList->back()) == mData->mNotScope.end())
return tokenList->back()->scope()->nestedIn; return tokenList->back()->scope()->nestedIn;
return tokenList->back()->scope(); return tokenList->back()->scope();
} }
@ -666,6 +669,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
end->scope(scope); end->scope(scope);
start->link(end); start->link(end);
end->link(start); end->link(start);
mData->mNotScope.insert(end);
return start; return start;
} }
if (nodeType == IntegerLiteral) if (nodeType == IntegerLiteral)