Ejemplo n.º 1
0
  public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final Exp exp = call.getArg(0);
    final ExpCacheDescriptor cacheDescriptor = new ExpCacheDescriptor(exp, compiler);
    if (call.getType() instanceof SetType) {
      return new GenericIterCalc(call) {
        public Object evaluate(Evaluator evaluator) {
          return evaluator.getCachedResult(cacheDescriptor);
        }

        public Calc[] getCalcs() {
          return new Calc[] {cacheDescriptor.getCalc()};
        }

        public ResultStyle getResultStyle() {
          // cached lists are immutable
          return ResultStyle.LIST;
        }
      };
    } else {
      return new GenericCalc(call) {
        public Object evaluate(Evaluator evaluator) {
          return evaluator.getCachedResult(cacheDescriptor);
        }

        public Calc[] getCalcs() {
          return new Calc[] {cacheDescriptor.getCalc()};
        }

        public ResultStyle getResultStyle() {
          return ResultStyle.VALUE;
        }
      };
    }
  }
Ejemplo n.º 2
0
 public Calc compileCall(final ResolvedFunCall call, ExpCompiler compiler) {
   final MemberCalc[] memberCalcs = compileMembers(call.getArg(0), call.getArg(1), compiler);
   return new AbstractListCalc(call, new Calc[] {memberCalcs[0], memberCalcs[1]}) {
     public List evaluateList(Evaluator evaluator) {
       final Member member0 = memberCalcs[0].evaluateMember(evaluator);
       final Member member1 = memberCalcs[1].evaluateMember(evaluator);
       if (member0.isNull() || member1.isNull()) {
         return Collections.EMPTY_LIST;
       }
       if (member0.getLevel() != member1.getLevel()) {
         throw evaluator.newEvalException(
             call.getFunDef(), "Members must belong to the same level");
       }
       return FunUtil.memberRange(evaluator, member0, member1);
     }
   };
 }
Ejemplo n.º 3
0
  public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final MemberCalc memberCalc = compiler.compileMember(call.getArg(0));
    final IntegerCalc integerCalc = compiler.compileInteger(call.getArg(1));
    final boolean lag = call.getFunName().equals("Lag");
    return new AbstractMemberCalc(call, new Calc[] {memberCalc, integerCalc}) {
      public Member evaluateMember(Evaluator evaluator) {
        Member member = memberCalc.evaluateMember(evaluator);
        int n = integerCalc.evaluateInteger(evaluator);
        if (lag) {
          if (n == Integer.MIN_VALUE) {
            // Bump up lagValue by one, otherwise -n (used
            // in the getLeadMember call below) is out of
            // range because Integer.MAX_VALUE ==
            // -(Integer.MIN_VALUE + 1).
            n += 1;
          }

          n = -n;
        }
        return evaluator.getSchemaReader().getLeadMember(member, n);
      }
    };
  }