handle_import_and_package.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_introducer_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_introducer_state_stack().Push(DeclIntroducerState::Import);
  14. return true;
  15. }
  16. auto HandleImportDecl(Context& context, Parse::ImportDeclId /*node_id*/)
  17. -> bool {
  18. auto introducer =
  19. context.decl_introducer_state_stack().Pop(DeclIntroducerState::Import);
  20. LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Export,
  21. Lex::TokenKind::Import);
  22. return true;
  23. }
  24. auto HandleLibraryIntroducer(Context& context,
  25. Parse::LibraryIntroducerId /*node_id*/) -> bool {
  26. context.decl_introducer_state_stack().Push(
  27. DeclIntroducerState::PackageOrLibrary);
  28. return true;
  29. }
  30. auto HandleLibraryDecl(Context& context, Parse::LibraryDeclId /*node_id*/)
  31. -> bool {
  32. auto introducer = context.decl_introducer_state_stack().Pop(
  33. DeclIntroducerState::PackageOrLibrary);
  34. LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Impl,
  35. Lex::TokenKind::Library);
  36. return true;
  37. }
  38. auto HandlePackageIntroducer(Context& context,
  39. Parse::PackageIntroducerId /*node_id*/) -> bool {
  40. context.decl_introducer_state_stack().Push(
  41. DeclIntroducerState::PackageOrLibrary);
  42. return true;
  43. }
  44. auto HandlePackageDecl(Context& context, Parse::PackageDeclId /*node_id*/)
  45. -> bool {
  46. auto introducer = context.decl_introducer_state_stack().Pop(
  47. DeclIntroducerState::PackageOrLibrary);
  48. LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Impl,
  49. Lex::TokenKind::Package);
  50. return true;
  51. }
  52. auto HandleLibrarySpecifier(Context& /*context*/,
  53. Parse::LibrarySpecifierId /*node_id*/) -> bool {
  54. return true;
  55. }
  56. auto HandlePackageName(Context& /*context*/, Parse::PackageNameId /*node_id*/)
  57. -> bool {
  58. return true;
  59. }
  60. auto HandleLibraryName(Context& /*context*/, Parse::LibraryNameId /*node_id*/)
  61. -> bool {
  62. return true;
  63. }
  64. auto HandleDefaultLibrary(Context& /*context*/,
  65. Parse::DefaultLibraryId /*node_id*/) -> bool {
  66. return true;
  67. }
  68. } // namespace Carbon::Check