1#!/usr/bin/env python3 2""" 3# Created: Mon Jun 20 17:00:36 2022 (-0400) 4# @author: Jacob Faibussowitsch 5""" 6from __future__ import annotations 7 8from .._typing import * 9 10from ..util._clang import ( 11 clx_scalar_type_kinds, clx_real_type_kinds, clx_int_type_kinds, clx_mpiint_type_kinds, 12 clx_bool_type_kinds, clx_enum_type_kinds 13) 14 15from ._util import ( 16 check_matching_arg_num, check_matching_classid, check_is_petsc_object, check_matching_specific_type, 17 convert_to_correct_PetscValidLogicalCollectiveXXX, 18 check_is_PetscScalar_and_not_PetscReal, 19 check_is_PetscReal_and_not_PetscScalar, 20 check_int_is_not_PetscBool, 21 check_MPIInt_is_not_PetscInt, 22 check_is_PetscBool 23) 24 25"""Specific 'driver' function to test a particular function archetype""" 26def check_obj_idx_generic(linter: Linter, func: Cursor, parent: Cursor) -> None: 27 r"""For generic checks where the form is func(obj1, idx1,..., objN, idxN) 28 29 Parameters 30 ---------- 31 linter : 32 the linter instance 33 func : 34 the function cursor to check 35 parent : 36 the cursor of the parent function 37 38 Notes 39 ----- 40 This is used 'generic' checking macros. I.e. they are comprised of argument and arg_idx pairs, so 41 the only thing to really check is whether the argument number matches. 42 """ 43 func_args = linter.get_argument_cursors(func) 44 parent_args = linter.get_argument_cursors(parent) 45 46 for obj, idx in zip(func_args[::2], func_args[1::2]): 47 check_matching_arg_num(linter, obj, idx, parent_args) 48 return 49 50def checkPetscValidHeaderSpecificType(linter: Linter, func: Cursor, parent: Cursor) -> None: 51 r"""Specific check for PetscValidHeaderSpecificType(obj, classid, idx, type) 52 53 Parameters 54 ---------- 55 linter : 56 the linter instance 57 func : 58 the function cursor to check 59 parent : 60 the cursor of the parent function 61 """ 62 func_args = linter.get_argument_cursors(func) 63 parent_args = linter.get_argument_cursors(parent) 64 65 # Don't need the type 66 obj, classid, idx, _ = func_args 67 check_matching_classid(linter, obj, classid) 68 check_matching_arg_num(linter, obj, idx, parent_args) 69 return 70 71def checkPetscValidHeaderSpecific(linter: Linter, func: Cursor, parent: Cursor) -> None: 72 r"""Specific check for PetscValidHeaderSpecific(obj, classid, idx) 73 74 Parameters 75 ---------- 76 linter : 77 the linter instance 78 func : 79 the function cursor to check 80 parent : 81 the cursor of the parent function 82 """ 83 func_args = linter.get_argument_cursors(func) 84 parent_args = linter.get_argument_cursors(parent) 85 86 obj, classid, idx = func_args 87 check_matching_classid(linter, obj, classid) 88 check_matching_arg_num(linter, obj, idx, parent_args) 89 return 90 91def checkPetscValidHeader(linter: Linter, func: Cursor, parent: Cursor) -> None: 92 r"""Specific check for PetscValidHeader(obj, idx) 93 94 Parameters 95 ---------- 96 linter : 97 the linter instance 98 func : 99 the function cursor to check 100 parent : 101 the cursor of the parent function 102 """ 103 func_args = linter.get_argument_cursors(func) 104 parent_args = linter.get_argument_cursors(parent) 105 106 obj, idx = func_args 107 check_is_petsc_object(linter, obj) 108 check_matching_arg_num(linter, obj, idx, parent_args) 109 return 110 111def checkPetscValidLogicalCollective(linter: Linter, func: Cursor, parent: Cursor, expected_types: Collection[clx.TypeKind], **kwargs) -> None: 112 r"""Generic check for PetscValidLogicalCollectiveXXX(pobj, obj, idx) 113 114 Parameters 115 ---------- 116 linter : 117 the linter instance 118 func : 119 the function cursor to check 120 parent : 121 the cursor of the parent function 122 expected_types : 123 the set of expected types that the second argument in `func` may have 124 **kwargs : 125 additional keyword arguments to `check_matching_specific_type()` 126 """ 127 func_args = linter.get_argument_cursors(func) 128 parent_args = linter.get_argument_cursors(parent) 129 130 # don't need the PETSc object, nothing to check there 131 _, obj, idx = func_args 132 kwargs.setdefault('func_cursor', func) 133 kwargs.setdefault('failure_function', convert_to_correct_PetscValidLogicalCollectiveXXX) 134 check_matching_specific_type(linter, obj, expected_types, False, **kwargs) 135 check_matching_arg_num(linter, obj, idx, parent_args) 136 return 137 138def checkPetscValidLogicalCollectiveScalar(linter: Linter, func: Cursor, parent: Cursor) -> None: 139 r"""Specific check for PetscValidLogicalCollectiveScalar(pobj, obj, idx) 140 141 Parameters 142 ---------- 143 linter : 144 the linter instance 145 func : 146 the function cursor to check 147 parent : 148 the cursor of the parent function 149 """ 150 checkPetscValidLogicalCollective( 151 linter, func, parent, clx_scalar_type_kinds, 152 success_function=check_is_PetscScalar_and_not_PetscReal, 153 valid_func='PetscValidLogicalCollectiveReal' 154 ) 155 return 156 157def checkPetscValidLogicalCollectiveReal(linter: Linter, func: Cursor, parent: Cursor) -> None: 158 r"""Specific check for PetscValidLogicalCollectiveReal(pobj, obj, idx) 159 160 Parameters 161 ---------- 162 linter : 163 the linter instance 164 func : 165 the function cursor to check 166 parent : 167 the cursor of the parent function 168 """ 169 checkPetscValidLogicalCollective( 170 linter, func, parent, clx_real_type_kinds, 171 success_function=check_is_PetscReal_and_not_PetscScalar, 172 valid_func='PetscValidLogicalCollectiveScalar' 173 ) 174 return 175 176def checkPetscValidLogicalCollectiveInt(linter: Linter, func: Cursor, parent: Cursor) -> None: 177 r"""Specific check for PetscValidLogicalCollectiveInt(pobj, obj, idx) 178 179 Parameters 180 ---------- 181 linter : 182 the linter instance 183 func : 184 the function cursor to check 185 parent : 186 the cursor of the parent function 187 """ 188 checkPetscValidLogicalCollective( 189 linter, func, parent, clx_int_type_kinds, 190 success_function=check_int_is_not_PetscBool, valid_func='PetscValidLogicalCollectiveBool' 191 ) 192 return 193 194def checkPetscValidLogicalCollectiveMPIInt(linter: Linter, func: Cursor, parent: Cursor) -> None: 195 r"""Specific check for PetscValidLogicalCollectiveMPIInt(pobj, obj, idx) 196 197 Parameters 198 ---------- 199 linter : 200 the linter instance 201 func : 202 the function cursor to check 203 parent : 204 the cursor of the parent function 205 """ 206 checkPetscValidLogicalCollective( 207 linter, func, parent, clx_mpiint_type_kinds, 208 success_function=check_MPIInt_is_not_PetscInt, valid_func='PetscValidLogicalCollectiveInt' 209 ) 210 return 211 212def checkPetscValidLogicalCollectiveBool(linter: Linter, func: Cursor, parent: Cursor) -> None: 213 r"""Specific check for PetscValidLogicalCollectiveBool(pobj, obj, idx) 214 215 Parameters 216 ---------- 217 linter : 218 the linter instance 219 func : 220 the function cursor to check 221 parent : 222 the cursor of the parent function 223 """ 224 checkPetscValidLogicalCollective( 225 linter, func, parent, clx_bool_type_kinds, success_function=check_is_PetscBool 226 ) 227 return 228 229def checkPetscValidLogicalCollectiveEnum(linter: Linter, func: Cursor, parent: Cursor) -> None: 230 r"""Specific check for PetscValidLogicalCollectiveEnum(pobj, obj, idx) 231 232 Parameters 233 ---------- 234 linter : 235 the linter instance 236 func : 237 the function cursor to check 238 parent : 239 the cursor of the parent function 240 """ 241 checkPetscValidLogicalCollective(linter, func, parent, clx_enum_type_kinds) 242 return 243