+
+ if (!this.isSuperorType(md2.getClassDesc(), md1.getClassDesc()))
+ return false;
+
+ return true;
+ }
+
+ public MethodDescriptor getMethod(ClassDescriptor cd, String name, TypeDescriptor[] types) {
+ Set methoddescriptorset=cd.getMethodTable().getSet(name);
+ MethodDescriptor bestmd=null;
+NextMethod:
+ for(Iterator methodit=methoddescriptorset.iterator(); methodit.hasNext();) {
+ MethodDescriptor currmd=(MethodDescriptor)methodit.next();
+ /* Need correct number of parameters */
+ if (types.length!=currmd.numParameters())
+ continue;
+ for(int i=0; i<types.length; i++) {
+ if (!this.isSuperorType(currmd.getParamType(i),types[i]))
+ continue NextMethod;
+ }
+ /* Method okay so far */
+ if (bestmd==null)
+ bestmd=currmd;
+ else {
+ if (isMoreSpecific(currmd,bestmd)) {
+ bestmd=currmd;
+ } else if (!isMoreSpecific(bestmd, currmd))
+ throw new Error("No method is most specific");
+
+ /* Is this more specific than bestmd */
+ }
+ }
+ if (bestmd==null)
+ throw new Error("Could find: "+name + " in "+cd);
+
+ return bestmd;
+ }
+
+ public void createFullTable() {
+ subclasstable=new Hashtable();
+
+ Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
+ while(classit.hasNext()) {
+ ClassDescriptor cd=(ClassDescriptor)classit.next();
+ ClassDescriptor tmp=cd.getSuperDesc();
+
+ while(tmp!=null) {
+ if (!subclasstable.containsKey(tmp))
+ subclasstable.put(tmp,new HashSet());
+ HashSet hs=(HashSet)subclasstable.get(tmp);
+ hs.add(cd);
+ tmp=tmp.getSuperDesc();
+ }
+ }
+ }
+
+ public Set getSubClasses(ClassDescriptor cd) {
+ return (Set)subclasstable.get(cd);
+ }
+
+ public ClassDescriptor getSuper(ClassDescriptor cd) {
+ return (ClassDescriptor)supertable.get(cd);
+ }
+
+ public boolean isCastable(TypeDescriptor original, TypeDescriptor casttype) {
+ if (original.isChar()&&
+ (casttype.isByte()||
+ casttype.isShort()))
+ return true;
+
+ if (casttype.isChar()&&
+ (original.isByte()||
+ original.isShort()||
+ original.isInt()||
+ original.isLong()||
+ original.isFloat()||
+ original.isDouble()))
+ return true;
+
+ return false;
+ }
+
+ public boolean isSuperorType(TypeDescriptor possiblesuper, TypeDescriptor cd2) {
+ if (possiblesuper.isOffset() || cd2.isOffset()) return true;
+ //Matching type are always okay
+ if (possiblesuper.equals(cd2))
+ return true;
+
+ if ((possiblesuper.isTag() && !cd2.isTag())||
+ (!possiblesuper.isTag() && cd2.isTag()))
+ return false;
+
+ //Handle arrays
+ if (cd2.isArray()||possiblesuper.isArray()) {
+ // Object is super class of all arrays
+ if (possiblesuper.getSymbol().equals(ObjectClass)&&!possiblesuper.isArray())
+ return true;
+
+ // If we have the same dimensionality of arrays & both are classes, we can default to the normal test
+ if (cd2.isClass()&&possiblesuper.isClass()
+ &&(possiblesuper.getArrayCount()==cd2.getArrayCount())&&
+ isSuperorType(possiblesuper.getClassDesc(), cd2.getClassDesc()))
+ return true;
+
+ // Object is superclass of all array classes
+ if (possiblesuper.getSymbol().equals(ObjectClass)&&cd2.isClass()
+ &&(possiblesuper.getArrayCount()<cd2.getArrayCount()))
+ return true;
+
+ //Allow arraytype=null statements
+ if (possiblesuper.isArray()&&cd2.isNull())
+ return true;
+
+ return false;