Christophe Favergeon | 3b2a0ee | 2019-06-12 13:29:14 +0200 | [diff] [blame^] | 1 | import argparse |
| 2 | import TestScripts.NewParser as parse |
| 3 | import TestScripts.CodeGen |
| 4 | from 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 |
| 8 | def 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 | |
| 16 | def 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 | |
| 39 | def deprecate(root,others): |
| 40 | if others: |
| 41 | deprecateRec(root,deque(others),True) |
| 42 | correctDeprecation(root) |
| 43 | |
| 44 | parser = argparse.ArgumentParser(description='Parse test description') |
| 45 | parser.add_argument('-f', nargs='?',type = str, default="test.txt", help="File path") |
| 46 | |
| 47 | parser.add_argument('-p', nargs='?',type = str, default="Patterns", help="Pattern dir path") |
| 48 | parser.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. |
| 54 | parser.add_argument('-e', action='store_true', help="Embedded test") |
| 55 | |
| 56 | parser.add_argument('others', nargs=argparse.REMAINDER) |
| 57 | |
| 58 | args = parser.parse_args() |
| 59 | |
| 60 | |
| 61 | if 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) |
| 72 | else: |
| 73 | parser.print_help() |