Files
carbon-lang/toolchain/check/handle_import_and_package.cpp
T
Richard Smith 23f9065949 Implement proposal #3927. (#3963)
Change syntax for package declaration to put the `impl` keyword at the
start and remove the `api` keyword.

To support this, rearrange processing of package, library, and import
declarations to use the general modifier handling support in declaration
parsing rather than special-case logic.

There is an ambiguity in `impl package.Foo as Bar`, which we resolve by
treating `package` as an introducer after a modifier only if it's not
followed by `.`.
2024-05-21 00:36:03 +00:00

77 lines
2.4 KiB
C++

// 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/check/context.h"
#include "toolchain/check/decl_state.h"
#include "toolchain/check/modifiers.h"
namespace Carbon::Check {
// `import` and `package` are structured by parsing. As a consequence, no
// checking logic is needed here.
auto HandleImportIntroducer(Context& context,
Parse::ImportIntroducerId /*node_id*/) -> bool {
context.decl_state_stack().Push(DeclState::Import);
return true;
}
auto HandleImportDecl(Context& context, Parse::ImportDeclId /*node_id*/)
-> bool {
LimitModifiersOnDecl(context, KeywordModifierSet::Export,
Lex::TokenKind::Import);
context.decl_state_stack().Pop(DeclState::Import);
return true;
}
auto HandleLibraryIntroducer(Context& context,
Parse::LibraryIntroducerId /*node_id*/) -> bool {
context.decl_state_stack().Push(DeclState::PackageOrLibrary);
return true;
}
auto HandleLibraryDecl(Context& context, Parse::LibraryDeclId /*node_id*/)
-> bool {
LimitModifiersOnDecl(context, KeywordModifierSet::Impl,
Lex::TokenKind::Library);
context.decl_state_stack().Pop(DeclState::PackageOrLibrary);
return true;
}
auto HandlePackageIntroducer(Context& context,
Parse::PackageIntroducerId /*node_id*/) -> bool {
context.decl_state_stack().Push(DeclState::PackageOrLibrary);
return true;
}
auto HandlePackageDecl(Context& context, Parse::PackageDeclId /*node_id*/)
-> bool {
LimitModifiersOnDecl(context, KeywordModifierSet::Impl,
Lex::TokenKind::Package);
context.decl_state_stack().Pop(DeclState::PackageOrLibrary);
return true;
}
auto HandleLibrarySpecifier(Context& /*context*/,
Parse::LibrarySpecifierId /*node_id*/) -> bool {
return true;
}
auto HandlePackageName(Context& /*context*/, Parse::PackageNameId /*node_id*/)
-> bool {
return true;
}
auto HandleLibraryName(Context& /*context*/, Parse::LibraryNameId /*node_id*/)
-> bool {
return true;
}
auto HandleDefaultLibrary(Context& /*context*/,
Parse::DefaultLibraryId /*node_id*/) -> bool {
return true;
}
} // namespace Carbon::Check