summary refs log tree commit diff stats
path: root/rod/c2nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-02-13 21:24:52 +0100
committerAraq <rumpf_a@web.de>2011-02-13 21:24:52 +0100
commit55c40746474cff452c09fa9c1244e3d0c7b3ad21 (patch)
tree3c3f4cf72a24b98ecabc7f259cc3018ad936ddb9 /rod/c2nim
parentc717304ce61acdf7f980bc4ed185e7ea9e886dd5 (diff)
downloadNim-55c40746474cff452c09fa9c1244e3d0c7b3ad21.tar.gz
REPL improvements
Diffstat (limited to 'rod/c2nim')
-rwxr-xr-xrod/c2nim/cparse.nim6
-rwxr-xr-xrod/c2nim/cpp.nim13
2 files changed, 16 insertions, 3 deletions
diff --git a/rod/c2nim/cparse.nim b/rod/c2nim/cparse.nim
index da96de1f4..704e132f0 100755
--- a/rod/c2nim/cparse.nim
+++ b/rod/c2nim/cparse.nim
@@ -1,7 +1,7 @@
 #
 #
 #      c2nim - C to Nimrod source converter
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2011 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -48,6 +48,7 @@ type
     backtrack: seq[ref TToken]
     inTypeDef: int
     scopeCounter: int
+    hasDeadCodeElimPragma: bool
   
   TReplaceTuple* = array[0..1, string]
 
@@ -289,7 +290,7 @@ proc mangleName(s: string, p: TParser): string =
 
 proc isPrivate(s: string, p: TParser): bool = 
   for pattern in items(p.options.privateRules): 
-     if s.match(pattern): return true
+    if s.match(pattern): return true
 
 proc mangledIdent(ident: string, p: TParser): PNode = 
   result = newNodeP(nkIdent, p)
@@ -381,6 +382,7 @@ proc markTypeIdent(p: var TParser, typ: PNode) =
       while t != nil and t.kind in {nkVarTy, nkPtrTy, nkRefTy}: 
         prefix.add('P')
         t = t.sons[0]
+      if prefix.len == 0: prefix.add('T')
     expectIdent(p)
     p.options.toMangle[p.tok.s] = prefix & mangleRules(p.tok.s, p)
   
diff --git a/rod/c2nim/cpp.nim b/rod/c2nim/cpp.nim
index e7c7e86b0..61b91e4de 100755
--- a/rod/c2nim/cpp.nim
+++ b/rod/c2nim/cpp.nim
@@ -1,7 +1,7 @@
 #
 #
 #      c2nim - C to Nimrod source converter
-#        (c) Copyright 2010 Andreas Rumpf
+#        (c) Copyright 2011 Andreas Rumpf
 #
 #    See the file "copying.txt", included in this
 #    distribution, for details about the copyright.
@@ -297,6 +297,16 @@ proc parseMangleDir(p: var TParser) =
   getTok(p)
   eatNewLine(p, nil)
 
+proc modulePragmas(p: var TParser): PNode = 
+  if p.options.dynlibSym.len > 0 and not p.hasDeadCodeElimPragma:
+    p.hasDeadCodeElimPragma = true
+    result = newNodeP(nkPragma, p)
+    var e = newNodeP(nkExprColonExpr, p)
+    addSon(e, newIdentNodeP("deadCodeElim", p), newIdentNodeP("on", p))
+    addSon(result, e)
+  else:
+    result = ast.emptyNode
+
 proc parseDir(p: var TParser): PNode = 
   result = ast.emptyNode
   assert(p.tok.xkind in {pxDirective, pxDirectiveParLe})
@@ -317,6 +327,7 @@ proc parseDir(p: var TParser): PNode =
     discard setOption(p.options, key, p.tok.s)
     getTok(p)
     eatNewLine(p, nil)
+    result = modulePragmas(p)
   of "mangle":
     parseMangleDir(p)
   of "def":