size.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Implementation of the size intrinsic.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Contributed by Paul Brook <paul@nowt.org>
  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. index_type
  22. size0 (const array_t * array)
  23. {
  24. int n;
  25. index_type size;
  26. index_type len;
  27. size = 1;
  28. for (n = 0; n < GFC_DESCRIPTOR_RANK (array); n++)
  29. {
  30. len = GFC_DESCRIPTOR_EXTENT(array,n);
  31. if (len < 0)
  32. len = 0;
  33. size *= len;
  34. }
  35. return size;
  36. }
  37. iexport(size0);
  38. extern index_type size1 (const array_t * array, index_type dim);
  39. export_proto(size1);
  40. index_type
  41. size1 (const array_t * array, index_type dim)
  42. {
  43. index_type size;
  44. dim--;
  45. size = GFC_DESCRIPTOR_EXTENT(array,dim);
  46. if (size < 0)
  47. size = 0;
  48. return size;
  49. }