-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for toggling Fortran features (#864)
- implicit-typing: toggle default implicit typing rules - option to disable in GFortran - option to enable in LFortran - implicit-external: toggle implicit external interfaces - option to disable in GFortran - option to enable in LFortran - source-form: select source form ("free", "fixed", or "default") - option to set free/fixed form in GFortran - option to set fixed form in LFortran
- Loading branch information
Showing
19 changed files
with
368 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
program test | ||
use lib | ||
call hello | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "fixed-form" | ||
fortran.source-form = "fixed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module lib | ||
contains | ||
subroutine h e l l o | ||
print '(a)', | ||
+"Hello, fixed world!" | ||
end subroutine | ||
end module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
program test | ||
use lib | ||
call hello | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "free-form" | ||
fortran.source-form = "free" | ||
executable = [{main="main.f", name="free-form"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module lib | ||
contains | ||
subroutine hello | ||
print '(a)', "Hello, free world!" | ||
end subroutine | ||
end module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
program test | ||
integer :: ijk | ||
call impl(ijk) | ||
if (ijk /= 1) error stop | ||
end program test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "implicit-external" | ||
fortran.implicit-external = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
subroutine impl(ijk) | ||
integer :: ijk | ||
ijk = 1 | ||
end subroutine impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
program test | ||
use impl | ||
if (ijk /= 1) error stop | ||
end program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "implicit-typing" | ||
fortran.implicit-typing = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module impl | ||
parameter(ijk = 1) | ||
end module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
module fpm_manifest_fortran | ||
use fpm_error, only : error_t, syntax_error, fatal_error | ||
use fpm_toml, only : toml_table, toml_key, toml_stat, get_value | ||
implicit none | ||
private | ||
|
||
public :: fortran_config_t, new_fortran_config | ||
|
||
!> Configuration data for Fortran | ||
type :: fortran_config_t | ||
|
||
!> Enable default implicit typing | ||
logical :: implicit_typing | ||
|
||
!> Enable implicit external interfaces | ||
logical :: implicit_external | ||
|
||
!> Form to use for all Fortran sources | ||
character(:), allocatable :: source_form | ||
|
||
end type fortran_config_t | ||
|
||
contains | ||
|
||
!> Construct a new build configuration from a TOML data structure | ||
subroutine new_fortran_config(self, table, error) | ||
|
||
!> Instance of the fortran configuration | ||
type(fortran_config_t), intent(out) :: self | ||
|
||
!> Instance of the TOML data structure | ||
type(toml_table), intent(inout) :: table | ||
|
||
!> Error handling | ||
type(error_t), allocatable, intent(out) :: error | ||
|
||
integer :: stat | ||
character(:), allocatable :: source_form | ||
|
||
call check(table, error) | ||
if (allocated(error)) return | ||
|
||
call get_value(table, "implicit-typing", self%implicit_typing, .false., stat=stat) | ||
|
||
if (stat /= toml_stat%success) then | ||
call fatal_error(error,"Error while reading value for 'implicit-typing' in fpm.toml, expecting logical") | ||
return | ||
end if | ||
|
||
call get_value(table, "implicit-external", self%implicit_external, .false., stat=stat) | ||
|
||
if (stat /= toml_stat%success) then | ||
call fatal_error(error,"Error while reading value for 'implicit-external' in fpm.toml, expecting logical") | ||
return | ||
end if | ||
|
||
call get_value(table, "source-form", source_form, "free", stat=stat) | ||
|
||
if (stat /= toml_stat%success) then | ||
call fatal_error(error,"Error while reading value for 'source-form' in fpm.toml, expecting logical") | ||
return | ||
end if | ||
select case(source_form) | ||
case default | ||
call fatal_error(error,"Value of source-form cannot be '"//source_form//"'") | ||
return | ||
case("free", "fixed", "default") | ||
self%source_form = source_form | ||
end select | ||
|
||
end subroutine new_fortran_config | ||
|
||
!> Check local schema for allowed entries | ||
subroutine check(table, error) | ||
|
||
!> Instance of the TOML data structure | ||
type(toml_table), intent(inout) :: table | ||
|
||
!> Error handling | ||
type(error_t), allocatable, intent(out) :: error | ||
|
||
type(toml_key), allocatable :: list(:) | ||
integer :: ikey | ||
|
||
call table%get_keys(list) | ||
|
||
! table can be empty | ||
if (size(list) < 1) return | ||
|
||
do ikey = 1, size(list) | ||
select case(list(ikey)%key) | ||
|
||
case("implicit-typing", "implicit-external", "source-form") | ||
continue | ||
|
||
case default | ||
call syntax_error(error, "Key "//list(ikey)%key//" is not allowed in fortran") | ||
exit | ||
|
||
end select | ||
end do | ||
|
||
end subroutine check | ||
|
||
end module fpm_manifest_fortran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.