mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 21:31:04 +01:00
Separate ClassType from ClassDeclaration. (#3329)
Retain the `ClassDeclaration` node to represent a syntactic declaration of a class (including possibly a declaration of a generic class), but use a separate SemIR node to represent the class type itself. This allows us to give the two separate treatment. The `ClassDeclaration` is still entered into the name lookup table for its enclosing scope, but when it is named in an expression, the class type is produced instead. When the class declaration is named in a declaration name, it can be used to define members of the class, but an expression that resolves to the class type cannot be used to define members of the class. In order to distinguish these cases, use `Name` rather than `NameExpression` for the left-hand side of a `QualifiedName` parse node. This removes the only use of the `Expression` form of a declaration name, so that is also removed. In the future, `ClassType` will also be used to describe types such as `Vector(T)`, for which there is no corresponding `ClassDeclaration`.
This commit is contained in:
@@ -17,10 +17,7 @@ static auto HandleDeclarationNameAndParams(Context& context, State after_name)
|
||||
context.PushState(state);
|
||||
|
||||
if (context.PositionIs(Lex::TokenKind::Period)) {
|
||||
// Because there's a qualifier, we process the first segment as an
|
||||
// expression for simplicity. This just means semantics has one less thing
|
||||
// to handle here.
|
||||
context.AddLeafNode(NodeKind::NameExpression, *identifier);
|
||||
context.AddLeafNode(NodeKind::Name, *identifier);
|
||||
state.state = State::PeriodAsDeclaration;
|
||||
context.PushState(state);
|
||||
} else {
|
||||
@@ -71,6 +68,15 @@ static auto HandleDeclarationNameAndParamsAfterName(Context& context,
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: We can have a parameter list after a name qualifier, regardless of
|
||||
// whether the entity itself permits or requires parameters:
|
||||
//
|
||||
// fn Class(T:! type).AnotherClass(U:! type).Function(v: T) {}
|
||||
//
|
||||
// We should retain a `DeclarationNameAndParams...` state on the stack in all
|
||||
// cases below to check for a period after a parameter list, which indicates
|
||||
// that we've not finished parsing the declaration name.
|
||||
|
||||
if (params == Params::None) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user