summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-file-system.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-02-04 17:30:51 -0500
committerGitHub <noreply@github.com>2019-02-04 17:30:51 -0500
commit9b80537bc0272a9caf93f146d8964d9bdd4a407e (patch)
tree13c2e92adca1b78b632bd8dd6cc1fecb5a12ded9 /source/slang/slang-file-system.cpp
parent0d206996cd68b9f08ae1b4d9da6f16293984302c (diff)
Feature/view path (#824)
* Use 'is' over 'as' where appropriate. * dynamic_cast -> dynamicCast * Replace 'dynamicCast' with 'as' where has no change in behavior/ambiguity. * Replace dynamicCast with as where doesn't change behavior/non ambiguous. * Keep a per view path to the file loaded - such that diagnostic messages always display the path to the requested file. * Add simplifyPath to ISlangFileSystemExt Simplify (if possible) paths that are set on SourceFile and SourcView - doing so makes reading paths simpler. * Fix small typo. * Improve documentation in source for getFileUniqueIdentity * Fix override warning.
Diffstat (limited to 'source/slang/slang-file-system.cpp')
-rw-r--r--source/slang/slang-file-system.cpp48
1 files changed, 45 insertions, 3 deletions
diff --git a/source/slang/slang-file-system.cpp b/source/slang/slang-file-system.cpp
index b3ba692bd..d52ea1157 100644
--- a/source/slang/slang-file-system.cpp
+++ b/source/slang/slang-file-system.cpp
@@ -76,6 +76,13 @@ SlangResult OSFileSystem::getCanonicalPath(const char* path, ISlangBlob** outCan
return SLANG_OK;
}
+SlangResult OSFileSystem::getSimplifiedPath(const char* pathIn, ISlangBlob** outSimplifiedPath)
+{
+ String simplifiedPath = Path::Simplify(_fixPathDelimiters(pathIn));
+ *outSimplifiedPath = StringUtil::createStringBlob(simplifiedPath).detach();
+ return SLANG_OK;
+}
+
SlangResult OSFileSystem::calcCombinedPath(SlangPathType fromPathType, const char* fromPath, const char* path, ISlangBlob** pathOut)
{
// Don't need to fix delimiters - because combine path handles both path delimiter types
@@ -143,9 +150,10 @@ ISlangUnknown* CacheFileSystem::getInterface(const Guid& guid)
return _getInterface(this, guid);
}
-CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode) :
+CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMode uniqueIdentityMode, PathStyle pathStyle) :
m_fileSystem(fileSystem),
- m_uniqueIdentityMode(uniqueIdentityMode)
+ m_uniqueIdentityMode(uniqueIdentityMode),
+ m_pathStyle(pathStyle)
{
// Try to get the more sophisticated interface
fileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)m_fileSystemExt.writeRef());
@@ -162,6 +170,17 @@ CacheFileSystem::CacheFileSystem(ISlangFileSystem* fileSystem, UniqueIdentityMod
default: break;
}
+ if (m_fileSystemExt)
+ {
+ // We just defer to the m_fileSystem, so we mark as unknown
+ m_pathStyle = PathStyle::Unknown;
+ }
+ else if (m_pathStyle == PathStyle::Default)
+ {
+ // We'll assume it's simplify-able
+ m_pathStyle = PathStyle::Simplifiable;
+ }
+
// It can't be default
SLANG_ASSERT(m_uniqueIdentityMode != UniqueIdentityMode::Default);
}
@@ -286,7 +305,7 @@ CacheFileSystem::PathInfo* CacheFileSystem::_resolveUniqueIdentityCacheInfo(cons
// At this point they must have same uniqueIdentity
SLANG_ASSERT(pathInfo->getUniqueIdentity() == uniqueIdentity);
- // If we have the file contents (because of calcing uniqueIdentity), and there isn't a read fileblob already
+ // If we have the file contents (because of calc-ing uniqueIdentity), and there isn't a read file blob already
// store the data as if read, so doesn't get read again
if (fileContents && !pathInfo->m_fileBlob)
{
@@ -414,6 +433,29 @@ SlangResult CacheFileSystem::getPathType(const char* pathIn, SlangPathType* path
return toResult(info->m_getPathTypeResult);
}
+SlangResult CacheFileSystem::getSimplifiedPath(const char* path, ISlangBlob** outSimplifiedPath)
+{
+ // If we have a ISlangFileSystemExt we can just pass on the request to it
+ if (m_fileSystemExt)
+ {
+ return m_fileSystemExt->getSimplifiedPath(path, outSimplifiedPath);
+ }
+ else
+ {
+ // Use the path style to see what we can do with it
+ switch (m_pathStyle)
+ {
+ case PathStyle::Simplifiable:
+ {
+ String simplifiedPath = Path::Simplify(_fixPathDelimiters(path));
+ *outSimplifiedPath = StringUtil::createStringBlob(simplifiedPath).detach();
+ return SLANG_OK;
+ }
+ default: return SLANG_E_NOT_IMPLEMENTED;
+ }
+ }
+}
+
SlangResult CacheFileSystem::getCanonicalPath(const char* path, ISlangBlob** outCanonicalPath)
{
// If we don't have a backing full file system, we can't produce a canonical path with just ISlangFileSystem::loadFile