Skip to content

Commit a8db107

Browse files
committed
fix: Set class key of elaborated type specifiers
1 parent bf5f22a commit a8db107

File tree

8 files changed

+19
-0
lines changed

8 files changed

+19
-0
lines changed

src/frontend/cxx/ast_printer.cc

+6
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,12 @@ void ASTPrinter::visit(UnderlyingTypeSpecifierAST* ast) {
16081608

16091609
void ASTPrinter::visit(ElaboratedTypeSpecifierAST* ast) {
16101610
fmt::print(out_, "{}\n", "elaborated-type-specifier");
1611+
if (ast->classKey != TokenKind::T_EOF_SYMBOL) {
1612+
++indent_;
1613+
fmt::print(out_, "{:{}}", "", indent_ * 2);
1614+
fmt::print(out_, "class-key: {}\n", Token::spell(ast->classKey));
1615+
--indent_;
1616+
}
16111617
if (ast->attributeList) {
16121618
++indent_;
16131619
fmt::print(out_, "{:{}}", "", indent_ * 2);

src/parser/cxx/ast.fbs

+1
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,7 @@ table ElaboratedTypeSpecifier /* SpecifierAST */ {
13061306
attribute_list: [AttributeSpecifier];
13071307
nested_name_specifier: NestedNameSpecifier;
13081308
name: Name;
1309+
class_key: uint32;
13091310
class_loc: SourceLocation;
13101311
}
13111312

src/parser/cxx/ast.h

+1
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,7 @@ class ElaboratedTypeSpecifierAST final : public SpecifierAST {
26802680
List<AttributeSpecifierAST*>* attributeList = nullptr;
26812681
NestedNameSpecifierAST* nestedNameSpecifier = nullptr;
26822682
NameAST* name = nullptr;
2683+
TokenKind classKey = TokenKind::T_EOF_SYMBOL;
26832684

26842685
void accept(ASTVisitor* visitor) override { visitor->visit(this); }
26852686

src/parser/cxx/ast_cloner.cc

+2
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,8 @@ void ASTCloner::visit(ElaboratedTypeSpecifierAST* ast) {
29922992
copy->nestedNameSpecifier = accept(ast->nestedNameSpecifier);
29932993

29942994
copy->name = accept(ast->name);
2995+
2996+
copy->classKey = ast->classKey;
29952997
}
29962998

29972999
void ASTCloner::visit(DecltypeAutoSpecifierAST* ast) {

src/parser/cxx/ast_decoder.cc

+1
Original file line numberDiff line numberDiff line change
@@ -2913,6 +2913,7 @@ auto ASTDecoder::decodeElaboratedTypeSpecifier(
29132913
ast->nestedNameSpecifier =
29142914
decodeNestedNameSpecifier(node->nested_name_specifier());
29152915
ast->name = decodeName(node->name(), node->name_type());
2916+
ast->classKey = static_cast<TokenKind>(node->class_key());
29162917
return ast;
29172918
}
29182919

src/parser/cxx/ast_encoder.cc

+1
Original file line numberDiff line numberDiff line change
@@ -4324,6 +4324,7 @@ void ASTEncoder::visit(ElaboratedTypeSpecifierAST* ast) {
43244324
builder.add_nested_name_specifier(nestedNameSpecifier.o);
43254325
builder.add_name(name);
43264326
builder.add_name_type(static_cast<io::Name>(nameType));
4327+
builder.add_class_key(static_cast<std::uint32_t>(ast->classKey));
43274328

43284329
offset_ = builder.Finish().Union();
43294330
type_ = io::Specifier_ElaboratedTypeSpecifier;

src/parser/cxx/parser.cc

+6
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,7 @@ auto Parser::parse_elaborated_type_specifier_helper(
43434343
ast->classLoc = classLoc;
43444344
ast->attributeList = attributes;
43454345
ast->name = name;
4346+
ast->classKey = unit->tokenKind(classLoc);
43464347

43474348
return true;
43484349
}
@@ -4369,6 +4370,7 @@ auto Parser::parse_elaborated_type_specifier_helper(
43694370
ast->classLoc = classLoc;
43704371
ast->attributeList = attributes;
43714372
ast->name = name;
4373+
ast->classKey = unit->tokenKind(classLoc);
43724374

43734375
return true;
43744376
}
@@ -4391,6 +4393,7 @@ auto Parser::parse_elaborated_type_specifier_helper(
43914393
ast->attributeList = attributes;
43924394
ast->nestedNameSpecifier = nestedNameSpecifier;
43934395
ast->name = name;
4396+
ast->classKey = unit->tokenKind(classLoc);
43944397

43954398
return true;
43964399
}
@@ -4406,6 +4409,7 @@ auto Parser::parse_elaborated_type_specifier_helper(
44064409
ast->attributeList = attributes;
44074410
ast->nestedNameSpecifier = nestedNameSpecifier;
44084411
ast->name = nullptr; // error
4412+
ast->classKey = unit->tokenKind(classLoc);
44094413

44104414
return true;
44114415
}
@@ -4423,6 +4427,7 @@ auto Parser::parse_elaborated_type_specifier_helper(
44234427
ast->attributeList = attributes;
44244428
ast->nestedNameSpecifier = nestedNameSpecifier;
44254429
ast->name = name;
4430+
ast->classKey = unit->tokenKind(classLoc);
44264431

44274432
return true;
44284433
}
@@ -4451,6 +4456,7 @@ auto Parser::parse_elaborated_enum_specifier(ElaboratedTypeSpecifierAST*& yyast,
44514456
ast->classLoc = enumLoc;
44524457
ast->nestedNameSpecifier = nestedNameSpecifier;
44534458
ast->name = name;
4459+
ast->classKey = TokenKind::T_ENUM;
44544460

44554461
return true;
44564462
}

tests/unit_tests/ast/using_enum_declaration_01.cc

+1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ struct S {
2828
// CHECK-NEXT: declaration-list
2929
// CHECK-NEXT: using-enum-declaration
3030
// CHECK-NEXT: enum-type-specifier: elaborated-type-specifier
31+
// CHECK-NEXT: class-key: enum
3132
// CHECK-NEXT: name: simple-name
3233
// CHECK-NEXT: identifier: fruit

0 commit comments

Comments
 (0)