History

tccgen.c: Allow type attributes to prefix enum/struct/union name

From gcc docs: "You may also specify attributes between the enum, struct or union tag and the name of the type rather than after the closing brace." Adds `82_attribs_position.c` in `tests/tests2`

Vlad Vissoultchev committed 10 years ago

Commit 0691b761 parent effc7d93 files · +28 −10Browse files

Unified · Split

3 files
  1. tccgen.c +14 −10
  2. tests/tests2/82_attribs_position.c +14 −0
  3. tests/tests2/82_attribs_position.expect +0 −0
tccgen.c+14−10
@@ -2906,16 +2906,20 @@ static void parse_attribute(AttributeDef *ad) · 2905 unmodified lines
29062906 }
29072907
29082908 /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
2909−static void struct_decl(CType *type, int u)
2909+static void struct_decl(CType *type, AttributeDef *ad, int u)
29102910 {
29112911 int a, v, size, align, maxalign, c, offset, flexible;
29122912 int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt;
29132913 Sym *s, *ss, *ass, **ps;
2914− AttributeDef ad;
2914+ AttributeDef ad1;
29152915 CType type1, btype;
29162916
29172917 a = tok; /* save decl type */
29182918 next();
2919+ if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2) {
2920+ parse_attribute(ad);
2921+ next();
2922+ }
29192923 if (tok != '{') {
29202924 v = tok;
29212925 next();
@@ -2983,7 +2987,7 @@ static void struct_decl(CType *type, int u) · 61 unmodified lines
29832987 offset = 0;
29842988 flexible = 0;
29852989 while (tok != '}') {
2986− parse_btype(&btype, &ad);
2990+ parse_btype(&btype, &ad1);
29872991 while (1) {
29882992 if (flexible)
29892993 tcc_error("flexible array member '%s' not at the end of struct",
@@ -2992,7 +2996,7 @@ static void struct_decl(CType *type, int u) · 2 unmodified lines
29922996 v = 0;
29932997 type1 = btype;
29942998 if (tok != ':') {
2995− type_decl(&type1, &ad, &v, TYPE_DIRECT | TYPE_ABSTRACT);
2999+ type_decl(&type1, &ad1, &v, TYPE_DIRECT | TYPE_ABSTRACT);
29963000 if (v == 0) {
29973001 if ((type1.t & VT_BTYPE) != VT_STRUCT)
29983002 expect("identifier");
@@ -3028,10 +3032,10 @@ static void struct_decl(CType *type, int u) · 29 unmodified lines
30283032 get_tok_str(v, NULL));
30293033 }
30303034 size = type_size(&type1, &align);
3031− if (ad.a.aligned) {
3032− if (align < ad.a.aligned)
3033− align = ad.a.aligned;
3034− } else if (ad.a.packed) {
3035+ if (ad1.a.aligned) {
3036+ if (align < ad1.a.aligned)
3037+ align = ad1.a.aligned;
3038+ } else if (ad1.a.packed) {
30353039 align = 1;
30363040 } else if (*tcc_state->pack_stack_ptr) {
30373041 if (align > *tcc_state->pack_stack_ptr)
@@ -3232,14 +3236,14 @@ static int parse_btype(CType *type, AttributeDef *ad) · 194 unmodified lines
32323236 }
32333237 break;
32343238 case TOK_ENUM:
3235− struct_decl(&type1, VT_ENUM);
3239+ struct_decl(&type1, ad, VT_ENUM);
32363240 basic_type2:
32373241 u = type1.t;
32383242 type->ref = type1.ref;
32393243 goto basic_type1;
32403244 case TOK_STRUCT:
32413245 case TOK_UNION:
3242− struct_decl(&type1, VT_STRUCT);
3246+ struct_decl(&type1, ad, VT_STRUCT);
32433247 goto basic_type2;
32443248
32453249 /* type modifiers */
tests/tests2/82_attribs_position.c+14−0
@@ -0,0 +1,14 @@
1+typedef unsigned short uint16_t;
2+typedef unsigned char uint8_t;
3+
4+typedef union Unaligned16a {
5+ uint16_t u;
6+ uint8_t b[2];
7+} __attribute__((packed)) Unaligned16a;
8+
9+typedef union __attribute__((packed)) Unaligned16b {
10+ uint16_t u;
11+ uint8_t b[2];
12+} Unaligned16b;
13+
14+int main () { return 0; }
tests/tests2/82_attribs_position.expect+0−0

Empty file added.

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