Exemple #1
0
    def test_struct_members_are_kept(self):
        functions = {
            "f": {
                "decl": "struct s f();",
                "header": "tx.h",
                "name": "f",
                "params": [],
                "ret_type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2"
            }
        }
        types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "members": [{
                    "name": "a",
                    "type": "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
                }],
                "name":
                "struct s",
                "type":
                "structure",
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types), types)
Exemple #2
0
    def test_all_unused_type_are_removed(self):
        functions = {
            "f": {
                "decl": "int f();",
                "header": "tx.h",
                "name": "f",
                "params": [],
                "ret_type": "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            }
        }
        types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "name": "const",
                "type": "qualifier",
                "modified_type": "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            },
            "685e80366130387cb75c055248326976d16fdf8d": {
                "name": "float",
                "type": "floating_point_type"
            },
            "d8c550a1f49f312b1bf5709f7f7c7e25e1dfe210": {
                "dimensions": [10],
                "element_type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2",
                "type": "array"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "members": [{
                    "name": "a",
                    "type": "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
                }],
                "name":
                "struct s",
                "type":
                "struct",
            }
        }
        expected_types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types),
                         expected_types)
Exemple #3
0
def main(args):
    merged_types = {}
    merged_functions = {}

    for path in args.path:
        for json_file in get_files_with_suffix_from_path(path, '.json'):
            logging.info('Merging json file {}'.format(json_file))
            merge_json_file(merged_types, merged_functions, json_file)

    if not args.keep_unused_types:
        merged_types = remove_unused_json_types(merged_functions, merged_types)

    logging.info('Writing output to: {}'.format(args.output))
    with open(args.output, 'w') as output_file:
        print_types_functions_json(
            output_file, merged_types, merged_functions, args.json_indent)
Exemple #4
0
    def test_pointed_type_is_kept(self):
        functions = {
            "f": {
                "decl": "int * f();",
                "header": "tx.h",
                "name": "f",
                "params": [],
                "ret_type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2"
            }
        }
        types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "type": "pointer",
                "pointed_type": "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types), types)
Exemple #5
0
    def test_function_type_params_are_kept(self):
        functions = {
            "f": {
                "decl":
                "int f(int f(char));",
                "header":
                "tx.h",
                "name":
                "f",
                "params": [{
                    "name": "f",
                    "type": "361d6282a400aca2fb0ce4b769c85ee086a9ee4c"
                }],
                "ret_type":
                "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            }
        }
        types = {
            "361d6282a400aca2fb0ce4b769c85ee086a9ee4c": {
                "params": [{
                    "name": "",
                    "type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2"
                }],
                "ret_type":
                "46f8ab7c0cff9df7cd124852e26022a6bf89e315",
                "type":
                "function"
            },
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "name": "char",
                "type": "integral_type"
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types), types)
Exemple #6
0
    def test_element_type_of_array_is_kept(self):
        functions = {
            "f": {
                "decl":
                "int f(char a[10]);",
                "header":
                "tx.h",
                "name":
                "f",
                "params": [
                    {
                        "name": "a",
                        "type": "d8c550a1f49f312b1bf5709f7f7c7e25e1dfe210"
                    },
                ],
                "ret_type":
                "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            }
        }
        types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "name": "char",
                "type": "integral_type"
            },
            "d8c550a1f49f312b1bf5709f7f7c7e25e1dfe210": {
                "dimensions": [10],
                "element_type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2",
                "type": "array"
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types), types)
Exemple #7
0
    def test_all_func_parameter_types_are_kept(self):
        functions = {
            "f": {
                "decl":
                "int f(char a, float f);",
                "header":
                "tx.h",
                "name":
                "f",
                "params": [{
                    "name": "a",
                    "type": "71fafc4e2fc1e47e234762a96b80512b6b5534c2"
                }, {
                    "name": "f",
                    "type": "685e80366130387cb75c055248326976d16fdf8d"
                }],
                "ret_type":
                "46f8ab7c0cff9df7cd124852e26022a6bf89e315"
            }
        }
        types = {
            "46f8ab7c0cff9df7cd124852e26022a6bf89e315": {
                "name": "int",
                "type": "integral_type"
            },
            "685e80366130387cb75c055248326976d16fdf8d": {
                "name": "float",
                "type": "floating_point_type"
            },
            "71fafc4e2fc1e47e234762a96b80512b6b5534c2": {
                "name": "char",
                "type": "integral_type"
            }
        }

        self.assertEqual(remove_unused_json_types(functions, types), types)