Skip to content

Commit

Permalink
Cleanup: replace var_dicts with cldicts in write_debug_checks in suit…
Browse files Browse the repository at this point in the history
…e_objects.py; remove pointer attribute in metavar.py and fortran_tools/parse_fortran.py; import Fortran conditional regex statements from parse_tools
  • Loading branch information
climbfuji committed Nov 22, 2023
1 parent 7256311 commit c2db64d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
3 changes: 0 additions & 3 deletions scripts/fortran_tools/parse_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,6 @@ def parse_fortran_var_decl(line, source, run_env):
if 'allocatable' in varprops:
prop_dict['allocatable'] = 'True'
# end if
if 'pointer' in varprops:
prop_dict['pointer'] = 'True'
# end if
if intent is not None:
prop_dict['intent'] = intent
# end if
Expand Down
9 changes: 1 addition & 8 deletions scripts/metavar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from parse_tools import check_default_value, check_valid_values
from parse_tools import ParseContext, ParseSource, type_name
from parse_tools import ParseInternalError, ParseSyntaxError, CCPPError
from parse_tools import FORTRAN_CONDITIONAL_REGEX_WORDS, FORTRAN_CONDITIONAL_REGEX
from var_props import CCPP_LOOP_DIM_SUBSTS, VariableProperty, VarCompatObj
from var_props import find_horizontal_dimension, find_vertical_dimension
from var_props import standard_name_to_long_name, default_kind_val
Expand Down Expand Up @@ -85,12 +86,6 @@
'horizontal_loop_begin', 'horizontal_loop_end',
'vertical_layer_index', 'vertical_interface_index']

# DH* Is there a better place for these definitions?
FORTRAN_CONDITIONAL_REGEX_WORDS = [' ', '(', ')', '==', '/=', '<=', '>=', '<', '>', '.eqv.', '.neqv.',
'.true.', '.false.', '.lt.', '.le.', '.eq.', '.ge.', '.gt.', '.ne.',
'.not.', '.and.', '.or.', '.xor.']
FORTRAN_CONDITIONAL_REGEX = re.compile(r"[\w']+|" + "|".join([word.replace('(','\(').replace(')', '\)') for word in FORTRAN_CONDITIONAL_REGEX_WORDS]))

###############################################################################
# Used for creating template variables
_MVAR_DUMMY_RUN_ENV = CCPPFrameworkEnv(None, ndict={'host_files':'',
Expand Down Expand Up @@ -193,8 +188,6 @@ class Var:
optional_in=True, default_in=False),
VariableProperty('allocatable', bool,
optional_in=True, default_in=False),
VariableProperty('pointer', bool,
optional_in=True, default_in=False),
VariableProperty('diagnostic_name', str,
optional_in=True, default_in='',
check_fn_in=check_diagnostic_id),
Expand Down
5 changes: 4 additions & 1 deletion scripts/parse_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from xml_tools import find_schema_file, find_schema_version
from xml_tools import read_xml_file, validate_xml_file
from xml_tools import PrettyElementTree
from fortran_conditional import FORTRAN_CONDITIONAL_REGEX_WORDS, FORTRAN_CONDITIONAL_REGEX
# pylint: enable=wrong-import-position

__all__ = [
Expand Down Expand Up @@ -73,5 +74,7 @@
'set_log_to_stdout',
'type_name',
'unique_standard_name',
'validate_xml_file'
'validate_xml_file',
'FORTRAN_CONDITIONAL_REGEX_WORDS',
'FORTRAN_CONDITIONAL_REGEX'
]
32 changes: 14 additions & 18 deletions scripts/suite_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,7 @@ def write_var_debug_check(self, var, dummy, cldicts, outfile, errcode, errmsg, i
standard_name = var.get_prop_value('standard_name')
dimensions = var.get_dimensions()
active = var.get_prop_value('active')
pointer = var.get_prop_value('pointer')
allocatable = var.get_prop_value('allocatable')
# The order is important to get the correct local name - DH* not sure ...
#var_dicts = [ self.__group.call_list ] + self.__group.suite_dicts()
var_dicts = cldicts

# Need the local name as it comes from the group call list
# or from the suite, not how it is called in the scheme (var)
Expand All @@ -1307,21 +1303,21 @@ def write_var_debug_check(self, var, dummy, cldicts, outfile, errcode, errmsg, i
if dvar:
break
if not dvar:
raise Exception(f"No variable with standard name '{standard_name}' in var_dicts")
raise Exception(f"No variable with standard name '{standard_name}' in cldicts")
local_name = dvar.get_prop_value('local_name')

# If the variable is allocatable or a pointer and the intent for the
# scheme is 'out', then we can't test anything because the scheme is
# going to allocate the variable or associate the pointer. We don't have
# this information earlier in add_var_debug_check, therefore need to back
# out here, using the information from the scheme variable (call list).
# If the variable is allocatable and the intent for the scheme is 'out',
# then we can't test anything because the scheme is going to allocate
# the variable. We don't have this information earlier in
# add_var_debug_check, therefore need to back out here,
# using the information from the scheme variable (call list).
svar = self.call_list.find_variable(standard_name=standard_name)
intent = svar.get_prop_value('intent')
if intent == 'out' and (allocatable or pointer):
if intent == 'out' and allocatable:
return

# Get the condition on which the variable is active
(conditional, _) = var.conditional(var_dicts)
(conditional, _) = var.conditional(cldicts)

# For scalars, assign to dummy variable if the variable intent is in/inout
if not dimensions:
Expand All @@ -1342,12 +1338,12 @@ def write_var_debug_check(self, var, dummy, cldicts, outfile, errcode, errmsg, i
if not ':' in dim:
# In capgen, any true dimension (that is not a single index) does
# have a colon (:) in the dimension, therefore this is an index
for var_dict in var_dicts:
for var_dict in cldicts:
dvar = var_dict.find_variable(standard_name=dim, any_scope=False)
if dvar is not None:
break
if not dvar:
raise Exception(f"No variable with standard name '{dim}' in var_dicts")
raise Exception(f"No variable with standard name '{dim}' in cldicts")
dim_lname = dvar.get_prop_value('local_name')
dim_length = 1
dim_strings.append(dim_lname)
Expand All @@ -1374,20 +1370,20 @@ def write_var_debug_check(self, var, dummy, cldicts, outfile, errcode, errmsg, i
else:
(ldim, udim) = dim.split(":")
# Get dimension for lower bound
for var_dict in var_dicts:
for var_dict in cldicts:
dvar = var_dict.find_variable(standard_name=ldim, any_scope=False)
if dvar is not None:
break
if not dvar:
raise Exception(f"No variable with standard name '{ldim}' in var_dicts")
raise Exception(f"No variable with standard name '{ldim}' in cldicts")
ldim_lname = dvar.get_prop_value('local_name')
# Get dimension for upper bound
for var_dict in var_dicts:
for var_dict in cldicts:
dvar = var_dict.find_variable(standard_name=udim, any_scope=False)
if dvar is not None:
break
if not dvar:
raise Exception(f"No variable with standard name '{udim}' in var_dicts")
raise Exception(f"No variable with standard name '{udim}' in cldicts")
udim_lname = dvar.get_prop_value('local_name')
# Assemble dimensions and bounds for size checking
dim_length = f'{udim_lname}-{ldim_lname}+1'
Expand Down

0 comments on commit c2db64d

Please sign in to comment.