From f356cba704e8e45832ac363b5bf205a63f39257a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 14 Aug 2020 19:49:10 -0700 Subject: [PATCH] stage2: populate some of the astgen switch possibilities Idea here is simply to entice people to contribute astgen code :) --- lib/std/zig/ast.zig | 16 +++++------ src-self-hosted/astgen.zig | 56 +++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 9258fc58d0..f5149e3a82 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -530,15 +530,15 @@ pub const Node = struct { // Misc DocComment, - SwitchCase, - SwitchElse, - Else, - Payload, - PointerPayload, - PointerIndexPayload, + SwitchCase, // TODO make this not a child of AST Node + SwitchElse, // TODO make this not a child of AST Node + Else, // TODO make this not a child of AST Node + Payload, // TODO make this not a child of AST Node + PointerPayload, // TODO make this not a child of AST Node + PointerIndexPayload, // TODO make this not a child of AST Node ContainerField, - ErrorTag, - FieldInitializer, + ErrorTag, // TODO make this not a child of AST Node + FieldInitializer, // TODO make this not a child of AST Node pub fn Type(tag: Tag) type { return switch (tag) { diff --git a/src-self-hosted/astgen.zig b/src-self-hosted/astgen.zig index 6cf2ff184d..4dec87f364 100644 --- a/src-self-hosted/astgen.zig +++ b/src-self-hosted/astgen.zig @@ -47,7 +47,19 @@ pub fn typeExpr(mod: *Module, scope: *Scope, type_node: *ast.Node) InnerError!*z /// Turn Zig AST into untyped ZIR istructions. pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerError!*zir.Inst { switch (node.tag) { + .Root => unreachable, // Top-level declaration. + .Use => unreachable, // Top-level declaration. + .TestDecl => unreachable, // Top-level declaration. + .DocComment => unreachable, // Top-level declaration. .VarDecl => unreachable, // Handled in `blockExpr`. + .SwitchCase => unreachable, // Handled in `switchExpr`. + .SwitchElse => unreachable, // Handled in `switchExpr`. + .Else => unreachable, // Handled explicitly the control flow expression functions. + .Payload => unreachable, // Handled explicitly. + .PointerPayload => unreachable, // Handled explicitly. + .PointerIndexPayload => unreachable, // Handled explicitly. + .ErrorTag => unreachable, // Handled explicitly. + .FieldInitializer => unreachable, // Handled explicitly. .Assign => return rlWrapVoid(mod, scope, rl, node, try assign(mod, scope, node.castTag(.Assign).?)), .AssignBitAnd => return rlWrapVoid(mod, scope, rl, node, try assignOp(mod, scope, node.castTag(.AssignBitAnd).?, .bitand)), @@ -109,7 +121,49 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: *ast.Node) InnerEr .UnwrapOptional => return unwrapOptional(mod, scope, rl, node.castTag(.UnwrapOptional).?), .Block => return rlWrapVoid(mod, scope, rl, node, try blockExpr(mod, scope, node.castTag(.Block).?)), .LabeledBlock => return labeledBlockExpr(mod, scope, rl, node.castTag(.LabeledBlock).?), - else => return mod.failNode(scope, node, "TODO implement astgen.Expr for {}", .{@tagName(node.tag)}), + .Defer => return mod.failNode(scope, node, "TODO implement astgen.expr for .Defer", .{}), + .Catch => return mod.failNode(scope, node, "TODO implement astgen.expr for .Catch", .{}), + .BoolAnd => return mod.failNode(scope, node, "TODO implement astgen.expr for .BoolAnd", .{}), + .BoolOr => return mod.failNode(scope, node, "TODO implement astgen.expr for .BoolOr", .{}), + .ErrorUnion => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorUnion", .{}), + .MergeErrorSets => return mod.failNode(scope, node, "TODO implement astgen.expr for .MergeErrorSets", .{}), + .Range => return mod.failNode(scope, node, "TODO implement astgen.expr for .Range", .{}), + .OrElse => return mod.failNode(scope, node, "TODO implement astgen.expr for .OrElse", .{}), + .AddressOf => return mod.failNode(scope, node, "TODO implement astgen.expr for .AddressOf", .{}), + .Await => return mod.failNode(scope, node, "TODO implement astgen.expr for .Await", .{}), + .BitNot => return mod.failNode(scope, node, "TODO implement astgen.expr for .BitNot", .{}), + .Negation => return mod.failNode(scope, node, "TODO implement astgen.expr for .Negation", .{}), + .NegationWrap => return mod.failNode(scope, node, "TODO implement astgen.expr for .NegationWrap", .{}), + .Resume => return mod.failNode(scope, node, "TODO implement astgen.expr for .Resume", .{}), + .Try => return mod.failNode(scope, node, "TODO implement astgen.expr for .Try", .{}), + .ArrayType => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayType", .{}), + .ArrayTypeSentinel => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayTypeSentinel", .{}), + .PtrType => return mod.failNode(scope, node, "TODO implement astgen.expr for .PtrType", .{}), + .SliceType => return mod.failNode(scope, node, "TODO implement astgen.expr for .SliceType", .{}), + .Slice => return mod.failNode(scope, node, "TODO implement astgen.expr for .Slice", .{}), + .ArrayAccess => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayAccess", .{}), + .ArrayInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializer", .{}), + .ArrayInitializerDot => return mod.failNode(scope, node, "TODO implement astgen.expr for .ArrayInitializerDot", .{}), + .StructInitializer => return mod.failNode(scope, node, "TODO implement astgen.expr for .StructInitializer", .{}), + .StructInitializerDot => return mod.failNode(scope, node, "TODO implement astgen.expr for .StructInitializerDot", .{}), + .Switch => return mod.failNode(scope, node, "TODO implement astgen.expr for .Switch", .{}), + .For => return mod.failNode(scope, node, "TODO implement astgen.expr for .For", .{}), + .Suspend => return mod.failNode(scope, node, "TODO implement astgen.expr for .Suspend", .{}), + .Continue => return mod.failNode(scope, node, "TODO implement astgen.expr for .Continue", .{}), + .Break => return mod.failNode(scope, node, "TODO implement astgen.expr for .Break", .{}), + .AnyType => return mod.failNode(scope, node, "TODO implement astgen.expr for .AnyType", .{}), + .ErrorType => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorType", .{}), + .FnProto => return mod.failNode(scope, node, "TODO implement astgen.expr for .FnProto", .{}), + .AnyFrameType => return mod.failNode(scope, node, "TODO implement astgen.expr for .AnyFrameType", .{}), + .EnumLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .EnumLiteral", .{}), + .MultilineStringLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .MultilineStringLiteral", .{}), + .CharLiteral => return mod.failNode(scope, node, "TODO implement astgen.expr for .CharLiteral", .{}), + .GroupedExpression => return mod.failNode(scope, node, "TODO implement astgen.expr for .GroupedExpression", .{}), + .ErrorSetDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ErrorSetDecl", .{}), + .ContainerDecl => return mod.failNode(scope, node, "TODO implement astgen.expr for .ContainerDecl", .{}), + .Comptime => return mod.failNode(scope, node, "TODO implement astgen.expr for .Comptime", .{}), + .Nosuspend => return mod.failNode(scope, node, "TODO implement astgen.expr for .Nosuspend", .{}), + .ContainerField => return mod.failNode(scope, node, "TODO implement astgen.expr for .ContainerField", .{}), } }