member_access.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_CHECK_MEMBER_ACCESS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_MEMBER_ACCESS_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Returns the highest allowed access for members of `name_scope_const_id`. For
  10. // example, if this returns `Protected` then only `Public` and `Protected`
  11. // accesses are allowed -- not `Private`.
  12. auto GetHighestAllowedAccess(Context& context, SemIR::LocId loc_id,
  13. SemIR::ConstantId name_scope_const_id)
  14. -> SemIR::AccessKind;
  15. // Creates SemIR to perform a member access with base expression `base_id` and
  16. // member name `name_id`. When `required`, failing to find the name is a
  17. // diagnosed error; otherwise, `None` is returned. Returns the result of the
  18. // access.
  19. auto PerformMemberAccess(Context& context, SemIR::LocId loc_id,
  20. SemIR::InstId base_id, SemIR::NameId name_id,
  21. bool required = true) -> SemIR::InstId;
  22. // Creates SemIR to perform a compound member access with base expression
  23. // `base_id` and member name expression `member_expr_id`. Returns the result of
  24. // the access. If specified, `missing_impl_diagnoser()` is used to build an
  25. // error diagnostic when impl binding fails due to a missing `impl`.
  26. auto PerformCompoundMemberAccess(
  27. Context& context, SemIR::LocId loc_id, SemIR::InstId base_id,
  28. SemIR::InstId member_expr_id,
  29. MakeDiagnosticBuilderFn missing_impl_diagnoser = nullptr) -> SemIR::InstId;
  30. // Finds the value of an associated entity (given by assoc_entity_inst_id, a
  31. // member of the interface given by interface_type_id) associated with a type or
  32. // facet (given by base_id). Never does instance binding.
  33. auto GetAssociatedValue(Context& context, SemIR::LocId loc_id,
  34. SemIR::InstId base_id,
  35. SemIR::ConstantId assoc_entity_const_id,
  36. SemIR::SpecificInterface interface) -> SemIR::InstId;
  37. // Creates SemIR to perform a tuple index with base expression `tuple_inst_id`
  38. // and index expression `index_inst_id`. Returns the result of the access.
  39. auto PerformTupleAccess(Context& context, SemIR::LocId loc_id,
  40. SemIR::InstId tuple_inst_id,
  41. SemIR::InstId index_inst_id) -> SemIR::InstId;
  42. } // namespace Carbon::Check
  43. #endif // CARBON_TOOLCHAIN_CHECK_MEMBER_ACCESS_H_