1 /* E X P R E S S I O N C H E C K I N G */
3 /* Check expressions, and try to evaluate them as far as possible.
28 extern char *symbol2str();
29 STATIC int ChkUnOper();
33 register struct node *nd;
36 if( nd->nd_class == Def && nd->nd_def ) {
37 if( nd->nd_def->df_kind != D_ERROR )
38 node_error(nd,"\"%s\": %s",
39 nd->nd_def->df_idf->id_text, mess);
41 else node_error(nd, "%s", mess);
47 register struct node *nd;
49 nd = MkLeaf(Value, &dot);
50 nd->nd_type = int_type;
51 nd->nd_symb = INTEGER;
52 nd->nd_INT = (arith) 0;
53 nd = MkNode(Link, nd, NULLNODE, &dot);
60 register struct node *nd;
62 while( nd && nd->nd_class != Def ) {
63 if( (nd->nd_class == Arrsel) || (nd->nd_class == LinkDef) )
65 else if( nd->nd_class == Arrow)
70 if( nd && nd->nd_class == Def ) {
71 register struct def *df = nd->nd_def;
73 if( df->df_kind != D_FIELD ) {
74 if( !(df->df_flags & (D_SET|D_VARPAR)) &&
75 (df->df_scope == CurrentScope) )
76 if( !is_anon_idf(df->df_idf) ) {
77 warning("\"%s\" used before set",
80 df->df_flags |= (D_USED | D_SET);
87 register struct node *expp;
89 register struct node *nd;
91 if( !(nd = expp->nd_right) ) nd = expp;
93 if( nd->nd_class == Name && !ChkLinkOrName(nd) ) return 0;
95 if( nd->nd_class != Value || expp->nd_left ) {
96 Xerror(nd, "constant expected");
100 if( expp->nd_class == Uoper )
101 return ChkUnOper(expp);
102 else if( nd != expp ) {
103 Xerror(expp, "constant expected");
111 register struct node *expp;
113 /* Check that "expp" indicates an item that can be accessed */
115 if( !ChkLhs(expp) ) return 0;
117 if( expp->nd_class == Def && expp->nd_def->df_kind == D_FUNCTION ) {
118 Xerror(expp, "illegal use of function name");
126 register struct node *expp;
130 /* Check that "expp" indicates an item that can be the lhs
133 if( !ChkVarAccess(expp) ) return 0;
135 class = expp->nd_class;
137 /* a constant is replaced by it's value in ChkLinkOrName, check here !,
138 * the remaining classes are checked by ChkVarAccess
140 if( class == Value ) {
141 node_error(expp, "can't access a value");
146 !(expp->nd_def->df_kind & (D_FIELD | D_FUNCTION | D_VARIABLE)) ) {
147 Xerror(expp, "variable expected");
151 /* assignment to function name */
152 if( class == Def && expp->nd_def->df_kind == D_FUNCTION )
153 if( expp->nd_def->prc_res )
154 expp->nd_type = ResultType(expp->nd_def->df_type);
156 Xerror(expp, "illegal assignment to function-name");
166 register struct node *expp;
168 switch( expp->nd_symb ) {
184 register struct node *expp;
186 register struct def *df;
188 expp->nd_type = error_type;
190 if( expp->nd_class == Name ) {
191 expp->nd_def = lookfor(expp, CurrVis, 1);
192 expp->nd_class = Def;
193 expp->nd_type = expp->nd_def->df_type;
195 else if( expp->nd_class == Link ) {
196 /* a selection from a record */
197 register struct node *left = expp->nd_left;
199 assert(expp->nd_symb == '.');
201 if( !ChkVariable(left) ) return 0;
203 if( left->nd_type->tp_fund != T_RECORD ) {
204 Xerror(left, "illegal selection");
208 if( !(df = lookup(expp->nd_IDF, left->nd_type->rec_scope, D_INUSE)) ) {
209 id_not_declared(expp);
214 expp->nd_type = df->df_type;
215 expp->nd_class = LinkDef;
219 assert(expp->nd_class == Def);
223 if( df->df_kind & (D_ENUM | D_CONST) ) {
225 /* Replace an enum-literal or a CONST identifier by its value.
227 if( df->df_kind == D_ENUM ) {
228 expp->nd_class = Value;
229 expp->nd_INT = df->enm_val;
230 expp->nd_symb = INTEGER;
233 unsigned int ln = expp->nd_lineno;
235 assert(df->df_kind == D_CONST);
236 *expp = *(df->con_const);
237 expp->nd_lineno = ln;
240 return df->df_kind != D_ERROR;
244 ChkExLinkOrName(expp)
245 register struct node *expp;
247 if( !ChkLinkOrName(expp) ) return 0;
248 if( expp->nd_class != Def ) return 1;
250 if( !(expp->nd_def->df_kind & D_VALUE) ) {
251 Xerror(expp, "value expected");
259 register struct node *expp;
261 /* Check an unary operation.
263 register struct node *right = expp->nd_right;
264 register struct type *tpr;
266 if( !ChkExpression(right) ) return 0;
270 expp->nd_type = tpr = BaseType(right->nd_type);
272 switch( expp->nd_symb ) {
274 if( tpr->tp_fund & T_NUMERIC ) {
282 if( tpr->tp_fund == T_INTEGER || tpr->tp_fund == T_LONG ) {
283 if( right->nd_class == Value )
287 if( tpr->tp_fund == T_REAL ) {
288 if( right->nd_class == Value ) {
289 expp->nd_token.tk_data.tk_real = right->nd_RIV;
290 expp->nd_class = Value;
291 expp->nd_symb = REAL;
293 expp->nd_right = NULLNODE;
300 if( tpr == bool_type ) {
301 if( right->nd_class == Value )
308 /* Delete the brackets */
314 crash("(ChkUnOper)");
316 node_error(expp, "\"%s\": illegal operand", symbol2str(expp->nd_symb));
321 ResultOfOperation(operator, tpl, tpr)
322 struct type *tpl, *tpr;
324 /* Return the result type of the binary operation "operator",
325 with operand types "tpl" and "tpr".
340 if( tpl == real_type || tpr == real_type )
342 if( tpl == long_type || tpr == long_type)
348 if (tpr == long_type && tpl == int_type) return tpr;
353 AllowedTypes(operator)
355 /* Return a bit mask indicating the allowed operand types for
356 binary operator "operator".
363 return T_NUMERIC | T_SET;
368 return T_INTEGER | T_LONG;
371 return T_ENUMERATION;
374 return T_ENUMERATION | T_CHAR | T_NUMERIC |
375 T_SET | T_POINTER | T_STRINGCONST |
379 return T_ENUMERATION | T_CHAR | T_NUMERIC |
380 T_SET | T_STRINGCONST;
383 return T_ENUMERATION | T_CHAR | T_NUMERIC |
386 crash("(AllowedTypes)");
394 return operator == OR || operator == AND;
399 register struct node *expp;
401 /* Check a binary operation.
403 register struct node *left, *right;
404 struct type *tpl, *tpr;
407 left = expp->nd_left;
408 right = expp->nd_right;
410 retval = ChkExpression(left);
411 retval &= ChkExpression(right);
416 tpl = BaseType(left->nd_type);
417 tpr = BaseType(right->nd_type);
419 expp->nd_type = ResultOfOperation(expp->nd_symb, tpl ,tpr);
421 /* Check that the application of the operator is allowed on the type
423 There are some needles and pins:
424 - Boolean operators are only allowed on boolean operands, but the
425 "allowed-mask" of "AllowedTypes" can only indicate an enumeration
427 - The IN-operator has as right-hand-side operand a set.
428 - Strings and packed arrays can be equivalent.
429 - In some cases, integers must be converted to reals.
430 - If one of the operands is the empty set then the result doesn't
431 have to be the empty set.
434 if( expp->nd_symb == IN ) {
435 if( tpr->tp_fund != T_SET ) {
436 node_error(expp, "\"IN\": right operand must be a set");
439 if( !TstAssCompat(tpl, ElementType(tpr)) ) {
440 node_error(expp, "\"IN\": incompatible types");
443 if( left->nd_class == Value && right->nd_class == Set )
448 if( !retval ) return 0;
450 allowed = AllowedTypes(expp->nd_symb);
452 if( !(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed) ) {
454 extern arith IsString();
456 if( allowed & T_STRINGCONST && (ub = IsString(tpl)) ) {
457 if( ub == IsString(tpr) )
460 node_error(expp, "\"%s\": incompatible types",
461 symbol2str(expp->nd_symb));
465 else if( allowed & T_STRING && tpl->tp_fund == T_STRING )
468 node_error(expp, "\"%s\": illegal operand type(s)",
469 symbol2str(expp->nd_symb));
473 if( Boolean(expp->nd_symb) && tpl != bool_type ) {
474 node_error(expp, "\"%s\": illegal operand type(s)",
475 symbol2str(expp->nd_symb));
479 if( allowed & T_NUMERIC ) {
480 if( (tpl == int_type || tpl == long_type) &&
481 (tpr == real_type || expp->nd_symb == '/') ) {
483 MkNode(Cast, NULLNODE, expp->nd_left, &dot);
484 expp->nd_left->nd_type = tpl = real_type;
486 if( tpl == real_type &&
487 (tpr == int_type || tpr == long_type)) {
489 MkNode(Cast, NULLNODE, expp->nd_right, &dot);
490 expp->nd_right->nd_type = tpr = real_type;
492 if( tpl == int_type && tpr == long_type) {
494 MkNode(IntCoerc, NULLNODE, expp->nd_left, &dot);
495 expp->nd_left->nd_type = long_type;
497 else if( tpl == long_type && tpr == int_type) {
499 MkNode(IntCoerc, NULLNODE, expp->nd_right, &dot);
500 expp->nd_right->nd_type = long_type;
504 /* Operands must be compatible */
505 if( !TstCompat(tpl, tpr) ) {
506 node_error(expp, "\"%s\": incompatible types",
507 symbol2str(expp->nd_symb));
511 if( tpl->tp_fund & T_SET ) {
512 if( tpl == emptyset_type )
514 else if( tpr == emptyset_type )
515 right->nd_type = tpl;
517 if( expp->nd_type == emptyset_type )
519 if( left->nd_class == Set && right->nd_class == Set )
522 else if( tpl->tp_fund != T_REAL &&
523 left->nd_class == Value && right->nd_class == Value )
530 ChkElement(expp, tp, set, cnt)
531 register struct node *expp;
532 register struct type **tp;
536 /* Check elements of a set. This routine may call itself
537 recursively. Also try to compute the set!
539 register struct node *left = expp->nd_left;
540 register struct node *right = expp->nd_right;
542 extern char *Malloc();
544 if( expp->nd_class == Link && expp->nd_symb == UPTO ) {
545 /* [ ... , expr1 .. expr2, ... ]
546 First check expr1 and expr2, and try to compute them.
548 if( !ChkElement(left, tp, set, cnt) ||
549 !ChkElement(right, tp, set, cnt) )
552 if( left->nd_class == Value &&
553 right->nd_class == Value && *set ) {
555 if( left->nd_INT > right->nd_INT ) {
556 /* Remove lower and upper bound of the range.
559 (*set)[left->nd_INT/wrd_bits] &=
560 ~(1 << (left->nd_INT%wrd_bits));
561 (*set)[right->nd_INT/wrd_bits] &=
562 ~(1 << (right->nd_INT%wrd_bits));
565 /* We have a constant range. Put all elements
568 for( i = left->nd_INT + 1; i < right->nd_INT; i++ )
569 (*set)[i/wrd_bits] |= ( 1 << (i%wrd_bits) );
574 /* Here, a single element is checked
576 if( !ChkExpression(expp) ) return 0;
579 if( *tp == emptyset_type ) {
580 /* first element in set determines the type of the set */
583 *tp = set_type(expp->nd_type, 0);
584 size = (*tp)->tp_size * (sizeof(arith) / word_size);
585 *set = (arith *) Malloc(size);
586 clear((char *) *set, size);
588 else if( !TstCompat(ElementType(*tp), expp->nd_type) ) {
589 node_error(expp, "set element has incompatible type");
593 if( expp->nd_class == Value ) {
594 /* a constant element
598 if( expp->nd_type == int_type ) {
599 /* Check only integer base-types because they are not
600 equal to the integer host-type. The other base-types
601 are equal to their host-types.
604 if( i < 0 || i > max_intset ) {
605 node_error(expp, "set element out of range");
610 if( *set ) (*set)[i/wrd_bits] |= ( 1 << (i%wrd_bits));
623 register struct node *expp;
625 /* Check the legality of a SET aggregate, and try to evaluate it
626 compile time. Unfortunately this is all rather complicated.
628 register struct node *nd = expp->nd_right;
629 arith *set = (arith *) 0;
632 assert(expp->nd_symb == SET);
634 expp->nd_type = emptyset_type;
636 /* Now check the elements given, and try to compute a constant set.
637 First allocate room for the set, but only if it isn't empty.
640 /* The resulting set IS empty, so we just return
642 expp->nd_class = Set;
643 expp->nd_set = (arith *) 0;
647 /* Now check the elements, one by one
650 assert(nd->nd_class == Link && nd->nd_symb == ',');
652 if( !ChkElement(nd->nd_left, &(expp->nd_type), &set, &cnt) )
658 /* Yes, it was a constant set, and we managed to compute it!
659 Notice that at the moment there is no such thing as
660 partial evaluation. Either we evaluate the set, or we
661 don't (at all). Improvement not neccesary (???)
662 ??? sets have a contant part and a variable part ???
664 expp->nd_class = Set;
666 /* after all the work we've done, the set turned out
673 FreeNode(expp->nd_right);
674 expp->nd_right = NULLNODE;
681 ChkAllowedVar(nd, reading) /* reading indicates read or readln */
682 register struct node *nd;
686 switch( nd->nd_class ) {
688 if( nd->nd_def->df_flags & D_INLOOP ) {
689 message = "control variable";
692 if( nd->nd_def->df_kind != D_FIELD ) break;
696 assert(nd->nd_def->df_kind == D_FIELD);
698 if( nd->nd_def->fld_flags & F_PACKED )
699 message = "field of packed record";
700 else if( nd->nd_def->fld_flags & F_SELECTOR )
701 message = "variant selector";
705 if( IsPacked(nd->nd_left->nd_type) )
706 if( !reading ) message = "component of packed array";
710 if( nd->nd_right->nd_type->tp_fund == T_FILE )
711 message = "filebuffer variable";
715 crash("(ChkAllowedVar)");
718 MarkDef(nd, D_SET, 1);
724 register struct node *nd, *name;
727 An actual variable parameter shall not denote a field
728 that is the selector of a variant-part or a component
729 of a variable where that variable possesses a type
730 that is designated packed.
732 static char err_mes[80];
733 char *message = (char *) 0;
735 if( !ChkVariable(nd) ) return 0;
737 message = ChkAllowedVar(nd, 0);
740 sprint(err_mes, "%s can't be a variable parameter", message);
741 Xerror(name, err_mes);
748 getarg(argp, bases, varaccess, name, paramtp)
749 struct node **argp, *name;
750 struct type *paramtp;
752 /* This routine is used to fetch the next argument from an
753 argument list. The argument list is indicated by "argp".
754 The parameter "bases" is a bitset indicating which types are
755 allowed at this point, and "varaccess" is a flag indicating
756 that the address from this argument is taken, so that it
757 must be a varaccess and may not be a register variable.
759 register struct node *arg = (*argp)->nd_right;
760 register struct node *left;
763 Xerror(name, "too few arguments supplied");
770 if( paramtp && paramtp->tp_fund & T_ROUTINE ) {
771 /* From the context it appears that the occurrence of the
772 procedure/function-identifier is not a call.
774 if( left->nd_class != NameOrCall ) {
775 Xerror(name, "illegal proc/func parameter");
778 else if( ChkLinkOrName(left->nd_left) ) {
779 left->nd_type = left->nd_left->nd_type;
780 MarkUsed(left->nd_left);
784 else if( varaccess ) {
785 if( !ChkVarPar(left, name) ) {
790 else if( !ChkExpression(left) ) {
797 if( !varaccess && bases == T_INTEGER &&
798 BaseType(left->nd_type)->tp_fund == T_LONG) {
799 arg->nd_left = MkNode(IntReduc, NULLNODE, left, &dot);
800 arg->nd_left->nd_type = int_type;
804 if( bases && !(BaseType(left->nd_type)->tp_fund & bases) ) {
805 Xerror(name, "unexpected parameter type");
816 /* Check a procedure call
818 register struct node *left;
820 register struct paramlist *param;
825 struct type *lasttp = NULLTYPE;
827 name = left = expp->nd_left;
829 if( left->nd_type == error_type ) {
830 /* Just check parameters as if they were value parameters
832 expp->nd_type = error_type;
833 while( expp->nd_right )
834 (void) getarg(&expp, 0, 0, name, NULLTYPE);
838 expp->nd_type = ResultType(left->nd_type);
840 /* Check parameter list
842 for( param = ParamList(left->nd_type); param; param = param->next ) {
843 if( !(left = getarg(&expp, 0, (int) IsVarParam(param), name,
844 TypeOfParam(param))) )
848 new_par_section = lasttp != TypeOfParam(param);
849 if( !TstParCompat(TypeOfParam(param), left->nd_type,
850 (int) IsVarParam(param), left, new_par_section) ) {
851 sprint(ebuf, "type incompatibility in parameter %d",
857 /* Convert between integers and longs.
859 if( !IsVarParam(param) && options['d'] ) {
860 if( left->nd_type->tp_fund == T_INTEGER &&
861 TypeOfParam(param)->tp_fund == T_LONG) {
863 MkNode(IntCoerc, NULLNODE, left, &dot);
864 expp->nd_left->nd_type = long_type;
865 left = expp->nd_left;
867 else if( left->nd_type->tp_fund == T_LONG &&
868 TypeOfParam(param)->tp_fund == T_INTEGER) {
870 MkNode(IntReduc, NULLNODE, left, &dot);
871 expp->nd_left->nd_type = int_type;
872 left = expp->nd_left;
876 if( left->nd_type == emptyset_type )
877 /* type of emptyset determined by the context */
878 left->nd_type = TypeOfParam(param);
880 lasttp = TypeOfParam(param);
883 if( expp->nd_right ) {
884 Xerror(name, "too many arguments supplied");
885 while( expp->nd_right )
886 (void) getarg(&expp, 0, 0, name, NULLTYPE);
893 STATIC int ChkStandard();
897 register struct node *expp;
899 /* Check something that looks like a procedure or function call.
900 Of course this does not have to be a call at all,
901 it may also be a standard procedure call.
904 /* First, get the name of the function or procedure
906 register struct node *left = expp->nd_left;
908 expp->nd_type = error_type;
910 if( ChkLinkOrName(left) ) {
913 if( IsProcCall(left) || left->nd_type == error_type ) {
915 It may also be a call to a standard procedure
918 if( left->nd_type == std_type )
919 /* A standard procedure
921 return ChkStandard(expp, left);
923 /* Here, we have found a real procedure call.
927 node_error(left, "procedure or function expected");
931 return ChkProcCall(expp);
936 register struct node *expp;
938 if( !ChkCall(expp) ) return 0;
940 if( !expp->nd_type ) {
941 node_error(expp, "function call expected");
949 register struct node *expp;
951 /* From the context it appears that the occurrence of the function-
952 identifier is a call to that function
954 assert(expp->nd_class == NameOrCall);
955 expp->nd_class = Call;
957 return ChkExCall(expp);
961 ChkStandard(expp,left)
962 register struct node *expp, *left;
964 /* Check a call of a standard procedure or function
967 struct node *arg = expp;
968 struct node *name = left;
971 assert(left->nd_class == Def);
973 req = left->nd_def->df_value.df_reqname;
978 if( !(left = getarg(&arg, T_NUMERIC, 0, name, NULLTYPE)) )
980 expp->nd_type = left->nd_type;
981 if( left->nd_class == Value &&
982 expp->nd_type->tp_fund != T_REAL )
992 if( !(left = getarg(&arg, T_NUMERIC, 0, name, NULLTYPE)) )
994 expp->nd_type = real_type;
995 if( BaseType(left->nd_type)->tp_fund == T_INTEGER ||
996 BaseType(left->nd_type)->tp_fund == T_LONG) {
997 arg->nd_left = MkNode(Cast,NULLNODE, arg->nd_left,&dot);
998 arg->nd_left->nd_type = real_type;
1004 if( !(left = getarg(&arg, T_REAL, 0, name, NULLTYPE)) )
1006 expp->nd_type = int_type;
1010 if( !(left = getarg(&arg, T_ORDINAL, 0, name, NULLTYPE)) )
1012 if( BaseType(left->nd_type)->tp_fund == T_LONG ) {
1013 arg->nd_left = MkNode(IntReduc, NULLNODE, arg->nd_left, &dot);
1014 arg->nd_left->nd_type = int_type;
1016 expp->nd_type = int_type;
1017 if( left->nd_class == Value )
1018 cstcall(expp, R_ORD);
1022 if( !(left = getarg(&arg, T_INTEGER, 0, name, NULLTYPE)) )
1024 expp->nd_type = char_type;
1025 if( left->nd_class == Value )
1026 cstcall(expp, R_CHR);
1031 if( !(left = getarg(&arg, T_ORDINAL, 0, name, NULLTYPE)) )
1033 expp->nd_type = left->nd_type;
1034 if( left->nd_class == Value && options['R'] )
1039 if( !(left = getarg(&arg, T_INTEGER | T_LONG , 0, name, NULLTYPE)) )
1041 expp->nd_type = bool_type;
1042 if( left->nd_class == Value )
1043 cstcall(expp, R_ODD);
1052 if( req == R_PAGE ) {
1053 expp->nd_type = NULLTYPE;
1059 expp->nd_type = NULLTYPE;
1061 else expp->nd_type = bool_type;
1063 if( !arg->nd_right ) {
1066 if( !(nd = ChkStdInOut(name->nd_IDF->id_text, st_out)) )
1069 expp->nd_right = MkNode(Link, nd, NULLNODE, &dot);
1070 expp->nd_right->nd_symb = ',';
1071 arg = arg->nd_right;
1074 if( !(left = getarg(&arg, T_FILE, 1, name, NULLTYPE)) )
1076 if( (req == R_PAGE || req == R_EOLN)
1077 && left->nd_type != text_type ) {
1078 Xerror(name, "textfile expected");
1088 if( !(left = getarg(&arg, T_FILE, 1, name, NULLTYPE)) )
1090 expp->nd_type = NULLTYPE;
1095 struct type *tp1, *tp2, *tp3;
1097 if( req == R_PACK ) {
1099 if( !(left = getarg(&arg, T_ARRAY, 1, name, NULLTYPE)) )
1101 tp1 = left->nd_type; /* (a) */
1102 if( !(left = getarg(&arg, 0, 0, name, NULLTYPE)) )
1104 tp2 = left->nd_type; /* (i) */
1105 if( !(left = getarg(&arg, T_ARRAY, 1, name, NULLTYPE)) )
1107 tp3 = left->nd_type; /* (z) */
1110 /* unpack(z, a, i) */
1111 if( !(left = getarg(&arg, T_ARRAY, 1, name, NULLTYPE)) )
1113 tp3 = left->nd_type; /* (z) */
1114 if( !(left = getarg(&arg, T_ARRAY, 1, name, NULLTYPE)) )
1116 tp1 = left->nd_type; /* (a) */
1117 if( !(left = getarg(&arg, 0, 0, name, NULLTYPE)) )
1119 tp2 = left->nd_type; /* (i) */
1121 if( IsConformantArray(tp1) || IsPacked(tp1) ) {
1122 Xerror(name, "unpacked array expected");
1125 if( !TstAssCompat(IndexType(tp1), tp2) ) {
1126 Xerror(name, "ordinal constant expected");
1129 if( IsConformantArray(tp3) || !IsPacked(tp3) ) {
1130 Xerror(name, "packed array expected");
1133 if( !TstTypeEquiv(tp1->arr_elem, tp3->arr_elem) ) {
1134 Xerror(name, "component types of arrays not equal");
1137 expp->nd_type = NULLTYPE;
1143 if( !(left = getarg(&arg, T_POINTER, 1, name, NULLTYPE)) )
1145 if( arg->nd_right ) {
1146 /* varargs new/dispose(p,c1,.....) */
1147 register struct selector *sel;
1150 if( PointedtoType(left->nd_type)->tp_fund != T_RECORD )
1152 sel = PointedtoType(left->nd_type)->rec_sel;
1156 arg = arg->nd_right;
1157 left = arg->nd_left;
1159 /* ISO : COMPILETIME CONSTANTS NOT PERMITTED */
1160 if( !ChkConstant(left) ) return 0;
1162 if( !TstCompat(left->nd_type, sel->sel_type) ) {
1164 "type incompatibility in caselabel");
1168 i = left->nd_INT - sel->sel_lb;
1169 if( i < 0 || i >= sel->sel_ncst ) {
1171 "case constant: out of bounds");
1175 sel = sel->sel_ptrs[i];
1176 } while( arg->nd_right );
1178 FreeNode(expp->nd_right->nd_right);
1179 expp->nd_right->nd_right = NULLNODE;
1181 expp->nd_type = NULLTYPE;
1186 if( !(left = getarg(&arg, T_POINTER, 1, name, NULLTYPE)) )
1188 expp->nd_type = NULLTYPE;
1192 if( !arg->nd_right ) /* insert 0 parameter */
1193 arg->nd_right = ZeroParam();
1194 if( !(left = getarg(&arg, T_INTEGER, 0, name, NULLTYPE)) )
1196 expp->nd_type = NULLTYPE;
1200 crash("(ChkStandard)");
1203 if( arg->nd_right ) {
1204 Xerror(name, "too many arguments supplied");
1213 register struct node *expp;
1215 /* Check an application of the '^' operator.
1216 The operand must be a variable of a pointer-type or a
1217 variable of a file-type.
1220 register struct type *tp;
1222 assert(expp->nd_class == Arrow);
1223 assert(expp->nd_symb == '^');
1225 expp->nd_type = error_type;
1227 if( !ChkVariable(expp->nd_right) ) return 0;
1229 MarkUsed(expp->nd_right);
1231 tp = expp->nd_right->nd_type;
1233 if( !(tp->tp_fund & (T_POINTER | T_FILE)) ) {
1234 node_error(expp, "\"^\": illegal operand");
1238 expp->nd_type = PointedtoType(tp);
1244 register struct node *expp;
1246 /* Check an array selection.
1247 The left hand side must be a variable of an array type,
1248 and the right hand side must be an expression that is
1249 assignment compatible with the array-index.
1252 register struct type *tpl, *tpr;
1255 assert(expp->nd_class == Arrsel);
1256 assert(expp->nd_symb == '[');
1258 expp->nd_type = error_type;
1260 /* Check the index first, so a[a[j]] is checked in order of
1261 * evaluation. This to make sure that warnings are generated
1262 * in the right order.
1264 retval = ChkExpression(expp->nd_right);
1265 MarkUsed(expp->nd_right);
1266 retval &= ChkVariable(expp->nd_left);
1268 tpl = expp->nd_left->nd_type;
1269 tpr = expp->nd_right->nd_type;
1270 if( tpl == error_type || tpr == error_type ) return 0;
1272 if( tpl->tp_fund != T_ARRAY ) {
1273 node_error(expp, "not indexing an ARRAY type");
1277 /* Type of the index must be assignment compatible with
1278 the index type of the array.
1280 if( !TstCompat(IndexType(tpl), tpr) ) {
1281 node_error(expp, "incompatible index type");
1285 if( tpr == long_type ) {
1286 expp->nd_right = MkNode(IntReduc, NULLNODE, expp->nd_right, &dot);
1287 expp->nd_right->nd_type = int_type;
1290 expp->nd_type = tpl->arr_elem;
1304 node_error(expp, "variable-access expected");
1308 extern int NodeCrash();
1310 int (*ExprChkTable[])() = {
1333 int (*VarAccChkTable[])() = {