1: #ifndef lint
   2: static char RCSid[] = "$Header: checktype.c,v 2.0 85/11/21 07:21:27 jqj Exp $";
   3: #endif
   4: 
   5: /* $Log:	checktype.c,v $
   6:  * Revision 2.0  85/11/21  07:21:27  jqj
   7:  * 4.3BSD standard release
   8:  *
   9:  * Revision 1.5  85/11/20  13:01:59  root
  10:  * Gould bugfixes, I guess
  11:  *
  12:  * Revision 1.4  85/05/06  08:12:54  jqj
  13:  * Almost Beta-test version.
  14:  *
  15:  * Revision 1.3  85/03/11  16:38:34  jqj
  16:  * Public alpha-test version, released 11 March 1985
  17:  *
  18:  * Revision 1.2  85/02/21  11:04:43  jqj
  19:  * alpha test version
  20:  *
  21:  * Revision 1.1  85/02/15  13:55:13  jqj
  22:  * Initial revision
  23:  *
  24:  */
  25: 
  26: #include "compiler.h"
  27: 
  28: static int
  29: type_check_list(typtr, p)
  30:     struct type *typtr;
  31:     list p;
  32: {
  33:     for ( ; p != NIL ; p = cdr(p))
  34:         if (! type_check(typtr, (struct constant *) car(p)) )
  35:             return(0);
  36:     return(1);
  37: }
  38: 
  39: static int
  40: type_check_enumeration(typtr, value)
  41:     struct type *typtr;
  42:     struct constant *value;
  43: {
  44:     list p;
  45: 
  46:     if (typtr->type_constr != value->cn_constr)
  47:         return(0);
  48:     for (p = typtr->type_list; p != NIL; p = cdr(p))
  49:         if (streq(value->cn_value, name_of((struct object *) caar(p))))
  50:             return(1);
  51:     return(0);
  52: }
  53: 
  54: static int
  55: type_check_record(typtr, value)
  56:     struct type *typtr;
  57:     struct constant *value;
  58: {
  59:     if (typtr->type_constr != value->cn_constr)
  60:         return(0);
  61:     /* ### not yet implemented */
  62:     return(1);
  63: }
  64: 
  65: /*
  66:  * Make sure a number is a valid constant for this type.
  67:  */
  68: int
  69: type_check(typtr, value)
  70:     struct type *typtr;
  71:     struct constant *value;
  72: {
  73: 
  74:     switch (typtr->type_constr) {
  75:     case C_NUMERIC:
  76:     case C_BOOLEAN:
  77:     case C_STRING:
  78:         return(typtr->type_constr == value->cn_constr);
  79:     case C_ENUMERATION:
  80:         return( type_check_enumeration(typtr, value) );
  81:     case C_ARRAY:
  82:         if (value->cn_constr == C_RECORD && value->cn_list == NIL &&
  83:             typtr->type_size == 0)
  84:             return(1);
  85:         return( (typtr->type_constr == value->cn_constr) &&
  86:             typtr->type_size == length(value->cn_list) &&
  87:             type_check_list(typtr->type_basetype, value->cn_list));
  88:     case C_SEQUENCE:
  89:         if (value->cn_constr == C_ARRAY) {
  90:             value->cn_constr = C_SEQUENCE;
  91:         }
  92:         if (value->cn_constr == C_RECORD && value->cn_list == NIL)
  93:             return(1);
  94:         return( (typtr->type_constr == value->cn_constr) &&
  95:             type_check_list(typtr->type_basetype, value->cn_list));
  96:     case C_RECORD:
  97:         return( type_check_record(typtr, value) );
  98:     case C_PROCEDURE:
  99:     case C_ERROR:
 100:         return(value->cn_constr == C_NUMERIC);
 101:     }
 102:     /*NOTREACHED*/
 103: }

Defined functions

type_check defined in line 68; used 2 times
type_check_enumeration defined in line 39; used 1 times
  • in line 80
type_check_list defined in line 28; used 2 times
type_check_record defined in line 54; used 1 times
  • in line 97

Defined variables

RCSid defined in line 2; never used
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1087
Valid CSS Valid XHTML 1.0 Strict