Mercurial > lcfOS
comparison python/ppci/c3/astnodes.py @ 389:2ec730e45ea1
Added check for recursive struct
author | Windel Bouwman |
---|---|
date | Fri, 16 May 2014 12:29:31 +0200 |
parents | 5477e499b039 |
children | 6ae782a085e0 |
comparison
equal
deleted
inserted
replaced
388:e07c2a9abac1 | 389:2ec730e45ea1 |
---|---|
2 AST (abstract syntax tree) nodes for the c3 language. | 2 AST (abstract syntax tree) nodes for the c3 language. |
3 The tree is build by the parser. | 3 The tree is build by the parser. |
4 Then it is checked | 4 Then it is checked |
5 Finally code is generated from it. | 5 Finally code is generated from it. |
6 """ | 6 """ |
7 | |
8 from ppci import SourceLocation | |
9 | 7 |
10 | 8 |
11 class Node: | 9 class Node: |
12 """ Base class of all nodes in a AST """ | 10 """ Base class of all nodes in a AST """ |
13 pass | 11 pass |
40 def add_declaration(self, decl): | 38 def add_declaration(self, decl): |
41 self.declarations.append(decl) | 39 self.declarations.append(decl) |
42 if isinstance(decl, Function): | 40 if isinstance(decl, Function): |
43 decl.package = self | 41 decl.package = self |
44 | 42 |
43 @property | |
44 def Types(self): | |
45 return self.innerScope.Types | |
46 | |
45 def __repr__(self): | 47 def __repr__(self): |
46 return 'MODULE {}'.format(self.name) | 48 return 'MODULE {}'.format(self.name) |
47 | 49 |
48 | 50 |
49 class Type(Node): | 51 class Type(Node): |
93 """ Field of a struct type """ | 95 """ Field of a struct type """ |
94 def __init__(self, name, typ): | 96 def __init__(self, name, typ): |
95 assert type(name) is str | 97 assert type(name) is str |
96 self.name = name | 98 self.name = name |
97 self.typ = typ | 99 self.typ = typ |
100 | |
101 def __repr__(self): | |
102 return 'Member {}'.format(self.name) | |
98 | 103 |
99 | 104 |
100 class StructureType(Type): | 105 class StructureType(Type): |
101 """ Struct type consisting of several named members """ | 106 """ Struct type consisting of several named members """ |
102 def __init__(self, mems): | 107 def __init__(self, mems): |