File: mangle.cc

package info (click to toggle)
aspectc%2B%2B 1.0pre4~svn.20090918-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 117,308 kB
  • ctags: 410,601
  • sloc: cpp: 1,883,007; ansic: 17,279; sh: 2,190; makefile: 1,088
file content (89 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (3)
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
#include "mangle.h"
#include <stdio.h>

const char* demangleandprint(const char *type) {
  const char *end = type;
  if (!type) {
    printf("<no type>");
    return 0;
  }
  if ((*type == 'v') && (!*(type+1))) {
    printf ("void");
    return 0;
  }
  switch (*type) {
  case 'i' : printf("int");
    end = type+1;
    break;
  case 'j' : printf("unsigned int");
    end = type+1;
    break;
  case 'P' : {
    end = demangleandprint(type+1);
    printf("*");
  } break;
  case 'R' : {
    end = demangleandprint(type+1);
    printf("&");
  } break;
  case 'N' : {
    type++;
    end++;
    while (*end != 'E') {
      end = demangleandprint(end);
      if (*end != 'E') printf("::");
    }
  } break;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9': {
    unsigned l = 0;
    while ((*type >= '0') && (*type <= '9')) {
      l = l*10 + *type-'0';
      type++;
      end++;
    }
    for (unsigned i=0; i<l; i++, type++, end++) printf("%c", *type);
    break;
  }
  }
  return end;
}


void printvalue(void *data, const char *type) {
  if (!type) {
    printf("<no type>");
    return;
  }
  if ((*type == 'v') && (!*(type+1))) {
    printf ("void");
    return ;
  }
  if (!data) {
    printf("<no value>");
    return;
  } 
  switch (*type) {
  case 'i' : printf ("%d", *(int *)data); break;
  case 'j' : printf ("%d", *(unsigned int *)data); break;
  case 'P' :
  case 'R' :
  case 'N' : printf ("%x", *(unsigned int *)data); break;
  }
}

void castandprint(void *data, const char *type) {
  printf("(");
  demangleandprint(type);
  printf(")");
  printvalue(data, type);
}