semanticAnalyser.js 22 KB

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