History

Make parse_btype only accept one basic type

This makes int char c; and struct {} int c; generate an error. Thanks Mobi Phil for reporting.

Thomas Preud'homme committed 12 years ago

Commit b68499e1 parent ec1c8301 file · +15 −8Browse files

Unified · Split

tccgen.c+15−8
@@ -2988,19 +2988,25 @@ static void struct_decl(CType *type, int u, int tdef) · 2987 unmodified lines
2988 }2988 }
2989}2989}
2990 2990
2991/* return 1 if basic type is a type size (short, long, long long) */
2992int is_btype_size (int bt)
2993{
2994 return bt == VT_SHORT || bt == VT_LONG || bt == VT_LLONG;
2995}
2996
2991/* return 0 if no type declaration. otherwise, return the basic type2997/* return 0 if no type declaration. otherwise, return the basic type
2992 and skip it. 2998 and skip it.
2993 */2999 */
2994static int parse_btype(CType *type, AttributeDef *ad)3000static int parse_btype(CType *type, AttributeDef *ad)
2995{3001{
2996 int t, u, type_found, typespec_found, typedef_found;3002 int t, u, bt_size, complete, type_found, typespec_found;
2997 Sym *s;3003 Sym *s;
2998 CType type1;3004 CType type1;
2999 3005
3000 memset(ad, 0, sizeof(AttributeDef));3006 memset(ad, 0, sizeof(AttributeDef));
3007 complete = 0;
3001 type_found = 0;3008 type_found = 0;
3002 typespec_found = 0;3009 typespec_found = 0;
3003 typedef_found = 0;
3004 t = 0;3010 t = 0;
3005 while(1) {3011 while(1) {
3006 switch(tok) {3012 switch(tok) {
@@ -3015,9 +3021,12 @@ static int parse_btype(CType *type, AttributeDef *ad) · 8 unmodified lines
3015 basic_type:3021 basic_type:
3016 next();3022 next();
3017 basic_type1:3023 basic_type1:
3018 if ((t & VT_BTYPE) != 0)3024 if (complete)
3019 tcc_error("too many basic types");3025 tcc_error("too many basic types");
3020 t |= u;3026 t |= u;
3027 bt_size = is_btype_size (u & VT_BTYPE);
3028 if (u == VT_INT || (!bt_size && !(t & VT_TYPEDEF)))
3029 complete = 1;
3021 typespec_found = 1;3030 typespec_found = 1;
3022 break;3031 break;
3023 case TOK_VOID:3032 case TOK_VOID:
@@ -3027,9 +3036,8 @@ static int parse_btype(CType *type, AttributeDef *ad) · 3 unmodified lines
3027 u = VT_SHORT;3036 u = VT_SHORT;
3028 goto basic_type;3037 goto basic_type;
3029 case TOK_INT:3038 case TOK_INT:
3030 next();3039 u = VT_INT;
3031 typespec_found = 1;3040 goto basic_type;
3032 break;
3033 case TOK_LONG:3041 case TOK_LONG:
3034 next();3042 next();
3035 if ((t & VT_BTYPE) == VT_DOUBLE) {3043 if ((t & VT_BTYPE) == VT_DOUBLE) {
@@ -3149,12 +3157,11 @@ static int parse_btype(CType *type, AttributeDef *ad) · 113 unmodified lines
3149 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);3157 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
3150 goto basic_type2;3158 goto basic_type2;
3151 default:3159 default:
3152 if (typespec_found || typedef_found)3160 if (typespec_found)
3153 goto the_end;3161 goto the_end;
3154 s = sym_find(tok);3162 s = sym_find(tok);
3155 if (!s || !(s->type.t & VT_TYPEDEF))3163 if (!s || !(s->type.t & VT_TYPEDEF))
3156 goto the_end;3164 goto the_end;
3157 typedef_found = 1;
3158 t |= (s->type.t & ~VT_TYPEDEF);3165 t |= (s->type.t & ~VT_TYPEDEF);
3159 type->ref = s->type.ref;3166 type->ref = s->type.ref;
3160 if (s->r) {3167 if (s->r) {

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