summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index a9868898e..a7a4fc8dc 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2564,7 +2564,42 @@ void FrontEndCompileRequest::addTranslationUnitSourceFile(
int translationUnitIndex,
SourceFile* sourceFile)
{
- translationUnits[translationUnitIndex]->addSourceFile(sourceFile);
+ auto translationUnit = translationUnits[translationUnitIndex];
+
+ // TODO(JS):
+ // The larger problem here is that a file on a file system *could* be interpretted in different ways.
+ // When the user supplies the source as a string, we use the source type specified for the translation unit.
+ //
+ // If it's on the file system it could be (say) compiled as HLSL or some other way. A *downstream* compiler
+ // that used the file system may care.
+ //
+ // We will assume here, that if it's loaded from the file system, it's path extension defines how it should be interpretted
+ // If that wasn't the case we'd have to either *copy*, or do some command line fiddling to tell it for the downstream compiler
+ // what the file is.
+
+ const auto& pathInfo = sourceFile->getPathInfo();
+ const auto pathType = pathInfo.type;
+
+ switch (pathType)
+ {
+ case PathInfo::Type::FromString:
+ {
+ // Set the artifact type from the the source language type
+ auto sourceDesc = ArtifactDescUtil::makeDescForSourceLanguage(asExternal(translationUnit->sourceLanguage));
+ sourceFile->maybeAddArtifact(&sourceDesc, nullptr);
+ break;
+ }
+ case PathInfo::Type::FoundPath:
+ case PathInfo::Type::Normal:
+ {
+ // We'll *not* use the source for the artifact type. Doing so will lead to the type being determined via extension
+ sourceFile->maybeAddArtifact(nullptr, getLinkage()->getFileSystemExt());
+ break;
+ }
+ }
+
+ // Add the source file
+ translationUnit->addSourceFile(sourceFile);
}
void FrontEndCompileRequest::addTranslationUnitSourceBlob(
@@ -2575,8 +2610,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceBlob(
// The path specified may or may not be a file path - mark as being constructed 'FromString'.
SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(PathInfo::makeFromString(path), sourceBlob);
- sourceFile->maybeAddArtifact(nullptr);
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}
@@ -2588,8 +2621,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceString(
// The path specified may or may not be a file path - mark as being constructed 'FromString'.
SourceFile* sourceFile = getSourceManager()->createSourceFileWithString(PathInfo::makeFromString(path), source);
- sourceFile->maybeAddArtifact(nullptr);
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}
@@ -2622,8 +2653,6 @@ void FrontEndCompileRequest::addTranslationUnitSourceFile(
// Was loaded from the specified path
SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(pathInfo, sourceBlob);
- sourceFile->maybeAddArtifact(getLinkage()->getFileSystemExt());
-
addTranslationUnitSourceFile(translationUnitIndex, sourceFile);
}