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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
/**
* @file
* @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de)
* @copyright Simplified BSD
*
* @cond
* This program is free software: you can redistribute it and/or modify
* it under the terms of the FreeBSD license as published by the FreeBSD
* project.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the FreeBSD license along with this
* program. If not, see <http://www.opensource.org/licenses/bsd-license>.
* @endcond
*/
#include "InterpreterRC.h"
#include "uscxml/Factory.h"
#include "uscxml/concurrency/DelayedEventQueue.h"
#include <glog/logging.h>
#include "uscxml/UUID.h"
#include "uscxml/DOMUtils.h"
#define VERBOSE 0
#define VERBOSE_STATE_SELECTION 0
#define VERBOSE_FIND_LCCA 0
namespace uscxml {
using namespace Arabica::XPath;
using namespace Arabica::DOM;
#if 1
size_t padding = 0;
std::string getPadding() {
std::string pad = "";
for (int i = 0; i < padding; i++) {
pad += " ";
}
return pad;
}
#endif
Arabica::XPath::NodeSet<std::string> InterpreterRC::removeConflictingTransitions(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) {
Arabica::XPath::NodeSet<std::string> filteredTransitions;
for (unsigned int i = 0; i < enabledTransitions.size(); i++) {
Element<std::string> t1(enabledTransitions[i]);
bool t1Preempted = false;
Arabica::XPath::NodeSet<std::string> transitionsToRemove;
for (unsigned int j = 0; j < filteredTransitions.size(); j++) {
Element<std::string> t2(enabledTransitions[j]);
if (hasIntersection(computeExitSet(t1), computeExitSet(t2))) {
if (isDescendant(getSourceState(t1), getSourceState(t2))) {
transitionsToRemove.push_back(t2);
} else {
t1Preempted = true;
break;
}
}
}
if (!t1Preempted) {
// remove transitionsToRemove from filteredTransitions
std::list<Node<std::string> > tmp;
for (int i = 0; i < filteredTransitions.size(); i++) {
if (!isMember(filteredTransitions[i], transitionsToRemove)) {
tmp.push_back(filteredTransitions[i]);
}
}
filteredTransitions = NodeSet<std::string>();
filteredTransitions.insert(filteredTransitions.end(), tmp.begin(), tmp.end());
filteredTransitions.push_back(t1);
}
}
return filteredTransitions;
}
bool InterpreterRC::hasIntersection(const Arabica::XPath::NodeSet<std::string>& nodeSet1, const Arabica::XPath::NodeSet<std::string>& nodeSet2) {
for (unsigned int i = 0; i < nodeSet1.size(); i++) {
for (unsigned int j = 0; j < nodeSet2.size(); j++) {
if (nodeSet1[i] == nodeSet2[j])
return true;
}
}
return false;
}
void InterpreterRC::exitStates(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) {
NodeSet<std::string> statesToExit = computeExitSet(enabledTransitions);
#if VERBOSE_STATE_SELECTION
std::cout << "exitStates: ";
for (int i = 0; i < statesToExit.size(); i++) {
std::cout << ATTR_CAST(statesToExit[i], "id") << " ";
}
std::cout << std::endl;
#endif
// remove statesToExit from _statesToInvoke
std::list<Node<std::string> > tmp;
for (int i = 0; i < _statesToInvoke.size(); i++) {
if (!isMember(_statesToInvoke[i], statesToExit)) {
tmp.push_back(_statesToInvoke[i]);
}
}
_statesToInvoke = NodeSet<std::string>();
_statesToInvoke.insert(_statesToInvoke.end(), tmp.begin(), tmp.end());
statesToExit.forward(false);
statesToExit.sort();
for (int i = 0; i < statesToExit.size(); i++) {
NodeSet<std::string> histories = filterChildElements(_nsInfo.xmlNSPrefix + "history", statesToExit[i]);
for (int j = 0; j < histories.size(); j++) {
Element<std::string> historyElem = (Element<std::string>)histories[j];
std::string historyType = (historyElem.hasAttribute("type") ? historyElem.getAttribute("type") : "shallow");
NodeSet<std::string> historyNodes;
for (int k = 0; k < _configuration.size(); k++) {
if (iequals(historyType, "deep")) {
if (isAtomic(Element<std::string>(_configuration[k])) && isDescendant(_configuration[k], statesToExit[i]))
historyNodes.push_back(_configuration[k]);
} else {
if (_configuration[k].getParentNode() == statesToExit[i])
historyNodes.push_back(_configuration[k]);
}
}
_historyValue[historyElem.getAttribute("id")] = historyNodes;
}
}
for (int i = 0; i < statesToExit.size(); i++) {
USCXML_MONITOR_CALLBACK3(beforeExitingState, Element<std::string>(statesToExit[i]), (i + 1 < statesToExit.size()))
NodeSet<std::string> onExits = filterChildElements(_nsInfo.xmlNSPrefix + "onExit", statesToExit[i]);
for (int j = 0; j < onExits.size(); j++) {
Element<std::string> onExitElem = (Element<std::string>)onExits[j];
executeContent(onExitElem);
}
USCXML_MONITOR_CALLBACK3(afterExitingState, Element<std::string>(statesToExit[i]), (i + 1 < statesToExit.size()))
NodeSet<std::string> invokes = filterChildElements(_nsInfo.xmlNSPrefix + "invoke", statesToExit[i]);
for (int j = 0; j < invokes.size(); j++) {
Element<std::string> invokeElem = (Element<std::string>)invokes[j];
cancelInvoke(invokeElem);
}
// remove statesToExit[i] from _configuration - test409
tmp.clear();
for (int j = 0; j < _configuration.size(); j++) {
if (_configuration[j] != statesToExit[i]) {
tmp.push_back(_configuration[j]);
}
}
_configuration = NodeSet<std::string>();
_configuration.insert(_configuration.end(), tmp.begin(), tmp.end());
}
}
/*
function computeExitSet(transitions)
statesToExit = new OrderedSet
for t in transitions:
if(t.target):
domain = getTransitionDomain(t)
for s in configuration:
if isDescendant(s,domain):
statesToExit.add(s)
return statesToExit
*/
Arabica::XPath::NodeSet<std::string> InterpreterRC::computeExitSet(const Arabica::XPath::NodeSet<std::string>& transitions) {
NodeSet<std::string> statesToExit;
for (unsigned int i = 0; i < transitions.size(); i++) {
Element<std::string> t(transitions[i]);
if (!isTargetless(t)) {
Arabica::DOM::Node<std::string> domain = getTransitionDomain(t);
if (!domain)
continue;
for (unsigned int j = 0; j < _configuration.size(); j++) {
const Node<std::string>& s = _configuration[j];
if (isDescendant(s, domain)) {
statesToExit.push_back(s);
}
}
}
}
#if VERBOSE
std::cout << "computeExitSet: ";
for (int i = 0; i < statesToExit.size(); i++) {
std::cout << ATTR_CAST(statesToExit[i], "id") << " ";
}
std::cout << std::endl;
#endif
return statesToExit;
}
Arabica::XPath::NodeSet<std::string> InterpreterRC::computeExitSet(const Arabica::DOM::Node<std::string>& transition) {
Arabica::XPath::NodeSet<std::string> transitions;
transitions.push_back(transition);
return computeExitSet(transitions);
}
void InterpreterRC::enterStates(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) {
NodeSet<std::string> statesToEnter;
NodeSet<std::string> statesForDefaultEntry;
// initialize the temporary table for default content in history states
std::map<std::string, Arabica::DOM::Node<std::string> > defaultHistoryContent;
computeEntrySet(enabledTransitions, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
statesToEnter.to_document_order();
#if VERBOSE_STATE_SELECTION
std::cout << "enterStates: ";
for (int i = 0; i < statesToEnter.size(); i++) {
std::cout << ATTR_CAST(statesToEnter[i], "id") << " ";
}
std::cout << std::endl;
#endif
for (int i = 0; i < statesToEnter.size(); i++) {
Element<std::string> s = (Element<std::string>)statesToEnter[i];
USCXML_MONITOR_CALLBACK3(beforeEnteringState, s, i + 1 < statesToEnter.size())
_configuration.push_back(s);
_statesToInvoke.push_back(s);
if (_binding == LATE && !isMember(s, _alreadyEntered)) {
NodeSet<std::string> dataModelElems = filterChildElements(_nsInfo.xmlNSPrefix + "datamodel", s);
if(dataModelElems.size() > 0 && _dataModel) {
Arabica::XPath::NodeSet<std::string> dataElems = filterChildElements(_nsInfo.xmlNSPrefix + "data", dataModelElems[0]);
for (int j = 0; j < dataElems.size(); j++) {
if (dataElems[j].getNodeType() == Node_base::ELEMENT_NODE)
initializeData(Element<std::string>(dataElems[j]));
}
}
_alreadyEntered.push_back(s);
}
// execute onentry executable content
NodeSet<std::string> onEntryElems = filterChildElements(_nsInfo.xmlNSPrefix + "onEntry", s);
executeContent(onEntryElems, false);
if (isMember(s, statesForDefaultEntry)) {
// execute initial transition content for compound states
Arabica::XPath::NodeSet<std::string> transitions = _xpath.evaluate("" + _nsInfo.xpathPrefix + "initial/" + _nsInfo.xpathPrefix + "transition", s).asNodeSet();
if (transitions.size() > 0) {
executeContent(transitions);
}
}
USCXML_MONITOR_CALLBACK3(afterEnteringState, s, i + 1 < statesToEnter.size())
// std::cout << "HIST?: " << ATTR(s, "id") << std::endl;
if (defaultHistoryContent.find(ATTR(s, "id")) != defaultHistoryContent.end()) {
executeContent(Element<std::string>(defaultHistoryContent[ATTR(s, "id")]));
}
if (isFinal(s)) {
internalDoneSend(s);
if (parentIsScxmlState(s)) {
_topLevelFinalReached = true;
} else {
Element<std::string> parent = (Element<std::string>)s.getParentNode();
Element<std::string> grandParent = (Element<std::string>)parent.getParentNode();
internalDoneSend(parent);
if (isParallel(grandParent)) {
Arabica::XPath::NodeSet<std::string> childs = getChildStates(grandParent);
bool inFinalState = true;
for (int j = 0; j < childs.size(); j++) {
if (!isInFinalState(Element<std::string>(childs[j]))) {
inFinalState = false;
break;
}
}
if (inFinalState) {
internalDoneSend(grandParent);
}
}
}
}
}
}
/*
procedure computeEntrySet(transitions, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
for t in transitions:
for s in t.target:
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
ancestor = getTransitionDomain(t)
for s in getEffectiveTargetStates(t)):
addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
*/
void InterpreterRC::computeEntrySet(const Arabica::XPath::NodeSet<std::string>& transitions,
NodeSet<std::string>& statesToEnter,
NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> >& defaultHistoryContent) {
// add all descendants in a dedicated first step
for (int i = 0; i < transitions.size(); i++) {
Element<std::string> t(transitions[i]);
NodeSet<std::string> targets = getTargetStates(t);
for (int j = 0; j < targets.size(); j++) {
Element<std::string> s = Element<std::string>(targets[j]);
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
}
// only now add the ancestors
for (int i = 0; i < transitions.size(); i++) {
Element<std::string> t(transitions[i]);
Element<std::string> ancestor = Element<std::string>(getTransitionDomain(t));
NodeSet<std::string> effectiveTargetStates = getEffectiveTargetStates(t);
for (int j = 0; j < effectiveTargetStates.size(); j++) {
Element<std::string> s = Element<std::string>(effectiveTargetStates[j]);
addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
}
}
/*
function getEffectiveTargetStates(transition)
effectiveTargets = new OrderedSet()
for s in transition.target
if isHistoryState(s):
if historyValue[s.id]:
effectiveTargets.union(historyValue[s.id])
else:
effectiveTargets.union(getEffectiveTargetStates(s.transition))
else:
effectiveTargets.add(s)
return effectiveTargets
*/
Arabica::XPath::NodeSet<std::string> InterpreterRC::getEffectiveTargetStates(const Arabica::DOM::Element<std::string>& transition) {
NodeSet<std::string> effectiveTargets;
NodeSet<std::string> targets;
if (isState(transition)) {
targets = getInitialStates(transition);
return targets;
} else {
targets = getTargetStates(transition);
}
for (int j = 0; j < targets.size(); j++) {
Element<std::string> s = Element<std::string>(targets[j]);
if (isHistory(s)) {
if (_historyValue.find(ATTR(s, "id")) != _historyValue.end()) {
targets.push_back(_historyValue[ATTR(s, "id")]);
} else {
NodeSet<std::string> histTrans = filterChildElements(_nsInfo.xmlNSPrefix + "transition", s);
// TODO: what if there are many history transitions?
if (histTrans.size() > 0)
targets.push_back(getEffectiveTargetStates(Element<std::string>(histTrans[0])));
}
} else {
effectiveTargets.push_back(s);
}
}
return effectiveTargets;
}
void InterpreterRC::computeEntrySet(const Arabica::DOM::Node<std::string>& transition,
NodeSet<std::string>& statesToEnter,
NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> >& defaultHistoryContent) {
Arabica::XPath::NodeSet<std::string> transitions;
transitions.push_back(transition);
computeEntrySet(transitions, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
/*
procedure addDescendantStatesToEnter(state,statesToEnter,statesForDefaultEntry, defaultHistoryContent):
if isHistoryState(state):
if historyValue[state.id]:
for s in historyValue[state.id]:
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
else:
defaultHistoryContent[state.parent.id] = state.transition.content
for s in state.transition.target:
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
else:
statesToEnter.add(state)
if isCompoundState(state):
statesForDefaultEntry.add(state)
for s in getEffectiveTargetStates(state.initial.transition):
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
else:
if isParallelState(state):
for child in getChildStates(state):
if not statesToEnter.some(lambda s: isDescendant(s,child)):
addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
*/
void InterpreterRC::addDescendantStatesToEnter(const Arabica::DOM::Element<std::string>& state,
Arabica::XPath::NodeSet<std::string>& statesToEnter,
Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> >& defaultHistoryContent) {
#if VERBOSE_STATE_SELECTION
std::cout << getPadding() << "addDescendantStatesToEnter: " << ATTR(state, "id") << std::endl;
padding++;
#endif
if (isHistory(state)) {
/*
if historyValue[state.id]:
for s in historyValue[state.id]:
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
else:
defaultHistoryContent[state.parent.id] = state.transition.content
for s in state.transition.target:
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state.parent, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
*/
std::string stateId = ATTR(state, "id");
if (_historyValue.find(stateId) != _historyValue.end()) {
const Arabica::XPath::NodeSet<std::string>& historyValue = _historyValue[stateId];
for (int i = 0; i < historyValue.size(); i++) {
const Element<std::string>& s = Element<std::string>(historyValue[i]);
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
addAncestorStatesToEnter(s, getParentState(s), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
} else {
NodeSet<std::string> transitions = filterChildElements(_nsInfo.xmlNSPrefix + "transition", state);
if (transitions.size() > 0) {
// TODO: what if there are many history transitions?
// std::cout << "HIST: " << ATTR_CAST(getParentState(state), "id") << std::endl;
defaultHistoryContent[ATTR_CAST(getParentState(state), "id")] = transitions[0];
}
for (int i = 0; i < transitions.size(); i++) {
NodeSet<std::string> targets = getTargetStates(Element<std::string>(transitions[i]));
for (int j = 0; j < targets.size(); j++) {
const Element<std::string>& s = Element<std::string>(targets[i]);
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
addAncestorStatesToEnter(s, getParentState(s), statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
}
}
} else {
/*
statesToEnter.add(state)
if isCompoundState(state):
statesForDefaultEntry.add(state)
for s in getEffectiveTargetStates(state.initial.transition):
addDescendantStatesToEnter(s,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
else:
if isParallelState(state):
for child in getChildStates(state):
if not statesToEnter.some(lambda s: isDescendant(s,child)):
addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
*/
if (!isMember(state, statesToEnter)) { // adding an existing element invalidates old reference
#if VERBOSE_STATE_SELECTION
std::cout << getPadding() << "adding: " << ATTR_CAST(state, "id") << std::endl;
#endif
statesToEnter.push_back(state);
}
if (isCompound(state)) {
statesForDefaultEntry.push_back(state);
// test 579 - initial leads to history still fails
NodeSet<std::string> targets = getEffectiveTargetStates(Element<std::string>(state));
for (int i = 0; i < targets.size(); i++) {
const Element<std::string>& s = Element<std::string>(targets[i]);
addDescendantStatesToEnter(s, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
for (int i = 0; i < targets.size(); i++) {
const Element<std::string>& s = Element<std::string>(targets[i]);
addAncestorStatesToEnter(s, state, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
}
} else if(isParallel(state)) {
NodeSet<std::string> childStates = getChildStates(state);
for (int i = 0; i < childStates.size(); i++) {
const Element<std::string>& child = Element<std::string>(childStates[i]);
for (int j = 0; j < statesToEnter.size(); j++) {
const Node<std::string>& s = statesToEnter[j];
if (isDescendant(s, child)) {
goto BREAK_LOOP;
}
}
addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
BREAK_LOOP:
;
}
}
}
padding--;
}
/*
procedure addAncestorStatesToEnter(state, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent)
for anc in getProperAncestors(state,ancestor):
statesToEnter.add(anc)
if isParallelState(anc):
for child in getChildStates(anc):
if not statesToEnter.some(lambda s: isDescendant(s,child)):
addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent)
*/
void InterpreterRC::addAncestorStatesToEnter(const Arabica::DOM::Element<std::string>& state,
const Arabica::DOM::Element<std::string>& ancestor,
Arabica::XPath::NodeSet<std::string>& statesToEnter,
Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry,
std::map<std::string, Arabica::DOM::Node<std::string> >& defaultHistoryContent) {
#if VERBOSE_STATE_SELECTION
std::cout << getPadding() << "addAncestorStatesToEnter: " << ATTR(state, "id") << " - " << ATTR(ancestor, "id") << std::endl;
padding++;
#endif
NodeSet<std::string> ancestors = getProperAncestors(state, ancestor);
for (int i = 0; i < ancestors.size(); i++) {
const Node<std::string>& anc = ancestors[i];
#if VERBOSE_STATE_SELECTION
std::cout << getPadding() << "adding: " << ATTR_CAST(anc, "id") << std::endl;
#endif
statesToEnter.push_back(anc);
if (isParallel(Element<std::string>(anc))) {
NodeSet<std::string> childStates = getChildStates(anc);
for (int j = 0; j < childStates.size(); j++) {
const Element<std::string>& child = Element<std::string>(childStates[j]);
for (int k = 0; k < statesToEnter.size(); k++) {
const Node<std::string>& s = statesToEnter[k];
if (isDescendant(s, child)) {
goto BREAK_LOOP;
}
}
addDescendantStatesToEnter(child,statesToEnter,statesForDefaultEntry, defaultHistoryContent);
BREAK_LOOP:
;
}
}
}
padding--;
}
/*
function getTransitionDomain(t)
tstates = getEffectiveTargetStates(t)
if not tstates:
return null
elif t.type == "internal" and isCompoundState(t.source) and tstates.every(lambda s: isDescendant(s,t.source)):
return t.source
else:
return findLCCA([t.source].append(tstates))
*/
Arabica::DOM::Node<std::string> InterpreterRC::getTransitionDomain(const Arabica::DOM::Element<std::string>& transition) {
NodeSet<std::string> tStates = getEffectiveTargetStates(transition);
if (tStates.size() == 0) {
return Arabica::DOM::Node<std::string>(); // null
}
std::string transitionType = (HAS_ATTR(transition, "type") ? ATTR(transition, "type") : "external");
Node<std::string> source = getSourceState(transition);
if (iequals(transitionType, "internal") && isCompound(Element<std::string>(source))) {
for (int i = 0; i < tStates.size(); i++) {
const Node<std::string>& s = tStates[i];
if (!isDescendant(s, source))
goto BREAK_LOOP;
}
return source;
}
BREAK_LOOP:
Arabica::XPath::NodeSet<std::string> states;
states.push_back(source);
states.push_back(tStates);
return findLCCA(states);
}
}
|