Skip to content

Commit

Permalink
Scope normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienRietteMTO committed Oct 15, 2024
1 parent a84df61 commit 2d5f6cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pyft/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def _getRecur(node, level, basePath=''):
if tag(child) in self.SCOPE_CONSTRUCT.values()]:
nodePath = self._getNodePath(child)
if excludeKinds is None or nodePath.split(':')[0] not in excludeKinds:
scopePath = self._getNodePath(child) if basePath in ('', '/') \
scopePath = nodePath if basePath in ('', '/') \
else basePath + '/' + nodePath
results.append(PYFTscope(child,
scopePath=scopePath, parentScope=self,
Expand Down
24 changes: 21 additions & 3 deletions src/pyft/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,28 @@ def varList(self):
# Restrict the object to the current node
return self.mainScope._varList.restrict(self.path, self._excludeContains)

# No @debugDecor for this low-level method
def _normalizeScopeVar(self, scopeVarList):
"""
Internal method to normalize scopeVarList
(list of tuples made of scope path, variable name, and optional other values)
"""
return [(self.normalizeScope(scopePath), var.upper(), *other)
for (scopePath, var, *other) in scopeVarList]

# No @debugDecor for this low-level method
def _normalizeUniqVar(self, scopeVarList):
"""
Internal method to suppress duplicates in scopeVarList
(list of tuples made of scope path and variable name)
(list of tuples made of scope path, variable name, and optional other values)
"""
return list(set((self.normalizeScope(scopePath), var.upper())
for (scopePath, var) in scopeVarList))
# We could use list(set(self._normalizeScopeVar(scopeVarList)))
# but order differs from one execution to the other
result = []
for scopeVar in self._normalizeScopeVar(scopeVarList):
if scopeVar not in result:
result.append(scopeVar)
return result

@debugDecor
def attachArraySpecToEntity(self):
Expand Down Expand Up @@ -496,6 +510,8 @@ def addVar(self, varList):
- position of the variable in the list of dummy argument,
None for a local variable
"""
varList = self._normalizeUniqVar(varList)

for (scopePath, name, declStmt, pos) in varList:
scope = self.getScopeNode(scopePath)

Expand Down Expand Up @@ -586,6 +602,8 @@ def addModuleVar(self, moduleVarList):
subroutine FOO:
USE MODD_XX, ONLY: Y
"""
moduleVarList = self._normalizeScopeVar(moduleVarList)

for (scopePath, moduleName, varName) in moduleVarList:
if varName is None:
varName = []
Expand Down

0 comments on commit 2d5f6cf

Please sign in to comment.