blob: b2416f3930e5e07cd02d50efb324b5155b0ed48f [file] [log] [blame]
Dan Sinclair6e581892020-03-02 15:47:43 -05001// 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
17namespace tint {
18namespace ast {
19
Dan Sinclairf4434cd2020-03-17 03:54:38 +000020UnaryDerivativeExpression::UnaryDerivativeExpression() : Expression() {}
21
Dan Sinclair6e581892020-03-02 15:47:43 -050022UnaryDerivativeExpression::UnaryDerivativeExpression(
23 UnaryDerivative op,
24 DerivativeModifier mod,
25 std::unique_ptr<Expression> param)
26 : Expression(), op_(op), modifier_(mod), param_(std::move(param)) {}
27
28UnaryDerivativeExpression::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
35UnaryDerivativeExpression::~UnaryDerivativeExpression() = default;
36
37bool UnaryDerivativeExpression::IsValid() const {
Dan Sinclairf4434cd2020-03-17 03:54:38 +000038 if (param_ == nullptr || !param_->IsValid()) {
39 return false;
40 }
Dan Sinclair6e581892020-03-02 15:47:43 -050041 return true;
42}
43
44void 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 Sinclairf4434cd2020-03-17 03:54:38 +000051 param_->to_str(out, indent + 2);
Dan Sinclair6e581892020-03-02 15:47:43 -050052 make_indent(out, indent);
Dan Sinclairf4434cd2020-03-17 03:54:38 +000053 out << "}" << std::endl;
Dan Sinclair6e581892020-03-02 15:47:43 -050054}
55
56} // namespace ast
57} // namespace tint