| author | |
| committer | |
| log | 77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4 |
| tree | 207f75d690aa32ba054c0a4a78ad05ad1ca9902e |
| parent | ec1b6f66737f8c3cbc0420715c2c502c7e710081 |
| signature |
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.
closes #102333 files changed, 187 insertions(+), 189 deletions(-)
build.zig+3-3| ... | ... | @@ -102,11 +102,11 @@ pub fn build(b: *Builder) !void { |
| 102 | 102 | |
| 103 | 103 | b.default_step.dependOn(&exe.step); |
| 104 | 104 | |
| 105 | const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") ?? false; | |
| 105 | const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false; | |
| 106 | 106 | if (!skip_self_hosted) { |
| 107 | 107 | test_step.dependOn(&exe.step); |
| 108 | 108 | } |
| 109 | const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") ?? false; | |
| 109 | const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") orelse false; | |
| 110 | 110 | exe.setVerboseLink(verbose_link_exe); |
| 111 | 111 | |
| 112 | 112 | b.installArtifact(exe); |
| ... | ... | @@ -114,7 +114,7 @@ pub fn build(b: *Builder) !void { |
| 114 | 114 | installCHeaders(b, c_header_files); |
| 115 | 115 | |
| 116 | 116 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 117 | const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false; | |
| 117 | const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") orelse false; | |
| 118 | 118 | |
| 119 | 119 | test_step.dependOn(docs_step); |
| 120 | 120 |
doc/docgen.zig+3-3| ... | ... | @@ -25,13 +25,13 @@ pub fn main() !void { |
| 25 | 25 | |
| 26 | 26 | if (!args_it.skip()) @panic("expected self arg"); |
| 27 | 27 | |
| 28 | const zig_exe = try (args_it.next(allocator) ?? @panic("expected zig exe arg")); | |
| 28 | const zig_exe = try (args_it.next(allocator) orelse @panic("expected zig exe arg")); | |
| 29 | 29 | defer allocator.free(zig_exe); |
| 30 | 30 | |
| 31 | const in_file_name = try (args_it.next(allocator) ?? @panic("expected input arg")); | |
| 31 | const in_file_name = try (args_it.next(allocator) orelse @panic("expected input arg")); | |
| 32 | 32 | defer allocator.free(in_file_name); |
| 33 | 33 | |
| 34 | const out_file_name = try (args_it.next(allocator) ?? @panic("expected output arg")); | |
| 34 | const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg")); | |
| 35 | 35 | defer allocator.free(out_file_name); |
| 36 | 36 | |
| 37 | 37 | var in_file = try os.File.openRead(allocator, in_file_name); |
doc/langref.html.in+8-8| ... | ... | @@ -985,7 +985,7 @@ a ^= b</code></pre></td> |
| 985 | 985 | </td> |
| 986 | 986 | </tr> |
| 987 | 987 | <tr> |
| 988 | <td><pre><code class="zig">a ?? b</code></pre></td> | |
| 988 | <td><pre><code class="zig">a orelse b</code></pre></td> | |
| 989 | 989 | <td> |
| 990 | 990 | <ul> |
| 991 | 991 | <li>{#link|Optionals#}</li> |
| ... | ... | @@ -998,7 +998,7 @@ a ^= b</code></pre></td> |
| 998 | 998 | </td> |
| 999 | 999 | <td> |
| 1000 | 1000 | <pre><code class="zig">const value: ?u32 = null; |
| 1001 | const unwrapped = value ?? 1234; | |
| 1001 | const unwrapped = value orelse 1234; | |
| 1002 | 1002 | unwrapped == 1234</code></pre> |
| 1003 | 1003 | </td> |
| 1004 | 1004 | </tr> |
| ... | ... | @@ -1011,7 +1011,7 @@ unwrapped == 1234</code></pre> |
| 1011 | 1011 | </td> |
| 1012 | 1012 | <td> |
| 1013 | 1013 | Equivalent to: |
| 1014 | <pre><code class="zig">a ?? unreachable</code></pre> | |
| 1014 | <pre><code class="zig">a orelse unreachable</code></pre> | |
| 1015 | 1015 | </td> |
| 1016 | 1016 | <td> |
| 1017 | 1017 | <pre><code class="zig">const value: ?u32 = 5678; |
| ... | ... | @@ -1278,7 +1278,7 @@ x{} x.* x.? |
| 1278 | 1278 | == != &lt; &gt; &lt;= &gt;= |
| 1279 | 1279 | and |
| 1280 | 1280 | or |
| 1281 | ?? catch | |
| 1281 | orelse catch | |
| 1282 | 1282 | = *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre> |
| 1283 | 1283 | {#header_close#} |
| 1284 | 1284 | {#header_close#} |
| ... | ... | @@ -3062,7 +3062,7 @@ fn createFoo(param: i32) !Foo { |
| 3062 | 3062 | // but we want to return it if the function succeeds. |
| 3063 | 3063 | errdefer deallocateFoo(foo); |
| 3064 | 3064 | |
| 3065 | const tmp_buf = allocateTmpBuffer() ?? return error.OutOfMemory; | |
| 3065 | const tmp_buf = allocateTmpBuffer() orelse return error.OutOfMemory; | |
| 3066 | 3066 | // tmp_buf is truly a temporary resource, and we for sure want to clean it up |
| 3067 | 3067 | // before this block leaves scope |
| 3068 | 3068 | defer deallocateTmpBuffer(tmp_buf); |
| ... | ... | @@ -3219,13 +3219,13 @@ struct Foo *do_a_thing(void) { |
| 3219 | 3219 | extern fn malloc(size: size_t) ?*u8; |
| 3220 | 3220 | |
| 3221 | 3221 | fn doAThing() ?*Foo { |
| 3222 | const ptr = malloc(1234) ?? return null; | |
| 3222 | const ptr = malloc(1234) orelse return null; | |
| 3223 | 3223 | // ... |
| 3224 | 3224 | } |
| 3225 | 3225 | {#code_end#} |
| 3226 | 3226 | <p> |
| 3227 | 3227 | Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr" |
| 3228 | is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator | |
| 3228 | is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>orelse</code> keyword | |
| 3229 | 3229 | unwrapped the optional type and therefore <code>ptr</code> is guaranteed to be non-null everywhere |
| 3230 | 3230 | it is used in the function. |
| 3231 | 3231 | </p> |
| ... | ... | @@ -5941,7 +5941,7 @@ AsmClobbers= ":" list(String, ",") |
| 5941 | 5941 | |
| 5942 | 5942 | UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression |
| 5943 | 5943 | |
| 5944 | UnwrapOptional = "??" Expression | |
| 5944 | UnwrapOptional = "orelse" Expression | |
| 5945 | 5945 | |
| 5946 | 5946 | UnwrapError = "catch" option("|" Symbol "|") Expression |
| 5947 | 5947 |
src-self-hosted/main.zig+7-7| ... | ... | @@ -212,7 +212,7 @@ fn cmdBuild(allocator: *Allocator, args: []const []const u8) !void { |
| 212 | 212 | const build_runner_path = try os.path.join(allocator, special_dir, "build_runner.zig"); |
| 213 | 213 | defer allocator.free(build_runner_path); |
| 214 | 214 | |
| 215 | const build_file = flags.single("build-file") ?? "build.zig"; | |
| 215 | const build_file = flags.single("build-file") orelse "build.zig"; | |
| 216 | 216 | const build_file_abs = try os.path.resolve(allocator, ".", build_file); |
| 217 | 217 | defer allocator.free(build_file_abs); |
| 218 | 218 | |
| ... | ... | @@ -516,7 +516,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo |
| 516 | 516 | |
| 517 | 517 | const basename = os.path.basename(in_file.?); |
| 518 | 518 | var it = mem.split(basename, "."); |
| 519 | const root_name = it.next() ?? { | |
| 519 | const root_name = it.next() orelse { | |
| 520 | 520 | try stderr.write("file name cannot be empty\n"); |
| 521 | 521 | os.exit(1); |
| 522 | 522 | }; |
| ... | ... | @@ -535,7 +535,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo |
| 535 | 535 | |
| 536 | 536 | const zig_root_source_file = in_file; |
| 537 | 537 | |
| 538 | const full_cache_dir = os.path.resolve(allocator, ".", flags.single("cache-dir") ?? "zig-cache"[0..]) catch { | |
| 538 | const full_cache_dir = os.path.resolve(allocator, ".", flags.single("cache-dir") orelse "zig-cache"[0..]) catch { | |
| 539 | 539 | os.exit(1); |
| 540 | 540 | }; |
| 541 | 541 | defer allocator.free(full_cache_dir); |
| ... | ... | @@ -555,9 +555,9 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo |
| 555 | 555 | ); |
| 556 | 556 | defer module.destroy(); |
| 557 | 557 | |
| 558 | module.version_major = try std.fmt.parseUnsigned(u32, flags.single("ver-major") ?? "0", 10); | |
| 559 | module.version_minor = try std.fmt.parseUnsigned(u32, flags.single("ver-minor") ?? "0", 10); | |
| 560 | module.version_patch = try std.fmt.parseUnsigned(u32, flags.single("ver-patch") ?? "0", 10); | |
| 558 | module.version_major = try std.fmt.parseUnsigned(u32, flags.single("ver-major") orelse "0", 10); | |
| 559 | module.version_minor = try std.fmt.parseUnsigned(u32, flags.single("ver-minor") orelse "0", 10); | |
| 560 | module.version_patch = try std.fmt.parseUnsigned(u32, flags.single("ver-patch") orelse "0", 10); | |
| 561 | 561 | |
| 562 | 562 | module.is_test = false; |
| 563 | 563 | |
| ... | ... | @@ -652,7 +652,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | try module.build(); |
| 655 | try module.link(flags.single("out-file") ?? null); | |
| 655 | try module.link(flags.single("out-file") orelse null); | |
| 656 | 656 | |
| 657 | 657 | if (flags.present("print-timing-info")) { |
| 658 | 658 | // codegen_print_timing_info(g, stderr); |
src-self-hosted/module.zig+4-4| ... | ... | @@ -130,13 +130,13 @@ pub const Module = struct { |
| 130 | 130 | var name_buffer = try Buffer.init(allocator, name); |
| 131 | 131 | errdefer name_buffer.deinit(); |
| 132 | 132 | |
| 133 | const context = c.LLVMContextCreate() ?? return error.OutOfMemory; | |
| 133 | const context = c.LLVMContextCreate() orelse return error.OutOfMemory; | |
| 134 | 134 | errdefer c.LLVMContextDispose(context); |
| 135 | 135 | |
| 136 | const module = c.LLVMModuleCreateWithNameInContext(name_buffer.ptr(), context) ?? return error.OutOfMemory; | |
| 136 | const module = c.LLVMModuleCreateWithNameInContext(name_buffer.ptr(), context) orelse return error.OutOfMemory; | |
| 137 | 137 | errdefer c.LLVMDisposeModule(module); |
| 138 | 138 | |
| 139 | const builder = c.LLVMCreateBuilderInContext(context) ?? return error.OutOfMemory; | |
| 139 | const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory; | |
| 140 | 140 | errdefer c.LLVMDisposeBuilder(builder); |
| 141 | 141 | |
| 142 | 142 | const module_ptr = try allocator.create(Module); |
| ... | ... | @@ -223,7 +223,7 @@ pub const Module = struct { |
| 223 | 223 | c.ZigLLVMParseCommandLineOptions(self.llvm_argv.len + 1, c_compatible_args.ptr); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); | |
| 226 | const root_src_path = self.root_src_path orelse @panic("TODO handle null root src path"); | |
| 227 | 227 | const root_src_real_path = os.path.real(self.allocator, root_src_path) catch |err| { |
| 228 | 228 | try printError("unable to get real path '{}': {}", root_src_path, err); |
| 229 | 229 | return err; |
src/all_types.hpp+6-1| ... | ... | @@ -387,6 +387,7 @@ enum NodeType { |
| 387 | 387 | NodeTypeSliceExpr, |
| 388 | 388 | NodeTypeFieldAccessExpr, |
| 389 | 389 | NodeTypePtrDeref, |
| 390 | NodeTypeUnwrapOptional, | |
| 390 | 391 | NodeTypeUse, |
| 391 | 392 | NodeTypeBoolLiteral, |
| 392 | 393 | NodeTypeNullLiteral, |
| ... | ... | @@ -575,6 +576,10 @@ struct AstNodeCatchExpr { |
| 575 | 576 | AstNode *op2; |
| 576 | 577 | }; |
| 577 | 578 | |
| 579 | struct AstNodeUnwrapOptional { | |
| 580 | AstNode *expr; | |
| 581 | }; | |
| 582 | ||
| 578 | 583 | enum CastOp { |
| 579 | 584 | CastOpNoCast, // signifies the function call expression is not a cast |
| 580 | 585 | CastOpNoop, // fn call expr is a cast, but does nothing |
| ... | ... | @@ -624,7 +629,6 @@ enum PrefixOp { |
| 624 | 629 | PrefixOpNegation, |
| 625 | 630 | PrefixOpNegationWrap, |
| 626 | 631 | PrefixOpOptional, |
| 627 | PrefixOpUnwrapOptional, | |
| 628 | 632 | PrefixOpAddrOf, |
| 629 | 633 | }; |
| 630 | 634 | |
| ... | ... | @@ -909,6 +913,7 @@ struct AstNode { |
| 909 | 913 | AstNodeTestDecl test_decl; |
| 910 | 914 | AstNodeBinOpExpr bin_op_expr; |
| 911 | 915 | AstNodeCatchExpr unwrap_err_expr; |
| 916 | AstNodeUnwrapOptional unwrap_optional; | |
| 912 | 917 | AstNodePrefixOpExpr prefix_op_expr; |
| 913 | 918 | AstNodePointerType pointer_type; |
| 914 | 919 | AstNodeFnCallExpr fn_call_expr; |
src/analyze.cpp+1| ... | ... | @@ -3308,6 +3308,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 3308 | 3308 | case NodeTypeAsmExpr: |
| 3309 | 3309 | case NodeTypeFieldAccessExpr: |
| 3310 | 3310 | case NodeTypePtrDeref: |
| 3311 | case NodeTypeUnwrapOptional: | |
| 3311 | 3312 | case NodeTypeStructField: |
| 3312 | 3313 | case NodeTypeContainerInitExpr: |
| 3313 | 3314 | case NodeTypeStructValueField: |
src/ast_render.cpp+10-2| ... | ... | @@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) { |
| 50 | 50 | case BinOpTypeAssignBitXor: return "^="; |
| 51 | 51 | case BinOpTypeAssignBitOr: return "|="; |
| 52 | 52 | case BinOpTypeAssignMergeErrorSets: return "||="; |
| 53 | case BinOpTypeUnwrapOptional: return "??"; | |
| 53 | case BinOpTypeUnwrapOptional: return "orelse"; | |
| 54 | 54 | case BinOpTypeArrayCat: return "++"; |
| 55 | 55 | case BinOpTypeArrayMult: return "**"; |
| 56 | 56 | case BinOpTypeErrorUnion: return "!"; |
| ... | ... | @@ -67,7 +67,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) { |
| 67 | 67 | case PrefixOpBoolNot: return "!"; |
| 68 | 68 | case PrefixOpBinNot: return "~"; |
| 69 | 69 | case PrefixOpOptional: return "?"; |
| 70 | case PrefixOpUnwrapOptional: return "??"; | |
| 71 | 70 | case PrefixOpAddrOf: return "&"; |
| 72 | 71 | } |
| 73 | 72 | zig_unreachable(); |
| ... | ... | @@ -222,6 +221,8 @@ static const char *node_type_str(NodeType node_type) { |
| 222 | 221 | return "FieldAccessExpr"; |
| 223 | 222 | case NodeTypePtrDeref: |
| 224 | 223 | return "PtrDerefExpr"; |
| 224 | case NodeTypeUnwrapOptional: | |
| 225 | return "UnwrapOptional"; | |
| 225 | 226 | case NodeTypeContainerDecl: |
| 226 | 227 | return "ContainerDecl"; |
| 227 | 228 | case NodeTypeStructField: |
| ... | ... | @@ -711,6 +712,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 711 | 712 | fprintf(ar->f, ".*"); |
| 712 | 713 | break; |
| 713 | 714 | } |
| 715 | case NodeTypeUnwrapOptional: | |
| 716 | { | |
| 717 | AstNode *lhs = node->data.unwrap_optional.expr; | |
| 718 | render_node_ungrouped(ar, lhs); | |
| 719 | fprintf(ar->f, ".?"); | |
| 720 | break; | |
| 721 | } | |
| 714 | 722 | case NodeTypeUndefinedLiteral: |
| 715 | 723 | fprintf(ar->f, "undefined"); |
| 716 | 724 | break; |
src/ir.cpp+13-18| ... | ... | @@ -4661,21 +4661,6 @@ static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode |
| 4661 | 4661 | return ir_build_load_ptr(irb, scope, source_node, payload_ptr); |
| 4662 | 4662 | } |
| 4663 | 4663 | |
| 4664 | static IrInstruction *ir_gen_maybe_assert_ok(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { | |
| 4665 | assert(node->type == NodeTypePrefixOpExpr); | |
| 4666 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; | |
| 4667 | ||
| 4668 | IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR); | |
| 4669 | if (maybe_ptr == irb->codegen->invalid_instruction) | |
| 4670 | return irb->codegen->invalid_instruction; | |
| 4671 | ||
| 4672 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true); | |
| 4673 | if (lval.is_ptr) | |
| 4674 | return unwrapped_ptr; | |
| 4675 | ||
| 4676 | return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); | |
| 4677 | } | |
| 4678 | ||
| 4679 | 4664 | static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4680 | 4665 | assert(node->type == NodeTypePrefixOpExpr); |
| 4681 | 4666 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| ... | ... | @@ -4705,8 +4690,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod |
| 4705 | 4690 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval); |
| 4706 | 4691 | case PrefixOpOptional: |
| 4707 | 4692 | return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval); |
| 4708 | case PrefixOpUnwrapOptional: | |
| 4709 | return ir_gen_maybe_assert_ok(irb, scope, node, lval); | |
| 4710 | 4693 | case PrefixOpAddrOf: { |
| 4711 | 4694 | AstNode *expr_node = node->data.prefix_op_expr.primary_expr; |
| 4712 | 4695 | return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval); |
| ... | ... | @@ -6541,7 +6524,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 6541 | 6524 | return ir_build_load_ptr(irb, scope, node, ptr_instruction); |
| 6542 | 6525 | } |
| 6543 | 6526 | case NodeTypePtrDeref: { |
| 6544 | assert(node->type == NodeTypePtrDeref); | |
| 6545 | 6527 | AstNode *expr_node = node->data.ptr_deref_expr.target; |
| 6546 | 6528 | IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval); |
| 6547 | 6529 | if (value == irb->codegen->invalid_instruction) |
| ... | ... | @@ -6549,6 +6531,19 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 6549 | 6531 | |
| 6550 | 6532 | return ir_build_un_op(irb, scope, node, IrUnOpDereference, value); |
| 6551 | 6533 | } |
| 6534 | case NodeTypeUnwrapOptional: { | |
| 6535 | AstNode *expr_node = node->data.unwrap_optional.expr; | |
| 6536 | ||
| 6537 | IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR); | |
| 6538 | if (maybe_ptr == irb->codegen->invalid_instruction) | |
| 6539 | return irb->codegen->invalid_instruction; | |
| 6540 | ||
| 6541 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true); | |
| 6542 | if (lval.is_ptr) | |
| 6543 | return unwrapped_ptr; | |
| 6544 | ||
| 6545 | return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); | |
| 6546 | } | |
| 6552 | 6547 | case NodeTypeThisLiteral: |
| 6553 | 6548 | return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval); |
| 6554 | 6549 | case NodeTypeBoolLiteral: |
src/parser.cpp+7-6| ... | ... | @@ -1151,9 +1151,8 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, |
| 1151 | 1151 | } else if (token->id == TokenIdQuestion) { |
| 1152 | 1152 | *token_index += 1; |
| 1153 | 1153 | |
| 1154 | AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, first_token); | |
| 1155 | node->data.prefix_op_expr.prefix_op = PrefixOpUnwrapOptional; | |
| 1156 | node->data.prefix_op_expr.primary_expr = primary_expr; | |
| 1154 | AstNode *node = ast_create_node(pc, NodeTypeUnwrapOptional, first_token); | |
| 1155 | node->data.unwrap_optional.expr = primary_expr; | |
| 1157 | 1156 | |
| 1158 | 1157 | primary_expr = node; |
| 1159 | 1158 | } else { |
| ... | ... | @@ -1173,7 +1172,6 @@ static PrefixOp tok_to_prefix_op(Token *token) { |
| 1173 | 1172 | case TokenIdMinusPercent: return PrefixOpNegationWrap; |
| 1174 | 1173 | case TokenIdTilde: return PrefixOpBinNot; |
| 1175 | 1174 | case TokenIdQuestion: return PrefixOpOptional; |
| 1176 | case TokenIdDoubleQuestion: return PrefixOpUnwrapOptional; | |
| 1177 | 1175 | case TokenIdAmpersand: return PrefixOpAddrOf; |
| 1178 | 1176 | default: return PrefixOpInvalid; |
| 1179 | 1177 | } |
| ... | ... | @@ -2312,7 +2310,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma |
| 2312 | 2310 | |
| 2313 | 2311 | /* |
| 2314 | 2312 | UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression |
| 2315 | UnwrapOptional : "??" BoolOrExpression | |
| 2313 | UnwrapOptional = "orelse" Expression | |
| 2316 | 2314 | UnwrapError = "catch" option("|" Symbol "|") Expression |
| 2317 | 2315 | */ |
| 2318 | 2316 | static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| ... | ... | @@ -2322,7 +2320,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo |
| 2322 | 2320 | |
| 2323 | 2321 | Token *token = &pc->tokens->at(*token_index); |
| 2324 | 2322 | |
| 2325 | if (token->id == TokenIdDoubleQuestion) { | |
| 2323 | if (token->id == TokenIdKeywordOrElse) { | |
| 2326 | 2324 | *token_index += 1; |
| 2327 | 2325 | |
| 2328 | 2326 | AstNode *rhs = ast_parse_expression(pc, token_index, true); |
| ... | ... | @@ -3035,6 +3033,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 3035 | 3033 | case NodeTypePtrDeref: |
| 3036 | 3034 | visit_field(&node->data.ptr_deref_expr.target, visit, context); |
| 3037 | 3035 | break; |
| 3036 | case NodeTypeUnwrapOptional: | |
| 3037 | visit_field(&node->data.unwrap_optional.expr, visit, context); | |
| 3038 | break; | |
| 3038 | 3039 | case NodeTypeUse: |
| 3039 | 3040 | visit_field(&node->data.use.expr, visit, context); |
| 3040 | 3041 | break; |
src/tokenizer.cpp+6-21| ... | ... | @@ -134,6 +134,7 @@ static const struct ZigKeyword zig_keywords[] = { |
| 134 | 134 | {"noalias", TokenIdKeywordNoAlias}, |
| 135 | 135 | {"null", TokenIdKeywordNull}, |
| 136 | 136 | {"or", TokenIdKeywordOr}, |
| 137 | {"orelse", TokenIdKeywordOrElse}, | |
| 137 | 138 | {"packed", TokenIdKeywordPacked}, |
| 138 | 139 | {"promise", TokenIdKeywordPromise}, |
| 139 | 140 | {"pub", TokenIdKeywordPub}, |
| ... | ... | @@ -215,7 +216,6 @@ enum TokenizeState { |
| 215 | 216 | TokenizeStateSawGreaterThanGreaterThan, |
| 216 | 217 | TokenizeStateSawDot, |
| 217 | 218 | TokenizeStateSawDotDot, |
| 218 | TokenizeStateSawQuestionMark, | |
| 219 | 219 | TokenizeStateSawAtSign, |
| 220 | 220 | TokenizeStateCharCode, |
| 221 | 221 | TokenizeStateError, |
| ... | ... | @@ -532,6 +532,10 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 532 | 532 | begin_token(&t, TokenIdComma); |
| 533 | 533 | end_token(&t); |
| 534 | 534 | break; |
| 535 | case '?': | |
| 536 | begin_token(&t, TokenIdQuestion); | |
| 537 | end_token(&t); | |
| 538 | break; | |
| 535 | 539 | case '{': |
| 536 | 540 | begin_token(&t, TokenIdLBrace); |
| 537 | 541 | end_token(&t); |
| ... | ... | @@ -624,28 +628,10 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 624 | 628 | begin_token(&t, TokenIdDot); |
| 625 | 629 | t.state = TokenizeStateSawDot; |
| 626 | 630 | break; |
| 627 | case '?': | |
| 628 | begin_token(&t, TokenIdQuestion); | |
| 629 | t.state = TokenizeStateSawQuestionMark; | |
| 630 | break; | |
| 631 | 631 | default: |
| 632 | 632 | invalid_char_error(&t, c); |
| 633 | 633 | } |
| 634 | 634 | break; |
| 635 | case TokenizeStateSawQuestionMark: | |
| 636 | switch (c) { | |
| 637 | case '?': | |
| 638 | set_token_id(&t, t.cur_tok, TokenIdDoubleQuestion); | |
| 639 | end_token(&t); | |
| 640 | t.state = TokenizeStateStart; | |
| 641 | break; | |
| 642 | default: | |
| 643 | t.pos -= 1; | |
| 644 | end_token(&t); | |
| 645 | t.state = TokenizeStateStart; | |
| 646 | continue; | |
| 647 | } | |
| 648 | break; | |
| 649 | 635 | case TokenizeStateSawDot: |
| 650 | 636 | switch (c) { |
| 651 | 637 | case '.': |
| ... | ... | @@ -1480,7 +1466,6 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 1480 | 1466 | case TokenizeStateSawGreaterThan: |
| 1481 | 1467 | case TokenizeStateSawGreaterThanGreaterThan: |
| 1482 | 1468 | case TokenizeStateSawDot: |
| 1483 | case TokenizeStateSawQuestionMark: | |
| 1484 | 1469 | case TokenizeStateSawAtSign: |
| 1485 | 1470 | case TokenizeStateSawStarPercent: |
| 1486 | 1471 | case TokenizeStateSawPlusPercent: |
| ... | ... | @@ -1545,7 +1530,6 @@ const char * token_name(TokenId id) { |
| 1545 | 1530 | case TokenIdDash: return "-"; |
| 1546 | 1531 | case TokenIdDivEq: return "/="; |
| 1547 | 1532 | case TokenIdDot: return "."; |
| 1548 | case TokenIdDoubleQuestion: return "??"; | |
| 1549 | 1533 | case TokenIdEllipsis2: return ".."; |
| 1550 | 1534 | case TokenIdEllipsis3: return "..."; |
| 1551 | 1535 | case TokenIdEof: return "EOF"; |
| ... | ... | @@ -1582,6 +1566,7 @@ const char * token_name(TokenId id) { |
| 1582 | 1566 | case TokenIdKeywordNoAlias: return "noalias"; |
| 1583 | 1567 | case TokenIdKeywordNull: return "null"; |
| 1584 | 1568 | case TokenIdKeywordOr: return "or"; |
| 1569 | case TokenIdKeywordOrElse: return "orelse"; | |
| 1585 | 1570 | case TokenIdKeywordPacked: return "packed"; |
| 1586 | 1571 | case TokenIdKeywordPromise: return "promise"; |
| 1587 | 1572 | case TokenIdKeywordPub: return "pub"; |
src/tokenizer.hpp+1-1| ... | ... | @@ -41,7 +41,6 @@ enum TokenId { |
| 41 | 41 | TokenIdDash, |
| 42 | 42 | TokenIdDivEq, |
| 43 | 43 | TokenIdDot, |
| 44 | TokenIdDoubleQuestion, | |
| 45 | 44 | TokenIdEllipsis2, |
| 46 | 45 | TokenIdEllipsis3, |
| 47 | 46 | TokenIdEof, |
| ... | ... | @@ -76,6 +75,7 @@ enum TokenId { |
| 76 | 75 | TokenIdKeywordNoAlias, |
| 77 | 76 | TokenIdKeywordNull, |
| 78 | 77 | TokenIdKeywordOr, |
| 78 | TokenIdKeywordOrElse, | |
| 79 | 79 | TokenIdKeywordPacked, |
| 80 | 80 | TokenIdKeywordPromise, |
| 81 | 81 | TokenIdKeywordPub, |
src/translate_c.cpp+9-7| ... | ... | @@ -260,6 +260,12 @@ static AstNode *trans_create_node_prefix_op(Context *c, PrefixOp op, AstNode *ch |
| 260 | 260 | return node; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child_node) { | |
| 264 | AstNode *node = trans_create_node(c, NodeTypeUnwrapOptional); | |
| 265 | node->data.unwrap_optional.expr = child_node; | |
| 266 | return node; | |
| 267 | } | |
| 268 | ||
| 263 | 269 | static AstNode *trans_create_node_bin_op(Context *c, AstNode *lhs_node, BinOpType op, AstNode *rhs_node) { |
| 264 | 270 | AstNode *node = trans_create_node(c, NodeTypeBinOpExpr); |
| 265 | 271 | node->data.bin_op_expr.op1 = lhs_node; |
| ... | ... | @@ -382,7 +388,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r |
| 382 | 388 | fn_def->data.fn_def.fn_proto = fn_proto; |
| 383 | 389 | fn_proto->data.fn_proto.fn_def_node = fn_def; |
| 384 | 390 | |
| 385 | AstNode *unwrap_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, ref_node); | |
| 391 | AstNode *unwrap_node = trans_create_node_unwrap_null(c, ref_node); | |
| 386 | 392 | AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr); |
| 387 | 393 | fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node; |
| 388 | 394 | |
| ... | ... | @@ -409,10 +415,6 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r |
| 409 | 415 | return fn_def; |
| 410 | 416 | } |
| 411 | 417 | |
| 412 | static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child) { | |
| 413 | return trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, child); | |
| 414 | } | |
| 415 | ||
| 416 | 418 | static AstNode *get_global(Context *c, Buf *name) { |
| 417 | 419 | { |
| 418 | 420 | auto entry = c->global_table.maybe_get(name); |
| ... | ... | @@ -1963,7 +1965,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc |
| 1963 | 1965 | bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType()); |
| 1964 | 1966 | if (is_fn_ptr) |
| 1965 | 1967 | return value_node; |
| 1966 | AstNode *unwrapped = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, value_node); | |
| 1968 | AstNode *unwrapped = trans_create_node_unwrap_null(c, value_node); | |
| 1967 | 1969 | return trans_create_node_ptr_deref(c, unwrapped); |
| 1968 | 1970 | } |
| 1969 | 1971 | case UO_Plus: |
| ... | ... | @@ -2587,7 +2589,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope * |
| 2587 | 2589 | } |
| 2588 | 2590 | } |
| 2589 | 2591 | if (callee_node == nullptr) { |
| 2590 | callee_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, callee_raw_node); | |
| 2592 | callee_node = trans_create_node_unwrap_null(c, callee_raw_node); | |
| 2591 | 2593 | } |
| 2592 | 2594 | } else { |
| 2593 | 2595 | callee_node = callee_raw_node; |
std/atomic/queue.zig+2-2| ... | ... | @@ -33,8 +33,8 @@ pub fn Queue(comptime T: type) type { |
| 33 | 33 | pub fn get(self: *Self) ?*Node { |
| 34 | 34 | var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst); |
| 35 | 35 | while (true) { |
| 36 | const node = head.next ?? return null; | |
| 37 | head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return node; | |
| 36 | const node = head.next orelse return null; | |
| 37 | head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return node; | |
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | }; |
std/atomic/stack.zig+2-2| ... | ... | @@ -28,14 +28,14 @@ pub fn Stack(comptime T: type) type { |
| 28 | 28 | var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst); |
| 29 | 29 | while (true) { |
| 30 | 30 | node.next = root; |
| 31 | root = @cmpxchgWeak(?*Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? break; | |
| 31 | root = @cmpxchgWeak(?*Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse break; | |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | pub fn pop(self: *Self) ?*Node { |
| 36 | 36 | var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst); |
| 37 | 37 | while (true) { |
| 38 | root = @cmpxchgWeak(?*Node, &self.root, root, (root ?? return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return root; | |
| 38 | root = @cmpxchgWeak(?*Node, &self.root, root, (root orelse return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return root; | |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 |
std/buf_map.zig+3-3| ... | ... | @@ -19,7 +19,7 @@ pub const BufMap = struct { |
| 19 | 19 | pub fn deinit(self: *const BufMap) void { |
| 20 | 20 | var it = self.hash_map.iterator(); |
| 21 | 21 | while (true) { |
| 22 | const entry = it.next() ?? break; | |
| 22 | const entry = it.next() orelse break; | |
| 23 | 23 | self.free(entry.key); |
| 24 | 24 | self.free(entry.value); |
| 25 | 25 | } |
| ... | ... | @@ -37,12 +37,12 @@ pub const BufMap = struct { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | pub fn get(self: *const BufMap, key: []const u8) ?[]const u8 { |
| 40 | const entry = self.hash_map.get(key) ?? return null; | |
| 40 | const entry = self.hash_map.get(key) orelse return null; | |
| 41 | 41 | return entry.value; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | pub fn delete(self: *BufMap, key: []const u8) void { |
| 45 | const entry = self.hash_map.remove(key) ?? return; | |
| 45 | const entry = self.hash_map.remove(key) orelse return; | |
| 46 | 46 | self.free(entry.key); |
| 47 | 47 | self.free(entry.value); |
| 48 | 48 | } |
std/buf_set.zig+2-2| ... | ... | @@ -17,7 +17,7 @@ pub const BufSet = struct { |
| 17 | 17 | pub fn deinit(self: *const BufSet) void { |
| 18 | 18 | var it = self.hash_map.iterator(); |
| 19 | 19 | while (true) { |
| 20 | const entry = it.next() ?? break; | |
| 20 | const entry = it.next() orelse break; | |
| 21 | 21 | self.free(entry.key); |
| 22 | 22 | } |
| 23 | 23 | |
| ... | ... | @@ -33,7 +33,7 @@ pub const BufSet = struct { |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | pub fn delete(self: *BufSet, key: []const u8) void { |
| 36 | const entry = self.hash_map.remove(key) ?? return; | |
| 36 | const entry = self.hash_map.remove(key) orelse return; | |
| 37 | 37 | self.free(entry.key); |
| 38 | 38 | } |
| 39 | 39 |
std/build.zig+12-12| ... | ... | @@ -136,7 +136,7 @@ pub const Builder = struct { |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void { |
| 139 | self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default | |
| 139 | self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default | |
| 140 | 140 | self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable; |
| 141 | 141 | self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable; |
| 142 | 142 | } |
| ... | ... | @@ -312,9 +312,9 @@ pub const Builder = struct { |
| 312 | 312 | if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| { |
| 313 | 313 | var it = mem.split(nix_cflags_compile, " "); |
| 314 | 314 | while (true) { |
| 315 | const word = it.next() ?? break; | |
| 315 | const word = it.next() orelse break; | |
| 316 | 316 | if (mem.eql(u8, word, "-isystem")) { |
| 317 | const include_path = it.next() ?? { | |
| 317 | const include_path = it.next() orelse { | |
| 318 | 318 | warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n"); |
| 319 | 319 | break; |
| 320 | 320 | }; |
| ... | ... | @@ -330,9 +330,9 @@ pub const Builder = struct { |
| 330 | 330 | if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| { |
| 331 | 331 | var it = mem.split(nix_ldflags, " "); |
| 332 | 332 | while (true) { |
| 333 | const word = it.next() ?? break; | |
| 333 | const word = it.next() orelse break; | |
| 334 | 334 | if (mem.eql(u8, word, "-rpath")) { |
| 335 | const rpath = it.next() ?? { | |
| 335 | const rpath = it.next() orelse { | |
| 336 | 336 | warn("Expected argument after -rpath in NIX_LDFLAGS\n"); |
| 337 | 337 | break; |
| 338 | 338 | }; |
| ... | ... | @@ -362,7 +362,7 @@ pub const Builder = struct { |
| 362 | 362 | } |
| 363 | 363 | self.available_options_list.append(available_option) catch unreachable; |
| 364 | 364 | |
| 365 | const entry = self.user_input_options.get(name) ?? return null; | |
| 365 | const entry = self.user_input_options.get(name) orelse return null; | |
| 366 | 366 | entry.value.used = true; |
| 367 | 367 | switch (type_id) { |
| 368 | 368 | TypeId.Bool => switch (entry.value.value) { |
| ... | ... | @@ -416,9 +416,9 @@ pub const Builder = struct { |
| 416 | 416 | pub fn standardReleaseOptions(self: *Builder) builtin.Mode { |
| 417 | 417 | if (self.release_mode) |mode| return mode; |
| 418 | 418 | |
| 419 | const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false; | |
| 420 | const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false; | |
| 421 | const release_small = self.option(bool, "release-small", "size optimizations on and safety off") ?? false; | |
| 419 | const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") orelse false; | |
| 420 | const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") orelse false; | |
| 421 | const release_small = self.option(bool, "release-small", "size optimizations on and safety off") orelse false; | |
| 422 | 422 | |
| 423 | 423 | const mode = if (release_safe and !release_fast and !release_small) builtin.Mode.ReleaseSafe else if (release_fast and !release_safe and !release_small) builtin.Mode.ReleaseFast else if (release_small and !release_fast and !release_safe) builtin.Mode.ReleaseSmall else if (!release_fast and !release_safe and !release_small) builtin.Mode.Debug else x: { |
| 424 | 424 | warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)"); |
| ... | ... | @@ -518,7 +518,7 @@ pub const Builder = struct { |
| 518 | 518 | // make sure all args are used |
| 519 | 519 | var it = self.user_input_options.iterator(); |
| 520 | 520 | while (true) { |
| 521 | const entry = it.next() ?? break; | |
| 521 | const entry = it.next() orelse break; | |
| 522 | 522 | if (!entry.value.used) { |
| 523 | 523 | warn("Invalid option: -D{}\n\n", entry.key); |
| 524 | 524 | self.markInvalidUserInput(); |
| ... | ... | @@ -1246,7 +1246,7 @@ pub const LibExeObjStep = struct { |
| 1246 | 1246 | { |
| 1247 | 1247 | var it = self.link_libs.iterator(); |
| 1248 | 1248 | while (true) { |
| 1249 | const entry = it.next() ?? break; | |
| 1249 | const entry = it.next() orelse break; | |
| 1250 | 1250 | zig_args.append("--library") catch unreachable; |
| 1251 | 1251 | zig_args.append(entry.key) catch unreachable; |
| 1252 | 1252 | } |
| ... | ... | @@ -1696,7 +1696,7 @@ pub const TestStep = struct { |
| 1696 | 1696 | { |
| 1697 | 1697 | var it = self.link_libs.iterator(); |
| 1698 | 1698 | while (true) { |
| 1699 | const entry = it.next() ?? break; | |
| 1699 | const entry = it.next() orelse break; | |
| 1700 | 1700 | try zig_args.append("--library"); |
| 1701 | 1701 | try zig_args.append(entry.key); |
| 1702 | 1702 | } |
std/debug/index.zig+10-10| ... | ... | @@ -208,7 +208,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us |
| 208 | 208 | .name = "???", |
| 209 | 209 | .address = address, |
| 210 | 210 | }; |
| 211 | const symbol = debug_info.symbol_table.search(address) ?? &unknown; | |
| 211 | const symbol = debug_info.symbol_table.search(address) orelse &unknown; | |
| 212 | 212 | try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address); |
| 213 | 213 | }, |
| 214 | 214 | else => { |
| ... | ... | @@ -268,10 +268,10 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 268 | 268 | try st.elf.openFile(allocator, &st.self_exe_file); |
| 269 | 269 | errdefer st.elf.close(); |
| 270 | 270 | |
| 271 | st.debug_info = (try st.elf.findSection(".debug_info")) ?? return error.MissingDebugInfo; | |
| 272 | st.debug_abbrev = (try st.elf.findSection(".debug_abbrev")) ?? return error.MissingDebugInfo; | |
| 273 | st.debug_str = (try st.elf.findSection(".debug_str")) ?? return error.MissingDebugInfo; | |
| 274 | st.debug_line = (try st.elf.findSection(".debug_line")) ?? return error.MissingDebugInfo; | |
| 271 | st.debug_info = (try st.elf.findSection(".debug_info")) orelse return error.MissingDebugInfo; | |
| 272 | st.debug_abbrev = (try st.elf.findSection(".debug_abbrev")) orelse return error.MissingDebugInfo; | |
| 273 | st.debug_str = (try st.elf.findSection(".debug_str")) orelse return error.MissingDebugInfo; | |
| 274 | st.debug_line = (try st.elf.findSection(".debug_line")) orelse return error.MissingDebugInfo; | |
| 275 | 275 | st.debug_ranges = (try st.elf.findSection(".debug_ranges")); |
| 276 | 276 | try scanAllCompileUnits(st); |
| 277 | 277 | return st; |
| ... | ... | @@ -443,7 +443,7 @@ const Die = struct { |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | fn getAttrAddr(self: *const Die, id: u64) !u64 { |
| 446 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | |
| 446 | const form_value = self.getAttr(id) orelse return error.MissingDebugInfo; | |
| 447 | 447 | return switch (form_value.*) { |
| 448 | 448 | FormValue.Address => |value| value, |
| 449 | 449 | else => error.InvalidDebugInfo, |
| ... | ... | @@ -451,7 +451,7 @@ const Die = struct { |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | fn getAttrSecOffset(self: *const Die, id: u64) !u64 { |
| 454 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | |
| 454 | const form_value = self.getAttr(id) orelse return error.MissingDebugInfo; | |
| 455 | 455 | return switch (form_value.*) { |
| 456 | 456 | FormValue.Const => |value| value.asUnsignedLe(), |
| 457 | 457 | FormValue.SecOffset => |value| value, |
| ... | ... | @@ -460,7 +460,7 @@ const Die = struct { |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | fn getAttrUnsignedLe(self: *const Die, id: u64) !u64 { |
| 463 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | |
| 463 | const form_value = self.getAttr(id) orelse return error.MissingDebugInfo; | |
| 464 | 464 | return switch (form_value.*) { |
| 465 | 465 | FormValue.Const => |value| value.asUnsignedLe(), |
| 466 | 466 | else => error.InvalidDebugInfo, |
| ... | ... | @@ -468,7 +468,7 @@ const Die = struct { |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | fn getAttrString(self: *const Die, st: *ElfStackTrace, id: u64) ![]u8 { |
| 471 | const form_value = self.getAttr(id) ?? return error.MissingDebugInfo; | |
| 471 | const form_value = self.getAttr(id) orelse return error.MissingDebugInfo; | |
| 472 | 472 | return switch (form_value.*) { |
| 473 | 473 | FormValue.String => |value| value, |
| 474 | 474 | FormValue.StrPtr => |offset| getString(st, offset), |
| ... | ... | @@ -748,7 +748,7 @@ fn parseDie(st: *ElfStackTrace, abbrev_table: *const AbbrevTable, is_64: bool) ! |
| 748 | 748 | var in_file_stream = io.FileInStream.init(in_file); |
| 749 | 749 | const in_stream = &in_file_stream.stream; |
| 750 | 750 | const abbrev_code = try readULeb128(in_stream); |
| 751 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) ?? return error.InvalidDebugInfo; | |
| 751 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; | |
| 752 | 752 | |
| 753 | 753 | var result = Die{ |
| 754 | 754 | .tag_id = table_entry.tag_id, |
std/heap.zig+5-5| ... | ... | @@ -97,12 +97,12 @@ pub const DirectAllocator = struct { |
| 97 | 97 | }, |
| 98 | 98 | Os.windows => { |
| 99 | 99 | const amt = n + alignment + @sizeOf(usize); |
| 100 | const heap_handle = self.heap_handle ?? blk: { | |
| 101 | const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory; | |
| 100 | const heap_handle = self.heap_handle orelse blk: { | |
| 101 | const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) orelse return error.OutOfMemory; | |
| 102 | 102 | self.heap_handle = hh; |
| 103 | 103 | break :blk hh; |
| 104 | 104 | }; |
| 105 | const ptr = os.windows.HeapAlloc(heap_handle, 0, amt) ?? return error.OutOfMemory; | |
| 105 | const ptr = os.windows.HeapAlloc(heap_handle, 0, amt) orelse return error.OutOfMemory; | |
| 106 | 106 | const root_addr = @ptrToInt(ptr); |
| 107 | 107 | const rem = @rem(root_addr, alignment); |
| 108 | 108 | const march_forward_bytes = if (rem == 0) 0 else (alignment - rem); |
| ... | ... | @@ -142,7 +142,7 @@ pub const DirectAllocator = struct { |
| 142 | 142 | const root_addr = @intToPtr(*align(1) usize, old_record_addr).*; |
| 143 | 143 | const old_ptr = @intToPtr(*c_void, root_addr); |
| 144 | 144 | const amt = new_size + alignment + @sizeOf(usize); |
| 145 | const new_ptr = os.windows.HeapReAlloc(self.heap_handle.?, 0, old_ptr, amt) ?? blk: { | |
| 145 | const new_ptr = os.windows.HeapReAlloc(self.heap_handle.?, 0, old_ptr, amt) orelse blk: { | |
| 146 | 146 | if (new_size > old_mem.len) return error.OutOfMemory; |
| 147 | 147 | const new_record_addr = old_record_addr - new_size + old_mem.len; |
| 148 | 148 | @intToPtr(*align(1) usize, new_record_addr).* = root_addr; |
| ... | ... | @@ -343,7 +343,7 @@ pub const ThreadSafeFixedBufferAllocator = struct { |
| 343 | 343 | if (new_end_index > self.buffer.len) { |
| 344 | 344 | return error.OutOfMemory; |
| 345 | 345 | } |
| 346 | end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index..new_end_index]; | |
| 346 | end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse return self.buffer[adjusted_index..new_end_index]; | |
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 |
std/linked_list.zig+2-2| ... | ... | @@ -169,7 +169,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 169 | 169 | /// Returns: |
| 170 | 170 | /// A pointer to the last node in the list. |
| 171 | 171 | pub fn pop(list: *Self) ?*Node { |
| 172 | const last = list.last ?? return null; | |
| 172 | const last = list.last orelse return null; | |
| 173 | 173 | list.remove(last); |
| 174 | 174 | return last; |
| 175 | 175 | } |
| ... | ... | @@ -179,7 +179,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 179 | 179 | /// Returns: |
| 180 | 180 | /// A pointer to the first node in the list. |
| 181 | 181 | pub fn popFirst(list: *Self) ?*Node { |
| 182 | const first = list.first ?? return null; | |
| 182 | const first = list.first orelse return null; | |
| 183 | 183 | list.remove(first); |
| 184 | 184 | return first; |
| 185 | 185 | } |
std/os/index.zig+7-7| ... | ... | @@ -425,7 +425,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator: |
| 425 | 425 | return posixExecveErrnoToErr(posix.getErrno(posix.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr))); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin"; | |
| 428 | const PATH = getEnvPosix("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; | |
| 429 | 429 | // PATH.len because it is >= the largest search_path |
| 430 | 430 | // +1 for the / to join the search path and exe_path |
| 431 | 431 | // +1 for the null terminating byte |
| ... | ... | @@ -490,7 +490,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { |
| 490 | 490 | errdefer result.deinit(); |
| 491 | 491 | |
| 492 | 492 | if (is_windows) { |
| 493 | const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory; | |
| 493 | const ptr = windows.GetEnvironmentStringsA() orelse return error.OutOfMemory; | |
| 494 | 494 | defer assert(windows.FreeEnvironmentStringsA(ptr) != 0); |
| 495 | 495 | |
| 496 | 496 | var i: usize = 0; |
| ... | ... | @@ -573,7 +573,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 { |
| 573 | 573 | return allocator.shrink(u8, buf, result); |
| 574 | 574 | } |
| 575 | 575 | } else { |
| 576 | const result = getEnvPosix(key) ?? return error.EnvironmentVariableNotFound; | |
| 576 | const result = getEnvPosix(key) orelse return error.EnvironmentVariableNotFound; | |
| 577 | 577 | return mem.dupe(allocator, u8, result); |
| 578 | 578 | } |
| 579 | 579 | } |
| ... | ... | @@ -1641,7 +1641,7 @@ pub const ArgIterator = struct { |
| 1641 | 1641 | if (builtin.os == Os.windows) { |
| 1642 | 1642 | return self.inner.next(allocator); |
| 1643 | 1643 | } else { |
| 1644 | return mem.dupe(allocator, u8, self.inner.next() ?? return null); | |
| 1644 | return mem.dupe(allocator, u8, self.inner.next() orelse return null); | |
| 1645 | 1645 | } |
| 1646 | 1646 | } |
| 1647 | 1647 | |
| ... | ... | @@ -2457,9 +2457,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 2457 | 2457 | } |
| 2458 | 2458 | }; |
| 2459 | 2459 | |
| 2460 | const heap_handle = windows.GetProcessHeap() ?? return SpawnThreadError.OutOfMemory; | |
| 2460 | const heap_handle = windows.GetProcessHeap() orelse return SpawnThreadError.OutOfMemory; | |
| 2461 | 2461 | const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext); |
| 2462 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory; | |
| 2462 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory; | |
| 2463 | 2463 | errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); |
| 2464 | 2464 | const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; |
| 2465 | 2465 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; |
| ... | ... | @@ -2468,7 +2468,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 2468 | 2468 | outer_context.thread.data.alloc_start = bytes_ptr; |
| 2469 | 2469 | |
| 2470 | 2470 | const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner); |
| 2471 | outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? { | |
| 2471 | outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { | |
| 2472 | 2472 | const err = windows.GetLastError(); |
| 2473 | 2473 | return switch (err) { |
| 2474 | 2474 | else => os.unexpectedErrorWindows(err), |
std/os/linux/vdso.zig+4-4| ... | ... | @@ -28,7 +28,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | const dynv = maybe_dynv ?? return 0; | |
| 31 | const dynv = maybe_dynv orelse return 0; | |
| 32 | 32 | if (base == @maxValue(usize)) return 0; |
| 33 | 33 | |
| 34 | 34 | var maybe_strings: ?[*]u8 = null; |
| ... | ... | @@ -52,9 +52,9 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | const strings = maybe_strings ?? return 0; | |
| 56 | const syms = maybe_syms ?? return 0; | |
| 57 | const hashtab = maybe_hashtab ?? return 0; | |
| 55 | const strings = maybe_strings orelse return 0; | |
| 56 | const syms = maybe_syms orelse return 0; | |
| 57 | const hashtab = maybe_hashtab orelse return 0; | |
| 58 | 58 | if (maybe_verdef == null) maybe_versym = null; |
| 59 | 59 | |
| 60 | 60 | const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON); |
std/os/path.zig+6-6| ... | ... | @@ -182,8 +182,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | var it = mem.split(path, []u8{this_sep}); |
| 185 | _ = (it.next() ?? return relative_path); | |
| 186 | _ = (it.next() ?? return relative_path); | |
| 185 | _ = (it.next() orelse return relative_path); | |
| 186 | _ = (it.next() orelse return relative_path); | |
| 187 | 187 | return WindowsPath{ |
| 188 | 188 | .is_abs = isAbsoluteWindows(path), |
| 189 | 189 | .kind = WindowsPath.Kind.NetworkShare, |
| ... | ... | @@ -200,8 +200,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | var it = mem.split(path, []u8{this_sep}); |
| 203 | _ = (it.next() ?? return relative_path); | |
| 204 | _ = (it.next() ?? return relative_path); | |
| 203 | _ = (it.next() orelse return relative_path); | |
| 204 | _ = (it.next() orelse return relative_path); | |
| 205 | 205 | return WindowsPath{ |
| 206 | 206 | .is_abs = isAbsoluteWindows(path), |
| 207 | 207 | .kind = WindowsPath.Kind.NetworkShare, |
| ... | ... | @@ -923,7 +923,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) |
| 923 | 923 | var from_it = mem.split(resolved_from, "/\\"); |
| 924 | 924 | var to_it = mem.split(resolved_to, "/\\"); |
| 925 | 925 | while (true) { |
| 926 | const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); | |
| 926 | const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest()); | |
| 927 | 927 | const to_rest = to_it.rest(); |
| 928 | 928 | if (to_it.next()) |to_component| { |
| 929 | 929 | // TODO ASCII is wrong, we actually need full unicode support to compare paths. |
| ... | ... | @@ -974,7 +974,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![ |
| 974 | 974 | var from_it = mem.split(resolved_from, "/"); |
| 975 | 975 | var to_it = mem.split(resolved_to, "/"); |
| 976 | 976 | while (true) { |
| 977 | const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); | |
| 977 | const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest()); | |
| 978 | 978 | const to_rest = to_it.rest(); |
| 979 | 979 | if (to_it.next()) |to_component| { |
| 980 | 980 | if (mem.eql(u8, from_component, to_component)) |
std/os/windows/util.zig+1-1| ... | ... | @@ -153,7 +153,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) |
| 153 | 153 | pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE { |
| 154 | 154 | const padded_buff = try cstr.addNullByte(allocator, dll_path); |
| 155 | 155 | defer allocator.free(padded_buff); |
| 156 | return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; | |
| 156 | return windows.LoadLibraryA(padded_buff.ptr) orelse error.DllNotFound; | |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | pub fn windowsUnloadDll(hModule: windows.HMODULE) void { |
std/special/build_runner.zig+5-5| ... | ... | @@ -27,15 +27,15 @@ pub fn main() !void { |
| 27 | 27 | // skip my own exe name |
| 28 | 28 | _ = arg_it.skip(); |
| 29 | 29 | |
| 30 | const zig_exe = try unwrapArg(arg_it.next(allocator) ?? { | |
| 30 | const zig_exe = try unwrapArg(arg_it.next(allocator) orelse { | |
| 31 | 31 | warn("Expected first argument to be path to zig compiler\n"); |
| 32 | 32 | return error.InvalidArgs; |
| 33 | 33 | }); |
| 34 | const build_root = try unwrapArg(arg_it.next(allocator) ?? { | |
| 34 | const build_root = try unwrapArg(arg_it.next(allocator) orelse { | |
| 35 | 35 | warn("Expected second argument to be build root directory path\n"); |
| 36 | 36 | return error.InvalidArgs; |
| 37 | 37 | }); |
| 38 | const cache_root = try unwrapArg(arg_it.next(allocator) ?? { | |
| 38 | const cache_root = try unwrapArg(arg_it.next(allocator) orelse { | |
| 39 | 39 | warn("Expected third argument to be cache root directory path\n"); |
| 40 | 40 | return error.InvalidArgs; |
| 41 | 41 | }); |
| ... | ... | @@ -84,12 +84,12 @@ pub fn main() !void { |
| 84 | 84 | } else if (mem.eql(u8, arg, "--help")) { |
| 85 | 85 | return usage(&builder, false, try stdout_stream); |
| 86 | 86 | } else if (mem.eql(u8, arg, "--prefix")) { |
| 87 | prefix = try unwrapArg(arg_it.next(allocator) ?? { | |
| 87 | prefix = try unwrapArg(arg_it.next(allocator) orelse { | |
| 88 | 88 | warn("Expected argument after --prefix\n\n"); |
| 89 | 89 | return usageAndErr(&builder, false, try stderr_stream); |
| 90 | 90 | }); |
| 91 | 91 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 92 | const search_prefix = try unwrapArg(arg_it.next(allocator) ?? { | |
| 92 | const search_prefix = try unwrapArg(arg_it.next(allocator) orelse { | |
| 93 | 93 | warn("Expected argument after --search-prefix\n\n"); |
| 94 | 94 | return usageAndErr(&builder, false, try stderr_stream); |
| 95 | 95 | }); |
std/unicode.zig+1-1| ... | ... | @@ -220,7 +220,7 @@ const Utf8Iterator = struct { |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | pub fn nextCodepoint(it: *Utf8Iterator) ?u32 { |
| 223 | const slice = it.nextCodepointSlice() ?? return null; | |
| 223 | const slice = it.nextCodepointSlice() orelse return null; | |
| 224 | 224 | |
| 225 | 225 | switch (slice.len) { |
| 226 | 226 | 1 => return u32(slice[0]), |
std/zig/parse.zig+24-23| ... | ... | @@ -43,7 +43,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 43 | 43 | |
| 44 | 44 | // skip over line comments at the top of the file |
| 45 | 45 | while (true) { |
| 46 | const next_tok = tok_it.peek() ?? break; | |
| 46 | const next_tok = tok_it.peek() orelse break; | |
| 47 | 47 | if (next_tok.id != Token.Id.LineComment) break; |
| 48 | 48 | _ = tok_it.next(); |
| 49 | 49 | } |
| ... | ... | @@ -197,7 +197,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 197 | 197 | const lib_name_token = nextToken(&tok_it, &tree); |
| 198 | 198 | const lib_name_token_index = lib_name_token.index; |
| 199 | 199 | const lib_name_token_ptr = lib_name_token.ptr; |
| 200 | break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) ?? { | |
| 200 | break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) orelse { | |
| 201 | 201 | prevToken(&tok_it, &tree); |
| 202 | 202 | break :blk null; |
| 203 | 203 | }; |
| ... | ... | @@ -1434,13 +1434,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1434 | 1434 | try stack.append(State{ |
| 1435 | 1435 | .ExpectTokenSave = ExpectTokenSave{ |
| 1436 | 1436 | .id = Token.Id.AngleBracketRight, |
| 1437 | .ptr = &async_node.rangle_bracket.? }, | |
| 1437 | .ptr = &async_node.rangle_bracket.?, | |
| 1438 | }, | |
| 1438 | 1439 | }); |
| 1439 | 1440 | try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } }); |
| 1440 | 1441 | continue; |
| 1441 | 1442 | }, |
| 1442 | 1443 | State.AsyncEnd => |ctx| { |
| 1443 | const node = ctx.ctx.get() ?? continue; | |
| 1444 | const node = ctx.ctx.get() orelse continue; | |
| 1444 | 1445 | |
| 1445 | 1446 | switch (node.id) { |
| 1446 | 1447 | ast.Node.Id.FnProto => { |
| ... | ... | @@ -1813,7 +1814,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1813 | 1814 | continue; |
| 1814 | 1815 | }, |
| 1815 | 1816 | State.RangeExpressionEnd => |opt_ctx| { |
| 1816 | const lhs = opt_ctx.get() ?? continue; | |
| 1817 | const lhs = opt_ctx.get() orelse continue; | |
| 1817 | 1818 | |
| 1818 | 1819 | if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| { |
| 1819 | 1820 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -1835,7 +1836,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1835 | 1836 | }, |
| 1836 | 1837 | |
| 1837 | 1838 | State.AssignmentExpressionEnd => |opt_ctx| { |
| 1838 | const lhs = opt_ctx.get() ?? continue; | |
| 1839 | const lhs = opt_ctx.get() orelse continue; | |
| 1839 | 1840 | |
| 1840 | 1841 | const token = nextToken(&tok_it, &tree); |
| 1841 | 1842 | const token_index = token.index; |
| ... | ... | @@ -1865,7 +1866,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1865 | 1866 | }, |
| 1866 | 1867 | |
| 1867 | 1868 | State.UnwrapExpressionEnd => |opt_ctx| { |
| 1868 | const lhs = opt_ctx.get() ?? continue; | |
| 1869 | const lhs = opt_ctx.get() orelse continue; | |
| 1869 | 1870 | |
| 1870 | 1871 | const token = nextToken(&tok_it, &tree); |
| 1871 | 1872 | const token_index = token.index; |
| ... | ... | @@ -1900,7 +1901,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1900 | 1901 | }, |
| 1901 | 1902 | |
| 1902 | 1903 | State.BoolOrExpressionEnd => |opt_ctx| { |
| 1903 | const lhs = opt_ctx.get() ?? continue; | |
| 1904 | const lhs = opt_ctx.get() orelse continue; | |
| 1904 | 1905 | |
| 1905 | 1906 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| { |
| 1906 | 1907 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -1924,7 +1925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1924 | 1925 | }, |
| 1925 | 1926 | |
| 1926 | 1927 | State.BoolAndExpressionEnd => |opt_ctx| { |
| 1927 | const lhs = opt_ctx.get() ?? continue; | |
| 1928 | const lhs = opt_ctx.get() orelse continue; | |
| 1928 | 1929 | |
| 1929 | 1930 | if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| { |
| 1930 | 1931 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -1948,7 +1949,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1948 | 1949 | }, |
| 1949 | 1950 | |
| 1950 | 1951 | State.ComparisonExpressionEnd => |opt_ctx| { |
| 1951 | const lhs = opt_ctx.get() ?? continue; | |
| 1952 | const lhs = opt_ctx.get() orelse continue; | |
| 1952 | 1953 | |
| 1953 | 1954 | const token = nextToken(&tok_it, &tree); |
| 1954 | 1955 | const token_index = token.index; |
| ... | ... | @@ -1978,7 +1979,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 1978 | 1979 | }, |
| 1979 | 1980 | |
| 1980 | 1981 | State.BinaryOrExpressionEnd => |opt_ctx| { |
| 1981 | const lhs = opt_ctx.get() ?? continue; | |
| 1982 | const lhs = opt_ctx.get() orelse continue; | |
| 1982 | 1983 | |
| 1983 | 1984 | if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| { |
| 1984 | 1985 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -2002,7 +2003,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2002 | 2003 | }, |
| 2003 | 2004 | |
| 2004 | 2005 | State.BinaryXorExpressionEnd => |opt_ctx| { |
| 2005 | const lhs = opt_ctx.get() ?? continue; | |
| 2006 | const lhs = opt_ctx.get() orelse continue; | |
| 2006 | 2007 | |
| 2007 | 2008 | if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| { |
| 2008 | 2009 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -2026,7 +2027,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2026 | 2027 | }, |
| 2027 | 2028 | |
| 2028 | 2029 | State.BinaryAndExpressionEnd => |opt_ctx| { |
| 2029 | const lhs = opt_ctx.get() ?? continue; | |
| 2030 | const lhs = opt_ctx.get() orelse continue; | |
| 2030 | 2031 | |
| 2031 | 2032 | if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| { |
| 2032 | 2033 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -2050,7 +2051,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2050 | 2051 | }, |
| 2051 | 2052 | |
| 2052 | 2053 | State.BitShiftExpressionEnd => |opt_ctx| { |
| 2053 | const lhs = opt_ctx.get() ?? continue; | |
| 2054 | const lhs = opt_ctx.get() orelse continue; | |
| 2054 | 2055 | |
| 2055 | 2056 | const token = nextToken(&tok_it, &tree); |
| 2056 | 2057 | const token_index = token.index; |
| ... | ... | @@ -2080,7 +2081,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2080 | 2081 | }, |
| 2081 | 2082 | |
| 2082 | 2083 | State.AdditionExpressionEnd => |opt_ctx| { |
| 2083 | const lhs = opt_ctx.get() ?? continue; | |
| 2084 | const lhs = opt_ctx.get() orelse continue; | |
| 2084 | 2085 | |
| 2085 | 2086 | const token = nextToken(&tok_it, &tree); |
| 2086 | 2087 | const token_index = token.index; |
| ... | ... | @@ -2110,7 +2111,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2110 | 2111 | }, |
| 2111 | 2112 | |
| 2112 | 2113 | State.MultiplyExpressionEnd => |opt_ctx| { |
| 2113 | const lhs = opt_ctx.get() ?? continue; | |
| 2114 | const lhs = opt_ctx.get() orelse continue; | |
| 2114 | 2115 | |
| 2115 | 2116 | const token = nextToken(&tok_it, &tree); |
| 2116 | 2117 | const token_index = token.index; |
| ... | ... | @@ -2141,7 +2142,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2141 | 2142 | }, |
| 2142 | 2143 | |
| 2143 | 2144 | State.CurlySuffixExpressionEnd => |opt_ctx| { |
| 2144 | const lhs = opt_ctx.get() ?? continue; | |
| 2145 | const lhs = opt_ctx.get() orelse continue; | |
| 2145 | 2146 | |
| 2146 | 2147 | if (tok_it.peek().?.id == Token.Id.Period) { |
| 2147 | 2148 | const node = try arena.construct(ast.Node.SuffixOp{ |
| ... | ... | @@ -2189,7 +2190,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2189 | 2190 | }, |
| 2190 | 2191 | |
| 2191 | 2192 | State.TypeExprEnd => |opt_ctx| { |
| 2192 | const lhs = opt_ctx.get() ?? continue; | |
| 2193 | const lhs = opt_ctx.get() orelse continue; | |
| 2193 | 2194 | |
| 2194 | 2195 | if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| { |
| 2195 | 2196 | const node = try arena.construct(ast.Node.InfixOp{ |
| ... | ... | @@ -2269,7 +2270,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2269 | 2270 | }, |
| 2270 | 2271 | |
| 2271 | 2272 | State.SuffixOpExpressionEnd => |opt_ctx| { |
| 2272 | const lhs = opt_ctx.get() ?? continue; | |
| 2273 | const lhs = opt_ctx.get() orelse continue; | |
| 2273 | 2274 | |
| 2274 | 2275 | const token = nextToken(&tok_it, &tree); |
| 2275 | 2276 | const token_index = token.index; |
| ... | ... | @@ -2418,7 +2419,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2418 | 2419 | continue; |
| 2419 | 2420 | }, |
| 2420 | 2421 | Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => { |
| 2421 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable); | |
| 2422 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) orelse unreachable); | |
| 2422 | 2423 | continue; |
| 2423 | 2424 | }, |
| 2424 | 2425 | Token.Id.LParen => { |
| ... | ... | @@ -2648,7 +2649,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2648 | 2649 | const token = nextToken(&tok_it, &tree); |
| 2649 | 2650 | const token_index = token.index; |
| 2650 | 2651 | const token_ptr = token.ptr; |
| 2651 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? { | |
| 2652 | opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) orelse { | |
| 2652 | 2653 | prevToken(&tok_it, &tree); |
| 2653 | 2654 | if (opt_ctx != OptionalCtx.Optional) { |
| 2654 | 2655 | ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } }; |
| ... | ... | @@ -3348,7 +3349,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok |
| 3348 | 3349 | assert(result.ptr.id != Token.Id.LineComment); |
| 3349 | 3350 | |
| 3350 | 3351 | while (true) { |
| 3351 | const next_tok = tok_it.peek() ?? return result; | |
| 3352 | const next_tok = tok_it.peek() orelse return result; | |
| 3352 | 3353 | if (next_tok.id != Token.Id.LineComment) return result; |
| 3353 | 3354 | _ = tok_it.next(); |
| 3354 | 3355 | } |
| ... | ... | @@ -3356,7 +3357,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok |
| 3356 | 3357 | |
| 3357 | 3358 | fn prevToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) void { |
| 3358 | 3359 | while (true) { |
| 3359 | const prev_tok = tok_it.prev() ?? return; | |
| 3360 | const prev_tok = tok_it.prev() orelse return; | |
| 3360 | 3361 | if (prev_tok.id == Token.Id.LineComment) continue; |
| 3361 | 3362 | return; |
| 3362 | 3363 | } |
std/zig/render.zig+4-4| ... | ... | @@ -83,7 +83,7 @@ fn renderRoot( |
| 83 | 83 | var start_col: usize = 0; |
| 84 | 84 | var it = tree.root_node.decls.iterator(0); |
| 85 | 85 | while (true) { |
| 86 | var decl = (it.next() ?? return).*; | |
| 86 | var decl = (it.next() orelse return).*; | |
| 87 | 87 | // look for zig fmt: off comment |
| 88 | 88 | var start_token_index = decl.firstToken(); |
| 89 | 89 | zig_fmt_loop: while (start_token_index != 0) { |
| ... | ... | @@ -112,7 +112,7 @@ fn renderRoot( |
| 112 | 112 | const start = tree.tokens.at(start_token_index + 1).start; |
| 113 | 113 | try stream.print("{}\n", tree.source[start..end_token.end]); |
| 114 | 114 | while (tree.tokens.at(decl.firstToken()).start < end_token.end) { |
| 115 | decl = (it.next() ?? return).*; | |
| 115 | decl = (it.next() orelse return).*; | |
| 116 | 116 | } |
| 117 | 117 | break :zig_fmt_loop; |
| 118 | 118 | } |
| ... | ... | @@ -1993,7 +1993,7 @@ fn renderDocComments( |
| 1993 | 1993 | indent: usize, |
| 1994 | 1994 | start_col: *usize, |
| 1995 | 1995 | ) (@typeOf(stream).Child.Error || Error)!void { |
| 1996 | const comment = node.doc_comments ?? return; | |
| 1996 | const comment = node.doc_comments orelse return; | |
| 1997 | 1997 | var it = comment.lines.iterator(0); |
| 1998 | 1998 | const first_token = node.firstToken(); |
| 1999 | 1999 | while (it.next()) |line_token_index| { |
| ... | ... | @@ -2021,7 +2021,7 @@ fn nodeIsBlock(base: *const ast.Node) bool { |
| 2021 | 2021 | } |
| 2022 | 2022 | |
| 2023 | 2023 | fn nodeCausesSliceOpSpace(base: *ast.Node) bool { |
| 2024 | const infix_op = base.cast(ast.Node.InfixOp) ?? return false; | |
| 2024 | const infix_op = base.cast(ast.Node.InfixOp) orelse return false; | |
| 2025 | 2025 | return switch (infix_op.op) { |
| 2026 | 2026 | ast.Node.InfixOp.Op.Period => false, |
| 2027 | 2027 | else => true, |
test/cases/cast.zig+3-3| ... | ... | @@ -73,7 +73,7 @@ fn Struct(comptime T: type) type { |
| 73 | 73 | |
| 74 | 74 | fn maybePointer(self: ?*const Self) Self { |
| 75 | 75 | const none = Self{ .x = if (T == void) void{} else 0 }; |
| 76 | return (self ?? &none).*; | |
| 76 | return (self orelse &none).*; | |
| 77 | 77 | } |
| 78 | 78 | }; |
| 79 | 79 | } |
| ... | ... | @@ -87,7 +87,7 @@ const Union = union { |
| 87 | 87 | |
| 88 | 88 | fn maybePointer(self: ?*const Union) Union { |
| 89 | 89 | const none = Union{ .x = 0 }; |
| 90 | return (self ?? &none).*; | |
| 90 | return (self orelse &none).*; | |
| 91 | 91 | } |
| 92 | 92 | }; |
| 93 | 93 | |
| ... | ... | @@ -100,7 +100,7 @@ const Enum = enum { |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | fn maybePointer(self: ?*const Enum) Enum { |
| 103 | return (self ?? &Enum.None).*; | |
| 103 | return (self orelse &Enum.None).*; | |
| 104 | 104 | } |
| 105 | 105 | }; |
| 106 | 106 |
test/cases/null.zig+5-5| ... | ... | @@ -15,13 +15,13 @@ test "optional type" { |
| 15 | 15 | |
| 16 | 16 | const next_x: ?i32 = null; |
| 17 | 17 | |
| 18 | const z = next_x ?? 1234; | |
| 18 | const z = next_x orelse 1234; | |
| 19 | 19 | |
| 20 | 20 | assert(z == 1234); |
| 21 | 21 | |
| 22 | 22 | const final_x: ?i32 = 13; |
| 23 | 23 | |
| 24 | const num = final_x ?? unreachable; | |
| 24 | const num = final_x orelse unreachable; | |
| 25 | 25 | |
| 26 | 26 | assert(num == 13); |
| 27 | 27 | } |
| ... | ... | @@ -38,7 +38,7 @@ test "test maybe object and get a pointer to the inner value" { |
| 38 | 38 | |
| 39 | 39 | test "rhs maybe unwrap return" { |
| 40 | 40 | const x: ?bool = true; |
| 41 | const y = x ?? return; | |
| 41 | const y = x orelse return; | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | test "maybe return" { |
| ... | ... | @@ -53,7 +53,7 @@ fn maybeReturnImpl() void { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | fn foo(x: ?i32) ?bool { |
| 56 | const value = x ?? return null; | |
| 56 | const value = x orelse return null; | |
| 57 | 57 | return value > 1234; |
| 58 | 58 | } |
| 59 | 59 | |
| ... | ... | @@ -140,6 +140,6 @@ test "unwrap optional which is field of global var" { |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | test "null with default unwrap" { |
| 143 | const x: i32 = null ?? 1; | |
| 143 | const x: i32 = null orelse 1; | |
| 144 | 144 | assert(x == 1); |
| 145 | 145 | } |
test/compile_errors.zig+1-1| ... | ... | @@ -2296,7 +2296,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2296 | 2296 | \\ |
| 2297 | 2297 | \\ defer try canFail(); |
| 2298 | 2298 | \\ |
| 2299 | \\ const a = maybeInt() ?? return; | |
| 2299 | \\ const a = maybeInt() orelse return; | |
| 2300 | 2300 | \\} |
| 2301 | 2301 | \\ |
| 2302 | 2302 | \\fn canFail() error!void { } |
test/translate_c.zig+10-10| ... | ... | @@ -246,13 +246,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 246 | 246 | \\pub extern var fn_ptr: ?extern fn() void; |
| 247 | 247 | , |
| 248 | 248 | \\pub inline fn foo() void { |
| 249 | \\ return (??fn_ptr)(); | |
| 249 | \\ return fn_ptr.?(); | |
| 250 | 250 | \\} |
| 251 | 251 | , |
| 252 | 252 | \\pub extern var fn_ptr2: ?extern fn(c_int, f32) u8; |
| 253 | 253 | , |
| 254 | 254 | \\pub inline fn bar(arg0: c_int, arg1: f32) u8 { |
| 255 | \\ return (??fn_ptr2)(arg0, arg1); | |
| 255 | \\ return fn_ptr2.?(arg0, arg1); | |
| 256 | 256 | \\} |
| 257 | 257 | ); |
| 258 | 258 | |
| ... | ... | @@ -608,7 +608,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 608 | 608 | \\ field: c_int, |
| 609 | 609 | \\}; |
| 610 | 610 | \\pub export fn read_field(foo: ?[*]struct_Foo) c_int { |
| 611 | \\ return (??foo).field; | |
| 611 | \\ return foo.?.field; | |
| 612 | 612 | \\} |
| 613 | 613 | ); |
| 614 | 614 | |
| ... | ... | @@ -969,11 +969,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 969 | 969 | \\pub export fn bar() void { |
| 970 | 970 | \\ var f: ?extern fn() void = foo; |
| 971 | 971 | \\ var b: ?extern fn() c_int = baz; |
| 972 | \\ (??f)(); | |
| 973 | \\ (??f)(); | |
| 972 | \\ f.?(); | |
| 973 | \\ f.?(); | |
| 974 | 974 | \\ foo(); |
| 975 | \\ _ = (??b)(); | |
| 976 | \\ _ = (??b)(); | |
| 975 | \\ _ = b.?(); | |
| 976 | \\ _ = b.?(); | |
| 977 | 977 | \\ _ = baz(); |
| 978 | 978 | \\} |
| 979 | 979 | ); |
| ... | ... | @@ -984,7 +984,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 984 | 984 | \\} |
| 985 | 985 | , |
| 986 | 986 | \\pub export fn foo(x: ?[*]c_int) void { |
| 987 | \\ (??x).* = 1; | |
| 987 | \\ x.?.* = 1; | |
| 988 | 988 | \\} |
| 989 | 989 | ); |
| 990 | 990 | |
| ... | ... | @@ -1012,7 +1012,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1012 | 1012 | \\pub fn foo() c_int { |
| 1013 | 1013 | \\ var x: c_int = 1234; |
| 1014 | 1014 | \\ var ptr: ?[*]c_int = &x; |
| 1015 | \\ return (??ptr).*; | |
| 1015 | \\ return ptr.?.*; | |
| 1016 | 1016 | \\} |
| 1017 | 1017 | ); |
| 1018 | 1018 | |
| ... | ... | @@ -1119,7 +1119,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1119 | 1119 | \\pub const glClearPFN = PFNGLCLEARPROC; |
| 1120 | 1120 | , |
| 1121 | 1121 | \\pub inline fn glClearUnion(arg0: GLbitfield) void { |
| 1122 | \\ return (??glProcs.gl.Clear)(arg0); | |
| 1122 | \\ return glProcs.gl.Clear.?(arg0); | |
| 1123 | 1123 | \\} |
| 1124 | 1124 | , |
| 1125 | 1125 | \\pub const OpenGLProcs = union_OpenGLProcs; |