Revision 9
Added by Willibald K. over 8 years ago
OoaPrologStatement.java | ||
---|---|---|
45 | 45 |
import org.momut.ooas.ast.statements.KillStatement; |
46 | 46 |
import org.momut.ooas.ast.statements.NondetBlock; |
47 | 47 |
import org.momut.ooas.ast.statements.PrioBlock; |
48 |
import org.momut.ooas.ast.statements.QualitativeConstraintStatement; |
|
49 | 48 |
import org.momut.ooas.ast.statements.SeqBlock; |
50 | 49 |
import org.momut.ooas.ast.statements.SkipStatement; |
51 | 50 |
import org.momut.ooas.ast.statements.Statement; |
... | ... | |
74 | 73 |
protected OoasCodeEmitter m_emitter = new OoasCodeEmitter(); |
75 | 74 |
|
76 | 75 |
@Override |
77 |
public /*override*/ void visit(NondetBlock nondetBlock)
|
|
76 |
public void visit(NondetBlock nondetBlock) |
|
78 | 77 |
{ |
79 | 78 |
int y = 0; |
80 |
for (Statement x: nondetBlock.statements()) |
|
79 |
for (final Statement x: nondetBlock.statements())
|
|
81 | 80 |
{ |
82 | 81 |
if (y != 0) |
83 | 82 |
m_emitter.Append("; "); |
... | ... | |
90 | 89 |
} |
91 | 90 |
|
92 | 91 |
@Override |
93 |
public /*override*/ void visit(SeqBlock seqBlock)
|
|
92 |
public void visit(SeqBlock seqBlock) |
|
94 | 93 |
{ |
95 | 94 |
int y = 0; |
96 | 95 |
if (seqBlock.symbols().symbolList().size() > 0) |
97 | 96 |
{ |
98 | 97 |
m_emitter.Append("(["); |
99 |
for (Identifier sym: seqBlock.symbols().symbolList()) |
|
98 |
for (final Identifier sym: seqBlock.symbols().symbolList())
|
|
100 | 99 |
{ |
101 | 100 |
if (y != 0) |
102 | 101 |
m_emitter.AppendLine(", "); |
103 | 102 |
else |
104 | 103 |
y++; |
105 | 104 |
|
106 |
OoaPrologType atype = createTypeVisitor(); |
|
105 |
final OoaPrologType atype = createTypeVisitor();
|
|
107 | 106 |
sym.type().Accept(atype); |
108 |
OoaPrologIdentifier anIdent = createIdentifierVisitor(); |
|
107 |
final OoaPrologIdentifier anIdent = createIdentifierVisitor();
|
|
109 | 108 |
sym.Accept(anIdent); |
110 | 109 |
m_emitter.Append(String.format("%s:%s", anIdent.toString(), atype.toString())); |
111 | 110 |
} |
... | ... | |
113 | 112 |
} |
114 | 113 |
|
115 | 114 |
y = 0; |
116 |
for (Statement x: seqBlock.statements()) |
|
115 |
for (final Statement x: seqBlock.statements())
|
|
117 | 116 |
{ |
118 | 117 |
if (y != 0) |
119 | 118 |
m_emitter.AppendLine(", "); |
... | ... | |
129 | 128 |
} |
130 | 129 |
|
131 | 130 |
@Override |
132 |
public /*override*/ void visit(PrioBlock prioBlock)
|
|
131 |
public void visit(PrioBlock prioBlock) |
|
133 | 132 |
{ |
134 | 133 |
int y = 0; |
135 |
for (Statement x: prioBlock.statements()) |
|
134 |
for (final Statement x: prioBlock.statements())
|
|
136 | 135 |
{ |
137 | 136 |
if (y != 0) |
138 | 137 |
m_emitter.Append("// "); |
... | ... | |
145 | 144 |
} |
146 | 145 |
|
147 | 146 |
@Override |
148 |
public /*override*/ void visit(GuardedCommand guardedCommand)
|
|
147 |
public void visit(GuardedCommand guardedCommand) |
|
149 | 148 |
{ |
150 |
OoaPrologExpression expr = createExpressionVisitor(); |
|
149 |
final OoaPrologExpression expr = createExpressionVisitor();
|
|
151 | 150 |
guardedCommand.guard().Accept(expr); |
152 | 151 |
|
153 | 152 |
m_emitter.AppendLineIncIndent(String.format("(%s%s) %s ", |
... | ... | |
162 | 161 |
} |
163 | 162 |
|
164 | 163 |
@Override |
165 |
public /*override*/ void visit(Assignment assignment)
|
|
164 |
public void visit(Assignment assignment) |
|
166 | 165 |
{ |
167 | 166 |
if (assignment.nondetExpression() != null) |
168 | 167 |
throw new NotImplementedException(); |
169 | 168 |
|
170 |
Iterator<Expression> aPlaceIt = assignment.places().iterator(); |
|
171 |
Iterator<Expression> aValueIt = assignment.values().iterator(); |
|
172 |
ArrayList<String> assignments = new ArrayList<String>(); |
|
169 |
final Iterator<Expression> aPlaceIt = assignment.places().iterator();
|
|
170 |
final Iterator<Expression> aValueIt = assignment.values().iterator();
|
|
171 |
final ArrayList<String> assignments = new ArrayList<String>();
|
|
173 | 172 |
|
174 | 173 |
while (aPlaceIt.hasNext()) |
175 | 174 |
{ |
176 | 175 |
final Expression aPlace = aPlaceIt.next(); |
177 | 176 |
final Expression aValue = aValueIt.next(); |
178 | 177 |
|
179 |
OoaPrologExpression prologPlace = createExpressionVisitor(true); |
|
178 |
final OoaPrologExpression prologPlace = createExpressionVisitor(true);
|
|
180 | 179 |
aPlace.Accept(prologPlace); |
181 | 180 |
assert(prologPlace.tmpVariables().size() == 1); |
182 | 181 |
|
183 |
OoaPrologExpression prologValue = createExpressionVisitor(); |
|
182 |
final OoaPrologExpression prologValue = createExpressionVisitor();
|
|
184 | 183 |
aValue.Accept(prologValue); |
185 | 184 |
assert(prologValue.tmpVariables().size() == 1); |
186 | 185 |
|
... | ... | |
213 | 212 |
} |
214 | 213 |
|
215 | 214 |
int pos = 0; |
216 |
for (String s: assignments) |
|
215 |
for (final String s: assignments)
|
|
217 | 216 |
{ |
218 | 217 |
if (pos != 0) |
219 | 218 |
m_emitter.Append(","); |
... | ... | |
223 | 222 |
} |
224 | 223 |
|
225 | 224 |
@Override |
226 |
public /*override*/ void visit(Call call)
|
|
225 |
public void visit(Call call) |
|
227 | 226 |
{ |
228 |
Expression ce = call.callExpression(); |
|
227 |
final Expression ce = call.callExpression();
|
|
229 | 228 |
String callstatement = ""; |
230 |
StringBuilder parameter = new StringBuilder(); |
|
229 |
final StringBuilder parameter = new StringBuilder();
|
|
231 | 230 |
boolean hideCall = false; |
232 | 231 |
|
233 | 232 |
if (ce.kind() == ExpressionKind.Identifier) |
234 | 233 |
callstatement = ((IdentifierExpression)ce).identifier().tokenText(); |
235 | 234 |
else if (ce.kind() == ExpressionKind.Call) |
236 | 235 |
{ |
237 |
CallExpression parens = (CallExpression)ce; |
|
236 |
final CallExpression parens = (CallExpression)ce;
|
|
238 | 237 |
|
239 |
OoaPrologExpression prologexpr = createExpressionVisitor(); |
|
238 |
final OoaPrologExpression prologexpr = createExpressionVisitor();
|
|
240 | 239 |
parens.child().Accept(prologexpr); |
241 | 240 |
|
242 | 241 |
if (parens.child().kind() == ExpressionKind.Identifier && |
243 | 242 |
((IdentifierExpression)parens.child()).identifier().kind() == IdentifierKind.NamedActionIdentifier) |
244 | 243 |
{ |
245 | 244 |
// we need to hide internal actions |
246 |
NamedActionIdentifier namedactionid = (NamedActionIdentifier)((IdentifierExpression)parens.child()).identifier(); |
|
245 |
final NamedActionIdentifier namedactionid = (NamedActionIdentifier)((IdentifierExpression)parens.child()).identifier();
|
|
247 | 246 |
hideCall = ((FunctionType)namedactionid.type()).functionType() == FunctionTypeEnum.Internal; |
248 | 247 |
} |
249 | 248 |
|
250 | 249 |
m_emitter.Append(prologexpr.toString()); |
251 | 250 |
callstatement = prologexpr.tmpVariables().get(0); |
252 | 251 |
int i = 0; |
253 |
for (Expression arg: parens.arguments()) |
|
252 |
for (final Expression arg: parens.arguments())
|
|
254 | 253 |
{ |
255 | 254 |
if (i != 0) |
256 | 255 |
parameter.append(", "); |
257 | 256 |
else |
258 | 257 |
i++; |
259 |
OoaPrologExpression paramexpr = createExpressionVisitor(); |
|
258 |
final OoaPrologExpression paramexpr = createExpressionVisitor();
|
|
260 | 259 |
arg.Accept(paramexpr); |
261 | 260 |
m_emitter.Append(paramexpr.toString()); |
262 | 261 |
parameter.append(paramexpr.tmpVariables().get(0)); |
... | ... | |
275 | 274 |
} |
276 | 275 |
|
277 | 276 |
@Override |
278 |
public /*override*/ void visit(SkipStatement skipStatement)
|
|
277 |
public void visit(SkipStatement skipStatement) |
|
279 | 278 |
{ |
280 | 279 |
m_emitter.Append("skip"); |
281 | 280 |
} |
282 | 281 |
|
283 | 282 |
@Override |
284 |
public /*override*/ void visit(AbortStatement abortStatement)
|
|
283 |
public void visit(AbortStatement abortStatement) |
|
285 | 284 |
{ |
286 | 285 |
throw new NotImplementedException(); |
287 | 286 |
} |
288 | 287 |
|
289 | 288 |
@Override |
290 |
public /*override*/ void visit(KillStatement killStatement)
|
|
289 |
public void visit(KillStatement killStatement) |
|
291 | 290 |
{ |
292 | 291 |
throw new NotImplementedException(); |
293 | 292 |
} |
294 | 293 |
|
295 | 294 |
@Override |
296 |
public /*override*/ void visit(QualitativeConstraintStatement qalitativeConstraintStatement)
|
|
295 |
public String toString()
|
|
297 | 296 |
{ |
298 |
if (qalitativeConstraintStatement.tag) |
|
299 |
{ |
|
300 |
m_emitter.Append("% observable assignment in actionhead"); |
|
301 |
return; |
|
302 |
} |
|
303 |
|
|
304 |
OoaPrologIdentifier id1 = createIdentifierVisitor(); |
|
305 |
OoaPrologIdentifier id2 = createIdentifierVisitor(); |
|
306 |
OoaPrologIdentifier id3 = createIdentifierVisitor(); |
|
307 |
|
|
308 |
|
|
309 |
switch (qalitativeConstraintStatement.operation()) |
|
310 |
{ |
|
311 |
case Deriv: |
|
312 |
qalitativeConstraintStatement.variable0().Accept(id1); |
|
313 |
qalitativeConstraintStatement.variable1().Accept(id2); |
|
314 |
m_emitter.Append(String.format("%s := dt %s", id1.toString(), id2.toString())); |
|
315 |
break; |
|
316 |
case Diff: |
|
317 |
qalitativeConstraintStatement.variable0().Accept(id1); |
|
318 |
qalitativeConstraintStatement.variable1().Accept(id2); |
|
319 |
qalitativeConstraintStatement.variable2().Accept(id3); |
|
320 |
m_emitter.Append(String.format("%s := %s - %s", id1.toString(), id2.toString(), id3.toString())); |
|
321 |
break; |
|
322 |
case Equal: |
|
323 |
qalitativeConstraintStatement.variable0().Accept(id1); |
|
324 |
qalitativeConstraintStatement.variable1().Accept(id2); |
|
325 |
m_emitter.Append(String.format("%s := %s", id1.toString(), id2.toString())); |
|
326 |
break; |
|
327 |
|
|
328 |
case Prod: |
|
329 |
qalitativeConstraintStatement.variable0().Accept(id1); |
|
330 |
qalitativeConstraintStatement.variable1().Accept(id2); |
|
331 |
qalitativeConstraintStatement.variable2().Accept(id3); |
|
332 |
m_emitter.Append(String.format("%s := %s * %s", id1.toString(), id2.toString(), id3.toString())); |
|
333 |
break; |
|
334 |
|
|
335 |
case Sum: |
|
336 |
qalitativeConstraintStatement.variable0().Accept(id1); |
|
337 |
qalitativeConstraintStatement.variable1().Accept(id2); |
|
338 |
qalitativeConstraintStatement.variable2().Accept(id3); |
|
339 |
m_emitter.Append(String.format("%s := %s + %s", id1.toString(), id2.toString(), id3.toString())); |
|
340 |
break; |
|
341 |
|
|
342 |
default: |
|
343 |
throw new NotImplementedException(); |
|
344 |
} |
|
345 |
} |
|
346 |
|
|
347 |
|
|
348 |
@Override |
|
349 |
public /*override*/ String toString() |
|
350 |
{ |
|
351 | 297 |
return m_emitter.toString(); |
352 | 298 |
} |
353 | 299 |
|
Also available in: Unified diff
remove support for Qualitative Action Systems, rename UlyssesType to Type