Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
353:b8ad45b3a573 | 354:5477e499b039 |
---|---|
1 from .astnodes import Constant, Variable, Function, BaseType, Symbol | 1 from .astnodes import Constant, Variable, Function, BaseType, Symbol |
2 from .astnodes import ArrayType, StructureType, DefinedType, PointerType | |
3 from .astnodes import StructField | |
2 | 4 |
3 | 5 |
4 class Scope: | 6 class Scope: |
5 """ A scope contains all symbols in a scope. It also has a parent scope, | 7 """ A scope contains all symbols in a scope. It also has a parent scope, |
6 when looking for a symbol, also the parent scopes are checked. """ | 8 when looking for a symbol, also the parent scopes are checked. """ |
70 intType.bytesize = target.byte_sizes['int'] | 72 intType.bytesize = target.byte_sizes['int'] |
71 scope.addSymbol(intType) | 73 scope.addSymbol(intType) |
72 scope.addSymbol(BaseType('double')) | 74 scope.addSymbol(BaseType('double')) |
73 scope.addSymbol(BaseType('void')) | 75 scope.addSymbol(BaseType('void')) |
74 scope.addSymbol(BaseType('bool')) | 76 scope.addSymbol(BaseType('bool')) |
75 scope.addSymbol(BaseType('string')) | 77 byteType = BaseType('byte') |
76 scope.addSymbol(BaseType('byte')) | 78 byteType.bytesize = target.byte_sizes['byte'] |
79 scope.addSymbol(byteType) | |
80 | |
81 # Construct string type from others: | |
82 ln = StructField('len', intType) | |
83 txt = StructField('txt', ArrayType(byteType, 0)) | |
84 strType = DefinedType('string', PointerType(StructureType([ln, txt])), None) | |
85 scope.addSymbol(strType) | |
77 return scope | 86 return scope |