| ... | ... | @@ -126,7 +126,9 @@ pub const Node = struct { |
| 126 | 126 | CompoundStmt, |
| 127 | 127 | IfStmt, |
| 128 | 128 | StaticAssert, |
| 129 | | FnDef, |
| 129 | Fn, |
| 130 | Typedef, |
| 131 | Var, |
| 130 | 132 | }; |
| 131 | 133 | |
| 132 | 134 | pub const Root = struct { |
| ... | ... | @@ -274,13 +276,85 @@ pub const Node = struct { |
| 274 | 276 | semicolon: TokenIndex, |
| 275 | 277 | }; |
| 276 | 278 | |
| 277 | | pub const FnDef = struct { |
| 278 | | base: Node = Node{ .id = .FnDef }, |
| 279 | pub const Declarator = struct { |
| 280 | pointer: *Pointer, |
| 281 | identifier: ?TokenIndex, |
| 282 | kind: union(enum) { |
| 283 | Simple, |
| 284 | Complex: struct { |
| 285 | lparen: TokenIndex, |
| 286 | inner: *Declarator, |
| 287 | rparen: TokenIndex, |
| 288 | }, |
| 289 | Fn: ParamList, |
| 290 | Array: ArrayList, |
| 291 | }, |
| 292 | |
| 293 | pub const ArrayList = std.SegmentedList(*Array, 2); |
| 294 | pub const ParamList = std.SegmentedList(*Param, 4); |
| 295 | }; |
| 296 | |
| 297 | pub const Array = union(enum) { |
| 298 | Unspecified, |
| 299 | Variable: TokenIndex, |
| 300 | Known: *Expr, |
| 301 | }; |
| 302 | |
| 303 | pub const Pointer = struct { |
| 304 | asterisk: TokenIndex, |
| 305 | qual: TypeQual, |
| 306 | pointer: ?*Pointer, |
| 307 | }; |
| 308 | |
| 309 | pub const Param = struct { |
| 310 | kind: union(enum) { |
| 311 | Variable, |
| 312 | Old: TokenIndex, |
| 313 | Normal: struct { |
| 314 | decl_spec: *DeclSpec, |
| 315 | declarator: *Declarator, |
| 316 | }, |
| 317 | }, |
| 318 | }; |
| 319 | |
| 320 | pub const Fn = struct { |
| 321 | base: Node = Node{ .id = .Fn }, |
| 279 | 322 | decl_spec: DeclSpec, |
| 280 | | declarator: *Node, |
| 323 | declarator: *Declarator, |
| 281 | 324 | old_decls: OldDeclList, |
| 282 | | body: *CompoundStmt, |
| 325 | body: ?*CompoundStmt, |
| 283 | 326 | |
| 284 | 327 | pub const OldDeclList = SegmentedList(*Node, 0); |
| 285 | 328 | }; |
| 329 | |
| 330 | pub const Typedef = struct { |
| 331 | base: Node = Node{ .id = .Typedef }, |
| 332 | decl_spec: DeclSpec, |
| 333 | declarators: DeclaratorList, |
| 334 | |
| 335 | pub const DeclaratorList = std.SegmentedList(*Declarator, 2); |
| 336 | }; |
| 337 | |
| 338 | pub const Var = struct { |
| 339 | base: Node = Node{ .id = .Var }, |
| 340 | decl_spec: DeclSpec, |
| 341 | initializers: Initializers, |
| 342 | |
| 343 | pub const Initializers = std.SegmentedList(*Initialized, 2); |
| 344 | }; |
| 345 | |
| 346 | pub const Initialized = struct { |
| 347 | declarator: *Declarator, |
| 348 | eq: TokenIndex, |
| 349 | init: Initializer, |
| 350 | }; |
| 351 | |
| 352 | pub const Initializer = union(enum) { |
| 353 | list: struct { |
| 354 | initializers: InitializerList, |
| 355 | rbrace: TokenIndex, |
| 356 | }, |
| 357 | expr: *Expr, |
| 358 | pub const InitializerList = std.SegmentedList(*Initializer, 4); |
| 359 | }; |
| 286 | 360 | }; |