104494
|
1 /* Test file for C language.
|
|
2 * Attempt to include as many aspects of the C language as possible.
|
|
3 *
|
|
4 * $Id: test.c,v 1.12 2008/05/17 20:16:03 zappo Exp $
|
|
5 *
|
|
6 */
|
|
7 /* types of include files */
|
|
8 #include "includeme1.h"
|
|
9 #include <includeme2.h>
|
|
10 #include <subdir/includeme3.h>
|
|
11 #include <includeme.notanhfile>
|
|
12 #include <stdlib.h>
|
|
13 #include <cmath>
|
|
14
|
|
15 #if 0
|
|
16 int dont_show_function()
|
|
17 {
|
|
18 }
|
|
19 #endif
|
|
20
|
|
21 /* Global types */
|
|
22 struct mystruct1 {
|
|
23 int slot11;
|
|
24 char slot12;
|
|
25 float slot13;
|
|
26 };
|
|
27
|
|
28 struct mystruct2 {
|
|
29 int slot21;
|
|
30 char slot22;
|
|
31 float slot23;
|
|
32 } var_of_type_mystruct2;
|
|
33
|
|
34 struct {
|
|
35 int slot31;
|
|
36 char slot32;
|
|
37 float slot33;
|
|
38 } var_of_anonymous_struct;
|
|
39
|
|
40 typedef struct mystruct1 typedef_of_mystruct1;
|
|
41 typedef struct mystruct1 *typedef_of_pointer_mystruct1;
|
|
42 typedef struct { int slot_a; } typedef_of_anonymous_struct;
|
|
43 typedef struct A {
|
|
44 } B;
|
|
45
|
|
46 typedef struct mystruct1 td1, td2;
|
|
47
|
|
48 union myunion1 {
|
|
49 int slot41;
|
|
50 char slot42;
|
|
51 float slot43;
|
|
52 };
|
|
53
|
|
54 union myunion2 {
|
|
55 int slot51;
|
|
56 char slot52;
|
|
57 float slot53;
|
|
58 } var_of_type_myunion2;
|
|
59
|
|
60 struct {
|
|
61 int slot61;
|
|
62 char slot72;
|
|
63 float slot83;
|
|
64 } var_of_anonymous_union;
|
|
65
|
|
66 typedef union myunion1 typedef_of_myunion1;
|
|
67 typedef union myunion1 *typedef_of_pointer_myunion1;
|
|
68 typedef union { int slot_a; } typedef_of_anonymous_union;
|
|
69
|
|
70 enum myenum1 { enum11 = 1, enum12 };
|
|
71 enum myenum2 { enum21, enum22 = 2 } var_of_type_myenum2;
|
|
72 enum { enum31, enum32 } var_of_anonymous_enum;
|
|
73
|
|
74 typedef enum myenum1 typedef_of_myenum1;
|
|
75 typedef enum myenum1 *typedef_of_pointer_myenum1;
|
|
76 typedef enum { enum_a = 3, enum_b } typedef_of_anonymous_enum;
|
|
77
|
|
78 typedef int typedef_of_int;
|
|
79
|
|
80 /* Here are some simpler variable types */
|
|
81 int var1;
|
|
82 int varbit1:1;
|
|
83 char var2;
|
|
84 float var3;
|
|
85 mystruct1 var3;
|
|
86 struct mystruct1 var4;
|
|
87 union myunion1 var5;
|
|
88 enum myenum1 var6;
|
|
89
|
|
90 char *varp1;
|
|
91 char **varp2;
|
|
92 char varv1[1];
|
|
93 char varv2[1][2];
|
|
94
|
|
95 char *varpa1 = "moose";
|
|
96 struct mystruct2 vara2 = { 1, 'a', 0.0 };
|
|
97 enum myenum1 vara3 = enum11;
|
|
98 int vara4 = (int)0.0;
|
|
99 int vara5 = funcall();
|
|
100
|
|
101 int mvar1, mvar2, mvar3;
|
|
102 char *mvarp1, *mvarp2, *mvarp3;
|
|
103 char *mvarpa1 = 'a', *mvarpa2 = 'b', *mvarpa3 = 'c';
|
|
104 char mvaras1[10], mvaras2[12][13], *mvaras3 = 'd';
|
|
105
|
|
106 static register const unsigned int tmvar1;
|
|
107
|
|
108 #define MACRO1 1
|
|
109 #define MACRO2(foo) (1+foo)
|
|
110
|
|
111 /* Here are some function prototypes */
|
|
112
|
|
113 /* This is legal, but I decided not to support inferred integer
|
|
114 * types on functions and variables.
|
|
115 */
|
|
116 fun0();
|
|
117 int funp1();
|
|
118 char funp2(int arg11);
|
|
119 float funp3(char arg21, char arg22);
|
|
120 struct mystrct1 funp4(struct mystruct2 arg31, union myunion2 arg32);
|
|
121 enum myenum1 funp5(char *arg41, union myunion1 *arg42);
|
|
122
|
|
123 char funpp1 __P(char argp1, struct mystruct2 argp2, char *arg4p);
|
|
124
|
|
125 int fun1();
|
|
126
|
|
127 /* Here is a function pointer */
|
|
128 int (*funcptr)(int a, int b);
|
|
129
|
|
130 /* Function Definitions */
|
|
131
|
|
132 /* This is legal, but I decided not to support inferred integer
|
|
133 * types on functions and variables.
|
|
134 */
|
|
135 fun0()
|
|
136 {
|
|
137 int sv = 0;
|
|
138 }
|
|
139
|
|
140 int fun1 ()
|
|
141 {
|
|
142 int sv = 1;
|
|
143 }
|
|
144
|
|
145 int fun1p1 (void)
|
|
146 {
|
|
147 int sv = 1;
|
|
148 }
|
|
149
|
|
150 char fun2(int arg_11)
|
|
151 {
|
|
152 char sv = 2;
|
|
153 }
|
|
154
|
|
155 float fun3(char arg_21, char arg_22)
|
|
156 {
|
|
157 char sv = 3;
|
|
158 }
|
|
159
|
|
160 struct mystrct1 fun4(struct mystruct2 arg31, union myunion2 arg32)
|
|
161 {
|
|
162 sv = 4;
|
|
163 }
|
|
164
|
|
165 enum myenum1 fun5(char *arg41, union myunion1 *arg42)
|
|
166 {
|
|
167 sv = 5;
|
|
168 }
|
|
169
|
|
170 /* Functions with K&R syntax. */
|
|
171 struct mystrct1 funk1(arg_31, arg_32)
|
|
172 struct mystruct2 arg_31;
|
|
173 union myunion2 arg32;
|
|
174 {
|
|
175 sv = 4;
|
|
176 }
|
|
177
|
|
178 enum myenum1 *funk2(arg_41, arg_42)
|
|
179 char *arg_41;
|
|
180 union myunion1 *arg_42;
|
|
181 {
|
|
182 sv = 5;
|
|
183
|
|
184 if(foo) {
|
|
185 }
|
|
186 }
|
|
187
|
|
188 int funk3(arg_51, arg_53)
|
|
189 int arg_51;
|
|
190 char arg_53;
|
|
191 {
|
|
192 char q = 'a';
|
|
193 int sv = 6;
|
|
194 td1 ms1;
|
|
195 enum myenum1 testconst;
|
|
196
|
|
197 /* Function argument analysis */
|
|
198 funk3(ms1.slot11, arg_53 );
|
|
199 sv = 7;
|
|
200
|
|
201 /* Slot deref on assignee */
|
|
202 ms1.slot11 = s;
|
|
203
|
|
204 /* Enum/const completion */
|
|
205 testconst = e;
|
|
206
|
|
207 /* Bad var/slot and param */
|
|
208 blah.notafunction(moose);
|
|
209
|
|
210 /* Print something. */
|
|
211 printf("Moose", );
|
|
212
|
|
213 tan();
|
|
214 }
|
|
215
|
|
216 int funk4_fixme(arg_61, arg_62)
|
|
217 int arg_61, arg_62;
|
|
218 {
|
|
219
|
|
220 }
|
|
221
|
|
222 /* End of C tests */
|