public override void TraverseChildren(ISwitchCase switchCase) { if (!switchCase.IsDefault) { Result++; } base.TraverseChildren(switchCase); }
public override void Visit(ISwitchCase switchCase) { if (Process(switchCase)) { visitor.Visit(switchCase); } base.Visit(switchCase); }
private static void ReportAtLastClause([NotNull] ISwitchCase switchCase, OperationAnalysisContext context) { ICaseClause lastClause = switchCase.Clauses.Last(); Location location = lastClause.GetLocationForKeyword(); context.ReportDiagnostic(Diagnostic.Create(Rule, location)); }
public ISwitch <TSource, TResult> AddDefault(ISwitchCase <TSource, TResult> defaultCase) { if (_defaultCase != null) { _defaultCase = defaultCase; return(this); } throw new InvalidOperationException("A default state has already been defined for this switch statement."); }
/// <summary> /// Get the mutable copy of a switch case. /// </summary> /// <param name="swithCase"></param> /// <returns></returns> public virtual SwitchCase GetMutableCopy(ISwitchCase swithCase) { object cachedValue; if (this.cache.TryGetValue(swithCase, out cachedValue)) return (SwitchCase)cachedValue; var result = new SwitchCase(swithCase); // Probably not necessary, no two switch cases are shared. this.cache.Add(swithCase, result); this.cache.Add(result, result); return result; }
private static bool HasDefaultCase(ISwitchCase switchCase) { foreach (var clause in switchCase.Clauses) { if (clause.CaseKind == CaseKind.Default) { return(true); } } return(false); }
private static bool HasDefaultCase(ISwitchCase switchCase) { foreach (var clause in switchCase.Clauses) { if (clause.CaseKind == CaseKind.Default) { return true; } } return false; }
public override void TraverseChildren(ISwitchStatement switchStatement) { var eTraverser = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); eTraverser.Traverse(switchStatement.Expression); var conditionExpr = eTraverser.TranslatedExpressions.Pop(); // Can't depend on default case existing or its index in the collection. var switchCases = new List <ISwitchCase>(); ISwitchCase defaultCase = null; foreach (var switchCase in switchStatement.Cases) { if (switchCase.IsDefault) { defaultCase = switchCase; } else { switchCases.Add(switchCase); } } Bpl.StmtList defaultStmts = null; if (defaultCase != null) { var defaultBodyTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext); defaultBodyTraverser.Traverse(defaultCase.Body); defaultStmts = defaultBodyTraverser.StmtBuilder.Collect(defaultCase.Token()); } Bpl.IfCmd ifCmd = null; for (int i = switchCases.Count - 1; 0 <= i; i--) { var switchCase = switchCases[i]; var scTraverser = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext); scTraverser.Traverse(switchCase.Expression); var scConditionExpr = scTraverser.TranslatedExpressions.Pop(); var condition = Bpl.Expr.Eq(conditionExpr, scConditionExpr); var scBodyTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext); scBodyTraverser.Traverse(switchCase.Body); ifCmd = new Bpl.IfCmd(switchCase.Token(), condition, scBodyTraverser.StmtBuilder.Collect(switchCase.Token()), ifCmd, defaultStmts); defaultStmts = null; // default body goes only into the innermost if-then-else } StmtBuilder.Add(ifCmd); }
public override void VisitSwitchCase(ISwitchCase operation) { var caseClauseCountStr = $"{operation.Clauses.Length} case clauses"; var statementCountStr = $"{operation.Body.Length} statements"; LogString($"{nameof(ISwitchCase)} ({caseClauseCountStr}, {statementCountStr})"); LogCommonPropertiesAndNewLine(operation); Indent(); VisitArray(operation.Clauses, "Clauses", logElementCount: false); VisitArray(operation.Body, "Body", logElementCount: false); Unindent(); }
public override void TraverseChildren(ISwitchCase switchCase) { if (switchCase.IsDefault) { this.sourceEmitterOutput.WriteLine("default:", true); } else { this.sourceEmitterOutput.Write("case ", true); this.Traverse(switchCase.Expression); this.sourceEmitterOutput.WriteLine(":"); } this.sourceEmitterOutput.IncreaseIndent(); this.Traverse(switchCase.Body); this.sourceEmitterOutput.DecreaseIndent(); }
public virtual void VisitSwitchCase(ISwitchCase value) { if (value != null) { if (value is IConditionCase conditionCase) { VisitConditionCase(conditionCase); } else { IDefaultCase defaultCase = value as IDefaultCase; if (defaultCase == null) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Invalid switch case type '{0}'.", new object[] { value.GetType().Name })); } VisitDefaultCase(defaultCase); } } }
/// <summary> /// Performs some computation with the given switch case. /// </summary> /// <param name="switchCase"></param> public virtual void Visit(ISwitchCase switchCase) { }
/// <summary> /// Traverses the children of the switch case. /// </summary> public virtual void TraverseChildren(ISwitchCase switchCase) { Contract.Requires(switchCase != null); if (!switchCase.IsDefault) { this.Traverse(switchCase.Expression); if (this.StopTraversal) return; } this.Traverse(switchCase.Body); }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Traverses the given switch case. /// </summary> /// <param name="switchCase"></param> public virtual void Visit(ISwitchCase switchCase) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(switchCase); if (!switchCase.IsDefault) this.Visit(switchCase.Expression); this.Visit(switchCase.Body); //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count. this.path.Pop(); }
public virtual void onASTElement(ISwitchCase switchCase) { }
public void Visit(ISwitchCase switchCase) { this.result = this.copier.Copy(switchCase); }
/// <summary> /// Returns a deep copy of the given switch case. /// </summary> /// <param name="switchCase"></param> public SwitchCase Copy(ISwitchCase switchCase) { var mutableCopy = this.shallowCopier.Copy(switchCase); if (!mutableCopy.IsDefault) mutableCopy.Expression = this.Copy(mutableCopy.Expression); mutableCopy.Body = this.Copy(mutableCopy.Body); return mutableCopy; }
/// <summary> /// Initializes a new instance of the <see cref="SwitchCase"/> class. /// </summary> /// <param name="switchCase">The switch case.</param> public SwitchCase(ISwitchCase switchCase) { this.body = new List<IStatement>(switchCase.Body); if (!switchCase.IsDefault) this.expression = switchCase.Expression; else this.expression = CodeDummy.Constant; this.locations = new List<ILocation>(switchCase.Locations); }
public override IOperation VisitSwitchCase(ISwitchCase operation, object argument) { return(new SwitchCase(VisitArray(operation.Clauses), VisitArray(operation.Body), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }
/// <summary> /// /// </summary> /// <param name="gotoSwitchCaseStatement"></param> public GotoSwitchCaseStatement(IGotoSwitchCaseStatement gotoSwitchCaseStatement) : base(gotoSwitchCaseStatement) { this.targetCase = gotoSwitchCaseStatement.TargetCase; }
/// <summary> /// /// </summary> public GotoSwitchCaseStatement() { this.targetCase = CodeDummy.SwitchCase; }
public override void VisitSwitchCase(ISwitchCase operation) { base.VisitSwitchCase(operation); }
public override void VisitSwitchCase([NotNull] ISwitchCase operation) { VisitArray(operation.Clauses); }
public void Visit(ISwitchCase switchCase) { throw new NotImplementedException(); }
public override void Visit(ISwitchCase switchCase) { if(Process(switchCase)){visitor.Visit(switchCase);} base.Visit(switchCase); }
/// <summary> /// Rewrites the given switch case. /// </summary> /// <param name="switchCase"></param> public virtual ISwitchCase Rewrite(ISwitchCase switchCase) { return switchCase; }
/// <summary> /// Returns a shallow copy of the given switch case. /// </summary> /// <param name="switchCase"></param> public SwitchCase Copy(ISwitchCase switchCase) { Contract.Requires(switchCase != null); Contract.Ensures(Contract.Result<SwitchCase>() != null); return new SwitchCase(switchCase); }
/// <summary> /// Generates IL for the specified switch case. /// </summary> /// <param name="switchCase">The switch case.</param> public override void TraverseChildren(ISwitchCase switchCase) { this.Traverse(switchCase.Body); }
/// <summary> /// Returns a deep copy of the given switch case. /// </summary> /// <param name="switchCase"></param> public SwitchCase Copy(ISwitchCase switchCase) { Contract.Requires(switchCase != null); Contract.Ensures(Contract.Result<SwitchCase>() != null); var mutableCopy = this.shallowCopier.Copy(switchCase); if (!mutableCopy.IsDefault) mutableCopy.Expression = this.Copy(mutableCopy.Expression); mutableCopy.Body = this.Copy(mutableCopy.Body); return mutableCopy; }
/// <summary> /// Returns a shallow copy of the given switch case. /// </summary> /// <param name="switchCase"></param> public SwitchCase Copy(ISwitchCase switchCase) { return new SwitchCase(switchCase); }
public virtual void VisitSwitchCase(ISwitchCase operation) { DefaultVisit(operation); }
public void Visit(ISwitchCase switchCase) { this.result = this.rewriter.Rewrite(switchCase); }
/// <summary> /// Performs some computation with the given switch case. /// </summary> /// <param name="switchCase"></param> public virtual void Visit(ISwitchCase switchCase) { }
public override void TraverseChildren(ISwitchCase switchCase) { MethodEnter(switchCase); base.TraverseChildren(switchCase); MethodExit(); }
/// <inheritdoc /> public override Expression VisitSwitchCase(ISwitchCase operation, LocalBinder argument) { throw Unexpected(operation, nameof(VisitSwitchStatement)); }
/// <summary> /// Traverses the switch case. /// </summary> public void Traverse(ISwitchCase switchCase) { Contract.Requires(switchCase != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(switchCase); if (this.StopTraversal) return; this.TraverseChildren(switchCase); if (this.StopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(switchCase); }
public virtual void onASTElement(ISwitchCase switchCase) { }
public void Visit(ISwitchCase switchCase) { this.traverser.Traverse(switchCase); }
public override void VisitSwitchCase(ISwitchCase operation) { VisitArray(operation.Clauses); VisitArray(operation.Body); }
public void Visit(ISwitchCase switchCase) { Contract.Requires(switchCase != null); throw new NotImplementedException(); }
public virtual void VisitSwitchCase(ISwitchCase operation) { DefaultVisit(operation); }
/// <summary> /// Rewrites the given switch case. /// </summary> /// <param name="switchCase"></param> public virtual ISwitchCase Rewrite(ISwitchCase switchCase) { var mutableSwitchCase = switchCase as SwitchCase; if (mutableSwitchCase == null) return switchCase; this.RewriteChildren(mutableSwitchCase); return mutableSwitchCase; }
public override void Visit(ISwitchCase switchCase) { allElements.Add(new InvokInfo(Traverser, "ISwitchCase", switchCase)); }
public override void VisitSwitchCase(ISwitchCase operation) { base.VisitSwitchCase(operation); }
/// <inheritdoc /> public override IOperation VisitSwitchCase(ISwitchCase operation, object argument) { return(base.VisitSwitchCase(operation, argument)); }
public override void TraverseChildren(ISwitchCase switchCase) { if (switchCase.IsDefault) this.sourceEmitterOutput.WriteLine("default:", true); else { this.sourceEmitterOutput.Write("case ", true); this.Traverse(switchCase.Expression); this.sourceEmitterOutput.WriteLine(":"); } this.sourceEmitterOutput.IncreaseIndent(); this.Traverse(switchCase.Body); this.sourceEmitterOutput.DecreaseIndent(); }
public virtual void VisitSwitchCase(ISwitchCase value) { if (value == null) { return; } IConditionCase conditionCase = value as IConditionCase; if (conditionCase != null) { this.VisitConditionCase(conditionCase); return; } IDefaultCase defaultCase = value as IDefaultCase; if (defaultCase != null) { this.VisitDefaultCase(defaultCase); return; } throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Invalid switch case type '{0}'.", value.GetType().Name)); }
public ISwitch <TSource, TResult> AddCase(ISwitchCase <TSource, TResult> customCase) { _conditionalCases.Add(customCase); return(this); }
public override void TraverseChildren(ISwitchCase switchCase) { if (!switchCase.IsDefault) Result++; base.TraverseChildren(switchCase); }
public override void TraverseChildren(ISwitchCase switchCase) { MethodEnter(switchCase); base.TraverseChildren(switchCase); MethodExit(); }
/// <summary> /// Visits the specified switch case. /// </summary> /// <param name="switchCase">The switch case.</param> /// <returns></returns> public virtual ISwitchCase Visit(ISwitchCase switchCase) { SwitchCase mutableSwitchCase = switchCase as SwitchCase; if (!this.copyOnlyIfNotAlreadyMutable || mutableSwitchCase == null) mutableSwitchCase = new SwitchCase(switchCase); return Visit(mutableSwitchCase); }