Merge branch 'wkalinin-csymbols-1'

* wkalinin-csymbols-1:
  obscure case workaround in std::set wrapper, where ignored type still need to be processed
  global unnamed structures ignored
  test added for nested unnamed C struct %extend
  %extend for nested unnamed C structs
This commit is contained in:
William S Fulton 2014-05-20 18:10:41 +01:00
commit 9e4bce051d
5 changed files with 39 additions and 11 deletions

View file

@ -44,6 +44,13 @@
return $self->num; return $self->num;
} }
} }
%extend FOO_bar {
void bar_extend() {
$self->d = 1;
}
};
#endif #endif
%inline %{ %inline %{
@ -72,5 +79,17 @@ typedef struct {
int num; int num;
} lowB_instance; } lowB_instance;
} NestedB; } NestedB;
typedef struct {
int a;
union {
char c;
int d;
} bar;
} FOO;
struct {
int i;
} THING;
%} %}

View file

@ -41,7 +41,7 @@ int yyparse();
static Node *top = 0; /* Top of the generated parse tree */ static Node *top = 0; /* Top of the generated parse tree */
static int unnamed = 0; /* Unnamed datatype counter */ static int unnamed = 0; /* Unnamed datatype counter */
static Hash *extendhash = 0; /* Hash table of added methods */ Hash *extendhash = 0; /* Hash table of added methods */
static Hash *classes = 0; /* Hash table of classes */ static Hash *classes = 0; /* Hash table of classes */
static Hash *classes_typedefs = 0; /* Hash table of typedef classes: typedef struct X {...} Y; */ static Hash *classes_typedefs = 0; /* Hash table of typedef classes: typedef struct X {...} Y; */
static Symtab *prev_symtab = 0; static Symtab *prev_symtab = 0;
@ -655,7 +655,7 @@ static void add_symbols_copy(Node *n) {
actually needs to take precedence. Therefore, we will selectively nuke symbols actually needs to take precedence. Therefore, we will selectively nuke symbols
from the current symbol table, replacing them with the added methods */ from the current symbol table, replacing them with the added methods */
static void merge_extensions(Node *cls, Node *am) { void merge_extensions(Node *cls, Node *am) {
Node *n; Node *n;
Node *csym; Node *csym;
@ -708,7 +708,7 @@ static void merge_extensions(Node *cls, Node *am) {
} }
} }
static void append_previous_extension(Node *cls, Node *am) { void append_previous_extension(Node *cls, Node *am) {
Node *n, *ne; Node *n, *ne;
Node *pe = 0; Node *pe = 0;
Node *ae = 0; Node *ae = 0;
@ -737,7 +737,7 @@ static void append_previous_extension(Node *cls, Node *am) {
/* Check for unused %extend. Special case, don't report unused /* Check for unused %extend. Special case, don't report unused
extensions for templates */ extensions for templates */
static void check_extensions() { void check_extensions() {
Iterator ki; Iterator ki;
if (!extendhash) return; if (!extendhash) return;
@ -1579,7 +1579,6 @@ program : interface {
Setattr(module_node,"name",ModuleName); Setattr(module_node,"name",ModuleName);
} }
Setattr($1,"module",module_node); Setattr($1,"module",module_node);
check_extensions();
top = $1; top = $1;
} }
| PARSETYPE parm SEMI { | PARSETYPE parm SEMI {

View file

@ -198,6 +198,7 @@ static String *external_runtime_name = 0;
enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 }; enum { STAGE1=1, STAGE2=2, STAGE3=4, STAGE4=8, STAGEOVERFLOW=16 };
static List *libfiles = 0; static List *libfiles = 0;
static List *all_output_files = 0; static List *all_output_files = 0;
extern "C" void check_extensions();
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* check_extension() * check_extension()
@ -1172,6 +1173,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
Printf(stdout, "Processing unnamed structs...\n"); Printf(stdout, "Processing unnamed structs...\n");
Swig_nested_name_unnamed_c_structs(top); Swig_nested_name_unnamed_c_structs(top);
} }
check_extensions();
if (Verbose) { if (Verbose) {
Printf(stdout, "Processing types...\n"); Printf(stdout, "Processing types...\n");

View file

@ -338,7 +338,9 @@ static void insertNodeAfter(Node *n, Node *c) {
set_nextSibling(n, c); set_nextSibling(n, c);
set_previousSibling(c, n); set_previousSibling(c, n);
} }
extern "C" Hash *extendhash;
extern "C" void merge_extensions(Node *cls, Node *am);
extern "C" void append_previous_extension(Node *cls, Node *am);
void Swig_nested_name_unnamed_c_structs(Node *n) { void Swig_nested_name_unnamed_c_structs(Node *n) {
if (!classhash) if (!classhash)
classhash = Getattr(n, "classes"); classhash = Getattr(n, "classes");
@ -376,16 +378,14 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
decl = nextSibling(decl); decl = nextSibling(decl);
} }
Delete(ty); Delete(ty);
// Check for extensions
/* // TODO: we can save extensions hash like class hash and move check_extensions() after nesting processing
if (extendhash) { if (extendhash) {
if (Node *am = Getattr(extendhash, name)) { if (Node *am = Getattr(extendhash, name)) {
// Merge the extension into the symbol table // Merge the extension into the symbol table
merge_extensions(c, am); merge_extensions(c, am);
append_previous_extension(c, am); append_previous_extension(c, am);
Delattr(extendhash, clsname); Delattr(extendhash, name);
} }
}*/ }
Swig_symbol_setscope(Swig_symbol_global_scope()); Swig_symbol_setscope(Swig_symbol_global_scope());
add_symbols_c(c); add_symbols_c(c);
@ -396,7 +396,12 @@ void Swig_nested_name_unnamed_c_structs(Node *n) {
Delete(ins); Delete(ins);
Delattr(c, "nested:outer"); Delattr(c, "nested:outer");
} else { } else {
// global unnamed struct - ignore it // global unnamed struct - ignore it and it's instances
SetFlag(c, "feature:ignore");
while (next && Getattr(next, "nested:unnamedtype") == c) {
SetFlag(next, "feature:ignore");
next = nextSibling(next);
}
c = next; c = next;
continue; continue;
} }

View file

@ -667,6 +667,9 @@ class TypePass:private Dispatcher {
/* Normalize types. */ /* Normalize types. */
SwigType *ty = Getattr(n, "type"); SwigType *ty = Getattr(n, "type");
if (!ty) {
return SWIG_OK;
}
normalize_type(ty); normalize_type(ty);
SwigType *decl = Getattr(n, "decl"); SwigType *decl = Getattr(n, "decl");
if (decl) { if (decl) {