Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call chain following for external types #584

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ford/sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,9 +1479,9 @@ def get_label_item(context, label):
context = item
elif isinstance(item, FortranVariable):
type_str = strip_type(item.full_type)
if item.parent is None:
if not (parent_all_types := getattr(item.parent, "all_types", {})):
return None
context = item.parent.all_types.get(type_str, None)
context = parent_all_types.get(type_str, None)
else:
context = None

Expand Down
23 changes: 21 additions & 2 deletions test/test_projects/test_external_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@
import copy
from urllib.parse import urlparse
import json
from typing import Dict, Any

import ford

from bs4 import BeautifulSoup
import pytest


REMOTE_TYPE_JSON: Dict[str, Any] = {
"name": "remote_type",
"external_url": "./type/remote_type.html",
"obj": "type",
"extends": None,
"variables": [
{
"name": "cptr",
"external_url": "./type/config.html#variable-cptr",
"obj": "variable",
"vartype": "type",
"permission": "public",
},
],
"boundprocs": [],
"permission": "public",
}

REMOTE_MODULES_JSON = [
{
"name": "remote_module",
Expand All @@ -32,7 +51,7 @@
},
},
"pub_absints": {},
"pub_types": {},
"pub_types": {"remote_type": REMOTE_TYPE_JSON},
"pub_vars": {},
"functions": [],
"subroutines": [
Expand All @@ -51,7 +70,7 @@
],
"interfaces": [],
"absinterfaces": [],
"types": [],
"types": [REMOTE_TYPE_JSON],
"variables": [],
}
]
Expand Down
17 changes: 17 additions & 0 deletions test/test_sourceform.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ def test_function_and_subroutine_call_on_same_line(parse_fortran_file):
""",
["p_faz", "p_fuz"],
),
(
"""
USE m_baz, ONLY: t_unknown_parent
TYPE(t_unknown_parent)
call t_unknown_parent%known_method()
""",
["known_method"],
),
],
)
def test_type_chain_function_and_subroutine_calls(
Expand Down Expand Up @@ -501,13 +509,19 @@ def test_type_chain_function_and_subroutine_calls(

USE m_foo, ONLY: t_baz
USE m_bar, ONLY: t_foo
USE unknown_module
TYPE, EXTENDS(t_foo) :: t_bar
TYPE(t_baz) :: v_baz
CONTAINS
PROCEDURE :: p_bar
PROCEDURE :: renamed => p_bar
END TYPE t_bar

TYPE, EXTENDS(unknown_type) :: t_unknown_parent
CONTAINS
PROCEDURE, NOPASS :: known_method
END TYPE

CONTAINS

SUBROUTINE p_bar(self)
Expand All @@ -518,6 +532,9 @@ def test_type_chain_function_and_subroutine_calls(
INTEGER, DIMENSION(2), INTENT(IN) :: var_int
END SUBROUTINE p_buz

SUBROUTINE known_method()
END SUBROUTINE

END MODULE m_baz

MODULE m_main
Expand Down
15 changes: 14 additions & 1 deletion test_data/external_project/top_level_project/src/top_level.f90
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
module config_mod
use remote_module
implicit none
contains

function create() result(config)
type (remote_type) :: config
! Checks call chain following when using external entities
config%cptr%buffer(1:1) = 10
end function create
end module config_mod


module myAbort
use external_module
type, public, extends(solverAborts_type) :: vel_abortCriteria_type
Expand Down Expand Up @@ -39,7 +52,7 @@ program top_level

type, extends(test) :: maintest
character(len=10) :: label
end type
end type maintest

call external_sub
call remote_sub
Expand Down