summarylogtreecommitdiffstats
path: root/13_local_typedef.patch
blob: 20553bb88d3db4bb367979d95825fb44ab2180fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Description: Basic support for typedefs inside functions
Author: Fabian Brosda <fabi3141@gmx.de>
Last-Update: 2020-07-10

diff --unified --recursive --text --new-file c-wrapper-0.6.1/src/c-parser.c c-wrapper-0.6.1-new/src/c-parser.c
--- c-wrapper-0.6.1/src/c-parser.c	2020-07-10 09:31:37.678880351 +0200
+++ c-wrapper-0.6.1-new/src/c-parser.c	2020-07-10 11:24:40.687237976 +0200
@@ -594,6 +594,26 @@
     }
 }
 
+static void emit_typedef(ScmObj type_decl_list)
+{
+    ScmObj p;
+
+    SCM_FOR_EACH(p, type_decl_list) {
+        ScmObj v = SCM_CAR(p);
+        ScmObj ctype = SCM_TYPE_DECL_CTYPE(v);
+        ScmObj new_ctype = SCM_TYPE_DECL_NAME(v);
+        ScmObj sym = CParser_ctype2class_symbol(new_ctype);
+
+        Scm_DefChunkDictSetTypename(new_ctype,
+                                    Scm_MakeDefChunk(SYM(S_typedef),
+                                                     new_ctype,
+                                                     SCM_LIST1(sym),
+                                                     SCM_LIST3(SYM(S_define), sym, ctype)));
+        Scm_InstallType(new_ctype);
+    }
+}
+
+
 ScmObj Scm_MakeTypeDecl(ScmObj type_spec_list, ScmObj declarator)
 {
     ScmObj lst = SCM_NIL;
@@ -612,6 +632,7 @@
     
     SCM_FOR_EACH(pair, type_spec_list) {
         if (SCM_EQ(SCM_CAR(pair), SYM(U_typedef))) {
+            emit_typedef(Scm_Cons(Scm_MakeTypeDecl(SCM_CDR(pair), declarator), lst));
             continue;
         }
         lst = Scm_Cons(SCM_CAR(pair), lst);
@@ -1542,25 +1563,6 @@
     SCM_RETURN(SCM_UNDEFINED);
 }
                                                              
-static void emit_typedef(ScmObj type_decl_list)
-{
-    ScmObj p;
-
-    SCM_FOR_EACH(p, type_decl_list) {
-        ScmObj v = SCM_CAR(p);
-        ScmObj ctype = SCM_TYPE_DECL_CTYPE(v);
-        ScmObj new_ctype = SCM_TYPE_DECL_NAME(v);
-        ScmObj sym = CParser_ctype2class_symbol(new_ctype);
-
-        Scm_DefChunkDictSetTypename(new_ctype,
-                                    Scm_MakeDefChunk(SYM(S_typedef),
-                                                     new_ctype,
-                                                     SCM_LIST1(sym),
-                                                     SCM_LIST3(SYM(S_define), sym, ctype)));
-        Scm_InstallType(new_ctype);
-    }
-}
-
 static void emit_define_extern(ScmObj declaration)
 {
     ScmObj ctype = SCM_TYPE_DECL_CTYPE(declaration);
diff --unified --recursive --text --new-file c-wrapper-0.6.1/testsuite/local_typedef.c c-wrapper-0.6.1-new/testsuite/local_typedef.c
--- c-wrapper-0.6.1/testsuite/local_typedef.c	1970-01-01 01:00:00.000000000 +0100
+++ c-wrapper-0.6.1-new/testsuite/local_typedef.c	2020-07-10 11:36:22.222238897 +0200
@@ -0,0 +1,6 @@
+#include "local_typedef.h"
+
+int local_typedef(void)
+{
+    return helper();
+}
diff --unified --recursive --text --new-file c-wrapper-0.6.1/testsuite/local_typedef.h c-wrapper-0.6.1-new/testsuite/local_typedef.h
--- c-wrapper-0.6.1/testsuite/local_typedef.h	1970-01-01 01:00:00.000000000 +0100
+++ c-wrapper-0.6.1-new/testsuite/local_typedef.h	2020-07-10 11:36:13.598926230 +0200
@@ -0,0 +1,8 @@
+extern int local_typedef(void);
+
+int helper(void)
+{
+    typedef int _my_type;
+    _my_type ret = 1;
+    return ret;
+}
diff --unified --recursive --text --new-file c-wrapper-0.6.1/testsuite/local-typedef.scm c-wrapper-0.6.1-new/testsuite/local-typedef.scm
--- c-wrapper-0.6.1/testsuite/local-typedef.scm	1970-01-01 01:00:00.000000000 +0100
+++ c-wrapper-0.6.1-new/testsuite/local-typedef.scm	2020-07-10 11:37:12.818784249 +0200
@@ -0,0 +1,19 @@
+;;;
+;;; Test local typedefs
+;;;
+
+(use gauche.test)
+
+(test-start "c-wrapper (local typedefs)")
+(use c-wrapper)
+
+(c-load-library "./local_typedef")
+(c-include "./local_typedef.h")
+
+(test "local_typedef"
+      1
+      (lambda ()
+        (local_typedef)))
+
+;; epilogue
+(test-end)
diff --unified --recursive --text --new-file c-wrapper-0.6.1/testsuite/Makefile.in c-wrapper-0.6.1-new/testsuite/Makefile.in
--- c-wrapper-0.6.1/testsuite/Makefile.in	2020-07-10 09:31:37.678880351 +0200
+++ c-wrapper-0.6.1-new/testsuite/Makefile.in	2020-07-10 11:18:42.768062987 +0200
@@ -57,6 +57,9 @@
 fptr_array.$(DYLIBEXT): fptr_array.o
 	$(CC) $(LDFLAGS) $@ $<
 
+local_typedef.$(DYLIBEXT): local_typedef.o
+	$(CC) $(LDFLAGS) $@ $<
+
 gcc_extension.$(DYLIBEXT): gcc_extension.o
 	$(CC) $(LDFLAGS) $@ $<
 
@@ -65,7 +68,7 @@
 
 check: $(CHECK_TARGET)
 
-check-c: ffitest.$(DYLIBEXT) fptr_array.$(DYLIBEXT) gcc_extension.$(DYLIBEXT)
+check-c: ffitest.$(DYLIBEXT) fptr_array.$(DYLIBEXT) gcc_extension.$(DYLIBEXT) local_typedef.$(DYLIBEXT)
 	@rm -f test.log
 	$(GOSH) -I../src -I../lib attr-test.scm >> test.log
 	$(GOSH) -I../src -I../lib ffitest.scm >> test.log
@@ -74,6 +77,7 @@
 	$(GOSH) -I../src -I../lib struct_in_union-test.scm >> test.log
 	$(GOSH) -I../src -I../lib stdio-test.scm >> test.log
 	$(GOSH) -I../src -I../lib math-test.scm >> test.log
+	$(GOSH) -I../src -I../lib local-typedef.scm >> test.log
 	$(GOSH) -I../src -I../lib inline-test.scm >> test.log
 	$(GOSH) -I../src -I../lib fptr_array-test.scm >> test.log
 	$(GOSH) -I../src -I../lib array_qualifier-test.scm >> test.log
@@ -83,7 +87,7 @@
 	$(GOSH) -I../src -I../lib -I../objc objc-test.scm >> test.log
 
 clean :
-	rm -rf core ffitest.$(DYLIBEXT) objc-test.$(DYLIBEXT) fptr_array.$(DYLIBEXT) gcc_extension.$(DYLIBEXT) *.o $(GENERATED) *~ test.log so_locations
+	rm -rf core ffitest.$(DYLIBEXT) objc-test.$(DYLIBEXT) fptr_array.$(DYLIBEXT) gcc_extension.$(DYLIBEXT) local_typedef.$(DYLIBEXT) *.o $(GENERATED) *~ test.log so_locations
 
 distclean : clean
 	rm -rf $(CONFIG_GENERATED)