~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Source/Modules/typepass.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-09-01 18:35:55 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050901183555-eq59uwhq8b62e44c
Tags: 1.3.24-1ubuntu4
* Use php5-dev instead of php4-dev, to kick php4 out of main.
* Drop support for generation of pike bindings, as nothing uses it,
  and swig is the only thing keeping pike7.6 in main (Ubuntu #13796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * See the file LICENSE for information on usage and redistribution.    
22
22
 * ----------------------------------------------------------------------------- */
23
23
 
24
 
char cvsroot_typepass_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/typepass.cxx,v 1.14 2004/08/23 20:09:00 wsfulton Exp $";
 
24
char cvsroot_typepass_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/typepass.cxx,v 1.21 2004/12/14 21:25:12 wsfulton Exp $";
25
25
 
26
26
#include "swigmod.h"
27
27
 
127
127
    }
128
128
    Swig_symbol_setscope(currentsym);
129
129
  }
130
 
  
 
130
 
131
131
  /* generate C++ inheritance type-relationships */
132
 
  void cplus_inherit_types(Node *first, Node *cls, String *clsname, String *cast = 0) {
 
132
  void cplus_inherit_types_impl(Node *first, Node *cls, String*clsname,
 
133
                                const char *bases, const char *baselist,
 
134
                                int ispublic, String *cast = 0) {
133
135
      
134
136
    if (first == cls) return;  /* The Marcelo check */
135
137
    if (!cls) cls = first;
136
138
 
137
 
    List *ilist = Getattr(cls,"bases");
 
139
    List *ilist = Getattr(cls,bases);
138
140
    if (!ilist) {
139
 
      List *nlist = Getattr(cls,"baselist");
 
141
      List *nlist = Getattr(cls,baselist);
140
142
      if (nlist) {
141
143
        int     len = Len(nlist);
142
144
        int i;
176
178
                  } 
177
179
                }
178
180
                if (Strcmp(nodeType(bcls),"classforward") != 0) {
179
 
                  Swig_error(Getfile(bname),Getline(bname),"'%s' is not a class. \n",bname);
 
181
                  Swig_error(Getfile(cls),Getline(cls),"'%s' does not have a valid base class.\n", Getattr(cls,"name"));
 
182
                  Swig_error(Getfile(bcls),Getline(bcls),"'%s' is not a valid base class.\n", bname);
180
183
                } else {
181
 
                  Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(bname),Getline(bname),"Base class '%s' is incomplete.\n", bname);
 
184
                  Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(cls),Getline(cls),"Base class '%s' is incomplete.\n", bname);
 
185
                  Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(bcls),Getline(bcls),"Only forward declaration '%s' was found.\n", bname);
182
186
                  clsforward = 1;
183
187
                }
184
188
                bcls = 0;
187
191
                  if (!ilist) ilist = NewList();
188
192
                  Append(ilist,bcls);
189
193
                } else {
190
 
                  Swig_error(Getfile(bcls),Getline(bcls),"class '%s' must be defined before it is used as a base class.\n", bname);
 
194
                  Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(cls),Getline(cls),"Base class '%s' undefined.\n", bname);
 
195
                  Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(bcls),Getline(bcls),"'%s' must be defined before it is used as a base class.\n", bname);
191
196
                }
192
197
              }
193
198
            }
197
202
          if (tname) Delete(tname);
198
203
          if (!bcls) {
199
204
            if (!clsforward) {
200
 
              if (!Getmeta(bname,"already_warned")) {
201
 
                Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname),Getline(bname),"Nothing known about class '%s'. Ignored.\n", SwigType_namestr(bname));
 
205
              if (ispublic && !Getmeta(bname,"already_warned")) {
 
206
                Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls),Getline(cls),"Nothing known about base class '%s'. Ignored.\n", SwigType_namestr(bname));
202
207
                if (Strchr(bname,'<')) {
203
 
                  Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bname), Getline(bname), "Maybe you forgot to instantiate '%s' using %%template.\n", SwigType_namestr(bname));
 
208
                  Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Maybe you forgot to instantiate '%s' using %%template.\n", SwigType_namestr(bname));
204
209
                }
205
210
                Setmeta(bname,"already_warned","1");
206
211
              }
210
215
        }
211
216
      }
212
217
      if (ilist) {
213
 
        Setattr(cls,"bases",ilist);
 
218
        Setattr(cls,bases,ilist);
214
219
      }
215
220
    }
216
221
    if (!ilist) return;
240
245
 
241
246
      /* Recursively hit base classes */
242
247
      String *newcast = NewStringf("(%s *)%s", SwigType_namestr(Getattr(bclass,"name")), cast);
243
 
      cplus_inherit_types(first,bclass,clsname, newcast);
 
248
      cplus_inherit_types_impl(first,bclass,clsname,bases,baselist,ispublic,newcast);
244
249
      Delete(newcast);
245
250
    }
246
251
  }
247
252
 
248
 
  /* Clean overloaded list.  Removes templates, friends, ignored, and errors */
249
 
 
250
 
  void clean_overloaded(Node *n) {
251
 
    Node *nn = Getattr(n,"sym:overloaded");
252
 
    Node *first = 0;
253
 
    int   cnt = 0;
254
 
    while (nn) {
255
 
      if ((Strcmp(nodeType(nn),"template") == 0) ||
256
 
          (Getattr(nn,"feature:ignore")) ||
257
 
          (Getattr(nn,"error")) ||
258
 
          // (checkAttribute(nn,"storage","friend")) ||
259
 
          ((Strcmp(nodeType(nn),"using") == 0) && !firstChild(nn))) {
260
 
        /* Remove from overloaded list */
261
 
        Node *ps = Getattr(nn,"sym:previousSibling");
262
 
        Node *ns = Getattr(nn,"sym:nextSibling");
263
 
        if (ps) {
264
 
          Setattr(ps,"sym:nextSibling",ns);
265
 
        } 
266
 
        if (ns) {
267
 
          Setattr(ns,"sym:previousSibling",ps);
268
 
        }
269
 
        Delattr(nn,"sym:previousSibling");
270
 
        Delattr(nn,"sym:nextSibling");
271
 
        Delattr(nn,"sym:overloaded");
272
 
        nn = ns;
273
 
        continue;
274
 
      } else if ((Strcmp(nodeType(nn),"using") == 0)) {
275
 
        /* A possibly dangerous parse tree hack.  We're going to
276
 
           cut the parse tree node out and stick in the resolved
277
 
           using declarations */
278
 
        
279
 
        Node *ps = Getattr(nn,"sym:previousSibling");
280
 
        Node *ns = Getattr(nn,"sym:nextSibling");
281
 
        Node *un = firstChild(nn);
282
 
        Node *pn = un;
283
 
 
284
 
        if (!first) {
285
 
          first = un;
286
 
        }
287
 
        while (pn) {
288
 
          Node *ppn = Getattr(pn,"sym:nextSibling");
289
 
          Setattr(pn,"sym:overloaded",first);
290
 
          Setattr(pn,"sym:overname", NewStringf("%s_%d", Getattr(nn,"sym:overname"), cnt++));
291
 
          if (ppn) pn = ppn;
292
 
          else break;
293
 
        }
294
 
        if (ps) {
295
 
          Setattr(ps,"sym:nextSibling",un);
296
 
          Setattr(un,"sym:previousSibling",ps);
297
 
        }
298
 
        if (ns) {
299
 
          Setattr(ns,"sym:previousSibling", pn);
300
 
          Setattr(pn,"sym:nextSibling",ns);
301
 
        }
302
 
        if (!first) {
303
 
          first = un;
304
 
          Setattr(nn,"sym:overloaded",first);
305
 
        }
306
 
      } else {
307
 
        if (!first) first = nn;
308
 
        Setattr(nn,"sym:overloaded",first);
 
253
  void append_list(List *lb, List *la) {
 
254
    if (la && lb) {
 
255
      for (Iterator bi = First(la); bi.item; bi = Next(bi)) {
 
256
        Append(lb,bi.item);
309
257
      }
310
 
      nn = Getattr(nn,"sym:nextSibling");
311
258
    }
312
 
    if (!first || (first && !Getattr(first,"sym:nextSibling"))) {
313
 
      Delattr(n,"sym:overloaded");
 
259
  }
 
260
 
 
261
  void cplus_inherit_types(Node *first, Node *cls, String *clsname, String *cast = 0) {
 
262
    cplus_inherit_types_impl(first, cls, clsname, "bases", "baselist", 1, cast);
 
263
    cplus_inherit_types_impl(first, cls, clsname, "protectedbases","protectedbaselist", 0, cast);
 
264
    cplus_inherit_types_impl(first, cls, clsname, "privatebases"  ,"privatebaselist", 0, cast);
 
265
 
 
266
    if (!cls) cls = first;
 
267
 
 
268
    List *allbases = NewList();
 
269
    append_list(allbases,Getattr(cls,"bases"));
 
270
    append_list(allbases,Getattr(cls,"protectedbases"));
 
271
    append_list(allbases,Getattr(cls,"privatebases"));
 
272
    if (Len(allbases)) {
 
273
      Setattr(cls,"allbases",allbases);
 
274
    } else {
 
275
      Delete(allbases);
314
276
    }
315
277
  }
316
278
 
739
701
    String *name = Getattr(n,"name");
740
702
 
741
703
    if (name) {
742
 
      // Correct the name to contain the fully qualified scopename
 
704
      String *scope = 0;
 
705
 
743
706
      // Add a typedef to the type table so that we can use 'enum Name' as well as just 'Name'
744
707
      if (nsname || inclass) {
745
 
        String *nname = 0;
 
708
 
 
709
        // But first correct the name and tdname to contain the fully qualified scopename
746
710
        if (nsname && inclass) {
747
 
          nname = NewStringf("%s::%s::%s", nsname, Getattr(inclass,"name"), name);
 
711
          scope = NewStringf("%s::%s", nsname, Getattr(inclass,"name"));
748
712
        } else if (nsname) {
749
 
          nname = NewStringf("%s::%s", nsname, name);
 
713
          scope = NewStringf("%s", nsname);
750
714
        } else if (inclass) {
751
 
          nname = NewStringf("%s::%s", Getattr(inclass,"name"), name);
 
715
          scope = NewStringf("%s", Getattr(inclass,"name"));
752
716
        }
 
717
 
 
718
        String *nname = NewStringf("%s::%s", scope, name);
753
719
        Setattr(n,"name",nname);
 
720
 
 
721
        String *tdname = Getattr(n,"tdname");
 
722
        if (tdname) {
 
723
          tdname = NewStringf("%s::%s", scope, tdname);
 
724
          Setattr(n,"tdname",tdname);
 
725
        }
 
726
 
754
727
        SwigType *t = NewStringf("enum %s", nname);
755
728
        SwigType_typedef(t,name);
756
 
        Delete(nname);
757
729
      } else {
758
730
        SwigType *t = NewStringf("enum %s", name);
759
731
        SwigType_typedef(t,name);
760
732
      }
761
 
    }
 
733
      Delete(scope);
 
734
    }
 
735
 
 
736
    String *tdname = Getattr(n,"tdname");
 
737
    String *unnamed = Getattr(n,"unnamed");
 
738
    String *storage = Getattr(n,"storage");
 
739
 
 
740
    // Construct enumtype - for declaring an enum of this type with SwigType_ltype() etc
 
741
    String *enumtype = 0;
 
742
    if (unnamed && tdname && (Cmp(storage,"typedef") == 0)) {
 
743
      enumtype = Copy(Getattr(n,"tdname"));
 
744
    } else if (name) {
 
745
      enumtype = NewStringf("%s%s", CPlusPlus ? "" : "enum ", Getattr(n,"name"));
 
746
    } else {
 
747
      // anonymous enums
 
748
      enumtype = Copy(Getattr(n,"type"));
 
749
    }
 
750
    Setattr(n,"enumtype",enumtype);
762
751
 
763
752
    emit_children(n);
764
753
    return SWIG_OK;