summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-03-16 19:33:24 +0100
committerAraq <rumpf_a@web.de>2012-03-16 19:33:24 +0100
commitbe1154106a81207dfaf383afc25bfa0e2efb90c7 (patch)
tree981fc574252d4b7dde5f8884b7376497ccb8fde3 /compiler
parent4da067691eb61554515197fa79392b1509c2e566 (diff)
downloadNim-be1154106a81207dfaf383afc25bfa0e2efb90c7.tar.gz
clean separation of PNimrodNode and tyExpr
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/sem.nim4
-rwxr-xr-xcompiler/seminst.nim5
-rwxr-xr-xcompiler/semstmts.nim16
-rwxr-xr-xcompiler/semtypes.nim18
4 files changed, 27 insertions, 16 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 1bc2cee09..1c1b4351d 100755
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -31,8 +31,8 @@ proc semLambda(c: PContext, n: PNode): PNode
 proc semTypeNode(c: PContext, n: PNode, prev: PType): PType
 proc semStmt(c: PContext, n: PNode): PNode
 proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
-proc addParams(c: PContext, n: PNode)
-proc addResult(c: PContext, t: PType, info: TLineInfo)
+proc addParams(c: PContext, n: PNode, kind: TSymKind)
+proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind)
 proc addResultNode(c: PContext, n: PNode)
 proc instGenericContainer(c: PContext, n: PNode, header: PType): PType
 
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 503b3c7f6..1da6a671f 100755
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -75,7 +75,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
     addDecl(c, result)
     pushProcCon(c, result)
     if result.kind in {skProc, skMethod, skConverter}: 
-      addResult(c, result.typ.sons[0], n.info)
+      addResult(c, result.typ.sons[0], n.info, result.kind)
       addResultNode(c, n)
     var b = semStmtScope(c, n.sons[bodyPos])
     # XXX Bad hack for tests/titer2 and tests/tactiontable
@@ -92,7 +92,8 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) =
       openScope(c.tab)
       var n = oldPrc.ast
       n.sons[bodyPos] = copyTree(s.getBody)
-      if n.sons[paramsPos].kind != nkEmpty: addParams(c, oldPrc.typ.n)
+      if n.sons[paramsPos].kind != nkEmpty: 
+        addParams(c, oldPrc.typ.n, oldPrc.kind)
       instantiateBody(c, n, oldPrc)
       closeScope(c.tab)
       popInfoContext()
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 8b758d9f7..5b4639f26 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -599,12 +599,12 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
   result = n
 
 proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) = 
-  s.typ = semProcTypeNode(c, n, genericParams, nil)
+  s.typ = semProcTypeNode(c, n, genericParams, nil, s.kind)
 
-proc addParams(c: PContext, n: PNode) = 
+proc addParams(c: PContext, n: PNode, kind: TSymKind) = 
   for i in countup(1, sonsLen(n)-1): 
     if (n.sons[i].kind != nkSym): InternalError(n.info, "addParams")
-    addDecl(c, n.sons[i].sym)
+    addParamOrResult(c, n.sons[i].sym, kind)
 
 proc semBorrow(c: PContext, n: PNode, s: PSym) = 
   # search for the correct alias:
@@ -615,13 +615,13 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) =
   else:
     LocalError(n.info, errNoSymbolToBorrowFromFound) 
   
-proc addResult(c: PContext, t: PType, info: TLineInfo) = 
+proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) = 
   if t != nil: 
     var s = newSym(skResult, getIdent"result", getCurrOwner())
     s.info = info
     s.typ = t
     incl(s.flags, sfUsed)
-    addDecl(c, s)
+    addParamOrResult(c, s, owner)
     c.p.resultSym = s
 
 proc addResultNode(c: PContext, n: PNode) = 
@@ -653,7 +653,7 @@ proc semLambda(c: PContext, n: PNode): PNode =
     if sfImportc in s.flags: 
       LocalError(n.sons[bodyPos].info, errImplOfXNotAllowed, s.name.s)
     pushProcCon(c, s)
-    addResult(c, s.typ.sons[0], n.info)
+    addResult(c, s.typ.sons[0], n.info, skProc)
     n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos])
     addResultNode(c, n)
     popProcCon(c)
@@ -717,7 +717,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
     openScope(c.tab)          # open scope for old (correct) parameter symbols
     if proto.ast.sons[genericParamsPos].kind != nkEmpty: 
       addGenericParamListToScope(c, proto.ast.sons[genericParamsPos])
-    addParams(c, proto.typ.n)
+    addParams(c, proto.typ.n, proto.kind)
     proto.info = s.info       # more accurate line information
     s.typ = proto.typ
     s = proto
@@ -737,7 +737,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
       ParamsTypeCheck(c, s.typ)
       pushProcCon(c, s)
       if s.typ.sons[0] != nil and kind != skIterator: 
-        addResult(c, s.typ.sons[0], n.info)
+        addResult(c, s.typ.sons[0], n.info, kind)
       if sfImportc notin s.flags: 
         # no semantic checking for importc:
         n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos])
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 5a1fc004d..cec3a9f7e 100755
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -510,9 +510,18 @@ proc paramType(c: PContext, n, genericParams: PNode, cl: var TIntSet): PType =
   if genericParams != nil and sonsLen(genericParams) == 0: 
     result = addTypeVarsOfGenericBody(c, result, genericParams, cl)
 
+proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
+  if kind == skMacro and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}:
+    let nn = getSysSym"PNimrodNode"
+    var a = copySym(param)
+    a.typ = nn.typ
+    addDecl(c, a)
+  else:
+    addDecl(c, param)
+
 proc semProcTypeNode(c: PContext, n, genericParams: PNode, 
-                     prev: PType): PType = 
-  var 
+                     prev: PType, kind: TSymKind): PType = 
+  var
     def, res: PNode
     typ: PType
     cl: TIntSet
@@ -568,7 +577,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
         LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
       addSon(result.n, newSymNode(arg))
       addSon(result, typ)
-      addDecl(c, arg)
+      addParamOrResult(c, arg, kind)
 
   if n.sons[0].kind != nkEmpty: 
     var r = paramType(c, n.sons[0], genericParams, cl)
@@ -717,7 +726,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
   of nkProcTy: 
     checkSonsLen(n, 2)
     openScope(c.tab)
-    result = semProcTypeNode(c, n.sons[0], nil, prev)
+    result = semProcTypeNode(c, n.sons[0], nil, prev, skProc)
     # dummy symbol for `pragma`:
     var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
     s.typ = result
@@ -769,6 +778,7 @@ proc processMagicType(c: PContext, m: PSym) =
   of mSet: setMagicType(m, tySet, 0) 
   of mSeq: setMagicType(m, tySequence, 0)
   of mOrdinal: setMagicType(m, tyOrdinal, 0)
+  of mPNimrodNode: nil
   else: GlobalError(m.info, errTypeExpected)
   
 proc newConstraint(c: PContext, k: TTypeKind): PType =