swig/SWIG/Source/CParse/util.c
Marcelo Matus 83013d7c0e 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
2003-12-11 03:59:18 +00:00

111 lines
3 KiB
C

/* -----------------------------------------------------------------------------
* util.c
*
* Parsing utilities
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
*
* Copyright (C) 1999-2000. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
char cvsroot_util_c[] = "$Header$";
#include "swig.h"
extern SwigType *Swig_cparse_type(String *);
/* -----------------------------------------------------------------------------
* Swig_cparse_replace_descriptor()
*
* Replaces type descriptor string $descriptor() with the SWIG type descriptor
* string.
* ----------------------------------------------------------------------------- */
void Swig_cparse_replace_descriptor(String *s) {
char tmp[512];
String *arg = 0;
SwigType *t;
while (Strstr(s,"$descriptor(")) {
char *d = tmp;
int level = 0;
char *c = Strstr(s,"$descriptor(");
while (*c) {
if (*c == '(') level++;
if (*c == ')') {
level--;
if (level == 0) {
break;
}
}
*d = *c;
d++;
c++;
}
*d = 0;
arg = NewString(tmp+12);
t = Swig_cparse_type(arg);
Delete(arg);
arg = 0;
if (t) {
String *mangle;
String *descriptor;
mangle = SwigType_manglestr(t);
descriptor = NewStringf("SWIGTYPE%s",mangle);
SwigType_remember(t);
*d = ')';
d++;
*d = 0;
Replace(s,tmp,descriptor,DOH_REPLACE_ANY);
Delete(mangle);
Delete(descriptor);
} else {
Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n");
break;
}
}
}
/* -----------------------------------------------------------------------------
* cparse_normalize_void()
*
* This function is used to replace arguments of the form (void) with empty
* arguments in C++
* ----------------------------------------------------------------------------- */
void cparse_normalize_void(Node *n) {
String *decl = Getattr(n,"decl");
Parm *parms = Getattr(n,"parms");
if (SwigType_isfunction(decl)) {
if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms,"type")) == T_VOID)) {
Replaceall(decl,"f(void).","f().");
Delattr(n,"parms");
}
}
}
/* -----------------------------------------------------------------------------
* 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;
}