Package com.hpctoday.fada

Examples of com.hpctoday.fada.Expression


    for (String it : to_be_ducplicated) {
      StringBuilder positive = new StringBuilder();
      StringBuilder negative = new StringBuilder();
      positive.append("_pos_").append(it);
      negative.append("_neg_").append(it);
      Expression sub = new Expression(new Expression(positive.toString()), Expression.Operation.FADA_SUB, new Expression(
          negative.toString()));
      constraints.add(new Inequation(new Expression(it), Inequation.Predicate.FADA_EQ, sub));
      constraints.add(new Inequation(new Expression(positive.toString()), Inequation.Predicate.FADA_GREATER_EQ, new Expression(0)));
      constraints.add(new Inequation(new Expression(negative.toString()), Inequation.Predicate.FADA_GREATER_EQ, new Expression(0)));
      var.add(positive.toString());
      var.add(negative.toString());
    }
  }
View Full Code Here


     
      RationalVector<N> vector = parm.getParameters();
      RationalNumber<N> gcd = vector.gcd().inverse();
      vector = vector.multiply(gcd);
     
      Expression num = PipVectorToExpression(vector, __params, __new_param);
     
      //Build denominator
      Expression newparm_def;
      if(gcd.isInteger()){
        int value = (int)gcd.value();
        Expression deno = new Expression(value);
        newparm_def = new Expression(num, Expression.Operation.FADA_DIV, deno);
      } else {
        int n = (int)gcd.getNumerator().value();
        int d = (int)gcd.getDenominator().value();
        Expression exp1 = new Expression(new Expression(d), Expression.Operation.FADA_MUL, num);
        newparm_def = new Expression(exp1, Expression.Operation.FADA_DIV, new Expression(n));
      }
     

      __new_param.put(new_rank, newparm_def);
    }
   
    SubSolution<N> sSolution = solution.getSolution();
    // conditional node
    if(sSolution instanceof PipQuast){
      PipQuast<N> __quast = (PipQuast<N>)sSolution;
      Expression ineq = PipVectorToExpression(__quast.getCondition(), __params, __new_param);
      Condition __cond = new Condition(new Inequation(ineq.GetLeftChild(), Inequation.Predicate.FADA_GREATER_EQ, ineq.GetRightChild()));
      log.trace("Cond: " + __cond);
      return new Quast(__cond,
          FromPipQuast(__index, __deep, __counters, __params, __quast.getThen(), __new_param),
          FromPipQuast(__index, __deep, __counters, __params, __quast.getElse(), __new_param));
    } else if(sSolution instanceof PipList){ // leaf
View Full Code Here

    // pip_List_print(stdout,__pipv);
 
    log.trace("param: " + __param);
    log.trace("pipv: " + __pipv);
   
    Expression result_pos;
    Expression result_neg;
   
    if (__pipv.get(nb_parameters + __new_param.size()).signum() >= 0) { // constant
      // FIXME: Downcasting
      int value = (int)__pipv.get(nb_parameters + __new_param.size()).value();
      result_pos = new Expression(value);
      result_neg = new Expression(0);
    } else {
      int value = (int)__pipv.get(nb_parameters + __new_param.size()).value();
      result_pos = new Expression(0);
      result_neg = new Expression(-1 * value);
    }
 
    for (int i = 0; i < nb_parameters; i++) { // handle old parameters
      // FIXME: Downcasting
      int coef = (int) __pipv.get(i).value();
      // cout<<"\n i = "<<i<<"    coef = "<<coef<<"     nom param = "<<__param.operator[](i);
      if (coef != 0) {
        Expression param = new Expression(__param.get(i));
        switch (coef) {
        case 1:
          result_pos = new Expression(result_pos, Expression.Operation.FADA_ADD, param);
          break;
        case -1:
          result_neg = new Expression(result_neg, Expression.Operation.FADA_ADD, param);
          break;
        case 0:
          break;
        default: {
          if (coef > 0) {
            Expression __coef = new Expression(coef);
            Expression __term = new Expression(__coef, Expression.Operation.FADA_MUL, param);
            result_pos = new Expression(result_pos, Expression.Operation.FADA_ADD, __term);
          } else {
            Expression __coef = new Expression(-1 * coef);
            Expression __term = new Expression(__coef, Expression.Operation.FADA_MUL, param);
            result_neg = new Expression(result_pos, Expression.Operation.FADA_ADD, __term);
          }
          break;
        }
        }
      }
    }
    // cout<<"\n\nhhhhhhhhhhhhhhhhh\n";
 
    // Newparms handling
    for (int i : __new_param.keySet()) {
      Expression param = __new_param.get(i);
      // FIXME: Downcasting
      int coef = (int) __pipv.get(i).value();
      switch (coef) {
      case 0:
        break;
      case 1:
        result_pos = new Expression(result_pos, Expression.Operation.FADA_ADD, param);
        break;
      case -1:
        result_neg = new Expression(result_neg, Expression.Operation.FADA_ADD, param);
        break;
      default:
        if (coef > 0) {
          Expression __coef = new Expression(coef);
          Expression __term = new Expression(__coef, Expression.Operation.FADA_MUL, param);
          result_pos = new Expression(result_pos, Expression.Operation.FADA_ADD, __term);
        } else {
          Expression __coef = new Expression(-1 * coef);
          Expression __term = new Expression(__coef, Expression.Operation.FADA_MUL, param);
          result_neg = new Expression(result_pos, Expression.Operation.FADA_ADD, __term);
        }
        break;
      }
    }
    result_pos = result_pos.Simplify();
    // result_pos.Print();
    Expression final_res = new Expression(result_pos.Simplify(), Expression.Operation.FADA_SUB, result_neg.Simplify());
    // cout<<"\n\nhhhhhhhhhhhhhhhhh\n";
    // final_res.Print();
    return final_res;
  }
View Full Code Here

        finalCond = operandVisitor.getCond().Negate();
        break;
      case IASTUnaryExpression.op_prefixIncr:
        opr = new ExprVisitor();
        expr.getOperand().accept(opr);
        finalExpr = opr.getExpr().add(new Expression(1));
        break;
      case IASTUnaryExpression.op_minus:
        opr = new ExprVisitor();
        expr.getOperand().accept(opr);
        //FIXME what if operand is floating number
        finalExpr = opr.getExpr().mul(new Expression(-1));
        break;
      case IASTUnaryExpression.op_plus:
        opr = new ExprVisitor();
        expr.getOperand().accept(opr);
        finalExpr = opr.getExpr();
View Full Code Here

        return visit_binary_expression(bexpr);
      }
    }else if (expr instanceof IASTIdExpression){
      //IASTIdExpression id = (IASTIdExpression) expr;
      //System.err.println(id.getName().getBinding());
      finalExpr = new Expression(expr.getRawSignature());
      return PROCESS_SKIP;
    } else if (expr instanceof IASTLiteralExpression) {
      IASTLiteralExpression literal = (IASTLiteralExpression) expr;
      try {
        int value = Integer.parseInt(literal.getRawSignature());
        finalExpr = new Expression(value);
      } catch (NumberFormatException ex){
        //finalExpr = new Expression(expr.getRawSignature());
        finalExpr = new Expression(1000);
      }
      return PROCESS_SKIP;
    } else if (expr instanceof IASTArraySubscriptExpression){
      ArrayAccessVisitor aVisitor = new ArrayAccessVisitor();
      expr.accept(aVisitor);
      finalExpr = new Expression(aVisitor.id);
      for (int i = aVisitor.indices.size()-1; i >=0; i--) {
        finalExpr.AddIndex(aVisitor.indices.get(i));
      }
      finalCond =  new Condition(new Inequation(finalExpr, Inequation.Predicate.FADA_NEQ, new Expression(0)));
      return PROCESS_SKIP;
    } else if (expr instanceof IASTUnaryExpression){
      return visit ((IASTUnaryExpression)expr);
    } else if (expr instanceof IASTFunctionCallExpression){
      IASTFunctionCallExpression funcExpr = (IASTFunctionCallExpression)expr;
     
      List<Expression> arguments = new ArrayList<Expression>();
      for(IASTInitializerClause argument: funcExpr.getArguments()){
        ExprVisitor visitor = new ExprVisitor();
        argument.accept(visitor);
        arguments.add(visitor.getExpr());
      }
     
      finalExpr = new Expression(Expression.Leaf.FADA_function, funcExpr.getFunctionNameExpression().getRawSignature(), arguments);
     
      finalCond =  new Condition(new Inequation(finalExpr, Inequation.Predicate.FADA_NEQ, new Expression(0)));
      return PROCESS_SKIP;
    } else {
      System.err.println("ExprVisitor.visit: " + expr.getRawSignature() + " " + expr.getClass());
     
      return PROCESS_ABORT;
View Full Code Here

   
      if (isAssign(bexpr)) {
                               
        ExprVisitor rhsVisitor = new ExprVisitor();
        bexpr.getOperand2().accept(rhsVisitor);
        Expression rhs = rhsVisitor.getExpr();
       
        ExprVisitor lhsVisitor = new ExprVisitor();
       
        switch (bexpr.getOperator()) {
          case IASTBinaryExpression.op_plusAssign:
View Full Code Here

      case IASTUnaryExpression.op_prefixIncr:
      case IASTUnaryExpression.op_postFixIncr:
        {
          ExprVisitor lhsVisitor = new ExprVisitor();
          ((IASTUnaryExpression) expr).getOperand().accept(lhsVisitor);
          Expression lhsExpr = lhsVisitor.getExpr();
          String lhs = lhsExpr.Generate_C_Code();
         
          Expression rhs = lhsExpr.add(1);
          Statement stmt = new Statement(new Assignment (lhs, rhs));
 
          if(inElse) parent.Enclose(stmt, true);
          else parent.Enclose(stmt, false);
        }
        break;
      case IASTUnaryExpression.op_prefixDecr:
      case IASTUnaryExpression.op_postFixDecr:
        {
          ExprVisitor lhsVisitor = new ExprVisitor();
          ((IASTUnaryExpression) expr).getOperand().accept(lhsVisitor);
          Expression lhsExpr = lhsVisitor.getExpr();
          String lhs = lhsExpr.Generate_C_Code();
         
          Expression rhs = lhsExpr.add(1);
          Statement stmt = new Statement(new Assignment (lhs, rhs));
 
          if(inElse) parent.Enclose(stmt, true);
          else parent.Enclose(stmt, false);
        }
View Full Code Here

          ExprVisitor visitor = new ExprVisitor();
          exp.accept(visitor);
          
          List<Expression> arguments = new ArrayList<Expression>();
          arguments.add(visitor.getExpr());
          Expression retExp = new Expression(Expression.Leaf.FADA_function, "return", arguments);
          Statement retStmt = new Statement(new Assignment ("", retExp));
          AST.Enclose(retStmt, false);
        }
      } else {
        System.err.println("FadaVisitor Unknown Statement: [" + stmt.getClass() + "] " + stmt.getRawSignature());
View Full Code Here

TOP

Related Classes of com.hpctoday.fada.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.