modifiers.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef CARBON_TOOLCHAIN_CHECK_MODIFIERS_H_
  5. #define CARBON_TOOLCHAIN_CHECK_MODIFIERS_H_
  6. #include "toolchain/check/context.h"
  7. namespace Carbon::Check {
  8. // Reports a diagnostic if access control modifiers on this are not allowed for
  9. // a declaration in `parent_scope_inst`, and updates `introducer`.
  10. //
  11. // `parent_scope_inst` may be nullopt for a declaration in a block scope.
  12. auto CheckAccessModifiersOnDecl(Context& context,
  13. DeclIntroducerState& introducer,
  14. std::optional<SemIR::Inst> parent_scope_inst)
  15. -> void;
  16. // Reports a diagnostic if the method function modifiers `abstract`, `virtual`,
  17. // or `impl` are present but not permitted on a function declaration in
  18. // `parent_scope_inst`.
  19. //
  20. // `parent_scope_inst` may be nullopt for a declaration in a block scope.
  21. auto CheckMethodModifiersOnFunction(
  22. Context& context, DeclIntroducerState& introducer,
  23. SemIR::InstId parent_scope_inst_id,
  24. std::optional<SemIR::Inst> parent_scope_inst) -> void;
  25. // Reports a diagnostic (using `decl_kind`) if modifiers on this declaration are
  26. // not in `allowed`. Updates `introducer`.
  27. auto LimitModifiersOnDecl(Context& context, DeclIntroducerState& introducer,
  28. KeywordModifierSet allowed) -> void;
  29. auto LimitModifiersOnNotDefinition(Context& context,
  30. DeclIntroducerState& introducer,
  31. KeywordModifierSet allowed) -> void;
  32. // Restricts the `extern` modifier to only be used on namespace-scoped
  33. // declarations. Diagnoses and cleans up:
  34. // - `extern library` on a definition.
  35. // - `extern` on a scoped entity.
  36. //
  37. // `parent_scope_inst` may be nullopt for a declaration in a block scope.
  38. auto RestrictExternModifierOnDecl(Context& context,
  39. DeclIntroducerState& introducer,
  40. std::optional<SemIR::Inst> parent_scope_inst,
  41. bool is_definition) -> void;
  42. // Report a diagonostic if `default` and `final` modifiers are used on
  43. // declarations where they are not allowed. Right now they are only allowed
  44. // inside interfaces.
  45. //
  46. // `parent_scope_inst` may be nullopt for a declaration in a block scope.
  47. auto RequireDefaultFinalOnlyInInterfaces(
  48. Context& context, DeclIntroducerState& introducer,
  49. std::optional<SemIR::Inst> parent_scope_inst) -> void;
  50. } // namespace Carbon::Check
  51. #endif // CARBON_TOOLCHAIN_CHECK_MODIFIERS_H_