Non functional: Simplify accesses to the parseContext in the flex file.
authorJohn Kessenich <cepheus@frii.com>
Thu, 24 Jan 2013 22:33:43 +0000 (22:33 +0000)
committerJohn Kessenich <cepheus@frii.com>
Thu, 24 Jan 2013 22:33:43 +0000 (22:33 +0000)
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20315 e7fa87d3-cd2b-0410-9028-fcbf551c1848

glslang/MachineIndependent/glslang.l

index 1fb8a9c..7b05463 100644 (file)
 /* Based on\r
 ANSI C grammar, Lex specification\r
 \r
-In 1985, Jeff Lee published this Lex specification together with a Yacc \r
-grammar for the April 30, 1985 ANSI C draft.  Tom Stockfisch reposted \r
-both to net.sources in 1987; that original, as mentioned in the answer \r
-to question 17.25 of the comp.lang.c FAQ, can be ftp'ed from ftp.uu.net, \r
-file usenet/net.sources/ansi.c.grammar.Z. \r
+In 1985, Jeff Lee published this Lex specification together with a Yacc\r
+grammar for the April 30, 1985 ANSI C draft.  Tom Stockfisch reposted\r
+both to net.sources in 1987; that original, as mentioned in the answer\r
+to question 17.25 of the comp.lang.c FAQ, can be ftp'ed from ftp.uu.net,\r
+file usenet/net.sources/ansi.c.grammar.Z.\r
 \r
-I intend to keep this version as close to the current C Standard grammar \r
-as possible; please let me know if you discover discrepancies. \r
+I intend to keep this version as close to the current C Standard grammar\r
+as possible; please let me know if you discover discrepancies.\r
 \r
-Jutta Degener, 1995 \r
+Jutta Degener, 1995\r
 */\r
 \r
 D           [0-9]\r
@@ -62,7 +62,7 @@ LF          [lL][fF]
 /* TODO: double literals, which will likely require pre-processor rework */\r
 /* TODO: unsigned int literals, which will likely require pre-processor rework */\r
 \r
-%option nounput \r
+%option nounput\r
 %{\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -79,13 +79,13 @@ TSourceLoc yylineno;
 \r
 #ifdef _WIN32\r
     extern int yyparse(TParseContext&);\r
-    #define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext)    \r
+    #define YY_DECL int yylex(YYSTYPE* pyylval, TParseContext& parseContext)\r
 #else\r
     extern int yyparse(void*);\r
     #define YY_DECL int yylex(YYSTYPE* pyylval, void* parseContextLocal)\r
     #define parseContext (*((TParseContext*)(parseContextLocal)))              \r
 #endif\r
\r
+\r
 #define YY_INPUT(buf,result,max_size) (result = yy_input(buf, max_size))\r
 \r
 %}\r
@@ -317,10 +317,10 @@ TSourceLoc yylineno;
 "namespace"    {  PaReservedWord(); return 0; }\r
 "using"        {  PaReservedWord(); return 0; }\r
 \r
-{L}({L}|{D})*       {  \r
-   pyylval->lex.line = yylineno; \r
-   pyylval->lex.string = NewPoolTString(yytext); \r
-   return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol); \r
+{L}({L}|{D})*       {\r
+   pyylval->lex.line = yylineno;\r
+   pyylval->lex.string = NewPoolTString(yytext);\r
+   return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol);\r
 }\r
 \r
 0[xX]{H}+         { pyylval->lex.line = yylineno; pyylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }\r
@@ -343,7 +343,7 @@ TSourceLoc yylineno;
 {D}+"."{D}*({E})?{LF} { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }\r
 "."{D}+({E})?{LF}     { pyylval->lex.line = yylineno; pyylval->lex.d = atof(yytext); return(DOUBLECONSTANT); }\r
 \r
-"/*"            {  int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; }   \r
+"/*"            {  int ret = PaParseComment(pyylval->lex.line, parseContext); if (!ret) return ret; }\r
 \r
 "+="            {  pyylval->lex.line = yylineno; return(ADD_ASSIGN); }\r
 "-="            {  pyylval->lex.line = yylineno; return(SUB_ASSIGN); }\r
@@ -392,10 +392,10 @@ TSourceLoc yylineno;
 "&"         {  pyylval->lex.line = yylineno; return(AMPERSAND); }\r
 "?"         {  pyylval->lex.line = yylineno; return(QUESTION); }\r
 \r
-<FIELDS>{L}({L}|{D})* { \r
-BEGIN(INITIAL);      \r
-    pyylval->lex.line = yylineno;     \r
-    pyylval->lex.string = NewPoolTString(yytext); \r
+<FIELDS>{L}({L}|{D})* {\r
+BEGIN(INITIAL);\r
+    pyylval->lex.line = yylineno;\r
+    pyylval->lex.string = NewPoolTString(yytext);\r
     return FIELD_SELECTION; }\r
 <FIELDS>[ \t\v\f\r] {}\r
 \r
@@ -410,7 +410,7 @@ BEGIN(INITIAL);
 //Including Pre-processor.\r
 extern "C" {\r
   #include "./preprocessor/preprocess.h"\r
-} \r
+}\r
 \r
 //\r
 // The YY_INPUT macro just calls this.  Maybe this could be just put into\r
@@ -424,7 +424,7 @@ int yy_input(char* buf, int max_size)
 \r
     if ((len = yylex_CPP(buf, max_size)) == 0)\r
         return 0;\r
-    if (len >= max_size) \r
+    if (len >= max_size)\r
         YY_FATAL_ERROR( "input buffer overflow, can't enlarge buffer because scanner uses REJECT" );\r
 \r
     buf[len] = ' ';\r
@@ -441,15 +441,15 @@ int yy_input(char* buf, int max_size)
 int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseContextLocal)\r
 {\r
     int argv0len;\r
-    \r
-    ScanFromString(argv[0]); \r
-    \r
+\r
+    ScanFromString(argv[0]);\r
+\r
     //Storing the Current Compiler Parse context into the cpp structure.\r
        cpp->pC = (void*)&parseContextLocal;\r
        \r
        if (!argv || argc == 0)\r
         return 1;\r
-    \r
+\r
     for (int i = 0; i < argc; ++i) {\r
         if (!argv[i]) {\r
             parseContextLocal.error(0, "Null shader source string", "", "");\r
@@ -457,7 +457,7 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
             return 1;\r
         }\r
     }\r
-    \r
+\r
     if (!strLen) {\r
         argv0len = (int) strlen(argv[0]);\r
         strLen   = &argv0len;\r
@@ -470,11 +470,11 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
     cpp->PaStrLen   = strLen;\r
     cpp->notAVersionToken = 0;\r
     yylineno   = 1;\r
-   \r
-    if (*cpp->PaStrLen >= 0) {    \r
+\r
+    if (*cpp->PaStrLen >= 0) {\r
         int ret;\r
         #ifdef _WIN32\r
-            ret = yyparse(parseContextLocal);            \r
+            ret = yyparse(parseContextLocal);\r
         #else\r
             ret = yyparse((void*)(&parseContextLocal));\r
         #endif\r
@@ -487,9 +487,11 @@ int PaParseStrings(char* argv[], int strLen[], int argc, TParseContext& parseCon
         return 0;\r
 }\r
 \r
-void yyerror(char *s) \r
+void yyerror(char *s)\r
 {\r
-    if (((TParseContext *)cpp->pC)->AfterEOF) {\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    if (parseContext.AfterEOF) {\r
         if (cpp->tokensBeforeEOF == 1) {\r
             GlobalParseContext->error(yylineno, "syntax error", "pre-mature EOF", s, "");\r
             GlobalParseContext->recover();\r
@@ -497,7 +499,7 @@ void yyerror(char *s)
     } else {\r
         GlobalParseContext->error(yylineno, "syntax error", yytext, s, "");\r
         GlobalParseContext->recover();\r
-    }            \r
+    }\r
 }\r
 \r
 void PaReservedWord()\r
@@ -516,7 +518,7 @@ int PaIdentOrType(TString& id, TParseContext& parseContextLocal, TSymbol*& symbo
             return TYPE_NAME;\r
         }\r
     }\r
-    \r
+\r
     return IDENTIFIER;\r
 }\r
 \r
@@ -524,7 +526,7 @@ int PaParseComment(int &lineno, TParseContext& parseContextLocal)
 {\r
     int transitionFlag = 0;\r
     int nextChar;\r
-    \r
+\r
     while (transitionFlag != 2) {\r
         nextChar = yyinput();\r
         if (nextChar == '\n')\r
@@ -542,7 +544,7 @@ int PaParseComment(int &lineno, TParseContext& parseContextLocal)
             /* Raise error message here */\r
             parseContextLocal.error(yylineno, "End of shader found before end of comment.", "", "", "");\r
             GlobalParseContext->recover();\r
-            return YY_NULL; \r
+            return YY_NULL;\r
         default :  /* Any other character will be a part of the comment */\r
             transitionFlag = 0;\r
         }\r
@@ -554,23 +556,31 @@ extern "C" {
 \r
 void CPPDebugLogMsg(const char *msg)\r
 {\r
-    ((TParseContext *)cpp->pC)->infoSink.debug.message(EPrefixNone, msg);\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    parseContext.infoSink.debug.message(EPrefixNone, msg);\r
 }\r
 \r
 void CPPWarningToInfoLog(const char *msg)\r
 {\r
-    ((TParseContext *)cpp->pC)->infoSink.info.message(EPrefixWarning, msg, yylineno); \r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    parseContext.infoSink.info.message(EPrefixWarning, msg, yylineno);\r
 }\r
 \r
 void CPPShInfoLogMsg(const char *msg)\r
 {\r
-    ((TParseContext *)cpp->pC)->error(yylineno,"", "",msg,"");\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    parseContext.error(yylineno,"", "",msg,"");\r
     GlobalParseContext->recover();\r
 }\r
 \r
 void CPPErrorToInfoLog(char *msg)\r
 {\r
-    ((TParseContext *)cpp->pC)->error(yylineno, "CPP error:", "",msg,"");\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    parseContext.error(yylineno, "CPP error:", "",msg,"");\r
     GlobalParseContext->recover();\r
 }\r
 \r
@@ -608,27 +618,29 @@ void DecLineNumber(void)
 }\r
 \r
 void HandlePragma(const char **tokens, int numTokens)\r
-{    \r
+{\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
     if (!strcmp(tokens[0], "optimize")) {\r
         if (numTokens != 4) {\r
             CPPShInfoLogMsg("optimize pragma syntax is incorrect");\r
             return;\r
         }\r
-        \r
+\r
         if (strcmp(tokens[1], "(")) {\r
             CPPShInfoLogMsg("\"(\" expected after 'optimize' keyword");\r
             return;\r
         }\r
-            \r
+\r
         if (!strcmp(tokens[2], "on"))\r
-            ((TParseContext *)cpp->pC)->contextPragma.optimize = true;\r
+            parseContext.contextPragma.optimize = true;\r
         else if (!strcmp(tokens[2], "off"))\r
-            ((TParseContext *)cpp->pC)->contextPragma.optimize = false;\r
+            parseContext.contextPragma.optimize = false;\r
         else {\r
             CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'optimize' pragma");\r
             return;\r
         }\r
-        \r
+\r
         if (strcmp(tokens[3], ")")) {\r
             CPPShInfoLogMsg("\")\" expected to end 'optimize' pragma");\r
             return;\r
@@ -638,21 +650,21 @@ void HandlePragma(const char **tokens, int numTokens)
             CPPShInfoLogMsg("debug pragma syntax is incorrect");\r
             return;\r
         }\r
-        \r
+\r
         if (strcmp(tokens[1], "(")) {\r
             CPPShInfoLogMsg("\"(\" expected after 'debug' keyword");\r
             return;\r
         }\r
-            \r
+\r
         if (!strcmp(tokens[2], "on"))\r
-            ((TParseContext *)cpp->pC)->contextPragma.debug = true;\r
+            parseContext.contextPragma.debug = true;\r
         else if (!strcmp(tokens[2], "off"))\r
-            ((TParseContext *)cpp->pC)->contextPragma.debug = false;\r
+            parseContext.contextPragma.debug = false;\r
         else {\r
             CPPShInfoLogMsg("\"on\" or \"off\" expected after '(' for 'debug' pragma");\r
             return;\r
         }\r
-        \r
+\r
         if (strcmp(tokens[3], ")")) {\r
             CPPShInfoLogMsg("\")\" expected to end 'debug' pragma");\r
             return;\r
@@ -662,23 +674,23 @@ void HandlePragma(const char **tokens, int numTokens)
 #ifdef PRAGMA_TABLE\r
         //\r
         // implementation specific pragma\r
-        // use ((TParseContext *)cpp->pC)->contextPragma.pragmaTable to store the information about pragma\r
+        // use parseContext.contextPragma.pragmaTable to store the information about pragma\r
         // For now, just ignore the pragma that the implementation cannot recognize\r
         // An Example of one such implementation for a pragma that has a syntax like\r
         // #pragma pragmaname(pragmavalue)\r
         // This implementation stores the current pragmavalue against the pragma name in pragmaTable.\r
-        //        \r
-        if (numTokens == 4 && !strcmp(tokens[1], "(") && !strcmp(tokens[3], ")")) {              \r
-            TPragmaTable& pragmaTable = ((TParseContext *)cpp->pC)->contextPragma.pragmaTable;\r
+        //\r
+        if (numTokens == 4 && !strcmp(tokens[1], "(") && !strcmp(tokens[3], ")")) {\r
+            TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;\r
             TPragmaTable::iterator iter;\r
             iter = pragmaTable.find(TString(tokens[0]));\r
             if (iter != pragmaTable.end()) {\r
                 iter->second = tokens[2];\r
             } else {\r
                 pragmaTable[tokens[0]] = tokens[2];\r
-            }        \r
+            }\r
         } else if (numTokens >= 2) {\r
-            TPragmaTable& pragmaTable = ((TParseContext *)cpp->pC)->contextPragma.pragmaTable;\r
+            TPragmaTable& pragmaTable = parseContext.contextPragma.pragmaTable;\r
             TPragmaTable::iterator iter;\r
             iter = pragmaTable.find(TString(tokens[0]));\r
             if (iter != pragmaTable.end()) {\r
@@ -693,26 +705,33 @@ void HandlePragma(const char **tokens, int numTokens)
 \r
 void StoreStr(char *string)\r
 {\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
     TString strSrc;\r
     strSrc = TString(string);\r
 \r
-    ((TParseContext *)cpp->pC)->HashErrMsg = ((TParseContext *)cpp->pC)->HashErrMsg + " " + strSrc;\r
+    parseContext.HashErrMsg = parseContext.HashErrMsg + " " + strSrc;\r
 }\r
 \r
 const char* GetStrfromTStr(void)\r
 {\r
-    cpp->ErrMsg = (((TParseContext *)cpp->pC)->HashErrMsg).c_str();\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    cpp->ErrMsg = parseContext.HashErrMsg.c_str();\r
     return cpp->ErrMsg;\r
 }\r
 \r
 void ResetTString(void)\r
 {\r
-    ((TParseContext *)cpp->pC)->HashErrMsg = "";\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+\r
+    parseContext.HashErrMsg = "";\r
 }\r
 \r
 void SetVersion(int version)\r
 {\r
-    ((TParseContext *)cpp->pC)->version = version;\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
+    parseContext.version = version;\r
 }\r
 \r
 const int FirstProfileVersion = 150;\r
@@ -721,32 +740,32 @@ const int FirstProfileVersion = 150;
 // if there is a version, sending in a ENoProfile if there is no profile given.\r
 void SetProfile(EProfile profile)\r
 {\r
-    int version = ((TParseContext *)cpp->pC)->version;\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
 \r
     if (profile == ENoProfile) {\r
-        if (version == 100 || version == 300) {\r
+        if (parseContext.version == 100 || parseContext.version == 300) {\r
             CPPErrorToInfoLog("versions 100 and 300 require specifying the es profile");\r
-            ((TParseContext *)cpp->pC)->profile = ENoProfile;\r
-        } else if (version >= FirstProfileVersion)\r
-            ((TParseContext *)cpp->pC)->profile = ECoreProfile;\r
+            parseContext.profile = ENoProfile;\r
+        } else if (parseContext.version >= FirstProfileVersion)\r
+            parseContext.profile = ECoreProfile;\r
         else\r
-            ((TParseContext *)cpp->pC)->profile = ENoProfile;\r
+            parseContext.profile = ENoProfile;\r
     } else { \r
         // a profile was provided...\r
-        if (version == 100 || version == 300) {\r
+        if (parseContext.version == 100 || parseContext.version == 300) {\r
             if (profile != EEsProfile)\r
                 CPPErrorToInfoLog("versions 100 and 300 only support the es profile");            \r
-            ((TParseContext *)cpp->pC)->profile = EEsProfile;\r
+            parseContext.profile = EEsProfile;\r
         } else {\r
             if (profile == EEsProfile) {\r
                 CPPErrorToInfoLog("only versions 100 and 300 support the es profile");\r
-                if (version >= FirstProfileVersion)\r
-                    ((TParseContext *)cpp->pC)->profile = ECoreProfile;\r
+                if (parseContext.version >= FirstProfileVersion)\r
+                    parseContext.profile = ECoreProfile;\r
                 else\r
-                    ((TParseContext *)cpp->pC)->profile = ENoProfile;\r
+                    parseContext.profile = ENoProfile;\r
             } else {\r
                 // typical desktop case... e.g., "#version 410 core"\r
-                ((TParseContext *)cpp->pC)->profile = profile;\r
+                parseContext.profile = profile;\r
             }\r
         }\r
     }\r
@@ -765,36 +784,37 @@ TBehavior GetBehavior(const char* behavior)
     else {\r
         CPPShInfoLogMsg((TString("behavior '") + behavior + "' is not supported").c_str());\r
         return EBhDisable;\r
-    }        \r
+    }\r
 }\r
 \r
-void  updateExtensionBehavior(const char* extName, const char* behavior)\r
+void updateExtensionBehavior(const char* extName, const char* behavior)\r
 {\r
+    TParseContext& parseContext = *((TParseContext *)cpp->pC);\r
     TBehavior behaviorVal = GetBehavior(behavior);\r
     TMap<TString, TBehavior>:: iterator iter;\r
     TString msg;\r
-    \r
+\r
     // special cased for all extension\r
     if (!strcmp(extName, "all")) {\r
         if (behaviorVal == EBhRequire || behaviorVal == EBhEnable) {\r
-            CPPShInfoLogMsg("extension 'all' cannot have 'require' or 'enable' behavior");  \r
+            CPPShInfoLogMsg("extension 'all' cannot have 'require' or 'enable' behavior");\r
             return;\r
         } else {\r
-            for (iter =  ((TParseContext *)cpp->pC)->extensionBehavior.begin(); iter != ((TParseContext *)cpp->pC)->extensionBehavior.end(); ++iter)\r
+            for (iter = parseContext.extensionBehavior.begin(); iter != parseContext.extensionBehavior.end(); ++iter)\r
                 iter->second = behaviorVal;\r
-        }        \r
+        }\r
     } else {\r
-        iter = ((TParseContext *)cpp->pC)->extensionBehavior.find(TString(extName));\r
-        if (iter == ((TParseContext *)cpp->pC)->extensionBehavior.end()) {\r
+        iter = parseContext.extensionBehavior.find(TString(extName));\r
+        if (iter == parseContext.extensionBehavior.end()) {\r
             switch (behaviorVal) {\r
             case EBhRequire:\r
-                CPPShInfoLogMsg((TString("extension '") + extName + "' is not supported").c_str());  \r
+                CPPShInfoLogMsg((TString("extension '") + extName + "' is not supported").c_str());\r
                 break;\r
             case EBhEnable:\r
             case EBhWarn:\r
             case EBhDisable:\r
                 msg = TString("extension '") + extName + "' is not supported";\r
-                ((TParseContext *)cpp->pC)->infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno); \r
+                parseContext.infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno);\r
                 break;\r
             }\r
             return;\r
@@ -802,7 +822,7 @@ void  updateExtensionBehavior(const char* extName, const char* behavior)
             iter->second = behaviorVal;\r
     }\r
 }\r
-        \r
+\r
 }  // extern "C"\r
 \r
 void setInitialState()\r