Parsing and basic checking for abstract class and base class. (#3385)

For now, we require the same introducer to be used each time a class is
declared, but see #3384.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2023-11-13 20:38:21 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 49591d1360
commit 2715e2276e
23 changed files with 520 additions and 114 deletions
+31
View File
@@ -0,0 +1,31 @@
// 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
// TODO: Improve the diagnostic to say that the `abstract` modifier can't be
// used on an `interface`.
// CHECK:STDERR: fail_introducer.carbon:[[@LINE+3]]:1: ERROR: Unrecognized declaration introducer.
// CHECK:STDERR: abstract interface I;
// CHECK:STDERR: ^
abstract interface I;
// CHECK:STDERR: fail_introducer.carbon:[[@LINE+3]]:1: ERROR: Unrecognized declaration introducer.
// CHECK:STDERR: base fn F();
// CHECK:STDERR: ^
base fn F();
// CHECK:STDERR: fail_introducer.carbon:[[@LINE+3]]:1: ERROR: Unrecognized declaration introducer.
// CHECK:STDERR: abstract base class C;
// CHECK:STDERR: ^
abstract base class C;
// CHECK:STDOUT: - filename: fail_introducer.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'EmptyDecl', text: ';', has_error: yes},
// CHECK:STDOUT: {kind: 'EmptyDecl', text: ';', has_error: yes},
// CHECK:STDOUT: {kind: 'EmptyDecl', text: ';', has_error: yes},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
+44
View File
@@ -0,0 +1,44 @@
// 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
class A;
base class B;
abstract class C;
class A {}
base class B {}
abstract class C {}
// CHECK:STDOUT: - filename: introducer.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'Name', text: 'A'},
// CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 3},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'},
// CHECK:STDOUT: {kind: 'Name', text: 'B'},
// CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 4},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'},
// CHECK:STDOUT: {kind: 'Name', text: 'C'},
// CHECK:STDOUT: {kind: 'ClassDecl', text: ';', subtree_size: 4},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'Name', text: 'A'},
// CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3},
// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 4},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'BaseModifier', text: 'base'},
// CHECK:STDOUT: {kind: 'Name', text: 'B'},
// CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4},
// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5},
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
// CHECK:STDOUT: {kind: 'AbstractModifier', text: 'abstract'},
// CHECK:STDOUT: {kind: 'Name', text: 'C'},
// CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 4},
// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 5},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]