generic_region_stack.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #include "toolchain/check/generic_region_stack.h"
  5. namespace Carbon::Check {
  6. auto GenericRegionStack::Push() -> void { dependent_insts_stack_.PushArray(); }
  7. auto GenericRegionStack::Pop() -> void { dependent_insts_stack_.PopArray(); }
  8. auto GenericRegionStack::AddDependentInst(DependentInst inst) -> void {
  9. if (dependent_insts_stack_.empty()) {
  10. // If we don't have a generic region here, leave the dependent instruction
  11. // unattached. This happens for out-of-line redeclarations of members of
  12. // dependent scopes:
  13. //
  14. // class A(T:! type) {
  15. // fn F();
  16. // }
  17. // // Has generic type and constant value, but no generic region.
  18. // fn A(T:! type).F() {}
  19. //
  20. // TODO: Use a different instruction kind for out-of-line definitions and
  21. // CHECK this doesn't happen.
  22. return;
  23. }
  24. dependent_insts_stack_.AppendToTop(inst);
  25. }
  26. auto GenericRegionStack::PeekDependentInsts() -> llvm::ArrayRef<DependentInst> {
  27. return dependent_insts_stack_.PeekArray();
  28. }
  29. } // namespace Carbon::Check