Skip to content

Commit

Permalink
rename Fmi2Builder to FmiBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Oct 5, 2023
1 parent 4bbe9b5 commit c85f4ee
Show file tree
Hide file tree
Showing 66 changed files with 610 additions and 633 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;

@SuppressWarnings("unused")
public interface Fmi2Builder<S, B, E, SETTINGS> {
public interface FmiBuilder<S, B, E, SETTINGS> {
B build() throws Exception;

SETTINGS getSettings();
Expand Down Expand Up @@ -63,7 +63,7 @@ public interface Fmi2Builder<S, B, E, SETTINGS> {
<V, T> Variable<T, V> getFmuVariableFrom(E exp);


interface RuntimeModule<S> extends Fmi2Builder.Variable<S, NamedVariable<S>> {
interface RuntimeModule<S> extends FmiBuilder.Variable<S, NamedVariable<S>> {
void initialize(List<RuntimeFunction> declaredFuncs);

void initialize(RuntimeFunction... declaredFuncs);
Expand All @@ -90,15 +90,15 @@ interface IFunctionBuilder {

IFunctionBuilder setReturnType(String name);

IFunctionBuilder setReturnType(Fmi2Builder.RuntimeFunction.FunctionType.Type type);
IFunctionBuilder setReturnType(FmiBuilder.RuntimeFunction.FunctionType.Type type);

IFunctionBuilder addArgument(String name, Fmi2Builder.RuntimeFunction.FunctionType.Type type);
IFunctionBuilder addArgument(String name, FmiBuilder.RuntimeFunction.FunctionType.Type type);

IFunctionBuilder useVargs();

IFunctionBuilder addArgument(String name, String type);

Fmi2Builder.RuntimeFunction build();
FmiBuilder.RuntimeFunction build();
}

interface RuntimeFunction {
Expand Down Expand Up @@ -522,7 +522,7 @@ interface Fmu2Variable<S, PS> extends Variable<S, NamedVariable<S>> {
// }
Fmi2ComponentVariable<S, PS> instantiate(String namePrefix, TryScope<PStm> enclosingTryScope, Scope<PStm> scope, String environmentName);

Fmi2ComponentVariable<S, PS> instantiate(String namePrefix, Fmi2Builder.TryScope<PStm> enclosingTryScope, Fmi2Builder.Scope<PStm> scope,
Fmi2ComponentVariable<S, PS> instantiate(String namePrefix, FmiBuilder.TryScope<PStm> enclosingTryScope, FmiBuilder.Scope<PStm> scope,
String environmentName, boolean loggingOn);

Fmi2ComponentVariable<S, PS> instantiate(String name, TryScope<S> enclosingTryScope, Scope<S> scope);
Expand Down Expand Up @@ -839,7 +839,7 @@ interface Variable<T, V> {
Scope<T> getDeclaredScope();
}

interface ArrayVariable<T, CV> extends Variable<T, Fmi2Builder.NamedVariable<T>> {
interface ArrayVariable<T, CV> extends Variable<T, FmiBuilder.NamedVariable<T>> {
int size();

List<? extends Variable<T, CV>> items();
Expand All @@ -850,7 +850,7 @@ interface ArrayVariable<T, CV> extends Variable<T, Fmi2Builder.NamedVariable<T>>
interface ExpressionValue extends ProvidesTypedReferenceExp {
}

interface BooleanExpressionValue extends Fmi2Builder.ExpressionValue {
interface BooleanExpressionValue extends FmiBuilder.ExpressionValue {
}

interface DoubleExpressionValue extends NumericExpressionValue {
Expand All @@ -859,7 +859,7 @@ interface DoubleExpressionValue extends NumericExpressionValue {
interface IntExpressionValue extends NumericExpressionValue {
}

interface StringExpressionValue extends Fmi2Builder.ExpressionValue {
interface StringExpressionValue extends FmiBuilder.ExpressionValue {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.intocps.maestro.ast.node.PStm;
import org.intocps.maestro.core.messages.ErrorReporter;
import org.intocps.maestro.core.messages.IErrorReporter;
import org.intocps.maestro.framework.fmi2.api.Fmi2Builder;
import org.intocps.maestro.framework.fmi2.api.FmiBuilder;
import org.intocps.maestro.interpreter.DefaultExternalValueFactory;
import org.intocps.maestro.interpreter.MableInterpreter;
import org.intocps.maestro.interpreter.api.IValueLifecycleHandler;
Expand Down Expand Up @@ -99,45 +99,43 @@ public void check(String spec,

assertTrue(res, "Type check errors:" + out);

new MableInterpreter(
new DefaultExternalValueFactory(new File("target"),typeChecker::findModule,
new ByteArrayInputStream(runtimedata.getBytes(StandardCharsets.UTF_8)))).execute(
doc);
new MableInterpreter(new DefaultExternalValueFactory(new File("target"), typeChecker::findModule,
new ByteArrayInputStream(runtimedata.getBytes(StandardCharsets.UTF_8)))).execute(doc);
}

public static class MDebugAssert {
private final Fmi2Builder builder;
private final Fmi2Builder.RuntimeModule<PStm> mdebugAssert;
private final FmiBuilder builder;
private final FmiBuilder.RuntimeModule<PStm> mdebugAssert;

public MDebugAssert(Fmi2Builder builder, Fmi2Builder.RuntimeModule<PStm> mdebugAssert) {
public MDebugAssert(FmiBuilder builder, FmiBuilder.RuntimeModule<PStm> mdebugAssert) {
this.builder = builder;
this.mdebugAssert = mdebugAssert;
}

public static MDebugAssert create(Fmi2Builder builder) {
Fmi2Builder.RuntimeModule<PStm> mdebugAssert = builder.loadRuntimeModule(MDebugAssert.class.getSimpleName());
public static MDebugAssert create(FmiBuilder builder) {
FmiBuilder.RuntimeModule<PStm> mdebugAssert = builder.loadRuntimeModule(MDebugAssert.class.getSimpleName());
return new MDebugAssert(builder, mdebugAssert);

}

public void assertEquals(Fmi2Builder.Variable a, Fmi2Builder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).setName("assertEquals").build(), a, b);
public void assertEquals(FmiBuilder.Variable a, FmiBuilder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", FmiBuilder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).setName("assertEquals").build(), a, b);
}

public void assertEquals(Object a, Fmi2Builder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).setName("assertEquals").build(), a, b);
public void assertEquals(Object a, FmiBuilder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", FmiBuilder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).setName("assertEquals").build(), a, b);
}

public void assertNotEquals(Fmi2Builder.Variable a, Fmi2Builder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).setName("assertNotEquals").build(), a, b);
public void assertNotEquals(FmiBuilder.Variable a, FmiBuilder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", FmiBuilder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).setName("assertNotEquals").build(), a, b);
}

public void assertNotEquals(Object a, Fmi2Builder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).setName("assertNotEquals").build(), a, b);
public void assertNotEquals(Object a, FmiBuilder.Variable b) {
this.mdebugAssert.callVoid(builder.getFunctionBuilder().addArgument("a", FmiBuilder.RuntimeFunction.FunctionType.Type.Any)
.addArgument("b", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).setName("assertNotEquals").build(), a, b);
}

@IValueLifecycleHandler.ValueLifecycle(name = "MDebugAssert")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Factory {

public Fmi2Builder get(Types type) {
public FmiBuilder get(Types type) {
switch (type) {
case Mabl:
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.intocps.maestro.framework.fmi2.api.mabl;

import org.intocps.maestro.ast.node.PStm;
import org.intocps.maestro.framework.fmi2.api.Fmi2Builder;
import org.intocps.maestro.framework.fmi2.api.FmiBuilder;
import org.intocps.maestro.framework.fmi2.api.mabl.scoping.DynamicActiveBuilderScope;
import org.intocps.maestro.framework.fmi2.api.mabl.variables.BooleanVariableFmi2Api;

Expand All @@ -17,11 +17,11 @@ public class BooleanBuilderFmi2Api {
private final DynamicActiveBuilderScope dynamicScope;
private final MablApiBuilder builder;
private String moduleIdentifier;
private Fmi2Builder.RuntimeModule<PStm> runtimeModule;
private FmiBuilder.RuntimeModule<PStm> runtimeModule;
private boolean runtimeModuleMode = false;


public BooleanBuilderFmi2Api(MablApiBuilder mablApiBuilder, Fmi2Builder.RuntimeModule<PStm> runtimeModule) {
public BooleanBuilderFmi2Api(MablApiBuilder mablApiBuilder, FmiBuilder.RuntimeModule<PStm> runtimeModule) {
this(mablApiBuilder.getDynamicScope(), mablApiBuilder);
this.runtimeModuleMode = true;
this.runtimeModule = runtimeModule;
Expand All @@ -36,15 +36,15 @@ public BooleanBuilderFmi2Api(DynamicActiveBuilderScope dynamicScope, MablApiBuil

}

public BooleanVariableFmi2Api allTrue(String variablePrefix, List<? extends Fmi2Builder.ProvidesTypedReferenceExp> parameters) {
public BooleanVariableFmi2Api allTrue(String variablePrefix, List<? extends FmiBuilder.ProvidesTypedReferenceExp> parameters) {
return allTrueFalse(variablePrefix, parameters, ALL_TRUE_FUNCTION_NAME);
}

public BooleanVariableFmi2Api allFalse(String variablePrefix, List<? extends Fmi2Builder.ProvidesTypedReferenceExp> parameters) {
public BooleanVariableFmi2Api allFalse(String variablePrefix, List<? extends FmiBuilder.ProvidesTypedReferenceExp> parameters) {
return allTrueFalse(variablePrefix, parameters, ALL_FALSE_FUNCTION_NAME);
}

private BooleanVariableFmi2Api allTrueFalse(String variablePrefix, List<? extends Fmi2Builder.ProvidesTypedReferenceExp> parameters,
private BooleanVariableFmi2Api allTrueFalse(String variablePrefix, List<? extends FmiBuilder.ProvidesTypedReferenceExp> parameters,
String function) {
String variableName = dynamicScope.getName(variablePrefix);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.intocps.maestro.ast.node.PStateDesignator;
import org.intocps.maestro.ast.node.PStm;
import org.intocps.maestro.ast.node.PType;
import org.intocps.maestro.framework.fmi2.api.Fmi2Builder;
import org.intocps.maestro.framework.fmi2.api.FmiBuilder;
import org.intocps.maestro.framework.fmi2.api.mabl.variables.ComponentVariableFmi2Api;
import org.intocps.maestro.framework.fmi2.api.mabl.variables.FmuVariableFmi2Api;
import org.intocps.maestro.framework.fmi2.api.mabl.variables.VariableFmi2Api;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static List<PStm> createTypeConvertingAssignment(PStateDesignator designa
return statements;
}

public static List<PStm> createTypeConvertingAssignment(MablApiBuilder builder, Fmi2Builder.Scope<PStm> scope, PStateDesignator designator,
public static List<PStm> createTypeConvertingAssignment(MablApiBuilder builder, FmiBuilder.Scope<PStm> scope, PStateDesignator designator,
PExp value, PType valueType, PType targetType) {

return createTypeConvertingAssignment(designator, value, valueType, targetType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.intocps.maestro.framework.fmi2.api.mabl;

import org.intocps.maestro.ast.node.PStm;
import org.intocps.maestro.framework.fmi2.api.Fmi2Builder;
import org.intocps.maestro.framework.fmi2.api.FmiBuilder;

public class ConsolePrinter {
private final Fmi2Builder.RuntimeModule<PStm> module;
private final Fmi2Builder.RuntimeFunction printFunc;
private final Fmi2Builder.RuntimeFunction printlnFunc;
private final FmiBuilder.RuntimeModule<PStm> module;
private final FmiBuilder.RuntimeFunction printFunc;
private final FmiBuilder.RuntimeFunction printlnFunc;

public ConsolePrinter(MablApiBuilder builder, Fmi2Builder.RuntimeModule<PStm> module) {
public ConsolePrinter(MablApiBuilder builder, FmiBuilder.RuntimeModule<PStm> module) {
this.module = module;

printFunc = builder.getFunctionBuilder().setName("print").addArgument("format", Fmi2Builder.RuntimeFunction.FunctionType.Type.String)
.addArgument("args", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).useVargs()
.setReturnType(Fmi2Builder.RuntimeFunction.FunctionType.Type.Void).build();
printFunc = builder.getFunctionBuilder().setName("print").addArgument("format", FmiBuilder.RuntimeFunction.FunctionType.Type.String)
.addArgument("args", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).useVargs()
.setReturnType(FmiBuilder.RuntimeFunction.FunctionType.Type.Void).build();

printlnFunc = builder.getFunctionBuilder().setName("println").addArgument("format", Fmi2Builder.RuntimeFunction.FunctionType.Type.String)
.addArgument("args", Fmi2Builder.RuntimeFunction.FunctionType.Type.Any).useVargs()
.setReturnType(Fmi2Builder.RuntimeFunction.FunctionType.Type.Void).build();
printlnFunc = builder.getFunctionBuilder().setName("println").addArgument("format", FmiBuilder.RuntimeFunction.FunctionType.Type.String)
.addArgument("args", FmiBuilder.RuntimeFunction.FunctionType.Type.Any).useVargs()
.setReturnType(FmiBuilder.RuntimeFunction.FunctionType.Type.Void).build();

module.initialize(printFunc, printlnFunc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.intocps.maestro.ast.AVariableDeclaration;
import org.intocps.maestro.ast.MableAstFactory;
import org.intocps.maestro.ast.node.*;
import org.intocps.maestro.framework.fmi2.api.Fmi2Builder;
import org.intocps.maestro.framework.fmi2.api.FmiBuilder;
import org.intocps.maestro.framework.fmi2.api.mabl.scoping.DynamicActiveBuilderScope;
import org.intocps.maestro.framework.fmi2.api.mabl.variables.DoubleVariableFmi2Api;

Expand All @@ -20,7 +20,7 @@ public class DataWriter {
private final MablApiBuilder mablApiBuilder;
private final String FUNCTION_CLOSE = "close";
private String moduleIdentifier;
private Fmi2Builder.RuntimeModule<PStm> runtimeModule;
private FmiBuilder.RuntimeModule<PStm> runtimeModule;
private boolean runtimeModuleMode = false;


Expand All @@ -31,7 +31,7 @@ public DataWriter(DynamicActiveBuilderScope dynamicScope, MablApiBuilder mablApi
this.moduleIdentifier = "dataWriter";
}

public DataWriter(MablApiBuilder mablApiBuilder, Fmi2Builder.RuntimeModule<PStm> runtimeModule) {
public DataWriter(MablApiBuilder mablApiBuilder, FmiBuilder.RuntimeModule<PStm> runtimeModule) {
this(mablApiBuilder.getDynamicScope(), mablApiBuilder);
this.runtimeModuleMode = true;
this.runtimeModule = runtimeModule;
Expand Down Expand Up @@ -86,7 +86,7 @@ public class DataWriterInstance {
* The name of the variable with the data writer instance configuration
*/
private String dataWriterInstanceConfigurationVariableName;
private Fmi2Builder.RuntimeModule<PStm> runtimeModule;
private FmiBuilder.RuntimeModule<PStm> runtimeModule;

public DataWriterInstance(DynamicActiveBuilderScope dynamicScope, MablApiBuilder mablApiBuilder, DataWriter dataWriter) {

Expand All @@ -96,7 +96,7 @@ public DataWriterInstance(DynamicActiveBuilderScope dynamicScope, MablApiBuilder
}

public DataWriterInstance(DynamicActiveBuilderScope dynamicScope, MablApiBuilder mablApiBuilder, DataWriter dataWriter,
Fmi2Builder.RuntimeModule<PStm> runtimeModule) {
FmiBuilder.RuntimeModule<PStm> runtimeModule) {
this(dynamicScope, mablApiBuilder, dataWriter);
this.runtimeModuleMode = true;
this.runtimeModule = runtimeModule;
Expand Down Expand Up @@ -141,8 +141,8 @@ public void log(DoubleVariableFmi2Api time) {
if (!initialized) {
throw new RuntimeException("DataWriter has not been initialized!");
}
AExpressionStm stm = MableAstFactory.newExpressionStm(MableAstFactory
.newACallExp(MableAstFactory.newAIdentifierExp(this.dataWriter.moduleIdentifier),
AExpressionStm stm = MableAstFactory.newExpressionStm(
MableAstFactory.newACallExp(MableAstFactory.newAIdentifierExp(this.dataWriter.moduleIdentifier),
MableAstFactory.newAIdentifier(this.FUNCTION_WRITEDATAPOINT), Stream.concat(
Arrays.asList(MableAstFactory.newAIdentifierExp(this.dataWriterInstanceConfigurationVariableName),
time.getReferenceExp().clone()).stream(),
Expand Down
Loading

0 comments on commit c85f4ee

Please sign in to comment.