IDL compiler front-end library
Loading...
Searching...
No Matches
IDL_FrontEnd.h
Go to the documentation of this file.
1
2/*
3* Nirvana IDL front-end library.
4*
5* This is a part of the Nirvana project.
6*
7* Author: Igor Popov
8*
9* Copyright (c) 2021 Igor Popov.
10*
11* This program is free software; you can redistribute it and/or modify
12* it under the terms of the GNU Lesser General Public License as published by
13* the Free Software Foundation; either version 3 of the License, or
14* (at your option) any later version.
15*
16* This program is distributed in the hope that it will be useful,
17* but WITHOUT ANY WARRANTY; without even the implied warranty of
18* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19* GNU General Public License for more details.
20*
21* You should have received a copy of the GNU Lesser General Public
22* License along with this library. If not, see <http://www.gnu.org/licenses/>.
23*
24* Send comments and/or bug reports to:
25* popov.nirvana@gmail.com
26*/
27#ifndef IDLFE_IDL_FRONTEND_H_
28#define IDLFE_IDL_FRONTEND_H_
29#pragma once
30
31#include <assert.h>
32#include <string>
33#include <vector>
34#include <iostream>
35#include <filesystem>
36
37namespace AST {
38class Root;
39class Builder;
40class Interface;
41}
42
43namespace FE {
44class Driver;
45}
46
47namespace simplecpp {
48struct DUI;
49}
50
63{
64public:
70 int main (int argc, const char* const argv []) noexcept
71 {
72 return run (filename (argv [0]), argc - 1, argv + 1);
73 }
74
82 int run (const char* command, int argc, const char* const argv []) noexcept;
83
88 static const char* filename (const char* path) noexcept;
89
91 unsigned flags () const noexcept
92 {
93 return flags_;
94 }
95
97 static const unsigned FLAG_DEPRECATE_ANONYMOUS_TYPES = 1;
98
100 static const unsigned FLAG_DEPRECATE_PSEUDO_INTERFACES = 2;
101
103 static const unsigned FLAG_ENABLE_CONST_OBJREF = 4;
104
106 std::ostream& err_out () const noexcept
107 {
108 return err_out_;
109 }
110
111protected:
112 friend class FE::Driver;
113 friend class AST::Builder;
114
117 {
118 public:
120 const char* arg () const noexcept
121 {
122 assert (!end ());
123 return *arg_;
124 }
125
127 bool end () const noexcept
128 {
129 return arg_ >= end_;
130 }
131
135 bool next () noexcept;
136
145 const char* parameter (const char* switch_end);
146
151 CmdLine (int argc, const char* const argv []) :
152 arg_ (argv),
153 end_ (argv + argc)
154 {}
155
156 private:
157 const char* const* arg_;
158 const char* const* end_;
159 };
160
166 IDL_FrontEnd (unsigned flags = 0, std::ostream& err_out = std::cerr) :
167 command_ (nullptr),
168 flags_ (flags),
169 err_out_ (err_out),
170 preprocess_to_stdout_ (false)
171 {}
172
179 virtual void parse_arguments (CmdLine& args);
180
199 virtual bool parse_command_line (CmdLine& args);
200
206 virtual void print_usage_info (const char* exe_name);
207
209 std::vector <std::string>& defines () noexcept
210 {
211 return defines_;
212 }
213
215 std::vector <std::string>& undefines () noexcept
216 {
217 return undefines_;
218 }
219
221 std::vector <std::string>& include_paths () noexcept
222 {
223 return include_paths_;
224 }
225
227 std::vector <std::string>& includes () noexcept
228 {
229 return includes_;
230 }
231
233 std::vector <std::string>& files () noexcept
234 {
235 return files_;
236 }
237
245 virtual void generate_code (const AST::Root& tree) = 0;
246
252 virtual void file_begin (const std::filesystem::path& file, AST::Builder& builder)
253 {}
254
263 virtual void interface_end (const AST::Interface& itf, AST::Builder& builder)
264 {}
265
266private:
267 bool compile (const simplecpp::DUI& prep_params, const std::string& file);
268
269private:
270 const char* command_;
271 unsigned flags_;
272 std::vector <std::string> defines_;
273 std::vector <std::string> undefines_;
274 std::vector <std::string> include_paths_;
275 std::vector <std::string> includes_;
276 std::vector <std::string> files_;
277 std::ostream& err_out_;
278 bool preprocess_to_stdout_;
279};
280
284
285#endif
The AST builder.
Definition Builder.h:60
Interface definition.
Definition Interface.h:95
Abstract Syntax Tree root.
Definition Root.h:62
Command line argument iterator.
bool end() const noexcept
bool next() noexcept
Advances to the next argument.
const char * parameter(const char *switch_end)
Get the parameter followed to the switch.
const char * arg() const noexcept
IDL front-end.
IDL_FrontEnd(unsigned flags=0, std::ostream &err_out=std::cerr)
Constructor.
std::vector< std::string > & include_paths() noexcept
std::ostream & err_out() const noexcept
virtual void generate_code(const AST::Root &tree)=0
Generate user code from AST.
int main(int argc, const char *const argv[]) noexcept
Call this method from the main() function.
virtual void print_usage_info(const char *exe_name)
Prints usage information to std::cout.
std::vector< std::string > & undefines() noexcept
static const unsigned FLAG_ENABLE_CONST_OBJREF
Allow Nirvana const interface references.
virtual bool parse_command_line(CmdLine &args)
Parse command line parameter.
std::vector< std::string > & defines() noexcept
static const unsigned FLAG_DEPRECATE_ANONYMOUS_TYPES
Disallows anonymous IDL types as required by the C++11 Language Mapping Specification.
std::vector< std::string > & includes() noexcept
std::vector< std::string > & files() noexcept
static const char * filename(const char *path) noexcept
Get file name from path.
virtual void parse_arguments(CmdLine &args)
Parse command line parameters.
virtual void file_begin(const std::filesystem::path &file, AST::Builder &builder)
Begin of the file parsing.
int run(const char *command, int argc, const char *const argv[]) noexcept
The same as main (), but aruments must not include the first main() argument (executable file name).
unsigned flags() const noexcept
virtual void interface_end(const AST::Interface &itf, AST::Builder &builder)
End of the interface parsing.
static const unsigned FLAG_DEPRECATE_PSEUDO_INTERFACES
Disallows pseudo interfaces.
Abstract Syntax Tree namespace.
Definition Array.h:34