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/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties b/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties
new file mode 100644
index 00000000000..185a840ec69
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/build.properties
@@ -0,0 +1,16 @@
+###############################################################################
+# Copyright (c) 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
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties b/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties
new file mode 100644
index 00000000000..b09765a2e51
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/plugin.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 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
+###############################################################################
+# 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/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ActionTestSuite.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ActionTestSuite.java
new file mode 100644
index 00000000000..6262e2735da
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ActionTestSuite.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser.action.c99;
+
+import org.eclipse.cdt.core.dom.lrparser.action.c99.SymbolTableTests;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ActionTestSuite extends TestSuite {
+
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+
+ suite.addTestSuite(SymbolTableTests.class);
+ suite.addTestSuite(ResolverActionTests.class);
+
+ return suite;
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ResolverActionTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ResolverActionTests.java
new file mode 100644
index 00000000000..a2524edf6c3
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/ResolverActionTests.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser.action.c99;
+
+import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.TK_identifier;
+import static org.eclipse.cdt.internal.core.dom.lrparser.c99.C99Parsersym.TK_int;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import lpg.lpgjavaruntime.IToken;
+import lpg.lpgjavaruntime.Token;
+
+import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
+
+public class ResolverActionTests extends TestCase {
+
+ /**
+ * We are testing the parser actions in isolation without running
+ * an actual parser, therefore we need to mock out the parser object.
+ */
+ private static class MockParser implements IParserActionTokenProvider {
+
+ public List ruleTokens;
+
+ public MockParser(Object ... tokenTypes) {
+ this.ruleTokens = tokens(tokenTypes);
+ }
+ public List getCommentTokens() {
+ return null;
+ }
+ public IToken getEOFToken() {
+ return null;
+ }
+ public IToken getLeftIToken() {
+ return ruleTokens.get(0);
+ }
+ public IToken getRightIToken() {
+ return ruleTokens.get(ruleTokens.size()-1);
+ }
+ public List getRuleTokens() {
+ return ruleTokens;
+ }
+ public void setRuleTokens(Object ... tokenTypes) {
+ this.ruleTokens = tokens(tokenTypes);
+ }
+ static List tokens(Object[] tokenTypes) {
+ List tokens = new ArrayList();
+ if(tokenTypes == null)
+ return tokens;
+
+ for(final Object o : tokenTypes) {
+ IToken token;
+ if(o instanceof Integer)
+ token = new Token(0, 0, ((Integer)o).intValue());
+ else if(o instanceof String)
+ token = new Token(0, 0, TK_identifier) {
+ @Override public String toString() {
+ return o.toString();
+ }
+ };
+ else
+ throw new AssertionFailedError();
+
+ tokens.add(token);
+ }
+ return tokens;
+ }
+ }
+
+
+ /**
+ * Parsing: int x;, then undo, then parse again
+ */
+ @SuppressWarnings("deprecation")
+ public void testResolverActions1() {
+ MockParser mockParser = new MockParser();
+ C99ResolveParserAction action = new C99ResolveParserAction(mockParser);
+
+ mockParser.setRuleTokens(TK_int);
+ action.openDeclarationScope();
+ action.consumeDeclSpecToken();
+ mockParser.setRuleTokens("x");
+ action.consumeDirectDeclaratorIdentifier();
+ action.consumeDeclaratorComplete();
+ action.closeDeclarationScope();
+
+ C99SymbolTable symbolTable;
+ symbolTable = action.getSymbolTable();
+ assertEquals(1, symbolTable.size());
+ C99Variable binding = (C99Variable) symbolTable.lookup(CNamespace.IDENTIFIER, "x");
+ assertEquals("x", binding.getName());
+
+ // cool, now undo!
+ assertEquals(5, action.undoStackSize());
+ action.undo(5);
+ assertEquals(0, action.undoStackSize());
+ assertEquals(0, action.getDeclarationStack().size());
+ symbolTable = action.getSymbolTable();
+ assertTrue(symbolTable.isEmpty());
+
+ // rerun
+ mockParser.setRuleTokens(TK_int);
+ action.openDeclarationScope();
+ action.consumeDeclSpecToken();
+ mockParser.setRuleTokens("x");
+ action.consumeDirectDeclaratorIdentifier();
+ action.consumeDeclaratorComplete();
+ action.closeDeclarationScope();
+
+ symbolTable = action.getSymbolTable();
+ assertEquals(1, symbolTable.size());
+ binding = (C99Variable) symbolTable.lookup(CNamespace.IDENTIFIER, "x");
+ assertEquals("x", binding.getName());
+ }
+}
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/SymbolTableTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/SymbolTableTests.java
new file mode 100644
index 00000000000..1dee48b6215
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/dom/lrparser/action/c99/SymbolTableTests.java
@@ -0,0 +1,152 @@
+package org.eclipse.cdt.core.dom.lrparser.action.c99;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.lrparser.action.FunctionalMap;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Label;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Structure;
+import org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings.C99Variable;
+
+@SuppressWarnings("deprecation")
+public class SymbolTableTests extends TestCase {
+ // TODO write tests for imperative symbol table
+
+ private final String[] KEYS = { "pantera", "soulfly", "inflames", "megadeth", "archenemy", "carcass" };
+
+ public void testPersistence() {
+ FunctionalMap st0 = FunctionalMap.emptyMap();
+ assertTrue(st0.isEmpty());
+
+ FunctionalMap st1 = st0.insert(KEYS[0], 1);
+
+ // empty symbol table does not change
+ assertTrue(st0.isEmpty());
+ assertNull(st0.lookup(KEYS[1]));
+
+ // a new symbol table was created
+ assertFalse(st1.isEmpty());
+ assertEquals(new Integer(1), st1.lookup(KEYS[0]));
+
+ FunctionalMap st2 = st1.insert(KEYS[1], 2);
+ FunctionalMap st3 = st2.insert(KEYS[2], 3);
+ FunctionalMap st4 = st3.insert(KEYS[3], 4);
+ FunctionalMap st5 = st4.insert(KEYS[4], 5);
+
+ assertMap(st0, KEYS, new Integer[] {null, null, null, null, null, null} );
+ assertMap(st1, KEYS, new Integer[] {1, null, null, null, null, null} );
+ assertMap(st2, KEYS, new Integer[] {1, 2, null, null, null, null} );
+ assertMap(st3, KEYS, new Integer[] {1, 2, 3, null, null, null} );
+ assertMap(st4, KEYS, new Integer[] {1, 2, 3, 4, null, null} );
+ assertMap(st5, KEYS, new Integer[] {1, 2, 3, 4, 5, null} );
+ }
+
+
+
+ public void testOverride() {
+ FunctionalMap map1 = FunctionalMap.emptyMap();
+ for(int i = 0; i < KEYS.length; i++) {
+ map1 = map1.insert(KEYS[i], i);
+ }
+
+ assertMap(map1, KEYS, new Integer[] {0, 1, 2, 3, 4, 5});
+
+ FunctionalMap map2 = map1.insert(KEYS[5], 999);
+ FunctionalMap map3 = map2.insert(KEYS[5], null);
+
+ assertEquals(new Integer(5), map1.lookup(KEYS[5]));
+ assertEquals(new Integer(999), map2.lookup(KEYS[5]));
+ assertNull(map3.lookup(KEYS[5]));
+ }
+
+
+ private static void assertMap(FunctionalMap map, Comparable[] keys, Object[] vals) {
+ assert keys.length == vals.length;
+
+ for(int i = 0; i < keys.length; i++) {
+ assertEquals( "the key '" + keys[i] + "' did not match", vals[i], map.lookup((keys[i])));
+ if(vals[i] != null) {
+ assertTrue("key '" + keys[i] + "' not in map", map.containsKey(keys[i]));
+ }
+ }
+ }
+
+
+ public void testFunctionalSymbolTable1() {
+ C99SymbolTable st = C99SymbolTable.EMPTY_TABLE;
+
+ for(String key : KEYS) {
+ st = st.insert(CNamespace.IDENTIFIER, key, new C99Variable(key));
+ }
+ for(String key : KEYS) {
+ st = st.insert(CNamespace.GOTO_LABEL, key, new C99Label(key));
+ }
+ for(String key : KEYS) {
+ st = st.insert(CNamespace.STRUCT_TAG, key, new C99Structure(key));
+ }
+
+ assertFunctionalSymbolTableContainsAllThePairs(st);
+ }
+
+ public void testFunctionalSymbolTable2() {
+ C99SymbolTable st = C99SymbolTable.EMPTY_TABLE;
+
+ // same test as above but this time we insert the keys in a different order
+ for(String key : KEYS) {
+ st = st.insert(CNamespace.IDENTIFIER, key, new C99Variable(key));
+ st = st.insert(CNamespace.GOTO_LABEL, key, new C99Label(key));
+ st = st.insert(CNamespace.STRUCT_TAG, key, new C99Structure(key));
+ }
+
+ assertFunctionalSymbolTableContainsAllThePairs(st);
+ }
+
+ private void assertFunctionalSymbolTableContainsAllThePairs(C99SymbolTable st) {
+ assertEquals(KEYS.length * 3, st.size());
+ for(String key : KEYS) {
+ IBinding b = st.lookup(CNamespace.IDENTIFIER, key);
+ assertNotNull(b);
+ C99Variable x = (C99Variable)b;
+ assertEquals(key, x.getName());
+ }
+ for(String key : KEYS) {
+ IBinding b = st.lookup(CNamespace.GOTO_LABEL, key);
+ assertNotNull(b);
+ C99Label x = (C99Label)b;
+ assertEquals(key, x.getName());
+ }
+ for(String key : KEYS) {
+ IBinding b = st.lookup(CNamespace.STRUCT_TAG, key);
+ assertNotNull(b);
+ C99Structure x = (C99Structure)b;
+ assertEquals(key, x.getName());
+ }
+ }
+
+
+ public void testProperFail() {
+ FunctionalMap map = FunctionalMap.emptyMap();
+ try {
+ map.insert(null, 99);
+ fail();
+ } catch (NullPointerException _) {}
+
+ try {
+ map.containsKey(null);
+ fail();
+ } catch (NullPointerException _) {}
+
+ try {
+ map.lookup(null);
+ fail();
+ } catch (NullPointerException _) {}
+
+ C99SymbolTable table = C99SymbolTable.EMPTY_TABLE;
+ try {
+ table.insert(null, null, new C99Variable("blah")); //$NON-NLS-1$
+ fail();
+ } catch (NullPointerException _) {}
+
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/Activator.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/Activator.java
new file mode 100644
index 00000000000..c4b48fd8096
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/Activator.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.cdt.core.parser.c99.tests";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CommentTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CommentTests.java
new file mode 100644
index 00000000000..79dfdf8ffd6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CommentTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.CommentTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99CommentTests extends CommentTests {
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
+ throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected IASTTranslationUnit parse(String code, ParserLanguage lang,
+ boolean useGNUExtensions, boolean expectNoProblems,
+ boolean parseComments) throws ParserException {
+
+
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems, parseComments);
+
+ return ParseHelper.commentParse(code, getLanguage());
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ public void testBug191266() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append("#define MACRO 1000000000000 \n");
+ sb.append("int x = MACRO; \n");
+ sb.append("//comment\n");
+ String code = sb.toString();
+
+ IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, false, true);
+
+ IASTComment[] comments = tu.getComments();
+ assertEquals(1, comments.length);
+
+ IASTFileLocation location = comments[0].getFileLocation();
+ assertEquals(code.indexOf("//"), location.getNodeOffset());
+ assertEquals("//comment".length(), location.getNodeLength());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompleteParser2Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompleteParser2Tests.java
new file mode 100644
index 00000000000..f1c622010b5
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompleteParser2Tests.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.CompleteParser2Tests;
+
+public class C99CompleteParser2Tests extends CompleteParser2Tests {
+
+ protected IASTTranslationUnit parse(String code, boolean expectedToPass,
+ ParserLanguage lang, boolean gcc) throws Exception {
+
+ if(lang != ParserLanguage.C)
+ return super.parse(code, expectedToPass, lang, gcc);
+
+ return ParseHelper.parse(code, getLanguage(), expectedToPass);
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ // Tests that are failing at this point
+
+ public void testBug39676_tough() { // is this C99?
+ try {
+ super.testBug39676_tough();
+ } catch(AssertionFailedError _) {
+ return;
+ } catch(Exception _) {
+ return;
+ }
+
+ fail();
+ }
+
+// public void testPredefinedSymbol_bug70928_infinite_loop_test1() throws Exception { // gcc extension
+// try {
+// super.testPredefinedSymbol_bug70928_infinite_loop_test1();
+// fail();
+// } catch(AssertionError _) { }
+// }
+//
+// public void testPredefinedSymbol_bug70928_infinite_loop_test2() throws Exception { // gcc extension
+// try {
+// super.testPredefinedSymbol_bug70928_infinite_loop_test2();
+// fail();
+// } catch(AssertionError _) { }
+// }
+//
+//
+// public void testBug102376() throws Exception { // gcc extension
+// try {
+// super.testBug102376();
+// fail();
+// } catch(AssertionError _) { }
+// }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionBasicTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionBasicTest.java
new file mode 100644
index 00000000000..5d9ab1467b3
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionBasicTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.prefix.BasicCompletionTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99CompletionBasicTest extends BasicCompletionTest {
+
+ public C99CompletionBasicTest() { }
+
+
+ protected IASTCompletionNode getCompletionNode(String code,
+ ParserLanguage lang, boolean useGNUExtensions)
+ throws ParserException {
+
+ if(ParserLanguage.C == lang) {
+ return ParseHelper.getCompletionNode(code, getLanguage());
+ }
+ else {
+ // TODO: parsing of C++
+ return super.getCompletionNode(code, lang, useGNUExtensions);
+ }
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+ // The C99 parser currently doesn't support ambiguity nodes.
+ // Therefore calling IASTCompletionNode.getNames() will
+ // never return more than one name.
+
+
+ @Override
+ public void testFunction() throws Exception {
+ StringBuffer code = new StringBuffer();
+ code.append("void func(int x) { }");//$NON-NLS-1$
+ code.append("void func2() { fu");//$NON-NLS-1$
+
+ // C
+ IASTCompletionNode node = getGCCCompletionNode(code.toString());
+ IASTName[] names = node.getNames();
+
+ // There is only one name, for now
+ assertEquals(1, names.length);
+ // The expression points to our functions
+ IBinding[] bindings = sortBindings(names[0].getCompletionContext().findBindings(names[0], true));
+ // There should be two since they both start with fu
+ assertEquals(2, bindings.length);
+ assertEquals("func", ((IFunction)bindings[0]).getName());//$NON-NLS-1$
+ assertEquals("func2", ((IFunction)bindings[1]).getName());//$NON-NLS-1$
+
+ }
+
+ @Override
+ public void testTypedef() throws Exception {
+ StringBuffer code = new StringBuffer();
+ code.append("typedef int blah;");//$NON-NLS-1$
+ code.append("bl");//$NON-NLS-1$
+
+ // C
+ IASTCompletionNode node = getGCCCompletionNode(code.toString());
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+ IBinding[] bindings = names[0].getCompletionContext().findBindings(names[0], true);
+ assertEquals(1, bindings.length);
+ assertEquals("blah", ((ITypedef)bindings[0]).getName());//$NON-NLS-1$
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionParseTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionParseTest.java
new file mode 100644
index 00000000000..ecb9846b3f6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99CompletionParseTest.java
@@ -0,0 +1,424 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
+import org.eclipse.cdt.core.dom.ast.IField;
+import org.eclipse.cdt.core.dom.ast.ITypedef;
+import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+
+
+/**
+ * Reuse the completion parse tests from the old parser for now.
+ *
+ * This test suite is specific to C99.
+ */
+public class C99CompletionParseTest extends TestCase {
+
+ public C99CompletionParseTest() { }
+ public C99CompletionParseTest(String name) { super(name); }
+
+
+ protected IASTCompletionNode parse(String code, int offset) throws Exception {
+ return ParseHelper.getCompletionNode(code, getLanguage(), offset);
+ }
+
+
+ private static class BindingsComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ IBinding b1 = (IBinding)o1;
+ IBinding b2 = (IBinding)o2;
+ return b1.getName().compareTo(b2.getName());
+ }
+ }
+
+ private static BindingsComparator bindingsComparator = new BindingsComparator();
+
+ protected IBinding[] sortBindings(IBinding[] bindings) {
+ Arrays.sort(bindings, bindingsComparator);
+ return bindings;
+ }
+
+ protected IBinding[] getBindings(IASTName[] names) {
+ return sortBindings(names[0].getCompletionContext().findBindings(names[0], true));
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ // First steal tests from CompletionParseTest
+
+
+ public void testCompletionStructField() throws Exception
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "int aVar; " ); //$NON-NLS-1$
+ sb.append( "struct D{ " ); //$NON-NLS-1$
+ sb.append( " int aField1; " ); //$NON-NLS-1$
+ sb.append( " int aField2; " ); //$NON-NLS-1$
+ sb.append( "}; " ); //$NON-NLS-1$
+ sb.append( "void foo(){" ); //$NON-NLS-1$
+ sb.append( " struct D d; " ); //$NON-NLS-1$
+ sb.append( " d.a " ); //$NON-NLS-1$
+ sb.append( "}\n" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf( "d.a" ); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index + 3 );
+ assertNotNull( node );
+
+ String prefix = node.getPrefix();
+ assertNotNull( prefix );
+ assertEquals( prefix, "a" ); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("aField1", ((IField)bindings[0]).getName());
+ assertEquals("aField2", ((IField)bindings[1]).getName());
+ }
+
+ public void testCompletionStructFieldPointer() throws Exception
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("struct Cube { "); //$NON-NLS-1$
+ sb.append(" int nLen; "); //$NON-NLS-1$
+ sb.append(" int nWidth; "); //$NON-NLS-1$
+ sb.append(" int nHeight; "); //$NON-NLS-1$
+ sb.append("}; "); //$NON-NLS-1$
+ sb.append("int volume( struct Cube * pCube ) { "); //$NON-NLS-1$
+ sb.append(" pCube->SP "); //$NON-NLS-1$
+
+ String code = sb.toString();
+ IASTCompletionNode node = parse( code, code.indexOf("SP")); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("nHeight", ((IField)bindings[0]).getName());
+ assertEquals("nLen", ((IField)bindings[1]).getName());
+ assertEquals("nWidth", ((IField)bindings[2]).getName());
+ }
+
+
+ public void testCompletionParametersAsLocalVariables() throws Exception{
+ StringBuffer sb = new StringBuffer();
+ sb.append( "int foo( int aParameter ){" ); //$NON-NLS-1$
+ sb.append( " int aLocal;" ); //$NON-NLS-1$
+ sb.append( " if( aLocal != 0 ){" ); //$NON-NLS-1$
+ sb.append( " int aBlockLocal;" ); //$NON-NLS-1$
+ sb.append( " a \n" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf( " a " ); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index + 2 );
+ assertNotNull( node );
+
+ assertEquals("a", node.getPrefix()); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("aBlockLocal", ((IVariable)bindings[0]).getName());
+ assertEquals("aLocal", ((IVariable)bindings[1]).getName());
+ assertEquals("aParameter", ((IVariable)bindings[2]).getName());
+ }
+
+
+ public void testCompletionTypedef() throws Exception{
+ StringBuffer sb = new StringBuffer();
+ sb.append( "typedef int Int; "); //$NON-NLS-1$
+ sb.append( "InSP" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf( "SP" ); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull(node);
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ assertEquals("In", node.getPrefix());
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("Int", ((ITypedef)bindings[0]).getName());
+ }
+
+ public void testCompletion() throws Exception
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("#define GL_T 0x2001\n"); //$NON-NLS-1$
+ sb.append("#define GL_TRUE 0x1\n"); //$NON-NLS-1$
+ sb.append("typedef unsigned char GLboolean;\n"); //$NON-NLS-1$
+ sb.append("static GLboolean should_rotate = GL_T"); //$NON-NLS-1$
+
+ String code = sb.toString();
+
+ int index = code.indexOf("= GL_T"); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index + 6);
+ assertNotNull(node);
+
+ assertEquals("GL_T", node.getPrefix()); //$NON-NLS-1$
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+ }
+
+ public void testCompletionInTypeDef() throws Exception{
+ StringBuffer sb = new StringBuffer();
+ sb.append( "struct A { int name; }; \n" ); //$NON-NLS-1$
+ sb.append( "typedef struct A * PA; \n" ); //$NON-NLS-1$
+ sb.append( "int main() { \n" ); //$NON-NLS-1$
+ sb.append( " PA a; \n" ); //$NON-NLS-1$
+ sb.append( " a->SP \n" ); //$NON-NLS-1$
+ sb.append( "} \n" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf("SP"); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("name", ((IField)bindings[0]).getName());
+ }
+
+
+ public void _testCompletionFunctionCall() throws Exception
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "struct A { \n" ); //$NON-NLS-1$
+ sb.append( " int f2; \n" ); //$NON-NLS-1$
+ sb.append( " int f4; \n" ); //$NON-NLS-1$
+ sb.append( "}; \n" ); //$NON-NLS-1$
+ sb.append( "const A * foo(){} \n" ); //$NON-NLS-1$
+ sb.append( "void main( ) \n" ); //$NON-NLS-1$
+ sb.append( "{ \n" ); //$NON-NLS-1$
+ sb.append( " foo()->SP \n" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf( "SP" ); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("f2", ((IField)bindings[0]).getName());
+ assertEquals("f4", ((IField)bindings[1]).getName());
+ }
+
+
+ public void _testCompletionSizeof() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "int f() {\n" ); //$NON-NLS-1$
+ sb.append( "short blah;\n" ); //$NON-NLS-1$
+ sb.append( "int x = sizeof(bl" ); //$NON-NLS-1$
+
+ String code = sb.toString();
+ int index = code.indexOf( "of(bl" ); //$NON-NLS-1$
+
+ IASTCompletionNode node = parse( code, index + 5);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("blah", ((IVariable)bindings[0]).getName());
+ }
+
+
+ public void testCompletionForLoop() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "int f() {\n" ); //$NON-NLS-1$
+ sb.append( " int biSizeImage = 5;\n" ); //$NON-NLS-1$
+ sb.append( "for (int i = 0; i < bi " ); //$NON-NLS-1$
+ String code = sb.toString();
+
+ int index = code.indexOf("< bi");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("biSizeImage", ((IVariable)bindings[0]).getName());
+ }
+
+
+
+ public void testCompletionStructPointer() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append(" struct Temp { char * total; };" );
+ sb.append(" int f(struct Temp * t) {" );
+ sb.append(" t->t[5] = t->" );
+ String code = sb.toString();
+
+ int index = code.indexOf("= t->");
+
+ IASTCompletionNode node = parse( code, index + 5);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(1, bindings.length);
+ assertEquals("total", ((IVariable)bindings[0]).getName());
+ }
+
+
+ public void testCompletionEnum() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "typedef int DWORD;\n" ); //$NON-NLS-1$
+ sb.append( "typedef char BYTE;\n"); //$NON-NLS-1$
+ sb.append( "#define MAKEFOURCC(ch0, ch1, ch2, ch3) \\\n"); //$NON-NLS-1$
+ sb.append( "((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \\\n"); //$NON-NLS-1$
+ sb.append( "((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))\n"); //$NON-NLS-1$
+ sb.append( "enum e {\n"); //$NON-NLS-1$
+ sb.append( "blah1 = 5,\n"); //$NON-NLS-1$
+ sb.append( "blah2 = MAKEFOURCC('a', 'b', 'c', 'd'),\n"); //$NON-NLS-1$
+ sb.append( "blah3\n"); //$NON-NLS-1$
+ sb.append( "};\n"); //$NON-NLS-1$
+ sb.append( "e mye = bl\n"); //$NON-NLS-1$
+ String code = sb.toString();
+
+ int index = code.indexOf("= bl");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(3, bindings.length);
+ assertEquals("blah1", ((IEnumerator)bindings[0]).getName());
+ assertEquals("blah2", ((IEnumerator)bindings[1]).getName());
+ assertEquals("blah3", ((IEnumerator)bindings[2]).getName());
+ }
+
+
+ public void testCompletionStructArray() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "struct packet { int a; int b; };\n" ); //$NON-NLS-1$
+ sb.append( "struct packet buffer[5];\n" ); //$NON-NLS-1$
+ sb.append( "int main(int argc, char **argv) {\n" ); //$NON-NLS-1$
+ sb.append( " buffer[2]." ); //$NON-NLS-1$
+ String code = sb.toString();
+
+ int index = code.indexOf("[2].");
+
+ IASTCompletionNode node = parse( code, index + 4);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ IBinding[] bindings = getBindings(names);
+
+ assertEquals(2, bindings.length);
+ assertEquals("a", ((IField)bindings[0]).getName());
+ assertEquals("b", ((IField)bindings[1]).getName());
+ }
+
+
+ public void testCompletionPreprocessorDirective() throws Exception {
+ IASTCompletionNode node = parse("#", 1);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+
+ assertEquals("#", node.getPrefix());
+ }
+
+ public void testCompletionPreprocessorMacro() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "#define AMACRO 99 \n");
+ sb.append( "int main() { \n");
+ sb.append( " int AVAR; \n");
+ sb.append( " int x = A \n");
+ String code = sb.toString();
+
+ int index = code.indexOf("= A");
+
+ IASTCompletionNode node = parse( code, index + 3);
+ assertNotNull( node );
+
+ IASTName[] names = node.getNames();
+ assertEquals(1, names.length);
+ assertEquals("A", node.getPrefix());
+ }
+
+
+ public void testCompletionInsidePreprocessorDirective() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "#define MAC1 99 \n");
+ sb.append( "#define MAC2 99 \n");
+ sb.append( "#ifdef MA");
+ String code = sb.toString();
+
+ int index = code.length();
+
+ IASTCompletionNode node = parse( code, index );
+ assertNotNull( node );
+
+ assertEquals("MA", node.getPrefix());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationInclusionTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationInclusionTests.java
new file mode 100644
index 00000000000..19798739bee
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationInclusionTests.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import java.util.Collections;
+
+import org.eclipse.cdt.core.dom.ast.IASTComment;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
+import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationInclusionTests;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
+import org.eclipse.core.resources.IFile;
+
+public class C99DOMLocationInclusionTests extends DOMLocationInclusionTests {
+
+ public C99DOMLocationInclusionTests() {
+ }
+
+ public C99DOMLocationInclusionTests(String name, Class className) {
+ super(name, className);
+ }
+
+ public C99DOMLocationInclusionTests(String name) {
+ super(name);
+ }
+
+ protected IASTTranslationUnit parse(IFile code, IScannerInfo s)
+ throws Exception {
+
+ CodeReader codeReader = new CodeReader(code.getLocation().toOSString());
+ BaseExtensibleLanguage lang = getLanguage();
+ IASTTranslationUnit tu = lang.getASTTranslationUnit(codeReader, s, SavedCodeReaderFactory.getInstance(), null, BaseExtensibleLanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
+
+ return tu;
+ }
+
+ protected IASTTranslationUnit parse(IFile code) throws Exception {
+
+ return parse(code, new ExtendedScannerInfo());
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationMacroTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationMacroTests.java
new file mode 100644
index 00000000000..5fdd7cfc71c
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationMacroTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
+import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationMacroTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99DOMLocationMacroTests extends DOMLocationMacroTests {
+
+
+ public C99DOMLocationMacroTests() {
+ super();
+ }
+
+
+ public C99DOMLocationMacroTests(String name) {
+ super(name);
+ }
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang == ParserLanguage.C) {
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+ else
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ /**
+ * Tests GCC specific stuff, not applicable at this point
+ */
+ public void testStdioBug() throws ParserException {
+ try {
+ super.testStdioBug();
+ fail();
+ }
+ catch(Throwable e) { }
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationTests.java
new file mode 100644
index 00000000000..fe81bddc2fb
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMLocationTests.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMLocationTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99DOMLocationTests extends DOMLocationTests {
+
+ public C99DOMLocationTests() { }
+ public C99DOMLocationTests(String name) { super(name); }
+
+ @Override
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
+ throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ // this one fails because the C99 parser does error recovery differently
+ public void test162180_1() throws Exception {
+ try {
+ super.test162180_1();
+ fail();
+ }
+ catch(AssertionFailedError e) {}
+
+ }
+
+ public void test162180_3() throws Exception {
+ try {
+ super.test162180_3();
+ fail();
+ }
+ catch(AssertionFailedError e) {}
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMPreprocessorInformationTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMPreprocessorInformationTest.java
new file mode 100644
index 00000000000..46e49449448
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DOMPreprocessorInformationTest.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.DOMPreprocessorInformationTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99DOMPreprocessorInformationTest extends DOMPreprocessorInformationTest {
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ //if(lang != ParserLanguage.C)
+ // return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DigraphTrigraphTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DigraphTrigraphTests.java
new file mode 100644
index 00000000000..9065c0ab3d6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99DigraphTrigraphTests.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+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.IASTInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+
+public class C99DigraphTrigraphTests extends TestCase {
+
+
+ public C99DigraphTrigraphTests() { }
+ public C99DigraphTrigraphTests(String name) { super(name); }
+
+
+ protected IASTTranslationUnit parse(String code) {
+ return ParseHelper.parse(code, getLanguage(), true);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ public void testTrigraphSequences() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("??=define SIZE ??/ \n"); // trigraph used as backslash to ignore newline
+ sb.append("99 \n");
+ sb.append("int main(void)??< \n");
+ sb.append(" int arr??(SIZE??); \n");
+ sb.append(" arr??(4??) = '0' - (??-0 ??' 1 ??! 2); \n");
+ sb.append(" printf(\"%c??/n\", arr??(4??)); \n");
+ sb.append("??> \n");
+ String code = sb.toString();
+
+ IASTTranslationUnit tu = parse(code);
+ assertNotNull(tu);
+
+ IASTPreprocessorStatement[] defines = tu.getAllPreprocessorStatements();
+ assertEquals(1, defines.length);
+ IASTPreprocessorMacroDefinition macro = (IASTPreprocessorMacroDefinition)defines[0];
+ assertEquals("SIZE", macro.getName().toString());
+ //assertEquals("99", macro.getExpansion());
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(3, statements.length);
+
+ // int arr??(SIZE??);
+ IASTSimpleDeclaration arr = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTArrayDeclarator arr_decl = (IASTArrayDeclarator)arr.getDeclarators()[0];
+ IASTArrayModifier modifier = arr_decl.getArrayModifiers()[0];
+ IASTLiteralExpression lit = (IASTLiteralExpression)modifier.getConstantExpression();
+ assertEquals(IASTLiteralExpression.lk_integer_constant, lit.getKind());
+
+ // arr??(4??) = '0' - (??-0 ??' 1 ??! 2);
+ IASTBinaryExpression expr = (IASTBinaryExpression)((IASTExpressionStatement)statements[1]).getExpression();
+ assertEquals(IASTBinaryExpression.op_assign, expr.getOperator());
+ IASTArraySubscriptExpression arr_op = (IASTArraySubscriptExpression)expr.getOperand1();
+ assertEquals("4", ((IASTLiteralExpression)arr_op.getSubscriptExpression()).toString());
+ IASTBinaryExpression cond = (IASTBinaryExpression)((IASTUnaryExpression)((IASTBinaryExpression)expr.getOperand2()).getOperand2()).getOperand();
+ assertEquals(IASTBinaryExpression.op_binaryOr, cond.getOperator());
+ IASTBinaryExpression cond2 = (IASTBinaryExpression)cond.getOperand1();
+ assertEquals(IASTBinaryExpression.op_binaryXor, cond2.getOperator());
+ IASTUnaryExpression not = (IASTUnaryExpression)cond2.getOperand1();
+ assertEquals(IASTUnaryExpression.op_tilde, not.getOperator());
+
+ // printf(\"%c??/n\", arr??(4??));
+ IASTFunctionCallExpression expr2 = (IASTFunctionCallExpression)((IASTExpressionStatement)statements[2]).getExpression();
+ IASTExpressionList params = (IASTExpressionList) expr2.getParameterExpression();
+ IASTArraySubscriptExpression arr_op2 = (IASTArraySubscriptExpression)params.getExpressions()[1];
+ assertEquals("4", ((IASTLiteralExpression)arr_op2.getSubscriptExpression()).toString());
+ }
+
+
+ public void testTrigraphEscapeSequences() {
+ // a ??/ trigraph should act just like a backslash in a string literal
+ StringBuffer sb = new StringBuffer();
+ sb.append("int main(void)??< \n");
+ sb.append(" char str[] = \"??/\"??/n\"; \n");
+ sb.append(" char c = '??/u0000'; \n");
+ sb.append("??> \n");
+ String code = sb.toString();
+ parse(code); // will throw an exception if there are parse errors
+ }
+
+
+ public void testDigraphSequences() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("%:define join(a, b) a %:%: b \n");
+ sb.append("int main() <% \n");
+ sb.append(" int arr<:5:>; \n");
+ sb.append("%> \n");
+ String code = sb.toString();
+
+ IASTTranslationUnit tu = parse(code); // will throw an exception if there are parse errors
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(1, statements.length);
+
+ IASTSimpleDeclaration arr = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTArrayDeclarator arr_decl = (IASTArrayDeclarator)arr.getDeclarators()[0];
+ IASTArrayModifier modifier = arr_decl.getArrayModifiers()[0];
+ IASTLiteralExpression lit = (IASTLiteralExpression)modifier.getConstantExpression();
+ assertEquals("5", lit.toString());
+
+ }
+
+
+ public void testTrigraphAndDigraphSequecesInPreprocessorDirectives() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("%:define join1(a, b) a %:%: b \n");
+ sb.append("%:define str1(a) %: a \n");
+ sb.append("??=define join2(a, b) a ??=??= b \n");
+ sb.append("??=define str2(a) ??= a \n");
+ sb.append("int main() <% \n");
+ sb.append(" int join1(x, y) = str1(its all good); \n");
+ sb.append(" int join2(a, b) = str2(its still good); \n");
+ sb.append("%> \n");
+ String code = sb.toString();
+
+ IASTTranslationUnit tu = parse(code); // will throw an exception if there are parse errors
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition)tu.getDeclarations()[0];
+ IASTCompoundStatement body = (IASTCompoundStatement) main.getBody();
+ IASTStatement[] statements = body.getStatements();
+ assertEquals(2, statements.length);
+
+ IASTSimpleDeclaration decl1 = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[0]).getDeclaration();
+ IASTDeclarator declarator1 = decl1.getDeclarators()[0];
+ assertEquals("xy", declarator1.getName().toString());
+ IASTLiteralExpression expr1 = (IASTLiteralExpression)((IASTInitializerExpression)declarator1.getInitializer()).getExpression();
+ assertEquals(IASTLiteralExpression.lk_string_literal, expr1.getKind());
+ assertEquals("\"its all good\"", expr1.toString());
+
+ IASTSimpleDeclaration decl2 = (IASTSimpleDeclaration)((IASTDeclarationStatement)statements[1]).getDeclaration();
+ IASTDeclarator declarator2 = decl2.getDeclarators()[0];
+ assertEquals("ab", declarator2.getName().toString());
+ IASTLiteralExpression expr2 = (IASTLiteralExpression)((IASTInitializerExpression)declarator2.getInitializer()).getExpression();
+ assertEquals(IASTLiteralExpression.lk_string_literal, expr2.getKind());
+ assertEquals("its still good", expr2.toString());
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99GCCTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99GCCTests.java
new file mode 100644
index 00000000000..e8870b00943
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99GCCTests.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99GCCTests extends GCCTests {
+
+ public C99GCCTests() {}
+ public C99GCCTests(String name) { super(name); }
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99KnRTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99KnRTests.java
new file mode 100644
index 00000000000..aabf43559b6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99KnRTests.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2KnRTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+/**
+ * @author Mike Kucera
+ */
+public class C99KnRTests extends AST2KnRTests {
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang == ParserLanguage.C) {
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+ else
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+ // TODO: Failing tests, will get around to fixing these bugs
+
+ public void testKRCProblem3() throws Exception {
+ try {
+ super.testKRCProblem3();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ public void testKRCProblem4() throws Exception {
+ try {
+ super.testKRCProblem4();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ public void testKRCProblem5() throws Exception {
+ try {
+ super.testKRCProblem5();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+ public void testKRCProblem2() throws Exception {
+ try {
+ super.testKRCProblem2();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SelectionParseTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SelectionParseTest.java
new file mode 100644
index 00000000000..54702ac3f87
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SelectionParseTest.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import java.util.Collections;
+
+import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2SelectionParseTest;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+
+public class C99SelectionParseTest extends AST2SelectionParseTest {
+
+ public C99SelectionParseTest() {}
+ public C99SelectionParseTest(String name) { super(name); }
+
+ protected IASTNode parse(String code, ParserLanguage lang, int offset, int length) throws ParserException {
+ if(lang == ParserLanguage.C)
+ return parse(code, lang, false, false, offset, length);
+ else
+ return super.parse(code, lang, offset, length);
+ }
+
+ protected IASTNode parse(IFile file, ParserLanguage lang, int offset, int length) throws ParserException {
+ if(lang == ParserLanguage.C) {
+ IASTTranslationUnit tu = parse(file, lang, false, false);
+ return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
+ }
+ else
+ return super.parse(file, lang, offset, length);
+ }
+
+ protected IASTNode parse(String code, ParserLanguage lang, int offset, int length, boolean expectedToPass) throws ParserException {
+ if(lang == ParserLanguage.C)
+ return parse(code, lang, false, expectedToPass, offset, length);
+ else
+ return super.parse(code, lang, offset, length, expectedToPass);
+ }
+
+ protected IASTNode parse(String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems, int offset, int length) throws ParserException {
+ if(lang == ParserLanguage.C) {
+ IASTTranslationUnit tu = ParseHelper.parse(code, getLanguage(), useGNUExtensions, expectNoProblems, 0);
+ return tu.selectNodeForLocation(tu.getFilePath(), offset, length);
+ }
+ else
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems, offset, length);
+ }
+
+ protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, IScannerInfo scanInfo, boolean useGNUExtensions, boolean expectNoProblems )
+ throws ParserException {
+
+ if(lang != ParserLanguage.C)
+ return super.parse(file, lang, useGNUExtensions, expectNoProblems);
+
+ String fileName = file.getLocation().toOSString();
+ ICodeReaderFactory fileCreator = SavedCodeReaderFactory.getInstance();
+ CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(fileName);
+ return ParseHelper.parse(reader, getLanguage(), scanInfo, fileCreator, expectNoProblems, true, 0);
+ }
+
+ protected IASTTranslationUnit parse( IFile file, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems )
+ throws ParserException {
+ return parse(file, lang, new ScannerInfo(), useGNUExtensions, expectNoProblems);
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+// public void testBug193185_IncludeNext() throws Exception
+// {
+// String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$
+// String i1Next = "int one; \n#include_next "; //$NON-NLS-1$
+// String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$
+// String i3Next = "int three; \n"; //$NON-NLS-1$
+//
+//
+// IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$
+// importFile( "foo.h", i1Next ); //$NON-NLS-1$
+// IFolder twof = importFolder("two"); //$NON-NLS-1$
+// IFolder threef = importFolder("three"); //$NON-NLS-1$
+// importFile( "two/foo.h", i2Next ); //$NON-NLS-1$
+// importFile( "three/foo.h", i3Next ); //$NON-NLS-1$
+//
+// String[] path = new String[] {
+// twof.getRawLocation().toOSString(),
+// threef.getRawLocation().toOSString()
+// };
+//
+// IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path );
+//
+// IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true);
+//
+// IASTDeclaration[] decls = tu.getDeclarations();
+// assertEquals(4, decls.length);
+//
+// IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0];
+// assertEquals("zero", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+//
+// declaration = (IASTSimpleDeclaration)decls[1];
+// assertEquals("one", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+//
+// declaration = (IASTSimpleDeclaration)decls[2];
+// assertEquals("two", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+//
+// declaration = (IASTSimpleDeclaration)decls[3];
+// assertEquals("three", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+// }
+//
+//
+// public void testBug193366() throws Exception
+// {
+// String baseFile =
+// "#define FOOH \n" + //$NON-NLS-1$
+// "#define bar blahblahblah \n" + //$NON-NLS-1$
+// "#include FOOH \n" + //$NON-NLS-1$
+// "#include \n"; //$NON-NLS-1$
+//
+// String fooFile = "int x; \n"; //$NON-NLS-1$
+// String barFile = "int y; \n"; //$NON-NLS-1$
+//
+//
+// IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$
+// IFolder include = importFolder("inc"); //$NON-NLS-1$
+// importFile( "inc/foo.h", fooFile ); //$NON-NLS-1$
+// importFile( "inc/bar.h", barFile ); //$NON-NLS-1$
+//
+// String[] path = new String[] { include.getRawLocation().toOSString() };
+// IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path );
+//
+// IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true);
+//
+// IASTDeclaration[] decls = tu.getDeclarations();
+// assertEquals(2, decls.length);
+//
+// IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0];
+// assertEquals("x", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+//
+// declaration = (IASTSimpleDeclaration)decls[1];
+// assertEquals("y", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$
+// }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SpecTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SpecTests.java
new file mode 100644
index 00000000000..47cf41b902b
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99SpecTests.java
@@ -0,0 +1,211 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2CSpecTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99SpecTests extends AST2CSpecTest {
+
+ public C99SpecTests() { }
+ public C99SpecTests(String name) { super(name); }
+
+
+ /**
+ * Only parses it as C actually
+ * @throws ParserException
+ */
+ protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings);
+ parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings);
+ }
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException {
+ if(lang == ParserLanguage.C)
+ return ParseHelper.parse(code, getLanguage(), true, checkBindings, expectedProblemBindings );
+ else
+ return super.parse(code, lang, checkBindings, expectedProblemBindings);
+ }
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+ //Assignment statements cannot exists outside of a function body
+ @Override
+ public void test5_1_2_3s15() throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("//#include \n"); //$NON-NLS-1$
+ buffer.append("int foo() { \n"); //$NON-NLS-1$
+ buffer.append("int sum;\n"); //$NON-NLS-1$
+ buffer.append("char *p;\n"); //$NON-NLS-1$
+ buffer.append("sum = sum * 10 - '0' + (*p++ = getchar());\n"); //$NON-NLS-1$
+ buffer.append("sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));\n"); //$NON-NLS-1$
+ buffer.append("} \n"); //$NON-NLS-1$
+ parseCandCPP(buffer.toString(), false, 0);
+ }
+
+
+ // offsetof does not work if is not included!
+ @Override
+ public void test6_7_2_1s17() throws Exception {
+ try {
+ super.test6_7_2_1s17();
+ } catch(AssertionFailedError _) {
+ return;
+ }
+
+ fail();
+ }
+
+
+ // Tests from AST2CSpecFailingTests
+
+ /**
+ * TODO: This one fails, it can't resolve one of the bindings (const t) I think
+ *
+ [--Start Example(C 6.7.7-6):
+ typedef signed int t;
+ typedef int plain;
+ struct tag {
+ unsigned t:4;
+ const t:5;
+ plain r:5;
+ };
+ t f(t (t));
+ long t;
+ --End Example]
+ */
+ public void test6_7_7s6() throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("typedef signed int t;\n"); //$NON-NLS-1$
+ buffer.append("typedef int plain;\n"); //$NON-NLS-1$
+ buffer.append("struct tag {\n"); //$NON-NLS-1$
+ buffer.append("unsigned t:4;\n"); //$NON-NLS-1$
+ buffer.append("const t:5;\n"); //$NON-NLS-1$
+ buffer.append("plain r:5;\n"); //$NON-NLS-1$
+ buffer.append("};\n"); //$NON-NLS-1$
+ buffer.append("t f(t (t));\n"); //$NON-NLS-1$
+ buffer.append("long t;\n"); //$NON-NLS-1$
+
+ try {
+ parse(buffer.toString(), ParserLanguage.C, true, 0);
+ } catch(AssertionFailedError _) {
+ // there should be an error
+ }
+ }
+
+
+
+ /**
+ [--Start Example(C 6.10.3.5-5):
+ #define x 3
+ #define f(a) f(x * (a))
+ #undef x
+ #define x 2
+ #define g f
+ #define z z[0]
+ #define h g(~
+ #define m(a) a(w)
+ #define w 0,1
+ #define t(a) a
+ #define p() int
+ #define q(x) x
+ #define r(x,y) x ## y
+ #define str(x) # x
+ int foo() {
+ p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
+ char c[2][6] = { str(hello), str() };
+ }
+ --End Example]
+ */
+ @Override
+ public void test6_10_3_5s5() throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("#define x 3\n"); //$NON-NLS-1$
+ buffer.append("#define f(a) f(x * (a))\n"); //$NON-NLS-1$
+ buffer.append("#undef x\n"); //$NON-NLS-1$
+ buffer.append("#define x 2\n"); //$NON-NLS-1$
+ buffer.append("#define g f\n"); //$NON-NLS-1$
+ buffer.append("#define z z[0]\n"); //$NON-NLS-1$
+ buffer.append("#define h g(~\n"); //$NON-NLS-1$
+ buffer.append("#define m(a) a(w)\n"); //$NON-NLS-1$
+ buffer.append("#define w 0,1\n"); //$NON-NLS-1$
+ buffer.append("#define t(a) a\n"); //$NON-NLS-1$
+ buffer.append("#define p() int\n"); //$NON-NLS-1$
+ buffer.append("#define q(x) x\n"); //$NON-NLS-1$
+ buffer.append("#define r(x,y) x ## y\n"); //$NON-NLS-1$
+ buffer.append("#define str(x) # x\n"); //$NON-NLS-1$
+ buffer.append("int foo() {\n"); //$NON-NLS-1$
+ buffer.append("p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };\n"); //$NON-NLS-1$
+ buffer.append("char c[2][6] = { str(hello), str() };\n"); //$NON-NLS-1$
+ buffer.append("}\n"); //$NON-NLS-1$
+
+ //parseCandCPP(buffer.toString(), true, 0);
+ // TODO: this only works on the C99 parser for now
+ parse(buffer.toString(), ParserLanguage.C, true, 0);
+ }
+
+
+ /**
+ [--Start Example(C 6.10.3.5-7):
+ #define t(x,y,z) x ## y ## z
+ int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
+ t(10,,), t(,11,), t(,,12), t(,,) };
+ --End Example]
+ */
+ @Override
+ public void test6_10_3_5s7() throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$
+ buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$
+ buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$
+
+ // TODO: this only works on the C99 parser for now
+ parse(buffer.toString(), ParserLanguage.C, true, 0);
+ }
+
+ /**
+ * This test seems to be incorrect in AST2SpecTests
+ */
+ @Override
+ public void test4s6() throws Exception {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("#ifdef __STDC_IEC_559__ /* FE_UPWARD defined */\n"); //$NON-NLS-1$
+ buffer.append("fesetround(FE_UPWARD);\n"); //$NON-NLS-1$
+ buffer.append("#endif\n"); //$NON-NLS-1$
+ parseCandCPP(buffer.toString(), false, 0);
+ }
+
+
+ @Override
+ public void test6_7_8s24() throws Exception { // complex isn't declared as a typedef
+ try {
+ super.test6_7_8s24();
+ fail();
+ } catch(AssertionFailedError _) { }
+ }
+
+
+ @Override
+ public void test6_7_8s34() throws Exception { // div_t isn't declared as a typedef
+ try {
+ super.test6_7_8s34();
+ fail();
+ } catch(AssertionFailedError _) { }
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99TaskParserTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99TaskParserTest.java
new file mode 100644
index 00000000000..9de4d8122b6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99TaskParserTest.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.TaskParserTest;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99TaskParserTest extends TaskParserTest {
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99Tests.java
new file mode 100644
index 00000000000..399ba88e1ab
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99Tests.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+
+/**
+ *
+ * @author Mike Kucera
+ *
+ */
+public class C99Tests extends AST2Tests {
+
+ public static TestSuite suite() {
+ return suite(C99Tests.class);
+ }
+
+ public C99Tests(String name) {
+ super(name);
+ }
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ public void testMultipleHashHash() throws Exception {
+ String code = "#define TWICE(a) int a##tera; int a##ther; \n TWICE(pan)";
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+
+ public void testBug191279() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append(" /**/ \n");
+ sb.append("# define YO 99 /**/ \n");
+ sb.append("# undef YO /**/ ");
+ sb.append(" /* $ */ ");
+ String code = sb.toString();
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+
+ public void testBug191324() throws Exception {
+ StringBuffer sb = new StringBuffer();
+ sb.append("int x$y = 99; \n");
+ sb.append("int $q = 100; \n"); // can use $ as first character in identifier
+ sb.append("#ifndef SS$_INVFILFOROP \n");
+ sb.append("int z; \n");
+ sb.append("#endif \n");
+ String code = sb.toString();
+ parseAndCheckBindings(code, ParserLanguage.C);
+ }
+
+ public void testBug192009_implicitInt() throws Exception {
+ String code = "main() { int x; }";
+ IASTTranslationUnit tu = parse(code, ParserLanguage.C, false, true);
+
+ IASTDeclaration[] declarations = tu.getDeclarations();
+ assertEquals(1, declarations.length);
+
+ IASTFunctionDefinition main = (IASTFunctionDefinition) declarations[0];
+ ICASTSimpleDeclSpecifier declSpec = (ICASTSimpleDeclSpecifier) main.getDeclSpecifier();
+ assertEquals(0, declSpec.getType());
+
+
+ assertEquals("main", main.getDeclarator().getName().toString());
+ }
+
+
+
+ public void testBug93980() { // some wierd gcc extension I think
+ try {
+ super.testBug93980();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+ public void testBug95866() { // gcc extension
+ try {
+ super.testBug95866();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+ public void testBug80171() throws Exception { // implicit int not supported
+ try {
+ super.testBug80171();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+ public void testBug196468_emptyArrayInitializer() { // empty array initializer is a gcc extension
+ try {
+ super.testBug196468_emptyArrayInitializer();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+ public void testBug75340() { // not legal c99
+ try {
+ super.testBug75340();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+ public void test92791() { // I think the test is wrong, the second code snippet contains a redeclaration
+ try {
+ super.test92791();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+
+ public void testBug192165() { // gcc extension: typeof
+ try {
+ super.testBug192165();
+ fail();
+ } catch(Throwable _) { }
+ }
+
+
+
+ public void testBug191450_attributesInBetweenPointers() { // gcc extension: attributes
+ try {
+ super.testBug191450_attributesInBetweenPointers();
+ fail();
+ } catch(Throwable _) { }
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilOldTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilOldTests.java
new file mode 100644
index 00000000000..576b884d165
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilOldTests.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilOldTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99UtilOldTests extends AST2UtilOldTests {
+
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+
+
+ public void testCastExpression() throws Exception { // A not typedefed
+ try {
+ super.testCastExpression();
+ fail();
+ } catch(AssertionFailedError _) {}
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilTests.java
new file mode 100644
index 00000000000..f63eb9f9277
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/C99UtilTests.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.dom.lrparser.c99.C99Language;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.core.parser.tests.ast2.AST2UtilTests;
+import org.eclipse.cdt.internal.core.parser.ParserException;
+
+public class C99UtilTests extends AST2UtilTests {
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang);
+
+ return parse(code, lang, false, true );
+ }
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions);
+
+ return parse( code, lang, useGNUExtensions, true );
+ }
+
+ protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, boolean expectNoProblems ) throws ParserException {
+ if(lang != ParserLanguage.C)
+ return super.parse(code, lang, useGNUExtensions, expectNoProblems);
+
+ return ParseHelper.parse(code, getLanguage(), expectNoProblems);
+ }
+
+
+ protected BaseExtensibleLanguage getLanguage() {
+ return C99Language.getDefault();
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParseHelper.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParseHelper.java
new file mode 100644
index 00000000000..2c4d2e89e33
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParseHelper.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.AssertionFailedError;
+
+import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IProblemBinding;
+import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
+import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
+import org.eclipse.cdt.core.model.AbstractLanguage;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.parser.ScannerInfo;
+import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Utility methods for parsing test code using the C99 LPG parser.
+ *
+ * @author Mike Kucera
+ */
+public class ParseHelper {
+
+ static int testsRun = 0;
+
+ private static class C99NameResolver extends ASTVisitor {
+ {
+ shouldVisitNames = true;
+ }
+ public int numProblemBindings=0;
+ public int numNullBindings=0;
+
+ public int visit( IASTName name ){
+ IBinding binding = name.resolveBinding();
+ if (binding instanceof IProblemBinding)
+ numProblemBindings++;
+ if (binding == null)
+ numNullBindings++;
+ return PROCESS_CONTINUE;
+ }
+ }
+
+
+
+ public static IASTTranslationUnit parse(char[] code, BaseExtensibleLanguage lang, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings) {
+ CodeReader codeReader = new CodeReader(code);
+ return parse(codeReader, lang, new ScannerInfo(), null, expectNoProblems, checkBindings, expectedProblemBindings);
+ }
+
+ public static IASTTranslationUnit parse(String code, BaseExtensibleLanguage lang, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings) {
+ return parse(code.toCharArray(), lang, expectNoProblems, checkBindings, expectedProblemBindings);
+ }
+
+
+ public static IASTTranslationUnit parse(String code, BaseExtensibleLanguage lang, boolean expectNoProblems) {
+ return parse(code, lang, expectNoProblems, false, 0);
+ }
+
+
+
+ public static IASTTranslationUnit parse(CodeReader codeReader, BaseExtensibleLanguage language, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, boolean expectNoProblems, boolean checkBindings, int expectedProblemBindings) {
+ testsRun++;
+
+ IASTTranslationUnit tu;
+ try {
+ tu = language.getASTTranslationUnit(codeReader, scanInfo, fileCreator, null, ParserUtil.getParserLogService());
+ } catch (CoreException e) {
+ throw new AssertionFailedError(e.toString());
+ }
+
+ // should parse correctly first before we look at the bindings
+ if(expectNoProblems )
+ {
+ if (CVisitor.getProblems(tu).length != 0) {
+ throw new AssertionFailedError(" CVisitor has AST Problems " ); //$NON-NLS-1$
+ }
+
+ // TODO: actually collect preprocessor problems
+ if (tu.getPreprocessorProblems().length != 0) {
+ throw new AssertionFailedError(" C TranslationUnit has Preprocessor Problems " ); //$NON-NLS-1$
+ }
+ }
+
+ // resolve all bindings
+ if (checkBindings) {
+
+ C99NameResolver res = new C99NameResolver();
+ tu.accept( res );
+ if (res.numProblemBindings != expectedProblemBindings )
+ throw new AssertionFailedError("Expected " + expectedProblemBindings + " problem(s), encountered " + res.numProblemBindings ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ return tu;
+ }
+
+
+ public static IASTTranslationUnit commentParse(String code, BaseExtensibleLanguage language) {
+ CodeReader codeReader = new CodeReader(code.toCharArray());
+ IASTTranslationUnit tu;
+ try {
+ tu = language.getASTTranslationUnit(codeReader, new ScannerInfo(), null, null, AbstractLanguage.OPTION_ADD_COMMENTS, ParserUtil.getParserLogService());
+ } catch (CoreException e) {
+ throw new AssertionFailedError(e.toString());
+ }
+ return tu;
+ }
+
+ public static IASTCompletionNode getCompletionNode(String code, BaseExtensibleLanguage lang) {
+ return getCompletionNode(code, lang, code.length());
+ }
+
+
+ public static IASTCompletionNode getCompletionNode(String code, BaseExtensibleLanguage language, int offset) {
+ CodeReader reader = new CodeReader(code.toCharArray());
+ return language.getCompletionNode(reader, new ScannerInfo(), null, null, ParserUtil.getParserLogService(), offset);
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParserTestSuite.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParserTestSuite.java
new file mode 100644
index 00000000000..3927c09a930
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/c99/ParserTestSuite.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.lrparser.tests.c99;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ParserTestSuite extends TestSuite {
+
+ // TODO: the following test are not being reused
+ //
+ // DOMGCCSelectionParseExtensionsTest
+ // DOMSelectionParseTest
+ // GCCCompleteParseExtensionsTest
+ // QuickParser2Tests
+ //
+ // and perhaps others
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+
+ suite.addTestSuite(C99Tests.class); // has some tests that do fail
+
+ suite.addTestSuite(C99SpecTests.class); // a couple of failures
+ suite.addTestSuite(C99KnRTests.class); // mostly fail due to ambiguities
+
+ // The majority of the content assist test are in the ui tests plugin
+ suite.addTestSuite(C99CompletionBasicTest.class);
+ // this one still has a lot of failing tests though
+ suite.addTestSuite(C99SelectionParseTest.class);
+
+ suite.addTestSuite(C99DOMLocationInclusionTests.class);
+ suite.addTestSuite(C99DOMLocationTests.class);
+ suite.addTestSuite(C99DOMLocationMacroTests.class);
+ suite.addTestSuite(C99DOMPreprocessorInformationTest.class);
+ suite.addTestSuite(C99CommentTests.class);
+ suite.addTestSuite(C99DigraphTrigraphTests.class);
+ suite.addTestSuite(C99GCCTests.class);
+ suite.addTestSuite(C99UtilOldTests.class);
+ suite.addTestSuite(C99UtilTests.class);
+ suite.addTestSuite(C99CompleteParser2Tests.class);
+ suite.addTestSuite(C99TaskParserTest.class);
+
+
+ return suite;
+ }
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/.classpath b/lrparser/org.eclipse.cdt.core.lrparser/.classpath
new file mode 100644
index 00000000000..751c8f2e504
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/.project b/lrparser/org.eclipse.cdt.core.lrparser/.project
new file mode 100644
index 00000000000..b101bd0e58f
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/.project
@@ -0,0 +1,34 @@
+
+
+ org.eclipse.cdt.core.parser.c99
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+ net.sourceforge.metrics.builder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+ net.sourceforge.metrics.nature
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/.settings/org.eclipse.jdt.core.prefs b/lrparser/org.eclipse.cdt.core.lrparser/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..96d4911cd62
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Mon Jul 30 15:15:28 EDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..8d4148969a6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.1
+Bundle-SymbolicName: org.eclipse.cdt.core.lrparser;singleton:=true
+Bundle-Version: 4.0.1.qualifier
+Bundle-ClassPath: .
+Require-Bundle: org.eclipse.cdt.core,
+ net.sourceforge.lpg.lpgjavaruntime;bundle-version="1.1.0";visibility:=reexport,
+ org.eclipse.core.runtime
+Export-Package: org.eclipse.cdt.core.dom.lrparser,
+ org.eclipse.cdt.core.dom.lrparser.action,
+ org.eclipse.cdt.core.dom.lrparser.action.c99,
+ org.eclipse.cdt.core.dom.lrparser.c99,
+ org.eclipse.cdt.internal.core.dom.lrparser.c99;x-internal:=true,
+ org.eclipse.cdt.internal.core.dom.lrparser.c99.bindings
+Bundle-Localization: plugin
+Bundle-Vendor: %Bundle-Vendor.0
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/about.html b/lrparser/org.eclipse.cdt.core.lrparser/about.html
new file mode 100644
index 00000000000..d7c511887d6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/about.html
@@ -0,0 +1,24 @@
+
+
+About
+
+
+
About This Content
+
+
June 22, 2007
+
License
+
+
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/lrparser/org.eclipse.cdt.core.lrparser/about.ini b/lrparser/org.eclipse.cdt.core.lrparser/about.ini
new file mode 100644
index 00000000000..b3cd8d70ba9
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/about.ini
@@ -0,0 +1,24 @@
+# about.ini
+# contains information about a feature
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# "%key" are externalized strings defined in about.properties
+# This file does not need to be translated.
+
+# Property "aboutText" contains blurb for "About" dialog (translated)
+aboutText=%blurb
+
+# Property "windowImage" contains path to window icon (16x16)
+# needed for primary features only
+
+# Property "featureImage" contains path to feature image (32x32)
+featureImage=eclipse32.gif
+
+# Property "aboutImage" contains path to product image (500x330 or 115x164)
+# needed for primary features only
+
+# Property "appName" contains name of the application (translated)
+# needed for primary features only
+
+# Property "welcomePerspective" contains the id of the perspective in which the
+# welcome page is to be opened.
+# optional
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/about.mappings b/lrparser/org.eclipse.cdt.core.lrparser/about.mappings
new file mode 100644
index 00000000000..0824105e69d
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/about.mappings
@@ -0,0 +1,9 @@
+# about.mappings
+# contains fill-ins for about.properties
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# This file does not need to be translated.
+
+# The following should contain the build version.
+# e.g. "0=20020612"
+# This value will be added automaticaly via the build scripts
+0=@build@
\ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/about.properties b/lrparser/org.eclipse.cdt.core.lrparser/about.properties
new file mode 100644
index 00000000000..262b4010c35
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/about.properties
@@ -0,0 +1,25 @@
+###############################################################################
+# Copyright (c) 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
+###############################################################################
+# about.properties
+# contains externalized strings for about.ini
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# fill-ins are supplied by about.mappings
+# This file should be translated.
+# NOTE TO TRANSLATOR: Please do not translate the featureVersion variable.
+
+
+blurb=CDT C99 Parser Support\n\
+\n\
+Version: {featureVersion}\n\
+Build id: {0}\n\
+\n\
+(c) Copyright Eclipse contributors and others, 2007. All rights reserved.\n\
+Visit http://www.eclipse.org/cdt
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/build.properties b/lrparser/org.eclipse.cdt.core.lrparser/build.properties
new file mode 100644
index 00000000000..71b26d6c8f3
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/build.properties
@@ -0,0 +1,21 @@
+###############################################################################
+# Copyright (c) 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
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ plugin.properties,\
+ plugin.xml,\
+ eclipse32.gif,\
+ about.ini,\
+ about.mappings,\
+ about.properties
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/eclipse32.gif b/lrparser/org.eclipse.cdt.core.lrparser/eclipse32.gif
new file mode 100644
index 00000000000..e6ad7ccd75b
Binary files /dev/null and b/lrparser/org.eclipse.cdt.core.lrparser/eclipse32.gif differ
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties b/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties
new file mode 100644
index 00000000000..165e3722a96
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/plugin.properties
@@ -0,0 +1,18 @@
+###############################################################################
+# Copyright (c) 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
+###############################################################################
+
+Bundle-Name.0 = LR Parser Plug-in
+Bundle-Vendor.0 = Eclipse.org
+Bundle-Name.1 = LR Parser Plug-in
+
+# built-in languages
+language.name.c99= C99
+language.name.isocpp= ISO C++
\ No newline at end of file
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml b/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml
new file mode 100644
index 00000000000..abca5716d74
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/plugin.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java
new file mode 100644
index 00000000000..c35084bc969
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
+import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
+import org.eclipse.cdt.core.dom.lrparser.util.DebugUtil;
+import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.AbstractLanguage;
+import org.eclipse.cdt.core.model.ICLanguageKeywords;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.parser.CodeReader;
+import org.eclipse.cdt.core.parser.IParserLogService;
+import org.eclipse.cdt.core.parser.IScanner;
+import org.eclipse.cdt.core.parser.IScannerInfo;
+import org.eclipse.cdt.core.parser.ParserLanguage;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
+import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
+import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
+import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
+import org.eclipse.core.runtime.CoreException;
+
+
+/**
+ * Implementation of the ILanguage extension point,
+ * provides the ability to add LPG based languages to CDT.
+ *
+ * @author Mike Kucera
+ */
+@SuppressWarnings("restriction")
+public abstract class BaseExtensibleLanguage extends AbstractLanguage implements ILanguage, ICLanguageKeywords {
+
+
+ /**
+ * Retrieve the parser (runs after the preprocessor runs).
+ *
+ * Can be overridden in subclasses to provide a different parser
+ * for a language extension.
+ */
+ protected abstract IParser getParser();
+
+
+ /**
+ * A token map is used to map tokens from the DOM preprocessor
+ * to the tokens defined by an LPG parser.
+ */
+ protected abstract ITokenMap getTokenMap();
+
+
+ /**
+ * Normally all the AST nodes are created by the parser, but we
+ * need the root node ahead of time.
+ *
+ * The preprocessor is responsible for creating preprocessor AST nodes,
+ * so the preprocessor needs access to the translation unit so that it can
+ * set the parent pointers on the AST nodes it creates.
+ *
+ * @return an IASTTranslationUnit object thats empty and will be filled in by the parser
+ */
+ protected abstract IASTTranslationUnit createASTTranslationUnit();
+
+
+ /**
+ * Returns the ParserLanguage value that is to be used when creating
+ * an instance of CPreprocessor.
+ *
+ */
+ protected abstract ParserLanguage getParserLanguageForPreprocessor();
+
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter == IPDOMLinkageFactory.class)
+ return new PDOMCLinkageFactory();
+
+ return super.getAdapter(adapter);
+ }
+
+
+
+
+ @SuppressWarnings("nls")
+ @Override
+ public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
+ ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException {
+
+ ILanguage gccLanguage = GCCLanguage.getDefault();
+ IASTTranslationUnit gtu = gccLanguage.getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
+
+ System.out.println();
+ System.out.println("********************************************************");
+ System.out.println("GCC AST:");
+ DebugUtil.printAST(gtu);
+ System.out.println();
+
+
+
+ //IParseResult parseResult = parse(reader, scanInfo, fileCreator, index, null, null);
+ //IASTTranslationUnit tu = parseResult.getTranslationUnit();
+
+ // TODO temporary
+ IScannerExtensionConfiguration config = new GCCScannerExtensionConfiguration();
+
+ ParserLanguage pl = getParserLanguageForPreprocessor();
+ IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
+ preprocessor.setScanComments((options & OPTION_ADD_COMMENTS) != 0);
+ preprocessor.setComputeImageLocations((options & AbstractLanguage.OPTION_NO_IMAGE_LOCATIONS) == 0);
+
+ IParser parser = getParser();
+ IASTTranslationUnit tu = createTranslationUnit(index, preprocessor);
+
+ CPreprocessorAdapter.runCPreprocessor(preprocessor, parser, getTokenMap(), tu);
+
+ parser.parse(tu); // the parser will fill in the rest of the AST
+
+
+ System.out.println("Base Extensible Language AST:");
+ //DebugUtil.printAST(tu);
+ return tu;
+ }
+
+
+ public IASTTranslationUnit getASTTranslationUnit(CodeReader reader,
+ IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
+ IIndex index, IParserLogService log) throws CoreException {
+
+ return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
+ }
+
+
+ public IASTCompletionNode getCompletionNode(CodeReader reader,
+ IScannerInfo scanInfo, ICodeReaderFactory fileCreator,
+ IIndex index, IParserLogService log, int offset) {
+
+ // TODO temporary
+ IScannerExtensionConfiguration config = new GCCScannerExtensionConfiguration();
+
+ ParserLanguage pl = getParserLanguageForPreprocessor();
+ IScanner preprocessor = new CPreprocessor(reader, scanInfo, pl, log, config, fileCreator);
+ preprocessor.setContentAssistMode(offset);
+
+ IParser parser = getParser();
+ IASTTranslationUnit tu = createTranslationUnit(index, preprocessor);
+
+ CPreprocessorAdapter.runCPreprocessor(preprocessor, parser, getTokenMap(), tu);
+
+ // the parser will fill in the rest of the AST
+ IASTCompletionNode completionNode = parser.parse(tu);
+ return completionNode;
+ }
+
+
+ /**
+ * Gets the translation unit object and sets the index and the location resolver.
+ */
+ private IASTTranslationUnit createTranslationUnit(IIndex index, IScanner preprocessor) {
+ IASTTranslationUnit tu = createASTTranslationUnit();
+ tu.setIndex(index);
+ if(tu instanceof CASTTranslationUnit) {
+ ((CASTTranslationUnit)tu).setLocationResolver(preprocessor.getLocationResolver());
+ }
+ return tu;
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
new file mode 100644
index 00000000000..987d7957dfb
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/CPreprocessorAdapter.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+import lpg.lpgjavaruntime.IToken;
+import lpg.lpgjavaruntime.Token;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.lrparser.action.ITokenMap;
+import org.eclipse.cdt.core.parser.EndOfFileException;
+import org.eclipse.cdt.core.parser.IScanner;
+
+/**
+ * Adapts the CPreprocessor from the CDT core for use with LPG based parsers.
+ *
+ * @author Mike Kucera
+ *
+ */
+class CPreprocessorAdapter {
+
+ /**
+ * During content assist the preprocessor may return a completion token
+ * which represents the identifier on which the user invoked content assist.
+ * The the preprocessor normally returns arbitrarily many end-of-completion
+ * (EOC) tokens.
+ *
+ * A bottom-up parser cannot know ahead of time how many EOC tokens are
+ * needed in order for the parse to complete successfully. So we pick
+ * a number that seems arbitrarily large enough.
+ */
+ private static final int NUM_EOC_TOKENS = 50;
+
+ private static final int DUMMY_TOKEN_KIND = 0;
+
+
+ private static final int tCOMPLETION = org.eclipse.cdt.core.parser.IToken.tCOMPLETION;
+ private static final int tEND_OF_INPUT = org.eclipse.cdt.core.parser.IToken.tEND_OF_INPUT;
+ private static final int tEOC = org.eclipse.cdt.core.parser.IToken.tEOC;
+
+
+
+ /**
+ * Collect the tokens generated by the preprocessor.
+ *
+ * TODO: should preprocessor.nextTokenRaw() be called instead?
+ */
+ @SuppressWarnings("restriction")
+ public static void runCPreprocessor(IScanner preprocessor, ITokenCollector tokenCollector, ITokenMap tokenMap, IASTTranslationUnit tu) {
+ // LPG requires that the token stream start with a dummy token
+ tokenCollector.addToken(createDummyToken());
+
+ preprocessor.getLocationResolver().setRootNode(tu);
+
+ try {
+ while(true) {
+ org.eclipse.cdt.core.parser.IToken domToken = preprocessor.nextToken(); // throws EndOfFileException
+ int type = domToken.getType();
+
+ IToken token = new LPGTokenAdapter(domToken, tokenMap.mapKind(type));
+ tokenCollector.addToken(token);
+
+ if(type == tCOMPLETION) {
+ // the token after the completion token must be an EOC token
+ org.eclipse.cdt.core.parser.IToken domEocToken = preprocessor.nextToken();
+ assert domEocToken.getType() == tEOC;
+
+ IToken eocToken = createEOCToken(domEocToken, tokenMap);
+
+ for(int i = 0; i < NUM_EOC_TOKENS; i++)
+ tokenCollector.addToken(eocToken); // reuse the same reference, no need to create several objects
+
+ break;
+ }
+ }
+ } catch (EndOfFileException e) {
+ // just break out of the loop
+ }
+
+ // LPG requires that the token stream end with an EOF token
+ tokenCollector.addToken(createEOFToken(tokenMap));
+ }
+
+
+
+
+ private static IToken createEOCToken(org.eclipse.cdt.core.parser.IToken domEocToken, ITokenMap tokenMap) {
+ return new LPGTokenAdapter(domEocToken, tokenMap.mapKind(domEocToken.getType()));
+ }
+
+ private static IToken createDummyToken() {
+ return new Token(null, 0, 0, DUMMY_TOKEN_KIND);
+ }
+
+ private static IToken createEOFToken(ITokenMap tokenMap) {
+ return new Token(null, 0, 0, tokenMap.mapKind(tEND_OF_INPUT));
+ }
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java
new file mode 100644
index 00000000000..9510cc46a6a
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParser.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+
+
+/**
+ * Represents a parser that can be used by BaseExtensibleLanguage.
+ *
+ * @author Mike Kucera
+ */
+public interface IParser extends ITokenCollector {
+
+ /**
+ * Performs the actual parse.
+ *
+ * The given translation unit is assumed to not have any children, during the parse
+ * it will have its declaration fields filled in, resulting in a complete AST.
+ *
+ * If there were any errors during the parse these will be represented in the
+ * AST as problem nodes.
+ *
+ * If the parser encounters a completion token then a completion node
+ * is returned, null is returned otherwise.
+ *
+ * @param tu An IASTTranslationUnit instance that will have its declarators filled in.
+ * @return a completion node if a completion token is encountered during the parser, null otherwise.
+ */
+ public IASTCompletionNode parse(IASTTranslationUnit tu);
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java
new file mode 100644
index 00000000000..a58b77306ab
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/IParserActionTokenProvider.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+import java.util.List;
+
+import lpg.lpgjavaruntime.IToken;
+
+/**
+ * Provides an interface to the token stream that
+ * can be used by the parser semantic actions.
+ *
+ * Allows the semantic actions to directly inspect the token
+ * stream. Used to calculate AST node offsets and for
+ * other purposes.
+ *
+ * TODO There are still issues with getLeftIToken() and
+ * getRightIToken(), they should return null when used with
+ * an empty rule but currently they don't.
+ *
+ * @author Mike Kucera
+ */
+public interface IParserActionTokenProvider {
+
+ /**
+ * Returns the tokens that were parsed to recognized
+ * the currently executing rule.
+ *
+ * @returns a read-only list of tokens, will not be null but may be empty
+ */
+ public List getRuleTokens();
+
+ /**
+ * Usually equivalent to getRuleTokens().get(0); but more efficient.
+ *
+ * However, when called during an empty rule it will return the token to the
+ * left of the location of the empty rule.
+ */
+ public IToken getLeftIToken();
+
+ /**
+ * Usually equivalent to getRuleTokens().get(getRuleTokens().size()-1); but more efficient.
+ *
+ * However, when called during an empty rule it will return the token to the
+ * right of the location of the empty rule.
+ */
+ public IToken getRightIToken();
+
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java
new file mode 100644
index 00000000000..a35fc09b468
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/ITokenCollector.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+import lpg.lpgjavaruntime.IToken;
+
+/**
+ * An LPG parser object is initialized with the list of tokens
+ * before parsing is invoked.
+ *
+ * This interface allows tokens to be "injected" into the parser
+ * before the parser is run.
+ *
+ * @author Mike Kucera
+ */
+public interface ITokenCollector {
+ public void addToken(IToken token);
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java
new file mode 100644
index 00000000000..ad68293a0f5
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LPGTokenAdapter.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser;
+
+
+import lpg.lpgjavaruntime.PrsStream;
+
+/**
+ * The CPreprocessor from the CDT core returns tokens that
+ * are of the type org.eclipse.cdt.core.parser.IToken,
+ * however LPG wants the tokens to be of the type lpg.lpgjavaruntime.IToken.
+ *
+ * So these adapter objects are used to wrap the tokens returned
+ * by CPreprocessor so that they can be used with LPG.
+ *
+ * @author Mike Kucera
+ */
+class LPGTokenAdapter implements lpg.lpgjavaruntime.IToken {
+
+ /** The token object that is being wrapped */
+ private final org.eclipse.cdt.core.parser.IToken token;
+
+
+ private int tokenIndex;
+ private int adjunctIndex;
+
+ private int kind;
+
+ public LPGTokenAdapter(org.eclipse.cdt.core.parser.IToken token, int parserKind) {
+ this.token = token;
+ this.kind = parserKind;
+ }
+
+ public int getAdjunctIndex() {
+ return adjunctIndex;
+ }
+
+ public int getColumn() {
+ return 0;
+ }
+
+ public int getEndColumn() {
+ return 0;
+ }
+
+ public int getEndLine() {
+ return 0;
+ }
+
+ public int getEndOffset() {
+ return token.getEndOffset();
+ }
+
+ public lpg.lpgjavaruntime.IToken[] getFollowingAdjuncts() {
+ return null;
+ }
+
+ public int getKind() {
+ return kind;
+ }
+
+ public int getLine() {
+ return 0;
+ }
+
+ public lpg.lpgjavaruntime.IToken[] getPrecedingAdjuncts() {
+ return null;
+ }
+
+ public PrsStream getPrsStream() {
+ return null;
+ }
+
+ public int getStartOffset() {
+ return token.getOffset();
+ }
+
+ public int getTokenIndex() {
+ return tokenIndex;
+ }
+
+ @Deprecated
+ public String getValue(char[] arg0) {
+ return toString();
+ }
+
+ public void setAdjunctIndex(int adjunctIndex) {
+ this.adjunctIndex = adjunctIndex;
+ }
+
+ public void setEndOffset(int arg0) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setKind(int kind) {
+ this.kind = kind;
+ }
+
+ public void setStartOffset(int arg0) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ public void setTokenIndex(int tokenIndex) {
+ this.tokenIndex = tokenIndex;
+ }
+
+ @Override
+ public String toString() {
+ return token.toString();
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java
new file mode 100644
index 00000000000..50c6430a7ea
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/ASTCompletionNode.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser.action;
+
+import java.util.LinkedList;
+
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+
+/**
+ * An AST node that represents the location of content assist
+ * in the source file.
+ *
+ * This node may contain the prefix text of an identifier up to the point. If
+ * there is no prefix, the completion occurred at the point where a new token
+ * would have begun.
+ *
+ * Contains a list of name nodes, each name represents an identifier
+ * at the point where content assist was invoked. There is usually
+ * a single name node, however if an ambiguity is detected then that section
+ * of the source may be interpreted in more than one way (for example, as an expression then as a declaration).
+ * This results in an ambiguity node in the tree and one name node for each of the ways it can be interpreted.
+ *
+ * The full AST may be accessed via getTranslationUnit() or by following
+ * the parent pointers of the name nodes.
+ *
+ * @author Mike Kucera
+ */
+public class ASTCompletionNode implements IASTCompletionNode {
+
+ private final LinkedList names = new LinkedList();
+
+ private final String prefix;
+ private final IASTTranslationUnit tu;
+
+
+ /**
+ * Creates a completion node.
+ * @throws NullPointerException if tu is null
+ * @throws IllegalArgumentException if prefix is the empty string, it should be null instead
+ */
+ public ASTCompletionNode(String prefix, IASTTranslationUnit tu) {
+ if("".equals(prefix)) //$NON-NLS-1$
+ throw new IllegalArgumentException("prefix cannot be the empty string"); //$NON-NLS-1$
+ if(tu == null)
+ throw new NullPointerException("tu is null"); //$NON-NLS-1$
+
+ this.prefix = prefix;
+ this.tu = tu;
+ }
+
+
+ public void addName(IASTName name) {
+ names.add(name);
+ }
+
+
+ /**
+ * Returns the length of the prefix.
+ */
+ public int getLength() {
+ return prefix == null ? 0 : prefix.length();
+ }
+
+
+ public IASTName[] getNames() {
+ return names.toArray(new IASTName[0]);
+ }
+
+
+ /**
+ * If the point of completion was at the end of a potential identifier, this
+ * string contains the text of that identifier.
+ *
+ * @returns a string of length >= 1 or null
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public IASTTranslationUnit getTranslationUnit() {
+ return tu;
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java
new file mode 100644
index 00000000000..841ec45e80f
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/BuildASTParserAction.java
@@ -0,0 +1,1042 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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.dom.lrparser.action;
+
+import java.util.Collections;
+import java.util.List;
+
+import lpg.lpgjavaruntime.IToken;
+
+import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
+import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
+import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
+import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
+import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
+import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
+import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
+import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
+import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
+import org.eclipse.cdt.core.dom.ast.IASTForStatement;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
+import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializer;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
+import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
+import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
+import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
+import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IASTProblemHolder;
+import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
+import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
+import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
+import org.eclipse.cdt.core.dom.ast.c.ICASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
+import org.eclipse.cdt.core.dom.lrparser.IParserActionTokenProvider;
+import org.eclipse.cdt.core.dom.lrparser.util.DebugUtil;
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+import org.eclipse.cdt.internal.core.dom.parser.c.CASTNode;
+
+
+/**
+ * Parser semantic actions that are common to both C and C++.
+ *
+ * @author Mike Kucera
+ */
+@SuppressWarnings("restriction")
+public abstract class BuildASTParserAction {
+
+
+ /**
+ * Used with very simple optional rules that just say
+ * that some particular token or keyword is optional.
+ * The presence of the PLACE_HOLDER on the stack means that the keyword
+ * was parsed, the presence of null means the keyword wasn't parsed.
+ *
+ * @see BuildASTParserAction#consumePlaceHolder()
+ * @see BuildASTParserAction#consumeEmpty()
+ */
+ protected static final Object PLACE_HOLDER = Boolean.TRUE;
+
+
+ // turn debug tracing on and off
+ // TODO move this into an AspectJ project
+ protected static final boolean TRACE_ACTIONS = true;
+ protected static final boolean TRACE_AST_STACK = true;
+
+
+ /** Stack that holds the intermediate nodes as the AST is being built */
+ protected final ScopedStack