From a912d8f0f481cadc188e7d821a11e3dbb400b0c4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 28 Jul 2009 12:57:25 +0200 Subject: [PATCH] PHP: fix for the director_using testcase --- CHANGES.current | 5 ++++ Examples/test-suite/director_using.i | 2 + Source/Include/swigwarn.h | 1 + Source/Modules/php.cxx | 44 +++++++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index ece5818..f2b3fc6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,11 @@ Version 1.3.40 (in progress) ============================ +2009-07-28: vmiklos + [PHP] If a member function is not public but it has a base + which is public, then now a warning is issued and the member + function will be public, as PHP requires this. + 2009-07-21: vmiklos [PHP] Director support added. diff --git a/Examples/test-suite/director_using.i b/Examples/test-suite/director_using.i index 104528c..9001ffb 100644 --- a/Examples/test-suite/director_using.i +++ b/Examples/test-suite/director_using.i @@ -1,5 +1,7 @@ %module(directors="1",dirprot="1") director_using +%warnfilter(SWIGWARN_PHP_PUBLIC_BASE) FooBar; + %{ #include #include diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 5be0305..e8fa159 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -250,6 +250,7 @@ #define WARN_PHP_MULTIPLE_INHERITANCE 870 #define WARN_PHP_UNKNOWN_PRAGMA 871 +#define WARN_PHP_PUBLIC_BASE 872 /* please leave 870-889 free for PHP */ diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 8d65df8..2c6168b 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1520,7 +1520,48 @@ public: Printf(output, "\n"); // If it's a member function or a class constructor... if (wrapperType == memberfn || (constructor && current_class)) { - String *acc = Getattr(n, "access"); + String *acc = NewString(Getattr(n, "access")); + // If a base has the same method with public access, then PHP + // requires to have it here as public as well + Node *bases = Getattr(Swig_methodclass(n), "bases"); + if (bases && Strcmp(acc, "public") != 0) { + String *warnmsg = 0; + int haspublicbase = 0; + Iterator i = First(bases); + while (i.item) { + Node *j = firstChild(i.item); + while (j) { + if (Strcmp(Getattr(j, "name"), Getattr(n, "name")) != 0) { + j = nextSibling(j); + continue; + } + if (Strcmp(nodeType(j), "cdecl") == 0) { + if (!Getattr(j, "access") || checkAttribute(j, "access", "public")) { + haspublicbase = 1; + } + } else if (Strcmp(nodeType(j), "using") == 0 && firstChild(j) && Strcmp(nodeType(firstChild(j)), "cdecl") == 0) { + if (!Getattr(firstChild(j), "access") || checkAttribute(firstChild(j), "access", "public")) { + haspublicbase = 1; + } + } + if (haspublicbase) { + warnmsg = NewStringf("Modifying the access of '%s::%s' to public, as the base '%s' has it as public as well.\n", Getattr(current_class, "classtype"), Getattr(n, "name"), Getattr(i.item, "classtype")); + break; + } + j = nextSibling(j); + } + i = Next(i); + if (haspublicbase) { + break; + } + } + if (Getattr(n, "access") && haspublicbase) { + Delete(acc); + acc = NewString("public"); + Swig_warning(WARN_PHP_PUBLIC_BASE, input_file, line_number, Char(warnmsg)); + Delete(warnmsg); + } + } if (constructor) { const char * arg0; if (max_num_of_arguments > 0) { @@ -1540,6 +1581,7 @@ public: } else { Printf(output, "\t%s function %s(%s) {\n", acc, methodname, args); } + Delete(acc); } else { Printf(output, "\tstatic function %s(%s) {\n", methodname, args); } -- 1.6.3.3