blob: ed26446d90ad95b070ed803788295ac191ce98cc [file] [log] [blame]
dan sinclaira322f5d2020-03-30 22:46:06 +00001// 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 Claytoned2b9782020-12-01 18:04:17 +000017#include "src/ast/module.h"
Ben Clayton1e29f4b2021-01-21 16:20:40 +000018#include "src/clone_context.h"
Ben Claytoned2b9782020-12-01 18:04:17 +000019
Ben Clayton89ea7052020-12-02 18:19:28 +000020TINT_INSTANTIATE_CLASS_ID(tint::ast::ScalarConstructorExpression);
21
dan sinclaira322f5d2020-03-30 22:46:06 +000022namespace tint {
23namespace ast {
24
Ben Claytonb053acf2020-11-16 16:31:07 +000025ScalarConstructorExpression::ScalarConstructorExpression(const Source& source,
26 Literal* litearl)
Ben Claytone319d7f2020-11-30 23:30:58 +000027 : Base(source), literal_(litearl) {}
dan sinclaira322f5d2020-03-30 22:46:06 +000028
Ryan Harrison4d32be42020-04-09 18:52:06 +000029ScalarConstructorExpression::ScalarConstructorExpression(
30 ScalarConstructorExpression&&) = default;
31
dan sinclaira322f5d2020-03-30 22:46:06 +000032ScalarConstructorExpression::~ScalarConstructorExpression() = default;
33
Ben Claytoned2b9782020-12-01 18:04:17 +000034ScalarConstructorExpression* ScalarConstructorExpression::Clone(
35 CloneContext* ctx) const {
36 return ctx->mod->create<ScalarConstructorExpression>(ctx->Clone(source()),
37 ctx->Clone(literal_));
38}
39
dan sinclaira322f5d2020-03-30 22:46:06 +000040bool ScalarConstructorExpression::IsValid() const {
41 return literal_ != nullptr;
42}
43
44void ScalarConstructorExpression::to_str(std::ostream& out,
45 size_t indent) const {
46 make_indent(out, indent);
dan sinclair80598ed2020-11-16 14:46:27 +000047 out << "ScalarConstructor[" << result_type_str() << "]{" << literal_->to_str()
48 << "}" << std::endl;
dan sinclaira322f5d2020-03-30 22:46:06 +000049}
50
51} // namespace ast
52} // namespace tint