@Override public void visit(FunctionCall call) { if (includeFunctionNames) { call.getFunction().accept(this); } for (SEXP expr : call.getArguments().values()) { expr.accept(this); } }
@Override public Vector.Builder copySomeAttributesFrom(SEXP exp, Symbol... toCopy) { if (exp.getAttributes() != Null.INSTANCE) { throw new UnsupportedOperationException(NULL_IS_IMMUTABLE); } return this; }
private Function evaluateFunction(SEXP functionExp, Environment rho) { if (functionExp instanceof Symbol) { Symbol symbol = (Symbol) functionExp; Function fn = rho.findFunction(this, symbol); if (fn == null) { throw new EvalException("could not find function '%s'", symbol.getPrintName()); } return fn; } else { SEXP evaluated = evaluate(functionExp, rho).force(this); if (!(evaluated instanceof Function)) { throw new EvalException( "'function' of lang expression is of unsupported type '%s'", evaluated.getTypeName()); } return (Function) evaluated; } }
@Internal("all.names") public static StringVector allNames(SEXP expr, boolean function, int maxNames, boolean unique) { AllNamesVisitor visitor = new AllNamesVisitor(); visitor.includeFunctionNames = function; visitor.maxNames = maxNames; visitor.unique = unique; expr.accept(visitor); return visitor.names.build(); }
@Override public int hashCode() { int result = 1; PairList.Node node = this; while (true) { result = 31 * result + (tag != null ? tag.hashCode() : 0); result = 31 * result + (node.value != null ? node.value.hashCode() : 0); if (node.nextNode == Null.INSTANCE) { break; } node = (Node) node.nextNode; } return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Node node = (Node) o; if (nextNode != null ? !nextNode.equals(node.nextNode) : node.nextNode != null) { return false; } if (tag != null ? !tag.equals(node.tag) : node.tag != null) { return false; } if (value != null ? !value.equals(node.value) : node.value != null) { return false; } return true; }
public SEXP evaluate(SEXP expression, Environment rho) { if (expression instanceof Symbol) { return evaluateSymbol((Symbol) expression, rho); } else if (expression instanceof ExpressionVector) { return evaluateExpressionVector((ExpressionVector) expression, rho); } else if (expression instanceof FunctionCall) { return evaluateCall((FunctionCall) expression, rho); } else if (expression instanceof Promise) { return expression.force(this); } else if (expression != Null.INSTANCE && expression instanceof PromisePairList) { throw new EvalException("'...' used in an incorrect context"); } else { clearInvisibleFlag(); return expression; } }
private static SubstituteContext buildContext(Context context, SEXP evaluatedEnv) { if (evaluatedEnv instanceof Environment) { if (context.getGlobalEnvironment() == evaluatedEnv) { return new GlobalEnvironmentContext(); } else { return new EnvironmentContext((Environment) evaluatedEnv); } } else if (evaluatedEnv instanceof ListVector) { return new ListContext((ListVector) evaluatedEnv); } else if (evaluatedEnv instanceof PairList) { return new PairListContext((PairList) evaluatedEnv); } else { throw new EvalException( "Cannot substitute using environment of type %s: expected list, pairlist, or environment", evaluatedEnv.getTypeName()); } }
@Override public void visit(ExpressionVector vector) { for (SEXP expr : vector) { expr.accept(this); } }
private static SEXP substitute(SEXP exp, SubstituteContext context) { SubstitutingVisitor visitor = new SubstitutingVisitor(context); exp.accept(visitor); return visitor.getResult(); }