mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
added xmltree.innerText; fixes #49
This commit is contained in:
@@ -1058,8 +1058,7 @@ proc genNew(p: BProc, e: PNode) =
|
||||
proc genNewSeq(p: BProc, e: PNode) =
|
||||
var
|
||||
a, b, c: TLoc
|
||||
seqtype: PType
|
||||
seqType = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||
var seqType = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||
InitLocExpr(p, e.sons[1], a)
|
||||
InitLocExpr(p, e.sons[2], b)
|
||||
initLoc(c, locExpr, a.t, OnHeap)
|
||||
@@ -1069,15 +1068,12 @@ proc genNewSeq(p: BProc, e: PNode) =
|
||||
genAssignment(p, a, c, {})
|
||||
|
||||
proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
|
||||
var
|
||||
a: TLoc
|
||||
dest, t: PType
|
||||
r, nilcheck: PRope
|
||||
var a: TLoc
|
||||
initLocExpr(p, x, a)
|
||||
dest = skipTypes(typ, abstractPtrs)
|
||||
r = rdLoc(a)
|
||||
nilCheck = nil
|
||||
t = skipTypes(a.t, abstractInst)
|
||||
var dest = skipTypes(typ, abstractPtrs)
|
||||
var r = rdLoc(a)
|
||||
var nilCheck: PRope = nil
|
||||
var t = skipTypes(a.t, abstractInst)
|
||||
while t.kind in {tyVar, tyPtr, tyRef}:
|
||||
if t.kind != tyVar: nilCheck = 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 mEnumToStr: genRepr(p, e, d)
|
||||
of mAssert:
|
||||
if (optAssert in p.Options):
|
||||
if optAssert in p.Options:
|
||||
expr(p, e.sons[1], d)
|
||||
line = toRope(toLinenumber(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)
|
||||
|
||||
proc upConv(p: BProc, n: PNode, d: var TLoc) =
|
||||
var
|
||||
a: TLoc
|
||||
dest, t: PType
|
||||
r, nilCheck: PRope
|
||||
var a: TLoc
|
||||
initLocExpr(p, n.sons[0], a)
|
||||
dest = skipTypes(n.typ, abstractPtrs)
|
||||
if (optObjCheck in p.options) and not (isPureObject(dest)):
|
||||
r = rdLoc(a)
|
||||
nilCheck = nil
|
||||
t = skipTypes(a.t, abstractInst)
|
||||
var dest = skipTypes(n.typ, abstractPtrs)
|
||||
if optObjCheck in p.options and not isPureObject(dest):
|
||||
var r = rdLoc(a)
|
||||
var nilCheck: PRope = nil
|
||||
var t = skipTypes(a.t, abstractInst)
|
||||
while t.kind in {tyVar, tyPtr, tyRef}:
|
||||
if t.kind != tyVar: nilCheck = r
|
||||
r = ropef("(*$1)", [r])
|
||||
t = skipTypes(t.sons[0], abstractInst)
|
||||
if gCmd != cmdCompileToCpp:
|
||||
while (t.kind == tyObject) and (t.sons[0] != nil):
|
||||
while t.kind == tyObject and t.sons[0] != nil:
|
||||
app(r, ".Sup")
|
||||
t = skipTypes(t.sons[0], abstractInst)
|
||||
if nilCheck != nil:
|
||||
@@ -1753,7 +1746,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||
putLocIntoDest(p, d, sym.loc)
|
||||
of skProc, skConverter:
|
||||
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)
|
||||
putLocIntoDest(p, d, sym.loc)
|
||||
of skConst:
|
||||
@@ -1768,7 +1761,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||
putIntoDest(p, d, e.typ, toRope(sym.position))
|
||||
of skVar, skResult:
|
||||
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)
|
||||
if sfThreadVar in sym.flags:
|
||||
AccessThreadLocalVar(p, sym)
|
||||
@@ -1803,7 +1796,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||
genCall(p, e, d)
|
||||
of nkCurly: genSetConstr(p, e, d)
|
||||
of nkBracket:
|
||||
if (skipTypes(e.typ, abstractVarRange).kind == tySequence):
|
||||
if skipTypes(e.typ, abstractVarRange).kind == tySequence:
|
||||
genSeqConstr(p, e, d)
|
||||
else:
|
||||
genArrayConstr(p, e, d)
|
||||
|
||||
@@ -489,13 +489,16 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
InternalError(a.info, "semTypeSection: containerID")
|
||||
s.typ.containerID = getID()
|
||||
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
|
||||
# so we use tyEmpty instead of nil to not crash for strange conversions
|
||||
# like: mydata.seq
|
||||
addSon(s.typ, newTypeS(tyEmpty, c))
|
||||
s.ast = a
|
||||
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
|
||||
popOwner()
|
||||
closeScope(c.tab)
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
|
||||
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) =
|
||||
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
|
||||
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.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:
|
||||
localError(info, errInheritanceOnlyWithNonFinalObjects)
|
||||
|
||||
|
||||
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
||||
result = t.kind in GenericTypes
|
||||
|
||||
@@ -121,10 +127,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
|
||||
var newbody = ReplaceTypeVarsT(cl, lastSon(body))
|
||||
newbody.flags = newbody.flags + t.flags + body.flags
|
||||
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
||||
addSon(result, newbody)
|
||||
addSon(result, newbody)
|
||||
#writeln(output, ropeToStr(Typetoyaml(newbody)));
|
||||
checkConstructedType(cl.info, newbody)
|
||||
|
||||
checkPartialConstructedType(cl.info, newbody)
|
||||
|
||||
proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
||||
result = t
|
||||
if t == nil: return
|
||||
@@ -139,6 +145,7 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
|
||||
else:
|
||||
if containsGenericType(t):
|
||||
result = copyType(t, t.owner, false)
|
||||
result.size = -1 # needs to be recomputed
|
||||
for i in countup(0, sonsLen(result) - 1):
|
||||
result.sons[i] = ReplaceTypeVarsT(cl, result.sons[i])
|
||||
result.n = ReplaceTypeVarsN(cl, result.n)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
# (c) Copyright 2011 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
@@ -71,6 +71,15 @@ proc text*(n: PXmlNode): string {.inline.} =
|
||||
assert n.k in {xnText, xnComment, xnCData, xnEntity}
|
||||
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.} =
|
||||
## gets the tag name of `n`. `n` has to be an ``xnElement`` node.
|
||||
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
|
||||
- optional indentation for 'case' statement
|
||||
- make threadvar efficient again on linux after testing
|
||||
- test the sort implementation again
|
||||
- export re-entrant and non-reentrant locks and condition vars; threads should
|
||||
not have an inbox per default
|
||||
- add --deadlock_prevention:on|off switch? timeout for locks?
|
||||
- make threadvar efficient again on linux after testing
|
||||
- ``pure`` --> ``noStackFrame``, ``noRtti``
|
||||
|
||||
|
||||
version 0.9.0
|
||||
=============
|
||||
@@ -57,8 +59,8 @@ version 0.9.XX
|
||||
is the same as:
|
||||
|
||||
p(a, b, proc() =
|
||||
echo a
|
||||
echo b)
|
||||
echo a
|
||||
echo b)
|
||||
|
||||
Library
|
||||
-------
|
||||
|
||||
@@ -66,6 +66,7 @@ Library Additions
|
||||
- Added ``strutils.unindent``.
|
||||
- Added ``system.slurp`` for easy resource embedding.
|
||||
- Added ``system.running`` for threads.
|
||||
- Added proc ``xmltree.innerText``.
|
||||
|
||||
|
||||
2011-07-10 Version 0.8.12 released
|
||||
|
||||
Reference in New Issue
Block a user