Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 51 additions & 34 deletions src/parser/cxx/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,33 +850,38 @@ auto Parser::parse_unqualified_id(UnqualifiedIdAST*& yyast,
NestedNameSpecifierAST* nestedNameSpecifier,
bool isTemplateIntroduced,
bool inRequiresClause) -> bool {
if (SourceLocation tildeLoc; match(TokenKind::T_TILDE, tildeLoc)) {
if (DecltypeSpecifierAST* decltypeSpecifier = nullptr;
parse_decltype_specifier(decltypeSpecifier)) {
auto decltypeName = make_node<DecltypeIdAST>(pool_);
decltypeName->decltypeSpecifier = decltypeSpecifier;
if (is_parsing_cxx()) {
// allow destructor only in C++ mode
if (SourceLocation tildeLoc; match(TokenKind::T_TILDE, tildeLoc)) {
if (DecltypeSpecifierAST* decltypeSpecifier = nullptr;
parse_decltype_specifier(decltypeSpecifier)) {
auto decltypeName = make_node<DecltypeIdAST>(pool_);
decltypeName->decltypeSpecifier = decltypeSpecifier;

auto ast = make_node<DestructorIdAST>(pool_);
yyast = ast;
ast->tildeLoc = tildeLoc;
ast->id = decltypeName;

return true;
}

UnqualifiedIdAST* name = nullptr;
if (!parse_type_name(name, nestedNameSpecifier, isTemplateIntroduced))
return false;

auto ast = make_node<DestructorIdAST>(pool_);
yyast = ast;
ast->tildeLoc = tildeLoc;
ast->id = decltypeName;
ast->id = name;

return true;
}

UnqualifiedIdAST* name = nullptr;
if (!parse_type_name(name, nestedNameSpecifier, isTemplateIntroduced))
return false;

auto ast = make_node<DestructorIdAST>(pool_);
yyast = ast;
ast->tildeLoc = tildeLoc;
ast->id = name;

return true;
}

auto lookat_template_id = [&] {
if (!is_parsing_cxx()) return false;

LookaheadParser lookahead{this};
if (!parse_template_id(yyast, nestedNameSpecifier, isTemplateIntroduced))
return false;
Expand Down Expand Up @@ -913,13 +918,17 @@ auto Parser::parse_unqualified_id(UnqualifiedIdAST*& yyast,

void Parser::parse_optional_nested_name_specifier(
NestedNameSpecifierAST*& yyast, NestedNameSpecifierContext ctx) {
if (!is_parsing_cxx()) return;

LookaheadParser lookahead(this);
if (!parse_nested_name_specifier(yyast, ctx)) return;
lookahead.commit();
}

auto Parser::parse_decltype_nested_name_specifier(
NestedNameSpecifierAST*& yyast, NestedNameSpecifierContext ctx) -> bool {
if (!is_parsing_cxx()) return false;

LookaheadParser lookahead{this};

SourceLocation decltypeLoc;
Expand Down Expand Up @@ -7978,6 +7987,8 @@ auto Parser::parse_member_declaration_helper(DeclarationAST*& yyast) -> bool {
}

auto lookat_function_definition = [&] {
if (!is_parsing_cxx()) return false;

LookaheadParser lookahead{this};

auto functionDeclarator = getFunctionPrototype(declarator);
Expand Down Expand Up @@ -8154,32 +8165,34 @@ auto Parser::parse_member_declarator(InitDeclaratorAST*& yyast,
ast->declarator = declarator;
ast->symbol = symbol;

if (auto functionDeclarator = getFunctionPrototype(declarator)) {
RequiresClauseAST* requiresClause = nullptr;
if (is_parsing_cxx()) {
if (auto functionDeclarator = getFunctionPrototype(declarator)) {
RequiresClauseAST* requiresClause = nullptr;

if (parse_requires_clause(requiresClause)) {
ast->requiresClause = requiresClause;
} else {
parse_virt_specifier_seq(functionDeclarator);
if (parse_requires_clause(requiresClause)) {
ast->requiresClause = requiresClause;
} else {
parse_virt_specifier_seq(functionDeclarator);

if (!functionDeclarator->attributeList) {
parse_optional_attribute_specifier_seq(
functionDeclarator->attributeList);
}
if (!functionDeclarator->attributeList) {
parse_optional_attribute_specifier_seq(
functionDeclarator->attributeList);
}

SourceLocation equalLoc;
SourceLocation zeroLoc;
SourceLocation equalLoc;
SourceLocation zeroLoc;

const auto isPure = parse_pure_specifier(equalLoc, zeroLoc);
const auto isPure = parse_pure_specifier(equalLoc, zeroLoc);

functionDeclarator->isPure = isPure;
functionDeclarator->isPure = isPure;
}

return true;
}

return true;
(void)parse_brace_or_equal_initializer(ast->initializer);
}

(void)parse_brace_or_equal_initializer(ast->initializer);

return true;
}

Expand Down Expand Up @@ -9160,6 +9173,8 @@ auto Parser::parse_function_operator_template_id(
auto Parser::parse_template_id(UnqualifiedIdAST*& yyast,
NestedNameSpecifierAST* nestedNameSpecifier,
bool isTemplateIntroduced) -> bool {
if (!is_parsing_cxx()) return false;

if (LiteralOperatorTemplateIdAST* templateName = nullptr;
parse_literal_operator_template_id(templateName, nestedNameSpecifier)) {
yyast = templateName;
Expand Down Expand Up @@ -9287,6 +9302,8 @@ auto Parser::parse_constraint_expression(ExpressionAST*& yyast) -> bool {
auto Parser::parse_deduction_guide(DeclarationAST*& yyast,
TemplateDeclarationAST* templateHead)
-> bool {
if (!is_parsing_cxx()) return false;

SpecifierAST* explicitSpecifier = nullptr;
SourceLocation identifierLoc;
SourceLocation lparenLoc;
Expand Down