Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Parser/C++/syn/builder.hh
1| // Synopsis C++ Parser: builder.hh header file
2| // The Builder class, which builds an AST. Used by the SWalker which calls the
3| // appropriate Builder member functions
4|
5| // $Id: builder.hh,v 1.32 2003/01/27 06:53:37 chalky Exp $
6| //
7| // This file is a part of Synopsis.
8| // Copyright (C) 2002 Stephen Davies
9| //
10| // Synopsis is free software; you can redistribute it and/or modify it
11| // under the terms of the GNU General Public License as published by
12| // the Free Software Foundation; either version 2 of the License, or
13| // (at your option) any later version.
14| //
15| // This program is distributed in the hope that it will be useful,
16| // but WITHOUT ANY WARRANTY; without even the implied warranty of
17| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18| // General Public License for more details.
19| //
20| // You should have received a copy of the GNU General Public License
21| // along with this program; if not, write to the Free Software
22| // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23| // 02111-1307, USA.
24|
25| #ifndef H_SYNOPSIS_CPP_BUILDER
26| #define H_SYNOPSIS_CPP_BUILDER
27|
28| #include <map>
29| #include "ast.hh"
30| #include "common.hh"
31|
32|
33| namespace Types
34| {
35| class Type;
36| class Base;
37| class Named;
38| class Unknown;
39| class TemplateType;
40| class FuncPtr;
41| class Dependent;
42| }
43|
44|
45| class SWalker;
46|
47|
48| class Lookup;
49|
50| class ScopeInfo;
51| typedef std::vector<ScopeInfo*> ScopeSearch;
52|
53|
54| enum NamespaceType
55| {
56| NamespaceNamed,
57| NamespaceAnon,
58| NamespaceUnique,
59| NamespaceTemplate,
60| };
61|
62|
63|
64|
65|
66|
67| class Builder
68| {
69| friend class Lookup;
70| public:
71|
72| Builder(AST::SourceFile* file);
73|
74|
75| ~Builder();
76|
77|
78| void set_swalker(SWalker* swalker)
79| {
80| m_swalker = swalker;
81| }
82|
83|
84| void set_access(AST::Access);
85|
86|
87| AST::SourceFile* file() const
88| {
89| return m_file;
90| }
91|
92| void set_file(AST::SourceFile*);
93|
94|
95| const AST::Declaration::vector& builtin_decls() const;
96|
97|
98|
99|
100|
101|
102| AST::Scope* scope()
103| {
104| return m_scope;
105| }
106|
107|
108| ScopeInfo* scopeinfo()
109| {
110| return m_scopes.back();
111| }
112|
113|
114| AST::Scope* global()
115| {
116| return m_global;
117| }
118|
119|
120| Lookup* lookup()
121| {
122| return m_lookup;
123| }
124|
125|
126|
127|
128|
129|
130|
131|
132| void add(AST::Declaration* declaration, bool is_template = false);
133|
134|
135| void add(Types::Named* named);
136|
137|
138|
139|
140| void add_macros(const std::vector<AST::Macro*>&);
141|
142|
143|
144|
145| AST::Namespace* start_namespace(const std::string& name, NamespaceType type);
146|
147|
148| void end_namespace();
149|
150|
151| AST::Namespace* start_template();
152|
153|
154| void end_template();
155|
156|
157|
158|
159|
160|
161| AST::Class* start_class(int, const std::string& type, const std::string& name,
162| AST::Parameter::vector* templ_params);
163|
164|
165| AST::Class* start_class(int, const std::string& type, const ScopedName& names);
166|
167|
168|
169|
170|
171| void update_class_base_search();
172|
173|
174| void end_class();
175|
176|
177| void start_function_impl(const ScopedName& name);
178|
179|
180| void end_function_impl();
181|
182|
183| AST::Function* add_function(int, const std::string& name,
184| const std::vector<std::string>& premod, Types::Type* ret,
185| const std::string& realname, AST::Parameter::vector* templ_params);
186|
187|
188| AST::Variable* add_variable(int, const std::string& name, Types::Type* vtype, bool constr, const std::string& type);
189|
190|
191| void add_this_variable();
192|
193|
194| AST::Typedef* add_typedef(int, const std::string& name, Types::Type* alias, bool constr);
195|
196|
197| AST::Enumerator* add_enumerator(int, const std::string& name, const std::string& value);
198|
199|
200| AST::Enum* add_enum(int, const std::string& name, const AST::Enumerator::vector &);
201|
202|
203|
204| AST::Declaration* add_tail_comment(int line);
205|
206|
207|
208|
209|
210|
211| void add_using_namespace(Types::Named* type);
212|
213|
214| void add_aliased_using_namespace(Types::Named* type, const std::string& alias);
215|
216|
217| void add_using_declaration(Types::Named* type);
218|
219|
220|
221|
222| bool mapName(const ScopedName& name, std::vector<AST::Scope*>&, Types::Named*&);
223|
224|
225| Types::Base* create_base(const std::string& name);
226|
227|
228| Types::Dependent* create_dependent(const std::string& name);
229|
230|
231| Types::Unknown* create_unknown(const std::string& name);
232|
233|
234| Types::Template* create_template(const std::string& name, const std::vector<Types::Type*>&);
235|
236|
237| Types::Unknown* add_unknown(const std::string& name);
238|
239|
240| AST::Forward* add_forward(int lineno, const std::string& name, AST::Parameter::vector* templ_params);
241|
242| private:
243|
244| AST::SourceFile* m_file;
245|
246|
247| AST::Scope* m_global;
248|
249|
250| AST::Scope* m_scope;
251|
252|
253| int m_unique;
254|
255|
256| std::vector<ScopeInfo*> m_scopes;
257|
258|
259| struct Private;
260|
261| Private* m;
262|
263|
264|
265| ScopeInfo* find_info(AST::Scope*);
266|
267|
268| void add_class_bases(AST::Class* clas, ScopeSearch& search);
269|
270|
271| std::string dump_search(ScopeInfo* scope);
272|
273|
274| void do_add_using_namespace(ScopeInfo* target, ScopeInfo* scope);
275|
276|
277| class EqualScope;
278|
279|
280|
281| SWalker* m_swalker;
282|
283|
284| Lookup* m_lookup;
285|
286| };
287|
288| #endif
289|