• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #ifndef SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
16 #define SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
17 
18 #include <vector>
19 
20 #include "src/sem/expression.h"
21 
22 namespace tint {
23 
24 /// Forward declarations
25 namespace ast {
26 class MemberAccessorExpression;
27 }  // namespace ast
28 
29 namespace sem {
30 
31 /// Forward declarations
32 class Struct;
33 class StructMember;
34 
35 /// MemberAccessorExpression holds the semantic information for a
36 /// ast::MemberAccessorExpression node.
37 class MemberAccessorExpression
38     : public Castable<MemberAccessorExpression, Expression> {
39  public:
40   /// Constructor
41   /// @param declaration the AST node
42   /// @param type the resolved type of the expression
43   /// @param statement the statement that owns this expression
44   MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
45                            const sem::Type* type,
46                            const Statement* statement);
47 
48   /// Destructor
49   ~MemberAccessorExpression() override;
50 };
51 
52 /// StructMemberAccess holds the semantic information for a
53 /// ast::MemberAccessorExpression node that represents an access to a structure
54 /// member.
55 class 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
61   /// @param statement the statement that owns this expression
62   /// @param member the structure member
63   StructMemberAccess(const ast::MemberAccessorExpression* declaration,
64                      const sem::Type* type,
65                      const Statement* statement,
66                      const StructMember* member);
67 
68   /// Destructor
69   ~StructMemberAccess() override;
70 
71   /// @returns the structure member
Member()72   StructMember const* Member() const { return member_; }
73 
74  private:
75   StructMember const* const member_;
76 };
77 
78 /// Swizzle holds the semantic information for a ast::MemberAccessorExpression
79 /// node that represents a vector swizzle.
80 class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
81  public:
82   /// Constructor
83   /// @param declaration the AST node
84   /// @param type the resolved type of the expression
85   /// @param statement the statement that owns this expression
86   /// @param indices the swizzle indices
87   Swizzle(const ast::MemberAccessorExpression* declaration,
88           const sem::Type* type,
89           const 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
Indices()96   const std::vector<uint32_t>& Indices() const { return indices_; }
97 
98  private:
99   std::vector<uint32_t> const indices_;
100 };
101 
102 }  // namespace sem
103 }  // namespace tint
104 
105 #endif  // SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_
106