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; }
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; }
/** 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(); }
/** 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(); }
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); } }
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; }
@Override public void accept(GrammarItemVisitor visitor) { visitor.visitAssignStm(this); if (exp.handleProceedWith(visitor)) { exp.accept(visitor); } visitor.leaveAssignStm(this); }
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); } }
public void extractPTypeExps(List l) { Exp e; Iterator<Exp> i = exps.iterator(); while (i.hasNext()) { e = i.next(); e.extractPTypeExps(l); } }
public void allPreds(int arity, List result) { Exp e; Iterator<Exp> i = exps.iterator(); while (i.hasNext()) { e = i.next(); e.allPreds(arity, result); } }
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); }
@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; }
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; }
/** 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; }
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; }
public void allSubExps(List result) { result.add(this); Exp e; Iterator<Exp> i = exps.iterator(); while (i.hasNext()) { e = i.next(); e.allSubExps(result); } }
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); } }
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); } }
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; }
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; }
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? }
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; }
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; }
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; }
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; }
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; }
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; }
public void prettyPrint() { if (myLineNumber != null) { System.out.print(myLineNumber.getName() + ": "); } System.out.print("Goal "); exp.prettyPrint(); }
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); }