require_impls_stack.h 1.5 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_CHECK_REQUIRE_IMPLS_STACK_H_
  5. #define CARBON_TOOLCHAIN_CHECK_REQUIRE_IMPLS_STACK_H_
  6. #include "common/array_stack.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // A stack where each frame holds an array of RequireImplsIds and is associated
  10. // with an enclosing scope that can be searched for in the stack.
  11. class RequireImplsStack {
  12. public:
  13. using EnclosingScopeId =
  14. std::variant<SemIR::InterfaceId, SemIR::NamedConstraintId>;
  15. // Push a new stack frame for an interface or named constraint to add
  16. // RequireImplsIds.
  17. auto Push(EnclosingScopeId scope_id) -> void;
  18. // Pop the top stack frame and all its RequireImplsIds.
  19. auto Pop() -> void;
  20. // Append to the top stack frame.
  21. auto AppendToTop(SemIR::RequireImplsId id) -> void;
  22. // Returns the RequireImplsIds in the top stack frame.
  23. auto PeekTop() const -> llvm::ArrayRef<SemIR::RequireImplsId>;
  24. // Finds the stack frame for a given scope and returns the RequireImplsIds in
  25. // that stack frame.
  26. auto PeekForScope(EnclosingScopeId scope_id)
  27. -> llvm::ArrayRef<SemIR::RequireImplsId>;
  28. private:
  29. llvm::SmallVector<EnclosingScopeId> scope_ids_;
  30. ArrayStack<SemIR::RequireImplsId> array_stack_;
  31. };
  32. } // namespace Carbon::Check
  33. #endif // CARBON_TOOLCHAIN_CHECK_REQUIRE_IMPLS_STACK_H_