|
@@ -10,8 +10,11 @@
|
|
|
*/
|
|
*/
|
|
|
package org.yakindu.sct.simulation.runtime.stext.builder;
|
|
package org.yakindu.sct.simulation.runtime.stext.builder;
|
|
|
|
|
|
|
|
-import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.*;
|
|
|
|
|
|
|
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_AND;
|
|
|
|
|
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_OR;
|
|
|
|
|
+import static org.yakindu.sct.simulation.runtime.stext.CoreFunction.BIT_XOR;
|
|
|
|
|
|
|
|
|
|
+import java.io.StringReader;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -19,479 +22,499 @@ import java.util.Map;
|
|
|
|
|
|
|
|
import org.eclipse.emf.common.util.Enumerator;
|
|
import org.eclipse.emf.common.util.Enumerator;
|
|
|
import org.eclipse.emf.ecore.EAttribute;
|
|
import org.eclipse.emf.ecore.EAttribute;
|
|
|
-import org.eclipse.emf.ecore.EEnumLiteral;
|
|
|
|
|
import org.eclipse.emf.ecore.EObject;
|
|
import org.eclipse.emf.ecore.EObject;
|
|
|
import org.eclipse.emf.ecore.EReference;
|
|
import org.eclipse.emf.ecore.EReference;
|
|
|
import org.eclipse.emf.ecore.EStructuralFeature;
|
|
import org.eclipse.emf.ecore.EStructuralFeature;
|
|
|
-
|
|
|
|
|
-import org.yakindu.sct.simulation.runtime.stext.*;
|
|
|
|
|
|
|
+import org.eclipse.xtext.ParserRule;
|
|
|
|
|
+import org.eclipse.xtext.XtextFactory;
|
|
|
|
|
+import org.eclipse.xtext.nodemodel.INode;
|
|
|
|
|
+import org.eclipse.xtext.parser.IParseResult;
|
|
|
|
|
+import org.eclipse.xtext.parser.IParser;
|
|
|
|
|
+import org.yakindu.sct.model.stext.ui.internal.STextActivator;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Assign;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.BinaryOperation;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Conditional;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Constant;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Function;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.FunctionMethod;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.ProcedureCall;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.RTExpression;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.RTTrigger;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Raise;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.Statement;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.StatementSequence;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.UnaryOperation;
|
|
|
|
|
+import org.yakindu.sct.simulation.runtime.stext.VariableRef;
|
|
|
|
|
+
|
|
|
|
|
+import com.google.inject.Inject;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * The ExpressionBuilder creates an executable structure from the textual expression definition
|
|
|
|
|
- * or the corresponding EMF based abstract syntax tree. This AST is defined by the expression grammer
|
|
|
|
|
- * of this plugin.<br>
|
|
|
|
|
|
|
+ * The ExpressionBuilder creates an executable structure from the textual
|
|
|
|
|
+ * expression definition or the corresponding EMF based abstract syntax tree.
|
|
|
|
|
+ * This AST is defined by the expression grammer of this plugin.<br>
|
|
|
* <br>
|
|
* <br>
|
|
|
- * Expression builder instances are state-less so a single instance can be used to build
|
|
|
|
|
- * expression runtime structures multiple times and in parallel.<br>
|
|
|
|
|
|
|
+ * Expression builder instances are state-less so a single instance can be used
|
|
|
|
|
+ * to build expression runtime structures multiple times and in parallel.<br>
|
|
|
* <br>
|
|
* <br>
|
|
|
- * The current implementation mainly consist of a set of builder functions with a name prefix 'build'.
|
|
|
|
|
- * This class defines a build function for each grammar rule. So when changing the grammer it will be necessary
|
|
|
|
|
- * to change, add or remove build methods for the affected grammar rules. The implementation strongly relies on dynamic dispatch of build function calls and therefore
|
|
|
|
|
|
|
+ * The current implementation mainly consist of a set of builder functions with
|
|
|
|
|
+ * a name prefix 'build'. This class defines a build function for each grammar
|
|
|
|
|
+ * rule. So when changing the grammer it will be necessary to change, add or
|
|
|
|
|
+ * remove build methods for the affected grammar rules. The implementation
|
|
|
|
|
+ * strongly relies on dynamic dispatch of build function calls and therefore
|
|
|
* makes use of the 'pluggable adapter' pattern and Java reflection. <br>
|
|
* makes use of the 'pluggable adapter' pattern and Java reflection. <br>
|
|
|
* <br>
|
|
* <br>
|
|
|
- * Example:
|
|
|
|
|
- * <code>
|
|
|
|
|
|
|
+ * Example: <code>
|
|
|
* (new ExpressionBuilder()).build("a = 2*b; a <<= 2;");
|
|
* (new ExpressionBuilder()).build("a = 2*b; a <<= 2;");
|
|
|
* </code>
|
|
* </code>
|
|
|
*
|
|
*
|
|
|
* @author terfloth@itemis.de
|
|
* @author terfloth@itemis.de
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
*/
|
|
*/
|
|
|
public class ExpressionBuilder extends Function {
|
|
public class ExpressionBuilder extends Function {
|
|
|
|
|
|
|
|
- /** Builder functions always*/
|
|
|
|
|
- protected static Class<?>[] paramTypes = new Class[]{EObject.class};
|
|
|
|
|
|
|
+ @Inject
|
|
|
|
|
+ private IParser parser;
|
|
|
|
|
+
|
|
|
|
|
+ /** Builder functions always */
|
|
|
|
|
+ protected static Class<?>[] paramTypes = new Class[] { EObject.class };
|
|
|
|
|
|
|
|
protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
|
|
protected static Map<String, String> assignFunctionMap = new HashMap<String, String>();
|
|
|
|
|
|
|
|
static {
|
|
static {
|
|
|
- assignFunctionMap.put("multAssign", "*");
|
|
|
|
|
- assignFunctionMap.put("divAssign", "/");
|
|
|
|
|
|
|
+ assignFunctionMap.put("multAssign", "*");
|
|
|
|
|
+ assignFunctionMap.put("divAssign", "/");
|
|
|
assignFunctionMap.put("modAssign", "%");
|
|
assignFunctionMap.put("modAssign", "%");
|
|
|
- assignFunctionMap.put("addAssign", "+");
|
|
|
|
|
- assignFunctionMap.put("subAssign", "-");
|
|
|
|
|
- assignFunctionMap.put("leftShiftAssign", "<<");
|
|
|
|
|
- assignFunctionMap.put("rightShiftAssign", ">>");
|
|
|
|
|
- assignFunctionMap.put("andAssign", "&");
|
|
|
|
|
- assignFunctionMap.put("xorAssign", "^");
|
|
|
|
|
|
|
+ assignFunctionMap.put("addAssign", "+");
|
|
|
|
|
+ assignFunctionMap.put("subAssign", "-");
|
|
|
|
|
+ assignFunctionMap.put("leftShiftAssign", "<<");
|
|
|
|
|
+ assignFunctionMap.put("rightShiftAssign", ">>");
|
|
|
|
|
+ assignFunctionMap.put("andAssign", "&");
|
|
|
|
|
+ assignFunctionMap.put("xorAssign", "^");
|
|
|
assignFunctionMap.put("orAssign", "|");
|
|
assignFunctionMap.put("orAssign", "|");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public ExpressionBuilder() {
|
|
|
|
|
+ parser = STextActivator.getInstance()
|
|
|
|
|
+ .getInjector("org.yakindu.sct.model.stext.SText")
|
|
|
|
|
+ .getInstance(IParser.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * Static helper method that creates a executable expression structure from a expression string.
|
|
|
|
|
|
|
+ * Static helper method that creates a executable expression structure from
|
|
|
|
|
+ * a expression string.
|
|
|
*
|
|
*
|
|
|
* @param actionExpression
|
|
* @param actionExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
public static Statement buildAction(String actionExpression) {
|
|
public static Statement buildAction(String actionExpression) {
|
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
|
- return builder.buildActionExpression(actionExpression);
|
|
|
|
|
|
|
+ return builder.buildEffect(actionExpression);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Static helper method that creates a executable expression structure from a expression string.
|
|
|
|
|
|
|
+ * Static helper method that creates a executable expression structure from
|
|
|
|
|
+ * a expression string.
|
|
|
*
|
|
*
|
|
|
* @param guardExpression
|
|
* @param guardExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
- public static Expression buildGuard(String guardExpression) {
|
|
|
|
|
|
|
+ public static RTExpression buildGuard(String guardExpression) {
|
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
|
return builder.buildGuardExpression(guardExpression);
|
|
return builder.buildGuardExpression(guardExpression);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Static helper method that creates a executable expression structure from a expression string.
|
|
|
|
|
|
|
+ * Static helper method that creates a executable expression structure from
|
|
|
|
|
+ * a expression string.
|
|
|
*
|
|
*
|
|
|
* @param guardExpression
|
|
* @param guardExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
- public static List<Trigger> buildTriggers(String guardExpression) {
|
|
|
|
|
|
|
+ public static List<RTTrigger> buildTriggers(String guardExpression) {
|
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
ExpressionBuilder builder = new ExpressionBuilder();
|
|
|
return builder.buildTriggerExpression(guardExpression);
|
|
return builder.buildTriggerExpression(guardExpression);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * The primary builder method that creates a executable statement structure from a expression string.
|
|
|
|
|
|
|
+ * The primary builder method that creates a executable statement structure
|
|
|
|
|
+ * from a expression string.
|
|
|
*
|
|
*
|
|
|
* @param actionExpression
|
|
* @param actionExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
- public Statement buildActionExpression(String expr) {
|
|
|
|
|
- EObject root = JavaExtensions.parseActionExpressionObject(expr);
|
|
|
|
|
- return (Statement) build(root);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public Statement buildEffect(String expr) {
|
|
|
|
|
+ ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
|
|
|
|
|
+ parserRule.setName("Statement");
|
|
|
|
|
+ IParseResult result = parser.parse(parserRule, new StringReader(expr));
|
|
|
|
|
+ if(result.hasSyntaxErrors()){
|
|
|
|
|
+ StringBuilder errorMessages = new StringBuilder();
|
|
|
|
|
+ Iterable<INode> syntaxErrors = result.getSyntaxErrors();
|
|
|
|
|
+ for (INode iNode : syntaxErrors) {
|
|
|
|
|
+ errorMessages.append(iNode.getSyntaxErrorMessage());
|
|
|
|
|
+ errorMessages.append("\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new RuntimeException("Could not parse expression, syntax errors: " + errorMessages);
|
|
|
|
|
+ }
|
|
|
|
|
+ EObject rootASTElement = result.getRootASTElement();
|
|
|
|
|
+ return (Statement) build(rootASTElement);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * The primary builder method that creates a executable guard expression structure from an expression string.
|
|
|
|
|
|
|
+ * The primary builder method that creates a executable guard expression
|
|
|
|
|
+ * structure from an expression string.
|
|
|
*
|
|
*
|
|
|
* @param actionExpression
|
|
* @param actionExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
- public Expression buildGuardExpression(String expr) {
|
|
|
|
|
- EObject root = JavaExtensions.parseGuardExpressionObject(expr);
|
|
|
|
|
- return (Expression) build(root);
|
|
|
|
|
|
|
+ public RTExpression buildGuardExpression(String expr) {
|
|
|
|
|
+ EObject root = parser.parse(new StringReader(expr)).getRootASTElement();
|
|
|
|
|
+ return (RTExpression) build(root);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
- * The primary builder method that creates a executable guard expression structure from an expression string.
|
|
|
|
|
|
|
+ * The primary builder method that creates a executable guard expression
|
|
|
|
|
+ * structure from an expression string.
|
|
|
*
|
|
*
|
|
|
* @param actionExpression
|
|
* @param actionExpression
|
|
|
* @return an executable statement object.
|
|
* @return an executable statement object.
|
|
|
*/
|
|
*/
|
|
|
- public List<Trigger> buildTriggerExpression(String expr) {
|
|
|
|
|
- EObject root = JavaExtensions.parseTriggerExpressionObject(expr);
|
|
|
|
|
- return (List<Trigger>) build(root);
|
|
|
|
|
|
|
+ public List<RTTrigger> buildTriggerExpression(String expr) {
|
|
|
|
|
+ EObject root = parser.parse(new StringReader(expr)).getRootASTElement();
|
|
|
|
|
+ return (List<RTTrigger>) build(root);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public List<Trigger> buildTriggerExpression(EObject obj) {
|
|
|
|
|
- List<Trigger> triggers = new ArrayList<Trigger>();
|
|
|
|
|
|
|
+ public List<RTTrigger> buildTriggerExpression(EObject obj) {
|
|
|
|
|
+ List<RTTrigger> triggers = new ArrayList<RTTrigger>();
|
|
|
|
|
|
|
|
for (EObject child : obj.eContents()) {
|
|
for (EObject child : obj.eContents()) {
|
|
|
- Trigger trigger = (Trigger) build(child);
|
|
|
|
|
- if(trigger != null) triggers.add(trigger);
|
|
|
|
|
|
|
+ RTTrigger trigger = (RTTrigger) build(child);
|
|
|
|
|
+ if (trigger != null)
|
|
|
|
|
+ triggers.add(trigger);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return triggers;
|
|
return triggers;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Trigger buildTrigger(EObject obj) {
|
|
|
|
|
- return (Trigger) build(getToOne(obj, "event"));
|
|
|
|
|
|
|
+ public RTTrigger buildTrigger(EObject obj) {
|
|
|
|
|
+ return (RTTrigger) build(getToOne(obj, "event"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Trigger buildSignalEvent(EObject obj) {
|
|
|
|
|
- return new Trigger.SignalEvent(getString(obj, "identifier"));
|
|
|
|
|
|
|
+ public RTTrigger buildSignalEvent(EObject obj) {
|
|
|
|
|
+ return new RTTrigger.SignalEvent(getString(obj, "identifier"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Trigger buildTimeEvent(EObject obj) {
|
|
|
|
|
- return new Trigger.TimeEvent(buildRefExpression(obj, "duration"));
|
|
|
|
|
|
|
+ public RTTrigger buildTimeEvent(EObject obj) {
|
|
|
|
|
+ return new RTTrigger.TimeEvent(buildRefExpression(obj, "duration"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildTimeConstant(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildTimeConstant(EObject obj) {
|
|
|
int duration = getInteger(obj, "value");
|
|
int duration = getInteger(obj, "value");
|
|
|
String unit = getLiteral(obj, "unit");
|
|
String unit = getLiteral(obj, "unit");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (unit != null) {
|
|
if (unit != null) {
|
|
|
- if ("second".equals(unit)) duration *= 1000;
|
|
|
|
|
- else if ("nanosecond".equals(unit)) duration /= 1000;
|
|
|
|
|
|
|
+ if ("second".equals(unit))
|
|
|
|
|
+ duration *= 1000;
|
|
|
|
|
+ else if ("nanosecond".equals(unit))
|
|
|
|
|
+ duration /= 1000;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return new Constant(duration);
|
|
return new Constant(duration);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildGuardExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildGuardExpression(EObject obj) {
|
|
|
return buildRefExpression(obj, "expression");
|
|
return buildRefExpression(obj, "expression");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
public Statement buildActionExpression(EObject obj) {
|
|
public Statement buildActionExpression(EObject obj) {
|
|
|
StatementSequence seq = new StatementSequence();
|
|
StatementSequence seq = new StatementSequence();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for (EObject child : obj.eContents()) {
|
|
for (EObject child : obj.eContents()) {
|
|
|
Statement stmt = (Statement) build(child);
|
|
Statement stmt = (Statement) build(child);
|
|
|
- if(stmt != null) seq.add(stmt);
|
|
|
|
|
|
|
+ if (stmt != null)
|
|
|
|
|
+ seq.add(stmt);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return seq;
|
|
return seq;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
public Statement buildEventRaising(EObject obj) {
|
|
public Statement buildEventRaising(EObject obj) {
|
|
|
-
|
|
|
|
|
- EObject event = getToOne(obj, "event");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ EObject event = getToOne(obj, "event");
|
|
|
return new Raise(getString(event, "identifier"));
|
|
return new Raise(getString(event, "identifier"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
public Statement buildProcedureCall(EObject obj) {
|
|
public Statement buildProcedureCall(EObject obj) {
|
|
|
-
|
|
|
|
|
- EObject event = getToOne(obj, "procedure");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ EObject event = getToOne(obj, "procedure");
|
|
|
return new ProcedureCall(getString(event, "identifier"));
|
|
return new ProcedureCall(getString(event, "identifier"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Statement buildVariableAssignment(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public Statement buildAssignment(EObject obj) {
|
|
|
|
|
+
|
|
|
VariableRef var = (VariableRef) build(getToOne(obj, "variableReference"));
|
|
VariableRef var = (VariableRef) build(getToOne(obj, "variableReference"));
|
|
|
String operator = getLiteral(obj, "operator");
|
|
String operator = getLiteral(obj, "operator");
|
|
|
- Expression exp = (Expression) build(getToOne(obj, "value"));
|
|
|
|
|
|
|
+ RTExpression exp = (RTExpression) build(getToOne(obj, "expression"));
|
|
|
|
|
|
|
|
- if (! "assign".equals(operator)) {
|
|
|
|
|
|
|
+ if (!"assign".equals(operator)) {
|
|
|
String mappedOperator = assignFunctionMap.get(operator);
|
|
String mappedOperator = assignFunctionMap.get(operator);
|
|
|
- if (mappedOperator == null)
|
|
|
|
|
- throw new BuilderException("Assignment operator '" + operator + "' can not be resolved to a function.");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (mappedOperator == null)
|
|
|
|
|
+ throw new BuilderException("Assignment operator '" + operator
|
|
|
|
|
+ + "' can not be resolved to a function.");
|
|
|
|
|
+
|
|
|
exp = new BinaryOperation(mappedOperator, var, exp);
|
|
exp = new BinaryOperation(mappedOperator, var, exp);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return new Assign(var, exp);
|
|
return new Assign(var, exp);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildConditionalExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
- Expression op3 = buildRefExpression(obj, "operand3");
|
|
|
|
|
|
|
+ public RTExpression buildConditionalExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
+ RTExpression op3 = buildRefExpression(obj, "operand3");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null && op3 != null)
|
|
if (op1 != null && op2 != null && op3 != null)
|
|
|
return new Conditional(op1, op2, op3);
|
|
return new Conditional(op1, op2, op3);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildBooleanOrExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBooleanOrExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(BinaryOperation.OR, op1, op2);
|
|
return new BinaryOperation(BinaryOperation.OR, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildBooleanAndExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBooleanAndExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(BinaryOperation.AND, op1, op2);
|
|
return new BinaryOperation(BinaryOperation.AND, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildBitwiseXorExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBitwiseXorExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(BIT_XOR, op1, op2);
|
|
return new BinaryOperation(BIT_XOR, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildBitwiseOrExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBitwiseOrExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(BIT_OR, op1, op2);
|
|
return new BinaryOperation(BIT_OR, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildBitwiseAndExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBitwiseAndExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(BIT_AND, op1, op2);
|
|
return new BinaryOperation(BIT_AND, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
- public Expression buildBinaryOperation(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
- Expression op2 = buildRefExpression(obj, "operand2");
|
|
|
|
|
|
|
+ public RTExpression buildBinaryOperation(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression op1 = buildRefExpression(obj, "operand1");
|
|
|
|
|
+ RTExpression op2 = buildRefExpression(obj, "operand2");
|
|
|
String operator = getLiteral(obj, "operator");
|
|
String operator = getLiteral(obj, "operator");
|
|
|
|
|
|
|
|
if (op1 != null && op2 != null)
|
|
if (op1 != null && op2 != null)
|
|
|
return new BinaryOperation(operator, op1, op2);
|
|
return new BinaryOperation(operator, op1, op2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return op1;
|
|
return op1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildEqualityExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildEqualityExpression(EObject obj) {
|
|
|
return buildBinaryOperation(obj);
|
|
return buildBinaryOperation(obj);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildRelationalExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildRelationalExpression(EObject obj) {
|
|
|
return buildBinaryOperation(obj);
|
|
return buildBinaryOperation(obj);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildShiftExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildShiftExpression(EObject obj) {
|
|
|
return buildBinaryOperation(obj);
|
|
return buildBinaryOperation(obj);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildAdditiveExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildAdditiveExpression(EObject obj) {
|
|
|
return buildBinaryOperation(obj);
|
|
return buildBinaryOperation(obj);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildMultiplicativeExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildMultiplicativeExpression(EObject obj) {
|
|
|
return buildBinaryOperation(obj);
|
|
return buildBinaryOperation(obj);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildUnaryExpression(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- Expression operand = buildRefExpression(obj, "operand");
|
|
|
|
|
|
|
+ public RTExpression buildUnaryExpression(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ RTExpression operand = buildRefExpression(obj, "operand");
|
|
|
String operator = getLiteral(obj, "operator");
|
|
String operator = getLiteral(obj, "operator");
|
|
|
|
|
|
|
|
if (operand != null && operator != null)
|
|
if (operand != null && operator != null)
|
|
|
return new UnaryOperation(operator, operand);
|
|
return new UnaryOperation(operator, operand);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return operand;
|
|
return operand;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildNestedExpression(EObject obj) {
|
|
|
|
|
|
|
+ public RTExpression buildNestedExpression(EObject obj) {
|
|
|
return buildRefExpression(obj, "expression");
|
|
return buildRefExpression(obj, "expression");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildLiteralValue(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- String value = getString(obj, "value");
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public RTExpression buildLiteralValue(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ String value = getString(obj, "value");
|
|
|
|
|
+
|
|
|
// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
|
|
// TODO: nur provisrisch - Grammatik muss noch ge�ndert werden,
|
|
|
// um unterschiedliche Literaltypen unterscheiden zu koennen
|
|
// um unterschiedliche Literaltypen unterscheiden zu koennen
|
|
|
if (value != null) {
|
|
if (value != null) {
|
|
|
-
|
|
|
|
|
- if ("true".equals(value)) return new Constant(Boolean.TRUE);
|
|
|
|
|
-
|
|
|
|
|
- if ("false".equals(value)) return new Constant(Boolean.FALSE);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if ("true".equals(value))
|
|
|
|
|
+ return new Constant(Boolean.TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ if ("false".equals(value))
|
|
|
|
|
+ return new Constant(Boolean.FALSE);
|
|
|
|
|
|
|
|
try { // flaot
|
|
try { // flaot
|
|
|
if (value.contains("."))
|
|
if (value.contains("."))
|
|
|
return new Constant(Float.parseFloat(value));
|
|
return new Constant(Float.parseFloat(value));
|
|
|
- } catch (NumberFormatException e1) { /* need to be quite */ }
|
|
|
|
|
|
|
+ } catch (NumberFormatException e1) { /* need to be quite */
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
try { // hex int
|
|
try { // hex int
|
|
|
if (value.startsWith("0x"))
|
|
if (value.startsWith("0x"))
|
|
|
- return new Constant(new Integer(Integer.parseInt(value.substring(2), 16)));
|
|
|
|
|
- } catch (NumberFormatException e1) { /* need to be quite */ }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return new Constant(new Integer(Integer.parseInt(
|
|
|
|
|
+ value.substring(2), 16)));
|
|
|
|
|
+ } catch (NumberFormatException e1) { /* need to be quite */
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try { // int
|
|
try { // int
|
|
|
return new Constant(new Integer(Integer.parseInt(value)));
|
|
return new Constant(new Integer(Integer.parseInt(value)));
|
|
|
- } catch (NumberFormatException e1) { /* need to be quite */ }
|
|
|
|
|
-
|
|
|
|
|
- if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith("\"") && value.endsWith("\"")) )
|
|
|
|
|
- return new Constant(value.substring(1, value.length()-1));
|
|
|
|
|
|
|
+ } catch (NumberFormatException e1) { /* need to be quite */
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ((value.startsWith("'") && value.endsWith("'"))
|
|
|
|
|
+ || (value.startsWith("\"") && value.endsWith("\"")))
|
|
|
|
|
+ return new Constant(value.substring(1, value.length() - 1));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return new Constant(value);
|
|
return new Constant(value);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@FunctionMethod("build")
|
|
@FunctionMethod("build")
|
|
|
- public Expression buildVariableReference(EObject obj) {
|
|
|
|
|
-
|
|
|
|
|
- EObject var = getToOne(obj, "variable");
|
|
|
|
|
|
|
+ public RTExpression buildVariableReference(EObject obj) {
|
|
|
|
|
+
|
|
|
|
|
+ EObject var = getToOne(obj, "variable");
|
|
|
return new VariableRef(getString(var, "identifier"));
|
|
return new VariableRef(getString(var, "identifier"));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Internal build method that performs the dynamic dispatch to the appropriate (correctly named)
|
|
|
|
|
- * builder function. The parameter is always a EObject and since we have use dynamic EMF we match by
|
|
|
|
|
- * naming conventions.
|
|
|
|
|
|
|
+ * Internal build method that performs the dynamic dispatch to the
|
|
|
|
|
+ * appropriate (correctly named) builder function. The parameter is always a
|
|
|
|
|
+ * EObject and since we have use dynamic EMF we match by naming conventions.
|
|
|
*
|
|
*
|
|
|
* @param obj
|
|
* @param obj
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
protected Object build(EObject obj) {
|
|
protected Object build(EObject obj) {
|
|
|
- if ( obj == null ) return null;
|
|
|
|
|
-
|
|
|
|
|
- Object[] params = new Object[]{obj};
|
|
|
|
|
-
|
|
|
|
|
- Function f = ExpressionBuilder.lookup(this.getClass(), "build" + obj.eClass().getName(), paramTypes);
|
|
|
|
|
- if (f != null)
|
|
|
|
|
|
|
+ if (obj == null)
|
|
|
|
|
+ return null;
|
|
|
|
|
+
|
|
|
|
|
+ Object[] params = new Object[] { obj };
|
|
|
|
|
+
|
|
|
|
|
+ Function f = ExpressionBuilder.lookup(this.getClass(), "build"
|
|
|
|
|
+ + obj.eClass().getName(), paramTypes);
|
|
|
|
|
+ if (f != null)
|
|
|
return f.execute(params);
|
|
return f.execute(params);
|
|
|
-
|
|
|
|
|
- throw new BuilderException("No builder function for: " + obj.eClass().getName());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ throw new BuilderException("No builder function for: "
|
|
|
|
|
+ + obj.eClass().getName());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- protected Expression buildRefExpression(EObject obj, String refName) {
|
|
|
|
|
- return (Expression) build(getToOne(obj, refName));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ protected RTExpression buildRefExpression(EObject obj, String refName) {
|
|
|
|
|
+ return (RTExpression) build(getToOne(obj, refName));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
protected EObject getToOne(EObject obj, String name) {
|
|
protected EObject getToOne(EObject obj, String name) {
|
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
|
- if ( feature instanceof EReference ) {
|
|
|
|
|
|
|
+ if (feature instanceof EReference) {
|
|
|
EReference ref = (EReference) feature;
|
|
EReference ref = (EReference) feature;
|
|
|
return (EObject) obj.eGet(ref);
|
|
return (EObject) obj.eGet(ref);
|
|
|
}
|
|
}
|
|
|
throw new BuilderException();
|
|
throw new BuilderException();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
protected String getString(EObject obj, String name) {
|
|
protected String getString(EObject obj, String name) {
|
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
|
- if ( feature instanceof EAttribute ) {
|
|
|
|
|
|
|
+ if (feature instanceof EAttribute) {
|
|
|
EAttribute attr = (EAttribute) feature;
|
|
EAttribute attr = (EAttribute) feature;
|
|
|
return (String) obj.eGet(attr);
|
|
return (String) obj.eGet(attr);
|
|
|
}
|
|
}
|
|
|
throw new BuilderException();
|
|
throw new BuilderException();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
protected Integer getInteger(EObject obj, String name) {
|
|
protected Integer getInteger(EObject obj, String name) {
|
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
|
- if ( feature instanceof EAttribute ) {
|
|
|
|
|
|
|
+ if (feature instanceof EAttribute) {
|
|
|
EAttribute attr = (EAttribute) feature;
|
|
EAttribute attr = (EAttribute) feature;
|
|
|
return (Integer) obj.eGet(attr);
|
|
return (Integer) obj.eGet(attr);
|
|
|
}
|
|
}
|
|
|
throw new BuilderException();
|
|
throw new BuilderException();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
protected String getLiteral(EObject obj, String name) {
|
|
protected String getLiteral(EObject obj, String name) {
|
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
EStructuralFeature feature = obj.eClass().getEStructuralFeature(name);
|
|
|
- if ( feature instanceof EAttribute ) {
|
|
|
|
|
|
|
+ if (feature instanceof EAttribute) {
|
|
|
EAttribute attr = (EAttribute) feature;
|
|
EAttribute attr = (EAttribute) feature;
|
|
|
String literalValue = ((Enumerator) obj.eGet(attr)).getName();
|
|
String literalValue = ((Enumerator) obj.eGet(attr)).getName();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return ("NULL".equals(literalValue)) ? null : literalValue;
|
|
return ("NULL".equals(literalValue)) ? null : literalValue;
|
|
|
}
|
|
}
|
|
|
throw new BuilderException();
|
|
throw new BuilderException();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|