8000 Begin better treatment of types · python/cpython@3c9a567 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c9a567

Browse files
committed
Begin better treatment of types
1 parent 96832de commit 3c9a567

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

Tools/cases_generator/eparser.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,19 @@ class Cast(Node):
6868

6969

7070
@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):
7283
name: Token
73-
stars: int
7484

7585

7686
@dataclass
@@ -251,14 +261,26 @@ def cast(self):
251261

252262
@contextual
253263
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)
262284

263285
@contextual
264286
def term(self) -> Node | None:

0 commit comments

Comments
 (0)
0