📄 classinstanceexpr.java
字号:
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 ClassInstanceExpr extends Access implements Cloneable {
public void flushCache() { super.flushCache(); isDAafterInstance_Variable_visited = new java.util.HashMap(4); isDAafterInstance_Variable_values = null; isDAafter_Variable_visited = new java.util.HashMap(4); computeDAbefore_int_Variable_visited = new java.util.HashMap(4); computeDAbefore_int_Variable_values = null; isDUafterInstance_Variable_visited = new java.util.HashMap(4); isDUafter_Variable_visited = new java.util.HashMap(4); computeDUbefore_int_Variable_visited = new java.util.HashMap(4); computeDUbefore_int_Variable_values = null; applicableAndAccessible_ConstructorDecl_visited = new java.util.HashMap(4); decls_visited = -1; decls_computed = false; decls_value = null; decl_visited = -1; decl_computed = false; decl_value = null; qualifiedLookupType_String_visited = new java.util.HashMap(4); localLookupType_String_visited = new java.util.HashMap(4); localLookupType_String_values = null; validArgs_visited = -1; predNameType_visited = -1; type_visited = -1; type_computed = false; type_value = null; noEnclosingInstance_visited = -1; handlesException_TypeDecl_visited = new java.util.HashMap(4); typeObject_visited = -1; unknownConstructor_visited = -1; enclosingInstance_visited = -1; inExplicitConstructorInvocation_visited = -1; } @SuppressWarnings({"unchecked", "cast"}) public ClassInstanceExpr clone() throws CloneNotSupportedException { ClassInstanceExpr node = (ClassInstanceExpr)super.clone(); node.isDAafterInstance_Variable_visited = new java.util.HashMap(4); node.isDAafterInstance_Variable_values = null; node.isDAafter_Variable_visited = new java.util.HashMap(4); node.computeDAbefore_int_Variable_visited = new java.util.HashMap(4); node.computeDAbefore_int_Variable_values = null; node.isDUafterInstance_Variable_visited = new java.util.HashMap(4); node.isDUafter_Variable_visited = new java.util.HashMap(4); node.computeDUbefore_int_Variable_visited = new java.util.HashMap(4); node.computeDUbefore_int_Variable_values = null; node.applicableAndAccessible_ConstructorDecl_visited = new java.util.HashMap(4); node.decls_visited = -1; node.decls_computed = false; node.decls_value = null; node.decl_visited = -1; node.decl_computed = false; node.decl_value = null; node.qualifiedLookupType_String_visited = new java.util.HashMap(4); node.localLookupType_String_visited = new java.util.HashMap(4); node.localLookupType_String_values = null; node.validArgs_visited = -1; node.predNameType_visited = -1; node.type_visited = -1; node.type_computed = false; node.type_value = null; node.noEnclosingInstance_visited = -1; node.handlesException_TypeDecl_visited = new java.util.HashMap(4); node.typeObject_visited = -1; node.unknownConstructor_visited = -1; node.enclosingInstance_visited = -1; node.inExplicitConstructorInvocation_visited = -1; node.in$Circle(false); node.is$Final(false); return node; } @SuppressWarnings({"unchecked", "cast"}) public ClassInstanceExpr copy() { try { ClassInstanceExpr node = (ClassInstanceExpr)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 ClassInstanceExpr fullCopy() { ClassInstanceExpr res = (ClassInstanceExpr)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 139 public void accessControl() { super.accessControl(); if(type().isAbstract()) error("Can not instantiate abstract class " + type().fullName()); if(!decl().accessibleFrom(hostType())) error("constructor " + decl().signature() + " is not accessible"); } // Declared in ExceptionHandling.jrag at line 253 protected boolean reachedException(TypeDecl catchType) { ConstructorDecl decl = decl(); for(int i = 0; i < decl.getNumException(); i++) { TypeDecl exceptionType = decl.getException(i).type(); if(catchType.mayCatch(exceptionType)) return true; } return super.reachedException(catchType); } // Declared in LookupType.jrag at line 326 public SimpleSet keepInnerClasses(SimpleSet c) { SimpleSet newSet = SimpleSet.emptySet; for(Iterator iter = c.iterator(); iter.hasNext(); ) { TypeDecl t = (TypeDecl)iter.next(); if(t.isInnerType() && t.isClassDecl()) { newSet = newSet.add(c); } } return newSet; } // Declared in NameCheck.jrag at line 137 public void nameCheck() { super.nameCheck(); if(decls().isEmpty()) error("can not instantiate " + type().typeName() + " no matching constructor found in " + type().typeName()); else if(decls().size() > 1 && validArgs()) { error("several most specific constructors found"); for(Iterator iter = decls().iterator(); iter.hasNext(); ) { error(" " + ((ConstructorDecl)iter.next()).signature()); } } } // Declared in NodeConstructors.jrag at line 82 public ClassInstanceExpr(Access type, List args) { this(type, args, new Opt()); } // Declared in PrettyPrint.jadd at line 345 public void toString(StringBuffer s) { s.append("new "); getAccess().toString(s); s.append("("); if(getNumArg() > 0) { getArg(0).toString(s); for(int i = 1; i < getNumArg(); i++) { s.append(", "); getArg(i).toString(s); } } s.append(")"); if(hasTypeDecl()) { TypeDecl decl = getTypeDecl(); s.append(" {\n"); indent++; for(int i = 0; i < decl.getNumBodyDecl(); i++) { if(!(decl.getBodyDecl(i) instanceof ConstructorDecl)) decl.getBodyDecl(i).toString(s); } indent--; s.append(indent()); s.append("}"); } } // Declared in TypeCheck.jrag at line 434 public void typeCheck() { if(isQualified() && qualifier().isTypeAccess() && !qualifier().type().isUnknown()) error("*** The expression in a qualified class instance expr must not be a type name"); // 15.9 if(isQualified() && !type().isInnerClass() && !((ClassDecl)type()).superclass().isInnerClass() && !type().isUnknown()) { error("*** Qualified class instance creation can only instantiate inner classes and their anonymous subclasses"); } if(!type().isClassDecl()) { error("*** Can only instantiate classes, which " + type().typeName() + " is not"); } typeCheckEnclosingInstance(); typeCheckAnonymousSuperclassEnclosingInstance(); } // Declared in TypeCheck.jrag at line 448 public void typeCheckEnclosingInstance() { TypeDecl C = type(); if(!C.isInnerClass()) return; TypeDecl enclosing = null; if(C.isAnonymous()) { if(noEnclosingInstance()) { enclosing = null; } else { enclosing = hostType(); } } else if(C.isLocalClass()) { if(C.inStaticContext()) { enclosing = null; } else if(noEnclosingInstance()) { enclosing = unknownType(); } else { TypeDecl nest = hostType(); while(nest != null && !nest.instanceOf(C.enclosingType())) nest = nest.enclosingType(); enclosing = nest; } } else if(C.isMemberType()) { if(!isQualified()) { if(noEnclosingInstance()) { error("No enclosing instance to initialize " + C.typeName() + " with"); //System.err.println("ClassInstanceExpr: Non qualified MemberType " + C.typeName() + " is in a static context when instantiated in " + this); enclosing = unknownType(); } else { TypeDecl nest = hostType(); while(nest != null && !nest.instanceOf(C.enclosingType())) nest = nest.enclosingType(); enclosing = nest == null ? unknownType() : nest; } } else { enclosing = enclosingInstance(); } } if(enclosing != null && !enclosing.instanceOf(type().enclosingType())) { String msg = enclosing == null ? "None" : enclosing.typeName(); error("*** Can not instantiate " + type().typeName() + " with the enclosing instance " + msg + " due to incorrect enclosing instance"); } else if(!isQualified() && C.isMemberType() && inExplicitConstructorInvocation() && enclosing == hostType()) { error("*** The innermost enclosing instance of type " + enclosing.typeName() + " is this which is not yet initialized here."); } } // Declared in TypeCheck.jrag at line 521 public void typeCheckAnonymousSuperclassEnclosingInstance() { if(type().isAnonymous() && ((ClassDecl)type()).superclass().isInnerType()) { TypeDecl S = ((ClassDecl)type()).superclass(); if(S.isLocalClass()) { if(S.inStaticContext()) { } else if(noEnclosingInstance()) { error("*** No enclosing instance to class " + type().typeName() + " due to static context"); } else if(inExplicitConstructorInvocation()) error("*** No enclosing instance to superclass " + S.typeName() + " of " + type().typeName() + " since this is not initialized yet"); } else if(S.isMemberType()) { if(!isQualified()) { // 15.9.2 2nd paragraph if(noEnclosingInstance()) { error("*** No enclosing instance to class " + type().typeName() + " due to static context"); } else { TypeDecl nest = hostType(); while(nest != null && !nest.instanceOf(S.enclosingType())) nest = nest.enclosingType(); if(nest == null) { error("*** No enclosing instance to superclass " + S.typeName() + " of " + type().typeName()); } else if(inExplicitConstructorInvocation()) { error("*** No enclosing instance to superclass " + S.typeName() + " of " + type().typeName() + " since this is not initialized yet"); } } } } } } // Declared in java.ast at line 3 // Declared in java.ast line 34
public ClassInstanceExpr() { super();
setChild(new List(), 1);
setChild(new Opt(), 2);
} // Declared in java.ast at line 12
// Declared in java.ast line 34 public ClassInstanceExpr(Access p0, List<Expr> p1, Opt<TypeDecl> p2) { setChild(p0, 0); setChild(p1, 1); setChild(p2, 2); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -