Leonardus
Loading...
Searching...
No Matches
interpreter.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <memory>
21
22// Inc HAA
23#include "dbc.h"
24#include "helper.h"
25#include "error.h"
26
27
28class Context;
29class SOF;
30
31
37class Interpreter : protected DbC {
38
41 int startup_nof_ = -1;
43 struct PimplTime;
45 size_t odo_changes_ = 0;
47 std::string iif_{};
50 bool verbose_ = false;
51 bool odo_ = false;
52 bool suppressaec_ = false;
53 size_t odo_iterations_ = 10;
54 size_t maxopeelevel_ = 2;
55 size_t realprecision_ = 10;
60
61
64 virtual ~Interpreter();
65
66
68 void help() const;
69
70
77 static std::string unescape( const std::string & p_s );
78
79
81 void property_statistics() const;
82
83
85 void status_statistics() const;
86
87
88protected:
89#ifndef DBC_IS_VOID
94 bool invariant() const noexcept override { /* LCOV_EXCL_START */
95 if( pimpltime_ == nullptr )
96 return false;
97 if( outf_ == nullptr )
98 return false;
99 return true;
100 } /* LCOV_EXCL_STOP */
101#endif
102
103
104public:
105 Interpreter( const Interpreter& ) = delete;
106 Interpreter( Interpreter&& ) = delete;
107 Interpreter& operator=( const Interpreter& ) = delete;
108 Interpreter& operator=( Interpreter&& ) = delete;
109
110
111public: /* accessor */
114 static auto get() {
115 if( !instance_ ) {
116 instance_ = new (std::nothrow) Interpreter;
117 if( instance_ == nullptr )
118 panicExit( "memory" ); /* LCOV_EXCL_LINE */
119 }
120
121 DBC_POST( instance_ != nullptr );
122 return instance_;
123 }
124
125
127 std::string getIif() const { return iif_; }
128
129
131 int getStartup_nof() const { return startup_nof_; }
132
133
135 bool getVerbose() const { return verbose_; }
136
137
139 void setContext( Context * p_c ) { curctx_ = p_c; }
140
141
143 void setSuppressAEC( bool p_saec ) { suppressaec_ = p_saec; }
144
145
147 bool getSuppressAEC() const { return suppressaec_; }
148
149
151 void setOdo( bool p_odo ) { odo_ = p_odo; }
152
153
155 bool getOdo() const { return odo_; }
156
157
159 size_t getOdoIterations() const { return odo_iterations_; }
160
161
163 size_t getMaxopeelevel() const { return maxopeelevel_; }
164
165
167 size_t getRealprecision() const { return realprecision_; }
168
169
171 void setRealprecision( size_t p_prec ) { realprecision_ = p_prec; }
172
173
174public: /* other */
181 void processLeonLine( std::string & p_line, Context & k ) const;
182
183
186 void print( const std::string & p_line ) const;
187
188
191 void print( std::string_view p_line ) const;
192
193
196 static void addchanges( size_t p_allchanges ) {
197 get()->odo_changes_ += p_allchanges;
198 }
199
200
206 static void shutdown();
207
208
216 void startup( int p_argc, char * p_argv[] );
217
218
221 __int128 msec() const;
222
223
234 static void leak_statistics( bool p_force, const std::string & p_fname, int p_nof );
235
236
238 void snap();
239
240
243 if( verbose_ )
244 snap();
245 }
246};
The context of execution.
Definition context.h:45
Design by contract interface class.
Definition dbc.h:30
Interpreter status.
Definition interpreter.h:37
bool getOdo() const
Getter for odo_.
Definition interpreter.h:155
static void addchanges(size_t p_allchanges)
Add p_allchanges to odo_changes_ counter.
Definition interpreter.h:196
static auto get()
Getter for singleton pointer.
Definition interpreter.h:114
void startup(int p_argc, char *p_argv[])
Interpreter start up IO file handling.
Definition interpreter.cpp:176
void processLeonLine(std::string &p_line, Context &k) const
Processes one line of the leon-format input.
Definition interpreter.cpp:134
virtual ~Interpreter()
Private dtor.
Definition interpreter.cpp:63
static void shutdown()
Shut down.
Definition interpreter.cpp:104
SOF * outf_
Interpreter Property.
Definition interpreter.h:48
void property_statistics() const
Dumps property statistical data.
Definition interpreter.cpp:231
bool odo_
Interpreter Property.
Definition interpreter.h:51
void setContext(Context *p_c)
Setter for current context.
Definition interpreter.h:139
void help() const
Command line help text.
Definition interpreter.cpp:73
void setRealprecision(size_t p_prec)
Setter for realprecision_.
Definition interpreter.h:171
static Interpreter * instance_
Pointer to the singleton instance or a nullptr.
Definition interpreter.h:39
size_t odo_iterations_
Interpreter Property.
Definition interpreter.h:53
std::string iif_
Interpreter Property.
Definition interpreter.h:47
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:242
bool suppressaec_
Interpreter Property.
Definition interpreter.h:52
size_t maxopeelevel_
Interpreter Property.
Definition interpreter.h:54
void setSuppressAEC(bool p_saec)
Setter for suppressaec_.
Definition interpreter.h:143
void status_statistics() const
Dumps various status statistical data.
Definition interpreter.cpp:221
Interpreter()
Private ctor.
Definition interpreter.cpp:56
size_t odo_changes_
Number of changes applied by odo.
Definition interpreter.h:45
PimplTime * pimpltime_
Structure for opaque pointer pimpltime_.
Definition interpreter.h:44
void snap()
Snapshot of complete Interpreter and Context statistics to Interpreter-outfile.
Definition interpreter.cpp:268
size_t getOdoIterations() const
Getter for odo_iterations_.
Definition interpreter.h:159
void setOdo(bool p_odo)
Setter for odo_.
Definition interpreter.h:151
size_t realprecision_
Interpreter Property.
Definition interpreter.h:55
bool verbose_
Interpreter Property.
Definition interpreter.h:50
int getStartup_nof() const
Getter for startup_nof_.
Definition interpreter.h:131
bool getSuppressAEC() const
Getter for suppressaec_.
Definition interpreter.h:147
std::string getIif() const
Getter for initial input file.
Definition interpreter.h:127
void snapIfVerbose()
Snapshot if verbose mode is enabled.
Definition interpreter.h:242
bool invariant() const noexcept override
Checks class invariants.
Definition interpreter.h:94
size_t getMaxopeelevel() const
Getter for maximum opee level.
Definition interpreter.h:163
bool getVerbose() const
Getter for verbose mode.
Definition interpreter.h:135
size_t getRealprecision() const
Getter for realprecision_.
Definition interpreter.h:167
Context * curctx_
Access to the current Context.
Definition interpreter.h:42
static std::string unescape(const std::string &p_s)
Unescape string.
Definition interpreter.cpp:112
void print(const std::string &p_line) const
Wrapper around SOF::writestring().
Definition interpreter.cpp:99
__int128 msec() const
Milliseconds since program start.
Definition interpreter.cpp:215
int startup_nof_
Number of open files at program startup.
Definition interpreter.h:41
Semantic Object File.
Definition sof.h:35
Helpers for design by contract idioms.
#define DBC_POST(XXX)
Assert for postconditions.
Definition dbc.h:109
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:50