ClangImport; Set Token::scope properly for empty enum body

This commit is contained in:
Daniel Marjamäki 2020-12-29 16:34:06 +01:00
parent 4bd5933691
commit 79a8f21183
2 changed files with 18 additions and 7 deletions

View File

@ -596,9 +596,9 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
scope->classDef = def;
scope->check = nestedIn->check;
scope->bodyStart = addtoken(tokenList, "{");
tokenList->back()->scope(scope);
mData->scopeAccessControl[scope] = scope->defaultAccess();
if (!children2.empty()) {
tokenList->back()->scope(scope);
for (AstNodePtr astNode: children2) {
if (astNode->nodeType == "VisibilityAttr")
continue;
@ -894,9 +894,9 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
}
if (nodeType == EnumDecl) {
int colIndex = mExtTokens.size() - 1;
while (colIndex > 0 && mExtTokens[colIndex].compare(0,4,"col:") != 0)
while (colIndex > 0 && mExtTokens[colIndex].compare(0,4,"col:") != 0 && mExtTokens[colIndex].compare(0,5,"line:") != 0)
--colIndex;
if (colIndex == 0 || colIndex + 2 >= mExtTokens.size() || mExtTokens[colIndex + 1] != "referenced")
if (colIndex == 0)
return nullptr;
mData->enumValue = 0;
@ -904,10 +904,14 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
Token *nametok = nullptr;
{
int nameIndex = mExtTokens.size() - 1;
while (nameIndex > 0 && mExtTokens[nameIndex][0] == '\'')
while (nameIndex > colIndex && mExtTokens[nameIndex][0] == '\'')
--nameIndex;
if (nameIndex > colIndex + 1)
if (nameIndex > colIndex)
nametok = addtoken(tokenList, mExtTokens[nameIndex]);
if (mExtTokens.back()[0] == '\'') {
addtoken(tokenList, ":");
addTypeTokens(tokenList, mExtTokens.back());
}
}
Scope *enumscope = createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok);
if (nametok)

View File

@ -73,6 +73,7 @@ private:
TEST_CASE(doStmt);
TEST_CASE(enumDecl1);
TEST_CASE(enumDecl2);
TEST_CASE(enumDecl3);
TEST_CASE(forStmt);
TEST_CASE(funcdecl1);
TEST_CASE(funcdecl2);
@ -678,9 +679,15 @@ private:
}
void enumDecl2() {
// enum syntax_option_type : unsigned int { };
const char clang[] = "`-EnumDecl 0xb55d50 <2.cpp:4:3, col:44> col:8 syntax_option_type 'unsigned int'";
ASSERT_EQUALS("", parse(clang));
ASSERT_EQUALS("enum syntax_option_type : unsigned int { }", parse(clang));
}
void enumDecl3() {
const char clang[] = "|-EnumDecl 0x1586e48 <2.cpp:1:3, line:5:3> line:1:8 __syntax_option\n"
"| |-EnumConstantDecl 0x1586f18 <line:3:5> col:5 referenced _S_polynomial '__syntax_option'\n"
"| `-EnumConstantDecl 0x1586f68 <line:4:5> col:5 _S_syntax_last '__syntax_option'";
ASSERT_EQUALS("enum __syntax_option { _S_polynomial , _S_syntax_last }", parse(clang));
}
void forStmt() {