handle_namespace.cpp 944 B

1234567891011121314151617181920212223242526
  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. #include "toolchain/sem_ir/inst.h"
  6. namespace Carbon::Check {
  7. auto HandleNamespaceStart(Context& context, Parse::Node /*parse_node*/)
  8. -> bool {
  9. context.declaration_name_stack().PushScopeAndStartName();
  10. return true;
  11. }
  12. auto HandleNamespace(Context& context, Parse::Node parse_node) -> bool {
  13. auto name_context = context.declaration_name_stack().FinishName();
  14. auto namespace_id = context.AddInst(SemIR::Namespace{
  15. parse_node, context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType),
  16. context.name_scopes().Add()});
  17. context.declaration_name_stack().AddNameToLookup(name_context, namespace_id);
  18. context.declaration_name_stack().PopScope();
  19. return true;
  20. }
  21. } // namespace Carbon::Check