Add sizeof for arrays of integral types (#8445)
This commit is contained in:
parent
c3a9ac4d35
commit
404f0d64af
2 changed files with 21 additions and 3 deletions
|
|
@ -609,7 +609,7 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
||||||
if computeSize(g.config, a.typ) < 0:
|
if computeSize(g.config, a.typ) < 0:
|
||||||
localError(g.config, a.info, "cannot evaluate 'sizeof' because its type is not defined completely")
|
localError(g.config, a.info, "cannot evaluate 'sizeof' because its type is not defined completely")
|
||||||
result = nil
|
result = nil
|
||||||
elif skipTypes(a.typ, typedescInst+{tyRange}).kind in
|
elif skipTypes(a.typ, typedescInst+{tyRange, tyArray}).kind in
|
||||||
IntegralTypes+NilableTypes+{tySet}:
|
IntegralTypes+NilableTypes+{tySet}:
|
||||||
#{tyArray,tyObject,tyTuple}:
|
#{tyArray,tyObject,tyTuple}:
|
||||||
result = newIntNodeT(getSize(g.config, a.typ), n, g)
|
result = newIntNodeT(getSize(g.config, a.typ), n, g)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# Test the sizeof proc
|
discard """
|
||||||
|
file: "tsize.nim"
|
||||||
|
output: "40 3 12 32"
|
||||||
|
"""
|
||||||
type
|
type
|
||||||
TMyRecord {.final.} = object
|
TMyRecord {.final.} = object
|
||||||
x, y: int
|
x, y: int
|
||||||
|
|
@ -7,4 +9,20 @@ type
|
||||||
r: float
|
r: float
|
||||||
s: string
|
s: string
|
||||||
|
|
||||||
|
TMyEnum = enum
|
||||||
|
tmOne, tmTwo, tmThree, tmFour
|
||||||
|
|
||||||
|
TMyArray1 = array[3, uint8]
|
||||||
|
TMyArray2 = array[1..3, int32]
|
||||||
|
TMyArray3 = array[TMyEnum, float64]
|
||||||
|
|
||||||
|
const
|
||||||
|
mysize1 = sizeof(TMyArray1)
|
||||||
|
mysize2 = sizeof(TMyArray2)
|
||||||
|
mysize3 = sizeof(TMyArray3)
|
||||||
|
|
||||||
write(stdout, sizeof(TMyRecord))
|
write(stdout, sizeof(TMyRecord))
|
||||||
|
echo ' ', mysize1, ' ', mysize2, ' ',mysize3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue