public override void EnterCall(HS_Gen1Parser.CallContext context)
{
if (_debug)
{
_logger.Call(context, CompilerContextAction.Enter);
}
LinkDatum();
// Retrieve information from the context.
string name = context.callID().GetTextSanitized();
string expectedType = _expectedTypes.PopType();
int contextParameterCount = context.expression().Length;
// Handle script references.
if (IsScriptReference(expectedType, contextParameterCount, context))
{
return;
}
// Handle functions.
var functions = _opcodes.GetFunctionInfo(name);
foreach(var func in functions)
{
if(!CheckParameterSanity(context, func))
{
continue;
}
string returnType = DetermineReturnType(func, expectedType, context);
// If a function, which satisfies the requirements, was found, perform the necessary push operations and create expression nodes.
if (!(returnType is null))
{
EqualityPush(func.ReturnType);
PushCallParameters(func, contextParameterCount, expectedType, context);
CreateFunctionCall(func, _opcodes.GetTypeInfo(returnType).Opcode, context.GetCorrectTextPosition(_missingCarriageReturnPositions), GetLineNumber(context));
return;
}
}
string errorMessage = contextParameterCount == 1 ?
$"Failed to process the call {name} with 1 parameter." :
$"Failed to process the call {name} with {contextParameterCount} parameters.";
throw new CompilerException(errorMessage + $" The expected return type was {expectedType}.", context);
}