PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Source/Modules/utils.cxx

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