semanticAnalyser.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. if(name.match(/^\$.+$/)) {
  53. const fun = LanguageDefinedFunction.getFunction(name);
  54. if(!!!fun) {
  55. throw ProcessorErrorFactory.not_implemented(name);
  56. }
  57. return fun;
  58. } else {
  59. const val = this.ast.functions.find( v => v.name === name);
  60. if (!!!val) {
  61. return null;
  62. }
  63. return val;
  64. }
  65. }
  66. analyseTree () {
  67. const globalVars = this.ast.global;
  68. this.pushMap();
  69. this.assertDeclarations(globalVars);
  70. const functions = this.ast.functions;
  71. const mainFunc = functions.filter((f) => f.name === null);
  72. if (mainFunc.length <= 0) {
  73. throw ProcessorErrorFactory.main_missing();
  74. }
  75. for (let i = 0; i < functions.length; i++) {
  76. const fun = functions[i];
  77. this.assertFunction(fun);
  78. }
  79. return this.ast;
  80. }
  81. assertDeclarations (list) {
  82. for (let i = 0; i < list.length; i++) {
  83. this.assertDeclaration(list[i]);
  84. }
  85. }
  86. assertDeclaration (declaration) {
  87. if (declaration instanceof ArrayDeclaration) {
  88. if(declaration.initial === null) {
  89. const lineType = this.evaluateExpressionType(declaration.lines);
  90. if (!lineType.isCompatible(Types.INTEGER)) {
  91. throw ProcessorErrorFactory.array_dimension_not_int_full(declaration.sourceInfo);
  92. }
  93. if (declaration.columns !== null) {
  94. const columnType = this.evaluateExpressionType(declaration.columns);
  95. if (!columnType.isCompatible(Types.INTEGER)) {
  96. throw ProcessorErrorFactory.array_dimension_not_int_full(declaration.sourceInfo);
  97. }
  98. }
  99. this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
  100. return;
  101. }
  102. this.evaluateArrayLiteral(declaration.id, declaration.lines, declaration.columns, declaration.type, declaration.initial);
  103. this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
  104. } else {
  105. if(declaration.initial === null) {
  106. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
  107. return;
  108. }
  109. const resultType = this.evaluateExpressionType(declaration.initial);
  110. if(resultType instanceof MultiType) {
  111. if(!resultType.isCompatible(declaration.type)) {
  112. const stringInfo = declaration.type.stringInfo();
  113. const info = stringInfo[0];
  114. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
  115. }
  116. this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type})
  117. } else if((!declaration.type.isCompatible(resultType) && !Config.enable_type_casting)
  118. || (!declaration.type.isCompatible(resultType) && Config.enable_type_casting
  119. && !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.expression.toString(), 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.condition.toString(), 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. || (!resultType.isCompatible(typeInfo.type) && Config.enable_type_casting
  409. && !Store.canImplicitTypeCast(typeInfo.type, resultType))) {
  410. const stringInfo = typeInfo.type.stringInfo();
  411. const info = stringInfo[0];
  412. throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, cmd.sourceInfo);
  413. }
  414. }
  415. return optional;
  416. } else if (cmd instanceof Break) {
  417. return optional;
  418. } else if (cmd instanceof IfThenElse) {
  419. const resultType = this.evaluateExpressionType(cmd.condition);
  420. if (!resultType.isCompatible(Types.BOOLEAN)) {
  421. throw ProcessorErrorFactory.if_condition_type_full(cmd.condition.toString(), cmd.sourceInfo);
  422. }
  423. if(cmd.ifFalse instanceof IfThenElse) {
  424. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommand(type, cmd.ifFalse, optional);
  425. } else {
  426. return this.checkCommands(type, cmd.ifTrue.commands, optional) && this.checkCommands(type, cmd.ifFalse.commands,optional);
  427. }
  428. } else if (cmd instanceof FunctionCall) {
  429. let fun = null;
  430. if (cmd.isMainCall) {
  431. fun = this.getMainFunction();
  432. } else {
  433. fun = this.findFunction(cmd.id);
  434. }
  435. if(fun === null) {
  436. throw ProcessorErrorFactory.function_missing_full(cmd.id, cmd.sourceInfo);
  437. }
  438. this.assertParameters(fun, cmd.actualParameters);
  439. return optional;
  440. } else if (cmd instanceof Return) {
  441. const funcName = this.currentFunction.isMain ? LanguageDefinedFunction.getMainFunctionName() : this.currentFunction.name
  442. if (cmd.expression === null && !type.isCompatible(Types.VOID)) {
  443. const stringInfo = type.stringInfo();
  444. const info = stringInfo[0];
  445. throw ProcessorErrorFactory.invalid_void_return_full(funcName, info.type, info.dim, cmd.sourceInfo);
  446. } else if (cmd.expression !== null) {
  447. const resultType = this.evaluateExpressionType(cmd.expression);
  448. if (!type.isCompatible(resultType)) {
  449. const stringInfo = type.stringInfo();
  450. const info = stringInfo[0];
  451. throw ProcessorErrorFactory.invalid_return_type_full(funcName, info.type, info.dim, cmd.sourceInfo);
  452. } else {
  453. return true;
  454. }
  455. } else {
  456. return true;
  457. }
  458. }
  459. }
  460. checkCommands (type, cmds, optional) {
  461. return cmds.reduce(
  462. (last, next) => this.checkCommand(type, next, optional) || last, optional
  463. );
  464. }
  465. assertParameters (fun, actualParametersList) {
  466. if (fun.formalParameters.length !== actualParametersList.length) {
  467. throw ProcessorErrorFactory.invalid_parameters_size_full(fun.name, actualParametersList.length, fun.formalParameters.length, null);
  468. }
  469. for (let i = 0; i < actualParametersList.length; i++) {
  470. const param = actualParametersList[i];
  471. const formalParam = fun.formalParameters[i];
  472. const id = formalParam.id;
  473. if(formalParam.byRef) {
  474. if (!(param instanceof VariableLiteral || param instanceof ArrayAccess)) {
  475. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  476. }
  477. }
  478. const resultType = this.evaluateExpressionType(param);
  479. if(resultType instanceof MultiType && formalParam.type instanceof MultiType) {
  480. let shared = 0
  481. for (let j = 0; j < resultType.types.length; j++) {
  482. const element = resultType.types[j];
  483. if(formalParam.type.types.indexOf(element) !== -1) {
  484. shared++;
  485. }
  486. }
  487. if(shared <= 0) {
  488. if(Config.enable_type_casting && !formalParam.byRef) {
  489. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  490. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  491. continue;
  492. }
  493. }
  494. }
  495. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  496. }
  497. } else if (resultType instanceof MultiType) {
  498. if(!resultType.isCompatible(formalParam.type)) {
  499. if(Config.enable_type_casting && !formalParam.byRef) {
  500. if(resultType.isCompatible(Types.INTEGER) || resultType.isCompatible(Types.REAL)) {
  501. if(formalParam.type.isCompatible(Types.INTEGER) || formalParam.type.isCompatible(Types.REAL)) {
  502. continue;
  503. }
  504. }
  505. }
  506. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  507. }
  508. } else if(!formalParam.type.isCompatible(resultType)) {
  509. if(Config.enable_type_casting && !formalParam.byRef) {
  510. if (Store.canImplicitTypeCast(formalParam.type, resultType)) {
  511. continue;
  512. }
  513. }
  514. throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
  515. }
  516. }
  517. }
  518. }