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