Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1 | // Copyright 2020 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 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 15 | #ifndef SRC_TINT_LANG_WGSL_AST_INT_LITERAL_EXPRESSION_H_ |
| 16 | #define SRC_TINT_LANG_WGSL_AST_INT_LITERAL_EXPRESSION_H_ |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 17 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 18 | #include "src/tint/lang/wgsl/ast/literal_expression.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 19 | |
dan sinclair | 34323ac | 2022-04-07 18:39:35 +0000 | [diff] [blame] | 20 | namespace tint::ast { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 21 | |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 22 | /// An integer literal. The literal may have an 'i', 'u' or no suffix. |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 23 | class IntLiteralExpression final : public Castable<IntLiteralExpression, LiteralExpression> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 24 | public: |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 25 | /// Literal suffix |
| 26 | enum class Suffix { |
| 27 | /// No suffix |
| 28 | kNone, |
| 29 | /// 'i' suffix (i32) |
| 30 | kI, |
| 31 | /// 'u' suffix (u32) |
| 32 | kU, |
| 33 | }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 34 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 35 | /// Constructor |
| 36 | /// @param pid the identifier of the program that owns this node |
Ben Clayton | 4a92a3c | 2022-07-18 20:50:02 +0000 | [diff] [blame] | 37 | /// @param nid the unique node identifier |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 38 | /// @param src the source of this node |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 39 | /// @param val the literal value |
| 40 | /// @param suf the literal suffix |
dan sinclair | 637a2fe | 2023-07-24 21:11:41 +0000 | [diff] [blame] | 41 | IntLiteralExpression(GenerationID pid, NodeID nid, const Source& src, int64_t val, Suffix suf); |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 42 | |
| 43 | ~IntLiteralExpression() override; |
| 44 | |
| 45 | /// Clones this node and all transitive child nodes using the `CloneContext` |
| 46 | /// `ctx`. |
| 47 | /// @param ctx the clone context |
| 48 | /// @return the newly cloned node |
Ben Clayton | ae18c41 | 2023-07-29 13:00:40 +0000 | [diff] [blame] | 49 | const IntLiteralExpression* Clone(CloneContext& ctx) const override; |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 50 | |
| 51 | /// The literal value |
| 52 | const int64_t value; |
| 53 | |
| 54 | /// The literal suffix |
| 55 | const Suffix suffix; |
| 56 | }; |
| 57 | |
Ben Clayton | 6891960 | 2023-07-28 22:51:18 +0000 | [diff] [blame] | 58 | /// @param suffix the enum value |
| 59 | /// @returns the string for the given enum value |
| 60 | std::string_view ToString(IntLiteralExpression::Suffix suffix); |
| 61 | |
dan sinclair | 6cc183c | 2023-03-02 21:28:45 +0000 | [diff] [blame] | 62 | /// Writes the integer literal suffix to the stream. |
| 63 | /// @param out the stream to write to |
Ben Clayton | 8822e29 | 2022-05-04 22:18:49 +0000 | [diff] [blame] | 64 | /// @param suffix the suffix to write |
| 65 | /// @returns out so calls can be chained |
Ben Clayton | 6891960 | 2023-07-28 22:51:18 +0000 | [diff] [blame] | 66 | template <typename STREAM, typename = traits::EnableIfIsOStream<STREAM>> |
| 67 | auto& operator<<(STREAM& out, IntLiteralExpression::Suffix suffix) { |
| 68 | return out << ToString(suffix); |
| 69 | } |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 70 | |
dan sinclair | 34323ac | 2022-04-07 18:39:35 +0000 | [diff] [blame] | 71 | } // namespace tint::ast |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 72 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 73 | #endif // SRC_TINT_LANG_WGSL_AST_INT_LITERAL_EXPRESSION_H_ |