From 47632b7aaf75fc72bb8b080a1c7db1e2ba9c33ff Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Tue, 16 Jun 2015 19:49:22 +0000 Subject: [PATCH] glslang front-end: track column numbers (they don't go anywhere yet, just get tracked). Andrew Woloszyn . git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31506 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- glslang/Include/Common.h | 2 ++ glslang/Include/intermediate.h | 2 +- glslang/MachineIndependent/ParseHelper.cpp | 3 ++- glslang/MachineIndependent/Scan.h | 27 ++++++++++++++++--- glslang/MachineIndependent/ShaderLang.cpp | 3 +-- .../preprocessor/PpContext.h | 5 ++-- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/glslang/Include/Common.h b/glslang/Include/Common.h index 0295c102..0940f30a 100644 --- a/glslang/Include/Common.h +++ b/glslang/Include/Common.h @@ -177,8 +177,10 @@ inline const TString String(const int i, const int base = 10) } struct TSourceLoc { + void init() { string = 0; line = 0; column = 0; } int string; int line; + int column; }; typedef TMap TPragmaTable; diff --git a/glslang/Include/intermediate.h b/glslang/Include/intermediate.h index b999dd90..cf24e014 100644 --- a/glslang/Include/intermediate.h +++ b/glslang/Include/intermediate.h @@ -400,7 +400,7 @@ class TIntermNode { public: POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator()) - TIntermNode() { loc.line = 0; loc.string = 0; } + TIntermNode() { loc.init(); } virtual glslang::TSourceLoc getLoc() const { return loc; } virtual void setLoc(glslang::TSourceLoc l) { loc = l; } virtual void traverse(glslang::TIntermTraverser*) = 0; diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index b2abec69..6d2ec6bc 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -2819,7 +2819,8 @@ void TParseContext::redeclareBuiltinBlock(TSourceLoc loc, TTypeList& newTypeList // look for match bool found = false; TTypeList::const_iterator newMember; - TSourceLoc memberLoc = {}; + TSourceLoc memberLoc; + memberLoc.init(); for (newMember = newTypeList.begin(); newMember != newTypeList.end(); ++newMember) { if (member->type->getFieldName() == newMember->type->getFieldName()) { found = true; diff --git a/glslang/MachineIndependent/Scan.h b/glslang/MachineIndependent/Scan.h index 67e6193e..91aa604b 100644 --- a/glslang/MachineIndependent/Scan.h +++ b/glslang/MachineIndependent/Scan.h @@ -52,7 +52,9 @@ public: loc = new TSourceLoc[numSources]; loc[currentSource].string = -stringBias; loc[currentSource].line = 1; + loc[currentSource].column = 0; } + virtual ~TInputScanner() { delete [] loc; @@ -68,8 +70,11 @@ public: return -1; int ret = sources[currentSource][currentChar]; - if (ret == '\n') + ++loc[currentSource].column; + if (ret == '\n') { ++loc[currentSource].line; + loc[currentSource].column = 0; + } advance(); return ret; @@ -87,9 +92,23 @@ public: // go back one character void unget() { - if (currentChar > 0) + if (currentChar > 0) { --currentChar; - else { + --loc[currentSource].column; + if (loc[currentSource].column < 0) { + // We've moved back past a new line. Find the + // previous newline (or start of the file) to compute + // the column count on the now current line. + size_t ch = currentChar; + while(ch > 0) { + if (sources[currentSource][ch] == '\n') { + break; + } + --ch; + } + loc[currentSource].column = currentChar - ch; + } + } else { do { --currentSource; } while (currentSource > 0 && lengths[currentSource] == 0); @@ -125,12 +144,14 @@ protected: if (currentSource < numSources) { loc[currentSource].string = loc[currentSource - 1].string + 1; loc[currentSource].line = 1; + loc[currentSource].column = 0; } while (currentSource < numSources && lengths[currentSource] == 0) { ++currentSource; if (currentSource < numSources) { loc[currentSource].string = loc[currentSource - 1].string + 1; loc[currentSource].line = 1; + loc[currentSource].column = 0; } } currentChar = 0; diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index 075ee8d0..59b692cd 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -560,8 +560,7 @@ bool CompileDeferred( parseContext.addError(); if (warnVersionNotFirst) { TSourceLoc loc; - loc.line = 1; - loc.string = 0; + loc.init(); parseContext.warn(loc, "Illegal to have non-comment, non-whitespace tokens before #version", "#version", ""); } diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 97081a34..2fc5369d 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -87,9 +87,8 @@ namespace glslang { class TPpToken { public: TPpToken() : token(0), ival(0), space(false), dval(0.0), atom(0) - { - loc.line = 0; - loc.string = 0; + { + loc.init(); name[0] = 0; }