| 1 |
/* |
| 2 |
* Mesa 3-D graphics library |
| 3 |
* Version: 6.3 |
| 4 |
* |
| 5 |
* Copyright (C) 2005 Brian Paul All Rights Reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
* copy of this software and associated documentation files (the "Software"), |
| 9 |
* to deal in the Software without restriction, including without limitation |
| 10 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
* Software is furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included |
| 15 |
* in all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
/** |
| 26 |
* \file traverse_wrap.h |
| 27 |
* Handy TIntermTraverser class wrapper |
| 28 |
* \author Michal Krol |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifndef __TRAVERSE_WRAP_H__ |
| 32 |
#define __TRAVERSE_WRAP_H__ |
| 33 |
|
| 34 |
#include "Include/intermediate.h" |
| 35 |
|
| 36 |
/* |
| 37 |
The original TIntermTraverser class that is used to walk the intermediate tree, |
| 38 |
is not very elegant in its design. One must define static functions with |
| 39 |
appropriate prototypes, construct TIntermTraverser object, and set its member |
| 40 |
function pointers to one's static functions. If traversal-specific data |
| 41 |
is needed, a new class must be derived, and one must up-cast the object |
| 42 |
passed as a parameter to the static function. |
| 43 |
|
| 44 |
The class below eliminates this burden by providing virtual methods that are |
| 45 |
to be overridden in the derived class. |
| 46 |
*/ |
| 47 |
|
| 48 |
class traverse_wrap: private TIntermTraverser |
| 49 |
{ |
| 50 |
private: |
| 51 |
static void _visitSymbol (TIntermSymbol *S, TIntermTraverser *T) { |
| 52 |
static_cast<traverse_wrap *> (T)->Symbol (*S); |
| 53 |
} |
| 54 |
static void _visitConstantUnion (TIntermConstantUnion *U, TIntermTraverser *T) { |
| 55 |
static_cast<traverse_wrap *> (T)->ConstantUnion (*U); |
| 56 |
} |
| 57 |
static bool _visitBinary (bool preVisit, TIntermBinary *B, TIntermTraverser *T) { |
| 58 |
return static_cast<traverse_wrap *> (T)->Binary (preVisit, *B); |
| 59 |
} |
| 60 |
static bool _visitUnary (bool preVisit, TIntermUnary *U, TIntermTraverser *T) { |
| 61 |
return static_cast<traverse_wrap *> (T)->Unary (preVisit, *U); |
| 62 |
} |
| 63 |
static bool _visitSelection (bool preVisit, TIntermSelection *S, TIntermTraverser *T) { |
| 64 |
return static_cast<traverse_wrap *> (T)->Selection (preVisit, *S); |
| 65 |
} |
| 66 |
static bool _visitAggregate (bool preVisit, TIntermAggregate *A, TIntermTraverser *T) { |
| 67 |
return static_cast<traverse_wrap *> (T)->Aggregate (preVisit, *A); |
| 68 |
} |
| 69 |
static bool _visitLoop (bool preVisit, TIntermLoop *L, TIntermTraverser *T) { |
| 70 |
return static_cast<traverse_wrap *> (T)->Loop (preVisit, *L); |
| 71 |
} |
| 72 |
static bool _visitBranch (bool preVisit, TIntermBranch *B, TIntermTraverser *T) { |
| 73 |
return static_cast<traverse_wrap *> (T)->Branch (preVisit, *B); |
| 74 |
} |
| 75 |
public: |
| 76 |
traverse_wrap () { |
| 77 |
visitSymbol = _visitSymbol; |
| 78 |
visitConstantUnion = _visitConstantUnion; |
| 79 |
visitBinary = _visitBinary; |
| 80 |
visitUnary = _visitUnary; |
| 81 |
visitSelection = _visitSelection; |
| 82 |
visitAggregate = _visitAggregate; |
| 83 |
visitLoop = _visitLoop; |
| 84 |
visitBranch = _visitBranch; |
| 85 |
} |
| 86 |
protected: |
| 87 |
virtual void Symbol (const TIntermSymbol &) { |
| 88 |
} |
| 89 |
virtual void ConstantUnion (const TIntermConstantUnion &) { |
| 90 |
} |
| 91 |
virtual bool Binary (bool, const TIntermBinary &) { |
| 92 |
return true; |
| 93 |
} |
| 94 |
virtual bool Unary (bool, const TIntermUnary &) { |
| 95 |
return true; |
| 96 |
} |
| 97 |
virtual bool Selection (bool, const TIntermSelection &) { |
| 98 |
return true; |
| 99 |
} |
| 100 |
virtual bool Aggregate (bool, const TIntermAggregate &) { |
| 101 |
return true; |
| 102 |
} |
| 103 |
virtual bool Loop (bool, const TIntermLoop &) { |
| 104 |
return true; |
| 105 |
} |
| 106 |
virtual bool Branch (bool, const TIntermBranch &) { |
| 107 |
return true; |
| 108 |
} |
| 109 |
}; |
| 110 |
|
| 111 |
#endif |
| 112 |
|