1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 8 unchanged lines hidden (view full) --- 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23/* 24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
25 * Copyright (c) 2013, Joyent Inc. All rights reserved. 26 * Copyright (c) 2013 by Delphix. All rights reserved. |
27 */ 28 29#pragma ident "%Z%%M% %I% %E% SMI" 30 31/* 32 * DTrace D Language Parser 33 * 34 * The D Parser is a lex/yacc parser consisting of the lexer dt_lex.l, the --- 157 unchanged lines hidden (view full) --- 192 } 193} 194 195int 196dt_type_lookup(const char *s, dtrace_typeinfo_t *tip) 197{ 198 static const char delimiters[] = " \t\n\r\v\f*`"; 199 dtrace_hdl_t *dtp = yypcb->pcb_hdl; |
200 const char *p, *q, *r, *end, *obj; |
201 202 for (p = s, end = s + strlen(s); *p != '\0'; p = q) { 203 while (isspace(*p)) 204 p++; /* skip leading whitespace prior to token */ 205 206 if (p == end || (q = strpbrk(p + 1, delimiters)) == NULL) 207 break; /* empty string or single token remaining */ 208 --- 11 unchanged lines hidden (view full) --- 220 /* 221 * Copy the original string up to the start of this 222 * token (p) into type, and then concatenate everything 223 * after q. This is the type name without the object. 224 */ 225 bcopy(s, type, (size_t)(p - s)); 226 bcopy(q + 1, type + (size_t)(p - s), strlen(q + 1) + 1); 227 |
228 /* 229 * There may be at most three delimeters. The second 230 * delimeter is usually used to distinguish the type 231 * within a given module, however, there could be a link 232 * map id on the scene in which case that delimeter 233 * would be the third. We determine presence of the lmid 234 * if it rouglhly meets the from LM[0-9] 235 */ 236 if ((r = strchr(q + 1, '`')) != NULL && 237 ((r = strchr(r + 1, '`')) != NULL)) { 238 if (strchr(r + 1, '`') != NULL) 239 return (dt_set_errno(dtp, 240 EDT_BADSCOPE)); 241 if (q[1] != 'L' || q[2] != 'M') 242 return (dt_set_errno(dtp, 243 EDT_BADSCOPE)); 244 } |
245 246 return (dtrace_lookup_by_type(dtp, object, type, tip)); 247 } 248 } 249 250 if (yypcb->pcb_idepth != 0) 251 obj = DTRACE_OBJ_CDEFS; 252 else --- 13 unchanged lines hidden (view full) --- 266 */ 267int 268dt_type_pointer(dtrace_typeinfo_t *tip) 269{ 270 dtrace_hdl_t *dtp = yypcb->pcb_hdl; 271 ctf_file_t *ctfp = tip->dtt_ctfp; 272 ctf_id_t type = tip->dtt_type; 273 ctf_id_t base = ctf_type_resolve(ctfp, type); |
274 uint_t bflags = tip->dtt_flags; |
275 276 dt_module_t *dmp; 277 ctf_id_t ptr; 278 279 if ((ptr = ctf_type_pointer(ctfp, type)) != CTF_ERR || 280 (ptr = ctf_type_pointer(ctfp, base)) != CTF_ERR) { 281 tip->dtt_type = ptr; 282 return (0); --- 15 unchanged lines hidden (view full) --- 298 if (ptr == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) { 299 dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp); 300 return (dt_set_errno(dtp, EDT_CTF)); 301 } 302 303 tip->dtt_object = dmp->dm_name; 304 tip->dtt_ctfp = dmp->dm_ctfp; 305 tip->dtt_type = ptr; |
306 tip->dtt_flags = bflags; |
307 308 return (0); 309} 310 311const char * 312dt_type_name(ctf_file_t *ctfp, ctf_id_t type, char *buf, size_t len) 313{ 314 dtrace_hdl_t *dtp = yypcb->pcb_hdl; --- 87 unchanged lines hidden (view full) --- 402 *ofp = rfp; 403 *otype = rtype; 404} 405 406void 407dt_node_promote(dt_node_t *lp, dt_node_t *rp, dt_node_t *dnp) 408{ 409 dt_type_promote(lp, rp, &dnp->dn_ctfp, &dnp->dn_type); |
410 dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type, B_FALSE); |
411 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); 412} 413 414const char * 415dt_node_name(const dt_node_t *dnp, char *buf, size_t len) 416{ 417 char n1[DT_TYPE_NAMELEN]; 418 char n2[DT_TYPE_NAMELEN]; --- 252 unchanged lines hidden (view full) --- 671 "predefined minimum\n", dt_node_name(dnp, s, sizeof (s)), 672 dtrace_attr2str(attr, a, sizeof (a))); 673 } 674 675 dnp->dn_attr = attr; 676} 677 678void |
679dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type, 680 boolean_t user) |
681{ 682 ctf_id_t base = ctf_type_resolve(fp, type); 683 uint_t kind = ctf_type_kind(fp, base); 684 ctf_encoding_t e; 685 686 dnp->dn_flags &= 687 ~(DT_NF_SIGNED | DT_NF_REF | DT_NF_BITFIELD | DT_NF_USERLAND); 688 --- 15 unchanged lines hidden (view full) --- 704 if (kind == CTF_K_STRUCT || kind == CTF_K_UNION || 705 kind == CTF_K_FORWARD || 706 kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION) 707 dnp->dn_flags |= DT_NF_REF; 708 else if (yypcb != NULL && fp == DT_DYN_CTFP(yypcb->pcb_hdl) && 709 type == DT_DYN_TYPE(yypcb->pcb_hdl)) 710 dnp->dn_flags |= DT_NF_REF; 711 |
712 if (user) 713 dnp->dn_flags |= DT_NF_USERLAND; 714 |
715 dnp->dn_flags |= DT_NF_COOKED; 716 dnp->dn_ctfp = fp; 717 dnp->dn_type = type; 718} 719 720void 721dt_node_type_propagate(const dt_node_t *src, dt_node_t *dst) 722{ --- 21 unchanged lines hidden (view full) --- 744 745 return (dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf, len)); 746} 747 748size_t 749dt_node_type_size(const dt_node_t *dnp) 750{ 751 ctf_id_t base; |
752 dtrace_hdl_t *dtp = yypcb->pcb_hdl; |
753 754 if (dnp->dn_kind == DT_NODE_STRING) 755 return (strlen(dnp->dn_string) + 1); 756 757 if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL) 758 return (dt_ident_size(dnp->dn_ident)); 759 760 base = ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type); 761 762 if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_FORWARD) 763 return (0); 764 |
765 /* 766 * Here we have a 32-bit user pointer that is being used with a 64-bit 767 * kernel. When we're using it and its tagged as a userland reference -- 768 * then we need to keep it as a 32-bit pointer. However, if we are 769 * referring to it as a kernel address, eg. being used after a copyin() 770 * then we need to make sure that we actually return the kernel's size 771 * of a pointer, 8 bytes. 772 */ 773 if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_POINTER && 774 ctf_getmodel(dnp->dn_ctfp) == CTF_MODEL_ILP32 && 775 !(dnp->dn_flags & DT_NF_USERLAND) && 776 dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) 777 return (8); 778 |
779 return (ctf_type_size(dnp->dn_ctfp, dnp->dn_type)); 780} 781 782/* 783 * Determine if the specified parse tree node references an identifier of the 784 * specified kind, and if so return a pointer to it; otherwise return NULL. 785 * This function resolves the identifier itself, following through any inlines. 786 */ --- 470 unchanged lines hidden (view full) --- 1257 else if (c == 'L' || c == 'l') 1258 i += 2; 1259 } 1260 1261 for (; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i += n) { 1262 if (value <= dtp->dt_ints[i].did_limit) { 1263 dt_node_type_assign(dnp, 1264 dtp->dt_ints[i].did_ctfp, |
1265 dtp->dt_ints[i].did_type, B_FALSE); |
1266 1267 /* 1268 * If a prefix character is present in macro text, add 1269 * in the corresponding operator node (see dt_lex.l). 1270 */ 1271 switch (yyintprefix) { 1272 case '+': 1273 return (dt_node_op1(DT_TOK_IPOS, dnp)); --- 18 unchanged lines hidden (view full) --- 1292 dt_node_t *dnp; 1293 1294 if (string == NULL) 1295 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM); 1296 1297 dnp = dt_node_alloc(DT_NODE_STRING); 1298 dnp->dn_op = DT_TOK_STRING; 1299 dnp->dn_string = string; |
1300 dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), B_FALSE); |
1301 1302 return (dnp); 1303} 1304 1305dt_node_t * 1306dt_node_ident(char *name) 1307{ 1308 dt_ident_t *idp; --- 59 unchanged lines hidden (view full) --- 1368 if (err != 0) { 1369 free(name); 1370 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); 1371 } 1372 1373 dnp = dt_node_alloc(DT_NODE_TYPE); 1374 dnp->dn_op = DT_TOK_IDENT; 1375 dnp->dn_string = name; |
1376 |
1377 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, dtt.dtt_flags); 1378 |
1379 if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp || 1380 dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp) 1381 dt_node_attr_assign(dnp, _dtrace_defattr); 1382 else 1383 dt_node_attr_assign(dnp, _dtrace_typattr); 1384 1385 return (dnp); 1386} --- 226 unchanged lines hidden (view full) --- 1613 * If the pre-existing ident has its di_type set, propagate 1614 * the type by hand so as not to trigger a prototype check for 1615 * arrays (yet); otherwise we use dt_ident_cook() on the ident 1616 * to ensure it is fully initialized before looking at it. 1617 */ 1618 bzero(&idn, sizeof (dt_node_t)); 1619 1620 if (idp != NULL && idp->di_type != CTF_ERR) |
1621 dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type, 1622 B_FALSE); |
1623 else if (idp != NULL) 1624 (void) dt_ident_cook(&idn, idp, NULL); 1625 1626 if (assc) { 1627 if (class == DT_DC_THIS) { 1628 xyerror(D_DECL_LOCASSC, "associative arrays " 1629 "may not be declared as local variables:" 1630 " %s\n", dsp->ds_ident); --- 193 unchanged lines hidden (view full) --- 1824 } 1825 1826 if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) { 1827 xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n", 1828 name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp))); 1829 } 1830 1831 bzero(&dn, sizeof (dn)); |
1832 dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type, B_FALSE); |
1833 1834 if (dn.dn_flags & DT_NF_BITFIELD) { 1835 xyerror(D_OFFSETOF_BITFIELD, 1836 "cannot take offset of a bit-field: %s\n", name); 1837 } 1838 1839 return (dt_node_int(ctm.ctm_offset / NBBY)); 1840} --- 39 unchanged lines hidden (view full) --- 1880 size_t size = dt_node_type_size(cp); 1881 1882 if (size == 0) { 1883 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an " 1884 "operand of unknown size\n"); 1885 } 1886 1887 dt_node_type_assign(cp, dtp->dt_ddefs->dm_ctfp, |
1888 ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"), 1889 B_FALSE); |
1890 1891 cp->dn_kind = DT_NODE_INT; 1892 cp->dn_op = DT_TOK_INT; 1893 cp->dn_value = size; 1894 1895 return (cp); 1896 } 1897 --- 61 unchanged lines hidden (view full) --- 1959 uintmax_t r = rp->dn_value; 1960 1961 dnp = dt_node_int(0); /* allocate new integer node for result */ 1962 1963 switch (op) { 1964 case DT_TOK_LOR: 1965 dnp->dn_value = l || r; 1966 dt_node_type_assign(dnp, |
1967 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
1968 break; 1969 case DT_TOK_LXOR: 1970 dnp->dn_value = (l != 0) ^ (r != 0); 1971 dt_node_type_assign(dnp, |
1972 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
1973 break; 1974 case DT_TOK_LAND: 1975 dnp->dn_value = l && r; 1976 dt_node_type_assign(dnp, |
1977 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
1978 break; 1979 case DT_TOK_BOR: 1980 dnp->dn_value = l | r; 1981 dt_node_promote(lp, rp, dnp); 1982 break; 1983 case DT_TOK_XOR: 1984 dnp->dn_value = l ^ r; 1985 dt_node_promote(lp, rp, dnp); 1986 break; 1987 case DT_TOK_BAND: 1988 dnp->dn_value = l & r; 1989 dt_node_promote(lp, rp, dnp); 1990 break; 1991 case DT_TOK_EQU: 1992 dnp->dn_value = l == r; 1993 dt_node_type_assign(dnp, |
1994 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
1995 break; 1996 case DT_TOK_NEQ: 1997 dnp->dn_value = l != r; 1998 dt_node_type_assign(dnp, |
1999 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
2000 break; 2001 case DT_TOK_LT: 2002 dt_node_promote(lp, rp, dnp); 2003 if (dnp->dn_flags & DT_NF_SIGNED) 2004 dnp->dn_value = (intmax_t)l < (intmax_t)r; 2005 else 2006 dnp->dn_value = l < r; 2007 dt_node_type_assign(dnp, |
2008 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
2009 break; 2010 case DT_TOK_LE: 2011 dt_node_promote(lp, rp, dnp); 2012 if (dnp->dn_flags & DT_NF_SIGNED) 2013 dnp->dn_value = (intmax_t)l <= (intmax_t)r; 2014 else 2015 dnp->dn_value = l <= r; 2016 dt_node_type_assign(dnp, |
2017 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
2018 break; 2019 case DT_TOK_GT: 2020 dt_node_promote(lp, rp, dnp); 2021 if (dnp->dn_flags & DT_NF_SIGNED) 2022 dnp->dn_value = (intmax_t)l > (intmax_t)r; 2023 else 2024 dnp->dn_value = l > r; 2025 dt_node_type_assign(dnp, |
2026 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
2027 break; 2028 case DT_TOK_GE: 2029 dt_node_promote(lp, rp, dnp); 2030 if (dnp->dn_flags & DT_NF_SIGNED) 2031 dnp->dn_value = (intmax_t)l >= (intmax_t)r; 2032 else 2033 dnp->dn_value = l >= r; 2034 dt_node_type_assign(dnp, |
2035 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), B_FALSE); |
2036 break; 2037 case DT_TOK_LSH: 2038 dnp->dn_value = l << r; 2039 dt_node_type_propagate(lp, dnp); 2040 dt_node_attr_assign(rp, 2041 dt_attr_min(lp->dn_attr, rp->dn_attr)); 2042 break; 2043 case DT_TOK_RSH: --- 224 unchanged lines hidden (view full) --- 2268 } 2269 2270 /* 2271 * If the inline identifier is not defined, then create it with the 2272 * orphan flag set. We do not insert the identifier into dt_globals 2273 * until we have successfully cooked the right-hand expression, below. 2274 */ 2275 dnp = dt_node_alloc(DT_NODE_INLINE); |
2276 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, B_FALSE); |
2277 dt_node_attr_assign(dnp, _dtrace_defattr); 2278 2279 if (dt_node_is_void(dnp)) { 2280 xyerror(D_DECL_VOIDOBJ, 2281 "cannot declare void inline: %s\n", dsp->ds_ident); 2282 } 2283 2284 if (ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve( --- 138 unchanged lines hidden (view full) --- 2423 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); 2424 } 2425 2426 dnp = dt_node_alloc(DT_NODE_MEMBER); 2427 dnp->dn_membname = name; 2428 dnp->dn_membexpr = expr; 2429 2430 if (ddp != NULL) |
2431 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, 2432 dtt.dtt_flags); |
2433 2434 return (dnp); 2435} 2436 2437dt_node_t * 2438dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members) 2439{ 2440 dtrace_hdl_t *dtp = yypcb->pcb_hdl; --- 14 unchanged lines hidden (view full) --- 2455 dt_decl_free(sdp); 2456 2457 if (edst != 0 || esrc != 0) { 2458 free(name); 2459 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER); 2460 } 2461 2462 bzero(&sn, sizeof (sn)); |
2463 dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type, B_FALSE); |
2464 2465 bzero(&dn, sizeof (dn)); |
2466 dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type, B_FALSE); |
2467 2468 if (dt_xlator_lookup(dtp, &sn, &dn, DT_XLATE_EXACT) != NULL) { 2469 xyerror(D_XLATE_REDECL, 2470 "translator from %s to %s has already been declared\n", 2471 dt_node_type_name(&sn, n1, sizeof (n1)), 2472 dt_node_type_name(&dn, n2, sizeof (n2))); 2473 } 2474 --- 229 unchanged lines hidden (view full) --- 2704 * have dynamic types and must be referenced using operator []. 2705 * This is handled explicitly by the code for DT_TOK_LBRAC. 2706 */ 2707 if (idp->di_kind != DT_IDENT_ARRAY && 2708 idp->di_kind != DT_IDENT_AGG) 2709 attr = dt_ident_cook(dnp, idp, NULL); 2710 else { 2711 dt_node_type_assign(dnp, |
2712 DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); |
2713 attr = idp->di_attr; 2714 } 2715 2716 free(dnp->dn_string); 2717 dnp->dn_string = NULL; 2718 dnp->dn_kind = dnkind; 2719 dnp->dn_ident = idp; 2720 dnp->dn_flags |= DT_NF_LVALUE; --- 59 unchanged lines hidden (view full) --- 2780 idp->di_type = dtt.dtt_type; 2781 2782 free(dnp->dn_string); 2783 dnp->dn_string = NULL; 2784 dnp->dn_kind = DT_NODE_SYM; 2785 dnp->dn_ident = idp; 2786 dnp->dn_flags |= DT_NF_LVALUE; 2787 |
2788 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, 2789 dtt.dtt_flags); |
2790 dt_node_attr_assign(dnp, _dtrace_symattr); 2791 2792 if (uref) { 2793 idp->di_flags |= DT_IDFLG_USER; 2794 dnp->dn_flags |= DT_NF_USERLAND; 2795 } 2796 2797 } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) { --- 31 unchanged lines hidden (view full) --- 2829 * have dynamic types and must be referenced using operator []. 2830 * This is handled explicitly by the code for DT_TOK_LBRAC. 2831 */ 2832 if (idp->di_kind != DT_IDENT_ARRAY && 2833 idp->di_kind != DT_IDENT_AGG) 2834 attr = dt_ident_cook(dnp, idp, NULL); 2835 else { 2836 dt_node_type_assign(dnp, |
2837 DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); |
2838 attr = idp->di_attr; 2839 } 2840 2841 free(dnp->dn_string); 2842 dnp->dn_string = NULL; 2843 dnp->dn_kind = dnkind; 2844 dnp->dn_ident = idp; 2845 dnp->dn_flags |= DT_NF_LVALUE | DT_NF_WRITABLE; --- 86 unchanged lines hidden (view full) --- 2932 2933 cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */ 2934 2935 if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) { 2936 if (dt_type_lookup("int64_t", &dtt) != 0) 2937 xyerror(D_TYPE_ERR, "failed to lookup int64_t\n"); 2938 2939 dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type); |
2940 dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type, 2941 dtt.dtt_flags); |
2942 } 2943 2944 if (cp->dn_kind == DT_NODE_VAR) 2945 cp->dn_ident->di_flags |= idflags; 2946 2947 switch (dnp->dn_op) { 2948 case DT_TOK_DEREF: 2949 /* 2950 * If the deref operator is applied to a translated pointer, 2951 * we set our output type to the output of the translation. 2952 */ 2953 if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) { 2954 dt_xlator_t *dxp = idp->di_data; 2955 2956 dnp->dn_ident = &dxp->dx_souid; 2957 dt_node_type_assign(dnp, |
2958 dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type, 2959 cp->dn_flags & DT_NF_USERLAND); |
2960 break; 2961 } 2962 2963 type = ctf_type_resolve(cp->dn_ctfp, cp->dn_type); 2964 kind = ctf_type_kind(cp->dn_ctfp, type); 2965 2966 if (kind == CTF_K_ARRAY) { 2967 if (ctf_array_info(cp->dn_ctfp, type, &r) != 0) { 2968 dtp->dt_ctferr = ctf_errno(cp->dn_ctfp); 2969 longjmp(yypcb->pcb_jmpbuf, EDT_CTF); 2970 } else 2971 type = r.ctr_contents; 2972 } else if (kind == CTF_K_POINTER) { 2973 type = ctf_type_reference(cp->dn_ctfp, type); 2974 } else { 2975 xyerror(D_DEREF_NONPTR, 2976 "cannot dereference non-pointer type\n"); 2977 } 2978 |
2979 dt_node_type_assign(dnp, cp->dn_ctfp, type, 2980 cp->dn_flags & DT_NF_USERLAND); |
2981 base = ctf_type_resolve(cp->dn_ctfp, type); 2982 kind = ctf_type_kind(cp->dn_ctfp, base); 2983 2984 if (kind == CTF_K_INTEGER && ctf_type_encoding(cp->dn_ctfp, 2985 base, &e) == 0 && IS_VOID(e)) { 2986 xyerror(D_DEREF_VOID, 2987 "cannot dereference pointer to void\n"); 2988 } --- 40 unchanged lines hidden (view full) --- 3029 dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */ 3030 break; 3031 3032 case DT_TOK_LNEG: 3033 if (!dt_node_is_scalar(cp)) { 3034 xyerror(D_OP_SCALAR, "operator %s requires an operand " 3035 "of scalar type\n", opstr(dnp->dn_op)); 3036 } |
3037 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), 3038 B_FALSE); |
3039 break; 3040 3041 case DT_TOK_ADDROF: 3042 if (cp->dn_kind == DT_NODE_VAR || cp->dn_kind == DT_NODE_AGG) { 3043 xyerror(D_ADDROF_VAR, 3044 "cannot take address of dynamic variable\n"); 3045 } 3046 --- 16 unchanged lines hidden (view full) --- 3063 dtt.dtt_ctfp = cp->dn_ctfp; 3064 dtt.dtt_type = cp->dn_type; 3065 3066 if (dt_type_pointer(&dtt) == -1) { 3067 xyerror(D_TYPE_ERR, "cannot find type for \"&\": %s*\n", 3068 dt_node_type_name(cp, n, sizeof (n))); 3069 } 3070 |
3071 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type, 3072 cp->dn_flags & DT_NF_USERLAND); |
3073 break; 3074 3075 case DT_TOK_SIZEOF: 3076 if (cp->dn_flags & DT_NF_BITFIELD) { 3077 xyerror(D_SIZEOF_BITFIELD, 3078 "cannot apply sizeof to a bit-field\n"); 3079 } 3080 3081 if (dt_node_sizeof(cp) == 0) { 3082 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an " 3083 "operand of unknown size\n"); 3084 } 3085 3086 dt_node_type_assign(dnp, dtp->dt_ddefs->dm_ctfp, |
3087 ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"), 3088 B_FALSE); |
3089 break; 3090 3091 case DT_TOK_STRINGOF: 3092 if (!dt_node_is_scalar(cp) && !dt_node_is_pointer(cp) && 3093 !dt_node_is_strcompat(cp)) { 3094 xyerror(D_STRINGOF_TYPE, 3095 "cannot apply stringof to a value of type %s\n", 3096 dt_node_type_name(cp, n, sizeof (n))); 3097 } |
3098 dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp), 3099 cp->dn_flags & DT_NF_USERLAND); |
3100 break; 3101 3102 case DT_TOK_PREINC: 3103 case DT_TOK_POSTINC: 3104 case DT_TOK_PREDEC: 3105 case DT_TOK_POSTDEC: 3106 if (dt_node_is_scalar(cp) == 0) { 3107 xyerror(D_OP_SCALAR, "operator %s requires operand of " --- 176 unchanged lines hidden (view full) --- 3284 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF); 3285 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); 3286 3287 if (!dt_node_is_scalar(lp) || !dt_node_is_scalar(rp)) { 3288 xyerror(D_OP_SCALAR, "operator %s requires operands " 3289 "of scalar type\n", opstr(op)); 3290 } 3291 |
3292 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), 3293 B_FALSE); |
3294 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); 3295 break; 3296 3297 case DT_TOK_LT: 3298 case DT_TOK_LE: 3299 case DT_TOK_GT: 3300 case DT_TOK_GE: 3301 case DT_TOK_EQU: --- 27 unchanged lines hidden (view full) --- 3329 3330 free(rp->dn_string); 3331 rp->dn_string = NULL; 3332 rp->dn_kind = DT_NODE_INT; 3333 rp->dn_flags |= DT_NF_COOKED; 3334 rp->dn_op = DT_TOK_INT; 3335 rp->dn_value = (intmax_t)val; 3336 |
3337 dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type, 3338 B_FALSE); |
3339 dt_node_attr_assign(rp, _dtrace_symattr); 3340 } 3341 3342 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF); 3343 3344 /* 3345 * The rules for type checking for the relational operators are 3346 * described in the ANSI-C spec (see K&R[A7.9-10]). We perform --- 15 unchanged lines hidden (view full) --- 3362 /*EMPTY*/; 3363 else if (dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) { 3364 xyerror(D_OP_INCOMPAT, "operands have " 3365 "incompatible types: \"%s\" %s \"%s\"\n", 3366 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), 3367 dt_node_type_name(rp, n2, sizeof (n2))); 3368 } 3369 |
3370 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp), 3371 B_FALSE); |
3372 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); 3373 break; 3374 3375 case DT_TOK_ADD: 3376 case DT_TOK_SUB: { 3377 /* 3378 * The rules for type checking for the additive operators are 3379 * described in the ANSI-C spec (see K&R[A7.7]). Pointers and --- 31 unchanged lines hidden (view full) --- 3411 uref = 0; 3412 } else { 3413 xyerror(D_OP_INCOMPAT, "operands have incompatible " 3414 "types: \"%s\" %s \"%s\"\n", 3415 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op), 3416 dt_node_type_name(rp, n2, sizeof (n2))); 3417 } 3418 |
3419 dt_node_type_assign(dnp, ctfp, type, B_FALSE); |
3420 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr)); 3421 3422 if (uref) 3423 dnp->dn_flags |= DT_NF_USERLAND; 3424 break; 3425 } 3426 3427 case DT_TOK_OR_EQ: --- 124 unchanged lines hidden (view full) --- 3552 3553 /* 3554 * If the left-hand side of an assignment statement is a virgin 3555 * variable created by this compilation pass, reset the type of 3556 * this variable to the type of the right-hand side. 3557 */ 3558 if (lp->dn_kind == DT_NODE_VAR && 3559 dt_ident_unref(lp->dn_ident)) { |
3560 dt_node_type_assign(lp, ctfp, type, B_FALSE); |
3561 dt_ident_type_assign(lp->dn_ident, ctfp, type); 3562 3563 if (uref) { 3564 lp->dn_flags |= DT_NF_USERLAND; 3565 lp->dn_ident->di_flags |= DT_IDFLG_USER; 3566 } 3567 } 3568 --- 197 unchanged lines hidden (view full) --- 3766 xyerror(D_TYPE_MEMBER, 3767 "%s is not a member of %s\n", rp->dn_string, 3768 ctf_type_name(ctfp, type, n1, sizeof (n1))); 3769 } 3770 3771 type = ctf_type_resolve(ctfp, m.ctm_type); 3772 kind = ctf_type_kind(ctfp, type); 3773 |
3774 dt_node_type_assign(dnp, ctfp, m.ctm_type, B_FALSE); |
3775 dt_node_attr_assign(dnp, lp->dn_attr); 3776 3777 if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY || 3778 dt_node_is_string(dnp))) 3779 dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */ 3780 3781 if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) && 3782 (kind != CTF_K_ARRAY || dt_node_is_string(dnp))) --- 109 unchanged lines hidden (view full) --- 3892 if (dxp == NULL) { 3893 xyerror(D_XLATE_NONE, 3894 "cannot translate from \"%s\" to \"%s\"\n", 3895 dt_node_type_name(rp, n1, sizeof (n1)), 3896 dt_node_type_name(lp, n2, sizeof (n2))); 3897 } 3898 3899 dnp->dn_ident = dt_xlator_ident(dxp, lp->dn_ctfp, lp->dn_type); |
3900 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), 3901 B_FALSE); |
3902 dt_node_attr_assign(dnp, 3903 dt_attr_min(rp->dn_attr, dnp->dn_ident->di_attr)); 3904 break; 3905 } 3906 3907 case DT_TOK_LPAR: { 3908 ctf_id_t ltype, rtype; 3909 uint_t lkind, rkind; --- 148 unchanged lines hidden (view full) --- 4058 "operator ?: operands must have compatible types\n"); 4059 } 4060 4061 if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) { 4062 xyerror(D_OP_ACT, "action cannot be " 4063 "used in a conditional context\n"); 4064 } 4065 |
4066 dt_node_type_assign(dnp, ctfp, type, B_FALSE); |
4067 dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_expr->dn_attr, 4068 dt_attr_min(lp->dn_attr, rp->dn_attr))); 4069 4070 return (dnp); 4071} 4072 4073static dt_node_t * 4074dt_cook_statement(dt_node_t *dnp, uint_t idflags) --- 16 unchanged lines hidden (view full) --- 4091{ 4092 dtrace_hdl_t *dtp = yypcb->pcb_hdl; 4093 4094 if (dnp->dn_aggfun != NULL) { 4095 dnp->dn_aggfun = dt_node_cook(dnp->dn_aggfun, DT_IDFLG_REF); 4096 dt_node_attr_assign(dnp, dt_ident_cook(dnp, 4097 dnp->dn_ident, &dnp->dn_aggtup)); 4098 } else { |
4099 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), 4100 B_FALSE); |
4101 dt_node_attr_assign(dnp, dnp->dn_ident->di_attr); 4102 } 4103 4104 return (dnp); 4105} 4106 4107/* 4108 * Since D permits new variable identifiers to be instantiated in any program --- 185 unchanged lines hidden (view full) --- 4294 mnp->dn_membname, &ctm) == CTF_ERR) { 4295 xyerror(D_XLATE_MEMB, 4296 "translator member %s is not a member of %s\n", 4297 mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp, 4298 dxp->dx_dst_type, n1, sizeof (n1))); 4299 } 4300 4301 (void) dt_node_cook(mnp, DT_IDFLG_REF); |
4302 dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type, 4303 B_FALSE); |
4304 attr = dt_attr_min(attr, mnp->dn_attr); 4305 4306 if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) { 4307 xyerror(D_XLATE_INCOMPAT, 4308 "translator member %s definition uses " 4309 "incompatible types: \"%s\" = \"%s\"\n", 4310 mnp->dn_membname, 4311 dt_node_type_name(mnp, n1, sizeof (n1)), 4312 dt_node_type_name(mnp->dn_membexpr, 4313 n2, sizeof (n2))); 4314 } 4315 } 4316 4317 dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals); 4318 4319 dxp->dx_souid.di_attr = attr; 4320 dxp->dx_ptrid.di_attr = attr; 4321 |
4322 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp), B_FALSE); |
4323 dt_node_attr_assign(dnp, _dtrace_defattr); 4324 4325 return (dnp); 4326} 4327 4328static void 4329dt_node_provider_cmp_argv(dt_provider_t *pvp, dt_node_t *pnp, const char *kind, 4330 uint_t old_argc, dt_node_t *old_argv, uint_t new_argc, dt_node_t *new_argv) --- 276 unchanged lines hidden (view full) --- 4607 tp->dtdt_kind = DIF_TYPE_STRING; 4608 tp->dtdt_ckind = CTF_K_UNKNOWN; 4609 } else { 4610 tp->dtdt_kind = DIF_TYPE_CTF; 4611 tp->dtdt_ckind = ctf_type_kind(dnp->dn_ctfp, 4612 ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type)); 4613 } 4614 |
4615 tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ? 4616 (dnp->dn_flags & DT_NF_USERLAND) ? DIF_TF_BYUREF : 4617 DIF_TF_BYREF : 0; |
4618 tp->dtdt_pad = 0; 4619 tp->dtdt_size = ctf_type_size(dnp->dn_ctfp, dnp->dn_type); 4620} 4621 4622void 4623dt_node_printr(dt_node_t *dnp, FILE *fp, int depth) 4624{ 4625 char n[DT_TYPE_NAMELEN], buf[BUFSIZ], a[8]; --- 360 unchanged lines hidden --- |