array_type.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 (): boolean {
  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 (): object[] {
  21. const list = this.innerType.stringInfo();
  22. list.forEach(v => {
  23. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  24. const tmp = v as any;
  25. tmp.dim = this.dimensions;
  26. });
  27. return list;
  28. }
  29. get value (): undefined {
  30. return undefined;
  31. }
  32. get ord (): undefined {
  33. return undefined;
  34. }
  35. canAccept (another: IType, used_dims: number): boolean {
  36. const free_dims = this.dimensions - used_dims;
  37. if(another instanceof ArrayType) {
  38. return free_dims == another.dimensions && this.innerType.isCompatible(another.innerType);
  39. } else {
  40. return free_dims == 0 && this.innerType.isCompatible(another);
  41. }
  42. }
  43. }