mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:21:16 +01:00
Previously we walked the global variables defined by the current file and emitted an LLVM global variable definition for each of them. Now instead, when emitting a constant reference to a global variable, we emit an LLVM global variable declaration, and we then subsequently walk the global variables defined by the current file and convert each of them from a declaration to a definition. In order to make import of names of global variables work, add support for import of `var`, as well as support for importing `tuple_access` and `tuple_pattern` in the case where the `var` has a tuple pattern in its declaration. Also treat `bind_name`s that are reference bindings to `var`s as having the same constant reference value as their `var` so that we can properly import and lower them. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
59 lines
2.2 KiB
C++
59 lines
2.2 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;
|
|
|
|
// 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_
|