/
githubmirror
/
carbon-lang
Обзор
Документация
Войти
/
githubmirror
/
carbon-lang
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
toolchain/parse/handle_inline_decl.cpp
43 строки
2 KB
Richard Smith
Add support for `inline Cpp` declarations. (#6994)
01 апр 2026, 01:27
Не верифицирован
01 апр 2026, 01:27
8b59e85
Код
Авторство
О чём код?
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "toolchain/lex/token_kind.h" #include "toolchain/parse/context.h" #include "toolchain/parse/handle.h" #include "toolchain/parse/node_kind.h" #include "toolchain/parse/state.h" namespace Carbon::Parse { auto HandleInlineDeclAfterIntroducer(Context& context) -> void { auto state = context.PopState(); if (auto cpp_token = context.ConsumeIf(Lex::TokenKind::Cpp)) { context.AddLeafNode(NodeKind::CppNameExpr, *cpp_token); } else { CARBON_DIAGNOSTIC(ExpectedCppAfterInline, Error, "expected `Cpp` after `inline`"); context.emitter().Emit(*context.position(), ExpectedCppAfterInline); context.AddNode(NodeKind::InlineCppDecl, context.SkipPastLikelyEnd(state.token), /*has_error=*/true); return; } if (auto str = context.ConsumeIf(Lex::TokenKind::StringLiteral)) { context.AddLeafNode(NodeKind::InlineImportBody, *str); context.AddNodeExpectingDeclSemi(state, NodeKind::InlineCppDecl, Lex::TokenKind::Inline, /*is_def_allowed=*/false); } else { CARBON_DIAGNOSTIC(ExpectedStringAfterInlineCpp, Error, "expected string literal after `inline Cpp`"); context.emitter().Emit(*context.position(), ExpectedStringAfterInlineCpp); context.AddNode(NodeKind::InlineCppDecl, context.SkipPastLikelyEnd(state.token), /*has_error=*/true); } } } // namespace Carbon::Parse