authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-10 01:18:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-10 01:18:31-04:00
log0a95b0f1ffeb8ae5ee317b02626890adebe5ec63
treeb81af85f0e9ba611aa24ae8b1c855095f5c8f9e8
parent77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4

std.zig: update syntax for orelse keyword


4 files changed, 9 insertions(+), 38 deletions(-)

src/ir.cpp-16
...@@ -14842,22 +14842,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14842,22 +14842,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14842 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;14842 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14843 if (type_is_invalid(type_entry)) {14843 if (type_is_invalid(type_entry)) {
14844 return ira->codegen->builtin_types.entry_invalid;14844 return ira->codegen->builtin_types.entry_invalid;
14845 } else if (type_entry->id == TypeTableEntryIdMetaType) {
14846 // surprise! actually this is just ??T not an unwrap maybe instruction
14847 ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
14848 assert(ptr_val->type->id == TypeTableEntryIdMetaType);
14849 TypeTableEntry *child_type = ptr_val->data.x_type;
14850
14851 type_ensure_zero_bits_known(ira->codegen, child_type);
14852 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
14853 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
14854
14855 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
14856 unwrap_maybe_instruction->base.source_node, layer2);
14857 IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
14858 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14859 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
14860 return result_instr->value.type;
14861 } else if (type_entry->id != TypeTableEntryIdOptional) {14845 } else if (type_entry->id != TypeTableEntryIdOptional) {
14862 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,14846 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
14863 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));14847 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
std/zig/parse.zig+1-1
...@@ -3248,7 +3248,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {...@@ -3248,7 +3248,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
3248fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {3248fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
3249 return switch (id) {3249 return switch (id) {
3250 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },3250 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },
3251 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },3251 Token.Id.Keyword_orelse => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
3252 else => null,3252 else => null,
3253 };3253 };
3254}3254}
std/zig/parser_test.zig+1-1
...@@ -1151,7 +1151,7 @@ test "zig fmt: infix operators" {...@@ -1151,7 +1151,7 @@ test "zig fmt: infix operators" {
1151 \\ _ = i!i;1151 \\ _ = i!i;
1152 \\ _ = i ** i;1152 \\ _ = i ** i;
1153 \\ _ = i ++ i;1153 \\ _ = i ++ i;
1154 \\ _ = i ?? i;1154 \\ _ = i orelse i;
1155 \\ _ = i % i;1155 \\ _ = i % i;
1156 \\ _ = i / i;1156 \\ _ = i / i;
1157 \\ _ = i *% i;1157 \\ _ = i *% i;
std/zig/tokenizer.zig+7-20
...@@ -39,6 +39,7 @@ pub const Token = struct {...@@ -39,6 +39,7 @@ pub const Token = struct {
39 Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },39 Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },
40 Keyword{ .bytes = "null", .id = Id.Keyword_null },40 Keyword{ .bytes = "null", .id = Id.Keyword_null },
41 Keyword{ .bytes = "or", .id = Id.Keyword_or },41 Keyword{ .bytes = "or", .id = Id.Keyword_or },
42 Keyword{ .bytes = "orelse", .id = Id.Keyword_orelse },
42 Keyword{ .bytes = "packed", .id = Id.Keyword_packed },43 Keyword{ .bytes = "packed", .id = Id.Keyword_packed },
43 Keyword{ .bytes = "promise", .id = Id.Keyword_promise },44 Keyword{ .bytes = "promise", .id = Id.Keyword_promise },
44 Keyword{ .bytes = "pub", .id = Id.Keyword_pub },45 Keyword{ .bytes = "pub", .id = Id.Keyword_pub },
...@@ -129,7 +130,6 @@ pub const Token = struct {...@@ -129,7 +130,6 @@ pub const Token = struct {
129 Ampersand,130 Ampersand,
130 AmpersandEqual,131 AmpersandEqual,
131 QuestionMark,132 QuestionMark,
132 QuestionMarkQuestionMark,
133 AngleBracketLeft,133 AngleBracketLeft,
134 AngleBracketLeftEqual,134 AngleBracketLeftEqual,
135 AngleBracketAngleBracketLeft,135 AngleBracketAngleBracketLeft,
...@@ -171,6 +171,7 @@ pub const Token = struct {...@@ -171,6 +171,7 @@ pub const Token = struct {
171 Keyword_noalias,171 Keyword_noalias,
172 Keyword_null,172 Keyword_null,
173 Keyword_or,173 Keyword_or,
174 Keyword_orelse,
174 Keyword_packed,175 Keyword_packed,
175 Keyword_promise,176 Keyword_promise,
176 Keyword_pub,177 Keyword_pub,
...@@ -254,7 +255,6 @@ pub const Tokenizer = struct {...@@ -254,7 +255,6 @@ pub const Tokenizer = struct {
254 Ampersand,255 Ampersand,
255 Caret,256 Caret,
256 Percent,257 Percent,
257 QuestionMark,
258 Plus,258 Plus,
259 PlusPercent,259 PlusPercent,
260 AngleBracketLeft,260 AngleBracketLeft,
...@@ -345,6 +345,11 @@ pub const Tokenizer = struct {...@@ -345,6 +345,11 @@ pub const Tokenizer = struct {
345 self.index += 1;345 self.index += 1;
346 break;346 break;
347 },347 },
348 '?' => {
349 result.id = Token.Id.QuestionMark;
350 self.index += 1;
351 break;
352 },
348 ':' => {353 ':' => {
349 result.id = Token.Id.Colon;354 result.id = Token.Id.Colon;
350 self.index += 1;355 self.index += 1;
...@@ -359,9 +364,6 @@ pub const Tokenizer = struct {...@@ -359,9 +364,6 @@ pub const Tokenizer = struct {
359 '+' => {364 '+' => {
360 state = State.Plus;365 state = State.Plus;
361 },366 },
362 '?' => {
363 state = State.QuestionMark;
364 },
365 '<' => {367 '<' => {
366 state = State.AngleBracketLeft;368 state = State.AngleBracketLeft;
367 },369 },
...@@ -496,18 +498,6 @@ pub const Tokenizer = struct {...@@ -496,18 +498,6 @@ pub const Tokenizer = struct {
496 },498 },
497 },499 },
498500
499 State.QuestionMark => switch (c) {
500 '?' => {
501 result.id = Token.Id.QuestionMarkQuestionMark;
502 self.index += 1;
503 break;
504 },
505 else => {
506 result.id = Token.Id.QuestionMark;
507 break;
508 },
509 },
510
511 State.Percent => switch (c) {501 State.Percent => switch (c) {
512 '=' => {502 '=' => {
513 result.id = Token.Id.PercentEqual;503 result.id = Token.Id.PercentEqual;
...@@ -1084,9 +1074,6 @@ pub const Tokenizer = struct {...@@ -1084,9 +1074,6 @@ pub const Tokenizer = struct {
1084 State.Plus => {1074 State.Plus => {
1085 result.id = Token.Id.Plus;1075 result.id = Token.Id.Plus;
1086 },1076 },
1087 State.QuestionMark => {
1088 result.id = Token.Id.QuestionMark;
1089 },
1090 State.Percent => {1077 State.Percent => {
1091 result.id = Token.Id.Percent;1078 result.id = Token.Id.Percent;
1092 },1079 },