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:
Richard Smith authored and GitHub committed 2023-10-24 01:26:44 +00:00
1 parent ce248239d4
commit 7d9340880e
29 files changed
+186 -105

No files matched your search

+3 -9
View File
@@ -15,10 +15,9 @@ class Context;
// Provides support and stacking for qualified declaration name handling.
//
// A qualified declaration name will consist of entries which are either
// Identifiers or full expressions. Expressions are expected to resolve to
// types, such as how `fn Vector(i32).Clear() { ... }` uses the expression
// `Vector(i32)` to indicate the type whose member is being declared.
// A qualified declaration name will consist of entries, which are `Name`s
// optionally followed by generic parameter lists, such as `Vector(T:! type)`
// in `fn Vector(T:! type).Clear();`, but parameter lists aren't supported yet.
// Identifiers such as `Clear` will be resolved to a name if possible, for
// example when declaring things that are in a non-generic type or namespace,
// and are otherwise marked as an unresolved identifier.
@@ -111,11 +110,6 @@ class DeclarationNameStack {
auto MakeUnqualifiedName(Parse::Node parse_node, StringId name_id)
-> NameContext;
// Applies an expression from the node stack to the top of the declaration
// name stack.
auto ApplyExpressionQualifier(Parse::Node parse_node, SemIR::NodeId node_id)
-> void;
// Applies a Name from the node stack to the top of the declaration name
// stack.
auto ApplyNameQualifier(Parse::Node parse_node, StringId name_id) -> void;