Skip to content

Commit bbc079a

Browse files
Add to_annotated_type and enable type_checked_cast for annotated_typet
1 parent 553a9d9 commit bbc079a

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void java_bytecode_convert_classt::convert(
455455
{
456456
convert_annotations(
457457
f.annotations,
458-
static_cast<annotated_typet &>(new_symbol.type).get_annotations());
458+
type_checked_cast<annotated_typet>(new_symbol.type).get_annotations());
459459
}
460460

461461
// Do we have the static field symbol already?

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void java_bytecode_convert_method_lazy(
374374
{
375375
convert_annotations(
376376
m.annotations,
377-
static_cast<annotated_typet &>(static_cast<typet &>(member_type))
377+
type_checked_cast<annotated_typet>(static_cast<typet &>(member_type))
378378
.get_annotations());
379379
}
380380

src/java_bytecode/java_qualifiers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ void java_qualifierst::read(const typet &src)
4747
void java_qualifierst::write(typet &src) const
4848
{
4949
c_qualifierst::write(src);
50-
auto &annotated_type = static_cast<annotated_typet &>(src);
51-
annotated_type.get_annotations() = annotations;
50+
type_checked_cast<annotated_typet>(src).get_annotations() = annotations;
5251
}
5352

5453
qualifierst &java_qualifierst::operator+=(const qualifierst &other)

src/java_bytecode/java_types.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ class annotated_typet : public typet
8181
}
8282
};
8383

84+
inline const annotated_typet &to_annotated_type(const typet &type)
85+
{
86+
return static_cast<const annotated_typet &>(type);
87+
}
88+
89+
inline annotated_typet &to_annotated_type(typet &type)
90+
{
91+
return static_cast<annotated_typet &>(type);
92+
}
93+
94+
template <>
95+
inline bool can_cast_type<annotated_typet>(const typet &type)
96+
{
97+
return true;
98+
}
99+
84100
class java_class_typet:public class_typet
85101
{
86102
public:
@@ -102,7 +118,7 @@ class java_class_typet:public class_typet
102118

103119
std::vector<java_annotationt> &get_annotations()
104120
{
105-
return static_cast<annotated_typet &>(
121+
return type_checked_cast<annotated_typet>(
106122
static_cast<typet &>(*this)).get_annotations();
107123
}
108124
};

0 commit comments

Comments
 (0)