astToStr is now immediate

This commit is contained in:
Araq
2013-06-02 21:52:04 +02:00
parent fa062ca0c4
commit 4308f32255
4 changed files with 28 additions and 6 deletions

View File

@@ -524,6 +524,8 @@ type
PType* = ref TType
PSym* = ref TSym
TNode*{.final, acyclic.} = object # on a 32bit machine, this takes 32 bytes
when defined(useNodeIds):
id*: int
typ*: PType
comment*: string
info*: TLineInfo
@@ -917,6 +919,10 @@ proc copyObjectSet(dest: var TObjectSet, src: TObjectSet) =
proc discardSons(father: PNode) =
father.sons = nil
when defined(useNodeIds):
const nodeIdToDebug = 140600
var gNodeId: int
proc newNode(kind: TNodeKind): PNode =
new(result)
result.kind = kind
@@ -924,6 +930,11 @@ proc newNode(kind: TNodeKind): PNode =
result.info.fileIndex = int32(- 1)
result.info.col = int16(- 1)
result.info.line = int16(- 1)
when defined(useNodeIds):
result.id = gNodeId
if result.id == nodeIdToDebug:
writeStackTrace()
inc gNodeId
proc newIntNode(kind: TNodeKind, intVal: BiggestInt): PNode =
result = newNode(kind)

View File

@@ -396,8 +396,8 @@ proc PragmaWatchpoint(c: PContext, n: PNode) =
proc semAsmOrEmit*(con: PContext, n: PNode, marker: char): PNode =
case n.sons[1].kind
of nkStrLit, nkRStrLit, nkTripleStrLit:
result = copyNode(n)
of nkStrLit, nkRStrLit, nkTripleStrLit:
result = newNode(if n.kind == nkAsmStmt: nkAsmStmt else: nkArgList, n.info)
var str = n.sons[1].strVal
if str == "":
LocalError(n.info, errEmptyAsm)

View File

@@ -50,13 +50,20 @@ proc typeMismatch(n: PNode, formal, actual: PType) =
typeToString(actual) & ") " &
`%`(msgKindToString(errButExpectedX), [typeToString(formal)]))
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
result = IndexTypesMatch(c, formal, arg.typ, arg)
if result == nil:
typeMismatch(arg, formal, arg.typ)
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
if arg.typ.isNil:
LocalError(arg.info, errExprXHasNoType,
renderTree(arg, {renderNoComments}))
# error correction:
result = copyNode(arg)
result.typ = formal
else:
result = IndexTypesMatch(c, formal, arg.typ, arg)
if result == nil:
typeMismatch(arg, formal, arg.typ)
# error correction:
result = copyNode(arg)
result.typ = formal
var CommonTypeBegin = PType(kind: tyExpr)

View File

@@ -1441,6 +1441,10 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
of mShallowCopy: result = semShallowCopy(c, n, flags)
of mExpandToAst: result = semExpandToAst(c, n, s, flags)
of mQuoteAst: result = semQuoteAst(c, n)
of mAstToStr:
checkSonsLen(n, 2)
result = newStrNodeT(renderTree(n[1], {renderNoComments}), n)
result.typ = getSysType(tyString)
else: result = semDirectOp(c, n, flags)
proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =