From fa4223e4969c4c98b50b8e9fdac486172f809384 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 7 Apr 2015 21:34:23 +0100 Subject: [PATCH] Fix parsing of extern "C" and typedef for example: extern "C" typedef void (*Hook2_t)(int, const char *); extern "C" typedef int Integer; Closes #375 --- CHANGES.current | 5 +++++ Examples/test-suite/extern_c.i | 15 +++++++++++++++ Source/CParse/parser.y | 22 ++++++++-------------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c8a376e0a..c1e293413 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.6 (in progress) =========================== +2015-04-07: wsfulton + Fix #375 - parsing of extern "C" and typedef for example: + extern "C" typedef void (*Hook2_t)(int, const char *); + extern "C" typedef int Integer; + 2015-03-12: olly -DSWIG_DIRECTOR_STATIC is now supported for all languages with director support, not only Python and PHP. diff --git a/Examples/test-suite/extern_c.i b/Examples/test-suite/extern_c.i index 9c17d18fb..e56d9f128 100644 --- a/Examples/test-suite/extern_c.i +++ b/Examples/test-suite/extern_c.i @@ -14,3 +14,18 @@ typedef int Integer2; void RealFunction(int value) {} %} + +%inline %{ +extern "C" { + typedef void (*Hook1_t)(int, const char *); +} +extern "C" typedef void (*Hook2_t)(int, const char *); +void funcy1(Hook1_t) {} +void funcy2(Hook2_t) {} +Hook1_t hook1; +Hook2_t hook2; + +extern "C" typedef int Integer; +Integer int1; +%} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 1fb759081..3050cd02a 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -1414,7 +1414,7 @@ static void mark_nodes_as_extend(Node *n) { /* Misc */ %type identifier; %type initializer cpp_const exception_specification; -%type storage_class; +%type storage_class extern_string; %type parms ptail rawparms varargs_parms ; %type templateparameters templateparameterstail; %type

parm valparm rawvalparms valparms valptail ; @@ -4652,9 +4652,7 @@ anon_bitfield_type : primitive_type { $$ = $1; /* ====================================================================== * PRIMITIVES * ====================================================================== */ - -storage_class : EXTERN { $$ = "extern"; } - | EXTERN string { +extern_string : EXTERN string { if (strcmp($2,"C") == 0) { $$ = "externc"; } else if (strcmp($2,"C++") == 0) { @@ -4664,16 +4662,12 @@ storage_class : EXTERN { $$ = "extern"; } $$ = 0; } } - | EXTERN string THREAD_LOCAL { - if (strcmp($2,"C") == 0) { - $$ = "externc thread_local"; - } else if (strcmp($2,"C++") == 0) { - $$ = "extern thread_local"; - } else { - Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2); - $$ = 0; - } - } + ; + +storage_class : EXTERN { $$ = "extern"; } + | extern_string { $$ = $1; } + | extern_string THREAD_LOCAL { $$ = "thread_local"; } + | extern_string TYPEDEF { $$ = "typedef"; } | STATIC { $$ = "static"; } | TYPEDEF { $$ = "typedef"; } | VIRTUAL { $$ = "virtual"; }