Beispiel #1
0
func composeInts(expr *ast.Expr) (funcs.Ints, error) {
	uniq, err := prep(expr, types.LIST_INT)
	if err != nil {
		return nil, err
	}
	if expr.List != nil {
		vs, err := newValues(expr.GetList().GetElems())
		if err != nil {
			return nil, err
		}
		bs := make([]funcs.Int, len(vs))
		var ok bool
		for i := range vs {
			bs[i], ok = vs[i].(funcs.Int)
			if !ok {
				return nil, &errExpected{types.SINGLE_INT.String(), expr.String()}
			}
		}
		return funcs.NewListOfInt(bs), nil
	}
	values, err := newValues(expr.GetFunction().GetParams())
	if err != nil {
		return nil, err
	}
	return funcs.NewIntsFunc(uniq, values...)
}
Beispiel #2
0
//Which returns the type that the expression will return.
func Which(expr *ast.Expr) (types.Type, error) {
	if expr.Terminal != nil {
		term := expr.GetTerminal()
		if term.DoubleValue != nil {
			return types.SINGLE_DOUBLE, nil
		}
		if term.IntValue != nil {
			return types.SINGLE_INT, nil
		}
		if term.UintValue != nil {
			return types.SINGLE_UINT, nil
		}
		if term.BoolValue != nil {
			return types.SINGLE_BOOL, nil
		}
		if term.StringValue != nil {
			return types.SINGLE_STRING, nil
		}
		if term.BytesValue != nil {
			return types.SINGLE_BYTES, nil
		}
		if term.Variable != nil {
			return term.Variable.Type, nil
		}
	}
	if expr.List != nil {
		return expr.GetList().GetType(), nil
	}
	if expr.Function != nil {
		fnc := expr.GetFunction()
		uniq, err := WhichFunc(fnc)
		if err != nil {
			return 0, err
		}
		return funcs.Out(uniq)
	}
	return 0, &errUnknownType{expr}
}