Leonardus
Loading...
Searching...
No Matches
interpreter.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <iostream>
21#include <memory>
22
23// Inc HAA
24#include "dbc.h"
25#include "helper.h"
26#include "error.h"
27
28
29class LineSource;
30class Context;
31
36class Interpreter : protected DbC {
41 struct PimplTime;
43 size_t odo_changes_ = 0;
45 bool verbose_ = false;
46 bool odo_ = false;
47 std::ostream cout_{ std::cout.rdbuf() };
48 size_t odo_iterations_ = 10;
49 size_t maxopeelevel_ = 2;
54
55
58 virtual ~Interpreter();
59
60
62 void help();
63
64
66 static std::string strEscape( const std::string & p_s );
67
68
69protected:
70#ifndef DBC_IS_VOID
75 bool invariant() const noexcept override { /* LCOV_EXCL_START */
76 return pimpltime_ != nullptr;
77 } /* LCOV_EXCL_STOP */
78#endif
79
80
81public:
83 Interpreter( const Interpreter& ) = delete;
84
85
87 Interpreter( Interpreter&& ) = delete;
88
89
91 Interpreter& operator=( const Interpreter& ) = delete;
92
93
96
97
98public: /* accessor */
101 static auto get() {
102 if( !instance_ ) {
103 instance_ = new (std::nothrow) Interpreter;
104 if( instance_ == nullptr )
105 panicExit(); /* LCOV_EXCL_LINE */
106 }
107
108 DBC_POST( instance_ != nullptr );
109 return instance_;
110 }
111
112
114 static Context * getContext();
115
116
118 bool getVerbose() const { return verbose_; }
119
120
122 void setContext( Context * p_c ) { curctx_ = p_c; }
123
124
127 __int128 getClockStart() const;
128
129
131 void setOdo( bool p_odo ) { odo_ = p_odo; }
132
133
135 bool getOdo() const { return odo_; }
136
137
139 size_t getOdoIterations() const { return odo_iterations_; }
140
141
143 size_t getMaxopeelevel() const { return maxopeelevel_; }
144
145
147 std::ostream & getCout() { return cout_; }
148
149
150public: /* other */
154 void leonline( std::string & p_line, Context & k );
155
156
160 bool getLine( std::string & p_line ) const;
161
162
164 static void addchanges( size_t p_allchanges ) {
165 get()->odo_changes_ += p_allchanges;
166 }
167
168
174 static void shutdown();
175
176
179 void commandline( int p_argc, char* p_argv[] );
180
181
183 void property_statistics();
184
185
187 void status_statistics();
188
189
194 static void memory_statistics( bool p_force, std::ostream & p_cout );
195
196
199 void snap();
200};
The context of execution.
Definition context.h:42
Design by contract interface class.
Definition dbc.h:26
Interpreter status.
Definition interpreter.h:36
bool getOdo() const
Getter for odo_.
Definition interpreter.h:135
static void addchanges(size_t p_allchanges)
Add p_allchanges to odo_changes_ counter.
Definition interpreter.h:164
Interpreter(const Interpreter &)=delete
Delete the copy ctor.
static auto get()
Get the singleton pointer.
Definition interpreter.h:101
virtual ~Interpreter()
Private dtor.
Definition interpreter.cpp:64
static void shutdown()
Shut down.
Definition interpreter.cpp:112
static void memory_statistics(bool p_force, std::ostream &p_cout)
Dumps memory statistical data.
Definition interpreter.cpp:240
Interpreter & operator=(Interpreter &&)=delete
Delete move assignement.
bool odo_
Interpreter Property.
Definition interpreter.h:46
bool getLine(std::string &p_line) const
Wrapper around getline to hide input stream.
Definition interpreter.cpp:105
void setContext(Context *p_c)
Setter for current context.
Definition interpreter.h:122
std::ostream cout_
Interpreter Property.
Definition interpreter.h:47
static Interpreter * instance_
Pointer to the singleton instance or a nullptr.
Definition interpreter.h:37
size_t odo_iterations_
Interpreter Property.
Definition interpreter.h:48
static Context * getContext()
Get the current context.
Definition interpreter.cpp:73
static std::string strEscape(const std::string &p_s)
Substitutes double backslashes by single backslashes and sequences backslash + 'n' by the ASCII CR co...
Definition interpreter.cpp:120
__int128 getClockStart() const
Getter for clock start.
Definition interpreter.cpp:81
void leonline(std::string &p_line, Context &k)
Processes one line of the leon-format input.
Definition interpreter.cpp:142
size_t maxopeelevel_
Interpreter Property.
Definition interpreter.h:49
std::ostream & getCout()
Getter for cout_.
Definition interpreter.h:147
Interpreter()
Private ctor.
Definition interpreter.cpp:58
Interpreter(Interpreter &&)=delete
Delete the move ctor.
size_t odo_changes_
Number of changes applied by odo.
Definition interpreter.h:43
PimplTime * pimpltime_
Pointer to implemenation of time functions - opaque pointer.
Definition interpreter.h:42
void commandline(int p_argc, char *p_argv[])
Command line parsing.
Definition interpreter.cpp:183
void snap()
Snapshot of complete Interpreter and Context statistics to Interpreter-cout.
Definition interpreter.cpp:259
size_t getOdoIterations() const
Getter for odo_iterations_.
Definition interpreter.h:139
void status_statistics()
Dumps various status statistical data.
Definition interpreter.cpp:217
void setOdo(bool p_odo)
Setter for odo_.
Definition interpreter.h:131
bool verbose_
Interpreter Property.
Definition interpreter.h:45
LineSource * linesource_
Read from cin or from file.
Definition interpreter.h:40
bool invariant() const noexcept override
Checks class invariants.
Definition interpreter.h:75
size_t getMaxopeelevel() const
Getter for maximum opee level.
Definition interpreter.h:143
bool getVerbose() const
Getter for verbose mode.
Definition interpreter.h:118
void help()
Command line help text.
Definition interpreter.cpp:86
Context * curctx_
Access to the current Context.
Definition interpreter.h:39
void property_statistics()
Dumps property statistical data.
Definition interpreter.cpp:230
Interpreter & operator=(const Interpreter &)=delete
Delete copy assignement.
Abstraction of input channel.
Definition linesource.h:35
Helpers for design by contract idioms.
#define DBC_POST(XXX)
Assert for postconditions.
Definition dbc.h:81
void panicExit()
Panic exit( EC_PANIC ).
Definition error.cpp:106
Error handling.
Miscellaneous definitions and functions.
Pointer to Implementation for Time.
Definition interpreter.cpp:52