1//
2// Copyright (c) 2012 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
7#ifndef COMPILER_RENAME_FUNCTION
8#define COMPILER_RENAME_FUNCTION
9
10#include "compiler/translator/IntermNode.h"
11
12//
13// Renames a function, including its declaration and any calls to it.
14//
15class RenameFunction : public TIntermTraverser
16{
17public:
18    RenameFunction(const TString& oldFunctionName, const TString& newFunctionName)
19    : TIntermTraverser(true, false, false)
20    , mOldFunctionName(oldFunctionName)
21    , mNewFunctionName(newFunctionName) {}
22
23    virtual bool visitAggregate(Visit visit, TIntermAggregate* node)
24    {
25        TOperator op = node->getOp();
26        if ((op == EOpFunction || op == EOpFunctionCall) && node->getName() == mOldFunctionName)
27            node->setName(mNewFunctionName);
28        return true;
29    }
30
31private:
32    const TString mOldFunctionName;
33    const TString mNewFunctionName;
34};
35
36#endif  // COMPILER_RENAME_FUNCTION
37