Beispiel #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)
Beispiel #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)
Beispiel #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')
Beispiel #4
0
def deep_copy(ast: AST):
    """

	:param ast:
	:return: a deep copy of `ast`

	Only parents and identifiers are updated in the returned ast (e.g., inferred types are not preserved)
	"""
    v = DeepCopyVisitor()
    ast_copy = v.visit(ast)
    ast_copy.parent = ast.parent
    set_parents(ast_copy)
    link_identifiers(ast_copy)
    return ast_copy
Beispiel #5
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)
		s = re.sub(" +\n", "\n", s)
		# next statement can be enabled to determine the computed output
		# print(s)

		# check output
		self.maxDiff = None
		self.assertMultiLineEqual(analysis.code(), s)
Beispiel #6
0
	def test_alias_analysis(self):
		# perform analysis
		ast = build_ast(self.example.code())
		set_parents(ast)
		link_identifiers(ast)
		alias_analysis(ast)