summaryrefslogtreecommitdiffstats
path: root/source/slang/source-loc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/source-loc.cpp')
-rw-r--r--source/slang/source-loc.cpp74
1 files changed, 57 insertions, 17 deletions
diff --git a/source/slang/source-loc.cpp b/source/slang/source-loc.cpp
index 6d6d63ae1..c567dbf22 100644
--- a/source/slang/source-loc.cpp
+++ b/source/slang/source-loc.cpp
@@ -159,7 +159,7 @@ PathInfo SourceView::_getPathInfo(StringSlicePool::Handle pathHandle) const
// If there is no override path, then just the source files path
if (pathHandle == StringSlicePool::Handle(0))
{
- return m_sourceFile->pathInfo;
+ return m_sourceFile->getPathInfo();
}
else
{
@@ -172,7 +172,7 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type)
{
if (type == SourceLocType::Actual)
{
- return m_sourceFile->pathInfo;
+ return m_sourceFile->getPathInfo();
}
const int entryIndex = findEntryIndex(loc);
@@ -181,6 +181,12 @@ PathInfo SourceView::getPathInfo(SourceLoc loc, SourceLocType type)
/* !!!!!!!!!!!!!!!!!!!!!!! SourceFile !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+void SourceFile::setLineBreakOffsets(const uint32_t* offsets, UInt numOffsets)
+{
+ m_lineBreakOffsets.Clear();
+ m_lineBreakOffsets.AddRange(offsets, numOffsets);
+}
+
const List<uint32_t>& SourceFile::getLineBreakOffsets()
{
// We now have a raw input file that we can search for line breaks.
@@ -188,6 +194,8 @@ const List<uint32_t>& SourceFile::getLineBreakOffsets()
// cache an array of line break locations in the file.
if (m_lineBreakOffsets.Count() == 0)
{
+ UnownedStringSlice content = getContent();
+
char const* begin = content.begin();
char const* end = content.end();
@@ -232,7 +240,7 @@ const List<uint32_t>& SourceFile::getLineBreakOffsets()
int SourceFile::calcLineIndexFromOffset(int offset)
{
- SLANG_ASSERT(UInt(offset) <= content.size());
+ SLANG_ASSERT(UInt(offset) <= getContentSize());
// Make sure we have the line break offsets
const auto& lineBreakOffsets = getLineBreakOffsets();
@@ -266,6 +274,38 @@ int SourceFile::calcColumnIndex(int lineIndex, int offset)
return offset - lineBreakOffsets[lineIndex];
}
+/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceFile !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void SourceFile::setContents(ISlangBlob* blob)
+{
+ const UInt contentSize = blob->getBufferSize();
+
+ SLANG_ASSERT(contentSize == m_contentSize);
+
+ char const* contentBegin = (char const*)blob->getBufferPointer();
+ char const* contentEnd = contentBegin + contentSize;
+
+ m_contentBlob = blob;
+ m_content = UnownedStringSlice(contentBegin, contentEnd);
+}
+
+void SourceFile::setContents(const String& content)
+{
+ ComPtr<ISlangBlob> contentBlob = StringUtil::createStringBlob(content);
+ setContents(contentBlob);
+}
+
+SourceFile::SourceFile(const PathInfo& pathInfo, size_t contentSize) :
+ m_pathInfo(pathInfo),
+ m_contentSize(contentSize)
+{
+}
+
+SourceFile::~SourceFile()
+{
+
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!! SourceManager !!!!!!!!!!!!!!!!!!!!!!!!!!!! */
void SourceManager::initialize(
@@ -319,29 +359,29 @@ SourceRange SourceManager::allocateSourceRange(UInt size)
return SourceRange(beginLoc, endLoc);
}
-SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, ISlangBlob* contentBlob)
+RefPtr<SourceFile> SourceManager::createSourceFileWithSize(const PathInfo& pathInfo, size_t contentSize)
{
- char const* contentBegin = (char const*) contentBlob->getBufferPointer();
- UInt contentSize = contentBlob->getBufferSize();
- char const* contentEnd = contentBegin + contentSize;
+ SourceFile* sourceFile = new SourceFile(pathInfo, contentSize);
+ return sourceFile;
+}
- SourceFile* sourceFile = new SourceFile();
- sourceFile->pathInfo = pathInfo;
- sourceFile->contentBlob = contentBlob;
- sourceFile->content = UnownedStringSlice(contentBegin, contentEnd);
-
+RefPtr<SourceFile> SourceManager::createSourceFileWithString(const PathInfo& pathInfo, const String& contents)
+{
+ SourceFile* sourceFile = new SourceFile(pathInfo, contents.Length());
+ sourceFile->setContents(contents);
return sourceFile;
}
-
-SourceFile* SourceManager::createSourceFile(const PathInfo& pathInfo, const String& content)
+
+RefPtr<SourceFile> SourceManager::createSourceFileWithBlob(const PathInfo& pathInfo, ISlangBlob* blob)
{
- ComPtr<ISlangBlob> contentBlob = StringUtil::createStringBlob(content);
- return createSourceFile(pathInfo, contentBlob);
+ RefPtr<SourceFile> sourceFile(new SourceFile(pathInfo, blob->getBufferSize()));
+ sourceFile->setContents(blob);
+ return sourceFile;
}
SourceView* SourceManager::createSourceView(SourceFile* sourceFile)
{
- SourceRange range = allocateSourceRange(sourceFile->content.size());
+ SourceRange range = allocateSourceRange(sourceFile->getContentSize());
SourceView* sourceView = new SourceView(this, sourceFile, range);
m_sourceViews.Add(sourceView);