dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [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/scalar_constructor_expression.h" |
| 16 | |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 17 | #include "src/ast/module.h" |
Ben Clayton | 1e29f4b | 2021-01-21 16:20:40 +0000 | [diff] [blame^] | 18 | #include "src/clone_context.h" |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 19 | |
Ben Clayton | 89ea705 | 2020-12-02 18:19:28 +0000 | [diff] [blame] | 20 | TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression); |
| 21 | |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 22 | namespace tint { |
| 23 | namespace ast { |
| 24 | |
Ben Clayton | b053acf | 2020-11-16 16:31:07 +0000 | [diff] [blame] | 25 | ScalarConstructorExpression::ScalarConstructorExpression(const Source& source, |
| 26 | Literal* litearl) |
Ben Clayton | e319d7f | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 27 | : Base(source), literal_(litearl) {} |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 28 | |
Ryan Harrison | 4d32be4 | 2020-04-09 18:52:06 +0000 | [diff] [blame] | 29 | ScalarConstructorExpression::ScalarConstructorExpression( |
| 30 | ScalarConstructorExpression&&) = default; |
| 31 | |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 32 | ScalarConstructorExpression::~ScalarConstructorExpression() = default; |
| 33 | |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 34 | ScalarConstructorExpression* ScalarConstructorExpression::Clone( |
| 35 | CloneContext* ctx) const { |
| 36 | return ctx->mod->create<ScalarConstructorExpression>(ctx->Clone(source()), |
| 37 | ctx->Clone(literal_)); |
| 38 | } |
| 39 | |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 40 | bool ScalarConstructorExpression::IsValid() const { |
| 41 | return literal_ != nullptr; |
| 42 | } |
| 43 | |
| 44 | void ScalarConstructorExpression::to_str(std::ostream& out, |
| 45 | size_t indent) const { |
| 46 | make_indent(out, indent); |
dan sinclair | 80598ed | 2020-11-16 14:46:27 +0000 | [diff] [blame] | 47 | out << "ScalarConstructor[" << result_type_str() << "]{" << literal_->to_str() |
| 48 | << "}" << std::endl; |
dan sinclair | a322f5d | 2020-03-30 22:46:06 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace ast |
| 52 | } // namespace tint |