LOGIN   :::   RECOVER PASS   :::   GET ACCOUNT    
Browse
  • Projects
  • Code (CVS)
  • Forums
  • News
  • Articles
  • Polls
  •  
    OpenCores
  • FAQ
  • CVS HowTo
  • Mission
  • Media
  • Tools
  • Advertise
  • Mirrors
  • Logos
  • Contact us
  • Job Opportunity
  •  
    Tools
  • Search
      
  • Download Cores (CVSGet)
  •  
    More
  • Wishbone
  • Perlilog
  • EDA tools
  • OpenTech CD
  •  
    Navigation: All forums > Cvs-checkins > Message List > Message Post

    Message

    Reply | Reply all
    Date Prev | Date Next | Thread Prev | Thread Next Date Index | Thread Index

    From: cvs at opencores.org<cvs@o...>
    Date: Tue Feb 26 00:29:34 CET 2008
    Subject: [cvs-checkins] MODIFIED: jop ...
    Top
    Date: 00/08/02 26:00:29

    Modified: jop/java/tools/src/com/jopdesign/libgraph/struct
    ConstantClass.java ClassInfo.java
    ConstantMethod.java MethodCode.java AppStruct.java
    ConstantField.java ConstantPoolInfo.java
    Log:
    fixes for incomplete code loading, added more array handling code


    Revision Changes Path
    1.3 jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantClass.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantClass.java.diff?r1=1.2&r2=1.3

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: ConstantClass.java
    ===================================================================
    RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantClass.java,v
    retrieving revision 1.2
    retrieving revision 1.3
    diff -u -b -r1.2 -r1.3
    --- ConstantClass.java 14 Feb 2008 01:26:02 -0000 1.2
    +++ ConstantClass.java 25 Feb 2008 23:29:34 -0000 1.3
    @@ -18,6 +18,8 @@
    */
    package com.jopdesign.libgraph.struct;

    +import com.jopdesign.libgraph.struct.type.ArrayRefType;
    +
    /**
    * @author Stefan Hepp, e0026640@s...
    */
    @@ -26,6 +28,7 @@
    private ClassInfo classInfo;
    private String className;
    private boolean cInterface;
    + private ArrayRefType arrayType;

    public ConstantClass(ClassInfo classInfo) {
    this.classInfo = classInfo;
    @@ -44,6 +47,15 @@
    this.cInterface = isInterface;
    }

    + /**
    + * Create an array class.
    + * @param arrayType the type of the array (including the array itself).
    + */
    + public ConstantClass(ArrayRefType arrayType) {
    + className = arrayType.getDescriptor();
    + this.arrayType = arrayType;
    + }
    +
    public ClassInfo getClassInfo() {
    return classInfo;
    }
    @@ -59,4 +71,12 @@
    public boolean isInterface() {
    return classInfo != null ? classInfo.isInterface() : cInterface;
    }
    +
    + public boolean isArray() {
    + return arrayType != null;
    + }
    +
    + public ArrayRefType getArrayType() {
    + return arrayType;
    + }
    }



    1.5 jop/java/tools/src/com/jopdesign/libgraph/struct/ClassInfo.java

    http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/ClassInfo.java.diff?r1=1.4&r2=1.5

    (In the diff below, changes in quantity of whitespace are not shown.)

    Index: ClassInfo.java
    ===================================================================
    RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/ClassInfo.java,v
    retrieving revision 1.4
    retrieving revision 1.5
    diff -u -b -r1.4 -r1.5
    --- ClassInfo.java 15 Feb 2008 21:08:20 -0000 1.4
    +++ ClassInfo.java 25 Feb 2008 23:29:34 -0000 1.5
    @@ -331,6 +331,7 @@
    * @return the method if found, else null.
    * @see #getMethodInfo(String)
    * @see #getInheritedMethodInfo(String, boolean, boolean)
    + * @see #findInterfaceMethodInfo(String)
    */
    public MethodInfo getVirtualMethodInfo(String methodName, String signature) {
    return getVirtualMethodInfo(MethodSignature.createFullName(methodName, signature));
    @@ -346,9 +347,15 @@
    * @return the method if found, else null.
    * @see #getMethodInfo(String)
    * @see #getInheritedMethodInfo(String, boolean, boolean)
    + * @see #findInterfaceMethodInfo(String)
    */
    public MethodInfo getVirtualMethodInfo(String method) { - return getInheritedMethodInfo(method, false, true); + MethodInfo methodInfo = getInheritedMethodInfo(method, false, true); + if ( methodInfo == null ) { + // maybe defined in interfaces + methodInfo = findInterfaceMethodInfo(method); + } + return methodInfo; } /** @@ -370,7 +377,7 @@ // check if this method can be overwritten. if (inheritedOnly && method != null) { - if (method.isPrivate() || method.isStatic()) { + if (method.isPrivate()) { method = null; } } @@ -381,6 +388,36 @@ return method; } + /** + * Find the (first) interface this class implements and which defines the given method. + * + * @param methodName full method name as created by {@link com.jopdesign.libgraph.struct.type.MethodSignature#createFullName(String,String)} ). + * @return the method of the (first) interface which defines the method, or null if no matching interface is found. + */ + public MethodInfo findInterfaceMethodInfo(String methodName) { + + List queue = new LinkedList(interfaces); + Set visited = new HashSet(interfaces.size()); + + while ( !queue.isEmpty() ) { + + ClassInfo info = (ClassInfo) queue.remove(0); + if ( visited.contains(info.getClassName()) ) { + continue; + } + + MethodInfo method = info.getMethodInfo(methodName); + if ( method != null ) { + return method; + } + + visited.add(info.getClassName()); + queue.addAll(info.getInterfaces()); + } + + return null; + } + public FieldInfo getFieldInfo(String name) { return (FieldInfo) fields.get(name); } @@ -398,7 +435,7 @@ field = sup.getFieldInfo(name); if ( inheritedOnly && field != null ) { - if ( field.isPrivate() || field.isStatic() ) { + if ( field.isPrivate() ) { field = null; } } @@ -413,7 +450,7 @@ * (re)load all class informations from javaClass. * @return true if references have changed. */ - public boolean reload() { + public boolean reload() throws TypeException { boolean refChanged = false; boolean complete = true; @@ -421,16 +458,18 @@ // get super class (null if this is java.lang.Object) String superClassName = getSuperClassName(); if ( superClassName != null ) { - superClass = appStruct.getClassInfo(superClassName); + superClass = appStruct.getClassInfo(superClassName, true); if ( superClass != null ) { refChanged = superClass.addSubClass(this) || refChanged; refChanged = references.add(superClass) || refChanged; } else { complete = false; - logger.warn("Could not find superclass {" + superClassName + + if (logger.isInfoEnabled()) { + logger.info("Could not load superclass {" + superClassName + "} for class {" + getClassName() + "}."); } } + } interfaces = loadInterfaces(); @@ -520,7 +559,7 @@ return out.toString(); } - protected abstract Set loadInterfaces(); + protected abstract Set loadInterfaces() throws TypeException; protected abstract void loadMethodInfos(); 1.2 jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantMethod.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantMethod.java.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: ConstantMethod.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantMethod.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- ConstantMethod.java 13 Jan 2008 20:29:32 -0000 1.1 +++ ConstantMethod.java 25 Feb 2008 23:29:34 -0000 1.2 @@ -39,6 +39,13 @@ private static final Logger logger = Logger.getLogger(ConstantMethod.class); private boolean cInterface; + private boolean cStatic; + + public ConstantMethod(MethodInfo methodInfo) throws TypeException { + this.classInfo = methodInfo.getClassInfo(); + this.methodInfo = methodInfo; + this.signature = methodInfo.getMethodSignature(); + } public ConstantMethod(ClassInfo classInfo, MethodInfo methodInfo) throws TypeException { this.classInfo = classInfo; @@ -46,10 +53,12 @@ this.signature = methodInfo.getMethodSignature(); } - - public ConstantMethod(String className, String methodName, String signature, boolean isInterface) { + public ConstantMethod(String className, String methodName, String signature, boolean isInterface, + boolean isStatic) + { this.className = className; this.cInterface = isInterface; + this.cStatic = isStatic; try { this.signature = TypeHelper.parseSignature(null, methodName, signature); } catch (TypeException e) { @@ -99,4 +108,16 @@ public boolean isInterface() { return classInfo != null ? classInfo.isInterface() : cInterface; } + + public boolean isStatic() { + return methodInfo != null ? methodInfo.isStatic() : cStatic; + } + + public String getFQMethodName() { + return MethodInfo.createFQMethodName(getClassName(), getMethodName(), getSignature()); + } + + public String toString() { + return getFQMethodName(); + } } 1.3 jop/java/tools/src/com/jopdesign/libgraph/struct/MethodCode.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/MethodCode.java.diff?r1=1.2&r2=1.3 (In the diff below, changes in quantity of whitespace are not shown.) Index: MethodCode.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/MethodCode.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- MethodCode.java 14 Feb 2008 01:26:02 -0000 1.2 +++ MethodCode.java 25 Feb 2008 23:29:34 -0000 1.3 @@ -117,10 +117,9 @@ /** * get a list of all invoked methods of this method. - * TODO return also instruction-nr, constantpool-nr?; also return invocations outside loaded classes? + * TODO return also instruction-nr, constantpool-nr?; also return invocations to anonymous classes? * @return a list of {@link MethodInvocation} classes for invoked methods. - * @throws TypeException if referenced class is missing - * @throws TypeException if any type is used which cannot be loaded + * @throws TypeException if referenced class is missing or if any type is used which cannot be loaded. */ public abstract List getInvokedMethods() throws TypeException; 1.4 jop/java/tools/src/com/jopdesign/libgraph/struct/AppStruct.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/AppStruct.java.diff?r1=1.3&r2=1.4 (In the diff below, changes in quantity of whitespace are not shown.) Index: AppStruct.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/AppStruct.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- AppStruct.java 15 Feb 2008 21:08:20 -0000 1.3 +++ AppStruct.java 25 Feb 2008 23:29:34 -0000 1.4 @@ -18,7 +18,8 @@ */ package com.jopdesign.libgraph.struct; -import com.jopdesign.libgraph.struct.type.MethodSignature; +import com.jopdesign.libgraph.struct.type.ArrayRefType; +import com.jopdesign.libgraph.struct.type.TypeHelper; import org.apache.log4j.Logger; import java.io.IOException; @@ -87,6 +88,13 @@ */ public ClassInfo tryLoadMissingClass(String className) throws TypeException { + if ( config.isLibraryClassName(className) ) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping post-loading of library class {" + className + "}"); + } + return null; + } + if ( !config.doLoadOnDemand() ) { if ( config.doAllowIncompleteCode() || config.isNativeClassName(className) ) { if (logger.isTraceEnabled()) { @@ -152,10 +160,26 @@ return classInfos.values(); } + /** + * Get a known classInfo by name. + * This does not try to load unkown classes. + * + * @see #getClassInfo(String, boolean) + * @param className the fully qualified classname. + * @return the classinfo if found, else null. + */ public ClassInfo getClassInfo(String className) { return (ClassInfo) classInfos.get(className); } + /** + * Get a classInfo and try to load it if not found. + * + * @param className the fully qualified class name of the class to load. + * @param ignoreMissing if the class is not loaded, throw an exception. + * @return the classInfo or null if class not found and ignoreMissing is true. + * @throws TypeException if the class should be loaded but was not found. + */ public ClassInfo getClassInfo(String className, boolean ignoreMissing) throws TypeException { ClassInfo classInfo = getClassInfo(className); if ( classInfo == null ) { @@ -168,7 +192,7 @@ } /** - * A small helper to create a constantclass for a classname. + * A function to create a constantclass for a classname. * This function tries to load the class with {@link #getClassInfo(String)} and {@link #tryLoadMissingClass(String)} * and creates an anonymous constantclass if the class could not be loaded. * @@ -178,6 +202,13 @@ * @throws TypeException if the class could not be loaded and anonymous classes are disabled. */ public ConstantClass getConstantClass(String className, boolean isInterface) throws TypeException { + + // This is an array-class + if ( className.startsWith("[") ) { + ArrayRefType type = (ArrayRefType) TypeHelper.parseType(this, className); + return new ConstantClass(type); + } + ClassInfo classInfo = getClassInfo(className); if ( classInfo == null ) { classInfo = tryLoadMissingClass(className); @@ -191,30 +222,58 @@ return cls; } - public ConstantMethod getConstantMethod(ConstantClass clazz, String methodName, String signature) throws TypeException { - - ConstantMethod method; + public ConstantMethod getConstantMethod(ConstantClass clazz, String methodName, String signature, + boolean isStatic) throws TypeException + { + ConstantMethod method = null; ClassInfo info = clazz.getClassInfo(); if ( info != null ) { - String fullName = MethodSignature.createFullName(methodName, signature); - MethodInfo methodInfo = info.getInheritedMethodInfo(fullName, false, true); + MethodInfo methodInfo = info.getVirtualMethodInfo(methodName, signature); if ( methodInfo != null ) { method = new ConstantMethod(info, methodInfo); } else { - throw new TypeException("Could not find method {"+methodName+"} with signature {"+signature+"} in class {" + - info.getClassName()+"}"); + // TODO check if class really extends unloaded classes, else throw exception + //throw new TypeException("Could not find method {" + methodName + "} with signature {" + + // signature + "} in class {" + info.getClassName() + "}"); + } } - } else { - method = new ConstantMethod(clazz.getClassName(), methodName, signature, clazz.isInterface()); + if ( method == null ) { + method = new ConstantMethod(clazz.getClassName(), methodName, signature, clazz.isInterface(), isStatic); } return method; } + public ConstantField getConstantField(ConstantClass clazz, String fieldName, String signature, + boolean isStatic) throws TypeException + { + ConstantField field = null; + + ClassInfo info = clazz.getClassInfo(); + if ( info != null ) { + + FieldInfo fieldInfo = info.getVirtualFieldInfo(fieldName); + + if ( fieldInfo != null ) { + field = new ConstantField(info, fieldInfo); + } else { + // TODO check if class really extends unloaded classes, else throw exception + //throw new TypeException("Could not find field {"+fieldName+"} in class {"+info.getClassName()+"}."); + } + + } + + if ( field == null ) { + field = new ConstantField(clazz.getClassName(), fieldName, signature, isStatic); + } + + return field; + } + public void addClass(ClassInfo classInfo) { classInfos.put(classInfo.getClassName(), classInfo); 1.4 jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantField.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantField.java.diff?r1=1.3&r2=1.4 (In the diff below, changes in quantity of whitespace are not shown.) Index: ConstantField.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantField.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- ConstantField.java 22 Feb 2008 19:51:09 -0000 1.3 +++ ConstantField.java 25 Feb 2008 23:29:34 -0000 1.4 @@ -18,6 +18,10 @@ */ package com.jopdesign.libgraph.struct; +import com.jopdesign.libgraph.struct.type.TypeHelper; +import com.jopdesign.libgraph.struct.type.TypeInfo; +import org.apache.log4j.Logger; + /** * Container for a reference to a field. * As the reference may refer to a subclass of the class which defines the field, @@ -32,16 +36,18 @@ private String className; private String fieldName; private String signature; + private boolean isStatic; public ConstantField(ClassInfo classInfo, FieldInfo fieldInfo) { this.classInfo = classInfo; this.fieldInfo = fieldInfo; } - public ConstantField(String className, String fieldName, String signature) { + public ConstantField(String className, String fieldName, String signature, boolean isStatic) { this.className = className; this.fieldName = fieldName; this.signature = signature; + this.isStatic = isStatic; } public ClassInfo getClassInfo() { @@ -78,10 +84,22 @@ } public boolean isStatic() { - return fieldInfo != null ? fieldInfo.isStatic() : false; + return fieldInfo != null ? fieldInfo.isStatic() : isStatic; } public String getFQName() { return getClassName() + "#" + getFieldName(); } + + public TypeInfo getType() { + if ( fieldInfo != null ) { + return fieldInfo.getType(); + } + try { + return TypeHelper.parseType(null, getSignature()); + } catch (TypeException e) { + Logger.getLogger(this.getClass()).error("Could not create anonymous type for {"+getSignature()+"}."); + } + return null; + } } 1.2 jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantPoolInfo.java http://www.opencores.org/cvsweb.shtml/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantPoolInfo.java.diff?r1=1.1&r2=1.2 (In the diff below, changes in quantity of whitespace are not shown.) Index: ConstantPoolInfo.java =================================================================== RCS file: /cvsroot/stefant/jop/java/tools/src/com/jopdesign/libgraph/struct/ConstantPoolInfo.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- ConstantPoolInfo.java 13 Jan 2008 20:29:32 -0000 1.1 +++ ConstantPoolInfo.java 25 Feb 2008 23:29:34 -0000 1.2 @@ -37,9 +37,9 @@ public abstract ConstantClass getClassReference(int pos) throws TypeException; - public abstract ConstantMethod getMethodReference(int pos) throws TypeException; + public abstract ConstantMethod getMethodReference(int pos, boolean isStatic) throws TypeException; - public abstract ConstantField getFieldReference(int pos) throws TypeException; + public abstract ConstantField getFieldReference(int pos, boolean isStatic) throws TypeException; /** * Add a constant to the constantpool. Return the index of the constant.

     
    Copyright (c) 1999 OPENCORES.ORG. All rights reserved.