1
0

semanticAnalyser.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. || (Config.enable_type_casting && !Store.canImplicitTypeCast(declaration.type, resultType))) {
  120. const stringInfo = declaration.type.stringInfo();
  121. const info = stringInfo[0];
  122. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
  123. } else {
  124. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
  125. }
  126. }
  127. }
  128. evaluateExpressionType (expression) {
  129. if(expression instanceof UnaryApp) {
  130. const op = expression.op;
  131. const resultType = this.evaluateExpressionType(expression.left);
  132. return resultTypeAfterUnaryOp(op, resultType);
  133. } else if (expression instanceof InfixApp) {
  134. const op = expression.op;
  135. const resultTypeLeft = this.evaluateExpressionType(expression.left);
  136. const resultTypeRight = this.evaluateExpressionType(expression.right);
  137. return resultTypeAfterInfixOp(op, resultTypeLeft, resultTypeRight);
  138. } else if (expression instanceof Literal) {
  139. return this.evaluateLiteralType(expression);
  140. } else if (expression instanceof FunctionCall) {
  141. if (expression.isMainCall) {
  142. throw ProcessorErrorFactory.void_in_expression_full(LanguageDefinedFunction.getMainFunctionName(), expression.sourceInfo);
  143. }
  144. const fun = this.findFunction(expression.id);
  145. if(fun === null) {
  146. throw ProcessorErrorFactory.function_missing_full(expression.id, expression.sourceInfo);
  147. }
  148. if (fun.returnType.isCompatible(Types.VOID)) {
  149. throw ProcessorErrorFactory.void_in_expression_full(expression.id, expression.sourceInfo);
  150. }
  151. this.assertParameters(fun, expression.actualParameters);
  152. return fun.returnType;
  153. } else if (expression instanceof ArrayAccess) {
  154. const arrayTypeInfo = this.findSymbol(expression.id, this.symbolMap);
  155. if(arrayTypeInfo === null) {
  156. throw ProcessorErrorFactory.symbol_not_found_full(expression.id, expression.sourceInfo);
  157. }
  158. if (!(arrayTypeInfo.type instanceof CompoundType)) {
  159. throw ProcessorErrorFactory.invalid_array_access_full(expression.id, expression.sourceInfo);
  160. }
  161. const lineType = this.evaluateExpressionType(expression.line);
  162. if (!lineType.isCompatible(Types.INTEGER)) {
  163. throw ProcessorErrorFactory.array_dimension_not_int_full(expression.sourceInfo);
  164. }
  165. if (expression.column !== null) {
  166. if (arrayTypeInfo.columns === null) {
  167. throw ProcessorErrorFactory.invalid_matrix_access_full(expression.id, expression.sourceInfo);
  168. }
  169. const columnType = this.evaluateExpressionType(expression.column);
  170. if(!columnType.isCompatible(Types.INTEGER)) {
  171. throw ProcessorErrorFactory.array_dimension_not_int_full(expression.sourceInfo);
  172. }
  173. }
  174. const arrType = arrayTypeInfo.type;
  175. if(expression.column !== null) {
  176. // indexing matrix
  177. return arrType.innerType;
  178. } else {
  179. if(arrayTypeInfo.columns === null) {
  180. return arrType.innerType;
  181. }
  182. return new CompoundType(arrType.innerType, 1);
  183. }
  184. }
  185. }
  186. evaluateLiteralType (literal) {
  187. if(literal instanceof IntLiteral) {
  188. return literal.type;
  189. } else if (literal instanceof RealLiteral) {
  190. return literal.type;
  191. } else if (literal instanceof StringLiteral) {
  192. return literal.type;
  193. } else if (literal instanceof BoolLiteral) {
  194. return literal.type;
  195. } else if (literal instanceof VariableLiteral) {
  196. const typeInfo = this.findSymbol(literal.id, this.symbolMap);
  197. if(typeInfo === null) {
  198. throw ProcessorErrorFactory.symbol_not_found_full(literal.id, literal.sourceInfo);
  199. }
  200. if (typeInfo.type instanceof CompoundType) {
  201. return typeInfo.type;
  202. }
  203. return typeInfo.type;
  204. } else {
  205. console.warn("Evaluating type only for an array literal...");
  206. let last = null;
  207. if(literal.value.length === 1) {
  208. last = this.evaluateExpressionType(literal.value[0]);
  209. } else {
  210. for (let i = 0; i < literal.value.length; i++) {
  211. const e = this.evaluateExpressionType(literal.value[i]);
  212. if(last === null) {
  213. last = e;
  214. } else if(!last.isCompatible(e)) {
  215. const strInfo = last.stringInfo();
  216. const info = strInfo[0];
  217. const strExp = literal.toString();
  218. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  219. }
  220. }
  221. }
  222. if(last instanceof CompoundType) {
  223. return new CompoundType(last.innerType, last.dimensions + 1);
  224. }
  225. return new CompoundType(last, 1);
  226. }
  227. }
  228. evaluateArrayLiteral (id, lines, columns, type, literal) {
  229. /* if (literal instanceof ArrayLiteral) {
  230. const dimType = this.evaluateExpressionType(lines);
  231. if (!dimType.isCompatible(Types.INTEGER)) {
  232. throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
  233. }
  234. if ((lines instanceof IntLiteral)) {
  235. if (!lines.value.eq(literal.value.length)) {
  236. if(type.dimensions > 1) {
  237. throw ProcessorErrorFactory.matrix_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
  238. } else {
  239. throw ProcessorErrorFactory.vector_line_outbounds_full(id, literal.value.length, lines.value.toNumber(), literal.sourceInfo)
  240. }
  241. } else if (lines.value.isNeg()) {
  242. throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
  243. }
  244. }
  245. if (columns === null) {
  246. // it's a vector...
  247. literal.value.reduce((last, next) => {
  248. const eType = this.evaluateExpressionType(next);
  249. if (!last.canAccept(eType)) {
  250. const strInfo = last.stringInfo();
  251. const info = strInfo[0];
  252. const strExp = literal.toString();
  253. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  254. }
  255. return last;
  256. }, type);
  257. return true;
  258. } else {
  259. const dimType = this.evaluateExpressionType(columns);
  260. if (!dimType.isCompatible(Types.INTEGER)) {
  261. throw ProcessorErrorFactory.array_dimension_not_int_full(literal.sourceInfo);
  262. }
  263. if ((columns instanceof IntLiteral)) {
  264. const columnValue = literal.value[0].value.length;
  265. if (!columns.value.eq(columnValue)) {
  266. if(type.dimensions > 1) {
  267. throw ProcessorErrorFactory.matrix_column_outbounds_full(id, literal.value.length, columns.value.toNumber(), literal.sourceInfo)
  268. } else {
  269. throw ProcessorErrorFactory.invalid_matrix_access_full(id, literal.sourceInfo);
  270. }
  271. } else if (columns.value.isNeg()) {
  272. throw ProcessorErrorFactory.array_dimension_not_positive_full(literal.sourceInfo);
  273. }
  274. for (let i = 0; i < columns; i++) {
  275. const anotherArray = literal.value[i];
  276. this.evaluateArrayLiteral(id, columns, null, type, anotherArray)
  277. }
  278. }
  279. }
  280. } else {
  281. const resultType = this.evaluateExpressionType(literal);
  282. if (!(resultType instanceof CompoundType)) {
  283. const strInfo = type.stringInfo();
  284. const info = strInfo[0];
  285. const strExp = literal.toString();
  286. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  287. }
  288. if (!type.isCompatible(resultType)) {
  289. const strInfo = type.stringInfo();
  290. const info = strInfo[0];
  291. const strExp = literal.toString();
  292. throw ProcessorErrorFactory.incompatible_types_array_full(strExp,info.type, info.dim, literal.sourceInfo);
  293. }
  294. return true;
  295. } */
  296. return true;
  297. }
  298. assertFunction (fun) {
  299. this.pushMap();
  300. this.currentFunction = fun;
  301. fun.formalParameters.forEach(formalParam => {
  302. if(formalParam.type instanceof CompoundType) {
  303. if(formalParam.type.dimensions > 1) {
  304. this.insertSymbol(formalParam.id, {id: formalParam.id, lines: -1, columns: -1, type: formalParam.type});
  305. } else {
  306. this.insertSymbol(formalParam.id, {id: formalParam.id, lines: -1, columns: null, type: formalParam.type});
  307. }
  308. } else {
  309. this.insertSymbol(formalParam.id, {id: formalParam.id, type: formalParam.type});
  310. }
  311. })
  312. this.assertDeclarations(fun.variablesDeclarations);
  313. const optional = fun.returnType.isCompatible(Types.VOID);
  314. const valid = this.assertReturn(fun, optional);
  315. if (!valid) {
  316. throw ProcessorErrorFactory.function_no_return(fun.name);
  317. }
  318. this.popMap();
  319. }
  320. assertReturn (fun, optional) {
  321. return fun.commands.reduce(
  322. (last, next) => this.checkCommand(fun.returnType, next, optional) || last, optional
  323. );
  324. }
  325. checkCommand (type, cmd, optional) {
  326. if (cmd instanceof While) {
  327. const resultType = this.evaluateExpressionType(cmd.expression);
  328. if (!resultType.isCompatible(Types.BOOLEAN)) {
  329. throw ProcessorErrorFactory.loop_condition_type_full(cmd.sourceInfo);
  330. }
  331. this.checkCommands(type, cmd.commands, optional);
  332. return false;
  333. } else if (cmd instanceof For) {
  334. this.checkCommand(type, cmd.assignment, optional);
  335. const resultType = this.evaluateExpressionType(cmd.condition);
  336. if (!resultType.isCompatible(Types.BOOLEAN)) {
  337. throw ProcessorErrorFactory.for_condition_type_full(cmd.sourceInfo);
  338. }
  339. this.checkCommand(type, cmd.increment, optional);
  340. this.checkCommands(type, cmd.commands, optional);
  341. return false;
  342. } else if (cmd instanceof Switch) {
  343. const sType = this.evaluateExpressionType(cmd.expression);
  344. let result = optional;
  345. let hasDefault = false;
  346. for (let i = 0; i < cmd.cases.length; i++) {
  347. const aCase = cmd.cases[i];
  348. if (aCase.expression !== null) {
  349. const caseType = this.evaluateExpressionType(aCase.expression);
  350. if (!sType.isCompatible(caseType)) {
  351. const strInfo = sType.stringInfo();
  352. const info = strInfo[0];
  353. const strExp = aCase.expression.toString();
  354. throw ProcessorErrorFactory.invalid_case_type_full(strExp, info.type, info.dim, aCase.sourceInfo);
  355. }
  356. } else {
  357. hasDefault = true;
  358. }
  359. result = result && this.checkCommands(type, aCase.commands, result);
  360. }
  361. return result && hasDefault;
  362. } else if (cmd instanceof ArrayIndexAssign) {
  363. const typeInfo = this.findSymbol(cmd.id, this.symbolMap);
  364. if(typeInfo === null) {
  365. throw ProcessorErrorFactory.symbol_not_found_full(cmd.id, cmd.sourceInfo);
  366. }
  367. if(!(typeInfo.type instanceof CompoundType)) {
  368. throw ProcessorErrorFactory.invalid_array_access_full(cmd.id, cmd.sourceInfo);
  369. }
  370. const exp = cmd.expression;
  371. const lineExp = cmd.line;
  372. const lineType = this.evaluateExpressionType(lineExp);
  373. if (!lineType.isCompatible(Types.INTEGER)) {
  374. throw ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo);
  375. }
  376. const columnExp = cmd.column;
  377. if (typeInfo.columns === null && columnExp !== null) {
  378. throw ProcessorErrorFactory.invalid_matrix_access_full(cmd.id, cmd.sourceInfo);
  379. } else if (columnExp !== null) {
  380. const columnType = this.evaluateExpressionType(columnExp);
  381. if (!columnType.isCompatible(Types.INTEGER)) {
  382. throw ProcessorErrorFactory.array_dimension_not_int_full(cmd.sourceInfo);
  383. }
  384. }
  385. // exp can be a arrayLiteral, a single value exp or an array access
  386. if(exp instanceof ArrayLiteral) {
  387. this.evaluateArrayLiteral(cmd.id, typeInfo.lines, (columnExp ? typeInfo.columns : null), typeInfo.type, exp);
  388. } else {
  389. // cannot properly evaluate since type system is poorly constructed
  390. }
  391. return optional;
  392. } else if (cmd instanceof Assign) {
  393. const typeInfo = this.findSymbol(cmd.id, this.symbolMap);
  394. if(typeInfo === null) {
  395. throw ProcessorErrorFactory.symbol_not_found_full(cmd.id, cmd.sourceInfo);
  396. }
  397. const exp = cmd.expression;
  398. if(exp instanceof ArrayLiteral) {
  399. if(!(typeInfo.type instanceof CompoundType)) {
  400. const stringInfo = typeInfo.type.stringInfo();
  401. const info = stringInfo[0];
  402. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
  403. }
  404. this.evaluateArrayLiteral(cmd.id, typeInfo.lines, typeInfo.columns, typeInfo.type, exp);
  405. } else {
  406. const resultType = this.evaluateExpressionType(exp);
  407. if((!resultType.isCompatible(typeInfo.type) && !Config.enable_type_casting)
  408. || (Config.enable_type_casting && !Store.canImplicitTypeCast(typeInfo.type, resultType))) {
  409. const stringInfo = typeInfo.type.stringInfo();
  410. const info = stringInfo[0];
  411. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
  412. }
  413. }
  414. return optional;
  415. } else if (cmd instanceof Break) {
  416. return optional;
  417. } else if (cmd instanceof IfThenElse) {
  418. const resultType = this.evaluateExpressionType(cmd.condition);
  419. if (!resultType.isCompatible(Types.BOOLEAN)) {
  420. throw ProcessorErrorFactory.if_condition_type_full(cmd.sourceInfo);
  421. }
  422. if(cmd.ifFalse instanceof IfThenElse) {
  423. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommand(type, cmd.ifFalse, optional);
  424. } else {
  425. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommands(type, cmd.ifFalse.commands,optional);
  426. }
  427. } else if (cmd instanceof FunctionCall) {
  428. let fun = null;
  429. if (cmd.isMainCall) {
  430. fun = this.getMainFunction();
  431. } else {
  432. fun = this.findFunction(cmd.id);
  433. }
  434. if(fun === null) {
  435. throw ProcessorErrorFactory.function_missing_full(cmd.id, cmd.sourceInfo);
  436. }
  437. this.assertParameters(fun, cmd.actualParameters);
  438. return optional;
  439. } else if (cmd instanceof Return) {
  440. const funcName = this.currentFunction.isMain ? LanguageDefinedFunction.getMainFunctionName() : this.currentFunction.name
  441. if (cmd.expression === null && !type.isCompatible(Types.VOID)) {
  442. const stringInfo = type.stringInfo();
  443. const info = stringInfo[0];
  444. throw ProcessorErrorFactory.invalid_void_return_full(funcName, info.type, info.dim, cmd.sourceInfo);
  445. } else if (cmd.expression !== null) {
  446. const resultType = this.evaluateExpressionType(cmd.expression);
  447. if (!type.isCompatible(resultType)) {
  448. const stringInfo = type.stringInfo();
  449. const info = stringInfo[0];
  450. throw ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo);
  451. } else {
  452. return true;
  453. }
  454. } else {
  455. return true;
  456. }
  457. }
  458. }
  459. checkCommands (type, cmds, optional) {
  460. return cmds.reduce(
  461. (last, next) => this.checkCommand(type, next, optional) || last, optional
  462. );
  463. }
  464. assertParameters (fun, actualParametersList) {
  465. if (fun.formalParameters.length !== actualParametersList.length) {
  466. throw ProcessorErrorFactory.invalid_parameters_size_full(fun.name, actualParametersList.length, fun.formalParameters.length, null);
  467. }
  468. for (let i = 0; i < actualParametersList.length; i++) {
  469. const param = actualParametersList[i];
  470. const formalParam = fun.formalParameters[i];
  471. const id = formalParam.id;
  472. if(formalParam.byRef) {
  473. if (!(param instanceof VariableLiteral || param instanceof ArrayAccess)) {
  474. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  475. }
  476. }
  477. const resultType = this.evaluateExpressionType(param);
  478. if(resultType instanceof MultiType && formalParam.type instanceof MultiType) {
  479. let shared = 0
  480. for (let j = 0; j < resultType.types.length; j++) {
  481. const element = resultType.types[j];
  482. if(formalParam.type.types.indexOf(element) !== -1) {
  483. shared++;
  484. }
  485. }
  486. if(shared <= 0) {
  487. if(Config.enable_type_casting && !formalParam.byRef) {
  488. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  489. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  490. continue;
  491. }
  492. }
  493. }
  494. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  495. }
  496. } else if (resultType instanceof MultiType) {
  497. if(!resultType.isCompatible(formalParam.type)) {
  498. if(Config.enable_type_casting && !formalParam.byRef) {
  499. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  500. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  501. continue;
  502. }
  503. }
  504. }
  505. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  506. }
  507. } else if(!formalParam.type.isCompatible(resultType)) {
  508. if(Config.enable_type_casting && !formalParam.byRef) {
  509. if (Store.canImplicitTypeCast(formalParam.type, resultType)) {
  510. continue;
  511. }
  512. }
  513. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  514. }
  515. }
  516. }
  517. }