145
149
if (childName == "place-bound") {
146
150
std::vector<std::string> places;
147
151
for (auto it = child->first_node(); it ; it = it->next_sibling()) {
148
if (strcmp(it->name(), "place") != 0) return nullptr;
152
if (strcmp(it->name(), "place") != 0)
149
157
auto place = parsePlace(it);
150
if (place == "") return nullptr; // invalid place name
151
auto tmp = std::make_shared<LessThanCondition>(
152
std::make_shared<IdentifierExpr>(place),
153
std::make_shared<LiteralExpr>(0));
154
if (cond == nullptr) {
157
cond = std::make_shared<AndCondition>(cond, tmp);
161
return nullptr; // invalid place name
159
163
places.push_back(place);
161
cond->setPlaceNameForBounds(places);
162
return std::make_shared<EFCondition>(cond);
165
auto bnds = std::make_shared<UpperBoundsCondition>(places);
166
return std::make_shared<EFCondition>(bnds);
163
167
} else if ((cond = parseBooleanFormula(child)) != nullptr) {
192
197
if ((cond = parseBooleanFormula(element->first_node())) != nullptr)
193
198
return std::make_shared<EFCondition>(cond);
194
199
} else if (elementName == "exists-path") {
195
if (getChildCount(element) != 1) return nullptr;
200
if (getChildCount(element) != 1)
196
205
auto child = element->first_node();
197
206
if (strcmp(child->name(), "next") == 0) {
198
if (getChildCount(child) != 1) return nullptr;
207
if (getChildCount(child) != 1)
199
212
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
200
213
return std::make_shared<EXCondition>(cond);
201
214
} else if (strcmp(child->name(), "globally") == 0) {
202
if (getChildCount(child) != 1) return nullptr;
215
if (getChildCount(child) != 1)
203
220
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
204
221
return std::make_shared<EGCondition>(cond);
205
222
} else if (strcmp(child->name(), "finally") == 0) {
206
if (getChildCount(child) != 1) return nullptr;
223
if (getChildCount(child) != 1)
207
228
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
208
229
return std::make_shared<EFCondition>(cond);
209
230
} else if (strcmp(child->name(), "until") == 0) {
210
if (getChildCount(child) != 2) return nullptr;
231
if (getChildCount(child) != 2)
211
236
auto before = child->first_node();
212
237
auto reach = before->next_sibling();
213
238
if (getChildCount(before) != 1 || getChildCount(reach) != 1 ||
214
strcmp(before->name(), "before") != 0 || strcmp(reach->name(), "reach") != 0) return nullptr;
239
strcmp(before->name(), "before") != 0 || strcmp(reach->name(), "reach") != 0)
215
244
if ((cond = parseBooleanFormula(before->first_node())) != nullptr) {
216
245
if ((cond2 = parseBooleanFormula(reach->first_node())) != nullptr) {
217
246
return std::make_shared<EUCondition>(cond, cond2);
221
250
} else if (elementName == "all-paths") {
222
if (getChildCount(element) != 1) return nullptr;
251
if (getChildCount(element) != 1)
223
256
auto child = element->first_node();
224
257
if (strcmp(child->name(), "next") == 0) {
225
if (getChildCount(child) != 1) return nullptr;
258
if (getChildCount(child) != 1)
226
263
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
227
264
return std::make_shared<AXCondition>(cond);
228
265
} else if (strcmp(child->name(), "globally") == 0) {
229
if (getChildCount(child) != 1) return nullptr;
266
if (getChildCount(child) != 1)
230
271
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
231
272
return std::make_shared<AGCondition>(cond);
232
273
} else if (strcmp(child->name(), "finally") == 0) {
233
if (getChildCount(child) != 1) return nullptr;
274
if (getChildCount(child) != 1)
234
279
if ((cond = parseBooleanFormula(child->first_node())) != nullptr)
235
280
return std::make_shared<AFCondition>(cond);
236
281
} else if (strcmp(child->name(), "until") == 0) {
237
if (getChildCount(child) != 2) return nullptr;
282
if (getChildCount(child) != 2)
238
287
auto before = child->first_node();
239
288
auto reach = before->next_sibling();
240
289
if (getChildCount(before) != 1 || getChildCount(reach) != 1 ||
241
strcmp(before->name(), "before") != 0 || strcmp(reach->name(), "reach") != 0) return nullptr;
290
strcmp(before->name(), "before") != 0 || strcmp(reach->name(), "reach") != 0)
242
295
if ((cond = parseBooleanFormula(before->first_node())) != nullptr){
243
296
if ((cond2 = parseBooleanFormula(reach->first_node())) != nullptr) {
244
297
return std::make_shared<AUCondition>(cond, cond2);
252
305
} else if (elementName == "false") {
253
306
return BooleanCondition::FALSE_CONSTANT;
254
307
} else if (elementName == "negation") {
255
if (getChildCount(element) != 1) return nullptr;
308
if (getChildCount(element) != 1)
256
313
auto child = element->first_node();
257
314
if (strcmp(child->name(), "invariant") == 0) {
258
315
if ((cond = parseBooleanFormula(child->first_node())) != nullptr) {
274
331
} else if (elementName == "conjunction") {
275
332
auto children = element->first_node();
276
if (getChildCount(element) < 2) return nullptr;
333
if (getChildCount(element) < 2)
277
338
auto it = children;
278
339
cond = parseBooleanFormula(it);
279
340
// skip a sibling
280
341
for (it = it->next_sibling(); it; it = it->next_sibling()) {
281
342
Condition_ptr child = parseBooleanFormula(it);
282
if(child == nullptr || cond == nullptr) return nullptr;
343
if(child == nullptr || cond == nullptr)
283
348
cond = std::make_shared<AndCondition>(cond, child);
286
351
} else if (elementName == "disjunction") {
287
352
auto children = element->first_node();
288
if (getChildCount(element) < 2) return nullptr;
353
if (getChildCount(element) < 2)
289
358
auto it = children;
290
359
cond = parseBooleanFormula(it);
291
360
// skip a sibling
292
361
for (it = it->next_sibling(); it; it = it->next_sibling()) {
293
362
Condition_ptr child = parseBooleanFormula(it);
294
if(child == nullptr || cond == nullptr) return nullptr;
363
if(child == nullptr || cond == nullptr)
295
368
cond = std::make_shared<OrCondition>(cond, child);
298
371
} else if (elementName == "exclusive-disjunction") {
299
372
auto children = element->first_node();
300
if (getChildCount(element) != 2) return nullptr; // we support only two subformulae here
373
if (getChildCount(element) != 2)
301
378
cond = parseBooleanFormula(children);
302
379
cond2 = parseBooleanFormula(children->next_sibling());
303
if (cond == nullptr || cond2 == nullptr) return nullptr;
380
if (cond == nullptr || cond2 == nullptr)
304
385
return std::make_shared<OrCondition>(
305
386
std::make_shared<AndCondition>(cond, std::make_shared<NotCondition>(cond2)),
306
387
std::make_shared<AndCondition>(std::make_shared<NotCondition>(cond), cond2));
307
388
} else if (elementName == "implication") {
308
389
auto children = element->first_node();
309
if (getChildCount(element) != 2) return nullptr; // implication has only two subformulae
390
if (getChildCount(element) != 2)
310
395
cond = parseBooleanFormula(children);
311
396
cond2 = parseBooleanFormula(children->next_sibling());
312
if (cond == nullptr || cond2 == nullptr) return nullptr;
397
if (cond == nullptr || cond2 == nullptr)
313
402
return std::make_shared<OrCondition>(std::make_shared<NotCondition>(cond), cond2);
314
403
} else if (elementName == "equivalence") {
315
404
auto children = element->first_node();
316
if (getChildCount(element) != 2) return nullptr; // we support only two subformulae here
405
if (getChildCount(element) != 2)
317
410
cond = parseBooleanFormula(children);
318
411
cond2 = parseBooleanFormula(children->next_sibling());
319
412
if (cond == nullptr || cond2 == nullptr) return nullptr;
324
417
elementName == "integer-lt" || elementName == "integer-le" ||
325
418
elementName == "integer-gt" || elementName == "integer-ge") {
326
419
auto children = element->first_node();
327
if (getChildCount(element) != 2) return nullptr; // exactly two integer subformulae are required
420
if (getChildCount(element) != 2)
328
425
Expr_ptr expr1 = parseIntegerExpression(children);
329
426
Expr_ptr expr2 = parseIntegerExpression(children->next_sibling());
330
if(expr1 == nullptr || expr2 == nullptr) return nullptr;
427
if(expr1 == nullptr || expr2 == nullptr)
331
432
if (elementName == "integer-eq") return std::make_shared<EqualCondition>(expr1, expr2);
332
433
else if (elementName == "integer-ne") return std::make_shared<NotEqualCondition>(expr1, expr2);
333
434
else if (elementName == "integer-lt") return std::make_shared<LessThanCondition>(expr1, expr2);
336
437
else if (elementName == "integer-ge") return std::make_shared<GreaterThanOrEqualCondition>(expr1, expr2);
337
438
} else if (elementName == "is-fireable") {
338
439
size_t nrOfChildren = getChildCount(element);
339
if (nrOfChildren == 0) return nullptr;
440
if (nrOfChildren == 0)
340
445
std::vector<Condition_ptr> conds;
341
446
for (auto it = element->first_node(); it; it = it->next_sibling()) {
342
if (strcmp(it->name(), "transition") != 0) return nullptr;
447
if (strcmp(it->name(), "transition") != 0)
343
452
conds.emplace_back(std::make_shared<FireableCondition>(it->value()));
345
454
return std::make_shared<OrCondition>(conds);
456
std::cout << elementName << std::endl;
351
462
string elementName = element->name();
352
463
if (elementName == "integer-constant") {
354
if (sscanf(element->value(), "%d", &i) == EOF) return nullptr; // expected integer at this place
465
if (sscanf(element->value(), "%d", &i) == EOF)
355
470
return std::make_shared<LiteralExpr>(i);
356
471
} else if (elementName == "tokens-count") {
357
472
auto children = element->first_node();