]> code.delx.au - gnu-emacs/blob - test/cedet/tests/test.c
f33e970e6fc49e75e2c6d3a286a3876837613bb8
[gnu-emacs] / test / cedet / tests / test.c
1 /* test.c --- Semantic unit test for C.
2
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011 Free Software Foundation, Inc.
5
6 Author: Eric M. Ludlam <eric@siege-engine.com>
7
8 This file is part of GNU Emacs.
9
10 GNU Emacs is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 GNU Emacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 /* Attempt to include as many aspects of the C language as possible.
25 */
26
27 /* types of include files */
28 #include "includeme1.h"
29 #include <includeme2.h>
30 #include <subdir/includeme3.h>
31 #include <includeme.notanhfile>
32 #include <stdlib.h>
33 #include <cmath>
34
35 #if 0
36 int dont_show_function()
37 {
38 }
39 #endif
40
41 /* Global types */
42 struct mystruct1 {
43 int slot11;
44 char slot12;
45 float slot13;
46 };
47
48 struct mystruct2 {
49 int slot21;
50 char slot22;
51 float slot23;
52 } var_of_type_mystruct2;
53
54 struct {
55 int slot31;
56 char slot32;
57 float slot33;
58 } var_of_anonymous_struct;
59
60 typedef struct mystruct1 typedef_of_mystruct1;
61 typedef struct mystruct1 *typedef_of_pointer_mystruct1;
62 typedef struct { int slot_a; } typedef_of_anonymous_struct;
63 typedef struct A {
64 } B;
65
66 typedef struct mystruct1 td1, td2;
67
68 union myunion1 {
69 int slot41;
70 char slot42;
71 float slot43;
72 };
73
74 union myunion2 {
75 int slot51;
76 char slot52;
77 float slot53;
78 } var_of_type_myunion2;
79
80 struct {
81 int slot61;
82 char slot72;
83 float slot83;
84 } var_of_anonymous_union;
85
86 typedef union myunion1 typedef_of_myunion1;
87 typedef union myunion1 *typedef_of_pointer_myunion1;
88 typedef union { int slot_a; } typedef_of_anonymous_union;
89
90 enum myenum1 { enum11 = 1, enum12 };
91 enum myenum2 { enum21, enum22 = 2 } var_of_type_myenum2;
92 enum { enum31, enum32 } var_of_anonymous_enum;
93
94 typedef enum myenum1 typedef_of_myenum1;
95 typedef enum myenum1 *typedef_of_pointer_myenum1;
96 typedef enum { enum_a = 3, enum_b } typedef_of_anonymous_enum;
97
98 typedef int typedef_of_int;
99
100 /* Here are some simpler variable types */
101 int var1;
102 int varbit1:1;
103 char var2;
104 float var3;
105 mystruct1 var3;
106 struct mystruct1 var4;
107 union myunion1 var5;
108 enum myenum1 var6;
109
110 char *varp1;
111 char **varp2;
112 char varv1[1];
113 char varv2[1][2];
114
115 char *varpa1 = "moose";
116 struct mystruct2 vara2 = { 1, 'a', 0.0 };
117 enum myenum1 vara3 = enum11;
118 int vara4 = (int)0.0;
119 int vara5 = funcall();
120
121 int mvar1, mvar2, mvar3;
122 char *mvarp1, *mvarp2, *mvarp3;
123 char *mvarpa1 = 'a', *mvarpa2 = 'b', *mvarpa3 = 'c';
124 char mvaras1[10], mvaras2[12][13], *mvaras3 = 'd';
125
126 static register const unsigned int tmvar1;
127
128 #define MACRO1 1
129 #define MACRO2(foo) (1+foo)
130
131 /* Here are some function prototypes */
132
133 /* This is legal, but I decided not to support inferred integer
134 * types on functions and variables.
135 */
136 fun0();
137 int funp1();
138 char funp2(int arg11);
139 float funp3(char arg21, char arg22);
140 struct mystrct1 funp4(struct mystruct2 arg31, union myunion2 arg32);
141 enum myenum1 funp5(char *arg41, union myunion1 *arg42);
142
143 char funpp1 __P(char argp1, struct mystruct2 argp2, char *arg4p);
144
145 int fun1();
146
147 /* Here is a function pointer */
148 int (*funcptr)(int a, int b);
149
150 /* Function Definitions */
151
152 /* This is legal, but I decided not to support inferred integer
153 * types on functions and variables.
154 */
155 fun0()
156 {
157 int sv = 0;
158 }
159
160 int fun1 ()
161 {
162 int sv = 1;
163 }
164
165 int fun1p1 (void)
166 {
167 int sv = 1;
168 }
169
170 char fun2(int arg_11)
171 {
172 char sv = 2;
173 }
174
175 float fun3(char arg_21, char arg_22)
176 {
177 char sv = 3;
178 }
179
180 struct mystrct1 fun4(struct mystruct2 arg31, union myunion2 arg32)
181 {
182 sv = 4;
183 }
184
185 enum myenum1 fun5(char *arg41, union myunion1 *arg42)
186 {
187 sv = 5;
188 }
189
190 /* Functions with K&R syntax. */
191 struct mystrct1 funk1(arg_31, arg_32)
192 struct mystruct2 arg_31;
193 union myunion2 arg32;
194 {
195 sv = 4;
196 }
197
198 enum myenum1 *funk2(arg_41, arg_42)
199 char *arg_41;
200 union myunion1 *arg_42;
201 {
202 sv = 5;
203
204 if(foo) {
205 }
206 }
207
208 int funk3(arg_51, arg_53)
209 int arg_51;
210 char arg_53;
211 {
212 char q = 'a';
213 int sv = 6;
214 td1 ms1;
215 enum myenum1 testconst;
216
217 /* Function argument analysis */
218 funk3(ms1.slot11, arg_53 );
219 sv = 7;
220
221 /* Slot deref on assignee */
222 ms1.slot11 = s;
223
224 /* Enum/const completion */
225 testconst = e;
226
227 /* Bad var/slot and param */
228 blah.notafunction(moose);
229
230 /* Print something. */
231 printf("Moose", );
232
233 tan();
234 }
235
236 int funk4_fixme(arg_61, arg_62)
237 int arg_61, arg_62;
238 {
239
240 }
241
242 /* End of C tests */
243