summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/check.cpp47
-rw-r--r--source/slang/parser.cpp3
-rw-r--r--source/slang/syntax.h1
-rw-r--r--tests/front-end/import-exported-a.slang5
-rw-r--r--tests/front-end/import-exported-b.slang5
-rw-r--r--tests/front-end/import-exported.slang8
6 files changed, 53 insertions, 16 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 582f19448..11efb2f7d 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -4893,6 +4893,36 @@ namespace Slang
return expr;
}
+ void importModuleIntoScope(Scope* scope, ProgramSyntaxNode* moduleDecl)
+ {
+ // If we've imported this one already, then
+ // skip the step where we modify the current scope.
+ if (importedModules.Contains(moduleDecl))
+ {
+ return;
+ }
+ importedModules.Add(moduleDecl);
+
+
+ // Create a new sub-scope to wire the module
+ // into our lookup chain.
+ auto subScope = new Scope();
+ subScope->containerDecl = moduleDecl;
+
+ subScope->nextSibling = scope->nextSibling;
+ scope->nextSibling = subScope;
+
+ // Also import any modules from nested `import` declarations
+ // with the `__exported` modifier
+ for (auto importDecl : moduleDecl->getMembersOfType<ImportDecl>())
+ {
+ if (!importDecl->HasModifier<ExportedModifier>())
+ continue;
+
+ importModuleIntoScope(scope, importDecl->importedModuleDecl.Ptr());
+ }
+ }
+
virtual void visitImportDecl(ImportDecl* decl) override
{
if(decl->IsChecked(DeclCheckState::Checked))
@@ -4917,22 +4947,7 @@ namespace Slang
// it later during code generation.
decl->importedModuleDecl = importedModuleDecl;
- // If we've imported this one already, then
- // skip the step where we modify the current scope.
- if (importedModules.Contains(importedModuleDecl.Ptr()))
- {
- return;
- }
- importedModules.Add(importedModuleDecl.Ptr());
-
-
- // Create a new sub-scope to wire the module
- // into our lookup chain.
- auto subScope = new Scope();
- subScope->containerDecl = importedModuleDecl.Ptr();
-
- subScope->nextSibling = scope->nextSibling;
- scope->nextSibling = subScope;
+ importModuleIntoScope(scope.Ptr(), importedModuleDecl.Ptr());
decl->SetCheckState(DeclCheckState::Checked);
}
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp
index 8edc3a122..1d843c821 100644
--- a/source/slang/parser.cpp
+++ b/source/slang/parser.cpp
@@ -619,6 +619,9 @@ namespace Slang
CASE(__prefix, PrefixModifier);
CASE(__postfix, PostfixModifier);
+ // Modifier to apply to `import` that should be re-exported
+ CASE(__exported, ExportedModifier);
+
#undef CASE
else if (AdvanceIf(parser, "__intrinsic_op"))
diff --git a/source/slang/syntax.h b/source/slang/syntax.h
index 7a1701b88..7289719f4 100644
--- a/source/slang/syntax.h
+++ b/source/slang/syntax.h
@@ -57,6 +57,7 @@ namespace Slang
SIMPLE_MODIFIER(FromStdLib);
SIMPLE_MODIFIER(Prefix);
SIMPLE_MODIFIER(Postfix);
+ SIMPLE_MODIFIER(Exported);
#undef SIMPLE_MODIFIER
diff --git a/tests/front-end/import-exported-a.slang b/tests/front-end/import-exported-a.slang
new file mode 100644
index 000000000..b624241e5
--- /dev/null
+++ b/tests/front-end/import-exported-a.slang
@@ -0,0 +1,5 @@
+//TEST_IGNORE_FILE:
+
+// This file imports other code, and re-exports it to clients of this module.
+
+__exported __import import_exported_b; \ No newline at end of file
diff --git a/tests/front-end/import-exported-b.slang b/tests/front-end/import-exported-b.slang
new file mode 100644
index 000000000..144f62060
--- /dev/null
+++ b/tests/front-end/import-exported-b.slang
@@ -0,0 +1,5 @@
+//TEST_IGNORE_FILE:
+
+// This file defines the code that will be (transitively) imported into `import-exported.slang`
+
+float foo(float x) { return x; } \ No newline at end of file
diff --git a/tests/front-end/import-exported.slang b/tests/front-end/import-exported.slang
new file mode 100644
index 000000000..7c2d911dd
--- /dev/null
+++ b/tests/front-end/import-exported.slang
@@ -0,0 +1,8 @@
+//TEST:SIMPLE:
+
+// Confirming that we can use a re-exported function
+
+// `a` imports `b` (which defines `foo`) and re-exports it
+__import import_exported_a;
+
+float bar(float x) { return foo(x); } \ No newline at end of file