michael@0: // michael@0: // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "compiler/intermediate.h" michael@0: michael@0: class TAliveTraverser : public TIntermTraverser { michael@0: public: michael@0: TAliveTraverser(TQualifier q) : TIntermTraverser(true, false, false, true), found(false), qualifier(q) michael@0: { michael@0: } michael@0: michael@0: bool wasFound() { return found; } michael@0: michael@0: protected: michael@0: bool found; michael@0: TQualifier qualifier; michael@0: michael@0: void visitSymbol(TIntermSymbol*); michael@0: bool visitSelection(Visit, TIntermSelection*); michael@0: }; michael@0: michael@0: // michael@0: // Report whether or not a variable of the given qualifier type michael@0: // is guaranteed written. Not always possible to determine if michael@0: // it is written conditionally. michael@0: // michael@0: // ?? It does not do this well yet, this is just a place holder michael@0: // that simply determines if it was reference at all, anywhere. michael@0: // michael@0: bool QualifierWritten(TIntermNode* node, TQualifier qualifier) michael@0: { michael@0: TAliveTraverser it(qualifier); michael@0: michael@0: if (node) michael@0: node->traverse(&it); michael@0: michael@0: return it.wasFound(); michael@0: } michael@0: michael@0: void TAliveTraverser::visitSymbol(TIntermSymbol* node) michael@0: { michael@0: // michael@0: // If it's what we're looking for, record it. michael@0: // michael@0: if (node->getQualifier() == qualifier) michael@0: found = true; michael@0: } michael@0: michael@0: bool TAliveTraverser::visitSelection(Visit preVisit, TIntermSelection* node) michael@0: { michael@0: if (wasFound()) michael@0: return false; michael@0: michael@0: return true; michael@0: }