def updateVariableNames(a, varMap, scopeName, randomCounter, imports):
if not isinstance(a, ast.AST):
return
if type(a) in [ast.FunctionDef, ast.ClassDef]:
if a.name in varMap:
if not hasattr(a, "originalId"):
a.originalId = a.name
a.name = varMap[a.name]
anonymizeStatementNames(a, varMap, "_" + a.name, imports)
elif type(a) == ast.arg:
if a.arg not in varMap and not (builtInName(a.arg) or importedName(a.arg, imports)):
log("Can't assign to arg?", "bug")
if a.arg in varMap:
if not hasattr(a, "originalId"):
a.originalId = a.arg
if varMap[a.arg][0] == "r":
a.randomVar = True # so we know it can crash
if a.arg == varMap[a.arg]:
# Check whether this is a given name
if not isAnonVariable(varMap[a.arg]):
a.dontChangeName = True
a.arg = varMap[a.arg]
elif type(a) == ast.Name:
if a.id not in varMap and not (builtInName(a.id) or importedName(a.id, imports)):
varMap[a.id] = "r" + str(randomCounter[0]) + scopeName
randomCounter[0] += 1
if a.id in varMap:
if not hasattr(a, "originalId"):
a.originalId = a.id
if varMap[a.id][0] == "r":
a.randomVar = True # so we know it can crash
if a.id == varMap[a.id]:
# Check whether this is a given name
if not isAnonVariable(varMap[a.id]):
a.dontChangeName = True
a.id = varMap[a.id]
else:
for child in ast.iter_child_nodes(a):
updateVariableNames(child, varMap, scopeName, randomCounter, imports)
评论列表
文章目录