Skip to content

Commit dd42e2d

Browse files
committed
implement compile_command_table_t
1 parent e5c1cd6 commit dd42e2d

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

src/fpm_compile_commands.F90

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,26 @@ module fpm_compile_commands
1616

1717
contains
1818

19-
!> Serialization procedures
19+
!> Serialization interface
2020
procedure :: serializable_is_same => compile_command_is_same
2121
procedure :: dump_to_toml => compile_command_dump_toml
2222
procedure :: load_from_toml => compile_command_load_toml
2323

2424
end type compile_command_t
2525

26+
type, extends(serializable_t) :: compile_command_table_t
27+
28+
type(compile_command_t), allocatable :: command(:)
29+
30+
contains
31+
32+
!> Serialization interface
33+
procedure :: serializable_is_same => cct_is_same
34+
procedure :: dump_to_toml => cct_dump_toml
35+
procedure :: load_from_toml => cct_load_toml
36+
37+
38+
end type compile_command_table_t
2639

2740
contains
2841

@@ -92,5 +105,78 @@ logical function compile_command_is_same(this,that)
92105

93106
end function compile_command_is_same
94107

108+
!> Dump compile_command_table_t to toml table
109+
subroutine cct_dump_toml(self, table, error)
110+
111+
!> Instance of the serializable object
112+
class(compile_command_table_t), intent(inout) :: self
113+
114+
!> Data structure
115+
type(toml_table), intent(inout) :: table
116+
117+
!> Error handling
118+
type(error_t), allocatable, intent(out) :: error
119+
120+
! call set_string(table, "directory", self%directory, error, 'compile_command_table_t')
121+
! if (allocated(error)) return
122+
! call set_list(table, "arguments", self%arguments, error)
123+
! if (allocated(error)) return
124+
! call set_string(table, "file", self%file, error, 'compile_command_table_t')
125+
! if (allocated(error)) return
126+
127+
end subroutine cct_dump_toml
128+
129+
!> Read compile_command_table_t from toml table (no checks made at this stage)
130+
subroutine cct_load_toml(self, table, error)
131+
132+
!> Instance of the serializable object
133+
class(compile_command_table_t), intent(inout) :: self
134+
135+
!> Data structure
136+
type(toml_table), intent(inout) :: table
137+
138+
!> Error handling
139+
type(error_t), allocatable, intent(out) :: error
140+
141+
! call get_value(table, "directory", self%directory, error, 'compile_command_table_t')
142+
! if (allocated(error)) return
143+
! call get_list(table, "arguments", self%arguments, error)
144+
! if (allocated(error)) return
145+
! call get_value(table, "file", self%file, error, 'compile_command_table_t')
146+
! if (allocated(error)) return
147+
148+
end subroutine cct_load_toml
149+
150+
!> Check that two compile_command_table_t objects are equal
151+
logical function cct_is_same(this,that)
152+
class(compile_command_table_t), intent(in) :: this
153+
class(serializable_t), intent(in) :: that
154+
155+
integer :: i
156+
157+
cct_is_same = .false.
158+
159+
select type (other=>that)
160+
type is (compile_command_table_t)
161+
162+
if (allocated(this%command).neqv.allocated(other%command)) return
163+
if (allocated(this%command)) then
164+
if (.not.(size (this%command) ==size (other%command))) return
165+
if (.not.(ubound(this%command,1)==ubound(other%command,1))) return
166+
if (.not.(lbound(this%command,1)==lbound(other%command,1))) return
167+
do i=lbound(this%command,1),ubound(this%command,1)
168+
if (.not.this%command(i)==other%command(i)) return
169+
end do
170+
end if
171+
172+
class default
173+
! Not the same type
174+
return
175+
end select
176+
177+
!> All checks passed!
178+
cct_is_same = .true.
179+
180+
end function cct_is_same
95181

96182
end module fpm_compile_commands

0 commit comments

Comments
 (0)