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

EnterScriptDeclaration() public method

Processes script declarations. Opens a datum. Creates the script node and the initial "begin" expression. Generates the variable lookup. Pushes return types.
public EnterScriptDeclaration ( HS_Gen1Parser.ScriptDeclarationContext context ) : void
context HS_Gen1Parser.ScriptDeclarationContext
return void
        public override void EnterScriptDeclaration(HS_Gen1Parser.ScriptDeclarationContext context)
        {
            if(_debug)
            {
                _logger.Script(context, CompilerContextAction.Enter);
            }

            // Create new script object and add it to the table.
            Script script = ScriptObjectCreation.GetScriptFromContext(context, _currentIndex, _opcodes);
            _scripts.Add(script);

            // Generate the parameter lookup.
            for(ushort i = 0; i < script.Parameters.Count; i++)
            {
                ScriptParameter parameter = script.Parameters[i];
                var info = new ParameterInfo(parameter.Name, _opcodes.GetTypeInfo(parameter.Type).Name, i);
                _parameterLookup.Add(info.Name, info);
            }

            string returnType = context.VALUETYPE().GetTextSanitized();
            int expressionCount = context.expression().Count();

            // The final expression must match the return type of this script.
            _expectedTypes.PushType(returnType);
            // The other expressions can be of any type.
            if (expressionCount > 1)
            {
                _expectedTypes.PushTypes("void", expressionCount - 1);
            }

            CreateInitialBegin(returnType, context.GetCorrectTextPosition(_missingCarriageReturnPositions));
        }