|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# BSD 3-Clause License |
| 3 | +# |
| 4 | +# Copyright (c) 2026, Science and Technology Facilities Council. |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are met: |
| 9 | +# |
| 10 | +# * Redistributions of source code must retain the above copyright notice, this |
| 11 | +# list of conditions and the following disclaimer. |
| 12 | +# |
| 13 | +# * Redistributions in binary form must reproduce the above copyright notice, |
| 14 | +# this list of conditions and the following disclaimer in the documentation |
| 15 | +# and/or other materials provided with the distribution. |
| 16 | +# |
| 17 | +# * Neither the name of the copyright holder nor the names of its |
| 18 | +# contributors may be used to endorse or promote products derived from |
| 19 | +# this software without specific prior written permission. |
| 20 | +# |
| 21 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 24 | +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 25 | +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 27 | +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 28 | +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 29 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 31 | +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 32 | +# POSSIBILITY OF SUCH DAMAGE. |
| 33 | +# ----------------------------------------------------------------------------- |
| 34 | + |
| 35 | +""" |
| 36 | +Module containing Fortran2008 Intrinsics. |
| 37 | +""" |
| 38 | + |
| 39 | +from fparser.two.Fortran2003 import Intrinsic_Name as F2003_Intrinsic_Name |
| 40 | +from fparser.two.Fortran2003 import ( |
| 41 | + Intrinsic_Function_Reference as F2003_Intrinsic_Function_Reference, |
| 42 | +) |
| 43 | + |
| 44 | + |
| 45 | +class Intrinsic_Name(F2003_Intrinsic_Name): |
| 46 | + """ |
| 47 | + Represents the name of a Fortran 2008 intrinsic function. |
| 48 | +
|
| 49 | + All generic intrinsic names are specified as keys in the |
| 50 | + `generic_function_names` dictionary, with their values indicating |
| 51 | + the minimum and maximum number of arguments allowed for this |
| 52 | + intrinsic function. A `-1` indicates an unlimited number of |
| 53 | + arguments. The names are split into the categories specified in |
| 54 | + the Fortran2003 specification document. |
| 55 | +
|
| 56 | + All specific intrinsic names (which have a different name to their |
| 57 | + generic counterpart) are specified as keys in the |
| 58 | + `specific_function_names` dictionary, with their values indicating |
| 59 | + which generic function they are associated with |
| 60 | + """ |
| 61 | + |
| 62 | + f08_math_intrinsics = { |
| 63 | + "ERF": {"min": 1, "max": 1}, |
| 64 | + "GAMMA": {"min": 1, "max": 1}, |
| 65 | + } |
| 66 | + |
| 67 | + f08_bitshift_intrinsics = { |
| 68 | + "SHIFTL": {"min": 2, "max": 2}, |
| 69 | + "SHIFTR": {"min": 2, "max": 2}, |
| 70 | + "SHIFTA": {"min": 2, "max": 2}, |
| 71 | + } |
| 72 | + |
| 73 | + # Create the dicts (not inherited from F2003_Intrinsic_Name) |
| 74 | + generic_function_names = {} |
| 75 | + generic_function_names.update(F2003_Intrinsic_Name.generic_function_names) |
| 76 | + generic_function_names.update(f08_math_intrinsics) |
| 77 | + generic_function_names.update(f08_bitshift_intrinsics) |
| 78 | + |
| 79 | + specific_function_names = F2003_Intrinsic_Name.specific_function_names |
| 80 | + |
| 81 | + # A list of all function names |
| 82 | + function_names = list(generic_function_names.keys()) + list( |
| 83 | + specific_function_names.keys() |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +class Intrinsic_Function_Reference(F2003_Intrinsic_Function_Reference): |
| 88 | + """ |
| 89 | + Represents Fortran intrinsics:: |
| 90 | +
|
| 91 | + function-reference is intrinsic-name ( [ actual-arg-spec-list ] ) |
| 92 | +
|
| 93 | + """ |
| 94 | + |
| 95 | + # Set the type of Intrinsic_Name to be used |
| 96 | + _intrinsic_type = Intrinsic_Name |
0 commit comments