Lines Matching +full:sub +full:- +full:node
22 * awk -- executor
36 static NODE *arithmetic(NODE *np);
37 static NODE *comparison(NODE *np);
38 static int type_of(NODE *np);
39 static NODE *lfield(INT fieldno, NODE *value);
40 static NODE *rfield(INT fieldno);
41 static NODE *userfunc(NODE *np);
43 static NODE *exprconcat(NODE *np, int len);
44 static int s_if(NODE *np);
45 static int s_while(NODE *np);
46 static int s_for(NODE *np);
47 static int s_forin(NODE *np);
48 static void setrefield(NODE *value);
50 static int action(NODE *np);
51 static wchar_t *makeindex(NODE *np, wchar_t *array, int tag);
52 static int exprtest(NODE *np);
59 * when overflow occurs during +, -, or * operations. This is very
60 * non-portable if you desire such a speed optimisation. You may wish
80 (i1 == LONG_MIN && i2 == -1))) goto overflow
93 static NODE nodes[NSNODE]; /* Cache of quick access nodes */
94 static NODE *fnodep = &nodes[0];
98 static NODE *retval; /* Last return value of a function */
102 * for-in loops. This needs to be global so that delete can check to see
103 * if it is deleting the next node to be used by a loop.
106 static NODE* forindex[NFORINLOOP];
107 static NODE** next_forin = forindex;
110 * Assign a string directly to a NODE without creating an intermediate
111 * NODE. This can handle either FALLOC, FSTATIC, FNOALLOC or FSENSE for
112 * "flags" argument. Also the NODE "np" must be reduced to an lvalue
116 strassign(NODE *np, STRING string, int flags, size_t length) in strassign()
118 if (np->n_type == FUNC) in strassign()
120 else if (np->n_type == GETLINE || np->n_type == KEYWORD) in strassign()
122 if (np->n_flags & FSPECIAL) { in strassign()
126 if (isastring(np->n_flags)) in strassign()
127 free((wchar_t *)np->n_string); in strassign()
128 np->n_strlen = length++; in strassign()
131 np->n_string = (STRING) emalloc(length); in strassign()
132 (void) memcpy((void *)np->n_string, string, length); in strassign()
134 np->n_string = string; in strassign()
140 np->n_flags &= FSAVE; in strassign()
146 np->n_flags |= flags; in strassign()
150 * Assign to a variable node.
155 NODE *
156 nassign(NODE *np, NODE *value) in nassign()
161 /* short circuit assignment of a node to itself */ in nassign()
164 if (np->n_flags & FSPECIAL) { in nassign()
166 if (isastring(np->n_flags)) in nassign()
167 free((void *)np->n_string); in nassign()
168 len = sizeof (wchar_t) * ((np->n_strlen = in nassign()
170 np->n_string = emalloc(len); in nassign()
171 (void) memcpy((wchar_t *)np->n_string, cp, len); in nassign()
172 np->n_flags = FALLOC|FSTRING|FSPECIAL; in nassign()
174 if (np->n_string[0] == '\n') in nassign()
176 else if (np->n_string[0] == '\0') in nassign()
185 if (wcslen((wchar_t *)np->n_string) > 1) in nassign()
187 else if (np->n_string[0] == ' ') in nassign()
195 if (isastring(np->n_flags)) in nassign()
196 free((wchar_t *)np->n_string); in nassign()
197 if (isstring(value->n_flags)) { in nassign()
198 np->n_strlen = value->n_strlen; in nassign()
199 if (value->n_flags&FALLOC || value->n_string != _null) { in nassign()
200 len = (np->n_strlen+1) * sizeof (wchar_t); in nassign()
201 np->n_string = emalloc(len); in nassign()
202 (void) memcpy(np->n_string, value->n_string, len); in nassign()
203 np->n_flags &= FSAVE; in nassign()
204 np->n_flags |= value->n_flags & ~FSAVE; in nassign()
205 np->n_flags |= FALLOC; in nassign()
208 np->n_string = value->n_string; in nassign()
209 } else if (value->n_flags & FINT) in nassign()
210 np->n_int = value->n_int; in nassign()
212 np->n_real = value->n_real; in nassign()
213 np->n_flags &= FSAVE; in nassign()
214 np->n_flags |= value->n_flags & ~FSAVE; in nassign()
222 setrefield(NODE *np) in setrefield()
227 if ((n = REGWCOMP(&re, np->n_string)) != REG_OK) { in setrefield()
230 (char *)linebuf, np->n_string); in setrefield()
237 * Assign to an l-value node.
239 NODE *
240 assign(NODE *left, NODE *right) in assign()
242 if (isleaf(right->n_flags)) { in assign()
243 if (right->n_type == PARM) in assign()
244 right = right->n_next; in assign()
248 switch (left->n_type) { in assign()
257 * If it's a parameter then link to the actual value node and in assign()
260 left = left->n_next; in assign()
264 return (lfield(exprint(left->n_left), right)); in assign()
269 left->n_name); in assign()
279 * Compiled tree non-terminal node.
281 NODE *
282 node(int type, NODE *left, NODE *right) in node() function
284 register NODE *np; in node()
287 np->n_left = left; in node()
288 np->n_right = right; in node()
289 np->n_lineno = lineno; in node()
294 * Create an integer node.
296 NODE *
299 register NODE *np; in intnode()
302 np->n_flags = FINT|FVINT; in intnode()
303 np->n_int = i; in intnode()
308 * Create a real number node.
310 NODE *
313 register NODE *np; in realnode()
316 np->n_flags = FREAL|FVREAL; in realnode()
317 np->n_real = real; in realnode()
322 * Make a node for a string.
324 NODE *
327 register NODE *np; in stringnode()
330 np->n_strlen = length; in stringnode()
332 np->n_string = emalloc(length = (length+1) * sizeof (wchar_t)); in stringnode()
333 (void) memcpy(np->n_string, s, length); in stringnode()
335 np->n_string = s; in stringnode()
342 np->n_flags = type_of(np); in stringnode()
345 np->n_flags = FSTRING; in stringnode()
346 np->n_flags |= how; in stringnode()
365 * Allocate an empty node of given type.
366 * String space for the node is given by `length'.
368 NODE *
371 register NODE *np; in emptynode()
376 np = (NODE *)emalloc(sizeof (NODE) + in emptynode()
379 np->n_next = freelist; in emptynode()
383 np->n_flags = FNONTOK; in emptynode()
384 np->n_type = type; in emptynode()
385 np->n_alink = NNULL; in emptynode()
391 * Free a node.
394 freenode(NODE *np) in freenode()
396 if (isastring(np->n_flags)) in freenode()
397 free((wchar_t *)np->n_string); in freenode()
398 else if (np->n_type == RE) { in freenode()
399 REGWFREE(np->n_regexp); in freenode()
410 register NODE *np; in kinstall()
415 np->n_keywtype = type; in kinstall()
416 (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t)); in kinstall()
421 * Install built-in function.
423 NODE *
426 register NODE *np; in finstall()
431 np->n_function = func; in finstall()
432 (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t)); in finstall()
440 * 1 if no creation of a new NODE,
441 * 0 if ok to create new NODE
443 NODE *
447 register NODE *np; in vlookup()
451 if (np->n_hash == hash && wcscmp(name, np->n_name) == 0) in vlookup()
453 np = np->n_next; in vlookup()
459 np->n_flags = FSTRING|FVINT; in vlookup()
460 np->n_strlen = 0; in vlookup()
461 np->n_string = _null; in vlookup()
462 (void) memcpy(np->n_name, name, in vlookup()
473 addsymtab(NODE *np) in addsymtab()
475 register NODE **spp; in addsymtab()
477 np->n_hash = dohash((wchar_t *)np->n_name); in addsymtab()
478 spp = &symtab[hashbuck(np->n_hash)]; in addsymtab()
479 np->n_next = *spp; in addsymtab()
484 * Delete the given node from the symbol table.
485 * If fflag is non-zero, also free the node space.
491 delsymtab(NODE *np, int fflag) in delsymtab()
493 register NODE *rnp; in delsymtab()
494 register NODE *prevp; in delsymtab()
495 register NODE **sptr; in delsymtab()
502 h = hashbuck(np->n_hash); in delsymtab()
504 for (rnp = symtab[h]; rnp != NNULL; rnp = rnp->n_next) { in delsymtab()
507 * check all of the for-in loop pointers in delsymtab()
514 if (*--sptr == rnp) { in delsymtab()
515 *sptr = rnp->n_next; in delsymtab()
521 symtab[h] = rnp->n_next; else in delsymtab()
522 prevp->n_next = rnp->n_next; in delsymtab()
555 execute(NODE *wp) in execute()
557 register NODE *np; in execute()
559 register NODE *tnp; in execute()
567 if (wp->n_type == COMMA) { in execute()
568 np = wp->n_left; in execute()
569 wp = wp->n_right; in execute()
574 if (np->n_type != PACT) in execute()
577 * Save the parent node and evaluate the pattern. in execute()
582 np = np->n_left; in execute()
587 if (np->n_type != phase) in execute()
589 } else if ((type = np->n_type) == BEGIN || type == END) { in execute()
597 if (np->n_flags & FMATCH) { in execute()
598 if (exprint(np->n_right) != 0) in execute()
599 np->n_flags &= ~FMATCH; in execute()
600 } else if (exprint(np->n_left) != 0) { in execute()
601 if (exprint(np->n_right) == 0) in execute()
602 np->n_flags |= FMATCH; in execute()
608 if (action(np->n_right)) { in execute()
623 register NODE *np, *nnp; in freetemps()
628 if (isastring(np->n_flags)) { in freetemps()
629 free((wchar_t *)np->n_string); in freetemps()
630 } else if (np->n_type == RE) { in freetemps()
631 REGWFREE(np->n_regexp); in freetemps()
636 nnp = np->n_next; in freetemps()
647 action(NODE *wp) in action()
649 register NODE *np; in action()
651 register NODE *l; in action()
654 if (wp->n_type == COMMA) { in action()
655 np = wp->n_left; in action()
656 wp = wp->n_right; in action()
669 switch (np->n_type) { in action()
671 (void) assign(np->n_left, np->n_right); in action()
683 if (np->n_left != NNULL) in action()
684 act = (int)exprint(np->n_left); else in action()
692 np = np->n_left != NNULL in action()
693 ? exprreduce(np->n_left) in action()
696 retval->n_flags = FINT; in action()
705 return (np->n_type); in action()
708 if ((l = np->n_left)->n_type == PARM) { in action()
709 l = l->n_next; in action()
710 if (!(l->n_flags & FLARRAY)) in action()
711 l = l->n_alink; in action()
713 switch (l->n_type) { in action()
719 if ((np = l->n_left)->n_type == PARM) { in action()
720 np = np->n_next; in action()
721 if (!(np->n_flags & FLARRAY)) in action()
722 np = np->n_alink; in action()
725 * get pointer to the node for this array in action()
733 * because arrays are singley-linked. in action()
736 if (np->n_alink == l) { in action()
737 np->n_alink = l->n_alink; in action()
740 np = np->n_alink; in action()
746 if (isstring(l->n_flags) && in action()
747 l->n_string == _null) in action()
795 delarray(NODE *np) in delarray()
797 register NODE *nnp; in delarray()
799 nnp = np->n_alink; in delarray()
800 np->n_alink = NNULL; in delarray()
802 np = nnp->n_alink; in delarray()
812 exprint(NODE *np) in exprint()
814 if (isleaf(np->n_flags)) { in exprint()
815 if (np->n_type == PARM) in exprint()
816 np = np->n_next; in exprint()
820 switch (np->n_type) { in exprint()
824 if (np->n_flags & FINT) in exprint()
825 return (np->n_int); in exprint()
826 if (np->n_flags & FREAL) in exprint()
827 return ((INT)np->n_real); in exprint()
828 return ((INT)wcstoll(np->n_string, NULL, 10)); in exprint()
841 exprreal(NODE *np) in exprreal()
845 if (isleaf(np->n_flags)) { in exprreal()
846 if (np->n_type == PARM) in exprreal()
847 np = np->n_next; in exprreal()
851 switch (np->n_type) { in exprreal()
855 if (np->n_flags & FREAL) in exprreal()
856 return (np->n_real); in exprreal()
857 if (np->n_flags & FINT) in exprreal()
858 return ((REAL)np->n_int); in exprreal()
859 return ((REAL)wcstod((wchar_t *)np->n_string, (wchar_t **)0)); in exprreal()
872 exprstring(NODE *np) in exprstring()
874 if (isleaf(np->n_flags)) { in exprstring()
875 if (np->n_type == PARM) in exprstring()
876 np = np->n_next; in exprstring()
880 switch (np->n_type) { in exprstring()
884 if (isstring(np->n_flags)) in exprstring()
885 return (np->n_string); in exprstring()
886 if (np->n_flags & FINT) in exprstring()
887 return (STRING)lltoa((long long)np->n_int); in exprstring()
892 (double)np->n_real); in exprstring()
918 *--p = '\0'; in lltoa()
920 neg = 1, l = -l; else in lltoa()
924 *--p = s%10 + '0'; in lltoa()
929 *--p = l%10 + '0'; in lltoa()
934 *--p = '-'; in lltoa()
939 * Return pointer to node with concatenation of operands of CONCAT node.
944 * operand is not a CONCAT node.
946 static NODE *
947 exprconcat(NODE *np, int len) in exprconcat()
949 /* we KNOW (np->n_type==CONCAT) */ in exprconcat()
950 register NODE *lnp = np->n_left; in exprconcat()
951 register NODE *rnp = np->n_right; in exprconcat()
958 if (isleaf(rnp->n_flags) && rnp->n_type == PARM) in exprconcat()
959 rnp = rnp->n_next; in exprconcat()
960 if (isstring(rnp->n_flags)) { in exprconcat()
961 rsp = rnp->n_string; in exprconcat()
962 rlen = rnp->n_strlen; in exprconcat()
971 if (lnp->n_type == CONCAT) { in exprconcat()
973 cp = lnp->n_string; in exprconcat()
974 llen = lnp->n_strlen; in exprconcat()
978 if (isleaf(lnp->n_flags) && lnp->n_type == PARM) in exprconcat()
979 lnp = lnp->n_next; in exprconcat()
980 if (isstring(lnp->n_flags)) { in exprconcat()
981 lsp = lnp->n_string; in exprconcat()
982 llen = lnp->n_strlen; in exprconcat()
990 lnp->n_strlen += rlen; in exprconcat()
995 * Reduce an expression to a terminal node.
997 NODE *
998 exprreduce(NODE *np) in exprreduce()
1001 NODE *tnp; in exprreduce()
1009 * a var or constant is a leaf-node (no further reduction required) in exprreduce()
1012 if ((t = np->n_type) == VAR || t == CONSTANT) in exprreduce()
1015 * If it's a parameter then it is probably a leaf node but it in exprreduce()
1020 if ((np = np->n_next)->n_type == ARRAY) in exprreduce()
1021 awkerr(badarray, np->n_name); in exprreduce()
1025 * All the rest are non-leaf nodes. in exprreduce()
1033 return (rfield(exprint(np->n_left))); in exprreduce()
1038 temp = np->n_type; in exprreduce()
1039 tnp = np->n_left; in exprreduce()
1040 np = np->n_right; in exprreduce()
1042 fname = aname = tnp->n_name; in exprreduce()
1043 if (tnp->n_type == PARM) { in exprreduce()
1044 tnp = tnp->n_next; in exprreduce()
1045 tag = tnp->n_scope; in exprreduce()
1046 if (!(tnp->n_flags & FLARRAY)) { in exprreduce()
1047 tnp = tnp->n_alink; in exprreduce()
1049 aname = tnp->n_name; in exprreduce()
1051 if (tnp->n_type != ARRAY) { in exprreduce()
1052 if (!isstring(tnp->n_flags) || tnp->n_string != _null) in exprreduce()
1057 if (tnp->n_alink != NNULL) { in exprreduce()
1058 tag = tnp->n_scope; in exprreduce()
1059 if (!(tnp->n_flags & FLARRAY)) in exprreduce()
1060 tnp = tnp->n_alink; in exprreduce()
1061 aname = tnp->n_name; in exprreduce()
1064 if (tnp->n_flags & FLARRAY) in exprreduce()
1065 tag = tnp->n_scope; in exprreduce()
1070 if (np == NNULL || np->n_type == COMMA) in exprreduce()
1079 if (!(np->n_flags & FINARRAY)) { in exprreduce()
1080 np->n_alink = tnp->n_alink; in exprreduce()
1081 tnp->n_alink = np; in exprreduce()
1082 np->n_flags |= FINARRAY; in exprreduce()
1093 --concflag; in exprreduce()
1097 return (intnode(exprtest(np->n_left) == 0 ? (INT)1 : (INT)0)); in exprreduce()
1100 return ((exprtest(np->n_left) != 0 && in exprreduce()
1101 exprtest(np->n_right) != 0) ? const1 : const0); in exprreduce()
1104 return ((exprtest(np->n_left) != 0 || in exprreduce()
1105 exprtest(np->n_right) != 0) ? const1 : const0); in exprreduce()
1117 f1 = (double)exprreal(np->n_left); in exprreduce()
1118 f2 = (double)exprreal(np->n_right); in exprreduce()
1123 if (np->n_right->n_type != COLON) in exprreduce()
1125 if (exprtest(np->n_left)) in exprreduce()
1126 np = np->n_right->n_left; else in exprreduce()
1127 np = np->n_right->n_right; in exprreduce()
1139 case SUB: in exprreduce()
1146 inc_oper->n_type = SUB; in exprreduce()
1149 inc_oper->n_type = ADD; in exprreduce()
1151 if ((np = np->n_left)->n_type == INDEX) in exprreduce()
1153 if (np->n_flags & FREAL) in exprreduce()
1154 tnp = realnode(np->n_real); in exprreduce()
1157 inc_oper->n_left = np; in exprreduce()
1162 inc_oper->n_type = SUB; in exprreduce()
1165 inc_oper->n_type = ADD; in exprreduce()
1167 if ((np = np->n_left)->n_type == INDEX) in exprreduce()
1169 inc_oper->n_left = np; in exprreduce()
1173 asn_oper->n_type = ADD; in exprreduce()
1176 asn_oper->n_type = SUB; in exprreduce()
1179 asn_oper->n_type = MUL; in exprreduce()
1182 asn_oper->n_type = DIV; in exprreduce()
1185 asn_oper->n_type = REM; in exprreduce()
1188 asn_oper->n_type = EXP; in exprreduce()
1190 asn_oper->n_right = np->n_right; in exprreduce()
1191 if ((np = np->n_left)->n_type == INDEX) in exprreduce()
1193 asn_oper->n_left = np; in exprreduce()
1201 return ((*np->n_left->n_function)(np->n_right)); in exprreduce()
1204 if (regmatch(np->n_regexp, linebuf) == REG_OK) in exprreduce()
1209 cp = exprstring(np->n_left); in exprreduce()
1210 if (regmatch(getregexp(np->n_right), cp) == REG_OK) in exprreduce()
1215 cp = exprstring(np->n_left); in exprreduce()
1216 if (regmatch(getregexp(np->n_right), cp) != REG_OK) in exprreduce()
1221 return (assign(np->n_left, np->n_right)); in exprreduce()
1224 awkerr(badarray, np->n_name); in exprreduce()
1227 awkerr(varnotfunc, np->n_name); in exprreduce()
1239 static NODE *
1240 arithmetic(NODE *np) in arithmetic()
1242 register NODE *left, *right; in arithmetic()
1248 left = exprreduce(np->n_left); in arithmetic()
1249 if (isreal(left->n_flags) || in arithmetic()
1250 (isstring(left->n_flags) && (type_of(left)&FVREAL))) { in arithmetic()
1253 r2 = exprreal(np->n_right); in arithmetic()
1256 right = exprreduce(np->n_right); in arithmetic()
1257 if (isreal(right->n_flags) || in arithmetic()
1258 (isstring(right->n_flags) && (type_of(right)&FVREAL))) { in arithmetic()
1269 switch (np->n_type) { in arithmetic()
1279 * Strategically placed between ADD and SUB in arithmetic()
1288 case SUB: in arithmetic()
1290 iresult = i1 - i2; in arithmetic()
1293 r1 -= r2; in arithmetic()
1336 static NODE *
1337 comparison(NODE *np) in comparison()
1339 register NODE *left, *right; in comparison()
1345 left = np->n_left; in comparison()
1346 if (isleaf(left->n_flags)) { in comparison()
1347 if (left->n_type == PARM) in comparison()
1348 left = left->n_next; in comparison()
1351 tl = left->n_flags; in comparison()
1352 right = np->n_right; in comparison()
1353 if (isleaf(right->n_flags)) { in comparison()
1354 if (right->n_type == PARM) in comparison()
1355 right = right->n_next; in comparison()
1359 --concflag; in comparison()
1361 tr = right->n_flags; in comparison()
1366 * if it's false, then AWK will use the POSIX-mandated behaviour. in comparison()
1377 cmp = -1; in comparison()
1386 cmp = -1; in comparison()
1408 cmp = -1; in comparison()
1417 cmp = -1; in comparison()
1425 switch (np->n_type) { in comparison()
1453 * The node must be a FSTRING type and the return value
1457 type_of(NODE *np) in type_of()
1466 cp = (wchar_t *)np->n_string; in type_of()
1471 if (*cp == '-' || *cp == '+') in type_of()
1498 case '-': in type_of()
1529 static NODE *
1540 cp = fields[fieldno-1]; in rfield()
1564 n = ep-ip; in fieldsplit()
1569 if (varNF->n_flags & FINT) in fieldsplit()
1570 varNF->n_int = fcount; in fieldsplit()
1572 constant->n_int = fcount; in fieldsplit()
1581 * Return the unevaluated node as one doesn't always need it
1584 static NODE *
1585 lfield(INT fieldno, NODE *np) in lfield()
1605 if (--fieldno < nfield && in lfield()
1652 lbuflen = op-linebuf; in lfield()
1653 if (varNF->n_flags & FINT) in lfield()
1654 varNF->n_int = nfield; in lfield()
1656 constant->n_int = nfield; in lfield()
1670 static NODE *
1671 userfunc(NODE *np) in userfunc()
1673 register NODE *temp; in userfunc()
1674 NODE *fnp; in userfunc()
1676 if ((fnp = np->n_left) == NNULL) in userfunc()
1678 if (fnp->n_type != UFUNC) in userfunc()
1679 awkerr(varnotfunc, fnp->n_name); in userfunc()
1684 fnp->n_name, NRECUR); in userfunc()
1688 fnp->n_name); in userfunc()
1691 fnp = fnp->n_ufunc; in userfunc()
1693 register NODE *formal; in userfunc()
1694 register NODE *actual; in userfunc()
1695 NODE *formlist, *actlist, *templist, *temptail; in userfunc()
1698 actlist = np->n_right; in userfunc()
1699 formlist = fnp->n_left; in userfunc()
1708 register NODE *array; in userfunc()
1720 switch (actual->n_type) { in userfunc()
1727 array = actual = actual->n_next; in userfunc()
1728 t = actual->n_type; in userfunc()
1729 scope_tag = actual->n_scope; in userfunc()
1730 if (!(actual->n_flags & FLARRAY)) in userfunc()
1731 array = actual->n_alink; in userfunc()
1738 temp = emptynode(t, len = wcslen(formal->n_name)); in userfunc()
1739 (void) memcpy(temp->n_name, formal->n_name, in userfunc()
1741 temp->n_flags = FSTRING|FVINT; in userfunc()
1742 temp->n_string = _null; in userfunc()
1743 temp->n_strlen = 0; in userfunc()
1747 temp->n_flags |= FLARRAY; in userfunc()
1748 temp->n_scope = scope_tag; in userfunc()
1754 temp->n_alink = actual; in userfunc()
1759 temptail->n_next = temp; in userfunc()
1763 temp->n_next = NNULL; in userfunc()
1764 if (actual->n_type == CONSTANT) in userfunc()
1765 temp->n_alink = temp; in userfunc()
1767 temp->n_alink = array; in userfunc()
1772 formlist = fnp->n_left; in userfunc()
1775 templist = temp->n_next; in userfunc()
1777 temp->n_next = formal->n_next; in userfunc()
1778 formal->n_next = temp; in userfunc()
1790 register NODE *savenode = curnode; in userfunc()
1793 if (action(fnp->n_right) == RETURN) in userfunc()
1799 register NODE *formal; in userfunc()
1800 NODE *formlist; in userfunc()
1802 formlist = fnp->n_left; in userfunc()
1804 temp = formal->n_next; in userfunc()
1805 formal->n_next = temp->n_next; in userfunc()
1806 /* if node is a local array, free the elements */ in userfunc()
1807 if (temp->n_type == ARRAY && (temp->n_scope == slevel)) in userfunc()
1812 --slevel; in userfunc()
1820 getregexp(NODE *np) in getregexp()
1822 if (np->n_type == RE) in getregexp()
1823 return (np->n_regexp); in getregexp()
1825 return (np->n_regexp); in getregexp()
1831 NODE *
1832 getlist(NODE **npp) in getlist()
1834 register NODE *np; in getlist()
1838 if (np->n_type == COMMA) { in getlist()
1839 *npp = np->n_right; in getlist()
1840 return (np->n_left); in getlist()
1851 s_if(NODE *np) in s_if()
1853 register NODE *xp; in s_if()
1856 test = exprtest(np->n_left); in s_if()
1857 xp = np->n_right; in s_if()
1858 if (xp->n_type != ELSE) in s_if()
1861 xp = xp->n_left; in s_if()
1863 xp = xp->n_right; in s_if()
1871 s_while(NODE *np) in s_while()
1875 if (np->n_type == DO) in s_while()
1878 if (exprtest(np->n_left) == 0) in s_while()
1881 if ((act = action(np->n_right)) != 0) { in s_while()
1901 s_for(NODE *np) in s_for()
1903 register NODE *testnp, *incnp, *initnp; in s_for()
1905 NODE *listp; in s_for()
1907 listp = np->n_left; in s_for()
1916 if ((act = action(np->n_right)) != 0) { in s_for()
1939 s_forin(NODE *np) in s_forin()
1941 register NODE *left; in s_forin()
1943 register NODE *var; in s_forin()
1944 register NODE **nnp; in s_forin()
1945 register NODE *statement; in s_forin()
1951 left = np->n_left; in s_forin()
1952 statement = np->n_right; in s_forin()
1953 if (left->n_type != IN) in s_forin()
1955 if ((var = left->n_left)->n_type == PARM) in s_forin()
1956 var = var->n_next; in s_forin()
1957 np = left->n_right; in s_forin()
1958 if (np->n_type == PARM) { in s_forin()
1959 np = np->n_next; in s_forin()
1960 if (!(np->n_flags & FLARRAY)) in s_forin()
1961 np = np->n_alink; in s_forin()
1969 * At this point if the node is not actually an array in s_forin()
1974 if (np->n_type != ARRAY) { in s_forin()
1975 if (!isstring(np->n_flags) || np->n_string != _null) in s_forin()
1976 awkerr(notarray, np->n_name); in s_forin()
1980 if (np->n_alink != NNULL) in s_forin()
1981 if (!(np->n_flags & FLARRAY)) in s_forin()
1982 np = np->n_alink; in s_forin()
1986 * Set up a pointer to the first node in the array list. in s_forin()
1989 * that might be pointing at a node which has been deleted. in s_forin()
1994 if ((*(nnp = next_forin) = np->n_alink) == 0) in s_forin()
2008 for (alen = 0; (*nnp)->n_name[alen++] != ']'; ) in s_forin()
2009 if ((*nnp)->n_name[alen] == '\0') in s_forin()
2016 index = left->n_name; in s_forin()
2020 index = np->n_name+alen; in s_forin()
2021 *nnp = np->n_alink; in s_forin()
2037 next_forin--; in s_forin()
2044 NODE *
2045 symwalk(int *buckp, NODE **npp) in symwalk()
2047 register NODE *np; in symwalk()
2056 if (np->n_type == VAR && in symwalk()
2057 (!isstring(np->n_flags) || np->n_string != _null)) { in symwalk()
2058 *npp = np->n_next; in symwalk()
2061 np = np->n_next; in symwalk()
2070 exprtest(NODE *np) in exprtest()
2079 if (isint(t = np->n_flags)) { in exprtest()
2082 return (np->n_int != 0); in exprtest()
2087 rval = isstring(t) ? exprreal(np) : np->n_real; in exprtest()
2096 * The node (np) is the list of indices and 'array' is the array name.
2099 makeindex(NODE *np, wchar_t *array, int tag) in makeindex()
2104 register NODE *index; in makeindex()
2121 if (np->n_type != COMMA) { in makeindex()
2125 if (isleaf(np->n_flags) && np->n_type == PARM) in makeindex()
2126 np = np->n_next; in makeindex()
2127 if (isstring(np->n_flags)) { in makeindex()
2128 indstr = np->n_string; in makeindex()
2129 len = np->n_strlen; in makeindex()
2144 *cp++ = tags[--taglen]; in makeindex()
2163 cp[n++] = tags[--taglen]; in makeindex()
2179 * Promote a node to an array. In the simplest case, just set the
2180 * node type field to ARRAY. The more complicated case involves walking
2185 promote(NODE *n) in promote()
2187 register NODE *prev = NNULL; in promote()
2188 register NODE *next; in promote()
2192 * setting each node to type array. in promote()
2194 while ((n->n_flags & FLARRAY) && (n->n_alink != n)) { in promote()
2195 n->n_type = ARRAY; in promote()
2196 next = n->n_alink; in promote()
2197 n->n_alink = prev; in promote()
2204 * reset it's alink field to NNULL - normally it points back in promote()
2205 * to itself - this is used in other parts of the code to in promote()
2208 n->n_type = ARRAY; in promote()
2209 if (n->n_flags & FLARRAY) in promote()
2210 n->n_alink = NNULL; in promote()
2218 prev->n_flags &= ~FLARRAY; in promote()
2219 next = prev->n_alink; in promote()
2220 prev->n_alink = n; in promote()