PageRenderTime 67ms CodeModel.GetById 46ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Source/CParse/util.c

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