Make v the view of code statement stmt.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | src |
source text |
||
| type(token_list_t), | intent(in) | :: | tokens |
tokens of |
||
| type(statement_t), | intent(in) | :: | stmt |
the statement |
||
| type(statement_view_t), | intent(out) | :: | v |
the view |
subroutine set_view(src, tokens, stmt, v) !! Make `v` the view of code statement `stmt`. character(len=*), intent(in) :: src !! source text type(token_list_t), intent(in) :: tokens !! tokens of `src` type(statement_t), intent(in) :: stmt !! the statement type(statement_view_t), intent(out) :: v !! the view integer :: j, p, d, total ! the code tokens, as code_tokens finds them, counted first to allocate once v%n = 0 do j = stmt%first, stmt%last if (is_statement_code(j)) v%n = v%n + 1 end do allocate (v%code(v%n), v%kinds(v%n), v%depth(v%n), v%lo(v%n), v%hi(v%n)) p = 0 do j = stmt%first, stmt%last if (.not. is_statement_code(j)) cycle p = p + 1 v%code(p) = j end do total = 0 do j = 1, v%n total = total + tokens%tok(v%code(j))%last - tokens%tok(v%code(j))%first + 1 end do allocate (character(len=total) :: v%low) p = 0 d = 0 do j = 1, v%n associate (t => tokens%tok(v%code(j))) v%kinds(j) = t%kind v%lo(j) = p + 1 v%low(p + 1:p + t%last - t%first + 1) = src(t%first:t%last) call make_lowercase(v%low(p + 1:p + t%last - t%first + 1)) p = p + t%last - t%first + 1 v%hi(j) = p end associate v%depth(j) = d if (v%kinds(j) /= TK_OP) cycle select case (v%low(v%lo(j):v%hi(j))) case ('(', '[') d = d + 1 case (')', ']') d = max(0, d - 1) v%depth(j) = d end select end do if (v%n > 1) then if (v%kinds(1) == TK_INT) v%first = 2 end if contains logical function is_statement_code(k) !! True if token `k` is one of the code tokens of the statement (not a `;` separator). integer, intent(in) :: k !! index into the token list is_statement_code = is_code_kind(tokens%tok(k)%kind) if (is_statement_code .and. tokens%tok(k)%kind == TK_OP) & is_statement_code = src(tokens%tok(k)%first:tokens%tok(k)%last) /= ';' end function is_statement_code end subroutine set_view