Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [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 | |
| 15 | #ifndef SRC_AST_LITERAL_H_ |
| 16 | #define SRC_AST_LITERAL_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | |
Ben Clayton | 6f58546 | 2020-11-13 21:43:58 +0000 | [diff] [blame] | 20 | #include "src/ast/node.h" |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 21 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 22 | namespace tint { |
| 23 | namespace ast { |
| 24 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 25 | /// Base class for a literal value |
Ben Clayton | e319d7f | 2020-11-30 23:30:58 +0000 | [diff] [blame] | 26 | class Literal : public Castable<Literal, Node> { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 27 | public: |
Ben Clayton | 6f58546 | 2020-11-13 21:43:58 +0000 | [diff] [blame] | 28 | ~Literal() override; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 29 | |
Ben Clayton | 6f58546 | 2020-11-13 21:43:58 +0000 | [diff] [blame] | 30 | /// Writes a representation of the node to the output stream |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 31 | /// @param sem the semantic info for the program |
Ben Clayton | 6f58546 | 2020-11-13 21:43:58 +0000 | [diff] [blame] | 32 | /// @param out the stream to write to |
| 33 | /// @param indent number of spaces to indent the node when writing |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 34 | void to_str(const sem::Info& sem, |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 35 | std::ostream& out, |
| 36 | size_t indent) const override; |
Ben Clayton | 6f58546 | 2020-11-13 21:43:58 +0000 | [diff] [blame] | 37 | |
Ben Clayton | dd1b6fc | 2021-01-29 10:55:40 +0000 | [diff] [blame] | 38 | /// @param sem the semantic info for the program |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 39 | /// @returns the literal as a string |
Antonio Maiorano | 5cd71b8 | 2021-04-16 19:07:51 +0000 | [diff] [blame] | 40 | virtual std::string to_str(const sem::Info& sem) const = 0; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 41 | |
dan sinclair | 113fb07 | 2020-03-27 00:45:34 +0000 | [diff] [blame] | 42 | /// @returns the name for this literal. This name is unique to this value. |
| 43 | virtual std::string name() const = 0; |
| 44 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 45 | protected: |
| 46 | /// Constructor |
Ben Clayton | e6995de | 2021-04-13 23:27:27 +0000 | [diff] [blame] | 47 | /// @param program_id the identifier of the program that owns this node |
Ben Clayton | 5ed161b | 2020-12-12 01:35:43 +0000 | [diff] [blame] | 48 | /// @param source the input source |
Ben Clayton | 109b18f | 2021-04-28 13:50:43 +0000 | [diff] [blame] | 49 | Literal(ProgramID program_id, const Source& source); |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | } // namespace ast |
| 53 | } // namespace tint |
| 54 | |
| 55 | #endif // SRC_AST_LITERAL_H_ |