%rename(x) Foo::y();

%inline %{
class Foo {
protected:
    void x();
public:
    void y();
};

%}

will work in plain or plain director mode, but it will complain the
same as before with director protected support.

The reason is that the parser emmits the warning, and at that stage it
is not possible to decide if the protected Foo::x() could or not
conflict with the renamed Foo::y(), since Foo::x() could be virtual,
even when no "virtual" attribute is used.



Core:
 parser.y: Detect the dirprot mode and prevents the generation of
           protected symbols at the parsing stage.
 lang.cxx: Export the director_protected_mode for parser.y and the
           director protected member detection is much cleaner.
 main.cxx: Fix the -dirprot flag, it was working in SWIG_FEATURE but
           not in the command line.(minor thing not relate to the error).
 swigmod.h: added Lang::dirprot_mode() for cleaner detection.
 utils.cxx: is_member_director() centralizes and improve the test.

Test suite:
 protected_rename.i: added %inline, so it can compile now.
 director_protected.i: more cases, checking using %rename.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5530 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2003-12-10 23:10:31 +00:00
commit 7335663344
7 changed files with 89 additions and 28 deletions

View file

@ -49,6 +49,11 @@ extern String *scanner_ccode;
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms);
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms);
extern int Swig_need_protected();
/* NEW Variables */
extern void generate_all(Node *);
@ -68,6 +73,7 @@ static char *last_cpptype = 0;
static int inherit_list = 0;
static Parm *template_parameters = 0;
static int extendmode = 0;
static int dirprot_mode = 0;
/* -----------------------------------------------------------------------------
* Assist Functions
@ -150,6 +156,19 @@ static Node *copy_node(Node *n) {
return nn;
}
/* Detects when we need to record protected member information.*/
static int need_protected(Node* n)
{
if (!(Swig_need_protected() || dirprot_mode)) return 0;
//
// Here detect if 'n' is a function.
//
return (Strcmp(nodeType(n),"cdecl") == 0)
&& (Len(Getattr(n,"decl")) > 0);
}
/* -----------------------------------------------------------------------------
* Variables
* ----------------------------------------------------------------------------- */
@ -315,11 +334,7 @@ static void add_symbols(Node *n) {
if (inclass && (cplus_mode == CPLUS_PRIVATE)) {
while (n) {
Swig_symbol_add(0, n); /* Add to C symbol table */
if (cplus_mode == CPLUS_PRIVATE) {
Setattr(n,"access", "private");
} else {
Setattr(n,"access", "protected");
}
Setattr(n,"access", "private");
if (add_only_one) break;
n = nextSibling(n);
}
@ -328,15 +343,14 @@ static void add_symbols(Node *n) {
while (n) {
String *symname;
if (inclass && (cplus_mode == CPLUS_PROTECTED)) {
if (Strcmp(nodeType(n),"constructor") == 0) {
if (!Getattr(n,"access")) {
Swig_symbol_add(0, n); /* Add to C symbol table */
Setattr(n,"access", "protected");
}
Setattr(n,"access", "protected");
if (!need_protected(n)) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
if (add_only_one) break;
n = nextSibling(n);
continue;
}
Setattr(n,"access", "protected");
}
if (Getattr(n,"sym:name")) {
n = nextSibling(n);
@ -385,7 +399,7 @@ static void add_symbols(Node *n) {
Setattr(n,"sym:name",symname);
} else if ((Strcmp(nodeType(n),"template") == 0) && (Strcmp(Getattr(n,"templatetype"),"cdecl") == 0)) {
Setattr(n,"sym:name",symname);
} else {
} else {
String *e = NewString("");
Printf(e,"Identifier '%s' redeclared (ignored).", symname);
if (Cmp(symname,Getattr(n,"name"))) {
@ -1390,6 +1404,8 @@ module_directive: MODULE options idstring {
$$ = new_node("module");
Setattr($$,"name",$3);
if ($2) Setattr($$,"options",$2);
if ($2 && Getattr($2,"directors") && Getattr($2,"dirprot"))
dirprot_mode = 1;
if (!ModuleName) ModuleName = NewString($3);
if (!module_node) module_node = $$;
}