fix comments
This commit is contained in:
parent
4d87d666ee
commit
a65e9c0e25
2 changed files with 52 additions and 23 deletions
|
|
@ -633,26 +633,21 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc typeRangeRel(f, a: PType): TTypeRelation {.noinline.} =
|
proc typeRangeRel(f, a: PType): TTypeRelation {.noinline.} =
|
||||||
template check_range_in(t: typedesc): untyped =
|
template check_range[T](a_first, a_last, f_first, f_last: T): TTypeRelation =
|
||||||
let
|
if a_first == f_first and a_last == f_last:
|
||||||
a0 = firstValue[t](a)
|
isEqual
|
||||||
a1 = lastValue[t](a)
|
elif a_first >= f_first and a_last <= f_last:
|
||||||
f0 = firstValue[t](f)
|
isConvertible
|
||||||
f1 = lastValue[t](f)
|
elif a_first <= f_last and f_first <= a_last:
|
||||||
if a0 == f0 and a1 == f1:
|
|
||||||
result = isEqual
|
|
||||||
elif a0 >= f0 and a1 <= f1:
|
|
||||||
result = isConvertible
|
|
||||||
elif a0 <= f1 and f0 <= a1:
|
|
||||||
# X..Y and C..D overlap iff (X <= D and C <= Y)
|
# X..Y and C..D overlap iff (X <= D and C <= Y)
|
||||||
result = isConvertible
|
isConvertible
|
||||||
else:
|
else:
|
||||||
result = isNone
|
isNone
|
||||||
|
|
||||||
if f.isOrdinalType:
|
if f.isOrdinalType:
|
||||||
check_range_in(BiggestInt)
|
check_range(firstOrd(a), lastOrd(a), firstOrd(f), lastOrd(f))
|
||||||
else:
|
else:
|
||||||
check_range_in(BiggestFloat)
|
check_range(firstFloat(a), lastFloat(a), firstFloat(f), lastFloat(f))
|
||||||
|
|
||||||
|
|
||||||
proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||||
|
|
|
||||||
|
|
@ -88,13 +88,16 @@ proc isPureObject*(typ: PType): bool =
|
||||||
|
|
||||||
proc getOrdValue*(n: PNode): BiggestInt =
|
proc getOrdValue*(n: PNode): BiggestInt =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkCharLit..nkUInt64Lit: result = n.intVal
|
of nkCharLit..nkUInt64Lit: n.intVal
|
||||||
of nkNilLit: result = 0
|
of nkNilLit: 0
|
||||||
of nkHiddenStdConv: result = getOrdValue(n.sons[1])
|
of nkHiddenStdConv: getOrdValue(n.sons[1])
|
||||||
else:
|
else: high(BiggestInt)
|
||||||
#localError(n.info, errOrdinalTypeExpected)
|
|
||||||
# XXX check usages of getOrdValue
|
proc getFloatValue*(n: PNode): BiggestFloat =
|
||||||
result = high(BiggestInt)
|
case n.kind
|
||||||
|
of nkFloatLiterals: n.floatVal
|
||||||
|
of nkHiddenStdConv: getFloatValue(n.sons[1])
|
||||||
|
else: NaN
|
||||||
|
|
||||||
proc isIntLit*(t: PType): bool {.inline.} =
|
proc isIntLit*(t: PType): bool {.inline.} =
|
||||||
result = t.kind == tyInt and t.n != nil and t.n.kind == nkIntLit
|
result = t.kind == tyInt and t.n != nil and t.n.kind == nkIntLit
|
||||||
|
|
@ -623,6 +626,21 @@ proc firstOrd*(t: PType): BiggestInt =
|
||||||
internalError(newPartialConfigRef(), "invalid kind for firstOrd(" & $t.kind & ')')
|
internalError(newPartialConfigRef(), "invalid kind for firstOrd(" & $t.kind & ')')
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
|
|
||||||
|
proc firstFloat*(t: PType): BiggestFloat =
|
||||||
|
case t.kind
|
||||||
|
of tyFloat..tyFloat128: -Inf
|
||||||
|
of tyRange:
|
||||||
|
assert(t.n != nil) # range directly given:
|
||||||
|
assert(t.n.kind == nkRange)
|
||||||
|
getFloatValue(t.n.sons[0])
|
||||||
|
of tyVar: firstFloat(t.sons[0])
|
||||||
|
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tyStatic, tyInferred:
|
||||||
|
firstFloat(lastSon(t))
|
||||||
|
else:
|
||||||
|
internalError(newPartialConfigRef(), "invalid kind for firstValue(" & $t.kind & ')')
|
||||||
|
NaN
|
||||||
|
|
||||||
proc lastOrd*(t: PType; fixedUnsigned = false): BiggestInt =
|
proc lastOrd*(t: PType; fixedUnsigned = false): BiggestInt =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyBool: result = 1
|
of tyBool: result = 1
|
||||||
|
|
@ -663,6 +681,22 @@ proc lastOrd*(t: PType; fixedUnsigned = false): BiggestInt =
|
||||||
internalError(newPartialConfigRef(), "invalid kind for lastOrd(" & $t.kind & ')')
|
internalError(newPartialConfigRef(), "invalid kind for lastOrd(" & $t.kind & ')')
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
|
|
||||||
|
proc lastFloat*(t: PType): BiggestFloat =
|
||||||
|
case t.kind
|
||||||
|
of tyFloat..tyFloat128: Inf
|
||||||
|
of tyVar: lastFloat(t.sons[0])
|
||||||
|
of tyRange:
|
||||||
|
assert(t.n != nil) # range directly given:
|
||||||
|
assert(t.n.kind == nkRange)
|
||||||
|
getFloatValue(t.n.sons[1])
|
||||||
|
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tyStatic, tyInferred:
|
||||||
|
lastFloat(lastSon(t))
|
||||||
|
else:
|
||||||
|
internalError(newPartialConfigRef(), "invalid kind for lastOrd(" & $t.kind & ')')
|
||||||
|
NaN
|
||||||
|
|
||||||
|
|
||||||
proc lengthOrd*(t: PType): BiggestInt =
|
proc lengthOrd*(t: PType): BiggestInt =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyInt64, tyInt32, tyInt: result = lastOrd(t)
|
of tyInt64, tyInt32, tyInt: result = lastOrd(t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue