Exemplo n.º 1
0
def run_ar_tests():
    """
    Прогоняет тесты записей активаций для всех программ
    в папках samples/good и samples/bad
    :return:
    """
    print("### Тесты AR ###")
    print()

    if not os.path.exists('../tests/st'):
        os.mkdir('../tests/st')

    if not os.path.exists('../tests/st/good'):
        os.mkdir('../tests/st/good')

    good_samples = os.listdir('../samples/good')
    for sample in good_samples:
        print(f'Разбираем хорошую программу {sample} ...')
        program = parse_program(Path('../samples/good') / Path(sample))

        table = Table()
        filler = TableFiller(table, verbose=False)
        filler.fill_table(program)

        frame_filler = FrameFiller(table)
        frame_filler.fill()
        print()
Exemplo n.º 2
0
def run_lir_tests():
    """
    Прогоняет тесты линеаризации канонических IR деревьев
    в папке samples/good
    :return:
    """
    sys.setrecursionlimit(1500)

    print("### Тесты LIR ###")
    print()

    if not os.path.exists('../tests/lir_tree'):
        os.mkdir('../tests/lir_tree')

    if not os.path.exists('../tests/lir_tree/good'):
        os.mkdir('../tests/lir_tree/good')

    good_samples = os.listdir('../samples/good')
    for sample in good_samples:
        print(f'Разбираем хорошую программу {sample} ...')
        program = parse_program(Path("../samples/good") / Path(sample))
        print()

        table = Table()
        filler = TableFiller(table, verbose=False)
        filler.fill_table(program)
        table = filler.table

        type_checker = TypeChecker(table)
        type_checker.check_ast_st(program)

        filler.fill_class_struct()
        table = filler.table

        frame_filler = FrameFiller(table, verbose=False)
        frame_filler.fill()

        builder = IRBuilder(table)
        builder.parse(program)
        trees = builder.trees

        canonizer = EseqCanonizer()
        canonized_trees = dict()
        for key, tree in trees.items():
            canonized_tree = canonizer.canonize(tree)
            canonized_trees[key] = canonized_tree

        linearizer = Linearizer()
        linearized = dict()
        for tree_key, tree_value in canonized_trees.items():
            linearized[tree_key] = []
            linearized[tree_key] = linearizer.linearize(
                tree_value, linearized[tree_key])

        printer = IRPrinter(
            Path('../tests/lir_tree/good') /
            Path(sample.replace('.java', '.gv')))
        printer.create_linearized_graph(linearized)
        printer.print_to_file()
        print()
Exemplo n.º 3
0
def run_tc_tests():
    """
    Прогоняет тесты проверки типов тайпчекером для всех программ
    в папках samples/good и samples/bad
    :return:
    """
    print("### Тесты TC ###")
    print()

    if not os.path.exists('../tests/st'):
        os.mkdir('../tests/st')

    if not os.path.exists('../tests/st/good'):
        os.mkdir('../tests/st/good')

    good_samples = os.listdir('../samples/good')
    for sample in good_samples:
        print(f'Разбираем хорошую программу {sample} ...')
        program = parse_program(Path('../samples/good') / Path(sample))

        table = Table()
        filler = TableFiller(table)
        filler.fill_table(program)

        type_checker = TypeChecker(table)
        type_checker.check_ast_st(program)
        print()

    if not os.path.exists('../tests/st/bad'):
        os.mkdir('../tests/st/bad')

    bad_samples = os.listdir('../samples/bad')
    for sample in bad_samples:
        print(f'Разбираем плохую программу {sample} ...')
        try:
            program = parse_program(Path('../samples/bad') / Path(sample))

            table = Table()
            filler = TableFiller(table, verbose=False)
            filler.fill_table(program)

            type_checker = TypeChecker(table)
            type_checker.check_ast_st(program)
        except SyntaxError as error:
            print(error)
        print()
Exemplo n.º 4
0
def run_st_tests():
    """
    Прогоняет тесты получения символьной таблицы для всех программ
    в папках samples/good и samples/bad
    :return:
    """
    print("### Тесты ST ###")
    print()

    if not os.path.exists('../tests/st'):
        os.mkdir('../tests/st')

    if not os.path.exists('../tests/st/good'):
        os.mkdir('../tests/st/good')

    good_samples = os.listdir('../samples/good')
    for sample in good_samples:
        print(f'Разбираем хорошую программу {sample} ...')
        program = parse_program(Path('../samples/good') / Path(sample))

        table = Table()
        filler = TableFiller(table, verbose=True)
        filler.fill_table(program)
        print()

    if not os.path.exists('../tests/st/bad'):
        os.mkdir('../tests/st/bad')

    bad_samples = os.listdir('../samples/bad')
    for sample in bad_samples:
        print(f'Разбираем плохую программу {sample} ...')
        try:
            program = parse_program(Path('../samples/bad') / Path(sample))

            table = Table()
            filler = TableFiller(table, verbose=True)
            filler.fill_table(program)
        except SyntaxError as error:
            print(error)
        print()
Exemplo n.º 5
0
def run_ir_tests():
    """
    Прогоняет тесты записей активаций для всех программ
    в папках samples/good и samples/bad
    :return:
    """
    print("### Тесты IR ###")
    print()

    if not os.path.exists('../tests/ir_tree'):
        os.mkdir('../tests/ir_tree')

    if not os.path.exists('../tests/ir_tree/good'):
        os.mkdir('../tests/ir_tree/good')

    good_samples = os.listdir('../samples/good')
    for sample in good_samples:
        print(f'Разбираем хорошую программу {sample} ...')
        program = parse_program(Path("../samples/good") / Path(sample))
        print()

        table = Table()
        filler = TableFiller(table, verbose=False)
        filler.fill_table(program)
        table = filler.table

        type_checker = TypeChecker(table)
        type_checker.check_ast_st(program)

        filler.fill_class_struct()
        table = filler.table

        frame_filler = FrameFiller(table, verbose=False)
        frame_filler.fill()

        builder = IRBuilder(table)
        builder.parse(program)
        trees = builder.trees

        printer = IRPrinter(
            Path('../tests/ir_tree/good') /
            Path(sample.replace('.java', '.gv')))
        printer.create_graph(trees)
        printer.print_to_file()
        print()
Exemplo n.º 6
0
    # строим абстрактное синтаксическое дерево
    print('### Построение абстрактного синтаксического дерева ###')
    program = parse_program("../samples/good/Factorial.java")
    print()

    # распечатываем абстрактное синтаксическое дерево
    print('### Печать абстрактного синтаксического дерева ###')
    printer = Printer('../tests/ast_tree.gv')
    printer.visit(program)
    printer.print_to_file()
    print()

    # отображаем символьную таблицу
    print('### Символьная таблица ###')
    table = Table()
    filler = TableFiller(table, verbose=True)
    filler.fill_table(program)
    table = filler.table
    print()

    # проверка тайпчекером
    print('### Проверка типов тайпчекером ###')
    type_checker = TypeChecker(table, verbose=True)
    type_checker.check_ast_st(program)
    print()

    # заполняем class_struct-ы
    filler.fill_class_struct()
    table = filler.table

    # записи активаций