Leonardus
interpreter.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <iostream>
20#include <memory>
21
22#include "dbc.h"
23#include "helper.h"
24#include "error.h"
25
26class LineSource;
27class Context;
28
33class Interpreter : protected DbC {
38 struct PimplTime;
40 size_t odo_changes_ = 0;
42 bool verbose_ = false;
43 bool odo_ = false;
44 std::ostream cout_{ std::cout.rdbuf() };
45 size_t odo_iterations_ = 10;
46 size_t maxopeelevel_ = 2;
51
52
55 virtual ~Interpreter();
56
57
59 void help();
60
61
63 static std::string strEscape( const std::string & p_s );
64
65
66protected:
67#ifndef DBC_IS_VOID
72 bool invariant() const noexcept override { /* LCOV_EXCL_START */
73 return pimpltime_ != nullptr;
74 } /* LCOV_EXCL_STOP */
75#endif
76
77
78public:
80 Interpreter( const Interpreter& ) = delete;
81
82
84 Interpreter( Interpreter&& ) = delete;
85
86
88 Interpreter& operator=( const Interpreter& ) = delete;
89
90
93
94
95public: /* accessor */
98 static auto get() {
99 if( !instance_ ) {
100 instance_ = new (std::nothrow) Interpreter;
101 if( instance_ == nullptr )
102 panicExit(); /* LCOV_EXCL_LINE */
103 }
104
105 DBC_POST( instance_ != nullptr );
106 return instance_;
107 }
108
109
111 static Context * getContext();
112
113
115 bool getVerbose() const { return verbose_; }
116
117
119 void setContext( Context * p_c ) { curctx_ = p_c; }
120
121
124 __int128 getClockStart() const;
125
126
128 void setOdo( bool p_odo ) { odo_ = p_odo; }
129
130
132 bool getOdo() const { return odo_; }
133
134
136 size_t getOdoIterations() const { return odo_iterations_; }
137
138
140 size_t getMaxopeelevel() const { return maxopeelevel_; }
141
142
144 std::ostream & getCout() { return cout_; }
145
146
147public: /* other */
151 void leonline( std::string & p_line, Context & k );
152
153
157 bool getLine( std::string & p_line ) const;
158
159
161 static void addchanges( size_t p_allchanges ) {
162 get()->odo_changes_ += p_allchanges;
163 }
164
165
171 static void shutdown();
172
173
176 void commandline( int p_argc, char* p_argv[] );
177
178
180 void property_statistics();
181
182
184 void status_statistics();
185
186
191 static void memory_statistics( bool p_force, std::ostream & p_cout );
192
193
196 void snap();
197};
The context of execution.
Definition: context.h:37
Design by contract interface class.
Definition: dbc.h:25
Interpreter status.
Definition: interpreter.h:33
bool getOdo() const
Getter for odo_.
Definition: interpreter.h:132
static void addchanges(size_t p_allchanges)
Add p_allchanges to odo_changes_ counter.
Definition: interpreter.h:161
Interpreter(const Interpreter &)=delete
Delete the copy ctor.
static auto get()
Get the singleton pointer.
Definition: interpreter.h:98
virtual ~Interpreter()
Private dtor.
Definition: interpreter.cpp:61
static void shutdown()
Shut down.
Definition: interpreter.cpp:109
static void memory_statistics(bool p_force, std::ostream &p_cout)
Dumps memory statistical data.
Definition: interpreter.cpp:237
Interpreter & operator=(Interpreter &&)=delete
Delete move assignement.
bool odo_
Interpreter Property.
Definition: interpreter.h:43
bool getLine(std::string &p_line) const
Wrapper around getline to hide input stream.
Definition: interpreter.cpp:102
void setContext(Context *p_c)
Setter for current context.
Definition: interpreter.h:119
std::ostream cout_
Interpreter Property.
Definition: interpreter.h:44
static Interpreter * instance_
Pointer to the singleton instance or a nullptr.
Definition: interpreter.h:34
size_t odo_iterations_
Interpreter Property.
Definition: interpreter.h:45
static Context * getContext()
Get the current context.
Definition: interpreter.cpp:70
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:117
__int128 getClockStart() const
Getter for clock start.
Definition: interpreter.cpp:78
void leonline(std::string &p_line, Context &k)
Processes one line of the leon-format input.
Definition: interpreter.cpp:139
size_t maxopeelevel_
Interpreter Property.
Definition: interpreter.h:46
std::ostream & getCout()
Getter for cout_.
Definition: interpreter.h:144
Interpreter()
Private ctor.
Definition: interpreter.cpp:55
Interpreter(Interpreter &&)=delete
Delete the move ctor.
size_t odo_changes_
Number of changes applied by odo.
Definition: interpreter.h:40
PimplTime * pimpltime_
Pointer to implemenation of time functions - opaque pointer.
Definition: interpreter.h:39
void commandline(int p_argc, char *p_argv[])
Command line parsing.
Definition: interpreter.cpp:180
void snap()
Snapshot of complete Interpreter and Context statistics to Interpreter-cout.
Definition: interpreter.cpp:256
size_t getOdoIterations() const
Getter for odo_iterations_.
Definition: interpreter.h:136
void status_statistics()
Dumps various status statistical data.
Definition: interpreter.cpp:214
void setOdo(bool p_odo)
Setter for odo_.
Definition: interpreter.h:128
bool verbose_
Interpreter Property.
Definition: interpreter.h:42
LineSource * linesource_
Read from cin or from file.
Definition: interpreter.h:37
bool invariant() const noexcept override
Checks class invariants.
Definition: interpreter.h:72
size_t getMaxopeelevel() const
Getter for maximum opee level.
Definition: interpreter.h:140
bool getVerbose() const
Getter for verbose mode.
Definition: interpreter.h:115
void help()
Command line help text.
Definition: interpreter.cpp:83
Context * curctx_
Access to the current Context.
Definition: interpreter.h:36
void property_statistics()
Dumps property statistical data.
Definition: interpreter.cpp:227
Interpreter & operator=(const Interpreter &)=delete
Delete copy assignement.
Abstraction of input channel.
Definition: linesource.h:29
Helpers for design by contract idioms.
#define DBC_POST(XXX)
Assert for postconditions.
Definition: dbc.h:80
void panicExit()
Panic exit( EC_PANIC ).
Definition: error.cpp:103
Error handling.
Miscellaneous definitions and functions.
Pointer to Implementation for Time.
Definition: interpreter.cpp:49