HLSL: Add function call syntax and AST building.

This commit is contained in:
John Kessenich
2016-05-13 09:33:42 -06:00
parent 9db3117e38
commit 4678ca9dac
6 changed files with 83 additions and 25 deletions

View File

@@ -608,7 +608,7 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
return false;
// arguments
TIntermAggregate* arguments = nullptr;
TIntermTyped* arguments = nullptr;
if (! acceptArguments(constructorFunction, arguments)) {
expected("constructor arguments");
return false;
@@ -628,10 +628,17 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
// function_call
// : [idToken] arguments
//
bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*&)
bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*& node)
{
// todo
return false;
// arguments
TFunction* function = new TFunction(idToken.string, TType(EbtVoid));
TIntermTyped* arguments = nullptr;
if (! acceptArguments(function, arguments))
return false;
node = parseContext.handleFunctionCall(idToken.loc, function, arguments);
return true;
}
// arguments
@@ -640,7 +647,7 @@ bool HlslGrammar::acceptFunctionCall(HlslToken idToken, TIntermTyped*&)
// The arguments are pushed onto the 'function' argument list and
// onto the 'arguments' aggregate.
//
bool HlslGrammar::acceptArguments(TFunction* function, TIntermAggregate*& arguments)
bool HlslGrammar::acceptArguments(TFunction* function, TIntermTyped*& arguments)
{
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen))
@@ -649,7 +656,7 @@ bool HlslGrammar::acceptArguments(TFunction* function, TIntermAggregate*& argume
do {
// expression
TIntermTyped* arg;
if (! acceptExpression(arg))
if (! acceptAssignmentExpression(arg))
break;
// hook it up

View File

@@ -71,7 +71,7 @@ namespace glslang {
bool acceptPostfixExpression(TIntermTyped*&);
bool acceptConstructor(TIntermTyped*&);
bool acceptFunctionCall(HlslToken, TIntermTyped*&);
bool acceptArguments(TFunction*, TIntermAggregate*&);
bool acceptArguments(TFunction*, TIntermTyped*&);
bool acceptLiteral(TIntermTyped*&);
bool acceptCompoundStatement(TIntermAggregate*&);
bool acceptStatement(TIntermNode*&);

View File

@@ -754,12 +754,15 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
return paramNodes;
}
void HlslParseContext::handleFunctionArgument(TFunction* function, TIntermAggregate*& arguments, TIntermTyped* arg)
void HlslParseContext::handleFunctionArgument(TFunction* function, TIntermTyped*& arguments, TIntermTyped* newArg)
{
TParameter param = { 0, new TType };
param.type->shallowCopy(arg->getType());
param.type->shallowCopy(newArg->getType());
function->addParameter(param);
arguments = intermediate.growAggregate(arguments, arg);
if (arguments)
arguments = intermediate.growAggregate(arguments, newArg);
else
arguments = newArg;
}
//

View File

@@ -83,7 +83,7 @@ public:
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
TFunction* handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&);
void handleFunctionArgument(TFunction*, TIntermAggregate*&, TIntermTyped*);
void handleFunctionArgument(TFunction*, TIntermTyped*& arguments, TIntermTyped* newArg);
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermNode*);
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
void addInputArgumentConversions(const TFunction&, TIntermNode*&) const;