-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassinfo.h
More file actions
194 lines (159 loc) · 4.75 KB
/
classinfo.h
File metadata and controls
194 lines (159 loc) · 4.75 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef CLASSINFO_H
#define CLASSINFO_H
// ----------------------------------------------------------------------
// Representation of class info
//
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <deque>
using namespace std;
class Class;
class Method;
class Field;
class AllocSite;
typedef map<unsigned int, Method*> MethodMap;
typedef map<unsigned int, Field*> FieldMap;
typedef map<unsigned int, Class*> ClassMap;
typedef map<unsigned int, AllocSite*> AllocSiteMap;
typedef deque<unsigned int> DequeId_t;
// -- Global info, including the big routine to read the names file
typedef std::pair<Method *, Method *> ContextPair;
// (f,g) where f is the caller (or returner)
// and g is the current function
class ClassInfo
{
public:
// -- Contents of the names file
static ClassMap TheClasses;
// -- All methods (also in the classes)
static MethodMap TheMethods;
// -- All fields (also in the classes)
static FieldMap TheFields;
// -- Allocation sites
static AllocSiteMap TheAllocSites;
// -- Debug flag
static bool debug_names;
// -- Flag whether we check for the main function or not
static bool main_flag;
// -- Read the names file
static void read_names_file( const char *filename,
string main_package,
string main_function );
static void read_names_file_no_mainfunc( const char *filename );
static void __read_names_file( const char *filename,
string main_class,
string main_function );
static Method * get_main_method() {
return _main_method;
}
static void set_main_flag() {
ClassInfo::main_flag = true;
}
static void unset_main_flag() {
ClassInfo::main_flag = false;
}
private:
static Method *_main_method;
};
// -- Representation of classes
class Entity
{
protected:
unsigned int m_id;
string m_name;
public:
Entity()
: m_id(0)
, m_name() {
}
Entity(unsigned int id, const string& name)
: m_id(id)
, m_name(name) {
}
unsigned int getId() const { return m_id; }
const string& getName() const { return m_name; }
};
class Field : public Entity
{
private:
bool m_isStatic;
Class* m_class;
string m_descriptor;
public:
Field(unsigned int id, Class* cls, char* name, char* descriptor, bool isstatic)
: Entity(id, name)
, m_isStatic(isstatic)
, m_class(cls)
, m_descriptor(descriptor) {
}
Class* getClass() const { return m_class; }
};
class AllocSite : public Entity
{
private:
Method* m_method;
string m_descriptor;
int m_dimensions;
public:
AllocSite( unsigned int id,
Method* meth,
char* name,
char* descriptor,
unsigned int dimensions )
: Entity(id, name)
, m_method(meth)
, m_descriptor(descriptor)
, m_dimensions(dimensions) {
}
Method* getMethod() const { return m_method; }
const string& getType() const { return m_descriptor; }
string info();
};
class Method : public Entity
{
private:
Class* m_class;
string m_descriptor;
string m_flags;
AllocSiteMap m_allocsites;
public:
Method( unsigned int id,
Class *cls,
char *name,
char *descriptor,
char *flags )
: Entity(id, name)
, m_class(cls)
, m_descriptor(descriptor)
, m_flags(flags) {
}
Class* getClass() const { return m_class; }
void addAllocSite(AllocSite* a) { m_allocsites[a->getId()] = a; }
string info();
string getName();
};
class Class : public Entity
{
private:
unsigned int m_superclassId;
bool m_is_interface;
MethodMap m_methods;
FieldMap m_fields;
public:
Class(unsigned int id, const string& name, bool is_interface)
: Entity(id, name)
, m_superclassId(0)
, m_is_interface(is_interface) {
}
void setSuperclassId(unsigned int sid) { m_superclassId = sid; }
void addMethod(Method* m) { m_methods[m->getId()] = m; }
void addField(Field* f) { m_fields[f->getId()] = f; }
string info() { return m_name; }
};
#endif