blob: 1a81f9a507ad0ae31338c979afe907751f8e4b39 [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
Olli Etuahofbb1c792018-01-19 16:26:59 +020020constexpr const ImmutableString kEmptyName("");
21
Olli Etuaho95ed1942018-02-01 14:01:19 +020022} // anonymous namespace
23
Olli Etuahofbb1c792018-01-19 16:26:59 +020024TFunctionLookup::TFunctionLookup(const ImmutableString &name, const TType *constructorType)
Olli Etuaho95ed1942018-02-01 14:01:19 +020025 : mName(name), mConstructorType(constructorType), mThisNode(nullptr)
26{
27}
28
29// static
30TFunctionLookup *TFunctionLookup::CreateConstructor(const TType *type)
31{
32 ASSERT(type != nullptr);
Olli Etuahofbb1c792018-01-19 16:26:59 +020033 return new TFunctionLookup(kEmptyName, type);
Olli Etuaho95ed1942018-02-01 14:01:19 +020034}
35
36// static
Olli Etuahofbb1c792018-01-19 16:26:59 +020037TFunctionLookup *TFunctionLookup::CreateFunctionCall(const ImmutableString &name)
Olli Etuaho95ed1942018-02-01 14:01:19 +020038{
Olli Etuahofbb1c792018-01-19 16:26:59 +020039 ASSERT(name != "");
Olli Etuaho95ed1942018-02-01 14:01:19 +020040 return new TFunctionLookup(name, nullptr);
41}
42
Olli Etuahofbb1c792018-01-19 16:26:59 +020043const ImmutableString &TFunctionLookup::name() const
Olli Etuaho95ed1942018-02-01 14:01:19 +020044{
Olli Etuahofbb1c792018-01-19 16:26:59 +020045 return mName;
Olli Etuaho95ed1942018-02-01 14:01:19 +020046}
47
Olli Etuahofbb1c792018-01-19 16:26:59 +020048ImmutableString TFunctionLookup::getMangledName() const
Olli Etuaho95ed1942018-02-01 14:01:19 +020049{
Olli Etuahofbb1c792018-01-19 16:26:59 +020050 return GetMangledName(mName.data(), mArguments);
Olli Etuaho95ed1942018-02-01 14:01:19 +020051}
52
Olli Etuahofbb1c792018-01-19 16:26:59 +020053ImmutableString TFunctionLookup::GetMangledName(const char *functionName,
54 const TIntermSequence &arguments)
Olli Etuaho95ed1942018-02-01 14:01:19 +020055{
Olli Etuahofbb1c792018-01-19 16:26:59 +020056 std::string newName(functionName);
Olli Etuaho95ed1942018-02-01 14:01:19 +020057 newName += kFunctionMangledNameSeparator;
58
59 for (TIntermNode *argument : arguments)
60 {
61 newName += argument->getAsTyped()->getType().getMangledName();
62 }
Olli Etuahofbb1c792018-01-19 16:26:59 +020063 return ImmutableString(newName);
Olli Etuaho95ed1942018-02-01 14:01:19 +020064}
65
66bool TFunctionLookup::isConstructor() const
67{
68 return mConstructorType != nullptr;
69}
70
71const TType &TFunctionLookup::constructorType() const
72{
73 return *mConstructorType;
74}
75
76void TFunctionLookup::setThisNode(TIntermTyped *thisNode)
77{
78 mThisNode = thisNode;
79}
80
81TIntermTyped *TFunctionLookup::thisNode() const
82{
83 return mThisNode;
84}
85
86void TFunctionLookup::addArgument(TIntermTyped *argument)
87{
88 mArguments.push_back(argument);
89}
90
91TIntermSequence &TFunctionLookup::arguments()
92{
93 return mArguments;
94}
95
96} // namespace sh