added xmltree.innerText; fixes #49
This commit is contained in:
parent
c6038dda04
commit
2183bf77a6
7 changed files with 114 additions and 33 deletions
|
|
@ -1058,8 +1058,7 @@ proc genNew(p: BProc, e: PNode) =
|
||||||
proc genNewSeq(p: BProc, e: PNode) =
|
proc genNewSeq(p: BProc, e: PNode) =
|
||||||
var
|
var
|
||||||
a, b, c: TLoc
|
a, b, c: TLoc
|
||||||
seqtype: PType
|
var seqType = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||||
seqType = skipTypes(e.sons[1].typ, abstractVarRange)
|
|
||||||
InitLocExpr(p, e.sons[1], a)
|
InitLocExpr(p, e.sons[1], a)
|
||||||
InitLocExpr(p, e.sons[2], b)
|
InitLocExpr(p, e.sons[2], b)
|
||||||
initLoc(c, locExpr, a.t, OnHeap)
|
initLoc(c, locExpr, a.t, OnHeap)
|
||||||
|
|
@ -1069,15 +1068,12 @@ proc genNewSeq(p: BProc, e: PNode) =
|
||||||
genAssignment(p, a, c, {})
|
genAssignment(p, a, c, {})
|
||||||
|
|
||||||
proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
|
proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
|
||||||
var
|
var a: TLoc
|
||||||
a: TLoc
|
|
||||||
dest, t: PType
|
|
||||||
r, nilcheck: PRope
|
|
||||||
initLocExpr(p, x, a)
|
initLocExpr(p, x, a)
|
||||||
dest = skipTypes(typ, abstractPtrs)
|
var dest = skipTypes(typ, abstractPtrs)
|
||||||
r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
nilCheck = nil
|
var nilCheck: PRope = nil
|
||||||
t = skipTypes(a.t, abstractInst)
|
var t = skipTypes(a.t, abstractInst)
|
||||||
while t.kind in {tyVar, tyPtr, tyRef}:
|
while t.kind in {tyVar, tyPtr, tyRef}:
|
||||||
if t.kind != tyVar: nilCheck = r
|
if t.kind != tyVar: nilCheck = r
|
||||||
r = ropef("(*$1)", [r])
|
r = ropef("(*$1)", [r])
|
||||||
|
|
@ -1546,7 +1542,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
of mStrToStr: expr(p, e.sons[1], d)
|
of mStrToStr: expr(p, e.sons[1], d)
|
||||||
of mEnumToStr: genRepr(p, e, d)
|
of mEnumToStr: genRepr(p, e, d)
|
||||||
of mAssert:
|
of mAssert:
|
||||||
if (optAssert in p.Options):
|
if optAssert in p.Options:
|
||||||
expr(p, e.sons[1], d)
|
expr(p, e.sons[1], d)
|
||||||
line = toRope(toLinenumber(e.info))
|
line = toRope(toLinenumber(e.info))
|
||||||
filen = makeCString(ToFilename(e.info))
|
filen = makeCString(ToFilename(e.info))
|
||||||
|
|
@ -1689,22 +1685,19 @@ proc genStmtListExpr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
if length > 0: expr(p, n.sons[length - 1], d)
|
if length > 0: expr(p, n.sons[length - 1], d)
|
||||||
|
|
||||||
proc upConv(p: BProc, n: PNode, d: var TLoc) =
|
proc upConv(p: BProc, n: PNode, d: var TLoc) =
|
||||||
var
|
var a: TLoc
|
||||||
a: TLoc
|
|
||||||
dest, t: PType
|
|
||||||
r, nilCheck: PRope
|
|
||||||
initLocExpr(p, n.sons[0], a)
|
initLocExpr(p, n.sons[0], a)
|
||||||
dest = skipTypes(n.typ, abstractPtrs)
|
var dest = skipTypes(n.typ, abstractPtrs)
|
||||||
if (optObjCheck in p.options) and not (isPureObject(dest)):
|
if optObjCheck in p.options and not isPureObject(dest):
|
||||||
r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
nilCheck = nil
|
var nilCheck: PRope = nil
|
||||||
t = skipTypes(a.t, abstractInst)
|
var t = skipTypes(a.t, abstractInst)
|
||||||
while t.kind in {tyVar, tyPtr, tyRef}:
|
while t.kind in {tyVar, tyPtr, tyRef}:
|
||||||
if t.kind != tyVar: nilCheck = r
|
if t.kind != tyVar: nilCheck = r
|
||||||
r = ropef("(*$1)", [r])
|
r = ropef("(*$1)", [r])
|
||||||
t = skipTypes(t.sons[0], abstractInst)
|
t = skipTypes(t.sons[0], abstractInst)
|
||||||
if gCmd != cmdCompileToCpp:
|
if gCmd != cmdCompileToCpp:
|
||||||
while (t.kind == tyObject) and (t.sons[0] != nil):
|
while t.kind == tyObject and t.sons[0] != nil:
|
||||||
app(r, ".Sup")
|
app(r, ".Sup")
|
||||||
t = skipTypes(t.sons[0], abstractInst)
|
t = skipTypes(t.sons[0], abstractInst)
|
||||||
if nilCheck != nil:
|
if nilCheck != nil:
|
||||||
|
|
@ -1753,7 +1746,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
putLocIntoDest(p, d, sym.loc)
|
putLocIntoDest(p, d, sym.loc)
|
||||||
of skProc, skConverter:
|
of skProc, skConverter:
|
||||||
genProc(p.module, sym)
|
genProc(p.module, sym)
|
||||||
if ((sym.loc.r == nil) or (sym.loc.t == nil)):
|
if sym.loc.r == nil or sym.loc.t == nil:
|
||||||
InternalError(e.info, "expr: proc not init " & sym.name.s)
|
InternalError(e.info, "expr: proc not init " & sym.name.s)
|
||||||
putLocIntoDest(p, d, sym.loc)
|
putLocIntoDest(p, d, sym.loc)
|
||||||
of skConst:
|
of skConst:
|
||||||
|
|
@ -1768,7 +1761,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
putIntoDest(p, d, e.typ, toRope(sym.position))
|
putIntoDest(p, d, e.typ, toRope(sym.position))
|
||||||
of skVar, skResult:
|
of skVar, skResult:
|
||||||
if sfGlobal in sym.flags: genVarPrototype(p.module, sym)
|
if sfGlobal in sym.flags: genVarPrototype(p.module, sym)
|
||||||
if ((sym.loc.r == nil) or (sym.loc.t == nil)):
|
if sym.loc.r == nil or sym.loc.t == nil:
|
||||||
InternalError(e.info, "expr: var not init " & sym.name.s)
|
InternalError(e.info, "expr: var not init " & sym.name.s)
|
||||||
if sfThreadVar in sym.flags:
|
if sfThreadVar in sym.flags:
|
||||||
AccessThreadLocalVar(p, sym)
|
AccessThreadLocalVar(p, sym)
|
||||||
|
|
@ -1803,7 +1796,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
genCall(p, e, d)
|
genCall(p, e, d)
|
||||||
of nkCurly: genSetConstr(p, e, d)
|
of nkCurly: genSetConstr(p, e, d)
|
||||||
of nkBracket:
|
of nkBracket:
|
||||||
if (skipTypes(e.typ, abstractVarRange).kind == tySequence):
|
if skipTypes(e.typ, abstractVarRange).kind == tySequence:
|
||||||
genSeqConstr(p, e, d)
|
genSeqConstr(p, e, d)
|
||||||
else:
|
else:
|
||||||
genArrayConstr(p, e, d)
|
genArrayConstr(p, e, d)
|
||||||
|
|
|
||||||
|
|
@ -489,13 +489,16 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
InternalError(a.info, "semTypeSection: containerID")
|
InternalError(a.info, "semTypeSection: containerID")
|
||||||
s.typ.containerID = getID()
|
s.typ.containerID = getID()
|
||||||
a.sons[1] = semGenericParamList(c, a.sons[1], s.typ)
|
a.sons[1] = semGenericParamList(c, a.sons[1], s.typ)
|
||||||
|
s.typ.size = -1 # could not be computed properly
|
||||||
# we fill it out later. For magic generics like 'seq', it won't be filled
|
# we fill it out later. For magic generics like 'seq', it won't be filled
|
||||||
# so we use tyEmpty instead of nil to not crash for strange conversions
|
# so we use tyEmpty instead of nil to not crash for strange conversions
|
||||||
# like: mydata.seq
|
# like: mydata.seq
|
||||||
addSon(s.typ, newTypeS(tyEmpty, c))
|
addSon(s.typ, newTypeS(tyEmpty, c))
|
||||||
s.ast = a
|
s.ast = a
|
||||||
var body = semTypeNode(c, a.sons[2], nil)
|
var body = semTypeNode(c, a.sons[2], nil)
|
||||||
if body != nil: body.sym = s
|
if body != nil:
|
||||||
|
body.sym = s
|
||||||
|
body.size = -1 # could not be computed properly
|
||||||
s.typ.sons[sonsLen(s.typ) - 1] = body
|
s.typ.sons[sonsLen(s.typ) - 1] = body
|
||||||
popOwner()
|
popOwner()
|
||||||
closeScope(c.tab)
|
closeScope(c.tab)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@
|
||||||
|
|
||||||
import ast, astalgo, msgs, types, semdata
|
import ast, astalgo, msgs, types, semdata
|
||||||
|
|
||||||
|
proc checkPartialConstructedType(info: TLineInfo, t: PType) =
|
||||||
|
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
|
||||||
|
LocalError(info, errInvalidPragmaX, "acyclic")
|
||||||
|
elif t.kind == tyVar and t.sons[0].kind == tyVar:
|
||||||
|
LocalError(info, errVarVarTypeNotAllowed)
|
||||||
|
|
||||||
proc checkConstructedType*(info: TLineInfo, t: PType) =
|
proc checkConstructedType*(info: TLineInfo, t: PType) =
|
||||||
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
|
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
|
||||||
LocalError(info, errInvalidPragmaX, "acyclic")
|
LocalError(info, errInvalidPragmaX, "acyclic")
|
||||||
|
|
@ -22,7 +28,7 @@ proc checkConstructedType*(info: TLineInfo, t: PType) =
|
||||||
if t.kind == tyObject and t.sons[0] != nil:
|
if t.kind == tyObject and t.sons[0] != nil:
|
||||||
if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:
|
if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:
|
||||||
localError(info, errInheritanceOnlyWithNonFinalObjects)
|
localError(info, errInheritanceOnlyWithNonFinalObjects)
|
||||||
|
|
||||||
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
||||||
result = t.kind in GenericTypes
|
result = t.kind in GenericTypes
|
||||||
|
|
||||||
|
|
@ -121,10 +127,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
var newbody = ReplaceTypeVarsT(cl, lastSon(body))
|
var newbody = ReplaceTypeVarsT(cl, lastSon(body))
|
||||||
newbody.flags = newbody.flags + t.flags + body.flags
|
newbody.flags = newbody.flags + t.flags + body.flags
|
||||||
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
||||||
addSon(result, newbody)
|
addSon(result, newbody)
|
||||||
#writeln(output, ropeToStr(Typetoyaml(newbody)));
|
#writeln(output, ropeToStr(Typetoyaml(newbody)));
|
||||||
checkConstructedType(cl.info, newbody)
|
checkPartialConstructedType(cl.info, newbody)
|
||||||
|
|
||||||
proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result = t
|
result = t
|
||||||
if t == nil: return
|
if t == nil: return
|
||||||
|
|
@ -139,6 +145,7 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
else:
|
else:
|
||||||
if containsGenericType(t):
|
if containsGenericType(t):
|
||||||
result = copyType(t, t.owner, false)
|
result = copyType(t, t.owner, false)
|
||||||
|
result.size = -1 # needs to be recomputed
|
||||||
for i in countup(0, sonsLen(result) - 1):
|
for i in countup(0, sonsLen(result) - 1):
|
||||||
result.sons[i] = ReplaceTypeVarsT(cl, result.sons[i])
|
result.sons[i] = ReplaceTypeVarsT(cl, result.sons[i])
|
||||||
result.n = ReplaceTypeVarsN(cl, result.n)
|
result.n = ReplaceTypeVarsN(cl, result.n)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Nimrod's Runtime Library
|
# Nimrod's Runtime Library
|
||||||
# (c) Copyright 2010 Andreas Rumpf
|
# (c) Copyright 2011 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -71,6 +71,15 @@ proc text*(n: PXmlNode): string {.inline.} =
|
||||||
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
||||||
result = n.fText
|
result = n.fText
|
||||||
|
|
||||||
|
proc innerText*(n: PXmlNode): string =
|
||||||
|
## gets the inner text of `n`. `n` has to be an ``xnElement`` node. Only
|
||||||
|
## ``xnText`` and ``xnEntity`` nodes are considered part of `n`'s inner text,
|
||||||
|
## other child nodes are silently ignored.
|
||||||
|
result = ""
|
||||||
|
assert n.k == xnElement
|
||||||
|
for i in 0 .. n.s.len-1:
|
||||||
|
if n.s[i].k in {xnText, xnEntity}: result.add(n.fText)
|
||||||
|
|
||||||
proc tag*(n: PXmlNode): string {.inline.} =
|
proc tag*(n: PXmlNode): string {.inline.} =
|
||||||
## gets the tag name of `n`. `n` has to be an ``xnElement`` node.
|
## gets the tag name of `n`. `n` has to be an ``xnElement`` node.
|
||||||
assert n.k == xnElement
|
assert n.k == xnElement
|
||||||
|
|
|
||||||
66
tests/reject/tillegaltyperecursion.nim
Normal file
66
tests/reject/tillegaltyperecursion.nim
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nimrod c --threads:on $# $#"
|
||||||
|
errormsg: "illegal recursion in type 'TIRC'"
|
||||||
|
line: 16
|
||||||
|
"""
|
||||||
|
|
||||||
|
import events
|
||||||
|
import sockets
|
||||||
|
import strutils
|
||||||
|
import os
|
||||||
|
|
||||||
|
type
|
||||||
|
TMessageReceivedEventArgs = object of TEventArgs
|
||||||
|
Nick*: string
|
||||||
|
Message*: string
|
||||||
|
TIRC = object
|
||||||
|
EventEmitter: TEventEmitter
|
||||||
|
MessageReceivedHandler*: TEventHandler
|
||||||
|
Socket: TSocket
|
||||||
|
Thread: TThread[TIRC]
|
||||||
|
|
||||||
|
proc initIRC*(): TIRC =
|
||||||
|
result.Socket = socket()
|
||||||
|
result.EventEmitter = initEventEmitter()
|
||||||
|
result.MessageReceivedHandler = initEventHandler("MessageReceived")
|
||||||
|
|
||||||
|
proc IsConnected*(irc: var TIRC): bool =
|
||||||
|
return running(irc.Thread)
|
||||||
|
|
||||||
|
|
||||||
|
proc sendRaw*(irc: var TIRC, message: string) =
|
||||||
|
irc.Socket.send(message & "\r\L")
|
||||||
|
proc handleData(irc: TIRC) {.thread.} =
|
||||||
|
var connected = False
|
||||||
|
while connected:
|
||||||
|
var tup = @[irc.Socket]
|
||||||
|
var o = select(tup, 200)
|
||||||
|
echo($o)
|
||||||
|
echo($len(tup))
|
||||||
|
if len(tup) == 1:
|
||||||
|
#Connected
|
||||||
|
connected = True
|
||||||
|
|
||||||
|
#Parse data here
|
||||||
|
|
||||||
|
else:
|
||||||
|
#Disconnected
|
||||||
|
connected = False
|
||||||
|
return
|
||||||
|
|
||||||
|
proc Connect*(irc: var TIRC, nick: string, host: string, port: int = 6667) =
|
||||||
|
connect(irc.Socket ,host ,TPort(port),TDomain.AF_INET)
|
||||||
|
send(irc.Socket,"USER " & nick & " " & nick & " " & nick & " " & nick &"\r\L")
|
||||||
|
send(irc.Socket,"NICK " & nick & "\r\L")
|
||||||
|
var thread: TThread[TIRC]
|
||||||
|
createThread(thread, handleData, irc)
|
||||||
|
irc.Thread = thread
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
var irc = initIRC()
|
||||||
|
irc.Connect("AmryBot[Nim]","irc.freenode.net",6667)
|
||||||
|
irc.sendRaw("JOIN #nimrod")
|
||||||
|
os.Sleep(4000)
|
||||||
8
todo.txt
8
todo.txt
|
|
@ -3,11 +3,13 @@ Version 0.8.14
|
||||||
|
|
||||||
- fix ``m*`` for generics
|
- fix ``m*`` for generics
|
||||||
- optional indentation for 'case' statement
|
- optional indentation for 'case' statement
|
||||||
- make threadvar efficient again on linux after testing
|
|
||||||
- test the sort implementation again
|
- test the sort implementation again
|
||||||
- export re-entrant and non-reentrant locks and condition vars; threads should
|
- export re-entrant and non-reentrant locks and condition vars; threads should
|
||||||
not have an inbox per default
|
not have an inbox per default
|
||||||
- add --deadlock_prevention:on|off switch? timeout for locks?
|
- add --deadlock_prevention:on|off switch? timeout for locks?
|
||||||
|
- make threadvar efficient again on linux after testing
|
||||||
|
- ``pure`` --> ``noStackFrame``, ``noRtti``
|
||||||
|
|
||||||
|
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
=============
|
=============
|
||||||
|
|
@ -57,8 +59,8 @@ version 0.9.XX
|
||||||
is the same as:
|
is the same as:
|
||||||
|
|
||||||
p(a, b, proc() =
|
p(a, b, proc() =
|
||||||
echo a
|
echo a
|
||||||
echo b)
|
echo b)
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ Library Additions
|
||||||
- Added ``strutils.unindent``.
|
- Added ``strutils.unindent``.
|
||||||
- Added ``system.slurp`` for easy resource embedding.
|
- Added ``system.slurp`` for easy resource embedding.
|
||||||
- Added ``system.running`` for threads.
|
- Added ``system.running`` for threads.
|
||||||
|
- Added proc ``xmltree.innerText``.
|
||||||
|
|
||||||
|
|
||||||
2011-07-10 Version 0.8.12 released
|
2011-07-10 Version 0.8.12 released
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue