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/angleutils.h" 13 14 namespace sh 15 { 16 17 class TCompiler; 18 class TIntermBlock; 19 class TIntermTyped; 20 class TSymbolTable; 21 class TVariable; 22 23 ANGLE_NO_DISCARD bool ReplaceVariable(TCompiler *compiler, 24 TIntermBlock *root, 25 const TVariable *toBeReplaced, 26 const TVariable *replacement); 27 ANGLE_NO_DISCARD bool ReplaceVariableWithTyped(TCompiler *compiler, 28 TIntermBlock *root, 29 const TVariable *toBeReplaced, 30 const TIntermTyped *replacement); 31 32 using VariableReplacementMap = angle::HashMap<const TVariable *, const TIntermTyped *>; 33 34 // Replace a set of variables with their corresponding expression. 35 ANGLE_NO_DISCARD bool ReplaceVariables(TCompiler *compiler, 36 TIntermBlock *root, 37 const VariableReplacementMap &variableMap); 38 39 // Find all declarators, and replace the TVariable they are declaring with a duplicate. This is 40 // used to support deepCopy of TIntermBlock and TIntermLoop nodes that include declarations. 41 // Replacements already present in variableMap are preserved. 42 void GetDeclaratorReplacements(TSymbolTable *symbolTable, 43 TIntermBlock *root, 44 VariableReplacementMap *variableMap); 45 46 } // namespace sh 47 48 #endif // COMPILER_TRANSLATOR_TREEUTIL_REPLACEVARIABLE_H_ 49