chomik 0.2.1
experimental and minimalistic programming language

My name is Pawel Biernacki.
I am a software engineer.
This site is my hobby project.

Loading...
Searching...
No Matches
chomik.h
Go to the documentation of this file.
1#ifndef CHOMIK_H
2#define CHOMIK_H
3
4#include <vector>
5#include <map>
6#include <memory>
7#include <string>
8#include <iostream>
9#include <sstream>
10#include <fstream>
11#include <random>
12#include <iomanip>
13#include <regex>
14
15//#define CHOMIK_DONT_USE_OPTIMIZATIONS
16// disable this flag to build an optimized chomik
17
18namespace chomik
19{
20 class signature;
21 class code;
22
27 {
28 private:
29 static const std::string array_of_predefined_types[];
30 public:
31 static bool get_type_is_predefined(const std::string & type_name);
32 };
33
38 {
39 private:
40 static const std::string array_of_predefined_variables[];
41 public:
42 static bool get_variable_is_predefined(const std::string & prefix);
43 };
44
49 {
50 protected:
51 std::shared_ptr<signature> actual_name;
52 public:
54
55 variable_with_value(std::shared_ptr<signature> && n): actual_name{std::move(n)} {}
57
58 std::string get_signature_item_representation(int item_index) const;
59 std::string get_signature_item_type_name(int item_index) const;
61
62 virtual void report(std::ostream & s) const = 0;
63
65
67
68 virtual int get_value_integer() const { return 0; }
69
70 virtual double get_value_float() const { return 0.0; }
71
72 virtual std::string get_value_string() const { return "?"; }
73
74 virtual std::string get_value_enum() const { return ""; }
75
76 virtual void get_value_code(code & target) const {}
77
78 virtual void assign_value_integer(int v) {}
79
80 virtual void assign_value_float(double v) {}
81
82 virtual void assign_value_string(std::string v) {}
83
84 virtual void assign_value_enum(std::string v) {}
85
86 virtual void assign_value_code(const code & ci) {}
87
88 virtual std::string get_debug_type_name() const { return "variable_with_value"; }
89 };
90
91
92 class machine;
93 class basic_generator;
94
99 {
100 protected:
101 const std::string placeholder;
102 public:
103 placeholder_with_value(const std::string & n): placeholder{n} {}
104
105 const std::string & get_name() const { return placeholder; }
106
108
109 virtual void report(std::ostream & s) const = 0;
110
112
113 virtual bool get_is_valid() const { return true; }
114
115 virtual bool get_is_terminated() const { return false; }
116
117 virtual void increment() {}
118
119 virtual std::string get_value_string() const { return ""; }
120
121 virtual std::string get_value_enum() const { return ""; }
122
123 virtual void get_value_code(code & target) const {}
124
125 virtual bool get_exceeds_level(int max_level) const { return false; }
126
127 virtual int get_level() const { return 0; }
128
130
131 virtual void update_int_value(int f, int l) {}
132
133 };
134
135 class mapping_generator;
136 class external_placeholder_generator;
137 class generator;
138
143 {
144 private:
145 bool successful;
146 std::map<std::string, int> map_placeholder_names_to_integer;
147 std::map<std::string, double> map_placeholder_names_to_float;
148 std::map<std::string, std::string> map_placeholder_names_to_string;
149 std::map<std::string, std::string> map_placeholder_names_to_identifier;
150 std::map<std::string, code> map_placeholder_names_to_code;
151 std::map<std::string, bool> map_placeholder_names_to_flag_has_been_bound;
152
153 std::map<std::string, std::string> map_placeholder_names_to_placeholder_names;
154 public:
155 matching_protocol(): successful{true} {}
156 bool get_is_placeholder_bound_as_integer(const std::string & p) const { return map_placeholder_names_to_integer.find(p)!=map_placeholder_names_to_integer.end(); }
157 bool get_is_placeholder_bound_as_float(const std::string & p) const { return map_placeholder_names_to_float.find(p)!=map_placeholder_names_to_float.end(); }
158 bool get_is_placeholder_bound_as_string(const std::string & p) const { return map_placeholder_names_to_string.find(p)!=map_placeholder_names_to_string.end(); }
159 bool get_is_placeholder_bound_as_identifier(const std::string & p) const { return map_placeholder_names_to_identifier.find(p)!=map_placeholder_names_to_identifier.end(); }
160 int get_placeholder_value_integer(const std::string & p) const { return map_placeholder_names_to_integer.at(p); }
161 double get_placeholder_value_float(const std::string & p) const { return map_placeholder_names_to_float.at(p); }
162 std::string get_placeholder_value_string(const std::string & p) const { return map_placeholder_names_to_string.at(p); }
163 std::string get_placeholder_value_identifier(const std::string & p) const { return map_placeholder_names_to_identifier.at(p); }
164
165 void bind_placeholder_as_integer(const std::string & p, int v)
166 {
167 auto [it, s] = map_placeholder_names_to_integer.insert(std::pair(p,v));
168 if (!s) throw std::runtime_error("failed to bind a placeholder");
169 }
170 void bind_placeholder_as_float(const std::string & p, double v)
171 {
172 auto [it, s] = map_placeholder_names_to_float.insert(std::pair(p,v));
173 if (!s) throw std::runtime_error("failed to bind a placeholder");
174 }
175 void bind_placeholder_as_string(const std::string & p, std::string v)
176 {
177 auto [it, s] = map_placeholder_names_to_string.insert(std::pair(p,v));
178 if (!s) throw std::runtime_error("failed to bind a placeholder");
179 }
180 void bind_placeholder_as_identifier(const std::string & p, std::string v)
181 {
182 auto [it, s] = map_placeholder_names_to_identifier.insert(std::pair(p,v));
183 if (!s) throw std::runtime_error("failed to bind a placeholder");
184 }
185 void bind_placeholder_as_code(const std::string & p, const code & c);
186 void bind_placeholder_as_placeholder(const std::string & p, const std::string & p2)
187 {
188 auto [it, s] = map_placeholder_names_to_placeholder_names.insert(std::pair(p,p2));
189 if (!s) throw std::runtime_error("failed to bind a placeholder");
190 }
191
192 bool get_is_successful() const { return successful; }
193
194 void report(std::ostream & s) const;
195
197
199
200 void copy_bound_placeholders(generator & target) const;
201 };
202
203
204 class generic_name_item;
205 class machine;
206 class basic_generator;
207
212 {
213 protected:
215 public:
217
218 virtual ~signature_item() {}
219 virtual void report(std::ostream & s) const = 0;
220
221 std::string get_string_representation() const;
222
223 virtual std::string get_type_name() const = 0;
224
225 virtual void print(std::ostream & s) const { report(s); } // printing is usually the same as reporting
226
227 virtual bool get_is_predefined() const { return false; }
228
229 virtual bool get_it_is_identifier(const std::string & pattern) const { return false; }
230
231 virtual bool get_it_is_string() const { return false; }
232
233 virtual bool get_it_is_integer() const { return false; }
234
235 virtual bool get_it_is_float() const { return false; }
236
237 virtual bool get_it_is_enum() const { return false; }
238
239 virtual bool get_it_is_code() const { return false; }
240
241 virtual int get_value_integer() const { return 0; }
242
243 virtual double get_value_float() const { return 0.0; }
244
245 virtual std::string get_value_string() const { return ""; }
246
247 virtual std::string get_value_enum() const { return ""; }
248
249 virtual void get_value_code(std::unique_ptr<code> & target) {}
250
251 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const = 0;
252
253 virtual void get_copy(std::shared_ptr<signature_item> & target) const = 0;
254
255 virtual std::string get_debug_type_name() const { return "signature_item"; }
256 };
257
262 template <typename TYPE>
264 {
265 protected:
266 const TYPE value;
267 public:
269
270 virtual void report(std::ostream & s) const override
271 {
272 s << value;
273 }
274 };
275
277 {
278 public:
280 virtual bool get_it_is_integer() const override { return true; }
281 virtual int get_value_integer() const override { return value; }
282
283 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
284
285 virtual void get_copy(std::shared_ptr<signature_item> & target) const override
286 {
287 target = std::make_shared<simple_value_integer_signature_item>(source, value);
288 }
289
290 virtual std::string get_debug_type_name() const { return "simple_value_integer_signature_item"; }
291
292 virtual std::string get_type_name() const override { return "integer"; }
293 };
294
296 {
297 public:
299 virtual bool get_it_is_float() const override { return true; }
300 virtual double get_value_float() const override { return value; }
301
302 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
303
304 virtual void get_copy(std::shared_ptr<signature_item> & target) const override
305 {
306 target = std::make_shared<simple_value_float_signature_item>(source, value);
307 }
308
309 virtual std::string get_debug_type_name() const { return "simple_value_float_signature_item"; }
310
311 virtual std::string get_type_name() const override { return "float"; }
312 };
313
319 {
320 public:
321 simple_value_string_signature_item(const generic_name_item & s, const std::string v): simple_value_signature_item<std::string>{s, v} {}
322 virtual void report(std::ostream & s) const override
323 {
324 s << '\"' << value << '\"';
325 }
326 virtual void print(std::ostream & s) const override
327 {
328 s << value;
329 }
330
331 virtual bool get_it_is_string() const override { return true; }
332
333 virtual std::string get_value_string() const override { return value; }
334
335 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
336
337 virtual void get_copy(std::shared_ptr<signature_item> & target) const override
338 {
339 target = std::make_shared<simple_value_string_signature_item>(source, value);
340 }
341
342 virtual std::string get_debug_type_name() const { return "simple_value_string_signature_item"; }
343
344 virtual std::string get_type_name() const override { return "string"; }
345 };
346
351 {
352 private:
353 std::vector<std::string> vector_of_identifiers;
354 const std::string debug_name; // only for debugging
355 public:
356 dictionary_of_identifiers(const std::string & d): debug_name{d} {}
357 int get_identifier_index(const std::string id); // if necessary - create a new identifier
358 const std::string get_identifier_by_index(int index) const;
359 };
360
361
363 {
364 protected:
366 public:
367
368 };
369
370
371#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
376 {
377 public:
379
380 virtual bool get_is_predefined() const override { return predefined_variables::get_variable_is_predefined(value); }
381
382 virtual bool get_it_is_identifier(const std::string & pattern) const { return value == pattern; }
383
384 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
385
386 virtual bool get_it_is_enum() const override { return true; }
387
388 virtual std::string get_value_enum() const override { return value; }
389
390 virtual void get_copy(std::shared_ptr<signature_item> & target) const override
391 {
392 target = std::make_shared<simple_value_enum_signature_item>(source, value);
393 }
394
395 virtual std::string get_debug_type_name() const { return "simple_value_enum_signature_item"; }
396
397 const std::string get_enum() const { return value; }
398
399 virtual std::string get_type_name() const override { return "identifier"; }
400 };
401#else
403 {
404 public:
405 simple_value_enum_signature_item(const generic_name_item & s, const std::string & i): simple_value_signature_item<int>(s, our_dictionary.get_identifier_index(i)) {}
406
407 virtual void print(std::ostream & s) const override
408 {
410 }
411
412 virtual void report(std::ostream & s) const override
413 {
415 }
416
418
419 virtual bool get_it_is_identifier(const std::string & pattern) const { return our_dictionary.get_identifier_by_index(value) == pattern; }
420
421 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
422
423 virtual bool get_it_is_enum() const override { return true; }
424
425 virtual std::string get_value_enum() const override { return our_dictionary.get_identifier_by_index(value); }
426
427 virtual void get_copy(std::shared_ptr<signature_item> & target) const override
428 {
429 const std::string id = our_dictionary.get_identifier_by_index(value);
430 target = std::make_shared<simple_value_enum_signature_item>(source, id);
431 }
432
433 virtual std::string get_debug_type_name() const { return "simple_value_enum_signature_item"; }
434
435 const std::string get_enum() const { return our_dictionary.get_identifier_by_index(value); }
436
437 virtual std::string get_type_name() const override { return "identifier"; }
438 };
439#endif
440
441
443 {
444 private:
445 std::unique_ptr<code> my_code;
446 public:
447 code_signature_item(const generic_name_item & s, const code & c): signature_item{s}, my_code{std::make_unique<code>(c)} {}
448
449 code_signature_item(const code_signature_item & s): signature_item{s.source}, my_code{std::make_unique<code>(*s.my_code)} {}
450
451 virtual void report(std::ostream & s) const override;
452
453 virtual bool get_it_is_code() const override { return true; }
454
455 virtual bool get_match(const generic_name_item & gni, const machine & m, const basic_generator & g, matching_protocol & target) const override;
456
457 virtual void get_copy(std::shared_ptr<signature_item> & target) const;
458
459 virtual std::string get_type_name() const override { return "code"; }
460 };
461
462 class generic_name;
463 class machine;
464 class signature_common_data;
465 class generic_stream;
466
467
473 {
474 private:
475 static std::unique_ptr<signature_common_data> our_common_data;
476
477 std::vector<std::shared_ptr<signature_item>> vector_of_items;
478
479 unsigned line_number;
480
481 bool get_it_has_prefix(const std::string & pattern) const;
482
483 void execute_predefined_print(machine & m) const;
484 void execute_predefined_create(machine & m) const;
485 void execute_predefined_get(machine & m) const;
486 void execute_predefined_read(machine & m) const;
487 void execute_predefined_compare(machine & m) const;
488 void execute_predefined_add(machine & m) const;
489 void execute_predefined_subtract(machine & m) const;
490 void execute_predefined_multiply(machine & m) const;
491 void execute_predefined_divide(machine & m) const;
492 void execute_predefined_set(machine & m) const;
493 void execute_predefined_getline(machine & m) const;
494 void execute_predefined_execution(machine & m) const;
495 void execute_predefined_match(machine & m) const;
496 void execute_predefined_modulo(machine & m) const;
497 void execute_predefined_cast(machine & m) const;
498
499 void set_stream_flags(machine & m, generic_stream & gs) const;
500
501 public:
502 signature(const generic_name & gn, const machine & m, const basic_generator & g);
505
506 void set_line_number(unsigned n) { line_number = n; }
507
508 int get_amount_of_items() const { return vector_of_items.size(); }
509
510 void report(std::ostream & s) const;
511
512 void add_content(std::shared_ptr<signature_item> && i);
513
514 std::string get_string_representation() const;
515
516 std::string get_item_representation(int item_index) const { return vector_of_items[item_index]->get_string_representation(); }
517 std::string get_item_type_name(int item_index) const { return vector_of_items[item_index]->get_type_name(); }
518
519 bool get_is_predefined(const machine & m) const;
520
522
523 const std::vector<std::shared_ptr<signature_item>> & get_vector_of_items() const { return vector_of_items; }
524 };
525
530 {
531 private:
532 const std::string my_signature_regular_expression_code;
533
534 std::unique_ptr<generic_name> my_name;
535
536 std::vector<std::shared_ptr<signature_item>> vector_of_items;
537
538 std::unique_ptr<std::regex> my_regular_expression;
539
540 enum class state { INITIAL, IDENTIFIER, PLACEHOLDER_1, PLACEHOLDER_2, PLACEHOLDER_3, PLACEHOLDER_4, PLACEHOLDER_5, PLACEHOLDER_6 };
541
542 void parse(const std::string & c);
543
544 public:
545 signature_regular_expression(const std::string & c);
546
547 const std::vector<std::shared_ptr<signature_item>> & get_vector_of_items() const { return vector_of_items; }
548
549 std::regex& get_regular_expression() { return *my_regular_expression; }
550 };
551
552
557 {
558 public:
559 virtual ~generic_type() {}
560 virtual void report(std::ostream & s) const = 0;
561 virtual bool get_is_finite() const = 0;
564
565 virtual std::string get_type_name(const machine & m, const basic_generator & g) const = 0;
566
567 virtual std::string get_generic_type_name() const = 0;
568
569 virtual std::string get_low_level_type_name() const = 0;
570
571 virtual void get_copy(std::shared_ptr<generic_type> & target) const = 0;
572
573 virtual void get_copy(std::unique_ptr<generic_type> & target) const = 0;
574
575 virtual bool get_is_equal(const generic_type & t) const = 0;
576
577 virtual bool get_is_an_ad_hoc_type() const = 0;
578
579 virtual void update_boundaries(machine & m, int & f, int & l, basic_generator & g) const {}
580 };
581
582
583
585 {
586 private:
587 const std::string name;
588 public:
589 generic_type_named(const char * const n): name{n} {}
590
591 generic_type_named(const std::string & n): name{n} {}
592
593 virtual std::string get_type_name(const machine & m, const basic_generator & g) const override
594 {
595 return name;
596 }
597
598 virtual std::string get_generic_type_name() const override
599 {
600 return name;
601 }
602
603 virtual std::string get_low_level_type_name() const override
604 {
605 return name;
606 }
607
608 virtual void report(std::ostream & s) const
609 {
610 s << name;
611 }
612
613 virtual bool get_is_finite() const override
614 {
615 if (name == "integer" || name == "float" || name=="string" || name=="code") // these types are built-in and infinite
616 return false;
617 return true;
618 }
619
621
622 virtual void add_placeholders_to_generator(basic_generator & g) const override {}
623
624 virtual void get_copy(std::shared_ptr<generic_type> & target) const override
625 {
626 target = std::make_shared<generic_type_named>(name);
627 }
628
629 virtual void get_copy(std::unique_ptr<generic_type> & target) const override
630 {
631 target = std::make_unique<generic_type_named>(name);
632 }
633
634 virtual bool get_is_equal(const generic_type & t) const override
635 {
636 // TODO fix me
637 return false;
638 }
639
640 virtual bool get_is_an_ad_hoc_type() const override
641 {
642 return false;// The named types are not "ad hoc" types
643 }
644 };
645
646
648 {
649 public:
651
652 virtual void report(std::ostream & s) const = 0;
653
654 virtual int get_value(const machine & m, const basic_generator & g) const = 0;
655
657
658 virtual void get_copy(std::unique_ptr<generic_range_boundary> & target) const = 0;
659 };
660
662 {
663 private:
664 const int b;
665 public:
667
668 virtual void report(std::ostream & s) const override
669 {
670 s << b;
671 }
672
673 virtual int get_value(const machine & m, const basic_generator & g) const override
674 {
675 return b;
676 }
677
678 virtual void get_copy(std::unique_ptr<generic_range_boundary> & target) const override
679 {
680 target = std::make_unique<generic_range_boundary_int_literal>(b);
681 }
682
683 };
684
686 {
687 private:
688 std::unique_ptr<generic_name> name;
689
690 public:
695
697
698 virtual void report(std::ostream & s) const override;
699
700 virtual int get_value(const machine & m, const basic_generator & g) const override;
701
702 virtual void add_placeholders_to_generator(basic_generator & g) const override;
703
704 virtual void get_copy(std::unique_ptr<generic_range_boundary> & target) const override
705 {
706 target = std::make_unique<generic_range_boundary_variable_value>(*name);
707 }
708 };
709
710
712 {
713 private:
714 std::unique_ptr<generic_range_boundary> min_boundary, max_boundary;
715 public:
716 /* This constructor owns the first and second parameter, the parser must not destroy them! */
718 min_boundary{min_b}, max_boundary{max_b}
719 {
720 }
721
722 generic_range(std::unique_ptr<generic_range_boundary> && a, std::unique_ptr<generic_range_boundary> && b):
723 min_boundary{std::move(a)}, max_boundary{std::move(b)} {}
724
725 void report(std::ostream & s) const
726 {
727 min_boundary->report(s);
728 s << "..";
729 max_boundary->report(s);
730 }
731
732 int get_min_value(const machine & m, const basic_generator & g) const
733 {
734 return min_boundary->get_value(m, g);
735 }
736 int get_max_value(const machine & m, const basic_generator & g) const
737 {
738 return max_boundary->get_value(m, g);
739 }
740
742 {
743 min_boundary->add_placeholders_to_generator(g);
744 max_boundary->add_placeholders_to_generator(g);
745 }
746
747 void get_copy(std::unique_ptr<generic_range> & target) const
748 {
749 std::unique_ptr<generic_range_boundary> a, b;
750 min_boundary->get_copy(a);
751 max_boundary->get_copy(b);
752 target = std::make_unique<generic_range>(std::move(a), std::move(b));
753 }
754 };
755
757 {
758 private:
759 std::unique_ptr<generic_range> r;
760 public:
764 generic_type_range(generic_range * const nr): r{nr} {}
765
767 {
768 std::unique_ptr<generic_range> i;
769 rn.get_copy(i);
770 r = std::move(i);
771 }
772
773 virtual void report(std::ostream & s) const
774 {
775 r->report(s);
776 }
777
778 virtual bool get_is_finite() const override
779 {
780 return true;
781 }
782
783 int get_min_value(const machine & m, const basic_generator & g) const
784 {
785 return r->get_min_value(m, g);
786 }
787 int get_max_value(const machine & m, const basic_generator & g) const
788 {
789 return r->get_max_value(m, g);
790 }
791
794
796 {
797 r->add_placeholders_to_generator(g);
798 }
799
800 virtual std::string get_type_name(const machine & m, const basic_generator & g) const override
801 {
802 std::stringstream s;
803 s << get_min_value(m, g) << ".." << get_max_value(m, g);
804 return s.str();
805 }
806
807 virtual std::string get_generic_type_name() const override
808 {
809 std::stringstream s;
810 r->report(s);
811 return s.str();
812 }
813
814
815 virtual std::string get_low_level_type_name() const override
816 {
817 return "integer";
818 }
819
820 virtual void get_copy(std::shared_ptr<generic_type> & target) const override
821 {
822 target = std::make_shared<generic_type_range>(*r);
823 }
824
825 virtual void get_copy(std::unique_ptr<generic_type> & target) const override
826 {
827 target = std::make_unique<generic_type_range>(*r);
828 }
829
830 virtual bool get_is_equal(const generic_type & t) const override
831 {
832 // TODO fix me
833 return false;
834 }
835
836 virtual bool get_is_an_ad_hoc_type() const override
837 {
838 return true;
839 }
840
841 virtual void update_boundaries(machine & m, int & f, int & l, basic_generator & g) const override
842 {
843 f = get_min_value(m, g);
844 l = get_max_value(m, g);
845 }
846 };
847
848 class replacing_policy;
849 class type_instance;
850 class type_definition;
851
856 {
857 protected:
858 unsigned line_number;
859
860 static const std::vector<std::shared_ptr<type_definition>> dummy;
861
862 public:
864
865 statement(unsigned l): line_number{l} {}
866
867 virtual ~statement() {}
868
870 virtual void report(std::ostream & s) const = 0;
871
872 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const = 0;
873
874 virtual void expand(machine & m, int depth) const {}
875
877
878 void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const;
879
880 virtual bool get_is_code_assignment(machine & m) const { return false; }
881
882 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & s) const = 0;
883
884 virtual void get_copy(std::shared_ptr<statement> & target) const = 0;
885
886
887 virtual const std::vector<std::shared_ptr<type_definition>> & get_vector_of_type_definitions() const { return dummy; }
888 };
889
894 {
895 public:
897
898 virtual void report(std::ostream & s) const = 0;
899
901
902 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const = 0;
903
904 virtual void add_content_to_signature(signature & target) const {}
905
906 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const = 0;
907
908 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const = 0;
909
910 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const = 0;
911
912 virtual bool get_is_identifier() const { return false; }
913
914 virtual bool get_is_integer() const { return false; }
915
916 virtual bool get_is_float() const { return false; }
917
918 virtual bool get_is_string() const { return false; }
919
920 virtual bool get_is_code() const { return false; }
921
922 virtual bool get_is_placeholder() const { return false; }
923
924 virtual std::string get_placeholder_name() const { return ""; }
925
926 virtual bool get_match_integer(int v, const machine & m, const basic_generator & g) const { return false; }
927 virtual bool get_match_float(double v, const machine & m, const basic_generator & g) const { return false; }
928 virtual bool get_match_string(const std::string & v, const machine & m, const basic_generator & g) const { return false; }
929 virtual bool get_match_identifier(const std::string & v, const machine & m, const basic_generator & g) const { return false; }
930 virtual bool get_match_code(const code & v, const machine & m, const basic_generator & g) const { return false; }
931
932 virtual bool get_is_variable_value() const { return false; }
933 };
934
935 class list_of_generic_name_items;
936
941 {
942 private:
943 std::vector<std::shared_ptr<generic_name_item>> vector_of_name_items;
944 public:
949
951
953
954 void report(std::ostream & s) const;
955
956 const std::vector<std::shared_ptr<generic_name_item>> & get_vector_of_name_items() const { return vector_of_name_items; }
957
958 std::string get_actual_text_representation(const machine & m, const basic_generator & g) const;
959
961
962 void add_generic_name_item(std::shared_ptr<generic_name_item> && i)
963 {
964 vector_of_name_items.push_back(std::move(i));
965 }
966
967 void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const;
968
969 bool operator==(const generic_name & n) const;
970 };
971
976 {
977 private:
978#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
979 const std::string identifier;
980#else
981 const int index;
982#endif
983
984
985 public:
986#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
987 identifier_name_item(const char * const i): identifier{i} {}
988
989 identifier_name_item(const std::string & i): identifier{i} {}
990#else
991 identifier_name_item(const char * const i): index{our_dictionary.get_identifier_index(i)} {}
992
993 identifier_name_item(const std::string & i): index{our_dictionary.get_identifier_index(i)} {}
994#endif
995
996 virtual void report(std::ostream & s) const override
997 {
998#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
999 s << identifier;
1000#else
1002#endif
1003 }
1004
1005 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override
1006 {
1007#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1008 target.add_content(std::make_shared<simple_value_enum_signature_item>(*this, identifier));
1009#else
1010 target.add_content(std::make_shared<simple_value_enum_signature_item>(*this, our_dictionary.get_identifier_by_index(index)));
1011#endif
1012 }
1013
1014 virtual void add_content_to_signature(signature & target) const override
1015 {
1016#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1017 target.add_content(std::make_shared<simple_value_enum_signature_item>(*this, identifier));
1018#else
1019 target.add_content(std::make_shared<simple_value_enum_signature_item>(*this, our_dictionary.get_identifier_by_index(index)));
1020#endif
1021 }
1022
1023 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override
1024 {
1025#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1026 return identifier;
1027#else
1029#endif
1030 }
1031
1032 virtual void add_placeholders_to_generator(basic_generator & g) const override {}
1033
1034 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
1035 {
1036#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1037 target.add_generic_name_item(std::make_unique<identifier_name_item>(get_actual_text_representation(m, g)));
1038#else
1039 target.add_generic_name_item(std::make_unique<identifier_name_item>(our_dictionary.get_identifier_by_index(index)));
1040#endif
1041 }
1042
1043 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1044 {
1045#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1046 gni = std::make_shared<identifier_name_item>(identifier);
1047#else
1048 gni = std::make_shared<identifier_name_item>(our_dictionary.get_identifier_by_index(index));
1049#endif
1050 }
1051
1052 virtual bool get_is_identifier() const override { return true; }
1053
1054 virtual bool get_match_identifier(const std::string & v, const machine & m, const basic_generator & g) const override
1055 {
1056#ifdef CHOMIK_DONT_USE_OPTIMIZATIONS
1057 return identifier==v;
1058#else
1059 return our_dictionary.get_identifier_by_index(index)==v;
1060#endif
1061 }
1062 };
1063
1065 {
1066 private:
1067 const std::string placeholder;
1068 std::shared_ptr<generic_type> type_name;
1069 public:
1073 placeholder_name_item(const char * const p, generic_type * const t): placeholder{p}, type_name{t} {}
1074
1075 placeholder_name_item(const std::string & p, const generic_type & t): placeholder{p}
1076 {
1077 std::shared_ptr<generic_type> i;
1078 t.get_copy(i);
1079 type_name = std::move(i);
1080 }
1081
1082 virtual void report(std::ostream & s) const override
1083 {
1084 s << '(' << placeholder << ':';
1085 type_name->report(s);
1086 s << ')';
1087 }
1088
1089 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1090
1091 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override;
1092
1093 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
1094
1095 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
1096
1097 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1098 {
1099 gni = std::make_shared<placeholder_name_item>(placeholder, *type_name);
1100 }
1101
1102 virtual bool get_is_placeholder() const override { return true; }
1103
1104 virtual std::string get_placeholder_name() const { return placeholder; }
1105
1106 generic_type & get_type() const { return *type_name; }
1107 };
1108
1109 class list_of_generic_name_items;
1110
1112 {
1113 private:
1114 std::shared_ptr<generic_name> name;
1115 public:
1120
1122
1123 virtual void report(std::ostream & s) const override;
1124
1125 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override;
1126
1127 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
1128
1129 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1130
1131 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
1132
1133 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1134 {
1135 gni = std::make_shared<variable_value_name_item>(*name);
1136 }
1137
1138 virtual bool get_match_integer(int v, const machine & m, const basic_generator & g) const override;
1139 virtual bool get_match_float(double v, const machine & m, const basic_generator & g) const override;
1140 virtual bool get_match_string(const std::string & v, const machine & m, const basic_generator & g) const override;
1141 virtual bool get_match_identifier(const std::string & v, const machine & m, const basic_generator & g) const override;
1142 virtual bool get_match_code(const code & v, const machine & m, const basic_generator & g) const override;
1143
1144 virtual bool get_is_variable_value() const override { return true; }
1145 };
1146
1148 {
1149 private:
1150 std::unique_ptr<code> my_code;
1151 public:
1152 code_name_item(): my_code{std::make_unique<code>()} {}
1154
1155 virtual void report(std::ostream & s) const override;
1156
1157 virtual bool get_is_code() const override { return true; }
1158
1159 virtual bool get_match_code(const code & v, const machine & m, const basic_generator & g) const override;
1160
1161 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1162
1163 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override;
1164
1165 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
1166
1167 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
1168
1169 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1170 {
1171 gni = std::make_shared<code_name_item>(*my_code);
1172 }
1173 };
1174
1175
1176
1177
1182 {
1183 private:
1184 friend class signature;
1185 generic_name generic_name_the_print_target_stream_index,
1186 generic_name_the_print_separator,
1187 generic_name_the_print_end_of_line,
1188 generic_name_the_created_stream_index,
1189 generic_name_the_set_to_stream_stream_index,
1190 generic_name_the_get_from_stream_stream_index,
1191 generic_name_the_get_from_stream_result,
1192 generic_name_the_read_from_stream_source_stream_index,
1193 generic_name_the_read_from_stream_result_integer,
1194 generic_name_the_read_from_stream_result_string,
1195 generic_name_the_read_from_stream_max_size,
1196 generic_name_the_compare_result,
1197 generic_name_the_multiply_result_integer,
1198 generic_name_the_divide_result_float,
1199 generic_name_the_add_result_integer,
1200 generic_name_the_subtract_result_integer,
1201 generic_name_the_get_is_defined_result,
1202 generic_name_the_get_amount_of_ad_hoc_types_result,
1203 generic_name_the_get_amount_of_variables_in_the_memory_result,
1204 generic_name_the_get_amount_of_items_in_the_memory_variables_signature_result,
1205 generic_name_the_get_signature_item_representation_result,
1206 generic_name_the_get_signature_item_types_name_result,
1207 generic_name_the_getline_stream_index,
1208 generic_name_the_getline_result,
1209 generic_name_the_created_signature_regular_expression_index,
1210 generic_name_the_match_expression_index,
1211 generic_name_the_match_result,
1212 generic_name_the_modulo_result_integer,
1213 generic_name_the_stream_is_good,
1214 generic_name_the_cast_result_integer,
1215 generic_name_the_multiply_result_float,
1216 generic_name_the_cast_result_float,
1217 generic_name_the_add_result_float,
1218 generic_name_the_subtract_result_float;
1219
1220 std::unique_ptr<signature> signature_the_print_target_stream_index,
1221 signature_the_print_separator,
1222 signature_the_print_end_of_line,
1223 signature_the_created_stream_index,
1224 signature_the_set_to_stream_stream_index,
1225 signature_the_get_from_stream_stream_index,
1226 signature_the_get_from_stream_result,
1227 signature_the_read_from_stream_source_stream_index,
1228 signature_the_read_from_stream_result_integer,
1229 signature_the_read_from_stream_result_string,
1230 signature_the_read_from_stream_max_size,
1231 signature_the_compare_result,
1232 signature_the_multiply_result_integer,
1233 signature_the_divide_result_float,
1234 signature_the_add_result_integer,
1235 signature_the_subtract_result_integer,
1236 signature_the_get_is_defined_result,
1237 signature_the_get_amount_of_ad_hoc_types_result,
1238 signature_the_get_amount_of_variables_in_the_memory_result,
1239 signature_the_get_amount_of_items_in_the_memory_variables_signature_result,
1240 signature_the_get_signature_item_representation_result,
1241 signature_the_get_signature_item_types_name_result,
1242 signature_the_getline_stream_index,
1243 signature_the_getline_result,
1244 signature_the_created_signature_regular_expression_index,
1245 signature_the_match_expression_index,
1246 signature_the_match_result,
1247 signature_the_modulo_result_integer,
1248 signature_the_stream_is_good,
1249 signature_the_cast_result_integer,
1250 signature_the_multiply_result_float,
1251 signature_the_cast_result_float,
1252 signature_the_add_result_float,
1253 signature_the_subtract_result_float;
1254
1255 std::vector<std::unique_ptr<signature>> signature_the_match_group_integer_x;
1256 std::vector<std::unique_ptr<signature>> signature_the_match_group_boolean_x;
1257
1258 public:
1261 };
1262
1263
1264
1265 template <typename TYPE>
1267 {
1268 protected:
1269 const TYPE my_value;
1270 public:
1272 virtual void report(std::ostream & s) const override
1273 {
1274 s << my_value;
1275 }
1276
1277 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override
1278 {
1279 std::stringstream s;
1280 s << my_value;
1281 return s.str();
1282 }
1283
1285
1286 };
1287
1288
1290 {
1291 public:
1293 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override
1294 {
1295 target.add_content(std::make_shared<simple_value_integer_signature_item>(*this, my_value));
1296 }
1297
1298 virtual void add_content_to_signature(signature & target) const override
1299 {
1300 target.add_content(std::make_shared<simple_value_integer_signature_item>(*this, my_value));
1301 }
1302
1303 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
1304 {
1305 target.add_generic_name_item(std::make_shared<name_item_integer>(my_value));
1306 }
1307
1308 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1309 {
1310 gni = std::make_shared<name_item_integer>(my_value);
1311 }
1312
1313 virtual bool get_is_integer() const override { return true; }
1314
1315 virtual bool get_match_integer(int v, const machine & m, const basic_generator & g) const override { return my_value == v; }
1316 };
1317
1318
1319 class name_item_float: public simple_name_item<double>
1320 {
1321 public:
1322 name_item_float(double v): simple_name_item<double>{v} {}
1323 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override
1324 {
1325 target.add_content(std::make_shared<simple_value_float_signature_item>(*this, my_value));
1326 }
1327 virtual void add_content_to_signature(signature & target) const override
1328 {
1329 target.add_content(std::make_shared<simple_value_float_signature_item>(*this, my_value));
1330 }
1331
1332 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
1333 {
1334 target.add_generic_name_item(std::make_shared<name_item_float>(my_value));
1335 }
1336
1337 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1338 {
1339 gni = std::make_shared<name_item_float>(my_value);
1340 }
1341
1342 virtual bool get_is_float() const override { return true; }
1343
1344 virtual bool get_match_float(double v, const machine & m, const basic_generator & g) const override { return my_value == v; } // comparing doubles for equality is questionable
1345 };
1346
1347 class name_item_string: public simple_name_item<std::string>
1348 {
1349 public:
1350 name_item_string(std::string v): simple_name_item<std::string>{v} {}
1351
1352 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
1353 {
1354 target.add_generic_name_item(std::make_shared<name_item_string>(my_value));
1355 }
1356 virtual void report(std::ostream & s) const override
1357 {
1358 s << '\"' << my_value << '\"';
1359 }
1360 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override;
1361
1362 virtual void add_content_to_signature(signature & target) const override
1363 {
1364 target.add_content(std::make_shared<simple_value_string_signature_item>(*this, my_value));
1365 }
1366
1367 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override
1368 {
1369 gni = std::make_shared<name_item_string>(my_value);
1370 }
1371
1372 virtual bool get_is_string() const override { return true; }
1373
1374 virtual bool get_match_string(const std::string & v, const machine & m, const basic_generator & g) const override { return my_value == v; }
1375 };
1376
1377
1378 class code;
1379 class list_of_statements;
1380
1382 {
1383 private:
1384 std::unique_ptr<code> my_code_pointer;
1385 public:
1389 name_item_code(list_of_statements * const l): my_code_pointer{std::make_unique<code>(l)} {}
1390
1392
1393 name_item_code(): my_code_pointer{std::make_unique<code>()} {}
1394
1395 virtual void report(std::ostream & s) const override;
1396
1397 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1398
1399 virtual void add_content_to_signature(signature & target, const machine & m, const basic_generator & g) const override;
1400
1401 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
1402
1403 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
1404
1405 virtual void get_copy(std::shared_ptr<generic_name_item> & gni) const override;
1406 };
1407
1408
1410
1412 {
1413 private:
1414 const std::string name;
1415 std::unique_ptr<type_definition_body> body;
1416 public:
1420 type_definition(const char * const type_name, type_definition_body * const b): name{type_name}, body{b} {}
1421
1422 void report(std::ostream & s) const;
1423
1424 void expand(machine & m, int depth, std::shared_ptr<type_instance> & e) const;
1425
1427
1428 const std::string & get_name() const { return name; }
1429
1430 bool get_is_range() const;
1431
1432 type_definition_body& get_body() { return *body; }
1433 };
1434 class type_instance;
1435
1437 {
1438 private:
1439 public:
1441
1442 virtual void report(std::ostream & s) const = 0;
1443
1444 virtual void expand(machine & m, int depth, const std::string & n, std::shared_ptr<type_instance> & e) const = 0;
1445
1447
1448 virtual bool get_is_range() const = 0;
1449
1450 virtual int get_min_value(machine & m, basic_generator & g) const { return 0; }
1451
1452 virtual int get_max_value(machine & m, basic_generator & g) const { return 0; }
1453 };
1454
1456 {
1457 private:
1458 std::unique_ptr<generic_range> r;
1459 public:
1464
1465 virtual void report(std::ostream & s) const override
1466 {
1467 r->report(s);
1468 }
1469
1470 virtual void expand(machine & m, int depth, const std::string & n, std::shared_ptr<type_instance> & e) const override;
1471
1472 virtual void add_placeholders_to_generator(basic_generator & g) const override
1473 {
1474 r->add_placeholders_to_generator(g);
1475 }
1476
1477 virtual bool get_is_range() const override
1478 {
1479 return true;
1480 }
1481 virtual int get_min_value(machine & m, basic_generator & g) const override { return r->get_min_value(m, g); }
1482
1483 virtual int get_max_value(machine & m, basic_generator & g) const override { return r->get_max_value(m, g); }
1484 };
1485
1486 class list_of_generic_names;
1487
1489 {
1490 private:
1491 const std::string placeholder_name_in_father, placeholder_name_in_son;
1492 public:
1493 mapping_generator_placeholder(const std::string & fn, const std::string sn): placeholder_name_in_father{fn}, placeholder_name_in_son{sn} {}
1494 };
1495
1497 {
1498 private:
1499 const std::string name;
1500 std::shared_ptr<generic_type> placeholder_type;
1501
1502 public:
1503 generator_placeholder(const std::string & n, std::shared_ptr<generic_type> && t): name{n}, placeholder_type{std::move(t)} {}
1504
1505 const std::string & get_name() const { return name; }
1506
1508 {
1509 return placeholder_type->get_is_finite();
1510 }
1511
1512 generic_type& get_placeholder_type() { return *placeholder_type; }
1513
1514 const generic_type& get_placeholder_type() const { return *placeholder_type; }
1515 };
1516
1517 class generic_value;
1518
1519
1520 template <typename TYPE, int REPRESENTATION_TYPE> class simple_placeholder_with_value;
1521 template <typename TYPE, int REPRESENTATION_TYPE> class simple_placeholder_with_value_and_report;
1522
1523 class description_of_a_cartesian_product;
1524
1532 {
1533 protected:
1534 std::weak_ptr<basic_generator> my_father; // this pointer is used when the generators are nested
1535
1537
1538 public:
1540 {
1541 }
1542
1543 void set_father(std::shared_ptr<basic_generator> f) { my_father = f; }
1544
1545 virtual const std::string convert_childs_placeholder_name_to_father(const std::string & cpn) const { return cpn; }
1546
1547 virtual bool get_has_placeholder_with_value(const std::string & p) const { return false; }
1548
1550
1551 virtual const placeholder_with_value& get_placeholder_with_value(const std::string & p) const;
1552
1553 virtual void report(std::ostream & s) const {};
1554
1555 virtual void add_placeholder(const std::string & p, std::shared_ptr<generic_type> && t) {}
1556
1557 virtual bool get_can_have_placeholders() const { return false; }
1558
1559 virtual int get_placeholder_value_integer(const std::string & p) const;
1560
1561 virtual double get_placeholder_value_float(const std::string & p) const;
1562
1563 std::string get_placeholder_value_string(const std::string & p) const;
1564
1565 std::string get_placeholder_value_enum(const std::string & p) const;
1566
1567 virtual void get_placeholder_value_code(const std::string & p, code & target) const;
1568
1570
1572
1574
1576
1577 virtual void initialize(machine & m) = 0;
1578
1579 virtual bool get_is_valid() { return true; }
1580
1581 virtual void increment(machine & m) = 0;
1582
1583 virtual bool get_terminated() const { return true; }
1584
1585 virtual std::string get_actual_text_representation_of_a_placeholder(const std::string & placeholder) const { return ""; }
1586
1587 virtual bool get_has_placeholder(const std::string & p) const { return false; }
1588
1590
1591 virtual void add_mapping(const std::string & f, const std::string & s) {}
1592
1593 virtual void initialize_mapping(const matching_protocol & mp) {}
1594
1595 virtual void debug() const {}
1596
1597 virtual void finalize(machine & m) {}
1598
1599 };
1600
1605 {
1606 private:
1607 std::map<std::string, std::string> map_child_placeholder_to_father_placeholder;
1608
1609 const std::string my_filename;
1610 const unsigned line_number;
1611
1612 public:
1613 mapping_generator(const std::string & filename, unsigned new_line_number): my_filename{filename}, line_number{new_line_number} {}
1614
1615 virtual const std::string convert_childs_placeholder_name_to_father(const std::string & cpn) const override;
1616
1617 virtual void report(std::ostream & s) const override;
1618
1619 virtual bool get_has_placeholder_with_value(const std::string & p) const override;
1620
1621 virtual placeholder_with_value& get_placeholder_with_value(const std::string & p) override;
1622
1623 virtual const placeholder_with_value& get_placeholder_with_value(const std::string & p) const override;
1624
1626
1627 virtual void initialize(machine & m) override;
1628
1629 virtual void increment(machine & m) override;
1630
1631 virtual void add_mapping(const std::string & f, const std::string & s)
1632 {
1633 auto [it, success] = map_child_placeholder_to_father_placeholder.insert(std::pair(s, f));
1634 if (!success)
1635 {
1636 throw std::runtime_error("failed to add mapping to a mapping generator");
1637 }
1638 }
1639
1640 void clear_mappings() { map_child_placeholder_to_father_placeholder.clear(); }
1641
1642 virtual void initialize_mapping(const matching_protocol & mp) override;
1643
1644
1645 };
1646
1647
1648 template <typename GENERATOR_TYPE> class machine_finalization_guard
1649 {
1650 private:
1651 GENERATOR_TYPE & my_generator;
1652 machine & my_machine;
1653 public:
1654 machine_finalization_guard(machine & m, GENERATOR_TYPE & p): my_machine{m}, my_generator{p} {}
1655 ~machine_finalization_guard() { my_generator.finalize(my_machine); }
1656 };
1657
1663 {
1664 private:
1665 std::vector<std::shared_ptr<generator_placeholder>> vector_of_placeholders;
1666 std::map<std::string, std::shared_ptr<generator_placeholder>> map_placeholder_names_to_placeholders;
1667
1668 std::vector<std::shared_ptr<placeholder_with_value>> memory;
1669 std::map<std::string, std::shared_ptr<placeholder_with_value>> map_placeholder_names_to_placeholders_with_value;
1670
1671 int initial_amount_of_ad_hoc_type_instances; // we need to remember this value, it will be necessary to clean the ad hoc types afterwards
1672
1673 const std::string my_filename;
1674 const unsigned line_number;
1675
1676 public:
1677 generator(const generic_name & gn, const std::string & filename, unsigned new_line_number);
1678 generator(const generic_range & gr, const std::string & filename, unsigned new_line_number);
1679 generator(const generic_value & gv, const std::string & filename, unsigned new_line_number);
1680 generator(const std::string & filename, unsigned new_line_number);
1681
1683
1684 virtual bool get_can_have_placeholders() const { return true; }
1685
1686 virtual bool get_has_placeholder(const std::string & p) const override;
1687
1688 virtual bool get_has_placeholder_with_value(const std::string & p) const override;
1689
1690 virtual placeholder_with_value& get_placeholder_with_value(const std::string & p) override;
1691
1692 virtual const placeholder_with_value& get_placeholder_with_value(const std::string & p) const override;
1693
1694 virtual int get_placeholder_value_integer(const std::string & p) const override;
1695
1696 virtual double get_placeholder_value_float(const std::string & p) const override;
1697
1698 virtual void get_placeholder_value_code(const std::string & p, code & target) const override;
1699
1700 virtual std::string get_actual_text_representation_of_a_placeholder(const std::string & placeholder) const override
1701 {
1702 return "unknown_placeholder";
1703 }
1704
1705 virtual void add_placeholder(const std::string & p, std::shared_ptr<generic_type> && t) override;
1706
1707 void add_placeholder_with_value(std::shared_ptr<placeholder_with_value> && p)
1708 {
1709 std::shared_ptr<placeholder_with_value> p2{p};
1710 auto [it, success] = map_placeholder_names_to_placeholders_with_value.insert(std::pair(p->get_name(), std::move(p2)));
1711 if (!success)
1712 {
1713 throw std::runtime_error("failed to insert a placeholder with value");
1714 }
1715
1716 memory.push_back(std::move(p));
1717 }
1718
1719 virtual void report(std::ostream & s) const override;
1720
1722
1724
1725 // TODO - if there is at least one empty type then the whole cartesian product is empty
1726 virtual bool get_the_cartesian_product_of_placeholder_types_is_empty() const override { return false; }
1727
1728 // TODO - it is also possible for some types like range 1..1
1730
1731 virtual void initialize(machine & m) override;
1732
1733 virtual bool get_is_valid() override;
1734
1735 virtual void increment(machine & m) override;
1736
1737 virtual bool get_terminated() const override;
1738
1739 bool get_does_not_exceed_level(int max_level) const;
1740
1741 virtual void debug() const override;
1742
1743 virtual void finalize(machine & m) override;
1744 };
1745
1751 {
1752 private:
1753 std::vector<std::shared_ptr<placeholder_with_value>> memory;
1754 std::map<std::string, std::shared_ptr<placeholder_with_value>> map_placeholder_names_to_placeholders_with_value;
1755
1756 const std::string my_filename;
1757 const unsigned line_number;
1758
1759 public:
1760 external_placeholder_generator(const std::string & filename, unsigned new_line_number);
1761
1762 virtual void report(std::ostream & s) const override;
1763
1764 virtual void initialize(machine & m) override;
1765
1766 virtual void increment(machine & m) override;
1767
1769
1770 virtual void initialize_mapping(const matching_protocol & mp) override;
1771
1772 virtual bool get_has_placeholder_with_value(const std::string & p) const override;
1773
1774 virtual placeholder_with_value& get_placeholder_with_value(const std::string & p) override;
1775
1776 virtual const placeholder_with_value& get_placeholder_with_value(const std::string & p) const override;
1777
1779
1780 void add_placeholder_with_value(std::shared_ptr<placeholder_with_value> && p);
1781 };
1782
1783
1785 {
1786 private:
1787 std::vector<std::shared_ptr<generic_name>> vector_of_names;
1788 public:
1793
1794 virtual void report(std::ostream & s) const override;
1795
1796 virtual void expand(machine & m, int depth, const std::string & n, std::shared_ptr<type_instance> & e) const override;
1797
1798 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1799
1800 virtual bool get_is_range() const
1801 {
1802 return false;
1803 }
1804 };
1805
1807 {
1808 private:
1809 std::vector<std::shared_ptr<type_definition>> vector_of_type_definitions;
1810 public:
1812 {
1813 if (t)
1814 {
1815 std::shared_ptr<type_definition> xt{t};
1816 vector_of_type_definitions.push_back(std::move(xt));
1817 }
1818 if (l)
1819 {
1820 for (auto & i: l->vector_of_type_definitions)
1821 {
1822 std::shared_ptr<type_definition> yl{i};
1823 vector_of_type_definitions.push_back(std::move(yl));
1824 }
1825 }
1826 }
1827
1828 std::vector<std::shared_ptr<type_definition>> & get_vector_of_type_definitions() { return vector_of_type_definitions; }
1829 };
1830
1832 {
1833 private:
1834 std::vector<std::shared_ptr<generic_name>> vector_of_names;
1835 public:
1840 {
1841 if (gn)
1842 {
1843 std::shared_ptr<generic_name> xt{gn};
1844 vector_of_names.push_back(std::move(xt));
1845 }
1846 if (l)
1847 {
1848 for (auto & i: l->vector_of_names)
1849 {
1850 std::shared_ptr<generic_name> yl{i};
1851 vector_of_names.push_back(std::move(yl));
1852 }
1853 }
1854 }
1855
1856 std::vector<std::shared_ptr<generic_name>>& get_vector_of_names() { return vector_of_names; }
1857 };
1858
1864 {
1865 private:
1866 std::vector<std::shared_ptr<type_definition>> vector_of_type_definitions;
1867 public:
1871 type_definition_statement(list_of_type_definitions * const l, unsigned new_line_number): statement{new_line_number}
1872 {
1873 if (l)
1874 {
1875 for (auto & i: l->get_vector_of_type_definitions())
1876 {
1877 std::shared_ptr<type_definition> x{i};
1878 vector_of_type_definitions.push_back(std::move(x));
1879 }
1880 }
1881 }
1882
1883 type_definition_statement(unsigned new_line_number): statement{new_line_number}
1884 {
1885 }
1886
1888
1889 virtual void report(std::ostream & s) const override;
1890
1891 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
1892
1893 virtual void expand(machine & m, int depth) const override;
1894
1895 virtual void add_placeholders_to_generator(basic_generator & g) const override;
1896
1897 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
1898
1899 virtual void get_copy(std::shared_ptr<statement> & target) const override
1900 {
1901 // TODO - implement
1902 }
1903
1904 virtual const std::vector<std::shared_ptr<type_definition>> & get_vector_of_type_definitions() const override { return vector_of_type_definitions; }
1905 };
1906
1908 {
1909 private:
1910 std::shared_ptr<generic_name> name;
1911 std::shared_ptr<generic_type> type_name;
1912
1913 public:
1917 variable_definition(std::shared_ptr<generic_name> && n, std::shared_ptr<generic_type> && t): name{n}, type_name{t} {}
1918
1919 void report(std::ostream & s) const
1920 {
1921 name->report(s);
1922 s << ':';
1923 type_name->report(s);
1924 }
1925
1926 void expand(machine & m, int depth) const;
1927
1929 {
1930 name->add_placeholders_to_generator(g);
1931 type_name->add_placeholders_to_generator(g);
1932 }
1933
1934 bool operator==(const variable_definition & d) const;
1935 };
1936
1938 {
1939 private:
1940 std::vector<std::shared_ptr<variable_definition>> vector_of_variable_definitions;
1941 public:
1946 {
1947 if (vd)
1948 {
1949 std::shared_ptr<variable_definition> x{vd};
1950 vector_of_variable_definitions.push_back(std::move(x));
1951 }
1952 if (l)
1953 {
1954 for (auto & i: l->vector_of_variable_definitions)
1955 {
1956 std::shared_ptr<variable_definition> y{i};
1957 vector_of_variable_definitions.push_back(std::move(y));
1958 }
1959 }
1960 }
1961
1962 std::vector<std::shared_ptr<variable_definition>>& get_vector_of_variable_definitions() { return vector_of_variable_definitions; }
1963 };
1964
1965
1967 {
1968 private:
1969 std::vector<std::shared_ptr<variable_definition>> vector_of_variable_definitions;
1970 public:
1975 statement{new_line_number}
1976 {
1977 if (l)
1978 {
1979 for (auto & i: l->get_vector_of_variable_definitions())
1980 {
1981 std::shared_ptr<variable_definition> y{i};
1982 vector_of_variable_definitions.push_back(std::move(y));
1983 }
1984 }
1985 }
1986
1987 variable_definition_statement(unsigned new_line_number): statement{new_line_number}
1988 {
1989 }
1990
1991
1993
1995 {
1996 return *vector_of_variable_definitions[vector_of_variable_definitions.size()-1];
1997 }
1998
1999 virtual void report(std::ostream & s) const override;
2000
2001 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
2002
2003 virtual void expand(machine & m, int depth) const override;
2004
2005 virtual void add_placeholders_to_generator(basic_generator & g) const override;
2006
2007 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
2008
2009 virtual void get_copy(std::shared_ptr<statement> & target) const override
2010 {
2011 // TODO - implement
2012 }
2013
2015 };
2016
2021 {
2022 public:
2024
2026 };
2027
2029 {
2030 public:
2031 virtual bool replace_all_variables_with_their_values() const override { return false; }
2032
2033 virtual bool replace_known_placeholders_with_their_values() const override { return true; }
2034 };
2035
2037 {
2038 public:
2039 virtual bool replace_all_variables_with_their_values() const override { return true; }
2040
2041 virtual bool replace_known_placeholders_with_their_values() const override { return true; }
2042 };
2043
2044 class generic_literal;
2045
2050 {
2051 public:
2052 virtual ~generic_value() {}
2053
2054 virtual void report(std::ostream & s) const = 0;
2055
2057
2058 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const = 0;
2059
2060 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const { return 0; }
2061
2062 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const { return 0.0; }
2063
2064 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const { return ""; }
2065
2066 virtual std::string get_actual_enum_value(const machine & m, const basic_generator & g) const { return ""; }
2067
2068 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const {}
2069
2071
2072 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const = 0;
2073
2074 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<generic_value> & target) const = 0;
2075
2076 virtual void get_copy(std::unique_ptr<generic_value> & target) const = 0;
2077
2078 virtual void get_literal_copy(std::unique_ptr<generic_literal> & target) const {}
2079
2080 virtual bool get_is_code_with_placeholders(machine & m, basic_generator & g) const { return false; }
2081
2082 virtual bool get_is_literal() const { return false; }
2083
2084 virtual bool get_is_code(machine & m) const { return false; }
2085
2086 };
2087
2088
2093 {
2094 private:
2095 std::unique_ptr<generic_name> name;
2096
2097 public:
2102
2103 generic_value_variable_value(std::unique_ptr<generic_name> && n): name{std::move(n)} {}
2104
2105 generic_value_variable_value(const generic_name & gn): name{std::make_unique<generic_name>(gn)} {}
2106
2107 virtual void report(std::ostream & s) const override
2108 {
2109 s << '<';
2110 name->report(s);
2111 s << '>';
2112 }
2113
2115
2116 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
2117
2118 virtual void add_placeholders_to_generator(basic_generator & g) const override
2119 {
2120 /*
2121 std::cout << "generic_value_variable_value - adding placeholders from ";
2122 name->report(std::cout);
2123 std::cout << " to the generator\n";
2124 */
2125 name->add_placeholders_to_generator(g);
2126 }
2127
2128 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
2129
2130 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const override;
2131
2132 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const override;
2133
2134 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const override;
2135
2136 virtual std::string get_actual_enum_value(const machine & m, const basic_generator & g) const override;
2137
2138 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const override;
2139
2140 virtual void get_copy(std::unique_ptr<generic_value> & target) const override
2141 {
2142 target = std::make_unique<generic_value_variable_value>(*name);
2143 }
2144
2145 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<generic_value> & target) const override;
2146
2147
2148 virtual bool get_is_code(machine & m) const override;
2149 };
2150
2151
2156 {
2157 public:
2158 virtual ~generic_literal() {}
2159 virtual void report(std::ostream & s) const = 0;
2160
2162
2163 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const = 0;
2164
2166
2167 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const {}
2168
2169 virtual std::string get_actual_enum_value(const machine & m, const basic_generator & g) const { return ""; }
2170
2171 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const { return 0; }
2172
2173 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const { return 0.0; }
2174
2175 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const { return ""; }
2176
2177 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const = 0;
2178
2179 virtual void get_copy(std::unique_ptr<generic_literal> & target) const = 0;
2180
2181 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const = 0;
2182
2183 virtual bool get_is_code() const { return false; }
2184 };
2185
2186
2191 {
2192 private:
2193 const std::string placeholder;
2194 std::unique_ptr<generic_type> type_name;
2196 public:
2201 placeholder{p}, type_name{t}, expected_type{e} {}
2202
2203 generic_literal_placeholder(const std::string & p, std::unique_ptr<generic_type> && t, variable_with_value::actual_memory_representation_type e):
2204 placeholder{p}, type_name{std::move(t)}, expected_type{e} {}
2205
2207
2208 virtual void report(std::ostream & s) const override;
2209
2210 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
2211
2212 virtual void add_placeholders_to_generator(basic_generator & g) const override;
2213
2214 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
2215
2216 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const override;
2217
2218 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const override;
2219
2220 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const override;
2221
2222 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const override;
2223
2224 virtual void get_copy(std::unique_ptr<generic_literal> & target) const override
2225 {
2226 std::unique_ptr<generic_type> t;
2227 type_name->get_copy(t);
2228 target = std::make_unique<generic_literal_placeholder>(placeholder, std::move(t), expected_type);
2229 }
2230
2231 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override;
2232 };
2233
2235 {
2236 private:
2237 std::unique_ptr<generic_literal> literal;
2238 public:
2242 generic_value_literal(generic_literal * const l): literal{l} {}
2243
2244 generic_value_literal(std::unique_ptr<generic_literal> && l): literal{std::move(l)} {}
2245
2246
2248 {
2249 return literal->get_actual_memory_representation_type(m, g);
2250 }
2251 virtual void report(std::ostream & s) const override
2252 {
2253 s << "literal ";
2254 literal->report(s);
2255 }
2256
2257 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override
2258 {
2259 return literal->get_actual_text_representation(m, g);
2260 }
2261 virtual void add_placeholders_to_generator(basic_generator & g) const override
2262 {
2263 literal->add_placeholders_to_generator(g);
2264 }
2265
2266 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
2267 {
2268 literal->get_result_replacing_placeholders(m, g, p, target);
2269 }
2270
2271 virtual std::string get_actual_enum_value(const machine & m, const basic_generator & g) const override { return literal->get_actual_enum_value(m, g); }
2272
2273 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const override { return literal->get_actual_integer_value(m, g); }
2274
2275 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const override { return literal->get_actual_float_value(m, g); }
2276
2277 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const override;
2278
2279 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const override;
2280
2281 virtual void get_copy(std::unique_ptr<generic_value> & target) const override;
2282
2283 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<generic_value> & target) const override;
2284
2285 virtual bool get_is_literal() const override { return true; }
2286
2287 virtual void get_literal_copy(std::unique_ptr<generic_literal> & target) const
2288 {
2289 literal->get_copy(target);
2290 }
2291
2292 virtual bool get_is_code(machine & m) const override { return literal->get_is_code(); }
2293 };
2294
2295 template <typename TYPE, int REPRESENTATION_TYPE>
2297 {
2298 protected:
2299 const TYPE my_value;
2300 public:
2301 simple_literal(const TYPE v): my_value{v} {}
2302 virtual void report(std::ostream & s) const override
2303 {
2304 s << "value " << my_value;
2305 }
2306
2311
2312 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override
2313 {
2314 std::stringstream s;
2315 s << my_value;
2316 return s.str();
2317 }
2318 virtual void add_placeholders_to_generator(basic_generator & g) const override {}
2319
2320 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
2321 {
2322 // left empty intentionally
2323 }
2324
2325 };
2326
2327 class simple_literal_integer: public simple_literal<int, static_cast<int>(chomik::variable_with_value::actual_memory_representation_type::INTEGER)>
2328 {
2329 public:
2330 simple_literal_integer(int v): simple_literal<int, static_cast<int>(chomik::variable_with_value::actual_memory_representation_type::INTEGER)>(v) {}
2331 virtual int get_value_integer() const { return my_value; }
2332
2333 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const override { return my_value; }
2334
2335 virtual void get_copy(std::unique_ptr<generic_literal> & target) const override
2336 {
2337 target = std::make_unique<simple_literal_integer>(my_value);
2338 }
2339
2340 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override
2341 {
2342 get_copy(target);
2343 }
2344 };
2345
2346 class simple_literal_float: public simple_literal<double, static_cast<int>(chomik::variable_with_value::actual_memory_representation_type::FLOAT)>
2347 {
2348 public:
2349 simple_literal_float(double v): simple_literal<double, static_cast<int>(chomik::variable_with_value::actual_memory_representation_type::FLOAT)>(v) {}
2350 virtual double get_value_float() const { return my_value; }
2351 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const override { return my_value; }
2352
2353 virtual void get_copy(std::unique_ptr<generic_literal> & target) const override
2354 {
2355 target = std::make_unique<simple_literal_float>(my_value);
2356 }
2357
2358 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override
2359 {
2360 get_copy(target);
2361 }
2362 };
2363
2364
2365
2366 class simple_literal_string: public simple_literal<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::STRING)>
2367 {
2368 public:
2369 simple_literal_string(const std::string & v): simple_literal<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::STRING)>{v} {}
2370
2371 virtual void report(std::ostream & s) const override
2372 {
2373 s << "value string " << '\"' << my_value << '\"';
2374 }
2375
2376 virtual std::string get_value_string() const { return my_value; }
2377
2378 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const override { return my_value; }
2379
2380 virtual void get_copy(std::unique_ptr<generic_literal> & target) const
2381 {
2382 target = std::make_unique<simple_literal_string>(my_value);
2383 }
2384
2385 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override
2386 {
2387 get_copy(target);
2388 }
2389 };
2390
2391
2392 class list_of_statements;
2393
2398 {
2399 private:
2400 std::unique_ptr<code> my_code_pointer;
2401 public:
2405 generic_literal_code(list_of_statements * const l): my_code_pointer{std::make_unique<code>(l)}
2406 {
2407 }
2408
2409 generic_literal_code(): my_code_pointer{std::make_unique<code>()}
2410 {
2411 }
2412
2413 generic_literal_code(const code & c): my_code_pointer{std::make_unique<code>(c)} {}
2414
2415 generic_literal_code(std::unique_ptr<code> && c): my_code_pointer{std::move(c)} {}
2416
2417
2418 code & get_code() { return *my_code_pointer; }
2419
2420 virtual void report(std::ostream & s) const override;
2421
2426 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
2427
2428 virtual void add_placeholders_to_generator(basic_generator & g) const override;
2429
2430 virtual void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const override;
2431
2432 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
2433
2434 virtual void get_copy(std::unique_ptr<generic_literal> & target) const
2435 {
2436 target = std::make_unique<generic_literal_code>(*my_code_pointer);
2437 }
2438
2439 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override;
2440
2441 virtual bool get_is_code() const override { return true; }
2442 };
2443
2445 {
2446 private:
2447 const std::string type_name;
2448 std::unique_ptr<generic_name> name;
2449 public:
2453 generic_literal_enum(const char * const tn, generic_name * const gn): type_name{tn}, name{gn} {}
2454
2455 generic_literal_enum(const std::string & tn, const generic_name & gn): type_name{tn}, name{std::make_unique<generic_name>(gn)} {}
2456
2457 virtual void report(std::ostream & s) const override
2458 {
2459 s << "value " << type_name << ' ';
2460 name->report(s);
2461 }
2462
2467
2468 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override
2469 {
2470 return name->get_actual_text_representation(m, g);
2471 }
2472 virtual void add_placeholders_to_generator(basic_generator & g) const override
2473 {
2474 name->add_placeholders_to_generator(g);
2475 }
2476
2477 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override
2478 {
2479 }
2480
2481 virtual std::string get_actual_enum_value(const machine & m, const basic_generator & g) const override { return name->get_actual_text_representation(m, g); }
2482
2483 virtual void get_copy(std::unique_ptr<generic_literal> & target) const override
2484 {
2485 target = std::make_unique<generic_literal_enum>(type_name, *name);
2486 }
2487
2488 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::unique_ptr<generic_literal> & target) const override
2489 {
2490 get_copy(target);
2491 }
2492 };
2493
2494
2496 {
2497 private:
2498 const std::string placeholder;
2499 std::shared_ptr<generic_type> type_name;
2500 public:
2501 generic_value_placeholder(const char * const p, generic_type * const t): placeholder{p}, type_name{t} {}
2502
2503 generic_value_placeholder(const std::string & p, std::shared_ptr<generic_type> && gt): placeholder{p}, type_name{std::move(gt)} {}
2504
2505 virtual void report(std::ostream & s) const override
2506 {
2507 s << "[ (" << placeholder << ':';
2508 type_name->report(s);
2509 s << ") ]";
2510 }
2511
2513
2514 virtual std::string get_actual_text_representation(const machine & m, const basic_generator & g) const override;
2515
2516 virtual void add_placeholders_to_generator(basic_generator & g) const override
2517 {
2518 std::shared_ptr<generic_type> t{type_name};
2519 g.add_placeholder(placeholder, std::move(t));
2520 type_name->add_placeholders_to_generator(g);
2521 }
2522 virtual void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const override;
2523
2524 virtual void get_copy(std::unique_ptr<generic_value> & target) const override
2525 {
2526 std::shared_ptr<generic_type> i;
2527 type_name->get_copy(i);
2528 target = std::make_unique<generic_value_placeholder>(placeholder, std::move(i));
2529 }
2530
2531 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<generic_value> & target) const override;
2532 };
2533
2539 {
2540 private:
2541 std::unique_ptr<generic_name> name;
2542 std::unique_ptr<generic_value> value;
2543
2544 void execute_if_cartesian_product_has_one_item(machine & m, std::shared_ptr<basic_generator> & g) const;
2545
2546 void execute_if_cartesian_product_is_finite_and_small(machine & m, std::shared_ptr<basic_generator> & g) const;
2547
2548 void execute_if_cartesian_product_is_large_or_infinite(machine & m, std::shared_ptr<basic_generator> & g) const;
2549
2550 public:
2554 assignment_statement(generic_name * const n, generic_value * const v, unsigned new_line_number): name{n}, value{v}, statement{new_line_number} {}
2555
2556 assignment_statement(const generic_value & gv, unsigned new_line_number):
2557 statement{new_line_number}, name{std::make_unique<generic_name>()}
2558 {
2559 std::unique_ptr<generic_value> i;
2560 gv.get_copy(i);
2561 value = std::move(i);
2562 }
2563
2564 assignment_statement(const generic_name & gn, const generic_value & gv, unsigned new_line_number);
2565
2567
2568 virtual void report(std::ostream & s) const override;
2569
2570 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
2571
2572 virtual void add_placeholders_to_generator(basic_generator & g) const override
2573 {
2574 name->add_placeholders_to_generator(g);
2575 // we do not do value->add_placeholders_to_generator(g); !!! this is intentional!
2576 }
2577
2578 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
2579
2580 virtual void get_copy(std::shared_ptr<statement> & target) const override;
2581
2582 virtual bool get_is_code_assignment(machine & m) const override { return value->get_is_code(m); }
2583 };
2584
2585
2590 {
2591 public:
2592 execute_statement(unsigned new_line_number): statement{new_line_number} {}
2594 };
2595
2596
2602 {
2603 private:
2604 std::unique_ptr<generic_value> value; // it should be a code
2605
2606 void execute_if_cartesian_product_has_one_item(machine & m, basic_generator & g) const;
2607
2608 void execute_if_cartesian_product_is_finite_and_small(machine & m, basic_generator & g) const;
2609
2610 void execute_if_cartesian_product_is_large_or_infinite(machine & m, basic_generator & g) const;
2611
2612 public:
2613 execute_value_statement(std::unique_ptr<generic_value> && v, unsigned new_line_number): value{std::move(v)}, execute_statement{new_line_number} {}
2614
2615 //execute_value_statement(unsigned new_line_number): value{std::make_unique<generic_value_literal>()}, execute_statement{new_line_number} {}
2616
2617 virtual statement_type get_statement_type() const override { return statement_type::EXECUTE; }
2618
2619 virtual void report(std::ostream & s) const override;
2620
2621 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
2622
2623 virtual void add_placeholders_to_generator(basic_generator & g) const override;
2624
2625 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
2626
2627 virtual void get_copy(std::shared_ptr<statement> & target) const override
2628 {
2629 std::unique_ptr<generic_value> n;
2630 value->get_copy(n);
2631 target = std::make_shared<execute_value_statement>(std::move(n), line_number);
2632 }
2633 };
2634
2635
2641 {
2642 private:
2643 std::unique_ptr<generic_name> name;
2644
2645 void execute_if_cartesian_product_has_one_item(machine & m, std::shared_ptr<basic_generator> & g) const;
2646
2647 void execute_if_cartesian_product_is_finite_and_small(machine & m, std::shared_ptr<basic_generator> & g) const;
2648
2649 void execute_if_cartesian_product_is_large_or_infinite(machine & m, std::shared_ptr<basic_generator> & g) const;
2650
2651 public:
2652 execute_variable_value_statement(std::unique_ptr<generic_name> && n, unsigned new_line_number): name{std::move(n)}, execute_statement{new_line_number} {}
2653
2654 execute_variable_value_statement(unsigned new_line_number): name{std::make_unique<generic_name>()}, execute_statement{new_line_number}
2655 {
2656 }
2657
2658 void add_generic_name_item(std::shared_ptr<generic_name_item> && i)
2659 {
2660 name->add_generic_name_item(std::move(i));
2661 }
2662
2663 virtual statement_type get_statement_type() const override { return statement_type::EXECUTE; }
2664
2665 virtual void report(std::ostream & s) const override;
2666
2667 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
2668
2669 virtual void add_placeholders_to_generator(basic_generator & g) const override;
2670
2671 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
2672
2673 virtual void get_copy(std::shared_ptr<statement> & target) const override
2674 {
2675 std::unique_ptr<generic_name> n=std::make_unique<generic_name>(*name);
2676 target = std::make_shared<execute_variable_value_statement>(std::move(n), line_number);
2677 }
2678 };
2679
2680
2685 {
2686 private:
2687 const int depth;
2688 public:
2689 expand_statement(int nd, unsigned new_line_number): depth{nd}, statement{new_line_number} {}
2690
2691 virtual statement_type get_statement_type() const override { return statement_type::EXPAND; }
2692
2693 virtual void report(std::ostream & s) const override
2694 {
2695 s << "expand(" << depth << ");";
2696 }
2697
2698 virtual void execute(machine & m, std::shared_ptr<const statement> && i, std::shared_ptr<basic_generator> father=nullptr) const override;
2699
2700 virtual void add_placeholders_to_generator(basic_generator & g) const override {}
2701
2702 virtual void make_copy_with_replacements(const machine & m, const basic_generator & g, const replacing_policy & p, std::shared_ptr<statement> & target) const override;
2703
2704 virtual void get_copy(std::shared_ptr<statement> & target) const
2705 {
2706 target = std::make_shared<expand_statement>(depth, line_number);
2707 }
2708 };
2709
2710
2715 {
2716 private:
2717 std::vector<std::shared_ptr<statement>> vector_of_statements;
2718 bool is_main;
2719 public:
2726
2727 void report(std::ostream & s) const;
2728
2729 std::vector<std::shared_ptr<statement>>& get_vector_of_statements() { return vector_of_statements; }
2730
2731 const std::vector<std::shared_ptr<statement>>& get_vector_of_statements() const { return vector_of_statements; }
2732
2733 void add_statement(std::shared_ptr<statement> && s)
2734 {
2735 vector_of_statements.push_back(std::move(s));
2736 }
2737
2738 void set_is_main(bool m)
2739 {
2740 is_main = m;
2741 }
2742
2744
2745 void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const;
2746
2747 bool operator==(const list_of_statements & l) const;
2748 };
2749
2750
2752 {
2753 private:
2754 std::vector<std::shared_ptr<generic_name_item>> vector_of_name_items;
2755 public:
2760 {
2761 if (i)
2762 {
2763 std::shared_ptr<generic_name_item> xi{i};
2764 vector_of_name_items.push_back(std::move(xi));
2765 }
2766 if (l)
2767 {
2768 for (auto & j: l->vector_of_name_items)
2769 {
2770 std::shared_ptr<generic_name_item> y{j};
2771 vector_of_name_items.push_back(std::move(y));
2772 }
2773 }
2774 }
2775
2776 std::vector<std::shared_ptr<generic_name_item>> & get_vector_of_name_items() { return vector_of_name_items; }
2777 };
2778
2779 class type_instance_enum_value;
2780
2782 {
2783 private:
2784 static const std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator dummy;
2785 protected:
2786 std::string name;
2787 public:
2789
2790 type_instance(const std::string & n): name{n} {}
2791
2792 virtual void report(std::ostream & s) const = 0;
2793
2794 virtual void add_type_instance_enum_value(const signature & n, unsigned new_level=1) {}
2795
2796 virtual void add_type_instance_enum_value(const std::string & n, unsigned new_level=1) {}
2797
2798 virtual std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator get_first_iterator_for_enum() const { return dummy; }
2799 virtual std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator get_last_iterator_for_enum() const { return dummy; }
2800
2801 virtual int get_first_iterator_for_range() const { return 0; }
2802 virtual int get_last_iterator_for_range() const { return 0; }
2803
2804 const std::string get_name() const { return name; }
2805
2807
2808 virtual int get_amount_of_values() const = 0;
2809
2810 virtual std::string get_enum_item(int i) { return ""; }
2811
2813
2814 void update_name(const std::string & n) { name = n; }
2815 };
2816
2817
2818
2819 template <typename TYPE, int REPRESENTATION_TYPE> class simple_placeholder_with_value: public placeholder_with_value
2820 {
2821 protected:
2822 TYPE value;
2824 public:
2825 simple_placeholder_with_value(const std::string & p, const TYPE v, type_instance * ti):
2827
2832
2833 TYPE get_value() const { return value; }
2834
2835 virtual void update_int_value(TYPE f, TYPE l) { value = f; }
2836
2837
2839 {
2840 // if the placeholder type instance is an ad hoc range
2841 // then update its type instance
2842 if (my_type_instance) my_type_instance->update(*this, m, g);
2843 }
2844 };
2845
2846 template <typename TYPE, int REPRESENTATION_TYPE> class simple_placeholder_with_value_and_report: public simple_placeholder_with_value<TYPE, REPRESENTATION_TYPE>
2847 {
2848 public:
2849 simple_placeholder_with_value_and_report(const std::string & p, const TYPE v, type_instance * ti): simple_placeholder_with_value<TYPE, REPRESENTATION_TYPE>{p, v, ti} {}
2850
2851 virtual void report(std::ostream & s) const override
2852 {
2854
2855 s << simple_placeholder_with_value<TYPE, REPRESENTATION_TYPE>::placeholder << '=';
2856 //x,report(s);
2857 s << ' ';
2858 }
2859 };
2860
2861
2863 {
2864 private:
2865 const std::string name;
2866 const unsigned level;
2867 public:
2868 type_instance_enum_value(const std::string & n, unsigned new_level): name{n}, level{new_level} {}
2869
2870 const std::string & get_name() const { return name; }
2871
2872 unsigned get_level() const { return level; }
2873 };
2874
2876 {
2877 private:
2878 std::vector<std::unique_ptr<type_instance_enum_value>> vector_of_values;
2879 public:
2880 type_instance_enum(const std::string & n): type_instance{n} {}
2881
2882 virtual void add_type_instance_enum_value(const signature & n, unsigned new_level) override;
2883
2884 virtual void add_type_instance_enum_value(const std::string & n, unsigned int new_level) override;
2885
2886 virtual void report(std::ostream & s) const override;
2887
2888 virtual std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator get_first_iterator_for_enum() const override
2889 {
2890 return vector_of_values.begin();
2891 }
2892 virtual std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator get_last_iterator_for_enum() const override
2893 {
2894 return vector_of_values.end();
2895 }
2896
2898
2899 virtual int get_amount_of_values() const override { return vector_of_values.size(); }
2900
2901 virtual std::string get_enum_item(int i) { return vector_of_values[i]->get_name(); }
2902 };
2903
2905 {
2906 protected:
2908 public:
2909 type_instance_range(const std::string & n, int b1, int b2): type_instance{n}, min_boundary{b1}, max_boundary{b2} {}
2910
2911 virtual void report(std::ostream & s) const override;
2912
2913 virtual int get_first_iterator_for_range() const override { return min_boundary; }
2914
2915 virtual int get_last_iterator_for_range() const override { return max_boundary; }
2916
2918
2919 virtual int get_amount_of_values() const override { return max_boundary - min_boundary + 1; }
2920
2921 };
2922
2923
2925 {
2926 private:
2927 const generic_type & my_type;
2928
2929 public:
2930 type_instance_ad_hoc_range(const generic_type & t, const std::string & n, int b1, int b2):
2931 my_type{t}, type_instance_range{n, b1, b2}
2932 {
2933 }
2934
2935 virtual void update(placeholder_with_value & v, machine & m, basic_generator & g) override;
2936
2937 virtual void report(std::ostream & s) const override;
2938 };
2939
2944 {
2945 private:
2946 const std::string placeholder;
2947 const std::string type_name;
2948 const bool is_finite; // some of the dimensions can be finite
2949 public:
2950 cartesian_product_dimension(const std::string & p, const std::string & t, bool f): placeholder{p}, type_name{t}, is_finite{f} {}
2952
2953 void report(std::ostream & s) const;
2954 };
2955
2960 {
2961 private:
2962 std::vector<std::unique_ptr<cartesian_product_dimension>> vector_of_dimensions;
2963 public:
2965 void add_dimension(std::unique_ptr<cartesian_product_dimension> && d)
2966 {
2967 vector_of_dimensions.push_back(std::move(d));
2968 }
2969 void report(std::ostream & s) const;
2970 };
2971
2972
2974 {
2975 private:
2976 std::unique_ptr<description_of_a_cartesian_product> my_cartesian_product;
2977 public:
2978 family_of_variables(std::unique_ptr<description_of_a_cartesian_product> && d): my_cartesian_product{std::move(d)} {}
2980 };
2981
2982
2984 {
2985 private:
2986 public:
2988 virtual void report(std::ostream & s) const = 0;
2989
2992
2993 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const { return 0; }
2994 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const { return 0.0; }
2995 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const { return ""; }
2996 virtual std::string get_actual_identifier_value(const machine & m, const basic_generator & g) const { return ""; }
2997 virtual void get_actual_code_value(const machine & m, const basic_generator & g, code & target) const {}
2998
2999 };
3000
3007 {
3008 private:
3009 std::unique_ptr<generic_literal> my_value;
3011 public:
3013 my_value{std::move(v)}, actual_type{t} {}
3014 virtual void report(std::ostream & s) const override;
3015
3017
3018 virtual int get_actual_integer_value(const machine & m, const basic_generator & g) const override { return my_value->get_actual_integer_value(m, g); }
3019 virtual double get_actual_float_value(const machine & m, const basic_generator & g) const override { return my_value->get_actual_float_value(m, g); }
3020 virtual std::string get_actual_string_value(const machine & m, const basic_generator & g) const override { return my_value->get_actual_string_value(m, g); }
3021 virtual std::string get_actual_identifier_value(const machine & m, const basic_generator & g) const override { return my_value->get_actual_enum_value(m, g); }
3022 virtual void get_actual_code_value(const machine & m, const basic_generator & g, code & target) const;
3023 };
3024
3029 {
3030 private:
3031 std::unique_ptr<generic_literal> my_value;
3032 public:
3033 assignment_source_code_pattern(std::unique_ptr<generic_literal> && v): my_value{std::move(v)} {}
3034 virtual void report(std::ostream & s) const override;
3035
3038
3039 virtual void get_actual_code_value(const machine & m, const basic_generator & g, code & target) const override;
3040 };
3041
3043 {
3044 private:
3045 std::unique_ptr<generic_value> my_value;
3046 public:
3047 assignment_source_variable_value(std::unique_ptr<generic_value> && v): my_value{std::move(v)} {}
3048 virtual void report(std::ostream & s) const override;
3049
3050
3051 virtual void get_actual_code_value(const machine & m, const basic_generator & g, code & target) const override;
3052
3053 };
3054
3055
3060 {
3061 private:
3062 std::unique_ptr<generic_name> my_assignment_target;
3063 std::unique_ptr<description_of_a_cartesian_product> my_cartesian_product;
3064 std::unique_ptr<assignment_source> my_assignment_source;
3065
3066 public:
3067 assignment_event(std::unique_ptr<generic_name> && t,
3068 std::unique_ptr<description_of_a_cartesian_product> && p,
3069 std::unique_ptr<assignment_source> && s):
3070 my_assignment_target{std::move(t)},
3071 my_cartesian_product{std::move(p)},
3072 my_assignment_source{std::move(s)} {}
3073 virtual ~assignment_event() {} // this may be not necessary
3074 void report(std::ostream & s) const;
3075 bool get_match(const signature & s, const machine & m, const basic_generator & g, matching_protocol & target) const;
3076 const assignment_source& get_source() const { return *my_assignment_source; }
3077 };
3078
3079
3080 template <typename TYPE, int REPRESENTATION_TYPE> class simple_variable_with_value: public variable_with_value
3081 {
3082 protected:
3083 TYPE value;
3084 public:
3085 simple_variable_with_value(std::shared_ptr<signature> && s, TYPE v): variable_with_value{std::move(s)}, value{v} {}
3086
3087 virtual void report(std::ostream & s) const override
3088 {
3089 actual_name->report(s);
3090 s << '=' << value << "\n";
3091 }
3092
3094 {
3095 return static_cast<actual_memory_representation_type>(REPRESENTATION_TYPE);
3096 }
3097
3098 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value<>"; }
3099 };
3100
3101 class simple_variable_with_value_integer: public simple_variable_with_value<int, static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>
3102 {
3103 public:
3104 simple_variable_with_value_integer(std::shared_ptr<signature> && s, int v): simple_variable_with_value<int, static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>(std::move(s), v) {}
3105
3106 virtual int get_value_integer() const override { return value; }
3107
3108 virtual void assign_value_integer(int v) override { value = v; }
3109
3110 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value_integer"; }
3111
3112 };
3113
3114 class simple_variable_with_value_float: public simple_variable_with_value<double, static_cast<int>(variable_with_value::actual_memory_representation_type::FLOAT)>
3115 {
3116 public:
3117 simple_variable_with_value_float(std::shared_ptr<signature> && s, double v): simple_variable_with_value<double, static_cast<int>(variable_with_value::actual_memory_representation_type::FLOAT)>(std::move(s), v) {}
3118
3119 virtual double get_value_float() const override { return value; }
3120
3121 virtual void assign_value_float(double v) override { value = v; }
3122
3123 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value_float"; }
3124 };
3125
3126 class simple_variable_with_value_string: public simple_variable_with_value<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::STRING)>
3127 {
3128 public:
3129 simple_variable_with_value_string(std::shared_ptr<signature> && s, std::string v): simple_variable_with_value<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::STRING)>(std::move(s), v) {}
3130
3131 virtual std::string get_value_string() const override { return value; }
3132
3133 virtual void assign_value_string(std::string v) override { value = v; }
3134
3135 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value_string"; }
3136 };
3137
3138 class simple_variable_with_value_enum: public simple_variable_with_value<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::ENUM)>
3139 {
3140 public:
3141 simple_variable_with_value_enum(std::shared_ptr<signature> && s, std::string v): simple_variable_with_value<std::string, static_cast<int>(variable_with_value::actual_memory_representation_type::ENUM)>(std::move(s), v) {}
3142
3143 virtual std::string get_value_enum() const override { return value; }
3144
3145 virtual void assign_value_enum(std::string v) override { value = v; }
3146
3147 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value_enum"; }
3148 };
3149
3154 {
3155 private:
3156 std::unique_ptr<code> value;
3157 public:
3158 variable_with_value_code(std::shared_ptr<signature> && s, std::unique_ptr<code> && v): variable_with_value{std::move(s)}, value{std::move(v)} {}
3159
3160 virtual void report(std::ostream & s) const override;
3161
3162 virtual void get_value_code(code & target) const;
3163
3164 virtual void assign_value_code(const code & ci) override;
3165
3170
3171 virtual std::string get_debug_type_name() const override { return "simple_variable_with_value_code"; }
3172 };
3173
3174
3175 class simple_placeholder_for_enum: public simple_placeholder_with_value<std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator, static_cast<int>(variable_with_value::actual_memory_representation_type::ENUM)>
3176 {
3177 private:
3178 using iterator_type = std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator;
3179 const iterator_type first, last;
3180 public:
3181 simple_placeholder_for_enum(const std::string & p, const iterator_type f, const iterator_type l, type_instance * ti):
3182 simple_placeholder_with_value<std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator, static_cast<int>(variable_with_value::actual_memory_representation_type::ENUM)>
3183 {p, f, ti}, first{f}, last{l} {}
3184
3185 virtual void report(std::ostream & s) const override
3186 {
3187 s << placeholder << '=' << (*value)->get_name() << "\n";
3188 }
3189
3190 virtual bool get_is_valid() const override
3191 {
3192 return value != last;
3193 }
3194
3195 virtual bool get_is_terminated() const override
3196 {
3197 return value == last;
3198 }
3199 virtual void increment() override { if (value == last) value = first; else value++; }
3200
3201 virtual std::string get_value_enum() const override { return (*value)->get_name(); }
3202
3203 virtual bool get_exceeds_level(int max_level) const
3204 {
3205 return (*value)->get_level() > max_level;
3206 }
3207
3208 virtual int get_level() const { return (*value)->get_level(); }
3209 };
3210
3211
3213 static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>
3214 {
3215 public:
3216 simple_placeholder_for_infinite_range(const std::string & p, type_instance * ti): simple_placeholder_with_value<int, static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>{p, 0, ti} {}
3217
3218 virtual void report(std::ostream & s) const override
3219 {
3220 s << placeholder << '=' << value << "\n";
3221 }
3222 virtual bool get_is_valid() const override
3223 {
3224 return true;
3225 }
3226 virtual bool get_is_terminated() const override
3227 {
3228 return false;
3229 }
3230 virtual void increment() override { value++; }
3231
3232 };
3233
3234
3236 static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>
3237 {
3238 private:
3239 int first, last;
3240
3241 public:
3242 simple_placeholder_for_range(const std::string & p, const int f, const int l, type_instance * ti): simple_placeholder_with_value<int, static_cast<int>(variable_with_value::actual_memory_representation_type::INTEGER)>{p, f, ti}, first{f}, last{l+1} {}
3243
3244 virtual void report(std::ostream & s) const override
3245 {
3246 s << placeholder << '=' << value << "\n";
3247 }
3248 virtual bool get_is_valid() const override
3249 {
3250 return value != last;
3251 }
3252 virtual bool get_is_terminated() const override
3253 {
3254 return value >= last;
3255 }
3256 virtual void increment() override { if (value == last) value = first; else value++; }
3257
3258
3259 virtual void update_int_value(int f, int l) override;
3260
3261 };
3262
3267 {
3268 protected:
3269 int max_size; // for reading
3270
3274 void read_string_of_x_characters(std::string & target, unsigned x);
3275
3276 public:
3278 void set_max_size(int ms) { max_size = ms; }
3279 virtual ~generic_stream() {}
3280 virtual bool get_allows_input() const { return false; }
3281 virtual bool get_allows_output() const { return false; }
3282 virtual bool get_should_be_opened() const { return false; }
3283 virtual bool get_should_be_closed() const { return false; }
3284 virtual std::ostream& get_output_stream() { return std::cout; }
3285 virtual std::istream& get_input_stream() { return std::cin; }
3286 virtual std::string get_result() const { return ""; }
3287 virtual std::string getline_result() const { return ""; }
3288 virtual void set_result(const std::string & r) {}
3289 virtual int read_integer() { return 0; }
3290 virtual bool read_char(unsigned char & target) { return false; }
3291 virtual std::string read_string() { std::string t; read_string_of_x_characters(t, max_size); return t; }
3292 virtual void getline() {}
3293
3294 virtual bool get_is_good() { return true; }
3295 };
3296
3298 {
3299 public:
3300 virtual bool get_allows_output() const override { return true; }
3301 virtual std::ostream& get_output_stream() override { return std::cout; }
3302 };
3303
3305 {
3306 public:
3307 virtual bool get_allows_output() const override { return true; }
3308 virtual std::ostream& get_output_stream() override { return std::cerr; }
3309 };
3310
3312 {
3313 private:
3314 std::string my_getline_result;
3315 public:
3316 virtual bool get_allows_input() const override { return true; }
3317 virtual int read_integer() override { int n; std::cin >> std::setw(max_size) >> n; return n; }
3318 virtual bool read_char(unsigned char & target) override { target = std::cin.get(); return std::cin.operator bool(); }
3319
3320 virtual void getline() override { std::getline(std::cin, my_getline_result); } // TODO error handling
3321 virtual std::string getline_result() const override { return my_getline_result; }
3322
3323 virtual bool get_is_good() override { return std::cin.good(); }
3324 };
3325
3327 {
3328 public:
3329 };
3330
3332 {
3333 private:
3334 std::ofstream file_stream;
3335 public:
3336 generic_stream_file_output(const std::string & file_name): file_stream{file_name} {}
3337 virtual bool get_allows_output() const override { return true; }
3338 virtual bool get_should_be_opened() const override { return true; }
3339 virtual bool get_should_be_closed() const override { return true; }
3340 virtual std::ostream& get_output_stream() override { return file_stream; }
3341
3342 virtual bool get_is_good() override { return file_stream.good(); }
3343 };
3344
3346 {
3347 private:
3348 std::ifstream file_stream;
3349 std::string my_getline_result;
3350 public:
3351 generic_stream_file_input(const std::string & file_name): file_stream{file_name} {}
3352
3353 virtual bool get_allows_input() const { return true; }
3354 virtual bool get_should_be_opened() const override { return true; }
3355 virtual bool get_should_be_closed() const override { return true; }
3356 virtual std::istream& get_input_stream() override { return file_stream; }
3357
3358 virtual bool read_char(unsigned char & target) override { target = file_stream.get(); return file_stream.operator bool(); }
3359 virtual void getline() override { std::getline(file_stream, my_getline_result); } // TODO error handling
3360 virtual std::string getline_result() const override { return my_getline_result; }
3361
3362 virtual int read_integer() override { int result = 0; file_stream >> result; return result; }
3363
3364 virtual bool get_is_good() override { return file_stream.good(); }
3365 };
3366
3368 {
3369 private:
3370 std::stringstream string_stream;
3371 std::string my_getline_result;
3372 public:
3374 generic_stream_stringstream(const std::string & s): string_stream{s} {}
3375
3376 virtual bool get_allows_input() const { return true; }
3377 virtual bool get_allows_output() const { return true; }
3378 virtual std::ostream& get_output_stream() override { return string_stream; }
3379 virtual std::istream& get_input_stream() override { return string_stream; }
3380
3381 virtual std::string get_result() const override { return string_stream.str(); }
3382 virtual void set_result(const std::string & r) override { string_stream.clear(); string_stream.str(r); }
3383
3384 virtual int read_integer() override { int v; string_stream >> v; return v; }
3385
3386 virtual bool read_char(unsigned char & target) override { target = string_stream.get(); return string_stream.operator bool(); }
3387
3388 virtual void getline() override { std::getline(string_stream, my_getline_result); } // TODO error handling
3389 virtual std::string getline_result() const override { return my_getline_result; }
3390
3391 virtual bool get_is_good() override { return string_stream.good(); }
3392 };
3393
3395 {
3396 private:
3397 std::default_random_engine generator;
3398 std::uniform_int_distribution<int> distribution;
3399
3400 std::random_device dev;
3401 std::mt19937 rng;
3402 std::uniform_int_distribution<std::mt19937::result_type> dist;
3403 public:
3404 generic_stream_random_number_stream(int a, int b): rng{dev()}, dist(a, b) {}
3405 virtual bool get_allows_input() const override { return true; }
3406 virtual int read_integer() override;
3407 };
3408
3410 {
3411 private:
3412 const std::string type_name;
3413 machine & my_machine;
3414 public:
3415 generic_stream_random_enum_stream(const std::string & n, machine & m);
3416 virtual bool get_allows_input() const override { return true; }
3417 virtual std::string read_string() override;
3418 };
3419
3420
3425 {
3426 private:
3428 friend class signature;
3429 static constexpr int max_match_group_index = 10;
3430
3431 protected:
3432 std::vector<std::shared_ptr<const statement>> vector_of_type_definiton_statements;
3433 std::vector<std::shared_ptr<const statement>> vector_of_variable_definition_statements;
3434
3435 std::vector<std::shared_ptr<type_instance>> vector_of_type_instances, vector_of_ad_hoc_type_instances;
3436 std::map<std::string, std::shared_ptr<type_instance>> map_type_name_to_type_instance;
3437
3438 std::vector<std::shared_ptr<family_of_variables>> vector_of_variable_families;
3439
3440 std::vector<std::unique_ptr<assignment_event>> vector_of_assignment_events;
3441
3442 std::vector<std::shared_ptr<variable_with_value>> memory;
3443
3444 std::map<std::string, std::shared_ptr<variable_with_value>> map_signature_string_representation_to_variable_with_value;
3445
3446 std::vector<std::unique_ptr<generic_stream>> vector_of_streams;
3447
3448 std::vector<std::unique_ptr<signature_regular_expression>> vector_of_signature_regular_expressions;
3449
3450 public:
3451 // these methods are useful for certain reflection-like capabilities
3452 int get_amount_of_variables_in_the_memory() const { return memory.size(); }
3454 {
3455 if (i>=0 && i<memory.size()) return memory[i]->get_amount_of_signature_items();
3456 return 0;
3457 } // TODO - error handling
3458 std::string get_signature_item_representation(int var_index, int item_index) const;
3459 std::string get_signature_item_type_name(int var_index, int item_index) const;
3460
3461 // The machine should be prevented to create files in sandbox environments
3462 virtual bool get_can_create_files() const { return true; }
3463
3464 int get_max_enum_type_index(const std::string & tn) const;
3465
3466 std::string get_enum_type_item(const std::string & tn, int i) const;
3467
3468 const std::vector<std::unique_ptr<assignment_event>> & get_vector_of_assignment_events() const { return vector_of_assignment_events; }
3469
3470 void add_signature_regular_expression(std::unique_ptr<signature_regular_expression> && e)
3471 {
3472 vector_of_signature_regular_expressions.push_back(std::move(e));
3473 }
3474
3475 void add_stream(std::unique_ptr<generic_stream> && s)
3476 {
3477 vector_of_streams.push_back(std::move(s));
3478 }
3479
3480 void add_assignment_event(std::unique_ptr<assignment_event> && e)
3481 {
3482 vector_of_assignment_events.push_back(std::move(e));
3483 }
3484
3485 void add_type_definition_statement(std::shared_ptr<const statement> && s)
3486 {
3487 vector_of_type_definiton_statements.push_back(std::move(s));
3488 }
3489
3490 void add_variable_definition_statement(std::shared_ptr<const statement> && s)
3491 {
3492 vector_of_variable_definition_statements.push_back(std::move(s));
3493 }
3494
3495 bool get_type_instance_is_known(const std::string & type_name) const
3496 {
3497 return map_type_name_to_type_instance.find(type_name) != map_type_name_to_type_instance.end();
3498 }
3499
3500 type_instance & get_type_instance(const std::string & type_name) const
3501 {
3502 return *map_type_name_to_type_instance.at(type_name);
3503 }
3504
3505 void get_first_and_last_iterators_for_enum_type(const std::string & type_name, std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator & f, std::vector<std::unique_ptr<type_instance_enum_value>>::const_iterator & l) const
3506 {
3507 f = map_type_name_to_type_instance.at(type_name)->get_first_iterator_for_enum();
3508 l = map_type_name_to_type_instance.at(type_name)->get_last_iterator_for_enum();
3509 }
3510
3511 void get_first_and_last_iterators_for_range_type(const std::string & type_name, int & f, int & l) const
3512 {
3513 f = map_type_name_to_type_instance.at(type_name)->get_first_iterator_for_range();
3514 l = map_type_name_to_type_instance.at(type_name)->get_last_iterator_for_range();
3515 }
3516
3517 void get_first_and_last_iterators_for_ad_hoc_range_type(const std::string & type_name, int & f, int & l) const;
3518
3519 void add_type_instance(std::shared_ptr<type_instance> && i)
3520 {
3521 auto [it, success] = map_type_name_to_type_instance.insert(std::pair(i->get_name(), i));
3522
3523 if (!success)
3524 {
3525 throw std::runtime_error("failed to insert a type instance into machine's map");
3526 }
3527
3528 std::shared_ptr<type_instance> i2{i};
3529 vector_of_type_instances.push_back(std::move(i2));
3530 }
3531
3536
3537 void add_variable_with_value(std::shared_ptr<variable_with_value> && vv);
3538
3539 void expand(int i);
3540
3541 void report(std::ostream & s) const;
3542
3544
3546
3548
3550
3552
3554
3555 std::string get_variable_value_enum(const signature & vn) const;
3556
3557 std::string get_variable_value_string(const signature & vn) const;
3558
3560
3561 double get_variable_value_float(const signature & vn) const;
3562
3563 void get_variable_value_code(const signature & vn, code & target) const;
3564
3566
3568
3570
3571 virtual bool get_is_user_defined_executable(const signature & s) const { return false; }
3572
3574
3575
3576 int get_last_created_stream_index() const { return vector_of_streams.size()-1; } // because we only create streams, we do not delete them (this may change!!!)
3577
3578 int get_last_created_signature_regular_expression_index() const { return vector_of_signature_regular_expressions.size()-1; } // because we only create signature regular expressions, we do not delete them (this may change!!!)
3579
3580 int get_amount_of_streams() const { return vector_of_streams.size(); }
3581
3583
3585
3587
3588 type_instance* create_an_ad_hoc_type(const generic_type & t, generator & g, const std::string & tn);
3589
3590 void add_ad_hoc_type(std::shared_ptr<type_instance_ad_hoc_range> && t);
3591
3593
3595
3597 };
3598
3603 class code
3604 {
3605 private:
3606 std::shared_ptr<list_of_statements> body;
3607
3608 bool is_main; // this is used for pretty-printing only
3609
3610 public:
3614 code(list_of_statements * const l): body{std::make_shared<list_of_statements>(nullptr, l)}, is_main{false}
3615 {
3616 body->set_is_main(is_main);
3617 }
3618
3619 code(): body{std::make_shared<list_of_statements>(nullptr, nullptr)}, is_main{false}
3620 {
3621 body->set_is_main(is_main);
3622 }
3623
3624 code(const code & c);
3625
3626 void execute(machine & m, std::shared_ptr<basic_generator> father=nullptr) const;
3627
3628 void add_statement(std::shared_ptr<statement> && s)
3629 {
3630 body->add_statement(std::move(s));
3631 }
3632
3633 void set_is_main(bool m)
3634 {
3635 is_main = m;
3636 body->set_is_main(m);
3637 }
3638
3639 const list_of_statements& get_body() const { return *body; }
3640
3641 void report(std::ostream & s) const;
3642
3644
3645 void get_actual_code_value(const machine & m, const basic_generator & g, const replacing_policy & p, code & target) const;
3646
3647 void add_content_to_signature(const generic_name_item & s, signature & target, const machine & m, const basic_generator & g) const;
3648
3649 std::string get_actual_text_representation(const machine & m, const basic_generator & g) const;
3650
3651 void get_result_replacing_placeholders(const machine & m, const basic_generator & g, const replacing_policy & p, generic_name & target) const;
3652
3653 bool operator==(const code & c) const;
3654 };
3655
3660 {
3661 private:
3662 code my_code;
3663 public:
3665
3666 void execute(machine & m) const;
3667 void report(std::ostream & s) const { my_code.report(s); }
3668
3669 void add_statement(std::shared_ptr<statement> && s);
3670
3671 };
3672
3673
3679 {
3680 private:
3681 program & my_program;
3682
3683 static parser * the_parser_pointer;
3684
3685 public:
3686 static void register_parser(parser * p) { the_parser_pointer = p; }
3687 static parser * get_parser_pointer() { return the_parser_pointer; }
3688
3690
3691 int parse(const char * filename);
3692 int parse_string(const std::string & code, std::ostream & error_stream);
3693
3695 };
3696
3697}
3698
3699std::ostream & operator<<(std::ostream & s, const chomik::generic_value & v);
3700std::ostream & operator<<(std::ostream & s, const chomik::code & c);
3701std::ostream & operator<<(std::ostream & s, const chomik::generic_name & n);
3702std::ostream & operator<<(std::ostream & s, const chomik::basic_generator & g);
3703std::ostream & operator<<(std::ostream & s, const chomik::generator & g);
3704std::ostream & operator<<(std::ostream & s, const chomik::generic_name_item & i);
3705std::ostream & operator<<(std::ostream & s, const chomik::signature & x);
3706std::ostream & operator<<(std::ostream & s, const chomik::signature_item & x);
3707std::ostream & operator<<(std::ostream & s, const chomik::statement & x);
3708std::ostream & operator<<(std::ostream & s, const chomik::generic_type & x);
3709std::ostream & operator<<(std::ostream & s, const chomik::type_definition_body & x);
3710std::ostream & operator<<(std::ostream & s, const chomik::type_definition & x);
3711std::ostream & operator<<(std::ostream & s, const chomik::assignment_event & x);
3712std::ostream & operator<<(std::ostream & s, const chomik::assignment_source & x);
3713std::ostream & operator<<(std::ostream & s, const chomik::placeholder_with_value & x);
3714std::ostream & operator<<(std::ostream & s, const chomik::matching_protocol & x);
3715std::ostream & operator<<(std::ostream & s, const chomik::generic_literal & l);
3716#endif
std::ostream & operator<<(std::ostream &s, const chomik::generic_value &v)
Definition chomik.h:3060
const assignment_source & get_source() const
Definition chomik.h:3076
assignment_event(std::unique_ptr< generic_name > &&t, std::unique_ptr< description_of_a_cartesian_product > &&p, std::unique_ptr< assignment_source > &&s)
Definition chomik.h:3067
void report(std::ostream &s) const
bool get_match(const signature &s, const machine &m, const basic_generator &g, matching_protocol &target) const
virtual ~assignment_event()
Definition chomik.h:3073
virtual void get_actual_code_value(const machine &m, const basic_generator &g, code &target) const override
assignment_source_code_pattern(std::unique_ptr< generic_literal > &&v)
Definition chomik.h:3033
virtual void report(std::ostream &s) const override
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type() const override
Definition chomik.h:3036
virtual void report(std::ostream &s) const override
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:3019
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:3020
virtual void get_actual_code_value(const machine &m, const basic_generator &g, code &target) const
virtual std::string get_actual_identifier_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:3021
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:3018
assignment_source_literal_value(std::unique_ptr< generic_literal > &&v, variable_with_value::actual_memory_representation_type t)
Definition chomik.h:3012
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type() const override
Definition chomik.h:3016
virtual void get_actual_code_value(const machine &m, const basic_generator &g, code &target) const override
virtual void report(std::ostream &s) const override
assignment_source_variable_value(std::unique_ptr< generic_value > &&v)
Definition chomik.h:3047
Definition chomik.h:2984
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2993
virtual void report(std::ostream &s) const =0
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type() const
Definition chomik.h:2990
virtual void get_actual_code_value(const machine &m, const basic_generator &g, code &target) const
Definition chomik.h:2997
virtual std::string get_actual_identifier_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2996
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2995
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2994
virtual ~assignment_source()
Definition chomik.h:2987
Definition chomik.h:2539
virtual void get_copy(std::shared_ptr< statement > &target) const override
assignment_statement(generic_name *const n, generic_value *const v, unsigned new_line_number)
Definition chomik.h:2554
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
virtual bool get_is_code_assignment(machine &m) const override
Definition chomik.h:2582
assignment_statement(const generic_value &gv, unsigned new_line_number)
Definition chomik.h:2556
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2572
virtual void report(std::ostream &s) const override
assignment_statement(const generic_name &gn, const generic_value &gv, unsigned new_line_number)
virtual statement_type get_statement_type() const override
Definition chomik.h:2566
Definition chomik.h:363
static dictionary_of_identifiers our_dictionary
Definition chomik.h:365
Definition chomik.h:1532
virtual void initialize_description_of_a_cartesian_product(description_of_a_cartesian_product &target) const =0
virtual ~basic_generator()
Definition chomik.h:1539
virtual std::string get_actual_text_representation_of_a_placeholder(const std::string &placeholder) const
Definition chomik.h:1585
virtual void add_placeholder(const std::string &p, std::shared_ptr< generic_type > &&t)
Definition chomik.h:1555
virtual void report(std::ostream &s) const
Definition chomik.h:1553
virtual double get_placeholder_value_float(const std::string &p) const
std::string get_placeholder_value_enum(const std::string &p) const
virtual placeholder_with_value & get_placeholder_with_value(const std::string &p)
virtual void add_mapping(const std::string &f, const std::string &s)
Definition chomik.h:1591
virtual void initialize_mapping(const matching_protocol &mp)
Definition chomik.h:1593
virtual const std::string convert_childs_placeholder_name_to_father(const std::string &cpn) const
Definition chomik.h:1545
virtual bool get_can_have_placeholders() const
Definition chomik.h:1557
virtual void debug() const
Definition chomik.h:1595
static simple_placeholder_with_value_and_report< int, static_cast< int >(chomik::variable_with_value::actual_memory_representation_type::INTEGER)> dummy
Definition chomik.h:1536
virtual void initialize(machine &m)=0
void set_father(std::shared_ptr< basic_generator > f)
Definition chomik.h:1543
virtual void increment(machine &m)=0
virtual bool get_the_cartesian_product_of_placeholder_types_is_finite() const
std::string get_placeholder_value_string(const std::string &p) const
virtual int get_placeholder_value_integer(const std::string &p) const
std::weak_ptr< basic_generator > my_father
Definition chomik.h:1534
virtual bool get_terminated() const
Definition chomik.h:1583
virtual bool get_the_cartesian_product_of_placeholder_types_is_empty() const
virtual bool get_the_cartesian_product_of_placeholder_types_is_small(machine &m) const
virtual bool get_has_placeholder_with_value(const std::string &p) const
Definition chomik.h:1547
virtual void finalize(machine &m)
Definition chomik.h:1597
virtual bool get_is_valid()
Definition chomik.h:1579
virtual bool get_the_cartesian_product_of_placeholder_types_has_one_item() const
virtual void get_placeholder_value_code(const std::string &p, code &target) const
virtual const placeholder_with_value & get_placeholder_with_value(const std::string &p) const
virtual bool get_has_placeholder(const std::string &p) const
Definition chomik.h:1587
Definition chomik.h:2944
cartesian_product_dimension(const std::string &p, const std::string &t, bool f)
Definition chomik.h:2950
virtual ~cartesian_product_dimension()
Definition chomik.h:2951
void report(std::ostream &s) const
Definition chomik.h:1148
virtual bool get_match_code(const code &v, const machine &m, const basic_generator &g) const override
code_name_item(const code &c)
virtual bool get_is_code() const override
Definition chomik.h:1157
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
code_name_item()
Definition chomik.h:1152
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1169
virtual void report(std::ostream &s) const override
Definition chomik.h:443
code_signature_item(const generic_name_item &s, const code &c)
Definition chomik.h:447
virtual void report(std::ostream &s) const override
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const override
virtual bool get_it_is_code() const override
Definition chomik.h:453
virtual void get_copy(std::shared_ptr< signature_item > &target) const
code_signature_item(const code_signature_item &s)
Definition chomik.h:449
virtual std::string get_type_name() const override
Definition chomik.h:459
Definition chomik.h:3604
bool operator==(const code &c) const
void add_content_to_signature(const generic_name_item &s, signature &target, const machine &m, const basic_generator &g) const
void report(std::ostream &s) const
void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const
code(list_of_statements *const l)
Definition chomik.h:3614
void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const
code(const code &c)
std::string get_actual_text_representation(const machine &m, const basic_generator &g) const
void add_statement(std::shared_ptr< statement > &&s)
Definition chomik.h:3628
code()
Definition chomik.h:3619
void execute(machine &m, std::shared_ptr< basic_generator > father=nullptr) const
const list_of_statements & get_body() const
Definition chomik.h:3639
void add_placeholders_to_generator(basic_generator &g) const
void set_is_main(bool m)
Definition chomik.h:3633
void report(std::ostream &s) const
description_of_a_cartesian_product(const basic_generator &g)
void add_dimension(std::unique_ptr< cartesian_product_dimension > &&d)
Definition chomik.h:2965
Definition chomik.h:351
dictionary_of_identifiers(const std::string &d)
Definition chomik.h:356
int get_identifier_index(const std::string id)
const std::string get_identifier_by_index(int index) const
Definition chomik.h:2590
execute_statement(unsigned new_line_number)
Definition chomik.h:2592
virtual ~execute_statement()
Definition chomik.h:2593
Definition chomik.h:2602
virtual statement_type get_statement_type() const override
Definition chomik.h:2617
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual void report(std::ostream &s) const override
virtual void get_copy(std::shared_ptr< statement > &target) const override
Definition chomik.h:2627
execute_value_statement(std::unique_ptr< generic_value > &&v, unsigned new_line_number)
Definition chomik.h:2613
virtual void add_placeholders_to_generator(basic_generator &g) const override
execute_variable_value_statement(unsigned new_line_number)
Definition chomik.h:2654
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
void add_generic_name_item(std::shared_ptr< generic_name_item > &&i)
Definition chomik.h:2658
virtual void get_copy(std::shared_ptr< statement > &target) const override
Definition chomik.h:2673
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
execute_variable_value_statement(std::unique_ptr< generic_name > &&n, unsigned new_line_number)
Definition chomik.h:2652
virtual statement_type get_statement_type() const override
Definition chomik.h:2663
virtual void report(std::ostream &s) const override
Definition chomik.h:2685
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
expand_statement(int nd, unsigned new_line_number)
Definition chomik.h:2689
virtual statement_type get_statement_type() const override
Definition chomik.h:2691
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2700
virtual void report(std::ostream &s) const override
Definition chomik.h:2693
virtual void get_copy(std::shared_ptr< statement > &target) const
Definition chomik.h:2704
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
virtual void initialize_description_of_a_cartesian_product(description_of_a_cartesian_product &target) const override
virtual const placeholder_with_value & get_placeholder_with_value(const std::string &p) const override
virtual void initialize_mapping(const matching_protocol &mp) override
virtual placeholder_with_value & get_placeholder_with_value(const std::string &p) override
virtual void report(std::ostream &s) const override
virtual bool get_has_placeholder_with_value(const std::string &p) const override
external_placeholder_generator(const std::string &filename, unsigned new_line_number)
virtual void increment(machine &m) override
virtual void initialize(machine &m) override
void add_placeholder_with_value(std::shared_ptr< placeholder_with_value > &&p)
Definition chomik.h:2974
virtual ~family_of_variables()
Definition chomik.h:2979
family_of_variables(std::unique_ptr< description_of_a_cartesian_product > &&d)
Definition chomik.h:2978
Definition chomik.h:1497
const std::string & get_name() const
Definition chomik.h:1505
generator_placeholder(const std::string &n, std::shared_ptr< generic_type > &&t)
Definition chomik.h:1503
bool get_type_is_finite() const
Definition chomik.h:1507
const generic_type & get_placeholder_type() const
Definition chomik.h:1514
generic_type & get_placeholder_type()
Definition chomik.h:1512
Definition chomik.h:1663
virtual const placeholder_with_value & get_placeholder_with_value(const std::string &p) const override
virtual bool get_terminated() const override
virtual void finalize(machine &m) override
generator(const generic_name &gn, const std::string &filename, unsigned new_line_number)
virtual placeholder_with_value & get_placeholder_with_value(const std::string &p) override
virtual int get_placeholder_value_integer(const std::string &p) const override
virtual void initialize(machine &m) override
virtual std::string get_actual_text_representation_of_a_placeholder(const std::string &placeholder) const override
Definition chomik.h:1700
virtual bool get_the_cartesian_product_of_placeholder_types_is_empty() const override
Definition chomik.h:1726
virtual bool get_has_placeholder(const std::string &p) const override
bool get_does_not_exceed_level(int max_level) const
virtual void get_placeholder_value_code(const std::string &p, code &target) const override
virtual bool get_can_have_placeholders() const
Definition chomik.h:1684
generator(const generic_range &gr, const std::string &filename, unsigned new_line_number)
virtual void increment(machine &m) override
virtual void report(std::ostream &s) const override
void add_placeholder_with_value(std::shared_ptr< placeholder_with_value > &&p)
Definition chomik.h:1707
virtual bool get_has_placeholder_with_value(const std::string &p) const override
virtual bool get_the_cartesian_product_of_placeholder_types_has_one_item() const override
virtual void initialize_description_of_a_cartesian_product(description_of_a_cartesian_product &target) const override
virtual bool get_the_cartesian_product_of_placeholder_types_is_small(machine &m) const override
virtual bool get_is_valid() override
virtual double get_placeholder_value_float(const std::string &p) const override
generator(const generic_value &gv, const std::string &filename, unsigned new_line_number)
virtual void debug() const override
virtual void add_placeholder(const std::string &p, std::shared_ptr< generic_type > &&t) override
generator(const std::string &filename, unsigned new_line_number)
virtual bool get_the_cartesian_product_of_placeholder_types_is_finite() const override
Definition chomik.h:2398
generic_literal_code(std::unique_ptr< code > &&c)
Definition chomik.h:2415
generic_literal_code(list_of_statements *const l)
Definition chomik.h:2405
virtual void report(std::ostream &s) const override
generic_literal_code(const code &c)
Definition chomik.h:2413
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const override
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
generic_literal_code()
Definition chomik.h:2409
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
Definition chomik.h:2422
virtual bool get_is_code() const override
Definition chomik.h:2441
code & get_code()
Definition chomik.h:2418
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual void get_copy(std::unique_ptr< generic_literal > &target) const
Definition chomik.h:2434
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:2445
generic_literal_enum(const char *const tn, generic_name *const gn)
Definition chomik.h:2453
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2488
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
Definition chomik.h:2463
virtual std::string get_actual_enum_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2481
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:2468
virtual void get_copy(std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2483
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2472
generic_literal_enum(const std::string &tn, const generic_name &gn)
Definition chomik.h:2455
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:2477
virtual void report(std::ostream &s) const override
Definition chomik.h:2457
Definition chomik.h:2191
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
Definition chomik.h:2206
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const override
generic_literal_placeholder(const char *const p, generic_type *const t, variable_with_value::actual_memory_representation_type e)
Definition chomik.h:2200
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const override
virtual void report(std::ostream &s) const override
generic_literal_placeholder(const std::string &p, std::unique_ptr< generic_type > &&t, variable_with_value::actual_memory_representation_type e)
Definition chomik.h:2203
virtual void get_copy(std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2224
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2156
virtual void report(std::ostream &s) const =0
virtual std::string get_actual_enum_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2169
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const =0
virtual ~generic_literal()
Definition chomik.h:2158
virtual bool get_is_code() const
Definition chomik.h:2183
virtual void get_copy(std::unique_ptr< generic_literal > &target) const =0
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const =0
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const
Definition chomik.h:2167
virtual void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:2165
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const =0
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2173
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2175
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2171
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const =0
Definition chomik.h:894
virtual void add_placeholders_to_generator(basic_generator &g) const =0
virtual bool get_match_code(const code &v, const machine &m, const basic_generator &g) const
Definition chomik.h:930
virtual bool get_is_variable_value() const
Definition chomik.h:932
virtual void report(std::ostream &s) const =0
virtual bool get_is_string() const
Definition chomik.h:918
virtual bool get_match_string(const std::string &v, const machine &m, const basic_generator &g) const
Definition chomik.h:928
virtual void add_content_to_signature(signature &target) const
Definition chomik.h:904
virtual bool get_match_identifier(const std::string &v, const machine &m, const basic_generator &g) const
Definition chomik.h:929
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const =0
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const =0
virtual ~generic_name_item()
Definition chomik.h:896
virtual bool get_match_float(double v, const machine &m, const basic_generator &g) const
Definition chomik.h:927
virtual bool get_is_float() const
Definition chomik.h:916
virtual std::string get_placeholder_name() const
Definition chomik.h:924
virtual bool get_match_integer(int v, const machine &m, const basic_generator &g) const
Definition chomik.h:926
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const =0
virtual bool get_is_code() const
Definition chomik.h:920
virtual bool get_is_identifier() const
Definition chomik.h:912
virtual bool get_is_placeholder() const
Definition chomik.h:922
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const =0
virtual bool get_is_integer() const
Definition chomik.h:914
Definition chomik.h:941
generic_name(const generic_name &gn)
generic_name(list_of_generic_name_items *const l)
void report(std::ostream &s) const
void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const
const std::vector< std::shared_ptr< generic_name_item > > & get_vector_of_name_items() const
Definition chomik.h:956
std::string get_actual_text_representation(const machine &m, const basic_generator &g) const
void add_placeholders_to_generator(basic_generator &g) const
bool operator==(const generic_name &n) const
void add_generic_name_item(std::shared_ptr< generic_name_item > &&i)
Definition chomik.h:962
generic_range_boundary_int_literal(const int i)
Definition chomik.h:666
virtual void report(std::ostream &s) const override
Definition chomik.h:668
virtual int get_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:673
virtual void get_copy(std::unique_ptr< generic_range_boundary > &target) const override
Definition chomik.h:678
generic_range_boundary_variable_value(generic_name *gn)
Definition chomik.h:694
generic_range_boundary_variable_value(const generic_name &gn)
virtual int get_value(const machine &m, const basic_generator &g) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual void get_copy(std::unique_ptr< generic_range_boundary > &target) const override
Definition chomik.h:704
virtual void report(std::ostream &s) const override
Definition chomik.h:648
virtual int get_value(const machine &m, const basic_generator &g) const =0
virtual ~generic_range_boundary()
Definition chomik.h:650
virtual void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:656
virtual void report(std::ostream &s) const =0
virtual void get_copy(std::unique_ptr< generic_range_boundary > &target) const =0
Definition chomik.h:712
generic_range(std::unique_ptr< generic_range_boundary > &&a, std::unique_ptr< generic_range_boundary > &&b)
Definition chomik.h:722
void report(std::ostream &s) const
Definition chomik.h:725
void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:741
void get_copy(std::unique_ptr< generic_range > &target) const
Definition chomik.h:747
int get_min_value(const machine &m, const basic_generator &g) const
Definition chomik.h:732
generic_range(generic_range_boundary *const min_b, generic_range_boundary *const max_b)
Definition chomik.h:717
int get_max_value(const machine &m, const basic_generator &g) const
Definition chomik.h:736
Definition chomik.h:3346
virtual void getline() override
Definition chomik.h:3359
virtual bool get_should_be_closed() const override
Definition chomik.h:3355
virtual int read_integer() override
Definition chomik.h:3362
virtual bool read_char(unsigned char &target) override
Definition chomik.h:3358
virtual bool get_is_good() override
Definition chomik.h:3364
virtual std::string getline_result() const override
Definition chomik.h:3360
virtual std::istream & get_input_stream() override
Definition chomik.h:3356
virtual bool get_allows_input() const
Definition chomik.h:3353
generic_stream_file_input(const std::string &file_name)
Definition chomik.h:3351
virtual bool get_should_be_opened() const override
Definition chomik.h:3354
Definition chomik.h:3332
generic_stream_file_output(const std::string &file_name)
Definition chomik.h:3336
virtual bool get_should_be_opened() const override
Definition chomik.h:3338
virtual bool get_is_good() override
Definition chomik.h:3342
virtual bool get_allows_output() const override
Definition chomik.h:3337
virtual std::ostream & get_output_stream() override
Definition chomik.h:3340
virtual bool get_should_be_closed() const override
Definition chomik.h:3339
Definition chomik.h:3327
generic_stream_random_enum_stream(const std::string &n, machine &m)
virtual bool get_allows_input() const override
Definition chomik.h:3416
virtual std::string read_string() override
virtual bool get_allows_input() const override
Definition chomik.h:3405
generic_stream_random_number_stream(int a, int b)
Definition chomik.h:3404
virtual std::ostream & get_output_stream() override
Definition chomik.h:3308
virtual bool get_allows_output() const override
Definition chomik.h:3307
virtual bool get_allows_input() const override
Definition chomik.h:3316
virtual bool get_is_good() override
Definition chomik.h:3323
virtual bool read_char(unsigned char &target) override
Definition chomik.h:3318
virtual int read_integer() override
Definition chomik.h:3317
virtual void getline() override
Definition chomik.h:3320
virtual std::string getline_result() const override
Definition chomik.h:3321
virtual bool get_allows_output() const override
Definition chomik.h:3300
virtual std::ostream & get_output_stream() override
Definition chomik.h:3301
Definition chomik.h:3368
virtual int read_integer() override
Definition chomik.h:3384
virtual bool get_allows_output() const
Definition chomik.h:3377
virtual std::istream & get_input_stream() override
Definition chomik.h:3379
virtual std::string getline_result() const override
Definition chomik.h:3389
virtual void set_result(const std::string &r) override
Definition chomik.h:3382
virtual bool read_char(unsigned char &target) override
Definition chomik.h:3386
virtual std::ostream & get_output_stream() override
Definition chomik.h:3378
generic_stream_stringstream()
Definition chomik.h:3373
virtual void getline() override
Definition chomik.h:3388
generic_stream_stringstream(const std::string &s)
Definition chomik.h:3374
virtual bool get_allows_input() const
Definition chomik.h:3376
virtual std::string get_result() const override
Definition chomik.h:3381
virtual bool get_is_good() override
Definition chomik.h:3391
Definition chomik.h:3267
virtual bool get_should_be_closed() const
Definition chomik.h:3283
virtual void getline()
Definition chomik.h:3292
virtual void set_result(const std::string &r)
Definition chomik.h:3288
virtual ~generic_stream()
Definition chomik.h:3279
virtual std::string getline_result() const
Definition chomik.h:3287
generic_stream()
Definition chomik.h:3277
virtual std::istream & get_input_stream()
Definition chomik.h:3285
virtual bool get_is_good()
Definition chomik.h:3294
virtual bool get_allows_output() const
Definition chomik.h:3281
virtual std::string read_string()
Definition chomik.h:3291
void set_max_size(int ms)
Definition chomik.h:3278
virtual bool get_allows_input() const
Definition chomik.h:3280
int max_size
Definition chomik.h:3269
virtual int read_integer()
Definition chomik.h:3289
virtual bool get_should_be_opened() const
Definition chomik.h:3282
virtual bool read_char(unsigned char &target)
Definition chomik.h:3290
void read_string_of_x_characters(std::string &target, unsigned x)
virtual std::string get_result() const
Definition chomik.h:3286
virtual std::ostream & get_output_stream()
Definition chomik.h:3284
Definition chomik.h:585
virtual void get_copy(std::shared_ptr< generic_type > &target) const override
Definition chomik.h:624
virtual void report(std::ostream &s) const
Definition chomik.h:608
virtual bool get_is_an_ad_hoc_type() const override
Definition chomik.h:640
virtual bool get_is_equal(const generic_type &t) const override
Definition chomik.h:634
virtual bool get_is_finite() const override
Definition chomik.h:613
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(const machine &m) const override
generic_type_named(const std::string &n)
Definition chomik.h:591
generic_type_named(const char *const n)
Definition chomik.h:589
virtual std::string get_type_name(const machine &m, const basic_generator &g) const override
Definition chomik.h:593
virtual void get_copy(std::unique_ptr< generic_type > &target) const override
Definition chomik.h:629
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:622
virtual std::string get_low_level_type_name() const override
Definition chomik.h:603
virtual std::string get_generic_type_name() const override
Definition chomik.h:598
Definition chomik.h:757
virtual void get_copy(std::shared_ptr< generic_type > &target) const override
Definition chomik.h:820
virtual bool get_is_finite() const override
Definition chomik.h:778
generic_type_range(generic_range *const nr)
Definition chomik.h:764
virtual void get_copy(std::unique_ptr< generic_type > &target) const override
Definition chomik.h:825
virtual void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:795
virtual std::string get_type_name(const machine &m, const basic_generator &g) const override
Definition chomik.h:800
virtual std::string get_generic_type_name() const override
Definition chomik.h:807
virtual bool get_is_an_ad_hoc_type() const override
Definition chomik.h:836
int get_min_value(const machine &m, const basic_generator &g) const
Definition chomik.h:783
virtual void update_boundaries(machine &m, int &f, int &l, basic_generator &g) const override
Definition chomik.h:841
virtual void report(std::ostream &s) const
Definition chomik.h:773
int get_max_value(const machine &m, const basic_generator &g) const
Definition chomik.h:787
virtual bool get_is_equal(const generic_type &t) const override
Definition chomik.h:830
virtual std::string get_low_level_type_name() const override
Definition chomik.h:815
generic_type_range(const generic_range &rn)
Definition chomik.h:766
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(const machine &m) const override
Definition chomik.h:792
Definition chomik.h:557
virtual std::string get_generic_type_name() const =0
virtual void report(std::ostream &s) const =0
virtual std::string get_low_level_type_name() const =0
virtual bool get_is_equal(const generic_type &t) const =0
virtual bool get_is_an_ad_hoc_type() const =0
virtual ~generic_type()
Definition chomik.h:559
virtual void update_boundaries(machine &m, int &f, int &l, basic_generator &g) const
Definition chomik.h:579
virtual bool get_is_finite() const =0
virtual void get_copy(std::shared_ptr< generic_type > &target) const =0
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(const machine &m) const =0
virtual std::string get_type_name(const machine &m, const basic_generator &g) const =0
virtual void add_placeholders_to_generator(basic_generator &g) const =0
virtual void get_copy(std::unique_ptr< generic_type > &target) const =0
Definition chomik.h:2235
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
Definition chomik.h:2247
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2273
virtual void get_literal_copy(std::unique_ptr< generic_literal > &target) const
Definition chomik.h:2287
virtual void report(std::ostream &s) const override
Definition chomik.h:2251
virtual bool get_is_literal() const override
Definition chomik.h:2285
generic_value_literal(std::unique_ptr< generic_literal > &&l)
Definition chomik.h:2244
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const override
virtual bool get_is_code(machine &m) const override
Definition chomik.h:2292
virtual std::string get_actual_enum_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2271
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const override
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2275
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2261
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:2257
virtual void get_copy(std::unique_ptr< generic_value > &target) const override
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< generic_value > &target) const override
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:2266
generic_value_literal(generic_literal *const l)
Definition chomik.h:2242
Definition chomik.h:2496
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
virtual void get_copy(std::unique_ptr< generic_value > &target) const override
Definition chomik.h:2524
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< generic_value > &target) const override
generic_value_placeholder(const char *const p, generic_type *const t)
Definition chomik.h:2501
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
virtual void report(std::ostream &s) const override
Definition chomik.h:2505
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2516
generic_value_placeholder(const std::string &p, std::shared_ptr< generic_type > &&gt)
Definition chomik.h:2503
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:2093
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const override
generic_value_variable_value(std::unique_ptr< generic_name > &&n)
Definition chomik.h:2103
virtual std::string get_actual_enum_value(const machine &m, const basic_generator &g) const override
generic_value_variable_value(const generic_name &gn)
Definition chomik.h:2105
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const override
virtual void report(std::ostream &s) const override
Definition chomik.h:2107
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const override
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const override
generic_value_variable_value(generic_name *const n)
Definition chomik.h:2101
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
virtual void get_copy(std::unique_ptr< generic_value > &target) const override
Definition chomik.h:2140
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2118
virtual bool get_is_code(machine &m) const override
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< generic_value > &target) const override
Definition chomik.h:2050
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< generic_value > &target) const =0
virtual bool get_is_literal() const
Definition chomik.h:2082
virtual void get_copy(std::unique_ptr< generic_value > &target) const =0
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const =0
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2064
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const =0
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2060
virtual void add_placeholders_to_generator(basic_generator &g) const =0
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2062
virtual void get_literal_copy(std::unique_ptr< generic_literal > &target) const
Definition chomik.h:2078
virtual void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const
Definition chomik.h:2068
virtual std::string get_actual_enum_value(const machine &m, const basic_generator &g) const
Definition chomik.h:2066
virtual bool get_is_code(machine &m) const
Definition chomik.h:2084
virtual ~generic_value()
Definition chomik.h:2052
virtual bool get_is_code_with_placeholders(machine &m, basic_generator &g) const
Definition chomik.h:2080
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const =0
virtual void report(std::ostream &s) const =0
Definition chomik.h:976
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:1032
virtual bool get_is_identifier() const override
Definition chomik.h:1052
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
Definition chomik.h:1005
virtual bool get_match_identifier(const std::string &v, const machine &m, const basic_generator &g) const override
Definition chomik.h:1054
identifier_name_item(const std::string &i)
Definition chomik.h:993
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1043
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:1034
identifier_name_item(const char *const i)
Definition chomik.h:991
virtual void add_content_to_signature(signature &target) const override
Definition chomik.h:1014
virtual void report(std::ostream &s) const override
Definition chomik.h:996
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:1023
Definition chomik.h:2752
std::vector< std::shared_ptr< generic_name_item > > & get_vector_of_name_items()
Definition chomik.h:2776
list_of_generic_name_items(generic_name_item *const i, list_of_generic_name_items *const l)
Definition chomik.h:2759
Definition chomik.h:1832
list_of_generic_names(generic_name *const gn, list_of_generic_names *const l)
Definition chomik.h:1839
std::vector< std::shared_ptr< generic_name > > & get_vector_of_names()
Definition chomik.h:1856
Definition chomik.h:2715
bool operator==(const list_of_statements &l) const
void report(std::ostream &s) const
void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const
void add_placeholders_to_generator(basic_generator &g) const
std::vector< std::shared_ptr< statement > > & get_vector_of_statements()
Definition chomik.h:2729
list_of_statements(const list_of_statements &s)
void set_is_main(bool m)
Definition chomik.h:2738
const std::vector< std::shared_ptr< statement > > & get_vector_of_statements() const
Definition chomik.h:2731
list_of_statements(statement *const s, list_of_statements *const l)
void add_statement(std::shared_ptr< statement > &&s)
Definition chomik.h:2733
Definition chomik.h:1807
std::vector< std::shared_ptr< type_definition > > & get_vector_of_type_definitions()
Definition chomik.h:1828
list_of_type_definitions(type_definition *const t, list_of_type_definitions *const l)
Definition chomik.h:1811
Definition chomik.h:1938
list_of_variable_definitions(variable_definition *const vd, list_of_variable_definitions *const l)
Definition chomik.h:1945
std::vector< std::shared_ptr< variable_definition > > & get_vector_of_variable_definitions()
Definition chomik.h:1962
Definition chomik.h:1649
~machine_finalization_guard()
Definition chomik.h:1655
machine_finalization_guard(machine &m, GENERATOR_TYPE &p)
Definition chomik.h:1654
Definition chomik.h:3425
const std::vector< std::unique_ptr< assignment_event > > & get_vector_of_assignment_events() const
Definition chomik.h:3468
std::vector< std::unique_ptr< generic_stream > > vector_of_streams
Definition chomik.h:3446
void add_variable_definition_statement(std::shared_ptr< const statement > &&s)
Definition chomik.h:3490
std::string get_signature_item_type_name(int var_index, int item_index) const
void report(std::ostream &s) const
std::map< std::string, std::shared_ptr< type_instance > > map_type_name_to_type_instance
Definition chomik.h:3436
signature_regular_expression & get_signature_regular_expression(int i)
Definition chomik.h:3586
void add_signature_regular_expression(std::unique_ptr< signature_regular_expression > &&e)
Definition chomik.h:3470
void get_variable_value_code(const signature &vn, code &target) const
std::vector< std::unique_ptr< signature_regular_expression > > vector_of_signature_regular_expressions
Definition chomik.h:3448
std::vector< std::shared_ptr< const statement > > vector_of_variable_definition_statements
Definition chomik.h:3433
void add_type_instance(std::shared_ptr< type_instance > &&i)
Definition chomik.h:3519
void destroy_ad_hoc_type_instances_above(int amount)
int get_max_enum_type_index(const std::string &tn) const
void get_first_and_last_iterators_for_ad_hoc_range_type(const std::string &type_name, int &f, int &l) const
static std::ostream * current_compilation_error_stream
Definition chomik.h:3596
int get_amount_of_variables_in_the_memory() const
Definition chomik.h:3452
std::vector< std::shared_ptr< const statement > > vector_of_type_definiton_statements
Definition chomik.h:3432
variable_with_value & get_variable_with_value_by_index(int index)
int get_amount_of_streams() const
Definition chomik.h:3580
std::string get_enum_type_item(const std::string &tn, int i) const
std::string get_actual_text_representation_of_a_variable(const signature &vn) const
int get_last_created_stream_index() const
Definition chomik.h:3576
std::string get_variable_value_enum(const signature &vn) const
void add_variable_with_value(std::shared_ptr< variable_with_value > &&vv)
std::map< std::string, std::shared_ptr< variable_with_value > > map_signature_string_representation_to_variable_with_value
Definition chomik.h:3444
std::vector< std::shared_ptr< variable_with_value > > memory
Definition chomik.h:3442
std::string get_variable_value_string(const signature &vn) const
virtual void execute_user_defined_executable(const signature &s)
Definition chomik.h:3573
std::vector< std::unique_ptr< assignment_event > > vector_of_assignment_events
Definition chomik.h:3440
void get_first_and_last_iterators_for_enum_type(const std::string &type_name, std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator &f, std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator &l) const
Definition chomik.h:3505
type_instance * create_an_ad_hoc_type(const generic_type &t, generator &g, const std::string &tn)
int get_amount_of_signature_regular_expressions() const
Definition chomik.h:3582
const variable_with_value & get_variable_with_value(const signature &vn) const
bool get_variable_is_represented_in_memory(const signature &vn) const
virtual void create_predefined_types()
virtual void create_predefined_variables()
void get_first_and_last_iterators_for_range_type(const std::string &type_name, int &f, int &l) const
Definition chomik.h:3511
static std::ostream * current_runtime_warning_stream
Definition chomik.h:3596
std::string get_signature_item_representation(int var_index, int item_index) const
void add_type_definition_statement(std::shared_ptr< const statement > &&s)
Definition chomik.h:3485
variable_with_value & get_variable_with_value(const signature &vn)
variable_with_value::actual_memory_representation_type get_actual_memory_representation_type_of_the_variable(const signature &vn) const
void add_stream(std::unique_ptr< generic_stream > &&s)
Definition chomik.h:3475
void add_ad_hoc_type(std::shared_ptr< type_instance_ad_hoc_range > &&t)
int get_last_created_signature_regular_expression_index() const
Definition chomik.h:3578
void create_auxilliary_variables_for_type_instance(type_instance &ti)
double get_variable_value_float(const signature &vn) const
virtual bool get_is_user_defined_executable(const signature &s) const
Definition chomik.h:3571
type_instance & get_type_instance(const std::string &type_name) const
Definition chomik.h:3500
int get_amount_of_ad_hoc_type_instances() const
Definition chomik.h:3594
bool get_type_instance_is_known(const std::string &type_name) const
Definition chomik.h:3495
virtual bool get_can_create_files() const
Definition chomik.h:3462
virtual void create_predefined_streams()
std::vector< std::shared_ptr< type_instance > > vector_of_type_instances
Definition chomik.h:3435
generic_stream & get_stream(int i)
Definition chomik.h:3584
std::vector< std::shared_ptr< family_of_variables > > vector_of_variable_families
Definition chomik.h:3438
void add_assignment_event(std::unique_ptr< assignment_event > &&e)
Definition chomik.h:3480
int get_variable_value_integer(const signature &vn) const
void expand(int i)
std::vector< std::shared_ptr< type_instance > > vector_of_ad_hoc_type_instances
Definition chomik.h:3435
int get_amount_of_items_in_the_memory_variables_signature(int i) const
Definition chomik.h:3453
mapping_generator_placeholder(const std::string &fn, const std::string sn)
Definition chomik.h:1493
Definition chomik.h:1605
virtual void initialize_description_of_a_cartesian_product(description_of_a_cartesian_product &target) const override
mapping_generator(const std::string &filename, unsigned new_line_number)
Definition chomik.h:1613
virtual void increment(machine &m) override
virtual const placeholder_with_value & get_placeholder_with_value(const std::string &p) const override
virtual const std::string convert_childs_placeholder_name_to_father(const std::string &cpn) const override
virtual void report(std::ostream &s) const override
virtual void initialize_mapping(const matching_protocol &mp) override
void clear_mappings()
Definition chomik.h:1640
virtual void initialize(machine &m) override
virtual bool get_has_placeholder_with_value(const std::string &p) const override
virtual placeholder_with_value & get_placeholder_with_value(const std::string &p) override
virtual void add_mapping(const std::string &f, const std::string &s)
Definition chomik.h:1631
Definition chomik.h:143
void bind_placeholder_as_float(const std::string &p, double v)
Definition chomik.h:170
bool get_is_placeholder_bound_as_integer(const std::string &p) const
Definition chomik.h:156
std::string get_placeholder_value_identifier(const std::string &p) const
Definition chomik.h:163
void bind_placeholder_as_integer(const std::string &p, int v)
Definition chomik.h:165
bool get_is_placeholder_bound_as_identifier(const std::string &p) const
Definition chomik.h:159
void report(std::ostream &s) const
void initialize_mapping(external_placeholder_generator &target) const
void bind_placeholder_as_identifier(const std::string &p, std::string v)
Definition chomik.h:180
double get_placeholder_value_float(const std::string &p) const
Definition chomik.h:161
int get_placeholder_value_integer(const std::string &p) const
Definition chomik.h:160
std::string get_placeholder_value_string(const std::string &p) const
Definition chomik.h:162
void copy_bound_placeholders(generator &target) const
matching_protocol()
Definition chomik.h:155
void bind_placeholder_as_placeholder(const std::string &p, const std::string &p2)
Definition chomik.h:186
bool get_is_placeholder_bound_as_string(const std::string &p) const
Definition chomik.h:158
bool get_is_successful() const
Definition chomik.h:192
void initialize_mapping(mapping_generator &target) const
void bind_placeholder_as_string(const std::string &p, std::string v)
Definition chomik.h:175
void bind_placeholder_as_code(const std::string &p, const code &c)
bool get_is_placeholder_bound_as_float(const std::string &p) const
Definition chomik.h:157
Definition chomik.h:1382
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
virtual void report(std::ostream &s) const override
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
name_item_code(list_of_statements *const l)
Definition chomik.h:1389
name_item_code()
Definition chomik.h:1393
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
name_item_code(const code &cp)
Definition chomik.h:1320
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:1332
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
Definition chomik.h:1323
name_item_float(double v)
Definition chomik.h:1322
virtual bool get_match_float(double v, const machine &m, const basic_generator &g) const override
Definition chomik.h:1344
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1337
virtual void add_content_to_signature(signature &target) const override
Definition chomik.h:1327
virtual bool get_is_float() const override
Definition chomik.h:1342
Definition chomik.h:1290
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:1303
name_item_integer(int v)
Definition chomik.h:1292
virtual bool get_is_integer() const override
Definition chomik.h:1313
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1308
virtual void add_content_to_signature(signature &target) const override
Definition chomik.h:1298
virtual bool get_match_integer(int v, const machine &m, const basic_generator &g) const override
Definition chomik.h:1315
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
Definition chomik.h:1293
Definition chomik.h:1348
virtual void report(std::ostream &s) const override
Definition chomik.h:1356
name_item_string(std::string v)
Definition chomik.h:1350
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
virtual bool get_is_string() const override
Definition chomik.h:1372
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:1352
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1367
virtual void add_content_to_signature(signature &target) const override
Definition chomik.h:1362
virtual bool get_match_string(const std::string &v, const machine &m, const basic_generator &g) const override
Definition chomik.h:1374
Definition chomik.h:3679
int parse(const char *filename)
static void register_parser(parser *p)
Definition chomik.h:3686
void copy_list_of_statements_to_the_program(list_of_statements *const l)
int parse_string(const std::string &code, std::ostream &error_stream)
static parser * get_parser_pointer()
Definition chomik.h:3687
parser(program &p)
Definition chomik.h:1065
placeholder_name_item(const std::string &p, const generic_type &t)
Definition chomik.h:1075
generic_type & get_type() const
Definition chomik.h:1106
virtual void report(std::ostream &s) const override
Definition chomik.h:1082
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1097
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual std::string get_placeholder_name() const
Definition chomik.h:1104
virtual bool get_is_placeholder() const override
Definition chomik.h:1102
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
placeholder_name_item(const char *const p, generic_type *const t)
Definition chomik.h:1073
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
Definition chomik.h:99
virtual void update_ad_hoc_range_type_instance(machine &m, basic_generator &g)
Definition chomik.h:129
virtual int get_level() const
Definition chomik.h:127
virtual bool get_is_valid() const
Definition chomik.h:113
virtual bool get_is_terminated() const
Definition chomik.h:115
virtual std::string get_value_string() const
Definition chomik.h:119
virtual ~placeholder_with_value()
Definition chomik.h:107
virtual std::string get_value_enum() const
Definition chomik.h:121
virtual void get_value_code(code &target) const
Definition chomik.h:123
const std::string & get_name() const
Definition chomik.h:105
virtual bool get_exceeds_level(int max_level) const
Definition chomik.h:125
virtual void update_int_value(int f, int l)
Definition chomik.h:131
virtual variable_with_value::actual_memory_representation_type get_representation_type() const =0
virtual void report(std::ostream &s) const =0
virtual void increment()
Definition chomik.h:117
const std::string placeholder
Definition chomik.h:101
placeholder_with_value(const std::string &n)
Definition chomik.h:103
Definition chomik.h:27
static bool get_type_is_predefined(const std::string &type_name)
Definition chomik.h:38
static bool get_variable_is_predefined(const std::string &prefix)
Definition chomik.h:3660
void report(std::ostream &s) const
Definition chomik.h:3667
void add_statement(std::shared_ptr< statement > &&s)
void execute(machine &m) const
Definition chomik.h:2037
virtual bool replace_known_placeholders_with_their_values() const override
Definition chomik.h:2041
virtual bool replace_all_variables_with_their_values() const override
Definition chomik.h:2039
Definition chomik.h:2029
virtual bool replace_all_variables_with_their_values() const override
Definition chomik.h:2031
virtual bool replace_known_placeholders_with_their_values() const override
Definition chomik.h:2033
Definition chomik.h:2021
virtual bool replace_known_placeholders_with_their_values() const =0
virtual bool replace_all_variables_with_their_values() const =0
Definition chomik.h:1182
~signature_common_data()
Definition chomik.h:1260
Definition chomik.h:212
virtual std::string get_debug_type_name() const
Definition chomik.h:255
virtual bool get_it_is_code() const
Definition chomik.h:239
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const =0
virtual bool get_it_is_float() const
Definition chomik.h:235
virtual bool get_it_is_enum() const
Definition chomik.h:237
virtual void print(std::ostream &s) const
Definition chomik.h:225
virtual bool get_it_is_identifier(const std::string &pattern) const
Definition chomik.h:229
virtual std::string get_type_name() const =0
virtual int get_value_integer() const
Definition chomik.h:241
virtual bool get_is_predefined() const
Definition chomik.h:227
std::string get_string_representation() const
virtual std::string get_value_string() const
Definition chomik.h:245
signature_item(const generic_name_item &s)
Definition chomik.h:216
virtual std::string get_value_enum() const
Definition chomik.h:247
virtual void report(std::ostream &s) const =0
virtual ~signature_item()
Definition chomik.h:218
virtual bool get_it_is_integer() const
Definition chomik.h:233
const generic_name_item & source
Definition chomik.h:214
virtual bool get_it_is_string() const
Definition chomik.h:231
virtual double get_value_float() const
Definition chomik.h:243
virtual void get_copy(std::shared_ptr< signature_item > &target) const =0
virtual void get_value_code(std::unique_ptr< code > &target)
Definition chomik.h:249
const std::vector< std::shared_ptr< signature_item > > & get_vector_of_items() const
Definition chomik.h:547
signature_regular_expression(const std::string &c)
std::regex & get_regular_expression()
Definition chomik.h:549
Definition chomik.h:473
void execute_predefined(machine &m) const
std::string get_string_representation() const
void add_content(std::shared_ptr< signature_item > &&i)
void report(std::ostream &s) const
void set_line_number(unsigned n)
Definition chomik.h:506
std::string get_item_type_name(int item_index) const
Definition chomik.h:517
const std::vector< std::shared_ptr< signature_item > > & get_vector_of_items() const
Definition chomik.h:523
bool get_is_predefined(const machine &m) const
signature(const generic_name &gn, const machine &m, const basic_generator &g)
signature(const generic_name &gn)
std::string get_item_representation(int item_index) const
Definition chomik.h:516
int get_amount_of_items() const
Definition chomik.h:508
Definition chomik.h:2347
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2358
virtual double get_value_float() const
Definition chomik.h:2350
virtual void get_copy(std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2353
simple_literal_float(double v)
Definition chomik.h:2349
virtual double get_actual_float_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2351
Definition chomik.h:2328
virtual int get_actual_integer_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2333
virtual void get_copy(std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2335
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2340
simple_literal_integer(int v)
Definition chomik.h:2330
virtual int get_value_integer() const
Definition chomik.h:2331
Definition chomik.h:2367
virtual std::string get_value_string() const
Definition chomik.h:2376
virtual void get_copy(std::unique_ptr< generic_literal > &target) const
Definition chomik.h:2380
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::unique_ptr< generic_literal > &target) const override
Definition chomik.h:2385
virtual std::string get_actual_string_value(const machine &m, const basic_generator &g) const override
Definition chomik.h:2378
simple_literal_string(const std::string &v)
Definition chomik.h:2369
virtual void report(std::ostream &s) const override
Definition chomik.h:2371
Definition chomik.h:2297
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:2312
simple_literal(const TYPE v)
Definition chomik.h:2301
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:2318
virtual variable_with_value::actual_memory_representation_type get_actual_memory_representation_type(machine &m, basic_generator &g) const override
Definition chomik.h:2307
const TYPE my_value
Definition chomik.h:2299
virtual void report(std::ostream &s) const override
Definition chomik.h:2302
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
Definition chomik.h:2320
Definition chomik.h:1267
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
Definition chomik.h:1277
virtual void report(std::ostream &s) const override
Definition chomik.h:1272
virtual void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:1284
const TYPE my_value
Definition chomik.h:1269
simple_name_item(TYPE v)
Definition chomik.h:1271
Definition chomik.h:3176
virtual bool get_is_valid() const override
Definition chomik.h:3190
virtual int get_level() const
Definition chomik.h:3208
virtual void increment() override
Definition chomik.h:3199
virtual bool get_exceeds_level(int max_level) const
Definition chomik.h:3203
simple_placeholder_for_enum(const std::string &p, const iterator_type f, const iterator_type l, type_instance *ti)
Definition chomik.h:3181
virtual void report(std::ostream &s) const override
Definition chomik.h:3185
virtual bool get_is_terminated() const override
Definition chomik.h:3195
virtual std::string get_value_enum() const override
Definition chomik.h:3201
virtual bool get_is_valid() const override
Definition chomik.h:3222
virtual bool get_is_terminated() const override
Definition chomik.h:3226
virtual void increment() override
Definition chomik.h:3230
simple_placeholder_for_infinite_range(const std::string &p, type_instance *ti)
Definition chomik.h:3216
virtual void report(std::ostream &s) const override
Definition chomik.h:3218
Definition chomik.h:3237
virtual void report(std::ostream &s) const override
Definition chomik.h:3244
simple_placeholder_for_range(const std::string &p, const int f, const int l, type_instance *ti)
Definition chomik.h:3242
virtual bool get_is_valid() const override
Definition chomik.h:3248
virtual void update_int_value(int f, int l) override
virtual bool get_is_terminated() const override
Definition chomik.h:3252
virtual void increment() override
Definition chomik.h:3256
simple_placeholder_with_value_and_report(const std::string &p, const TYPE v, type_instance *ti)
Definition chomik.h:2849
virtual void report(std::ostream &s) const override
Definition chomik.h:2851
TYPE value
Definition chomik.h:2822
simple_placeholder_with_value(const std::string &p, const TYPE v, type_instance *ti)
Definition chomik.h:2825
virtual void update_int_value(TYPE f, TYPE l)
Definition chomik.h:2835
type_instance * my_type_instance
Definition chomik.h:2823
virtual void update_ad_hoc_range_type_instance(machine &m, basic_generator &g) override
Definition chomik.h:2838
virtual variable_with_value::actual_memory_representation_type get_representation_type() const override
Definition chomik.h:2828
TYPE get_value() const
Definition chomik.h:2833
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const override
virtual bool get_it_is_identifier(const std::string &pattern) const
Definition chomik.h:419
virtual void print(std::ostream &s) const override
Definition chomik.h:407
virtual void get_copy(std::shared_ptr< signature_item > &target) const override
Definition chomik.h:427
virtual std::string get_type_name() const override
Definition chomik.h:437
simple_value_enum_signature_item(const generic_name_item &s, const std::string &i)
Definition chomik.h:405
virtual bool get_is_predefined() const override
Definition chomik.h:417
virtual void report(std::ostream &s) const override
Definition chomik.h:412
virtual std::string get_value_enum() const override
Definition chomik.h:425
const std::string get_enum() const
Definition chomik.h:435
virtual std::string get_debug_type_name() const
Definition chomik.h:433
virtual bool get_it_is_enum() const override
Definition chomik.h:423
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const override
virtual bool get_it_is_float() const override
Definition chomik.h:299
virtual void get_copy(std::shared_ptr< signature_item > &target) const override
Definition chomik.h:304
simple_value_float_signature_item(const generic_name_item &s, const double v)
Definition chomik.h:298
virtual double get_value_float() const override
Definition chomik.h:300
virtual std::string get_type_name() const override
Definition chomik.h:311
virtual std::string get_debug_type_name() const
Definition chomik.h:309
virtual std::string get_type_name() const override
Definition chomik.h:292
virtual std::string get_debug_type_name() const
Definition chomik.h:290
virtual void get_copy(std::shared_ptr< signature_item > &target) const override
Definition chomik.h:285
simple_value_integer_signature_item(const generic_name_item &s, const int v)
Definition chomik.h:279
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const override
virtual int get_value_integer() const override
Definition chomik.h:281
virtual bool get_it_is_integer() const override
Definition chomik.h:280
virtual void report(std::ostream &s) const override
Definition chomik.h:270
simple_value_signature_item(const generic_name_item &s, const TYPE v)
Definition chomik.h:268
const TYPE value
Definition chomik.h:266
virtual std::string get_debug_type_name() const
Definition chomik.h:342
virtual std::string get_type_name() const override
Definition chomik.h:344
virtual void print(std::ostream &s) const override
Definition chomik.h:326
virtual bool get_match(const generic_name_item &gni, const machine &m, const basic_generator &g, matching_protocol &target) const override
virtual std::string get_value_string() const override
Definition chomik.h:333
virtual bool get_it_is_string() const override
Definition chomik.h:331
virtual void get_copy(std::shared_ptr< signature_item > &target) const override
Definition chomik.h:337
simple_value_string_signature_item(const generic_name_item &s, const std::string v)
Definition chomik.h:321
virtual void report(std::ostream &s) const override
Definition chomik.h:322
simple_variable_with_value_enum(std::shared_ptr< signature > &&s, std::string v)
Definition chomik.h:3141
virtual void assign_value_enum(std::string v) override
Definition chomik.h:3145
virtual std::string get_debug_type_name() const override
Definition chomik.h:3147
virtual std::string get_value_enum() const override
Definition chomik.h:3143
virtual double get_value_float() const override
Definition chomik.h:3119
virtual std::string get_debug_type_name() const override
Definition chomik.h:3123
virtual void assign_value_float(double v) override
Definition chomik.h:3121
simple_variable_with_value_float(std::shared_ptr< signature > &&s, double v)
Definition chomik.h:3117
virtual void assign_value_integer(int v) override
Definition chomik.h:3108
virtual int get_value_integer() const override
Definition chomik.h:3106
simple_variable_with_value_integer(std::shared_ptr< signature > &&s, int v)
Definition chomik.h:3104
virtual std::string get_debug_type_name() const override
Definition chomik.h:3110
virtual void assign_value_string(std::string v) override
Definition chomik.h:3133
virtual std::string get_value_string() const override
Definition chomik.h:3131
simple_variable_with_value_string(std::shared_ptr< signature > &&s, std::string v)
Definition chomik.h:3129
virtual std::string get_debug_type_name() const override
Definition chomik.h:3135
Definition chomik.h:3081
virtual void report(std::ostream &s) const override
Definition chomik.h:3087
virtual actual_memory_representation_type get_representation_type() const override
Definition chomik.h:3093
TYPE value
Definition chomik.h:3083
simple_variable_with_value(std::shared_ptr< signature > &&s, TYPE v)
Definition chomik.h:3085
virtual std::string get_debug_type_name() const override
Definition chomik.h:3098
Definition chomik.h:856
virtual const std::vector< std::shared_ptr< type_definition > > & get_vector_of_type_definitions() const
Definition chomik.h:887
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &s) const =0
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const =0
virtual void add_placeholders_to_generator(basic_generator &g) const =0
virtual bool get_is_code_assignment(machine &m) const
Definition chomik.h:880
virtual void get_copy(std::shared_ptr< statement > &target) const =0
unsigned line_number
Definition chomik.h:858
void get_actual_code_value(const machine &m, const basic_generator &g, const replacing_policy &p, code &target) const
virtual ~statement()
Definition chomik.h:867
statement_type
Definition chomik.h:863
virtual void report(std::ostream &s) const =0
static const std::vector< std::shared_ptr< type_definition > > dummy
Definition chomik.h:860
virtual statement_type get_statement_type() const =0
virtual void expand(machine &m, int depth) const
Definition chomik.h:874
statement(unsigned l)
Definition chomik.h:865
Definition chomik.h:1785
virtual void expand(machine &m, int depth, const std::string &n, std::shared_ptr< type_instance > &e) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
type_definition_body_enum(list_of_generic_names *const l)
virtual void report(std::ostream &s) const override
virtual bool get_is_range() const
Definition chomik.h:1800
Definition chomik.h:1456
virtual int get_max_value(machine &m, basic_generator &g) const override
Definition chomik.h:1483
type_definition_body_range(generic_range *const nr)
Definition chomik.h:1463
virtual void add_placeholders_to_generator(basic_generator &g) const override
Definition chomik.h:1472
virtual bool get_is_range() const override
Definition chomik.h:1477
virtual void report(std::ostream &s) const override
Definition chomik.h:1465
virtual int get_min_value(machine &m, basic_generator &g) const override
Definition chomik.h:1481
virtual void expand(machine &m, int depth, const std::string &n, std::shared_ptr< type_instance > &e) const override
Definition chomik.h:1437
virtual void expand(machine &m, int depth, const std::string &n, std::shared_ptr< type_instance > &e) const =0
virtual void add_placeholders_to_generator(basic_generator &g) const =0
virtual ~type_definition_body()
Definition chomik.h:1440
virtual int get_max_value(machine &m, basic_generator &g) const
Definition chomik.h:1452
virtual bool get_is_range() const =0
virtual int get_min_value(machine &m, basic_generator &g) const
Definition chomik.h:1450
virtual void report(std::ostream &s) const =0
Definition chomik.h:1864
virtual void report(std::ostream &s) const override
virtual void get_copy(std::shared_ptr< statement > &target) const override
Definition chomik.h:1899
virtual const std::vector< std::shared_ptr< type_definition > > & get_vector_of_type_definitions() const override
Definition chomik.h:1904
virtual void add_placeholders_to_generator(basic_generator &g) const override
type_definition_statement(unsigned new_line_number)
Definition chomik.h:1883
type_definition_statement(list_of_type_definitions *const l, unsigned new_line_number)
Definition chomik.h:1871
virtual void expand(machine &m, int depth) const override
virtual statement_type get_statement_type() const override
Definition chomik.h:1887
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
Definition chomik.h:1412
type_definition(const char *const type_name, type_definition_body *const b)
Definition chomik.h:1420
void report(std::ostream &s) const
bool get_is_range() const
void add_placeholders_to_generator(basic_generator &g) const
type_definition_body & get_body()
Definition chomik.h:1432
void expand(machine &m, int depth, std::shared_ptr< type_instance > &e) const
const std::string & get_name() const
Definition chomik.h:1428
Definition chomik.h:2925
virtual void update(placeholder_with_value &v, machine &m, basic_generator &g) override
virtual void report(std::ostream &s) const override
type_instance_ad_hoc_range(const generic_type &t, const std::string &n, int b1, int b2)
Definition chomik.h:2930
Definition chomik.h:2863
const std::string & get_name() const
Definition chomik.h:2870
unsigned get_level() const
Definition chomik.h:2872
type_instance_enum_value(const std::string &n, unsigned new_level)
Definition chomik.h:2868
Definition chomik.h:2876
virtual void add_type_instance_enum_value(const signature &n, unsigned new_level) override
virtual type_instance_mode get_mode() const
Definition chomik.h:2897
type_instance_enum(const std::string &n)
Definition chomik.h:2880
virtual std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator get_last_iterator_for_enum() const override
Definition chomik.h:2892
virtual void add_type_instance_enum_value(const std::string &n, unsigned int new_level) override
virtual void report(std::ostream &s) const override
virtual std::string get_enum_item(int i)
Definition chomik.h:2901
virtual std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator get_first_iterator_for_enum() const override
Definition chomik.h:2888
virtual int get_amount_of_values() const override
Definition chomik.h:2899
Definition chomik.h:2905
virtual void report(std::ostream &s) const override
virtual int get_last_iterator_for_range() const override
Definition chomik.h:2915
type_instance_range(const std::string &n, int b1, int b2)
Definition chomik.h:2909
virtual type_instance_mode get_mode() const
Definition chomik.h:2917
virtual int get_first_iterator_for_range() const override
Definition chomik.h:2913
virtual int get_amount_of_values() const override
Definition chomik.h:2919
int max_boundary
Definition chomik.h:2907
int min_boundary
Definition chomik.h:2907
Definition chomik.h:2782
virtual void add_type_instance_enum_value(const signature &n, unsigned new_level=1)
Definition chomik.h:2794
type_instance(const std::string &n)
Definition chomik.h:2790
virtual void update(placeholder_with_value &v, machine &m, basic_generator &g)
Definition chomik.h:2812
virtual int get_last_iterator_for_range() const
Definition chomik.h:2802
type_instance_mode
Definition chomik.h:2788
void update_name(const std::string &n)
Definition chomik.h:2814
virtual int get_amount_of_values() const =0
std::string name
Definition chomik.h:2786
virtual std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator get_last_iterator_for_enum() const
Definition chomik.h:2799
const std::string get_name() const
Definition chomik.h:2804
virtual void report(std::ostream &s) const =0
virtual std::string get_enum_item(int i)
Definition chomik.h:2810
virtual std::vector< std::unique_ptr< type_instance_enum_value > >::const_iterator get_first_iterator_for_enum() const
Definition chomik.h:2798
virtual int get_first_iterator_for_range() const
Definition chomik.h:2801
virtual void add_type_instance_enum_value(const std::string &n, unsigned new_level=1)
Definition chomik.h:2796
virtual type_instance_mode get_mode() const
Definition chomik.h:2806
virtual void execute(machine &m, std::shared_ptr< const statement > &&i, std::shared_ptr< basic_generator > father=nullptr) const override
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual void report(std::ostream &s) const override
virtual void expand(machine &m, int depth) const override
virtual void get_copy(std::shared_ptr< statement > &target) const override
Definition chomik.h:2009
variable_definition_statement(unsigned new_line_number)
Definition chomik.h:1987
bool operator==(const variable_definition_statement &s) const
virtual void make_copy_with_replacements(const machine &m, const basic_generator &g, const replacing_policy &p, std::shared_ptr< statement > &target) const override
variable_definition & get_last_variable_definition()
Definition chomik.h:1994
variable_definition_statement(list_of_variable_definitions *const l, unsigned new_line_number)
Definition chomik.h:1974
virtual statement_type get_statement_type() const override
Definition chomik.h:1992
Definition chomik.h:1908
void add_placeholders_to_generator(basic_generator &g) const
Definition chomik.h:1928
void expand(machine &m, int depth) const
void report(std::ostream &s) const
Definition chomik.h:1919
bool operator==(const variable_definition &d) const
variable_definition(std::shared_ptr< generic_name > &&n, std::shared_ptr< generic_type > &&t)
Definition chomik.h:1917
Definition chomik.h:1112
virtual bool get_match_identifier(const std::string &v, const machine &m, const basic_generator &g) const override
virtual void report(std::ostream &s) const override
virtual bool get_match_float(double v, const machine &m, const basic_generator &g) const override
virtual std::string get_actual_text_representation(const machine &m, const basic_generator &g) const override
virtual void get_result_replacing_placeholders(const machine &m, const basic_generator &g, const replacing_policy &p, generic_name &target) const override
variable_value_name_item(list_of_generic_name_items *const l)
virtual void get_copy(std::shared_ptr< generic_name_item > &gni) const override
Definition chomik.h:1133
virtual void add_content_to_signature(signature &target, const machine &m, const basic_generator &g) const override
variable_value_name_item(const generic_name &gn)
virtual void add_placeholders_to_generator(basic_generator &g) const override
virtual bool get_is_variable_value() const override
Definition chomik.h:1144
virtual bool get_match_integer(int v, const machine &m, const basic_generator &g) const override
virtual bool get_match_code(const code &v, const machine &m, const basic_generator &g) const override
virtual bool get_match_string(const std::string &v, const machine &m, const basic_generator &g) const override
Definition chomik.h:3154
virtual actual_memory_representation_type get_representation_type() const override
Definition chomik.h:3166
virtual void get_value_code(code &target) const
virtual void report(std::ostream &s) const override
variable_with_value_code(std::shared_ptr< signature > &&s, std::unique_ptr< code > &&v)
Definition chomik.h:3158
virtual std::string get_debug_type_name() const override
Definition chomik.h:3171
virtual void assign_value_code(const code &ci) override
Definition chomik.h:49
virtual void report(std::ostream &s) const =0
virtual void assign_value_string(std::string v)
Definition chomik.h:82
virtual int get_value_integer() const
Definition chomik.h:68
virtual double get_value_float() const
Definition chomik.h:70
actual_memory_representation_type
Definition chomik.h:53
virtual std::string get_value_enum() const
Definition chomik.h:74
virtual actual_memory_representation_type get_representation_type() const =0
variable_with_value(std::shared_ptr< signature > &&n)
Definition chomik.h:55
virtual ~variable_with_value()
Definition chomik.h:56
virtual std::string get_debug_type_name() const
Definition chomik.h:88
int get_amount_of_signature_items() const
virtual void assign_value_code(const code &ci)
Definition chomik.h:86
std::shared_ptr< signature > actual_name
Definition chomik.h:51
virtual void assign_value_enum(std::string v)
Definition chomik.h:84
std::string get_signature_item_type_name(int item_index) const
virtual void assign_value_float(double v)
Definition chomik.h:80
virtual std::string get_value_string() const
Definition chomik.h:72
virtual void get_value_code(code &target) const
Definition chomik.h:76
std::string get_signature_string_representation() const
std::string get_signature_item_representation(int item_index) const
virtual void assign_value_integer(int v)
Definition chomik.h:78
Definition chomik.h:19

copyright by Pawel Biernacki

Vantaa 2022