processorErrorFactory.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import { RuntimeError } from './runtimeError';
  2. import { SemanticError } from './semanticError';
  3. import * as LocalizedStringsService from './../../services/localizedStringsService';
  4. const LocalizedStrings = LocalizedStringsService.getInstance();
  5. export const ProcessorErrorFactory = Object.freeze({
  6. symbol_not_found_full: (id, sourceInfo) => {
  7. if(sourceInfo) {
  8. const context = [id, sourceInfo.line, sourceInfo.column];
  9. return new SemanticError(LocalizedStrings.getError("symbol_not_found_full", context));
  10. } else {
  11. return ProcessorErrorFactory.symbol_not_found(id);
  12. }
  13. },
  14. symbol_not_found: (id) => {
  15. const context = [id];
  16. return new SemanticError(LocalizedStrings.getError("symbol_not_found", context));
  17. },
  18. function_missing_full: (id, sourceInfo) => {
  19. if(sourceInfo) {
  20. const context = [id, sourceInfo.line, sourceInfo.column];
  21. return new SemanticError(LocalizedStrings.getError("function_missing_full", context));
  22. } else {
  23. return ProcessorErrorFactory.function_missing(id);
  24. }
  25. },
  26. function_missing: (id) => {
  27. const context = [id];
  28. return new SemanticError(LocalizedStrings.getError("function_missing", context));
  29. },
  30. main_missing: () => {
  31. return new SemanticError(LocalizedStrings.getError("main_missing"));
  32. }, // TODO: better urgent error message
  33. array_dimension_not_int_full: (sourceInfo) => {
  34. if(sourceInfo) {
  35. const context = [sourceInfo.line];
  36. return new SemanticError(LocalizedStrings.getError("array_dimension_not_int_full", context));
  37. } else {
  38. return ProcessorErrorFactory.array_dimension_not_int();
  39. }
  40. },
  41. array_dimension_not_int: () => {
  42. return new SemanticError(LocalizedStrings.getError("array_dimension_not_int"));
  43. },
  44. unknown_command_full: (sourceInfo)=> {
  45. if(sourceInfo) {
  46. const context = [sourceInfo.line];
  47. return new RuntimeError(LocalizedStrings.getError("unknown_command_full", context));
  48. } else {
  49. return ProcessorErrorFactory.unknown_command();
  50. }
  51. },
  52. unknown_command: ()=> {
  53. return new RuntimeError(LocalizedStrings.getError("unknown_command"));
  54. },
  55. incompatible_types_full: (type, dim, sourceInfo) => {
  56. if(sourceInfo) {
  57. const context = [LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];
  58. return new SemanticError(LocalizedStrings.getError("incompatible_types_full", context));
  59. } else {
  60. return ProcessorErrorFactory.incompatible_types(type, dim);
  61. }
  62. },
  63. incompatible_types: (type, dim) => {
  64. const context = [LocalizedStrings.translateType(type, dim)];
  65. return new SemanticError(LocalizedStrings.getError("incompatible_types", context));
  66. },
  67. incompatible_types_array_full: (exp, type, dim, sourceInfo) => {
  68. if(sourceInfo) {
  69. const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];
  70. return new SemanticError(LocalizedStrings.getError("incompatible_types_array_full", context));
  71. } else {
  72. return ProcessorErrorFactory.incompatible_types_array(exp, type, dim);
  73. }
  74. },
  75. incompatible_types_array: (exp, type, dim) => {
  76. const context = [exp, LocalizedStrings.translateType(type, dim)];
  77. return new SemanticError(LocalizedStrings.getError("incompatible_types_array", context));
  78. },
  79. loop_condition_type_full: (exp, sourceInfo) => {
  80. if(sourceInfo) {
  81. const context = [sourceInfo.line, sourceInfo.column, exp];
  82. return new SemanticError(LocalizedStrings.getError("loop_condition_type_full", context));
  83. } else {
  84. return ProcessorErrorFactory.loop_condition_type(exp);
  85. }
  86. },
  87. loop_condition_type: (exp) => {
  88. const context = [exp];
  89. return new SemanticError(LocalizedStrings.getError("loop_condition_type", context));
  90. },
  91. endless_loop_full: (sourceInfo) => {
  92. if(sourceInfo) {
  93. const context = [sourceInfo.line];
  94. return new SemanticError(LocalizedStrings.getError("endless_loop_full", context));
  95. } else {
  96. return ProcessorErrorFactory.endless_loop();
  97. }
  98. },
  99. endless_loop: () => {
  100. return new SemanticError(LocalizedStrings.getError("endless_loop"));
  101. },
  102. for_condition_type_full: (exp, sourceInfo) => {
  103. if(sourceInfo) {
  104. const context = [sourceInfo.line, sourceInfo.column, exp];
  105. return new SemanticError(LocalizedStrings.getError("for_condition_type_full", context));
  106. } else {
  107. return ProcessorErrorFactory.for_condition_type(exp);
  108. }
  109. },
  110. for_condition_type: (exp) => {
  111. const context = [exp];
  112. return new SemanticError(LocalizedStrings.getError("for_condition_type", context));
  113. },
  114. if_condition_type_full: (exp, sourceInfo) => {
  115. if(sourceInfo) {
  116. const context = [sourceInfo.line, sourceInfo.column, exp];
  117. return new SemanticError(LocalizedStrings.getError("if_condition_type_full", context));
  118. } else {
  119. return ProcessorErrorFactory.if_condition_type(exp);
  120. }
  121. },
  122. if_condition_type: (exp) => {
  123. const context = [exp];
  124. return new SemanticError(LocalizedStrings.getError("if_condition_type", context));
  125. },
  126. invalid_global_var: () => {
  127. return new RuntimeError(LocalizedStrings.getError("invalid_global_var"))
  128. },
  129. not_implemented: (id) => {
  130. const context = [id]
  131. return new RuntimeError(LocalizedStrings.getError("not_implemented", context))
  132. },
  133. invalid_case_type_full: (exp, type, dim, sourceInfo) => {
  134. if(sourceInfo) {
  135. const context = [exp, LocalizedStrings.translateType(type, dim), sourceInfo.line, sourceInfo.column];
  136. return new SemanticError(LocalizedStrings.getError("invalid_case_type_full", context));
  137. } else {
  138. return ProcessorErrorFactory.invalid_case_type(exp, type, dim);
  139. }
  140. },
  141. invalid_case_type: (exp, type, dim) => {
  142. const context = [exp, LocalizedStrings.translateType(type, dim)];
  143. return new SemanticError(LocalizedStrings.getError("invalid_case_type", context));
  144. },
  145. void_in_expression_full: (id, sourceInfo) => {
  146. if(sourceInfo) {
  147. const context = [sourceInfo.line, sourceInfo.column, id];
  148. return new SemanticError(LocalizedStrings.getError("void_in_expression_full", context));
  149. } else {
  150. return ProcessorErrorFactory.void_in_expression(id);
  151. }
  152. },
  153. void_in_expression: (id) => {
  154. const context = [id];
  155. return new SemanticError(LocalizedStrings.getError("void_in_expression", context));
  156. },
  157. invalid_array_access_full: (id, sourceInfo) => {
  158. if(sourceInfo) {
  159. const context = [id, sourceInfo.line, sourceInfo.column];
  160. return new SemanticError(LocalizedStrings.getError("invalid_array_access_full", context));
  161. } else {
  162. return ProcessorErrorFactory.invalid_array_access(id);
  163. }
  164. },
  165. invalid_array_access: (id) => {
  166. const context = [id];
  167. return new SemanticError(LocalizedStrings.getError("invalid_array_access", context));
  168. },
  169. invalid_matrix_access_full: (id, sourceInfo) => {
  170. if(sourceInfo) {
  171. const context = [id, sourceInfo.line, sourceInfo.column];
  172. return new SemanticError(LocalizedStrings.getError("invalid_matrix_access_full", context));
  173. } else {
  174. return ProcessorErrorFactory.invalid_matrix_access(id);
  175. }
  176. },
  177. invalid_matrix_access: (id) => {
  178. const context = [id];
  179. return new SemanticError(LocalizedStrings.getError("invalid_matrix_access", context));
  180. },
  181. matrix_column_outbounds_full: (id, value, columns, sourceInfo) => {
  182. if(sourceInfo) {
  183. const context = [sourceInfo.line, value, id, columns];
  184. return new RuntimeError(LocalizedStrings.getError("matrix_column_outbounds_full", context));
  185. } else {
  186. return ProcessorErrorFactory.matrix_column_outbounds(id, value, columns);
  187. }
  188. },
  189. matrix_column_outbounds: (id, value, columns) => {
  190. const context = [value, id, columns];
  191. return new RuntimeError(LocalizedStrings.getError("matrix_column_outbounds", context));
  192. },
  193. matrix_line_outbounds_full: (id, value, lines, sourceInfo) => {
  194. if(sourceInfo) {
  195. const context = [sourceInfo.line, value, id, lines];
  196. return new RuntimeError(LocalizedStrings.getError("matrix_line_outbounds_full", context));
  197. } else {
  198. return ProcessorErrorFactory.matrix_line_outbounds(id, value, lines);
  199. }
  200. },
  201. matrix_line_outbounds: (id, value, lines) => {
  202. const context = [value, id, lines];
  203. return new RuntimeError(LocalizedStrings.getError("matrix_line_outbounds", context));
  204. },
  205. vector_line_outbounds_full: (id, value, lines, sourceInfo) => {
  206. if(sourceInfo) {
  207. const context = [sourceInfo.line, value, id, lines];
  208. return new RuntimeError(LocalizedStrings.getError("vector_line_outbounds_full", context));
  209. } else {
  210. return ProcessorErrorFactory.vector_line_outbounds(id, value, lines);
  211. }
  212. },
  213. vector_line_outbounds: (id, value, lines) => {
  214. const context = [value, id, lines];
  215. return new RuntimeError(LocalizedStrings.getError("vector_line_outbounds", context));
  216. },
  217. vector_not_matrix_full: (id, sourceInfo) => {
  218. if(sourceInfo) {
  219. const context = [sourceInfo.line, id];
  220. return new RuntimeError(LocalizedStrings.getError("vector_not_matrix_full", context));
  221. } else {
  222. return ProcessorErrorFactory.vector_not_matrix(id);
  223. }
  224. },
  225. vector_not_matrix: (id) => {
  226. const context = [id];
  227. return new RuntimeError(LocalizedStrings.getError("vector_not_matrix", context));
  228. },
  229. function_no_return: (id) => {
  230. const context = [id];
  231. return new SemanticError(LocalizedStrings.getError("function_no_return", context));
  232. },
  233. invalid_void_return_full: (id, type, dim, sourceInfo) => {
  234. if(sourceInfo) {
  235. const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];
  236. return new SemanticError(LocalizedStrings.getError("invalid_void_return_full", context));
  237. } else {
  238. return ProcessorErrorFactory.invalid_void_return(id, type, dim);
  239. }
  240. },
  241. invalid_void_return: (id, type, dim) => {
  242. const context = [id, LocalizedStrings.translateType(type, dim)];
  243. return new SemanticError(LocalizedStrings.getError("invalid_void_return_full", context));
  244. },
  245. invalid_return_type_full: (id, type, dim, sourceInfo) => {
  246. if(sourceInfo) {
  247. const context = [sourceInfo.line, id, LocalizedStrings.translateType(type, dim)];
  248. return new SemanticError(LocalizedStrings.getError("invalid_return_type_full", context));
  249. } else {
  250. return ProcessorErrorFactory.invalid_return_type(id, type, dim);
  251. }
  252. },
  253. invalid_return_type: (id, type, dim) => {
  254. const context = [id, LocalizedStrings.translateType(type, dim)];
  255. return new SemanticError(LocalizedStrings.getError("invalid_return_type", context));
  256. },
  257. invalid_parameters_size_full: (id, expected, actual, sourceInfo) => {
  258. if(sourceInfo) {
  259. const context = [sourceInfo.line, id, expected, actual];
  260. return new SemanticError(LocalizedStrings.getError("invalid_parameters_size_full", context));
  261. } else {
  262. return ProcessorErrorFactory.invalid_parameters_size(id, expected, actual);
  263. }
  264. },
  265. invalid_parameters_size: (id, expected, actual) => {
  266. const context = [id, expected, actual];
  267. return new SemanticError(LocalizedStrings.getError("invalid_parameters_size", context));
  268. },
  269. invalid_parameter_type_full: (id, exp, sourceInfo) => {
  270. if(sourceInfo) {
  271. const context = [exp, id, sourceInfo.line];
  272. return new SemanticError(LocalizedStrings.getError("invalid_parameter_type_full", context));
  273. } else {
  274. return ProcessorErrorFactory.invalid_parameter_type(id, exp);
  275. }
  276. },
  277. invalid_parameter_type: (id, exp) => {
  278. const context = [exp, id];
  279. return new SemanticError(LocalizedStrings.getError("invalid_parameter_type_full", context));
  280. },
  281. invalid_ref_full: (id, exp, sourceInfo) => {
  282. if(sourceInfo) {
  283. const context = [exp, id , sourceInfo.line];
  284. return new SemanticError(LocalizedStrings.getError("invalid_ref_full", context));
  285. } else {
  286. return ProcessorErrorFactory.invalid_ref(id, exp);
  287. }
  288. },
  289. invalid_ref: (id, exp) => {
  290. const context = [exp, id];
  291. return new SemanticError(LocalizedStrings.getError("invalid_ref", context));
  292. },
  293. unexpected_break_command_full: (sourceInfo) => {
  294. if(sourceInfo) {
  295. const context = [sourceInfo.line];
  296. return new RuntimeError(LocalizedStrings.getError("unexpected_break_command_full", context));
  297. } else {
  298. return ProcessorErrorFactory.unexpected_break_command();
  299. }
  300. },
  301. unexpected_break_command: () => {
  302. return new RuntimeError(LocalizedStrings.getError("unexpected_break_command"));
  303. },
  304. invalid_array_literal_type_full: (exp, sourceInfo) => {
  305. if(sourceInfo) {
  306. const context = [sourceInfo.line, exp];
  307. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_type_full", context));
  308. } else {
  309. return ProcessorErrorFactory.invalid_array_literal_type(exp);
  310. }
  311. },
  312. invalid_array_literal_type: (exp) => {
  313. const context = [exp];
  314. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_type", context));
  315. },
  316. invalid_array_literal_line_full: (expected, actual, sourceInfo) => {
  317. if(sourceInfo) {
  318. const context = [sourceInfo.line, expected, actual];
  319. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_line_full", context));
  320. } else {
  321. return ProcessorErrorFactory.invalid_array_literal_type(expected, actual);
  322. }
  323. },
  324. invalid_array_literal_line: (expected, actual) => {
  325. const context = [expected, actual];
  326. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_line", context));
  327. },
  328. invalid_array_literal_column_full: (expected, actual, sourceInfo) => {
  329. if(sourceInfo) {
  330. const context = [sourceInfo.line, expected, actual];
  331. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_column_full", context));
  332. } else {
  333. return ProcessorErrorFactory.invalid_array_literal_column(expected, actual);
  334. }
  335. },
  336. invalid_array_literal_column: (expected, actual) => {
  337. const context = [expected, actual];
  338. return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_column", context));
  339. },
  340. invalid_unary_op_full: (opName, type, dim, sourceInfo) => {
  341. if(sourceInfo) {
  342. const context = [sourceInfo.line, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
  343. return new RuntimeError(LocalizedStrings.getError("invalid_unary_op_full", context));
  344. } else {
  345. return ProcessorErrorFactory.invalid_unary_op(opName, type, dim);
  346. }
  347. },
  348. invalid_unary_op: (opName, type, dim) => {
  349. const context = [LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
  350. return new RuntimeError(LocalizedStrings.getError("invalid_unary_op", context));
  351. },
  352. invalid_infix_op_full: (opName, typeLeft, dimLeft, typeRight, dimRight, sourceInfo) => {
  353. if(sourceInfo) {
  354. const context = [sourceInfo.line, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
  355. return new RuntimeError(LocalizedStrings.getError("invalid_infix_op_full", context));
  356. } else {
  357. return ProcessorErrorFactory.invalid_infix_op(opName, typeLeft, dimLeft, typeRight, dimRight);
  358. }
  359. },
  360. invalid_infix_op: (opName, typeLeft, dimLeft, typeRight, dimRight) => {
  361. const context = [LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
  362. return new RuntimeError(LocalizedStrings.getError("invalid_infix_op", context));
  363. },
  364. array_dimension_not_positive_full: (sourceInfo) => {
  365. if(sourceInfo) {
  366. const context = [sourceInfo.line];
  367. return new SemanticError(LocalizedStrings.getError("array_dimension_not_positive_full", context));
  368. } else {
  369. return ProcessorErrorFactory.array_dimension_not_positive();
  370. }
  371. },
  372. array_dimension_not_positive: () => {
  373. return new SemanticError(LocalizedStrings.getError("array_dimension_not_positive"));
  374. },
  375. invalid_type_conversion: (value, type, dim) => {
  376. const context = [value, LocalizedStrings.translateType(type, dim)];
  377. return new RuntimeError(LocalizedStrings.getError("invalid_type_conversion", context));
  378. }
  379. });