|
|
@@ -510,8 +510,76 @@ Element function rhs_rewrite(final_matches : Element,plabel_to_rhsnode:Element,
|
|
|
log("unsupported metatype in rhs")
|
|
|
return 0
|
|
|
|
|
|
-Element function tf_executeRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
- //TODO support for multiple ruleTypes
|
|
|
+Element function tf_executeFRule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
+
|
|
|
+ //find LHS
|
|
|
+ //TODO if no lhs (is this allowed to happen?) // or empty lhs
|
|
|
+ Element tf_er_lhs
|
|
|
+ tf_er_lhs = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "lhs"))
|
|
|
+ tf_er_lhs = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_lhs)), tf_er_model, pivots)
|
|
|
+ Integer nr_of_lhs_matches
|
|
|
+ nr_of_lhs_matches = list_len(tf_er_lhs)
|
|
|
+
|
|
|
+ //find NACs if at least one lhs is found (otherwise not needed)
|
|
|
+ Integer nr_of_nac_matches
|
|
|
+ nr_of_nac_matches = 0
|
|
|
+ Element tf_er_nac
|
|
|
+ tf_er_nac = create_node()
|
|
|
+ if(nr_of_lhs_matches > 0):
|
|
|
+ Element tf_er_nac_
|
|
|
+ tf_er_nac_ = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, dict_read(dict_read(dict_read(tf_er_transformation, "metamodel"), "model"), "nac"))
|
|
|
+ Element partial_nac_matches
|
|
|
+ while (read_nr_out(tf_er_nac_) > 0):
|
|
|
+ partial_nac_matches = tf_matchAll(tf_er_transformation, read_edge_dst(set_pop(tf_er_nac_)), tf_er_model, pivots)
|
|
|
+ while (read_nr_out(partial_nac_matches)>0):
|
|
|
+ list_append(tf_er_nac, set_pop(partial_nac_matches))
|
|
|
+ nr_of_nac_matches = list_len(tf_er_nac)
|
|
|
+
|
|
|
+ //remove from lhs matches that share a node with a nac match
|
|
|
+ //TODO if nac is not related to match (no plabels match)
|
|
|
+ Element final_matches
|
|
|
+ final_matches = mergeLHSNAC(tf_er_lhs, tf_er_nac)
|
|
|
+
|
|
|
+ //extract pivots from the matches
|
|
|
+ extractPivots(final_matches, pivots, tf_er_transformation, tf_er_model)
|
|
|
+
|
|
|
+ //rhs part
|
|
|
+
|
|
|
+ //create plabel_to_rhsnode
|
|
|
+ Element RHS
|
|
|
+ RHS = allOutgoingAssociationInstances(tf_er_transformation, tf_er_rule, tf_er_transformation["metamodel"]["model"]["rhs"])
|
|
|
+ if(read_nr_out(RHS) > 0):
|
|
|
+ RHS = read_edge_dst(set_pop(RHS))
|
|
|
+ Element metamodelTransf //transformation metamodel
|
|
|
+ metamodelTransf = tf_er_transformation["metamodel"]["model"]
|
|
|
+ Element post2ram // type of the post2ram edge
|
|
|
+ post2ram = dict_read(metamodelTransf, "post2ram")
|
|
|
+ post2ram = allOutgoingAssociationInstances(tf_er_transformation, RHS, post2ram)
|
|
|
+ Element plabel_to_rhsnode //dict in the form plabel->node
|
|
|
+ plabel_to_rhsnode = create_node()
|
|
|
+ Element rhs_node
|
|
|
+ Integer rhs_plabel
|
|
|
+ while (integer_lt(0, list_len(post2ram))):
|
|
|
+ rhs_node = read_edge_dst(set_pop(post2ram))
|
|
|
+ rhs_plabel = read_attribute(tf_er_transformation, getName(tf_er_transformation, rhs_node), "plabel")
|
|
|
+ dict_add(plabel_to_rhsnode,rhs_plabel, rhs_node)
|
|
|
+
|
|
|
+ rhs_rewrite(final_matches ,plabel_to_rhsnode, tf_er_transformation, tf_er_model )
|
|
|
+
|
|
|
+ return pivots
|
|
|
+
|
|
|
+Integer function modulo(a:Integer,b:Integer):
|
|
|
+ return a - integer_division(a,b)*b
|
|
|
+
|
|
|
+Integer RandomNumberState
|
|
|
+Integer function getRandomNumber(min:Integer, max:Integer):
|
|
|
+ if( bool_not(is_physical_int(RandomNumberState))):
|
|
|
+ RandomNumberState = 4 // xkcd.com/221/
|
|
|
+ RandomNumberState = modulo((8121*RandomNumberState) + 28411, 134456)
|
|
|
+ return modulo(RandomNumberState , (max-min)+1)+min
|
|
|
+
|
|
|
+
|
|
|
+Element function tf_executeARule(tf_er_transformation: Element,tf_er_rule: Element, tf_er_model: Element, pivots : Element):
|
|
|
|
|
|
//find LHS
|
|
|
//TODO if no lhs (is this allowed to happen?) // or empty lhs
|
|
|
@@ -585,13 +653,13 @@ Element function executeRuleBlock(transformation_model : Element,hostmodel:Eleme
|
|
|
log("running arule")
|
|
|
Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
|
|
|
log(getName(transformation_model, Rule))
|
|
|
- pivots = tf_executeRule(transformation_model, Rule, hostmodel, pivots)
|
|
|
+ pivots = tf_executeARule(transformation_model, Rule, hostmodel, pivots)
|
|
|
succes = True
|
|
|
elif (typename == "FRule"):
|
|
|
log("running frule")
|
|
|
Rule = read_edge_dst(set_pop(allOutgoingAssociationInstances(transformation_model, ruleblock, transformation_model["metamodel"]["model"]["getrule"])))
|
|
|
log(getName(transformation_model, Rule))
|
|
|
- pivots = tf_executeRule(transformation_model, Rule, hostmodel, pivots)
|
|
|
+ pivots = tf_executeFRule(transformation_model, Rule, hostmodel, pivots)
|
|
|
succes = True
|
|
|
else:
|
|
|
log("RuleType is not supported yet")
|