Fixed for latest zig master build

This commit is contained in:
Alexandros Naskos 2020-07-23 19:06:39 +03:00
parent a1c0f86066
commit b71585da1d
3 changed files with 62 additions and 43 deletions

View File

@ -673,20 +673,34 @@ pub fn resolveTypeOfNodeInternal(
.ErrorSetDecl => {
return TypeWithHandle.typeVal(node_handle);
},
.SuffixOp => {
const suffix_op = node.castTag(.SuffixOp).?;
.Slice => {
const slice = node.castTag(.Slice).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = suffix_op.lhs,
.node = slice.lhs,
.handle = handle,
}, bound_type_params)) orelse return null;
return switch (suffix_op.op) {
return try resolveBracketAccessType(store, arena, left_type, .Range, bound_type_params);
},
.Deref, .UnwrapOptional => {
const suffix = node.cast(ast.Node.SimpleSuffixOp).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = suffix.lhs,
.handle = handle,
}, bound_type_params)) orelse return null;
return switch (node.tag) {
.UnwrapOptional => try resolveUnwrapOptionalType(store, arena, left_type, bound_type_params),
.Deref => try resolveDerefType(store, arena, left_type, bound_type_params),
.ArrayAccess => try resolveBracketAccessType(store, arena, left_type, .Single, bound_type_params),
.Slice => try resolveBracketAccessType(store, arena, left_type, .Range, bound_type_params),
else => null,
else => unreachable,
};
},
.ArrayAccess => {
const arr_acc = node.castTag(.ArrayAccess).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = arr_acc.lhs,
.handle = handle,
}, bound_type_params)) orelse return null;
return try resolveBracketAccessType(store, arena, left_type, .Single, bound_type_params);
},
.Period => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
const rhs_str = nodeToString(handle.tree, infix_op.rhs) orelse return null;
@ -716,7 +730,7 @@ pub fn resolveTypeOfNodeInternal(
return try child.resolveType(store, arena, bound_type_params);
} else return null;
},
.UnwrapOptional => {
.OrElse => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
const left_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = infix_op.lhs,
@ -1337,7 +1351,7 @@ 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, .UnwrapOptional, .AddressOf, .Await, .BitNot, .BoolNot, .OptionalType, .Negation, .NegationWrap, .Resume, .Try, .ArrayType, .ArrayTypeSentinel, .PtrType, .SliceType, .SuffixOp, .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, .ControlFlowExpression, .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

@ -273,22 +273,25 @@ fn symbolReferencesInternal(
try symbolReferencesInternal(arena, store, .{ .node = param, .handle = handle }, decl, encoding, context, handler);
}
},
.SuffixOp => {
const suffix_op = node.cast(ast.Node.SuffixOp).?;
try symbolReferencesInternal(arena, store, .{ .node = suffix_op.lhs, .handle = handle }, decl, encoding, context, handler);
switch (suffix_op.op) {
.ArrayAccess => |acc| try symbolReferencesInternal(arena, store, .{ .node = acc, .handle = handle }, decl, encoding, context, handler),
.Slice => |sl| {
try symbolReferencesInternal(arena, store, .{ .node = sl.start, .handle = handle }, decl, encoding, context, handler);
if (sl.end) |end| {
.Slice => {
const slice = node.castTag(.Slice).?;
try symbolReferencesInternal(arena, store, .{ .node = slice.lhs, .handle = handle }, decl, encoding, context, handler);
try symbolReferencesInternal(arena, store, .{ .node = slice.start, .handle = handle }, decl, encoding, context, handler);
if (slice.end) |end| {
try symbolReferencesInternal(arena, store, .{ .node = end, .handle = handle }, decl, encoding, context, handler);
}
if (sl.sentinel) |sentinel| {
if (slice.sentinel) |sentinel| {
try symbolReferencesInternal(arena, store, .{ .node = sentinel, .handle = handle }, decl, encoding, context, handler);
}
},
else => {},
}
.ArrayAccess => {
const arr_acc = node.castTag(.ArrayAccess).?;
try symbolReferencesInternal(arena, store, .{ .node = arr_acc.lhs, .handle = handle }, decl, encoding, context, handler);
try symbolReferencesInternal(arena, store, .{ .node = arr_acc.index_expr, .handle = handle }, decl, encoding, context, handler);
},
.Deref, .UnwrapOptional => {
const suffix = node.cast(ast.Node.SimpleSuffixOp).?;
try symbolReferencesInternal(arena, store, .{ .node = suffix.lhs, .handle = handle }, decl, encoding, context, handler);
},
.GroupedExpression => {
const grouped = node.cast(ast.Node.GroupedExpression).?;
@ -351,7 +354,7 @@ fn symbolReferencesInternal(
}
}
},
.Add, .AddWrap, .ArrayCat, .ArrayMult, .Assign, .AssignBitAnd, .AssignBitOr, .AssignBitShiftLeft, .AssignBitShiftRight, .AssignBitXor, .AssignDiv, .AssignSub, .AssignSubWrap, .AssignMod, .AssignAdd, .AssignAddWrap, .AssignMul, .AssignMulWrap, .BangEqual, .BitAnd, .BitOr, .BitShiftLeft, .BitShiftRight, .BitXor, .BoolOr, .Div, .EqualEqual, .ErrorUnion, .GreaterOrEqual, .GreaterThan, .LessOrEqual, .LessThan, .MergeErrorSets, .Mod, .Mul, .MulWrap, .Range, .Sub, .SubWrap, .UnwrapOptional => {
.Add, .AddWrap, .ArrayCat, .ArrayMult, .Assign, .AssignBitAnd, .AssignBitOr, .AssignBitShiftLeft, .AssignBitShiftRight, .AssignBitXor, .AssignDiv, .AssignSub, .AssignSubWrap, .AssignMod, .AssignAdd, .AssignAddWrap, .AssignMul, .AssignMulWrap, .BangEqual, .BitAnd, .BitOr, .BitShiftLeft, .BitShiftRight, .BitXor, .BoolOr, .Div, .EqualEqual, .ErrorUnion, .GreaterOrEqual, .GreaterThan, .LessOrEqual, .LessThan, .MergeErrorSets, .Mod, .Mul, .MulWrap, .Range, .Sub, .SubWrap, .OrElse => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler);

View File

@ -541,21 +541,23 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
}
for (call.paramsConst()) |param| try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, param });
},
.SuffixOp => {
const suffix_op = node.cast(ast.Node.SuffixOp).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, suffix_op.lhs });
switch (suffix_op.op) {
.ArrayAccess => |n| {
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, n });
.Slice => {
const slice = node.castTag(.Slice).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.lhs });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.start });
try writeToken(builder, slice.start.lastToken() + 1, .operator);
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.end });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, slice.sentinel });
},
.Slice => |s| {
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, s.start });
try writeToken(builder, s.start.lastToken() + 1, .operator);
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, s.end });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, s.sentinel });
.ArrayAccess => {
const arr_acc = node.castTag(.ArrayAccess).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, arr_acc.lhs });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, arr_acc.index_expr });
},
else => try writeToken(builder, suffix_op.rtoken, .operator),
}
.Deref, .UnwrapOptional => {
const suffix = node.cast(ast.Node.SimpleSuffixOp).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, suffix.lhs });
try writeToken(builder, suffix.rtoken, .operator);
},
.GroupedExpression => {
const grouped_expr = node.cast(ast.Node.GroupedExpression).?;
@ -620,12 +622,12 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, test_decl.name });
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, test_decl.body_node });
},
.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, .UnwrapOptional => {
.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 => {
const infix_op = node.cast(ast.Node.SimpleInfixOp).?;
try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, infix_op.lhs });
if (node.tag != .Period and node.tag != .Catch) {
const token_type: TokenType = switch (node.tag) {
.BoolAnd, .BoolOr, .UnwrapOptional => .keyword,
.BoolAnd, .BoolOr, .OrElse => .keyword,
else => .operator,
};