File: class_93.f90

package info (click to toggle)
lfortran 0.59.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 56,736 kB
  • sloc: cpp: 168,052; f90: 74,272; python: 17,537; ansic: 7,705; yacc: 2,345; sh: 1,334; fortran: 895; makefile: 37; javascript: 15
file content (54 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
! Test copy-in/copy-out for class member passed to type-bound procedure
module class_93_mod
  implicit none

  type :: token_t
    integer :: val = 0
  end type

  type :: lexer_t
    integer :: pos = 0
    type(token_t) :: tokens(3)
  contains
    procedure :: next => lexer_next
  end type

  type :: parser_t
    type(token_t) :: token
  end type

contains

  subroutine lexer_next(lexer, token)
    class(lexer_t), intent(inout) :: lexer
    type(token_t), intent(inout) :: token
    lexer%pos = lexer%pos + 1
    token = lexer%tokens(lexer%pos)
  end subroutine

  subroutine parse(parser, lexer)
    class(parser_t), intent(inout) :: parser
    class(lexer_t), intent(inout) :: lexer
    call lexer%next(parser%token)
  end subroutine

end module

program class_93
  use class_93_mod
  implicit none
  type(parser_t) :: parser
  type(lexer_t) :: lexer

  lexer%tokens(1)%val = 10
  lexer%tokens(2)%val = 20
  lexer%tokens(3)%val = 30

  call parse(parser, lexer)
  if (parser%token%val /= 10) error stop

  call parse(parser, lexer)
  if (parser%token%val /= 20) error stop

  print *, "PASSED"
end program