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 * utils.cxx 6 * 7 * Various utility functions. 8 * ----------------------------------------------------------------------------- */ 9 10char cvsroot_utils_cxx[] = "$Id: utils.cxx 10423 2008-05-07 20:59:00Z wsfulton $"; 11 12#include <swigmod.h> 13 14int is_public(Node *n) { 15 String *access = Getattr(n, "access"); 16 return !access || !Cmp(access, "public"); 17} 18 19int is_private(Node *n) { 20 String *access = Getattr(n, "access"); 21 return access && !Cmp(access, "private"); 22} 23 24int is_protected(Node *n) { 25 String *access = Getattr(n, "access"); 26 return access && !Cmp(access, "protected"); 27} 28 29static int is_member_director_helper(Node *parentnode, Node *member) { 30 int parent_nodirector = GetFlag(parentnode, "feature:nodirector"); 31 if (parent_nodirector) 32 return 0; 33 int parent_director = Swig_director_mode() && GetFlag(parentnode, "feature:director"); 34 int cdecl_director = parent_director || GetFlag(member, "feature:director"); 35 int cdecl_nodirector = GetFlag(member, "feature:nodirector"); 36 return cdecl_director && !cdecl_nodirector && !GetFlag(member, "feature:extend"); 37} 38 39int is_member_director(Node *parentnode, Node *member) { 40 if (parentnode && checkAttribute(member, "storage", "virtual")) { 41 return is_member_director_helper(parentnode, member); 42 } else { 43 return 0; 44 } 45} 46 47int is_member_director(Node *member) { 48 return is_member_director(Getattr(member, "parentNode"), member); 49} 50 51// Identifies the additional protected members that are generated when the allprotected option is used. 52// This does not include protected virtual methods as they are turned on with the dirprot option. 53int is_non_virtual_protected_access(Node *n) { 54 int result = 0; 55 if (Swig_director_mode() && Swig_director_protected_mode() && Swig_all_protected_mode() && is_protected(n) && !checkAttribute(n, "storage", "virtual")) { 56 if (is_member_director_helper(Getattr(n, "parentNode"), n)) 57 result = 1; 58 } 59 return result; 60} 61 62/* Clean overloaded list. Removes templates, ignored, and errors */ 63 64void clean_overloaded(Node *n) { 65 Node *nn = Getattr(n, "sym:overloaded"); 66 Node *first = 0; 67 while (nn) { 68 String *ntype = nodeType(nn); 69 if ((GetFlag(nn, "feature:ignore")) || 70 (Getattr(nn, "error")) || 71 (Strcmp(ntype, "template") == 0) || 72 ((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn) && !is_non_virtual_protected_access(n))) { 73 /* Remove from overloaded list */ 74 Node *ps = Getattr(nn, "sym:previousSibling"); 75 Node *ns = Getattr(nn, "sym:nextSibling"); 76 if (ps) { 77 Setattr(ps, "sym:nextSibling", ns); 78 } 79 if (ns) { 80 Setattr(ns, "sym:previousSibling", ps); 81 } 82 Delattr(nn, "sym:previousSibling"); 83 Delattr(nn, "sym:nextSibling"); 84 Delattr(nn, "sym:overloaded"); 85 nn = ns; 86 continue; 87 } else { 88 if (!first) 89 first = nn; 90 Setattr(nn, "sym:overloaded", first); 91 } 92 nn = Getattr(nn, "sym:nextSibling"); 93 } 94 if (!first || (first && !Getattr(first, "sym:nextSibling"))) { 95 if (Getattr(n, "sym:overloaded")) 96 Delattr(n, "sym:overloaded"); 97 } 98} 99