private bool IsScriptReference(string expectedReturnType, int expectedParameterCount, HS_Gen1Parser.CallContext context)
{
string key = context.callID().GetTextSanitized();
if(!_scriptLookup.ContainsKey(key))
{
if (expectedReturnType == TypeHelper.ScriptReference)
{
throw new CompilerException($"The compiler expected a Script Reference but a Script with the name \"{key}\" could not be found. " +
"Please check your script declarations and your spelling.", context);
}
else
{
return false;
}
}
// Try to find a script, which satisfies all conditions.
foreach(ScriptInfo info in _scriptLookup[key])
{
if(info.Parameters.Count != expectedParameterCount)
{
continue;
}
string returnType = DetermineReturnType(info, expectedReturnType, context);
if(!(returnType is null))
{
// Check for equality functions.
EqualityPush(returnType);
// Push the parameters to the type stack.
if (expectedParameterCount > 0)
{
string[] parameterTypes = info.Parameters.Select(p => p.ReturnType).ToArray();
_expectedTypes.PushTypes(parameterTypes);
}
// Create a script reference node.
CreateScriptReference(info, _opcodes.GetTypeInfo(returnType).Opcode, context.GetCorrectTextPosition(_missingCarriageReturnPositions), GetLineNumber(context));
return true;
}
}
return false;
}