Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a90e5d1299bd7eebdeb37acb5167ba4da361bd1 (plain) (blame)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.parser.xlc.tests;


public class XLCExtensionsTest extends XLCTestBase {

	public XLCExtensionsTest() {
	}
	
	public XLCExtensionsTest(String name) {
		super(name);
	}
	
	public void testHexadecimalFloatingPointLiterals() throws Exception {
		String code =
			"int test() {        \n"+
			"	 0x0A2B.0FDp+2f; \n"+
			"	 0X12D.p-44F;    \n"+
			"	 0xBACP+2L;      \n"+
			"}\n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testFuncPredefinedIdentifier() {
		String code =
			"void test() {       \n" +
            "     __func__;      \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testStringConcatenation() {
		String code =
			"void test() {       \n" +
            "     \"hello \" \"there\";   \n" +
            "     \"hello \" L\"there\";  \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testLongLong() {
		String code =
			"void test() {       \n" +
            "     long long x;   \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testComplex() {
		String code =
			"void test() {       \n" +
            "     float _Complex x;   \n" +
            "     double _Complex y;   \n" +
            "     long double _Complex z;   \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testBool() {
		String code =
			"_Bool f(int a, int b) { \n" +
            "    return a==b; \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
	}
	
	public void testTrailingCommaInEnum() {
		String code =
			"void test() {       \n" +
            "     enum grain { oats, wheat, barley, corn, rice, };   \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	

	public void testNonLValueArraySubscript() {
		String code =
			"struct trio{int a[3];};  \n" +
	        "struct trio f();         \n" +
	        "foo (int index)          \n" +
	        "{                        \n" +
	        "   return f().a[index];  \n" +
	        "}  \n";             

		parse(code, getCLanguage(), true);
	}
	
	public void testStaticArrayIndices() {
		String code =
			"void test() {       \n" +
            "     void foo1(int arr [static 10]);       \n" +
            "     int i = 10;                           \n" +
            "     void foo2(int arr [static const i]);  \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
	}
	
	public void testFunctionLikeMacrosVariableArguments() {
		String code =
			"#define debug(...)   fprintf(stderr, __VA_ARGS__) \n" +
			"int test() { \n" +
            "    debug(\"flag\");  \n" +
		    " } \n";

		parse(code, getCLanguage(), false);
	}
	
	public void testFunctionLikeMacrosEmptyArgument() {
		String code =
			"#define SUM(a,b,c) a + b + c \n" +
			"int test() { \n" +
            "   SUM(1,,3);  \n" +
		    " } \n";

		parse(code, getCLanguage(), true);
	}
	
	public void testPredefinedMacroNamesC() {
		String code =
			"void test() {         \n" +
            "    __DATE__;         \n" +
            "    __FILE__;         \n" +
            "    __LINE__;         \n" +
            "    __STDC_HOSTED__;  \n" +
            "    __STDC_VERSION__; \n" +
            "    __TIME__;         \n" +
            "}  \n";

		parse(code, getCLanguage(), true);
	}
	
	public void testPredefinedMacroNamesCpp() {
		String code =
			"void test() {      \n" +
            "    __DATE__;      \n" +
            "    __FILE__;      \n" +
            "    __LINE__;      \n" +
            "    __TIME__;      \n" +
          //  "    __cplusplus;   \n" +
            "}  \n";

		parse(code, getCPPLanguage(), true);
	}
	
	
	public void testCompoundLiterals() {
		String code =
			"void test() {       \n" +
            "     drawline((struct point){6,7});   \n" +
            " }  \n";

		parse(code, getCLanguage(), false);
	}
	
	

	public void testPragma() {
		String code =
			"void test() {       \n" +
            "    _Pragma ( \"pack(full)\" )   \n" +
            " }  \n";

		parse(code, getCLanguage(), true);
	}
	
	
	public void testStandardPragmas() {
		String code =
			"#pragma STDC FP_CONTRACT ON           \n" +
			"#pragma STDC FENV_ACCESS OFF          \n" +
			"#pragma STDC CX_LIMITED_RANGE DEFAULT \n";

		parse(code, getCLanguage(), true);
	}
	
	public void testLineDirective() {
		String code =
			"#define LINE200 200 \n" +
			"#line 100           \n" +
			"#line LINE200       \n";

		parse(code, getCLanguage(), true);
	}
	
	
	/**
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228826
	 * http://publib.boulder.ibm.com/infocenter/comphelp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.aix.doc/language_ref/restrict_type_qualifier.html
	 * 
	 * TODO Need a properties page so that things like this can be configured by the user.
	 */
	public void testRestrictC() {
		String code =
			"void foo(int n, int * restrict  a, int * __restrict b, int * __restrict__  c) {} ";

		parse(code, getCLanguage(), true);
	}
	public void testRestrictCPP() {
		String code =
			"void restrict(); \n " +
			"void __restrict(); \n " +
			"void __restrict__(); \n ";

		parse(code, getCPPLanguage(), true);
	}
	
	
	
	public void testUTFLiterals() {
		String code =
			"void test() { \n " +
			"  u\"ucs characters \\u1234 and \\u8180 \"; \n " +
			"  U\"ucs characters \\u1234 and \\u8180 \"; \n " +
			"  U\"concatenation \\u1234 \"  u\"is allowed \\u8180 \"; \n " +
			"  u'\\u1234'; \n " +
		    "  U'\\u1234'; \n " +
		    "}";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	
	public void testFloatingPoingTypes() {
		String code =
			"  _Decimal32 x = 22.2df; \n " +
			"  _Decimal64 y = 33.3dd; \n " +
			"  _Decimal128 z = 33.3dl; \n ";

		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true);
	}
	
	public void testVariableLengthArrays() {
		String code =
			"double maximum1(int n, int m, double a[n][m]);\n" +
			"double maximum2(int n, int m, double a[*][*]);\n" +
			"double maximum3(int n, int m, double a[ ][*]);\n" +
			"double maximum4(int n, int m, double a[ ][m]);\n";
		
		parse(code, getCLanguage(), true);
		parse(code, getCPPLanguage(), true); // xlc supports this in C++
	}
	
}

Back to the top