Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: da1d30aae86ce3850f263f8108701f0cd26656cc (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
/*******************************************************************************
 * 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;

import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;


public class VectorExtensionsTest extends XLCTestBase {

	public VectorExtensionsTest() {
	}
	
	public VectorExtensionsTest(String name) {
		super(name);
	}
	
    	
    
    public void testVector1() {
    	String code =
    		"int test() {  \n" +
    		"   vector unsigned int a = {1,2,3,4};  \n" +
    		"   vector unsigned int b = {2,4,6,8};  \n" +
    		"   vector unsigned int c = a + b;      \n" +
    		"   int e = b > a;                      \n" +
    		"   int f = a[2];                       \n" +
    		"   vector unsigned int d = ++a;        \n" +
    		"}\n";

    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void testVectorDeclarations() {
    	String code =
    		"vector unsigned char a;	  \n" +
    		"vector signed char b;  \n" +
    		"vector bool char c;	  \n" +
    		"vector unsigned short d; 	  \n" +
    		"vector unsigned short int e;  \n" +
    		"vector signed short f;  \n" +
    		"vector signed short int g;  \n" +
    		"vector bool short h;	  \n" +
    		"vector bool short int i;  \n" +
    		"vector unsigned int j;  \n" +
    		"vector unsigned long k;  \n" +
    		"vector unsigned long int l;  \n" +
    		"vector signed int m;  \n" +
    		"vector signed long n;  \n" +
    		"vector signed long int o;  \n" +
    		"vector bool int p;  \n" +
    		"vector bool long q;  \n" +
    		"vector bool long int r;  \n" +
    		"vector float s;  \n" +
    		"vector pixel t;  \n" +
    		"__vector __pixel u;  \n";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    // these are only treated as keywords inside a vector declaration
    public void testReservedWords() {
    	String code = 
    		"int pixel; " +
    		"int bool;  ";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    
    public void testVectorLiterals() {
    	String code = 
    		"int test() {" +
    		"    (vector unsigned int)(10); " +
    		"    (vector unsigned int)(14, 82, 73, 700); " +
    		"    (vector pixel)(14, 82, 73, 700); " +
    		"    (vector bool int)(10); " +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void testVectorInitializers() {
    	String code = 
    		"int test() {" +
    		"    vector unsigned int v3 = {1,2,3,4}; " +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
   
    
    public void testVectorTypedefs() {
    	String code = 
    		"int test() {" +
    		"     typedef vector pixel vint16; " +
    		"     vint16 v1;" +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void testVectorCompoundLiterals() {
    	String code = 
    		"int test() {" +
    		"    (vector unsigned int){10}; " +
    		"    (vector unsigned int){14, 82, 73, 700}; " +
    		"    (vector pixel){14, 82, 73, 700}; " +
    		"    (vector bool int){10}; " +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void testVectorAlignof() {
    	String code = 
    		"int test() {" +
    		"   vector unsigned int v1 = (vector unsigned int)(10);  \n" +
    		"   vector unsigned int *pv1 = &v1;  \n" +
    		"   __alignof__(v1); \n" +
    		"   __alignof__(&v1);  \n" +
    		"   __alignof__(*pv1);  \n" +
    		"   __alignof__(pv1);  \n" +
    		"   __alignof__(vector signed char);  \n" +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void testVectorTypeof() {
    	String code = 
    		"int test() {" +
    		"   vector unsigned int v1 = (vector unsigned int)(10);  \n" +
    		"   vector unsigned int *pv1 = &v1;  \n" +
    		"   __typeof__(v1); \n" +
    		"   __typeof__(&v1);  \n" +
    		"   __typeof__(*pv1);  \n" +
    		"   __typeof__(pv1);  \n" +
    		"   __typeof__(vector signed char);  \n" +
    		"}";
    
    	parse(code, getCLanguage(), true);
    	parse(code, getCPPLanguage(), true);
    }
    
    public void _testOverloads() {
    	String code =
    		"void foo(int); \n" +
    		"void foo(vector unsigned int); \n" +
    		"void foo(vector pixel) \n" +
    		"int test() { \n" +
    		"    int x; \n" +
    		"    vector unsigned int y; \n" +
    		"    vector pixel z; \n" +
    		"    foo(x); \n" +
    		"    foo(y); \n" +
    		"    foo(z); \n" +
    		"} \n";
    	
    	IASTTranslationUnit tu = parse(code, getCPPLanguage(), true);
    	
    	
    	IASTDeclaration[] decls = tu.getDeclarations();
    	IASTName foo1 = ((IASTSimpleDeclaration)decls[0]).getDeclarators()[0].getName();
    	IASTName foo2 = ((IASTSimpleDeclaration)decls[1]).getDeclarators()[0].getName();
    	IASTName foo3 = ((IASTSimpleDeclaration)decls[2]).getDeclarators()[0].getName();
    	
    	IASTFunctionDefinition func = (IASTFunctionDefinition) decls[4];
    	IASTStatement[] stats = ((IASTCompoundStatement)func.getBody()).getStatements();
    	
    	IASTName fooCall1 = ((IASTIdExpression)((IASTFunctionCallExpression)((IASTExpressionStatement)stats[3]).getExpression()).getFunctionNameExpression()).getName();
    	IASTName fooCall2 = ((IASTIdExpression)((IASTFunctionCallExpression)((IASTExpressionStatement)stats[4]).getExpression()).getFunctionNameExpression()).getName();
    	IASTName fooCall3 = ((IASTIdExpression)((IASTFunctionCallExpression)((IASTExpressionStatement)stats[5]).getExpression()).getFunctionNameExpression()).getName();
    	
    	assertSame(foo1.resolveBinding(), fooCall1.resolveBinding());
    	assertSame(foo2.resolveBinding(), fooCall2.resolveBinding());
    	assertSame(foo3.resolveBinding(), fooCall3.resolveBinding());
    }
}

Back to the top