diff python/ppci/c3/scope.py @ 354:5477e499b039

Added some sort of string functionality
author Windel Bouwman
date Thu, 13 Mar 2014 18:59:06 +0100
parents e609d5296ee9
children 2ec730e45ea1
line wrap: on
line diff
--- a/python/ppci/c3/scope.py	Sun Mar 09 18:49:10 2014 +0100
+++ b/python/ppci/c3/scope.py	Thu Mar 13 18:59:06 2014 +0100
@@ -1,4 +1,6 @@
 from .astnodes import Constant, Variable, Function, BaseType, Symbol
+from .astnodes import ArrayType, StructureType, DefinedType, PointerType
+from .astnodes import StructField
 
 
 class Scope:
@@ -72,6 +74,13 @@
     scope.addSymbol(BaseType('double'))
     scope.addSymbol(BaseType('void'))
     scope.addSymbol(BaseType('bool'))
-    scope.addSymbol(BaseType('string'))
-    scope.addSymbol(BaseType('byte'))
+    byteType = BaseType('byte')
+    byteType.bytesize = target.byte_sizes['byte']
+    scope.addSymbol(byteType)
+
+    # Construct string type from others:
+    ln = StructField('len', intType)
+    txt = StructField('txt', ArrayType(byteType, 0))
+    strType = DefinedType('string', PointerType(StructureType([ln, txt])), None)
+    scope.addSymbol(strType)
     return scope