handle_import_and_package.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/check/decl_state.h"
  6. #include "toolchain/check/handle.h"
  7. #include "toolchain/check/modifiers.h"
  8. namespace Carbon::Check {
  9. // `import` and `package` are structured by parsing. As a consequence, no
  10. // checking logic is needed here.
  11. auto HandleImportIntroducer(Context& context,
  12. Parse::ImportIntroducerId /*node_id*/) -> bool {
  13. context.decl_state_stack().Push(DeclState::Import);
  14. return true;
  15. }
  16. auto HandleImportDecl(Context& context, Parse::ImportDeclId /*node_id*/)
  17. -> bool {
  18. LimitModifiersOnDecl(context, KeywordModifierSet::Export,
  19. Lex::TokenKind::Import);
  20. context.decl_state_stack().Pop(DeclState::Import);
  21. return true;
  22. }
  23. auto HandleLibraryIntroducer(Context& context,
  24. Parse::LibraryIntroducerId /*node_id*/) -> bool {
  25. context.decl_state_stack().Push(DeclState::PackageOrLibrary);
  26. return true;
  27. }
  28. auto HandleLibraryDecl(Context& context, Parse::LibraryDeclId /*node_id*/)
  29. -> bool {
  30. LimitModifiersOnDecl(context, KeywordModifierSet::Impl,
  31. Lex::TokenKind::Library);
  32. context.decl_state_stack().Pop(DeclState::PackageOrLibrary);
  33. return true;
  34. }
  35. auto HandlePackageIntroducer(Context& context,
  36. Parse::PackageIntroducerId /*node_id*/) -> bool {
  37. context.decl_state_stack().Push(DeclState::PackageOrLibrary);
  38. return true;
  39. }
  40. auto HandlePackageDecl(Context& context, Parse::PackageDeclId /*node_id*/)
  41. -> bool {
  42. LimitModifiersOnDecl(context, KeywordModifierSet::Impl,
  43. Lex::TokenKind::Package);
  44. context.decl_state_stack().Pop(DeclState::PackageOrLibrary);
  45. return true;
  46. }
  47. auto HandleLibrarySpecifier(Context& /*context*/,
  48. Parse::LibrarySpecifierId /*node_id*/) -> bool {
  49. return true;
  50. }
  51. auto HandlePackageName(Context& /*context*/, Parse::PackageNameId /*node_id*/)
  52. -> bool {
  53. return true;
  54. }
  55. auto HandleLibraryName(Context& /*context*/, Parse::LibraryNameId /*node_id*/)
  56. -> bool {
  57. return true;
  58. }
  59. auto HandleDefaultLibrary(Context& /*context*/,
  60. Parse::DefaultLibraryId /*node_id*/) -> bool {
  61. return true;
  62. }
  63. } // namespace Carbon::Check