From 890403f576a85a7dca90d9d20360cd73c9ec9604 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 5 Mar 2019 13:30:36 -0500 Subject: * Fix issue with dependency including source path - even if source was compiled from a string (#878) * Added FromString Type to PathInfo to identify paths that are not from 'files' --- source/slang/slang.cpp | 29 ++++++++++++++--------------- source/slang/source-loc.cpp | 6 +++++- source/slang/source-loc.h | 8 ++++++-- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index c6946a93d..1eea13230 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -427,13 +427,12 @@ void TranslationUnitRequest::addSourceFile(SourceFile* sourceFile) // We want to record that the compiled module has a dependency // on the path of the source file, but we also need to account // for cases where the user added a source string/blob without - // an associated path (so that the API passes along an empty - // string). - // - auto path = sourceFile->getPathInfo().foundPath; - if(path.Length()) + // an associated path and/or wasn't from a file. + + auto pathInfo = sourceFile->getPathInfo(); + if (pathInfo.hasFileFoundPath()) { - getModule()->addFilePathDependency(path); + getModule()->addFilePathDependency(pathInfo.foundPath); } } @@ -976,8 +975,8 @@ void FrontEndCompileRequest::addTranslationUnitSourceBlob( String const& path, ISlangBlob* sourceBlob) { - PathInfo pathInfo = PathInfo::makePath(path); - SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(pathInfo, sourceBlob); + // The path specified may or may not be a file path - mark as being constructed 'FromString'. + SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(PathInfo::makeFromString(path), sourceBlob); addTranslationUnitSourceFile(translationUnitIndex, sourceFile); } @@ -987,9 +986,9 @@ void FrontEndCompileRequest::addTranslationUnitSourceString( String const& path, String const& source) { - PathInfo pathInfo = PathInfo::makePath(path); - SourceFile* sourceFile = getSourceManager()->createSourceFileWithString(pathInfo, source); - + // The path specified may or may not be a file path - mark as being constructed 'FromString'. + SourceFile* sourceFile = getSourceManager()->createSourceFileWithString(PathInfo::makeFromString(path), source); + addTranslationUnitSourceFile(translationUnitIndex, sourceFile); } @@ -1017,10 +1016,10 @@ void FrontEndCompileRequest::addTranslationUnitSourceFile( return; } - addTranslationUnitSourceBlob( - translationUnitIndex, - path, - sourceBlob); + // Was loaded from the specified path + const auto pathInfo = PathInfo::makePath(path); + SourceFile* sourceFile = getSourceManager()->createSourceFileWithBlob(pathInfo, sourceBlob); + addTranslationUnitSourceFile(translationUnitIndex, sourceFile); } int FrontEndCompileRequest::addEntryPoint( diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp index 00b6d3be4..886b4fefb 100644 --- a/source/slang/source-loc.cpp +++ b/source/slang/source-loc.cpp @@ -14,7 +14,11 @@ const String PathInfo::getMostUniqueIdentity() const switch (type) { case Type::Normal: return uniqueIdentity; - case Type::FoundPath: return foundPath; + case Type::FoundPath: + case Type::FromString: + { + return foundPath; + } default: return ""; } } diff --git a/source/slang/source-loc.h b/source/slang/source-loc.h index ad0453d0e..e12ec640e 100644 --- a/source/slang/source-loc.h +++ b/source/slang/source-loc.h @@ -45,7 +45,8 @@ struct PathInfo { Unknown, ///< The path is not known Normal, ///< Normal has both path and uniqueIdentity - FoundPath, ///< Just has a found path (uniqueIdentity is unknown, or even 'unknowable') + FoundPath, ///< Just has a found path (uniqueIdentity is unknown, or even 'unknowable') + FromString, ///< Created from a string (so found path might not be defined and should not be taken as to map to a loaded file) TokenPaste, ///< No paths, just created to do a macro expansion TypeParse, ///< No path, just created to do a type parse CommandLine, ///< A macro constructed from the command line @@ -54,7 +55,9 @@ struct PathInfo /// True if has a canonical path SLANG_FORCE_INLINE bool hasUniqueIdentity() const { return type == Type::Normal && uniqueIdentity.Length() > 0; } /// True if has a regular found path - SLANG_FORCE_INLINE bool hasFoundPath() const { return type == Type::Normal || type == Type::FoundPath; } + SLANG_FORCE_INLINE bool hasFoundPath() const { return type == Type::Normal || type == Type::FoundPath || (type == Type::FromString && foundPath.Length() > 0); } + /// True if has a found path that has originated from a file (as opposed to string or some other origin) + SLANG_FORCE_INLINE bool hasFileFoundPath() const { return (type == Type::Normal || type == Type::FoundPath) && foundPath.Length() > 0; } /// Returns the 'most unique' identity for the path. If has a 'uniqueIdentity' returns that, else the foundPath, else "". const String getMostUniqueIdentity() const; @@ -66,6 +69,7 @@ struct PathInfo static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.Length() > 0); return PathInfo { Type::FoundPath, pathIn, String()}; } static PathInfo makeTypeParse() { return PathInfo { Type::TypeParse, "type string", String() }; } static PathInfo makeCommandLine() { return PathInfo { Type::CommandLine, "command line", String() }; } + static PathInfo makeFromString(const String& userPath) { return PathInfo{ Type::FromString, userPath, String() }; } Type type; ///< The type of path String foundPath; ///< The path where the file was found (might contain relative elements) -- cgit v1.2.3