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/identifier_expression.h" |
| 16 | |
Ben Clayton | a6b9a8e | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 17 | #include "src/program_builder.h" |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 18 | |
Ben Clayton | 7732ca5 | 2021-03-02 20:51:18 +0000 | [diff] [blame] | 19 | TINT_INSTANTIATE_TYPEINFO(tint::ast::IdentifierExpression); |
Ben Clayton | 89ea705 | 2020-12-02 18:19:28 +0000 | [diff] [blame] | 20 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 21 | namespace tint { |
| 22 | namespace ast { |
| 23 | |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 24 | IdentifierExpression::IdentifierExpression(ProgramID program_id, |
| 25 | const Source& source, |
| 26 | Symbol sym) |
| 27 | : Base(program_id, source), sym_(sym) { |
Ben Clayton | 13ef87c | 2021-04-15 18:20:03 +0000 | [diff] [blame] | 28 | TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(sym_, program_id); |
Ben Clayton | 8454d82 | 2021-03-10 11:41:49 +0000 | [diff] [blame] | 29 | TINT_ASSERT(sym_.IsValid()); |
| 30 | } |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 31 | |
Ryan Harrison | 4d32be4 | 2020-04-09 18:52:06 +0000 | [diff] [blame] | 32 | IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default; |
| 33 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 34 | IdentifierExpression::~IdentifierExpression() = default; |
| 35 | |
Ben Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 36 | IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const { |
Ben Clayton | 545c974 | 2021-02-11 20:27:14 +0000 | [diff] [blame] | 37 | // 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 Clayton | ed2b978 | 2020-12-01 18:04:17 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 43 | void IdentifierExpression::to_str(const sem::Info& sem, |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 44 | std::ostream& out, |
| 45 | size_t indent) const { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 46 | make_indent(out, indent); |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 47 | out << "Identifier[" << result_type_str(sem) << "]{" << sym_.to_str() << "}" |
dan sinclair | 80598ed | 2020-11-16 14:46:27 +0000 | [diff] [blame] | 48 | << std::endl; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace ast |
| 52 | } // namespace tint |