blob: e298024ad128e5b44e92350ffa0502ca3760154d [file] [log] [blame]
Ben Claytonc1052a42021-02-03 23:55:56 +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
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000015#ifndef SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
16#define SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
Ben Claytonc1052a42021-02-03 23:55:56 +000017
Ben Clayton6d612ad2021-02-24 14:15:02 +000018#include <vector>
19
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000020#include "src/sem/expression.h"
Ben Claytonc1052a42021-02-03 23:55:56 +000021
22namespace tint {
Ben Claytone9c49842021-04-09 13:56:08 +000023
24/// Forward declarations
25namespace ast {
26class MemberAccessorExpression;
27} // namespace ast
28
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000029namespace sem {
Ben Claytonc1052a42021-02-03 23:55:56 +000030
Ben Claytone9c49842021-04-09 13:56:08 +000031/// Forward declarations
32class Struct;
33class StructMember;
34
Ben Claytonc1052a42021-02-03 23:55:56 +000035/// MemberAccessorExpression holds the semantic information for a
36/// ast::MemberAccessorExpression node.
37class MemberAccessorExpression
38 : public Castable<MemberAccessorExpression, Expression> {
39 public:
40 /// Constructor
James Pricec9af5972021-02-16 21:15:01 +000041 /// @param declaration the AST node
Ben Claytonc1052a42021-02-03 23:55:56 +000042 /// @param type the resolved type of the expression
Ben Claytonf97b9c92021-02-16 18:45:45 +000043 /// @param statement the statement that owns this expression
Ben Claytone9c49842021-04-09 13:56:08 +000044 MemberAccessorExpression(ast::MemberAccessorExpression* declaration,
Antonio Maiorano26fa9922021-04-22 15:34:13 +000045 const sem::Type* type,
Ben Claytone9c49842021-04-09 13:56:08 +000046 Statement* statement);
Ben Clayton6d612ad2021-02-24 14:15:02 +000047
48 /// Destructor
49 ~MemberAccessorExpression() override;
Ben Claytone9c49842021-04-09 13:56:08 +000050};
Ben Claytonc1052a42021-02-03 23:55:56 +000051
Ben Claytone9c49842021-04-09 13:56:08 +000052/// StructMemberAccess holds the semantic information for a
53/// ast::MemberAccessorExpression node that represents an access to a structure
54/// member.
55class StructMemberAccess
56 : public Castable<StructMemberAccess, MemberAccessorExpression> {
57 public:
58 /// Constructor
59 /// @param declaration the AST node
60 /// @param type the resolved type of the expression
Ben Clayton962d46e2021-04-09 16:51:38 +000061 /// @param statement the statement that owns this expression
Ben Claytone9c49842021-04-09 13:56:08 +000062 /// @param member the structure member
63 StructMemberAccess(ast::MemberAccessorExpression* declaration,
Antonio Maiorano26fa9922021-04-22 15:34:13 +000064 const sem::Type* type,
Ben Claytone9c49842021-04-09 13:56:08 +000065 Statement* statement,
66 const StructMember* member);
Ben Clayton6d612ad2021-02-24 14:15:02 +000067
Ben Claytone9c49842021-04-09 13:56:08 +000068 /// Destructor
69 ~StructMemberAccess() override;
70
71 /// @returns the structure member
72 StructMember const* Member() const { return member_; }
Ben Claytonc1052a42021-02-03 23:55:56 +000073
74 private:
Ben Claytone9c49842021-04-09 13:56:08 +000075 StructMember const* const member_;
76};
77
78/// Swizzle holds the semantic information for a ast::MemberAccessorExpression
79/// node that represents a vector swizzle.
80class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
81 public:
82 /// Constructor
83 /// @param declaration the AST node
84 /// @param type the resolved type of the expression
Ben Clayton962d46e2021-04-09 16:51:38 +000085 /// @param statement the statement that
Ben Claytone9c49842021-04-09 13:56:08 +000086 /// @param indices the swizzle indices
87 Swizzle(ast::MemberAccessorExpression* declaration,
Antonio Maiorano26fa9922021-04-22 15:34:13 +000088 const sem::Type* type,
Ben Claytone9c49842021-04-09 13:56:08 +000089 Statement* statement,
90 std::vector<uint32_t> indices);
91
92 /// Destructor
93 ~Swizzle() override;
94
95 /// @return the swizzle indices, if this is a vector swizzle
96 const std::vector<uint32_t>& Indices() const { return indices_; }
97
98 private:
99 std::vector<uint32_t> const indices_;
Ben Claytonc1052a42021-02-03 23:55:56 +0000100};
101
Antonio Maiorano5cd71b82021-04-16 19:07:51 +0000102} // namespace sem
Ben Claytonc1052a42021-02-03 23:55:56 +0000103} // namespace tint
104
Antonio Maiorano5cd71b82021-04-16 19:07:51 +0000105#endif // SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_