Brendon Costa wrote: > Hi all, > > How can I find a FUNCTION_DECL node from a CALL_EXPR node for virtual > function calls? >
Well I have managed to achieve this, though I don't know if it is the best way to do so. For the sake of people that may find this question in the list archives I will show how i did this. >From a CALL_EXPR node, i get TREE_OPERAND(call_expr, 0). If this is a OBJ_TYPE_REF then this is either a virtual function call or a function pointer call to a class member (Maybe something else too but I cant think what). ref = TREE_OPERAND(call_expr, 0); /* Get the INTEGER_CST node that contains the index to virtual function lookup table */ virt_index = TREE_OPERAND(ref, 0); /* Get the type of the class which this method belongs to */ pointer_type = TREE_TYPE(TREE_OPERAND(call_expr, 0)); method_type = TREE_TYPE(pointer_type); class_type = TYPE_METHOD_BASETYPE(method_type); virt_list = BINFO_VIRTUALS(TYPE_BINFO(class_type)); for (virt = virt_list; virt; virt = TREE_CHAIN(virt)) { fndecl = BV_FN(virt); index = DECL_VINDEX(fndecl); !! Now if index and virt_index are the same then fndecl is the FUNCTION_DECL node for the virtual function being called. !! } I hope this might help someone. Also if anyone can see a major problem in this code or a much better way of doing this I would love to hear it. I discovered mostly through trial and error so there is a chance that it could be completely incorrect. Brendon.