CPascalErrors.cp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. (* ==================================================================== *)
  2. (* *)
  3. (* Error Module for the Gardens Point Component Pascal Compiler. *)
  4. (* Copyright (c) John Gough 1999, 2000. *)
  5. (* *)
  6. (* ==================================================================== *)
  7. MODULE CPascalErrors;
  8. IMPORT
  9. GPCPcopyright,
  10. GPTextFiles,
  11. Console,
  12. FileNames,
  13. Scnr := CPascalS,
  14. LitValue,
  15. GPText;
  16. (* ============================================================ *)
  17. CONST
  18. consoleWidth = 80;
  19. listingWidth = 256;
  20. listingMax = listingWidth-1;
  21. TYPE
  22. ParseHandler* = POINTER TO RECORD (Scnr.ErrorHandler)
  23. END;
  24. SemanticHdlr* = POINTER TO RECORD (Scnr.ErrorHandler)
  25. END;
  26. TYPE
  27. Message = LitValue.CharOpen;
  28. Err = POINTER TO ErrDesc;
  29. ErrDesc = RECORD
  30. num, lin, col: INTEGER;
  31. msg: Message;
  32. END;
  33. ErrBuff = POINTER TO ARRAY OF Err;
  34. VAR
  35. parsHdlr : ParseHandler;
  36. semaHdlr : SemanticHdlr;
  37. eBuffer : ErrBuff; (* Invariant: eBuffer[eTide] = NIL *)
  38. eLimit : INTEGER; (* High index of dynamic array. *)
  39. eTide : INTEGER; (* Next index for insertion in buf *)
  40. prompt* : BOOLEAN; (* Emit error message immediately *)
  41. nowarn* : BOOLEAN; (* Don't store warning messages *)
  42. srcNam : FileNames.NameString;
  43. forVisualStudio* : BOOLEAN;
  44. xmlErrors* : BOOLEAN;
  45. (* ============================================================ *)
  46. PROCEDURE StoreError (eNum, linN, colN : INTEGER; mesg: Message);
  47. (* Store an error message for later printing *)
  48. VAR
  49. nextErr: Err;
  50. (* -------------------------------------- *)
  51. PROCEDURE append(b : ErrBuff; n : Err) : ErrBuff;
  52. VAR s : ErrBuff;
  53. i : INTEGER;
  54. BEGIN
  55. IF eTide = eLimit THEN (* must expand *)
  56. s := b;
  57. eLimit := eLimit * 2 + 1;
  58. NEW(b, eLimit+1);
  59. FOR i := 0 TO eTide DO b[i] := s[i] END;
  60. END;
  61. b[eTide] := n; INC(eTide); b[eTide] := NIL;
  62. RETURN b;
  63. END append;
  64. (* -------------------------------------- *)
  65. BEGIN
  66. NEW(nextErr);
  67. nextErr.num := eNum;
  68. nextErr.msg := mesg;
  69. nextErr.col := colN;
  70. nextErr.lin := linN;
  71. eBuffer := append(eBuffer, nextErr);
  72. END StoreError;
  73. (* ============================================================ *)
  74. PROCEDURE QuickSort(min, max : INTEGER);
  75. VAR i,j : INTEGER;
  76. key : INTEGER;
  77. tmp : Err;
  78. (* ------------------------------------------------- *)
  79. PROCEDURE keyVal(i : INTEGER) : INTEGER;
  80. BEGIN
  81. IF (eBuffer[i].col <= 0) OR (eBuffer[i].col >= listingWidth) THEN
  82. eBuffer[i].col := listingMax;
  83. END;
  84. RETURN eBuffer[i].lin * 256 + eBuffer[i].col;
  85. END keyVal;
  86. (* ------------------------------------------------- *)
  87. BEGIN
  88. i := min; j := max;
  89. key := keyVal((min+max) DIV 2);
  90. REPEAT
  91. WHILE keyVal(i) < key DO INC(i) END;
  92. WHILE keyVal(j) > key DO DEC(j) END;
  93. IF i <= j THEN
  94. tmp := eBuffer[i]; eBuffer[i] := eBuffer[j]; eBuffer[j] := tmp;
  95. INC(i); DEC(j);
  96. END;
  97. UNTIL i > j;
  98. IF min < j THEN QuickSort(min,j) END;
  99. IF i < max THEN QuickSort(i,max) END;
  100. END QuickSort;
  101. (* ============================================================ *)
  102. PROCEDURE (h : ParseHandler)Report*(num,lin,col : INTEGER);
  103. VAR str : ARRAY 128 OF CHAR;
  104. msg : Message;
  105. idx : INTEGER;
  106. len : INTEGER;
  107. BEGIN
  108. CASE num OF
  109. | 0: str := "EOF expected";
  110. | 1: str := "ident expected";
  111. | 2: str := "integer expected";
  112. | 3: str := "real expected";
  113. | 4: str := "CharConstant expected";
  114. | 5: str := "string expected";
  115. | 6: str := "'*' expected";
  116. | 7: str := "'-' expected";
  117. | 8: str := "'!' expected";
  118. | 9: str := "'.' expected";
  119. | 10: str := "'=' expected";
  120. | 11: str := "'ARRAY' expected";
  121. | 12: str := "',' expected";
  122. | 13: str := "'OF' expected";
  123. | 14: str := "'ABSTRACT' expected";
  124. | 15: str := "'EXTENSIBLE' expected";
  125. | 16: str := "'LIMITED' expected";
  126. | 17: str := "'RECORD' expected";
  127. | 18: str := "'(' expected";
  128. | 19: str := "'+' expected";
  129. | 20: str := "')' expected";
  130. | 21: str := "'END' expected";
  131. | 22: str := "';' expected";
  132. | 23: str := "':' expected";
  133. | 24: str := "'POINTER' expected";
  134. | 25: str := "'TO' expected";
  135. | 26: str := "'PROCEDURE' expected";
  136. | 27: str := "'[' expected";
  137. | 28: str := "']' expected";
  138. | 29: str := "'^' expected";
  139. | 30: str := "'$' expected";
  140. | 31: str := "'#' expected";
  141. | 32: str := "'<' expected";
  142. | 33: str := "'<=' expected";
  143. | 34: str := "'>' expected";
  144. | 35: str := "'>=' expected";
  145. | 36: str := "'IN' expected";
  146. | 37: str := "'IS' expected";
  147. | 38: str := "'OR' expected";
  148. | 39: str := "'/' expected";
  149. | 40: str := "'DIV' expected";
  150. | 41: str := "'MOD' expected";
  151. | 42: str := "'&' expected";
  152. | 43: str := "'NIL' expected";
  153. | 44: str := "'~' expected";
  154. | 45: str := "'{' expected";
  155. | 46: str := "'}' expected";
  156. | 47: str := "'..' expected";
  157. | 48: str := "'EXIT' expected";
  158. | 49: str := "'RETURN' expected";
  159. | 50: str := "'NEW' expected";
  160. | 51: str := "':=' expected";
  161. | 52: str := "'IF' expected";
  162. | 53: str := "'THEN' expected";
  163. | 54: str := "'ELSIF' expected";
  164. | 55: str := "'ELSE' expected";
  165. | 56: str := "'CASE' expected";
  166. | 57: str := "'|' expected";
  167. | 58: str := "'WHILE' expected";
  168. | 59: str := "'DO' expected";
  169. | 60: str := "'REPEAT' expected";
  170. | 61: str := "'UNTIL' expected";
  171. | 62: str := "'FOR' expected";
  172. | 63: str := "'BY' expected";
  173. | 64: str := "'LOOP' expected";
  174. | 65: str := "'WITH' expected";
  175. | 66: str := "'EMPTY' expected";
  176. | 67: str := "'BEGIN' expected";
  177. | 68: str := "'CONST' expected";
  178. | 69: str := "'TYPE' expected";
  179. | 70: str := "'VAR' expected";
  180. | 71: str := "'OUT' expected";
  181. | 72: str := "'IMPORT' expected";
  182. | 73: str := "'MODULE' expected";
  183. | 74: str := "'CLOSE' expected";
  184. | 75: str := "'JAVACLASS' expected";
  185. | 76: str := "not expected";
  186. | 77: str := "error in OtherAtts";
  187. | 78: str := "error in MethAttributes";
  188. | 79: str := "error in ProcedureStuff";
  189. | 80: str := "this symbol not expected in StatementSequence";
  190. | 81: str := "this symbol not expected in StatementSequence";
  191. | 82: str := "error in IdentStatement";
  192. | 83: str := "error in MulOperator";
  193. | 84: str := "error in Factor";
  194. | 85: str := "error in AddOperator";
  195. | 86: str := "error in Relation";
  196. | 87: str := "error in OptAttr";
  197. | 88: str := "error in ProcedureType";
  198. | 89: str := "error in Type";
  199. | 90: str := "error in Module";
  200. | 91: str := "invalid lexical token";
  201. END;
  202. len := LEN(str$);
  203. NEW(msg, len+1);
  204. FOR idx := 0 TO len-1 DO
  205. msg[idx] := str[idx];
  206. END;
  207. msg[len] := 0X;
  208. StoreError(num,lin,col,msg);
  209. INC(Scnr.errors);
  210. END Report;
  211. (* ============================================================ *)
  212. PROCEDURE (h : ParseHandler)RepSt1*(num : INTEGER;
  213. IN s1 : ARRAY OF CHAR;
  214. lin,col : INTEGER),EMPTY;
  215. PROCEDURE (h : ParseHandler)RepSt2*(num : INTEGER;
  216. IN s1,s2 : ARRAY OF CHAR;
  217. lin,col : INTEGER),EMPTY;
  218. (* ============================================================ *)
  219. PROCEDURE (h : SemanticHdlr)Report*(num,lin,col : INTEGER);
  220. VAR str : ARRAY 128 OF CHAR;
  221. msg : Message;
  222. idx : INTEGER;
  223. len : INTEGER;
  224. BEGIN
  225. CASE num OF
  226. (* ======================= ERRORS ========================= *)
  227. | -1: str := "invalid character";
  228. | 0: RETURN; (* just a placeholder *)
  229. | 1: str := "Name after 'END' does not match";
  230. | 2: str := "Identifier not known in this scope";
  231. | 3: str := "Identifier not known in qualified scope";
  232. | 4: str := "This name already known in this scope";
  233. | 5: str := "This identifier is not a type name";
  234. | 6: str := "This fieldname clashes with previous fieldname";
  235. | 7: str := "Qualified identifier is not a type name";
  236. | 8: str := "Not a record type, so you cannot select a field";
  237. | 9: str := "Identifier is not a fieldname of the current type";
  238. | 10: str := "Not an array type, so you cannot index into it";
  239. | 11: str := "Too many indices for the dimension of the array";
  240. | 12: str := "Not a pointer type, so you cannot dereference it";
  241. | 13: str := "Not a procedure call or type guard";
  242. | 14: str := "Basetype is not record or pointer type";
  243. | 15: str := "Typename not a subtype of the current type";
  244. | 16: str := "Basetype was not declared ABSTRACT or EXTENSIBLE";
  245. | 17: str := "Not dynamically typed, so you cannot have type-guard";
  246. | 18: str := "The type-guard must be a record type here";
  247. | 19: str := "This constant token not known";
  248. | 20: str := "Name of formal is not unique";
  249. | 21: str := "Actual parameter is not compatible with formal type";
  250. | 22: str := "Too few actual parameters";
  251. | 23: str := "Too many actual parameters";
  252. | 24: str := "Attempt to use a proper procedure when function needed";
  253. | 25: str := "Expression is not constant";
  254. | 26: str := "Range of the numerical type exceeded";
  255. | 27: str := "String literal too long for destination type";
  256. | 28: str := "Low value of range not in SET base-type range";
  257. | 29: str := "High value of range not in SET base-type range";
  258. | 30: str := "Low value of range cannot be greater than high value";
  259. | 31: str := "Array index not of an integer type";
  260. | 32: str := "Literal array index is outside array bounds";
  261. | 33: str := "Literal value is not in SET base-type range";
  262. | 34: str := "Typename is not a subtype of the type of destination";
  263. | 35: str := "Expression is not of SET type";
  264. | 36: str := "Expression is not of BOOLEAN type";
  265. | 37: str := "Expression is not of an integer type";
  266. | 38: str := "Expression is not of a numeric type";
  267. | 39: str := "Overflow of negation of literal value";
  268. | 40: str := "Expression is not of ARRAY type";
  269. | 41: str := "Expression is not of character array type";
  270. | 42: str := "Expression is not a standard function";
  271. | 43: str := "Expression is not of character type";
  272. | 44: str := "Literal expression is not in CHAR range";
  273. | 45: str := "Expression is not of REAL type";
  274. | 46: str := "Optional param of LEN must be a positive integer constant";
  275. | 47: str := "LONG cannot be applied to this type";
  276. | 48: str := "Name is not the name of a basic type";
  277. | 49: str := "MAX and MIN not applicable to this type";
  278. | 50: str := "ORD only applies to SET and CHAR types";
  279. | 51: str := "SHORT cannot be applied to this type";
  280. | 52: str := "Both operands must be numeric, SET or CHAR types";
  281. | 53: str := "Character constant outside CHAR range";
  282. | 54: str := "Bad conversion type";
  283. | 55: str := "Numeric overflow in constant evaluation";
  284. | 56: str := "BITS only applies to expressions of type INTEGER";
  285. | 57: str := "Operands in '=' or '#' test are not type compatible";
  286. | 58: str := "EXIT is only permitted inside a LOOP";
  287. | 59: str := "BY expression must be a constant expression";
  288. | 60: str := "Case label is not an integer or character constant";
  289. | 61: str := "Method attributes don't apply to ordinary procedure";
  290. | 62: str := "Forward type-bound method elaborated as static procedure";
  291. | 63: str := "Forward static procedure elaborated as type-bound method";
  292. | 64: str := "Forward method had different receiver mode";
  293. | 65: str := "Forward procedure had non-matching formal types";
  294. | 66: str := "Forward method had different attributes";
  295. | 67: str := "Variable cannot have open array type";
  296. | 68: str := "Arrays must have at least one element";
  297. | 69: str := "Fixed array cannot have open array element type";
  298. | 70: str := "Forward procedure had different names for formals";
  299. | 71: str := "This imported type is LIMITED, and cannot be instantiated";
  300. | 72: str := "Forward procedure was not elaborated by end of block";
  301. | 73: str := "RETURN is not legal in a module body";
  302. | 74: str := "This is a proper procedure, it cannot return a value";
  303. | 75: str := "This is a function, it must return a value";
  304. | 76: str := "RETURN value not assign-compatible with function type";
  305. | 77: str := "Actual for VAR formal must be a writeable variable";
  306. | 78: str := "Functions cannot return record types";
  307. | 79: str := "Functions cannot return array types";
  308. | 80: str := "This designator is not the name of a proper procedure";
  309. | 81: str := "FOR loops cannot have zero step size";
  310. | 82: str := "This fieldname clashes with an inherited fieldname";
  311. | 83: str := "Expression not assign-compatible with destination";
  312. | 84: str := "FOR loop control variable must be of integer type";
  313. | 85: str := "Identifier is not the name of a variable";
  314. | 86: str := "Typename is not an extension of the variable type";
  315. | 87: str := "The selected identifier is not of dynamic type";
  316. | 88: str := "Case select expression is not of integer or CHAR type";
  317. | 89: str := "Case select value is duplicated for this statement";
  318. | 90: str := "Variables of ABSTRACT type cannot be instantiated";
  319. | 91: str := "Optional param of ASSERT must be an integer constant";
  320. | 92: str := "This is not a standard procedure";
  321. | 93: str := "The param of HALT must be a constant integer";
  322. | 94: str := "This variable is not of pointer or vector type";
  323. | 95: str := "NEW requires a length param for open arrays and vectors";
  324. | 96: str := "NEW only applies to pointers to records and arrays";
  325. | 97: str := "This call of NEW has too many lengths specified";
  326. | 98: str := "Length for an open array NEW must be an integer type";
  327. | 99: str := "Length only applies to open arrays and vectors";
  328. | 100: str := "This call of NEW needs more length params";
  329. | 101: str := "Numeric literal is too large, even for long type";
  330. | 102: str := "Only ABSTRACT basetypes can have abstract extensions";
  331. | 103: str := "This expression is read-only";
  332. | 104: str := "Receiver type must be a record, or pointer to record";
  333. | 105: str := "This method is not a redefinition, you must use NEW";
  334. | 106: str := "This method is a redefinition, you must not use NEW";
  335. | 107: str := "Receivers of record type must be VAR or IN mode";
  336. | 108: str := "Final method cannot be redefined";
  337. | 109: str := "Only ABSTRACT method can have ABSTRACT redefinition";
  338. | 110: str := "This type has ABSTRACT method, must be ABSTRACT";
  339. | 111: str := "Type has NEW,EMPTY method, must be ABSTRACT or EXTENSIBLE";
  340. | 112: str := "Only EMPTY or ABSTRACT method can be redefined EMPTY";
  341. | 113: str := "This redefinition of exported method must be exported";
  342. | 114: str := "This is an EMPTY method, and cannot have OUT parameters";
  343. | 115: str := "This is an EMPTY method, and cannot return a value";
  344. | 116: str := "Redefined method must have consistent return type";
  345. | 117: str := "Type has EXTENSIBLE method, must be ABSTRACT or EXTENSIBLE";
  346. | 118: str := "Empty or abstract methods cannot be called by super-call";
  347. | 119: str := "Super-call is invalid here";
  348. | 120: str := "There is no overridden method with this name";
  349. | 121: str := "Not all abstract methods were implemented";
  350. | 122: str := "This procedure is not at module scope, cannot be a method";
  351. | 123: str := "There is a cycle in the base-type declarations";
  352. | 124: str := "There is a cycle in the field-type declarations";
  353. | 125: str := "Cycle in typename equivalence declarations";
  354. | 126: str := "There is a cycle in the array element type declarations";
  355. | 127: str := "This is an implement-only method, and cannot be called";
  356. | 128: str := "Only declarations at module level can be exported";
  357. | 129: str := "Cannot open symbol file";
  358. | 130: str := "Bad magic number in symbol file";
  359. | 131: str := "This type is an INTERFACE, and cannot be instantiated";
  360. | 132: str := "Corrupted symbol file";
  361. | 133: str := "Inconsistent module keys";
  362. | 134: str := "Types can only be public or fully private";
  363. | 135: str := "This variable may be uninitialized";
  364. | 136: str := "Not all paths to END contain a RETURN statement";
  365. | 137: str := "This type tries to directly include itself";
  366. | 138: str := "Not all paths to END in RESCUE contain a RETURN statement";
  367. | 139: str := "Not all OUT parameters have been assigned to";
  368. | 140: str := "Pointer bound type can only be RECORD or ARRAY";
  369. | 141: str := "GPCP restriction: select expression cannot be LONGINT";
  370. | 142: str := "Cannot assign entire open array";
  371. | 143: str := "Cannot assign entire extensible or abstract record";
  372. | 144: str := "Foreign modules must be compiled with '-special'";
  373. | 145: str := "This type tries to indirectly include itself";
  374. | 146: str := "Constructors are declared without receiver";
  375. | 147: str := "Multiple supertype constructors match these parameters";
  376. | 148: str := "This type has another constructor with equal signature";
  377. | 149: str := "This procedure needs parameters";
  378. | 150: str := "Parameter types of exported procedures must be exported";
  379. | 151: str := "Return types of exported procedures must be exported";
  380. | 152: str := "Bound type of foreign reference type cannot be assigned";
  381. | 153: str := "Bound type of foreign reference type cannot be value param";
  382. | 154: str := "It is not possible to extend an interface type";
  383. | 155: str := "NEW illegal unless foreign supertype has no-arg constructor";
  384. | 156: str := "Interfaces can't extend anything. Leave blank or use ANYREC";
  385. | 157: str := "Only extensions of Foreign classes can implement interfaces";
  386. | 158: str := "Additional base types must be interface types";
  387. | 159: str := "Not all interface methods were implemented";
  388. | 160: str := "Inherited procedure had non-matching formal types";
  389. | 161: str := "Only foreign procs and fields can have protected mode";
  390. | 162: str := "This name only accessible in extensions of defining type";
  391. | 163: str := "Interface implementation has wrong export mode";
  392. (**)| 164: str := "Non-locally accessed variable may be uninitialized";
  393. | 165: str := "This procedure cannot be used as a procedure value";
  394. | 166: str := "Super calls are only valid on the current receiver";
  395. | 167: str := "SIZE is not meaningful in this implementation";
  396. | 168: str := "Character literal outside SHORTCHAR range";
  397. | 169: str := "Module exporting this type is not imported";
  398. | 170: str := "This module has already been directly imported";
  399. | 171: str := "Invalid binary operation on these types";
  400. | 172: str := "Name clash in imported scope";
  401. | 173: str := "This module indirectly imported with different key";
  402. | 174: str := "Actual for IN formal must be record, array or string";
  403. | 175: str := "The module exporting this name has not been imported";
  404. | 176: str := "The current type is opaque and cannot be selected further";
  405. | 177: str := "File creation error";
  406. | 178: str := "This record field is read-only";
  407. | 179: str := "This IN parameter is read-only";
  408. | 180: str := "This variable is read-only";
  409. | 181: str := "This identifier is read-only";
  410. | 182: str := "Attempt to use a function when a proper procedure needed";
  411. | 183: str := "This record is private, you cannot export this field";
  412. | 184: str := "This record is readonly, this field cannot be public";
  413. | 185: str := "Static members can only be defined with -special";
  414. | 186: str := 'Ids with "$", "@" or "`" can only be defined with -special';
  415. | 187: str := "Idents escaped with ` must have length >= 2";
  416. | 188: str := "Methods of INTERFACE types must be ABSTRACT";
  417. | 189: str := "Non-local access to byref param of value type";
  418. | 190: str := "Temporary restriction: non-locals not allowed";
  419. | 191: str := "Temporary restriction: only name equivalence here";
  420. | 192: str := "Only '=' or ':' can go here";
  421. | 193: str := "THROW needs a string or native exception object";
  422. | 194: str := 'Only "UNCHECKED_ARITHMETIC" can go here';
  423. | 195: str := "NEW method cannot be exported if receiver type is private";
  424. | 196: str := "Only static fields can select on a type-name";
  425. | 197: str := "Only static methods can select on a type-name";
  426. | 198: str := "Static fields can only select on a type-name";
  427. | 199: str := "Static methods can only select on a type-name";
  428. | 200: str := "Constructors cannot be declared for imported types";
  429. | 201: str := "Constructors must return POINTER TO RECORD type";
  430. | 202: str := "Base type does not have a matching constructor";
  431. | 203: str := "Base type does not allow a no-arg constructor";
  432. | 204: str := "Constructors only allowed for extensions of foreign types";
  433. | 205: str := "Methods can only be declared for local record types";
  434. | 206: str := "Receivers of pointer type must have value mode";
  435. | 207: str := "Feature with this name already known in binding scope";
  436. | 208: str := "EVENT types only valid for .NET target";
  437. | 209: str := "Events must have a valid formal parameter list";
  438. | 210: str := "REGISTER expects an EVENT type here";
  439. | 211: str := "Only procedure literals allowed here";
  440. | 212: str := "Event types cannot be local to procedures";
  441. | 213: str := "Temporary restriction: no proc. variables with JVM";
  442. | 214: str := "Interface types cannot be anonymous";
  443. | 215: str := "Interface types must be exported";
  444. | 216: str := "Interface methods must be exported";
  445. | 217: str := "Covariant OUT parameters unsafe removed from language";
  446. | 218: str := "No procedure of this name with matching parameters";
  447. | 219: str := "Multiple overloaded procedure signatures match this call";
  448. | 220: RETURN; (* BEWARE PREMATURE EXIT *)
  449. | 221: str := "Non-standard construct, not allowed with /strict";
  450. | 222: str := "This is not a value: thus cannot end with a type guard";
  451. | 223: str := "Override of imp-only in exported type must be imp-only";
  452. | 224: str := "This designator is not a procedure or a function call";
  453. | 225: str := "Non-empty constructors can only return SELF";
  454. | 226: str := "USHORT cannot be applied to this type";
  455. | 227: str := "Cannot import SYSTEM without /unsafe option";
  456. | 228: str := "Cannot import SYSTEM unless target=net";
  457. | 229: str := "Designator is not of VECTOR type";
  458. | 230: str := "Type is incompatible with element type";
  459. | 231: str := "Vectors are always one-dimensional only";
  460. | 232: str := 'Hex constant too big, use suffix "L" instead';
  461. | 233: str := "Literal constant too big, even for LONGINT";
  462. | 234: str := "Extension of LIMITED type must be limited";
  463. | 235: str := "LIMITED types can only be extended in the same module";
  464. | 236: str := "Cannot resolve CLR name of this type";
  465. | 237: str := "Invalid hex escape sequence in this string";
  466. | 238: str := "STA is illegal unless target is NET";
  467. | 298: str := "ILASM failed to assemble IL file";
  468. | 299: str := "Compiler raised an internal exception";
  469. (* ===================== END ERRORS ======================= *)
  470. (* ====================== WARNINGS ======================== *)
  471. | 300: str := "Warning: Super calls are deprecated";
  472. | 301: str := "Warning: Procedure variables are deprecated";
  473. | 302: str := "Warning: Non-local variable access here";
  474. | 303: str := "Warning: Numeric literal is not in the SET range [0 .. 31]";
  475. | 304: str := "Warning: This procedure is not exported, called or assigned";
  476. | 305: str := "Warning: Another constructor has an equal signature";
  477. | 306: str := "Warning: Covariant OUT parameters unsafe when aliassed";
  478. | 307: str := "Warning: Multiple overloaded procedure signatures match this call";
  479. | 308: str := "Warning: Default static class has name clash";
  480. | 309: str := "Warning: Looking for an automatically renamed module";
  481. | 310,
  482. 311: str := "Warning: This variable is accessed from nested procedure";
  483. | 312,
  484. 313: RETURN; (* BEWARE PREMATURE EXIT *)
  485. | 314: str := "The anonymous record type is incomptible with all values";
  486. | 315: str := "The anonymous array type is incomptible with all values";
  487. | 316: str := "This pointer type may still have its default NIL value";
  488. | 317: str := "Empty CASE statement will trap if control reaches here";
  489. | 318: str := "Empty WITH statement will trap if control reaches here";
  490. | 319: str := "STA has no effect without CPmain or WinMain";
  491. | 320: str := "Procedure variables with JVM target are experimental";
  492. (* ==================== END WARNINGS ====================== *)
  493. ELSE
  494. str := "Semantic error: " + LitValue.intToCharOpen(num)^;
  495. END;
  496. len := LEN(str$);
  497. NEW(msg, len+1);
  498. FOR idx := 0 TO len-1 DO
  499. msg[idx] := str[idx];
  500. END;
  501. msg[len] := 0X;
  502. IF num < 300 THEN
  503. INC(Scnr.errors);
  504. StoreError(num,lin,col,msg);
  505. ELSIF ~nowarn THEN
  506. INC(Scnr.warnings);
  507. StoreError(num,lin,col,msg);
  508. END;
  509. IF prompt THEN
  510. IF num < 300 THEN
  511. Console.WriteString("Error");
  512. ELSE
  513. Console.WriteString("Warning");
  514. END;
  515. Console.WriteInt(num,0);
  516. Console.WriteString("@ line:");
  517. Console.WriteInt(lin,0);
  518. Console.WriteString(", col:");
  519. Console.WriteInt(col,0);
  520. Console.WriteLn;
  521. Console.WriteString(str);
  522. Console.WriteLn;
  523. END;
  524. END Report;
  525. (* ============================================================ *)
  526. PROCEDURE (h : SemanticHdlr)RepSt1*(num : INTEGER;
  527. IN s1 : ARRAY OF CHAR;
  528. lin,col : INTEGER);
  529. VAR msg : Message;
  530. BEGIN
  531. CASE num OF
  532. | 0: msg := LitValue.strToCharOpen("Expected: END " + s1);
  533. | 1: msg := LitValue.strToCharOpen("Expected: " + s1);
  534. | 89: msg := LitValue.strToCharOpen("Duplicated selector values <"
  535. + s1 + ">");
  536. | 9,
  537. 169: msg := LitValue.strToCharOpen("Current type was <"
  538. + s1 + '>');
  539. | 117: msg := LitValue.strToCharOpen("Type <"
  540. + s1 + "> must be extensible");
  541. | 121: msg := LitValue.strToCharOpen("Missing methods <" + s1 + '>');
  542. | 145: msg := LitValue.strToCharOpen("Types on cycle <" + s1 + '>');
  543. | 129,
  544. 130,
  545. 132: msg := LitValue.strToCharOpen("Filename <" + s1 + '>');
  546. | 133: msg := LitValue.strToCharOpen("Module <"
  547. + s1 + "> already imported with different key");
  548. | 138: msg := LitValue.strToCharOpen('<'
  549. + s1 + '> not assigned before "RETURN"');
  550. | 139: msg := LitValue.strToCharOpen('<'
  551. + s1 + '> not assigned before end of procedure');
  552. | 154: msg := LitValue.strToCharOpen('<'
  553. + s1 + "> is a Foreign interface type");
  554. | 157: msg := LitValue.strToCharOpen('<'
  555. + s1 + "> is not a Foreign type");
  556. | 158: msg := LitValue.strToCharOpen('<'
  557. + s1 + "> is not a foreign language interface type");
  558. | 159: msg := LitValue.strToCharOpen("Missing interface methods <"
  559. + s1 + '>');
  560. | 162: msg := LitValue.strToCharOpen('<'
  561. + s1 + "> is a protected, foreign-language feature");
  562. | 164: msg := LitValue.strToCharOpen('<'
  563. + s1 + "> not assigned before this call");
  564. | 172: msg := LitValue.strToCharOpen('Name <'
  565. + s1 + '> clashes in imported scope');
  566. | 175,
  567. 176: msg := LitValue.strToCharOpen("Module "
  568. + '<' + s1 + "> is not imported");
  569. | 189: msg := LitValue.strToCharOpen('Non-local access to <'
  570. + s1 + '> cannot be verified on .NET');
  571. | 205,
  572. 207: msg := LitValue.strToCharOpen(
  573. "Binding scope of feature is record type <" + s1 + ">");
  574. | 236: msg := LitValue.strToCharOpen(
  575. "Cannot resolve CLR name of type : " + s1);
  576. | 299: msg := LitValue.strToCharOpen("Exception: " + s1);
  577. | 308: msg := LitValue.strToCharOpen(
  578. "Renaming static class to <" + s1 + ">");
  579. | 310: msg := LitValue.strToCharOpen('Access to <'
  580. + s1 + '> has copying not reference semantics');
  581. | 311: msg := LitValue.strToCharOpen('Access to variable <'
  582. + s1 + '> will be inefficient');
  583. | 220,
  584. 312: msg := LitValue.strToCharOpen("Matches with - " + s1);
  585. | 313: msg := LitValue.strToCharOpen("Bound to - " + s1);
  586. END;
  587. IF ~nowarn OR (* If warnings are on OR *)
  588. (num < 300) THEN (* this is an error then *)
  589. StoreError(num,lin,0,msg); (* (1) Store THIS message *)
  590. h.Report(num,lin,col); (* (2) Generate other msg *)
  591. END;
  592. (*
  593. * IF (num # 251) & (num # 252) THEN
  594. * StoreError(num,lin,col,msg);
  595. * h.Report(num,lin,col);
  596. * ELSIF ~nowarn THEN
  597. * StoreError(num,lin,col,msg);
  598. * END;
  599. *)
  600. END RepSt1;
  601. (* ============================================================ *)
  602. PROCEDURE (h : SemanticHdlr)RepSt2*(num : INTEGER;
  603. IN s1,s2 : ARRAY OF CHAR;
  604. lin,col : INTEGER);
  605. (*
  606. * VAR str : ARRAY 128 OF CHAR;
  607. * msg : Message;
  608. * idx : INTEGER;
  609. * len : INTEGER;
  610. *)
  611. VAR msg : Message;
  612. BEGIN
  613. CASE num OF
  614. | 21,
  615. 217,
  616. 306: msg := LitValue.strToCharOpen(
  617. "Actual par-type was " + s1 + ", Formal type was " + s2);
  618. | 76: msg := LitValue.strToCharOpen(
  619. "Expr-type was " + s2 + ", should be " + s1);
  620. | 57,
  621. 83: msg := LitValue.strToCharOpen(
  622. "LHS type was " + s1 + ", RHS type was " + s2);
  623. | 116: msg := LitValue.strToCharOpen(
  624. "Inherited retType is " + s1 + ", this retType " + s2);
  625. | 131: msg := LitValue.strToCharOpen(
  626. "Module name in file <" + s1 + ".cps> was <" + s2 + '>');
  627. | 172: msg := LitValue.strToCharOpen(
  628. 'Name <' + s1 + '> clashes in scope <' + s2 + '>');
  629. | 230: msg := LitValue.strToCharOpen(
  630. "Expression type is " + s2 + ", element type is " + s1);
  631. | 309: msg := LitValue.strToCharOpen(
  632. 'Looking for module "' + s1 + '" in file <' + s2 + '>');
  633. END;
  634. (*
  635. * len := LEN(str$);
  636. * NEW(msg, len+1);
  637. * FOR idx := 0 TO len-1 DO
  638. * msg[idx] := str[idx];
  639. * END;
  640. * msg[len] := 0X;
  641. *)
  642. StoreError(num,lin,col,msg);
  643. h.Report(num,lin,col);
  644. END RepSt2;
  645. (* ============================================================ *)
  646. PROCEDURE GetLine (VAR pos : INTEGER;
  647. OUT line : ARRAY OF CHAR;
  648. OUT eof : BOOLEAN);
  649. (** Read a source line. Return empty line if eof *)
  650. CONST
  651. cr = 0DX;
  652. lf = 0AX;
  653. tab = 09X;
  654. VAR
  655. ch: CHAR;
  656. i: INTEGER;
  657. BEGIN
  658. ch := Scnr.charAt(pos); INC(pos);
  659. i := 0;
  660. eof := FALSE;
  661. WHILE (ch # lf) & (ch # 0X) DO
  662. IF ch = cr THEN (* skip *)
  663. ELSIF ch = tab THEN
  664. REPEAT line[MIN(i,listingMax)] := ' '; INC(i) UNTIL i MOD 8 = 0;
  665. ELSE
  666. line[MIN(i,listingMax)] := ch; INC(i);
  667. END;
  668. ch := Scnr.charAt(pos); INC(pos);
  669. END;
  670. eof := (i = 0) & (ch = 0X); line[MIN(i,listingMax)] := 0X;
  671. END GetLine;
  672. (* ============================================================ *)
  673. PROCEDURE PrintErr(IN desc : ErrDesc);
  674. (** Print an error message *)
  675. VAR mLen : INTEGER;
  676. indx : INTEGER;
  677. BEGIN
  678. GPText.WriteString(Scnr.lst, "**** ");
  679. mLen := LEN(desc.msg$);
  680. IF desc.col = listingMax THEN (* write field of width (col-2) *)
  681. GPText.WriteString(Scnr.lst, desc.msg);
  682. ELSIF mLen < desc.col-1 THEN (* write field of width (col-2) *)
  683. GPText.WriteFiller(Scnr.lst, desc.msg, "-", desc.col-1);
  684. GPText.Write(Scnr.lst, "^");
  685. ELSIF mLen + desc.col + 5 < consoleWidth THEN
  686. GPText.WriteFiller(Scnr.lst, "", "-", desc.col-1);
  687. GPText.WriteString(Scnr.lst, "^ ");
  688. GPText.WriteString(Scnr.lst, desc.msg);
  689. ELSE
  690. GPText.WriteFiller(Scnr.lst, "", "-", desc.col-1);
  691. GPText.Write(Scnr.lst, "^");
  692. GPText.WriteLn(Scnr.lst);
  693. GPText.WriteString(Scnr.lst, "**** ");
  694. GPText.WriteString(Scnr.lst, desc.msg);
  695. END;
  696. GPText.WriteLn(Scnr.lst);
  697. END PrintErr;
  698. (* ============================================================ *)
  699. PROCEDURE Display (IN desc : ErrDesc);
  700. (** Display an error message *)
  701. VAR mLen : INTEGER;
  702. indx : INTEGER;
  703. BEGIN
  704. Console.WriteString("**** ");
  705. mLen := LEN(desc.msg$);
  706. IF desc.col = listingMax THEN
  707. Console.WriteString(desc.msg);
  708. ELSIF mLen < desc.col-1 THEN
  709. Console.WriteString(desc.msg);
  710. FOR indx := mLen TO desc.col-2 DO Console.Write("-") END;
  711. Console.Write("^");
  712. ELSIF mLen + desc.col + 5 < consoleWidth THEN
  713. FOR indx := 2 TO desc.col DO Console.Write("-") END;
  714. Console.WriteString("^ ");
  715. Console.WriteString(desc.msg);
  716. ELSE
  717. FOR indx := 2 TO desc.col DO Console.Write("-") END;
  718. Console.Write("^");
  719. Console.WriteLn;
  720. Console.WriteString("**** ");
  721. Console.WriteString(desc.msg);
  722. END;
  723. Console.WriteLn;
  724. END Display;
  725. (* ============================================================ *)
  726. PROCEDURE DisplayVS (IN desc : ErrDesc);
  727. (** Display an error message for Visual Studio *)
  728. VAR mLen : INTEGER;
  729. indx : INTEGER;
  730. BEGIN
  731. Console.WriteString(srcNam);
  732. Console.Write("(");
  733. Console.WriteInt(desc.lin,1);
  734. Console.Write(",");
  735. Console.WriteInt(desc.col,1);
  736. Console.WriteString(") : ");
  737. IF desc.num < 300 THEN
  738. Console.WriteString("error : ");
  739. ELSE
  740. Console.WriteString("warning : ");
  741. END;
  742. Console.WriteString(desc.msg);
  743. Console.WriteLn;
  744. END DisplayVS;
  745. (* ============================================================ *)
  746. PROCEDURE DisplayXMLHeader ();
  747. BEGIN
  748. Console.WriteString('<?xml version="1.0"?>');
  749. Console.WriteLn;
  750. Console.WriteString('<compilererrors errorsContained="yes">');
  751. Console.WriteLn;
  752. END DisplayXMLHeader;
  753. PROCEDURE DisplayXMLEnd ();
  754. BEGIN
  755. Console.WriteString('</compilererrors>');
  756. Console.WriteLn;
  757. END DisplayXMLEnd;
  758. PROCEDURE DisplayXML (IN desc : ErrDesc);
  759. (** Display an error message in xml format (for eclipse) *)
  760. (* <?xml version="1.0"?>
  761. * <compilererrors errorsContained="yes">
  762. * <error>
  763. * <line> 1 </line>
  764. * <position> 34 </position>
  765. * <description> ; expected </description>
  766. * </error>
  767. * ...
  768. * </compilererrors>
  769. *)
  770. VAR mLen : INTEGER;
  771. indx : INTEGER;
  772. isWarn : BOOLEAN;
  773. BEGIN
  774. isWarn := desc.num >= 300;
  775. IF isWarn THEN
  776. Console.WriteString(" <warning> ");
  777. ELSE
  778. Console.WriteString(" <error> ");
  779. END;
  780. Console.WriteLn;
  781. Console.WriteString(" <line> ");
  782. Console.WriteInt(desc.lin,1);
  783. Console.WriteString(" </line>"); Console.WriteLn;
  784. Console.WriteString(" <position> ");
  785. Console.WriteInt(desc.col,1);
  786. Console.WriteString(" </position>"); Console.WriteLn;
  787. Console.WriteString(" <description> ");
  788. IF isWarn THEN
  789. Console.WriteString("warning : ");
  790. ELSE
  791. Console.WriteString("error : ");
  792. END;
  793. Console.WriteString(desc.msg);
  794. Console.WriteString(" </description> "); Console.WriteLn;
  795. IF isWarn THEN
  796. Console.WriteString(" </warning> ");
  797. ELSE
  798. Console.WriteString(" </error> ");
  799. END;
  800. Console.WriteLn;
  801. END DisplayXML;
  802. (* ============================================================ *)
  803. PROCEDURE PrintLine(n : INTEGER; IN l : ARRAY OF CHAR);
  804. BEGIN
  805. GPText.WriteInt(Scnr.lst, n, 4); GPText.Write(Scnr.lst, " ");
  806. GPText.WriteString(Scnr.lst, l); GPText.WriteLn(Scnr.lst);
  807. END PrintLine;
  808. (* ============================================================ *)
  809. PROCEDURE DisplayLn(n : INTEGER; IN l : ARRAY OF CHAR);
  810. BEGIN
  811. Console.WriteInt(n, 4); Console.Write(" ");
  812. Console.WriteString(l); Console.WriteLn;
  813. END DisplayLn;
  814. (* ============================================================ *)
  815. PROCEDURE PrintListing*(list : BOOLEAN);
  816. (** Print a source listing with error messages *)
  817. VAR
  818. nextErr : Err; (* next error descriptor *)
  819. nextLin : INTEGER; (* line num of nextErr *)
  820. eof : BOOLEAN; (* end of file found *)
  821. lnr : INTEGER; (* current line number *)
  822. errC : INTEGER; (* current error index *)
  823. srcPos : INTEGER; (* postion in sourceFile *)
  824. line : ARRAY listingWidth OF CHAR;
  825. BEGIN
  826. IF xmlErrors THEN DisplayXMLHeader(); END;
  827. nextLin := 0;
  828. IF eTide > 0 THEN QuickSort(0, eTide-1) END;
  829. IF list THEN
  830. GPText.WriteString(Scnr.lst, "Listing:");
  831. GPText.WriteLn(Scnr.lst); GPText.WriteLn(Scnr.lst);
  832. END;
  833. srcPos := 0; nextErr := eBuffer[0];
  834. GetLine(srcPos, line, eof); lnr := 1; errC := 0;
  835. WHILE ~ eof DO
  836. IF nextErr # NIL THEN nextLin := nextErr.lin END;
  837. IF list THEN PrintLine(lnr, line) END;
  838. IF ~forVisualStudio & ~xmlErrors & (~list OR (lnr = nextLin)) THEN
  839. DisplayLn(lnr, line)
  840. END;
  841. WHILE (nextErr # NIL) & (nextErr.lin = lnr) DO
  842. IF list THEN PrintErr(nextErr) END;
  843. IF forVisualStudio THEN
  844. DisplayVS(nextErr);
  845. ELSIF xmlErrors THEN
  846. DisplayXML(nextErr);
  847. ELSE
  848. Display(nextErr);
  849. END;
  850. INC(errC);
  851. nextErr := eBuffer[errC];
  852. END;
  853. GetLine(srcPos, line, eof); INC(lnr);
  854. END;
  855. WHILE nextErr # NIL DO
  856. IF list THEN PrintErr(nextErr) END;
  857. IF forVisualStudio THEN
  858. DisplayVS(nextErr);
  859. ELSE
  860. Display(nextErr);
  861. END;
  862. INC(errC);
  863. nextErr := eBuffer[errC];
  864. END;
  865. (*
  866. * IF list THEN
  867. * GPText.WriteLn(Scnr.lst);
  868. * GPText.WriteInt(Scnr.lst, errC, 5);
  869. * GPText.WriteString(Scnr.lst, " error");
  870. * IF errC # 1 THEN GPText.Write(Scnr.lst, "s") END;
  871. * GPText.WriteLn(Scnr.lst);
  872. * GPText.WriteLn(Scnr.lst);
  873. * GPText.WriteLn(Scnr.lst);
  874. * END;
  875. *)
  876. IF list THEN
  877. GPText.WriteLn(Scnr.lst);
  878. GPText.WriteString(Scnr.lst, "There were: ");
  879. IF Scnr.errors = 0 THEN
  880. GPText.WriteString(Scnr.lst, "No errors");
  881. ELSE
  882. GPText.WriteInt(Scnr.lst, Scnr.errors, 0);
  883. GPText.WriteString(Scnr.lst, " error");
  884. IF Scnr.errors # 1 THEN GPText.Write(Scnr.lst, "s") END;
  885. END;
  886. GPText.WriteString(Scnr.lst, ", and ");
  887. IF Scnr.warnings = 0 THEN
  888. GPText.WriteString(Scnr.lst, "No warnings");
  889. ELSE
  890. GPText.WriteInt(Scnr.lst, Scnr.warnings, 0);
  891. GPText.WriteString(Scnr.lst, " warning");
  892. IF Scnr.warnings # 1 THEN GPText.Write(Scnr.lst, "s") END;
  893. END;
  894. GPText.WriteLn(Scnr.lst);
  895. GPText.WriteLn(Scnr.lst);
  896. GPText.WriteLn(Scnr.lst);
  897. END;
  898. IF xmlErrors THEN DisplayXMLEnd(); END;
  899. END PrintListing;
  900. PROCEDURE ResetErrorList*();
  901. BEGIN
  902. eTide := 0;
  903. eBuffer[0] := NIL;
  904. END ResetErrorList;
  905. (* ============================================================ *)
  906. PROCEDURE Init*;
  907. BEGIN
  908. NEW(parsHdlr); Scnr.ParseErr := parsHdlr;
  909. NEW(semaHdlr); Scnr.SemError := semaHdlr;
  910. END Init;
  911. (* ============================================================ *)
  912. PROCEDURE SetSrcNam* (IN nam : ARRAY OF CHAR);
  913. BEGIN
  914. GPText.Assign(nam,srcNam);
  915. END SetSrcNam;
  916. (* ============================================================ *)
  917. BEGIN
  918. NEW(eBuffer, 8); eBuffer[0] := NIL; eLimit := 7; eTide := 0;
  919. prompt := FALSE;
  920. nowarn := FALSE;
  921. forVisualStudio := FALSE;
  922. END CPascalErrors.
  923. (* ============================================================ *)