bool check_cast(const DexType* type, const DexType* base_type) { if (type == base_type) return true; const auto cls = type_class(type); if (cls == nullptr) return false; if (check_cast(cls->get_super_class(), base_type)) return true; auto intfs = cls->get_interfaces(); for (auto intf : intfs->get_type_list()) { if (check_cast(intf, base_type)) return true; } return false; }
int check_operation(ast::abstract::Operation* op) { assert(op != nullptr); switch(*op) { case ast::VariableNode: return check_variable(dynamic_cast<ast::Variable*>(op)); break; case ast::ConstantNode: return check_constant(dynamic_cast<ast::Constant*>(op)); break; case ast::CastNode: return check_cast(dynamic_cast<ast::Cast*>(op)); break; case ast::UnOpNode: return check_un_op(dynamic_cast<ast::UnOp*>(op)); break; case ast::BinOpNode: return check_bin_op(dynamic_cast<ast::BinOp*>(op)); break; case ast::CallNode: return check_call(dynamic_cast<ast::Call*>(op)); break; } assert(false); return EXIT_FAILURE; }
std::vector<const DexMethod*> select_from(const VirtualScope* scope, const DexType* type) { std::vector<const DexMethod*> refined_scope; std::unordered_map<const DexType*, DexMethod*> non_child_methods; bool found_root_method = false; for (const auto& method : scope->methods) { if (check_cast(method.first->get_class(), type)) { found_root_method = found_root_method || type == method.first->get_class(); refined_scope.emplace_back(method.first); } else { non_child_methods[method.first->get_class()] = method.first; } } if (!found_root_method) { auto cls = type_class(type); while (cls != nullptr) { const auto super = cls->get_super_class(); const auto& meth = non_child_methods.find(super); if (meth != non_child_methods.end()) { refined_scope.emplace_back(meth->second); return refined_scope; } cls = type_class(super); } } return refined_scope; }
CAMLexport GdkPixmap *GdkPixmap_val(value val) { if (!Field(val,1)) ml_raise_gdk ("attempt to use destroyed GdkPixmap"); return check_cast(GDK_PIXMAP,val); }
CAMLexport GdkImage *GdkImage_val(value val) { if (!Field(val,1)) ml_raise_gdk ("attempt to use destroyed GdkImage"); return check_cast(GDK_IMAGE,val); }