Example #1
0
 private Statement ParseUnaryConditionalBranch(IOperation currentOperation)
 {
     Expression condition = this.PopOperandStack();
       var castIfPossible = condition as CastIfPossible;
       if (castIfPossible != null) {
     condition = new CheckIfInstance() {
       Locations = castIfPossible.Locations,
       Operand = castIfPossible.ValueToCast,
       TypeToCheck = castIfPossible.TargetType,
     };
       } else if (condition.Type != Dummy.TypeReference && condition.Type.TypeCode != PrimitiveTypeCode.Boolean) {
     var defaultValue = new DefaultValue() { DefaultValueType = condition.Type, Type = condition.Type };
     condition = new NotEquality() { LeftOperand = condition, RightOperand = defaultValue };
       }
       condition.Type = this.platformType.SystemBoolean;
       GotoStatement gotoStatement = MakeGoto(currentOperation);
       ConditionalStatement ifStatement = new ConditionalStatement();
       ifStatement.Condition = condition;
       switch (currentOperation.OperationCode) {
     case OperationCode.Brfalse:
     case OperationCode.Brfalse_S:
       ifStatement.TrueBranch = new EmptyStatement();
       ifStatement.FalseBranch = gotoStatement;
       break;
     case OperationCode.Brtrue:
     case OperationCode.Brtrue_S:
     default:
       ifStatement.TrueBranch = gotoStatement;
       ifStatement.FalseBranch = new EmptyStatement();
       break;
       }
       return ifStatement;
 }
Example #2
0
 /// <summary>
 /// Visits the specified check if instance.
 /// </summary>
 /// <param name="checkIfInstance">The check if instance.</param>
 /// <returns></returns>
 protected virtual IExpression DeepCopy(CheckIfInstance checkIfInstance)
 {
     checkIfInstance.Operand = Substitute(checkIfInstance.Operand);
       checkIfInstance.TypeToCheck = Substitute(checkIfInstance.TypeToCheck);
       checkIfInstance.Type = this.Substitute(checkIfInstance.Type);
       return checkIfInstance;
 }
 public override IExpression Rewrite(ILogicalNot logicalNot) {
   if (logicalNot.Type is Dummy)
     return IfThenElseReplacer.InvertCondition(this.Rewrite(logicalNot.Operand));
   else if (logicalNot.Operand.Type.TypeCode == PrimitiveTypeCode.Int32)
     return new Equality() {
       LeftOperand = this.Rewrite(logicalNot.Operand),
       RightOperand = new CompileTimeConstant() { Value = 0, Type = this.host.PlatformType.SystemInt32 },
       Type = this.host.PlatformType.SystemBoolean,
     };
   else {
     var castIfPossible = logicalNot.Operand as CastIfPossible;
     if (castIfPossible != null) {
       var mutableLogicalNot = logicalNot as LogicalNot;
       if (mutableLogicalNot != null) {
         var operand = new CheckIfInstance() {
           Locations = castIfPossible.Locations,
           Operand = castIfPossible.ValueToCast,
           Type = this.host.PlatformType.SystemBoolean,
           TypeToCheck = castIfPossible.TargetType,
         };
         mutableLogicalNot.Operand = operand;
         return mutableLogicalNot;
       }
     }
     return base.Rewrite(logicalNot);
   }
 }
Example #4
0
 /// <summary>
 /// Visits the specified check if instance.
 /// </summary>
 /// <param name="checkIfInstance">The check if instance.</param>
 public override void Visit(ICheckIfInstance checkIfInstance)
 {
     CheckIfInstance mutableCheckIfInstance = new CheckIfInstance(checkIfInstance);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableCheckIfInstance);
 }
 public override IExpression Visit(LogicalNot logicalNot)
 {
     if (logicalNot.Type == Dummy.TypeReference)
     return PatternDecompiler.InvertCondition(this.Visit(logicalNot.Operand));
       else if (logicalNot.Operand.Type.TypeCode == PrimitiveTypeCode.Int32)
     return new Equality() {
       LeftOperand = this.Visit(logicalNot.Operand),
       RightOperand = new CompileTimeConstant() { Value = 0, Type = this.host.PlatformType.SystemInt32 },
       Type = this.host.PlatformType.SystemBoolean,
       Locations = logicalNot.Locations
     };
       else {
     var castIfPossible = logicalNot.Operand as CastIfPossible;
     if (castIfPossible != null) {
       var operand = new CheckIfInstance() {
     Locations = castIfPossible.Locations,
     Operand = castIfPossible.ValueToCast,
     Type = this.host.PlatformType.SystemBoolean,
     TypeToCheck = castIfPossible.TargetType,
       };
       logicalNot.Operand = operand;
       return logicalNot;
     }
     return base.Visit(logicalNot);
       }
 }
Example #6
0
 /// <summary>
 /// Rewrites the children of the given check-if-instance expression.
 /// </summary>
 public virtual void RewriteChildren(CheckIfInstance checkIfInstance)
 {
     this.RewriteChildren((Expression)checkIfInstance);
       checkIfInstance.Operand = this.Rewrite(checkIfInstance.Operand);
       checkIfInstance.TypeToCheck = this.Rewrite(checkIfInstance.TypeToCheck);
 }
Example #7
0
 /// <summary>
 /// Visits the specified check if instance.
 /// </summary>
 /// <param name="checkIfInstance">The check if instance.</param>
 public override void Visit(ICheckIfInstance checkIfInstance)
 {
     CheckIfInstance mutableCheckIfInstance = checkIfInstance as CheckIfInstance;
     if (alwaysMakeACopy || mutableCheckIfInstance == null) mutableCheckIfInstance = new CheckIfInstance(checkIfInstance);
     this.resultExpression = this.myCodeMutator.Visit(mutableCheckIfInstance);
 }
Example #8
0
 /// <summary>
 /// Visits the specified check if instance.
 /// </summary>
 /// <param name="checkIfInstance">The check if instance.</param>
 /// <returns></returns>
 public virtual IExpression Visit(CheckIfInstance checkIfInstance)
 {
     checkIfInstance.Operand = Visit(checkIfInstance.Operand);
       checkIfInstance.TypeToCheck = Visit(checkIfInstance.TypeToCheck);
       checkIfInstance.Type = this.Visit(checkIfInstance.Type);
       return checkIfInstance;
 }