Improve preprocessor by using GLSL scanner, allowing read-only strings to be compiled, unifying of line # tracking, and correct detection that ES #version appeared after a comment.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23721 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-10-28 18:12:06 +00:00
parent 9497485e14
commit ea869fb403
20 changed files with 285 additions and 300 deletions

View file

@ -84,7 +84,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace glslang {
TPpContext::TPpContext(TParseContext& pc) :
preamble(0), strings(0), notAVersionToken(false), parseContext(pc)
preamble(0), strings(0), parseContext(pc)
{
InitAtomTable();
InitScanner(this);
@ -101,28 +101,17 @@ TPpContext::~TPpContext()
delete [] preamble;
}
void TPpContext::setPreamble(const char* p, size_t l)
void TPpContext::setInput(TInputScanner& input, bool versionWillBeError)
{
if (p && l > 0) {
// preAmble could be a hard-coded string; make writable copy
// TODO: efficiency PP: make it not need writable strings
preambleLength = l;
preamble = new char[preambleLength + 1];
memcpy(preamble, p, preambleLength + 1); // TODO: PP: assuming nul-terminated strings
ScanFromString(preamble);
currentString = -1;
}
}
void TPpContext::setShaderStrings(char* s[], size_t l[], int n)
{
strings = s;
lengths = l;
numStrings = n;
if (! preamble) {
ScanFromString(strings[0]);
currentString = 0;
}
StringInputSrc *in = (StringInputSrc *)malloc(sizeof(StringInputSrc));
memset(in, 0, sizeof(StringInputSrc));
in->input = &input;
in->base.scan = byte_scan;
in->base.getch = (int (*)(TPpContext*, InputSrc *, TPpToken *))str_getch;
in->base.ungetch = (void (*)(TPpContext*, InputSrc *, int, TPpToken *))str_ungetch;
in->base.prev = currentInput;
currentInput = &in->base;
errorOnVersion = versionWillBeError;
}
} // end namespace glslang