1d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Licensed under the Apache License, Version 2.0 (the "License");
4d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// you may not use this file except in compliance with the License.
5d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// You may obtain a copy of the License at
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
7d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//    http://www.apache.org/licenses/LICENSE-2.0
8d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//
9d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Unless required by applicable law or agreed to in writing, software
10d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// distributed under the License is distributed on an "AS IS" BASIS,
11d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// See the License for the specific language governing permissions and
13d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// limitations under the License.
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
15cc863da574ed5079b055574127fe5788a9a0fc33Nicolas Capens#include "intermediate.h"
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse the intermediate representation tree, and
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// call a node type specific function for each node.
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Done recursively through the member function Traverse().
21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Node types can be skipped if their function to call is 0,
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// but their subtree will still be traversed.
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Nodes with children can have their whole subtree skipped
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// if preVisit is turned on and the type specific function
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// returns false.
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// preVisit, postVisit, and rightToLeft control what order
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// nodes are visited in.
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traversal functions for terminals are straighforward....
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermSymbol::traverse(TIntermTraverser* it)
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	it->visitSymbol(this);
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermConstantUnion::traverse(TIntermTraverser* it)
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	it->visitConstantUnion(this);
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse a binary node.
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermBinary::traverse(TIntermTraverser* it)
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	// visit the node before children if pre-visiting.
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(it->preVisit)
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitBinary(PreVisit, this);
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
58d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	// Visit the children, in the right order.
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit)
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
6476a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
66d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		if(it->rightToLeft)
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(right)
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				right->traverse(it);
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
72d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(it->inVisit)
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				visit = it->visitBinary(InVisit, this);
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(visit && left)
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				left->traverse(it);
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(left)
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				left->traverse(it);
88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
89d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(it->inVisit)
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				visit = it->visitBinary(InVisit, this);
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(visit && right)
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				right->traverse(it);
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	// Visit the node after the children, if requested and the traversal
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	// hasn't been cancelled yet.
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	//
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit && it->postVisit)
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitBinary(PostVisit, this);
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse a unary node.  Same comments in binary node apply here.
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermUnary::traverse(TIntermTraverser* it)
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (it->preVisit)
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitUnary(PreVisit, this);
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit) {
12576a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		operand->traverse(it);
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
129d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit && it->postVisit)
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitUnary(PostVisit, this);
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse an aggregate node.  Same comments in binary node apply here.
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermAggregate::traverse(TIntermTraverser* it)
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
140d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(it->preVisit)
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitAggregate(PreVisit, this);
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
145d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit)
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
14876a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(it->rightToLeft)
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(TIntermSequence::reverse_iterator sit = sequence.rbegin(); sit != sequence.rend(); sit++)
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				(*sit)->traverse(it);
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				if(visit && it->inVisit)
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					if(*sit != sequence.front())
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						visit = it->visitAggregate(InVisit, this);
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			for(TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				(*sit)->traverse(it);
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				if(visit && it->inVisit)
172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				{
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					if(*sit != sequence.back())
174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					{
175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman						visit = it->visitAggregate(InVisit, this);
176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman					}
177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				}
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
180d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit && it->postVisit)
185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitAggregate(PostVisit, this);
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse a selection node.  Same comments in binary node apply here.
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermSelection::traverse(TIntermTraverser* it)
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (it->preVisit)
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitSelection(PreVisit, this);
199d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit) {
20176a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if (it->rightToLeft) {
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if (falseBlock)
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				falseBlock->traverse(it);
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if (trueBlock)
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				trueBlock->traverse(it);
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition->traverse(it);
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		} else {
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			condition->traverse(it);
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if (trueBlock)
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				trueBlock->traverse(it);
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if (falseBlock)
213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				falseBlock->traverse(it);
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit && it->postVisit)
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitSelection(PostVisit, this);
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
22376a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu// Traverse a switch node.  Same comments in binary node apply here.
22476a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu//
22576a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetuvoid TIntermSwitch::traverse(TIntermTraverser *it)
22676a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu{
22776a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	bool visit = true;
22876a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
22976a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(it->preVisit)
23076a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		visit = it->visitSwitch(PreVisit, this);
23176a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
23276a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(visit)
23376a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	{
23476a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
235478dd9a470bc45758a9400af6b2896c2f3d4abf6Alexis Hetu		if(it->inVisit)
236478dd9a470bc45758a9400af6b2896c2f3d4abf6Alexis Hetu			visit = it->visitSwitch(InVisit, this);
23776a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->decrementDepth();
23876a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	}
23976a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
24076a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(visit && it->postVisit)
24176a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->visitSwitch(PostVisit, this);
24276a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu}
24376a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
24476a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu//
24576a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu// Traverse a switch node.  Same comments in binary node apply here.
24676a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu//
24776a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetuvoid TIntermCase::traverse(TIntermTraverser *it)
24876a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu{
24976a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	bool visit = true;
25076a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
25176a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(it->preVisit)
25276a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		visit = it->visitCase(PreVisit, this);
25376a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
25476a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(visit && mCondition)
25576a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		mCondition->traverse(it);
25676a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
25776a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu	if(visit && it->postVisit)
25876a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->visitCase(PostVisit, this);
25976a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu}
26076a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu
26176a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu//
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse a loop node.  Same comments in binary node apply here.
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermLoop::traverse(TIntermTraverser* it)
265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(it->preVisit)
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitLoop(PreVisit, this);
271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
272d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit)
274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
27576a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		if(it->rightToLeft)
278894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(expr)
280894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				expr->traverse(it);
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(body)
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				body->traverse(it);
287894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
288894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
289894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(cond)
290894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
291894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				cond->traverse(it);
292894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
293894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
294894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		else
295894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		{
296894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(cond)
297894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
298894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				cond->traverse(it);
299894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(body)
302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				body->traverse(it);
304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			if(expr)
307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			{
308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman				expr->traverse(it);
309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman			}
310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		}
311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
314894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if(visit && it->postVisit)
316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	{
317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitLoop(PostVisit, this);
318894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Traverse a branch node.  Same comments in binary node apply here.
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid TIntermBranch::traverse(TIntermTraverser* it)
325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	bool visit = true;
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (it->preVisit)
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		visit = it->visitBranch(PreVisit, this);
330d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit && expression) {
33276a343af4ea1f781a56fec006b5fe67a5615d5f8Alexis Hetu		it->incrementDepth(this);
333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		expression->traverse(it);
334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->decrementDepth();
335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	}
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman	if (visit && it->postVisit)
338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman		it->visitBranch(PostVisit, this);
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
341