classdecl.java
来自「JDK1.4编译器前端」· Java 代码 · 共 1,302 行 · 第 1/4 页
JAVA
1,302 行
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.*;// 4.3 Reference Types and Valuespublic class ClassDecl extends ReferenceType implements Cloneable {
public void flushCache() { super.flushCache(); cast_Constant_visited = new java.util.HashMap(4); add_Constant_Constant_visited = new java.util.HashMap(4); questionColon_Constant_Constant_Constant_visited = new java.util.HashMap(4); eqIsTrue_Expr_Expr_visited = new java.util.HashMap(4); lineNumber_visited = -1; lookupSuperConstructor_visited = -1; noConstructor_visited = -1; noConstructor_computed = false; interfacesMethodsSignature_String_visited = new java.util.HashMap(4); interfacesMethodsSignatureMap_visited = -1; interfacesMethodsSignatureMap_computed = false; interfacesMethodsSignatureMap_value = null; methodsSignatureMap_visited = -1; methodsSignatureMap_computed = false; methodsSignatureMap_value = null; ancestorMethods_String_visited = new java.util.HashMap(4); ancestorMethods_String_values = null; memberTypes_String_visited = new java.util.HashMap(4); memberTypes_String_values = null; memberFields_String_visited = new java.util.HashMap(4); memberFields_String_values = null; unimplementedMethods_visited = -1; unimplementedMethods_computed = false; unimplementedMethods_value = null; hasAbstract_visited = -1; hasAbstract_computed = false; castingConversionTo_TypeDecl_visited = new java.util.HashMap(4); castingConversionTo_TypeDecl_values = null; isClassDecl_visited = -1; isString_visited = -1; isString_computed = false; isObject_visited = -1; isObject_computed = false; instanceOf_TypeDecl_visited = new java.util.HashMap(4); instanceOf_TypeDecl_values = null; isSupertypeOfClassDecl_ClassDecl_visited = new java.util.HashMap(4); isSupertypeOfInterfaceDecl_InterfaceDecl_visited = new java.util.HashMap(4); isSupertypeOfArrayDecl_ArrayDecl_visited = new java.util.HashMap(4); isInnerClass_visited = -1; isCircular_visited = 0; isCircular_computed = false; isCircular_initialized = false; } @SuppressWarnings({"unchecked", "cast"}) public ClassDecl clone() throws CloneNotSupportedException { ClassDecl node = (ClassDecl)super.clone(); node.cast_Constant_visited = new java.util.HashMap(4); node.add_Constant_Constant_visited = new java.util.HashMap(4); node.questionColon_Constant_Constant_Constant_visited = new java.util.HashMap(4); node.eqIsTrue_Expr_Expr_visited = new java.util.HashMap(4); node.lineNumber_visited = -1; node.lookupSuperConstructor_visited = -1; node.noConstructor_visited = -1; node.noConstructor_computed = false; node.interfacesMethodsSignature_String_visited = new java.util.HashMap(4); node.interfacesMethodsSignatureMap_visited = -1; node.interfacesMethodsSignatureMap_computed = false; node.interfacesMethodsSignatureMap_value = null; node.methodsSignatureMap_visited = -1; node.methodsSignatureMap_computed = false; node.methodsSignatureMap_value = null; node.ancestorMethods_String_visited = new java.util.HashMap(4); node.ancestorMethods_String_values = null; node.memberTypes_String_visited = new java.util.HashMap(4); node.memberTypes_String_values = null; node.memberFields_String_visited = new java.util.HashMap(4); node.memberFields_String_values = null; node.unimplementedMethods_visited = -1; node.unimplementedMethods_computed = false; node.unimplementedMethods_value = null; node.hasAbstract_visited = -1; node.hasAbstract_computed = false; node.castingConversionTo_TypeDecl_visited = new java.util.HashMap(4); node.castingConversionTo_TypeDecl_values = null; node.isClassDecl_visited = -1; node.isString_visited = -1; node.isString_computed = false; node.isObject_visited = -1; node.isObject_computed = false; node.instanceOf_TypeDecl_visited = new java.util.HashMap(4); node.instanceOf_TypeDecl_values = null; node.isSupertypeOfClassDecl_ClassDecl_visited = new java.util.HashMap(4); node.isSupertypeOfInterfaceDecl_InterfaceDecl_visited = new java.util.HashMap(4); node.isSupertypeOfArrayDecl_ArrayDecl_visited = new java.util.HashMap(4); node.isInnerClass_visited = -1; node.isCircular_visited = 0; node.isCircular_computed = false; node.isCircular_initialized = false; node.in$Circle(false); node.is$Final(false); return node; } @SuppressWarnings({"unchecked", "cast"}) public ClassDecl copy() { try { ClassDecl node = (ClassDecl)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 ClassDecl fullCopy() { ClassDecl res = (ClassDecl)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 147 public void accessControl() { super.accessControl(); // 8.1.1.2 final Classes TypeDecl typeDecl = hasSuperclass() ? superclass() : null; if(typeDecl != null && !typeDecl.accessibleFromExtend(this)) //if(typeDecl != null && !isCircular() && !typeDecl.accessibleFrom(this)) error("class " + fullName() + " may not extend non accessible type " + typeDecl.fullName()); if(hasSuperclass() && !superclass().accessibleFrom(this)) error("a superclass must be accessible which " + superclass().name() + " is not"); // 8.1.4 for(int i = 0; i < getNumImplements(); i++) { TypeDecl decl = getImplements(i).type(); if(!decl.isCircular() && !decl.accessibleFrom(this)) error("class " + fullName() + " can not implement non accessible type " + decl.fullName()); } } // Declared in ExceptionHandling.jrag at line 92 public void exceptionHandling() { constructors(); super.exceptionHandling(); } // Declared in LookupMethod.jrag at line 248 // iterator over all methods in implemented interfaces public Iterator interfacesMethodsIterator() { return new Iterator() { private Iterator outer = interfacesMethodsSignatureMap().values().iterator(); private Iterator inner = null; public boolean hasNext() { if((inner == null || !inner.hasNext()) && outer.hasNext()) inner = ((SimpleSet)outer.next()).iterator(); return inner == null ? false : inner.hasNext(); } public Object next() { return inner.next(); } public void remove() { throw new UnsupportedOperationException(); } }; } // Declared in Modifiers.jrag at line 94 public void checkModifiers() { super.checkModifiers(); // 8.1.1.2 final Classes TypeDecl typeDecl = hasSuperclass() ? superclass() : null; if(typeDecl != null && typeDecl.isFinal()) { error("class " + fullName() + " may not extend final class " + typeDecl.fullName()); } } // Declared in PrettyPrint.jadd at line 74 public void toString(StringBuffer s) { getModifiers().toString(s); s.append("class " + name()); if(hasSuperClassAccess()) { s.append(" extends "); getSuperClassAccess().toString(s); } if(getNumImplements() > 0) { s.append(" implements "); getImplements(0).toString(s); for(int i = 1; i < getNumImplements(); i++) { s.append(", "); getImplements(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 594 public boolean hasSuperclass() { return !isObject(); } // Declared in TypeAnalysis.jrag at line 598 public ClassDecl superclass() { if(isObject()) return null; if(hasSuperClassAccess() && !isCircular() && getSuperClassAccess().type().isClassDecl()) return (ClassDecl)getSuperClassAccess().type(); return (ClassDecl)typeObject(); } // Declared in TypeAnalysis.jrag at line 613 public Iterator interfacesIterator() { 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(isObject() || isCircular()) return; while(index < getNumImplements()) { TypeDecl typeDecl = getImplements(index++).type(); if(!typeDecl.isCircular() && typeDecl.isInterfaceDecl()) { current = typeDecl; return; } } } }; } // Declared in TypeHierarchyCheck.jrag at line 239 public void nameCheck() { super.nameCheck(); if(hasSuperClassAccess() && !getSuperClassAccess().type().isClassDecl()) error("class may only inherit a class and not " + getSuperClassAccess().type().typeName()); if(isObject() && hasSuperClassAccess()) error("class Object may not have superclass"); if(isObject() && getNumImplements() != 0) error("class Object may not implement interfaces"); // 8.1.3 if(isCircular()) error("circular inheritance dependency in " + typeName()); // 8.1.4 HashSet set = new HashSet(); for(int i = 0; i < getNumImplements(); i++) { TypeDecl decl = getImplements(i).type(); if(!decl.isInterfaceDecl() && !decl.isUnknown()) error("type " + fullName() + " tries to implement non interface type " + decl.fullName()); if(set.contains(decl)) error("type " + decl.fullName() + " mentionened multiple times in implements clause"); set.add(decl); } for(Iterator iter = interfacesMethodsIterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); if(localMethodsSignature(m.signature()).isEmpty()) { SimpleSet s = superclass().methodsSignature(m.signature()); for(Iterator i2 = s.iterator(); i2.hasNext(); ) { MethodDecl n = (MethodDecl)i2.next(); if(n.accessibleFrom(this)) { interfaceMethodCompatibleWithInherited(m, n); } } if(s.isEmpty()) { for(Iterator i2 = interfacesMethodsSignature(m.signature()).iterator(); i2.hasNext(); ) { MethodDecl n = (MethodDecl)i2.next(); if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(n)) error("Xthe return type of method " + m.signature() + " in " + m.hostType().typeName() + " does not match the return type of method " + n.signature() + " in " + n.hostType().typeName() + " and may thus not be overriden"); } } } } } // Declared in TypeHierarchyCheck.jrag at line 286 private void interfaceMethodCompatibleWithInherited(MethodDecl m, MethodDecl n) { if(n.isStatic()) error("Xa static method may not hide an instance method"); if(!n.isAbstract() && !n.isPublic()) error("Xoverriding access modifier error for " + m.signature() + " in " + m.hostType().typeName() + " and " + n.hostType().typeName()); if(!n.mayOverrideReturn(m) && !m.mayOverrideReturn(m)) error("Xthe return type of method " + m.signature() + " in " + m.hostType().typeName() + " does not match the return type of method " + n.signature() + " in " + n.hostType().typeName() + " and may thus not be overriden"); if(!n.isAbstract()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?