diff options
author | Ed Willink | 2015-03-08 12:32:46 +0000 |
---|---|---|
committer | Ed Willink | 2015-03-16 13:47:52 +0000 |
commit | ca0cbbff3da9073d8b5fd7dfecf71d1f8437e3a8 (patch) | |
tree | 6ec21d78193bd0f4fffa266df2753b76ea2504f1 | |
parent | 59f1ba692d33e28174ed53409a844d5d93306fba (diff) | |
download | org.eclipse.qvtd-ewillink/PartialEvaluator.tar.gz org.eclipse.qvtd-ewillink/PartialEvaluator.tar.xz org.eclipse.qvtd-ewillink/PartialEvaluator.zip |
[wip] PartialEvaluatorewillink/PartialEvaluator
-rw-r--r-- | plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ecore | 68 | ||||
-rw-r--r-- | plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ocl | 80 |
2 files changed, 148 insertions, 0 deletions
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ecore b/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ecore new file mode 100644 index 000000000..f1d1ea166 --- /dev/null +++ b/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ecore @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="partialevaluator" nsURI="http://www.eclipse.org/qvt/2015/PartialEvaluator"
+ nsPrefix="pe">
+ <eAnnotations source="http://www.eclipse.org/OCL/Import">
+ <details key="pivot" value="http://www.eclipse.org/ocl/2015/Library"/>
+ <details key="values" value="http://www.eclipse.org/ocl/2015/Values"/>
+ </eAnnotations>
+ <eClassifiers xsi:type="ecore:EClass" name="ClassInstance" eSuperTypes="#//ObjectInstance"/>
+ <eClassifiers xsi:type="ecore:EClass" name="CompleteResult" eSuperTypes="#//Result">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="object2" lowerBound="1"
+ eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Evaluator">
+ <eOperations name="getVariable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value">
+ <eParameters name="variable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//VariableDeclaration"/>
+ </eOperations>
+ <eOperations name="navigateProperty" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value">
+ <eParameters name="source" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//ObjectValue"/>
+ <eParameters name="property" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//Property"/>
+ </eOperations>
+ <eOperations name="setVariable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value">
+ <eParameters name="variable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//Variable"/>
+ <eParameters name="value" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ </eOperations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Instance" abstract="true"/>
+ <eClassifiers xsi:type="ecore:EClass" name="ObjectInstance" abstract="true" eSuperTypes="#//Instance">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="object" lowerBound="1"
+ eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//ObjectValue"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="PartialEvaluator" eSuperTypes="#//Evaluator">
+ <eOperations name="evaluate" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value">
+ <eParameters name="expression" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//OCLExpression"/>
+ </eOperations>
+ <eOperations name="getUnresolved" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ <eOperations name="getVariable" lowerBound="1" eType="#//PartialResult">
+ <eParameters name="variable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//VariableDeclaration"/>
+ </eOperations>
+ <eOperations name="isUnresolved" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean">
+ <eParameters name="values" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ </eOperations>
+ <eOperations name="makeObjectInstance" lowerBound="1" eType="#//ObjectInstance">
+ <eParameters name="value" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ </eOperations>
+ <eOperations name="makePropertyInstance" lowerBound="1" eType="#//PropertyInstance">
+ <eParameters name="object" lowerBound="1" eType="#//ObjectInstance"/>
+ <eParameters name="property" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//Property"/>
+ </eOperations>
+ <eOperations name="setVariable" lowerBound="1" eType="#//PartialResult">
+ <eParameters name="variable" lowerBound="1" eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//Variable"/>
+ <eParameters name="result" lowerBound="1" eType="#//PartialResult"/>
+ </eOperations>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="PartialResult" eSuperTypes="#//Result">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="result" lowerBound="1"
+ eType="ecore:EClass http://www.eclipse.org/ocl/2015/Values#//Value"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="dependencies" ordered="false"
+ upperBound="-1" eType="#//Instance"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="PropertyInstance" eSuperTypes="#//Instance">
+ <eStructuralFeatures xsi:type="ecore:EReference" name="object" lowerBound="1"
+ eType="#//ObjectInstance"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="property" lowerBound="1"
+ eType="ecore:EClass http://www.eclipse.org/ocl/2015/Pivot#//Property"/>
+ </eClassifiers>
+ <eClassifiers xsi:type="ecore:EClass" name="Result" abstract="true"/>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ocl b/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ocl new file mode 100644 index 000000000..7ad69db08 --- /dev/null +++ b/plugins/org.eclipse.qvtd.pivot.qvtimperative/model/PartialEvaluator.ocl @@ -0,0 +1,80 @@ +import pe : 'PartialEvaluator.ecore#/' +import pivot : 'http://www.eclipse.org/ocl/2015/Pivot' +import v : 'http://www.eclipse.org/ocl/2015/Values' + +package ocl + +context BooleanLiteralExp +def: eval(evaluator : pe::Evaluator) : v::Value = self.booleanSymbol + +context IfExp +def: eval(evaluator : pe::Evaluator) : v::Value = + let condition : Boolean = self.ownedCondition.eval(evaluator) in + if condition.oclIsUndefined() then condition + else if condition then self.ownedThen.eval(evaluator) + else self.ownedElse.eval(evaluator) + endif + endif +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = + let conditionResult : pe::PartialResult = evaluator.evaluate(self.ownedCondition) in + let condition : v::Value = conditionResult.result in + if evaluator.isUnresolved(condition) or condition.oclIsUndefined() then conditionResult + else + let ifResult : pe::PartialResult = evaluator.evaluate(if condition then self.ownedThen else self.ownedElse endif) in + pe::PartialResult { + result = ifResult.result, + dependencies = conditionResult.dependencies->union(ifResult.dependencies) + } + endif + +context IntegerLiteralExp +def: eval(evaluator : pe::Evaluator) : v::Value = self.integerSymbol + +context LetExp +def: eval(evaluator : pe::Evaluator) : v::Value = + let value : v::Value = self.ownedIn.eval(evaluator) in + evaluator.setVariable(self.ownedVariable, value) +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = + let inResult : pe::PartialResult = evaluator.evaluate(self.ownedIn) in + evaluator.setVariable(self.ownedVariable, inResult) + +context LiteralExp +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = + pe::PartialResult { + result = eval(evaluator), + dependencies = Set{} + } + +context OCLExpression +def: eval(evaluator : pe::Evaluator) : v::Value = invalid +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = invalid + +context PropertyCallExp +def: eval(evaluator : pe::Evaluator) : v::Value = + evaluator.navigateProperty(self.ownedSource.eval(evaluator).oclAsType(v::ObjectValue), self.referredProperty) +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = + let sourceResult : pe::PartialResult = evaluator.evaluate(self.ownedSource) in + let sourceInstance : pe::ObjectInstance = evaluator.makeObjectInstance(sourceResult.result) in + let propertyInstance : pe::PropertyInstance = evaluator.makePropertyInstance(sourceInstance, self.referredProperty) in + let sourceDependencies : pe::PropertyInstance = sourceResult.dependencies in + pe::PartialResult { + result = if propertyInstance <> null then sourceResult.result else evaluator.getUnresolved() endif, + dependencies = if propertyInstance <> null then sourceDependencies->including(propertyInstance) else sourceDependencies endif + } + +context RealLiteralExp +def: eval(evaluator : pe::Evaluator) : v::Value = self.realSymbol + +context StringLiteralExp +def: eval(evaluator : pe::Evaluator) : v::Value = self.stringSymbol + +context UnlimitedNaturalLiteralExp +def: eval(evaluator : pe::Evaluator) : v::Value = self.unlimitedNaturalSymbol + +context VariableExp +def: eval(evaluator : pe::Evaluator) : v::Value = + evaluator.getVariable(self.referredVariable) +def: partialEval(evaluator : pe::PartialEvaluator) : pe::PartialResult = + evaluator.getVariable(self.referredVariable) + +endpackage |