Skip to content

Commit 06f31c5

Browse files
Add to_annotated_type and enable type_checked_cast for annotated_typet
1 parent a58741c commit 06f31c5

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/java_bytecode/java_bytecode_convert_class.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void java_bytecode_convert_classt::convert(
467467
{
468468
convert_annotations(
469469
f.annotations,
470-
static_cast<annotated_typet &>(new_symbol.type).get_annotations());
470+
type_checked_cast<annotated_typet>(new_symbol.type).get_annotations());
471471
}
472472

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

src/java_bytecode/java_bytecode_convert_method.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ void java_bytecode_convert_method_lazy(
392392
{
393393
convert_annotations(
394394
m.annotations,
395-
static_cast<annotated_typet &>(static_cast<typet &>(member_type))
395+
type_checked_cast<annotated_typet>(static_cast<typet &>(member_type))
396396
.get_annotations());
397397
}
398398

src/java_bytecode/java_qualifiers.cpp

+1-2
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

+17-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ class annotated_typet : public typet
8282
}
8383
};
8484

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

130146
std::vector<java_annotationt> &get_annotations()
131147
{
132-
return static_cast<annotated_typet &>(
148+
return type_checked_cast<annotated_typet>(
133149
static_cast<typet &>(*this)).get_annotations();
134150
}
135151
};

0 commit comments

Comments
 (0)