Esempio n. 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();
  }
Esempio n. 3
0
  @Override
  public <T> void convert(MetadataParser<T> p, Object expressionsNode) {
    if (anIf == null) {
      throw com.redhat.lightblue.util.Error.get(
          RDBMSConstants.ERR_FIELD_REQUIRED, "No if informed");
    }
    if (then == null) {
      throw com.redhat.lightblue.util.Error.get(
          RDBMSConstants.ERR_FIELD_REQUIRED, "No then informed");
    }
    T eT = p.newNode();
    T iT = p.newNode();

    anIf.convert(p, null, iT);
    p.putObject(eT, "if", iT);

    then.convert(p, null, eT);

    if (elseIfList != null && !elseIfList.isEmpty()) {
      Object arri = p.newArrayField(eT, "elseIf");
      for (ElseIf e : elseIfList) {
        e.convert(p, arri, null);
      }
    }

    if (anElse != null) {
      anElse.convert(p, null, eT);
    }

    p.addObjectToArray(expressionsNode, eT);
  }
Esempio n. 4
0
  /**
   * switch case for ALL orders
   *
   * @param e the EObject w'd like to know more about
   */
  private void execute(EObject e) {
    if (e instanceof Refresh) {
      refresh();
    } else if (e instanceof Navigate) {
      navigateTo(((Navigate) e).getUrl());
    } else if (e instanceof Store) {
      store((Store) e);
    } else if (e instanceof ReDefine) {
      redefine((ReDefine) e);
    } else if (e instanceof Delete) {
      delete((Delete) e);
    } else if (e instanceof ActionSelect) {
      select((ActionSelect) e);
    } else if (e instanceof ActionWithObject) {
      ActionWithObject awo = (ActionWithObject) e;
      execute(awo.getObject(), awo);
    } else if (e instanceof CheckBox) {
      tickBox((CheckBox) e);
    } else if (e instanceof Rickroll) {
      rickRoll();
    } else if (e instanceof DoWait) {
      waitFor(((DoWait) e).getMillisec());
    }
    // conditions :
    else if (Condition.class.isAssignableFrom(e.getClass())) {
      eval((Condition) e);
    }
    // structures :
    else if (e instanceof If) {
      If i = ((If) e);
      structureIf(i.getCond(), i.getActionThen(), i.getActionElse());
    } else if (e instanceof Loop) {
      Loop i = (Loop) e;
      structureLoop(i.getCond(), i.getMilliseconds(), i.getActions());
    } else if (e instanceof DoAll) {
      DoAll i = (DoAll) e;
      structureDoAll(i.getColl(), i.getTodo());
    } else if (e instanceof Execute) {

      executeSubProcedure((Execute) e);
    }
  }
 /** Given generalized if expression, desugar into __cond calls (binding) where required. */
 @Override
 public Node forIf(If i) {
   List<IfClause> clauses = i.getClauses();
   int n = clauses.size();
   if (n <= 0) bug(i, "if with no clauses!");
   for (IfClause c : clauses) {
     if (c.getTestClause().getBind().size() == 0) continue;
     // If we get here we have a generalized if.
     // Desugar it into nested ifs and calls.
     // Then return the desugared result.
     Expr result = null;
     if (i.getElseClause().isSome()) {
       result = i.getElseClause().unwrap();
     }
     // Traverse each clause and desugar it into an if or a __cond as appropriate.
     for (--n; n >= 0; --n) {
       result = addIfClause(clauses.get(n), result);
     }
     return result;
   }
   // If we get here, it's not a generalized if.  Just recur.
   return super.forIf(i);
 }
Esempio n. 6
0
  @Override
  public void visit(If ifStm) {
    System.out.print("if (");
    if (ifStm.getCondExp() != null) ifStm.getCondExp().accept(this);
    System.out.println(")");

    System.out.print("\t\t\t");
    if (ifStm.getTrueStm() != null) ifStm.getTrueStm().accept(this);
    System.out.println();

    System.out.println("\t\telse");
    System.out.print("\t\t\t");
    if (ifStm.getFalseStm() != null) ifStm.getFalseStm().accept(this);
  }
Esempio n. 7
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");
      }
    }
  }