@Override public Void visit(FunctionDecl fd, Collection<VariableExpr> freeVars) throws CompilationException { fd.getFuncBody().accept(this, freeVars); return null; }
@Override public Boolean visit(FunctionDecl fd, ILangExpression arg) throws CompilationException { return fd.getFuncBody().accept(this, arg); }
@Override public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException { fd.setFuncBody(visit(fd.getFuncBody(), fd)); return null; }
@Override public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException { fd.setFuncBody(visit(fd.getFuncBody(), fd)); return null; }
@Override public Boolean visit(FunctionDecl fd, List<FunctionDecl> arg) throws CompilationException { // Careful, we should only do this after analyzing the graph of function // calls. Pair<Boolean, Expression> p = inlineUdfsInExpr(fd.getFuncBody(), arg); fd.setFuncBody(p.second); return p.first; }
@Override public Void visit(FunctionDecl fd, Integer step) throws CompilationException { out.println(skip(step) + "FunctionDecl " + fd.getSignature().getName() + "(" + fd.getParamList().toString() + ") {"); fd.getFuncBody().accept(this, step + 1); out.println(skip(step) + "}"); out.println(); return null; }
@Override public Void visit(FunctionDecl fd, Integer step) throws CompilationException { out.print(skip(step) + "declare function " + generateFullName(null, fd.getSignature().getName()) + "("); List<Identifier> parameters = new ArrayList<>(); parameters.addAll(fd.getParamList()); printDelimitedIdentifiers(parameters, COMMA); out.println(") {"); fd.getFuncBody().accept(this, step + 2); out.println(); out.print(skip(step) + "}"); out.println(";"); return null; }
@Override public Expression visit(FunctionDecl fd, ILangExpression arg) throws CompilationException { scopeChecker.createNewScope(); fd.setFuncBody(visit(fd.getFuncBody(), fd)); scopeChecker.removeCurrentScope(); return null; }
@Override public FunctionDecl visit(FunctionDecl fd, Void arg) throws CompilationException { FunctionDecl copy = new FunctionDecl(fd.getSignature(), fd.getParamList(), (Expression) fd.getFuncBody().accept(this, arg)); copy.setSourceLocation(fd.getSourceLocation()); return copy; }
functionDecls = retrieveUsedStoredFunctions(metadataProvider, functionDecl.getFuncBody(), declaredFunctions, functionDecls, functionCollector, functionParser, functionNormalizer);
@Override public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FunctionDecl fd, VariableSubstitutionEnvironment env) throws CompilationException { List<VarIdentifier> newList = new ArrayList<>(fd.getParamList().size()); for (VarIdentifier vi : fd.getParamList()) { VariableExpr varExpr = new VariableExpr(vi); if (!env.constainsOldVar(varExpr)) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, fd.getSourceLocation(), "Parameter " + vi + " does not appear in the substitution list."); } Expression newExpr = env.findSubstitution(varExpr); if (newExpr.getKind() != Kind.VARIABLE_EXPRESSION) { throw new CompilationException(ErrorCode.COMPILATION_ERROR, fd.getSourceLocation(), "Parameter " + vi + " cannot be substituted by a non-variable expression."); } newList.add(((VariableExpr) newExpr).getVar()); } Pair<ILangExpression, VariableSubstitutionEnvironment> p1 = fd.getFuncBody().accept(this, env); FunctionDecl newF = new FunctionDecl(fd.getSignature(), newList, (Expression) p1.first); newF.setSourceLocation(fd.getSourceLocation()); return new Pair<>(newF, env); }
implem.getFuncBody().accept(cloneVisitor, subts); Expression resExpr; if (clauses.isEmpty()) {
private Expression rewriteFunctionBody(FunctionDecl fnDecl) throws CompilationException { SourceLocation sourceLoc = fnDecl.getSourceLocation(); Query wrappedQuery = new Query(false); wrappedQuery.setSourceLocation(sourceLoc); wrappedQuery.setBody(fnDecl.getFuncBody()); wrappedQuery.setTopLevel(false); String fnNamespace = fnDecl.getSignature().getNamespace(); Dataverse defaultDataverse = metadataProvider.getDefaultDataverse(); Dataverse fnDataverse; if (fnNamespace == null || fnNamespace.equals(defaultDataverse.getDataverseName())) { fnDataverse = defaultDataverse; } else { try { fnDataverse = metadataProvider.findDataverse(fnNamespace); } catch (AlgebricksException e) { throw new CompilationException(ErrorCode.UNKNOWN_DATAVERSE, e, sourceLoc, fnNamespace); } } metadataProvider.setDefaultDataverse(fnDataverse); try { IQueryRewriter queryRewriter = rewriterFactory.createQueryRewriter(); queryRewriter.rewrite(declaredFunctions, wrappedQuery, metadataProvider, context, true, fnDecl.getParamList()); return wrappedQuery.getBody(); } finally { metadataProvider.setDefaultDataverse(defaultDataverse); } }