Clang import; Handle EnumDecl without children

This commit is contained in:
Daniel Marjamäki 2020-01-26 14:35:08 +01:00
parent 5c02265041
commit 211d2e336d
1 changed files with 17 additions and 17 deletions

View File

@ -489,18 +489,22 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
scope->type = scopeType; scope->type = scopeType;
scope->classDef = def; scope->classDef = def;
scope->check = nestedIn->check; scope->check = nestedIn->check;
Token *bodyStart = children[0]->addtoken(tokenList, "{"); if (!children.empty()) {
tokenList->back()->scope(scope); Token *bodyStart = children[0]->addtoken(tokenList, "{");
for (AstNodePtr astNode: children) { tokenList->back()->scope(scope);
astNode->createTokens(tokenList); for (AstNodePtr astNode: children) {
if (!Token::Match(tokenList->back(), "[;{}]")) astNode->createTokens(tokenList);
astNode->addtoken(tokenList, ";"); if (scopeType == Scope::ScopeType::eEnum)
astNode->addtoken(tokenList, ",");
else if (!Token::Match(tokenList->back(), "[;{}]"))
astNode->addtoken(tokenList, ";");
}
Token *bodyEnd = children.back()->addtoken(tokenList, "}");
bodyStart->link(bodyEnd);
bodyEnd->link(bodyStart);
scope->bodyStart = bodyStart;
scope->bodyEnd = bodyEnd;
} }
Token *bodyEnd = children.back()->addtoken(tokenList, "}");
bodyStart->link(bodyEnd);
bodyEnd->link(bodyStart);
scope->bodyStart = bodyStart;
scope->bodyEnd = bodyEnd;
return scope; return scope;
} }
@ -769,12 +773,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
Scope *enumscope = createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok); Scope *enumscope = createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok);
if (nametok) if (nametok)
enumscope->className = nametok->str(); enumscope->className = nametok->str();
for (Token *tok = enumtok; tok; tok = tok->next()) { if (enumscope->bodyEnd && Token::simpleMatch(enumscope->bodyEnd->previous(), ", }"))
if (Token::simpleMatch(tok, "; }")) const_cast<Token *>(enumscope->bodyEnd)->deletePrevious();
tok->deleteThis();
else if (tok->str() == ";")
tok->str(",");
}
// Create enum type // Create enum type
mData->mSymbolDatabase->typeList.push_back(Type(enumtok, enumscope, enumtok->scope())); mData->mSymbolDatabase->typeList.push_back(Type(enumtok, enumscope, enumtok->scope()));