fixes for director class naming when nested classes are used

This commit is contained in:
Vladimir Kalinin 2014-03-13 14:57:17 +04:00
commit e18044185e
7 changed files with 67 additions and 47 deletions

View file

@ -284,6 +284,7 @@ CPP_TEST_CASES += \
naturalvar_more \ naturalvar_more \
naturalvar_onoff \ naturalvar_onoff \
nested_class \ nested_class \
nested_directors \
nested_comment \ nested_comment \
nested_scope \ nested_scope \
nested_workaround \ nested_workaround \

View file

@ -0,0 +1,20 @@
using System;
using nested_directorsNamespace;
#pragma warning disable 219
public class CNested : Base.Nest {
public override bool GetValue() {return true;}
}
public class CSub : Sub {
protected override bool GetValue() { return base.GetValue(); }
public bool Test(){ return GetValue(); }
}
public class runme {
static void Main() {
CNested n = new CNested();
CSub s = new CSub();
if (!s.Test())
throw new Exception("Sub.GetValue");
}
}

View file

@ -0,0 +1,35 @@
%module(directors="1", allprotected="1") nested_directors
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Base::Nest;
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Sub::IListener;
%feature("director") Base;
%feature("director") Sub;
%feature("director") Base::Nest;
%inline %{
namespace NN {
class Base {
public:
virtual ~Base(){}
class Nest {
public:
virtual ~Nest(){}
virtual bool GetValue(){ return false; }
};
protected:
virtual bool DoNothing() = 0;
};
class Sub : public Base {
public:
class IListener {
};
public:
virtual ~Sub(){}
protected:
void DoSomething(){}
virtual bool GetValue() const { return true; }
};
}
%}

View file

@ -203,26 +203,6 @@ public:
return proxyname; return proxyname;
} }
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *directorClassName(Node *n) {
String *dirclassname;
const char *attrib = "director:classname";
if (!(dirclassname = Getattr(n, attrib))) {
String *classname = getClassPrefix();
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
}
else
dirclassname = Copy(dirclassname);
return dirclassname;
}
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* main() * main()
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */

View file

@ -2373,6 +2373,7 @@ int Language::classDeclaration(Node *n) {
String *oldDirectorClassName = DirectorClassName; String *oldDirectorClassName = DirectorClassName;
String *oldNSpace = NSpace; String *oldNSpace = NSpace;
Node *oldCurrentClass = CurrentClass; Node *oldCurrentClass = CurrentClass;
int dir = 0;
String *kind = Getattr(n, "kind"); String *kind = Getattr(n, "kind");
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
@ -2424,7 +2425,6 @@ int Language::classDeclaration(Node *n) {
/* Call classHandler() here */ /* Call classHandler() here */
if (!ImportMode) { if (!ImportMode) {
int dir = 0;
if (directorsEnabled()) { if (directorsEnabled()) {
int ndir = GetFlag(n, "feature:director"); int ndir = GetFlag(n, "feature:director");
int nndir = GetFlag(n, "feature:nodirector"); int nndir = GetFlag(n, "feature:nodirector");
@ -2481,7 +2481,9 @@ int Language::classDeclaration(Node *n) {
ClassPrefix = oldClassPrefix; ClassPrefix = oldClassPrefix;
Delete(ClassName); Delete(ClassName);
ClassName = oldClassName; ClassName = oldClassName;
Delete(DirectorClassName); if (dir) {
Delete(DirectorClassName);
}
DirectorClassName = oldDirectorClassName; DirectorClassName = oldDirectorClassName;
return SWIG_OK; return SWIG_OK;
} }
@ -2749,7 +2751,7 @@ int Language::constructorHandler(Node *n) {
Setattr(n, "handled_as_constructor", "1"); Setattr(n, "handled_as_constructor", "1");
} }
Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend, DirectorClassName);
Setattr(n, "sym:name", mrename); Setattr(n, "sym:name", mrename);
functionWrapper(n); functionWrapper(n);
Delete(mrename); Delete(mrename);
@ -2771,7 +2773,7 @@ int Language::copyconstructorHandler(Node *n) {
String *director_ctor = get_director_ctor_code(n, director_ctor_code, String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code, director_prot_ctor_code,
abstracts); abstracts);
Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend); Swig_ConstructorToFunction(n, NSpace, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend, DirectorClassName);
Setattr(n, "sym:name", mrename); Setattr(n, "sym:name", mrename);
functionWrapper(n); functionWrapper(n);
Delete(mrename); Delete(mrename);

View file

@ -1181,23 +1181,14 @@ Node *Swig_directormap(Node *module, String *type) {
* This function creates a C wrapper for a C constructor function. * This function creates a C wrapper for a C constructor function.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname) {
ParmList *parms;
Parm *prefix_args;
Parm *p; Parm *p;
ParmList *directorparms; ParmList *directorparms;
SwigType *type; SwigType *type;
int use_director; int use_director = Swig_directorclass(n);
String *directorScope = NewString(nspace); ParmList *parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
use_director = Swig_directorclass(n);
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
/* Prepend the list of prefix_args (if any) */ /* Prepend the list of prefix_args (if any) */
prefix_args = Getattr(n, "director:prefix_args"); Parm *prefix_args = Getattr(n, "director:prefix_args");
if (prefix_args != NIL) { if (prefix_args != NIL) {
Parm *p2, *p3; Parm *p2, *p3;
@ -1250,18 +1241,11 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
if (use_director) { if (use_director) {
Node *parent = Swig_methodclass(n); Node *parent = Swig_methodclass(n);
int abstract = Getattr(parent, "abstracts") != 0; int abstract = Getattr(parent, "abstracts") != 0;
String *name = Getattr(parent, "sym:name");
String *directorname;
String *action = NewStringEmpty(); String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison); String *tmp_none_comparison = Copy(none_comparison);
String *director_call; String *director_call;
String *nodirector_call; String *nodirector_call;
if (Len(directorScope) > 0)
directorname = NewStringf("SwigDirector_%s_%s", directorScope, name);
else
directorname = NewStringf("SwigDirector_%s", name);
Replaceall(tmp_none_comparison, "$arg", "arg1"); Replaceall(tmp_none_comparison, "$arg", "arg1");
director_call = Swig_cppconstructor_director_call(directorname, directorparms); director_call = Swig_cppconstructor_director_call(directorname, directorparms);
@ -1300,7 +1284,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
Setattr(n, "wrap:action", action); Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison); Delete(tmp_none_comparison);
Delete(action); Delete(action);
Delete(directorname);
} else { } else {
String *call = Swig_cppconstructor_call(classname, parms); String *call = Swig_cppconstructor_call(classname, parms);
String *cres = Swig_cresult(type, Swig_cresult_name(), call); String *cres = Swig_cresult(type, Swig_cresult_name(), call);
@ -1322,7 +1305,6 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
if (directorparms != parms) if (directorparms != parms)
Delete(directorparms); Delete(directorparms);
Delete(parms); Delete(parms);
Delete(directorScope);
return SWIG_OK; return SWIG_OK;
} }

View file

@ -374,7 +374,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
/* --- Transformations --- */ /* --- Transformations --- */
extern int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director); extern int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int flags, SwigType *director_type, int is_director);
extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags); extern int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags, String *directorname);
extern int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags); extern int Swig_DestructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, int cplus, int flags);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);