Files
carbon-lang/toolchain/check/class.h
T
Nicholas Bishop 773ecdfac6 Implement static var class fields (#7215)
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.
2026-05-18 20:09:17 +00:00

35 lines
1.3 KiB
C++

// 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
#ifndef CARBON_TOOLCHAIN_CHECK_CLASS_H_
#define CARBON_TOOLCHAIN_CHECK_CLASS_H_
#include "toolchain/check/context.h"
namespace Carbon::Check {
// Sets the `Self` type for the class.
auto SetClassSelfType(Context& context, SemIR::ClassId class_id) -> void;
// Starts the class definition, adding `Self` to name lookup.
auto StartClassDefinition(Context& context, SemIR::Class& class_info,
SemIR::InstId definition_id) -> void;
// Computes the object representation for a fully defined class.
auto ComputeClassObjectRepr(Context& context, Parse::ClassDefinitionId node_id,
SemIR::ClassId class_id,
llvm::ArrayRef<SemIR::InstId> field_decls,
llvm::ArrayRef<SemIR::InstId> vtable_contents,
llvm::ArrayRef<SemIR::InstId> body) -> void;
// Whether a non-static field decl is currently being checked.
auto InNonStaticFieldDecl(Context& context) -> bool;
// Whether a static class var decl is currently being checked.
auto InStaticClassScopeVar(Context& context) -> bool;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_CLASS_H_