dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 1 | // Copyright 2022 The Tint Authors. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 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 | |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 15 | #ifndef SRC_TINT_TYPE_BOOL_H_ |
| 16 | #define SRC_TINT_TYPE_BOOL_H_ |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 17 | |
| 18 | #include <string> |
| 19 | |
dan sinclair | 5f764d8 | 2022-12-08 00:32:27 +0000 | [diff] [blame] | 20 | #include "src/tint/type/type.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 21 | |
| 22 | // X11 likes to #define Bool leading to confusing error messages. |
| 23 | // If its defined, undefine it. |
| 24 | #ifdef Bool |
| 25 | #undef Bool |
| 26 | #endif |
| 27 | |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 28 | namespace tint::type { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 29 | |
| 30 | /// A boolean type |
dan sinclair | 98705d4 | 2022-12-08 22:21:24 +0000 | [diff] [blame] | 31 | class Bool final : public Castable<Bool, Type> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 32 | public: |
| 33 | /// Constructor |
| 34 | Bool(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 35 | |
Ben Clayton | ce93a6b | 2022-12-19 17:07:29 +0000 | [diff] [blame] | 36 | /// Destructor |
| 37 | ~Bool() override; |
Ben Clayton | 4391975 | 2022-03-07 17:05:28 +0000 | [diff] [blame] | 38 | |
Ben Clayton | 7c3e9a6 | 2022-12-16 15:31:19 +0000 | [diff] [blame] | 39 | /// @param other the other node to compare against |
| 40 | /// @returns true if the this type is equal to @p other |
| 41 | bool Equals(const UniqueNode& other) const override; |
Ben Clayton | 4391975 | 2022-03-07 17:05:28 +0000 | [diff] [blame] | 42 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 43 | /// @param symbols the program's symbol table |
| 44 | /// @returns the name for this type that closely resembles how it would be |
| 45 | /// declared in WGSL. |
| 46 | std::string FriendlyName(const SymbolTable& symbols) const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 47 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 48 | /// @returns the size in bytes of the type. |
| 49 | /// @note: booleans are not host-sharable, but still may exist in workgroup |
| 50 | /// storage. |
| 51 | uint32_t Size() const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 52 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 53 | /// @returns the alignment in bytes of the type. |
| 54 | /// @note: booleans are not host-sharable, but still may exist in workgroup |
| 55 | /// storage. |
| 56 | uint32_t Align() const override; |
dan sinclair | f8abdc7 | 2023-01-05 21:07:15 +0000 | [diff] [blame] | 57 | |
| 58 | /// @param ctx the clone context |
| 59 | /// @returns a clone of this type |
| 60 | Bool* Clone(CloneContext& ctx) const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 63 | } // namespace tint::type |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 64 | |
dan sinclair | d37ecf9 | 2022-12-08 16:39:59 +0000 | [diff] [blame] | 65 | #endif // SRC_TINT_TYPE_BOOL_H_ |