1) Allow '\' before a non-newline as a token in the preprocessor, and 2) localize line-continuation to just the pp scanner.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24530 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
@@ -190,12 +190,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
||||
TSourceLoc defineLoc = ppToken->loc; // because ppToken is going to go to the next line before we report errors
|
||||
mac.body = new TokenStream;
|
||||
while (token != '\n') {
|
||||
if (token == '\\') {
|
||||
parseContext.lineContinuationCheck(ppToken->loc, false);
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
if (token == '\n' || token == '\r')
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
}
|
||||
RecordToken(mac.body, token, ppToken);
|
||||
token = currentInput->scan(this, currentInput, ppToken);
|
||||
if (token != '\n' && ppToken->space)
|
||||
|
||||
@@ -281,20 +281,29 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
||||
case 'k': case 'l': case 'm': case 'n': case 'o':
|
||||
case 'p': case 'q': case 'r': case 's': case 't':
|
||||
case 'u': case 'v': case 'w': case 'x': case 'y':
|
||||
case 'z': case '\\' :
|
||||
case 'z': case '\\':
|
||||
do {
|
||||
if (ch == '\\') {
|
||||
// escaped character
|
||||
pp->parseContext.lineContinuationCheck(ppToken->loc, false);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
if (ch == '\r' || ch == '\n') {
|
||||
pp->parseContext.lineContinuationCheck(ppToken->loc, false);
|
||||
int nextch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
if (ch == '\r' && nextch == '\n')
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
else
|
||||
ch = nextch;
|
||||
} else
|
||||
pp->parseContext.error(ppToken->loc, "can only escape newlines", "\\", "");
|
||||
} else {
|
||||
// Not an escaped newline.
|
||||
// Put back whatever it was
|
||||
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
|
||||
// If not in the middle of an identifier, the \ is our token
|
||||
if (len == 0)
|
||||
return '\\';
|
||||
// Otherwise, put back the \ character, leave it for the next call
|
||||
ch = '\\'; // for the upcoming unget(...ch...);
|
||||
break;
|
||||
}
|
||||
} else if (len < TPpToken::maxTokenLength) {
|
||||
tokenText[len++] = ch;
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
@@ -303,7 +312,7 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
||||
pp->parseContext.error(ppToken->loc, "name too long", "", "");
|
||||
AlreadyComplained = 1;
|
||||
}
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||
}
|
||||
} while ((ch >= 'a' && ch <= 'z') ||
|
||||
(ch >= 'A' && ch <= 'Z') ||
|
||||
|
||||
Reference in New Issue
Block a user