summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/astalgo.nim2
-rw-r--r--compiler/cgen.nim25
-rw-r--r--compiler/evaltempl.nim21
-rw-r--r--compiler/sem.nim1
-rw-r--r--compiler/semfold.nim2
-rw-r--r--compiler/sigmatch.nim4
-rw-r--r--compiler/suggest.nim5
7 files changed, 43 insertions, 17 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index 7c07b2995..affbdffd9 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -386,6 +386,7 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
     var istr = rspaces(indent + 2)
     result = "{$N$1\"kind\": $2" %
              [istr, makeYamlString($n.kind)]
+    addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
     if maxRecDepth != 0:
       case n.kind
       of nkCharLit..nkUInt64Lit:
@@ -418,7 +419,6 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
             addf(result, "$N$1$2", [rspaces(indent + 4), debugTree(n.sons[i],
                 indent + 4, maxRecDepth - 1, renderType)])
           addf(result, "$N$1]", [istr])
-    addf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
     addf(result, "$N$1}", [rspaces(indent)])
 
 proc debug(n: PSym) =
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 082512753..0ca8e46fc 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -184,24 +184,27 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool =
     result = true
 
 proc genLineDir(p: BProc, t: PNode) =
-  let info = t.info
-  #if t.kind in nkCallKinds+{nkStmtListExpr} and t.len > 1: t[1].info
-  #else: t.info
-  var line = info.safeLineNm
+  var tt = t
+  #while tt.kind in {nkStmtListExpr}+nkCallKinds:
+  #  tt = tt.lastSon
+  if tt.kind in nkCallKinds and tt.len > 1:
+    tt = tt.sons[1]
+  let line = tt.info.safeLineNm
+
   if optEmbedOrigSrc in gGlobalOptions:
-    add(p.s(cpsStmts), ~"//" & info.sourceLine & rnl)
-  genCLineDir(p.s(cpsStmts), info.toFullPath, line)
+    add(p.s(cpsStmts), ~"//" & tt.info.sourceLine & rnl)
+  genCLineDir(p.s(cpsStmts), tt.info.toFullPath, line)
   if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
       (p.prc == nil or sfPure notin p.prc.flags):
-    if freshLineInfo(p, info):
+    if freshLineInfo(p, tt.info):
       linefmt(p, cpsStmts, "#endb($1, $2);$n",
-              line.rope, makeCString(toFilename(info)))
+              line.rope, makeCString(toFilename(tt.info)))
   elif ({optLineTrace, optStackTrace} * p.options ==
       {optLineTrace, optStackTrace}) and
-      (p.prc == nil or sfPure notin p.prc.flags) and info.fileIndex >= 0:
-    if freshLineInfo(p, info):
+      (p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex >= 0:
+    if freshLineInfo(p, tt.info):
       linefmt(p, cpsStmts, "nimln($1, $2);$n",
-              line.rope, info.quotedFilename)
+              line.rope, tt.info.quotedFilename)
 
 proc postStmtActions(p: BProc) {.inline.} =
   add(p.s(cpsStmts), p.module.injectStmt)
diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim
index 96ede44fd..87745f7ed 100644
--- a/compiler/evaltempl.nim
+++ b/compiler/evaltempl.nim
@@ -104,6 +104,25 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
 var evalTemplateCounter* = 0
   # to prevent endless recursion in templates instantiation
 
+proc wrapInComesFrom*(info: TLineInfo; res: PNode): PNode =
+  when true:
+    result = res
+    result.info = info
+    if result.kind in {nkStmtList, nkStmtListExpr} and result.len > 0:
+      result.lastSon.info = info
+    when false:
+      # this hack is required to
+      var x = result
+      while x.kind == nkStmtListExpr: x = x.lastSon
+      if x.kind in nkCallKinds:
+        for i in 1..<x.len:
+          if x[i].kind in nkCallKinds:
+            x.sons[i].info = info
+  else:
+    result = newNodeI(nkPar, info)
+    result.add res
+    result.flags.incl nfNone
+
 proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
   inc(evalTemplateCounter)
   if evalTemplateCounter > 100:
@@ -132,5 +151,5 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
     #if ctx.instLines: result.info = n.info
     for i in countup(0, safeLen(body) - 1):
       evalTemplateAux(body.sons[i], args, ctx, result)
-
+  result = wrapInComesFrom(n.info, result)
   dec(evalTemplateCounter)
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 7524d7388..755abec5d 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -369,6 +369,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
   result = evalMacroCall(c.module, c.cache, n, nOrig, sym)
   if efNoSemCheck notin flags:
     result = semAfterMacroCall(c, result, sym, flags)
+  result = wrapInComesFrom(nOrig.info, result)
   popInfoContext()
 
 proc forceBool(c: PContext, n: PNode): PNode =
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 0f1138e04..39d84c0fa 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -769,7 +769,7 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
   of nkCast:
     var a = getConstExpr(m, n.sons[1])
     if a == nil: return
-    if n.typ.kind in NilableTypes:
+    if n.typ != nil and n.typ.kind in NilableTypes:
       # we allow compile-time 'cast' for pointer types:
       result = a
       result.typ = n.typ
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 16358b1a8..a94579339 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -172,7 +172,9 @@ proc sumGeneric(t: PType): int =
       inc result
     of tyGenericInvocation, tyTuple, tyProc:
       result += ord(t.kind == tyGenericInvocation)
-      for i in 0 .. <t.len: result += t.sons[i].sumGeneric
+      for i in 0 .. <t.len:
+        if t.sons[i] != nil:
+          result += t.sons[i].sumGeneric
       break
     of tyGenericParam, tyExpr, tyStatic, tyStmt: break
     of tyAlias: t = t.lastSon
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 888e80085..958dfe50e 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -57,10 +57,11 @@ proc symToSuggest(s: PSym, isLocal: bool, section: string, li: TLineInfo;
     result.qualifiedPath = @[]
     if not isLocal and s.kind != skModule:
       let ow = s.owner
-      if ow.kind != skModule and ow.owner != nil:
+      if ow != nil and ow.kind != skModule and ow.owner != nil:
         let ow2 = ow.owner
         result.qualifiedPath.add(ow2.origModuleName)
-      result.qualifiedPath.add(ow.origModuleName)
+      if ow != nil:
+        result.qualifiedPath.add(ow.origModuleName)
     result.qualifiedPath.add(s.name.s)
 
     if s.typ != nil: