1 // 2 // Copyright 2018 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 // ReplaceVariable.h: Replace all references to a specific variable in the AST with references to 7 // another variable. 8 9 #ifndef COMPILER_TRANSLATOR_TREEUTIL_REPLACEVARIABLE_H_ 10 #define COMPILER_TRANSLATOR_TREEUTIL_REPLACEVARIABLE_H_ 11 12 #include "common/debug.h" 13 14 #include <stack> 15 #include <unordered_map> 16 17 namespace sh 18 { 19 20 class TCompiler; 21 class TFunction; 22 class TIntermAggregate; 23 class TIntermBlock; 24 class TIntermFunctionPrototype; 25 class TIntermNode; 26 class TIntermTyped; 27 class TSymbolTable; 28 class TVariable; 29 30 ANGLE_NO_DISCARD bool ReplaceVariable(TCompiler *compiler, 31 TIntermBlock *root, 32 const TVariable *toBeReplaced, 33 const TVariable *replacement); 34 ANGLE_NO_DISCARD bool ReplaceVariableWithTyped(TCompiler *compiler, 35 TIntermBlock *root, 36 const TVariable *toBeReplaced, 37 const TIntermTyped *replacement); 38 39 using VariableReplacementMap = angle::HashMap<const TVariable *, const TIntermTyped *>; 40 41 // Replace a set of variables with their corresponding expression. 42 ANGLE_NO_DISCARD bool ReplaceVariables(TCompiler *compiler, 43 TIntermBlock *root, 44 const VariableReplacementMap &variableMap); 45 46 // Find all declarators, and replace the TVariable they are declaring with a duplicate. This is 47 // used to support deepCopy of TIntermBlock and TIntermLoop nodes that include declarations. 48 // Replacements already present in variableMap are preserved. 49 void GetDeclaratorReplacements(TSymbolTable *symbolTable, 50 TIntermBlock *root, 51 VariableReplacementMap *variableMap); 52 53 } // namespace sh 54 55 #endif // COMPILER_TRANSLATOR_TREEUTIL_REPLACEVARIABLE_H_ 56