Fixed for zig master branch

This commit is contained in:
Alexandros Naskos 2020-07-24 10:33:13 +03:00
parent 1c725f85aa
commit bda78e1f76
3 changed files with 112 additions and 29 deletions

View File

@ -299,13 +299,9 @@ fn findReturnStatementInternal(
var result: ?*ast.Node.ControlFlowExpression = null;
var child_idx: usize = 0;
while (base_node.iterate(child_idx)) |child_node| : (child_idx += 1) {
switch (child_node.tag) {
.ControlFlowExpression => blk: {
const cfe = child_node.castTag(.ControlFlowExpression).?;
if (cfe.kind != .Return) break :blk;
if (child_node.castTag(.Return)) |cfe| {
// If we are calling ourselves recursively, ignore this return.
if (cfe.rhs) |rhs| {
if (cfe.getRHS()) |rhs| {
if (rhs.castTag(.Call)) |call_node| {
if (call_node.lhs.tag == .Identifier) {
if (std.mem.eql(u8, getDeclName(tree, call_node.lhs).?, getDeclName(tree, &fn_decl.base).?)) {
@ -319,8 +315,6 @@ fn findReturnStatementInternal(
already_found.* = true;
result = cfe;
continue;
},
else => {},
}
result = findReturnStatementInternal(tree, fn_decl, child_node, already_found);
@ -345,7 +339,7 @@ fn resolveReturnType(
// If this is a type function and it only contains a single return statement that returns
// a container declaration, we will return that declaration.
const ret = findReturnStatement(handle.tree, fn_decl) orelse return null;
if (ret.rhs) |rhs| {
if (ret.getRHS()) |rhs| {
return try resolveTypeOfNodeInternal(store, arena, .{
.node = rhs,
.handle = handle,
@ -1337,7 +1331,96 @@ pub fn documentPositionContext(arena: *std.heap.ArenaAllocator, document: types.
fn addOutlineNodes(allocator: *std.mem.Allocator, tree: *ast.Tree, child: *ast.Node, context: *GetDocumentSymbolsContext) anyerror!void {
switch (child.tag) {
.StringLiteral, .IntegerLiteral, .BuiltinCall, .Call, .Identifier, .Add, .AddWrap, .ArrayCat, .ArrayMult, .Assign, .AssignBitAnd, .AssignBitOr, .AssignBitShiftLeft, .AssignBitShiftRight, .AssignBitXor, .AssignDiv, .AssignSub, .AssignSubWrap, .AssignMod, .AssignAdd, .AssignAddWrap, .AssignMul, .AssignMulWrap, .BangEqual, .BitAnd, .BitOr, .BitShiftLeft, .BitShiftRight, .BitXor, .BoolAnd, .BoolOr, .Div, .EqualEqual, .ErrorUnion, .GreaterOrEqual, .GreaterThan, .LessOrEqual, .LessThan, .MergeErrorSets, .Mod, .Mul, .MulWrap, .Period, .Range, .Sub, .SubWrap, .OrElse, .AddressOf, .Await, .BitNot, .BoolNot, .OptionalType, .Negation, .NegationWrap, .Resume, .Try, .ArrayType, .ArrayTypeSentinel, .PtrType, .SliceType, .Slice, .Deref, .UnwrapOptional, .ArrayAccess, .ControlFlowExpression, .ArrayInitializerDot, .SwitchElse, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload, .StructInitializerDot, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .StructInitializer, .FieldInitializer, .If, .MultilineStringLiteral, .UndefinedLiteral, .AnyType, .Block, .ErrorSetDecl => return,
.StringLiteral,
.IntegerLiteral,
.BuiltinCall,
.Call,
.Identifier,
.Add,
.AddWrap,
.ArrayCat,
.ArrayMult,
.Assign,
.AssignBitAnd,
.AssignBitOr,
.AssignBitShiftLeft,
.AssignBitShiftRight,
.AssignBitXor,
.AssignDiv,
.AssignSub,
.AssignSubWrap,
.AssignMod,
.AssignAdd,
.AssignAddWrap,
.AssignMul,
.AssignMulWrap,
.BangEqual,
.BitAnd,
.BitOr,
.BitShiftLeft,
.BitShiftRight,
.BitXor,
.BoolAnd,
.BoolOr,
.Div,
.EqualEqual,
.ErrorUnion,
.GreaterOrEqual,
.GreaterThan,
.LessOrEqual,
.LessThan,
.MergeErrorSets,
.Mod,
.Mul,
.MulWrap,
.Period,
.Range,
.Sub,
.SubWrap,
.OrElse,
.AddressOf,
.Await,
.BitNot,
.BoolNot,
.OptionalType,
.Negation,
.NegationWrap,
.Resume,
.Try,
.ArrayType,
.ArrayTypeSentinel,
.PtrType,
.SliceType,
.Slice,
.Deref,
.UnwrapOptional,
.ArrayAccess,
.Return,
.Break,
.Continue,
.ArrayInitializerDot,
.SwitchElse,
.SwitchCase,
.For,
.EnumLiteral,
.PointerIndexPayload,
.StructInitializerDot,
.PointerPayload,
.While,
.Switch,
.Else,
.BoolLiteral,
.NullLiteral,
.Defer,
.StructInitializer,
.FieldInitializer,
.If,
.MultilineStringLiteral,
.UndefinedLiteral,
.AnyType,
.Block,
.ErrorSetDecl,
=> return,
.ContainerDecl => {
const decl = child.castTag(.ContainerDecl).?;

View File

@ -296,9 +296,9 @@ fn symbolReferencesInternal(
const grouped = node.cast(ast.Node.GroupedExpression).?;
try symbolReferencesInternal(arena, store, .{ .node = grouped.expr, .handle = handle }, decl, encoding, context, handler);
},
.ControlFlowExpression => {
.Return, .Break, .Continue => {
const cfe = node.cast(ast.Node.ControlFlowExpression).?;
if (cfe.rhs) |rhs| {
if (cfe.getRHS()) |rhs| {
try symbolReferencesInternal(arena, store, .{ .node = rhs, .handle = handle }, decl, encoding, context, handler);
}
},

View File

@ -563,15 +563,15 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
const grouped_expr = node.cast(ast.Node.GroupedExpression).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, grouped_expr.expr });
},
.ControlFlowExpression => {
.Return, .Break, .Continue => {
const cfe = node.cast(ast.Node.ControlFlowExpression).?;
try writeToken(builder, cfe.ltoken, .keyword);
switch (cfe.kind) {
.Break => |label| if (label) |n| try writeToken(builder, n.firstToken(), .label),
.Continue => |label| if (label) |n| try writeToken(builder, n.firstToken(), .label),
switch (node.tag) {
.Break => if (cfe.getLabel()) |n| try writeToken(builder, n, .label),
.Continue => if (cfe.getLabel()) |n| try writeToken(builder, n, .label),
else => {},
}
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, cfe.rhs });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, cfe.getRHS() });
},
.Suspend => {
const suspend_node = node.cast(ast.Node.Suspend).?;