member_access.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_diagnostic_context()` is used to
  25. // provide context for the error diagnostic when impl binding fails due to a
  26. // missing `impl`.
  27. //
  28. // On failure, an ErrorInst is returned and a diagnostic is produced unless
  29. // `diagnose` is false. It is incorrect to specify `diagnose` as false if the
  30. // resulting ErrorInst may appear in the produced SemIR.
  31. auto PerformCompoundMemberAccess(
  32. Context& context, SemIR::LocId loc_id, SemIR::InstId base_id,
  33. SemIR::InstId member_expr_id, bool diagnose = true,
  34. DiagnosticContextFn missing_impl_diagnostic_context = nullptr)
  35. -> SemIR::InstId;
  36. // Finds the value of an associated entity (given by assoc_entity_inst_id, a
  37. // member of the interface given by interface_type_id) associated with a type or
  38. // facet (given by base_id). Never does instance binding.
  39. auto GetAssociatedValue(Context& context, SemIR::LocId loc_id,
  40. SemIR::InstId base_id,
  41. SemIR::ConstantId assoc_entity_const_id,
  42. SemIR::SpecificInterface interface) -> SemIR::InstId;
  43. // Creates SemIR to perform a tuple index with base expression `tuple_inst_id`
  44. // and index expression `index_inst_id`. Returns the result of the access.
  45. auto PerformTupleAccess(Context& context, SemIR::LocId loc_id,
  46. SemIR::InstId tuple_inst_id,
  47. SemIR::InstId index_inst_id) -> SemIR::InstId;
  48. } // namespace Carbon::Check
  49. #endif // CARBON_TOOLCHAIN_CHECK_MEMBER_ACCESS_H_