From 211d2e336d6bb7f0c7d73f59e296ec99c922bf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 26 Jan 2020 14:35:08 +0100 Subject: [PATCH] Clang import; Handle EnumDecl without children --- lib/clangimport.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index ea19dc26b..ce5d30e25 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -489,18 +489,22 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType scope->type = scopeType; scope->classDef = def; scope->check = nestedIn->check; - Token *bodyStart = children[0]->addtoken(tokenList, "{"); - tokenList->back()->scope(scope); - for (AstNodePtr astNode: children) { - astNode->createTokens(tokenList); - if (!Token::Match(tokenList->back(), "[;{}]")) - astNode->addtoken(tokenList, ";"); + if (!children.empty()) { + Token *bodyStart = children[0]->addtoken(tokenList, "{"); + tokenList->back()->scope(scope); + for (AstNodePtr astNode: children) { + astNode->createTokens(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; } @@ -769,12 +773,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) Scope *enumscope = createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok); if (nametok) enumscope->className = nametok->str(); - for (Token *tok = enumtok; tok; tok = tok->next()) { - if (Token::simpleMatch(tok, "; }")) - tok->deleteThis(); - else if (tok->str() == ";") - tok->str(","); - } + if (enumscope->bodyEnd && Token::simpleMatch(enumscope->bodyEnd->previous(), ", }")) + const_cast(enumscope->bodyEnd)->deletePrevious(); // Create enum type mData->mSymbolDatabase->typeList.push_back(Type(enumtok, enumscope, enumtok->scope()));