|
| | __init__ (self, mainScope, _preCompute=None) |
| |
| | __getitem__ (self, *args, **kwargs) |
| |
| | __setitem__ (self, *args, **kwargs) |
| |
| | __delitem__ (self, *args, **kwargs) |
| |
| | __len__ (self, *args, **kwargs) |
| |
| | restrict (self, scopePath, excludeContains) |
| |
| | findVar (self, varName, array=None, exactScope=False, extraVarList=None) |
| |
| | showVarList (self) |
| |
Store the characteristics of all variables contained in a source code.
This class provides methods to query, search, and manage variables
declared in a FORTRAN scope (module, subroutine, function, or type).
Attributes
----------
_varList : list
List of variable descriptors for the current scope.
_fullVarList : list
Complete list of variable descriptors for the whole file.
_scopePath : str
Path of the current scope (e.g., 'module:MODULE/sub:SUB').
Notes
-----
- Variables are found in modules only if the 'ONLY' attribute is used.
- Array specification and type are unknown for module variables.
- 'ASSOCIATE' statements are not followed.
Examples
--------
>>> pft = PYFT('myfile.F90')
>>> vl = pft.varList
>>> vl.findVar('X')
{'n': 'X', 't': 'REAL', 'as': [(None, '10')], 'i': None, ...}
>>> vl.findVar('Y', array=True) # Search only arrays
{'n': 'Y', 't': 'REAL', 'as': [(None, '100'), (None, '100')], ...}
Definition at line 84 of file variables.py.
| pyfortool.variables.VarList.findVar |
( |
|
self, |
|
|
|
varName, |
|
|
|
array = None, |
|
|
|
exactScope = False, |
|
|
|
extraVarList = None |
|
) |
| |
Search for a variable in the list of declared variables.
Parameters
----------
varName : str
Name of the variable to search for.
array : bool, optional
True to limit search to arrays only,
False to limit search to non-array (scalar) variables only,
None (default) to return any variable type.
exactScope : bool, optional
If True, only search for variables declared in the current scope path.
If False (default), search in current scope and all parent scopes.
extraVarList : list, optional
Additional list of variable descriptors to search in.
Useful when variables are defined but not yet in varList.
Returns
-------
dict or None
Variable descriptor dictionary with keys:
- 'n': variable name (uppercase)
- 't': type specification (e.g., 'REAL', 'INTEGER')
- 'as': array specification as list of (lower, upper) tuples
- 'i': intent specification (e.g., 'IN', 'OUT', 'INOUT')
- 'arg': True if dummy argument
- 'scopePath': path where variable is declared
- 'use': module name if imported via USE statement
Returns None if variable not found.
Notes
-----
The function returns the declaration of the variable found in the
deepest (most specific) scope. If `array` is specified, only
returns the variable if its declaration matches the expected kind.
Examples
--------
>>> vl = pft.varList
>>> vl.findVar('X') # Find any variable named X
{'n': 'X', 't': 'REAL', 'as': [], 'i': None, ...}
>>> vl.findVar('Y', array=True) # Find array Y
{'n': 'Y', 't': 'REAL', 'as': [(None, '100')], ...}
>>> vl.findVar('Z', array=False) # Find scalar Z
{'n': 'Z', 't': 'INTEGER', 'as': [], ...}
>>> vl.findVar('P', exactScope=True) # Only in current scope
{'n': 'P', 't': 'REAL', ...}
Definition at line 275 of file variables.py.