Closed benedekh closed 3 years ago
Please find an example model attached. Please note that it is the original Gamma statechart without any transformations: example.txt
The state machine has an integer variable called data
with an initial value 0. Besides, the SM has two states: Start
and Finish
, connected by a Transition that has several effects.
In the entry actions of the state machine, there are several references for this data
variable (see screenshot), which are all correctly transformed by the above mentioned ExpressionTransformer.
As mentioned before, the Transition has several actions as effect. The frist 4 actions all have a reference for the aforementioned data
variable. Although the first 3 of them are transformed without any problems, the bug that is reported in this issue arises as soon as we try to transform the leftOperand
of the not equals expressions (see exclamation mark in the screenshot).
To give some more context:
@Varadbal please let me know, if you need any further information.
Hacky workaround in hu.bme.mit.gamma.statechart.lowlevel.transformation.Trace:
def isMapped(VariableDeclaration gammaVariable) {
checkNotNull(gammaVariable)
varDeclMappings.containsKey(gammaVariable) || varDeclMappings.containsValue(gammaVariable) // insert the second OR clause
}
def get(VariableDeclaration gammaVariable) {
checkNotNull(gammaVariable)
var candidate = varDeclMappings.get(gammaVariable)
candidate === null && isMapped(gammaVariable) ? gammaVariable: candidate // insert this line
}
@Varadbal could you please comment something about this issue? The issue is present, the hacky workaround clearly does not solve the issue and can cause further complications...
f061f4c5c00312cbf3e302a42d2a96e2f0dce710 should fix this issue.
The
hu.bme.mit.gamma.statechart.lowlevel.transformation.ExpressionTransformer.transformExpression(DirectReferenceExpression expression)
method works strange. First it transforms the VariableDeclaration (VD) to a new one (using thehu.bme.mit.gamma.statechart.lowlevel.transformation.Trace
class), but later on it tries to transform the resulting VD again, instead of the original VD. It results in a faulty behavior, because the Trace does not include the resulting VD in its internal caches, due to the fact that it should NOT be transformed again.It looks as if the resulting VD would override the original VD in the model somehow. Therefore when the
transformExpression(DirectReferenceExpression expression)
method is called again, then it is called with the resulting VD instead of the original one. See screenshot 1 below.The faulty code snippet can be seen on Screenshot 2 below. In the first invocation, the upper
if
block is executed (if (
trace.isMapped...), which gets the resulting VD from the trace correctly. However, when the method is called again, then the
else` branch of this if statement is executed, because the resulting VD is NOT in the Trace (as it was the result, but not an origin of a preceding transformation).As a quick-fix I changed the
isMapped(VariableDeclaration)
andget(VariableDeclaration)
methods of the Trace class so that, if the resulting VD is its parameter, then it returns itself, if it is in the VD cache as value (since it is on the "right hand side" of the transformation, which means it had been created because of a transformation). However, this is a dirty fix and the real cause of the original problem must be discovered and fixed instead./cc @grbeni