Hash :
8b5e8fdb
Author :
Date :
2017-12-15T14:59:15
Replace remaining usage of TName with TSymbol TName used to contain just a subset of the information stored in TSymbol. It makes more sense to use TSymbol directly instead of converting it to TName. This also improves type safety a bit by making some functions only take in TVariable or TFunction instead of the more generic TName. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Icb46923c25d33ebbbbc06ddc487da25957dda771 Reviewed-on: https://chromium-review.googlesource.com/829143 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Symbol.cpp: Symbols representing variables, functions, structures and interface blocks.
//
#if defined(_MSC_VER)
#pragma warning(disable : 4718)
#endif
#include "compiler/translator/Symbol.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
namespace
{
static const char kFunctionMangledNameSeparator = '(';
} // anonymous namespace
TSymbol::TSymbol(TSymbolTable *symbolTable,
const TString *name,
SymbolType symbolType,
TExtension extension)
: mName(name),
mUniqueId(symbolTable->nextUniqueId()),
mSymbolType(symbolType),
mExtension(extension)
{
ASSERT(mSymbolType == SymbolType::BuiltIn || mExtension == TExtension::UNDEFINED);
ASSERT(mName != nullptr || mSymbolType == SymbolType::AngleInternal ||
mSymbolType == SymbolType::NotResolved || mSymbolType == SymbolType::Empty);
ASSERT(mName == nullptr || *mName != "");
}
const TString &TSymbol::name() const
{
if (mName != nullptr)
{
return *mName;
}
ASSERT(mSymbolType == SymbolType::AngleInternal);
TInfoSinkBase symbolNameOut;
symbolNameOut << "s" << mUniqueId.get();
return *NewPoolTString(symbolNameOut.c_str());
}
const TString &TSymbol::getMangledName() const
{
ASSERT(mSymbolType != SymbolType::Empty);
return name();
}
TVariable::TVariable(TSymbolTable *symbolTable,
const TString *name,
const TType &t,
SymbolType symbolType,
TExtension extension)
: TSymbol(symbolTable, name, symbolType, extension), type(t), unionArray(nullptr)
{
}
TStructure::TStructure(TSymbolTable *symbolTable,
const TString *name,
const TFieldList *fields,
SymbolType symbolType)
: TSymbol(symbolTable, name, symbolType), TFieldListCollection(fields)
{
}
void TStructure::createSamplerSymbols(const TString &namePrefix,
const TString &apiNamePrefix,
TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
TSymbolTable *symbolTable) const
{
ASSERT(containsSamplers());
for (const auto *field : *mFields)
{
const TType *fieldType = field->type();
if (IsSampler(fieldType->getBasicType()) || fieldType->isStructureContainingSamplers())
{
TString fieldName = namePrefix + "_" + field->name();
TString fieldApiName = apiNamePrefix + "." + field->name();
fieldType->createSamplerSymbols(fieldName, fieldApiName, outputSymbols,
outputSymbolsToAPINames, symbolTable);
}
}
}
void TStructure::setName(const TString &name)
{
TString *mutableName = const_cast<TString *>(mName);
*mutableName = name;
}
TInterfaceBlock::TInterfaceBlock(TSymbolTable *symbolTable,
const TString *name,
const TFieldList *fields,
const TLayoutQualifier &layoutQualifier,
SymbolType symbolType,
TExtension extension)
: TSymbol(symbolTable, name, symbolType, extension),
TFieldListCollection(fields),
mBlockStorage(layoutQualifier.blockStorage),
mBinding(layoutQualifier.binding)
{
ASSERT(name != nullptr);
}
TFunction::TFunction(TSymbolTable *symbolTable,
const TString *name,
const TType *retType,
SymbolType symbolType,
bool knownToNotHaveSideEffects,
TOperator tOp,
TExtension extension)
: TSymbol(symbolTable, name, symbolType, extension),
returnType(retType),
mangledName(nullptr),
op(tOp),
defined(false),
mHasPrototypeDeclaration(false),
mKnownToNotHaveSideEffects(knownToNotHaveSideEffects)
{
// Functions with an empty name are not allowed.
ASSERT(symbolType != SymbolType::Empty);
ASSERT(name != nullptr || symbolType == SymbolType::AngleInternal || tOp != EOpNull);
}
//
// Functions have buried pointers to delete.
//
TFunction::~TFunction()
{
clearParameters();
}
void TFunction::clearParameters()
{
for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i)
delete (*i).type;
parameters.clear();
mangledName = nullptr;
}
void TFunction::swapParameters(const TFunction ¶metersSource)
{
clearParameters();
for (auto parameter : parametersSource.parameters)
{
addParameter(parameter);
}
}
const TString *TFunction::buildMangledName() const
{
std::string newName = name().c_str();
newName += kFunctionMangledNameSeparator;
for (const auto &p : parameters)
{
newName += p.type->getMangledName();
}
return NewPoolTString(newName.c_str());
}
const TString &TFunction::GetMangledNameFromCall(const TString &functionName,
const TIntermSequence &arguments)
{
std::string newName = functionName.c_str();
newName += kFunctionMangledNameSeparator;
for (TIntermNode *argument : arguments)
{
newName += argument->getAsTyped()->getType().getMangledName();
}
return *NewPoolTString(newName.c_str());
}
bool TFunction::isMain() const
{
return symbolType() == SymbolType::UserDefined && name() == "main";
}
bool TFunction::isImageFunction() const
{
return symbolType() == SymbolType::BuiltIn &&
(name() == "imageSize" || name() == "imageLoad" || name() == "imageStore");
}
} // namespace sh