Abstract directors and typemap fixes.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5024 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Mark Rose 2003-08-30 05:03:34 +00:00
commit c1b57370b6
10 changed files with 97 additions and 17 deletions

View file

@ -1640,6 +1640,8 @@ int Language::classDeclaration(Node *n) {
int Language::classHandler(Node *n) {
bool hasDirector = Swig_directorclass(n);
/* Emit all of the class members */
emit_children(n);
@ -1659,7 +1661,7 @@ int Language::classHandler(Node *n) {
if (!ImportMode && (GenerateDefault && !Getattr(n,"feature:nodefault"))) {
if (!Getattr(n,"has_constructor") && !Getattr(n,"allocate:has_constructor") && (Getattr(n,"allocate:default_constructor"))) {
/* Note: will need to change this to support different kinds of classes */
if (!Abstract) {
if (!Abstract || hasDirector) {
Setattr(CurrentClass,"feature:new","1");
constructorHandler(CurrentClass);
Delattr(CurrentClass,"feature:new");
@ -1671,7 +1673,7 @@ int Language::classHandler(Node *n) {
}
/* emit director disown method */
if (Getattr(n, "vtable")) {
if (hasDirector) {
classDirectorDisown(n);
}

View file

@ -650,24 +650,38 @@ Swig_ConstructorToFunction(Node *n, String *classname,
if (cplus) {
/* if a C++ director class exists, create it rather than the original class */
if (use_director) {
int abstract = Getattr(n, "abstract") != 0;
Node *parent = Swig_methodclass(n);
String *name = Getattr(parent, "sym:name");
String* directorname = NewStringf("__DIRECTOR__%s", name);
String* action = NewString("");
String* tmp_none_comparison = Copy(none_comparison);
String* director_call;
String* nodirector_call;
Replaceall( tmp_none_comparison, "$arg", "arg1" );
/* if Python class has been subclassed, create a director instance.
* otherwise, just create a normal instance.
*/
/* arty: arg1 != Py_None => tmp_none_comparison */
Printv(action, "if (",tmp_none_comparison,") {/* subclassed */\n",
Swig_cresult(type, "result", Swig_cppconstructor_director_call(directorname, parms)),
"} else {\n",
Swig_cresult(type, "result", Swig_cppconstructor_nodirector_call(classname, parms)),
"}\n",
NULL);
director_call = Swig_cppconstructor_director_call(directorname, parms);
nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms);
if (abstract) {
/* whether or not the abstract class has been subclassed in python,
* create a director instance (there's no way to create a normal
* instance). if any of the pure virtual methods haven't been
* implemented in the target language, calls to those methods will
* generate SWIG_DIRECTOR_PURE_VIRTUAL exceptions.
*/
Printv(action, Swig_cresult(type, "result", director_call), NULL);
} else {
/* if the proxy class has been subclassed, create a director instance.
* otherwise, just create a normal instance.
*/
Printv(action,
"if (",tmp_none_comparison,") {/* subclassed */\n",
Swig_cresult(type, "result", director_call),
"} else {\n",
Swig_cresult(type, "result", nodirector_call),
"}\n", NULL);
}
Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison);
Delete(action);