History

refactor post_type() to be explicit about its recursion

Joe Soroka committed 15 years ago

Commit 89059f91 parent 772b3021 file · +20 −5Browse files

Unified · Split

tccgen.c+20−5
@@ -3048,7 +3048,9 @@ static void asm_label_instr(CString *astr) · 3047 unmodified lines
30483048 #endif
30493049 }
30503050
3051−static void post_type(CType *type, AttributeDef *ad)
3051+static void post_type_array(CType *type, AttributeDef *ad);
3052+
3053+static void post_type_args(CType *type, AttributeDef *ad)
30523054 {
30533055 int n, l, t1, arg_size, align;
30543056 Sym **plast, *s, *first;
@@ -3114,14 +3116,23 @@ static void post_type(CType *type, AttributeDef *ad) · 59 unmodified lines
31143116 /* some ancient pre-K&R C allows a function to return an array
31153117 and the array brackets to be put after the arguments, such
31163118 that "int c()[]" means the same as "int[] c()" */
3117− post_type(type, ad);
3119+ if (tok == '[')
3120+ post_type_array(type, ad);
31183121 /* we push a anonymous symbol which will contain the function prototype */
31193122 ad->func_args = arg_size;
31203123 s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
31213124 s->next = first;
31223125 type->t = t1 | VT_FUNC;
31233126 type->ref = s;
3124− } else if (tok == '[') {
3127+ }
3128+}
3129+
3130+static void post_type_array(CType *type, AttributeDef *ad)
3131+{
3132+ int n, t1;
3133+ Sym *s;
3134+
3135+ if (tok == '[') {
31253136 /* array definition */
31263137 next();
31273138 if (tok == TOK_RESTRICT1)
@@ -3136,7 +3147,8 @@ static void post_type(CType *type, AttributeDef *ad) · 8 unmodified lines
31363147 /* parse next post type */
31373148 t1 = type->t & VT_STORAGE;
31383149 type->t &= ~VT_STORAGE;
3139− post_type(type, ad);
3150+ if (tok == '[')
3151+ post_type_array(type, ad);
31403152
31413153 /* we push a anonymous symbol which will contain the array
31423154 element type */
@@ -3210,7 +3222,10 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) · 67 unmodified lines
32103222 *v = 0;
32113223 }
32123224 }
3213− post_type(type, ad);
3225+ if (tok == '(')
3226+ post_type_args(type, ad);
3227+ else if (tok == '[')
3228+ post_type_array(type, ad);
32143229 if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
32153230 parse_attribute(ad);
32163231

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t