summaryrefslogtreecommitdiffstats
path: root/src/uscxml/transform/ChartToPromela.h
blob: b8b513e96a0625a6e5505b49b0a4c364d0ceeeba (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
/**
 *  @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
 */

#ifndef CHARTTOPROMELA_H_RP48RFDJ
#define CHARTTOPROMELA_H_RP48RFDJ

#include "Transformer.h"
#include "ChartToC.h"
#include "uscxml/util/DOM.h"

#include "promela/PromelaInlines.h"
#include "promela/PromelaCodeAnalyzer.h"

#include <ostream>

namespace uscxml {

class USCXML_API ChartToPromela : public ChartToC {
public:
	virtual ~ChartToPromela();
	static Transformer transform(const Interpreter& other);

	void writeTo(std::ostream& stream);

protected:
	ChartToPromela(const Interpreter& other) : ChartToC(other) {
        _prefix = "U" + _md5.substr(0, 8) + "_";
    }

	void writeTransitions(std::ostream& stream);
	void writeStates(std::ostream& stream);
    
    void writeCommonTypeDefs(std::ostream& stream);
    void writeCommonVariables(std::ostream& stream);
    void writeTypeDefs(std::ostream& stream);
    void writeVariables(std::ostream& stream);

//  void writeTypeDefs(std::ostream& stream);
//	void writeTypes(std::ostream& stream);
	void writeMacros(std::ostream& stream);
	void writeFSM(std::ostream& stream);
    void writeFSMDequeueEvent(std::ostream& stream);
//    void writeFSMRescheduleMachines(std::ostream& stream);
//    void writeFSMMacrostep(std::ostream& stream);
//    void writeFSMDequeueInternalOrSpontaneousEvent(std::ostream& stream);
    void writeFSMSelectTransitions(std::ostream& stream);
    void writeFSMRememberHistory(std::ostream& stream);
    void writeFSMEstablishEntrySet(std::ostream& stream);
    void writeFSMExitStates(std::ostream& stream);
    void writeFSMTakeTransitions(std::ostream& stream);
    void writeFSMEnterStates(std::ostream& stream);
    void writeFSMTerminateMachine(std::ostream& stream);

	void writeExecContent(std::ostream& stream, const XERCESC_NS::DOMNode* node, size_t indent = 0);
    void writeRaiseDoneDate(std::ostream& stream, const XERCESC_NS::DOMElement* donedata, size_t indent = 0);

    void writeStrings(std::ostream& stream);

    void writeCancelEvents(std::ostream& stream, int indent = 0);
    void writeScheduleMachines(std::ostream& stream, int indent = 0);
    void writeDetermineShortestDelay(std::ostream& stream, int indent = 0);
    void writeRescheduleProcess(std::ostream& stream, int indent = 0);
    void writeInsertWithDelay(std::ostream& stream, int indent = 0);
    void writeAdvanceTime(std::ostream& stream, int indent = 0);
    void writeRemovePendingEventsFromInvoker(std::ostream& stream, int indent = 0);

    void prepare();
    
    void writeBitClearMacro(std::ostream& stream);
    void writeBitHasAndMacro(std::ostream& stream);
    void writeBitHasAnyMacro(std::ostream& stream);
    void writeBitOrMacro(std::ostream& stream);
    void writeBitCopyMacro(std::ostream& stream);
    void writeBitAndMacro(std::ostream& stream);
    void writeBitAndNotMacro(std::ostream& stream);

	void printBitArray(std::ostream& stream,
	                   const std::string& array,
	                   size_t length,
	                   size_t indent = 0);

	PromelaCodeAnalyzer* _analyzer = NULL;

	ChartToPromela* _parentTopMost = NULL;
	ChartToPromela* _parent = NULL;
	std::string _invokerid;

    size_t _internalQueueLength = 7;
    size_t _externalQueueLength = 7;
    bool _allowEventInterleaving = false;
    
	std::map<std::string, XERCESC_NS::DOMElement* > _machinesPerId;
	std::map<std::string, XERCESC_NS::DOMElement* >* _machinesAllPerId = NULL;
	std::map<XERCESC_NS::DOMElement*, ChartToPromela*> _machinesNested;
	std::map<XERCESC_NS::DOMElement*, ChartToPromela*>* _machinesAll = NULL;

	std::set<std::string> _dataModelVars;
    std::list<std::string> _varInitializers; // pending initializations for arrays

	std::string beautifyIndentation(const std::string& code, size_t indent = 0);
	void writeIfBlock(std::ostream& stream, std::list<XERCESC_NS::DOMElement*>& condChain, size_t indent = 0);

	std::string dataToAssignments(const std::string& prefix, const Data& data);
	std::string sanitizeCode(const std::string& code);
	std::string declForRange(const std::string& identifier, long minValue, long maxValue, bool nativeOnly = false);

	friend class PromelaCodeAnalyzer;
};

}

#endif /* end of include guard: CHARTTOPROMELA_H_RP48RFDJ */