summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsefftinge2008-03-05 08:01:46 (EST)
committersefftinge2008-03-05 08:01:46 (EST)
commit3553236d4eb56787873fe00698dddd71691c78fa (patch)
tree0852a50a346a0331083fd40598bd2afbb1460a33
parent7fcc1f51426ca3c974f164f0102571f12a4119de (diff)
downloadorg.eclipse.xpand-3553236d4eb56787873fe00698dddd71691c78fa.zip
org.eclipse.xpand-3553236d4eb56787873fe00698dddd71691c78fa.tar.gz
org.eclipse.xpand-3553236d4eb56787873fe00698dddd71691c78fa.tar.bz2
static typesystem (434th draft)
-rw-r--r--plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/AnalyzeContext.java47
-rw-r--r--plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/DeclarationsContributorFactory.java15
-rw-r--r--plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/LanguageSpecificDeclarationContributorFactory.java32
3 files changed, 93 insertions, 1 deletions
diff --git a/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/AnalyzeContext.java b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/AnalyzeContext.java
index e19feba..4d76250 100644
--- a/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/AnalyzeContext.java
+++ b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/AnalyzeContext.java
@@ -15,6 +15,8 @@
*/
package org.eclipse.xand3.analyzation;
+import java.util.HashMap;
+
import org.eclipse.xpand3.staticTypesystem.AbstractTypeReference;
/**
@@ -28,8 +30,51 @@ public interface AnalyzeContext {
boolean hasThis();
Var getThis();
Var getVariable(String varName);
-
AnalyzeContext cloneWith(Var var);
+
+ public final static AnalyzeContext EMPTY_CTX = new AnalyzeContextImpl();
+
+ class AnalyzeContextImpl implements AnalyzeContext {
+ private HashMap<String, Var> scope = new HashMap<String, Var>();
+ public AnalyzeContextImpl() {
+ }
+ /**
+ *
+ */
+ public AnalyzeContextImpl(AnalyzeContextImpl old) {
+ scope.putAll(old.scope);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.xand3.analyzation.AnalyzeContext#cloneWith(org.eclipse.xand3.analyzation.AnalyzeContext.Var)
+ */
+ public AnalyzeContext cloneWith(Var var) {
+ AnalyzeContextImpl newOne = new AnalyzeContextImpl(this);
+ newOne.scope.put(var.name, var);
+ return newOne;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xand3.analyzation.AnalyzeContext#getThis()
+ */
+ public Var getThis() {
+ return scope.get(IMPLICIT_VARIABLE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xand3.analyzation.AnalyzeContext#getVariable(java.lang.String)
+ */
+ public Var getVariable(String varName) {
+ return scope.get(varName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.xand3.analyzation.AnalyzeContext#hasThis()
+ */
+ public boolean hasThis() {
+ return scope.containsKey(IMPLICIT_VARIABLE);
+ }
+
+ }
public class Var {
diff --git a/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/DeclarationsContributorFactory.java b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/DeclarationsContributorFactory.java
index d2320b1..f92bf52 100644
--- a/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/DeclarationsContributorFactory.java
+++ b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/DeclarationsContributorFactory.java
@@ -15,13 +15,28 @@
*/
package org.eclipse.xand3.analyzation.typesystem;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* @author Sven Efftinge
*
*/
public class DeclarationsContributorFactory {
+
+ private final static Set<LanguageSpecificDeclarationContributorFactory> factories = new HashSet<LanguageSpecificDeclarationContributorFactory>();
+
+ public static void registerLanguageSpecificFactory(LanguageSpecificDeclarationContributorFactory factory) {
+ factories.add(factory);
+ }
+
public static DeclarationsContributor createDeclarationContributor(String namespace) {
+ for (LanguageSpecificDeclarationContributorFactory factory : factories) {
+ if (factory.canHandle(namespace)) {
+ return factory.createDeclarationContributor(namespace);
+ }
+ }
return null;
}
}
diff --git a/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/LanguageSpecificDeclarationContributorFactory.java b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/LanguageSpecificDeclarationContributorFactory.java
new file mode 100644
index 0000000..b32e6e3
--- /dev/null
+++ b/plugins/org.eclipse.xpand3/src/org/eclipse/xand3/analyzation/typesystem/LanguageSpecificDeclarationContributorFactory.java
@@ -0,0 +1,32 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2002-2007 itemis AG 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:
+ * itemis AG - Initial API and implementation
+ *
+ * </copyright>
+ *
+ */
+package org.eclipse.xand3.analyzation.typesystem;
+
+/**
+ * @author Sven Efftinge
+ *
+ */
+public interface LanguageSpecificDeclarationContributorFactory {
+ /**
+ * gives the middle end a way to declare if it can and wants to handle a given
+ * source file / resource. If and only if it returns true, it will be asked for
+ * the functions and advice provided in this resource.
+ */
+ boolean canHandle (String resourceName);
+
+
+ DeclarationsContributor createDeclarationContributor(String resourceName);
+}