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