summaryrefslogtreecommitdiffstats
path: root/source/slang/source-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-01-21 16:41:54 -0500
committerGitHub <noreply@github.com>2019-01-21 16:41:54 -0500
commitbd815f02d846a50e16dab67e6512db2a6215c41f (patch)
tree01e391757bdb8f2d15bdc010227d522bddac3936 /source/slang/source-loc.cpp
parent0a3ef7b4ae02983ea3f986ba8211e7c6af9d254b (diff)
Feature/file unique identity (#789)
* * Fix memory bug around expanding va_args - needed buffer to have space for terminating 0 * Fix problem with FileWriter defaults being globals, as memory they allocate, will only be freed after return from main - work around by making StdWriters RefObject derived, and kept in scope such the writers are destroyed before checks for leaks is found * Added SimplifyPathAndHash mode for CacheFileSystem - will simplify the path and see if simplified path is in cache before reading file (limiting amout of underlying file requests) * * Added calcReplaceChar * Renamed DefaultFileSystem to OSFileSystem * Made OSFileSystem convert windows \ to / on linux * Simplified logic for caching in CacheFileSystem. * Added pragma-once-c to add extra test, but also so there is an 'include' directory in preprocessor tests. * Small fixes in pragma once test. * Simplified cache handling path, so that paths/simplified paths area always added. * Improve naming of methods for different caches. * Removed references to 'canonicalPath' and made 'uniqueIdentity' * * Re-add support for canonicalPath to ISlangFileSystem -> not for uniqueIdentifier but as a way to display 'canonicalPath' * Added peliminary support for being able to display verbose paths in a diagnostic * Added 'clearCache' support * Added verbose path support to SourceManager (now needs a ISlangFileSystemExt to do this) * Added support for '-verbose-path' option to slangc and slang-test.
Diffstat (limited to 'source/slang/source-loc.cpp')
-rw-r--r--source/slang/source-loc.cpp59
1 files changed, 41 insertions, 18 deletions
diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp
index 78477bb78..6507ea4b7 100644
--- a/source/slang/source-loc.cpp
+++ b/source/slang/source-loc.cpp
@@ -9,11 +9,11 @@ namespace Slang {
/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceView !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
-const String PathInfo::getMostUniquePath() const
+const String PathInfo::getMostUniqueIdentity() const
{
switch (type)
{
- case Type::Normal: return canonicalPath;
+ case Type::Normal: return uniqueIdentity;
case Type::FoundPath: return foundPath;
default: return "";
}
@@ -89,7 +89,7 @@ void SourceView::addLineDirective(SourceLoc directiveLoc, StringSlicePool::Handl
void SourceView::addLineDirective(SourceLoc directiveLoc, const String& path, int line)
{
- StringSlicePool::Handle pathHandle = m_sourceManager->getStringSlicePool().add(path.getUnownedSlice());
+ StringSlicePool::Handle pathHandle = getSourceManager()->getStringSlicePool().add(path.getUnownedSlice());
return addLineDirective(directiveLoc, pathHandle, line);
}
@@ -163,8 +163,7 @@ PathInfo SourceView::_getPathInfo(StringSlicePool::Handle pathHandle) const
}
else
{
- // We don't have a full normal path (including 'canonical') so just go with FoundPath
- return PathInfo::makePath(m_sourceManager->getStringSlicePool().getSlice(pathHandle));
+ return PathInfo::makePath(getSourceManager()->getStringSlicePool().getSlice(pathHandle));
}
}
@@ -295,7 +294,8 @@ void SourceFile::setContents(const String& content)
setContents(contentBlob);
}
-SourceFile::SourceFile(const PathInfo& pathInfo, size_t contentSize) :
+SourceFile::SourceFile(SourceManager* sourceManager, const PathInfo& pathInfo, size_t contentSize) :
+ m_sourceManager(sourceManager),
m_pathInfo(pathInfo),
m_contentSize(contentSize)
{
@@ -303,14 +303,37 @@ SourceFile::SourceFile(const PathInfo& pathInfo, size_t contentSize) :
SourceFile::~SourceFile()
{
+}
+
+String SourceFile::calcVerbosePath() const
+{
+ ISlangFileSystemExt* fileSystemExt = getSourceManager()->getFileSystemExt();
+ if (fileSystemExt)
+ {
+ String canonicalPath;
+ ComPtr<ISlangBlob> canonicalPathBlob;
+ if (SLANG_SUCCEEDED(fileSystemExt->getCanonicalPath(m_pathInfo.foundPath.Buffer(), canonicalPathBlob.writeRef())))
+ {
+ canonicalPath = StringUtil::getString(canonicalPathBlob);
+ }
+ if (canonicalPath.Length() > 0)
+ {
+ return canonicalPath;
+ }
+ }
+
+ return m_pathInfo.foundPath;
}
/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceManager !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
void SourceManager::initialize(
- SourceManager* p)
+ SourceManager* p,
+ ISlangFileSystemExt* fileSystemExt)
{
+ m_fileSystemExt = fileSystemExt;
+
m_parent = p;
if( p )
@@ -374,14 +397,14 @@ SourceRange SourceManager::allocateSourceRange(UInt size)
SourceFile* SourceManager::createSourceFileWithSize(const PathInfo& pathInfo, size_t contentSize)
{
- SourceFile* sourceFile = new SourceFile(pathInfo, contentSize);
+ SourceFile* sourceFile = new SourceFile(this, pathInfo, contentSize);
m_sourceFiles.Add(sourceFile);
return sourceFile;
}
SourceFile* SourceManager::createSourceFileWithString(const PathInfo& pathInfo, const String& contents)
{
- SourceFile* sourceFile = new SourceFile(pathInfo, contents.Length());
+ SourceFile* sourceFile = new SourceFile(this, pathInfo, contents.Length());
m_sourceFiles.Add(sourceFile);
sourceFile->setContents(contents);
return sourceFile;
@@ -389,7 +412,7 @@ SourceFile* SourceManager::createSourceFileWithString(const PathInfo& pathInfo,
SourceFile* SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob)
{
- SourceFile* sourceFile = new SourceFile(pathInfo, blob->getBufferSize());
+ SourceFile* sourceFile = new SourceFile(this, pathInfo, blob->getBufferSize());
m_sourceFiles.Add(sourceFile);
sourceFile->setContents(blob);
return sourceFile;
@@ -398,7 +421,7 @@ SourceFile* SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, IS
SourceView* SourceManager::createSourceView(SourceFile* sourceFile)
{
SourceRange range = allocateSourceRange(sourceFile->getContentSize());
- SourceView* sourceView = new SourceView(this, sourceFile, range);
+ SourceView* sourceView = new SourceView(sourceFile, range);
m_sourceViews.Add(sourceView);
return sourceView;
@@ -479,18 +502,18 @@ SourceView* SourceManager::findSourceViewRecursively(SourceLoc loc) const
return nullptr;
}
-SourceFile* SourceManager::findSourceFile(const String& canonicalPath) const
+SourceFile* SourceManager::findSourceFile(const String& uniqueIdentity) const
{
- SourceFile*const* filePtr = m_sourceFileMap.TryGetValue(canonicalPath);
+ SourceFile*const* filePtr = m_sourceFileMap.TryGetValue(uniqueIdentity);
return (filePtr) ? *filePtr : nullptr;
}
-SourceFile* SourceManager::findSourceFileRecursively(const String& canonicalPath) const
+SourceFile* SourceManager::findSourceFileRecursively(const String& uniqueIdentity) const
{
const SourceManager* manager = this;
do
{
- SourceFile* sourceFile = manager->findSourceFile(canonicalPath);
+ SourceFile* sourceFile = manager->findSourceFile(uniqueIdentity);
if (sourceFile)
{
return sourceFile;
@@ -500,10 +523,10 @@ SourceFile* SourceManager::findSourceFileRecursively(const String& canonicalPath
return nullptr;
}
-void SourceManager::addSourceFile(const String& canonicalPath, SourceFile* sourceFile)
+void SourceManager::addSourceFile(const String& uniqueIdentity, SourceFile* sourceFile)
{
- SLANG_ASSERT(!findSourceFileRecursively(canonicalPath));
- m_sourceFileMap.Add(canonicalPath, sourceFile);
+ SLANG_ASSERT(!findSourceFileRecursively(uniqueIdentity));
+ m_sourceFileMap.Add(uniqueIdentity, sourceFile);
}
HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc loc, SourceLocType type)