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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// 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
#include <iostream>
#include "node.hh"
namespace cait::node {
variable::variable(const token &variable_name,
std::vector<token> variable_value_list)
: _name(variable_name), _value_list(std::move(variable_value_list)) {}
[[nodiscard]] auto variable::string() const -> std::string {
std::ostringstream values;
for (const auto &command : this->_value_list) {
values << command.word << " ";
}
return this->_name.word + " = " + values.str();
}
[[nodiscard]] auto variable::name() const noexcept -> const token & {
return this->_name;
}
[[maybe_unused]] [[nodiscard]] auto variable::value_list() const noexcept
-> const std::vector<token> & {
return this->_value_list;
}
rule::rule(const token &rule_name, item_map_type rule_item_map)
: _name(rule_name), _item_map(std::move(rule_item_map)) {}
[[nodiscard]] auto rule::string() const -> std::string {
std::ostringstream values;
for (const auto &item : this->_item_map) {
values << " " << item.first << " = ";
for (const auto &command : item.second) {
values << command.word << " ";
}
values << '\n';
}
// Clip off the last newline
return "rule " + this->_name.word + "\n" +
values.str().substr(0, values.str().size() - 1);
}
[[nodiscard]] auto rule::name() const noexcept -> const token & {
return this->_name;
}
[[maybe_unused]] [[nodiscard]] auto rule::item_map() const noexcept
-> const item_map_type & {
return this->_item_map;
}
pool::pool(const token &pool_name, const token &pool_depth)
: _name(pool_name), _depth(pool_depth) {}
[[nodiscard]] auto pool::string() const -> std::string {
return "pool " + this->_name.word + "\n depth = " + this->_depth.word;
}
[[nodiscard]] auto pool::name() const noexcept -> const token & {
return this->_name;
}
[[maybe_unused]] [[nodiscard]] auto pool::depth() const noexcept
-> const token & {
return this->_depth;
}
build::build(const token &build_output, const token &build_rule,
std::vector<token> build_inputs)
: _output(build_output), _rule(build_rule),
_inputs(std::move(build_inputs)) {}
[[nodiscard]] auto build::string() const -> std::string {
std::ostringstream values;
for (const auto &command : this->_inputs) {
values << command.word << " ";
}
return "build " + this->_output.word + ": " + this->_rule.word + ' ' +
values.str();
}
[[maybe_unused]] [[nodiscard]] auto build::output() const noexcept
-> const token & {
return this->_output;
}
[[maybe_unused]] [[nodiscard]] auto build::rule() const noexcept
-> const token & {
return this->_rule;
}
[[maybe_unused]] [[nodiscard]] auto build::inputs() const noexcept
-> const std::vector<token> & {
return this->_inputs;
}
default_::default_(std::vector<token> default_targets)
: _targets(std::move(default_targets)) {}
[[nodiscard]] auto default_::string() const -> std::string {
std::ostringstream values;
for (const auto &target : this->_targets) {
values << target.word << " ";
}
return "default " + values.str();
}
[[maybe_unused]] [[nodiscard]] auto default_::targets() const noexcept
-> const std::vector<token> & {
return this->_targets;
}
include::include(const token &include_path) : _path(include_path) {}
[[nodiscard]] auto include::string() const -> std::string {
return "include " + this->_path.word;
}
[[maybe_unused]] [[nodiscard]] auto include::path() const noexcept
-> const token & {
return this->_path;
}
subninja::subninja(const token &subninja_path) : _path(subninja_path) {}
[[nodiscard]] auto subninja::string() const -> std::string {
return "subninja " + this->_path.word;
}
[[maybe_unused]] [[nodiscard]] auto subninja::path() const noexcept
-> const token & {
return this->_path;
}
} // namespace cait::node
|