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