Preprocessor: Fixed that some comments incorrectly substituted a new line instead of space. Also generally cleaned up the space-related coding.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24387 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
8e789e8d62
commit
e28beee891
@ -70,8 +70,9 @@ ERROR: 12:1234: '#line' : unexpected tokens following directive
|
|||||||
ERROR: 12:20001: '#error' : line should be 20001
|
ERROR: 12:20001: '#error' : line should be 20001
|
||||||
ERROR: 12:20011: '#error' : line should be 20011
|
ERROR: 12:20011: '#error' : line should be 20011
|
||||||
ERROR: 12:20021: '#error' : line should be 20021
|
ERROR: 12:20021: '#error' : line should be 20021
|
||||||
|
ERROR: 12:20046: '#define' : Macro redefined; different substitutions: SPACE_IN_MIDDLE
|
||||||
ERROR: 12:10003: '' : missing #endif
|
ERROR: 12:10003: '' : missing #endif
|
||||||
ERROR: 71 compilation errors. No code generated.
|
ERROR: 72 compilation errors. No code generated.
|
||||||
|
|
||||||
|
|
||||||
ERROR: node is still EOpNull!
|
ERROR: node is still EOpNull!
|
||||||
@ -148,6 +149,19 @@ ERROR: node is still EOpNull!
|
|||||||
0:202 'f' (double)
|
0:202 'f' (double)
|
||||||
0:202 Constant:
|
0:202 Constant:
|
||||||
0:202 0.000800
|
0:202 0.000800
|
||||||
|
12:20032 Function Definition: foo234( (void)
|
||||||
|
12:20032 Function Parameters:
|
||||||
|
12:20034 Sequence
|
||||||
|
12:20034 move second child to first child (4-component vector of float)
|
||||||
|
12:20034 gl_Position: direct index for structure (gl_Position 4-component vector of float)
|
||||||
|
12:20034 '__anon__1' (out block{gl_Position,gl_PointSize,gl_ClipDistance,gl_ClipVertex,gl_FrontColor,gl_BackColor,gl_FrontSecondaryColor,gl_BackSecondaryColor,gl_TexCoord,gl_FogFragCoord})
|
||||||
|
12:20034 Constant:
|
||||||
|
12:20034 0 (const uint)
|
||||||
|
12:20034 Constant:
|
||||||
|
12:20034 6.000000
|
||||||
|
12:20034 6.000000
|
||||||
|
12:20034 6.000000
|
||||||
|
12:20034 6.000000
|
||||||
0:? Linker Objects
|
0:? Linker Objects
|
||||||
0:? 'sum' (float)
|
0:? 'sum' (float)
|
||||||
0:? 'linenumber' (int)
|
0:? 'linenumber' (int)
|
||||||
|
|||||||
@ -263,6 +263,31 @@ double f = f1;
|
|||||||
#line +20020
|
#line +20020
|
||||||
#error line should be 20021
|
#error line should be 20021
|
||||||
|
|
||||||
|
#define VAL1 1.0
|
||||||
|
#define VAL2 2.0
|
||||||
|
|
||||||
|
#define RES2 /* test a multiline
|
||||||
|
comment in a macro definition */ (RES1 * VAL2)
|
||||||
|
#define RES1 (VAL2 / VAL1)
|
||||||
|
#define RES2 /* comment */(RES1 * VAL2)
|
||||||
|
#define /* */SUM_VALUES (RES2 + RES1)
|
||||||
|
|
||||||
|
void foo234()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(SUM_VALUES);
|
||||||
|
}
|
||||||
|
|
||||||
|
// more whitespace recording tests
|
||||||
|
#define SPACE_AT_END(a,b) spaceAtEndIsOkay
|
||||||
|
#define SPACE_AT_END(a,b) spaceAtEndIsOkay // space at end
|
||||||
|
|
||||||
|
#define SPACE_AT_BEGIN(a,b)spaceAtBeginIsOkay
|
||||||
|
#define SPACE_AT_BEGIN(a,b) spaceAtBeginIsOkay
|
||||||
|
|
||||||
|
// space in middle is an error
|
||||||
|
#define SPACE_IN_MIDDLE(a,b) space +in middle
|
||||||
|
#define SPACE_IN_MIDDLE(a,b) space + in middle
|
||||||
|
|
||||||
#line 10000
|
#line 10000
|
||||||
#if 1
|
#if 1
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -9,5 +9,5 @@
|
|||||||
// source have to figure out how to create revision.h just to get a build
|
// source have to figure out how to create revision.h just to get a build
|
||||||
// going. However, if it is not updated, it can be a version behind.
|
// going. However, if it is not updated, it can be a version behind.
|
||||||
|
|
||||||
#define GLSLANG_REVISION "24377"
|
#define GLSLANG_REVISION "24378"
|
||||||
#define GLSLANG_DATE "2013/12/05 13:58:16"
|
#define GLSLANG_DATE "2013/12/05 14:51:40"
|
||||||
|
|||||||
@ -128,24 +128,27 @@ int TPpContext::InitCPP()
|
|||||||
// Handle #define
|
// Handle #define
|
||||||
int TPpContext::CPPdefine(TPpToken* ppToken)
|
int TPpContext::CPPdefine(TPpToken* ppToken)
|
||||||
{
|
{
|
||||||
int token, atom, args[maxMacroArgs], argc;
|
|
||||||
MacroSymbol mac;
|
MacroSymbol mac;
|
||||||
Symbol *symb;
|
Symbol *symb;
|
||||||
token = currentInput->scan(this, currentInput, ppToken);
|
|
||||||
|
// get macro name
|
||||||
|
int token = currentInput->scan(this, currentInput, ppToken);
|
||||||
if (token != CPP_IDENTIFIER) {
|
if (token != CPP_IDENTIFIER) {
|
||||||
parseContext.error(ppToken->loc, "must be followed by macro name", "#define", "");
|
parseContext.error(ppToken->loc, "must be followed by macro name", "#define", "");
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
atom = ppToken->atom;
|
int atom = ppToken->atom;
|
||||||
const char* definedName = GetAtomString(atom);
|
const char* definedName = GetAtomString(atom);
|
||||||
if (ppToken->loc.string >= 0) {
|
if (ppToken->loc.string >= 0) {
|
||||||
// We are in user code; check for reserved name use:
|
// We are in user code; check for reserved name use:
|
||||||
parseContext.reservedPpErrorCheck(ppToken->loc, definedName, "#define");
|
parseContext.reservedPpErrorCheck(ppToken->loc, definedName, "#define");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gather parameters to the macro, between (...)
|
||||||
token = currentInput->scan(this, currentInput, ppToken);
|
token = currentInput->scan(this, currentInput, ppToken);
|
||||||
if (token == '(' && !ppToken->ival) {
|
if (token == '(' && ! ppToken->space) {
|
||||||
// gather arguments
|
int argc = 0;
|
||||||
argc = 0;
|
int args[maxMacroArgs];
|
||||||
do {
|
do {
|
||||||
token = currentInput->scan(this, currentInput, ppToken);
|
token = currentInput->scan(this, currentInput, ppToken);
|
||||||
if (argc == 0 && token == ')')
|
if (argc == 0 && token == ')')
|
||||||
@ -155,7 +158,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
// check for duplication
|
// check for duplication of parameter name
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
for (int a = 0; a < argc; ++a) {
|
for (int a = 0; a < argc; ++a) {
|
||||||
if (args[a] == ppToken->atom) {
|
if (args[a] == ppToken->atom) {
|
||||||
@ -182,6 +185,8 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
memcpy(mac.args, args, argc * sizeof(int));
|
memcpy(mac.args, args, argc * sizeof(int));
|
||||||
token = currentInput->scan(this, currentInput, ppToken);
|
token = currentInput->scan(this, currentInput, ppToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// record the definition of the macro
|
||||||
TSourceLoc defineLoc = ppToken->loc; // because ppToken is going to go to the next line before we report errors
|
TSourceLoc defineLoc = ppToken->loc; // because ppToken is going to go to the next line before we report errors
|
||||||
mac.body = new TokenStream;
|
mac.body = new TokenStream;
|
||||||
while (token != '\n') {
|
while (token != '\n') {
|
||||||
@ -192,14 +197,12 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
token = currentInput->scan(this, currentInput, ppToken);
|
token = currentInput->scan(this, currentInput, ppToken);
|
||||||
}
|
}
|
||||||
RecordToken(mac.body, token, ppToken);
|
RecordToken(mac.body, token, ppToken);
|
||||||
int spaceCandidate = currentInput->getch(this, currentInput, ppToken);
|
|
||||||
if (spaceCandidate == ' ' || spaceCandidate == '\t')
|
|
||||||
RecordToken(mac.body, ' ', 0);
|
|
||||||
else
|
|
||||||
currentInput->ungetch(this, currentInput, spaceCandidate, ppToken);
|
|
||||||
token = currentInput->scan(this, currentInput, ppToken);
|
token = currentInput->scan(this, currentInput, ppToken);
|
||||||
|
if (token != '\n' && ppToken->space)
|
||||||
|
RecordToken(mac.body, ' ', ppToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for duplicate definition
|
||||||
symb = LookUpSymbol(atom);
|
symb = LookUpSymbol(atom);
|
||||||
if (symb) {
|
if (symb) {
|
||||||
if (! symb->mac.undef) {
|
if (! symb->mac.undef) {
|
||||||
@ -209,7 +212,7 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
if (symb->mac.argc != mac.argc)
|
if (symb->mac.argc != mac.argc)
|
||||||
parseContext.error(defineLoc, "Macro redefined; different number of arguments:", "#define", GetAtomString(atom));
|
parseContext.error(defineLoc, "Macro redefined; different number of arguments:", "#define", GetAtomString(atom));
|
||||||
else {
|
else {
|
||||||
for (argc=0; argc < mac.argc; argc++) {
|
for (int argc = 0; argc < mac.argc; argc++) {
|
||||||
if (symb->mac.args[argc] != mac.args[argc])
|
if (symb->mac.args[argc] != mac.args[argc])
|
||||||
parseContext.error(defineLoc, "Macro redefined; different argument names:", "#define", GetAtomString(atom));
|
parseContext.error(defineLoc, "Macro redefined; different argument names:", "#define", GetAtomString(atom));
|
||||||
}
|
}
|
||||||
@ -229,9 +232,9 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
|
|||||||
} while (newToken > 0);
|
} while (newToken > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
symb = AddSymbol(atom);
|
symb = AddSymbol(atom);
|
||||||
}
|
|
||||||
delete symb->mac.body;
|
delete symb->mac.body;
|
||||||
symb->mac = mac;
|
symb->mac = mac;
|
||||||
|
|
||||||
@ -930,6 +933,7 @@ int TPpContext::zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken* ppToken)
|
|||||||
|
|
||||||
strcpy(ppToken->name, "0");
|
strcpy(ppToken->name, "0");
|
||||||
ppToken->ival = 0;
|
ppToken->ival = 0;
|
||||||
|
ppToken->space = false;
|
||||||
|
|
||||||
// pop input
|
// pop input
|
||||||
pp->currentInput = in->prev;
|
pp->currentInput = in->prev;
|
||||||
@ -953,6 +957,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, int expandUndef)
|
|||||||
int token;
|
int token;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
|
|
||||||
|
ppToken->space = false;
|
||||||
if (atom == __LINE__Atom) {
|
if (atom == __LINE__Atom) {
|
||||||
ppToken->ival = parseContext.getCurrentLoc().line;
|
ppToken->ival = parseContext.getCurrentLoc().line;
|
||||||
sprintf(ppToken->name, "%d", ppToken->ival);
|
sprintf(ppToken->name, "%d", ppToken->ival);
|
||||||
|
|||||||
@ -84,7 +84,7 @@ namespace glslang {
|
|||||||
|
|
||||||
class TPpToken {
|
class TPpToken {
|
||||||
public:
|
public:
|
||||||
TPpToken() : token(0), ival(0), dval(0.0), atom(0)
|
TPpToken() : token(0), ival(0), space(false), dval(0.0), atom(0)
|
||||||
{
|
{
|
||||||
loc.line = 0;
|
loc.line = 0;
|
||||||
loc.string = 0;
|
loc.string = 0;
|
||||||
@ -103,6 +103,7 @@ public:
|
|||||||
|
|
||||||
TSourceLoc loc;
|
TSourceLoc loc;
|
||||||
int token;
|
int token;
|
||||||
|
bool space; // true if a space (for white space or a removed comment) should also be recognized, in front of the token returned
|
||||||
int ival;
|
int ival;
|
||||||
double dval;
|
double dval;
|
||||||
int atom;
|
int atom;
|
||||||
|
|||||||
@ -257,10 +257,11 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
|||||||
unsigned ival = 0;
|
unsigned ival = 0;
|
||||||
|
|
||||||
ppToken->ival = 0;
|
ppToken->ival = 0;
|
||||||
|
ppToken->space = false;
|
||||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
while (ch == ' ' || ch == '\t' || ch == '\r') {
|
while (ch == ' ' || ch == '\t' || ch == '\r') {
|
||||||
ppToken->ival = 1;
|
ppToken->space = true;
|
||||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,17 +650,13 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (ch != '\n' && ch != EOF);
|
} while (ch != '\n' && ch != EOF);
|
||||||
if (ch == EOF)
|
ppToken->space = true;
|
||||||
return EOF;
|
return ch;
|
||||||
return '\n';
|
|
||||||
} else if (ch == '*') {
|
} else if (ch == '*') {
|
||||||
int nlcount = 0;
|
|
||||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||||
do {
|
do {
|
||||||
while (ch != '*') {
|
while (ch != '*') {
|
||||||
if (ch == '\n')
|
if (ch == EOF) {
|
||||||
nlcount++;
|
|
||||||
else if (ch == EOF) {
|
|
||||||
pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
|
pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
|
||||||
|
|
||||||
return EOF;
|
return EOF;
|
||||||
@ -673,9 +670,9 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
|||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
} while (ch != '/');
|
} while (ch != '/');
|
||||||
if (nlcount)
|
ppToken->space = true;
|
||||||
return '\n';
|
// loop again to get the next token...
|
||||||
// Go try it again...
|
break;
|
||||||
} else if (ch == '=') {
|
} else if (ch == '=') {
|
||||||
return CPP_DIV_ASSIGN;
|
return CPP_DIV_ASSIGN;
|
||||||
} else {
|
} else {
|
||||||
@ -709,7 +706,6 @@ int TPpContext::sourceScan(TPpContext* pp, InputSrc*, TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ppToken->ival = 0;
|
|
||||||
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,9 +143,6 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken* ppToken)
|
|||||||
}
|
}
|
||||||
lAddByte(pTok, 0);
|
lAddByte(pTok, 0);
|
||||||
break;
|
break;
|
||||||
case '(':
|
|
||||||
lAddByte(pTok, (unsigned char)(ppToken->ival ? 1 : 0));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -179,9 +176,6 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
|
|||||||
if (ltoken > 127)
|
if (ltoken > 127)
|
||||||
ltoken += 128;
|
ltoken += 128;
|
||||||
switch (ltoken) {
|
switch (ltoken) {
|
||||||
case '(':
|
|
||||||
ppToken->ival = lReadByte(pTok);
|
|
||||||
break;
|
|
||||||
case CPP_STRCONSTANT:
|
case CPP_STRCONSTANT:
|
||||||
case CPP_IDENTIFIER:
|
case CPP_IDENTIFIER:
|
||||||
case CPP_FLOATCONSTANT:
|
case CPP_FLOATCONSTANT:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user