daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 7 | #include "compiler/translator/IntermNode.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 9 | void TIntermTraverser::pushParentBlock(TIntermAggregate *node) |
| 10 | { |
| 11 | if (rightToLeft) |
| 12 | mParentBlockStack.push_back(ParentBlock(node, node->getSequence()->size() - 1)); |
| 13 | else |
| 14 | mParentBlockStack.push_back(ParentBlock(node, 0)); |
| 15 | } |
| 16 | |
| 17 | void TIntermTraverser::incrementParentBlockPos() |
| 18 | { |
| 19 | if (rightToLeft) |
| 20 | --mParentBlockStack.back().pos; |
| 21 | else |
| 22 | ++mParentBlockStack.back().pos; |
| 23 | } |
| 24 | |
| 25 | void TIntermTraverser::popParentBlock() |
| 26 | { |
| 27 | ASSERT(!mParentBlockStack.empty()); |
| 28 | mParentBlockStack.pop_back(); |
| 29 | } |
| 30 | |
| 31 | void TIntermTraverser::insertStatementsInParentBlock(const TIntermSequence &insertions) |
| 32 | { |
| 33 | ASSERT(!mParentBlockStack.empty()); |
| 34 | NodeInsertMultipleEntry insert(mParentBlockStack.back().node, mParentBlockStack.back().pos, insertions); |
| 35 | mInsertions.push_back(insert); |
| 36 | } |
| 37 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | // |
| 39 | // Traverse the intermediate representation tree, and |
| 40 | // call a node type specific function for each node. |
| 41 | // Done recursively through the member function Traverse(). |
| 42 | // Node types can be skipped if their function to call is 0, |
| 43 | // but their subtree will still be traversed. |
| 44 | // Nodes with children can have their whole subtree skipped |
| 45 | // if preVisit is turned on and the type specific function |
| 46 | // returns false. |
| 47 | // |
| 48 | // preVisit, postVisit, and rightToLeft control what order |
| 49 | // nodes are visited in. |
| 50 | // |
| 51 | |
| 52 | // |
| 53 | // Traversal functions for terminals are straighforward.... |
| 54 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 55 | void TIntermSymbol::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 56 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 57 | it->visitSymbol(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 60 | void TIntermConstantUnion::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 61 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 62 | it->visitConstantUnion(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // |
| 66 | // Traverse a binary node. |
| 67 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 68 | void TIntermBinary::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 69 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 70 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 71 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 72 | // |
| 73 | // visit the node before children if pre-visiting. |
| 74 | // |
| 75 | if (it->preVisit) |
| 76 | visit = it->visitBinary(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 77 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 78 | // |
| 79 | // Visit the children, in the right order. |
| 80 | // |
| 81 | if (visit) |
| 82 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 83 | it->incrementDepth(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 84 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 85 | if (it->rightToLeft) |
| 86 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 87 | if (mRight) |
| 88 | mRight->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 89 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 90 | if (it->inVisit) |
| 91 | visit = it->visitBinary(InVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 92 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 93 | if (visit && mLeft) |
| 94 | mLeft->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 95 | } |
| 96 | else |
| 97 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 98 | if (mLeft) |
| 99 | mLeft->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 100 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 101 | if (it->inVisit) |
| 102 | visit = it->visitBinary(InVisit, this); |
| 103 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 104 | if (visit && mRight) |
| 105 | mRight->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | it->decrementDepth(); |
| 109 | } |
| 110 | |
| 111 | // |
| 112 | // Visit the node after the children, if requested and the traversal |
| 113 | // hasn't been cancelled yet. |
| 114 | // |
| 115 | if (visit && it->postVisit) |
| 116 | it->visitBinary(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // |
| 120 | // Traverse a unary node. Same comments in binary node apply here. |
| 121 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 122 | void TIntermUnary::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 123 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 124 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 125 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 126 | if (it->preVisit) |
| 127 | visit = it->visitUnary(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 128 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 129 | if (visit) { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 130 | it->incrementDepth(this); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 131 | mOperand->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 132 | it->decrementDepth(); |
| 133 | } |
| 134 | |
| 135 | if (visit && it->postVisit) |
| 136 | it->visitUnary(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | // |
| 140 | // Traverse an aggregate node. Same comments in binary node apply here. |
| 141 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 142 | void TIntermAggregate::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 143 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 144 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 145 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 146 | if (it->preVisit) |
| 147 | visit = it->visitAggregate(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 148 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 149 | if (visit) |
| 150 | { |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 151 | if (mOp == EOpSequence) |
| 152 | it->pushParentBlock(this); |
| 153 | |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 154 | it->incrementDepth(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 155 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 156 | if (it->rightToLeft) |
| 157 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 158 | for (TIntermSequence::reverse_iterator sit = mSequence.rbegin(); |
| 159 | sit != mSequence.rend(); sit++) |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 160 | { |
| 161 | (*sit)->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 162 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 163 | if (visit && it->inVisit) |
| 164 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 165 | if (*sit != mSequence.front()) |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 166 | visit = it->visitAggregate(InVisit, this); |
| 167 | } |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 168 | if (mOp == EOpSequence) |
| 169 | { |
| 170 | it->incrementParentBlockPos(); |
| 171 | } |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | else |
| 175 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 176 | for (TIntermSequence::iterator sit = mSequence.begin(); |
| 177 | sit != mSequence.end(); sit++) |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 178 | { |
| 179 | (*sit)->traverse(it); |
| 180 | |
| 181 | if (visit && it->inVisit) |
| 182 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 183 | if (*sit != mSequence.back()) |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 184 | visit = it->visitAggregate(InVisit, this); |
| 185 | } |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 186 | if (mOp == EOpSequence) |
| 187 | { |
| 188 | it->incrementParentBlockPos(); |
| 189 | } |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | it->decrementDepth(); |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 194 | |
| 195 | if (mOp == EOpSequence) |
| 196 | it->popParentBlock(); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (visit && it->postVisit) |
| 200 | it->visitAggregate(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | // |
| 204 | // Traverse a selection node. Same comments in binary node apply here. |
| 205 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 206 | void TIntermSelection::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 207 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 208 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 209 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 210 | if (it->preVisit) |
| 211 | visit = it->visitSelection(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 212 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 213 | if (visit) |
| 214 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 215 | it->incrementDepth(this); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 216 | if (it->rightToLeft) |
| 217 | { |
| 218 | if (mFalseBlock) |
| 219 | mFalseBlock->traverse(it); |
| 220 | if (mTrueBlock) |
| 221 | mTrueBlock->traverse(it); |
| 222 | mCondition->traverse(it); |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | mCondition->traverse(it); |
| 227 | if (mTrueBlock) |
| 228 | mTrueBlock->traverse(it); |
| 229 | if (mFalseBlock) |
| 230 | mFalseBlock->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 231 | } |
| 232 | it->decrementDepth(); |
| 233 | } |
| 234 | |
| 235 | if (visit && it->postVisit) |
| 236 | it->visitSelection(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 240 | // Traverse a switch node. Same comments in binary node apply here. |
| 241 | // |
| 242 | void TIntermSwitch::traverse(TIntermTraverser *it) |
| 243 | { |
| 244 | bool visit = true; |
| 245 | |
| 246 | if (it->preVisit) |
| 247 | visit = it->visitSwitch(PreVisit, this); |
| 248 | |
| 249 | if (visit) |
| 250 | { |
| 251 | it->incrementDepth(this); |
| 252 | if (it->rightToLeft) |
| 253 | { |
| 254 | if (mStatementList) |
| 255 | mStatementList->traverse(it); |
| 256 | if (it->inVisit) |
| 257 | visit = it->visitSwitch(InVisit, this); |
| 258 | if (visit) |
| 259 | mInit->traverse(it); |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | mInit->traverse(it); |
| 264 | if (it->inVisit) |
| 265 | visit = it->visitSwitch(InVisit, this); |
| 266 | if (visit && mStatementList) |
| 267 | mStatementList->traverse(it); |
| 268 | } |
| 269 | it->decrementDepth(); |
| 270 | } |
| 271 | |
| 272 | if (visit && it->postVisit) |
| 273 | it->visitSwitch(PostVisit, this); |
| 274 | } |
| 275 | |
| 276 | // |
| 277 | // Traverse a switch node. Same comments in binary node apply here. |
| 278 | // |
| 279 | void TIntermCase::traverse(TIntermTraverser *it) |
| 280 | { |
| 281 | bool visit = true; |
| 282 | |
| 283 | if (it->preVisit) |
| 284 | visit = it->visitCase(PreVisit, this); |
| 285 | |
| 286 | if (visit && mCondition) |
| 287 | mCondition->traverse(it); |
| 288 | |
| 289 | if (visit && it->postVisit) |
| 290 | it->visitCase(PostVisit, this); |
| 291 | } |
| 292 | |
| 293 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 294 | // Traverse a loop node. Same comments in binary node apply here. |
| 295 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 296 | void TIntermLoop::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 297 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 298 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 299 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 300 | if (it->preVisit) |
| 301 | visit = it->visitLoop(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 302 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 303 | if (visit) |
| 304 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 305 | it->incrementDepth(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 306 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 307 | if (it->rightToLeft) |
| 308 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 309 | if (mExpr) |
| 310 | mExpr->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 311 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 312 | if (mBody) |
| 313 | mBody->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 314 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 315 | if (mCond) |
| 316 | mCond->traverse(it); |
Zhenyao Mo | 6cb95f3 | 2013-10-03 17:01:52 -0700 | [diff] [blame] | 317 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 318 | if (mInit) |
| 319 | mInit->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 320 | } |
| 321 | else |
| 322 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 323 | if (mInit) |
| 324 | mInit->traverse(it); |
Zhenyao Mo | 6cb95f3 | 2013-10-03 17:01:52 -0700 | [diff] [blame] | 325 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 326 | if (mCond) |
| 327 | mCond->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 328 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 329 | if (mBody) |
| 330 | mBody->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 331 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 332 | if (mExpr) |
| 333 | mExpr->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 334 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 335 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 336 | it->decrementDepth(); |
| 337 | } |
| 338 | |
| 339 | if (visit && it->postVisit) |
| 340 | it->visitLoop(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // |
| 344 | // Traverse a branch node. Same comments in binary node apply here. |
| 345 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 346 | void TIntermBranch::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 347 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 348 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 349 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 350 | if (it->preVisit) |
| 351 | visit = it->visitBranch(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 352 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 353 | if (visit && mExpression) { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 354 | it->incrementDepth(this); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 355 | mExpression->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 356 | it->decrementDepth(); |
| 357 | } |
| 358 | |
| 359 | if (visit && it->postVisit) |
| 360 | it->visitBranch(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 363 | void TIntermRaw::traverse(TIntermTraverser *it) |
| 364 | { |
| 365 | it->visitRaw(this); |
| 366 | } |