1 /**********************************************************************/
2 /* Array Descriptor class for J2CPS */
4 /* (c) copyright QUT */
5 /**********************************************************************/
8 import java
.io
.DataOutputStream
;
9 import java
.io
.IOException
;
11 public class ArrayDesc
extends TypeDesc
{
13 static ArrayDesc
[] arrayTypes
= new ArrayDesc
[10];
14 static int numArrayTypes
= 0;
19 TypeDesc ultimateElemType
;
20 public int elemTypeFixUp
= 0;
22 public ArrayDesc(int eF
) {
23 typeOrd
= TypeDesc
.arrT
;
24 name
= "ARRAY OF " + eF
;
29 public ArrayDesc (int dimNum
,TypeDesc eType
,boolean makePtr
) {
32 for (int i
=1; i
< dimNum
; i
++) {
33 name
= name
+ "ARRAY OF ";
35 name
= name
+ eType
.name
;
36 typeOrd
= TypeDesc
.arrT
;
39 ultimateElemType
= eType
;
41 ptrType
= new PtrDesc(this);
45 public void SetPtrType(PtrDesc ptrTy
) {
49 public static TypeDesc
GetArrayType(String sig
,int start
,boolean getPtr
) {
51 if (sig
.charAt(start
) != '[') {
52 System
.out
.println(sig
.substring(start
) + " is not an array type!");
55 int dimCount
= 0, ix
= start
;
56 while (sig
.charAt(ix
) == '[') { ix
++; dimCount
++; }
57 uEType
= TypeDesc
.GetType(sig
,ix
);
58 ArrayDesc thisArr
= FindArrayType(dimCount
,uEType
,getPtr
);
60 ArrayDesc arrD
= thisArr
;
61 while (dimCount
> 1) {
62 arrD
.elemType
= FindArrayType(dimCount
,uEType
,true);
63 if (arrD
.elemType
instanceof ArrayDesc
) {
64 arrD
= (ArrayDesc
)arrD
.elemType
;
68 arrD
.elemType
= uEType
;
69 if (getPtr
) { return thisArr
.ptrType
; } else { return thisArr
; }
72 public static ArrayDesc
FindArrayType(int dimNum
, TypeDesc eType
,
74 for (int i
=0; i
< numArrayTypes
; i
++) {
75 if ((arrayTypes
[i
].dim
== dimNum
) &&
76 (arrayTypes
[i
].ultimateElemType
== eType
)) {
77 if (mkPtr
&& arrayTypes
[i
].ptrType
== null) {
78 arrayTypes
[i
].ptrType
= new PtrDesc(arrayTypes
[i
]);
83 arrayTypes
[numArrayTypes
++] = new ArrayDesc(dimNum
,eType
,mkPtr
);
84 if (numArrayTypes
== arrayTypes
.length
) {
85 ArrayDesc
[] temp
= arrayTypes
;
86 arrayTypes
= new ArrayDesc
[numArrayTypes
* 2];
87 System
.arraycopy(temp
, 0, arrayTypes
, 0, numArrayTypes
);
89 return arrayTypes
[numArrayTypes
-1];
93 public String
getTypeMnemonic() {
94 return 'a' + elemType
.getTypeMnemonic();
98 public void writeType(DataOutputStream out
, PackageDesc thisPack
)
100 // Array = TypeHeader arrSy TypeOrd (Byte | Number | ) endAr.
101 out
.writeByte(SymbolFile
.arrSy
);
102 SymbolFile
.writeTypeOrd(out
,elemType
);
103 out
.writeByte(SymbolFile
.endAr
);
106 public void AddImport(ClassDesc thisClass
) {
107 if (ultimateElemType
instanceof ClassDesc
) {
108 thisClass
.AddImport((ClassDesc
)ultimateElemType
);