PyForTool
Python-fortran-tool
|
Public Member Functions | |
__init__ (self, **kwargs) | |
varList (self) | |
attachArraySpecToEntity (self) | |
checkImplicitNone (self, mustRaise=False) | |
checkIntent (self, mustRaise=False) | |
removeVar (self, varList, simplify=False) | |
addVar (self, varList) | |
addModuleVar (self, moduleVarList) | |
showUnusedVar (self) | |
removeUnusedLocalVar (self, excludeList=None, simplify=False) | |
addExplicitArrayBounds (self, node=None) | |
addArrayParentheses (self) | |
addArrayParenthesesInNode (self, node) | |
modifyAutomaticArrays (self, declTemplate=None, startTemplate=None, endTemplate=None) | |
findIndexArrayBounds (self, arr, index, loopVar) | |
arrayR2parensR (self, namedE, table) | |
findArrayBounds (self, arr, loopVar, extraVarList=None) | |
renameVar (self, oldName, newName) | |
removeVarIfUnused (self, varList, excludeDummy=False, excludeModule=False, simplify=False) | |
isVarUsed (self, varList, exactScope=False, dummyAreAlwaysUsed=False) | |
addArgInTree (self, varName, declStmt, pos, stopScopes, moduleVarList=None, otherNames=None, parser=None, parserOptions=None, wrapH=False) | |
Static Public Member Functions | |
varSpec2stmt (varSpec) | |
Public Attributes | |
path | |
Protected Member Functions | |
_normalizeScopeVar (self, scopeVarList) | |
_normalizeUniqVar (self, scopeVarList) | |
Protected Attributes | |
_varList | |
_excludeContains | |
Methos to deal with variables
Definition at line 250 of file variables.py.
pyfortool.variables.Variables.__init__ | ( | self, | |
** | kwargs | ||
) |
**kwargs is used to enable the use of super().__init__
Reimplemented in pyfortool.pyfortool.PYFT, and pyfortool.scope.PYFTscope.
Definition at line 254 of file variables.py.
|
protected |
Internal method to normalize scopeVarList (list of tuples made of scope path, variable name, and optional other values)
Definition at line 274 of file variables.py.
|
protected |
Internal method to suppress duplicates in scopeVarList (list of tuples made of scope path, variable name, and optional other values)
Definition at line 283 of file variables.py.
pyfortool.variables.Variables.addArgInTree | ( | self, | |
varName, | |||
declStmt, | |||
pos, | |||
stopScopes, | |||
moduleVarList = None , |
|||
otherNames = None , |
|||
parser = None , |
|||
parserOptions = None , |
|||
wrapH = False |
|||
) |
Adds an argument to the routine and propagates it upward until we encounter a scope where the variable exists or a scope in stopScopes :param varName: variable name :param declStmt: declarative statment (will be used by addVar) :param pos: position of the variable in the list of dummy argument :param stopScopes: list of scopes to reach :param moduleVarList: list of module variable specification to insert in the xml code a module variable specification is a list of two elements: - module name - variable name or or list of variable names or None to add a USE statement without the ONLY attribute use moduleVarList to not add module variables :param otherNames: None or list of other variable names that can be used These variables are used first :param parser, parserOptions, wrapH: see the PYFT class Argument is inserted only on paths leading to one of scopes listed in stopScopes
Definition at line 1358 of file variables.py.
pyfortool.variables.Variables.addArrayParentheses | ( | self | ) |
Look for arrays and add parenthesis. A => A(:)
Definition at line 749 of file variables.py.
pyfortool.variables.Variables.addArrayParenthesesInNode | ( | self, | |
node | |||
) |
Look for arrays and add parenthesis. A => A(:) :param node: xml node in which ':' must be added
Definition at line 793 of file variables.py.
pyfortool.variables.Variables.addExplicitArrayBounds | ( | self, | |
node = None |
|||
) |
Replace ':' by explicit arrays bounds. :param node: xml node in which ':' must be replaced (None to replace everywhere)
Definition at line 693 of file variables.py.
pyfortool.variables.Variables.addModuleVar | ( | self, | |
moduleVarList | |||
) |
:param moduleVarList: list of module variable specification to insert in the xml code a module variable specification is a list of three elements: - scope path (path to module, subroutine, function or type declaration) - module name - variable name or or list of variable names or None to add a USE statement without the ONLY attribute For example addModuleVar('sub:FOO', 'MODD_XX', 'Y') will add the following line in subroutine FOO: USE MODD_XX, ONLY: Y
Definition at line 594 of file variables.py.
pyfortool.variables.Variables.addVar | ( | self, | |
varList | |||
) |
:param varList: list of variable specification to insert in the xml code a variable specification is a list of four elements: - variable scope path (path to module, subroutine, function or type declaration) - variable name - declarative statment - position of the variable in the list of dummy argument, None for a local variable
Definition at line 504 of file variables.py.
pyfortool.variables.Variables.arrayR2parensR | ( | self, | |
namedE, | |||
table | |||
) |
Transform a array-R into a parens-R node by replacing slices by variables In 'A(:)', the ':' is in a array-R node whereas in 'A(JL)', 'JL' is in a parens-R node. Both the array-R and the parens-R nodes are inside a R-LT node :param namedE: a named-E node :param table: dictionnary returned by the decode function :param varList: None or a VarList object in which varaibles are searched for
Definition at line 1043 of file variables.py.
pyfortool.variables.Variables.attachArraySpecToEntity | ( | self | ) |
Find all T-decl-stmt elements that have a child element 'attribute' with attribute-N="DIMENSION" and move the attribute into EN-N elements E.g., before : REAL, DIMENSION(D%NIJT,D%NKT) :: ZTLK, ZRT INTEGER, PARAMETER, DIMENSION(1,1) :: IBUEXTRAIND=(/18, 30/) after : REAL :: ZTLK(D%NIJT,D%NKT), ZRT(D%NIJT,D%NKT) INTEGER, PARAMETER :: IBUEXTRAIND(1,1)=(/18, 30/) Limitations : "DIMENSION" must be in upper case in attribute.text
Definition at line 297 of file variables.py.
pyfortool.variables.Variables.checkImplicitNone | ( | self, | |
mustRaise = False |
|||
) |
:param mustRaise: True to raise Issue a logging.warning if the "IMPLICIT NONE" statment is missing If mustRaise is True, issue a logging.error instead and raise an error
Definition at line 327 of file variables.py.
pyfortool.variables.Variables.checkIntent | ( | self, | |
mustRaise = False |
|||
) |
:param mustRaise: True to raise Issue a logging.warning if some "INTENT" attributes are missing If mustRaise is True, issue a logging.error instead and raise an error
Definition at line 349 of file variables.py.
pyfortool.variables.Variables.findArrayBounds | ( | self, | |
arr, | |||
loopVar, | |||
extraVarList = None |
|||
) |
Find bounds and loop variable given an array :param arr: array node (named-E node with a array-R child) :param loopVar: None to create new variable for each added DO loop or a function that return the name of the variable to use for the loop control. This function returns a string (name of the variable), or True to create a new variable, or False to not transform this statement The functions takes as arguments: - lower and upper bounds as defined in the declaration statement - lower and upper bounds as given in the statement - name of the array - index of the rank :param extraVarList: None or list of variables (such as those contained in a VarList object) defined but not yet available in the self.varList object. :return: the tuple (table, newVar) where: table is a dictionnary: keys are loop variable names values are tuples with lower and upper bounds newVar is a list of loop variables not found in varList. This list has the same format as the varList list. In case the loop variable cannot be defined, the function returns (None, [])
Definition at line 1137 of file variables.py.
pyfortool.variables.Variables.findIndexArrayBounds | ( | self, | |
arr, | |||
index, | |||
loopVar | |||
) |
Find bounds and loop variable for a given array index :param arr: array node (named-E node with a array-R child) :param index: index of the rank of the array :param loopVar: None to create new variable for each added DO loop or a function that return the name of the variable to use for the loop control. This function returns a string (name of the variable), or True to create a new variable, or False to not transform this statement The functions takes as arguments: - lower and upper bounds as defined in the declaration statement - lower and upper bounds as given in the statement - name of the array - index of the rank :return: the tuple (loopName, lowerBound, upperBound) where: loopName is the name of the variable to use for the loop lower and upper bounds are the bounds to use for the DO loop loopName can be: - a string - False to discard this index - True to create a new variable to loop with
Definition at line 989 of file variables.py.
pyfortool.variables.Variables.isVarUsed | ( | self, | |
varList, | |||
exactScope = False , |
|||
dummyAreAlwaysUsed = False |
|||
) |
:param varList: list of variables to test. Each item is a list or tuple of two elements. The first one describes where the variable is declared, the second one is the name of the variable. The first element is a '/'-separated path with each element having the form 'module:<name of the module>', 'sub:<name of the subroutine>' or 'func:<name of the function>' :param exactScope: True to search strictly in scope :param dummyAreAlwaysUsed: Returns True if variable is a dummy argument :return: a dict whose keys are the elements of varList, and values are True when the variable is used, False otherwise If exactScope is True, the function will search for variable usage only in this scope. But this feature has a limited interest. If exactScope is False: - if scopePath is a subroutine/function in a contains section, and if the variable is not declared in this scope, usages are searched in the module/subroutine/function upper that declared the variable and in all subroutines/functions in the contains section - if scopePath is a module/subroutine/function that has a contains sections, usages are searched in all subroutines/functions in the contains section To know if a variable can be removed, you must use exactScope=False
Definition at line 1261 of file variables.py.
pyfortool.variables.Variables.modifyAutomaticArrays | ( | self, | |
declTemplate = None , |
|||
startTemplate = None , |
|||
endTemplate = None |
|||
) |
:param declTemplate: declaration template :param startTemplate: template for the first executable statement :param: endTemplate: template for the last executable statement :return: number of arrays modified Modifies all automatic arrays declaration in subroutine and functions. The declaration is replaced by the declaration template, the start template is inserted as first executable statement and the end template as last executable statement. Each template can use the following place holders: "{doubledotshape}", "{shape}", "{lowUpList}", "{name}" and "{type}" wich are, respectively modified into ":, :, :", "I, I:J, 0:I", "1, I, I, J, 0, I", "A", "REAL" if the original declaration statement was "A(I, I:J, 0:I)". The template "{type}, DIMENSION({doubledotshape}), ALLOCATABLE :: {name}# ALLOCATE({name}({shape}))#DEALLOCATE({name})" replaces automatic arrays by allocatables
Definition at line 826 of file variables.py.
pyfortool.variables.Variables.removeUnusedLocalVar | ( | self, | |
excludeList = None , |
|||
simplify = False |
|||
) |
Remove unused local variables (dummy and module variables are not suppressed) :param excludeList: list of variable names to exclude from removal (even if unused) :param simplify: try to simplify code (if we delete a declaration statement that used a variable as kind selector, and if this variable is not used else where, we also delete it)
Definition at line 673 of file variables.py.
pyfortool.variables.Variables.removeVar | ( | self, | |
varList, | |||
simplify = False |
|||
) |
:param varList: list of variables to remove. Each item is a list or tuple of two elements. The first one describes where the variable is used, the second one is the name of the variable. The first element is a '/'-separated path with each element having the form 'module:<name of the module>', 'sub:<name of the subroutine>', 'func:<name of the function>' or 'type:<name of the type>' :param simplify: try to simplify code (if we delete a declaration statement that used a variable as kind selector, and if this variable is not used else where, we also delete it) Remove the variable from declaration, and from the argument list if needed
Definition at line 370 of file variables.py.
pyfortool.variables.Variables.removeVarIfUnused | ( | self, | |
varList, | |||
excludeDummy = False , |
|||
excludeModule = False , |
|||
simplify = False |
|||
) |
:param varList: list of variables to remove if unused. Each item is a list or tuple of two elements. The first one describes where the variable is used, the second one is the name of the variable. The first element is a '/'-separated path with each element having the form 'module:<name of the module>', 'sub:<name of the subroutine>' or 'func:<name of the function>' :param excludeDummy: if True, dummy arguments are always kept untouched :param excludeModule: if True, module variables are always kept untouched :param simplify: try to simplify code (if we delete a declaration statement that used a variable as kind selector, and if this variable is not used else where, we also delete it) :return: the varList without the unremovable variables If possible, remove the variable from declaration, and from the argument list if needed
Definition at line 1230 of file variables.py.
pyfortool.variables.Variables.renameVar | ( | self, | |
oldName, | |||
newName | |||
) |
:param oldName: old name of the variable :param newName: new name of the variable
Definition at line 1216 of file variables.py.
pyfortool.variables.Variables.showUnusedVar | ( | self | ) |
Displays on stdout a list of unued variables
Definition at line 657 of file variables.py.
pyfortool.variables.Variables.varList | ( | self | ) |
Returns the varList object corresponding to the node
Definition at line 261 of file variables.py.
|
static |
:param varSpec: a variable description, same form as the items return by self.varList :return: the associated declarative statement
Definition at line 951 of file variables.py.
|
protected |
Definition at line 271 of file variables.py.
|
protected |
Definition at line 258 of file variables.py.
pyfortool.variables.Variables.path |
Reimplemented in pyfortool.scope.PYFTscope.
Definition at line 271 of file variables.py.