semanticAnalyser.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. import { ProcessorErrorFactory } from './../error/processorErrorFactory';
  2. import { LanguageDefinedFunction } from './../definedFunctions';
  3. import { LanguageService } from './../../services/languageService';
  4. import { ArrayDeclaration, While, For, Switch, Assign, Break, IfThenElse, Return, ArrayIndexAssign } from '../../ast/commands';
  5. import { InfixApp, UnaryApp, FunctionCall, IntLiteral, RealLiteral, StringLiteral, BoolLiteral, VariableLiteral, ArrayLiteral, ArrayAccess } from '../../ast/expressions';
  6. import { Literal } from '../../ast/expressions/literal';
  7. import { resultTypeAfterInfixOp, resultTypeAfterUnaryOp } from '../compatibilityTable';
  8. import { Types } from '../../typeSystem/types';
  9. import { CompoundType } from '../../typeSystem/compoundType';
  10. import { MultiType } from '../../typeSystem/multiType';
  11. import { Config } from '../../util/config';
  12. import { Store } from '../store/store';
  13. export class SemanticAnalyser {
  14. constructor(ast) {
  15. this.ast = ast;
  16. this.lexerClass = LanguageService.getCurrentLexer();
  17. const lexer = new this.lexerClass(null);
  18. this.literalNames = lexer.literalNames;
  19. this.symbolMap = null;
  20. this.currentFunction = null;
  21. }
  22. pushMap () {
  23. if(this.symbolMap === null) {
  24. this.symbolMap = {map:{}, next: null};
  25. } else {
  26. const n = {map:{}, next: this.symbolMap};
  27. this.symbolMap = n;
  28. }
  29. }
  30. popMap () {
  31. if(this.symbolMap !== null) {
  32. this.symbolMap = this.symbolMap.next;
  33. }
  34. }
  35. insertSymbol (id, typeInfo) {
  36. this.symbolMap.map[id] = typeInfo;
  37. }
  38. findSymbol (id, symMap) {
  39. if(!symMap.map[id]) {
  40. if(symMap.next) {
  41. return this.findSymbol(id, symMap.next);
  42. }
  43. return null;
  44. } else {
  45. return symMap.map[id];
  46. }
  47. }
  48. getMainFunction () {
  49. return this.ast.functions.find(v => v.isMain);
  50. }
  51. findFunction (name) {
  52. console.log(name);
  53. if(name.match(/^\$.+$/)) {
  54. const fun = LanguageDefinedFunction.getFunction(name);
  55. if(!!!fun) {
  56. throw ProcessorErrorFactory.not_implemented(name);
  57. }
  58. return fun;
  59. } else {
  60. const val = this.ast.functions.find( v => v.name === name);
  61. if (!!!val) {
  62. return null;
  63. }
  64. return val;
  65. }
  66. }
  67. analyseTree () {
  68. const globalVars = this.ast.global;
  69. this.pushMap();
  70. this.assertDeclarations(globalVars);
  71. const functions = this.ast.functions;
  72. const mainFunc = functions.filter((f) => f.name === null);
  73. if (mainFunc.length <= 0) {
  74. throw ProcessorErrorFactory.main_missing();
  75. }
  76. for (let i = 0; i < functions.length; i++) {
  77. const fun = functions[i];
  78. this.assertFunction(fun);
  79. }
  80. return this.ast;
  81. }
  82. assertDeclarations (list) {
  83. for (let i = 0; i < list.length; i++) {
  84. this.assertDeclaration(list[i]);
  85. }
  86. }
  87. assertDeclaration (declaration) {
  88. if (declaration instanceof ArrayDeclaration) {
  89. if(declaration.initial === null) {
  90. const lineType = this.evaluateExpressionType(declaration.lines);
  91. if (!lineType.isCompatible(Types.INTEGER)) {
  92. throw ProcessorErrorFactory.array_dimension_not_int_full(declaration.sourceInfo);
  93. }
  94. if (declaration.columns !== null) {
  95. const columnType = this.evaluateExpressionType(declaration.columns);
  96. if (!columnType.isCompatible(Types.INTEGER)) {
  97. throw ProcessorErrorFactory.array_dimension_not_int_full(declaration.sourceInfo);
  98. }
  99. }
  100. this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
  101. return;
  102. }
  103. this.evaluateArrayLiteral(declaration.id, declaration.lines, declaration.columns, declaration.type, declaration.initial);
  104. this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
  105. } else {
  106. if(declaration.initial === null) {
  107. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
  108. return;
  109. }
  110. const resultType = this.evaluateExpressionType(declaration.initial);
  111. if(resultType instanceof MultiType) {
  112. if(!resultType.isCompatible(declaration.type)) {
  113. const stringInfo = declaration.type.stringInfo();
  114. const info = stringInfo[0];
  115. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
  116. }
  117. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type})
  118. } else if((!declaration.type.isCompatible(resultType) && !Config.enable_type_casting)
  119. || (!declaration.type.isCompatible(resultType) && Config.enable_type_casting
  120. && !Store.canImplicitTypeCast(declaration.type, resultType))) {
  121. const stringInfo = declaration.type.stringInfo();
  122. const info = stringInfo[0];
  123. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
  124. } else {
  125. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
  126. }
  127. }
  128. }
  129. evaluateExpressionType (expression) {
  130. if(expression instanceof UnaryApp) {
  131. const op = expression.op;
  132. const resultType = this.evaluateExpressionType(expression.left);
  133. return resultTypeAfterUnaryOp(op, resultType);
  134. } else if (expression instanceof InfixApp) {
  135. const op = expression.op;
  136. const resultTypeLeft = this.evaluateExpressionType(expression.left);
  137. const resultTypeRight = this.evaluateExpressionType(expression.right);
  138. return resultTypeAfterInfixOp(op, resultTypeLeft, resultTypeRight);
  139. } else if (expression instanceof Literal) {
  140. return this.evaluateLiteralType(expression);
  141. } else if (expression instanceof FunctionCall) {
  142. if (expression.isMainCall) {
  143. throw ProcessorErrorFactory.void_in_expression_full(LanguageDefinedFunction.getMainFunctionName(), expression.sourceInfo);
  144. }
  145. const fun = this.findFunction(expression.id);
  146. if(fun === null) {
  147. throw ProcessorErrorFactory.function_missing_full(expression.id, expression.sourceInfo);
  148. }
  149. if (fun.returnType.isCompatible(Types.VOID)) {
  150. throw ProcessorErrorFactory.void_in_expression_full(expression.id, expression.sourceInfo);
  151. }
  152. this.assertParameters(fun, expression.actualParameters);
  153. return fun.returnType;
  154. } else if (expression instanceof ArrayAccess) {
  155. const arrayTypeInfo = this.findSymbol(expression.id, this.symbolMap);
  156. if(arrayTypeInfo === null) {
  157. throw ProcessorErrorFactory.symbol_not_found_full(expression.id, expression.sourceInfo);
  158. }
  159. if (!(arrayTypeInfo.type instanceof CompoundType)) {
  160. throw ProcessorErrorFactory.invalid_array_access_full(expression.id, expression.sourceInfo);
  161. }
  162. const lineType = this.evaluateExpressionType(expression.line);
  163. if (!lineType.isCompatible(Types.INTEGER)) {
  164. throw ProcessorErrorFactory.array_dimension_not_int_full(expression.sourceInfo);
  165. }
  166. if (expression.column !== null) {
  167. if (arrayTypeInfo.columns === null) {
  168. throw ProcessorErrorFactory.invalid_matrix_access_full(expression.id, expression.sourceInfo);
  169. }
  170. const columnType = this.evaluateExpressionType(expression.column);
  171. if(!columnType.isCompatible(Types.INTEGER)) {
  172. throw ProcessorErrorFactory.array_dimension_not_int_full(expression.sourceInfo);
  173. }
  174. }
  175. const arrType = arrayTypeInfo.type;
  176. if(expression.column !== null) {
  177. // indexing matrix
  178. return arrType.innerType;
  179. } else {
  180. if(arrayTypeInfo.columns === null) {
  181. return arrType.innerType;
  182. }
  183. return new CompoundType(arrType.innerType, 1);
  184. }
  185. }
  186. }
  187. evaluateLiteralType (literal) {
  188. if(literal instanceof IntLiteral) {
  189. return literal.type;
  190. } else if (literal instanceof RealLiteral) {
  191. return literal.type;
  192. } else if (literal instanceof StringLiteral) {
  193. return literal.type;
  194. } else if (literal instanceof BoolLiteral) {
  195. return literal.type;
  196. } else if (literal instanceof VariableLiteral) {
  197. const typeInfo = this.findSymbol(literal.id, this.symbolMap);
  198. if(typeInfo === null) {
  199. throw ProcessorErrorFactory.symbol_not_found_full(literal.id, literal.sourceInfo);
  200. }
  201. if (typeInfo.type instanceof CompoundType) {
  202. return typeInfo.type;
  203. }
  204. return typeInfo.type;
  205. } else {
  206. console.warn("Evaluating type only for an array literal...");
  207. let last = null;
  208. if(literal.value.length === 1) {
  209. last = this.evaluateExpressionType(literal.value[0]);
  210. } else {
  211. for (let i = 0; i < literal.value.length; i++) {
  212. const e = this.evaluateExpressionType(literal.value[i]);
  213. if(last === null) {
  214. last = e;
  215. } else if(!last.isCompatible(e)) {
  216. const strInfo = last.stringInfo();
  217. const info = strInfo[0];
  218. const strExp = literal.toString();
  219. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  220. }
  221. }
  222. }
  223. if(last instanceof CompoundType) {
  224. return new CompoundType(last.innerType, last.dimensions + 1);
  225. }
  226. return new CompoundType(last, 1);
  227. }
  228. }
  229. evaluateArrayLiteral (id, lines, columns, type, literal) {
  230. /* if (literal instanceof ArrayLiteral) {
  231. const dimType = this.evaluateExpressionType(lines);
  232. if (!dimType.isCompatible(Types.INTEGER)) {
  233. throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
  234. }
  235. if ((lines instanceof IntLiteral)) {
  236. if (!lines.value.eq(literal.value.length)) {
  237. if(type.dimensions > 1) {
  238. throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
  239. } else {
  240. throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
  241. }
  242. } else if (lines.value.isNeg()) {
  243. throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
  244. }
  245. }
  246. if (columns === null) {
  247. // it's a vector...
  248. literal.value.reduce((last, next) => {
  249. const eType = this.evaluateExpressionType(next);
  250. if (!last.canAccept(eType)) {
  251. const strInfo = last.stringInfo();
  252. const info = strInfo[0];
  253. const strExp = literal.toString();
  254. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  255. }
  256. return last;
  257. }, type);
  258. return true;
  259. } else {
  260. const dimType = this.evaluateExpressionType(columns);
  261. if (!dimType.isCompatible(Types.INTEGER)) {
  262. throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
  263. }
  264. if ((columns instanceof IntLiteral)) {
  265. const columnValue = literal.value[0].value.length;
  266. if (!columns.value.eq(columnValue)) {
  267. if(type.dimensions > 1) {
  268. throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.value.toNumber(), literal.sourceInfo)
  269. } else {
  270. throw ProcessorErrorFactory.invalid_matrix_access_full(id, literal.sourceInfo);
  271. }
  272. } else if (columns.value.isNeg()) {
  273. throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
  274. }
  275. for (let i = 0; i < columns; i++) {
  276. const anotherArray = literal.value[i];
  277. this.evaluateArrayLiteral(id, columns, null, type, anotherArray)
  278. }
  279. }
  280. }
  281. } else {
  282. const resultType = this.evaluateExpressionType(literal);
  283. if (!(resultType instanceof CompoundType)) {
  284. const strInfo = type.stringInfo();
  285. const info = strInfo[0];
  286. const strExp = literal.toString();
  287. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  288. }
  289. if (!type.isCompatible(resultType)) {
  290. const strInfo = type.stringInfo();
  291. const info = strInfo[0];
  292. const strExp = literal.toString();
  293. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  294. }
  295. return true;
  296. } */
  297. return true;
  298. }
  299. assertFunction (fun) {
  300. this.pushMap();
  301. this.currentFunction = fun;
  302. fun.formalParameters.forEach(formalParam => {
  303. if(formalParam.type instanceof CompoundType) {
  304. if(formalParam.type.dimensions > 1) {
  305. this.insertSymbol(formalParam.id, {id: formalParam.id, lines: -1, columns: -1, type: formalParam.type});
  306. } else {
  307. this.insertSymbol(formalParam.id, {id: formalParam.id, lines: -1, columns: null, type: formalParam.type});
  308. }
  309. } else {
  310. this.insertSymbol(formalParam.id, {id: formalParam.id, type: formalParam.type});
  311. }
  312. })
  313. this.assertDeclarations(fun.variablesDeclarations);
  314. const optional = fun.returnType.isCompatible(Types.VOID);
  315. const valid = this.assertReturn(fun, optional);
  316. if (!valid) {
  317. throw ProcessorErrorFactory.function_no_return(fun.name);
  318. }
  319. this.popMap();
  320. }
  321. assertReturn (fun, optional) {
  322. return fun.commands.reduce(
  323. (last, next) => this.checkCommand(fun.returnType, next, optional) || last, optional
  324. );
  325. }
  326. checkCommand (type, cmd, optional) {
  327. if (cmd instanceof While) {
  328. const resultType = this.evaluateExpressionType(cmd.expression);
  329. if (!resultType.isCompatible(Types.BOOLEAN)) {
  330. throw ProcessorErrorFactory.loop_condition_type_full(cmd.sourceInfo);
  331. }
  332. this.checkCommands(type, cmd.commands, optional);
  333. return false;
  334. } else if (cmd instanceof For) {
  335. this.checkCommand(type, cmd.assignment, optional);
  336. const resultType = this.evaluateExpressionType(cmd.condition);
  337. if (!resultType.isCompatible(Types.BOOLEAN)) {
  338. throw ProcessorErrorFactory.for_condition_type_full(cmd.sourceInfo);
  339. }
  340. this.checkCommand(type, cmd.increment, optional);
  341. this.checkCommands(type, cmd.commands, optional);
  342. return false;
  343. } else if (cmd instanceof Switch) {
  344. const sType = this.evaluateExpressionType(cmd.expression);
  345. let result = optional;
  346. let hasDefault = false;
  347. for (let i = 0; i < cmd.cases.length; i++) {
  348. const aCase = cmd.cases[i];
  349. if (aCase.expression !== null) {
  350. const caseType = this.evaluateExpressionType(aCase.expression);
  351. if (!sType.isCompatible(caseType)) {
  352. const strInfo = sType.stringInfo();
  353. const info = strInfo[0];
  354. const strExp = aCase.expression.toString();
  355. throw ProcessorErrorFactory.invalid_case_type_full(strExp, info.type, info.dim, aCase.sourceInfo);
  356. }
  357. } else {
  358. hasDefault = true;
  359. }
  360. result = result && this.checkCommands(type, aCase.commands, result);
  361. }
  362. return result && hasDefault;
  363. } else if (cmd instanceof ArrayIndexAssign) {
  364. const typeInfo = this.findSymbol(cmd.id, this.symbolMap);
  365. if(typeInfo === null) {
  366. throw ProcessorErrorFactory.symbol_not_found_full(cmd.id, cmd.sourceInfo);
  367. }
  368. if(!(typeInfo.type instanceof CompoundType)) {
  369. throw ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo);
  370. }
  371. const exp = cmd.expression;
  372. const lineExp = cmd.line;
  373. const lineType = this.evaluateExpressionType(lineExp);
  374. if (!lineType.isCompatible(Types.INTEGER)) {
  375. throw ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo);
  376. }
  377. const columnExp = cmd.column;
  378. if (typeInfo.columns === null && columnExp !== null) {
  379. throw ProcessorErrorFactory.invalid_matrix_access_full(cmd.id, cmd.sourceInfo);
  380. } else if (columnExp !== null) {
  381. const columnType = this.evaluateExpressionType(columnExp);
  382. if (!columnType.isCompatible(Types.INTEGER)) {
  383. throw ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo);
  384. }
  385. }
  386. // exp can be a arrayLiteral, a single value exp or an array access
  387. if(exp instanceof ArrayLiteral) {
  388. this.evaluateArrayLiteral(cmd.id, typeInfo.lines, (columnExp ? typeInfo.columns : null), typeInfo.type, exp);
  389. } else {
  390. // cannot properly evaluate since type system is poorly constructed
  391. }
  392. return optional;
  393. } else if (cmd instanceof Assign) {
  394. const typeInfo = this.findSymbol(cmd.id, this.symbolMap);
  395. if(typeInfo === null) {
  396. throw ProcessorErrorFactory.symbol_not_found_full(cmd.id, cmd.sourceInfo);
  397. }
  398. const exp = cmd.expression;
  399. if(exp instanceof ArrayLiteral) {
  400. if(!(typeInfo.type instanceof CompoundType)) {
  401. const stringInfo = typeInfo.type.stringInfo();
  402. const info = stringInfo[0];
  403. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
  404. }
  405. this.evaluateArrayLiteral(cmd.id, typeInfo.lines, typeInfo.columns, typeInfo.type, exp);
  406. } else {
  407. const resultType = this.evaluateExpressionType(exp);
  408. if((!resultType.isCompatible(typeInfo.type) && !Config.enable_type_casting)
  409. || (!resultType.isCompatible(typeInfo.type) && Config.enable_type_casting
  410. && !Store.canImplicitTypeCast(typeInfo.type, resultType))) {
  411. const stringInfo = typeInfo.type.stringInfo();
  412. const info = stringInfo[0];
  413. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
  414. }
  415. }
  416. return optional;
  417. } else if (cmd instanceof Break) {
  418. return optional;
  419. } else if (cmd instanceof IfThenElse) {
  420. const resultType = this.evaluateExpressionType(cmd.condition);
  421. if (!resultType.isCompatible(Types.BOOLEAN)) {
  422. throw ProcessorErrorFactory.if_condition_type_full(cmd.sourceInfo);
  423. }
  424. if(cmd.ifFalse instanceof IfThenElse) {
  425. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommand(type, cmd.ifFalse, optional);
  426. } else {
  427. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommands(type, cmd.ifFalse.commands,optional);
  428. }
  429. } else if (cmd instanceof FunctionCall) {
  430. let fun = null;
  431. if (cmd.isMainCall) {
  432. fun = this.getMainFunction();
  433. } else {
  434. fun = this.findFunction(cmd.id);
  435. }
  436. if(fun === null) {
  437. throw ProcessorErrorFactory.function_missing_full(cmd.id, cmd.sourceInfo);
  438. }
  439. this.assertParameters(fun, cmd.actualParameters);
  440. return optional;
  441. } else if (cmd instanceof Return) {
  442. const funcName = this.currentFunction.isMain ? LanguageDefinedFunction.getMainFunctionName() : this.currentFunction.name
  443. if (cmd.expression === null && !type.isCompatible(Types.VOID)) {
  444. const stringInfo = type.stringInfo();
  445. const info = stringInfo[0];
  446. throw ProcessorErrorFactory.invalid_void_return_full(funcName, info.type, info.dim, cmd.sourceInfo);
  447. } else if (cmd.expression !== null) {
  448. const resultType = this.evaluateExpressionType(cmd.expression);
  449. if (!type.isCompatible(resultType)) {
  450. const stringInfo = type.stringInfo();
  451. const info = stringInfo[0];
  452. throw ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo);
  453. } else {
  454. return true;
  455. }
  456. } else {
  457. return true;
  458. }
  459. }
  460. }
  461. checkCommands (type, cmds, optional) {
  462. return cmds.reduce(
  463. (last, next) => this.checkCommand(type, next, optional) || last, optional
  464. );
  465. }
  466. assertParameters (fun, actualParametersList) {
  467. if (fun.formalParameters.length !== actualParametersList.length) {
  468. throw ProcessorErrorFactory.invalid_parameters_size_full(fun.name, actualParametersList.length, fun.formalParameters.length, null);
  469. }
  470. for (let i = 0; i < actualParametersList.length; i++) {
  471. const param = actualParametersList[i];
  472. const formalParam = fun.formalParameters[i];
  473. const id = formalParam.id;
  474. if(formalParam.byRef) {
  475. if (!(param instanceof VariableLiteral || param instanceof ArrayAccess)) {
  476. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  477. }
  478. }
  479. const resultType = this.evaluateExpressionType(param);
  480. if(resultType instanceof MultiType && formalParam.type instanceof MultiType) {
  481. let shared = 0
  482. for (let j = 0; j < resultType.types.length; j++) {
  483. const element = resultType.types[j];
  484. if(formalParam.type.types.indexOf(element) !== -1) {
  485. shared++;
  486. }
  487. }
  488. if(shared <= 0) {
  489. if(Config.enable_type_casting && !formalParam.byRef) {
  490. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  491. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  492. continue;
  493. }
  494. }
  495. }
  496. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  497. }
  498. } else if (resultType instanceof MultiType) {
  499. if(!resultType.isCompatible(formalParam.type)) {
  500. if(Config.enable_type_casting && !formalParam.byRef) {
  501. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  502. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  503. continue;
  504. }
  505. }
  506. }
  507. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  508. }
  509. } else if(!formalParam.type.isCompatible(resultType)) {
  510. if(Config.enable_type_casting && !formalParam.byRef) {
  511. if (Store.canImplicitTypeCast(formalParam.type, resultType)) {
  512. continue;
  513. }
  514. }
  515. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  516. }
  517. }
  518. }
  519. }