public override IStatement VisitForEachStatement(ForEachStatementSyntax node)
        {
            var s = this.semanticModel.GetDeclaredSymbol(node) as Microsoft.CodeAnalysis.CSharp.Symbols.LocalSymbol;

            if (s != null)
            {
                var local = new LocalDefinition()
                {
                    Name             = this.host.NameTable.GetNameFor(s.Name),
                    MethodDefinition = this.method,
                    Type             = this.mapper.Map(s.Type),
                };


                this.expressionVisitor.RegisterLocal(s, local);
                var body        = this.Visit(node.Statement);
                var foreachStmt = new ForEachStatement()
                {
                    Body       = this.Visit(node.Statement),
                    Collection = this.expressionVisitor.Visit(node.Expression),
                    Variable   = local,
                    Locations  = Helper.SourceLocation(this.tree, node),
                };

                if (!(foreachStmt.Collection.Type is IArrayTypeReference))
                {
                    var msg = String.Format("VisitForEachStatement can't handle the type '{0}'", TypeHelper.GetTypeName(foreachStmt.Collection.Type, NameFormattingOptions.None));
                    throw new InvalidDataException(msg);
                }

                return(foreachStmt);
            }
            throw new InvalidDataException("VisitForEachStatement couldn't find something to return");
        }
Beispiel #2
0
 public virtual ICodeNode VisitForEachStatement(ForEachStatement node)
 {
     node.Variable   = (VariableDeclarationExpression)Visit(node.Variable);
     node.Collection = (Expression)Visit(node.Collection);
     node.Body       = (BlockStatement)Visit(node.Body);
     return(node);
 }
Beispiel #3
0
        protected override IPyStatement[] VisitForEachStatement(ForEachStatement src)
        {
            var g                = src.VarName;
            var collection       = TransValue(src.Collection);
            var statement        = this.TranslateStatementOne(src.Statement);
            PyForEachStatement a = null;

            if (src.ItemType.DotnetType.IsGenericType)
            {
                var gtd = src.ItemType.DotnetType.GetGenericTypeDefinition();
                if (gtd == typeof(KeyValuePair <,>))
                {
                    a = new PyForEachStatement(src.VarName, collection, statement);
                    // $i@Key
                    a.KeyVarname   = src.VarName + "@Key";
                    a.ValueVarname = src.VarName + "@Value";
                }
            }

            if (a == null)
            {
                a = new PyForEachStatement(src.VarName, collection, statement);
            }
            return(MkArray(a));
        }
 public virtual ICodeNode VisitForEachStatement(ForEachStatement node)
 {
     node.set_Variable((VariableDeclarationExpression)this.Visit(node.get_Variable()));
     node.set_Collection((Expression)this.Visit(node.get_Collection()));
     node.set_Body((BlockStatement)this.Visit(node.get_Body()));
     return(node);
 }
Beispiel #5
0
 public virtual void VisitForEachStatement(ForEachStatement node)
 {
     this.Visit(node.get_Variable());
     this.Visit(node.get_Collection());
     this.Visit(node.get_Body());
     return;
 }
Beispiel #6
0
        public override void VisitForEachStatement(ForEachStatement node)
        {
            Append("foreach (var ");
            node.Identifier.Accept(this);
            Append(" in ");
            node.Expression.Accept(this);
            Append(")");
            NewLine();
            Append("{");
            Indent();
            NewLine();

            if (node.Statement is Block)
            {
                node.Statement.Accept(this);
            }
            else
            {
                var block = new Block(node.Statement);
                block.Accept(this);
            }

            Outdent();
            Append("}");
        }
        private void GenerateForeachStatement()
        {
            if (foreachVariable == null)
            {
                foreachVariable = new VariableDefinition(foreachVariableType, this.methodContext.Method);
                foreachVariableInstructions.Clear();
                this.methodContext.VariablesToRename.Add(foreachVariable);
            }
            VariableDeclarationExpression vd = new VariableDeclarationExpression(foreachVariable, foreachVariableInstructions);

            Expression foreachCollectionExpression = foreachCollection.CloneAndAttachInstructions(foreachCollectionInstructions);

            if (foreachCollectionExpression is BaseReferenceExpression)
            {
                foreachCollectionExpression = new ThisReferenceExpression(this.methodContext.Method.DeclaringType, foreachCollectionExpression.UnderlyingSameMethodInstructions);
            }

            @foreach = new ForEachStatement(vd, foreachCollectionExpression, foreachBody, foreachConditionInstructions, theTry.Finally.UnderlyingSameMethodInstructions);
            GetCurrentFixer gcf = new GetCurrentFixer(theEnumerator, foreachVariable);

            gcf.Visit(@foreach);

            IsEnumeratorUsedVisitor enumeratorUsedVisitor = new IsEnumeratorUsedVisitor(theEnumerator);

            enumeratorUsedVisitor.Visit(@foreach);
            isEnumeratorUsedInsideForEach = enumeratorUsedVisitor.IsEnumeratorUsed;
        }
Beispiel #8
0
        /// <summary>
        /// Factory method for class <see cref="ForEachStatementASTWalker"/>.
        /// </summary>
        /// <param name="node"><see cref="CSharpSyntaxNode"/> Used to initialize the walker.</param>
        /// <param name="semanticModel">The semantic model.</param>
        /// <returns></returns>
        public static ForEachStatementASTWalker Create(CSharpSyntaxNode node, SemanticModel semanticModel = null)
        {
            ForEachStatement helper = new ForEachStatement(node as ForEachStatementSyntax);

            var statement = ForEachStatementTranslationUnit.Create();

            return(new ForEachStatementASTWalker(node, statement, semanticModel));
        }
 public ForEachExpressionInterpreter(ExpressionInterpreterHandler expressionInterpreterHandler, ForEachStatement forEachStatement, System.Collections.Generic.List <ParameterExpression> scopedLocalVariable, LabelTarget brk, LabelTarget cont)
 {
     this.expressionInterpreterHandler = expressionInterpreterHandler;
     this.forEachStatement             = forEachStatement;
     this.scopedLocalVariable          = scopedLocalVariable;
     this.brk  = brk;
     this.cont = cont;
 }
 public override ICodeNode VisitForEachStatement(ForEachStatement node)
 {
     codeNodeTypes.Push(CodeNodeType.BinaryExpression);
     node.Variable = (VariableDeclarationExpression)Visit(node.Variable);
     codeNodeTypes.Pop();
     node.Collection = (Telerik.JustDecompiler.Ast.Expressions.Expression)Visit(node.Collection);
     node.Body       = (BlockStatement)Visit(node.Body);
     return(node);
 }
 public override ICodeNode VisitForEachStatement(ForEachStatement node)
 {
     this.codeNodeTypes.Push(24);
     node.set_Variable((VariableDeclarationExpression)this.Visit(node.get_Variable()));
     dummyVar0 = this.codeNodeTypes.Pop();
     node.set_Collection((Expression)this.Visit(node.get_Collection()));
     node.set_Body((BlockStatement)this.Visit(node.get_Body()));
     return(node);
 }
Beispiel #12
0
 public object VisitForEachStatement(ForEachStatement s, object context)
 {
     StringBuilder.Append("foreach (var ");
     StringBuilder.Append(s.Variable.Content);
     StringBuilder.Append(" : ");
     s.Collection.AcceptVisitor(this, context);
     StringBuilder.Append(") ");
     s.Body.AcceptVisitor(this, context);
     return(null);
 }
 public override void VisitForEachStatement(ForEachStatement node)
 {
     expressions.Push(ExpressionKind.ForEachVariable);
     Visit(node.Variable);
     expressions.Pop();
     expressions.Push(ExpressionKind.ForEachExpression);
     Visit(node.Collection);
     expressions.Pop();
     ClearPendingForSuggestion();
     Visit(node.Body);
 }
Beispiel #14
0
        protected override void VisitForEachStatement(ForEachStatement tree)
        {
            _TrySetResult(tree);
            if (_result != null)
            {
                return;
            }

            VisitAnySyntaxTree(tree.exp);
            VisitAnySyntaxTree(tree.block);
        }
 public override void VisitForEachStatement(ForEachStatement node)
 {
     this.expressions.Push(2);
     this.Visit(node.get_Variable());
     dummyVar0 = this.expressions.Pop();
     this.expressions.Push(3);
     this.Visit(node.get_Collection());
     dummyVar1 = this.expressions.Pop();
     this.ClearPendingForSuggestion();
     this.Visit(node.get_Body());
     return;
 }
Beispiel #16
0
        protected override object VisitForEachStatement(ForEachStatementSyntax node)
        {
            var collection = InternalVisitExpression(node.Expression);

#if ROSLYN
            var info1 = ModelExtensions.GetDeclaredSymbol(context.RoslynModel, node);
            var info  = info1 as ILocalSymbol;
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            var rosType          = context.Roslyn_ResolveType(info.Type);
            var loopVariableType = new LangType(rosType);
            var loopVariableName = info.Name;
#else
            var type = _VisitExpression(node.Type);
            if (type is UnknownIdentifierValue)
            {
                var xx = type as UnknownIdentifierValue;
                if (xx.Identifier == "var")
                {
                    var et = TypesUtil.GetEnumerateItemType(collection.ValueType);
                    type = new TypeValue(et);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            Debug.Assert(type is TypeValue);
            Debug.Assert((type as TypeValue).DotnetType == rosType);
            var loopVariableType = new LangType((type as TypeValue).DotnetType);
            var loopVariableName = _Name(node.Identifier);
#endif

            var ps = new VariableDeclaration(
                loopVariableType,
                new[]
            {
                new VariableDeclarator(loopVariableName, null, null)
            }
                );
            return(context.DoWithLocalVariables(ps,
                                                () =>
            {
                var stat = Visit(node.Statement);
                Debug.Assert(stat is IStatement);
                var g = new ForEachStatement(loopVariableType, loopVariableName, collection, stat as IStatement);
                return g;
            }));
        }
Beispiel #17
0
        /// <summary>
        /// Visits the specified for each statement.
        /// </summary>
        /// <param name="forEachStatement">For each statement.</param>
        public override void Visit(ForEachStatement forEachStatement)
        {
            WriteLinkLine(forEachStatement);

            if (forEachStatement.Variable == null)
            {
                localVariableCount++;

                Identifier parameterType;
                Identifier parameterMember;
                if (!TryParameters(forEachStatement.Collection, out parameterType, out parameterMember))
                {
                    Write(@"#error ""Unexpected parameter for 'foreach params' [");
                    VisitDynamic(forEachStatement.Collection);
                    WriteLine(@"]. Expecting single property access""");
                    return;
                }

                string variable = "____" + localVariableCount;
                Write("foreach(").Write("var ").Write(variable).Write(" in ");
                VisitDynamic(forEachStatement.Collection);
                WriteLine(")");

                var statement = forEachStatement.Body as BlockStatement;
                if (statement == null)
                {
                    statement = new BlockStatement {
                        Span = forEachStatement.Body.Span
                    };
                    statement.Statements.Add(forEachStatement.Body);
                }
                AddPushPopParameters(statement, parameterType, parameterMember, new VariableReferenceExpression(variable), forEachStatement.Span);

                VisitDynamic(statement);

                localVariableCount--;
            }
            else
            {
                Write("foreach(");
                IsVisitingVariableInlines = true;
                VisitDynamic(forEachStatement.Variable);
                IsVisitingVariableInlines = false;
                Write(" in ");
                VisitDynamic(forEachStatement.Collection);
                Write(")");
                WriteLine();
                VisitDynamic(forEachStatement.Body);
            }
        }
Beispiel #18
0
 public override void VisitForEachStatement(ForEachStatement node)
 {
     WriteKeyword("foreach");
     WriteSpace();
     WriteToken("(");
     Visit(node.Variable);
     WriteSpace();
     WriteKeyword("in");
     WriteSpace();
     Visit(node.Expression);
     WriteToken(")");
     WriteLine();
     Visit(node.Body);
 }
 private void ClearState()
 {
     insideTry = false;
     foundEnumeratorAssignment = false;
     foundWhile        = false;
     foreachCollection = null;
     foreachVariable   = null;
     foreachVariableInstructions.Clear();
     foreachCollectionInstructions.Clear();
     foreachBody   = new BlockStatement();
     theEnumerator = null;
     theTry        = null;
     @foreach      = null;
     enumeratorAssignmentStatement = null;
     foreachVariableType           = null;
     isEnumeratorUsedInsideForEach = false;
     foreachConditionInstructions  = null;
 }
Beispiel #20
0
 public virtual T Visit(ForEachStatement stmt) => Visit(stmt as Statement);
Beispiel #21
0
 private Statement ParseForEach(TokenSet followers)
   //^ requires this.currentToken == Token.Foreach;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   this.GetNextToken();
   this.Skip(Token.LeftParenthesis);
   TypeExpression variableType = this.ParseTypeExpression(false, false, followers|Parser.IdentifierOrNonReservedKeyword|Token.In|Token.RightParenthesis);
   if (this.currentToken == Token.In)
     this.HandleError(Error.BadForeachDecl);
   NameDeclaration variableName = this.ParseNameDeclaration();
   this.Skip(Token.In);
   Expression collection = this.ParseExpression(followers|Token.RightParenthesis);
   this.Skip(Token.RightParenthesis);
   Statement body = this.ParseStatement(followers);
   slb.UpdateToSpan(body.SourceLocation);
   ForEachStatement result = new ForEachStatement(variableType, variableName, collection, body, slb);
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
Beispiel #22
0
 public virtual void VisitForEachStatement(ForEachStatement node)
 {
     Visit(node.Variable);
     Visit(node.Collection);
     Visit(node.Body);
 }
Beispiel #23
0
 private Statement ParseForEach(SourceLocationBuilder slb, TokenSet followers)
   //^ requires this.currentToken == Token.Each;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   this.GetNextToken();
   NameDeclaration variableName = this.ParseNameDeclaration();
   this.Skip(Token.In);
   Expression collection = this.ParseExpression(followers|Token.EndOfLine);
   this.Skip(Token.EndOfLine);
   BlockStatement body = this.ParseStatementBlock(followers|Token.Next);
   slb.UpdateToSpan(body.SourceLocation);
   TypeExpression variableType = new NamedTypeExpression(new SimpleName(this.nameTable.GetNameFor("var"), SourceDummy.SourceLocation, false));
   ForEachStatement result = new ForEachStatement(variableType, variableName, collection, body, slb);
   this.SkipClosingKeyword(Token.Next, followers);
   return result;
 }
 /**
  * Call back method that must be called as soon as the given <code>
  * ForEachStatement</code> object has been traversed.
  *
  * @param pForEachStatement  The <code>ForEachStatement</code> object that
  *                           has just been traversed.
  */
 public void actionPerformed(
      ForEachStatement pForEachStatement)
 {
     // Nothing to do.
 }
Beispiel #25
0
        private void AddArrayField(ClassDeclaration c, FieldInfo f)
        {
            // create a collection
            ClassDeclaration col = c.AddClass(conformer.ToSingular(f.Name) + "Collection");

            col.Parent = new TypeTypeDeclaration(typeof(System.Collections.CollectionBase));

            // add serializable attribute
            col.CustomAttributes.Add(typeof(SerializableAttribute));

            // default constructor
            col.AddConstructor();
            // default indexer
            IndexerDeclaration index = col.AddIndexer(
                typeof(Object)
                );
            ParameterDeclaration pindex = index.Signature.Parameters.Add(typeof(int), "index", false);

            // getter
            index.Get.Return(
                Expr.This.Prop("List").Item(Expr.Arg(pindex))
                );
            index.Set.AddAssign(
                Expr.This.Prop("List").Item(Expr.Arg(pindex)),
                Expr.Value
                );

            // add object method
            MethodDeclaration    addObject  = col.AddMethod("Add");
            ParameterDeclaration paraObject = addObject.Signature.Parameters.Add(new TypeTypeDeclaration(typeof(Object)), "o", true);

            addObject.Body.Add(
                Expr.This.Prop("List").Method("Add").Invoke(paraObject)
                );

            // if typed array add methods for type
            if (f.FieldType.GetElementType() != typeof(Object))
            {
                AddCollectionMethods(
                    col,
                    MapType(f.FieldType.GetElementType()),
                    this.conformer.ToCapitalized(f.FieldType.GetElementType().Name),
                    "o"
                    );
            }

            foreach (XmlElementAttribute ea in f.GetCustomAttributes(typeof(XmlElementAttribute), true))
            {
                string name  = this.conformer.ToCapitalized(ea.ElementName);
                string pname = this.conformer.ToCamel(name);

                ITypeDeclaration mappedType = null;
                if (ea.Type != null)
                {
                    mappedType = MapType(ea.Type);
                }

                if (mappedType == null || mappedType == f.FieldType.GetElementType())
                {
                    continue;
                }

                AddCollectionMethods(col, mappedType, name, pname);
            }

            // add field
            FieldDeclaration fd = c.AddField(col, f.Name);

            fd.InitExpression = Expr.New(col);
            PropertyDeclaration p = c.AddProperty(fd, f.Name, true, true, false);

            // setting attributes
            // attach xml text
            if (TypeHelper.HasCustomAttribute(f, typeof(XmlTextAttribute)))
            {
                AttributeDeclaration attr = p.CustomAttributes.Add(typeof(XmlTextAttribute));

                attr.Arguments.Add("Type", Expr.TypeOf(typeof(string)));

                // adding to string to collection
                MethodDeclaration tostring = col.AddMethod("ToString");
                tostring.Signature.ReturnType = new TypeTypeDeclaration(typeof(String));
                tostring.Attributes           = MemberAttributes.Public | MemberAttributes.Override;

                VariableDeclarationStatement sw = Stm.Var(typeof(StringWriter), "sw");
                sw.InitExpression = Expr.New(typeof(StringWriter));
                tostring.Body.Add(sw);
                ForEachStatement fe = Stm.ForEach(
                    typeof(string), "s", Expr.This.Prop("List"), false);

                fe.Body.Add(
                    Expr.Var(sw).Method("Write").Invoke(fe.Local)
                    );

                tostring.Body.Add(fe);
                tostring.Body.Return(Expr.Var(sw).Method("ToString").Invoke());
            }
            else if (TypeHelper.HasCustomAttribute(f, typeof(XmlArrayItemAttribute)))
            {
                // add xml array attribute
                AttributeDeclaration attr = p.CustomAttributes.Add(typeof(XmlArrayAttribute));
                attr.Arguments.Add("ElementName", Expr.Prim(f.Name));

                // add array item attribute
                XmlArrayItemAttribute arrayItem =
                    (XmlArrayItemAttribute)TypeHelper.GetFirstCustomAttribute(f, typeof(XmlArrayItemAttribute));

                attr = p.CustomAttributes.Add(typeof(XmlArrayItemAttribute));
                attr.Arguments.Add("ElementName", Expr.Prim(arrayItem.ElementName));
                //MMI:attr.Arguments.Add("Type",Expr.Prim(MapType(f.FieldType.GetElementType()).Name));
                attr.Arguments.Add("Type", Expr.TypeOf(MapType(f.FieldType.GetElementType())));

                if (arrayItem.Type != null)
                {
                    attr.Arguments.Add("DataType", Expr.Prim(arrayItem.DataType));
                }
                attr.Arguments.Add("IsNullable", Expr.Prim(arrayItem.IsNullable));
                if (this.Config.KeepNamespaces)
                {
                    attr.Arguments.Add("Namespace", Expr.Prim(arrayItem.Namespace));
                }
            }
            else
            {
                AttachXmlElementAttributes(p, f);
            }
        }
        /// <summary>
        /// Creates a ForStatement with the same behavior
        /// </summary>
        /// <param name="forEachStatement">the ForEachStatement</param>
        /// <returns>the ForStatement</returns>
        private static ForStatement ExpandForEachStatement(ForEachStatement forEachStatement)
        {
            if (forEachStatement != null)
            {
                var collec = forEachStatement.Collection.TypeInference.Declaration as Variable;
                LiteralExpression dimLit = null;
                if (collec.Type is ArrayType)
                {
                    if ((collec.Type as ArrayType).Dimensions.Count == 1)
                    {
                        dimLit = (collec.Type as ArrayType).Dimensions[0] as LiteralExpression;
                    }
                }

                if (dimLit != null)
                {
                    var initializer = new Variable(ScalarType.Int, forEachStatement.Variable.Name.Text + "Iter", new LiteralExpression(0));
                    var vre = new VariableReferenceExpression(initializer.Name);
                    var condition = new BinaryExpression(BinaryOperator.Less, vre, dimLit);
                    var next = new UnaryExpression(UnaryOperator.PreIncrement, vre);
                    ForStatement forStatement = new ForStatement(new DeclarationStatement(initializer), condition, next);
                    var body = new BlockStatement();

                    var variable = forEachStatement.Variable;
                    variable.InitialValue = new IndexerExpression(forEachStatement.Collection, new VariableReferenceExpression(initializer));
                    body.Statements.Add(new DeclarationStatement(variable));

                    if (forEachStatement.Body is BlockStatement)
                        body.Statements.AddRange((forEachStatement.Body as BlockStatement).Statements);
                    else
                        body.Statements.Add(forEachStatement.Body);

                    forStatement.Body = body;

                    return forStatement;
                }

                // TODO: multidimension-array?
                // TODO: unroll?
                // TODO: multiple foreach?
            }
            return null;
        }
 /**
  * Call back method that must be called when the given <code>
  * ForEachStatement</code> will become the next <i>traverse candidate</i>.
  *
  * @param pForEachStatement  The <code>ForEachStatement</code> object that
  *                           will become the next <i>traverse candidate</i>.
  */
 public void performAction(
      ForEachStatement pForEachStatement)
 {
     // Nothing to do.
 }
        private void Process_ForEach_Statement(StringBuilder sb, ForEachStatement statement)
        {
            sb.Append("foreach(");

            // Variable
            Process_Local_Variable_Declaration(sb, statement.VariableDeclaration as LocalVariableDeclaration);
            sb.Append(" in ");

            sb.Append(FormatExpression(statement.Expression));

            sb.Append(") ");

            sb.Append(ProcessStatement(statement.Statement));
        }
Beispiel #29
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public virtual void VisitForEachStatement(ForEachStatement statement)
        {
            VisitAbstractStatement(statement);
        }
Beispiel #30
0
 public virtual ForEachStatement RewriteForEachStatement(ForEachStatement statement)
 {
     return(statement);
 }
        /// <summary>
        /// Visits the specified for each statement.
        /// </summary>
        /// <param name="forEachStatement">For each statement.</param>
        public override void Visit(ForEachStatement forEachStatement)
        {
            WriteLinkLine(forEachStatement);

            if (forEachStatement.Variable == null)
            {
                localVariableCount++;

                Identifier parameterType;
                Identifier parameterMember;
                if (!TryParameters(forEachStatement.Collection, out parameterType, out parameterMember))
                {
                    Write(@"#error ""Unexpected parameter for 'foreach params' [");
                    VisitDynamic(forEachStatement.Collection);
                    WriteLine(@"]. Expecting single property access""");
                    return;
                }

                string variable = "____" + localVariableCount;
                Write("foreach(").Write("var ").Write(variable).Write(" in ");
                VisitDynamic(forEachStatement.Collection);
                WriteLine(")");

                var statement = forEachStatement.Body as BlockStatement;
                if (statement == null)
                {
                    statement = new BlockStatement {Span = forEachStatement.Body.Span};
                    statement.Statements.Add(forEachStatement.Body);
                }
                AddPushPopParameters(statement, parameterType, parameterMember, new VariableReferenceExpression(variable), forEachStatement.Span);

                VisitDynamic(statement);

                localVariableCount--;
            }
            else
            {
                Write("foreach(");
                IsVisitingVariableInlines = true;
                VisitDynamic(forEachStatement.Variable);
                IsVisitingVariableInlines = false;
                Write(" in ");
                VisitDynamic(forEachStatement.Collection);
                Write(")");
                WriteLine();
                VisitDynamic(forEachStatement.Body);
            }
        }
Beispiel #32
0
 protected abstract void VisitForEachStatement(ForEachStatement tree);
        public ClassDeclaration AddClass(NamespaceDeclaration ns)
        {
            ClassDeclaration col = ns.AddClass(this.CollectionName);

            // set base class as CollectionBase
            col.Parent = new TypeTypeDeclaration(typeof(CollectionBase));

            // default constructor
            col.AddConstructor();

            // add indexer
            if (this.ItemGet || this.ItemSet)
            {
                IndexerDeclaration index = col.AddIndexer(
                    this.Type
                    );
                ParameterDeclaration pindex = index.Signature.Parameters.Add(typeof(int), "index", false);

                // get body
                if (this.ItemGet)
                {
                    index.Get.Return(
                        (Expr.This.Prop("List").Item(Expr.Arg(pindex)).Cast(this.Type)
                        )
                        );
                }
                // set body
                if (this.ItemSet)
                {
                    index.Set.Add(
                        Stm.Assign(
                            Expr.This.Prop("List").Item(Expr.Arg(pindex)),
                            Expr.Value
                            )
                        );
                }
            }

            string pname = ns.Conformer.ToCamel(this.Type.Name);

            // add method
            if (this.Add)
            {
                MethodDeclaration    add  = col.AddMethod("Add");
                ParameterDeclaration para = add.Signature.Parameters.Add(this.Type, pname, true);
                add.Body.Add(
                    Expr.This.Prop("List").Method("Add").Invoke(para)
                    );
            }

            if (this.AddRange)
            {
                MethodDeclaration    add  = col.AddMethod("AddRange");
                ParameterDeclaration para = add.Signature.Parameters.Add(col, pname, true);

                ForEachStatement fe = Stm.ForEach(
                    this.Type,
                    "item",
                    Expr.Arg(para),
                    false
                    );
                fe.Body.Add(
                    Expr.This.Prop("List").Method("Add").Invoke(fe.Local)
                    );

                add.Body.Add(fe);
            }

            // contains method
            if (this.Contains)
            {
                MethodDeclaration contains = col.AddMethod("Contains");
                contains.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool));
                ParameterDeclaration para = contains.Signature.Parameters.Add(this.Type, pname, true);
                contains.Body.Return(
                    Expr.This.Prop("List").Method("Contains").Invoke(para)
                    );
            }

            // remove method
            if (this.Remove)
            {
                MethodDeclaration    remove = col.AddMethod("Remove");
                ParameterDeclaration para   = remove.Signature.Parameters.Add(this.Type, pname, true);

                remove.Doc.Summary.AddText("Removes the first occurrence of a specific ParameterDeclaration from this ParameterDeclarationCollection.");

                remove.Body.Add(
                    Expr.This.Prop("List").Method("Remove").Invoke(para)
                    );
            }

            // insert
            if (this.Insert)
            {
                MethodDeclaration    insert = col.AddMethod("Insert");
                ParameterDeclaration index  = insert.Signature.Parameters.Add(typeof(int), "index", true);
                ParameterDeclaration para   = insert.Signature.Parameters.Add(this.Type, pname, true);
                insert.Body.Add(
                    Expr.This.Prop("List").Method("Insert").Invoke(index, para)
                    );
            }

            // indexof
            if (this.IndexOf)
            {
                MethodDeclaration    indexof = col.AddMethod("IndexOf");
                ParameterDeclaration para    = indexof.Signature.Parameters.Add(this.Type, pname, true);
                indexof.Signature.ReturnType = new TypeTypeDeclaration(typeof(int));
                indexof.Body.Return(
                    Expr.This.Prop("List").Method("IndexOf").Invoke(para)
                    );
            }

            if (this.Enumerator)
            {
                // create subclass
                ClassDeclaration en = col.AddClass("Enumerator");
                // add wrapped field
                FieldDeclaration wrapped = en.AddField(
                    typeof(IEnumerator), "wrapped"
                    );
                // add IEnumerator
                en.Interfaces.Add(typeof(IEnumerator));

                // add constructor
                ConstructorDeclaration cs         = en.AddConstructor();
                ParameterDeclaration   collection = cs.Signature.Parameters.Add(col, "collection", true);
                cs.Body.Add(
                    Stm.Assign(
                        Expr.This.Field(wrapped),
                        Expr.Arg(collection).Cast(typeof(CollectionBase)).Method("GetEnumerator").Invoke()
                        )
                    );

                // add current
                PropertyDeclaration current = en.AddProperty(this.Type, "Current");
                current.Get.Return(
                    (Expr.This.Field(wrapped).Prop("Current")).Cast(this.Type)
                    );

                // add explicit interface implementation
                PropertyDeclaration currentEn = en.AddProperty(typeof(Object), "Current");
                currentEn.Get.Return(Expr.This.Prop(current));
                currentEn.PrivateImplementationType = wrapped.Type;

                // add reset
                MethodDeclaration reset = en.AddMethod("Reset");
                reset.ImplementationTypes.Add(wrapped.Type);
                reset.Body.Add(Expr.This.Field(wrapped).Method("Reset").Invoke());

                // add movenext
                MethodDeclaration movenext = en.AddMethod("MoveNext");
                movenext.ImplementationTypes.Add(wrapped.Type);
                movenext.Signature.ReturnType = new TypeTypeDeclaration(typeof(bool));
                movenext.Body.Return(Expr.This.Field(wrapped).Method("MoveNext").Invoke());

                // add get enuemrator
                MethodDeclaration geten = col.AddMethod("GetEnumerator");
                geten.Attributes |= MemberAttributes.New;
                geten.ImplementationTypes.Add(new TypeTypeDeclaration(typeof(IEnumerable)));
                geten.Signature.ReturnType = en;
                geten.Body.Return(Expr.New(en, Expr.This));
            }

            return(col);
        }
        /// <summary>
        /// Visits the ForEachStatement Node and collects information from it.
        /// </summary>
        /// <param name="forEachStatement">The ForEachStatement</param>
        public override Node Visit(ForEachStatement forEachStatement)
        {
            if (expandForEachStatements)
            {
                // run analysis on collection
                VisitDynamic(forEachStatement.Collection);

                var inference = forEachStatement.Collection.TypeInference.Declaration as Variable;
                if (!(inference != null && inference.Type is ArrayType))
                    return forEachStatement;

                if ((inference.Type as ArrayType).Dimensions.Count > 1)
                {
                    Error(XenkoMessageCode.ErrorMultiDimArray, forEachStatement.Span, inference, forEachStatement, analyzedModuleMixin.MixinName);
                    return forEachStatement;
                }

                var dim = (int)((inference.Type as ArrayType).Dimensions.FirstOrDefault() as LiteralExpression).Value;

                var result = new StatementList();
                for (int i = 0; i < dim; ++i)
                {
                    var cloned = forEachStatement.DeepClone();
                    var replace = new XenkoReplaceExtern(cloned.Variable, new IndexerExpression(cloned.Collection, new LiteralExpression(i)));
                    replace.Run(cloned.Body);
                    result.Add(cloned.Body);
                }

                VisitDynamic(result);
                return result;
            }
            else
            {
                base.Visit(forEachStatement);
                parsingInfo.ForEachStatements.Add(new StatementNodeCouple(forEachStatement, ParentNode));
                return forEachStatement;
            }
        }
 public YieldStateMachineCodeRemover(ForEachStatement @foreach, VariableReference enumeratorVariable)
 {
     this.@foreach           = @foreach;
     this.enumeratorVariable = enumeratorVariable;
 }
 public override ICodeNode VisitForEachStatement(ForEachStatement node)
 {
     node.set_Collection((Expression)this.Visit(node.get_Collection()));
     return(node);
 }
 public override void VisitForEachStatement(ForEachStatement node)
 {
     return;
 }
 public override void VisitForEachStatement(ForEachStatement node)
 {
     this.Visit(node.get_Collection());
     return;
 }