Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 1 | // Copyright 2021 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 | |
Ben Clayton | 3bfb681 | 2021-04-07 08:35:31 +0000 | [diff] [blame] | 15 | #include "src/ast/struct_member.h" |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 16 | #include "src/semantic/struct.h" |
| 17 | |
| 18 | TINT_INSTANTIATE_TYPEINFO(tint::semantic::Struct); |
| 19 | TINT_INSTANTIATE_TYPEINFO(tint::semantic::StructMember); |
| 20 | |
| 21 | namespace tint { |
| 22 | namespace semantic { |
| 23 | |
| 24 | Struct::Struct(type::Struct* type, |
| 25 | StructMemberList members, |
| 26 | uint32_t align, |
Ben Clayton | ad97343 | 2021-03-17 21:54:13 +0000 | [diff] [blame] | 27 | uint32_t size, |
Ben Clayton | a88090b | 2021-03-17 22:47:33 +0000 | [diff] [blame] | 28 | uint32_t size_no_padding, |
James Price | 494e82d | 2021-03-31 15:42:17 +0000 | [diff] [blame] | 29 | std::unordered_set<ast::StorageClass> storage_class_usage, |
| 30 | std::unordered_set<PipelineStageUsage> pipeline_stage_uses) |
Ben Clayton | ad97343 | 2021-03-17 21:54:13 +0000 | [diff] [blame] | 31 | : type_(type), |
| 32 | members_(std::move(members)), |
| 33 | align_(align), |
| 34 | size_(size), |
Ben Clayton | a88090b | 2021-03-17 22:47:33 +0000 | [diff] [blame] | 35 | size_no_padding_(size_no_padding), |
James Price | 494e82d | 2021-03-31 15:42:17 +0000 | [diff] [blame] | 36 | storage_class_usage_(std::move(storage_class_usage)), |
| 37 | pipeline_stage_uses_(std::move(pipeline_stage_uses)) {} |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 38 | |
| 39 | Struct::~Struct() = default; |
| 40 | |
Ben Clayton | 3bfb681 | 2021-04-07 08:35:31 +0000 | [diff] [blame] | 41 | const StructMember* Struct::FindMember(Symbol name) const { |
| 42 | for (auto* member : members_) { |
| 43 | if (member->Declaration()->symbol() == name) { |
| 44 | return member; |
| 45 | } |
| 46 | } |
| 47 | return nullptr; |
| 48 | } |
| 49 | |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 50 | StructMember::StructMember(ast::StructMember* declaration, |
| 51 | uint32_t offset, |
Ben Clayton | 822fa54 | 2021-03-15 20:25:12 +0000 | [diff] [blame] | 52 | uint32_t align, |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 53 | uint32_t size) |
Ben Clayton | 822fa54 | 2021-03-15 20:25:12 +0000 | [diff] [blame] | 54 | : declaration_(declaration), offset_(offset), align_(align), size_(size) {} |
Ben Clayton | d614dd5 | 2021-03-15 10:43:11 +0000 | [diff] [blame] | 55 | |
| 56 | StructMember::~StructMember() = default; |
| 57 | |
| 58 | } // namespace semantic |
| 59 | } // namespace tint |