Merge lp:~verifypn-stub/verifypn/substraction-fix into lp:verifypn

Proposed by Jiri Srba
Status: Merged
Approved by: Jiri Srba
Approved revision: 185
Merged at revision: 185
Proposed branch: lp:~verifypn-stub/verifypn/substraction-fix
Merge into: lp:verifypn
Diff against target: 37 lines (+20/-6)
1 file modified
PetriParse/QueryXMLParser.cpp (+20/-6)
To merge this branch: bzr merge lp:~verifypn-stub/verifypn/substraction-fix
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+330161@code.launchpad.net

Description of the change

Fixes n-ari subtractions.

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

tested and works

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'PetriParse/QueryXMLParser.cpp'
2--- PetriParse/QueryXMLParser.cpp 2017-08-01 19:54:53 +0000
3+++ PetriParse/QueryXMLParser.cpp 2017-09-04 13:31:57 +0000
4@@ -391,13 +391,27 @@
5 }
6 return expr;
7 } else if (elementName == "integer-difference") {
8- auto children = element->first_node();
9+ auto it = element->first_node();
10 size_t nrOfChildren = getChildCount(element);
11- if (nrOfChildren != 2) return NULL; // at least two integer subexpression are required
12- Expr_ptr expr1 = parseIntegerExpression(children);
13- Expr_ptr expr2 = parseIntegerExpression(children->next_sibling());
14- if(expr1 == NULL || expr2 == NULL) return NULL;
15- return std::make_shared<SubtractExpr>(expr1, expr2);
16+
17+ if(nrOfChildren == 1)
18+ {
19+ auto expr1 = std::make_shared<LiteralExpr>(0);
20+ auto expr2 = parseIntegerExpression(it);
21+ if(expr1 == nullptr || expr2 == nullptr) return nullptr;
22+ return std::make_shared<SubtractExpr>(expr1, expr2);
23+ }
24+ else
25+ {
26+ Expr_ptr expr = parseIntegerExpression(it);
27+ if(expr == nullptr) return nullptr;
28+ for (it = it->next_sibling(); it; it = it->next_sibling()) {
29+ Expr_ptr child = parseIntegerExpression(it);
30+ if(child == nullptr) return nullptr;
31+ expr = std::make_shared<SubtractExpr>(expr, child);
32+ }
33+ return expr;
34+ }
35 }
36 return NULL;
37 }

Subscribers

People subscribed via source and target branches