associated.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Implementation of the ASSOCIATED intrinsic
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. Contributed by kejia Zhao (CCRG) <kejia_zh@yahoo.com.cn>
  4. This file is part of the GNU Fortran 95 runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. extern int associated (const gfc_array_void *, const gfc_array_void *);
  22. export_proto(associated);
  23. int
  24. associated (const gfc_array_void *pointer, const gfc_array_void *target)
  25. {
  26. int n, rank;
  27. if (GFC_DESCRIPTOR_DATA (pointer) == NULL)
  28. return 0;
  29. if (GFC_DESCRIPTOR_DATA (pointer) != GFC_DESCRIPTOR_DATA (target))
  30. return 0;
  31. if (GFC_DESCRIPTOR_SPAN (pointer) != GFC_DESCRIPTOR_SPAN (target))
  32. return 0;
  33. if (GFC_DESCRIPTOR_DTYPE (pointer).type != GFC_DESCRIPTOR_DTYPE (target).type)
  34. return 0;
  35. rank = GFC_DESCRIPTOR_RANK (pointer);
  36. if (rank != GFC_DESCRIPTOR_RANK (target))
  37. return 0;
  38. for (n = 0; n < rank; n++)
  39. {
  40. long extent;
  41. extent = GFC_DESCRIPTOR_EXTENT(pointer,n);
  42. if (extent != GFC_DESCRIPTOR_EXTENT(target,n))
  43. return 0;
  44. if (GFC_DESCRIPTOR_STRIDE(pointer,n) != GFC_DESCRIPTOR_STRIDE(target,n) && extent != 1)
  45. return 0;
  46. if (extent <= 0)
  47. return 0;
  48. }
  49. return 1;
  50. }