DEADSOFTWARE

Remove batch
[gpcp-linux.git] / J2CPS / ArrayDesc.java
1 /**********************************************************************/
2 /* Array Descriptor class for J2CPS */
3 /* */
4 /* (c) copyright QUT */
5 /**********************************************************************/
6 package J2CPS;
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;
16 TypeDesc elemType;
17 PtrDesc ptrType;
18 int dim = 1;
19 TypeDesc ultimateElemType;
20 public int elemTypeFixUp = 0;
22 public ArrayDesc(int eF) {
23 typeOrd = TypeDesc.arrT;
24 name = "ARRAY OF " + eF;
25 elemTypeFixUp = eF;
26 writeDetails = true;
27 }
29 public ArrayDesc (int dimNum,TypeDesc eType,boolean makePtr) {
30 name = "ARRAY OF ";
31 writeDetails = true;
32 for (int i=1; i < dimNum; i++) {
33 name = name + "ARRAY OF ";
34 }
35 name = name + eType.name;
36 typeOrd = TypeDesc.arrT;
37 dim = dimNum;
38 elemType = eType;
39 ultimateElemType = eType;
40 if (makePtr) {
41 ptrType = new PtrDesc(this);
42 }
43 }
45 public void SetPtrType(PtrDesc ptrTy) {
46 ptrType = ptrTy;
47 }
49 public static TypeDesc GetArrayType(String sig,int start,boolean getPtr) {
50 TypeDesc uEType;
51 if (sig.charAt(start) != '[') {
52 System.out.println(sig.substring(start) + " is not an array type!");
53 System.exit(1);
54 }
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);
59 dimCount--;
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;
65 }
66 dimCount--;
67 }
68 arrD.elemType = uEType;
69 if (getPtr) { return thisArr.ptrType; } else { return thisArr; }
70 }
72 public static ArrayDesc FindArrayType(int dimNum, TypeDesc eType,
73 boolean mkPtr) {
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]);
79 }
80 return arrayTypes[i];
81 }
82 }
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);
88 }
89 return arrayTypes[numArrayTypes-1];
90 }
92 @Override
93 public String getTypeMnemonic() {
94 return 'a' + elemType.getTypeMnemonic();
95 }
97 @Override
98 public void writeType(DataOutputStream out, PackageDesc thisPack)
99 throws IOException {
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);