Пример #1
0
static void lRead4Bytes(TokenStream *fTok, unsigned char *fVal)
{
    fVal[0] = (unsigned char ) lReadByte(fTok);
    fVal[1] = (unsigned char ) lReadByte(fTok);
    fVal[2] = (unsigned char ) lReadByte(fTok);
    fVal[3] = (unsigned char ) lReadByte(fTok);
} // lRead4Bytes
Пример #2
0
int ReadToken(TokenStream *pTok)
{
    char symbol_name[MAX_SYMBOL_NAME_LEN + 1];
    char string_val[MAX_STRING_LEN + 1];
    int ltoken, len;
    char ch;

    ltoken = lReadByte(pTok);
    if (ltoken >= 0) {
        if (ltoken > 127)
            ltoken += 128;
        //ltoken = lExpandToken(ltoken);
        switch (ltoken) {
        case IDENT_SY:
        case TYPEIDENT_SY:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= 'a' && ch <= 'z') ||
                     (ch >= 'A' && ch <= 'Z') ||
                     (ch >= '0' && ch <= '9') ||
                     ch == '_')
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len] = ch;
                    len++;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            yylval.sc_ident = LookUpAddString(atable, symbol_name);
            return IDENT_SY;
            break;
        case STRCONST_SY:
            len = 0;
            while ((ch = lReadByte(pTok)) != 0)
                if (len < MAX_STRING_LEN)
                    string_val[len++] = ch;
            string_val[len] = 0;
            yylval.sc_ident = LookUpAddString(atable, string_val);
            break;
        case CFLOATCONST_SY:
        case FLOATCONST_SY:
        case FLOATHCONST_SY:
        case FLOATXCONST_SY:
            lRead4Bytes(pTok, (unsigned char *) &yylval.sc_fval);
            break;
        case INTCONST_SY:
            lRead4Bytes(pTok, (unsigned char *) &yylval.sc_int);
            break;
        case '(':
            yylval.sc_int = lReadByte(pTok);
            break;
        }
        return ltoken;
    }
    return EOF_SY;
} // ReadToken
Пример #3
0
/*
* Read the next token from a token stream (not the source stream, but stream used to hold a tokenized macro).
*/
int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
{
    char* tokenText = ppToken->name;
    int ltoken, len;
    int ch;

    ltoken = lReadByte(pTok);
    ppToken->loc = parseContext.getCurrentLoc();
    if (ltoken > 127)
        ltoken += 128;
    switch (ltoken) {
    case '#':        
        if (lReadByte(pTok) == '#') {
            parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)");
            parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, 0, "token pasting (##)");
            parseContext.error(ppToken->loc, "token pasting not implemented (internal error)", "##", "");
            //return PpAtomPaste;
            return ReadToken(pTok, ppToken);
        } else
            lUnreadByte(pTok);
        break;
    case PpAtomConstString:
    case PpAtomIdentifier:
    case PpAtomConstFloat:
    case PpAtomConstDouble:
    case PpAtomConstInt:
    case PpAtomConstUint:
        len = 0;
        ch = lReadByte(pTok);
        while (ch != 0) {
            if (len < MaxTokenLength) {
                tokenText[len] = (char)ch;
                len++;
                ch = lReadByte(pTok);
            } else {
                parseContext.error(ppToken->loc, "token too long", "", "");
                break;
            }
        }
        tokenText[len] = 0;

        switch (ltoken) {
        case PpAtomIdentifier:
            ppToken->atom = LookUpAddString(tokenText);
            break;
        case PpAtomConstString:
            break;
        case PpAtomConstFloat:
        case PpAtomConstDouble:
            strcpy(ppToken->name, tokenText);
            ppToken->dval = atof(ppToken->name);
            break;
        case PpAtomConstInt:
        case PpAtomConstUint:
            strcpy(ppToken->name, tokenText);
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->ival = strtol(ppToken->name, 0, 16);
                else
                    ppToken->ival = strtol(ppToken->name, 0, 8);
            } else
                ppToken->ival = atoi(ppToken->name);
            break;
        }
    }

    return ltoken;
}
Пример #4
0
int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
{
    char symbol_name[MAX_SYMBOL_NAME_LEN + 1];
    char string_val[MAX_STRING_LEN + 1];
    int ltoken, len;
    char ch;

    ltoken = lReadByte(pTok);
    if (ltoken >= 0) {
        if (ltoken > 127)
            ltoken += 128;
        switch (ltoken) {
        case CPP_IDENTIFIER:
        case CPP_TYPEIDENTIFIER:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= 'a' && ch <= 'z') ||
                     (ch >= 'A' && ch <= 'Z') ||
                     (ch >= '0' && ch <= '9') ||
                     ch == '_')
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len++] = ch;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            yylvalpp->sc_ident = LookUpAddString(atable, symbol_name);
            return CPP_IDENTIFIER;
            break;
        case CPP_STRCONSTANT:
            len = 0;
            while ((ch = lReadByte(pTok)) != 0)
                if (len < MAX_STRING_LEN)
                    string_val[len++] = ch;
            string_val[len] = '\0';
            yylvalpp->sc_ident = LookUpAddString(atable, string_val);
            break;
        case CPP_FLOATCONSTANT:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= '0' && ch <= '9')||(ch=='e'||ch=='E'||ch=='.')||(ch=='+'||ch=='-'))
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len++] = ch;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            strcpy(yylvalpp->symbol_name,symbol_name);
            yylvalpp->sc_fval=(float)atof_dot(yylvalpp->symbol_name);
            break;
        case CPP_INTCONSTANT:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= '0' && ch <= '9'))
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len++] = ch;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            strcpy(yylvalpp->symbol_name,symbol_name);
            yylvalpp->sc_int=atoi(yylvalpp->symbol_name);
            break;
        case '(':
            yylvalpp->sc_int = lReadByte(pTok);
            break;
        }
        return ltoken;
    }
    return EOF_SY;
} // ReadToken
Пример #5
0
/*
* Read the next token from a token stream (not the source stream, but stream used to hold a tokenized macro).
*/
int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
{
    char* tokenText = ppToken->name;
    int ltoken, len;
    int ch;

    ltoken = lReadByte(pTok);
    ppToken->loc = parseContext.getCurrentLoc();
    if (ltoken > 127)
        ltoken += 128;
    switch (ltoken) {
    case '#':
        // Check for ##, unless the current # is the last character
        if (pTok->current < pTok->data.size()) {
            if (lReadByte(pTok) == '#') {
                parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)");
                parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, 0, "token pasting (##)");
                parseContext.error(ppToken->loc, "token pasting not implemented (internal error)", "##", "");
                //return PpAtomPaste;
                return ReadToken(pTok, ppToken);
            } else
                lUnreadByte(pTok);
        }
        break;
    case PpAtomConstString:
    case PpAtomIdentifier:
    case PpAtomConstFloat:
    case PpAtomConstDouble:
#ifdef AMD_EXTENSIONS
    case PpAtomConstFloat16:
#endif
    case PpAtomConstInt:
    case PpAtomConstUint:
    case PpAtomConstInt64:
    case PpAtomConstUint64:
        len = 0;
        ch = lReadByte(pTok);
        while (ch != 0 && ch != EndOfInput) {
            if (len < MaxTokenLength) {
                tokenText[len] = (char)ch;
                len++;
                ch = lReadByte(pTok);
            } else {
                parseContext.error(ppToken->loc, "token too long", "", "");
                break;
            }
        }
        tokenText[len] = 0;

        switch (ltoken) {
        case PpAtomIdentifier:
            ppToken->atom = LookUpAddString(tokenText);
            break;
        case PpAtomConstString:
            break;
        case PpAtomConstFloat:
        case PpAtomConstDouble:
#ifdef AMD_EXTENSIONS
        case PpAtomConstFloat16:
#endif
            ppToken->dval = atof(ppToken->name);
            break;
        case PpAtomConstInt:
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->ival = (int)strtol(ppToken->name, 0, 16);
                else
                    ppToken->ival = (int)strtol(ppToken->name, 0, 8);
            } else
                ppToken->ival = atoi(ppToken->name);
            break;
        case PpAtomConstUint:
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->ival = (int)strtoul(ppToken->name, 0, 16);
                else
                    ppToken->ival = (int)strtoul(ppToken->name, 0, 8);
            } else
                ppToken->ival = (int)strtoul(ppToken->name, 0, 10);
            break;
        case PpAtomConstInt64:
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->i64val = strtoll(ppToken->name, nullptr, 16);
                else
                    ppToken->i64val = strtoll(ppToken->name, nullptr, 8);
            } else
                ppToken->i64val = atoll(ppToken->name);
            break;
        case PpAtomConstUint64:
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->i64val = (long long)strtoull(ppToken->name, nullptr, 16);
                else
                    ppToken->i64val = (long long)strtoull(ppToken->name, nullptr, 8);
            } else
                ppToken->i64val = (long long)strtoull(ppToken->name, 0, 10);
            break;
        }
    }

    return ltoken;
}
Пример #6
0
/*
* Read the next token from a token stream (not the source stream, but stream used to hold a tokenized macro).
*/
int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
{
    char tokenText[TPpToken::maxTokenLength + 1];
    int ltoken, len;
    int ch;

    ltoken = lReadByte(pTok);
    ppToken->loc = parseContext.getCurrentLoc();
    if (ltoken > 127)
        ltoken += 128;
    switch (ltoken) {
    case '#':        
        if (lReadByte(pTok) == '#') {
            parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)");
            parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, 0, "token pasting (##)");
            parseContext.error(ppToken->loc, "token pasting not implemented (internal error)", "##", "");
            //return CPP_TOKEN_PASTE;
            return ReadToken(pTok, ppToken);
        } else
            lUnreadByte(pTok);
        break;
    case CPP_STRCONSTANT:
    case CPP_IDENTIFIER:
    case CPP_FLOATCONSTANT:
    case CPP_DOUBLECONSTANT:
    case CPP_INTCONSTANT:
    case CPP_UINTCONSTANT:
        len = 0;
        ch = lReadByte(pTok);
        while (ch != 0) {
            if (len < TPpToken::maxTokenLength) {
                tokenText[len] = ch;
                len++;
                ch = lReadByte(pTok);
            } else {
                parseContext.error(ppToken->loc, "token too long", "", "");
                break;
            }
        }
        tokenText[len] = 0;

        switch (ltoken) {
        case CPP_IDENTIFIER:
        case CPP_STRCONSTANT:
            ppToken->atom = LookUpAddString(tokenText);
            break;
        case CPP_FLOATCONSTANT:
        case CPP_DOUBLECONSTANT:
            strcpy(ppToken->name, tokenText);
            ppToken->dval = atof(ppToken->name);
            break;
        case CPP_INTCONSTANT:
        case CPP_UINTCONSTANT:
            strcpy(ppToken->name, tokenText);
            if (len > 0 && tokenText[0] == '0') {
                if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                    ppToken->ival = strtol(ppToken->name, 0, 16);
                else
                    ppToken->ival = strtol(ppToken->name, 0, 8);
            } else
                ppToken->ival = atoi(ppToken->name);
            break;
        }
    }

    return ltoken;
}
Пример #7
0
int ReadToken(TokenStream *pTok, yystypepp * yylvalpp)
{
    char symbol_name[MAX_SYMBOL_NAME_LEN + 1];
    char string_val[MAX_STRING_LEN + 1];
    int ltoken, len;
    char ch;
    int base, accum;
    char ch_val;

    ltoken = lReadByte(pTok);
    if (ltoken >= 0) {
        if (ltoken > 127)
            ltoken += 128;
        switch (ltoken) {
        case CPP_IDENTIFIER:
        case CPP_TYPEIDENTIFIER:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= 'a' && ch <= 'z') ||
                     (ch >= 'A' && ch <= 'Z') ||
                     (ch >= '0' && ch <= '9') ||
                     ch == '_')
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len++] = ch;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            yylvalpp->sc_ident = LookUpAddString(atable, symbol_name);
            return CPP_IDENTIFIER;
            break;
        case CPP_STRCONSTANT:
            len = 0;
            while ((ch = lReadByte(pTok)) != 0)
                if (len < MAX_STRING_LEN)
                    string_val[len++] = ch;
            string_val[len] = '\0';
            yylvalpp->sc_ident = LookUpAddString(atable, string_val);
            break;
        case CPP_FLOATCONSTANT:
            len = 0;
            ch = lReadByte(pTok);
            while ((ch >= '0' && ch <= '9')||(ch=='e'||ch=='E'||ch=='.')||(ch=='+'||ch=='-'))
            {
                if (len < MAX_SYMBOL_NAME_LEN) {
                    symbol_name[len++] = ch;
                    ch = lReadByte(pTok);
                }
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            strcpy(yylvalpp->symbol_name,symbol_name);
            yylvalpp->sc_fval=(float)atof_dot(yylvalpp->symbol_name);
            break;
        case CPP_INTCONSTANT:
            len = 0;
	    accum = 0;
            ch = lReadByte(pTok);
            if (ch == '0') {
                symbol_name[len++] = ch;
                ch = lReadByte(pTok);
                if (ch == 'x' || ch == 'X') {
                    symbol_name[len++] = ch;
                    base = 16;
                    ch = lReadByte(pTok);
                } else {
                    base = 8;
                }
            } else {
                base = 10;
            }

            while (len < MAX_SYMBOL_NAME_LEN)
            {
                ch_val = -1;
                if (isdigit(ch))
                    ch_val = ch - '0';
                else if (isxdigit(ch))
                    ch_val = tolower(ch) - 'a' + 10;

                if (ch_val < 0 || ch_val >= base)
                    break;

                symbol_name[len++] = ch;
                accum = accum * base + ch_val;
                ch = lReadByte(pTok);
            }
            symbol_name[len] = '\0';
            assert(ch == '\0');
            strcpy(yylvalpp->symbol_name, symbol_name);
            yylvalpp->sc_int = accum;
            break;
        case '(':
            yylvalpp->sc_int = lReadByte(pTok);
            break;
        }
        return ltoken;
    }
    return EOF_SY;
} // ReadToken