Blamite.Blam.Scripting.Compiler.ScriptCompiler.IsScriptParameter C# (CSharp) Method

IsScriptParameter() private method

private IsScriptParameter ( string expectedReturnType, ParserRuleContext context ) : bool
expectedReturnType string
context ParserRuleContext
return bool
        private bool IsScriptParameter(string expectedReturnType, ParserRuleContext context)
        {
            // This script doesn't have parameters.
            if (_parameterLookup.Count == 0)
            {
                return false;
            }

            string text = context.GetTextSanitized();

            // The script doesn't have a parameter with this name.
            if (!_parameterLookup.TryGetValue(text, out ParameterInfo info))
            {
                return false;
            }

            string returnType = DetermineReturnType(info, expectedReturnType, context);

            if(returnType is null)
            {
                throw new CompilerException($"Failed to determine the return type of the parameter {text}.", context);
            }

            ushort returnTypeOpcode = _opcodes.GetTypeInfo(returnType).Opcode;
            ushort opcode = returnTypeOpcode;

            // (In)Equality functions are special
            if(context.Parent.Parent is HS_Gen1Parser.CallContext grandparent)
            {
                string funcName = grandparent.callID().GetTextSanitized();
                var funcInfo = _opcodes.GetFunctionInfo(funcName);
                if(funcInfo != null)
                {
                    if (funcInfo[0].Group == "Equality" || funcInfo[0].Group == "Inequality")
                    {
                        opcode = GetEqualityArgumentOP(returnTypeOpcode);
                    }
                }
            }

            var expression = new ScriptExpression
            {
                Index = _currentIndex,
                Opcode = opcode,
                ReturnType = returnTypeOpcode,
                Type = ScriptExpressionType.ParameterReference,
                Next = DatumIndex.Null,
                StringOffset = _strings.Cache(info.Name),
                Value = new LongExpressionValue(info.Opcode),
                LineNumber = GetLineNumber(context)
            };
            EqualityPush(info.ReturnType);
            OpenDatumAddExpressionIncrement(expression);

            return true;
        }