⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classdata.java

📁 java 到c的转换程序的原代码.对喜欢C程序而不懂JAVA程序的人很有帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * that instead. */    ocd = getByNameLoader (ncd.name, cld);    if (null != ocd) {        ncd = ocd;    } else {        /* Didn't have one before; memorize this one, if asked to do so. */        if (rememberp) {            addByNameLoader (ncd.name, cld, ncd);        }    }    /* Return what we got. */    return ncd;}/** Get a ClassData structure corresponding to the given Class, which must * have been resolved. */public static ClassDataforClass (Class cl){    ClassData cd;        /* If it's in the hash table, we're OK */    cd = getByNameLoader (cl.getName (), cl.getClassLoader ());    /* If it's not in the hash table, we're supposed to make one.  Do so. */    if (null == cd) {        /* Two caveats here: this only works when we're running in a         * Toba runtime system, because we'll be using a native function         * to parse the internal class structure.  Second, we _must_         * remember this thing, because we're storing a pointer to         * it in the internal structure (the pre-compiled struct class),         * and that's not scanned for GC */        cd = new ClassData (cl);        addByNameLoader (cl.getName (), cl.getClassLoader (), cd);    }    /* Return what we got. */    return cd;}/** Get a ClassData structure corresponding to the given name. */public static ClassDataforName (String nm)throws ClassNotFoundException{    ClassData cd;        /* This is only to be called within the translator, i.e. when there's no     * confusion about class loaders */    /* If it's in the hash table, we're OK */    cd = getByNameLoader (nm, null);    /* If it's not in the hash table, we're supposed to make one.  Do so. */    if (null == cd) {        cd = ClassData.forClass (Class.forName (nm));    }    /* Return what we got. */    return cd;}//  getmethod(name, climb) -- find "()V" method by name////  if climb is true, and if superclasses have been loaded, check them too.public Field getmethod(String name, boolean climb){    for (ClassData k = this; k != null; k = k.superclass) {	for (Field m = (Field)k.symtab.get(name); m != null; m = m.next) {	    if (m.signature.equals("()V")) {		return m;	    }	}	if (!climb)	    break;    }    return null;}//  Methods for dealing with superclasses, once they have been set.//  buildMethodTables(class) -- scan methods and build method tables.////  Assumes that superclasses have been loaded.private void buildMethodTables(boolean setSlots){    int mtsize;    int stsize = 0;        if (imtable != null)    	return;				// method table already initialized    if (superclass == null) {	mtsize = 0;    } else {	mtsize = superclass.imtable.length;    }    //  assign method table slots, checking for overrides of ancestors.nextmethod:    for (int i = 0; i < methods.length; i++) {	Field f = methods[i];	if ((f.access & ClassData.ACC_STATIC) != 0) {	    /* Give static method a slot in the static table for this class */            if (setSlots) {                f.tableslot = stsize;            } else {                if (f.tableslot != stsize) {                    throw new InternalError ("C class static method slot mismatch");                }            }            stsize++; 	} else {	    // this is a virtual method	    String name = f.name;	    int gen = 0;	    for (ClassData c = superclass; c != null; c = c.superclass) {		gen++;		for (Field a = (Field)c.symtab.get(name); 		     a != null; a = a.next) {		    if ((a.access & ClassData.ACC_PRIVATE) != 0)			continue;		    if (f.signature.equals(a.signature)) {			// this method overrides an ancestor			f.overrides = a.overrides + gen;                        if (setSlots) {                            f.tableslot = a.tableslot;                        } else {                            if (f.tableslot != a.tableslot) {                                throw new InternalError ("C class method instance override slot mismatch");                            }                        }			continue nextmethod;		    }		}	    }	    	    // method does not override an ancestor, so it 	    // gets a method table slot            if (setSlots) {                f.tableslot = mtsize;            } else {                if (f.tableslot != mtsize) {                    throw new InternalError ("C class method instance slot mismatch");                }            }            mtsize++;	}    }    // allocate and initialize instance method table    imtable = new Field[mtsize];    smtable = new Field[stsize];    if (superclass != null)	System.arraycopy(superclass.imtable, 0, imtable, 0,			 superclass.imtable.length);    for (int i = 0; i < methods.length; i++) {	Field f = methods[i];	if ((f.access & ClassData.ACC_STATIC) == 0)	    imtable[f.tableslot] = f;	else	    smtable[f.tableslot] = f;    }}//  ivregister(c, h) -- register instance variables in visibility table////  Put our visible fields into the visibility hash table. Assumes that //  the table alreay contains the visible fields for out superclassprivate void ivregister(){    for (int i = 0; i < fields.length; i++) {	Field f = fields[i];	if ((f.access & ClassData.ACC_STATIC) == 0)	    visiblevars.put(f.name, f);    }}// buildVariableTables(k) - Build table of instance and static variables. // Compute a hash table of // visible instance fields, also.private void buildVariableTables(boolean setSlots){    int ivtsize;    int svtsize = 0; // static variables are not inherited.    if (! setSlots) {//        System.out.println ("buildVariableTables on tobaclass:\n" + this);    }    /* Static vars aren't inherited, so start with zero; instance ones are,     * so start with superclass values if present. */    if (superclass != null) {	visiblevars = (Hashtable)superclass.visiblevars.clone();	ivtsize = superclass.ivtable.length;    } else {	visiblevars = new Hashtable();	ivtsize = 0;    }    ivregister();    // Compute the number of static and instance variables,    // and record their offset in the table as we go.    for (int i = 0; i < fields.length; i++) {	Field f = fields[i];//        System.out.println ("Field " + f.name + " slot " + f.tableslot + "; ivt=" +//                            ivtsize + ", svt=" + svtsize);	if ((f.access & ClassData.ACC_STATIC) == 0) {            if (setSlots) {                f.tableslot = ivtsize;            } else {                if (f.tableslot != ivtsize) {                    throw new InternalError ("C class instance var slot mismatch: " +                                             name + ", iv " + f.name + ", asg " + f.tableslot +                                             " and inferred " + ivtsize);                }            }            ++ivtsize;	} else {            if (setSlots) {                f.tableslot = svtsize;            } else {                if (f.tableslot != svtsize) {                    throw new InternalError ("C class static var slot mismatch");                }            }            ++svtsize;	}    }    ivtable = new Field[ivtsize];    cvtable = new Field[svtsize];    // Put all of our new variables into appropriate tables. We copy the     // table of instance variables from our superclass.        // copy the appropriate information from our superclass    if (superclass != null)	System.arraycopy(superclass.ivtable, 0, ivtable, 0,			 superclass.ivtable.length);    for (int i = 0; i < fields.length; i++) {	Field f = fields[i];	if ((f.access & ClassData.ACC_STATIC) == 0) {	    ivtable[f.tableslot] = f;	} else {	    cvtable[f.tableslot] = f;	}    }}// buildTables(k) - build the method and variable tables for this class.// assumes that these tables have already been built for my superclasspublic void buildTables(){    /* Do not screw with the table slots if this is a toba-generated whatsis.     * They're already right. */    buildMethodTables(CDSRC_tobaclass != cdsrc);    buildVariableTables(CDSRC_tobaclass != cdsrc);}private StringarrayString (Object ob[]){    if (null == ob) {        return "null";    } else {        StringBuffer str = new StringBuffer (Integer.toString (ob.length) + ": ");        int i;        for (i = 0; i < ob.length ; i++) {            str.append (ob[i] + " ");        }        return str.toString ();    }}public StringtoString (){    StringBuffer str = new StringBuffer ("");    str.append ("name: " + name + "\n");    str.append ("cname: " + cname + "\n");    str.append ("fname: " + fname + "\n");    str.append ("supername: " + supername + "\n");    str.append ("(major, minor): " + major + ", " + minor + "\n");    str.append ("access: 0x" + Integer.toHexString (access) + "\n");    str.append ("Constants: " + arrayString (constants) + "\n");    str.append ("Interfaces: " + arrayString (interfaces) + "\n");    str.append ("Fields: " + arrayString (fields) + "\n");    str.append ("Methods: " + arrayString (methods) + "\n");    str.append ("Inst Methods: " + arrayString (imtable) + "\n");    str.append ("Stat Methods: " + arrayString (smtable) + "\n");    str.append ("Attributes: " + arrayString (attributes) + "\n");    str.append ("Source: " + cdsrc + "\n");    str.append ("State: " + state + "\n");    return str.toString ();}} // class ClassData

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -