Skip to content

Commit 9b15b0b

Browse files
Add to_annotated_type and enable type_checked_cast for annotated_typet
1 parent dd99cb3 commit 9b15b0b

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
@@ -451,7 +451,7 @@ void java_bytecode_convert_classt::convert(
451451
{
452452
convert_annotations(
453453
f.annotations,
454-
static_cast<annotated_typet &>(new_symbol.type).get_annotations());
454+
type_checked_cast<annotated_typet>(new_symbol.type).get_annotations());
455455
}
456456

457457
// 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
@@ -371,7 +371,7 @@ void java_bytecode_convert_method_lazy(
371371
{
372372
convert_annotations(
373373
m.annotations,
374-
static_cast<annotated_typet &>(static_cast<typet &>(member_type))
374+
type_checked_cast<annotated_typet>(static_cast<typet &>(member_type))
375375
.get_annotations());
376376
}
377377

src/java_bytecode/java_qualifiers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ void java_qualifierst::read(const typet &src)
7878
void java_qualifierst::write(typet &src) const
7979
{
8080
c_qualifierst::write(src);
81-
auto &annotated_type = static_cast<annotated_typet &>(src);
82-
annotated_type.get_annotations() = annotations;
81+
type_checked_cast<annotated_typet>(src).get_annotations() = annotations;
8382
}
8483

8584
c_qualifierst &java_qualifierst::operator+=(const c_qualifierst &c_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)