Ejemplo n.º 1
0
func (n *operatorNode) connectable1(t types.Type, dst *port) bool {
	if n.op == "==" || n.op == "!=" {
		switch underlying(t).(type) {
		case *types.Slice, *types.Map, *types.Signature:
			// these types are comparable only with nil
			other := n.ins[0]
			if other == dst {
				other = n.ins[1]
			}
			return len(other.conns) == 0
		}
		return types.Comparable(t)
	}
	b, ok := underlying(t).(*types.Basic)
	if !ok {
		return false
	}
	i := b.Info
	switch n.op {
	case "!", "&&", "||":
		return i&types.IsBoolean != 0
	case "+":
		return i&(types.IsString|types.IsNumeric) != 0
	case "-", "*", "/":
		return i&types.IsNumeric != 0
	case "%", "&", "|", "^", "&^", "<<", ">>":
		if (n.op == "<<" || n.op == ">>") && dst == n.ins[1] {
			return i&types.IsUnsigned != 0
		}
		return i&types.IsInteger != 0
	case "<", "<=", ">", ">=":
		return i&types.IsOrdered != 0
	}
	panic(n.op)
}
Ejemplo n.º 2
0
func isComparableType(obj types.Object) bool {
	switch obj {
	case protoPointer, protoArray, protoChan, protoInterface, protoStruct:
		return true
	}
	t, ok := obj.(*types.TypeName)
	return ok && t.GetType() != nil && types.Comparable(t.GetType())
}