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