@@ -615,8 +615,13 @@ end function parse_sequence
615
615
! USE [, intrinsic] :: module_name [, only: only_list]
616
616
! USE [, non_intrinsic] :: module_name [, only: only_list]
617
617
subroutine parse_use_statement (f_filename ,i ,line ,use_stmt ,is_intrinsic ,module_name ,error )
618
- character (* ), intent (in ) :: f_filename,line
619
- integer , intent (in ) :: i ! line number
618
+
619
+ ! > Current file name and line number (for error messaging)
620
+ character (* ), intent (in ) :: f_filename
621
+ integer , intent (in ) :: i
622
+
623
+ ! > The line being parsed. MUST BE preprocessed with trim(adjustl()
624
+ character (* ), intent (in ) :: line
620
625
logical , intent (out ) :: use_stmt,is_intrinsic
621
626
character (:), allocatable , intent (out ) :: module_name
622
627
type (error_t), allocatable , intent (out ) :: error
@@ -629,54 +634,57 @@ subroutine parse_use_statement(f_filename,i,line,use_stmt,is_intrinsic,module_na
629
634
' ieee_features ' , &
630
635
' omp_lib ' ]
631
636
632
- character (len= :), allocatable :: lowercase, temp_string
637
+ character (len= :), allocatable :: temp_string
633
638
integer :: colons,intr,nonintr,j,stat
634
639
logical :: has_intrinsic_name
635
640
636
641
use_stmt = .false.
637
642
is_intrinsic = .false.
638
643
if (len_trim (line)<= 0 ) return
639
644
640
- ! Preprocess: lowercase, remove heading spaces
641
- lowercase = lower(trim (adjustl (line)))
645
+ ! Quick check that the line is preprocessed
646
+ if (line(1 :1 )==' ' ) then
647
+ call fatal_error(error,' internal_error: source file line is not trim(adjustl()) on input to parse_use_statement' )
648
+ return
649
+ end if
642
650
643
651
! 'use' should be the first string in the adjustl line
644
- use_stmt = index (lowercase ,' use ' )==1 .or. index (lowercase ,' use::' )==1 .or. index (lowercase ,' use,' )==1
652
+ use_stmt = index (line ,' use ' )==1 .or. index (line ,' use::' )==1 .or. index (line ,' use,' )==1
645
653
if (.not. use_stmt) return
646
- colons = index (lowercase ,' ::' )
654
+ colons = index (line ,' ::' )
647
655
nonintr = 0
648
656
intr = 0
649
657
650
658
have_colons: if (colons> 3 ) then
651
659
652
660
! there may be an intrinsic/non-intrinsic spec
653
- nonintr = index (lowercase (1 :colons-1 ),' non_intrinsic' )
654
- if (nonintr== 0 ) intr = index (lowercase (1 :colons-1 ),' intrinsic' )
661
+ nonintr = index (line (1 :colons-1 ),' non_intrinsic' )
662
+ if (nonintr== 0 ) intr = index (line (1 :colons-1 ),' intrinsic' )
655
663
656
664
657
- temp_string = split_n(lowercase ,delims= ' :' ,n= 2 ,stat= stat)
665
+ temp_string = split_n(line ,delims= ' :' ,n= 2 ,stat= stat)
658
666
if (stat /= 0 ) then
659
667
call file_parse_error(error,f_filename, &
660
668
' unable to find used module name' ,i, &
661
- lowercase ,colons)
669
+ line ,colons)
662
670
return
663
671
end if
664
672
665
673
module_name = split_n(temp_string,delims= ' ,' ,n= 1 ,stat= stat)
666
674
if (stat /= 0 ) then
667
675
call file_parse_error(error,f_filename, &
668
676
' unable to find used module name' ,i, &
669
- lowercase )
677
+ line )
670
678
return
671
679
end if
672
680
673
681
else
674
682
675
- module_name = split_n(lowercase ,n= 2 ,delims= ' ,' ,stat= stat)
683
+ module_name = split_n(line ,n= 2 ,delims= ' ,' ,stat= stat)
676
684
if (stat /= 0 ) then
677
685
call file_parse_error(error,f_filename, &
678
686
' unable to find used module name' ,i, &
679
- lowercase )
687
+ line )
680
688
return
681
689
end if
682
690
@@ -694,7 +702,7 @@ subroutine parse_use_statement(f_filename,i,line,use_stmt,is_intrinsic,module_na
694
702
if (index (module_name,' &' )<= 0 ) then
695
703
call file_parse_error(error,f_filename, &
696
704
' module ' // module_name// ' is declared intrinsic but it is not ' ,i, &
697
- lowercase )
705
+ line )
698
706
return
699
707
endif
700
708
endif
0 commit comments