array_type.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { IType } from "./itype";
  2. import { Type } from "./type";
  3. export class ArrayType implements IType {
  4. public innerType: IType;
  5. constructor (type: Type, public dimensions: number) {
  6. this.innerType = type;
  7. }
  8. get isVector () {
  9. return this.dimensions == 1;
  10. }
  11. isCompatible (another: IType): boolean {
  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. get value () {
  28. return undefined;
  29. }
  30. get ord () {
  31. return undefined;
  32. }
  33. canAccept (another: IType) {
  34. if(another instanceof ArrayType) {
  35. return false; // return this.dimensions > another.dimensions && this.innerType.isCompatible(another.innerType);
  36. } else {
  37. return this.dimensions == 1 && this.innerType.isCompatible(another);
  38. }
  39. }
  40. }