Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 1 | // Copyright 2020 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "src/ast/unary_derivative_expression.h" |
| 16 | |
| 17 | namespace tint { |
| 18 | namespace ast { |
| 19 | |
Dan Sinclair | f4434cd | 2020-03-17 03:54:38 +0000 | [diff] [blame] | 20 | UnaryDerivativeExpression::UnaryDerivativeExpression() : Expression() {} |
| 21 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 22 | UnaryDerivativeExpression::UnaryDerivativeExpression( |
| 23 | UnaryDerivative op, |
| 24 | DerivativeModifier mod, |
| 25 | std::unique_ptr<Expression> param) |
| 26 | : Expression(), op_(op), modifier_(mod), param_(std::move(param)) {} |
| 27 | |
| 28 | UnaryDerivativeExpression::UnaryDerivativeExpression( |
| 29 | const Source& source, |
| 30 | UnaryDerivative op, |
| 31 | DerivativeModifier mod, |
| 32 | std::unique_ptr<Expression> param) |
| 33 | : Expression(source), op_(op), modifier_(mod), param_(std::move(param)) {} |
| 34 | |
| 35 | UnaryDerivativeExpression::~UnaryDerivativeExpression() = default; |
| 36 | |
| 37 | bool UnaryDerivativeExpression::IsValid() const { |
Dan Sinclair | f4434cd | 2020-03-17 03:54:38 +0000 | [diff] [blame] | 38 | if (param_ == nullptr || !param_->IsValid()) { |
| 39 | return false; |
| 40 | } |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | |
| 44 | void UnaryDerivativeExpression::to_str(std::ostream& out, size_t indent) const { |
| 45 | make_indent(out, indent); |
| 46 | out << "UnaryDerivative{" << std::endl; |
| 47 | make_indent(out, indent + 2); |
| 48 | out << op_ << std::endl; |
| 49 | make_indent(out, indent + 2); |
| 50 | out << modifier_ << std::endl; |
Dan Sinclair | f4434cd | 2020-03-17 03:54:38 +0000 | [diff] [blame] | 51 | param_->to_str(out, indent + 2); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 52 | make_indent(out, indent); |
Dan Sinclair | f4434cd | 2020-03-17 03:54:38 +0000 | [diff] [blame] | 53 | out << "}" << std::endl; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } // namespace ast |
| 57 | } // namespace tint |