示例#1
0
    def run(self):
        """
        Entry point for parsing a python script. This will read the script
        line by line until it reaches the end, then it will call
        write_cpp_files to export the code into a cpp file
        """

        # Index for main file and key for main function
        file_index = 0
        function_key = "0"

        # All the code will start with 1 tab indent
        indent = 1

        # Source: https://www.mattlayman.com/blog/2018/decipher-python-ast/
        with open(self.script_path, "r") as py_source:
            tree = ast.parse(py_source.read())
            py_source.seek(0)
            all_lines = py_source.read().splitlines()

        analyzer = pyanalyzer.PyAnalyzer(self.output_files, all_lines)
        analyzer.analyze(tree.body, file_index, function_key, indent)

        self.apply_variable_types()
        self.ingest_comments(all_lines)
        self.write_cpp_files()
示例#2
0
def test_type_precedence_d():
    type_a = ["int"]
    type_b = ["bool"]

    analyzer = pya.PyAnalyzer([], [])
    returned_type = analyzer.type_precedence(type_a, type_b)

    assert returned_type == type_a
示例#3
0
def test_type_precedence_c():
    type_a = ["str"]
    type_b = ["float"]

    analyzer = pya.PyAnalyzer([], [])
    returned_type = analyzer.type_precedence(type_a, type_b)

    assert returned_type == type_a