# 2.11BSD#431 - /usr/src/ucb/PORT/pascal/src/clas.c

##### Functions

    classify          X
    isa               X
    isnta             X
    nameof            X
    nowexp            X
    scalar            X
    text              X
    whereis           X

##### Variables

    clnames           X
    clnxxxx           X

       1: /*
       2:  * Copyright (c) 1980 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #ifndef lint
       8: static char sccsid[] = "@(#)clas.c	5.2 (Berkeley) 6/5/85";
       9: #endif not lint
      10: #include "whoami.h"
      11: #include "0.h"
      12: #include "tree.h"
      13: #include "tree_ty.h"
      14:
      15: /*
      16:  * This is the array of class
      17:  * names for the classes returned
      18:  * by classify.  The order of the
      19:  * classes is the same as the base
      20:  * of the namelist, with special
      21:  * negative index entries for structures,
      22:  * scalars, pointers, sets and strings
      23:  * to be collapsed into.
      24:  */
      25: char    *clnxxxx[] =
      26: {
      27:     "file",         /* -7	TFILE */
      28:     "record",       /* -6	TREC */
      29:     "array",        /* -5	TARY */
      30:     "scalar",       /* -4	TSCAL */
      31:     "pointer",      /* -3	TPTR */
      32:     "set",          /* -2	TSET */
      33:     "string",       /* -1	TSTR */
      34:     "SNARK",        /*  0	NIL */
      35:     "Boolean",      /*  1	TBOOL */
      36:     "char",         /*  2	TCHAR */
      37:     "integer",      /*  3	TINT */
      38:     "real",         /*  4	TREAL */
      39:     "\"nil\"",      /*  5	TNIL */
      40: };
      41:
      42: char **clnames  = &clnxxxx[-(TFIRST)];
      43:
      44: /*
      45:  * Classify takes a pointer
      46:  * to a type and returns one
      47:  * of several interesting group
      48:  * classifications for easy use.
      49:  */
      50: classify(p1)
      51:     struct nl *p1;
      52: {
      53:     register struct nl *p;
      54:
      55:     p = p1;
      56: swit:
      57:     if (p == NLNIL) {
      58:         nocascade();
      59:         return (NIL);
      60:     }
      61:     if (p == &nl[TSTR])
      62:         return (TSTR);
      63:     if ( p == &nl[ TSET ] ) {
      64:         return TSET;
      65:     }
      66:     switch (p->class) {
      67:         case PTR:
      68:             return (TPTR);
      69:         case ARRAY:
      70:             if (p->type == nl+T1CHAR)
      71:                 return (TSTR);
      72:             return (TARY);
      73:         case STR:
      74:             return (TSTR);
      75:         case SET:
      76:             return (TSET);
      77:         case CRANGE:
      78:         case RANGE:
      79:             p = p->type;
      80:             goto swit;
      81:         case TYPE:
      82:             if (p <= nl+TLAST)
      83:                 return (p - nl);
      84:             panic("clas2");
      85:         case FILET:
      86:             return (TFILE);
      87:         case RECORD:
      88:             return (TREC);
      89:         case SCAL:
      90:             return (TSCAL);
      91:         default:
      92:             {
      93:                 panic("clas");
      94:                 return(NIL);
      95:             }
      96:     }
      97: }
      98:
      99: #ifndef PI0
     100: /*
     101:  * Is p a text file?
     102:  */
     103: text(p)
     104:     struct nl *p;
     105: {
     106:
     107:     return (p != NIL && p->class == FILET && p->type == nl+T1CHAR);
     108: }
     109: #endif
     110:
     111: /*
     112:  * Scalar returns a pointer to
     113:  * the the base scalar type of
     114:  * its argument if its argument
     115:  * is a SCALar else NIL.
     116:  */
     117: struct nl *
     118: scalar(p1)
     119:     struct nl *p1;
     120: {
     121:     register struct nl *p;
     122:
     123:     p = p1;
     124:     if (p == NLNIL)
     125:         return (NLNIL);
     126:     if (p->class == RANGE || p->class == CRANGE)
     127:         p = p->type;
     128:     if (p == NLNIL)
     129:         return (NLNIL);
     130:     return (p->class == SCAL ? p : NLNIL);
     131: }
     132:
     133: /*
     134:  * Isa tells whether p
     135:  * is one of a group of
     136:  * namelist classes.  The
     137:  * classes wanted are specified
     138:  * by the characters in s.
     139:  * (Note that s would more efficiently,
     140:  * if less clearly, be given by a mask.)
     141:  */
     142: isa(p, s)
     143:     register struct nl *p;
     144:     char *s;
     145: {
     146:     register i;
     147:     register char *cp;
     148:
     149:     if (p == NIL)
     150:         return (NIL);
     151:     /*
     152: 	 * map ranges down to
     153: 	 * the base type
     154: 	 */
     155:     if (p->class == RANGE) {
     156:         p = p->type;
     157:     }
     158:     /*
     159: 	 * the following character/class
     160: 	 * associations are made:
     161: 	 *
     162: 	 *	s	scalar
     163: 	 *	b	Boolean
     164: 	 *	c	character
     165: 	 *	i	integer
     166: 	 *	d	double (real)
     167: 	 *	t	set
     168: 	 */
     169:     switch (p->class) {
     170:         case SET:
     171:             i = TDOUBLE+1;
     172:             break;
     173:         case SCAL:
     174:             i = 0;
     175:             break;
     176:         case CRANGE:
     177:             /*
     178: 			 * find the base type of a conformant array range
     179: 			 */
     180:             switch (classify(p->type)) {
     181:                 case TBOOL: i = 1; break;
     182:                 case TCHAR: i = 2; break;
     183:                 case TINT: i = 3; break;
     184:                 case TSCAL: i = 0; break;
     185:                 default:
     186:                     panic( "isa" );
     187:             }
     188:             break;
     189:         default:
     190:             i = p - nl;
     191:     }
     192:     if (i >= 0 && i <= TDOUBLE+1) {
     193:         i = "sbcidt"[i];
     194:         cp = s;
     195:         while (*cp)
     196:             if (*cp++ == i)
     197:                 return (1);
     198:     }
     199:     return (NIL);
     200: }
     201:
     202: /*
     203:  * Isnta is !isa
     204:  */
     205: isnta(p, s)
     206:     struct nl *p;
     207:     char *s;
     208: {
     209:
     210:     return (!isa(p, s));
     211: }
     212:
     213: /*
     214:  * "shorthand"
     215:  */
     216: char *
     217: nameof(p)
     218: struct nl *p;
     219: {
     220:
     221:     return (clnames[classify(p)]);
     222: }
     223:
     224: #ifndef PI0
     225: /* find out for sure what kind of node this is being passed
     226:    possibly several different kinds of node are passed to it */
     227: int nowexp(r)
     228:     struct tnode *r;
     229: {
     230:     if (r->tag == T_WEXP) {
     231:         if (r->var_node.cptr == NIL)
     232:             error("Oct/hex allowed only on writeln/write calls");
     233:         else
     234:             error("Width expressions allowed only in writeln/write calls");
     235:         return (1);
     236:     }
     237:     return (NIL);
     238: }
     239: #endif
     240:
     241:     /*
     242:      *	is a variable a local, a formal parameter, or a global?
     243:      *	all this from just the offset:
     244:      *	    globals are at levels 0 or 1
     245:      *	    positives are parameters
     246:      *	    negative evens are locals
     247:      */
     248: /*ARGSUSED*/
     249: whereis( offset , other_flags )
     250:     int     offset;
     251:     char    other_flags;
     252: {
     253:
     254: #   ifdef OBJ
     255:     return ( offset >= 0 ? PARAMVAR : LOCALVAR );
     256: #   endif OBJ
     257: #   ifdef PC
     258:     switch ( other_flags & ( NGLOBAL | NPARAM | NLOCAL | NNLOCAL) ) {
     259:         default:
     260:         panic( "whereis" );
     261:         case NGLOBAL:
     262:         return GLOBALVAR;
     263:         case NPARAM:
     264:         return PARAMVAR;
     265:         case NNLOCAL:
     266:         return NAMEDLOCALVAR;
     267:         case NLOCAL:
     268:         return LOCALVAR;
     269:     }
     270: #   endif PC
     271: }

#### Defined functions

classify defined in line 50; used 52 times

- in line 180, 221
- in /usr/src/ucb/PORT/pascal/src/call.c line 71, 244(2), 341, 387
- in /usr/src/ucb/PORT/pascal/src/const.c line 167
- in /usr/src/ucb/PORT/pascal/src/conv.c line 72-75(2), 93
- in /usr/src/ucb/PORT/pascal/src/fend.c line 682, 920
- in /usr/src/ucb/PORT/pascal/src/fhdr.c line 151
- in /usr/src/ucb/PORT/pascal/src/func.c line 185
- in /usr/src/ucb/PORT/pascal/src/pcfunc.c line 285
- in /usr/src/ucb/PORT/pascal/src/pcproc.c line 285, 381, 402, 532, 1021, 1031, 1072, 1203, 1307, 1346, 1385, 1487
- in /usr/src/ucb/PORT/pascal/src/proc.c line 251, 470, 777, 866, 946, 978, 1013, 1077
- in /usr/src/ucb/PORT/pascal/src/rval.c line 234, 735, 808-809(2), 1147
- in /usr/src/ucb/PORT/pascal/src/stat.c line 381, 398, 421, 444, 479
- in /usr/src/ucb/PORT/pascal/src/stkrval.c line 91, 115, 167, 258
- in /usr/src/ucb/PORT/pascal/src/type.c line 314-315(2)

isa defined in line 142; used 48 times

- in line 210
- in /usr/src/ucb/PORT/pascal/src/call.c line 381
- in /usr/src/ucb/PORT/pascal/src/const.c line 105-107(2)
- in /usr/src/ucb/PORT/pascal/src/cset.c line 136, 144
- in /usr/src/ucb/PORT/pascal/src/func.c line 141, 171-175(2), 182, 196, 205
- in /usr/src/ucb/PORT/pascal/src/pcfunc.c line 238, 246, 256-260(2), 282, 296, 322
- in /usr/src/ucb/PORT/pascal/src/pcproc.c line 308, 334, 1004, 1082, 1121
- in /usr/src/ucb/PORT/pascal/src/proc.c line 274, 300, 746
- in /usr/src/ucb/PORT/pascal/src/rval.c line 417-420(2), 540, 552-554(4), 574, 582-587(2), 605, 714
- in /usr/src/ucb/PORT/pascal/src/stab.c line 454-456(2)
- in /usr/src/ucb/PORT/pascal/src/stat.c line 323
- in /usr/src/ucb/PORT/pascal/src/stkrval.c line 98, 140, 234, 273, 314
- in /usr/src/ucb/PORT/pascal/src/type.c line 343

isnta defined in line 205; used 55 times

- in /usr/src/ucb/PORT/pascal/src/case.c line 61
- in /usr/src/ucb/PORT/pascal/src/const.c line 225
- in /usr/src/ucb/PORT/pascal/src/cset.c line 104, 140, 151
- in /usr/src/ucb/PORT/pascal/src/forop.c line 166
- in /usr/src/ucb/PORT/pascal/src/func.c line 143, 155, 163, 200, 222, 229, 236
- in /usr/src/ucb/PORT/pascal/src/pccaseop.c line 94
- in /usr/src/ucb/PORT/pascal/src/pcfunc.c line 185, 196, 207, 216, 227, 300, 328, 341, 356
- in /usr/src/ucb/PORT/pascal/src/pcproc.c line 684, 754, 779, 1338, 1367, 1413, 1476
- in /usr/src/ucb/PORT/pascal/src/proc.c line 516, 542, 970, 993, 1032, 1087
- in /usr/src/ucb/PORT/pascal/src/rec.c line 176
- in /usr/src/ucb/PORT/pascal/src/rval.c line 410, 435, 461-465(2), 498-502(2), 623, 636-640(2), 659-663(2), 1203
- in /usr/src/ucb/PORT/pascal/src/sconv.c line 43(2)
- in /usr/src/ucb/PORT/pascal/src/stat.c line 576, 642, 688
- in /usr/src/ucb/PORT/pascal/src/type.c line 349

nameof defined in line 216; used 101 times

- in /usr/src/ucb/PORT/pascal/src/0.h line 722
- in /usr/src/ucb/PORT/pascal/src/case.c line 62
- in /usr/src/ucb/PORT/pascal/src/const.c line 227
- in /usr/src/ucb/PORT/pascal/src/cset.c line 141
- in /usr/src/ucb/PORT/pascal/src/fend.c line 239
- in /usr/src/ucb/PORT/pascal/src/fhdr.c line 370
- in /usr/src/ucb/PORT/pascal/src/forop.c line 167
- in /usr/src/ucb/PORT/pascal/src/func.c line 144, 156, 164, 179, 192, 201, 223, 230, 237, 244, 251
- in /usr/src/ucb/PORT/pascal/src/lval.c line 174, 228, 269
- in /usr/src/ucb/PORT/pascal/src/pccaseop.c line 95
- in /usr/src/ucb/PORT/pascal/src/pcfunc.c line 186, 197, 208, 217, 228, 253, 265, 292, 301, 329, 342, 357, 369, 380
- in /usr/src/ucb/PORT/pascal/src/pclval.c line 302, 320, 345
- in /usr/src/ucb/PORT/pascal/src/pcproc.c line 162, 685, 755, 1160, 1189, 1204, 1234, 1308, 1339, 1347, 1368, 1386, 1406, 1414, 1433, 1477, 1488, 1528, 1534, 1541
- in /usr/src/ucb/PORT/pascal/src/proc.c line 151, 517, 543, 826, 849, 867, 893, 947, 971, 979, 994, 1014, 1033, 1040, 1054, 1078, 1088, 1123-1127(2), 1133
- in /usr/src/ucb/PORT/pascal/src/rec.c line 177
- in /usr/src/ucb/PORT/pascal/src/rval.c line 411, 436, 462-466(2), 499-503(2), 637-641(2), 660-664(2), 942, 1204
- in /usr/src/ucb/PORT/pascal/src/stat.c line 265, 577, 643, 689
- in /usr/src/ucb/PORT/pascal/src/type.c line 219, 236, 318(2), 351

nowexp defined in line 227; used 4 times

- in /usr/src/ucb/PORT/pascal/src/lval.c line 55
- in /usr/src/ucb/PORT/pascal/src/pclval.c line 57
- in /usr/src/ucb/PORT/pascal/src/rval.c line 88
- in /usr/src/ucb/PORT/pascal/src/stkrval.c line 54

scalar defined in line 117; used 7 times

- in /usr/src/ucb/PORT/pascal/src/0.h line 745
- in /usr/src/ucb/PORT/pascal/src/conv.c line 108(2)
- in /usr/src/ucb/PORT/pascal/src/rval.c line 829(2)
- in /usr/src/ucb/PORT/pascal/src/type.c line 322(2)

text defined in line 103; used 10 times

- in /usr/src/ucb/PORT/pascal/src/fend.c line 243, 264
- in /usr/src/ucb/PORT/pascal/src/func.c line 243
- in /usr/src/ucb/PORT/pascal/src/pcfunc.c line 368
- in /usr/src/ucb/PORT/pascal/src/pcproc.c line 1215, 1405, 1432
- in /usr/src/ucb/PORT/pascal/src/proc.c line 852, 1039, 1053

whereis defined in line 249; used 4 times

- in /usr/src/ucb/PORT/pascal/src/forop.c line 147-150(2)
- in /usr/src/ucb/PORT/pascal/src/p2put.c line 244, 283

#### Defined variables

clnames defined in line 42; used 1 times

- in line 221

clnxxxx defined in line 25; used 1 times

- in line 42

sccsid defined in line 8; never used

Last modified: 1985-06-05 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 953 |