PHP: fix for the director_using testcase

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11459 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Miklos Vajna 2009-07-28 11:47:36 +00:00
commit 0fa227ea83
4 changed files with 51 additions and 1 deletions

View file

@ -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.

View file

@ -1,5 +1,7 @@
%module(directors="1",dirprot="1") director_using
%warnfilter(SWIGWARN_PHP_PUBLIC_BASE) FooBar;
%{
#include <string>
#include <iostream>

View file

@ -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 */

View file

@ -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);
}