Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +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 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 15 | #ifndef SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_ |
| 16 | #define SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_ |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 17 | |
Ben Clayton | 6d612ad | 2021-02-24 14:15:02 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 20 | #include "src/sem/expression.h" |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 21 | |
| 22 | namespace tint { |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 23 | |
| 24 | /// Forward declarations |
| 25 | namespace ast { |
| 26 | class MemberAccessorExpression; |
| 27 | } // namespace ast |
| 28 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 29 | namespace sem { |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 30 | |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 31 | /// Forward declarations |
| 32 | class Struct; |
| 33 | class StructMember; |
| 34 | |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 35 | /// MemberAccessorExpression holds the semantic information for a |
| 36 | /// ast::MemberAccessorExpression node. |
| 37 | class MemberAccessorExpression |
| 38 | : public Castable<MemberAccessorExpression, Expression> { |
| 39 | public: |
| 40 | /// Constructor |
James Price | c9af597 | 2021-02-16 21:15:01 +0000 | [diff] [blame] | 41 | /// @param declaration the AST node |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 42 | /// @param type the resolved type of the expression |
Ben Clayton | f97b9c9 | 2021-02-16 18:45:45 +0000 | [diff] [blame] | 43 | /// @param statement the statement that owns this expression |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 44 | MemberAccessorExpression(ast::MemberAccessorExpression* declaration, |
Antonio Maiorano | 26fa992 | 2021-04-22 15:34:13 +0000 | [diff] [blame] | 45 | const sem::Type* type, |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 46 | Statement* statement); |
Ben Clayton | 6d612ad | 2021-02-24 14:15:02 +0000 | [diff] [blame] | 47 | |
| 48 | /// Destructor |
| 49 | ~MemberAccessorExpression() override; |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 50 | }; |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 51 | |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 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 |
Ben Clayton | 962d46e | 2021-04-09 16:51:38 +0000 | [diff] [blame] | 61 | /// @param statement the statement that owns this expression |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 62 | /// @param member the structure member |
| 63 | StructMemberAccess(ast::MemberAccessorExpression* declaration, |
Antonio Maiorano | 26fa992 | 2021-04-22 15:34:13 +0000 | [diff] [blame] | 64 | const sem::Type* type, |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 65 | Statement* statement, |
| 66 | const StructMember* member); |
Ben Clayton | 6d612ad | 2021-02-24 14:15:02 +0000 | [diff] [blame] | 67 | |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 68 | /// Destructor |
| 69 | ~StructMemberAccess() override; |
| 70 | |
| 71 | /// @returns the structure member |
| 72 | StructMember const* Member() const { return member_; } |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 73 | |
| 74 | private: |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 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 |
Ben Clayton | 962d46e | 2021-04-09 16:51:38 +0000 | [diff] [blame] | 85 | /// @param statement the statement that |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 86 | /// @param indices the swizzle indices |
| 87 | Swizzle(ast::MemberAccessorExpression* declaration, |
Antonio Maiorano | 26fa992 | 2021-04-22 15:34:13 +0000 | [diff] [blame] | 88 | const sem::Type* type, |
Ben Clayton | e9c4984 | 2021-04-09 13:56:08 +0000 | [diff] [blame] | 89 | 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 Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 102 | } // namespace sem |
Ben Clayton | c1052a4 | 2021-02-03 23:55:56 +0000 | [diff] [blame] | 103 | } // namespace tint |
| 104 | |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 105 | #endif // SRC_SEM_MEMBER_ACCESSOR_EXPRESSION_H_ |