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
12namespace sh
13{
14
15namespace
16{
17
18const char kFunctionMangledNameSeparator = '(';
19
20constexpr const ImmutableString kEmptyName("");
21
22} // anonymous namespace
23
24TFunctionLookup::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
31TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type)
32{
33 ASSERT(type != nullptr);
34 return new TFunctionLookup(kEmptyName, type, nullptr);
35}
36
37// static
38TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name,
39 const TSymbol *symbol)
40{
41 ASSERT(name != "");
42 return new TFunctionLookup(name, nullptr, symbol);
43}
44
45const ImmutableString &TFunctionLookup::name() const
46{
47 return mName;
48}
49
50ImmutableString TFunctionLookup::getMangledName() const
51{
52 return GetMangledName(mName.data(), mArguments);
53}
54
55ImmutableString 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
68bool TFunctionLookup::isConstructor() const
69{
70 return mConstructorType != nullptr;
71}
72
73const TType &TFunctionLookup::constructorType() const
74{
75 return *mConstructorType;
76}
77
78void TFunctionLookup::setThisNode(TIntermTyped *thisNode)
79{
80 mThisNode = thisNode;
81}
82
83TIntermTyped *TFunctionLookup::thisNode() const
84{
85 return mThisNode;
86}
87
88void TFunctionLookup::addArgument(TIntermTyped *argument)
89{
90 mArguments.push_back(argument);
91}
92
93TIntermSequence &TFunctionLookup::arguments()
94{
95 return mArguments;
96}
97
98const TSymbol *TFunctionLookup::symbol() const
99{
100 return mSymbol;
101}
102
103} // namespace sh
104