Пример #1
0
 public static void EmitJumpUnlessCondition(
     CompilerTarget target, AstExpr cond, string targetLabel)
 {
     if (cond == null)
         throw new ArgumentNullException("cond", Resources.AstLazyLogical__Condition_must_not_be_null);
     if (target == null)
         throw new ArgumentNullException("target", Resources.AstNode_Compiler_target_must_not_be_null);
     if (String.IsNullOrEmpty(targetLabel))
         throw new ArgumentException(
             Resources.AstLazyLogical__targetLabel_must_neither_be_null_nor_empty, "targetLabel");
     var logical = cond as AstLazyLogical;
     if (logical != null)
     {
         var continueLabel = "Continue\\Lazy\\" + Guid.NewGuid().ToString("N");
         logical.EmitCode(target, continueLabel, targetLabel); //inverted
         target.EmitLabel(cond.Position, continueLabel);
     }
     else
     {
         cond.EmitValueCode(target);
         target.EmitJumpIfFalse(cond.Position, targetLabel);
     }
 }
Пример #2
0
 public static void EmitJumpCondition(
     CompilerTarget target,
     AstExpr cond,
     string targetLabel,
     string alternativeLabel,
     bool isPositive)
 {
     if (cond == null)
         throw new ArgumentNullException("cond", Resources.AstLazyLogical__Condition_must_not_be_null);
     if (target == null)
         throw new ArgumentNullException("target", Resources.AstNode_Compiler_target_must_not_be_null);
     if (String.IsNullOrEmpty(targetLabel))
         throw new ArgumentException(
             Resources.AstLazyLogical__targetLabel_must_neither_be_null_nor_empty, "targetLabel");
     if (String.IsNullOrEmpty(alternativeLabel))
         throw new ArgumentException(
             Resources.AstLazyLogical_alternativeLabel_may_neither_be_null_nor_empty, "alternativeLabel");
     var logical = cond as AstLazyLogical;
     if (!isPositive)
     {
         //Invert if needed
         var tmpLabel = alternativeLabel;
         alternativeLabel = targetLabel;
         targetLabel = tmpLabel;
     }
     if (logical != null)
     {
         logical.EmitCode(target, targetLabel, alternativeLabel);
     }
     else
     {
         cond.EmitValueCode(target);
         target.EmitJumpIfTrue(cond.Position, targetLabel);
         target.EmitJump(cond.Position, alternativeLabel);
     }
 }