mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 21:30:44 +00:00
Avoid using a large switch that needs to be manually extended when adding a new kind of instruction. Instead, the expression category for an instruction is now specified when defining the `InstKind`. In passing, add a distinct expression category value for patterns. This isn't used for much except some error checking at the moment, but it keeps the number of instructions that we need to manually classify as `NotExpr` despite having a type very low.
33 lines
1.1 KiB
C++
33 lines
1.1 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"
|
|
#include "toolchain/sem_ir/inst_kind.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
// Returns the expression category for an instruction.
|
|
auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory;
|
|
|
|
// Returns whether the given expression category is for a reference expression.
|
|
inline auto IsRefCategory(ExprCategory cat) -> bool {
|
|
return cat == ExprCategory::DurableRef || cat == ExprCategory::EphemeralRef;
|
|
}
|
|
|
|
// 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_
|