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