Lines Matching refs:sym
50 void access_symbol(struct symbol *sym)
52 if (sym->ctype.modifiers & MOD_INLINE) {
53 if (!sym->accessed) {
54 add_symbol(&translation_unit_used_list, sym);
55 sym->accessed = 1;
62 struct symbol *sym;
64 for (sym = ident->symbols; sym; sym = sym->next_id) {
65 if (sym->namespace & ns) {
66 sym->used = 1;
67 return sym;
80 struct symbol *sym = __alloc_symbol(0);
81 sym->type = type;
82 sym->pos = pos;
83 sym->endpos.type = 0;
84 return sym;
99 static void lay_out_union(struct symbol *sym, struct struct_union_info *info)
101 if (sym->bit_size < 0 && is_array_type(sym))
102 sparse_error(sym->pos, "flexible array member '%s' in a union", show_ident(sym->ident));
104 if (sym->bit_size > info->bit_size)
105 info->bit_size = sym->bit_size;
107 sym->offset = 0;
110 static int bitfield_base_size(struct symbol *sym)
112 if (sym->type == SYM_NODE)
113 sym = sym->ctype.base_type;
114 if (sym->type == SYM_BITFIELD)
115 sym = sym->ctype.base_type;
116 return sym->bit_size;
122 static void lay_out_struct(struct symbol *sym, struct struct_union_info *info)
129 base_size = sym->bit_size;
136 if (!is_array_type(sym))
139 info->flex_array = sym;
142 alignment = info->packed ? 1 : sym->ctype.alignment;
148 if (is_bitfield_type (sym)) {
150 int room = bitfield_base_size(sym) - bit_offset;
158 sym->offset = bits_to_bytes(bit_size - bit_offset);
159 sym->bit_offset = bit_offset;
160 sym->ctype.base_type->bit_offset = bit_offset;
162 // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width);
164 if (info->packed && sym->type == SYM_NODE)
165 sym->packed = 1;
173 sym->offset = bits_to_bytes(bit_size);
176 // warning (sym->pos, "regular: offset=%d", sym->offset);
184 static void examine_anonymous_member(struct symbol *sym)
186 unsigned long mod = sym->ctype.modifiers & MOD_QUALIFIER;
189 if (sym->type == SYM_NODE)
190 sym = sym->ctype.base_type;
191 if (sym->type != SYM_STRUCT && sym->type != SYM_UNION)
194 FOR_EACH_PTR(sym->symbol_list, sub) {
204 static struct symbol * examine_struct_union_type(struct symbol *sym, int advance)
207 .packed = sym->packed,
217 FOR_EACH_PTR(sym->symbol_list, member) {
228 if (member->ctype.alignment > info.max_align && !sym->packed) {
241 if (!sym->ctype.alignment)
242 sym->ctype.alignment = info.max_align;
245 bit_align = bytes_to_bits(sym->ctype.alignment)-1;
251 if (info.has_flex_array && (!is_union_type(sym) || Wflexible_array_union))
252 sym->has_flex_array = 1;
253 sym->bit_size = bit_size;
254 return sym;
257 static struct symbol *examine_base_type(struct symbol *sym)
261 if (sym->ctype.base_type == &autotype_ctype) {
262 struct symbol *type = evaluate_expression(sym->initializer);
266 warning(sym->pos, "__auto_type on bitfield");
271 sym->ctype.base_type = type;
275 base_type = examine_symbol_type(sym->ctype.base_type);
278 combine_address_space(sym->pos, &sym->ctype.as, base_type->ctype.as);
279 sym->ctype.modifiers |= base_type->ctype.modifiers & MOD_PTRINHERIT;
281 (struct ptr_list **)&sym->ctype.contexts);
284 sym->ctype.base_type = base_type;
285 sym->rank = base_type->rank;
290 static struct symbol * examine_array_type(struct symbol *sym)
292 struct symbol *base_type = examine_base_type(sym);
294 struct expression *array_size = sym->array_size;
297 return sym;
309 warning(sym->pos, "array of flexible structures");
311 if (!sym->ctype.alignment)
312 sym->ctype.alignment = alignment;
313 sym->bit_size = bit_size;
314 return sym;
317 static struct symbol *examine_bitfield_type(struct symbol *sym)
319 struct symbol *base_type = examine_base_type(sym);
323 return sym;
324 if (sym->bit_size > base_type->bit_size) {
325 sparse_error(sym->pos, "bitfield '%s' is wider (%d) than its type (%s)",
326 show_ident(sym->ident), sym->bit_size, show_typename(base_type));
327 sym->bit_size = -1;
331 if (!sym->ctype.alignment)
332 sym->ctype.alignment = alignment;
338 sym->ctype.modifiers |= modifiers & MOD_SIGNEDNESS;
339 return sym;
345 void merge_type(struct symbol *sym, struct symbol *base_type)
347 combine_address_space(sym->pos, &sym->ctype.as, base_type->ctype.as);
348 sym->ctype.modifiers |= (base_type->ctype.modifiers & ~MOD_STORAGE);
350 (struct ptr_list **)&sym->ctype.contexts);
351 sym->ctype.base_type = base_type->ctype.base_type;
352 if (sym->ctype.base_type->type == SYM_NODE)
353 merge_type(sym, sym->ctype.base_type);
450 static struct expression *get_symbol_initializer(struct symbol *sym)
453 if (sym->initializer)
454 return sym->initializer;
455 } while ((sym = sym->same_symbol) != NULL);
476 static struct symbol * examine_node_type(struct symbol *sym)
478 struct symbol *base_type = examine_base_type(sym);
486 return sym;
492 sym->ctype.modifiers |= (MOD_SIGNEDNESS & base_type->ctype.modifiers);
494 if (!sym->ctype.alignment)
495 sym->ctype.alignment = alignment;
499 struct expression *initializer = get_symbol_initializer(sym);
505 bit_size = implicit_array_size(sym, count);
509 sym->bit_size = bit_size;
510 sym->rank = base_type->rank;
511 return sym;
514 static struct symbol *examine_enum_type(struct symbol *sym)
516 struct symbol *base_type = examine_base_type(sym);
518 sym->ctype.modifiers |= (base_type->ctype.modifiers & MOD_SIGNEDNESS);
519 sym->bit_size = bits_in_enum;
520 if (base_type->bit_size > sym->bit_size)
521 sym->bit_size = base_type->bit_size;
522 sym->ctype.alignment = enum_alignment;
523 if (base_type->ctype.alignment > sym->ctype.alignment)
524 sym->ctype.alignment = base_type->ctype.alignment;
525 return sym;
528 static struct symbol *examine_pointer_type(struct symbol *sym)
537 if (!sym->bit_size)
538 sym->bit_size = bits_in_pointer;
539 if (!sym->ctype.alignment)
540 sym->ctype.alignment = pointer_alignment;
541 return sym;
544 static struct symbol *examine_typeof(struct symbol *sym)
546 struct symbol *base = evaluate_expression(sym->initializer);
557 sym->type = SYM_NODE;
558 sym->ctype.modifiers = mod;
559 sym->ctype.base_type = base;
560 return examine_node_type(sym);
567 struct symbol *examine_symbol_type(struct symbol * sym)
569 if (!sym)
570 return sym;
573 if (sym->examined)
574 return sym;
575 sym->examined = 1;
577 switch (sym->type) {
580 return examine_node_type(sym);
582 return examine_array_type(sym);
584 return examine_struct_union_type(sym, 1);
586 return examine_struct_union_type(sym, 0);
588 return examine_pointer_type(sym);
590 return examine_enum_type(sym);
592 return examine_bitfield_type(sym);
595 return sym;
597 return examine_typeof(sym);
599 sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident));
602 sparse_error(sym->pos, "ctype on uninitialized symbol '%s'", show_typename(sym));
605 examine_base_type(sym);
606 return sym;
608 examine_base_type(sym);
609 return sym;
611 sparse_error(sym->pos, "Examining unknown symbol type %d", sym->type);
614 return sym;
644 struct symbol *examine_pointer_target(struct symbol *sym)
646 return examine_base_type(sym);
685 static void inherit_declaration(struct symbol *sym, struct symbol *prev)
690 sym->ctype.modifiers |= mods & MOD_FUN_ATTR;
693 void check_declaration(struct symbol *sym)
696 struct symbol *next = sym;
699 if (next->namespace != sym->namespace)
701 if (sym->scope == next->scope) {
702 sym->same_symbol = next;
703 inherit_declaration(sym, next);
707 if (sym->ctype.modifiers & MOD_EXTERN) {
709 sym->same_symbol = next;
719 warning(sym->pos, "symbol '%s' shadows an earlier one", show_ident(sym->ident));
724 static void inherit_static(struct symbol *sym)
729 if (sym->ctype.modifiers & (MOD_STATIC|MOD_EXTERN))
732 for (prev = sym->next_id; prev; prev = prev->next_id) {
738 sym->ctype.modifiers |= prev->ctype.modifiers & MOD_STATIC;
745 void bind_symbol_with_scope(struct symbol *sym, struct ident *ident, enum namespace ns, struct scope *scope)
747 if (sym->bound) {
748 sparse_error(sym->pos, "internal error: symbol type already bound");
752 sparse_error(sym->pos, "Trying to use reserved word '%s' as identifier", show_ident(ident));
755 sym->namespace = ns;
756 sym->next_id = ident->symbols;
757 ident->symbols = sym;
758 if (sym->ident && sym->ident != ident)
759 warning(sym->pos, "Symbol '%s' already bound", show_ident(sym->ident));
760 sym->ident = ident;
761 sym->bound = 1;
766 inherit_static(sym);
769 if (sym->ctype.modifiers & MOD_STATIC ||
770 is_extern_inline(sym)) {
774 sym->ctype.modifiers |= mod;
776 bind_scope(sym, scope);
779 void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns)
787 bind_symbol_with_scope(sym, ident, ns, scope);
793 struct symbol *sym = lookup_symbol(ident, namespace);
795 if (sym && sym->type != type)
797 type, sym->type);
799 if (!sym) {
802 sym = alloc_symbol(token->pos, type);
803 bind_symbol(sym, token->ident, namespace);
805 return sym;
960 struct symbol *sym = ctype->ptr;
967 sym->type = ctype->type;
968 sym->rank = ctype->rank;
969 sym->bit_size = bit_size;
970 sym->ctype.alignment = alignment;
971 sym->ctype.base_type = ctype->base_type;
972 sym->ctype.modifiers = ctype->modifiers;
974 if (sym->type == SYM_NODE) {
975 struct symbol *base = sym->ctype.base_type;
976 sym->rank = base->rank;
978 sym->bit_size = base->bit_size;
980 sym->ctype.alignment = base->ctype.alignment;