Skip to content

Commit 51d0e8f

Browse files
committed
fix: Set the virt specifier attributes
1 parent 4e9134e commit 51d0e8f

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

src/frontend/cxx/ast_printer.cc

+18
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,24 @@ void ASTPrinter::visit(PtrToMemberOperatorAST* ast) {
19421942

19431943
void ASTPrinter::visit(FunctionDeclaratorAST* ast) {
19441944
fmt::print(out_, "{}\n", "function-declarator");
1945+
if (ast->isFinal) {
1946+
++indent_;
1947+
fmt::print(out_, "{:{}}", "", indent_ * 2);
1948+
fmt::print(out_, "is-final: {}\n", ast->isFinal);
1949+
--indent_;
1950+
}
1951+
if (ast->isOverride) {
1952+
++indent_;
1953+
fmt::print(out_, "{:{}}", "", indent_ * 2);
1954+
fmt::print(out_, "is-override: {}\n", ast->isOverride);
1955+
--indent_;
1956+
}
1957+
if (ast->isPure) {
1958+
++indent_;
1959+
fmt::print(out_, "{:{}}", "", indent_ * 2);
1960+
fmt::print(out_, "is-pure: {}\n", ast->isPure);
1961+
--indent_;
1962+
}
19451963
accept(ast->parametersAndQualifiers, "parameters-and-qualifiers");
19461964
accept(ast->trailingReturnType, "trailing-return-type");
19471965
}

src/parser/cxx/ast.h

+3
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,9 @@ class FunctionDeclaratorAST final : public DeclaratorModifierAST {
30943094

30953095
ParametersAndQualifiersAST* parametersAndQualifiers = nullptr;
30963096
TrailingReturnTypeAST* trailingReturnType = nullptr;
3097+
bool isFinal = false;
3098+
bool isOverride = false;
3099+
bool isPure = false;
30973100

30983101
void accept(ASTVisitor* visitor) override { visitor->visit(this); }
30993102

src/parser/cxx/ast_cloner.cc

+6
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,12 @@ void ASTCloner::visit(FunctionDeclaratorAST* ast) {
35393539
copy->parametersAndQualifiers = accept(ast->parametersAndQualifiers);
35403540

35413541
copy->trailingReturnType = accept(ast->trailingReturnType);
3542+
3543+
copy->isFinal = ast->isFinal;
3544+
3545+
copy->isOverride = ast->isOverride;
3546+
3547+
copy->isPure = ast->isPure;
35423548
}
35433549

35443550
void ASTCloner::visit(ArrayDeclaratorAST* ast) {

src/parser/cxx/parser.cc

+34-21
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,7 @@ auto Parser::parse_notypespec_function_definition(
36643664

36653665
const auto has_requires_clause = parse_requires_clause(requiresClause);
36663666

3667-
if (!has_requires_clause) parse_virt_specifier_seq();
3667+
if (!has_requires_clause) parse_virt_specifier_seq(functionDeclarator);
36683668

36693669
SourceLocation semicolonLoc;
36703670

@@ -5513,12 +5513,11 @@ auto Parser::parse_expr_or_braced_init_list(ExpressionAST*& yyast) -> bool {
55135513
return true;
55145514
}
55155515

5516-
auto Parser::parse_virt_specifier_seq() -> bool {
5517-
SourceLocation finalLoc;
5518-
5519-
if (!parse_virt_specifier(finalLoc)) return false;
5516+
auto Parser::parse_virt_specifier_seq(FunctionDeclaratorAST* functionDeclarator)
5517+
-> bool {
5518+
if (!parse_virt_specifier(functionDeclarator)) return false;
55205519

5521-
while (parse_virt_specifier(finalLoc)) {
5520+
while (parse_virt_specifier(functionDeclarator)) {
55225521
//
55235522
}
55245523

@@ -6996,12 +6995,14 @@ auto Parser::parse_member_declaration_helper(DeclarationAST*& yyast) -> bool {
69966995

69976996
const auto hasDeclarator = parse_declarator(declarator);
69986997

6999-
if (hasDeclarator && getFunctionDeclarator(declarator)) {
6998+
auto functionDeclarator = getFunctionDeclarator(declarator);
6999+
7000+
if (hasDeclarator && functionDeclarator) {
70007001
RequiresClauseAST* requiresClause = nullptr;
70017002

70027003
const auto has_requires_clause = parse_requires_clause(requiresClause);
70037004

7004-
if (!has_requires_clause) parse_virt_specifier_seq();
7005+
if (!has_requires_clause) parse_virt_specifier_seq(functionDeclarator);
70057006

70067007
if (lookat_function_body()) {
70077008
FunctionBodyAST* functionBody = nullptr;
@@ -7125,14 +7126,20 @@ auto Parser::parse_member_declarator(InitDeclaratorAST*& yyast,
71257126

71267127
ast->declarator = declarator;
71277128

7128-
if (getFunctionDeclarator(declarator)) {
7129+
if (auto functionDeclarator = getFunctionDeclarator(declarator)) {
71297130
RequiresClauseAST* requiresClause = nullptr;
71307131

71317132
if (parse_requires_clause(requiresClause)) {
71327133
ast->requiresClause = requiresClause;
71337134
} else {
7134-
parse_virt_specifier_seq();
7135-
parse_pure_specifier();
7135+
parse_virt_specifier_seq(functionDeclarator);
7136+
7137+
SourceLocation equalLoc;
7138+
SourceLocation zeroLoc;
7139+
7140+
const auto isPure = parse_pure_specifier(equalLoc, zeroLoc);
7141+
7142+
functionDeclarator->isPure = isPure;
71367143
}
71377144

71387145
return true;
@@ -7143,24 +7150,30 @@ auto Parser::parse_member_declarator(InitDeclaratorAST*& yyast,
71437150
return true;
71447151
}
71457152

7146-
auto Parser::parse_virt_specifier(SourceLocation& loc) -> bool {
7147-
if (parse_final(loc)) return true;
7153+
auto Parser::parse_virt_specifier(FunctionDeclaratorAST* functionDeclarator)
7154+
-> bool {
7155+
SourceLocation loc;
7156+
7157+
if (parse_final(loc)) {
7158+
functionDeclarator->isFinal = true;
7159+
return true;
7160+
}
71487161

7149-
if (parse_override(loc)) return true;
7162+
if (parse_override(loc)) {
7163+
functionDeclarator->isOverride = true;
7164+
return true;
7165+
}
71507166

71517167
return false;
71527168
}
71537169

7154-
auto Parser::parse_pure_specifier() -> bool {
7155-
SourceLocation equalLoc;
7156-
7170+
auto Parser::parse_pure_specifier(SourceLocation& equalLoc,
7171+
SourceLocation& zeroLoc) -> bool {
71577172
if (!match(TokenKind::T_EQUAL, equalLoc)) return false;
71587173

7159-
SourceLocation literalLoc;
7160-
7161-
if (!match(TokenKind::T_INTEGER_LITERAL, literalLoc)) return false;
7174+
if (!match(TokenKind::T_INTEGER_LITERAL, zeroLoc)) return false;
71627175

7163-
const auto& number = unit->tokenText(literalLoc);
7176+
const auto& number = unit->tokenText(zeroLoc);
71647177

71657178
if (number != "0") return false;
71667179

src/parser/cxx/parser.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ class Parser final {
330330
DesignatedInitializerClauseAST*& yyast) -> bool;
331331
auto parse_designator(DesignatorAST*& yyast) -> bool;
332332
auto parse_expr_or_braced_init_list(ExpressionAST*& yyast) -> bool;
333-
auto parse_virt_specifier_seq() -> bool;
333+
auto parse_virt_specifier_seq(FunctionDeclaratorAST* functionDeclarator)
334+
-> bool;
334335
auto lookat_function_body() -> bool;
335336
auto parse_function_body(FunctionBodyAST*& yyast) -> bool;
336337
auto parse_enum_specifier(SpecifierAST*& yyast) -> bool;
@@ -398,8 +399,9 @@ class Parser final {
398399
const DeclSpecs& specs) -> bool;
399400
auto parse_member_declarator(InitDeclaratorAST*& yyast,
400401
const DeclSpecs& specs) -> bool;
401-
auto parse_virt_specifier(SourceLocation& loc) -> bool;
402-
auto parse_pure_specifier() -> bool;
402+
auto parse_virt_specifier(FunctionDeclaratorAST* functionDeclarator) -> bool;
403+
auto parse_pure_specifier(SourceLocation& equalLoc, SourceLocation& zeroLoc)
404+
-> bool;
403405
auto parse_conversion_function_id(NameAST*& yyast) -> bool;
404406
auto parse_base_clause(BaseClauseAST*& yyast) -> bool;
405407
auto parse_base_specifier_list(List<BaseSpecifierAST*>*& yyast) -> bool;

0 commit comments

Comments
 (0)