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