Skip to content

Commit 6fa72c8

Browse files
authored
Merge pull request #1000 from smowton/smowton/feature/class_access_flags
Add support for recording and propagating class access flags
2 parents c50f3d5 + 7cf8d5f commit 6fa72c8

5 files changed

+43
-1
lines changed

src/java_bytecode/java_bytecode_convert_class.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void java_bytecode_convert_classt::convert(const classt &c)
8686
return;
8787
}
8888

89-
class_typet class_type;
89+
java_class_typet class_type;
9090

9191
class_type.set_tag(c.name);
9292
class_type.set(ID_base_name, c.name);
@@ -98,6 +98,15 @@ void java_bytecode_convert_classt::convert(const classt &c)
9898
class_type.set(ID_enumeration, true);
9999
}
100100

101+
if(c.is_public)
102+
class_type.set_access(ID_public);
103+
else if(c.is_protected)
104+
class_type.set_access(ID_protected);
105+
else if(c.is_private)
106+
class_type.set_access(ID_private);
107+
else
108+
class_type.set_access(ID_default);
109+
101110
if(!c.extends.empty())
102111
{
103112
symbol_typet base("java::"+id2string(c.extends));

src/java_bytecode/java_bytecode_parse_tree.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void java_bytecode_parse_treet::classt::swap(
2626
std::swap(other.is_enum, is_enum);
2727
std::swap(other.enum_elements, enum_elements);
2828
std::swap(other.is_abstract, is_abstract);
29+
std::swap(other.is_public, is_public);
30+
std::swap(other.is_protected, is_protected);
31+
std::swap(other.is_private, is_private);
2932
other.implements.swap(implements);
3033
other.fields.swap(fields);
3134
other.methods.swap(methods);

src/java_bytecode/java_bytecode_parse_tree.h

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class java_bytecode_parse_treet
169169
irep_idt name, extends;
170170
bool is_abstract=false;
171171
bool is_enum=false;
172+
bool is_public=false, is_protected=false, is_private=false;
172173
size_t enum_elements=0;
173174

174175
typedef std::list<irep_idt> implementst;

src/java_bytecode/java_bytecode_parser.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ void java_bytecode_parsert::rClassFile()
279279

280280
parsed_class.is_abstract=(access_flags&ACC_ABSTRACT)!=0;
281281
parsed_class.is_enum=(access_flags&ACC_ENUM)!=0;
282+
parsed_class.is_public=(access_flags&ACC_PUBLIC)!=0;
283+
parsed_class.is_protected=(access_flags&ACC_PROTECTED)!=0;
284+
parsed_class.is_private=(access_flags&ACC_PRIVATE)!=0;
282285
parsed_class.name=
283286
constant(this_class).type().get(ID_C_base_name);
284287

src/java_bytecode/java_types.h

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/type.h>
1414
#include <util/std_types.h>
1515

16+
class java_class_typet:public class_typet
17+
{
18+
public:
19+
const irep_idt &get_access() const
20+
{
21+
return get(ID_access);
22+
}
23+
24+
void set_access(const irep_idt &access)
25+
{
26+
return set(ID_access, access);
27+
}
28+
};
29+
30+
inline const java_class_typet &to_java_class_type(const typet &type)
31+
{
32+
assert(type.id()==ID_struct);
33+
return static_cast<const java_class_typet &>(type);
34+
}
35+
36+
inline java_class_typet &to_java_class_type(typet &type)
37+
{
38+
assert(type.id()==ID_struct);
39+
return static_cast<java_class_typet &>(type);
40+
}
41+
1642
typet java_int_type();
1743
typet java_long_type();
1844
typet java_short_type();

0 commit comments

Comments
 (0)