From dbf5f413cd7a7b0448312a6f198b2a544087ac58 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 10 Jan 2019 16:01:05 -0500 Subject: 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. --- source/slang/source-loc.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'source/slang/source-loc.cpp') 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 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 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 SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob) +SourceFile* SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob) { - RefPtr 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* 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) -- cgit v1.2.3