IDL compiler front-end library
Loading...
Searching...
No Matches
Root.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_AST_ROOT_H_
28#define IDLFE_AST_ROOT_H_
29#pragma once
30
31#include "Item.h"
32#include "Symbols.h"
33#include "Container.h"
34#include <filesystem>
35#include <unordered_set>
36
37namespace AST {
38
59class Root :
60 public Item,
61 public Container
62{
63public:
65 const std::filesystem::path& file () const noexcept
66 {
67 return main_file_;
68 }
69
72 bool visit (CodeGen& cg) const;
73
75 operator Symbols& () noexcept
76 {
77 return symbols_;
78 }
79
81 operator const Symbols& () const noexcept
82 {
83 return symbols_;
84 }
85
86private:
87 template <class T> friend class Ptr;
88
89 Root (const std::string& file) :
90 Item (Item::Kind::ROOT),
91 main_file_ (add_file (file))
92 {}
93
94 friend class Builder;
95
96 const std::filesystem::path& add_file (const std::string& name)
97 {
98 return *files_.insert (std::filesystem::absolute (name)).first;
99 }
100
101private:
102 struct fs_hash
103 {
104 size_t operator () (const std::filesystem::path& p) const
105 {
106 return std::filesystem::hash_value (p);
107 }
108 };
109
110 std::unordered_set <std::filesystem::path, fs_hash> files_;
111 const std::filesystem::path& main_file_;
112 Symbols symbols_;
113};
114
115}
116
117#endif
Base for code generators. Abstract class.
Definition CodeGen.h:75
Sequential container of the AST items.
Definition Container.h:58
An AST item.
Definition Item.h:41
Kind
The kind of item.
Definition Item.h:45
@ ROOT
class Root
AST item smart pointer.
Definition Item.h:134
Abstract Syntax Tree root.
Definition Root.h:62
bool visit(CodeGen &cg) const
Visit all items for the code generation.
const std::filesystem::path & file() const noexcept
Definition Root.h:65
Set of the named items.
Definition Symbols.h:38
Abstract Syntax Tree namespace.
Definition Array.h:34