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

📄 interfacedecl.java

📁 JDK1.4编译器后端
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

package AST;
import java.util.HashSet;import java.util.LinkedHashSet;import java.io.FileNotFoundException;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;public class InterfaceDecl extends ReferenceType implements Cloneable {
    public void flushCache() {        super.flushCache();        methodsSignatureMap_computed = false;        methodsSignatureMap_value = null;        ancestorMethods_String_values = null;        memberTypes_String_values = null;        memberFields_String_values = null;        isStatic_computed = false;        castingConversionTo_TypeDecl_values = null;        instanceOf_TypeDecl_values = null;        isCircular_visited = 0;        isCircular_computed = false;        isCircular_initialized = false;        typeDescriptor_computed = false;        typeDescriptor_value = null;    }     @SuppressWarnings({"unchecked", "cast"})  public InterfaceDecl clone() throws CloneNotSupportedException {        InterfaceDecl node = (InterfaceDecl)super.clone();        node.methodsSignatureMap_computed = false;        node.methodsSignatureMap_value = null;        node.ancestorMethods_String_values = null;        node.memberTypes_String_values = null;        node.memberFields_String_values = null;        node.isStatic_computed = false;        node.castingConversionTo_TypeDecl_values = null;        node.instanceOf_TypeDecl_values = null;        node.isCircular_visited = 0;        node.isCircular_computed = false;        node.isCircular_initialized = false;        node.typeDescriptor_computed = false;        node.typeDescriptor_value = null;        node.in$Circle(false);        node.is$Final(false);    return node;    }     @SuppressWarnings({"unchecked", "cast"})  public InterfaceDecl copy() {      try {          InterfaceDecl node = (InterfaceDecl)clone();          if(children != null) node.children = (ASTNode[])children.clone();          return node;      } catch (CloneNotSupportedException e) {      }      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");      return null;    }     @SuppressWarnings({"unchecked", "cast"})  public InterfaceDecl fullCopy() {        InterfaceDecl res = (InterfaceDecl)copy();        for(int i = 0; i < getNumChildNoTransform(); i++) {          ASTNode node = getChildNoTransform(i);          if(node != null) node = node.fullCopy();          res.setChild(node, i);        }        return res;    }    // Declared in AccessControl.jrag at line 167  public void accessControl() {    super.accessControl();        if(!isCircular()) {      // 9.1.2      HashSet set = new HashSet();      for(int i = 0; i < getNumSuperInterfaceId(); i++) {        TypeDecl decl = getSuperInterfaceId(i).type();        if(!decl.isInterfaceDecl() && !decl.isUnknown())          error("interface " + fullName() + " tries to extend non interface type " + decl.fullName());        if(!decl.isCircular() && !decl.accessibleFrom(this))          error("interface " + fullName() + " can not extend non accessible type " + decl.fullName());        if(set.contains(decl))          error("extended interface " + decl.fullName() + " mentionened multiple times in extends clause");        set.add(decl);      }    }  }    // Declared in Modifiers.jrag at line 104    public void checkModifiers() {    super.checkModifiers();  }    // Declared in PrettyPrint.jadd at line 99    public void toString(StringBuffer s) {    getModifiers().toString(s);    s.append("interface " + name());    if(getNumSuperInterfaceId() > 0) {      s.append(" extends ");      getSuperInterfaceId(0).toString(s);      for(int i = 1; i < getNumSuperInterfaceId(); i++) {        s.append(", ");        getSuperInterfaceId(i).toString(s);      }    }    s.append(" {\n");    indent++;    for(int i=0; i < getNumBodyDecl(); i++) {      getBodyDecl(i).toString(s);    }        indent--;    s.append(indent() + "}\n");  }    // Declared in TypeAnalysis.jrag at line 642    public Iterator superinterfacesIterator() {    return new Iterator() {      public boolean hasNext() {        computeNextCurrent();        return current != null;      }      public Object next() {        return current;      }      public void remove() {        throw new UnsupportedOperationException();      }      private int index = 0;      private TypeDecl current = null;      private void computeNextCurrent() {        current = null;        if(isCircular()) return;        while(index < getNumSuperInterfaceId()) {          TypeDecl typeDecl = getSuperInterfaceId(index++).type();          if(!typeDecl.isCircular() && typeDecl.isInterfaceDecl()) {            current = typeDecl;            return;          }        }      }    };  }    // Declared in TypeHierarchyCheck.jrag at line 312  public void nameCheck() {    super.nameCheck();    if(isCircular())      error("circular inheritance dependency in " + typeName());     else {      for(int i = 0; i < getNumSuperInterfaceId(); i++) {        TypeDecl typeDecl = getSuperInterfaceId(i).type();        if(typeDecl.isCircular())          error("circular inheritance dependency in " + typeName());       }    }    for(Iterator iter = methodsSignatureMap().values().iterator(); iter.hasNext(); ) {      SimpleSet set = (SimpleSet)iter.next();      if(set.size() > 1) {        Iterator i2 = set.iterator();        MethodDecl m = (MethodDecl)i2.next();        while(i2.hasNext()) {          MethodDecl n = (MethodDecl)i2.next();          if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(n))            error("multiply inherited methods with the same signature must have the same return type");        }      }    }  }    // Declared in GenerateClassfile.jrag at line 142    public void generateClassfile() {    super.generateClassfile();    String fileName = destinationPath() + File.separator + constantPoolName() + ".class";    if(Program.verbose()) System.out.println("Writing class file to " + fileName);    try {      ConstantPool cp = constantPool();      // force building of constant pool      cp.addClass(constantPoolName());      cp.addClass("java/lang/Object");      for(int i = 0; i < getNumSuperInterfaceId(); i++) {        cp.addClass(getSuperInterfaceId(i).type().constantPoolName());      }      for(Iterator iter = bcFields().iterator(); iter.hasNext(); ) {        FieldDeclaration field = (FieldDeclaration) iter.next();        cp.addUtf8(field.name());        cp.addUtf8(field.type().typeDescriptor());        field.attributes();      }      for(Iterator iter = bcMethods().iterator(); iter.hasNext(); ) {        Object obj = iter.next();        if(obj instanceof MethodDecl) {          MethodDecl m = (MethodDecl) obj;          cp.addUtf8(m.name());          cp.addUtf8(m.descName());          m.attributes();        }      }      attributes();            if(hasClinit()) {        cp.addUtf8("<clinit>");        cp.addUtf8("()V");        clinit_attributes();      }      // actual classfile generation      File dest = new File(fileName);      File parentFile = dest.getParentFile();      if(parentFile != null)        parentFile.mkdirs();      FileOutputStream f = new FileOutputStream(fileName);      DataOutputStream out = new DataOutputStream(new BufferedOutputStream(f));      out.writeInt(magicHeader());      out.writeChar(minorVersion());      out.writeChar(majorVersion());      cp.emit(out);      int flags = flags();      if(isNestedType())        flags = mangledFlags(flags);      if(isInterfaceDecl())        flags |= Modifiers.ACC_INTERFACE;      out.writeChar(flags);      out.writeChar(cp.addClass(constantPoolName()));      out.writeChar(cp.addClass("java/lang/Object"));      if(getNumSuperInterfaceId() == 1 && getSuperInterfaceId(0).type().isObject())        out.writeChar(0);      else        out.writeChar(getNumSuperInterfaceId());      for(int i = 0; i < getNumSuperInterfaceId(); i++) {        TypeDecl typeDecl = getSuperInterfaceId(i).type();        if(typeDecl.isInterfaceDecl())          out.writeChar(cp.addClass(typeDecl.constantPoolName()));      }      Collection fields = bcFields();      out.writeChar(fields.size());      for(Iterator iter = fields.iterator(); iter.hasNext(); ) {        FieldDeclaration field = (FieldDeclaration) iter.next();        out.writeChar(field.flags());        out.writeChar(cp.addUtf8(field.name()));        out.writeChar(cp.addUtf8(field.type().typeDescriptor()));        out.writeChar(field.attributes().size());        for(Iterator itera = field.attributes().iterator(); itera.hasNext();)          ((Attribute)itera.next()).emit(out);      }      Collection methods = bcMethods();      out.writeChar(methods.size() + (hasClinit() ? 1 : 0));      for(Iterator iter = methods.iterator(); iter.hasNext(); ) {        BodyDecl b = (BodyDecl)iter.next();        b.generateMethod(out, cp);      }      if(hasClinit()) {        out.writeChar(Modifiers.ACC_STATIC);        out.writeChar(cp.addUtf8("<clinit>"));        out.writeChar(cp.addUtf8("()V"));        out.writeChar(clinit_attributes().size());        for(Iterator itera = clinit_attributes().iterator(); itera.hasNext();)          ((Attribute)itera.next()).emit(out);      }      out.writeChar(attributes().size());      for(Iterator itera = attributes().iterator(); itera.hasNext();)        ((Attribute)itera.next()).emit(out);      out.close();    } catch (IOException e) {      e.printStackTrace();    }  }    // Declared in Java2Rewrites.jrag at line 100  public FieldDeclaration createStaticClassField(String name) {    return methodHolder().createStaticClassField(name);  }    // Declared in Java2Rewrites.jrag at line 103  public MethodDecl createStaticClassMethod() {    return methodHolder().createStaticClassMethod();  }    // Declared in Java2Rewrites.jrag at line 107  // create anonymous class to delegate to  private TypeDecl methodHolder = null;    // Declared in Java2Rewrites.jrag at line 108

⌨️ 快捷键说明

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