• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BLOCK_STATEMENT_H_
16 #define SRC_AST_BLOCK_STATEMENT_H_
17 
18 #include <utility>
19 
20 #include "src/ast/statement.h"
21 
22 namespace tint {
23 namespace ast {
24 
25 /// A block statement
26 class BlockStatement : public Castable<BlockStatement, Statement> {
27  public:
28   /// Constructor
29   /// @param program_id the identifier of the program that owns this node
30   /// @param source the block statement source
31   /// @param statements the statements
32   BlockStatement(ProgramID program_id,
33                  const Source& source,
34                  const StatementList& statements);
35   /// Move constructor
36   BlockStatement(BlockStatement&&);
37   ~BlockStatement() override;
38 
39   /// @returns true if the block has no statements
Empty()40   bool Empty() const { return statements.empty(); }
41 
42   /// @returns the last statement in the block or nullptr if block empty
Last()43   const Statement* Last() const {
44     return statements.empty() ? nullptr : statements.back();
45   }
46 
47   /// Clones this node and all transitive child nodes using the `CloneContext`
48   /// `ctx`.
49   /// @param ctx the clone context
50   /// @return the newly cloned node
51   const BlockStatement* Clone(CloneContext* ctx) const override;
52 
53   /// the statement list
54   const StatementList statements;
55 };
56 
57 }  // namespace ast
58 }  // namespace tint
59 
60 #endif  // SRC_AST_BLOCK_STATEMENT_H_
61