private void introduceLetClauses(List<Pair<Expression, VarIdentifier>> fromBindingList, List<AbstractClause> toLetWhereList) { for (Pair<Expression, VarIdentifier> p : fromBindingList) { Expression bindExpr = p.first; VarIdentifier var = p.second; VariableExpr varExpr = new VariableExpr(var); varExpr.setSourceLocation(bindExpr.getSourceLocation()); toLetWhereList.add(new LetClause(varExpr, bindExpr)); context.addExcludedForFieldAccessVar(var); } fromBindingList.clear(); }
final public LetClause LetElement() throws ParseException, ParseException { VariableExpr varExp; Expression beExp; extendCurrentScope(); varExp = Variable(); jj_consume_token(EQ); beExp = Expression(); LetClause lc = new LetClause(varExp, beExp); lc.setSourceLocation(varExp.getSourceLocation()); {if (true) return lc;} throw new Error("Missing return statement in function"); }
final public LetClause WithElement() throws ParseException, ParseException { VariableExpr varExp; Expression beExp; extendCurrentScope(); varExp = Variable(); jj_consume_token(AS); beExp = Expression(); LetClause lc = new LetClause(varExp, beExp); lc.setSourceLocation(varExp.getSourceLocation()); {if (true) return lc;} throw new Error("Missing return statement in function"); }
private void wrapInLets() { // If the top expression of the main statement is not a FLWOR, it wraps // it into a let clause. if (topStatement == null) { return; } Expression body = topStatement.getBody(); if (body.getKind() != Kind.FLWOGR_EXPRESSION) { VarIdentifier var = context.newVariable(); VariableExpr v = new VariableExpr(var); LetClause c1 = new LetClause(v, body); ArrayList<Clause> clauseList = new ArrayList<>(1); clauseList.add(c1); FLWOGRExpression newBody = new FLWOGRExpression(clauseList, new VariableExpr(var)); topStatement.setBody(newBody); } }
@Override public LetClause visit(LetClause letClause, Void arg) throws CompilationException { LetClause copy = new LetClause((VariableExpr) letClause.getVarExpr().accept(this, arg), (Expression) letClause.getBindingExpr().accept(this, arg)); copy.setSourceLocation(letClause.getSourceLocation()); return copy; }
private void introduceLetClauses(Map<Expression, VarIdentifier> letVarMap, Map<Expression, ColumnAliasBinding> aliasBindingMap, SelectBlock selectBlock) throws CompilationException { List<AbstractClause> targetLetClauses = selectBlock.hasGroupbyClause() ? selectBlock.getLetHavingListAfterGroupby() : selectBlock.getLetWhereList(); for (Map.Entry<Expression, VarIdentifier> me : letVarMap.entrySet()) { Expression columnAliasVarExpr = me.getKey(); SourceLocation sourceLoc = columnAliasVarExpr.getSourceLocation(); ColumnAliasBinding columnAliasBinding = aliasBindingMap.get(columnAliasVarExpr); if (columnAliasBinding == null) { throw new CompilationException(ErrorCode.COMPILATION_ILLEGAL_STATE, sourceLoc); } VarIdentifier letVarId = me.getValue(); // add a let clause defining the new variable VariableExpr letVarDefExpr = new VariableExpr(letVarId); letVarDefExpr.setSourceLocation(sourceLoc); LetClause newLetClause = new LetClause(letVarDefExpr, columnAliasBinding.getExpression()); newLetClause.setSourceLocation(sourceLoc); targetLetClauses.add(newLetClause); // replace original column alias expression with variable reference VariableExpr letVarRefExpr = new VariableExpr(letVarId); letVarRefExpr.setSourceLocation(sourceLoc); columnAliasBinding.setExpression(letVarRefExpr); context.addExcludedForFieldAccessVar(letVarId); } }
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(LetClause lc, VariableSubstitutionEnvironment env) throws CompilationException { Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = lc.getBindingExpr().accept(this, env); VariableExpr varExpr = lc.getVarExpr(); VariableExpr newVe = generateNewVariable(context, varExpr); LetClause newLet = new LetClause(newVe, (Expression) p1.first); newLet.setSourceLocation(lc.getSourceLocation()); return new Pair<>(newLet, VariableCloneAndSubstitutionUtil.eliminateSubstFromList(lc.getVarExpr(), env)); }
final public Clause LetClause() throws ParseException, ParseException { LetClause lc = new LetClause(); VariableExpr varExp; Expression beExp; extendCurrentScope(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LET: jj_consume_token(LET); break; case WITH: jj_consume_token(WITH); break; default: jj_la1[33] = jj_gen; jj_consume_token(-1); throw new ParseException(); } varExp = Variable(); jj_consume_token(ASSIGN); beExp = Expression(); getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); lc.setVarExpr(varExp); lc.setBindingExpr(beExp); {if (true) return lc;} throw new Error("Missing return statement in function"); }
final public Clause LetClause() throws ParseException, ParseException { LetClause lc = new LetClause(); VariableExpr varExp; Expression beExp; extendCurrentScope(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LET: jj_consume_token(LET); break; case WITH: jj_consume_token(WITH); break; default: jj_la1[103] = jj_gen; jj_consume_token(-1); throw new ParseException(); } varExp = Variable(); jj_consume_token(ASSIGN); beExp = Expression(); getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); lc.setVarExpr(varExp); lc.setBindingExpr(beExp); {if (true) return lc;} throw new Error("Missing return statement in function"); }
VariableExpr newVRef1 = new VariableExpr(newV); newVRef1.setSourceLocation(sourceLoc); LetClause c = new LetClause(newVRef1, (Expression) p1.first); c.setSourceLocation(sourceLoc); clauses.add(c);