summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/compiler/translator/RenameFunction.h
blob: fd6a365fea86c1cdee5b594da3d4483c0ab4fce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

#ifndef COMPILER_TRANSLATOR_RENAMEFUNCTION_H_
#define COMPILER_TRANSLATOR_RENAMEFUNCTION_H_

#include "compiler/translator/IntermNode.h"

//
// Renames a function, including its declaration and any calls to it.
//
class RenameFunction : public TIntermTraverser
{
public:
    RenameFunction(const TString& oldFunctionName, const TString& newFunctionName)
    : TIntermTraverser(true, false, false)
    , mOldFunctionName(oldFunctionName)
    , mNewFunctionName(newFunctionName) {}

    bool visitAggregate(Visit visit, TIntermAggregate *node) override
    {
        TOperator op = node->getOp();
        if ((op == EOpFunction || op == EOpFunctionCall) && node->getName() == mOldFunctionName)
            node->setName(mNewFunctionName);
        return true;
    }

private:
    const TString mOldFunctionName;
    const TString mNewFunctionName;
};

#endif  // COMPILER_TRANSLATOR_RENAMEFUNCTION_H_