[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it a bug in Hierarchy?



Hi Feng!

What should be wrong with that piece of code? As far as I can see, it
does the right thing.

The catch is that the object _must_ be of the specified class, not any
subclass. If the object can be of a subclass of the given class, then
you will have to look in all subclasses and see if any of these define
their own method of the same signature.

Hope this helps.


Feng QIAN wrote:
> 
> Hi, following is a piece code in Hierarchy.java resolving virtual method
> calls. Can it do the right thing? I think probably it is wrong.
> 
> // Questions about method invocation.
> 
> /** Given an object of actual type C (o = new C()), returns the method which
>     on an o.f() invocation.
> */
> 
> public SootMethod resolveConcreteDispatch(SootClass concreteType,
>                                           SootMethod m)
> {
>         checkState();
> 
>         if (concreteType.isInterface())
>             throw new RuntimeException("class needed!");
> 
>         Iterator it = getSuperclassesOfIncluding(concreteType).iterator();
>         String methodSig = m.getSubSignature();
> 
>         while (it.hasNext())
>         {
>             SootClass c = (SootClass)it.next();
>             if (c.declaresMethod(methodSig))
>                 return c.getMethod(methodSig);
>         }
> 
>         throw new RuntimeException("could not resolve concrete
> dispatch!\nType: "
> 
> }
> 
> ====================
> Feng Qian                                       fqian@sable.mcgill.ca

-- 
Ole Friis Østergaard <olef@daimi.au.dk>
  For unge til at føle ansvaret tynge
  som andet end dårlig samvittighed
  (Steffen Brandt)