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 #include "src/reader/spirv/construct.h"
16
17 namespace tint {
18 namespace reader {
19 namespace spirv {
20
Construct(const Construct * the_parent,int the_depth,Kind the_kind,uint32_t the_begin_id,uint32_t the_end_id,uint32_t the_begin_pos,uint32_t the_end_pos,uint32_t the_scope_end_pos)21 Construct::Construct(const Construct* the_parent,
22 int the_depth,
23 Kind the_kind,
24 uint32_t the_begin_id,
25 uint32_t the_end_id,
26 uint32_t the_begin_pos,
27 uint32_t the_end_pos,
28 uint32_t the_scope_end_pos)
29 : parent(the_parent),
30 enclosing_loop(
31 // Compute the enclosing loop construct. Doing this in the
32 // constructor member list lets us make the member const.
33 // Compare parent depth because loop and continue are siblings and
34 // it's incidental which will appear on the stack first.
35 the_kind == kLoop
36 ? this
37 : ((parent && parent->depth < the_depth) ? parent->enclosing_loop
38 : nullptr)),
39 enclosing_continue(
40 // Compute the enclosing continue construct. Doing this in the
41 // constructor member list lets us make the member const.
42 // Compare parent depth because loop and continue are siblings and
43 // it's incidental which will appear on the stack first.
44 the_kind == kContinue ? this
45 : ((parent && parent->depth < the_depth)
46 ? parent->enclosing_continue
47 : nullptr)),
48 enclosing_loop_or_continue_or_switch(
49 // Compute the enclosing loop or continue or switch construct.
50 // Doing this in the constructor member list lets us make the
51 // member const.
52 // Compare parent depth because loop and continue are siblings and
53 // it's incidental which will appear on the stack first.
54 (the_kind == kLoop || the_kind == kContinue ||
55 the_kind == kSwitchSelection)
56 ? this
57 : ((parent && parent->depth < the_depth)
58 ? parent->enclosing_loop_or_continue_or_switch
59 : nullptr)),
60 depth(the_depth),
61 kind(the_kind),
62 begin_id(the_begin_id),
63 end_id(the_end_id),
64 begin_pos(the_begin_pos),
65 end_pos(the_end_pos),
66 scope_end_pos(the_scope_end_pos) {}
67
68 } // namespace spirv
69 } // namespace reader
70 } // namespace tint
71