aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend')
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend38
1 files changed, 38 insertions, 0 deletions
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
index 1b68fed2..9e11d2cf 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/ExpressionEvaluation2Logic.xtend
@@ -1,6 +1,7 @@
1package hu.bme.mit.inf.dslreasoner.viatra2logic 1package hu.bme.mit.inf.dslreasoner.viatra2logic
2 2
3import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder 3import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder
4import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.IfThenElse
4import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term 5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term
5import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable 6import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable
6import java.util.Map 7import java.util.Map
@@ -8,9 +9,11 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable
8import org.eclipse.xtext.xbase.XBinaryOperation 9import org.eclipse.xtext.xbase.XBinaryOperation
9import org.eclipse.xtext.xbase.XExpression 10import org.eclipse.xtext.xbase.XExpression
10import org.eclipse.xtext.xbase.XFeatureCall 11import org.eclipse.xtext.xbase.XFeatureCall
12import org.eclipse.xtext.xbase.XIfExpression
11import org.eclipse.xtext.xbase.XMemberFeatureCall 13import org.eclipse.xtext.xbase.XMemberFeatureCall
12import org.eclipse.xtext.xbase.XNumberLiteral 14import org.eclipse.xtext.xbase.XNumberLiteral
13import org.eclipse.xtext.xbase.XUnaryOperation 15import org.eclipse.xtext.xbase.XUnaryOperation
16import org.eclipse.xtext.xbase.XBlockExpression
14 17
15class ExpressionEvaluation2Logic { 18class ExpressionEvaluation2Logic {
16 val extension LogicProblemBuilder builder = new LogicProblemBuilder 19 val extension LogicProblemBuilder builder = new LogicProblemBuilder
@@ -139,6 +142,41 @@ class ExpressionEvaluation2Logic {
139 throw new UnsupportedOperationException('''Unsupported numeric type: "«s»"''') 142 throw new UnsupportedOperationException('''Unsupported numeric type: "«s»"''')
140 } 143 }
141 144
145 def protected dispatch Term transform(XIfExpression i, Map<PVariable, Variable> variable2Variable) {
146
147 val cond_op = i.^if.transform(variable2Variable)
148 val then_op = i.then.transform(variable2Variable)
149 val else_op = i.^else.transform(variable2Variable)
150
151 if (cond_op === null) {
152 println("-> " + i.^if)
153 println("-> " + i.then)
154 println("-> " + i.^else)
155 throw new UnsupportedOperationException('''Your ITE statement has a null condition.''')
156 }
157 if (then_op === null) {
158 println("-> " + i.^if)
159 println("-> " + i.then)
160 println("-> " + i.^else)
161 throw new UnsupportedOperationException('''Your ITE statement has a null "then" statement"".''')
162 }
163 return ITE(cond_op, then_op, else_op)
164 }
165
166 def protected dispatch Term transform(XBlockExpression b, Map<PVariable, Variable> variable2Variable) {
167 val exprs = newArrayList
168 for(e:b.expressions){ exprs.add(transform(e, variable2Variable)) }
169
170 if (exprs.size > 1)
171 throw new UnsupportedOperationException('''blocks with more than 1 statement are not currently supportes: "«exprs»"''')
172 if (exprs.isEmpty)
173 throw new UnsupportedOperationException('''blocks is empty: "«exprs»"''')
174
175 return exprs.get(0)
176 }
177
178
179
142 def protected dispatch Term transform(XExpression e, Map<PVariable, Variable> variable2Variable) { 180 def protected dispatch Term transform(XExpression e, Map<PVariable, Variable> variable2Variable) {
143 throw new UnsupportedOperationException('''Unsupported expression: "«e.class.simpleName»" - «e»''') 181 throw new UnsupportedOperationException('''Unsupported expression: "«e.class.simpleName»" - «e»''')
144 } 182 }