expr_info.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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. #include "toolchain/sem_ir/inst_kind.h"
  10. namespace Carbon::SemIR {
  11. // Returns the expression category for an instruction.
  12. auto GetExprCategory(const File& file, InstId inst_id) -> ExprCategory;
  13. // Returns whether the given expression category is for a reference expression.
  14. inline auto IsRefCategory(ExprCategory cat) -> bool {
  15. return cat == ExprCategory::DurableRef || cat == ExprCategory::EphemeralRef;
  16. }
  17. // Given a primitive-form initializing expression, find its return slot
  18. // argument. If `allow_transitive` is true, the result may be an argument to
  19. // some other inst whose outcome is forwarded by `init_id`; otherwise the result
  20. // must be an argument to `init_id` itself. Returns `None` if no such return
  21. // slot is found.
  22. auto FindReturnSlotArgForInitializer(const File& sem_ir, InstId init_id,
  23. bool allow_transitive = true) -> InstId;
  24. } // namespace Carbon::SemIR
  25. #endif // CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_