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 | { |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 12 | mParentBlockStack.push_back(ParentBlock(node, 0)); |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | void TIntermTraverser::incrementParentBlockPos() |
| 16 | { |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 17 | ++mParentBlockStack.back().pos; |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void TIntermTraverser::popParentBlock() |
| 21 | { |
| 22 | ASSERT(!mParentBlockStack.empty()); |
| 23 | mParentBlockStack.pop_back(); |
| 24 | } |
| 25 | |
| 26 | void TIntermTraverser::insertStatementsInParentBlock(const TIntermSequence &insertions) |
| 27 | { |
| 28 | ASSERT(!mParentBlockStack.empty()); |
| 29 | NodeInsertMultipleEntry insert(mParentBlockStack.back().node, mParentBlockStack.back().pos, insertions); |
| 30 | mInsertions.push_back(insert); |
| 31 | } |
| 32 | |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 33 | TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type, TQualifier qualifier) |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 34 | { |
| 35 | // Each traversal uses at most one temporary variable, so the index stays the same within a single traversal. |
| 36 | TInfoSinkBase symbolNameOut; |
| 37 | ASSERT(mTemporaryIndex != nullptr); |
| 38 | symbolNameOut << "s" << (*mTemporaryIndex); |
| 39 | TString symbolName = symbolNameOut.c_str(); |
| 40 | |
| 41 | TIntermSymbol *node = new TIntermSymbol(0, symbolName, type); |
| 42 | node->setInternal(true); |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 43 | node->getTypePointer()->setQualifier(qualifier); |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 44 | return node; |
| 45 | } |
| 46 | |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 47 | TIntermSymbol *TIntermTraverser::createTempSymbol(const TType &type) |
| 48 | { |
| 49 | return createTempSymbol(type, EvqTemporary); |
| 50 | } |
| 51 | |
Olli Etuaho | 4f1af78 | 2015-05-25 11:55:07 +0300 | [diff] [blame] | 52 | TIntermAggregate *TIntermTraverser::createTempDeclaration(const TType &type) |
| 53 | { |
| 54 | TIntermAggregate *tempDeclaration = new TIntermAggregate(EOpDeclaration); |
| 55 | tempDeclaration->getSequence()->push_back(createTempSymbol(type)); |
| 56 | return tempDeclaration; |
| 57 | } |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 58 | |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 59 | TIntermAggregate *TIntermTraverser::createTempInitDeclaration(TIntermTyped *initializer, TQualifier qualifier) |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 60 | { |
| 61 | ASSERT(initializer != nullptr); |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 62 | TIntermSymbol *tempSymbol = createTempSymbol(initializer->getType(), qualifier); |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 63 | TIntermAggregate *tempDeclaration = new TIntermAggregate(EOpDeclaration); |
| 64 | TIntermBinary *tempInit = new TIntermBinary(EOpInitialize); |
| 65 | tempInit->setLeft(tempSymbol); |
| 66 | tempInit->setRight(initializer); |
| 67 | tempInit->setType(tempSymbol->getType()); |
| 68 | tempDeclaration->getSequence()->push_back(tempInit); |
| 69 | return tempDeclaration; |
| 70 | } |
| 71 | |
Olli Etuaho | a4aa4e3 | 2015-06-04 15:54:30 +0300 | [diff] [blame] | 72 | TIntermAggregate *TIntermTraverser::createTempInitDeclaration(TIntermTyped *initializer) |
| 73 | { |
| 74 | return createTempInitDeclaration(initializer, EvqTemporary); |
| 75 | } |
| 76 | |
Olli Etuaho | d4f303e | 2015-05-20 17:09:06 +0300 | [diff] [blame] | 77 | TIntermBinary *TIntermTraverser::createTempAssignment(TIntermTyped *rightNode) |
| 78 | { |
| 79 | ASSERT(rightNode != nullptr); |
| 80 | TIntermSymbol *tempSymbol = createTempSymbol(rightNode->getType()); |
| 81 | TIntermBinary *assignment = new TIntermBinary(EOpAssign); |
| 82 | assignment->setLeft(tempSymbol); |
| 83 | assignment->setRight(rightNode); |
| 84 | assignment->setType(tempSymbol->getType()); |
| 85 | return assignment; |
| 86 | } |
| 87 | |
| 88 | void TIntermTraverser::useTemporaryIndex(unsigned int *temporaryIndex) |
| 89 | { |
| 90 | mTemporaryIndex = temporaryIndex; |
| 91 | } |
| 92 | |
| 93 | void TIntermTraverser::nextTemporaryIndex() |
| 94 | { |
| 95 | ASSERT(mTemporaryIndex != nullptr); |
| 96 | ++(*mTemporaryIndex); |
| 97 | } |
| 98 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 99 | void TIntermTraverser::addToFunctionMap(const TString &name, TIntermSequence *paramSequence) |
| 100 | { |
| 101 | mFunctionMap[name] = paramSequence; |
| 102 | } |
| 103 | |
| 104 | bool TIntermTraverser::isInFunctionMap(const TIntermAggregate *callNode) const |
| 105 | { |
| 106 | ASSERT(callNode->getOp() == EOpFunctionCall || callNode->getOp() == EOpInternalFunctionCall); |
| 107 | return (mFunctionMap.find(callNode->getName()) != mFunctionMap.end()); |
| 108 | } |
| 109 | |
| 110 | TIntermSequence *TIntermTraverser::getFunctionParameters(const TIntermAggregate *callNode) |
| 111 | { |
| 112 | ASSERT(isInFunctionMap(callNode)); |
| 113 | return mFunctionMap[callNode->getName()]; |
| 114 | } |
| 115 | |
| 116 | void TIntermTraverser::setInFunctionCallOutParameter(bool inOutParameter) |
| 117 | { |
| 118 | mInFunctionCallOutParameter = inOutParameter; |
| 119 | } |
| 120 | |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 121 | bool TIntermTraverser::isInFunctionCallOutParameter() const |
| 122 | { |
| 123 | return mInFunctionCallOutParameter; |
| 124 | } |
| 125 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 126 | // |
| 127 | // Traverse the intermediate representation tree, and |
| 128 | // call a node type specific function for each node. |
| 129 | // Done recursively through the member function Traverse(). |
| 130 | // Node types can be skipped if their function to call is 0, |
| 131 | // but their subtree will still be traversed. |
| 132 | // Nodes with children can have their whole subtree skipped |
| 133 | // if preVisit is turned on and the type specific function |
| 134 | // returns false. |
| 135 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 136 | |
| 137 | // |
| 138 | // Traversal functions for terminals are straighforward.... |
| 139 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 140 | void TIntermSymbol::traverse(TIntermTraverser *it) |
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 | it->visitSymbol(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 145 | void TIntermConstantUnion::traverse(TIntermTraverser *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 | it->visitConstantUnion(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // |
| 151 | // Traverse a binary node. |
| 152 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 153 | void TIntermBinary::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 154 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 155 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 156 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 157 | // |
| 158 | // visit the node before children if pre-visiting. |
| 159 | // |
| 160 | if (it->preVisit) |
| 161 | visit = it->visitBinary(PreVisit, this); |
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 | // |
| 164 | // Visit the children, in the right order. |
| 165 | // |
| 166 | if (visit) |
| 167 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 168 | it->incrementDepth(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 169 | |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 170 | // Some binary operations like indexing can be inside an expression which must be an |
| 171 | // l-value. |
| 172 | bool parentOperatorRequiresLValue = it->operatorRequiresLValue(); |
| 173 | bool parentInFunctionCallOutParameter = it->isInFunctionCallOutParameter(); |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 174 | if (isAssignment()) |
| 175 | { |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 176 | ASSERT(!it->isLValueRequiredHere()); |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 177 | it->setOperatorRequiresLValue(true); |
| 178 | } |
| 179 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 180 | if (mLeft) |
| 181 | mLeft->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 182 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 183 | if (it->inVisit) |
| 184 | visit = it->visitBinary(InVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 185 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 186 | if (isAssignment()) |
| 187 | it->setOperatorRequiresLValue(false); |
| 188 | |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 189 | // Index is not required to be an l-value even when the surrounding expression is required |
| 190 | // to be an l-value. |
| 191 | if (mOp == EOpIndexDirect || mOp == EOpIndexDirectInterfaceBlock || |
| 192 | mOp == EOpIndexDirectStruct || mOp == EOpIndexIndirect) |
| 193 | { |
| 194 | it->setOperatorRequiresLValue(false); |
| 195 | it->setInFunctionCallOutParameter(false); |
| 196 | } |
| 197 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 198 | if (visit && mRight) |
| 199 | mRight->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 200 | |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 201 | it->setOperatorRequiresLValue(parentOperatorRequiresLValue); |
| 202 | it->setInFunctionCallOutParameter(parentInFunctionCallOutParameter); |
| 203 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 204 | it->decrementDepth(); |
| 205 | } |
| 206 | |
| 207 | // |
| 208 | // Visit the node after the children, if requested and the traversal |
| 209 | // hasn't been cancelled yet. |
| 210 | // |
| 211 | if (visit && it->postVisit) |
| 212 | it->visitBinary(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // |
| 216 | // Traverse a unary node. Same comments in binary node apply here. |
| 217 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 218 | void TIntermUnary::traverse(TIntermTraverser *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 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 221 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 222 | if (it->preVisit) |
| 223 | visit = it->visitUnary(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 224 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 225 | if (visit) |
| 226 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 227 | it->incrementDepth(this); |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 228 | |
Olli Etuaho | 8afe1e1 | 2015-08-05 18:00:01 +0300 | [diff] [blame] | 229 | ASSERT(!it->operatorRequiresLValue()); |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 230 | switch (getOp()) |
| 231 | { |
| 232 | case EOpPostIncrement: |
| 233 | case EOpPostDecrement: |
| 234 | case EOpPreIncrement: |
| 235 | case EOpPreDecrement: |
| 236 | it->setOperatorRequiresLValue(true); |
| 237 | break; |
| 238 | default: |
| 239 | break; |
| 240 | } |
| 241 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 242 | mOperand->traverse(it); |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 243 | |
| 244 | it->setOperatorRequiresLValue(false); |
| 245 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 246 | it->decrementDepth(); |
| 247 | } |
| 248 | |
| 249 | if (visit && it->postVisit) |
| 250 | it->visitUnary(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // |
| 254 | // Traverse an aggregate node. Same comments in binary node apply here. |
| 255 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 256 | void TIntermAggregate::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 257 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 258 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 259 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 260 | switch (mOp) |
| 261 | { |
| 262 | case EOpFunction: |
| 263 | { |
| 264 | TIntermAggregate *params = mSequence.front()->getAsAggregate(); |
| 265 | ASSERT(params != nullptr); |
| 266 | ASSERT(params->getOp() == EOpParameters); |
| 267 | it->addToFunctionMap(mName, params->getSequence()); |
| 268 | break; |
| 269 | } |
| 270 | case EOpPrototype: |
| 271 | it->addToFunctionMap(mName, &mSequence); |
| 272 | break; |
| 273 | default: |
| 274 | break; |
| 275 | } |
| 276 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 277 | if (it->preVisit) |
| 278 | visit = it->visitAggregate(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 279 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 280 | if (visit) |
| 281 | { |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 282 | bool inFunctionMap = false; |
| 283 | if (mOp == EOpFunctionCall) |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 284 | { |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 285 | inFunctionMap = it->isInFunctionMap(this); |
| 286 | if (!inFunctionMap) |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 287 | { |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 288 | // The function is not user-defined - it is likely built-in texture function. |
| 289 | // Assume that those do not have out parameters. |
| 290 | it->setInFunctionCallOutParameter(false); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 294 | it->incrementDepth(this); |
Olli Etuaho | 56eea88 | 2015-05-18 12:41:03 +0300 | [diff] [blame] | 295 | |
Olli Etuaho | a26ad58 | 2015-08-04 13:51:47 +0300 | [diff] [blame] | 296 | if (inFunctionMap) |
| 297 | { |
| 298 | TIntermSequence *params = it->getFunctionParameters(this); |
| 299 | TIntermSequence::iterator paramIter = params->begin(); |
| 300 | for (auto *child : mSequence) |
| 301 | { |
| 302 | ASSERT(paramIter != params->end()); |
| 303 | TQualifier qualifier = (*paramIter)->getAsTyped()->getQualifier(); |
| 304 | it->setInFunctionCallOutParameter(qualifier == EvqOut || qualifier == EvqInOut); |
| 305 | |
| 306 | child->traverse(it); |
| 307 | if (visit && it->inVisit) |
| 308 | { |
| 309 | if (child != mSequence.back()) |
| 310 | visit = it->visitAggregate(InVisit, this); |
| 311 | } |
| 312 | |
| 313 | ++paramIter; |
| 314 | } |
| 315 | |
| 316 | it->setInFunctionCallOutParameter(false); |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | if (mOp == EOpSequence) |
| 321 | it->pushParentBlock(this); |
| 322 | |
| 323 | for (auto *child : mSequence) |
| 324 | { |
| 325 | child->traverse(it); |
| 326 | if (visit && it->inVisit) |
| 327 | { |
| 328 | if (child != mSequence.back()) |
| 329 | visit = it->visitAggregate(InVisit, this); |
| 330 | } |
| 331 | |
| 332 | if (mOp == EOpSequence) |
| 333 | it->incrementParentBlockPos(); |
| 334 | } |
| 335 | |
| 336 | if (mOp == EOpSequence) |
| 337 | it->popParentBlock(); |
| 338 | } |
| 339 | |
| 340 | it->decrementDepth(); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | if (visit && it->postVisit) |
| 344 | it->visitAggregate(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | // |
| 348 | // Traverse a selection node. Same comments in binary node apply here. |
| 349 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 350 | void TIntermSelection::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 351 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 352 | bool visit = true; |
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 (it->preVisit) |
| 355 | visit = it->visitSelection(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 356 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 357 | if (visit) |
| 358 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 359 | it->incrementDepth(this); |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 360 | mCondition->traverse(it); |
| 361 | if (mTrueBlock) |
| 362 | mTrueBlock->traverse(it); |
| 363 | if (mFalseBlock) |
| 364 | mFalseBlock->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 365 | it->decrementDepth(); |
| 366 | } |
| 367 | |
| 368 | if (visit && it->postVisit) |
| 369 | it->visitSelection(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | // |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 373 | // Traverse a switch node. Same comments in binary node apply here. |
| 374 | // |
| 375 | void TIntermSwitch::traverse(TIntermTraverser *it) |
| 376 | { |
| 377 | bool visit = true; |
| 378 | |
| 379 | if (it->preVisit) |
| 380 | visit = it->visitSwitch(PreVisit, this); |
| 381 | |
| 382 | if (visit) |
| 383 | { |
| 384 | it->incrementDepth(this); |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 385 | mInit->traverse(it); |
| 386 | if (it->inVisit) |
| 387 | visit = it->visitSwitch(InVisit, this); |
| 388 | if (visit && mStatementList) |
| 389 | mStatementList->traverse(it); |
Olli Etuaho | a3a3666 | 2015-02-17 13:46:51 +0200 | [diff] [blame] | 390 | it->decrementDepth(); |
| 391 | } |
| 392 | |
| 393 | if (visit && it->postVisit) |
| 394 | it->visitSwitch(PostVisit, this); |
| 395 | } |
| 396 | |
| 397 | // |
| 398 | // Traverse a switch node. Same comments in binary node apply here. |
| 399 | // |
| 400 | void TIntermCase::traverse(TIntermTraverser *it) |
| 401 | { |
| 402 | bool visit = true; |
| 403 | |
| 404 | if (it->preVisit) |
| 405 | visit = it->visitCase(PreVisit, this); |
| 406 | |
| 407 | if (visit && mCondition) |
| 408 | mCondition->traverse(it); |
| 409 | |
| 410 | if (visit && it->postVisit) |
| 411 | it->visitCase(PostVisit, this); |
| 412 | } |
| 413 | |
| 414 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 415 | // Traverse a loop node. Same comments in binary node apply here. |
| 416 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 417 | void TIntermLoop::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 418 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 419 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 420 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 421 | if (it->preVisit) |
| 422 | visit = it->visitLoop(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 423 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 424 | if (visit) |
| 425 | { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 426 | it->incrementDepth(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 427 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 428 | if (mInit) |
| 429 | mInit->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 430 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 431 | if (mCond) |
| 432 | mCond->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 433 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 434 | if (mBody) |
| 435 | mBody->traverse(it); |
Zhenyao Mo | 6cb95f3 | 2013-10-03 17:01:52 -0700 | [diff] [blame] | 436 | |
Olli Etuaho | 64f0be9 | 2015-06-03 17:38:34 +0300 | [diff] [blame] | 437 | if (mExpr) |
| 438 | mExpr->traverse(it); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 439 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 440 | it->decrementDepth(); |
| 441 | } |
| 442 | |
| 443 | if (visit && it->postVisit) |
| 444 | it->visitLoop(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // |
| 448 | // Traverse a branch node. Same comments in binary node apply here. |
| 449 | // |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 450 | void TIntermBranch::traverse(TIntermTraverser *it) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 451 | { |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 452 | bool visit = true; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 453 | |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 454 | if (it->preVisit) |
| 455 | visit = it->visitBranch(PreVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 456 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 457 | if (visit && mExpression) { |
Zhenyao Mo | 7cab38b | 2013-10-15 12:59:30 -0700 | [diff] [blame] | 458 | it->incrementDepth(this); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 459 | mExpression->traverse(it); |
Zhenyao Mo | e88dcaf | 2013-10-03 16:55:19 -0700 | [diff] [blame] | 460 | it->decrementDepth(); |
| 461 | } |
| 462 | |
| 463 | if (visit && it->postVisit) |
| 464 | it->visitBranch(PostVisit, this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 467 | void TIntermRaw::traverse(TIntermTraverser *it) |
| 468 | { |
| 469 | it->visitRaw(this); |
| 470 | } |