aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Matus <mmatus@acms.arizona.edu>2003-12-11 03:59:18 +0000
committerMarcelo Matus <mmatus@acms.arizona.edu>2003-12-11 03:59:18 +0000
commit9c372c5c646dc0ee7c20e15fb64a189297bff83e (patch)
tree43fb449be41a586c41235dafcaa8c745451485a1
parent72984676ca9549ed7ac4d7fac8a2dbc7f67c5bb3 (diff)
downloadswig-9c372c5c646dc0ee7c20e15fb64a189297bff83e.tar.gz
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/SWIG@5533 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Examples/test-suite/director_protected.i11
-rw-r--r--Examples/test-suite/director_using.i3
-rw-r--r--Source/CParse/parser.y25
-rw-r--r--Source/CParse/util.c22
4 files changed, 38 insertions, 23 deletions
diff --git a/Examples/test-suite/director_protected.i b/Examples/test-suite/director_protected.i
index 69ce58e87..4b3495865 100644
--- a/Examples/test-suite/director_protected.i
+++ b/Examples/test-suite/director_protected.i
@@ -13,6 +13,8 @@
%newobject *::create();
%rename(a) Bar::hello;
+%rename(s) Foo::p;
+%rename(q) Foo::r;
%inline {
class Foo {
@@ -21,7 +23,16 @@ public:
virtual std::string pong() {
return "Foo::pong();" + ping();
}
+
+ int p(){ return 1;}
+ int r(){ return 1;}
+
+
protected:
+
+ typedef int q();
+ static int s();
+
Foo() {}
virtual std::string ping() = 0;
diff --git a/Examples/test-suite/director_using.i b/Examples/test-suite/director_using.i
index 35472035b..de1c572bf 100644
--- a/Examples/test-suite/director_using.i
+++ b/Examples/test-suite/director_using.i
@@ -1,5 +1,4 @@
-%module(directors="1",dirprot="1") director_nested
- //%module director_nested
+%module(directors="1",dirprot="1") director_using
%{
#include <string>
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index b22bca9bb..97151e8c8 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -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) {
diff --git a/Source/CParse/util.c b/Source/CParse/util.c
index ab9a0a69e..18aa99789 100644
--- a/Source/CParse/util.c
+++ b/Source/CParse/util.c
@@ -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;
+}