@@ -31,6 +31,13 @@ proc writeFlags[E](dest: var TokenBuf; flags: set[E]) =
3131 else :
3232 dest.addDotToken
3333
34+ proc toNif (c: var EncodeContext ; info: TLineInfo ): PackedLineInfo =
35+ if info == unknownLineInfo:
36+ NoLineInfo
37+ else :
38+ let fileId = pool.files.getOrIncl (c.conf.toFullPath (info.fileIndex))
39+ pack (pool.man, fileId, info.line.int32 , info.col)
40+
3441proc toNifModuleId (c: var EncodeContext ; moduleId: int ) =
3542 # `ItemId.module` in PType and PSym (and `PSym.position` when it is skModule) are module's FileIndex
3643 # but it cannot be directly encoded as the uniqueness of it can broke
@@ -48,28 +55,29 @@ proc toNif(c: var EncodeContext; typ: PType)
4855proc toNif (c: var EncodeContext ; n: PNode )
4956
5057proc toNifDef (c: var EncodeContext ; sym: PSym ) =
51- c.dest.buildTree symIdTag:
52- c.toNifModuleId sym.itemId.module
53- c.dest.addIntLit sym.itemId.item
54- c.dest.addIdent sym.name.s
55- c.dest.writeFlags sym.flags
56- c.dest.addIntLit sym.disamb
57- c.dest.buildTree sym.kind.toNifTag:
58- case sym.kind
59- of skLet, skVar, skField, skForVar:
60- c.toNif sym.guard
61- c.dest.addIntLit sym.bitsize
62- c.dest.addIntLit sym.alignment
63- else :
64- discard
65- if sym.kind == skModule:
66- c.toNifModuleId sym.position
58+ c.dest.addParLe symIdTag, c.toNif sym.info
59+ c.toNifModuleId sym.itemId.module
60+ c.dest.addIntLit sym.itemId.item
61+ c.dest.addIdent sym.name.s
62+ c.dest.writeFlags sym.flags
63+ c.dest.addIntLit sym.disamb
64+ c.dest.buildTree sym.kind.toNifTag:
65+ case sym.kind
66+ of skLet, skVar, skField, skForVar:
67+ c.toNif sym.guard
68+ c.dest.addIntLit sym.bitsize
69+ c.dest.addIntLit sym.alignment
6770 else :
68- c.dest.addIntLit sym.position
69- c.toNif sym.typ
70- c.toNif sym.owner
71- c.dest.addIdent toNifTag (sym.loc.k)
72- c.dest.addStrLit sym.loc.snippet
71+ discard
72+ if sym.kind == skModule:
73+ c.toNifModuleId sym.position
74+ else :
75+ c.dest.addIntLit sym.position
76+ c.toNif sym.typ
77+ c.toNif sym.owner
78+ c.dest.addIdent toNifTag (sym.loc.k)
79+ c.dest.addStrLit sym.loc.snippet
80+ c.dest.addParRi
7381
7482proc toNifDef (c: var EncodeContext ; typ: PType ) =
7583 c.dest.buildTree typeIdTag:
@@ -115,7 +123,7 @@ proc writeNodeFlags(dest: var TokenBuf; flags: set[TNodeFlag]) {.inline.} =
115123 writeFlags dest, flags
116124
117125template withNode (c: var EncodeContext ; n: PNode ; body: untyped ) =
118- c.dest.addParLe pool.tags.getOrIncl (toNifTag (n.kind))
126+ c.dest.addParLe pool.tags.getOrIncl (toNifTag (n.kind)), c. toNif n.info
119127 writeNodeFlags (c.dest, n.flags)
120128 c.toNif n.typ
121129 body
@@ -127,10 +135,12 @@ proc toNif(c: var EncodeContext; n: PNode) =
127135 else :
128136 case n.kind:
129137 of nkEmpty:
130- c.dest.addParLe pool.tags.getOrIncl (toNifTag (nkEmpty))
138+ let info = c.toNif n.info
139+ c.dest.addParLe pool.tags.getOrIncl (toNifTag (nkEmpty)), info
131140 c.dest.addParRi
132141 of nkIdent:
133- c.dest.addParLe pool.tags.getOrIncl (toNifTag (nkIdent))
142+ let info = c.toNif n.info
143+ c.dest.addParLe pool.tags.getOrIncl (toNifTag (nkIdent)), info
134144 c.dest.addIdent n.ident.s
135145 c.dest.addParRi
136146 of nkSym:
0 commit comments