diff options
Diffstat (limited to 'source/compiler-core/slang-source-loc.cpp')
| -rw-r--r-- | source/compiler-core/slang-source-loc.cpp | 76 |
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()) |
