Shader: Fill SourceLocation info to AST when parsing

This commit is contained in:
SirLynix
2022-03-28 18:24:51 +02:00
committed by Jérôme Leclercq
parent 8429411755
commit 78f4751967
10 changed files with 339 additions and 173 deletions

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/ShaderLangSourceLocation.hpp>
#include <cassert>
#include <Nazara/Shader/Debug.hpp>
namespace Nz::ShaderLang
@@ -42,6 +43,40 @@ namespace Nz::ShaderLang
{
}
inline void SourceLocation::ExtendToLeft(const SourceLocation& leftLocation)
{
assert(file == leftLocation.file);
assert(leftLocation.startLine <= endLine);
startLine = leftLocation.startLine;
assert(leftLocation.startLine < endLine || leftLocation.startColumn <= endColumn);
startColumn = leftLocation.startColumn;
}
inline void SourceLocation::ExtendToRight(const SourceLocation& rightLocation)
{
assert(file == rightLocation.file);
assert(rightLocation.endLine >= startLine);
endLine = rightLocation.endLine;
assert(rightLocation.endLine > startLine || rightLocation.endColumn >= startColumn);
endColumn = endColumn;
}
inline SourceLocation SourceLocation::BuildFromTo(const SourceLocation& leftSource, const SourceLocation& rightSource)
{
assert(leftSource.file == rightSource.file);
assert(leftSource.startLine <= rightSource.endLine);
assert(leftSource.startLine < rightSource.endLine || leftSource.startColumn <= rightSource.endColumn);
SourceLocation sourceLoc;
sourceLoc.file = leftSource.file;
sourceLoc.startLine = leftSource.startLine;
sourceLoc.startColumn = leftSource.startColumn;
sourceLoc.endLine = rightSource.endLine;
sourceLoc.endColumn = rightSource.endColumn;
return sourceLoc;
}
inline bool SourceLocation::IsValid() const
{
return startLine != 0 && endLine != 0 && endColumn != 0 && startColumn != 0;