cct_load_toml Subroutine

public subroutine cct_load_toml(self, table, error)

Read compile_command_table_t from toml table (no checks made at this stage)

Type Bound

compile_command_table_t

Arguments

Type IntentOptional Attributes Name
class(compile_command_table_t), intent(inout) :: self

Instance of the serializable object

type(toml_table), intent(inout) :: table

Data structure

type(error_t), intent(out), allocatable :: error

Error handling


Variables

Type Visibility Attributes Name Initial
type(toml_array), public, pointer :: array
type(toml_table), public, pointer :: elem
integer, public :: i
integer, public :: n
integer, public :: stat

Source Code

    subroutine cct_load_toml(self, table, error)

        !> Instance of the serializable object
        class(compile_command_table_t), intent(inout) :: self

        !> Data structure
        type(toml_table), intent(inout) :: table
        
        !> Error handling
        type(error_t), allocatable, intent(out) :: error
        
        integer :: stat, i, n
        type(toml_array), pointer :: array
        type(toml_table), pointer :: elem
                
        call self%destroy()
        
        call get_value(table, key='compile_commands', ptr=array, requested=.true.,stat=stat)

        if (stat/=toml_stat%success .or. .not.associated(array)) then 
            
            call fatal_error(error, "TOML table has no 'compile_commands' key")
            return
            
        else
            
            n = len(array)               
            if (n<=0) return
                    
            allocate(self%command(n))
            
            do i = 1, n
                call get_value(array, pos=i, ptr=elem, stat=stat)
                if (stat /= toml_stat%success .or. .not.associated(elem)) then
                    call fatal_error(error, "Entry in 'compile_commands' field cannot be read")
                    return
                end if
                
                call self%command(i)%load(elem, error)
                if (allocated(error)) return
                
            end do            
            
        end if

    end subroutine cct_load_toml