blob: fc32c434f67cffedbb3c342d0bcc57dc5da0838f [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/identifier_expression.h"
16
Ben Claytona6b9a8e2021-01-26 16:57:10 +000017#include "src/program_builder.h"
Ben Claytoned2b9782020-12-01 18:04:17 +000018
Ben Clayton7732ca52021-03-02 20:51:18 +000019TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression);
Ben Clayton89ea7052020-12-02 18:19:28 +000020
Dan Sinclair6e581892020-03-02 15:47:43 -050021namespace tint {
22namespace ast {
23
Ben Claytone6995de2021-04-13 23:27:27 +000024IdentifierExpression::IdentifierExpression(ProgramID program_id,
25 const Source& source,
26 Symbol sym)
27 : Base(program_id, source), sym_(sym) {
Ben Clayton13ef87c2021-04-15 18:20:03 +000028 TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(sym_, program_id);
Ben Clayton8454d822021-03-10 11:41:49 +000029 TINT_ASSERT(sym_.IsValid());
30}
Dan Sinclair6e581892020-03-02 15:47:43 -050031
Ryan Harrison4d32be42020-04-09 18:52:06 +000032IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
33
Dan Sinclair6e581892020-03-02 15:47:43 -050034IdentifierExpression::~IdentifierExpression() = default;
35
Ben Claytoned2b9782020-12-01 18:04:17 +000036IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
Ben Clayton545c9742021-02-11 20:27:14 +000037 // Clone arguments outside of create() call to have deterministic ordering
38 auto src = ctx->Clone(source());
39 auto sym = ctx->Clone(symbol());
40 return ctx->dst->create<IdentifierExpression>(src, sym);
Ben Claytoned2b9782020-12-01 18:04:17 +000041}
42
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000043void IdentifierExpression::to_str(const sem::Info& sem,
Ben Claytondd1b6fc2021-01-29 10:55:40 +000044 std::ostream& out,
45 size_t indent) const {
Dan Sinclair6e581892020-03-02 15:47:43 -050046 make_indent(out, indent);
Ben Claytondd1b6fc2021-01-29 10:55:40 +000047 out << "Identifier[" << result_type_str(sem) << "]{" << sym_.to_str() << "}"
dan sinclair80598ed2020-11-16 14:46:27 +000048 << std::endl;
Dan Sinclair6e581892020-03-02 15:47:43 -050049}
50
51} // namespace ast
52} // namespace tint