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
This commit is contained in:
William S Fulton 2015-04-07 21:34:23 +01:00
commit fa4223e496
3 changed files with 28 additions and 14 deletions

View file

@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress) 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 2015-03-12: olly
-DSWIG_DIRECTOR_STATIC is now supported for all languages with -DSWIG_DIRECTOR_STATIC is now supported for all languages with
director support, not only Python and PHP. director support, not only Python and PHP.

View file

@ -14,3 +14,18 @@ typedef int Integer2;
void RealFunction(int value) {} 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;
%}

View file

@ -1414,7 +1414,7 @@ static void mark_nodes_as_extend(Node *n) {
/* Misc */ /* Misc */
%type <id> identifier; %type <id> identifier;
%type <dtype> initializer cpp_const exception_specification; %type <dtype> initializer cpp_const exception_specification;
%type <id> storage_class; %type <id> storage_class extern_string;
%type <pl> parms ptail rawparms varargs_parms ; %type <pl> parms ptail rawparms varargs_parms ;
%type <pl> templateparameters templateparameterstail; %type <pl> templateparameters templateparameterstail;
%type <p> parm valparm rawvalparms valparms valptail ; %type <p> parm valparm rawvalparms valparms valptail ;
@ -4652,9 +4652,7 @@ anon_bitfield_type : primitive_type { $$ = $1;
/* ====================================================================== /* ======================================================================
* PRIMITIVES * PRIMITIVES
* ====================================================================== */ * ====================================================================== */
extern_string : EXTERN string {
storage_class : EXTERN { $$ = "extern"; }
| EXTERN string {
if (strcmp($2,"C") == 0) { if (strcmp($2,"C") == 0) {
$$ = "externc"; $$ = "externc";
} else if (strcmp($2,"C++") == 0) { } else if (strcmp($2,"C++") == 0) {
@ -4664,16 +4662,12 @@ storage_class : EXTERN { $$ = "extern"; }
$$ = 0; $$ = 0;
} }
} }
| EXTERN string THREAD_LOCAL { ;
if (strcmp($2,"C") == 0) {
$$ = "externc thread_local"; storage_class : EXTERN { $$ = "extern"; }
} else if (strcmp($2,"C++") == 0) { | extern_string { $$ = $1; }
$$ = "extern thread_local"; | extern_string THREAD_LOCAL { $$ = "thread_local"; }
} else { | extern_string TYPEDEF { $$ = "typedef"; }
Swig_warning(WARN_PARSE_UNDEFINED_EXTERN,cparse_file, cparse_line,"Unrecognized extern type \"%s\".\n", $2);
$$ = 0;
}
}
| STATIC { $$ = "static"; } | STATIC { $$ = "static"; }
| TYPEDEF { $$ = "typedef"; } | TYPEDEF { $$ = "typedef"; }
| VIRTUAL { $$ = "virtual"; } | VIRTUAL { $$ = "virtual"; }