public override void TraverseChildren(IGotoStatement gotoStatement) { IName target = gotoStatement.TargetStatement.Label; ITryCatchFinallyStatement targetStatement = this.sink.MostNestedTryStatement(target); int count = 0; while (count < this.sink.nestedTryCatchFinallyStatements.Count) { int index = this.sink.nestedTryCatchFinallyStatements.Count - count - 1; ITryCatchFinallyStatement nestedStatement = this.sink.nestedTryCatchFinallyStatements[index].Item1; if (targetStatement == nestedStatement) { break; } int labelId; string label; this.sink.AddEscapingEdge(nestedStatement, out labelId, out label); StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(labelId))); string finallyLabel = this.sink.FindOrCreateFinallyLabel(nestedStatement); StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List <string>(new string[] { finallyLabel }))); StmtBuilder.AddLabelCmd(label); count++; } StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List <string>(new string[] { target.Value }))); }
public override void TraverseChildren(IGotoStatement gotoStatement) { var mutableGoto = gotoStatement as GotoStatement; if (mutableGoto == null) { return; } var target = gotoStatement.TargetStatement as LabeledStatement; if (target != null && this.trystartOutsideLabels.Contains(target)) { var key = (uint)target.Label.UniqueKey; var gotos = this.gotosThatTarget[key]; if (gotos != null) { gotos.Remove(gotoStatement); } var newTarget = this.insideLabelFor[key]; mutableGoto.TargetStatement = newTarget; Contract.Assume(newTarget != null); key = (uint)newTarget.Label.UniqueKey; gotos = this.gotosThatTarget[key]; if (gotos == null) { this.gotosThatTarget[key] = gotos = new List <IGotoStatement>(); } gotos.Add(gotoStatement); } }
public static ISwitchCase IsGotoCase(IGotoStatement go) { var label = go.Label; //body of switch case var parent = label.ParentStatement; if (parent == null) { return(null); } var sc = parent.ParentStatement as ISwitchCase; if (sc == null) { return(null); } if (!ReferenceEquals(sc.Body[0], label)) { return(null); } //first parent is collection of switch cases var sw = sc.ParentStatement.ParentStatement; return(HasParent(go, sw) ? sc : null); }
public override void VisitGotoStatement(IGotoStatement gotoStatement) { Value = new Statement() { GotoStatement = new GotoStatementFactory(gotoStatement).Value }; }
public override void Visit(IGotoStatement gotoStatement) { if (Process(gotoStatement)) { visitor.Visit(gotoStatement); } base.Visit(gotoStatement); }
public override void TraverseChildren(IGotoStatement gotoStatement) { if (gotoStatement == this.backwardsBranch) { if (this.currentIf != null && this.currentIf.TrueBranch == this.currentBlock && this.currentIf.FalseBranch is EmptyStatement) { this.ifContainingBackwardsBranch = this.currentIf; this.blockContainingIfContainingBackwardsBranch = this.blockContainingCurrentIf; } } this.gotosAlreadyTraversed.Add(gotoStatement); base.TraverseChildren(gotoStatement); }
private void ProcessGotoStatement(IGotoStatement pStatement) { if (mCurrentBlock.Terminated) { mCurrentBlock = CreateBlock(CreateLabel()); } HLLabel labelTarget = null; if (!mRemappedLabels.TryGetValue(pStatement.TargetStatement.Label.Value, out labelTarget)) { labelTarget = CreateLabel(); mRemappedLabels.Add(pStatement.TargetStatement.Label.Value, labelTarget); } mCurrentBlock.EmitGoto(labelTarget); }
public override void TraverseChildren(IGotoStatement gotoStatement) { if (this.referencedLabels == null) { this.referencedLabels = new Dictionary <int, uint>(); } var key = gotoStatement.TargetStatement.Label.UniqueKey; if (this.referencedLabels.ContainsKey(key)) { this.referencedLabels[key]++; } else { this.referencedLabels.Add(key, 1); } }
public override void TraverseChildren(ILabeledStatement labeledStatement) { if (this.loopHeader == null) { List <IGotoStatement> predecessors; if (this.predecessors.TryGetValue(labeledStatement, out predecessors)) { if (predecessors.Count == 1 && !this.gotosAlreadyTraversed.Contains(predecessors[0])) { this.blockContainingLoopHeader = this.currentBlock; this.loopHeader = labeledStatement; this.backwardsBranch = predecessors[0]; this.ifContainingBackwardsBranch = null; } } } base.TraverseChildren(labeledStatement); }
protected CognitiveComplexityHintBase(ITreeNode node, DocumentOffset offset, int value) { _node = node; _offset = offset; Value = value; Description = node switch { IWhileStatement _ => "While-Statement (increases nesting)", ISwitchStatement _ => "Switch-Statement (increases nesting)", IDoStatement _ => "Do-While-Statement (increases nesting)", IIfStatement _ => "If-Statement (increases nesting)", IForStatement _ => "For-Statement (increases nesting)", IForeachStatement _ => "Foreach-Statement (increases nesting)", ICatchClause _ => "Catch-Clause (increases nesting)", IGotoStatement _ => "Goto-Statement", IBreakStatement _ => "Break-Statement", IConditionalOrExpression _ => "First/alternating conditional Expression", IConditionalAndExpression _ => "First/alternating conditional Expression", ICSharpStatement _ => "If-Statement (increases nesting)", ICSharpExpression _ => "Recursive Call", _ => throw new NotSupportedException(node.GetType().FullName) }; }
public void Visit(IGotoStatement gotoStatement) { Contract.Requires(gotoStatement != null); throw new NotImplementedException(); }
public override void TraverseChildren(IGotoStatement gotoStatement) { IName target = gotoStatement.TargetStatement.Label; ITryCatchFinallyStatement targetStatement = this.sink.MostNestedTryStatement(target); int count = 0; while (count < this.sink.nestedTryCatchFinallyStatements.Count) { int index = this.sink.nestedTryCatchFinallyStatements.Count - count - 1; ITryCatchFinallyStatement nestedStatement = this.sink.nestedTryCatchFinallyStatements[index].Item1; if (targetStatement == nestedStatement) break; int labelId; string label; this.sink.AddEscapingEdge(nestedStatement, out labelId, out label); StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(labelId))); string finallyLabel = this.sink.FindOrCreateFinallyLabel(nestedStatement); StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List<string>(new string[] {finallyLabel}))); StmtBuilder.AddLabelCmd(label); count++; } StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List<string>(new string[] {target.Value}))); }
/// <summary> /// Returns a deep copy of the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public GotoStatement Copy(IGotoStatement gotoStatement) { var mutableCopy = this.shallowCopier.Copy(gotoStatement); return mutableCopy; }
public virtual void VisitGotoStatement(IGotoStatement value) { }
public override void TraverseChildren(IGotoStatement gotoStatement) { this.sourceEmitterOutput.Write("goto ", true); this.sourceEmitterOutput.Write(gotoStatement.TargetStatement.Label.Value); this.sourceEmitterOutput.WriteLine(";"); }
/// <summary> /// Generates IL for the specified goto statement. /// </summary> /// <param name="gotoStatement">The goto statement.</param> public override void TraverseChildren(IGotoStatement gotoStatement) { this.EmitSequencePoint(gotoStatement.Locations); ILGeneratorLabel targetLabel; if (!this.labelFor.TryGetValue(gotoStatement.TargetStatement.Label.UniqueKey, out targetLabel)) { targetLabel = new ILGeneratorLabel(); this.labelFor.Add(gotoStatement.TargetStatement.Label.UniqueKey, targetLabel); } if (this.LabelIsOutsideCurrentExceptionBlock(targetLabel)) this.generator.Emit(OperationCode.Leave, targetLabel); else this.generator.Emit(OperationCode.Br, targetLabel); this.lastStatementWasUnconditionalTransfer = true; }
public virtual void VisitGotoStatement(IGotoStatement gotoStatement) { Visit(gotoStatement); }
public override void Visit(IGotoStatement gotoStatement) { //update loop nest level if (!_visitedGotoStatements.Contains(gotoStatement)) { _loopNestLevel++; _visitedGotoStatements.Add(gotoStatement); _loopInvariants.Add(new HashSet<string>()); if (_loopNestLevel == 1) { _outmostLoopStart = gotoStatement; _pendingOutmostLoopEndToRegister = new List<StatementTmpCopyInformation>(); } } base.Visit(gotoStatement); }
public void Visit(IGotoStatement stmt, SSTPrintingContext c) { c.Indentation().Keyword("goto").Space().Text(stmt.Label).Text(";"); }
private void WriteGotoStatement(IGotoStatement statement, IFormatter formatter) { this.WriteStatementSeparator(formatter); formatter.WriteKeyword("goto"); formatter.Write(" "); this.WriteDeclaration(statement.Name, formatter); }
// For the first assignment to a local variable in a block before a control statement is hit, // if the local variable is not mentioned previously, we turn this assignment into a local declaration. private void AddDeclarationsWithInitialValues(IEnumerable <ILocalDefinition> localVariables, BasicBlock block) { List <ILocalDefinition> topLevelLocals = new List <ILocalDefinition>(localVariables); List <ILocalDefinition> localsMet = new List <ILocalDefinition>(); for (int i = 0; i < block.Statements.Count; i++) { if (topLevelLocals.Count == 0) { break; } IExpressionStatement expressionStatement = block.Statements[i] as IExpressionStatement; if (expressionStatement != null) { IAssignment assignment = expressionStatement.Expression as IAssignment; if (assignment != null) { ILocalDefinition localDef = assignment.Target.Definition as ILocalDefinition; if (localDef != null && topLevelLocals.Contains(localDef) && !localsMet.Contains(localDef) && !this.declaredLocals.ContainsKey(localDef)) { LocalDeclarationStatement localDecl = new LocalDeclarationStatement() { LocalVariable = localDef, InitialValue = assignment.Source, Locations = new List <ILocation>(expressionStatement.Locations), }; this.declaredLocals.Add(localDef, true); block.Statements[i] = localDecl; topLevelLocals.Remove(localDef); localsMet.Add(localDef); } } } LocalFinder finder = new LocalFinder(); finder.Traverse(block.Statements[i]); foreach (ILocalDefinition local in finder.FoundLocals) { if (!localsMet.Contains(local)) { localsMet.Add(local); } } //Once we see a statement that can transfer control somewhere else, we //no longer know that any subsequent assignment dominates all references //and hence cannot postpone adding the declaration until we can unify it with the assignment. IGotoStatement gotoStatement = block.Statements[i] as IGotoStatement; if (gotoStatement != null) { break; } IConditionalStatement conditionalStatement = block.Statements[i] as IConditionalStatement; if (conditionalStatement != null) { break; } ISwitchStatement switchStatement = block.Statements[i] as ISwitchStatement; if (switchStatement != null) { break; } IForEachStatement foreachStatement = block.Statements[i] as IForEachStatement; if (foreachStatement != null) { break; } IForStatement forStatement = block.Statements[i] as IForStatement; if (forStatement != null) { break; } ITryCatchFinallyStatement tryStatement = block.Statements[i] as ITryCatchFinallyStatement; if (tryStatement != null) { break; } } }
public override void VisitGotoStatement(IGotoStatement gotoStatement) { Steps.Add(new WriteGotoKeyword()); Steps.Add(new WriteWhitespace()); Steps.Add(new WriteName(gotoStatement.LabelName)); }
public virtual void Visit(IGotoStatement stmt, TContext context) { }
public override void Visit(IGotoStatement gotoStatement) { allElements.Add(new InvokInfo(Traverser, "IGotoStatement", gotoStatement)); }
/// <summary> /// /// </summary> /// <param name="gotoStatement"></param> public GotoStatement(IGotoStatement gotoStatement) : base(gotoStatement) { this.targetStatement = gotoStatement.TargetStatement; }
public void Visit(IGotoStatement gotoStatement) { this.result = this.copier.Copy(gotoStatement); }
public override IStatement Visit(IStatement statement) { IGotoStatement gotoStatement = statement as IGotoStatement; if (gotoStatement != null) { this.visitedUnconditionalBranch = true; foreach (object ob in this.path) { if (ob is IConditionalStatement) { this.visitedUnconditionalBranch = false; } } StackOfLocals newStack = null; if (this.stackFor.TryGetValue(gotoStatement.TargetStatement, out newStack)) { return(this.TransferStack(gotoStatement, newStack)); } this.stackFor.Add(gotoStatement.TargetStatement, this.operandStack.Clone(this.block)); return(gotoStatement); } ILabeledStatement labeledStatement = statement as ILabeledStatement; if (labeledStatement != null) { StackOfLocals newStack = null; if (this.stackFor.TryGetValue(labeledStatement, out newStack)) { return(this.TransferStack(labeledStatement, newStack)); } this.stackFor.Add(labeledStatement, this.operandStack.Clone(this.block)); return(labeledStatement); } PushStatement /*?*/ push = statement as PushStatement; if (push != null) { push.ValueToPush = this.Visit(push.ValueToPush); this.tempCounter = this.body.localVariablesAndTemporaries.Count; var temp = new TempVariable() { Name = this.body.host.NameTable.GetNameFor("__temp_" + this.tempCounter++) }; temp.Type = push.ValueToPush.Type; this.operandStack.Push(temp); this.body.numberOfReferences.Add(temp, 0); var ctc = push.ValueToPush as ICompileTimeConstant; // "push null" doesn't tell us enough to know what type it really is if (ctc != null && ctc.Value == null) // REVIEW: need to make sure the type is a reference type? { temp.isPolymorphic = true; } var be = push.ValueToPush as IBoundExpression; if (be != null) { var sourceLocal = be.Definition as TempVariable; if (sourceLocal != null && sourceLocal.isPolymorphic) { temp.isPolymorphic = true; } } if (push.ValueToPush.Type is IManagedPointerTypeReference) { temp.turnIntoPopValueExpression = true; return(statement); } this.body.localVariablesAndTemporaries.Add(temp); if (this.block.LocalVariables == null) { this.block.LocalVariables = new List <ILocalDefinition>(); } this.block.LocalVariables.Add(temp); this.body.numberOfAssignments.Add(temp, 1); return(new ExpressionStatement() { Expression = new Assignment() { Target = new TargetExpression() { Definition = temp }, Source = push.ValueToPush }, Locations = push.Locations }); } if (statement is EndFilter || statement is EndFinally) { this.visitedUnconditionalBranch = true; return(statement); } if (statement is SwitchInstruction) { return(statement); } return(base.Visit(statement)); }
public virtual void onASTElement(IGotoStatement gotoStatement) { }
private void ProcessGotoStatement(IGotoStatement pStatement) { if (mCurrentBlock.Terminated) mCurrentBlock = CreateBlock(CreateLabel()); HLLabel labelTarget = null; if (!mRemappedLabels.TryGetValue(pStatement.TargetStatement.Label.Value, out labelTarget)) { labelTarget = CreateLabel(); mRemappedLabels.Add(pStatement.TargetStatement.Label.Value, labelTarget); } mCurrentBlock.EmitGoto(labelTarget); }
public override void TraverseChildren(IGotoStatement gotoStatement) { var mutableGoto = gotoStatement as GotoStatement; if (mutableGoto == null) return; var target = gotoStatement.TargetStatement as LabeledStatement; if (target != null && this.trystartOutsideLabels.Contains(target)) { var key = (uint)target.Label.UniqueKey; var gotos = this.gotosThatTarget[key]; if (gotos != null) gotos.Remove(gotoStatement); var newTarget = this.insideLabelFor[key]; mutableGoto.TargetStatement = newTarget; Contract.Assume(newTarget != null); key = (uint)newTarget.Label.UniqueKey; gotos = this.gotosThatTarget[key]; if (gotos == null) this.gotosThatTarget[key] = gotos = new List<IGotoStatement>(); gotos.Add(gotoStatement); } }
/// <summary> /// Visits the specified goto statement. /// </summary> /// <param name="gotoStatement">The goto statement.</param> public override void Visit(IGotoStatement gotoStatement) { GotoStatement mutableGotoStatement = new GotoStatement(gotoStatement); this.resultStatement = this.myCodeCopier.DeepCopy(mutableGotoStatement); }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Traverses the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public virtual void Visit(IGotoStatement gotoStatement) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(gotoStatement); //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count. this.path.Pop(); }
/// <summary> /// Returns a shallow copy of the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public GotoStatement Copy(IGotoStatement gotoStatement) { return new GotoStatement(gotoStatement); }
public override void Visit(IGotoStatement gotoStatement) { if(Process(gotoStatement)){visitor.Visit(gotoStatement);} base.Visit(gotoStatement); }
public int Visit(IGotoStatement stmt, int context) { return(1); }
public override void TraverseChildren(IGotoStatement gotoStatement) { this.referencedLabels[gotoStatement.TargetStatement.Label.UniqueKey] = true; }
public override void TraverseChildren(IGotoStatement gotoStatement) { MethodEnter(gotoStatement); base.TraverseChildren(gotoStatement); MethodExit(); }
/// <summary> /// Rewrites the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public virtual IStatement Rewrite(IGotoStatement gotoStatement) { return gotoStatement; }
/// <summary> /// Traverses the goto statement. /// </summary> public void Traverse(IGotoStatement gotoStatement) { Contract.Requires(gotoStatement != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(gotoStatement); if (this.StopTraversal) return; this.TraverseChildren(gotoStatement); if (this.StopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(gotoStatement); }
public void Visit(IGotoStatement gotoStatement) { this.traverser.Traverse(gotoStatement); }
/// <summary> /// Performs some computation with the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public virtual void Visit(IGotoStatement gotoStatement) { }
public override void VisitGotoStatement(IGotoStatement value) { WriteUnsupported(value); }
/// <summary> /// Traverses the children of the goto statement. /// </summary> public virtual void TraverseChildren(IGotoStatement gotoStatement) { Contract.Requires(gotoStatement != null); this.TraverseChildren((IStatement)gotoStatement); }
public override void TraverseChildren(IGotoStatement gotoStatement) { if (this.referencedLabels == null) this.referencedLabels = new Dictionary<int, uint>(); var key = gotoStatement.TargetStatement.Label.UniqueKey; if (this.referencedLabels.ContainsKey(key)) this.referencedLabels[key]++; else this.referencedLabels.Add(key, 1); }
/// <summary> /// Performs some computation with the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public virtual void Visit(IGotoStatement gotoStatement) { this.Visit((IStatement)gotoStatement); }
/// <summary> /// Returns a deep copy of the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public GotoStatement Copy(IGotoStatement gotoStatement) { Contract.Requires(gotoStatement != null); Contract.Ensures(Contract.Result<GotoStatement>() != null); var mutableCopy = this.shallowCopier.Copy(gotoStatement); return mutableCopy; }
public void Visit(IGotoStatement gotoStatement) { throw new NotImplementedException(); }
/// <summary> /// Returns a shallow copy of the given goto statement. /// </summary> /// <param name="gotoStatement"></param> public GotoStatement Copy(IGotoStatement gotoStatement) { Contract.Requires(gotoStatement != null); Contract.Ensures(Contract.Result<GotoStatement>() != null); return new GotoStatement(gotoStatement); }
public override void Visit(IGotoStatement stmt, RelativeEditLocation loc) { loc.Size++; }
public virtual void VisitGotoStatement(IGotoStatement s) { }
public override IStatement Visit(IGotoStatement stmt, int context) { return(new GotoStatement { Label = stmt.Label }); }
public override void TraverseChildren(ILabeledStatement labeledStatement) { if (this.loopHeader == null) { List<IGotoStatement> predecessors; if (this.predecessors.TryGetValue(labeledStatement, out predecessors)) { if (predecessors.Count == 1 && !this.gotosAlreadyTraversed.Contains(predecessors[0])) { this.blockContainingLoopHeader = this.currentBlock; this.loopHeader = labeledStatement; this.backwardsBranch = predecessors[0]; this.ifContainingBackwardsBranch = null; } } } base.TraverseChildren(labeledStatement); }