blob: b6b9b621f6b2c3ec2ef23eaee007d66547dcb6fd [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
Ben Clayton3ea3c992020-11-18 21:19:22 +000018#include <memory>
Ben Clayton3ea3c992020-11-18 21:19:22 +000019#include <utility>
Dan Sinclair6e581892020-03-02 15:47:43 -050020
21#include "src/ast/expression.h"
dan sinclairb4fee2f2020-09-22 19:42:13 +000022#include "src/ast/intrinsic.h"
dan sinclair6b59bf42020-12-11 19:16:13 +000023#include "src/symbol.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050024
25namespace tint {
26namespace ast {
27
28/// An identifier expression
Ben Claytone319d7f2020-11-30 23:30:58 +000029class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
Dan Sinclair6e581892020-03-02 15:47:43 -050030 public:
31 /// Constructor
Dan Sinclair6e581892020-03-02 15:47:43 -050032 /// @param source the source
dan sinclair6b59bf42020-12-11 19:16:13 +000033 /// @param sym the symbol for the identifier
dan sinclairc8c31562021-01-11 16:24:32 +000034 IdentifierExpression(const Source& source, Symbol sym);
Dan Sinclair6e581892020-03-02 15:47:43 -050035 /// Move constructor
Ryan Harrison4d32be42020-04-09 18:52:06 +000036 IdentifierExpression(IdentifierExpression&&);
Dan Sinclair6e581892020-03-02 15:47:43 -050037 ~IdentifierExpression() override;
38
dan sinclair6b59bf42020-12-11 19:16:13 +000039 /// @returns the symbol for the identifier
40 Symbol symbol() const { return sym_; }
dan sinclairb4fee2f2020-09-22 19:42:13 +000041
42 /// Sets the intrinsic for this identifier
43 /// @param i the intrinsic to set
44 void set_intrinsic(Intrinsic i) { intrinsic_ = i; }
45 /// @returns the intrinsic this identifier represents
46 Intrinsic intrinsic() const { return intrinsic_; }
Ben Clayton3ea3c992020-11-18 21:19:22 +000047
48 /// Sets the intrinsic signature
49 /// @param s the intrinsic signature to set
50 void set_intrinsic_signature(std::unique_ptr<intrinsic::Signature> s) {
51 intrinsic_sig_ = std::move(s);
52 }
53 /// @returns the intrinsic signature for this identifier.
54 const intrinsic::Signature* intrinsic_signature() const {
55 return intrinsic_sig_.get();
56 }
57
dan sinclairb4fee2f2020-09-22 19:42:13 +000058 /// @returns true if this identifier is for an intrinsic
59 bool IsIntrinsic() const { return intrinsic_ != Intrinsic::kNone; }
Dan Sinclair6e581892020-03-02 15:47:43 -050060
Ben Claytoned2b9782020-12-01 18:04:17 +000061 /// Clones this node and all transitive child nodes using the `CloneContext`
62 /// `ctx`.
63 /// @note Semantic information such as resolved expression type and intrinsic
64 /// information is not cloned.
65 /// @param ctx the clone context
66 /// @return the newly cloned node
67 IdentifierExpression* Clone(CloneContext* ctx) const override;
68
Dan Sinclair6e581892020-03-02 15:47:43 -050069 /// @returns true if the node is valid
70 bool IsValid() const override;
71
72 /// Writes a representation of the node to the output stream
73 /// @param out the stream to write to
74 /// @param indent number of spaces to indent the node when writing
75 void to_str(std::ostream& out, size_t indent) const override;
76
77 private:
78 IdentifierExpression(const IdentifierExpression&) = delete;
79
Ben Claytonbe963762020-12-15 14:52:38 +000080 Symbol const sym_;
dan sinclair987376c2021-01-12 04:34:53 +000081
Ben Claytonbe963762020-12-15 14:52:38 +000082 Intrinsic intrinsic_ = Intrinsic::kNone; // Semantic info
83 std::unique_ptr<intrinsic::Signature> intrinsic_sig_; // Semantic info
Dan Sinclair6e581892020-03-02 15:47:43 -050084};
85
86} // namespace ast
87} // namespace tint
88
89#endif // SRC_AST_IDENTIFIER_EXPRESSION_H_