blob: e8828d7efd960c972caeb201d4147ba9bf6e1a20 [file] [log] [blame]
Dan Sinclair6e581892020-03-02 15:47:43 -05001// 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 Clayton6f585462020-11-13 21:43:58 +000020#include "src/ast/node.h"
dan sinclair113fb072020-03-27 00:45:34 +000021
Dan Sinclair6e581892020-03-02 15:47:43 -050022namespace tint {
23namespace ast {
24
Dan Sinclair6e581892020-03-02 15:47:43 -050025/// Base class for a literal value
Ben Claytone319d7f2020-11-30 23:30:58 +000026class Literal : public Castable<Literal, Node> {
Dan Sinclair6e581892020-03-02 15:47:43 -050027 public:
Ben Clayton6f585462020-11-13 21:43:58 +000028 ~Literal() override;
Dan Sinclair6e581892020-03-02 15:47:43 -050029
Ben Clayton6f585462020-11-13 21:43:58 +000030 /// Writes a representation of the node to the output stream
Ben Claytondd1b6fc2021-01-29 10:55:40 +000031 /// @param sem the semantic info for the program
Ben Clayton6f585462020-11-13 21:43:58 +000032 /// @param out the stream to write to
33 /// @param indent number of spaces to indent the node when writing
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000034 void to_str(const sem::Info& sem,
Ben Claytondd1b6fc2021-01-29 10:55:40 +000035 std::ostream& out,
36 size_t indent) const override;
Ben Clayton6f585462020-11-13 21:43:58 +000037
Ben Claytondd1b6fc2021-01-29 10:55:40 +000038 /// @param sem the semantic info for the program
Dan Sinclair6e581892020-03-02 15:47:43 -050039 /// @returns the literal as a string
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000040 virtual std::string to_str(const sem::Info& sem) const = 0;
Dan Sinclair6e581892020-03-02 15:47:43 -050041
dan sinclair113fb072020-03-27 00:45:34 +000042 /// @returns the name for this literal. This name is unique to this value.
43 virtual std::string name() const = 0;
44
Dan Sinclair6e581892020-03-02 15:47:43 -050045 protected:
46 /// Constructor
Ben Claytone6995de2021-04-13 23:27:27 +000047 /// @param program_id the identifier of the program that owns this node
Ben Clayton5ed161b2020-12-12 01:35:43 +000048 /// @param source the input source
Ben Clayton109b18f2021-04-28 13:50:43 +000049 Literal(ProgramID program_id, const Source& source);
Dan Sinclair6e581892020-03-02 15:47:43 -050050};
51
52} // namespace ast
53} // namespace tint
54
55#endif // SRC_AST_LITERAL_H_