• 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/variable.h"
16 
17 #include <utility>
18 
19 #include "src/ast/identifier_expression.h"
20 #include "src/ast/variable.h"
21 
22 TINT_INSTANTIATE_TYPEINFO(tint::sem::Variable);
23 TINT_INSTANTIATE_TYPEINFO(tint::sem::GlobalVariable);
24 TINT_INSTANTIATE_TYPEINFO(tint::sem::LocalVariable);
25 TINT_INSTANTIATE_TYPEINFO(tint::sem::Parameter);
26 TINT_INSTANTIATE_TYPEINFO(tint::sem::VariableUser);
27 
28 namespace tint {
29 namespace sem {
30 
Variable(const ast::Variable * declaration,const sem::Type * type,ast::StorageClass storage_class,ast::Access access,Constant constant_value)31 Variable::Variable(const ast::Variable* declaration,
32                    const sem::Type* type,
33                    ast::StorageClass storage_class,
34                    ast::Access access,
35                    Constant constant_value)
36     : declaration_(declaration),
37       type_(type),
38       storage_class_(storage_class),
39       access_(access),
40       constant_value_(constant_value) {}
41 
42 Variable::~Variable() = default;
43 
LocalVariable(const ast::Variable * declaration,const sem::Type * type,ast::StorageClass storage_class,ast::Access access,const sem::Statement * statement,Constant constant_value)44 LocalVariable::LocalVariable(const ast::Variable* declaration,
45                              const sem::Type* type,
46                              ast::StorageClass storage_class,
47                              ast::Access access,
48                              const sem::Statement* statement,
49                              Constant constant_value)
50     : Base(declaration, type, storage_class, access, std::move(constant_value)),
51       statement_(statement) {}
52 
53 LocalVariable::~LocalVariable() = default;
54 
GlobalVariable(const ast::Variable * declaration,const sem::Type * type,ast::StorageClass storage_class,ast::Access access,Constant constant_value,sem::BindingPoint binding_point)55 GlobalVariable::GlobalVariable(const ast::Variable* declaration,
56                                const sem::Type* type,
57                                ast::StorageClass storage_class,
58                                ast::Access access,
59                                Constant constant_value,
60                                sem::BindingPoint binding_point)
61     : Base(declaration, type, storage_class, access, std::move(constant_value)),
62       binding_point_(binding_point) {}
63 
64 GlobalVariable::~GlobalVariable() = default;
65 
Parameter(const ast::Variable * declaration,uint32_t index,const sem::Type * type,ast::StorageClass storage_class,ast::Access access,const ParameterUsage usage)66 Parameter::Parameter(const ast::Variable* declaration,
67                      uint32_t index,
68                      const sem::Type* type,
69                      ast::StorageClass storage_class,
70                      ast::Access access,
71                      const ParameterUsage usage /* = ParameterUsage::kNone */)
72     : Base(declaration, type, storage_class, access, Constant{}),
73       index_(index),
74       usage_(usage) {}
75 
76 Parameter::~Parameter() = default;
77 
VariableUser(const ast::IdentifierExpression * declaration,Statement * statement,sem::Variable * variable)78 VariableUser::VariableUser(const ast::IdentifierExpression* declaration,
79                            Statement* statement,
80                            sem::Variable* variable)
81     : Base(declaration, variable->Type(), statement, variable->ConstantValue()),
82       variable_(variable) {}
83 
84 }  // namespace sem
85 }  // namespace tint
86