1 | ###########################################################################
|
---|
2 | # A module to unmangle symbols
|
---|
3 | #
|
---|
4 | # Copyright (C) 2016 Andrey Ponomarenko's ABI Laboratory
|
---|
5 | #
|
---|
6 | # Written by Andrey Ponomarenko
|
---|
7 | #
|
---|
8 | # This program is free software: you can redistribute it and/or modify
|
---|
9 | # it under the terms of the GNU General Public License or the GNU Lesser
|
---|
10 | # General Public License as published by the Free Software Foundation.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # and the GNU Lesser General Public License along with this program.
|
---|
19 | # If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | ###########################################################################
|
---|
21 | use strict;
|
---|
22 |
|
---|
23 | sub unmangle($)
|
---|
24 | {
|
---|
25 | my $Name = $_[0];
|
---|
26 |
|
---|
27 | $Name=~s!/!.!g;
|
---|
28 | $Name=~s!:\(!(!g;
|
---|
29 | $Name=~s!\).+\Z!)!g;
|
---|
30 |
|
---|
31 | if($Name=~/\A(.+)\((.+)\)/)
|
---|
32 | {
|
---|
33 | my ($ShortName, $MangledParams) = ($1, $2);
|
---|
34 | my @UnmangledParams = ();
|
---|
35 | my ($IsArray, $Shift, $Pos, $CurParam) = (0, 0, 0, "");
|
---|
36 | while($Pos<length($MangledParams))
|
---|
37 | {
|
---|
38 | my $Symbol = substr($MangledParams, $Pos, 1);
|
---|
39 | if($Symbol eq "[")
|
---|
40 | { # array
|
---|
41 | $IsArray = 1;
|
---|
42 | $Pos+=1;
|
---|
43 | }
|
---|
44 | elsif($Symbol eq "L")
|
---|
45 | { # class
|
---|
46 | if(substr($MangledParams, $Pos+1)=~/\A(.+?);/) {
|
---|
47 | $CurParam = $1;
|
---|
48 | $Shift = length($CurParam)+2;
|
---|
49 | }
|
---|
50 | if($IsArray) {
|
---|
51 | $CurParam .= "[]";
|
---|
52 | }
|
---|
53 | $Pos+=$Shift;
|
---|
54 | push(@UnmangledParams, $CurParam);
|
---|
55 | ($IsArray, $Shift, $CurParam) = (0, 0, "")
|
---|
56 | }
|
---|
57 | else
|
---|
58 | {
|
---|
59 | if($Symbol eq "C") {
|
---|
60 | $CurParam = "char";
|
---|
61 | }
|
---|
62 | elsif($Symbol eq "B") {
|
---|
63 | $CurParam = "byte";
|
---|
64 | }
|
---|
65 | elsif($Symbol eq "S") {
|
---|
66 | $CurParam = "short";
|
---|
67 | }
|
---|
68 | elsif($Symbol eq "S") {
|
---|
69 | $CurParam = "short";
|
---|
70 | }
|
---|
71 | elsif($Symbol eq "I") {
|
---|
72 | $CurParam = "int";
|
---|
73 | }
|
---|
74 | elsif($Symbol eq "F") {
|
---|
75 | $CurParam = "float";
|
---|
76 | }
|
---|
77 | elsif($Symbol eq "J") {
|
---|
78 | $CurParam = "long";
|
---|
79 | }
|
---|
80 | elsif($Symbol eq "D") {
|
---|
81 | $CurParam = "double";
|
---|
82 | }
|
---|
83 | else {
|
---|
84 | printMsg("INFO", "WARNING: unmangling error");
|
---|
85 | }
|
---|
86 | if($IsArray) {
|
---|
87 | $CurParam .= "[]";
|
---|
88 | }
|
---|
89 | $Pos+=1;
|
---|
90 | push(@UnmangledParams, $CurParam);
|
---|
91 | ($IsArray, $Shift, $CurParam) = (0, 0, "")
|
---|
92 | }
|
---|
93 | }
|
---|
94 | return $ShortName."(".join(", ", @UnmangledParams).")";
|
---|
95 | }
|
---|
96 |
|
---|
97 | return $Name;
|
---|
98 | }
|
---|
99 |
|
---|
100 | return 1;
|
---|