diff 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
line wrap: on
line diff
--- a/python/c3/analyse.py	Sat Jul 13 19:53:44 2013 +0200
+++ b/python/c3/analyse.py	Sat Jul 13 20:20:44 2013 +0200
@@ -1,6 +1,7 @@
 from .visitor import Visitor
 from .astnodes import *
 from .scope import Scope, topScope
+from .typecheck import theType
 
 class Analyzer:
     """ 
@@ -79,8 +80,12 @@
             t.ptype = self.resolveType(t.ptype, scope)
             return t
         elif type(t) is StructureType:
+            offset = 0
             for mem in t.mems:
+                mem.offset = offset
                 mem.typ = self.resolveType(mem.typ, scope)
+                offset += theType(mem.typ).bytesize
+            t.bytesize = offset
             return t
         elif type(t) is Designator:
             t = self.resolveDesignator(t, scope)
@@ -90,7 +95,7 @@
             return t
         else:
             raise Exception('Error resolving type {} {}'.format(t, type(t)))
-        
+
     def findRefs(self, sym):
         if type(sym) in [Variable, Constant]:
             sym.typ = self.resolveType(sym.typ, sym.scope)