Exemplo n.º 1
0
 def test_symbol_table(self):
     ast = build_ast(self.example.code())
     set_parents(ast)
     fill_symbol_table(ast)
     link_identifiers(ast)
     contract = ast.contracts[0]
     self.assertEqual(contract.idf.name, self.name)
Exemplo n.º 2
0
    def test_link_identifiers(self):
        ast = build_ast(simple.code())
        set_parents(ast)
        link_identifiers(ast)

        self.get_ast_elements(ast)

        self.assertEqual(self.identifier_expr.target, self.decl)
        self.assertEqual(self.identifier_expr.get_annotated_type(),
                         self.decl.annotated_type)
Exemplo n.º 3
0
    def test_link_identifiers(self):
        ast = build_ast(simple_storage.code())
        set_parents(ast)
        link_identifiers(ast)
        assignment = ast['SimpleStorage']['set'].body[0]
        self.assertIsInstance(assignment, AssignmentStatement)

        stored_data = assignment.lhs.target
        self.assertEqual(stored_data, ast['SimpleStorage']['storedData'])

        x = assignment.rhs.target
        self.assertEqual(x.idf.name, 'x')
Exemplo n.º 4
0
def transform_ast(ast: SourceUnit) -> Tuple[SourceUnit, Dict[ConstructorOrFunctionDefinition, CircuitHelper]]:
    """
    Convert zkay to solidity AST + proof circuits

    :param ast: zkay AST
    :return: solidity AST and dictionary which maps all function definitions which require verification
             to the corresponding circuit helper instance.
    """
    zt = ZkayTransformer()
    new_ast = zt.visit(ast)

    # restore all parent pointers and identifier targets
    set_parents(new_ast)
    link_identifiers(new_ast)
    return new_ast, zt.circuits
Exemplo n.º 5
0
def deep_copy(ast: T, with_types=False, with_analysis=False) -> T:
    """

    :param ast:
    :param with_types: (optional)
    :return: a deep copy of `ast`

    Only parents and identifiers are updated in the returned ast (e.g., inferred types are not preserved)
    """
    assert isinstance(ast, AST)
    v = DeepCopyVisitor(with_types, with_analysis)
    ast_copy = v.visit(ast)
    ast_copy.parent = ast.parent
    set_parents(ast_copy)
    link_identifiers(ast_copy)
    return ast_copy
Exemplo n.º 6
0
    def test_alias_analysis(self):
        # perform analysis
        ast = build_ast(analysis.code())
        set_parents(ast)
        link_identifiers(ast)
        alias_analysis(ast)

        # generate string, including analysis results
        v = AnalysisCodeVisitor()
        s = v.visit(ast)
        # next statement can be enabled to determine the computed output
        # print(s)

        # check output
        self.maxDiff = None
        self.assertMultiLineEqual(analysis.code(),
                                  re.sub(" +\n", "\n", s.code()))
Exemplo n.º 7
0
def _replace_ast(old_ast: AST, new_ast: AST):
    new_ast.parent = old_ast.parent
    DeepCopyVisitor.copy_ast_fields(old_ast, new_ast)
    if old_ast.parent is not None:
        set_parents(new_ast)
        link_identifiers(new_ast)
Exemplo n.º 8
0
 def test_alias_analysis(self):
     # perform analysis
     ast = build_ast(self.example.code())
     set_parents(ast)
     link_identifiers(ast)
     alias_analysis(ast)