expr_info.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // Returns whether the given expression category is for an initializer
  18. // (see inst_kind.h for background).
  19. inline auto IsInitializerCategory(ExprCategory cat) -> bool {
  20. return cat == ExprCategory::ReprInitializing ||
  21. cat == ExprCategory::InPlaceInitializing;
  22. }
  23. // If `init_id` is an initializer, find the inst ID that specifies the storage
  24. // to initialize, if any. If `allow_transitive` is true, the result may be an
  25. // argument to some other inst whose outcome is forwarded by `init_id`;
  26. // otherwise the result must be an argument to `init_id` itself. Returns `None`
  27. // if there is no such storage argument. When `allow_transitive` is true, this
  28. // can only return `None` if `init_id` is known not to perform in-place
  29. // initialization; i.e. its type's initializing representation is not in-place,
  30. // and its category is `Initializing`.
  31. auto FindStorageArgForInitializer(const File& sem_ir, InstId init_id,
  32. bool allow_transitive = true) -> InstId;
  33. } // namespace Carbon::SemIR
  34. #endif // CARBON_TOOLCHAIN_SEM_IR_EXPR_INFO_H_