/// <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; } }