Gyoji Compiler
Loading...
Searching...
No Matches
ns2.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#include <string>
16#include <memory>
17#include <list>
18#include <map>
19#include <vector>
20
21#include <gyoji-misc/pointers.hpp>
22#include <gyoji-context/source-reference.hpp>
23
24namespace Gyoji::frontend::namespaces {
25
26 class NS2;
27 class NS2Context;
28
40 class NS2Entity {
41 public:
72
74 std::string _name,
75 EntityType _type,
76 NS2Entity *parent,
77 const Gyoji::context::SourceReference & _source_ref
78 );
79 ~NS2Entity();
80
93 const std::string & get_name() const;
94
95 std::string get_fully_qualified_name() const;
96
103 const EntityType & get_type() const;
104
105 NS2Entity* get_parent() const;
106
107 NS2Entity* add_identifier(
108 std::string _name,
109 const Gyoji::context::SourceReference & _source_ref
110 );
111
112 NS2Entity* add_type(
113 std::string _name,
114 const Gyoji::context::SourceReference & _source_ref
115 );
116 NS2Entity* add_class(
117 std::string _name,
118 const Gyoji::context::SourceReference & _source_ref
119 );
120
121 NS2Entity* add_namespace(
122 std::string _namespace,
123 const Gyoji::context::SourceReference & _source_ref
124 );
125
126 NS2Entity* add_entity(std::string _name, Gyoji::owned<NS2Entity> _entity);
127
128 NS2Entity *get_entity(std::string _name) const;
129
130 const Gyoji::context::SourceReference & get_source_ref() const;
131
132 void dump(int indent) const;
133
134
135 private:
136 std::string name;
137 EntityType type;
138 NS2Entity *parent;
139 const Gyoji::context::SourceReference & source_ref;
141 };
142
143 class NS2SearchPaths {
144 public:
145 NS2SearchPaths();
146 ~NS2SearchPaths();
147
153 void add_using(std::string name, NS2Entity *alias);
154
160 NS2Entity *get_name(std::string name);
161
162 const std::vector<std::pair<std::string, NS2Entity*>> & get_aliases() const;
163 private:
174
181 };
182
193 public:
194 NS2Context();
195 ~NS2Context();
196
206 void namespace_using(std::string name, NS2Entity* alias);
207
224 NS2Entity* namespace_find_in(NS2Entity* current, std::string _name) const;
225
227
228 NS2Entity* namespace_find(std::string name) const;
229
230 NS2Entity *get_current() const;
235 void namespace_push(NS2Entity *ns);
236 void namespace_pop();
237
238 void dump() const;
239
240 static const std::string NAMESPACE_DELIMITER;
241 private:
242
249
259 };
260
261};
262
References a location in the source-file.
Definition source-reference.hpp:30
NS2Entity * namespace_find_in(NS2Entity *current, std::string _name) const
Definition ns2.cpp:289
void namespace_using(std::string name, NS2Entity *alias)
Definition ns2.cpp:282
void namespace_push(NS2Entity *ns)
Definition ns2.cpp:364
Entity living inside a namespace.
Definition ns2.hpp:40
const EntityType & get_type() const
Definition ns2.cpp:65
@ ENTITY_TYPE_TYPE
Definition ns2.hpp:53
@ ENTITY_TYPE_LABEL
Definition ns2.hpp:70
@ ENTITY_TYPE_CLASS
Definition ns2.hpp:59
@ ENTITY_TYPE_IDENTIFIER
Definition ns2.hpp:47
const std::string & get_name() const
Definition ns2.cpp:42