From 489378b939222a2b1660eff48f05c7c918f01fe6 Mon Sep 17 00:00:00 2001 From: SuperAuguste Date: Thu, 16 Jul 2020 15:19:08 -0400 Subject: [PATCH] fix comment in references.zig, format --- src/analysis.zig | 182 +++++++++++++++------------------------------ src/references.zig | 79 ++++++++++---------- 2 files changed, 96 insertions(+), 165 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 721bb28..5c1f5cf 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -687,77 +687,65 @@ pub fn resolveTypeOfNodeInternal( else => null, }; }, - // .InfixOp => { - // const infix_op = node.castTag(.InfixOp).?; - // switch (infix_op.op) { - .Period => { - const infix_op = node.cast(ast.Node.SimpleInfixOp).?; - const rhs_str = nodeToString(handle.tree, infix_op.rhs) orelse return null; - // If we are accessing a pointer type, remove one pointerness level :) - const left_type = try resolveFieldAccessLhsType( - store, - arena, - (try resolveTypeOfNodeInternal(store, arena, .{ - .node = infix_op.lhs, - .handle = handle, - }, bound_type_params)) orelse return null, - bound_type_params, - ); + .Period => { + const infix_op = node.cast(ast.Node.SimpleInfixOp).?; + const rhs_str = nodeToString(handle.tree, infix_op.rhs) orelse return null; + // If we are accessing a pointer type, remove one pointerness level :) + const left_type = try resolveFieldAccessLhsType( + store, + arena, + (try resolveTypeOfNodeInternal(store, arena, .{ + .node = infix_op.lhs, + .handle = handle, + }, bound_type_params)) orelse return null, + bound_type_params, + ); - const left_type_node = switch (left_type.type.data) { - .other => |n| n, - else => return null, - }; + const left_type_node = switch (left_type.type.data) { + .other => |n| n, + else => return null, + }; - if (try lookupSymbolContainer( - store, - arena, - .{ .node = left_type_node, .handle = left_type.handle }, - rhs_str, - !left_type.type.is_type_val, - )) |child| { - return try child.resolveType(store, arena, bound_type_params); - } else return null; - }, - .UnwrapOptional => { - const infix_op = node.cast(ast.Node.SimpleInfixOp).?; - const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ - .node = infix_op.lhs, - .handle = handle, - }, bound_type_params)) orelse return null; - return try resolveUnwrapOptionalType(store, arena, left_type, bound_type_params); - }, - .Catch => { - const infix_op = node.cast(ast.Node.SimpleInfixOp).?; - const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ - .node = infix_op.lhs, - .handle = handle, - }, bound_type_params)) orelse return null; - return try resolveUnwrapErrorType(store, arena, left_type, bound_type_params); - }, - .ErrorUnion => return TypeWithHandle.typeVal(node_handle), - // else => return null, - // } - // }, - // .PrefixOp => { - // const prefix_op = node.castTag(.PrefixOp).?; - // switch (prefix_op.op) { - .SliceType, - .ArrayType, - .OptionalType, - .PtrType, - => return TypeWithHandle.typeVal(node_handle), - .Try => { - const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; - const rhs_type = (try resolveTypeOfNodeInternal(store, arena, .{ - .node = prefix_op.rhs, - .handle = handle, - }, bound_type_params)) orelse return null; - return try resolveUnwrapErrorType(store, arena, rhs_type, bound_type_params); - }, - // else => {}, - // } - // }, + if (try lookupSymbolContainer( + store, + arena, + .{ .node = left_type_node, .handle = left_type.handle }, + rhs_str, + !left_type.type.is_type_val, + )) |child| { + return try child.resolveType(store, arena, bound_type_params); + } else return null; + }, + .UnwrapOptional => { + const infix_op = node.cast(ast.Node.SimpleInfixOp).?; + const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ + .node = infix_op.lhs, + .handle = handle, + }, bound_type_params)) orelse return null; + return try resolveUnwrapOptionalType(store, arena, left_type, bound_type_params); + }, + .Catch => { + const infix_op = node.cast(ast.Node.SimpleInfixOp).?; + const left_type = (try resolveTypeOfNodeInternal(store, arena, .{ + .node = infix_op.lhs, + .handle = handle, + }, bound_type_params)) orelse return null; + return try resolveUnwrapErrorType(store, arena, left_type, bound_type_params); + }, + .ErrorUnion => return TypeWithHandle.typeVal(node_handle), + .SliceType, + .ArrayType, + .OptionalType, + .PtrType, + => return TypeWithHandle.typeVal(node_handle), + .Try => { + const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; + const rhs_type = (try resolveTypeOfNodeInternal(store, arena, .{ + .node = prefix_op.rhs, + .handle = handle, + }, bound_type_params)) orelse return null; + return try resolveUnwrapErrorType(store, arena, rhs_type, bound_type_params); + }, .BuiltinCall => { const builtin_call = node.castTag(.BuiltinCall).?; const call_name = handle.tree.tokenSlice(builtin_call.builtin_token); @@ -1349,61 +1337,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, .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, .ContainerDecl => { const decl = child.castTag(.ContainerDecl).?; diff --git a/src/references.zig b/src/references.zig index 870a7d4..555c44a 100644 --- a/src/references.zig +++ b/src/references.zig @@ -214,7 +214,7 @@ fn symbolReferencesInternal( const info = switch (node.tag) { .PtrType => node.castTag(.PtrType).?.ptr_info, .SliceType => node.castTag(.SliceType).?.ptr_info, - else => return + else => return, }; const prefix_op = node.cast(ast.Node.SimplePrefixOp).?; @@ -317,50 +317,47 @@ fn symbolReferencesInternal( const test_decl = node.cast(ast.Node.TestDecl).?; try symbolReferencesInternal(arena, store, .{ .node = test_decl.body_node, .handle = handle }, decl, encoding, context, handler); }, - else => { - // switch (ast.Node.Tag.Type(node.tag)) { - // SimpleInfixOp => { - // switch (node.tag) { - // .Period => { - // try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler); + .Period => { + const infix_op = node.cast(ast.Node.SimpleInfixOp).?; - // const rhs_str = analysis.nodeToString(handle.tree, infix_op.rhs) orelse return; - // var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator); - // const left_type = try analysis.resolveFieldAccessLhsType( - // store, - // arena, - // (try analysis.resolveTypeOfNodeInternal(store, arena, .{ - // .node = infix_op.lhs, - // .handle = handle, - // }, &bound_type_params)) orelse return, - // &bound_type_params, - // ); + try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler); - // const left_type_node = switch (left_type.type.data) { - // .other => |n| n, - // else => return, - // }; + const rhs_str = analysis.nodeToString(handle.tree, infix_op.rhs) orelse return; + var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator); + const left_type = try analysis.resolveFieldAccessLhsType( + store, + arena, + (try analysis.resolveTypeOfNodeInternal(store, arena, .{ + .node = infix_op.lhs, + .handle = handle, + }, &bound_type_params)) orelse return, + &bound_type_params, + ); - // if (try analysis.lookupSymbolContainer( - // store, - // arena, - // .{ .node = left_type_node, .handle = left_type.handle }, - // rhs_str, - // !left_type.type.is_type_val, - // )) |child| { - // if (std.meta.eql(child, decl)) { - // try tokenReference(handle, infix_op.rhs.firstToken(), encoding, context, handler); - // } - // } - // }, - // else => { - // try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler); - // try symbolReferencesInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, encoding, context, handler); - // }, - // } - // } - // } + const left_type_node = switch (left_type.type.data) { + .other => |n| n, + else => return, + }; + + if (try analysis.lookupSymbolContainer( + store, + arena, + .{ .node = left_type_node, .handle = left_type.handle }, + rhs_str, + !left_type.type.is_type_val, + )) |child| { + if (std.meta.eql(child, decl)) { + try tokenReference(handle, infix_op.rhs.firstToken(), encoding, context, handler); + } + } }, + .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 => { + const infix_op = node.cast(ast.Node.SimpleInfixOp).?; + + try symbolReferencesInternal(arena, store, .{ .node = infix_op.lhs, .handle = handle }, decl, encoding, context, handler); + try symbolReferencesInternal(arena, store, .{ .node = infix_op.rhs, .handle = handle }, decl, encoding, context, handler); + }, + else => {}, } }