Mercurial > lcfOS
comparison python/c3/analyse.py @ 231:521567d17388
simplify blink.c3
author | Windel Bouwman |
---|---|
date | Sat, 13 Jul 2013 20:20:44 +0200 |
parents | 82dfe6a32717 |
children | e41e4109addd |
comparison
equal
deleted
inserted
replaced
230:88a1e0baef65 | 231:521567d17388 |
---|---|
1 from .visitor import Visitor | 1 from .visitor import Visitor |
2 from .astnodes import * | 2 from .astnodes import * |
3 from .scope import Scope, topScope | 3 from .scope import Scope, topScope |
4 from .typecheck import theType | |
4 | 5 |
5 class Analyzer: | 6 class Analyzer: |
6 """ | 7 """ |
7 Context handling is done here. | 8 Context handling is done here. |
8 Scope is attached to the correct modules. | 9 Scope is attached to the correct modules. |
77 # TODO: what about structs? | 78 # TODO: what about structs? |
78 if type(t) is PointerType: | 79 if type(t) is PointerType: |
79 t.ptype = self.resolveType(t.ptype, scope) | 80 t.ptype = self.resolveType(t.ptype, scope) |
80 return t | 81 return t |
81 elif type(t) is StructureType: | 82 elif type(t) is StructureType: |
83 offset = 0 | |
82 for mem in t.mems: | 84 for mem in t.mems: |
85 mem.offset = offset | |
83 mem.typ = self.resolveType(mem.typ, scope) | 86 mem.typ = self.resolveType(mem.typ, scope) |
87 offset += theType(mem.typ).bytesize | |
88 t.bytesize = offset | |
84 return t | 89 return t |
85 elif type(t) is Designator: | 90 elif type(t) is Designator: |
86 t = self.resolveDesignator(t, scope) | 91 t = self.resolveDesignator(t, scope) |
87 return self.resolveType(t, scope) | 92 return self.resolveType(t, scope) |
88 elif isinstance(t, Type): | 93 elif isinstance(t, Type): |
89 # Already resolved?? | 94 # Already resolved?? |
90 return t | 95 return t |
91 else: | 96 else: |
92 raise Exception('Error resolving type {} {}'.format(t, type(t))) | 97 raise Exception('Error resolving type {} {}'.format(t, type(t))) |
93 | 98 |
94 def findRefs(self, sym): | 99 def findRefs(self, sym): |
95 if type(sym) in [Variable, Constant]: | 100 if type(sym) in [Variable, Constant]: |
96 sym.typ = self.resolveType(sym.typ, sym.scope) | 101 sym.typ = self.resolveType(sym.typ, sym.scope) |
97 elif type(sym) is TypeCast: | 102 elif type(sym) is TypeCast: |
98 sym.to_type = self.resolveType(sym.to_type, sym.scope) | 103 sym.to_type = self.resolveType(sym.to_type, sym.scope) |