|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from dataclasses import dataclass, field |
| 4 | +from typing import NamedTuple |
| 5 | + |
| 6 | +#: A single line range tuple |
| 7 | +Range = NamedTuple("Range", [("start", int), ("end", int)]) |
| 8 | + |
| 9 | + |
| 10 | +@dataclass |
| 11 | +class VAR_info: |
| 12 | + """Holds information about a Fortran VARIABLE""" |
| 13 | + |
| 14 | + var_type: str #: Type of variable e.g. ``INTEGER``, ``REAL``, etc. |
| 15 | + #: keywords associated with this variable e.g. SAVE, DIMENSION, etc. |
| 16 | + keywords: list[str] #: Keywords associated with variable |
| 17 | + var_names: list[str] #: Variable names |
| 18 | + |
| 19 | + |
| 20 | +@dataclass |
| 21 | +class SELECT_info: |
| 22 | + """Holds information about a SELECT construct""" |
| 23 | + |
| 24 | + type: int #: Type of SELECT e.g. normal, select type, select kind, select rank |
| 25 | + binding: str #: Variable/Object being selected upon |
| 26 | + desc: str #: Description of select e.g. "TYPE", "CLASS", None |
| 27 | + |
| 28 | + |
| 29 | +@dataclass |
| 30 | +class CLASS_info: |
| 31 | + """Holds information about a Fortran CLASS""" |
| 32 | + |
| 33 | + name: str #: Class name |
| 34 | + parent: str #: Parent object of class e.g. ``TYPE, EXTENDS(scaled_vector) :: a`` |
| 35 | + keywords: str #: Keywords associated with the class |
| 36 | + |
| 37 | + |
| 38 | +@dataclass |
| 39 | +class USE_info: |
| 40 | + """Holds information about a Fortran USE statement""" |
| 41 | + |
| 42 | + mod_name: str #: Module name |
| 43 | + #: List of procedures, variables, interfaces, etc. imported via only |
| 44 | + only_list: set[str] |
| 45 | + #: A dictionary holding the new names after a rename operation |
| 46 | + rename_map: dict[str, str] |
| 47 | + |
| 48 | + |
| 49 | +@dataclass |
| 50 | +class GEN_info: |
| 51 | + """Holds information about a GENERIC PROCEDURE DEFINITION""" |
| 52 | + |
| 53 | + bound_name: str #: Procedure name |
| 54 | + pro_links: list[str] #: Procedure links |
| 55 | + vis_flag: int #: Visibility flag, public or private |
| 56 | + |
| 57 | + |
| 58 | +@dataclass |
| 59 | +class SMOD_info: |
| 60 | + """Holds information about Fortran SUBMODULES""" |
| 61 | + |
| 62 | + name: str #: Submodule name |
| 63 | + parent: str #: Submodule i.e. module, parent |
| 64 | + |
| 65 | + |
| 66 | +@dataclass |
| 67 | +class INT_info: |
| 68 | + """Holds information about a Fortran INTERFACE""" |
| 69 | + |
| 70 | + name: str #: Interface name |
| 71 | + abstract: bool #: Whether or not the interface is abstract |
| 72 | + |
| 73 | + |
| 74 | +@dataclass |
| 75 | +class VIS_info: |
| 76 | + """Holds information about the VISIBILITY of a module's contents""" |
| 77 | + |
| 78 | + type: int #: Visibility type 0: PUBLIC 1: PRIVATE TODO: convert to boolean |
| 79 | + obj_names: list[str] #: Module variables, procedures, etc. with that visibility |
| 80 | + |
| 81 | + |
| 82 | +@dataclass |
| 83 | +class INCLUDE_info: |
| 84 | + """Holds information about a Fortran INCLUDE statement""" |
| 85 | + |
| 86 | + line_number: int #: Line number of include |
| 87 | + path: str #: File path to include |
| 88 | + file: None # fortran_file #: fortran_file object |
| 89 | + scope_objs: list[str] #: A list of available scopes |
| 90 | + |
| 91 | + |
| 92 | +@dataclass |
| 93 | +class SUB_info: |
| 94 | + """Holds information about a Fortran SUBROUTINE""" |
| 95 | + |
| 96 | + name: str #: Procedure name |
| 97 | + args: str #: Argument list |
| 98 | + #: Keywords associated with procedure |
| 99 | + keywords: list[str] = field(default_factory=list) |
| 100 | + #: Whether or not this is a ``MODULE PROCEDURE`` |
| 101 | + mod_flag: bool = field(default=False) |
| 102 | + |
| 103 | + |
| 104 | +@dataclass |
| 105 | +class RESULT_sig: |
| 106 | + """Holds information about the RESULT section of a Fortran FUNCTION""" |
| 107 | + |
| 108 | + name: str = field(default=None) #: Variable name of result |
| 109 | + type: str = field(default=None) #: Variable type of result |
| 110 | + #: Keywords associated with the result variable, can append without init |
| 111 | + keywords: list[str] = field(default_factory=list) |
| 112 | + |
| 113 | + |
| 114 | +@dataclass |
| 115 | +class FUN_sig(SUB_info): |
| 116 | + """Holds information about a Fortran FUNCTION""" |
| 117 | + |
| 118 | + #: Function's result with default ``result.name = name`` |
| 119 | + result: RESULT_sig = field(default_factory=RESULT_sig) |
| 120 | + |
| 121 | + def __post_init__(self): |
| 122 | + if not self.result.name: |
| 123 | + self.result.name = self.name |
0 commit comments