summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-source-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-09-01 10:06:19 -0400
committerGitHub <noreply@github.com>2022-09-01 10:06:19 -0400
commit3c0177134d126956336865623ea3d6861be59cfa (patch)
tree920ba158afe75edde6f5254617dfa22ffeb98403 /source/compiler-core/slang-source-loc.cpp
parentcd8715a7760189c54b36c0c250efbe1db5b8635c (diff)
Make FileSystem files and OS files distinct (#2383)
* #include an absolute path didn't work - because paths were taken to always be relative. * Make DownstreamCompileOptions use POD types. * CharSliceAllocator -> SliceAllocator Added SliceConverter CharSliceCaster -> SliceCaster * First attempt at zero terminating around blobs. * Fix clang warning. * Add SlangTerminatedChars Make Blob implementations support it. Make most blobs 'terminated'. * Fix bug setting up sourceFiles for CommandLineDownstreamCompiler. * Traffic in TerminatedCharSlice for sourceFiles. Use ArtifactDesc to generate temporary file names for source. * Fix typo in testing for shared library/C++. * Working with source being passed as artifacts to DownstreamCompiler. * Use artifacts in SourceManager/SourceFile. * Support infering extension from the original file extension. * * Infer extension if can't determine from the artifact type * Split IOSFile/IExtFile representations * Move responsibility for creating OS file to the handler. * Disable the check memory path.
Diffstat (limited to 'source/compiler-core/slang-source-loc.cpp')
-rw-r--r--source/compiler-core/slang-source-loc.cpp76
1 files changed, 35 insertions, 41 deletions
diff --git a/source/compiler-core/slang-source-loc.cpp b/source/compiler-core/slang-source-loc.cpp
index c82636248..6b4c5654d 100644
--- a/source/compiler-core/slang-source-loc.cpp
+++ b/source/compiler-core/slang-source-loc.cpp
@@ -6,6 +6,8 @@
#include "slang-artifact-representation-impl.h"
#include "slang-artifact-impl.h"
+#include "slang-artifact-util.h"
+#include "slang-artifact-desc-util.h"
namespace Slang {
@@ -432,69 +434,61 @@ String SourceFile::calcVerbosePath() const
return m_pathInfo.foundPath;
}
-void SourceFile::maybeAddArtifact(ISlangFileSystemExt* ext)
+void SourceFile::maybeAddArtifact(const ArtifactDesc* inArtifactDesc, ISlangFileSystemExt* ext)
{
if (!m_contentBlob)
{
return;
}
- // If there already is an artifact, or we are not using OSFile system then
+ // If there already is an artifact, we don't need to create one
if (m_artifact)
{
- // TODO(JS):
- // Check if it has the blob or not
+ // Check it has a blob and the blob is the same as the content blob
SLANG_ASSERT(m_contentBlob == findRepresentation<ISlangBlob>(m_artifact));
return;
}
- // We don't know how the source will be used
- m_artifact = Artifact::create(ArtifactDesc::make(ArtifactKind::Source, ArtifactPayload::Unknown, ArtifactStyle::Unknown));
+ ArtifactDesc artifactDesc;
- // Add the blob as a representation.
- m_artifact->addRepresentationUnknown(m_contentBlob);
-
- // If we have the file system see if we can set up a path too
- if (ext)
+ if (inArtifactDesc)
{
- const auto osPathKind = ext->getOSPathKind();
+ artifactDesc = *inArtifactDesc;
+ }
+ else
+ {
+ // Set the default
+ artifactDesc = ArtifactDesc::make(ArtifactKind::Source, ArtifactPayload::Unknown, ArtifactStyle::Unknown);
- if (osPathKind != OSPathKind::None)
+ // Let's work out from the
+ // We could try and work it out
+ if (getPathInfo().foundPath.getLength())
{
- String path;
- switch (osPathKind)
- {
- case OSPathKind::Canonical:
- {
- // Get the canonical path
- ComPtr<ISlangBlob> canonicalPath;
- if (SLANG_SUCCEEDED(ext->getCanonicalPath(getPathInfo().foundPath.getBuffer(), canonicalPath.writeRef())))
- {
- path = StringUtil::getString(canonicalPath);
- }
- break;
- }
- case OSPathKind::Direct:
- {
- path = getPathInfo().foundPath;
- break;
- }
- }
+ // Let's work out what kind of source it is from the this
+ auto desc = ArtifactDescUtil::getDescFromPath(getPathInfo().foundPath.getUnownedSlice());
- if (path.getLength())
+ // If found something just use that
+ if (desc.kind == ArtifactKind::Source)
{
- // We can sanity check that this works
- SlangPathType pathType;
- if (SLANG_SUCCEEDED(ext->getPathType(path.getBuffer(), &pathType)))
- {
- // We can add a file representation
- FileArtifactRepresentation* fileRep = new FileArtifactRepresentation(IFileArtifactRepresentation::Kind::Reference, path.getUnownedSlice(), nullptr, nullptr);
- m_artifact->addRepresentation(fileRep);
- }
+ artifactDesc = desc;
}
}
}
+ // We don't know how the source will be used
+ m_artifact = Artifact::create(artifactDesc);
+
+ // Add the blob as a representation.
+ m_artifact->addRepresentationUnknown(m_contentBlob);
+
+ // If we have the file system, set up the rep to that
+ if (ext)
+ {
+ // Add the representation on the file system
+ auto extRep = new ExtFileArtifactRepresentation(getPathInfo().foundPath.getUnownedSlice(), ext);
+ m_artifact->addRepresentation(extRep);
+ }
+
// Get the name
auto name = getPathInfo().getName();
if (name.getLength())