From af169355f72c1a431a2b6dcd2c21381717b92ae9 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Wed, 22 Nov 2023 09:47:48 -0700 Subject: [PATCH] Cleanup: replace var_dicts with cldicts in write_debug_checks in suite_objects.py; remove pointer attribute in metavar.py and fortran_tools/parse_fortran.py; import Fortran conditional regex statements from parse_tools --- scripts/fortran_tools/parse_fortran.py | 3 --- scripts/framework_env.py | 0 scripts/metavar.py | 9 +------- scripts/parse_tools/__init__.py | 5 +++- scripts/suite_objects.py | 32 +++++++++++--------------- 5 files changed, 19 insertions(+), 30 deletions(-) mode change 100755 => 100644 scripts/fortran_tools/parse_fortran.py mode change 100755 => 100644 scripts/framework_env.py mode change 100755 => 100644 scripts/suite_objects.py diff --git a/scripts/fortran_tools/parse_fortran.py b/scripts/fortran_tools/parse_fortran.py old mode 100755 new mode 100644 index a3a05cc5..9aa4de7a --- a/scripts/fortran_tools/parse_fortran.py +++ b/scripts/fortran_tools/parse_fortran.py @@ -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 diff --git a/scripts/framework_env.py b/scripts/framework_env.py old mode 100755 new mode 100644 diff --git a/scripts/metavar.py b/scripts/metavar.py index ed80cd70..16b175a9 100755 --- a/scripts/metavar.py +++ b/scripts/metavar.py @@ -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 @@ -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':'', @@ -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), diff --git a/scripts/parse_tools/__init__.py b/scripts/parse_tools/__init__.py index 4f888fb1..3ce9d344 100644 --- a/scripts/parse_tools/__init__.py +++ b/scripts/parse_tools/__init__.py @@ -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__ = [ @@ -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' ] diff --git a/scripts/suite_objects.py b/scripts/suite_objects.py old mode 100755 new mode 100644 index 15b06be7..2ba55802 --- a/scripts/suite_objects.py +++ b/scripts/suite_objects.py @@ -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) @@ -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: @@ -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) @@ -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'