Skip to content

Commit

Permalink
Merge branch 'master' into 266-fix-examples-in-how-to-write-a-build-c…
Browse files Browse the repository at this point in the history
…onfiguration
  • Loading branch information
MatthewHambley authored Sep 25, 2023
2 parents 962e85c + 4e31606 commit 223acdf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/fab/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def metrics_summary(metrics_folder: Path):
# taller plot after 500 files
# todo: we should also increase the width when lots of quick files become sub-pixel
size = max(10.0, 10 * len(values) / 500)
plt.figure(figsize=[10, size])
plt.figure(figsize=(10, size))

plt.barh(
y=list(range(len(values))),
Expand Down
13 changes: 8 additions & 5 deletions source/fab/parse/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
from typing import Union, Optional, Iterable, Dict, Any, Set

from fparser.two.Fortran2003 import ( # type: ignore
Use_Stmt, Module_Stmt, Program_Stmt, Subroutine_Stmt, Function_Stmt, Language_Binding_Spec,
Entity_Decl_List, Use_Stmt, Module_Stmt, Program_Stmt, Subroutine_Stmt, Function_Stmt, Language_Binding_Spec,
Char_Literal_Constant, Interface_Block, Name, Comment, Module, Call_Stmt, Derived_Type_Def, Derived_Type_Stmt,
Type_Attr_Spec_List, Type_Attr_Spec, Type_Name)

# todo: what else should we be importing from 2008 instead of 2003? This seems fragile.
from fparser.two.Fortran2008 import ( # type: ignore
Type_Declaration_Stmt, Attr_Spec_List, Entity_Decl_List)
Type_Declaration_Stmt, Attr_Spec_List)

from fab.dep_tree import AnalysedDependent
from fab.parse.fortran_common import iter_content, _has_ancestor_type, _typed_child, FortranAnalyserBase
Expand Down Expand Up @@ -227,7 +227,10 @@ def walk_nodes(self, fpath, file_hash, node_tree) -> AnalysedFortran:
spec_list = _typed_child(stmt, Type_Attr_Spec_List)
type_spec = _typed_child(spec_list, Type_Attr_Spec)
if type_spec.children[0] == 'EXTENDS':
if type(type_spec.children[1]) == Name and type_spec.children[1].string == 'kernel_type':
if (
isinstance(type_spec.children[1], Name)
and type_spec.children[1].string == 'kernel_type'
):

# We've found a psyclone kernel metadata. What's it called?
kernel_name = _typed_child(stmt, Type_Name).string
Expand Down Expand Up @@ -314,9 +317,9 @@ def _process_subroutine_or_function(self, analysed_file, fpath, obj):
# not bound, just record the presence of the fortran symbol
# we don't need to record stuff in modules (we think!)
elif not _has_ancestor_type(obj, Module) and not _has_ancestor_type(obj, Interface_Block):
if type(obj) == Subroutine_Stmt:
if isinstance(obj, Subroutine_Stmt):
analysed_file.add_symbol_def(str(obj.get_name()))
if type(obj) == Function_Stmt:
if isinstance(obj, Function_Stmt):
_, name, _, _ = obj.items
analysed_file.add_symbol_def(name.string)

Expand Down
10 changes: 5 additions & 5 deletions source/fab/parse/fortran_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Union, Tuple
from typing import Union, Tuple, Type

from fparser.common.readfortran import FortranFileReader # type: ignore
from fparser.two.parser import ParserFactory # type: ignore
Expand Down Expand Up @@ -48,18 +48,18 @@ def _has_ancestor_type(obj, obj_type):
if not obj.parent:
return False

if type(obj.parent) == obj_type:
if isinstance(obj.parent, obj_type):
return True

return _has_ancestor_type(obj.parent, obj_type)


def _typed_child(parent, child_type, must_exist=False):
def _typed_child(parent, child_type: Type, must_exist=False):
# Look for a child of a certain type.
# Returns the child or None.
# Raises ValueError if more than one child of the given type is found.

children = list(filter(lambda child: type(child) == child_type, parent.children))
children = list(filter(lambda child: isinstance(child, child_type), parent.children))
print(children)
if len(children) > 1:
raise ValueError(f"too many children found of type {child_type}")

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/parse/c/test_c_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ def test_clang_disable():
with mock.patch('fab.parse.c.file_checksum') as mock_file_checksum:
result = CAnalyser().run(Path(__file__).parent / "test_c_analyser.c")

assert type(result[0]) == ImportWarning
assert isinstance(result[0], ImportWarning)
mock_file_checksum.assert_not_called()
2 changes: 1 addition & 1 deletion tests/unit_tests/parse/fortran/test_fortran_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_define_without_bind_name(self, tmp_path):
tree = f2008_parser(reader)

# find the tree node representing the variable binding
var_decl = next(obj for obj in iter_content(tree) if type(obj) == Type_Declaration_Stmt)
var_decl = next(obj for obj in iter_content(tree) if isinstance(obj, Type_Declaration_Stmt))

# run our handler
fpath = Path('foo')
Expand Down

0 comments on commit 223acdf

Please sign in to comment.