Example #1
0
 public If(If i) {
   this.cond = new Expression(i.getCond());
   this.baseCase = new Expression(i.getBaseCase());
   this.recCase = new Expression(i.getRecCase());
   this.ifZero = i.getIfZero();
   copyEnvironment(i);
 }
  @Override
  public void meet(If node) throws RuntimeException {
    builder.append("CASE WHEN ");

    optypes.push(ValueType.BOOL);
    node.getCondition().visit(this);
    optypes.pop();

    optypes.push(new OPTypeFinder(node).coerce());
    builder.append(" THEN ");
    node.getResult().visit(this);
    builder.append(" ELSE ");
    node.getAlternative().visit(this);
    builder.append(" END");
    optypes.pop();
  }
Example #3
0
  public void writeConditionalBranch16(ConditionalBranch16 _branch16, boolean _invert)
      throws CodeGenException {

    if (_branch16 instanceof If) {
      final If iff = (If) _branch16;

      writeInstruction(iff.getLhs());
      write(_branch16.getOperator().getText(_invert));
      writeInstruction(iff.getRhs());
    } else if (_branch16 instanceof I_IFNULL) {
      final I_IFNULL iff = (I_IFNULL) _branch16;
      writeInstruction(iff.getFirstChild());

      if (_invert) {
        write(" != NULL");
      } else {
        write(" == NULL");
      }

    } else if (_branch16 instanceof I_IFNONNULL) {
      final I_IFNONNULL iff = (I_IFNONNULL) _branch16;
      writeInstruction(iff.getFirstChild());

      if (_invert) {
        write(" == NULL");
      } else {
        write(" != NULL");
      }
    } else if (_branch16 instanceof IfUnary) {
      final IfUnary branch16 = (IfUnary) _branch16;
      final Instruction comparison = branch16.getUnary();
      final ByteCode comparisonByteCode = comparison.getByteCode();
      final String comparisonOperator = _branch16.getOperator().getText(_invert);

      switch (comparisonByteCode) {
        case FCMPG:
        case DCMPG:
        case FCMPL:
        case DCMPL:
          if (Config.verboseComparitor) {
            write("/* bytecode=" + comparisonByteCode.getName() + " invert=" + _invert + "*/");
          }
          writeInstruction(comparison.getFirstChild());
          write(comparisonOperator);
          writeInstruction(comparison.getLastChild());
          break;
        default:
          if (Config.verboseComparitor) {
            write(
                "/* default bytecode="
                    + comparisonByteCode.getName()
                    + " invert="
                    + _invert
                    + "*/");
          }
          writeInstruction(comparison);
          write(comparisonOperator);
          write("0");
      }
    }
  }