@@ -68,9 +68,19 @@ class Cast(Node):
68
68
69
69
70
70
@dataclass
71
- class Type (Node ):
71
+ class PointerType (Node ):
72
+ # *type; **type is represented as PointerType(PointerType(type))
73
+ type : Node
74
+
75
+
76
+ @dataclass
77
+ class NumericType (Node ):
78
+ number_type : list [Token ] # int, register unsigned long, char, float, etc.
79
+
80
+
81
+ @dataclass
82
+ class NamedType (Node ):
72
83
name : Token
73
- stars : int
74
84
75
85
76
86
@dataclass
@@ -251,14 +261,26 @@ def cast(self):
251
261
252
262
@contextual
253
263
def type (self ):
254
- token = self .peek ()
255
- if token and token .kind in (lx .INT , lx .CHAR , lx .FLOAT , lx .DOUBLE , lx .IDENTIFIER ):
256
- type = self .next ()
257
- assert type
258
- stars = 0
259
- while self .expect (lx .TIMES ):
260
- stars += 1
261
- return Type (type , stars )
264
+ if not (type := self .type_name ()):
265
+ return None
266
+ while self .expect (lx .TIMES ):
267
+ type = PointerType (type )
268
+ # TODO: [] and ()
269
+ return type
270
+
271
+ @contextual
272
+ def type_name (self ):
273
+ if not (token := self .peek ()):
274
+ return None
275
+ # TODO: unsigned, short, long
276
+ # TODO: const, volatile, extern, register, etc.
277
+ if token .kind in (lx .INT , lx .CHAR , lx .FLOAT , lx .DOUBLE ):
278
+ self .next ()
279
+ return NumericType ([token ])
280
+ if token .kind == lx .IDENTIFIER :
281
+ # TODO: Check the list of known typedefs
282
+ self .next ()
283
+ return NamedType (token )
262
284
263
285
@contextual
264
286
def term (self ) -> Node | None :
0 commit comments