first steps

This commit is contained in:
Araq 2014-07-20 01:06:03 +02:00
commit 0297c61378
7 changed files with 45 additions and 26 deletions

View file

@ -768,6 +768,8 @@ type
# it won't cause problems
TTypeSeq* = seq[PType]
TTypeAttachedOp* = enum
attachedDestructor, attachedAsgn, attachedDeepCopy
TType* {.acyclic.} = object of TIdObj # \
# types are identical iff they have the
# same id; there may be multiple copies of a type
@ -785,12 +787,13 @@ type
# the body of the user-defined type class
# formal param list
# else: unused
destructor*: PSym # destructor. warning: nil here may not necessary
# mean that there is no destructor.
# see instantiateDestructor in types.nim
owner*: PSym # the 'owner' of the type
sym*: PSym # types have the sym associated with them
# it is used for converting types to strings
attachedOp*: array[TTypeAttachedOp, PSym] # \
# destructor. warning: nil here may not necessary
# mean that there is no destructor.
# see instantiateDestructor in types.nim
size*: BiggestInt # the size of the type in bytes
# -1 means that the size is unkwown
align*: int # the type's alignment requirements
@ -1189,7 +1192,7 @@ proc assignType(dest, src: PType) =
dest.n = src.n
dest.size = src.size
dest.align = src.align
dest.destructor = src.destructor
dest.attachedOps = src.attachedOps
# this fixes 'type TLock = TSysLock':
if src.sym != nil:
if dest.sym != nil:

View file

@ -214,9 +214,9 @@ proc optAsgnLoc(a: TLoc, t: PType, field: PRope): TLoc =
proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
let newflags =
if src.k == locData:
flags + { needToCopy }
flags + {needToCopy}
elif tfShallow in dest.t.flags:
flags - { needToCopy }
flags - {needToCopy}
else:
flags
for i in 0 .. <dest.t.len:
@ -230,9 +230,9 @@ proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags,
if t == nil: return
let newflags =
if src.k == locData:
flags + { needToCopy }
flags + {needToCopy}
elif tfShallow in dest.t.flags:
flags - { needToCopy }
flags - {needToCopy}
else:
flags
case t.kind

View file

@ -332,7 +332,7 @@ const
errUsingNoSymbol: "'$1' is not a variable, constant or a proc name",
errMacroBodyDependsOnGenericTypes: "the macro body cannot be compiled, " &
"because the parameter '$1' has a generic type",
errDestructorNotGenericEnough: "Destructor signarue is too specific. " &
errDestructorNotGenericEnough: "Destructor signature is too specific. " &
"A destructor must be associated will all instantiations of a generic type",
errInlineIteratorsAsProcParams: "inline iterators can be used as parameters only for " &
"templates, macros and other inline iterators",

View file

@ -42,7 +42,7 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
localError(n.info, errDestructorNotGenericEnough)
return
t.destructor = s
t.attachedOp[attachedDestructor] = s
# automatically insert calls to base classes' destructors
if n.sons[bodyPos].kind != nkEmpty:
for i in countup(0, t.sonsLen - 1):
@ -52,7 +52,7 @@ proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
let destructableT = instantiateDestructor(c, t.sons[i])
if destructableT != nil:
n.sons[bodyPos].addSon(newNode(nkCall, t.sym.info, @[
useSym(destructableT.destructor),
useSym(destructableT.attachedOp[attachedDestructor]),
n.sons[paramsPos][1][0]]))
proc destroyFieldOrFields(c: PContext, field: PNode, holder: PNode): PNode
@ -61,7 +61,7 @@ proc destroySym(c: PContext, field: PSym, holder: PNode): PNode =
let destructableT = instantiateDestructor(c, field.typ)
if destructableT != nil:
result = newNode(nkCall, field.info, @[
useSym(destructableT.destructor),
useSym(destructableT.attachedOp[attachedDestructor]),
newNode(nkDotExpr, field.info, @[holder, useSym(field)])])
proc destroyCase(c: PContext, n: PNode, holder: PNode): PNode =
@ -128,10 +128,10 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
let typeHoldingUserDefinition = if t.kind == tyGenericInst: t.base
else: t
if typeHoldingUserDefinition.destructor != nil:
if typeHoldingUserDefinition.attachedOp[attachedDestructor] != nil:
# XXX: This is not entirely correct for recursive types, but we need
# it temporarily to hide the "destroy is already defined" problem
if typeHoldingUserDefinition.destructor notin
if typeHoldingUserDefinition.attachedOp[attachedDestructor] notin
[analyzingDestructor, destructorIsTrivial]:
return typeHoldingUserDefinition
else:
@ -143,12 +143,12 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
if instantiateDestructor(c, t.sons[0]) != nil:
if rangeDestructorProc == nil:
rangeDestructorProc = searchInScopes(c, getIdent"nimDestroyRange")
t.destructor = rangeDestructorProc
t.attachedOp[attachedDestructor] = rangeDestructorProc
return t
else:
return nil
of tyTuple, tyObject:
t.destructor = analyzingDestructor
t.attachedOp[attachedDestructor] = analyzingDestructor
let generated = generateDestructor(c, t)
if generated != nil:
internalAssert t.sym != nil
@ -169,10 +169,10 @@ proc instantiateDestructor(c: PContext, typ: PType): PType =
generated
])
let semantizedDef = semProc(c, fullDef)
t.destructor = semantizedDef[namePos].sym
t.attachedOp[attachedDestructor] = semantizedDef[namePos].sym
return t
else:
t.destructor = destructorIsTrivial
t.attachedOp[attachedDestructor] = destructorIsTrivial
return nil
else:
return nil
@ -226,7 +226,7 @@ proc insertDestructors(c: PContext,
tryStmt.addSon(
newNode(nkFinally, info, @[
semStmt(c, newNode(nkCall, info, @[
useSym(destructableT.destructor),
useSym(destructableT.attachedOp[attachedDestructor]),
useSym(varId.sym)]))]))
result.outer = newNodeI(nkStmtList, info)

View file

@ -325,7 +325,7 @@ proc suggestSym*(info: TLineInfo; s: PSym) {.inline.} =
if isServing:
addToSourceMap(s, info)
proc markUsed(info: TLineInfo; s: PSym) =
proc markUsed*(info: TLineInfo; s: PSym) =
incl(s.flags, sfUsed)
if {sfDeprecated, sfError} * s.flags != {}:
if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)