@@ -367,11 +367,12 @@ static inline void psyms(const char *msg, Sym *s, Sym *last)
367367static void type_to_str (char * buf , int buf_size , CType * type , const char * varstr );
368368
369369/* print type */
370- static void ptype (CType * type , int v )
370+ static void ptype (const char * msg , CType * type , int v )
371371{
372372 char buf [500 ];
373- type_to_str (buf , sizeof (buf ), type , get_tok_str (v , NULL ));
374- printf ("type = '%s'\n" , buf );
373+ type_to_str (buf , sizeof (buf ), type ,
374+ (v & ~SYM_FIELD ) ? get_tok_str (v , NULL ) : NULL );
375+ printf ("%s : %s;\n" , msg , buf );
375376}
376377#endif
377378
@@ -714,13 +715,6 @@ ST_INLN Sym *sym_find(int v)
714715 return table_ident [v ]-> sym_identifier ;
715716}
716717
717- static int sym_scope_e (Sym * s )
718- {
719- return IS_ENUM_VAL (s -> type .t )
720- ? s -> type .ref -> sym_scope
721- : s -> sym_scope ;
722- }
723-
724718/* make sym in-/visible to the parser */
725719static inline void sym_link (Sym * s , int yes )
726720{
@@ -731,15 +725,21 @@ static inline void sym_link(Sym *s, int yes)
731725 else
732726 ps = & ts -> sym_identifier ;
733727 if (yes ) {
734- if (* ps && sym_scope_e (* ps ) == local_scope )
735- tcc_error ("redeclaration of '%s'" , get_tok_str (s -> v , NULL ));
736728 s -> prev_tok = * ps , * ps = s ;
737729 s -> sym_scope = local_scope ;
738730 } else {
739731 * ps = s -> prev_tok ;
740732 }
741733}
742734
735+ static inline int sym_scope_ex (Sym * s )
736+ {
737+ /* enums have 'sym_scope' overwritten by 'enum_val' */
738+ return IS_ENUM_VAL (s -> type .t )
739+ ? s -> type .ref -> sym_scope
740+ : s -> sym_scope ;
741+ }
742+
743743/* push a given symbol on the symbol stack */
744744ST_FUNC Sym * sym_push (int v , CType * type , int r , int c )
745745{
@@ -755,6 +755,8 @@ ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
755755 if ((v & ~SYM_STRUCT ) < SYM_FIRST_ANOM ) {
756756 /* record symbol in token array */
757757 sym_link (s , 1 );
758+ if (s -> prev_tok && sym_scope_ex (s -> prev_tok ) == local_scope )
759+ tcc_error ("redeclaration of '%s'" , get_tok_str (s -> v , NULL ));
758760 }
759761 return s ;
760762}
@@ -1330,26 +1332,26 @@ static void move_ref_to_global(Sym *s)
13301332 if (!(bt == VT_PTR
13311333 || bt == VT_FUNC
13321334 || bt == VT_STRUCT
1333- || (( IS_ENUM (s -> type .t )) && ( bt = VT_ENUM , 1 ) )))
1335+ || IS_ENUM (s -> type .t )))
13341336 return ;
13351337
13361338 for (s = s -> type .ref , n = 0 ; s ; s = s -> next ) {
13371339 for (lp = & local_stack ; !!(l = * lp ); lp = & l -> prev ) {
13381340 if (l == s ) {
13391341 * lp = s -> prev ;
13401342 s -> prev = global_stack , global_stack = s ;
1341- if (n || bt == VT_PTR ) {
1343+ if (n || bt == VT_PTR || bt == VT_FUNC ) {
13421344 move_ref_to_global (s );
13431345 } else {
1344- if ((bt == VT_STRUCT || bt == VT_ENUM )
1345- && (s -> v & ~SYM_STRUCT ) < SYM_FIRST_ANOM ) {
1346+ if ((s -> v & ~SYM_STRUCT ) < SYM_FIRST_ANOM ) {
13461347 /* copy struct/enum tag to local scope */
13471348 s -> v |= SYM_FIELD ;
13481349 l = sym_copy (s , lp );
13491350 l -> v &= ~SYM_FIELD ;
13501351 }
1351- n = 1 ;
13521352 }
1353+ if (bt != VT_PTR )
1354+ n = 1 ;
13531355 break ;
13541356 }
13551357 }
@@ -8715,6 +8717,7 @@ static int decl(int l)
87158717 type = btype ;
87168718 ad = adbase ;
87178719 type_decl (& type , & ad , & v , TYPE_DIRECT );
8720+ /*ptype("decl", &type, v);*/
87188721
87198722 if ((type .t & VT_BTYPE ) == VT_FUNC ) {
87208723 if ((type .t & VT_STATIC ) && (l != VT_CONST ))
0 commit comments