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_onoff \
nested_class \
nested_directors \
nested_comment \
nested_scope \
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;
}
/* -----------------------------------------------------------------------------
* 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()
* ------------------------------------------------------------ */

View file

@ -2373,6 +2373,7 @@ int Language::classDeclaration(Node *n) {
String *oldDirectorClassName = DirectorClassName;
String *oldNSpace = NSpace;
Node *oldCurrentClass = CurrentClass;
int dir = 0;
String *kind = Getattr(n, "kind");
String *name = Getattr(n, "name");
@ -2424,7 +2425,6 @@ int Language::classDeclaration(Node *n) {
/* Call classHandler() here */
if (!ImportMode) {
int dir = 0;
if (directorsEnabled()) {
int ndir = GetFlag(n, "feature:director");
int nndir = GetFlag(n, "feature:nodirector");
@ -2481,7 +2481,9 @@ int Language::classDeclaration(Node *n) {
ClassPrefix = oldClassPrefix;
Delete(ClassName);
ClassName = oldClassName;
Delete(DirectorClassName);
if (dir) {
Delete(DirectorClassName);
}
DirectorClassName = oldDirectorClassName;
return SWIG_OK;
}
@ -2749,7 +2751,7 @@ int Language::constructorHandler(Node *n) {
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);
functionWrapper(n);
Delete(mrename);
@ -2771,7 +2773,7 @@ int Language::copyconstructorHandler(Node *n) {
String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code,
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);
functionWrapper(n);
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.
* ----------------------------------------------------------------------------- */
int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) {
ParmList *parms;
Parm *prefix_args;
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) {
Parm *p;
ParmList *directorparms;
SwigType *type;
int use_director;
String *directorScope = NewString(nspace);
Replace(directorScope, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
use_director = Swig_directorclass(n);
parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
int use_director = Swig_directorclass(n);
ParmList *parms = CopyParmList(nonvoid_parms(Getattr(n, "parms")));
/* 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) {
Parm *p2, *p3;
@ -1250,18 +1241,11 @@ int Swig_ConstructorToFunction(Node *n, const_String_or_char_ptr nspace, String
if (use_director) {
Node *parent = Swig_methodclass(n);
int abstract = Getattr(parent, "abstracts") != 0;
String *name = Getattr(parent, "sym:name");
String *directorname;
String *action = NewStringEmpty();
String *tmp_none_comparison = Copy(none_comparison);
String *director_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");
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);
Delete(tmp_none_comparison);
Delete(action);
Delete(directorname);
} else {
String *call = Swig_cppconstructor_call(classname, parms);
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)
Delete(directorparms);
Delete(parms);
Delete(directorScope);
return SWIG_OK;
}

View file

@ -374,7 +374,7 @@ extern int ParmList_is_compactdefargs(ParmList *p);
/* --- 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_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_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);