mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-27 14:50:10 +01:00
This adds the `static` token to the lexer and parses it as a modifier. In check, `FullPatternStack::Kind::FieldDecl` is now used for both static and non-static vars. Static vars get treated basically the same as `NameBindingDecl`s. Global initialization is used for static var initializers. To make the necessary stack information available to `pattern_match.cpp`, the `full_pattern_stack` and `decl_introducer_state_stack` are now popped later in `handle_let_and_var.cpp`. In lowering, each class's body is checked for `VarStorage` insts and lowered the same as global vars.
48 lines
2.6 KiB
Plaintext
48 lines
2.6 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
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/parse/testdata/class/var.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/parse/testdata/class/var.carbon
|
|
|
|
class Foo {
|
|
var x: i32;
|
|
var y: i32 = 0;
|
|
static var z: i32;
|
|
}
|
|
|
|
|
|
// CHECK:STDOUT: - filename: var.carbon
|
|
// CHECK:STDOUT: parse_tree: [
|
|
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
|
|
// CHECK:STDOUT: {kind: 'ClassIntroducer', text: 'class'},
|
|
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'Foo'},
|
|
// CHECK:STDOUT: {kind: 'ClassDefinitionStart', text: '{', subtree_size: 3},
|
|
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
|
|
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'x'},
|
|
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
|
// CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 3},
|
|
// CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 4},
|
|
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 6},
|
|
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
|
|
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'y'},
|
|
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
|
// CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 3},
|
|
// CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 4},
|
|
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
|
|
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
|
|
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 8},
|
|
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
|
|
// CHECK:STDOUT: {kind: 'StaticModifier', text: 'static'},
|
|
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeSignature', text: 'z'},
|
|
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
|
|
// CHECK:STDOUT: {kind: 'VarBindingPattern', text: ':', subtree_size: 3},
|
|
// CHECK:STDOUT: {kind: 'VariablePattern', text: 'var', subtree_size: 4},
|
|
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 7},
|
|
// CHECK:STDOUT: {kind: 'ClassDefinition', text: '}', subtree_size: 25},
|
|
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
|
|
// CHECK:STDOUT: ]
|