array_type.js 912 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Type } from "./type";
  2. export class ArrayType extends Type {
  3. constructor (type, dimensions) {
  4. super(null);
  5. this.innerType = type;
  6. this.dimensions = dimensions;
  7. }
  8. get isVector () {
  9. return this.dimensions == 1;
  10. }
  11. isCompatible (another) {
  12. if(another instanceof ArrayType){
  13. if(this.dimensions !== another.dimensions) {
  14. return false;
  15. }
  16. return this.innerType.isCompatible(another.innerType);
  17. }
  18. return false;
  19. }
  20. stringInfo () {
  21. const list = this.innerType.stringInfo();
  22. list.forEach(v => {
  23. v.dim = this.dimensions;
  24. });
  25. return list;
  26. }
  27. canAccept (another) {
  28. if(another instanceof ArrayType) {
  29. return false;// return this.dimensions > another.dimensions && this.innerType.isCompatible(another.innerType);
  30. } else {
  31. return this.dimensions == 1 && this.innerType.isCompatible(another);
  32. }
  33. }
  34. }