Deprecate.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from collections import deque
  2. import TestScripts.Parser
  3. # When deprecation is forced on some nodes
  4. # we ensure that a parent of a valid node is also valid
  5. def correctDeprecation(node):
  6. current = node.data["deprecated"]
  7. for c in node.children:
  8. if not correctDeprecation(c):
  9. current = False
  10. node.data["deprecated"] = current
  11. return(current)
  12. def inheritDeprecation(node,deprecated):
  13. current = node.data["deprecated"] or deprecated
  14. node.data["deprecated"] = current
  15. if node.kind != TestScripts.Parser.TreeElem.TEST:
  16. for c in node.children:
  17. inheritDeprecation(c,current)
  18. def deprecateRec(root,others,deprecated):
  19. if others:
  20. newOthers=others.copy()
  21. newOthers.popleft()
  22. if root.kind == TestScripts.Parser.TreeElem.TEST:
  23. if others[0].isdigit() and int(root.id) == int(others[0]):
  24. root.data["deprecated"]=False
  25. for c in root.children:
  26. deprecateRec(c,newOthers,False)
  27. else:
  28. root.data["deprecated"]=True
  29. for c in root.children:
  30. deprecateRec(c,others,deprecated)
  31. else:
  32. if root.data["class"] == others[0]:
  33. root.data["deprecated"]=False
  34. for c in root.children:
  35. deprecateRec(c,newOthers,False)
  36. else:
  37. root.data["deprecated"]=deprecated
  38. for c in root.children:
  39. deprecateRec(c,others,deprecated)
  40. def deprecate(root,others):
  41. inheritDeprecation(root,False)
  42. if others:
  43. deprecateRec(root,deque(others),True)
  44. correctDeprecation(root)