1// 2//Copyright (C) 2002-2005 3Dlabs Inc. Ltd. 3//Copyright (C) 2013 LunarG, Inc. 4// 5//All rights reserved. 6// 7//Redistribution and use in source and binary forms, with or without 8//modification, are permitted provided that the following conditions 9//are met: 10// 11// Redistributions of source code must retain the above copyright 12// notice, this list of conditions and the following disclaimer. 13// 14// Redistributions in binary form must reproduce the above 15// copyright notice, this list of conditions and the following 16// disclaimer in the documentation and/or other materials provided 17// with the distribution. 18// 19// Neither the name of 3Dlabs Inc. Ltd. nor the names of its 20// contributors may be used to endorse or promote products derived 21// from this software without specific prior written permission. 22// 23//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34//POSSIBILITY OF SUCH DAMAGE. 35// 36 37#include "../Include/intermediate.h" 38#include "RemoveTree.h" 39 40namespace glslang { 41 42// 43// Code to recursively delete the intermediate tree. 44// 45struct TRemoveTraverser : TIntermTraverser { 46 TRemoveTraverser() : TIntermTraverser(false, false, true, false) {} 47 48 virtual void visitSymbol(TIntermSymbol* node) 49 { 50 delete node; 51 } 52 53 virtual bool visitBinary(TVisit /* visit*/ , TIntermBinary* node) 54 { 55 delete node; 56 57 return true; 58 } 59 60 virtual bool visitUnary(TVisit /* visit */, TIntermUnary* node) 61 { 62 delete node; 63 64 return true; 65 } 66 67 virtual bool visitAggregate(TVisit /* visit*/ , TIntermAggregate* node) 68 { 69 delete node; 70 71 return true; 72 } 73 74 virtual bool visitSelection(TVisit /* visit*/ , TIntermSelection* node) 75 { 76 delete node; 77 78 return true; 79 } 80 81 virtual bool visitSwitch(TVisit /* visit*/ , TIntermSwitch* node) 82 { 83 delete node; 84 85 return true; 86 } 87 88 virtual void visitConstantUnion(TIntermConstantUnion* node) 89 { 90 delete node; 91 } 92 93 virtual bool visitLoop(TVisit /* visit*/ , TIntermLoop* node) 94 { 95 delete node; 96 97 return true; 98 } 99 100 virtual bool visitBranch(TVisit /* visit*/ , TIntermBranch* node) 101 { 102 delete node; 103 104 return true; 105 } 106}; 107 108// 109// Entry point. 110// 111void RemoveAllTreeNodes(TIntermNode* root) 112{ 113 TRemoveTraverser it; 114 115 root->traverse(&it); 116} 117 118} // end namespace glslang 119