1: # include   "../ingres.h"
   2: # include   "../aux.h"
   3: # include   "../tree.h"
   4: # include   "../symbol.h"
   5: # include   "ovqp.h"
   6: /*
   7: ** TYPECHECK
   8: **
   9: **	Performs typechecking and conversions where appropriate .
  10: **	Prohibits mixed type expressions.
  11: */
  12: 
  13: typecheck(pp1, pp2, opval)
  14: struct symbol   *pp1, *pp2;
  15: int     opval;
  16: {
  17:     register struct symbol  *p1, *p2;
  18:     register int        i;
  19: 
  20:     p1 = pp1;
  21:     p2 = pp2;
  22: 
  23:     i = (p1->type == CHAR & p2->type == CHAR);  /* c is true only if both are chars */
  24:     switch (opval)
  25:     {
  26: 
  27:       case opCONCAT:
  28:         if (!i)
  29:             ov_err(NUMERIC);    /* numeric in a char operator */
  30:         return; /* else no further checking is needed */
  31: 
  32:       case opADD:
  33:       case opSUB:
  34:       case opMUL:
  35:       case opDIV:
  36:       case opPOW:
  37:       case opMOD:
  38:         if (i)
  39:             ov_err(BADCHAR);    /* arithmetic operation on two character fields */
  40:     }
  41: 
  42:     /* first check for identical types of symbols */
  43:     if (p1->type == p2->type)
  44:     {
  45:         if (p1->len == p2->len)
  46:             return;
  47:         /* lengths are different. make p2 point to the smaller one */
  48:         if (p1->len < p2->len)
  49:         {
  50:             p2 = p1;
  51:             p1 = pp2;
  52:         }
  53: 
  54:         switch (p2->type)
  55:         {
  56: 
  57:           case INT:
  58:             if (p1->len == 4)
  59:                 i2toi4(p2);
  60: 
  61:           case CHAR:
  62:             return; /* done if char or int */
  63: 
  64:           case FLOAT:
  65:             f8tof4(p2);
  66:             return;
  67:         }
  68:     }
  69: 
  70:     /* at least one symbol is an INT or FLOAT. The other can't be a CHAR */
  71:     if (p1->type == CHAR || p2->type == CHAR)
  72:         ov_err(BADMIX); /* attempting binary operation on one CHAR field with a numeric */
  73: 
  74:     /* one symbol is an INT and the other a FLOAT */
  75:     if (p2->type == INT)
  76:     {
  77:         /* exchange so that p1 is an INT and p2 is a FLOAT */
  78:         p1 = p2;
  79:         p2 = pp1;
  80:     }
  81: 
  82:     /* p1 is an INT and p2 a FLOAT */
  83:     itof(p1);
  84:     if (p2->len == 4)
  85:         f8tof4(p2);
  86: }
  87: 
  88: 
  89: typecoerce(tosx, ntype, nlen)
  90: struct stacksym *tosx;
  91: int     ntype;
  92: int     nlen;
  93: 
  94: /*
  95: **	Coerce the top of stack symbol to the
  96: **	specified type and length. If the current
  97: **	value is a character then it must be converted
  98: **	to numeric. A user error will occure is the
  99: **	char is not syntaxtically correct.
 100: */
 101: 
 102: {
 103:     register struct stacksym    *tos;
 104:     register char           *cp;
 105:     register int            *val;
 106:     int             ret;
 107:     char                temp[256];
 108: 
 109:     tos = tosx;
 110: 
 111:     if (tos->type == CHAR)
 112:     {
 113:         val = tos->value;
 114:         cp = temp;
 115:         bmove(cpderef(tos->value), cp, tos->len & I1MASK);
 116:         cp[tos->len & I1MASK] = '\0';
 117:         if (ntype == FLOAT)
 118:             ret = atof(cp, val);
 119:         else
 120:         {
 121:             if (nlen == 4)
 122:                 ret = atol(cp, val);
 123:             else
 124:                 ret = atoi(cp, val);
 125:         }
 126:         if (ret < 0)
 127:             ov_err(CHARCONVERT);
 128:         tos->type = ntype;
 129:         tos->len = nlen;
 130:     }
 131:     else
 132:         rcvt(tos, ntype, nlen);
 133: }
 134: 
 135: 
 136: i2toi4(pp)
 137: struct symbol *pp;
 138: {
 139:     register struct symbol  *p;
 140: 
 141:     p = pp;
 142: 
 143:     i4deref(p->value) = i2deref(p->value);
 144:     p->len = 4;
 145: }
 146: 
 147: 
 148: i4toi2(pp)
 149: struct symbol *pp;
 150: {
 151:     register struct symbol  *p;
 152: 
 153:     p = pp;
 154: 
 155:     i2deref(p->value) = i4deref(p->value);
 156:     p->len = 2;
 157: }
 158: 
 159: 
 160: itof(pp)
 161: struct symbol *pp;
 162: {
 163:     register struct symbol  *p;
 164: 
 165:     p  = pp;
 166: 
 167:     if  (p->len == 4)
 168:         f8deref(p->value) = i4deref(p->value);
 169:     else
 170:         f8deref(p->value) = i2deref(p->value);
 171:     p->type = FLOAT;
 172:     p->len= 8;
 173: }
 174: 
 175: 
 176: ftoi2(pp)
 177: struct symbol *pp;
 178: {
 179:     register struct symbol  *p;
 180: 
 181:     p = pp;
 182: 
 183:     i2deref(p->value) = f8deref(p->value);
 184:     p->type = INT;
 185:     p->len = 2;
 186: }
 187: 
 188: 
 189: ftoi4(pp)
 190: struct symbol *pp;
 191: {
 192:     register struct symbol  *p;
 193: 
 194:     p = pp;
 195:     i4deref(p->value) = f8deref(p->value);
 196:     p->type = INT;
 197:     p->len = 4;
 198: }
 199: 
 200: 
 201: f8tof4(pp)
 202: struct symbol   *pp;
 203: {
 204:     register struct symbol  *p;
 205: 
 206:     p = pp;
 207:     f4deref(p->value) = f8deref(p->value);
 208:     p->len = 4;
 209: }

Defined functions

f8tof4 defined in line 201; used 2 times
ftoi2 defined in line 176; used 1 times
ftoi4 defined in line 189; used 1 times
i2toi4 defined in line 136; used 2 times
i4toi2 defined in line 148; used 1 times
itof defined in line 160; used 8 times
typecheck defined in line 13; used 1 times
typecoerce defined in line 89; used 5 times
Last modified: 1995-02-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3115
Valid CSS Valid XHTML 1.0 Strict