History

some indentation made prev patch pretty; removed it

Joe Soroka committed 15 years ago

Commit 545a37b1 parent 89059f91 file · +81 −85Browse files

Unified · Split

tccgen.c+81−85
@@ -3057,74 +3057,72 @@ static void post_type_args(CType *type, AttributeDef *ad) · 3056 unmodified lines
30573057 AttributeDef ad1;
30583058 CType pt;
30593059
3060− if (tok == '(') {
3061− /* function declaration */
3062− next();
3063− l = 0;
3064− first = NULL;
3065− plast = &first;
3066− arg_size = 0;
3067− if (tok != ')') {
3068− for(;;) {
3069− /* read param name and compute offset */
3070− if (l != FUNC_OLD) {
3071− if (!parse_btype(&pt, &ad1)) {
3072− if (l) {
3073− error("invalid type");
3074− } else {
3075− l = FUNC_OLD;
3076− goto old_proto;
3077− }
3060+ /* function declaration */
3061+ next();
3062+ l = 0;
3063+ first = NULL;
3064+ plast = &first;
3065+ arg_size = 0;
3066+ if (tok != ')') {
3067+ for(;;) {
3068+ /* read param name and compute offset */
3069+ if (l != FUNC_OLD) {
3070+ if (!parse_btype(&pt, &ad1)) {
3071+ if (l) {
3072+ error("invalid type");
3073+ } else {
3074+ l = FUNC_OLD;
3075+ goto old_proto;
30783076 }
3079− l = FUNC_NEW;
3080− if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')')
3081− break;
3082− type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
3083− if ((pt.t & VT_BTYPE) == VT_VOID)
3084− error("parameter declared as void");
3085− arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
3086− } else {
3087− old_proto:
3088− n = tok;
3089− if (n < TOK_UIDENT)
3090− expect("identifier");
3091− pt.t = VT_INT;
3092− next();
30933077 }
3094− convert_parameter_type(&pt);
3095− s = sym_push(n | SYM_FIELD, &pt, 0, 0);
3096− *plast = s;
3097− plast = &s->next;
3098− if (tok == ')')
3099− break;
3100− skip(',');
3101− if (l == FUNC_NEW && tok == TOK_DOTS) {
3102− l = FUNC_ELLIPSIS;
3103− next();
3078+ l = FUNC_NEW;
3079+ if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')')
31043080 break;
3105− }
3081+ type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
3082+ if ((pt.t & VT_BTYPE) == VT_VOID)
3083+ error("parameter declared as void");
3084+ arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
3085+ } else {
3086+ old_proto:
3087+ n = tok;
3088+ if (n < TOK_UIDENT)
3089+ expect("identifier");
3090+ pt.t = VT_INT;
3091+ next();
3092+ }
3093+ convert_parameter_type(&pt);
3094+ s = sym_push(n | SYM_FIELD, &pt, 0, 0);
3095+ *plast = s;
3096+ plast = &s->next;
3097+ if (tok == ')')
3098+ break;
3099+ skip(',');
3100+ if (l == FUNC_NEW && tok == TOK_DOTS) {
3101+ l = FUNC_ELLIPSIS;
3102+ next();
3103+ break;
31063104 }
31073105 }
3108− /* if no parameters, then old type prototype */
3109− if (l == 0)
3110− l = FUNC_OLD;
3111− skip(')');
3112− t1 = type->t & VT_STORAGE;
3113− /* NOTE: const is ignored in returned type as it has a special
3114− meaning in gcc / C++ */
3115− type->t &= ~(VT_STORAGE | VT_CONSTANT);
3116− /* some ancient pre-K&R C allows a function to return an array
3117− and the array brackets to be put after the arguments, such
3118− that "int c()[]" means the same as "int[] c()" */
3119− if (tok == '[')
3120− post_type_array(type, ad);
3121− /* we push a anonymous symbol which will contain the function prototype */
3122− ad->func_args = arg_size;
3123− s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
3124− s->next = first;
3125− type->t = t1 | VT_FUNC;
3126− type->ref = s;
31273106 }
3107+ /* if no parameters, then old type prototype */
3108+ if (l == 0)
3109+ l = FUNC_OLD;
3110+ skip(')');
3111+ t1 = type->t & VT_STORAGE;
3112+ /* NOTE: const is ignored in returned type as it has a special
3113+ meaning in gcc / C++ */
3114+ type->t &= ~(VT_STORAGE | VT_CONSTANT);
3115+ /* some ancient pre-K&R C allows a function to return an array
3116+ and the array brackets to be put after the arguments, such
3117+ that "int c()[]" means the same as "int[] c()" */
3118+ if (tok == '[')
3119+ post_type_array(type, ad);
3120+ /* we push a anonymous symbol which will contain the function prototype */
3121+ ad->func_args = arg_size;
3122+ s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
3123+ s->next = first;
3124+ type->t = t1 | VT_FUNC;
3125+ type->ref = s;
31283126 }
31293127
31303128 static void post_type_array(CType *type, AttributeDef *ad)
@@ -3132,32 +3130,30 @@ static void post_type_array(CType *type, AttributeDef *ad) · 1 unmodified line
31323130 int n, t1;
31333131 Sym *s;
31343132
3135− if (tok == '[') {
3136− /* array definition */
3133+ /* array definition */
3134+ next();
3135+ if (tok == TOK_RESTRICT1)
31373136 next();
3138− if (tok == TOK_RESTRICT1)
3139− next();
3140− n = -1;
3141− if (tok != ']') {
3142− n = expr_const();
3143− if (n < 0)
3144− error("invalid array size");
3145− }
3146− skip(']');
3147− /* parse next post type */
3148− t1 = type->t & VT_STORAGE;
3149− type->t &= ~VT_STORAGE;
3150− if (tok == '[')
3151− post_type_array(type, ad);
3152−
3153− /* we push a anonymous symbol which will contain the array
3154− element type */
3155− s = sym_push(SYM_FIELD, type, 0, n);
3137+ n = -1;
3138+ if (tok != ']') {
3139+ n = expr_const();
3140+ if (n < 0)
3141+ error("invalid array size");
3142+ }
3143+ skip(']');
3144+ /* parse next post type */
3145+ t1 = type->t & VT_STORAGE;
3146+ type->t &= ~VT_STORAGE;
3147+ if (tok == '[')
3148+ post_type_array(type, ad);
3149+
3150+ /* we push a anonymous symbol which will contain the array
3151+ element type */
3152+ s = sym_push(SYM_FIELD, type, 0, n);
31563153 if (n < 0)
31573154 ARRAY_RESIZE(s->r) = 1;
3158− type->t = t1 | VT_ARRAY | VT_PTR;
3159− type->ref = s;
3160− }
3155+ type->t = t1 | VT_ARRAY | VT_PTR;
3156+ type->ref = s;
31613157 }
31623158
31633159 /* Parse a type declaration (except basic type), and return the type

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