handle_adapt.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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/parse/context.h"
  5. namespace Carbon::Parse {
  6. // Handles processing of a complete `adapt T` declaration.
  7. auto HandleAdaptDecl(Context& context) -> void {
  8. // TODO: This is identical to HandleBaseDecl other than the `NodeKind`,
  9. // and very similar to `HandleNamespaceFinish` and `HandleAliasFinish`.
  10. // We should factor out this common work.
  11. auto state = context.PopState();
  12. auto semi = context.ConsumeIf(Lex::TokenKind::Semi);
  13. if (!semi && !state.has_error) {
  14. context.EmitExpectedDeclSemi(context.tokens().GetKind(state.token));
  15. state.has_error = true;
  16. }
  17. if (state.has_error) {
  18. context.RecoverFromDeclError(state, NodeKind::AdaptDecl,
  19. /*skip_past_likely_end=*/true);
  20. return;
  21. }
  22. context.AddNode(NodeKind::AdaptDecl, *semi, state.subtree_start,
  23. state.has_error);
  24. }
  25. } // namespace Carbon::Parse