Beispiel #1
0
int TPpContext::CPPifdef(int defined, TPpToken * yylvalpp)
{
    int token = currentInput->scan(this, currentInput, yylvalpp);
    int name = yylvalpp->atom;
    if (++ifdepth > maxIfNesting) {
        parseContext.error(yylvalpp->loc, "maximum nesting depth exceededextension name not specified", "#ifdef", "");
        return 0;
    }
    elsetracker++;
    if (token != CPP_IDENTIFIER) {
        if (defined)
            parseContext.error(yylvalpp->loc, "must be followed by macro name", "#ifdef", "");
        else 
            parseContext.error(yylvalpp->loc, "must be followed by macro name", "#ifndef", "");
    } else {
        Symbol *s = LookUpSymbol(macros, name);
        token = currentInput->scan(this, currentInput, yylvalpp);
        if (token != '\n') {
            parseContext.error(yylvalpp->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
            while (token != '\n')
                token = currentInput->scan(this, currentInput, yylvalpp);
        }
        if (((s && !s->details.mac.undef) ? 1 : 0) != defined)
            token = CPPelse(1, yylvalpp);
    }
    return token;
} // CPPifdef
Beispiel #2
0
static int CPPifdef(int defined, yystypepp * yylvalpp)
{
	int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
	int name = yylvalpp->sc_ident;
	if (++cpp->ifdepth > MAX_IF_NESTING) {
		CPPErrorToInfoLog("max #if nesting depth exceeded");
		return 0;
	}
	cpp->elsetracker++;
	cpp->elsedepth[cpp->elsetracker] = 0;
	if (token != CPP_IDENTIFIER) {
		defined ? CPPErrorToInfoLog("ifdef") : CPPErrorToInfoLog("ifndef");
	} else {
		Symbol *s = LookUpSymbol(macros, name);
		token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
		if (token != '\n') {
			CPPWarningToInfoLog(
					"unexpected tokens following #ifdef preprocessor directive - expected a newline");
			while (token != '\n')
				token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
		}
		if (((s && !s->details.mac.undef) ? 1 : 0) != defined) {
			token = CPPelse(1, yylvalpp);
		}
	}

	return token;
} /* CPPifdef */
Beispiel #3
0
// Handle #ifdef
int TPpContext::CPPifdef(int defined, TPpToken* ppToken)
{
    int token = scanToken(ppToken);
    int name = ppToken->atom;
    if (++ifdepth > maxIfNesting) {
        parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", "");
        return 0;
    }
    elsetracker++;
    if (token != PpAtomIdentifier) {
        if (defined)
            parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifdef", "");
        else 
            parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", "");
    } else {
        Symbol *s = LookUpSymbol(name);
        token = scanToken(ppToken);
        if (token != '\n') {
            parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
            while (token != '\n' && token != EndOfInput)
                token = scanToken(ppToken);
        }
        if (((s && !s->mac.undef) ? 1 : 0) != defined)
            token = CPPelse(1, ppToken);
    }

    return token;
}
Beispiel #4
0
static int CPPif(yystypepp * yylvalpp)
{
	int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
	int res = 0, err = 0;
	cpp->elsetracker++;
	cpp->elsedepth[cpp->elsetracker] = 0;
	if (!cpp->ifdepth++)
		ifloc = *cpp->tokenLoc;
	if (cpp->ifdepth > MAX_IF_NESTING) {
		CPPErrorToInfoLog("max #if nesting depth exceeded");
		return 0;
	}
	token = eval(token, MIN_PREC, &res, &err, yylvalpp);
	if (token != '\n') {
		CPPWarningToInfoLog(
				"unexpected tokens following the preprocessor directive - expected a newline");
		while (token != '\n')
			token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
	}
	if (!res && !err) {
		token = CPPelse(1, yylvalpp);
	}

	return token;
} /* CPPif */
Beispiel #5
0
// Handle #ifdef
int TPpContext::CPPifdef(int defined, TPpToken* ppToken)
{
    int token = scanToken(ppToken);
    if (++ifdepth > maxIfNesting) {
        parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#ifdef", "");
        return 0;
    }
    elsetracker++;
    if (token != PpAtomIdentifier) {
        if (defined)
            parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifdef", "");
        else
            parseContext.ppError(ppToken->loc, "must be followed by macro name", "#ifndef", "");
    } else {
        MacroSymbol* macro = lookupMacroDef(atomStrings.getAtom(ppToken->name));
        token = scanToken(ppToken);
        if (token != '\n') {
            parseContext.ppError(ppToken->loc, "unexpected tokens following #ifdef directive - expected a newline", "#ifdef", "");
            while (token != '\n' && token != EndOfInput)
                token = scanToken(ppToken);
        }
        if (((macro != nullptr && !macro->undef) ? 1 : 0) != defined)
            token = CPPelse(1, ppToken);
    }

    return token;
}
Beispiel #6
0
// Handle #if
int TPpContext::CPPif(TPpToken* ppToken) 
{
    int token = scanToken(ppToken);
    elsetracker++;
    ifdepth++;
    if (ifdepth > maxIfNesting) {
        parseContext.ppError(ppToken->loc, "maximum nesting depth exceeded", "#if", "");
        return 0;
    }
    int res = 0;
    bool err = false;
    token = eval(token, MIN_PRECEDENCE, false, res, err, ppToken);
    token = extraTokenCheck(PpAtomIf, ppToken, token);
    if (!res && !err)
        token = CPPelse(1, ppToken);

    return token;
}
Beispiel #7
0
// Handle #if
int TPpContext::CPPif(TPpToken* ppToken) 
{
    int token = currentInput->scan(this, currentInput, ppToken);
    elsetracker++;
    if (! ifdepth++)
        ifloc = ppToken->loc;
    if (ifdepth > maxIfNesting) {
        parseContext.error(ppToken->loc, "maximum nesting depth exceeded", "#if", "");
        return 0;
    }
    int res = 0;
    bool err = false;
    token = eval(token, MIN_PRECEDENCE, res, err, ppToken);
    token = extraTokenCheck(ifAtom, ppToken, token);
    if (!res && !err)
        token = CPPelse(1, ppToken);

    return token;
}
Beispiel #8
0
static int CPPifdef(int defined, yystypepp * yylvalpp)
{
    int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
    int name = yylvalpp->sc_ident;
    if(++cpp->ifdepth > MAX_IF_NESTING){
        CPPErrorToInfoLog("max #if nesting depth exceeded");
        cpp->CompileError = 1;
        return 0;
    }
    cpp->elsetracker++;
    // sanity check elsetracker
    if (cpp->elsetracker < 0 || cpp->elsetracker >= MAX_IF_NESTING) {
        CPPErrorToInfoLog("mismatched #if/#endif statements");
        cpp->CompileError = 1;
        return 0;
    }
    cpp->elsedepth[cpp->elsetracker] = 0;

    if (token != CPP_IDENTIFIER) {
            defined ? CPPErrorToInfoLog("ifdef"):CPPErrorToInfoLog("ifndef");
    } else {
        Symbol *s = LookUpSymbol(macros, name);
        token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
        if (token != '\n') {
            CPPWarningToInfoLog("unexpected tokens following #ifdef 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;
                }
            }
        }
        if (((s && !s->details.mac.undef) ? 1 : 0) != defined)
            token = CPPelse(1, yylvalpp);
    }
    return token;
} // CPPifdef
Beispiel #9
0
int TPpContext::CPPif (TPpToken * yylvalpp) 
{
    int token = currentInput->scan(this, currentInput, yylvalpp);
    int res = 0, err = 0;
    elsetracker++;
    if (! ifdepth++)
        ifloc = yylvalpp->loc;
    if (ifdepth > maxIfNesting) {
        parseContext.error(yylvalpp->loc, "maximum nesting depth exceeded", "#if", "");
        return 0;
    }
    token = eval(token, MIN_PREC, &res, &err, yylvalpp);
    if (token != '\n') {
        parseContext.warn(yylvalpp->loc, "unexpected tokens following #if directive - expected a newline", "#if", "");
        while (token != '\n')
            token = currentInput->scan(this, currentInput, yylvalpp);
    } 
    if (!res && !err) {
        token = CPPelse(1, yylvalpp);
    }

    return token;
} // CPPif
Beispiel #10
0
static int CPPif(yystypepp * yylvalpp) {
    int token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
    int res = 0, err = 0;

    if (!cpp->ifdepth++)
        ifloc = *cpp->tokenLoc;
    if(cpp->ifdepth > MAX_IF_NESTING){
        CPPErrorToInfoLog("max #if nesting depth exceeded");
        cpp->CompileError = 1;
        return 0;
    }
    cpp->elsetracker++;
    // sanity check elsetracker
    if (cpp->elsetracker < 0 || cpp->elsetracker >= MAX_IF_NESTING) {
        CPPErrorToInfoLog("mismatched #if/#endif statements");
        cpp->CompileError = 1;
        return 0;
    }
    cpp->elsedepth[cpp->elsetracker] = 0;

    token = eval(token, MIN_PREC, &res, &err, yylvalpp);
    if (token != '\n') {
        CPPWarningToInfoLog("unexpected tokens following #if 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 #if preprocessor directive - expected a newline");
                return 0;
            }
        }
    } 
    if (!res && !err) {
        token = CPPelse(1, yylvalpp);
    }

    return token;
} // CPPif
Beispiel #11
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
Beispiel #12
0
int TPpContext::readCPPline(TPpToken * yylvalpp)
{
    int token = currentInput->scan(this, currentInput, yylvalpp);
    bool isVersion = false;

    if (token == CPP_IDENTIFIER) {
        if (yylvalpp->atom == defineAtom) {
            token = CPPdefine(yylvalpp);
        } else if (yylvalpp->atom == elseAtom) {
            if (ChkCorrectElseNesting()) {
                if (! ifdepth) {
                    parseContext.error(yylvalpp->loc, "mismatched statements", "#else", "");
                }
                token = currentInput->scan(this, currentInput, yylvalpp);
                if (token != '\n') {                     
                    parseContext.warn(yylvalpp->loc, "unexpected tokens following #else directive - expected a newline", "#else", "");
                    while (token != '\n')
                        token = currentInput->scan(this, currentInput, yylvalpp);
                }
                token = CPPelse(0, yylvalpp);
            } else {
                parseContext.error(yylvalpp->loc, "#else after a #else", "#else", "");
                ifdepth = 0;
                notAVersionToken = true;
                return 0;
            }
        } else if (yylvalpp->atom == elifAtom) {
            if (! ifdepth) {
                parseContext.error(yylvalpp->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); 
            while (token != '\n')
                token = currentInput->scan(this, currentInput, yylvalpp);
            token = CPPelse(0, yylvalpp);
        } else if (yylvalpp->atom == endifAtom) {
            elsedepth[elsetracker] = 0;
            --elsetracker;
            if (! ifdepth)
                parseContext.error(yylvalpp->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);
            isVersion = true;
        } else if (yylvalpp->atom == extensionAtom) {
            token = CPPextension(yylvalpp);
        } else {
            parseContext.error(yylvalpp->loc, "Invalid Directive", "#", GetStringOfAtom(&atomTable, yylvalpp->atom));
        }
    }
    while (token != '\n' && token != 0 && token != EOF) {
        token = currentInput->scan(this, currentInput, yylvalpp);
    }

    notAVersionToken = ! isVersion;

    return token;
} // readCPPline
Beispiel #13
0
int TPpContext::readCPPline(TPpToken* ppToken)
{
    int token = scanToken(ppToken);

    if (token == PpAtomIdentifier) {
        switch (ppToken->atom) {
        case PpAtomDefine:
            token = CPPdefine(ppToken);
            break;
        case PpAtomElse:
            if (elsetracker[elseSeen])
                parseContext.ppError(ppToken->loc, "#else after #else", "#else", "");
            elsetracker[elseSeen] = true;
            if (! ifdepth)
                parseContext.ppError(ppToken->loc, "mismatched statements", "#else", "");
            token = extraTokenCheck(PpAtomElse, ppToken, scanToken(ppToken));
            token = CPPelse(0, ppToken);
            break;
        case PpAtomElif:
            if (! ifdepth)
                parseContext.ppError(ppToken->loc, "mismatched statements", "#elif", "");
            if (elseSeen[elsetracker])
                parseContext.ppError(ppToken->loc, "#elif after #else", "#elif", "");
            // this token is really a dont care, but we still need to eat the tokens
            token = scanToken(ppToken); 
            while (token != '\n' && token != EndOfInput)
                token = scanToken(ppToken);
            token = CPPelse(0, ppToken);
            break;
        case PpAtomEndif:
            elseSeen[elsetracker] = false;
            --elsetracker;
            if (! ifdepth)
                parseContext.ppError(ppToken->loc, "mismatched statements", "#endif", "");
            else
                --ifdepth;
            token = extraTokenCheck(PpAtomEndif, ppToken, scanToken(ppToken));
            break;
        case PpAtomIf:
            token = CPPif(ppToken);
            break;
        case PpAtomIfdef:
            token = CPPifdef(1, ppToken);
            break;
        case PpAtomIfndef:
            token = CPPifdef(0, ppToken);
            break;
        case PpAtomInclude:
            parseContext.ppRequireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_include_directive, "#include");
            token = CPPinclude(ppToken);
            break;
        case PpAtomLine:
            token = CPPline(ppToken);
            break;
        case PpAtomPragma:
            token = CPPpragma(ppToken);
            break;
        case PpAtomUndef:
            token = CPPundef(ppToken);
            break;
        case PpAtomError:
            token = CPPerror(ppToken);
            break;
        case PpAtomVersion:
            token = CPPversion(ppToken);
            break;
        case PpAtomExtension:
            token = CPPextension(ppToken);
            break;
        default:
            parseContext.ppError(ppToken->loc, "invalid directive:", "#", ppToken->name);
            break;
        }
    } else if (token != '\n' && token != EndOfInput)
        parseContext.ppError(ppToken->loc, "invalid directive", "#", "");

    while (token != '\n' && token != EndOfInput)
        token = scanToken(ppToken);

    return token;
}
Beispiel #14
0
int TPpContext::readCPPline(TPpToken* ppToken)
{
    int token = currentInput->scan(this, currentInput, ppToken);
    bool isVersion = false;

    if (token == CPP_IDENTIFIER) {
        if (ppToken->atom == defineAtom) {
            token = CPPdefine(ppToken);
        } else if (ppToken->atom == elseAtom) {
            if (! elsetracker[elseSeen]) {
                elsetracker[elseSeen] = true;
                if (! ifdepth)
                    parseContext.error(ppToken->loc, "mismatched statements", "#else", "");
                token = extraTokenCheck(elseAtom, ppToken, currentInput->scan(this, currentInput, ppToken));
                token = CPPelse(0, ppToken);
            } else {
                parseContext.error(ppToken->loc, "#else after a #else", "#else", "");
                ifdepth = 0;
                return 0;
            }
        } else if (ppToken->atom == elifAtom) {
            if (! ifdepth)
                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, ppToken); 
            while (token != '\n')
                token = currentInput->scan(this, currentInput, ppToken);
            token = CPPelse(0, ppToken);
        } else if (ppToken->atom == endifAtom) {
            elseSeen[elsetracker] = false;
            --elsetracker;
            if (! ifdepth)
                parseContext.error(ppToken->loc, "mismatched statements", "#endif", "");
            else
                --ifdepth;
            token = extraTokenCheck(endifAtom, ppToken, currentInput->scan(this, currentInput, ppToken));
        } 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 (ppToken->atom == extensionAtom) {
            token = CPPextension(ppToken);
        } else {
            parseContext.error(ppToken->loc, "invalid directive:", "#", GetAtomString(ppToken->atom));
        }
    } else if (token != '\n' && token > 0)
        parseContext.error(ppToken->loc, "invalid directive", "#", "");

    while (token != '\n' && token != 0 && token != EOF)
        token = currentInput->scan(this, currentInput, ppToken);

    return token;
}