diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/.classpath b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/.classpath
new file mode 100644
index 00000000000..64c5e31b7a2
--- /dev/null
+++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/.classpath
@@ -0,0 +1,7 @@
+
+
April 17, 2009
+The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.
+ +If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.
+ + \ No newline at end of file diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/build.properties b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/build.properties new file mode 100644 index 00000000000..6e948c2375e --- /dev/null +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/build.properties @@ -0,0 +1,15 @@ +############################################################################### +# 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 +############################################################################### + +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/VectorExtensionsTest.java b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/VectorExtensionsTest.java new file mode 100644 index 00000000000..da1d30aae86 --- /dev/null +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/VectorExtensionsTest.java @@ -0,0 +1,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()); + } +} diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCExtensionsTest.java b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCExtensionsTest.java new file mode 100644 index 00000000000..2a90e5d1299 --- /dev/null +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCExtensionsTest.java @@ -0,0 +1,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++ + } + +} diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCParserTestSuite.java b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCParserTestSuite.java new file mode 100644 index 00000000000..933bffbc089 --- /dev/null +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCParserTestSuite.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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 junit.framework.Test; +import junit.framework.TestSuite; + +public class XLCParserTestSuite { + + + public static Test suite() { + return new TestSuite() {{ + addTestSuite(VectorExtensionsTest.class); + addTestSuite(XLCExtensionsTest.class); + }}; + } +} \ No newline at end of file diff --git a/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCTestBase.java b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCTestBase.java new file mode 100644 index 00000000000..5d6b8fe4b76 --- /dev/null +++ b/xlc/org.eclipse.cdt.core.lrparser.xlc.tests/src/org/eclipse/cdt/core/parser/xlc/tests/XLCTestBase.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 junit.framework.TestCase; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.lrparser.tests.ParseHelper; +import org.eclipse.cdt.core.lrparser.xlc.XlcCLanguage; +import org.eclipse.cdt.core.lrparser.xlc.XlcCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; + +public class XLCTestBase extends TestCase { + + public XLCTestBase() { + } + + public XLCTestBase(String name) { + super(name); + } + + protected IASTTranslationUnit parse(String code, ILanguage language, boolean checkBindings) { + ParseHelper.Options options = new ParseHelper.Options(); + options.setCheckSyntaxProblems(true); + options.setCheckPreprocessorProblems(true); + options.setCheckBindings(checkBindings); + return ParseHelper.parse(code, language, options); + } + + protected XlcCLanguage getCLanguage() { + return XlcCLanguage.getDefault(); + } + + protected XlcCPPLanguage getCPPLanguage() { + return XlcCPPLanguage.getDefault(); + } + +}