summaryrefslogtreecommitdiffstats
path: root/source/slang/source-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-10-16 18:49:11 -0400
committerGitHub <noreply@github.com>2018-10-16 18:49:11 -0400
commit3e74d39f24fdfaa547ce900be177863e2bfe2dea (patch)
tree9a5143e6de4caa27b23fc870003011e96129905f /source/slang/source-loc.cpp
parent204fb3c75b520a2cbb1c25f995a8c424ec2753f3 (diff)
Feature/include refactor (#675)
* Refactor of path handling. * Added PathInfo * Changed ISlangFileSystem - such that has separate concepts of reading a file, getting a relative path and getting a canonical path * Added support for getting a canonical path for windows/linux * Made maps/testing around canonicalPaths * User output remains around 'foundPath' - which is the same as before * Small improvements around PathInfo * Added a type and make constructors to make clear the different 'path' uses * Fixed bug in findViewRecursively * Checking and reporting for ignored #pragma once. * Removed SLANG_PATH_TYPE_NONE as doesn't serve any useful purpose. * Improve comments in slang.h aroung ISlangFileSystem * Remove the need for <windows.h> in slang-io.cpp * Ran premake5. * Improvements and fixes around PathInfo. * Fix typo on linix GetCanonical * Make the ISlangFileSystem the same as before, and ISlangFileSystem contain the new methods. Internally it always uses the ISlangFileSystemExt, and will wrap a ISlangFileSystem with WrapFileSystem, if it is determined (via queryInterface) that it doesn't implement the full interface.
Diffstat (limited to 'source/slang/source-loc.cpp')
-rw-r--r--source/slang/source-loc.cpp95
1 files changed, 54 insertions, 41 deletions
diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp
index d6b75b909..1c3b8c70a 100644
--- a/source/slang/source-loc.cpp
+++ b/source/slang/source-loc.cpp
@@ -5,7 +5,19 @@
namespace Slang {
-/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceUnit !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceView !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+const String PathInfo::getMostUniquePath() const
+{
+ switch (type)
+ {
+ case Type::Normal: return canonicalPath;
+ case Type::FoundPath: return foundPath;
+ default: return "";
+ }
+}
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceView !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
int SourceView::findEntryIndex(SourceLoc sourceLoc) const
{
@@ -136,38 +148,33 @@ HumaneSourceLoc SourceView::getHumaneLoc(SourceLoc loc, SourceLocType type)
pathHandle = entry.m_pathHandle;
}
+ humaneLoc.pathInfo = _getPathInfo(pathHandle);
+ return humaneLoc;
+}
+
+PathInfo SourceView::_getPathInfo(StringSlicePool::Handle pathHandle) const
+{
// If there is no override path, then just the source files path
if (pathHandle == StringSlicePool::Handle(0))
{
- humaneLoc.path = m_sourceFile->path;
+ return m_sourceFile->pathInfo;
}
else
{
- humaneLoc.path = m_sourceManager->getStringSlicePool().getSlice(pathHandle);
+ // We don't have a full normal path (including 'canonical') so just go with FoundPath
+ return PathInfo::makePath(m_sourceManager->getStringSlicePool().getSlice(pathHandle));
}
-
- return humaneLoc;
}
-String SourceView::getPath(SourceLoc loc, SourceLocType type)
+PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type)
{
if (type == SourceLocType::Actual)
{
- return m_sourceFile->path;
+ return m_sourceFile->pathInfo;
}
const int entryIndex = findEntryIndex(loc);
- const StringSlicePool::Handle pathHandle = (entryIndex >= 0) ? m_entries[entryIndex].m_pathHandle : StringSlicePool::Handle(0);
-
- // If there is no override path, then just the source files path
- if (pathHandle == StringSlicePool::Handle(0))
- {
- return m_sourceFile->path;
- }
- else
- {
- return m_sourceManager->getStringSlicePool().getSlice(pathHandle);
- }
+ return _getPathInfo((entryIndex >= 0) ? m_entries[entryIndex].m_pathHandle : StringSlicePool::Handle(0));
}
/* !!!!!!!!!!!!!!!!!!!!!!! SourceFile !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
@@ -300,28 +307,24 @@ SourceRange SourceManager::allocateSourceRange(UInt size)
return SourceRange(beginLoc, endLoc);
}
-SourceFile* SourceManager::createSourceFile(
- String const& path,
- ISlangBlob* contentBlob)
+SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, ISlangBlob* contentBlob)
{
char const* contentBegin = (char const*) contentBlob->getBufferPointer();
UInt contentSize = contentBlob->getBufferSize();
char const* contentEnd = contentBegin + contentSize;
SourceFile* sourceFile = new SourceFile();
- sourceFile->path = path;
+ sourceFile->pathInfo = pathInfo;
sourceFile->contentBlob = contentBlob;
sourceFile->content = UnownedStringSlice(contentBegin, contentEnd);
return sourceFile;
}
-
-SourceFile* SourceManager::createSourceFile(
- String const& path,
- String const& content)
+
+SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, const String& content)
{
ComPtr<ISlangBlob> contentBlob = createStringBlob(content);
- return createSourceFile(path, contentBlob);
+ return createSourceFile(pathInfo, contentBlob);
}
SourceView* SourceManager::createSourceView(SourceFile* sourceFile)
@@ -394,13 +397,12 @@ SourceView* SourceManager::findSourceViewRecursively(SourceLoc loc) const
const SourceManager* manager = this;
do
{
- SourceView* sourceView = findSourceView(loc);
+ SourceView* sourceView = manager->findSourceView(loc);
// If we found a hit we are done
if (sourceView)
{
return sourceView;
}
-
// Try the parent
manager = manager->m_parent;
}
@@ -409,20 +411,31 @@ SourceView* SourceManager::findSourceViewRecursively(SourceLoc loc) const
return nullptr;
}
-SourceFile* SourceManager::findSourceFile(const String& path)
+SourceFile* SourceManager::findSourceFile(const String& canonicalPath) const
+{
+ RefPtr<SourceFile>* filePtr = m_sourceFiles.TryGetValue(canonicalPath);
+ return (filePtr) ? filePtr->Ptr() : nullptr;
+}
+
+SourceFile* SourceManager::findSourceFileRecursively(const String& canonicalPath) const
{
- RefPtr<SourceFile>* filePtr = m_sourceFiles.TryGetValue(path);
- if (filePtr)
+ const SourceManager* manager = this;
+ do
{
- return filePtr->Ptr();
- }
- return m_parent ? m_parent->findSourceFile(path) : nullptr;
+ SourceFile* sourceFile = manager->findSourceFile(canonicalPath);
+ if (sourceFile)
+ {
+ return sourceFile;
+ }
+ manager = manager->m_parent;
+ } while (manager);
+ return nullptr;
}
-void SourceManager::addSourceFile(const String& path, SourceFile* sourceFile)
+void SourceManager::addSourceFile(const String& canonicalPath, SourceFile* sourceFile)
{
- SLANG_ASSERT(!findSourceFile(path));
- m_sourceFiles.Add(path, sourceFile);
+ SLANG_ASSERT(!findSourceFileRecursively(canonicalPath));
+ m_sourceFiles.Add(canonicalPath, sourceFile);
}
HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc loc, SourceLocType type)
@@ -438,16 +451,16 @@ HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc loc, SourceLocType type)
}
}
-String SourceManager::getPath(SourceLoc loc, SourceLocType type)
+PathInfo SourceManager::getPathInfo(SourceLoc loc, SourceLocType type)
{
SourceView* sourceView = findSourceViewRecursively(loc);
if (sourceView)
{
- return sourceView->getPath(loc, type);
+ return sourceView->getPathInfo(loc, type);
}
else
{
- return String("unknown");
+ return PathInfo::makeUnknown();
}
}