handle_class.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/context.h"
  5. namespace Carbon::Check {
  6. auto HandleClassIntroducer(Context& context, Parse::Node parse_node) -> bool {
  7. // Create a node block to hold the nodes created as part of the class
  8. // signature, such as generic parameters.
  9. context.node_block_stack().Push();
  10. // Push the bracketing node.
  11. context.node_stack().Push(parse_node);
  12. // A name should always follow.
  13. context.declaration_name_stack().Push();
  14. return true;
  15. }
  16. static auto BuildClassDeclaration(Context& context) -> void {
  17. auto name_context = context.declaration_name_stack().Pop();
  18. auto class_keyword =
  19. context.node_stack()
  20. .PopForSoloParseNode<Parse::NodeKind::ClassIntroducer>();
  21. // TODO: Track this somewhere.
  22. context.node_block_stack().Pop();
  23. auto class_id = context.semantics_ir().AddClass(
  24. {.name_id = name_context.state ==
  25. DeclarationNameStack::NameContext::State::Unresolved
  26. ? name_context.unresolved_name_id
  27. : SemIR::StringId(SemIR::StringId::InvalidIndex)});
  28. auto class_decl_id = context.AddNode(SemIR::ClassDeclaration(
  29. class_keyword, SemIR::TypeId::TypeType, class_id));
  30. context.declaration_name_stack().AddNameToLookup(name_context, class_decl_id);
  31. }
  32. auto HandleClassDeclaration(Context& context, Parse::Node /*parse_node*/)
  33. -> bool {
  34. BuildClassDeclaration(context);
  35. return true;
  36. }
  37. auto HandleClassDefinitionStart(Context& context, Parse::Node parse_node)
  38. -> bool {
  39. BuildClassDeclaration(context);
  40. // TODO: Introduce `Self`.
  41. return context.TODO(parse_node, "HandleClassDefinitionStart");
  42. }
  43. auto HandleClassDefinition(Context& context, Parse::Node parse_node) -> bool {
  44. return context.TODO(parse_node, "HandleClassDefinition");
  45. }
  46. } // namespace Carbon::Check