~ubuntu-branches/ubuntu/jaunty/aspectc++/jaunty

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/src/Signature.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-07-07 14:41:02 UTC
  • mfrom: (1.1.3 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707144102-lzml7t07f3sl00r5
Tags: 1.0pre4~svn.20080711-1
* new upstream snapshot.
* include all upstream documentation. Clarifying emails regarding
  licensing has been included into debian/copyright.
* reformat description following recomendations of
  http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
  (Closes: #480316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This file is part of PUMA.
2
 
// Copyright (C) 1999-2003  The PUMA developer team.
3
 
//                                                                
4
 
// This program is free software;  you can redistribute it and/or 
5
 
// modify it under the terms of the GNU General Public License as 
6
 
// published by the Free Software Foundation; either version 2 of 
7
 
// the License, or (at your option) any later version.            
8
 
//                                                                
9
 
// This program is distributed in the hope that it will be useful,
10
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
11
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
12
 
// GNU General Public License for more details.                   
13
 
//                                                                
14
 
// You should have received a copy of the GNU General Public      
15
 
// License along with this program; if not, write to the Free     
16
 
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
17
 
// MA  02111-1307  USA                                            
18
 
 
19
 
#include "Puma/Signature.h"
20
 
#include "Puma/StrCol.h"
21
 
#include <string.h>
22
 
#include <iostream>
23
 
using namespace std;
24
 
 
25
 
namespace Puma {
26
 
 
27
 
 
28
 
Signature::Signature (const char *sig) {
29
 
  parse (sig);
30
 
}
31
 
 
32
 
 
33
 
// Translate multi-word identifiers (unsigned int and friends) to
34
 
// non-spaced identifiers by replacing any space with a minus. 
35
 
void Signature::translate_multiword_identifiers (char *s) {
36
 
  const char *multiwords[] = { 
37
 
    "unsigned char", "signed char",
38
 
    "unsigned short", "signed short",
39
 
    "unsigned int", "signed int", 
40
 
    "unsigned long", "signed long",
41
 
    "long long", 
42
 
    "unsigned long long", "signed long long",
43
 
    "long double",
44
 
    "operator "
45
 
  };
46
 
  for (unsigned i = 0; i < sizeof (multiwords) / sizeof (char*); i++) {
47
 
    const char *w = multiwords[i];
48
 
    char *j;
49
 
    while ((j = strstr (s, w)) != 0) {
50
 
      for (int k = 0; w[k]; k++) {
51
 
        if (w[k] == ' ') {
52
 
          j[k] = '-';
53
 
        }
54
 
      }
55
 
    }
56
 
  }
57
 
}
58
 
 
59
 
 
60
 
void Signature::parse (const char *sig) {
61
 
  _argc = 0;
62
 
  _method = false;
63
 
 
64
 
  // remove heading, tailing and multiple spaces 
65
 
  while (*sig == ' ') sig++;
66
 
  char *s = new char[strlen(sig)+1];
67
 
  char *q = s;
68
 
  int   space_count = 0;
69
 
  while (*sig) {
70
 
    if (! strcmp (sig, "const")) {
71
 
      sig += 5;
72
 
      continue;
73
 
    }
74
 
    if (! strcmp (sig, "volatile")) {
75
 
      sig += 8;
76
 
      continue;
77
 
    }
78
 
    if (*sig == ' ') {
79
 
      space_count++;
80
 
    } else {
81
 
      if (space_count) {
82
 
          *q++ = ' ';
83
 
        space_count = 0;
84
 
      }
85
 
      *q++ = *sig;
86
 
    }
87
 
    sig++;
88
 
  }
89
 
  *q = 0;
90
 
    
91
 
  // translate multi-word identifiers into single words
92
 
  translate_multiword_identifiers (s);
93
 
 
94
 
  // get the parameter list
95
 
  if ((q = strchr (s, 0))[-1] == ')') {
96
 
    q--;
97
 
    _method = true;
98
 
        
99
 
    // strip the parameter list from the signature
100
 
    int level = 1;
101
 
    while (level != 0) {
102
 
      switch (*--q) {
103
 
        case ')': level++; break;
104
 
        case '(': level--; break;
105
 
      }
106
 
    }
107
 
    *q++ = 0;
108
 
    strchr (q,0)[-1] = 0;
109
 
 
110
 
    // remove all spaces from the parameter list
111
 
    char *p = new char[strlen (q) + 1];
112
 
    char *r = p;
113
 
    while (*q) {
114
 
      if (*q != ' ') 
115
 
        *r++ = *q;
116
 
      q++;
117
 
    }
118
 
    *r = 0;
119
 
        
120
 
    // parse the arguments
121
 
    r = q = p;
122
 
    level = 0;
123
 
    while (*r) {
124
 
      switch (*r) {
125
 
        case ',':
126
 
          if (level == 0) {
127
 
            *r = 0;
128
 
            _argv[_argc++] = StrCol::dup (q);
129
 
            q = r+1;
130
 
          }
131
 
          break;
132
 
        case '(': level++; break;
133
 
        case ')': level++; break;
134
 
      }
135
 
      r++;
136
 
    }
137
 
    if (r > q) {
138
 
      _argv[_argc++] = StrCol::dup (q);
139
 
    }
140
 
        
141
 
    delete[] p;
142
 
  }
143
 
 
144
 
  q = strrchr (s, ' ');
145
 
  if (q) {
146
 
    *q = 0;
147
 
    q++;
148
 
  } else {
149
 
    q = "";
150
 
  }
151
 
  _name = q;
152
 
  _type = s;
153
 
}
154
 
 
155
 
 
156
 
const char *Signature::name () {
157
 
  return _name;
158
 
}
159
 
 
160
 
 
161
 
const char *Signature::type () {
162
 
  return _type;
163
 
}
164
 
 
165
 
 
166
 
const char *Signature::argv (int i) {
167
 
  return _argv[i];
168
 
}
169
 
 
170
 
 
171
 
unsigned Signature::argc () {
172
 
  return _argc;
173
 
}
174
 
 
175
 
 
176
 
bool Signature::method () {
177
 
  return _method;
178
 
}
179
 
 
180
 
 
181
 
} // namespace Puma