00001 package edu.ksu.cis.bandera.jjjc.symboltable;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import java.lang.reflect.Modifier;
00036 import edu.ksu.cis.bandera.jjjc.exception.*;
00037
00038 public class ArrayType extends ReferenceType {
00039 public final Type baseType;
00040 public int nDimensions;
00041 public Field length;
00042
00043
00044
00045
00046
00047 public ArrayType(Type baseType, int nDimensions) {
00048 this.baseType = baseType;
00049 this.nDimensions = nDimensions;
00050 name = baseType.getName();
00051 try {
00052 length = new Field(new Name("length"), IntType.TYPE);
00053 length.modifiers = Modifier.PUBLIC | Modifier.FINAL;
00054 length.isArrayLength = true;
00055 length.arrayType = this;
00056 } catch (InvalidNameException e) {};
00057 }
00058
00059
00060
00061
00062 public String getFullyQualifiedName() {
00063 StringBuffer result = new StringBuffer(name.toString());
00064 for (int i = 0; i < nDimensions; i++) {
00065 result.append("[]");
00066 }
00067
00068 return result.toString();
00069 }
00070
00071
00072
00073
00074 public Name getName() {
00075 return name;
00076 }
00077
00078
00079
00080
00081
00082 public boolean isValidNarrowingConversion(Type otherType){
00083 if ((otherType instanceof ArrayType) && (baseType instanceof ReferenceType)) {
00084 ArrayType otherArrayType = (ArrayType) otherType;
00085 return (otherArrayType.baseType instanceof ReferenceType) && (this.nDimensions == otherArrayType.nDimensions)
00086 && (baseType.isValidNarrowingConversion(otherArrayType.baseType));
00087 } else return false;
00088 }
00089
00090
00091
00092
00093
00094 public boolean isValidWideningConversion(Type otherType) {
00095 if ("java.lang.Object".equals(otherType.getFullyQualifiedName()) ||
00096 "java.lang.Cloneable".equals(otherType.getFullyQualifiedName()))
00097 return true;
00098 else if ((otherType instanceof ArrayType) && (baseType instanceof ReferenceType)) {
00099 ArrayType otherArrayType = (ArrayType) otherType;
00100 return (otherArrayType.baseType instanceof ReferenceType) && (this.nDimensions == otherArrayType.nDimensions)
00101 && (baseType.isValidWideningConversion(otherArrayType.baseType));
00102 } else return false;
00103 }
00104 }