blob: c83fc48a1fe001d24a3c558fce8de2a1bed46e05 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
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
7//
8// Definition of the in-memory high-level intermediate representation
9// of shaders. This is a tree that parser creates.
10//
11// Nodes in the tree are defined as a hierarchy of classes derived from
12// TIntermNode. Each is a node in a tree. There is no preset branching factor;
13// each node can have it's own type of list of children.
14//
15
16#ifndef __INTERMEDIATE_H
17#define __INTERMEDIATE_H
18
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "compiler/Common.h"
20#include "compiler/Types.h"
21#include "compiler/ConstantUnion.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
23//
24// Operators used by the high-level (parse tree) representation.
25//
26enum TOperator {
alokp@chromium.org2cf17712010-03-30 20:33:18 +000027 EOpNull, // if in a node, should only mean a node is still being built
28 EOpSequence, // denotes a list of statements, or parameters, etc.
29 EOpFunctionCall,
30 EOpFunction, // For function definition
31 EOpParameters, // an aggregate listing the parameters to a function
daniel@transgaming.comd1acd1e2010-04-13 03:25:57 +000032
alokp@chromium.org2cf17712010-03-30 20:33:18 +000033 EOpDeclaration,
daniel@transgaming.comd1acd1e2010-04-13 03:25:57 +000034 EOpPrototype,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035
alokp@chromium.org2cf17712010-03-30 20:33:18 +000036 //
37 // Unary operators
38 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039
alokp@chromium.org2cf17712010-03-30 20:33:18 +000040 EOpNegative,
41 EOpLogicalNot,
42 EOpVectorLogicalNot,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000043
alokp@chromium.org2cf17712010-03-30 20:33:18 +000044 EOpPostIncrement,
45 EOpPostDecrement,
46 EOpPreIncrement,
47 EOpPreDecrement,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000048
alokp@chromium.org2cf17712010-03-30 20:33:18 +000049 EOpConvIntToBool,
50 EOpConvFloatToBool,
51 EOpConvBoolToFloat,
52 EOpConvIntToFloat,
53 EOpConvFloatToInt,
54 EOpConvBoolToInt,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000055
alokp@chromium.org2cf17712010-03-30 20:33:18 +000056 //
57 // binary operations
58 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000059
alokp@chromium.org2cf17712010-03-30 20:33:18 +000060 EOpAdd,
61 EOpSub,
62 EOpMul,
63 EOpDiv,
64 EOpEqual,
65 EOpNotEqual,
66 EOpVectorEqual,
67 EOpVectorNotEqual,
68 EOpLessThan,
69 EOpGreaterThan,
70 EOpLessThanEqual,
71 EOpGreaterThanEqual,
72 EOpComma,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073
alokp@chromium.org2cf17712010-03-30 20:33:18 +000074 EOpVectorTimesScalar,
75 EOpVectorTimesMatrix,
76 EOpMatrixTimesVector,
77 EOpMatrixTimesScalar,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078
alokp@chromium.org2cf17712010-03-30 20:33:18 +000079 EOpLogicalOr,
80 EOpLogicalXor,
81 EOpLogicalAnd,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082
alokp@chromium.org2cf17712010-03-30 20:33:18 +000083 EOpIndexDirect,
84 EOpIndexIndirect,
85 EOpIndexDirectStruct,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000086
alokp@chromium.org2cf17712010-03-30 20:33:18 +000087 EOpVectorSwizzle,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000088
alokp@chromium.org2cf17712010-03-30 20:33:18 +000089 //
90 // Built-in functions potentially mapped to operators
91 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092
alokp@chromium.org2cf17712010-03-30 20:33:18 +000093 EOpRadians,
94 EOpDegrees,
95 EOpSin,
96 EOpCos,
97 EOpTan,
98 EOpAsin,
99 EOpAcos,
100 EOpAtan,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000101
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000102 EOpPow,
103 EOpExp,
104 EOpLog,
105 EOpExp2,
106 EOpLog2,
107 EOpSqrt,
108 EOpInverseSqrt,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000110 EOpAbs,
111 EOpSign,
112 EOpFloor,
113 EOpCeil,
114 EOpFract,
115 EOpMod,
116 EOpMin,
117 EOpMax,
118 EOpClamp,
119 EOpMix,
120 EOpStep,
121 EOpSmoothStep,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000122
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000123 EOpLength,
124 EOpDistance,
125 EOpDot,
126 EOpCross,
127 EOpNormalize,
128 EOpFaceForward,
129 EOpReflect,
130 EOpRefract,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000131
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000132 //EOpDPdx, // Fragment only, OES_standard_derivatives extension
133 //EOpDPdy, // Fragment only, OES_standard_derivatives extension
134 //EOpFwidth, // Fragment only, OES_standard_derivatives extension
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000136 EOpMatrixTimesMatrix,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000137
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000138 EOpAny,
139 EOpAll,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000141 //
142 // Branch
143 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000144
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000145 EOpKill, // Fragment only
146 EOpReturn,
147 EOpBreak,
148 EOpContinue,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000149
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000150 //
151 // Constructors
152 //
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000154 EOpConstructInt,
155 EOpConstructBool,
156 EOpConstructFloat,
157 EOpConstructVec2,
158 EOpConstructVec3,
159 EOpConstructVec4,
160 EOpConstructBVec2,
161 EOpConstructBVec3,
162 EOpConstructBVec4,
163 EOpConstructIVec2,
164 EOpConstructIVec3,
165 EOpConstructIVec4,
166 EOpConstructMat2,
167 EOpConstructMat3,
168 EOpConstructMat4,
169 EOpConstructStruct,
170
171 //
172 // moves
173 //
174
175 EOpAssign,
176 EOpInitialize,
177 EOpAddAssign,
178 EOpSubAssign,
179 EOpMulAssign,
180 EOpVectorTimesMatrixAssign,
181 EOpVectorTimesScalarAssign,
182 EOpMatrixTimesScalarAssign,
183 EOpMatrixTimesMatrixAssign,
184 EOpDivAssign,
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000185};
186
187class TIntermTraverser;
188class TIntermAggregate;
189class TIntermBinary;
daniel@transgaming.com4a35ef22010-04-08 03:51:06 +0000190class TIntermUnary;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000191class TIntermConstantUnion;
192class TIntermSelection;
193class TIntermTyped;
194class TIntermSymbol;
alokp@chromium.orgd88b7732010-05-26 15:13:14 +0000195class TIntermLoop;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000196class TInfoSink;
197
198//
199// Base class for the tree nodes
200//
201class TIntermNode {
202public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000203 POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000204
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000205 TIntermNode() : line(0) {}
206 virtual TSourceLoc getLine() const { return line; }
207 virtual void setLine(TSourceLoc l) { line = l; }
208 virtual void traverse(TIntermTraverser*) = 0;
alokp@chromium.orgd88b7732010-05-26 15:13:14 +0000209 virtual TIntermTyped* getAsTyped() { return 0; }
210 virtual TIntermConstantUnion* getAsConstantUnion() { return 0; }
211 virtual TIntermAggregate* getAsAggregate() { return 0; }
212 virtual TIntermBinary* getAsBinaryNode() { return 0; }
213 virtual TIntermUnary* getAsUnaryNode() { return 0; }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000214 virtual TIntermSelection* getAsSelectionNode() { return 0; }
alokp@chromium.orgd88b7732010-05-26 15:13:14 +0000215 virtual TIntermSymbol* getAsSymbolNode() { return 0; }
216 virtual TIntermLoop* getAsLoopNode() { return 0; }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000217 virtual ~TIntermNode() { }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000218protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000219 TSourceLoc line;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000220};
221
222//
223// This is just to help yacc.
224//
225struct TIntermNodePair {
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000226 TIntermNode* node1;
227 TIntermNode* node2;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000228};
229
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000230//
231// Intermediate class for nodes that have a type.
232//
233class TIntermTyped : public TIntermNode {
234public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000235 TIntermTyped(const TType& t) : type(t) { }
236 virtual TIntermTyped* getAsTyped() { return this; }
237 virtual void setType(const TType& t) { type = t; }
238 virtual const TType& getType() const { return type; }
239 virtual TType* getTypePointer() { return &type; }
alokp@chromium.orgdd037b22010-03-30 18:47:20 +0000240
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000241 virtual TBasicType getBasicType() const { return type.getBasicType(); }
242 virtual TQualifier getQualifier() const { return type.getQualifier(); }
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000243 virtual TPrecision getPrecision() const { return type.getPrecision(); }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000244 virtual int getNominalSize() const { return type.getNominalSize(); }
245 virtual int getSize() const { return type.getInstanceSize(); }
246 virtual bool isMatrix() const { return type.isMatrix(); }
247 virtual bool isArray() const { return type.isArray(); }
248 virtual bool isVector() const { return type.isVector(); }
daniel@transgaming.comd91cfe72010-04-13 03:26:17 +0000249 virtual bool isScalar() const { return type.isScalar(); }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000250 const char* getBasicString() const { return type.getBasicString(); }
251 const char* getQualifierString() const { return type.getQualifierString(); }
252 TString getCompleteString() const { return type.getCompleteString(); }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
254protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000255 TType type;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000256};
257
258//
259// Handle for, do-while, and while loops.
260//
261class TIntermLoop : public TIntermNode {
262public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000263 TIntermLoop(TIntermNode *init, TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) :
264 init(init),
265 body(aBody),
266 test(aTest),
267 terminal(aTerminal),
268 first(testFirst) { }
alokp@chromium.orgd88b7732010-05-26 15:13:14 +0000269 virtual TIntermLoop* getAsLoopNode() { return this; }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000270 virtual void traverse(TIntermTraverser*);
271 TIntermNode *getInit() { return init; }
272 TIntermNode *getBody() { return body; }
273 TIntermTyped *getTest() { return test; }
274 TIntermTyped *getTerminal() { return terminal; }
275 bool testFirst() { return first; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000277 TIntermNode *init;
278 TIntermNode *body; // code to loop over
279 TIntermTyped *test; // exit condition associated with loop, could be 0 for 'for' loops
280 TIntermTyped *terminal; // exists for for-loops
281 bool first; // true for while and for, not for do-while
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000282};
283
284//
285// Handle break, continue, return, and kill.
286//
287class TIntermBranch : public TIntermNode {
288public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000289 TIntermBranch(TOperator op, TIntermTyped* e) :
290 flowOp(op),
291 expression(e) { }
292 virtual void traverse(TIntermTraverser*);
293 TOperator getFlowOp() { return flowOp; }
294 TIntermTyped* getExpression() { return expression; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000296 TOperator flowOp;
297 TIntermTyped* expression; // non-zero except for "return exp;" statements
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298};
299
300//
301// Nodes that correspond to symbols or constants in the source code.
302//
303class TIntermSymbol : public TIntermTyped {
304public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000305 // if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from
306 // per process globalpoolallocator, then it causes increased memory usage per compile
307 // it is essential to use "symbol = sym" to assign to symbol
308 TIntermSymbol(int i, const TString& sym, const TType& t) :
309 TIntermTyped(t), id(i) { symbol = sym;}
310 virtual int getId() const { return id; }
311 virtual const TString& getSymbol() const { return symbol; }
312 virtual void traverse(TIntermTraverser*);
313 virtual TIntermSymbol* getAsSymbolNode() { return this; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000314protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000315 int id;
316 TString symbol;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000317};
318
319class TIntermConstantUnion : public TIntermTyped {
320public:
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +0000321 TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }
322 ConstantUnion* getUnionArrayPointer() const { return unionArrayPointer; }
323 void setUnionArrayPointer(ConstantUnion *c) { unionArrayPointer = c; }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000324 virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
325 virtual void traverse(TIntermTraverser* );
326 virtual TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000327protected:
alokp@chromium.org6ff56fd2010-05-05 16:37:50 +0000328 ConstantUnion *unionArrayPointer;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000329};
330
331//
332// Intermediate class for node types that hold operators.
333//
334class TIntermOperator : public TIntermTyped {
335public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000336 TOperator getOp() const { return op; }
337 bool modifiesState() const;
338 bool isConstructor() const;
339 virtual bool promote(TInfoSink&) { return true; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000340protected:
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000341 TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat, EbpUndefined)), op(o) {}
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000342 TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {}
343 TOperator op;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344};
345
346//
347// Nodes for all the basic binary math operators.
348//
349class TIntermBinary : public TIntermOperator {
350public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000351 TIntermBinary(TOperator o) : TIntermOperator(o) {}
352 virtual void traverse(TIntermTraverser*);
353 virtual void setLeft(TIntermTyped* n) { left = n; }
354 virtual void setRight(TIntermTyped* n) { right = n; }
355 virtual TIntermTyped* getLeft() const { return left; }
356 virtual TIntermTyped* getRight() const { return right; }
357 virtual TIntermBinary* getAsBinaryNode() { return this; }
358 virtual bool promote(TInfoSink&);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000359protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000360 TIntermTyped* left;
361 TIntermTyped* right;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000362};
363
364//
365// Nodes for unary math operators.
366//
367class TIntermUnary : public TIntermOperator {
368public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000369 TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {}
370 TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {}
371 virtual void traverse(TIntermTraverser*);
372 virtual void setOperand(TIntermTyped* o) { operand = o; }
373 virtual TIntermTyped* getOperand() { return operand; }
daniel@transgaming.com4a35ef22010-04-08 03:51:06 +0000374 virtual TIntermUnary* getAsUnaryNode() { return this; }
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000375 virtual bool promote(TInfoSink&);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000376protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000377 TIntermTyped* operand;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000378};
379
380typedef TVector<TIntermNode*> TIntermSequence;
381typedef TVector<int> TQualifierList;
382//
383// Nodes that operate on an arbitrary sized set of children.
384//
385class TIntermAggregate : public TIntermOperator {
386public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000387 TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { }
388 TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { }
389 ~TIntermAggregate() { delete pragmaTable; }
390 virtual TIntermAggregate* getAsAggregate() { return this; }
391 virtual void setOperator(TOperator o) { op = o; }
392 virtual TIntermSequence& getSequence() { return sequence; }
393 virtual void setName(const TString& n) { name = n; }
394 virtual const TString& getName() const { return name; }
395 virtual void traverse(TIntermTraverser*);
396 virtual void setUserDefined() { userDefined = true; }
397 virtual bool isUserDefined() { return userDefined; }
398 virtual TQualifierList& getQualifier() { return qualifier; }
399 void setOptimize(bool o) { optimize = o; }
400 void setDebug(bool d) { debug = d; }
401 bool getOptimize() { return optimize; }
402 bool getDebug() { return debug; }
403 void addToPragmaTable(const TPragmaTable& pTable);
404 const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000405protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000406 TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
407 TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
408 TIntermSequence sequence;
409 TQualifierList qualifier;
410 TString name;
411 bool userDefined; // used for user defined function names
412 bool optimize;
413 bool debug;
414 TPragmaTable *pragmaTable;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000415};
416
417//
418// For if tests. Simplified since there is no switch statement.
419//
420class TIntermSelection : public TIntermTyped {
421public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000422 TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000423 TIntermTyped(TType(EbtVoid, EbpUndefined)), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000424 TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
425 TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
426 virtual void traverse(TIntermTraverser*);
427 bool usesTernaryOperator() const { return getBasicType() != EbtVoid; }
428 virtual TIntermNode* getCondition() const { return condition; }
429 virtual TIntermNode* getTrueBlock() const { return trueBlock; }
430 virtual TIntermNode* getFalseBlock() const { return falseBlock; }
431 virtual TIntermSelection* getAsSelectionNode() { return this; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000432protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000433 TIntermTyped* condition;
434 TIntermNode* trueBlock;
435 TIntermNode* falseBlock;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000436};
437
438enum Visit
439{
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000440 PreVisit,
441 InVisit,
442 PostVisit
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000443};
444
445//
446// For traversing the tree. User should derive from this,
447// put their traversal specific data in it, and then pass
448// it to a Traverse method.
449//
450// When using this, just fill in the methods for nodes you want visited.
451// Return false from a pre-visit to skip visiting that node's subtree.
452//
453class TIntermTraverser
454{
455public:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000456 POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000457
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000458 TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) :
459 preVisit(preVisit),
460 inVisit(inVisit),
461 postVisit(postVisit),
462 rightToLeft(rightToLeft),
463 depth(0) {}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000464
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000465 virtual void visitSymbol(TIntermSymbol*) {}
466 virtual void visitConstantUnion(TIntermConstantUnion*) {}
467 virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;}
468 virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;}
469 virtual bool visitSelection(Visit visit, TIntermSelection*) {return true;}
470 virtual bool visitAggregate(Visit visit, TIntermAggregate*) {return true;}
471 virtual bool visitLoop(Visit visit, TIntermLoop*) {return true;}
472 virtual bool visitBranch(Visit visit, TIntermBranch*) {return true;}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000473
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000474 void incrementDepth() {depth++;}
475 void decrementDepth() {depth--;}
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000476
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000477 const bool preVisit;
478 const bool inVisit;
479 const bool postVisit;
480 const bool rightToLeft;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000481
482protected:
alokp@chromium.org2cf17712010-03-30 20:33:18 +0000483 int depth;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000484};
485
486#endif // __INTERMEDIATE_H