PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/Swig/deprecate.c

#
C | 109 lines | 30 code | 11 blank | 68 comment | 7 complexity | 1c85e522fa738a771cd79adf94845d25 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. char cvsroot_deprecate_c[] = "$Id: parms.c 9630 2007-01-02 21:17:19Z beazley $";
  16. #include "swig.h"
  17. /* ---------------------------------------------------------------------
  18. * ParmList_is_compactdefargs()
  19. *
  20. * Returns 1 if the parameter list passed in is marked for compact argument
  21. * handling (by the "compactdefargs" attribute). Otherwise returns 0.
  22. * ---------------------------------------------------------------------- */
  23. /* Discussion:
  24. "compactdefargs" is a property set by the Parser to indicate special
  25. handling of default arguments. This property seems to be something that
  26. is associated with functions and methods rather than low-level ParmList
  27. objects. Therefore, I don't like the fact that this special purpose
  28. feature is bolted onto the side of ParmList objects.
  29. Proposed solution:
  30. 1. "compactdefargs" should be a feature set on function/method nodes
  31. instead of ParmList objects. For example, if you have a function,
  32. you would check the function node to see if the parameters are
  33. to be handled in this way.
  34. Difficulties:
  35. 1. This is used by functions in cwrap.c and emit.cxx, none of which
  36. are passed information about the function/method node. We might
  37. have to change the API of those functions to make this work correctly.
  38. For example:
  39. int emit_num_required(ParmList *parms)
  40. might become
  41. int emit_num_required(ParmList *parms, int compactargs)
  42. */
  43. int ParmList_is_compactdefargs(ParmList *p) {
  44. int compactdefargs = 0;
  45. if (p) {
  46. compactdefargs = Getattr(p, "compactdefargs") ? 1 : 0;
  47. /* The "compactdefargs" attribute should only be set on the first parameter in the list.
  48. * However, sometimes an extra parameter is inserted at the beginning of the parameter list,
  49. * so we check the 2nd parameter too. */
  50. if (!compactdefargs) {
  51. Parm *nextparm = nextSibling(p);
  52. compactdefargs = (nextparm && Getattr(nextparm, "compactdefargs")) ? 1 : 0;
  53. }
  54. }
  55. return compactdefargs;
  56. }
  57. /* ---------------------------------------------------------------------
  58. * ParmList_errorstr()
  59. *
  60. * Generate a prototype string suitable for use in error/warning messages.
  61. * Similar to ParmList_protostr() but is also aware of hidden parameters.
  62. * ---------------------------------------------------------------------- */
  63. /* Discussion. This function is used to generate error messages, but take
  64. into account that there might be a hidden parameter. Although this involves
  65. parameter lists, it really isn't a core feature of swigparm.h or parms.c.
  66. This is because the "hidden" attribute of parameters is added elsewhere (cwrap.c).
  67. For now, this function is placed here because it doesn't really seem to fit in
  68. with the parms.c interface.
  69. */
  70. String *ParmList_errorstr(ParmList *p) {
  71. String *out = NewStringEmpty();
  72. while (p) {
  73. if (Getattr(p,"hidden")) {
  74. p = nextSibling(p);
  75. } else {
  76. String *pstr = SwigType_str(Getattr(p, "type"), 0);
  77. Append(out, pstr);
  78. p = nextSibling(p);
  79. if (p) {
  80. Append(out, ",");
  81. }
  82. Delete(pstr);
  83. }
  84. }
  85. return out;
  86. }