blob: d2caba87a5e01019e0a8b256ade8789529291ba6 [file] [log] [blame]
Christophe Favergeon3b2a0ee2019-06-12 13:29:14 +02001import argparse
2import TestScripts.NewParser as parse
3import TestScripts.CodeGen
4from collections import deque
5
6# When deprecation is forced on some nodes
7# we ensure that a parent of a valid node is also valid
8def correctDeprecation(node):
9 current = node.data["deprecated"]
10 for c in node.children:
11 if not correctDeprecation(c):
12 current = False
13 node.data["deprecated"] = current
14 return(current)
15
16def deprecateRec(root,others,deprecated):
17 if others:
18 newOthers=others.copy()
19 newOthers.popleft()
20 if root.kind == TestScripts.Parser.TreeElem.TEST:
21 if others[0].isdigit() and int(root.id) == int(others[0]):
22 root.data["deprecated"]=False
23 for c in root.children:
24 deprecateRec(c,newOthers,False)
25 else:
26 root.data["deprecated"]=True
27 for c in root.children:
28 deprecateRec(c,others,deprecated)
29 else:
30 if root.data["class"] == others[0]:
31 root.data["deprecated"]=False
32 for c in root.children:
33 deprecateRec(c,newOthers,False)
34 else:
35 root.data["deprecated"]=deprecated
36 for c in root.children:
37 deprecateRec(c,others,deprecated)
38
39def deprecate(root,others):
40 if others:
41 deprecateRec(root,deque(others),True)
42 correctDeprecation(root)
43
44parser = argparse.ArgumentParser(description='Parse test description')
45parser.add_argument('-f', nargs='?',type = str, default="test.txt", help="File path")
46
47parser.add_argument('-p', nargs='?',type = str, default="Patterns", help="Pattern dir path")
48parser.add_argument('-d', nargs='?',type = str, default="Parameters", help="Parameter dir path")
49
50# -e true when no semihosting
51# Input is include files
52# Output is only one stdout
53# So the .h for include files need to be generated.
54parser.add_argument('-e', action='store_true', help="Embedded test")
55
56parser.add_argument('others', nargs=argparse.REMAINDER)
57
58args = parser.parse_args()
59
60
61if args.f is not None:
62 # Create a treeelemt object
63 p = parse.Parser()
64 # Create a codegen object
65 c = TestScripts.CodeGen.CodeGen(args.p,args.d, args.e)
66 # Parse the test description.
67 root = p.parse(args.f)
68 deprecate(root,args.others)
69 print(root)
70 # Generate code with the tree of tests
71 c.genCodeForTree(root)
72else:
73 parser.print_help()