コード例 #1
0
        protected void SetupNew(ScopeGroup getter, ScopeGroup scope, IndexedVar store, ScopeGroup typeScope, TranslateRule context, CreateObjectNode node)
        {
            // Set the default variables in the struct
            for (int i = 0; i < DefinedVars.Length; i++)
            {
                if (DefinedVars[i].Value != null)
                {
                    context.Actions.AddRange(
                        store.SetVariable(context.ParseExpression(typeScope, typeScope, DefinedVars[i].Value), null, i)
                        );
                }
            }

            Constructor constructor = Constructors.FirstOrDefault(c => c.Parameters.Length == node.Parameters.Length);

            if (constructor == null)
            {
                throw SyntaxErrorException.NotAConstructor(TypeKind, Name, node.Parameters.Length, node.Location);
            }

            if (context.MethodStackNotRecursive.Contains(constructor))
            {
                throw new SyntaxErrorException("Constructors cannot be recursive.", node.Location);
            }
            context.MethodStackNotRecursive.Add(constructor);

            ScopeGroup constructorScope = typeScope.Child();

            IWorkshopTree[] parameters = context.ParseParameters(
                getter,
                scope,
                constructor.Parameters,
                node.Parameters,
                node.TypeName,
                node.Location
                );

            context.AssignParameterVariables(constructorScope, constructor.Parameters, parameters, node);
            if (constructor.BlockNode != null)
            {
                context.ParseBlock(constructorScope, constructorScope, constructor.BlockNode, true, null);
            }
            constructorScope.Out(context);
            context.MethodStackNotRecursive.Remove(constructor);
        }