From e9b7d5e68eeeb6d468d407437502fd1c178adc43 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 28 Sep 2011 00:41:40 +0200 Subject: [PATCH] c2nim: bugfix: parsing of typedef'ed function pointers --- compiler/c2nim/cparse.nim | 18 +++++++----------- compiler/c2nim/tests/systest.c | 1 + 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);