CPascalErrors.cp 41 KB

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