// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.rule;

import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.evaluation.Context;
import com.yahoo.searchlib.rankingexpression.evaluation.Value;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.evaluation.TypeContext;

import java.io.Serializable;
import java.util.Deque;

/**
 * Superclass of all expression nodes. Expression nodes have their identity determined by their content.
 * All expression nodes are immutable.
 *
 * @author Simon Thoresen
 */
public abstract class ExpressionNode implements Serializable {

    @Override
    public final int hashCode() {
        return toString().hashCode();
    }

    @Override
    public final boolean equals(Object obj) {
        return obj instanceof ExpressionNode && toString().equals(obj.toString());
    }

    @Override
    public final String toString() {
        return toString(new StringBuilder(), new SerializationContext(), null, null).toString();
    }

    /**
     * Returns a script instance of this based on the supplied script functions.
     *
     * @param context the serialization context
     * @param path the call path to this, used for cycle detection, or null if this is a root
     * @param parent the parent node of this, or null if it a root
     * @return the main script, referring to script instances.
     */
    public abstract StringBuilder toString(StringBuilder builder, SerializationContext context, Deque<String> path, CompositeNode parent);

    /**
     * Returns the type this will return if evaluated with the given context.
     *
     * @param context the variable type bindings to use for this evaluation
     * @throws IllegalArgumentException if there are variables which are not bound in the given map
     */
    public abstract TensorType type(TypeContext<Reference> context);

    /**
     * Returns the value of evaluating this expression over the given context.
     *
     * @param context the variable bindings to use for this evaluation
     * @throws IllegalArgumentException if there are variables which are not bound in the given map
     */
    public abstract Value evaluate(Context context);

}

@@ -1219,32 +1219,97 @@
 nctions.%0A     *%0A
+     * @param builder the StringBuilder that will be appended to%0A
      * @param co
@@ -1708,24 +1708,691 @@
 e parent);%0A%0A
+    /**%0A     * Returns a script instance of this based on the supplied script functions.%0A     * @Deprecated, use the faster one that takes and returns a StringBuilder instead.%0A     *%0A     * @param context the serialization context%0A     * @param path the call path to this, used for cycle detection, or null if this is a root%0A     * @param parent the parent node of this, or null if it a root%0A     * @return the main script, referring to script instances.%0A     */%0A    @Deprecated%0A    public String toString(SerializationContext context, Deque%3CString%3E path, CompositeNode parent) %7B%0A        return toString(new StringBuilder(), context, path, parent).toString();%0A    %7D%0A%0A
     /**%0A    

Add back public interface, now deprecated