mirror of https://github.com/swig/swig
fixed %template within %extend, test added
fixed language symbol table nested classes name separator, test added fixed %feature "flatnested" working with %extend fixed Swig_offset_string for empty string added simple template to save/restore values in current scope (readability reasons)
This commit is contained in:
parent
8dba8b1fde
commit
b4fef06c42
|
@ -29,6 +29,7 @@ public class template_nested_runme {
|
||||||
OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass();
|
OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass();
|
||||||
inner2.setEmbeddedVar(2);
|
inner2.setEmbeddedVar(2);
|
||||||
OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2);
|
OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2);
|
||||||
|
OuterClass.T_OuterClassInner1Double inner3 = new OuterClass.T_OuterClassInner1Double();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,10 +167,16 @@ struct Outer {
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
typedef struct InnerSameName {
|
typedef struct InnerSameName {
|
||||||
Integer x;
|
Integer x;
|
||||||
|
struct InnerSameName2 {};
|
||||||
} InnerSameName;
|
} InnerSameName;
|
||||||
|
|
||||||
InnerSameName* makeInnerSameName() { return 0; }
|
InnerSameName* makeInnerSameName() { return 0; }
|
||||||
};
|
};
|
||||||
|
#if defined(SWIGCSHARP) || defined (SWIGJAVA)
|
||||||
|
// place a class with the same name as in Outer in global scope, to test language symbol table
|
||||||
|
class InnerSameName {};
|
||||||
|
class InnerSameName2 {};
|
||||||
|
#endif
|
||||||
%}
|
%}
|
||||||
|
|
||||||
// Ignore nested struct instance
|
// Ignore nested struct instance
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace ns {
|
||||||
%}
|
%}
|
||||||
%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
|
%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
|
||||||
%template(T_NormalTemplateInt) ns::NormalTemplate<int>;
|
%template(T_NormalTemplateInt) ns::NormalTemplate<int>;
|
||||||
|
%template(T_NormalTemplateDouble) ns::NormalTemplate<double>;
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
namespace ns {
|
namespace ns {
|
||||||
|
@ -70,6 +71,9 @@ namespace ns {
|
||||||
};
|
};
|
||||||
Inner2<int> useInner2(const Inner2<int>& inner) { return inner; }
|
Inner2<int> useInner2(const Inner2<int>& inner) { return inner; }
|
||||||
Inner2<NormalClass> useInner2Again(const Inner2<NormalClass>& inner) { return inner; }
|
Inner2<NormalClass> useInner2Again(const Inner2<NormalClass>& inner) { return inner; }
|
||||||
|
#ifdef SWIG
|
||||||
|
%template(T_OuterClassInner1Double) Inner1<double>;
|
||||||
|
#endif
|
||||||
int iii;
|
int iii;
|
||||||
};
|
};
|
||||||
struct ABC {
|
struct ABC {
|
||||||
|
@ -105,8 +109,10 @@ namespace ns {
|
||||||
NestedStruct useNestedStruct(const NestedStruct& inner) { return inner; }
|
NestedStruct useNestedStruct(const NestedStruct& inner) { return inner; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
%extend ns::OuterClass {
|
||||||
|
%template(T_OuterClassInner2Double) Inner2<double>;
|
||||||
|
}
|
||||||
|
|
||||||
%template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod<ns::NormalClass>;
|
%template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod<ns::NormalClass>;
|
||||||
%template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1<int>;
|
%template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1<int>;
|
||||||
|
|
|
@ -1311,16 +1311,18 @@ static void default_arguments(Node *n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* tag_nodes()
|
* mark_nodes_as_extend()
|
||||||
*
|
*
|
||||||
* Used by the parser to mark subtypes with extra information.
|
* Used by the %extend to mark subtypes with "feature:extend".
|
||||||
|
* template instances declared within %extend are skipped
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void tag_nodes(Node *n, const_String_or_char_ptr attrname, DOH *value) {
|
static void mark_nodes_as_extend(Node *n) {
|
||||||
while (n) {
|
for (; n; n = nextSibling(n)) {
|
||||||
Setattr(n, attrname, value);
|
if (Getattr(n, "template") && Strcmp(nodeType(n), "class") == 0)
|
||||||
tag_nodes(firstChild(n), attrname, value);
|
continue;
|
||||||
n = nextSibling(n);
|
Setattr(n, "feature:extend", "1");
|
||||||
|
mark_nodes_as_extend(firstChild(n));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1648,9 +1650,7 @@ extend_directive : EXTEND options idcolon LBRACE {
|
||||||
clsname = make_class_name($3);
|
clsname = make_class_name($3);
|
||||||
Setattr($$,"name",clsname);
|
Setattr($$,"name",clsname);
|
||||||
|
|
||||||
/* Mark members as extend */
|
mark_nodes_as_extend($6);
|
||||||
|
|
||||||
tag_nodes($6,"feature:extend",(char*) "1");
|
|
||||||
if (current_class) {
|
if (current_class) {
|
||||||
/* We add the extension to the previously defined class */
|
/* We add the extension to the previously defined class */
|
||||||
appendChild($$,$6);
|
appendChild($$,$6);
|
||||||
|
@ -4267,7 +4267,7 @@ cpp_members : cpp_member cpp_members {
|
||||||
}
|
}
|
||||||
} cpp_members RBRACE cpp_members {
|
} cpp_members RBRACE cpp_members {
|
||||||
$$ = new_node("extend");
|
$$ = new_node("extend");
|
||||||
tag_nodes($4,"feature:extend",(char*) "1");
|
mark_nodes_as_extend($4);
|
||||||
appendChild($$,$4);
|
appendChild($$,$4);
|
||||||
set_nextSibling($$,$6);
|
set_nextSibling($$,$6);
|
||||||
}
|
}
|
||||||
|
|
|
@ -559,9 +559,11 @@ Allocate():
|
||||||
virtual int classDeclaration(Node *n) {
|
virtual int classDeclaration(Node *n) {
|
||||||
Symtab *symtab = Swig_symbol_current();
|
Symtab *symtab = Swig_symbol_current();
|
||||||
Swig_symbol_setscope(Getattr(n, "symtab"));
|
Swig_symbol_setscope(Getattr(n, "symtab"));
|
||||||
Node *oldInclass = inclass;
|
save_value<Node*> oldInclass(inclass);
|
||||||
AccessMode oldAcessMode = cplus_mode;
|
save_value<AccessMode> oldAcessMode(cplus_mode);
|
||||||
|
save_value<int> oldExtendMode(extendmode);
|
||||||
|
if (Getattr(n, "template"))
|
||||||
|
extendmode = 0;
|
||||||
if (!CPlusPlus) {
|
if (!CPlusPlus) {
|
||||||
/* Always have default constructors/destructors in C */
|
/* Always have default constructors/destructors in C */
|
||||||
Setattr(n, "allocate:default_constructor", "1");
|
Setattr(n, "allocate:default_constructor", "1");
|
||||||
|
@ -729,8 +731,6 @@ Allocate():
|
||||||
|
|
||||||
/* Only care about default behavior. Remove temporary values */
|
/* Only care about default behavior. Remove temporary values */
|
||||||
Setattr(n, "allocate:visit", "1");
|
Setattr(n, "allocate:visit", "1");
|
||||||
inclass = oldInclass;
|
|
||||||
cplus_mode = oldAcessMode;
|
|
||||||
Swig_symbol_setscope(symtab);
|
Swig_symbol_setscope(symtab);
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1888,10 +1888,10 @@ public:
|
||||||
if (Node *outer = Getattr(n, "nested:outer")) {
|
if (Node *outer = Getattr(n, "nested:outer")) {
|
||||||
String *outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
|
String *outerClassesPrefix = Copy(Getattr(outer, "sym:name"));
|
||||||
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
|
for (outer = Getattr(outer, "nested:outer"); outer != 0; outer = Getattr(outer, "nested:outer")) {
|
||||||
Push(outerClassesPrefix, "::");
|
Push(outerClassesPrefix, ".");
|
||||||
Push(outerClassesPrefix, Getattr(outer, "sym:name"));
|
Push(outerClassesPrefix, Getattr(outer, "sym:name"));
|
||||||
}
|
}
|
||||||
String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix;
|
String *fnspace = nspace ? NewStringf("%s.%s", nspace, outerClassesPrefix) : outerClassesPrefix;
|
||||||
if (!addSymbol(proxy_class_name, n, fnspace))
|
if (!addSymbol(proxy_class_name, n, fnspace))
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
if (nspace)
|
if (nspace)
|
||||||
|
|
|
@ -1969,8 +1969,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outerClassesPrefix) {
|
if (outerClassesPrefix) {
|
||||||
Replaceall(outerClassesPrefix, ".", "::");
|
String *fnspace = nspace ? NewStringf("%s.%s", nspace, outerClassesPrefix) : outerClassesPrefix;
|
||||||
String *fnspace = nspace ? NewStringf("%s::%s", nspace, outerClassesPrefix) : outerClassesPrefix;
|
|
||||||
if (!addSymbol(proxy_class_name, n, fnspace))
|
if (!addSymbol(proxy_class_name, n, fnspace))
|
||||||
return SWIG_ERROR;
|
return SWIG_ERROR;
|
||||||
if (nspace)
|
if (nspace)
|
||||||
|
|
|
@ -525,15 +525,9 @@ int Language::top(Node *n) {
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Language::extendDirective(Node *n) {
|
int Language::extendDirective(Node *n) {
|
||||||
int oldam = Extend;
|
save_value<int> oldam(Extend, CWRAP_EXTEND);
|
||||||
AccessMode oldmode = cplus_mode;
|
save_value<AccessMode> oldmode(cplus_mode, PUBLIC);
|
||||||
Extend = CWRAP_EXTEND;
|
|
||||||
cplus_mode = PUBLIC;
|
|
||||||
|
|
||||||
emit_children(n);
|
emit_children(n);
|
||||||
|
|
||||||
Extend = oldam;
|
|
||||||
cplus_mode = oldmode;
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2486,7 +2480,9 @@ int Language::classDeclaration(Node *n) {
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Language::classHandler(Node *n) {
|
int Language::classHandler(Node *n) {
|
||||||
|
save_value<int> oldExtend(Extend);
|
||||||
|
if (Getattr(n, "template"))
|
||||||
|
Extend = 0;
|
||||||
bool hasDirector = Swig_directorclass(n) ? true : false;
|
bool hasDirector = Swig_directorclass(n) ? true : false;
|
||||||
|
|
||||||
/* Emit all of the class members */
|
/* Emit all of the class members */
|
||||||
|
@ -2519,7 +2515,7 @@ int Language::classHandler(Node *n) {
|
||||||
if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) {
|
if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) {
|
||||||
Node *vtable = Getattr(n, "vtable");
|
Node *vtable = Getattr(n, "vtable");
|
||||||
String *symname = Getattr(n, "sym:name");
|
String *symname = Getattr(n, "sym:name");
|
||||||
AccessMode old_mode = cplus_mode;
|
save_value<AccessMode> old_mode(cplus_mode);
|
||||||
cplus_mode = PROTECTED;
|
cplus_mode = PROTECTED;
|
||||||
int len = Len(vtable);
|
int len = Len(vtable);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
|
@ -2548,7 +2544,6 @@ int Language::classHandler(Node *n) {
|
||||||
}
|
}
|
||||||
Delete(wrapname);
|
Delete(wrapname);
|
||||||
}
|
}
|
||||||
cplus_mode = old_mode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -432,6 +432,8 @@ void Swig_nested_process_classes(Node *n) {
|
||||||
removeNode(c);
|
removeNode(c);
|
||||||
if (!checkAttribute(c, "access", "public"))
|
if (!checkAttribute(c, "access", "public"))
|
||||||
SetFlag(c, "feature:ignore");
|
SetFlag(c, "feature:ignore");
|
||||||
|
else if (Strcmp(nodeType(n),"extend") == 0 && Strcmp(nodeType(parentNode(n)),"class") == 0)
|
||||||
|
insertNodeAfter(parentNode(n), c);
|
||||||
else
|
else
|
||||||
insertNodeAfter(n, c);
|
insertNodeAfter(n, c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -423,4 +423,13 @@ void Swig_process_types(Node *n);
|
||||||
void Swig_nested_process_classes(Node *n);
|
void Swig_nested_process_classes(Node *n);
|
||||||
void Swig_nested_name_unnamed_c_structs(Node *n);
|
void Swig_nested_name_unnamed_c_structs(Node *n);
|
||||||
|
|
||||||
|
template <class T> class save_value {
|
||||||
|
T _value;
|
||||||
|
T& _value_ptr;
|
||||||
|
public:
|
||||||
|
save_value(T& value) : _value(value), _value_ptr(value){}
|
||||||
|
save_value(T& value, T new_val) : _value(value), _value_ptr(value){ value = new_val; }
|
||||||
|
~save_value(){ _value_ptr = _value; }
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -417,7 +417,7 @@ class TypePass:private Dispatcher {
|
||||||
String *unnamed = Getattr(n, "unnamed");
|
String *unnamed = Getattr(n, "unnamed");
|
||||||
String *storage = Getattr(n, "storage");
|
String *storage = Getattr(n, "storage");
|
||||||
String *kind = Getattr(n, "kind");
|
String *kind = Getattr(n, "kind");
|
||||||
Node *oldinclass = inclass;
|
save_value<Node*> oldinclass(inclass);
|
||||||
List *olist = normalize;
|
List *olist = normalize;
|
||||||
Symtab *symtab;
|
Symtab *symtab;
|
||||||
String *nname = 0;
|
String *nname = 0;
|
||||||
|
@ -537,8 +537,6 @@ class TypePass:private Dispatcher {
|
||||||
|
|
||||||
normalize = olist;
|
normalize = olist;
|
||||||
|
|
||||||
inclass = oldinclass;
|
|
||||||
|
|
||||||
/* If in a namespace, patch the class name */
|
/* If in a namespace, patch the class name */
|
||||||
if (nname) {
|
if (nname) {
|
||||||
Setattr(n, "name", nname);
|
Setattr(n, "name", nname);
|
||||||
|
|
|
@ -1154,13 +1154,13 @@ String *Swig_string_strip(String *s) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void Swig_offset_string(String *s, int number) {
|
void Swig_offset_string(String *s, int number) {
|
||||||
char *res;
|
char *res, *p, *end, *start;
|
||||||
char *p;
|
|
||||||
char *end;
|
|
||||||
/* count a number of lines in s */
|
/* count a number of lines in s */
|
||||||
int lines = 1;
|
int lines = 1;
|
||||||
int len = Len(s);
|
int len = Len(s);
|
||||||
char *start = strchr(Char(s), '\n');
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
start = strchr(Char(s), '\n');
|
||||||
while (start) {
|
while (start) {
|
||||||
++lines;
|
++lines;
|
||||||
start = strchr(start + 1, '\n');
|
start = strchr(start + 1, '\n');
|
||||||
|
|
Loading…
Reference in New Issue