-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/values/LongExpressionValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.intocps.maestro.framework.fmi2.api.mabl.values; | ||
|
||
import org.intocps.maestro.ast.node.AIntNumericPrimitiveType; | ||
import org.intocps.maestro.ast.node.ALongNumericPrimitiveType; | ||
import org.intocps.maestro.ast.node.PExp; | ||
import org.intocps.maestro.ast.node.PType; | ||
import org.intocps.maestro.framework.fmi2.api.FmiBuilder; | ||
import org.intocps.maestro.framework.fmi2.api.mabl.NumericExpressionValueFmi2Api; | ||
|
||
import static org.intocps.maestro.ast.MableAstFactory.*; | ||
|
||
|
||
public class LongExpressionValue extends NumericExpressionValueFmi2Api implements FmiBuilder.LongExpressionValue { | ||
|
||
final PType type = new ALongNumericPrimitiveType(); | ||
final PExp exp; | ||
|
||
public LongExpressionValue(PExp exp) { | ||
this.exp = exp; | ||
} | ||
|
||
public LongExpressionValue(long value) { | ||
this.exp = newALongLiteralExp(value); | ||
} | ||
|
||
public static LongExpressionValue of(int i) { | ||
return new LongExpressionValue(newAIntLiteralExp(i)); | ||
} | ||
|
||
@Override | ||
public PExp getExp() { | ||
return this.exp.clone(); | ||
} | ||
|
||
@Override | ||
public PType getType() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public LongExpressionValue subtraction(int v) { | ||
return new LongExpressionValue(newMinusExp(getExp(), newAIntLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public LongExpressionValue addition(int v) { | ||
return new LongExpressionValue(newPlusExp(getExp(), newAIntLiteralExp(v))); | ||
} | ||
|
||
// TODO: This one is tricky. And int divided by and int, should that be a double or an int? It depends on the target variable. | ||
// Not considered for now. | ||
@Override | ||
public DoubleExpressionValue divide(int v) { | ||
return new DoubleExpressionValue(newDivideExp(getExp(), newAIntLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public LongExpressionValue multiply(int v) { | ||
return new LongExpressionValue(newMultiplyExp(getExp(), newAIntLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public DoubleExpressionValue subtraction(double v) { | ||
return new DoubleExpressionValue(newMinusExp(getExp(), newARealLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public DoubleExpressionValue addition(double v) { | ||
return new DoubleExpressionValue(newPlusExp(getExp(), newARealLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public DoubleExpressionValue divide(double v) { | ||
return new DoubleExpressionValue(newDivideExp(getExp(), newARealLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public DoubleExpressionValue multiply(double v) { | ||
return new DoubleExpressionValue(newMultiplyExp(getExp(), newARealLiteralExp(v))); | ||
} | ||
|
||
@Override | ||
public NumericExpressionValueFmi2Api addition(FmiBuilder.NumericTypedReferenceExp v) { | ||
if (v instanceof DoubleExpressionValue) { | ||
return new DoubleExpressionValue(newPlusExp(this.getExp(), v.getExp())); | ||
} else if (v instanceof LongExpressionValue) { | ||
return new LongExpressionValue(newPlusExp(this.getExp(), v.getExp())); | ||
} else { | ||
throw new RuntimeException(v + " is not of type NumericExpressionValue."); | ||
} | ||
} | ||
|
||
@Override | ||
public NumericExpressionValueFmi2Api divide(FmiBuilder.NumericTypedReferenceExp v) { | ||
if (v instanceof DoubleExpressionValue || v instanceof LongExpressionValue) { | ||
return new DoubleExpressionValue(newDivideExp(this.getExp(), v.getExp())); | ||
} else { | ||
throw new RuntimeException(v + " is not of type IntExpressionValue nor DoubleExpressionValue."); | ||
} | ||
} | ||
|
||
@Override | ||
public NumericExpressionValueFmi2Api subtraction(FmiBuilder.NumericTypedReferenceExp v) { | ||
if (v instanceof DoubleExpressionValue) { | ||
return new DoubleExpressionValue(newMinusExp(this.getExp(), v.getExp())); | ||
} else if (v instanceof LongExpressionValue) { | ||
return new LongExpressionValue(newMinusExp(this.getExp(), v.getExp())); | ||
} else { | ||
throw new RuntimeException(v + " is not of type IntExpressionValue nor DoubleExpressionValue."); | ||
} | ||
} | ||
|
||
@Override | ||
public NumericExpressionValueFmi2Api multiply(FmiBuilder.NumericTypedReferenceExp v) { | ||
if (v instanceof DoubleExpressionValue) { | ||
return new DoubleExpressionValue(newMultiplyExp(this.getExp(), v.getExp())); | ||
} else if (v instanceof LongExpressionValue) { | ||
return new LongExpressionValue(newMultiplyExp(this.getExp(), v.getExp())); | ||
} else { | ||
throw new RuntimeException(v + " is not of type IntExpressionValue nor DoubleExpressionValue."); | ||
|
||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/LongVariableFmi2Api.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.intocps.maestro.framework.fmi2.api.mabl.variables; | ||
|
||
import org.intocps.maestro.ast.node.*; | ||
import org.intocps.maestro.framework.fmi2.api.FmiBuilder; | ||
import org.intocps.maestro.framework.fmi2.api.mabl.scoping.IMablScope; | ||
import org.intocps.maestro.framework.fmi2.api.mabl.values.LongExpressionValue; | ||
|
||
import static org.intocps.maestro.ast.MableAstFactory.*; | ||
|
||
public class LongVariableFmi2Api extends VariableFmi2Api<FmiBuilder.LongExpressionValue> implements FmiBuilder.LongVariable<PStm> { | ||
public LongVariableFmi2Api(PStm declaration, IMablScope declaredScope, FmiBuilder.DynamicActiveScope<PStm> dynamicScope, | ||
PStateDesignator designator, PExp referenceExp) { | ||
super(declaration, newALongNumericPrimitiveType(), declaredScope, dynamicScope, designator, referenceExp); | ||
} | ||
|
||
|
||
@Override | ||
public void decrement() { | ||
this.decrement(dynamicScope); | ||
} | ||
|
||
public void decrement(FmiBuilder.Scope<PStm> scope) { | ||
scope.add(newAAssignmentStm(this.getDesignator(), newMinusExp(this.getReferenceExp(), newAIntLiteralExp(1)))); | ||
} | ||
|
||
@Override | ||
public void increment() { | ||
this.increment(dynamicScope); | ||
} | ||
|
||
@Override | ||
public LongExpressionValue toMath() { | ||
return new LongExpressionValue(this.getReferenceExp().clone()); | ||
} | ||
|
||
@Override | ||
public void setValue(FmiBuilder.LongExpressionValue addition) { | ||
declaredScope.add(newAAssignmentStm(this.getDesignator(), addition.getExp())); | ||
} | ||
|
||
public void increment(FmiBuilder.Scope<PStm> scope) { | ||
scope.add(newAAssignmentStm(this.getDesignator(), newPlusExp(this.getReferenceExp(), newAIntLiteralExp(1)))); | ||
} | ||
|
||
@Override | ||
public PType getType() { | ||
return new AIntNumericPrimitiveType(); | ||
} | ||
|
||
@Override | ||
public PExp getExp() { | ||
return this.getReferenceExp(); | ||
} | ||
|
||
@Override | ||
public LongVariableFmi2Api clone(PStm declaration, IMablScope declaredScope, PStateDesignator designator, PExp referenceExp) { | ||
return new LongVariableFmi2Api(declaration, declaredScope, dynamicScope, designator, referenceExp); | ||
} | ||
} |