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 <set>
19#include <string>
20#include <unordered_map>
21#include <unordered_set>
22#include <vector>
23
24namespace sen::lang
25{
26
29
30struct TypeSet;
31
33struct TypeSet
34{
35 std::string fileName;
36 std::string parentDirectory;
37 std::vector<std::string> package;
38 std::vector<ConstTypeHandle<sen::CustomType>> types;
39 std::vector<const TypeSet*> importedSets;
40};
41
44{
45 std::filesystem::path originalFileName;
46 std::filesystem::path absoluteFileName;
47 std::vector<std::filesystem::path> includePaths;
48};
49
52{
53 using TypeSetStorageContainerType = std::vector<std::unique_ptr<TypeSet>>;
54
55public:
56 class TypeSetIterator: public TypeSetStorageContainerType::const_iterator
57 {
58 using IterBaseTy = TypeSetStorageContainerType::const_iterator;
59
60 public:
61 // NOLINTNEXTLINE(readability-identifier-naming)
62 using value_type = typename TypeSetStorageContainerType::const_iterator::value_type::element_type;
63 using pointer = value_type*; // NOLINT(readability-identifier-naming)
64 using reference = value_type&; // NOLINT(readability-identifier-naming)
65
66 reference operator*() const { return *this->IterBaseTy::operator*(); }
67 pointer operator->() const { return this->IterBaseTy::operator*().get(); }
68 reference operator[](IterBaseTy::difference_type idx) const { return *(this->IterBaseTy::operator[](idx)); }
69 };
70
71public:
72 [[nodiscard]] TypeSet* createNewTypeSet() noexcept(noexcept(TypeSet()))
73 {
74 return typeSets_.emplace_back(std::make_unique<TypeSet>()).get();
75 }
76
77 void prepend(std::unique_ptr<TypeSet> newTypeSet) { typeSets_.insert(typeSets_.begin(), std::move(newTypeSet)); }
78 void append(std::unique_ptr<TypeSet> newTypeSet) { typeSets_.push_back(std::move(newTypeSet)); }
79 void reserve(size_t n) { typeSets_.reserve(n); }
80 [[nodiscard]] size_t size() const { return typeSets_.size(); }
81
82 [[nodiscard]] TypeSetIterator begin() const { return {typeSets_.cbegin()}; }
83 [[nodiscard]] TypeSetIterator end() const { return {typeSets_.cend()}; }
84
86 void recordReadFile(const std::filesystem::path& file) { readFiles_.insert(file); }
87
89 [[nodiscard]] const std::set<std::filesystem::path>& readFiles() const { return readFiles_; }
90
91private:
92 TypeSetStorageContainerType typeSets_;
93 std::set<std::filesystem::path> readFiles_;
94};
95
97{
98 std::unordered_set<std::string> checkedProperties;
99 std::unordered_set<std::string> deferredMethods;
100};
101
103{
105 std::unordered_map<std::string, ClassAnnotations> classAnnotations;
106};
107
110{
111public:
113 StlResolver(const std::vector<StlStatement>& statements,
114 const ResolverContext& context,
115 TypeSetContext& globalContext) noexcept;
116
118 [[nodiscard]] const TypeSet* resolve(const TypeSettings& settings);
119
120private:
121 const std::vector<StlStatement>& statements_;
122 const ResolverContext& context_;
123 TypeSetContext& globalContext_;
124};
125
127[[nodiscard]] const TypeSet* readTypesFile(const std::filesystem::path& fileName,
128 const std::vector<std::filesystem::path>& includePaths,
129 TypeSetContext& globalTypeSetContext,
130 const TypeSettings& settings,
131 std::string_view from = {});
132
135[[nodiscard]] std::string computePackagePrefix(const std::vector<std::string>& path);
136
138
139} // namespace sen::lang
140
141#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:57
value_type * pointer
Definition stl_resolver.h:63
value_type & reference
Definition stl_resolver.h:64
typename TypeSetStorageContainerType::const_iterator::value_type::element_type value_type
Definition stl_resolver.h:62
reference operator*() const
Definition stl_resolver.h:66
pointer operator->() const
Definition stl_resolver.h:67
reference operator[](IterBaseTy::difference_type idx) const
Definition stl_resolver.h:68
The set of types used during resolution.
Definition stl_resolver.h:52
void prepend(std::unique_ptr< TypeSet > newTypeSet)
Definition stl_resolver.h:77
TypeSetIterator begin() const
Definition stl_resolver.h:82
const std::set< std::filesystem::path > & readFiles() const
Every file read while resolving, transitive imports included.
Definition stl_resolver.h:89
void reserve(size_t n)
Definition stl_resolver.h:79
size_t size() const
Definition stl_resolver.h:80
void recordReadFile(const std::filesystem::path &file)
Records a file the resolver opened. Sorted, so a depfile is reproducible.
Definition stl_resolver.h:86
void append(std::unique_ptr< TypeSet > newTypeSet)
Definition stl_resolver.h:78
TypeSet * createNewTypeSet() noexcept(noexcept(TypeSet()))
Definition stl_resolver.h:72
TypeSetIterator end() const
Definition stl_resolver.h:83
std::vector< ConstTypeHandle< sen::CustomType > > types
Definition stl_resolver.h:38
std::vector< const TypeSet * > importedSets
Definition stl_resolver.h:39
std::vector< std::string > package
Definition stl_resolver.h:37
std::string fileName
Definition stl_resolver.h:35
std::filesystem::path originalFileName
Definition stl_resolver.h:45
std::string parentDirectory
Definition stl_resolver.h:36
std::filesystem::path absoluteFileName
Definition stl_resolver.h:46
std::vector< std::filesystem::path > includePaths
Definition stl_resolver.h:47
std::unordered_set< std::string > deferredMethods
Definition stl_resolver.h:99
std::unordered_set< std::string > checkedProperties
Definition stl_resolver.h:98
std::string computePackagePrefix(const std::vector< std::string > &path)
Joins a package path (e.g. ["sen", "components", "jsonrpc"]) into the dotted form used in STL declara...
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:97
The environment where a resolution takes place.
Definition stl_resolver.h:44
A set of types coming from a STL file.
Definition stl_resolver.h:34
Definition code_location.h:14
Definition stl_resolver.h:103
std::unordered_map< std::string, ClassAnnotations > classAnnotations
Qualified class name to its annotations.
Definition stl_resolver.h:105