summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorahaase2008-02-18 07:25:57 (EST)
committer ahaase2008-02-18 07:25:57 (EST)
commit2d81a241f4252fe74810b2f82d9f72e53079f665 (patch)
tree3eebfc039d73acea5ad162144929cb6fb66e2014
parentaeacc5a21edf02c3eabdcb596bbb235d86026fdd (diff)
downloadorg.eclipse.xpand-2d81a241f4252fe74810b2f82d9f72e53079f665.zip
org.eclipse.xpand-2d81a241f4252fe74810b2f82d9f72e53079f665.tar.gz
org.eclipse.xpand-2d81a241f4252fe74810b2f82d9f72e53079f665.tar.bz2
refactored: removed explicit globalVar support from the backend - it is now part of the XtendLib
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java2
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/GlobalParamContext.java22
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java35
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java6
-rw-r--r--plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/GlobalParamContextImpl.java29
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java7
-rw-r--r--plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java17
7 files changed, 21 insertions, 97 deletions
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
index 802a71f..c21df69 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/ExecutionContext.java
@@ -21,8 +21,6 @@ public interface ExecutionContext {
LocalVarContext getLocalVarContext ();
void setLocalVarContext (LocalVarContext ctx);
- GlobalParamContext getGlobalParamContext ();
-
BackendTypesystem getTypesystem ();
FunctionDefContext getFunctionDefContext ();
void setFunctionDefContext (FunctionDefContext ctx);
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/GlobalParamContext.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/GlobalParamContext.java
deleted file mode 100644
index 16ded3e..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/common/GlobalParamContext.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-Copyright (c) 2008 Arno Haase.
-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:
- Arno Haase - initial API and implementation
- */
-package org.eclipse.xtend.backend.common;
-
-import java.util.Map;
-
-
-/**
- *
- * @author Arno Haase (http://www.haase-consulting.com)
- */
-public interface GlobalParamContext {
- Map<String, Object> getGlobalParams();
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java
deleted file mode 100644
index a4d9fe5..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/expr/GlobalParamExpression.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-Copyright (c) 2008 Arno Haase.
-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:
- Arno Haase - initial API and implementation
- */
-package org.eclipse.xtend.backend.expr;
-
-import org.eclipse.xtend.backend.common.ExecutionContext;
-import org.eclipse.xtend.backend.common.ExpressionBase;
-import org.eclipse.xtend.backend.common.SourcePos;
-
-/**
- * A "global variable" is a constant that is bound outside the execution of the program. Its
- * purpose is to e.g. make configuration properties available inside the program.
- *
- * @author Arno Haase (http://www.haase-consulting.com)
- */
-public final class GlobalParamExpression extends ExpressionBase {
- private final String _varName;
-
- public GlobalParamExpression (String varName, SourcePos sourcePos) {
- super(sourcePos);
- _varName = varName;
- }
-
- @Override
- protected Object evaluateInternal (ExecutionContext ctx) {
- return ctx.getGlobalParamContext().getGlobalParams().get (_varName);
- }
-}
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
index fa22cf5..c27ba97 100644
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/ExecutionContextImpl.java
@@ -21,7 +21,6 @@ import org.eclipse.xtend.backend.common.CreationCache;
import org.eclipse.xtend.backend.common.ExecutionContext;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.FunctionInvoker;
-import org.eclipse.xtend.backend.common.GlobalParamContext;
import org.eclipse.xtend.backend.common.LocalVarContext;
import org.eclipse.xtend.backend.common.SourcePos;
import org.eclipse.xtend.backend.common.StacktraceEntry;
@@ -37,7 +36,6 @@ public final class ExecutionContextImpl implements ExecutionContext {
private LocalVarContext _localVarContext = new LocalVarContext ();
private final FunctionInvoker _functionInvoker = new FunctionInvokerImpl ();
private final BackendTypesystem _typeSystem;
- private final GlobalParamContext _globalParamContext = new GlobalParamContextImpl ();
private final boolean _logStacktrace;
private final List<StacktraceEntry> _stacktrace = new ArrayList<StacktraceEntry> ();
@@ -77,10 +75,6 @@ public final class ExecutionContextImpl implements ExecutionContext {
return _typeSystem;
}
- public GlobalParamContext getGlobalParamContext() {
- return _globalParamContext;
- }
-
public void logNullDeRef (SourcePos pos) {
final StringBuilder sb = new StringBuilder ("dereferenced null " + ((pos != null) ? ("(" + pos + ")") : ""));
for (int i=_stacktrace.size() - 1; i>= 0; i--)
diff --git a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/GlobalParamContextImpl.java b/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/GlobalParamContextImpl.java
deleted file mode 100644
index 53b596e..0000000
--- a/plugins/org.eclipse.xtend.backend/src/org/eclipse/xtend/backend/internal/GlobalParamContextImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-Copyright (c) 2008 Arno Haase.
-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:
- Arno Haase - initial API and implementation
- */
-package org.eclipse.xtend.backend.internal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.xtend.backend.common.GlobalParamContext;
-
-
-/**
- *
- * @author Arno Haase (http://www.haase-consulting.com)
- */
-public final class GlobalParamContextImpl implements GlobalParamContext {
- private final Map<String, Object> _globalVars = new HashMap<String, Object> ();
-
- public Map<String, Object> getGlobalParams() {
- return _globalVars;
- }
-}
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
index cfc5d26..6e474d3 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/OldExpressionConverter.java
@@ -64,6 +64,7 @@ import org.eclipse.xtend.backend.types.builtin.CollectionType;
import org.eclipse.xtend.backend.types.builtin.ObjectType;
import org.eclipse.xtend.backend.util.CollectionHelper;
import org.eclipse.xtend.backend.util.Pair;
+import org.eclipse.xtend.backend.xtendlib.XtendLibNames;
import org.eclipse.xtend.expression.ExecutionContext;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.typesystem.StaticProperty;
@@ -115,7 +116,7 @@ final class OldExpressionConverter {
return convertBooleanOperation ((BooleanOperation) expr);
if (expr instanceof GlobalVarExpression)
- return new org.eclipse.xtend.backend.expr.GlobalParamExpression (((GlobalVarExpression) expr).getVarName(), getSourcePos(expr));
+ return convertGlobalVarExpression ((GlobalVarExpression) expr);
if (expr instanceof LetExpression)
return convertLetExpression((LetExpression) expr);
if (expr instanceof ChainExpression)
@@ -402,6 +403,10 @@ final class OldExpressionConverter {
return result;
}
+ private ExpressionBase convertGlobalVarExpression (GlobalVarExpression expr) {
+ return new InvocationOnObjectExpression (XtendLibNames.GLOBAL_VAR_VALUE, Arrays.asList (new LiteralExpression (expr.getVarName(), getSourcePos(expr))), true, getSourcePos (expr));
+ }
+
private ExpressionBase convertBooleanOperation (BooleanOperation expr) {
final ExpressionBase left = convert (expr.getLeft());
final ExpressionBase right = convert (expr.getRight());
diff --git a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
index 222d28c..bddf50f 100644
--- a/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.old/src/org/eclipse/xtend/middleend/old/XtendBackendFacade.java
@@ -25,7 +25,10 @@ import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.FunctionDefContext;
import org.eclipse.xtend.backend.common.NamedFunction;
import org.eclipse.xtend.backend.functions.FunctionDefContextFactory;
+import org.eclipse.xtend.backend.functions.FunctionDefContextInternal;
import org.eclipse.xtend.backend.functions.SourceDefinedFunction;
+import org.eclipse.xtend.backend.xtendlib.XtendGlobalVarOperations;
+import org.eclipse.xtend.backend.xtendlib.XtendLibContributor;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtend.typesystem.MetaModel;
@@ -85,13 +88,23 @@ public final class XtendBackendFacade {
final ExpressionBase newAst = new OldExpressionConverter (ctx, typeConverter, "<no file>").convert(oldAst);
- final FunctionDefContext fdc = (initialXtendFileName != null) ? createForFile (initialXtendFileName, fileEncoding, mms).getFunctionDefContext() : new FunctionDefContextFactory (ts).create();
+ final FunctionDefContext fdc = createEmptyFdc (ts, initialXtendFileName, fileEncoding, mms);
final ExecutionContext newCtx = BackendFacade.createExecutionContext (fdc, ts, true); //TODO configure isLogStacktrace
newCtx.getLocalVarContext().getLocalVars().putAll (localVars);
- newCtx.getGlobalParamContext().getGlobalParams().putAll (globalVars);
+ newCtx.getContributionStateContext().storeState (XtendGlobalVarOperations.GLOBAL_VAR_VALUES_KEY, globalVars);
return newAst.evaluate (newCtx);
}
+
+ private static FunctionDefContext createEmptyFdc (BackendTypesystem ts, String initialXtendFileName, String fileEncoding, Collection<MetaModel> mms) {
+ if (initialXtendFileName != null)
+ return createForFile (initialXtendFileName, fileEncoding, mms).getFunctionDefContext();
+
+ final FunctionDefContextInternal result = new FunctionDefContextFactory (ts).create();
+ result.register (new XtendLibContributor (ts).getContributedFunctions());
+ return result;
+ }
+
/**
* This function invokes a single Xtend function, returning the result. The fileEncoding may be null, in which case the platform's default file