PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/Modules/utils.cxx

#
C++ | 220 lines | 116 code | 34 blank | 70 comment | 34 complexity | 8634e4321230fb0c6cd722668b4ba507 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. * utils.cxx
  10. *
  11. * Various utility functions.
  12. * ----------------------------------------------------------------------------- */
  13. char cvsroot_utils_cxx[] = "$Id: utils.cxx 12654 2011-05-05 06:09:55Z wsfulton $";
  14. #include <swigmod.h>
  15. int is_public(Node *n) {
  16. String *access = Getattr(n, "access");
  17. return !access || !Cmp(access, "public");
  18. }
  19. int is_private(Node *n) {
  20. String *access = Getattr(n, "access");
  21. return access && !Cmp(access, "private");
  22. }
  23. int is_protected(Node *n) {
  24. String *access = Getattr(n, "access");
  25. return access && !Cmp(access, "protected");
  26. }
  27. static int is_member_director_helper(Node *parentnode, Node *member) {
  28. int parent_nodirector = GetFlag(parentnode, "feature:nodirector");
  29. if (parent_nodirector)
  30. return 0;
  31. int parent_director = Swig_director_mode() && GetFlag(parentnode, "feature:director");
  32. int cdecl_director = parent_director || GetFlag(member, "feature:director");
  33. int cdecl_nodirector = GetFlag(member, "feature:nodirector");
  34. return cdecl_director && !cdecl_nodirector && !GetFlag(member, "feature:extend");
  35. }
  36. int is_member_director(Node *parentnode, Node *member) {
  37. if (parentnode && checkAttribute(member, "storage", "virtual")) {
  38. return is_member_director_helper(parentnode, member);
  39. } else {
  40. return 0;
  41. }
  42. }
  43. int is_member_director(Node *member) {
  44. return is_member_director(Getattr(member, "parentNode"), member);
  45. }
  46. // Identifies the additional protected members that are generated when the allprotected option is used.
  47. // This does not include protected virtual methods as they are turned on with the dirprot option.
  48. int is_non_virtual_protected_access(Node *n) {
  49. int result = 0;
  50. if (Swig_director_mode() && Swig_director_protected_mode() && Swig_all_protected_mode() && is_protected(n) && !checkAttribute(n, "storage", "virtual")) {
  51. Node *parentNode = Getattr(n, "parentNode");
  52. // When vtable is empty, the director class does not get emitted, so a check for an empty vtable should be done.
  53. // However, vtable is set in Language and so is not yet set when methods in Typepass call clean_overloaded()
  54. // which calls is_non_virtual_protected_access. So commented out below.
  55. // Moving the director vtable creation into into Typepass should solve this problem.
  56. if (is_member_director_helper(parentNode, n) /* && Getattr(parentNode, "vtable")*/)
  57. result = 1;
  58. }
  59. return result;
  60. }
  61. /* Clean overloaded list. Removes templates, ignored, and errors */
  62. void clean_overloaded(Node *n) {
  63. Node *nn = Getattr(n, "sym:overloaded");
  64. Node *first = 0;
  65. while (nn) {
  66. String *ntype = nodeType(nn);
  67. if ((GetFlag(nn, "feature:ignore")) ||
  68. (Getattr(nn, "error")) ||
  69. (Strcmp(ntype, "template") == 0) ||
  70. ((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn) && !is_non_virtual_protected_access(n))) {
  71. /* Remove from overloaded list */
  72. Node *ps = Getattr(nn, "sym:previousSibling");
  73. Node *ns = Getattr(nn, "sym:nextSibling");
  74. if (ps) {
  75. Setattr(ps, "sym:nextSibling", ns);
  76. }
  77. if (ns) {
  78. Setattr(ns, "sym:previousSibling", ps);
  79. }
  80. Delattr(nn, "sym:previousSibling");
  81. Delattr(nn, "sym:nextSibling");
  82. Delattr(nn, "sym:overloaded");
  83. nn = ns;
  84. continue;
  85. } else {
  86. if (!first)
  87. first = nn;
  88. Setattr(nn, "sym:overloaded", first);
  89. }
  90. nn = Getattr(nn, "sym:nextSibling");
  91. }
  92. if (!first || (first && !Getattr(first, "sym:nextSibling"))) {
  93. if (Getattr(n, "sym:overloaded"))
  94. Delattr(n, "sym:overloaded");
  95. }
  96. }
  97. /* -----------------------------------------------------------------------------
  98. * Swig_set_max_hash_expand()
  99. *
  100. * Controls how many Hash objects are displayed when displaying nested Hash objects.
  101. * Makes DohSetMaxHashExpand an externally callable function (for debugger).
  102. * ----------------------------------------------------------------------------- */
  103. void Swig_set_max_hash_expand(int count) {
  104. SetMaxHashExpand(count);
  105. }
  106. extern "C" {
  107. /* -----------------------------------------------------------------------------
  108. * Swig_get_max_hash_expand()
  109. *
  110. * Returns how many Hash objects are displayed when displaying nested Hash objects.
  111. * Makes DohGetMaxHashExpand an externally callable function (for debugger).
  112. * ----------------------------------------------------------------------------- */
  113. int Swig_get_max_hash_expand() {
  114. return GetMaxHashExpand();
  115. }
  116. /* -----------------------------------------------------------------------------
  117. * Swig_to_doh_string()
  118. *
  119. * DOH version of Swig_to_string()
  120. * ----------------------------------------------------------------------------- */
  121. static String *Swig_to_doh_string(DOH *object, int count) {
  122. int old_count = Swig_get_max_hash_expand();
  123. if (count >= 0)
  124. Swig_set_max_hash_expand(count);
  125. String *debug_string = object ? NewStringf("%s", object) : NewString("NULL");
  126. Swig_set_max_hash_expand(old_count);
  127. return debug_string;
  128. }
  129. /* -----------------------------------------------------------------------------
  130. * Swig_to_doh_string_with_location()
  131. *
  132. * DOH version of Swig_to_string_with_location()
  133. * ----------------------------------------------------------------------------- */
  134. static String *Swig_to_doh_string_with_location(DOH *object, int count) {
  135. int old_count = Swig_get_max_hash_expand();
  136. if (count >= 0)
  137. Swig_set_max_hash_expand(count);
  138. String *debug_string = Swig_stringify_with_location(object);
  139. Swig_set_max_hash_expand(old_count);
  140. return debug_string;
  141. }
  142. /* -----------------------------------------------------------------------------
  143. * Swig_to_string()
  144. *
  145. * Swig debug - return C string representation of any DOH type.
  146. * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0
  147. * Note: leaks memory.
  148. * ----------------------------------------------------------------------------- */
  149. const char *Swig_to_string(DOH *object, int count) {
  150. return Char(Swig_to_doh_string(object, count));
  151. }
  152. /* -----------------------------------------------------------------------------
  153. * Swig_to_string_with_location()
  154. *
  155. * Swig debug - return C string representation of any DOH type, within [] brackets
  156. * for Hash and List types, prefixed by line and file information.
  157. * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0
  158. * Note: leaks memory.
  159. * ----------------------------------------------------------------------------- */
  160. const char *Swig_to_string_with_location(DOH *object, int count) {
  161. return Char(Swig_to_doh_string_with_location(object, count));
  162. }
  163. /* -----------------------------------------------------------------------------
  164. * Swig_print()
  165. *
  166. * Swig debug - display string representation of any DOH type.
  167. * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0
  168. * ----------------------------------------------------------------------------- */
  169. void Swig_print(DOH *object, int count) {
  170. String *output = Swig_to_doh_string(object, count);
  171. Printf(stdout, "%s\n", output);
  172. Delete(output);
  173. }
  174. /* -----------------------------------------------------------------------------
  175. * Swig_to_string_with_location()
  176. *
  177. * Swig debug - display string representation of any DOH type, within [] brackets
  178. * for Hash and List types, prefixed by line and file information.
  179. * Nested Hash types expand count is value of Swig_get_max_hash_expand when count<0
  180. * ----------------------------------------------------------------------------- */
  181. void Swig_print_with_location(DOH *object, int count) {
  182. String *output = Swig_to_doh_string_with_location(object, count);
  183. Printf(stdout, "%s\n", output);
  184. Delete(output);
  185. }
  186. } // extern "C"