expr_info.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
  5. #define CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_
  6. #include <cstdint>
  7. #include "toolchain/sem_ir/file.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::SemIR {
  10. // The expression category of a sem_ir instruction. See /docs/design/values.md
  11. // for details.
  12. enum class ExprCategory : int8_t {
  13. // This instruction does not correspond to an expression, and as such has no
  14. // category.
  15. NotExpr,
  16. // The category of this instruction is not known due to an error.
  17. Error,
  18. // This instruction represents a value expression.
  19. Value,
  20. // This instruction represents a durable reference expression, that denotes an
  21. // object that outlives the current full expression context.
  22. DurableRef,
  23. // This instruction represents an ephemeral reference expression, that denotes
  24. // an object that does not outlive the current full expression context.
  25. EphemeralRef,
  26. // This instruction represents an initializing expression, that describes how
  27. // to initialize an object.
  28. Initializing,
  29. // This instruction represents a syntactic combination of expressions that are
  30. // permitted to have different expression categories. This is used for tuple
  31. // and struct literals, where the subexpressions for different elements can
  32. // have different categories.
  33. Mixed,
  34. Last = Mixed
  35. };
  36. // Returns the expression category for an instruction.
  37. auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory;
  38. // Returns whether the given expression category is for a reference expression.
  39. inline auto IsRefCategory(ExprCategory cat) -> bool {
  40. return cat == ExprCategory::DurableRef || cat == ExprCategory::EphemeralRef;
  41. }
  42. // Given an initializing expression, find its return slot argument. Returns
  43. // `None` if there is no return slot, because the initialization is not
  44. // performed in place.
  45. auto FindReturnSlotArgForInitializer(const File& sem_ir, InstId init_id)
  46. -> InstId;
  47. } // namespace Carbon::SemIR
  48. #endif // CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_