PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/CParse/util.c

#
C | 92 lines | 58 code | 10 blank | 24 comment | 15 complexity | b9fd98554a2dc5dd425268f8bcc6abfc 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. * util.c
  10. *
  11. * Parsing utilities.
  12. * ----------------------------------------------------------------------------- */
  13. char cvsroot_util_c[] = "$Id: util.c 11876 2010-02-27 23:53:33Z wsfulton $";
  14. #include "swig.h"
  15. #include "cparse.h"
  16. /* -----------------------------------------------------------------------------
  17. * Swig_cparse_replace_descriptor()
  18. *
  19. * Replaces type descriptor string $descriptor() with the SWIG type descriptor
  20. * string.
  21. * ----------------------------------------------------------------------------- */
  22. void Swig_cparse_replace_descriptor(String *s) {
  23. char tmp[512];
  24. String *arg = 0;
  25. SwigType *t;
  26. char *c = 0;
  27. while ((c = strstr(Char(s), "$descriptor("))) {
  28. char *d = tmp;
  29. int level = 0;
  30. while (*c) {
  31. if (*c == '(')
  32. level++;
  33. if (*c == ')') {
  34. level--;
  35. if (level == 0) {
  36. break;
  37. }
  38. }
  39. *d = *c;
  40. d++;
  41. c++;
  42. }
  43. *d = 0;
  44. arg = NewString(tmp + 12);
  45. t = Swig_cparse_type(arg);
  46. Delete(arg);
  47. arg = 0;
  48. if (t) {
  49. String *mangle;
  50. String *descriptor;
  51. mangle = SwigType_manglestr(t);
  52. descriptor = NewStringf("SWIGTYPE%s", mangle);
  53. SwigType_remember(t);
  54. *d = ')';
  55. d++;
  56. *d = 0;
  57. Replace(s, tmp, descriptor, DOH_REPLACE_ANY);
  58. Delete(mangle);
  59. Delete(descriptor);
  60. Delete(t);
  61. } else {
  62. Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n");
  63. break;
  64. }
  65. }
  66. }
  67. /* -----------------------------------------------------------------------------
  68. * cparse_normalize_void()
  69. *
  70. * This function is used to replace arguments of the form (void) with empty
  71. * arguments in C++
  72. * ----------------------------------------------------------------------------- */
  73. void cparse_normalize_void(Node *n) {
  74. String *decl = Getattr(n, "decl");
  75. Parm *parms = Getattr(n, "parms");
  76. if (SwigType_isfunction(decl)) {
  77. if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms, "type")) == T_VOID)) {
  78. Replaceall(decl, "f(void).", "f().");
  79. Delattr(n, "parms");
  80. }
  81. }
  82. }