@Override public void enterExpression(VirtDataParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); }
@Override public void exitVirtdataCall(VirtDataParser.VirtdataCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void exitLvalue(MetagenParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
default List<ResolvedFunction> resolveFunctions(String spec) { List<ResolvedFunction> resolvedFunctions = new ArrayList<>(); VirtDataDSL.ParseResult parseResult = VirtDataDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } List<Expression> expressions = parseResult.flow.getExpressions(); if (expressions.size() > 1) { throw new RuntimeException("Unable to promote a lambda flow to a data mapper here."); } FunctionCall call = expressions.get(0).getCall(); List<ResolvedFunction> found = resolveFunctions( Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null), Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null), call.getFunctionName(), call.getArguments()); resolvedFunctions.addAll(found); return resolvedFunctions; }
@Override public void exitLvalue(VirtDataParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
public static LongUnaryOperator forSpec(String spec) { LambdasDSL.ParseResult parseResult = LambdasDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } MetagenFlow flow = parseResult.flow; if (flow.getExpressions().size()>1) { throw new RuntimeException("Unable to parse flows in " + IntegerDistributions.class); } FunctionCall call = flow.getLastExpression().getCall(); Class<?> inType = Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); Class<?> outType = Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); inType = (inType==null ? long.class : inType); outType = (outType==null ? long.class : outType); List<ResolvedFunction> resolvedFunctions = new IntegerDistributions().resolveFunctions( outType, inType, call.getFunctionName(), call.getArguments() ); if (resolvedFunctions.size()>1) { throw new RuntimeException("Found " + resolvedFunctions.size() + " implementations, be more specific with" + "input or output qualifiers as in int -> or -> long"); } return (LongUnaryOperator) resolvedFunctions.get(0).getFunctionObject(); }
@Override public void enterExpression(LambdasParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); //logger.debug("parsing metagen expression."); }
@Override public void exitVirtdataCall(VirtDataParser.VirtdataCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void exitLvalue(LambdasParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
public static LongToDoubleFunction forSpec(String spec) { LambdasDSL.ParseResult parseResult = LambdasDSL.parse(spec); if (parseResult.throwable!=null) { throw new RuntimeException(parseResult.throwable); } MetagenFlow flow = parseResult.flow; if (flow.getExpressions().size()>1) { throw new RuntimeException("Unable to parse flows in " + IntegerDistributions.class); } FunctionCall call = flow.getLastExpression().getCall(); Class<?> inType = Optional.ofNullable(call.getInputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); Class<?> outType = Optional.ofNullable(call.getOutputType()).map(ValueType::valueOfClassName).map(ValueType::getValueClass).orElse(null); if (inType!=null && inType!=long.class) { throw new RuntimeException("This only supports long for input."); } if (outType!=null && outType!=double.class) { throw new RuntimeException("This only supports double fo routput."); } inType = (inType==null ? long.class : inType); outType = (outType==null ? int.class : outType); List<ResolvedFunction> resolvedFunctions = new RealDistributions().resolveFunctions( outType, inType, call.getFunctionName(), call.getArguments() ); if (resolvedFunctions.size()>1) { throw new RuntimeException("Found " + resolvedFunctions.size() + " implementations, be more specific with" + "input or output qualifiers as in int -> or -> long"); } return ((LongToDoubleFunction) resolvedFunctions.get(0).getFunctionObject()); }
@Override public void enterExpression(VirtDataParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); }
@Override public void exitMetagenCall(MetagenParser.MetagenCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
@Override public void exitLvalue(VirtDataParser.LvalueContext ctx) { flows.peek().getLastExpression().setAssignment(new Assignment(ctx.ID().getSymbol().getText())); }
String specifiedInputClassName = flow.getFirstExpression().getCall().getInputType(); Class<?> specifiedInputClass = ValueType.classOfType(specifiedInputClassName); if (specifiedInputClass!=null) { flow.getFirstExpression().getCall().setInputType(requiredInputType.getCanonicalName()); String specifiedOutputClassName = flow.getLastExpression().getCall().getOutputType(); Class<?> specifiedOutputClass = ValueType.classOfType(specifiedOutputClassName); if (specifiedOutputClass != null) { flow.getLastExpression().getCall().setOutputType(requiredOutputType.getCanonicalName());
@Override public void enterExpression(MetagenParser.ExpressionContext ctx) { expressionContexts.push(ctx); flows.peek().addExpression(new Expression()); //logger.debug("parsing metagen expression."); }
@Override public void exitMetagenCall(LambdasParser.MetagenCallContext ctx) { FunctionCall topFunctionCall = calls.pop(); if (calls.empty()) { flows.peek().getLastExpression().setCall(topFunctionCall); } else { calls.peek().addFunctionArg(topFunctionCall); } callContexts.pop(); }
Optional.ofNullable(flow.getLastExpression().getCall().getOutputType()) .map(ValueType::valueOfClassName).map(ValueType::getValueClass); FunctionCall call = flow.getExpressions().get(i).getCall(); List<ResolvedFunction> nodeFunctions = new LinkedList<>(); List<ResolvedFunction> flattenedFuncs = optimizePath(funcs, ValueType.classOfType(flow.getLastExpression().getCall().getOutputType()));