semanticAnalyser.js 22 KB

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