Skip to content

Commit

Permalink
improved atl-ocl support (close #172)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacedo committed Apr 23, 2014
1 parent 9492912 commit 336f945
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ INode translate(OperationCallExp expr) throws EchoError {
res = ((IFormula) src).not();
else if (expr.getReferredOperation().getName().equals("isEmpty"))
res = ((IExpression) src).no();
else if (expr.getReferredOperation().getName().equals("notEmpty"))
res = ((IExpression) src).some();
else if (expr.getReferredOperation().getName().equals("size")) {
EchoReporter.getInstance().warning(
"Integer operators (size) require suitable bitwidths.",
Expand Down Expand Up @@ -423,6 +425,10 @@ else if (expr.getReferredOperation().getName().equals("-"))
.getArgument().get(0)));
else if (expr.getReferredOperation().getName().equals("allInstances"))
res = src;
else if (expr.getReferredOperation().getName().equals("oclIsKindOf"))
res = ((IExpression) src).in(translateExpression(expr.getArgument().get(0)));
else if (expr.getReferredOperation().getName().equals("oclAsType"))
res = ((IExpression) src);
else if (expr.getReferredOperation().getName().equals("oclIsNew")) {
EObject container = expr.eContainer();
while (!(container instanceof IteratorExp) && container != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pt.uminho.haslab.echo.EchoError;
import pt.uminho.haslab.echo.EchoOptionsSetup;
import pt.uminho.haslab.echo.EchoReporter;
import pt.uminho.haslab.echo.EchoTypeError;
import pt.uminho.haslab.echo.ErrorTransform;
import pt.uminho.haslab.echo.ErrorUnsupported;
import pt.uminho.haslab.echo.engine.EchoHelper;
Expand Down Expand Up @@ -53,13 +54,31 @@ public INode translateAtlOcl(EObject expr) throws EchoError {
return translateAtlOclBooleanLit(expr);
} else if (expr.eClass().getName().equals("Binding")) {
return translateAtlOclBinding(expr);
} else if (expr.eClass().getName().equals("IfExp")) {
return translateAtlOclIf(expr);
} else if (expr.eClass().getName().equals("IteratorExp")) {
return translateAtlOclIterator(expr);
} else
throw new ErrorUnsupported("OCL expression not supported: " + expr
+ ".");
}

private INode translateAtlOclIf(EObject expr) throws EchoError {
EStructuralFeature x = expr.eClass().getEStructuralFeature("condition");
IFormula eif = (IFormula) translateAtlOcl((EObject) expr.eGet(x));
x = expr.eClass().getEStructuralFeature("thenExpression");
INode thenExpr = translateAtlOcl((EObject) expr.eGet(x));
x = expr.eClass().getEStructuralFeature("elseExpression");
INode elseExpr = translateAtlOcl((EObject) expr.eGet(x));

if (thenExpr instanceof IExpression && elseExpr instanceof IExpression)
return eif.thenElse((IExpression) thenExpr,(IExpression) elseExpr);
else if (thenExpr instanceof IFormula && elseExpr instanceof IFormula)
return (IFormula) eif.thenElse((IFormula) thenExpr,(IFormula) elseExpr);

throw new EchoTypeError("Expression: "+expr.getClass());
}

IExpression translateAtlOclVariable(EObject expr) {
EStructuralFeature x = expr.eClass().getEStructuralFeature(
"referredVariable");
Expand Down Expand Up @@ -184,6 +203,8 @@ INode translateAtlOclOperationCall(EObject expr) throws EchoError {
res = ((IFormula) src).not();
else if (operatorname.equals("isEmpty"))
res = ((IExpression) src).no();
else if (operatorname.equals("notEmpty"))
res = ((IExpression) src).some();
else if (operatorname.equals("size"))
res = ((IExpression) src).cardinality();
else if (operatorname.equals("=")) {
Expand Down Expand Up @@ -232,22 +253,45 @@ else if (operatorname.equals(">="))
else if (operatorname.equals("union"))
res = ((IExpression) src)
.union((IExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("including"))
res = ((IExpression) src)
.union((IExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("excluding"))
res = ((IExpression) src)
.difference((IExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("intersection"))
res = ((IExpression) src)
.intersection((IExpression) translateAtlOcl(argumentso
.get(0)));
else if (operatorname.equals("includes"))
res = ((IExpression) translateAtlOcl(argumentso.get(0)))
.in((IExpression) src);
else if (operatorname.equals("includesAll"))
res = ((IExpression) translateAtlOcl(argumentso.get(0)))
.in((IExpression) src);
else if (operatorname.equals("excludes"))
res = ((IExpression) translateAtlOcl(argumentso.get(0)))
.in((IExpression) src).not();
else if (operatorname.equals("excludesAll"))
res = ((IExpression) translateAtlOcl(argumentso.get(0)))
.in((IExpression) src).not();
else if (operatorname.equals("oclAsSet")
|| operatorname.equals("asSet"))
res = src;
else if (operatorname.equals("oclIsKindOf"))
res = ((IExpression) src).in((IExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("oclAsType"))
res = ((IExpression) src);
else if (operatorname.equals("+"))
res = ((IIntExpression) src)
.plus((IIntExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("-"))
res = ((IIntExpression) src)
.minus((IIntExpression) translateAtlOcl(argumentso.get(0)));
else if (operatorname.equals("-")) {
INode x = translateAtlOcl(argumentso.get(0));
if (src instanceof IIntExpression && x instanceof IIntExpression)
res = ((IIntExpression) src).minus((IIntExpression) x);
else
res = ((IIntExpression) src).difference((IIntExpression) x);
}
else if (operatorname.equals("allInstances"))
res = src;
else if (((EATLTransformation) context.getCallerRel().transformation.transformation).getRelation(operatorname) != null) {
Expand Down

0 comments on commit 336f945

Please sign in to comment.