Olli Etuaho | 95ed194 | 2018-02-01 14:01:19 +0200 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 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 | // FunctionLookup.cpp: Used for storing function calls that have not yet been resolved during |
| 7 | // parsing. |
| 8 | // |
| 9 | |
| 10 | #include "compiler/translator/FunctionLookup.h" |
| 11 | |
| 12 | namespace sh |
| 13 | { |
| 14 | |
| 15 | namespace |
| 16 | { |
| 17 | |
| 18 | const char kFunctionMangledNameSeparator = '('; |
| 19 | |
| 20 | } // anonymous namespace |
| 21 | |
| 22 | TFunctionLookup::TFunctionLookup(const TString *name, const TType *constructorType) |
| 23 | : mName(name), mConstructorType(constructorType), mThisNode(nullptr) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | // static |
| 28 | TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type) |
| 29 | { |
| 30 | ASSERT(type != nullptr); |
| 31 | return new TFunctionLookup(nullptr, type); |
| 32 | } |
| 33 | |
| 34 | // static |
| 35 | TFunctionLookup *TFunctionLookup::CreateFunctionCall(const TString *name) |
| 36 | { |
| 37 | ASSERT(name != nullptr); |
| 38 | return new TFunctionLookup(name, nullptr); |
| 39 | } |
| 40 | |
| 41 | const TString &TFunctionLookup::name() const |
| 42 | { |
| 43 | return *mName; |
| 44 | } |
| 45 | |
| 46 | const TString &TFunctionLookup::getMangledName() const |
| 47 | { |
| 48 | return GetMangledName(*mName, mArguments); |
| 49 | } |
| 50 | |
| 51 | const TString &TFunctionLookup::GetMangledName(const TString &functionName, |
| 52 | const TIntermSequence &arguments) |
| 53 | { |
| 54 | std::string newName = functionName.c_str(); |
| 55 | newName += kFunctionMangledNameSeparator; |
| 56 | |
| 57 | for (TIntermNode *argument : arguments) |
| 58 | { |
| 59 | newName += argument->getAsTyped()->getType().getMangledName(); |
| 60 | } |
| 61 | return *NewPoolTString(newName.c_str()); |
| 62 | } |
| 63 | |
| 64 | bool TFunctionLookup::isConstructor() const |
| 65 | { |
| 66 | return mConstructorType != nullptr; |
| 67 | } |
| 68 | |
| 69 | const TType &TFunctionLookup::constructorType() const |
| 70 | { |
| 71 | return *mConstructorType; |
| 72 | } |
| 73 | |
| 74 | void TFunctionLookup::setThisNode(TIntermTyped *thisNode) |
| 75 | { |
| 76 | mThisNode = thisNode; |
| 77 | } |
| 78 | |
| 79 | TIntermTyped *TFunctionLookup::thisNode() const |
| 80 | { |
| 81 | return mThisNode; |
| 82 | } |
| 83 | |
| 84 | void TFunctionLookup::addArgument(TIntermTyped *argument) |
| 85 | { |
| 86 | mArguments.push_back(argument); |
| 87 | } |
| 88 | |
| 89 | TIntermSequence &TFunctionLookup::arguments() |
| 90 | { |
| 91 | return mArguments; |
| 92 | } |
| 93 | |
| 94 | } // namespace sh |