handle_import_and_package.cpp 2.4 KB

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