Files
carbon-lang/toolchain/sem_ir/pattern.h
T
Richard Smith 5b884ae14d Improve lowering for global variables. (#5492)
- Track the `VarPattern` instruction on the `VarStorage` instruction so
that it's available for name mangling.
- Mangle global variables based on the first binding name within their
pattern.
- Give global variables external rather than internal linkage, except if
they have no bindings whatsoever in their pattern.
- To support lowering references to bindings nested within a global var,
such as for `var (x: i32, b: i32)`, add some basic initial support for
reference constant expressions. Treat a global `var` as a reference
constant, and treat an aggregate access into a reference constant as a
reference constant.
2025-05-21 00:09:10 +00:00

36 lines
1.4 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_SEM_IR_PATTERN_H_
#define CARBON_TOOLCHAIN_SEM_IR_PATTERN_H_
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/ids.h"
namespace Carbon::SemIR {
// Returns true if `pattern_id` is a `self` parameter pattern, such as
// `self: Foo` or `addr self: Self*`.
auto IsSelfPattern(const File& sem_ir, InstId pattern_id) -> bool;
// If `pattern_id` introduces any name bindings, this returns the `EntityNameId`
// of the lexically-first such binding. Otherwise, returns `None`.
auto GetFirstBindingNameFromPatternId(const File& sem_ir, InstId pattern_id)
-> EntityNameId;
// If `pattern_id` is a declaration of a single name, this returns that name,
// and otherwise returns `None`. This tries to "see through" wrappers like
// `AddrPattern` and `*ParamPattern`, so this may return the same name for
// different insts if one is an ancestor of the other (or if they represent
// separate declarations of the same name).
//
// This should only be used for decorative purposes such as SemIR
// pretty-printing or LLVM parameter naming.
auto GetPrettyNameFromPatternId(const File& sem_ir, InstId pattern_id)
-> NameId;
} // namespace Carbon::SemIR
#endif // CARBON_TOOLCHAIN_SEM_IR_PATTERN_H_