summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsefftinge2008-03-04 11:03:11 (EST)
committer sefftinge2008-03-04 11:03:11 (EST)
commite01af59c42b0f8a812da1a73d98b68203e906324 (patch)
tree5c68262da285598d0af5e2a1fc8993dea711e881
parentd1ad1ec9f6e2d1f11dbc9b1d00afb766571defae (diff)
downloadorg.eclipse.xpand-e01af59c42b0f8a812da1a73d98b68203e906324.zip
org.eclipse.xpand-e01af59c42b0f8a812da1a73d98b68203e906324.tar.gz
org.eclipse.xpand-e01af59c42b0f8a812da1a73d98b68203e906324.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/BackendTypeConverter.java2
-rw-r--r--plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendBackendFacade.java16
-rw-r--r--plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendFrontendASTConverter.java53
3 files changed, 36 insertions, 35 deletions
diff --git a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/BackendTypeConverter.java b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/BackendTypeConverter.java
index 1ff4438..a700382 100644
--- a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/BackendTypeConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/BackendTypeConverter.java
@@ -37,7 +37,7 @@ public class BackendTypeConverter {
return getEnumLiteral(qualify(name));
}
- private String qualify(Identifier name) {
+ public static String qualify(Identifier name) {
String value = name.getValue();
if (name.getNext() != null) {
value += SyntaxConstants.NS_DELIM + qualify(name.getNext());
diff --git a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendBackendFacade.java b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendBackendFacade.java
index 3822893..7180a5f 100644
--- a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendBackendFacade.java
+++ b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendBackendFacade.java
@@ -51,26 +51,10 @@ public class XtendBackendFacade {
throw new UnsupportedOperationException("Not yet implemented");
}
- public static Object evaluateExpression(String extensionFile, String expression, Map<String, Object> localVars) {
- return createForFile(extensionFile).evaluateExpression(expression, localVars);
- }
-
private static XtendBackendFacade createForFile(String extensionFile) {
return new XtendBackendFacade(extensionFile);
}
- private Object evaluateExpression(String expression, Map<String, Object> localVars) {
- if (localVars == null)
- localVars = new HashMap<String, Object>();
- File f = parse();
-
- Extension ext = ctx.findExtension(expression, f.getDeclarations());
- ExpressionBase expr = new XtendFrontendASTConverter(ctx, typeConverter, extensionFile
- + SyntaxConstants.NS_DELIM + ext.getName().getValue()).convert(ext);
-
- return expr.evaluate(middleEnd.getExecutionContext());
- }
-
private File parse() {
// TODO: To be impl
throw new UnsupportedOperationException("Not yet impl");
diff --git a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendFrontendASTConverter.java b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendFrontendASTConverter.java
index d0eaabb..43cb1e4 100644
--- a/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendFrontendASTConverter.java
+++ b/plugins/org.eclipse.xtend.middleend.xpand3/src/org/eclipse/xtend/middleend/internal/xpand3/XtendFrontendASTConverter.java
@@ -20,6 +20,9 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.xand3.analyzation.AnalyzeContext;
+import org.eclipse.xand3.analyzation.TypeSystem;
+import org.eclipse.xand3.analyzation.AnalyzeContext.Var;
+import org.eclipse.xpand3.Identifier;
import org.eclipse.xpand3.SyntaxElement;
import org.eclipse.xpand3.expression.AbstractExpression;
import org.eclipse.xpand3.expression.BooleanLiteral;
@@ -42,6 +45,8 @@ import org.eclipse.xpand3.expression.StringLiteral;
import org.eclipse.xpand3.expression.SwitchExpression;
import org.eclipse.xpand3.expression.TypeSelectExpression;
import org.eclipse.xpand3.staticTypesystem.AbstractTypeReference;
+import org.eclipse.xpand3.staticTypesystem.FunctionType;
+import org.eclipse.xpand3.staticTypesystem.Type;
import org.eclipse.xtend.backend.common.ExpressionBase;
import org.eclipse.xtend.backend.common.SourcePos;
import org.eclipse.xtend.backend.common.StaticProperty;
@@ -74,6 +79,7 @@ public class XtendFrontendASTConverter {
private String extensionName;
private final BackendTypeConverter typeConverter;
private AnalyzeContext ctx;
+ private TypeSystem typeSystem;
public XtendFrontendASTConverter(AnalyzeContext ctx, BackendTypeConverter typeConverter, String extensionName) {
this.ctx = ctx;
@@ -140,7 +146,7 @@ public class XtendFrontendASTConverter {
return new LiteralExpression(staticProp.get(), sourcePos);
// 2. check for a local variable
- if (ctx.getLocalVars().containsKey(expr.getName().getValue()))
+ if (ctx.getVariable(expr.getName().getValue()) != null)
return new LocalVarEvalExpression(expr.getName().getValue(), sourcePos);
// 3. check for a type literal
@@ -172,9 +178,10 @@ public class XtendFrontendASTConverter {
final String functionName = expr.getName().getValue();
final AnalyzeContext oldCtx = ctx;
- ctx = ctx.cloneWithVariable(expr.getEleName(), null /*
- * TODO ObjectType
- */);
+ ctx = ctx.cloneWith(new AnalyzeContext.Var(BackendTypeConverter.qualify(expr.getEleName()), null) /*
+ * TODO
+ * ObjectType
+ */);
final ExpressionBase bodyExpr = convert(expr.getClosure());
ctx = oldCtx;
@@ -196,7 +203,9 @@ public class XtendFrontendASTConverter {
public ExpressionBase convert(TypeSelectExpression expr) {
final SourcePos sourcePos = getSourcePos(expr);
- final AbstractExpression t = ctx.getTypeForName(expr.getTypeLiteral());
+ final Type t = typeSystem.typeForName(toString(expr.getTypeLiteral()));// TODO
+ // type
+ // args
final ExpressionBase typeExpr = new LiteralExpression(typeConverter.convertToBackendType(t), sourcePos);
if (expr.getTarget() == null) {
@@ -212,6 +221,14 @@ public class XtendFrontendASTConverter {
typeExpr), false, sourcePos);
}
+ /**
+ * @param typeLiteral
+ * @return
+ */
+ private String toString(Identifier id) {
+ return BackendTypeConverter.qualify(id);
+ }
+
public ExpressionBase convert(OperationCall expr) {
final SourcePos sourcePos = getSourcePos(expr);
final String functionName = transformFunctionName(expr.getName().getValue());
@@ -234,7 +251,8 @@ public class XtendFrontendASTConverter {
else {
final ExpressionBase thisExpression = new LocalVarEvalExpression(
org.eclipse.xtend.backend.common.SyntaxConstants.THIS, sourcePos);
- final AbstractTypeReference thisType = ctx.getVariable(AnalyzeContext.IMPLICIT_VARIABLE);
+ Var thisVar = ctx.getThis();
+ final AbstractTypeReference thisType = thisVar.getValue();
return createInvocationOnTargetExpression(functionName, thisExpression, thisType, params,
paramTypes, true, sourcePos);
}
@@ -263,15 +281,16 @@ public class XtendFrontendASTConverter {
final AbstractTypeReference varType = analyze(expr.getVarExpression());
final AnalyzeContext oldCtx = ctx;
- ctx = ctx.cloneWithVariable(expr.getVarName(), varType);
+ String varName = toString(expr.getVarName());
+ ctx = ctx.cloneWith(new AnalyzeContext.Var(varName, varType));
try {
- if (oldCtx.getLocalVars().containsKey(expr.getVarName()))
- return new HidingLocalVarDefExpression(expr.getVarName().getValue(), varExpr, convert(expr
- .getTargetExpression()), getSourcePos(expr));
+ if (oldCtx.getVariable(varName) != null)
+ return new HidingLocalVarDefExpression(varName, varExpr, convert(expr.getTargetExpression()),
+ getSourcePos(expr));
else
- return new NewLocalVarDefExpression(expr.getVarName().getValue(), varExpr, convert(expr
- .getTargetExpression()), getSourcePos(expr));
+ return new NewLocalVarDefExpression(varName, varExpr, convert(expr.getTargetExpression()),
+ getSourcePos(expr));
} finally {
ctx = oldCtx;
}
@@ -364,14 +383,12 @@ public class XtendFrontendASTConverter {
}
private boolean hasMatchingOperationCall(String functionName, AbstractTypeReference[] paramTypes) {
- if (ctx.getExtensionForTypes(functionName, paramTypes) != null)
+ FunctionType functionType = typeSystem.functionForNameAndParameterTypes(functionName, paramTypes);
+ if (functionType != null) {
return true;
-
- if (paramTypes.length == 0)
+ } else {
return false;
-
- final AbstractTypeReference target = paramTypes[0];
- return ctx.getOperationFor(target, functionName, CollectionHelper.withoutFirst(paramTypes)) != null;
+ }
}
private ExpressionBase createPropertyExpression(ExpressionBase target, Object type, String varName,