Extend the syntax of #line and __FILE__ to support filename strings.

According to the GLSL spec, the second parameter to #line should be
an integer source string number and __FILE__ will be substituted
with the integer source string number currently processed. This
patch extends the syntax of #line and __FILE__. Now #line accepts
as the second parameter a filename string quoted by double quotation
marks. And if such a #line is set, __FILE__ will be substituted with
the currently set filename string. The implementation is done via
introducing a new extension GL_GOOGLE_cpp_style_line_directive using
the extension framework.

The purpose is to support cpp-style #line directives, which is
required by #include.
This commit is contained in:
Lei Zhang 2015-06-25 17:53:54 -04:00
parent c777fc2c4c
commit 5011fbebc3
16 changed files with 176 additions and 19 deletions

View file

@ -57,6 +57,9 @@ public:
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f)
{
loc = new TSourceLoc[numSources];
for (int i = 0; i < numSources; ++i) {
loc[i].init();
}
loc[currentSource].string = -stringBias;
loc[currentSource].line = 1;
loc[currentSource].column = 0;
@ -140,7 +143,12 @@ public:
// for #line override
void setLine(int newLine) { loc[getLastValidSourceIndex()].line = newLine; }
void setString(int newString) { loc[getLastValidSourceIndex()].string = newString; }
void setFile(const char* filename) { loc[getLastValidSourceIndex()].name = filename; }
void setString(int newString)
{
loc[getLastValidSourceIndex()].string = newString;
loc[getLastValidSourceIndex()].name = nullptr;
}
const TSourceLoc& getSourceLoc() const { return loc[std::max(0, std::min(currentSource, numSources - finale - 1))]; }
// Returns the index (starting from 0) of the most recent valid source string we are reading from.