comparison python/c3/analyse.py @ 186:46d62dadd61b

Improved testsuite
author Windel Bouwman
date Sat, 25 May 2013 14:26:25 +0200
parents 0b5b2ee6b435
children c1ccb1cb4cef
comparison
equal deleted inserted replaced
185:51a6440d6398 186:46d62dadd61b
4 class Analyzer: 4 class Analyzer:
5 """ This class checks names and references """ 5 """ This class checks names and references """
6 def __init__(self, diag): 6 def __init__(self, diag):
7 self.diag = diag 7 self.diag = diag
8 self.visitor = Visitor(self.a1, self.analyze) 8 self.visitor = Visitor(self.a1, self.analyze)
9
9 def analyzePackage(self, pkg): 10 def analyzePackage(self, pkg):
10 self.visitor.visit(pkg) 11 self.ok = True
12 self.visitor.visit(pkg)
13 return self.ok
11 def resolveDesignator(self, d, referee=None): 14 def resolveDesignator(self, d, referee=None):
12 assert type(d) is Designator 15 assert type(d) is Designator
13 if d.scope.hasSymbol(d.tname): 16 if d.scope.hasSymbol(d.tname):
14 s = d.scope.getSymbol(d.tname) 17 s = d.scope.getSymbol(d.tname)
15 if hasattr(s, 'addRef'): 18 if hasattr(s, 'addRef'):
16 # TODO: make this nicer 19 # TODO: make this nicer
17 s.addRef(referee) 20 s.addRef(referee)
18 return s 21 return s
19 else: 22 else:
23 self.ok = False
20 msg = 'Cannot resolve name {0}'.format(d.tname) 24 msg = 'Cannot resolve name {0}'.format(d.tname)
21 self.diag.error(msg, d.loc) 25 self.diag.error(msg, d.loc)
22 def a1(self, sym): 26 def a1(self, sym):
23 pass 27 pass
24 def analyze(self, sym): 28 def analyze(self, sym):