Ejemplo n.º 1
0
 public override void TraverseChildren(ISwitchCase switchCase)
 {
     if (!switchCase.IsDefault)
     {
         Result++;
     }
     base.TraverseChildren(switchCase);
 }
Ejemplo n.º 2
0
 public override void Visit(ISwitchCase switchCase)
 {
     if (Process(switchCase))
     {
         visitor.Visit(switchCase);
     }
     base.Visit(switchCase);
 }
Ejemplo n.º 3
0
        private static void ReportAtLastClause([NotNull] ISwitchCase switchCase, OperationAnalysisContext context)
        {
            ICaseClause lastClause = switchCase.Clauses.Last();

            Location location = lastClause.GetLocationForKeyword();

            context.ReportDiagnostic(Diagnostic.Create(Rule, location));
        }
Ejemplo n.º 4
0
 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.");
 }
Ejemplo n.º 5
0
 /// <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;
 }
Ejemplo n.º 6
0
        private static bool HasDefaultCase(ISwitchCase switchCase)
        {
            foreach (var clause in switchCase.Clauses)
            {
                if (clause.CaseKind == CaseKind.Default)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
 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();
 }
Ejemplo n.º 11
0
 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);
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Performs some computation with the given switch case.
 /// </summary>
 /// <param name="switchCase"></param>
 public virtual void Visit(ISwitchCase switchCase)
 {
 }
Ejemplo n.º 13
0
 /// <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);
 }
Ejemplo n.º 14
0
 //^ 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();
 }
Ejemplo n.º 15
0
 public virtual void onASTElement(ISwitchCase switchCase)
 {
 }
Ejemplo n.º 16
0
 public void Visit(ISwitchCase switchCase)
 {
     this.result = this.copier.Copy(switchCase);
 }
Ejemplo n.º 17
0
 /// <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;
 }
Ejemplo n.º 18
0
 /// <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);
 }
Ejemplo n.º 19
0
 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));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gotoSwitchCaseStatement"></param>
 public GotoSwitchCaseStatement(IGotoSwitchCaseStatement gotoSwitchCaseStatement)
     : base(gotoSwitchCaseStatement)
 {
     this.targetCase = gotoSwitchCaseStatement.TargetCase;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// 
 /// </summary>
 public GotoSwitchCaseStatement()
 {
     this.targetCase = CodeDummy.SwitchCase;
 }
Ejemplo n.º 22
0
 public override void VisitSwitchCase(ISwitchCase operation)
 {
     base.VisitSwitchCase(operation);
 }
 public override void VisitSwitchCase([NotNull] ISwitchCase operation)
 {
     VisitArray(operation.Clauses);
 }
Ejemplo n.º 24
0
 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;
 }
Ejemplo n.º 27
0
    /// <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);
    }
Ejemplo n.º 28
0
 /// <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);
 }
Ejemplo n.º 29
0
    /// <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;
    }
Ejemplo n.º 30
0
 /// <summary>
 /// Returns a shallow copy of the given switch case.
 /// </summary>
 /// <param name="switchCase"></param>
 public SwitchCase Copy(ISwitchCase switchCase)
 {
     return new SwitchCase(switchCase);
 }
Ejemplo n.º 31
0
 public virtual void VisitSwitchCase(ISwitchCase operation)
 {
     DefaultVisit(operation);
 }
Ejemplo n.º 32
0
 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)
 {
 }
Ejemplo n.º 34
0
        public override void TraverseChildren(ISwitchCase switchCase)
{ MethodEnter(switchCase);
            base.TraverseChildren(switchCase);
     MethodExit();   }
Ejemplo n.º 35
0
 /// <inheritdoc />
 public override Expression VisitSwitchCase(ISwitchCase operation, LocalBinder argument)
 {
     throw Unexpected(operation, nameof(VisitSwitchStatement));
 }
Ejemplo n.º 36
0
 /// <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);
 }
Ejemplo n.º 37
0
 public virtual void onASTElement(ISwitchCase switchCase) { }
Ejemplo n.º 38
0
 public void Visit(ISwitchCase switchCase)
 {
     this.traverser.Traverse(switchCase);
 }
Ejemplo n.º 39
0
 public override void VisitSwitchCase(ISwitchCase operation)
 {
     VisitArray(operation.Clauses);
     VisitArray(operation.Body);
 }
Ejemplo n.º 40
0
 public void Visit(ISwitchCase switchCase)
 {
     Contract.Requires(switchCase != null);
       throw new NotImplementedException();
 }
Ejemplo n.º 41
0
 public virtual void VisitSwitchCase(ISwitchCase operation)
 {
     DefaultVisit(operation);
 }
Ejemplo n.º 42
0
 /// <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;
 }
Ejemplo n.º 43
0
 public override void Visit(ISwitchCase switchCase)
 {
     allElements.Add(new InvokInfo(Traverser, "ISwitchCase", switchCase));
 }
Ejemplo n.º 44
0
 public override void VisitSwitchCase(ISwitchCase operation)
 {
     base.VisitSwitchCase(operation);
 }
Ejemplo n.º 45
0
 /// <inheritdoc />
 public override IOperation VisitSwitchCase(ISwitchCase operation, object argument)
 {
     return(base.VisitSwitchCase(operation, argument));
 }
Ejemplo n.º 46
0
 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();
 }
Ejemplo n.º 47
0
        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));
        }
Ejemplo n.º 48
0
 public ISwitch <TSource, TResult> AddCase(ISwitchCase <TSource, TResult> customCase)
 {
     _conditionalCases.Add(customCase);
     return(this);
 }
Ejemplo n.º 49
0
 public override void TraverseChildren(ISwitchCase switchCase)
 {
     if (!switchCase.IsDefault)
         Result++;
     base.TraverseChildren(switchCase);
 }
Ejemplo n.º 50
0
 public override void TraverseChildren(ISwitchCase switchCase)
 {
     MethodEnter(switchCase);
     base.TraverseChildren(switchCase);
     MethodExit();
 }
Ejemplo n.º 51
0
 /// <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);
 }