@@ -1154,3 +1154,60 @@ void mark_java_implicitly_generic_class_type(
1154
1154
}
1155
1155
}
1156
1156
}
1157
+
1158
+ // / If access1 is stricter than access2, returns true, otherwise returns false.
1159
+ // / Assumed order of strictness:
1160
+ // / private, default (package_private), protected, public
1161
+ bool compare_access (irep_idt access1, irep_idt access2)
1162
+ {
1163
+ if (access1 == access2)
1164
+ return false ;
1165
+ if (access1 == ID_private)
1166
+ return true ;
1167
+ if (access1 == ID_default && access2 != ID_private)
1168
+ return true ;
1169
+ if (access1 == ID_protected && access2 == ID_public)
1170
+ return true ;
1171
+ return false ;
1172
+ }
1173
+
1174
+ // / Inner class accessibility depends not only on the inner class' access
1175
+ // / modifier, but the access modifiers of its containing classes. This checks
1176
+ // / all of the containing classes of an inner class and sets the access of the
1177
+ // / inner class to the strictest of its containing classes. For example, for a
1178
+ // / deeply nested structure Outer.Middle.Inner with access modifiers public,
1179
+ // / private, public, respectively, the access of Inner should be private
1180
+ // / (not public) because one of its containing classes has private access.
1181
+ // / \param inner_class_name
1182
+ // / \param symbol_table
1183
+ void determine_inner_class_accessibility (
1184
+ const irep_idt &inner_class_name,
1185
+ symbol_tablet &symbol_table)
1186
+ {
1187
+ const std::string qualified_inner_class_name =
1188
+ " java::" + id2string (inner_class_name);
1189
+ PRECONDITION (symbol_table.has_symbol (qualified_inner_class_name));
1190
+ symbolt &inner_class_symbol =
1191
+ symbol_table.get_writeable_ref (qualified_inner_class_name);
1192
+ java_class_typet &inner_class_type =
1193
+ to_java_class_type (inner_class_symbol.type );
1194
+
1195
+ if (!inner_class_type.get_is_inner_class ())
1196
+ return ;
1197
+ if (inner_class_type.get_containing_class ().empty ())
1198
+ return ;
1199
+ const std::string qualified_containing_class_name =
1200
+ " java::" + id2string (inner_class_type.get_containing_class ());
1201
+ PRECONDITION (symbol_table.has_symbol (qualified_containing_class_name));
1202
+ symbolt &containing_class_symbol =
1203
+ symbol_table.get_writeable_ref (qualified_containing_class_name);
1204
+ java_class_typet &containing_class_type =
1205
+ to_java_class_type (containing_class_symbol.type );
1206
+
1207
+ if (
1208
+ compare_access (
1209
+ containing_class_type.get_access (), inner_class_type.get_access ()))
1210
+ {
1211
+ inner_class_type.set_access (containing_class_type.get_access ());
1212
+ }
1213
+ }
0 commit comments