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