Non functional: Simplify accesses to the parseContext in the flex file.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20315 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-01-24 22:33:43 +00:00
parent 6dc6df377d
commit 62b51a2b7e

View File

@ -489,7 +489,9 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
void yyerror(char *s) void yyerror(char *s)
{ {
if (((TParseContext *)cpp->pC)->AfterEOF) { TParseContext& parseContext = *((TParseContext *)cpp->pC);
if (parseContext.AfterEOF) {
if (cpp->tokensBeforeEOF == 1) { if (cpp->tokensBeforeEOF == 1) {
GlobalParseContext->error(yylineno, "syntax error", "pre-mature EOF", s, ""); GlobalParseContext->error(yylineno, "syntax error", "pre-mature EOF", s, "");
GlobalParseContext->recover(); GlobalParseContext->recover();
@ -554,23 +556,31 @@ extern "C" {
void CPPDebugLogMsg(const char *msg) void CPPDebugLogMsg(const char *msg)
{ {
((TParseContext *)cpp->pC)->infoSink.debug.message(EPrefixNone, msg); TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.infoSink.debug.message(EPrefixNone, msg);
} }
void CPPWarningToInfoLog(const char *msg) void CPPWarningToInfoLog(const char *msg)
{ {
((TParseContext *)cpp->pC)->infoSink.info.message(EPrefixWarning, msg, yylineno); TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.infoSink.info.message(EPrefixWarning, msg, yylineno);
} }
void CPPShInfoLogMsg(const char *msg) void CPPShInfoLogMsg(const char *msg)
{ {
((TParseContext *)cpp->pC)->error(yylineno,"", "",msg,""); TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.error(yylineno,"", "",msg,"");
GlobalParseContext->recover(); GlobalParseContext->recover();
} }
void CPPErrorToInfoLog(char *msg) void CPPErrorToInfoLog(char *msg)
{ {
((TParseContext *)cpp->pC)->error(yylineno, "CPP error:", "",msg,""); TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.error(yylineno, "CPP error:", "",msg,"");
GlobalParseContext->recover(); GlobalParseContext->recover();
} }
@ -609,6 +619,8 @@ void DecLineNumber(void)
void HandlePragma(const char **tokens, int numTokens) void HandlePragma(const char **tokens, int numTokens)
{ {
TParseContext& parseContext = *((TParseContext *)cpp->pC);
if (!strcmp(tokens[0], "optimize")) { if (!strcmp(tokens[0], "optimize")) {
if (numTokens != 4) { if (numTokens != 4) {
CPPShInfoLogMsg("optimize pragma syntax is incorrect"); CPPShInfoLogMsg("optimize pragma syntax is incorrect");
@ -621,9 +633,9 @@ void HandlePragma(const char **tokens, int numTokens)
} }
if (!strcmp(tokens[2], "on")) if (!strcmp(tokens[2], "on"))
((TParseContext *)cpp->pC)->contextPragma.optimize = true; parseContext.contextPragma.optimize = true;
else if (!strcmp(tokens[2], "off")) else if (!strcmp(tokens[2], "off"))
((TParseContext *)cpp->pC)->contextPragma.optimize = false; parseContext.contextPragma.optimize = false;
else { else {
CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'optimize' pragma"); CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'optimize' pragma");
return; return;
@ -645,9 +657,9 @@ void HandlePragma(const char **tokens, int numTokens)
} }
if (!strcmp(tokens[2], "on")) if (!strcmp(tokens[2], "on"))
((TParseContext *)cpp->pC)->contextPragma.debug = true; parseContext.contextPragma.debug = true;
else if (!strcmp(tokens[2], "off")) else if (!strcmp(tokens[2], "off"))
((TParseContext *)cpp->pC)->contextPragma.debug = false; parseContext.contextPragma.debug = false;
else { else {
CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'debug' pragma"); CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'debug' pragma");
return; return;
@ -662,14 +674,14 @@ void HandlePragma(const char **tokens, int numTokens)
#ifdef PRAGMA_TABLE #ifdef PRAGMA_TABLE
// //
// implementation specific pragma // implementation specific pragma
// use ((TParseContext *)cpp->pC)->contextPragma.pragmaTable to store the information about pragma // use parseContext.contextPragma.pragmaTable to store the information about pragma
// For now, just ignore the pragma that the implementation cannot recognize // For now, just ignore the pragma that the implementation cannot recognize
// An Example of one such implementation for a pragma that has a syntax like // An Example of one such implementation for a pragma that has a syntax like
// #pragma pragmaname(pragmavalue) // #pragma pragmaname(pragmavalue)
// This implementation stores the current pragmavalue against the pragma name in pragmaTable. // This implementation stores the current pragmavalue against the pragma name in pragmaTable.
// //
if (numTokens == 4 && !strcmp(tokens[1], "(") && !strcmp(tokens[3], ")")) { if (numTokens == 4 && !strcmp(tokens[1], "(") && !strcmp(tokens[3], ")")) {
TPragmaTable& pragmaTable = ((TParseContext *)cpp->pC)->contextPragma.pragmaTable; TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;
TPragmaTable::iterator iter; TPragmaTable::iterator iter;
iter = pragmaTable.find(TString(tokens[0])); iter = pragmaTable.find(TString(tokens[0]));
if (iter != pragmaTable.end()) { if (iter != pragmaTable.end()) {
@ -678,7 +690,7 @@ void HandlePragma(const char **tokens, int numTokens)
pragmaTable[tokens[0]] = tokens[2]; pragmaTable[tokens[0]] = tokens[2];
} }
} else if (numTokens >= 2) { } else if (numTokens >= 2) {
TPragmaTable& pragmaTable = ((TParseContext *)cpp->pC)->contextPragma.pragmaTable; TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;
TPragmaTable::iterator iter; TPragmaTable::iterator iter;
iter = pragmaTable.find(TString(tokens[0])); iter = pragmaTable.find(TString(tokens[0]));
if (iter != pragmaTable.end()) { if (iter != pragmaTable.end()) {
@ -693,26 +705,33 @@ void HandlePragma(const char **tokens, int numTokens)
void StoreStr(char *string) void StoreStr(char *string)
{ {
TParseContext& parseContext = *((TParseContext *)cpp->pC);
TString strSrc; TString strSrc;
strSrc = TString(string); strSrc = TString(string);
((TParseContext *)cpp->pC)->HashErrMsg = ((TParseContext *)cpp->pC)->HashErrMsg + " " + strSrc; parseContext.HashErrMsg = parseContext.HashErrMsg + " " + strSrc;
} }
const char* GetStrfromTStr(void) const char* GetStrfromTStr(void)
{ {
cpp->ErrMsg = (((TParseContext *)cpp->pC)->HashErrMsg).c_str(); TParseContext& parseContext = *((TParseContext *)cpp->pC);
cpp->ErrMsg = parseContext.HashErrMsg.c_str();
return cpp->ErrMsg; return cpp->ErrMsg;
} }
void ResetTString(void) void ResetTString(void)
{ {
((TParseContext *)cpp->pC)->HashErrMsg = ""; TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.HashErrMsg = "";
} }
void SetVersion(int version) void SetVersion(int version)
{ {
((TParseContext *)cpp->pC)->version = version; TParseContext& parseContext = *((TParseContext *)cpp->pC);
parseContext.version = version;
} }
const int FirstProfileVersion = 150; const int FirstProfileVersion = 150;
@ -721,32 +740,32 @@ const int FirstProfileVersion = 150;
// if there is a version, sending in a ENoProfile if there is no profile given. // if there is a version, sending in a ENoProfile if there is no profile given.
void SetProfile(EProfile profile) void SetProfile(EProfile profile)
{ {
int version = ((TParseContext *)cpp->pC)->version; TParseContext& parseContext = *((TParseContext *)cpp->pC);
if (profile == ENoProfile) { if (profile == ENoProfile) {
if (version == 100 || version == 300) { if (parseContext.version == 100 || parseContext.version == 300) {
CPPErrorToInfoLog("versions 100 and 300 require specifying the es profile"); CPPErrorToInfoLog("versions 100 and 300 require specifying the es profile");
((TParseContext *)cpp->pC)->profile = ENoProfile; parseContext.profile = ENoProfile;
} else if (version >= FirstProfileVersion) } else if (parseContext.version >= FirstProfileVersion)
((TParseContext *)cpp->pC)->profile = ECoreProfile; parseContext.profile = ECoreProfile;
else else
((TParseContext *)cpp->pC)->profile = ENoProfile; parseContext.profile = ENoProfile;
} else { } else {
// a profile was provided... // a profile was provided...
if (version == 100 || version == 300) { if (parseContext.version == 100 || parseContext.version == 300) {
if (profile != EEsProfile) if (profile != EEsProfile)
CPPErrorToInfoLog("versions 100 and 300 only support the es profile"); CPPErrorToInfoLog("versions 100 and 300 only support the es profile");
((TParseContext *)cpp->pC)->profile = EEsProfile; parseContext.profile = EEsProfile;
} else { } else {
if (profile == EEsProfile) { if (profile == EEsProfile) {
CPPErrorToInfoLog("only versions 100 and 300 support the es profile"); CPPErrorToInfoLog("only versions 100 and 300 support the es profile");
if (version >= FirstProfileVersion) if (parseContext.version >= FirstProfileVersion)
((TParseContext *)cpp->pC)->profile = ECoreProfile; parseContext.profile = ECoreProfile;
else else
((TParseContext *)cpp->pC)->profile = ENoProfile; parseContext.profile = ENoProfile;
} else { } else {
// typical desktop case... e.g., "#version 410 core" // typical desktop case... e.g., "#version 410 core"
((TParseContext *)cpp->pC)->profile = profile; parseContext.profile = profile;
} }
} }
} }
@ -768,8 +787,9 @@ TBehavior GetBehavior(const char* behavior)
} }
} }
void updateExtensionBehavior(const char* extName, const char* behavior) void updateExtensionBehavior(const char* extName, const char* behavior)
{ {
TParseContext& parseContext = *((TParseContext *)cpp->pC);
TBehavior behaviorVal = GetBehavior(behavior); TBehavior behaviorVal = GetBehavior(behavior);
TMap<TString, TBehavior>:: iterator iter; TMap<TString, TBehavior>:: iterator iter;
TString msg; TString msg;
@ -780,12 +800,12 @@ void updateExtensionBehavior(const char* extName, const char* behavior)
CPPShInfoLogMsg("extension 'all' cannot have 'require' or 'enable' behavior"); CPPShInfoLogMsg("extension 'all' cannot have 'require' or 'enable' behavior");
return; return;
} else { } else {
for (iter = ((TParseContext *)cpp->pC)->extensionBehavior.begin(); iter != ((TParseContext *)cpp->pC)->extensionBehavior.end(); ++iter) for (iter = parseContext.extensionBehavior.begin(); iter != parseContext.extensionBehavior.end(); ++iter)
iter->second = behaviorVal; iter->second = behaviorVal;
} }
} else { } else {
iter = ((TParseContext *)cpp->pC)->extensionBehavior.find(TString(extName)); iter = parseContext.extensionBehavior.find(TString(extName));
if (iter == ((TParseContext *)cpp->pC)->extensionBehavior.end()) { if (iter == parseContext.extensionBehavior.end()) {
switch (behaviorVal) { switch (behaviorVal) {
case EBhRequire: case EBhRequire:
CPPShInfoLogMsg((TString("extension '") + extName + "' is not supported").c_str()); CPPShInfoLogMsg((TString("extension '") + extName + "' is not supported").c_str());
@ -794,7 +814,7 @@ void updateExtensionBehavior(const char* extName, const char* behavior)
case EBhWarn: case EBhWarn:
case EBhDisable: case EBhDisable:
msg = TString("extension '") + extName + "' is not supported"; msg = TString("extension '") + extName + "' is not supported";
((TParseContext *)cpp->pC)->infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno); parseContext.infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno);
break; break;
} }
return; return;