ERRORS.ob07 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. (*
  2. BSD 2-Clause License
  3. Copyright (c) 2018-2022, Anton Krotov
  4. All rights reserved.
  5. *)
  6. MODULE ERRORS;
  7. IMPORT C := CONSOLE, UTILS;
  8. PROCEDURE HintMsg* (name: ARRAY OF CHAR; line, col, hint: INTEGER);
  9. BEGIN
  10. IF hint = 0 THEN
  11. C.String(" hint ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
  12. C.String("variable '"); C.String(name); C.StringLn("' never used")
  13. END
  14. END HintMsg;
  15. PROCEDURE WarningMsg* (line, col, warning: INTEGER);
  16. BEGIN
  17. C.String(" warning ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
  18. CASE warning OF
  19. |0: C.StringLn("passing a string value as a fixed array")
  20. |1: C.StringLn("endless FOR loop")
  21. |2: C.StringLn("identifier too long")
  22. END
  23. END WarningMsg;
  24. PROCEDURE ErrorMsg* (fname: ARRAY OF CHAR; line, col, errno: INTEGER);
  25. VAR
  26. str: ARRAY 80 OF CHAR;
  27. BEGIN
  28. C.Ln;
  29. C.String(" error ("); C.Int(errno); C.String(") ("); C.Int(line); C.String(":"); C.Int(col); C.String(") ");
  30. CASE errno OF
  31. | 1: str := "missing 'H' or 'X'"
  32. | 2: str := "missing scale"
  33. | 3: str := "unclosed string"
  34. | 4: str := "illegal character"
  35. | 5: str := "string too long"
  36. | 7: str := "number too long"
  37. | 8..12: str := "number too large"
  38. | 13: str := "real numbers not supported"
  39. | 21: str := "'MODULE' expected"
  40. | 22: str := "identifier expected"
  41. | 23: str := "module name does not match file name"
  42. | 24: str := "';' expected"
  43. | 25: str := "identifier does not match module name"
  44. | 26: str := "'.' expected"
  45. | 27: str := "'END' expected"
  46. | 28: str := "',', ';' or ':=' expected"
  47. | 29: str := "module not found"
  48. | 30: str := "multiply defined identifier"
  49. | 31: str := "recursive import"
  50. | 32: str := "'=' expected"
  51. | 33: str := "')' expected"
  52. | 34: str := "syntax error in expression"
  53. | 35: str := "'}' expected"
  54. | 36: str := "incompatible operand"
  55. | 37: str := "incompatible operands"
  56. | 38: str := "'RETURN' expected"
  57. | 39: str := "integer overflow"
  58. | 40: str := "floating point overflow"
  59. | 41: str := "not enough floating point registers; simplify expression"
  60. | 42: str := "out of range 0..255"
  61. | 43: str := "expression is not an integer"
  62. | 44: str := "out of range 0..MAXSET"
  63. | 45: str := "division by zero"
  64. | 46: str := "IV out of range"
  65. | 47: str := "'OF' or ',' expected"
  66. | 48: str := "undeclared identifier"
  67. | 49: str := "type expected"
  68. | 50: str := "recursive type definition"
  69. | 51: str := "illegal value of constant"
  70. | 52: str := "not a record type"
  71. | 53: str := "':' expected"
  72. | 54: str := "need to import SYSTEM"
  73. | 55: str := "pointer type not defined"
  74. | 56: str := "out of range 0..MAXSET"
  75. | 57: str := "'TO' expected"
  76. | 58: str := "not a record type"
  77. | 59: str := "this expression cannot be a procedure"
  78. | 60: str := "identifier does not match procedure name"
  79. | 61: str := "illegally marked identifier"
  80. | 62: str := "expression should be constant"
  81. | 63: str := "not enough RAM"
  82. | 64: str := "'(' expected"
  83. | 65: str := "',' expected"
  84. | 66: str := "incompatible parameter"
  85. | 67: str := "'OF' expected"
  86. | 68: str := "type expected"
  87. | 69: str := "result type of procedure is not a basic type"
  88. | 70: str := "import not supported"
  89. | 71: str := "']' expected"
  90. | 72: str := "expression is not BOOLEAN"
  91. | 73: str := "not a record"
  92. | 74: str := "undefined record field"
  93. | 75: str := "not an array"
  94. | 76: str := "expression is not an integer"
  95. | 77: str := "not a pointer"
  96. | 78: str := "type guard not allowed"
  97. | 79: str := "not a type"
  98. | 80: str := "not a record type"
  99. | 81: str := "not a pointer type"
  100. | 82: str := "type guard not allowed"
  101. | 83: str := "index out of range"
  102. | 84: str := "dimension too large"
  103. | 85: str := "procedure must have level 0"
  104. | 86: str := "not a procedure"
  105. | 87: str := "incompatible expression (RETURN)"
  106. | 88: str := "'THEN' expected"
  107. | 89: str := "'DO' expected"
  108. | 90: str := "'UNTIL' expected"
  109. | 91: str := "incompatible assignment"
  110. | 92: str := "procedure call of a function"
  111. | 93: str := "not a variable"
  112. | 94: str := "read only variable"
  113. | 95: str := "invalid type of expression (CASE)"
  114. | 96: str := "':=' expected"
  115. | 97: str := "not INTEGER variable"
  116. | 98: str := "illegal value of constant (0)"
  117. | 99: str := "incompatible label"
  118. |100: str := "multiply defined label"
  119. |101: str := "too large parameter of WCHR"
  120. |102: str := "label expected"
  121. |103: str := "illegal value of constant"
  122. |104: str := "type too large"
  123. |105: str := "access to intermediate variables not allowed"
  124. |106: str := "qualified identifier expected"
  125. |107: str := "too large parameter of CHR"
  126. |108: str := "a variable or a procedure expected"
  127. |109: str := "expression should be constant"
  128. |110: str := "out of range 0..65535"
  129. |111: str := "record [noalign] cannot have a base type"
  130. |112: str := "record [noalign] cannot be a base type"
  131. |113: str := "result type of procedure should not be REAL"
  132. |114: str := "identifiers 'lib_init' and 'version' are reserved"
  133. |115: str := "recursive constant definition"
  134. |116: str := "procedure too deep nested"
  135. |117: str := "string expected"
  136. |118: str := "'$END', '$ELSE' or '$ELSIF' without '$IF'"
  137. |119: str := "'$IF', '$ELSIF', '$ELSE' or '$END' expected"
  138. |120: str := "too many formal parameters"
  139. |121: str := "multiply defined handler"
  140. |122: str := "bad divisor"
  141. |123: str := "illegal flag"
  142. |124: str := "unknown flag"
  143. |125: str := "flag not supported"
  144. |126: str := "type of formal parameter should not be REAL"
  145. END;
  146. C.StringLn(str);
  147. C.String(" file: "); C.StringLn(fname);
  148. UTILS.Exit(1)
  149. END ErrorMsg;
  150. PROCEDURE Error1 (s1: ARRAY OF CHAR);
  151. BEGIN
  152. C.Ln;
  153. C.StringLn(s1);
  154. UTILS.Exit(1)
  155. END Error1;
  156. PROCEDURE Error3 (s1, s2, s3: ARRAY OF CHAR);
  157. BEGIN
  158. C.Ln;
  159. C.String(s1); C.String(s2); C.StringLn(s3);
  160. UTILS.Exit(1)
  161. END Error3;
  162. PROCEDURE Error5 (s1, s2, s3, s4, s5: ARRAY OF CHAR);
  163. BEGIN
  164. C.Ln;
  165. C.String(s1); C.String(s2); C.String(s3); C.String(s4); C.StringLn(s5);
  166. UTILS.Exit(1)
  167. END Error5;
  168. PROCEDURE WrongRTL* (ProcName: ARRAY OF CHAR);
  169. BEGIN
  170. Error5("procedure ", UTILS.RTL_NAME, ".", ProcName, " not found")
  171. END WrongRTL;
  172. PROCEDURE BadParam* (param: ARRAY OF CHAR);
  173. BEGIN
  174. Error3("bad parameter: ", param, "")
  175. END BadParam;
  176. PROCEDURE FileNotFound* (Path, Name, Ext: ARRAY OF CHAR);
  177. BEGIN
  178. Error5("file ", Path, Name, Ext, " not found")
  179. END FileNotFound;
  180. PROCEDURE Error* (n: INTEGER);
  181. BEGIN
  182. CASE n OF
  183. |201: Error1("writing file error")
  184. |202: Error1("too many relocations")
  185. |203: Error1("size of program is too large")
  186. |204: Error1("size of variables is too large")
  187. |205: Error1("not enough parameters")
  188. |206: Error1("bad parameter <target>")
  189. |207: Error3('inputfile name extension must be "', UTILS.FILE_EXT, '"')
  190. |208: Error1("not enough RAM")
  191. END
  192. END Error;
  193. END ERRORS.