@@ -5363,39 +5363,7 @@ auto Parser::parse_elaborated_type_specifier(
53635363 className = nameId->identifier ;
53645364 }
53655365
5366- const auto location = ast->unqualifiedId ->firstSourceLocation ();
5367-
5368- const auto _ = Binder::ScopeGuard{&binder_};
5369-
5370- if (ast->nestedNameSpecifier ) {
5371- auto parent = ast->nestedNameSpecifier ->symbol ;
5372-
5373- if (parent && parent->isClassOrNamespace ()) {
5374- setScope (static_cast <ScopedSymbol*>(parent));
5375- }
5376- }
5377-
5378- ClassSymbol* classSymbol = nullptr ;
5379-
5380- if (scope ()->isClassOrNamespaceScope ()) {
5381- for (auto candidate : scope ()->find (className) | views::classes) {
5382- classSymbol = candidate;
5383- break ;
5384- }
5385- }
5386-
5387- if (!classSymbol) {
5388- const auto isUnion = classKey == TokenKind::T_UNION;
5389- classSymbol = control_->newClassSymbol (scope (), location);
5390-
5391- classSymbol->setIsUnion (isUnion);
5392- classSymbol->setName (className);
5393- classSymbol->setTemplateParameters (binder_.currentTemplateParameters ());
5394- binder_.declaringScope ()->addSymbol (classSymbol);
5395- }
5396-
5397- ast->symbol = classSymbol;
5398- specs.type = classSymbol->type ();
5366+ binder_.bind (ast, specs);
53995367
54005368 return true ;
54015369}
@@ -6014,51 +5982,35 @@ auto Parser::parse_parameter_declaration_clause(
60145982
60155983 auto _ = Binder::ScopeGuard{&binder_};
60165984
6017- bool parsed = false ;
6018-
6019- SourceLocation ellipsisLoc;
6020- FunctionParametersSymbol* functionParametersSymbol = nullptr ;
5985+ auto ast = make_node<ParameterDeclarationClauseAST>(pool_);
60215986
6022- if (match (TokenKind::T_DOT_DOT_DOT, ellipsisLoc)) {
6023- parsed = true ;
5987+ binder_.bind (ast);
60245988
6025- auto ast = make_node<ParameterDeclarationClauseAST>(pool_);
5989+ if ( match (TokenKind::T_DOT_DOT_DOT, ast-> ellipsisLoc )) {
60265990 yyast = ast;
60275991
6028- ast->ellipsisLoc = ellipsisLoc;
60295992 ast->isVariadic = true ;
6030- ast->functionParametersSymbol =
6031- control_->newFunctionParametersSymbol (scope (), {});
6032- } else if (List<ParameterDeclarationAST*>* parameterDeclarationList = nullptr ;
6033- parse_parameter_declaration_list (parameterDeclarationList,
6034- functionParametersSymbol)) {
6035- parsed = true ;
6036-
6037- auto ast = make_node<ParameterDeclarationClauseAST>(pool_);
5993+ } else if (parse_parameter_declaration_list (ast)) {
60385994 yyast = ast;
6039- ast-> parameterDeclarationList = parameterDeclarationList;
5995+
60405996 match (TokenKind::T_COMMA, ast->commaLoc );
60415997 ast->isVariadic = match (TokenKind::T_DOT_DOT_DOT, ast->ellipsisLoc );
6042- ast->functionParametersSymbol = functionParametersSymbol;
6043- } else {
6044- parsed = false ;
60455998 }
60465999
6000+ const auto parsed = yyast != nullptr ;
6001+
60476002 parameter_declaration_clauses_.set (start, currentLocation (), yyast, parsed);
60486003
60496004 return parsed;
60506005}
60516006
60526007auto Parser::parse_parameter_declaration_list (
6053- List<ParameterDeclarationAST*>*& yyast,
6054- FunctionParametersSymbol*& functionParametersSymbol) -> bool {
6055- auto it = &yyast;
6008+ ParameterDeclarationClauseAST* ast) -> bool {
6009+ auto it = &ast->parameterDeclarationList ;
60566010
60576011 auto _ = Binder::ScopeGuard{&binder_};
60586012
6059- functionParametersSymbol = control_->newFunctionParametersSymbol (scope (), {});
6060-
6061- setScope (functionParametersSymbol);
6013+ setScope (ast->functionParametersSymbol );
60626014
60636015 ParameterDeclarationAST* declaration = nullptr ;
60646016
@@ -7794,72 +7746,13 @@ auto Parser::parse_class_specifier(
77947746 ast->isFinal = true ;
77957747 }
77967748
7797- auto _ = Binder::ScopeGuard{&binder_};
7798-
77997749 if (scope ()->isTemplateParametersScope ()) {
78007750 mark_maybe_template_name (unqualifiedId);
78017751 }
78027752
7803- auto templateParameters = binder_.currentTemplateParameters ();
7804-
7805- if (nestedNameSpecifier) {
7806- auto parent = nestedNameSpecifier->symbol ;
7807-
7808- if (parent && parent->isClassOrNamespace ()) {
7809- setScope (static_cast <ScopedSymbol*>(parent));
7810- }
7811- }
7812-
7813- ClassSymbol* primaryTemplate = nullptr ;
7814-
7815- if (templateId && scope ()->isTemplateParametersScope ()) {
7816- for (auto candidate :
7817- binder_.declaringScope ()->find (className) | views::classes) {
7818- primaryTemplate = candidate;
7819- break ;
7820- }
7821-
7822- if (!primaryTemplate && config_.checkTypes ) {
7823- parse_error (location,
7824- std::format (" specialization of undeclared template '{}'" ,
7825- className->name ()));
7826- }
7827- }
7828-
7829- ClassSymbol* classSymbol = nullptr ;
7830-
7831- if (className) {
7832- for (auto candidate :
7833- binder_.declaringScope ()->find (className) | views::classes) {
7834- classSymbol = candidate;
7835- break ;
7836- }
7837- }
7838-
7839- if (classSymbol && classSymbol->isComplete ()) {
7840- classSymbol = nullptr ;
7841- }
7842-
7843- if (!classSymbol) {
7844- classSymbol = control_->newClassSymbol (scope (), location);
7845- classSymbol->setIsUnion (isUnion);
7846- classSymbol->setName (className);
7847- classSymbol->setTemplateParameters (templateParameters);
7848-
7849- if (!primaryTemplate) {
7850- binder_.declaringScope ()->addSymbol (classSymbol);
7851- } else {
7852- std::vector<TemplateArgument> arguments;
7853- // TODO: parse template arguments
7854- primaryTemplate->addSpecialization (arguments, classSymbol);
7855- }
7856- }
7857-
7858- if (finalLoc) {
7859- classSymbol->setFinal (true );
7860- }
7753+ auto _ = Binder::ScopeGuard{&binder_};
78617754
7862- ast-> symbol = classSymbol ;
7755+ binder_. bind ( ast, specs) ;
78637756
78647757 setScope (ast->symbol );
78657758
@@ -7874,14 +7767,7 @@ auto Parser::parse_class_specifier(
78747767 expect (TokenKind::T_RBRACE, ast->rbraceLoc );
78757768 }
78767769
7877- if (!binder_.inTemplate ()) {
7878- auto status = classSymbol->buildClassLayout (control_);
7879- if (!status.has_value () && config_.checkTypes ) {
7880- parse_error (classSymbol->location (), status.error ());
7881- }
7882- }
7883-
7884- classSymbol->setComplete (true );
7770+ binder_.complete (ast);
78857771
78867772 return true ;
78877773}
0 commit comments