aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2025-01-31 08:34:15 +0000
committergingerBill <bill@gingerbill.org>2025-01-31 08:34:15 +0000
commit0cd20e61ab5989e7a759051df2a629facfb53f41 (patch)
tree346d6eeb162fd57626ca029b56ca16328ead23d0 /src
parent2656ecd4e17d448f1d972270bde87f75bc096d0d (diff)
Add `@(export) foreign import`
Diffstat (limited to 'src')
-rw-r--r--src/checker.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index baa1e0d2b..0ac787e00 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -5016,6 +5016,9 @@ gb_internal DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) {
error(elem, "Expected a string value for '%.*s'", LIT(name));
}
return true;
+ } else if (name == "export") {
+ ac->is_export = true;
+ return true;
} else if (name == "force" || name == "require") {
if (value != nullptr) {
error(elem, "Expected no parameter for '%.*s'", LIT(name));
@@ -5181,14 +5184,21 @@ gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) {
GB_ASSERT(fl->library_name.pos.line != 0);
fl->library_name.string = library_name;
+ AttributeContext ac = {};
+ check_decl_attributes(ctx, fl->attributes, foreign_import_decl_attribute, &ac);
+
+ Scope *scope = parent_scope;
+ if (ac.is_export) {
+ scope = parent_scope->parent;
+ }
+
Entity *e = alloc_entity_library_name(parent_scope, fl->library_name, t_invalid,
fl->fullpaths, library_name);
e->LibraryName.decl = decl;
add_entity_flags_from_file(ctx, e, parent_scope);
- add_entity(ctx, parent_scope, nullptr, e);
+ add_entity(ctx, scope, nullptr, e);
+
- AttributeContext ac = {};
- check_decl_attributes(ctx, fl->attributes, foreign_import_decl_attribute, &ac);
if (ac.require_declaration) {
mpsc_enqueue(&ctx->info->required_foreign_imports_through_force_queue, e);
add_entity_use(ctx, nullptr, e);