blob: ee575a84a4697f9d6e0a2a507047763cdbf35366 [file] [log] [blame]
Olli Etuaho95ed1942018-02-01 14:01:19 +02001//
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
20} // anonymous namespace
21
22TFunctionLookup::TFunctionLookup(const TString *name, const TType *constructorType)
23 : mName(name), mConstructorType(constructorType), mThisNode(nullptr)
24{
25}
26
27// static
28TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type)
29{
30 ASSERT(type != nullptr);
31 return new TFunctionLookup(nullptr, type);
32}
33
34// static
35TFunctionLookup *TFunctionLookup::CreateFunctionCall(const TString *name)
36{
37 ASSERT(name != nullptr);
38 return new TFunctionLookup(name, nullptr);
39}
40
41const TString &TFunctionLookup::name() const
42{
43 return *mName;
44}
45
46const TString &TFunctionLookup::getMangledName() const
47{
48 return GetMangledName(*mName, mArguments);
49}
50
51const 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
64bool TFunctionLookup::isConstructor() const
65{
66 return mConstructorType != nullptr;
67}
68
69const TType &TFunctionLookup::constructorType() const
70{
71 return *mConstructorType;
72}
73
74void TFunctionLookup::setThisNode(TIntermTyped *thisNode)
75{
76 mThisNode = thisNode;
77}
78
79TIntermTyped *TFunctionLookup::thisNode() const
80{
81 return mThisNode;
82}
83
84void TFunctionLookup::addArgument(TIntermTyped *argument)
85{
86 mArguments.push_back(argument);
87}
88
89TIntermSequence &TFunctionLookup::arguments()
90{
91 return mArguments;
92}
93
94} // namespace sh