protected override void AppendMessageHeaderCore( ILGenerator generator, ForEachLoop loop, MessageField field) { LocalBuilder length = generator.DeclareLocal(typeof(int)); loop.Create(body => { body.Emit(OpCodes.Ldarg_1); loop.LoadCurrentAs(FieldType); field.AppendFieldLength(generator); body.Emit(OpCodes.Ldloc, length.LocalIndex); body.Emit(OpCodes.Add); body.Emit(OpCodes.Stloc, length.LocalIndex); }); generator.Emit(OpCodes.Ldloc, length.LocalIndex); Label done = generator.DefineLabel(); generator.Emit(OpCodes.Brfalse, done); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Ldc_I4, MessageTag.AsInt(field.Number, WireType.String)); generator.Call <MessageWriter>("WriteVarint", typeof(uint)); generator.Emit(OpCodes.Ldloc, length.LocalIndex); generator.Call <MessageWriter>("WriteVarint", typeof(uint)).Pop(); generator.MarkLabel(done); }
public ExecutableNodeFactory(Executable executable, Executables collection) { _collection = collection; _executable = (DtsContainer)executable; _host = _executable as TaskHost; _seq = _executable as Sequence; _foreachloop = _executable as ForEachLoop; _forloop = _executable as ForLoop; _psExecutable = PSObject.AsPSObject(_executable); if (null != _host) { _psExecutable.Properties.Add(new PSNoteProperty("IsTaskHost", true)); _mainPipe = _host.InnerObject as MainPipe; } if (null != _mainPipe) { _psExecutable.Properties.Add(new PSNoteProperty("IsDataFlow", true)); } if (null != _seq) { _psExecutable.Properties.Add(new PSNoteProperty("IsSequence", true)); } if (null != _foreachloop) { _psExecutable.Properties.Add(new PSNoteProperty("IsForEachLoop", true)); } if (null != _forloop) { _psExecutable.Properties.Add(new PSNoteProperty("IsForLoop", true)); } }
public ExecutableNodeFactory(Executable executable,Executables collection) { _collection = collection; _executable = (DtsContainer)executable; _host = _executable as TaskHost; _seq = _executable as Sequence; _foreachloop = _executable as ForEachLoop; _forloop = _executable as ForLoop; _psExecutable = PSObject.AsPSObject(_executable); if (null != _host) { _psExecutable.Properties.Add( new PSNoteProperty( "IsTaskHost", true )); _mainPipe = _host.InnerObject as MainPipe; } if (null != _mainPipe) { _psExecutable.Properties.Add(new PSNoteProperty("IsDataFlow", true)); } if (null != _seq) { _psExecutable.Properties.Add(new PSNoteProperty("IsSequence", true)); } if (null != _foreachloop) { _psExecutable.Properties.Add(new PSNoteProperty("IsForEachLoop", true)); } if (null != _forloop) { _psExecutable.Properties.Add(new PSNoteProperty("IsForLoop", true)); } }
private void CheckForEachLoop(ForEachLoop forEachLoop, TreeNode parent) { // Check properties of loop itself ScanProperties(forEachLoop, parent); // Check properties of enumerator, when present ForEachEnumeratorHost enumerator = forEachLoop.ForEachEnumerator; if (enumerator != null) { TreeNode enumeratorFolder = AddFolder(enumerator.GetType().Name, parent); ScanProperties(enumerator, enumeratorFolder); } // Check the (output) variable mappings TreeNode variableMappings = AddFolder("VariableMappings", parent); foreach (ForEachVariableMapping mapping in forEachLoop.VariableMappings) { string match; string value = mapping.VariableName; if (!string.IsNullOrEmpty(value) && PropertyMatchEval(value, out match)) { VariableFoundEventArgs info = new VariableFoundEventArgs(); info.Match = match; OnRaiseVariableFound(info); AddNode(variableMappings, mapping.ValueIndex.ToString(), GetImageIndex(IconKeyProperty), mapping, true); } } }
public Statement DecompileForEach(bool isDynArray = false) { PopByte(); var scopeStatements = new List <Statement>(); var iteratorFunc = DecompileExpression(); if (iteratorFunc == null) { return(null); } if (isDynArray) { Expression dynArrVar = DecompileExpression(); bool hasIndex = Convert.ToBoolean(ReadByte()); Expression dynArrIndex = DecompileExpression(); iteratorFunc = new DynArrayIterator(iteratorFunc, dynArrVar, dynArrIndex); } var scopeEnd = ReadUInt16(); // MemOff ForEachScopes.Push(scopeEnd); Scopes.Add(scopeStatements); CurrentScope.Push(Scopes.Count - 1); while (Position < Size) { if (CurrentIs(OpCodes.IteratorNext)) { PopByte(); // IteratorNext if (PeekByte == (byte)OpCodes.IteratorPop) { StatementLocations[(ushort)(Position - 1)] = new IteratorNext(); StatementLocations[(ushort)Position] = new IteratorPop(); PopByte(); // IteratorPop break; } Position--; } var current = DecompileStatement(); if (current == null) { return(null); // ERROR ? } scopeStatements.Add(current); } CurrentScope.Pop(); ForEachScopes.Pop(); var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements)) { iteratorPopPos = Position - 1 }; StatementLocations.Add(StartPositions.Pop(), statement); return(statement); }
public void Equality_Default() { var a = new ForEachLoop(); var b = new ForEachLoop(); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public void ShouldConvertForeachLoop() { var forEachLoop = new ForEachLoop(); string java = ReadSample("Sample10.java"); string csharp = forEachLoop.Apply(java); Assert.Equal(ReadSample("Sample10.csharp"), csharp, new StringCompIgnoreWhiteSpace()); }
public void Equality_DifferentDeclaration() { var a = new ForEachLoop { Declaration = SomeDeclaration() }; var b = new ForEachLoop(); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void Equality_DifferentLoopedReference() { var a = new ForEachLoop { LoopedReference = SomeVarRef("a") }; var b = new ForEachLoop(); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void DefaultValues() { var sut = new ForEachLoop(); Assert.AreEqual(new VariableDeclaration(), sut.Declaration); Assert.AreEqual(new VariableReference(), sut.LoopedReference); Assert.AreEqual(Lists.NewList <IStatement>(), sut.Body); Assert.AreNotEqual(0, sut.GetHashCode()); Assert.AreNotEqual(1, sut.GetHashCode()); }
public void Equality_DifferentBody() { var a = new ForEachLoop(); a.Body.Add(new ReturnStatement()); var b = new ForEachLoop(); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public override void AppendWrite(ILGenerator il, MessageField field) { var loop = new ForEachLoop(il, property); AppendMessageHeaderCore(il, loop, field); loop.Create(body => { field.AppendHeader(il); loop.LoadCurrentAs(FieldType); field.AppendWriteField(il); body.Emit(OpCodes.Pop); }); }
public void CompileForEachLoop(ForEachLoop forEach) { textWriter.Write("foreach ("); if (forEach.KeyName != ForEachLoop.DEFAULT_KEY_NAME) { textWriter.Write("{0} => ", SafeName(forEach.KeyName)); } textWriter.Write("{0} in ", SafeName(forEach.ValueName)); forEach.Enumerated.AcceptCompiler(this); textWriter.WriteLine(")"); MayBeIndent(forEach.Body); }
public override void AppendWrite(ILGenerator generator, MessageField field) { ForEachLoop loop = new ForEachLoop(generator, Property); AppendMessageHeaderCore(generator, loop, field); loop.Create(body => { field.AppendHeader(generator); loop.LoadCurrentAs(FieldType); field.AppendWriteField(generator); body.Emit(OpCodes.Pop); }); }
public static void Write(ForEachLoop forEachLoop, IndentedStreamWriter writer) { var forEachLoopHeadWriter = new ForEachLoopHeadWriter(writer, forEachLoop); forEachLoopHeadWriter.Make(); writer.OpenBrackets(); var forEachLoopBodyWriter = new ForEachLoopBodyWriter(writer, forEachLoop); forEachLoopBodyWriter.Make(); writer.CloseBrackets(); }
public bool VisitNode(ForEachLoop node) { // foreach IteratorFunction(parameters) { /n contents /n } Write($"{FOREACH} "); node.IteratorCall.AcceptVisitor(this); Write("{"); NestingLevel++; node.Body.AcceptVisitor(this); NestingLevel--; Write("}"); return(true); }
public void ChildrenIdentity() { var sut = new ForEachLoop { Declaration = SomeDeclaration(), LoopedReference = SomeVarRef("a"), Body = { new ReturnStatement() } }; AssertChildren(sut, sut.Declaration, sut.LoopedReference, sut.Body.First()); }
public static async Task WriteAsync(ForEachLoop forEachLoop, IndentedStreamWriter writer) { await writer.WriteLineAsync($"foreach ({forEachLoop.Item} in {forEachLoop.Collection})"); await writer.WriteLineAsync("{").ConfigureAwait(false); writer.IndentationLevel++; var bodyWriter = new BodyWriter(writer); forEachLoop.Body(bodyWriter); writer.IndentationLevel--; await writer.WriteLineAsync("}").ConfigureAwait(false); }
public void SettingValues() { var sut = new ForEachLoop { Declaration = SomeDeclaration(), LoopedReference = SomeVarRef("a"), Body = { new ReturnStatement() } }; Assert.AreEqual(SomeVarRef("a"), sut.LoopedReference); Assert.AreEqual(SomeDeclaration(), sut.Declaration); Assert.AreEqual(Lists.NewList(new ReturnStatement()), sut.Body); }
public void ForEachLoop() { var sst = new ForEachLoop { Declaration = SSTUtil.Declare("e", Names.Type("T,P")), LoopedReference = SSTUtil.VariableReference("elements"), Body = { new ContinueStatement() } }; AssertPrint( sst, "foreach (T e in elements)", "{", " continue;", "}"); }
public override void VisitForeachStatement(IForeachStatement stmt, IList <IStatement> body) { if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) { body.Add(EmptyCompletionExpression); } var loop = new ForEachLoop { LoopedReference = _exprVisitor.ToVariableRef(stmt.Collection, body) }; body.Add(loop); foreach (var itDecl in stmt.IteratorDeclarations) { var localVar = itDecl.DeclaredElement.GetName <ILocalVariableName>(); loop.Declaration = new VariableDeclaration { Reference = new VariableReference { Identifier = localVar.Name }, Type = localVar.ValueType }; } if (IsTargetMatch(stmt, CompletionCase.InBody)) { loop.Body.Add(EmptyCompletionExpression); } if (stmt.Body != null) { stmt.Body.Accept(this, loop.Body); } if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) { body.Add(EmptyCompletionExpression); } }
private void CheckProperties(IDTSPropertiesProvider propProvider, BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } if (propProvider is DtsContainer) { DtsContainer container = (DtsContainer)propProvider; string containerKey = PackageHelper.GetContainerKey(container); string objectTypeName = container.GetType().Name; if (container is TaskHost) { if (((TaskHost)container).InnerObject is MainPipe) { objectTypeName = typeof(MainPipe).Name; // Prevents it from saying COM Object } else { objectTypeName = ((TaskHost)container).InnerObject.GetType().Name; } ScanProperties(worker, path, typeof(TaskHost), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } else if (container is ForEachLoop) { ForEachLoop loop = container as ForEachLoop; ScanProperties(worker, path, typeof(ForEachLoop), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); ScanProperties(worker, path + "\\ForEachEnumerator.", typeof(ForEachEnumerator), objectTypeName, container.ID, loop.ForEachEnumerator.ID, container.Name, loop.ForEachEnumerator, containerKey); } else { ScanProperties(worker, path, container.GetType(), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } ScanVariables(worker, path, objectTypeName, container.ID, container.Variables); } }
public void CompileForEachLoop(ForEachLoop forEach) { XmlElement previousElement = currentElement; XmlElement tmpElement = document.CreateElement("ForEachLoop"); tmpElement.SetAttribute("ValueName", forEach.ValueName); if (forEach.KeyName != ForEachLoop.DEFAULT_KEY_NAME) { tmpElement.SetAttribute("KeyName", forEach.KeyName); } currentElement = document.CreateElement("Enumerated"); forEach.Enumerated.AcceptCompiler(this); tmpElement.AppendChild(currentElement); currentElement = document.CreateElement("Body"); forEach.Body.AcceptCompiler(this); tmpElement.AppendChild(currentElement); previousElement.AppendChild(tmpElement); currentElement = previousElement; }
public void Equality_ReallyTheSame() { var a = new ForEachLoop { LoopedReference = SomeVarRef("a"), Declaration = SomeDeclaration(), Body = { new ReturnStatement() } }; var b = new ForEachLoop { LoopedReference = SomeVarRef("a"), Declaration = SomeDeclaration(), Body = { new ReturnStatement() } }; Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
protected override void AppendMessageHeaderCore( ILGenerator generator, ForEachLoop loop, MessageField field) { LocalBuilder length = generator.DeclareLocal(typeof(int)); loop.Create(body => { body.Emit(OpCodes.Ldarg_1); loop.LoadCurrentAs(FieldType); field.AppendFieldLength(generator); body.Emit(OpCodes.Ldloc, length.LocalIndex); body.Emit(OpCodes.Add); body.Emit(OpCodes.Stloc, length.LocalIndex); }); generator.Emit(OpCodes.Ldloc, length.LocalIndex); Label done = generator.DefineLabel(); generator.Emit(OpCodes.Brfalse, done); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Ldc_I4, MessageTag.AsInt(field.Number, WireType.String)); generator.Call<MessageWriter>("WriteVarint", typeof(uint)); generator.Emit(OpCodes.Ldloc, length.LocalIndex); generator.Call<MessageWriter>("WriteVarint", typeof(uint)).Pop(); generator.MarkLabel(done); }
private void CheckProperties(IDTSPropertiesProvider propProvider, BackgroundWorker worker, string path) { if (worker.CancellationPending) { return; } if (propProvider is DtsContainer) { DtsContainer container = (DtsContainer)propProvider; string containerKey = PackageHelper.GetContainerKey(container); string objectTypeName = container.GetType().Name; TaskHost taskHost = container as TaskHost; if (taskHost != null) { objectTypeName = CheckTaskHost(taskHost, worker, path, container, containerKey); } else if (container is ForEachLoop) { ForEachLoop loop = container as ForEachLoop; ScanProperties(worker, path, typeof(ForEachLoop), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); if (loop.ForEachEnumerator != null) { // A For Each Loop that has not been configured yet will not have an enumerator, so ensure we check ScanProperties(worker, path + "\\ForEachEnumerator.", typeof(ForEachEnumerator), objectTypeName, container.ID, loop.ForEachEnumerator.ID, container.Name, loop.ForEachEnumerator, containerKey); } } else { ScanProperties(worker, path, container.GetType(), objectTypeName, container.ID, container.ID, container.Name, propProvider, containerKey); } ScanVariables(worker, path, objectTypeName, container.ID, container.Variables); } }
public ForEachLoopBodyWriter(IndentedStreamWriter writer, ForEachLoop forEachLoop) : base(writer) => _forEachLoop = forEachLoop;
void expressionListWindow_EditExpressionSelected(object sender, EditExpressionSelectedEventArgs e) { try { Package package = null; DtsContainer container = null; if (win == null) { return; } try { package = GetCurrentPackage(); if (package == null) { return; } } catch (Exception ex) { System.Diagnostics.Debug.Assert(false, ex.ToString()); return; } // Parameters for Expression Editor Variables variables = null; VariableDispenser variableDispenser = null; string propertyName = string.Empty; Type propertyType = null; // Target objects IDTSPropertiesProvider propertiesProvider = null; Variable variable = null; PrecedenceConstraint constraint = null; // Get the container container = SSISHelpers.FindContainer(package, e.ContainerID); // Get the property details and variable objects for the editor if (e.Type == typeof(Variable)) { variable = SSISHelpers.FindVariable(container, e.ObjectID); propertyName = "Value"; propertyType = System.Type.GetType("System." + variable.DataType.ToString()); variables = container.Variables; variableDispenser = container.VariableDispenser; } else if (e.Type == typeof(PrecedenceConstraint)) { constraint = SSISHelpers.FindConstraint(container, e.ObjectID); propertyName = "Expression"; propertyType = typeof(bool); variables = container.Variables; variableDispenser = container.VariableDispenser; } else { if (e.Type == typeof(ConnectionManager)) { propertiesProvider = SSISHelpers.FindConnectionManager(package, e.ObjectID) as IDTSPropertiesProvider; } else if (e.Type == typeof(ForEachEnumerator)) { ForEachLoop forEachLoop = container as ForEachLoop; propertiesProvider = forEachLoop.ForEachEnumerator as IDTSPropertiesProvider; } else { propertiesProvider = container as IDTSPropertiesProvider; } if (propertiesProvider != null) { DtsProperty property = propertiesProvider.Properties[e.Property]; propertyName = property.Name; propertyType = PackageHelper.GetTypeFromTypeCode(property.Type); variables = container.Variables; variableDispenser = container.VariableDispenser; } else { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Expression editing not supported on this object ({0}).", e.ObjectID)); } } // Show the editor Konesans.Dts.ExpressionEditor.ExpressionEditorPublic editor = new Konesans.Dts.ExpressionEditor.ExpressionEditorPublic(variables, variableDispenser, propertyType, propertyName, e.Expression); editor.Editor.ExpressionFont = ExpressionFont; editor.Editor.ExpressionColor = ExpressionColor; editor.Editor.ResultFont = ResultFont; editor.Editor.ResultColor = ResultColor; if (editor.ShowDialog() == DialogResult.OK) { // Get expression string expression = editor.Expression; if (expression == null || string.IsNullOrEmpty(expression.Trim())) { expression = null; } // Set the new expression on the target object object objectChanged = null; if (variable != null) { if (expression == null) { variable.EvaluateAsExpression = false; } variable.Expression = expression; objectChanged = variable; } else if (constraint != null) { if (expression == null) { constraint.EvalOp = DTSPrecedenceEvalOp.Constraint; } constraint.Expression = expression; objectChanged = constraint; } else if (propertiesProvider != null) { // TaskHost, Sequence, ForLoop, ForEachLoop and ConnectionManager propertiesProvider.SetExpression(e.Property, expression); objectChanged = propertiesProvider; } expressionListWindow_RefreshExpressions(null, null); // Finish displaying expressions list before you mark the package // as dirty (which runs the expression highlighter) System.Windows.Forms.Application.DoEvents(); SetPackageAsDirty(package, expression, objectChanged); } } catch (Exception ex) { throw ex; } }
protected virtual void AppendMessageHeaderCore(ILGenerator generator, ForEachLoop loop, MessageField field) { }
public static void Compile(ByteCodeCompiler bcc, ParserContext parser, ByteBuffer buffer, ForEachLoop forEachLoop) { bcc.CompileExpression(parser, buffer, forEachLoop.IterationExpression, true); buffer.Add( forEachLoop.IterationExpression.FirstToken, OpCode.VERIFY_TYPE_IS_ITERABLE, forEachLoop.ListLocalId.ID, forEachLoop.IndexLocalId.ID); ByteBuffer body = new ByteBuffer(); ByteBuffer body2 = new ByteBuffer(); bcc.Compile(parser, body2, forEachLoop.Code); body.Add( forEachLoop.FirstToken, OpCode.ITERATION_STEP, body2.Size + 1, forEachLoop.IterationVariableId.ID, forEachLoop.IndexLocalId.ID, forEachLoop.ListLocalId.ID); body2.Add(null, OpCode.JUMP, -body2.Size - 2); body.Concat(body2); body.ResolveBreaks(); body.ResolveContinues(); buffer.Concat(body); }
public Statement DecompileForEach(bool isDynArray = false) // TODO: guess for loop, probably requires a large restructure { PopByte(); var scopeStatements = new List <Statement>(); var iteratorFunc = DecompileExpression(); if (iteratorFunc == null) { return(null); } Expression dynArrVar = null; Expression dynArrIndex = null; bool unknByte = false; if (isDynArray) { dynArrVar = DecompileExpression(); unknByte = Convert.ToBoolean(ReadByte()); dynArrIndex = DecompileExpression(); } var scopeEnd = ReadUInt16(); // MemOff ForEachScopes.Push(scopeEnd); Scopes.Add(scopeStatements); CurrentScope.Push(Scopes.Count - 1); while (Position < Size) { if (CurrentIs(StandardByteCodes.IteratorNext) && PeekByte == (byte)StandardByteCodes.IteratorPop) { PopByte(); // IteratorNext PopByte(); // IteratorPop break; } var current = DecompileStatement(); if (current == null) { return(null); // ERROR ? } scopeStatements.Add(current); } CurrentScope.Pop(); ForEachScopes.Pop(); if (isDynArray) { var builder = new CodeBuilderVisitor(); // what a wonderful hack, TODO. iteratorFunc.AcceptVisitor(builder); var arrayName = new SymbolReference(null, null, null, builder.GetCodeString()); var parameters = new List <Expression>() { dynArrVar, dynArrIndex }; iteratorFunc = new FunctionCall(arrayName, parameters, null, null); } var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements, null, null), null, null); StatementLocations.Add(StartPositions.Pop(), statement); return(statement); }
public bool VisitNode(ForEachLoop node) { throw new NotImplementedException(); }
public void VisitorWithReturnIsImplemented() { var sut = new ForEachLoop(); sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23)); }