Skip to content

Commit 13c003b

Browse files
Merge pr #33: renamed basic data structures and methods towards modernization
Renamed basic data structures like createFrame and toString
2 parents c0b830d + 727abcd commit 13c003b

23 files changed

Lines changed: 437 additions & 474 deletions

include/utap/StatementBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace UTAP
4242
* The \a params frame is used temporarily during parameter
4343
* parsing.
4444
*/
45-
frame_t params{frame_t::createFrame()};
45+
frame_t params{frame_t::create()};
4646

4747
/** The function currently being parsed. */
4848
function_t* currentFun{nullptr};

include/utap/document.h

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ namespace UTAP
5151
*/
5252
struct variable_t
5353
{
54-
symbol_t uid; /**< The symbol of the variables */
55-
expression_t expr; /**< The initialiser */
56-
std::string toString() const;
54+
symbol_t uid; /**< The symbol of the variable */
55+
expression_t init; /**< The initializer */
56+
std::string str() const; /**< computes a string representation */
5757
};
5858

5959
/** Information about a location.
@@ -62,15 +62,15 @@ namespace UTAP
6262
is generated by the type checker; until then the rate
6363
expressions are part of the invariant.
6464
*/
65-
struct state_t
65+
struct location_t
6666
{
6767
symbol_t uid; /**< The symbol of the location */
6868
expression_t name; /**< TODO: the location name with its position */
6969
expression_t invariant; /**< The invariant */
7070
expression_t exponentialRate;
7171
expression_t costRate; /**< Rate expression */
72-
int32_t locNr; /**< Location number in template */
73-
std::string toString() const;
72+
int32_t nr; /**< Location number in a template */
73+
std::string str() const;
7474
};
7575

7676
/** Information about a branchpoint.
@@ -95,16 +95,16 @@ namespace UTAP
9595
int nr; /**< Placement in input file */
9696
bool control; /**< Controllable (true/false) */
9797
std::string actname;
98-
state_t* src; /**< Pointer to source location */
98+
location_t* src; /**< Pointer to source location */
9999
branchpoint_t* srcb; /**< Pointer to source branchpoint */
100-
state_t* dst; /**< Pointer to destination location */
100+
location_t* dst; /**< Pointer to destination location */
101101
branchpoint_t* dstb; /**< Pointer to destination branchpoint */
102102
frame_t select; /**< Frame for non-deterministic select */
103103
expression_t guard; /**< The guard */
104104
expression_t assign; /**< The assignment */
105105
expression_t sync; /**< The synchronisation */
106106
expression_t prob; /**< Probability for probabilistic edges. */
107-
std::string toString() const;
107+
std::string str() const;
108108
std::vector<int32_t> selectValues; /**<The select values, if any */
109109
};
110110

@@ -118,10 +118,10 @@ namespace UTAP
118118
symbol_t uid; /**< The symbol of the function. */
119119
std::set<symbol_t> changes{}; /**< Variables changed by this function. */
120120
std::set<symbol_t> depends{}; /**< Variables the function depends on. */
121-
std::list<variable_t> variables{}; /**< Local variables. */
121+
std::list<variable_t> variables{}; /**< Local variables. List is used for stable pointers. */
122122
std::unique_ptr<BlockStatement> body{nullptr}; /**< Pointer to the block. */
123123
function_t() = default;
124-
std::string toString() const; // used to write the XML file
124+
std::string str() const; /**< string representation, used to write the XML file */
125125
};
126126

127127
struct progress_t
@@ -167,7 +167,7 @@ namespace UTAP
167167
struct declarations_t
168168
{
169169
frame_t frame;
170-
std::list<variable_t> variables; /**< Variables */
170+
std::list<variable_t> variables; /**< Variables. List is used for stable pointers. */
171171
std::list<function_t> functions; /**< Functions */
172172
std::list<progress_t> progress; /**< Progress measures */
173173
std::list<iodecl_t> iodecl;
@@ -176,7 +176,7 @@ namespace UTAP
176176
/** Add function declaration. */
177177
bool addFunction(type_t type, std::string name, position_t, function_t*&);
178178
/** The following methods are used to write the declarations in an XML file */
179-
std::string toString(bool global = false) const;
179+
std::string str(bool global = false) const;
180180
std::string getConstants() const;
181181
std::string getTypeDefinitions() const;
182182
std::string getVariables(bool global) const;
@@ -198,7 +198,7 @@ namespace UTAP
198198
expression_t label; /**< The label */
199199
bool isInPrechart{};
200200
int get_nr() const { return nr; }
201-
message_t() = default;
201+
bool empty() const { return nr == -1; }
202202
};
203203
/** Information about a condition. Conditions have an anchor instance lines.
204204
* The label is stored as an expression.
@@ -207,12 +207,12 @@ namespace UTAP
207207
{
208208
int nr{-1}; /**< Placement in input file */
209209
int location{-1};
210-
std::vector<instanceLine_t*> anchors{}; /**< Pointer to anchor instance lines */ // TODO
211-
expression_t label; /**< The label */
210+
std::vector<instanceLine_t*> anchors{}; /**< Pointer to anchor instance lines */
211+
expression_t label; /**< The label */
212212
bool isInPrechart{false};
213213
bool isHot{false};
214214
int get_nr() const { return nr; }
215-
condition_t() = default;
215+
bool empty() const { return nr == -1; }
216216
};
217217

218218
/** Information about an update. Update have an anchor instance line.
@@ -225,8 +225,8 @@ namespace UTAP
225225
instanceLine_t* anchor{nullptr}; /**< Pointer to anchor instance line */
226226
expression_t label; /**< The label */
227227
bool isInPrechart{};
228-
update_t() = default;
229228
int get_nr() const { return nr; }
229+
bool empty() const { return nr == -1; }
230230
};
231231

232232
struct simregion_t
@@ -253,8 +253,10 @@ namespace UTAP
253253
delete update;
254254
}
255255

256-
std::string toString() const;
257-
256+
std::string str() const;
257+
bool has_message() const { return message != nullptr && !message->empty(); }
258+
bool has_condition() const { return condition != nullptr && !condition->empty(); }
259+
bool has_update() const { return update != nullptr && !update->empty(); }
258260
void setMessage(std::deque<message_t>& messages, int nr);
259261
void setCondition(std::deque<condition_t>& conditions, int nr);
260262
void setUpdate(std::deque<update_t>& updates, int nr);
@@ -289,11 +291,13 @@ namespace UTAP
289291

290292
bool equals(const cut_t& y) const;
291293

292-
std::string toString() const
294+
std::string str() const
293295
{
294296
std::string s = "CUT(";
295-
for (unsigned int i = 0; i < simregions.size(); ++i)
296-
s += simregions[i].toString() + " ";
297+
for (unsigned int i = 0; i < simregions.size(); ++i) {
298+
s += simregions[i].str();
299+
s += " ";
300+
}
297301
s = s.substr(0, s.size() - 1);
298302
s += ")";
299303
return s;
@@ -357,7 +361,7 @@ namespace UTAP
357361
{
358362
symbol_t init; /**< The initial location */
359363
frame_t templateset; /**< Template set decls */
360-
std::deque<state_t> states; /**< Locations */
364+
std::deque<location_t> locations; /**< Locations */
361365
std::deque<branchpoint_t> branchpoints; /**< Branchpoints */
362366
std::deque<edge_t> edges; /**< Edges */
363367
std::vector<expression_t> dynamicEvals;
@@ -372,7 +376,7 @@ namespace UTAP
372376
std::vector<expression_t>& getDynamicEval() { return dynamicEvals; }
373377

374378
/** Add another location to template. */
375-
state_t& addLocation(const std::string& name, expression_t inv, expression_t er, position_t pos);
379+
location_t& addLocation(const std::string& name, expression_t inv, expression_t er, position_t pos);
376380

377381
/** Add another branchpoint to template. */
378382
branchpoint_t& addBranchpoint(const std::string&, position_t);
@@ -430,7 +434,7 @@ namespace UTAP
430434
expression_t head; //!< First expression in priority declaration
431435
tail_t tail; //!< Pairs: separator and channel expressions
432436

433-
std::string toString() const;
437+
std::string str() const;
434438
};
435439

436440
enum class expectation_type { Symbolic, Probability, NumericValue, _ErrorValue };
@@ -492,7 +496,7 @@ namespace UTAP
492496
virtual void visitVariable(variable_t&) {}
493497
virtual bool visitTemplateBefore(template_t&) { return true; }
494498
virtual void visitTemplateAfter(template_t&) {}
495-
virtual void visitState(state_t&) {}
499+
virtual void visitLocation(location_t&) {}
496500
virtual void visitEdge(edge_t&) {}
497501
virtual void visitInstance(instance_t&) {}
498502
virtual void visitProcess(instance_t&) {}

include/utap/expression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace UTAP
133133
Constants::synchronisation_t getSync() const;
134134

135135
/** Returns a string representation of the expression. */
136-
std::string toString(bool old = false) const;
136+
std::string str(bool old = false) const;
137137

138138
/** Returns the ith subexpression. */
139139
expression_t& operator[](uint32_t);
@@ -245,11 +245,11 @@ namespace UTAP
245245

246246
// true if empty or equal to 1.
247247
bool isTrue() const;
248-
friend std::ostream& operator<<(std::ostream& o, const UTAP::expression_t& e) { return o << e.toString(); }
248+
friend std::ostream& operator<<(std::ostream& o, const UTAP::expression_t& e) { return o << e.str(); }
249249

250250
private:
251251
int getPrecedence() const;
252-
void toString(bool, char*& str, char*& end, int& size) const;
252+
void str(bool, char*& str, char*& end, int& size) const;
253253
void appendBoundType(char*& str, char*& end, int& size, expression_t e) const;
254254
};
255255

include/utap/featurechecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace UTAP
4040
void visitEdge(edge_t& edge) override;
4141
void visitAssignment(expression_t& ass);
4242
void visitGuard(expression_t& guard);
43-
void visitState(state_t& state) override;
43+
void visitLocation(location_t& state) override;
4444

4545
void visitFrame(const frame_t& frame);
4646
bool isRateDisallowedInSymbolic(const expression_t& e);

include/utap/position.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace UTAP
107107
error_t(line_t start, line_t end, position_t pos, std::string msg, std::string ctx = {}):
108108
start{std::move(start)}, end{std::move(end)}, position{pos}, msg{std::move(msg)}, context{std::move(ctx)}
109109
{}
110-
std::string toString() const;
110+
std::string str() const;
111111
};
112112
} // namespace UTAP
113113

include/utap/statement.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace UTAP
3838
virtual ~Statement() noexcept = default;
3939
virtual int32_t accept(StatementVisitor* visitor) = 0;
4040
virtual bool returns() = 0;
41-
virtual std::string toString(const std::string& prefix) const = 0;
41+
virtual std::string str(const std::string& prefix) const = 0;
4242

4343
protected:
4444
Statement() = default;
@@ -50,7 +50,7 @@ namespace UTAP
5050
EmptyStatement() = default;
5151
int32_t accept(StatementVisitor* visitor) override;
5252
bool returns() override;
53-
std::string toString(const std::string& prefix) const override;
53+
std::string str(const std::string& prefix) const override;
5454
};
5555

5656
class ExprStatement : public Statement
@@ -60,7 +60,7 @@ namespace UTAP
6060
explicit ExprStatement(expression_t expr): expr{std::move(expr)} {}
6161
int32_t accept(StatementVisitor* visitor) override;
6262
bool returns() override;
63-
std::string toString(const std::string& prefix) const override;
63+
std::string str(const std::string& prefix) const override;
6464
};
6565

6666
class AssertStatement : public Statement
@@ -70,7 +70,7 @@ namespace UTAP
7070
explicit AssertStatement(expression_t expr): expr{std::move(expr)} {}
7171
int32_t accept(StatementVisitor* visitor) override;
7272
bool returns() override;
73-
std::string toString(const std::string& prefix) const override;
73+
std::string str(const std::string& prefix) const override;
7474
};
7575

7676
class ForStatement : public Statement
@@ -83,7 +83,7 @@ namespace UTAP
8383
ForStatement(expression_t, expression_t, expression_t, std::unique_ptr<Statement>);
8484
int32_t accept(StatementVisitor* visitor) override;
8585
bool returns() override;
86-
std::string toString(const std::string& prefix) const override;
86+
std::string str(const std::string& prefix) const override;
8787
};
8888

8989
/**
@@ -103,7 +103,7 @@ namespace UTAP
103103
frame_t getFrame() { return frame; }
104104
int32_t accept(StatementVisitor* visitor) override;
105105
bool returns() override;
106-
std::string toString(const std::string& prefix) const override;
106+
std::string str(const std::string& prefix) const override;
107107
};
108108

109109
class WhileStatement : public Statement
@@ -114,7 +114,7 @@ namespace UTAP
114114
WhileStatement(expression_t, std::unique_ptr<Statement>);
115115
int32_t accept(StatementVisitor* visitor) override;
116116
bool returns() override;
117-
std::string toString(const std::string& prefix) const override;
117+
std::string str(const std::string& prefix) const override;
118118
};
119119

120120
class DoWhileStatement : public Statement
@@ -125,7 +125,7 @@ namespace UTAP
125125
DoWhileStatement(std::unique_ptr<Statement>, expression_t);
126126
int32_t accept(StatementVisitor* visitor) override;
127127
bool returns() override;
128-
std::string toString(const std::string& prefix) const override;
128+
std::string str(const std::string& prefix) const override;
129129
};
130130

131131
class BlockStatement : public Statement, public declarations_t
@@ -152,7 +152,7 @@ namespace UTAP
152152
bool empty() const { return stats.empty(); }
153153
iterator begin();
154154
iterator end();
155-
std::string toString(const std::string& prefix) const override;
155+
std::string str(const std::string& prefix) const override;
156156
};
157157

158158
class ExternalBlockStatement : public BlockStatement
@@ -176,7 +176,7 @@ namespace UTAP
176176
SwitchStatement(frame_t frame, expression_t expr): BlockStatement{std::move(frame)}, cond{std::move(expr)} {}
177177
int32_t accept(StatementVisitor* visitor) override;
178178
bool returns() override;
179-
std::string toString(const std::string& prefix) const override;
179+
std::string str(const std::string& prefix) const override;
180180
};
181181

182182
class CaseStatement : public BlockStatement
@@ -186,7 +186,7 @@ namespace UTAP
186186
CaseStatement(frame_t frame, expression_t expr): BlockStatement{std::move(frame)}, cond{std::move(expr)} {}
187187
int32_t accept(StatementVisitor* visitor) override;
188188
bool returns() override;
189-
std::string toString(const std::string& prefix) const override;
189+
std::string str(const std::string& prefix) const override;
190190
};
191191

192192
class DefaultStatement : public BlockStatement
@@ -206,7 +206,7 @@ namespace UTAP
206206
IfStatement(expression_t, std::unique_ptr<Statement>, std::unique_ptr<Statement> falseStat = nullptr);
207207
int32_t accept(StatementVisitor* visitor) override;
208208
bool returns() override;
209-
std::string toString(const std::string& prefix) const override;
209+
std::string str(const std::string& prefix) const override;
210210
};
211211

212212
class BreakStatement : public Statement
@@ -215,7 +215,7 @@ namespace UTAP
215215
BreakStatement() = default;
216216
int32_t accept(StatementVisitor* visitor) override;
217217
bool returns() override;
218-
std::string toString(const std::string& prefix) const override;
218+
std::string str(const std::string& prefix) const override;
219219
};
220220

221221
class ContinueStatement : public Statement
@@ -224,7 +224,7 @@ namespace UTAP
224224
ContinueStatement() = default;
225225
int32_t accept(StatementVisitor* visitor) override;
226226
bool returns() override;
227-
std::string toString(const std::string& prefix) const override;
227+
std::string str(const std::string& prefix) const override;
228228
};
229229

230230
class ReturnStatement : public Statement
@@ -235,7 +235,7 @@ namespace UTAP
235235
explicit ReturnStatement(expression_t expr): value{std::move(expr)} {}
236236
int32_t accept(StatementVisitor* visitor) override;
237237
bool returns() override;
238-
std::string toString(const std::string& prefix) const override;
238+
std::string str(const std::string& prefix) const override;
239239
};
240240

241241
class StatementVisitor

include/utap/symbols.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ namespace UTAP
209209
frame_t getParent() const;
210210

211211
/** Returns true if this frame has a parent */
212-
bool hasParent() const;
212+
bool has_parent() const;
213213

214214
/** Creates and returns a new root-frame. */
215-
static frame_t createFrame();
215+
static frame_t create();
216216

217217
/** Creates and returns a new sub-frame. */
218-
static frame_t createFrame(const frame_t& parent);
218+
static frame_t create(const frame_t& parent);
219219
};
220220
} // namespace UTAP
221221

include/utap/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace UTAP
182182
std::pair<expression_t, expression_t> getRange() const;
183183

184184
/** Generates string representation of the type. */
185-
std::string toString() const;
185+
std::string str() const;
186186

187187
std::string toDeclarationString() const;
188188

0 commit comments

Comments
 (0)