Fixed more %rename errors, and moving

the function 'need_protected' outside parser.y,
ie, if more subtle cases appear, they can be
fixed without changing parser.y.

Now parser.y looks much more like the original 1.32.

 Source/CParse/parser.y: moving and fixing 'need_protected'
 Source/CParse/util.c:  moving and fixing 'need_protected'
 Examples/test-suite/director_protected.i: more %rename cases
 Examples/test-suite/director_using.i: fixing bad module name

The errors in question where related to the mix of
%rename + (typedef|static)  + protected + dirprot_mode:


%rename(s) Foo::p;
%rename(q) Foo::r;

%inline {
class Foo {
public:
  virtual ~Foo() {}

  int p(){ return 1;}
  int r(){ return 1;}

protected:

  typedef int q();
  static int s();
};

since q and s look like functions, the parser was adding them
completly to the symbol table, and clashing latter with the
attemped renames.

The error was only visible when dirprot was enabled, with
the old behavior it was ok.

Marcelo


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5533 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2003-12-11 03:59:18 +00:00
commit 83013d7c0e
4 changed files with 38 additions and 23 deletions

View file

@ -49,11 +49,6 @@ 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 *);
@ -156,19 +151,6 @@ 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
* ----------------------------------------------------------------------------- */
@ -321,6 +303,7 @@ static String *name_warning(String *name,SwigType *decl) {
static int add_only_one = 0;
extern void cparse_normalize_void(Node *);
extern int need_protected(Node *n, int dirprot_mode);
static void add_symbols(Node *n) {
String *decl;
@ -344,7 +327,7 @@ static void add_symbols(Node *n) {
String *symname;
if (inclass && (cplus_mode == CPLUS_PROTECTED)) {
Setattr(n,"access", "protected");
if (!need_protected(n)) {
if (!need_protected(n, dirprot_mode)) {
/* Only add to C symbol table and continue */
Swig_symbol_add(0, n);
if (add_only_one) break;
@ -399,7 +382,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"))) {
@ -2045,7 +2028,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
/* Set up inheritance in symbol table */
{
Symtab *csyms;
List *baselist = Getattr($$,"baselist");
List *baselist = Getattr($$,"baselist");
csyms = Swig_symbol_current();
Swig_symbol_setscope(Getattr($$,"symtab"));
if (baselist) {

View file

@ -87,3 +87,25 @@ void cparse_normalize_void(Node *n) {
}
}
}
/* -----------------------------------------------------------------------------
* int need_protected(Node* n, int dirprot_mode)
*
* Detects when we need to fully register the protected member.
*
* ----------------------------------------------------------------------------- */
extern int Swig_need_protected();
int need_protected(Node* n, int dirprot_mode)
{
if (!(Swig_need_protected() || dirprot_mode)) return 0;
/* First, 'n' looks like a function */
if (SwigType_isfunction(Getattr(n,"decl"))) {
String *storage = Getattr(n,"storage");
/* and the function is declared like virtual, or it has no
storage. This eliminates typedef, static and so on. */
return (!storage || (Strcmp(storage,"virtual") == 0));
}
return 0;
}