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