From d2c2d5ac09a414955b89efaaef61f7d01f78bd59 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Sun, 3 Sep 2000 21:24:13 +0000 Subject: [PATCH] Didn't fix the virtual member function problem (at least I don't think so), but I did discover a simple code-generation optimization that greatly reduces the amount of wrapper code generated for interfaces with lots of virtual functions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@816 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/SWIG1.1/cplus.cxx | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Source/SWIG1.1/cplus.cxx b/Source/SWIG1.1/cplus.cxx index 335c7ac0d..906c81ac2 100644 --- a/Source/SWIG1.1/cplus.cxx +++ b/Source/SWIG1.1/cplus.cxx @@ -190,7 +190,17 @@ public: int inherited; // Was this member inherited? CPP_member *next; // Next member (for building linked lists) int id; // type id when created + String *signature; + CPP_member() { + signature = 0; + is_static = 0; + is_virtual = 0; + base = 0; + code = 0; + file = 0; + next = 0; + } virtual void inherit(int) { }; // Inheritance rule (optional) virtual void emit() = 0; // Emit rule }; @@ -220,6 +230,7 @@ public: next = 0; line = line_number; file = input_file; + signature = NewStringf("%s(%s)", n, ParmList_str(l)); id = cpp_id; if (AddMethods) { if (strlen(Char(CCode))) @@ -356,7 +367,6 @@ public: void inherit(int mode) { // Set up the proper addmethods mode and provide C code (if provided) int oldaddmethods = AddMethods; - int oldnewobject = NewObject; AddMethods = new_method; Clear(CCode); Append(CCode,code); @@ -1142,7 +1152,21 @@ void cplus_member_func(char *name, char *iname, SwigType *type, ParmList *l, if (Inherit_mode) { CPP_member *m = current_class->search_member(temp_iname); - if (m) return; + if (m) { + /* The current member is already part of the class. However, we might be + able to make some "optimizations" if it's virtual */ + + if ((is_virtual) && (m->is_virtual)) { + if (m->signature) { + /* Printf(stdout,"Member : %s, %d, '%s'\n", m->name, m->is_virtual, m->signature); */ + String *ns = NewStringf("%s(%s)", name, ParmList_str(l)); + if (Cmp(ns,m->signature) == 0) { + m->base = Swig_copy_string(inherit_base_class); + } + } + } + return; + } } // Add it to our C++ class list