Esempio 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)
Esempio n. 2
0
	def test_all_nodes_have_parent(self):
		ast = build_ast(self.example.code())
		set_parents(ast)

		# test
		v = ParentChecker()
		v.visit(ast)
Esempio n. 3
0
	def test_root_children_have_parent(self):
		ast = build_ast(self.example.code())
		set_parents(ast)

		# test
		for c in ast.children():
			self.assertEqual(c.parent, ast)
Esempio n. 4
0
	def test_contract_identifier(self):
		ast = build_ast(self.example.code())
		set_parents(ast)

		# test
		contract = ast.contracts[0]
		idf = contract.idf
		self.assertEqual(idf.parent, contract)
Esempio n. 5
0
    def test_fill_symbol_table(self):
        ast = build_ast(simple.code())
        fill_symbol_table(ast)

        self.get_ast_elements(ast)

        self.assertDictEqual(ast.names, {'Simple': self.contract.idf})
        self.assertDictEqual(self.contract.names, {'f': self.f.idf})
        self.assertDictEqual(self.body.names, {'x': self.decl.idf})
Esempio n. 6
0
def get_processed_ast(code,
                      parents=True,
                      link_identifiers=True,
                      check_return=True,
                      alias_analysis=True,
                      type_check=True):
    ast = build_ast(code)
    process_ast(ast, parents, link_identifiers, check_return, alias_analysis,
                type_check)
    return ast
Esempio n. 7
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)
Esempio n. 8
0
 def test_to_ast_and_back(self):
     # ast
     ast = build_ast(self.example.code())
     # back to string
     new_code = str(ast)
     self.assertIn(self.example.name(), new_code)
     new_code = normalize_code(new_code)
     # reference
     reference = normalize_code(self.example.code())
     # check
     self.assertEqual(reference, new_code)
Esempio n. 9
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')
Esempio n. 10
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)
Esempio n. 11
0
 def test_deep_copy(self):
     ast = build_ast(self.example.code())
     ast_2 = deep_copy(ast)
     self.assertEqual(str(ast), str(ast_2))
Esempio n. 12
0
    def test_fill_symbol_table(self):
        ast = build_ast(simple_storage.code())
        fill_symbol_table(ast)

        contract = ast.contracts[0]
        self.assertDictEqual(ast.names, {'SimpleStorage': contract.idf})
Esempio n. 13
0
 def test_build_ast(self):
     ast = build_ast(self.example.code())
     self.assertIsNotNone(ast)
Esempio n. 14
0
	def test_alias_analysis(self):
		# perform analysis
		ast = build_ast(self.example.code())
		set_parents(ast)
		link_identifiers(ast)
		alias_analysis(ast)