processorErrorFactory.js 28 KB

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