引数を持たない update や input メソッド用の処理を追加した.
1 parent 2ab9b01 commit ed8c151f4906a054d37796940e2c0862de709e72
Naoya Nitta authored on 30 Jun 2023
Showing 2 changed files
View
14
AlgebraicDataflowArchitectureModel/models/Clock.dtram
model {
channel CIO1 {
out min(m, tick) == mod(m + 1, 60)
out min(m: Int, tick) == mod(m + 1, 60)
}
channel HourUpdate {
in hour(h, update(h')) == h'
out hour_hand(h_ang, update(h')) == h' / 6 * PI
in hour(h: Int, update(h2)) == h2
out hour_hand(h_ang: Float, update(h2)) == h2 / 6 * PI
}
channel MinUpdate {
in min(m, update(m')) == m'
out min_hand(m_ang, update(m')) == m' / 30 * PI
in min(m, update(m2)) == m2
out min_hand(m_ang: Float, update(m2)) == m2 / 30 * PI
}
channel Clock {
in min(m, update(m')) == m'
out hour(h, update(m')) == if(eq(m', 0), mod(h + 1, 24), h)
in min(m, update(m2)) == m2
out hour(h, update(m2)) == if(eq(m2, 0), mod(h + 1, 24), h)
}
}
geometry {
node c HourUpdate:520,340,30,30
View
53
AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java
import models.algebra.Type;
import models.algebra.UnificationFailed;
import models.algebra.ValueUndefined;
import models.algebra.Variable;
import models.controlFlowModel.CallEdge;
import models.controlFlowModel.ControlFlowGraph;
import models.controlFlowModel.EntryPointObjectNode;
import models.controlFlowModel.ObjectNode;
import models.controlFlowModel.StatefulObjectNode;
Node dstNode = outEdge.getDestination();
MethodDeclaration calleeMethod = declareAndFillUpdateAndInputMethods(dstNode, outEdge, node, dataFlowInform, componentMap, langSpec);
if (input == null) {
// Declare an input method.
input = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters()));
if (calleeMethod.getParameters() != null) {
input = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters()));
} else {
input = langSpec.newMethodDeclaration(calleeMethod.getName(), null);
}
}
// Add a statement to call the destination method.
addInvocationInMediatorUpdate(input, calleeMethod, ((ObjectNode) dstNode).getName(), dataFlowInform, langSpec);
}
Node dstNode = outEdge.getDestination();
MethodDeclaration calleeMethod = declareAndFillUpdateAndInputMethods(dstNode, outEdge, prevResNode, dataFlowInform, componentMap, langSpec);
if (updateOrInput == null && prevResNode instanceof EntryPointObjectNode) {
// Declare an input method.
updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters()));
if (calleeMethod.getParameters() != null) {
updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters()));
} else {
updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), null);
}
component.addMethod(updateOrInput);
}
// Add a statement to call the destination method.
addInvocationInMediatorUpdate(updateOrInput, calleeMethod, ((ObjectNode) dstNode).getName(), dataFlowInform, langSpec);
private static void addInvocationInResourceUpdate(Node node, MethodDeclaration resourceUpdateMethod, MethodDeclaration calleeMethod, String dstNodeName, ILanguageSpecific langSpec) {
List<String> params = new ArrayList<>();
params.add(langSpec.getFieldAccessor(fieldOfResourceState));
for (VariableDeclaration v: calleeMethod.getParameters()) {
if (!((ObjectNode) node).getName().equals(v.getName())) {
params.add(v.getName());
if (calleeMethod.getParameters() != null) {
for (VariableDeclaration v: calleeMethod.getParameters()) {
if (!((ObjectNode) node).getName().equals(v.getName())) {
params.add(v.getName());
}
}
}
// for (ChannelMember rc: re.getChannelGenerator().getReferenceChannelMembers()) {
// // to get the value of reference member.
private static void addInvocationInMediatorUpdate(MethodDeclaration resourceUpdateMethod, MethodDeclaration calleeMethod, String dstNodeName, Map<Edge, Map<PushPullValue, List<ResourceNode>>> dataFlowInform, ILanguageSpecific langSpec) {
Map<MethodDeclaration, Set<IdentifierTemplate>> referredResources = new HashMap<>();
List<String> params = new ArrayList<>();
for (VariableDeclaration v: calleeMethod.getParameters()) {
params.add(v.getName());
if (calleeMethod.getParameters() != null) {
for (VariableDeclaration v: calleeMethod.getParameters()) {
params.add(v.getName());
}
}
resourceUpdateMethod.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstNodeName),
calleeMethod.getName(),
params) + langSpec.getStatementDelimiter()); // this.dst.updateSrc(value, refParams);
mainInput = langSpec.newMethodDeclaration(str, false, null, params);
mainComponent.addMethod(mainInput);
} else {
// Add type to a parameter without type.
for (VariableDeclaration param: mainInput.getParameters()) {
if (param.getType() == null) {
for (VariableDeclaration p: params) {
if (param.getName().equals(p.getName()) && p.getType() != null) {
param.setType(p.getType());
if (mainInput.getParameters() != null) {
for (VariableDeclaration param: mainInput.getParameters()) {
if (param.getType() == null) {
for (VariableDeclaration p: params) {
if (param.getName().equals(p.getName()) && p.getType() != null) {
param.setType(p.getType());
}
}
}
}
}