1 /**********************************************************************/
2 /* Symbol File class for J2CPS */
4 /* (c) copyright QUT */
5 /**********************************************************************/
9 import java
.util
.ArrayList
;
13 /************************************************************************/
14 /* Symbol file reading/writing */
15 /************************************************************************/
16 // Collected syntax ---
18 // SymFile = Header [String (falSy | truSy)]
19 // {Import | Constant | Variable | Type | Procedure}
21 // Header = magic modSy Name.
22 // Import = impSy Name [String] Key.
23 // Constant = conSy Name Literal.
24 // Variable = varSy Name TypeOrd.
25 // Type = typSy Name TypeOrd.
26 // Procedure = prcSy Name [String] [truSy] FormalType.
27 // Method = mthSy Name Byte Byte TypeOrd [String] FormalType.
28 // FormalType = [retSy TypeOrd] frmSy {parSy Byte TypeOrd} endFm.
30 // TypeHeader = tDefS Ord [fromS Ord Name].
31 // TypeList = start {Array | Record | Pointer | ProcType |
32 // NamedType | Enum} close.
33 // Array = TypeHeader arrSy TypeOrd (Byte | Number | ) endAr.
34 // Pointer = TypeHeader ptrSy TypeOrd.
35 // ProcType = TypeHeader pTpSy FormalType.
36 // EventType = TypeHeader evtSy FormalType.
37 // Record = TypeHeader recSy recAtt [truSy | falSy] [basSy TypeOrd]
38 // [iFcSy basSy TypeOrd {basSy TypeOrd}]
39 // {Name TypeOrd} {Method} {Statics} endRc.
40 // Statics = ( Constant | Variable | Procedure ).
41 // Enum = TypeHeader eTpSy { Constant } endRc.
42 // NamedType = TypeHeader.
43 // Name = namSy byte UTFstring.
44 // Literal = Number | String | Set | Char | Real | falSy | truSy.
46 // String = strSy UTFstring.
47 // Number = numSy java.lang.long.
48 // Real = fltSy java.lang.double.
49 // Set = setSy java.lang.int.
50 // Key = keySy java.lang.int.
51 // Char = chrSy java.lang.char.
53 // Notes on the syntax:
54 // All record types must have a Name field, even though this is often
55 // redundant. The issue is that every record type (including those that
56 // are anonymous in CP) corresponds to a Java class, and the definer
57 // and the user of the class _must_ agree on the JVM name of the class.
58 // The same reasoning applies to procedure types, which must have equal
59 // interface names in all modules.
62 static final String
[] mthAtt
= {"", ",NEW", ",ABSTRACT", ",NEW,ABSTRACT",
63 ",EMPTY", ",NEW,EMPTY",
64 ",EXTENSIBLE", ",NEW,EXTENSIBLE"};
65 static final String
[] recAtt
= {"RECORD ", "ABSTRACT RECORD ",
66 "LIMITED RECORD ", "EXTENSIBLE RECORD "};
67 static final String
[] mark
= {"", "*", "-", "!"};
68 static final String
[] varMark
= {"", "IN", "OUT", "VAR"};
70 private static final String spaces
= " ";
71 private static final String recEndSpace
= " ";
72 private static final char qSepCh
= '/';
74 static final int modSy
= (int) 'H';
75 static final int namSy
= (int) '$';
76 static final int bytSy
= (int) '\\';
77 static final int numSy
= (int) '#';
78 static final int chrSy
= (int) 'c';
79 static final int strSy
= (int) 's';
80 static final int fltSy
= (int) 'r';
81 static final int falSy
= (int) '0';
82 static final int truSy
= (int) '1';
83 static final int impSy
= (int) 'I';
84 static final int setSy
= (int) 'S';
85 static final int keySy
= (int) 'K';
86 static final int conSy
= (int) 'C';
87 static final int typSy
= (int) 'T';
88 static final int tDefS
= (int) 't';
89 static final int prcSy
= (int) 'P';
90 static final int retSy
= (int) 'R';
91 static final int mthSy
= (int) 'M';
92 static final int varSy
= (int) 'V';
93 static final int parSy
= (int) 'p';
94 static final int iFcSy
= (int) '~';
96 static final int start
= (int) '&';
97 static final int close
= (int) '!';
99 static final int recSy
= (int) '{';
100 static final int endRc
= (int) '}';
101 static final int frmSy
= (int) '(';
102 static final int fromS
= (int) '@';
103 static final int endFm
= (int) ')';
104 static final int arrSy
= (int) '[';
105 static final int endAr
= (int) ']';
106 static final int pTpSy
= (int) '%';
107 static final int evtSy
= (int) 'v';
108 static final int ptrSy
= (int) '^';
109 static final int basSy
= (int) '+';
110 static final int eTpSy
= (int) 'e';
112 static final int magic
= 0xdeadd0d0;
114 static final int prvMode
= 0;
115 static final int pubMode
= 1;
116 static final int rdoMode
= 2;
117 static final int protect
= 3;
119 private static final int initTypeListSize
= 128;
120 public static TypeDesc
[] typeList
= new TypeDesc
[initTypeListSize
];
121 private static int nextType
= TypeDesc
.ordT
;
122 private static int tListIx
= 0;
123 private static int sSym
= 0;
124 private static int acc
= 0;
125 private static String name
;
126 private static int iVal
;
127 private static long lVal
;
128 private static int tOrd
;
129 private static char cVal
;
130 private static double dVal
;
131 private static DataInputStream in
;
133 // Symbol file writing
135 static void writeName(DataOutputStream out
,int access
, String name
)
137 out
.writeByte(namSy
);
138 if (ConstantPool
.isPublic(access
)) { out
.writeByte(pubMode
); }
139 else if (ConstantPool
.isProtected(access
)) { out
.writeByte(protect
); }
140 else /* if (ConstantPool.isPrivate(access)) */ { out
.writeByte(prvMode
); }
144 static void writeString(DataOutputStream out
,String str
) throws IOException
{
145 out
.writeByte(strSy
);
149 static void writeLiteral(DataOutputStream out
,Object val
) throws IOException
{
150 if (val
instanceof String
) {
151 writeString(out
,(String
) val
);
152 } else if (val
instanceof Integer
) {
153 out
.writeByte(numSy
);
154 out
.writeLong(((Integer
)val
).longValue());
155 } else if (val
instanceof Long
) {
156 out
.writeByte(numSy
);
157 out
.writeLong(((Long
)val
).longValue());
158 } else if (val
instanceof Float
) {
159 out
.writeByte(fltSy
);
160 out
.writeDouble(((Float
)val
).doubleValue());
161 } else if (val
instanceof Double
) {
162 out
.writeByte(fltSy
);
163 out
.writeDouble(((Double
)val
).doubleValue());
165 System
.out
.println("Unknown constant type");
170 public static void writeOrd(DataOutputStream out
,int i
) throws IOException
{
173 throw new IOException();
177 } else if (i
<= 0x7fff) {
178 out
.writeByte(128 + i
% 128);
179 out
.writeByte(i
/ 128);
181 throw new IOException();
185 private static void InsertType(TypeDesc ty
) {
186 if (ty
.outTypeNum
> 0) { return; }
187 ty
.outTypeNum
= nextType
++;
188 if (tListIx
>= typeList
.length
) {
189 TypeDesc
[] tmp
= new TypeDesc
[typeList
.length
+ initTypeListSize
];
190 System
.arraycopy(typeList
, 0, tmp
, 0, typeList
.length
);
193 typeList
[tListIx
++] = ty
;
196 public static void AddType(TypeDesc ty
) {
198 if (!ty
.writeDetails
) { return; }
199 if (ty
instanceof ClassDesc
) {
200 ClassDesc aClass
= (ClassDesc
)ty
;
201 if (aClass
.outBaseTypeNum
> 0) { return; }
202 aClass
.outBaseTypeNum
= nextType
++;
203 if (aClass
.superClass
!= null) {
204 aClass
.superClass
.writeDetails
= true;
205 AddType(aClass
.superClass
);
207 if (aClass
.isInterface
) {
208 for (int i
=0; i
< aClass
.interfaces
.length
; i
++) {
209 aClass
.interfaces
[i
].writeDetails
= true;
210 AddType(aClass
.interfaces
[i
]);
213 } else if (ty
instanceof PtrDesc
) {
214 ty
= ((PtrDesc
)ty
).boundType
;
215 if (ty
.outTypeNum
== 0) { AddType(ty
); }
216 } else if (ty
instanceof ArrayDesc
) {
217 ty
= ((ArrayDesc
)ty
).elemType
;
218 while (ty
instanceof ArrayDesc
) {
219 ArrayDesc aTy
= (ArrayDesc
)ty
;
220 if (aTy
.ptrType
.outTypeNum
== 0) { InsertType(aTy
.ptrType
); }
221 if (aTy
.outTypeNum
== 0) { InsertType(aTy
); }
224 if (ty
.outTypeNum
== 0) { InsertType(ty
); }
228 static void writeTypeOrd(DataOutputStream out
,TypeDesc ty
)throws IOException
{
229 if (ty
.typeOrd
< TypeDesc
.ordT
) {
230 out
.writeByte(ty
.typeOrd
);
232 if (ty
.outTypeNum
== 0) { AddType(ty
); }
233 if (ty
.outTypeNum
== 0) {
234 System
.out
.println("ERROR: type has number 0 for type " + ty
.name
);
237 writeOrd(out
,ty
.outTypeNum
);
241 public static void WriteFormalType(MethodInfo m
,DataOutputStream out
)
243 if ((m
.retType
!= null) && (m
.retType
.typeOrd
!= 0)) {
244 out
.writeByte(retSy
);
245 writeTypeOrd(out
,m
.retType
);
247 out
.writeByte(frmSy
);
248 for (int i
=0; i
< m
.parTypes
.length
; i
++) {
249 out
.writeByte(parSy
);
250 if (m
.parTypes
[i
] instanceof ArrayDesc
) {
251 out
.writeByte(1); // array params are IN
253 out
.writeByte(0); // all other java parameters are value
255 writeTypeOrd(out
,m
.parTypes
[i
]);
257 out
.writeByte(endFm
);
260 public static void WriteSymbolFile(PackageDesc thisPack
) throws IOException
{
262 DataOutputStream out
= J2CPSFiles
.CreateSymFile(thisPack
.cpName
);
264 System
.out
.println("INFO: Creating symbol file " + thisPack
.cpName
);
267 out
.writeByte(modSy
);
268 writeName(out
,0,thisPack
.cpName
);
269 writeString(out
,thisPack
.javaName
);
270 out
.writeByte(falSy
); /* package is not an interface */
271 for (int i
=0; i
< thisPack
.imports
.size(); i
++) {
272 out
.writeByte(impSy
);
273 PackageDesc imp
= (PackageDesc
)thisPack
.imports
.get(i
);
275 writeName(out
,0,imp
.cpName
);
276 writeString(out
,imp
.javaName
);
277 out
.writeByte(keySy
);
280 for (int cNum
=0; cNum
< thisPack
.classes
.length
; cNum
++) {
281 ClassDesc thisClass
= thisPack
.classes
[cNum
];
282 if ((thisClass
!= null) && ConstantPool
.isPublic(thisClass
.access
)) {
283 thisClass
.writeDetails
= true;
284 out
.writeByte(typSy
);
285 writeName(out
,thisClass
.access
,thisClass
.objName
);
286 writeTypeOrd(out
,thisClass
);
289 out
.writeByte(start
);
290 for (int i
=0; i
< tListIx
; i
++) {
291 out
.writeByte(tDefS
);
292 writeOrd(out
,typeList
[i
].outTypeNum
);
293 typeList
[i
].writeType(out
,thisPack
);
295 out
.writeByte(close
);
296 out
.writeByte(keySy
);
298 thisPack
.ResetImports();
301 // Symbol file reading
303 private static void InsertType(int tNum
,TypeDesc ty
) {
304 if (tNum
>= typeList
.length
) {
305 int newLen
= 2 * typeList
.length
;
306 while (tNum
>= newLen
) { newLen
+= typeList
.length
; }
307 TypeDesc
[] tmp
= new TypeDesc
[newLen
];
308 System
.arraycopy(typeList
, 0, tmp
, 0, typeList
.length
);
315 private static int readOrd() throws IOException
{
316 int b1
= in
.readUnsignedByte();
317 if (b1
<= 0x7f) { return b1
; }
318 else { int b2
= in
.readByte();
319 return b1
- 128 + b2
* 128; }
322 private static void GetSym() throws IOException
{
323 sSym
= in
.readByte();
325 case namSy
: acc
= in
.readByte(); // fall through
326 case strSy
: name
= in
.readUTF(); break;
332 case basSy
: tOrd
= readOrd(); break;
333 case bytSy
: iVal
= in
.readByte(); break;
335 case setSy
: iVal
= in
.readInt(); break;
336 case numSy
: lVal
= in
.readLong(); break;
337 case fltSy
: dVal
= in
.readDouble(); break;
338 case chrSy
: cVal
= in
.readChar(); break;
360 default: char ch
= (char) sSym
;
361 System
.out
.println("Bad symbol file format." +ch
+" "+sSym
);
366 private static void Expect(int expSym
) throws IOException
{
367 if (expSym
!= sSym
) {
368 System
.out
.println("Error in symbol file: expecting " +
369 String
.valueOf((char) expSym
) + " got " +
370 String
.valueOf((char) sSym
));
376 private static void Check(int expSym
) {
377 if (expSym
!= sSym
) {
378 System
.out
.println("Error in symbol file: checking " +
379 String
.valueOf((char) expSym
) + " got " +
380 String
.valueOf((char) sSym
));
385 private static void SkipToEndRec(DataInputStream in
) throws IOException
{
386 while (sSym
!= endRc
) {
392 } else if (sSym
== varSy
) {
395 } else if (sSym
== conSy
) {
398 } else if (sSym
== prcSy
) {
400 } else if (sSym
== parSy
) {
403 } else if (sSym
== namSy
) {
411 private static int GetAccess() {
412 if (acc
== prvMode
) { return ConstantPool
.ACC_PRIVATE
; }
413 else if (acc
== pubMode
) { return ConstantPool
.ACC_PUBLIC
; }
414 else if (acc
== protect
) { return ConstantPool
.ACC_PROTECTED
; }
418 private static ClassDesc
GetClassDesc(PackageDesc thisPack
,String className
) {
419 ClassDesc aClass
= ClassDesc
.GetClassDesc(thisPack
.name
+ qSepCh
+
421 if (aClass
.fieldList
== null){ aClass
.fieldList
= new ArrayList(); }
422 if (aClass
.methodList
== null){ aClass
.methodList
= new ArrayList(); }
426 private static void GetConstant(ClassDesc cClass
) throws IOException
{
427 // Constant = conSy Name Literal.
428 // Literal = Number | String | Set | Char | Real | falSy | truSy.
432 String constName
= name
;
433 int fAcc
= GetAccess();
434 fAcc
= fAcc
+ ConstantPool
.ACC_STATIC
+ ConstantPool
.ACC_FINAL
;
437 case numSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.longT
);
438 val
= new Long(lVal
); break;
439 case strSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.strT
);
441 case setSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.setT
);
442 val
= new Integer(iVal
); break;
443 case chrSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.charT
);
444 val
= new Character(cVal
); break;
445 case fltSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.dbleT
);
446 val
= new Double(dVal
); break;
447 case falSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.boolT
);
449 case truSy
: typ
= TypeDesc
.GetBasicType(TypeDesc
.boolT
);
452 boolean ok
= cClass
.fieldList
.add(new FieldInfo(cClass
,fAcc
,constName
,typ
,val
));
456 private static void GetVar(ClassDesc vClass
) throws IOException
{
457 // Variable = varSy Name TypeOrd.
459 String varName
= name
;
460 int fAcc
= GetAccess();
462 FieldInfo f
= new FieldInfo(vClass
,fAcc
,varName
,null,null);
463 f
.typeFixUp
= readOrd();
464 vClass
.fieldList
.add(f
);
468 private static void GetType(PackageDesc thisPack
) throws IOException
{
469 // Type = typSy Name TypeOrd.
471 ClassDesc thisClass
= GetClassDesc(thisPack
,name
);
472 thisClass
.access
= GetAccess();
474 int tNum
= readOrd();
475 thisClass
.inTypeNum
= tNum
;
476 InsertType(tNum
,thisClass
);
480 private static void GetFormalType(ClassDesc thisClass
,MethodInfo thisMethod
)
482 // FormalType = [retSy TypeOrd] frmSy {parSy Byte TypeOrd} endFm.
483 int [] pars
= new int[20];
485 TypeDesc retType
= TypeDesc
.GetBasicType(TypeDesc
.noTyp
);
486 if (sSym
== retSy
) { thisMethod
.retTypeFixUp
= tOrd
; GetSym();}
488 while (sSym
!= endFm
) {
490 in
.readByte(); /* ignore par mode */
491 pars
[numPars
++] = readOrd();
495 thisMethod
.parFixUps
= new int[numPars
];
496 System
.arraycopy(pars
, 0, thisMethod
.parFixUps
, 0, numPars
);
500 private static void GetMethod(ClassDesc thisClass
) throws IOException
{
501 // Method = mthSy Name Byte Byte TypeOrd [String] FormalType.
506 int pAcc
= GetAccess();
507 int attr
= in
.readByte();
508 int recMode
= in
.readByte();
509 int cNum
= readOrd();
510 if (cNum
!= thisClass
.inTypeNum
) {
511 System
.err
.println("Method not part of THIS class!");
515 if (sSym
== strSy
) { jName
= name
; GetSym(); }
516 MethodInfo m
= new MethodInfo(thisClass
,nam
,jName
,pAcc
);
518 case 1 : if (!m
.isInitProc
) {
519 m
.accessFlags
+= ConstantPool
.ACC_FINAL
;
522 case 2 : m
.overridding
= true;
523 m
.accessFlags
+= (ConstantPool
.ACC_ABSTRACT
+
524 ConstantPool
.ACC_FINAL
);
526 case 3 : m
.accessFlags
+= (ConstantPool
.ACC_ABSTRACT
+
527 ConstantPool
.ACC_FINAL
);
529 case 6 : m
.overridding
= true;
533 GetFormalType(thisClass
,m
);
534 thisClass
.methodList
.add(m
);
535 thisClass
.scope
.put(m
.name
,m
);
538 private static void GetProc(ClassDesc pClass
) throws IOException
{
539 // Proc = prcSy Name [String] [truSy] FormalType.
542 String procName
= name
;
543 int pAcc
= GetAccess();
544 pAcc
= pAcc
+ ConstantPool
.ACC_STATIC
;
546 if (sSym
== strSy
) { jName
= name
; GetSym(); }
547 MethodInfo m
= new MethodInfo(pClass
,procName
,jName
,pAcc
);
548 if (sSym
== truSy
) { m
.isInitProc
= true; GetSym(); }
549 GetFormalType(pClass
,m
);
550 pClass
.methodList
.add(m
);
553 private static void ClearTypeList() {
554 for (int i
=0; i
< typeList
.length
; i
++) {
555 if (typeList
[i
] != null) {
556 if (typeList
[i
].typeOrd
>= TypeDesc
.specT
) {
557 typeList
[i
].inTypeNum
= 0;
558 typeList
[i
].outTypeNum
= 0;
560 if (typeList
[i
] instanceof ClassDesc
) {
561 ((ClassDesc
)typeList
[i
]).inBaseTypeNum
= 0;
562 ((ClassDesc
)typeList
[i
]).outBaseTypeNum
= 0;
563 ((ClassDesc
)typeList
[i
]).writeDetails
= false;
564 } else if (typeList
[i
] instanceof ArrayDesc
) {
565 ((ArrayDesc
)typeList
[i
]).elemTypeFixUp
= 0;
571 nextType
= TypeDesc
.ordT
;
574 private static void FixArrayElemType(ArrayDesc arr
) {
575 if (arr
.elemTypeFixUp
== 0) { return; }
576 TypeDesc elem
= GetFixUpType(arr
.elemTypeFixUp
);
577 if (elem
instanceof ArrayDesc
) {
578 FixArrayElemType((ArrayDesc
)elem
);
579 arr
.dim
= ((ArrayDesc
)elem
).dim
+ 1;
580 arr
.ultimateElemType
= ((ArrayDesc
)elem
).ultimateElemType
;
582 arr
.ultimateElemType
= elem
;
587 private static TypeDesc
GetFixUpType (int num
) {
588 if (num
< TypeDesc
.specT
) { return TypeDesc
.GetBasicType(num
); }
589 if (typeList
[num
] instanceof PtrDesc
) {
590 return ((PtrDesc
)typeList
[num
]).boundType
;
592 return typeList
[num
];
595 public static void ReadSymbolFile(File symFile
,PackageDesc thisPack
)
596 throws FileNotFoundException
, IOException
{
598 if (ClassDesc
.verbose
)
599 System
.out
.println("INFO: Reading symbol file " + symFile
.getName());
602 ClassDesc aClass
, impClass
;
604 FileInputStream fIn
= new FileInputStream(symFile
);
605 in
= new DataInputStream(fIn
);
606 if (in
.readInt() != magic
) {
607 System
.out
.println(symFile
.getName() + " is not a valid symbol file.");
612 if (!thisPack
.cpName
.equals(name
)) {
613 System
.out
.println("ERROR: Symbol file " + symFile
.getName() +
614 " does not contain MODULE " + thisPack
.cpName
+ ", it contains MODULE " +
620 if (!name
.equals(thisPack
.javaName
)) {
621 System
.out
.println("Wrong name in symbol file.");
626 System
.out
.println("ERROR: Java Package cannot be an interface.");
631 System
.err
.println("<" + symFile
.getName() +
632 "> NOT A SYMBOL FILE FOR A JAVA PACKAGE!");
635 while (sSym
!= start
) {
637 case impSy
: GetSym(); // name
641 PackageDesc pack
= PackageDesc
.getPackage(name
);
642 thisPack
.imports
.add(pack
);
649 case prcSy
: System
.out
.println("Symbol File is not from a java class");
652 case typSy
: GetType(thisPack
); break;
656 while (sSym
!= close
) {
659 String impModName
= null;
660 int impAcc
= 0, impModAcc
= 0;
662 int tNum
= tOrd
; GetSym();
663 if (tNum
> maxInNum
) { maxInNum
= tNum
; }
665 int impNum
= tOrd
- 1;
668 String impName
= name
;
673 impPack
= (PackageDesc
)thisPack
.imports
.get(impNum
);
675 impClass
= GetClassDesc(impPack
,impName
);
679 case arrSy
: ArrayDesc newArr
= null;
684 if (elemOrd
< typeList
.length
) {
685 if (elemOrd
< TypeDesc
.specT
) {
686 eTy
= TypeDesc
.GetBasicType(elemOrd
);
688 eTy
= typeList
[elemOrd
];
690 if ((eTy
!= null) && (eTy
instanceof PtrDesc
) &&
691 (((PtrDesc
)eTy
).boundType
!= null) &&
692 (((PtrDesc
)eTy
).boundType
instanceof ClassDesc
)) {
693 eTy
= ((PtrDesc
)eTy
).boundType
;
697 newArr
= ArrayDesc
.FindArrayType(1,eTy
,true);
699 newArr
= new ArrayDesc(elemOrd
);
701 if ((tNum
< typeList
.length
) && (typeList
[tNum
] != null)) {
702 PtrDesc desc
= (PtrDesc
) typeList
[tNum
];
703 if (desc
.inBaseTypeNum
!= tNum
) {
704 System
.out
.println("WRONG BASE TYPE FOR POINTER!");
708 newArr
.SetPtrType(desc
);
710 InsertType(tNum
,newArr
);
712 case ptrSy
: TypeDesc ty
= null;
713 if (impClass
!= null) {
714 InsertType(tNum
,impClass
);
717 ty
.inBaseTypeNum
= tOrd
;
719 } else if ((tNum
< typeList
.length
) &&
720 (typeList
[tNum
] != null) &&
721 (typeList
[tNum
] instanceof ClassDesc
)) {
724 ty
.inBaseTypeNum
= tOrd
;
727 ty
= new PtrDesc(tNum
,tOrd
);
729 if ((tOrd
< typeList
.length
) &&
730 (typeList
[tOrd
] != null)) {
731 ((PtrDesc
)ty
).Init(typeList
[tOrd
]);
736 case recSy
: if ((tNum
>= typeList
.length
) || (typeList
[tNum
] == null)||
737 (!(typeList
[tNum
] instanceof ClassDesc
))) {
738 /* cannot have record type that is not a base type
739 of a pointer in a java file */
741 "RECORD TYPE " + tNum
+ " IS NOT POINTER BASE TYPE!");
744 aClass
= (ClassDesc
) typeList
[tNum
];
746 aClass
.setRecAtt(acc
);
754 aClass
.isInterface
= true;
756 } else if (sSym
== falSy
) {
760 aClass
.superNum
= tOrd
;
765 aClass
.intNums
= new int[10];
767 while (sSym
== basSy
) {
768 if (aClass
.numInts
>= aClass
.intNums
.length
) {
769 int tmp
[] = new int[aClass
.intNums
.length
*2];
770 System
.arraycopy(aClass
.intNums
, 0, tmp
, 0, aClass
.intNums
.length
);
771 aClass
.intNums
= tmp
;
773 aClass
.intNums
[aClass
.numInts
] = tOrd
;
778 while (sSym
== namSy
) {
779 FieldInfo f
= new FieldInfo(aClass
,GetAccess(),name
,
781 f
.typeFixUp
= readOrd();
783 boolean ok
= aClass
.fieldList
.add(f
);
784 aClass
.scope
.put(f
.name
,f
);
786 while ((sSym
== mthSy
) || (sSym
== prcSy
) ||
787 (sSym
== varSy
) || (sSym
== conSy
)) {
789 case mthSy
: GetMethod(aClass
); break;
790 case prcSy
: GetProc(aClass
); break;
791 case varSy
: GetVar(aClass
); break;
792 case conSy
: GetConstant(aClass
); break;
798 case pTpSy
: System
.out
.println("CANNOT HAVE PROC TYPE IN JAVA FILE!");
800 case evtSy
:System
.out
.println("CANNOT HAVE EVENT TYPE IN JAVA FILE!");
802 case eTpSy
: System
.out
.println("CANNOT HAVE ENUM TYPE IN JAVA FILE!");
805 case close
: InsertType(tNum
,impClass
);
807 default : char ch
= (char) sSym
;
808 System
.out
.println("UNRECOGNISED TYPE!" + sSym
+ " " + ch
);
816 for (int i
= TypeDesc
.specT
; i
<= maxInNum
; i
++) {
817 if ((typeList
[i
] != null) && (typeList
[i
] instanceof ClassDesc
)) {
818 if (!((ClassDesc
)typeList
[i
]).read
) {
819 aClass
= (ClassDesc
)typeList
[i
];
820 if (aClass
.superNum
!= 0) {
821 aClass
.superClass
= (ClassDesc
)typeList
[aClass
.superNum
];
823 aClass
.interfaces
= new ClassDesc
[aClass
.numInts
];
824 for (int j
=0; j
< aClass
.numInts
; j
++) {
825 aClass
.interfaces
[j
] = (ClassDesc
) GetFixUpType(aClass
.intNums
[j
]);
828 if (aClass
.fieldList
== null) {
831 size
= aClass
.fieldList
.size();
833 aClass
.fields
= new FieldInfo
[size
];
834 for (int j
=0; j
< size
; j
++) {
835 aClass
.fields
[j
] = (FieldInfo
)aClass
.fieldList
.get(j
);
836 aClass
.fields
[j
].type
= GetFixUpType(aClass
.fields
[j
].typeFixUp
);
837 if (aClass
.fields
[j
].type
instanceof ClassDesc
) {
838 aClass
.AddImport((ClassDesc
)aClass
.fields
[j
].type
);
841 aClass
.fieldList
= null;
842 if (aClass
.methodList
== null) { size
= 0;
843 } else { size
= aClass
.methodList
.size(); }
844 aClass
.methods
= new MethodInfo
[size
];
845 for (int k
=0; k
< size
; k
++) {
846 aClass
.methods
[k
] = (MethodInfo
)aClass
.methodList
.get(k
);
847 aClass
.methods
[k
].retType
= GetFixUpType(
848 aClass
.methods
[k
].retTypeFixUp
);
849 if (aClass
.methods
[k
].retType
instanceof ClassDesc
) {
850 aClass
.AddImport((ClassDesc
)aClass
.methods
[k
].retType
);
852 aClass
.methods
[k
].parTypes
= new TypeDesc
[
853 aClass
.methods
[k
].parFixUps
.length
];
854 for (int j
=0; j
< aClass
.methods
[k
].parFixUps
.length
; j
++) {
855 aClass
.methods
[k
].parTypes
[j
] = GetFixUpType(
856 aClass
.methods
[k
].parFixUps
[j
]);
857 if (aClass
.methods
[k
].parTypes
[j
] instanceof ClassDesc
) {
858 aClass
.AddImport((ClassDesc
)aClass
.methods
[k
].parTypes
[j
]);
862 aClass
.methodList
= null;
866 } else if ((typeList
[i
] != null) && (typeList
[i
] instanceof ArrayDesc
)) {
867 FixArrayElemType((ArrayDesc
)typeList
[i
]);
868 } else if ((typeList
[i
] != null) && (typeList
[i
] instanceof PtrDesc
)) {
869 PtrDesc ptr
= (PtrDesc
)typeList
[i
];
870 if (ptr
.typeOrd
== TypeDesc
.arrPtr
) {
871 ptr
.Init(typeList
[ptr
.inBaseTypeNum
]);
873 } else if (typeList
[i
] != null) {
874 System
.out
.println("Type " + i
+ " " + typeList
[i
].name
+
875 " is NOT array or class");