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