blob: 2331093279e5a8812a4d1f83e7bb1e4437d64e62 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*******************************************************************************
* Copyright (c) 2010 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.generator.generic;
import org.eclipse.etrice.core.room.CPBranchTransition;
import org.eclipse.etrice.core.room.ContinuationTransition;
import org.eclipse.etrice.core.room.InitialTransition;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.TriggeredTransition;
import org.eclipse.etrice.core.room.VarDecl;
import org.eclipse.etrice.generator.etricegen.ExpandedActorClass;
import org.eclipse.etrice.generator.etricegen.ITransitionChainVisitor;
import org.eclipse.etrice.generator.etricegen.TransitionChain;
import org.eclipse.etrice.generator.extensions.Extensions;
import com.google.inject.Inject;
public class LanguageTransitionChainVisitor implements ITransitionChainVisitor {
private ExpandedActorClass ac;
private LanguageGenerator javaGen = new LanguageGenerator();
@Inject ILanguageExtension langExt;
private String typedData = "";
private String dataArg = "";
LanguageTransitionChainVisitor(ExpandedActorClass ac, TransitionChain tc) {
this.ac = ac;
if (tc.getTransition() instanceof TriggeredTransition) {
// we rely on the previous checking during the generator model creation
VarDecl data = ((TriggeredTransition)tc.getTransition()).getTriggers().get(0).getMsgFromIfPairs().get(0).getMessage().getData();
String[] result = javaGen.getArglistAndTypedData(data);
dataArg = result[0];
typedData = result[1];
}
}
// ITransitionChainVisitor interface
public String genActionOperationCall(Transition tr) {
if (tr.getAction()!=null && !tr.getAction().getCommands().isEmpty()) {
if (tr instanceof InitialTransition)
return Extensions.getActionCodeOperationName(tr)+"("+langExt.selfPointer(false)+");\n";
else
return Extensions.getActionCodeOperationName(tr)+"("+langExt.selfPointer(true)+"ifitem"+dataArg+");\n";
}
return "";
}
public String genEntryOperationCall(State state) {
return Extensions.getEntryCodeOperationName(state)+"("+langExt.selfPointer(false)+");\n";
}
public String genExitOperationCall(State state) {
return Extensions.getExitCodeOperationName(state)+"("+langExt.selfPointer(false)+");\n";
}
public String genElseIfBranch(CPBranchTransition tr, boolean isFirst) {
String result = "";
if (!isFirst )
result = "}\nelse ";
result += "if ("+ac.getCode(tr.getCondition())+") {\n";
return result;
}
public String genElseBranch(ContinuationTransition tr) {
String result = "}\nelse {\n";
return result;
}
public String genEndIf() {
return "}\n";
}
public String genReturnState(State state) {
return "return " + Extensions.getStateId(state) + ";";
}
public String genTypedData() {
return typedData;
}
}
|