public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args, InvocationExpressionSyntax invocation) { design.Variables.Where(variable => !variable.IsGlobal).ForEach(variable => variable.IsUsed = false); var access = (MemberAccessExpressionSyntax)invocation.Expression; var name = (GenericNameSyntax)access.Name; var type = name.TypeArgumentList.Arguments[0]; if (design.RewriteChain.Count == 1) { design.NotRewrite = true; return; } design.FirstCollection = design.CurrentCollection = null; design.AddIterator(); design.CurrentIterator.IgnoreIterator = true; design.CurrentIterator.ForFrom = 0; design.CurrentIterator.ForTo = 0; design.CurrentIterator.ForIndexer = CreateLocalVariable(design, Int, 0); design.ResultSize = 0; design.SourceSize = 0; design.ListEnumeration = false; design.SimpleEnumeration = true; if (design.CurrentIndexer == null) { design.CurrentIterator.Indexer = design.CurrentIterator.ForIndexer; design.CurrentIterator.Indexer.IsGlobal = true; } design.LastValue = new TypedValueBridge(type, Default(type)); design.CurrentCollection = null; }
public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args) { design.Variables.Where(variable => !variable.IsGlobal).ForEach(variable => variable.IsUsed = false); var itemValue = args[0]; var countValue = args[1]; if (!AssertGreaterEqual(design, countValue, 0)) { return; } design.AddIterator(); design.CurrentIterator.ForFrom = 0; design.CurrentIterator.ForTo = countValue - 1; design.CurrentIterator.ForIndexer = CreateLocalVariable(design, Int); design.ResultSize = countValue; design.SourceSize = countValue; design.ListEnumeration = false; design.SimpleEnumeration = true; if (design.CurrentIndexer == null) { design.CurrentIterator.Indexer = design.CurrentIterator.ForIndexer; design.CurrentIterator.Indexer.IsGlobal = true; } design.LastValue = new TypedValueBridge(itemValue.GetType(design), itemValue); design.FirstCollection = design.CurrentCollection = null; }
private static void UnknownSourceSize(RewriteDesign design) { design.Indexer = null; var reverseIndexerVariable = CreateGlobalVariable(design, Int, 8); var currentLengthVariable = CreateGlobalVariable(design, Int, 8); var resultVariable = CreateGlobalVariable(design, design.LastValue.ArrayType(), CreateArray(design.LastValue.ArrayType(), 8)); var sizeVariable = CreateGlobalVariable(design, Int); design.ForAdd(reverseIndexerVariable.PreDecrement()); design.ForAdd(If(reverseIndexerVariable < 0, Block( sizeVariable.Assign(currentLengthVariable), "LinqRewrite".Access("Core", "EnlargeExtensions", "LogEnlargeReverseArray") .Invoke(2, RefArg(resultVariable), RefArg(currentLengthVariable)), reverseIndexerVariable.Assign(currentLengthVariable - sizeVariable - 1)))); design.ForAdd(resultVariable[reverseIndexerVariable].Assign(design.LastValue)); design.Indexer = null; design.Iterators.All.ForEach(x => x.Complete = true); design.AddIterator(new CollectionValueBridge(design, resultVariable.Type, design.LastValue.Type, resultVariable, true)); design.CurrentCollection = design.CurrentIterator.Collection; RewriteCollectionEnumeration.RewriteOther(design, design.CurrentCollection); design.ResultSize = design.SourceSize = currentLengthVariable - reverseIndexerVariable; design.CurrentIterator.ForFrom = reverseIndexerVariable; design.CurrentIterator.ForTo = currentLengthVariable - 1; design.Indexer = null; }
public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args, bool?reuseVariables = null) { if (!AssertNotNull(design, design.CurrentCollection)) { return; } design.AddIterator(design.CurrentCollection); RewriteOther(design, design.CurrentCollection, null, false, reuseVariables); }
public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args) { var sourceSizeValue = design.SourceSize; var resultSizeValue = design.ResultSize; var collectionValue = args[0]; if (!AssertNotNull(design, collectionValue)) { return; } LocalVariable itemVariable; var lastVariable = TryGetVariable(design, design.LastValue); if (lastVariable != null) { itemVariable = lastVariable; } else { itemVariable = CreateGlobalVariable(design, design.LastValue.Type); design.ForAdd(itemVariable.Assign(design.LastValue)); design.LastValue = new TypedValueBridge(design.LastValue.Type, itemVariable); } itemVariable.IsGlobal = true; var collectionType = design.Data.GetTypeInfo(collectionValue).Type; design.AddIterator(new CollectionValueBridge(design, collectionType, collectionValue, true)); RewriteCollectionEnumeration.RewriteOther(design, design.CurrentIterator.Collection, itemVariable, true); design.ListEnumeration = design.IncompleteIterators.All(x => x.ListEnumeration); if (sourceSizeValue != null && design.SourceSize != null) { design.SourceSize += sourceSizeValue; } else { design.SourceSize = null; } if (resultSizeValue != null && design.ResultSize != null) { design.ResultSize += resultSizeValue; } else { design.ResultSize = null; } (design.ModifiedEnumeration, design.ResultSize) = (true, design.ResultSize); }