Print this page
4210 unsigned unsigned short short is valid in dtrace
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Eric Diven <eric.diven@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libdtrace/common/dt_decl.c
+++ new/usr/src/lib/libdtrace/common/dt_decl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright (c) 2012 by Delphix. All rights reserved.
24 + * Copyright (c) 2013 by Delphix. All rights reserved.
25 25 */
26 26
27 27 #include <strings.h>
28 28 #include <stdlib.h>
29 29 #include <limits.h>
30 30 #include <alloca.h>
31 31 #include <assert.h>
32 32
33 33 #include <dt_decl.h>
34 34 #include <dt_parser.h>
35 35 #include <dt_module.h>
36 36 #include <dt_impl.h>
37 37
38 38 static dt_decl_t *
39 39 dt_decl_check(dt_decl_t *ddp)
40 40 {
41 41 if (ddp->dd_kind == CTF_K_UNKNOWN)
42 42 return (ddp); /* nothing to check if the type is not yet set */
43 43
44 44 if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "char") == 0 &&
45 45 (ddp->dd_attr & (DT_DA_SHORT | DT_DA_LONG | DT_DA_LONGLONG))) {
46 46 xyerror(D_DECL_CHARATTR, "invalid type declaration: short and "
47 47 "long may not be used with char type\n");
48 48 }
49 49
50 50 if (ddp->dd_name != NULL && strcmp(ddp->dd_name, "void") == 0 &&
51 51 (ddp->dd_attr & (DT_DA_SHORT | DT_DA_LONG | DT_DA_LONGLONG |
52 52 (DT_DA_SIGNED | DT_DA_UNSIGNED)))) {
53 53 xyerror(D_DECL_VOIDATTR, "invalid type declaration: attributes "
54 54 "may not be used with void type\n");
55 55 }
56 56
57 57 if (ddp->dd_kind != CTF_K_INTEGER &&
58 58 (ddp->dd_attr & (DT_DA_SIGNED | DT_DA_UNSIGNED))) {
59 59 xyerror(D_DECL_SIGNINT, "invalid type declaration: signed and "
60 60 "unsigned may only be used with integer type\n");
61 61 }
62 62
63 63 if (ddp->dd_kind != CTF_K_INTEGER && ddp->dd_kind != CTF_K_FLOAT &&
64 64 (ddp->dd_attr & (DT_DA_LONG | DT_DA_LONGLONG))) {
65 65 xyerror(D_DECL_LONGINT, "invalid type declaration: long and "
66 66 "long long may only be used with integer or "
67 67 "floating-point type\n");
68 68 }
69 69
70 70 return (ddp);
71 71 }
72 72
73 73 dt_decl_t *
74 74 dt_decl_alloc(ushort_t kind, char *name)
75 75 {
76 76 dt_decl_t *ddp = malloc(sizeof (dt_decl_t));
77 77
78 78 if (ddp == NULL)
79 79 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
80 80
81 81 ddp->dd_kind = kind;
82 82 ddp->dd_attr = 0;
83 83 ddp->dd_ctfp = NULL;
84 84 ddp->dd_type = CTF_ERR;
85 85 ddp->dd_name = name;
86 86 ddp->dd_node = NULL;
87 87 ddp->dd_next = NULL;
88 88
89 89 return (ddp);
90 90 }
91 91
92 92 void
93 93 dt_decl_free(dt_decl_t *ddp)
94 94 {
95 95 dt_decl_t *ndp;
96 96
97 97 for (; ddp != NULL; ddp = ndp) {
98 98 ndp = ddp->dd_next;
99 99 free(ddp->dd_name);
100 100 dt_node_list_free(&ddp->dd_node);
101 101 free(ddp);
102 102 }
103 103 }
104 104
105 105 void
106 106 dt_decl_reset(void)
107 107 {
108 108 dt_scope_t *dsp = &yypcb->pcb_dstack;
109 109 dt_decl_t *ddp = dsp->ds_decl;
110 110
111 111 while (ddp->dd_next != NULL) {
112 112 dsp->ds_decl = ddp->dd_next;
113 113 ddp->dd_next = NULL;
114 114 dt_decl_free(ddp);
115 115 ddp = dsp->ds_decl;
116 116 }
117 117 }
118 118
119 119 dt_decl_t *
120 120 dt_decl_push(dt_decl_t *ddp)
121 121 {
122 122 dt_scope_t *dsp = &yypcb->pcb_dstack;
123 123 dt_decl_t *top = dsp->ds_decl;
124 124
125 125 if (top != NULL &&
126 126 top->dd_kind == CTF_K_UNKNOWN && top->dd_name == NULL) {
127 127 top->dd_kind = CTF_K_INTEGER;
128 128 (void) dt_decl_check(top);
129 129 }
130 130
131 131 assert(ddp->dd_next == NULL);
132 132 ddp->dd_next = top;
133 133 dsp->ds_decl = ddp;
134 134
135 135 return (ddp);
136 136 }
137 137
138 138 dt_decl_t *
139 139 dt_decl_pop(void)
140 140 {
141 141 dt_scope_t *dsp = &yypcb->pcb_dstack;
142 142 dt_decl_t *ddp = dt_decl_top();
143 143
144 144 dsp->ds_decl = NULL;
145 145 free(dsp->ds_ident);
146 146 dsp->ds_ident = NULL;
147 147 dsp->ds_ctfp = NULL;
148 148 dsp->ds_type = CTF_ERR;
149 149 dsp->ds_class = DT_DC_DEFAULT;
150 150 dsp->ds_enumval = -1;
151 151
152 152 return (ddp);
153 153 }
154 154
155 155 dt_decl_t *
156 156 dt_decl_pop_param(char **idp)
157 157 {
158 158 dt_scope_t *dsp = &yypcb->pcb_dstack;
159 159
160 160 if (dsp->ds_class != DT_DC_DEFAULT && dsp->ds_class != DT_DC_REGISTER) {
161 161 xyerror(D_DECL_PARMCLASS, "inappropriate storage class "
162 162 "for function or associative array parameter\n");
163 163 }
164 164
165 165 if (idp != NULL && dt_decl_top() != NULL) {
166 166 *idp = dsp->ds_ident;
167 167 dsp->ds_ident = NULL;
168 168 }
169 169
170 170 return (dt_decl_pop());
171 171 }
172 172
173 173 dt_decl_t *
174 174 dt_decl_top(void)
175 175 {
176 176 dt_decl_t *ddp = yypcb->pcb_dstack.ds_decl;
177 177
178 178 if (ddp == NULL)
179 179 longjmp(yypcb->pcb_jmpbuf, EDT_NODECL);
180 180
181 181 if (ddp->dd_kind == CTF_K_UNKNOWN && ddp->dd_name == NULL) {
182 182 ddp->dd_kind = CTF_K_INTEGER;
183 183 (void) dt_decl_check(ddp);
184 184 }
185 185
186 186 return (ddp);
187 187 }
188 188
189 189 dt_decl_t *
190 190 dt_decl_ident(char *name)
191 191 {
192 192 dt_scope_t *dsp = &yypcb->pcb_dstack;
193 193 dt_decl_t *ddp = dsp->ds_decl;
194 194
195 195 if (dsp->ds_ident != NULL) {
196 196 free(name);
197 197 xyerror(D_DECL_IDENT, "old-style declaration or "
198 198 "incorrect type specified\n");
199 199 }
200 200
201 201 dsp->ds_ident = name;
202 202
203 203 if (ddp == NULL)
204 204 ddp = dt_decl_push(dt_decl_alloc(CTF_K_UNKNOWN, NULL));
205 205
206 206 return (ddp);
207 207 }
208 208
209 209 void
210 210 dt_decl_class(dt_dclass_t class)
211 211 {
212 212 dt_scope_t *dsp = &yypcb->pcb_dstack;
213 213
214 214 if (dsp->ds_class != DT_DC_DEFAULT) {
215 215 xyerror(D_DECL_CLASS, "only one storage class allowed "
216 216 "in a declaration\n");
217 217 }
218 218
219 219 dsp->ds_class = class;
220 220 }
221 221
222 222 /*
223 223 * Set the kind and name of the current declaration. If none is allocated,
224 224 * make a new decl and push it on to the top of our stack. If the name or kind
225 225 * is already set for the current decl, then we need to fail this declaration.
226 226 * This can occur because too many types were given (e.g. "int int"), etc.
227 227 */
228 228 dt_decl_t *
229 229 dt_decl_spec(ushort_t kind, char *name)
230 230 {
231 231 dt_decl_t *ddp = yypcb->pcb_dstack.ds_decl;
232 232
233 233 if (ddp == NULL)
234 234 return (dt_decl_push(dt_decl_alloc(kind, name)));
235 235
236 236 /*
237 237 * If we already have a type name specified and we see another type
238 238 * name, this is an error if the declaration is a typedef. If the
239 239 * declaration is not a typedef, then the user may be trying to declare
240 240 * a variable whose name has been returned by lex as a TNAME token:
241 241 * call dt_decl_ident() as if the grammar's IDENT rule was matched.
242 242 */
243 243 if (ddp->dd_name != NULL && kind == CTF_K_TYPEDEF) {
244 244 if (yypcb->pcb_dstack.ds_class != DT_DC_TYPEDEF)
245 245 return (dt_decl_ident(name));
246 246 xyerror(D_DECL_IDRED, "identifier redeclared: %s\n", name);
247 247 }
248 248
249 249 if (ddp->dd_name != NULL || ddp->dd_kind != CTF_K_UNKNOWN)
250 250 xyerror(D_DECL_COMBO, "invalid type combination\n");
251 251
252 252 ddp->dd_kind = kind;
253 253 ddp->dd_name = name;
254 254
255 255 return (dt_decl_check(ddp));
256 256 }
257 257
258 258 dt_decl_t *
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
259 259 dt_decl_attr(ushort_t attr)
260 260 {
261 261 dt_decl_t *ddp = yypcb->pcb_dstack.ds_decl;
262 262
263 263 if (ddp == NULL) {
264 264 ddp = dt_decl_push(dt_decl_alloc(CTF_K_UNKNOWN, NULL));
265 265 ddp->dd_attr = attr;
266 266 return (ddp);
267 267 }
268 268
269 + if ((attr & DT_DA_LONG) && (ddp->dd_attr & DT_DA_LONGLONG)) {
270 + xyerror(D_DECL_COMBO, "the attribute 'long' may only "
271 + "be used at most twice in a declaration");
272 + }
273 +
274 + if ((attr & DT_DA_SHORT) && (ddp->dd_attr & DT_DA_SHORT)) {
275 + xyerror(D_DECL_COMBO, "the attribute 'short' may only be "
276 + "used at most once in a declaration");
277 + }
278 +
279 + if ((attr & DT_DA_SIGNED) && (ddp->dd_attr & DT_DA_SIGNED)) {
280 + xyerror(D_DECL_COMBO, "the attribute 'signed' may only be "
281 + "used at most once in a declaration");
282 + }
283 +
284 + if ((attr & DT_DA_UNSIGNED) && (ddp->dd_attr & DT_DA_UNSIGNED)) {
285 + xyerror(D_DECL_COMBO, "the attribute 'unsigned' may only be "
286 + "used at most once in a declaration");
287 + }
288 +
269 289 if (attr == DT_DA_LONG && (ddp->dd_attr & DT_DA_LONG)) {
270 290 ddp->dd_attr &= ~DT_DA_LONG;
271 291 attr = DT_DA_LONGLONG;
272 292 }
273 293
274 294 ddp->dd_attr |= attr;
275 295 return (dt_decl_check(ddp));
276 296 }
277 297
278 298 /*
279 299 * Examine the list of formal parameters 'flist' and determine if the formal
280 300 * name fnp->dn_string is defined in this list (B_TRUE) or not (B_FALSE).
281 301 * If 'fnp' is in 'flist', do not search beyond 'fnp' itself in 'flist'.
282 302 */
283 303 static int
284 304 dt_decl_protoform(dt_node_t *fnp, dt_node_t *flist)
285 305 {
286 306 dt_node_t *dnp;
287 307
288 308 for (dnp = flist; dnp != fnp && dnp != NULL; dnp = dnp->dn_list) {
289 309 if (dnp->dn_string != NULL &&
290 310 strcmp(dnp->dn_string, fnp->dn_string) == 0)
291 311 return (B_TRUE);
292 312 }
293 313
294 314 return (B_FALSE);
295 315 }
296 316
297 317 /*
298 318 * Common code for parsing array, function, and probe definition prototypes.
299 319 * The prototype node list is specified as 'plist'. The formal prototype
300 320 * against which to compare the prototype is specified as 'flist'. If plist
301 321 * and flist are the same, we require that named parameters are unique. If
302 322 * plist and flist are different, we require that named parameters in plist
303 323 * match a name that is present in flist.
304 324 */
305 325 int
306 326 dt_decl_prototype(dt_node_t *plist,
307 327 dt_node_t *flist, const char *kind, uint_t flags)
308 328 {
309 329 char n[DT_TYPE_NAMELEN];
310 330 int is_void, v = 0, i = 1;
311 331 int form = plist != flist;
312 332 dt_node_t *dnp;
313 333
314 334 for (dnp = plist; dnp != NULL; dnp = dnp->dn_list, i++) {
315 335
316 336 if (dnp->dn_type == CTF_ERR && !(flags & DT_DP_VARARGS)) {
317 337 dnerror(dnp, D_DECL_PROTO_VARARGS, "%s prototype may "
318 338 "not use a variable-length argument list\n", kind);
319 339 }
320 340
321 341 if (dt_node_is_dynamic(dnp) && !(flags & DT_DP_DYNAMIC)) {
322 342 dnerror(dnp, D_DECL_PROTO_TYPE, "%s prototype may not "
323 343 "use parameter of type %s: %s, parameter #%d\n",
324 344 kind, dt_node_type_name(dnp, n, sizeof (n)),
325 345 dnp->dn_string ? dnp->dn_string : "(anonymous)", i);
326 346 }
327 347
328 348 is_void = dt_node_is_void(dnp);
329 349 v += is_void;
330 350
331 351 if (is_void && !(flags & DT_DP_VOID)) {
332 352 dnerror(dnp, D_DECL_PROTO_TYPE, "%s prototype may not "
333 353 "use parameter of type %s: %s, parameter #%d\n",
334 354 kind, dt_node_type_name(dnp, n, sizeof (n)),
335 355 dnp->dn_string ? dnp->dn_string : "(anonymous)", i);
336 356 }
337 357
338 358 if (is_void && dnp->dn_string != NULL) {
339 359 dnerror(dnp, D_DECL_PROTO_NAME, "void parameter may "
340 360 "not have a name: %s\n", dnp->dn_string);
341 361 }
342 362
343 363 if (dnp->dn_string != NULL &&
344 364 dt_decl_protoform(dnp, flist) != form) {
345 365 dnerror(dnp, D_DECL_PROTO_FORM, "parameter is "
346 366 "%s declared in %s prototype: %s, parameter #%d\n",
347 367 form ? "not" : "already", kind, dnp->dn_string, i);
348 368 }
349 369
350 370 if (dnp->dn_string == NULL &&
351 371 !is_void && !(flags & DT_DP_ANON)) {
352 372 dnerror(dnp, D_DECL_PROTO_NAME, "parameter declaration "
353 373 "requires a name: parameter #%d\n", i);
354 374 }
355 375 }
356 376
357 377 if (v != 0 && plist->dn_list != NULL)
358 378 xyerror(D_DECL_PROTO_VOID, "void must be sole parameter\n");
359 379
360 380 return (v ? 0 : i - 1); /* return zero if sole parameter is 'void' */
361 381 }
362 382
363 383 dt_decl_t *
364 384 dt_decl_array(dt_node_t *dnp)
365 385 {
366 386 dt_decl_t *ddp = dt_decl_push(dt_decl_alloc(CTF_K_ARRAY, NULL));
367 387 dt_scope_t *dsp = &yypcb->pcb_dstack;
368 388 dt_decl_t *ndp = ddp;
369 389
370 390 /*
371 391 * After pushing the array on to the decl stack, scan ahead for multi-
372 392 * dimensional array declarations and push the current decl to the
373 393 * bottom to match the resulting CTF type tree and data layout. Refer
374 394 * to the comments in dt_decl_type() and ISO C 6.5.2.1 for more info.
375 395 */
376 396 while (ndp->dd_next != NULL && ndp->dd_next->dd_kind == CTF_K_ARRAY)
377 397 ndp = ndp->dd_next; /* skip to bottom-most array declaration */
378 398
379 399 if (ndp != ddp) {
380 400 if (dnp != NULL && dnp->dn_kind == DT_NODE_TYPE) {
381 401 xyerror(D_DECL_DYNOBJ,
382 402 "cannot declare array of associative arrays\n");
383 403 }
384 404 dsp->ds_decl = ddp->dd_next;
385 405 ddp->dd_next = ndp->dd_next;
386 406 ndp->dd_next = ddp;
387 407 }
388 408
389 409 if (ddp->dd_next->dd_name != NULL &&
390 410 strcmp(ddp->dd_next->dd_name, "void") == 0)
391 411 xyerror(D_DECL_VOIDOBJ, "cannot declare array of void\n");
392 412
393 413 if (dnp != NULL && dnp->dn_kind != DT_NODE_TYPE) {
394 414 dnp = ddp->dd_node = dt_node_cook(dnp, DT_IDFLG_REF);
395 415
396 416 if (dt_node_is_posconst(dnp) == 0) {
397 417 xyerror(D_DECL_ARRSUB, "positive integral constant "
398 418 "expression or tuple signature expected as "
399 419 "array declaration subscript\n");
400 420 }
401 421
402 422 if (dnp->dn_value > UINT_MAX)
403 423 xyerror(D_DECL_ARRBIG, "array dimension too big\n");
404 424
405 425 } else if (dnp != NULL) {
406 426 ddp->dd_node = dnp;
407 427 (void) dt_decl_prototype(dnp, dnp, "array", DT_DP_ANON);
408 428 }
409 429
410 430 return (ddp);
411 431 }
412 432
413 433 /*
414 434 * When a function is declared, we need to fudge the decl stack a bit if the
415 435 * declaration uses the function pointer (*)() syntax. In this case, the
416 436 * dt_decl_func() call occurs *after* the dt_decl_ptr() call, even though the
417 437 * resulting type is "pointer to function". To make the pointer land on top,
418 438 * we check to see if 'pdp' is non-NULL and a pointer. If it is, we search
419 439 * backward for a decl tagged with DT_DA_PAREN, and if one is found, the func
420 440 * decl is inserted behind this node in the decl list instead of at the top.
421 441 * In all cases, the func decl's dd_next pointer is set to the decl chain
422 442 * for the function's return type and the function parameter list is discarded.
423 443 */
424 444 dt_decl_t *
425 445 dt_decl_func(dt_decl_t *pdp, dt_node_t *dnp)
426 446 {
427 447 dt_decl_t *ddp = dt_decl_alloc(CTF_K_FUNCTION, NULL);
428 448
429 449 ddp->dd_node = dnp;
430 450
431 451 (void) dt_decl_prototype(dnp, dnp, "function",
432 452 DT_DP_VARARGS | DT_DP_VOID | DT_DP_ANON);
433 453
434 454 if (pdp == NULL || pdp->dd_kind != CTF_K_POINTER)
435 455 return (dt_decl_push(ddp));
436 456
437 457 while (pdp->dd_next != NULL && !(pdp->dd_next->dd_attr & DT_DA_PAREN))
438 458 pdp = pdp->dd_next;
439 459
440 460 if (pdp->dd_next == NULL)
441 461 return (dt_decl_push(ddp));
442 462
443 463 ddp->dd_next = pdp->dd_next;
444 464 pdp->dd_next = ddp;
445 465
446 466 return (pdp);
447 467 }
448 468
449 469 dt_decl_t *
450 470 dt_decl_ptr(void)
451 471 {
452 472 return (dt_decl_push(dt_decl_alloc(CTF_K_POINTER, NULL)));
453 473 }
454 474
455 475 dt_decl_t *
456 476 dt_decl_sou(uint_t kind, char *name)
457 477 {
458 478 dt_decl_t *ddp = dt_decl_spec(kind, name);
459 479 char n[DT_TYPE_NAMELEN];
460 480 ctf_file_t *ctfp;
461 481 ctf_id_t type;
462 482 uint_t flag;
463 483
464 484 if (yypcb->pcb_idepth != 0)
465 485 ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp;
466 486 else
467 487 ctfp = yypcb->pcb_hdl->dt_ddefs->dm_ctfp;
468 488
469 489 if (yypcb->pcb_dstack.ds_next != NULL)
470 490 flag = CTF_ADD_NONROOT;
471 491 else
472 492 flag = CTF_ADD_ROOT;
473 493
474 494 (void) snprintf(n, sizeof (n), "%s %s",
475 495 kind == CTF_K_STRUCT ? "struct" : "union",
476 496 name == NULL ? "(anon)" : name);
477 497
478 498 if (name != NULL && (type = ctf_lookup_by_name(ctfp, n)) != CTF_ERR &&
479 499 ctf_type_kind(ctfp, type) != CTF_K_FORWARD)
480 500 xyerror(D_DECL_TYPERED, "type redeclared: %s\n", n);
481 501
482 502 if (kind == CTF_K_STRUCT)
483 503 type = ctf_add_struct(ctfp, flag, name);
484 504 else
485 505 type = ctf_add_union(ctfp, flag, name);
486 506
487 507 if (type == CTF_ERR || ctf_update(ctfp) == CTF_ERR) {
488 508 xyerror(D_UNKNOWN, "failed to define %s: %s\n",
489 509 n, ctf_errmsg(ctf_errno(ctfp)));
490 510 }
491 511
492 512 ddp->dd_ctfp = ctfp;
493 513 ddp->dd_type = type;
494 514
495 515 dt_scope_push(ctfp, type);
496 516 return (ddp);
497 517 }
498 518
499 519 void
500 520 dt_decl_member(dt_node_t *dnp)
501 521 {
502 522 dt_scope_t *dsp = yypcb->pcb_dstack.ds_next;
503 523 dt_decl_t *ddp = yypcb->pcb_dstack.ds_decl;
504 524 char *ident = yypcb->pcb_dstack.ds_ident;
505 525
506 526 const char *idname = ident ? ident : "(anon)";
507 527 char n[DT_TYPE_NAMELEN];
508 528
509 529 dtrace_typeinfo_t dtt;
510 530 ctf_encoding_t cte;
511 531 ctf_id_t base;
512 532 uint_t kind;
513 533 ssize_t size;
514 534
515 535 if (dsp == NULL)
516 536 longjmp(yypcb->pcb_jmpbuf, EDT_NOSCOPE);
517 537
518 538 if (ddp == NULL)
519 539 longjmp(yypcb->pcb_jmpbuf, EDT_NODECL);
520 540
521 541 if (dnp == NULL && ident == NULL)
522 542 xyerror(D_DECL_MNAME, "member declaration requires a name\n");
523 543
524 544 if (ddp->dd_kind == CTF_K_UNKNOWN && ddp->dd_name == NULL) {
525 545 ddp->dd_kind = CTF_K_INTEGER;
526 546 (void) dt_decl_check(ddp);
527 547 }
528 548
529 549 if (dt_decl_type(ddp, &dtt) != 0)
530 550 longjmp(yypcb->pcb_jmpbuf, EDT_COMPILER);
531 551
532 552 if (ident != NULL && strchr(ident, '`') != NULL) {
533 553 xyerror(D_DECL_SCOPE, "D scoping operator may not be used "
534 554 "in a member name (%s)\n", ident);
535 555 }
536 556
537 557 if (dtt.dtt_ctfp == DT_DYN_CTFP(yypcb->pcb_hdl) &&
538 558 dtt.dtt_type == DT_DYN_TYPE(yypcb->pcb_hdl)) {
539 559 xyerror(D_DECL_DYNOBJ,
540 560 "cannot have dynamic member: %s\n", ident);
541 561 }
542 562
543 563 base = ctf_type_resolve(dtt.dtt_ctfp, dtt.dtt_type);
544 564 kind = ctf_type_kind(dtt.dtt_ctfp, base);
545 565 size = ctf_type_size(dtt.dtt_ctfp, base);
546 566
547 567 if (kind == CTF_K_FORWARD || ((kind == CTF_K_STRUCT ||
548 568 kind == CTF_K_UNION) && size == 0)) {
549 569 xyerror(D_DECL_INCOMPLETE, "incomplete struct/union/enum %s: "
550 570 "%s\n", dt_type_name(dtt.dtt_ctfp, dtt.dtt_type,
551 571 n, sizeof (n)), ident);
552 572 }
553 573
554 574 if (size == 0)
555 575 xyerror(D_DECL_VOIDOBJ, "cannot have void member: %s\n", ident);
556 576
557 577 /*
558 578 * If a bit-field qualifier was part of the member declaration, create
559 579 * a new integer type of the same name and attributes as the base type
560 580 * and size equal to the specified number of bits. We reset 'dtt' to
561 581 * refer to this new bit-field type and continue on to add the member.
562 582 */
563 583 if (dnp != NULL) {
564 584 dnp = dt_node_cook(dnp, DT_IDFLG_REF);
565 585
566 586 /*
567 587 * A bit-field member with no declarator is permitted to have
568 588 * size zero and indicates that no more fields are to be packed
569 589 * into the current storage unit. We ignore these directives
570 590 * as the underlying ctf code currently does so for all fields.
571 591 */
572 592 if (ident == NULL && dnp->dn_kind == DT_NODE_INT &&
573 593 dnp->dn_value == 0) {
574 594 dt_node_free(dnp);
575 595 goto done;
576 596 }
577 597
578 598 if (dt_node_is_posconst(dnp) == 0) {
579 599 xyerror(D_DECL_BFCONST, "positive integral constant "
580 600 "expression expected as bit-field size\n");
581 601 }
582 602
583 603 if (ctf_type_kind(dtt.dtt_ctfp, base) != CTF_K_INTEGER ||
584 604 ctf_type_encoding(dtt.dtt_ctfp, base, &cte) == CTF_ERR ||
585 605 IS_VOID(cte)) {
586 606 xyerror(D_DECL_BFTYPE, "invalid type for "
587 607 "bit-field: %s\n", idname);
588 608 }
589 609
590 610 if (dnp->dn_value > cte.cte_bits) {
591 611 xyerror(D_DECL_BFSIZE, "bit-field too big "
592 612 "for type: %s\n", idname);
593 613 }
594 614
595 615 cte.cte_offset = 0;
596 616 cte.cte_bits = (uint_t)dnp->dn_value;
597 617
598 618 dtt.dtt_type = ctf_add_integer(dsp->ds_ctfp,
599 619 CTF_ADD_NONROOT, ctf_type_name(dtt.dtt_ctfp,
600 620 dtt.dtt_type, n, sizeof (n)), &cte);
601 621
602 622 if (dtt.dtt_type == CTF_ERR ||
603 623 ctf_update(dsp->ds_ctfp) == CTF_ERR) {
604 624 xyerror(D_UNKNOWN, "failed to create type for "
605 625 "member '%s': %s\n", idname,
606 626 ctf_errmsg(ctf_errno(dsp->ds_ctfp)));
607 627 }
608 628
609 629 dtt.dtt_ctfp = dsp->ds_ctfp;
610 630 dt_node_free(dnp);
611 631 }
612 632
613 633 /*
614 634 * If the member type is not defined in the same CTF container as the
615 635 * one associated with the current scope (i.e. the container for the
616 636 * struct or union itself) or its parent, copy the member type into
617 637 * this container and reset dtt to refer to the copied type.
618 638 */
619 639 if (dtt.dtt_ctfp != dsp->ds_ctfp &&
620 640 dtt.dtt_ctfp != ctf_parent_file(dsp->ds_ctfp)) {
621 641
622 642 dtt.dtt_type = ctf_add_type(dsp->ds_ctfp,
623 643 dtt.dtt_ctfp, dtt.dtt_type);
624 644 dtt.dtt_ctfp = dsp->ds_ctfp;
625 645
626 646 if (dtt.dtt_type == CTF_ERR ||
627 647 ctf_update(dtt.dtt_ctfp) == CTF_ERR) {
628 648 xyerror(D_UNKNOWN, "failed to copy type of '%s': %s\n",
629 649 idname, ctf_errmsg(ctf_errno(dtt.dtt_ctfp)));
630 650 }
631 651 }
632 652
633 653 if (ctf_add_member(dsp->ds_ctfp, dsp->ds_type,
634 654 ident, dtt.dtt_type) == CTF_ERR) {
635 655 xyerror(D_UNKNOWN, "failed to define member '%s': %s\n",
636 656 idname, ctf_errmsg(ctf_errno(dsp->ds_ctfp)));
637 657 }
638 658
639 659 done:
640 660 free(ident);
641 661 yypcb->pcb_dstack.ds_ident = NULL;
642 662 dt_decl_reset();
643 663 }
644 664
645 665 /*ARGSUSED*/
646 666 static int
647 667 dt_decl_hasmembers(const char *name, int value, void *private)
648 668 {
649 669 return (1); /* abort search and return true if a member exists */
650 670 }
651 671
652 672 dt_decl_t *
653 673 dt_decl_enum(char *name)
654 674 {
655 675 dt_decl_t *ddp = dt_decl_spec(CTF_K_ENUM, name);
656 676 char n[DT_TYPE_NAMELEN];
657 677 ctf_file_t *ctfp;
658 678 ctf_id_t type;
659 679 uint_t flag;
660 680
661 681 if (yypcb->pcb_idepth != 0)
662 682 ctfp = yypcb->pcb_hdl->dt_cdefs->dm_ctfp;
663 683 else
664 684 ctfp = yypcb->pcb_hdl->dt_ddefs->dm_ctfp;
665 685
666 686 if (yypcb->pcb_dstack.ds_next != NULL)
667 687 flag = CTF_ADD_NONROOT;
668 688 else
669 689 flag = CTF_ADD_ROOT;
670 690
671 691 (void) snprintf(n, sizeof (n), "enum %s", name ? name : "(anon)");
672 692
673 693 if (name != NULL && (type = ctf_lookup_by_name(ctfp, n)) != CTF_ERR) {
674 694 if (ctf_enum_iter(ctfp, type, dt_decl_hasmembers, NULL))
675 695 xyerror(D_DECL_TYPERED, "type redeclared: %s\n", n);
676 696 } else if ((type = ctf_add_enum(ctfp, flag, name)) == CTF_ERR) {
677 697 xyerror(D_UNKNOWN, "failed to define %s: %s\n",
678 698 n, ctf_errmsg(ctf_errno(ctfp)));
679 699 }
680 700
681 701 ddp->dd_ctfp = ctfp;
682 702 ddp->dd_type = type;
683 703
684 704 dt_scope_push(ctfp, type);
685 705 return (ddp);
686 706 }
687 707
688 708 void
689 709 dt_decl_enumerator(char *s, dt_node_t *dnp)
690 710 {
691 711 dt_scope_t *dsp = yypcb->pcb_dstack.ds_next;
692 712 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
693 713
694 714 dt_idnode_t *inp;
695 715 dt_ident_t *idp;
696 716 char *name;
697 717 int value;
698 718
699 719 name = strdupa(s);
700 720 free(s);
701 721
702 722 if (dsp == NULL)
703 723 longjmp(yypcb->pcb_jmpbuf, EDT_NOSCOPE);
704 724
705 725 assert(dsp->ds_decl->dd_kind == CTF_K_ENUM);
706 726 value = dsp->ds_enumval + 1; /* default is previous value plus one */
707 727
708 728 if (strchr(name, '`') != NULL) {
709 729 xyerror(D_DECL_SCOPE, "D scoping operator may not be used in "
710 730 "an enumerator name (%s)\n", name);
711 731 }
712 732
713 733 /*
714 734 * If the enumerator is being assigned a value, cook and check the node
715 735 * and then free it after we get the value. We also permit references
716 736 * to identifiers which are previously defined enumerators in the type.
717 737 */
718 738 if (dnp != NULL) {
719 739 if (dnp->dn_kind != DT_NODE_IDENT || ctf_enum_value(
720 740 dsp->ds_ctfp, dsp->ds_type, dnp->dn_string, &value) != 0) {
721 741 dnp = dt_node_cook(dnp, DT_IDFLG_REF);
722 742
723 743 if (dnp->dn_kind != DT_NODE_INT) {
724 744 xyerror(D_DECL_ENCONST, "enumerator '%s' must "
725 745 "be assigned to an integral constant "
726 746 "expression\n", name);
727 747 }
728 748
729 749 if ((intmax_t)dnp->dn_value > INT_MAX ||
730 750 (intmax_t)dnp->dn_value < INT_MIN) {
731 751 xyerror(D_DECL_ENOFLOW, "enumerator '%s' value "
732 752 "overflows INT_MAX (%d)\n", name, INT_MAX);
733 753 }
734 754
735 755 value = (int)dnp->dn_value;
736 756 }
737 757 dt_node_free(dnp);
738 758 }
739 759
740 760 if (ctf_add_enumerator(dsp->ds_ctfp, dsp->ds_type,
741 761 name, value) == CTF_ERR || ctf_update(dsp->ds_ctfp) == CTF_ERR) {
742 762 xyerror(D_UNKNOWN, "failed to define enumerator '%s': %s\n",
743 763 name, ctf_errmsg(ctf_errno(dsp->ds_ctfp)));
744 764 }
745 765
746 766 dsp->ds_enumval = value; /* save most recent value */
747 767
748 768 /*
749 769 * If the enumerator name matches an identifier in the global scope,
750 770 * flag this as an error. We only do this for "D" enumerators to
751 771 * prevent "C" header file enumerators from conflicting with the ever-
752 772 * growing list of D built-in global variables and inlines. If a "C"
753 773 * enumerator conflicts with a global identifier, we add the enumerator
754 774 * but do not insert a corresponding inline (i.e. the D variable wins).
755 775 */
756 776 if (dt_idstack_lookup(&yypcb->pcb_globals, name) != NULL) {
757 777 if (dsp->ds_ctfp == dtp->dt_ddefs->dm_ctfp) {
758 778 xyerror(D_DECL_IDRED,
759 779 "identifier redeclared: %s\n", name);
760 780 } else
761 781 return;
762 782 }
763 783
764 784 dt_dprintf("add global enumerator %s = %d\n", name, value);
765 785
766 786 idp = dt_idhash_insert(dtp->dt_globals, name, DT_IDENT_ENUM,
767 787 DT_IDFLG_INLINE | DT_IDFLG_REF, 0, _dtrace_defattr, 0,
768 788 &dt_idops_inline, NULL, dtp->dt_gen);
769 789
770 790 if (idp == NULL)
771 791 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
772 792
773 793 yyintprefix = 0;
774 794 yyintsuffix[0] = '\0';
775 795 yyintdecimal = 0;
776 796
777 797 dnp = dt_node_int(value);
778 798 dt_node_type_assign(dnp, dsp->ds_ctfp, dsp->ds_type);
779 799
780 800 if ((inp = malloc(sizeof (dt_idnode_t))) == NULL)
781 801 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
782 802
783 803 /*
784 804 * Remove the INT node from the node allocation list and store it in
785 805 * din_list and din_root so it persists with and is freed by the ident.
786 806 */
787 807 assert(yypcb->pcb_list == dnp);
788 808 yypcb->pcb_list = dnp->dn_link;
789 809 dnp->dn_link = NULL;
790 810
791 811 bzero(inp, sizeof (dt_idnode_t));
792 812 inp->din_list = dnp;
793 813 inp->din_root = dnp;
794 814
795 815 idp->di_iarg = inp;
796 816 idp->di_ctfp = dsp->ds_ctfp;
797 817 idp->di_type = dsp->ds_type;
798 818 }
799 819
800 820 /*
801 821 * Look up the type corresponding to the specified decl stack. The scoping of
802 822 * the underlying type names is handled by dt_type_lookup(). We build up the
803 823 * name from the specified string and prefixes and then lookup the type. If
804 824 * we fail, an errmsg is saved and the caller must abort with EDT_COMPILER.
805 825 */
806 826 int
807 827 dt_decl_type(dt_decl_t *ddp, dtrace_typeinfo_t *tip)
808 828 {
809 829 dtrace_hdl_t *dtp = yypcb->pcb_hdl;
810 830
811 831 dt_module_t *dmp;
812 832 ctf_arinfo_t r;
813 833 ctf_id_t type;
814 834
815 835 char n[DT_TYPE_NAMELEN];
816 836 uint_t flag;
817 837 char *name;
818 838 int rv;
819 839
820 840 /*
821 841 * Based on our current #include depth and decl stack depth, determine
822 842 * which dynamic CTF module and scope to use when adding any new types.
823 843 */
824 844 dmp = yypcb->pcb_idepth ? dtp->dt_cdefs : dtp->dt_ddefs;
825 845 flag = yypcb->pcb_dstack.ds_next ? CTF_ADD_NONROOT : CTF_ADD_ROOT;
826 846
827 847 /*
828 848 * If we have already cached a CTF type for this decl, then we just
829 849 * return the type information for the cached type.
830 850 */
831 851 if (ddp->dd_ctfp != NULL &&
832 852 (dmp = dt_module_lookup_by_ctf(dtp, ddp->dd_ctfp)) != NULL) {
833 853 tip->dtt_object = dmp->dm_name;
834 854 tip->dtt_ctfp = ddp->dd_ctfp;
835 855 tip->dtt_type = ddp->dd_type;
836 856 return (0);
837 857 }
838 858
839 859 /*
840 860 * Currently CTF treats all function pointers identically. We cache a
841 861 * representative ID of kind CTF_K_FUNCTION and just return that type.
842 862 * If we want to support full function declarations, dd_next refers to
843 863 * the declaration of the function return type, and the parameter list
844 864 * should be parsed and hung off a new pointer inside of this decl.
845 865 */
846 866 if (ddp->dd_kind == CTF_K_FUNCTION) {
847 867 tip->dtt_object = dtp->dt_ddefs->dm_name;
848 868 tip->dtt_ctfp = DT_FUNC_CTFP(dtp);
849 869 tip->dtt_type = DT_FUNC_TYPE(dtp);
850 870 return (0);
851 871 }
852 872
853 873 /*
854 874 * If the decl is a pointer, resolve the rest of the stack by calling
855 875 * dt_decl_type() recursively and then compute a pointer to the result.
856 876 * Similar to the code above, we return a cached id for function ptrs.
857 877 */
858 878 if (ddp->dd_kind == CTF_K_POINTER) {
859 879 if (ddp->dd_next->dd_kind == CTF_K_FUNCTION) {
860 880 tip->dtt_object = dtp->dt_ddefs->dm_name;
861 881 tip->dtt_ctfp = DT_FPTR_CTFP(dtp);
862 882 tip->dtt_type = DT_FPTR_TYPE(dtp);
863 883 return (0);
864 884 }
865 885
866 886 if ((rv = dt_decl_type(ddp->dd_next, tip)) == 0 &&
867 887 (rv = dt_type_pointer(tip)) != 0) {
868 888 xywarn(D_UNKNOWN, "cannot find type: %s*: %s\n",
869 889 dt_type_name(tip->dtt_ctfp, tip->dtt_type,
870 890 n, sizeof (n)), ctf_errmsg(dtp->dt_ctferr));
871 891 }
872 892
873 893 return (rv);
874 894 }
875 895
876 896 /*
877 897 * If the decl is an array, we must find the base type and then call
878 898 * dt_decl_type() recursively and then build an array of the result.
879 899 * The C and D multi-dimensional array syntax requires that consecutive
880 900 * array declarations be processed from right-to-left (i.e. top-down
881 901 * from the perspective of the declaration stack). For example, an
882 902 * array declaration such as int x[3][5] is stored on the stack as:
883 903 *
884 904 * (bottom) NULL <- ( INT "int" ) <- ( ARR [3] ) <- ( ARR [5] ) (top)
885 905 *
886 906 * but means that x is declared to be an array of 3 objects each of
887 907 * which is an array of 5 integers, or in CTF representation:
888 908 *
889 909 * type T1:( content=int, nelems=5 ) type T2:( content=T1, nelems=3 )
890 910 *
891 911 * For more details, refer to K&R[5.7] and ISO C 6.5.2.1. Rather than
892 912 * overcomplicate the implementation of dt_decl_type(), we push array
893 913 * declarations down into the stack in dt_decl_array(), above, so that
894 914 * by the time dt_decl_type() is called, the decl stack looks like:
895 915 *
896 916 * (bottom) NULL <- ( INT "int" ) <- ( ARR [5] ) <- ( ARR [3] ) (top)
897 917 *
898 918 * which permits a straightforward recursive descent of the decl stack
899 919 * to build the corresponding CTF type tree in the appropriate order.
900 920 */
901 921 if (ddp->dd_kind == CTF_K_ARRAY) {
902 922 /*
903 923 * If the array decl has a parameter list associated with it,
904 924 * this is an associative array declaration: return <DYN>.
905 925 */
906 926 if (ddp->dd_node != NULL &&
907 927 ddp->dd_node->dn_kind == DT_NODE_TYPE) {
908 928 tip->dtt_object = dtp->dt_ddefs->dm_name;
909 929 tip->dtt_ctfp = DT_DYN_CTFP(dtp);
910 930 tip->dtt_type = DT_DYN_TYPE(dtp);
911 931 return (0);
912 932 }
913 933
914 934 if ((rv = dt_decl_type(ddp->dd_next, tip)) != 0)
915 935 return (rv);
916 936
917 937 /*
918 938 * If the array base type is not defined in the target
919 939 * container or its parent, copy the type to the target
920 940 * container and reset dtt_ctfp and dtt_type to the copy.
921 941 */
922 942 if (tip->dtt_ctfp != dmp->dm_ctfp &&
923 943 tip->dtt_ctfp != ctf_parent_file(dmp->dm_ctfp)) {
924 944
925 945 tip->dtt_type = ctf_add_type(dmp->dm_ctfp,
926 946 tip->dtt_ctfp, tip->dtt_type);
927 947 tip->dtt_ctfp = dmp->dm_ctfp;
928 948
929 949 if (tip->dtt_type == CTF_ERR ||
930 950 ctf_update(tip->dtt_ctfp) == CTF_ERR) {
931 951 xywarn(D_UNKNOWN, "failed to copy type: %s\n",
932 952 ctf_errmsg(ctf_errno(tip->dtt_ctfp)));
933 953 return (-1);
934 954 }
935 955 }
936 956
937 957 /*
938 958 * The array index type is irrelevant in C and D: just set it
939 959 * to "long" for all array types that we create on-the-fly.
940 960 */
941 961 r.ctr_contents = tip->dtt_type;
942 962 r.ctr_index = ctf_lookup_by_name(tip->dtt_ctfp, "long");
943 963 r.ctr_nelems = ddp->dd_node ?
944 964 (uint_t)ddp->dd_node->dn_value : 0;
945 965
946 966 tip->dtt_object = dmp->dm_name;
947 967 tip->dtt_ctfp = dmp->dm_ctfp;
948 968 tip->dtt_type = ctf_add_array(dmp->dm_ctfp, CTF_ADD_ROOT, &r);
949 969
950 970 if (tip->dtt_type == CTF_ERR ||
951 971 ctf_update(tip->dtt_ctfp) == CTF_ERR) {
952 972 xywarn(D_UNKNOWN, "failed to create array type: %s\n",
953 973 ctf_errmsg(ctf_errno(tip->dtt_ctfp)));
954 974 return (-1);
955 975 }
956 976
957 977 return (0);
958 978 }
959 979
960 980 /*
961 981 * Allocate space for the type name and enough space for the maximum
962 982 * additional text ("unsigned long long \0" requires 20 more bytes).
963 983 */
964 984 name = alloca(ddp->dd_name ? strlen(ddp->dd_name) + 20 : 20);
965 985 name[0] = '\0';
966 986
967 987 switch (ddp->dd_kind) {
968 988 case CTF_K_INTEGER:
969 989 case CTF_K_FLOAT:
970 990 if (ddp->dd_attr & DT_DA_SIGNED)
971 991 (void) strcat(name, "signed ");
972 992 if (ddp->dd_attr & DT_DA_UNSIGNED)
973 993 (void) strcat(name, "unsigned ");
974 994 if (ddp->dd_attr & DT_DA_SHORT)
975 995 (void) strcat(name, "short ");
976 996 if (ddp->dd_attr & DT_DA_LONG)
977 997 (void) strcat(name, "long ");
978 998 if (ddp->dd_attr & DT_DA_LONGLONG)
979 999 (void) strcat(name, "long long ");
980 1000 if (ddp->dd_attr == 0 && ddp->dd_name == NULL)
981 1001 (void) strcat(name, "int");
982 1002 break;
983 1003 case CTF_K_STRUCT:
984 1004 (void) strcpy(name, "struct ");
985 1005 break;
986 1006 case CTF_K_UNION:
987 1007 (void) strcpy(name, "union ");
988 1008 break;
989 1009 case CTF_K_ENUM:
990 1010 (void) strcpy(name, "enum ");
991 1011 break;
992 1012 case CTF_K_TYPEDEF:
993 1013 break;
994 1014 default:
995 1015 xywarn(D_UNKNOWN, "internal error -- "
996 1016 "bad decl kind %u\n", ddp->dd_kind);
997 1017 return (-1);
998 1018 }
999 1019
1000 1020 /*
1001 1021 * Add dd_name unless a short, long, or long long is explicitly
1002 1022 * suffixed by int. We use the C/CTF canonical names for integers.
1003 1023 */
1004 1024 if (ddp->dd_name != NULL && (ddp->dd_kind != CTF_K_INTEGER ||
1005 1025 (ddp->dd_attr & (DT_DA_SHORT | DT_DA_LONG | DT_DA_LONGLONG)) == 0))
1006 1026 (void) strcat(name, ddp->dd_name);
1007 1027
1008 1028 /*
1009 1029 * Lookup the type. If we find it, we're done. Otherwise create a
1010 1030 * forward tag for the type if it is a struct, union, or enum. If
1011 1031 * we can't find it and we can't create a tag, return failure.
1012 1032 */
1013 1033 if ((rv = dt_type_lookup(name, tip)) == 0)
1014 1034 return (rv);
1015 1035
1016 1036 switch (ddp->dd_kind) {
1017 1037 case CTF_K_STRUCT:
1018 1038 case CTF_K_UNION:
1019 1039 case CTF_K_ENUM:
1020 1040 type = ctf_add_forward(dmp->dm_ctfp, flag,
1021 1041 ddp->dd_name, ddp->dd_kind);
1022 1042 break;
1023 1043 default:
1024 1044 xywarn(D_UNKNOWN, "failed to resolve type %s: %s\n", name,
1025 1045 dtrace_errmsg(dtp, dtrace_errno(dtp)));
1026 1046 return (rv);
1027 1047 }
1028 1048
1029 1049 if (type == CTF_ERR || ctf_update(dmp->dm_ctfp) == CTF_ERR) {
1030 1050 xywarn(D_UNKNOWN, "failed to add forward tag for %s: %s\n",
1031 1051 name, ctf_errmsg(ctf_errno(dmp->dm_ctfp)));
1032 1052 return (-1);
1033 1053 }
1034 1054
1035 1055 ddp->dd_ctfp = dmp->dm_ctfp;
1036 1056 ddp->dd_type = type;
1037 1057
1038 1058 tip->dtt_object = dmp->dm_name;
1039 1059 tip->dtt_ctfp = dmp->dm_ctfp;
1040 1060 tip->dtt_type = type;
1041 1061
1042 1062 return (0);
1043 1063 }
1044 1064
1045 1065 void
1046 1066 dt_scope_create(dt_scope_t *dsp)
1047 1067 {
1048 1068 dsp->ds_decl = NULL;
1049 1069 dsp->ds_next = NULL;
1050 1070 dsp->ds_ident = NULL;
1051 1071 dsp->ds_ctfp = NULL;
1052 1072 dsp->ds_type = CTF_ERR;
1053 1073 dsp->ds_class = DT_DC_DEFAULT;
1054 1074 dsp->ds_enumval = -1;
1055 1075 }
1056 1076
1057 1077 void
1058 1078 dt_scope_destroy(dt_scope_t *dsp)
1059 1079 {
1060 1080 dt_scope_t *nsp;
1061 1081
1062 1082 for (; dsp != NULL; dsp = nsp) {
1063 1083 dt_decl_free(dsp->ds_decl);
1064 1084 free(dsp->ds_ident);
1065 1085 nsp = dsp->ds_next;
1066 1086 if (dsp != &yypcb->pcb_dstack)
1067 1087 free(dsp);
1068 1088 }
1069 1089 }
1070 1090
1071 1091 void
1072 1092 dt_scope_push(ctf_file_t *ctfp, ctf_id_t type)
1073 1093 {
1074 1094 dt_scope_t *rsp = &yypcb->pcb_dstack;
1075 1095 dt_scope_t *dsp = malloc(sizeof (dt_scope_t));
1076 1096
1077 1097 if (dsp == NULL)
1078 1098 longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);
1079 1099
1080 1100 dsp->ds_decl = rsp->ds_decl;
1081 1101 dsp->ds_next = rsp->ds_next;
1082 1102 dsp->ds_ident = rsp->ds_ident;
1083 1103 dsp->ds_ctfp = ctfp;
1084 1104 dsp->ds_type = type;
1085 1105 dsp->ds_class = rsp->ds_class;
1086 1106 dsp->ds_enumval = rsp->ds_enumval;
1087 1107
1088 1108 dt_scope_create(rsp);
1089 1109 rsp->ds_next = dsp;
1090 1110 }
1091 1111
1092 1112 dt_decl_t *
1093 1113 dt_scope_pop(void)
1094 1114 {
1095 1115 dt_scope_t *rsp = &yypcb->pcb_dstack;
1096 1116 dt_scope_t *dsp = rsp->ds_next;
1097 1117
1098 1118 if (dsp == NULL)
1099 1119 longjmp(yypcb->pcb_jmpbuf, EDT_NOSCOPE);
1100 1120
1101 1121 if (dsp->ds_ctfp != NULL && ctf_update(dsp->ds_ctfp) == CTF_ERR) {
1102 1122 xyerror(D_UNKNOWN, "failed to update type definitions: %s\n",
1103 1123 ctf_errmsg(ctf_errno(dsp->ds_ctfp)));
1104 1124 }
1105 1125
1106 1126 dt_decl_free(rsp->ds_decl);
1107 1127 free(rsp->ds_ident);
1108 1128
1109 1129 rsp->ds_decl = dsp->ds_decl;
1110 1130 rsp->ds_next = dsp->ds_next;
1111 1131 rsp->ds_ident = dsp->ds_ident;
1112 1132 rsp->ds_ctfp = dsp->ds_ctfp;
1113 1133 rsp->ds_type = dsp->ds_type;
1114 1134 rsp->ds_class = dsp->ds_class;
1115 1135 rsp->ds_enumval = dsp->ds_enumval;
1116 1136
1117 1137 free(dsp);
1118 1138 return (rsp->ds_decl);
1119 1139 }
↓ open down ↓ |
841 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX