mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Parse parameters in name qualifiers. (#3988)
Parse the name of a declaration as a sequence of `NameQualifier`s -- which have a name, possibly parameters, and a trailing period -- followed by a name and possibly parameters. This prepares us for parsing declarations of members of generic classes and similar cases, but actually supporting such member redeclarations is left to a future change. We previously required functions to have parameters, but no longer do, following the direction of #3848. Cases like namespaces that can't actually have parameters are now diagnosed in check instead of in parse. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
582b2c04dd
commit
28170c7867
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "toolchain/base/kind_switch.h"
|
||||
#include "toolchain/check/context.h"
|
||||
#include "toolchain/check/diagnostic_helpers.h"
|
||||
#include "toolchain/diagnostics/diagnostic.h"
|
||||
#include "toolchain/sem_ir/ids.h"
|
||||
|
||||
namespace Carbon::Check {
|
||||
@@ -56,14 +58,24 @@ auto DeclNameStack::PushScopeAndStartName() -> void {
|
||||
auto DeclNameStack::FinishName() -> NameContext {
|
||||
CARBON_CHECK(decl_name_stack_.back().state != NameContext::State::Finished)
|
||||
<< "Finished name twice";
|
||||
if (context_->node_stack()
|
||||
.PopAndDiscardSoloNodeIdIf<Parse::NodeKind::QualifiedName>()) {
|
||||
// Any parts from a QualifiedName will already have been processed
|
||||
// into the name.
|
||||
} else {
|
||||
// The name had no qualifiers, so we need to process the node now.
|
||||
auto [loc_id, name_id] = context_->node_stack().PopNameWithNodeId();
|
||||
ApplyNameQualifier(loc_id, name_id);
|
||||
auto [params_loc_id, params_id] =
|
||||
context_->node_stack().PopWithNodeIdIf<Parse::NodeKind::TuplePattern>();
|
||||
auto [implicit_params_loc_id, implicit_params_id] =
|
||||
context_->node_stack()
|
||||
.PopWithNodeIdIf<Parse::NodeKind::ImplicitParamList>();
|
||||
auto [loc_id, name_id] = context_->node_stack().PopNameWithNodeId();
|
||||
|
||||
ApplyNameQualifier(loc_id, name_id);
|
||||
|
||||
if (params_id || implicit_params_id) {
|
||||
// TODO: Say which kind of declaration we're parsing.
|
||||
CARBON_DIAGNOSTIC(UnexpectedDeclNameParams, Error,
|
||||
"Declaration cannot have parameters.");
|
||||
// Point to the lexically first parameter list in the diagnostic.
|
||||
context_->emitter().Emit(implicit_params_id
|
||||
? static_cast<SemIRLoc>(implicit_params_loc_id)
|
||||
: params_loc_id,
|
||||
UnexpectedDeclNameParams);
|
||||
}
|
||||
|
||||
NameContext result = decl_name_stack_.back();
|
||||
|
||||
Reference in New Issue
Block a user