OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.26/] [lcc/] [cpp/] [eval.c] - Diff between revs 4 and 270

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 270
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "cpp.h"
#include "cpp.h"
 
 
#define NSTAK   32
#define NSTAK   32
#define SGN     0
#define SGN     0
#define UNS     1
#define UNS     1
#define UND     2
#define UND     2
 
 
#define UNSMARK 0x1000
#define UNSMARK 0x1000
 
 
struct value {
struct value {
        long    val;
        long    val;
        int     type;
        int     type;
};
};
 
 
/* conversion types */
/* conversion types */
#define RELAT   1
#define RELAT   1
#define ARITH   2
#define ARITH   2
#define LOGIC   3
#define LOGIC   3
#define SPCL    4
#define SPCL    4
#define SHIFT   5
#define SHIFT   5
#define UNARY   6
#define UNARY   6
 
 
/* operator priority, arity, and conversion type, indexed by tokentype */
/* operator priority, arity, and conversion type, indexed by tokentype */
struct pri {
struct pri {
        char    pri;
        char    pri;
        char    arity;
        char    arity;
        char    ctype;
        char    ctype;
} priority[] = {
} priority[] = {
        { 0, 0, 0 },               /* END */
        { 0, 0, 0 },               /* END */
        { 0, 0, 0 },               /* UNCLASS */
        { 0, 0, 0 },               /* UNCLASS */
        { 0, 0, 0 },               /* NAME */
        { 0, 0, 0 },               /* NAME */
        { 0, 0, 0 },               /* NUMBER */
        { 0, 0, 0 },               /* NUMBER */
        { 0, 0, 0 },               /* STRING */
        { 0, 0, 0 },               /* STRING */
        { 0, 0, 0 },               /* CCON */
        { 0, 0, 0 },               /* CCON */
        { 0, 0, 0 },               /* NL */
        { 0, 0, 0 },               /* NL */
        { 0, 0, 0 },               /* WS */
        { 0, 0, 0 },               /* WS */
        { 0, 0, 0 },               /* DSHARP */
        { 0, 0, 0 },               /* DSHARP */
        { 11, 2, RELAT },       /* EQ */
        { 11, 2, RELAT },       /* EQ */
        { 11, 2, RELAT },       /* NEQ */
        { 11, 2, RELAT },       /* NEQ */
        { 12, 2, RELAT },       /* LEQ */
        { 12, 2, RELAT },       /* LEQ */
        { 12, 2, RELAT },       /* GEQ */
        { 12, 2, RELAT },       /* GEQ */
        { 13, 2, SHIFT },       /* LSH */
        { 13, 2, SHIFT },       /* LSH */
        { 13, 2, SHIFT },       /* RSH */
        { 13, 2, SHIFT },       /* RSH */
        { 7, 2, LOGIC },        /* LAND */
        { 7, 2, LOGIC },        /* LAND */
        { 6, 2, LOGIC },        /* LOR */
        { 6, 2, LOGIC },        /* LOR */
        { 0, 0, 0 },               /* PPLUS */
        { 0, 0, 0 },               /* PPLUS */
        { 0, 0, 0 },               /* MMINUS */
        { 0, 0, 0 },               /* MMINUS */
        { 0, 0, 0 },               /* ARROW */
        { 0, 0, 0 },               /* ARROW */
        { 0, 0, 0 },               /* SBRA */
        { 0, 0, 0 },               /* SBRA */
        { 0, 0, 0 },               /* SKET */
        { 0, 0, 0 },               /* SKET */
        { 3, 0, 0 },              /* LP */
        { 3, 0, 0 },              /* LP */
        { 3, 0, 0 },              /* RP */
        { 3, 0, 0 },              /* RP */
        { 0, 0, 0 },               /* DOT */
        { 0, 0, 0 },               /* DOT */
        { 10, 2, ARITH },       /* AND */
        { 10, 2, ARITH },       /* AND */
        { 15, 2, ARITH },       /* STAR */
        { 15, 2, ARITH },       /* STAR */
        { 14, 2, ARITH },       /* PLUS */
        { 14, 2, ARITH },       /* PLUS */
        { 14, 2, ARITH },       /* MINUS */
        { 14, 2, ARITH },       /* MINUS */
        { 16, 1, UNARY },       /* TILDE */
        { 16, 1, UNARY },       /* TILDE */
        { 16, 1, UNARY },       /* NOT */
        { 16, 1, UNARY },       /* NOT */
        { 15, 2, ARITH },       /* SLASH */
        { 15, 2, ARITH },       /* SLASH */
        { 15, 2, ARITH },       /* PCT */
        { 15, 2, ARITH },       /* PCT */
        { 12, 2, RELAT },       /* LT */
        { 12, 2, RELAT },       /* LT */
        { 12, 2, RELAT },       /* GT */
        { 12, 2, RELAT },       /* GT */
        { 9, 2, ARITH },        /* CIRC */
        { 9, 2, ARITH },        /* CIRC */
        { 8, 2, ARITH },        /* OR */
        { 8, 2, ARITH },        /* OR */
        { 5, 2, SPCL },         /* QUEST */
        { 5, 2, SPCL },         /* QUEST */
        { 5, 2, SPCL },         /* COLON */
        { 5, 2, SPCL },         /* COLON */
        { 0, 0, 0 },               /* ASGN */
        { 0, 0, 0 },               /* ASGN */
        { 4, 2, 0 },             /* COMMA */
        { 4, 2, 0 },             /* COMMA */
        { 0, 0, 0 },               /* SHARP */
        { 0, 0, 0 },               /* SHARP */
        { 0, 0, 0 },               /* SEMIC */
        { 0, 0, 0 },               /* SEMIC */
        { 0, 0, 0 },               /* CBRA */
        { 0, 0, 0 },               /* CBRA */
        { 0, 0, 0 },               /* CKET */
        { 0, 0, 0 },               /* CKET */
        { 0, 0, 0 },               /* ASPLUS */
        { 0, 0, 0 },               /* ASPLUS */
        { 0, 0, 0 },               /* ASMINUS */
        { 0, 0, 0 },               /* ASMINUS */
        { 0, 0, 0 },               /* ASSTAR */
        { 0, 0, 0 },               /* ASSTAR */
        { 0, 0, 0 },               /* ASSLASH */
        { 0, 0, 0 },               /* ASSLASH */
        { 0, 0, 0 },               /* ASPCT */
        { 0, 0, 0 },               /* ASPCT */
        { 0, 0, 0 },               /* ASCIRC */
        { 0, 0, 0 },               /* ASCIRC */
        { 0, 0, 0 },               /* ASLSH */
        { 0, 0, 0 },               /* ASLSH */
        { 0, 0, 0 },               /* ASRSH */
        { 0, 0, 0 },               /* ASRSH */
        { 0, 0, 0 },               /* ASOR */
        { 0, 0, 0 },               /* ASOR */
        { 0, 0, 0 },               /* ASAND */
        { 0, 0, 0 },               /* ASAND */
        { 0, 0, 0 },               /* ELLIPS */
        { 0, 0, 0 },               /* ELLIPS */
        { 0, 0, 0 },               /* DSHARP1 */
        { 0, 0, 0 },               /* DSHARP1 */
        { 0, 0, 0 },               /* NAME1 */
        { 0, 0, 0 },               /* NAME1 */
        { 16, 1, UNARY },       /* DEFINED */
        { 16, 1, UNARY },       /* DEFINED */
        { 16, 0, UNARY },        /* UMINUS */
        { 16, 0, UNARY },        /* UMINUS */
};
};
 
 
int     evalop(struct pri);
int     evalop(struct pri);
struct  value tokval(Token *);
struct  value tokval(Token *);
struct value vals[NSTAK], *vp;
struct value vals[NSTAK], *vp;
enum toktype ops[NSTAK], *op;
enum toktype ops[NSTAK], *op;
 
 
/*
/*
 * Evaluate an #if #elif #ifdef #ifndef line.  trp->tp points to the keyword.
 * Evaluate an #if #elif #ifdef #ifndef line.  trp->tp points to the keyword.
 */
 */
long
long
eval(Tokenrow *trp, int kw)
eval(Tokenrow *trp, int kw)
{
{
        Token *tp;
        Token *tp;
        Nlist *np;
        Nlist *np;
        int ntok, rand;
        int ntok, rand;
 
 
        trp->tp++;
        trp->tp++;
        if (kw==KIFDEF || kw==KIFNDEF) {
        if (kw==KIFDEF || kw==KIFNDEF) {
                if (trp->lp - trp->bp != 4 || trp->tp->type!=NAME) {
                if (trp->lp - trp->bp != 4 || trp->tp->type!=NAME) {
                        error(ERROR, "Syntax error in #ifdef/#ifndef");
                        error(ERROR, "Syntax error in #ifdef/#ifndef");
                        return 0;
                        return 0;
                }
                }
                np = lookup(trp->tp, 0);
                np = lookup(trp->tp, 0);
                return (kw==KIFDEF) == (np && np->flag&(ISDEFINED|ISMAC));
                return (kw==KIFDEF) == (np && np->flag&(ISDEFINED|ISMAC));
        }
        }
        ntok = trp->tp - trp->bp;
        ntok = trp->tp - trp->bp;
        kwdefined->val = KDEFINED;      /* activate special meaning of defined */
        kwdefined->val = KDEFINED;      /* activate special meaning of defined */
        expandrow(trp, "<if>");
        expandrow(trp, "<if>");
        kwdefined->val = NAME;
        kwdefined->val = NAME;
        vp = vals;
        vp = vals;
        op = ops;
        op = ops;
        *op++ = END;
        *op++ = END;
        for (rand=0, tp = trp->bp+ntok; tp < trp->lp; tp++) {
        for (rand=0, tp = trp->bp+ntok; tp < trp->lp; tp++) {
                switch(tp->type) {
                switch(tp->type) {
                case WS:
                case WS:
                case NL:
                case NL:
                        continue;
                        continue;
 
 
                /* nilary */
                /* nilary */
                case NAME:
                case NAME:
                case NAME1:
                case NAME1:
                case NUMBER:
                case NUMBER:
                case CCON:
                case CCON:
                case STRING:
                case STRING:
                        if (rand)
                        if (rand)
                                goto syntax;
                                goto syntax;
                        if (vp == &vals[NSTAK]) {
                        if (vp == &vals[NSTAK]) {
                                error(ERROR, "Eval botch (stack overflow)");
                                error(ERROR, "Eval botch (stack overflow)");
                                return 0;
                                return 0;
                        }
                        }
                        *vp++ = tokval(tp);
                        *vp++ = tokval(tp);
                        rand = 1;
                        rand = 1;
                        continue;
                        continue;
 
 
                /* unary */
                /* unary */
                case DEFINED:
                case DEFINED:
                case TILDE:
                case TILDE:
                case NOT:
                case NOT:
                        if (rand)
                        if (rand)
                                goto syntax;
                                goto syntax;
                        *op++ = tp->type;
                        *op++ = tp->type;
                        continue;
                        continue;
 
 
                /* unary-binary */
                /* unary-binary */
                case PLUS: case MINUS: case STAR: case AND:
                case PLUS: case MINUS: case STAR: case AND:
                        if (rand==0) {
                        if (rand==0) {
                                if (tp->type==MINUS)
                                if (tp->type==MINUS)
                                        *op++ = UMINUS;
                                        *op++ = UMINUS;
                                if (tp->type==STAR || tp->type==AND) {
                                if (tp->type==STAR || tp->type==AND) {
                                        error(ERROR, "Illegal operator * or & in #if/#elsif");
                                        error(ERROR, "Illegal operator * or & in #if/#elsif");
                                        return 0;
                                        return 0;
                                }
                                }
                                continue;
                                continue;
                        }
                        }
                        /* flow through */
                        /* flow through */
 
 
                /* plain binary */
                /* plain binary */
                case EQ: case NEQ: case LEQ: case GEQ: case LSH: case RSH:
                case EQ: case NEQ: case LEQ: case GEQ: case LSH: case RSH:
                case LAND: case LOR: case SLASH: case PCT:
                case LAND: case LOR: case SLASH: case PCT:
                case LT: case GT: case CIRC: case OR: case QUEST:
                case LT: case GT: case CIRC: case OR: case QUEST:
                case COLON: case COMMA:
                case COLON: case COMMA:
                        if (rand==0)
                        if (rand==0)
                                goto syntax;
                                goto syntax;
                        if (evalop(priority[tp->type])!=0)
                        if (evalop(priority[tp->type])!=0)
                                return 0;
                                return 0;
                        *op++ = tp->type;
                        *op++ = tp->type;
                        rand = 0;
                        rand = 0;
                        continue;
                        continue;
 
 
                case LP:
                case LP:
                        if (rand)
                        if (rand)
                                goto syntax;
                                goto syntax;
                        *op++ = LP;
                        *op++ = LP;
                        continue;
                        continue;
 
 
                case RP:
                case RP:
                        if (!rand)
                        if (!rand)
                                goto syntax;
                                goto syntax;
                        if (evalop(priority[RP])!=0)
                        if (evalop(priority[RP])!=0)
                                return 0;
                                return 0;
                        if (op<=ops || op[-1]!=LP) {
                        if (op<=ops || op[-1]!=LP) {
                                goto syntax;
                                goto syntax;
                        }
                        }
                        op--;
                        op--;
                        continue;
                        continue;
 
 
                default:
                default:
                        error(ERROR,"Bad operator (%t) in #if/#elsif", tp);
                        error(ERROR,"Bad operator (%t) in #if/#elsif", tp);
                        return 0;
                        return 0;
                }
                }
        }
        }
        if (rand==0)
        if (rand==0)
                goto syntax;
                goto syntax;
        if (evalop(priority[END])!=0)
        if (evalop(priority[END])!=0)
                return 0;
                return 0;
        if (op!=&ops[1] || vp!=&vals[1]) {
        if (op!=&ops[1] || vp!=&vals[1]) {
                error(ERROR, "Botch in #if/#elsif");
                error(ERROR, "Botch in #if/#elsif");
                return 0;
                return 0;
        }
        }
        if (vals[0].type==UND)
        if (vals[0].type==UND)
                error(ERROR, "Undefined expression value");
                error(ERROR, "Undefined expression value");
        return vals[0].val;
        return vals[0].val;
syntax:
syntax:
        error(ERROR, "Syntax error in #if/#elsif");
        error(ERROR, "Syntax error in #if/#elsif");
        return 0;
        return 0;
}
}
 
 
int
int
evalop(struct pri pri)
evalop(struct pri pri)
{
{
        struct value v1, v2;
        struct value v1, v2;
        long rv1, rv2;
        long rv1, rv2;
        int rtype, oper;
        int rtype, oper;
 
 
        rv2=0;
        rv2=0;
        rtype=0;
        rtype=0;
        while (pri.pri < priority[op[-1]].pri) {
        while (pri.pri < priority[op[-1]].pri) {
                oper = *--op;
                oper = *--op;
                if (priority[oper].arity==2) {
                if (priority[oper].arity==2) {
                        v2 = *--vp;
                        v2 = *--vp;
                        rv2 = v2.val;
                        rv2 = v2.val;
                }
                }
                v1 = *--vp;
                v1 = *--vp;
                rv1 = v1.val;
                rv1 = v1.val;
/*lint -e574 -e644 */
/*lint -e574 -e644 */
                switch (priority[oper].ctype) {
                switch (priority[oper].ctype) {
                case 0:
                case 0:
                default:
                default:
                        error(WARNING, "Syntax error in #if/#endif");
                        error(WARNING, "Syntax error in #if/#endif");
                        return 1;
                        return 1;
                case ARITH:
                case ARITH:
                case RELAT:
                case RELAT:
                        if (v1.type==UNS || v2.type==UNS)
                        if (v1.type==UNS || v2.type==UNS)
                                rtype = UNS;
                                rtype = UNS;
                        else
                        else
                                rtype = SGN;
                                rtype = SGN;
                        if (v1.type==UND || v2.type==UND)
                        if (v1.type==UND || v2.type==UND)
                                rtype = UND;
                                rtype = UND;
                        if (priority[oper].ctype==RELAT && rtype==UNS) {
                        if (priority[oper].ctype==RELAT && rtype==UNS) {
                                oper |= UNSMARK;
                                oper |= UNSMARK;
                                rtype = SGN;
                                rtype = SGN;
                        }
                        }
                        break;
                        break;
                case SHIFT:
                case SHIFT:
                        if (v1.type==UND || v2.type==UND)
                        if (v1.type==UND || v2.type==UND)
                                rtype = UND;
                                rtype = UND;
                        else
                        else
                                rtype = v1.type;
                                rtype = v1.type;
                        if (rtype==UNS)
                        if (rtype==UNS)
                                oper |= UNSMARK;
                                oper |= UNSMARK;
                        break;
                        break;
                case UNARY:
                case UNARY:
                        rtype = v1.type;
                        rtype = v1.type;
                        break;
                        break;
                case LOGIC:
                case LOGIC:
                case SPCL:
                case SPCL:
                        break;
                        break;
                }
                }
                switch (oper) {
                switch (oper) {
                case EQ: case EQ|UNSMARK:
                case EQ: case EQ|UNSMARK:
                        rv1 = rv1==rv2; break;
                        rv1 = rv1==rv2; break;
                case NEQ: case NEQ|UNSMARK:
                case NEQ: case NEQ|UNSMARK:
                        rv1 = rv1!=rv2; break;
                        rv1 = rv1!=rv2; break;
                case LEQ:
                case LEQ:
                        rv1 = rv1<=rv2; break;
                        rv1 = rv1<=rv2; break;
                case GEQ:
                case GEQ:
                        rv1 = rv1>=rv2; break;
                        rv1 = rv1>=rv2; break;
                case LT:
                case LT:
                        rv1 = rv1<rv2; break;
                        rv1 = rv1<rv2; break;
                case GT:
                case GT:
                        rv1 = rv1>rv2; break;
                        rv1 = rv1>rv2; break;
                case LEQ|UNSMARK:
                case LEQ|UNSMARK:
                        rv1 = (unsigned long)rv1<=rv2; break;
                        rv1 = (unsigned long)rv1<=rv2; break;
                case GEQ|UNSMARK:
                case GEQ|UNSMARK:
                        rv1 = (unsigned long)rv1>=rv2; break;
                        rv1 = (unsigned long)rv1>=rv2; break;
                case LT|UNSMARK:
                case LT|UNSMARK:
                        rv1 = (unsigned long)rv1<rv2; break;
                        rv1 = (unsigned long)rv1<rv2; break;
                case GT|UNSMARK:
                case GT|UNSMARK:
                        rv1 = (unsigned long)rv1>rv2; break;
                        rv1 = (unsigned long)rv1>rv2; break;
                case LSH:
                case LSH:
                        rv1 <<= rv2; break;
                        rv1 <<= rv2; break;
                case LSH|UNSMARK:
                case LSH|UNSMARK:
                        rv1 = (unsigned long)rv1<<rv2; break;
                        rv1 = (unsigned long)rv1<<rv2; break;
                case RSH:
                case RSH:
                        rv1 >>= rv2; break;
                        rv1 >>= rv2; break;
                case RSH|UNSMARK:
                case RSH|UNSMARK:
                        rv1 = (unsigned long)rv1>>rv2; break;
                        rv1 = (unsigned long)rv1>>rv2; break;
                case LAND:
                case LAND:
                        rtype = UND;
                        rtype = UND;
                        if (v1.type==UND)
                        if (v1.type==UND)
                                break;
                                break;
                        if (rv1!=0) {
                        if (rv1!=0) {
                                if (v2.type==UND)
                                if (v2.type==UND)
                                        break;
                                        break;
                                rv1 = rv2!=0;
                                rv1 = rv2!=0;
                        } else
                        } else
                                rv1 = 0;
                                rv1 = 0;
                        rtype = SGN;
                        rtype = SGN;
                        break;
                        break;
                case LOR:
                case LOR:
                        rtype = UND;
                        rtype = UND;
                        if (v1.type==UND)
                        if (v1.type==UND)
                                break;
                                break;
                        if (rv1==0) {
                        if (rv1==0) {
                                if (v2.type==UND)
                                if (v2.type==UND)
                                        break;
                                        break;
                                rv1 = rv2!=0;
                                rv1 = rv2!=0;
                        } else
                        } else
                                rv1 = 1;
                                rv1 = 1;
                        rtype = SGN;
                        rtype = SGN;
                        break;
                        break;
                case AND:
                case AND:
                        rv1 &= rv2; break;
                        rv1 &= rv2; break;
                case STAR:
                case STAR:
                        rv1 *= rv2; break;
                        rv1 *= rv2; break;
                case PLUS:
                case PLUS:
                        rv1 += rv2; break;
                        rv1 += rv2; break;
                case MINUS:
                case MINUS:
                        rv1 -= rv2; break;
                        rv1 -= rv2; break;
                case UMINUS:
                case UMINUS:
                        if (v1.type==UND)
                        if (v1.type==UND)
                                rtype = UND;
                                rtype = UND;
                        rv1 = -rv1; break;
                        rv1 = -rv1; break;
                case OR:
                case OR:
                        rv1 |= rv2; break;
                        rv1 |= rv2; break;
                case CIRC:
                case CIRC:
                        rv1 ^= rv2; break;
                        rv1 ^= rv2; break;
                case TILDE:
                case TILDE:
                        rv1 = ~rv1; break;
                        rv1 = ~rv1; break;
                case NOT:
                case NOT:
                        rv1 = !rv1; if (rtype!=UND) rtype = SGN; break;
                        rv1 = !rv1; if (rtype!=UND) rtype = SGN; break;
                case SLASH:
                case SLASH:
                        if (rv2==0) {
                        if (rv2==0) {
                                rtype = UND;
                                rtype = UND;
                                break;
                                break;
                        }
                        }
                        if (rtype==UNS)
                        if (rtype==UNS)
                                rv1 /= (unsigned long)rv2;
                                rv1 /= (unsigned long)rv2;
                        else
                        else
                                rv1 /= rv2;
                                rv1 /= rv2;
                        break;
                        break;
                case PCT:
                case PCT:
                        if (rv2==0) {
                        if (rv2==0) {
                                rtype = UND;
                                rtype = UND;
                                break;
                                break;
                        }
                        }
                        if (rtype==UNS)
                        if (rtype==UNS)
                                rv1 %= (unsigned long)rv2;
                                rv1 %= (unsigned long)rv2;
                        else
                        else
                                rv1 %= rv2;
                                rv1 %= rv2;
                        break;
                        break;
                case COLON:
                case COLON:
                        if (op[-1] != QUEST)
                        if (op[-1] != QUEST)
                                error(ERROR, "Bad ?: in #if/endif");
                                error(ERROR, "Bad ?: in #if/endif");
                        else {
                        else {
                                op--;
                                op--;
                                if ((--vp)->val==0)
                                if ((--vp)->val==0)
                                        v1 = v2;
                                        v1 = v2;
                                rtype = v1.type;
                                rtype = v1.type;
                                rv1 = v1.val;
                                rv1 = v1.val;
                        }
                        }
                        break;
                        break;
                case DEFINED:
                case DEFINED:
                        break;
                        break;
                default:
                default:
                        error(ERROR, "Eval botch (unknown operator)");
                        error(ERROR, "Eval botch (unknown operator)");
                        return 1;
                        return 1;
                }
                }
/*lint +e574 +e644 */
/*lint +e574 +e644 */
                v1.val = rv1;
                v1.val = rv1;
                v1.type = rtype;
                v1.type = rtype;
                if (vp == &vals[NSTAK]) {
                if (vp == &vals[NSTAK]) {
                        error(ERROR, "Eval botch (stack overflow)");
                        error(ERROR, "Eval botch (stack overflow)");
                        return 0;
                        return 0;
                }
                }
                *vp++ = v1;
                *vp++ = v1;
        }
        }
        return 0;
        return 0;
}
}
 
 
struct value
struct value
tokval(Token *tp)
tokval(Token *tp)
{
{
        struct value v;
        struct value v;
        Nlist *np;
        Nlist *np;
        int i, base, c;
        int i, base, c;
        unsigned long n;
        unsigned long n;
        uchar *p;
        uchar *p;
 
 
        v.type = SGN;
        v.type = SGN;
        v.val = 0;
        v.val = 0;
        switch (tp->type) {
        switch (tp->type) {
 
 
        case NAME:
        case NAME:
                v.val = 0;
                v.val = 0;
                break;
                break;
 
 
        case NAME1:
        case NAME1:
                if ((np = lookup(tp, 0)) != NULL && np->flag&(ISDEFINED|ISMAC))
                if ((np = lookup(tp, 0)) != NULL && np->flag&(ISDEFINED|ISMAC))
                        v.val = 1;
                        v.val = 1;
                break;
                break;
 
 
        case NUMBER:
        case NUMBER:
                n = 0;
                n = 0;
                base = 10;
                base = 10;
                p = tp->t;
                p = tp->t;
                c = p[tp->len];
                c = p[tp->len];
                p[tp->len] = '\0';
                p[tp->len] = '\0';
                if (*p=='0') {
                if (*p=='0') {
                        base = 8;
                        base = 8;
                        if (p[1]=='x' || p[1]=='X') {
                        if (p[1]=='x' || p[1]=='X') {
                                base = 16;
                                base = 16;
                                p++;
                                p++;
                        }
                        }
                        p++;
                        p++;
                }
                }
                for (;; p++) {
                for (;; p++) {
                        if ((i = digit(*p)) < 0)
                        if ((i = digit(*p)) < 0)
                                break;
                                break;
                        if (i>=base)
                        if (i>=base)
                                error(WARNING,
                                error(WARNING,
                                  "Bad digit in number %t", tp);
                                  "Bad digit in number %t", tp);
                        n *= base;
                        n *= base;
                        n += i;
                        n += i;
                }
                }
                if (n>=0x80000000 && base!=10)
                if (n>=0x80000000 && base!=10)
                        v.type = UNS;
                        v.type = UNS;
                for (; *p; p++) {
                for (; *p; p++) {
                        if (*p=='u' || *p=='U')
                        if (*p=='u' || *p=='U')
                                v.type = UNS;
                                v.type = UNS;
                        else if (*p=='l' || *p=='L')
                        else if (*p=='l' || *p=='L')
                                ;
                                ;
                        else {
                        else {
                                error(ERROR,
                                error(ERROR,
                                  "Bad number %t in #if/#elsif", tp);
                                  "Bad number %t in #if/#elsif", tp);
                                break;
                                break;
                        }
                        }
                }
                }
                v.val = n;
                v.val = n;
                tp->t[tp->len] = c;
                tp->t[tp->len] = c;
                break;
                break;
 
 
        case CCON:
        case CCON:
                n = 0;
                n = 0;
                p = tp->t;
                p = tp->t;
                if (*p=='L') {
                if (*p=='L') {
                        p += 1;
                        p += 1;
                        error(WARNING, "Wide char constant value undefined");
                        error(WARNING, "Wide char constant value undefined");
                }
                }
                p += 1;
                p += 1;
                if (*p=='\\') {
                if (*p=='\\') {
                        p += 1;
                        p += 1;
                        if ((i = digit(*p))>=0 && i<=7) {
                        if ((i = digit(*p))>=0 && i<=7) {
                                n = i;
                                n = i;
                                p += 1;
                                p += 1;
                                if ((i = digit(*p))>=0 && i<=7) {
                                if ((i = digit(*p))>=0 && i<=7) {
                                        p += 1;
                                        p += 1;
                                        n <<= 3;
                                        n <<= 3;
                                        n += i;
                                        n += i;
                                        if ((i = digit(*p))>=0 && i<=7) {
                                        if ((i = digit(*p))>=0 && i<=7) {
                                                p += 1;
                                                p += 1;
                                                n <<= 3;
                                                n <<= 3;
                                                n += i;
                                                n += i;
                                        }
                                        }
                                }
                                }
                        } else if (*p=='x') {
                        } else if (*p=='x') {
                                p += 1;
                                p += 1;
                                while ((i = digit(*p))>=0 && i<=15) {
                                while ((i = digit(*p))>=0 && i<=15) {
                                        p += 1;
                                        p += 1;
                                        n <<= 4;
                                        n <<= 4;
                                        n += i;
                                        n += i;
                                }
                                }
                        } else {
                        } else {
                                static char cvcon[]
                                static char cvcon[]
                                  = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
                                  = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
                                for (i=0; i<sizeof(cvcon); i+=2) {
                                for (i=0; i<sizeof(cvcon); i+=2) {
                                        if (*p == cvcon[i]) {
                                        if (*p == cvcon[i]) {
                                                n = cvcon[i+1];
                                                n = cvcon[i+1];
                                                break;
                                                break;
                                        }
                                        }
                                }
                                }
                                p += 1;
                                p += 1;
                                if (i>=sizeof(cvcon))
                                if (i>=sizeof(cvcon))
                                        error(WARNING,
                                        error(WARNING,
                                         "Undefined escape in character constant");
                                         "Undefined escape in character constant");
                        }
                        }
                } else if (*p=='\'')
                } else if (*p=='\'')
                        error(ERROR, "Empty character constant");
                        error(ERROR, "Empty character constant");
                else
                else
                        n = *p++;
                        n = *p++;
                if (*p!='\'')
                if (*p!='\'')
                        error(WARNING, "Multibyte character constant undefined");
                        error(WARNING, "Multibyte character constant undefined");
                else if (n>127)
                else if (n>127)
                        error(WARNING, "Character constant taken as not signed");
                        error(WARNING, "Character constant taken as not signed");
                v.val = n;
                v.val = n;
                break;
                break;
 
 
        case STRING:
        case STRING:
                error(ERROR, "String in #if/#elsif");
                error(ERROR, "String in #if/#elsif");
                break;
                break;
        }
        }
        return v;
        return v;
}
}
 
 
int
int
digit(int i)
digit(int i)
{
{
        if ('0'<=i && i<='9')
        if ('0'<=i && i<='9')
                i -= '0';
                i -= '0';
        else if ('a'<=i && i<='f')
        else if ('a'<=i && i<='f')
                i -= 'a'-10;
                i -= 'a'-10;
        else if ('A'<=i && i<='F')
        else if ('A'<=i && i<='F')
                i -= 'A'-10;
                i -= 'A'-10;
        else
        else
                i = -1;
                i = -1;
        return i;
        return i;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.