Example #1
0
  public Exp replace(Exp old, Exp replacement) {
    if (!(old instanceof QuantExp)) {
      if (where != null) {
        Exp whr = where.replace(old, replacement);
        if (whr != null) this.setWhere(whr);
      }
      if (body != null) {
        Exp bdy = body.replace(old, replacement);
        if (bdy != null) this.setBody(bdy);
        // Not used anywhere below. - YS
        // String str = bdy.toString(0, 0);
      }
      if (vars != null && old instanceof VarExp && replacement instanceof VarExp) {
        // What if Replacement isn't VarExp?
        List<MathVarDec> newVars = new List<MathVarDec>();
        Iterator<MathVarDec> i = vars.iterator();
        while (i.hasNext()) {
          MathVarDec tmp = i.next();
          if (tmp.getName().toString().equals(((VarExp) old).getName().toString())) {
            tmp.setName(((VarExp) replacement).getName());
          }

          newVars.add(tmp);
        }
      }
      return this;
    } else return this;
  }
Example #2
0
  public Exp validate(Exp exp, boolean scalar) {
    Exp resolved;
    try {
      resolved = (Exp) resolvedNodes.get(exp);
    } catch (ClassCastException e) {
      // A classcast exception will occur if there is a String
      // placeholder in the map. This is an internal error -- should
      // not occur for any query, valid or invalid.
      throw Util.newInternal(
          e, "Infinite recursion encountered while validating '" + Util.unparse(exp) + "'");
    }
    if (resolved == null) {
      try {
        stack.push((QueryPart) exp);
        // To prevent recursion, put in a placeholder while we're
        // resolving.
        resolvedNodes.put((QueryPart) exp, placeHolder);
        resolved = exp.accept(this);
        Util.assertTrue(resolved != null);
        resolvedNodes.put((QueryPart) exp, (QueryPart) resolved);
      } finally {
        stack.pop();
      }
    }

    if (scalar) {
      final Type type = resolved.getType();
      if (!TypeUtil.canEvaluate(type)) {
        String exprString = Util.unparse(resolved);
        throw MondrianResource.instance().MdxMemberExpIsSet.ex(exprString);
      }
    }

    return resolved;
  }
  public Exp copy() {
    Exp copy = new VariableDotExp(location, new List<VariableExp>(segments), semanticExp);

    copy.setType(type);

    return copy;
  }
Example #4
0
  /** Returns a formatted text string of this class. */
  public String toString(int indent) {

    StringBuffer sb = new StringBuffer();

    printSpace(indent, sb);

    sb.append("Iterate \n");
    if (maintaining != null) {
      printSpace(indent, sb);
      sb.append("\tmaintaining " + maintaining.toString(0) + ";\n");
    }
    if (decreasing != null) {
      printSpace(indent, sb);
      sb.append("\tdecreasing " + decreasing.toString(0) + ";\n");
    }
    if (!changing.isEmpty()) {
      printSpace(indent, sb);
      sb.append("\tchanging " + argumentsToString(changing) + ";\n");
    }
    //	printSpace(indent, sb);

    Iterator<Statement> i = statements.iterator();
    while (i.hasNext()) {
      sb.append((i.next()).toString(indent + 4 * 2) + ";\n");
    }
    printSpace(indent, sb);
    sb.append("repeat");

    return sb.toString();
  }
Example #5
0
  /** Returns a formatted text string of this class. */
  public String asString(int indent, int increment) {

    StringBuffer sb = new StringBuffer();

    printSpace(indent, sb);
    sb.append("IterateStmt\n");

    if (changing != null) {
      sb.append(changing.asString(indent + increment, increment));
    }

    if (maintaining != null) {
      sb.append(maintaining.asString(indent + increment, increment));
    }

    if (decreasing != null) {
      sb.append(decreasing.asString(indent + increment, increment));
    }

    if (statements != null) {
      sb.append(statements.asString(indent + increment, increment));
    }

    return sb.toString();
  }
Example #6
0
 public void allLits(int arity, List result, boolean b) {
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     e.allLits(arity, result, b);
   }
 }
Example #7
0
 public boolean removeUnscoped(List vars) {
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     Exp e = i.next();
     if (e.removeUnscoped(vars)) i.remove();
   }
   return false;
 }
Example #8
0
 @Override
 public void accept(GrammarItemVisitor visitor) {
   visitor.visitAssignStm(this);
   if (exp.handleProceedWith(visitor)) {
     exp.accept(visitor);
   }
   visitor.leaveAssignStm(this);
 }
Example #9
0
 void getOuterRefs(Exp e, List<Exp> refs) {
   // now, recurse
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     Exp ex = i.next();
     ex.getOuterRefs(e, refs);
   }
 }
Example #10
0
 public void extractPTypeExps(List l) {
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     e.extractPTypeExps(l);
   }
 }
Example #11
0
 public void allPreds(int arity, List result) {
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     e.allPreds(arity, result);
   }
 }
Example #12
0
 public FunDef resolve(Exp[] args, Validator validator, List<Conversion> conversions) {
   if (args.length != 1) {
     return null;
   }
   final Exp exp = args[0];
   final int category = exp.getCategory();
   final Type type = exp.getType();
   return new CacheFunDef(NAME, SIGNATURE, DESCRIPTION, SYNTAX, category, type);
 }
Example #13
0
  @Override
  public String printAst(int offset) {
    String out = "(REL EXP" + op + " ";
    if (e1 != null) out += e1.printAst(offset + 2) + " ";
    if (e2 != null) out += e2.printAst(offset + 2) + " ";
    out += ")";

    return out;
  }
Example #14
0
  public Exp remember() {
    if (where instanceof OldExp) this.setWhere(((OldExp) (where)).getExp());
    if (body instanceof OldExp) this.setBody(((OldExp) (body)).getExp());

    if (where != null) where = where.remember();
    if (body != null) body = body.remember();

    return this;
  }
Example #15
0
 /** Returns true if the variable is found in any sub expression of this one. * */
 public boolean containsVar(String varName, boolean IsOldExp) {
   if (where != null && where.containsVar(varName, IsOldExp)) {
     return true;
   }
   if (body.containsVar(varName, IsOldExp)) {
     return true;
   }
   return false;
 }
Example #16
0
 public Exp deleteExp(Exp l) {
   IntSet result = new IntSet();
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     Exp e = i.next();
     if (e != l) result.exps.add(e.deleteExp(l));
   }
   return result;
 }
Example #17
0
 public void allSubExps(List result) {
   result.add(this);
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     e.allSubExps(result);
   }
 }
Example #18
0
 public void allSubExps(Type type, List result) {
   if (type == null || type().equals(type)) result.add(this);
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     e.allSubExps(type, result);
   }
 }
Example #19
0
 public void allSubExps(String type, List result) {
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     if (e.getClass().getName().equals(type)) result.add(e);
     e.allSubExps(type, result);
   }
 }
Example #20
0
 public int expCount(int eq, Exp e) {
   int count = 0;
   if (equals(eq, e)) count++;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     Exp ex = i.next();
     count += ex.expCount(eq, e);
   }
   return count;
 }
Example #21
0
 public int predCount(Object p) {
   int result = 0;
   Exp e;
   Iterator<Exp> i = exps.iterator();
   while (i.hasNext()) {
     e = i.next();
     result += e.predCount(p);
   }
   return result;
 }
Example #22
0
 public Type inferType(List<Var> vars, List<List<Type>> varTypes) {
   for (Exp e : exps) {
     Type t = e.inferType(vars, varTypes);
     if (t == null || !t.subType(PType.E)) {
       inferedType = null; // update cache
       return null;
     }
   }
   inferedType = FType.ET; // update cache
   return FType.ET; // could we infer subtypes here?
 }
Example #23
0
  public Exp instReplace(Exp olde, Exp newe) {
    if (this == olde) return newe;

    Exp e;
    for (int i = 0; i < exps.size(); i++) {
      e = exps.get(i);
      exps.set(i, e.instReplace(olde, newe));
      e = exps.get(i);
      if (e == null) return null;
    }
    return this;
  }
Example #24
0
  public int expCount(int id) {
    int result = 0;
    Exp ex;
    Iterator<Exp> i;

    i = exps.iterator();
    while (i.hasNext()) {
      ex = i.next();
      result += ex.expCount(id);
    }
    return result;
  }
Example #25
0
  public int repeatExpCount(int t, Exp e) {
    int result = 0;
    Exp ex;
    Iterator<Exp> i;

    i = exps.iterator();
    while (i.hasNext()) {
      ex = i.next();
      result += ex.repeatExpCount(t, e);
    }
    return result;
  }
Example #26
0
  public int repeatPredCount(int t, Object p) {
    int result = 0;
    Exp e;
    Iterator<Exp> i;

    i = exps.iterator();
    while (i.hasNext()) {
      e = i.next();
      result += e.repeatPredCount(t, p);
    }
    return result;
  }
Example #27
0
 public Exp replace(Exp olde, Exp newe) {
   // System.out.println("Exps: "+exps);
   if (equals(olde)) return newe;
   Exp e;
   for (int i = 0; i < exps.size(); i++) {
     e = exps.get(i);
     if (e.equals(olde)) exps.set(i, newe);
     else exps.set(i, e.replace(olde, newe));
     e = exps.get(i);
     if (e == null) return null;
   }
   return this;
 }
Example #28
0
  public Exp substituteChildren(java.util.Map<Exp, Exp> substitutions) {
    Exp retval;

    List<ProgramExp> newArguments = new List<ProgramExp>();
    for (ProgramExp a : arguments) {
      newArguments.add((ProgramExp) substitute(a, substitutions));
    }

    retval =
        new ProgramParamExp(
            location, name, newArguments, (ProgramExp) substitute(semanticExp, substitutions));

    retval.setType(type);
    return retval;
  }
Example #29
0
 public void prettyPrint() {
   if (myLineNumber != null) {
     System.out.print(myLineNumber.getName() + ": ");
   }
   System.out.print("Goal ");
   exp.prettyPrint();
 }
Example #30
0
 public void extractFuncts(List functors, List functees, Exp orig) {
   List vars = body.freeVars();
   if (vars.size() == 1) {
     Var v = (Var) vars.get(0);
     Exp functee = new Funct(v, body.copy());
     Var v2 = new Var(functee.type());
     Appl a = new Appl(v2, v);
     Exp e = body;
     body = a;
     Exp functorbody = orig.copy();
     body = e;
     Exp functor = new Funct(v2, functorbody);
     functors.add(functor);
     functees.add(functee);
   }
   body.extractFuncts(functors, functees, orig);
 }