|
26 | 26 | !>
|
27 | 27 | module fpm_model
|
28 | 28 | use iso_fortran_env, only: int64
|
29 |
| -use fpm_strings, only: string_t |
| 29 | +use fpm_strings, only: string_t, str |
30 | 30 | use fpm_dependency, only: dependency_tree_t
|
31 | 31 | implicit none
|
32 | 32 |
|
33 | 33 | private
|
34 |
| -public :: fpm_model_t, srcfile_t, build_target_t, build_target_ptr |
| 34 | +public :: fpm_model_t, srcfile_t, build_target_t, build_target_ptr, & |
| 35 | + show_model |
35 | 36 |
|
36 | 37 | public :: FPM_UNIT_UNKNOWN, FPM_UNIT_PROGRAM, FPM_UNIT_MODULE, &
|
37 | 38 | FPM_UNIT_SUBMODULE, FPM_UNIT_SUBPROGRAM, FPM_UNIT_CSOURCE, &
|
@@ -194,4 +195,234 @@ module fpm_model
|
194 | 195 |
|
195 | 196 | end type fpm_model_t
|
196 | 197 |
|
| 198 | +contains |
| 199 | + |
| 200 | +function info_build_target(t) result(s) |
| 201 | + type(build_target_t), intent(in) :: t |
| 202 | + character(:), allocatable :: s |
| 203 | + integer :: i |
| 204 | + !type build_target_t |
| 205 | + s = "build_target_t(" |
| 206 | + ! character(:), allocatable :: output_file |
| 207 | + s = s // 'output_file="' // t%output_file // '"' |
| 208 | + ! type(srcfile_t), allocatable :: source |
| 209 | + if (allocated(t%source)) then |
| 210 | + s = s // ", source=" // info_srcfile_short(t%source) |
| 211 | + else |
| 212 | + s = s // ", source=()" |
| 213 | + end if |
| 214 | + ! type(build_target_ptr), allocatable :: dependencies(:) |
| 215 | + s = s // ", dependencies=[" |
| 216 | + if (allocated(t%dependencies)) then |
| 217 | + do i = 1, size(t%dependencies) |
| 218 | + s = s // info_build_target_short(t%dependencies(i)%ptr) |
| 219 | + if (i < size(t%dependencies)) s = s // ", " |
| 220 | + end do |
| 221 | + end if |
| 222 | + s = s // "]" |
| 223 | + ! integer :: target_type = FPM_TARGET_UNKNOWN |
| 224 | + s = s // ", target_type=" |
| 225 | + select case(t%target_type) |
| 226 | + case (FPM_TARGET_UNKNOWN) |
| 227 | + s = s // "FPM_TARGET_UNKNOWN" |
| 228 | + case (FPM_TARGET_EXECUTABLE) |
| 229 | + s = s // "FPM_TARGET_EXECUTABLE" |
| 230 | + case (FPM_TARGET_ARCHIVE) |
| 231 | + s = s // "FPM_TARGET_ARCHIVE" |
| 232 | + case (FPM_TARGET_OBJECT) |
| 233 | + s = s // "FPM_TARGET_OBJECT" |
| 234 | + case default |
| 235 | + s = s // "INVALID" |
| 236 | + end select |
| 237 | + ! type(string_t), allocatable :: link_libraries(:) |
| 238 | + s = s // ", link_libraries=[" |
| 239 | + if (allocated(t%link_libraries)) then |
| 240 | + do i = 1, size(t%link_libraries) |
| 241 | + s = s // '"' // t%link_libraries(i)%s // '"' |
| 242 | + if (i < size(t%link_libraries)) s = s // ", " |
| 243 | + end do |
| 244 | + end if |
| 245 | + s = s // "]" |
| 246 | + ! type(string_t), allocatable :: link_objects(:) |
| 247 | + s = s // ", link_objects=[" |
| 248 | + if (allocated(t%link_objects)) then |
| 249 | + do i = 1, size(t%link_objects) |
| 250 | + s = s // '"' // t%link_objects(i)%s // '"' |
| 251 | + if (i < size(t%link_objects)) s = s // ", " |
| 252 | + end do |
| 253 | + end if |
| 254 | + s = s // "]" |
| 255 | + ! logical :: touched = .false. |
| 256 | + s = s // ", touched=" // str(t%touched) |
| 257 | + ! logical :: sorted = .false. |
| 258 | + s = s // ", sorted=" // str(t%sorted) |
| 259 | + ! logical :: skip = .false. |
| 260 | + s = s // ", skip=" // str(t%skip) |
| 261 | + ! integer :: schedule = -1 |
| 262 | + s = s // ", schedule=" // str(t%schedule) |
| 263 | + ! integer(int64), allocatable :: digest_cached |
| 264 | + if (allocated(t%digest_cached)) then |
| 265 | + s = s // ", digest_cached=" // str(t%digest_cached) |
| 266 | + else |
| 267 | + s = s // ", digest_cached=()" |
| 268 | + end if |
| 269 | + !end type build_target_t |
| 270 | + s = s // ")" |
| 271 | +end function |
| 272 | + |
| 273 | +function info_build_target_short(t) result(s) |
| 274 | + ! Prints a shortened representation of build_target_t |
| 275 | + type(build_target_t), intent(in) :: t |
| 276 | + character(:), allocatable :: s |
| 277 | + integer :: i |
| 278 | + s = "build_target_t(" |
| 279 | + s = s // 'output_file="' // t%output_file // '"' |
| 280 | + s = s // ", ...)" |
| 281 | +end function |
| 282 | + |
| 283 | +function info_srcfile(source) result(s) |
| 284 | + type(srcfile_t), intent(in) :: source |
| 285 | + character(:), allocatable :: s |
| 286 | + integer :: i |
| 287 | + !type srcfile_t |
| 288 | + s = "srcfile_t(" |
| 289 | + ! character(:), allocatable :: file_name |
| 290 | + s = s // 'file_name="' // source%file_name // '"' |
| 291 | + ! character(:), allocatable :: exe_name |
| 292 | + s = s // ', exe_name="' // source%exe_name // '"' |
| 293 | + ! integer :: unit_scope = FPM_SCOPE_UNKNOWN |
| 294 | + s = s // ", unit_scope=" |
| 295 | + select case(source%unit_scope) |
| 296 | + case (FPM_SCOPE_UNKNOWN) |
| 297 | + s = s // "FPM_SCOPE_UNKNOWN" |
| 298 | + case (FPM_SCOPE_LIB) |
| 299 | + s = s // "FPM_SCOPE_LIB" |
| 300 | + case (FPM_SCOPE_DEP) |
| 301 | + s = s // "FPM_SCOPE_DEP" |
| 302 | + case (FPM_SCOPE_APP) |
| 303 | + s = s // "FPM_SCOPE_APP" |
| 304 | + case (FPM_SCOPE_TEST) |
| 305 | + s = s // "FPM_SCOPE_TEST" |
| 306 | + case (FPM_SCOPE_EXAMPLE) |
| 307 | + s = s // "FPM_SCOPE_EXAMPLE" |
| 308 | + case default |
| 309 | + s = s // "INVALID" |
| 310 | + end select |
| 311 | + ! type(string_t), allocatable :: modules_provided(:) |
| 312 | + s = s // ", modules_provided=[" |
| 313 | + do i = 1, size(source%modules_provided) |
| 314 | + s = s // '"' // source%modules_provided(i)%s // '"' |
| 315 | + if (i < size(source%modules_provided)) s = s // ", " |
| 316 | + end do |
| 317 | + s = s // "]" |
| 318 | + ! integer :: unit_type = FPM_UNIT_UNKNOWN |
| 319 | + s = s // ", unit_type=" |
| 320 | + select case(source%unit_type) |
| 321 | + case (FPM_UNIT_UNKNOWN) |
| 322 | + s = s // "FPM_UNIT_UNKNOWN" |
| 323 | + case (FPM_UNIT_PROGRAM) |
| 324 | + s = s // "FPM_UNIT_PROGRAM" |
| 325 | + case (FPM_UNIT_MODULE) |
| 326 | + s = s // "FPM_UNIT_MODULE" |
| 327 | + case (FPM_UNIT_SUBMODULE) |
| 328 | + s = s // "FPM_UNIT_SUBMODULE" |
| 329 | + case (FPM_UNIT_SUBPROGRAM) |
| 330 | + s = s // "FPM_UNIT_SUBPROGRAM" |
| 331 | + case (FPM_UNIT_CSOURCE) |
| 332 | + s = s // "FPM_UNIT_CSOURCE" |
| 333 | + case (FPM_UNIT_CHEADER) |
| 334 | + s = s // "FPM_UNIT_CHEADER" |
| 335 | + case default |
| 336 | + s = s // "INVALID" |
| 337 | + end select |
| 338 | + ! type(string_t), allocatable :: modules_used(:) |
| 339 | + s = s // ", modules_used=[" |
| 340 | + do i = 1, size(source%modules_used) |
| 341 | + s = s // '"' // source%modules_used(i)%s // '"' |
| 342 | + if (i < size(source%modules_used)) s = s // ", " |
| 343 | + end do |
| 344 | + s = s // "]" |
| 345 | + ! type(string_t), allocatable :: include_dependencies(:) |
| 346 | + s = s // ", include_dependencies=[" |
| 347 | + do i = 1, size(source%include_dependencies) |
| 348 | + s = s // '"' // source%include_dependencies(i)%s // '"' |
| 349 | + if (i < size(source%include_dependencies)) s = s // ", " |
| 350 | + end do |
| 351 | + s = s // "]" |
| 352 | + ! type(string_t), allocatable :: link_libraries(:) |
| 353 | + s = s // ", link_libraries=[" |
| 354 | + do i = 1, size(source%link_libraries) |
| 355 | + s = s // '"' // source%link_libraries(i)%s // '"' |
| 356 | + if (i < size(source%link_libraries)) s = s // ", " |
| 357 | + end do |
| 358 | + s = s // "]" |
| 359 | + ! integer(int64) :: digest |
| 360 | + s = s // ", digest=" // str(source%digest) |
| 361 | + !end type srcfile_t |
| 362 | + s = s // ")" |
| 363 | +end function |
| 364 | + |
| 365 | +function info_srcfile_short(source) result(s) |
| 366 | + ! Prints a shortened version of srcfile_t |
| 367 | + type(srcfile_t), intent(in) :: source |
| 368 | + character(:), allocatable :: s |
| 369 | + integer :: i |
| 370 | + s = "srcfile_t(" |
| 371 | + s = s // 'file_name="' // source%file_name // '"' |
| 372 | + s = s // ", ...)" |
| 373 | +end function |
| 374 | + |
| 375 | +function info_model(model) result(s) |
| 376 | + type(fpm_model_t), intent(in) :: model |
| 377 | + character(:), allocatable :: s |
| 378 | + integer :: i |
| 379 | + !type :: fpm_model_t |
| 380 | + s = "fpm_model_t(" |
| 381 | + ! character(:), allocatable :: package_name |
| 382 | + s = s // 'package_name="' // model%package_name // '"' |
| 383 | + ! type(srcfile_t), allocatable :: sources(:) |
| 384 | + s = s // ", sources=[" |
| 385 | + do i = 1, size(model%sources) |
| 386 | + s = s // info_srcfile(model%sources(i)) |
| 387 | + if (i < size(model%sources)) s = s // ", " |
| 388 | + end do |
| 389 | + s = s // "]" |
| 390 | + ! type(build_target_ptr), allocatable :: targets(:) |
| 391 | + s = s // ", targets=[" |
| 392 | + do i = 1, size(model%targets) |
| 393 | + s = s // info_build_target(model%targets(i)%ptr) |
| 394 | + if (i < size(model%targets)) s = s // ", " |
| 395 | + end do |
| 396 | + s = s // "]" |
| 397 | + ! character(:), allocatable :: fortran_compiler |
| 398 | + s = s // ', fortran_compiler="' // model%fortran_compiler // '"' |
| 399 | + ! character(:), allocatable :: fortran_compile_flags |
| 400 | + s = s // ', fortran_compile_flags="' // model%fortran_compile_flags // '"' |
| 401 | + ! character(:), allocatable :: link_flags |
| 402 | + s = s // ', link_flags="' // model%link_flags // '"' |
| 403 | + ! character(:), allocatable :: library_file |
| 404 | + s = s // ', library_file="' // model%library_file // '"' |
| 405 | + ! character(:), allocatable :: output_directory |
| 406 | + s = s // ', output_directory="' // model%output_directory // '"' |
| 407 | + ! type(string_t), allocatable :: link_libraries(:) |
| 408 | + s = s // ", link_libraries=[" |
| 409 | + do i = 1, size(model%link_libraries) |
| 410 | + s = s // '"' // model%link_libraries(i)%s // '"' |
| 411 | + if (i < size(model%link_libraries)) s = s // ", " |
| 412 | + end do |
| 413 | + s = s // "]" |
| 414 | + ! type(dependency_tree_t) :: deps |
| 415 | + ! TODO: print `dependency_tree_t` properly, which should become part of the |
| 416 | + ! model, not imported from another file |
| 417 | + s = s // ", deps=dependency_tree_t(...)" |
| 418 | + !end type fpm_model_t |
| 419 | + s = s // ")" |
| 420 | +end function |
| 421 | + |
| 422 | +subroutine show_model(model) |
| 423 | + ! Prints a human readable representation of the Model |
| 424 | + type(fpm_model_t), intent(in) :: model |
| 425 | + print *, info_model(model) |
| 426 | +end subroutine |
| 427 | + |
197 | 428 | end module fpm_model
|
0 commit comments