10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1717Swesolows * Common Development and Distribution License (the "License"). 6*1717Swesolows * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1717Swesolows 220Sstevel@tonic-gate /* 231414Scindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate * 260Sstevel@tonic-gate * eval.c -- constraint evaluation module 270Sstevel@tonic-gate * 280Sstevel@tonic-gate * this module evaluates constraints. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <stdio.h> 340Sstevel@tonic-gate #include <stdlib.h> 350Sstevel@tonic-gate #include <ctype.h> 360Sstevel@tonic-gate #include <string.h> 370Sstevel@tonic-gate #include "alloc.h" 380Sstevel@tonic-gate #include "out.h" 390Sstevel@tonic-gate #include "stable.h" 400Sstevel@tonic-gate #include "literals.h" 410Sstevel@tonic-gate #include "lut.h" 420Sstevel@tonic-gate #include "tree.h" 430Sstevel@tonic-gate #include "ptree.h" 440Sstevel@tonic-gate #include "itree.h" 451414Scindi #include "ipath.h" 460Sstevel@tonic-gate #include "eval.h" 470Sstevel@tonic-gate #include "config.h" 480Sstevel@tonic-gate #include "platform.h" 491414Scindi #include "fme.h" 501414Scindi #include "stats.h" 510Sstevel@tonic-gate 520Sstevel@tonic-gate static struct node *eval_dup(struct node *np, struct lut *ex, 531414Scindi struct node *epnames[]); 541414Scindi static int check_expr_args(struct evalue *lp, struct evalue *rp, 551414Scindi enum datatype dtype, struct node *np); 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * begins_with -- return true if rhs path begins with everything in lhs path 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate static int 610Sstevel@tonic-gate begins_with(struct node *lhs, struct node *rhs) 620Sstevel@tonic-gate { 630Sstevel@tonic-gate int lnum; 640Sstevel@tonic-gate int rnum; 650Sstevel@tonic-gate 660Sstevel@tonic-gate if (lhs == NULL) 670Sstevel@tonic-gate return (1); /* yep -- it all matched */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate if (rhs == NULL) 700Sstevel@tonic-gate return (0); /* nope, ran out of rhs first */ 710Sstevel@tonic-gate 720Sstevel@tonic-gate ASSERTeq(lhs->t, T_NAME, ptree_nodetype2str); 730Sstevel@tonic-gate ASSERTeq(rhs->t, T_NAME, ptree_nodetype2str); 740Sstevel@tonic-gate 750Sstevel@tonic-gate if (lhs->u.name.s != rhs->u.name.s) 760Sstevel@tonic-gate return (0); /* nope, different component names */ 770Sstevel@tonic-gate 780Sstevel@tonic-gate if (lhs->u.name.child && lhs->u.name.child->t == T_NUM) 790Sstevel@tonic-gate lnum = (int)lhs->u.name.child->u.ull; 800Sstevel@tonic-gate else 810Sstevel@tonic-gate out(O_DIE, "begins_with: unexpected lhs child"); 820Sstevel@tonic-gate 830Sstevel@tonic-gate if (rhs->u.name.child && rhs->u.name.child->t == T_NUM) 840Sstevel@tonic-gate rnum = (int)rhs->u.name.child->u.ull; 850Sstevel@tonic-gate else 860Sstevel@tonic-gate out(O_DIE, "begins_with: unexpected rhs child"); 870Sstevel@tonic-gate 880Sstevel@tonic-gate if (lnum != rnum) 890Sstevel@tonic-gate return (0); /* nope, instance numbers were different */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate return (begins_with(lhs->u.name.next, rhs->u.name.next)); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate 940Sstevel@tonic-gate /* 950Sstevel@tonic-gate * evaluate a variety of functions and place result in valuep. return 1 if 960Sstevel@tonic-gate * function evaluation was successful; 0 if otherwise (e.g., the case of an 970Sstevel@tonic-gate * invalid argument to the function) 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate /*ARGSUSED*/ 1000Sstevel@tonic-gate static int 1010Sstevel@tonic-gate eval_func(struct node *funcnp, struct lut *ex, struct node *epnames[], 1020Sstevel@tonic-gate struct node *np, struct lut **globals, 1030Sstevel@tonic-gate struct config *croot, struct arrow *arrowp, int try, struct evalue *valuep) 1040Sstevel@tonic-gate { 1050Sstevel@tonic-gate const char *funcname = funcnp->u.func.s; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate if (funcname == L_within) { 1080Sstevel@tonic-gate /* within()'s are not really constraints -- always true */ 1090Sstevel@tonic-gate valuep->t = UINT64; 1100Sstevel@tonic-gate valuep->v = 1; 1110Sstevel@tonic-gate return (1); 1120Sstevel@tonic-gate } else if (funcname == L_is_under) { 1130Sstevel@tonic-gate struct node *lhs; 1140Sstevel@tonic-gate struct node *rhs; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate if (np->u.expr.left->t == T_NAME) 1170Sstevel@tonic-gate lhs = np->u.expr.left; 1180Sstevel@tonic-gate else if (np->u.expr.left->u.func.s == L_fru) 1190Sstevel@tonic-gate lhs = eval_fru(np->u.expr.left->u.func.arglist); 1200Sstevel@tonic-gate else if (np->u.expr.left->u.func.s == L_asru) 1210Sstevel@tonic-gate lhs = eval_asru(np->u.expr.left->u.func.arglist); 1220Sstevel@tonic-gate else 1230Sstevel@tonic-gate out(O_DIE, "is_under: unexpected lhs type: %s", 1240Sstevel@tonic-gate ptree_nodetype2str(np->u.expr.left->t)); 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate if (np->u.expr.right->t == T_NAME) 1270Sstevel@tonic-gate rhs = np->u.expr.right; 1280Sstevel@tonic-gate else if (np->u.expr.right->u.func.s == L_fru) 1290Sstevel@tonic-gate rhs = eval_fru(np->u.expr.right->u.func.arglist); 1300Sstevel@tonic-gate else if (np->u.expr.right->u.func.s == L_asru) 1310Sstevel@tonic-gate rhs = eval_asru(np->u.expr.right->u.func.arglist); 1320Sstevel@tonic-gate else 1330Sstevel@tonic-gate out(O_DIE, "is_under: unexpected rhs type: %s", 1340Sstevel@tonic-gate ptree_nodetype2str(np->u.expr.right->t)); 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* eval_dup will expand wildcards, iterators, etc... */ 1370Sstevel@tonic-gate lhs = eval_dup(lhs, ex, epnames); 1380Sstevel@tonic-gate rhs = eval_dup(rhs, ex, epnames); 1390Sstevel@tonic-gate valuep->t = UINT64; 1400Sstevel@tonic-gate valuep->v = begins_with(lhs, rhs); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate out(O_ALTFP|O_VERB2|O_NONL, "eval_func:is_under("); 1430Sstevel@tonic-gate ptree_name_iter(O_ALTFP|O_VERB2|O_NONL, lhs); 1440Sstevel@tonic-gate out(O_ALTFP|O_VERB2|O_NONL, ","); 1450Sstevel@tonic-gate ptree_name_iter(O_ALTFP|O_VERB2|O_NONL, rhs); 1460Sstevel@tonic-gate out(O_ALTFP|O_VERB2, ") returned %d", (int)valuep->v); 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate tree_free(lhs); 1490Sstevel@tonic-gate tree_free(rhs); 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate return (1); 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate if (try) 1550Sstevel@tonic-gate return (0); 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate if (funcname == L_fru) { 1580Sstevel@tonic-gate valuep->t = NODEPTR; 159*1717Swesolows valuep->v = (uintptr_t)eval_fru(np); 1600Sstevel@tonic-gate return (1); 1610Sstevel@tonic-gate } else if (funcname == L_asru) { 1620Sstevel@tonic-gate valuep->t = NODEPTR; 163*1717Swesolows valuep->v = (uintptr_t)eval_asru(np); 1640Sstevel@tonic-gate return (1); 1651414Scindi } else if (funcname == L_defined) { 1661414Scindi ASSERTeq(np->t, T_GLOBID, ptree_nodetype2str); 1671414Scindi valuep->t = UINT64; 1681414Scindi valuep->v = (lut_lookup(*globals, 1691414Scindi (void *)np->u.globid.s, NULL) != NULL); 1701414Scindi return (1); 1710Sstevel@tonic-gate } else if (funcname == L_call) { 1720Sstevel@tonic-gate return (! platform_call(np, globals, croot, arrowp, valuep)); 1730Sstevel@tonic-gate } else if (funcname == L_is_connected) { 1740Sstevel@tonic-gate return (! config_is_connected(np, croot, valuep)); 1750Sstevel@tonic-gate } else if (funcname == L_is_on) { 1760Sstevel@tonic-gate return (! config_is_on(np, croot, valuep)); 1770Sstevel@tonic-gate } else if (funcname == L_is_present) { 1780Sstevel@tonic-gate return (! config_is_present(np, croot, valuep)); 1790Sstevel@tonic-gate } else if (funcname == L_is_type) { 1800Sstevel@tonic-gate return (! config_is_type(np, croot, valuep)); 1810Sstevel@tonic-gate } else if (funcname == L_confprop) { 1820Sstevel@tonic-gate return (! config_confprop(np, croot, valuep)); 1830Sstevel@tonic-gate } else if (funcname == L_envprop) { 1840Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 1850Sstevel@tonic-gate "eval_func: %s not yet supported", funcname); 1860Sstevel@tonic-gate } else if (funcname == L_payloadprop) { 1871414Scindi outfl(O_ALTFP|O_VERB2|O_NONL, np->file, np->line, 1880Sstevel@tonic-gate "payloadprop(\"%s\") ", np->u.quote.s); 189186Sdb35262 1901414Scindi if (platform_payloadprop(np, valuep)) { 1911414Scindi /* platform_payloadprop() returned false */ 1921414Scindi out(O_ALTFP|O_VERB2, "not found."); 1931414Scindi return (0); 1941414Scindi } else { 195186Sdb35262 switch (valuep->t) { 196186Sdb35262 case UINT64: 197186Sdb35262 case NODEPTR: 1981414Scindi out(O_ALTFP|O_VERB2, "found: %llu", valuep->v); 199186Sdb35262 break; 200186Sdb35262 case STRING: 2011414Scindi out(O_ALTFP|O_VERB2, "found: \"%s\"", 202*1717Swesolows (char *)(uintptr_t)valuep->v); 203186Sdb35262 break; 204186Sdb35262 default: 2051414Scindi out(O_ALTFP|O_VERB2, "found: undefined"); 206186Sdb35262 break; 207186Sdb35262 } 2081414Scindi return (1); 2091414Scindi } 2101414Scindi } else if (funcname == L_setpayloadprop) { 2111414Scindi struct evalue *payloadvalp; 2121414Scindi 2131414Scindi ASSERTinfo(np->t == T_LIST, ptree_nodetype2str(np->t)); 2141414Scindi ASSERTinfo(np->u.expr.left->t == T_QUOTE, 2151414Scindi ptree_nodetype2str(np->u.expr.left->t)); 2161414Scindi 2171414Scindi outfl(O_ALTFP|O_VERB2|O_NONL, np->file, np->line, 2181414Scindi "setpayloadprop: %s: %s=", 2191414Scindi arrowp->tail->myevent->enode->u.event.ename->u.name.s, 2201414Scindi np->u.expr.left->u.quote.s); 2211414Scindi ptree_name_iter(O_ALTFP|O_VERB2|O_NONL, np->u.expr.right); 2221414Scindi 2231414Scindi /* 2241414Scindi * allocate a struct evalue to hold the payload property's 2251414Scindi * value, unless we've been here already, in which case we 2261414Scindi * might calculate a different value, but we'll store it 2271414Scindi * in the already-allocated struct evalue. 2281414Scindi */ 2291414Scindi if ((payloadvalp = (struct evalue *)lut_lookup( 2301414Scindi arrowp->tail->myevent->payloadprops, 2311414Scindi (void *)np->u.expr.left->u.quote.s, NULL)) == NULL) { 2321414Scindi payloadvalp = MALLOC(sizeof (*payloadvalp)); 2331414Scindi } 2341414Scindi 2351414Scindi if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 2361414Scindi arrowp, try, payloadvalp)) { 2371414Scindi out(O_ALTFP|O_VERB2, " (cannot eval, using zero)"); 2381414Scindi payloadvalp->t = UINT64; 2391414Scindi payloadvalp->v = 0; 2401414Scindi } else { 2411414Scindi if (payloadvalp->t == UINT64) 2421414Scindi out(O_ALTFP|O_VERB2, 2431414Scindi " (%llu)", payloadvalp->v); 2441414Scindi else 245*1717Swesolows out(O_ALTFP|O_VERB2, " (\"%s\")", 246*1717Swesolows (char *)(uintptr_t)payloadvalp->v); 2471414Scindi } 2481414Scindi 2491414Scindi /* add to table of payload properties for current problem */ 2501414Scindi arrowp->tail->myevent->payloadprops = 2511414Scindi lut_add(arrowp->tail->myevent->payloadprops, 2521414Scindi (void *)np->u.expr.left->u.quote.s, 2531414Scindi (void *)payloadvalp, NULL); 2541414Scindi 2551414Scindi /* function is always true */ 2561414Scindi valuep->t = UINT64; 2571414Scindi valuep->v = 1; 2581414Scindi return (1); 2591414Scindi } else if (funcname == L_payloadprop_defined) { 2601414Scindi outfl(O_ALTFP|O_VERB2|O_NONL, np->file, np->line, 2611414Scindi "payloadprop_defined(\"%s\") ", np->u.quote.s); 2621414Scindi 2631414Scindi if (platform_payloadprop(np, NULL)) { 2641414Scindi /* platform_payloadprop() returned false */ 2651414Scindi valuep->v = 0; 2661414Scindi out(O_ALTFP|O_VERB2, "not found."); 2671414Scindi } else { 2681414Scindi valuep->v = 1; 2691414Scindi out(O_ALTFP|O_VERB2, "found."); 2701414Scindi } 2711414Scindi valuep->t = UINT64; 2721414Scindi return (1); 2731414Scindi } else if (funcname == L_payloadprop_contains) { 2741414Scindi int nvals; 2751414Scindi struct evalue *vals; 2761414Scindi struct evalue cmpval; 2771414Scindi 2781414Scindi ASSERTinfo(np->t == T_LIST, ptree_nodetype2str(np->t)); 2791414Scindi ASSERTinfo(np->u.expr.left->t == T_QUOTE, 2801414Scindi ptree_nodetype2str(np->u.expr.left->t)); 2811414Scindi 2821414Scindi outfl(O_ALTFP|O_VERB2|O_NONL, np->file, np->line, 2831414Scindi "payloadprop_contains(\"%s\", ", 2841414Scindi np->u.expr.left->u.quote.s); 2851414Scindi ptree_name_iter(O_ALTFP|O_VERB2|O_NONL, np->u.expr.right); 2861414Scindi outfl(O_ALTFP|O_VERB2|O_NONL, np->file, np->line, ") "); 2871414Scindi 2881414Scindi /* evaluate the expression we're comparing against */ 2891414Scindi if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 2901414Scindi arrowp, try, &cmpval)) { 2911414Scindi out(O_ALTFP|O_VERB2|O_NONL, 2921414Scindi "(cannot eval, using zero) "); 2931414Scindi cmpval.t = UINT64; 2941414Scindi cmpval.v = 0; 2951414Scindi } else { 2961414Scindi if (cmpval.t == UINT64) 2971414Scindi out(O_ALTFP|O_VERB2, 2981414Scindi "(%llu) ", cmpval.v); 2991414Scindi else 3001414Scindi out(O_ALTFP|O_VERB2, 301*1717Swesolows "(\"%s\") ", (char *)(uintptr_t)cmpval.v); 3021414Scindi } 3031414Scindi 3041414Scindi /* get the payload values and check for a match */ 3051414Scindi vals = platform_payloadprop_values(np->u.expr.left->u.quote.s, 3061414Scindi &nvals); 3071414Scindi valuep->t = UINT64; 3081414Scindi valuep->v = 0; 3091414Scindi if (nvals == 0) { 3101414Scindi out(O_ALTFP|O_VERB2, "not found."); 3111414Scindi } else { 3121414Scindi struct evalue preval; 3131414Scindi int i; 3141414Scindi 3151414Scindi out(O_ALTFP|O_VERB2|O_NONL, "found %d values ", nvals); 3161414Scindi 3171414Scindi for (i = 0; i < nvals; i++) { 3181414Scindi 3191414Scindi preval.t = vals[i].t; 3201414Scindi preval.v = vals[i].v; 3211414Scindi 3221414Scindi if (check_expr_args(&vals[i], &cmpval, 3231414Scindi UNDEFINED, np)) 3241414Scindi continue; 3251414Scindi 3261414Scindi /* 3271414Scindi * If we auto-converted the value to a 3281414Scindi * string, we need to free the 3291414Scindi * original tree value. 3301414Scindi */ 3311414Scindi if (preval.t == NODEPTR && 332*1717Swesolows ((struct node *)(uintptr_t)(preval.v))->t == 333*1717Swesolows T_NAME) { 334*1717Swesolows tree_free((struct node *)(uintptr_t) 335*1717Swesolows preval.v); 3361414Scindi } 3371414Scindi 3381414Scindi if (vals[i].v == cmpval.v) { 3391414Scindi valuep->v = 1; 3401414Scindi break; 3411414Scindi } 3421414Scindi } 343186Sdb35262 3441414Scindi if (valuep->v) 3451414Scindi out(O_ALTFP|O_VERB2, "match."); 3461414Scindi else 3471414Scindi out(O_ALTFP|O_VERB2, "no match."); 348186Sdb35262 3491414Scindi for (i = 0; i < nvals; i++) { 3501414Scindi if (vals[i].t == NODEPTR) { 351*1717Swesolows tree_free((struct node *)(uintptr_t) 352*1717Swesolows vals[i].v); 3531414Scindi break; 3541414Scindi } 355186Sdb35262 } 3561414Scindi FREE(vals); 3571414Scindi } 3581414Scindi return (1); 3591414Scindi } else if (funcname == L_confcall) { 3601414Scindi return (!platform_confcall(np, globals, croot, arrowp, valuep)); 3611414Scindi } else if (funcname == L_count) { 3621414Scindi struct stats *statp; 3631423Sgavinm struct istat_entry ent; 364186Sdb35262 3651414Scindi ASSERTinfo(np->t == T_EVENT, ptree_nodetype2str(np->t)); 3661414Scindi 3671423Sgavinm ent.ename = np->u.event.ename->u.name.s; 3681423Sgavinm ent.ipath = ipath(np->u.event.epname); 3691423Sgavinm 3701414Scindi valuep->t = UINT64; 3711414Scindi if ((statp = (struct stats *) 3721423Sgavinm lut_lookup(Istats, &ent, (lut_cmp)istat_cmp)) == NULL) 3731414Scindi valuep->v = 0; 3741414Scindi else 3751414Scindi valuep->v = stats_counter_value(statp); 3761414Scindi 3771414Scindi return (1); 3780Sstevel@tonic-gate } else 3790Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 3800Sstevel@tonic-gate "eval_func: unexpected func: %s", funcname); 3810Sstevel@tonic-gate /*NOTREACHED*/ 382*1717Swesolows return (0); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate static struct node * 3860Sstevel@tonic-gate eval_wildcardedname(struct node *np, struct lut *ex, struct node *epnames[]) 3870Sstevel@tonic-gate { 3880Sstevel@tonic-gate struct node *npstart, *npend, *npref, *newnp; 3890Sstevel@tonic-gate struct node *np1, *np2, *retp; 3900Sstevel@tonic-gate int i; 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate if (epnames == NULL || epnames[0] == NULL) 3930Sstevel@tonic-gate return (NULL); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate for (i = 0; epnames[i] != NULL; i++) { 3960Sstevel@tonic-gate if (tree_namecmp(np, epnames[i]) == 0) 3970Sstevel@tonic-gate return (NULL); 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate /* 4010Sstevel@tonic-gate * get to this point if np does not match any of the entries in 4020Sstevel@tonic-gate * epnames. check if np is a path that must preceded by a wildcard 4030Sstevel@tonic-gate * portion. for this case we must first determine which epnames[] 4040Sstevel@tonic-gate * entry should be used for wildcarding. 4050Sstevel@tonic-gate */ 4060Sstevel@tonic-gate npstart = NULL; 4070Sstevel@tonic-gate for (i = 0; epnames[i] != NULL; i++) { 4080Sstevel@tonic-gate for (npref = epnames[i]; npref; npref = npref->u.name.next) { 4090Sstevel@tonic-gate if (npref->u.name.s == np->u.name.s) { 4100Sstevel@tonic-gate for (np1 = npref, np2 = np; 4110Sstevel@tonic-gate np1 != NULL && np2 != NULL; 4120Sstevel@tonic-gate np1 = np1->u.name.next, 4130Sstevel@tonic-gate np2 = np2->u.name.next) { 4140Sstevel@tonic-gate if (np1->u.name.s != np2->u.name.s) 4150Sstevel@tonic-gate break; 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate if (np2 == NULL) { 4180Sstevel@tonic-gate npstart = epnames[i]; 4190Sstevel@tonic-gate npend = npref; 4200Sstevel@tonic-gate if (np1 == NULL) 4210Sstevel@tonic-gate break; 4220Sstevel@tonic-gate } 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate if (npstart != NULL) 4270Sstevel@tonic-gate break; 4280Sstevel@tonic-gate } 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate if (npstart == NULL) { 4310Sstevel@tonic-gate /* no match; np is not a path to be wildcarded */ 4320Sstevel@tonic-gate return (NULL); 4330Sstevel@tonic-gate } 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate /* 4360Sstevel@tonic-gate * dup (npstart -- npend) which is the wildcarded portion. all 4370Sstevel@tonic-gate * children should be T_NUMs. 4380Sstevel@tonic-gate */ 4390Sstevel@tonic-gate retp = NULL; 4400Sstevel@tonic-gate for (npref = npstart; 4410Sstevel@tonic-gate ! (npref == NULL || npref == npend); 4420Sstevel@tonic-gate npref = npref->u.name.next) { 4430Sstevel@tonic-gate newnp = newnode(T_NAME, np->file, np->line); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate newnp->u.name.t = npref->u.name.t; 4460Sstevel@tonic-gate newnp->u.name.s = npref->u.name.s; 4470Sstevel@tonic-gate newnp->u.name.last = newnp; 4480Sstevel@tonic-gate newnp->u.name.it = npref->u.name.it; 4490Sstevel@tonic-gate newnp->u.name.cp = npref->u.name.cp; 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate ASSERT(npref->u.name.child != NULL); 4520Sstevel@tonic-gate ASSERT(npref->u.name.child->t == T_NUM); 4530Sstevel@tonic-gate newnp->u.name.child = newnode(T_NUM, np->file, np->line); 4540Sstevel@tonic-gate newnp->u.name.child->u.ull = npref->u.name.child->u.ull; 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate if (retp == NULL) { 4570Sstevel@tonic-gate retp = newnp; 4580Sstevel@tonic-gate } else { 4590Sstevel@tonic-gate retp->u.name.last->u.name.next = newnp; 4600Sstevel@tonic-gate retp->u.name.last = newnp; 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate ASSERT(retp != NULL); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* now append the nonwildcarded portion */ 4670Sstevel@tonic-gate retp = tree_name_append(retp, eval_dup(np, ex, NULL)); 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate return (retp); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate static struct node * 4730Sstevel@tonic-gate eval_dup(struct node *np, struct lut *ex, struct node *epnames[]) 4740Sstevel@tonic-gate { 4750Sstevel@tonic-gate struct node *newnp; 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate if (np == NULL) 4780Sstevel@tonic-gate return (NULL); 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate switch (np->t) { 4810Sstevel@tonic-gate case T_GLOBID: 4820Sstevel@tonic-gate return (tree_globid(np->u.globid.s, np->file, np->line)); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate case T_ASSIGN: 4850Sstevel@tonic-gate case T_CONDIF: 4860Sstevel@tonic-gate case T_CONDELSE: 4870Sstevel@tonic-gate case T_NE: 4880Sstevel@tonic-gate case T_EQ: 4890Sstevel@tonic-gate case T_LT: 4900Sstevel@tonic-gate case T_LE: 4910Sstevel@tonic-gate case T_GT: 4920Sstevel@tonic-gate case T_GE: 4930Sstevel@tonic-gate case T_BITAND: 4940Sstevel@tonic-gate case T_BITOR: 4950Sstevel@tonic-gate case T_BITXOR: 4960Sstevel@tonic-gate case T_BITNOT: 4970Sstevel@tonic-gate case T_LSHIFT: 4980Sstevel@tonic-gate case T_RSHIFT: 4990Sstevel@tonic-gate case T_LIST: 5000Sstevel@tonic-gate case T_AND: 5010Sstevel@tonic-gate case T_OR: 5020Sstevel@tonic-gate case T_NOT: 5030Sstevel@tonic-gate case T_ADD: 5040Sstevel@tonic-gate case T_SUB: 5050Sstevel@tonic-gate case T_MUL: 5060Sstevel@tonic-gate case T_DIV: 5070Sstevel@tonic-gate case T_MOD: 5080Sstevel@tonic-gate return (tree_expr(np->t, 5090Sstevel@tonic-gate eval_dup(np->u.expr.left, ex, epnames), 5100Sstevel@tonic-gate eval_dup(np->u.expr.right, ex, epnames))); 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate case T_NAME: { 5130Sstevel@tonic-gate struct iterinfo *iterinfop; 5140Sstevel@tonic-gate struct node *newchild = NULL; 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate iterinfop = lut_lookup(ex, (void *)np->u.name.s, NULL); 5170Sstevel@tonic-gate if (iterinfop != NULL) { 5180Sstevel@tonic-gate /* explicit iterator; not part of pathname */ 5190Sstevel@tonic-gate newnp = newnode(T_NUM, np->file, np->line); 5200Sstevel@tonic-gate newnp->u.ull = iterinfop->num; 5210Sstevel@tonic-gate return (newnp); 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate /* see if np is a path with wildcard portion */ 5250Sstevel@tonic-gate newnp = eval_wildcardedname(np, ex, epnames); 5260Sstevel@tonic-gate if (newnp != NULL) 5270Sstevel@tonic-gate return (newnp); 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* turn off wildcarding for child */ 5300Sstevel@tonic-gate newchild = eval_dup(np->u.name.child, ex, NULL); 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate if (newchild != NULL) { 5330Sstevel@tonic-gate if (newchild->t != T_NUM) { 5340Sstevel@tonic-gate /* 5350Sstevel@tonic-gate * not a number, eh? we must resolve this 5360Sstevel@tonic-gate * to a number. 5370Sstevel@tonic-gate */ 5380Sstevel@tonic-gate struct evalue value; 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate if (eval_expr(newchild, ex, epnames, 5410Sstevel@tonic-gate NULL, NULL, NULL, 1, &value) == 0 || 5420Sstevel@tonic-gate value.t != UINT64) { 5430Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 5440Sstevel@tonic-gate "eval_dup: could not resolve " 5450Sstevel@tonic-gate "iterator of %s", np->u.name.s); 5460Sstevel@tonic-gate } 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate tree_free(newchild); 5490Sstevel@tonic-gate newchild = newnode(T_NUM, np->file, np->line); 5500Sstevel@tonic-gate newchild->u.ull = value.v; 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate newnp = newnode(np->t, np->file, np->line); 5540Sstevel@tonic-gate newnp->u.name.s = np->u.name.s; 5550Sstevel@tonic-gate newnp->u.name.it = np->u.name.it; 5560Sstevel@tonic-gate newnp->u.name.cp = np->u.name.cp; 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate newnp->u.name.last = newnp; 5590Sstevel@tonic-gate newnp->u.name.child = newchild; 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate if (np->u.name.next != NULL) { 5620Sstevel@tonic-gate /* turn off wildcarding for next */ 5630Sstevel@tonic-gate return (tree_name_append(newnp, 5640Sstevel@tonic-gate eval_dup(np->u.name.next, ex, NULL))); 5650Sstevel@tonic-gate } else { 5660Sstevel@tonic-gate return (newnp); 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate } else { 5690Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 5700Sstevel@tonic-gate "eval_dup: internal error: \"%s\" is neither " 5710Sstevel@tonic-gate "an iterator nor a pathname", np->u.name.s); 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate /*NOTREACHED*/ 5740Sstevel@tonic-gate break; 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5771414Scindi case T_EVENT: 5781414Scindi newnp = newnode(T_NAME, np->file, np->line); 5791414Scindi 5801414Scindi newnp->u.name.t = np->u.event.ename->u.name.t; 5811414Scindi newnp->u.name.s = np->u.event.ename->u.name.s; 5821414Scindi newnp->u.name.it = np->u.event.ename->u.name.it; 5831414Scindi newnp->u.name.last = newnp; 5841414Scindi 5851414Scindi return (tree_event(newnp, 5861414Scindi eval_dup(np->u.event.epname, ex, epnames), 5871414Scindi eval_dup(np->u.event.eexprlist, ex, epnames))); 5881414Scindi 5890Sstevel@tonic-gate case T_FUNC: 5900Sstevel@tonic-gate return (tree_func(np->u.func.s, 5910Sstevel@tonic-gate eval_dup(np->u.func.arglist, ex, epnames), 5920Sstevel@tonic-gate np->file, np->line)); 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate case T_QUOTE: 5950Sstevel@tonic-gate newnp = newnode(T_QUOTE, np->file, np->line); 5960Sstevel@tonic-gate newnp->u.quote.s = np->u.quote.s; 5970Sstevel@tonic-gate return (newnp); 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate case T_NUM: 6000Sstevel@tonic-gate newnp = newnode(T_NUM, np->file, np->line); 6010Sstevel@tonic-gate newnp->u.ull = np->u.ull; 6020Sstevel@tonic-gate return (newnp); 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate default: 6050Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 6060Sstevel@tonic-gate "eval_dup: unexpected node type: %s", 6070Sstevel@tonic-gate ptree_nodetype2str(np->t)); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate /*NOTREACHED*/ 610*1717Swesolows return (0); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate /* 6140Sstevel@tonic-gate * eval_potential -- see if constraint is potentially true 6150Sstevel@tonic-gate * 6160Sstevel@tonic-gate * this function is used at instance tree creation time to see if 6170Sstevel@tonic-gate * any constraints are already known to be false. if this function 6180Sstevel@tonic-gate * returns false, then the constraint will always be false and there's 6190Sstevel@tonic-gate * no need to include the propagation arrow in the instance tree. 6200Sstevel@tonic-gate * 6210Sstevel@tonic-gate * if this routine returns true, either the constraint is known to 6220Sstevel@tonic-gate * be always true (so there's no point in attaching the constraint 6230Sstevel@tonic-gate * to the propagation arrow in the instance tree), or the constraint 6240Sstevel@tonic-gate * contains "deferred" expressions like global variables or poller calls 6250Sstevel@tonic-gate * and so it must be evaluated during calls to fme_eval(). in this last 6260Sstevel@tonic-gate * case, where a constraint needs to be attached to the propagation arrow 6270Sstevel@tonic-gate * in the instance tree, this routine returns a newly created constraint 6280Sstevel@tonic-gate * in *newc where all the non-deferred things have been filled in. 6290Sstevel@tonic-gate * 6300Sstevel@tonic-gate * so in summary: 6310Sstevel@tonic-gate * 6320Sstevel@tonic-gate * return of false: constraint can never be true, *newc will be NULL. 6330Sstevel@tonic-gate * 6340Sstevel@tonic-gate * return of true with *newc unchanged: constraint will always be true. 6350Sstevel@tonic-gate * 6360Sstevel@tonic-gate * return of true with *newc changed: use new constraint in *newc. 6370Sstevel@tonic-gate * 6380Sstevel@tonic-gate * the lookup table for all explicit iterators, ex, is passed in. 6390Sstevel@tonic-gate * 6400Sstevel@tonic-gate * *newc can either be NULL on entry, or if can contain constraints from 6410Sstevel@tonic-gate * previous calls to eval_potential() (i.e. for building up an instance 6420Sstevel@tonic-gate * tree constraint from several potential constraints). if *newc already 6430Sstevel@tonic-gate * contains constraints, anything added to it will be joined by adding 6440Sstevel@tonic-gate * a T_AND node at the top of *newc. 6450Sstevel@tonic-gate */ 6460Sstevel@tonic-gate int 6470Sstevel@tonic-gate eval_potential(struct node *np, struct lut *ex, struct node *epnames[], 6480Sstevel@tonic-gate struct node **newc) 6490Sstevel@tonic-gate { 6500Sstevel@tonic-gate struct node *newnp; 6510Sstevel@tonic-gate struct evalue value; 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate if (eval_expr(np, ex, epnames, NULL, NULL, NULL, 1, &value) == 0) { 6540Sstevel@tonic-gate /* 6550Sstevel@tonic-gate * couldn't eval expression because 6560Sstevel@tonic-gate * it contains deferred items. make 6570Sstevel@tonic-gate * a duplicate expression with all the 6580Sstevel@tonic-gate * non-deferred items expanded. 6590Sstevel@tonic-gate */ 6600Sstevel@tonic-gate newnp = eval_dup(np, ex, epnames); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate if (*newc == NULL) { 6630Sstevel@tonic-gate /* 6640Sstevel@tonic-gate * constraint is potentially true if deferred 6650Sstevel@tonic-gate * expression in newnp is true. *newc was NULL 6660Sstevel@tonic-gate * so new constraint is just the one in newnp. 6670Sstevel@tonic-gate */ 6680Sstevel@tonic-gate *newc = newnp; 6690Sstevel@tonic-gate return (1); 6700Sstevel@tonic-gate } else { 6710Sstevel@tonic-gate /* 6720Sstevel@tonic-gate * constraint is potentially true if deferred 6730Sstevel@tonic-gate * expression in newnp is true. *newc already 6740Sstevel@tonic-gate * contained a constraint so add an AND with the 6750Sstevel@tonic-gate * constraint in newnp. 6760Sstevel@tonic-gate */ 6770Sstevel@tonic-gate *newc = tree_expr(T_AND, *newc, newnp); 6780Sstevel@tonic-gate return (1); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate } else if (value.t == UNDEFINED) { 6810Sstevel@tonic-gate /* constraint can never be true */ 6820Sstevel@tonic-gate return (0); 6830Sstevel@tonic-gate } else if (value.t == UINT64 && value.v == 0) { 6840Sstevel@tonic-gate /* constraint can never be true */ 6850Sstevel@tonic-gate return (0); 6860Sstevel@tonic-gate } else { 6870Sstevel@tonic-gate /* constraint is always true (nothing deferred to eval) */ 6880Sstevel@tonic-gate return (1); 6890Sstevel@tonic-gate } 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate static int 6930Sstevel@tonic-gate check_expr_args(struct evalue *lp, struct evalue *rp, enum datatype dtype, 6940Sstevel@tonic-gate struct node *np) 6950Sstevel@tonic-gate { 6961414Scindi /* auto-convert T_NAMES to strings */ 697*1717Swesolows if (lp->t == NODEPTR && ((struct node *)(uintptr_t)(lp->v))->t == 698*1717Swesolows T_NAME) { 699*1717Swesolows char *s = ipath2str(NULL, 700*1717Swesolows ipath((struct node *)(uintptr_t)lp->v)); 7011414Scindi lp->t = STRING; 702*1717Swesolows lp->v = (uintptr_t)stable(s); 7031414Scindi FREE(s); 7041414Scindi out(O_ALTFP|O_VERB2, "convert lhs path to \"%s\"", 705*1717Swesolows (char *)(uintptr_t)lp->v); 7061414Scindi } 7071414Scindi if (rp != NULL && 708*1717Swesolows rp->t == NODEPTR && ((struct node *)(uintptr_t)(rp->v))->t == 709*1717Swesolows T_NAME) { 710*1717Swesolows char *s = ipath2str(NULL, 711*1717Swesolows ipath((struct node *)(uintptr_t)rp->v)); 7121414Scindi rp->t = STRING; 713*1717Swesolows rp->v = (uintptr_t)stable(s); 7141414Scindi FREE(s); 7151414Scindi out(O_ALTFP|O_VERB2, "convert rhs path to \"%s\"", 716*1717Swesolows (char *)(uintptr_t)rp->v); 7171414Scindi } 7181414Scindi 7191414Scindi /* auto-convert strings to numbers */ 7201414Scindi if (dtype == UINT64) { 7211414Scindi if (lp->t == STRING) { 7221414Scindi lp->t = UINT64; 723*1717Swesolows lp->v = strtoull((char *)(uintptr_t)lp->v, NULL, 0); 7241414Scindi } 7251414Scindi if (rp != NULL && rp->t == STRING) { 7261414Scindi rp->t = UINT64; 727*1717Swesolows rp->v = strtoull((char *)(uintptr_t)rp->v, NULL, 0); 7281414Scindi } 7291414Scindi } 7301414Scindi 7310Sstevel@tonic-gate if (dtype != UNDEFINED && lp->t != dtype) { 7320Sstevel@tonic-gate outfl(O_OK, np->file, np->line, 7330Sstevel@tonic-gate "invalid datatype of argument for operation %s", 7340Sstevel@tonic-gate ptree_nodetype2str(np->t)); 7350Sstevel@tonic-gate return (1); 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate if (rp != NULL && lp->t != rp->t) { 7390Sstevel@tonic-gate outfl(O_OK, np->file, np->line, 7400Sstevel@tonic-gate "mismatch in datatype of arguments for operation %s", 7410Sstevel@tonic-gate ptree_nodetype2str(np->t)); 7420Sstevel@tonic-gate return (1); 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate return (0); 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate /* 7490Sstevel@tonic-gate * eval_expr -- evaluate expression into *valuep 7500Sstevel@tonic-gate * 7510Sstevel@tonic-gate * the meaning of the return value depends on the input value of try. 7520Sstevel@tonic-gate * 7530Sstevel@tonic-gate * for try == 1: if any deferred items are encounted, bail out and return 7540Sstevel@tonic-gate * false. returns true if we made it through entire expression without 7550Sstevel@tonic-gate * hitting any deferred items. 7560Sstevel@tonic-gate * 7570Sstevel@tonic-gate * for try == 0: return true if all operations were performed successfully. 7580Sstevel@tonic-gate * return false if otherwise. for example, any of the following conditions 7590Sstevel@tonic-gate * will result in a false return value: 7600Sstevel@tonic-gate * - attempted use of an uninitialized global variable 7610Sstevel@tonic-gate * - failure in function evaluation 7620Sstevel@tonic-gate * - illegal arithmetic operation (argument out of range) 7630Sstevel@tonic-gate */ 7640Sstevel@tonic-gate int 7650Sstevel@tonic-gate eval_expr(struct node *np, struct lut *ex, struct node *epnames[], 7660Sstevel@tonic-gate struct lut **globals, struct config *croot, struct arrow *arrowp, 7670Sstevel@tonic-gate int try, struct evalue *valuep) 7680Sstevel@tonic-gate { 7690Sstevel@tonic-gate struct evalue *gval; 7700Sstevel@tonic-gate struct evalue lval; 7710Sstevel@tonic-gate struct evalue rval; 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate if (np == NULL) { 7740Sstevel@tonic-gate valuep->t = UINT64; 7750Sstevel@tonic-gate valuep->v = 1; /* no constraint means "true" */ 7760Sstevel@tonic-gate return (1); 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate 7790Sstevel@tonic-gate valuep->t = UNDEFINED; 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate switch (np->t) { 7820Sstevel@tonic-gate case T_GLOBID: 7830Sstevel@tonic-gate if (try) 7840Sstevel@tonic-gate return (0); 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate /* 7870Sstevel@tonic-gate * only handle case of getting (and not setting) the value 7880Sstevel@tonic-gate * of a global variable 7890Sstevel@tonic-gate */ 7900Sstevel@tonic-gate gval = lut_lookup(*globals, (void *)np->u.globid.s, NULL); 7910Sstevel@tonic-gate if (gval == NULL) { 7920Sstevel@tonic-gate valuep->t = UNDEFINED; 7930Sstevel@tonic-gate return (0); 7940Sstevel@tonic-gate } else { 7950Sstevel@tonic-gate valuep->t = gval->t; 7960Sstevel@tonic-gate valuep->v = gval->v; 7970Sstevel@tonic-gate return (1); 7980Sstevel@tonic-gate } 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate case T_ASSIGN: 8010Sstevel@tonic-gate if (try) 8020Sstevel@tonic-gate return (0); 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate /* 8050Sstevel@tonic-gate * first evaluate rhs, then try to store value in lhs which 8060Sstevel@tonic-gate * should be a global variable 8070Sstevel@tonic-gate */ 8080Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 8090Sstevel@tonic-gate arrowp, try, &rval)) 8100Sstevel@tonic-gate return (0); 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate ASSERT(np->u.expr.left->t == T_GLOBID); 8130Sstevel@tonic-gate gval = lut_lookup(*globals, 8140Sstevel@tonic-gate (void *)np->u.expr.left->u.globid.s, NULL); 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate if (gval == NULL) { 8170Sstevel@tonic-gate gval = MALLOC(sizeof (*gval)); 8180Sstevel@tonic-gate *globals = lut_add(*globals, 8190Sstevel@tonic-gate (void *) np->u.expr.left->u.globid.s, 8200Sstevel@tonic-gate gval, NULL); 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate gval->t = rval.t; 8240Sstevel@tonic-gate gval->v = rval.v; 8251414Scindi 8261414Scindi if (gval->t == UINT64) { 8271414Scindi out(O_ALTFP|O_VERB2, 8281414Scindi "assign $%s=%llu", 8291414Scindi np->u.expr.left->u.globid.s, gval->v); 8301414Scindi } else { 8311414Scindi out(O_ALTFP|O_VERB2, 8321414Scindi "assign $%s=\"%s\"", 833*1717Swesolows np->u.expr.left->u.globid.s, 834*1717Swesolows (char *)(uintptr_t)gval->v); 8351414Scindi } 8361414Scindi 8371414Scindi /* 8381414Scindi * but always return true -- an assignment should not 8391414Scindi * cause a constraint to be false. 8401414Scindi */ 8411414Scindi valuep->t = UINT64; 8421414Scindi valuep->v = 1; 8430Sstevel@tonic-gate return (1); 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate case T_EQ: 8460Sstevel@tonic-gate #define IMPLICIT_ASSIGN_IN_EQ 8470Sstevel@tonic-gate #ifdef IMPLICIT_ASSIGN_IN_EQ 8480Sstevel@tonic-gate /* 8490Sstevel@tonic-gate * if lhs is an uninitialized global variable, perform 8500Sstevel@tonic-gate * an assignment. 8510Sstevel@tonic-gate * 8520Sstevel@tonic-gate * one insidious side effect of implicit assignment is 8530Sstevel@tonic-gate * that the "==" operator does not return a Boolean if 8540Sstevel@tonic-gate * implicit assignment was performed. 8550Sstevel@tonic-gate */ 8560Sstevel@tonic-gate if (try == 0 && 8570Sstevel@tonic-gate np->u.expr.left->t == T_GLOBID && 8580Sstevel@tonic-gate (gval = lut_lookup(*globals, 8590Sstevel@tonic-gate (void *)np->u.expr.left->u.globid.s, NULL)) == NULL) { 8600Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, 8610Sstevel@tonic-gate croot, arrowp, try, &rval)) 8620Sstevel@tonic-gate return (0); 8630Sstevel@tonic-gate 8640Sstevel@tonic-gate gval = MALLOC(sizeof (*gval)); 8650Sstevel@tonic-gate *globals = lut_add(*globals, 8660Sstevel@tonic-gate (void *) np->u.expr.left->u.globid.s, 8670Sstevel@tonic-gate gval, NULL); 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate gval->t = rval.t; 8700Sstevel@tonic-gate gval->v = rval.v; 8710Sstevel@tonic-gate valuep->t = rval.t; 8720Sstevel@tonic-gate valuep->v = rval.v; 8730Sstevel@tonic-gate return (1); 8740Sstevel@tonic-gate } 8750Sstevel@tonic-gate #endif /* IMPLICIT_ASSIGN_IN_EQ */ 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 8780Sstevel@tonic-gate arrowp, try, &lval)) 8790Sstevel@tonic-gate return (0); 8800Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 8810Sstevel@tonic-gate arrowp, try, &rval)) 8820Sstevel@tonic-gate return (0); 8830Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UNDEFINED, np)) 8840Sstevel@tonic-gate return (0); 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate valuep->t = UINT64; 8870Sstevel@tonic-gate valuep->v = (lval.v == rval.v); 8880Sstevel@tonic-gate return (1); 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate case T_LT: 8910Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 8920Sstevel@tonic-gate arrowp, try, &lval)) 8930Sstevel@tonic-gate return (0); 8940Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 8950Sstevel@tonic-gate arrowp, try, &rval)) 8960Sstevel@tonic-gate return (0); 8971414Scindi if (check_expr_args(&lval, &rval, UINT64, np)) 8980Sstevel@tonic-gate return (0); 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate valuep->t = UINT64; 9010Sstevel@tonic-gate valuep->v = (lval.v < rval.v); 9020Sstevel@tonic-gate return (1); 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate case T_LE: 9050Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9060Sstevel@tonic-gate arrowp, try, &lval)) 9070Sstevel@tonic-gate return (0); 9080Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9090Sstevel@tonic-gate arrowp, try, &rval)) 9100Sstevel@tonic-gate return (0); 9111414Scindi if (check_expr_args(&lval, &rval, UINT64, np)) 9120Sstevel@tonic-gate return (0); 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate valuep->t = UINT64; 9150Sstevel@tonic-gate valuep->v = (lval.v <= rval.v); 9160Sstevel@tonic-gate return (1); 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate case T_GT: 9190Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9200Sstevel@tonic-gate arrowp, try, &lval)) 9210Sstevel@tonic-gate return (0); 9220Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9230Sstevel@tonic-gate arrowp, try, &rval)) 9240Sstevel@tonic-gate return (0); 9251414Scindi if (check_expr_args(&lval, &rval, UINT64, np)) 9260Sstevel@tonic-gate return (0); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate valuep->t = UINT64; 9290Sstevel@tonic-gate valuep->v = (lval.v > rval.v); 9300Sstevel@tonic-gate return (1); 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate case T_GE: 9330Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9340Sstevel@tonic-gate arrowp, try, &lval)) 9350Sstevel@tonic-gate return (0); 9360Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9370Sstevel@tonic-gate arrowp, try, &rval)) 9380Sstevel@tonic-gate return (0); 9391414Scindi if (check_expr_args(&lval, &rval, UINT64, np)) 9400Sstevel@tonic-gate return (0); 9410Sstevel@tonic-gate 9420Sstevel@tonic-gate valuep->t = UINT64; 9430Sstevel@tonic-gate valuep->v = (lval.v >= rval.v); 9440Sstevel@tonic-gate return (1); 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate case T_BITAND: 9470Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9480Sstevel@tonic-gate arrowp, try, &lval)) 9490Sstevel@tonic-gate return (0); 9500Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9510Sstevel@tonic-gate arrowp, try, &rval)) 9520Sstevel@tonic-gate return (0); 9530Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 9540Sstevel@tonic-gate return (0); 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate valuep->t = lval.t; 9570Sstevel@tonic-gate valuep->v = (lval.v & rval.v); 9580Sstevel@tonic-gate return (1); 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate case T_BITOR: 9610Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9620Sstevel@tonic-gate arrowp, try, &lval)) 9630Sstevel@tonic-gate return (0); 9640Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9650Sstevel@tonic-gate arrowp, try, &rval)) 9660Sstevel@tonic-gate return (0); 9670Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 9680Sstevel@tonic-gate return (0); 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate valuep->t = lval.t; 9710Sstevel@tonic-gate valuep->v = (lval.v | rval.v); 9720Sstevel@tonic-gate return (1); 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate case T_BITXOR: 9750Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9760Sstevel@tonic-gate arrowp, try, &lval)) 9770Sstevel@tonic-gate return (0); 9780Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 9790Sstevel@tonic-gate arrowp, try, &rval)) 9800Sstevel@tonic-gate return (0); 9810Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 9820Sstevel@tonic-gate return (0); 9830Sstevel@tonic-gate 9840Sstevel@tonic-gate valuep->t = lval.t; 9850Sstevel@tonic-gate valuep->v = (lval.v ^ rval.v); 9860Sstevel@tonic-gate return (1); 9870Sstevel@tonic-gate 9880Sstevel@tonic-gate case T_BITNOT: 9890Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 9900Sstevel@tonic-gate arrowp, try, &lval)) 9910Sstevel@tonic-gate return (0); 9920Sstevel@tonic-gate ASSERT(np->u.expr.right == NULL); 9930Sstevel@tonic-gate if (check_expr_args(&lval, NULL, UINT64, np)) 9940Sstevel@tonic-gate return (0); 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate valuep->t = UINT64; 9970Sstevel@tonic-gate valuep->v = ~ lval.v; 9980Sstevel@tonic-gate return (1); 9990Sstevel@tonic-gate 10000Sstevel@tonic-gate case T_LSHIFT: 10010Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 10020Sstevel@tonic-gate arrowp, try, &lval)) 10030Sstevel@tonic-gate return (0); 10040Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 10050Sstevel@tonic-gate arrowp, try, &rval)) 10060Sstevel@tonic-gate return (0); 10070Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 10080Sstevel@tonic-gate return (0); 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate valuep->t = UINT64; 10110Sstevel@tonic-gate valuep->v = (lval.v << rval.v); 10120Sstevel@tonic-gate return (1); 10130Sstevel@tonic-gate 10140Sstevel@tonic-gate case T_RSHIFT: 10150Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 10160Sstevel@tonic-gate arrowp, try, &lval)) 10170Sstevel@tonic-gate return (0); 10180Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 10190Sstevel@tonic-gate arrowp, try, &rval)) 10200Sstevel@tonic-gate return (0); 10210Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 10220Sstevel@tonic-gate return (0); 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate valuep->t = UINT64; 10250Sstevel@tonic-gate valuep->v = (lval.v >> rval.v); 10260Sstevel@tonic-gate return (1); 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate case T_CONDIF: { 10290Sstevel@tonic-gate struct node *retnp; 10300Sstevel@tonic-gate int dotrue = 0; 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate /* 10330Sstevel@tonic-gate * evaluate 10340Sstevel@tonic-gate * expression ? stmtA [ : stmtB ] 10350Sstevel@tonic-gate * 10360Sstevel@tonic-gate * first see if expression is true or false, then determine 10370Sstevel@tonic-gate * if stmtA (or stmtB, if it exists) should be evaluated. 10380Sstevel@tonic-gate * 10390Sstevel@tonic-gate * "dotrue = 1" means stmtA should be evaluated. 10400Sstevel@tonic-gate */ 10410Sstevel@tonic-gate if (eval_expr(np->u.expr.left, ex, epnames, globals, croot, 10420Sstevel@tonic-gate arrowp, try, &lval) && 10430Sstevel@tonic-gate lval.t != UNDEFINED && lval.v != 0) 10440Sstevel@tonic-gate dotrue = 1; 10450Sstevel@tonic-gate 10460Sstevel@tonic-gate ASSERT(np->u.expr.right != NULL); 10470Sstevel@tonic-gate if (np->u.expr.right->t == T_CONDELSE) { 10480Sstevel@tonic-gate if (dotrue) 10490Sstevel@tonic-gate retnp = np->u.expr.right->u.expr.left; 10500Sstevel@tonic-gate else 10510Sstevel@tonic-gate retnp = np->u.expr.right->u.expr.right; 10520Sstevel@tonic-gate } else { 10530Sstevel@tonic-gate /* no ELSE clause */ 10540Sstevel@tonic-gate if (dotrue) 10550Sstevel@tonic-gate retnp = np->u.expr.right; 10560Sstevel@tonic-gate else { 10570Sstevel@tonic-gate valuep->t = UINT64; 10580Sstevel@tonic-gate valuep->v = 0; 10590Sstevel@tonic-gate return (0); 10600Sstevel@tonic-gate } 10610Sstevel@tonic-gate } 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate if (!eval_expr(retnp, ex, epnames, globals, croot, 10640Sstevel@tonic-gate arrowp, try, valuep)) 10650Sstevel@tonic-gate return (0); 10660Sstevel@tonic-gate return (1); 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate case T_CONDELSE: 10700Sstevel@tonic-gate /* 10710Sstevel@tonic-gate * shouldn't get here, since T_CONDELSE is supposed to be 10720Sstevel@tonic-gate * evaluated as part of T_CONDIF 10730Sstevel@tonic-gate */ 10740Sstevel@tonic-gate out(O_ALTFP|O_DIE, "eval_expr: wrong context for operation %s", 10750Sstevel@tonic-gate ptree_nodetype2str(np->t)); 10760Sstevel@tonic-gate return (0); 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate case T_NE: 10790Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 10800Sstevel@tonic-gate arrowp, try, &lval)) 10810Sstevel@tonic-gate return (0); 10820Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 10830Sstevel@tonic-gate arrowp, try, &rval)) 10840Sstevel@tonic-gate return (0); 10850Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UNDEFINED, np)) 10860Sstevel@tonic-gate return (0); 10870Sstevel@tonic-gate 10880Sstevel@tonic-gate valuep->t = UINT64; 10890Sstevel@tonic-gate valuep->v = (lval.v != rval.v); 10900Sstevel@tonic-gate return (1); 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate case T_LIST: 10930Sstevel@tonic-gate case T_AND: 10940Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 10950Sstevel@tonic-gate arrowp, try, valuep)) 10960Sstevel@tonic-gate return (0); 10970Sstevel@tonic-gate if (valuep->v == 0) { 10980Sstevel@tonic-gate valuep->t = UINT64; 10990Sstevel@tonic-gate return (1); 11000Sstevel@tonic-gate } 11010Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11020Sstevel@tonic-gate arrowp, try, valuep)) 11030Sstevel@tonic-gate return (0); 11040Sstevel@tonic-gate valuep->t = UINT64; 11050Sstevel@tonic-gate valuep->v = valuep->v == 0 ? 0 : 1; 11060Sstevel@tonic-gate return (1); 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate case T_OR: 11090Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11100Sstevel@tonic-gate arrowp, try, valuep)) 11110Sstevel@tonic-gate return (0); 11120Sstevel@tonic-gate if (valuep->v != 0) { 11130Sstevel@tonic-gate valuep->t = UINT64; 11140Sstevel@tonic-gate valuep->v = 1; 11150Sstevel@tonic-gate return (1); 11160Sstevel@tonic-gate } 11170Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11180Sstevel@tonic-gate arrowp, try, valuep)) 11190Sstevel@tonic-gate return (0); 11200Sstevel@tonic-gate valuep->t = UINT64; 11210Sstevel@tonic-gate valuep->v = valuep->v == 0 ? 0 : 1; 11220Sstevel@tonic-gate return (1); 11230Sstevel@tonic-gate 11240Sstevel@tonic-gate case T_NOT: 11250Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11260Sstevel@tonic-gate arrowp, try, valuep)) 11270Sstevel@tonic-gate return (0); 11280Sstevel@tonic-gate valuep->t = UINT64; 11290Sstevel@tonic-gate valuep->v = ! valuep->v; 11300Sstevel@tonic-gate return (1); 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate case T_ADD: 11330Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11340Sstevel@tonic-gate arrowp, try, &lval)) 11350Sstevel@tonic-gate return (0); 11360Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11370Sstevel@tonic-gate arrowp, try, &rval)) 11380Sstevel@tonic-gate return (0); 11390Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 11400Sstevel@tonic-gate return (0); 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate valuep->t = lval.t; 11430Sstevel@tonic-gate valuep->v = lval.v + rval.v; 11440Sstevel@tonic-gate return (1); 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate case T_SUB: 11470Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11480Sstevel@tonic-gate arrowp, try, &lval)) 11490Sstevel@tonic-gate return (0); 11500Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11510Sstevel@tonic-gate arrowp, try, &rval)) 11520Sstevel@tonic-gate return (0); 11530Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 11540Sstevel@tonic-gate return (0); 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate /* since valuep is unsigned, return false if lval.v < rval.v */ 11570Sstevel@tonic-gate if (lval.v < rval.v) { 11580Sstevel@tonic-gate out(O_ERR, "eval_expr: T_SUB result is out of range"); 11590Sstevel@tonic-gate valuep->t = UNDEFINED; 11600Sstevel@tonic-gate return (0); 11610Sstevel@tonic-gate } 11620Sstevel@tonic-gate 11630Sstevel@tonic-gate valuep->t = lval.t; 11640Sstevel@tonic-gate valuep->v = lval.v - rval.v; 11650Sstevel@tonic-gate return (1); 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate case T_MUL: 11680Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11690Sstevel@tonic-gate arrowp, try, &lval)) 11700Sstevel@tonic-gate return (0); 11710Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11720Sstevel@tonic-gate arrowp, try, &rval)) 11730Sstevel@tonic-gate return (0); 11740Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 11750Sstevel@tonic-gate return (0); 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate valuep->t = lval.t; 11780Sstevel@tonic-gate valuep->v = lval.v * rval.v; 11790Sstevel@tonic-gate return (1); 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate case T_DIV: 11820Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 11830Sstevel@tonic-gate arrowp, try, &lval)) 11840Sstevel@tonic-gate return (0); 11850Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 11860Sstevel@tonic-gate arrowp, try, &rval)) 11870Sstevel@tonic-gate return (0); 11880Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 11890Sstevel@tonic-gate return (0); 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate /* return false if dividing by zero */ 11920Sstevel@tonic-gate if (rval.v == 0) { 11930Sstevel@tonic-gate out(O_ERR, "eval_expr: T_DIV division by zero"); 11940Sstevel@tonic-gate valuep->t = UNDEFINED; 11950Sstevel@tonic-gate return (0); 11960Sstevel@tonic-gate } 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate valuep->t = lval.t; 11990Sstevel@tonic-gate valuep->v = lval.v / rval.v; 12000Sstevel@tonic-gate return (1); 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate case T_MOD: 12030Sstevel@tonic-gate if (!eval_expr(np->u.expr.left, ex, epnames, globals, croot, 12040Sstevel@tonic-gate arrowp, try, &lval)) 12050Sstevel@tonic-gate return (0); 12060Sstevel@tonic-gate if (!eval_expr(np->u.expr.right, ex, epnames, globals, croot, 12070Sstevel@tonic-gate arrowp, try, &rval)) 12080Sstevel@tonic-gate return (0); 12090Sstevel@tonic-gate if (check_expr_args(&lval, &rval, UINT64, np)) 12100Sstevel@tonic-gate return (0); 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate /* return false if dividing by zero */ 12130Sstevel@tonic-gate if (rval.v == 0) { 12140Sstevel@tonic-gate out(O_ERR, "eval_expr: T_MOD division by zero"); 12150Sstevel@tonic-gate valuep->t = UNDEFINED; 12160Sstevel@tonic-gate return (0); 12170Sstevel@tonic-gate } 12180Sstevel@tonic-gate 12190Sstevel@tonic-gate valuep->t = lval.t; 12200Sstevel@tonic-gate valuep->v = lval.v % rval.v; 12210Sstevel@tonic-gate return (1); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate case T_NAME: 12240Sstevel@tonic-gate if (try) { 12250Sstevel@tonic-gate struct iterinfo *iterinfop; 12260Sstevel@tonic-gate 12270Sstevel@tonic-gate /* 12280Sstevel@tonic-gate * at itree_create() time, we can expand simple 12290Sstevel@tonic-gate * iterators. anything else we'll punt on. 12300Sstevel@tonic-gate */ 12310Sstevel@tonic-gate iterinfop = lut_lookup(ex, (void *)np->u.name.s, NULL); 12320Sstevel@tonic-gate if (iterinfop != NULL) { 12330Sstevel@tonic-gate /* explicit iterator; not part of pathname */ 12340Sstevel@tonic-gate valuep->t = UINT64; 12350Sstevel@tonic-gate valuep->v = (unsigned long long)iterinfop->num; 12360Sstevel@tonic-gate return (1); 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate return (0); 12390Sstevel@tonic-gate } 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate /* return address of struct node */ 12420Sstevel@tonic-gate valuep->t = NODEPTR; 1243*1717Swesolows valuep->v = (uintptr_t)np; 12440Sstevel@tonic-gate return (1); 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate case T_QUOTE: 12470Sstevel@tonic-gate valuep->t = STRING; 1248*1717Swesolows valuep->v = (uintptr_t)np->u.quote.s; 12490Sstevel@tonic-gate return (1); 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate case T_FUNC: 12520Sstevel@tonic-gate return (eval_func(np, ex, epnames, np->u.func.arglist, 12530Sstevel@tonic-gate globals, croot, arrowp, try, valuep)); 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate case T_NUM: 12560Sstevel@tonic-gate valuep->t = UINT64; 12570Sstevel@tonic-gate valuep->v = np->u.ull; 12580Sstevel@tonic-gate return (1); 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate default: 12610Sstevel@tonic-gate outfl(O_DIE, np->file, np->line, 12620Sstevel@tonic-gate "eval_expr: unexpected node type: %s", 12630Sstevel@tonic-gate ptree_nodetype2str(np->t)); 12640Sstevel@tonic-gate } 12650Sstevel@tonic-gate /*NOTREACHED*/ 1266*1717Swesolows return (0); 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate /* 12700Sstevel@tonic-gate * eval_fru() and eval_asru() don't do much, but are called from a number 12710Sstevel@tonic-gate * of places. 12720Sstevel@tonic-gate */ 12730Sstevel@tonic-gate struct node * 12740Sstevel@tonic-gate eval_fru(struct node *np) 12750Sstevel@tonic-gate { 12760Sstevel@tonic-gate ASSERT(np->t == T_NAME); 12770Sstevel@tonic-gate return (np); 12780Sstevel@tonic-gate } 12790Sstevel@tonic-gate 12800Sstevel@tonic-gate struct node * 12810Sstevel@tonic-gate eval_asru(struct node *np) 12820Sstevel@tonic-gate { 12830Sstevel@tonic-gate ASSERT(np->t == T_NAME); 12840Sstevel@tonic-gate return (np); 12850Sstevel@tonic-gate } 1286