True if a and b have the same code tokens, in the same order, with the same text and the
same joins across line breaks (blanks, comments and line layout may differ). Names and dot
operators are compared ignoring case, as Fortran does, and the two spellings of a relational
operator (< and .lt.) are the same.
With reordered_use, use statements may also be in a different order within a run of them
(not across other statements or preprocessor lines), and so may the items of an only: list.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | a |
first source text |
||
| character(len=*), | intent(in) | :: | b |
second source text |
||
| logical, | intent(in), | optional | :: | reordered_use |
allow reordered |
|
| type(token_list_t), | intent(in), | optional | :: | a_tokens |
the tokens of |
logical function same_code(a, b, reordered_use, a_tokens) !! True if `a` and `b` have the same code tokens, in the same order, with the same text and the !! same joins across line breaks (blanks, comments and line layout may differ). Names and dot !! operators are compared ignoring case, as Fortran does, and the two spellings of a relational !! operator (`<` and `.lt.`) are the same. !! !! With `reordered_use`, `use` statements may also be in a different order within a run of them !! (not across other statements or preprocessor lines), and so may the items of an `only:` list. character(len=*), intent(in) :: a !! first source text character(len=*), intent(in) :: b !! second source text logical, intent(in), optional :: reordered_use !! allow reordered `use` statements; default false type(token_list_t), intent(in), optional :: a_tokens !! the tokens of `a`, if already known type(token_list_t) :: ta, tb if (present(reordered_use)) then if (reordered_use) then same_code = code_signature(a) == code_signature(b) return end if end if ! token by token, without building signatures call tokenize(b, tb) if (present(a_tokens)) then same_code = same_lists(a_tokens) ! without a copy of the token list else call tokenize(a, ta) same_code = same_lists(ta) end if contains logical function same_lists(ta) !! True if the code tokens of `a` (`ta`) match those of `b` (`tb`). type(token_list_t), intent(in) :: ta !! the tokens of `a` integer :: i, j same_lists = .false. i = 0 j = 0 do i = next_code(ta, i) j = next_code(tb, j) if (i > ta%n .or. j > tb%n) exit if (.not. same_token(a, ta%tok(i), b, tb%tok(j))) return end do same_lists = i > ta%n .and. j > tb%n end function same_lists pure integer function next_code(tokens, k) result(next) !! The index of the first code token after token `k`, or `tokens%n + 1`. type(token_list_t), intent(in) :: tokens !! the token list integer, intent(in) :: k !! index into `tokens`, or 0 to start at the beginning next = k + 1 do while (next <= tokens%n) if (is_code_kind(tokens%tok(next)%kind)) return next = next + 1 end do end function next_code end function same_code