| @@ -1096,18 +1096,24 @@ static Sym *sym_copy(Sym *s0, Sym **ps) · 1095 unmodified lines |
| 1096 | return s; | 1096 | return s; |
| 1097 | } | 1097 | } |
| 1098 | | 1098 | |
| 1099 | /* copy a list of syms */ | 1099 | /* copy s->type.ref to stack 'ps' for VT_FUNC and VT_PTR */ |
| 1100 | static void sym_copy_ref(Sym *s0, Sym **ps) | 1100 | static void sym_copy_ref(Sym *s, Sym **ps) |
| 1101 | { | 1101 | { |
| 1102 | Sym *s, **sp = &s0->type.ref; | 1102 | int bt = s->type.t & VT_BTYPE; |
| 1103 | for (s = *sp, *sp = NULL; s; s = s->next) | 1103 | if (bt == VT_FUNC || bt == VT_PTR) { |
| 1104 | sp = &(*sp = sym_copy(s, ps))->next; | 1104 | Sym **sp = &s->type.ref; |
| | 1105 | for (s = *sp, *sp = NULL; s; s = s->next) { |
| | 1106 | Sym *s2 = sym_copy(s, ps); |
| | 1107 | sp = &(*sp = s2)->next; |
| | 1108 | sym_copy_ref(s2, ps); |
| | 1109 | } |
| | 1110 | } |
| 1105 | } | 1111 | } |
| 1106 | | 1112 | |
| 1107 | /* define a new external reference to a symbol 'v' */ | 1113 | /* define a new external reference to a symbol 'v' */ |
| 1108 | static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) | 1114 | static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) |
| 1109 | { | 1115 | { |
| 1110 | Sym *s; int bt; | 1116 | Sym *s; |
| 1111 | | 1117 | |
| 1112 | /* look for global symbol */ | 1118 | /* look for global symbol */ |
| 1113 | s = sym_find(v); | 1119 | s = sym_find(v); |
| @@ -1121,16 +1127,14 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 7 unmodified lines |
| 1121 | s->a = ad->a; | 1127 | s->a = ad->a; |
| 1122 | s->asm_label = ad->asm_label; | 1128 | s->asm_label = ad->asm_label; |
| 1123 | s->type.ref = type->ref; | 1129 | s->type.ref = type->ref; |
| 1124 | bt = s->type.t & (VT_BTYPE|VT_ARRAY); | 1130 | /* copy type to the global stack */ |
| 1125 | /* copy type to the global stack also */ | 1131 | if (local_stack) |
| 1126 | if (local_scope && (bt == VT_FUNC || (bt & VT_ARRAY))) | | |
| 1127 | sym_copy_ref(s, &global_stack); | 1132 | sym_copy_ref(s, &global_stack); |
| 1128 | } else { | 1133 | } else { |
| 1129 | patch_storage(s, ad, type); | 1134 | patch_storage(s, ad, type); |
| 1130 | bt = s->type.t & VT_BTYPE; | | |
| 1131 | } | 1135 | } |
| 1132 | /* push variables to local scope if any */ | 1136 | /* push variables on local_stack if any */ |
| 1133 | if (local_stack && bt != VT_FUNC) | 1137 | if (local_stack && (s->type.t & VT_BTYPE) != VT_FUNC) |
| 1134 | s = sym_copy(s, &local_stack); | 1138 | s = sym_copy(s, &local_stack); |
| 1135 | return s; | 1139 | return s; |
| 1136 | } | 1140 | } |