| author | |
| committer | |
| log | 4cb55d3af6a71467b7d4399bedb961c81e9ad3d5 |
| tree | bab3cda68f650e04b453d2fcfa6853e0af840c05 |
| parent | b63b3dc75690b016309b19c9f91f454f5f7bf4bb |
| parent | fec4555476e38d2eeb1dfb02572404b243acd0b2 |
11 files changed, 58 insertions(+), 44 deletions(-)
doc/docgen.zig-1| ... | ... | @@ -795,7 +795,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 795 | 795 | std.zig.Token.Id.Keyword_null, |
| 796 | 796 | std.zig.Token.Id.Keyword_true, |
| 797 | 797 | std.zig.Token.Id.Keyword_false, |
| 798 | std.zig.Token.Id.Keyword_this, | |
| 799 | 798 | => { |
| 800 | 799 | try out.write("<span class=\"tok-null\">"); |
| 801 | 800 | try writeEscaped(out, src[token.start..token.end]); |
src-self-hosted/ir.zig-1| ... | ... | @@ -1151,7 +1151,6 @@ pub const Builder = struct { |
| 1151 | 1151 | ast.Node.Id.BoolLiteral => return error.Unimplemented, |
| 1152 | 1152 | ast.Node.Id.NullLiteral => return error.Unimplemented, |
| 1153 | 1153 | ast.Node.Id.UndefinedLiteral => return error.Unimplemented, |
| 1154 | ast.Node.Id.ThisLiteral => return error.Unimplemented, | |
| 1155 | 1154 | ast.Node.Id.Unreachable => return error.Unimplemented, |
| 1156 | 1155 | ast.Node.Id.Identifier => { |
| 1157 | 1156 | const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node); |
src/analyze.cpp+3-7| ... | ... | @@ -601,7 +601,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { |
| 601 | 601 | if (child_type->zero_bits) { |
| 602 | 602 | entry->type_ref = LLVMInt1Type(); |
| 603 | 603 | entry->di_type = g->builtin_types.entry_bool->di_type; |
| 604 | } else if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { | |
| 604 | } else if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) { | |
| 605 | 605 | assert(child_type->di_type); |
| 606 | 606 | // this is an optimization but also is necessary for calling C |
| 607 | 607 | // functions where all pointers are maybe pointers |
| ... | ... | @@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) { |
| 4145 | 4145 | } |
| 4146 | 4146 | |
| 4147 | 4147 | bool type_is_nonnull_ptr(ZigType *type) { |
| 4148 | return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type); | |
| 4149 | } | |
| 4150 | ||
| 4151 | bool type_is_non_optional_pointer(ZigType *type) { | |
| 4152 | return get_codegen_ptr_type(type) == type; | |
| 4148 | return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type); | |
| 4153 | 4149 | } |
| 4154 | 4150 | |
| 4155 | 4151 | uint32_t get_ptr_align(CodeGen *g, ZigType *type) { |
| ... | ... | @@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) { |
| 4667 | 4663 | return type_has_bits(type_entry->data.error_union.payload_type); |
| 4668 | 4664 | case ZigTypeIdOptional: |
| 4669 | 4665 | return type_has_bits(type_entry->data.maybe.child_type) && |
| 4670 | !type_is_non_optional_pointer(type_entry->data.maybe.child_type) && | |
| 4666 | !type_is_nonnull_ptr(type_entry->data.maybe.child_type) && | |
| 4671 | 4667 | type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet; |
| 4672 | 4668 | case ZigTypeIdUnion: |
| 4673 | 4669 | assert(type_entry->data.unionation.zero_bits_known); |
src/analyze.hpp-1| ... | ... | @@ -60,7 +60,6 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c |
| 60 | 60 | Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); |
| 61 | 61 | Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name); |
| 62 | 62 | void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node); |
| 63 | bool type_is_non_optional_pointer(ZigType *type); | |
| 64 | 63 | |
| 65 | 64 | ZigType *get_src_ptr_type(ZigType *type); |
| 66 | 65 | ZigType *get_codegen_ptr_type(ZigType *type); |
src/c_tokenizer.cpp+7| ... | ... | @@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) { |
| 362 | 362 | ctok->cur_tok->id = CTokIdNumLitFloat; |
| 363 | 363 | buf_append_char(&ctok->buf, '.'); |
| 364 | 364 | break; |
| 365 | case 'l': | |
| 366 | case 'L': | |
| 367 | case 'u': | |
| 368 | case 'U': | |
| 369 | c -= 1; | |
| 370 | ctok->state = CTokStateDecimal; | |
| 371 | continue; | |
| 365 | 372 | default: |
| 366 | 373 | c -= 1; |
| 367 | 374 | ctok->state = CTokStateOctal; |
src/codegen.cpp+6-6| ... | ... | @@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru |
| 3948 | 3948 | static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) { |
| 3949 | 3949 | assert(maybe_type->id == ZigTypeIdOptional); |
| 3950 | 3950 | ZigType *child_type = maybe_type->data.maybe.child_type; |
| 3951 | if (child_type->zero_bits) { | |
| 3951 | if (!type_has_bits(child_type)) { | |
| 3952 | 3952 | return maybe_handle; |
| 3953 | 3953 | } else { |
| 3954 | bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; | |
| 3954 | bool is_scalar = !handle_is_ptr(maybe_type); | |
| 3955 | 3955 | if (is_scalar) { |
| 3956 | 3956 | return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), ""); |
| 3957 | 3957 | } else { |
| ... | ... | @@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec |
| 3991 | 3991 | if (child_type->zero_bits) { |
| 3992 | 3992 | return nullptr; |
| 3993 | 3993 | } else { |
| 3994 | bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet; | |
| 3994 | bool is_scalar = !handle_is_ptr(maybe_type); | |
| 3995 | 3995 | if (is_scalar) { |
| 3996 | 3996 | return maybe_ptr; |
| 3997 | 3997 | } else { |
| ... | ... | @@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I |
| 4854 | 4854 | } |
| 4855 | 4855 | |
| 4856 | 4856 | LLVMValueRef payload_val = ir_llvm_value(g, instruction->value); |
| 4857 | if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) { | |
| 4857 | if (!handle_is_ptr(wanted_type)) { | |
| 4858 | 4858 | return payload_val; |
| 4859 | 4859 | } |
| 4860 | 4860 | |
| ... | ... | @@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu |
| 8690 | 8690 | case ZigTypeIdOptional: |
| 8691 | 8691 | { |
| 8692 | 8692 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 8693 | if (child_type->zero_bits) { | |
| 8693 | if (!type_has_bits(child_type)) { | |
| 8694 | 8694 | buf_init_from_str(out_buf, "bool"); |
| 8695 | 8695 | return; |
| 8696 | } else if (type_is_non_optional_pointer(child_type)) { | |
| 8696 | } else if (type_is_nonnull_ptr(child_type)) { | |
| 8697 | 8697 | return get_c_type(g, gen_h, child_type, out_buf); |
| 8698 | 8698 | } else { |
| 8699 | 8699 | zig_unreachable(); |
std/zig/ast.zig-18| ... | ... | @@ -302,7 +302,6 @@ pub const Node = struct { |
| 302 | 302 | BoolLiteral, |
| 303 | 303 | NullLiteral, |
| 304 | 304 | UndefinedLiteral, |
| 305 | ThisLiteral, | |
| 306 | 305 | Unreachable, |
| 307 | 306 | Identifier, |
| 308 | 307 | GroupedExpression, |
| ... | ... | @@ -1997,23 +1996,6 @@ pub const Node = struct { |
| 1997 | 1996 | } |
| 1998 | 1997 | }; |
| 1999 | 1998 | |
| 2000 | pub const ThisLiteral = struct { | |
| 2001 | base: Node, | |
| 2002 | token: TokenIndex, | |
| 2003 | ||
| 2004 | pub fn iterate(self: *ThisLiteral, index: usize) ?*Node { | |
| 2005 | return null; | |
| 2006 | } | |
| 2007 | ||
| 2008 | pub fn firstToken(self: *const ThisLiteral) TokenIndex { | |
| 2009 | return self.token; | |
| 2010 | } | |
| 2011 | ||
| 2012 | pub fn lastToken(self: *const ThisLiteral) TokenIndex { | |
| 2013 | return self.token; | |
| 2014 | } | |
| 2015 | }; | |
| 2016 | ||
| 2017 | 1999 | pub const AsmOutput = struct { |
| 2018 | 2000 | base: Node, |
| 2019 | 2001 | lbracket: TokenIndex, |
std/zig/parse.zig-4| ... | ... | @@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 2563 | 2563 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index); |
| 2564 | 2564 | continue; |
| 2565 | 2565 | }, |
| 2566 | Token.Id.Keyword_this => { | |
| 2567 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.ThisLiteral, token.index); | |
| 2568 | continue; | |
| 2569 | }, | |
| 2570 | 2566 | Token.Id.Keyword_var => { |
| 2571 | 2567 | _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index); |
| 2572 | 2568 | continue; |
std/zig/render.zig-4| ... | ... | @@ -880,10 +880,6 @@ fn renderExpression( |
| 880 | 880 | const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base); |
| 881 | 881 | return renderToken(tree, stream, null_literal.token, indent, start_col, space); |
| 882 | 882 | }, |
| 883 | ast.Node.Id.ThisLiteral => { | |
| 884 | const this_literal = @fieldParentPtr(ast.Node.ThisLiteral, "base", base); | |
| 885 | return renderToken(tree, stream, this_literal.token, indent, start_col, space); | |
| 886 | }, | |
| 887 | 883 | ast.Node.Id.Unreachable => { |
| 888 | 884 | const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base); |
| 889 | 885 | return renderToken(tree, stream, unreachable_node.token, indent, start_col, space); |
std/zig/tokenizer.zig-2| ... | ... | @@ -52,7 +52,6 @@ pub const Token = struct { |
| 52 | 52 | Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend }, |
| 53 | 53 | Keyword{ .bytes = "switch", .id = Id.Keyword_switch }, |
| 54 | 54 | Keyword{ .bytes = "test", .id = Id.Keyword_test }, |
| 55 | Keyword{ .bytes = "this", .id = Id.Keyword_this }, | |
| 56 | 55 | Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal }, |
| 57 | 56 | Keyword{ .bytes = "true", .id = Id.Keyword_true }, |
| 58 | 57 | Keyword{ .bytes = "try", .id = Id.Keyword_try }, |
| ... | ... | @@ -183,7 +182,6 @@ pub const Token = struct { |
| 183 | 182 | Keyword_suspend, |
| 184 | 183 | Keyword_switch, |
| 185 | 184 | Keyword_test, |
| 186 | Keyword_this, | |
| 187 | 185 | Keyword_threadlocal, |
| 188 | 186 | Keyword_true, |
| 189 | 187 | Keyword_try, |
test/translate_c.zig+42| ... | ... | @@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1425 | 1425 | \\pub export fn bar() void {} |
| 1426 | 1426 | ); |
| 1427 | 1427 | |
| 1428 | cases.addC("u integer suffix after 0 (zero) in macro definition", | |
| 1429 | "#define ZERO 0U" | |
| 1430 | , | |
| 1431 | "pub const ZERO = c_uint(0);" | |
| 1432 | ); | |
| 1433 | ||
| 1434 | cases.addC("l integer suffix after 0 (zero) in macro definition", | |
| 1435 | "#define ZERO 0L" | |
| 1436 | , | |
| 1437 | "pub const ZERO = c_long(0);" | |
| 1438 | ); | |
| 1439 | ||
| 1440 | cases.addC("ul integer suffix after 0 (zero) in macro definition", | |
| 1441 | "#define ZERO 0UL" | |
| 1442 | , | |
| 1443 | "pub const ZERO = c_ulong(0);" | |
| 1444 | ); | |
| 1445 | ||
| 1446 | cases.addC("lu integer suffix after 0 (zero) in macro definition", | |
| 1447 | "#define ZERO 0LU" | |
| 1448 | , | |
| 1449 | "pub const ZERO = c_ulong(0);" | |
| 1450 | ); | |
| 1451 | ||
| 1452 | cases.addC("ll integer suffix after 0 (zero) in macro definition", | |
| 1453 | "#define ZERO 0LL" | |
| 1454 | , | |
| 1455 | "pub const ZERO = c_longlong(0);" | |
| 1456 | ); | |
| 1457 | ||
| 1458 | cases.addC("ull integer suffix after 0 (zero) in macro definition", | |
| 1459 | "#define ZERO 0ULL" | |
| 1460 | , | |
| 1461 | "pub const ZERO = c_ulonglong(0);" | |
| 1462 | ); | |
| 1463 | ||
| 1464 | cases.addC("llu integer suffix after 0 (zero) in macro definition", | |
| 1465 | "#define ZERO 0LLU" | |
| 1466 | , | |
| 1467 | "pub const ZERO = c_ulonglong(0);" | |
| 1468 | ); | |
| 1469 | ||
| 1428 | 1470 | // cases.add("empty array with initializer", |
| 1429 | 1471 | // "int a[4] = {};" |
| 1430 | 1472 | // , |