Skip to content

Commit 79a8f21

Browse files
committed
ClangImport; Set Token::scope properly for empty enum body
1 parent 4bd5933 commit 79a8f21

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

lib/clangimport.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,9 @@ Scope *clangimport::AstNode::createScope(TokenList *tokenList, Scope::ScopeType
596596
scope->classDef = def;
597597
scope->check = nestedIn->check;
598598
scope->bodyStart = addtoken(tokenList, "{");
599+
tokenList->back()->scope(scope);
599600
mData->scopeAccessControl[scope] = scope->defaultAccess();
600601
if (!children2.empty()) {
601-
tokenList->back()->scope(scope);
602602
for (AstNodePtr astNode: children2) {
603603
if (astNode->nodeType == "VisibilityAttr")
604604
continue;
@@ -894,20 +894,24 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
894894
}
895895
if (nodeType == EnumDecl) {
896896
int colIndex = mExtTokens.size() - 1;
897-
while (colIndex > 0 && mExtTokens[colIndex].compare(0,4,"col:") != 0)
897+
while (colIndex > 0 && mExtTokens[colIndex].compare(0,4,"col:") != 0 && mExtTokens[colIndex].compare(0,5,"line:") != 0)
898898
--colIndex;
899-
if (colIndex == 0 || colIndex + 2 >= mExtTokens.size() || mExtTokens[colIndex + 1] != "referenced")
899+
if (colIndex == 0)
900900
return nullptr;
901901

902902
mData->enumValue = 0;
903903
Token *enumtok = addtoken(tokenList, "enum");
904904
Token *nametok = nullptr;
905905
{
906906
int nameIndex = mExtTokens.size() - 1;
907-
while (nameIndex > 0 && mExtTokens[nameIndex][0] == '\'')
907+
while (nameIndex > colIndex && mExtTokens[nameIndex][0] == '\'')
908908
--nameIndex;
909-
if (nameIndex > colIndex + 1)
909+
if (nameIndex > colIndex)
910910
nametok = addtoken(tokenList, mExtTokens[nameIndex]);
911+
if (mExtTokens.back()[0] == '\'') {
912+
addtoken(tokenList, ":");
913+
addTypeTokens(tokenList, mExtTokens.back());
914+
}
911915
}
912916
Scope *enumscope = createScope(tokenList, Scope::ScopeType::eEnum, children, enumtok);
913917
if (nametok)

test/testclangimport.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class TestClangImport: public TestFixture {
7373
TEST_CASE(doStmt);
7474
TEST_CASE(enumDecl1);
7575
TEST_CASE(enumDecl2);
76+
TEST_CASE(enumDecl3);
7677
TEST_CASE(forStmt);
7778
TEST_CASE(funcdecl1);
7879
TEST_CASE(funcdecl2);
@@ -678,9 +679,15 @@ class TestClangImport: public TestFixture {
678679
}
679680

680681
void enumDecl2() {
681-
// enum syntax_option_type : unsigned int { };
682682
const char clang[] = "`-EnumDecl 0xb55d50 <2.cpp:4:3, col:44> col:8 syntax_option_type 'unsigned int'";
683-
ASSERT_EQUALS("", parse(clang));
683+
ASSERT_EQUALS("enum syntax_option_type : unsigned int { }", parse(clang));
684+
}
685+
686+
void enumDecl3() {
687+
const char clang[] = "|-EnumDecl 0x1586e48 <2.cpp:1:3, line:5:3> line:1:8 __syntax_option\n"
688+
"| |-EnumConstantDecl 0x1586f18 <line:3:5> col:5 referenced _S_polynomial '__syntax_option'\n"
689+
"| `-EnumConstantDecl 0x1586f68 <line:4:5> col:5 _S_syntax_last '__syntax_option'";
690+
ASSERT_EQUALS("enum __syntax_option { _S_polynomial , _S_syntax_last }", parse(clang));
684691
}
685692

686693
void forStmt() {

0 commit comments

Comments
 (0)