function.js 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Types } from './../../typeSystem/types';
  2. export class Function {
  3. /**
  4. *
  5. * @param {string} name
  6. * @param {import('./../../typeSystem/itype').IType} returnType
  7. * @param {import('./formalParameter').FormalParameter[]} formalParameters
  8. * @param {import('./commandBlock').CommandBlock} commandBlock
  9. */
  10. constructor(name, returnType, formalParameters, commandBlock) {
  11. this.name = name;
  12. this.returnType = returnType;
  13. this.formalParameters = formalParameters;
  14. this.commandBlock = commandBlock;
  15. this._sourceInfo = null;
  16. }
  17. get isMain () {
  18. return this.name === null && this.returnType.isCompatible(Types.VOID);
  19. }
  20. get commands () {
  21. return this.commandBlock.commands;
  22. }
  23. get variablesDeclarations () {
  24. return this.commandBlock.variables;
  25. }
  26. set sourceInfo (sourceInfo) {
  27. this._sourceInfo = sourceInfo;
  28. }
  29. get sourceInfo () {
  30. return this._sourceInfo;
  31. }
  32. hasVariadic () {
  33. return this.formalParameters.some( p => p.variadic);
  34. }
  35. }