--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 6.3\r
+ *\r
+ * Copyright (C) 2005 Brian Paul All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/**\r
+ * \file traverse_wrap.h\r
+ * Handy TIntermTraverser class wrapper\r
+ * \author Michal Krol\r
+ */\r
+\r
+#ifndef __TRAVERSE_WRAP_H__\r
+#define __TRAVERSE_WRAP_H__\r
+\r
+#include "Include/intermediate.h"\r
+\r
+/*\r
+ The original TIntermTraverser class that is used to walk the intermediate tree,\r
+ is not very elegant in its design. One must define static functions with\r
+ appropriate prototypes, construct TIntermTraverser object, and set its member\r
+ function pointers to one's static functions. If traversal-specific data\r
+ is needed, a new class must be derived, and one must up-cast the object\r
+ passed as a parameter to the static function.\r
+\r
+ The class below eliminates this burden by providing virtual methods that are\r
+ to be overridden in the derived class.\r
+*/\r
+\r
+class traverse_wrap: private TIntermTraverser\r
+{\r
+private:\r
+ static void _visitSymbol (TIntermSymbol *S, TIntermTraverser *T) {\r
+ static_cast<traverse_wrap *> (T)->Symbol (*S);\r
+ }\r
+ static void _visitConstantUnion (TIntermConstantUnion *U, TIntermTraverser *T) {\r
+ static_cast<traverse_wrap *> (T)->ConstantUnion (*U);\r
+ }\r
+ static bool _visitBinary (bool preVisit, TIntermBinary *B, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Binary (preVisit, *B);\r
+ }\r
+ static bool _visitUnary (bool preVisit, TIntermUnary *U, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Unary (preVisit, *U);\r
+ }\r
+ static bool _visitSelection (bool preVisit, TIntermSelection *S, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Selection (preVisit, *S);\r
+ }\r
+ static bool _visitAggregate (bool preVisit, TIntermAggregate *A, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Aggregate (preVisit, *A);\r
+ }\r
+ static bool _visitLoop (bool preVisit, TIntermLoop *L, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Loop (preVisit, *L);\r
+ }\r
+ static bool _visitBranch (bool preVisit, TIntermBranch *B, TIntermTraverser *T) {\r
+ return static_cast<traverse_wrap *> (T)->Branch (preVisit, *B);\r
+ }\r
+public:\r
+ traverse_wrap () {\r
+ visitSymbol = _visitSymbol;\r
+ visitConstantUnion = _visitConstantUnion;\r
+ visitBinary = _visitBinary;\r
+ visitUnary = _visitUnary;\r
+ visitSelection = _visitSelection;\r
+ visitAggregate = _visitAggregate;\r
+ visitLoop = _visitLoop;\r
+ visitBranch = _visitBranch;\r
+ }\r
+protected:\r
+ virtual void Symbol (const TIntermSymbol &) {\r
+ }\r
+ virtual void ConstantUnion (const TIntermConstantUnion &) {\r
+ }\r
+ virtual bool Binary (bool, const TIntermBinary &) {\r
+ return true;\r
+ }\r
+ virtual bool Unary (bool, const TIntermUnary &) {\r
+ return true;\r
+ }\r
+ virtual bool Selection (bool, const TIntermSelection &) {\r
+ return true;\r
+ }\r
+ virtual bool Aggregate (bool, const TIntermAggregate &) {\r
+ return true;\r
+ }\r
+ virtual bool Loop (bool, const TIntermLoop &) {\r
+ return true;\r
+ }\r
+ virtual bool Branch (bool, const TIntermBranch &) {\r
+ return true;\r
+ }\r
+};\r
+\r
+#endif\r
+\r