Deleted Added
sdiff udiff text old ( 256281 ) new ( 268578 )
full compact
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) 2011, Joyent Inc. All rights reserved.
26 * Copyright (c) 2012 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, *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 if (strchr(q + 1, '`') != NULL)
229 return (dt_set_errno(dtp, EDT_BADSCOPE));
230
231 return (dtrace_lookup_by_type(dtp, object, type, tip));
232 }
233 }
234
235 if (yypcb->pcb_idepth != 0)
236 obj = DTRACE_OBJ_CDEFS;
237 else

--- 13 unchanged lines hidden (view full) ---

251 */
252int
253dt_type_pointer(dtrace_typeinfo_t *tip)
254{
255 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
256 ctf_file_t *ctfp = tip->dtt_ctfp;
257 ctf_id_t type = tip->dtt_type;
258 ctf_id_t base = ctf_type_resolve(ctfp, type);
259
260 dt_module_t *dmp;
261 ctf_id_t ptr;
262
263 if ((ptr = ctf_type_pointer(ctfp, type)) != CTF_ERR ||
264 (ptr = ctf_type_pointer(ctfp, base)) != CTF_ERR) {
265 tip->dtt_type = ptr;
266 return (0);

--- 15 unchanged lines hidden (view full) ---

282 if (ptr == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) {
283 dtp->dt_ctferr = ctf_errno(dmp->dm_ctfp);
284 return (dt_set_errno(dtp, EDT_CTF));
285 }
286
287 tip->dtt_object = dmp->dm_name;
288 tip->dtt_ctfp = dmp->dm_ctfp;
289 tip->dtt_type = ptr;
290
291 return (0);
292}
293
294const char *
295dt_type_name(ctf_file_t *ctfp, ctf_id_t type, char *buf, size_t len)
296{
297 dtrace_hdl_t *dtp = yypcb->pcb_hdl;

--- 87 unchanged lines hidden (view full) ---

385 *ofp = rfp;
386 *otype = rtype;
387}
388
389void
390dt_node_promote(dt_node_t *lp, dt_node_t *rp, dt_node_t *dnp)
391{
392 dt_type_promote(lp, rp, &dnp->dn_ctfp, &dnp->dn_type);
393 dt_node_type_assign(dnp, dnp->dn_ctfp, dnp->dn_type);
394 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
395}
396
397const char *
398dt_node_name(const dt_node_t *dnp, char *buf, size_t len)
399{
400 char n1[DT_TYPE_NAMELEN];
401 char n2[DT_TYPE_NAMELEN];

--- 252 unchanged lines hidden (view full) ---

654 "predefined minimum\n", dt_node_name(dnp, s, sizeof (s)),
655 dtrace_attr2str(attr, a, sizeof (a)));
656 }
657
658 dnp->dn_attr = attr;
659}
660
661void
662dt_node_type_assign(dt_node_t *dnp, ctf_file_t *fp, ctf_id_t type)
663{
664 ctf_id_t base = ctf_type_resolve(fp, type);
665 uint_t kind = ctf_type_kind(fp, base);
666 ctf_encoding_t e;
667
668 dnp->dn_flags &=
669 ~(DT_NF_SIGNED | DT_NF_REF | DT_NF_BITFIELD | DT_NF_USERLAND);
670

--- 15 unchanged lines hidden (view full) ---

686 if (kind == CTF_K_STRUCT || kind == CTF_K_UNION ||
687 kind == CTF_K_FORWARD ||
688 kind == CTF_K_ARRAY || kind == CTF_K_FUNCTION)
689 dnp->dn_flags |= DT_NF_REF;
690 else if (yypcb != NULL && fp == DT_DYN_CTFP(yypcb->pcb_hdl) &&
691 type == DT_DYN_TYPE(yypcb->pcb_hdl))
692 dnp->dn_flags |= DT_NF_REF;
693
694 dnp->dn_flags |= DT_NF_COOKED;
695 dnp->dn_ctfp = fp;
696 dnp->dn_type = type;
697}
698
699void
700dt_node_type_propagate(const dt_node_t *src, dt_node_t *dst)
701{

--- 21 unchanged lines hidden (view full) ---

723
724 return (dt_type_name(dnp->dn_ctfp, dnp->dn_type, buf, len));
725}
726
727size_t
728dt_node_type_size(const dt_node_t *dnp)
729{
730 ctf_id_t base;
731
732 if (dnp->dn_kind == DT_NODE_STRING)
733 return (strlen(dnp->dn_string) + 1);
734
735 if (dt_node_is_dynamic(dnp) && dnp->dn_ident != NULL)
736 return (dt_ident_size(dnp->dn_ident));
737
738 base = ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type);
739
740 if (ctf_type_kind(dnp->dn_ctfp, base) == CTF_K_FORWARD)
741 return (0);
742
743 return (ctf_type_size(dnp->dn_ctfp, dnp->dn_type));
744}
745
746/*
747 * Determine if the specified parse tree node references an identifier of the
748 * specified kind, and if so return a pointer to it; otherwise return NULL.
749 * This function resolves the identifier itself, following through any inlines.
750 */

--- 470 unchanged lines hidden (view full) ---

1221 else if (c == 'L' || c == 'l')
1222 i += 2;
1223 }
1224
1225 for (; i < sizeof (dtp->dt_ints) / sizeof (dtp->dt_ints[0]); i += n) {
1226 if (value <= dtp->dt_ints[i].did_limit) {
1227 dt_node_type_assign(dnp,
1228 dtp->dt_ints[i].did_ctfp,
1229 dtp->dt_ints[i].did_type);
1230
1231 /*
1232 * If a prefix character is present in macro text, add
1233 * in the corresponding operator node (see dt_lex.l).
1234 */
1235 switch (yyintprefix) {
1236 case '+':
1237 return (dt_node_op1(DT_TOK_IPOS, dnp));

--- 18 unchanged lines hidden (view full) ---

1256 dt_node_t *dnp;
1257
1258 if (string == NULL)
1259 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1260
1261 dnp = dt_node_alloc(DT_NODE_STRING);
1262 dnp->dn_op = DT_TOK_STRING;
1263 dnp->dn_string = string;
1264 dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
1265
1266 return (dnp);
1267}
1268
1269dt_node_t *
1270dt_node_ident(char *name)
1271{
1272 dt_ident_t *idp;

--- 59 unchanged lines hidden (view full) ---

1332 if (err != 0) {
1333 free(name);
1334 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
1335 }
1336
1337 dnp = dt_node_alloc(DT_NODE_TYPE);
1338 dnp->dn_op = DT_TOK_IDENT;
1339 dnp->dn_string = name;
1340 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
1341
1342 if (dtt.dtt_ctfp == dtp->dt_cdefs->dm_ctfp ||
1343 dtt.dtt_ctfp == dtp->dt_ddefs->dm_ctfp)
1344 dt_node_attr_assign(dnp, _dtrace_defattr);
1345 else
1346 dt_node_attr_assign(dnp, _dtrace_typattr);
1347
1348 return (dnp);
1349}

--- 226 unchanged lines hidden (view full) ---

1576 * If the pre-existing ident has its di_type set, propagate
1577 * the type by hand so as not to trigger a prototype check for
1578 * arrays (yet); otherwise we use dt_ident_cook() on the ident
1579 * to ensure it is fully initialized before looking at it.
1580 */
1581 bzero(&idn, sizeof (dt_node_t));
1582
1583 if (idp != NULL && idp->di_type != CTF_ERR)
1584 dt_node_type_assign(&idn, idp->di_ctfp, idp->di_type);
1585 else if (idp != NULL)
1586 (void) dt_ident_cook(&idn, idp, NULL);
1587
1588 if (assc) {
1589 if (class == DT_DC_THIS) {
1590 xyerror(D_DECL_LOCASSC, "associative arrays "
1591 "may not be declared as local variables:"
1592 " %s\n", dsp->ds_ident);

--- 193 unchanged lines hidden (view full) ---

1786 }
1787
1788 if (ctf_member_info(dtt.dtt_ctfp, type, name, &ctm) == CTF_ERR) {
1789 xyerror(D_UNKNOWN, "failed to determine offset of %s: %s\n",
1790 name, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
1791 }
1792
1793 bzero(&dn, sizeof (dn));
1794 dt_node_type_assign(&dn, dtt.dtt_ctfp, ctm.ctm_type);
1795
1796 if (dn.dn_flags & DT_NF_BITFIELD) {
1797 xyerror(D_OFFSETOF_BITFIELD,
1798 "cannot take offset of a bit-field: %s\n", name);
1799 }
1800
1801 return (dt_node_int(ctm.ctm_offset / NBBY));
1802}

--- 39 unchanged lines hidden (view full) ---

1842 size_t size = dt_node_type_size(cp);
1843
1844 if (size == 0) {
1845 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
1846 "operand of unknown size\n");
1847 }
1848
1849 dt_node_type_assign(cp, dtp->dt_ddefs->dm_ctfp,
1850 ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
1851
1852 cp->dn_kind = DT_NODE_INT;
1853 cp->dn_op = DT_TOK_INT;
1854 cp->dn_value = size;
1855
1856 return (cp);
1857 }
1858

--- 61 unchanged lines hidden (view full) ---

1920 uintmax_t r = rp->dn_value;
1921
1922 dnp = dt_node_int(0); /* allocate new integer node for result */
1923
1924 switch (op) {
1925 case DT_TOK_LOR:
1926 dnp->dn_value = l || r;
1927 dt_node_type_assign(dnp,
1928 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1929 break;
1930 case DT_TOK_LXOR:
1931 dnp->dn_value = (l != 0) ^ (r != 0);
1932 dt_node_type_assign(dnp,
1933 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1934 break;
1935 case DT_TOK_LAND:
1936 dnp->dn_value = l && r;
1937 dt_node_type_assign(dnp,
1938 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1939 break;
1940 case DT_TOK_BOR:
1941 dnp->dn_value = l | r;
1942 dt_node_promote(lp, rp, dnp);
1943 break;
1944 case DT_TOK_XOR:
1945 dnp->dn_value = l ^ r;
1946 dt_node_promote(lp, rp, dnp);
1947 break;
1948 case DT_TOK_BAND:
1949 dnp->dn_value = l & r;
1950 dt_node_promote(lp, rp, dnp);
1951 break;
1952 case DT_TOK_EQU:
1953 dnp->dn_value = l == r;
1954 dt_node_type_assign(dnp,
1955 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1956 break;
1957 case DT_TOK_NEQ:
1958 dnp->dn_value = l != r;
1959 dt_node_type_assign(dnp,
1960 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1961 break;
1962 case DT_TOK_LT:
1963 dt_node_promote(lp, rp, dnp);
1964 if (dnp->dn_flags & DT_NF_SIGNED)
1965 dnp->dn_value = (intmax_t)l < (intmax_t)r;
1966 else
1967 dnp->dn_value = l < r;
1968 dt_node_type_assign(dnp,
1969 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1970 break;
1971 case DT_TOK_LE:
1972 dt_node_promote(lp, rp, dnp);
1973 if (dnp->dn_flags & DT_NF_SIGNED)
1974 dnp->dn_value = (intmax_t)l <= (intmax_t)r;
1975 else
1976 dnp->dn_value = l <= r;
1977 dt_node_type_assign(dnp,
1978 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1979 break;
1980 case DT_TOK_GT:
1981 dt_node_promote(lp, rp, dnp);
1982 if (dnp->dn_flags & DT_NF_SIGNED)
1983 dnp->dn_value = (intmax_t)l > (intmax_t)r;
1984 else
1985 dnp->dn_value = l > r;
1986 dt_node_type_assign(dnp,
1987 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1988 break;
1989 case DT_TOK_GE:
1990 dt_node_promote(lp, rp, dnp);
1991 if (dnp->dn_flags & DT_NF_SIGNED)
1992 dnp->dn_value = (intmax_t)l >= (intmax_t)r;
1993 else
1994 dnp->dn_value = l >= r;
1995 dt_node_type_assign(dnp,
1996 DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
1997 break;
1998 case DT_TOK_LSH:
1999 dnp->dn_value = l << r;
2000 dt_node_type_propagate(lp, dnp);
2001 dt_node_attr_assign(rp,
2002 dt_attr_min(lp->dn_attr, rp->dn_attr));
2003 break;
2004 case DT_TOK_RSH:

--- 224 unchanged lines hidden (view full) ---

2229 }
2230
2231 /*
2232 * If the inline identifier is not defined, then create it with the
2233 * orphan flag set. We do not insert the identifier into dt_globals
2234 * until we have successfully cooked the right-hand expression, below.
2235 */
2236 dnp = dt_node_alloc(DT_NODE_INLINE);
2237 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2238 dt_node_attr_assign(dnp, _dtrace_defattr);
2239
2240 if (dt_node_is_void(dnp)) {
2241 xyerror(D_DECL_VOIDOBJ,
2242 "cannot declare void inline: %s\n", dsp->ds_ident);
2243 }
2244
2245 if (ctf_type_kind(dnp->dn_ctfp, ctf_type_resolve(

--- 138 unchanged lines hidden (view full) ---

2384 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2385 }
2386
2387 dnp = dt_node_alloc(DT_NODE_MEMBER);
2388 dnp->dn_membname = name;
2389 dnp->dn_membexpr = expr;
2390
2391 if (ddp != NULL)
2392 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2393
2394 return (dnp);
2395}
2396
2397dt_node_t *
2398dt_node_xlator(dt_decl_t *ddp, dt_decl_t *sdp, char *name, dt_node_t *members)
2399{
2400 dtrace_hdl_t *dtp = yypcb->pcb_hdl;

--- 14 unchanged lines hidden (view full) ---

2415 dt_decl_free(sdp);
2416
2417 if (edst != 0 || esrc != 0) {
2418 free(name);
2419 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
2420 }
2421
2422 bzero(&sn, sizeof (sn));
2423 dt_node_type_assign(&sn, src.dtt_ctfp, src.dtt_type);
2424
2425 bzero(&dn, sizeof (dn));
2426 dt_node_type_assign(&dn, dst.dtt_ctfp, dst.dtt_type);
2427
2428 if (dt_xlator_lookup(dtp, &sn, &dn, DT_XLATE_EXACT) != NULL) {
2429 xyerror(D_XLATE_REDECL,
2430 "translator from %s to %s has already been declared\n",
2431 dt_node_type_name(&sn, n1, sizeof (n1)),
2432 dt_node_type_name(&dn, n2, sizeof (n2)));
2433 }
2434

--- 229 unchanged lines hidden (view full) ---

2664 * have dynamic types and must be referenced using operator [].
2665 * This is handled explicitly by the code for DT_TOK_LBRAC.
2666 */
2667 if (idp->di_kind != DT_IDENT_ARRAY &&
2668 idp->di_kind != DT_IDENT_AGG)
2669 attr = dt_ident_cook(dnp, idp, NULL);
2670 else {
2671 dt_node_type_assign(dnp,
2672 DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
2673 attr = idp->di_attr;
2674 }
2675
2676 free(dnp->dn_string);
2677 dnp->dn_string = NULL;
2678 dnp->dn_kind = dnkind;
2679 dnp->dn_ident = idp;
2680 dnp->dn_flags |= DT_NF_LVALUE;

--- 59 unchanged lines hidden (view full) ---

2740 idp->di_type = dtt.dtt_type;
2741
2742 free(dnp->dn_string);
2743 dnp->dn_string = NULL;
2744 dnp->dn_kind = DT_NODE_SYM;
2745 dnp->dn_ident = idp;
2746 dnp->dn_flags |= DT_NF_LVALUE;
2747
2748 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
2749 dt_node_attr_assign(dnp, _dtrace_symattr);
2750
2751 if (uref) {
2752 idp->di_flags |= DT_IDFLG_USER;
2753 dnp->dn_flags |= DT_NF_USERLAND;
2754 }
2755
2756 } else if (scope == DTRACE_OBJ_EXEC && create == B_TRUE) {

--- 31 unchanged lines hidden (view full) ---

2788 * have dynamic types and must be referenced using operator [].
2789 * This is handled explicitly by the code for DT_TOK_LBRAC.
2790 */
2791 if (idp->di_kind != DT_IDENT_ARRAY &&
2792 idp->di_kind != DT_IDENT_AGG)
2793 attr = dt_ident_cook(dnp, idp, NULL);
2794 else {
2795 dt_node_type_assign(dnp,
2796 DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
2797 attr = idp->di_attr;
2798 }
2799
2800 free(dnp->dn_string);
2801 dnp->dn_string = NULL;
2802 dnp->dn_kind = dnkind;
2803 dnp->dn_ident = idp;
2804 dnp->dn_flags |= DT_NF_LVALUE | DT_NF_WRITABLE;

--- 86 unchanged lines hidden (view full) ---

2891
2892 cp = dnp->dn_child = dt_node_cook(cp, 0); /* don't set idflags yet */
2893
2894 if (cp->dn_kind == DT_NODE_VAR && dt_ident_unref(cp->dn_ident)) {
2895 if (dt_type_lookup("int64_t", &dtt) != 0)
2896 xyerror(D_TYPE_ERR, "failed to lookup int64_t\n");
2897
2898 dt_ident_type_assign(cp->dn_ident, dtt.dtt_ctfp, dtt.dtt_type);
2899 dt_node_type_assign(cp, dtt.dtt_ctfp, dtt.dtt_type);
2900 }
2901
2902 if (cp->dn_kind == DT_NODE_VAR)
2903 cp->dn_ident->di_flags |= idflags;
2904
2905 switch (dnp->dn_op) {
2906 case DT_TOK_DEREF:
2907 /*
2908 * If the deref operator is applied to a translated pointer,
2909 * we set our output type to the output of the translation.
2910 */
2911 if ((idp = dt_node_resolve(cp, DT_IDENT_XLPTR)) != NULL) {
2912 dt_xlator_t *dxp = idp->di_data;
2913
2914 dnp->dn_ident = &dxp->dx_souid;
2915 dt_node_type_assign(dnp,
2916 dnp->dn_ident->di_ctfp, dnp->dn_ident->di_type);
2917 break;
2918 }
2919
2920 type = ctf_type_resolve(cp->dn_ctfp, cp->dn_type);
2921 kind = ctf_type_kind(cp->dn_ctfp, type);
2922
2923 if (kind == CTF_K_ARRAY) {
2924 if (ctf_array_info(cp->dn_ctfp, type, &r) != 0) {
2925 dtp->dt_ctferr = ctf_errno(cp->dn_ctfp);
2926 longjmp(yypcb->pcb_jmpbuf, EDT_CTF);
2927 } else
2928 type = r.ctr_contents;
2929 } else if (kind == CTF_K_POINTER) {
2930 type = ctf_type_reference(cp->dn_ctfp, type);
2931 } else {
2932 xyerror(D_DEREF_NONPTR,
2933 "cannot dereference non-pointer type\n");
2934 }
2935
2936 dt_node_type_assign(dnp, cp->dn_ctfp, type);
2937 base = ctf_type_resolve(cp->dn_ctfp, type);
2938 kind = ctf_type_kind(cp->dn_ctfp, base);
2939
2940 if (kind == CTF_K_INTEGER && ctf_type_encoding(cp->dn_ctfp,
2941 base, &e) == 0 && IS_VOID(e)) {
2942 xyerror(D_DEREF_VOID,
2943 "cannot dereference pointer to void\n");
2944 }

--- 40 unchanged lines hidden (view full) ---

2985 dt_node_type_propagate(cp, dnp); /* see K&R[A7.4.4-6] */
2986 break;
2987
2988 case DT_TOK_LNEG:
2989 if (!dt_node_is_scalar(cp)) {
2990 xyerror(D_OP_SCALAR, "operator %s requires an operand "
2991 "of scalar type\n", opstr(dnp->dn_op));
2992 }
2993 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
2994 break;
2995
2996 case DT_TOK_ADDROF:
2997 if (cp->dn_kind == DT_NODE_VAR || cp->dn_kind == DT_NODE_AGG) {
2998 xyerror(D_ADDROF_VAR,
2999 "cannot take address of dynamic variable\n");
3000 }
3001

--- 16 unchanged lines hidden (view full) ---

3018 dtt.dtt_ctfp = cp->dn_ctfp;
3019 dtt.dtt_type = cp->dn_type;
3020
3021 if (dt_type_pointer(&dtt) == -1) {
3022 xyerror(D_TYPE_ERR, "cannot find type for \"&\": %s*\n",
3023 dt_node_type_name(cp, n, sizeof (n)));
3024 }
3025
3026 dt_node_type_assign(dnp, dtt.dtt_ctfp, dtt.dtt_type);
3027
3028 if (cp->dn_flags & DT_NF_USERLAND)
3029 dnp->dn_flags |= DT_NF_USERLAND;
3030 break;
3031
3032 case DT_TOK_SIZEOF:
3033 if (cp->dn_flags & DT_NF_BITFIELD) {
3034 xyerror(D_SIZEOF_BITFIELD,
3035 "cannot apply sizeof to a bit-field\n");
3036 }
3037
3038 if (dt_node_sizeof(cp) == 0) {
3039 xyerror(D_SIZEOF_TYPE, "cannot apply sizeof to an "
3040 "operand of unknown size\n");
3041 }
3042
3043 dt_node_type_assign(dnp, dtp->dt_ddefs->dm_ctfp,
3044 ctf_lookup_by_name(dtp->dt_ddefs->dm_ctfp, "size_t"));
3045 break;
3046
3047 case DT_TOK_STRINGOF:
3048 if (!dt_node_is_scalar(cp) && !dt_node_is_pointer(cp) &&
3049 !dt_node_is_strcompat(cp)) {
3050 xyerror(D_STRINGOF_TYPE,
3051 "cannot apply stringof to a value of type %s\n",
3052 dt_node_type_name(cp, n, sizeof (n)));
3053 }
3054 dt_node_type_assign(dnp, DT_STR_CTFP(dtp), DT_STR_TYPE(dtp));
3055 break;
3056
3057 case DT_TOK_PREINC:
3058 case DT_TOK_POSTINC:
3059 case DT_TOK_PREDEC:
3060 case DT_TOK_POSTDEC:
3061 if (dt_node_is_scalar(cp) == 0) {
3062 xyerror(D_OP_SCALAR, "operator %s requires operand of "

--- 176 unchanged lines hidden (view full) ---

3239 lp = dnp->dn_left = dt_node_cook(lp, DT_IDFLG_REF);
3240 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3241
3242 if (!dt_node_is_scalar(lp) || !dt_node_is_scalar(rp)) {
3243 xyerror(D_OP_SCALAR, "operator %s requires operands "
3244 "of scalar type\n", opstr(op));
3245 }
3246
3247 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
3248 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3249 break;
3250
3251 case DT_TOK_LT:
3252 case DT_TOK_LE:
3253 case DT_TOK_GT:
3254 case DT_TOK_GE:
3255 case DT_TOK_EQU:

--- 27 unchanged lines hidden (view full) ---

3283
3284 free(rp->dn_string);
3285 rp->dn_string = NULL;
3286 rp->dn_kind = DT_NODE_INT;
3287 rp->dn_flags |= DT_NF_COOKED;
3288 rp->dn_op = DT_TOK_INT;
3289 rp->dn_value = (intmax_t)val;
3290
3291 dt_node_type_assign(rp, lp->dn_ctfp, lp->dn_type);
3292 dt_node_attr_assign(rp, _dtrace_symattr);
3293 }
3294
3295 rp = dnp->dn_right = dt_node_cook(rp, DT_IDFLG_REF);
3296
3297 /*
3298 * The rules for type checking for the relational operators are
3299 * described in the ANSI-C spec (see K&R[A7.9-10]). We perform

--- 15 unchanged lines hidden (view full) ---

3315 /*EMPTY*/;
3316 else if (dt_node_is_ptrcompat(lp, rp, NULL, NULL) == 0) {
3317 xyerror(D_OP_INCOMPAT, "operands have "
3318 "incompatible types: \"%s\" %s \"%s\"\n",
3319 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3320 dt_node_type_name(rp, n2, sizeof (n2)));
3321 }
3322
3323 dt_node_type_assign(dnp, DT_INT_CTFP(dtp), DT_INT_TYPE(dtp));
3324 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3325 break;
3326
3327 case DT_TOK_ADD:
3328 case DT_TOK_SUB: {
3329 /*
3330 * The rules for type checking for the additive operators are
3331 * described in the ANSI-C spec (see K&R[A7.7]). Pointers and

--- 31 unchanged lines hidden (view full) ---

3363 uref = 0;
3364 } else {
3365 xyerror(D_OP_INCOMPAT, "operands have incompatible "
3366 "types: \"%s\" %s \"%s\"\n",
3367 dt_node_type_name(lp, n1, sizeof (n1)), opstr(op),
3368 dt_node_type_name(rp, n2, sizeof (n2)));
3369 }
3370
3371 dt_node_type_assign(dnp, ctfp, type);
3372 dt_node_attr_assign(dnp, dt_attr_min(lp->dn_attr, rp->dn_attr));
3373
3374 if (uref)
3375 dnp->dn_flags |= DT_NF_USERLAND;
3376 break;
3377 }
3378
3379 case DT_TOK_OR_EQ:

--- 124 unchanged lines hidden (view full) ---

3504
3505 /*
3506 * If the left-hand side of an assignment statement is a virgin
3507 * variable created by this compilation pass, reset the type of
3508 * this variable to the type of the right-hand side.
3509 */
3510 if (lp->dn_kind == DT_NODE_VAR &&
3511 dt_ident_unref(lp->dn_ident)) {
3512 dt_node_type_assign(lp, ctfp, type);
3513 dt_ident_type_assign(lp->dn_ident, ctfp, type);
3514
3515 if (uref) {
3516 lp->dn_flags |= DT_NF_USERLAND;
3517 lp->dn_ident->di_flags |= DT_IDFLG_USER;
3518 }
3519 }
3520

--- 197 unchanged lines hidden (view full) ---

3718 xyerror(D_TYPE_MEMBER,
3719 "%s is not a member of %s\n", rp->dn_string,
3720 ctf_type_name(ctfp, type, n1, sizeof (n1)));
3721 }
3722
3723 type = ctf_type_resolve(ctfp, m.ctm_type);
3724 kind = ctf_type_kind(ctfp, type);
3725
3726 dt_node_type_assign(dnp, ctfp, m.ctm_type);
3727 dt_node_attr_assign(dnp, lp->dn_attr);
3728
3729 if (op == DT_TOK_PTR && (kind != CTF_K_ARRAY ||
3730 dt_node_is_string(dnp)))
3731 dnp->dn_flags |= DT_NF_LVALUE; /* see K&R[A7.3.3] */
3732
3733 if (op == DT_TOK_DOT && (lp->dn_flags & DT_NF_LVALUE) &&
3734 (kind != CTF_K_ARRAY || dt_node_is_string(dnp)))

--- 109 unchanged lines hidden (view full) ---

3844 if (dxp == NULL) {
3845 xyerror(D_XLATE_NONE,
3846 "cannot translate from \"%s\" to \"%s\"\n",
3847 dt_node_type_name(rp, n1, sizeof (n1)),
3848 dt_node_type_name(lp, n2, sizeof (n2)));
3849 }
3850
3851 dnp->dn_ident = dt_xlator_ident(dxp, lp->dn_ctfp, lp->dn_type);
3852 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
3853 dt_node_attr_assign(dnp,
3854 dt_attr_min(rp->dn_attr, dnp->dn_ident->di_attr));
3855 break;
3856 }
3857
3858 case DT_TOK_LPAR: {
3859 ctf_id_t ltype, rtype;
3860 uint_t lkind, rkind;

--- 148 unchanged lines hidden (view full) ---

4009 "operator ?: operands must have compatible types\n");
4010 }
4011
4012 if (dt_node_is_actfunc(lp) || dt_node_is_actfunc(rp)) {
4013 xyerror(D_OP_ACT, "action cannot be "
4014 "used in a conditional context\n");
4015 }
4016
4017 dt_node_type_assign(dnp, ctfp, type);
4018 dt_node_attr_assign(dnp, dt_attr_min(dnp->dn_expr->dn_attr,
4019 dt_attr_min(lp->dn_attr, rp->dn_attr)));
4020
4021 return (dnp);
4022}
4023
4024static dt_node_t *
4025dt_cook_statement(dt_node_t *dnp, uint_t idflags)

--- 16 unchanged lines hidden (view full) ---

4042{
4043 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
4044
4045 if (dnp->dn_aggfun != NULL) {
4046 dnp->dn_aggfun = dt_node_cook(dnp->dn_aggfun, DT_IDFLG_REF);
4047 dt_node_attr_assign(dnp, dt_ident_cook(dnp,
4048 dnp->dn_ident, &dnp->dn_aggtup));
4049 } else {
4050 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
4051 dt_node_attr_assign(dnp, dnp->dn_ident->di_attr);
4052 }
4053
4054 return (dnp);
4055}
4056
4057/*
4058 * Since D permits new variable identifiers to be instantiated in any program

--- 185 unchanged lines hidden (view full) ---

4244 mnp->dn_membname, &ctm) == CTF_ERR) {
4245 xyerror(D_XLATE_MEMB,
4246 "translator member %s is not a member of %s\n",
4247 mnp->dn_membname, ctf_type_name(dxp->dx_dst_ctfp,
4248 dxp->dx_dst_type, n1, sizeof (n1)));
4249 }
4250
4251 (void) dt_node_cook(mnp, DT_IDFLG_REF);
4252 dt_node_type_assign(mnp, dxp->dx_dst_ctfp, ctm.ctm_type);
4253 attr = dt_attr_min(attr, mnp->dn_attr);
4254
4255 if (dt_node_is_argcompat(mnp, mnp->dn_membexpr) == 0) {
4256 xyerror(D_XLATE_INCOMPAT,
4257 "translator member %s definition uses "
4258 "incompatible types: \"%s\" = \"%s\"\n",
4259 mnp->dn_membname,
4260 dt_node_type_name(mnp, n1, sizeof (n1)),
4261 dt_node_type_name(mnp->dn_membexpr,
4262 n2, sizeof (n2)));
4263 }
4264 }
4265
4266 dt_idstack_pop(&yypcb->pcb_globals, dxp->dx_locals);
4267
4268 dxp->dx_souid.di_attr = attr;
4269 dxp->dx_ptrid.di_attr = attr;
4270
4271 dt_node_type_assign(dnp, DT_DYN_CTFP(dtp), DT_DYN_TYPE(dtp));
4272 dt_node_attr_assign(dnp, _dtrace_defattr);
4273
4274 return (dnp);
4275}
4276
4277static void
4278dt_node_provider_cmp_argv(dt_provider_t *pvp, dt_node_t *pnp, const char *kind,
4279 uint_t old_argc, dt_node_t *old_argv, uint_t new_argc, dt_node_t *new_argv)

--- 276 unchanged lines hidden (view full) ---

4556 tp->dtdt_kind = DIF_TYPE_STRING;
4557 tp->dtdt_ckind = CTF_K_UNKNOWN;
4558 } else {
4559 tp->dtdt_kind = DIF_TYPE_CTF;
4560 tp->dtdt_ckind = ctf_type_kind(dnp->dn_ctfp,
4561 ctf_type_resolve(dnp->dn_ctfp, dnp->dn_type));
4562 }
4563
4564 tp->dtdt_flags = (dnp->dn_flags & DT_NF_REF) ? DIF_TF_BYREF : 0;
4565 tp->dtdt_pad = 0;
4566 tp->dtdt_size = ctf_type_size(dnp->dn_ctfp, dnp->dn_type);
4567}
4568
4569void
4570dt_node_printr(dt_node_t *dnp, FILE *fp, int depth)
4571{
4572 char n[DT_TYPE_NAMELEN], buf[BUFSIZ], a[8];

--- 360 unchanged lines hidden ---