Lines Matching refs:np

38 static NODE	*arithmetic(NODE *np);
39 static NODE *comparison(NODE *np);
40 static int type_of(NODE *np);
43 static NODE *userfunc(NODE *np);
45 static NODE *exprconcat(NODE *np, int len);
46 static int s_if(NODE *np);
47 static int s_while(NODE *np);
48 static int s_for(NODE *np);
49 static int s_forin(NODE *np);
52 static int action(NODE *np);
53 static wchar_t *makeindex(NODE *np, wchar_t *array, int tag);
54 static int exprtest(NODE *np);
114 * "flags" argument. Also the NODE "np" must be reduced to an lvalue
118 strassign(NODE *np, STRING string, int flags, size_t length)
120 if (np->n_type == FUNC)
122 else if (np->n_type == GETLINE || np->n_type == KEYWORD)
124 if (np->n_flags & FSPECIAL) {
125 (void) nassign(np, stringnode(string, flags, length));
128 if (isastring(np->n_flags))
129 free((wchar_t *)np->n_string);
130 np->n_strlen = length++;
133 np->n_string = (STRING) emalloc(length);
134 (void) memcpy((void *)np->n_string, string, length);
136 np->n_string = string;
142 np->n_flags &= FSAVE;
145 flags |= type_of(np);
148 np->n_flags |= flags;
158 nassign(NODE *np, NODE *value)
164 if (np == value)
165 return (np);
166 if (np->n_flags & FSPECIAL) {
167 if (np == varRS || np == varFS) {
168 if (isastring(np->n_flags))
169 free((void *)np->n_string);
170 len = sizeof (wchar_t) * ((np->n_strlen =
172 np->n_string = emalloc(len);
173 (void) memcpy((wchar_t *)np->n_string, cp, len);
174 np->n_flags = FALLOC|FSTRING|FSPECIAL;
175 if (np == varRS) {
176 if (np->n_string[0] == '\n')
178 else if (np->n_string[0] == '\0')
182 } else if (np == varFS) {
187 if (wcslen((wchar_t *)np->n_string) > 1)
188 setrefield(np);
189 else if (np->n_string[0] == ' ')
194 return (np);
197 if (isastring(np->n_flags))
198 free((wchar_t *)np->n_string);
200 np->n_strlen = value->n_strlen;
202 len = (np->n_strlen+1) * sizeof (wchar_t);
203 np->n_string = emalloc(len);
204 (void) memcpy(np->n_string, value->n_string, len);
205 np->n_flags &= FSAVE;
206 np->n_flags |= value->n_flags & ~FSAVE;
207 np->n_flags |= FALLOC;
208 return (np);
210 np->n_string = value->n_string;
212 np->n_int = value->n_int;
214 np->n_real = value->n_real;
215 np->n_flags &= FSAVE;
216 np->n_flags |= value->n_flags & ~FSAVE;
217 return (np);
224 setrefield(NODE *np)
229 if ((n = REGWCOMP(&re, np->n_string)) != REG_OK) {
232 (char *)linebuf, np->n_string);
286 register NODE *np;
288 np = emptynode(type, 0);
289 np->n_left = left;
290 np->n_right = right;
291 np->n_lineno = lineno;
292 return (np);
301 register NODE *np;
303 np = emptynode(CONSTANT, 0);
304 np->n_flags = FINT|FVINT;
305 np->n_int = i;
306 return (np);
315 register NODE *np;
317 np = emptynode(CONSTANT, 0);
318 np->n_flags = FREAL|FVREAL;
319 np->n_real = real;
320 return (np);
329 register NODE *np;
331 np = emptynode(CONSTANT, 0);
332 np->n_strlen = length;
334 np->n_string = emalloc(length = (length+1) * sizeof (wchar_t));
335 (void) memcpy(np->n_string, s, length);
337 np->n_string = s;
344 np->n_flags = type_of(np);
347 np->n_flags = FSTRING;
348 np->n_flags |= how;
349 return (np);
373 register NODE *np;
376 np = fnodep++;
378 np = (NODE *)emalloc(sizeof (NODE) +
381 np->n_next = freelist;
382 freelist = np;
385 np->n_flags = FNONTOK;
386 np->n_type = type;
387 np->n_alink = NNULL;
389 return (np);
396 freenode(NODE *np)
398 if (isastring(np->n_flags))
399 free((wchar_t *)np->n_string);
400 else if (np->n_type == RE) {
401 REGWFREE(np->n_regexp);
403 free((wchar_t *)np);
412 register NODE *np;
416 np = emptynode(KEYWORD, l);
417 np->n_keywtype = type;
418 (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t));
419 addsymtab(np);
428 register NODE *np;
432 np = emptynode(type, l);
433 np->n_function = func;
434 (void) memcpy(np->n_name, name, (l+1) * sizeof (wchar_t));
435 addsymtab(np);
436 return (np);
449 register NODE *np;
451 np = symtab[hashbuck(hash = dohash((wchar_t *)name))];
452 while (np != NNULL) {
453 if (np->n_hash == hash && wcscmp(name, np->n_name) == 0)
454 return (np);
455 np = np->n_next;
458 np = NNULL;
460 np = emptynode(VAR, hash = wcslen(name));
461 np->n_flags = FSTRING|FVINT;
462 np->n_strlen = 0;
463 np->n_string = _null;
464 (void) memcpy(np->n_name, name,
466 addsymtab(np);
468 return (np);
475 addsymtab(NODE *np)
479 np->n_hash = dohash((wchar_t *)np->n_name);
480 spp = &symtab[hashbuck(np->n_hash)];
481 np->n_next = *spp;
482 *spp = np;
493 delsymtab(NODE *np, int fflag)
504 h = hashbuck(np->n_hash);
507 if (rnp == np) {
559 register NODE *np;
570 np = wp->n_left;
573 np = wp;
576 if (np->n_type != PACT)
583 tnp = np;
584 np = np->n_left;
585 if (np == NNULL) {
589 if (np->n_type != phase)
591 } else if ((type = np->n_type) == BEGIN || type == END) {
599 if (np->n_flags & FMATCH) {
600 if (exprint(np->n_right) != 0)
601 np->n_flags &= ~FMATCH;
602 } else if (exprint(np->n_left) != 0) {
603 if (exprint(np->n_right) == 0)
604 np->n_flags |= FMATCH;
607 } else if (exprint(np) == 0)
609 np = tnp;
610 if (action(np->n_right)) {
625 register NODE *np, *nnp;
629 for (np = &nodes[0]; np < fnodep; np++) {
630 if (isastring(np->n_flags)) {
631 free((wchar_t *)np->n_string);
632 } else if (np->n_type == RE) {
633 REGWFREE(np->n_regexp);
637 for (np = freelist; np != NNULL; np = nnp) {
638 nnp = np->n_next;
639 freenode(np);
651 register NODE *np;
657 np = wp->n_left;
660 np = wp;
665 curnode = np;
671 switch (np->n_type) {
673 (void) assign(np->n_left, np->n_right);
677 s_print(np);
681 s_prf(np);
685 if (np->n_left != NNULL)
686 act = (int)exprint(np->n_left); else
694 np = np->n_left != NNULL
695 ? exprreduce(np->n_left)
699 (void) nassign(retval, np);
707 return (np->n_type);
710 if ((l = np->n_left)->n_type == PARM) {
721 if ((np = l->n_left)->n_type == PARM) {
722 np = np->n_next;
723 if (!(np->n_flags & FLARRAY))
724 np = np->n_alink;
737 while (np != NNULL) {
738 if (np->n_alink == l) {
739 np->n_alink = l->n_alink;
742 np = np->n_alink;
760 if ((act = s_while(np)) != 0)
765 if ((act = s_for(np)) != 0)
770 if ((act = s_forin(np)) != 0)
775 if ((act = s_if(np)) != 0)
780 (void) exprreduce(np);
796 delarray(NODE *np)
800 nnp = np->n_alink;
801 np->n_alink = NNULL;
803 np = nnp->n_alink;
805 nnp = np;
813 exprint(NODE *np)
815 if (isleaf(np->n_flags)) {
816 if (np->n_type == PARM)
817 np = np->n_next;
820 np = exprreduce(np);
821 switch (np->n_type) {
825 if (np->n_flags & FINT)
826 return (np->n_int);
827 if (np->n_flags & FREAL)
828 return ((INT)np->n_real);
829 return ((INT)wcstoll(np->n_string, NULL, 10));
842 exprreal(NODE *np)
846 if (isleaf(np->n_flags)) {
847 if (np->n_type == PARM)
848 np = np->n_next;
851 np = exprreduce(np);
852 switch (np->n_type) {
856 if (np->n_flags & FREAL)
857 return (np->n_real);
858 if (np->n_flags & FINT)
859 return ((REAL)np->n_int);
860 return ((REAL)wcstod((wchar_t *)np->n_string, (wchar_t **)0));
873 exprstring(NODE *np)
875 if (isleaf(np->n_flags)) {
876 if (np->n_type == PARM)
877 np = np->n_next;
880 np = exprreduce(np);
881 switch (np->n_type) {
885 if (isstring(np->n_flags))
886 return (np->n_string);
887 if (np->n_flags & FINT)
888 return (STRING)lltoa((long long)np->n_int);
893 (double)np->n_real);
948 exprconcat(NODE *np, int len)
950 /* we KNOW (np->n_type==CONCAT) */
951 register NODE *lnp = np->n_left;
952 register NODE *rnp = np->n_right;
999 exprreduce(NODE *np)
1013 if ((t = np->n_type) == VAR || t == CONSTANT)
1014 return (np);
1021 if ((np = np->n_next)->n_type == ARRAY)
1022 awkerr(badarray, np->n_name);
1024 return (np);
1028 curnode = np;
1031 return (userfunc(np));
1034 return (rfield(exprint(np->n_left)));
1039 temp = np->n_type;
1040 tnp = np->n_left;
1041 np = np->n_right;
1071 if (np == NNULL || np->n_type == COMMA)
1074 np = vlook(exprstring(np));
1075 return (np);
1077 cp = makeindex(np, aname, tag);
1079 np = vlook(cp);
1080 if (!(np->n_flags & FINARRAY)) {
1081 np->n_alink = tnp->n_alink;
1082 tnp->n_alink = np;
1083 np->n_flags |= FINARRAY;
1086 np = vlookup(cp, 1) == NNULL ? const0 : const1;
1089 return (np);
1093 np = exprconcat(np, 0);
1095 return (np);
1098 return (intnode(exprtest(np->n_left) == 0 ? (INT)1 : (INT)0));
1101 return ((exprtest(np->n_left) != 0 &&
1102 exprtest(np->n_right) != 0) ? const1 : const0);
1105 return ((exprtest(np->n_left) != 0 ||
1106 exprtest(np->n_right) != 0) ? const1 : const0);
1118 f1 = (double)exprreal(np->n_left);
1119 f2 = (double)exprreal(np->n_right);
1124 if (np->n_right->n_type != COLON)
1126 if (exprtest(np->n_left))
1127 np = np->n_right->n_left; else
1128 np = np->n_right->n_right;
1129 return (exprreduce(np));
1137 return (comparison(np));
1144 return (arithmetic(np));
1152 if ((np = np->n_left)->n_type == INDEX)
1153 np = exprreduce(np);
1154 if (np->n_flags & FREAL)
1155 tnp = realnode(np->n_real);
1157 tnp = intnode(exprint(np));
1158 inc_oper->n_left = np;
1159 (void) assign(np, inc_oper);
1168 if ((np = np->n_left)->n_type == INDEX)
1169 np = exprreduce(np);
1170 inc_oper->n_left = np;
1171 return (assign(np, inc_oper));
1191 asn_oper->n_right = np->n_right;
1192 if ((np = np->n_left)->n_type == INDEX)
1193 np = exprreduce(np);
1194 asn_oper->n_left = np;
1195 return (assign(np, asn_oper));
1199 return (f_getline(np));
1202 return ((*np->n_left->n_function)(np->n_right));
1205 if (regmatch(np->n_regexp, linebuf) == REG_OK)
1210 cp = exprstring(np->n_left);
1211 if (regmatch(getregexp(np->n_right), cp) == REG_OK)
1216 cp = exprstring(np->n_left);
1217 if (regmatch(getregexp(np->n_right), cp) != REG_OK)
1222 return (assign(np->n_left, np->n_right));
1225 awkerr(badarray, np->n_name);
1229 awkerr(varnotfunc, np->n_name);
1243 arithmetic(NODE *np)
1251 left = exprreduce(np->n_left);
1256 r2 = exprreal(np->n_right);
1259 right = exprreduce(np->n_right);
1272 switch (np->n_type) {
1340 comparison(NODE *np)
1348 left = np->n_left;
1355 right = np->n_right;
1428 switch (np->n_type) {
1460 type_of(NODE *np)
1469 cp = (wchar_t *)np->n_string;
1588 lfield(INT fieldno, NODE *np)
1598 newlen = wcslen(newval = (wchar_t *)exprstring(np));
1663 return (np);
1674 userfunc(NODE *np)
1679 if ((fnp = np->n_left) == NNULL)
1701 actlist = np->n_right;
1797 np = retval; else
1798 np = const0;
1816 return (np);
1823 getregexp(NODE *np)
1825 if (np->n_type == RE)
1826 return (np->n_regexp);
1827 np = renode((wchar_t *)exprstring(np));
1828 return (np->n_regexp);
1837 register NODE *np;
1839 if ((np = *npp) == NNULL)
1840 return (np);
1841 if (np->n_type == COMMA) {
1842 *npp = np->n_right;
1843 return (np->n_left);
1846 return (np);
1854 s_if(NODE *np)
1859 test = exprtest(np->n_left);
1860 xp = np->n_right;
1874 s_while(NODE *np)
1878 if (np->n_type == DO)
1881 if (exprtest(np->n_left) == 0)
1884 if ((act = action(np->n_right)) != 0) {
1904 s_for(NODE *np)
1910 listp = np->n_left;
1919 if ((act = action(np->n_right)) != 0) {
1942 s_forin(NODE *np)
1954 left = np->n_left;
1955 statement = np->n_right;
1960 np = left->n_right;
1961 if (np->n_type == PARM) {
1962 np = np->n_next;
1963 if (!(np->n_flags & FLARRAY))
1964 np = np->n_alink;
1966 if (np == varSYMTAB) {
1968 np = NNULL;
1977 if (np->n_type != ARRAY) {
1978 if (!isstring(np->n_flags) || np->n_string != _null)
1979 awkerr(notarray, np->n_name);
1982 promote(np);
1983 if (np->n_alink != NNULL)
1984 if (!(np->n_flags & FLARRAY))
1985 np = np->n_alink;
1997 if ((*(nnp = next_forin) = np->n_alink) == 0)
2017 if ((left = symwalk(&nbuck, &np)) == NNULL)
2021 if ((np = *nnp) == NNULL)
2023 index = np->n_name+alen;
2024 *nnp = np->n_alink;
2050 register NODE *np;
2052 np = *npp;
2054 while (np == NNULL) {
2057 np = symtab[(*buckp)++];
2059 if (np->n_type == VAR &&
2060 (!isstring(np->n_flags) || np->n_string != _null)) {
2061 *npp = np->n_next;
2062 return (np);
2064 np = np->n_next;
2073 exprtest(NODE *np)
2077 if (np == NNULL)
2081 np = exprreduce(np);
2082 if (isint(t = np->n_flags)) {
2084 return (exprint(np) != 0);
2085 return (np->n_int != 0);
2090 rval = isstring(t) ? exprreal(np) : np->n_real;
2093 return (*(wchar_t *)exprstring(np) != '\0');
2099 * The node (np) is the list of indices and 'array' is the array name.
2102 makeindex(NODE *np, wchar_t *array, int tag)
2124 if (np->n_type != COMMA) {
2128 if (isleaf(np->n_flags) && np->n_type == PARM)
2129 np = np->n_next;
2130 if (isstring(np->n_flags)) {
2131 indstr = np->n_string;
2132 len = np->n_strlen;
2134 indstr = exprstring(np);
2156 while ((index = getlist(&np)) != NNULL) {