Skip to content

Commit 3c0bbcb

Browse files
committed
do not preprocess with trim(adjustl(line))
1 parent 44d2b3c commit 3c0bbcb

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/fpm_source_parsing.f90

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,13 @@ end function parse_sequence
615615
! USE [, intrinsic] :: module_name [, only: only_list]
616616
! USE [, non_intrinsic] :: module_name [, only: only_list]
617617
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
620625
logical, intent(out) :: use_stmt,is_intrinsic
621626
character(:), allocatable, intent(out) :: module_name
622627
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
629634
'ieee_features ', &
630635
'omp_lib ']
631636

632-
character(len=:), allocatable :: lowercase,temp_string
637+
character(len=:), allocatable :: temp_string
633638
integer :: colons,intr,nonintr,j,stat
634639
logical :: has_intrinsic_name
635640

636641
use_stmt = .false.
637642
is_intrinsic = .false.
638643
if (len_trim(line)<=0) return
639644

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
642650

643651
! '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
645653
if (.not.use_stmt) return
646-
colons = index(lowercase,'::')
654+
colons = index(line,'::')
647655
nonintr = 0
648656
intr = 0
649657

650658
have_colons: if (colons>3) then
651659

652660
! 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')
655663

656664

657-
temp_string = split_n(lowercase,delims=':',n=2,stat=stat)
665+
temp_string = split_n(line,delims=':',n=2,stat=stat)
658666
if (stat /= 0) then
659667
call file_parse_error(error,f_filename, &
660668
'unable to find used module name',i, &
661-
lowercase,colons)
669+
line,colons)
662670
return
663671
end if
664672

665673
module_name = split_n(temp_string,delims=' ,',n=1,stat=stat)
666674
if (stat /= 0) then
667675
call file_parse_error(error,f_filename, &
668676
'unable to find used module name',i, &
669-
lowercase)
677+
line)
670678
return
671679
end if
672680

673681
else
674682

675-
module_name = split_n(lowercase,n=2,delims=' ,',stat=stat)
683+
module_name = split_n(line,n=2,delims=' ,',stat=stat)
676684
if (stat /= 0) then
677685
call file_parse_error(error,f_filename, &
678686
'unable to find used module name',i, &
679-
lowercase)
687+
line)
680688
return
681689
end if
682690

@@ -694,7 +702,7 @@ subroutine parse_use_statement(f_filename,i,line,use_stmt,is_intrinsic,module_na
694702
if (index(module_name,'&')<=0) then
695703
call file_parse_error(error,f_filename, &
696704
'module '//module_name//' is declared intrinsic but it is not ',i, &
697-
lowercase)
705+
line)
698706
return
699707
endif
700708
endif

0 commit comments

Comments
 (0)