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