summaryrefslogtreecommitdiffstats
path: root/src/uscxml/debug/InterpreterIssue.cpp
blob: 346c0f6ff13db5bdbd0c109fc6a5ea77fc312db7 (plain)
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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
/**
 *  @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 <string>

#include "InterpreterIssue.h"
#include "uscxml/util/DOM.h"
#include "uscxml/util/String.h"
#include "uscxml/util/Predicates.h"
#include "uscxml/interpreter/InterpreterImpl.h"
#include "uscxml/plugins/Factory.h"

#include <xercesc/dom/DOMDocument.hpp>

using namespace XERCESC_NS;

namespace uscxml {

InterpreterIssue::InterpreterIssue(const std::string& msg, DOMNode* node, IssueSeverity severity, const std::string& specRef) : message(msg), node(node), severity(severity), specRef(specRef) {
	if (node)
		xPath = DOMUtils::xPathForNode(node);
}

// find all elements in the SCXML namespace in one traversal
void assembleNodeSets(const std::string nsPrefix, DOMElement* node, std::map<std::string, std::list<DOMElement*> >& sets) {
	for (auto childElem = node->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) {

		if (TAGNAME(childElem).find(nsPrefix) == 0) {
			// correct namespace, insert via localname
			sets[LOCALNAME(childElem)].push_back(static_cast<DOMElement*>(childElem));
		}
		assembleNodeSets(nsPrefix, childElem, sets);
	}
}

std::list<std::set<const DOMElement* > > getAllConfigurations(const DOMElement* root) {
	std::list<std::set<const DOMElement* > > allConfigurations;
	std::string nsPrefix = X(root->getPrefix());
	std::string localName = X(root->getLocalName());
	bool isAtomic = true;

//	std::cout << *root;

	for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) {
//		std::cout << *childElem;

		if (XMLString::compareIString(childElem->getTagName(), X(nsPrefix + "state")) == 0 ||
		        XMLString::compareIString(childElem->getTagName(), X(nsPrefix + "parallel")) == 0 ||
		        XMLString::compareIString(childElem->getTagName(), X(nsPrefix + "final")) == 0) {
			// nested child state
			std::list<std::set<const DOMElement*> > nestedConfigurations = getAllConfigurations(childElem);
			isAtomic = false;
			if (localName == "parallel" && allConfigurations.size() > 0) {
				// for every nested configuration, every new nested is valid
				std::list<std::set<const DOMElement*> > combinedConfigurations;
				for (auto existIter = allConfigurations.begin(); existIter != allConfigurations.end(); existIter++) {
					std::set<const DOMElement*> existingConfig = *existIter;

					for (auto newIter = nestedConfigurations.begin(); newIter != nestedConfigurations.end(); newIter++) {

						std::set<const DOMElement*> newConfig = *newIter;
						std::set<const DOMElement*> combinedSet;
						combinedSet.insert(existingConfig.begin(), existingConfig.end());
						combinedSet.insert(newConfig.begin(), newConfig.end());

						combinedConfigurations.push_back(combinedSet);
					}
				}
				allConfigurations = combinedConfigurations;
			} else {
				// just add nested configurations and this
				for (auto newIter = nestedConfigurations.begin(); newIter != nestedConfigurations.end(); newIter++) {
					std::set<const DOMElement*> newConfig = *newIter;
					if (localName != "scxml")
						newConfig.insert(root);
					allConfigurations.push_back(newConfig);
				}
			}
		}
	}

	if (isAtomic) {
		std::set<const DOMElement*> soleConfig;
		soleConfig.insert(root);
		allConfigurations.push_back(soleConfig);
	}
	return allConfigurations;

}

/**
 * Can the given states ever appear in an active configuration?
 */
bool hasLegalCompletion(const std::list<DOMElement*>& states) {
	if (states.size() < 2)
		return true;

	// iterate every pair
	for (auto outer = states.begin(); outer != states.end(); outer++) {
		DOMElement* s1 = *outer;
		for (auto inner = outer; inner != states.end(); inner++) {
			if (inner == outer)
				continue;

			DOMElement* s2 = *inner;
			DOMNode* parent;

			// ok to be directly ancestorally related
			if (DOMUtils::isDescendant(s1, s2) || DOMUtils::isDescendant(s2, s1))
				goto NEXT_PAIR;

			// find least common ancestor
			parent = s1->getParentNode();
			while(parent && parent->getNodeType() == DOMNode::ELEMENT_NODE) {
				if (DOMUtils::isDescendant(s2, parent)) {
					if (isParallel(static_cast<DOMElement*>(parent)))
						goto NEXT_PAIR;
				}
				parent = parent->getParentNode();
			}

			return false;
NEXT_PAIR:
			;
		}
	}
	return true;
}

std::list<InterpreterIssue> InterpreterIssue::forInterpreter(InterpreterImpl* interpreter) {
	// some things we need to prepare first
	if (interpreter->_factory == NULL)
		interpreter->_factory = Factory::getInstance();

	std::list<InterpreterIssue> issues;

	try {
		interpreter->setupDOM();
	} catch(Event e) {
		InterpreterIssue issue("Could not setup SCXML DOM: " + e.data.asJSON(), NULL, InterpreterIssue::USCXML_ISSUE_FATAL);
		issues.push_back(issue);
	}

	if (!interpreter->_scxml) {
		InterpreterIssue issue("No SCXML element to be found", NULL, InterpreterIssue::USCXML_ISSUE_FATAL);
		issues.push_back(issue);
		return issues;
	}

	std::map<std::string, DOMElement* > seenStates;

	// get some aliases
	DOMElement* _scxml = interpreter->_scxml;
	Factory* _factory = interpreter->_factory;
	DataModel& _dataModel = interpreter->_dataModel;
	std::string xmlNSPrefix = interpreter->_xmlPrefix;

	std::map<std::string, std::list<DOMElement*> > nodeSets;
	assembleNodeSets(xmlNSPrefix, _scxml, nodeSets);


	std::list<DOMElement*> scxmls = nodeSets["scxml"];
	scxmls.push_back(_scxml);

	std::list<XERCESC_NS::DOMElement*> reachable = getReachableStates(_scxml);

	std::list<DOMElement*>& states = nodeSets["state"];
	std::list<DOMElement*>& parallels = nodeSets["parallel"];
	std::list<DOMElement*>& transitions = nodeSets["transition"];
	std::list<DOMElement*>& initials = nodeSets["initial"];
	std::list<DOMElement*>& finals = nodeSets["final"];
	std::list<DOMElement*>& onEntries = nodeSets["onentry"];
	std::list<DOMElement*>& onExits = nodeSets["onexit"];
	std::list<DOMElement*>& histories = nodeSets["history"];

	std::list<DOMElement*>& raises = nodeSets["raise"];
	std::list<DOMElement*>& ifs = nodeSets["if"];
	std::list<DOMElement*>& elseIfs = nodeSets["elseif"];
	std::list<DOMElement*>& elses = nodeSets["else"];
	std::list<DOMElement*>& foreachs = nodeSets["foreach"];
	std::list<DOMElement*>& logs = nodeSets["log"];

	std::list<DOMElement*>& dataModels = nodeSets["datamodel"];
	std::list<DOMElement*>& datas = nodeSets["data"];
	std::list<DOMElement*>& assigns = nodeSets["assign"];
	std::list<DOMElement*>& doneDatas = nodeSets["donedata"];
	std::list<DOMElement*>& contents = nodeSets["content"];
	std::list<DOMElement*>& params = nodeSets["param"];
	std::list<DOMElement*>& scripts = nodeSets["script"];

	std::list<DOMElement*>& sends = nodeSets["send"];
	std::list<DOMElement*>& cancels = nodeSets["cancel"];
	std::list<DOMElement*>& invokes = nodeSets["invoke"];
	std::list<DOMElement*>& finalizes = nodeSets["finalize"];

	std::list<DOMElement*> allStates;
	allStates.insert(allStates.end(), states.begin(), states.end());
	allStates.insert(allStates.end(), parallels.begin(), parallels.end());
	allStates.insert(allStates.end(), histories.begin(), histories.end());
	allStates.insert(allStates.end(), finals.begin(), finals.end());

	std::list<DOMElement*> allExecContents;
	allExecContents.insert(allExecContents.end(), raises.begin(), raises.end());
	allExecContents.insert(allExecContents.end(), ifs.begin(), ifs.end());
	allExecContents.insert(allExecContents.end(), elseIfs.begin(), elseIfs.end());
	allExecContents.insert(allExecContents.end(), elses.begin(), elses.end());
	allExecContents.insert(allExecContents.end(), foreachs.begin(), foreachs.end());
	allExecContents.insert(allExecContents.end(), logs.begin(), logs.end());
	allExecContents.insert(allExecContents.end(), sends.begin(), sends.end());
	allExecContents.insert(allExecContents.end(), assigns.begin(), assigns.end());
	allExecContents.insert(allExecContents.end(), scripts.begin(), scripts.end());
	allExecContents.insert(allExecContents.end(), cancels.begin(), cancels.end());

	std::list<DOMElement*> allElements;
	allElements.insert(allElements.end(), scxmls.begin(), scxmls.end());
	allElements.insert(allElements.end(), allStates.begin(), allStates.end());
	allElements.insert(allElements.end(), allExecContents.begin(), allExecContents.end());
	allElements.insert(allElements.end(), transitions.begin(), transitions.end());
	allElements.insert(allElements.end(), initials.begin(), initials.end());
	allElements.insert(allElements.end(), onEntries.begin(), onEntries.end());
	allElements.insert(allElements.end(), onExits.begin(), onExits.end());
	allElements.insert(allElements.end(), dataModels.begin(), dataModels.end());
	allElements.insert(allElements.end(), datas.begin(), datas.end());
	allElements.insert(allElements.end(), doneDatas.begin(), doneDatas.end());
	allElements.insert(allElements.end(), contents.begin(), contents.end());
	allElements.insert(allElements.end(), params.begin(), params.end());
	allElements.insert(allElements.end(), invokes.begin(), invokes.end());
	allElements.insert(allElements.end(), finalizes.begin(), finalizes.end());


	std::set<std::string> execContentSet;
	execContentSet.insert("if");
	execContentSet.insert("elseif");
	execContentSet.insert("else");
	execContentSet.insert("foreach");
	execContentSet.insert("raise");
	execContentSet.insert("send");
	execContentSet.insert("cancel");
	execContentSet.insert("assign");
	execContentSet.insert("script");
	execContentSet.insert("log");

	// required attributes per standard
	std::map<std::string, std::set<std::string> > reqAttr;
	reqAttr["scxml"].insert("xmlns");
	reqAttr["scxml"].insert("version");
	reqAttr["raise"].insert("event");
	reqAttr["if"].insert("cond");
	reqAttr["elseif"].insert("cond");
	reqAttr["foreach"].insert("array");
	reqAttr["foreach"].insert("item");
	reqAttr["data"].insert("id");
	reqAttr["assign"].insert("location");
	reqAttr["param"].insert("name");

	// these are the valid children for elements in the SCXML namespace as per specification
	std::map<std::string, std::set<std::string> > validChildren;
	validChildren["scxml"].insert("state");
	validChildren["scxml"].insert("parallel");
	validChildren["scxml"].insert("final");
	validChildren["scxml"].insert("datamodel");
	validChildren["scxml"].insert("script");

	validChildren["state"].insert("onentry");
	validChildren["state"].insert("onexit");
	validChildren["state"].insert("transition");
	validChildren["state"].insert("state");
	validChildren["state"].insert("parallel");
	validChildren["state"].insert("history");
	validChildren["state"].insert("datamodel");
	validChildren["state"].insert("invoke");
	validChildren["state"].insert("initial");
	validChildren["state"].insert("final");

	validChildren["parallel"].insert("onentry");
	validChildren["parallel"].insert("onexit");
	validChildren["parallel"].insert("transition");
	validChildren["parallel"].insert("state");
	validChildren["parallel"].insert("parallel");
	validChildren["parallel"].insert("history");
	validChildren["parallel"].insert("datamodel");
	validChildren["parallel"].insert("invoke");

	validChildren["transition"] = execContentSet;
	validChildren["onentry"] = execContentSet;
	validChildren["onexit"] = execContentSet;
	validChildren["finalize"] = execContentSet;

	validChildren["if"] = execContentSet;
	validChildren["elseif"] = execContentSet;
	validChildren["else"] = execContentSet;
	validChildren["foreach"] = execContentSet;

	validChildren["initial"].insert("transition");
	validChildren["history"].insert("transition");

	validChildren["final"].insert("onentry");
	validChildren["final"].insert("onexit");
	validChildren["final"].insert("donedata");

	validChildren["datamodel"].insert("data");

	validChildren["donedata"].insert("content");
	validChildren["donedata"].insert("param");

	validChildren["send"].insert("content");
	validChildren["send"].insert("param");

	validChildren["invoke"].insert("content");
	validChildren["invoke"].insert("param");
	validChildren["invoke"].insert("finalize");

	// inverse validChildren to validParents
	std::map<std::string, std::set<std::string> > validParents;
	for (std::map<std::string, std::set<std::string> >::iterator parentIter = validChildren.begin(); parentIter != validChildren.end(); parentIter++) {
		for (std::set<std::string>::iterator childIter = parentIter->second.begin(); childIter != parentIter->second.end(); childIter++) {
			validParents[*childIter].insert(parentIter->first);
		}
	}


	for (auto stateIter = allStates.begin(); stateIter != allStates.end(); stateIter++) {
		DOMElement* state = static_cast<DOMElement*>(*stateIter);

		if (DOMUtils::isMember(state, finals) && !HAS_ATTR(state, kXMLCharId)) // id is not required for finals
			continue;

		// check for existance of id attribute - this not actually required!
		if (!HAS_ATTR(state, kXMLCharId)) {
			issues.push_back(InterpreterIssue("State has no 'id' attribute", state, InterpreterIssue::USCXML_ISSUE_FATAL));
			continue;
		}

		if (ATTR(state, kXMLCharId).size() == 0) {
			issues.push_back(InterpreterIssue("State has empty 'id' attribute", state, InterpreterIssue::USCXML_ISSUE_FATAL));
			continue;
		}

		std::string stateId = ATTR(state, kXMLCharId);

		// check for valid transition with history states
		if (LOCALNAME(state) == "history") {
			std::list<DOMElement*> transitions = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "transition", state, false);
			if (transitions.size() > 1) {
				issues.push_back(InterpreterIssue("History pseudo-state with id '" + stateId + "' has multiple transitions", state, InterpreterIssue::USCXML_ISSUE_FATAL));
			} else if (transitions.size() == 0) {
				issues.push_back(InterpreterIssue("History pseudo-state with id '" + stateId + "' has no default transition", state, InterpreterIssue::USCXML_ISSUE_FATAL));
			} else {
				DOMElement* transition = static_cast<DOMElement*>(transitions.front());
				if (HAS_ATTR(transition, kXMLCharCond)) {
					issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' must not have a condition", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
				}
				if (HAS_ATTR(transition, kXMLCharEvent)) {
					issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' must not have an event attribute", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
				}
				if (!HAS_ATTR(transition, kXMLCharTarget)) {
					issues.push_back(InterpreterIssue("Transition in history pseudo-state '" + stateId + "' has no target", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
				} else {
					std::list<DOMElement*> targetStates = getTargetStates(transition, _scxml);
					for (auto tIter = targetStates.begin(); tIter != targetStates.end(); tIter++) {
						DOMElement* target = *tIter;
						if (HAS_ATTR(state, kXMLCharType) && ATTR(state, kXMLCharType) == "deep") {
							if (!DOMUtils::isDescendant(target, state->getParentNode())) {
								issues.push_back(InterpreterIssue("Transition in deep history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, kXMLCharId) + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
							}
						} else {
							if (target->getParentNode() != state->getParentNode()) {
								issues.push_back(InterpreterIssue("Transition in shallow history pseudo-state '" + stateId + "' has illegal target state '" + ATTR(target, kXMLCharId) + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
							}
						}
					}
				}
			}
		}

		// check whether state is reachable
		if (!DOMUtils::isMember(state, reachable) && areFromSameMachine(state, interpreter->_scxml)) {
			issues.push_back(InterpreterIssue("State with id '" + stateId + "' is unreachable", state, InterpreterIssue::USCXML_ISSUE_WARNING));
		}

		// check for uniqueness of id attribute
		if (seenStates.find(stateId) != seenStates.end()) {
			issues.push_back(InterpreterIssue("Duplicate state with id '" + stateId + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL));
			continue;
		}
		seenStates[ATTR(state, kXMLCharId)] = state;
	}

	for (auto tIter = transitions.begin(); tIter != transitions.end(); tIter++) {
		DOMElement* transition = *tIter;

		// check for valid target
		if (HAS_ATTR(transition, kXMLCharTarget)) {
			std::list<std::string> targetIds = tokenize(ATTR(transition, kXMLCharTarget));
			if (targetIds.size() == 0) {
				issues.push_back(InterpreterIssue("Transition has empty target state list", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
			}

			for (std::list<std::string>::iterator targetIter = targetIds.begin(); targetIter != targetIds.end(); targetIter++) {
				if (seenStates.find(*targetIter) == seenStates.end()) {
					issues.push_back(InterpreterIssue("Transition has non-existant target state with id '" + *targetIter + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
					continue;
				}
			}
		}
	}

	// check for redundancy of transition
	for (auto stateIter = allStates.begin(); stateIter != allStates.end(); stateIter++) {
		DOMElement* state = *stateIter;
		std::list<DOMElement*> transitions = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "transition", state, false);

		for (auto tIter = transitions.begin(); tIter != transitions.end(); tIter++) {
			DOMElement* transition = *tIter;
			for (auto t2Iter = transitions.begin(); t2Iter != tIter; t2Iter++) {
				DOMElement* earlierTransition = *t2Iter;

				// will the earlier transition always be enabled when the later is?
				if (!HAS_ATTR(earlierTransition, kXMLCharCond)) {
					// earlier transition has no condition -> check event descriptor
					if (!HAS_ATTR(earlierTransition, kXMLCharEvent)) {
						// earlier transition is eventless
						issues.push_back(InterpreterIssue("Transition can never be optimally enabled", transition, InterpreterIssue::USCXML_ISSUE_INFO));
						goto NEXT_TRANSITION;

					} else if (HAS_ATTR(transition, kXMLCharEvent)) {
						// does the earlier transition match all our events?
						std::list<std::string> events = tokenize(ATTR(transition, kXMLCharEvent));

						bool allMatched = true;
						for (std::list<std::string>::iterator eventIter = events.begin(); eventIter != events.end(); eventIter++) {
							if (!nameMatch(ATTR(earlierTransition, kXMLCharEvent), *eventIter)) {
								allMatched = false;
								break;
							}
						}

						if (allMatched) {
							issues.push_back(InterpreterIssue("Transition can never be optimally enabled", transition, InterpreterIssue::USCXML_ISSUE_INFO));
							goto NEXT_TRANSITION;
						}
					}
				}
			}
NEXT_TRANSITION:
			;
		}
	}

	// check for useless history elements
	{
		for (auto histIter = histories.begin(); histIter != histories.end(); histIter++) {
			DOMElement* history = *histIter;

			if (!history->getParentNode() || history->getParentNode()->getNodeType() != DOMNode::ELEMENT_NODE)
				continue; // syntax check will have catched this

			DOMElement* parent = static_cast<DOMElement*>(history->getParentNode());
			if (isAtomic(parent)) {
				issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, kXMLCharId) + "' in atomic state", history, InterpreterIssue::USCXML_ISSUE_INFO));
				continue;
			}
			std::list<std::set<const DOMElement* > > configs = getAllConfigurations(parent);
			if (configs.size() <= 1) {
				issues.push_back(InterpreterIssue("Useless history '" + ATTR(history, kXMLCharId) + "' in state with single legal configuration", history, InterpreterIssue::USCXML_ISSUE_INFO));
				continue;
			}
		}
	}

	// check for valid initial attribute
	{
		std::list<DOMElement*> withInitialAttr;
		withInitialAttr.insert(withInitialAttr.end(), allStates.begin(), allStates.end());
		withInitialAttr.push_back(_scxml);

		for (auto stateIter = withInitialAttr.begin(); stateIter != withInitialAttr.end(); stateIter++) {
			DOMElement* state = *stateIter;

			if (HAS_ATTR(state, kXMLCharInitial)) {
				std::list<DOMElement*> childs;
				std::list<DOMElement*> tmp;
				tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "state", state, true);
				childs.insert(childs.end(), tmp.begin(), tmp.end());
				tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "parallel", state, true);
				childs.insert(childs.end(), tmp.begin(), tmp.end());
				tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "final", state, true);
				childs.insert(childs.end(), tmp.begin(), tmp.end());
				tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "history", state, true);
				childs.insert(childs.end(), tmp.begin(), tmp.end());

				std::list<std::string> intials = tokenize(ATTR(state, kXMLCharInitial));
				for (std::list<std::string>::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) {
					if (seenStates.find(*initIter) == seenStates.end()) {
						issues.push_back(InterpreterIssue("Initial attribute has invalid target state with id '" + *initIter + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL));
						continue;
					}
					// value of the 'initial' attribute [..] must be descendants of the containing <state> or <parallel> element
					if (!DOMUtils::isMember(seenStates[*initIter], childs)) {
						issues.push_back(InterpreterIssue("Initial attribute references non-child state '" + *initIter + "'", state, InterpreterIssue::USCXML_ISSUE_FATAL));
					}
				}
			}
		}
	}

	// check for legal configuration of target sets
	{
		std::map<DOMElement*, std::string > targetIdSets;
		for (auto iter = transitions.begin(); iter != transitions.end(); iter++) {
			DOMElement* transition = *iter;

			if (HAS_ATTR(transition, kXMLCharTarget)) {
				targetIdSets[transition] = ATTR(transition, kXMLCharTarget);
			}
		}

		for (auto iter = initials.begin(); iter != initials.end(); iter++) {
			DOMElement* initial = *iter;

			if (HAS_ATTR(initial, kXMLCharTarget)) {
				targetIdSets[initial] = ATTR(initial, kXMLCharTarget);
			}
		}

		for (auto iter = allStates.begin(); iter != allStates.end(); iter++) {
			DOMElement* state = *iter;

			if (HAS_ATTR(state, kXMLCharInitial)) {
				targetIdSets[state] = ATTR(state, kXMLCharInitial);
			}
		}

		for (auto setIter = targetIdSets.begin();
		        setIter != targetIdSets.end();
		        setIter++) {
			std::list<DOMElement*> targets;
			std::list<std::string> targetIds = tokenize(setIter->second);
			for (auto tgtIter = targetIds.begin(); tgtIter != targetIds.end(); tgtIter++) {
				if (seenStates.find(*tgtIter) == seenStates.end())
					goto NEXT_SET;
				targets.push_back(seenStates[*tgtIter]);
			}
			if (!hasLegalCompletion(targets)) {
				issues.push_back(InterpreterIssue("Target states cause illegal configuration", setIter->first, InterpreterIssue::USCXML_ISSUE_FATAL));
			}
NEXT_SET:
			;
		}
	}

	// check for valid initial transition
	{
		std::list<DOMElement*> initTrans;

		for (auto iter = initials.begin(); iter != initials.end(); iter++) {
			DOMElement* initial = *iter;

			std::list<DOMElement*> initTransitions = DOMUtils::filterChildElements(XML_PREFIX(initial).str() + "transition", initial, true);
			if (initTransitions.size() != 1) {
				issues.push_back(InterpreterIssue("Initial element must define exactly one transition", initial, InterpreterIssue::USCXML_ISSUE_FATAL));
			}
			initTrans.insert(initTrans.end(), initTransitions.begin(), initTransitions.end());

		}

		for (auto iter = initTrans.begin(); iter != initTrans.end(); iter++) {
			DOMElement* transition = *iter;

			/* In a conformant SCXML document, this transition must not contain 'cond' or 'event' attributes, and must specify a non-null 'target'
			 * whose value is a valid state specification consisting solely of descendants of the containing state
			 */

			if (HAS_ATTR(transition, kXMLCharCond)) {
				issues.push_back(InterpreterIssue("Initial transition cannot have a condition", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
			}
			if (HAS_ATTR(transition, kXMLCharEvent)) {
				issues.push_back(InterpreterIssue("Initial transition cannot be eventful", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
			}

			if (!transition->getParentNode() ||
			        !transition->getParentNode()->getParentNode() ||
			        transition->getParentNode()->getParentNode()->getNodeType() != DOMNode::ELEMENT_NODE)
				continue; // syntax will catch this one
			DOMElement* state = static_cast<DOMElement*>(transition->getParentNode()->getParentNode());
			if (!isState(state))
				continue; // syntax will catch this one

			std::list<DOMElement*> childs;
			std::list<DOMElement*> tmp;
			tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "state", state, true);
			childs.insert(childs.end(), tmp.begin(), tmp.end());
			tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "parallel", state, true);
			childs.insert(childs.end(), tmp.begin(), tmp.end());
			tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "final", state, true);
			childs.insert(childs.end(), tmp.begin(), tmp.end());
			tmp = DOMUtils::filterChildElements(XML_PREFIX(state).str() + "history", state, true);
			childs.insert(childs.end(), tmp.begin(), tmp.end());

			std::list<std::string> intials = tokenize(ATTR(transition, kXMLCharTarget));
			for (std::list<std::string>::iterator initIter = intials.begin(); initIter != intials.end(); initIter++) {
				// the 'target' of a <transition> inside an <initial> or <history> element: all the states must be descendants of the containing <state> or <parallel> element
				if (!DOMUtils::isMember(seenStates[*initIter], childs)) {
					issues.push_back(InterpreterIssue("Target of initial transition references non-child state '" + *initIter + "'", transition, InterpreterIssue::USCXML_ISSUE_FATAL));
				}
			}
		}
	}


	// check that all invokers exists
	{
		for (auto iter = invokes.begin(); iter != invokes.end(); iter++) {
			DOMElement* invoke = *iter;
			if (HAS_ATTR(invoke, kXMLCharType) && !_factory->hasInvoker(ATTR(invoke, kXMLCharType))) {
				// unknown at factory - adhoc extension?
				if (HAS_ATTR(invoke, kXMLCharId) && interpreter->_invokers.find(ATTR(invoke, kXMLCharId)) != interpreter->_invokers.end())
					continue; // not an issue

				IssueSeverity severity;
				if (HAS_ATTR(invoke, kXMLCharIdLocation)) {
					// we might still resolve at runtime
					severity = InterpreterIssue::USCXML_ISSUE_WARNING;
				} else {
					// fatality!
					severity = InterpreterIssue::USCXML_ISSUE_FATAL;
				}
				issues.push_back(InterpreterIssue("Invoke with unknown type '" + ATTR(invoke, kXMLCharType) + "'", invoke, severity));
				continue;
			}
		}
	}

	// check that all io processors exists
	{
		for (auto iter = sends.begin(); iter != sends.end(); iter++) {
			DOMElement* send = *iter;
			if (HAS_ATTR(send, kXMLCharType) && !_factory->hasIOProcessor(ATTR(send, kXMLCharType))) {
				if (interpreter->_ioProcs.find(ATTR(send, kXMLCharType)) != interpreter->_ioProcs.end())
					continue; // not an issue, available ad-hoc

				issues.push_back(InterpreterIssue("Send to unknown IO Processor '" + ATTR(send, kXMLCharType) + "'", send, InterpreterIssue::USCXML_ISSUE_FATAL));
				continue;
			}
		}
	}

	// check that all custom executable content is known
	{
		std::list<DOMElement*> allExecContentContainers;
		allExecContentContainers.insert(allExecContentContainers.end(), onEntries.begin(), onEntries.end());
		allExecContentContainers.insert(allExecContentContainers.end(), onExits.begin(), onExits.end());
		allExecContentContainers.insert(allExecContentContainers.end(), transitions.begin(), transitions.end());
		allExecContentContainers.insert(allExecContentContainers.end(), finalizes.begin(), finalizes.end());

		for (auto bIter = allExecContentContainers.begin(); bIter != allExecContentContainers.end(); bIter++) {
			DOMElement* block = *bIter;
			std::list<DOMNode*> execContents = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, block);
			for (auto ecIter = execContents.begin(); ecIter != execContents.end(); ecIter++) {
				DOMElement* execContent = static_cast<DOMElement*>(*ecIter);
				// SCXML specific executable content, always available
				if (DOMUtils::isMember(execContent, allExecContents)) {
					continue;
				}

				if (!_factory->hasExecutableContent(X(execContent->getLocalName()), X(execContent->getNamespaceURI()))) {
					issues.push_back(InterpreterIssue("Executable content element '" + (std::string)X(execContent->getLocalName()) + "' in namespace '" + (std::string)X(execContent->getNamespaceURI()) + "' unknown", execContent, InterpreterIssue::USCXML_ISSUE_FATAL));
					continue;
				}
			}
		}
	}

	// check that all SCXML elements have valid parents and required attributes
	{
		for (auto iter = allElements.begin(); iter != allElements.end(); iter++) {
			DOMElement* element = *iter;
			std::string localName = LOCALNAME(element);

			if (reqAttr.find(localName) != reqAttr.end()) {
				for (std::set<std::string>::const_iterator reqIter = reqAttr[localName].begin();
				        reqIter != reqAttr[localName].end(); reqIter++) {
					if (!HAS_ATTR(element, X(*reqIter))) {
						issues.push_back(InterpreterIssue("Element " + localName + " is missing required attribute '" + *reqIter + "'", element, InterpreterIssue::USCXML_ISSUE_WARNING));
					}
					if (HAS_ATTR(element, X(*reqIter)) && ATTR(element, X(*reqIter)).size() == 0) {
						issues.push_back(InterpreterIssue("Required attribute '" + *reqIter + "' of element " + localName + " is empty", element, InterpreterIssue::USCXML_ISSUE_WARNING));
					}
				}
			}

			if (localName == "scxml") // can be anywhere: <assign>, <content>, <other:embed>
				continue;

			if (!element->getParentNode() || element->getParentNode()->getNodeType() != DOMNode::ELEMENT_NODE) {
				issues.push_back(InterpreterIssue("Parent of " + localName + " is no element", element, InterpreterIssue::USCXML_ISSUE_WARNING));
				continue;
			}

			DOMElement* parent = static_cast<DOMElement*>(element->getParentNode());
			std::string parentName = LOCALNAME(parent);

			if (validParents[localName].find(parentName) == validParents[localName].end()) {
				issues.push_back(InterpreterIssue("Element " + localName + " can be no child of " + parentName, element, InterpreterIssue::USCXML_ISSUE_WARNING));
				continue;
			}
		}
	}

	// check attribute constraints
	{
		for (auto iter = initials.begin(); iter != initials.end(); iter++) {
			DOMElement* initial = *iter;
			if (initial->getParentNode() && initial->getParentNode()->getNodeType() == DOMNode::ELEMENT_NODE) {
				DOMElement* state = static_cast<DOMElement*>(initial->getParentNode());
				if (HAS_ATTR(state, kXMLCharInitial)) {
					issues.push_back(InterpreterIssue("State with initial attribute cannot have <initial> child ", state, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
				if (isAtomic(state)) {
					issues.push_back(InterpreterIssue("Atomic state cannot have <initial> child ", state, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
		}
		for (auto iter = allStates.begin(); iter != allStates.end(); iter++) {
			DOMElement* state = *iter;
			if (isAtomic(state) && HAS_ATTR(state, kXMLCharInitial)) {
				issues.push_back(InterpreterIssue("Atomic state cannot have initial attribute ", state, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = assigns.begin(); iter != assigns.end(); iter++) {
			DOMElement* assign = *iter;
			if (HAS_ATTR(assign, kXMLCharExpr) && assign->getChildNodes()->getLength() > 0) {
				issues.push_back(InterpreterIssue("Assign element cannot have expr attribute and children", assign, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = contents.begin(); iter != contents.end(); iter++) {
			DOMElement* content = *iter;
			if (HAS_ATTR(content, kXMLCharExpr) && content->getChildNodes()->getLength() > 0) {
				issues.push_back(InterpreterIssue("Content element cannot have expr attribute and children", content, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = params.begin(); iter != params.end(); iter++) {
			DOMElement* param = *iter;
			if (HAS_ATTR(param, kXMLCharExpr) && HAS_ATTR(param, kXMLCharLocation)) {
				issues.push_back(InterpreterIssue("Param element cannot have both expr and location attribute", param, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = scripts.begin(); iter != scripts.end(); iter++) {
			DOMElement* script = *iter;
			if (HAS_ATTR(script, kXMLCharSource) && script->getChildNodes()->getLength() > 0) {
				issues.push_back(InterpreterIssue("Script element cannot have src attribute and children", script, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = sends.begin(); iter != sends.end(); iter++) {
			DOMElement* send = *iter;
			if (HAS_ATTR(send, kXMLCharEvent) && HAS_ATTR(send, kXMLCharEventExpr)) {
				issues.push_back(InterpreterIssue("Send element cannot have both event and eventexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(send, kXMLCharTarget) && HAS_ATTR(send, kXMLCharTargetExpr)) {
				issues.push_back(InterpreterIssue("Send element cannot have both target and targetexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(send, kXMLCharType) && HAS_ATTR(send, kXMLCharTypeExpr)) {
				issues.push_back(InterpreterIssue("Send element cannot have both type and typeexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(send, kXMLCharId) && HAS_ATTR(send, kXMLCharIdLocation)) {
				issues.push_back(InterpreterIssue("Send element cannot have both id and idlocation attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(send, kXMLCharDelay) && HAS_ATTR(send, kXMLCharDelayExpr)) {
				issues.push_back(InterpreterIssue("Send element cannot have both delay and delayexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(send, kXMLCharDelay) && HAS_ATTR(send, kXMLCharTarget) && ATTR(send, kXMLCharTarget)== "_internal") {
				issues.push_back(InterpreterIssue("Send element cannot have delay with target _internal", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}

			std::list<DOMElement*> contentChilds = DOMUtils::filterChildElements(XML_PREFIX(send).str() + "content", send, false);
			std::list<DOMElement*> paramChilds = DOMUtils::filterChildElements(XML_PREFIX(send).str() + "param", send, false);

			if (HAS_ATTR(send, kXMLCharNameList) && contentChilds.size() > 0) {
				issues.push_back(InterpreterIssue("Send element cannot have namelist attribute and content child", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}

			if (paramChilds.size() > 0 && contentChilds.size() > 0) {
				issues.push_back(InterpreterIssue("Send element cannot have param child and content child", send, InterpreterIssue::USCXML_ISSUE_WARNING));
			}

		}
		for (auto iter = cancels.begin(); iter != cancels.end(); iter++) {
			DOMElement* cancel = *iter;
			if (HAS_ATTR(cancel, kXMLCharSendId) && HAS_ATTR(cancel, kXMLCharSendIdExpr)) {
				issues.push_back(InterpreterIssue("Cancel element cannot have both sendid and eventexpr sendidexpr", cancel, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
		}

		for (auto iter = invokes.begin(); iter != invokes.end(); iter++) {
			DOMElement* invoke = *iter;
			if (HAS_ATTR(invoke, kXMLCharType) && HAS_ATTR(invoke, kXMLCharTypeExpr)) {
				issues.push_back(InterpreterIssue("Invoke element cannot have both type and typeexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(invoke, kXMLCharSource) && HAS_ATTR(invoke, kXMLCharSourceExpr)) {
				issues.push_back(InterpreterIssue("Invoke element cannot have both src and srcexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(invoke, kXMLCharId) && HAS_ATTR(invoke, kXMLCharIdLocation)) {
				issues.push_back(InterpreterIssue("Invoke element cannot have both id and idlocation attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(invoke, kXMLCharNameList) && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "param", invoke, false).size() > 0) {
				issues.push_back(InterpreterIssue("Invoke element cannot have namelist attribute and param child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
			}
			if (HAS_ATTR(invoke, kXMLCharSource) && DOMUtils::filterChildElements(XML_PREFIX(invoke).str() + "content", invoke, false).size() > 0) {
				issues.push_back(InterpreterIssue("Invoke element cannot have src attribute and content child", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));

			}
		}
		for (auto iter = doneDatas.begin(); iter != doneDatas.end(); iter++) {
			DOMElement* donedata = *iter;
			if (DOMUtils::filterChildElements(XML_PREFIX(donedata).str() + "content", donedata, false).size() > 0 &&
			        DOMUtils::filterChildElements(XML_PREFIX(donedata).str() + "param", donedata, false).size() > 0) {
				issues.push_back(InterpreterIssue("Donedata element cannot have param child and content child", donedata, InterpreterIssue::USCXML_ISSUE_WARNING));

			}
		}
	}

	// check that the datamodel is known if not already instantiated
	if (!interpreter->_dataModel) {
		if (HAS_ATTR(_scxml, kXMLCharDataModel)) {
			if (!_factory->hasDataModel(ATTR(_scxml, kXMLCharDataModel))) {
				issues.push_back(InterpreterIssue("SCXML document requires unknown datamodel '" + ATTR(_scxml, kXMLCharDataModel) + "'", _scxml, InterpreterIssue::USCXML_ISSUE_FATAL));

				// we cannot even check the rest as we require a datamodel
				return issues;
			}
		}
	}

	bool instantiatedDataModel = false;
	// instantiate datamodel if not explicitly set
	if (!_dataModel) {
		if (HAS_ATTR(_scxml, kXMLCharDataModel)) {
			// might throw
			_dataModel = _factory->createDataModel(ATTR(_scxml, kXMLCharDataModel), interpreter);
			instantiatedDataModel = true;
		} else {
			_dataModel = _factory->createDataModel("null", interpreter);
		}
	}


	// test all scripts for valid syntax
	{
		for (auto iter = scripts.begin(); iter != scripts.end(); iter++) {
			DOMElement* script = *iter;

			if (script->hasChildNodes()) {
				// search for the text node with the actual script
				std::string scriptContent;
				for (DOMNode* child = script->getFirstChild(); child; child = child->getNextSibling()) {
					if (child->getNodeType() == DOMNode::TEXT_NODE || child->getNodeType() == DOMNode::CDATA_SECTION_NODE)
						scriptContent += (std::string)X(child->getNodeValue());
				}

				if (!_dataModel.isValidSyntax(scriptContent)) {
					issues.push_back(InterpreterIssue("Syntax error in script", script, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
		}
	}

	// test the various attributes with datamodel expressions for valid syntax
	{
		std::list<DOMElement*> withCondAttrs;
		withCondAttrs.insert(withCondAttrs.end(), transitions.begin(), transitions.end());
		withCondAttrs.insert(withCondAttrs.end(), ifs.begin(), ifs.end());
		withCondAttrs.insert(withCondAttrs.end(), elseIfs.begin(), elseIfs.end());

		for (auto iter = withCondAttrs.begin(); iter != withCondAttrs.end(); iter++) {
			DOMElement* condAttr = *iter;
			if (HAS_ATTR(condAttr, kXMLCharCond)) {
				if (!_dataModel.isValidSyntax(ATTR(condAttr, kXMLCharCond))) {
					issues.push_back(InterpreterIssue("Syntax error in cond attribute", condAttr, InterpreterIssue::USCXML_ISSUE_WARNING));
					continue;
				}
			}
		}
	}

	{
		std::list<DOMElement*> withExprAttrs;
		withExprAttrs.insert(withExprAttrs.end(), logs.begin(), logs.end());
		withExprAttrs.insert(withExprAttrs.end(), datas.begin(), datas.end());
		withExprAttrs.insert(withExprAttrs.end(), assigns.begin(), assigns.end());
		withExprAttrs.insert(withExprAttrs.end(), contents.begin(), contents.end());
		withExprAttrs.insert(withExprAttrs.end(), params.begin(), params.end());

		for (auto iter = withExprAttrs.begin(); iter != withExprAttrs.end(); iter++) {
			DOMElement* withExprAttr = *iter;
			if (HAS_ATTR(withExprAttr, kXMLCharExpr)) {
				if (DOMUtils::isMember(withExprAttr, datas) || DOMUtils::isMember(withExprAttr, assigns)) {
					if (!_dataModel.isValidSyntax("foo = " + ATTR(withExprAttr, kXMLCharExpr))) { // TODO: this is ECMAScripty!
						issues.push_back(InterpreterIssue("Syntax error in expr attribute", withExprAttr, InterpreterIssue::USCXML_ISSUE_WARNING));
						continue;
					}
				} else {
					if (!_dataModel.isValidSyntax(ATTR(withExprAttr, kXMLCharExpr))) {
						issues.push_back(InterpreterIssue("Syntax error in expr attribute", withExprAttr, InterpreterIssue::USCXML_ISSUE_WARNING));
						continue;
					}
				}
			}
		}
	}

	{
		for (auto iter = foreachs.begin(); iter != foreachs.end(); iter++) {
			DOMElement* foreach = *iter;
			if (HAS_ATTR(foreach, kXMLCharArray)) {
				if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharArray))) {
					issues.push_back(InterpreterIssue("Syntax error in array attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(foreach, kXMLCharItem)) {
				if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharItem))) {
					issues.push_back(InterpreterIssue("Syntax error in item attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(foreach, kXMLCharIndex)) {
				if (!_dataModel.isValidSyntax(ATTR(foreach, kXMLCharIndex))) {
					issues.push_back(InterpreterIssue("Syntax error in index attribute", foreach, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
		}
	}

	{
		for (auto iter = sends.begin(); iter != sends.end(); iter++) {
			DOMElement* send = *iter;
			if (HAS_ATTR(send, kXMLCharEventExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharEventExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in eventexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(send, kXMLCharTargetExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharTargetExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in targetexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(send, kXMLCharTypeExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharTypeExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in typeexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(send, kXMLCharIdLocation)) {
				if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharIdLocation))) {
					issues.push_back(InterpreterIssue("Syntax error in idlocation attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
			if (HAS_ATTR(send, kXMLCharDelayExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(send, kXMLCharDelayExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in delayexpr attribute", send, InterpreterIssue::USCXML_ISSUE_WARNING));
				}
			}
		}

	}

	{
		for (auto iter = invokes.begin(); iter != invokes.end(); iter++) {
			DOMElement* invoke = *iter;
			if (HAS_ATTR(invoke, kXMLCharTypeExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharTypeExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in typeexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
					continue;
				}
			}
			if (HAS_ATTR(invoke, kXMLCharSourceExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharSourceExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in srcexpr attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
					continue;
				}
			}
			if (HAS_ATTR(invoke, kXMLCharIdLocation)) {
				if (!_dataModel.isValidSyntax(ATTR(invoke, kXMLCharIdLocation))) {
					issues.push_back(InterpreterIssue("Syntax error in idlocation attribute", invoke, InterpreterIssue::USCXML_ISSUE_WARNING));
					continue;
				}
			}
		}
	}

	{
		for (auto iter = cancels.begin(); iter != cancels.end(); iter++) {
			DOMElement* cancel = *iter;
			if (HAS_ATTR(cancel, kXMLCharSendIdExpr)) {
				if (!_dataModel.isValidSyntax(ATTR(cancel, kXMLCharSendIdExpr))) {
					issues.push_back(InterpreterIssue("Syntax error in sendidexpr attribute", cancel, InterpreterIssue::USCXML_ISSUE_WARNING));
					continue;
				}
			}
		}
	}

	if (instantiatedDataModel)
		_dataModel = DataModel();

	return issues;
}

std::ostream& operator<< (std::ostream& os, const InterpreterIssue& issue) {
	switch (issue.severity) {
	case InterpreterIssue::USCXML_ISSUE_FATAL:
		os << "Issue (FATAL) ";
		break;
	case InterpreterIssue::USCXML_ISSUE_WARNING:
		os << "Issue (WARNING) ";
		break;
	case InterpreterIssue::USCXML_ISSUE_INFO:
		os << "Issue (INFO) ";
		break;
	default:
		break;
	}

	if (issue.xPath.size() > 0) {
		os << "at " << issue.xPath << ": ";
	} else {
		os << ": ";
	}
	os << issue.message;
	return os;
}


}