blob: d715863734d72b24ed0ea24d5707ef739e0f075e [file] [log] [blame]
Ben Claytond614dd52021-03-15 10:43:11 +00001// 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 Clayton3bfb6812021-04-07 08:35:31 +000015#include "src/ast/struct_member.h"
Ben Claytond614dd52021-03-15 10:43:11 +000016#include "src/semantic/struct.h"
17
18TINT_INSTANTIATE_TYPEINFO(tint::semantic::Struct);
19TINT_INSTANTIATE_TYPEINFO(tint::semantic::StructMember);
20
21namespace tint {
22namespace semantic {
23
24Struct::Struct(type::Struct* type,
25 StructMemberList members,
26 uint32_t align,
Ben Claytonad973432021-03-17 21:54:13 +000027 uint32_t size,
Ben Claytona88090b2021-03-17 22:47:33 +000028 uint32_t size_no_padding,
James Price494e82d2021-03-31 15:42:17 +000029 std::unordered_set<ast::StorageClass> storage_class_usage,
30 std::unordered_set<PipelineStageUsage> pipeline_stage_uses)
Ben Claytonad973432021-03-17 21:54:13 +000031 : type_(type),
32 members_(std::move(members)),
33 align_(align),
34 size_(size),
Ben Claytona88090b2021-03-17 22:47:33 +000035 size_no_padding_(size_no_padding),
James Price494e82d2021-03-31 15:42:17 +000036 storage_class_usage_(std::move(storage_class_usage)),
37 pipeline_stage_uses_(std::move(pipeline_stage_uses)) {}
Ben Claytond614dd52021-03-15 10:43:11 +000038
39Struct::~Struct() = default;
40
Ben Clayton3bfb6812021-04-07 08:35:31 +000041const 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 Claytond614dd52021-03-15 10:43:11 +000050StructMember::StructMember(ast::StructMember* declaration,
51 uint32_t offset,
Ben Clayton822fa542021-03-15 20:25:12 +000052 uint32_t align,
Ben Claytond614dd52021-03-15 10:43:11 +000053 uint32_t size)
Ben Clayton822fa542021-03-15 20:25:12 +000054 : declaration_(declaration), offset_(offset), align_(align), size_(size) {}
Ben Claytond614dd52021-03-15 10:43:11 +000055
56StructMember::~StructMember() = default;
57
58} // namespace semantic
59} // namespace tint