Search in sources :

Example 1 with Concatter

use of com.google.devtools.build.lib.syntax.Concatable.Concatter in project bazel by bazelbuild.

the class BinaryOperatorExpression method plus.

/** Implements Operator.PLUS. */
private static Object plus(Object lval, Object rval, Environment env, Location location) throws EvalException {
    // int + int
    if (lval instanceof Integer && rval instanceof Integer) {
        return ((Integer) lval).intValue() + ((Integer) rval).intValue();
    }
    // string + string
    if (lval instanceof String && rval instanceof String) {
        return (String) lval + (String) rval;
    }
    if (lval instanceof SelectorValue || rval instanceof SelectorValue || lval instanceof SelectorList || rval instanceof SelectorList) {
        return SelectorList.concat(location, lval, rval);
    }
    if ((lval instanceof Tuple) && (rval instanceof Tuple)) {
        return Tuple.copyOf(Iterables.concat((Tuple) lval, (Tuple) rval));
    }
    if ((lval instanceof MutableList) && (rval instanceof MutableList)) {
        return MutableList.concat((MutableList) lval, (MutableList) rval, env);
    }
    if (lval instanceof SkylarkDict && rval instanceof SkylarkDict) {
        return SkylarkDict.plus((SkylarkDict<?, ?>) lval, (SkylarkDict<?, ?>) rval, env);
    }
    if (lval instanceof Concatable && rval instanceof Concatable) {
        Concatable lobj = (Concatable) lval;
        Concatable robj = (Concatable) rval;
        Concatter concatter = lobj.getConcatter();
        if (concatter != null && concatter.equals(robj.getConcatter())) {
            return concatter.concat(lobj, robj, location);
        } else {
            throw typeException(lval, rval, Operator.PLUS, location);
        }
    }
    // TODO(bazel-team): Remove this case. Union of sets should use '|' instead of '+'.
    if (lval instanceof SkylarkNestedSet) {
        return new SkylarkNestedSet((SkylarkNestedSet) lval, rval, location);
    }
    throw typeException(lval, rval, Operator.PLUS, location);
}
Also used : MutableList(com.google.devtools.build.lib.syntax.SkylarkList.MutableList) Concatter(com.google.devtools.build.lib.syntax.Concatable.Concatter) Tuple(com.google.devtools.build.lib.syntax.SkylarkList.Tuple)

Aggregations

Concatter (com.google.devtools.build.lib.syntax.Concatable.Concatter)1 MutableList (com.google.devtools.build.lib.syntax.SkylarkList.MutableList)1 Tuple (com.google.devtools.build.lib.syntax.SkylarkList.Tuple)1