mirror of https://github.com/swig/swig
Add using declarations to templates into typedef table.
Fixes #1051. Using declarations to templates were missing in SWIG's internal typedef tables. This led to a few problems, such as, templates that did not instantiate and generated C++ code that did not compile as SWIG did not know what scope the template was in. This happened mostly when a using declaration was used on a template type in a completely unrelated namespace.
This commit is contained in:
parent
bf98c5304f
commit
96e99416d7
|
@ -436,6 +436,7 @@ CPP_TEST_CASES += \
|
|||
template_methods \
|
||||
template_namespace_forward_declaration \
|
||||
template_using_directive_and_declaration_forward \
|
||||
template_using_directive_typedef \
|
||||
template_nested \
|
||||
template_nested_typemaps \
|
||||
template_ns \
|
||||
|
|
|
@ -19,32 +19,32 @@ public class template_using_directive_and_declaration_forward_runme {
|
|||
template_using_directive_and_declaration_forward.useit1b(new Thing1Int());
|
||||
template_using_directive_and_declaration_forward.useit1c(new Thing1Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit2(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2a(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2b(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2c(new Thing2Int());
|
||||
template_using_directive_and_declaration_forward.useit2d(new Thing2Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit3(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3a(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3b(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3c(new Thing3Int());
|
||||
template_using_directive_and_declaration_forward.useit3d(new Thing3Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit4(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4a(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4b(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4c(new Thing4Int());
|
||||
template_using_directive_and_declaration_forward.useit4d(new Thing4Int());
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit5(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5a(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5b(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5c(new Thing5Int());
|
||||
template_using_directive_and_declaration_forward.useit5d(new Thing5Int());
|
||||
|
||||
|
||||
//BROKEN template_using_directive_and_declaration_forward.useit7(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7a(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7b(new Thing7Int());
|
||||
template_using_directive_and_declaration_forward.useit7c(new Thing7Int());
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
import template_using_directive_typedef.*;
|
||||
|
||||
public class template_using_directive_typedef_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("template_using_directive_typedef");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
Vector_Obj vo = new Vector_Obj();
|
||||
|
||||
Holder h = new Holder();
|
||||
h.holder_use1(vo, vo, vo);
|
||||
h.holder_use2(vo, vo, vo);
|
||||
h.holder_use3(vo, vo, vo);
|
||||
|
||||
template_using_directive_typedef.tns_holder_use(vo, vo);
|
||||
template_using_directive_typedef.tns_use(vo, vo, vo);
|
||||
template_using_directive_typedef.global_holder_use(vo);
|
||||
template_using_directive_typedef.global_use(vo, vo, vo);
|
||||
template_using_directive_typedef.ns1_holder_use(vo);
|
||||
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import template_using_directive_typedef
|
||||
|
||||
vo = template_using_directive_typedef.Vector_Obj();
|
||||
|
||||
h = template_using_directive_typedef.Holder();
|
||||
h.holder_use1(vo, vo, vo);
|
||||
h.holder_use2(vo, vo, vo);
|
||||
h.holder_use3(vo, vo, vo);
|
||||
|
||||
template_using_directive_typedef.tns_holder_use(vo, vo);
|
||||
template_using_directive_typedef.tns_use(vo, vo, vo);
|
||||
template_using_directive_typedef.global_holder_use(vo);
|
||||
template_using_directive_typedef.global_use(vo, vo, vo);
|
||||
template_using_directive_typedef.ns1_holder_use(vo);
|
||||
template_using_directive_typedef.ns2_holder_use(vo, vo, vo, vo);
|
|
@ -1199,10 +1199,7 @@ class TypePass:private Dispatcher {
|
|||
} else if (Strcmp(ntype, "enum") == 0) {
|
||||
SwigType_typedef_using(Getattr(n, "uname"));
|
||||
} else if (Strcmp(ntype, "template") == 0) {
|
||||
/*
|
||||
Printf(stdout, "usingDeclaration template %s --- %s\n", Getattr(n, "name"), Getattr(n, "uname"));
|
||||
SwigType_typedef_using(Getattr(n, "uname"));
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,10 +42,15 @@
|
|||
* "name" - Scope name
|
||||
* "qname" - Fully qualified typename
|
||||
* "typetab" - Type table containing typenames and typedef information
|
||||
* For a given key in the typetab table, the value is a fully
|
||||
* qualified name if not pointing to itself.
|
||||
* "symtab" - Hash table of symbols defined in a scope
|
||||
* "inherit" - List of inherited scopes
|
||||
* "parent" - Parent scope
|
||||
*
|
||||
* The contents of these tables can be viewed for debugging using the -debug-typedef
|
||||
* option which calls SwigType_print_scope().
|
||||
*
|
||||
* Typedef information is stored in the "typetab" hash table. For example,
|
||||
* if you have these declarations:
|
||||
*
|
||||
|
@ -210,6 +215,7 @@ void SwigType_typesystem_init() {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int SwigType_typedef(const SwigType *type, const_String_or_char_ptr name) {
|
||||
/* Printf(stdout, "typedef %s %s\n", type, name); */
|
||||
if (Getattr(current_typetab, name))
|
||||
return -1; /* Already defined */
|
||||
if (Strcmp(type, name) == 0) { /* Can't typedef a name to itself */
|
||||
|
@ -660,6 +666,17 @@ static SwigType *typedef_resolve(Typetab *s, String *base) {
|
|||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SwigType_typedef_resolve()
|
||||
*
|
||||
* Given a type declaration, this function looks to reduce/resolve the type via a
|
||||
* typedef (including via C++ using declarations).
|
||||
*
|
||||
* If it is able to find a typedef, the resolved type is returned. If no typedef
|
||||
* is found NULL is returned. The type name is resolved in the current scope.
|
||||
* The type returned is not always fully qualified for the global scope, it is
|
||||
* valid for use in the current scope. If the current scope is global scope, a
|
||||
* fully qualified type should be returned.
|
||||
*
|
||||
* Some additional notes are in Doc/Manual/Extending.html.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* #define SWIG_DEBUG */
|
||||
|
@ -786,6 +803,25 @@ SwigType *SwigType_typedef_resolve(const SwigType *t) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!type && SwigType_istemplate(base)) {
|
||||
String *tprefix = SwigType_templateprefix(base);
|
||||
String *rtprefix = SwigType_typedef_resolve(tprefix);
|
||||
/* We're looking for a using declaration on the template prefix to resolve the template prefix
|
||||
* in another scope. Using declaration do not have template parameters. */
|
||||
if (rtprefix && !SwigType_istemplate(rtprefix)) {
|
||||
String *tsuffix = SwigType_templatesuffix(base);
|
||||
String *targs = SwigType_templateargs(base);
|
||||
type = NewString(rtprefix);
|
||||
newtype = 1;
|
||||
Append(type, targs);
|
||||
Append(type, tsuffix);
|
||||
Delete(targs);
|
||||
Delete(tsuffix);
|
||||
Delete(rtprefix);
|
||||
}
|
||||
Delete(tprefix);
|
||||
}
|
||||
|
||||
if (type && (Equal(base, type))) {
|
||||
if (newtype)
|
||||
Delete(type);
|
||||
|
@ -1106,10 +1142,6 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
|
|||
Parm *p;
|
||||
List *parms;
|
||||
ty = Swig_symbol_template_deftype(e, current_symtab);
|
||||
/*
|
||||
String *dt = Swig_symbol_template_deftype(e, current_symtab);
|
||||
ty = Swig_symbol_type_qualify(dt, 0);
|
||||
*/
|
||||
e = ty;
|
||||
parms = SwigType_parmlist(e);
|
||||
tprefix = SwigType_templateprefix(e);
|
||||
|
@ -1176,9 +1208,6 @@ SwigType *SwigType_typedef_qualified(const SwigType *t) {
|
|||
Delete(tprefix);
|
||||
Delete(qprefix);
|
||||
Delete(parms);
|
||||
/*
|
||||
Delete(dt);
|
||||
*/
|
||||
}
|
||||
Append(result, e);
|
||||
Delete(ty);
|
||||
|
@ -1258,7 +1287,7 @@ int SwigType_typedef_using(const_String_or_char_ptr name) {
|
|||
|
||||
String *defined_name = 0;
|
||||
|
||||
/* Printf(stdout,"using %s\n", name); */
|
||||
/* Printf(stdout, "using %s\n", name); */
|
||||
|
||||
if (!Swig_scopename_check(name))
|
||||
return -1; /* Not properly qualified */
|
||||
|
|
Loading…
Reference in New Issue