Add symbol table function to get TFunction for a built-in op
Built-in function parameter qualifiers are stored in the symbol table.
Some AST traversers need the qualifier information for ops to
determine whether a node is being written to. Add an utility function
that maps a TIntermAggregate node to a symbol table entry, so that the
traversers can get to this information in a convenient way.
This will be necessary for adding more built-ins that have out
parameters from ESSL 3.10.
BUG=angleproject:1730
TEST=angle_unittests
Change-Id: I4bc622d70b2326a04cc858ff1258c22320c590dc
Reviewed-on: https://chromium-review.googlesource.com/431109
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index 44c4ca4..beda47a 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -14,7 +14,9 @@
#endif
#include "compiler/translator/SymbolTable.h"
+
#include "compiler/translator/Cache.h"
+#include "compiler/translator/IntermNode.h"
#include <stdio.h>
#include <algorithm>
@@ -153,6 +155,30 @@
return 0;
}
+TFunction *TSymbolTable::findBuiltInOp(TIntermAggregate *callNode, int shaderVersion) const
+{
+ ASSERT(!callNode->isConstructor());
+ ASSERT(callNode->getOp() != EOpFunctionCall);
+ TString opString = GetOperatorString(callNode->getOp());
+ // The return type doesn't affect the mangled name of the function, which is used to look it up.
+ TType dummyReturnType;
+ TFunction call(&opString, &dummyReturnType, callNode->getOp());
+ TIntermSequence *sequence = callNode->getSequence();
+ for (auto *child : *sequence)
+ {
+ TType *paramType = child->getAsTyped()->getTypePointer();
+ TConstParameter p(paramType);
+ call.addParameter(p);
+ }
+
+ TSymbol *sym = findBuiltIn(call.getMangledName(), shaderVersion);
+ ASSERT(sym != nullptr && sym->isFunction());
+
+ TFunction *builtInFunc = static_cast<TFunction *>(sym);
+ ASSERT(builtInFunc->getParamCount() == sequence->size());
+ return builtInFunc;
+}
+
TSymbolTable::~TSymbolTable()
{
while (table.size() > 0)