// This file is part of Cait . // Copyright (C) 2022-2022 Fuwn // // 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 . // // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only #include #include "node.hh" namespace cait::node { variable::variable(const token &variable_name, std::vector 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 & { 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 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 & { return this->_inputs; } default_::default_(std::vector 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 & { 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