summaryrefslogtreecommitdiffstats
path: root/source/slang/source-loc.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-01-10 16:01:05 -0500
committerGitHub <noreply@github.com>2019-01-10 16:01:05 -0500
commitdbf5f413cd7a7b0448312a6f198b2a544087ac58 (patch)
treef9dce7776ed118f5b97e2446dccbb2631edec3d8 /source/slang/source-loc.cpp
parenteb331446e3bee812d1df19cf59eb2d23d287ac74 (diff)
Improvements around review of debug serialization info (#769)
* * Make SourceView and SourceFile no longer derive from RefObject * Both have life time now managed by SourceManager * Tidied up a little around the serialization test code - just create the IRModule once * Simplified code around deleting SourceView/File. * Looked into generateIRForTranslationUnit - seems reasonable to just call it once, because it has side effects.
Diffstat (limited to 'source/slang/source-loc.cpp')
-rw-r--r--source/slang/source-loc.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp
index c567dbf22..78477bb78 100644
--- a/source/slang/source-loc.cpp
+++ b/source/slang/source-loc.cpp
@@ -332,6 +332,19 @@ void SourceManager::initialize(
m_nextLoc = m_startLoc;
}
+SourceManager::~SourceManager()
+{
+ for (auto item : m_sourceViews)
+ {
+ delete item;
+ }
+
+ for (auto item : m_sourceFiles)
+ {
+ delete item;
+ }
+}
+
UnownedStringSlice SourceManager::allocateStringSlice(const UnownedStringSlice& slice)
{
const UInt numChars = slice.size();
@@ -359,22 +372,25 @@ SourceRange SourceManager::allocateSourceRange(UInt size)
return SourceRange(beginLoc, endLoc);
}
-RefPtr<SourceFile> SourceManager::createSourceFileWithSize(const PathInfo& pathInfo, size_t contentSize)
+SourceFile* SourceManager::createSourceFileWithSize(const PathInfo& pathInfo, size_t contentSize)
{
SourceFile* sourceFile = new SourceFile(pathInfo, contentSize);
+ m_sourceFiles.Add(sourceFile);
return sourceFile;
}
-RefPtr<SourceFile> SourceManager::createSourceFileWithString(const PathInfo& pathInfo, const String& contents)
+SourceFile* SourceManager::createSourceFileWithString(const PathInfo& pathInfo, const String& contents)
{
SourceFile* sourceFile = new SourceFile(pathInfo, contents.Length());
+ m_sourceFiles.Add(sourceFile);
sourceFile->setContents(contents);
return sourceFile;
}
-RefPtr<SourceFile> SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob)
+SourceFile* SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob)
{
- RefPtr<SourceFile> sourceFile(new SourceFile(pathInfo, blob->getBufferSize()));
+ SourceFile* sourceFile = new SourceFile(pathInfo, blob->getBufferSize());
+ m_sourceFiles.Add(sourceFile);
sourceFile->setContents(blob);
return sourceFile;
}
@@ -465,8 +481,8 @@ SourceView* SourceManager::findSourceViewRecursively(SourceLoc loc) const
SourceFile* SourceManager::findSourceFile(const String& canonicalPath) const
{
- RefPtr<SourceFile>* filePtr = m_sourceFiles.TryGetValue(canonicalPath);
- return (filePtr) ? filePtr->Ptr() : nullptr;
+ SourceFile*const* filePtr = m_sourceFileMap.TryGetValue(canonicalPath);
+ return (filePtr) ? *filePtr : nullptr;
}
SourceFile* SourceManager::findSourceFileRecursively(const String& canonicalPath) const
@@ -487,7 +503,7 @@ SourceFile* SourceManager::findSourceFileRecursively(const String& canonicalPath
void SourceManager::addSourceFile(const String& canonicalPath, SourceFile* sourceFile)
{
SLANG_ASSERT(!findSourceFileRecursively(canonicalPath));
- m_sourceFiles.Add(canonicalPath, sourceFile);
+ m_sourceFileMap.Add(canonicalPath, sourceFile);
}
HumaneSourceLoc SourceManager::getHumaneLoc(SourceLoc loc, SourceLocType type)