PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Source/Swig/deprecate.c

#
C | 109 lines | 30 code | 11 blank | 68 comment | 7 complexity | 1c85e522fa738a771cd79adf94845d25 MD5 | raw file
  1/* -----------------------------------------------------------------------------
  2 * This file is part of SWIG, which is licensed as a whole under version 3 
  3 * (or any later version) of the GNU General Public License. Some additional
  4 * terms also apply to certain portions of SWIG. The full details of the SWIG
  5 * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6 * included with the SWIG source code as distributed by the SWIG developers
  7 * and at http://www.swig.org/legal.html.
  8 *
  9 * deprecate.c
 10 *
 11 * The functions in this file are SWIG core functions that are deprecated 
 12 * or which do not fit in nicely with everything else.  Generally this means
 13 * that the function and/or API needs to be changed in some future release.
 14 * ----------------------------------------------------------------------------- */
 15
 16char cvsroot_deprecate_c[] = "$Id: parms.c 9630 2007-01-02 21:17:19Z beazley $";
 17
 18#include "swig.h"
 19
 20/* ---------------------------------------------------------------------
 21 * ParmList_is_compactdefargs()
 22 *
 23 * Returns 1 if the parameter list passed in is marked for compact argument
 24 * handling (by the "compactdefargs" attribute). Otherwise returns 0.
 25 * ---------------------------------------------------------------------- */
 26
 27/* Discussion:
 28
 29  "compactdefargs" is a property set by the Parser to indicate special
 30  handling of default arguments.   This property seems to be something that
 31  is associated with functions and methods rather than low-level ParmList
 32  objects.   Therefore, I don't like the fact that this special purpose
 33  feature is bolted onto the side of ParmList objects.
 34
 35  Proposed solution:
 36
 37     1. "compactdefargs" should be a feature set on function/method nodes
 38        instead of ParmList objects.  For example, if you have a function,
 39        you would check the function node to see if the parameters are
 40        to be handled in this way.
 41
 42
 43  Difficulties:
 44
 45     1. This is used by functions in cwrap.c and emit.cxx, none of which
 46        are passed information about the function/method node.   We might
 47        have to change the API of those functions to make this work correctly.
 48        For example:
 49
 50           int emit_num_required(ParmList *parms)
 51
 52        might become
 53
 54           int emit_num_required(ParmList *parms, int compactargs)
 55
 56*/
 57
 58int ParmList_is_compactdefargs(ParmList *p) {
 59  int compactdefargs = 0;
 60
 61  if (p) {
 62    compactdefargs = Getattr(p, "compactdefargs") ? 1 : 0;
 63
 64    /* The "compactdefargs" attribute should only be set on the first parameter in the list.
 65     * However, sometimes an extra parameter is inserted at the beginning of the parameter list,
 66     * so we check the 2nd parameter too. */
 67    if (!compactdefargs) {
 68      Parm *nextparm = nextSibling(p);
 69      compactdefargs = (nextparm && Getattr(nextparm, "compactdefargs")) ? 1 : 0;
 70    }
 71  }
 72
 73  return compactdefargs;
 74}
 75
 76/* ---------------------------------------------------------------------
 77 * ParmList_errorstr()
 78 *
 79 * Generate a prototype string suitable for use in error/warning messages.
 80 * Similar to ParmList_protostr() but is also aware of hidden parameters.
 81 * ---------------------------------------------------------------------- */
 82
 83/* Discussion.  This function is used to generate error messages, but take 
 84   into account that there might be a hidden parameter.  Although this involves
 85   parameter lists, it really isn't a core feature of swigparm.h or parms.c.
 86   This is because the "hidden" attribute of parameters is added elsewhere (cwrap.c).
 87
 88   For now, this function is placed here because it doesn't really seem to fit in
 89   with the parms.c interface.
 90 
 91*/
 92
 93String *ParmList_errorstr(ParmList *p) {
 94  String *out = NewStringEmpty();
 95  while (p) {
 96    if (Getattr(p,"hidden")) {
 97      p = nextSibling(p);
 98    } else {
 99      String *pstr = SwigType_str(Getattr(p, "type"), 0);
100      Append(out, pstr);
101      p = nextSibling(p);
102      if (p) {
103	Append(out, ",");
104      }
105      Delete(pstr);
106    }
107  }
108  return out;
109}