1 |
2
|
krennw
|
|
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 |
|
|
package org.momut.ooas.visitors.analysis;
|
29 |
|
|
|
30 |
|
|
import java.util.ArrayList;
|
31 |
6
|
krennw
|
import java.util.Collections;
|
32 |
2
|
krennw
|
import java.util.HashSet;
|
33 |
|
|
|
34 |
6
|
krennw
|
import org.momut.ooas.ast.expressions.CallExpression;
|
35 |
|
|
import org.momut.ooas.ast.expressions.Expression;
|
36 |
|
|
import org.momut.ooas.ast.expressions.ExpressionKind;
|
37 |
|
|
import org.momut.ooas.ast.expressions.UnaryOperator;
|
38 |
|
|
import org.momut.ooas.ast.identifiers.Identifier;
|
39 |
|
|
import org.momut.ooas.ast.identifiers.IdentifierKind;
|
40 |
|
|
import org.momut.ooas.ast.identifiers.MainModule;
|
41 |
|
|
import org.momut.ooas.ast.identifiers.NamedActionIdentifier;
|
42 |
|
|
import org.momut.ooas.ast.identifiers.ParameterIdentifier;
|
43 |
|
|
import org.momut.ooas.ast.types.FunctionType;
|
44 |
|
|
import org.momut.ooas.ast.types.UlyssesType;
|
45 |
|
|
import org.momut.ooas.codegen.prolog.OoaPrologIdentifier;
|
46 |
|
|
import org.momut.ooas.parser.ParserMessage;
|
47 |
|
|
import org.momut.ooas.parser.ParserState;
|
48 |
|
|
import org.momut.ooas.visitors.OoaCompleteAstTraversalVisitor;
|
49 |
|
|
|
50 |
|
|
|
51 |
2
|
krennw
|
public class OoaPrintActionsVisitor extends OoaCompleteAstTraversalVisitor {
|
52 |
|
|
|
53 |
|
|
private final ArrayList<String> m_result = new ArrayList<>();
|
54 |
|
|
private final OoaPrologIdentifier.Factory m_idFactory;
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
@SuppressWarnings("unused")
|
58 |
|
|
private void printNamedActions(MainModule mainModule)
|
59 |
|
|
{
|
60 |
|
|
for (final Identifier x: mainModule.instance().symbols().symbolList())
|
61 |
|
|
{
|
62 |
|
|
if (x.kind() != IdentifierKind.NamedActionIdentifier)
|
63 |
|
|
continue;
|
64 |
|
|
|
65 |
|
|
final NamedActionIdentifier action = (NamedActionIdentifier)x;
|
66 |
|
|
final FunctionType actionType = (FunctionType) action.type();
|
67 |
|
|
String ctrObs = "";
|
68 |
|
|
switch(actionType.functionType()) {
|
69 |
|
|
default:
|
70 |
|
|
|
71 |
|
|
throw new UnsupportedOperationException();
|
72 |
|
|
case Continuous:
|
73 |
|
|
|
74 |
|
|
throw new UnsupportedOperationException();
|
75 |
|
|
case Internal:
|
76 |
|
|
case Method:
|
77 |
|
|
|
78 |
|
|
continue;
|
79 |
|
|
case Observable:
|
80 |
|
|
|
81 |
|
|
ctrObs = "obs";
|
82 |
|
|
break;
|
83 |
|
|
case Controllable:
|
84 |
|
|
|
85 |
|
|
ctrObs = "ctr";
|
86 |
|
|
break;
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
final OoaPrologIdentifier pIdent = m_idFactory.create();
|
90 |
|
|
action.Accept(pIdent);
|
91 |
|
|
|
92 |
|
|
final StringBuilder parameter = new StringBuilder();
|
93 |
|
|
if (action.parameter().size() > 0) {
|
94 |
|
|
parameter.append("(");
|
95 |
|
|
int z = 0;
|
96 |
|
|
for (final ParameterIdentifier param: action.parameter()) {
|
97 |
|
|
if (z != 0) {
|
98 |
|
|
parameter.append(", ");
|
99 |
|
|
} else
|
100 |
|
|
z++;
|
101 |
|
|
final OoaPrologIdentifier pParamIdent = m_idFactory.create();
|
102 |
|
|
param.Accept(pParamIdent);
|
103 |
|
|
parameter.append(pParamIdent.toString());
|
104 |
|
|
}
|
105 |
|
|
parameter.append(")");
|
106 |
|
|
}
|
107 |
|
|
m_result.add(String.format("%s %s%s", ctrObs, pIdent.toString().replaceAll("'", ""), parameter.toString()));
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
@Override
|
112 |
|
|
public void visit(MainModule mainModule) {
|
113 |
|
|
|
114 |
|
|
mainModule.instance().doOdBlock().Accept(this);
|
115 |
|
|
final StringBuilder b = new StringBuilder();
|
116 |
|
|
b.append("List of controllable/observable actions used:");
|
117 |
|
|
b.append(System.lineSeparator());
|
118 |
6
|
krennw
|
Collections.sort(m_result);
|
119 |
|
|
int i = 0;
|
120 |
2
|
krennw
|
for (final String s: m_result) {
|
121 |
6
|
krennw
|
i ++;
|
122 |
|
|
b.append(String.format("\t%s:\t%s",i,s));
|
123 |
2
|
krennw
|
b.append(System.lineSeparator());
|
124 |
|
|
}
|
125 |
6
|
krennw
|
|
126 |
2
|
krennw
|
m_ParserState.AddMessage(new ParserMessage("",0,0, b.toString()));
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
HashSet<String> m_seenActions = new HashSet<String>();
|
130 |
|
|
|
131 |
|
|
@Override
|
132 |
6
|
krennw
|
public void visit(CallExpression e)
|
133 |
|
|
{
|
134 |
|
|
final FunctionType actionType = (FunctionType) e.child().type();
|
135 |
|
|
String ctrObs = "";
|
136 |
|
|
switch(actionType.functionType()) {
|
137 |
|
|
default:
|
138 |
|
|
|
139 |
|
|
throw new UnsupportedOperationException();
|
140 |
|
|
case Continuous:
|
141 |
|
|
|
142 |
|
|
throw new UnsupportedOperationException();
|
143 |
|
|
case Internal:
|
144 |
|
|
case Method:
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
return;
|
148 |
|
|
case Observable:
|
149 |
|
|
|
150 |
|
|
ctrObs = "obs";
|
151 |
|
|
break;
|
152 |
|
|
case Controllable:
|
153 |
|
|
|
154 |
|
|
ctrObs = "ctr";
|
155 |
|
|
break;
|
156 |
|
|
}
|
157 |
|
|
final OoaPrologIdentifier pIdent = m_idFactory.create();
|
158 |
|
|
e.child().Accept(pIdent);
|
159 |
2
|
krennw
|
|
160 |
6
|
krennw
|
final StringBuilder parameter = new StringBuilder();
|
161 |
|
|
if (e.arguments().size() > 0) {
|
162 |
|
|
int z = 0;
|
163 |
|
|
for (final UlyssesType ut: actionType.parameter()) {
|
164 |
|
|
if (e.arguments().size() <= z)
|
165 |
|
|
continue;
|
166 |
|
|
Expression arg = e.arguments().get(z);
|
167 |
|
|
while (arg.kind() == ExpressionKind.Cast)
|
168 |
|
|
arg = ((UnaryOperator)arg).child();
|
169 |
|
|
|
170 |
|
|
if (z != 0) {
|
171 |
|
|
parameter.append(", ");
|
172 |
|
|
} else
|
173 |
|
|
z++;
|
174 |
|
|
parameter.append(ut.toString());
|
175 |
|
|
parameter.append(" #: ");
|
176 |
|
|
parameter.append( Integer.toString(ut.valueCount()) );
|
177 |
|
|
parameter.append(" [call-type: ");
|
178 |
|
|
parameter.append(arg.type().toString());
|
179 |
|
|
parameter.append(" #: ");
|
180 |
|
|
parameter.append( Integer.toString(arg.type().valueCount()) );
|
181 |
|
|
parameter.append("]");
|
182 |
2
|
krennw
|
}
|
183 |
6
|
krennw
|
}
|
184 |
2
|
krennw
|
|
185 |
6
|
krennw
|
final String actionString = String.format("%s %s(%s)", ctrObs, pIdent.toString().replaceAll("'", ""), parameter.toString());
|
186 |
|
|
if (!m_seenActions.contains(actionString)) {
|
187 |
|
|
m_seenActions.add(actionString);
|
188 |
|
|
m_result.add(actionString);
|
189 |
|
|
}
|
190 |
|
|
};
|
191 |
|
|
|
192 |
|
|
|
193 |
2
|
krennw
|
@Override
|
194 |
|
|
public String toString() {
|
195 |
|
|
return m_result.toString();
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
public OoaPrintActionsVisitor(ParserState aState) {
|
199 |
|
|
super(aState);
|
200 |
|
|
m_idFactory = new OoaPrologIdentifier.Factory();
|
201 |
|
|
}
|
202 |
|
|
} |