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

📄 typeanalysis.jrag

📁 JDK1.4编译器前端
💻 JRAG
📖 第 1 页 / 共 2 页
字号:
      return getLeftOperand().type().binaryNumericPromotion(getRightOperand().type());    else if(getLeftOperand().type().isBoolean() && getRightOperand().type().isBoolean())      // 15.22.2      return typeBoolean();    return unknownType();  }    // 15.20.2  eq InstanceOfExpr.type() = typeBoolean();  // 15.25  eq ConditionalExpr.type() {    TypeDecl trueType = getTrueExpr().type();    TypeDecl falseType = getFalseExpr().type();        if(trueType == falseType) return trueType;        if(trueType.isNumericType() && falseType.isNumericType()) {      if(trueType.isByte() && falseType.isShort()) return falseType;      if(trueType.isShort() && falseType.isByte()) return trueType;      if((trueType.isByte() || trueType.isShort() || trueType.isChar()) &&          falseType.isInt() && getFalseExpr().isConstant() && getFalseExpr().representableIn(trueType))        return trueType;      if((falseType.isByte() || falseType.isShort() || falseType.isChar()) &&          trueType.isInt() && getTrueExpr().isConstant() && getTrueExpr().representableIn(falseType))        return falseType;      return trueType.binaryNumericPromotion(falseType);    }    else if(trueType.isBoolean() && falseType.isBoolean()) {      return trueType;    }    else if(trueType.isReferenceType() && falseType.isNull()) {      return trueType;    }    else if(trueType.isNull() && falseType.isReferenceType()) {      return falseType;    }    else if(trueType.isReferenceType() && falseType.isReferenceType()) {      if(trueType.assignConversionTo(falseType, null))        return falseType;      if(falseType.assignConversionTo(trueType, null))        return trueType;      return unknownType();    }    else      return unknownType();  }  eq ClassAccess.type() = lookupType("java.lang", "Class");}aspect TypeWideningAndIdentity {  syn lazy boolean TypeDecl.instanceOf(TypeDecl type);  eq TypeDecl.instanceOf(TypeDecl type) = type == this;  eq ClassDecl.instanceOf(TypeDecl type) = type.isSupertypeOfClassDecl(this);  eq InterfaceDecl.instanceOf(TypeDecl type) = type.isSupertypeOfInterfaceDecl(this);  eq ArrayDecl.instanceOf(TypeDecl type) = type.isSupertypeOfArrayDecl(this);  eq PrimitiveType.instanceOf(TypeDecl type) = type.isSupertypeOfPrimitiveType(this);  eq NullType.instanceOf(TypeDecl type) = type.isSupertypeOfNullType(this);  eq VoidType.instanceOf(TypeDecl type) = type.isSupertypeOfVoidType(this);  eq UnknownType.instanceOf(TypeDecl type) = true;  eq UnknownType.isSupertypeOfClassDecl(ClassDecl type) = true;  eq UnknownType.isSupertypeOfInterfaceDecl(InterfaceDecl type) = true;  eq UnknownType.isSupertypeOfArrayDecl(ArrayDecl type) = true;  eq UnknownType.isSupertypeOfPrimitiveType(PrimitiveType type) = true;  eq UnknownType.isSupertypeOfNullType(NullType type) = true;    syn boolean TypeDecl.isSupertypeOfClassDecl(ClassDecl type) = type == this;  eq ClassDecl.isSupertypeOfClassDecl(ClassDecl type) {    if(super.isSupertypeOfClassDecl(type))      return true;    return type.hasSuperclass() && type.superclass() != null && type.superclass().instanceOf(this);  }  eq InterfaceDecl.isSupertypeOfClassDecl(ClassDecl type) {    if(super.isSupertypeOfClassDecl(type))      return true;    for(Iterator iter = type.interfacesIterator(); iter.hasNext(); ) {      TypeDecl typeDecl = (TypeDecl)iter.next();      if(typeDecl.instanceOf(this))        return true;    }    return type.hasSuperclass() && type.superclass() != null && type.superclass().instanceOf(this);  }    syn boolean TypeDecl.isSupertypeOfInterfaceDecl(InterfaceDecl type) = type == this;  eq ClassDecl.isSupertypeOfInterfaceDecl(InterfaceDecl type) = isObject();  eq InterfaceDecl.isSupertypeOfInterfaceDecl(InterfaceDecl type) {    if(super.isSupertypeOfInterfaceDecl(type))      return true;    for(Iterator iter = type.superinterfacesIterator(); iter.hasNext(); ) {      TypeDecl superinterface = (TypeDecl)iter.next();      if(superinterface.instanceOf(this))        return true;    }    return false;  }  syn boolean TypeDecl.isSupertypeOfArrayDecl(ArrayDecl type) = this == type;  eq ClassDecl.isSupertypeOfArrayDecl(ArrayDecl type) {    if(super.isSupertypeOfArrayDecl(type))      return true;    return type.hasSuperclass() && type.superclass() != null && type.superclass().instanceOf(this);  }  eq InterfaceDecl.isSupertypeOfArrayDecl(ArrayDecl type) {    if(super.isSupertypeOfArrayDecl(type))      return true;    for(Iterator iter = type.interfacesIterator(); iter.hasNext(); ) {      TypeDecl typeDecl = (TypeDecl)iter.next();      if(typeDecl.instanceOf(this))        return true;    }    return false;  }    eq ArrayDecl.isSupertypeOfArrayDecl(ArrayDecl type) {    if(type.elementType().isPrimitive() && elementType().isPrimitive())      return type.dimension() == dimension() && type.elementType() == elementType();    return type.componentType().instanceOf(componentType());  }    syn boolean TypeDecl.isSupertypeOfPrimitiveType(PrimitiveType type) = type == this;  eq PrimitiveType.isSupertypeOfPrimitiveType(PrimitiveType type) {    if(super.isSupertypeOfPrimitiveType(type))      return true;    return type.hasSuperclass() && type.superclass().isPrimitive() && type.superclass().instanceOf(this);  }    syn boolean TypeDecl.isSupertypeOfNullType(NullType type) = false;  eq ReferenceType.isSupertypeOfNullType(NullType type) = true;  eq NullType.isSupertypeOfNullType(NullType type) = true;    syn boolean TypeDecl.isSupertypeOfVoidType(VoidType type) = false;  eq VoidType.isSupertypeOfVoidType(VoidType type) = true;}aspect NestedTypes {    eq CompilationUnit.getChild().enclosingType() = null;    eq TypeDecl.getBodyDecl().enclosingType() = this;  inh TypeDecl TypeDecl.enclosingType();  syn TypeDecl TypeDecl.topLevelType() {    if(isTopLevelType())      return this;    return enclosingType().topLevelType();  }  syn Stmt Expr.enclosingStmt() {    ASTNode node = this;    while(node != null && !(node instanceof Stmt))      node = node.getParent();    return (Stmt)node;  }  inh BodyDecl Expr.enclosingBodyDecl();  inh BodyDecl Stmt.enclosingBodyDecl();  inh BodyDecl TypeDecl.enclosingBodyDecl();  eq Program.getChild().enclosingBodyDecl() = null;  eq BodyDecl.getChild().enclosingBodyDecl() = this;    // 8  inh boolean TypeDecl.isNestedType();  eq CompilationUnit.getChild().isNestedType() = false;  eq TypeDecl.getBodyDecl().isNestedType() = true;  // 8  syn boolean TypeDecl.isTopLevelType() = !isNestedType();  // 8.5  inh boolean TypeDecl.isMemberType();  eq MemberClassDecl.getClassDecl().isMemberType() = true;  eq MemberInterfaceDecl.getInterfaceDecl().isMemberType() = true;  eq CompilationUnit.getTypeDecl().isMemberType() = false;  eq ClassInstanceExpr.getTypeDecl().isMemberType() = false;  eq Program.getChild().isMemberType() = false;    // 8.1.2  syn boolean TypeDecl.isInnerClass() = false;  eq ClassDecl.isInnerClass() = isNestedType() && !isStatic() && enclosingType().isClassDecl();  syn boolean TypeDecl.isInnerType() = (isLocalClass() || isAnonymous() || (isMemberType() && !isStatic())) && !inStaticContext();  syn boolean TypeDecl.isInnerTypeOf(TypeDecl typeDecl) = typeDecl == this || (isInnerType() && enclosingType().isInnerTypeOf(typeDecl));  inh boolean TypeDecl.isLocalClass();  eq CompilationUnit.getChild().isLocalClass() = false;  eq TypeDecl.getBodyDecl().isLocalClass() = false;  eq LocalClassDeclStmt.getClassDecl().isLocalClass() = true;    syn TypeDecl TypeDecl.withinBodyThatSubclasses(TypeDecl type) {    if(instanceOf(type))      return this;    if(!isTopLevelType())      return enclosingType().withinBodyThatSubclasses(type);    return null;  }    syn boolean TypeDecl.encloses(TypeDecl type) = type.enclosedBy(this);  syn boolean TypeDecl.enclosedBy(TypeDecl type) {    if(this == type)      return true;    if(isTopLevelType())      return false;    return enclosingType().enclosedBy(type);  }  eq CompilationUnit.getChild().hostPackage() = packageName();  inh String TypeDecl.hostPackage();  inh String BodyDecl.hostPackage();  inh String Expr.hostPackage();    syn TypeDecl TypeDecl.hostType() = this;  eq TypeDecl.getBodyDecl().hostType() = hostType();  eq TypeDecl.getModifiers().hostType() = hostType();  eq ClassInstanceExpr.getTypeDecl().hostType() = hostType();  eq PrimitiveType.getSuperClassAccess().hostType() = hostType();  eq ClassDecl.getSuperClassAccess().hostType() = hostType();  eq ClassDecl.getImplements().hostType() = hostType();  eq InterfaceDecl.getSuperInterfaceId().hostType() = hostType();    eq Program.getChild().hostType() = null;  eq CompilationUnit.getImportDecl().hostType() = null;    inh TypeDecl BodyDecl.hostType();  inh TypeDecl Expr.hostType();  inh TypeDecl Stmt.hostType();  inh TypeDecl VariableDeclaration.hostType();  inh TypeDecl ParameterDeclaration.hostType();}aspect SuperClasses {  public boolean ClassDecl.hasSuperclass() {    return !isObject();  }  public ClassDecl ClassDecl.superclass() {    if(isObject())      return null;    if(hasSuperClassAccess() && !isCircular() && getSuperClassAccess().type().isClassDecl())      return (ClassDecl)getSuperClassAccess().type();    return (ClassDecl)typeObject();  }    public boolean PrimitiveType.hasSuperclass() {    return !isObject();  }  syn TypeDecl PrimitiveType.superclass() = getSuperClassAccess().type();    public Iterator ClassDecl.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;          }        }      }    };  }    public Iterator InterfaceDecl.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;          }        }      }    };  }  }aspect Circularity {  inh lazy TypeDecl TypeDecl.unknownType();  syn lazy boolean TypeDecl.isCircular() circular [true] = false;  eq ClassDecl.isCircular() {    if(hasSuperClassAccess()) {      Access a = getSuperClassAccess().lastAccess();      while(a != null) {        if(a.type().isCircular())          return true;        a = (a.isQualified() && a.qualifier().isTypeAccess()) ? (Access)a.qualifier() : null;      }    }    for(int i = 0; i < getNumImplements(); i++) {      Access a = getImplements(i).lastAccess();      while(a != null) {        if(a.type().isCircular())          return true;        a = (a.isQualified() && a.qualifier().isTypeAccess()) ? (Access)a.qualifier() : null;      }    }    return false;  }  eq InterfaceDecl.isCircular() {    for(int i = 0; i < getNumSuperInterfaceId(); i++) {      Access a = getSuperInterfaceId(i).lastAccess();      while(a != null) {        if(a.type().isCircular())          return true;        a = (a.isQualified() && a.qualifier().isTypeAccess()) ? (Access)a.qualifier() : null;      }    }    return false;  }}

⌨️ 快捷键说明

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