blob: 8fd9cfa9376700ba2e9da04bfe34fdfbf2aab8a4 [file] [log] [blame]
Ben Claytondcdf66e2022-06-17 12:48:51 +00001// Copyright 2022 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_TINT_AST_LET_H_
16#define SRC_TINT_AST_LET_H_
17
18#include "src/tint/ast/variable.h"
19
20namespace tint::ast {
21
22/// A "let" declaration is a name for a function-scoped runtime typed value.
23///
24/// Examples:
25///
26/// ```
27/// let twice_depth : i32 = width + width; // Must have initializer
28/// ```
29/// @see https://www.w3.org/TR/WGSL/#let-decls
30class Let final : public Castable<Let, Variable> {
31 public:
32 /// Create a 'let' variable
Ben Clayton4a92a3c2022-07-18 20:50:02 +000033 /// @param pid the identifier of the program that owns this node
34 /// @param nid the unique node identifier
Ben Claytondcdf66e2022-06-17 12:48:51 +000035 /// @param source the variable source
36 /// @param sym the variable symbol
37 /// @param type the declared variable type
dan sinclair6e77b472022-10-20 13:38:28 +000038 /// @param initializer the initializer expression
Ben Claytondcdf66e2022-06-17 12:48:51 +000039 /// @param attributes the variable attributes
Ben Clayton4a92a3c2022-07-18 20:50:02 +000040 Let(ProgramID pid,
41 NodeID nid,
Ben Claytondcdf66e2022-06-17 12:48:51 +000042 const Source& source,
43 const Symbol& sym,
44 const ast::Type* type,
dan sinclair6e77b472022-10-20 13:38:28 +000045 const Expression* initializer,
Ben Clayton783b1692022-08-02 17:03:35 +000046 utils::VectorRef<const Attribute*> attributes);
Ben Claytondcdf66e2022-06-17 12:48:51 +000047
48 /// Move constructor
49 Let(Let&&);
50
51 /// Destructor
52 ~Let() override;
53
Ben Claytone48ef8e2022-06-26 10:52:50 +000054 /// @returns "let"
55 const char* Kind() const override;
56
Ben Claytondcdf66e2022-06-17 12:48:51 +000057 /// Clones this node and all transitive child nodes using the `CloneContext`
58 /// `ctx`.
59 /// @param ctx the clone context
60 /// @return the newly cloned node
61 const Let* Clone(CloneContext* ctx) const override;
62};
63
64} // namespace tint::ast
65
66#endif // SRC_TINT_AST_LET_H_