-
Notifications
You must be signed in to change notification settings - Fork 10
/
Qualifiers.cpp
157 lines (155 loc) · 5.29 KB
/
Qualifiers.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Software License Agreement
*
* Copyright(C) 1994-2023 David Lindauer, (LADSoft)
*
* This file is part of the Orange C Compiler package.
*
* The Orange C Compiler package is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Orange C Compiler package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Orange C. If not, see <http://www.gnu.org/licenses/>.
*
* contact information:
* email: [email protected] <David Lindauer>
*
*/
#include "DotNetPELib.h"
namespace DotNetPELib
{
const char* Qualifiers::qualifierNames_[] = {"public",
"private",
"static",
"instance",
"explicit",
"ansi",
"sealed",
"enum",
"value",
"sequential",
"auto",
"literal",
"hidebysig",
"preservesig",
"specialname",
"rtspecialname",
"cil",
"managed",
"runtime",
"",
"virtual",
"newslot",
"beforefieldinit",
"",
"",
"",
"",
"",
"",
"",
"",
""};
int Qualifiers::afterFlags_ = Qualifiers::PreserveSig | Qualifiers::CIL | Qualifiers::Managed | Qualifiers::Runtime;
void Qualifiers::ILSrcDumpBeforeFlags(PELib& peLib) const
{
int n = ~afterFlags_ & flags_;
for (int i = 0; i < 32; i++)
if (n & (1 << i))
peLib.Out() << " " << qualifierNames_[i];
}
void Qualifiers::ILSrcDumpAfterFlags(PELib& peLib) const
{
int n = afterFlags_ & flags_;
for (int i = 0; i < 32; i++)
if (n & (1 << i))
peLib.Out() << " " << qualifierNames_[i];
}
void Qualifiers::ObjOut(PELib& peLib, int pass) const { peLib.Out() << flags_; }
void Qualifiers::ObjIn(PELib& peLib, bool definition) { flags_ = peLib.ObjInt(); }
void Qualifiers::ReverseNamePrefix(std::string& rv, const DataContainer* parent, int& pos, bool type)
{
if (parent)
{
ReverseNamePrefix(rv, parent->Parent(), pos, type);
if (pos != 0)
{
rv += parent->Name();
if (typeid(*parent) == typeid(Class) && (!parent->Parent() || typeid(*(parent->Parent())) != typeid(Class)))
rv += type ? "\xf8" : "/";
else
rv += '.';
}
else if (typeid(*parent) == typeid(AssemblyDef))
{
if (parent->InAssemblyRef())
{
rv += std::string("[") + parent->Name() + "]";
}
}
pos++;
}
}
std::string Qualifiers::GetNamePrefix(const DataContainer* parent, bool type)
{
std::string rv;
if (parent)
{
int pos = 0;
ReverseNamePrefix(rv, parent, pos, type);
}
return rv;
}
std::string Qualifiers::GetName(const std::string& root, const DataContainer* parent, bool type)
{
std::string rv = GetNamePrefix(parent, type);
if (rv.size())
{
rv = rv.substr(0, rv.size() - 1);
}
if (root.size())
{
if (rv.size())
rv += "::";
rv += "'" + root + "'";
}
return rv;
}
std::string Qualifiers::GetObjName(const std::string& stem, const DataContainer* parent)
{
int pos = 0;
std::string rv;
ReverseNamePrefix(rv, parent, pos, false);
int npos = rv.find('/');
if (npos != std::string::npos)
rv[npos] = '.';
if (rv.size())
{
if (rv[rv.size() - 1] == '.')
{
if (rv.size() == 1)
rv = "";
else
rv = rv.substr(0, rv.size() - 1);
}
}
if (stem.size())
{
if (rv.size())
{
rv = rv + "::" + stem;
}
else
{
rv = stem;
}
}
return rv;
}
} // namespace DotNetPELib