diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 11 | ||||
-rw-r--r-- | compiler/pragmas.nim | 4 | ||||
-rw-r--r-- | compiler/sem.nim | 15 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 |
4 files changed, 28 insertions, 6 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index d4d5bce9c..e69b83181 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 4e2a4e536..cc432aea8 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -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) diff --git a/compiler/sem.nim b/compiler/sem.nim index 671bd0043..bcdfc7939 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 03730f30c..fba028a46 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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 = |