File: utils.cxx

package info (click to toggle)
swig1.3 1.3.29-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,096 kB
  • ctags: 12,521
  • sloc: cpp: 34,881; ansic: 27,466; python: 8,393; makefile: 4,838; yacc: 4,816; java: 4,629; sh: 3,594; cs: 3,175; ruby: 2,678; perl: 2,349; lisp: 1,984; tcl: 1,243; php: 1,026; ml: 823
file content (124 lines) | stat: -rw-r--r-- 3,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ----------------------------------------------------------------------------- 
 * See the LICENSE file for information on copyright, usage and redistribution
 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
 *
 * utils.cxx
 *
 * Various utility functions.
 * ----------------------------------------------------------------------------- */

char cvsroot_utils_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/utils.cxx,v 1.10 2006/03/06 22:50:59 wsfulton Exp $";

#include <swigmod.h>

int is_public(Node* n) 
{
  String* access = Getattr(n, "access");
  return !access || !Cmp(access, "public");
}

int is_private(Node* n) 
{
  String* access = Getattr(n, "access");
  return access && !Cmp(access, "private");
}

int is_protected(Node* n) 
{
  String* access = Getattr(n, "access");
  return access && !Cmp(access, "protected");
}

int is_member_director(Node* parentnode, Node* member) 
{
  int director_mode = Swig_director_mode();

  if (checkAttribute(member,"director","1")) return 1;
  if (parentnode && checkAttribute(member, "storage", "virtual")) {
    int parent_nodirector = GetFlag(parentnode,"feature:nodirector");
    if (parent_nodirector) return 0;
    int parent_director = director_mode && GetFlag(parentnode,"feature:director");
    int cdecl_director = parent_director || GetFlag(member,"feature:director");
    int cdecl_nodirector = GetFlag(member,"feature:nodirector");
    return cdecl_director && !cdecl_nodirector;
  } else {
    return 0;
  }
}

int is_member_director(Node* member)
{
  return is_member_director(Getattr(member, "parentNode"), member);
}


/* Clean overloaded list.  Removes templates, ignored, and errors */

void clean_overloaded(Node *n) {
  Node *nn = Getattr(n,"sym:overloaded");
  Node *first = 0;
  int   cnt = 0;
  while (nn) {
    String *ntype = nodeType(nn);
    if ((GetFlag(nn,"feature:ignore")) ||
	(Getattr(nn,"error")) ||
	(Strcmp(ntype,"template") == 0) ||
	((Strcmp(ntype,"cdecl") == 0) && is_protected(nn) && !is_member_director(nn)) ||
	((Strcmp(ntype,"using") == 0) && !firstChild(nn))) {
      /* Remove from overloaded list */
      Node *ps = Getattr(nn,"sym:previousSibling");
      Node *ns = Getattr(nn,"sym:nextSibling");
      if (ps) {
	Setattr(ps,"sym:nextSibling",ns);
      } 
      if (ns) {
	Setattr(ns,"sym:previousSibling",ps);
      }
      Delattr(nn,"sym:previousSibling");
      Delattr(nn,"sym:nextSibling");
      Delattr(nn,"sym:overloaded");
      nn = ns;
      continue;
    } else if ((Strcmp(ntype,"using") == 0)) {
      /* A possibly dangerous parse tree hack.  We're going to
	 cut the parse tree node out and stick in the resolved
	 using declarations */
	
      Node *ps = Getattr(nn,"sym:previousSibling");
      Node *ns = Getattr(nn,"sym:nextSibling");
      Node *un = firstChild(nn);
      Node *pn = un;

      if (!first) {
	first = un;
      }
      while (pn) {
	Node *ppn = Getattr(pn,"sym:nextSibling");
	Setattr(pn,"sym:overloaded",first);
	Setattr(pn,"sym:overname", NewStringf("%s_%d", Getattr(nn,"sym:overname"), cnt++));
	if (ppn) pn = ppn;
	else break;
      }
      if (ps) {
	Setattr(ps,"sym:nextSibling",un);
	Setattr(un,"sym:previousSibling",ps);
      }
      if (ns) {
	Setattr(ns,"sym:previousSibling", pn);
	Setattr(pn,"sym:nextSibling",ns);
      }
      if (!first) {
	first = un;
	Setattr(nn,"sym:overloaded",first);
      }
    } else {
      if (!first) first = nn;
      Setattr(nn,"sym:overloaded",first);
    }
    nn = Getattr(nn,"sym:nextSibling");
  }
  if (!first || (first && !Getattr(first,"sym:nextSibling"))) {
    Delattr(n,"sym:overloaded");
  }
}