glslang front-end: track column numbers (they don't go anywhere yet, just get tracked). Andrew Woloszyn <awoloszyn@google.com>.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31506 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2015-06-16 19:49:22 +00:00
parent edadf45605
commit 47632b7aaf
6 changed files with 32 additions and 10 deletions

View File

@ -177,8 +177,10 @@ inline const TString String(const int i, const int base = 10)
} }
struct TSourceLoc { struct TSourceLoc {
void init() { string = 0; line = 0; column = 0; }
int string; int string;
int line; int line;
int column;
}; };
typedef TMap<TString, TString> TPragmaTable; typedef TMap<TString, TString> TPragmaTable;

View File

@ -400,7 +400,7 @@ class TIntermNode {
public: public:
POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator()) POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
TIntermNode() { loc.line = 0; loc.string = 0; } TIntermNode() { loc.init(); }
virtual glslang::TSourceLoc getLoc() const { return loc; } virtual glslang::TSourceLoc getLoc() const { return loc; }
virtual void setLoc(glslang::TSourceLoc l) { loc = l; } virtual void setLoc(glslang::TSourceLoc l) { loc = l; }
virtual void traverse(glslang::TIntermTraverser*) = 0; virtual void traverse(glslang::TIntermTraverser*) = 0;

View File

@ -2819,7 +2819,8 @@ void TParseContext::redeclareBuiltinBlock(TSourceLoc loc, TTypeList& newTypeList
// look for match // look for match
bool found = false; bool found = false;
TTypeList::const_iterator newMember; TTypeList::const_iterator newMember;
TSourceLoc memberLoc = {}; TSourceLoc memberLoc;
memberLoc.init();
for (newMember = newTypeList.begin(); newMember != newTypeList.end(); ++newMember) { for (newMember = newTypeList.begin(); newMember != newTypeList.end(); ++newMember) {
if (member->type->getFieldName() == newMember->type->getFieldName()) { if (member->type->getFieldName() == newMember->type->getFieldName()) {
found = true; found = true;

View File

@ -52,7 +52,9 @@ public:
loc = new TSourceLoc[numSources]; loc = new TSourceLoc[numSources];
loc[currentSource].string = -stringBias; loc[currentSource].string = -stringBias;
loc[currentSource].line = 1; loc[currentSource].line = 1;
loc[currentSource].column = 0;
} }
virtual ~TInputScanner() virtual ~TInputScanner()
{ {
delete [] loc; delete [] loc;
@ -68,8 +70,11 @@ public:
return -1; return -1;
int ret = sources[currentSource][currentChar]; int ret = sources[currentSource][currentChar];
if (ret == '\n') ++loc[currentSource].column;
if (ret == '\n') {
++loc[currentSource].line; ++loc[currentSource].line;
loc[currentSource].column = 0;
}
advance(); advance();
return ret; return ret;
@ -87,9 +92,23 @@ public:
// go back one character // go back one character
void unget() void unget()
{ {
if (currentChar > 0) if (currentChar > 0) {
--currentChar; --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 { do {
--currentSource; --currentSource;
} while (currentSource > 0 && lengths[currentSource] == 0); } while (currentSource > 0 && lengths[currentSource] == 0);
@ -125,12 +144,14 @@ protected:
if (currentSource < numSources) { if (currentSource < numSources) {
loc[currentSource].string = loc[currentSource - 1].string + 1; loc[currentSource].string = loc[currentSource - 1].string + 1;
loc[currentSource].line = 1; loc[currentSource].line = 1;
loc[currentSource].column = 0;
} }
while (currentSource < numSources && lengths[currentSource] == 0) { while (currentSource < numSources && lengths[currentSource] == 0) {
++currentSource; ++currentSource;
if (currentSource < numSources) { if (currentSource < numSources) {
loc[currentSource].string = loc[currentSource - 1].string + 1; loc[currentSource].string = loc[currentSource - 1].string + 1;
loc[currentSource].line = 1; loc[currentSource].line = 1;
loc[currentSource].column = 0;
} }
} }
currentChar = 0; currentChar = 0;

View File

@ -560,8 +560,7 @@ bool CompileDeferred(
parseContext.addError(); parseContext.addError();
if (warnVersionNotFirst) { if (warnVersionNotFirst) {
TSourceLoc loc; TSourceLoc loc;
loc.line = 1; loc.init();
loc.string = 0;
parseContext.warn(loc, "Illegal to have non-comment, non-whitespace tokens before #version", "#version", ""); parseContext.warn(loc, "Illegal to have non-comment, non-whitespace tokens before #version", "#version", "");
} }

View File

@ -87,9 +87,8 @@ namespace glslang {
class TPpToken { class TPpToken {
public: public:
TPpToken() : token(0), ival(0), space(false), dval(0.0), atom(0) TPpToken() : token(0), ival(0), space(false), dval(0.0), atom(0)
{ {
loc.line = 0; loc.init();
loc.string = 0;
name[0] = 0; name[0] = 0;
} }