Add export keyword handling. (#3944)

This provides `export import` logic in lex, parse, and check; `export
name` logic is only in lex and parse, not check.

I think with `export name` I'm going to need to modify import_ref and
some consolidation logic, whereas `export import` seems feasible to keep
as primarily import logic. Given the implementations were looking like
they'd diverge more substantially, I thought it'd be helpful to cut the
PR here.
This commit is contained in:
Jon Ross-Perkins
2024-05-10 22:54:06 +00:00
committed by GitHub
parent c7e4cb2c76
commit a16842ab37
21 changed files with 1823 additions and 81 deletions
+11 -3
View File
@@ -213,9 +213,11 @@ static auto CopyEnclosingNameScopesFromImportIR(
auto ImportLibraryFromCurrentPackage(Context& context,
SemIR::TypeId namespace_type_id,
Parse::ImportDirectiveId node_id,
const SemIR::File& import_sem_ir) -> void {
auto ir_id =
AddImportIR(context, {.node_id = node_id, .sem_ir = &import_sem_ir});
const SemIR::File& import_sem_ir,
bool is_export) -> void {
auto ir_id = AddImportIR(
context,
{.node_id = node_id, .sem_ir = &import_sem_ir, .is_export = is_export});
context.import_ir_constant_values()[ir_id.index].Set(
SemIR::InstId::PackageNamespace,
@@ -257,6 +259,12 @@ auto ImportLibraryFromCurrentPackage(Context& context,
}
}
}
// If an import of the current package caused an error for the imported
// file, it transitively affects the current file too.
if (import_sem_ir.name_scopes().Get(SemIR::NameScopeId::Package).has_error) {
context.name_scopes().Get(SemIR::NameScopeId::Package).has_error = true;
}
}
auto ImportLibrariesFromOtherPackage(Context& context,