Sen API
Sen Libraries
Loading...
Searching...
No Matches
stl_resolver.h
Go to the documentation of this file.
1// === stl_resolver.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_CORE_LANG_STL_RESOLVER_H
9#define SEN_CORE_LANG_STL_RESOLVER_H
10
13#include "sen/core/meta/type.h"
14
15// std
16#include <filesystem>
17#include <memory>
18#include <string>
19#include <unordered_map>
20#include <unordered_set>
21#include <vector>
22
23namespace sen::lang
24{
25
28
29struct TypeSet;
30
32struct TypeSet
33{
34 std::string fileName;
35 std::string parentDirectory;
36 std::vector<std::string> package;
37 std::vector<ConstTypeHandle<sen::CustomType>> types;
38 std::vector<const TypeSet*> importedSets;
39};
40
43{
44 std::filesystem::path originalFileName;
45 std::filesystem::path absoluteFileName;
46 std::vector<std::filesystem::path> includePaths;
47};
48
51{
52 using TypeSetStorageContainerType = std::vector<std::unique_ptr<TypeSet>>;
53
54public:
55 class TypeSetIterator: public TypeSetStorageContainerType::const_iterator
56 {
57 using IterBaseTy = TypeSetStorageContainerType::const_iterator;
58
59 public:
60 // NOLINTNEXTLINE(readability-identifier-naming)
61 using value_type = typename TypeSetStorageContainerType::const_iterator::value_type::element_type;
62 using pointer = value_type*; // NOLINT(readability-identifier-naming)
63 using reference = value_type&; // NOLINT(readability-identifier-naming)
64
65 reference operator*() const { return *this->IterBaseTy::operator*(); }
66 pointer operator->() const { return this->IterBaseTy::operator*().get(); }
67 reference operator[](IterBaseTy::difference_type idx) const { return *(this->IterBaseTy::operator[](idx)); }
68 };
69
70public:
71 [[nodiscard]] TypeSet* createNewTypeSet() noexcept(noexcept(TypeSet()))
72 {
73 return typeSets_.emplace_back(std::make_unique<TypeSet>()).get();
74 }
75
76 void prepend(std::unique_ptr<TypeSet> newTypeSet) { typeSets_.insert(typeSets_.begin(), std::move(newTypeSet)); }
77 void append(std::unique_ptr<TypeSet> newTypeSet) { typeSets_.push_back(std::move(newTypeSet)); }
78 void reserve(size_t n) { typeSets_.reserve(n); }
79 [[nodiscard]] size_t size() const { return typeSets_.size(); }
80
81 [[nodiscard]] TypeSetIterator begin() const { return {typeSets_.cbegin()}; }
82 [[nodiscard]] TypeSetIterator end() const { return {typeSets_.cend()}; }
83
84private:
85 TypeSetStorageContainerType typeSets_;
86};
87
89{
90 std::unordered_set<std::string> checkedProperties;
91 std::unordered_set<std::string> deferredMethods;
92};
93
95{
97 std::unordered_map<std::string, ClassAnnotations> classAnnotations;
98};
99
102{
103public:
105 StlResolver(const std::vector<StlStatement>& statements,
106 const ResolverContext& context,
107 TypeSetContext& globalContext) noexcept;
108
110 [[nodiscard]] const TypeSet* resolve(const TypeSettings& settings);
111
112private:
113 const std::vector<StlStatement>& statements_;
114 const ResolverContext& context_;
115 TypeSetContext& globalContext_;
116};
117
119[[nodiscard]] const TypeSet* readTypesFile(const std::filesystem::path& fileName,
120 const std::vector<std::filesystem::path>& includePaths,
121 TypeSetContext& globalTypeSetContext,
122 const TypeSettings& settings,
123 std::string_view from = {});
124
126
127} // namespace sen::lang
128
129#endif // SEN_CORE_LANG_STL_RESOLVER_H
StlResolver(const std::vector< StlStatement > &statements, const ResolverContext &context, TypeSetContext &globalContext) noexcept
Stores the statements, context, and the global context.
const TypeSet * resolve(const TypeSettings &settings)
Do the resolution based on the inputs passed on the constructor.
Definition stl_resolver.h:56
value_type * pointer
Definition stl_resolver.h:62
value_type & reference
Definition stl_resolver.h:63
typename TypeSetStorageContainerType::const_iterator::value_type::element_type value_type
Definition stl_resolver.h:61
reference operator*() const
Definition stl_resolver.h:65
pointer operator->() const
Definition stl_resolver.h:66
reference operator[](IterBaseTy::difference_type idx) const
Definition stl_resolver.h:67
The set of types used during resolution.
Definition stl_resolver.h:51
void prepend(std::unique_ptr< TypeSet > newTypeSet)
Definition stl_resolver.h:76
TypeSetIterator begin() const
Definition stl_resolver.h:81
void reserve(size_t n)
Definition stl_resolver.h:78
size_t size() const
Definition stl_resolver.h:79
void append(std::unique_ptr< TypeSet > newTypeSet)
Definition stl_resolver.h:77
TypeSet * createNewTypeSet() noexcept(noexcept(TypeSet()))
Definition stl_resolver.h:71
TypeSetIterator end() const
Definition stl_resolver.h:82
std::vector< ConstTypeHandle< sen::CustomType > > types
Definition stl_resolver.h:37
std::vector< const TypeSet * > importedSets
Definition stl_resolver.h:38
std::vector< std::string > package
Definition stl_resolver.h:36
std::string fileName
Definition stl_resolver.h:34
std::filesystem::path originalFileName
Definition stl_resolver.h:44
std::string parentDirectory
Definition stl_resolver.h:35
std::filesystem::path absoluteFileName
Definition stl_resolver.h:45
std::vector< std::filesystem::path > includePaths
Definition stl_resolver.h:46
std::unordered_set< std::string > deferredMethods
Definition stl_resolver.h:91
std::unordered_set< std::string > checkedProperties
Definition stl_resolver.h:90
const TypeSet * readTypesFile(const std::filesystem::path &fileName, const std::vector< std::filesystem::path > &includePaths, TypeSetContext &globalTypeSetContext, const TypeSettings &settings, std::string_view from={})
Helper function to use the resolver.
Definition stl_resolver.h:89
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 code_location.h:14
Definition stl_resolver.h:95
std::unordered_map< std::string, ClassAnnotations > classAnnotations
Qualified class name to its annotations.
Definition stl_resolver.h:97