Files
carbon-lang/toolchain/parse/testdata/namespace/nested.carbon
T
Richard Smith 7d9340880e 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`.
2023-10-24 01:26:44 +00:00

45 lines
2.3 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
namespace Foo;
namespace Foo.Bar;
fn Foo.Bar.Baz() {
Foo.Bar.Wiz();
}
// CHECK:STDOUT: - filename: nested.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'NamespaceStart', text: 'namespace'},
// CHECK:STDOUT: {kind: 'Name', text: 'Foo'},
// CHECK:STDOUT: {kind: 'Namespace', text: ';', subtree_size: 3},
// CHECK:STDOUT: {kind: 'NamespaceStart', text: 'namespace'},
// CHECK:STDOUT: {kind: 'Name', text: 'Foo'},
// CHECK:STDOUT: {kind: 'Name', text: 'Bar'},
// CHECK:STDOUT: {kind: 'QualifiedDeclaration', text: '.', subtree_size: 3},
// CHECK:STDOUT: {kind: 'Namespace', text: ';', subtree_size: 5},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'Name', text: 'Foo'},
// CHECK:STDOUT: {kind: 'Name', text: 'Bar'},
// CHECK:STDOUT: {kind: 'QualifiedDeclaration', text: '.', subtree_size: 3},
// CHECK:STDOUT: {kind: 'Name', text: 'Baz'},
// CHECK:STDOUT: {kind: 'QualifiedDeclaration', text: '.', subtree_size: 5},
// CHECK:STDOUT: {kind: 'ParameterListStart', text: '('},
// CHECK:STDOUT: {kind: 'ParameterList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 9},
// CHECK:STDOUT: {kind: 'NameExpression', text: 'Foo'},
// CHECK:STDOUT: {kind: 'Name', text: 'Bar'},
// CHECK:STDOUT: {kind: 'MemberAccessExpression', text: '.', subtree_size: 3},
// CHECK:STDOUT: {kind: 'Name', text: 'Wiz'},
// CHECK:STDOUT: {kind: 'MemberAccessExpression', text: '.', subtree_size: 5},
// CHECK:STDOUT: {kind: 'CallExpressionStart', text: '(', subtree_size: 6},
// CHECK:STDOUT: {kind: 'CallExpression', text: ')', subtree_size: 7},
// CHECK:STDOUT: {kind: 'ExpressionStatement', text: ';', subtree_size: 8},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 18},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]