processorErrorFactory.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. import { RuntimeError } from "./runtimeError";
  2. import { SemanticError } from "./semanticError";
  3. import * as LocalizedStringsService from "./../../services/localizedStringsService";
  4. import { LanguageDefinedFunction } from "../definedFunctions";
  5. function createRuntimeError (i18n_id, context = []) {
  6. const LocalizedStrings = LocalizedStringsService.getInstance();
  7. return new RuntimeError(LocalizedStrings.getError(i18n_id, context), i18n_id);
  8. }
  9. function createSemanticError (i18n_id, context = []) {
  10. const LocalizedStrings = LocalizedStringsService.getInstance();
  11. return new SemanticError(
  12. LocalizedStrings.getError(i18n_id, context),
  13. i18n_id
  14. );
  15. }
  16. export const ProcessorErrorFactory = Object.freeze({
  17. symbol_not_found_full: (id, sourceInfo) => {
  18. if (sourceInfo) {
  19. const context = [id, sourceInfo.line, sourceInfo.column];
  20. const error = createSemanticError("symbol_not_found_full", context);
  21. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  22. return error;
  23. } else {
  24. return ProcessorErrorFactory.symbol_not_found(id);
  25. }
  26. },
  27. symbol_not_found: (id) => {
  28. const context = [id];
  29. return createSemanticError("symbol_not_found", context);
  30. },
  31. function_missing_full: (id, sourceInfo) => {
  32. if (sourceInfo) {
  33. const context = [id, sourceInfo.line, sourceInfo.column];
  34. const error = createSemanticError("function_missing_full", context);
  35. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  36. return error;
  37. } else {
  38. return ProcessorErrorFactory.function_missing(id);
  39. }
  40. },
  41. function_missing: (id) => {
  42. const context = [id];
  43. return createSemanticError("function_missing", context);
  44. },
  45. main_missing: () => {
  46. return createSemanticError("main_missing");
  47. },
  48. array_dimension_not_int_full: (sourceInfo) => {
  49. if (sourceInfo) {
  50. const context = [sourceInfo.line];
  51. const error = createSemanticError(
  52. "array_dimension_not_int_full",
  53. context
  54. );
  55. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  56. return error;
  57. } else {
  58. return ProcessorErrorFactory.array_dimension_not_int();
  59. }
  60. },
  61. array_dimension_not_int: () => {
  62. return createSemanticError("array_dimension_not_int");
  63. },
  64. unknown_command_full: (sourceInfo) => {
  65. if (sourceInfo) {
  66. const context = [sourceInfo.line];
  67. const error = createRuntimeError("unknown_command_full", context);
  68. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  69. return error;
  70. } else {
  71. return ProcessorErrorFactory.unknown_command();
  72. }
  73. },
  74. unknown_command: () => {
  75. return createRuntimeError("unknown_command");
  76. },
  77. incompatible_types_full: (
  78. left_type,
  79. left_dim,
  80. right_type,
  81. right_dim,
  82. exp,
  83. source_info
  84. ) => {
  85. const LocalizedStrings = LocalizedStringsService.getInstance();
  86. if (source_info) {
  87. const context = [
  88. LocalizedStrings.translateType(left_type, left_dim),
  89. exp,
  90. source_info.line,
  91. LocalizedStrings.translateType(right_type, right_dim),
  92. ];
  93. const error = createSemanticError("incompatible_types_full", context);
  94. error.context = { line: source_info.line, column: source_info.column };
  95. return error;
  96. } else {
  97. return ProcessorErrorFactory.incompatible_types(
  98. left_type,
  99. left_dim,
  100. right_type,
  101. right_dim,
  102. exp
  103. );
  104. }
  105. },
  106. incompatible_types: (left_type, left_dim, right_type, right_dim, exp) => {
  107. const LocalizedStrings = LocalizedStringsService.getInstance();
  108. const context = [
  109. LocalizedStrings.translateType(left_type, left_dim),
  110. exp,
  111. LocalizedStrings.translateType(right_type, right_dim),
  112. ];
  113. return createSemanticError("incompatible_types", context);
  114. },
  115. incompatible_types_array_full: (exp, type, dim, sourceInfo) => {
  116. const LocalizedStrings = LocalizedStringsService.getInstance();
  117. if (sourceInfo) {
  118. const context = [
  119. exp,
  120. LocalizedStrings.translateType(type, dim),
  121. sourceInfo.line,
  122. sourceInfo.column,
  123. ];
  124. const error = createSemanticError(
  125. "incompatible_types_array_full",
  126. context
  127. );
  128. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  129. return error;
  130. } else {
  131. return ProcessorErrorFactory.incompatible_types_array(exp, type, dim);
  132. }
  133. },
  134. incompatible_types_array: (exp, type, dim) => {
  135. const LocalizedStrings = LocalizedStringsService.getInstance();
  136. const context = [exp, LocalizedStrings.translateType(type, dim)];
  137. return createSemanticError("incompatible_types_array", context);
  138. },
  139. loop_condition_type_full: (exp, sourceInfo) => {
  140. if (sourceInfo) {
  141. const context = [sourceInfo.line, sourceInfo.column, exp];
  142. const error = createSemanticError("loop_condition_type_full", context);
  143. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  144. return error;
  145. } else {
  146. return ProcessorErrorFactory.loop_condition_type(exp);
  147. }
  148. },
  149. loop_condition_type: (exp) => {
  150. const context = [exp];
  151. return createSemanticError("loop_condition_type", context);
  152. },
  153. /**
  154. * @deprecated 01/10/2019
  155. */
  156. endless_loop_full: (sourceInfo) => {
  157. if (sourceInfo) {
  158. const context = [sourceInfo.line];
  159. const error = createSemanticError("endless_loop_full", context);
  160. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  161. return error;
  162. } else {
  163. return ProcessorErrorFactory.endless_loop();
  164. }
  165. },
  166. endless_loop: () => {
  167. return createSemanticError("endless_loop");
  168. },
  169. if_condition_type_full: (exp, sourceInfo) => {
  170. if (sourceInfo) {
  171. const context = [sourceInfo.line, sourceInfo.column, exp];
  172. const error = createSemanticError("if_condition_type_full", context);
  173. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  174. return error;
  175. } else {
  176. return ProcessorErrorFactory.if_condition_type(exp);
  177. }
  178. },
  179. if_condition_type: (exp) => {
  180. const context = [exp];
  181. return createSemanticError("if_condition_type", context);
  182. },
  183. invalid_global_var: () => {
  184. return createRuntimeError("invalid_global_var");
  185. },
  186. not_implemented: (id) => {
  187. const context = [id];
  188. return createRuntimeError("not_implemented", context);
  189. },
  190. invalid_case_type_full: (exp, type, dim, sourceInfo) => {
  191. const LocalizedStrings = LocalizedStringsService.getInstance();
  192. if (sourceInfo) {
  193. const context = [
  194. exp,
  195. LocalizedStrings.translateType(type, dim),
  196. sourceInfo.line,
  197. sourceInfo.column,
  198. ];
  199. const error = createSemanticError("invalid_case_type_full", context);
  200. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  201. return error;
  202. } else {
  203. return ProcessorErrorFactory.invalid_case_type(exp, type, dim);
  204. }
  205. },
  206. invalid_case_type: (exp, type, dim) => {
  207. const LocalizedStrings = LocalizedStringsService.getInstance();
  208. const context = [exp, LocalizedStrings.translateType(type, dim)];
  209. return createSemanticError("invalid_case_type", context);
  210. },
  211. void_in_expression_full: (id, sourceInfo) => {
  212. if (sourceInfo) {
  213. const context = [sourceInfo.line, sourceInfo.column, id];
  214. const error = createSemanticError("void_in_expression_full", context);
  215. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  216. return error;
  217. } else {
  218. return ProcessorErrorFactory.void_in_expression(id);
  219. }
  220. },
  221. void_in_expression: (id) => {
  222. const context = [id];
  223. return createSemanticError("void_in_expression", context);
  224. },
  225. invalid_array_access_full: (id, sourceInfo) => {
  226. if (sourceInfo) {
  227. const context = [id, sourceInfo.line, sourceInfo.column];
  228. const error = createSemanticError("invalid_array_access_full", context);
  229. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  230. return error;
  231. } else {
  232. return ProcessorErrorFactory.invalid_array_access(id);
  233. }
  234. },
  235. invalid_array_access: (id) => {
  236. const context = [id];
  237. return createSemanticError("invalid_array_access", context);
  238. },
  239. invalid_matrix_access_full: (id, sourceInfo) => {
  240. if (sourceInfo) {
  241. const context = [id, sourceInfo.line, sourceInfo.column];
  242. const error = createSemanticError("invalid_matrix_access_full", context);
  243. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  244. return error;
  245. } else {
  246. return ProcessorErrorFactory.invalid_matrix_access(id);
  247. }
  248. },
  249. invalid_matrix_access: (id) => {
  250. const context = [id];
  251. return createSemanticError("invalid_matrix_access", context);
  252. },
  253. matrix_column_outbounds_full: (id, value, columns, sourceInfo) => {
  254. if (sourceInfo) {
  255. const context = [sourceInfo.line, value, id, columns];
  256. const error = createRuntimeError("matrix_column_outbounds_full", context);
  257. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  258. return error;
  259. } else {
  260. return ProcessorErrorFactory.matrix_column_outbounds(id, value, columns);
  261. }
  262. },
  263. matrix_column_outbounds: (id, value, columns) => {
  264. const context = [value, id, columns];
  265. return createRuntimeError("matrix_column_outbounds", context);
  266. },
  267. matrix_line_outbounds_full: (id, value, lines, sourceInfo) => {
  268. if (sourceInfo) {
  269. const context = [sourceInfo.line, value, id, lines];
  270. const error = createRuntimeError("matrix_line_outbounds_full", context);
  271. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  272. return error;
  273. } else {
  274. return ProcessorErrorFactory.matrix_line_outbounds(id, value, lines);
  275. }
  276. },
  277. matrix_line_outbounds: (id, value, lines) => {
  278. const context = [value, id, lines];
  279. return createRuntimeError("matrix_line_outbounds", context);
  280. },
  281. vector_line_outbounds_full: (id, value, lines, sourceInfo) => {
  282. if (sourceInfo) {
  283. const context = [sourceInfo.line, value, id, lines];
  284. const error = createRuntimeError("vector_line_outbounds_full", context);
  285. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  286. return error;
  287. } else {
  288. return ProcessorErrorFactory.vector_line_outbounds(id, value, lines);
  289. }
  290. },
  291. vector_line_outbounds: (id, value, lines) => {
  292. const context = [value, id, lines];
  293. return createRuntimeError("vector_line_outbounds", context);
  294. },
  295. vector_not_matrix_full: (id, sourceInfo) => {
  296. if (sourceInfo) {
  297. const context = [sourceInfo.line, id];
  298. const error = createRuntimeError("vector_not_matrix_full", context);
  299. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  300. return error;
  301. } else {
  302. return ProcessorErrorFactory.vector_not_matrix(id);
  303. }
  304. },
  305. vector_not_matrix: (id) => {
  306. const context = [id];
  307. return createRuntimeError("vector_not_matrix", context);
  308. },
  309. function_no_return: (id) => {
  310. const context = [id];
  311. return createSemanticError("function_no_return", context);
  312. },
  313. invalid_void_return_full: (id, type, dim, sourceInfo) => {
  314. const LocalizedStrings = LocalizedStringsService.getInstance();
  315. if (sourceInfo) {
  316. const context = [
  317. sourceInfo.line,
  318. id,
  319. LocalizedStrings.translateType(type, dim),
  320. ];
  321. const error = createSemanticError("invalid_void_return_full", context);
  322. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  323. return error;
  324. } else {
  325. return ProcessorErrorFactory.invalid_void_return(id, type, dim);
  326. }
  327. },
  328. invalid_void_return: (id, type, dim) => {
  329. const LocalizedStrings = LocalizedStringsService.getInstance();
  330. const context = [id, LocalizedStrings.translateType(type, dim)];
  331. return createSemanticError("invalid_void_return_full", context);
  332. },
  333. invalid_return_type_full: (id, type, dim, sourceInfo) => {
  334. const LocalizedStrings = LocalizedStringsService.getInstance();
  335. if (sourceInfo) {
  336. const context = [
  337. sourceInfo.line,
  338. id,
  339. LocalizedStrings.translateType(type, dim),
  340. ];
  341. const error = createSemanticError("invalid_return_type_full", context);
  342. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  343. return error;
  344. } else {
  345. return ProcessorErrorFactory.invalid_return_type(id, type, dim);
  346. }
  347. },
  348. invalid_return_type: (id, type, dim) => {
  349. const LocalizedStrings = LocalizedStringsService.getInstance();
  350. const context = [id, LocalizedStrings.translateType(type, dim)];
  351. return createSemanticError("invalid_return_type", context);
  352. },
  353. invalid_parameters_size_full: (id, expected, actual, sourceInfo) => {
  354. if (sourceInfo) {
  355. const context = [sourceInfo.line, id, expected, actual];
  356. const error = createSemanticError(
  357. "invalid_parameters_size_full",
  358. context
  359. );
  360. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  361. return error;
  362. } else {
  363. return ProcessorErrorFactory.invalid_parameters_size(
  364. id,
  365. expected,
  366. actual
  367. );
  368. }
  369. },
  370. invalid_parameters_size: (id, expected, actual) => {
  371. const context = [id, expected, actual];
  372. return createSemanticError("invalid_parameters_size", context);
  373. },
  374. invalid_parameter_type_full: (fun_name, exp, sourceInfo) => {
  375. if (sourceInfo) {
  376. const context = [
  377. exp,
  378. LanguageDefinedFunction.getLocalName(fun_name),
  379. sourceInfo.line,
  380. ];
  381. const error = createSemanticError("invalid_parameter_type_full", context);
  382. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  383. return error;
  384. } else {
  385. return ProcessorErrorFactory.invalid_parameter_type(fun_name, exp);
  386. }
  387. },
  388. invalid_parameter_type: (fun_name, exp) => {
  389. const context = [exp, LanguageDefinedFunction.getLocalName(fun_name)];
  390. return createSemanticError("invalid_parameter_type_full", context);
  391. },
  392. invalid_ref_full: (id, exp, sourceInfo) => {
  393. if (sourceInfo) {
  394. const context = [exp, id, sourceInfo.line];
  395. const error = createSemanticError("invalid_ref_full", context);
  396. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  397. return error;
  398. } else {
  399. return ProcessorErrorFactory.invalid_ref(id, exp);
  400. }
  401. },
  402. invalid_ref: (id, exp) => {
  403. const context = [exp, id];
  404. return createSemanticError("invalid_ref", context);
  405. },
  406. unexpected_break_command_full: (sourceInfo) => {
  407. if (sourceInfo) {
  408. const context = [sourceInfo.line];
  409. const error = createRuntimeError(
  410. "unexpected_break_command_full",
  411. context
  412. );
  413. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  414. return error;
  415. } else {
  416. return ProcessorErrorFactory.unexpected_break_command();
  417. }
  418. },
  419. unexpected_break_command: () => {
  420. return createRuntimeError("unexpected_break_command");
  421. },
  422. invalid_array_literal_type_full: (exp, sourceInfo) => {
  423. if (sourceInfo) {
  424. const context = [sourceInfo.line, exp];
  425. const error = createRuntimeError(
  426. "invalid_array_literal_type_full",
  427. context
  428. );
  429. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  430. return error;
  431. } else {
  432. return ProcessorErrorFactory.invalid_array_literal_type(exp);
  433. }
  434. },
  435. invalid_array_literal_type: (exp) => {
  436. const context = [exp];
  437. return createRuntimeError("invalid_array_literal_type", context);
  438. },
  439. invalid_array_literal_line_full: (expected, actual, sourceInfo) => {
  440. if (sourceInfo) {
  441. const context = [sourceInfo.line, expected, actual];
  442. const error = createRuntimeError(
  443. "invalid_array_literal_line_full",
  444. context
  445. );
  446. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  447. return error;
  448. } else {
  449. return ProcessorErrorFactory.invalid_array_literal_type(expected, actual);
  450. }
  451. },
  452. invalid_array_literal_line: (expected, actual) => {
  453. const context = [expected, actual];
  454. return createRuntimeError("invalid_array_literal_line", context);
  455. },
  456. invalid_array_literal_column_full: (expected, actual, sourceInfo) => {
  457. if (sourceInfo) {
  458. const context = [sourceInfo.line, expected, actual];
  459. const error = createRuntimeError(
  460. "invalid_array_literal_column_full",
  461. context
  462. );
  463. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  464. return error;
  465. } else {
  466. return ProcessorErrorFactory.invalid_array_literal_column(
  467. expected,
  468. actual
  469. );
  470. }
  471. },
  472. invalid_array_literal_column: (expected, actual) => {
  473. const context = [expected, actual];
  474. return createRuntimeError("invalid_array_literal_column", context);
  475. },
  476. invalid_unary_op_full: (expString, opName, type, dim, sourceInfo) => {
  477. const LocalizedStrings = LocalizedStringsService.getInstance();
  478. if (sourceInfo) {
  479. const context = [
  480. sourceInfo.line,
  481. expString,
  482. LocalizedStrings.translateOp(opName),
  483. LocalizedStrings.translateType(type, dim),
  484. ];
  485. const error = createRuntimeError("invalid_unary_op_full", context);
  486. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  487. return error;
  488. } else {
  489. return ProcessorErrorFactory.invalid_unary_op(opName, type, dim);
  490. }
  491. },
  492. invalid_unary_op: (expString, opName, type, dim) => {
  493. const LocalizedStrings = LocalizedStringsService.getInstance();
  494. const context = [
  495. expString,
  496. LocalizedStrings.translateOp(opName),
  497. LocalizedStrings.translateType(type, dim),
  498. ];
  499. return createRuntimeError("invalid_unary_op", context);
  500. },
  501. invalid_infix_op_full: (
  502. expString,
  503. opName,
  504. typeLeft,
  505. dimLeft,
  506. typeRight,
  507. dimRight,
  508. sourceInfo
  509. ) => {
  510. const LocalizedStrings = LocalizedStringsService.getInstance();
  511. if (sourceInfo) {
  512. const context = [
  513. sourceInfo.line,
  514. expString,
  515. LocalizedStrings.translateOp(opName),
  516. LocalizedStrings.translateType(typeLeft, dimLeft),
  517. LocalizedStrings.translateType(typeRight, dimRight),
  518. ];
  519. const error = createRuntimeError("invalid_infix_op_full", context);
  520. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  521. return error;
  522. } else {
  523. return ProcessorErrorFactory.invalid_infix_op(
  524. opName,
  525. typeLeft,
  526. dimLeft,
  527. typeRight,
  528. dimRight
  529. );
  530. }
  531. },
  532. invalid_infix_op: (
  533. expString,
  534. opName,
  535. typeLeft,
  536. dimLeft,
  537. typeRight,
  538. dimRight
  539. ) => {
  540. const LocalizedStrings = LocalizedStringsService.getInstance();
  541. const context = [
  542. expString,
  543. LocalizedStrings.translateOp(opName),
  544. LocalizedStrings.translateType(typeLeft, dimLeft),
  545. LocalizedStrings.translateType(typeRight, dimRight),
  546. ];
  547. return createRuntimeError("invalid_infix_op", context);
  548. },
  549. array_dimension_not_positive_full: (sourceInfo) => {
  550. if (sourceInfo) {
  551. const context = [sourceInfo.line];
  552. const error = createSemanticError(
  553. "array_dimension_not_positive_full",
  554. context
  555. );
  556. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  557. return error;
  558. } else {
  559. return ProcessorErrorFactory.array_dimension_not_positive();
  560. }
  561. },
  562. array_dimension_not_positive: () => {
  563. return createSemanticError("array_dimension_not_positive");
  564. },
  565. invalid_type_conversion: (value, type, dim) => {
  566. const LocalizedStrings = LocalizedStringsService.getInstance();
  567. const context = [value, LocalizedStrings.translateType(type, dim)];
  568. return createRuntimeError("invalid_type_conversion", context);
  569. },
  570. invalid_read_type: (exp, type, dim, name, source_info) => {
  571. const LocalizedStrings = LocalizedStringsService.getInstance();
  572. const context = [
  573. source_info.line,
  574. exp,
  575. LocalizedStrings.translateType(type, dim),
  576. name,
  577. ];
  578. const error = createRuntimeError("invalid_read_type", context);
  579. error.context = { line: source_info.line, column: source_info.column };
  580. return error;
  581. },
  582. invalid_read_type_array: (
  583. exp,
  584. typePos,
  585. dimPos,
  586. name,
  587. typeArray,
  588. dimArray,
  589. sourceInfo
  590. ) => {
  591. const LocalizedStrings = LocalizedStringsService.getInstance();
  592. const context = [
  593. sourceInfo.line,
  594. exp,
  595. LocalizedStrings.translateType(typePos, dimPos),
  596. name,
  597. LocalizedStrings.translateType(typeArray, dimArray),
  598. ];
  599. const error = createRuntimeError("invalid_read_type_array", context);
  600. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  601. return error;
  602. },
  603. invalid_const_ref_full: (fun_name, exp, sourceInfo) => {
  604. if (sourceInfo) {
  605. const context = [
  606. exp,
  607. LanguageDefinedFunction.getLocalName(fun_name),
  608. sourceInfo.line,
  609. ];
  610. const error = createSemanticError("invalid_const_ref_full", context);
  611. error.context = { line: sourceInfo.line, column: sourceInfo.column };
  612. return error;
  613. } else {
  614. return ProcessorErrorFactory.invalid_const_ref(fun_name, exp);
  615. }
  616. },
  617. invalid_const_ref: (fun_name, exp) => {
  618. const context = [exp, LanguageDefinedFunction.getLocalName(fun_name)];
  619. const error = createSemanticError("invalid_const_ref", context);
  620. return error;
  621. },
  622. invalid_const_assignment_full: (var_id, source_info) => {
  623. if (source_info) {
  624. const context = [source_info.line, var_id];
  625. const error = createSemanticError(
  626. "invalid_const_assignment_full",
  627. context
  628. );
  629. error.context = { line: source_info.line, column: source_info.column };
  630. return error;
  631. } else {
  632. return ProcessorErrorFactory.invalid_const_assignment(var_id);
  633. }
  634. },
  635. invalid_const_assignment: (var_id) => {
  636. const context = [var_id];
  637. return createSemanticError("invalid_const_assignment", context);
  638. },
  639. invalid_vector_assignment_full: (
  640. left_id,
  641. left_size,
  642. right_id,
  643. right_size,
  644. source_info
  645. ) => {
  646. if (source_info) {
  647. const context = [
  648. source_info.line,
  649. left_id,
  650. left_size,
  651. right_id,
  652. right_size,
  653. ];
  654. const error = createRuntimeError(
  655. "invalid_vector_assignment_full",
  656. context
  657. );
  658. error.context = { line: source_info.line, column: source_info.column };
  659. return error;
  660. } else {
  661. return ProcessorErrorFactory.invalid_vector_assignment(
  662. left_id,
  663. left_size,
  664. right_id,
  665. right_size
  666. );
  667. }
  668. },
  669. invalid_vector_assignment: (left_id, left_size, right_id, right_size) => {
  670. const context = [left_id, left_size, right_id, right_size];
  671. return createRuntimeError("invalid_vector_assignment", context);
  672. },
  673. invalid_matrix_assignment_full: (
  674. left_id,
  675. left_line,
  676. left_column,
  677. right_id,
  678. right_line,
  679. right_column,
  680. source_info
  681. ) => {
  682. if (source_info) {
  683. const context = [
  684. source_info.line,
  685. left_id,
  686. left_line,
  687. left_column,
  688. right_id,
  689. right_line,
  690. right_column,
  691. ];
  692. const error = createRuntimeError(
  693. "invalid_matrix_assignment_full",
  694. context
  695. );
  696. error.context = { line: source_info.line, column: source_info.column };
  697. return error;
  698. } else {
  699. return ProcessorErrorFactory.invalid_matrix_assignment(
  700. left_id,
  701. left_line,
  702. left_column,
  703. right_id,
  704. right_line,
  705. right_column
  706. );
  707. }
  708. },
  709. invalid_matrix_assignment: (
  710. left_id,
  711. left_line,
  712. left_column,
  713. right_id,
  714. right_line,
  715. right_column
  716. ) => {
  717. const context = [
  718. left_id,
  719. left_line,
  720. left_column,
  721. right_id,
  722. right_line,
  723. right_column,
  724. ];
  725. return createRuntimeError("invalid_matrix_assignment", context);
  726. },
  727. matrix_to_vector_attr: (left_id, right_id, source_info) => {
  728. // SourceInfo have to be valid...
  729. const context = [source_info.line, right_id, left_id];
  730. const error = createSemanticError("matrix_to_vector_attr", context);
  731. error.context = { line: source_info.line, column: source_info.column };
  732. return error;
  733. },
  734. vector_to_matrix_attr: (left_id, right_id, source_info) => {
  735. // SourceInfo have to be valid...
  736. const context = [source_info.line, right_id, left_id];
  737. const error = createSemanticError("vector_to_matrix_attr", context);
  738. error.context = { line: source_info.line, column: source_info.column };
  739. return error;
  740. },
  741. invalid_matrix_index_assign_full: (
  742. mat_id,
  743. mat_line,
  744. mat_size,
  745. exp,
  746. exp_size,
  747. source_info
  748. ) => {
  749. if (source_info) {
  750. const context = [
  751. source_info.line,
  752. mat_line,
  753. mat_id,
  754. mat_size,
  755. exp,
  756. exp_size,
  757. ];
  758. const error = createRuntimeError(
  759. "invalid_matrix_index_assign_full",
  760. context
  761. );
  762. error.context = { line: source_info.line, column: source_info.column };
  763. return error;
  764. } else {
  765. return ProcessorErrorFactory.invalid_matrix_index_assign(
  766. mat_id,
  767. mat_line,
  768. mat_size,
  769. exp,
  770. exp_size
  771. );
  772. }
  773. },
  774. invalid_matrix_index_assign: (mat_id, mat_line, mat_size, exp, exp_size) => {
  775. const context = [mat_line, mat_id, mat_size, exp, exp_size];
  776. return createRuntimeError("invalid_matrix_index_assign", context);
  777. },
  778. invalid_number_elements_vector: (
  779. expected_num,
  780. exp,
  781. actual_num,
  782. source_info
  783. ) => {
  784. // SourceInfo have to be valid...
  785. const context = [expected_num, source_info.line, exp, actual_num];
  786. const error = createRuntimeError("invalid_number_elements_vector", context);
  787. error.context = { line: source_info.line, column: source_info.column };
  788. return error;
  789. },
  790. invalid_number_lines_matrix: (expected_num, exp, actual_num, source_info) => {
  791. // SourceInfo have to be valid...
  792. const context = [expected_num, source_info.line, exp, actual_num];
  793. const error = createRuntimeError("invalid_number_lines_matrix", context);
  794. error.context = { line: source_info.line, column: source_info.column };
  795. return error;
  796. },
  797. divsion_by_zero_full: (exp, source_info) => {
  798. if (source_info) {
  799. const context = [source_info.line, exp];
  800. const error = createRuntimeError("divsion_by_zero_full", context);
  801. error.context = { line: source_info.line, column: source_info.column };
  802. return error;
  803. } else {
  804. return ProcessorErrorFactory.divsion_by_zero(exp);
  805. }
  806. },
  807. divsion_by_zero: (exp) => {
  808. const context = [exp];
  809. return createRuntimeError("divsion_by_zero", context);
  810. },
  811. undefined_tanget_value: (value, source_info) => {
  812. const context = [source_info.line, value];
  813. const error = createRuntimeError("undefined_tanget_value", context);
  814. error.context = { line: source_info.line, column: source_info.column };
  815. return error;
  816. },
  817. negative_log_value: (source_info) => {
  818. const error = createRuntimeError("negative_log_value", [source_info.line]);
  819. error.context = { line: source_info.line, column: source_info.column };
  820. return error;
  821. },
  822. invalid_string_index: (index, str, source_info) => {
  823. const local_fun_name = LanguageDefinedFunction.getLocalName("$charAt");
  824. const context = [
  825. source_info.line,
  826. local_fun_name,
  827. index,
  828. str,
  829. str.length - 1,
  830. ];
  831. const error = createRuntimeError("invalid_string_index", context);
  832. error.context = { line: source_info.line, column: source_info.column };
  833. return error;
  834. },
  835. negative_sqrt_value: (source_info) => {
  836. const error = createRuntimeError("negative_sqrt_value", [source_info.line]);
  837. error.context = { line: source_info.line, column: source_info.column };
  838. return error;
  839. },
  840. /**
  841. * @deprecated 01/10/2019
  842. */
  843. exceeded_recursive_calls: (source_info) => {
  844. const context = [source_info.line];
  845. const error = createRuntimeError("exceeded_recursive_calls", context);
  846. error.context = { line: source_info.line, column: source_info.column };
  847. return error;
  848. },
  849. invalid_for_variable: (id, source_info) => {
  850. const context = [source_info.line, id];
  851. const error = createSemanticError("invalid_for_variable", context);
  852. error.context = { line: source_info.line, column: source_info.column };
  853. return error;
  854. },
  855. invalid_for_from: (exp, source_info) => {
  856. const context = [source_info.line, exp];
  857. const error = createSemanticError("invalid_for_from", context);
  858. error.context = { line: source_info.line, column: source_info.column };
  859. return error;
  860. },
  861. invalid_for_to: (exp, source_info) => {
  862. const context = [source_info.line, exp];
  863. const error = createSemanticError("invalid_for_to", context);
  864. error.context = { line: source_info.line, column: source_info.column };
  865. return error;
  866. },
  867. invalid_for_pass: (exp, source_info) => {
  868. const context = [source_info.line, exp];
  869. const error = createSemanticError("invalid_for_pass", context);
  870. error.context = { line: source_info.line, column: source_info.column };
  871. return error;
  872. },
  873. exceed_max_instructions: () => {
  874. return createRuntimeError("exceed_max_instructions");
  875. },
  876. });