name_component.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_NAME_COMPONENT_H_
  5. #define CARBON_TOOLCHAIN_CHECK_NAME_COMPONENT_H_
  6. #include "toolchain/check/node_stack.h"
  7. #include "toolchain/parse/node_ids.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. class Context;
  11. // A component in a declaration name, such as `C[T:! type](N:! T)` in
  12. // `fn C[T:! type](N:! T).F() {}`.
  13. struct NameComponent {
  14. // The name of the declaration.
  15. Parse::NodeId name_loc_id;
  16. SemIR::NameId name_id;
  17. // Parse tree bounds for the parameters, including both implicit and explicit
  18. // parameters. These will be compared to match between declaration and
  19. // definition.
  20. Parse::NodeId first_param_node_id;
  21. Parse::NodeId last_param_node_id;
  22. // The implicit parameter list.
  23. Parse::NodeId implicit_params_loc_id;
  24. SemIR::InstBlockId implicit_params_id;
  25. SemIR::InstBlockId implicit_param_patterns_id;
  26. // The explicit parameter list.
  27. Parse::NodeId params_loc_id;
  28. SemIR::InstBlockId params_id;
  29. SemIR::InstBlockId param_patterns_id;
  30. // The return slot.
  31. // TODO: These are only used for function declarations. Should they go
  32. // somewhere else?
  33. SemIR::InstId return_slot_pattern_id;
  34. SemIR::InstId return_slot_id;
  35. // The pattern block.
  36. SemIR::InstBlockId pattern_block_id;
  37. };
  38. // Pop a name component from the node stack and pattern block stack.
  39. auto PopNameComponent(Context& context, SemIR::InstId return_slot_pattern_id =
  40. SemIR::InstId::Invalid)
  41. -> NameComponent;
  42. // Pop the name of a declaration from the node stack and pattern block stack,
  43. // and diagnose if it has parameters.
  44. auto PopNameComponentWithoutParams(Context& context, Lex::TokenKind introducer)
  45. -> NameComponent;
  46. } // namespace Carbon::Check
  47. #endif // CARBON_TOOLCHAIN_CHECK_NAME_COMPONENT_H_