Sen API
Sen Libraries
Toggle main menu visibility
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
12
#include "
sen/core/lang/stl_parser.h
"
13
#include "
sen/core/lang/stl_resolver.h
"
14
#include "
sen/core/lang/stl_scanner.h
"
15
#include "
sen/core/lang/stl_statement.h
"
16
17
// std
18
#include <string>
19
#include <vector>
20
21
namespace
sen::gen::test
22
{
23
29
constexpr
auto
everyKindStl
= R
"(package k.deep;
30
31
// How far a thing is, in metres.
32
quantity<f32, m> Metres;
33
34
// The colours a thing may be painted.
35
enum Colour : u8 { red, green, blue }
36
37
// A place, given as two distances.
38
struct Point { x : Metres, y : Metres }
39
40
// A round thing, which is also a place.
41
struct Circle: Point { centre : Point, radius : Metres }
42
43
// Either a place or a round thing.
44
variant Figure { Point, Circle }
45
46
// Where something has been.
47
sequence<Point, 8> Track;
48
49
// Three distances, always three.
50
array<Metres, 3> Triple;
51
52
// A colour, or nothing.
53
optional<Colour> MaybeColour;
54
55
// Another name for a distance.
56
alias Distance Metres;
57
58
// The root of the little hierarchy.
59
class 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.
69
class 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.
79
class 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
106
class
ResolvedModel
107
{
108
public
:
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
123
private
:
124
std::vector<sen::lang::StlStatement> statements_;
125
sen::lang::ResolverContext
resolverContext_;
126
sen::lang::TypeSetContext
context_;
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
sen::gen::test::ResolvedModel::context
const sen::lang::TypeSetContext & context() const
Definition
every_kind_model.h:119
sen::gen::test::ResolvedModel::set
const sen::lang::TypeSet & set() const
Definition
every_kind_model.h:121
sen::gen::test::ResolvedModel::ResolvedModel
ResolvedModel(const std::string &stl)
Definition
every_kind_model.h:109
sen::lang::StlParser
Parses STL types and queries out of a list of tokens.
Definition
stl_parser.h:30
sen::lang::StlParser::parse
std::vector< StlStatement > parse()
Parse the tokens given in the constructor into a set of statements.
sen::lang::StlResolver
Resolves a list of statements into a set of types.
Definition
stl_resolver.h:102
sen::lang::StlResolver::resolve
const TypeSet * resolve(const TypeSettings &settings)
Do the resolution based on the inputs passed on the constructor.
sen::lang::StlScanner
Converts a string into a list of tokens.
Definition
stl_scanner.h:31
sen::lang::StlScanner::scanTokens
const StlTokenList & scanTokens()
Scans the string. Throws in case of error.
sen::lang::TypeSetContext
The set of types used during resolution.
Definition
stl_resolver.h:51
sen::lang::ResolverContext
The environment where a resolution takes place.
Definition
stl_resolver.h:43
sen::lang::TypeSet
A set of types coming from a STL file.
Definition
stl_resolver.h:33
sen::gen::test
Definition
every_kind_model.h:22
sen::gen::test::everyKindStl
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
stl_parser.h
stl_resolver.h
stl_scanner.h
stl_statement.h
libs
gen
test
every_kind_model.h
Generated by
1.17.0