Пример #1
0
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
Пример #2
0
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
Пример #3
0
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 */
Пример #4
0
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
Пример #5
0
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 */
Пример #6
0
int MacroExpand(int atom, yystypepp * yylvalpp)
{
    Symbol              *sym = LookUpSymbol(macros, atom);
    MacroInputSrc       *in;
    int i,j, token, depth=0;
    const char *message;
	if (atom == __LINE__Atom) {
        yylvalpp->sc_int = GetLineNumber();
        snprintf(yylvalpp->symbol_name, MAX_SYMBOL_NAME_LEN+1, "%d", yylvalpp->sc_int);
        UngetToken(CPP_INTCONSTANT, yylvalpp);
        return 1;
    }
    if (atom == __FILE__Atom) {
        yylvalpp->sc_int = GetStringNumber();
        snprintf(yylvalpp->symbol_name, MAX_SYMBOL_NAME_LEN+1, "%d", yylvalpp->sc_int);
        UngetToken(CPP_INTCONSTANT, yylvalpp);
        return 1;
    }
	if (atom == __VERSION__Atom) {
        strcpy(yylvalpp->symbol_name,ESSL_VERSION_STRING);
        yylvalpp->sc_int = atoi(yylvalpp->symbol_name);
        UngetToken(CPP_INTCONSTANT, yylvalpp);
        return 1;
    }
    if (!sym || sym->details.mac.undef) return 0;
    if (sym->details.mac.busy) return 0;        // no recursive expansions
    in = malloc(sizeof(*in));
    memset(in, 0, sizeof(*in));
    in->base.scan = (void *)macro_scan;
    in->base.line = cpp->currentInput->line;
    in->base.name = cpp->currentInput->name;
    in->mac = &sym->details.mac;
    if (sym->details.mac.args) {
        token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
		if (token != '(') {
            UngetToken(token, yylvalpp);
            yylvalpp->sc_ident = atom;
            return 0;
        }
        in->args = malloc(in->mac->argc * sizeof(TokenStream *));
        for (i=0; i<in->mac->argc; i++)
            in->args[i] = NewTokenStream("macro arg", 0);
		i=0;j=0;
        do{
            depth = 0;
			while(1) {
                token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
                if (token <= 0) {
                    StoreStr("EOF in Macro ");
                    StoreStr(GetStringOfAtom(atable,atom));
                    message=GetStrfromTStr();
                    CPPShInfoLogMsg(message);
                    ResetTString();
                    return 1;
                }
                if((in->mac->argc==0) && (token!=')')) break;
                if (depth == 0 && (token == ',' || token == ')')) break;
                if (token == '(') depth++;
                if (token == ')') depth--;
                RecordToken(in->args[i], token, yylvalpp);
                j=1;
			}
            if (token == ')') {
                if((in->mac->argc==1) &&j==0)
                    break;
                i++;
                break;
            }
            i++;
		}while(i < in->mac->argc);

        if (i < in->mac->argc) {
            StoreStr("Too few args in Macro ");
            StoreStr(GetStringOfAtom(atable,atom));
            message=GetStrfromTStr();
            CPPShInfoLogMsg(message);
            ResetTString();
        } else if (token != ')') {
            depth=0;
			while (token >= 0 && (depth > 0 || token != ')')) {
                if (token == ')') depth--;
                token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
                if (token == '(') depth++;
            }
			
            if (token <= 0) {
                StoreStr("EOF in Macro ");
                StoreStr(GetStringOfAtom(atable,atom));
                message=GetStrfromTStr();
                CPPShInfoLogMsg(message);
                ResetTString();
                return 1;
            }
            StoreStr("Too many args in Macro ");
            StoreStr(GetStringOfAtom(atable,atom));
            message=GetStrfromTStr();
            CPPShInfoLogMsg(message);
            ResetTString();
		}
		for (i=0; i<in->mac->argc; i++) {
            in->args[i] = PrescanMacroArg(in->args[i], yylvalpp);
        }
    }
#if 0
    printf("  <%s:%d>found macro %s\n", GetAtomString(atable, loc.file),
           loc.line, GetAtomString(atable, atom));
    for (i=0; i<in->mac->argc; i++) {
        printf("\targ %s = '", GetAtomString(atable, in->mac->args[i]));
        DumpTokenStream(stdout, in->args[i]);
        printf("'\n");
    }
#endif
	/*retain the input source*/
    in->base.prev = cpp->currentInput;
    sym->details.mac.busy = 1;
    RewindTokenStream(sym->details.mac.body);
    cpp->currentInput = &in->base;
    return 1;
} // MacroExpand
Пример #7
0
int readCPPline(yystypepp * yylvalpp)
{
    int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
    const char *message;

    if (token == CPP_IDENTIFIER) {
        if (yylvalpp->sc_ident == defineAtom) {
             token = CPPdefine(yylvalpp);
        } else if (yylvalpp->sc_ident == elseAtom) {
			 if(ChkCorrectElseNesting()){
                 if (!cpp->ifdepth ){
                     CPPErrorToInfoLog("#else mismatch");
                     cpp->CompileError=1;
                     return 0;
                 }
                 token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
                 if (token != '\n') {
                     CPPWarningToInfoLog("unexpected tokens following #else preprocessor directive - expected a newline");
                     while (token != '\n') {
                         token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
                         if (token <= 0) { // EOF or error
                             CPPErrorToInfoLog("unexpected end of input in #ifdef preprocessor directive - expected a newline");
                             return 0;
                         }
                     }
                 }
			     token = CPPelse(0, yylvalpp);
             }else{
                 CPPErrorToInfoLog("#else after a #else");
                 cpp->ifdepth = 0;
                 cpp->elsetracker = 0;
                 cpp->pastFirstStatement = 1;
                 cpp->CompileError = 1;
                 return 0;
             }
		} else if (yylvalpp->sc_ident == elifAtom) {
            if (!cpp->ifdepth){
                 CPPErrorToInfoLog("#elif mismatch");
                 cpp->CompileError=1;
                 return 0;
            } 
            // this token is really a dont care, but we still need to eat the tokens
            token = cpp->currentInput->scan(cpp->currentInput, yylvalpp); 
            while (token != '\n') {
                token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
                if (token <= 0) { // EOF or error
                    CPPErrorToInfoLog("unexpect tokens following #elif preprocessor directive - expected a newline");
                    cpp->CompileError = 1;
                    return 0;
                }
            }
		    token = CPPelse(0, yylvalpp);
        } else if (yylvalpp->sc_ident == endifAtom) {
             if (!cpp->ifdepth){
                 CPPErrorToInfoLog("#endif mismatch");
                 cpp->CompileError=1;
                 return 0;
             }
             else
                 --cpp->ifdepth;

             if (cpp->elsetracker)
                 --cpp->elsetracker;

	    } else if (yylvalpp->sc_ident == ifAtom) {
             token = CPPif(yylvalpp);
        } else if (yylvalpp->sc_ident == ifdefAtom) {
             token = CPPifdef(1, yylvalpp);
        } else if (yylvalpp->sc_ident == ifndefAtom) {
             token = CPPifdef(0, yylvalpp);
        } else if (yylvalpp->sc_ident == lineAtom) {
             token = CPPline(yylvalpp);
        } else if (yylvalpp->sc_ident == pragmaAtom) {
             token = CPPpragma(yylvalpp);
        } else if (yylvalpp->sc_ident == undefAtom) {
             token = CPPundef(yylvalpp);
        } else if (yylvalpp->sc_ident == errorAtom) {
             token = CPPerror(yylvalpp);
        } else if (yylvalpp->sc_ident == versionAtom) {
            token = CPPversion(yylvalpp);
        } else if (yylvalpp->sc_ident == extensionAtom) {
            token = CPPextension(yylvalpp);
        } else {
            StoreStr("Invalid Directive");
            StoreStr(GetStringOfAtom(atable,yylvalpp->sc_ident));
            message=GetStrfromTStr();
            CPPShInfoLogMsg(message);
            ResetTString();
        }
    }
    while (token != '\n' && token != 0 && token != EOF) {
		token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
	}
        
    cpp->pastFirstStatement = 1;

    return token;
} // readCPPline
Пример #8
0
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
Пример #9
0
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
Пример #10
0
int readCPPline(yystypepp * yylvalpp)
{
    int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
    const char *message;
    int isVersion = 0;
	
    if (token == CPP_IDENTIFIER) {
        if (yylvalpp->sc_ident == defineAtom) {
			token = CPPdefine(yylvalpp);
        } else if (yylvalpp->sc_ident == elseAtom) {
            token = CPPgotoEndOfIfBlock(1, yylvalpp);
            if (yylvalpp->sc_ident != endifAtom)
            {
                CPPErrorToInfoLog("#else or #elif mismatch");
                cpp->CompileError=1;
            }
            token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
            if (token != '\n')
                CPPWarningToInfoLog("unexpected tokens following #else preprocessor directive - expected a newline");
			
			if (!cpp->ifdepth){
				CPPErrorToInfoLog("#else or #elif mismatch");
				cpp->CompileError=1;
			}
			else
				--cpp->ifdepth;
        } else if (yylvalpp->sc_ident == elifAtom) {
            token = CPPgotoEndOfIfBlock(0, yylvalpp);
            assert(yylvalpp->sc_ident == endifAtom);
            token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
            if (!cpp->ifdepth){
                CPPErrorToInfoLog("#else or #elif mismatch");
                cpp->CompileError=1;
            }
            else
                --cpp->ifdepth;
        } else if (yylvalpp->sc_ident == endifAtom) {
			if (!cpp->ifdepth){
				CPPErrorToInfoLog("#endif mismatch");
				cpp->CompileError=1;
			}
			else
				--cpp->ifdepth;
        } else if (yylvalpp->sc_ident == ifAtom) {
			token = CPPif(yylvalpp);
        } else if (yylvalpp->sc_ident == ifdefAtom) {
			token = CPPifdef(1, yylvalpp);
        } else if (yylvalpp->sc_ident == ifndefAtom) {
			token = CPPifdef(0, yylvalpp);
        } else if (yylvalpp->sc_ident == lineAtom) {
			token = CPPline(yylvalpp);
        } else if (yylvalpp->sc_ident == pragmaAtom) {
			token = CPPpragma(yylvalpp);
        } else if (yylvalpp->sc_ident == undefAtom) {
			token = CPPundef(yylvalpp);
        } else if (yylvalpp->sc_ident == errorAtom) {
			token = CPPerror(yylvalpp);
        } else if (yylvalpp->sc_ident == versionAtom) {
            token = CPPversion(yylvalpp);
            isVersion = 1;
        } else {
            StoreStr("Invalid Directive");
            StoreStr(GetStringOfAtom(atable,yylvalpp->sc_ident));
            message=GetStrfromTStr();
            CPPShInfoLogMsg(message);
            ResetTString();
        }
    }
    while (token != '\n' && token != 0 && token != EOF) {
        token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
    }
	
    cpp->notAVersionToken = !isVersion;
	
    return token;
} // readCPPline