aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/docgen.zig1
-rw-r--r--src-self-hosted/ir.zig1
-rw-r--r--src/analyze.cpp10
-rw-r--r--src/analyze.hpp1
-rw-r--r--src/c_tokenizer.cpp7
-rw-r--r--src/codegen.cpp12
-rw-r--r--std/zig/ast.zig18
-rw-r--r--std/zig/parse.zig4
-rw-r--r--std/zig/render.zig4
-rw-r--r--std/zig/tokenizer.zig2
-rw-r--r--test/translate_c.zig42
11 files changed, 58 insertions, 44 deletions
diff --git a/doc/docgen.zig b/doc/docgen.zig
index 9ae3492841..880808de90 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -795,7 +795,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
std.zig.Token.Id.Keyword_null,
std.zig.Token.Id.Keyword_true,
std.zig.Token.Id.Keyword_false,
- std.zig.Token.Id.Keyword_this,
=> {
try out.write("<span class=\"tok-null\">");
try writeEscaped(out, src[token.start..token.end]);
diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig
index dc1b0dc943..b184a1bfee 100644
--- a/src-self-hosted/ir.zig
+++ b/src-self-hosted/ir.zig
@@ -1151,7 +1151,6 @@ pub const Builder = struct {
ast.Node.Id.BoolLiteral => return error.Unimplemented,
ast.Node.Id.NullLiteral => return error.Unimplemented,
ast.Node.Id.UndefinedLiteral => return error.Unimplemented,
- ast.Node.Id.ThisLiteral => return error.Unimplemented,
ast.Node.Id.Unreachable => return error.Unimplemented,
ast.Node.Id.Identifier => {
const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node);
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 6cbcc311ef..79a723b2e5 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -601,7 +601,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
if (child_type->zero_bits) {
entry->type_ref = LLVMInt1Type();
entry->di_type = g->builtin_types.entry_bool->di_type;
- } else if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
+ } else if (type_is_nonnull_ptr(child_type) || child_type->id == ZigTypeIdErrorSet) {
assert(child_type->di_type);
// this is an optimization but also is necessary for calling C
// functions where all pointers are maybe pointers
@@ -4145,11 +4145,7 @@ ZigType *get_codegen_ptr_type(ZigType *type) {
}
bool type_is_nonnull_ptr(ZigType *type) {
- return type_is_non_optional_pointer(type) && !ptr_allows_addr_zero(type);
-}
-
-bool type_is_non_optional_pointer(ZigType *type) {
- return get_codegen_ptr_type(type) == type;
+ return get_codegen_ptr_type(type) == type && !ptr_allows_addr_zero(type);
}
uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
@@ -4667,7 +4663,7 @@ bool handle_is_ptr(ZigType *type_entry) {
return type_has_bits(type_entry->data.error_union.payload_type);
case ZigTypeIdOptional:
return type_has_bits(type_entry->data.maybe.child_type) &&
- !type_is_non_optional_pointer(type_entry->data.maybe.child_type) &&
+ !type_is_nonnull_ptr(type_entry->data.maybe.child_type) &&
type_entry->data.maybe.child_type->id != ZigTypeIdErrorSet;
case ZigTypeIdUnion:
assert(type_entry->data.unionation.zero_bits_known);
diff --git a/src/analyze.hpp b/src/analyze.hpp
index 22e44ebd3f..3b4f6b7118 100644
--- a/src/analyze.hpp
+++ b/src/analyze.hpp
@@ -60,7 +60,6 @@ ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **c
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name);
void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
-bool type_is_non_optional_pointer(ZigType *type);
ZigType *get_src_ptr_type(ZigType *type);
ZigType *get_codegen_ptr_type(ZigType *type);
diff --git a/src/c_tokenizer.cpp b/src/c_tokenizer.cpp
index 3746cf5853..40ae8ceafe 100644
--- a/src/c_tokenizer.cpp
+++ b/src/c_tokenizer.cpp
@@ -362,6 +362,13 @@ void tokenize_c_macro(CTokenize *ctok, const uint8_t *c) {
ctok->cur_tok->id = CTokIdNumLitFloat;
buf_append_char(&ctok->buf, '.');
break;
+ case 'l':
+ case 'L':
+ case 'u':
+ case 'U':
+ c -= 1;
+ ctok->state = CTokStateDecimal;
+ continue;
default:
c -= 1;
ctok->state = CTokStateOctal;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 0620eb49d7..b996c2367a 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -3948,10 +3948,10 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
assert(maybe_type->id == ZigTypeIdOptional);
ZigType *child_type = maybe_type->data.maybe.child_type;
- if (child_type->zero_bits) {
+ if (!type_has_bits(child_type)) {
return maybe_handle;
} else {
- bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
+ bool is_scalar = !handle_is_ptr(maybe_type);
if (is_scalar) {
return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), "");
} else {
@@ -3991,7 +3991,7 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
if (child_type->zero_bits) {
return nullptr;
} else {
- bool is_scalar = type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet;
+ bool is_scalar = !handle_is_ptr(maybe_type);
if (is_scalar) {
return maybe_ptr;
} else {
@@ -4854,7 +4854,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
}
LLVMValueRef payload_val = ir_llvm_value(g, instruction->value);
- if (type_is_non_optional_pointer(child_type) || child_type->id == ZigTypeIdErrorSet) {
+ if (!handle_is_ptr(wanted_type)) {
return payload_val;
}
@@ -8690,10 +8690,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
case ZigTypeIdOptional:
{
ZigType *child_type = type_entry->data.maybe.child_type;
- if (child_type->zero_bits) {
+ if (!type_has_bits(child_type)) {
buf_init_from_str(out_buf, "bool");
return;
- } else if (type_is_non_optional_pointer(child_type)) {
+ } else if (type_is_nonnull_ptr(child_type)) {
return get_c_type(g, gen_h, child_type, out_buf);
} else {
zig_unreachable();
diff --git a/std/zig/ast.zig b/std/zig/ast.zig
index 421c657619..77daeb16e1 100644
--- a/std/zig/ast.zig
+++ b/std/zig/ast.zig
@@ -302,7 +302,6 @@ pub const Node = struct {
BoolLiteral,
NullLiteral,
UndefinedLiteral,
- ThisLiteral,
Unreachable,
Identifier,
GroupedExpression,
@@ -1997,23 +1996,6 @@ pub const Node = struct {
}
};
- pub const ThisLiteral = struct {
- base: Node,
- token: TokenIndex,
-
- pub fn iterate(self: *ThisLiteral, index: usize) ?*Node {
- return null;
- }
-
- pub fn firstToken(self: *const ThisLiteral) TokenIndex {
- return self.token;
- }
-
- pub fn lastToken(self: *const ThisLiteral) TokenIndex {
- return self.token;
- }
- };
-
pub const AsmOutput = struct {
base: Node,
lbracket: TokenIndex,
diff --git a/std/zig/parse.zig b/std/zig/parse.zig
index e957d1d3e1..7ab656413f 100644
--- a/std/zig/parse.zig
+++ b/std/zig/parse.zig
@@ -2563,10 +2563,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
_ = try createToCtxLiteral(arena, opt_ctx, ast.Node.NullLiteral, token.index);
continue;
},
- Token.Id.Keyword_this => {
- _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.ThisLiteral, token.index);
- continue;
- },
Token.Id.Keyword_var => {
_ = try createToCtxLiteral(arena, opt_ctx, ast.Node.VarType, token.index);
continue;
diff --git a/std/zig/render.zig b/std/zig/render.zig
index 50e928c0d8..3adf67c23b 100644
--- a/std/zig/render.zig
+++ b/std/zig/render.zig
@@ -880,10 +880,6 @@ fn renderExpression(
const null_literal = @fieldParentPtr(ast.Node.NullLiteral, "base", base);
return renderToken(tree, stream, null_literal.token, indent, start_col, space);
},
- ast.Node.Id.ThisLiteral => {
- const this_literal = @fieldParentPtr(ast.Node.ThisLiteral, "base", base);
- return renderToken(tree, stream, this_literal.token, indent, start_col, space);
- },
ast.Node.Id.Unreachable => {
const unreachable_node = @fieldParentPtr(ast.Node.Unreachable, "base", base);
return renderToken(tree, stream, unreachable_node.token, indent, start_col, space);
diff --git a/std/zig/tokenizer.zig b/std/zig/tokenizer.zig
index 79fd1c5612..2159371ccf 100644
--- a/std/zig/tokenizer.zig
+++ b/std/zig/tokenizer.zig
@@ -52,7 +52,6 @@ pub const Token = struct {
Keyword{ .bytes = "suspend", .id = Id.Keyword_suspend },
Keyword{ .bytes = "switch", .id = Id.Keyword_switch },
Keyword{ .bytes = "test", .id = Id.Keyword_test },
- Keyword{ .bytes = "this", .id = Id.Keyword_this },
Keyword{ .bytes = "threadlocal", .id = Id.Keyword_threadlocal },
Keyword{ .bytes = "true", .id = Id.Keyword_true },
Keyword{ .bytes = "try", .id = Id.Keyword_try },
@@ -183,7 +182,6 @@ pub const Token = struct {
Keyword_suspend,
Keyword_switch,
Keyword_test,
- Keyword_this,
Keyword_threadlocal,
Keyword_true,
Keyword_try,
diff --git a/test/translate_c.zig b/test/translate_c.zig
index eabd01ef62..f5eeceff95 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -1425,6 +1425,48 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn bar() void {}
);
+ cases.addC("u integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0U"
+ ,
+ "pub const ZERO = c_uint(0);"
+ );
+
+ cases.addC("l integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0L"
+ ,
+ "pub const ZERO = c_long(0);"
+ );
+
+ cases.addC("ul integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0UL"
+ ,
+ "pub const ZERO = c_ulong(0);"
+ );
+
+ cases.addC("lu integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0LU"
+ ,
+ "pub const ZERO = c_ulong(0);"
+ );
+
+ cases.addC("ll integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0LL"
+ ,
+ "pub const ZERO = c_longlong(0);"
+ );
+
+ cases.addC("ull integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0ULL"
+ ,
+ "pub const ZERO = c_ulonglong(0);"
+ );
+
+ cases.addC("llu integer suffix after 0 (zero) in macro definition",
+ "#define ZERO 0LLU"
+ ,
+ "pub const ZERO = c_ulonglong(0);"
+ );
+
// cases.add("empty array with initializer",
// "int a[4] = {};"
// ,