ModuleParser.SymU 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. MODULE ModuleParser;
  2. IMPORT Strings, Files, Streams, Diagnostics, FoxScanner, KernelLog, Texts, TextUtilities;
  3. CONST
  4. Public* = 1;
  5. PublicRO* = 2;
  6. Private* = 3;
  7. Exclusive* = 1;
  8. Active* = 2;
  9. Safe* = 3;
  10. Priority* = 4;
  11. Unchecked* = 5;
  12. Uncooperative* = 6;
  13. HasExclusiveBlock* = 7;
  14. Overwrite* = 8;
  15. Overwritten* = 9;
  16. Interrupt* = 10;
  17. ExclusiveStr = \"EXCLUSIVE"\;
  18. ActiveStr = \"ACTIVE"\;
  19. RealtimeStr = \"REALTIME"\;
  20. SafeStr = \"SAFE"\;
  21. PriorityStr = \"PRIORITY"\;
  22. UncheckedStr = \"UNCHECKED"\;
  23. UncooperativeStr = \"UNCOOPERATIVE"\;
  24. NoPAFStr = \"NOPAF"\;
  25. FixedStr = \"FIXED"\;
  26. AlignedStr = \"FIXED"\;
  27. DynamicStr = \"DYNAMIC"\;
  28. InterruptStr = \"INTERRUPT"\;
  29. PCOffsetStr = \"PCOFFSET"\;
  30. TYPE
  31. InfoItem* = OBJECT
  32. VAR
  33. name*: Strings.String;
  34. pos*: LONGINT;
  35. END InfoItem;
  36. Node* = OBJECT
  37. VAR
  38. parent-: Node;
  39. PROCEDURE ^ GetModule*(): Module;
  40. PROCEDURE ^ & Init*(parent: Node);
  41. END Node;
  42. NodeList* = OBJECT (Node)
  43. VAR
  44. next*: NodeList;
  45. END NodeList;
  46. Import* = OBJECT (NodeList)
  47. VAR
  48. ident*, alias*, context*: InfoItem;
  49. END Import;
  50. Definition* = OBJECT (NodeList)
  51. VAR
  52. ident*: InfoItem;
  53. refines*: Qualident;
  54. procs*: ProcHead;
  55. END Definition;
  56. Type* = OBJECT (Node)
  57. VAR
  58. qualident*: Qualident;
  59. array*: Array;
  60. record*: Record;
  61. pointer*: Pointer;
  62. object*: Object;
  63. enum*: Enum;
  64. cell*: Cell;
  65. port*: Port;
  66. procedure*: Procedure;
  67. END Type;
  68. Array* = OBJECT (Node)
  69. VAR
  70. open*: BOOLEAN;
  71. len*: InfoItem;
  72. base*: Type;
  73. END Array;
  74. Record* = OBJECT (Node)
  75. VAR
  76. super*: Qualident;
  77. superPtr*: Record;
  78. fieldList*: FieldDecl;
  79. END Record;
  80. FieldDecl* = OBJECT (NodeList)
  81. VAR
  82. identList*: IdentList;
  83. type*: Type;
  84. END FieldDecl;
  85. Pointer* = OBJECT (Node)
  86. VAR
  87. type*: Type;
  88. END Pointer;
  89. Enum* = OBJECT (Node)
  90. VAR
  91. identList*: IdentList;
  92. END Enum;
  93. Port* = OBJECT (Node)
  94. END Port;
  95. Cell* = OBJECT (Node)
  96. VAR
  97. modifiers*: SET;
  98. declSeq*: DeclSeq;
  99. bodyPos-: LONGINT;
  100. formalPars*: FormalPars;
  101. PROCEDURE ^ FindProcDecl*(CONST name: ARRAY OF CHAR): ProcDecl;
  102. END Cell;
  103. Object* = OBJECT (Node)
  104. VAR
  105. super*, implements*: Qualident;
  106. superPtr*: Object;
  107. modifiers*: SET;
  108. declSeq*: DeclSeq;
  109. bodyPos-: LONGINT;
  110. PROCEDURE ^ FindProcDecl*(CONST name: ARRAY OF CHAR): ProcDecl;
  111. END Object;
  112. Procedure* = OBJECT (Node)
  113. VAR
  114. delegate*: BOOLEAN;
  115. formalPars*: FormalPars;
  116. END Procedure;
  117. DeclSeq* = OBJECT (NodeList)
  118. VAR
  119. constDecl*: ConstDecl;
  120. typeDecl*: TypeDecl;
  121. varDecl*: VarDecl;
  122. procDecl*: ProcDecl;
  123. PROCEDURE ^ FindProcDecl*(CONST name: ARRAY OF CHAR): ProcDecl;
  124. PROCEDURE ^ FindTypeDecl*(CONST name: ARRAY OF CHAR): TypeDecl;
  125. END DeclSeq;
  126. ConstDecl* = OBJECT (NodeList)
  127. VAR
  128. identDef*: IdentDef;
  129. constExpr*: Expr;
  130. expr*: InfoItem;
  131. END ConstDecl;
  132. TypeDecl* = OBJECT (NodeList)
  133. VAR
  134. identDef*: IdentDef;
  135. type*: Type;
  136. END TypeDecl;
  137. VarDecl* = OBJECT (NodeList)
  138. VAR
  139. identList*: IdentList;
  140. type*: Type;
  141. END VarDecl;
  142. ProcDecl* = OBJECT (NodeList)
  143. VAR
  144. head*: ProcHead;
  145. declSeq*: DeclSeq;
  146. bodyPos-: LONGINT;
  147. END ProcDecl;
  148. ProcHead* = OBJECT (NodeList)
  149. VAR
  150. sysFlag*: InfoItem;
  151. constructor*, inline*, operator*: BOOLEAN;
  152. modifiers*: SET;
  153. identDef*: IdentDef;
  154. formalPars*: FormalPars;
  155. END ProcHead;
  156. FormalPars* = OBJECT (Node)
  157. VAR
  158. fpSectionList*: FPSection;
  159. returnType*: Type;
  160. END FormalPars;
  161. FPSection* = OBJECT (NodeList)
  162. VAR
  163. var*, const*: BOOLEAN;
  164. identList*: IdentList;
  165. type*: Type;
  166. END FPSection;
  167. Expr* = OBJECT (NodeList)
  168. VAR
  169. simpleExprL*, simpleExprR*: SimpleExpr;
  170. relation*: InfoItem;
  171. END Expr;
  172. SimpleExpr* = OBJECT (NodeList)
  173. VAR
  174. sign*: InfoItem;
  175. termL*, termR*: Term;
  176. addOp*: AddOp;
  177. END SimpleExpr;
  178. Term* = OBJECT (NodeList)
  179. VAR
  180. factorL*, factorR*: Factor;
  181. mulOp*: MulOp;
  182. END Term;
  183. Factor* = OBJECT (NodeList)
  184. VAR
  185. designator*: Designator;
  186. number*, string*, nil*, bool*: InfoItem;
  187. set*: Element;
  188. expr*: Expr;
  189. factor*: Factor;
  190. END Factor;
  191. Designator* = OBJECT (NodeList)
  192. VAR
  193. qualident*: Qualident;
  194. ident*, arrowUp*: InfoItem;
  195. exprList*: Expr;
  196. END Designator;
  197. Qualident* = OBJECT (NodeList)
  198. VAR
  199. ident*: InfoItem;
  200. END Qualident;
  201. Element* = OBJECT (NodeList)
  202. VAR
  203. expr*, upToExpr*: Expr;
  204. END Element;
  205. MulOp* = OBJECT (NodeList)
  206. VAR
  207. op*: InfoItem;
  208. END MulOp;
  209. AddOp* = OBJECT (NodeList)
  210. VAR
  211. op*: InfoItem;
  212. END AddOp;
  213. IdentDef* = OBJECT
  214. VAR
  215. ident*: InfoItem;
  216. vis*: SHORTINT;
  217. initializer*: InfoItem;
  218. external*: Strings.String;
  219. END IdentDef;
  220. IdentList* = OBJECT (NodeList)
  221. VAR
  222. identDef*: IdentDef;
  223. END IdentList;
  224. Module* = OBJECT (Node)
  225. VAR
  226. ident*, context*: InfoItem;
  227. importList*: Import;
  228. modifiers*: SET;
  229. definitions*: Definition;
  230. declSeq*: DeclSeq;
  231. bodyPos-: LONGINT;
  232. hasError-: BOOLEAN;
  233. resolved*: BOOLEAN;
  234. PROCEDURE ^ FindTypeDecl*(CONST name: ARRAY OF CHAR): TypeDecl;
  235. PROCEDURE ^ FindImport*(CONST name: ARRAY OF CHAR): Import;
  236. END Module;
  237. Parser = OBJECT
  238. VAR
  239. symbol: FoxScanner.Symbol;
  240. scanner: FoxScanner.Scanner;
  241. hasError: BOOLEAN;
  242. PROCEDURE ^ & Init*(scanner: FoxScanner.Scanner);
  243. PROCEDURE ^ NextSymbol;
  244. PROCEDURE ^ ModuleP(VAR module: Module);
  245. PROCEDURE ^ ImportListP(import: Import);
  246. PROCEDURE ^ DefinitionP(definition: Definition);
  247. PROCEDURE ^ DeclSeqP(declSeq: DeclSeq);
  248. PROCEDURE ^ ConstDeclP(const: ConstDecl);
  249. PROCEDURE ^ TypeDeclP(type: TypeDecl);
  250. PROCEDURE ^ VarDeclP(var: VarDecl);
  251. PROCEDURE ^ ProcDeclP(proc: ProcDecl);
  252. PROCEDURE ^ ProcHeadP(head: ProcHead);
  253. PROCEDURE ^ SysFlag;
  254. PROCEDURE ^ OSAIrq;
  255. PROCEDURE ^ FormalParsP(pars: FormalPars);
  256. PROCEDURE ^ FPSectionP(fpSection: FPSection);
  257. PROCEDURE ^ TypeP(type: Type);
  258. PROCEDURE ^ ArrayP(array: Array);
  259. PROCEDURE ^ RecordP(record: Record);
  260. PROCEDURE ^ FieldListP(fieldList: FieldDecl);
  261. PROCEDURE ^ FieldDeclP(fieldDecl: FieldDecl);
  262. PROCEDURE ^ PointerP(pointer: Pointer);
  263. PROCEDURE ^ EnumP(enum: Enum);
  264. PROCEDURE ^ PortP(port: Port);
  265. PROCEDURE ^ ObjectP(object: Object);
  266. PROCEDURE ^ CellP(cell: Cell);
  267. PROCEDURE ^ ProcedureP(proc: Procedure);
  268. PROCEDURE ^ ConstExprP(delimiter1, delimiter2: FoxScanner.Token; expr: InfoItem);
  269. PROCEDURE ^ BlockModifierP(allowBody: BOOLEAN; VAR modifiers: SET);
  270. PROCEDURE ^ ProcedureModifierP(procHead: ProcHead);
  271. PROCEDURE ^ ModifierValueP(VAR value: LONGINT);
  272. PROCEDURE ^ BodyP(allowBody: BOOLEAN; VAR modifiers: SET);
  273. PROCEDURE ^ QualidentP(qualident: Qualident);
  274. PROCEDURE ^ IdentDefP(identDef: IdentDef);
  275. PROCEDURE ^ Check(token: FoxScanner.Token);
  276. PROCEDURE ^ Error(pos: LONGINT);
  277. END Parser;
  278. ListEntry = POINTER TO RECORD
  279. module: Module;
  280. next: ListEntry;
  281. END;
  282. ModuleCache = OBJECT {EXCLUSIVE}
  283. VAR
  284. head: ListEntry;
  285. nofModules: LONGINT;
  286. PROCEDURE ^ Add(module: Module);
  287. PROCEDURE ^ Get(CONST moduleName: ARRAY OF CHAR): Module;
  288. PROCEDURE ^ Enumerate(enumerator: EnumeratorProc);
  289. PROCEDURE ^ FindEntry(CONST moduleName: ARRAY OF CHAR): ListEntry;
  290. PROCEDURE ^ & Init;
  291. END ModuleCache;
  292. EnumeratorProc = PROCEDURE {DELEGATE}(module: Module; cache: ModuleCache);
  293. PROCEDURE ^ AppendLast(head, node: NodeList);
  294. PROCEDURE ^ SplitName*(CONST name: ARRAY OF CHAR; VAR moduleName, typeName: ARRAY OF CHAR);
  295. PROCEDURE ^ FindType(CONST name: ARRAY OF CHAR; type: LONGINT; definitionModule: Module; cache: ModuleCache): TypeDecl;
  296. PROCEDURE ^ ResolveTypeHierarchy(module: Module; cache: ModuleCache);
  297. PROCEDURE ^ ResolveMethodOverwrites(module: Module; cache: ModuleCache);
  298. PROCEDURE ^ ParseFile*(CONST filename: ARRAY OF CHAR; diagnostics: Diagnostics.Diagnostics): Module;
  299. PROCEDURE ^ SetSuperTypes*(module: Module);
  300. PROCEDURE ^ Parse*(scanner: FoxScanner.Scanner; VAR module: Module);
  301. BEGIN
  302. END ModuleParser.