Sen API
Sen Libraries
Loading...
Searching...
No Matches
every_kind_model.h
Go to the documentation of this file.
1// === every_kind_model.h ==============================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_LIBS_GEN_TEST_EVERY_KIND_MODEL_H
9#define SEN_LIBS_GEN_TEST_EVERY_KIND_MODEL_H
10
11// sen
16
17// std
18#include <string>
19#include <vector>
20
22{
23
29constexpr auto everyKindStl = R"(package k.deep;
30
31// How far a thing is, in metres.
32quantity<f32, m> Metres;
33
34// The colours a thing may be painted.
35enum Colour : u8 { red, green, blue }
36
37// A place, given as two distances.
38struct Point { x : Metres, y : Metres }
39
40// A round thing, which is also a place.
41struct Circle: Point { centre : Point, radius : Metres }
42
43// Either a place or a round thing.
44variant Figure { Point, Circle }
45
46// Where something has been.
47sequence<Point, 8> Track;
48
49// Three distances, always three.
50array<Metres, 3> Triple;
51
52// A colour, or nothing.
53optional<Colour> MaybeColour;
54
55// Another name for a distance.
56alias Distance Metres;
57
58// The root of the little hierarchy.
59class Base
60{
61 // How many of it there are.
62 var one : Metres;
63
64 // Asked to settle down.
65 fn settle();
66}
67
68// One step down.
69class Middle: extends Base
70{
71 // Whether it is switched on.
72 var live : bool [writable];
73
74 // Emitted when it stops.
75 event stopped(why : Colour);
76}
77
78// Two steps down, and where most of the members are.
79class Derived: extends Middle
80{
81 // What shape it takes.
82 var shape : Figure;
83
84 // Everywhere it has been.
85 var trail : Track;
86
87 // Its colour, if it has one.
88 var tint : MaybeColour;
89
90 // How far away it is.
91 var span : Distance [confirmed];
92
93 // Three fixed distances.
94 var fixed : Triple;
95
96 // Works out how far, from a place.
97 fn measure(from : Point) -> Metres;
98
99 // Emitted when it moves.
100 event moved(to : Point);
101}
102)";
103
107{
108public:
109 explicit ResolvedModel(const std::string& stl)
110 {
111 sen::lang::StlScanner scanner {stl};
112 sen::lang::StlParser parser {scanner.scanTokens()};
113 statements_ = parser.parse();
114
115 sen::lang::StlResolver resolver {statements_, resolverContext_, context_};
116 set_ = resolver.resolve({});
117 }
118
119 [[nodiscard]] const sen::lang::TypeSetContext& context() const { return context_; }
120
121 [[nodiscard]] const sen::lang::TypeSet& set() const { return *set_; }
122
123private:
124 std::vector<sen::lang::StlStatement> statements_;
125 sen::lang::ResolverContext resolverContext_;
127 const sen::lang::TypeSet* set_ = nullptr;
128};
129
130} // namespace sen::gen::test
131
132#endif // SEN_LIBS_GEN_TEST_EVERY_KIND_MODEL_H
const sen::lang::TypeSetContext & context() const
Definition every_kind_model.h:119
const sen::lang::TypeSet & set() const
Definition every_kind_model.h:121
ResolvedModel(const std::string &stl)
Definition every_kind_model.h:109
Parses STL types and queries out of a list of tokens.
Definition stl_parser.h:30
std::vector< StlStatement > parse()
Parse the tokens given in the constructor into a set of statements.
Resolves a list of statements into a set of types.
Definition stl_resolver.h:102
const TypeSet * resolve(const TypeSettings &settings)
Do the resolution based on the inputs passed on the constructor.
Converts a string into a list of tokens.
Definition stl_scanner.h:31
const StlTokenList & scanTokens()
Scans the string. Throws in case of error.
The set of types used during resolution.
Definition stl_resolver.h:51
The environment where a resolution takes place.
Definition stl_resolver.h:43
A set of types coming from a STL file.
Definition stl_resolver.h:33
Definition every_kind_model.h:22
constexpr auto everyKindStl
One of everything the type system has, plus a class carrying a method and an event....
Definition every_kind_model.h:29