Non-functional: Use better token names for the preprocessor.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23624 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-10-20 18:37:53 +00:00
parent 1f4104fbb1
commit c973c004d4
5 changed files with 393 additions and 393 deletions

View file

@ -483,7 +483,7 @@ int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
loc = ppToken.loc; loc = ppToken.loc;
parserToken->sType.lex.loc = loc; parserToken->sType.lex.loc = loc;
switch (ppToken.ppToken) { switch (ppToken.token) {
case ';': afterType = false; return SEMICOLON; case ';': afterType = false; return SEMICOLON;
case ',': afterType = false; return COMMA; case ',': afterType = false; return COMMA;
case ':': return COLON; case ':': return COLON;

View file

@ -139,56 +139,56 @@ int TPpContext::FinalCPP()
return 1; return 1;
} }
int TPpContext::CPPdefine(TPpToken * yylvalpp) int TPpContext::CPPdefine(TPpToken * ppToken)
{ {
int token, atom, args[maxMacroArgs], argc; int token, atom, args[maxMacroArgs], argc;
MacroSymbol mac; MacroSymbol mac;
Symbol *symb; Symbol *symb;
memset(&mac, 0, sizeof(mac)); memset(&mac, 0, sizeof(mac));
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "must be followed by macro atom", "#define", ""); parseContext.error(ppToken->loc, "must be followed by macro atom", "#define", "");
return token; return token;
} }
atom = yylvalpp->atom; atom = ppToken->atom;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '(' && !yylvalpp->ival) { if (token == '(' && !ppToken->ival) {
// gather arguments // gather arguments
argc = 0; argc = 0;
do { do {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (argc == 0 && token == ')') if (argc == 0 && token == ')')
break; break;
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "bad argument", "#define", ""); parseContext.error(ppToken->loc, "bad argument", "#define", "");
return token; return token;
} }
if (argc < maxMacroArgs) if (argc < maxMacroArgs)
args[argc++] = yylvalpp->atom; args[argc++] = ppToken->atom;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} while (token == ','); } while (token == ',');
if (token != ')') { if (token != ')') {
parseContext.error(yylvalpp->loc, "missing parenthesis", "#define", ""); parseContext.error(ppToken->loc, "missing parenthesis", "#define", "");
return token; return token;
} }
mac.argc = argc; mac.argc = argc;
mac.args = (int*)mem_Alloc(pool, argc * sizeof(int)); mac.args = (int*)mem_Alloc(pool, argc * sizeof(int));
memcpy(mac.args, args, argc * sizeof(int)); memcpy(mac.args, args, argc * sizeof(int));
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
mac.body = NewTokenStream(GetAtomString(atom), pool); mac.body = NewTokenStream(GetAtomString(atom), pool);
while (token != '\n') { while (token != '\n') {
while (token == '\\') { while (token == '\\') {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n') if (token == '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
else else
RecordToken(mac.body, '\\', yylvalpp); RecordToken(mac.body, '\\', ppToken);
} }
RecordToken(mac.body, token, yylvalpp); RecordToken(mac.body, token, ppToken);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
}; };
symb = LookUpSymbol(atom); symb = LookUpSymbol(atom);
@ -204,12 +204,12 @@ int TPpContext::CPPdefine(TPpToken * yylvalpp)
RewindTokenStream(mac.body); RewindTokenStream(mac.body);
do { do {
int old_lval, old_token; int old_lval, old_token;
old_token = ReadToken(symb->mac.body, yylvalpp); old_token = ReadToken(symb->mac.body, ppToken);
old_lval = yylvalpp->ival; old_lval = ppToken->ival;
token = ReadToken(mac.body, yylvalpp); token = ReadToken(mac.body, ppToken);
if (token != old_token || yylvalpp->ival != old_lval) { if (token != old_token || ppToken->ival != old_lval) {
error: error:
parseContext.error(yylvalpp->loc, "Macro Redefined", "#define", GetAtomString(atom)); parseContext.error(ppToken->loc, "Macro Redefined", "#define", GetAtomString(atom));
break; break;
} }
} while (token > 0); } while (token > 0);
@ -222,28 +222,28 @@ error:
return '\n'; return '\n';
} // CPPdefine } // CPPdefine
int TPpContext::CPPundef(TPpToken * yylvalpp) int TPpContext::CPPundef(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
Symbol *symb; Symbol *symb;
if (token == '\n') { if (token == '\n') {
parseContext.error(yylvalpp->loc, "must be followed by macro name", "#undef", ""); parseContext.error(ppToken->loc, "must be followed by macro name", "#undef", "");
return token; return token;
} }
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "must be followed by macro name", "#undef", ""); parseContext.error(ppToken->loc, "must be followed by macro name", "#undef", "");
return token; return token;
} }
symb = LookUpSymbol(yylvalpp->atom); symb = LookUpSymbol(ppToken->atom);
if (symb) { if (symb) {
symb->mac.undef = 1; symb->mac.undef = 1;
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n') if (token != '\n')
parseContext.error(yylvalpp->loc, "can only be followed by a single macro name", "#undef", ""); parseContext.error(ppToken->loc, "can only be followed by a single macro name", "#undef", "");
return token; return token;
} // CPPundef } // CPPundef
@ -253,25 +253,25 @@ int TPpContext::CPPundef(TPpToken * yylvalpp)
** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false ** #elif, or #endif after a #if/#ifdef/#ifndef/#elif test was false
*/ */
int TPpContext::CPPelse(int matchelse, TPpToken * yylvalpp) int TPpContext::CPPelse(int matchelse, TPpToken * ppToken)
{ {
int atom; int atom;
int depth = 0; int depth = 0;
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
while (token > 0) { while (token > 0) {
if (token != '#') { if (token != '#') {
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
continue; continue;
} }
if ((token = currentInput->scan(this, currentInput, yylvalpp)) != CPP_IDENTIFIER) if ((token = currentInput->scan(this, currentInput, ppToken)) != CPP_IDENTIFIER)
continue; continue;
atom = yylvalpp->atom; atom = ppToken->atom;
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom) { if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom) {
depth++; depth++;
ifdepth++; ifdepth++;
@ -290,11 +290,11 @@ int TPpContext::CPPelse(int matchelse, TPpToken * yylvalpp)
} else if (matchelse && depth == 0) { } else if (matchelse && depth == 0) {
if (atom == elseAtom ) { if (atom == elseAtom ) {
// found the #else we are looking for // found the #else we are looking for
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n') { if (token != '\n') {
parseContext.warn(yylvalpp->loc, "#else", "unexpected tokens following #else directive - expected a newline", ""); parseContext.warn(ppToken->loc, "#else", "unexpected tokens following #else directive - expected a newline", "");
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
break; break;
} else if (atom == elifAtom) { } else if (atom == elifAtom) {
@ -306,10 +306,10 @@ int TPpContext::CPPelse(int matchelse, TPpToken * yylvalpp)
--elsetracker; --elsetracker;
} }
return CPPif (yylvalpp); return CPPif (ppToken);
} }
} else if ((atom == elseAtom) && (!ChkCorrectElseNesting())) } else if ((atom == elseAtom) && (!ChkCorrectElseNesting()))
parseContext.error(yylvalpp->loc, "#else after #else", "#else", ""); parseContext.error(ppToken->loc, "#else after #else", "#else", "");
}; // end while }; // end while
return token; return token;
@ -382,43 +382,43 @@ struct tunops {
#define ALEN(A) (sizeof(A)/sizeof(A[0])) #define ALEN(A) (sizeof(A)/sizeof(A[0]))
int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalpp) int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * ppToken)
{ {
int i, val; int i, val;
Symbol *s; Symbol *s;
if (token == CPP_IDENTIFIER) { if (token == CPP_IDENTIFIER) {
if (yylvalpp->atom == definedAtom) { if (ppToken->atom == definedAtom) {
bool needclose = 0; bool needclose = 0;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '(') { if (token == '(') {
needclose = true; needclose = true;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "incorrect directive, expected identifier", "preprocessor", ""); parseContext.error(ppToken->loc, "incorrect directive, expected identifier", "preprocessor", "");
*err = 1; *err = 1;
*res = 0; *res = 0;
return token; return token;
} }
*res = (s = LookUpSymbol(yylvalpp->atom)) *res = (s = LookUpSymbol(ppToken->atom))
? !s->mac.undef : 0; ? !s->mac.undef : 0;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (needclose) { if (needclose) {
if (token != ')') { if (token != ')') {
parseContext.error(yylvalpp->loc, "#else after #else", "", ""); parseContext.error(ppToken->loc, "#else after #else", "", "");
*err = 1; *err = 1;
*res = 0; *res = 0;
return token; return token;
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
} else { } else {
int macroReturn = MacroExpand(yylvalpp->atom, yylvalpp, 1); int macroReturn = MacroExpand(ppToken->atom, ppToken, 1);
if (macroReturn == 0) { if (macroReturn == 0) {
parseContext.error(yylvalpp->loc, "can't evaluate expression", "preprocessor", ""); parseContext.error(ppToken->loc, "can't evaluate expression", "preprocessor", "");
*err = 1; *err = 1;
*res = 0; *res = 0;
@ -427,34 +427,34 @@ int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalp
if (macroReturn == -1) { if (macroReturn == -1) {
if (parseContext.profile == EEsProfile) { if (parseContext.profile == EEsProfile) {
if (parseContext.messages & EShMsgRelaxedErrors) if (parseContext.messages & EShMsgRelaxedErrors)
parseContext.warn(yylvalpp->loc, "undefined macro in expression not allowed in es profile", "preprocessor", ""); parseContext.warn(ppToken->loc, "undefined macro in expression not allowed in es profile", "preprocessor", "");
else { else {
parseContext.error(yylvalpp->loc, "undefined macro in expression", "preprocessor", ""); parseContext.error(ppToken->loc, "undefined macro in expression", "preprocessor", "");
*err = 1; *err = 1;
} }
} }
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
return eval(token, prec, res, err, yylvalpp); return eval(token, prec, res, err, ppToken);
} }
} }
} else if (token == CPP_INTCONSTANT) { } else if (token == CPP_INTCONSTANT) {
*res = yylvalpp->ival; *res = ppToken->ival;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} else if (token == '(') { } else if (token == '(') {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, MIN_PREC, res, err, yylvalpp); token = eval(token, MIN_PREC, res, err, ppToken);
if (!*err) { if (!*err) {
if (token != ')') { if (token != ')') {
parseContext.error(yylvalpp->loc, "expected ')'", "preprocessor", ""); parseContext.error(ppToken->loc, "expected ')'", "preprocessor", "");
*err = 1; *err = 1;
*res = 0; *res = 0;
return token; return token;
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
} else { } else {
for (i = ALEN(unop) - 1; i >= 0; i--) { for (i = ALEN(unop) - 1; i >= 0; i--) {
@ -462,11 +462,11 @@ int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalp
break; break;
} }
if (i >= 0) { if (i >= 0) {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, UNARY, res, err, yylvalpp); token = eval(token, UNARY, res, err, ppToken);
*res = unop[i].op(*res); *res = unop[i].op(*res);
} else { } else {
parseContext.error(yylvalpp->loc, "", "bad expression", ""); parseContext.error(ppToken->loc, "", "bad expression", "");
*err = 1; *err = 1;
*res = 0; *res = 0;
@ -483,81 +483,81 @@ int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalp
if (i < 0 || binop[i].prec <= prec) if (i < 0 || binop[i].prec <= prec)
break; break;
val = *res; val = *res;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, binop[i].prec, res, err, yylvalpp); token = eval(token, binop[i].prec, res, err, ppToken);
*res = binop[i].op(val, *res); *res = binop[i].op(val, *res);
} }
return token; return token;
} // eval } // eval
int TPpContext::CPPif (TPpToken * yylvalpp) int TPpContext::CPPif (TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
int res = 0, err = 0; int res = 0, err = 0;
elsetracker++; elsetracker++;
if (! ifdepth++) if (! ifdepth++)
ifloc = yylvalpp->loc; ifloc = ppToken->loc;
if (ifdepth > maxIfNesting) { if (ifdepth > maxIfNesting) {
parseContext.error(yylvalpp->loc, "maximum nesting depth exceeded", "#if", ""); parseContext.error(ppToken->loc, "maximum nesting depth exceeded", "#if", "");
return 0; return 0;
} }
token = eval(token, MIN_PREC, &res, &err, yylvalpp); token = eval(token, MIN_PREC, &res, &err, ppToken);
if (token != '\n') { if (token != '\n') {
parseContext.warn(yylvalpp->loc, "unexpected tokens following #if directive - expected a newline", "#if", ""); parseContext.warn(ppToken->loc, "unexpected tokens following #if directive - expected a newline", "#if", "");
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
if (!res && !err) { if (!res && !err) {
token = CPPelse(1, yylvalpp); token = CPPelse(1, ppToken);
} }
return token; return token;
} // CPPif } // CPPif
int TPpContext::CPPifdef(int defined, TPpToken * yylvalpp) int TPpContext::CPPifdef(int defined, TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
int name = yylvalpp->atom; int name = ppToken->atom;
if (++ifdepth > maxIfNesting) { if (++ifdepth > maxIfNesting) {
parseContext.error(yylvalpp->loc, "maximum nesting depth exceeded", "#ifdef", ""); parseContext.error(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", "");
return 0; return 0;
} }
elsetracker++; elsetracker++;
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
if (defined) if (defined)
parseContext.error(yylvalpp->loc, "must be followed by macro name", "#ifdef", ""); parseContext.error(ppToken->loc, "must be followed by macro name", "#ifdef", "");
else else
parseContext.error(yylvalpp->loc, "must be followed by macro name", "#ifndef", ""); parseContext.error(ppToken->loc, "must be followed by macro name", "#ifndef", "");
} else { } else {
Symbol *s = LookUpSymbol(name); Symbol *s = LookUpSymbol(name);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n') { if (token != '\n') {
parseContext.error(yylvalpp->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", ""); parseContext.error(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
if (((s && !s->mac.undef) ? 1 : 0) != defined) if (((s && !s->mac.undef) ? 1 : 0) != defined)
token = CPPelse(1, yylvalpp); token = CPPelse(1, ppToken);
} }
return token; return token;
} // CPPifdef } // CPPifdef
// Handle #line // Handle #line
int TPpContext::CPPline(TPpToken * yylvalpp) int TPpContext::CPPline(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n') { if (token == '\n') {
parseContext.error(yylvalpp->loc, "must by followed by an integral literal", "#line", ""); parseContext.error(ppToken->loc, "must by followed by an integral literal", "#line", "");
return token; return token;
} }
else if (token == CPP_INTCONSTANT) { else if (token == CPP_INTCONSTANT) {
parseContext.currentLoc.line = atoi(yylvalpp->name); parseContext.currentLoc.line = atoi(ppToken->name);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == CPP_INTCONSTANT) { if (token == CPP_INTCONSTANT) {
parseContext.currentLoc.string = atoi(yylvalpp->name); parseContext.currentLoc.string = atoi(ppToken->name);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n') if (token != '\n')
parseContext.error(parseContext.currentLoc, "cannot be followed by more than two integral literals", "#line", ""); parseContext.error(parseContext.currentLoc, "cannot be followed by more than two integral literals", "#line", "");
} else if (token == '\n') } else if (token == '\n')
@ -572,23 +572,23 @@ int TPpContext::CPPline(TPpToken * yylvalpp)
} }
// Handle #error // Handle #error
int TPpContext::CPPerror(TPpToken * yylvalpp) int TPpContext::CPPerror(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
std::string message; std::string message;
TSourceLoc loc = yylvalpp->loc; TSourceLoc loc = ppToken->loc;
while (token != '\n') { while (token != '\n') {
if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT || if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT) { token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT) {
message.append(yylvalpp->name); message.append(ppToken->name);
} else if (token == CPP_IDENTIFIER || token == CPP_STRCONSTANT) { } else if (token == CPP_IDENTIFIER || token == CPP_STRCONSTANT) {
message.append(GetAtomString(yylvalpp->atom)); message.append(GetAtomString(ppToken->atom));
} else { } else {
message.append(GetAtomString(token)); message.append(GetAtomString(token));
} }
message.append(" "); message.append(" ");
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
//store this msg into the shader's information log..set the Compile Error flag!!!! //store this msg into the shader's information log..set the Compile Error flag!!!!
parseContext.error(loc, message.c_str(), "#error", ""); parseContext.error(loc, message.c_str(), "#error", "");
@ -596,7 +596,7 @@ int TPpContext::CPPerror(TPpToken * yylvalpp)
return '\n'; return '\n';
} }
int TPpContext::CPPpragma(TPpToken * yylvalpp) int TPpContext::CPPpragma(TPpToken * ppToken)
{ {
char SrcStrName[2]; char SrcStrName[2];
char** allTokens; char** allTokens;
@ -605,10 +605,10 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
const char* SrcStr; const char* SrcStr;
int i; int i;
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
if (token=='\n') { if (token=='\n') {
parseContext.error(yylvalpp->loc, "must be followed by pragma arguments", "#pragma", ""); parseContext.error(ppToken->loc, "must be followed by pragma arguments", "#pragma", "");
return token; return token;
} }
@ -621,7 +621,7 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
} }
switch (token) { switch (token) {
case CPP_IDENTIFIER: case CPP_IDENTIFIER:
SrcStr = GetAtomString(yylvalpp->atom); SrcStr = GetAtomString(ppToken->atom);
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr); strcpy(allTokens[tokenCount++], SrcStr);
break; break;
@ -629,12 +629,12 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
case CPP_UINTCONSTANT: case CPP_UINTCONSTANT:
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT: case CPP_DOUBLECONSTANT:
SrcStr = yylvalpp->name; SrcStr = ppToken->name;
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr); strcpy(allTokens[tokenCount++], SrcStr);
break; break;
case EOF: case EOF:
parseContext.error(yylvalpp->loc, "directive must end with a newline", "#pragma", ""); parseContext.error(ppToken->loc, "directive must end with a newline", "#pragma", "");
return token; return token;
default: default:
SrcStrName[0] = token; SrcStrName[0] = token;
@ -642,12 +642,12 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
allTokens[tokenCount] = (char*)malloc(2); allTokens[tokenCount] = (char*)malloc(2);
strcpy(allTokens[tokenCount++], SrcStrName); strcpy(allTokens[tokenCount++], SrcStrName);
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
currentInput->ungetch(this, currentInput, token, yylvalpp); currentInput->ungetch(this, currentInput, token, ppToken);
parseContext.handlePragma((const char**)allTokens, tokenCount); parseContext.handlePragma((const char**)allTokens, tokenCount);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
for (i = 0; i < tokenCount; ++i) { for (i = 0; i < tokenCount; ++i) {
free (allTokens[i]); free (allTokens[i]);
@ -658,151 +658,151 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
} // CPPpragma } // CPPpragma
// This is just for error checking: the version and profile are decided before preprocessing starts // This is just for error checking: the version and profile are decided before preprocessing starts
int TPpContext::CPPversion(TPpToken * yylvalpp) int TPpContext::CPPversion(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
if (notAVersionToken) if (notAVersionToken)
parseContext.error(yylvalpp->loc, "must occur before any other statement in the program", "#version", ""); parseContext.error(ppToken->loc, "must occur before any other statement in the program", "#version", "");
if (token == '\n') { if (token == '\n') {
parseContext.error(yylvalpp->loc, "must be followed by version number", "#version", ""); parseContext.error(ppToken->loc, "must be followed by version number", "#version", "");
return token; return token;
} }
if (token != CPP_INTCONSTANT) if (token != CPP_INTCONSTANT)
parseContext.error(yylvalpp->loc, "must be followed by version number", "#version", ""); parseContext.error(ppToken->loc, "must be followed by version number", "#version", "");
yylvalpp->ival = atoi(yylvalpp->name); ppToken->ival = atoi(ppToken->name);
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n') if (token == '\n')
return token; return token;
else { else {
if (yylvalpp->atom != coreAtom && if (ppToken->atom != coreAtom &&
yylvalpp->atom != compatibilityAtom && ppToken->atom != compatibilityAtom &&
yylvalpp->atom != esAtom) ppToken->atom != esAtom)
parseContext.error(yylvalpp->loc, "bad profile name; use es, core, or compatibility", "#version", ""); parseContext.error(ppToken->loc, "bad profile name; use es, core, or compatibility", "#version", "");
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n') if (token == '\n')
return token; return token;
else else
parseContext.error(yylvalpp->loc, "bad tokens following profile -- expected newline", "#version", ""); parseContext.error(ppToken->loc, "bad tokens following profile -- expected newline", "#version", "");
} }
return token; return token;
} // CPPversion } // CPPversion
int TPpContext::CPPextension(TPpToken * yylvalpp) int TPpContext::CPPextension(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
char extensionName[80]; char extensionName[80];
if (token=='\n') { if (token=='\n') {
parseContext.error(yylvalpp->loc, "extension name not specified", "#extension", ""); parseContext.error(ppToken->loc, "extension name not specified", "#extension", "");
return token; return token;
} }
if (token != CPP_IDENTIFIER) if (token != CPP_IDENTIFIER)
parseContext.error(yylvalpp->loc, "extension name expected", "#extension", ""); parseContext.error(ppToken->loc, "extension name expected", "#extension", "");
strcpy(extensionName, GetAtomString(yylvalpp->atom)); strcpy(extensionName, GetAtomString(ppToken->atom));
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != ':') { if (token != ':') {
parseContext.error(yylvalpp->loc, "':' missing after extension name", "#extension", ""); parseContext.error(ppToken->loc, "':' missing after extension name", "#extension", "");
return token; return token;
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != CPP_IDENTIFIER) { if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "behavior for extension not specified", "#extension", ""); parseContext.error(ppToken->loc, "behavior for extension not specified", "#extension", "");
return token; return token;
} }
parseContext.updateExtensionBehavior(extensionName, GetAtomString(yylvalpp->atom)); parseContext.updateExtensionBehavior(extensionName, GetAtomString(ppToken->atom));
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n') if (token == '\n')
return token; return token;
else else
parseContext.error(yylvalpp->loc, "extra tokens -- expected newline", "#extension",""); parseContext.error(ppToken->loc, "extra tokens -- expected newline", "#extension","");
return token; return token;
} // CPPextension } // CPPextension
int TPpContext::readCPPline(TPpToken * yylvalpp) int TPpContext::readCPPline(TPpToken * ppToken)
{ {
int token = currentInput->scan(this, currentInput, yylvalpp); int token = currentInput->scan(this, currentInput, ppToken);
bool isVersion = false; bool isVersion = false;
if (token == CPP_IDENTIFIER) { if (token == CPP_IDENTIFIER) {
if (yylvalpp->atom == defineAtom) { if (ppToken->atom == defineAtom) {
token = CPPdefine(yylvalpp); token = CPPdefine(ppToken);
} else if (yylvalpp->atom == elseAtom) { } else if (ppToken->atom == elseAtom) {
if (ChkCorrectElseNesting()) { if (ChkCorrectElseNesting()) {
if (! ifdepth) { if (! ifdepth) {
parseContext.error(yylvalpp->loc, "mismatched statements", "#else", ""); parseContext.error(ppToken->loc, "mismatched statements", "#else", "");
} }
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n') { if (token != '\n') {
parseContext.warn(yylvalpp->loc, "unexpected tokens following #else directive - expected a newline", "#else", ""); parseContext.warn(ppToken->loc, "unexpected tokens following #else directive - expected a newline", "#else", "");
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
token = CPPelse(0, yylvalpp); token = CPPelse(0, ppToken);
} else { } else {
parseContext.error(yylvalpp->loc, "#else after a #else", "#else", ""); parseContext.error(ppToken->loc, "#else after a #else", "#else", "");
ifdepth = 0; ifdepth = 0;
notAVersionToken = true; notAVersionToken = true;
return 0; return 0;
} }
} else if (yylvalpp->atom == elifAtom) { } else if (ppToken->atom == elifAtom) {
if (! ifdepth) { if (! ifdepth) {
parseContext.error(yylvalpp->loc, "mismatched statements", "#elif", ""); parseContext.error(ppToken->loc, "mismatched statements", "#elif", "");
} }
// this token is really a dont care, but we still need to eat the tokens // this token is really a dont care, but we still need to eat the tokens
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
while (token != '\n') while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
token = CPPelse(0, yylvalpp); token = CPPelse(0, ppToken);
} else if (yylvalpp->atom == endifAtom) { } else if (ppToken->atom == endifAtom) {
elsedepth[elsetracker] = 0; elsedepth[elsetracker] = 0;
--elsetracker; --elsetracker;
if (! ifdepth) if (! ifdepth)
parseContext.error(yylvalpp->loc, "mismatched statements", "#endif", ""); parseContext.error(ppToken->loc, "mismatched statements", "#endif", "");
else else
--ifdepth; --ifdepth;
} else if (yylvalpp->atom == ifAtom) { } else if (ppToken->atom == ifAtom) {
token = CPPif (yylvalpp); token = CPPif (ppToken);
} else if (yylvalpp->atom == ifdefAtom) { } else if (ppToken->atom == ifdefAtom) {
token = CPPifdef(1, yylvalpp); token = CPPifdef(1, ppToken);
} else if (yylvalpp->atom == ifndefAtom) { } else if (ppToken->atom == ifndefAtom) {
token = CPPifdef(0, yylvalpp); token = CPPifdef(0, ppToken);
} else if (yylvalpp->atom == lineAtom) { } else if (ppToken->atom == lineAtom) {
token = CPPline(yylvalpp); token = CPPline(ppToken);
} else if (yylvalpp->atom == pragmaAtom) { } else if (ppToken->atom == pragmaAtom) {
token = CPPpragma(yylvalpp); token = CPPpragma(ppToken);
} else if (yylvalpp->atom == undefAtom) { } else if (ppToken->atom == undefAtom) {
token = CPPundef(yylvalpp); token = CPPundef(ppToken);
} else if (yylvalpp->atom == errorAtom) { } else if (ppToken->atom == errorAtom) {
token = CPPerror(yylvalpp); token = CPPerror(ppToken);
} else if (yylvalpp->atom == versionAtom) { } else if (ppToken->atom == versionAtom) {
token = CPPversion(yylvalpp); token = CPPversion(ppToken);
isVersion = true; isVersion = true;
} else if (yylvalpp->atom == extensionAtom) { } else if (ppToken->atom == extensionAtom) {
token = CPPextension(yylvalpp); token = CPPextension(ppToken);
} else { } else {
parseContext.error(yylvalpp->loc, "Invalid Directive", "#", GetAtomString(yylvalpp->atom)); parseContext.error(ppToken->loc, "Invalid Directive", "#", GetAtomString(ppToken->atom));
} }
} }
while (token != '\n' && token != 0 && token != EOF) { while (token != '\n' && token != 0 && token != EOF) {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
} }
notAVersionToken = ! isVersion; notAVersionToken = ! isVersion;
@ -814,8 +814,8 @@ void TPpContext::FreeMacro(MacroSymbol *s) {
DeleteTokenStream(s->body); DeleteTokenStream(s->body);
} }
int eof_scan(TPpContext*, TPpContext::InputSrc* in, TPpToken* yylvalpp) { return -1; } int eof_scan(TPpContext*, TPpContext::InputSrc* in, TPpToken* ppToken) { return -1; }
void noop(TPpContext*, TPpContext::InputSrc* in, int ch, TPpToken* yylvalpp) { } void noop(TPpContext*, TPpContext::InputSrc* in, int ch, TPpToken* ppToken) { }
void TPpContext::PushEofSrc() void TPpContext::PushEofSrc()
{ {
@ -837,24 +837,24 @@ void TPpContext::PopEofSrc()
} }
} }
TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken * yylvalpp) TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken * ppToken)
{ {
int token; int token;
TokenStream *n; TokenStream *n;
RewindTokenStream(a); RewindTokenStream(a);
do { do {
token = ReadToken(a, yylvalpp); token = ReadToken(a, ppToken);
if (token == CPP_IDENTIFIER && LookUpSymbol(yylvalpp->atom)) if (token == CPP_IDENTIFIER && LookUpSymbol(ppToken->atom))
break; break;
} while (token > 0); } while (token > 0);
if (token <= 0) return a; if (token <= 0) return a;
n = NewTokenStream("macro arg", 0); n = NewTokenStream("macro arg", 0);
PushEofSrc(); PushEofSrc();
ReadFromTokenStream(a, 0, 0); ReadFromTokenStream(a, 0, 0);
while ((token = currentInput->scan(this, currentInput, yylvalpp)) > 0) { while ((token = currentInput->scan(this, currentInput, ppToken)) > 0) {
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->atom, yylvalpp, 0) == 1) if (token == CPP_IDENTIFIER && MacroExpand(ppToken->atom, ppToken, 0) == 1)
continue; continue;
RecordToken(n, token, yylvalpp); RecordToken(n, token, ppToken);
} }
PopEofSrc(); PopEofSrc();
DeleteTokenStream(a); DeleteTokenStream(a);
@ -868,20 +868,20 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken *
/* macro_scan --- /* macro_scan ---
** return the next token for a macro expansion, handling macro args ** return the next token for a macro expansion, handling macro args
*/ */
int TPpContext::macro_scan(TPpContext* pp, TPpContext::InputSrc* inInput, TPpToken* yylvalpp) int TPpContext::macro_scan(TPpContext* pp, TPpContext::InputSrc* inInput, TPpToken* ppToken)
{ {
TPpContext::MacroInputSrc* in = (TPpContext::MacroInputSrc*)inInput; TPpContext::MacroInputSrc* in = (TPpContext::MacroInputSrc*)inInput;
int i; int i;
int token = pp->ReadToken(in->mac->body, yylvalpp); int token = pp->ReadToken(in->mac->body, ppToken);
if (token == CPP_IDENTIFIER) { if (token == CPP_IDENTIFIER) {
for (i = in->mac->argc-1; i>=0; i--) for (i = in->mac->argc-1; i>=0; i--)
if (in->mac->args[i] == yylvalpp->atom) if (in->mac->args[i] == ppToken->atom)
break; break;
if (i >= 0) { if (i >= 0) {
pp->ReadFromTokenStream(in->args[i], yylvalpp->atom, 0); pp->ReadFromTokenStream(in->args[i], ppToken->atom, 0);
return pp->currentInput->scan(pp, pp->currentInput, yylvalpp); return pp->currentInput->scan(pp, pp->currentInput, ppToken);
} }
} }
@ -897,16 +897,16 @@ int TPpContext::macro_scan(TPpContext* pp, TPpContext::InputSrc* inInput, TPpTok
} }
free(in); free(in);
return pp->currentInput->scan(pp, pp->currentInput, yylvalpp); return pp->currentInput->scan(pp, pp->currentInput, ppToken);
} // macro_scan } // macro_scan
// return a zero, for scanning a macro that was never defined // return a zero, for scanning a macro that was never defined
int TPpContext::zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken* yylvalpp) int TPpContext::zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken* ppToken)
{ {
MacroInputSrc* in = (MacroInputSrc*)inInput; MacroInputSrc* in = (MacroInputSrc*)inInput;
strcpy(yylvalpp->name, "0"); strcpy(ppToken->name, "0");
yylvalpp->ival = 0; ppToken->ival = 0;
// pop input // pop input
pp->currentInput = in->base.prev; pp->currentInput = in->base.prev;
@ -923,7 +923,7 @@ int TPpContext::zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken* yylvalpp)
** expand to 0 and return -1. ** expand to 0 and return -1.
** Otherwise, return 0. ** Otherwise, return 0.
*/ */
int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef) int TPpContext::MacroExpand(int atom, TPpToken* ppToken, int expandUndef)
{ {
Symbol *sym = LookUpSymbol(atom); Symbol *sym = LookUpSymbol(atom);
MacroInputSrc *in; MacroInputSrc *in;
@ -931,25 +931,25 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
int depth = 0; int depth = 0;
if (atom == __LINE__Atom) { if (atom == __LINE__Atom) {
yylvalpp->ival = parseContext.currentLoc.line; ppToken->ival = parseContext.currentLoc.line;
sprintf(yylvalpp->name, "%d", yylvalpp->ival); sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp); UngetToken(CPP_INTCONSTANT, ppToken);
return 1; return 1;
} }
if (atom == __FILE__Atom) { if (atom == __FILE__Atom) {
yylvalpp->ival = parseContext.currentLoc.string; ppToken->ival = parseContext.currentLoc.string;
sprintf(yylvalpp->name, "%d", yylvalpp->ival); sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp); UngetToken(CPP_INTCONSTANT, ppToken);
return 1; return 1;
} }
if (atom == __VERSION__Atom) { if (atom == __VERSION__Atom) {
yylvalpp->ival = parseContext.version; ppToken->ival = parseContext.version;
sprintf(yylvalpp->name, "%d", yylvalpp->ival); sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp); UngetToken(CPP_INTCONSTANT, ppToken);
return 1; return 1;
} }
@ -979,10 +979,10 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
in->base.scan = macro_scan; in->base.scan = macro_scan;
in->mac = &sym->mac; in->mac = &sym->mac;
if (sym->mac.args) { if (sym->mac.args) {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token != '(') { if (token != '(') {
UngetToken(token, yylvalpp); UngetToken(token, ppToken);
yylvalpp->atom = atom; ppToken->atom = atom;
return 0; return 0;
} }
@ -994,9 +994,9 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
do { do {
depth = 0; depth = 0;
while (1) { while (1) {
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token <= 0) { if (token <= 0) {
parseContext.error(yylvalpp->loc, "EOF in macro", "preprocessor", GetAtomString(atom)); parseContext.error(ppToken->loc, "EOF in macro", "preprocessor", GetAtomString(atom));
return 1; return 1;
} }
@ -1004,7 +1004,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
if (depth == 0 && (token == ',' || token == ')')) break; if (depth == 0 && (token == ',' || token == ')')) break;
if (token == '(') depth++; if (token == '(') depth++;
if (token == ')') depth--; if (token == ')') depth--;
RecordToken(in->args[i], token, yylvalpp); RecordToken(in->args[i], token, ppToken);
j=1; j=1;
} }
if (token == ')') { if (token == ')') {
@ -1017,26 +1017,26 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
} while (i < in->mac->argc); } while (i < in->mac->argc);
if (i < in->mac->argc) if (i < in->mac->argc)
parseContext.error(yylvalpp->loc, "Too few args in Macro", "preprocessor", GetAtomString(atom)); parseContext.error(ppToken->loc, "Too few args in Macro", "preprocessor", GetAtomString(atom));
else if (token != ')') { else if (token != ')') {
depth=0; depth=0;
while (token >= 0 && (depth > 0 || token != ')')) { while (token >= 0 && (depth > 0 || token != ')')) {
if (token == ')') if (token == ')')
depth--; depth--;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
if (token == '(') if (token == '(')
depth++; depth++;
} }
if (token <= 0) { if (token <= 0) {
parseContext.error(yylvalpp->loc, "EOF in macro", "preprocessor", GetAtomString(atom)); parseContext.error(ppToken->loc, "EOF in macro", "preprocessor", GetAtomString(atom));
return 1; return 1;
} }
parseContext.error(yylvalpp->loc, "Too many args in Macro", "preprocessor", GetAtomString(atom)); parseContext.error(ppToken->loc, "Too many args in Macro", "preprocessor", GetAtomString(atom));
} }
for (i = 0; i<in->mac->argc; i++) { for (i = 0; i<in->mac->argc; i++) {
in->args[i] = PrescanMacroArg(in->args[i], yylvalpp); in->args[i] = PrescanMacroArg(in->args[i], ppToken);
} }
} }
#if 0 #if 0

View file

@ -90,7 +90,7 @@ public:
static const int maxTokenLength = 1024; static const int maxTokenLength = 1024;
TSourceLoc loc; TSourceLoc loc;
int ppToken; int token;
int ival; int ival;
double dval; double dval;
int atom; int atom;
@ -108,7 +108,7 @@ public:
void setPreamble(const char* preamble, size_t length); void setPreamble(const char* preamble, size_t length);
void setShaderStrings(char* strings[], size_t lengths[], int numStrings); void setShaderStrings(char* strings[], size_t lengths[], int numStrings);
const char* tokenize(TPpToken* yylvalpp); const char* tokenize(TPpToken* ppToken);
struct InputSrc { struct InputSrc {
struct InputSrc *prev; struct InputSrc *prev;
@ -230,25 +230,25 @@ protected:
int InitCPP(); int InitCPP();
int FinalCPP(); int FinalCPP();
int CPPdefine(TPpToken * yylvalpp); int CPPdefine(TPpToken * ppToken);
int CPPundef(TPpToken * yylvalpp); int CPPundef(TPpToken * ppToken);
int CPPelse(int matchelse, TPpToken * yylvalpp); int CPPelse(int matchelse, TPpToken * ppToken);
int eval(int token, int prec, int *res, int *err, TPpToken * yylvalpp); int eval(int token, int prec, int *res, int *err, TPpToken * ppToken);
int CPPif (TPpToken * yylvalpp); int CPPif (TPpToken * ppToken);
int CPPifdef(int defined, TPpToken * yylvalpp); int CPPifdef(int defined, TPpToken * ppToken);
int CPPline(TPpToken * yylvalpp); int CPPline(TPpToken * ppToken);
int CPPerror(TPpToken * yylvalpp); int CPPerror(TPpToken * ppToken);
int CPPpragma(TPpToken * yylvalpp); int CPPpragma(TPpToken * ppToken);
int CPPversion(TPpToken * yylvalpp); int CPPversion(TPpToken * ppToken);
int CPPextension(TPpToken * yylvalpp); int CPPextension(TPpToken * ppToken);
int readCPPline(TPpToken * yylvalpp); int readCPPline(TPpToken * ppToken);
void FreeMacro(MacroSymbol *s); void FreeMacro(MacroSymbol *s);
void PushEofSrc(); void PushEofSrc();
void PopEofSrc(); void PopEofSrc();
TokenStream* PrescanMacroArg(TokenStream *a, TPpToken * yylvalpp); TokenStream* PrescanMacroArg(TokenStream *a, TPpToken * ppToken);
static int macro_scan(TPpContext* pp, InputSrc *inInput, TPpToken * yylvalpp); static int macro_scan(TPpContext* pp, InputSrc *inInput, TPpToken * ppToken);
static int zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken * yylvalpp); static int zero_scan(TPpContext* pp, InputSrc *inInput, TPpToken * ppToken);
int MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef); int MacroExpand(int atom, TPpToken* ppToken, int expandUndef);
int ChkCorrectElseNesting(); int ChkCorrectElseNesting();
// //
@ -267,24 +267,24 @@ protected:
int lReadByte(TokenStream *pTok); int lReadByte(TokenStream *pTok);
TokenStream *NewTokenStream(const char *name, MemoryPool *pool); TokenStream *NewTokenStream(const char *name, MemoryPool *pool);
void DeleteTokenStream(TokenStream *pTok); void DeleteTokenStream(TokenStream *pTok);
void RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp); void RecordToken(TokenStream *pTok, int token, TPpToken * ppToken);
void RewindTokenStream(TokenStream *pTok); void RewindTokenStream(TokenStream *pTok);
int ReadToken(TokenStream *pTok, TPpToken * yylvalpp); int ReadToken(TokenStream *pTok, TPpToken * ppToken);
int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *)); int ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *));
void UngetToken(int token, TPpToken * yylvalpp); void UngetToken(int token, TPpToken * ppToken);
void DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * yylvalpp); void DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * ppToken);
struct TokenInputSrc { struct TokenInputSrc {
InputSrc base; InputSrc base;
TokenStream *tokens; TokenStream *tokens;
int (*final)(TPpContext *); int (*final)(TPpContext *);
}; };
static int scan_token(TPpContext*, TokenInputSrc *in, TPpToken * yylvalpp); static int scan_token(TPpContext*, TokenInputSrc *in, TPpToken * ppToken);
struct UngotToken { struct UngotToken {
InputSrc base; InputSrc base;
int token; int token;
TPpToken lval; TPpToken lval;
}; };
static int reget_token(TPpContext *, UngotToken *t, TPpToken * yylvalpp); static int reget_token(TPpContext *, UngotToken *t, TPpToken * ppToken);
// //
// From PpScanner.cpp // From PpScanner.cpp
@ -298,8 +298,8 @@ protected:
static void str_ungetch(TPpContext*, StringInputSrc *in, int ch, TPpToken *type); static void str_ungetch(TPpContext*, StringInputSrc *in, int ch, TPpToken *type);
int ScanFromString(char *s); int ScanFromString(char *s);
int check_EOF(int token); int check_EOF(int token);
int lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp); int lFloatConst(char *str, int len, int ch, TPpToken * ppToken);
static int byte_scan(TPpContext*, InputSrc *in, TPpToken * yylvalpp); static int byte_scan(TPpContext*, InputSrc *in, TPpToken * ppToken);
// //
// From PpAtom.cpp // From PpAtom.cpp

View file

@ -98,7 +98,7 @@ int eof_scan(TPpContext*, TPpContext::InputSrc*, TPpToken*)
return EOF; return EOF;
} }
void noop(TPpContext*, TPpContext::InputSrc *in, int ch, TPpToken * yylvalpp) void noop(TPpContext*, TPpContext::InputSrc *in, int ch, TPpToken * ppToken)
{ {
} }
@ -199,7 +199,7 @@ int TPpContext::ScanFromString(char *s)
* letter 'e', or a precision ending (e.g., F or LF). * letter 'e', or a precision ending (e.g., F or LF).
*/ */
int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp) int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * ppToken)
{ {
bool HasDecimalOrExponent = false; bool HasDecimalOrExponent = false;
int declen, exp, ExpSign; int declen, exp, ExpSign;
@ -213,7 +213,7 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
if (ch == '.') { if (ch == '.') {
HasDecimalOrExponent = true; HasDecimalOrExponent = true;
str[len++]=ch; str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
while (ch >= '0' && ch <= '9') { while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) { if (len < TPpToken::maxTokenLength) {
declen++; declen++;
@ -221,9 +221,9 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
str[len] = ch; str[len] = ch;
len++;str_len++; len++;str_len++;
} }
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
} else { } else {
parseContext.error(yylvalpp->loc, "float literal too long", "", ""); parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1; len = 1,str_len=1;
} }
} }
@ -234,77 +234,77 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
if (ch == 'e' || ch == 'E') { if (ch == 'e' || ch == 'E') {
HasDecimalOrExponent = true; HasDecimalOrExponent = true;
if (len >= TPpToken::maxTokenLength) { if (len >= TPpToken::maxTokenLength) {
parseContext.error(yylvalpp->loc, "float literal too long", "", ""); parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1; len = 1,str_len=1;
} else { } else {
ExpSign = 1; ExpSign = 1;
str[len++]=ch; str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
if (ch == '+') { if (ch == '+') {
str[len++]=ch; str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
} else if (ch == '-') { } else if (ch == '-') {
ExpSign = -1; ExpSign = -1;
str[len++]=ch; str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
} }
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
while (ch >= '0' && ch <= '9') { while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) { if (len < TPpToken::maxTokenLength) {
exp = exp*10 + ch - '0'; exp = exp*10 + ch - '0';
str[len++]=ch; str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp); ch = currentInput->getch(this, currentInput, ppToken);
} else { } else {
parseContext.error(yylvalpp->loc, "float literal too long", "", ""); parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1; len = 1,str_len=1;
} }
} }
} else { } else {
parseContext.error(yylvalpp->loc, "bad character in float exponent", "", ""); parseContext.error(ppToken->loc, "bad character in float exponent", "", "");
} }
exp *= ExpSign; exp *= ExpSign;
} }
} }
if (len == 0) { if (len == 0) {
yylvalpp->dval = 0.0; ppToken->dval = 0.0;
strcpy(str, "0.0"); strcpy(str, "0.0");
} else { } else {
if (ch == 'l' || ch == 'L') { if (ch == 'l' || ch == 'L') {
if (! HasDecimalOrExponent) if (! HasDecimalOrExponent)
parseContext.error(yylvalpp->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.error(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
int ch2 = currentInput->getch(this, currentInput, yylvalpp); int ch2 = currentInput->getch(this, currentInput, ppToken);
if (ch2 != 'f' && ch2 != 'F') { if (ch2 != 'f' && ch2 != 'F') {
currentInput->ungetch(this, currentInput, ch2, yylvalpp); currentInput->ungetch(this, currentInput, ch2, ppToken);
currentInput->ungetch(this, currentInput, ch, yylvalpp); currentInput->ungetch(this, currentInput, ch, ppToken);
} else { } else {
if (len < TPpToken::maxTokenLength) { if (len < TPpToken::maxTokenLength) {
str[len++] = ch; str[len++] = ch;
str[len++] = ch2; str[len++] = ch2;
isDouble = 1; isDouble = 1;
} else { } else {
parseContext.error(yylvalpp->loc, "float literal too long", "", ""); parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1; len = 1,str_len=1;
} }
} }
} else if (ch == 'f' || ch == 'F') { } else if (ch == 'f' || ch == 'F') {
if (! HasDecimalOrExponent) if (! HasDecimalOrExponent)
parseContext.error(yylvalpp->loc, "float literal needs a decimal point or exponent", "", ""); parseContext.error(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
str[len++] = ch; str[len++] = ch;
else { else {
parseContext.error(yylvalpp->loc, "float literal too long", "", ""); parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1; len = 1,str_len=1;
} }
} else } else
currentInput->ungetch(this, currentInput, ch, yylvalpp); currentInput->ungetch(this, currentInput, ch, ppToken);
str[len]='\0'; str[len]='\0';
yylvalpp->dval = strtod(str, 0); ppToken->dval = strtod(str, 0);
} }
// Suffix: // Suffix:
strcpy(yylvalpp->name, str); strcpy(ppToken->name, str);
if (isDouble) if (isDouble)
return CPP_DOUBLECONSTANT; return CPP_DOUBLECONSTANT;
@ -316,7 +316,7 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
///////////////////////////////////////// Normal Scanner ////////////////////////////////////// ///////////////////////////////////////// Normal Scanner //////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp) int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * ppToken)
{ {
char tokenText[TPpToken::maxTokenLength + 1]; char tokenText[TPpToken::maxTokenLength + 1];
int AlreadyComplained = 0; int AlreadyComplained = 0;
@ -324,15 +324,15 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
unsigned ival = 0; unsigned ival = 0;
for (;;) { for (;;) {
yylvalpp->ival = 0; ppToken->ival = 0;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
while (ch == ' ' || ch == '\t' || ch == '\r') { while (ch == ' ' || ch == '\t' || ch == '\r') {
yylvalpp->ival = 1; ppToken->ival = 1;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} }
yylvalpp->loc = pp->parseContext.currentLoc; ppToken->loc = pp->parseContext.currentLoc;
len = 0; len = 0;
switch (ch) { switch (ch) {
default: default:
@ -354,24 +354,24 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
do { do {
if (ch == '\\') { if (ch == '\\') {
// escaped character // escaped character
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\r' || ch == '\n') { if (ch == '\r' || ch == '\n') {
int nextch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); int nextch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\r' && nextch == '\n') if (ch == '\r' && nextch == '\n')
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
else else
ch = nextch; ch = nextch;
} else } else
pp->parseContext.error(yylvalpp->loc, "can only escape newlines", "\\", ""); pp->parseContext.error(ppToken->loc, "can only escape newlines", "\\", "");
} else if (len < TPpToken::maxTokenLength) { } else if (len < TPpToken::maxTokenLength) {
tokenText[len++] = ch; tokenText[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} else { } else {
if (! AlreadyComplained) { if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "name too long", "", ""); pp->parseContext.error(ppToken->loc, "name too long", "", "");
AlreadyComplained = 1; AlreadyComplained = 1;
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} }
} while ((ch >= 'a' && ch <= 'z') || } while ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') || (ch >= 'A' && ch <= 'Z') ||
@ -380,19 +380,19 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ch == '\\'); ch == '\\');
tokenText[len] = '\0'; tokenText[len] = '\0';
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
yylvalpp->atom = pp->LookUpAddString(tokenText); ppToken->atom = pp->LookUpAddString(tokenText);
return CPP_IDENTIFIER; return CPP_IDENTIFIER;
case '0': case '0':
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == 'x' || ch == 'X') { if (ch == 'x' || ch == 'X') {
// must be hexidecimal // must be hexidecimal
bool isUnsigned = false; bool isUnsigned = false;
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if ((ch >= '0' && ch <= '9') || if ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') || (ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f')) (ch >= 'a' && ch <= 'f'))
@ -400,7 +400,7 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ival = 0; ival = 0;
do { do {
if (ival <= 0x0fffffff) { if (ival <= 0x0fffffff) {
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
ii = ch - '0'; ii = ch - '0';
} else if (ch >= 'A' && ch <= 'F') { } else if (ch >= 'A' && ch <= 'F') {
@ -408,30 +408,30 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
} else if (ch >= 'a' && ch <= 'f') { } else if (ch >= 'a' && ch <= 'f') {
ii = ch - 'a' + 10; ii = ch - 'a' + 10;
} else } else
pp->parseContext.error(yylvalpp->loc, "bad digit in hexidecimal literal", "", ""); pp->parseContext.error(ppToken->loc, "bad digit in hexidecimal literal", "", "");
ival = (ival << 4) | ii; ival = (ival << 4) | ii;
} else { } else {
if (! AlreadyComplained) { if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "hexidecimal literal too big", "", ""); pp->parseContext.error(ppToken->loc, "hexidecimal literal too big", "", "");
AlreadyComplained = 1; AlreadyComplained = 1;
} }
ival = 0xffffffff; ival = 0xffffffff;
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while ((ch >= '0' && ch <= '9') || } while ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') || (ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f')); (ch >= 'a' && ch <= 'f'));
} else { } else {
pp->parseContext.error(yylvalpp->loc, "bad digit in hexidecimal literal", "", ""); pp->parseContext.error(ppToken->loc, "bad digit in hexidecimal literal", "", "");
} }
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
isUnsigned = true; isUnsigned = true;
} else } else
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
yylvalpp->name[len] = '\0'; ppToken->name[len] = '\0';
yylvalpp->ival = (int)ival; ppToken->ival = (int)ival;
if (isUnsigned) if (isUnsigned)
return CPP_UINTCONSTANT; return CPP_UINTCONSTANT;
@ -448,9 +448,9 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
// see how much octal-like stuff we can read // see how much octal-like stuff we can read
while (ch >= '0' && ch <= '7') { while (ch >= '0' && ch <= '7') {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", ""); pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1; AlreadyComplained = 1;
} }
if (ival <= 0x1fffffff) { if (ival <= 0x1fffffff) {
@ -458,7 +458,7 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ival = (ival << 3) | ii; ival = (ival << 3) | ii;
} else } else
octalOverflow = true; octalOverflow = true;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} }
// could be part of a float... // could be part of a float...
@ -466,33 +466,33 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
nonOctal = true; nonOctal = true;
do { do {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", ""); pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1; AlreadyComplained = 1;
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
} }
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L')
return pp->lFloatConst(yylvalpp->name, len, ch, yylvalpp); return pp->lFloatConst(ppToken->name, len, ch, ppToken);
// wasn't a float, so must be octal... // wasn't a float, so must be octal...
if (nonOctal) if (nonOctal)
pp->parseContext.error(yylvalpp->loc, "octal literal digit too large", "", ""); pp->parseContext.error(ppToken->loc, "octal literal digit too large", "", "");
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
isUnsigned = true; isUnsigned = true;
} else } else
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
yylvalpp->name[len] = '\0'; ppToken->name[len] = '\0';
if (octalOverflow) if (octalOverflow)
pp->parseContext.error(yylvalpp->loc, "octal literal too big", "", ""); pp->parseContext.error(ppToken->loc, "octal literal too big", "", "");
yylvalpp->ival = (int)ival; ppToken->ival = (int)ival;
if (isUnsigned) if (isUnsigned)
return CPP_UINTCONSTANT; return CPP_UINTCONSTANT;
@ -506,38 +506,38 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
do { do {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
else if (! AlreadyComplained) { else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", ""); pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1; AlreadyComplained = 1;
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') { if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') {
return pp->lFloatConst(yylvalpp->name, len, ch, yylvalpp); return pp->lFloatConst(ppToken->name, len, ch, ppToken);
} else { } else {
// Finish handling signed and unsigned integers // Finish handling signed and unsigned integers
int numericLen = len; int numericLen = len;
int uint = 0; int uint = 0;
if (ch == 'u' || ch == 'U') { if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength) if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch; ppToken->name[len++] = ch;
uint = 1; uint = 1;
} else } else
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
yylvalpp->name[len] = '\0'; ppToken->name[len] = '\0';
ival = 0; ival = 0;
for (ii = 0; ii < numericLen; ii++) { for (ii = 0; ii < numericLen; ii++) {
ch = yylvalpp->name[ii] - '0'; ch = ppToken->name[ii] - '0';
if ((ival > 429496729) || (ival == 429496729 && ch >= 6)) { if ((ival > 429496729) || (ival == 429496729 && ch >= 6)) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too big", "", ""); pp->parseContext.error(ppToken->loc, "numeric literal too big", "", "");
ival = -1; ival = -1;
break; break;
} else } else
ival = ival * 10 + ch; ival = ival * 10 + ch;
} }
yylvalpp->ival = (int)ival; ppToken->ival = (int)ival;
if (uint) if (uint)
return CPP_UINTCONSTANT; return CPP_UINTCONSTANT;
@ -546,112 +546,112 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
} }
break; break;
case '-': case '-':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '-') { if (ch == '-') {
return CPP_DEC_OP; return CPP_DEC_OP;
} else if (ch == '=') { } else if (ch == '=') {
return CPP_SUB_ASSIGN; return CPP_SUB_ASSIGN;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '-'; return '-';
} }
case '+': case '+':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '+') { if (ch == '+') {
return CPP_INC_OP; return CPP_INC_OP;
} else if (ch == '=') { } else if (ch == '=') {
return CPP_ADD_ASSIGN; return CPP_ADD_ASSIGN;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '+'; return '+';
} }
case '*': case '*':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') { if (ch == '=') {
return CPP_MUL_ASSIGN; return CPP_MUL_ASSIGN;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '*'; return '*';
} }
case '%': case '%':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') { if (ch == '=') {
return CPP_MOD_ASSIGN; return CPP_MOD_ASSIGN;
} else if (ch == '>'){ } else if (ch == '>'){
return CPP_RIGHT_BRACE; return CPP_RIGHT_BRACE;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '%'; return '%';
} }
case ':': case ':':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '>') { if (ch == '>') {
return CPP_RIGHT_BRACKET; return CPP_RIGHT_BRACKET;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return ':'; return ':';
} }
case '^': case '^':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '^') { if (ch == '^') {
return CPP_XOR_OP; return CPP_XOR_OP;
} else { } else {
if (ch == '=') if (ch == '=')
return CPP_XOR_ASSIGN; return CPP_XOR_ASSIGN;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '^'; return '^';
} }
} }
case '=': case '=':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') { if (ch == '=') {
return CPP_EQ_OP; return CPP_EQ_OP;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '='; return '=';
} }
case '!': case '!':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') { if (ch == '=') {
return CPP_NE_OP; return CPP_NE_OP;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '!'; return '!';
} }
case '|': case '|':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '|') { if (ch == '|') {
return CPP_OR_OP; return CPP_OR_OP;
} else { } else {
if (ch == '=') if (ch == '=')
return CPP_OR_ASSIGN; return CPP_OR_ASSIGN;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '|'; return '|';
} }
} }
case '&': case '&':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '&') { if (ch == '&') {
return CPP_AND_OP; return CPP_AND_OP;
} else { } else {
if (ch == '=') if (ch == '=')
return CPP_AND_ASSIGN; return CPP_AND_ASSIGN;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '&'; return '&';
} }
} }
case '<': case '<':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '<') { if (ch == '<') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') if (ch == '=')
return CPP_LEFT_ASSIGN; return CPP_LEFT_ASSIGN;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return CPP_LEFT_OP; return CPP_LEFT_OP;
} }
} else { } else {
@ -663,50 +663,50 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
else if (ch == ':') else if (ch == ':')
return CPP_LEFT_BRACKET; return CPP_LEFT_BRACKET;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '<'; return '<';
} }
} }
} }
case '>': case '>':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '>') { if (ch == '>') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') if (ch == '=')
return CPP_RIGHT_ASSIGN; return CPP_RIGHT_ASSIGN;
else{ else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return CPP_RIGHT_OP; return CPP_RIGHT_OP;
} }
} else { } else {
if (ch == '=') { if (ch == '=') {
return CPP_GE_OP; return CPP_GE_OP;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '>'; return '>';
} }
} }
case '.': case '.':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return pp->lFloatConst(yylvalpp->name, 0, '.', yylvalpp); return pp->lFloatConst(ppToken->name, 0, '.', ppToken);
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '.'; return '.';
} }
case '/': case '/':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '/') { if (ch == '/') {
do { do {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\\') { if (ch == '\\') {
// allow an escaped newline, otherwise escapes in comments are meaningless // allow an escaped newline, otherwise escapes in comments are meaningless
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\r' || ch == '\n') { if (ch == '\r' || ch == '\n') {
int nextch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); int nextch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\r' && nextch == '\n') if (ch == '\r' && nextch == '\n')
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
else else
ch = nextch; ch = nextch;
} }
@ -717,21 +717,21 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
return '\n'; return '\n';
} else if (ch == '*') { } else if (ch == '*') {
int nlcount = 0; int nlcount = 0;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
do { do {
while (ch != '*') { while (ch != '*') {
if (ch == '\n') if (ch == '\n')
nlcount++; nlcount++;
if (ch == EOF) { if (ch == EOF) {
pp->parseContext.error(yylvalpp->loc, "EOF in comment", "comment", ""); pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
return EOF; return EOF;
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} }
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == EOF) { if (ch == EOF) {
pp->parseContext.error(yylvalpp->loc, "EOF in comment", "comment", ""); pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
return EOF; return EOF;
} }
@ -742,15 +742,15 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
} else if (ch == '=') { } else if (ch == '=') {
return CPP_DIV_ASSIGN; return CPP_DIV_ASSIGN;
} else { } else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp); pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '/'; return '/';
} }
break; break;
case '"': case '"':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
while (ch != '"' && ch != '\n' && ch != EOF) { while (ch != '"' && ch != '\n' && ch != EOF) {
if (ch == '\\') { if (ch == '\\') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\n' || ch == EOF) { if (ch == '\n' || ch == EOF) {
break; break;
} }
@ -758,41 +758,41 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
if (len < TPpToken::maxTokenLength) { if (len < TPpToken::maxTokenLength) {
tokenText[len] = ch; tokenText[len] = ch;
len++; len++;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp); ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} else } else
break; break;
}; };
tokenText[len] = '\0'; tokenText[len] = '\0';
if (ch == '"') { if (ch == '"') {
yylvalpp->atom = pp->LookUpAddString(tokenText); ppToken->atom = pp->LookUpAddString(tokenText);
return CPP_STRCONSTANT; return CPP_STRCONSTANT;
} else { } else {
pp->parseContext.error(yylvalpp->loc, "end of line in string", "string", ""); pp->parseContext.error(ppToken->loc, "end of line in string", "string", "");
return CPP_ERROR_SY; return CPP_ERROR_SY;
} }
} }
} }
} // byte_scan } // byte_scan
const char* TPpContext::tokenize(TPpToken* yylvalpp) const char* TPpContext::tokenize(TPpToken* ppToken)
{ {
int token = '\n'; int token = '\n';
for(;;) { for(;;) {
const char* tokenString = 0; const char* tokenString = 0;
token = currentInput->scan(this, currentInput, yylvalpp); token = currentInput->scan(this, currentInput, ppToken);
yylvalpp->ppToken = token; ppToken->token = token;
if (check_EOF(token)) if (check_EOF(token))
return 0; return 0;
if (token == '#') { if (token == '#') {
if (previous_token == '\n' || previous_token == 0) { if (previous_token == '\n' || previous_token == 0) {
token = readCPPline(yylvalpp); token = readCPPline(ppToken);
if (check_EOF(token)) if (check_EOF(token))
return 0; return 0;
continue; continue;
} else { } else {
parseContext.error(yylvalpp->loc, "preprocessor directive cannot be preceded by another token", "#", ""); parseContext.error(ppToken->loc, "preprocessor directive cannot be preceded by another token", "#", "");
return 0; return 0;
} }
} }
@ -804,14 +804,14 @@ const char* TPpContext::tokenize(TPpToken* yylvalpp)
notAVersionToken = true; notAVersionToken = true;
// expand macros // expand macros
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->atom, yylvalpp, 0) == 1) if (token == CPP_IDENTIFIER && MacroExpand(ppToken->atom, ppToken, 0) == 1)
continue; continue;
if (token == CPP_IDENTIFIER) if (token == CPP_IDENTIFIER)
tokenString = GetAtomString(yylvalpp->atom); tokenString = GetAtomString(ppToken->atom);
else if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT || else if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT) token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT)
tokenString = yylvalpp->name; tokenString = ppToken->name;
else else
tokenString = GetAtomString(token); tokenString = GetAtomString(token);

View file

@ -243,7 +243,7 @@ void TPpContext::DeleteTokenStream(TokenStream *pTok)
* *
*/ */
void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp) void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * ppToken)
{ {
const char *s; const char *s;
char *str = NULL; char *str = NULL;
@ -256,7 +256,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
case CPP_IDENTIFIER: case CPP_IDENTIFIER:
case CPP_TYPEIDENTIFIER: case CPP_TYPEIDENTIFIER:
case CPP_STRCONSTANT: case CPP_STRCONSTANT:
s = GetAtomString(yylvalpp->atom); s = GetAtomString(ppToken->atom);
while (*s) while (*s)
lAddByte(pTok, (unsigned char) *s++); lAddByte(pTok, (unsigned char) *s++);
lAddByte(pTok, 0); lAddByte(pTok, 0);
@ -265,7 +265,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
case CPP_UINTCONSTANT: case CPP_UINTCONSTANT:
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT: case CPP_DOUBLECONSTANT:
str = yylvalpp->name; str = ppToken->name;
while (*str){ while (*str){
lAddByte(pTok, (unsigned char) *str); lAddByte(pTok, (unsigned char) *str);
str++; str++;
@ -273,7 +273,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
lAddByte(pTok, 0); lAddByte(pTok, 0);
break; break;
case '(': case '(':
lAddByte(pTok, (unsigned char)(yylvalpp->ival ? 1 : 0)); lAddByte(pTok, (unsigned char)(ppToken->ival ? 1 : 0));
default: default:
break; break;
} }
@ -297,7 +297,7 @@ void TPpContext::RewindTokenStream(TokenStream *pTok)
* *
*/ */
int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp) int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
{ {
//TODO: PP: why is this different than byte_scan //TODO: PP: why is this different than byte_scan
@ -306,7 +306,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
char ch; char ch;
ltoken = lReadByte(pTok); ltoken = lReadByte(pTok);
yylvalpp->loc = parseContext.currentLoc; ppToken->loc = parseContext.currentLoc;
if (ltoken >= 0) { if (ltoken >= 0) {
if (ltoken > 127) if (ltoken > 127)
ltoken += 128; ltoken += 128;
@ -325,13 +325,13 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
parseContext.error(yylvalpp->loc,"name too long", "", ""); parseContext.error(ppToken->loc,"name too long", "", "");
break; break;
} }
} }
tokenText[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
yylvalpp->atom = LookUpAddString(tokenText); ppToken->atom = LookUpAddString(tokenText);
return CPP_IDENTIFIER; return CPP_IDENTIFIER;
break; break;
case CPP_STRCONSTANT: case CPP_STRCONSTANT:
@ -344,7 +344,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
} }
tokenText[len] = 0; tokenText[len] = 0;
yylvalpp->atom = LookUpAddString(tokenText); ppToken->atom = LookUpAddString(tokenText);
break; break;
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT: case CPP_DOUBLECONSTANT:
@ -357,14 +357,14 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
parseContext.error(yylvalpp->loc,"float literal too long", "", ""); parseContext.error(ppToken->loc,"float literal too long", "", "");
break; break;
} }
} }
tokenText[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
strcpy(yylvalpp->name, tokenText); strcpy(ppToken->name, tokenText);
yylvalpp->dval = atof(yylvalpp->name); ppToken->dval = atof(ppToken->name);
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
case CPP_UINTCONSTANT: case CPP_UINTCONSTANT:
@ -377,17 +377,17 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++; len++;
ch = lReadByte(pTok); ch = lReadByte(pTok);
} else { } else {
parseContext.error(yylvalpp->loc,"integer literal too long", "", ""); parseContext.error(ppToken->loc,"integer literal too long", "", "");
break; break;
} }
} }
tokenText[len] = '\0'; tokenText[len] = '\0';
assert(ch == '\0'); assert(ch == '\0');
strcpy(yylvalpp->name,tokenText); strcpy(ppToken->name,tokenText);
yylvalpp->ival = atoi(yylvalpp->name); ppToken->ival = atoi(ppToken->name);
break; break;
case '(': case '(':
yylvalpp->ival = lReadByte(pTok); ppToken->ival = lReadByte(pTok);
break; break;
} }
return ltoken; return ltoken;
@ -395,9 +395,9 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
return EOF; return EOF;
} // ReadToken } // ReadToken
int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * yylvalpp) int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * ppToken)
{ {
int token = pp->ReadToken(in->tokens, yylvalpp); int token = pp->ReadToken(in->tokens, ppToken);
int (*final)(TPpContext *); int (*final)(TPpContext *);
if (token == '\n') { if (token == '\n') {
in->base.line++; in->base.line++;
@ -411,7 +411,7 @@ int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * yylvalp
if (final && !final(pp)) if (final && !final(pp))
return -1; return -1;
return pp->currentInput->scan(pp, pp->currentInput, yylvalpp); return pp->currentInput->scan(pp, pp->currentInput, ppToken);
} }
int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *)) int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpContext *))
@ -430,10 +430,10 @@ int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpC
return 1; return 1;
} }
int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * yylvalpp) int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * ppToken)
{ {
int token = t->token; int token = t->token;
*yylvalpp = t->lval; *ppToken = t->lval;
pp->currentInput = t->base.prev; pp->currentInput = t->base.prev;
free(t); free(t);
return token; return token;
@ -441,12 +441,12 @@ int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * yylvalpp)
typedef int (*scanFnPtr_t); typedef int (*scanFnPtr_t);
void TPpContext::UngetToken(int token, TPpToken * yylvalpp) void TPpContext::UngetToken(int token, TPpToken * ppToken)
{ {
UngotToken *t = (UngotToken *) malloc(sizeof(UngotToken)); UngotToken *t = (UngotToken *) malloc(sizeof(UngotToken));
memset(t, 0, sizeof(UngotToken)); memset(t, 0, sizeof(UngotToken));
t->token = token; t->token = token;
t->lval = *yylvalpp; t->lval = *ppToken;
t->base.scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token; t->base.scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token;
t->base.prev = currentInput; t->base.prev = currentInput;
t->base.name = currentInput->name; t->base.name = currentInput->name;
@ -455,28 +455,28 @@ void TPpContext::UngetToken(int token, TPpToken * yylvalpp)
} }
void TPpContext::DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * yylvalpp) void TPpContext::DumpTokenStream(FILE *fp, TokenStream *s, TPpToken * ppToken)
{ {
int token; int token;
if (fp == 0) fp = stdout; if (fp == 0) fp = stdout;
RewindTokenStream(s); RewindTokenStream(s);
while ((token = ReadToken(s, yylvalpp)) > 0) { while ((token = ReadToken(s, ppToken)) > 0) {
switch (token) { switch (token) {
case CPP_IDENTIFIER: case CPP_IDENTIFIER:
case CPP_TYPEIDENTIFIER: case CPP_TYPEIDENTIFIER:
printf("%s ", GetAtomString(yylvalpp->atom)); printf("%s ", GetAtomString(ppToken->atom));
break; break;
case CPP_STRCONSTANT: case CPP_STRCONSTANT:
printf("\"%s\"", GetAtomString(yylvalpp->atom)); printf("\"%s\"", GetAtomString(ppToken->atom));
break; break;
case CPP_FLOATCONSTANT: case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT: case CPP_DOUBLECONSTANT:
printf("%g9.6 ", yylvalpp->dval); printf("%g9.6 ", ppToken->dval);
break; break;
case CPP_INTCONSTANT: case CPP_INTCONSTANT:
case CPP_UINTCONSTANT: case CPP_UINTCONSTANT:
printf("%d ", yylvalpp->ival); printf("%d ", ppToken->ival);
break; break;
default: default:
if (token >= 127) if (token >= 127)