mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Fixes #5186 With @zygoloid's kind assistance, this generalizes the existing non-const lowering of ClassInit, that had previously only handled InitializeFrom, to find other cases - such as a nested ClassInit used to initialize a class member. This refactors the `FindReturnSlotArgForInitializer` from `check/convert.cpp` into `sem_ir/file.{h,cpp}` for use from lowering (since lower doesn't depend on check, which I assume is an intentional layering constraint - so figured it made sense to move it to sem_ir, and found one or two similar-ish utility functions in `sem_ir/file.{h,cpp}`, so figured that was a good spot)
54 lines
1.9 KiB
C++
54 lines
1.9 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_EXPR_INFO_H_
|
|
#define CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
|
|
|
|
#include <cstdint>
|
|
|
|
#include "toolchain/sem_ir/file.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
// The expression category of a sem_ir instruction. See /docs/design/values.md
|
|
// for details.
|
|
enum class ExprCategory : int8_t {
|
|
// This instruction does not correspond to an expression, and as such has no
|
|
// category.
|
|
NotExpr,
|
|
// The category of this instruction is not known due to an error.
|
|
Error,
|
|
// This instruction represents a value expression.
|
|
Value,
|
|
// This instruction represents a durable reference expression, that denotes an
|
|
// object that outlives the current full expression context.
|
|
DurableRef,
|
|
// This instruction represents an ephemeral reference expression, that denotes
|
|
// an object that does not outlive the current full expression context.
|
|
EphemeralRef,
|
|
// This instruction represents an initializing expression, that describes how
|
|
// to initialize an object.
|
|
Initializing,
|
|
// This instruction represents a syntactic combination of expressions that are
|
|
// permitted to have different expression categories. This is used for tuple
|
|
// and struct literals, where the subexpressions for different elements can
|
|
// have different categories.
|
|
Mixed,
|
|
Last = Mixed
|
|
};
|
|
|
|
// Returns the expression category for an instruction.
|
|
auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory;
|
|
|
|
// Given an initializing expression, find its return slot argument. Returns
|
|
// `None` if there is no return slot, because the initialization is not
|
|
// performed in place.
|
|
auto FindReturnSlotArgForInitializer(const File& sem_ir, InstId init_id)
|
|
-> InstId;
|
|
|
|
} // namespace Carbon::SemIR
|
|
|
|
#endif // CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
|