1 (* ==================================================================== *)
2 (* *)
3 (* SymFileRW: Symbol-file reading and writing for GPCP. *)
4 (* Copyright (c) John Gough 1999, 2000. *)
5 (* *)
6 (* ==================================================================== *)
10 IMPORT
11 GPCPcopyright,
12 RTS,
13 Error,
14 GPBinFiles,
15 FileNames,
16 LitValue,
17 CompState,
20 (* ========================================================================= *
21 // Collected syntax ---
22 //
23 // SymFile = Header [String (falSy | truSy | <other attribute>)]
24 // [ VersionName ]
25 // {Import | Constant | Variable | Type | Procedure}
26 // TypeList Key.
27 // -- optional String is external name.
28 // -- falSy ==> Java class
29 // -- truSy ==> Java interface
30 // -- others ...
31 // Header = magic modSy Name.
32 // VersionName= numSy longint numSy longint numSy longint.
33 // -- mj# mn# bld rv# 8xbyte extract
34 // Import = impSy Name [String] Key.
35 // -- optional string is explicit external name of class
36 // Constant = conSy Name Literal.
37 // Variable = varSy Name TypeOrd.
38 // Type = typSy Name TypeOrd.
39 // Procedure = prcSy Name [String] FormalType.
40 // -- optional string is explicit external name of procedure
41 // Method = mthSy Name byte byte TypeOrd [String] FormalType.
42 // -- optional string is explicit external name of method
43 // FormalType = [retSy TypeOrd] frmSy {parSy byte TypeOrd} endFm.
44 // -- optional phrase is return type for proper procedures
45 // TypeOrd = ordinal.
46 // TypeHeader = tDefS Ord [fromS Ord Name].
47 // -- optional phrase occurs if:
48 // -- type not from this module, i.e. indirect export
49 // TypeList = start { Array | Record | Pointer | ProcType } close.
50 // Array = TypeHeader arrSy TypeOrd (Byte | Number | <empty>) endAr.
51 // -- nullable phrase is array length for fixed length arrays
52 // Vector = TypeHeader vecSy TypeOrd endAr.
53 // Pointer = TypeHeader ptrSy TypeOrd.
54 // EventType = TypeHeader evtSy FormalType.
55 // ProcType = TypeHeader pTpSy FormalType.
56 // Record = TypeHeader recSy recAtt [truSy | falSy]
57 // [basSy TypeOrd] [ iFcSy {basSy TypeOrd}]
58 // {Name TypeOrd} {OtherStuff} endRc.
59 // -- truSy ==> is an extension of external interface
60 // -- falSy ==> is an extension of external class
61 // -- basSy option defines base type, if not ANY / j.l.Object
62 // OtherStuff = Method | Procedure | Variable | Constant.
63 // Enum = TypeHeader eTpSy { Constant } endRc.
64 // Name = namSy byte UTFstring.
65 // Literal = Number | String | Set | Char | Real | falSy | truSy.
66 // Byte = bytSy byte.
67 // String = strSy UTFstring.
68 // Number = numSy longint.
69 // Real = fltSy ieee-double.
70 // Set = setSy integer.
71 // Key = keySy integer..
72 // Char = chrSy unicode character.
73 //
74 // Notes on the syntax:
75 // All record types must have a Name field, even though this is often
76 // redundant. The issue is that every record type (including those that
77 // are anonymous in CP) corresponds to a IR class, and the definer
78 // and the user of the class _must_ agree on the IR name of the class.
79 // The same reasoning applies to procedure types, which must have equal
80 // interface names in all modules.
81 // ======================================================================== *)
83 CONST
97 CONST
101 VAR
111 (* ============================================================ *)
112 (* ======== Various reading utility procedures ======= *)
113 (* ============================================================ *)
116 BEGIN
120 (* ======================================= *)
123 CONST
131 BEGIN
133 (*
134 * bNm is the length in bytes of the UTF8 representation
135 *)
137 (*
138 * Worst case the number of chars will equal byte-number.
139 *)
151 ELSE
162 ELSE
165 ELSE
168 ELSE
176 (* ======================================= *)
179 BEGIN
183 (* ======================================= *)
187 (* overflow checking off here *)
191 (* ======================================= *)
197 (* overflow checking off here *)
205 (* ======================================= *)
209 BEGIN
214 (* ======================================= *)
218 BEGIN
221 ELSE
227 (* ============================================================ *)
228 (* ======== Symbol File Reader ======= *)
229 (* ============================================================ *)
232 BEGIN
237 (* ======================================= *)
240 BEGIN
243 | namSy :
246 | strSy :
250 | bytSy :
254 | numSy :
256 | fltSy :
258 | chrSy :
264 (* ======================================= *)
267 BEGIN
279 VAR
281 BEGIN
293 (* ======================================= *)
296 BEGIN
300 ELSE
305 (* ======================================= *)
309 (*
310 // FormalType = [retSy TypeOrd] frmSy {parSy byte TypeOrd} endFm.
311 // -- optional phrase is return type for proper procedures
312 *)
313 VAR
315 BEGIN
327 (* ============================================ *)
330 (* TypeList = start { Array | Record | Pointer | ProcType } close. *)
331 (* TypeHeader = tDefS Ord [fromS Ord Name]. *)
332 VAR
335 BEGIN
342 (* Get type info. *)
371 (* mthSy Name byte byte TypeOrd [String] FormalType. *)
403 (* ============================================ *)
406 (*
407 // SymFile = Header [String (falSy | truSy | <others>)]
408 // {Import | Constant | Variable | Type | Procedure}
409 // TypeList Key.
410 // Header = magic modSy Name.
411 //
412 *)
413 VAR
417 BEGIN
421 (* normal case, nothing to do *)
422 ELSE
439 ELSE
446 (* ignore major, minor and get next symbol *)
448 (* ignore build, revision and get next symbol *)
450 (* ignore assembly publickeytoken and get next symbol *)
454 LOOP
477 ELSE
484 BEGIN
488 (* ============================================================ *)
489 BEGIN
491 (* ============================================================ *)