Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2009-02-03 17:08:46 -0500
committerMike Kucera2009-02-03 17:08:46 -0500
commit897c5adf97a6c4c7ca020b1363564613cc1ad995 (patch)
treec9b95b4d120a3e5579b8b7ce594d4063fb1bb241 /lrparser
parent018af1b16ca786189bd9f097924684898544b9df (diff)
downloadorg.eclipse.cdt-897c5adf97a6c4c7ca020b1363564613cc1ad995.tar.gz
org.eclipse.cdt-897c5adf97a6c4c7ca020b1363564613cc1ad995.tar.xz
org.eclipse.cdt-897c5adf97a6c4c7ca020b1363564613cc1ad995.zip
added support for IBuiltinBindingsProvider to LR parsers
Diffstat (limited to 'lrparser')
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF2
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java28
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java59
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java7
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java6
-rw-r--r--lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java6
7 files changed, 113 insertions, 2 deletions
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
index 2a04b411e6..403832ca95 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
+++ b/lrparser/org.eclipse.cdt.core.lrparser/META-INF/MANIFEST.MF
@@ -23,3 +23,5 @@ Export-Package: org.eclipse.cdt.core.dom.lrparser,
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.cdt.core.dom.lrparser.LRParserPlugin
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
index 3bbac21499..b9cf479f36 100644
--- 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
@@ -15,13 +15,17 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.dom.parser.CLanguageKeywords;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.AbstractLanguage;
@@ -34,6 +38,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ASTPrinter;
import org.eclipse.cdt.core.parser.util.DebugUtil;
+import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
@@ -41,6 +46,7 @@ import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Status;
/**
@@ -87,6 +93,11 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
protected abstract IScannerExtensionConfiguration getScannerExtensionConfiguration();
+ /**
+ * Returns a bindings provider that will provide additional bindings based on the language extension.
+ */
+ protected abstract IBuiltinBindingsProvider getBuiltinBindingsProvider();
+
@SuppressWarnings("nls")
@Override
@@ -143,8 +154,23 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage {
- private static void setUpTranslationUnit(IASTTranslationUnit tu, IScanner preprocessor, IIndex index) {
+ private void setUpTranslationUnit(IASTTranslationUnit tu, IScanner preprocessor, IIndex index) throws CoreException {
tu.setIndex(index);
+
+ // add built-in names to the scope
+ IBuiltinBindingsProvider builtinBindingsProvider = getBuiltinBindingsProvider();
+ if (builtinBindingsProvider != null) {
+ IScope tuScope = tu.getScope();
+ IBinding[] bindings = builtinBindingsProvider.getBuiltinBindings(tuScope);
+ try {
+ for (IBinding binding : bindings) {
+ ASTInternal.addBinding(tuScope, binding);
+ }
+ } catch (DOMException e) {
+ throw new CoreException(LRParserPlugin.createStatus(e));
+ }
+ }
+
if(tu instanceof ASTTranslationUnit) {
((ASTTranslationUnit)tu).setLocationResolver(preprocessor.getLocationResolver());
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java
new file mode 100644
index 0000000000..69b6036ca6
--- /dev/null
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/LRParserPlugin.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core.dom.lrparser;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+
+
+public class LRParserPlugin extends Plugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.cdt.core.lrparser"; //$NON-NLS-1$
+
+
+ @SuppressWarnings("unused")
+ private static LRParserPlugin plugin;
+
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ try {
+ // shutdown code goes here
+ plugin = null;
+ }
+ finally {
+ super.stop(context);
+ }
+ }
+
+ /**
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ public static IStatus createStatus(String msg, Throwable e) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e);
+ }
+
+ /**
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ public static IStatus createStatus(Throwable e) {
+ return createStatus(e.getMessage(), e);
+ }
+
+}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java
index df858af37d..3bcb06dff6 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/c99/C99Language.java
@@ -16,7 +16,9 @@ import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.c.ANSICParserExtensionConfiguration;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ParserLanguage;
@@ -70,4 +72,9 @@ public class C99Language extends BaseExtensibleLanguage {
return ParserLanguage.C;
}
+ @Override
+ protected IBuiltinBindingsProvider getBuiltinBindingsProvider() {
+ return new ANSICParserExtensionConfiguration().getBuiltinBindingsProvider();
+ }
+
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java
index a07d32465b..0c514b89d3 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/cpp/ISOCPPLanguage.java
@@ -16,7 +16,9 @@ import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
import org.eclipse.cdt.core.dom.lrparser.ScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.ParserLanguage;
@@ -69,5 +71,8 @@ public class ISOCPPLanguage extends BaseExtensibleLanguage {
return ParserLanguage.CPP;
}
-
+ @Override
+ protected IBuiltinBindingsProvider getBuiltinBindingsProvider() {
+ return new ANSICPPParserExtensionConfiguration().getBuiltinBindingsProvider();
+ }
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java
index 6cbfc2272f..9d69cf4034 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GCCLanguage.java
@@ -15,7 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.c.GCCParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -69,4 +71,8 @@ public class GCCLanguage extends BaseExtensibleLanguage {
return ParserLanguage.C;
}
+ @Override
+ protected IBuiltinBindingsProvider getBuiltinBindingsProvider() {
+ return new GCCParserExtensionConfiguration().getBuiltinBindingsProvider();
+ }
}
diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java
index 219f540088..7bf49dcca1 100644
--- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java
+++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/gnu/GPPLanguage.java
@@ -15,7 +15,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage;
import org.eclipse.cdt.core.dom.lrparser.IDOMTokenMap;
import org.eclipse.cdt.core.dom.lrparser.IParser;
+import org.eclipse.cdt.core.dom.parser.IBuiltinBindingsProvider;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
+import org.eclipse.cdt.core.dom.parser.cpp.GPPParserExtensionConfiguration;
import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -69,4 +71,8 @@ public class GPPLanguage extends BaseExtensibleLanguage {
return ParserLanguage.CPP;
}
+ @Override
+ protected IBuiltinBindingsProvider getBuiltinBindingsProvider() {
+ return new GPPParserExtensionConfiguration().getBuiltinBindingsProvider();
+ }
}

Back to the top