aboutsummaryrefslogtreecommitdiff
path: root/pycparser/c_ast.py
diff options
context:
space:
mode:
authoreli.bendersky <devnull@localhost>2010-10-30 12:13:23 +0200
committereli.bendersky <devnull@localhost>2010-10-30 12:13:23 +0200
commitf890a86b31bc8095a501044e4b2071ffc993844d (patch)
treedea3ffd833bc6a43f747d3a66865d6ee4a4ea7df /pycparser/c_ast.py
parent98f453755aea35e4c69c665edc558d58dd2eb9f5 (diff)
downloadpycparser-f890a86b31bc8095a501044e4b2071ffc993844d.tar.gz
initial implementation of C99 named initializers and compound literals. The latter still doesn't work because of a shift/reduce conflict
Diffstat (limited to 'pycparser/c_ast.py')
-rw-r--r--pycparser/c_ast.py89
1 files changed, 71 insertions, 18 deletions
diff --git a/pycparser/c_ast.py b/pycparser/c_ast.py
index a3f6405..12d690c 100644
--- a/pycparser/c_ast.py
+++ b/pycparser/c_ast.py
@@ -156,21 +156,25 @@ class Struct(Node):
c.show(buf, offset + 2, attrnames, showcoord)
-class FuncCall(Node):
- def __init__(self, name, args, coord=None):
- self.name = name
- self.args = args
+class For(Node):
+ def __init__(self, init, cond, next, stmt, coord=None):
+ self.init = init
+ self.cond = cond
+ self.next = next
+ self.stmt = stmt
self.coord = coord
def children(self):
nodelist = []
- if self.name is not None: nodelist.append(self.name)
- if self.args is not None: nodelist.append(self.args)
+ if self.init is not None: nodelist.append(self.init)
+ if self.cond is not None: nodelist.append(self.cond)
+ if self.next is not None: nodelist.append(self.next)
+ if self.stmt is not None: nodelist.append(self.stmt)
return tuple(nodelist)
def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
lead = ' ' * offset
- buf.write(lead + 'FuncCall: ')
+ buf.write(lead + 'For: ')
if showcoord:
buf.write(' (at %s)' % self.coord)
@@ -238,6 +242,30 @@ class Union(Node):
c.show(buf, offset + 2, attrnames, showcoord)
+class CompoundLiteral(Node):
+ def __init__(self, type, init, coord=None):
+ self.type = type
+ self.init = init
+ self.coord = coord
+
+ def children(self):
+ nodelist = []
+ if self.type is not None: nodelist.append(self.type)
+ if self.init is not None: nodelist.append(self.init)
+ return tuple(nodelist)
+
+ def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
+ lead = ' ' * offset
+ buf.write(lead + 'CompoundLiteral: ')
+
+ if showcoord:
+ buf.write(' (at %s)' % self.coord)
+ buf.write('\n')
+
+ for c in self.children():
+ c.show(buf, offset + 2, attrnames, showcoord)
+
+
class TernaryOp(Node):
def __init__(self, cond, iftrue, iffalse, coord=None):
self.cond = cond
@@ -397,25 +425,21 @@ class Enumerator(Node):
c.show(buf, offset + 2, attrnames, showcoord)
-class For(Node):
- def __init__(self, init, cond, next, stmt, coord=None):
- self.init = init
- self.cond = cond
- self.next = next
- self.stmt = stmt
+class FuncCall(Node):
+ def __init__(self, name, args, coord=None):
+ self.name = name
+ self.args = args
self.coord = coord
def children(self):
nodelist = []
- if self.init is not None: nodelist.append(self.init)
- if self.cond is not None: nodelist.append(self.cond)
- if self.next is not None: nodelist.append(self.next)
- if self.stmt is not None: nodelist.append(self.stmt)
+ if self.name is not None: nodelist.append(self.name)
+ if self.args is not None: nodelist.append(self.args)
return tuple(nodelist)
def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
lead = ' ' * offset
- buf.write(lead + 'For: ')
+ buf.write(lead + 'FuncCall: ')
if showcoord:
buf.write(' (at %s)' % self.coord)
@@ -1115,6 +1139,35 @@ class While(Node):
c.show(buf, offset + 2, attrnames, showcoord)
+class NamedInitializer(Node):
+ def __init__(self, name, expr, coord=None):
+ self.name = name
+ self.expr = expr
+ self.coord = coord
+
+ def children(self):
+ nodelist = []
+ if self.expr is not None: nodelist.append(self.expr)
+ return tuple(nodelist)
+
+ def show(self, buf=sys.stdout, offset=0, attrnames=False, showcoord=False):
+ lead = ' ' * offset
+ buf.write(lead + 'NamedInitializer: ')
+
+ if attrnames:
+ attrstr = ', '.join('%s=%s' % nv for nv in [("name", repr(self.name))])
+ else:
+ attrstr = ', '.join('%s' % v for v in [self.name])
+ buf.write(attrstr)
+
+ if showcoord:
+ buf.write(' (at %s)' % self.coord)
+ buf.write('\n')
+
+ for c in self.children():
+ c.show(buf, offset + 2, attrnames, showcoord)
+
+
class EnumeratorList(Node):
def __init__(self, enumerators, coord=None):
self.enumerators = enumerators