diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/.classpath b/upc/org.eclipse.cdt.core.parser.upc.tests/.classpath
new file mode 100644
index 00000000000..751c8f2e504
--- /dev/null
+++ b/upc/org.eclipse.cdt.core.parser.upc.tests/.classpath
@@ -0,0 +1,7 @@
+
+
February 8, 2007
+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/upc/org.eclipse.cdt.core.parser.upc.tests/build.properties b/upc/org.eclipse.cdt.core.parser.upc.tests/build.properties new file mode 100644 index 00000000000..d944674ba0b --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/plugin.properties b/upc/org.eclipse.cdt.core.parser.upc.tests/plugin.properties new file mode 100644 index 00000000000..d14f04519d2 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/plugin.properties @@ -0,0 +1,5 @@ +# properties file for org.eclipse.cdt.core.parser.c99.tests +Bundle-Vendor.0 = Eclipse.org +Bundle-Name.0 = C99 Parser Tests Plug-in + +upcSourceName=UPC Source File \ No newline at end of file diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/AutomatedIntegrationSuite.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/AutomatedIntegrationSuite.java new file mode 100644 index 00000000000..ad8ee7c9e42 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/AutomatedIntegrationSuite.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AutomatedIntegrationSuite extends TestSuite { + + public static Test suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(UPCC99CommentTests.class); + suite.addTestSuite(UPCC99CompletionBasicTest.class); + suite.addTestSuite(UPCC99CompletionParseTest.class); + suite.addTestSuite(UPCC99DOMLocationInclusionTests.class); + suite.addTestSuite(UPCC99DOMLocationMacroTests.class); + suite.addTestSuite(UPCC99DOMLocationTests.class); + suite.addTestSuite(UPCC99DOMPreprocessorInformationTest.class); + suite.addTestSuite(UPCC99KnRTests.class); + suite.addTestSuite(UPCC99SelectionParseTest.class); + suite.addTestSuite(UPCC99SpecTests.class); + suite.addTestSuite(UPCC99Tests.class); + suite.addTestSuite(UPCLanguageExtensionTests.class); + + return suite; + } +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CommentTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CommentTests.java new file mode 100644 index 00000000000..deddb9ecab8 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CommentTests.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99CommentTests; + +public class UPCC99CommentTests extends C99CommentTests { + + protected C99Language getC99Language() { + return new UPCLanguage(); + } + + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionBasicTest.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionBasicTest.java new file mode 100644 index 00000000000..679fbf0535d --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionBasicTest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99CompletionBasicTest; + +public class UPCC99CompletionBasicTest extends C99CompletionBasicTest { + + public UPCC99CompletionBasicTest() { + } + + protected C99Language getC99Language() { + return new UPCLanguage(); + } + + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionParseTest.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionParseTest.java new file mode 100644 index 00000000000..6e6c6fe5a62 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99CompletionParseTest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99CompletionParseTest; + +public class UPCC99CompletionParseTest extends C99CompletionParseTest { + + public UPCC99CompletionParseTest(String name) { + super(name); + } + + + protected C99Language getLanguage() { + return new UPCLanguage(); + } +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationInclusionTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationInclusionTests.java new file mode 100644 index 00000000000..3010aeec06c --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationInclusionTests.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99DOMLocationInclusionTests; + +public class UPCC99DOMLocationInclusionTests extends C99DOMLocationInclusionTests { + + protected C99Language getLanguage() { + return new UPCLanguage(); + } + + public UPCC99DOMLocationInclusionTests() { + } + + public UPCC99DOMLocationInclusionTests(String name, Class className) { + super(name, className); + } + + public UPCC99DOMLocationInclusionTests(String name) { + super(name); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationMacroTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationMacroTests.java new file mode 100644 index 00000000000..7a8ef7d6ebc --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationMacroTests.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99DOMLocationMacroTests; + +public class UPCC99DOMLocationMacroTests extends C99DOMLocationMacroTests { + + public UPCC99DOMLocationMacroTests() { + } + + protected C99Language getLanguage() { + return new UPCLanguage(); + } +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationTests.java new file mode 100644 index 00000000000..ce7f704adf4 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMLocationTests.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99DOMLocationTests; + +public class UPCC99DOMLocationTests extends C99DOMLocationTests { + + public UPCC99DOMLocationTests() { + } + + public UPCC99DOMLocationTests(String name) { + super(name); + } + + protected C99Language getC99Language() { + return new UPCLanguage(); + } +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMPreprocessorInformationTest.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMPreprocessorInformationTest.java new file mode 100644 index 00000000000..b349f80af0d --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99DOMPreprocessorInformationTest.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99DOMPreprocessorInformationTest; + +public class UPCC99DOMPreprocessorInformationTest extends + C99DOMPreprocessorInformationTest { + + protected C99Language getC99Language() { + return new UPCLanguage(); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99KnRTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99KnRTests.java new file mode 100644 index 00000000000..bf44178dceb --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99KnRTests.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99KnRTests; + +public class UPCC99KnRTests extends C99KnRTests { + + public UPCC99KnRTests() { + } + + protected C99Language getLanguage() { + return new UPCLanguage(); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SelectionParseTest.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SelectionParseTest.java new file mode 100644 index 00000000000..009e4c7ade4 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SelectionParseTest.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99SelectionParseTest; + +public class UPCC99SelectionParseTest extends C99SelectionParseTest { + + public UPCC99SelectionParseTest() { + } + + public UPCC99SelectionParseTest(String name, Class className) { + super(name, className); + } + + public UPCC99SelectionParseTest(String name) { + super(name); + } + + protected C99Language getLanguage() { + return new UPCLanguage(); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SpecTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SpecTests.java new file mode 100644 index 00000000000..8f9ed3d3f02 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99SpecTests.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.parser.c99.tests.C99SpecTests; + +public class UPCC99SpecTests extends C99SpecTests { + + public UPCC99SpecTests() { + } + + public UPCC99SpecTests(String name) { + super(name); + } + + protected C99Language getLanguage() { + return new UPCLanguage(); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99Tests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99Tests.java new file mode 100644 index 00000000000..bfae72d3a59 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCC99Tests.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import org.eclipse.cdt.core.parser.c99.tests.C99Tests; +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +/** + * Run the C99 tests against the UPC parser + * + */ +public class UPCC99Tests extends C99Tests { + + public UPCC99Tests(String name) { + super(name); + } + + protected C99Language getC99Language() { + return new UPCLanguage(); + } + +} diff --git a/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCLanguageExtensionTests.java b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCLanguageExtensionTests.java new file mode 100644 index 00000000000..5485e3ed6b2 --- /dev/null +++ b/upc/org.eclipse.cdt.core.parser.upc.tests/src/org/eclipse/cdt/core/parser/upc/tests/UPCLanguageExtensionTests.java @@ -0,0 +1,498 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 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.upc.tests; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.dom.ast.*; +import org.eclipse.cdt.core.dom.c99.C99Language; +import org.eclipse.cdt.core.dom.upc.UPCLanguage; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTDeclSpecifier; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTForallStatement; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTKeywordExpression; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTSizeofExpression; +import org.eclipse.cdt.core.dom.upc.ast.IUPCASTSynchronizationStatement; +import org.eclipse.cdt.core.parser.c99.tests.ParseHelper; +import org.eclipse.cdt.internal.core.parser.ParserException; + +public class UPCLanguageExtensionTests extends TestCase { + + public UPCLanguageExtensionTests() { + } + + public UPCLanguageExtensionTests(String name) { + super(name); + } + + + protected C99Language getLanguage() { + return new UPCLanguage(); + } + + // test problem-free parsing of UPC constructs (maily declarations) + // test the AST is correct + // test that binding resolution works + + private IASTTranslationUnit parseAndCheckBindings(String code) throws ParserException { + return ParseHelper.parse(code, getLanguage(), true, true, 0 ); + } + + + private IASTTranslationUnit parse(String code) throws ParserException { + return ParseHelper.parse(code, getLanguage(), true, false, 0 ); + } + + + public void testUPCSharedDeclarations1() throws Exception { + StringBuffer sb = new StringBuffer(); + sb.append("shared int a [100+THREADS];\n");//$NON-NLS-1$ + sb.append("shared [] int b [THREADS];\n");//$NON-NLS-1$ + sb.append("shared [90] int c [10];\n");//$NON-NLS-1$ + sb.append("shared [*] int d [];\n");//$NON-NLS-1$ + sb.append("relaxed int x;");//$NON-NLS-1$ + sb.append("strict int y;");//$NON-NLS-1$ + String code = sb.toString(); + + IASTTranslationUnit tu = parseAndCheckBindings(code); + IScope globalScope = tu.getScope(); + assertNotNull(globalScope); + + IASTDeclaration[] declarations = tu.getDeclarations(); + assertNotNull(declarations); + assertEquals(6, declarations.length); + + // shared int a [100+THREADS]; + IASTSimpleDeclaration decl_a = (IASTSimpleDeclaration) declarations[0]; + IUPCASTSimpleDeclSpecifier declspec_a = (IUPCASTSimpleDeclSpecifier) decl_a.getDeclSpecifier(); + assertEquals(IUPCASTDeclSpecifier.rt_unspecified, declspec_a.getReferenceType()); + assertEquals(IUPCASTDeclSpecifier.sh_shared_default_block_size, declspec_a.getSharedQualifier()); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_a.getType()); + assertNull(declspec_a.getBlockSizeExpression()); + IASTDeclarator[] declarators = decl_a.getDeclarators(); + assertNotNull(declarators); + assertEquals(1, declarators.length); + IASTArrayDeclarator declarator_a = (IASTArrayDeclarator) declarators[0]; + IASTName name_a = declarator_a.getName(); + assertEquals("a", name_a.toString());//$NON-NLS-1$ + IASTArrayModifier[] array_modifiers = declarator_a.getArrayModifiers(); + assertNotNull(array_modifiers); + assertEquals(1, array_modifiers.length); + IASTBinaryExpression expr = (IASTBinaryExpression) array_modifiers[0].getConstantExpression(); + IUPCASTKeywordExpression threads = (IUPCASTKeywordExpression) expr.getOperand2(); + assertEquals(IUPCASTKeywordExpression.kw_threads, threads.getKeywordKind()); + + // shared [] int b [THREADS]; + IASTSimpleDeclaration decl_b = (IASTSimpleDeclaration) declarations[1]; + IUPCASTSimpleDeclSpecifier declspec_b = (IUPCASTSimpleDeclSpecifier) decl_b.getDeclSpecifier(); + assertEquals(IUPCASTDeclSpecifier.rt_unspecified, declspec_b.getReferenceType()); + assertEquals(IUPCASTDeclSpecifier.sh_shared_indefinite_allocation, declspec_b.getSharedQualifier()); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_b.getType()); + assertNull(declspec_b.getBlockSizeExpression()); + declarators = decl_b.getDeclarators(); + assertNotNull(declarators); + assertEquals(1, declarators.length); + IASTArrayDeclarator declarator_b = (IASTArrayDeclarator) declarators[0]; + IASTName name_b = declarator_b.getName(); + assertEquals("b", name_b.toString());//$NON-NLS-1$ + array_modifiers = declarator_b.getArrayModifiers(); + assertNotNull(array_modifiers); + assertEquals(1, array_modifiers.length); + threads = (IUPCASTKeywordExpression) array_modifiers[0].getConstantExpression(); + assertEquals(IUPCASTKeywordExpression.kw_threads, threads.getKeywordKind()); + + // shared [90] int c [10]; + IASTSimpleDeclaration decl_c = (IASTSimpleDeclaration) declarations[2]; + IUPCASTSimpleDeclSpecifier declspec_c = (IUPCASTSimpleDeclSpecifier) decl_c.getDeclSpecifier(); + assertEquals(IUPCASTDeclSpecifier.rt_unspecified, declspec_c.getReferenceType()); + assertEquals(IUPCASTDeclSpecifier.sh_shared_constant_expression, declspec_c.getSharedQualifier()); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_c.getType()); + IASTLiteralExpression literalExpr = (IASTLiteralExpression) declspec_c.getBlockSizeExpression(); + declarators = decl_c.getDeclarators(); + assertNotNull(declarators); + assertEquals(1, declarators.length); + IASTArrayDeclarator declarator_c = (IASTArrayDeclarator) declarators[0]; + IASTName name_c = declarator_c.getName(); + assertEquals("c", name_c.toString());//$NON-NLS-1$ + array_modifiers = declarator_c.getArrayModifiers(); + assertNotNull(array_modifiers); + assertEquals(1, array_modifiers.length); + assertNotNull(array_modifiers[0].getConstantExpression()); + + // shared [*] int d []; + IASTSimpleDeclaration decl_d = (IASTSimpleDeclaration) declarations[3]; + IUPCASTSimpleDeclSpecifier declspec_d = (IUPCASTSimpleDeclSpecifier) decl_d.getDeclSpecifier(); + assertEquals(IUPCASTDeclSpecifier.rt_unspecified, declspec_d.getReferenceType()); + assertEquals(IUPCASTDeclSpecifier.sh_shared_pure_allocation, declspec_d.getSharedQualifier()); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_d.getType()); + assertNull(declspec_d.getBlockSizeExpression()); + declarators = decl_d.getDeclarators(); + assertNotNull(declarators); + assertEquals(1, declarators.length); + IASTArrayDeclarator declarator_d = (IASTArrayDeclarator) declarators[0]; + IASTName name_d = declarator_d.getName(); + assertEquals("d", name_d.toString());//$NON-NLS-1$ + array_modifiers = declarator_d.getArrayModifiers(); + assertNotNull(array_modifiers); + assertEquals(1, array_modifiers.length); + assertNull(array_modifiers[0].getConstantExpression()); + + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[4]; + IUPCASTSimpleDeclSpecifier declspec_x = (IUPCASTSimpleDeclSpecifier) decl_x.getDeclSpecifier(); + assertEquals(IUPCASTSimpleDeclSpecifier.rt_relaxed, declspec_x.getReferenceType()); + + IASTSimpleDeclaration decl_y = (IASTSimpleDeclaration) declarations[5]; + IUPCASTSimpleDeclSpecifier declspec_y = (IUPCASTSimpleDeclSpecifier) decl_y.getDeclSpecifier(); + assertEquals(IUPCASTSimpleDeclSpecifier.rt_strict, declspec_y.getReferenceType()); + + + IVariable binding_a = (IVariable) name_a.resolveBinding(); + assertNotNull(binding_a); + assertEquals(globalScope, binding_a.getScope()); + + IVariable binding_b = (IVariable) name_a.resolveBinding(); + assertNotNull(binding_b); + assertEquals(globalScope, binding_b.getScope()); + + IVariable binding_c = (IVariable) name_a.resolveBinding(); + assertNotNull(binding_c); + assertEquals(globalScope, binding_c.getScope()); + + IVariable binding_d = (IVariable) name_a.resolveBinding(); + assertNotNull(binding_d); + assertEquals(globalScope, binding_d.getScope()); + + } + + + + public void testUPCSharedDeclarations2() throws Exception { + StringBuffer sb = new StringBuffer(); + sb.append("int x = 10;");//$NON-NLS-1$ + sb.append("shared [x] int a [];\n");//$NON-NLS-1$ + String code = sb.toString(); + + IASTTranslationUnit tu = parseAndCheckBindings(code); + IScope globalScope = tu.getScope(); + assertNotNull(globalScope); + + IASTDeclaration[] declarations = tu.getDeclarations(); + assertNotNull(declarations); + assertEquals(2, declarations.length); + + IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) declarations[0]; + + // shared [x] int a []; + IASTSimpleDeclaration decl_a = (IASTSimpleDeclaration) declarations[1]; + IUPCASTSimpleDeclSpecifier declspec_a = (IUPCASTSimpleDeclSpecifier) decl_a.getDeclSpecifier(); + assertEquals(IUPCASTDeclSpecifier.rt_unspecified, declspec_a.getReferenceType()); + assertEquals(IUPCASTDeclSpecifier.sh_shared_constant_expression, declspec_a.getSharedQualifier()); + assertEquals(IASTSimpleDeclSpecifier.t_int, declspec_a.getType()); + IASTIdExpression expr_x = (IASTIdExpression) declspec_a.getBlockSizeExpression(); + + IASTName name_x = expr_x.getName(); + IVariable binding_x = (IVariable) name_x.resolveBinding(); + assertNotNull(binding_x); + assertEquals(decl_x.getDeclarators()[0].getName().resolveBinding(), binding_x); + } + + + + public void testUPCForall1() throws Exception { + StringBuffer sb = new StringBuffer(); + sb.append("int main() {\n");//$NON-NLS-1$ + sb.append(" int i;\n");//$NON-NLS-1$ + sb.append(" shared float *a;\n");//$NON-NLS-1$ + sb.append(" upc_forall(i=0; i