Leonardus
Loading...
Searching...
No Matches
interpreter.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include "determinations.h"
21
22// Inc Pure
23#include "dbc.h"
24#include "helper.h"
25
26// Inc Medium
27#include "error.h"
28
29
30class Context;
31class SOF;
32
33
39class Interpreter : protected DbC {
40
43 int startup_nof_ = -1;
45 struct PimplTime;
47 size_t odo_changes_ = 0;
49 std::string iif_{};
52 bool verbose_ = false;
53 bool odo_ = false;
54 bool suppressaec_ = false;
56 size_t maxopeelevel_ = 2;
62
63
66 virtual ~Interpreter();
67
68
70 void help();
71
72
79 static std::string unescape( const std::string & p_s );
80
81
88 void print( const char * p_line );
89
90
93
94
96 void status_statistics();
97
98protected:
99
100#ifndef DBC_IS_VOID
105 bool invariant() const noexcept override { /* LCOV_EXCL_START */
106 if( pimpltime_ == nullptr )
107 return false;
108 if( outf_ == nullptr )
109 return false;
110 return true;
111 } /* LCOV_EXCL_STOP */
112#endif
113
114public:
115
116 Interpreter( const Interpreter& ) = delete;
117 Interpreter( Interpreter&& ) = delete;
118 Interpreter& operator=( const Interpreter& ) = delete;
119 Interpreter& operator=( Interpreter&& ) = delete;
120
121public: /* accessor */
122
125 static auto get() {
126 if( !instance_ ) {
127 instance_ = new (std::nothrow) Interpreter;
128 if( instance_ == nullptr )
129 panicExit( "memory" ); /* LCOV_EXCL_LINE */
130 }
131
132 DBC_POST( instance_ != nullptr );
133 return instance_;
134 }
135
136
138 std::string getIif() const { return iif_; }
139
140
142 int getStartup_nof() const { return startup_nof_; }
143
144
146 bool getVerbose() const { return verbose_; }
147
148
150 void setContext( Context * p_c ) { curctx_ = p_c; }
151
152
154 void setSuppressAEC( bool p_saec ) { suppressaec_ = p_saec; }
155
156
158 bool getSuppressAEC() const { return suppressaec_; }
159
160
162 void setOdo( bool p_odo ) { odo_ = p_odo; }
163
164
166 bool getOdo() const { return odo_; }
167
168
170 size_t getOdoIterations() const { return odo_iterations_; }
171
172
174 size_t getMaxopeelevel() const { return maxopeelevel_; }
175
176
178 size_t getRealprecision() const { return realprecision_; }
179
180
182 void setRealprecision( size_t p_prec ) { realprecision_ = p_prec; }
183
184public: /* other */
185
192 void processLeonLine( std::string & p_line, Context & k );
193
194
200 void print( const std::string & p_line );
201
202
205 static void addchanges( size_t p_allchanges ) {
206 get()->odo_changes_ += p_allchanges;
207 }
208
209
215 static void shutdown();
216
217
225 void startup( int p_argc, char * p_argv[] );
226
227
230 __int128 msec() const;
231
232
243 static void leak_statistics( bool p_force, const std::string & p_fname, int p_nof );
244
245
247 void snap();
248
249};
The context of execution.
Definition context.h:46
Design by contract interface class.
Definition dbc.h:30
Interpreter status.
Definition interpreter.h:39
bool getOdo() const
Getter for odo_.
Definition interpreter.h:166
static void addchanges(size_t p_allchanges)
Add p_allchanges to odo_changes_ counter.
Definition interpreter.h:205
static auto get()
Getter for singleton pointer.
Definition interpreter.h:125
void startup(int p_argc, char *p_argv[])
Interpreter start up IO file handling.
Definition interpreter.cpp:186
virtual ~Interpreter()
Private dtor.
Definition interpreter.cpp:66
static void shutdown()
Shut down.
Definition interpreter.cpp:109
SOF * outf_
Interpreter Property.
Definition interpreter.h:50
void print(const char *p_line)
Wrapper around SOF::writestring().
Definition interpreter.cpp:102
bool odo_
Interpreter Property.
Definition interpreter.h:53
void setContext(Context *p_c)
Setter for current context.
Definition interpreter.h:150
void setRealprecision(size_t p_prec)
Setter for realprecision_.
Definition interpreter.h:182
static Interpreter * instance_
Pointer to the singleton instance or a nullptr.
Definition interpreter.h:41
size_t odo_iterations_
Interpreter Property.
Definition interpreter.h:55
std::string iif_
Interpreter Property.
Definition interpreter.h:49
static void leak_statistics(bool p_force, const std::string &p_fname, int p_nof)
Dumps memory and open files statistical data.
Definition interpreter.cpp:252
bool suppressaec_
Interpreter Property.
Definition interpreter.h:54
size_t maxopeelevel_
Interpreter Property.
Definition interpreter.h:56
void setSuppressAEC(bool p_saec)
Setter for suppressaec_.
Definition interpreter.h:154
Interpreter()
Private ctor.
Definition interpreter.cpp:59
void processLeonLine(std::string &p_line, Context &k)
Processes one line of the leon-format input.
Definition interpreter.cpp:139
size_t odo_changes_
Number of changes applied by odo.
Definition interpreter.h:47
PimplTime * pimpltime_
Structure for opaque pointer pimpltime_.
Definition interpreter.h:46
void snap()
Snapshot of complete Interpreter and Context statistics to Interpreter-outfile.
Definition interpreter.cpp:278
size_t getOdoIterations() const
Getter for odo_iterations_.
Definition interpreter.h:170
void status_statistics()
Dumps various status statistical data.
Definition interpreter.cpp:231
void setOdo(bool p_odo)
Setter for odo_.
Definition interpreter.h:162
size_t realprecision_
Interpreter Property.
Definition interpreter.h:57
bool verbose_
Interpreter Property.
Definition interpreter.h:52
int getStartup_nof() const
Getter for startup_nof_.
Definition interpreter.h:142
bool getSuppressAEC() const
Getter for suppressaec_.
Definition interpreter.h:158
std::string getIif() const
Getter for initial input file.
Definition interpreter.h:138
bool invariant() const noexcept override
Checks class invariants.
Definition interpreter.h:105
size_t getMaxopeelevel() const
Getter for maximum opee level.
Definition interpreter.h:174
bool getVerbose() const
Getter for verbose mode.
Definition interpreter.h:146
size_t getRealprecision() const
Getter for realprecision_.
Definition interpreter.h:178
void help()
Command line help text.
Definition interpreter.cpp:76
Context * curctx_
Access to the current Context.
Definition interpreter.h:44
static std::string unescape(const std::string &p_s)
Unescape string.
Definition interpreter.cpp:117
void property_statistics()
Dumps property statistical data.
Definition interpreter.cpp:241
__int128 msec() const
Milliseconds since program start.
Definition interpreter.cpp:225
int startup_nof_
Number of open files at program startup.
Definition interpreter.h:43
Semantic Object File.
Definition sof.h:36
Helpers for design by contract idioms.
#define DBC_POST(XXX)
Assert for postconditions.
Definition dbc.h:110
Determinations of the compile time constants, which we can not calculate (so far).
constexpr size_t DET_MAXODO
Maximum odo iterations.
Definition determinations.h:36
constexpr size_t DET_REALPRECISION
Initial real precision for output.
Definition determinations.h:39
void panicExit(const char *p_msg1, const char *p_msg2)
Panic exit( EC_PANIC ).
Definition error.cpp:116
Error handling.
Miscellaneous definitions and functions.
Pointer to Implementation for Time.
Definition interpreter.cpp:53