diff options
| author | Fuwn <[email protected]> | 2022-06-24 04:34:06 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-06-24 04:34:06 -0700 |
| commit | 06a2da38c0bffa43c9e8a26b6d98dc95595dc081 (patch) | |
| tree | 09d1c29f9202b1cb8670fa1f0d6bcf256f8f738c /src/node.cc | |
| parent | docs(license): add gpl-3.0 (diff) | |
| download | cait-06a2da38c0bffa43c9e8a26b6d98dc95595dc081.tar.xz cait-06a2da38c0bffa43c9e8a26b6d98dc95595dc081.zip | |
ci: push source to remote
Diffstat (limited to 'src/node.cc')
| -rw-r--r-- | src/node.cc | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/src/node.cc b/src/node.cc new file mode 100644 index 0000000..9b76c27 --- /dev/null +++ b/src/node.cc @@ -0,0 +1,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 |