| 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 | constexpr const ImmutableString kEmptyName("" ); |
| 21 | |
| 22 | } // anonymous namespace |
| 23 | |
| 24 | TFunctionLookup::TFunctionLookup(const ImmutableString &name, |
| 25 | const TType *constructorType, |
| 26 | const TSymbol *symbol) |
| 27 | : mName(name), mConstructorType(constructorType), mThisNode(nullptr), mSymbol(symbol) |
| 28 | {} |
| 29 | |
| 30 | // static |
| 31 | TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type) |
| 32 | { |
| 33 | ASSERT(type != nullptr); |
| 34 | return new TFunctionLookup(kEmptyName, type, nullptr); |
| 35 | } |
| 36 | |
| 37 | // static |
| 38 | TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name, |
| 39 | const TSymbol *symbol) |
| 40 | { |
| 41 | ASSERT(name != "" ); |
| 42 | return new TFunctionLookup(name, nullptr, symbol); |
| 43 | } |
| 44 | |
| 45 | const ImmutableString &TFunctionLookup::name() const |
| 46 | { |
| 47 | return mName; |
| 48 | } |
| 49 | |
| 50 | ImmutableString TFunctionLookup::getMangledName() const |
| 51 | { |
| 52 | return GetMangledName(mName.data(), mArguments); |
| 53 | } |
| 54 | |
| 55 | ImmutableString TFunctionLookup::GetMangledName(const char *functionName, |
| 56 | const TIntermSequence &arguments) |
| 57 | { |
| 58 | std::string newName(functionName); |
| 59 | newName += kFunctionMangledNameSeparator; |
| 60 | |
| 61 | for (TIntermNode *argument : arguments) |
| 62 | { |
| 63 | newName += argument->getAsTyped()->getType().getMangledName(); |
| 64 | } |
| 65 | return ImmutableString(newName); |
| 66 | } |
| 67 | |
| 68 | bool TFunctionLookup::isConstructor() const |
| 69 | { |
| 70 | return mConstructorType != nullptr; |
| 71 | } |
| 72 | |
| 73 | const TType &TFunctionLookup::constructorType() const |
| 74 | { |
| 75 | return *mConstructorType; |
| 76 | } |
| 77 | |
| 78 | void TFunctionLookup::setThisNode(TIntermTyped *thisNode) |
| 79 | { |
| 80 | mThisNode = thisNode; |
| 81 | } |
| 82 | |
| 83 | TIntermTyped *TFunctionLookup::thisNode() const |
| 84 | { |
| 85 | return mThisNode; |
| 86 | } |
| 87 | |
| 88 | void TFunctionLookup::addArgument(TIntermTyped *argument) |
| 89 | { |
| 90 | mArguments.push_back(argument); |
| 91 | } |
| 92 | |
| 93 | TIntermSequence &TFunctionLookup::arguments() |
| 94 | { |
| 95 | return mArguments; |
| 96 | } |
| 97 | |
| 98 | const TSymbol *TFunctionLookup::symbol() const |
| 99 | { |
| 100 | return mSymbol; |
| 101 | } |
| 102 | |
| 103 | } // namespace sh |
| 104 | |