Skip to content

Commit

Permalink
Merge pull request #426 from INTO-CPS-Association/kel/fmi3-clocks
Browse files Browse the repository at this point in the history
Kel/fmi3 clocks
  • Loading branch information
lausdahl authored Oct 21, 2024
2 parents 37e0287 + 11f0c7e commit 3248f16
Show file tree
Hide file tree
Showing 23 changed files with 706 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ public static ARealLiteralExp newARealLiteralExp(Double value) {
return exp;
}

public static AFloatLiteralExp newAFloatLiteralExp(Float value) {
AFloatLiteralExp exp = new AFloatLiteralExp();
exp.setValue(value);
return exp;
}
public static AIntLiteralExp newAIntLiteralExp(Integer value) {
AIntLiteralExp exp = new AIntLiteralExp();
exp.setValue(value);
Expand Down Expand Up @@ -416,6 +421,10 @@ public static ARealNumericPrimitiveType newARealNumericPrimitiveType() {
ARealNumericPrimitiveType type = new ARealNumericPrimitiveType();
return type;
}
public static AFloatNumericPrimitiveType newAFloatNumericPrimitiveType() {
AFloatNumericPrimitiveType type = new AFloatNumericPrimitiveType();
return type;
}

public static ARealNumericPrimitiveType newRealType() {

Expand Down
3 changes: 3 additions & 0 deletions ast/src/main/resources/mabl.astv2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Tokens
java_Boolean = 'java:java.lang.Boolean';
java_Integer = 'java:java.lang.Integer';
java_Double = 'java:java.lang.Double';
java_Float = 'java:java.lang.Float';
java_Long = 'java:java.lang.Long';
lex_identifier='java:org.intocps.maestro.ast.LexIdentifier';

Expand Down Expand Up @@ -92,6 +93,8 @@ exp
| {int} [value]:java_Integer
| {uInt} [value]:java_Long
| {real} [value]:java_Double
| {long} [value]:java_Long
| {float} [value]:java_Float
;

#binary {-> package='org.intocps.maestro.ast'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ class Fmi3ModelDescription : ModelDescription {
?: typeDefinition?.canBeDeactivated){true->true;false,null->false},
node.attributes.getNamedItem("priority")?.nodeValue?.toUInt() ?: typeDefinition?.priority,
if (interval == null) typeDefinition!!.interval else valueOf(interval),
node.attributes.getNamedItem("intervalDecimal")?.nodeValue?.toFloat()
node.attributes.getNamedItem("intervalDecimal")?.nodeValue?.toDouble()
?: typeDefinition?.intervalDecimal,
node.attributes.getNamedItem("shiftDecimal")?.nodeValue?.toFloat() ?: typeDefinition?.shiftDecimal
?: (0).toFloat(),
node.attributes.getNamedItem("shiftDecimal")?.nodeValue?.toDouble() ?: typeDefinition?.shiftDecimal
?: (0).toDouble(),
node.attributes.getNamedItem("supportsFraction")?.nodeValue?.toBoolean()
?: typeDefinition?.supportsFraction ?: false,
node.attributes.getNamedItem("resolution")?.nodeValue?.toULong() ?: typeDefinition?.resolution,
Expand Down Expand Up @@ -665,8 +665,8 @@ class Fmi3ModelDescription : ModelDescription {
node.attributes.getNamedItem("canBeDeactivated")?.nodeValue?.toBoolean(),
node.attributes.getNamedItem("priority")?.nodeValue?.toUInt(),
valueOf(node.attributes.getNamedItem("interval")!!.nodeValue),
node.attributes.getNamedItem("intervalDecimal")?.nodeValue?.toFloat(),
node.attributes.getNamedItem("shiftDecimal")?.nodeValue?.toFloat(),
node.attributes.getNamedItem("intervalDecimal")?.nodeValue?.toDouble(),
node.attributes.getNamedItem("shiftDecimal")?.nodeValue?.toDouble(),
node.attributes.getNamedItem("supportsFraction")?.nodeValue?.toBoolean(),
node.attributes.getNamedItem("resolution")?.nodeValue?.toULong(),
node.attributes.getNamedItem("intervalCounter")?.nodeValue?.toULong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ data class ClockTypeDefinition(
val canBeDeactivated: Boolean? = false,
val priority: UInt?,
val interval: Fmi3ClockInterval,
val intervalDecimal: Float?,
val shiftDecimal: Float? = (0).toFloat(),
val intervalDecimal: Double?,
val shiftDecimal: Double? = (0).toDouble(),
val supportsFraction: Boolean? = false,
val resolution: ULong?,
val intervalCounter: ULong?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ class ClockVariable(
val canBeDeactivated: Boolean? = false,
val priority: UInt? = null,
val interval: Fmi3ClockInterval,
val intervalDecimal: Float? = null,
val shiftDecimal: Float? = (0).toFloat(),
val intervalDecimal: Double? = null,
val shiftDecimal: Double? = (0).toDouble(),
val supportsFraction: Boolean? = false,
val resolution: ULong? = null,
val intervalCounter: ULong? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ interface Scope<AST> extends Scoping<AST> {
* @return
*/
DoubleVariable<AST> store(double value);

FloatVariable<AST> store(float value);
StringVariable<AST> store(String value);

BoolVariable<AST> store(boolean value);

IntVariable<AST> store(int value);
UIntVariable<AST> storeUInt(long value);

/**
* Store a given value with a prefix name
Expand All @@ -248,16 +249,19 @@ interface Scope<AST> extends Scoping<AST> {
* @return
*/
DoubleVariable<AST> store(String name, double value);
FloatVariable<AST> store(String name, float value);

StringVariable<AST> store(String name, String value);

BoolVariable<AST> store(String name, boolean value);

IntVariable<AST> store(String name, int value);
UIntVariable<AST> storeUInt(String name, long value);

<CV> ArrayVariable<AST, CV> store(String name, CV[] value);

<V > ArrayVariable<AST,V> createArray(String name,Class<? extends V> type, IntVariable<AST>...sizes ) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
<V > ArrayVariable<AST,V> createArray(String name,Class<? extends V> type, UIntVariable<AST>...sizes ) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;

/**
* Store the given value and get a tag for it. Copy
Expand Down Expand Up @@ -477,6 +481,10 @@ interface DoubleVariable<AST> extends Variable<AST, DoubleExpressionValue>, Prov

void set(Double value);
}
interface FloatVariable<AST> extends Variable<AST, FloatExpressionValue>, ProvidesTypedReferenceExp, NumericTypedReferenceExp {

void set(Float value);
}

interface BoolVariable<AST> extends Variable<AST, BooleanExpressionValue>, ProvidesTypedReferenceExp {
Predicate toPredicate();
Expand Down Expand Up @@ -882,10 +890,15 @@ interface BooleanExpressionValue extends FmiBuilder.ExpressionValue {

interface DoubleExpressionValue extends NumericExpressionValue {
}
interface FloatExpressionValue extends NumericExpressionValue {
}

interface IntExpressionValue extends NumericExpressionValue {
}

interface LongExpressionValue extends NumericExpressionValue {
}

interface UIntExpressionValue extends IntExpressionValue {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public DoubleVariableFmi2Api store(double value) {
return activeScope.store(value);
}

@Override
public FloatVariableFmi2Api store(float value) {
return activeScope.store(value);
}

@Override
public StringVariableFmi2Api store(String value) {
return activeScope.store(value);
Expand All @@ -147,12 +152,24 @@ public IntVariableFmi2Api store(int value) {

}

@Override
public UIntVariableFmi2Api storeUInt(long value) {
return activeScope.storeUInt(value);

}


@Override
public DoubleVariableFmi2Api store(String name, double value) {
return activeScope.store(name, value);

}

@Override
public FloatVariableFmi2Api store(String name, float value) {
return activeScope.store(name,value);
}

@Override
public StringVariableFmi2Api store(String name, String value) {
return activeScope.store(name, value);
Expand All @@ -169,6 +186,13 @@ public IntVariableFmi2Api store(String name, int value) {
return activeScope.store(name, value);
}

@Override
public UIntVariableFmi2Api storeUInt(String name, long value) {
return activeScope.storeUInt(name, value);
}



/* @Override
public <ValType, Val extends Fmi2Builder.Value<ValType>, Var extends Fmi2Builder.Variable<PStm, Val>> Var store(String name, Var value) {
return activeScope.store(name, value);
Expand All @@ -192,6 +216,12 @@ public <V> ArrayVariableFmi2Api<V> createArray(String name, Class<? extends V> t
return activeScope.createArray(name,type,sizes);
}

@Override
public <V> ArrayVariableFmi2Api<V> createArray(String name, Class<? extends V> type,
FmiBuilder.UIntVariable<PStm>... sizes) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
return activeScope.createArray(name,type,sizes);
}

@Override
public <V> FmiBuilder.Variable<PStm, V> store(FmiBuilder.Value<V> tag) {
return activeScope.store(tag);
Expand All @@ -207,6 +237,11 @@ public DoubleVariableFmi2Api store(String namePrefix, DoubleVariableFmi2Api vari
return activeScope.store(namePrefix, variable);
}

@Override
public FloatVariableFmi2Api store(String namePrefix, FloatVariableFmi2Api variable) {
return activeScope.store(namePrefix,variable);
}

@Override
public ArrayVariableFmi2Api storeInArray(String name, VariableFmi2Api[] variables) {
return activeScope.storeInArray(name, variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,33 @@ public interface IMablScope extends FmiBuilder.Scope<PStm> {

@Override
DoubleVariableFmi2Api store(double value);
@Override
FloatVariableFmi2Api store(float value);

@Override
IntVariableFmi2Api store(int value);

@Override
UIntVariableFmi2Api storeUInt(long value);

@Override
StringVariableFmi2Api store(String value);

@Override
DoubleVariableFmi2Api store(String name, double value);

@Override
FloatVariableFmi2Api store(String name, float value);

@Override
BooleanVariableFmi2Api store(String name, boolean value);

@Override
IntVariableFmi2Api store(String name, int value);

@Override
UIntVariableFmi2Api storeUInt(String name, long value);

@Override
StringVariableFmi2Api store(String name, String value);

Expand All @@ -88,6 +99,7 @@ public interface IMablScope extends FmiBuilder.Scope<PStm> {

@Override
<V > ArrayVariableFmi2Api<V> createArray(String name,Class<? extends V> type, FmiBuilder.IntVariable<PStm>... sizes ) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
<V > ArrayVariableFmi2Api<V> createArray(String name,Class<? extends V> type, FmiBuilder.UIntVariable<PStm>... sizes ) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;

@Override
<V> FmiBuilder.Variable<PStm, V> store(FmiBuilder.Value<V> tag);
Expand All @@ -96,6 +108,7 @@ public interface IMablScope extends FmiBuilder.Scope<PStm> {

DoubleVariableFmi2Api store(String namePrefix, DoubleVariableFmi2Api variable);

FloatVariableFmi2Api store(String namePrefix, FloatVariableFmi2Api variable);
ArrayVariableFmi2Api storeInArray(String name, VariableFmi2Api[] variables);


Expand Down
Loading

0 comments on commit 3248f16

Please sign in to comment.