Skip to content

Commit

Permalink
atl (unique) lazy calls
Browse files Browse the repository at this point in the history
close #177 #173
  • Loading branch information
nmacedo committed Mar 21, 2014
1 parent 3cc0b53 commit 85e0e53
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
xsi:schemaLocation="NHSM /pt.uminho.haslab.echo.examples/metamodels/hsm2nhsm/NHSM.ecore"
name="machine">
<states name="X"/>
<states name="Y"/>
</nhsm:StateMachine>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.qvtd.pivot.qvtrelation.RelationCallExp;
import org.eclipse.qvtd.pivot.qvttemplate.ObjectTemplateExp;
import org.eclipse.qvtd.pivot.qvttemplate.PropertyTemplateItem;

import pt.uminho.haslab.echo.*;
import pt.uminho.haslab.echo.engine.ast.*;
import pt.uminho.haslab.mde.MDEManager;
Expand Down Expand Up @@ -456,13 +457,13 @@ IFormula translateFormula(RelationCallExp expr) throws EchoError {
}

// tries to call referred relation
IFormula res = ((ITContext) context).getCallerRel().transformation
IFormula res = (IFormula) ((ITContext) context).getCallerRel().transformation
.callRelation(rel,((ITContext) context),params);

// if it doesn't exist, process it
if (res == null) {
((ITContext) context).getCallerRel().newRelation(rel);
res = ((ITContext) context).getCallerRel().transformation
res = (IFormula) ((ITContext) context).getCallerRel().transformation
.callRelation(rel, ((ITContext) context), params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected AlloyExpression addNonTopRel(List<? extends EModelDomain> eModelDomain
}

@Override
public void newRelation(EQVTRelation rel) throws EchoError {
public void newRelation(ERelation rel) throws EchoError {
new EAlloyRelation(this, rel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pt.uminho.haslab.echo.engine.ast.IDecl;
import pt.uminho.haslab.echo.engine.ast.IExpression;
import pt.uminho.haslab.echo.engine.ast.IFormula;
import pt.uminho.haslab.echo.engine.ast.INode;
import pt.uminho.haslab.mde.transformation.EDependency;
import pt.uminho.haslab.mde.transformation.EModelDomain;
import pt.uminho.haslab.mde.transformation.EModelParameter;
Expand Down Expand Up @@ -234,7 +235,7 @@ protected void addTopRelationConstraint(EEngineRelation relation)

/** {@inheritDoc} */
@Override
public AlloyFormula callRelation(ERelation n, ITContext context,
public INode callRelation(ERelation n, ITContext context,
List<IExpression> params) {
if (subRelationFields == null) return null;

Expand All @@ -251,15 +252,19 @@ public AlloyFormula callRelation(ERelation n, ITContext context,
Expr exp = f.call(vars);

IExpression expp = new AlloyExpression(exp);

INode form = null;
// applies the relation parameters to the relation function
IExpression insig = params.get(params.size() - 1);
params.remove(insig);
for (IExpression param : params)
expp = param.join(expp);
IFormula form = insig.in(expp);

return (AlloyFormula) form;
if (params.size() == 1) {
form = params.get(0).join(expp);
}
else {
IExpression insig = params.get(params.size() - 1);
params.remove(insig);
for (IExpression param : params)
expp = param.join(expp);
form = insig.in(expp);
}
return form;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.ocl.examples.pivot.OCLExpression;

import pt.uminho.haslab.echo.EchoError;
import pt.uminho.haslab.echo.EchoOptionsSetup;
import pt.uminho.haslab.echo.EchoReporter;
import pt.uminho.haslab.echo.ErrorParser;
Expand All @@ -23,7 +25,11 @@
import pt.uminho.haslab.echo.engine.ast.INode;
import pt.uminho.haslab.mde.MDEManager;
import pt.uminho.haslab.mde.model.EMetamodel;
import pt.uminho.haslab.mde.transformation.atl.EATLRelation;
import pt.uminho.haslab.mde.transformation.atl.EATLTransformation;
import pt.uminho.haslab.mde.transformation.qvt.EQVTRelation;

import java.util.ArrayList;
import java.util.List;

public class OCL2Alloy2 {
Expand All @@ -34,8 +40,7 @@ public OCL2Alloy2(ITContext context) {
this.context = context;
}

public INode oclExprToAlloy(EObject expr) throws ErrorTransform,
ErrorAlloy, ErrorUnsupported, ErrorParser {
public INode oclExprToAlloy(EObject expr) throws EchoError {
if (expr.eClass().getName().equals("OperatorCallExp") ||
expr.eClass().getName().equals("OperationCallExp") ||
expr.eClass().getName().equals("CollectionOperationCallExp")) {
Expand Down Expand Up @@ -74,8 +79,7 @@ IFormula oclExprToAlloyBooleanLit(EObject expr) {
return Constants.FALSE();
}

INode oclExprToAlloyAttribute(EObject expr) throws ErrorTransform, ErrorAlloy,
ErrorUnsupported, ErrorParser {
INode oclExprToAlloyAttribute(EObject expr) throws EchoError {
INode res = null;
EStructuralFeature source = expr.eClass().getEStructuralFeature(
"source");
Expand Down Expand Up @@ -108,8 +112,7 @@ INode oclExprToAlloyAttribute(EObject expr) throws ErrorTransform, ErrorAlloy,
return res;
}

INode oclExprToAlloyBinding(EObject expr) throws ErrorTransform, ErrorAlloy,
ErrorUnsupported, ErrorParser {
INode oclExprToAlloyBinding(EObject expr) throws EchoError {
INode res = null;

EStructuralFeature value = expr.eClass().getEStructuralFeature("value");
Expand All @@ -133,7 +136,7 @@ INode oclExprToAlloyBinding(EObject expr) throws ErrorTransform, ErrorAlloy,
"propertyName");
IExpression aux = propertyToField((String) expr.eGet(oname), var);

if (valmodel != null && !varmodel.equals(valmodel)) {
if (valmodel != null && !varmodel.equals(valmodel) && val instanceof IExpression) {
EchoReporter.getInstance().debug(" *** Call implicit trace! "+context.getCallerRel().transformation.callAllRelation(context, (IExpression) val));
val = context.getCallerRel().transformation.callAllRelation(context, (IExpression) val);
}
Expand All @@ -158,8 +161,7 @@ INode oclExprToAlloyBinding(EObject expr) throws ErrorTransform, ErrorAlloy,
return res;
}

INode oclExprToAlloyOperationCall(EObject expr) throws ErrorTransform, ErrorAlloy,
ErrorUnsupported, ErrorParser {
INode oclExprToAlloyOperationCall(EObject expr) throws EchoError {
INode res = null;
EStructuralFeature source = expr.eClass().getEStructuralFeature(
"source");
Expand Down Expand Up @@ -236,6 +238,29 @@ else if (operatorname.equals("-"))
.minus((IIntExpression) oclExprToAlloy(argumentso.get(0)));
else if (operatorname.equals("allInstances"))
res = src;
else if (((EATLTransformation) context.getCallerRel().transformation.transformation).getRelation(operatorname) != null) {
EATLRelation rel = ((EATLTransformation) context.getCallerRel().transformation.transformation).getRelation(operatorname);

// translates variable parameters
List<IExpression> params = new ArrayList<IExpression>();
for (EObject arg : argumentso) {
IExpression param = (IExpression) oclExprToAlloy(arg);
params.add(param);
}

// tries to call referred relation
res = ((ITContext) context).getCallerRel().transformation
.callRelation(rel,((ITContext) context),params);

// if it doesn't exist, process it
if (res == null) {
((ITContext) context).getCallerRel().newRelation(rel);
res = ((ITContext) context).getCallerRel().transformation
.callRelation(rel, ((ITContext) context), params);
}
context.setCurrentModel(null);
EchoReporter.getInstance().debug("Call rule result: "+res);
}
else
throw new ErrorUnsupported("OCL operation not supported: "
+ expr.toString() + ".");
Expand Down Expand Up @@ -281,8 +306,7 @@ IExpression propertyToField(String propn, IExpression var)
return exp;
}

public IFormula translateExpressions(List<EObject> lex) throws ErrorAlloy,
ErrorTransform, ErrorUnsupported, ErrorParser {
public IFormula translateExpressions(List<EObject> lex) throws EchoError {
IFormula expr = Constants.TRUE();
for (Object ex : lex) {
expr = expr.and((IFormula) oclExprToAlloy((EObject) ex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pt.uminho.haslab.mde.transformation.EDependency;
import pt.uminho.haslab.mde.transformation.EModelDomain;
import pt.uminho.haslab.mde.transformation.ERelation;
import pt.uminho.haslab.mde.transformation.qvt.EQVTRelation;

import java.util.*;

Expand Down Expand Up @@ -262,7 +261,7 @@ private IFormula calculateConstraint() throws EchoError {
List<IExpression> params = new ArrayList<>();
for (IDecl d : rootVar2engineDecl.values())
params.add(d.variable());
targetFormula = targetFormula.and(transformation.callRelation(relation, context, params));
targetFormula = targetFormula.and((IFormula) transformation.callRelation(relation, context, params));
}

if (targetVar2engineDecl.size() == 1)
Expand Down Expand Up @@ -415,7 +414,7 @@ private IExpression addRelationField() throws EchoError {
*/
abstract protected IFormula simplify(IFormula formula) throws ErrorUnsupported;

public abstract void newRelation(EQVTRelation rel) throws EchoError;
public abstract void newRelation(ERelation rel) throws EchoError;

public enum Mode {
TOP_QUANTIFIER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected abstract void addTopRelationConstraint(EEngineRelation rel)
* @return the expression resulting from calling
* <code>rel</rel> over <code>params</code>
*/
public abstract IFormula callRelation(ERelation rel, ITContext context,
public abstract INode callRelation(ERelation rel, ITContext context,
List<IExpression> params);

public abstract IExpression callAllRelation(ITContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected KodkodExpression addNonTopRel(List<? extends EModelDomain> eModelDomai

/** {@inheritDoc} */
@Override
public void newRelation(EQVTRelation rel) throws EchoError {
public void newRelation(ERelation rel) throws EchoError {
new EKodkodRelation(this, rel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public static Map<EVariable,String> variablesOCLExpression (final EObject exp, f
if (exp.eClass().getName().equals("VariableExp")) {
final EStructuralFeature var = exp.eClass().getEStructuralFeature("referredVariable");
final EObject x = (EObject) exp.eGet(var);
if (vars.get(x) == null)
vars.put(EVariable.getVariable(x),null);
if (!x.eGet(x.eClass().getEStructuralFeature("varName")).equals("thisModule"))
if (vars.get(x) == null)
vars.put(EVariable.getVariable(x),null);
}/*
else if (exp instanceof ObjectTemplateExp) {
VariableDeclaration x = ((ObjectTemplateExp) exp).getBindsTo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class EATLTransformation extends ETransformation {

private Map<String,EATLModelParameter> modelParams;
private List<EATLRelation> relations;
private HashMap<String,EATLRelation> relations;
private EObject transformation;

public static Map<String,String> metamodeluris = new HashMap<>();
Expand All @@ -49,7 +49,7 @@ protected void process(EObject module) throws ErrorUnsupported, ErrorParser {
this.transformation = module;

if (modelParams == null) modelParams = new HashMap<>();
if (relations == null) relations = new ArrayList<>();
if (relations == null) relations = new HashMap<>();

if (!module.eClass().getName().equals("Module")) throw new ErrorParser("Bad atl");

Expand All @@ -71,7 +71,7 @@ protected void process(EObject module) throws ErrorUnsupported, ErrorParser {
EStructuralFeature outmdls = module.eClass().getEStructuralFeature("outModels");
EList<EObject> objs = (EList<EObject>) module.eGet(elements);
for (EObject x : objs)
relations.add(new EATLRelation(this,x));
relations.put((String) x.eGet(x.eClass().getEStructuralFeature("name")),new EATLRelation(this,x));
objs = (EList<EObject>) module.eGet(inmdls);
for (EObject x : objs)
modelParams.put((String) x.eGet(x.eClass().getEStructuralFeature("name")), new EATLModelParameter(x,this));
Expand All @@ -88,7 +88,11 @@ public List<EATLModelParameter> getModelParams() {

@Override
public List<EATLRelation> getRelations() {
return relations;
return new ArrayList<EATLRelation>(relations.values());
}

public EATLRelation getRelation(String name) {
return relations.get(name);
}

@Override
Expand Down

0 comments on commit 85e0e53

Please sign in to comment.