Leonardus
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <string_view>
22#include <cstdint>
23#include "determinations.h"
24
25// Inc Pure
26#include "dbc.h"
27#include "helper.h"
28
29// Inc Medium
30#include "counter.h"
31
32// Inc Rich
33#include "sok.h"
34#include "sof.h"
35
36
46class Context : public Counter<Context>, protected DbC {
47
48 bool run_ = true;
49 SOK os_{},
50 es_{},
53 std::string snapLeonline_{};
54 int proclevel_ = 0;
56 int loadlevel_ = 0;
58 int arraynesting_ = 0;
65 uint32_t seed_ = 0;
67protected:
68
69#ifndef DBC_IS_VOID
74 bool invariant() const noexcept override { /* LCOV_EXCL_START */
75 if( proclevel_ < 0 )
76 return false;
77 if( loadlevel_ < 0 )
78 return false;
79 if( inf_ == nullptr )
80 return false;
81 if( outf_ == nullptr )
82 return false;
83 if( ! inf_->isOpen() )
84 return false;
85 if( ! outf_->isOpen() )
86 return false;
87 return arraynesting_ >= 0;
88 } /* LCOV_EXCL_STOP */
89#endif
90
91public:
92
93 constexpr static size_t mindictstack_ = 3;
102 explicit Context( const std::string & p_inf_name );
103
104
105 Context() = delete;
106 Context( const Context & ) = delete;
107 Context( Context && ) = delete;
108 Context & operator=( const Context & ) = delete;
109 Context & operator=( Context && ) = delete;
110
111
114 virtual ~Context();
115
116public: /* accessor */
117
120 SOK & opst() { return os_; }
121
122
125 SOK & exst() { return es_; }
126
127
130 SOK & dist() { return ds_; }
131
132
134 size_t getProclevel() const { return static_cast<size_t>(proclevel_); }
135
136
138 size_t getLoadlevel() const { return static_cast<size_t>(loadlevel_); }
139
140
142 size_t getArraynesting() const { return static_cast<size_t>(arraynesting_); }
143
144
146 size_t getMaxloadlevel() const { return maxloadlevel_; }
147
148
150 bool getInterpreterLoop() const { return run_; }
151
152
154 void stopInterpreterLoop() { run_ = false; }
155
156
158 void setSnapLeonline( const std::string & p_line ) { snapLeonline_ = p_line; }
159
160
162 auto getAngularUnit() const { return angularunit_; }
163
164
166 void setAngularUnit( AngularUnit p_unit ) { angularunit_ = p_unit; }
167
168
170 uint32_t getSeed() const { return seed_; }
171
172
174 void setSeed( uint32_t p_seed ) { seed_ = p_seed; }
175
176public: /* other */
177
180 proclevel_++;
181 DBC_INV;
182 }
183
184
187 proclevel_--;
188 DBC_INV;
189 }
190
191
194 loadlevel_++;
195 DBC_INV;
196 }
197
198
201 loadlevel_--;
202 DBC_INV;
203 }
204
205
209 DBC_INV;
210 }
211
212
216 DBC_INV;
217 }
218
219
224 void print( const std::string & p_line ) {
225 outf_->writestring( p_line );
226
227 DBC_INV;
228 }
229
230
235 void print( std::string_view p_line ) {
236 outf_->writestring( p_line );
237
238 DBC_INV;
239 }
240
241
247 void print( const char * p_line ) {
248 DBC_PRE( p_line != nullptr );
249
250 outf_->writestring( p_line );
251
252 DBC_INV;
253 }
254
255
259 outf_->flush();
260
261 DBC_INV;
262 }
263
264
269 bool readLeonLine( std::string & p_line ) {
271
272 return inf_->readLeonLine( p_line );
273 }
274
275
277 void status_statistics();
278
279
281 void property_statistics();
282
283
285 void stack_statistics();
286
287
290 void pstackdump( const SOK & p_stack );
291
292};
The context of execution.
Definition context.h:46
size_t getLoadlevel() const
Getter for load level.
Definition context.h:138
SOK os_
The operand stack.
Definition context.h:49
uint32_t getSeed() const
Getter for seed_.
Definition context.h:170
void stopInterpreterLoop()
Sets run_ to false.
Definition context.h:154
SOK ds_
The dictionary stack is restricted to dictionary entries.
Definition context.h:51
void decArraynesting()
Decrements array nesting.
Definition context.h:214
void status_statistics()
Dumps a snapshot of the Context state to the output file.
Definition context.cpp:116
uint32_t seed_
Context Property.
Definition context.h:65
virtual ~Context()
Dtor.
Definition context.cpp:81
void stack_statistics()
Dumps a snapshot of stacks to the output file.
Definition context.cpp:126
bool invariant() const noexcept override
Checks class invariants.
Definition context.h:74
SOK & opst()
Access to the operand stack.
Definition context.h:120
SOF * inf_
Context Property.
Definition context.h:61
void property_statistics()
Dumps a snapshot of the Context properties to the output file.
Definition context.cpp:105
bool readLeonLine(std::string &p_line)
Wrapper around SOF::readLeonLine().
Definition context.h:269
size_t getMaxloadlevel() const
Getter for maximum load level.
Definition context.h:146
auto getAngularUnit() const
Getter for angularunit_.
Definition context.h:162
void incProclevel()
Increments the procedure level.
Definition context.h:179
bool run_
Control variable for the interpreter loop.
Definition context.h:48
int loadlevel_
The load level is incemented for ever load_exec() call.
Definition context.h:56
void incArraynesting()
Increments array nesting.
Definition context.h:207
void setAngularUnit(AngularUnit p_unit)
Setter for angularunit_.
Definition context.h:166
size_t getArraynesting() const
Getter for nesting level.
Definition context.h:142
AngularUnit angularunit_
Context Property.
Definition context.h:63
void decLoadlevel()
Decrements load level.
Definition context.h:200
void print(const std::string &p_line)
Wrapper around SOF::writestring().
Definition context.h:224
void print(const char *p_line)
Wrapper around SOF::writestring().
Definition context.h:247
static constexpr size_t mindictstack_
Corresponds with the setup in the ctor.
Definition context.h:93
bool getInterpreterLoop() const
Getter for interpreter loop control variable run_.
Definition context.h:150
void print(std::string_view p_line)
Wrapper around SOF::writestring().
Definition context.h:235
void setSnapLeonline(const std::string &p_line)
Setter for snapLeonline_.
Definition context.h:158
std::string snapLeonline_
For debugging purposes a copy of the current leon-format line.
Definition context.h:53
int arraynesting_
The nesting level is incemented for every array within an array for the bind operator.
Definition context.h:58
void decProclevel()
Decrements the procedure level.
Definition context.h:186
SOK & exst()
Access to the execution stack.
Definition context.h:125
void setSeed(uint32_t p_seed)
Setter for seed_.
Definition context.h:174
void pstackdump(const SOK &p_stack)
A dump of a single stack.
Definition context.cpp:89
SOK & dist()
Access to the dictionary stack.
Definition context.h:130
void flushoutfile()
Wrapper around SOF::flush().
Definition context.h:258
size_t maxloadlevel_
Context Property.
Definition context.h:64
int proclevel_
The process level is incremented for every '{' on input.
Definition context.h:54
SOF * outf_
Context Property.
Definition context.h:62
size_t getProclevel() const
Getter for procedure level.
Definition context.h:134
void incLoadlevel()
Increments load level.
Definition context.h:193
SOK es_
The execution stack.
Definition context.h:50
Counter base class.
Definition counter.h:30
Design by contract interface class.
Definition dbc.h:30
Semantic Object File.
Definition sof.h:36
OpError writestring(const std::string &p_data)
Writes to file.
Definition sof.cpp:133
bool isOpen() const
Checks if the file is open.
Definition sof.h:128
OpError flush()
Flushes the file.
Definition sof.cpp:82
bool readLeonLine(std::string &p_str)
Our std::getline( istream, string ) version.
Definition sof.cpp:168
Semantic Object stacK.
Definition sok.h:49
The class Counter.
Helpers for design by contract idioms.
#define DBC_INV
Assert for invariant checks in member functions.
Definition dbc.h:114
#define DBC_PRE(XXX)
Assert for preconditions.
Definition dbc.h:104
#define DBC_INV_RAII(TT)
Defines an instance of the class DbCRAIIassert<>, which calls the invariant()-function at the return ...
Definition dbc.h:94
Determinations of the compile time constants, which we can not calculate (so far).
constexpr size_t DET_MAXLOADLEVEL
A maximum of nesting load levels of name objects.
Definition determinations.h:42
Miscellaneous definitions and functions.
AngularUnit
Angular Unit for trigonometric functions.
Definition helper.h:71
@ DEG
degree.
@ D
SOD.
The class SOF - file object.
The class SOK - semantik object stack.