1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// This file is part of Cait <https://github.com/Fuwn/cait>.
// Copyright (C) 2022-2022 Fuwn <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
#ifndef NODE_HH
#define NODE_HH
#include <map>
#include <sstream>
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include "token.hh"
namespace cait::node {
class variable;
class rule;
class build;
class default_;
class pool;
class include;
class subninja;
using item_map_type = std::map<std::string, std::vector<token>>;
using node_set =
std::variant<rule, build, default_, variable, pool, include, subninja>;
class stringable {
public:
stringable();
explicit stringable(const stringable &);
virtual ~stringable();
[[nodiscard]] virtual auto string() const -> std::string = 0;
};
class variable : stringable {
private:
const token &_name;
std::vector<token> _value_list;
public:
variable(const token &, std::vector<token>);
[[nodiscard]] auto string() const -> std::string override;
[[nodiscard]] auto name() const noexcept -> const token &;
[[maybe_unused]] [[nodiscard]] auto value_list() const noexcept
-> const std::vector<token> &;
};
class rule : stringable {
private:
const token &_name;
item_map_type _item_map;
public:
rule(const token &, item_map_type);
[[nodiscard]] auto string() const -> std::string override;
[[nodiscard]] auto name() const noexcept -> const token &;
[[maybe_unused]] [[nodiscard]] auto item_map() const noexcept
-> const item_map_type &;
};
class pool : stringable {
private:
const token &_name;
const token &_depth;
public:
pool(const token &, const token &);
[[nodiscard]] auto string() const -> std::string override;
[[nodiscard]] auto name() const noexcept -> const token &;
[[maybe_unused]] [[nodiscard]] auto depth() const noexcept -> const token &;
};
class build : stringable {
private:
const token &_output;
const token &_rule;
std::vector<token> _inputs;
public:
build(const token &, const token &, std::vector<token>);
[[nodiscard]] auto string() const -> std::string override;
[[maybe_unused]] [[nodiscard]] auto output() const noexcept -> const token &;
[[maybe_unused]] [[nodiscard]] auto rule() const noexcept -> const token &;
[[maybe_unused]] [[nodiscard]] auto inputs() const noexcept
-> const std::vector<token> &;
};
class default_ : stringable {
private:
std::vector<token> _targets;
public:
explicit default_(std::vector<token>);
[[nodiscard]] auto string() const -> std::string override;
[[maybe_unused]] [[nodiscard]] auto targets() const noexcept
-> const std::vector<token> &;
};
class include : stringable {
private:
const token &_path;
public:
explicit include(const token &);
[[nodiscard]] auto string() const -> std::string override;
[[maybe_unused]] [[nodiscard]] auto path() const noexcept -> const token &;
};
class subninja : stringable {
private:
const token &_path;
public:
explicit subninja(const token &);
[[nodiscard]] auto string() const -> std::string override;
[[maybe_unused]] [[nodiscard]] auto path() const noexcept -> const token &;
};
} // namespace cait::node
#endif // NODE_HH
|