summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-09-28 00:41:40 +0200
committerAraq <rumpf_a@web.de>2011-09-28 00:41:40 +0200
commite9b7d5e68eeeb6d468d407437502fd1c178adc43 (patch)
tree0ce6957a7dc01b89c86f68e51c49abc857ad9d42
parentda6046dcba20cb4aaff1e5712ac7a33a3c4e8445 (diff)
downloadNim-e9b7d5e68eeeb6d468d407437502fd1c178adc43.tar.gz
c2nim: bugfix: parsing of typedef'ed function pointers
-rwxr-xr-xcompiler/c2nim/cparse.nim18
-rwxr-xr-xcompiler/c2nim/tests/systest.c1
2 files changed, 8 insertions, 11 deletions
diff --git a/compiler/c2nim/cparse.nim b/compiler/c2nim/cparse.nim
index 438d3755f..f8f58347d 100755
--- a/compiler/c2nim/cparse.nim
+++ b/compiler/c2nim/cparse.nim
@@ -270,7 +270,7 @@ proc mangleRules(s: string, p: TParser): string =
   block mangle:
     for pattern, frmt in items(p.options.mangleRules):
       if s.match(pattern):
-        result = s.replace(pattern, frmt)
+        result = s.replacef(pattern, frmt)
         break mangle
     block prefixes:
       for prefix in items(p.options.prefixes): 
@@ -674,21 +674,17 @@ proc addTypeDef(section, name, t: PNode) =
   addSon(section, def)
   
 proc otherTypeDef(p: var TParser, section, typ: PNode) = 
-  var name, t: PNode
-  case p.tok.xkind
-  of pxParLe: 
+  var name: PNode
+  var t = typ
+  if p.tok.xkind == pxStar:
+    t = pointer(p, t)
+  if p.tok.xkind == pxParLe: 
     # function pointer: typedef typ (*name)();
-    var x = parseFunctionPointerDecl(p, typ)
+    var x = parseFunctionPointerDecl(p, t)
     name = x[0]
     t = x[2]
-  of pxStar:
-    # typedef typ *b;
-    t = pointer(p, typ)
-    markTypeIdent(p, t)
-    name = skipIdentExport(p)
   else: 
     # typedef typ name;
-    t = typ
     markTypeIdent(p, t)
     name = skipIdentExport(p)
   t = parseTypeSuffix(p, t)
diff --git a/compiler/c2nim/tests/systest.c b/compiler/c2nim/tests/systest.c
index 4ba1d9044..d1fbb6784 100755
--- a/compiler/c2nim/tests/systest.c
+++ b/compiler/c2nim/tests/systest.c
@@ -10,6 +10,7 @@ extern "C" {
 #endif
 
 typedef void (*callback_t) (int rc);
+typedef const char* (*callback2)(int rc, long L, const char* buffer);
 
 int   aw_callback_set (AW_CALLBACK c, callback_t callback );
 int   aw_instance_callback_set (AW_CALLBACK c, callback_t callback);