Lines Matching refs:sym

49 void access_symbol(struct symbol *sym)  in access_symbol()  argument
51 if (sym->ctype.modifiers & MOD_INLINE) { in access_symbol()
52 if (!sym->accessed) { in access_symbol()
53 add_symbol(&translation_unit_used_list, sym); in access_symbol()
54 sym->accessed = 1; in access_symbol()
61 struct symbol *sym; in lookup_symbol() local
63 for (sym = ident->symbols; sym; sym = sym->next_id) { in lookup_symbol()
64 if (sym->namespace & ns) { in lookup_symbol()
65 sym->used = 1; in lookup_symbol()
66 return sym; in lookup_symbol()
79 struct symbol *sym = __alloc_symbol(0); in alloc_symbol() local
80 sym->type = type; in alloc_symbol()
81 sym->pos = pos; in alloc_symbol()
82 sym->endpos.type = 0; in alloc_symbol()
83 return sym; in alloc_symbol()
95 static void lay_out_union(struct symbol *sym, struct struct_union_info *info) in lay_out_union() argument
97 examine_symbol_type(sym); in lay_out_union()
100 if (sym->ident || !is_bitfield_type(sym)) { in lay_out_union()
101 if (sym->ctype.alignment > info->max_align) in lay_out_union()
102 info->max_align = sym->ctype.alignment; in lay_out_union()
105 if (sym->bit_size > info->bit_size) in lay_out_union()
106 info->bit_size = sym->bit_size; in lay_out_union()
108 sym->offset = 0; in lay_out_union()
111 static int bitfield_base_size(struct symbol *sym) in bitfield_base_size() argument
113 if (sym->type == SYM_NODE) in bitfield_base_size()
114 sym = sym->ctype.base_type; in bitfield_base_size()
115 if (sym->type == SYM_BITFIELD) in bitfield_base_size()
116 sym = sym->ctype.base_type; in bitfield_base_size()
117 return sym->bit_size; in bitfield_base_size()
123 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) in lay_out_struct() argument
128 examine_symbol_type(sym); in lay_out_struct()
131 if (sym->ident || !is_bitfield_type(sym)) { in lay_out_struct()
132 if (sym->ctype.alignment > info->max_align) in lay_out_struct()
133 info->max_align = sym->ctype.alignment; in lay_out_struct()
137 base_size = sym->bit_size; in lay_out_struct()
148 align_bit_mask = bytes_to_bits(sym->ctype.alignment) - 1; in lay_out_struct()
153 if (is_bitfield_type (sym)) { in lay_out_struct()
155 int room = bitfield_base_size(sym) - bit_offset; in lay_out_struct()
163 sym->offset = bits_to_bytes(bit_size - bit_offset); in lay_out_struct()
164 sym->bit_offset = bit_offset; in lay_out_struct()
165 sym->ctype.base_type->bit_offset = bit_offset; in lay_out_struct()
176 sym->offset = bits_to_bytes(bit_size); in lay_out_struct()
182 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance) in examine_struct_union_type() argument
194 FOR_EACH_PTR(sym->symbol_list, member) { in examine_struct_union_type()
198 if (!sym->ctype.alignment) in examine_struct_union_type()
199 sym->ctype.alignment = info.max_align; in examine_struct_union_type()
202 bit_align = bytes_to_bits(sym->ctype.alignment)-1; in examine_struct_union_type()
205 sym->bit_size = bit_size; in examine_struct_union_type()
206 return sym; in examine_struct_union_type()
209 static struct symbol *examine_base_type(struct symbol *sym) in examine_base_type() argument
214 base_type = examine_symbol_type(sym->ctype.base_type); in examine_base_type()
217 combine_address_space(sym->pos, &sym->ctype.as, base_type->ctype.as); in examine_base_type()
218 sym->ctype.modifiers |= base_type->ctype.modifiers & MOD_PTRINHERIT; in examine_base_type()
220 (struct ptr_list **)&sym->ctype.contexts); in examine_base_type()
223 sym->ctype.base_type = base_type; in examine_base_type()
228 static struct symbol * examine_array_type(struct symbol *sym) in examine_array_type() argument
230 struct symbol *base_type = examine_base_type(sym); in examine_array_type()
232 struct expression *array_size = sym->array_size; in examine_array_type()
235 return sym; in examine_array_type()
247 if (!sym->ctype.alignment) in examine_array_type()
248 sym->ctype.alignment = alignment; in examine_array_type()
249 sym->bit_size = bit_size; in examine_array_type()
250 return sym; in examine_array_type()
253 static struct symbol *examine_bitfield_type(struct symbol *sym) in examine_bitfield_type() argument
255 struct symbol *base_type = examine_base_type(sym); in examine_bitfield_type()
259 return sym; in examine_bitfield_type()
261 if (sym->bit_size > bit_size) in examine_bitfield_type()
262 warning(sym->pos, "impossible field-width, %d, for this type", sym->bit_size); in examine_bitfield_type()
265 if (!sym->ctype.alignment) in examine_bitfield_type()
266 sym->ctype.alignment = alignment; in examine_bitfield_type()
272 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS; in examine_bitfield_type()
273 return sym; in examine_bitfield_type()
279 void merge_type(struct symbol *sym, struct symbol *base_type) in merge_type() argument
281 combine_address_space(sym->pos, &sym->ctype.as, base_type->ctype.as); in merge_type()
282 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE); in merge_type()
284 (struct ptr_list **)&sym->ctype.contexts); in merge_type()
285 sym->ctype.base_type = base_type->ctype.base_type; in merge_type()
286 if (sym->ctype.base_type->type == SYM_NODE) in merge_type()
287 merge_type(sym, sym->ctype.base_type); in merge_type()
359 static struct expression *get_symbol_initializer(struct symbol *sym) in get_symbol_initializer() argument
362 if (sym->initializer) in get_symbol_initializer()
363 return sym->initializer; in get_symbol_initializer()
364 } while ((sym = sym->same_symbol) != NULL); in get_symbol_initializer()
385 static struct symbol * examine_node_type(struct symbol *sym) in examine_node_type() argument
387 struct symbol *base_type = examine_base_type(sym); in examine_node_type()
395 return sym; in examine_node_type()
401 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers); in examine_node_type()
403 if (!sym->ctype.alignment) in examine_node_type()
404 sym->ctype.alignment = alignment; in examine_node_type()
408 struct expression *initializer = get_symbol_initializer(sym); in examine_node_type()
414 bit_size = implicit_array_size(sym, count); in examine_node_type()
418 sym->bit_size = bit_size; in examine_node_type()
419 return sym; in examine_node_type()
422 static struct symbol *examine_enum_type(struct symbol *sym) in examine_enum_type() argument
424 struct symbol *base_type = examine_base_type(sym); in examine_enum_type()
426 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS); in examine_enum_type()
427 sym->bit_size = bits_in_enum; in examine_enum_type()
428 if (base_type->bit_size > sym->bit_size) in examine_enum_type()
429 sym->bit_size = base_type->bit_size; in examine_enum_type()
430 sym->ctype.alignment = enum_alignment; in examine_enum_type()
431 if (base_type->ctype.alignment > sym->ctype.alignment) in examine_enum_type()
432 sym->ctype.alignment = base_type->ctype.alignment; in examine_enum_type()
433 return sym; in examine_enum_type()
436 static struct symbol *examine_pointer_type(struct symbol *sym) in examine_pointer_type() argument
444 if (!sym->bit_size) in examine_pointer_type()
445 sym->bit_size = bits_in_pointer; in examine_pointer_type()
446 if (!sym->ctype.alignment) in examine_pointer_type()
447 sym->ctype.alignment = pointer_alignment; in examine_pointer_type()
448 return sym; in examine_pointer_type()
455 struct symbol *examine_symbol_type(struct symbol * sym) in examine_symbol_type() argument
457 if (!sym) in examine_symbol_type()
458 return sym; in examine_symbol_type()
461 if (sym->examined) in examine_symbol_type()
462 return sym; in examine_symbol_type()
463 sym->examined = 1; in examine_symbol_type()
465 switch (sym->type) { in examine_symbol_type()
468 return examine_node_type(sym); in examine_symbol_type()
470 return examine_array_type(sym); in examine_symbol_type()
472 return examine_struct_union_type(sym, 1); in examine_symbol_type()
474 return examine_struct_union_type(sym, 0); in examine_symbol_type()
476 return examine_pointer_type(sym); in examine_symbol_type()
478 return examine_enum_type(sym); in examine_symbol_type()
480 return examine_bitfield_type(sym); in examine_symbol_type()
483 return sym; in examine_symbol_type()
485 struct symbol *base = evaluate_expression(sym->initializer); in examine_symbol_type()
495 sym->type = SYM_NODE; in examine_symbol_type()
496 sym->ctype.modifiers = mod; in examine_symbol_type()
497 sym->ctype.base_type = base; in examine_symbol_type()
498 return examine_node_type(sym); in examine_symbol_type()
500 sym->type = SYM_NODE; in examine_symbol_type()
501 sym->ctype.base_type = &bad_ctype; in examine_symbol_type()
502 return sym; in examine_symbol_type()
505 sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident)); in examine_symbol_type()
511 examine_base_type(sym); in examine_symbol_type()
512 return sym; in examine_symbol_type()
514 examine_base_type(sym); in examine_symbol_type()
515 return sym; in examine_symbol_type()
520 return sym; in examine_symbol_type()
552 struct symbol *examine_pointer_target(struct symbol *sym) in examine_pointer_target() argument
554 return examine_base_type(sym); in examine_pointer_target()
592 void check_declaration(struct symbol *sym) in check_declaration() argument
595 struct symbol *next = sym; in check_declaration()
598 if (next->namespace != sym->namespace) in check_declaration()
600 if (sym->scope == next->scope) { in check_declaration()
601 sym->same_symbol = next; in check_declaration()
605 if (sym->ctype.modifiers & MOD_EXTERN) { in check_declaration()
607 sym->same_symbol = next; in check_declaration()
617 warning(sym->pos, "symbol '%s' shadows an earlier one", show_ident(sym->ident)); in check_declaration()
622 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) in bind_symbol() argument
625 if (sym->bound) { in bind_symbol()
626 sparse_error(sym->pos, "internal error: symbol type already bound"); in bind_symbol()
630 sparse_error(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident)); in bind_symbol()
633 sym->namespace = ns; in bind_symbol()
634 sym->next_id = ident->symbols; in bind_symbol()
635 ident->symbols = sym; in bind_symbol()
636 if (sym->ident && sym->ident != ident) in bind_symbol()
637 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident)); in bind_symbol()
638 sym->ident = ident; in bind_symbol()
639 sym->bound = 1; in bind_symbol()
646 if (sym->ctype.modifiers & MOD_STATIC || in bind_symbol()
647 is_extern_inline(sym)) { in bind_symbol()
651 sym->ctype.modifiers |= mod; in bind_symbol()
657 bind_scope(sym, scope); in bind_symbol()
663 struct symbol *sym = lookup_symbol(ident, namespace); in create_symbol() local
665 if (sym && sym->type != type) in create_symbol()
667 type, sym->type); in create_symbol()
669 if (!sym) { in create_symbol()
672 sym = alloc_symbol(token->pos, type); in create_symbol()
673 bind_symbol(sym, token->ident, namespace); in create_symbol()
675 return sym; in create_symbol()
812 struct symbol *sym = ctype->ptr; in init_ctype() local
819 sym->type = ctype->type; in init_ctype()
820 sym->bit_size = bit_size; in init_ctype()
821 sym->ctype.alignment = alignment; in init_ctype()
822 sym->ctype.base_type = ctype->base_type; in init_ctype()
823 sym->ctype.modifiers = ctype->modifiers; in init_ctype()