From 765c82671a733991c46f3d3e14297bc94d6b56c3 Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Fri, 8 Jun 2018 10:41:37 +0200 Subject: Updated to newest pointer syntax --- src/core.zig | 26 +++++++++++++------------- src/extended.zig | 37 +++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/core.zig b/src/core.zig index f2e1fe0..d870e8c 100644 --- a/src/core.zig +++ b/src/core.zig @@ -99,7 +99,7 @@ pub fn Param(comptime Id: type) type { takes_value: bool, names: Names, - pub fn init(id: Id, takes_value: bool, names: &const Names) Self { + pub fn init(id: Id, takes_value: bool, names: *const Names) Self { // Assert, that if the param have no name, then it has to take // a value. debug.assert( @@ -123,10 +123,10 @@ pub fn Arg(comptime Id: type) type { return struct { const Self = this; - param: &const Param(Id), + param: *const Param(Id), value: ?[]const u8, - pub fn init(param: &const Param(Id), value: ?[]const u8) Self { + pub fn init(param: *const Param(Id), value: ?[]const u8) Self { return Self { .param = param, .value = value, @@ -141,9 +141,9 @@ pub fn ArgIterator(comptime E: type) type { const Self = this; const Error = E; - nextFn: fn(iter: &Self) Error!?[]const u8, + nextFn: fn(iter: *Self) Error!?[]const u8, - pub fn next(iter: &Self) Error!?[]const u8 { + pub fn next(iter: *Self) Error!?[]const u8 { return iter.nextFn(iter); } }; @@ -168,7 +168,7 @@ pub const ArgSliceIterator = struct { }; } - fn nextFn(iter: &ArgIterator(Error)) Error!?[]const u8 { + fn nextFn(iter: *ArgIterator(Error)) Error!?[]const u8 { const self = @fieldParentPtr(ArgSliceIterator, "iter", iter); if (self.args.len <= self.index) return null; @@ -187,7 +187,7 @@ pub const OsArgIterator = struct { args: os.ArgIterator, iter: ArgIterator(Error), - pub fn init(allocator: &mem.Allocator) OsArgIterator { + pub fn init(allocator: *mem.Allocator) OsArgIterator { return OsArgIterator { .arena = heap.ArenaAllocator.init(allocator), .args = os.args(), @@ -197,11 +197,11 @@ pub const OsArgIterator = struct { }; } - pub fn deinit(iter: &OsArgIterator) void { + pub fn deinit(iter: *OsArgIterator) void { iter.arena.deinit(); } - fn nextFn(iter: &ArgIterator(Error)) Error!?[]const u8 { + fn nextFn(iter: *ArgIterator(Error)) Error!?[]const u8 { const self = @fieldParentPtr(OsArgIterator, "iter", iter); if (builtin.os == builtin.Os.windows) { return try self.args.next(self.allocator) ?? return null; @@ -229,10 +229,10 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { }; params: []const Param(Id), - iter: &ArgIterator(ArgError), + iter: *ArgIterator(ArgError), state: State, - pub fn init(params: []const Param(Id), iter: &ArgIterator(ArgError)) Self { + pub fn init(params: []const Param(Id), iter: *ArgIterator(ArgError)) Self { var res = Self { .params = params, .iter = iter, @@ -243,7 +243,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { } /// Get the next ::Arg that matches a ::Param. - pub fn next(clap: &Self) !?Arg(Id) { + pub fn next(clap: *Self) !?Arg(Id) { const ArgInfo = struct { const Kind = enum { Long, Short, Bare }; @@ -334,7 +334,7 @@ pub fn Clap(comptime Id: type, comptime ArgError: type) type { } } - fn chainging(clap: &Self, state: &const State.Chaining) !?Arg(Id) { + fn chainging(clap: *Self, state: *const State.Chaining) !?Arg(Id) { const arg = state.arg; const index = state.index; const next_index = index + 1; diff --git a/src/extended.zig b/src/extended.zig index ffcce5b..8fb017f 100644 --- a/src/extended.zig +++ b/src/extended.zig @@ -29,25 +29,25 @@ pub const Command = struct { params: []const Param, Result: type, - default: &const Opaque, + default: *const Opaque, - pub fn init(comptime Result: type, default: &const Result, params: []const Param) Command { + pub fn init(comptime Result: type, default: *const Result, params: []const Param) Command { return Command{ .params = params, .Result = Result, - .default = @ptrCast(&const Opaque, default), + .default = @ptrCast(*const Opaque, default), }; } }; pub const Parser = struct { - const UnsafeFunction = &const void; + const UnsafeFunction = *const void; FieldType: type, Errors: type, func: UnsafeFunction, - pub fn init(comptime FieldType: type, comptime Errors: type, func: parseFunc(FieldType, Errors)) Parser { + pub fn init(comptime FieldType: type, comptime Errors: type, func: ParseFunc(FieldType, Errors)) Parser { return Parser { .FieldType = FieldType, .Errors = Errors, @@ -55,20 +55,17 @@ pub const Parser = struct { }; } - fn parse(comptime parser: Parser, field_ptr: TakePtr(parser.FieldType), arg: []const u8) parser.Errors!void { - return @ptrCast(parseFunc(parser.FieldType, parser.Errors), parser.func)(field_ptr, arg); + fn parse(comptime parser: Parser, field_ptr: *parser.FieldType, arg: []const u8) parser.Errors!void { + return @ptrCast(ParseFunc(parser.FieldType, parser.Errors), parser.func)(field_ptr, arg); } - // TODO: This is a workaround, since we don't have pointer reform yet. - fn TakePtr(comptime T: type) type { return &T; } - - fn parseFunc(comptime FieldType: type, comptime Errors: type) type { - return fn(&FieldType, []const u8) Errors!void; + fn ParseFunc(comptime FieldType: type, comptime Errors: type) type { + return fn(*FieldType, []const u8) Errors!void; } pub fn int(comptime Int: type, comptime radix: u8) Parser { const func = struct { - fn i(field_ptr: &Int, arg: []const u8) !void { + fn i(field_ptr: *Int, arg: []const u8) !void { field_ptr.* = try fmt.parseInt(Int, arg, radix); } }.i; @@ -83,7 +80,7 @@ pub const Parser = struct { []const u8, error{}, struct { - fn s(field_ptr: &[]const u8, arg: []const u8) (error{}!void) { + fn s(field_ptr: *[]const u8, arg: []const u8) (error{}!void) { field_ptr.* = arg; } }.s @@ -98,23 +95,23 @@ pub fn Clap(comptime Result: type) type { params: []const Param, pub fn parse( - comptime clap: &const Self, + comptime clap: *const Self, comptime Error: type, - iter: &core.ArgIterator(Error), + iter: *core.ArgIterator(Error), ) !Result { // We initialize the core.Clap without any params, and fill them out in parseHelper. var c = core.Clap(usize, Error).init([]core.Param(usize){}, iter); const top_level_command = comptime Command.init(Result, &clap.default, clap.params); - return try parseHelper(top_level_command, Error, &c); + return try parseHelper(&top_level_command, Error, &c); } fn parseHelper( - comptime command: &const Command, + comptime command: *const Command, comptime Error: type, - clap: &core.Clap(usize, Error), + clap: *core.Clap(usize, Error), ) !command.Result { - var result = @ptrCast(&const command.Result, command.default).*; + var result = @ptrCast(*const command.Result, command.default).*; var handled = comptime blk: { var res: [command.params.len]bool = undefined; -- cgit v1.2.3