name_component.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/function.h"
  9. #include "toolchain/sem_ir/ids.h"
  10. namespace Carbon::Check {
  11. class Context;
  12. // A component in a declaration name, such as `C[T:! type](N:! T)` in
  13. // `fn C[T:! type](N:! T).F() {}`.
  14. struct NameComponent {
  15. // The name of the declaration.
  16. Parse::NodeId name_loc_id;
  17. SemIR::NameId name_id;
  18. // Parse tree bounds for the parameters, including both implicit and explicit
  19. // parameters. These will be compared to match between declaration and
  20. // definition.
  21. Parse::NodeId first_param_node_id;
  22. Parse::NodeId last_param_node_id;
  23. // The implicit parameter list.
  24. Parse::NodeId implicit_params_loc_id;
  25. SemIR::InstBlockId implicit_param_patterns_id;
  26. // The explicit parameter list.
  27. Parse::NodeId params_loc_id;
  28. SemIR::InstBlockId param_patterns_id;
  29. // The `Call` parameters of the entity, if it's a function (see the
  30. // corresponding members of SemIR::FunctionFields and
  31. // SemIR::EntityWithParamsBase).
  32. SemIR::InstBlockId call_param_patterns_id;
  33. SemIR::InstBlockId call_params_id;
  34. SemIR::Function::CallParamIndexRanges param_ranges;
  35. // The pattern block.
  36. SemIR::InstBlockId pattern_block_id;
  37. };
  38. // Pops a name component from the node stack (and pattern block stack, if it has
  39. // parameters).
  40. auto PopNameComponent(Context& context, SemIR::InstBlockId return_patterns_id =
  41. SemIR::InstBlockId::None)
  42. -> NameComponent;
  43. // Equivalent to PopNameComponent, but also diagnoses if the name component has
  44. // parameters.
  45. auto PopNameComponentWithoutParams(Context& context, Lex::TokenKind introducer)
  46. -> NameComponent;
  47. } // namespace Carbon::Check
  48. #endif // CARBON_TOOLCHAIN_CHECK_NAME_COMPONENT_H_