static int CPPline(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if(token=='\n'){ DecLineNumber(); CPPErrorToInfoLog("#line"); IncLineNumber(); return token; } else if (token == CPP_INTCONSTANT) { yylvalpp->sc_int=atoi(yylvalpp->symbol_name); SetLineNumber(yylvalpp->sc_int); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == CPP_INTCONSTANT) { yylvalpp->sc_int=atoi(yylvalpp->symbol_name); SetStringNumber(yylvalpp->sc_int); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if(token!='\n') CPPErrorToInfoLog("#line"); } else if (token == '\n'){ return token; } else{ CPPErrorToInfoLog("#line"); } } else{ CPPErrorToInfoLog("#line"); } return token; }
static int CPPversion(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (cpp->pastFirstStatement == 1) CPPShInfoLogMsg("#version must occur before any other statement in the program"); if(token=='\n'){ DecLineNumber(); CPPErrorToInfoLog("#version"); IncLineNumber(); return token; } if (token != CPP_INTCONSTANT) CPPErrorToInfoLog("#version"); yylvalpp->sc_int=atoi(yylvalpp->symbol_name); //SetVersionNumber(yylvalpp->sc_int); if (yylvalpp->sc_int != ESSL_VERSION_NUMBER) CPPShInfoLogMsg("Version number not supported by ESSL"); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == '\n'){ return token; } else{ CPPErrorToInfoLog("#version"); } return token; } // CPPversion
static int CPPerror(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); const char *message; while (token != '\n') { if (token <= 0){ CPPErrorToInfoLog("unexpected end of input in #error preprocessor directive - expected a newline"); return 0; }else if (token == CPP_FLOATCONSTANT || token == CPP_INTCONSTANT){ StoreStr(yylvalpp->symbol_name); }else if(token == CPP_IDENTIFIER || token == CPP_STRCONSTANT){ StoreStr(GetStringOfAtom(atable,yylvalpp->sc_ident)); }else { StoreStr(GetStringOfAtom(atable,token)); } token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } DecLineNumber(); //store this msg into the shader's information log..set the Compile Error flag!!!! message=GetStrfromTStr(); CPPShInfoLogMsg(message); ResetTString(); cpp->CompileError=1; IncLineNumber(); return '\n'; }//CPPerror
/* * str_getch() * takes care of reading from multiple strings. * returns the next-char from the input stream. * returns EOF when the complete shader is parsed. */ static int str_getch(StringInputSrc *in) { for(;;){ if (*in->p){ if (*in->p == '\n') { in->base.line++; IncLineNumber(); } return *in->p++; } if(++(cpp->PaWhichStr) < cpp->PaArgc){ free(in); SetStringNumber(cpp->PaWhichStr); SetLineNumber(1); ScanFromString(cpp->PaArgv[cpp->PaWhichStr]); in=(StringInputSrc*)cpp->currentInput; continue; } else{ cpp->currentInput = in->base.prev; cpp->PaWhichStr=0; free(in); return EOF; } } } // str_getch
static int CPPerror(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); const char *message; while (token != '\n') { if (token == CPP_FLOATCONSTANT || token == CPP_INTCONSTANT) { StoreStr(yylvalpp->symbol_name); } else if (token == CPP_IDENTIFIER || token == CPP_STRCONSTANT) { StoreStr(GetStringOfAtom(atable, yylvalpp->sc_ident)); } else { StoreStr(GetStringOfAtom(atable, token)); } token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } DecLineNumber(); /*store this msg into the shader's information log..set the Compile Error flag!!!! */ message = GetStrfromTStr(); CPPShInfoLogMsg(message); ResetTString(); cpp->CompileError = 1; IncLineNumber(); return '\n'; } /*CPPerror */
static int CPPline(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if(token=='\n'){ DecLineNumber(); CPPErrorToInfoLog("#line"); IncLineNumber(); return token; } else if (token == CPP_INTCONSTANT) { yylvalpp->sc_int=atoi(yylvalpp->symbol_name); SetLineNumber(yylvalpp->sc_int); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); // Modified for HLSL, which allows #line X "str", whereas GLSL is #line X Y if (token == CPP_STRCONSTANT) { token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if(token!='\n') CPPErrorToInfoLog("#line"); } else if (token == '\n'){ return token; } else{ CPPErrorToInfoLog("#line"); } } else{ CPPErrorToInfoLog("#line"); } return token; }
/* * str_getch() * takes care of reading from multiple strings. * returns the next-char from the input stream. * returns EOF when the complete shader is parsed. */ static int str_getch(InputSrc* arg) { StringInputSrc* in = (StringInputSrc*)arg; if (*in->p) { if (*in->p == '\n') { in->base.line++; IncLineNumber(); } return *in->p++; } cpp->currentInput = in->base.prev; free(in); return EOF; } // str_getch
static int CPPextension(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); char extensionName[MAX_SYMBOL_NAME_LEN + 1]; if(token=='\n'){ DecLineNumber(); CPPShInfoLogMsg("extension name not specified"); IncLineNumber(); return token; } if (token != CPP_IDENTIFIER) CPPErrorToInfoLog("#extension"); strncpy(extensionName, GetAtomString(atable, yylvalpp->sc_ident), MAX_SYMBOL_NAME_LEN); extensionName[MAX_SYMBOL_NAME_LEN] = '\0'; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token != ':') { CPPShInfoLogMsg("':' missing after extension name"); return token; } token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token != CPP_IDENTIFIER) { CPPShInfoLogMsg("behavior for extension not specified"); return token; } updateExtensionBehavior(extensionName, GetAtomString(atable, yylvalpp->sc_ident)); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == '\n'){ return token; } else{ CPPErrorToInfoLog("#extension"); } return token; } // CPPextension
static int CPPversion(yystypepp * yylvalpp) { int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (cpp->notAVersionToken == 1) CPPShInfoLogMsg( "#version must occur before any other statement in the program"); if (token == '\n') { DecLineNumber(); CPPErrorToInfoLog("#version"); IncLineNumber(); return token; } if (token != CPP_INTCONSTANT) CPPErrorToInfoLog("#version"); yylvalpp->sc_int = atoi(yylvalpp->symbol_name); setVersionNumber(yylvalpp->sc_int); if (yylvalpp->sc_int != GLSL_100_VERSION_NUMBER && yylvalpp->sc_int != GLSL_110_VERSION_NUMBER && yylvalpp->sc_int != GLSL_120_VERSION_NUMBER) { CPPShInfoLogMsg("Version number not supported by GL2"); } token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == '\n') { return token; } else { CPPErrorToInfoLog("#version"); } return token; } /* CPPversion */
static int CPPpragma(yystypepp * yylvalpp) { char SrcStrName[2]; char** allTokens; int tokenCount = 0; int maxTokenCount = 10; const char* SrcStr; int i; int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token=='\n') { DecLineNumber(); CPPErrorToInfoLog("#pragma"); IncLineNumber(); return token; } allTokens = (char**)malloc(sizeof(char*) * maxTokenCount); while (token != '\n') { if (tokenCount >= maxTokenCount) { maxTokenCount *= 2; allTokens = (char**)realloc((char**)allTokens, sizeof(char*) * maxTokenCount); } switch (token) { case CPP_IDENTIFIER: SrcStr = GetAtomString(atable, yylvalpp->sc_ident); allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); strcpy(allTokens[tokenCount++], SrcStr); break; case CPP_INTCONSTANT: SrcStr = yylvalpp->symbol_name; allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); strcpy(allTokens[tokenCount++], SrcStr); break; case CPP_FLOATCONSTANT: SrcStr = yylvalpp->symbol_name; allTokens[tokenCount] = (char*)malloc(strlen(SrcStr) + 1); strcpy(allTokens[tokenCount++], SrcStr); break; case -1: // EOF CPPShInfoLogMsg("#pragma directive must end with a newline"); goto freeMemoryAndReturnToken; default: SrcStrName[0] = token; SrcStrName[1] = '\0'; allTokens[tokenCount] = (char*)malloc(2); strcpy(allTokens[tokenCount++], SrcStrName); } token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } HandlePragma((const char**)allTokens, tokenCount); freeMemoryAndReturnToken: for (i = 0; i < tokenCount; ++i) { free (allTokens[i]); } free (allTokens); return token; } // CPPpragma
static int CPPdefine(yystypepp * yylvalpp) { int token, name, args[MAX_MACRO_ARGS], argc; const char *message; MacroSymbol mac; Symbol *symb; SourceLoc dummyLoc; memset(&mac, 0, sizeof(mac)); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token != CPP_IDENTIFIER) { CPPErrorToInfoLog("#define"); return token; } name = yylvalpp->sc_ident; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (token == '(' && !yylvalpp->sc_int) { // gather arguments argc = 0; do { token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); if (argc == 0 && token == ')') break; if (token != CPP_IDENTIFIER) { CPPErrorToInfoLog("#define"); return token; } if (argc < MAX_MACRO_ARGS) args[argc++] = yylvalpp->sc_ident; token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } while (token == ','); if (token != ')') { CPPErrorToInfoLog("#define"); return token; } mac.argc = argc; mac.args = mem_Alloc(macros->pool, argc * sizeof(int)); memcpy(mac.args, args, argc * sizeof(int)); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); } mac.body = NewTokenStream(GetAtomString(atable, name), macros->pool); while (token != '\n') { if (token == '\\') { CPPErrorToInfoLog("The line continuation character (\\) is not part of the OpenGL ES Shading Language"); return token; } else if (token <= 0) { // EOF or error CPPErrorToInfoLog("unexpected end of input in #define preprocessor directive - expected a newline"); return 0; } RecordToken(mac.body, token, yylvalpp); token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); }; symb = LookUpSymbol(macros, name); if (symb) { if (!symb->details.mac.undef) { // already defined -- need to make sure they are identical if (symb->details.mac.argc != mac.argc) goto error; for (argc=0; argc < mac.argc; argc++) if (symb->details.mac.args[argc] != mac.args[argc]) goto error; RewindTokenStream(symb->details.mac.body); RewindTokenStream(mac.body); do { int old_lval, old_token; old_token = ReadToken(symb->details.mac.body, yylvalpp); old_lval = yylvalpp->sc_int; token = ReadToken(mac.body, yylvalpp); if (token != old_token || yylvalpp->sc_int != old_lval) { error: StoreStr("Macro Redefined"); StoreStr(GetStringOfAtom(atable,name)); message=GetStrfromTStr(); DecLineNumber(); CPPShInfoLogMsg(message); IncLineNumber(); ResetTString(); break; } } while (token > 0); } //FreeMacro(&symb->details.mac); } else { dummyLoc.file = 0; dummyLoc.line = 0; symb = AddSymbol(&dummyLoc, macros, name, MACRO_S); } symb->details.mac = mac; return '\n'; } // CPPdefine