From afcaf96e6e9140e14415d9f058e7dcbfd611de78 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Sun, 12 Jul 2020 18:06:54 +0100 Subject: [PATCH] Replace var with anytype --- src/kernel/log.zig | 20 +++++++++--------- src/kernel/mem.zig | 8 ++++---- src/kernel/panic.zig | 2 +- src/kernel/tty.zig | 4 ++-- src/kernel/vfs.zig | 2 +- test/mock/kernel/log_mock.zig | 10 ++++----- test/mock/kernel/mem_mock.zig | 4 ++-- test/mock/kernel/mock_framework.zig | 32 ++++++++++++++--------------- test/mock/kernel/panic_mock.zig | 2 +- 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/kernel/log.zig b/src/kernel/log.zig index 40bd29d..625b8b0 100644 --- a/src/kernel/log.zig +++ b/src/kernel/log.zig @@ -46,9 +46,9 @@ fn logCallback(context: void, str: []const u8) LoggingError!usize { /// whether it is filtered. /// IN comptime format: []const u8 - The message format. Uses the standard format specification /// options. -/// IN args: var - A struct of the parameters for the format string. +/// IN args: anytype - A struct of the parameters for the format string. /// -pub fn log(comptime level: Level, comptime format: []const u8, args: var) void { +pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void { fmt.format(OutStream{ .context = {} }, "[" ++ @tagName(level) ++ "] " ++ format, args) catch unreachable; } @@ -58,9 +58,9 @@ pub fn log(comptime level: Level, comptime format: []const u8, args: var) void { /// Arguments: /// IN comptime format: []const u8 - The message format. Uses the standard format specification /// options. -/// IN args: var - A struct of the parameters for the format string. +/// IN args: anytype - A struct of the parameters for the format string. /// -pub fn logInfo(comptime format: []const u8, args: var) void { +pub fn logInfo(comptime format: []const u8, args: anytype) void { log(Level.INFO, format, args); } @@ -70,9 +70,9 @@ pub fn logInfo(comptime format: []const u8, args: var) void { /// Arguments: /// IN comptime format: []const u8 - The message format. Uses the standard format specification /// options. -/// IN args: var - A struct of the parameters for the format string. +/// IN args: anytype - A struct of the parameters for the format string. /// -pub fn logDebug(comptime format: []const u8, args: var) void { +pub fn logDebug(comptime format: []const u8, args: anytype) void { log(Level.DEBUG, format, args); } @@ -82,9 +82,9 @@ pub fn logDebug(comptime format: []const u8, args: var) void { /// Arguments: /// IN comptime format: []const u8 - The message format. Uses the standard format specification /// options. -/// IN args: var - A struct of the parameters for the format string. +/// IN args: anytype - A struct of the parameters for the format string. /// -pub fn logWarning(comptime format: []const u8, args: var) void { +pub fn logWarning(comptime format: []const u8, args: anytype) void { log(Level.WARNING, format, args); } @@ -94,9 +94,9 @@ pub fn logWarning(comptime format: []const u8, args: var) void { /// Arguments: /// IN comptime format: []const u8 - The message format. Uses the standard format specification /// options. -/// IN args: var - A struct of the parameters for the format string. +/// IN args: anytype - A struct of the parameters for the format string. /// -pub fn logError(comptime format: []const u8, args: var) void { +pub fn logError(comptime format: []const u8, args: anytype) void { log(Level.ERROR, format, args); } diff --git a/src/kernel/mem.zig b/src/kernel/mem.zig index 98bfd69..57f9099 100644 --- a/src/kernel/mem.zig +++ b/src/kernel/mem.zig @@ -65,12 +65,12 @@ pub var ADDR_OFFSET: usize = undefined; /// Convert a virtual address to its physical counterpart by subtracting the kernel virtual offset from the virtual address. /// /// Arguments: -/// IN virt: var - The virtual address to covert. Either an integer or pointer. +/// IN virt: anytype - The virtual address to covert. Either an integer or pointer. /// /// Return: @TypeOf(virt) /// The physical address. /// -pub fn virtToPhys(virt: var) @TypeOf(virt) { +pub fn virtToPhys(virt: anytype) @TypeOf(virt) { const T = @TypeOf(virt); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(virt) - ADDR_OFFSET), @@ -83,12 +83,12 @@ pub fn virtToPhys(virt: var) @TypeOf(virt) { /// Convert a physical address to its virtual counterpart by adding the kernel virtual offset to the physical address. /// /// Arguments: -/// IN phys: var - The physical address to covert. Either an integer or pointer. +/// IN phys: anytype - The physical address to covert. Either an integer or pointer. /// /// Return: @TypeOf(virt) /// The virtual address. /// -pub fn physToVirt(phys: var) @TypeOf(phys) { +pub fn physToVirt(phys: anytype) @TypeOf(phys) { const T = @TypeOf(phys); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(phys) + ADDR_OFFSET), diff --git a/src/kernel/panic.zig b/src/kernel/panic.zig index 8c61322..84705af 100644 --- a/src/kernel/panic.zig +++ b/src/kernel/panic.zig @@ -105,7 +105,7 @@ fn logTraceAddress(addr: usize) void { log.logError("{x}: {}\n", .{ addr, str }); } -pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn { +pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn { @setCold(true); log.logError("Kernel panic: " ++ format ++ "\n", args); if (trace) |trc| { diff --git a/src/kernel/tty.zig b/src/kernel/tty.zig index 0d54f03..eb6385e 100644 --- a/src/kernel/tty.zig +++ b/src/kernel/tty.zig @@ -47,9 +47,9 @@ fn printCallback(ctx: void, str: []const u8) !usize { /// /// Arguments: /// IN comptime format: []const u8 - The format string to print -/// IN args: var - The arguments to be used in the formatted string +/// IN args: anytype - The arguments to be used in the formatted string /// -pub fn print(comptime format: []const u8, args: var) void { +pub fn print(comptime format: []const u8, args: anytype) void { // Printing can't error because of the scrolling, if it does, we have a big problem fmt.format(OutStream{ .context = {} }, format, args) catch |e| { log.logError("TTY: Error printing. Error: {}\n", .{e}); diff --git a/src/kernel/vfs.zig b/src/kernel/vfs.zig index f15d0e5..e343e34 100644 --- a/src/kernel/vfs.zig +++ b/src/kernel/vfs.zig @@ -417,7 +417,7 @@ const TestFS = struct { self.allocator.destroy(self.fs); } - fn getTreeNode(test_fs: *Self, node: var) Allocator.Error!?*TreeNode { + fn getTreeNode(test_fs: *Self, node: anytype) Allocator.Error!?*TreeNode { switch (@TypeOf(node)) { *const Node, *const FileNode, *const DirNode => {}, else => @compileError("Node is of type " ++ @typeName(@TypeOf(node)) ++ ". Only *const Node, *const FileNode and *const DirNode are supported"), diff --git a/test/mock/kernel/log_mock.zig b/test/mock/kernel/log_mock.zig index 09ce7de..4a4b93f 100644 --- a/test/mock/kernel/log_mock.zig +++ b/test/mock/kernel/log_mock.zig @@ -12,22 +12,22 @@ pub const Level = enum { ERROR, }; -pub fn log(comptime level: Level, comptime format: []const u8, args: var) void { +pub fn log(comptime level: Level, comptime format: []const u8, args: anytype) void { //return mock_framework.performAction("log", void, level, format, args); } -pub fn logInfo(comptime format: []const u8, args: var) void { +pub fn logInfo(comptime format: []const u8, args: anytype) void { //return mock_framework.performAction("logInfo", void, format, args); } -pub fn logDebug(comptime format: []const u8, args: var) void { +pub fn logDebug(comptime format: []const u8, args: anytype) void { //return mock_framework.performAction("logDebug", void, format, args); } -pub fn logWarning(comptime format: []const u8, args: var) void { +pub fn logWarning(comptime format: []const u8, args: anytype) void { //return mock_framework.performAction("logWarning", void, format, args); } -pub fn logError(comptime format: []const u8, args: var) void { +pub fn logError(comptime format: []const u8, args: anytype) void { //return mock_framework.performAction("logError", void, format, args); } diff --git a/test/mock/kernel/mem_mock.zig b/test/mock/kernel/mem_mock.zig index fa00811..cfe7f36 100644 --- a/test/mock/kernel/mem_mock.zig +++ b/test/mock/kernel/mem_mock.zig @@ -31,7 +31,7 @@ pub const MemProfile = struct { // The size of the fixed allocator used before the heap is set up. Set to 1MiB. const FIXED_ALLOC_SIZE = 1024 * 1024; -pub fn virtToPhys(virt: var) @TypeOf(virt) { +pub fn virtToPhys(virt: anytype) @TypeOf(virt) { const T = @TypeOf(virt); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(virt) - KERNEL_ADDR_OFFSET), @@ -40,7 +40,7 @@ pub fn virtToPhys(virt: var) @TypeOf(virt) { }; } -pub fn physToVirt(phys: var) @TypeOf(phys) { +pub fn physToVirt(phys: anytype) @TypeOf(phys) { const T = @TypeOf(phys); return switch (@typeInfo(T)) { .Pointer => @intToPtr(T, @ptrToInt(phys) + KERNEL_ADDR_OFFSET), diff --git a/test/mock/kernel/mock_framework.zig b/test/mock/kernel/mock_framework.zig index 07ad6f6..642b8d7 100644 --- a/test/mock/kernel/mock_framework.zig +++ b/test/mock/kernel/mock_framework.zig @@ -161,12 +161,12 @@ fn Mock() type { /// to have a list of different types. /// /// Arguments: - /// IN arg: var - The data, this can be a function or basic type value. + /// IN arg: anytype - The data, this can be a function or basic type value. /// /// Return: DataElement /// A DataElement with the data wrapped. /// - fn createDataElement(arg: var) DataElement { + fn createDataElement(arg: anytype) DataElement { return switch (@TypeOf(arg)) { bool => DataElement{ .BOOL = arg }, u4 => DataElement{ .U4 = arg }, @@ -306,12 +306,12 @@ fn Mock() type { /// /// Arguments: /// IN RetType: type - The return type of the function. - /// IN params: var - The argument list for the function. + /// IN params: anytype - The argument list for the function. /// /// Return: type /// A function type that represents the return type and its arguments. /// - fn getFunctionType(comptime RetType: type, params: var) type { + fn getFunctionType(comptime RetType: type, params: anytype) type { return switch (params.len) { 0 => fn () RetType, 1 => fn (@TypeOf(params[0])) RetType, @@ -387,10 +387,10 @@ fn Mock() type { /// IN/OUT self: *Self - Self. This is the mocking object to be modified to add /// the test data. /// IN fun_name: []const u8 - The function name to add the test parameters to. - /// IN data: var - The data to add. + /// IN data: anytype - The data to add. /// IN action_type: ActionType - The action type to add. /// - pub fn addAction(self: *Self, comptime fun_name: []const u8, data: var, action_type: ActionType) void { + pub fn addAction(self: *Self, comptime fun_name: []const u8, data: anytype, action_type: ActionType) void { // Add a new mapping if one doesn't exist. if (!self.named_actions.contains(fun_name)) { self.named_actions.put(fun_name, TailQueue(Action).init()) catch unreachable; @@ -422,12 +422,12 @@ fn Mock() type { /// perform a action. /// IN fun_name: []const u8 - The function name to act on. /// IN RetType: type - The return type of the function being mocked. - /// IN params: var - The list of parameters of the mocked function. + /// IN params: anytype - The list of parameters of the mocked function. /// /// Return: RetType /// The return value of the mocked function. This can be void. /// - pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: var) RetType { + pub fn performAction(self: *Self, comptime fun_name: []const u8, comptime RetType: type, params: anytype) RetType { if (self.named_actions.getEntry(fun_name)) |kv_actions_list| { var action_list = kv_actions_list.value; // Peak the first action to test the action type @@ -655,9 +655,9 @@ pub fn freeTest() void { /// IN/OUT self: *Self - Self. This is the mocking object to be modified to add /// the test parameters. /// IN fun_name: []const u8 - The function name to add the test parameters to. -/// IN params: var - The parameters to add. +/// IN params: anytype - The parameters to add. /// -pub fn addTestParams(comptime fun_name: []const u8, params: var) void { +pub fn addTestParams(comptime fun_name: []const u8, params: anytype) void { var mock_obj = getMockObject(); comptime var i = 0; inline while (i < params.len) : (i += 1) { @@ -671,9 +671,9 @@ pub fn addTestParams(comptime fun_name: []const u8, params: var) void { /// /// Arguments: /// IN fun_name: []const u8 - The function name to add the function to. -/// IN function: var - The function to add. +/// IN function: anytype - The function to add. /// -pub fn addConsumeFunction(comptime fun_name: []const u8, function: var) void { +pub fn addConsumeFunction(comptime fun_name: []const u8, function: anytype) void { getMockObject().addAction(fun_name, function, ActionType.ConsumeFunctionCall); } @@ -683,9 +683,9 @@ pub fn addConsumeFunction(comptime fun_name: []const u8, function: var) void { /// /// Arguments: /// IN fun_name: []const u8 - The function name to add the function to. -/// IN function: var - The function to add. +/// IN function: anytype - The function to add. /// -pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void { +pub fn addRepeatFunction(comptime fun_name: []const u8, function: anytype) void { getMockObject().addAction(fun_name, function, ActionType.RepeatFunctionCall); } @@ -695,11 +695,11 @@ pub fn addRepeatFunction(comptime fun_name: []const u8, function: var) void { /// Arguments: /// IN fun_name: []const u8 - The function name to act on. /// IN RetType: type - The return type of the function being mocked. -/// IN params: var - The list of parameters of the mocked function. +/// IN params: anytype - The list of parameters of the mocked function. /// /// Return: RetType /// The return value of the mocked function. This can be void. /// -pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: var) RetType { +pub fn performAction(comptime fun_name: []const u8, comptime RetType: type, params: anytype) RetType { return getMockObject().performAction(fun_name, RetType, params); } diff --git a/test/mock/kernel/panic_mock.zig b/test/mock/kernel/panic_mock.zig index 632ec1f..9f2c110 100644 --- a/test/mock/kernel/panic_mock.zig +++ b/test/mock/kernel/panic_mock.zig @@ -2,7 +2,7 @@ const builtin = @import("builtin"); const std = @import("std"); const MemProfile = @import("mem_mock.zig").MemProfile; -pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: var) noreturn { +pub fn panic(trace: ?*builtin.StackTrace, comptime format: []const u8, args: anytype) noreturn { @setCold(true); std.debug.panic(format, args); }