blob: 3deff1685782f7644331805a59490420ce43c4ae [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_IDENTIFIER_EXPRESSION_H_
16#define SRC_AST_IDENTIFIER_EXPRESSION_H_
17
Dan Sinclair6e581892020-03-02 15:47:43 -050018#include "src/ast/expression.h"
19
20namespace tint {
21namespace ast {
22
23/// An identifier expression
Ben Claytone319d7f2020-11-30 23:30:58 +000024class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
Dan Sinclair6e581892020-03-02 15:47:43 -050025 public:
26 /// Constructor
Ben Claytone6995de2021-04-13 23:27:27 +000027 /// @param program_id the identifier of the program that owns this node
Dan Sinclair6e581892020-03-02 15:47:43 -050028 /// @param source the source
dan sinclair6b59bf42020-12-11 19:16:13 +000029 /// @param sym the symbol for the identifier
Ben Claytone6995de2021-04-13 23:27:27 +000030 IdentifierExpression(ProgramID program_id, const Source& source, Symbol sym);
Dan Sinclair6e581892020-03-02 15:47:43 -050031 /// Move constructor
Ryan Harrison4d32be42020-04-09 18:52:06 +000032 IdentifierExpression(IdentifierExpression&&);
Dan Sinclair6e581892020-03-02 15:47:43 -050033 ~IdentifierExpression() override;
34
dan sinclair6b59bf42020-12-11 19:16:13 +000035 /// @returns the symbol for the identifier
36 Symbol symbol() const { return sym_; }
dan sinclairb4fee2f2020-09-22 19:42:13 +000037
Ben Claytoned2b9782020-12-01 18:04:17 +000038 /// Clones this node and all transitive child nodes using the `CloneContext`
39 /// `ctx`.
Ben Claytoned2b9782020-12-01 18:04:17 +000040 /// @param ctx the clone context
41 /// @return the newly cloned node
42 IdentifierExpression* Clone(CloneContext* ctx) const override;
43
Dan Sinclair6e581892020-03-02 15:47:43 -050044 /// Writes a representation of the node to the output stream
Ben Claytondd1b6fc2021-01-29 10:55:40 +000045 /// @param sem the semantic info for the program
Dan Sinclair6e581892020-03-02 15:47:43 -050046 /// @param out the stream to write to
47 /// @param indent number of spaces to indent the node when writing
Antonio Maiorano5cd71b82021-04-16 19:07:51 +000048 void to_str(const sem::Info& sem,
Ben Claytondd1b6fc2021-01-29 10:55:40 +000049 std::ostream& out,
50 size_t indent) const override;
Dan Sinclair6e581892020-03-02 15:47:43 -050051
52 private:
53 IdentifierExpression(const IdentifierExpression&) = delete;
54
Ben Claytonbe963762020-12-15 14:52:38 +000055 Symbol const sym_;
Dan Sinclair6e581892020-03-02 15:47:43 -050056};
57
58} // namespace ast
59} // namespace tint
60
61#endif // SRC_AST_IDENTIFIER_EXPRESSION_H_