Mercurial > lcfOS
diff python/c3/analyse.py @ 251:6ed3d3a82a63
Added another c3 example. First import attempt
author | Windel Bouwman |
---|---|
date | Mon, 29 Jul 2013 20:23:13 +0200 |
parents | e41e4109addd |
children | 7416c923a02a |
line wrap: on
line diff
--- a/python/c3/analyse.py Sun Jul 28 19:07:51 2013 +0200 +++ b/python/c3/analyse.py Mon Jul 29 20:23:13 2013 +0200 @@ -12,13 +12,24 @@ def __init__(self, diag): self.diag = diag - def analyzePackage(self, pkg): + def analyzePackage(self, pkg, packageProvider): self.ok = True visitor = Visitor() # Prepare top level scope: self.scopeStack = [topScope] + modScope = Scope(self.CurrentScope) + self.scopeStack.append(modScope) visitor.visit(pkg, self.enterScope, self.quitScope) del self.scopeStack + + # Handle imports: + for i in pkg.imports: + ip = packageProvider.getPackage(i) + if not ip: + self.error('Cannot import {}'.format(i)) + continue + for x in ip.declarations: + modScope.addSymbol(x) visitor.visit(pkg, self.findRefs) visitor.visit(pkg, self.sanity) return self.ok @@ -28,31 +39,29 @@ self.diag.error(msg, loc) @property - def currentScope(self): + def CurrentScope(self): return self.scopeStack[-1] # Scope creation: def addSymbol(self, sym): - if self.currentScope.hasSymbol(sym.name): + if self.CurrentScope.hasSymbol(sym.name): self.error('Redefinition of {0}'.format(sym.name), sym.loc) else: - self.currentScope.addSymbol(sym) + self.CurrentScope.addSymbol(sym) def enterScope(self, sym): # Distribute the scope: - sym.scope = self.currentScope + sym.scope = self.CurrentScope # Add symbols to current scope: - if isinstance(sym, Symbol): - self.addSymbol(sym) - if isinstance(sym, DefinedType): + if isinstance(sym, Symbol) or isinstance(sym, DefinedType): self.addSymbol(sym) # Create subscope: if type(sym) in [Package, Function]: - newScope = Scope(self.currentScope) + newScope = Scope(self.CurrentScope) self.scopeStack.append(newScope) - sym.innerScope = self.currentScope + sym.innerScope = self.CurrentScope def quitScope(self, sym): # Pop out of scope: