Support line-continuation (backslash before newline) for tokens and one-line comments in the preprocessor.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22168 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
e5f80b8054
commit
d3f85891a7
@ -13,7 +13,7 @@ still in a comment
|
|||||||
|
|
||||||
// a different comment
|
// a different comment
|
||||||
#version 430 core
|
#version 430 core
|
||||||
varying vec4 v;
|
in vec4 v;
|
||||||
void main() {}
|
void main() {}
|
||||||
|
|
||||||
|
|
||||||
|
14
Test/lineContinuation.vert
Normal file
14
Test/lineContinuation.vert
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#version 300 es
|
||||||
|
|
||||||
|
// this file cont\
|
||||||
|
ains no errors
|
||||||
|
|
||||||
|
float f\
|
||||||
|
oo; // same as 'float foo;'
|
||||||
|
|
||||||
|
#define MAIN void main() \
|
||||||
|
{ \
|
||||||
|
gl_Position = vec4(foo); \
|
||||||
|
}
|
||||||
|
|
||||||
|
MAIN
|
@ -42,3 +42,4 @@ tokenLength.vert
|
|||||||
400.frag
|
400.frag
|
||||||
420.vert
|
420.vert
|
||||||
430scope.vert
|
430scope.vert
|
||||||
|
lineContinuation.vert
|
||||||
|
@ -382,7 +382,18 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||||||
case 'u': case 'v': case 'w': case 'x': case 'y':
|
case 'u': case 'v': case 'w': case 'x': case 'y':
|
||||||
case 'z':
|
case 'z':
|
||||||
do {
|
do {
|
||||||
if (len < MAX_SYMBOL_NAME_LEN) {
|
if (ch == '\\') {
|
||||||
|
// escaped character
|
||||||
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch == '\r' || ch == '\n') {
|
||||||
|
int nextch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch == '\r' && nextch == '\n')
|
||||||
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
else
|
||||||
|
ch = nextch;
|
||||||
|
} else
|
||||||
|
ShPpErrorToInfoLog("can only escape newlines");
|
||||||
|
} else if (len < MAX_SYMBOL_NAME_LEN) {
|
||||||
symbol_name[len] = ch;
|
symbol_name[len] = ch;
|
||||||
len++;
|
len++;
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
@ -393,7 +404,8 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||||||
} while ((ch >= 'a' && ch <= 'z') ||
|
} while ((ch >= 'a' && ch <= 'z') ||
|
||||||
(ch >= 'A' && ch <= 'Z') ||
|
(ch >= 'A' && ch <= 'Z') ||
|
||||||
(ch >= '0' && ch <= '9') ||
|
(ch >= '0' && ch <= '9') ||
|
||||||
ch == '_');
|
ch == '_' ||
|
||||||
|
ch == '\\');
|
||||||
if (len > MAX_SYMBOL_NAME_LEN)
|
if (len > MAX_SYMBOL_NAME_LEN)
|
||||||
len = MAX_SYMBOL_NAME_LEN;
|
len = MAX_SYMBOL_NAME_LEN;
|
||||||
symbol_name[len] = '\0';
|
symbol_name[len] = '\0';
|
||||||
@ -664,18 +676,25 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
|||||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||||
return lFloatConst(yylvalpp->symbol_name, 0, '.', yylvalpp);
|
return lFloatConst(yylvalpp->symbol_name, 0, '.', yylvalpp);
|
||||||
} else {
|
} else {
|
||||||
if (ch == '.') {
|
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||||
return -1; // Special EOF hack
|
return '.';
|
||||||
} else {
|
|
||||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
|
||||||
return '.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case '/':
|
case '/':
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
if (ch == '/') {
|
if (ch == '/') {
|
||||||
do {
|
do {
|
||||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch == '\\') {
|
||||||
|
// allow an escaped newline, otherwise escapes in comments are meaningless
|
||||||
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch == '\r' || ch == '\n') {
|
||||||
|
int nextch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
if (ch == '\r' && nextch == '\n')
|
||||||
|
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||||
|
else
|
||||||
|
ch = nextch;
|
||||||
|
}
|
||||||
|
}
|
||||||
} while (ch != '\n' && ch != EOF);
|
} while (ch != '\n' && ch != EOF);
|
||||||
if (ch == EOF)
|
if (ch == EOF)
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user