From: Vladimir K. <vka...@op...> - 2013-01-31 00:54:09
|
>> Hi, >> >> Any thoughts what should be done with unnamed structs? >> >> While working on nested classes support I met the test case >> "nested_structs", where the following is declared: >> >> %inline %{ >> struct Outer { >> struct { >> int val; >> } inner1, inner2, *inner3, inner4[1]; >> struct Named { >> int val; >> } inside1, inside2, *inside3, inside4[1]; >> } outer; >> >> Currently SWIG just outputs a warning that it cannot generate a >> wrapper for unnamed struct. >> >> Does anybody care about that, or it may be just left as is? >> > I don't recall anyone complaining about this before. Also we don't wrap > global unnamed structs, so I would just leave it as ignored. > >> We could e.g. adapt the old %name command to the task of assigning >> names to the unnamed structures, but on the other hand if someone >> is able to modify the header, he is as well able to give a name to the >> struct itself. >> >> Or perhaps some long unreadable name can be generated by default (like >> __unnamed_struct_SWIG_generated_123 (with unique counter)) >> This feature should probably be optional, as someone may not want to >> clutter scripting interface with such names. >> >> Other ideas? >> > %feature and %rename require types, but there is no type associated with > these anonymous structs. Some different mechanism would need to be > invented as to how to address these types. Or we'd have to adapt them to > use non standard syntax such as Outer::inner1. But given the lack of > interest in providing wrappers for non-nested anonymous structs, I don't > think it is worth putting any effort into this just yet. Some additional thoughts on the subject: Currently, working on nested classes, I already eliminated all the warnings in the csharp test suite except those generated by unnamed structures. There are about 20 of them. Also, I've broken/removed old C nested structures support that was copying struct definition to an %insert code and adding a typedef for it, generating a name from the outer class and data declarator names. It looked like this: struct Outer { struct { int val1; int val2; } data1, data2; }; and in the generated .c file there was inserted: typedef struct { int val1; int val2; } Outer_data1; typedef struct { int val1; int val2; } Outer_data2; and the proxy class looked like this: ... class Outer { public Outer_data1 data1; public Outer_data2 data2; } Of course this solution was rather ugly and brittle, but it was working, and some legacy code will no doubt be broken with this support removed. What I have in mind as a possible replacement is not wrapping the unnamed structure itself, but generating accessors to the nested data members. So that e.g. in C# proxy class would look like class Outer { public int data1_val1 {get;set;} public int data1_val2 {get;set;} public int data2_val1 {get;set;} public int data2_val2 {get;set;} } This solution requires no special features, and may be implemented almost entirely in the language module. But, of course, as you say, given the lack of interest, this may be postponed. Vladimir |