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;
parserToken->sType.lex.loc = loc;
switch (ppToken.ppToken) {
switch (ppToken.token) {
case ';': afterType = false; return SEMICOLON;
case ',': afterType = false; return COMMA;
case ':': return COLON;

View File

@ -139,56 +139,56 @@ int TPpContext::FinalCPP()
return 1;
}
int TPpContext::CPPdefine(TPpToken * yylvalpp)
int TPpContext::CPPdefine(TPpToken * ppToken)
{
int token, atom, args[maxMacroArgs], argc;
MacroSymbol mac;
Symbol *symb;
memset(&mac, 0, sizeof(mac));
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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;
}
atom = yylvalpp->atom;
token = currentInput->scan(this, currentInput, yylvalpp);
if (token == '(' && !yylvalpp->ival) {
atom = ppToken->atom;
token = currentInput->scan(this, currentInput, ppToken);
if (token == '(' && !ppToken->ival) {
// gather arguments
argc = 0;
do {
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (argc == 0 && token == ')')
break;
if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "bad argument", "#define", "");
parseContext.error(ppToken->loc, "bad argument", "#define", "");
return token;
}
if (argc < maxMacroArgs)
args[argc++] = yylvalpp->atom;
token = currentInput->scan(this, currentInput, yylvalpp);
args[argc++] = ppToken->atom;
token = currentInput->scan(this, currentInput, ppToken);
} while (token == ',');
if (token != ')') {
parseContext.error(yylvalpp->loc, "missing parenthesis", "#define", "");
parseContext.error(ppToken->loc, "missing parenthesis", "#define", "");
return token;
}
mac.argc = argc;
mac.args = (int*)mem_Alloc(pool, 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);
while (token != '\n') {
while (token == '\\') {
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (token == '\n')
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
else
RecordToken(mac.body, '\\', yylvalpp);
RecordToken(mac.body, '\\', ppToken);
}
RecordToken(mac.body, token, yylvalpp);
token = currentInput->scan(this, currentInput, yylvalpp);
RecordToken(mac.body, token, ppToken);
token = currentInput->scan(this, currentInput, ppToken);
};
symb = LookUpSymbol(atom);
@ -204,12 +204,12 @@ int TPpContext::CPPdefine(TPpToken * yylvalpp)
RewindTokenStream(mac.body);
do {
int old_lval, old_token;
old_token = ReadToken(symb->mac.body, yylvalpp);
old_lval = yylvalpp->ival;
token = ReadToken(mac.body, yylvalpp);
if (token != old_token || yylvalpp->ival != old_lval) {
old_token = ReadToken(symb->mac.body, ppToken);
old_lval = ppToken->ival;
token = ReadToken(mac.body, ppToken);
if (token != old_token || ppToken->ival != old_lval) {
error:
parseContext.error(yylvalpp->loc, "Macro Redefined", "#define", GetAtomString(atom));
parseContext.error(ppToken->loc, "Macro Redefined", "#define", GetAtomString(atom));
break;
}
} while (token > 0);
@ -222,28 +222,28 @@ error:
return '\n';
} // 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;
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;
}
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;
}
symb = LookUpSymbol(yylvalpp->atom);
symb = LookUpSymbol(ppToken->atom);
if (symb) {
symb->mac.undef = 1;
}
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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;
} // CPPundef
@ -253,25 +253,25 @@ int TPpContext::CPPundef(TPpToken * yylvalpp)
** #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 depth = 0;
int token = currentInput->scan(this, currentInput, yylvalpp);
int token = currentInput->scan(this, currentInput, ppToken);
while (token > 0) {
if (token != '#') {
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;
}
if ((token = currentInput->scan(this, currentInput, yylvalpp)) != CPP_IDENTIFIER)
if ((token = currentInput->scan(this, currentInput, ppToken)) != CPP_IDENTIFIER)
continue;
atom = yylvalpp->atom;
atom = ppToken->atom;
if (atom == ifAtom || atom == ifdefAtom || atom == ifndefAtom) {
depth++;
ifdepth++;
@ -290,11 +290,11 @@ int TPpContext::CPPelse(int matchelse, TPpToken * yylvalpp)
} else if (matchelse && depth == 0) {
if (atom == elseAtom ) {
// found the #else we are looking for
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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')
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
break;
} else if (atom == elifAtom) {
@ -306,10 +306,10 @@ int TPpContext::CPPelse(int matchelse, TPpToken * yylvalpp)
--elsetracker;
}
return CPPif (yylvalpp);
return CPPif (ppToken);
}
} else if ((atom == elseAtom) && (!ChkCorrectElseNesting()))
parseContext.error(yylvalpp->loc, "#else after #else", "#else", "");
parseContext.error(ppToken->loc, "#else after #else", "#else", "");
}; // end while
return token;
@ -382,43 +382,43 @@ struct tunops {
#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;
Symbol *s;
if (token == CPP_IDENTIFIER) {
if (yylvalpp->atom == definedAtom) {
if (ppToken->atom == definedAtom) {
bool needclose = 0;
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (token == '(') {
needclose = true;
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
if (token != CPP_IDENTIFIER) {
parseContext.error(yylvalpp->loc, "incorrect directive, expected identifier", "preprocessor", "");
parseContext.error(ppToken->loc, "incorrect directive, expected identifier", "preprocessor", "");
*err = 1;
*res = 0;
return token;
}
*res = (s = LookUpSymbol(yylvalpp->atom))
*res = (s = LookUpSymbol(ppToken->atom))
? !s->mac.undef : 0;
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (needclose) {
if (token != ')') {
parseContext.error(yylvalpp->loc, "#else after #else", "", "");
parseContext.error(ppToken->loc, "#else after #else", "", "");
*err = 1;
*res = 0;
return token;
}
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
} else {
int macroReturn = MacroExpand(yylvalpp->atom, yylvalpp, 1);
int macroReturn = MacroExpand(ppToken->atom, ppToken, 1);
if (macroReturn == 0) {
parseContext.error(yylvalpp->loc, "can't evaluate expression", "preprocessor", "");
parseContext.error(ppToken->loc, "can't evaluate expression", "preprocessor", "");
*err = 1;
*res = 0;
@ -427,34 +427,34 @@ int TPpContext::eval(int token, int prec, int *res, int *err, TPpToken * yylvalp
if (macroReturn == -1) {
if (parseContext.profile == EEsProfile) {
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 {
parseContext.error(yylvalpp->loc, "undefined macro in expression", "preprocessor", "");
parseContext.error(ppToken->loc, "undefined macro in expression", "preprocessor", "");
*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) {
*res = yylvalpp->ival;
token = currentInput->scan(this, currentInput, yylvalpp);
*res = ppToken->ival;
token = currentInput->scan(this, currentInput, ppToken);
} else if (token == '(') {
token = currentInput->scan(this, currentInput, yylvalpp);
token = eval(token, MIN_PREC, res, err, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, MIN_PREC, res, err, ppToken);
if (!*err) {
if (token != ')') {
parseContext.error(yylvalpp->loc, "expected ')'", "preprocessor", "");
parseContext.error(ppToken->loc, "expected ')'", "preprocessor", "");
*err = 1;
*res = 0;
return token;
}
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
} else {
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;
}
if (i >= 0) {
token = currentInput->scan(this, currentInput, yylvalpp);
token = eval(token, UNARY, res, err, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, UNARY, res, err, ppToken);
*res = unop[i].op(*res);
} else {
parseContext.error(yylvalpp->loc, "", "bad expression", "");
parseContext.error(ppToken->loc, "", "bad expression", "");
*err = 1;
*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)
break;
val = *res;
token = currentInput->scan(this, currentInput, yylvalpp);
token = eval(token, binop[i].prec, res, err, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
token = eval(token, binop[i].prec, res, err, ppToken);
*res = binop[i].op(val, *res);
}
return token;
} // 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;
elsetracker++;
if (! ifdepth++)
ifloc = yylvalpp->loc;
ifloc = ppToken->loc;
if (ifdepth > maxIfNesting) {
parseContext.error(yylvalpp->loc, "maximum nesting depth exceeded", "#if", "");
parseContext.error(ppToken->loc, "maximum nesting depth exceeded", "#if", "");
return 0;
}
token = eval(token, MIN_PREC, &res, &err, yylvalpp);
token = eval(token, MIN_PREC, &res, &err, ppToken);
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')
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
if (!res && !err) {
token = CPPelse(1, yylvalpp);
token = CPPelse(1, ppToken);
}
return token;
} // CPPif
int TPpContext::CPPifdef(int defined, TPpToken * yylvalpp)
int TPpContext::CPPifdef(int defined, TPpToken * ppToken)
{
int token = currentInput->scan(this, currentInput, yylvalpp);
int name = yylvalpp->atom;
int token = currentInput->scan(this, currentInput, ppToken);
int name = ppToken->atom;
if (++ifdepth > maxIfNesting) {
parseContext.error(yylvalpp->loc, "maximum nesting depth exceeded", "#ifdef", "");
parseContext.error(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", "");
return 0;
}
elsetracker++;
if (token != CPP_IDENTIFIER) {
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
parseContext.error(yylvalpp->loc, "must be followed by macro name", "#ifndef", "");
parseContext.error(ppToken->loc, "must be followed by macro name", "#ifndef", "");
} else {
Symbol *s = LookUpSymbol(name);
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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')
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
if (((s && !s->mac.undef) ? 1 : 0) != defined)
token = CPPelse(1, yylvalpp);
token = CPPelse(1, ppToken);
}
return token;
} // CPPifdef
// 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') {
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;
}
else if (token == CPP_INTCONSTANT) {
parseContext.currentLoc.line = atoi(yylvalpp->name);
token = currentInput->scan(this, currentInput, yylvalpp);
parseContext.currentLoc.line = atoi(ppToken->name);
token = currentInput->scan(this, currentInput, ppToken);
if (token == CPP_INTCONSTANT) {
parseContext.currentLoc.string = atoi(yylvalpp->name);
token = currentInput->scan(this, currentInput, yylvalpp);
parseContext.currentLoc.string = atoi(ppToken->name);
token = currentInput->scan(this, currentInput, ppToken);
if (token != '\n')
parseContext.error(parseContext.currentLoc, "cannot be followed by more than two integral literals", "#line", "");
} else if (token == '\n')
@ -572,23 +572,23 @@ int TPpContext::CPPline(TPpToken * yylvalpp)
}
// 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;
TSourceLoc loc = yylvalpp->loc;
TSourceLoc loc = ppToken->loc;
while (token != '\n') {
if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT) {
message.append(yylvalpp->name);
message.append(ppToken->name);
} else if (token == CPP_IDENTIFIER || token == CPP_STRCONSTANT) {
message.append(GetAtomString(yylvalpp->atom));
message.append(GetAtomString(ppToken->atom));
} else {
message.append(GetAtomString(token));
}
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!!!!
parseContext.error(loc, message.c_str(), "#error", "");
@ -596,7 +596,7 @@ int TPpContext::CPPerror(TPpToken * yylvalpp)
return '\n';
}
int TPpContext::CPPpragma(TPpToken * yylvalpp)
int TPpContext::CPPpragma(TPpToken * ppToken)
{
char SrcStrName[2];
char** allTokens;
@ -605,10 +605,10 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
const char* SrcStr;
int i;
int token = currentInput->scan(this, currentInput, yylvalpp);
int token = currentInput->scan(this, currentInput, ppToken);
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;
}
@ -621,7 +621,7 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
}
switch (token) {
case CPP_IDENTIFIER:
SrcStr = GetAtomString(yylvalpp->atom);
SrcStr = GetAtomString(ppToken->atom);
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr);
break;
@ -629,12 +629,12 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
case CPP_UINTCONSTANT:
case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
SrcStr = yylvalpp->name;
SrcStr = ppToken->name;
allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1);
strcpy(allTokens[tokenCount++], SrcStr);
break;
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;
default:
SrcStrName[0] = token;
@ -642,12 +642,12 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
allTokens[tokenCount] = (char*)malloc(2);
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);
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
for (i = 0; i < tokenCount; ++i) {
free (allTokens[i]);
@ -658,151 +658,151 @@ int TPpContext::CPPpragma(TPpToken * yylvalpp)
} // CPPpragma
// 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)
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') {
parseContext.error(yylvalpp->loc, "must be followed by version number", "#version", "");
parseContext.error(ppToken->loc, "must be followed by version number", "#version", "");
return token;
}
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')
return token;
else {
if (yylvalpp->atom != coreAtom &&
yylvalpp->atom != compatibilityAtom &&
yylvalpp->atom != esAtom)
parseContext.error(yylvalpp->loc, "bad profile name; use es, core, or compatibility", "#version", "");
if (ppToken->atom != coreAtom &&
ppToken->atom != compatibilityAtom &&
ppToken->atom != esAtom)
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')
return token;
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;
} // 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];
if (token=='\n') {
parseContext.error(yylvalpp->loc, "extension name not specified", "#extension", "");
parseContext.error(ppToken->loc, "extension name not specified", "#extension", "");
return token;
}
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 != ':') {
parseContext.error(yylvalpp->loc, "':' missing after extension name", "#extension", "");
parseContext.error(ppToken->loc, "':' missing after extension name", "#extension", "");
return token;
}
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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;
}
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')
return token;
else
parseContext.error(yylvalpp->loc, "extra tokens -- expected newline", "#extension","");
parseContext.error(ppToken->loc, "extra tokens -- expected newline", "#extension","");
return token;
} // 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;
if (token == CPP_IDENTIFIER) {
if (yylvalpp->atom == defineAtom) {
token = CPPdefine(yylvalpp);
} else if (yylvalpp->atom == elseAtom) {
if (ppToken->atom == defineAtom) {
token = CPPdefine(ppToken);
} else if (ppToken->atom == elseAtom) {
if (ChkCorrectElseNesting()) {
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') {
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')
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
token = CPPelse(0, yylvalpp);
token = CPPelse(0, ppToken);
} else {
parseContext.error(yylvalpp->loc, "#else after a #else", "#else", "");
parseContext.error(ppToken->loc, "#else after a #else", "#else", "");
ifdepth = 0;
notAVersionToken = true;
return 0;
}
} else if (yylvalpp->atom == elifAtom) {
} else if (ppToken->atom == elifAtom) {
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
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
while (token != '\n')
token = currentInput->scan(this, currentInput, yylvalpp);
token = CPPelse(0, yylvalpp);
} else if (yylvalpp->atom == endifAtom) {
token = currentInput->scan(this, currentInput, ppToken);
token = CPPelse(0, ppToken);
} else if (ppToken->atom == endifAtom) {
elsedepth[elsetracker] = 0;
--elsetracker;
if (! ifdepth)
parseContext.error(yylvalpp->loc, "mismatched statements", "#endif", "");
parseContext.error(ppToken->loc, "mismatched statements", "#endif", "");
else
--ifdepth;
} else if (yylvalpp->atom == ifAtom) {
token = CPPif (yylvalpp);
} else if (yylvalpp->atom == ifdefAtom) {
token = CPPifdef(1, yylvalpp);
} else if (yylvalpp->atom == ifndefAtom) {
token = CPPifdef(0, yylvalpp);
} else if (yylvalpp->atom == lineAtom) {
token = CPPline(yylvalpp);
} else if (yylvalpp->atom == pragmaAtom) {
token = CPPpragma(yylvalpp);
} else if (yylvalpp->atom == undefAtom) {
token = CPPundef(yylvalpp);
} else if (yylvalpp->atom == errorAtom) {
token = CPPerror(yylvalpp);
} else if (yylvalpp->atom == versionAtom) {
token = CPPversion(yylvalpp);
} else if (ppToken->atom == ifAtom) {
token = CPPif (ppToken);
} else if (ppToken->atom == ifdefAtom) {
token = CPPifdef(1, ppToken);
} else if (ppToken->atom == ifndefAtom) {
token = CPPifdef(0, ppToken);
} else if (ppToken->atom == lineAtom) {
token = CPPline(ppToken);
} else if (ppToken->atom == pragmaAtom) {
token = CPPpragma(ppToken);
} else if (ppToken->atom == undefAtom) {
token = CPPundef(ppToken);
} else if (ppToken->atom == errorAtom) {
token = CPPerror(ppToken);
} else if (ppToken->atom == versionAtom) {
token = CPPversion(ppToken);
isVersion = true;
} else if (yylvalpp->atom == extensionAtom) {
token = CPPextension(yylvalpp);
} else if (ppToken->atom == extensionAtom) {
token = CPPextension(ppToken);
} 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) {
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
}
notAVersionToken = ! isVersion;
@ -814,8 +814,8 @@ void TPpContext::FreeMacro(MacroSymbol *s) {
DeleteTokenStream(s->body);
}
int eof_scan(TPpContext*, TPpContext::InputSrc* in, TPpToken* yylvalpp) { return -1; }
void noop(TPpContext*, TPpContext::InputSrc* in, int ch, TPpToken* yylvalpp) { }
int eof_scan(TPpContext*, TPpContext::InputSrc* in, TPpToken* ppToken) { return -1; }
void noop(TPpContext*, TPpContext::InputSrc* in, int ch, TPpToken* ppToken) { }
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;
TokenStream *n;
RewindTokenStream(a);
do {
token = ReadToken(a, yylvalpp);
if (token == CPP_IDENTIFIER && LookUpSymbol(yylvalpp->atom))
token = ReadToken(a, ppToken);
if (token == CPP_IDENTIFIER && LookUpSymbol(ppToken->atom))
break;
} while (token > 0);
if (token <= 0) return a;
n = NewTokenStream("macro arg", 0);
PushEofSrc();
ReadFromTokenStream(a, 0, 0);
while ((token = currentInput->scan(this, currentInput, yylvalpp)) > 0) {
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->atom, yylvalpp, 0) == 1)
while ((token = currentInput->scan(this, currentInput, ppToken)) > 0) {
if (token == CPP_IDENTIFIER && MacroExpand(ppToken->atom, ppToken, 0) == 1)
continue;
RecordToken(n, token, yylvalpp);
RecordToken(n, token, ppToken);
}
PopEofSrc();
DeleteTokenStream(a);
@ -868,20 +868,20 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream *a, TPpToken *
/* macro_scan ---
** 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;
int i;
int token = pp->ReadToken(in->mac->body, yylvalpp);
int token = pp->ReadToken(in->mac->body, ppToken);
if (token == CPP_IDENTIFIER) {
for (i = in->mac->argc-1; i>=0; i--)
if (in->mac->args[i] == yylvalpp->atom)
if (in->mac->args[i] == ppToken->atom)
break;
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);
return pp->currentInput->scan(pp, pp->currentInput, yylvalpp);
return pp->currentInput->scan(pp, pp->currentInput, ppToken);
} // macro_scan
// 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;
strcpy(yylvalpp->name, "0");
yylvalpp->ival = 0;
strcpy(ppToken->name, "0");
ppToken->ival = 0;
// pop input
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.
** 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);
MacroInputSrc *in;
@ -931,25 +931,25 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
int depth = 0;
if (atom == __LINE__Atom) {
yylvalpp->ival = parseContext.currentLoc.line;
sprintf(yylvalpp->name, "%d", yylvalpp->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp);
ppToken->ival = parseContext.currentLoc.line;
sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, ppToken);
return 1;
}
if (atom == __FILE__Atom) {
yylvalpp->ival = parseContext.currentLoc.string;
sprintf(yylvalpp->name, "%d", yylvalpp->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp);
ppToken->ival = parseContext.currentLoc.string;
sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, ppToken);
return 1;
}
if (atom == __VERSION__Atom) {
yylvalpp->ival = parseContext.version;
sprintf(yylvalpp->name, "%d", yylvalpp->ival);
UngetToken(CPP_INTCONSTANT, yylvalpp);
ppToken->ival = parseContext.version;
sprintf(ppToken->name, "%d", ppToken->ival);
UngetToken(CPP_INTCONSTANT, ppToken);
return 1;
}
@ -979,10 +979,10 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
in->base.scan = macro_scan;
in->mac = &sym->mac;
if (sym->mac.args) {
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (token != '(') {
UngetToken(token, yylvalpp);
yylvalpp->atom = atom;
UngetToken(token, ppToken);
ppToken->atom = atom;
return 0;
}
@ -994,9 +994,9 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
do {
depth = 0;
while (1) {
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
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;
}
@ -1004,7 +1004,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
if (depth == 0 && (token == ',' || token == ')')) break;
if (token == '(') depth++;
if (token == ')') depth--;
RecordToken(in->args[i], token, yylvalpp);
RecordToken(in->args[i], token, ppToken);
j=1;
}
if (token == ')') {
@ -1017,26 +1017,26 @@ int TPpContext::MacroExpand(int atom, TPpToken* yylvalpp, int expandUndef)
} while (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 != ')') {
depth=0;
while (token >= 0 && (depth > 0 || token != ')')) {
if (token == ')')
depth--;
token = currentInput->scan(this, currentInput, yylvalpp);
token = currentInput->scan(this, currentInput, ppToken);
if (token == '(')
depth++;
}
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;
}
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++) {
in->args[i] = PrescanMacroArg(in->args[i], yylvalpp);
in->args[i] = PrescanMacroArg(in->args[i], ppToken);
}
}
#if 0

View File

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

View File

@ -98,7 +98,7 @@ int eof_scan(TPpContext*, TPpContext::InputSrc*, TPpToken*)
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).
*/
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;
int declen, exp, ExpSign;
@ -213,7 +213,7 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
if (ch == '.') {
HasDecimalOrExponent = true;
str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) {
declen++;
@ -221,9 +221,9 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
str[len] = ch;
len++;str_len++;
}
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
} else {
parseContext.error(yylvalpp->loc, "float literal too long", "", "");
parseContext.error(ppToken->loc, "float literal too long", "", "");
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') {
HasDecimalOrExponent = true;
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;
} else {
ExpSign = 1;
str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
if (ch == '+') {
str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
} else if (ch == '-') {
ExpSign = -1;
str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
}
if (ch >= '0' && ch <= '9') {
while (ch >= '0' && ch <= '9') {
if (len < TPpToken::maxTokenLength) {
exp = exp*10 + ch - '0';
str[len++]=ch;
ch = currentInput->getch(this, currentInput, yylvalpp);
ch = currentInput->getch(this, currentInput, ppToken);
} else {
parseContext.error(yylvalpp->loc, "float literal too long", "", "");
parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1;
}
}
} else {
parseContext.error(yylvalpp->loc, "bad character in float exponent", "", "");
parseContext.error(ppToken->loc, "bad character in float exponent", "", "");
}
exp *= ExpSign;
}
}
if (len == 0) {
yylvalpp->dval = 0.0;
ppToken->dval = 0.0;
strcpy(str, "0.0");
} else {
if (ch == 'l' || ch == 'L') {
if (! HasDecimalOrExponent)
parseContext.error(yylvalpp->loc, "float literal needs a decimal point or exponent", "", "");
int ch2 = currentInput->getch(this, currentInput, yylvalpp);
parseContext.error(ppToken->loc, "float literal needs a decimal point or exponent", "", "");
int ch2 = currentInput->getch(this, currentInput, ppToken);
if (ch2 != 'f' && ch2 != 'F') {
currentInput->ungetch(this, currentInput, ch2, yylvalpp);
currentInput->ungetch(this, currentInput, ch, yylvalpp);
currentInput->ungetch(this, currentInput, ch2, ppToken);
currentInput->ungetch(this, currentInput, ch, ppToken);
} else {
if (len < TPpToken::maxTokenLength) {
str[len++] = ch;
str[len++] = ch2;
isDouble = 1;
} else {
parseContext.error(yylvalpp->loc, "float literal too long", "", "");
parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1;
}
}
} else if (ch == 'f' || ch == 'F') {
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)
str[len++] = ch;
else {
parseContext.error(yylvalpp->loc, "float literal too long", "", "");
parseContext.error(ppToken->loc, "float literal too long", "", "");
len = 1,str_len=1;
}
} else
currentInput->ungetch(this, currentInput, ch, yylvalpp);
currentInput->ungetch(this, currentInput, ch, ppToken);
str[len]='\0';
yylvalpp->dval = strtod(str, 0);
ppToken->dval = strtod(str, 0);
}
// Suffix:
strcpy(yylvalpp->name, str);
strcpy(ppToken->name, str);
if (isDouble)
return CPP_DOUBLECONSTANT;
@ -316,7 +316,7 @@ int TPpContext::lFloatConst(char *str, int len, int ch, TPpToken * yylvalpp)
///////////////////////////////////////// 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];
int AlreadyComplained = 0;
@ -324,15 +324,15 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
unsigned ival = 0;
for (;;) {
yylvalpp->ival = 0;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ppToken->ival = 0;
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
while (ch == ' ' || ch == '\t' || ch == '\r') {
yylvalpp->ival = 1;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ppToken->ival = 1;
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
}
yylvalpp->loc = pp->parseContext.currentLoc;
ppToken->loc = pp->parseContext.currentLoc;
len = 0;
switch (ch) {
default:
@ -354,24 +354,24 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
do {
if (ch == '\\') {
// escaped character
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
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')
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
else
ch = nextch;
} else
pp->parseContext.error(yylvalpp->loc, "can only escape newlines", "\\", "");
pp->parseContext.error(ppToken->loc, "can only escape newlines", "\\", "");
} else if (len < TPpToken::maxTokenLength) {
tokenText[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} else {
if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "name too long", "", "");
pp->parseContext.error(ppToken->loc, "name too long", "", "");
AlreadyComplained = 1;
}
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
}
} while ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
@ -380,19 +380,19 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ch == '\\');
tokenText[len] = '\0';
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
yylvalpp->atom = pp->LookUpAddString(tokenText);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
ppToken->atom = pp->LookUpAddString(tokenText);
return CPP_IDENTIFIER;
case '0':
yylvalpp->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ppToken->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == 'x' || ch == 'X') {
// must be hexidecimal
bool isUnsigned = false;
yylvalpp->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ppToken->name[len++] = ch;
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f'))
@ -400,7 +400,7 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ival = 0;
do {
if (ival <= 0x0fffffff) {
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
if (ch >= '0' && ch <= '9') {
ii = ch - '0';
} 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') {
ii = ch - 'a' + 10;
} 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;
} else {
if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "hexidecimal literal too big", "", "");
pp->parseContext.error(ppToken->loc, "hexidecimal literal too big", "", "");
AlreadyComplained = 1;
}
ival = 0xffffffff;
}
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while ((ch >= '0' && ch <= '9') ||
(ch >= 'A' && ch <= 'F') ||
(ch >= 'a' && ch <= 'f'));
} 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 (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
isUnsigned = true;
} else
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
yylvalpp->name[len] = '\0';
yylvalpp->ival = (int)ival;
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
ppToken->name[len] = '\0';
ppToken->ival = (int)ival;
if (isUnsigned)
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
while (ch >= '0' && ch <= '7') {
if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", "");
pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
if (ival <= 0x1fffffff) {
@ -458,7 +458,7 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
ival = (ival << 3) | ii;
} else
octalOverflow = true;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
}
// could be part of a float...
@ -466,33 +466,33 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
nonOctal = true;
do {
if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", "");
pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while (ch >= '0' && ch <= '9');
}
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...
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 (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
isUnsigned = true;
} else
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
yylvalpp->name[len] = '\0';
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
ppToken->name[len] = '\0';
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)
return CPP_UINTCONSTANT;
@ -506,38 +506,38 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
do {
if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
else if (! AlreadyComplained) {
pp->parseContext.error(yylvalpp->loc, "numeric literal too long", "", "");
pp->parseContext.error(ppToken->loc, "numeric literal too long", "", "");
AlreadyComplained = 1;
}
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} while (ch >= '0' && ch <= '9');
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 {
// Finish handling signed and unsigned integers
int numericLen = len;
int uint = 0;
if (ch == 'u' || ch == 'U') {
if (len < TPpToken::maxTokenLength)
yylvalpp->name[len++] = ch;
ppToken->name[len++] = ch;
uint = 1;
} 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;
for (ii = 0; ii < numericLen; ii++) {
ch = yylvalpp->name[ii] - '0';
ch = ppToken->name[ii] - '0';
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;
break;
} else
ival = ival * 10 + ch;
}
yylvalpp->ival = (int)ival;
ppToken->ival = (int)ival;
if (uint)
return CPP_UINTCONSTANT;
@ -546,112 +546,112 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
}
break;
case '-':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '-') {
return CPP_DEC_OP;
} else if (ch == '=') {
return CPP_SUB_ASSIGN;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '-';
}
case '+':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '+') {
return CPP_INC_OP;
} else if (ch == '=') {
return CPP_ADD_ASSIGN;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '+';
}
case '*':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') {
return CPP_MUL_ASSIGN;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '*';
}
case '%':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') {
return CPP_MOD_ASSIGN;
} else if (ch == '>'){
return CPP_RIGHT_BRACE;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '%';
}
case ':':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '>') {
return CPP_RIGHT_BRACKET;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return ':';
}
case '^':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '^') {
return CPP_XOR_OP;
} else {
if (ch == '=')
return CPP_XOR_ASSIGN;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '^';
}
}
case '=':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') {
return CPP_EQ_OP;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '=';
}
case '!':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=') {
return CPP_NE_OP;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '!';
}
case '|':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '|') {
return CPP_OR_OP;
} else {
if (ch == '=')
return CPP_OR_ASSIGN;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '|';
}
}
case '&':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '&') {
return CPP_AND_OP;
} else {
if (ch == '=')
return CPP_AND_ASSIGN;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '&';
}
}
case '<':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '<') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=')
return CPP_LEFT_ASSIGN;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return CPP_LEFT_OP;
}
} else {
@ -663,50 +663,50 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
else if (ch == ':')
return CPP_LEFT_BRACKET;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '<';
}
}
}
case '>':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '>') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '=')
return CPP_RIGHT_ASSIGN;
else{
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return CPP_RIGHT_OP;
}
} else {
if (ch == '=') {
return CPP_GE_OP;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '>';
}
}
case '.':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch >= '0' && ch <= '9') {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
return pp->lFloatConst(yylvalpp->name, 0, '.', yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return pp->lFloatConst(ppToken->name, 0, '.', ppToken);
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '.';
}
case '/':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '/') {
do {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\\') {
// 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') {
int nextch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
int nextch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\r' && nextch == '\n')
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
else
ch = nextch;
}
@ -717,21 +717,21 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
return '\n';
} else if (ch == '*') {
int nlcount = 0;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
do {
while (ch != '*') {
if (ch == '\n')
nlcount++;
if (ch == EOF) {
pp->parseContext.error(yylvalpp->loc, "EOF in comment", "comment", "");
pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
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) {
pp->parseContext.error(yylvalpp->loc, "EOF in comment", "comment", "");
pp->parseContext.error(ppToken->loc, "EOF in comment", "comment", "");
return EOF;
}
@ -742,15 +742,15 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
} else if (ch == '=') {
return CPP_DIV_ASSIGN;
} else {
pp->currentInput->ungetch(pp, pp->currentInput, ch, yylvalpp);
pp->currentInput->ungetch(pp, pp->currentInput, ch, ppToken);
return '/';
}
break;
case '"':
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
while (ch != '"' && ch != '\n' && ch != EOF) {
if (ch == '\\') {
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
if (ch == '\n' || ch == EOF) {
break;
}
@ -758,41 +758,41 @@ int TPpContext::byte_scan(TPpContext* pp, InputSrc *in, TPpToken * yylvalpp)
if (len < TPpToken::maxTokenLength) {
tokenText[len] = ch;
len++;
ch = pp->currentInput->getch(pp, pp->currentInput, yylvalpp);
ch = pp->currentInput->getch(pp, pp->currentInput, ppToken);
} else
break;
};
tokenText[len] = '\0';
if (ch == '"') {
yylvalpp->atom = pp->LookUpAddString(tokenText);
ppToken->atom = pp->LookUpAddString(tokenText);
return CPP_STRCONSTANT;
} 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;
}
}
}
} // byte_scan
const char* TPpContext::tokenize(TPpToken* yylvalpp)
const char* TPpContext::tokenize(TPpToken* ppToken)
{
int token = '\n';
for(;;) {
const char* tokenString = 0;
token = currentInput->scan(this, currentInput, yylvalpp);
yylvalpp->ppToken = token;
token = currentInput->scan(this, currentInput, ppToken);
ppToken->token = token;
if (check_EOF(token))
return 0;
if (token == '#') {
if (previous_token == '\n' || previous_token == 0) {
token = readCPPline(yylvalpp);
token = readCPPline(ppToken);
if (check_EOF(token))
return 0;
continue;
} 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;
}
}
@ -804,14 +804,14 @@ const char* TPpContext::tokenize(TPpToken* yylvalpp)
notAVersionToken = true;
// expand macros
if (token == CPP_IDENTIFIER && MacroExpand(yylvalpp->atom, yylvalpp, 0) == 1)
if (token == CPP_IDENTIFIER && MacroExpand(ppToken->atom, ppToken, 0) == 1)
continue;
if (token == CPP_IDENTIFIER)
tokenString = GetAtomString(yylvalpp->atom);
tokenString = GetAtomString(ppToken->atom);
else if (token == CPP_INTCONSTANT || token == CPP_UINTCONSTANT ||
token == CPP_FLOATCONSTANT || token == CPP_DOUBLECONSTANT)
tokenString = yylvalpp->name;
tokenString = ppToken->name;
else
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;
char *str = NULL;
@ -256,7 +256,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
case CPP_IDENTIFIER:
case CPP_TYPEIDENTIFIER:
case CPP_STRCONSTANT:
s = GetAtomString(yylvalpp->atom);
s = GetAtomString(ppToken->atom);
while (*s)
lAddByte(pTok, (unsigned char) *s++);
lAddByte(pTok, 0);
@ -265,7 +265,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
case CPP_UINTCONSTANT:
case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
str = yylvalpp->name;
str = ppToken->name;
while (*str){
lAddByte(pTok, (unsigned char) *str);
str++;
@ -273,7 +273,7 @@ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken * yylvalpp)
lAddByte(pTok, 0);
break;
case '(':
lAddByte(pTok, (unsigned char)(yylvalpp->ival ? 1 : 0));
lAddByte(pTok, (unsigned char)(ppToken->ival ? 1 : 0));
default:
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
@ -306,7 +306,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
char ch;
ltoken = lReadByte(pTok);
yylvalpp->loc = parseContext.currentLoc;
ppToken->loc = parseContext.currentLoc;
if (ltoken >= 0) {
if (ltoken > 127)
ltoken += 128;
@ -325,13 +325,13 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++;
ch = lReadByte(pTok);
} else {
parseContext.error(yylvalpp->loc,"name too long", "", "");
parseContext.error(ppToken->loc,"name too long", "", "");
break;
}
}
tokenText[len] = '\0';
assert(ch == '\0');
yylvalpp->atom = LookUpAddString(tokenText);
ppToken->atom = LookUpAddString(tokenText);
return CPP_IDENTIFIER;
break;
case CPP_STRCONSTANT:
@ -344,7 +344,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
}
tokenText[len] = 0;
yylvalpp->atom = LookUpAddString(tokenText);
ppToken->atom = LookUpAddString(tokenText);
break;
case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
@ -357,14 +357,14 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++;
ch = lReadByte(pTok);
} else {
parseContext.error(yylvalpp->loc,"float literal too long", "", "");
parseContext.error(ppToken->loc,"float literal too long", "", "");
break;
}
}
tokenText[len] = '\0';
assert(ch == '\0');
strcpy(yylvalpp->name, tokenText);
yylvalpp->dval = atof(yylvalpp->name);
strcpy(ppToken->name, tokenText);
ppToken->dval = atof(ppToken->name);
break;
case CPP_INTCONSTANT:
case CPP_UINTCONSTANT:
@ -377,17 +377,17 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
len++;
ch = lReadByte(pTok);
} else {
parseContext.error(yylvalpp->loc,"integer literal too long", "", "");
parseContext.error(ppToken->loc,"integer literal too long", "", "");
break;
}
}
tokenText[len] = '\0';
assert(ch == '\0');
strcpy(yylvalpp->name,tokenText);
yylvalpp->ival = atoi(yylvalpp->name);
strcpy(ppToken->name,tokenText);
ppToken->ival = atoi(ppToken->name);
break;
case '(':
yylvalpp->ival = lReadByte(pTok);
ppToken->ival = lReadByte(pTok);
break;
}
return ltoken;
@ -395,9 +395,9 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *yylvalpp)
return EOF;
} // 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 *);
if (token == '\n') {
in->base.line++;
@ -411,7 +411,7 @@ int TPpContext::scan_token(TPpContext* pp, TokenInputSrc *in, TPpToken * yylvalp
if (final && !final(pp))
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 *))
@ -430,10 +430,10 @@ int TPpContext::ReadFromTokenStream(TokenStream *ts, int name, int (*final)(TPpC
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;
*yylvalpp = t->lval;
*ppToken = t->lval;
pp->currentInput = t->base.prev;
free(t);
return token;
@ -441,12 +441,12 @@ int TPpContext::reget_token(TPpContext* pp, UngotToken *t, TPpToken * yylvalpp)
typedef int (*scanFnPtr_t);
void TPpContext::UngetToken(int token, TPpToken * yylvalpp)
void TPpContext::UngetToken(int token, TPpToken * ppToken)
{
UngotToken *t = (UngotToken *) malloc(sizeof(UngotToken));
memset(t, 0, sizeof(UngotToken));
t->token = token;
t->lval = *yylvalpp;
t->lval = *ppToken;
t->base.scan = (int(*)(TPpContext*, struct InputSrc *, TPpToken *))reget_token;
t->base.prev = currentInput;
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;
if (fp == 0) fp = stdout;
RewindTokenStream(s);
while ((token = ReadToken(s, yylvalpp)) > 0) {
while ((token = ReadToken(s, ppToken)) > 0) {
switch (token) {
case CPP_IDENTIFIER:
case CPP_TYPEIDENTIFIER:
printf("%s ", GetAtomString(yylvalpp->atom));
printf("%s ", GetAtomString(ppToken->atom));
break;
case CPP_STRCONSTANT:
printf("\"%s\"", GetAtomString(yylvalpp->atom));
printf("\"%s\"", GetAtomString(ppToken->atom));
break;
case CPP_FLOATCONSTANT:
case CPP_DOUBLECONSTANT:
printf("%g9.6 ", yylvalpp->dval);
printf("%g9.6 ", ppToken->dval);
break;
case CPP_INTCONSTANT:
case CPP_UINTCONSTANT:
printf("%d ", yylvalpp->ival);
printf("%d ", ppToken->ival);
break;
default:
if (token >= 127)