Exemplo n.º 1
0
 override public IWorkshopTree New(ActionSet actionSet, Constructor constructor, IWorkshopTree[] constructorValues, object[] additionalParameterData)
 {
     if (TypeKind == TypeKind.Class)
     {
         return(NewClass(actionSet.New(actionSet.IndexAssigner.CreateContained()), constructor, constructorValues));
     }
     else if (TypeKind == TypeKind.Struct)
     {
         return(NewStruct(actionSet.New(actionSet.IndexAssigner.CreateContained()), constructor, constructorValues));
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        // Parses the method.
        public override IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
        {
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());
            var controller = new FunctionBuildController(actionSet, methodCall, new DefaultGroupDeterminer(GetOverrideFunctionHandlers()));

            return(controller.Call());
        }
Exemplo n.º 3
0
        override public IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
        {
            // Assign the parameters.
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            return(AbstractMacroBuilder.Call(actionSet, this, methodCall));
        }
        override public IWorkshopTree Parse(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            actionSet = actionSet
                        .New(actionSet.IndexAssigner.CreateContained());

            if (IsRecursive)
            {
                return(ParseRecursive(actionSet, parameterValues));
            }

            ReturnHandler returnHandler = new ReturnHandler(actionSet, Name, multiplePaths);

            actionSet = actionSet.New(returnHandler);

            AssignParameters(actionSet, ParameterVars, parameterValues);
            block.Translate(actionSet);

            returnHandler.ApplyReturnSkips();
            return(returnHandler.GetReturnedValue());
        }
        override public IWorkshopTree Parse(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            // Assign the parameters.
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());
            for (int i = 0; i < ParameterVars.Length; i++)
            {
                actionSet.IndexAssigner.Add(ParameterVars[i], parameterValues[i]);
            }

            // Parse the expression.
            return(Expression.Parse(actionSet));
        }
Exemplo n.º 6
0
        override public IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
        {
            // Assign the parameters.
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());
            for (int i = 0; i < ParameterVars.Length; i++)
            {
                actionSet.IndexAssigner.Add(ParameterVars[i], methodCall.ParameterValues[i]);
            }

            // Parse the expression.
            return(Expression.Parse(actionSet));
        }
Exemplo n.º 7
0
        public override IWorkshopTree New(ActionSet actionSet, Constructor constructor, IWorkshopTree[] constructorValues, object[] additionalParameterData)
        {
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            ClassData classData = actionSet.Translate.DeltinScript.GetComponent <ClassData>();

            // Classes are stored in the class array (`classData.ClassArray`),
            // this stores the index where the new class is created at.
            var classReference = Create(actionSet, classData);

            New(actionSet, new NewClassInfo(classReference, constructor, constructorValues, additionalParameterData));

            // Return the reference.
            return(classReference.GetVariable());
        }
        private IWorkshopTree ParseNormal(ActionSet actionSet, MethodCall methodCall)
        {
            // Create the return handler.
            ReturnHandler returnHandler = methodCall.ReturnHandler ?? new ReturnHandler(actionSet, Name, multiplePaths);

            actionSet = actionSet.New(returnHandler);

            // Assign the parameters and translate the block.
            AssignParameters(actionSet, ParameterVars, methodCall.ParameterValues);
            block.Translate(actionSet);

            if (methodCall.ResolveReturnHandler)
            {
                returnHandler.ApplyReturnSkips();
            }
            return(returnHandler.GetReturnedValue());
        }
Exemplo n.º 9
0
        public TranslateRule(DeltinScript deltinScript, RuleAction ruleAction)
        {
            DeltinScript = deltinScript;
            IsGlobal     = ruleAction.EventType == RuleEvent.OngoingGlobal;
            Name         = ruleAction.Name;
            EventType    = ruleAction.EventType;
            Team         = ruleAction.Team;
            Player       = ruleAction.Player;
            Disabled     = ruleAction.Disabled;
            Priority     = ruleAction.Priority;

            ActionSet = new ActionSet(this, null, Actions);

            GetConditions(ruleAction);

            RuleReturnHandler returnHandler = new RuleReturnHandler(ActionSet);

            ruleAction.Block.Translate(ActionSet.New(returnHandler));
        }
Exemplo n.º 10
0
        public override IWorkshopTree New(ActionSet actionSet, Constructor constructor, IWorkshopTree[] constructorValues, object[] additionalParameterData)
        {
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            ClassData classData = actionSet.Translate.DeltinScript.GetComponent <ClassData>();

            // Classes are stored in the class array (`classData.ClassArray`),
            // this stores the index where the new class is created at.
            var classReference = actionSet.VarCollection.Assign("_new_" + Name + "_class_index", actionSet.IsGlobal, true);

            classData.GetClassIndex(Identifier, classReference, actionSet);

            // Get object variables.
            BaseSetup(actionSet, (Element)classReference.GetVariable());
            New(actionSet, new NewClassInfo(classReference, constructor, constructorValues, additionalParameterData));

            // Return the reference.
            return(classReference.GetVariable());
        }
Exemplo n.º 11
0
        public TranslateRule(DeltinScript deltinScript, RuleAction ruleAction)
        {
            DeltinScript = deltinScript;
            IsGlobal     = ruleAction.EventType == RuleEvent.OngoingGlobal;
            Name         = ruleAction.Name;
            EventType    = ruleAction.EventType;
            Team         = ruleAction.Team;
            Player       = ruleAction.Player;
            Disabled     = ruleAction.Disabled;
            ContinueSkip = new ContinueSkip(this);

            ActionSet = new ActionSet(this, null, Actions);

            GetConditions(ruleAction);

            ReturnHandler returnHandler = new ReturnHandler(ActionSet, Name, false);

            ruleAction.Block.Translate(ActionSet.New(returnHandler));
            returnHandler.ApplyReturnSkips();
        }
        private IWorkshopTree ParseVirtual(ActionSet actionSet, MethodCall methodCall)
        {
            // Create the switch that chooses the overload.
            SwitchBuilder typeSwitch = new SwitchBuilder(actionSet);

            // Loop through all potential methods.
            IMethod[] options = Attributes.AllOverrideOptions();

            // Get the call settings.
            MethodCall callSettings = new MethodCall(methodCall.ParameterValues, methodCall.AdditionalParameterData)
            {
                ResolveOverrides     = false,
                ResolveReturnHandler = false,
                ReturnHandler        = new ReturnHandler(actionSet, Name, true)
            };

            // Parse the current overload.
            typeSwitch.NextCase(new V_Number(((ClassType)Attributes.ContainingType).Identifier));
            Parse(actionSet, callSettings);

            foreach (IMethod option in options)
            {
                // The action set for the overload.
                ActionSet optionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

                // Add the object variables of the selected method.
                option.Attributes.ContainingType.AddObjectVariablesToAssigner(optionSet.CurrentObject, optionSet.IndexAssigner);

                // Go to next case then parse the block.
                typeSwitch.NextCase(new V_Number(((ClassType)option.Attributes.ContainingType).Identifier));
                option.Parse(optionSet, callSettings);
            }

            ClassData classData = actionSet.Translate.DeltinScript.SetupClasses();

            // Finish the switch.
            typeSwitch.Finish(Element.Part <V_ValueInArray>(classData.ClassIndexes.GetVariable(), actionSet.CurrentObject));

            callSettings.ReturnHandler.ApplyReturnSkips();
            return(callSettings.ReturnHandler.GetReturnedValue());
        }
        // Parses the method.
        override public IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
        {
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            if (Attributes.WasOverriden && methodCall.ResolveOverrides)
            {
                return(ParseVirtual(actionSet, methodCall));
            }

            if (Attributes.Recursive && !IsSubroutine)
            {
                return(RecursiveStack.Call(this, methodCall, actionSet));
            }

            if (IsSubroutine)
            {
                return(ParseSubroutine(actionSet, methodCall));
            }

            return(ParseNormal(actionSet, methodCall));
        }
        /// <summary>Calls the method.</summary>
        private IWorkshopTree ParseCall(ActionSet actionSet, MethodCall methodCall)
        {
            // Create the array used for continuing after a recursive call.
            continueArray = actionSet.VarCollection.Assign("_" + method.Name + "_recursiveContinue", actionSet.IsGlobal, false);
            nextContinue  = actionSet.VarCollection.Assign("_" + method.Name + "_nextContinue", actionSet.IsGlobal, true);
            actionSet.InitialSet().AddAction(continueArray.SetVariable(new V_EmptyArray()));

            ReturnHandler returnHandler = methodCall.ReturnHandler ?? new ReturnHandler(actionSet, method.Name, method.multiplePaths);

            this.returnHandler = returnHandler;

            DefinedMethod.AssignParameters(actionSet, method.ParameterVars, methodCall.ParameterValues, true);

            actionSet.AddAction(Element.Part <A_While>(new V_True()));

            continueAt = new SkipStartMarker(actionSet);
            continueAt.SetSkipCount((Element)nextContinue.GetVariable());
            actionSet.AddAction(continueAt);

            method.block.Translate(actionSet.New(returnHandler));

            PopParameterStacks(actionSet);

            // Pop the continueArray.
            actionSet.AddAction(Element.Part <A_SkipIf>(new V_Compare(
                                                            Element.Part <V_CountOf>(continueArray.GetVariable()),
                                                            Operators.Equal,
                                                            new V_Number(0)
                                                            ), new V_Number(3)));

            actionSet.AddAction(nextContinue.SetVariable(Element.Part <V_LastOf>(continueArray.GetVariable())));
            actionSet.AddAction(continueArray.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.Part <V_CountOf>(continueArray.GetVariable()) - 1));

            actionSet.AddAction(endOfMethod);
            actionSet.AddAction(new A_End());

            actionSet.AddAction(nextContinue.SetVariable(0));

            return(returnHandler.GetReturnedValue());
        }
        public IWorkshopTree ParseVirtual()
        {
            IMacroOption[] options = AllOptions();

            //If there are no overrides, don't bother creating the lookup table
            if (options.Length == 1)
            {
                return(options[0].Parse(ActionSet));
            }

            List <IWorkshopTree> expElements = new List <IWorkshopTree>();
            List <int>           resolves    = new List <int>();
            List <int>           identifiers = new List <int>();
            bool needsResolve = false;

            foreach (var option in options)
            {
                var optionSet = ActionSet.New(ActionSet.IndexAssigner.CreateContained());
                option.Type().AddObjectVariablesToAssigner(optionSet.CurrentObject, optionSet.IndexAssigner);

                int currentIndex = expElements.Count;
                expElements.Add(option.Parse(optionSet));
                resolves.Add(currentIndex);
                identifiers.Add(((ClassType)option.Type()).Identifier);

                // Iterate through every type.
                foreach (CodeType type in ActionSet.Translate.DeltinScript.Types.AllTypes)
                {
                    // If 'type' does not equal the current virtual option's containing class...
                    if (option.Type() != type
                        // ...and 'type' implements the containing class...
                        && type.Implements(option.Type())
                        // ...and 'type' does not have their own function implementation...
                        && Deltin.Deltinteger.Parse.FunctionBuilder.VirtualLookupTable.AutoImplemented(option.Type(), options.Select(option => option.Type()).ToArray(), type))
                    // ...then add an additional case for 'type's class identifier.
                    {
                        needsResolve = true;
                        resolves.Add(currentIndex);
                        identifiers.Add(((ClassType)type).Identifier);
                    }
                }
            }

            Element expArray     = Element.CreateArray(expElements.ToArray());
            Element resolveArray = Element.CreateArray(resolves.Select(i => new V_Number(i)).ToArray());
            Element identArray   = Element.CreateArray(identifiers.Select(i => new V_Number(i)).ToArray());

            ClassData classData       = ActionSet.Translate.DeltinScript.GetComponent <ClassData>();
            Element   classIdentifier = Element.Part <V_ValueInArray>(classData.ClassIndexes.GetVariable(), ActionSet.CurrentObject);

            /*
             * class A // Class identifier: 5
             * {
             *  virtual define Macro: 2;
             * }
             * class B : A // Class identifier: 6
             * {
             *  override define Macro: 3;
             * }
             * In this case, the macro can be resolved like so:
             * [2, 3][Index Of([5, 6], class id)]
             * This output will not work in this case:
             * class A // Class identifier: 5
             * {
             *  virtual define Macro: 2;
             * }
             * class B : A // Class identifier: 6
             * {
             *  override define Macro: 3;
             * }
             * class C : B // Class identifier: 7
             * {
             * }
             * C does not implement 'Macro'. This will cause the output to be the same as above.
             * This is not correct. Since C implements B, it should return 3. Since Index Of returns -1, the macro will return 0 if 'new C().Macro' is called.
             * If this case happens, 'needsResolve' will be true. When it is true, do this instead:
             * [2, 3][0, 1, 1][IndexOf([5, 6, 7], class id)]
             * '[0, 1, 1]' will map the index to the correct macro value.
             */

            if (needsResolve)
            {
                return(expArray[resolveArray[Element.Part <V_IndexOfArrayValue>(identArray, classIdentifier)]]);
            }
            else
            {
                return(expArray[Element.Part <V_IndexOfArrayValue>(identArray, classIdentifier)]);
            }
        }
Exemplo n.º 16
0
 // IExpression
 public IWorkshopTree Parse(ActionSet actionSet, bool asElement = true)
 {
     return(CallingMethod.Parse(actionSet.New(NameRange), GetParameterValuesAsWorkshop(actionSet), OverloadChooser.AdditionalParameterData));
 }
        private IWorkshopTree ParseRecursive(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            // Check the method stack to see if this method was already called.
            RecursiveMethodStack lastCall = actionSet.Translate.MethodStack.FirstOrDefault(ms => ms.Function == this) as RecursiveMethodStack;

            // If not, set up the stack and call the method.
            if (lastCall == null)
            {
                // Assign the parameters.
                AssignParameters(actionSet, ParameterVars, parameterValues, true);

                // Get the return handler if a value is returned.
                ReturnHandler returnHandler = new ReturnHandler(actionSet, Name, true);

                // Set up the condinue skip array.
                IndexReference continueSkipArray = actionSet.VarCollection.Assign("recursiveContinueArray", actionSet.IsGlobal, false);

                SkipEndMarker methodStart = new SkipEndMarker();
                actionSet.AddAction(methodStart);

                // Add the method to the stack.
                var stack = new RecursiveMethodStack(this, returnHandler, continueSkipArray, methodStart);
                actionSet.Translate.MethodStack.Add(stack);

                // Parse the method block.
                block.Translate(actionSet.New(returnHandler));

                // Apply the returns.
                if (returnHandler != null)
                {
                    returnHandler.ApplyReturnSkips();
                }

                // Pop the recursive parameters
                // TODO: Make this work with all sub scoped variables somehow
                for (int i = 0; i < ParameterVars.Length; i++)
                {
                    var pop = (actionSet.IndexAssigner[ParameterVars[i]] as RecursiveIndexReference)?.Pop();
                    if (pop != null)
                    {
                        actionSet.AddAction(pop);
                    }
                }

                // Setup the continue skip
                actionSet.ContinueSkip.Setup(actionSet);
                actionSet.ContinueSkip.SetSkipCount(actionSet, Element.Part <V_LastOf>(continueSkipArray.GetVariable()));

                // Remove the last recursive continue skip.
                actionSet.AddAction(continueSkipArray.SetVariable(
                                        // Pop
                                        Element.Part <V_ArraySlice>(
                                            continueSkipArray.GetVariable(),
                                            new V_Number(0),
                                            Element.Part <V_CountOf>(continueSkipArray.GetVariable()) - 1
                                            )
                                        ));

                // Loop if there are any values in the continue skip array.
                actionSet.AddAction(Element.Part <A_LoopIf>(
                                        Element.Part <V_CountOf>(continueSkipArray.GetVariable()) > 0
                                        ));

                // Reset the continue skip.
                actionSet.ContinueSkip.ResetSkipCount(actionSet);
                actionSet.AddAction(continueSkipArray.SetVariable(0));

                // Remove the method from the stack.
                actionSet.Translate.MethodStack.Remove(stack);

                return(returnHandler.GetReturnedValue());
            }
            // If it is, push the parameters to the stack.
            else
            {
                for (int i = 0; i < ParameterVars.Length; i++)
                {
                    var varReference = actionSet.IndexAssigner[ParameterVars[i]];
                    if (varReference is RecursiveIndexReference)
                    {
                        actionSet.AddAction(((RecursiveIndexReference)varReference).Push(
                                                (Element)parameterValues[i]
                                                ));
                    }
                }

                // Add to the continue skip array.
                V_Number skipLength = new V_Number();
                actionSet.AddAction(lastCall.ContinueSkipArray.SetVariable(
                                        Element.Part <V_Append>(lastCall.ContinueSkipArray.GetVariable(), skipLength)
                                        ));

                actionSet.ContinueSkip.Setup(actionSet);
                actionSet.ContinueSkip.SetSkipCount(actionSet, lastCall.MethodStart);
                actionSet.AddAction(new A_Loop());

                SkipEndMarker continueAt = new SkipEndMarker();
                actionSet.AddAction(continueAt);
                skipLength.Value = actionSet.ContinueSkip.GetSkipCount(continueAt).Value;

                return(lastCall.ReturnHandler.GetReturnedValue());
            }
        }
Exemplo n.º 18
0
 // IStatement
 public void Translate(ActionSet actionSet)
 {
     CallingMethod.Parse(actionSet.New(NameRange), GetParameterValuesAsWorkshop(actionSet), OverloadChooser.AdditionalParameterData);
 }
        public IWorkshopTree Parse(ActionSet actionSet)
        {
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            return(AbstractMacroBuilder.Call(actionSet, this));
        }
Exemplo n.º 20
0
 // IExpression
 public IWorkshopTree Parse(ActionSet actionSet)
 {
     return(CallingMethod.Parse(actionSet.New(NameRange), GetMethodCall(actionSet)));
 }
        public ExpressionTreeParseResult ParseTree(ActionSet actionSet, bool expectingValue)
        {
            IGettable        resultingVariable = null; // The resulting variable.
            IWorkshopTree    target            = null; // The resulting player.
            IWorkshopTree    result            = null; // The resulting value.
            VarIndexAssigner currentAssigner   = actionSet.IndexAssigner;
            IWorkshopTree    currentObject     = null;

            Element[] resultIndex = new Element[0];

            for (int i = 0; i < Tree.Length; i++)
            {
                bool          isLast  = i == Tree.Length - 1;
                IWorkshopTree current = null;
                if (Tree[i] is CallVariableAction)
                {
                    var callVariableAction = (CallVariableAction)Tree[i];

                    var reference = currentAssigner[callVariableAction.Calling];
                    current = reference.GetVariable((Element)target);

                    resultIndex = new Element[callVariableAction.Index.Length];
                    for (int ai = 0; ai < callVariableAction.Index.Length; ai++)
                    {
                        var workshopIndex = callVariableAction.Index[ai].Parse(actionSet);
                        resultIndex[ai] = (Element)workshopIndex;
                        current         = Element.Part <V_ValueInArray>(current, workshopIndex);
                    }

                    // If this is the last node in the tree, set the resulting variable.
                    if (isLast)
                    {
                        resultingVariable = reference;
                    }
                }
                else
                {
                    var newCurrent = Tree[i].Parse(actionSet.New(currentAssigner).New(currentObject));
                    if (newCurrent != null)
                    {
                        current     = newCurrent;
                        resultIndex = new Element[0];
                    }
                }

                if (Tree[i].Type() == null)
                {
                    // If this isn't the last in the tree, set it as the target.
                    if (!isLast)
                    {
                        target = current;
                    }
                    currentObject = null;
                }
                else
                {
                    var type = Tree[i].Type();

                    currentObject   = current;
                    currentAssigner = actionSet.IndexAssigner.CreateContained();
                    type.AddObjectVariablesToAssigner(currentObject, currentAssigner);
                }

                result = current;
            }

            if (result == null && expectingValue)
            {
                throw new Exception("Expression tree result is null");
            }
            return(new ExpressionTreeParseResult(result, resultIndex, target, resultingVariable));
        }
 public IWorkshopTree Parse(ActionSet actionSet, bool asElement = true)
 {
     return(Element.Part <V_ValueInArray>(Expression.Parse(actionSet.New(expressionRange)), Index.Parse(actionSet.New(indexRange))));
 }
 public override void Parse(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
 {
     actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained()).PackThis();
     DefinedMethod.AssignParameters(actionSet, ParameterVars, parameterValues);
     Block.Translate(actionSet);
 }
Exemplo n.º 24
0
 public override void Parse(ActionSet actionSet, IWorkshopTree[] parameterValues)
 {
     actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());
     DefinedMethod.AssignParameters(actionSet, ParameterVars, parameterValues);
     Block.Translate(actionSet);
 }
Exemplo n.º 25
0
 // IStatement
 public void Translate(ActionSet actionSet)
 {
     CallingMethod.Parse(actionSet.New(NameRange), GetMethodCall(actionSet));
 }
Exemplo n.º 26
0
 // Parses the method.
 override public IWorkshopTree Parse(ActionSet actionSet, MethodCall methodCall)
 {
     actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());
     return(MethodBuilder.Call(this, methodCall, actionSet));
 }
Exemplo n.º 27
0
        // Sets up single-instance methods for methods with the 'rule' attribute.
        public void SetupSubroutine()
        {
            if (subroutineInfo != null || !IsSubroutine)
            {
                return;
            }

            // Setup the subroutine element.
            Subroutine subroutine = parseInfo.TranslateInfo.SubroutineCollection.NewSubroutine(Name);

            // Create the rule.
            TranslateRule subroutineRule = new TranslateRule(parseInfo.TranslateInfo, subroutine, SubroutineName, subroutineDefaultGlobal);

            // Setup the return handler.
            ReturnHandler returnHandler = new ReturnHandler(subroutineRule.ActionSet, Name, multiplePaths || Attributes.Virtual);
            ActionSet     actionSet     = subroutineRule.ActionSet.New(returnHandler).New(subroutineRule.ActionSet.IndexAssigner.CreateContained());

            // Get the variables that will be used to store the parameters.
            IndexReference[] parameterStores = new IndexReference[ParameterVars.Length];
            for (int i = 0; i < ParameterVars.Length; i++)
            {
                // Create the workshop variable the parameter will be stored as.
                IndexReference indexResult = actionSet.IndexAssigner.AddIndexReference(actionSet.VarCollection, ParameterVars[i], subroutineDefaultGlobal, Attributes.Recursive);
                parameterStores[i] = indexResult;

                // Assign virtual variables to the index reference.
                foreach (Var virtualParameterOption in VirtualVarGroup(i))
                {
                    actionSet.IndexAssigner.Add(virtualParameterOption, indexResult);
                }
            }

            // If the subroutine is an object function inside a class, create a variable to store the class object.
            IndexReference objectStore = null;

            if (Attributes.ContainingType != null && !Static)
            {
                objectStore = actionSet.VarCollection.Assign("_" + Name + "_subroutineStore", true, !Attributes.Recursive);

                // Set the objectStore as an empty array if the subroutine is recursive.
                if (Attributes.Recursive)
                {
                    actionSet.InitialSet().AddAction(objectStore.SetVariable(new V_EmptyArray()));
                    Attributes.ContainingType.AddObjectVariablesToAssigner(Element.Part <V_LastOf>(objectStore.GetVariable()), actionSet.IndexAssigner);
                    actionSet = actionSet.New(Element.Part <V_LastOf>(objectStore.GetVariable())).PackThis();
                }
                else
                {
                    Attributes.ContainingType.AddObjectVariablesToAssigner(objectStore.GetVariable(), actionSet.IndexAssigner);
                    actionSet = actionSet.New(objectStore.GetVariable()).PackThis();
                }
            }

            // Set the subroutine info.
            subroutineInfo = new SubroutineInfo(subroutine, returnHandler, subroutineRule, parameterStores, objectStore);

            MethodBuilder builder = new MethodBuilder(this, actionSet, returnHandler);

            builder.BuilderSet = builder.BuilderSet.New(Attributes.Recursive);
            builder.ParseInner();

            // Apply returns.
            returnHandler.ApplyReturnSkips();

            // Pop object array and parameters if recursive.
            if (Attributes.Recursive)
            {
                if (objectStore != null)
                {
                    actionSet.AddAction(objectStore.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.Part <V_CountOf>(objectStore.GetVariable()) - 1));
                }
                RecursiveStack.PopParameterStacks(actionSet, ParameterVars);
            }

            // Add the subroutine.
            Rule translatedRule = subroutineRule.GetRule();

            parseInfo.TranslateInfo.WorkshopRules.Add(translatedRule);

            var codeLens = new ElementCountCodeLens(DefinedAt.range, parseInfo.TranslateInfo.OptimizeOutput);

            parseInfo.Script.AddCodeLensRange(codeLens);
            codeLens.RuleParsed(translatedRule);
        }
Exemplo n.º 28
0
 protected override void New(ActionSet actionSet, NewClassInfo newClassInfo)
 {
     // Run the constructor.
     AddObjectVariablesToAssigner((Element)newClassInfo.ObjectReference.GetVariable(), actionSet.IndexAssigner);
     newClassInfo.Constructor.Parse(actionSet.New((Element)newClassInfo.ObjectReference.GetVariable()), newClassInfo.ConstructorValues, null);
 }