1
// This file is part of PUMA.
2
// Copyright (C) 1999-2003 The PUMA developer team.
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.
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.
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,
19
#include "Puma/Signature.h"
20
#include "Puma/StrCol.h"
28
Signature::Signature (const char *sig) {
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",
42
"unsigned long long", "signed long long",
46
for (unsigned i = 0; i < sizeof (multiwords) / sizeof (char*); i++) {
47
const char *w = multiwords[i];
49
while ((j = strstr (s, w)) != 0) {
50
for (int k = 0; w[k]; k++) {
60
void Signature::parse (const char *sig) {
64
// remove heading, tailing and multiple spaces
65
while (*sig == ' ') sig++;
66
char *s = new char[strlen(sig)+1];
70
if (! strcmp (sig, "const")) {
74
if (! strcmp (sig, "volatile")) {
91
// translate multi-word identifiers into single words
92
translate_multiword_identifiers (s);
94
// get the parameter list
95
if ((q = strchr (s, 0))[-1] == ')') {
99
// strip the parameter list from the signature
103
case ')': level++; break;
104
case '(': level--; break;
108
strchr (q,0)[-1] = 0;
110
// remove all spaces from the parameter list
111
char *p = new char[strlen (q) + 1];
120
// parse the arguments
128
_argv[_argc++] = StrCol::dup (q);
132
case '(': level++; break;
133
case ')': level++; break;
138
_argv[_argc++] = StrCol::dup (q);
144
q = strrchr (s, ' ');
156
const char *Signature::name () {
161
const char *Signature::type () {
166
const char *Signature::argv (int i) {
171
unsigned Signature::argc () {
176
bool Signature::method () {