History

tccgen: scopes levels for local symbols (update 2)

allow typedef int xxx; typedef int xxx; in the same scope as long as it is the same type

grischka committed 10 years ago

Commit a94e8d41 parent d48662d3 files · +21 −17Browse files

Unified · Split

3 files
  1. tccgen.c +14 −11
  2. tests/Makefile +1 −0
  3. tests/pp/Makefile +6 −6
tccgen.c+14−11
@@ -2927,13 +2927,10 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) · 2926 unmodified lines
2927 if (v < TOK_IDENT)2927 if (v < TOK_IDENT)
2928 expect("struct/union/enum name");2928 expect("struct/union/enum name");
2929 s = struct_find(v);2929 s = struct_find(v);
2930 if (s && s->type.t == a) {2930 if (s && (s->scope == local_scope || (tok != '{' && tok != ';'))) {
2931 if (0 == local_scope)2931 if (s->type.t != a)
2932 goto do_decl; /* compatibility with past behavior */2932 tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
2933 if (tok != '{' && tok != ';')2933 goto do_decl;
2934 goto do_decl; /* variable declaration: 'struct s x;' */
2935 if (s->scope == local_scope && (s->c == -1 || tok != '{'))
2936 goto do_decl; /* at least one must be incomplete type */
2937 }2934 }
2938 } else {2935 } else {
2939 v = anon_sym++;2936 v = anon_sym++;
@@ -3435,8 +3432,6 @@ static void post_type(CType *type, AttributeDef *ad) · 495 unmodified lines
3435 plast = &first;3432 plast = &first;
3436 arg_size = 0;3433 arg_size = 0;
3437 if (tok != ')') {3434 if (tok != ')') {
3438 int ls = local_scope;
3439 local_scope = 1; /* for struct decl inside function params */
3440 for(;;) {3435 for(;;) {
3441 /* read param name and compute offset */3436 /* read param name and compute offset */
3442 if (l != FUNC_OLD) {3437 if (l != FUNC_OLD) {
@@ -3476,7 +3471,6 @@ static void post_type(CType *type, AttributeDef *ad) · 33 unmodified lines
3476 break;3471 break;
3477 }3472 }
3478 }3473 }
3479 local_scope = ls;
3480 }3474 }
3481 /* if no parameters, then old type prototype */3475 /* if no parameters, then old type prototype */
3482 if (l == 0)3476 if (l == 0)
@@ -6434,7 +6428,16 @@ static int decl0(int l, int is_for_loop_init) · 2951 unmodified lines
6434 if (btype.t & VT_TYPEDEF) {6428 if (btype.t & VT_TYPEDEF) {
6435 /* save typedefed type */6429 /* save typedefed type */
6436 /* XXX: test storage specifiers ? */6430 /* XXX: test storage specifiers ? */
6437 sym = sym_push(v, &type, 0, 0);6431 sym = sym_find(v);
6432 if (sym && sym->scope == local_scope) {
6433 if (!is_compatible_types(&sym->type, &type)
6434 || !(sym->type.t & VT_TYPEDEF))
6435 tcc_error("incompatible redefinition of '%s'",
6436 get_tok_str(v, NULL));
6437 sym->type = type;
6438 } else {
6439 sym = sym_push(v, &type, 0, 0);
6440 }
6438 sym->a = ad.a;6441 sym->a = ad.a;
6439 sym->type.t |= VT_TYPEDEF;6442 sym->type.t |= VT_TYPEDEF;
6440 } else {6443 } else {
tests/Makefile+1−0
@@ -250,6 +250,7 @@ cache: tcc_g · 249 unmodified lines
250# clean250# clean
251clean:251clean:
252 $(MAKE) -C tests2 $@252 $(MAKE) -C tests2 $@
253 $(MAKE) -C pp $@
253 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \254 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc \
254 *-cc *-tcc *.exe \255 *-cc *-tcc *.exe \
255 hello libtcc_test vla_test tcctest[1234] ex? tcc_g256 hello libtcc_test vla_test tcctest[1234] ex? tcc_g
tests/pp/Makefile+6−6
@@ -8,16 +8,18 @@ TESTS += $(patsubst %.S,%.test,$(wildcard *.S)) · 7 unmodified lines
8 8
9all test : $(sort $(TESTS))9all test : $(sort $(TESTS))
10 10
11DIFF_OPTS = -Nu -b -B -I "^\#"
12
11%.test: %.c %.expect13%.test: %.c %.expect
12 @echo PPTest $* ...14 @echo PPTest $* ...
13 -@$(TCC) -E -P $< >$*.output 2>&1 ; \15 -@$(TCC) -E -P $< >$*.output 2>&1 ; \
14 diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \16 diff $(DIFF_OPTS) $*.expect $*.output \
15 && rm -f $*.output17 && rm -f $*.output
16 18
17%.test: %.S %.expect19%.test: %.S %.expect
18 @echo PPTest $* ...20 @echo PPTest $* ...
19 -@$(TCC) -E -P $< >$*.output 2>&1 ; \21 -@$(TCC) -E -P $< >$*.output 2>&1 ; \
20 diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \22 diff $(DIFF_OPTS) $*.expect $*.output \
21 && rm -f $*.output23 && rm -f $*.output
22 24
23# automatically generate .expect files with gcc:25# automatically generate .expect files with gcc:
@@ -33,10 +35,8 @@ all test : $(sort $(TESTS)) · 9 unmodified lines
33clean:35clean:
34 rm -vf *.output36 rm -vf *.output
35 37
36# 02.test : EXTRA_DIFF_OPTS = -w3802.test : DIFF_OPTS += -w
37# 03.test : EXTRA_DIFF_OPTS = -w3915.test : DIFF_OPTS += -w
38# 04.test : EXTRA_DIFF_OPTS = -w
39# 10.test : EXTRA_DIFF_OPTS = -w
40 40
41# diff options:41# diff options:
42# -b ighore space changes42# -b ighore space changes

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