• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 #include "src/sem/block_statement.h"
16 
17 #include "src/ast/block_statement.h"
18 #include "src/ast/function.h"
19 #include "src/sem/function.h"
20 
21 TINT_INSTANTIATE_TYPEINFO(tint::sem::BlockStatement);
22 TINT_INSTANTIATE_TYPEINFO(tint::sem::FunctionBlockStatement);
23 TINT_INSTANTIATE_TYPEINFO(tint::sem::LoopBlockStatement);
24 
25 namespace tint {
26 namespace sem {
27 
BlockStatement(const ast::BlockStatement * declaration,const CompoundStatement * parent,const sem::Function * function)28 BlockStatement::BlockStatement(const ast::BlockStatement* declaration,
29                                const CompoundStatement* parent,
30                                const sem::Function* function)
31     : Base(declaration, parent, function) {}
32 
33 BlockStatement::~BlockStatement() = default;
34 
Declaration() const35 const ast::BlockStatement* BlockStatement::Declaration() const {
36   return Base::Declaration()->As<ast::BlockStatement>();
37 }
38 
AddDecl(const ast::Variable * var)39 void BlockStatement::AddDecl(const ast::Variable* var) {
40   decls_.push_back(var);
41 }
42 
FunctionBlockStatement(const sem::Function * function)43 FunctionBlockStatement::FunctionBlockStatement(const sem::Function* function)
44     : Base(function->Declaration()->body, nullptr, function) {
45   TINT_ASSERT(Semantic, function);
46 }
47 
48 FunctionBlockStatement::~FunctionBlockStatement() = default;
49 
LoopBlockStatement(const ast::BlockStatement * declaration,const CompoundStatement * parent,const sem::Function * function)50 LoopBlockStatement::LoopBlockStatement(const ast::BlockStatement* declaration,
51                                        const CompoundStatement* parent,
52                                        const sem::Function* function)
53     : Base(declaration, parent, function) {
54   TINT_ASSERT(Semantic, parent);
55   TINT_ASSERT(Semantic, function);
56 }
57 LoopBlockStatement::~LoopBlockStatement() = default;
58 
SetFirstContinue(const ast::ContinueStatement * first_continue,size_t num_decls)59 void LoopBlockStatement::SetFirstContinue(
60     const ast::ContinueStatement* first_continue,
61     size_t num_decls) {
62   first_continue_ = first_continue;
63   num_decls_at_first_continue_ = num_decls;
64 }
65 
66 }  // namespace sem
67 }  // namespace tint
68