functionCall.js 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Expression } from './expression';
  2. import { LanguageDefinedFunction } from '../../processor/definedFunctions';
  3. export class FunctionCall extends Expression {
  4. /**
  5. *
  6. * @param {string} id
  7. * @param {Expression[]} actualParameters
  8. */
  9. constructor (id, actualParameters) {
  10. super();
  11. this.id = id;
  12. this.actualParameters = actualParameters;
  13. }
  14. get isMainCall () {
  15. return this.id === null;
  16. }
  17. get parametersSize () {
  18. return this.actualParameters.length;
  19. }
  20. toString () {
  21. let name = null;
  22. if(this.isMainCall) {
  23. name = LanguageDefinedFunction.getMainFunctionName();
  24. } else {
  25. name = LanguageDefinedFunction.getLocalName(this.id);
  26. }
  27. let params = null;
  28. if(this.actualParameters.length == 0) {
  29. params = "()";
  30. } else {
  31. const strParams = this.actualParameters.map(v => v.toString());
  32. params = "(" + strParams.join(",") + ")";
  33. }
  34. if(this.parenthesis) {
  35. return `(${name + params})`;
  36. } else {
  37. return name + params;
  38. }
  39. }
  40. }