| author | |
| committer | |
| log | 8b7539bd9554d25599ccff6f0e9ea79aa051946b |
| tree | 9157fafcbe37f904346fd73042be1d1d299d4da2 |
| parent | b5a36f676b1fd69f195d9f1eb6e35f3eb2f15946 |
| parent | b02341d6f58e0b8a87fc2ab589dcfd85e5dc96cd |
Conflicts:
src/clang.zig
Master branch renamed an enum; this branch gave it an explicit tag type
and explicitly initialized values. This commit combines the changes
together.45 files changed, 2689 insertions(+), 1445 deletions(-)
doc/docgen.zig+1| ... | @@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: | ... | @@ -808,6 +808,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: |
| 808 | .Keyword_noalias, | 808 | .Keyword_noalias, |
| 809 | .Keyword_noinline, | 809 | .Keyword_noinline, |
| 810 | .Keyword_nosuspend, | 810 | .Keyword_nosuspend, |
| 811 | .Keyword_opaque, | ||
| 811 | .Keyword_or, | 812 | .Keyword_or, |
| 812 | .Keyword_orelse, | 813 | .Keyword_orelse, |
| 813 | .Keyword_packed, | 814 | .Keyword_packed, |
doc/langref.html.in+11-9| ... | @@ -1988,7 +1988,7 @@ test "null terminated array" { | ... | @@ -1988,7 +1988,7 @@ test "null terminated array" { |
| 1988 | <li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li> | 1988 | <li>Supports slice syntax: {#syntax#}ptr[start..end]{#endsyntax#}</li> |
| 1989 | <li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li> | 1989 | <li>Supports pointer arithmetic: {#syntax#}ptr + x{#endsyntax#}, {#syntax#}ptr - x{#endsyntax#}</li> |
| 1990 | <li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be | 1990 | <li>{#syntax#}T{#endsyntax#} must have a known size, which means that it cannot be |
| 1991 | {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|Opaque Types#}.</li> | 1991 | {#syntax#}c_void{#endsyntax#} or any other {#link|opaque type|opaque#}.</li> |
| 1992 | </ul> | 1992 | </ul> |
| 1993 | </li> | 1993 | </li> |
| 1994 | </ul> | 1994 | </ul> |
| ... | @@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" { | ... | @@ -5545,7 +5545,7 @@ test "turn HashMap into a set with void" { |
| 5545 | </p> | 5545 | </p> |
| 5546 | <p> | 5546 | <p> |
| 5547 | {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this: | 5547 | {#syntax#}void{#endsyntax#} is distinct from {#syntax#}c_void{#endsyntax#}, which is defined like this: |
| 5548 | {#syntax#}pub const c_void = @Type(.Opaque);{#endsyntax#}. | 5548 | {#syntax#}pub const c_void = opaque {};{#endsyntax#}. |
| 5549 | {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size. | 5549 | {#syntax#}void{#endsyntax#} has a known size of 0 bytes, and {#syntax#}c_void{#endsyntax#} has an unknown, but non-zero, size. |
| 5550 | </p> | 5550 | </p> |
| 5551 | <p> | 5551 | <p> |
| ... | @@ -8471,7 +8471,7 @@ test "integer truncation" { | ... | @@ -8471,7 +8471,7 @@ test "integer truncation" { |
| 8471 | <li>{#link|Error Set Type#}</li> | 8471 | <li>{#link|Error Set Type#}</li> |
| 8472 | <li>{#link|Error Union Type#}</li> | 8472 | <li>{#link|Error Union Type#}</li> |
| 8473 | <li>{#link|Vectors#}</li> | 8473 | <li>{#link|Vectors#}</li> |
| 8474 | <li>{#link|Opaque Types#}</li> | 8474 | <li>{#link|opaque#}</li> |
| 8475 | <li>{#link|@Frame#}</li> | 8475 | <li>{#link|@Frame#}</li> |
| 8476 | <li>{#syntax#}anyframe{#endsyntax#}</li> | 8476 | <li>{#syntax#}anyframe{#endsyntax#}</li> |
| 8477 | <li>{#link|struct#}</li> | 8477 | <li>{#link|struct#}</li> |
| ... | @@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T { | ... | @@ -8547,17 +8547,18 @@ fn foo(comptime T: type, ptr: *T) T { |
| 8547 | {#header_close#} | 8547 | {#header_close#} |
| 8548 | {#header_close#} | 8548 | {#header_close#} |
| 8549 | 8549 | ||
| 8550 | {#header_open|Opaque Types#} | 8550 | {#header_open|opaque#} |
| 8551 | <p> | 8551 | <p> |
| 8552 | {#syntax#}@Type(.Opaque){#endsyntax#} creates a new type with an unknown (but non-zero) size and alignment. | 8552 | {#syntax#}opaque {}{#endsyntax#} declares a new type with an unknown (but non-zero) size and alignment. |
| 8553 | It can have declarations like structs, unions, or enums. | ||
| 8553 | </p> | 8554 | </p> |
| 8554 | <p> | 8555 | <p> |
| 8555 | This is typically used for type safety when interacting with C code that does not expose struct details. | 8556 | This is typically used for type safety when interacting with C code that does not expose struct details. |
| 8556 | Example: | 8557 | Example: |
| 8557 | </p> | 8558 | </p> |
| 8558 | {#code_begin|test_err|expected type '*Derp', found '*Wat'#} | 8559 | {#code_begin|test_err|expected type '*Derp', found '*Wat'#} |
| 8559 | const Derp = @Type(.Opaque); | 8560 | const Derp = opaque {}; |
| 8560 | const Wat = @Type(.Opaque); | 8561 | const Wat = opaque {}; |
| 8561 | 8562 | ||
| 8562 | extern fn bar(d: *Derp) void; | 8563 | extern fn bar(d: *Derp) void; |
| 8563 | fn foo(w: *Wat) callconv(.C) void { | 8564 | fn foo(w: *Wat) callconv(.C) void { |
| ... | @@ -11193,7 +11194,7 @@ PtrTypeStart | ... | @@ -11193,7 +11194,7 @@ PtrTypeStart |
| 11193 | ContainerDeclAuto &lt;- ContainerDeclType LBRACE ContainerMembers RBRACE | 11194 | ContainerDeclAuto &lt;- ContainerDeclType LBRACE ContainerMembers RBRACE |
| 11194 | 11195 | ||
| 11195 | ContainerDeclType | 11196 | ContainerDeclType |
| 11196 | &lt;- (KEYWORD_struct / KEYWORD_enum) (LPAREN Expr RPAREN)? | 11197 | &lt;- (KEYWORD_struct / KEYWORD_enum / KEYWORD_opaque) (LPAREN Expr RPAREN)? |
| 11197 | / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? | 11198 | / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? |
| 11198 | 11199 | ||
| 11199 | # Alignment | 11200 | # Alignment |
| ... | @@ -11340,6 +11341,7 @@ KEYWORD_inline &lt;- 'inline' end_of_word | ... | @@ -11340,6 +11341,7 @@ KEYWORD_inline &lt;- 'inline' end_of_word |
| 11340 | KEYWORD_noalias &lt;- 'noalias' end_of_word | 11341 | KEYWORD_noalias &lt;- 'noalias' end_of_word |
| 11341 | KEYWORD_nosuspend &lt;- 'nosuspend' end_of_word | 11342 | KEYWORD_nosuspend &lt;- 'nosuspend' end_of_word |
| 11342 | KEYWORD_null &lt;- 'null' end_of_word | 11343 | KEYWORD_null &lt;- 'null' end_of_word |
| 11344 | KEYWORD_opaque &lt;- 'opaque' end_of_word | ||
| 11343 | KEYWORD_or &lt;- 'or' end_of_word | 11345 | KEYWORD_or &lt;- 'or' end_of_word |
| 11344 | KEYWORD_orelse &lt;- 'orelse' end_of_word | 11346 | KEYWORD_orelse &lt;- 'orelse' end_of_word |
| 11345 | KEYWORD_packed &lt;- 'packed' end_of_word | 11347 | KEYWORD_packed &lt;- 'packed' end_of_word |
| ... | @@ -11368,7 +11370,7 @@ keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_anyframe / KEYWORD_anytype | ... | @@ -11368,7 +11370,7 @@ keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_anyframe / KEYWORD_anytype |
| 11368 | / KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer | 11370 | / KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer |
| 11369 | / KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false | 11371 | / KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false |
| 11370 | / KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline | 11372 | / KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline |
| 11371 | / KEYWORD_noalias / KEYWORD_null / KEYWORD_or | 11373 | / KEYWORD_noalias / KEYWORD_null / KEYWORD_opaque / KEYWORD_or |
| 11372 | / KEYWORD_orelse / KEYWORD_packed / KEYWORD_pub | 11374 | / KEYWORD_orelse / KEYWORD_packed / KEYWORD_pub |
| 11373 | / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection | 11375 | / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection |
| 11374 | / KEYWORD_struct / KEYWORD_suspend | 11376 | / KEYWORD_struct / KEYWORD_suspend |
lib/std/builtin.zig+7-2| ... | @@ -151,7 +151,6 @@ pub const Mode = enum { | ... | @@ -151,7 +151,6 @@ pub const Mode = enum { |
| 151 | pub const CallingConvention = enum { | 151 | pub const CallingConvention = enum { |
| 152 | Unspecified, | 152 | Unspecified, |
| 153 | C, | 153 | C, |
| 154 | Cold, | ||
| 155 | Naked, | 154 | Naked, |
| 156 | Async, | 155 | Async, |
| 157 | Interrupt, | 156 | Interrupt, |
| ... | @@ -199,7 +198,7 @@ pub const TypeInfo = union(enum) { | ... | @@ -199,7 +198,7 @@ pub const TypeInfo = union(enum) { |
| 199 | Union: Union, | 198 | Union: Union, |
| 200 | Fn: Fn, | 199 | Fn: Fn, |
| 201 | BoundFn: Fn, | 200 | BoundFn: Fn, |
| 202 | Opaque: void, | 201 | Opaque: Opaque, |
| 203 | Frame: Frame, | 202 | Frame: Frame, |
| 204 | AnyFrame: AnyFrame, | 203 | AnyFrame: AnyFrame, |
| 205 | Vector: Vector, | 204 | Vector: Vector, |
| ... | @@ -360,6 +359,12 @@ pub const TypeInfo = union(enum) { | ... | @@ -360,6 +359,12 @@ pub const TypeInfo = union(enum) { |
| 360 | args: []const FnArg, | 359 | args: []const FnArg, |
| 361 | }; | 360 | }; |
| 362 | 361 | ||
| 362 | /// This data structure is used by the Zig language code generation and | ||
| 363 | /// therefore must be kept in sync with the compiler implementation. | ||
| 364 | pub const Opaque = struct { | ||
| 365 | decls: []const Declaration, | ||
| 366 | }; | ||
| 367 | |||
| 363 | /// This data structure is used by the Zig language code generation and | 368 | /// This data structure is used by the Zig language code generation and |
| 364 | /// therefore must be kept in sync with the compiler implementation. | 369 | /// therefore must be kept in sync with the compiler implementation. |
| 365 | pub const Frame = struct { | 370 | pub const Frame = struct { |
lib/std/c.zig+2-2| ... | @@ -329,8 +329,8 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int; | ... | @@ -329,8 +329,8 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int; |
| 329 | pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; | 329 | pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; |
| 330 | pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; | 330 | pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; |
| 331 | 331 | ||
| 332 | pub const pthread_t = *@Type(.Opaque); | 332 | pub const pthread_t = *opaque {}; |
| 333 | pub const FILE = @Type(.Opaque); | 333 | pub const FILE = opaque {}; |
| 334 | 334 | ||
| 335 | pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void; | 335 | pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void; |
| 336 | pub extern "c" fn dlclose(handle: *c_void) c_int; | 336 | pub extern "c" fn dlclose(handle: *c_void) c_int; |
lib/std/crypto/aes.zig+9-1| ... | @@ -10,7 +10,15 @@ const builtin = std.builtin; | ... | @@ -10,7 +10,15 @@ const builtin = std.builtin; |
| 10 | 10 | ||
| 11 | const has_aesni = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes); | 11 | const has_aesni = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .aes); |
| 12 | const has_avx = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); | 12 | const has_avx = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); |
| 13 | const impl = if (std.Target.current.cpu.arch == .x86_64 and has_aesni and has_avx) @import("aes/aesni.zig") else @import("aes/soft.zig"); | 13 | const has_armaes = comptime std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes); |
| 14 | const impl = if (std.Target.current.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { | ||
| 15 | break :impl @import("aes/aesni.zig"); | ||
| 16 | } else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) | ||
| 17 | impl: { | ||
| 18 | break :impl @import("aes/armcrypto.zig"); | ||
| 19 | } else impl: { | ||
| 20 | break :impl @import("aes/soft.zig"); | ||
| 21 | }; | ||
| 14 | 22 | ||
| 15 | pub const Block = impl.Block; | 23 | pub const Block = impl.Block; |
| 16 | pub const AESEncryptCtx = impl.AESEncryptCtx; | 24 | pub const AESEncryptCtx = impl.AESEncryptCtx; |
lib/std/crypto/aes/aesni.zig-1| ... | @@ -3,7 +3,6 @@ | ... | @@ -3,7 +3,6 @@ |
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. |
| 4 | // The MIT license requires this copyright notice to be included in all copies | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | // and substantial portions of the software. | 5 | // and substantial portions of the software. |
| 6 | // Based on Go stdlib implementation | ||
| 7 | 6 | ||
| 8 | const std = @import("../../std.zig"); | 7 | const std = @import("../../std.zig"); |
| 9 | const mem = std.mem; | 8 | const mem = std.mem; |
lib/std/crypto/aes/armcrypto.zig created+490| ... | @@ -0,0 +1,490 @@ | ||
| 1 | // SPDX-License-Identifier: MIT | ||
| 2 | // Copyright (c) 2015-2020 Zig Contributors | ||
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | ||
| 4 | // The MIT license requires this copyright notice to be included in all copies | ||
| 5 | // and substantial portions of the software. | ||
| 6 | |||
| 7 | const std = @import("../../std.zig"); | ||
| 8 | const mem = std.mem; | ||
| 9 | const debug = std.debug; | ||
| 10 | const Vector = std.meta.Vector; | ||
| 11 | |||
| 12 | const BlockVec = Vector(2, u64); | ||
| 13 | |||
| 14 | /// A single AES block. | ||
| 15 | pub const Block = struct { | ||
| 16 | pub const block_size: usize = 16; | ||
| 17 | |||
| 18 | /// Internal representation of a block. | ||
| 19 | repr: BlockVec, | ||
| 20 | |||
| 21 | /// Convert a byte sequence into an internal representation. | ||
| 22 | pub inline fn fromBytes(bytes: *const [16]u8) Block { | ||
| 23 | const repr = mem.bytesToValue(BlockVec, bytes); | ||
| 24 | return Block{ .repr = repr }; | ||
| 25 | } | ||
| 26 | |||
| 27 | /// Convert the internal representation of a block into a byte sequence. | ||
| 28 | pub inline fn toBytes(block: Block) [16]u8 { | ||
| 29 | return mem.toBytes(block.repr); | ||
| 30 | } | ||
| 31 | |||
| 32 | /// XOR the block with a byte sequence. | ||
| 33 | pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 { | ||
| 34 | const x = block.repr ^ fromBytes(bytes).repr; | ||
| 35 | return mem.toBytes(x); | ||
| 36 | } | ||
| 37 | |||
| 38 | const zero = Vector(2, u64){ 0, 0 }; | ||
| 39 | |||
| 40 | /// Encrypt a block with a round key. | ||
| 41 | pub inline fn encrypt(block: Block, round_key: Block) Block { | ||
| 42 | return Block{ | ||
| 43 | .repr = asm ( | ||
| 44 | \\ mov %[out].16b, %[in].16b | ||
| 45 | \\ aese %[out].16b, %[zero].16b | ||
| 46 | \\ aesmc %[out].16b, %[out].16b | ||
| 47 | \\ eor %[out].16b, %[out].16b, %[rk].16b | ||
| 48 | : [out] "=&x" (-> BlockVec) | ||
| 49 | : [in] "x" (block.repr), | ||
| 50 | [rk] "x" (round_key.repr), | ||
| 51 | [zero] "x" (zero) | ||
| 52 | ), | ||
| 53 | }; | ||
| 54 | } | ||
| 55 | |||
| 56 | /// Encrypt a block with the last round key. | ||
| 57 | pub inline fn encryptLast(block: Block, round_key: Block) Block { | ||
| 58 | return Block{ | ||
| 59 | .repr = asm ( | ||
| 60 | \\ mov %[out].16b, %[in].16b | ||
| 61 | \\ aese %[out].16b, %[zero].16b | ||
| 62 | \\ eor %[out].16b, %[out].16b, %[rk].16b | ||
| 63 | : [out] "=&x" (-> BlockVec) | ||
| 64 | : [in] "x" (block.repr), | ||
| 65 | [rk] "x" (round_key.repr), | ||
| 66 | [zero] "x" (zero) | ||
| 67 | ), | ||
| 68 | }; | ||
| 69 | } | ||
| 70 | |||
| 71 | /// Decrypt a block with a round key. | ||
| 72 | pub inline fn decrypt(block: Block, inv_round_key: Block) Block { | ||
| 73 | return Block{ | ||
| 74 | .repr = asm ( | ||
| 75 | \\ mov %[out].16b, %[in].16b | ||
| 76 | \\ aesd %[out].16b, %[zero].16b | ||
| 77 | \\ aesimc %[out].16b, %[out].16b | ||
| 78 | \\ eor %[out].16b, %[out].16b, %[rk].16b | ||
| 79 | : [out] "=&x" (-> BlockVec) | ||
| 80 | : [in] "x" (block.repr), | ||
| 81 | [rk] "x" (inv_round_key.repr), | ||
| 82 | [zero] "x" (zero) | ||
| 83 | ), | ||
| 84 | }; | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Decrypt a block with the last round key. | ||
| 88 | pub inline fn decryptLast(block: Block, inv_round_key: Block) Block { | ||
| 89 | return Block{ | ||
| 90 | .repr = asm ( | ||
| 91 | \\ mov %[out].16b, %[in].16b | ||
| 92 | \\ aesd %[out].16b, %[zero].16b | ||
| 93 | \\ eor %[out].16b, %[out].16b, %[rk].16b | ||
| 94 | : [out] "=&x" (-> BlockVec) | ||
| 95 | : [in] "x" (block.repr), | ||
| 96 | [rk] "x" (inv_round_key.repr), | ||
| 97 | [zero] "x" (zero) | ||
| 98 | ), | ||
| 99 | }; | ||
| 100 | } | ||
| 101 | |||
| 102 | /// Apply the bitwise XOR operation to the content of two blocks. | ||
| 103 | pub inline fn xorBlocks(block1: Block, block2: Block) Block { | ||
| 104 | return Block{ .repr = block1.repr ^ block2.repr }; | ||
| 105 | } | ||
| 106 | |||
| 107 | /// Apply the bitwise AND operation to the content of two blocks. | ||
| 108 | pub inline fn andBlocks(block1: Block, block2: Block) Block { | ||
| 109 | return Block{ .repr = block1.repr & block2.repr }; | ||
| 110 | } | ||
| 111 | |||
| 112 | /// Apply the bitwise OR operation to the content of two blocks. | ||
| 113 | pub inline fn orBlocks(block1: Block, block2: Block) Block { | ||
| 114 | return Block{ .repr = block1.repr | block2.repr }; | ||
| 115 | } | ||
| 116 | |||
| 117 | /// Perform operations on multiple blocks in parallel. | ||
| 118 | pub const parallel = struct { | ||
| 119 | /// The recommended number of AES encryption/decryption to perform in parallel for the chosen implementation. | ||
| 120 | pub const optimal_parallel_blocks = 8; | ||
| 121 | |||
| 122 | /// Encrypt multiple blocks in parallel, each their own round key. | ||
| 123 | pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { | ||
| 124 | comptime var i = 0; | ||
| 125 | var out: [count]Block = undefined; | ||
| 126 | inline while (i < count) : (i += 1) { | ||
| 127 | out[i] = blocks[i].encrypt(round_keys[i]); | ||
| 128 | } | ||
| 129 | return out; | ||
| 130 | } | ||
| 131 | |||
| 132 | /// Decrypt multiple blocks in parallel, each their own round key. | ||
| 133 | pub inline fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { | ||
| 134 | comptime var i = 0; | ||
| 135 | var out: [count]Block = undefined; | ||
| 136 | inline while (i < count) : (i += 1) { | ||
| 137 | out[i] = blocks[i].decrypt(round_keys[i]); | ||
| 138 | } | ||
| 139 | return out; | ||
| 140 | } | ||
| 141 | |||
| 142 | /// Encrypt multple blocks in parallel with the same round key. | ||
| 143 | pub inline fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { | ||
| 144 | comptime var i = 0; | ||
| 145 | var out: [count]Block = undefined; | ||
| 146 | inline while (i < count) : (i += 1) { | ||
| 147 | out[i] = blocks[i].encrypt(round_key); | ||
| 148 | } | ||
| 149 | return out; | ||
| 150 | } | ||
| 151 | |||
| 152 | /// Decrypt multple blocks in parallel with the same round key. | ||
| 153 | pub inline fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { | ||
| 154 | comptime var i = 0; | ||
| 155 | var out: [count]Block = undefined; | ||
| 156 | inline while (i < count) : (i += 1) { | ||
| 157 | out[i] = blocks[i].decrypt(round_key); | ||
| 158 | } | ||
| 159 | return out; | ||
| 160 | } | ||
| 161 | |||
| 162 | /// Encrypt multple blocks in parallel with the same last round key. | ||
| 163 | pub inline fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { | ||
| 164 | comptime var i = 0; | ||
| 165 | var out: [count]Block = undefined; | ||
| 166 | inline while (i < count) : (i += 1) { | ||
| 167 | out[i] = blocks[i].encryptLast(round_key); | ||
| 168 | } | ||
| 169 | return out; | ||
| 170 | } | ||
| 171 | |||
| 172 | /// Decrypt multple blocks in parallel with the same last round key. | ||
| 173 | pub inline fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { | ||
| 174 | comptime var i = 0; | ||
| 175 | var out: [count]Block = undefined; | ||
| 176 | inline while (i < count) : (i += 1) { | ||
| 177 | out[i] = blocks[i].decryptLast(round_key); | ||
| 178 | } | ||
| 179 | return out; | ||
| 180 | } | ||
| 181 | }; | ||
| 182 | }; | ||
| 183 | |||
| 184 | fn KeySchedule(comptime AES: type) type { | ||
| 185 | std.debug.assert(AES.rounds == 10 or AES.rounds == 14); | ||
| 186 | const rounds = AES.rounds; | ||
| 187 | |||
| 188 | return struct { | ||
| 189 | const Self = @This(); | ||
| 190 | |||
| 191 | const zero = Vector(2, u64){ 0, 0 }; | ||
| 192 | const mask1 = @Vector(16, u8){ 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12 }; | ||
| 193 | const mask2 = @Vector(16, u8){ 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15 }; | ||
| 194 | |||
| 195 | round_keys: [rounds + 1]Block, | ||
| 196 | |||
| 197 | fn drc128(comptime rc: u8, t: BlockVec) BlockVec { | ||
| 198 | var v1: BlockVec = undefined; | ||
| 199 | var v2: BlockVec = undefined; | ||
| 200 | var v3: BlockVec = undefined; | ||
| 201 | var v4: BlockVec = undefined; | ||
| 202 | |||
| 203 | return asm ( | ||
| 204 | \\ movi %[v2].4s, %[rc] | ||
| 205 | \\ tbl %[v4].16b, {%[t].16b}, %[mask].16b | ||
| 206 | \\ ext %[r].16b, %[zero].16b, %[t].16b, #12 | ||
| 207 | \\ aese %[v4].16b, %[zero].16b | ||
| 208 | \\ eor %[v2].16b, %[r].16b, %[v2].16b | ||
| 209 | \\ ext %[r].16b, %[zero].16b, %[r].16b, #12 | ||
| 210 | \\ eor %[v1].16b, %[v2].16b, %[t].16b | ||
| 211 | \\ ext %[v3].16b, %[zero].16b, %[r].16b, #12 | ||
| 212 | \\ eor %[v1].16b, %[v1].16b, %[r].16b | ||
| 213 | \\ eor %[r].16b, %[v1].16b, %[v3].16b | ||
| 214 | \\ eor %[r].16b, %[r].16b, %[v4].16b | ||
| 215 | : [r] "=&x" (-> BlockVec), | ||
| 216 | [v1] "=&x" (v1), | ||
| 217 | [v2] "=&x" (v2), | ||
| 218 | [v3] "=&x" (v3), | ||
| 219 | [v4] "=&x" (v4) | ||
| 220 | : [rc] "N" (rc), | ||
| 221 | [t] "x" (t), | ||
| 222 | [zero] "x" (zero), | ||
| 223 | [mask] "x" (mask1) | ||
| 224 | ); | ||
| 225 | } | ||
| 226 | |||
| 227 | fn drc256(comptime second: bool, comptime rc: u8, t: BlockVec, tx: BlockVec) BlockVec { | ||
| 228 | var v1: BlockVec = undefined; | ||
| 229 | var v2: BlockVec = undefined; | ||
| 230 | var v3: BlockVec = undefined; | ||
| 231 | var v4: BlockVec = undefined; | ||
| 232 | |||
| 233 | return asm ( | ||
| 234 | \\ movi %[v2].4s, %[rc] | ||
| 235 | \\ tbl %[v4].16b, {%[t].16b}, %[mask].16b | ||
| 236 | \\ ext %[r].16b, %[zero].16b, %[tx].16b, #12 | ||
| 237 | \\ aese %[v4].16b, %[zero].16b | ||
| 238 | \\ eor %[v1].16b, %[tx].16b, %[r].16b | ||
| 239 | \\ ext %[r].16b, %[zero].16b, %[r].16b, #12 | ||
| 240 | \\ eor %[v1].16b, %[v1].16b, %[r].16b | ||
| 241 | \\ ext %[v3].16b, %[zero].16b, %[r].16b, #12 | ||
| 242 | \\ eor %[v1].16b, %[v1].16b, %[v2].16b | ||
| 243 | \\ eor %[v1].16b, %[v1].16b, %[v3].16b | ||
| 244 | \\ eor %[r].16b, %[v1].16b, %[v4].16b | ||
| 245 | : [r] "=&x" (-> BlockVec), | ||
| 246 | [v1] "=&x" (v1), | ||
| 247 | [v2] "=&x" (v2), | ||
| 248 | [v3] "=&x" (v3), | ||
| 249 | [v4] "=&x" (v4) | ||
| 250 | : [rc] "N" (if (second) @as(u8, 0) else rc), | ||
| 251 | [t] "x" (t), | ||
| 252 | [tx] "x" (tx), | ||
| 253 | [zero] "x" (zero), | ||
| 254 | [mask] "x" (if (second) mask2 else mask1) | ||
| 255 | ); | ||
| 256 | } | ||
| 257 | |||
| 258 | fn expand128(t1: *Block) Self { | ||
| 259 | var round_keys: [11]Block = undefined; | ||
| 260 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32, 64, 128, 27, 54 }; | ||
| 261 | inline for (rcs) |rc, round| { | ||
| 262 | round_keys[round] = t1.*; | ||
| 263 | t1.repr = drc128(rc, t1.repr); | ||
| 264 | } | ||
| 265 | round_keys[rcs.len] = t1.*; | ||
| 266 | return Self{ .round_keys = round_keys }; | ||
| 267 | } | ||
| 268 | |||
| 269 | fn expand256(t1: *Block, t2: *Block) Self { | ||
| 270 | var round_keys: [15]Block = undefined; | ||
| 271 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32 }; | ||
| 272 | round_keys[0] = t1.*; | ||
| 273 | inline for (rcs) |rc, round| { | ||
| 274 | round_keys[round * 2 + 1] = t2.*; | ||
| 275 | t1.repr = drc256(false, rc, t2.repr, t1.repr); | ||
| 276 | round_keys[round * 2 + 2] = t1.*; | ||
| 277 | t2.repr = drc256(true, rc, t1.repr, t2.repr); | ||
| 278 | } | ||
| 279 | round_keys[rcs.len * 2 + 1] = t2.*; | ||
| 280 | t1.repr = drc256(false, 64, t2.repr, t1.repr); | ||
| 281 | round_keys[rcs.len * 2 + 2] = t1.*; | ||
| 282 | return Self{ .round_keys = round_keys }; | ||
| 283 | } | ||
| 284 | |||
| 285 | /// Invert the key schedule. | ||
| 286 | pub fn invert(key_schedule: Self) Self { | ||
| 287 | const round_keys = &key_schedule.round_keys; | ||
| 288 | var inv_round_keys: [rounds + 1]Block = undefined; | ||
| 289 | inv_round_keys[0] = round_keys[rounds]; | ||
| 290 | comptime var i = 1; | ||
| 291 | inline while (i < rounds) : (i += 1) { | ||
| 292 | inv_round_keys[i] = Block{ | ||
| 293 | .repr = asm ( | ||
| 294 | \\ aesimc %[inv_rk].16b, %[rk].16b | ||
| 295 | : [inv_rk] "=x" (-> BlockVec) | ||
| 296 | : [rk] "x" (round_keys[rounds - i].repr) | ||
| 297 | ), | ||
| 298 | }; | ||
| 299 | } | ||
| 300 | inv_round_keys[rounds] = round_keys[0]; | ||
| 301 | return Self{ .round_keys = inv_round_keys }; | ||
| 302 | } | ||
| 303 | }; | ||
| 304 | } | ||
| 305 | |||
| 306 | /// A context to perform encryption using the standard AES key schedule. | ||
| 307 | pub fn AESEncryptCtx(comptime AES: type) type { | ||
| 308 | std.debug.assert(AES.key_bits == 128 or AES.key_bits == 256); | ||
| 309 | const rounds = AES.rounds; | ||
| 310 | |||
| 311 | return struct { | ||
| 312 | const Self = @This(); | ||
| 313 | pub const block = AES.block; | ||
| 314 | pub const block_size = block.block_size; | ||
| 315 | key_schedule: KeySchedule(AES), | ||
| 316 | |||
| 317 | /// Create a new encryption context with the given key. | ||
| 318 | pub fn init(key: [AES.key_bits / 8]u8) Self { | ||
| 319 | var t1 = Block.fromBytes(key[0..16]); | ||
| 320 | const key_schedule = if (AES.key_bits == 128) ks: { | ||
| 321 | break :ks KeySchedule(AES).expand128(&t1); | ||
| 322 | } else ks: { | ||
| 323 | var t2 = Block.fromBytes(key[16..32]); | ||
| 324 | break :ks KeySchedule(AES).expand256(&t1, &t2); | ||
| 325 | }; | ||
| 326 | return Self{ | ||
| 327 | .key_schedule = key_schedule, | ||
| 328 | }; | ||
| 329 | } | ||
| 330 | |||
| 331 | /// Encrypt a single block. | ||
| 332 | pub fn encrypt(ctx: Self, dst: *[16]u8, src: *const [16]u8) void { | ||
| 333 | const round_keys = ctx.key_schedule.round_keys; | ||
| 334 | var t = Block.fromBytes(src).xorBlocks(round_keys[0]); | ||
| 335 | comptime var i = 1; | ||
| 336 | inline while (i < rounds) : (i += 1) { | ||
| 337 | t = t.encrypt(round_keys[i]); | ||
| 338 | } | ||
| 339 | t = t.encryptLast(round_keys[rounds]); | ||
| 340 | dst.* = t.toBytes(); | ||
| 341 | } | ||
| 342 | |||
| 343 | /// Encrypt+XOR a single block. | ||
| 344 | pub fn xor(ctx: Self, dst: *[16]u8, src: *const [16]u8, counter: [16]u8) void { | ||
| 345 | const round_keys = ctx.key_schedule.round_keys; | ||
| 346 | var t = Block.fromBytes(&counter).xorBlocks(round_keys[0]); | ||
| 347 | comptime var i = 1; | ||
| 348 | inline while (i < rounds) : (i += 1) { | ||
| 349 | t = t.encrypt(round_keys[i]); | ||
| 350 | } | ||
| 351 | t = t.encryptLast(round_keys[rounds]); | ||
| 352 | dst.* = t.xorBytes(src); | ||
| 353 | } | ||
| 354 | |||
| 355 | /// Encrypt multiple blocks, possibly leveraging parallelization. | ||
| 356 | pub fn encryptWide(ctx: Self, comptime count: usize, dst: *[16 * count]u8, src: *const [16 * count]u8) void { | ||
| 357 | const round_keys = ctx.key_schedule.round_keys; | ||
| 358 | var ts: [count]Block = undefined; | ||
| 359 | comptime var j = 0; | ||
| 360 | inline while (j < count) : (j += 1) { | ||
| 361 | ts[j] = Block.fromBytes(src[j * 16 .. j * 16 + 16][0..16]).xorBlocks(round_keys[0]); | ||
| 362 | } | ||
| 363 | comptime var i = 1; | ||
| 364 | inline while (i < rounds) : (i += 1) { | ||
| 365 | ts = Block.parallel.encryptWide(count, ts, round_keys[i]); | ||
| 366 | } | ||
| 367 | i = 1; | ||
| 368 | inline while (i < count) : (i += 1) { | ||
| 369 | ts = Block.parallel.encryptLastWide(count, ts, round_keys[i]); | ||
| 370 | } | ||
| 371 | j = 0; | ||
| 372 | inline while (j < count) : (j += 1) { | ||
| 373 | dst[16 * j .. 16 * j + 16].* = ts[j].toBytes(); | ||
| 374 | } | ||
| 375 | } | ||
| 376 | |||
| 377 | /// Encrypt+XOR multiple blocks, possibly leveraging parallelization. | ||
| 378 | pub fn xorWide(ctx: Self, comptime count: usize, dst: *[16 * count]u8, src: *const [16 * count]u8, counters: [16 * count]u8) void { | ||
| 379 | const round_keys = ctx.key_schedule.round_keys; | ||
| 380 | var ts: [count]Block = undefined; | ||
| 381 | comptime var j = 0; | ||
| 382 | inline while (j < count) : (j += 1) { | ||
| 383 | ts[j] = Block.fromBytes(counters[j * 16 .. j * 16 + 16][0..16]).xorBlocks(round_keys[0]); | ||
| 384 | } | ||
| 385 | comptime var i = 1; | ||
| 386 | inline while (i < rounds) : (i += 1) { | ||
| 387 | ts = Block.parallel.encryptWide(count, ts, round_keys[i]); | ||
| 388 | } | ||
| 389 | ts = Block.parallel.encryptLastWide(count, ts, round_keys[i]); | ||
| 390 | j = 0; | ||
| 391 | inline while (j < count) : (j += 1) { | ||
| 392 | dst[16 * j .. 16 * j + 16].* = ts[j].xorBytes(src[16 * j .. 16 * j + 16]); | ||
| 393 | } | ||
| 394 | } | ||
| 395 | }; | ||
| 396 | } | ||
| 397 | |||
| 398 | /// A context to perform decryption using the standard AES key schedule. | ||
| 399 | pub fn AESDecryptCtx(comptime AES: type) type { | ||
| 400 | std.debug.assert(AES.key_bits == 128 or AES.key_bits == 256); | ||
| 401 | const rounds = AES.rounds; | ||
| 402 | |||
| 403 | return struct { | ||
| 404 | const Self = @This(); | ||
| 405 | pub const block = AES.block; | ||
| 406 | pub const block_size = block.block_size; | ||
| 407 | key_schedule: KeySchedule(AES), | ||
| 408 | |||
| 409 | /// Create a decryption context from an existing encryption context. | ||
| 410 | pub fn initFromEnc(ctx: AESEncryptCtx(AES)) Self { | ||
| 411 | return Self{ | ||
| 412 | .key_schedule = ctx.key_schedule.invert(), | ||
| 413 | }; | ||
| 414 | } | ||
| 415 | |||
| 416 | /// Create a new decryption context with the given key. | ||
| 417 | pub fn init(key: [AES.key_bits / 8]u8) Self { | ||
| 418 | const enc_ctx = AESEncryptCtx(AES).init(key); | ||
| 419 | return initFromEnc(enc_ctx); | ||
| 420 | } | ||
| 421 | |||
| 422 | /// Decrypt a single block. | ||
| 423 | pub fn decrypt(ctx: Self, dst: *[16]u8, src: *const [16]u8) void { | ||
| 424 | const inv_round_keys = ctx.key_schedule.round_keys; | ||
| 425 | var t = Block.fromBytes(src).xorBlocks(inv_round_keys[0]); | ||
| 426 | comptime var i = 1; | ||
| 427 | inline while (i < rounds) : (i += 1) { | ||
| 428 | t = t.decrypt(inv_round_keys[i]); | ||
| 429 | } | ||
| 430 | t = t.decryptLast(inv_round_keys[rounds]); | ||
| 431 | dst.* = t.toBytes(); | ||
| 432 | } | ||
| 433 | |||
| 434 | /// Decrypt multiple blocks, possibly leveraging parallelization. | ||
| 435 | pub fn decryptWide(ctx: Self, comptime count: usize, dst: *[16 * count]u8, src: *const [16 * count]u8) void { | ||
| 436 | const inv_round_keys = ctx.key_schedule.round_keys; | ||
| 437 | var ts: [count]Block = undefined; | ||
| 438 | comptime var j = 0; | ||
| 439 | inline while (j < count) : (j += 1) { | ||
| 440 | ts[j] = Block.fromBytes(src[j * 16 .. j * 16 + 16][0..16]).xorBlocks(inv_round_keys[0]); | ||
| 441 | } | ||
| 442 | comptime var i = 1; | ||
| 443 | inline while (i < rounds) : (i += 1) { | ||
| 444 | ts = Block.parallel.decryptWide(count, ts, inv_round_keys[i]); | ||
| 445 | } | ||
| 446 | i = 1; | ||
| 447 | inline while (i < count) : (i += 1) { | ||
| 448 | ts = Block.parallel.decryptLastWide(count, ts, inv_round_keys[i]); | ||
| 449 | } | ||
| 450 | j = 0; | ||
| 451 | inline while (j < count) : (j += 1) { | ||
| 452 | dst[16 * j .. 16 * j + 16].* = ts[j].toBytes(); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | }; | ||
| 456 | } | ||
| 457 | |||
| 458 | /// AES-128 with the standard key schedule. | ||
| 459 | pub const AES128 = struct { | ||
| 460 | pub const key_bits: usize = 128; | ||
| 461 | pub const rounds = ((key_bits - 64) / 32 + 8); | ||
| 462 | pub const block = Block; | ||
| 463 | |||
| 464 | /// Create a new context for encryption. | ||
| 465 | pub fn initEnc(key: [key_bits / 8]u8) AESEncryptCtx(AES128) { | ||
| 466 | return AESEncryptCtx(AES128).init(key); | ||
| 467 | } | ||
| 468 | |||
| 469 | /// Create a new context for decryption. | ||
| 470 | pub fn initDec(key: [key_bits / 8]u8) AESDecryptCtx(AES128) { | ||
| 471 | return AESDecryptCtx(AES128).init(key); | ||
| 472 | } | ||
| 473 | }; | ||
| 474 | |||
| 475 | /// AES-256 with the standard key schedule. | ||
| 476 | pub const AES256 = struct { | ||
| 477 | pub const key_bits: usize = 256; | ||
| 478 | pub const rounds = ((key_bits - 64) / 32 + 8); | ||
| 479 | pub const block = Block; | ||
| 480 | |||
| 481 | /// Create a new context for encryption. | ||
| 482 | pub fn initEnc(key: [key_bits / 8]u8) AESEncryptCtx(AES256) { | ||
| 483 | return AESEncryptCtx(AES256).init(key); | ||
| 484 | } | ||
| 485 | |||
| 486 | /// Create a new context for decryption. | ||
| 487 | pub fn initDec(key: [key_bits / 8]u8) AESDecryptCtx(AES256) { | ||
| 488 | return AESDecryptCtx(AES256).init(key); | ||
| 489 | } | ||
| 490 | }; | ||
lib/std/crypto/ghash.zig+19-1| ... | @@ -105,6 +105,17 @@ pub const Ghash = struct { | ... | @@ -105,6 +105,17 @@ pub const Ghash = struct { |
| 105 | return product[0]; | 105 | return product[0]; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | inline fn clmul_pmull(x: u64, y: u64) u64 { | ||
| 109 | const Vector = std.meta.Vector; | ||
| 110 | const product = asm ( | ||
| 111 | \\ pmull %[out].1q, %[x].1d, %[y].1d | ||
| 112 | : [out] "=w" (-> Vector(2, u64)) | ||
| 113 | : [x] "w" (@bitCast(Vector(2, u64), @as(u128, x))), | ||
| 114 | [y] "w" (@bitCast(Vector(2, u64), @as(u128, y))) | ||
| 115 | ); | ||
| 116 | return product[0]; | ||
| 117 | } | ||
| 118 | |||
| 108 | fn clmul_soft(x: u64, y: u64) u64 { | 119 | fn clmul_soft(x: u64, y: u64) u64 { |
| 109 | const x0 = x & 0x1111111111111111; | 120 | const x0 = x & 0x1111111111111111; |
| 110 | const x1 = x & 0x2222222222222222; | 121 | const x1 = x & 0x2222222222222222; |
| ... | @@ -127,7 +138,14 @@ pub const Ghash = struct { | ... | @@ -127,7 +138,14 @@ pub const Ghash = struct { |
| 127 | 138 | ||
| 128 | const has_pclmul = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .pclmul); | 139 | const has_pclmul = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .pclmul); |
| 129 | const has_avx = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); | 140 | const has_avx = comptime std.Target.x86.featureSetHas(std.Target.current.cpu.features, .avx); |
| 130 | const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) clmul_pclmul else clmul_soft; | 141 | const has_armaes = comptime std.Target.aarch64.featureSetHas(std.Target.current.cpu.features, .aes); |
| 142 | const clmul = if (std.Target.current.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: { | ||
| 143 | break :impl clmul_pclmul; | ||
| 144 | } else if (std.Target.current.cpu.arch == .aarch64 and has_armaes) impl: { | ||
| 145 | break :impl clmul_pmull; | ||
| 146 | } else impl: { | ||
| 147 | break :impl clmul_soft; | ||
| 148 | }; | ||
| 131 | 149 | ||
| 132 | fn blocks(st: *Ghash, msg: []const u8) void { | 150 | fn blocks(st: *Ghash, msg: []const u8) void { |
| 133 | assert(msg.len % 16 == 0); // GHASH blocks() expects full blocks | 151 | assert(msg.len % 16 == 0); // GHASH blocks() expects full blocks |
lib/std/event.zig+2| ... | @@ -12,6 +12,7 @@ pub const Locked = @import("event/locked.zig").Locked; | ... | @@ -12,6 +12,7 @@ pub const Locked = @import("event/locked.zig").Locked; |
| 12 | pub const RwLock = @import("event/rwlock.zig").RwLock; | 12 | pub const RwLock = @import("event/rwlock.zig").RwLock; |
| 13 | pub const RwLocked = @import("event/rwlocked.zig").RwLocked; | 13 | pub const RwLocked = @import("event/rwlocked.zig").RwLocked; |
| 14 | pub const Loop = @import("event/loop.zig").Loop; | 14 | pub const Loop = @import("event/loop.zig").Loop; |
| 15 | pub const WaitGroup = @import("event/WaitGroup.zig").WaitGroup; | ||
| 15 | 16 | ||
| 16 | test "import event tests" { | 17 | test "import event tests" { |
| 17 | _ = @import("event/channel.zig"); | 18 | _ = @import("event/channel.zig"); |
| ... | @@ -23,4 +24,5 @@ test "import event tests" { | ... | @@ -23,4 +24,5 @@ test "import event tests" { |
| 23 | _ = @import("event/rwlock.zig"); | 24 | _ = @import("event/rwlock.zig"); |
| 24 | _ = @import("event/rwlocked.zig"); | 25 | _ = @import("event/rwlocked.zig"); |
| 25 | _ = @import("event/loop.zig"); | 26 | _ = @import("event/loop.zig"); |
| 27 | _ = @import("event/wait_group.zig"); | ||
| 26 | } | 28 | } |
lib/std/event/loop.zig+2| ... | @@ -660,9 +660,11 @@ pub const Loop = struct { | ... | @@ -660,9 +660,11 @@ pub const Loop = struct { |
| 660 | const Wrapper = struct { | 660 | const Wrapper = struct { |
| 661 | const Args = @TypeOf(args); | 661 | const Args = @TypeOf(args); |
| 662 | fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void { | 662 | fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void { |
| 663 | loop.beginOneEvent(); | ||
| 663 | loop.yield(); | 664 | loop.yield(); |
| 664 | const result = @call(.{}, func, func_args); | 665 | const result = @call(.{}, func, func_args); |
| 665 | suspend { | 666 | suspend { |
| 667 | loop.finishOneEvent(); | ||
| 666 | allocator.destroy(@frame()); | 668 | allocator.destroy(@frame()); |
| 667 | } | 669 | } |
| 668 | } | 670 | } |
lib/std/event/wait_group.zig created+120| ... | @@ -0,0 +1,120 @@ | ||
| 1 | // SPDX-License-Identifier: MIT | ||
| 2 | // Copyright (c) 2015-2020 Zig Contributors | ||
| 3 | // This file is part of [zig](https://ziglang.org/), which is MIT licensed. | ||
| 4 | // The MIT license requires this copyright notice to be included in all copies | ||
| 5 | // and substantial portions of the software. | ||
| 6 | const std = @import("../std.zig"); | ||
| 7 | const builtin = @import("builtin"); | ||
| 8 | const Loop = std.event.Loop; | ||
| 9 | |||
| 10 | /// A WaitGroup keeps track and waits for a group of async tasks to finish. | ||
| 11 | /// Call `begin` when creating new tasks, and have tasks call `finish` when done. | ||
| 12 | /// You can provide a count for both operations to perform them in bulk. | ||
| 13 | /// Call `wait` to suspend until all tasks are completed. | ||
| 14 | /// Multiple waiters are supported. | ||
| 15 | /// | ||
| 16 | /// WaitGroup is an instance of WaitGroupGeneric, which takes in a bitsize | ||
| 17 | /// for the internal counter. WaitGroup defaults to a `usize` counter. | ||
| 18 | /// It's also possible to define a max value for the counter so that | ||
| 19 | /// `begin` will return error.Overflow when the limit is reached, even | ||
| 20 | /// if the integer type has not has not overflowed. | ||
| 21 | /// By default `max_value` is set to std.math.maxInt(CounterType). | ||
| 22 | pub const WaitGroup = WaitGroupGeneric(std.meta.bitCount(usize)); | ||
| 23 | |||
| 24 | pub fn WaitGroupGeneric(comptime counter_size: u16) type { | ||
| 25 | const CounterType = std.meta.Int(false, counter_size); | ||
| 26 | |||
| 27 | const global_event_loop = Loop.instance orelse | ||
| 28 | @compileError("std.event.WaitGroup currently only works with event-based I/O"); | ||
| 29 | |||
| 30 | return struct { | ||
| 31 | counter: CounterType = 0, | ||
| 32 | max_counter: CounterType = std.math.maxInt(CounterType), | ||
| 33 | mutex: std.Mutex = .{}, | ||
| 34 | waiters: ?*Waiter = null, | ||
| 35 | const Waiter = struct { | ||
| 36 | next: ?*Waiter, | ||
| 37 | tail: *Waiter, | ||
| 38 | node: Loop.NextTickNode, | ||
| 39 | }; | ||
| 40 | |||
| 41 | const Self = @This(); | ||
| 42 | pub fn begin(self: *Self, count: CounterType) error{Overflow}!void { | ||
| 43 | const held = self.mutex.acquire(); | ||
| 44 | defer held.release(); | ||
| 45 | |||
| 46 | const new_counter = try std.math.add(CounterType, self.counter, count); | ||
| 47 | if (new_counter > self.max_counter) return error.Overflow; | ||
| 48 | self.counter = new_counter; | ||
| 49 | } | ||
| 50 | |||
| 51 | pub fn finish(self: *Self, count: CounterType) void { | ||
| 52 | var waiters = blk: { | ||
| 53 | const held = self.mutex.acquire(); | ||
| 54 | defer held.release(); | ||
| 55 | self.counter = std.math.sub(CounterType, self.counter, count) catch unreachable; | ||
| 56 | if (self.counter == 0) { | ||
| 57 | const temp = self.waiters; | ||
| 58 | self.waiters = null; | ||
| 59 | break :blk temp; | ||
| 60 | } | ||
| 61 | break :blk null; | ||
| 62 | }; | ||
| 63 | |||
| 64 | // We don't need to hold the lock to reschedule any potential waiter. | ||
| 65 | while (waiters) |w| { | ||
| 66 | const temp_w = w; | ||
| 67 | waiters = w.next; | ||
| 68 | global_event_loop.onNextTick(&temp_w.node); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | pub fn wait(self: *Self) void { | ||
| 73 | const held = self.mutex.acquire(); | ||
| 74 | |||
| 75 | if (self.counter == 0) { | ||
| 76 | held.release(); | ||
| 77 | return; | ||
| 78 | } | ||
| 79 | |||
| 80 | var self_waiter: Waiter = undefined; | ||
| 81 | self_waiter.node.data = @frame(); | ||
| 82 | if (self.waiters) |head| { | ||
| 83 | head.tail.next = &self_waiter; | ||
| 84 | head.tail = &self_waiter; | ||
| 85 | } else { | ||
| 86 | self.waiters = &self_waiter; | ||
| 87 | self_waiter.tail = &self_waiter; | ||
| 88 | self_waiter.next = null; | ||
| 89 | } | ||
| 90 | suspend { | ||
| 91 | held.release(); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | } | ||
| 96 | |||
| 97 | test "basic WaitGroup usage" { | ||
| 98 | if (!std.io.is_async) return error.SkipZigTest; | ||
| 99 | |||
| 100 | // TODO https://github.com/ziglang/zig/issues/1908 | ||
| 101 | if (builtin.single_threaded) return error.SkipZigTest; | ||
| 102 | |||
| 103 | // TODO https://github.com/ziglang/zig/issues/3251 | ||
| 104 | if (builtin.os.tag == .freebsd) return error.SkipZigTest; | ||
| 105 | |||
| 106 | var initial_wg = WaitGroup{}; | ||
| 107 | var final_wg = WaitGroup{}; | ||
| 108 | |||
| 109 | try initial_wg.begin(1); | ||
| 110 | try final_wg.begin(1); | ||
| 111 | var task_frame = async task(&initial_wg, &final_wg); | ||
| 112 | initial_wg.finish(1); | ||
| 113 | final_wg.wait(); | ||
| 114 | await task_frame; | ||
| 115 | } | ||
| 116 | |||
| 117 | fn task(wg_i: *WaitGroup, wg_f: *WaitGroup) void { | ||
| 118 | wg_i.wait(); | ||
| 119 | wg_f.finish(1); | ||
| 120 | } | ||
lib/std/fmt.zig+5-2| ... | @@ -1181,13 +1181,16 @@ fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, opti | ... | @@ -1181,13 +1181,16 @@ fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, opti |
| 1181 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; | 1181 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; |
| 1182 | } | 1182 | } |
| 1183 | 1183 | ||
| 1184 | pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args)]u8 { | 1184 | pub fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8 { |
| 1185 | comptime var buf: [count(fmt, args)]u8 = undefined; | 1185 | comptime var buf: [count(fmt, args):0]u8 = undefined; |
| 1186 | _ = bufPrint(&buf, fmt, args) catch unreachable; | 1186 | _ = bufPrint(&buf, fmt, args) catch unreachable; |
| 1187 | buf[buf.len] = 0; | ||
| 1187 | return &buf; | 1188 | return &buf; |
| 1188 | } | 1189 | } |
| 1189 | 1190 | ||
| 1190 | test "comptimePrint" { | 1191 | test "comptimePrint" { |
| 1192 | @setEvalBranchQuota(2000); | ||
| 1193 | std.testing.expectEqual(*const [3:0]u8, @TypeOf(comptime comptimePrint("{}", .{100}))); | ||
| 1191 | std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); | 1194 | std.testing.expectEqualSlices(u8, "100", comptime comptimePrint("{}", .{100})); |
| 1192 | } | 1195 | } |
| 1193 | 1196 |
lib/std/math.zig+12-1| ... | @@ -110,7 +110,12 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { | ... | @@ -110,7 +110,12 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool { |
| 110 | } | 110 | } |
| 111 | 111 | ||
| 112 | pub fn doNotOptimizeAway(value: anytype) void { | 112 | pub fn doNotOptimizeAway(value: anytype) void { |
| 113 | mem.doNotOptimizeAway(value); | 113 | // TODO: use @declareSideEffect() when it is available. |
| 114 | // https://github.com/ziglang/zig/issues/6168 | ||
| 115 | const T = @TypeOf(value); | ||
| 116 | var x: T = undefined; | ||
| 117 | const p = @ptrCast(*volatile T, &x); | ||
| 118 | p.* = x; | ||
| 114 | } | 119 | } |
| 115 | 120 | ||
| 116 | pub fn raiseInvalid() void { | 121 | pub fn raiseInvalid() void { |
| ... | @@ -1131,3 +1136,9 @@ test "compare between signed and unsigned" { | ... | @@ -1131,3 +1136,9 @@ test "compare between signed and unsigned" { |
| 1131 | testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1))); | 1136 | testing.expect(!compare(@as(u8, 255), .eq, @as(i8, -1))); |
| 1132 | testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); | 1137 | testing.expect(compare(@as(u8, 1), .eq, @as(u8, 1))); |
| 1133 | } | 1138 | } |
| 1139 | |||
| 1140 | test "math.comptime" { | ||
| 1141 | comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5)); | ||
| 1142 | testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); | ||
| 1143 | } | ||
| 1144 |
lib/std/os/linux/bpf/kern.zig+25-25| ... | @@ -12,28 +12,28 @@ const in_bpf_program = switch (std.builtin.arch) { | ... | @@ -12,28 +12,28 @@ const in_bpf_program = switch (std.builtin.arch) { |
| 12 | 12 | ||
| 13 | pub const helpers = if (in_bpf_program) @import("helpers.zig") else struct {}; | 13 | pub const helpers = if (in_bpf_program) @import("helpers.zig") else struct {}; |
| 14 | 14 | ||
| 15 | pub const BpfSock = @Type(.Opaque); | 15 | pub const BpfSock = opaque {}; |
| 16 | pub const BpfSockAddr = @Type(.Opaque); | 16 | pub const BpfSockAddr = opaque {}; |
| 17 | pub const FibLookup = @Type(.Opaque); | 17 | pub const FibLookup = opaque {}; |
| 18 | pub const MapDef = @Type(.Opaque); | 18 | pub const MapDef = opaque {}; |
| 19 | pub const PerfEventData = @Type(.Opaque); | 19 | pub const PerfEventData = opaque {}; |
| 20 | pub const PerfEventValue = @Type(.Opaque); | 20 | pub const PerfEventValue = opaque {}; |
| 21 | pub const PidNsInfo = @Type(.Opaque); | 21 | pub const PidNsInfo = opaque {}; |
| 22 | pub const SeqFile = @Type(.Opaque); | 22 | pub const SeqFile = opaque {}; |
| 23 | pub const SkBuff = @Type(.Opaque); | 23 | pub const SkBuff = opaque {}; |
| 24 | pub const SkMsgMd = @Type(.Opaque); | 24 | pub const SkMsgMd = opaque {}; |
| 25 | pub const SkReusePortMd = @Type(.Opaque); | 25 | pub const SkReusePortMd = opaque {}; |
| 26 | pub const Sock = @Type(.Opaque); | 26 | pub const Sock = opaque {}; |
| 27 | pub const SockAddr = @Type(.Opaque); | 27 | pub const SockAddr = opaque {}; |
| 28 | pub const SockOps = @Type(.Opaque); | 28 | pub const SockOps = opaque {}; |
| 29 | pub const SockTuple = @Type(.Opaque); | 29 | pub const SockTuple = opaque {}; |
| 30 | pub const SpinLock = @Type(.Opaque); | 30 | pub const SpinLock = opaque {}; |
| 31 | pub const SysCtl = @Type(.Opaque); | 31 | pub const SysCtl = opaque {}; |
| 32 | pub const Tcp6Sock = @Type(.Opaque); | 32 | pub const Tcp6Sock = opaque {}; |
| 33 | pub const TcpRequestSock = @Type(.Opaque); | 33 | pub const TcpRequestSock = opaque {}; |
| 34 | pub const TcpSock = @Type(.Opaque); | 34 | pub const TcpSock = opaque {}; |
| 35 | pub const TcpTimewaitSock = @Type(.Opaque); | 35 | pub const TcpTimewaitSock = opaque {}; |
| 36 | pub const TunnelKey = @Type(.Opaque); | 36 | pub const TunnelKey = opaque {}; |
| 37 | pub const Udp6Sock = @Type(.Opaque); | 37 | pub const Udp6Sock = opaque {}; |
| 38 | pub const XdpMd = @Type(.Opaque); | 38 | pub const XdpMd = opaque {}; |
| 39 | pub const XfrmState = @Type(.Opaque); | 39 | pub const XfrmState = opaque {}; |
lib/std/os/uefi.zig+3-3| ... | @@ -17,7 +17,7 @@ pub var handle: Handle = undefined; | ... | @@ -17,7 +17,7 @@ pub var handle: Handle = undefined; |
| 17 | pub var system_table: *tables.SystemTable = undefined; | 17 | pub var system_table: *tables.SystemTable = undefined; |
| 18 | 18 | ||
| 19 | /// A handle to an event structure. | 19 | /// A handle to an event structure. |
| 20 | pub const Event = *@Type(.Opaque); | 20 | pub const Event = *opaque {}; |
| 21 | 21 | ||
| 22 | /// GUIDs must be align(8) | 22 | /// GUIDs must be align(8) |
| 23 | pub const Guid = extern struct { | 23 | pub const Guid = extern struct { |
| ... | @@ -51,7 +51,7 @@ pub const Guid = extern struct { | ... | @@ -51,7 +51,7 @@ pub const Guid = extern struct { |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | /// An EFI Handle represents a collection of related interfaces. | 53 | /// An EFI Handle represents a collection of related interfaces. |
| 54 | pub const Handle = *@Type(.Opaque); | 54 | pub const Handle = *opaque {}; |
| 55 | 55 | ||
| 56 | /// This structure represents time information. | 56 | /// This structure represents time information. |
| 57 | pub const Time = extern struct { | 57 | pub const Time = extern struct { |
| ... | @@ -108,4 +108,4 @@ pub const TimeCapabilities = extern struct { | ... | @@ -108,4 +108,4 @@ pub const TimeCapabilities = extern struct { |
| 108 | }; | 108 | }; |
| 109 | 109 | ||
| 110 | /// File Handle as specified in the EFI Shell Spec | 110 | /// File Handle as specified in the EFI Shell Spec |
| 111 | pub const FileHandle = *@Type(.Opaque); | 111 | pub const FileHandle = *opaque {}; |
lib/std/os/uefi/protocols/hii.zig+1-1| ... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
| 6 | const uefi = @import("std").os.uefi; | 6 | const uefi = @import("std").os.uefi; |
| 7 | const Guid = uefi.Guid; | 7 | const Guid = uefi.Guid; |
| 8 | 8 | ||
| 9 | pub const HIIHandle = *@Type(.Opaque); | 9 | pub const HIIHandle = *opaque {}; |
| 10 | 10 | ||
| 11 | /// The header found at the start of each package. | 11 | /// The header found at the start of each package. |
| 12 | pub const HIIPackageHeader = packed struct { | 12 | pub const HIIPackageHeader = packed struct { |
lib/std/os/windows/bits.zig+15-15| ... | @@ -32,16 +32,16 @@ pub const UCHAR = u8; | ... | @@ -32,16 +32,16 @@ pub const UCHAR = u8; |
| 32 | pub const FLOAT = f32; | 32 | pub const FLOAT = f32; |
| 33 | pub const HANDLE = *c_void; | 33 | pub const HANDLE = *c_void; |
| 34 | pub const HCRYPTPROV = ULONG_PTR; | 34 | pub const HCRYPTPROV = ULONG_PTR; |
| 35 | pub const HBRUSH = *@Type(.Opaque); | 35 | pub const HBRUSH = *opaque {}; |
| 36 | pub const HCURSOR = *@Type(.Opaque); | 36 | pub const HCURSOR = *opaque {}; |
| 37 | pub const HICON = *@Type(.Opaque); | 37 | pub const HICON = *opaque {}; |
| 38 | pub const HINSTANCE = *@Type(.Opaque); | 38 | pub const HINSTANCE = *opaque {}; |
| 39 | pub const HMENU = *@Type(.Opaque); | 39 | pub const HMENU = *opaque {}; |
| 40 | pub const HMODULE = *@Type(.Opaque); | 40 | pub const HMODULE = *opaque {}; |
| 41 | pub const HWND = *@Type(.Opaque); | 41 | pub const HWND = *opaque {}; |
| 42 | pub const HDC = *@Type(.Opaque); | 42 | pub const HDC = *opaque {}; |
| 43 | pub const HGLRC = *@Type(.Opaque); | 43 | pub const HGLRC = *opaque {}; |
| 44 | pub const FARPROC = *@Type(.Opaque); | 44 | pub const FARPROC = *opaque {}; |
| 45 | pub const INT = c_int; | 45 | pub const INT = c_int; |
| 46 | pub const LPBYTE = *BYTE; | 46 | pub const LPBYTE = *BYTE; |
| 47 | pub const LPCH = *CHAR; | 47 | pub const LPCH = *CHAR; |
| ... | @@ -81,7 +81,7 @@ pub const WPARAM = usize; | ... | @@ -81,7 +81,7 @@ pub const WPARAM = usize; |
| 81 | pub const LPARAM = ?*c_void; | 81 | pub const LPARAM = ?*c_void; |
| 82 | pub const LRESULT = ?*c_void; | 82 | pub const LRESULT = ?*c_void; |
| 83 | 83 | ||
| 84 | pub const va_list = *@Type(.Opaque); | 84 | pub const va_list = *opaque {}; |
| 85 | 85 | ||
| 86 | pub const TRUE = 1; | 86 | pub const TRUE = 1; |
| 87 | pub const FALSE = 0; | 87 | pub const FALSE = 0; |
| ... | @@ -1175,10 +1175,10 @@ pub const UNICODE_STRING = extern struct { | ... | @@ -1175,10 +1175,10 @@ pub const UNICODE_STRING = extern struct { |
| 1175 | Buffer: [*]WCHAR, | 1175 | Buffer: [*]WCHAR, |
| 1176 | }; | 1176 | }; |
| 1177 | 1177 | ||
| 1178 | const ACTIVATION_CONTEXT_DATA = @Type(.Opaque); | 1178 | const ACTIVATION_CONTEXT_DATA = opaque {}; |
| 1179 | const ASSEMBLY_STORAGE_MAP = @Type(.Opaque); | 1179 | const ASSEMBLY_STORAGE_MAP = opaque {}; |
| 1180 | const FLS_CALLBACK_INFO = @Type(.Opaque); | 1180 | const FLS_CALLBACK_INFO = opaque {}; |
| 1181 | const RTL_BITMAP = @Type(.Opaque); | 1181 | const RTL_BITMAP = opaque {}; |
| 1182 | pub const PRTL_BITMAP = *RTL_BITMAP; | 1182 | pub const PRTL_BITMAP = *RTL_BITMAP; |
| 1183 | const KAFFINITY = usize; | 1183 | const KAFFINITY = usize; |
| 1184 | 1184 |
lib/std/os/windows/ws2_32.zig+1-1| ... | @@ -5,7 +5,7 @@ | ... | @@ -5,7 +5,7 @@ |
| 5 | // and substantial portions of the software. | 5 | // and substantial portions of the software. |
| 6 | usingnamespace @import("bits.zig"); | 6 | usingnamespace @import("bits.zig"); |
| 7 | 7 | ||
| 8 | pub const SOCKET = *@Type(.Opaque); | 8 | pub const SOCKET = *opaque {}; |
| 9 | pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0)); | 9 | pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0)); |
| 10 | pub const SOCKET_ERROR = -1; | 10 | pub const SOCKET_ERROR = -1; |
| 11 | 11 |
lib/std/zig/ast.zig+1-1| ... | @@ -288,7 +288,7 @@ pub const Error = union(enum) { | ... | @@ -288,7 +288,7 @@ pub const Error = union(enum) { |
| 288 | pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'"); | 288 | pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'"); |
| 289 | pub const ExpectedFn = SingleTokenError("Expected function, found '{}'"); | 289 | pub const ExpectedFn = SingleTokenError("Expected function, found '{}'"); |
| 290 | pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'"); | 290 | pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'"); |
| 291 | pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', or '" ++ Token.Id.Keyword_enum.symbol() ++ "', found '{}'"); | 291 | pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', '" ++ Token.Id.Keyword_enum.symbol() ++ "', or '" ++ Token.Id.Keyword_opaque.symbol() ++ "', found '{}'"); |
| 292 | pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'"); | 292 | pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'"); |
| 293 | pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{}'"); | 293 | pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{}'"); |
| 294 | pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{}'"); | 294 | pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{}'"); |
lib/std/zig/parse.zig+2-1| ... | @@ -2896,11 +2896,12 @@ const Parser = struct { | ... | @@ -2896,11 +2896,12 @@ const Parser = struct { |
| 2896 | /// <- KEYWORD_struct | 2896 | /// <- KEYWORD_struct |
| 2897 | /// / KEYWORD_enum (LPAREN Expr RPAREN)? | 2897 | /// / KEYWORD_enum (LPAREN Expr RPAREN)? |
| 2898 | /// / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? | 2898 | /// / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? |
| 2899 | /// / KEYWORD_opaque | ||
| 2899 | fn parseContainerDeclType(p: *Parser) !?ContainerDeclType { | 2900 | fn parseContainerDeclType(p: *Parser) !?ContainerDeclType { |
| 2900 | const kind_token = p.nextToken(); | 2901 | const kind_token = p.nextToken(); |
| 2901 | 2902 | ||
| 2902 | const init_arg_expr = switch (p.token_ids[kind_token]) { | 2903 | const init_arg_expr = switch (p.token_ids[kind_token]) { |
| 2903 | .Keyword_struct => Node.ContainerDecl.InitArg{ .None = {} }, | 2904 | .Keyword_struct, .Keyword_opaque => Node.ContainerDecl.InitArg{ .None = {} }, |
| 2904 | .Keyword_enum => blk: { | 2905 | .Keyword_enum => blk: { |
| 2905 | if (p.eatToken(.LParen) != null) { | 2906 | if (p.eatToken(.LParen) != null) { |
| 2906 | const expr = try p.expectNode(parseExpr, .{ | 2907 | const expr = try p.expectNode(parseExpr, .{ |
lib/std/zig/render.zig+13-1| ... | @@ -1492,7 +1492,19 @@ fn renderExpression( | ... | @@ -1492,7 +1492,19 @@ fn renderExpression( |
| 1492 | 1492 | ||
| 1493 | // TODO remove after 0.7.0 release | 1493 | // TODO remove after 0.7.0 release |
| 1494 | if (mem.eql(u8, tree.tokenSlice(builtin_call.builtin_token), "@OpaqueType")) | 1494 | if (mem.eql(u8, tree.tokenSlice(builtin_call.builtin_token), "@OpaqueType")) |
| 1495 | return ais.writer().writeAll("@Type(.Opaque)"); | 1495 | return ais.writer().writeAll("opaque {}"); |
| 1496 | |||
| 1497 | // TODO remove after 0.7.0 release | ||
| 1498 | { | ||
| 1499 | const params = builtin_call.paramsConst(); | ||
| 1500 | if (mem.eql(u8, tree.tokenSlice(builtin_call.builtin_token), "@Type") and | ||
| 1501 | params.len == 1) | ||
| 1502 | { | ||
| 1503 | if (params[0].castTag(.EnumLiteral)) |enum_literal| | ||
| 1504 | if (mem.eql(u8, tree.tokenSlice(enum_literal.name), "Opaque")) | ||
| 1505 | return ais.writer().writeAll("opaque {}"); | ||
| 1506 | } | ||
| 1507 | } | ||
| 1496 | 1508 | ||
| 1497 | try renderToken(tree, ais, builtin_call.builtin_token, Space.None); // @name | 1509 | try renderToken(tree, ais, builtin_call.builtin_token, Space.None); // @name |
| 1498 | 1510 |
lib/std/zig/tokenizer.zig+3| ... | @@ -47,6 +47,7 @@ pub const Token = struct { | ... | @@ -47,6 +47,7 @@ pub const Token = struct { |
| 47 | .{ "noinline", .Keyword_noinline }, | 47 | .{ "noinline", .Keyword_noinline }, |
| 48 | .{ "nosuspend", .Keyword_nosuspend }, | 48 | .{ "nosuspend", .Keyword_nosuspend }, |
| 49 | .{ "null", .Keyword_null }, | 49 | .{ "null", .Keyword_null }, |
| 50 | .{ "opaque", .Keyword_opaque }, | ||
| 50 | .{ "or", .Keyword_or }, | 51 | .{ "or", .Keyword_or }, |
| 51 | .{ "orelse", .Keyword_orelse }, | 52 | .{ "orelse", .Keyword_orelse }, |
| 52 | .{ "packed", .Keyword_packed }, | 53 | .{ "packed", .Keyword_packed }, |
| ... | @@ -173,6 +174,7 @@ pub const Token = struct { | ... | @@ -173,6 +174,7 @@ pub const Token = struct { |
| 173 | Keyword_noinline, | 174 | Keyword_noinline, |
| 174 | Keyword_nosuspend, | 175 | Keyword_nosuspend, |
| 175 | Keyword_null, | 176 | Keyword_null, |
| 177 | Keyword_opaque, | ||
| 176 | Keyword_or, | 178 | Keyword_or, |
| 177 | Keyword_orelse, | 179 | Keyword_orelse, |
| 178 | Keyword_packed, | 180 | Keyword_packed, |
| ... | @@ -296,6 +298,7 @@ pub const Token = struct { | ... | @@ -296,6 +298,7 @@ pub const Token = struct { |
| 296 | .Keyword_noinline => "noinline", | 298 | .Keyword_noinline => "noinline", |
| 297 | .Keyword_nosuspend => "nosuspend", | 299 | .Keyword_nosuspend => "nosuspend", |
| 298 | .Keyword_null => "null", | 300 | .Keyword_null => "null", |
| 301 | .Keyword_opaque => "opaque", | ||
| 299 | .Keyword_or => "or", | 302 | .Keyword_or => "or", |
| 300 | .Keyword_orelse => "orelse", | 303 | .Keyword_orelse => "orelse", |
| 301 | .Keyword_packed => "packed", | 304 | .Keyword_packed => "packed", |
src/clang.zig+929-521| ... | @@ -1,91 +1,901 @@ | ... | @@ -1,91 +1,901 @@ |
| 1 | const builtin = @import("builtin"); | 1 | pub const builtin = @import("builtin"); |
| 2 | 2 | ||
| 3 | pub const struct_ZigClangConditionalOperator = @Type(.Opaque); | 3 | pub const SourceLocation = extern struct { |
| 4 | pub const struct_ZigClangBinaryConditionalOperator = @Type(.Opaque); | 4 | ID: c_uint, |
| 5 | pub const struct_ZigClangAbstractConditionalOperator = @Type(.Opaque); | 5 | |
| 6 | pub const struct_ZigClangAPInt = @Type(.Opaque); | 6 | pub const eq = ZigClangSourceLocation_eq; |
| 7 | pub const struct_ZigClangAPSInt = @Type(.Opaque); | 7 | extern fn ZigClangSourceLocation_eq(a: SourceLocation, b: SourceLocation) bool; |
| 8 | pub const struct_ZigClangAPFloat = @Type(.Opaque); | 8 | }; |
| 9 | pub const struct_ZigClangASTContext = @Type(.Opaque); | 9 | |
| 10 | pub const struct_ZigClangASTUnit = @Type(.Opaque); | 10 | pub const QualType = extern struct { |
| 11 | pub const struct_ZigClangArraySubscriptExpr = @Type(.Opaque); | 11 | ptr: ?*c_void, |
| 12 | pub const struct_ZigClangArrayType = @Type(.Opaque); | 12 | |
| 13 | pub const struct_ZigClangAttributedType = @Type(.Opaque); | 13 | pub const getCanonicalType = ZigClangQualType_getCanonicalType; |
| 14 | pub const struct_ZigClangBinaryOperator = @Type(.Opaque); | 14 | extern fn ZigClangQualType_getCanonicalType(QualType) QualType; |
| 15 | pub const struct_ZigClangBreakStmt = @Type(.Opaque); | 15 | |
| 16 | pub const struct_ZigClangBuiltinType = @Type(.Opaque); | 16 | pub const getTypePtr = ZigClangQualType_getTypePtr; |
| 17 | pub const struct_ZigClangCStyleCastExpr = @Type(.Opaque); | 17 | extern fn ZigClangQualType_getTypePtr(QualType) *const Type; |
| 18 | pub const struct_ZigClangCallExpr = @Type(.Opaque); | 18 | |
| 19 | pub const struct_ZigClangCaseStmt = @Type(.Opaque); | 19 | pub const getTypeClass = ZigClangQualType_getTypeClass; |
| 20 | pub const struct_ZigClangCompoundAssignOperator = @Type(.Opaque); | 20 | extern fn ZigClangQualType_getTypeClass(QualType) TypeClass; |
| 21 | pub const struct_ZigClangCompoundStmt = @Type(.Opaque); | 21 | |
| 22 | pub const struct_ZigClangConstantArrayType = @Type(.Opaque); | 22 | pub const addConst = ZigClangQualType_addConst; |
| 23 | pub const struct_ZigClangContinueStmt = @Type(.Opaque); | 23 | extern fn ZigClangQualType_addConst(*QualType) void; |
| 24 | pub const struct_ZigClangDecayedType = @Type(.Opaque); | 24 | |
| 25 | pub const ZigClangDecl = @Type(.Opaque); | 25 | pub const eq = ZigClangQualType_eq; |
| 26 | pub const struct_ZigClangDeclRefExpr = @Type(.Opaque); | 26 | extern fn ZigClangQualType_eq(QualType, arg1: QualType) bool; |
| 27 | pub const struct_ZigClangDeclStmt = @Type(.Opaque); | 27 | |
| 28 | pub const struct_ZigClangDefaultStmt = @Type(.Opaque); | 28 | pub const isConstQualified = ZigClangQualType_isConstQualified; |
| 29 | pub const struct_ZigClangDiagnosticOptions = @Type(.Opaque); | 29 | extern fn ZigClangQualType_isConstQualified(QualType) bool; |
| 30 | pub const struct_ZigClangDiagnosticsEngine = @Type(.Opaque); | 30 | |
| 31 | pub const struct_ZigClangDoStmt = @Type(.Opaque); | 31 | pub const isVolatileQualified = ZigClangQualType_isVolatileQualified; |
| 32 | pub const struct_ZigClangElaboratedType = @Type(.Opaque); | 32 | extern fn ZigClangQualType_isVolatileQualified(QualType) bool; |
| 33 | pub const struct_ZigClangEnumConstantDecl = @Type(.Opaque); | 33 | |
| 34 | pub const struct_ZigClangEnumDecl = @Type(.Opaque); | 34 | pub const isRestrictQualified = ZigClangQualType_isRestrictQualified; |
| 35 | pub const struct_ZigClangEnumType = @Type(.Opaque); | 35 | extern fn ZigClangQualType_isRestrictQualified(QualType) bool; |
| 36 | pub const struct_ZigClangExpr = @Type(.Opaque); | 36 | }; |
| 37 | pub const struct_ZigClangFieldDecl = @Type(.Opaque); | 37 | |
| 38 | pub const struct_ZigClangFileID = @Type(.Opaque); | 38 | pub const APValueLValueBase = extern struct { |
| 39 | pub const struct_ZigClangForStmt = @Type(.Opaque); | 39 | Ptr: ?*c_void, |
| 40 | pub const struct_ZigClangFullSourceLoc = @Type(.Opaque); | 40 | CallIndex: c_uint, |
| 41 | pub const struct_ZigClangFunctionDecl = @Type(.Opaque); | 41 | Version: c_uint, |
| 42 | pub const struct_ZigClangFunctionProtoType = @Type(.Opaque); | 42 | |
| 43 | pub const struct_ZigClangIfStmt = @Type(.Opaque); | 43 | pub const dyn_cast_Expr = ZigClangAPValueLValueBase_dyn_cast_Expr; |
| 44 | pub const struct_ZigClangImplicitCastExpr = @Type(.Opaque); | 44 | extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(APValueLValueBase) ?*const Expr; |
| 45 | pub const struct_ZigClangIncompleteArrayType = @Type(.Opaque); | 45 | }; |
| 46 | pub const struct_ZigClangIntegerLiteral = @Type(.Opaque); | 46 | |
| 47 | pub const struct_ZigClangMacroDefinitionRecord = @Type(.Opaque); | 47 | pub const APValueKind = extern enum { |
| 48 | pub const struct_ZigClangMacroExpansion = @Type(.Opaque); | 48 | None, |
| 49 | pub const struct_ZigClangMacroQualifiedType = @Type(.Opaque); | 49 | Indeterminate, |
| 50 | pub const struct_ZigClangMemberExpr = @Type(.Opaque); | 50 | Int, |
| 51 | pub const struct_ZigClangNamedDecl = @Type(.Opaque); | 51 | Float, |
| 52 | pub const struct_ZigClangNone = @Type(.Opaque); | 52 | FixedPoint, |
| 53 | pub const struct_ZigClangOpaqueValueExpr = @Type(.Opaque); | 53 | ComplexInt, |
| 54 | pub const struct_ZigClangPCHContainerOperations = @Type(.Opaque); | 54 | ComplexFloat, |
| 55 | pub const struct_ZigClangParenExpr = @Type(.Opaque); | 55 | LValue, |
| 56 | pub const struct_ZigClangParenType = @Type(.Opaque); | 56 | Vector, |
| 57 | pub const struct_ZigClangParmVarDecl = @Type(.Opaque); | 57 | Array, |
| 58 | pub const struct_ZigClangPointerType = @Type(.Opaque); | 58 | Struct, |
| 59 | pub const struct_ZigClangPreprocessedEntity = @Type(.Opaque); | 59 | Union, |
| 60 | pub const struct_ZigClangRecordDecl = @Type(.Opaque); | 60 | MemberPointer, |
| 61 | pub const struct_ZigClangRecordType = @Type(.Opaque); | 61 | AddrLabelDiff, |
| 62 | pub const struct_ZigClangReturnStmt = @Type(.Opaque); | 62 | }; |
| 63 | pub const struct_ZigClangSkipFunctionBodiesScope = @Type(.Opaque); | 63 | |
| 64 | pub const struct_ZigClangSourceManager = @Type(.Opaque); | 64 | pub const APValue = extern struct { |
| 65 | pub const struct_ZigClangSourceRange = @Type(.Opaque); | 65 | Kind: APValueKind, |
| 66 | pub const ZigClangStmt = @Type(.Opaque); | 66 | Data: if (builtin.os.tag == .windows and builtin.abi == .msvc) [52]u8 else [68]u8, |
| 67 | pub const struct_ZigClangStringLiteral = @Type(.Opaque); | 67 | |
| 68 | pub const struct_ZigClangStringRef = @Type(.Opaque); | 68 | pub const getKind = ZigClangAPValue_getKind; |
| 69 | pub const struct_ZigClangSwitchStmt = @Type(.Opaque); | 69 | extern fn ZigClangAPValue_getKind(*const APValue) APValueKind; |
| 70 | pub const struct_ZigClangTagDecl = @Type(.Opaque); | 70 | |
| 71 | pub const struct_ZigClangType = @Type(.Opaque); | 71 | pub const getInt = ZigClangAPValue_getInt; |
| 72 | pub const struct_ZigClangTypedefNameDecl = @Type(.Opaque); | 72 | extern fn ZigClangAPValue_getInt(*const APValue) *const APSInt; |
| 73 | pub const struct_ZigClangTypedefType = @Type(.Opaque); | 73 | |
| 74 | pub const struct_ZigClangUnaryExprOrTypeTraitExpr = @Type(.Opaque); | 74 | pub const getArrayInitializedElts = ZigClangAPValue_getArrayInitializedElts; |
| 75 | pub const struct_ZigClangUnaryOperator = @Type(.Opaque); | 75 | extern fn ZigClangAPValue_getArrayInitializedElts(*const APValue) c_uint; |
| 76 | pub const struct_ZigClangValueDecl = @Type(.Opaque); | 76 | |
| 77 | pub const struct_ZigClangVarDecl = @Type(.Opaque); | 77 | pub const getArraySize = ZigClangAPValue_getArraySize; |
| 78 | pub const struct_ZigClangWhileStmt = @Type(.Opaque); | 78 | extern fn ZigClangAPValue_getArraySize(*const APValue) c_uint; |
| 79 | pub const struct_ZigClangFunctionType = @Type(.Opaque); | 79 | |
| 80 | pub const struct_ZigClangPredefinedExpr = @Type(.Opaque); | 80 | pub const getLValueBase = ZigClangAPValue_getLValueBase; |
| 81 | pub const struct_ZigClangInitListExpr = @Type(.Opaque); | 81 | extern fn ZigClangAPValue_getLValueBase(*const APValue) APValueLValueBase; |
| 82 | pub const ZigClangPreprocessingRecord = @Type(.Opaque); | 82 | }; |
| 83 | pub const ZigClangFloatingLiteral = @Type(.Opaque); | 83 | |
| 84 | pub const ZigClangConstantExpr = @Type(.Opaque); | 84 | pub const ExprEvalResult = extern struct { |
| 85 | pub const ZigClangCharacterLiteral = @Type(.Opaque); | 85 | HasSideEffects: bool, |
| 86 | pub const ZigClangStmtExpr = @Type(.Opaque); | 86 | HasUndefinedBehavior: bool, |
| 87 | 87 | SmallVectorImpl: ?*c_void, | |
| 88 | pub const ZigClangBO = extern enum { | 88 | Val: APValue, |
| 89 | }; | ||
| 90 | |||
| 91 | pub const AbstractConditionalOperator = opaque { | ||
| 92 | pub const getCond = ZigClangAbstractConditionalOperator_getCond; | ||
| 93 | extern fn ZigClangAbstractConditionalOperator_getCond(*const AbstractConditionalOperator) *const Expr; | ||
| 94 | |||
| 95 | pub const getTrueExpr = ZigClangAbstractConditionalOperator_getTrueExpr; | ||
| 96 | extern fn ZigClangAbstractConditionalOperator_getTrueExpr(*const AbstractConditionalOperator) *const Expr; | ||
| 97 | |||
| 98 | pub const getFalseExpr = ZigClangAbstractConditionalOperator_getFalseExpr; | ||
| 99 | extern fn ZigClangAbstractConditionalOperator_getFalseExpr(*const AbstractConditionalOperator) *const Expr; | ||
| 100 | }; | ||
| 101 | |||
| 102 | pub const APFloat = opaque { | ||
| 103 | pub const toString = ZigClangAPFloat_toString; | ||
| 104 | extern fn ZigClangAPFloat_toString(*const APFloat, precision: c_uint, maxPadding: c_uint, truncateZero: bool) [*:0]const u8; | ||
| 105 | }; | ||
| 106 | |||
| 107 | pub const APInt = opaque { | ||
| 108 | pub const getLimitedValue = ZigClangAPInt_getLimitedValue; | ||
| 109 | extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64; | ||
| 110 | }; | ||
| 111 | |||
| 112 | pub const APSInt = opaque { | ||
| 113 | pub const isSigned = ZigClangAPSInt_isSigned; | ||
| 114 | extern fn ZigClangAPSInt_isSigned(*const APSInt) bool; | ||
| 115 | |||
| 116 | pub const isNegative = ZigClangAPSInt_isNegative; | ||
| 117 | extern fn ZigClangAPSInt_isNegative(*const APSInt) bool; | ||
| 118 | |||
| 119 | pub const negate = ZigClangAPSInt_negate; | ||
| 120 | extern fn ZigClangAPSInt_negate(*const APSInt) *const APSInt; | ||
| 121 | |||
| 122 | pub const free = ZigClangAPSInt_free; | ||
| 123 | extern fn ZigClangAPSInt_free(*const APSInt) void; | ||
| 124 | |||
| 125 | pub const getRawData = ZigClangAPSInt_getRawData; | ||
| 126 | extern fn ZigClangAPSInt_getRawData(*const APSInt) [*:0]const u64; | ||
| 127 | |||
| 128 | pub const getNumWords = ZigClangAPSInt_getNumWords; | ||
| 129 | extern fn ZigClangAPSInt_getNumWords(*const APSInt) c_uint; | ||
| 130 | }; | ||
| 131 | |||
| 132 | pub const ASTContext = opaque { | ||
| 133 | pub const getPointerType = ZigClangASTContext_getPointerType; | ||
| 134 | extern fn ZigClangASTContext_getPointerType(*const ASTContext, T: QualType) QualType; | ||
| 135 | }; | ||
| 136 | |||
| 137 | pub const ASTUnit = opaque { | ||
| 138 | pub const delete = ZigClangASTUnit_delete; | ||
| 139 | extern fn ZigClangASTUnit_delete(*ASTUnit) void; | ||
| 140 | |||
| 141 | pub const getASTContext = ZigClangASTUnit_getASTContext; | ||
| 142 | extern fn ZigClangASTUnit_getASTContext(*ASTUnit) *ASTContext; | ||
| 143 | |||
| 144 | pub const getSourceManager = ZigClangASTUnit_getSourceManager; | ||
| 145 | extern fn ZigClangASTUnit_getSourceManager(*ASTUnit) *SourceManager; | ||
| 146 | |||
| 147 | pub const visitLocalTopLevelDecls = ZigClangASTUnit_visitLocalTopLevelDecls; | ||
| 148 | extern fn ZigClangASTUnit_visitLocalTopLevelDecls(*ASTUnit, context: ?*c_void, Fn: ?fn (?*c_void, *const Decl) callconv(.C) bool) bool; | ||
| 149 | |||
| 150 | pub const getLocalPreprocessingEntities_begin = ZigClangASTUnit_getLocalPreprocessingEntities_begin; | ||
| 151 | extern fn ZigClangASTUnit_getLocalPreprocessingEntities_begin(*ASTUnit) PreprocessingRecord.iterator; | ||
| 152 | |||
| 153 | pub const getLocalPreprocessingEntities_end = ZigClangASTUnit_getLocalPreprocessingEntities_end; | ||
| 154 | extern fn ZigClangASTUnit_getLocalPreprocessingEntities_end(*ASTUnit) PreprocessingRecord.iterator; | ||
| 155 | }; | ||
| 156 | |||
| 157 | pub const ArraySubscriptExpr = opaque { | ||
| 158 | pub const getBase = ZigClangArraySubscriptExpr_getBase; | ||
| 159 | extern fn ZigClangArraySubscriptExpr_getBase(*const ArraySubscriptExpr) *const Expr; | ||
| 160 | |||
| 161 | pub const getIdx = ZigClangArraySubscriptExpr_getIdx; | ||
| 162 | extern fn ZigClangArraySubscriptExpr_getIdx(*const ArraySubscriptExpr) *const Expr; | ||
| 163 | }; | ||
| 164 | |||
| 165 | pub const ArrayType = opaque { | ||
| 166 | pub const getElementType = ZigClangArrayType_getElementType; | ||
| 167 | extern fn ZigClangArrayType_getElementType(*const ArrayType) QualType; | ||
| 168 | }; | ||
| 169 | |||
| 170 | pub const AttributedType = opaque { | ||
| 171 | pub const getEquivalentType = ZigClangAttributedType_getEquivalentType; | ||
| 172 | extern fn ZigClangAttributedType_getEquivalentType(*const AttributedType) QualType; | ||
| 173 | }; | ||
| 174 | |||
| 175 | pub const BinaryOperator = opaque { | ||
| 176 | pub const getOpcode = ZigClangBinaryOperator_getOpcode; | ||
| 177 | extern fn ZigClangBinaryOperator_getOpcode(*const BinaryOperator) BO; | ||
| 178 | |||
| 179 | pub const getBeginLoc = ZigClangBinaryOperator_getBeginLoc; | ||
| 180 | extern fn ZigClangBinaryOperator_getBeginLoc(*const BinaryOperator) SourceLocation; | ||
| 181 | |||
| 182 | pub const getLHS = ZigClangBinaryOperator_getLHS; | ||
| 183 | extern fn ZigClangBinaryOperator_getLHS(*const BinaryOperator) *const Expr; | ||
| 184 | |||
| 185 | pub const getRHS = ZigClangBinaryOperator_getRHS; | ||
| 186 | extern fn ZigClangBinaryOperator_getRHS(*const BinaryOperator) *const Expr; | ||
| 187 | |||
| 188 | pub const getType = ZigClangBinaryOperator_getType; | ||
| 189 | extern fn ZigClangBinaryOperator_getType(*const BinaryOperator) QualType; | ||
| 190 | }; | ||
| 191 | |||
| 192 | pub const BinaryConditionalOperator = opaque {}; | ||
| 193 | |||
| 194 | pub const BreakStmt = opaque {}; | ||
| 195 | |||
| 196 | pub const BuiltinType = opaque { | ||
| 197 | pub const getKind = ZigClangBuiltinType_getKind; | ||
| 198 | extern fn ZigClangBuiltinType_getKind(*const BuiltinType) BuiltinTypeKind; | ||
| 199 | }; | ||
| 200 | |||
| 201 | pub const CStyleCastExpr = opaque { | ||
| 202 | pub const getBeginLoc = ZigClangCStyleCastExpr_getBeginLoc; | ||
| 203 | extern fn ZigClangCStyleCastExpr_getBeginLoc(*const CStyleCastExpr) SourceLocation; | ||
| 204 | |||
| 205 | pub const getSubExpr = ZigClangCStyleCastExpr_getSubExpr; | ||
| 206 | extern fn ZigClangCStyleCastExpr_getSubExpr(*const CStyleCastExpr) *const Expr; | ||
| 207 | |||
| 208 | pub const getType = ZigClangCStyleCastExpr_getType; | ||
| 209 | extern fn ZigClangCStyleCastExpr_getType(*const CStyleCastExpr) QualType; | ||
| 210 | }; | ||
| 211 | |||
| 212 | pub const CallExpr = opaque { | ||
| 213 | pub const getCallee = ZigClangCallExpr_getCallee; | ||
| 214 | extern fn ZigClangCallExpr_getCallee(*const CallExpr) *const Expr; | ||
| 215 | |||
| 216 | pub const getNumArgs = ZigClangCallExpr_getNumArgs; | ||
| 217 | extern fn ZigClangCallExpr_getNumArgs(*const CallExpr) c_uint; | ||
| 218 | |||
| 219 | pub const getArgs = ZigClangCallExpr_getArgs; | ||
| 220 | extern fn ZigClangCallExpr_getArgs(*const CallExpr) [*]const *const Expr; | ||
| 221 | }; | ||
| 222 | |||
| 223 | pub const CaseStmt = opaque { | ||
| 224 | pub const getLHS = ZigClangCaseStmt_getLHS; | ||
| 225 | extern fn ZigClangCaseStmt_getLHS(*const CaseStmt) *const Expr; | ||
| 226 | |||
| 227 | pub const getRHS = ZigClangCaseStmt_getRHS; | ||
| 228 | extern fn ZigClangCaseStmt_getRHS(*const CaseStmt) ?*const Expr; | ||
| 229 | |||
| 230 | pub const getBeginLoc = ZigClangCaseStmt_getBeginLoc; | ||
| 231 | extern fn ZigClangCaseStmt_getBeginLoc(*const CaseStmt) SourceLocation; | ||
| 232 | |||
| 233 | pub const getSubStmt = ZigClangCaseStmt_getSubStmt; | ||
| 234 | extern fn ZigClangCaseStmt_getSubStmt(*const CaseStmt) *const Stmt; | ||
| 235 | }; | ||
| 236 | |||
| 237 | pub const CharacterLiteral = opaque { | ||
| 238 | pub const getBeginLoc = ZigClangCharacterLiteral_getBeginLoc; | ||
| 239 | extern fn ZigClangCharacterLiteral_getBeginLoc(*const CharacterLiteral) SourceLocation; | ||
| 240 | |||
| 241 | pub const getKind = ZigClangCharacterLiteral_getKind; | ||
| 242 | extern fn ZigClangCharacterLiteral_getKind(*const CharacterLiteral) CharacterLiteral_CharacterKind; | ||
| 243 | |||
| 244 | pub const getValue = ZigClangCharacterLiteral_getValue; | ||
| 245 | extern fn ZigClangCharacterLiteral_getValue(*const CharacterLiteral) c_uint; | ||
| 246 | }; | ||
| 247 | |||
| 248 | pub const CompoundAssignOperator = opaque { | ||
| 249 | pub const getType = ZigClangCompoundAssignOperator_getType; | ||
| 250 | extern fn ZigClangCompoundAssignOperator_getType(*const CompoundAssignOperator) QualType; | ||
| 251 | |||
| 252 | pub const getComputationLHSType = ZigClangCompoundAssignOperator_getComputationLHSType; | ||
| 253 | extern fn ZigClangCompoundAssignOperator_getComputationLHSType(*const CompoundAssignOperator) QualType; | ||
| 254 | |||
| 255 | pub const getComputationResultType = ZigClangCompoundAssignOperator_getComputationResultType; | ||
| 256 | extern fn ZigClangCompoundAssignOperator_getComputationResultType(*const CompoundAssignOperator) QualType; | ||
| 257 | |||
| 258 | pub const getBeginLoc = ZigClangCompoundAssignOperator_getBeginLoc; | ||
| 259 | extern fn ZigClangCompoundAssignOperator_getBeginLoc(*const CompoundAssignOperator) SourceLocation; | ||
| 260 | |||
| 261 | pub const getOpcode = ZigClangCompoundAssignOperator_getOpcode; | ||
| 262 | extern fn ZigClangCompoundAssignOperator_getOpcode(*const CompoundAssignOperator) BO; | ||
| 263 | |||
| 264 | pub const getLHS = ZigClangCompoundAssignOperator_getLHS; | ||
| 265 | extern fn ZigClangCompoundAssignOperator_getLHS(*const CompoundAssignOperator) *const Expr; | ||
| 266 | |||
| 267 | pub const getRHS = ZigClangCompoundAssignOperator_getRHS; | ||
| 268 | extern fn ZigClangCompoundAssignOperator_getRHS(*const CompoundAssignOperator) *const Expr; | ||
| 269 | }; | ||
| 270 | |||
| 271 | pub const CompoundStmt = opaque { | ||
| 272 | pub const body_begin = ZigClangCompoundStmt_body_begin; | ||
| 273 | extern fn ZigClangCompoundStmt_body_begin(*const CompoundStmt) const_body_iterator; | ||
| 274 | |||
| 275 | pub const body_end = ZigClangCompoundStmt_body_end; | ||
| 276 | extern fn ZigClangCompoundStmt_body_end(*const CompoundStmt) const_body_iterator; | ||
| 277 | |||
| 278 | pub const const_body_iterator = [*]const *Stmt; | ||
| 279 | }; | ||
| 280 | |||
| 281 | pub const ConditionalOperator = opaque {}; | ||
| 282 | |||
| 283 | pub const ConstantArrayType = opaque { | ||
| 284 | pub const getElementType = ZigClangConstantArrayType_getElementType; | ||
| 285 | extern fn ZigClangConstantArrayType_getElementType(*const ConstantArrayType) QualType; | ||
| 286 | |||
| 287 | pub const getSize = ZigClangConstantArrayType_getSize; | ||
| 288 | extern fn ZigClangConstantArrayType_getSize(*const ConstantArrayType) *const APInt; | ||
| 289 | }; | ||
| 290 | |||
| 291 | pub const ConstantExpr = opaque {}; | ||
| 292 | |||
| 293 | pub const ContinueStmt = opaque {}; | ||
| 294 | |||
| 295 | pub const DecayedType = opaque { | ||
| 296 | pub const getDecayedType = ZigClangDecayedType_getDecayedType; | ||
| 297 | extern fn ZigClangDecayedType_getDecayedType(*const DecayedType) QualType; | ||
| 298 | }; | ||
| 299 | |||
| 300 | pub const Decl = opaque { | ||
| 301 | pub const getLocation = ZigClangDecl_getLocation; | ||
| 302 | extern fn ZigClangDecl_getLocation(*const Decl) SourceLocation; | ||
| 303 | |||
| 304 | pub const castToNamedDecl = ZigClangDecl_castToNamedDecl; | ||
| 305 | extern fn ZigClangDecl_castToNamedDecl(decl: *const Decl) ?*const NamedDecl; | ||
| 306 | |||
| 307 | pub const getKind = ZigClangDecl_getKind; | ||
| 308 | extern fn ZigClangDecl_getKind(decl: *const Decl) DeclKind; | ||
| 309 | |||
| 310 | pub const getDeclKindName = ZigClangDecl_getDeclKindName; | ||
| 311 | extern fn ZigClangDecl_getDeclKindName(decl: *const Decl) [*:0]const u8; | ||
| 312 | }; | ||
| 313 | |||
| 314 | pub const DeclRefExpr = opaque { | ||
| 315 | pub const getDecl = ZigClangDeclRefExpr_getDecl; | ||
| 316 | extern fn ZigClangDeclRefExpr_getDecl(*const DeclRefExpr) *const ValueDecl; | ||
| 317 | |||
| 318 | pub const getFoundDecl = ZigClangDeclRefExpr_getFoundDecl; | ||
| 319 | extern fn ZigClangDeclRefExpr_getFoundDecl(*const DeclRefExpr) *const NamedDecl; | ||
| 320 | }; | ||
| 321 | |||
| 322 | pub const DeclStmt = opaque { | ||
| 323 | pub const decl_begin = ZigClangDeclStmt_decl_begin; | ||
| 324 | extern fn ZigClangDeclStmt_decl_begin(*const DeclStmt) const_decl_iterator; | ||
| 325 | |||
| 326 | pub const decl_end = ZigClangDeclStmt_decl_end; | ||
| 327 | extern fn ZigClangDeclStmt_decl_end(*const DeclStmt) const_decl_iterator; | ||
| 328 | |||
| 329 | pub const const_decl_iterator = [*]const *Decl; | ||
| 330 | }; | ||
| 331 | |||
| 332 | pub const DefaultStmt = opaque { | ||
| 333 | pub const getSubStmt = ZigClangDefaultStmt_getSubStmt; | ||
| 334 | extern fn ZigClangDefaultStmt_getSubStmt(*const DefaultStmt) *const Stmt; | ||
| 335 | }; | ||
| 336 | |||
| 337 | pub const DiagnosticOptions = opaque {}; | ||
| 338 | |||
| 339 | pub const DiagnosticsEngine = opaque {}; | ||
| 340 | |||
| 341 | pub const DoStmt = opaque { | ||
| 342 | pub const getCond = ZigClangDoStmt_getCond; | ||
| 343 | extern fn ZigClangDoStmt_getCond(*const DoStmt) *const Expr; | ||
| 344 | |||
| 345 | pub const getBody = ZigClangDoStmt_getBody; | ||
| 346 | extern fn ZigClangDoStmt_getBody(*const DoStmt) *const Stmt; | ||
| 347 | }; | ||
| 348 | |||
| 349 | pub const ElaboratedType = opaque { | ||
| 350 | pub const getNamedType = ZigClangElaboratedType_getNamedType; | ||
| 351 | extern fn ZigClangElaboratedType_getNamedType(*const ElaboratedType) QualType; | ||
| 352 | }; | ||
| 353 | |||
| 354 | pub const EnumConstantDecl = opaque { | ||
| 355 | pub const getInitExpr = ZigClangEnumConstantDecl_getInitExpr; | ||
| 356 | extern fn ZigClangEnumConstantDecl_getInitExpr(*const EnumConstantDecl) ?*const Expr; | ||
| 357 | |||
| 358 | pub const getInitVal = ZigClangEnumConstantDecl_getInitVal; | ||
| 359 | extern fn ZigClangEnumConstantDecl_getInitVal(*const EnumConstantDecl) *const APSInt; | ||
| 360 | }; | ||
| 361 | |||
| 362 | pub const EnumDecl = opaque { | ||
| 363 | pub const getCanonicalDecl = ZigClangEnumDecl_getCanonicalDecl; | ||
| 364 | extern fn ZigClangEnumDecl_getCanonicalDecl(*const EnumDecl) ?*const TagDecl; | ||
| 365 | |||
| 366 | pub const getIntegerType = ZigClangEnumDecl_getIntegerType; | ||
| 367 | extern fn ZigClangEnumDecl_getIntegerType(*const EnumDecl) QualType; | ||
| 368 | |||
| 369 | pub const getDefinition = ZigClangEnumDecl_getDefinition; | ||
| 370 | extern fn ZigClangEnumDecl_getDefinition(*const EnumDecl) ?*const EnumDecl; | ||
| 371 | |||
| 372 | pub const getLocation = ZigClangEnumDecl_getLocation; | ||
| 373 | extern fn ZigClangEnumDecl_getLocation(*const EnumDecl) SourceLocation; | ||
| 374 | |||
| 375 | pub const enumerator_begin = ZigClangEnumDecl_enumerator_begin; | ||
| 376 | extern fn ZigClangEnumDecl_enumerator_begin(*const EnumDecl) enumerator_iterator; | ||
| 377 | |||
| 378 | pub const enumerator_end = ZigClangEnumDecl_enumerator_end; | ||
| 379 | extern fn ZigClangEnumDecl_enumerator_end(*const EnumDecl) enumerator_iterator; | ||
| 380 | |||
| 381 | pub const enumerator_iterator = extern struct { | ||
| 382 | ptr: *c_void, | ||
| 383 | |||
| 384 | pub const next = ZigClangEnumDecl_enumerator_iterator_next; | ||
| 385 | extern fn ZigClangEnumDecl_enumerator_iterator_next(enumerator_iterator) enumerator_iterator; | ||
| 386 | |||
| 387 | pub const deref = ZigClangEnumDecl_enumerator_iterator_deref; | ||
| 388 | extern fn ZigClangEnumDecl_enumerator_iterator_deref(enumerator_iterator) *const EnumConstantDecl; | ||
| 389 | |||
| 390 | pub const neq = ZigClangEnumDecl_enumerator_iterator_neq; | ||
| 391 | extern fn ZigClangEnumDecl_enumerator_iterator_neq(enumerator_iterator, enumerator_iterator) bool; | ||
| 392 | }; | ||
| 393 | }; | ||
| 394 | |||
| 395 | pub const EnumType = opaque { | ||
| 396 | pub const getDecl = ZigClangEnumType_getDecl; | ||
| 397 | extern fn ZigClangEnumType_getDecl(*const EnumType) *const EnumDecl; | ||
| 398 | }; | ||
| 399 | |||
| 400 | pub const Expr = opaque { | ||
| 401 | pub const getStmtClass = ZigClangExpr_getStmtClass; | ||
| 402 | extern fn ZigClangExpr_getStmtClass(*const Expr) StmtClass; | ||
| 403 | |||
| 404 | pub const getType = ZigClangExpr_getType; | ||
| 405 | extern fn ZigClangExpr_getType(*const Expr) QualType; | ||
| 406 | |||
| 407 | pub const getBeginLoc = ZigClangExpr_getBeginLoc; | ||
| 408 | extern fn ZigClangExpr_getBeginLoc(*const Expr) SourceLocation; | ||
| 409 | |||
| 410 | pub const EvaluateAsConstantExpr = ZigClangExpr_EvaluateAsConstantExpr; | ||
| 411 | extern fn ZigClangExpr_EvaluateAsConstantExpr(*const Expr, *ExprEvalResult, Expr_ConstExprUsage, *const ASTContext) bool; | ||
| 412 | }; | ||
| 413 | |||
| 414 | pub const FieldDecl = opaque { | ||
| 415 | pub const getCanonicalDecl = ZigClangFieldDecl_getCanonicalDecl; | ||
| 416 | extern fn ZigClangFieldDecl_getCanonicalDecl(*const FieldDecl) ?*const FieldDecl; | ||
| 417 | |||
| 418 | pub const getAlignedAttribute = ZigClangFieldDecl_getAlignedAttribute; | ||
| 419 | extern fn ZigClangFieldDecl_getAlignedAttribute(*const FieldDecl, *const ASTContext) c_uint; | ||
| 420 | |||
| 421 | pub const isAnonymousStructOrUnion = ZigClangFieldDecl_isAnonymousStructOrUnion; | ||
| 422 | extern fn ZigClangFieldDecl_isAnonymousStructOrUnion(*const FieldDecl) bool; | ||
| 423 | |||
| 424 | pub const isBitField = ZigClangFieldDecl_isBitField; | ||
| 425 | extern fn ZigClangFieldDecl_isBitField(*const FieldDecl) bool; | ||
| 426 | |||
| 427 | pub const getType = ZigClangFieldDecl_getType; | ||
| 428 | extern fn ZigClangFieldDecl_getType(*const FieldDecl) QualType; | ||
| 429 | |||
| 430 | pub const getLocation = ZigClangFieldDecl_getLocation; | ||
| 431 | extern fn ZigClangFieldDecl_getLocation(*const FieldDecl) SourceLocation; | ||
| 432 | }; | ||
| 433 | |||
| 434 | pub const FileID = opaque {}; | ||
| 435 | |||
| 436 | pub const FloatingLiteral = opaque { | ||
| 437 | pub const getValueAsApproximateDouble = ZigClangAPFloat_getValueAsApproximateDouble; | ||
| 438 | extern fn ZigClangAPFloat_getValueAsApproximateDouble(*const FloatingLiteral) f64; | ||
| 439 | }; | ||
| 440 | |||
| 441 | pub const ForStmt = opaque { | ||
| 442 | pub const getInit = ZigClangForStmt_getInit; | ||
| 443 | extern fn ZigClangForStmt_getInit(*const ForStmt) ?*const Stmt; | ||
| 444 | |||
| 445 | pub const getCond = ZigClangForStmt_getCond; | ||
| 446 | extern fn ZigClangForStmt_getCond(*const ForStmt) ?*const Expr; | ||
| 447 | |||
| 448 | pub const getInc = ZigClangForStmt_getInc; | ||
| 449 | extern fn ZigClangForStmt_getInc(*const ForStmt) ?*const Expr; | ||
| 450 | |||
| 451 | pub const getBody = ZigClangForStmt_getBody; | ||
| 452 | extern fn ZigClangForStmt_getBody(*const ForStmt) *const Stmt; | ||
| 453 | }; | ||
| 454 | |||
| 455 | pub const FullSourceLoc = opaque {}; | ||
| 456 | |||
| 457 | pub const FunctionDecl = opaque { | ||
| 458 | pub const getType = ZigClangFunctionDecl_getType; | ||
| 459 | extern fn ZigClangFunctionDecl_getType(*const FunctionDecl) QualType; | ||
| 460 | |||
| 461 | pub const getLocation = ZigClangFunctionDecl_getLocation; | ||
| 462 | extern fn ZigClangFunctionDecl_getLocation(*const FunctionDecl) SourceLocation; | ||
| 463 | |||
| 464 | pub const hasBody = ZigClangFunctionDecl_hasBody; | ||
| 465 | extern fn ZigClangFunctionDecl_hasBody(*const FunctionDecl) bool; | ||
| 466 | |||
| 467 | pub const getStorageClass = ZigClangFunctionDecl_getStorageClass; | ||
| 468 | extern fn ZigClangFunctionDecl_getStorageClass(*const FunctionDecl) StorageClass; | ||
| 469 | |||
| 470 | pub const getParamDecl = ZigClangFunctionDecl_getParamDecl; | ||
| 471 | extern fn ZigClangFunctionDecl_getParamDecl(*const FunctionDecl, i: c_uint) *const ParmVarDecl; | ||
| 472 | |||
| 473 | pub const getBody = ZigClangFunctionDecl_getBody; | ||
| 474 | extern fn ZigClangFunctionDecl_getBody(*const FunctionDecl) *const Stmt; | ||
| 475 | |||
| 476 | pub const doesDeclarationForceExternallyVisibleDefinition = ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition; | ||
| 477 | extern fn ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(*const FunctionDecl) bool; | ||
| 478 | |||
| 479 | pub const isThisDeclarationADefinition = ZigClangFunctionDecl_isThisDeclarationADefinition; | ||
| 480 | extern fn ZigClangFunctionDecl_isThisDeclarationADefinition(*const FunctionDecl) bool; | ||
| 481 | |||
| 482 | pub const doesThisDeclarationHaveABody = ZigClangFunctionDecl_doesThisDeclarationHaveABody; | ||
| 483 | extern fn ZigClangFunctionDecl_doesThisDeclarationHaveABody(*const FunctionDecl) bool; | ||
| 484 | |||
| 485 | pub const isInlineSpecified = ZigClangFunctionDecl_isInlineSpecified; | ||
| 486 | extern fn ZigClangFunctionDecl_isInlineSpecified(*const FunctionDecl) bool; | ||
| 487 | |||
| 488 | pub const isDefined = ZigClangFunctionDecl_isDefined; | ||
| 489 | extern fn ZigClangFunctionDecl_isDefined(*const FunctionDecl) bool; | ||
| 490 | |||
| 491 | pub const getDefinition = ZigClangFunctionDecl_getDefinition; | ||
| 492 | extern fn ZigClangFunctionDecl_getDefinition(*const FunctionDecl) ?*const FunctionDecl; | ||
| 493 | |||
| 494 | pub const getSectionAttribute = ZigClangFunctionDecl_getSectionAttribute; | ||
| 495 | extern fn ZigClangFunctionDecl_getSectionAttribute(*const FunctionDecl, len: *usize) ?[*]const u8; | ||
| 496 | |||
| 497 | pub const getCanonicalDecl = ZigClangFunctionDecl_getCanonicalDecl; | ||
| 498 | extern fn ZigClangFunctionDecl_getCanonicalDecl(*const FunctionDecl) ?*const FunctionDecl; | ||
| 499 | |||
| 500 | pub const getAlignedAttribute = ZigClangFunctionDecl_getAlignedAttribute; | ||
| 501 | extern fn ZigClangFunctionDecl_getAlignedAttribute(*const FunctionDecl, *const ASTContext) c_uint; | ||
| 502 | }; | ||
| 503 | |||
| 504 | pub const FunctionProtoType = opaque { | ||
| 505 | pub const isVariadic = ZigClangFunctionProtoType_isVariadic; | ||
| 506 | extern fn ZigClangFunctionProtoType_isVariadic(*const FunctionProtoType) bool; | ||
| 507 | |||
| 508 | pub const getNumParams = ZigClangFunctionProtoType_getNumParams; | ||
| 509 | extern fn ZigClangFunctionProtoType_getNumParams(*const FunctionProtoType) c_uint; | ||
| 510 | |||
| 511 | pub const getParamType = ZigClangFunctionProtoType_getParamType; | ||
| 512 | extern fn ZigClangFunctionProtoType_getParamType(*const FunctionProtoType, i: c_uint) QualType; | ||
| 513 | |||
| 514 | pub const getReturnType = ZigClangFunctionProtoType_getReturnType; | ||
| 515 | extern fn ZigClangFunctionProtoType_getReturnType(*const FunctionProtoType) QualType; | ||
| 516 | }; | ||
| 517 | |||
| 518 | pub const FunctionType = opaque { | ||
| 519 | pub const getNoReturnAttr = ZigClangFunctionType_getNoReturnAttr; | ||
| 520 | extern fn ZigClangFunctionType_getNoReturnAttr(*const FunctionType) bool; | ||
| 521 | |||
| 522 | pub const getCallConv = ZigClangFunctionType_getCallConv; | ||
| 523 | extern fn ZigClangFunctionType_getCallConv(*const FunctionType) CallingConv; | ||
| 524 | |||
| 525 | pub const getReturnType = ZigClangFunctionType_getReturnType; | ||
| 526 | extern fn ZigClangFunctionType_getReturnType(*const FunctionType) QualType; | ||
| 527 | }; | ||
| 528 | |||
| 529 | pub const IfStmt = opaque { | ||
| 530 | pub const getThen = ZigClangIfStmt_getThen; | ||
| 531 | extern fn ZigClangIfStmt_getThen(*const IfStmt) *const Stmt; | ||
| 532 | |||
| 533 | pub const getElse = ZigClangIfStmt_getElse; | ||
| 534 | extern fn ZigClangIfStmt_getElse(*const IfStmt) ?*const Stmt; | ||
| 535 | |||
| 536 | pub const getCond = ZigClangIfStmt_getCond; | ||
| 537 | extern fn ZigClangIfStmt_getCond(*const IfStmt) *const Stmt; | ||
| 538 | }; | ||
| 539 | |||
| 540 | pub const ImplicitCastExpr = opaque { | ||
| 541 | pub const getBeginLoc = ZigClangImplicitCastExpr_getBeginLoc; | ||
| 542 | extern fn ZigClangImplicitCastExpr_getBeginLoc(*const ImplicitCastExpr) SourceLocation; | ||
| 543 | |||
| 544 | pub const getCastKind = ZigClangImplicitCastExpr_getCastKind; | ||
| 545 | extern fn ZigClangImplicitCastExpr_getCastKind(*const ImplicitCastExpr) CK; | ||
| 546 | |||
| 547 | pub const getSubExpr = ZigClangImplicitCastExpr_getSubExpr; | ||
| 548 | extern fn ZigClangImplicitCastExpr_getSubExpr(*const ImplicitCastExpr) *const Expr; | ||
| 549 | }; | ||
| 550 | |||
| 551 | pub const IncompleteArrayType = opaque { | ||
| 552 | pub const getElementType = ZigClangIncompleteArrayType_getElementType; | ||
| 553 | extern fn ZigClangIncompleteArrayType_getElementType(*const IncompleteArrayType) QualType; | ||
| 554 | }; | ||
| 555 | |||
| 556 | pub const IntegerLiteral = opaque { | ||
| 557 | pub const EvaluateAsInt = ZigClangIntegerLiteral_EvaluateAsInt; | ||
| 558 | extern fn ZigClangIntegerLiteral_EvaluateAsInt(*const IntegerLiteral, *ExprEvalResult, *const ASTContext) bool; | ||
| 559 | |||
| 560 | pub const getBeginLoc = ZigClangIntegerLiteral_getBeginLoc; | ||
| 561 | extern fn ZigClangIntegerLiteral_getBeginLoc(*const IntegerLiteral) SourceLocation; | ||
| 562 | |||
| 563 | pub const isZero = ZigClangIntegerLiteral_isZero; | ||
| 564 | extern fn ZigClangIntegerLiteral_isZero(*const IntegerLiteral, *bool, *const ASTContext) bool; | ||
| 565 | }; | ||
| 566 | |||
| 567 | pub const MacroDefinitionRecord = opaque { | ||
| 568 | pub const getName_getNameStart = ZigClangMacroDefinitionRecord_getName_getNameStart; | ||
| 569 | extern fn ZigClangMacroDefinitionRecord_getName_getNameStart(*const MacroDefinitionRecord) [*:0]const u8; | ||
| 570 | |||
| 571 | pub const getSourceRange_getBegin = ZigClangMacroDefinitionRecord_getSourceRange_getBegin; | ||
| 572 | extern fn ZigClangMacroDefinitionRecord_getSourceRange_getBegin(*const MacroDefinitionRecord) SourceLocation; | ||
| 573 | |||
| 574 | pub const getSourceRange_getEnd = ZigClangMacroDefinitionRecord_getSourceRange_getEnd; | ||
| 575 | extern fn ZigClangMacroDefinitionRecord_getSourceRange_getEnd(*const MacroDefinitionRecord) SourceLocation; | ||
| 576 | }; | ||
| 577 | |||
| 578 | pub const MacroQualifiedType = opaque { | ||
| 579 | pub const getModifiedType = ZigClangMacroQualifiedType_getModifiedType; | ||
| 580 | extern fn ZigClangMacroQualifiedType_getModifiedType(*const MacroQualifiedType) QualType; | ||
| 581 | }; | ||
| 582 | |||
| 583 | pub const MemberExpr = opaque { | ||
| 584 | pub const getBase = ZigClangMemberExpr_getBase; | ||
| 585 | extern fn ZigClangMemberExpr_getBase(*const MemberExpr) *const Expr; | ||
| 586 | |||
| 587 | pub const isArrow = ZigClangMemberExpr_isArrow; | ||
| 588 | extern fn ZigClangMemberExpr_isArrow(*const MemberExpr) bool; | ||
| 589 | |||
| 590 | pub const getMemberDecl = ZigClangMemberExpr_getMemberDecl; | ||
| 591 | extern fn ZigClangMemberExpr_getMemberDecl(*const MemberExpr) *const ValueDecl; | ||
| 592 | }; | ||
| 593 | |||
| 594 | pub const NamedDecl = opaque { | ||
| 595 | pub const getName_bytes_begin = ZigClangNamedDecl_getName_bytes_begin; | ||
| 596 | extern fn ZigClangNamedDecl_getName_bytes_begin(decl: *const NamedDecl) [*:0]const u8; | ||
| 597 | }; | ||
| 598 | |||
| 599 | pub const None = opaque {}; | ||
| 600 | |||
| 601 | pub const OpaqueValueExpr = opaque { | ||
| 602 | pub const getSourceExpr = ZigClangOpaqueValueExpr_getSourceExpr; | ||
| 603 | extern fn ZigClangOpaqueValueExpr_getSourceExpr(*const OpaqueValueExpr) ?*const Expr; | ||
| 604 | }; | ||
| 605 | |||
| 606 | pub const PCHContainerOperations = opaque {}; | ||
| 607 | |||
| 608 | pub const ParenExpr = opaque { | ||
| 609 | pub const getSubExpr = ZigClangParenExpr_getSubExpr; | ||
| 610 | extern fn ZigClangParenExpr_getSubExpr(*const ParenExpr) *const Expr; | ||
| 611 | }; | ||
| 612 | |||
| 613 | pub const ParenType = opaque { | ||
| 614 | pub const getInnerType = ZigClangParenType_getInnerType; | ||
| 615 | extern fn ZigClangParenType_getInnerType(*const ParenType) QualType; | ||
| 616 | }; | ||
| 617 | |||
| 618 | pub const ParmVarDecl = opaque { | ||
| 619 | pub const getOriginalType = ZigClangParmVarDecl_getOriginalType; | ||
| 620 | extern fn ZigClangParmVarDecl_getOriginalType(*const ParmVarDecl) QualType; | ||
| 621 | }; | ||
| 622 | |||
| 623 | pub const PointerType = opaque {}; | ||
| 624 | |||
| 625 | pub const PredefinedExpr = opaque { | ||
| 626 | pub const getFunctionName = ZigClangPredefinedExpr_getFunctionName; | ||
| 627 | extern fn ZigClangPredefinedExpr_getFunctionName(*const PredefinedExpr) *const StringLiteral; | ||
| 628 | }; | ||
| 629 | |||
| 630 | pub const PreprocessedEntity = opaque { | ||
| 631 | pub const getKind = ZigClangPreprocessedEntity_getKind; | ||
| 632 | extern fn ZigClangPreprocessedEntity_getKind(*const PreprocessedEntity) PreprocessedEntity_EntityKind; | ||
| 633 | }; | ||
| 634 | |||
| 635 | pub const PreprocessingRecord = opaque { | ||
| 636 | pub const iterator = extern struct { | ||
| 637 | I: c_int, | ||
| 638 | Self: *PreprocessingRecord, | ||
| 639 | |||
| 640 | pub const deref = ZigClangPreprocessingRecord_iterator_deref; | ||
| 641 | extern fn ZigClangPreprocessingRecord_iterator_deref(iterator) *PreprocessedEntity; | ||
| 642 | }; | ||
| 643 | }; | ||
| 644 | |||
| 645 | pub const RecordDecl = opaque { | ||
| 646 | pub const getCanonicalDecl = ZigClangRecordDecl_getCanonicalDecl; | ||
| 647 | extern fn ZigClangRecordDecl_getCanonicalDecl(*const RecordDecl) ?*const TagDecl; | ||
| 648 | |||
| 649 | pub const isUnion = ZigClangRecordDecl_isUnion; | ||
| 650 | extern fn ZigClangRecordDecl_isUnion(*const RecordDecl) bool; | ||
| 651 | |||
| 652 | pub const isStruct = ZigClangRecordDecl_isStruct; | ||
| 653 | extern fn ZigClangRecordDecl_isStruct(*const RecordDecl) bool; | ||
| 654 | |||
| 655 | pub const isAnonymousStructOrUnion = ZigClangRecordDecl_isAnonymousStructOrUnion; | ||
| 656 | extern fn ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl: ?*const RecordDecl) bool; | ||
| 657 | |||
| 658 | pub const getPackedAttribute = ZigClangRecordDecl_getPackedAttribute; | ||
| 659 | extern fn ZigClangRecordDecl_getPackedAttribute(*const RecordDecl) bool; | ||
| 660 | |||
| 661 | pub const getDefinition = ZigClangRecordDecl_getDefinition; | ||
| 662 | extern fn ZigClangRecordDecl_getDefinition(*const RecordDecl) ?*const RecordDecl; | ||
| 663 | |||
| 664 | pub const getLocation = ZigClangRecordDecl_getLocation; | ||
| 665 | extern fn ZigClangRecordDecl_getLocation(*const RecordDecl) SourceLocation; | ||
| 666 | |||
| 667 | pub const field_begin = ZigClangRecordDecl_field_begin; | ||
| 668 | extern fn ZigClangRecordDecl_field_begin(*const RecordDecl) field_iterator; | ||
| 669 | |||
| 670 | pub const field_end = ZigClangRecordDecl_field_end; | ||
| 671 | extern fn ZigClangRecordDecl_field_end(*const RecordDecl) field_iterator; | ||
| 672 | |||
| 673 | pub const field_iterator = extern struct { | ||
| 674 | ptr: *c_void, | ||
| 675 | |||
| 676 | pub const next = ZigClangRecordDecl_field_iterator_next; | ||
| 677 | extern fn ZigClangRecordDecl_field_iterator_next(field_iterator) field_iterator; | ||
| 678 | |||
| 679 | pub const deref = ZigClangRecordDecl_field_iterator_deref; | ||
| 680 | extern fn ZigClangRecordDecl_field_iterator_deref(field_iterator) *const FieldDecl; | ||
| 681 | |||
| 682 | pub const neq = ZigClangRecordDecl_field_iterator_neq; | ||
| 683 | extern fn ZigClangRecordDecl_field_iterator_neq(field_iterator, field_iterator) bool; | ||
| 684 | }; | ||
| 685 | }; | ||
| 686 | |||
| 687 | pub const RecordType = opaque { | ||
| 688 | pub const getDecl = ZigClangRecordType_getDecl; | ||
| 689 | extern fn ZigClangRecordType_getDecl(*const RecordType) *const RecordDecl; | ||
| 690 | }; | ||
| 691 | |||
| 692 | pub const ReturnStmt = opaque { | ||
| 693 | pub const getRetValue = ZigClangReturnStmt_getRetValue; | ||
| 694 | extern fn ZigClangReturnStmt_getRetValue(*const ReturnStmt) ?*const Expr; | ||
| 695 | }; | ||
| 696 | |||
| 697 | pub const SkipFunctionBodiesScope = opaque {}; | ||
| 698 | |||
| 699 | pub const SourceManager = opaque { | ||
| 700 | pub const getSpellingLoc = ZigClangSourceManager_getSpellingLoc; | ||
| 701 | extern fn ZigClangSourceManager_getSpellingLoc(*const SourceManager, Loc: SourceLocation) SourceLocation; | ||
| 702 | |||
| 703 | pub const getFilename = ZigClangSourceManager_getFilename; | ||
| 704 | extern fn ZigClangSourceManager_getFilename(*const SourceManager, SpellingLoc: SourceLocation) ?[*:0]const u8; | ||
| 705 | |||
| 706 | pub const getSpellingLineNumber = ZigClangSourceManager_getSpellingLineNumber; | ||
| 707 | extern fn ZigClangSourceManager_getSpellingLineNumber(*const SourceManager, Loc: SourceLocation) c_uint; | ||
| 708 | |||
| 709 | pub const getSpellingColumnNumber = ZigClangSourceManager_getSpellingColumnNumber; | ||
| 710 | extern fn ZigClangSourceManager_getSpellingColumnNumber(*const SourceManager, Loc: SourceLocation) c_uint; | ||
| 711 | |||
| 712 | pub const getCharacterData = ZigClangSourceManager_getCharacterData; | ||
| 713 | extern fn ZigClangSourceManager_getCharacterData(*const SourceManager, SL: SourceLocation) [*:0]const u8; | ||
| 714 | }; | ||
| 715 | |||
| 716 | pub const SourceRange = opaque {}; | ||
| 717 | |||
| 718 | pub const Stmt = opaque { | ||
| 719 | pub const getBeginLoc = ZigClangStmt_getBeginLoc; | ||
| 720 | extern fn ZigClangStmt_getBeginLoc(*const Stmt) SourceLocation; | ||
| 721 | |||
| 722 | pub const getStmtClass = ZigClangStmt_getStmtClass; | ||
| 723 | extern fn ZigClangStmt_getStmtClass(*const Stmt) StmtClass; | ||
| 724 | |||
| 725 | pub const classof_Expr = ZigClangStmt_classof_Expr; | ||
| 726 | extern fn ZigClangStmt_classof_Expr(*const Stmt) bool; | ||
| 727 | }; | ||
| 728 | |||
| 729 | pub const StmtExpr = opaque { | ||
| 730 | pub const getSubStmt = ZigClangStmtExpr_getSubStmt; | ||
| 731 | extern fn ZigClangStmtExpr_getSubStmt(*const StmtExpr) *const CompoundStmt; | ||
| 732 | }; | ||
| 733 | |||
| 734 | pub const StringLiteral = opaque { | ||
| 735 | pub const getKind = ZigClangStringLiteral_getKind; | ||
| 736 | extern fn ZigClangStringLiteral_getKind(*const StringLiteral) StringLiteral_StringKind; | ||
| 737 | |||
| 738 | pub const getString_bytes_begin_size = ZigClangStringLiteral_getString_bytes_begin_size; | ||
| 739 | extern fn ZigClangStringLiteral_getString_bytes_begin_size(*const StringLiteral, *usize) [*]const u8; | ||
| 740 | }; | ||
| 741 | |||
| 742 | pub const StringRef = opaque {}; | ||
| 743 | |||
| 744 | pub const SwitchStmt = opaque { | ||
| 745 | pub const getConditionVariableDeclStmt = ZigClangSwitchStmt_getConditionVariableDeclStmt; | ||
| 746 | extern fn ZigClangSwitchStmt_getConditionVariableDeclStmt(*const SwitchStmt) ?*const DeclStmt; | ||
| 747 | |||
| 748 | pub const getCond = ZigClangSwitchStmt_getCond; | ||
| 749 | extern fn ZigClangSwitchStmt_getCond(*const SwitchStmt) *const Expr; | ||
| 750 | |||
| 751 | pub const getBody = ZigClangSwitchStmt_getBody; | ||
| 752 | extern fn ZigClangSwitchStmt_getBody(*const SwitchStmt) *const Stmt; | ||
| 753 | |||
| 754 | pub const isAllEnumCasesCovered = ZigClangSwitchStmt_isAllEnumCasesCovered; | ||
| 755 | extern fn ZigClangSwitchStmt_isAllEnumCasesCovered(*const SwitchStmt) bool; | ||
| 756 | }; | ||
| 757 | |||
| 758 | pub const TagDecl = opaque { | ||
| 759 | pub const isThisDeclarationADefinition = ZigClangTagDecl_isThisDeclarationADefinition; | ||
| 760 | extern fn ZigClangTagDecl_isThisDeclarationADefinition(*const TagDecl) bool; | ||
| 761 | }; | ||
| 762 | |||
| 763 | pub const Type = opaque { | ||
| 764 | pub const getTypeClass = ZigClangType_getTypeClass; | ||
| 765 | extern fn ZigClangType_getTypeClass(*const Type) TypeClass; | ||
| 766 | |||
| 767 | pub const getPointeeType = ZigClangType_getPointeeType; | ||
| 768 | extern fn ZigClangType_getPointeeType(*const Type) QualType; | ||
| 769 | |||
| 770 | pub const isVoidType = ZigClangType_isVoidType; | ||
| 771 | extern fn ZigClangType_isVoidType(*const Type) bool; | ||
| 772 | |||
| 773 | pub const isConstantArrayType = ZigClangType_isConstantArrayType; | ||
| 774 | extern fn ZigClangType_isConstantArrayType(*const Type) bool; | ||
| 775 | |||
| 776 | pub const isRecordType = ZigClangType_isRecordType; | ||
| 777 | extern fn ZigClangType_isRecordType(*const Type) bool; | ||
| 778 | |||
| 779 | pub const isIncompleteOrZeroLengthArrayType = ZigClangType_isIncompleteOrZeroLengthArrayType; | ||
| 780 | extern fn ZigClangType_isIncompleteOrZeroLengthArrayType(*const Type, *const ASTContext) bool; | ||
| 781 | |||
| 782 | pub const isArrayType = ZigClangType_isArrayType; | ||
| 783 | extern fn ZigClangType_isArrayType(*const Type) bool; | ||
| 784 | |||
| 785 | pub const isBooleanType = ZigClangType_isBooleanType; | ||
| 786 | extern fn ZigClangType_isBooleanType(*const Type) bool; | ||
| 787 | |||
| 788 | pub const getTypeClassName = ZigClangType_getTypeClassName; | ||
| 789 | extern fn ZigClangType_getTypeClassName(*const Type) [*:0]const u8; | ||
| 790 | |||
| 791 | pub const getAsArrayTypeUnsafe = ZigClangType_getAsArrayTypeUnsafe; | ||
| 792 | extern fn ZigClangType_getAsArrayTypeUnsafe(*const Type) *const ArrayType; | ||
| 793 | |||
| 794 | pub const getAsRecordType = ZigClangType_getAsRecordType; | ||
| 795 | extern fn ZigClangType_getAsRecordType(*const Type) ?*const RecordType; | ||
| 796 | |||
| 797 | pub const getAsUnionType = ZigClangType_getAsUnionType; | ||
| 798 | extern fn ZigClangType_getAsUnionType(*const Type) ?*const RecordType; | ||
| 799 | }; | ||
| 800 | |||
| 801 | pub const TypedefNameDecl = opaque { | ||
| 802 | pub const getUnderlyingType = ZigClangTypedefNameDecl_getUnderlyingType; | ||
| 803 | extern fn ZigClangTypedefNameDecl_getUnderlyingType(*const TypedefNameDecl) QualType; | ||
| 804 | |||
| 805 | pub const getCanonicalDecl = ZigClangTypedefNameDecl_getCanonicalDecl; | ||
| 806 | extern fn ZigClangTypedefNameDecl_getCanonicalDecl(*const TypedefNameDecl) ?*const TypedefNameDecl; | ||
| 807 | |||
| 808 | pub const getLocation = ZigClangTypedefNameDecl_getLocation; | ||
| 809 | extern fn ZigClangTypedefNameDecl_getLocation(*const TypedefNameDecl) SourceLocation; | ||
| 810 | }; | ||
| 811 | |||
| 812 | pub const TypedefType = opaque { | ||
| 813 | pub const getDecl = ZigClangTypedefType_getDecl; | ||
| 814 | extern fn ZigClangTypedefType_getDecl(*const TypedefType) *const TypedefNameDecl; | ||
| 815 | }; | ||
| 816 | |||
| 817 | pub const UnaryExprOrTypeTraitExpr = opaque { | ||
| 818 | pub const getTypeOfArgument = ZigClangUnaryExprOrTypeTraitExpr_getTypeOfArgument; | ||
| 819 | extern fn ZigClangUnaryExprOrTypeTraitExpr_getTypeOfArgument(*const UnaryExprOrTypeTraitExpr) QualType; | ||
| 820 | |||
| 821 | pub const getBeginLoc = ZigClangUnaryExprOrTypeTraitExpr_getBeginLoc; | ||
| 822 | extern fn ZigClangUnaryExprOrTypeTraitExpr_getBeginLoc(*const UnaryExprOrTypeTraitExpr) SourceLocation; | ||
| 823 | |||
| 824 | pub const getKind = ZigClangUnaryExprOrTypeTraitExpr_getKind; | ||
| 825 | extern fn ZigClangUnaryExprOrTypeTraitExpr_getKind(*const UnaryExprOrTypeTraitExpr) UnaryExprOrTypeTrait_Kind; | ||
| 826 | }; | ||
| 827 | |||
| 828 | pub const UnaryOperator = opaque { | ||
| 829 | pub const getOpcode = ZigClangUnaryOperator_getOpcode; | ||
| 830 | extern fn ZigClangUnaryOperator_getOpcode(*const UnaryOperator) UO; | ||
| 831 | |||
| 832 | pub const getType = ZigClangUnaryOperator_getType; | ||
| 833 | extern fn ZigClangUnaryOperator_getType(*const UnaryOperator) QualType; | ||
| 834 | |||
| 835 | pub const getSubExpr = ZigClangUnaryOperator_getSubExpr; | ||
| 836 | extern fn ZigClangUnaryOperator_getSubExpr(*const UnaryOperator) *const Expr; | ||
| 837 | |||
| 838 | pub const getBeginLoc = ZigClangUnaryOperator_getBeginLoc; | ||
| 839 | extern fn ZigClangUnaryOperator_getBeginLoc(*const UnaryOperator) SourceLocation; | ||
| 840 | }; | ||
| 841 | |||
| 842 | pub const ValueDecl = opaque {}; | ||
| 843 | |||
| 844 | pub const VarDecl = opaque { | ||
| 845 | pub const getLocation = ZigClangVarDecl_getLocation; | ||
| 846 | extern fn ZigClangVarDecl_getLocation(*const VarDecl) SourceLocation; | ||
| 847 | |||
| 848 | pub const hasInit = ZigClangVarDecl_hasInit; | ||
| 849 | extern fn ZigClangVarDecl_hasInit(*const VarDecl) bool; | ||
| 850 | |||
| 851 | pub const getStorageClass = ZigClangVarDecl_getStorageClass; | ||
| 852 | extern fn ZigClangVarDecl_getStorageClass(*const VarDecl) StorageClass; | ||
| 853 | |||
| 854 | pub const getType = ZigClangVarDecl_getType; | ||
| 855 | extern fn ZigClangVarDecl_getType(*const VarDecl) QualType; | ||
| 856 | |||
| 857 | pub const getInit = ZigClangVarDecl_getInit; | ||
| 858 | extern fn ZigClangVarDecl_getInit(*const VarDecl) ?*const Expr; | ||
| 859 | |||
| 860 | pub const getTLSKind = ZigClangVarDecl_getTLSKind; | ||
| 861 | extern fn ZigClangVarDecl_getTLSKind(*const VarDecl) VarDecl_TLSKind; | ||
| 862 | |||
| 863 | pub const getCanonicalDecl = ZigClangVarDecl_getCanonicalDecl; | ||
| 864 | extern fn ZigClangVarDecl_getCanonicalDecl(*const VarDecl) ?*const VarDecl; | ||
| 865 | |||
| 866 | pub const getSectionAttribute = ZigClangVarDecl_getSectionAttribute; | ||
| 867 | extern fn ZigClangVarDecl_getSectionAttribute(*const VarDecl, len: *usize) ?[*]const u8; | ||
| 868 | |||
| 869 | pub const getAlignedAttribute = ZigClangVarDecl_getAlignedAttribute; | ||
| 870 | extern fn ZigClangVarDecl_getAlignedAttribute(*const VarDecl, *const ASTContext) c_uint; | ||
| 871 | |||
| 872 | pub const getTypeSourceInfo_getType = ZigClangVarDecl_getTypeSourceInfo_getType; | ||
| 873 | extern fn ZigClangVarDecl_getTypeSourceInfo_getType(*const VarDecl) QualType; | ||
| 874 | }; | ||
| 875 | |||
| 876 | pub const WhileStmt = opaque { | ||
| 877 | pub const getCond = ZigClangWhileStmt_getCond; | ||
| 878 | extern fn ZigClangWhileStmt_getCond(*const WhileStmt) *const Expr; | ||
| 879 | |||
| 880 | pub const getBody = ZigClangWhileStmt_getBody; | ||
| 881 | extern fn ZigClangWhileStmt_getBody(*const WhileStmt) *const Stmt; | ||
| 882 | }; | ||
| 883 | |||
| 884 | pub const InitListExpr = opaque { | ||
| 885 | pub const getInit = ZigClangInitListExpr_getInit; | ||
| 886 | extern fn ZigClangInitListExpr_getInit(*const InitListExpr, i: c_uint) *const Expr; | ||
| 887 | |||
| 888 | pub const getArrayFiller = ZigClangInitListExpr_getArrayFiller; | ||
| 889 | extern fn ZigClangInitListExpr_getArrayFiller(*const InitListExpr) *const Expr; | ||
| 890 | |||
| 891 | pub const getNumInits = ZigClangInitListExpr_getNumInits; | ||
| 892 | extern fn ZigClangInitListExpr_getNumInits(*const InitListExpr) c_uint; | ||
| 893 | |||
| 894 | pub const getInitializedFieldInUnion = ZigClangInitListExpr_getInitializedFieldInUnion; | ||
| 895 | extern fn ZigClangInitListExpr_getInitializedFieldInUnion(*const InitListExpr) ?*FieldDecl; | ||
| 896 | }; | ||
| 897 | |||
| 898 | pub const BO = extern enum { | ||
| 89 | PtrMemD, | 899 | PtrMemD, |
| 90 | PtrMemI, | 900 | PtrMemI, |
| 91 | Mul, | 901 | Mul, |
| ... | @@ -121,7 +931,7 @@ pub const ZigClangBO = extern enum { | ... | @@ -121,7 +931,7 @@ pub const ZigClangBO = extern enum { |
| 121 | Comma, | 931 | Comma, |
| 122 | }; | 932 | }; |
| 123 | 933 | ||
| 124 | pub const ZigClangUO = extern enum { | 934 | pub const UO = extern enum { |
| 125 | PostInc, | 935 | PostInc, |
| 126 | PostDec, | 936 | PostDec, |
| 127 | PreInc, | 937 | PreInc, |
| ... | @@ -138,7 +948,7 @@ pub const ZigClangUO = extern enum { | ... | @@ -138,7 +948,7 @@ pub const ZigClangUO = extern enum { |
| 138 | Coawait, | 948 | Coawait, |
| 139 | }; | 949 | }; |
| 140 | 950 | ||
| 141 | pub const ZigClangTypeClass = extern enum { | 951 | pub const TypeClass = extern enum { |
| 142 | Adjusted, | 952 | Adjusted, |
| 143 | Decayed, | 953 | Decayed, |
| 144 | ConstantArray, | 954 | ConstantArray, |
| ... | @@ -193,7 +1003,7 @@ pub const ZigClangTypeClass = extern enum { | ... | @@ -193,7 +1003,7 @@ pub const ZigClangTypeClass = extern enum { |
| 193 | ExtVector, | 1003 | ExtVector, |
| 194 | }; | 1004 | }; |
| 195 | 1005 | ||
| 196 | const ZigClangStmtClass = extern enum { | 1006 | const StmtClass = extern enum { |
| 197 | NoStmtClass, | 1007 | NoStmtClass, |
| 198 | GCCAsmStmtClass, | 1008 | GCCAsmStmtClass, |
| 199 | MSAsmStmtClass, | 1009 | MSAsmStmtClass, |
| ... | @@ -410,7 +1220,7 @@ const ZigClangStmtClass = extern enum { | ... | @@ -410,7 +1220,7 @@ const ZigClangStmtClass = extern enum { |
| 410 | WhileStmtClass, | 1220 | WhileStmtClass, |
| 411 | }; | 1221 | }; |
| 412 | 1222 | ||
| 413 | pub const ZigClangCK = extern enum { | 1223 | pub const CK = extern enum { |
| 414 | Dependent, | 1224 | Dependent, |
| 415 | BitCast, | 1225 | BitCast, |
| 416 | LValueBitCast, | 1226 | LValueBitCast, |
| ... | @@ -475,24 +1285,7 @@ pub const ZigClangCK = extern enum { | ... | @@ -475,24 +1285,7 @@ pub const ZigClangCK = extern enum { |
| 475 | IntToOCLSampler, | 1285 | IntToOCLSampler, |
| 476 | }; | 1286 | }; |
| 477 | 1287 | ||
| 478 | pub const ZigClangAPValueKind = extern enum { | 1288 | pub const DeclKind = extern enum { |
| 479 | None, | ||
| 480 | Indeterminate, | ||
| 481 | Int, | ||
| 482 | Float, | ||
| 483 | FixedPoint, | ||
| 484 | ComplexInt, | ||
| 485 | ComplexFloat, | ||
| 486 | LValue, | ||
| 487 | Vector, | ||
| 488 | Array, | ||
| 489 | Struct, | ||
| 490 | Union, | ||
| 491 | MemberPointer, | ||
| 492 | AddrLabelDiff, | ||
| 493 | }; | ||
| 494 | |||
| 495 | pub const ZigClangDeclKind = extern enum { | ||
| 496 | AccessSpec, | 1289 | AccessSpec, |
| 497 | Block, | 1290 | Block, |
| 498 | Captured, | 1291 | Captured, |
| ... | @@ -575,7 +1368,7 @@ pub const ZigClangDeclKind = extern enum { | ... | @@ -575,7 +1368,7 @@ pub const ZigClangDeclKind = extern enum { |
| 575 | TranslationUnit, | 1368 | TranslationUnit, |
| 576 | }; | 1369 | }; |
| 577 | 1370 | ||
| 578 | pub const ZigClangBuiltinTypeKind = extern enum { | 1371 | pub const BuiltinTypeKind = extern enum { |
| 579 | OCLImage1dRO, | 1372 | OCLImage1dRO, |
| 580 | OCLImage1dArrayRO, | 1373 | OCLImage1dArrayRO, |
| 581 | OCLImage1dBufferRO, | 1374 | OCLImage1dBufferRO, |
| ... | @@ -747,7 +1540,7 @@ pub const ZigClangBuiltinTypeKind = extern enum { | ... | @@ -747,7 +1540,7 @@ pub const ZigClangBuiltinTypeKind = extern enum { |
| 747 | OMPIterator, | 1540 | OMPIterator, |
| 748 | }; | 1541 | }; |
| 749 | 1542 | ||
| 750 | pub const ZigClangCallingConv = extern enum { | 1543 | pub const CallingConv = extern enum { |
| 751 | C, | 1544 | C, |
| 752 | X86StdCall, | 1545 | X86StdCall, |
| 753 | X86FastCall, | 1546 | X86FastCall, |
| ... | @@ -768,7 +1561,7 @@ pub const ZigClangCallingConv = extern enum { | ... | @@ -768,7 +1561,7 @@ pub const ZigClangCallingConv = extern enum { |
| 768 | AArch64VectorCall, | 1561 | AArch64VectorCall, |
| 769 | }; | 1562 | }; |
| 770 | 1563 | ||
| 771 | pub const ZigClangStorageClass = extern enum { | 1564 | pub const StorageClass = extern enum { |
| 772 | None, | 1565 | None, |
| 773 | Extern, | 1566 | Extern, |
| 774 | Static, | 1567 | Static, |
| ... | @@ -777,7 +1570,7 @@ pub const ZigClangStorageClass = extern enum { | ... | @@ -777,7 +1570,7 @@ pub const ZigClangStorageClass = extern enum { |
| 777 | Register, | 1570 | Register, |
| 778 | }; | 1571 | }; |
| 779 | 1572 | ||
| 780 | pub const ZigClangAPFloat_roundingMode = extern enum(i8) { | 1573 | pub const APFloat_roundingMode = extern enum(i8) { |
| 781 | TowardZero = 0, | 1574 | TowardZero = 0, |
| 782 | NearestTiesToEven = 1, | 1575 | NearestTiesToEven = 1, |
| 783 | TowardPositive = 2, | 1576 | TowardPositive = 2, |
| ... | @@ -787,7 +1580,7 @@ pub const ZigClangAPFloat_roundingMode = extern enum(i8) { | ... | @@ -787,7 +1580,7 @@ pub const ZigClangAPFloat_roundingMode = extern enum(i8) { |
| 787 | Invalid = -1, | 1580 | Invalid = -1, |
| 788 | }; | 1581 | }; |
| 789 | 1582 | ||
| 790 | pub const ZigClangStringLiteral_StringKind = extern enum { | 1583 | pub const StringLiteral_StringKind = extern enum { |
| 791 | Ascii, | 1584 | Ascii, |
| 792 | Wide, | 1585 | Wide, |
| 793 | UTF8, | 1586 | UTF8, |
| ... | @@ -795,7 +1588,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum { | ... | @@ -795,7 +1588,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum { |
| 795 | UTF32, | 1588 | UTF32, |
| 796 | }; | 1589 | }; |
| 797 | 1590 | ||
| 798 | pub const ZigClangCharacterLiteral_CharacterKind = extern enum { | 1591 | pub const CharacterLiteral_CharacterKind = extern enum { |
| 799 | Ascii, | 1592 | Ascii, |
| 800 | Wide, | 1593 | Wide, |
| 801 | UTF8, | 1594 | UTF8, |
| ... | @@ -803,32 +1596,35 @@ pub const ZigClangCharacterLiteral_CharacterKind = extern enum { | ... | @@ -803,32 +1596,35 @@ pub const ZigClangCharacterLiteral_CharacterKind = extern enum { |
| 803 | UTF32, | 1596 | UTF32, |
| 804 | }; | 1597 | }; |
| 805 | 1598 | ||
| 806 | pub const ZigClangRecordDecl_field_iterator = extern struct { | 1599 | pub const VarDecl_TLSKind = extern enum { |
| 807 | opaque: *c_void, | 1600 | None, |
| 808 | }; | 1601 | Static, |
| 809 | 1602 | Dynamic, | |
| 810 | pub const ZigClangEnumDecl_enumerator_iterator = extern struct { | ||
| 811 | opaque: *c_void, | ||
| 812 | }; | 1603 | }; |
| 813 | 1604 | ||
| 814 | pub const ZigClangPreprocessingRecord_iterator = extern struct { | 1605 | pub const ElaboratedTypeKeyword = extern enum { |
| 815 | I: c_int, | 1606 | Struct, |
| 816 | Self: *ZigClangPreprocessingRecord, | 1607 | Interface, |
| 1608 | Union, | ||
| 1609 | Class, | ||
| 1610 | Enum, | ||
| 1611 | Typename, | ||
| 1612 | None, | ||
| 817 | }; | 1613 | }; |
| 818 | 1614 | ||
| 819 | pub const ZigClangPreprocessedEntity_EntityKind = extern enum { | 1615 | pub const PreprocessedEntity_EntityKind = extern enum { |
| 820 | InvalidKind, | 1616 | InvalidKind, |
| 821 | MacroExpansionKind, | 1617 | MacroExpansionKind, |
| 822 | MacroDefinitionKind, | 1618 | MacroDefinitionKind, |
| 823 | InclusionDirectiveKind, | 1619 | InclusionDirectiveKind, |
| 824 | }; | 1620 | }; |
| 825 | 1621 | ||
| 826 | pub const ZigClangExpr_ConstExprUsage = extern enum { | 1622 | pub const Expr_ConstExprUsage = extern enum { |
| 827 | EvaluateForCodeGen, | 1623 | EvaluateForCodeGen, |
| 828 | EvaluateForMangling, | 1624 | EvaluateForMangling, |
| 829 | }; | 1625 | }; |
| 830 | 1626 | ||
| 831 | pub const ZigClangUnaryExprOrTypeTrait_Kind = extern enum { | 1627 | pub const UnaryExprOrTypeTrait_Kind = extern enum { |
| 832 | SizeOf, | 1628 | SizeOf, |
| 833 | AlignOf, | 1629 | AlignOf, |
| 834 | VecStep, | 1630 | VecStep, |
| ... | @@ -836,211 +1632,6 @@ pub const ZigClangUnaryExprOrTypeTrait_Kind = extern enum { | ... | @@ -836,211 +1632,6 @@ pub const ZigClangUnaryExprOrTypeTrait_Kind = extern enum { |
| 836 | PreferredAlignOf, | 1632 | PreferredAlignOf, |
| 837 | }; | 1633 | }; |
| 838 | 1634 | ||
| 839 | pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; | ||
| 840 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8; | ||
| 841 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | ||
| 842 | pub extern fn ZigClangSourceManager_getSpellingColumnNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | ||
| 843 | pub extern fn ZigClangSourceManager_getCharacterData(self: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*:0]const u8; | ||
| 844 | pub extern fn ZigClangASTContext_getPointerType(self: ?*const struct_ZigClangASTContext, T: struct_ZigClangQualType) struct_ZigClangQualType; | ||
| 845 | pub extern fn ZigClangASTUnit_getASTContext(self: ?*struct_ZigClangASTUnit) ?*struct_ZigClangASTContext; | ||
| 846 | pub extern fn ZigClangASTUnit_getSourceManager(self: *struct_ZigClangASTUnit) *struct_ZigClangSourceManager; | ||
| 847 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(self: *struct_ZigClangASTUnit, context: ?*c_void, Fn: ?fn (?*c_void, *const ZigClangDecl) callconv(.C) bool) bool; | ||
| 848 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) *const struct_ZigClangRecordDecl; | ||
| 849 | pub extern fn ZigClangTagDecl_isThisDeclarationADefinition(self: *const ZigClangTagDecl) bool; | ||
| 850 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) *const struct_ZigClangEnumDecl; | ||
| 851 | pub extern fn ZigClangRecordDecl_getCanonicalDecl(record_decl: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangTagDecl; | ||
| 852 | pub extern fn ZigClangFieldDecl_getCanonicalDecl(field_decl: ?*const struct_ZigClangFieldDecl) ?*const struct_ZigClangFieldDecl; | ||
| 853 | pub extern fn ZigClangFieldDecl_getAlignedAttribute(field_decl: ?*const struct_ZigClangFieldDecl, *const ZigClangASTContext) c_uint; | ||
| 854 | pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl; | ||
| 855 | pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl; | ||
| 856 | pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl; | ||
| 857 | pub extern fn ZigClangParmVarDecl_getOriginalType(self: ?*const struct_ZigClangParmVarDecl) struct_ZigClangQualType; | ||
| 858 | pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl; | ||
| 859 | pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8; | ||
| 860 | pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint; | ||
| 861 | pub extern fn ZigClangVarDecl_getAlignedAttribute(self: *const ZigClangVarDecl, *const ZigClangASTContext) c_uint; | ||
| 862 | pub extern fn ZigClangRecordDecl_getPackedAttribute(self: ?*const struct_ZigClangRecordDecl) bool; | ||
| 863 | pub extern fn ZigClangRecordDecl_getDefinition(self: ?*const struct_ZigClangRecordDecl) ?*const struct_ZigClangRecordDecl; | ||
| 864 | pub extern fn ZigClangEnumDecl_getDefinition(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangEnumDecl; | ||
| 865 | pub extern fn ZigClangRecordDecl_getLocation(self: ?*const struct_ZigClangRecordDecl) struct_ZigClangSourceLocation; | ||
| 866 | pub extern fn ZigClangEnumDecl_getLocation(self: ?*const struct_ZigClangEnumDecl) struct_ZigClangSourceLocation; | ||
| 867 | pub extern fn ZigClangTypedefNameDecl_getLocation(self: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangSourceLocation; | ||
| 868 | pub extern fn ZigClangDecl_getLocation(self: *const ZigClangDecl) ZigClangSourceLocation; | ||
| 869 | pub extern fn ZigClangRecordDecl_isUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | ||
| 870 | pub extern fn ZigClangRecordDecl_isStruct(record_decl: ?*const struct_ZigClangRecordDecl) bool; | ||
| 871 | pub extern fn ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | ||
| 872 | pub extern fn ZigClangRecordDecl_field_begin(*const struct_ZigClangRecordDecl) ZigClangRecordDecl_field_iterator; | ||
| 873 | pub extern fn ZigClangRecordDecl_field_end(*const struct_ZigClangRecordDecl) ZigClangRecordDecl_field_iterator; | ||
| 874 | pub extern fn ZigClangRecordDecl_field_iterator_next(ZigClangRecordDecl_field_iterator) ZigClangRecordDecl_field_iterator; | ||
| 875 | pub extern fn ZigClangRecordDecl_field_iterator_deref(ZigClangRecordDecl_field_iterator) *const struct_ZigClangFieldDecl; | ||
| 876 | pub extern fn ZigClangRecordDecl_field_iterator_neq(ZigClangRecordDecl_field_iterator, ZigClangRecordDecl_field_iterator) bool; | ||
| 877 | pub extern fn ZigClangEnumDecl_getIntegerType(self: ?*const struct_ZigClangEnumDecl) struct_ZigClangQualType; | ||
| 878 | pub extern fn ZigClangEnumDecl_enumerator_begin(*const ZigClangEnumDecl) ZigClangEnumDecl_enumerator_iterator; | ||
| 879 | pub extern fn ZigClangEnumDecl_enumerator_end(*const ZigClangEnumDecl) ZigClangEnumDecl_enumerator_iterator; | ||
| 880 | pub extern fn ZigClangEnumDecl_enumerator_iterator_next(ZigClangEnumDecl_enumerator_iterator) ZigClangEnumDecl_enumerator_iterator; | ||
| 881 | pub extern fn ZigClangEnumDecl_enumerator_iterator_deref(ZigClangEnumDecl_enumerator_iterator) *const ZigClangEnumConstantDecl; | ||
| 882 | pub extern fn ZigClangEnumDecl_enumerator_iterator_neq(ZigClangEnumDecl_enumerator_iterator, ZigClangEnumDecl_enumerator_iterator) bool; | ||
| 883 | pub extern fn ZigClangDecl_castToNamedDecl(decl: *const ZigClangDecl) ?*const ZigClangNamedDecl; | ||
| 884 | pub extern fn ZigClangNamedDecl_getName_bytes_begin(decl: ?*const struct_ZigClangNamedDecl) [*:0]const u8; | ||
| 885 | pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: struct_ZigClangSourceLocation) bool; | ||
| 886 | pub extern fn ZigClangTypedefType_getDecl(self: ?*const struct_ZigClangTypedefType) *const struct_ZigClangTypedefNameDecl; | ||
| 887 | pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(self: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType; | ||
| 888 | pub extern fn ZigClangQualType_getCanonicalType(self: struct_ZigClangQualType) struct_ZigClangQualType; | ||
| 889 | pub extern fn ZigClangQualType_getTypeClass(self: struct_ZigClangQualType) ZigClangTypeClass; | ||
| 890 | pub extern fn ZigClangQualType_getTypePtr(self: struct_ZigClangQualType) *const struct_ZigClangType; | ||
| 891 | pub extern fn ZigClangQualType_addConst(self: *struct_ZigClangQualType) void; | ||
| 892 | pub extern fn ZigClangQualType_eq(self: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool; | ||
| 893 | pub extern fn ZigClangQualType_isConstQualified(self: struct_ZigClangQualType) bool; | ||
| 894 | pub extern fn ZigClangQualType_isVolatileQualified(self: struct_ZigClangQualType) bool; | ||
| 895 | pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType) bool; | ||
| 896 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass; | ||
| 897 | pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType; | ||
| 898 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; | ||
| 899 | pub extern fn ZigClangType_isConstantArrayType(self: ?*const struct_ZigClangType) bool; | ||
| 900 | pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool; | ||
| 901 | pub extern fn ZigClangType_isIncompleteOrZeroLengthArrayType(self: ?*const struct_ZigClangType, *const ZigClangASTContext) bool; | ||
| 902 | pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool; | ||
| 903 | pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool; | ||
| 904 | pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*:0]const u8; | ||
| 905 | pub extern fn ZigClangType_getAsArrayTypeUnsafe(self: *const ZigClangType) *const ZigClangArrayType; | ||
| 906 | pub extern fn ZigClangType_getAsRecordType(self: *const ZigClangType) ?*const ZigClangRecordType; | ||
| 907 | pub extern fn ZigClangType_getAsUnionType(self: *const ZigClangType) ?*const ZigClangRecordType; | ||
| 908 | pub extern fn ZigClangStmt_getBeginLoc(self: *const ZigClangStmt) struct_ZigClangSourceLocation; | ||
| 909 | pub extern fn ZigClangStmt_getStmtClass(self: ?*const ZigClangStmt) ZigClangStmtClass; | ||
| 910 | pub extern fn ZigClangStmt_classof_Expr(self: ?*const ZigClangStmt) bool; | ||
| 911 | pub extern fn ZigClangExpr_getStmtClass(self: *const struct_ZigClangExpr) ZigClangStmtClass; | ||
| 912 | pub extern fn ZigClangExpr_getType(self: *const struct_ZigClangExpr) struct_ZigClangQualType; | ||
| 913 | pub extern fn ZigClangExpr_getBeginLoc(self: *const struct_ZigClangExpr) struct_ZigClangSourceLocation; | ||
| 914 | pub extern fn ZigClangInitListExpr_getInit(self: ?*const struct_ZigClangInitListExpr, i: c_uint) *const ZigClangExpr; | ||
| 915 | pub extern fn ZigClangInitListExpr_getArrayFiller(self: ?*const struct_ZigClangInitListExpr) *const ZigClangExpr; | ||
| 916 | pub extern fn ZigClangInitListExpr_getNumInits(self: ?*const struct_ZigClangInitListExpr) c_uint; | ||
| 917 | pub extern fn ZigClangInitListExpr_getInitializedFieldInUnion(self: ?*const struct_ZigClangInitListExpr) ?*ZigClangFieldDecl; | ||
| 918 | pub extern fn ZigClangAPValue_getKind(self: ?*const struct_ZigClangAPValue) ZigClangAPValueKind; | ||
| 919 | pub extern fn ZigClangAPValue_getInt(self: ?*const struct_ZigClangAPValue) *const struct_ZigClangAPSInt; | ||
| 920 | pub extern fn ZigClangAPValue_getArrayInitializedElts(self: ?*const struct_ZigClangAPValue) c_uint; | ||
| 921 | pub extern fn ZigClangAPValue_getArraySize(self: ?*const struct_ZigClangAPValue) c_uint; | ||
| 922 | pub extern fn ZigClangAPValue_getLValueBase(self: ?*const struct_ZigClangAPValue) struct_ZigClangAPValueLValueBase; | ||
| 923 | pub extern fn ZigClangAPSInt_isSigned(self: *const struct_ZigClangAPSInt) bool; | ||
| 924 | pub extern fn ZigClangAPSInt_isNegative(self: *const struct_ZigClangAPSInt) bool; | ||
| 925 | pub extern fn ZigClangAPSInt_negate(self: *const struct_ZigClangAPSInt) *const struct_ZigClangAPSInt; | ||
| 926 | pub extern fn ZigClangAPSInt_free(self: *const struct_ZigClangAPSInt) void; | ||
| 927 | pub extern fn ZigClangAPSInt_getRawData(self: *const struct_ZigClangAPSInt) [*:0]const u64; | ||
| 928 | pub extern fn ZigClangAPSInt_getNumWords(self: *const struct_ZigClangAPSInt) c_uint; | ||
| 929 | |||
| 930 | pub extern fn ZigClangAPInt_getLimitedValue(self: *const struct_ZigClangAPInt, limit: u64) u64; | ||
| 931 | pub extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(self: struct_ZigClangAPValueLValueBase) ?*const struct_ZigClangExpr; | ||
| 932 | pub extern fn ZigClangASTUnit_delete(self: ?*struct_ZigClangASTUnit) void; | ||
| 933 | |||
| 934 | pub extern fn ZigClangFunctionDecl_getType(self: *const ZigClangFunctionDecl) struct_ZigClangQualType; | ||
| 935 | pub extern fn ZigClangFunctionDecl_getLocation(self: *const ZigClangFunctionDecl) struct_ZigClangSourceLocation; | ||
| 936 | pub extern fn ZigClangFunctionDecl_hasBody(self: *const ZigClangFunctionDecl) bool; | ||
| 937 | pub extern fn ZigClangFunctionDecl_getStorageClass(self: *const ZigClangFunctionDecl) ZigClangStorageClass; | ||
| 938 | pub extern fn ZigClangFunctionDecl_getParamDecl(self: *const ZigClangFunctionDecl, i: c_uint) *const struct_ZigClangParmVarDecl; | ||
| 939 | pub extern fn ZigClangFunctionDecl_getBody(self: *const ZigClangFunctionDecl) *const ZigClangStmt; | ||
| 940 | pub extern fn ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(self: *const ZigClangFunctionDecl) bool; | ||
| 941 | pub extern fn ZigClangFunctionDecl_isThisDeclarationADefinition(self: *const ZigClangFunctionDecl) bool; | ||
| 942 | pub extern fn ZigClangFunctionDecl_doesThisDeclarationHaveABody(self: *const ZigClangFunctionDecl) bool; | ||
| 943 | pub extern fn ZigClangFunctionDecl_isInlineSpecified(self: *const ZigClangFunctionDecl) bool; | ||
| 944 | pub extern fn ZigClangFunctionDecl_isDefined(self: *const ZigClangFunctionDecl) bool; | ||
| 945 | pub extern fn ZigClangFunctionDecl_getDefinition(self: *const ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl; | ||
| 946 | pub extern fn ZigClangFunctionDecl_getSectionAttribute(self: *const ZigClangFunctionDecl, len: *usize) ?[*]const u8; | ||
| 947 | |||
| 948 | pub extern fn ZigClangBuiltinType_getKind(self: *const struct_ZigClangBuiltinType) ZigClangBuiltinTypeKind; | ||
| 949 | |||
| 950 | pub extern fn ZigClangFunctionType_getNoReturnAttr(self: *const ZigClangFunctionType) bool; | ||
| 951 | pub extern fn ZigClangFunctionType_getCallConv(self: *const ZigClangFunctionType) ZigClangCallingConv; | ||
| 952 | pub extern fn ZigClangFunctionType_getReturnType(self: *const ZigClangFunctionType) ZigClangQualType; | ||
| 953 | |||
| 954 | pub extern fn ZigClangFunctionProtoType_isVariadic(self: *const struct_ZigClangFunctionProtoType) bool; | ||
| 955 | pub extern fn ZigClangFunctionProtoType_getNumParams(self: *const struct_ZigClangFunctionProtoType) c_uint; | ||
| 956 | pub extern fn ZigClangFunctionProtoType_getParamType(self: *const struct_ZigClangFunctionProtoType, i: c_uint) ZigClangQualType; | ||
| 957 | pub extern fn ZigClangFunctionProtoType_getReturnType(self: *const ZigClangFunctionProtoType) ZigClangQualType; | ||
| 958 | |||
| 959 | pub const ZigClangSourceLocation = struct_ZigClangSourceLocation; | ||
| 960 | pub const ZigClangQualType = struct_ZigClangQualType; | ||
| 961 | pub const ZigClangConditionalOperator = struct_ZigClangConditionalOperator; | ||
| 962 | pub const ZigClangBinaryConditionalOperator = struct_ZigClangBinaryConditionalOperator; | ||
| 963 | pub const ZigClangAbstractConditionalOperator = struct_ZigClangAbstractConditionalOperator; | ||
| 964 | pub const ZigClangAPValueLValueBase = struct_ZigClangAPValueLValueBase; | ||
| 965 | pub const ZigClangAPValue = struct_ZigClangAPValue; | ||
| 966 | pub const ZigClangAPSInt = struct_ZigClangAPSInt; | ||
| 967 | pub const ZigClangAPFloat = struct_ZigClangAPFloat; | ||
| 968 | pub const ZigClangASTContext = struct_ZigClangASTContext; | ||
| 969 | pub const ZigClangASTUnit = struct_ZigClangASTUnit; | ||
| 970 | pub const ZigClangArraySubscriptExpr = struct_ZigClangArraySubscriptExpr; | ||
| 971 | pub const ZigClangArrayType = struct_ZigClangArrayType; | ||
| 972 | pub const ZigClangAttributedType = struct_ZigClangAttributedType; | ||
| 973 | pub const ZigClangBinaryOperator = struct_ZigClangBinaryOperator; | ||
| 974 | pub const ZigClangBreakStmt = struct_ZigClangBreakStmt; | ||
| 975 | pub const ZigClangBuiltinType = struct_ZigClangBuiltinType; | ||
| 976 | pub const ZigClangCStyleCastExpr = struct_ZigClangCStyleCastExpr; | ||
| 977 | pub const ZigClangCallExpr = struct_ZigClangCallExpr; | ||
| 978 | pub const ZigClangCaseStmt = struct_ZigClangCaseStmt; | ||
| 979 | pub const ZigClangCompoundAssignOperator = struct_ZigClangCompoundAssignOperator; | ||
| 980 | pub const ZigClangCompoundStmt = struct_ZigClangCompoundStmt; | ||
| 981 | pub const ZigClangConstantArrayType = struct_ZigClangConstantArrayType; | ||
| 982 | pub const ZigClangContinueStmt = struct_ZigClangContinueStmt; | ||
| 983 | pub const ZigClangDecayedType = struct_ZigClangDecayedType; | ||
| 984 | pub const ZigClangDeclRefExpr = struct_ZigClangDeclRefExpr; | ||
| 985 | pub const ZigClangDeclStmt = struct_ZigClangDeclStmt; | ||
| 986 | pub const ZigClangDefaultStmt = struct_ZigClangDefaultStmt; | ||
| 987 | pub const ZigClangDiagnosticOptions = struct_ZigClangDiagnosticOptions; | ||
| 988 | pub const ZigClangDiagnosticsEngine = struct_ZigClangDiagnosticsEngine; | ||
| 989 | pub const ZigClangDoStmt = struct_ZigClangDoStmt; | ||
| 990 | pub const ZigClangElaboratedType = struct_ZigClangElaboratedType; | ||
| 991 | pub const ZigClangEnumConstantDecl = struct_ZigClangEnumConstantDecl; | ||
| 992 | pub const ZigClangEnumDecl = struct_ZigClangEnumDecl; | ||
| 993 | pub const ZigClangEnumType = struct_ZigClangEnumType; | ||
| 994 | pub const ZigClangExpr = struct_ZigClangExpr; | ||
| 995 | pub const ZigClangFieldDecl = struct_ZigClangFieldDecl; | ||
| 996 | pub const ZigClangFileID = struct_ZigClangFileID; | ||
| 997 | pub const ZigClangForStmt = struct_ZigClangForStmt; | ||
| 998 | pub const ZigClangFullSourceLoc = struct_ZigClangFullSourceLoc; | ||
| 999 | pub const ZigClangFunctionDecl = struct_ZigClangFunctionDecl; | ||
| 1000 | pub const ZigClangFunctionProtoType = struct_ZigClangFunctionProtoType; | ||
| 1001 | pub const ZigClangIfStmt = struct_ZigClangIfStmt; | ||
| 1002 | pub const ZigClangImplicitCastExpr = struct_ZigClangImplicitCastExpr; | ||
| 1003 | pub const ZigClangIncompleteArrayType = struct_ZigClangIncompleteArrayType; | ||
| 1004 | pub const ZigClangIntegerLiteral = struct_ZigClangIntegerLiteral; | ||
| 1005 | pub const ZigClangMacroDefinitionRecord = struct_ZigClangMacroDefinitionRecord; | ||
| 1006 | pub const ZigClangMacroExpansion = struct_ZigClangMacroExpansion; | ||
| 1007 | pub const ZigClangMacroQualifiedType = struct_ZigClangMacroQualifiedType; | ||
| 1008 | pub const ZigClangMemberExpr = struct_ZigClangMemberExpr; | ||
| 1009 | pub const ZigClangNamedDecl = struct_ZigClangNamedDecl; | ||
| 1010 | pub const ZigClangNone = struct_ZigClangNone; | ||
| 1011 | pub const ZigClangOpaqueValueExpr = struct_ZigClangOpaqueValueExpr; | ||
| 1012 | pub const ZigClangPCHContainerOperations = struct_ZigClangPCHContainerOperations; | ||
| 1013 | pub const ZigClangParenExpr = struct_ZigClangParenExpr; | ||
| 1014 | pub const ZigClangParenType = struct_ZigClangParenType; | ||
| 1015 | pub const ZigClangParmVarDecl = struct_ZigClangParmVarDecl; | ||
| 1016 | pub const ZigClangPointerType = struct_ZigClangPointerType; | ||
| 1017 | pub const ZigClangPreprocessedEntity = struct_ZigClangPreprocessedEntity; | ||
| 1018 | pub const ZigClangRecordDecl = struct_ZigClangRecordDecl; | ||
| 1019 | pub const ZigClangRecordType = struct_ZigClangRecordType; | ||
| 1020 | pub const ZigClangReturnStmt = struct_ZigClangReturnStmt; | ||
| 1021 | pub const ZigClangSkipFunctionBodiesScope = struct_ZigClangSkipFunctionBodiesScope; | ||
| 1022 | pub const ZigClangSourceManager = struct_ZigClangSourceManager; | ||
| 1023 | pub const ZigClangSourceRange = struct_ZigClangSourceRange; | ||
| 1024 | pub const ZigClangStringLiteral = struct_ZigClangStringLiteral; | ||
| 1025 | pub const ZigClangStringRef = struct_ZigClangStringRef; | ||
| 1026 | pub const ZigClangSwitchStmt = struct_ZigClangSwitchStmt; | ||
| 1027 | pub const ZigClangTagDecl = struct_ZigClangTagDecl; | ||
| 1028 | pub const ZigClangType = struct_ZigClangType; | ||
| 1029 | pub const ZigClangTypedefNameDecl = struct_ZigClangTypedefNameDecl; | ||
| 1030 | pub const ZigClangTypedefType = struct_ZigClangTypedefType; | ||
| 1031 | pub const ZigClangUnaryExprOrTypeTraitExpr = struct_ZigClangUnaryExprOrTypeTraitExpr; | ||
| 1032 | pub const ZigClangUnaryOperator = struct_ZigClangUnaryOperator; | ||
| 1033 | pub const ZigClangValueDecl = struct_ZigClangValueDecl; | ||
| 1034 | pub const ZigClangVarDecl = struct_ZigClangVarDecl; | ||
| 1035 | pub const ZigClangWhileStmt = struct_ZigClangWhileStmt; | ||
| 1036 | pub const ZigClangFunctionType = struct_ZigClangFunctionType; | ||
| 1037 | pub const ZigClangPredefinedExpr = struct_ZigClangPredefinedExpr; | ||
| 1038 | pub const ZigClangInitListExpr = struct_ZigClangInitListExpr; | ||
| 1039 | |||
| 1040 | pub const struct_ZigClangSourceLocation = extern struct { | ||
| 1041 | ID: c_uint, | ||
| 1042 | }; | ||
| 1043 | |||
| 1044 | pub const Stage2ErrorMsg = extern struct { | 1635 | pub const Stage2ErrorMsg = extern struct { |
| 1045 | filename_ptr: ?[*]const u8, | 1636 | filename_ptr: ?[*]const u8, |
| 1046 | filename_len: usize, | 1637 | filename_len: usize, |
| ... | @@ -1054,199 +1645,16 @@ pub const Stage2ErrorMsg = extern struct { | ... | @@ -1054,199 +1645,16 @@ pub const Stage2ErrorMsg = extern struct { |
| 1054 | column: c_uint, | 1645 | column: c_uint, |
| 1055 | // byte offset into source | 1646 | // byte offset into source |
| 1056 | offset: c_uint, | 1647 | offset: c_uint, |
| 1057 | }; | ||
| 1058 | 1648 | ||
| 1059 | pub const struct_ZigClangQualType = extern struct { | 1649 | pub const delete = ZigClangErrorMsg_delete; |
| 1060 | ptr: ?*c_void, | 1650 | extern fn ZigClangErrorMsg_delete(ptr: [*]Stage2ErrorMsg, len: usize) void; |
| 1061 | }; | 1651 | }; |
| 1062 | 1652 | ||
| 1063 | pub const struct_ZigClangAPValueLValueBase = extern struct { | 1653 | pub const LoadFromCommandLine = ZigClangLoadFromCommandLine; |
| 1064 | Ptr: ?*c_void, | 1654 | extern fn ZigClangLoadFromCommandLine( |
| 1065 | CallIndex: c_uint, | ||
| 1066 | Version: c_uint, | ||
| 1067 | }; | ||
| 1068 | |||
| 1069 | pub extern fn ZigClangErrorMsg_delete(ptr: [*]Stage2ErrorMsg, len: usize) void; | ||
| 1070 | |||
| 1071 | pub extern fn ZigClangLoadFromCommandLine( | ||
| 1072 | args_begin: [*]?[*]const u8, | 1655 | args_begin: [*]?[*]const u8, |
| 1073 | args_end: [*]?[*]const u8, | 1656 | args_end: [*]?[*]const u8, |
| 1074 | errors_ptr: *[*]Stage2ErrorMsg, | 1657 | errors_ptr: *[*]Stage2ErrorMsg, |
| 1075 | errors_len: *usize, | 1658 | errors_len: *usize, |
| 1076 | resources_path: [*:0]const u8, | 1659 | resources_path: [*:0]const u8, |
| 1077 | ) ?*ZigClangASTUnit; | 1660 | ) ?*ASTUnit; |
| 1078 | |||
| 1079 | pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind; | ||
| 1080 | pub extern fn ZigClangDecl_getDeclKindName(decl: *const ZigClangDecl) [*:0]const u8; | ||
| 1081 | |||
| 1082 | pub const ZigClangCompoundStmt_const_body_iterator = [*]const *ZigClangStmt; | ||
| 1083 | |||
| 1084 | pub extern fn ZigClangCompoundStmt_body_begin(self: *const ZigClangCompoundStmt) ZigClangCompoundStmt_const_body_iterator; | ||
| 1085 | pub extern fn ZigClangCompoundStmt_body_end(self: *const ZigClangCompoundStmt) ZigClangCompoundStmt_const_body_iterator; | ||
| 1086 | |||
| 1087 | pub const ZigClangDeclStmt_const_decl_iterator = [*]const *ZigClangDecl; | ||
| 1088 | |||
| 1089 | pub extern fn ZigClangDeclStmt_decl_begin(self: *const ZigClangDeclStmt) ZigClangDeclStmt_const_decl_iterator; | ||
| 1090 | pub extern fn ZigClangDeclStmt_decl_end(self: *const ZigClangDeclStmt) ZigClangDeclStmt_const_decl_iterator; | ||
| 1091 | |||
| 1092 | pub extern fn ZigClangVarDecl_getLocation(self: *const struct_ZigClangVarDecl) ZigClangSourceLocation; | ||
| 1093 | pub extern fn ZigClangVarDecl_hasInit(self: *const struct_ZigClangVarDecl) bool; | ||
| 1094 | pub extern fn ZigClangVarDecl_getStorageClass(self: *const ZigClangVarDecl) ZigClangStorageClass; | ||
| 1095 | pub extern fn ZigClangVarDecl_getType(self: ?*const struct_ZigClangVarDecl) struct_ZigClangQualType; | ||
| 1096 | pub extern fn ZigClangVarDecl_getInit(*const ZigClangVarDecl) ?*const ZigClangExpr; | ||
| 1097 | pub extern fn ZigClangVarDecl_getTLSKind(self: ?*const struct_ZigClangVarDecl) ZigClangVarDecl_TLSKind; | ||
| 1098 | pub const ZigClangVarDecl_TLSKind = extern enum { | ||
| 1099 | None, | ||
| 1100 | Static, | ||
| 1101 | Dynamic, | ||
| 1102 | }; | ||
| 1103 | |||
| 1104 | pub extern fn ZigClangImplicitCastExpr_getBeginLoc(*const ZigClangImplicitCastExpr) ZigClangSourceLocation; | ||
| 1105 | pub extern fn ZigClangImplicitCastExpr_getCastKind(*const ZigClangImplicitCastExpr) ZigClangCK; | ||
| 1106 | pub extern fn ZigClangImplicitCastExpr_getSubExpr(*const ZigClangImplicitCastExpr) *const ZigClangExpr; | ||
| 1107 | |||
| 1108 | pub extern fn ZigClangArrayType_getElementType(*const ZigClangArrayType) ZigClangQualType; | ||
| 1109 | pub extern fn ZigClangIncompleteArrayType_getElementType(*const ZigClangIncompleteArrayType) ZigClangQualType; | ||
| 1110 | |||
| 1111 | pub extern fn ZigClangConstantArrayType_getElementType(self: *const struct_ZigClangConstantArrayType) ZigClangQualType; | ||
| 1112 | pub extern fn ZigClangConstantArrayType_getSize(self: *const struct_ZigClangConstantArrayType) *const struct_ZigClangAPInt; | ||
| 1113 | pub extern fn ZigClangDeclRefExpr_getDecl(*const ZigClangDeclRefExpr) *const ZigClangValueDecl; | ||
| 1114 | pub extern fn ZigClangDeclRefExpr_getFoundDecl(*const ZigClangDeclRefExpr) *const ZigClangNamedDecl; | ||
| 1115 | |||
| 1116 | pub extern fn ZigClangParenType_getInnerType(*const ZigClangParenType) ZigClangQualType; | ||
| 1117 | |||
| 1118 | pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType; | ||
| 1119 | |||
| 1120 | pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType; | ||
| 1121 | |||
| 1122 | pub extern fn ZigClangMacroQualifiedType_getModifiedType(*const ZigClangMacroQualifiedType) ZigClangQualType; | ||
| 1123 | |||
| 1124 | pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation; | ||
| 1125 | pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr; | ||
| 1126 | pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType; | ||
| 1127 | |||
| 1128 | pub const ZigClangExprEvalResult = struct_ZigClangExprEvalResult; | ||
| 1129 | pub const struct_ZigClangExprEvalResult = extern struct { | ||
| 1130 | HasSideEffects: bool, | ||
| 1131 | HasUndefinedBehavior: bool, | ||
| 1132 | SmallVectorImpl: ?*c_void, | ||
| 1133 | Val: ZigClangAPValue, | ||
| 1134 | }; | ||
| 1135 | |||
| 1136 | pub const struct_ZigClangAPValue = extern struct { | ||
| 1137 | Kind: ZigClangAPValueKind, | ||
| 1138 | Data: if (builtin.os.tag == .windows and builtin.abi == .msvc) [52]u8 else [68]u8, | ||
| 1139 | }; | ||
| 1140 | pub extern fn ZigClangVarDecl_getTypeSourceInfo_getType(self: *const struct_ZigClangVarDecl) struct_ZigClangQualType; | ||
| 1141 | |||
| 1142 | pub extern fn ZigClangIntegerLiteral_EvaluateAsInt(*const ZigClangIntegerLiteral, *ZigClangExprEvalResult, *const ZigClangASTContext) bool; | ||
| 1143 | pub extern fn ZigClangIntegerLiteral_getBeginLoc(*const ZigClangIntegerLiteral) ZigClangSourceLocation; | ||
| 1144 | pub extern fn ZigClangIntegerLiteral_isZero(*const ZigClangIntegerLiteral, *bool, *const ZigClangASTContext) bool; | ||
| 1145 | |||
| 1146 | pub extern fn ZigClangReturnStmt_getRetValue(*const ZigClangReturnStmt) ?*const ZigClangExpr; | ||
| 1147 | |||
| 1148 | pub extern fn ZigClangBinaryOperator_getOpcode(*const ZigClangBinaryOperator) ZigClangBO; | ||
| 1149 | pub extern fn ZigClangBinaryOperator_getBeginLoc(*const ZigClangBinaryOperator) ZigClangSourceLocation; | ||
| 1150 | pub extern fn ZigClangBinaryOperator_getLHS(*const ZigClangBinaryOperator) *const ZigClangExpr; | ||
| 1151 | pub extern fn ZigClangBinaryOperator_getRHS(*const ZigClangBinaryOperator) *const ZigClangExpr; | ||
| 1152 | pub extern fn ZigClangBinaryOperator_getType(*const ZigClangBinaryOperator) ZigClangQualType; | ||
| 1153 | |||
| 1154 | pub extern fn ZigClangDecayedType_getDecayedType(*const ZigClangDecayedType) ZigClangQualType; | ||
| 1155 | |||
| 1156 | pub extern fn ZigClangStringLiteral_getKind(*const ZigClangStringLiteral) ZigClangStringLiteral_StringKind; | ||
| 1157 | pub extern fn ZigClangStringLiteral_getString_bytes_begin_size(*const ZigClangStringLiteral, *usize) [*]const u8; | ||
| 1158 | |||
| 1159 | pub extern fn ZigClangParenExpr_getSubExpr(*const ZigClangParenExpr) *const ZigClangExpr; | ||
| 1160 | |||
| 1161 | pub extern fn ZigClangFieldDecl_isAnonymousStructOrUnion(*const struct_ZigClangFieldDecl) bool; | ||
| 1162 | pub extern fn ZigClangFieldDecl_isBitField(*const struct_ZigClangFieldDecl) bool; | ||
| 1163 | pub extern fn ZigClangFieldDecl_getType(*const struct_ZigClangFieldDecl) struct_ZigClangQualType; | ||
| 1164 | pub extern fn ZigClangFieldDecl_getLocation(*const struct_ZigClangFieldDecl) struct_ZigClangSourceLocation; | ||
| 1165 | |||
| 1166 | pub extern fn ZigClangEnumConstantDecl_getInitExpr(*const ZigClangEnumConstantDecl) ?*const ZigClangExpr; | ||
| 1167 | pub extern fn ZigClangEnumConstantDecl_getInitVal(*const ZigClangEnumConstantDecl) *const ZigClangAPSInt; | ||
| 1168 | |||
| 1169 | pub extern fn ZigClangASTUnit_getLocalPreprocessingEntities_begin(*ZigClangASTUnit) ZigClangPreprocessingRecord_iterator; | ||
| 1170 | pub extern fn ZigClangASTUnit_getLocalPreprocessingEntities_end(*ZigClangASTUnit) ZigClangPreprocessingRecord_iterator; | ||
| 1171 | pub extern fn ZigClangPreprocessingRecord_iterator_deref(ZigClangPreprocessingRecord_iterator) *ZigClangPreprocessedEntity; | ||
| 1172 | pub extern fn ZigClangPreprocessedEntity_getKind(*const ZigClangPreprocessedEntity) ZigClangPreprocessedEntity_EntityKind; | ||
| 1173 | |||
| 1174 | pub extern fn ZigClangMacroDefinitionRecord_getName_getNameStart(*const ZigClangMacroDefinitionRecord) [*:0]const u8; | ||
| 1175 | pub extern fn ZigClangMacroDefinitionRecord_getSourceRange_getBegin(*const ZigClangMacroDefinitionRecord) ZigClangSourceLocation; | ||
| 1176 | pub extern fn ZigClangMacroDefinitionRecord_getSourceRange_getEnd(*const ZigClangMacroDefinitionRecord) ZigClangSourceLocation; | ||
| 1177 | |||
| 1178 | pub extern fn ZigClangMacroExpansion_getDefinition(*const ZigClangMacroExpansion) *const ZigClangMacroDefinitionRecord; | ||
| 1179 | |||
| 1180 | pub extern fn ZigClangIfStmt_getThen(*const ZigClangIfStmt) *const ZigClangStmt; | ||
| 1181 | pub extern fn ZigClangIfStmt_getElse(*const ZigClangIfStmt) ?*const ZigClangStmt; | ||
| 1182 | pub extern fn ZigClangIfStmt_getCond(*const ZigClangIfStmt) *const ZigClangStmt; | ||
| 1183 | |||
| 1184 | pub extern fn ZigClangWhileStmt_getCond(*const ZigClangWhileStmt) *const ZigClangExpr; | ||
| 1185 | pub extern fn ZigClangWhileStmt_getBody(*const ZigClangWhileStmt) *const ZigClangStmt; | ||
| 1186 | |||
| 1187 | pub extern fn ZigClangDoStmt_getCond(*const ZigClangDoStmt) *const ZigClangExpr; | ||
| 1188 | pub extern fn ZigClangDoStmt_getBody(*const ZigClangDoStmt) *const ZigClangStmt; | ||
| 1189 | |||
| 1190 | pub extern fn ZigClangForStmt_getInit(*const ZigClangForStmt) ?*const ZigClangStmt; | ||
| 1191 | pub extern fn ZigClangForStmt_getCond(*const ZigClangForStmt) ?*const ZigClangExpr; | ||
| 1192 | pub extern fn ZigClangForStmt_getInc(*const ZigClangForStmt) ?*const ZigClangExpr; | ||
| 1193 | pub extern fn ZigClangForStmt_getBody(*const ZigClangForStmt) *const ZigClangStmt; | ||
| 1194 | |||
| 1195 | pub extern fn ZigClangAPFloat_toString(self: *const ZigClangAPFloat, precision: c_uint, maxPadding: c_uint, truncateZero: bool) [*:0]const u8; | ||
| 1196 | pub extern fn ZigClangAPFloat_getValueAsApproximateDouble(*const ZigClangFloatingLiteral) f64; | ||
| 1197 | |||
| 1198 | pub extern fn ZigClangAbstractConditionalOperator_getCond(*const ZigClangAbstractConditionalOperator) *const ZigClangExpr; | ||
| 1199 | pub extern fn ZigClangAbstractConditionalOperator_getTrueExpr(*const ZigClangAbstractConditionalOperator) *const ZigClangExpr; | ||
| 1200 | pub extern fn ZigClangAbstractConditionalOperator_getFalseExpr(*const ZigClangAbstractConditionalOperator) *const ZigClangExpr; | ||
| 1201 | |||
| 1202 | pub extern fn ZigClangSwitchStmt_getConditionVariableDeclStmt(*const ZigClangSwitchStmt) ?*const ZigClangDeclStmt; | ||
| 1203 | pub extern fn ZigClangSwitchStmt_getCond(*const ZigClangSwitchStmt) *const ZigClangExpr; | ||
| 1204 | pub extern fn ZigClangSwitchStmt_getBody(*const ZigClangSwitchStmt) *const ZigClangStmt; | ||
| 1205 | pub extern fn ZigClangSwitchStmt_isAllEnumCasesCovered(*const ZigClangSwitchStmt) bool; | ||
| 1206 | |||
| 1207 | pub extern fn ZigClangCaseStmt_getLHS(*const ZigClangCaseStmt) *const ZigClangExpr; | ||
| 1208 | pub extern fn ZigClangCaseStmt_getRHS(*const ZigClangCaseStmt) ?*const ZigClangExpr; | ||
| 1209 | pub extern fn ZigClangCaseStmt_getBeginLoc(*const ZigClangCaseStmt) ZigClangSourceLocation; | ||
| 1210 | pub extern fn ZigClangCaseStmt_getSubStmt(*const ZigClangCaseStmt) *const ZigClangStmt; | ||
| 1211 | |||
| 1212 | pub extern fn ZigClangDefaultStmt_getSubStmt(*const ZigClangDefaultStmt) *const ZigClangStmt; | ||
| 1213 | |||
| 1214 | pub extern fn ZigClangExpr_EvaluateAsConstantExpr(*const ZigClangExpr, *ZigClangExprEvalResult, ZigClangExpr_ConstExprUsage, *const ZigClangASTContext) bool; | ||
| 1215 | |||
| 1216 | pub extern fn ZigClangPredefinedExpr_getFunctionName(*const ZigClangPredefinedExpr) *const ZigClangStringLiteral; | ||
| 1217 | |||
| 1218 | pub extern fn ZigClangCharacterLiteral_getBeginLoc(*const ZigClangCharacterLiteral) ZigClangSourceLocation; | ||
| 1219 | pub extern fn ZigClangCharacterLiteral_getKind(*const ZigClangCharacterLiteral) ZigClangCharacterLiteral_CharacterKind; | ||
| 1220 | pub extern fn ZigClangCharacterLiteral_getValue(*const ZigClangCharacterLiteral) c_uint; | ||
| 1221 | |||
| 1222 | pub extern fn ZigClangStmtExpr_getSubStmt(*const ZigClangStmtExpr) *const ZigClangCompoundStmt; | ||
| 1223 | |||
| 1224 | pub extern fn ZigClangMemberExpr_getBase(*const ZigClangMemberExpr) *const ZigClangExpr; | ||
| 1225 | pub extern fn ZigClangMemberExpr_isArrow(*const ZigClangMemberExpr) bool; | ||
| 1226 | pub extern fn ZigClangMemberExpr_getMemberDecl(*const ZigClangMemberExpr) *const ZigClangValueDecl; | ||
| 1227 | |||
| 1228 | pub extern fn ZigClangArraySubscriptExpr_getBase(*const ZigClangArraySubscriptExpr) *const ZigClangExpr; | ||
| 1229 | pub extern fn ZigClangArraySubscriptExpr_getIdx(*const ZigClangArraySubscriptExpr) *const ZigClangExpr; | ||
| 1230 | |||
| 1231 | pub extern fn ZigClangCallExpr_getCallee(*const ZigClangCallExpr) *const ZigClangExpr; | ||
| 1232 | pub extern fn ZigClangCallExpr_getNumArgs(*const ZigClangCallExpr) c_uint; | ||
| 1233 | pub extern fn ZigClangCallExpr_getArgs(*const ZigClangCallExpr) [*]const *const ZigClangExpr; | ||
| 1234 | |||
| 1235 | pub extern fn ZigClangUnaryExprOrTypeTraitExpr_getTypeOfArgument(*const ZigClangUnaryExprOrTypeTraitExpr) ZigClangQualType; | ||
| 1236 | pub extern fn ZigClangUnaryExprOrTypeTraitExpr_getBeginLoc(*const ZigClangUnaryExprOrTypeTraitExpr) ZigClangSourceLocation; | ||
| 1237 | pub extern fn ZigClangUnaryExprOrTypeTraitExpr_getKind(*const ZigClangUnaryExprOrTypeTraitExpr) ZigClangUnaryExprOrTypeTrait_Kind; | ||
| 1238 | |||
| 1239 | pub extern fn ZigClangUnaryOperator_getOpcode(*const ZigClangUnaryOperator) ZigClangUO; | ||
| 1240 | pub extern fn ZigClangUnaryOperator_getType(*const ZigClangUnaryOperator) ZigClangQualType; | ||
| 1241 | pub extern fn ZigClangUnaryOperator_getSubExpr(*const ZigClangUnaryOperator) *const ZigClangExpr; | ||
| 1242 | pub extern fn ZigClangUnaryOperator_getBeginLoc(*const ZigClangUnaryOperator) ZigClangSourceLocation; | ||
| 1243 | |||
| 1244 | pub extern fn ZigClangOpaqueValueExpr_getSourceExpr(*const ZigClangOpaqueValueExpr) ?*const ZigClangExpr; | ||
| 1245 | |||
| 1246 | pub extern fn ZigClangCompoundAssignOperator_getType(*const ZigClangCompoundAssignOperator) ZigClangQualType; | ||
| 1247 | pub extern fn ZigClangCompoundAssignOperator_getComputationLHSType(*const ZigClangCompoundAssignOperator) ZigClangQualType; | ||
| 1248 | pub extern fn ZigClangCompoundAssignOperator_getComputationResultType(*const ZigClangCompoundAssignOperator) ZigClangQualType; | ||
| 1249 | pub extern fn ZigClangCompoundAssignOperator_getBeginLoc(*const ZigClangCompoundAssignOperator) ZigClangSourceLocation; | ||
| 1250 | pub extern fn ZigClangCompoundAssignOperator_getOpcode(*const ZigClangCompoundAssignOperator) ZigClangBO; | ||
| 1251 | pub extern fn ZigClangCompoundAssignOperator_getLHS(*const ZigClangCompoundAssignOperator) *const ZigClangExpr; | ||
| 1252 | pub extern fn ZigClangCompoundAssignOperator_getRHS(*const ZigClangCompoundAssignOperator) *const ZigClangExpr; |
src/clang_options_data.zig+34-6| ... | @@ -76,8 +76,22 @@ flagpd1("M"), | ... | @@ -76,8 +76,22 @@ flagpd1("M"), |
| 76 | .psl = false, | 76 | .psl = false, |
| 77 | }, | 77 | }, |
| 78 | flagpd1("Mach"), | 78 | flagpd1("Mach"), |
| 79 | flagpd1("O0"), | 79 | .{ |
| 80 | flagpd1("O4"), | 80 | .name = "O0", |
| 81 | .syntax = .flag, | ||
| 82 | .zig_equivalent = .optimize, | ||
| 83 | .pd1 = true, | ||
| 84 | .pd2 = false, | ||
| 85 | .psl = false, | ||
| 86 | }, | ||
| 87 | .{ | ||
| 88 | .name = "O4", | ||
| 89 | .syntax = .flag, | ||
| 90 | .zig_equivalent = .optimize, | ||
| 91 | .pd1 = true, | ||
| 92 | .pd2 = false, | ||
| 93 | .psl = false, | ||
| 94 | }, | ||
| 81 | .{ | 95 | .{ |
| 82 | .name = "O", | 96 | .name = "O", |
| 83 | .syntax = .flag, | 97 | .syntax = .flag, |
| ... | @@ -2186,7 +2200,7 @@ flagpd1("fcuda-rdc"), | ... | @@ -2186,7 +2200,7 @@ flagpd1("fcuda-rdc"), |
| 2186 | .{ | 2200 | .{ |
| 2187 | .name = "Os", | 2201 | .name = "Os", |
| 2188 | .syntax = .flag, | 2202 | .syntax = .flag, |
| 2189 | .zig_equivalent = .other, | 2203 | .zig_equivalent = .optimize, |
| 2190 | .pd1 = true, | 2204 | .pd1 = true, |
| 2191 | .pd2 = false, | 2205 | .pd2 = false, |
| 2192 | .psl = true, | 2206 | .psl = true, |
| ... | @@ -3377,7 +3391,14 @@ flagpd1("fxray-link-deps"), | ... | @@ -3377,7 +3391,14 @@ flagpd1("fxray-link-deps"), |
| 3377 | flagpd1("fzero-initialized-in-bss"), | 3391 | flagpd1("fzero-initialized-in-bss"), |
| 3378 | flagpd1("fzvector"), | 3392 | flagpd1("fzvector"), |
| 3379 | flagpd1("g0"), | 3393 | flagpd1("g0"), |
| 3380 | flagpd1("g1"), | 3394 | .{ |
| 3395 | .name = "g1", | ||
| 3396 | .syntax = .flag, | ||
| 3397 | .zig_equivalent = .debug, | ||
| 3398 | .pd1 = true, | ||
| 3399 | .pd2 = false, | ||
| 3400 | .psl = false, | ||
| 3401 | }, | ||
| 3381 | flagpd1("g2"), | 3402 | flagpd1("g2"), |
| 3382 | flagpd1("g3"), | 3403 | flagpd1("g3"), |
| 3383 | .{ | 3404 | .{ |
| ... | @@ -3410,7 +3431,14 @@ flagpd1("ggdb3"), | ... | @@ -3410,7 +3431,14 @@ flagpd1("ggdb3"), |
| 3410 | flagpd1("ggnu-pubnames"), | 3431 | flagpd1("ggnu-pubnames"), |
| 3411 | flagpd1("ginline-line-tables"), | 3432 | flagpd1("ginline-line-tables"), |
| 3412 | flagpd1("gline-directives-only"), | 3433 | flagpd1("gline-directives-only"), |
| 3413 | flagpd1("gline-tables-only"), | 3434 | .{ |
| 3435 | .name = "gline-tables-only", | ||
| 3436 | .syntax = .flag, | ||
| 3437 | .zig_equivalent = .debug, | ||
| 3438 | .pd1 = true, | ||
| 3439 | .pd2 = false, | ||
| 3440 | .psl = false, | ||
| 3441 | }, | ||
| 3414 | flagpd1("glldb"), | 3442 | flagpd1("glldb"), |
| 3415 | flagpd1("gmlt"), | 3443 | flagpd1("gmlt"), |
| 3416 | flagpd1("gmodules"), | 3444 | flagpd1("gmodules"), |
| ... | @@ -5535,7 +5563,7 @@ jspd1("iquote"), | ... | @@ -5535,7 +5563,7 @@ jspd1("iquote"), |
| 5535 | joinpd1("weak-l"), | 5563 | joinpd1("weak-l"), |
| 5536 | .{ | 5564 | .{ |
| 5537 | .name = "Ofast", | 5565 | .name = "Ofast", |
| 5538 | .syntax = .joined, | 5566 | .syntax = .flag, |
| 5539 | .zig_equivalent = .optimize, | 5567 | .zig_equivalent = .optimize, |
| 5540 | .pd1 = true, | 5568 | .pd1 = true, |
| 5541 | .pd2 = false, | 5569 | .pd2 = false, |
src/link/MachO.zig-21| ... | @@ -287,9 +287,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { | ... | @@ -287,9 +287,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 287 | } | 287 | } |
| 288 | const cmd = &self.load_commands.items[self.dylinker_cmd_index.?].Dylinker; | 288 | const cmd = &self.load_commands.items[self.dylinker_cmd_index.?].Dylinker; |
| 289 | off += cmd.name; | 289 | off += cmd.name; |
| 290 | const padding = cmd.cmdsize - @sizeOf(macho.dylinker_command); | ||
| 291 | log.debug("writing LC_LOAD_DYLINKER padding of size {} at 0x{x}\n", .{ padding, off }); | ||
| 292 | try self.addPadding(padding, off); | ||
| 293 | log.debug("writing LC_LOAD_DYLINKER path to dyld at 0x{x}\n", .{off}); | 290 | log.debug("writing LC_LOAD_DYLINKER path to dyld at 0x{x}\n", .{off}); |
| 294 | try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), off); | 291 | try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), off); |
| 295 | } | 292 | } |
| ... | @@ -302,9 +299,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { | ... | @@ -302,9 +299,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 302 | } | 299 | } |
| 303 | const cmd = &self.load_commands.items[self.libsystem_cmd_index.?].Dylib; | 300 | const cmd = &self.load_commands.items[self.libsystem_cmd_index.?].Dylib; |
| 304 | off += cmd.dylib.name; | 301 | off += cmd.dylib.name; |
| 305 | const padding = cmd.cmdsize - @sizeOf(macho.dylib_command); | ||
| 306 | log.debug("writing LC_LOAD_DYLIB padding of size {} at 0x{x}\n", .{ padding, off }); | ||
| 307 | try self.addPadding(padding, off); | ||
| 308 | log.debug("writing LC_LOAD_DYLIB path to libSystem at 0x{x}\n", .{off}); | 302 | log.debug("writing LC_LOAD_DYLIB path to libSystem at 0x{x}\n", .{off}); |
| 309 | try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off); | 303 | try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off); |
| 310 | } | 304 | } |
| ... | @@ -1264,21 +1258,6 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 { | ... | @@ -1264,21 +1258,6 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 { |
| 1264 | return self.makeString(new_name); | 1258 | return self.makeString(new_name); |
| 1265 | } | 1259 | } |
| 1266 | 1260 | ||
| 1267 | /// TODO This should not heap allocate, instead it should utilize a fixed size, statically allocated | ||
| 1268 | /// global const array. You could even use pwritev to write the same buffer multiple times with only | ||
| 1269 | /// 1 syscall if you needed to, for example, write 8192 bytes using a buffer of only 4096 bytes. | ||
| 1270 | /// This size parameter should probably be a usize not u64. | ||
| 1271 | fn addPadding(self: *MachO, size: u64, file_offset: u64) !void { | ||
| 1272 | if (size == 0) return; | ||
| 1273 | |||
| 1274 | const buf = try self.base.allocator.alloc(u8, @intCast(usize, size)); | ||
| 1275 | defer self.base.allocator.free(buf); | ||
| 1276 | |||
| 1277 | mem.set(u8, buf[0..], 0); | ||
| 1278 | |||
| 1279 | try self.base.file.?.pwriteAll(buf, file_offset); | ||
| 1280 | } | ||
| 1281 | |||
| 1282 | fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 { | 1261 | fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 { |
| 1283 | const hdr_size: u64 = @sizeOf(macho.mach_header_64); | 1262 | const hdr_size: u64 = @sizeOf(macho.mach_header_64); |
| 1284 | if (start < hdr_size) return hdr_size; | 1263 | if (start < hdr_size) return hdr_size; |
src/main.zig+17-7| ... | @@ -992,15 +992,20 @@ fn buildOutputType( | ... | @@ -992,15 +992,20 @@ fn buildOutputType( |
| 992 | }, | 992 | }, |
| 993 | .optimize => { | 993 | .optimize => { |
| 994 | // Alright, what release mode do they want? | 994 | // Alright, what release mode do they want? |
| 995 | if (mem.eql(u8, it.only_arg, "Os")) { | 995 | const level = if (it.only_arg.len >= 1 and it.only_arg[0] == 'O') it.only_arg[1..] else it.only_arg; |
| 996 | if (mem.eql(u8, level, "s") or | ||
| 997 | mem.eql(u8, level, "z")) | ||
| 998 | { | ||
| 996 | optimize_mode = .ReleaseSmall; | 999 | optimize_mode = .ReleaseSmall; |
| 997 | } else if (mem.eql(u8, it.only_arg, "O2") or | 1000 | } else if (mem.eql(u8, level, "1") or |
| 998 | mem.eql(u8, it.only_arg, "O3") or | 1001 | mem.eql(u8, level, "2") or |
| 999 | mem.eql(u8, it.only_arg, "O4")) | 1002 | mem.eql(u8, level, "3") or |
| 1003 | mem.eql(u8, level, "4") or | ||
| 1004 | mem.eql(u8, level, "fast")) | ||
| 1000 | { | 1005 | { |
| 1001 | optimize_mode = .ReleaseFast; | 1006 | optimize_mode = .ReleaseFast; |
| 1002 | } else if (mem.eql(u8, it.only_arg, "Og") or | 1007 | } else if (mem.eql(u8, level, "g") or |
| 1003 | mem.eql(u8, it.only_arg, "O0")) | 1008 | mem.eql(u8, level, "0")) |
| 1004 | { | 1009 | { |
| 1005 | optimize_mode = .Debug; | 1010 | optimize_mode = .Debug; |
| 1006 | } else { | 1011 | } else { |
| ... | @@ -1009,8 +1014,13 @@ fn buildOutputType( | ... | @@ -1009,8 +1014,13 @@ fn buildOutputType( |
| 1009 | }, | 1014 | }, |
| 1010 | .debug => { | 1015 | .debug => { |
| 1011 | strip = false; | 1016 | strip = false; |
| 1012 | if (mem.eql(u8, it.only_arg, "-g")) { | 1017 | if (mem.eql(u8, it.only_arg, "g")) { |
| 1013 | // We handled with strip = false above. | 1018 | // We handled with strip = false above. |
| 1019 | } else if (mem.eql(u8, it.only_arg, "g1") or | ||
| 1020 | mem.eql(u8, it.only_arg, "gline-tables-only")) | ||
| 1021 | { | ||
| 1022 | // We handled with strip = false above. but we also want reduced debug info. | ||
| 1023 | try clang_argv.append("-gline-tables-only"); | ||
| 1014 | } else { | 1024 | } else { |
| 1015 | try clang_argv.appendSlice(it.other_args); | 1025 | try clang_argv.appendSlice(it.other_args); |
| 1016 | } | 1026 | } |
src/stage1/all_types.hpp+4-1| ... | @@ -72,7 +72,6 @@ enum PtrLen { | ... | @@ -72,7 +72,6 @@ enum PtrLen { |
| 72 | enum CallingConvention { | 72 | enum CallingConvention { |
| 73 | CallingConventionUnspecified, | 73 | CallingConventionUnspecified, |
| 74 | CallingConventionC, | 74 | CallingConventionC, |
| 75 | CallingConventionCold, | ||
| 76 | CallingConventionNaked, | 75 | CallingConventionNaked, |
| 77 | CallingConventionAsync, | 76 | CallingConventionAsync, |
| 78 | CallingConventionInterrupt, | 77 | CallingConventionInterrupt, |
| ... | @@ -1054,6 +1053,7 @@ enum ContainerKind { | ... | @@ -1054,6 +1053,7 @@ enum ContainerKind { |
| 1054 | ContainerKindStruct, | 1053 | ContainerKindStruct, |
| 1055 | ContainerKindEnum, | 1054 | ContainerKindEnum, |
| 1056 | ContainerKindUnion, | 1055 | ContainerKindUnion, |
| 1056 | ContainerKindOpaque, | ||
| 1057 | }; | 1057 | }; |
| 1058 | 1058 | ||
| 1059 | enum ContainerLayout { | 1059 | enum ContainerLayout { |
| ... | @@ -1571,7 +1571,10 @@ enum OnePossibleValue { | ... | @@ -1571,7 +1571,10 @@ enum OnePossibleValue { |
| 1571 | }; | 1571 | }; |
| 1572 | 1572 | ||
| 1573 | struct ZigTypeOpaque { | 1573 | struct ZigTypeOpaque { |
| 1574 | AstNode *decl_node; | ||
| 1574 | Buf *bare_name; | 1575 | Buf *bare_name; |
| 1576 | |||
| 1577 | ScopeDecls *decls_scope; | ||
| 1575 | }; | 1578 | }; |
| 1576 | 1579 | ||
| 1577 | struct ZigTypeFnFrame { | 1580 | struct ZigTypeFnFrame { |
src/stage1/analyze.cpp+81-35| ... | @@ -86,14 +86,18 @@ ZigType *new_type_table_entry(ZigTypeId id) { | ... | @@ -86,14 +86,18 @@ ZigType *new_type_table_entry(ZigTypeId id) { |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) { | 88 | static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) { |
| 89 | if (type_entry->id == ZigTypeIdStruct) { | 89 | switch (type_entry->id) { |
| 90 | return &type_entry->data.structure.decls_scope; | 90 | case ZigTypeIdStruct: |
| 91 | } else if (type_entry->id == ZigTypeIdEnum) { | 91 | return &type_entry->data.structure.decls_scope; |
| 92 | return &type_entry->data.enumeration.decls_scope; | 92 | case ZigTypeIdEnum: |
| 93 | } else if (type_entry->id == ZigTypeIdUnion) { | 93 | return &type_entry->data.enumeration.decls_scope; |
| 94 | return &type_entry->data.unionation.decls_scope; | 94 | case ZigTypeIdUnion: |
| 95 | return &type_entry->data.unionation.decls_scope; | ||
| 96 | case ZigTypeIdOpaque: | ||
| 97 | return &type_entry->data.opaque.decls_scope; | ||
| 98 | default: | ||
| 99 | zig_unreachable(); | ||
| 95 | } | 100 | } |
| 96 | zig_unreachable(); | ||
| 97 | } | 101 | } |
| 98 | 102 | ||
| 99 | static ScopeExpr *find_expr_scope(Scope *scope) { | 103 | static ScopeExpr *find_expr_scope(Scope *scope) { |
| ... | @@ -912,13 +916,17 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c | ... | @@ -912,13 +916,17 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c |
| 912 | ZigType *import = scope ? get_scope_import(scope) : nullptr; | 916 | ZigType *import = scope ? get_scope_import(scope) : nullptr; |
| 913 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; | 917 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; |
| 914 | 918 | ||
| 919 | // Note: duplicated in get_partial_container_type | ||
| 915 | entry->llvm_type = LLVMInt8Type(); | 920 | entry->llvm_type = LLVMInt8Type(); |
| 916 | entry->llvm_di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, | 921 | entry->llvm_di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, |
| 917 | ZigLLVMTag_DW_structure_type(), full_name, | 922 | ZigLLVMTag_DW_structure_type(), full_name, |
| 918 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, | 923 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, |
| 919 | import ? import->data.structure.root_struct->di_file : nullptr, | 924 | import ? import->data.structure.root_struct->di_file : nullptr, |
| 920 | line); | 925 | line); |
| 926 | entry->data.opaque.decl_node = source_node; | ||
| 921 | entry->data.opaque.bare_name = bare_name; | 927 | entry->data.opaque.bare_name = bare_name; |
| 928 | entry->data.opaque.decls_scope = create_decls_scope( | ||
| 929 | g, source_node, scope, entry, import, &entry->name); | ||
| 922 | 930 | ||
| 923 | // The actual size is unknown, but the value must not be 0 because that | 931 | // The actual size is unknown, but the value must not be 0 because that |
| 924 | // is how type_has_bits is determined. | 932 | // is how type_has_bits is determined. |
| ... | @@ -949,7 +957,6 @@ const char *calling_convention_name(CallingConvention cc) { | ... | @@ -949,7 +957,6 @@ const char *calling_convention_name(CallingConvention cc) { |
| 949 | switch (cc) { | 957 | switch (cc) { |
| 950 | case CallingConventionUnspecified: return "Unspecified"; | 958 | case CallingConventionUnspecified: return "Unspecified"; |
| 951 | case CallingConventionC: return "C"; | 959 | case CallingConventionC: return "C"; |
| 952 | case CallingConventionCold: return "Cold"; | ||
| 953 | case CallingConventionNaked: return "Naked"; | 960 | case CallingConventionNaked: return "Naked"; |
| 954 | case CallingConventionAsync: return "Async"; | 961 | case CallingConventionAsync: return "Async"; |
| 955 | case CallingConventionInterrupt: return "Interrupt"; | 962 | case CallingConventionInterrupt: return "Interrupt"; |
| ... | @@ -971,7 +978,6 @@ bool calling_convention_allows_zig_types(CallingConvention cc) { | ... | @@ -971,7 +978,6 @@ bool calling_convention_allows_zig_types(CallingConvention cc) { |
| 971 | case CallingConventionAsync: | 978 | case CallingConventionAsync: |
| 972 | return true; | 979 | return true; |
| 973 | case CallingConventionC: | 980 | case CallingConventionC: |
| 974 | case CallingConventionCold: | ||
| 975 | case CallingConventionNaked: | 981 | case CallingConventionNaked: |
| 976 | case CallingConventionInterrupt: | 982 | case CallingConventionInterrupt: |
| 977 | case CallingConventionSignal: | 983 | case CallingConventionSignal: |
| ... | @@ -1080,6 +1086,8 @@ static ZigTypeId container_to_type(ContainerKind kind) { | ... | @@ -1080,6 +1086,8 @@ static ZigTypeId container_to_type(ContainerKind kind) { |
| 1080 | return ZigTypeIdEnum; | 1086 | return ZigTypeIdEnum; |
| 1081 | case ContainerKindUnion: | 1087 | case ContainerKindUnion: |
| 1082 | return ZigTypeIdUnion; | 1088 | return ZigTypeIdUnion; |
| 1089 | case ContainerKindOpaque: | ||
| 1090 | return ZigTypeIdOpaque; | ||
| 1083 | } | 1091 | } |
| 1084 | zig_unreachable(); | 1092 | zig_unreachable(); |
| 1085 | } | 1093 | } |
| ... | @@ -1121,6 +1129,22 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind | ... | @@ -1121,6 +1129,22 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind |
| 1121 | entry->data.unionation.decl_node = decl_node; | 1129 | entry->data.unionation.decl_node = decl_node; |
| 1122 | entry->data.unionation.layout = layout; | 1130 | entry->data.unionation.layout = layout; |
| 1123 | break; | 1131 | break; |
| 1132 | case ContainerKindOpaque: { | ||
| 1133 | ZigType *import = scope ? get_scope_import(scope) : nullptr; | ||
| 1134 | unsigned line = decl_node ? (unsigned)(decl_node->line + 1) : 0; | ||
| 1135 | // Note: duplicated in get_opaque_type | ||
| 1136 | entry->llvm_type = LLVMInt8Type(); | ||
| 1137 | entry->llvm_di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, | ||
| 1138 | ZigLLVMTag_DW_structure_type(), full_name, | ||
| 1139 | import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, | ||
| 1140 | import ? import->data.structure.root_struct->di_file : nullptr, | ||
| 1141 | line); | ||
| 1142 | entry->data.opaque.decl_node = decl_node; | ||
| 1143 | entry->abi_size = SIZE_MAX; | ||
| 1144 | entry->size_in_bits = SIZE_MAX; | ||
| 1145 | entry->abi_align = 1; | ||
| 1146 | break; | ||
| 1147 | } | ||
| 1124 | } | 1148 | } |
| 1125 | 1149 | ||
| 1126 | buf_init_from_str(&entry->name, full_name); | 1150 | buf_init_from_str(&entry->name, full_name); |
| ... | @@ -1730,7 +1754,7 @@ static Error emit_error_unless_type_allowed_in_packed_union(CodeGen *g, ZigType | ... | @@ -1730,7 +1754,7 @@ static Error emit_error_unless_type_allowed_in_packed_union(CodeGen *g, ZigType |
| 1730 | return emit_error_unless_type_allowed_in_packed_container(g, type_entry, source_node, "union"); | 1754 | return emit_error_unless_type_allowed_in_packed_container(g, type_entry, source_node, "union"); |
| 1731 | } | 1755 | } |
| 1732 | 1756 | ||
| 1733 | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { | 1757 | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, ExternPosition position, bool *result) { |
| 1734 | Error err; | 1758 | Error err; |
| 1735 | switch (type_entry->id) { | 1759 | switch (type_entry->id) { |
| 1736 | case ZigTypeIdInvalid: | 1760 | case ZigTypeIdInvalid: |
| ... | @@ -1749,8 +1773,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { | ... | @@ -1749,8 +1773,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1749 | case ZigTypeIdAnyFrame: | 1773 | case ZigTypeIdAnyFrame: |
| 1750 | *result = false; | 1774 | *result = false; |
| 1751 | return ErrorNone; | 1775 | return ErrorNone; |
| 1752 | case ZigTypeIdOpaque: | ||
| 1753 | case ZigTypeIdUnreachable: | 1776 | case ZigTypeIdUnreachable: |
| 1777 | *result = position == ExternPositionFunctionReturn; | ||
| 1778 | return ErrorNone; | ||
| 1779 | case ZigTypeIdOpaque: | ||
| 1754 | case ZigTypeIdBool: | 1780 | case ZigTypeIdBool: |
| 1755 | *result = true; | 1781 | *result = true; |
| 1756 | return ErrorNone; | 1782 | return ErrorNone; |
| ... | @@ -1768,23 +1794,27 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { | ... | @@ -1768,23 +1794,27 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1768 | return ErrorNone; | 1794 | return ErrorNone; |
| 1769 | } | 1795 | } |
| 1770 | case ZigTypeIdVector: | 1796 | case ZigTypeIdVector: |
| 1771 | return type_allowed_in_extern(g, type_entry->data.vector.elem_type, result); | 1797 | return type_allowed_in_extern(g, type_entry->data.vector.elem_type, ExternPositionOther, result); |
| 1772 | case ZigTypeIdFloat: | 1798 | case ZigTypeIdFloat: |
| 1773 | *result = true; | 1799 | *result = true; |
| 1774 | return ErrorNone; | 1800 | return ErrorNone; |
| 1775 | case ZigTypeIdArray: | 1801 | case ZigTypeIdArray: |
| 1776 | return type_allowed_in_extern(g, type_entry->data.array.child_type, result); | 1802 | if ((err = type_allowed_in_extern(g, type_entry->data.array.child_type, ExternPositionOther, result))) |
| 1803 | return err; | ||
| 1804 | *result = *result && | ||
| 1805 | position != ExternPositionFunctionParameter && | ||
| 1806 | position != ExternPositionFunctionReturn; | ||
| 1807 | return ErrorNone; | ||
| 1777 | case ZigTypeIdFn: | 1808 | case ZigTypeIdFn: |
| 1778 | *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc); | 1809 | *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc); |
| 1779 | return ErrorNone; | 1810 | return ErrorNone; |
| 1780 | case ZigTypeIdPointer: | 1811 | case ZigTypeIdPointer: |
| 1781 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) | 1812 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) |
| 1782 | return err; | 1813 | return err; |
| 1783 | if (!type_has_bits(g, type_entry)) { | 1814 | bool has_bits; |
| 1784 | *result = false; | 1815 | if ((err = type_has_bits2(g, type_entry, &has_bits))) |
| 1785 | return ErrorNone; | 1816 | return err; |
| 1786 | } | 1817 | *result = has_bits; |
| 1787 | *result = true; | ||
| 1788 | return ErrorNone; | 1818 | return ErrorNone; |
| 1789 | case ZigTypeIdStruct: | 1819 | case ZigTypeIdStruct: |
| 1790 | *result = type_entry->data.structure.layout == ContainerLayoutExtern || | 1820 | *result = type_entry->data.structure.layout == ContainerLayoutExtern || |
| ... | @@ -1796,23 +1826,24 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { | ... | @@ -1796,23 +1826,24 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1796 | *result = false; | 1826 | *result = false; |
| 1797 | return ErrorNone; | 1827 | return ErrorNone; |
| 1798 | } | 1828 | } |
| 1799 | if (!type_is_nonnull_ptr(g, child_type)) { | 1829 | bool is_nonnull_ptr; |
| 1830 | if ((err = type_is_nonnull_ptr2(g, child_type, &is_nonnull_ptr))) | ||
| 1831 | return err; | ||
| 1832 | if (!is_nonnull_ptr) { | ||
| 1800 | *result = false; | 1833 | *result = false; |
| 1801 | return ErrorNone; | 1834 | return ErrorNone; |
| 1802 | } | 1835 | } |
| 1803 | return type_allowed_in_extern(g, child_type, result); | 1836 | return type_allowed_in_extern(g, child_type, ExternPositionOther, result); |
| 1804 | } | 1837 | } |
| 1805 | case ZigTypeIdEnum: { | 1838 | case ZigTypeIdEnum: { |
| 1806 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) | 1839 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) |
| 1807 | return err; | 1840 | return err; |
| 1808 | ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; | 1841 | ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; |
| 1809 | if (type_entry->data.enumeration.has_explicit_tag_type) { | 1842 | if (type_entry->data.enumeration.has_explicit_tag_type) |
| 1810 | return type_allowed_in_extern(g, tag_int_type, result); | 1843 | return type_allowed_in_extern(g, tag_int_type, position, result); |
| 1811 | } else { | 1844 | *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || |
| 1812 | *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || | 1845 | type_entry->data.enumeration.layout == ContainerLayoutPacked; |
| 1813 | type_entry->data.enumeration.layout == ContainerLayoutPacked; | 1846 | return ErrorNone; |
| 1814 | return ErrorNone; | ||
| 1815 | } | ||
| 1816 | } | 1847 | } |
| 1817 | case ZigTypeIdUnion: | 1848 | case ZigTypeIdUnion: |
| 1818 | *result = type_entry->data.unionation.layout == ContainerLayoutExtern || | 1849 | *result = type_entry->data.unionation.layout == ContainerLayoutExtern || |
| ... | @@ -1909,7 +1940,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -1909,7 +1940,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1909 | 1940 | ||
| 1910 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | 1941 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1911 | bool ok_type; | 1942 | bool ok_type; |
| 1912 | if ((err = type_allowed_in_extern(g, type_entry, &ok_type))) | 1943 | if ((err = type_allowed_in_extern(g, type_entry, ExternPositionFunctionParameter, &ok_type))) |
| 1913 | return g->builtin_types.entry_invalid; | 1944 | return g->builtin_types.entry_invalid; |
| 1914 | if (!ok_type) { | 1945 | if (!ok_type) { |
| 1915 | add_node_error(g, param_node->data.param_decl.type, | 1946 | add_node_error(g, param_node->data.param_decl.type, |
| ... | @@ -2014,7 +2045,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -2014,7 +2045,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 2014 | if ((err = type_resolve(g, fn_type_id.return_type, ResolveStatusSizeKnown))) | 2045 | if ((err = type_resolve(g, fn_type_id.return_type, ResolveStatusSizeKnown))) |
| 2015 | return g->builtin_types.entry_invalid; | 2046 | return g->builtin_types.entry_invalid; |
| 2016 | bool ok_type; | 2047 | bool ok_type; |
| 2017 | if ((err = type_allowed_in_extern(g, fn_type_id.return_type, &ok_type))) | 2048 | if ((err = type_allowed_in_extern(g, fn_type_id.return_type, ExternPositionFunctionReturn, &ok_type))) |
| 2018 | return g->builtin_types.entry_invalid; | 2049 | return g->builtin_types.entry_invalid; |
| 2019 | if (!ok_type) { | 2050 | if (!ok_type) { |
| 2020 | add_node_error(g, fn_proto->return_type, | 2051 | add_node_error(g, fn_proto->return_type, |
| ... | @@ -2333,7 +2364,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -2333,7 +2364,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2333 | 2364 | ||
| 2334 | if (struct_type->data.structure.layout == ContainerLayoutExtern) { | 2365 | if (struct_type->data.structure.layout == ContainerLayoutExtern) { |
| 2335 | bool ok_type; | 2366 | bool ok_type; |
| 2336 | if ((err = type_allowed_in_extern(g, field_type, &ok_type))) { | 2367 | if ((err = type_allowed_in_extern(g, field_type, ExternPositionOther, &ok_type))) { |
| 2337 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; | 2368 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2338 | return ErrorSemanticAnalyzeFail; | 2369 | return ErrorSemanticAnalyzeFail; |
| 2339 | } | 2370 | } |
| ... | @@ -2588,7 +2619,7 @@ static Error type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty, bool *result | ... | @@ -2588,7 +2619,7 @@ static Error type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty, bool *result |
| 2588 | // signed char, a signed integer or an unsigned one. But GCC/Clang allow | 2619 | // signed char, a signed integer or an unsigned one. But GCC/Clang allow |
| 2589 | // other integral types as a compiler extension so let's accomodate them | 2620 | // other integral types as a compiler extension so let's accomodate them |
| 2590 | // aswell. | 2621 | // aswell. |
| 2591 | return type_allowed_in_extern(g, ty, result); | 2622 | return type_allowed_in_extern(g, ty, ExternPositionOther, result); |
| 2592 | } | 2623 | } |
| 2593 | 2624 | ||
| 2594 | static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | 2625 | static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| ... | @@ -3430,6 +3461,21 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { | ... | @@ -3430,6 +3461,21 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3430 | return ErrorNone; | 3461 | return ErrorNone; |
| 3431 | } | 3462 | } |
| 3432 | 3463 | ||
| 3464 | static Error resolve_opaque_type(CodeGen *g, ZigType *opaque_type) { | ||
| 3465 | Error err = ErrorNone; | ||
| 3466 | AstNode *container_node = opaque_type->data.opaque.decl_node; | ||
| 3467 | if (container_node != nullptr) { | ||
| 3468 | assert(container_node->type == NodeTypeContainerDecl); | ||
| 3469 | AstNodeContainerDecl *container_decl = &container_node->data.container_decl; | ||
| 3470 | for (size_t i = 0; i < container_decl->fields.length; i++) { | ||
| 3471 | AstNode *field_node = container_decl->fields.items[i]; | ||
| 3472 | add_node_error(g, field_node, buf_create_from_str("opaque types cannot have fields")); | ||
| 3473 | err = ErrorSemanticAnalyzeFail; | ||
| 3474 | } | ||
| 3475 | } | ||
| 3476 | return err; | ||
| 3477 | } | ||
| 3478 | |||
| 3433 | void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) { | 3479 | void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) { |
| 3434 | if (g->root_import == container_type || buf_len(&container_type->name) == 0) return; | 3480 | if (g->root_import == container_type || buf_len(&container_type->name) == 0) return; |
| 3435 | buf_append_buf(buf, &container_type->name); | 3481 | buf_append_buf(buf, &container_type->name); |
| ... | @@ -3603,7 +3649,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { | ... | @@ -3603,7 +3649,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3603 | tld_fn->base.resolution = TldResolutionInvalid; | 3649 | tld_fn->base.resolution = TldResolutionInvalid; |
| 3604 | return; | 3650 | return; |
| 3605 | case CallingConventionC: | 3651 | case CallingConventionC: |
| 3606 | case CallingConventionCold: | ||
| 3607 | case CallingConventionNaked: | 3652 | case CallingConventionNaked: |
| 3608 | case CallingConventionInterrupt: | 3653 | case CallingConventionInterrupt: |
| 3609 | case CallingConventionSignal: | 3654 | case CallingConventionSignal: |
| ... | @@ -3896,6 +3941,8 @@ static Error resolve_decl_container(CodeGen *g, TldContainer *tld_container) { | ... | @@ -3896,6 +3941,8 @@ static Error resolve_decl_container(CodeGen *g, TldContainer *tld_container) { |
| 3896 | return resolve_enum_zero_bits(g, tld_container->type_entry); | 3941 | return resolve_enum_zero_bits(g, tld_container->type_entry); |
| 3897 | case ZigTypeIdUnion: | 3942 | case ZigTypeIdUnion: |
| 3898 | return resolve_union_type(g, tld_container->type_entry); | 3943 | return resolve_union_type(g, tld_container->type_entry); |
| 3944 | case ZigTypeIdOpaque: | ||
| 3945 | return resolve_opaque_type(g, tld_container->type_entry); | ||
| 3899 | default: | 3946 | default: |
| 3900 | zig_unreachable(); | 3947 | zig_unreachable(); |
| 3901 | } | 3948 | } |
| ... | @@ -4462,6 +4509,7 @@ bool is_container(ZigType *type_entry) { | ... | @@ -4462,6 +4509,7 @@ bool is_container(ZigType *type_entry) { |
| 4462 | return type_entry->data.structure.special != StructSpecialSlice; | 4509 | return type_entry->data.structure.special != StructSpecialSlice; |
| 4463 | case ZigTypeIdEnum: | 4510 | case ZigTypeIdEnum: |
| 4464 | case ZigTypeIdUnion: | 4511 | case ZigTypeIdUnion: |
| 4512 | case ZigTypeIdOpaque: | ||
| 4465 | return true; | 4513 | return true; |
| 4466 | case ZigTypeIdPointer: | 4514 | case ZigTypeIdPointer: |
| 4467 | case ZigTypeIdMetaType: | 4515 | case ZigTypeIdMetaType: |
| ... | @@ -4481,7 +4529,6 @@ bool is_container(ZigType *type_entry) { | ... | @@ -4481,7 +4529,6 @@ bool is_container(ZigType *type_entry) { |
| 4481 | case ZigTypeIdErrorSet: | 4529 | case ZigTypeIdErrorSet: |
| 4482 | case ZigTypeIdFn: | 4530 | case ZigTypeIdFn: |
| 4483 | case ZigTypeIdBoundFn: | 4531 | case ZigTypeIdBoundFn: |
| 4484 | case ZigTypeIdOpaque: | ||
| 4485 | case ZigTypeIdVector: | 4532 | case ZigTypeIdVector: |
| 4486 | case ZigTypeIdFnFrame: | 4533 | case ZigTypeIdFnFrame: |
| 4487 | case ZigTypeIdAnyFrame: | 4534 | case ZigTypeIdAnyFrame: |
| ... | @@ -8168,6 +8215,7 @@ const char *container_string(ContainerKind kind) { | ... | @@ -8168,6 +8215,7 @@ const char *container_string(ContainerKind kind) { |
| 8168 | case ContainerKindEnum: return "enum"; | 8215 | case ContainerKindEnum: return "enum"; |
| 8169 | case ContainerKindStruct: return "struct"; | 8216 | case ContainerKindStruct: return "struct"; |
| 8170 | case ContainerKindUnion: return "union"; | 8217 | case ContainerKindUnion: return "union"; |
| 8218 | case ContainerKindOpaque: return "opaque"; | ||
| 8171 | } | 8219 | } |
| 8172 | zig_unreachable(); | 8220 | zig_unreachable(); |
| 8173 | } | 8221 | } |
| ... | @@ -8186,8 +8234,6 @@ Buf *type_bare_name(ZigType *type_entry) { | ... | @@ -8186,8 +8234,6 @@ Buf *type_bare_name(ZigType *type_entry) { |
| 8186 | return &type_entry->name; | 8234 | return &type_entry->name; |
| 8187 | } else if (is_container(type_entry)) { | 8235 | } else if (is_container(type_entry)) { |
| 8188 | return get_container_scope(type_entry)->bare_name; | 8236 | return get_container_scope(type_entry)->bare_name; |
| 8189 | } else if (type_entry->id == ZigTypeIdOpaque) { | ||
| 8190 | return type_entry->data.opaque.bare_name; | ||
| 8191 | } else { | 8237 | } else { |
| 8192 | return &type_entry->name; | 8238 | return &type_entry->name; |
| 8193 | } | 8239 | } |
src/stage1/analyze.hpp+7-1| ... | @@ -50,7 +50,13 @@ bool handle_is_ptr(CodeGen *g, ZigType *type_entry); | ... | @@ -50,7 +50,13 @@ bool handle_is_ptr(CodeGen *g, ZigType *type_entry); |
| 50 | bool type_has_bits(CodeGen *g, ZigType *type_entry); | 50 | bool type_has_bits(CodeGen *g, ZigType *type_entry); |
| 51 | Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result); | 51 | Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result); |
| 52 | 52 | ||
| 53 | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result); | 53 | enum ExternPosition { |
| 54 | ExternPositionFunctionParameter, | ||
| 55 | ExternPositionFunctionReturn, | ||
| 56 | ExternPositionOther, // array element, struct field, optional element, etc | ||
| 57 | }; | ||
| 58 | |||
| 59 | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, ExternPosition position, bool *result); | ||
| 54 | bool ptr_allows_addr_zero(ZigType *ptr_type); | 60 | bool ptr_allows_addr_zero(ZigType *ptr_type); |
| 55 | 61 | ||
| 56 | // Deprecated, use `type_is_nonnull_ptr2` | 62 | // Deprecated, use `type_is_nonnull_ptr2` |
src/stage1/codegen.cpp+12-20| ... | @@ -161,12 +161,6 @@ static ZigLLVM_CallingConv get_llvm_cc(CodeGen *g, CallingConvention cc) { | ... | @@ -161,12 +161,6 @@ static ZigLLVM_CallingConv get_llvm_cc(CodeGen *g, CallingConvention cc) { |
| 161 | return ZigLLVM_Fast; | 161 | return ZigLLVM_Fast; |
| 162 | case CallingConventionC: | 162 | case CallingConventionC: |
| 163 | return ZigLLVM_C; | 163 | return ZigLLVM_C; |
| 164 | case CallingConventionCold: | ||
| 165 | if ((g->zig_target->arch == ZigLLVM_x86 || | ||
| 166 | g->zig_target->arch == ZigLLVM_x86_64) && | ||
| 167 | g->zig_target->os != OsWindows) | ||
| 168 | return ZigLLVM_Cold; | ||
| 169 | return ZigLLVM_C; | ||
| 170 | case CallingConventionNaked: | 164 | case CallingConventionNaked: |
| 171 | zig_unreachable(); | 165 | zig_unreachable(); |
| 172 | case CallingConventionStdcall: | 166 | case CallingConventionStdcall: |
| ... | @@ -340,7 +334,6 @@ static bool cc_want_sret_attr(CallingConvention cc) { | ... | @@ -340,7 +334,6 @@ static bool cc_want_sret_attr(CallingConvention cc) { |
| 340 | case CallingConventionNaked: | 334 | case CallingConventionNaked: |
| 341 | zig_unreachable(); | 335 | zig_unreachable(); |
| 342 | case CallingConventionC: | 336 | case CallingConventionC: |
| 343 | case CallingConventionCold: | ||
| 344 | case CallingConventionInterrupt: | 337 | case CallingConventionInterrupt: |
| 345 | case CallingConventionSignal: | 338 | case CallingConventionSignal: |
| 346 | case CallingConventionStdcall: | 339 | case CallingConventionStdcall: |
| ... | @@ -449,7 +442,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { | ... | @@ -449,7 +442,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 449 | ZigLLVMFunctionSetCallingConv(llvm_fn, get_llvm_cc(g, cc)); | 442 | ZigLLVMFunctionSetCallingConv(llvm_fn, get_llvm_cc(g, cc)); |
| 450 | } | 443 | } |
| 451 | 444 | ||
| 452 | bool want_cold = fn->is_cold || cc == CallingConventionCold; | 445 | bool want_cold = fn->is_cold; |
| 453 | if (want_cold) { | 446 | if (want_cold) { |
| 454 | ZigLLVMAddFunctionAttrCold(llvm_fn); | 447 | ZigLLVMAddFunctionAttrCold(llvm_fn); |
| 455 | } | 448 | } |
| ... | @@ -8819,18 +8812,17 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { | ... | @@ -8819,18 +8812,17 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { |
| 8819 | 8812 | ||
| 8820 | static_assert(CallingConventionUnspecified == 0, ""); | 8813 | static_assert(CallingConventionUnspecified == 0, ""); |
| 8821 | static_assert(CallingConventionC == 1, ""); | 8814 | static_assert(CallingConventionC == 1, ""); |
| 8822 | static_assert(CallingConventionCold == 2, ""); | 8815 | static_assert(CallingConventionNaked == 2, ""); |
| 8823 | static_assert(CallingConventionNaked == 3, ""); | 8816 | static_assert(CallingConventionAsync == 3, ""); |
| 8824 | static_assert(CallingConventionAsync == 4, ""); | 8817 | static_assert(CallingConventionInterrupt == 4, ""); |
| 8825 | static_assert(CallingConventionInterrupt == 5, ""); | 8818 | static_assert(CallingConventionSignal == 5, ""); |
| 8826 | static_assert(CallingConventionSignal == 6, ""); | 8819 | static_assert(CallingConventionStdcall == 6, ""); |
| 8827 | static_assert(CallingConventionStdcall == 7, ""); | 8820 | static_assert(CallingConventionFastcall == 7, ""); |
| 8828 | static_assert(CallingConventionFastcall == 8, ""); | 8821 | static_assert(CallingConventionVectorcall == 8, ""); |
| 8829 | static_assert(CallingConventionVectorcall == 9, ""); | 8822 | static_assert(CallingConventionThiscall == 9, ""); |
| 8830 | static_assert(CallingConventionThiscall == 10, ""); | 8823 | static_assert(CallingConventionAPCS == 10, ""); |
| 8831 | static_assert(CallingConventionAPCS == 11, ""); | 8824 | static_assert(CallingConventionAAPCS == 11, ""); |
| 8832 | static_assert(CallingConventionAAPCS == 12, ""); | 8825 | static_assert(CallingConventionAAPCSVFP == 12, ""); |
| 8833 | static_assert(CallingConventionAAPCSVFP == 13, ""); | ||
| 8834 | 8826 | ||
| 8835 | static_assert(FnInlineAuto == 0, ""); | 8827 | static_assert(FnInlineAuto == 0, ""); |
| 8836 | static_assert(FnInlineAlways == 1, ""); | 8828 | static_assert(FnInlineAlways == 1, ""); |
src/stage1/ir.cpp+45-7| ... | @@ -18917,7 +18917,6 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport | ... | @@ -18917,7 +18917,6 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 18917 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); | 18917 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 18918 | } break; | 18918 | } break; |
| 18919 | case CallingConventionC: | 18919 | case CallingConventionC: |
| 18920 | case CallingConventionCold: | ||
| 18921 | case CallingConventionNaked: | 18920 | case CallingConventionNaked: |
| 18922 | case CallingConventionInterrupt: | 18921 | case CallingConventionInterrupt: |
| 18923 | case CallingConventionSignal: | 18922 | case CallingConventionSignal: |
| ... | @@ -18965,7 +18964,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport | ... | @@ -18965,7 +18964,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 18965 | break; | 18964 | break; |
| 18966 | case ZigTypeIdArray: { | 18965 | case ZigTypeIdArray: { |
| 18967 | bool ok_type; | 18966 | bool ok_type; |
| 18968 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) | 18967 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, ExternPositionOther, &ok_type))) |
| 18969 | return ira->codegen->invalid_inst_gen; | 18968 | return ira->codegen->invalid_inst_gen; |
| 18970 | 18969 | ||
| 18971 | if (!ok_type) { | 18970 | if (!ok_type) { |
| ... | @@ -20103,7 +20102,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -20103,7 +20102,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 20103 | if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || | 20102 | if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || |
| 20104 | uncasted_value->value->type->id == ZigTypeIdErrorSet) | 20103 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 20105 | { | 20104 | { |
| 20106 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); | 20105 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`")); |
| 20107 | return ira->codegen->invalid_inst_gen; | 20106 | return ira->codegen->invalid_inst_gen; |
| 20108 | } | 20107 | } |
| 20109 | return ir_const_void(ira, source_instr); | 20108 | return ir_const_void(ira, source_instr); |
| ... | @@ -22388,6 +22387,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, | ... | @@ -22388,6 +22387,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 22388 | prefix_name = "enum "; | 22387 | prefix_name = "enum "; |
| 22389 | } else if (bare_struct_type->id == ZigTypeIdUnion) { | 22388 | } else if (bare_struct_type->id == ZigTypeIdUnion) { |
| 22390 | prefix_name = "union "; | 22389 | prefix_name = "union "; |
| 22390 | } else if (bare_struct_type->id == ZigTypeIdOpaque) { | ||
| 22391 | prefix_name = "opaque type "; | ||
| 22391 | } else { | 22392 | } else { |
| 22392 | prefix_name = ""; | 22393 | prefix_name = ""; |
| 22393 | } | 22394 | } |
| ... | @@ -22588,7 +22589,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name | ... | @@ -22588,7 +22589,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 22588 | } | 22589 | } |
| 22589 | } | 22590 | } |
| 22590 | 22591 | ||
| 22591 | if (bare_type->id == ZigTypeIdEnum) { | 22592 | if (bare_type->id == ZigTypeIdEnum || bare_type->id == ZigTypeIdOpaque) { |
| 22592 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 22593 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 22593 | source_instr, container_ptr, container_ptr_src, container_type); | 22594 | source_instr, container_ptr, container_ptr_src, container_type); |
| 22594 | } | 22595 | } |
| ... | @@ -25184,7 +25185,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy | ... | @@ -25184,7 +25185,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25184 | case ZigTypeIdEnumLiteral: | 25185 | case ZigTypeIdEnumLiteral: |
| 25185 | case ZigTypeIdUndefined: | 25186 | case ZigTypeIdUndefined: |
| 25186 | case ZigTypeIdNull: | 25187 | case ZigTypeIdNull: |
| 25187 | case ZigTypeIdOpaque: | ||
| 25188 | result = ira->codegen->intern.for_void(); | 25188 | result = ira->codegen->intern.for_void(); |
| 25189 | break; | 25189 | break; |
| 25190 | case ZigTypeIdInt: | 25190 | case ZigTypeIdInt: |
| ... | @@ -25738,6 +25738,25 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy | ... | @@ -25738,6 +25738,25 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25738 | if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result))) | 25738 | if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result))) |
| 25739 | return err; | 25739 | return err; |
| 25740 | 25740 | ||
| 25741 | break; | ||
| 25742 | } | ||
| 25743 | case ZigTypeIdOpaque: | ||
| 25744 | { | ||
| 25745 | result = ira->codegen->pass1_arena->create<ZigValue>(); | ||
| 25746 | result->special = ConstValSpecialStatic; | ||
| 25747 | result->type = ir_type_info_get_type(ira, "Opaque", nullptr); | ||
| 25748 | |||
| 25749 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); | ||
| 25750 | result->data.x_struct.fields = fields; | ||
| 25751 | |||
| 25752 | // decls: []TypeInfo.Declaration | ||
| 25753 | ensure_field_index(result->type, "decls", 0); | ||
| 25754 | if ((err = ir_make_type_info_decls(ira, source_instr, fields[0], | ||
| 25755 | type_entry->data.opaque.decls_scope, false))) | ||
| 25756 | { | ||
| 25757 | return err; | ||
| 25758 | } | ||
| 25759 | |||
| 25741 | break; | 25760 | break; |
| 25742 | } | 25761 | } |
| 25743 | case ZigTypeIdFnFrame: | 25762 | case ZigTypeIdFnFrame: |
| ... | @@ -26045,6 +26064,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI | ... | @@ -26045,6 +26064,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 26045 | return get_error_union_type(ira->codegen, err_set_type, payload_type); | 26064 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 26046 | } | 26065 | } |
| 26047 | case ZigTypeIdOpaque: { | 26066 | case ZigTypeIdOpaque: { |
| 26067 | assert(payload->special == ConstValSpecialStatic); | ||
| 26068 | assert(payload->type == ir_type_info_get_type(ira, "Opaque", nullptr)); | ||
| 26069 | |||
| 26070 | ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 0); | ||
| 26071 | if (decls_value == nullptr) | ||
| 26072 | return ira->codegen->invalid_inst_gen->value->type; | ||
| 26073 | assert(decls_value->special == ConstValSpecialStatic); | ||
| 26074 | assert(is_slice(decls_value->type)); | ||
| 26075 | ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index]; | ||
| 26076 | size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint); | ||
| 26077 | if (decls_len != 0) { | ||
| 26078 | ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type")); | ||
| 26079 | return ira->codegen->invalid_inst_gen->value->type; | ||
| 26080 | } | ||
| 26081 | |||
| 26048 | Buf *bare_name = buf_alloc(); | 26082 | Buf *bare_name = buf_alloc(); |
| 26049 | Buf *full_name = get_anon_type_name(ira->codegen, | 26083 | Buf *full_name = get_anon_type_name(ira->codegen, |
| 26050 | ira->old_irb.exec, "opaque", source_instr->scope, source_instr->source_node, bare_name); | 26084 | ira->old_irb.exec, "opaque", source_instr->scope, source_instr->source_node, bare_name); |
| ... | @@ -29493,7 +29527,11 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, | ... | @@ -29493,7 +29527,11 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 29493 | return ira->codegen->invalid_inst_gen; | 29527 | return ira->codegen->invalid_inst_gen; |
| 29494 | 29528 | ||
| 29495 | if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { | 29529 | if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { |
| 29496 | ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); | 29530 | if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) { |
| 29531 | ir_add_error(ira, &instruction->base.base, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`")); | ||
| 29532 | }else{ | ||
| 29533 | ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); | ||
| 29534 | } | ||
| 29497 | } | 29535 | } |
| 29498 | 29536 | ||
| 29499 | return ir_const_void(ira, &instruction->base.base); | 29537 | return ir_const_void(ira, &instruction->base.base); |
| ... | @@ -32708,7 +32746,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { | ... | @@ -32708,7 +32746,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 32708 | return ErrorSemanticAnalyzeFail; | 32746 | return ErrorSemanticAnalyzeFail; |
| 32709 | } else if (lazy_ptr_type->ptr_len == PtrLenC) { | 32747 | } else if (lazy_ptr_type->ptr_len == PtrLenC) { |
| 32710 | bool ok_type; | 32748 | bool ok_type; |
| 32711 | if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type))) | 32749 | if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type))) |
| 32712 | return err; | 32750 | return err; |
| 32713 | if (!ok_type) { | 32751 | if (!ok_type) { |
| 32714 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, | 32752 | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
src/stage1/parser.cpp+9| ... | @@ -2920,6 +2920,7 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) { | ... | @@ -2920,6 +2920,7 @@ static AstNode *ast_parse_container_decl_auto(ParseContext *pc) { |
| 2920 | // <- KEYWORD_struct | 2920 | // <- KEYWORD_struct |
| 2921 | // / KEYWORD_enum (LPAREN Expr RPAREN)? | 2921 | // / KEYWORD_enum (LPAREN Expr RPAREN)? |
| 2922 | // / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? | 2922 | // / KEYWORD_union (LPAREN (KEYWORD_enum (LPAREN Expr RPAREN)? / Expr) RPAREN)? |
| 2923 | // / KEYWORD_opaque | ||
| 2923 | static AstNode *ast_parse_container_decl_type(ParseContext *pc) { | 2924 | static AstNode *ast_parse_container_decl_type(ParseContext *pc) { |
| 2924 | Token *first = eat_token_if(pc, TokenIdKeywordStruct); | 2925 | Token *first = eat_token_if(pc, TokenIdKeywordStruct); |
| 2925 | if (first != nullptr) { | 2926 | if (first != nullptr) { |
| ... | @@ -2929,6 +2930,14 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { | ... | @@ -2929,6 +2930,14 @@ static AstNode *ast_parse_container_decl_type(ParseContext *pc) { |
| 2929 | return res; | 2930 | return res; |
| 2930 | } | 2931 | } |
| 2931 | 2932 | ||
| 2933 | first = eat_token_if(pc, TokenIdKeywordOpaque); | ||
| 2934 | if (first != nullptr) { | ||
| 2935 | AstNode *res = ast_create_node(pc, NodeTypeContainerDecl, first); | ||
| 2936 | res->data.container_decl.init_arg_expr = nullptr; | ||
| 2937 | res->data.container_decl.kind = ContainerKindOpaque; | ||
| 2938 | return res; | ||
| 2939 | } | ||
| 2940 | |||
| 2932 | first = eat_token_if(pc, TokenIdKeywordEnum); | 2941 | first = eat_token_if(pc, TokenIdKeywordEnum); |
| 2933 | if (first != nullptr) { | 2942 | if (first != nullptr) { |
| 2934 | AstNode *init_arg_expr = nullptr; | 2943 | AstNode *init_arg_expr = nullptr; |
src/stage1/tokenizer.cpp+2| ... | @@ -133,6 +133,7 @@ static const struct ZigKeyword zig_keywords[] = { | ... | @@ -133,6 +133,7 @@ static const struct ZigKeyword zig_keywords[] = { |
| 133 | {"noinline", TokenIdKeywordNoInline}, | 133 | {"noinline", TokenIdKeywordNoInline}, |
| 134 | {"nosuspend", TokenIdKeywordNoSuspend}, | 134 | {"nosuspend", TokenIdKeywordNoSuspend}, |
| 135 | {"null", TokenIdKeywordNull}, | 135 | {"null", TokenIdKeywordNull}, |
| 136 | {"opaque", TokenIdKeywordOpaque}, | ||
| 136 | {"or", TokenIdKeywordOr}, | 137 | {"or", TokenIdKeywordOr}, |
| 137 | {"orelse", TokenIdKeywordOrElse}, | 138 | {"orelse", TokenIdKeywordOrElse}, |
| 138 | {"packed", TokenIdKeywordPacked}, | 139 | {"packed", TokenIdKeywordPacked}, |
| ... | @@ -1595,6 +1596,7 @@ const char * token_name(TokenId id) { | ... | @@ -1595,6 +1596,7 @@ const char * token_name(TokenId id) { |
| 1595 | case TokenIdKeywordNoInline: return "noinline"; | 1596 | case TokenIdKeywordNoInline: return "noinline"; |
| 1596 | case TokenIdKeywordNoSuspend: return "nosuspend"; | 1597 | case TokenIdKeywordNoSuspend: return "nosuspend"; |
| 1597 | case TokenIdKeywordNull: return "null"; | 1598 | case TokenIdKeywordNull: return "null"; |
| 1599 | case TokenIdKeywordOpaque: return "opaque"; | ||
| 1598 | case TokenIdKeywordOr: return "or"; | 1600 | case TokenIdKeywordOr: return "or"; |
| 1599 | case TokenIdKeywordOrElse: return "orelse"; | 1601 | case TokenIdKeywordOrElse: return "orelse"; |
| 1600 | case TokenIdKeywordPacked: return "packed"; | 1602 | case TokenIdKeywordPacked: return "packed"; |
src/stage1/tokenizer.hpp+1| ... | @@ -81,6 +81,7 @@ enum TokenId { | ... | @@ -81,6 +81,7 @@ enum TokenId { |
| 81 | TokenIdKeywordNoAlias, | 81 | TokenIdKeywordNoAlias, |
| 82 | TokenIdKeywordNoSuspend, | 82 | TokenIdKeywordNoSuspend, |
| 83 | TokenIdKeywordNull, | 83 | TokenIdKeywordNull, |
| 84 | TokenIdKeywordOpaque, | ||
| 84 | TokenIdKeywordOr, | 85 | TokenIdKeywordOr, |
| 85 | TokenIdKeywordOrElse, | 86 | TokenIdKeywordOrElse, |
| 86 | TokenIdKeywordPacked, | 87 | TokenIdKeywordPacked, |
src/translate_c.zig+682-682| ... | @@ -5,7 +5,7 @@ const std = @import("std"); | ... | @@ -5,7 +5,7 @@ const std = @import("std"); |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | const ast = std.zig.ast; | 6 | const ast = std.zig.ast; |
| 7 | const Token = std.zig.Token; | 7 | const Token = std.zig.Token; |
| 8 | usingnamespace @import("clang.zig"); | 8 | const clang = @import("clang.zig"); |
| 9 | const ctok = std.c.tokenizer; | 9 | const ctok = std.c.tokenizer; |
| 10 | const CToken = std.c.Token; | 10 | const CToken = std.c.Token; |
| 11 | const mem = std.mem; | 11 | const mem = std.mem; |
| ... | @@ -13,7 +13,7 @@ const math = std.math; | ... | @@ -13,7 +13,7 @@ const math = std.math; |
| 13 | 13 | ||
| 14 | const CallingConvention = std.builtin.CallingConvention; | 14 | const CallingConvention = std.builtin.CallingConvention; |
| 15 | 15 | ||
| 16 | pub const ClangErrMsg = Stage2ErrorMsg; | 16 | pub const ClangErrMsg = clang.Stage2ErrorMsg; |
| 17 | 17 | ||
| 18 | pub const Error = error{OutOfMemory}; | 18 | pub const Error = error{OutOfMemory}; |
| 19 | const TypeError = Error || error{UnsupportedType}; | 19 | const TypeError = Error || error{UnsupportedType}; |
| ... | @@ -259,11 +259,11 @@ pub const Context = struct { | ... | @@ -259,11 +259,11 @@ pub const Context = struct { |
| 259 | errors: std.ArrayListUnmanaged(ast.Error), | 259 | errors: std.ArrayListUnmanaged(ast.Error), |
| 260 | source_buffer: *std.ArrayList(u8), | 260 | source_buffer: *std.ArrayList(u8), |
| 261 | err: Error, | 261 | err: Error, |
| 262 | source_manager: *ZigClangSourceManager, | 262 | source_manager: *clang.SourceManager, |
| 263 | decl_table: DeclTable, | 263 | decl_table: DeclTable, |
| 264 | alias_list: AliasList, | 264 | alias_list: AliasList, |
| 265 | global_scope: *Scope.Root, | 265 | global_scope: *Scope.Root, |
| 266 | clang_context: *ZigClangASTContext, | 266 | clang_context: *clang.ASTContext, |
| 267 | mangle_count: u32 = 0, | 267 | mangle_count: u32 = 0, |
| 268 | root_decls: std.ArrayListUnmanaged(*ast.Node), | 268 | root_decls: std.ArrayListUnmanaged(*ast.Node), |
| 269 | 269 | ||
| ... | @@ -284,13 +284,13 @@ pub const Context = struct { | ... | @@ -284,13 +284,13 @@ pub const Context = struct { |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | /// Convert a clang source location to a file:line:column string | 286 | /// Convert a clang source location to a file:line:column string |
| 287 | fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 { | 287 | fn locStr(c: *Context, loc: clang.SourceLocation) ![]u8 { |
| 288 | const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc); | 288 | const spelling_loc = c.source_manager.getSpellingLoc(loc); |
| 289 | const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc); | 289 | const filename_c = c.source_manager.getFilename(spelling_loc); |
| 290 | const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)"); | 290 | const filename = if (filename_c) |s| try c.str(s) else @as([]const u8, "(no file)"); |
| 291 | 291 | ||
| 292 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); | 292 | const line = c.source_manager.getSpellingLineNumber(spelling_loc); |
| 293 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); | 293 | const column = c.source_manager.getSpellingColumnNumber(spelling_loc); |
| 294 | return std.fmt.allocPrint(c.arena, "{}:{}:{}", .{ filename, line, column }); | 294 | return std.fmt.allocPrint(c.arena, "{}:{}:{}", .{ filename, line, column }); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| ... | @@ -336,7 +336,7 @@ pub fn translate( | ... | @@ -336,7 +336,7 @@ pub fn translate( |
| 336 | errors: *[]ClangErrMsg, | 336 | errors: *[]ClangErrMsg, |
| 337 | resources_path: [*:0]const u8, | 337 | resources_path: [*:0]const u8, |
| 338 | ) !*ast.Tree { | 338 | ) !*ast.Tree { |
| 339 | const ast_unit = ZigClangLoadFromCommandLine( | 339 | const ast_unit = clang.LoadFromCommandLine( |
| 340 | args_begin, | 340 | args_begin, |
| 341 | args_end, | 341 | args_end, |
| 342 | &errors.ptr, | 342 | &errors.ptr, |
| ... | @@ -346,7 +346,7 @@ pub fn translate( | ... | @@ -346,7 +346,7 @@ pub fn translate( |
| 346 | if (errors.len == 0) return error.ASTUnitFailure; | 346 | if (errors.len == 0) return error.ASTUnitFailure; |
| 347 | return error.SemanticAnalyzeFail; | 347 | return error.SemanticAnalyzeFail; |
| 348 | }; | 348 | }; |
| 349 | defer ZigClangASTUnit_delete(ast_unit); | 349 | defer ast_unit.delete(); |
| 350 | 350 | ||
| 351 | var source_buffer = std.ArrayList(u8).init(gpa); | 351 | var source_buffer = std.ArrayList(u8).init(gpa); |
| 352 | defer source_buffer.deinit(); | 352 | defer source_buffer.deinit(); |
| ... | @@ -360,12 +360,12 @@ pub fn translate( | ... | @@ -360,12 +360,12 @@ pub fn translate( |
| 360 | .gpa = gpa, | 360 | .gpa = gpa, |
| 361 | .arena = &arena.allocator, | 361 | .arena = &arena.allocator, |
| 362 | .source_buffer = &source_buffer, | 362 | .source_buffer = &source_buffer, |
| 363 | .source_manager = ZigClangASTUnit_getSourceManager(ast_unit), | 363 | .source_manager = ast_unit.getSourceManager(), |
| 364 | .err = undefined, | 364 | .err = undefined, |
| 365 | .decl_table = DeclTable.init(gpa), | 365 | .decl_table = DeclTable.init(gpa), |
| 366 | .alias_list = AliasList.init(gpa), | 366 | .alias_list = AliasList.init(gpa), |
| 367 | .global_scope = try arena.allocator.create(Scope.Root), | 367 | .global_scope = try arena.allocator.create(Scope.Root), |
| 368 | .clang_context = ZigClangASTUnit_getASTContext(ast_unit).?, | 368 | .clang_context = ast_unit.getASTContext(), |
| 369 | .global_names = std.StringArrayHashMap(void).init(gpa), | 369 | .global_names = std.StringArrayHashMap(void).init(gpa), |
| 370 | .token_ids = .{}, | 370 | .token_ids = .{}, |
| 371 | .token_locs = .{}, | 371 | .token_locs = .{}, |
| ... | @@ -383,7 +383,7 @@ pub fn translate( | ... | @@ -383,7 +383,7 @@ pub fn translate( |
| 383 | 383 | ||
| 384 | try prepopulateGlobalNameTable(ast_unit, &context); | 384 | try prepopulateGlobalNameTable(ast_unit, &context); |
| 385 | 385 | ||
| 386 | if (!ZigClangASTUnit_visitLocalTopLevelDecls(ast_unit, &context, declVisitorC)) { | 386 | if (!ast_unit.visitLocalTopLevelDecls(&context, declVisitorC)) { |
| 387 | return context.err; | 387 | return context.err; |
| 388 | } | 388 | } |
| 389 | 389 | ||
| ... | @@ -421,21 +421,21 @@ pub fn translate( | ... | @@ -421,21 +421,21 @@ pub fn translate( |
| 421 | return tree; | 421 | return tree; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | fn prepopulateGlobalNameTable(ast_unit: *ZigClangASTUnit, c: *Context) !void { | 424 | fn prepopulateGlobalNameTable(ast_unit: *clang.ASTUnit, c: *Context) !void { |
| 425 | if (!ZigClangASTUnit_visitLocalTopLevelDecls(ast_unit, c, declVisitorNamesOnlyC)) { | 425 | if (!ast_unit.visitLocalTopLevelDecls(c, declVisitorNamesOnlyC)) { |
| 426 | return c.err; | 426 | return c.err; |
| 427 | } | 427 | } |
| 428 | 428 | ||
| 429 | // TODO if we see #undef, delete it from the table | 429 | // TODO if we see #undef, delete it from the table |
| 430 | var it = ZigClangASTUnit_getLocalPreprocessingEntities_begin(ast_unit); | 430 | var it = ast_unit.getLocalPreprocessingEntities_begin(); |
| 431 | const it_end = ZigClangASTUnit_getLocalPreprocessingEntities_end(ast_unit); | 431 | const it_end = ast_unit.getLocalPreprocessingEntities_end(); |
| 432 | 432 | ||
| 433 | while (it.I != it_end.I) : (it.I += 1) { | 433 | while (it.I != it_end.I) : (it.I += 1) { |
| 434 | const entity = ZigClangPreprocessingRecord_iterator_deref(it); | 434 | const entity = it.deref(); |
| 435 | switch (ZigClangPreprocessedEntity_getKind(entity)) { | 435 | switch (entity.getKind()) { |
| 436 | .MacroDefinitionKind => { | 436 | .MacroDefinitionKind => { |
| 437 | const macro = @ptrCast(*ZigClangMacroDefinitionRecord, entity); | 437 | const macro = @ptrCast(*clang.MacroDefinitionRecord, entity); |
| 438 | const raw_name = ZigClangMacroDefinitionRecord_getName_getNameStart(macro); | 438 | const raw_name = macro.getName_getNameStart(); |
| 439 | const name = try c.str(raw_name); | 439 | const name = try c.str(raw_name); |
| 440 | _ = try c.global_names.put(name, {}); | 440 | _ = try c.global_names.put(name, {}); |
| 441 | }, | 441 | }, |
| ... | @@ -444,7 +444,7 @@ fn prepopulateGlobalNameTable(ast_unit: *ZigClangASTUnit, c: *Context) !void { | ... | @@ -444,7 +444,7 @@ fn prepopulateGlobalNameTable(ast_unit: *ZigClangASTUnit, c: *Context) !void { |
| 444 | } | 444 | } |
| 445 | } | 445 | } |
| 446 | 446 | ||
| 447 | fn declVisitorNamesOnlyC(context: ?*c_void, decl: *const ZigClangDecl) callconv(.C) bool { | 447 | fn declVisitorNamesOnlyC(context: ?*c_void, decl: *const clang.Decl) callconv(.C) bool { |
| 448 | const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context)); | 448 | const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context)); |
| 449 | declVisitorNamesOnly(c, decl) catch |err| { | 449 | declVisitorNamesOnly(c, decl) catch |err| { |
| 450 | c.err = err; | 450 | c.err = err; |
| ... | @@ -453,7 +453,7 @@ fn declVisitorNamesOnlyC(context: ?*c_void, decl: *const ZigClangDecl) callconv( | ... | @@ -453,7 +453,7 @@ fn declVisitorNamesOnlyC(context: ?*c_void, decl: *const ZigClangDecl) callconv( |
| 453 | return true; | 453 | return true; |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | fn declVisitorC(context: ?*c_void, decl: *const ZigClangDecl) callconv(.C) bool { | 456 | fn declVisitorC(context: ?*c_void, decl: *const clang.Decl) callconv(.C) bool { |
| 457 | const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context)); | 457 | const c = @ptrCast(*Context, @alignCast(@alignOf(Context), context)); |
| 458 | declVisitor(c, decl) catch |err| { | 458 | declVisitor(c, decl) catch |err| { |
| 459 | c.err = err; | 459 | c.err = err; |
| ... | @@ -462,61 +462,61 @@ fn declVisitorC(context: ?*c_void, decl: *const ZigClangDecl) callconv(.C) bool | ... | @@ -462,61 +462,61 @@ fn declVisitorC(context: ?*c_void, decl: *const ZigClangDecl) callconv(.C) bool |
| 462 | return true; | 462 | return true; |
| 463 | } | 463 | } |
| 464 | 464 | ||
| 465 | fn declVisitorNamesOnly(c: *Context, decl: *const ZigClangDecl) Error!void { | 465 | fn declVisitorNamesOnly(c: *Context, decl: *const clang.Decl) Error!void { |
| 466 | if (ZigClangDecl_castToNamedDecl(decl)) |named_decl| { | 466 | if (decl.castToNamedDecl()) |named_decl| { |
| 467 | const decl_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(named_decl)); | 467 | const decl_name = try c.str(named_decl.getName_bytes_begin()); |
| 468 | _ = try c.global_names.put(decl_name, {}); | 468 | _ = try c.global_names.put(decl_name, {}); |
| 469 | } | 469 | } |
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { | 472 | fn declVisitor(c: *Context, decl: *const clang.Decl) Error!void { |
| 473 | switch (ZigClangDecl_getKind(decl)) { | 473 | switch (decl.getKind()) { |
| 474 | .Function => { | 474 | .Function => { |
| 475 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); | 475 | return visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl)); |
| 476 | }, | 476 | }, |
| 477 | .Typedef => { | 477 | .Typedef => { |
| 478 | _ = try transTypeDef(c, @ptrCast(*const ZigClangTypedefNameDecl, decl), true); | 478 | _ = try transTypeDef(c, @ptrCast(*const clang.TypedefNameDecl, decl), true); |
| 479 | }, | 479 | }, |
| 480 | .Enum => { | 480 | .Enum => { |
| 481 | _ = try transEnumDecl(c, @ptrCast(*const ZigClangEnumDecl, decl)); | 481 | _ = try transEnumDecl(c, @ptrCast(*const clang.EnumDecl, decl)); |
| 482 | }, | 482 | }, |
| 483 | .Record => { | 483 | .Record => { |
| 484 | _ = try transRecordDecl(c, @ptrCast(*const ZigClangRecordDecl, decl)); | 484 | _ = try transRecordDecl(c, @ptrCast(*const clang.RecordDecl, decl)); |
| 485 | }, | 485 | }, |
| 486 | .Var => { | 486 | .Var => { |
| 487 | return visitVarDecl(c, @ptrCast(*const ZigClangVarDecl, decl), null); | 487 | return visitVarDecl(c, @ptrCast(*const clang.VarDecl, decl), null); |
| 488 | }, | 488 | }, |
| 489 | .Empty => { | 489 | .Empty => { |
| 490 | // Do nothing | 490 | // Do nothing |
| 491 | }, | 491 | }, |
| 492 | else => { | 492 | else => { |
| 493 | const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl)); | 493 | const decl_name = try c.str(decl.getDeclKindName()); |
| 494 | try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", .{decl_name}); | 494 | try emitWarning(c, decl.getLocation(), "ignoring {} declaration", .{decl_name}); |
| 495 | }, | 495 | }, |
| 496 | } | 496 | } |
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | 499 | fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void { |
| 500 | const fn_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, fn_decl))); | 500 | const fn_name = try c.str(@ptrCast(*const clang.NamedDecl, fn_decl).getName_bytes_begin()); |
| 501 | if (c.global_scope.sym_table.contains(fn_name)) | 501 | if (c.global_scope.sym_table.contains(fn_name)) |
| 502 | return; // Avoid processing this decl twice | 502 | return; // Avoid processing this decl twice |
| 503 | 503 | ||
| 504 | // Skip this declaration if a proper definition exists | 504 | // Skip this declaration if a proper definition exists |
| 505 | if (!ZigClangFunctionDecl_isThisDeclarationADefinition(fn_decl)) { | 505 | if (!fn_decl.isThisDeclarationADefinition()) { |
| 506 | if (ZigClangFunctionDecl_getDefinition(fn_decl)) |def| | 506 | if (fn_decl.getDefinition()) |def| |
| 507 | return visitFnDecl(c, def); | 507 | return visitFnDecl(c, def); |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | const rp = makeRestorePoint(c); | 510 | const rp = makeRestorePoint(c); |
| 511 | const fn_decl_loc = ZigClangFunctionDecl_getLocation(fn_decl); | 511 | const fn_decl_loc = fn_decl.getLocation(); |
| 512 | const has_body = ZigClangFunctionDecl_hasBody(fn_decl); | 512 | const has_body = fn_decl.hasBody(); |
| 513 | const storage_class = ZigClangFunctionDecl_getStorageClass(fn_decl); | 513 | const storage_class = fn_decl.getStorageClass(); |
| 514 | const decl_ctx = FnDeclContext{ | 514 | const decl_ctx = FnDeclContext{ |
| 515 | .fn_name = fn_name, | 515 | .fn_name = fn_name, |
| 516 | .has_body = has_body, | 516 | .has_body = has_body, |
| 517 | .storage_class = storage_class, | 517 | .storage_class = storage_class, |
| 518 | .is_export = switch (storage_class) { | 518 | .is_export = switch (storage_class) { |
| 519 | .None => has_body and !ZigClangFunctionDecl_isInlineSpecified(fn_decl), | 519 | .None => has_body and !fn_decl.isInlineSpecified(), |
| 520 | .Extern, .Static => false, | 520 | .Extern, .Static => false, |
| 521 | .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}), | 521 | .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}), |
| 522 | .Auto => unreachable, // Not legal on functions | 522 | .Auto => unreachable, // Not legal on functions |
| ... | @@ -524,27 +524,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -524,27 +524,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 524 | }, | 524 | }, |
| 525 | }; | 525 | }; |
| 526 | 526 | ||
| 527 | var fn_qt = ZigClangFunctionDecl_getType(fn_decl); | 527 | var fn_qt = fn_decl.getType(); |
| 528 | 528 | ||
| 529 | const fn_type = while (true) { | 529 | const fn_type = while (true) { |
| 530 | const fn_type = ZigClangQualType_getTypePtr(fn_qt); | 530 | const fn_type = fn_qt.getTypePtr(); |
| 531 | 531 | ||
| 532 | switch (ZigClangType_getTypeClass(fn_type)) { | 532 | switch (fn_type.getTypeClass()) { |
| 533 | .Attributed => { | 533 | .Attributed => { |
| 534 | const attr_type = @ptrCast(*const ZigClangAttributedType, fn_type); | 534 | const attr_type = @ptrCast(*const clang.AttributedType, fn_type); |
| 535 | fn_qt = ZigClangAttributedType_getEquivalentType(attr_type); | 535 | fn_qt = attr_type.getEquivalentType(); |
| 536 | }, | 536 | }, |
| 537 | .Paren => { | 537 | .Paren => { |
| 538 | const paren_type = @ptrCast(*const ZigClangParenType, fn_type); | 538 | const paren_type = @ptrCast(*const clang.ParenType, fn_type); |
| 539 | fn_qt = ZigClangParenType_getInnerType(paren_type); | 539 | fn_qt = paren_type.getInnerType(); |
| 540 | }, | 540 | }, |
| 541 | else => break fn_type, | 541 | else => break fn_type, |
| 542 | } | 542 | } |
| 543 | } else unreachable; | 543 | } else unreachable; |
| 544 | 544 | ||
| 545 | const proto_node = switch (ZigClangType_getTypeClass(fn_type)) { | 545 | const proto_node = switch (fn_type.getTypeClass()) { |
| 546 | .FunctionProto => blk: { | 546 | .FunctionProto => blk: { |
| 547 | const fn_proto_type = @ptrCast(*const ZigClangFunctionProtoType, fn_type); | 547 | const fn_proto_type = @ptrCast(*const clang.FunctionProtoType, fn_type); |
| 548 | break :blk transFnProto(rp, fn_decl, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { | 548 | break :blk transFnProto(rp, fn_decl, fn_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 549 | error.UnsupportedType => { | 549 | error.UnsupportedType => { |
| 550 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); | 550 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); |
| ... | @@ -553,7 +553,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -553,7 +553,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 553 | }; | 553 | }; |
| 554 | }, | 554 | }, |
| 555 | .FunctionNoProto => blk: { | 555 | .FunctionNoProto => blk: { |
| 556 | const fn_no_proto_type = @ptrCast(*const ZigClangFunctionType, fn_type); | 556 | const fn_no_proto_type = @ptrCast(*const clang.FunctionType, fn_type); |
| 557 | break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { | 557 | break :blk transFnNoProto(rp, fn_no_proto_type, fn_decl_loc, decl_ctx, true) catch |err| switch (err) { |
| 558 | error.UnsupportedType => { | 558 | error.UnsupportedType => { |
| 559 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); | 559 | return failDecl(c, fn_decl_loc, fn_name, "unable to resolve prototype of function", .{}); |
| ... | @@ -561,7 +561,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -561,7 +561,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 561 | error.OutOfMemory => |e| return e, | 561 | error.OutOfMemory => |e| return e, |
| 562 | }; | 562 | }; |
| 563 | }, | 563 | }, |
| 564 | else => return failDecl(c, fn_decl_loc, fn_name, "unable to resolve function type {}", .{ZigClangType_getTypeClass(fn_type)}), | 564 | else => return failDecl(c, fn_decl_loc, fn_name, "unable to resolve function type {}", .{fn_type.getTypeClass()}), |
| 565 | }; | 565 | }; |
| 566 | 566 | ||
| 567 | if (!decl_ctx.has_body) { | 567 | if (!decl_ctx.has_body) { |
| ... | @@ -570,7 +570,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -570,7 +570,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | // actual function definition with body | 572 | // actual function definition with body |
| 573 | const body_stmt = ZigClangFunctionDecl_getBody(fn_decl); | 573 | const body_stmt = fn_decl.getBody(); |
| 574 | var block_scope = try Scope.Block.init(rp.c, &c.global_scope.base, false); | 574 | var block_scope = try Scope.Block.init(rp.c, &c.global_scope.base, false); |
| 575 | defer block_scope.deinit(); | 575 | defer block_scope.deinit(); |
| 576 | var scope = &block_scope.base; | 576 | var scope = &block_scope.base; |
| ... | @@ -582,9 +582,9 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -582,9 +582,9 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 582 | else | 582 | else |
| 583 | return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name}); | 583 | return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name}); |
| 584 | 584 | ||
| 585 | const c_param = ZigClangFunctionDecl_getParamDecl(fn_decl, param_id); | 585 | const c_param = fn_decl.getParamDecl(param_id); |
| 586 | const qual_type = ZigClangParmVarDecl_getOriginalType(c_param); | 586 | const qual_type = c_param.getOriginalType(); |
| 587 | const is_const = ZigClangQualType_isConstQualified(qual_type); | 587 | const is_const = qual_type.isConstQualified(); |
| 588 | 588 | ||
| 589 | const mangled_param_name = try block_scope.makeMangledName(c, param_name); | 589 | const mangled_param_name = try block_scope.makeMangledName(c, param_name); |
| 590 | 590 | ||
| ... | @@ -613,7 +613,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -613,7 +613,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 613 | param_id += 1; | 613 | param_id += 1; |
| 614 | } | 614 | } |
| 615 | 615 | ||
| 616 | const casted_body = @ptrCast(*const ZigClangCompoundStmt, body_stmt); | 616 | const casted_body = @ptrCast(*const clang.CompoundStmt, body_stmt); |
| 617 | transCompoundStmtInline(rp, &block_scope.base, casted_body, &block_scope) catch |err| switch (err) { | 617 | transCompoundStmtInline(rp, &block_scope.base, casted_body, &block_scope) catch |err| switch (err) { |
| 618 | error.OutOfMemory => |e| return e, | 618 | error.OutOfMemory => |e| return e, |
| 619 | error.UnsupportedTranslation, | 619 | error.UnsupportedTranslation, |
| ... | @@ -622,10 +622,10 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -622,10 +622,10 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 622 | }; | 622 | }; |
| 623 | // add return statement if the function didn't have one | 623 | // add return statement if the function didn't have one |
| 624 | blk: { | 624 | blk: { |
| 625 | const fn_ty = @ptrCast(*const ZigClangFunctionType, fn_type); | 625 | const fn_ty = @ptrCast(*const clang.FunctionType, fn_type); |
| 626 | 626 | ||
| 627 | if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) break :blk; | 627 | if (fn_ty.getNoReturnAttr()) break :blk; |
| 628 | const return_qt = ZigClangFunctionType_getReturnType(fn_ty); | 628 | const return_qt = fn_ty.getReturnType(); |
| 629 | if (isCVoid(return_qt)) break :blk; | 629 | if (isCVoid(return_qt)) break :blk; |
| 630 | 630 | ||
| 631 | if (block_scope.statements.items.len > 0) { | 631 | if (block_scope.statements.items.len > 0) { |
| ... | @@ -649,7 +649,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -649,7 +649,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 649 | .ltoken = try appendToken(rp.c, .Keyword_return, "return"), | 649 | .ltoken = try appendToken(rp.c, .Keyword_return, "return"), |
| 650 | .tag = .Return, | 650 | .tag = .Return, |
| 651 | }, .{ | 651 | }, .{ |
| 652 | .rhs = transZeroInitExpr(rp, scope, fn_decl_loc, ZigClangQualType_getTypePtr(return_qt)) catch |err| switch (err) { | 652 | .rhs = transZeroInitExpr(rp, scope, fn_decl_loc, return_qt.getTypePtr()) catch |err| switch (err) { |
| 653 | error.OutOfMemory => |e| return e, | 653 | error.OutOfMemory => |e| return e, |
| 654 | error.UnsupportedTranslation, | 654 | error.UnsupportedTranslation, |
| 655 | error.UnsupportedType, | 655 | error.UnsupportedType, |
| ... | @@ -666,14 +666,14 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | ... | @@ -666,14 +666,14 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 666 | } | 666 | } |
| 667 | 667 | ||
| 668 | /// if mangled_name is not null, this var decl was declared in a block scope. | 668 | /// if mangled_name is not null, this var decl was declared in a block scope. |
| 669 | fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[]const u8) Error!void { | 669 | fn visitVarDecl(c: *Context, var_decl: *const clang.VarDecl, mangled_name: ?[]const u8) Error!void { |
| 670 | const var_name = mangled_name orelse try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, var_decl))); | 670 | const var_name = mangled_name orelse try c.str(@ptrCast(*const clang.NamedDecl, var_decl).getName_bytes_begin()); |
| 671 | if (c.global_scope.sym_table.contains(var_name)) | 671 | if (c.global_scope.sym_table.contains(var_name)) |
| 672 | return; // Avoid processing this decl twice | 672 | return; // Avoid processing this decl twice |
| 673 | const rp = makeRestorePoint(c); | 673 | const rp = makeRestorePoint(c); |
| 674 | const visib_tok = if (mangled_name) |_| null else try appendToken(c, .Keyword_pub, "pub"); | 674 | const visib_tok = if (mangled_name) |_| null else try appendToken(c, .Keyword_pub, "pub"); |
| 675 | 675 | ||
| 676 | const thread_local_token = if (ZigClangVarDecl_getTLSKind(var_decl) == .None) | 676 | const thread_local_token = if (var_decl.getTLSKind() == .None) |
| 677 | null | 677 | null |
| 678 | else | 678 | else |
| 679 | try appendToken(c, .Keyword_threadlocal, "threadlocal"); | 679 | try appendToken(c, .Keyword_threadlocal, "threadlocal"); |
| ... | @@ -683,12 +683,12 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] | ... | @@ -683,12 +683,12 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] |
| 683 | // TODO https://github.com/ziglang/zig/issues/3756 | 683 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 684 | // TODO https://github.com/ziglang/zig/issues/1802 | 684 | // TODO https://github.com/ziglang/zig/issues/1802 |
| 685 | const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.arena, "{}_{}", .{ var_name, c.getMangle() }) else var_name; | 685 | const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.arena, "{}_{}", .{ var_name, c.getMangle() }) else var_name; |
| 686 | const var_decl_loc = ZigClangVarDecl_getLocation(var_decl); | 686 | const var_decl_loc = var_decl.getLocation(); |
| 687 | 687 | ||
| 688 | const qual_type = ZigClangVarDecl_getTypeSourceInfo_getType(var_decl); | 688 | const qual_type = var_decl.getTypeSourceInfo_getType(); |
| 689 | const storage_class = ZigClangVarDecl_getStorageClass(var_decl); | 689 | const storage_class = var_decl.getStorageClass(); |
| 690 | const is_const = ZigClangQualType_isConstQualified(qual_type); | 690 | const is_const = qual_type.isConstQualified(); |
| 691 | const has_init = ZigClangVarDecl_hasInit(var_decl); | 691 | const has_init = var_decl.hasInit(); |
| 692 | 692 | ||
| 693 | // In C extern variables with initializers behave like Zig exports. | 693 | // In C extern variables with initializers behave like Zig exports. |
| 694 | // extern int foo = 2; | 694 | // extern int foo = 2; |
| ... | @@ -725,7 +725,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] | ... | @@ -725,7 +725,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] |
| 725 | // with the variable type. | 725 | // with the variable type. |
| 726 | if (has_init) { | 726 | if (has_init) { |
| 727 | eq_tok = try appendToken(c, .Equal, "="); | 727 | eq_tok = try appendToken(c, .Equal, "="); |
| 728 | init_node = if (ZigClangVarDecl_getInit(var_decl)) |expr| | 728 | init_node = if (var_decl.getInit()) |expr| |
| 729 | transExprCoercing(rp, &c.global_scope.base, expr, .used, .r_value) catch |err| switch (err) { | 729 | transExprCoercing(rp, &c.global_scope.base, expr, .used, .r_value) catch |err| switch (err) { |
| 730 | error.UnsupportedTranslation, | 730 | error.UnsupportedTranslation, |
| 731 | error.UnsupportedType, | 731 | error.UnsupportedType, |
| ... | @@ -758,7 +758,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] | ... | @@ -758,7 +758,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] |
| 758 | 758 | ||
| 759 | const linksection_expr = blk: { | 759 | const linksection_expr = blk: { |
| 760 | var str_len: usize = undefined; | 760 | var str_len: usize = undefined; |
| 761 | if (ZigClangVarDecl_getSectionAttribute(var_decl, &str_len)) |str_ptr| { | 761 | if (var_decl.getSectionAttribute(&str_len)) |str_ptr| { |
| 762 | _ = try appendToken(rp.c, .Keyword_linksection, "linksection"); | 762 | _ = try appendToken(rp.c, .Keyword_linksection, "linksection"); |
| 763 | _ = try appendToken(rp.c, .LParen, "("); | 763 | _ = try appendToken(rp.c, .LParen, "("); |
| 764 | const expr = try transCreateNodeStringLiteral( | 764 | const expr = try transCreateNodeStringLiteral( |
| ... | @@ -773,7 +773,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] | ... | @@ -773,7 +773,7 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] |
| 773 | }; | 773 | }; |
| 774 | 774 | ||
| 775 | const align_expr = blk: { | 775 | const align_expr = blk: { |
| 776 | const alignment = ZigClangVarDecl_getAlignedAttribute(var_decl, rp.c.clang_context); | 776 | const alignment = var_decl.getAlignedAttribute(rp.c.clang_context); |
| 777 | if (alignment != 0) { | 777 | if (alignment != 0) { |
| 778 | _ = try appendToken(rp.c, .Keyword_align, "align"); | 778 | _ = try appendToken(rp.c, .Keyword_align, "align"); |
| 779 | _ = try appendToken(rp.c, .LParen, "("); | 779 | _ = try appendToken(rp.c, .LParen, "("); |
| ... | @@ -803,8 +803,8 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] | ... | @@ -803,8 +803,8 @@ fn visitVarDecl(c: *Context, var_decl: *const ZigClangVarDecl, mangled_name: ?[] |
| 803 | return addTopLevelDecl(c, checked_name, &node.base); | 803 | return addTopLevelDecl(c, checked_name, &node.base); |
| 804 | } | 804 | } |
| 805 | 805 | ||
| 806 | fn transTypeDefAsBuiltin(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, builtin_name: []const u8) !*ast.Node { | 806 | fn transTypeDefAsBuiltin(c: *Context, typedef_decl: *const clang.TypedefNameDecl, builtin_name: []const u8) !*ast.Node { |
| 807 | _ = try c.decl_table.put(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)), builtin_name); | 807 | _ = try c.decl_table.put(@ptrToInt(typedef_decl.getCanonicalDecl()), builtin_name); |
| 808 | return transCreateNodeIdentifier(c, builtin_name); | 808 | return transCreateNodeIdentifier(c, builtin_name); |
| 809 | } | 809 | } |
| 810 | 810 | ||
| ... | @@ -833,12 +833,12 @@ fn checkForBuiltinTypedef(checked_name: []const u8) ?[]const u8 { | ... | @@ -833,12 +833,12 @@ fn checkForBuiltinTypedef(checked_name: []const u8) ?[]const u8 { |
| 833 | return null; | 833 | return null; |
| 834 | } | 834 | } |
| 835 | 835 | ||
| 836 | fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_level_visit: bool) Error!?*ast.Node { | 836 | fn transTypeDef(c: *Context, typedef_decl: *const clang.TypedefNameDecl, top_level_visit: bool) Error!?*ast.Node { |
| 837 | if (c.decl_table.get(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)))) |name| | 837 | if (c.decl_table.get(@ptrToInt(typedef_decl.getCanonicalDecl()))) |name| |
| 838 | return transCreateNodeIdentifier(c, name); // Avoid processing this decl twice | 838 | return transCreateNodeIdentifier(c, name); // Avoid processing this decl twice |
| 839 | const rp = makeRestorePoint(c); | 839 | const rp = makeRestorePoint(c); |
| 840 | 840 | ||
| 841 | const typedef_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, typedef_decl))); | 841 | const typedef_name = try c.str(@ptrCast(*const clang.NamedDecl, typedef_decl).getName_bytes_begin()); |
| 842 | 842 | ||
| 843 | // TODO https://github.com/ziglang/zig/issues/3756 | 843 | // TODO https://github.com/ziglang/zig/issues/3756 |
| 844 | // TODO https://github.com/ziglang/zig/issues/1802 | 844 | // TODO https://github.com/ziglang/zig/issues/1802 |
| ... | @@ -851,7 +851,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_l | ... | @@ -851,7 +851,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_l |
| 851 | return transCreateNodeIdentifier(c, checked_name); | 851 | return transCreateNodeIdentifier(c, checked_name); |
| 852 | } | 852 | } |
| 853 | 853 | ||
| 854 | _ = try c.decl_table.put(@ptrToInt(ZigClangTypedefNameDecl_getCanonicalDecl(typedef_decl)), checked_name); | 854 | _ = try c.decl_table.put(@ptrToInt(typedef_decl.getCanonicalDecl()), checked_name); |
| 855 | const node = (try transCreateNodeTypedef(rp, typedef_decl, true, checked_name)) orelse return null; | 855 | const node = (try transCreateNodeTypedef(rp, typedef_decl, true, checked_name)) orelse return null; |
| 856 | try addTopLevelDecl(c, checked_name, node); | 856 | try addTopLevelDecl(c, checked_name, node); |
| 857 | return transCreateNodeIdentifier(c, checked_name); | 857 | return transCreateNodeIdentifier(c, checked_name); |
| ... | @@ -859,7 +859,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_l | ... | @@ -859,7 +859,7 @@ fn transTypeDef(c: *Context, typedef_decl: *const ZigClangTypedefNameDecl, top_l |
| 859 | 859 | ||
| 860 | fn transCreateNodeTypedef( | 860 | fn transCreateNodeTypedef( |
| 861 | rp: RestorePoint, | 861 | rp: RestorePoint, |
| 862 | typedef_decl: *const ZigClangTypedefNameDecl, | 862 | typedef_decl: *const clang.TypedefNameDecl, |
| 863 | toplevel: bool, | 863 | toplevel: bool, |
| 864 | checked_name: []const u8, | 864 | checked_name: []const u8, |
| 865 | ) Error!?*ast.Node { | 865 | ) Error!?*ast.Node { |
| ... | @@ -867,8 +867,8 @@ fn transCreateNodeTypedef( | ... | @@ -867,8 +867,8 @@ fn transCreateNodeTypedef( |
| 867 | const mut_tok = try appendToken(rp.c, .Keyword_const, "const"); | 867 | const mut_tok = try appendToken(rp.c, .Keyword_const, "const"); |
| 868 | const name_tok = try appendIdentifier(rp.c, checked_name); | 868 | const name_tok = try appendIdentifier(rp.c, checked_name); |
| 869 | const eq_token = try appendToken(rp.c, .Equal, "="); | 869 | const eq_token = try appendToken(rp.c, .Equal, "="); |
| 870 | const child_qt = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); | 870 | const child_qt = typedef_decl.getUnderlyingType(); |
| 871 | const typedef_loc = ZigClangTypedefNameDecl_getLocation(typedef_decl); | 871 | const typedef_loc = typedef_decl.getLocation(); |
| 872 | const init_node = transQualType(rp, child_qt, typedef_loc) catch |err| switch (err) { | 872 | const init_node = transQualType(rp, child_qt, typedef_loc) catch |err| switch (err) { |
| 873 | error.UnsupportedType => { | 873 | error.UnsupportedType => { |
| 874 | try failDecl(rp.c, typedef_loc, checked_name, "unable to resolve typedef child type", .{}); | 874 | try failDecl(rp.c, typedef_loc, checked_name, "unable to resolve typedef child type", .{}); |
| ... | @@ -890,12 +890,12 @@ fn transCreateNodeTypedef( | ... | @@ -890,12 +890,12 @@ fn transCreateNodeTypedef( |
| 890 | return &node.base; | 890 | return &node.base; |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?*ast.Node { | 893 | fn transRecordDecl(c: *Context, record_decl: *const clang.RecordDecl) Error!?*ast.Node { |
| 894 | if (c.decl_table.get(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)))) |name| | 894 | if (c.decl_table.get(@ptrToInt(record_decl.getCanonicalDecl()))) |name| |
| 895 | return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice | 895 | return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice |
| 896 | const record_loc = ZigClangRecordDecl_getLocation(record_decl); | 896 | const record_loc = record_decl.getLocation(); |
| 897 | 897 | ||
| 898 | var bare_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, record_decl))); | 898 | var bare_name = try c.str(@ptrCast(*const clang.NamedDecl, record_decl).getName_bytes_begin()); |
| 899 | var is_unnamed = false; | 899 | var is_unnamed = false; |
| 900 | // Record declarations such as `struct {...} x` have no name but they're not | 900 | // Record declarations such as `struct {...} x` have no name but they're not |
| 901 | // anonymous hence here isAnonymousStructOrUnion is not needed | 901 | // anonymous hence here isAnonymousStructOrUnion is not needed |
| ... | @@ -906,10 +906,10 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -906,10 +906,10 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 906 | 906 | ||
| 907 | var container_kind_name: []const u8 = undefined; | 907 | var container_kind_name: []const u8 = undefined; |
| 908 | var container_kind: std.zig.Token.Id = undefined; | 908 | var container_kind: std.zig.Token.Id = undefined; |
| 909 | if (ZigClangRecordDecl_isUnion(record_decl)) { | 909 | if (record_decl.isUnion()) { |
| 910 | container_kind_name = "union"; | 910 | container_kind_name = "union"; |
| 911 | container_kind = .Keyword_union; | 911 | container_kind = .Keyword_union; |
| 912 | } else if (ZigClangRecordDecl_isStruct(record_decl)) { | 912 | } else if (record_decl.isStruct()) { |
| 913 | container_kind_name = "struct"; | 913 | container_kind_name = "struct"; |
| 914 | container_kind = .Keyword_struct; | 914 | container_kind = .Keyword_struct; |
| 915 | } else { | 915 | } else { |
| ... | @@ -918,7 +918,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -918,7 +918,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 918 | } | 918 | } |
| 919 | 919 | ||
| 920 | const name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ container_kind_name, bare_name }); | 920 | const name = try std.fmt.allocPrint(c.arena, "{}_{}", .{ container_kind_name, bare_name }); |
| 921 | _ = try c.decl_table.put(@ptrToInt(ZigClangRecordDecl_getCanonicalDecl(record_decl)), name); | 921 | _ = try c.decl_table.put(@ptrToInt(record_decl.getCanonicalDecl()), name); |
| 922 | 922 | ||
| 923 | const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null; | 923 | const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null; |
| 924 | const mut_tok = try appendToken(c, .Keyword_const, "const"); | 924 | const mut_tok = try appendToken(c, .Keyword_const, "const"); |
| ... | @@ -929,13 +929,13 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -929,13 +929,13 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 929 | var semicolon: ast.TokenIndex = undefined; | 929 | var semicolon: ast.TokenIndex = undefined; |
| 930 | const init_node = blk: { | 930 | const init_node = blk: { |
| 931 | const rp = makeRestorePoint(c); | 931 | const rp = makeRestorePoint(c); |
| 932 | const record_def = ZigClangRecordDecl_getDefinition(record_decl) orelse { | 932 | const record_def = record_decl.getDefinition() orelse { |
| 933 | const opaque = try transCreateNodeOpaqueType(c); | 933 | const opaque_type = try transCreateNodeOpaqueType(c); |
| 934 | semicolon = try appendToken(c, .Semicolon, ";"); | 934 | semicolon = try appendToken(c, .Semicolon, ";"); |
| 935 | break :blk opaque; | 935 | break :blk opaque_type; |
| 936 | }; | 936 | }; |
| 937 | 937 | ||
| 938 | const layout_tok = try if (ZigClangRecordDecl_getPackedAttribute(record_decl)) | 938 | const layout_tok = try if (record_decl.getPackedAttribute()) |
| 939 | appendToken(c, .Keyword_packed, "packed") | 939 | appendToken(c, .Keyword_packed, "packed") |
| 940 | else | 940 | else |
| 941 | appendToken(c, .Keyword_extern, "extern"); | 941 | appendToken(c, .Keyword_extern, "extern"); |
| ... | @@ -946,30 +946,30 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -946,30 +946,30 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 946 | defer fields_and_decls.deinit(); | 946 | defer fields_and_decls.deinit(); |
| 947 | 947 | ||
| 948 | var unnamed_field_count: u32 = 0; | 948 | var unnamed_field_count: u32 = 0; |
| 949 | var it = ZigClangRecordDecl_field_begin(record_def); | 949 | var it = record_def.field_begin(); |
| 950 | const end_it = ZigClangRecordDecl_field_end(record_def); | 950 | const end_it = record_def.field_end(); |
| 951 | while (ZigClangRecordDecl_field_iterator_neq(it, end_it)) : (it = ZigClangRecordDecl_field_iterator_next(it)) { | 951 | while (it.neq(end_it)) : (it = it.next()) { |
| 952 | const field_decl = ZigClangRecordDecl_field_iterator_deref(it); | 952 | const field_decl = it.deref(); |
| 953 | const field_loc = ZigClangFieldDecl_getLocation(field_decl); | 953 | const field_loc = field_decl.getLocation(); |
| 954 | const field_qt = ZigClangFieldDecl_getType(field_decl); | 954 | const field_qt = field_decl.getType(); |
| 955 | 955 | ||
| 956 | if (ZigClangFieldDecl_isBitField(field_decl)) { | 956 | if (field_decl.isBitField()) { |
| 957 | const opaque = try transCreateNodeOpaqueType(c); | 957 | const opaque_type = try transCreateNodeOpaqueType(c); |
| 958 | semicolon = try appendToken(c, .Semicolon, ";"); | 958 | semicolon = try appendToken(c, .Semicolon, ";"); |
| 959 | try emitWarning(c, field_loc, "{} demoted to opaque type - has bitfield", .{container_kind_name}); | 959 | try emitWarning(c, field_loc, "{} demoted to opaque type - has bitfield", .{container_kind_name}); |
| 960 | break :blk opaque; | 960 | break :blk opaque_type; |
| 961 | } | 961 | } |
| 962 | 962 | ||
| 963 | if (ZigClangType_isIncompleteOrZeroLengthArrayType(qualTypeCanon(field_qt), c.clang_context)) { | 963 | if (qualTypeCanon(field_qt).isIncompleteOrZeroLengthArrayType(c.clang_context)) { |
| 964 | const opaque = try transCreateNodeOpaqueType(c); | 964 | const opaque_type = try transCreateNodeOpaqueType(c); |
| 965 | semicolon = try appendToken(c, .Semicolon, ";"); | 965 | semicolon = try appendToken(c, .Semicolon, ";"); |
| 966 | try emitWarning(c, field_loc, "{} demoted to opaque type - has variable length array", .{container_kind_name}); | 966 | try emitWarning(c, field_loc, "{} demoted to opaque type - has variable length array", .{container_kind_name}); |
| 967 | break :blk opaque; | 967 | break :blk opaque_type; |
| 968 | } | 968 | } |
| 969 | 969 | ||
| 970 | var is_anon = false; | 970 | var is_anon = false; |
| 971 | var raw_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl))); | 971 | var raw_name = try c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin()); |
| 972 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl) or raw_name.len == 0) { | 972 | if (field_decl.isAnonymousStructOrUnion() or raw_name.len == 0) { |
| 973 | // Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields. | 973 | // Context.getMangle() is not used here because doing so causes unpredictable field names for anonymous fields. |
| 974 | raw_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{unnamed_field_count}); | 974 | raw_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{unnamed_field_count}); |
| 975 | unnamed_field_count += 1; | 975 | unnamed_field_count += 1; |
| ... | @@ -979,16 +979,16 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -979,16 +979,16 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 979 | _ = try appendToken(c, .Colon, ":"); | 979 | _ = try appendToken(c, .Colon, ":"); |
| 980 | const field_type = transQualType(rp, field_qt, field_loc) catch |err| switch (err) { | 980 | const field_type = transQualType(rp, field_qt, field_loc) catch |err| switch (err) { |
| 981 | error.UnsupportedType => { | 981 | error.UnsupportedType => { |
| 982 | const opaque = try transCreateNodeOpaqueType(c); | 982 | const opaque_type = try transCreateNodeOpaqueType(c); |
| 983 | semicolon = try appendToken(c, .Semicolon, ";"); | 983 | semicolon = try appendToken(c, .Semicolon, ";"); |
| 984 | try emitWarning(c, record_loc, "{} demoted to opaque type - unable to translate type of field {}", .{ container_kind_name, raw_name }); | 984 | try emitWarning(c, record_loc, "{} demoted to opaque type - unable to translate type of field {}", .{ container_kind_name, raw_name }); |
| 985 | break :blk opaque; | 985 | break :blk opaque_type; |
| 986 | }, | 986 | }, |
| 987 | else => |e| return e, | 987 | else => |e| return e, |
| 988 | }; | 988 | }; |
| 989 | 989 | ||
| 990 | const align_expr = blk_2: { | 990 | const align_expr = blk_2: { |
| 991 | const alignment = ZigClangFieldDecl_getAlignedAttribute(field_decl, rp.c.clang_context); | 991 | const alignment = field_decl.getAlignedAttribute(rp.c.clang_context); |
| 992 | if (alignment != 0) { | 992 | if (alignment != 0) { |
| 993 | _ = try appendToken(rp.c, .Keyword_align, "align"); | 993 | _ = try appendToken(rp.c, .Keyword_align, "align"); |
| 994 | _ = try appendToken(rp.c, .LParen, "("); | 994 | _ = try appendToken(rp.c, .LParen, "("); |
| ... | @@ -1013,7 +1013,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -1013,7 +1013,7 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 1013 | 1013 | ||
| 1014 | if (is_anon) { | 1014 | if (is_anon) { |
| 1015 | _ = try c.decl_table.put( | 1015 | _ = try c.decl_table.put( |
| 1016 | @ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl)), | 1016 | @ptrToInt(field_decl.getCanonicalDecl()), |
| 1017 | raw_name, | 1017 | raw_name, |
| 1018 | ); | 1018 | ); |
| 1019 | } | 1019 | } |
| ... | @@ -1051,13 +1051,13 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* | ... | @@ -1051,13 +1051,13 @@ fn transRecordDecl(c: *Context, record_decl: *const ZigClangRecordDecl) Error!?* |
| 1051 | return transCreateNodeIdentifier(c, name); | 1051 | return transCreateNodeIdentifier(c, name); |
| 1052 | } | 1052 | } |
| 1053 | 1053 | ||
| 1054 | fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.Node { | 1054 | fn transEnumDecl(c: *Context, enum_decl: *const clang.EnumDecl) Error!?*ast.Node { |
| 1055 | if (c.decl_table.get(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)))) |name| | 1055 | if (c.decl_table.get(@ptrToInt(enum_decl.getCanonicalDecl()))) |name| |
| 1056 | return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice | 1056 | return try transCreateNodeIdentifier(c, name); // Avoid processing this decl twice |
| 1057 | const rp = makeRestorePoint(c); | 1057 | const rp = makeRestorePoint(c); |
| 1058 | const enum_loc = ZigClangEnumDecl_getLocation(enum_decl); | 1058 | const enum_loc = enum_decl.getLocation(); |
| 1059 | 1059 | ||
| 1060 | var bare_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, enum_decl))); | 1060 | var bare_name = try c.str(@ptrCast(*const clang.NamedDecl, enum_decl).getName_bytes_begin()); |
| 1061 | var is_unnamed = false; | 1061 | var is_unnamed = false; |
| 1062 | if (bare_name.len == 0) { | 1062 | if (bare_name.len == 0) { |
| 1063 | bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{c.getMangle()}); | 1063 | bare_name = try std.fmt.allocPrint(c.arena, "unnamed_{}", .{c.getMangle()}); |
| ... | @@ -1065,20 +1065,20 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No | ... | @@ -1065,20 +1065,20 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 1065 | } | 1065 | } |
| 1066 | 1066 | ||
| 1067 | const name = try std.fmt.allocPrint(c.arena, "enum_{}", .{bare_name}); | 1067 | const name = try std.fmt.allocPrint(c.arena, "enum_{}", .{bare_name}); |
| 1068 | _ = try c.decl_table.put(@ptrToInt(ZigClangEnumDecl_getCanonicalDecl(enum_decl)), name); | 1068 | _ = try c.decl_table.put(@ptrToInt(enum_decl.getCanonicalDecl()), name); |
| 1069 | 1069 | ||
| 1070 | const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null; | 1070 | const visib_tok = if (!is_unnamed) try appendToken(c, .Keyword_pub, "pub") else null; |
| 1071 | const mut_tok = try appendToken(c, .Keyword_const, "const"); | 1071 | const mut_tok = try appendToken(c, .Keyword_const, "const"); |
| 1072 | const name_tok = try appendIdentifier(c, name); | 1072 | const name_tok = try appendIdentifier(c, name); |
| 1073 | const eq_token = try appendToken(c, .Equal, "="); | 1073 | const eq_token = try appendToken(c, .Equal, "="); |
| 1074 | 1074 | ||
| 1075 | const init_node = if (ZigClangEnumDecl_getDefinition(enum_decl)) |enum_def| blk: { | 1075 | const init_node = if (enum_decl.getDefinition()) |enum_def| blk: { |
| 1076 | var pure_enum = true; | 1076 | var pure_enum = true; |
| 1077 | var it = ZigClangEnumDecl_enumerator_begin(enum_def); | 1077 | var it = enum_def.enumerator_begin(); |
| 1078 | var end_it = ZigClangEnumDecl_enumerator_end(enum_def); | 1078 | var end_it = enum_def.enumerator_end(); |
| 1079 | while (ZigClangEnumDecl_enumerator_iterator_neq(it, end_it)) : (it = ZigClangEnumDecl_enumerator_iterator_next(it)) { | 1079 | while (it.neq(end_it)) : (it = it.next()) { |
| 1080 | const enum_const = ZigClangEnumDecl_enumerator_iterator_deref(it); | 1080 | const enum_const = it.deref(); |
| 1081 | if (ZigClangEnumConstantDecl_getInitExpr(enum_const)) |_| { | 1081 | if (enum_const.getInitExpr()) |_| { |
| 1082 | pure_enum = false; | 1082 | pure_enum = false; |
| 1083 | break; | 1083 | break; |
| 1084 | } | 1084 | } |
| ... | @@ -1090,7 +1090,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No | ... | @@ -1090,7 +1090,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 1090 | var fields_and_decls = std.ArrayList(*ast.Node).init(c.gpa); | 1090 | var fields_and_decls = std.ArrayList(*ast.Node).init(c.gpa); |
| 1091 | defer fields_and_decls.deinit(); | 1091 | defer fields_and_decls.deinit(); |
| 1092 | 1092 | ||
| 1093 | const int_type = ZigClangEnumDecl_getIntegerType(enum_decl); | 1093 | const int_type = enum_decl.getIntegerType(); |
| 1094 | // The underlying type may be null in case of forward-declared enum | 1094 | // The underlying type may be null in case of forward-declared enum |
| 1095 | // types, while that's not ISO-C compliant many compilers allow this and | 1095 | // types, while that's not ISO-C compliant many compilers allow this and |
| 1096 | // default to the usual integer type used for all the enums. | 1096 | // default to the usual integer type used for all the enums. |
| ... | @@ -1115,12 +1115,12 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No | ... | @@ -1115,12 +1115,12 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 1115 | 1115 | ||
| 1116 | const lbrace_token = try appendToken(c, .LBrace, "{"); | 1116 | const lbrace_token = try appendToken(c, .LBrace, "{"); |
| 1117 | 1117 | ||
| 1118 | it = ZigClangEnumDecl_enumerator_begin(enum_def); | 1118 | it = enum_def.enumerator_begin(); |
| 1119 | end_it = ZigClangEnumDecl_enumerator_end(enum_def); | 1119 | end_it = enum_def.enumerator_end(); |
| 1120 | while (ZigClangEnumDecl_enumerator_iterator_neq(it, end_it)) : (it = ZigClangEnumDecl_enumerator_iterator_next(it)) { | 1120 | while (it.neq(end_it)) : (it = it.next()) { |
| 1121 | const enum_const = ZigClangEnumDecl_enumerator_iterator_deref(it); | 1121 | const enum_const = it.deref(); |
| 1122 | 1122 | ||
| 1123 | const enum_val_name = try c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, enum_const))); | 1123 | const enum_val_name = try c.str(@ptrCast(*const clang.NamedDecl, enum_const).getName_bytes_begin()); |
| 1124 | 1124 | ||
| 1125 | const field_name = if (!is_unnamed and mem.startsWith(u8, enum_val_name, bare_name)) | 1125 | const field_name = if (!is_unnamed and mem.startsWith(u8, enum_val_name, bare_name)) |
| 1126 | enum_val_name[bare_name.len..] | 1126 | enum_val_name[bare_name.len..] |
| ... | @@ -1131,7 +1131,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No | ... | @@ -1131,7 +1131,7 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 1131 | 1131 | ||
| 1132 | const int_node = if (!pure_enum) blk_2: { | 1132 | const int_node = if (!pure_enum) blk_2: { |
| 1133 | _ = try appendToken(c, .Colon, "="); | 1133 | _ = try appendToken(c, .Colon, "="); |
| 1134 | break :blk_2 try transCreateNodeAPInt(c, ZigClangEnumConstantDecl_getInitVal(enum_const)); | 1134 | break :blk_2 try transCreateNodeAPInt(c, enum_const.getInitVal()); |
| 1135 | } else | 1135 | } else |
| 1136 | null; | 1136 | null; |
| 1137 | 1137 | ||
| ... | @@ -1257,23 +1257,23 @@ const LRValue = enum { | ... | @@ -1257,23 +1257,23 @@ const LRValue = enum { |
| 1257 | fn transStmt( | 1257 | fn transStmt( |
| 1258 | rp: RestorePoint, | 1258 | rp: RestorePoint, |
| 1259 | scope: *Scope, | 1259 | scope: *Scope, |
| 1260 | stmt: *const ZigClangStmt, | 1260 | stmt: *const clang.Stmt, |
| 1261 | result_used: ResultUsed, | 1261 | result_used: ResultUsed, |
| 1262 | lrvalue: LRValue, | 1262 | lrvalue: LRValue, |
| 1263 | ) TransError!*ast.Node { | 1263 | ) TransError!*ast.Node { |
| 1264 | const sc = ZigClangStmt_getStmtClass(stmt); | 1264 | const sc = stmt.getStmtClass(); |
| 1265 | switch (sc) { | 1265 | switch (sc) { |
| 1266 | .BinaryOperatorClass => return transBinaryOperator(rp, scope, @ptrCast(*const ZigClangBinaryOperator, stmt), result_used), | 1266 | .BinaryOperatorClass => return transBinaryOperator(rp, scope, @ptrCast(*const clang.BinaryOperator, stmt), result_used), |
| 1267 | .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const ZigClangCompoundStmt, stmt)), | 1267 | .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const clang.CompoundStmt, stmt)), |
| 1268 | .CStyleCastExprClass => return transCStyleCastExprClass(rp, scope, @ptrCast(*const ZigClangCStyleCastExpr, stmt), result_used, lrvalue), | 1268 | .CStyleCastExprClass => return transCStyleCastExprClass(rp, scope, @ptrCast(*const clang.CStyleCastExpr, stmt), result_used, lrvalue), |
| 1269 | .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const ZigClangDeclStmt, stmt)), | 1269 | .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const clang.DeclStmt, stmt)), |
| 1270 | .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const ZigClangDeclRefExpr, stmt), lrvalue), | 1270 | .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const clang.DeclRefExpr, stmt), lrvalue), |
| 1271 | .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const ZigClangImplicitCastExpr, stmt), result_used), | 1271 | .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const clang.ImplicitCastExpr, stmt), result_used), |
| 1272 | .IntegerLiteralClass => return transIntegerLiteral(rp, scope, @ptrCast(*const ZigClangIntegerLiteral, stmt), result_used, .with_as), | 1272 | .IntegerLiteralClass => return transIntegerLiteral(rp, scope, @ptrCast(*const clang.IntegerLiteral, stmt), result_used, .with_as), |
| 1273 | .ReturnStmtClass => return transReturnStmt(rp, scope, @ptrCast(*const ZigClangReturnStmt, stmt)), | 1273 | .ReturnStmtClass => return transReturnStmt(rp, scope, @ptrCast(*const clang.ReturnStmt, stmt)), |
| 1274 | .StringLiteralClass => return transStringLiteral(rp, scope, @ptrCast(*const ZigClangStringLiteral, stmt), result_used), | 1274 | .StringLiteralClass => return transStringLiteral(rp, scope, @ptrCast(*const clang.StringLiteral, stmt), result_used), |
| 1275 | .ParenExprClass => { | 1275 | .ParenExprClass => { |
| 1276 | const expr = try transExpr(rp, scope, ZigClangParenExpr_getSubExpr(@ptrCast(*const ZigClangParenExpr, stmt)), .used, lrvalue); | 1276 | const expr = try transExpr(rp, scope, @ptrCast(*const clang.ParenExpr, stmt).getSubExpr(), .used, lrvalue); |
| 1277 | if (expr.tag == .GroupedExpression) return maybeSuppressResult(rp, scope, result_used, expr); | 1277 | if (expr.tag == .GroupedExpression) return maybeSuppressResult(rp, scope, result_used, expr); |
| 1278 | const node = try rp.c.arena.create(ast.Node.GroupedExpression); | 1278 | const node = try rp.c.arena.create(ast.Node.GroupedExpression); |
| 1279 | node.* = .{ | 1279 | node.* = .{ |
| ... | @@ -1283,11 +1283,11 @@ fn transStmt( | ... | @@ -1283,11 +1283,11 @@ fn transStmt( |
| 1283 | }; | 1283 | }; |
| 1284 | return maybeSuppressResult(rp, scope, result_used, &node.base); | 1284 | return maybeSuppressResult(rp, scope, result_used, &node.base); |
| 1285 | }, | 1285 | }, |
| 1286 | .InitListExprClass => return transInitListExpr(rp, scope, @ptrCast(*const ZigClangInitListExpr, stmt), result_used), | 1286 | .InitListExprClass => return transInitListExpr(rp, scope, @ptrCast(*const clang.InitListExpr, stmt), result_used), |
| 1287 | .ImplicitValueInitExprClass => return transImplicitValueInitExpr(rp, scope, @ptrCast(*const ZigClangExpr, stmt), result_used), | 1287 | .ImplicitValueInitExprClass => return transImplicitValueInitExpr(rp, scope, @ptrCast(*const clang.Expr, stmt), result_used), |
| 1288 | .IfStmtClass => return transIfStmt(rp, scope, @ptrCast(*const ZigClangIfStmt, stmt)), | 1288 | .IfStmtClass => return transIfStmt(rp, scope, @ptrCast(*const clang.IfStmt, stmt)), |
| 1289 | .WhileStmtClass => return transWhileLoop(rp, scope, @ptrCast(*const ZigClangWhileStmt, stmt)), | 1289 | .WhileStmtClass => return transWhileLoop(rp, scope, @ptrCast(*const clang.WhileStmt, stmt)), |
| 1290 | .DoStmtClass => return transDoWhileLoop(rp, scope, @ptrCast(*const ZigClangDoStmt, stmt)), | 1290 | .DoStmtClass => return transDoWhileLoop(rp, scope, @ptrCast(*const clang.DoStmt, stmt)), |
| 1291 | .NullStmtClass => { | 1291 | .NullStmtClass => { |
| 1292 | const block = try rp.c.createBlock(0); | 1292 | const block = try rp.c.createBlock(0); |
| 1293 | block.rbrace = try appendToken(rp.c, .RBrace, "}"); | 1293 | block.rbrace = try appendToken(rp.c, .RBrace, "}"); |
| ... | @@ -1295,29 +1295,29 @@ fn transStmt( | ... | @@ -1295,29 +1295,29 @@ fn transStmt( |
| 1295 | }, | 1295 | }, |
| 1296 | .ContinueStmtClass => return try transCreateNodeContinue(rp.c), | 1296 | .ContinueStmtClass => return try transCreateNodeContinue(rp.c), |
| 1297 | .BreakStmtClass => return transBreak(rp, scope), | 1297 | .BreakStmtClass => return transBreak(rp, scope), |
| 1298 | .ForStmtClass => return transForLoop(rp, scope, @ptrCast(*const ZigClangForStmt, stmt)), | 1298 | .ForStmtClass => return transForLoop(rp, scope, @ptrCast(*const clang.ForStmt, stmt)), |
| 1299 | .FloatingLiteralClass => return transFloatingLiteral(rp, scope, @ptrCast(*const ZigClangFloatingLiteral, stmt), result_used), | 1299 | .FloatingLiteralClass => return transFloatingLiteral(rp, scope, @ptrCast(*const clang.FloatingLiteral, stmt), result_used), |
| 1300 | .ConditionalOperatorClass => { | 1300 | .ConditionalOperatorClass => { |
| 1301 | return transConditionalOperator(rp, scope, @ptrCast(*const ZigClangConditionalOperator, stmt), result_used); | 1301 | return transConditionalOperator(rp, scope, @ptrCast(*const clang.ConditionalOperator, stmt), result_used); |
| 1302 | }, | 1302 | }, |
| 1303 | .BinaryConditionalOperatorClass => { | 1303 | .BinaryConditionalOperatorClass => { |
| 1304 | return transBinaryConditionalOperator(rp, scope, @ptrCast(*const ZigClangBinaryConditionalOperator, stmt), result_used); | 1304 | return transBinaryConditionalOperator(rp, scope, @ptrCast(*const clang.BinaryConditionalOperator, stmt), result_used); |
| 1305 | }, | 1305 | }, |
| 1306 | .SwitchStmtClass => return transSwitch(rp, scope, @ptrCast(*const ZigClangSwitchStmt, stmt)), | 1306 | .SwitchStmtClass => return transSwitch(rp, scope, @ptrCast(*const clang.SwitchStmt, stmt)), |
| 1307 | .CaseStmtClass => return transCase(rp, scope, @ptrCast(*const ZigClangCaseStmt, stmt)), | 1307 | .CaseStmtClass => return transCase(rp, scope, @ptrCast(*const clang.CaseStmt, stmt)), |
| 1308 | .DefaultStmtClass => return transDefault(rp, scope, @ptrCast(*const ZigClangDefaultStmt, stmt)), | 1308 | .DefaultStmtClass => return transDefault(rp, scope, @ptrCast(*const clang.DefaultStmt, stmt)), |
| 1309 | .ConstantExprClass => return transConstantExpr(rp, scope, @ptrCast(*const ZigClangExpr, stmt), result_used), | 1309 | .ConstantExprClass => return transConstantExpr(rp, scope, @ptrCast(*const clang.Expr, stmt), result_used), |
| 1310 | .PredefinedExprClass => return transPredefinedExpr(rp, scope, @ptrCast(*const ZigClangPredefinedExpr, stmt), result_used), | 1310 | .PredefinedExprClass => return transPredefinedExpr(rp, scope, @ptrCast(*const clang.PredefinedExpr, stmt), result_used), |
| 1311 | .CharacterLiteralClass => return transCharLiteral(rp, scope, @ptrCast(*const ZigClangCharacterLiteral, stmt), result_used, .with_as), | 1311 | .CharacterLiteralClass => return transCharLiteral(rp, scope, @ptrCast(*const clang.CharacterLiteral, stmt), result_used, .with_as), |
| 1312 | .StmtExprClass => return transStmtExpr(rp, scope, @ptrCast(*const ZigClangStmtExpr, stmt), result_used), | 1312 | .StmtExprClass => return transStmtExpr(rp, scope, @ptrCast(*const clang.StmtExpr, stmt), result_used), |
| 1313 | .MemberExprClass => return transMemberExpr(rp, scope, @ptrCast(*const ZigClangMemberExpr, stmt), result_used), | 1313 | .MemberExprClass => return transMemberExpr(rp, scope, @ptrCast(*const clang.MemberExpr, stmt), result_used), |
| 1314 | .ArraySubscriptExprClass => return transArrayAccess(rp, scope, @ptrCast(*const ZigClangArraySubscriptExpr, stmt), result_used), | 1314 | .ArraySubscriptExprClass => return transArrayAccess(rp, scope, @ptrCast(*const clang.ArraySubscriptExpr, stmt), result_used), |
| 1315 | .CallExprClass => return transCallExpr(rp, scope, @ptrCast(*const ZigClangCallExpr, stmt), result_used), | 1315 | .CallExprClass => return transCallExpr(rp, scope, @ptrCast(*const clang.CallExpr, stmt), result_used), |
| 1316 | .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(rp, scope, @ptrCast(*const ZigClangUnaryExprOrTypeTraitExpr, stmt), result_used), | 1316 | .UnaryExprOrTypeTraitExprClass => return transUnaryExprOrTypeTraitExpr(rp, scope, @ptrCast(*const clang.UnaryExprOrTypeTraitExpr, stmt), result_used), |
| 1317 | .UnaryOperatorClass => return transUnaryOperator(rp, scope, @ptrCast(*const ZigClangUnaryOperator, stmt), result_used), | 1317 | .UnaryOperatorClass => return transUnaryOperator(rp, scope, @ptrCast(*const clang.UnaryOperator, stmt), result_used), |
| 1318 | .CompoundAssignOperatorClass => return transCompoundAssignOperator(rp, scope, @ptrCast(*const ZigClangCompoundAssignOperator, stmt), result_used), | 1318 | .CompoundAssignOperatorClass => return transCompoundAssignOperator(rp, scope, @ptrCast(*const clang.CompoundAssignOperator, stmt), result_used), |
| 1319 | .OpaqueValueExprClass => { | 1319 | .OpaqueValueExprClass => { |
| 1320 | const source_expr = ZigClangOpaqueValueExpr_getSourceExpr(@ptrCast(*const ZigClangOpaqueValueExpr, stmt)).?; | 1320 | const source_expr = @ptrCast(*const clang.OpaqueValueExpr, stmt).getSourceExpr().?; |
| 1321 | const expr = try transExpr(rp, scope, source_expr, .used, lrvalue); | 1321 | const expr = try transExpr(rp, scope, source_expr, .used, lrvalue); |
| 1322 | if (expr.tag == .GroupedExpression) return maybeSuppressResult(rp, scope, result_used, expr); | 1322 | if (expr.tag == .GroupedExpression) return maybeSuppressResult(rp, scope, result_used, expr); |
| 1323 | const node = try rp.c.arena.create(ast.Node.GroupedExpression); | 1323 | const node = try rp.c.arena.create(ast.Node.GroupedExpression); |
| ... | @@ -1332,7 +1332,7 @@ fn transStmt( | ... | @@ -1332,7 +1332,7 @@ fn transStmt( |
| 1332 | return revertAndWarn( | 1332 | return revertAndWarn( |
| 1333 | rp, | 1333 | rp, |
| 1334 | error.UnsupportedTranslation, | 1334 | error.UnsupportedTranslation, |
| 1335 | ZigClangStmt_getBeginLoc(stmt), | 1335 | stmt.getBeginLoc(), |
| 1336 | "TODO implement translation of stmt class {}", | 1336 | "TODO implement translation of stmt class {}", |
| 1337 | .{@tagName(sc)}, | 1337 | .{@tagName(sc)}, |
| 1338 | ); | 1338 | ); |
| ... | @@ -1343,24 +1343,24 @@ fn transStmt( | ... | @@ -1343,24 +1343,24 @@ fn transStmt( |
| 1343 | fn transBinaryOperator( | 1343 | fn transBinaryOperator( |
| 1344 | rp: RestorePoint, | 1344 | rp: RestorePoint, |
| 1345 | scope: *Scope, | 1345 | scope: *Scope, |
| 1346 | stmt: *const ZigClangBinaryOperator, | 1346 | stmt: *const clang.BinaryOperator, |
| 1347 | result_used: ResultUsed, | 1347 | result_used: ResultUsed, |
| 1348 | ) TransError!*ast.Node { | 1348 | ) TransError!*ast.Node { |
| 1349 | const op = ZigClangBinaryOperator_getOpcode(stmt); | 1349 | const op = stmt.getOpcode(); |
| 1350 | const qt = ZigClangBinaryOperator_getType(stmt); | 1350 | const qt = stmt.getType(); |
| 1351 | var op_token: ast.TokenIndex = undefined; | 1351 | var op_token: ast.TokenIndex = undefined; |
| 1352 | var op_id: ast.Node.Tag = undefined; | 1352 | var op_id: ast.Node.Tag = undefined; |
| 1353 | switch (op) { | 1353 | switch (op) { |
| 1354 | .Assign => return try transCreateNodeAssign(rp, scope, result_used, ZigClangBinaryOperator_getLHS(stmt), ZigClangBinaryOperator_getRHS(stmt)), | 1354 | .Assign => return try transCreateNodeAssign(rp, scope, result_used, stmt.getLHS(), stmt.getRHS()), |
| 1355 | .Comma => { | 1355 | .Comma => { |
| 1356 | const block_scope = try scope.findBlockScope(rp.c); | 1356 | const block_scope = try scope.findBlockScope(rp.c); |
| 1357 | const expr = block_scope.base.parent == scope; | 1357 | const expr = block_scope.base.parent == scope; |
| 1358 | const lparen = if (expr) try appendToken(rp.c, .LParen, "(") else undefined; | 1358 | const lparen = if (expr) try appendToken(rp.c, .LParen, "(") else undefined; |
| 1359 | 1359 | ||
| 1360 | const lhs = try transExpr(rp, &block_scope.base, ZigClangBinaryOperator_getLHS(stmt), .unused, .r_value); | 1360 | const lhs = try transExpr(rp, &block_scope.base, stmt.getLHS(), .unused, .r_value); |
| 1361 | try block_scope.statements.append(lhs); | 1361 | try block_scope.statements.append(lhs); |
| 1362 | 1362 | ||
| 1363 | const rhs = try transExpr(rp, &block_scope.base, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); | 1363 | const rhs = try transExpr(rp, &block_scope.base, stmt.getRHS(), .used, .r_value); |
| 1364 | if (expr) { | 1364 | if (expr) { |
| 1365 | _ = try appendToken(rp.c, .Semicolon, ";"); | 1365 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 1366 | const break_node = try transCreateNodeBreak(rp.c, block_scope.label, rhs); | 1366 | const break_node = try transCreateNodeBreak(rp.c, block_scope.label, rhs); |
| ... | @@ -1382,9 +1382,9 @@ fn transBinaryOperator( | ... | @@ -1382,9 +1382,9 @@ fn transBinaryOperator( |
| 1382 | if (cIsSignedInteger(qt)) { | 1382 | if (cIsSignedInteger(qt)) { |
| 1383 | // signed integer division uses @divTrunc | 1383 | // signed integer division uses @divTrunc |
| 1384 | const div_trunc_node = try rp.c.createBuiltinCall("@divTrunc", 2); | 1384 | const div_trunc_node = try rp.c.createBuiltinCall("@divTrunc", 2); |
| 1385 | div_trunc_node.params()[0] = try transExpr(rp, scope, ZigClangBinaryOperator_getLHS(stmt), .used, .l_value); | 1385 | div_trunc_node.params()[0] = try transExpr(rp, scope, stmt.getLHS(), .used, .l_value); |
| 1386 | _ = try appendToken(rp.c, .Comma, ","); | 1386 | _ = try appendToken(rp.c, .Comma, ","); |
| 1387 | const rhs = try transExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); | 1387 | const rhs = try transExpr(rp, scope, stmt.getRHS(), .used, .r_value); |
| 1388 | div_trunc_node.params()[1] = rhs; | 1388 | div_trunc_node.params()[1] = rhs; |
| 1389 | div_trunc_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 1389 | div_trunc_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 1390 | return maybeSuppressResult(rp, scope, result_used, &div_trunc_node.base); | 1390 | return maybeSuppressResult(rp, scope, result_used, &div_trunc_node.base); |
| ... | @@ -1394,9 +1394,9 @@ fn transBinaryOperator( | ... | @@ -1394,9 +1394,9 @@ fn transBinaryOperator( |
| 1394 | if (cIsSignedInteger(qt)) { | 1394 | if (cIsSignedInteger(qt)) { |
| 1395 | // signed integer division uses @rem | 1395 | // signed integer division uses @rem |
| 1396 | const rem_node = try rp.c.createBuiltinCall("@rem", 2); | 1396 | const rem_node = try rp.c.createBuiltinCall("@rem", 2); |
| 1397 | rem_node.params()[0] = try transExpr(rp, scope, ZigClangBinaryOperator_getLHS(stmt), .used, .l_value); | 1397 | rem_node.params()[0] = try transExpr(rp, scope, stmt.getLHS(), .used, .l_value); |
| 1398 | _ = try appendToken(rp.c, .Comma, ","); | 1398 | _ = try appendToken(rp.c, .Comma, ","); |
| 1399 | const rhs = try transExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); | 1399 | const rhs = try transExpr(rp, scope, stmt.getRHS(), .used, .r_value); |
| 1400 | rem_node.params()[1] = rhs; | 1400 | rem_node.params()[1] = rhs; |
| 1401 | rem_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 1401 | rem_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 1402 | return maybeSuppressResult(rp, scope, result_used, &rem_node.base); | 1402 | return maybeSuppressResult(rp, scope, result_used, &rem_node.base); |
| ... | @@ -1420,7 +1420,7 @@ fn transBinaryOperator( | ... | @@ -1420,7 +1420,7 @@ fn transBinaryOperator( |
| 1420 | }, | 1420 | }, |
| 1421 | else => {}, | 1421 | else => {}, |
| 1422 | } | 1422 | } |
| 1423 | const lhs_node = try transExpr(rp, scope, ZigClangBinaryOperator_getLHS(stmt), .used, .l_value); | 1423 | const lhs_node = try transExpr(rp, scope, stmt.getLHS(), .used, .l_value); |
| 1424 | switch (op) { | 1424 | switch (op) { |
| 1425 | .Add => { | 1425 | .Add => { |
| 1426 | if (cIsUnsignedInteger(qt)) { | 1426 | if (cIsUnsignedInteger(qt)) { |
| ... | @@ -1498,7 +1498,7 @@ fn transBinaryOperator( | ... | @@ -1498,7 +1498,7 @@ fn transBinaryOperator( |
| 1498 | else => unreachable, | 1498 | else => unreachable, |
| 1499 | } | 1499 | } |
| 1500 | 1500 | ||
| 1501 | const rhs_node = try transExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value); | 1501 | const rhs_node = try transExpr(rp, scope, stmt.getRHS(), .used, .r_value); |
| 1502 | 1502 | ||
| 1503 | const lhs = if (isBoolRes(lhs_node)) init: { | 1503 | const lhs = if (isBoolRes(lhs_node)) init: { |
| 1504 | const cast_node = try rp.c.createBuiltinCall("@boolToInt", 1); | 1504 | const cast_node = try rp.c.createBuiltinCall("@boolToInt", 1); |
| ... | @@ -1520,18 +1520,18 @@ fn transBinaryOperator( | ... | @@ -1520,18 +1520,18 @@ fn transBinaryOperator( |
| 1520 | fn transCompoundStmtInline( | 1520 | fn transCompoundStmtInline( |
| 1521 | rp: RestorePoint, | 1521 | rp: RestorePoint, |
| 1522 | parent_scope: *Scope, | 1522 | parent_scope: *Scope, |
| 1523 | stmt: *const ZigClangCompoundStmt, | 1523 | stmt: *const clang.CompoundStmt, |
| 1524 | block: *Scope.Block, | 1524 | block: *Scope.Block, |
| 1525 | ) TransError!void { | 1525 | ) TransError!void { |
| 1526 | var it = ZigClangCompoundStmt_body_begin(stmt); | 1526 | var it = stmt.body_begin(); |
| 1527 | const end_it = ZigClangCompoundStmt_body_end(stmt); | 1527 | const end_it = stmt.body_end(); |
| 1528 | while (it != end_it) : (it += 1) { | 1528 | while (it != end_it) : (it += 1) { |
| 1529 | const result = try transStmt(rp, parent_scope, it[0], .unused, .r_value); | 1529 | const result = try transStmt(rp, parent_scope, it[0], .unused, .r_value); |
| 1530 | try block.statements.append(result); | 1530 | try block.statements.append(result); |
| 1531 | } | 1531 | } |
| 1532 | } | 1532 | } |
| 1533 | 1533 | ||
| 1534 | fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompoundStmt) TransError!*ast.Node { | 1534 | fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const clang.CompoundStmt) TransError!*ast.Node { |
| 1535 | var block_scope = try Scope.Block.init(rp.c, scope, false); | 1535 | var block_scope = try Scope.Block.init(rp.c, scope, false); |
| 1536 | defer block_scope.deinit(); | 1536 | defer block_scope.deinit(); |
| 1537 | try transCompoundStmtInline(rp, &block_scope.base, stmt, &block_scope); | 1537 | try transCompoundStmtInline(rp, &block_scope.base, stmt, &block_scope); |
| ... | @@ -1541,17 +1541,17 @@ fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompo | ... | @@ -1541,17 +1541,17 @@ fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompo |
| 1541 | fn transCStyleCastExprClass( | 1541 | fn transCStyleCastExprClass( |
| 1542 | rp: RestorePoint, | 1542 | rp: RestorePoint, |
| 1543 | scope: *Scope, | 1543 | scope: *Scope, |
| 1544 | stmt: *const ZigClangCStyleCastExpr, | 1544 | stmt: *const clang.CStyleCastExpr, |
| 1545 | result_used: ResultUsed, | 1545 | result_used: ResultUsed, |
| 1546 | lrvalue: LRValue, | 1546 | lrvalue: LRValue, |
| 1547 | ) TransError!*ast.Node { | 1547 | ) TransError!*ast.Node { |
| 1548 | const sub_expr = ZigClangCStyleCastExpr_getSubExpr(stmt); | 1548 | const sub_expr = stmt.getSubExpr(); |
| 1549 | const cast_node = (try transCCast( | 1549 | const cast_node = (try transCCast( |
| 1550 | rp, | 1550 | rp, |
| 1551 | scope, | 1551 | scope, |
| 1552 | ZigClangCStyleCastExpr_getBeginLoc(stmt), | 1552 | stmt.getBeginLoc(), |
| 1553 | ZigClangCStyleCastExpr_getType(stmt), | 1553 | stmt.getType(), |
| 1554 | ZigClangExpr_getType(sub_expr), | 1554 | sub_expr.getType(), |
| 1555 | try transExpr(rp, scope, sub_expr, .used, lrvalue), | 1555 | try transExpr(rp, scope, sub_expr, .used, lrvalue), |
| 1556 | )); | 1556 | )); |
| 1557 | return maybeSuppressResult(rp, scope, result_used, cast_node); | 1557 | return maybeSuppressResult(rp, scope, result_used, cast_node); |
| ... | @@ -1560,22 +1560,20 @@ fn transCStyleCastExprClass( | ... | @@ -1560,22 +1560,20 @@ fn transCStyleCastExprClass( |
| 1560 | fn transDeclStmtOne( | 1560 | fn transDeclStmtOne( |
| 1561 | rp: RestorePoint, | 1561 | rp: RestorePoint, |
| 1562 | scope: *Scope, | 1562 | scope: *Scope, |
| 1563 | decl: *const ZigClangDecl, | 1563 | decl: *const clang.Decl, |
| 1564 | block_scope: *Scope.Block, | 1564 | block_scope: *Scope.Block, |
| 1565 | ) TransError!*ast.Node { | 1565 | ) TransError!*ast.Node { |
| 1566 | const c = rp.c; | 1566 | const c = rp.c; |
| 1567 | 1567 | ||
| 1568 | switch (ZigClangDecl_getKind(decl)) { | 1568 | switch (decl.getKind()) { |
| 1569 | .Var => { | 1569 | .Var => { |
| 1570 | const var_decl = @ptrCast(*const ZigClangVarDecl, decl); | 1570 | const var_decl = @ptrCast(*const clang.VarDecl, decl); |
| 1571 | 1571 | ||
| 1572 | const qual_type = ZigClangVarDecl_getTypeSourceInfo_getType(var_decl); | 1572 | const qual_type = var_decl.getTypeSourceInfo_getType(); |
| 1573 | const name = try c.str(ZigClangNamedDecl_getName_bytes_begin( | 1573 | const name = try c.str(@ptrCast(*const clang.NamedDecl, var_decl).getName_bytes_begin()); |
| 1574 | @ptrCast(*const ZigClangNamedDecl, var_decl), | ||
| 1575 | )); | ||
| 1576 | const mangled_name = try block_scope.makeMangledName(c, name); | 1574 | const mangled_name = try block_scope.makeMangledName(c, name); |
| 1577 | 1575 | ||
| 1578 | switch (ZigClangVarDecl_getStorageClass(var_decl)) { | 1576 | switch (var_decl.getStorageClass()) { |
| 1579 | .Extern, .Static => { | 1577 | .Extern, .Static => { |
| 1580 | // This is actually a global variable, put it in the global scope and reference it. | 1578 | // This is actually a global variable, put it in the global scope and reference it. |
| 1581 | // `_ = mangled_name;` | 1579 | // `_ = mangled_name;` |
| ... | @@ -1585,18 +1583,18 @@ fn transDeclStmtOne( | ... | @@ -1585,18 +1583,18 @@ fn transDeclStmtOne( |
| 1585 | else => {}, | 1583 | else => {}, |
| 1586 | } | 1584 | } |
| 1587 | 1585 | ||
| 1588 | const mut_tok = if (ZigClangQualType_isConstQualified(qual_type)) | 1586 | const mut_tok = if (qual_type.isConstQualified()) |
| 1589 | try appendToken(c, .Keyword_const, "const") | 1587 | try appendToken(c, .Keyword_const, "const") |
| 1590 | else | 1588 | else |
| 1591 | try appendToken(c, .Keyword_var, "var"); | 1589 | try appendToken(c, .Keyword_var, "var"); |
| 1592 | const name_tok = try appendIdentifier(c, mangled_name); | 1590 | const name_tok = try appendIdentifier(c, mangled_name); |
| 1593 | 1591 | ||
| 1594 | _ = try appendToken(c, .Colon, ":"); | 1592 | _ = try appendToken(c, .Colon, ":"); |
| 1595 | const loc = ZigClangDecl_getLocation(decl); | 1593 | const loc = decl.getLocation(); |
| 1596 | const type_node = try transQualType(rp, qual_type, loc); | 1594 | const type_node = try transQualType(rp, qual_type, loc); |
| 1597 | 1595 | ||
| 1598 | const eq_token = try appendToken(c, .Equal, "="); | 1596 | const eq_token = try appendToken(c, .Equal, "="); |
| 1599 | var init_node = if (ZigClangVarDecl_getInit(var_decl)) |expr| | 1597 | var init_node = if (var_decl.getInit()) |expr| |
| 1600 | try transExprCoercing(rp, scope, expr, .used, .r_value) | 1598 | try transExprCoercing(rp, scope, expr, .used, .r_value) |
| 1601 | else | 1599 | else |
| 1602 | try transCreateNodeUndefinedLiteral(c); | 1600 | try transCreateNodeUndefinedLiteral(c); |
| ... | @@ -1619,13 +1617,11 @@ fn transDeclStmtOne( | ... | @@ -1619,13 +1617,11 @@ fn transDeclStmtOne( |
| 1619 | return &node.base; | 1617 | return &node.base; |
| 1620 | }, | 1618 | }, |
| 1621 | .Typedef => { | 1619 | .Typedef => { |
| 1622 | const typedef_decl = @ptrCast(*const ZigClangTypedefNameDecl, decl); | 1620 | const typedef_decl = @ptrCast(*const clang.TypedefNameDecl, decl); |
| 1623 | const name = try c.str(ZigClangNamedDecl_getName_bytes_begin( | 1621 | const name = try c.str(@ptrCast(*const clang.NamedDecl, typedef_decl).getName_bytes_begin()); |
| 1624 | @ptrCast(*const ZigClangNamedDecl, typedef_decl), | ||
| 1625 | )); | ||
| 1626 | 1622 | ||
| 1627 | const underlying_qual = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); | 1623 | const underlying_qual = typedef_decl.getUnderlyingType(); |
| 1628 | const underlying_type = ZigClangQualType_getTypePtr(underlying_qual); | 1624 | const underlying_type = underlying_qual.getTypePtr(); |
| 1629 | 1625 | ||
| 1630 | const mangled_name = try block_scope.makeMangledName(c, name); | 1626 | const mangled_name = try block_scope.makeMangledName(c, name); |
| 1631 | const node = (try transCreateNodeTypedef(rp, typedef_decl, false, mangled_name)) orelse | 1627 | const node = (try transCreateNodeTypedef(rp, typedef_decl, false, mangled_name)) orelse |
| ... | @@ -1635,18 +1631,18 @@ fn transDeclStmtOne( | ... | @@ -1635,18 +1631,18 @@ fn transDeclStmtOne( |
| 1635 | else => |kind| return revertAndWarn( | 1631 | else => |kind| return revertAndWarn( |
| 1636 | rp, | 1632 | rp, |
| 1637 | error.UnsupportedTranslation, | 1633 | error.UnsupportedTranslation, |
| 1638 | ZigClangDecl_getLocation(decl), | 1634 | decl.getLocation(), |
| 1639 | "TODO implement translation of DeclStmt kind {}", | 1635 | "TODO implement translation of DeclStmt kind {}", |
| 1640 | .{@tagName(kind)}, | 1636 | .{@tagName(kind)}, |
| 1641 | ), | 1637 | ), |
| 1642 | } | 1638 | } |
| 1643 | } | 1639 | } |
| 1644 | 1640 | ||
| 1645 | fn transDeclStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangDeclStmt) TransError!*ast.Node { | 1641 | fn transDeclStmt(rp: RestorePoint, scope: *Scope, stmt: *const clang.DeclStmt) TransError!*ast.Node { |
| 1646 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; | 1642 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; |
| 1647 | 1643 | ||
| 1648 | var it = ZigClangDeclStmt_decl_begin(stmt); | 1644 | var it = stmt.decl_begin(); |
| 1649 | const end_it = ZigClangDeclStmt_decl_end(stmt); | 1645 | const end_it = stmt.decl_end(); |
| 1650 | assert(it != end_it); | 1646 | assert(it != end_it); |
| 1651 | while (true) : (it += 1) { | 1647 | while (true) : (it += 1) { |
| 1652 | const node = try transDeclStmtOne(rp, scope, it[0], block_scope); | 1648 | const node = try transDeclStmtOne(rp, scope, it[0], block_scope); |
| ... | @@ -1663,11 +1659,11 @@ fn transDeclStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangDeclStmt) | ... | @@ -1663,11 +1659,11 @@ fn transDeclStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangDeclStmt) |
| 1663 | fn transDeclRefExpr( | 1659 | fn transDeclRefExpr( |
| 1664 | rp: RestorePoint, | 1660 | rp: RestorePoint, |
| 1665 | scope: *Scope, | 1661 | scope: *Scope, |
| 1666 | expr: *const ZigClangDeclRefExpr, | 1662 | expr: *const clang.DeclRefExpr, |
| 1667 | lrvalue: LRValue, | 1663 | lrvalue: LRValue, |
| 1668 | ) TransError!*ast.Node { | 1664 | ) TransError!*ast.Node { |
| 1669 | const value_decl = ZigClangDeclRefExpr_getDecl(expr); | 1665 | const value_decl = expr.getDecl(); |
| 1670 | const name = try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, value_decl))); | 1666 | const name = try rp.c.str(@ptrCast(*const clang.NamedDecl, value_decl).getName_bytes_begin()); |
| 1671 | const mangled_name = scope.getAlias(name); | 1667 | const mangled_name = scope.getAlias(name); |
| 1672 | return transCreateNodeIdentifier(rp.c, mangled_name); | 1668 | return transCreateNodeIdentifier(rp.c, mangled_name); |
| 1673 | } | 1669 | } |
| ... | @@ -1675,17 +1671,17 @@ fn transDeclRefExpr( | ... | @@ -1675,17 +1671,17 @@ fn transDeclRefExpr( |
| 1675 | fn transImplicitCastExpr( | 1671 | fn transImplicitCastExpr( |
| 1676 | rp: RestorePoint, | 1672 | rp: RestorePoint, |
| 1677 | scope: *Scope, | 1673 | scope: *Scope, |
| 1678 | expr: *const ZigClangImplicitCastExpr, | 1674 | expr: *const clang.ImplicitCastExpr, |
| 1679 | result_used: ResultUsed, | 1675 | result_used: ResultUsed, |
| 1680 | ) TransError!*ast.Node { | 1676 | ) TransError!*ast.Node { |
| 1681 | const c = rp.c; | 1677 | const c = rp.c; |
| 1682 | const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr); | 1678 | const sub_expr = expr.getSubExpr(); |
| 1683 | const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr)); | 1679 | const dest_type = getExprQualType(c, @ptrCast(*const clang.Expr, expr)); |
| 1684 | const src_type = getExprQualType(c, sub_expr); | 1680 | const src_type = getExprQualType(c, sub_expr); |
| 1685 | switch (ZigClangImplicitCastExpr_getCastKind(expr)) { | 1681 | switch (expr.getCastKind()) { |
| 1686 | .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => { | 1682 | .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => { |
| 1687 | const sub_expr_node = try transExpr(rp, scope, sub_expr, .used, .r_value); | 1683 | const sub_expr_node = try transExpr(rp, scope, sub_expr, .used, .r_value); |
| 1688 | return try transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node); | 1684 | return try transCCast(rp, scope, expr.getBeginLoc(), dest_type, src_type, sub_expr_node); |
| 1689 | }, | 1685 | }, |
| 1690 | .LValueToRValue, .NoOp, .FunctionToPointerDecay => { | 1686 | .LValueToRValue, .NoOp, .FunctionToPointerDecay => { |
| 1691 | const sub_expr_node = try transExpr(rp, scope, sub_expr, .used, .r_value); | 1687 | const sub_expr_node = try transExpr(rp, scope, sub_expr, .used, .r_value); |
| ... | @@ -1730,7 +1726,7 @@ fn transImplicitCastExpr( | ... | @@ -1730,7 +1726,7 @@ fn transImplicitCastExpr( |
| 1730 | else => |kind| return revertAndWarn( | 1726 | else => |kind| return revertAndWarn( |
| 1731 | rp, | 1727 | rp, |
| 1732 | error.UnsupportedTranslation, | 1728 | error.UnsupportedTranslation, |
| 1733 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, expr)), | 1729 | @ptrCast(*const clang.Stmt, expr).getBeginLoc(), |
| 1734 | "TODO implement translation of CastKind {}", | 1730 | "TODO implement translation of CastKind {}", |
| 1735 | .{@tagName(kind)}, | 1731 | .{@tagName(kind)}, |
| 1736 | ), | 1732 | ), |
| ... | @@ -1740,15 +1736,15 @@ fn transImplicitCastExpr( | ... | @@ -1740,15 +1736,15 @@ fn transImplicitCastExpr( |
| 1740 | fn transBoolExpr( | 1736 | fn transBoolExpr( |
| 1741 | rp: RestorePoint, | 1737 | rp: RestorePoint, |
| 1742 | scope: *Scope, | 1738 | scope: *Scope, |
| 1743 | expr: *const ZigClangExpr, | 1739 | expr: *const clang.Expr, |
| 1744 | used: ResultUsed, | 1740 | used: ResultUsed, |
| 1745 | lrvalue: LRValue, | 1741 | lrvalue: LRValue, |
| 1746 | grouped: bool, | 1742 | grouped: bool, |
| 1747 | ) TransError!*ast.Node { | 1743 | ) TransError!*ast.Node { |
| 1748 | if (ZigClangStmt_getStmtClass(@ptrCast(*const ZigClangStmt, expr)) == .IntegerLiteralClass) { | 1744 | if (@ptrCast(*const clang.Stmt, expr).getStmtClass() == .IntegerLiteralClass) { |
| 1749 | var is_zero: bool = undefined; | 1745 | var is_zero: bool = undefined; |
| 1750 | if (!ZigClangIntegerLiteral_isZero(@ptrCast(*const ZigClangIntegerLiteral, expr), &is_zero, rp.c.clang_context)) { | 1746 | if (!(@ptrCast(*const clang.IntegerLiteral, expr).isZero(&is_zero, rp.c.clang_context))) { |
| 1751 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(expr), "invalid integer literal", .{}); | 1747 | return revertAndWarn(rp, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid integer literal", .{}); |
| 1752 | } | 1748 | } |
| 1753 | return try transCreateNodeBoolLiteral(rp.c, !is_zero); | 1749 | return try transCreateNodeBoolLiteral(rp.c, !is_zero); |
| 1754 | } | 1750 | } |
| ... | @@ -1769,8 +1765,8 @@ fn transBoolExpr( | ... | @@ -1769,8 +1765,8 @@ fn transBoolExpr( |
| 1769 | return res; | 1765 | return res; |
| 1770 | } | 1766 | } |
| 1771 | 1767 | ||
| 1772 | const ty = ZigClangQualType_getTypePtr(getExprQualType(rp.c, expr)); | 1768 | const ty = getExprQualType(rp.c, expr).getTypePtr(); |
| 1773 | const node = try finishBoolExpr(rp, scope, ZigClangExpr_getBeginLoc(expr), ty, res, used); | 1769 | const node = try finishBoolExpr(rp, scope, expr.getBeginLoc(), ty, res, used); |
| 1774 | 1770 | ||
| 1775 | if (grouped) { | 1771 | if (grouped) { |
| 1776 | const rparen = try appendToken(rp.c, .RParen, ")"); | 1772 | const rparen = try appendToken(rp.c, .RParen, ")"); |
| ... | @@ -1786,16 +1782,16 @@ fn transBoolExpr( | ... | @@ -1786,16 +1782,16 @@ fn transBoolExpr( |
| 1786 | } | 1782 | } |
| 1787 | } | 1783 | } |
| 1788 | 1784 | ||
| 1789 | fn exprIsBooleanType(expr: *const ZigClangExpr) bool { | 1785 | fn exprIsBooleanType(expr: *const clang.Expr) bool { |
| 1790 | return qualTypeIsBoolean(ZigClangExpr_getType(expr)); | 1786 | return qualTypeIsBoolean(expr.getType()); |
| 1791 | } | 1787 | } |
| 1792 | 1788 | ||
| 1793 | fn exprIsStringLiteral(expr: *const ZigClangExpr) bool { | 1789 | fn exprIsStringLiteral(expr: *const clang.Expr) bool { |
| 1794 | switch (ZigClangExpr_getStmtClass(expr)) { | 1790 | switch (expr.getStmtClass()) { |
| 1795 | .StringLiteralClass => return true, | 1791 | .StringLiteralClass => return true, |
| 1796 | .PredefinedExprClass => return true, | 1792 | .PredefinedExprClass => return true, |
| 1797 | .UnaryOperatorClass => { | 1793 | .UnaryOperatorClass => { |
| 1798 | const op_expr = ZigClangUnaryOperator_getSubExpr(@ptrCast(*const ZigClangUnaryOperator, expr)); | 1794 | const op_expr = @ptrCast(*const clang.UnaryOperator, expr).getSubExpr(); |
| 1799 | return exprIsStringLiteral(op_expr); | 1795 | return exprIsStringLiteral(op_expr); |
| 1800 | }, | 1796 | }, |
| 1801 | else => return false, | 1797 | else => return false, |
| ... | @@ -1825,16 +1821,16 @@ fn isBoolRes(res: *ast.Node) bool { | ... | @@ -1825,16 +1821,16 @@ fn isBoolRes(res: *ast.Node) bool { |
| 1825 | fn finishBoolExpr( | 1821 | fn finishBoolExpr( |
| 1826 | rp: RestorePoint, | 1822 | rp: RestorePoint, |
| 1827 | scope: *Scope, | 1823 | scope: *Scope, |
| 1828 | loc: ZigClangSourceLocation, | 1824 | loc: clang.SourceLocation, |
| 1829 | ty: *const ZigClangType, | 1825 | ty: *const clang.Type, |
| 1830 | node: *ast.Node, | 1826 | node: *ast.Node, |
| 1831 | used: ResultUsed, | 1827 | used: ResultUsed, |
| 1832 | ) TransError!*ast.Node { | 1828 | ) TransError!*ast.Node { |
| 1833 | switch (ZigClangType_getTypeClass(ty)) { | 1829 | switch (ty.getTypeClass()) { |
| 1834 | .Builtin => { | 1830 | .Builtin => { |
| 1835 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 1831 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 1836 | 1832 | ||
| 1837 | switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 1833 | switch (builtin_ty.getKind()) { |
| 1838 | .Bool => return node, | 1834 | .Bool => return node, |
| 1839 | .Char_U, | 1835 | .Char_U, |
| 1840 | .UChar, | 1836 | .UChar, |
| ... | @@ -1879,10 +1875,10 @@ fn finishBoolExpr( | ... | @@ -1879,10 +1875,10 @@ fn finishBoolExpr( |
| 1879 | return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, used, false); | 1875 | return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, used, false); |
| 1880 | }, | 1876 | }, |
| 1881 | .Typedef => { | 1877 | .Typedef => { |
| 1882 | const typedef_ty = @ptrCast(*const ZigClangTypedefType, ty); | 1878 | const typedef_ty = @ptrCast(*const clang.TypedefType, ty); |
| 1883 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 1879 | const typedef_decl = typedef_ty.getDecl(); |
| 1884 | const underlying_type = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); | 1880 | const underlying_type = typedef_decl.getUnderlyingType(); |
| 1885 | return finishBoolExpr(rp, scope, loc, ZigClangQualType_getTypePtr(underlying_type), node, used); | 1881 | return finishBoolExpr(rp, scope, loc, underlying_type.getTypePtr(), node, used); |
| 1886 | }, | 1882 | }, |
| 1887 | .Enum => { | 1883 | .Enum => { |
| 1888 | const op_token = try appendToken(rp.c, .BangEqual, "!="); | 1884 | const op_token = try appendToken(rp.c, .BangEqual, "!="); |
| ... | @@ -1890,9 +1886,9 @@ fn finishBoolExpr( | ... | @@ -1890,9 +1886,9 @@ fn finishBoolExpr( |
| 1890 | return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, used, false); | 1886 | return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, used, false); |
| 1891 | }, | 1887 | }, |
| 1892 | .Elaborated => { | 1888 | .Elaborated => { |
| 1893 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ty); | 1889 | const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty); |
| 1894 | const named_type = ZigClangElaboratedType_getNamedType(elaborated_ty); | 1890 | const named_type = elaborated_ty.getNamedType(); |
| 1895 | return finishBoolExpr(rp, scope, loc, ZigClangQualType_getTypePtr(named_type), node, used); | 1891 | return finishBoolExpr(rp, scope, loc, named_type.getTypePtr(), node, used); |
| 1896 | }, | 1892 | }, |
| 1897 | else => {}, | 1893 | else => {}, |
| 1898 | } | 1894 | } |
| ... | @@ -1906,18 +1902,18 @@ const SuppressCast = enum { | ... | @@ -1906,18 +1902,18 @@ const SuppressCast = enum { |
| 1906 | fn transIntegerLiteral( | 1902 | fn transIntegerLiteral( |
| 1907 | rp: RestorePoint, | 1903 | rp: RestorePoint, |
| 1908 | scope: *Scope, | 1904 | scope: *Scope, |
| 1909 | expr: *const ZigClangIntegerLiteral, | 1905 | expr: *const clang.IntegerLiteral, |
| 1910 | result_used: ResultUsed, | 1906 | result_used: ResultUsed, |
| 1911 | suppress_as: SuppressCast, | 1907 | suppress_as: SuppressCast, |
| 1912 | ) TransError!*ast.Node { | 1908 | ) TransError!*ast.Node { |
| 1913 | var eval_result: ZigClangExprEvalResult = undefined; | 1909 | var eval_result: clang.ExprEvalResult = undefined; |
| 1914 | if (!ZigClangIntegerLiteral_EvaluateAsInt(expr, &eval_result, rp.c.clang_context)) { | 1910 | if (!expr.EvaluateAsInt(&eval_result, rp.c.clang_context)) { |
| 1915 | const loc = ZigClangIntegerLiteral_getBeginLoc(expr); | 1911 | const loc = expr.getBeginLoc(); |
| 1916 | return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{}); | 1912 | return revertAndWarn(rp, error.UnsupportedTranslation, loc, "invalid integer literal", .{}); |
| 1917 | } | 1913 | } |
| 1918 | 1914 | ||
| 1919 | if (suppress_as == .no_as) { | 1915 | if (suppress_as == .no_as) { |
| 1920 | const int_lit_node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val)); | 1916 | const int_lit_node = try transCreateNodeAPInt(rp.c, eval_result.Val.getInt()); |
| 1921 | return maybeSuppressResult(rp, scope, result_used, int_lit_node); | 1917 | return maybeSuppressResult(rp, scope, result_used, int_lit_node); |
| 1922 | } | 1918 | } |
| 1923 | 1919 | ||
| ... | @@ -1932,12 +1928,12 @@ fn transIntegerLiteral( | ... | @@ -1932,12 +1928,12 @@ fn transIntegerLiteral( |
| 1932 | // But the first step is to be correct, and the next step is to make the output more elegant. | 1928 | // But the first step is to be correct, and the next step is to make the output more elegant. |
| 1933 | 1929 | ||
| 1934 | // @as(T, x) | 1930 | // @as(T, x) |
| 1935 | const expr_base = @ptrCast(*const ZigClangExpr, expr); | 1931 | const expr_base = @ptrCast(*const clang.Expr, expr); |
| 1936 | const as_node = try rp.c.createBuiltinCall("@as", 2); | 1932 | const as_node = try rp.c.createBuiltinCall("@as", 2); |
| 1937 | const ty_node = try transQualType(rp, ZigClangExpr_getType(expr_base), ZigClangExpr_getBeginLoc(expr_base)); | 1933 | const ty_node = try transQualType(rp, expr_base.getType(), expr_base.getBeginLoc()); |
| 1938 | as_node.params()[0] = ty_node; | 1934 | as_node.params()[0] = ty_node; |
| 1939 | _ = try appendToken(rp.c, .Comma, ","); | 1935 | _ = try appendToken(rp.c, .Comma, ","); |
| 1940 | as_node.params()[1] = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&eval_result.Val)); | 1936 | as_node.params()[1] = try transCreateNodeAPInt(rp.c, eval_result.Val.getInt()); |
| 1941 | 1937 | ||
| 1942 | as_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 1938 | as_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 1943 | return maybeSuppressResult(rp, scope, result_used, &as_node.base); | 1939 | return maybeSuppressResult(rp, scope, result_used, &as_node.base); |
| ... | @@ -1946,10 +1942,10 @@ fn transIntegerLiteral( | ... | @@ -1946,10 +1942,10 @@ fn transIntegerLiteral( |
| 1946 | fn transReturnStmt( | 1942 | fn transReturnStmt( |
| 1947 | rp: RestorePoint, | 1943 | rp: RestorePoint, |
| 1948 | scope: *Scope, | 1944 | scope: *Scope, |
| 1949 | expr: *const ZigClangReturnStmt, | 1945 | expr: *const clang.ReturnStmt, |
| 1950 | ) TransError!*ast.Node { | 1946 | ) TransError!*ast.Node { |
| 1951 | const return_kw = try appendToken(rp.c, .Keyword_return, "return"); | 1947 | const return_kw = try appendToken(rp.c, .Keyword_return, "return"); |
| 1952 | const rhs: ?*ast.Node = if (ZigClangReturnStmt_getRetValue(expr)) |val_expr| | 1948 | const rhs: ?*ast.Node = if (expr.getRetValue()) |val_expr| |
| 1953 | try transExprCoercing(rp, scope, val_expr, .used, .r_value) | 1949 | try transExprCoercing(rp, scope, val_expr, .used, .r_value) |
| 1954 | else | 1950 | else |
| 1955 | null; | 1951 | null; |
| ... | @@ -1966,14 +1962,14 @@ fn transReturnStmt( | ... | @@ -1966,14 +1962,14 @@ fn transReturnStmt( |
| 1966 | fn transStringLiteral( | 1962 | fn transStringLiteral( |
| 1967 | rp: RestorePoint, | 1963 | rp: RestorePoint, |
| 1968 | scope: *Scope, | 1964 | scope: *Scope, |
| 1969 | stmt: *const ZigClangStringLiteral, | 1965 | stmt: *const clang.StringLiteral, |
| 1970 | result_used: ResultUsed, | 1966 | result_used: ResultUsed, |
| 1971 | ) TransError!*ast.Node { | 1967 | ) TransError!*ast.Node { |
| 1972 | const kind = ZigClangStringLiteral_getKind(stmt); | 1968 | const kind = stmt.getKind(); |
| 1973 | switch (kind) { | 1969 | switch (kind) { |
| 1974 | .Ascii, .UTF8 => { | 1970 | .Ascii, .UTF8 => { |
| 1975 | var len: usize = undefined; | 1971 | var len: usize = undefined; |
| 1976 | const bytes_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &len); | 1972 | const bytes_ptr = stmt.getString_bytes_begin_size(&len); |
| 1977 | const str = bytes_ptr[0..len]; | 1973 | const str = bytes_ptr[0..len]; |
| 1978 | 1974 | ||
| 1979 | var char_buf: [4]u8 = undefined; | 1975 | var char_buf: [4]u8 = undefined; |
| ... | @@ -1996,7 +1992,7 @@ fn transStringLiteral( | ... | @@ -1996,7 +1992,7 @@ fn transStringLiteral( |
| 1996 | .UTF16, .UTF32, .Wide => return revertAndWarn( | 1992 | .UTF16, .UTF32, .Wide => return revertAndWarn( |
| 1997 | rp, | 1993 | rp, |
| 1998 | error.UnsupportedTranslation, | 1994 | error.UnsupportedTranslation, |
| 1999 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), | 1995 | @ptrCast(*const clang.Stmt, stmt).getBeginLoc(), |
| 2000 | "TODO: support string literal kind {}", | 1996 | "TODO: support string literal kind {}", |
| 2001 | .{kind}, | 1997 | .{kind}, |
| 2002 | ), | 1998 | ), |
| ... | @@ -2041,13 +2037,13 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 { | ... | @@ -2041,13 +2037,13 @@ fn escapeChar(c: u8, char_buf: *[4]u8) []const u8 { |
| 2041 | fn transCCast( | 2037 | fn transCCast( |
| 2042 | rp: RestorePoint, | 2038 | rp: RestorePoint, |
| 2043 | scope: *Scope, | 2039 | scope: *Scope, |
| 2044 | loc: ZigClangSourceLocation, | 2040 | loc: clang.SourceLocation, |
| 2045 | dst_type: ZigClangQualType, | 2041 | dst_type: clang.QualType, |
| 2046 | src_type: ZigClangQualType, | 2042 | src_type: clang.QualType, |
| 2047 | expr: *ast.Node, | 2043 | expr: *ast.Node, |
| 2048 | ) !*ast.Node { | 2044 | ) !*ast.Node { |
| 2049 | if (ZigClangType_isVoidType(qualTypeCanon(dst_type))) return expr; | 2045 | if (qualTypeCanon(dst_type).isVoidType()) return expr; |
| 2050 | if (ZigClangQualType_eq(dst_type, src_type)) return expr; | 2046 | if (dst_type.eq(src_type)) return expr; |
| 2051 | if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) | 2047 | if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) |
| 2052 | return transCPtrCast(rp, loc, dst_type, src_type, expr); | 2048 | return transCPtrCast(rp, loc, dst_type, src_type, expr); |
| 2053 | if (cIsInteger(dst_type) and cIsInteger(src_type)) { | 2049 | if (cIsInteger(dst_type) and cIsInteger(src_type)) { |
| ... | @@ -2134,9 +2130,7 @@ fn transCCast( | ... | @@ -2134,9 +2130,7 @@ fn transCCast( |
| 2134 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 2130 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 2135 | return &builtin_node.base; | 2131 | return &builtin_node.base; |
| 2136 | } | 2132 | } |
| 2137 | if (ZigClangType_isBooleanType(qualTypeCanon(src_type)) and | 2133 | if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) { |
| 2138 | !ZigClangType_isBooleanType(qualTypeCanon(dst_type))) | ||
| 2139 | { | ||
| 2140 | // @boolToInt returns either a comptime_int or a u1 | 2134 | // @boolToInt returns either a comptime_int or a u1 |
| 2141 | const builtin_node = try rp.c.createBuiltinCall("@boolToInt", 1); | 2135 | const builtin_node = try rp.c.createBuiltinCall("@boolToInt", 1); |
| 2142 | builtin_node.params()[0] = expr; | 2136 | builtin_node.params()[0] = expr; |
| ... | @@ -2166,7 +2160,7 @@ fn transCCast( | ... | @@ -2166,7 +2160,7 @@ fn transCCast( |
| 2166 | 2160 | ||
| 2167 | return &cast_node.base; | 2161 | return &cast_node.base; |
| 2168 | } | 2162 | } |
| 2169 | if (ZigClangQualType_getTypeClass(ZigClangQualType_getCanonicalType(dst_type)) == .Enum) { | 2163 | if (dst_type.getCanonicalType().getTypeClass() == .Enum) { |
| 2170 | const builtin_node = try rp.c.createBuiltinCall("@intToEnum", 2); | 2164 | const builtin_node = try rp.c.createBuiltinCall("@intToEnum", 2); |
| 2171 | builtin_node.params()[0] = try transQualType(rp, dst_type, loc); | 2165 | builtin_node.params()[0] = try transQualType(rp, dst_type, loc); |
| 2172 | _ = try appendToken(rp.c, .Comma, ","); | 2166 | _ = try appendToken(rp.c, .Comma, ","); |
| ... | @@ -2174,8 +2168,8 @@ fn transCCast( | ... | @@ -2174,8 +2168,8 @@ fn transCCast( |
| 2174 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 2168 | builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| 2175 | return &builtin_node.base; | 2169 | return &builtin_node.base; |
| 2176 | } | 2170 | } |
| 2177 | if (ZigClangQualType_getTypeClass(ZigClangQualType_getCanonicalType(src_type)) == .Enum and | 2171 | if (src_type.getCanonicalType().getTypeClass() == .Enum and |
| 2178 | ZigClangQualType_getTypeClass(ZigClangQualType_getCanonicalType(dst_type)) != .Enum) | 2172 | dst_type.getCanonicalType().getTypeClass() != .Enum) |
| 2179 | { | 2173 | { |
| 2180 | const builtin_node = try rp.c.createBuiltinCall("@enumToInt", 1); | 2174 | const builtin_node = try rp.c.createBuiltinCall("@enumToInt", 1); |
| 2181 | builtin_node.params()[0] = expr; | 2175 | builtin_node.params()[0] = expr; |
| ... | @@ -2193,11 +2187,11 @@ fn transCCast( | ... | @@ -2193,11 +2187,11 @@ fn transCCast( |
| 2193 | fn transExpr( | 2187 | fn transExpr( |
| 2194 | rp: RestorePoint, | 2188 | rp: RestorePoint, |
| 2195 | scope: *Scope, | 2189 | scope: *Scope, |
| 2196 | expr: *const ZigClangExpr, | 2190 | expr: *const clang.Expr, |
| 2197 | used: ResultUsed, | 2191 | used: ResultUsed, |
| 2198 | lrvalue: LRValue, | 2192 | lrvalue: LRValue, |
| 2199 | ) TransError!*ast.Node { | 2193 | ) TransError!*ast.Node { |
| 2200 | return transStmt(rp, scope, @ptrCast(*const ZigClangStmt, expr), used, lrvalue); | 2194 | return transStmt(rp, scope, @ptrCast(*const clang.Stmt, expr), used, lrvalue); |
| 2201 | } | 2195 | } |
| 2202 | 2196 | ||
| 2203 | /// Same as `transExpr` but with the knowledge that the operand will be type coerced, and therefore | 2197 | /// Same as `transExpr` but with the knowledge that the operand will be type coerced, and therefore |
| ... | @@ -2205,21 +2199,21 @@ fn transExpr( | ... | @@ -2205,21 +2199,21 @@ fn transExpr( |
| 2205 | fn transExprCoercing( | 2199 | fn transExprCoercing( |
| 2206 | rp: RestorePoint, | 2200 | rp: RestorePoint, |
| 2207 | scope: *Scope, | 2201 | scope: *Scope, |
| 2208 | expr: *const ZigClangExpr, | 2202 | expr: *const clang.Expr, |
| 2209 | used: ResultUsed, | 2203 | used: ResultUsed, |
| 2210 | lrvalue: LRValue, | 2204 | lrvalue: LRValue, |
| 2211 | ) TransError!*ast.Node { | 2205 | ) TransError!*ast.Node { |
| 2212 | switch (ZigClangStmt_getStmtClass(@ptrCast(*const ZigClangStmt, expr))) { | 2206 | switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) { |
| 2213 | .IntegerLiteralClass => { | 2207 | .IntegerLiteralClass => { |
| 2214 | return transIntegerLiteral(rp, scope, @ptrCast(*const ZigClangIntegerLiteral, expr), .used, .no_as); | 2208 | return transIntegerLiteral(rp, scope, @ptrCast(*const clang.IntegerLiteral, expr), .used, .no_as); |
| 2215 | }, | 2209 | }, |
| 2216 | .CharacterLiteralClass => { | 2210 | .CharacterLiteralClass => { |
| 2217 | return transCharLiteral(rp, scope, @ptrCast(*const ZigClangCharacterLiteral, expr), .used, .no_as); | 2211 | return transCharLiteral(rp, scope, @ptrCast(*const clang.CharacterLiteral, expr), .used, .no_as); |
| 2218 | }, | 2212 | }, |
| 2219 | .UnaryOperatorClass => { | 2213 | .UnaryOperatorClass => { |
| 2220 | const un_expr = @ptrCast(*const ZigClangUnaryOperator, expr); | 2214 | const un_expr = @ptrCast(*const clang.UnaryOperator, expr); |
| 2221 | if (ZigClangUnaryOperator_getOpcode(un_expr) == .Extension) { | 2215 | if (un_expr.getOpcode() == .Extension) { |
| 2222 | return transExprCoercing(rp, scope, ZigClangUnaryOperator_getSubExpr(un_expr), used, lrvalue); | 2216 | return transExprCoercing(rp, scope, un_expr.getSubExpr(), used, lrvalue); |
| 2223 | } | 2217 | } |
| 2224 | }, | 2218 | }, |
| 2225 | else => {}, | 2219 | else => {}, |
| ... | @@ -2230,51 +2224,51 @@ fn transExprCoercing( | ... | @@ -2230,51 +2224,51 @@ fn transExprCoercing( |
| 2230 | fn transInitListExprRecord( | 2224 | fn transInitListExprRecord( |
| 2231 | rp: RestorePoint, | 2225 | rp: RestorePoint, |
| 2232 | scope: *Scope, | 2226 | scope: *Scope, |
| 2233 | loc: ZigClangSourceLocation, | 2227 | loc: clang.SourceLocation, |
| 2234 | expr: *const ZigClangInitListExpr, | 2228 | expr: *const clang.InitListExpr, |
| 2235 | ty: *const ZigClangType, | 2229 | ty: *const clang.Type, |
| 2236 | used: ResultUsed, | 2230 | used: ResultUsed, |
| 2237 | ) TransError!*ast.Node { | 2231 | ) TransError!*ast.Node { |
| 2238 | var is_union_type = false; | 2232 | var is_union_type = false; |
| 2239 | // Unions and Structs are both represented as RecordDecl | 2233 | // Unions and Structs are both represented as RecordDecl |
| 2240 | const record_ty = ZigClangType_getAsRecordType(ty) orelse | 2234 | const record_ty = ty.getAsRecordType() orelse |
| 2241 | blk: { | 2235 | blk: { |
| 2242 | is_union_type = true; | 2236 | is_union_type = true; |
| 2243 | break :blk ZigClangType_getAsUnionType(ty); | 2237 | break :blk ty.getAsUnionType(); |
| 2244 | } orelse unreachable; | 2238 | } orelse unreachable; |
| 2245 | const record_decl = ZigClangRecordType_getDecl(record_ty); | 2239 | const record_decl = record_ty.getDecl(); |
| 2246 | const record_def = ZigClangRecordDecl_getDefinition(record_decl) orelse | 2240 | const record_def = record_decl.getDefinition() orelse |
| 2247 | unreachable; | 2241 | unreachable; |
| 2248 | 2242 | ||
| 2249 | const ty_node = try transType(rp, ty, loc); | 2243 | const ty_node = try transType(rp, ty, loc); |
| 2250 | const init_count = ZigClangInitListExpr_getNumInits(expr); | 2244 | const init_count = expr.getNumInits(); |
| 2251 | var field_inits = std.ArrayList(*ast.Node).init(rp.c.gpa); | 2245 | var field_inits = std.ArrayList(*ast.Node).init(rp.c.gpa); |
| 2252 | defer field_inits.deinit(); | 2246 | defer field_inits.deinit(); |
| 2253 | 2247 | ||
| 2254 | _ = try appendToken(rp.c, .LBrace, "{"); | 2248 | _ = try appendToken(rp.c, .LBrace, "{"); |
| 2255 | 2249 | ||
| 2256 | var init_i: c_uint = 0; | 2250 | var init_i: c_uint = 0; |
| 2257 | var it = ZigClangRecordDecl_field_begin(record_def); | 2251 | var it = record_def.field_begin(); |
| 2258 | const end_it = ZigClangRecordDecl_field_end(record_def); | 2252 | const end_it = record_def.field_end(); |
| 2259 | while (ZigClangRecordDecl_field_iterator_neq(it, end_it)) : (it = ZigClangRecordDecl_field_iterator_next(it)) { | 2253 | while (it.neq(end_it)) : (it = it.next()) { |
| 2260 | const field_decl = ZigClangRecordDecl_field_iterator_deref(it); | 2254 | const field_decl = it.deref(); |
| 2261 | 2255 | ||
| 2262 | // The initializer for a union type has a single entry only | 2256 | // The initializer for a union type has a single entry only |
| 2263 | if (is_union_type and field_decl != ZigClangInitListExpr_getInitializedFieldInUnion(expr)) { | 2257 | if (is_union_type and field_decl != expr.getInitializedFieldInUnion()) { |
| 2264 | continue; | 2258 | continue; |
| 2265 | } | 2259 | } |
| 2266 | 2260 | ||
| 2267 | assert(init_i < init_count); | 2261 | assert(init_i < init_count); |
| 2268 | const elem_expr = ZigClangInitListExpr_getInit(expr, init_i); | 2262 | const elem_expr = expr.getInit(init_i); |
| 2269 | init_i += 1; | 2263 | init_i += 1; |
| 2270 | 2264 | ||
| 2271 | // Generate the field assignment expression: | 2265 | // Generate the field assignment expression: |
| 2272 | // .field_name = expr | 2266 | // .field_name = expr |
| 2273 | const period_tok = try appendToken(rp.c, .Period, "."); | 2267 | const period_tok = try appendToken(rp.c, .Period, "."); |
| 2274 | 2268 | ||
| 2275 | var raw_name = try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, field_decl))); | 2269 | var raw_name = try rp.c.str(@ptrCast(*const clang.NamedDecl, field_decl).getName_bytes_begin()); |
| 2276 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) { | 2270 | if (field_decl.isAnonymousStructOrUnion()) { |
| 2277 | const name = rp.c.decl_table.get(@ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl))).?; | 2271 | const name = rp.c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?; |
| 2278 | raw_name = try mem.dupe(rp.c.arena, u8, name); | 2272 | raw_name = try mem.dupe(rp.c.arena, u8, name); |
| 2279 | } | 2273 | } |
| 2280 | const field_name_tok = try appendIdentifier(rp.c, raw_name); | 2274 | const field_name_tok = try appendIdentifier(rp.c, raw_name); |
| ... | @@ -2304,8 +2298,8 @@ fn transInitListExprRecord( | ... | @@ -2304,8 +2298,8 @@ fn transInitListExprRecord( |
| 2304 | 2298 | ||
| 2305 | fn transCreateNodeArrayType( | 2299 | fn transCreateNodeArrayType( |
| 2306 | rp: RestorePoint, | 2300 | rp: RestorePoint, |
| 2307 | source_loc: ZigClangSourceLocation, | 2301 | source_loc: clang.SourceLocation, |
| 2308 | ty: *const ZigClangType, | 2302 | ty: *const clang.Type, |
| 2309 | len: anytype, | 2303 | len: anytype, |
| 2310 | ) !*ast.Node { | 2304 | ) !*ast.Node { |
| 2311 | const node = try rp.c.arena.create(ast.Node.ArrayType); | 2305 | const node = try rp.c.arena.create(ast.Node.ArrayType); |
| ... | @@ -2323,18 +2317,18 @@ fn transCreateNodeArrayType( | ... | @@ -2323,18 +2317,18 @@ fn transCreateNodeArrayType( |
| 2323 | fn transInitListExprArray( | 2317 | fn transInitListExprArray( |
| 2324 | rp: RestorePoint, | 2318 | rp: RestorePoint, |
| 2325 | scope: *Scope, | 2319 | scope: *Scope, |
| 2326 | loc: ZigClangSourceLocation, | 2320 | loc: clang.SourceLocation, |
| 2327 | expr: *const ZigClangInitListExpr, | 2321 | expr: *const clang.InitListExpr, |
| 2328 | ty: *const ZigClangType, | 2322 | ty: *const clang.Type, |
| 2329 | used: ResultUsed, | 2323 | used: ResultUsed, |
| 2330 | ) TransError!*ast.Node { | 2324 | ) TransError!*ast.Node { |
| 2331 | const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty); | 2325 | const arr_type = ty.getAsArrayTypeUnsafe(); |
| 2332 | const child_qt = ZigClangArrayType_getElementType(arr_type); | 2326 | const child_qt = arr_type.getElementType(); |
| 2333 | const init_count = ZigClangInitListExpr_getNumInits(expr); | 2327 | const init_count = expr.getNumInits(); |
| 2334 | assert(ZigClangType_isConstantArrayType(@ptrCast(*const ZigClangType, arr_type))); | 2328 | assert(@ptrCast(*const clang.Type, arr_type).isConstantArrayType()); |
| 2335 | const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, arr_type); | 2329 | const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, arr_type); |
| 2336 | const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty); | 2330 | const size_ap_int = const_arr_ty.getSize(); |
| 2337 | const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize)); | 2331 | const all_count = size_ap_int.getLimitedValue(math.maxInt(usize)); |
| 2338 | const leftover_count = all_count - init_count; | 2332 | const leftover_count = all_count - init_count; |
| 2339 | 2333 | ||
| 2340 | var init_node: *ast.Node.ArrayInitializer = undefined; | 2334 | var init_node: *ast.Node.ArrayInitializer = undefined; |
| ... | @@ -2343,7 +2337,7 @@ fn transInitListExprArray( | ... | @@ -2343,7 +2337,7 @@ fn transInitListExprArray( |
| 2343 | const ty_node = try transCreateNodeArrayType( | 2337 | const ty_node = try transCreateNodeArrayType( |
| 2344 | rp, | 2338 | rp, |
| 2345 | loc, | 2339 | loc, |
| 2346 | ZigClangQualType_getTypePtr(child_qt), | 2340 | child_qt.getTypePtr(), |
| 2347 | init_count, | 2341 | init_count, |
| 2348 | ); | 2342 | ); |
| 2349 | _ = try appendToken(rp.c, .LBrace, "{"); | 2343 | _ = try appendToken(rp.c, .LBrace, "{"); |
| ... | @@ -2357,7 +2351,7 @@ fn transInitListExprArray( | ... | @@ -2357,7 +2351,7 @@ fn transInitListExprArray( |
| 2357 | 2351 | ||
| 2358 | var i: c_uint = 0; | 2352 | var i: c_uint = 0; |
| 2359 | while (i < init_count) : (i += 1) { | 2353 | while (i < init_count) : (i += 1) { |
| 2360 | const elem_expr = ZigClangInitListExpr_getInit(expr, i); | 2354 | const elem_expr = expr.getInit(i); |
| 2361 | init_list[i] = try transExpr(rp, scope, elem_expr, .used, .r_value); | 2355 | init_list[i] = try transExpr(rp, scope, elem_expr, .used, .r_value); |
| 2362 | _ = try appendToken(rp.c, .Comma, ","); | 2356 | _ = try appendToken(rp.c, .Comma, ","); |
| 2363 | } | 2357 | } |
| ... | @@ -2368,7 +2362,7 @@ fn transInitListExprArray( | ... | @@ -2368,7 +2362,7 @@ fn transInitListExprArray( |
| 2368 | cat_tok = try appendToken(rp.c, .PlusPlus, "++"); | 2362 | cat_tok = try appendToken(rp.c, .PlusPlus, "++"); |
| 2369 | } | 2363 | } |
| 2370 | 2364 | ||
| 2371 | const ty_node = try transCreateNodeArrayType(rp, loc, ZigClangQualType_getTypePtr(child_qt), 1); | 2365 | const ty_node = try transCreateNodeArrayType(rp, loc, child_qt.getTypePtr(), 1); |
| 2372 | _ = try appendToken(rp.c, .LBrace, "{"); | 2366 | _ = try appendToken(rp.c, .LBrace, "{"); |
| 2373 | const filler_init_node = try ast.Node.ArrayInitializer.alloc(rp.c.arena, 1); | 2367 | const filler_init_node = try ast.Node.ArrayInitializer.alloc(rp.c.arena, 1); |
| 2374 | filler_init_node.* = .{ | 2368 | filler_init_node.* = .{ |
| ... | @@ -2376,7 +2370,7 @@ fn transInitListExprArray( | ... | @@ -2376,7 +2370,7 @@ fn transInitListExprArray( |
| 2376 | .rtoken = undefined, | 2370 | .rtoken = undefined, |
| 2377 | .list_len = 1, | 2371 | .list_len = 1, |
| 2378 | }; | 2372 | }; |
| 2379 | const filler_val_expr = ZigClangInitListExpr_getArrayFiller(expr); | 2373 | const filler_val_expr = expr.getArrayFiller(); |
| 2380 | filler_init_node.list()[0] = try transExpr(rp, scope, filler_val_expr, .used, .r_value); | 2374 | filler_init_node.list()[0] = try transExpr(rp, scope, filler_val_expr, .used, .r_value); |
| 2381 | filler_init_node.rtoken = try appendToken(rp.c, .RBrace, "}"); | 2375 | filler_init_node.rtoken = try appendToken(rp.c, .RBrace, "}"); |
| 2382 | 2376 | ||
| ... | @@ -2411,14 +2405,14 @@ fn transInitListExprArray( | ... | @@ -2411,14 +2405,14 @@ fn transInitListExprArray( |
| 2411 | fn transInitListExpr( | 2405 | fn transInitListExpr( |
| 2412 | rp: RestorePoint, | 2406 | rp: RestorePoint, |
| 2413 | scope: *Scope, | 2407 | scope: *Scope, |
| 2414 | expr: *const ZigClangInitListExpr, | 2408 | expr: *const clang.InitListExpr, |
| 2415 | used: ResultUsed, | 2409 | used: ResultUsed, |
| 2416 | ) TransError!*ast.Node { | 2410 | ) TransError!*ast.Node { |
| 2417 | const qt = getExprQualType(rp.c, @ptrCast(*const ZigClangExpr, expr)); | 2411 | const qt = getExprQualType(rp.c, @ptrCast(*const clang.Expr, expr)); |
| 2418 | var qual_type = ZigClangQualType_getTypePtr(qt); | 2412 | var qual_type = qt.getTypePtr(); |
| 2419 | const source_loc = ZigClangExpr_getBeginLoc(@ptrCast(*const ZigClangExpr, expr)); | 2413 | const source_loc = @ptrCast(*const clang.Expr, expr).getBeginLoc(); |
| 2420 | 2414 | ||
| 2421 | if (ZigClangType_isRecordType(qual_type)) { | 2415 | if (qual_type.isRecordType()) { |
| 2422 | return transInitListExprRecord( | 2416 | return transInitListExprRecord( |
| 2423 | rp, | 2417 | rp, |
| 2424 | scope, | 2418 | scope, |
| ... | @@ -2427,7 +2421,7 @@ fn transInitListExpr( | ... | @@ -2427,7 +2421,7 @@ fn transInitListExpr( |
| 2427 | qual_type, | 2421 | qual_type, |
| 2428 | used, | 2422 | used, |
| 2429 | ); | 2423 | ); |
| 2430 | } else if (ZigClangType_isArrayType(qual_type)) { | 2424 | } else if (qual_type.isArrayType()) { |
| 2431 | return transInitListExprArray( | 2425 | return transInitListExprArray( |
| 2432 | rp, | 2426 | rp, |
| 2433 | scope, | 2427 | scope, |
| ... | @@ -2437,7 +2431,7 @@ fn transInitListExpr( | ... | @@ -2437,7 +2431,7 @@ fn transInitListExpr( |
| 2437 | used, | 2431 | used, |
| 2438 | ); | 2432 | ); |
| 2439 | } else { | 2433 | } else { |
| 2440 | const type_name = rp.c.str(ZigClangType_getTypeClassName(qual_type)); | 2434 | const type_name = rp.c.str(qual_type.getTypeClassName()); |
| 2441 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported initlist type: '{}'", .{type_name}); | 2435 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported initlist type: '{}'", .{type_name}); |
| 2442 | } | 2436 | } |
| 2443 | } | 2437 | } |
| ... | @@ -2445,13 +2439,13 @@ fn transInitListExpr( | ... | @@ -2445,13 +2439,13 @@ fn transInitListExpr( |
| 2445 | fn transZeroInitExpr( | 2439 | fn transZeroInitExpr( |
| 2446 | rp: RestorePoint, | 2440 | rp: RestorePoint, |
| 2447 | scope: *Scope, | 2441 | scope: *Scope, |
| 2448 | source_loc: ZigClangSourceLocation, | 2442 | source_loc: clang.SourceLocation, |
| 2449 | ty: *const ZigClangType, | 2443 | ty: *const clang.Type, |
| 2450 | ) TransError!*ast.Node { | 2444 | ) TransError!*ast.Node { |
| 2451 | switch (ZigClangType_getTypeClass(ty)) { | 2445 | switch (ty.getTypeClass()) { |
| 2452 | .Builtin => { | 2446 | .Builtin => { |
| 2453 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 2447 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 2454 | switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 2448 | switch (builtin_ty.getKind()) { |
| 2455 | .Bool => return try transCreateNodeBoolLiteral(rp.c, false), | 2449 | .Bool => return try transCreateNodeBoolLiteral(rp.c, false), |
| 2456 | .Char_U, | 2450 | .Char_U, |
| 2457 | .UChar, | 2451 | .UChar, |
| ... | @@ -2479,15 +2473,13 @@ fn transZeroInitExpr( | ... | @@ -2479,15 +2473,13 @@ fn transZeroInitExpr( |
| 2479 | }, | 2473 | }, |
| 2480 | .Pointer => return transCreateNodeNullLiteral(rp.c), | 2474 | .Pointer => return transCreateNodeNullLiteral(rp.c), |
| 2481 | .Typedef => { | 2475 | .Typedef => { |
| 2482 | const typedef_ty = @ptrCast(*const ZigClangTypedefType, ty); | 2476 | const typedef_ty = @ptrCast(*const clang.TypedefType, ty); |
| 2483 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 2477 | const typedef_decl = typedef_ty.getDecl(); |
| 2484 | return transZeroInitExpr( | 2478 | return transZeroInitExpr( |
| 2485 | rp, | 2479 | rp, |
| 2486 | scope, | 2480 | scope, |
| 2487 | source_loc, | 2481 | source_loc, |
| 2488 | ZigClangQualType_getTypePtr( | 2482 | typedef_decl.getUnderlyingType().getTypePtr(), |
| 2489 | ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl), | ||
| 2490 | ), | ||
| 2491 | ); | 2483 | ); |
| 2492 | }, | 2484 | }, |
| 2493 | else => {}, | 2485 | else => {}, |
| ... | @@ -2499,19 +2491,19 @@ fn transZeroInitExpr( | ... | @@ -2499,19 +2491,19 @@ fn transZeroInitExpr( |
| 2499 | fn transImplicitValueInitExpr( | 2491 | fn transImplicitValueInitExpr( |
| 2500 | rp: RestorePoint, | 2492 | rp: RestorePoint, |
| 2501 | scope: *Scope, | 2493 | scope: *Scope, |
| 2502 | expr: *const ZigClangExpr, | 2494 | expr: *const clang.Expr, |
| 2503 | used: ResultUsed, | 2495 | used: ResultUsed, |
| 2504 | ) TransError!*ast.Node { | 2496 | ) TransError!*ast.Node { |
| 2505 | const source_loc = ZigClangExpr_getBeginLoc(expr); | 2497 | const source_loc = expr.getBeginLoc(); |
| 2506 | const qt = getExprQualType(rp.c, expr); | 2498 | const qt = getExprQualType(rp.c, expr); |
| 2507 | const ty = ZigClangQualType_getTypePtr(qt); | 2499 | const ty = qt.getTypePtr(); |
| 2508 | return transZeroInitExpr(rp, scope, source_loc, ty); | 2500 | return transZeroInitExpr(rp, scope, source_loc, ty); |
| 2509 | } | 2501 | } |
| 2510 | 2502 | ||
| 2511 | fn transIfStmt( | 2503 | fn transIfStmt( |
| 2512 | rp: RestorePoint, | 2504 | rp: RestorePoint, |
| 2513 | scope: *Scope, | 2505 | scope: *Scope, |
| 2514 | stmt: *const ZigClangIfStmt, | 2506 | stmt: *const clang.IfStmt, |
| 2515 | ) TransError!*ast.Node { | 2507 | ) TransError!*ast.Node { |
| 2516 | // if (c) t | 2508 | // if (c) t |
| 2517 | // if (c) t else e | 2509 | // if (c) t else e |
| ... | @@ -2524,13 +2516,13 @@ fn transIfStmt( | ... | @@ -2524,13 +2516,13 @@ fn transIfStmt( |
| 2524 | }, | 2516 | }, |
| 2525 | }; | 2517 | }; |
| 2526 | defer cond_scope.deinit(); | 2518 | defer cond_scope.deinit(); |
| 2527 | const cond_expr = @ptrCast(*const ZigClangExpr, ZigClangIfStmt_getCond(stmt)); | 2519 | const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond()); |
| 2528 | if_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); | 2520 | if_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); |
| 2529 | _ = try appendToken(rp.c, .RParen, ")"); | 2521 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2530 | 2522 | ||
| 2531 | if_node.body = try transStmt(rp, scope, ZigClangIfStmt_getThen(stmt), .unused, .r_value); | 2523 | if_node.body = try transStmt(rp, scope, stmt.getThen(), .unused, .r_value); |
| 2532 | 2524 | ||
| 2533 | if (ZigClangIfStmt_getElse(stmt)) |expr| { | 2525 | if (stmt.getElse()) |expr| { |
| 2534 | if_node.@"else" = try transCreateNodeElse(rp.c); | 2526 | if_node.@"else" = try transCreateNodeElse(rp.c); |
| 2535 | if_node.@"else".?.body = try transStmt(rp, scope, expr, .unused, .r_value); | 2527 | if_node.@"else".?.body = try transStmt(rp, scope, expr, .unused, .r_value); |
| 2536 | } | 2528 | } |
| ... | @@ -2541,7 +2533,7 @@ fn transIfStmt( | ... | @@ -2541,7 +2533,7 @@ fn transIfStmt( |
| 2541 | fn transWhileLoop( | 2533 | fn transWhileLoop( |
| 2542 | rp: RestorePoint, | 2534 | rp: RestorePoint, |
| 2543 | scope: *Scope, | 2535 | scope: *Scope, |
| 2544 | stmt: *const ZigClangWhileStmt, | 2536 | stmt: *const clang.WhileStmt, |
| 2545 | ) TransError!*ast.Node { | 2537 | ) TransError!*ast.Node { |
| 2546 | const while_node = try transCreateNodeWhile(rp.c); | 2538 | const while_node = try transCreateNodeWhile(rp.c); |
| 2547 | 2539 | ||
| ... | @@ -2552,7 +2544,7 @@ fn transWhileLoop( | ... | @@ -2552,7 +2544,7 @@ fn transWhileLoop( |
| 2552 | }, | 2544 | }, |
| 2553 | }; | 2545 | }; |
| 2554 | defer cond_scope.deinit(); | 2546 | defer cond_scope.deinit(); |
| 2555 | const cond_expr = @ptrCast(*const ZigClangExpr, ZigClangWhileStmt_getCond(stmt)); | 2547 | const cond_expr = @ptrCast(*const clang.Expr, stmt.getCond()); |
| 2556 | while_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); | 2548 | while_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); |
| 2557 | _ = try appendToken(rp.c, .RParen, ")"); | 2549 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2558 | 2550 | ||
| ... | @@ -2560,7 +2552,7 @@ fn transWhileLoop( | ... | @@ -2560,7 +2552,7 @@ fn transWhileLoop( |
| 2560 | .parent = scope, | 2552 | .parent = scope, |
| 2561 | .id = .Loop, | 2553 | .id = .Loop, |
| 2562 | }; | 2554 | }; |
| 2563 | while_node.body = try transStmt(rp, &loop_scope, ZigClangWhileStmt_getBody(stmt), .unused, .r_value); | 2555 | while_node.body = try transStmt(rp, &loop_scope, stmt.getBody(), .unused, .r_value); |
| 2564 | _ = try appendToken(rp.c, .Semicolon, ";"); | 2556 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 2565 | return &while_node.base; | 2557 | return &while_node.base; |
| 2566 | } | 2558 | } |
| ... | @@ -2568,7 +2560,7 @@ fn transWhileLoop( | ... | @@ -2568,7 +2560,7 @@ fn transWhileLoop( |
| 2568 | fn transDoWhileLoop( | 2560 | fn transDoWhileLoop( |
| 2569 | rp: RestorePoint, | 2561 | rp: RestorePoint, |
| 2570 | scope: *Scope, | 2562 | scope: *Scope, |
| 2571 | stmt: *const ZigClangDoStmt, | 2563 | stmt: *const clang.DoStmt, |
| 2572 | ) TransError!*ast.Node { | 2564 | ) TransError!*ast.Node { |
| 2573 | const while_node = try transCreateNodeWhile(rp.c); | 2565 | const while_node = try transCreateNodeWhile(rp.c); |
| 2574 | 2566 | ||
| ... | @@ -2590,13 +2582,13 @@ fn transDoWhileLoop( | ... | @@ -2590,13 +2582,13 @@ fn transDoWhileLoop( |
| 2590 | }; | 2582 | }; |
| 2591 | defer cond_scope.deinit(); | 2583 | defer cond_scope.deinit(); |
| 2592 | const prefix_op = try transCreateNodeSimplePrefixOp(rp.c, .BoolNot, .Bang, "!"); | 2584 | const prefix_op = try transCreateNodeSimplePrefixOp(rp.c, .BoolNot, .Bang, "!"); |
| 2593 | prefix_op.rhs = try transBoolExpr(rp, &cond_scope.base, @ptrCast(*const ZigClangExpr, ZigClangDoStmt_getCond(stmt)), .used, .r_value, true); | 2585 | prefix_op.rhs = try transBoolExpr(rp, &cond_scope.base, @ptrCast(*const clang.Expr, stmt.getCond()), .used, .r_value, true); |
| 2594 | _ = try appendToken(rp.c, .RParen, ")"); | 2586 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2595 | if_node.condition = &prefix_op.base; | 2587 | if_node.condition = &prefix_op.base; |
| 2596 | if_node.body = &(try transCreateNodeBreak(rp.c, null, null)).base; | 2588 | if_node.body = &(try transCreateNodeBreak(rp.c, null, null)).base; |
| 2597 | _ = try appendToken(rp.c, .Semicolon, ";"); | 2589 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 2598 | 2590 | ||
| 2599 | const body_node = if (ZigClangStmt_getStmtClass(ZigClangDoStmt_getBody(stmt)) == .CompoundStmtClass) blk: { | 2591 | const body_node = if (stmt.getBody().getStmtClass() == .CompoundStmtClass) blk: { |
| 2600 | // there's already a block in C, so we'll append our condition to it. | 2592 | // there's already a block in C, so we'll append our condition to it. |
| 2601 | // c: do { | 2593 | // c: do { |
| 2602 | // c: a; | 2594 | // c: a; |
| ... | @@ -2607,7 +2599,7 @@ fn transDoWhileLoop( | ... | @@ -2607,7 +2599,7 @@ fn transDoWhileLoop( |
| 2607 | // zig: b; | 2599 | // zig: b; |
| 2608 | // zig: if (!cond) break; | 2600 | // zig: if (!cond) break; |
| 2609 | // zig: } | 2601 | // zig: } |
| 2610 | const node = try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value); | 2602 | const node = try transStmt(rp, &loop_scope, stmt.getBody(), .unused, .r_value); |
| 2611 | break :blk node.castTag(.Block).?; | 2603 | break :blk node.castTag(.Block).?; |
| 2612 | } else blk: { | 2604 | } else blk: { |
| 2613 | // the C statement is without a block, so we need to create a block to contain it. | 2605 | // the C statement is without a block, so we need to create a block to contain it. |
| ... | @@ -2621,7 +2613,7 @@ fn transDoWhileLoop( | ... | @@ -2621,7 +2613,7 @@ fn transDoWhileLoop( |
| 2621 | new = true; | 2613 | new = true; |
| 2622 | const block = try rp.c.createBlock(2); | 2614 | const block = try rp.c.createBlock(2); |
| 2623 | block.statements_len = 1; // over-allocated so we can add another below | 2615 | block.statements_len = 1; // over-allocated so we can add another below |
| 2624 | block.statements()[0] = try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value); | 2616 | block.statements()[0] = try transStmt(rp, &loop_scope, stmt.getBody(), .unused, .r_value); |
| 2625 | break :blk block; | 2617 | break :blk block; |
| 2626 | }; | 2618 | }; |
| 2627 | 2619 | ||
| ... | @@ -2637,7 +2629,7 @@ fn transDoWhileLoop( | ... | @@ -2637,7 +2629,7 @@ fn transDoWhileLoop( |
| 2637 | fn transForLoop( | 2629 | fn transForLoop( |
| 2638 | rp: RestorePoint, | 2630 | rp: RestorePoint, |
| 2639 | scope: *Scope, | 2631 | scope: *Scope, |
| 2640 | stmt: *const ZigClangForStmt, | 2632 | stmt: *const clang.ForStmt, |
| 2641 | ) TransError!*ast.Node { | 2633 | ) TransError!*ast.Node { |
| 2642 | var loop_scope = Scope{ | 2634 | var loop_scope = Scope{ |
| 2643 | .parent = scope, | 2635 | .parent = scope, |
| ... | @@ -2647,7 +2639,7 @@ fn transForLoop( | ... | @@ -2647,7 +2639,7 @@ fn transForLoop( |
| 2647 | var block_scope: ?Scope.Block = null; | 2639 | var block_scope: ?Scope.Block = null; |
| 2648 | defer if (block_scope) |*bs| bs.deinit(); | 2640 | defer if (block_scope) |*bs| bs.deinit(); |
| 2649 | 2641 | ||
| 2650 | if (ZigClangForStmt_getInit(stmt)) |init| { | 2642 | if (stmt.getInit()) |init| { |
| 2651 | block_scope = try Scope.Block.init(rp.c, scope, false); | 2643 | block_scope = try Scope.Block.init(rp.c, scope, false); |
| 2652 | loop_scope.parent = &block_scope.?.base; | 2644 | loop_scope.parent = &block_scope.?.base; |
| 2653 | const init_node = try transStmt(rp, &block_scope.?.base, init, .unused, .r_value); | 2645 | const init_node = try transStmt(rp, &block_scope.?.base, init, .unused, .r_value); |
| ... | @@ -2662,20 +2654,20 @@ fn transForLoop( | ... | @@ -2662,20 +2654,20 @@ fn transForLoop( |
| 2662 | defer cond_scope.deinit(); | 2654 | defer cond_scope.deinit(); |
| 2663 | 2655 | ||
| 2664 | const while_node = try transCreateNodeWhile(rp.c); | 2656 | const while_node = try transCreateNodeWhile(rp.c); |
| 2665 | while_node.condition = if (ZigClangForStmt_getCond(stmt)) |cond| | 2657 | while_node.condition = if (stmt.getCond()) |cond| |
| 2666 | try transBoolExpr(rp, &cond_scope.base, cond, .used, .r_value, false) | 2658 | try transBoolExpr(rp, &cond_scope.base, cond, .used, .r_value, false) |
| 2667 | else | 2659 | else |
| 2668 | try transCreateNodeBoolLiteral(rp.c, true); | 2660 | try transCreateNodeBoolLiteral(rp.c, true); |
| 2669 | _ = try appendToken(rp.c, .RParen, ")"); | 2661 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2670 | 2662 | ||
| 2671 | if (ZigClangForStmt_getInc(stmt)) |incr| { | 2663 | if (stmt.getInc()) |incr| { |
| 2672 | _ = try appendToken(rp.c, .Colon, ":"); | 2664 | _ = try appendToken(rp.c, .Colon, ":"); |
| 2673 | _ = try appendToken(rp.c, .LParen, "("); | 2665 | _ = try appendToken(rp.c, .LParen, "("); |
| 2674 | while_node.continue_expr = try transExpr(rp, &cond_scope.base, incr, .unused, .r_value); | 2666 | while_node.continue_expr = try transExpr(rp, &cond_scope.base, incr, .unused, .r_value); |
| 2675 | _ = try appendToken(rp.c, .RParen, ")"); | 2667 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2676 | } | 2668 | } |
| 2677 | 2669 | ||
| 2678 | while_node.body = try transStmt(rp, &loop_scope, ZigClangForStmt_getBody(stmt), .unused, .r_value); | 2670 | while_node.body = try transStmt(rp, &loop_scope, stmt.getBody(), .unused, .r_value); |
| 2679 | if (block_scope) |*bs| { | 2671 | if (block_scope) |*bs| { |
| 2680 | try bs.statements.append(&while_node.base); | 2672 | try bs.statements.append(&while_node.base); |
| 2681 | return try bs.complete(rp.c); | 2673 | return try bs.complete(rp.c); |
| ... | @@ -2685,21 +2677,21 @@ fn transForLoop( | ... | @@ -2685,21 +2677,21 @@ fn transForLoop( |
| 2685 | } | 2677 | } |
| 2686 | } | 2678 | } |
| 2687 | 2679 | ||
| 2688 | fn getSwitchCaseCount(stmt: *const ZigClangSwitchStmt) usize { | 2680 | fn getSwitchCaseCount(stmt: *const clang.SwitchStmt) usize { |
| 2689 | const body = ZigClangSwitchStmt_getBody(stmt); | 2681 | const body = stmt.getBody(); |
| 2690 | assert(ZigClangStmt_getStmtClass(body) == .CompoundStmtClass); | 2682 | assert(body.getStmtClass() == .CompoundStmtClass); |
| 2691 | const comp = @ptrCast(*const ZigClangCompoundStmt, body); | 2683 | const comp = @ptrCast(*const clang.CompoundStmt, body); |
| 2692 | // TODO https://github.com/ziglang/zig/issues/1738 | 2684 | // TODO https://github.com/ziglang/zig/issues/1738 |
| 2693 | // return ZigClangCompoundStmt_body_end(comp) - ZigClangCompoundStmt_body_begin(comp); | 2685 | // return comp.body_end() - comp.body_begin(); |
| 2694 | const start_addr = @ptrToInt(ZigClangCompoundStmt_body_begin(comp)); | 2686 | const start_addr = @ptrToInt(comp.body_begin()); |
| 2695 | const end_addr = @ptrToInt(ZigClangCompoundStmt_body_end(comp)); | 2687 | const end_addr = @ptrToInt(comp.body_end()); |
| 2696 | return (end_addr - start_addr) / @sizeOf(*ZigClangStmt); | 2688 | return (end_addr - start_addr) / @sizeOf(*clang.Stmt); |
| 2697 | } | 2689 | } |
| 2698 | 2690 | ||
| 2699 | fn transSwitch( | 2691 | fn transSwitch( |
| 2700 | rp: RestorePoint, | 2692 | rp: RestorePoint, |
| 2701 | scope: *Scope, | 2693 | scope: *Scope, |
| 2702 | stmt: *const ZigClangSwitchStmt, | 2694 | stmt: *const clang.SwitchStmt, |
| 2703 | ) TransError!*ast.Node { | 2695 | ) TransError!*ast.Node { |
| 2704 | const switch_tok = try appendToken(rp.c, .Keyword_switch, "switch"); | 2696 | const switch_tok = try appendToken(rp.c, .Keyword_switch, "switch"); |
| 2705 | _ = try appendToken(rp.c, .LParen, "("); | 2697 | _ = try appendToken(rp.c, .LParen, "("); |
| ... | @@ -2713,7 +2705,7 @@ fn transSwitch( | ... | @@ -2713,7 +2705,7 @@ fn transSwitch( |
| 2713 | }, | 2705 | }, |
| 2714 | }; | 2706 | }; |
| 2715 | defer cond_scope.deinit(); | 2707 | defer cond_scope.deinit(); |
| 2716 | const switch_expr = try transExpr(rp, &cond_scope.base, ZigClangSwitchStmt_getCond(stmt), .used, .r_value); | 2708 | const switch_expr = try transExpr(rp, &cond_scope.base, stmt.getCond(), .used, .r_value); |
| 2717 | _ = try appendToken(rp.c, .RParen, ")"); | 2709 | _ = try appendToken(rp.c, .RParen, ")"); |
| 2718 | _ = try appendToken(rp.c, .LBrace, "{"); | 2710 | _ = try appendToken(rp.c, .LBrace, "{"); |
| 2719 | // reserve +1 case in case there is no default case | 2711 | // reserve +1 case in case there is no default case |
| ... | @@ -2748,7 +2740,7 @@ fn transSwitch( | ... | @@ -2748,7 +2740,7 @@ fn transSwitch( |
| 2748 | switch_scope.pending_block = try Scope.Block.init(rp.c, scope, false); | 2740 | switch_scope.pending_block = try Scope.Block.init(rp.c, scope, false); |
| 2749 | try switch_scope.pending_block.statements.append(&switch_node.base); | 2741 | try switch_scope.pending_block.statements.append(&switch_node.base); |
| 2750 | 2742 | ||
| 2751 | const last = try transStmt(rp, &block_scope.base, ZigClangSwitchStmt_getBody(stmt), .unused, .r_value); | 2743 | const last = try transStmt(rp, &block_scope.base, stmt.getBody(), .unused, .r_value); |
| 2752 | _ = try appendToken(rp.c, .Semicolon, ";"); | 2744 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 2753 | 2745 | ||
| 2754 | // take all pending statements | 2746 | // take all pending statements |
| ... | @@ -2776,7 +2768,7 @@ fn transSwitch( | ... | @@ -2776,7 +2768,7 @@ fn transSwitch( |
| 2776 | _ = try appendToken(rp.c, .Comma, ","); | 2768 | _ = try appendToken(rp.c, .Comma, ","); |
| 2777 | 2769 | ||
| 2778 | if (switch_scope.case_index >= switch_scope.cases.len) | 2770 | if (switch_scope.case_index >= switch_scope.cases.len) |
| 2779 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{}); | 2771 | return revertAndWarn(rp, error.UnsupportedTranslation, @ptrCast(*const clang.Stmt, stmt).getBeginLoc(), "TODO complex switch cases", .{}); |
| 2780 | switch_scope.cases[switch_scope.case_index] = &else_prong.base; | 2772 | switch_scope.cases[switch_scope.case_index] = &else_prong.base; |
| 2781 | switch_scope.case_index += 1; | 2773 | switch_scope.case_index += 1; |
| 2782 | } | 2774 | } |
| ... | @@ -2792,15 +2784,15 @@ fn transSwitch( | ... | @@ -2792,15 +2784,15 @@ fn transSwitch( |
| 2792 | fn transCase( | 2784 | fn transCase( |
| 2793 | rp: RestorePoint, | 2785 | rp: RestorePoint, |
| 2794 | scope: *Scope, | 2786 | scope: *Scope, |
| 2795 | stmt: *const ZigClangCaseStmt, | 2787 | stmt: *const clang.CaseStmt, |
| 2796 | ) TransError!*ast.Node { | 2788 | ) TransError!*ast.Node { |
| 2797 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; | 2789 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; |
| 2798 | const switch_scope = scope.getSwitch(); | 2790 | const switch_scope = scope.getSwitch(); |
| 2799 | const label = try block_scope.makeMangledName(rp.c, "case"); | 2791 | const label = try block_scope.makeMangledName(rp.c, "case"); |
| 2800 | _ = try appendToken(rp.c, .Semicolon, ";"); | 2792 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 2801 | 2793 | ||
| 2802 | const expr = if (ZigClangCaseStmt_getRHS(stmt)) |rhs| blk: { | 2794 | const expr = if (stmt.getRHS()) |rhs| blk: { |
| 2803 | const lhs_node = try transExpr(rp, scope, ZigClangCaseStmt_getLHS(stmt), .used, .r_value); | 2795 | const lhs_node = try transExpr(rp, scope, stmt.getLHS(), .used, .r_value); |
| 2804 | const ellips = try appendToken(rp.c, .Ellipsis3, "..."); | 2796 | const ellips = try appendToken(rp.c, .Ellipsis3, "..."); |
| 2805 | const rhs_node = try transExpr(rp, scope, rhs, .used, .r_value); | 2797 | const rhs_node = try transExpr(rp, scope, rhs, .used, .r_value); |
| 2806 | 2798 | ||
| ... | @@ -2813,7 +2805,7 @@ fn transCase( | ... | @@ -2813,7 +2805,7 @@ fn transCase( |
| 2813 | }; | 2805 | }; |
| 2814 | break :blk &node.base; | 2806 | break :blk &node.base; |
| 2815 | } else | 2807 | } else |
| 2816 | try transExpr(rp, scope, ZigClangCaseStmt_getLHS(stmt), .used, .r_value); | 2808 | try transExpr(rp, scope, stmt.getLHS(), .used, .r_value); |
| 2817 | 2809 | ||
| 2818 | const switch_prong = try transCreateNodeSwitchCase(rp.c, expr); | 2810 | const switch_prong = try transCreateNodeSwitchCase(rp.c, expr); |
| 2819 | switch_prong.expr = blk: { | 2811 | switch_prong.expr = blk: { |
| ... | @@ -2823,7 +2815,7 @@ fn transCase( | ... | @@ -2823,7 +2815,7 @@ fn transCase( |
| 2823 | _ = try appendToken(rp.c, .Comma, ","); | 2815 | _ = try appendToken(rp.c, .Comma, ","); |
| 2824 | 2816 | ||
| 2825 | if (switch_scope.case_index >= switch_scope.cases.len) | 2817 | if (switch_scope.case_index >= switch_scope.cases.len) |
| 2826 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{}); | 2818 | return revertAndWarn(rp, error.UnsupportedTranslation, @ptrCast(*const clang.Stmt, stmt).getBeginLoc(), "TODO complex switch cases", .{}); |
| 2827 | switch_scope.cases[switch_scope.case_index] = &switch_prong.base; | 2819 | switch_scope.cases[switch_scope.case_index] = &switch_prong.base; |
| 2828 | switch_scope.case_index += 1; | 2820 | switch_scope.case_index += 1; |
| 2829 | 2821 | ||
| ... | @@ -2840,13 +2832,13 @@ fn transCase( | ... | @@ -2840,13 +2832,13 @@ fn transCase( |
| 2840 | 2832 | ||
| 2841 | try switch_scope.pending_block.statements.append(pending_node); | 2833 | try switch_scope.pending_block.statements.append(pending_node); |
| 2842 | 2834 | ||
| 2843 | return transStmt(rp, scope, ZigClangCaseStmt_getSubStmt(stmt), .unused, .r_value); | 2835 | return transStmt(rp, scope, stmt.getSubStmt(), .unused, .r_value); |
| 2844 | } | 2836 | } |
| 2845 | 2837 | ||
| 2846 | fn transDefault( | 2838 | fn transDefault( |
| 2847 | rp: RestorePoint, | 2839 | rp: RestorePoint, |
| 2848 | scope: *Scope, | 2840 | scope: *Scope, |
| 2849 | stmt: *const ZigClangDefaultStmt, | 2841 | stmt: *const clang.DefaultStmt, |
| 2850 | ) TransError!*ast.Node { | 2842 | ) TransError!*ast.Node { |
| 2851 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; | 2843 | const block_scope = scope.findBlockScope(rp.c) catch unreachable; |
| 2852 | const switch_scope = scope.getSwitch(); | 2844 | const switch_scope = scope.getSwitch(); |
| ... | @@ -2861,7 +2853,7 @@ fn transDefault( | ... | @@ -2861,7 +2853,7 @@ fn transDefault( |
| 2861 | _ = try appendToken(rp.c, .Comma, ","); | 2853 | _ = try appendToken(rp.c, .Comma, ","); |
| 2862 | 2854 | ||
| 2863 | if (switch_scope.case_index >= switch_scope.cases.len) | 2855 | if (switch_scope.case_index >= switch_scope.cases.len) |
| 2864 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), "TODO complex switch cases", .{}); | 2856 | return revertAndWarn(rp, error.UnsupportedTranslation, @ptrCast(*const clang.Stmt, stmt).getBeginLoc(), "TODO complex switch cases", .{}); |
| 2865 | switch_scope.cases[switch_scope.case_index] = &else_prong.base; | 2857 | switch_scope.cases[switch_scope.case_index] = &else_prong.base; |
| 2866 | switch_scope.case_index += 1; | 2858 | switch_scope.case_index += 1; |
| 2867 | 2859 | ||
| ... | @@ -2877,26 +2869,26 @@ fn transDefault( | ... | @@ -2877,26 +2869,26 @@ fn transDefault( |
| 2877 | switch_scope.pending_block = try Scope.Block.init(rp.c, scope, false); | 2869 | switch_scope.pending_block = try Scope.Block.init(rp.c, scope, false); |
| 2878 | try switch_scope.pending_block.statements.append(pending_node); | 2870 | try switch_scope.pending_block.statements.append(pending_node); |
| 2879 | 2871 | ||
| 2880 | return transStmt(rp, scope, ZigClangDefaultStmt_getSubStmt(stmt), .unused, .r_value); | 2872 | return transStmt(rp, scope, stmt.getSubStmt(), .unused, .r_value); |
| 2881 | } | 2873 | } |
| 2882 | 2874 | ||
| 2883 | fn transConstantExpr(rp: RestorePoint, scope: *Scope, expr: *const ZigClangExpr, used: ResultUsed) TransError!*ast.Node { | 2875 | fn transConstantExpr(rp: RestorePoint, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!*ast.Node { |
| 2884 | var result: ZigClangExprEvalResult = undefined; | 2876 | var result: clang.ExprEvalResult = undefined; |
| 2885 | if (!ZigClangExpr_EvaluateAsConstantExpr(expr, &result, .EvaluateForCodeGen, rp.c.clang_context)) | 2877 | if (!expr.EvaluateAsConstantExpr(&result, .EvaluateForCodeGen, rp.c.clang_context)) |
| 2886 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(expr), "invalid constant expression", .{}); | 2878 | return revertAndWarn(rp, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid constant expression", .{}); |
| 2887 | 2879 | ||
| 2888 | var val_node: ?*ast.Node = null; | 2880 | var val_node: ?*ast.Node = null; |
| 2889 | switch (ZigClangAPValue_getKind(&result.Val)) { | 2881 | switch (result.Val.getKind()) { |
| 2890 | .Int => { | 2882 | .Int => { |
| 2891 | // See comment in `transIntegerLiteral` for why this code is here. | 2883 | // See comment in `transIntegerLiteral` for why this code is here. |
| 2892 | // @as(T, x) | 2884 | // @as(T, x) |
| 2893 | const expr_base = @ptrCast(*const ZigClangExpr, expr); | 2885 | const expr_base = @ptrCast(*const clang.Expr, expr); |
| 2894 | const as_node = try rp.c.createBuiltinCall("@as", 2); | 2886 | const as_node = try rp.c.createBuiltinCall("@as", 2); |
| 2895 | const ty_node = try transQualType(rp, ZigClangExpr_getType(expr_base), ZigClangExpr_getBeginLoc(expr_base)); | 2887 | const ty_node = try transQualType(rp, expr_base.getType(), expr_base.getBeginLoc()); |
| 2896 | as_node.params()[0] = ty_node; | 2888 | as_node.params()[0] = ty_node; |
| 2897 | _ = try appendToken(rp.c, .Comma, ","); | 2889 | _ = try appendToken(rp.c, .Comma, ","); |
| 2898 | 2890 | ||
| 2899 | const int_lit_node = try transCreateNodeAPInt(rp.c, ZigClangAPValue_getInt(&result.Val)); | 2891 | const int_lit_node = try transCreateNodeAPInt(rp.c, result.Val.getInt()); |
| 2900 | as_node.params()[1] = int_lit_node; | 2892 | as_node.params()[1] = int_lit_node; |
| 2901 | 2893 | ||
| 2902 | as_node.rparen_token = try appendToken(rp.c, .RParen, ")"); | 2894 | as_node.rparen_token = try appendToken(rp.c, .RParen, ")"); |
| ... | @@ -2904,26 +2896,26 @@ fn transConstantExpr(rp: RestorePoint, scope: *Scope, expr: *const ZigClangExpr, | ... | @@ -2904,26 +2896,26 @@ fn transConstantExpr(rp: RestorePoint, scope: *Scope, expr: *const ZigClangExpr, |
| 2904 | return maybeSuppressResult(rp, scope, used, &as_node.base); | 2896 | return maybeSuppressResult(rp, scope, used, &as_node.base); |
| 2905 | }, | 2897 | }, |
| 2906 | else => { | 2898 | else => { |
| 2907 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangExpr_getBeginLoc(expr), "unsupported constant expression kind", .{}); | 2899 | return revertAndWarn(rp, error.UnsupportedTranslation, expr.getBeginLoc(), "unsupported constant expression kind", .{}); |
| 2908 | }, | 2900 | }, |
| 2909 | } | 2901 | } |
| 2910 | } | 2902 | } |
| 2911 | 2903 | ||
| 2912 | fn transPredefinedExpr(rp: RestorePoint, scope: *Scope, expr: *const ZigClangPredefinedExpr, used: ResultUsed) TransError!*ast.Node { | 2904 | fn transPredefinedExpr(rp: RestorePoint, scope: *Scope, expr: *const clang.PredefinedExpr, used: ResultUsed) TransError!*ast.Node { |
| 2913 | return transStringLiteral(rp, scope, ZigClangPredefinedExpr_getFunctionName(expr), used); | 2905 | return transStringLiteral(rp, scope, expr.getFunctionName(), used); |
| 2914 | } | 2906 | } |
| 2915 | 2907 | ||
| 2916 | fn transCharLiteral( | 2908 | fn transCharLiteral( |
| 2917 | rp: RestorePoint, | 2909 | rp: RestorePoint, |
| 2918 | scope: *Scope, | 2910 | scope: *Scope, |
| 2919 | stmt: *const ZigClangCharacterLiteral, | 2911 | stmt: *const clang.CharacterLiteral, |
| 2920 | result_used: ResultUsed, | 2912 | result_used: ResultUsed, |
| 2921 | suppress_as: SuppressCast, | 2913 | suppress_as: SuppressCast, |
| 2922 | ) TransError!*ast.Node { | 2914 | ) TransError!*ast.Node { |
| 2923 | const kind = ZigClangCharacterLiteral_getKind(stmt); | 2915 | const kind = stmt.getKind(); |
| 2924 | const int_lit_node = switch (kind) { | 2916 | const int_lit_node = switch (kind) { |
| 2925 | .Ascii, .UTF8 => blk: { | 2917 | .Ascii, .UTF8 => blk: { |
| 2926 | const val = ZigClangCharacterLiteral_getValue(stmt); | 2918 | const val = stmt.getValue(); |
| 2927 | if (kind == .Ascii) { | 2919 | if (kind == .Ascii) { |
| 2928 | // C has a somewhat obscure feature called multi-character character | 2920 | // C has a somewhat obscure feature called multi-character character |
| 2929 | // constant | 2921 | // constant |
| ... | @@ -2942,7 +2934,7 @@ fn transCharLiteral( | ... | @@ -2942,7 +2934,7 @@ fn transCharLiteral( |
| 2942 | .UTF16, .UTF32, .Wide => return revertAndWarn( | 2934 | .UTF16, .UTF32, .Wide => return revertAndWarn( |
| 2943 | rp, | 2935 | rp, |
| 2944 | error.UnsupportedTranslation, | 2936 | error.UnsupportedTranslation, |
| 2945 | ZigClangStmt_getBeginLoc(@ptrCast(*const ZigClangStmt, stmt)), | 2937 | @ptrCast(*const clang.Stmt, stmt).getBeginLoc(), |
| 2946 | "TODO: support character literal kind {}", | 2938 | "TODO: support character literal kind {}", |
| 2947 | .{kind}, | 2939 | .{kind}, |
| 2948 | ), | 2940 | ), |
| ... | @@ -2952,9 +2944,9 @@ fn transCharLiteral( | ... | @@ -2952,9 +2944,9 @@ fn transCharLiteral( |
| 2952 | } | 2944 | } |
| 2953 | // See comment in `transIntegerLiteral` for why this code is here. | 2945 | // See comment in `transIntegerLiteral` for why this code is here. |
| 2954 | // @as(T, x) | 2946 | // @as(T, x) |
| 2955 | const expr_base = @ptrCast(*const ZigClangExpr, stmt); | 2947 | const expr_base = @ptrCast(*const clang.Expr, stmt); |
| 2956 | const as_node = try rp.c.createBuiltinCall("@as", 2); | 2948 | const as_node = try rp.c.createBuiltinCall("@as", 2); |
| 2957 | const ty_node = try transQualType(rp, ZigClangExpr_getType(expr_base), ZigClangExpr_getBeginLoc(expr_base)); | 2949 | const ty_node = try transQualType(rp, expr_base.getType(), expr_base.getBeginLoc()); |
| 2958 | as_node.params()[0] = ty_node; | 2950 | as_node.params()[0] = ty_node; |
| 2959 | _ = try appendToken(rp.c, .Comma, ","); | 2951 | _ = try appendToken(rp.c, .Comma, ","); |
| 2960 | as_node.params()[1] = int_lit_node; | 2952 | as_node.params()[1] = int_lit_node; |
| ... | @@ -2963,8 +2955,8 @@ fn transCharLiteral( | ... | @@ -2963,8 +2955,8 @@ fn transCharLiteral( |
| 2963 | return maybeSuppressResult(rp, scope, result_used, &as_node.base); | 2955 | return maybeSuppressResult(rp, scope, result_used, &as_node.base); |
| 2964 | } | 2956 | } |
| 2965 | 2957 | ||
| 2966 | fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangStmtExpr, used: ResultUsed) TransError!*ast.Node { | 2958 | fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const clang.StmtExpr, used: ResultUsed) TransError!*ast.Node { |
| 2967 | const comp = ZigClangStmtExpr_getSubStmt(stmt); | 2959 | const comp = stmt.getSubStmt(); |
| 2968 | if (used == .unused) { | 2960 | if (used == .unused) { |
| 2969 | return transCompoundStmt(rp, scope, comp); | 2961 | return transCompoundStmt(rp, scope, comp); |
| 2970 | } | 2962 | } |
| ... | @@ -2972,8 +2964,8 @@ fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangStmtExpr, | ... | @@ -2972,8 +2964,8 @@ fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangStmtExpr, |
| 2972 | var block_scope = try Scope.Block.init(rp.c, scope, true); | 2964 | var block_scope = try Scope.Block.init(rp.c, scope, true); |
| 2973 | defer block_scope.deinit(); | 2965 | defer block_scope.deinit(); |
| 2974 | 2966 | ||
| 2975 | var it = ZigClangCompoundStmt_body_begin(comp); | 2967 | var it = comp.body_begin(); |
| 2976 | const end_it = ZigClangCompoundStmt_body_end(comp); | 2968 | const end_it = comp.body_end(); |
| 2977 | while (it != end_it - 1) : (it += 1) { | 2969 | while (it != end_it - 1) : (it += 1) { |
| 2978 | const result = try transStmt(rp, &block_scope.base, it[0], .unused, .r_value); | 2970 | const result = try transStmt(rp, &block_scope.base, it[0], .unused, .r_value); |
| 2979 | try block_scope.statements.append(result); | 2971 | try block_scope.statements.append(result); |
| ... | @@ -2996,43 +2988,43 @@ fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangStmtExpr, | ... | @@ -2996,43 +2988,43 @@ fn transStmtExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangStmtExpr, |
| 2996 | return maybeSuppressResult(rp, scope, used, &grouped_expr.base); | 2988 | return maybeSuppressResult(rp, scope, used, &grouped_expr.base); |
| 2997 | } | 2989 | } |
| 2998 | 2990 | ||
| 2999 | fn transMemberExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangMemberExpr, result_used: ResultUsed) TransError!*ast.Node { | 2991 | fn transMemberExpr(rp: RestorePoint, scope: *Scope, stmt: *const clang.MemberExpr, result_used: ResultUsed) TransError!*ast.Node { |
| 3000 | var container_node = try transExpr(rp, scope, ZigClangMemberExpr_getBase(stmt), .used, .r_value); | 2992 | var container_node = try transExpr(rp, scope, stmt.getBase(), .used, .r_value); |
| 3001 | 2993 | ||
| 3002 | if (ZigClangMemberExpr_isArrow(stmt)) { | 2994 | if (stmt.isArrow()) { |
| 3003 | container_node = try transCreateNodePtrDeref(rp.c, container_node); | 2995 | container_node = try transCreateNodePtrDeref(rp.c, container_node); |
| 3004 | } | 2996 | } |
| 3005 | 2997 | ||
| 3006 | const member_decl = ZigClangMemberExpr_getMemberDecl(stmt); | 2998 | const member_decl = stmt.getMemberDecl(); |
| 3007 | const name = blk: { | 2999 | const name = blk: { |
| 3008 | const decl_kind = ZigClangDecl_getKind(@ptrCast(*const ZigClangDecl, member_decl)); | 3000 | const decl_kind = @ptrCast(*const clang.Decl, member_decl).getKind(); |
| 3009 | // If we're referring to a anonymous struct/enum find the bogus name | 3001 | // If we're referring to a anonymous struct/enum find the bogus name |
| 3010 | // we've assigned to it during the RecordDecl translation | 3002 | // we've assigned to it during the RecordDecl translation |
| 3011 | if (decl_kind == .Field) { | 3003 | if (decl_kind == .Field) { |
| 3012 | const field_decl = @ptrCast(*const struct_ZigClangFieldDecl, member_decl); | 3004 | const field_decl = @ptrCast(*const clang.FieldDecl, member_decl); |
| 3013 | if (ZigClangFieldDecl_isAnonymousStructOrUnion(field_decl)) { | 3005 | if (field_decl.isAnonymousStructOrUnion()) { |
| 3014 | const name = rp.c.decl_table.get(@ptrToInt(ZigClangFieldDecl_getCanonicalDecl(field_decl))).?; | 3006 | const name = rp.c.decl_table.get(@ptrToInt(field_decl.getCanonicalDecl())).?; |
| 3015 | break :blk try mem.dupe(rp.c.arena, u8, name); | 3007 | break :blk try mem.dupe(rp.c.arena, u8, name); |
| 3016 | } | 3008 | } |
| 3017 | } | 3009 | } |
| 3018 | const decl = @ptrCast(*const ZigClangNamedDecl, member_decl); | 3010 | const decl = @ptrCast(*const clang.NamedDecl, member_decl); |
| 3019 | break :blk try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(decl)); | 3011 | break :blk try rp.c.str(decl.getName_bytes_begin()); |
| 3020 | }; | 3012 | }; |
| 3021 | 3013 | ||
| 3022 | const node = try transCreateNodeFieldAccess(rp.c, container_node, name); | 3014 | const node = try transCreateNodeFieldAccess(rp.c, container_node, name); |
| 3023 | return maybeSuppressResult(rp, scope, result_used, node); | 3015 | return maybeSuppressResult(rp, scope, result_used, node); |
| 3024 | } | 3016 | } |
| 3025 | 3017 | ||
| 3026 | fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangArraySubscriptExpr, result_used: ResultUsed) TransError!*ast.Node { | 3018 | fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const clang.ArraySubscriptExpr, result_used: ResultUsed) TransError!*ast.Node { |
| 3027 | var base_stmt = ZigClangArraySubscriptExpr_getBase(stmt); | 3019 | var base_stmt = stmt.getBase(); |
| 3028 | 3020 | ||
| 3029 | // Unwrap the base statement if it's an array decayed to a bare pointer type | 3021 | // Unwrap the base statement if it's an array decayed to a bare pointer type |
| 3030 | // so that we index the array itself | 3022 | // so that we index the array itself |
| 3031 | if (ZigClangStmt_getStmtClass(@ptrCast(*const ZigClangStmt, base_stmt)) == .ImplicitCastExprClass) { | 3023 | if (@ptrCast(*const clang.Stmt, base_stmt).getStmtClass() == .ImplicitCastExprClass) { |
| 3032 | const implicit_cast = @ptrCast(*const ZigClangImplicitCastExpr, base_stmt); | 3024 | const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, base_stmt); |
| 3033 | 3025 | ||
| 3034 | if (ZigClangImplicitCastExpr_getCastKind(implicit_cast) == .ArrayToPointerDecay) { | 3026 | if (implicit_cast.getCastKind() == .ArrayToPointerDecay) { |
| 3035 | base_stmt = ZigClangImplicitCastExpr_getSubExpr(implicit_cast); | 3027 | base_stmt = implicit_cast.getSubExpr(); |
| 3036 | } | 3028 | } |
| 3037 | } | 3029 | } |
| 3038 | 3030 | ||
| ... | @@ -3040,7 +3032,7 @@ fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangArrayS | ... | @@ -3040,7 +3032,7 @@ fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangArrayS |
| 3040 | const node = try transCreateNodeArrayAccess(rp.c, container_node); | 3032 | const node = try transCreateNodeArrayAccess(rp.c, container_node); |
| 3041 | 3033 | ||
| 3042 | // cast if the index is long long or signed | 3034 | // cast if the index is long long or signed |
| 3043 | const subscr_expr = ZigClangArraySubscriptExpr_getIdx(stmt); | 3035 | const subscr_expr = stmt.getIdx(); |
| 3044 | const qt = getExprQualType(rp.c, subscr_expr); | 3036 | const qt = getExprQualType(rp.c, subscr_expr); |
| 3045 | const is_longlong = cIsLongLongInteger(qt); | 3037 | const is_longlong = cIsLongLongInteger(qt); |
| 3046 | const is_signed = cIsSignedInteger(qt); | 3038 | const is_signed = cIsSignedInteger(qt); |
| ... | @@ -3062,23 +3054,23 @@ fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangArrayS | ... | @@ -3062,23 +3054,23 @@ fn transArrayAccess(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangArrayS |
| 3062 | return maybeSuppressResult(rp, scope, result_used, &node.base); | 3054 | return maybeSuppressResult(rp, scope, result_used, &node.base); |
| 3063 | } | 3055 | } |
| 3064 | 3056 | ||
| 3065 | fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, result_used: ResultUsed) TransError!*ast.Node { | 3057 | fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const clang.CallExpr, result_used: ResultUsed) TransError!*ast.Node { |
| 3066 | const callee = ZigClangCallExpr_getCallee(stmt); | 3058 | const callee = stmt.getCallee(); |
| 3067 | var raw_fn_expr = try transExpr(rp, scope, callee, .used, .r_value); | 3059 | var raw_fn_expr = try transExpr(rp, scope, callee, .used, .r_value); |
| 3068 | 3060 | ||
| 3069 | var is_ptr = false; | 3061 | var is_ptr = false; |
| 3070 | const fn_ty = qualTypeGetFnProto(ZigClangExpr_getType(callee), &is_ptr); | 3062 | const fn_ty = qualTypeGetFnProto(callee.getType(), &is_ptr); |
| 3071 | 3063 | ||
| 3072 | const fn_expr = if (is_ptr and fn_ty != null) blk: { | 3064 | const fn_expr = if (is_ptr and fn_ty != null) blk: { |
| 3073 | if (ZigClangExpr_getStmtClass(callee) == .ImplicitCastExprClass) { | 3065 | if (callee.getStmtClass() == .ImplicitCastExprClass) { |
| 3074 | const implicit_cast = @ptrCast(*const ZigClangImplicitCastExpr, callee); | 3066 | const implicit_cast = @ptrCast(*const clang.ImplicitCastExpr, callee); |
| 3075 | 3067 | ||
| 3076 | if (ZigClangImplicitCastExpr_getCastKind(implicit_cast) == .FunctionToPointerDecay) { | 3068 | if (implicit_cast.getCastKind() == .FunctionToPointerDecay) { |
| 3077 | const subexpr = ZigClangImplicitCastExpr_getSubExpr(implicit_cast); | 3069 | const subexpr = implicit_cast.getSubExpr(); |
| 3078 | if (ZigClangExpr_getStmtClass(subexpr) == .DeclRefExprClass) { | 3070 | if (subexpr.getStmtClass() == .DeclRefExprClass) { |
| 3079 | const decl_ref = @ptrCast(*const ZigClangDeclRefExpr, subexpr); | 3071 | const decl_ref = @ptrCast(*const clang.DeclRefExpr, subexpr); |
| 3080 | const named_decl = ZigClangDeclRefExpr_getFoundDecl(decl_ref); | 3072 | const named_decl = decl_ref.getFoundDecl(); |
| 3081 | if (ZigClangDecl_getKind(@ptrCast(*const ZigClangDecl, named_decl)) == .Function) { | 3073 | if (@ptrCast(*const clang.Decl, named_decl).getKind() == .Function) { |
| 3082 | break :blk raw_fn_expr; | 3074 | break :blk raw_fn_expr; |
| 3083 | } | 3075 | } |
| 3084 | } | 3076 | } |
| ... | @@ -3088,11 +3080,11 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, | ... | @@ -3088,11 +3080,11 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, |
| 3088 | } else | 3080 | } else |
| 3089 | raw_fn_expr; | 3081 | raw_fn_expr; |
| 3090 | 3082 | ||
| 3091 | const num_args = ZigClangCallExpr_getNumArgs(stmt); | 3083 | const num_args = stmt.getNumArgs(); |
| 3092 | const node = try rp.c.createCall(fn_expr, num_args); | 3084 | const node = try rp.c.createCall(fn_expr, num_args); |
| 3093 | const call_params = node.params(); | 3085 | const call_params = node.params(); |
| 3094 | 3086 | ||
| 3095 | const args = ZigClangCallExpr_getArgs(stmt); | 3087 | const args = stmt.getArgs(); |
| 3096 | var i: usize = 0; | 3088 | var i: usize = 0; |
| 3097 | while (i < num_args) : (i += 1) { | 3089 | while (i < num_args) : (i += 1) { |
| 3098 | if (i != 0) { | 3090 | if (i != 0) { |
| ... | @@ -3103,9 +3095,9 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, | ... | @@ -3103,9 +3095,9 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, |
| 3103 | node.rtoken = try appendToken(rp.c, .RParen, ")"); | 3095 | node.rtoken = try appendToken(rp.c, .RParen, ")"); |
| 3104 | 3096 | ||
| 3105 | if (fn_ty) |ty| { | 3097 | if (fn_ty) |ty| { |
| 3106 | const canon = ZigClangQualType_getCanonicalType(ty.getReturnType()); | 3098 | const canon = ty.getReturnType().getCanonicalType(); |
| 3107 | const ret_ty = ZigClangQualType_getTypePtr(canon); | 3099 | const ret_ty = canon.getTypePtr(); |
| 3108 | if (ZigClangType_isVoidType(ret_ty)) { | 3100 | if (ret_ty.isVoidType()) { |
| 3109 | _ = try appendToken(rp.c, .Semicolon, ";"); | 3101 | _ = try appendToken(rp.c, .Semicolon, ";"); |
| 3110 | return &node.base; | 3102 | return &node.base; |
| 3111 | } | 3103 | } |
| ... | @@ -3115,32 +3107,32 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, | ... | @@ -3115,32 +3107,32 @@ fn transCallExpr(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCallExpr, |
| 3115 | } | 3107 | } |
| 3116 | 3108 | ||
| 3117 | const ClangFunctionType = union(enum) { | 3109 | const ClangFunctionType = union(enum) { |
| 3118 | Proto: *const ZigClangFunctionProtoType, | 3110 | Proto: *const clang.FunctionProtoType, |
| 3119 | NoProto: *const ZigClangFunctionType, | 3111 | NoProto: *const clang.FunctionType, |
| 3120 | 3112 | ||
| 3121 | fn getReturnType(self: @This()) ZigClangQualType { | 3113 | fn getReturnType(self: @This()) clang.QualType { |
| 3122 | switch (@as(@TagType(@This()), self)) { | 3114 | switch (@as(@TagType(@This()), self)) { |
| 3123 | .Proto => return ZigClangFunctionProtoType_getReturnType(self.Proto), | 3115 | .Proto => return self.Proto.getReturnType(), |
| 3124 | .NoProto => return ZigClangFunctionType_getReturnType(self.NoProto), | 3116 | .NoProto => return self.NoProto.getReturnType(), |
| 3125 | } | 3117 | } |
| 3126 | } | 3118 | } |
| 3127 | }; | 3119 | }; |
| 3128 | 3120 | ||
| 3129 | fn qualTypeGetFnProto(qt: ZigClangQualType, is_ptr: *bool) ?ClangFunctionType { | 3121 | fn qualTypeGetFnProto(qt: clang.QualType, is_ptr: *bool) ?ClangFunctionType { |
| 3130 | const canon = ZigClangQualType_getCanonicalType(qt); | 3122 | const canon = qt.getCanonicalType(); |
| 3131 | var ty = ZigClangQualType_getTypePtr(canon); | 3123 | var ty = canon.getTypePtr(); |
| 3132 | is_ptr.* = false; | 3124 | is_ptr.* = false; |
| 3133 | 3125 | ||
| 3134 | if (ZigClangType_getTypeClass(ty) == .Pointer) { | 3126 | if (ty.getTypeClass() == .Pointer) { |
| 3135 | is_ptr.* = true; | 3127 | is_ptr.* = true; |
| 3136 | const child_qt = ZigClangType_getPointeeType(ty); | 3128 | const child_qt = ty.getPointeeType(); |
| 3137 | ty = ZigClangQualType_getTypePtr(child_qt); | 3129 | ty = child_qt.getTypePtr(); |
| 3138 | } | 3130 | } |
| 3139 | if (ZigClangType_getTypeClass(ty) == .FunctionProto) { | 3131 | if (ty.getTypeClass() == .FunctionProto) { |
| 3140 | return ClangFunctionType{ .Proto = @ptrCast(*const ZigClangFunctionProtoType, ty) }; | 3132 | return ClangFunctionType{ .Proto = @ptrCast(*const clang.FunctionProtoType, ty) }; |
| 3141 | } | 3133 | } |
| 3142 | if (ZigClangType_getTypeClass(ty) == .FunctionNoProto) { | 3134 | if (ty.getTypeClass() == .FunctionNoProto) { |
| 3143 | return ClangFunctionType{ .NoProto = @ptrCast(*const ZigClangFunctionType, ty) }; | 3135 | return ClangFunctionType{ .NoProto = @ptrCast(*const clang.FunctionType, ty) }; |
| 3144 | } | 3136 | } |
| 3145 | return null; | 3137 | return null; |
| 3146 | } | 3138 | } |
| ... | @@ -3148,17 +3140,17 @@ fn qualTypeGetFnProto(qt: ZigClangQualType, is_ptr: *bool) ?ClangFunctionType { | ... | @@ -3148,17 +3140,17 @@ fn qualTypeGetFnProto(qt: ZigClangQualType, is_ptr: *bool) ?ClangFunctionType { |
| 3148 | fn transUnaryExprOrTypeTraitExpr( | 3140 | fn transUnaryExprOrTypeTraitExpr( |
| 3149 | rp: RestorePoint, | 3141 | rp: RestorePoint, |
| 3150 | scope: *Scope, | 3142 | scope: *Scope, |
| 3151 | stmt: *const ZigClangUnaryExprOrTypeTraitExpr, | 3143 | stmt: *const clang.UnaryExprOrTypeTraitExpr, |
| 3152 | result_used: ResultUsed, | 3144 | result_used: ResultUsed, |
| 3153 | ) TransError!*ast.Node { | 3145 | ) TransError!*ast.Node { |
| 3154 | const loc = ZigClangUnaryExprOrTypeTraitExpr_getBeginLoc(stmt); | 3146 | const loc = stmt.getBeginLoc(); |
| 3155 | const type_node = try transQualType( | 3147 | const type_node = try transQualType( |
| 3156 | rp, | 3148 | rp, |
| 3157 | ZigClangUnaryExprOrTypeTraitExpr_getTypeOfArgument(stmt), | 3149 | stmt.getTypeOfArgument(), |
| 3158 | loc, | 3150 | loc, |
| 3159 | ); | 3151 | ); |
| 3160 | 3152 | ||
| 3161 | const kind = ZigClangUnaryExprOrTypeTraitExpr_getKind(stmt); | 3153 | const kind = stmt.getKind(); |
| 3162 | const kind_str = switch (kind) { | 3154 | const kind_str = switch (kind) { |
| 3163 | .SizeOf => "@sizeOf", | 3155 | .SizeOf => "@sizeOf", |
| 3164 | .AlignOf => "@alignOf", | 3156 | .AlignOf => "@alignOf", |
| ... | @@ -3180,7 +3172,7 @@ fn transUnaryExprOrTypeTraitExpr( | ... | @@ -3180,7 +3172,7 @@ fn transUnaryExprOrTypeTraitExpr( |
| 3180 | return maybeSuppressResult(rp, scope, result_used, &builtin_node.base); | 3172 | return maybeSuppressResult(rp, scope, result_used, &builtin_node.base); |
| 3181 | } | 3173 | } |
| 3182 | 3174 | ||
| 3183 | fn qualTypeHasWrappingOverflow(qt: ZigClangQualType) bool { | 3175 | fn qualTypeHasWrappingOverflow(qt: clang.QualType) bool { |
| 3184 | if (cIsUnsignedInteger(qt)) { | 3176 | if (cIsUnsignedInteger(qt)) { |
| 3185 | // unsigned integer overflow wraps around. | 3177 | // unsigned integer overflow wraps around. |
| 3186 | return true; | 3178 | return true; |
| ... | @@ -3190,22 +3182,22 @@ fn qualTypeHasWrappingOverflow(qt: ZigClangQualType) bool { | ... | @@ -3190,22 +3182,22 @@ fn qualTypeHasWrappingOverflow(qt: ZigClangQualType) bool { |
| 3190 | } | 3182 | } |
| 3191 | } | 3183 | } |
| 3192 | 3184 | ||
| 3193 | fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnaryOperator, used: ResultUsed) TransError!*ast.Node { | 3185 | fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const clang.UnaryOperator, used: ResultUsed) TransError!*ast.Node { |
| 3194 | const op_expr = ZigClangUnaryOperator_getSubExpr(stmt); | 3186 | const op_expr = stmt.getSubExpr(); |
| 3195 | switch (ZigClangUnaryOperator_getOpcode(stmt)) { | 3187 | switch (stmt.getOpcode()) { |
| 3196 | .PostInc => if (qualTypeHasWrappingOverflow(ZigClangUnaryOperator_getType(stmt))) | 3188 | .PostInc => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3197 | return transCreatePostCrement(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", used) | 3189 | return transCreatePostCrement(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", used) |
| 3198 | else | 3190 | else |
| 3199 | return transCreatePostCrement(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", used), | 3191 | return transCreatePostCrement(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", used), |
| 3200 | .PostDec => if (qualTypeHasWrappingOverflow(ZigClangUnaryOperator_getType(stmt))) | 3192 | .PostDec => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3201 | return transCreatePostCrement(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", used) | 3193 | return transCreatePostCrement(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", used) |
| 3202 | else | 3194 | else |
| 3203 | return transCreatePostCrement(rp, scope, stmt, .AssignSub, .MinusEqual, "-=", used), | 3195 | return transCreatePostCrement(rp, scope, stmt, .AssignSub, .MinusEqual, "-=", used), |
| 3204 | .PreInc => if (qualTypeHasWrappingOverflow(ZigClangUnaryOperator_getType(stmt))) | 3196 | .PreInc => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3205 | return transCreatePreCrement(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", used) | 3197 | return transCreatePreCrement(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", used) |
| 3206 | else | 3198 | else |
| 3207 | return transCreatePreCrement(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", used), | 3199 | return transCreatePreCrement(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", used), |
| 3208 | .PreDec => if (qualTypeHasWrappingOverflow(ZigClangUnaryOperator_getType(stmt))) | 3200 | .PreDec => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3209 | return transCreatePreCrement(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", used) | 3201 | return transCreatePreCrement(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", used) |
| 3210 | else | 3202 | else |
| 3211 | return transCreatePreCrement(rp, scope, stmt, .AssignSub, .MinusEqual, "-=", used), | 3203 | return transCreatePreCrement(rp, scope, stmt, .AssignSub, .MinusEqual, "-=", used), |
| ... | @@ -3217,7 +3209,7 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar | ... | @@ -3217,7 +3209,7 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar |
| 3217 | .Deref => { | 3209 | .Deref => { |
| 3218 | const value_node = try transExpr(rp, scope, op_expr, used, .r_value); | 3210 | const value_node = try transExpr(rp, scope, op_expr, used, .r_value); |
| 3219 | var is_ptr = false; | 3211 | var is_ptr = false; |
| 3220 | const fn_ty = qualTypeGetFnProto(ZigClangExpr_getType(op_expr), &is_ptr); | 3212 | const fn_ty = qualTypeGetFnProto(op_expr.getType(), &is_ptr); |
| 3221 | if (fn_ty != null and is_ptr) | 3213 | if (fn_ty != null and is_ptr) |
| 3222 | return value_node; | 3214 | return value_node; |
| 3223 | const unwrapped = try transCreateNodeUnwrapNull(rp.c, value_node); | 3215 | const unwrapped = try transCreateNodeUnwrapNull(rp.c, value_node); |
| ... | @@ -3225,18 +3217,18 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar | ... | @@ -3225,18 +3217,18 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar |
| 3225 | }, | 3217 | }, |
| 3226 | .Plus => return transExpr(rp, scope, op_expr, used, .r_value), | 3218 | .Plus => return transExpr(rp, scope, op_expr, used, .r_value), |
| 3227 | .Minus => { | 3219 | .Minus => { |
| 3228 | if (!qualTypeHasWrappingOverflow(ZigClangExpr_getType(op_expr))) { | 3220 | if (!qualTypeHasWrappingOverflow(op_expr.getType())) { |
| 3229 | const op_node = try transCreateNodeSimplePrefixOp(rp.c, .Negation, .Minus, "-"); | 3221 | const op_node = try transCreateNodeSimplePrefixOp(rp.c, .Negation, .Minus, "-"); |
| 3230 | op_node.rhs = try transExpr(rp, scope, op_expr, .used, .r_value); | 3222 | op_node.rhs = try transExpr(rp, scope, op_expr, .used, .r_value); |
| 3231 | return &op_node.base; | 3223 | return &op_node.base; |
| 3232 | } else if (cIsUnsignedInteger(ZigClangExpr_getType(op_expr))) { | 3224 | } else if (cIsUnsignedInteger(op_expr.getType())) { |
| 3233 | // we gotta emit 0 -% x | 3225 | // we gotta emit 0 -% x |
| 3234 | const zero = try transCreateNodeInt(rp.c, 0); | 3226 | const zero = try transCreateNodeInt(rp.c, 0); |
| 3235 | const token = try appendToken(rp.c, .MinusPercent, "-%"); | 3227 | const token = try appendToken(rp.c, .MinusPercent, "-%"); |
| 3236 | const expr = try transExpr(rp, scope, op_expr, .used, .r_value); | 3228 | const expr = try transExpr(rp, scope, op_expr, .used, .r_value); |
| 3237 | return transCreateNodeInfixOp(rp, scope, zero, .SubWrap, token, expr, used, true); | 3229 | return transCreateNodeInfixOp(rp, scope, zero, .SubWrap, token, expr, used, true); |
| 3238 | } else | 3230 | } else |
| 3239 | return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangUnaryOperator_getBeginLoc(stmt), "C negation with non float non integer", .{}); | 3231 | return revertAndWarn(rp, error.UnsupportedTranslation, stmt.getBeginLoc(), "C negation with non float non integer", .{}); |
| 3240 | }, | 3232 | }, |
| 3241 | .Not => { | 3233 | .Not => { |
| 3242 | const op_node = try transCreateNodeSimplePrefixOp(rp.c, .BitNot, .Tilde, "~"); | 3234 | const op_node = try transCreateNodeSimplePrefixOp(rp.c, .BitNot, .Tilde, "~"); |
| ... | @@ -3249,22 +3241,22 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar | ... | @@ -3249,22 +3241,22 @@ fn transUnaryOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangUnar |
| 3249 | return &op_node.base; | 3241 | return &op_node.base; |
| 3250 | }, | 3242 | }, |
| 3251 | .Extension => { | 3243 | .Extension => { |
| 3252 | return transExpr(rp, scope, ZigClangUnaryOperator_getSubExpr(stmt), used, .l_value); | 3244 | return transExpr(rp, scope, stmt.getSubExpr(), used, .l_value); |
| 3253 | }, | 3245 | }, |
| 3254 | else => return revertAndWarn(rp, error.UnsupportedTranslation, ZigClangUnaryOperator_getBeginLoc(stmt), "unsupported C translation {}", .{ZigClangUnaryOperator_getOpcode(stmt)}), | 3246 | else => return revertAndWarn(rp, error.UnsupportedTranslation, stmt.getBeginLoc(), "unsupported C translation {}", .{stmt.getOpcode()}), |
| 3255 | } | 3247 | } |
| 3256 | } | 3248 | } |
| 3257 | 3249 | ||
| 3258 | fn transCreatePreCrement( | 3250 | fn transCreatePreCrement( |
| 3259 | rp: RestorePoint, | 3251 | rp: RestorePoint, |
| 3260 | scope: *Scope, | 3252 | scope: *Scope, |
| 3261 | stmt: *const ZigClangUnaryOperator, | 3253 | stmt: *const clang.UnaryOperator, |
| 3262 | op: ast.Node.Tag, | 3254 | op: ast.Node.Tag, |
| 3263 | op_tok_id: std.zig.Token.Id, | 3255 | op_tok_id: std.zig.Token.Id, |
| 3264 | bytes: []const u8, | 3256 | bytes: []const u8, |
| 3265 | used: ResultUsed, | 3257 | used: ResultUsed, |
| 3266 | ) TransError!*ast.Node { | 3258 | ) TransError!*ast.Node { |
| 3267 | const op_expr = ZigClangUnaryOperator_getSubExpr(stmt); | 3259 | const op_expr = stmt.getSubExpr(); |
| 3268 | 3260 | ||
| 3269 | if (used == .unused) { | 3261 | if (used == .unused) { |
| 3270 | // common case | 3262 | // common case |
| ... | @@ -3331,13 +3323,13 @@ fn transCreatePreCrement( | ... | @@ -3331,13 +3323,13 @@ fn transCreatePreCrement( |
| 3331 | fn transCreatePostCrement( | 3323 | fn transCreatePostCrement( |
| 3332 | rp: RestorePoint, | 3324 | rp: RestorePoint, |
| 3333 | scope: *Scope, | 3325 | scope: *Scope, |
| 3334 | stmt: *const ZigClangUnaryOperator, | 3326 | stmt: *const clang.UnaryOperator, |
| 3335 | op: ast.Node.Tag, | 3327 | op: ast.Node.Tag, |
| 3336 | op_tok_id: std.zig.Token.Id, | 3328 | op_tok_id: std.zig.Token.Id, |
| 3337 | bytes: []const u8, | 3329 | bytes: []const u8, |
| 3338 | used: ResultUsed, | 3330 | used: ResultUsed, |
| 3339 | ) TransError!*ast.Node { | 3331 | ) TransError!*ast.Node { |
| 3340 | const op_expr = ZigClangUnaryOperator_getSubExpr(stmt); | 3332 | const op_expr = stmt.getSubExpr(); |
| 3341 | 3333 | ||
| 3342 | if (used == .unused) { | 3334 | if (used == .unused) { |
| 3343 | // common case | 3335 | // common case |
| ... | @@ -3422,17 +3414,17 @@ fn transCreatePostCrement( | ... | @@ -3422,17 +3414,17 @@ fn transCreatePostCrement( |
| 3422 | return &grouped_expr.base; | 3414 | return &grouped_expr.base; |
| 3423 | } | 3415 | } |
| 3424 | 3416 | ||
| 3425 | fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompoundAssignOperator, used: ResultUsed) TransError!*ast.Node { | 3417 | fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const clang.CompoundAssignOperator, used: ResultUsed) TransError!*ast.Node { |
| 3426 | switch (ZigClangCompoundAssignOperator_getOpcode(stmt)) { | 3418 | switch (stmt.getOpcode()) { |
| 3427 | .MulAssign => if (qualTypeHasWrappingOverflow(ZigClangCompoundAssignOperator_getType(stmt))) | 3419 | .MulAssign => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3428 | return transCreateCompoundAssign(rp, scope, stmt, .AssignMulWrap, .AsteriskPercentEqual, "*%=", .MulWrap, .AsteriskPercent, "*%", used) | 3420 | return transCreateCompoundAssign(rp, scope, stmt, .AssignMulWrap, .AsteriskPercentEqual, "*%=", .MulWrap, .AsteriskPercent, "*%", used) |
| 3429 | else | 3421 | else |
| 3430 | return transCreateCompoundAssign(rp, scope, stmt, .AssignMul, .AsteriskEqual, "*=", .Mul, .Asterisk, "*", used), | 3422 | return transCreateCompoundAssign(rp, scope, stmt, .AssignMul, .AsteriskEqual, "*=", .Mul, .Asterisk, "*", used), |
| 3431 | .AddAssign => if (qualTypeHasWrappingOverflow(ZigClangCompoundAssignOperator_getType(stmt))) | 3423 | .AddAssign => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3432 | return transCreateCompoundAssign(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", .AddWrap, .PlusPercent, "+%", used) | 3424 | return transCreateCompoundAssign(rp, scope, stmt, .AssignAddWrap, .PlusPercentEqual, "+%=", .AddWrap, .PlusPercent, "+%", used) |
| 3433 | else | 3425 | else |
| 3434 | return transCreateCompoundAssign(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", .Add, .Plus, "+", used), | 3426 | return transCreateCompoundAssign(rp, scope, stmt, .AssignAdd, .PlusEqual, "+=", .Add, .Plus, "+", used), |
| 3435 | .SubAssign => if (qualTypeHasWrappingOverflow(ZigClangCompoundAssignOperator_getType(stmt))) | 3427 | .SubAssign => if (qualTypeHasWrappingOverflow(stmt.getType())) |
| 3436 | return transCreateCompoundAssign(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", .SubWrap, .MinusPercent, "-%", used) | 3428 | return transCreateCompoundAssign(rp, scope, stmt, .AssignSubWrap, .MinusPercentEqual, "-%=", .SubWrap, .MinusPercent, "-%", used) |
| 3437 | else | 3429 | else |
| 3438 | return transCreateCompoundAssign(rp, scope, stmt, .AssignSub, .MinusPercentEqual, "-=", .Sub, .Minus, "-", used), | 3430 | return transCreateCompoundAssign(rp, scope, stmt, .AssignSub, .MinusPercentEqual, "-=", .Sub, .Minus, "-", used), |
| ... | @@ -3446,9 +3438,9 @@ fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const Zig | ... | @@ -3446,9 +3438,9 @@ fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const Zig |
| 3446 | else => return revertAndWarn( | 3438 | else => return revertAndWarn( |
| 3447 | rp, | 3439 | rp, |
| 3448 | error.UnsupportedTranslation, | 3440 | error.UnsupportedTranslation, |
| 3449 | ZigClangCompoundAssignOperator_getBeginLoc(stmt), | 3441 | stmt.getBeginLoc(), |
| 3450 | "unsupported C translation {}", | 3442 | "unsupported C translation {}", |
| 3451 | .{ZigClangCompoundAssignOperator_getOpcode(stmt)}, | 3443 | .{stmt.getOpcode()}, |
| 3452 | ), | 3444 | ), |
| 3453 | } | 3445 | } |
| 3454 | } | 3446 | } |
| ... | @@ -3456,7 +3448,7 @@ fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const Zig | ... | @@ -3456,7 +3448,7 @@ fn transCompoundAssignOperator(rp: RestorePoint, scope: *Scope, stmt: *const Zig |
| 3456 | fn transCreateCompoundAssign( | 3448 | fn transCreateCompoundAssign( |
| 3457 | rp: RestorePoint, | 3449 | rp: RestorePoint, |
| 3458 | scope: *Scope, | 3450 | scope: *Scope, |
| 3459 | stmt: *const ZigClangCompoundAssignOperator, | 3451 | stmt: *const clang.CompoundAssignOperator, |
| 3460 | assign_op: ast.Node.Tag, | 3452 | assign_op: ast.Node.Tag, |
| 3461 | assign_tok_id: std.zig.Token.Id, | 3453 | assign_tok_id: std.zig.Token.Id, |
| 3462 | assign_bytes: []const u8, | 3454 | assign_bytes: []const u8, |
| ... | @@ -3468,9 +3460,9 @@ fn transCreateCompoundAssign( | ... | @@ -3468,9 +3460,9 @@ fn transCreateCompoundAssign( |
| 3468 | const is_shift = bin_op == .BitShiftLeft or bin_op == .BitShiftRight; | 3460 | const is_shift = bin_op == .BitShiftLeft or bin_op == .BitShiftRight; |
| 3469 | const is_div = bin_op == .Div; | 3461 | const is_div = bin_op == .Div; |
| 3470 | const is_mod = bin_op == .Mod; | 3462 | const is_mod = bin_op == .Mod; |
| 3471 | const lhs = ZigClangCompoundAssignOperator_getLHS(stmt); | 3463 | const lhs = stmt.getLHS(); |
| 3472 | const rhs = ZigClangCompoundAssignOperator_getRHS(stmt); | 3464 | const rhs = stmt.getRHS(); |
| 3473 | const loc = ZigClangCompoundAssignOperator_getBeginLoc(stmt); | 3465 | const loc = stmt.getBeginLoc(); |
| 3474 | const lhs_qt = getExprQualType(rp.c, lhs); | 3466 | const lhs_qt = getExprQualType(rp.c, lhs); |
| 3475 | const rhs_qt = getExprQualType(rp.c, rhs); | 3467 | const rhs_qt = getExprQualType(rp.c, rhs); |
| 3476 | const is_signed = cIsSignedInteger(lhs_qt); | 3468 | const is_signed = cIsSignedInteger(lhs_qt); |
| ... | @@ -3615,20 +3607,20 @@ fn transCreateCompoundAssign( | ... | @@ -3615,20 +3607,20 @@ fn transCreateCompoundAssign( |
| 3615 | 3607 | ||
| 3616 | fn transCPtrCast( | 3608 | fn transCPtrCast( |
| 3617 | rp: RestorePoint, | 3609 | rp: RestorePoint, |
| 3618 | loc: ZigClangSourceLocation, | 3610 | loc: clang.SourceLocation, |
| 3619 | dst_type: ZigClangQualType, | 3611 | dst_type: clang.QualType, |
| 3620 | src_type: ZigClangQualType, | 3612 | src_type: clang.QualType, |
| 3621 | expr: *ast.Node, | 3613 | expr: *ast.Node, |
| 3622 | ) !*ast.Node { | 3614 | ) !*ast.Node { |
| 3623 | const ty = ZigClangQualType_getTypePtr(dst_type); | 3615 | const ty = dst_type.getTypePtr(); |
| 3624 | const child_type = ZigClangType_getPointeeType(ty); | 3616 | const child_type = ty.getPointeeType(); |
| 3625 | const src_ty = ZigClangQualType_getTypePtr(src_type); | 3617 | const src_ty = src_type.getTypePtr(); |
| 3626 | const src_child_type = ZigClangType_getPointeeType(src_ty); | 3618 | const src_child_type = src_ty.getPointeeType(); |
| 3627 | 3619 | ||
| 3628 | if ((ZigClangQualType_isConstQualified(src_child_type) and | 3620 | if ((src_child_type.isConstQualified() and |
| 3629 | !ZigClangQualType_isConstQualified(child_type)) or | 3621 | !child_type.isConstQualified()) or |
| 3630 | (ZigClangQualType_isVolatileQualified(src_child_type) and | 3622 | (src_child_type.isVolatileQualified() and |
| 3631 | !ZigClangQualType_isVolatileQualified(child_type))) | 3623 | !child_type.isVolatileQualified())) |
| 3632 | { | 3624 | { |
| 3633 | // Casting away const or volatile requires us to use @intToPtr | 3625 | // Casting away const or volatile requires us to use @intToPtr |
| 3634 | const inttoptr_node = try rp.c.createBuiltinCall("@intToPtr", 2); | 3626 | const inttoptr_node = try rp.c.createBuiltinCall("@intToPtr", 2); |
| ... | @@ -3651,7 +3643,7 @@ fn transCPtrCast( | ... | @@ -3651,7 +3643,7 @@ fn transCPtrCast( |
| 3651 | ptrcast_node.params()[0] = dst_type_node; | 3643 | ptrcast_node.params()[0] = dst_type_node; |
| 3652 | _ = try appendToken(rp.c, .Comma, ","); | 3644 | _ = try appendToken(rp.c, .Comma, ","); |
| 3653 | 3645 | ||
| 3654 | if (ZigClangType_isVoidType(qualTypeCanon(child_type))) { | 3646 | if (qualTypeCanon(child_type).isVoidType()) { |
| 3655 | // void has 1-byte alignment, so @alignCast is not needed | 3647 | // void has 1-byte alignment, so @alignCast is not needed |
| 3656 | ptrcast_node.params()[1] = expr; | 3648 | ptrcast_node.params()[1] = expr; |
| 3657 | } else if (typeIsOpaque(rp.c, qualTypeCanon(child_type), loc)) { | 3649 | } else if (typeIsOpaque(rp.c, qualTypeCanon(child_type), loc)) { |
| ... | @@ -3691,9 +3683,9 @@ fn transBreak(rp: RestorePoint, scope: *Scope) TransError!*ast.Node { | ... | @@ -3691,9 +3683,9 @@ fn transBreak(rp: RestorePoint, scope: *Scope) TransError!*ast.Node { |
| 3691 | return &br.base; | 3683 | return &br.base; |
| 3692 | } | 3684 | } |
| 3693 | 3685 | ||
| 3694 | fn transFloatingLiteral(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangFloatingLiteral, used: ResultUsed) TransError!*ast.Node { | 3686 | fn transFloatingLiteral(rp: RestorePoint, scope: *Scope, stmt: *const clang.FloatingLiteral, used: ResultUsed) TransError!*ast.Node { |
| 3695 | // TODO use something more accurate | 3687 | // TODO use something more accurate |
| 3696 | const dbl = ZigClangAPFloat_getValueAsApproximateDouble(stmt); | 3688 | const dbl = stmt.getValueAsApproximateDouble(); |
| 3697 | const node = try rp.c.arena.create(ast.Node.OneToken); | 3689 | const node = try rp.c.arena.create(ast.Node.OneToken); |
| 3698 | node.* = .{ | 3690 | node.* = .{ |
| 3699 | .base = .{ .tag = .FloatLiteral }, | 3691 | .base = .{ .tag = .FloatLiteral }, |
| ... | @@ -3702,13 +3694,13 @@ fn transFloatingLiteral(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangFl | ... | @@ -3702,13 +3694,13 @@ fn transFloatingLiteral(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangFl |
| 3702 | return maybeSuppressResult(rp, scope, used, &node.base); | 3694 | return maybeSuppressResult(rp, scope, used, &node.base); |
| 3703 | } | 3695 | } |
| 3704 | 3696 | ||
| 3705 | fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangBinaryConditionalOperator, used: ResultUsed) TransError!*ast.Node { | 3697 | fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const clang.BinaryConditionalOperator, used: ResultUsed) TransError!*ast.Node { |
| 3706 | // GNU extension of the ternary operator where the middle expression is | 3698 | // GNU extension of the ternary operator where the middle expression is |
| 3707 | // omitted, the conditition itself is returned if it evaluates to true | 3699 | // omitted, the conditition itself is returned if it evaluates to true |
| 3708 | const casted_stmt = @ptrCast(*const ZigClangAbstractConditionalOperator, stmt); | 3700 | const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt); |
| 3709 | const cond_expr = ZigClangAbstractConditionalOperator_getCond(casted_stmt); | 3701 | const cond_expr = casted_stmt.getCond(); |
| 3710 | const true_expr = ZigClangAbstractConditionalOperator_getTrueExpr(casted_stmt); | 3702 | const true_expr = casted_stmt.getTrueExpr(); |
| 3711 | const false_expr = ZigClangAbstractConditionalOperator_getFalseExpr(casted_stmt); | 3703 | const false_expr = casted_stmt.getFalseExpr(); |
| 3712 | 3704 | ||
| 3713 | // c: (cond_expr)?:(false_expr) | 3705 | // c: (cond_expr)?:(false_expr) |
| 3714 | // zig: (blk: { | 3706 | // zig: (blk: { |
| ... | @@ -3748,8 +3740,8 @@ fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const | ... | @@ -3748,8 +3740,8 @@ fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const |
| 3748 | defer cond_scope.deinit(); | 3740 | defer cond_scope.deinit(); |
| 3749 | const tmp_var_node = try transCreateNodeIdentifier(rp.c, mangled_name); | 3741 | const tmp_var_node = try transCreateNodeIdentifier(rp.c, mangled_name); |
| 3750 | 3742 | ||
| 3751 | const ty = ZigClangQualType_getTypePtr(getExprQualType(rp.c, cond_expr)); | 3743 | const ty = getExprQualType(rp.c, cond_expr).getTypePtr(); |
| 3752 | const cond_node = try finishBoolExpr(rp, &cond_scope.base, ZigClangExpr_getBeginLoc(cond_expr), ty, tmp_var_node, used); | 3744 | const cond_node = try finishBoolExpr(rp, &cond_scope.base, cond_expr.getBeginLoc(), ty, tmp_var_node, used); |
| 3753 | if_node.condition = cond_node; | 3745 | if_node.condition = cond_node; |
| 3754 | _ = try appendToken(rp.c, .RParen, ")"); | 3746 | _ = try appendToken(rp.c, .RParen, ")"); |
| 3755 | 3747 | ||
| ... | @@ -3772,7 +3764,7 @@ fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const | ... | @@ -3772,7 +3764,7 @@ fn transBinaryConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const |
| 3772 | return maybeSuppressResult(rp, scope, used, &grouped_expr.base); | 3764 | return maybeSuppressResult(rp, scope, used, &grouped_expr.base); |
| 3773 | } | 3765 | } |
| 3774 | 3766 | ||
| 3775 | fn transConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangConditionalOperator, used: ResultUsed) TransError!*ast.Node { | 3767 | fn transConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const clang.ConditionalOperator, used: ResultUsed) TransError!*ast.Node { |
| 3776 | const grouped = scope.id == .Condition; | 3768 | const grouped = scope.id == .Condition; |
| 3777 | const lparen = if (grouped) try appendToken(rp.c, .LParen, "(") else undefined; | 3769 | const lparen = if (grouped) try appendToken(rp.c, .LParen, "(") else undefined; |
| 3778 | const if_node = try transCreateNodeIf(rp.c); | 3770 | const if_node = try transCreateNodeIf(rp.c); |
| ... | @@ -3784,10 +3776,10 @@ fn transConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigCla | ... | @@ -3784,10 +3776,10 @@ fn transConditionalOperator(rp: RestorePoint, scope: *Scope, stmt: *const ZigCla |
| 3784 | }; | 3776 | }; |
| 3785 | defer cond_scope.deinit(); | 3777 | defer cond_scope.deinit(); |
| 3786 | 3778 | ||
| 3787 | const casted_stmt = @ptrCast(*const ZigClangAbstractConditionalOperator, stmt); | 3779 | const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt); |
| 3788 | const cond_expr = ZigClangAbstractConditionalOperator_getCond(casted_stmt); | 3780 | const cond_expr = casted_stmt.getCond(); |
| 3789 | const true_expr = ZigClangAbstractConditionalOperator_getTrueExpr(casted_stmt); | 3781 | const true_expr = casted_stmt.getTrueExpr(); |
| 3790 | const false_expr = ZigClangAbstractConditionalOperator_getFalseExpr(casted_stmt); | 3782 | const false_expr = casted_stmt.getFalseExpr(); |
| 3791 | 3783 | ||
| 3792 | if_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); | 3784 | if_node.condition = try transBoolExpr(rp, &cond_scope.base, cond_expr, .used, .r_value, false); |
| 3793 | _ = try appendToken(rp.c, .RParen, ")"); | 3785 | _ = try appendToken(rp.c, .RParen, ")"); |
| ... | @@ -3845,22 +3837,22 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: *ast.Node) !void { | ... | @@ -3845,22 +3837,22 @@ fn addTopLevelDecl(c: *Context, name: []const u8, decl_node: *ast.Node) !void { |
| 3845 | _ = try c.global_scope.sym_table.put(name, decl_node); | 3837 | _ = try c.global_scope.sym_table.put(name, decl_node); |
| 3846 | } | 3838 | } |
| 3847 | 3839 | ||
| 3848 | fn transQualType(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) TypeError!*ast.Node { | 3840 | fn transQualType(rp: RestorePoint, qt: clang.QualType, source_loc: clang.SourceLocation) TypeError!*ast.Node { |
| 3849 | return transType(rp, ZigClangQualType_getTypePtr(qt), source_loc); | 3841 | return transType(rp, qt.getTypePtr(), source_loc); |
| 3850 | } | 3842 | } |
| 3851 | 3843 | ||
| 3852 | /// Produces a Zig AST node by translating a Clang QualType, respecting the width, but modifying the signed-ness. | 3844 | /// Produces a Zig AST node by translating a Clang QualType, respecting the width, but modifying the signed-ness. |
| 3853 | /// Asserts the type is an integer. | 3845 | /// Asserts the type is an integer. |
| 3854 | fn transQualTypeIntWidthOf(c: *Context, ty: ZigClangQualType, is_signed: bool) TypeError!*ast.Node { | 3846 | fn transQualTypeIntWidthOf(c: *Context, ty: clang.QualType, is_signed: bool) TypeError!*ast.Node { |
| 3855 | return transTypeIntWidthOf(c, qualTypeCanon(ty), is_signed); | 3847 | return transTypeIntWidthOf(c, qualTypeCanon(ty), is_signed); |
| 3856 | } | 3848 | } |
| 3857 | 3849 | ||
| 3858 | /// Produces a Zig AST node by translating a Clang Type, respecting the width, but modifying the signed-ness. | 3850 | /// Produces a Zig AST node by translating a Clang Type, respecting the width, but modifying the signed-ness. |
| 3859 | /// Asserts the type is an integer. | 3851 | /// Asserts the type is an integer. |
| 3860 | fn transTypeIntWidthOf(c: *Context, ty: *const ZigClangType, is_signed: bool) TypeError!*ast.Node { | 3852 | fn transTypeIntWidthOf(c: *Context, ty: *const clang.Type, is_signed: bool) TypeError!*ast.Node { |
| 3861 | assert(ZigClangType_getTypeClass(ty) == .Builtin); | 3853 | assert(ty.getTypeClass() == .Builtin); |
| 3862 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 3854 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 3863 | return transCreateNodeIdentifier(c, switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 3855 | return transCreateNodeIdentifier(c, switch (builtin_ty.getKind()) { |
| 3864 | .Char_U, .Char_S, .UChar, .SChar, .Char8 => if (is_signed) "i8" else "u8", | 3856 | .Char_U, .Char_S, .UChar, .SChar, .Char8 => if (is_signed) "i8" else "u8", |
| 3865 | .UShort, .Short => if (is_signed) "c_short" else "c_ushort", | 3857 | .UShort, .Short => if (is_signed) "c_short" else "c_ushort", |
| 3866 | .UInt, .Int => if (is_signed) "c_int" else "c_uint", | 3858 | .UInt, .Int => if (is_signed) "c_int" else "c_uint", |
| ... | @@ -3873,30 +3865,30 @@ fn transTypeIntWidthOf(c: *Context, ty: *const ZigClangType, is_signed: bool) Ty | ... | @@ -3873,30 +3865,30 @@ fn transTypeIntWidthOf(c: *Context, ty: *const ZigClangType, is_signed: bool) Ty |
| 3873 | }); | 3865 | }); |
| 3874 | } | 3866 | } |
| 3875 | 3867 | ||
| 3876 | fn isCBuiltinType(qt: ZigClangQualType, kind: ZigClangBuiltinTypeKind) bool { | 3868 | fn isCBuiltinType(qt: clang.QualType, kind: clang.BuiltinTypeKind) bool { |
| 3877 | const c_type = qualTypeCanon(qt); | 3869 | const c_type = qualTypeCanon(qt); |
| 3878 | if (ZigClangType_getTypeClass(c_type) != .Builtin) | 3870 | if (c_type.getTypeClass() != .Builtin) |
| 3879 | return false; | 3871 | return false; |
| 3880 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 3872 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 3881 | return ZigClangBuiltinType_getKind(builtin_ty) == kind; | 3873 | return builtin_ty.getKind() == kind; |
| 3882 | } | 3874 | } |
| 3883 | 3875 | ||
| 3884 | fn qualTypeIsPtr(qt: ZigClangQualType) bool { | 3876 | fn qualTypeIsPtr(qt: clang.QualType) bool { |
| 3885 | return ZigClangType_getTypeClass(qualTypeCanon(qt)) == .Pointer; | 3877 | return qualTypeCanon(qt).getTypeClass() == .Pointer; |
| 3886 | } | 3878 | } |
| 3887 | 3879 | ||
| 3888 | fn qualTypeIsBoolean(qt: ZigClangQualType) bool { | 3880 | fn qualTypeIsBoolean(qt: clang.QualType) bool { |
| 3889 | return ZigClangType_isBooleanType(qualTypeCanon(qt)); | 3881 | return qualTypeCanon(qt).isBooleanType(); |
| 3890 | } | 3882 | } |
| 3891 | 3883 | ||
| 3892 | fn qualTypeIntBitWidth(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) !u32 { | 3884 | fn qualTypeIntBitWidth(rp: RestorePoint, qt: clang.QualType, source_loc: clang.SourceLocation) !u32 { |
| 3893 | const ty = ZigClangQualType_getTypePtr(qt); | 3885 | const ty = qt.getTypePtr(); |
| 3894 | 3886 | ||
| 3895 | switch (ZigClangType_getTypeClass(ty)) { | 3887 | switch (ty.getTypeClass()) { |
| 3896 | .Builtin => { | 3888 | .Builtin => { |
| 3897 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 3889 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 3898 | 3890 | ||
| 3899 | switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 3891 | switch (builtin_ty.getKind()) { |
| 3900 | .Char_U, | 3892 | .Char_U, |
| 3901 | .UChar, | 3893 | .UChar, |
| 3902 | .Char_S, | 3894 | .Char_S, |
| ... | @@ -3911,9 +3903,9 @@ fn qualTypeIntBitWidth(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigCl | ... | @@ -3911,9 +3903,9 @@ fn qualTypeIntBitWidth(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigCl |
| 3911 | unreachable; | 3903 | unreachable; |
| 3912 | }, | 3904 | }, |
| 3913 | .Typedef => { | 3905 | .Typedef => { |
| 3914 | const typedef_ty = @ptrCast(*const ZigClangTypedefType, ty); | 3906 | const typedef_ty = @ptrCast(*const clang.TypedefType, ty); |
| 3915 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 3907 | const typedef_decl = typedef_ty.getDecl(); |
| 3916 | const type_name = try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, typedef_decl))); | 3908 | const type_name = try rp.c.str(@ptrCast(*const clang.NamedDecl, typedef_decl).getName_bytes_begin()); |
| 3917 | 3909 | ||
| 3918 | if (mem.eql(u8, type_name, "uint8_t") or mem.eql(u8, type_name, "int8_t")) { | 3910 | if (mem.eql(u8, type_name, "uint8_t") or mem.eql(u8, type_name, "int8_t")) { |
| 3919 | return 8; | 3911 | return 8; |
| ... | @@ -3933,7 +3925,7 @@ fn qualTypeIntBitWidth(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigCl | ... | @@ -3933,7 +3925,7 @@ fn qualTypeIntBitWidth(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigCl |
| 3933 | unreachable; | 3925 | unreachable; |
| 3934 | } | 3926 | } |
| 3935 | 3927 | ||
| 3936 | fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) !*ast.Node { | 3928 | fn qualTypeToLog2IntRef(rp: RestorePoint, qt: clang.QualType, source_loc: clang.SourceLocation) !*ast.Node { |
| 3937 | const int_bit_width = try qualTypeIntBitWidth(rp, qt, source_loc); | 3929 | const int_bit_width = try qualTypeIntBitWidth(rp, qt, source_loc); |
| 3938 | 3930 | ||
| 3939 | if (int_bit_width != 0) { | 3931 | if (int_bit_width != 0) { |
| ... | @@ -3980,83 +3972,83 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC | ... | @@ -3980,83 +3972,83 @@ fn qualTypeToLog2IntRef(rp: RestorePoint, qt: ZigClangQualType, source_loc: ZigC |
| 3980 | return &log2int_fn_call.base; | 3972 | return &log2int_fn_call.base; |
| 3981 | } | 3973 | } |
| 3982 | 3974 | ||
| 3983 | fn qualTypeChildIsFnProto(qt: ZigClangQualType) bool { | 3975 | fn qualTypeChildIsFnProto(qt: clang.QualType) bool { |
| 3984 | const ty = qualTypeCanon(qt); | 3976 | const ty = qualTypeCanon(qt); |
| 3985 | 3977 | ||
| 3986 | switch (ZigClangType_getTypeClass(ty)) { | 3978 | switch (ty.getTypeClass()) { |
| 3987 | .FunctionProto, .FunctionNoProto => return true, | 3979 | .FunctionProto, .FunctionNoProto => return true, |
| 3988 | else => return false, | 3980 | else => return false, |
| 3989 | } | 3981 | } |
| 3990 | } | 3982 | } |
| 3991 | 3983 | ||
| 3992 | fn qualTypeCanon(qt: ZigClangQualType) *const ZigClangType { | 3984 | fn qualTypeCanon(qt: clang.QualType) *const clang.Type { |
| 3993 | const canon = ZigClangQualType_getCanonicalType(qt); | 3985 | const canon = qt.getCanonicalType(); |
| 3994 | return ZigClangQualType_getTypePtr(canon); | 3986 | return canon.getTypePtr(); |
| 3995 | } | 3987 | } |
| 3996 | 3988 | ||
| 3997 | fn getExprQualType(c: *Context, expr: *const ZigClangExpr) ZigClangQualType { | 3989 | fn getExprQualType(c: *Context, expr: *const clang.Expr) clang.QualType { |
| 3998 | blk: { | 3990 | blk: { |
| 3999 | // If this is a C `char *`, turn it into a `const char *` | 3991 | // If this is a C `char *`, turn it into a `const char *` |
| 4000 | if (ZigClangExpr_getStmtClass(expr) != .ImplicitCastExprClass) break :blk; | 3992 | if (expr.getStmtClass() != .ImplicitCastExprClass) break :blk; |
| 4001 | const cast_expr = @ptrCast(*const ZigClangImplicitCastExpr, expr); | 3993 | const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr); |
| 4002 | if (ZigClangImplicitCastExpr_getCastKind(cast_expr) != .ArrayToPointerDecay) break :blk; | 3994 | if (cast_expr.getCastKind() != .ArrayToPointerDecay) break :blk; |
| 4003 | const sub_expr = ZigClangImplicitCastExpr_getSubExpr(cast_expr); | 3995 | const sub_expr = cast_expr.getSubExpr(); |
| 4004 | if (ZigClangExpr_getStmtClass(sub_expr) != .StringLiteralClass) break :blk; | 3996 | if (sub_expr.getStmtClass() != .StringLiteralClass) break :blk; |
| 4005 | const array_qt = ZigClangExpr_getType(sub_expr); | 3997 | const array_qt = sub_expr.getType(); |
| 4006 | const array_type = @ptrCast(*const ZigClangArrayType, ZigClangQualType_getTypePtr(array_qt)); | 3998 | const array_type = @ptrCast(*const clang.ArrayType, array_qt.getTypePtr()); |
| 4007 | var pointee_qt = ZigClangArrayType_getElementType(array_type); | 3999 | var pointee_qt = array_type.getElementType(); |
| 4008 | ZigClangQualType_addConst(&pointee_qt); | 4000 | pointee_qt.addConst(); |
| 4009 | return ZigClangASTContext_getPointerType(c.clang_context, pointee_qt); | 4001 | return c.clang_context.getPointerType(pointee_qt); |
| 4010 | } | 4002 | } |
| 4011 | return ZigClangExpr_getType(expr); | 4003 | return expr.getType(); |
| 4012 | } | 4004 | } |
| 4013 | 4005 | ||
| 4014 | fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocation) bool { | 4006 | fn typeIsOpaque(c: *Context, ty: *const clang.Type, loc: clang.SourceLocation) bool { |
| 4015 | switch (ZigClangType_getTypeClass(ty)) { | 4007 | switch (ty.getTypeClass()) { |
| 4016 | .Builtin => { | 4008 | .Builtin => { |
| 4017 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 4009 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 4018 | return ZigClangBuiltinType_getKind(builtin_ty) == .Void; | 4010 | return builtin_ty.getKind() == .Void; |
| 4019 | }, | 4011 | }, |
| 4020 | .Record => { | 4012 | .Record => { |
| 4021 | const record_ty = @ptrCast(*const ZigClangRecordType, ty); | 4013 | const record_ty = @ptrCast(*const clang.RecordType, ty); |
| 4022 | const record_decl = ZigClangRecordType_getDecl(record_ty); | 4014 | const record_decl = record_ty.getDecl(); |
| 4023 | const record_def = ZigClangRecordDecl_getDefinition(record_decl) orelse | 4015 | const record_def = record_decl.getDefinition() orelse |
| 4024 | return true; | 4016 | return true; |
| 4025 | var it = ZigClangRecordDecl_field_begin(record_def); | 4017 | var it = record_def.field_begin(); |
| 4026 | const end_it = ZigClangRecordDecl_field_end(record_def); | 4018 | const end_it = record_def.field_end(); |
| 4027 | while (ZigClangRecordDecl_field_iterator_neq(it, end_it)) : (it = ZigClangRecordDecl_field_iterator_next(it)) { | 4019 | while (it.neq(end_it)) : (it = it.next()) { |
| 4028 | const field_decl = ZigClangRecordDecl_field_iterator_deref(it); | 4020 | const field_decl = it.deref(); |
| 4029 | 4021 | ||
| 4030 | if (ZigClangFieldDecl_isBitField(field_decl)) { | 4022 | if (field_decl.isBitField()) { |
| 4031 | return true; | 4023 | return true; |
| 4032 | } | 4024 | } |
| 4033 | } | 4025 | } |
| 4034 | return false; | 4026 | return false; |
| 4035 | }, | 4027 | }, |
| 4036 | .Elaborated => { | 4028 | .Elaborated => { |
| 4037 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ty); | 4029 | const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty); |
| 4038 | const qt = ZigClangElaboratedType_getNamedType(elaborated_ty); | 4030 | const qt = elaborated_ty.getNamedType(); |
| 4039 | return typeIsOpaque(c, ZigClangQualType_getTypePtr(qt), loc); | 4031 | return typeIsOpaque(c, qt.getTypePtr(), loc); |
| 4040 | }, | 4032 | }, |
| 4041 | .Typedef => { | 4033 | .Typedef => { |
| 4042 | const typedef_ty = @ptrCast(*const ZigClangTypedefType, ty); | 4034 | const typedef_ty = @ptrCast(*const clang.TypedefType, ty); |
| 4043 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 4035 | const typedef_decl = typedef_ty.getDecl(); |
| 4044 | const underlying_type = ZigClangTypedefNameDecl_getUnderlyingType(typedef_decl); | 4036 | const underlying_type = typedef_decl.getUnderlyingType(); |
| 4045 | return typeIsOpaque(c, ZigClangQualType_getTypePtr(underlying_type), loc); | 4037 | return typeIsOpaque(c, underlying_type.getTypePtr(), loc); |
| 4046 | }, | 4038 | }, |
| 4047 | else => return false, | 4039 | else => return false, |
| 4048 | } | 4040 | } |
| 4049 | } | 4041 | } |
| 4050 | 4042 | ||
| 4051 | fn cIsInteger(qt: ZigClangQualType) bool { | 4043 | fn cIsInteger(qt: clang.QualType) bool { |
| 4052 | return cIsSignedInteger(qt) or cIsUnsignedInteger(qt); | 4044 | return cIsSignedInteger(qt) or cIsUnsignedInteger(qt); |
| 4053 | } | 4045 | } |
| 4054 | 4046 | ||
| 4055 | fn cIsUnsignedInteger(qt: ZigClangQualType) bool { | 4047 | fn cIsUnsignedInteger(qt: clang.QualType) bool { |
| 4056 | const c_type = qualTypeCanon(qt); | 4048 | const c_type = qualTypeCanon(qt); |
| 4057 | if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; | 4049 | if (c_type.getTypeClass() != .Builtin) return false; |
| 4058 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 4050 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 4059 | return switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4051 | return switch (builtin_ty.getKind()) { |
| 4060 | .Char_U, | 4052 | .Char_U, |
| 4061 | .UChar, | 4053 | .UChar, |
| 4062 | .Char_S, | 4054 | .Char_S, |
| ... | @@ -4071,11 +4063,11 @@ fn cIsUnsignedInteger(qt: ZigClangQualType) bool { | ... | @@ -4071,11 +4063,11 @@ fn cIsUnsignedInteger(qt: ZigClangQualType) bool { |
| 4071 | }; | 4063 | }; |
| 4072 | } | 4064 | } |
| 4073 | 4065 | ||
| 4074 | fn cIntTypeToIndex(qt: ZigClangQualType) u8 { | 4066 | fn cIntTypeToIndex(qt: clang.QualType) u8 { |
| 4075 | const c_type = qualTypeCanon(qt); | 4067 | const c_type = qualTypeCanon(qt); |
| 4076 | assert(ZigClangType_getTypeClass(c_type) == .Builtin); | 4068 | assert(c_type.getTypeClass() == .Builtin); |
| 4077 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 4069 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 4078 | return switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4070 | return switch (builtin_ty.getKind()) { |
| 4079 | .Bool, .Char_U, .Char_S, .UChar, .SChar, .Char8 => 1, | 4071 | .Bool, .Char_U, .Char_S, .UChar, .SChar, .Char8 => 1, |
| 4080 | .WChar_U, .WChar_S => 2, | 4072 | .WChar_U, .WChar_S => 2, |
| 4081 | .UShort, .Short, .Char16 => 3, | 4073 | .UShort, .Short, .Char16 => 3, |
| ... | @@ -4087,17 +4079,17 @@ fn cIntTypeToIndex(qt: ZigClangQualType) u8 { | ... | @@ -4087,17 +4079,17 @@ fn cIntTypeToIndex(qt: ZigClangQualType) u8 { |
| 4087 | }; | 4079 | }; |
| 4088 | } | 4080 | } |
| 4089 | 4081 | ||
| 4090 | fn cIntTypeCmp(a: ZigClangQualType, b: ZigClangQualType) math.Order { | 4082 | fn cIntTypeCmp(a: clang.QualType, b: clang.QualType) math.Order { |
| 4091 | const a_index = cIntTypeToIndex(a); | 4083 | const a_index = cIntTypeToIndex(a); |
| 4092 | const b_index = cIntTypeToIndex(b); | 4084 | const b_index = cIntTypeToIndex(b); |
| 4093 | return math.order(a_index, b_index); | 4085 | return math.order(a_index, b_index); |
| 4094 | } | 4086 | } |
| 4095 | 4087 | ||
| 4096 | fn cIsSignedInteger(qt: ZigClangQualType) bool { | 4088 | fn cIsSignedInteger(qt: clang.QualType) bool { |
| 4097 | const c_type = qualTypeCanon(qt); | 4089 | const c_type = qualTypeCanon(qt); |
| 4098 | if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; | 4090 | if (c_type.getTypeClass() != .Builtin) return false; |
| 4099 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 4091 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 4100 | return switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4092 | return switch (builtin_ty.getKind()) { |
| 4101 | .SChar, | 4093 | .SChar, |
| 4102 | .Short, | 4094 | .Short, |
| 4103 | .Int, | 4095 | .Int, |
| ... | @@ -4110,11 +4102,11 @@ fn cIsSignedInteger(qt: ZigClangQualType) bool { | ... | @@ -4110,11 +4102,11 @@ fn cIsSignedInteger(qt: ZigClangQualType) bool { |
| 4110 | }; | 4102 | }; |
| 4111 | } | 4103 | } |
| 4112 | 4104 | ||
| 4113 | fn cIsFloating(qt: ZigClangQualType) bool { | 4105 | fn cIsFloating(qt: clang.QualType) bool { |
| 4114 | const c_type = qualTypeCanon(qt); | 4106 | const c_type = qualTypeCanon(qt); |
| 4115 | if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; | 4107 | if (c_type.getTypeClass() != .Builtin) return false; |
| 4116 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 4108 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 4117 | return switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4109 | return switch (builtin_ty.getKind()) { |
| 4118 | .Float, | 4110 | .Float, |
| 4119 | .Double, | 4111 | .Double, |
| 4120 | .Float128, | 4112 | .Float128, |
| ... | @@ -4124,11 +4116,11 @@ fn cIsFloating(qt: ZigClangQualType) bool { | ... | @@ -4124,11 +4116,11 @@ fn cIsFloating(qt: ZigClangQualType) bool { |
| 4124 | }; | 4116 | }; |
| 4125 | } | 4117 | } |
| 4126 | 4118 | ||
| 4127 | fn cIsLongLongInteger(qt: ZigClangQualType) bool { | 4119 | fn cIsLongLongInteger(qt: clang.QualType) bool { |
| 4128 | const c_type = qualTypeCanon(qt); | 4120 | const c_type = qualTypeCanon(qt); |
| 4129 | if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; | 4121 | if (c_type.getTypeClass() != .Builtin) return false; |
| 4130 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, c_type); | 4122 | const builtin_ty = @ptrCast(*const clang.BuiltinType, c_type); |
| 4131 | return switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4123 | return switch (builtin_ty.getKind()) { |
| 4132 | .LongLong, .ULongLong, .Int128, .UInt128 => true, | 4124 | .LongLong, .ULongLong, .Int128, .UInt128 => true, |
| 4133 | else => false, | 4125 | else => false, |
| 4134 | }; | 4126 | }; |
| ... | @@ -4137,8 +4129,8 @@ fn transCreateNodeAssign( | ... | @@ -4137,8 +4129,8 @@ fn transCreateNodeAssign( |
| 4137 | rp: RestorePoint, | 4129 | rp: RestorePoint, |
| 4138 | scope: *Scope, | 4130 | scope: *Scope, |
| 4139 | result_used: ResultUsed, | 4131 | result_used: ResultUsed, |
| 4140 | lhs: *const ZigClangExpr, | 4132 | lhs: *const clang.Expr, |
| 4141 | rhs: *const ZigClangExpr, | 4133 | rhs: *const clang.Expr, |
| 4142 | ) !*ast.Node { | 4134 | ) !*ast.Node { |
| 4143 | // common case | 4135 | // common case |
| 4144 | // c: lhs = rhs | 4136 | // c: lhs = rhs |
| ... | @@ -4273,19 +4265,19 @@ fn transCreateNodeInfixOp( | ... | @@ -4273,19 +4265,19 @@ fn transCreateNodeInfixOp( |
| 4273 | fn transCreateNodeBoolInfixOp( | 4265 | fn transCreateNodeBoolInfixOp( |
| 4274 | rp: RestorePoint, | 4266 | rp: RestorePoint, |
| 4275 | scope: *Scope, | 4267 | scope: *Scope, |
| 4276 | stmt: *const ZigClangBinaryOperator, | 4268 | stmt: *const clang.BinaryOperator, |
| 4277 | op: ast.Node.Tag, | 4269 | op: ast.Node.Tag, |
| 4278 | used: ResultUsed, | 4270 | used: ResultUsed, |
| 4279 | grouped: bool, | 4271 | grouped: bool, |
| 4280 | ) !*ast.Node { | 4272 | ) !*ast.Node { |
| 4281 | std.debug.assert(op == .BoolAnd or op == .BoolOr); | 4273 | std.debug.assert(op == .BoolAnd or op == .BoolOr); |
| 4282 | 4274 | ||
| 4283 | const lhs_hode = try transBoolExpr(rp, scope, ZigClangBinaryOperator_getLHS(stmt), .used, .l_value, true); | 4275 | const lhs_hode = try transBoolExpr(rp, scope, stmt.getLHS(), .used, .l_value, true); |
| 4284 | const op_token = if (op == .BoolAnd) | 4276 | const op_token = if (op == .BoolAnd) |
| 4285 | try appendToken(rp.c, .Keyword_and, "and") | 4277 | try appendToken(rp.c, .Keyword_and, "and") |
| 4286 | else | 4278 | else |
| 4287 | try appendToken(rp.c, .Keyword_or, "or"); | 4279 | try appendToken(rp.c, .Keyword_or, "or"); |
| 4288 | const rhs = try transBoolExpr(rp, scope, ZigClangBinaryOperator_getRHS(stmt), .used, .r_value, true); | 4280 | const rhs = try transBoolExpr(rp, scope, stmt.getRHS(), .used, .r_value, true); |
| 4289 | 4281 | ||
| 4290 | return transCreateNodeInfixOp( | 4282 | return transCreateNodeInfixOp( |
| 4291 | rp, | 4283 | rp, |
| ... | @@ -4334,21 +4326,21 @@ fn transCreateNodePtrType( | ... | @@ -4334,21 +4326,21 @@ fn transCreateNodePtrType( |
| 4334 | return node; | 4326 | return node; |
| 4335 | } | 4327 | } |
| 4336 | 4328 | ||
| 4337 | fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node { | 4329 | fn transCreateNodeAPInt(c: *Context, int: *const clang.APSInt) !*ast.Node { |
| 4338 | const num_limbs = math.cast(usize, ZigClangAPSInt_getNumWords(int)) catch |err| switch (err) { | 4330 | const num_limbs = math.cast(usize, int.getNumWords()) catch |err| switch (err) { |
| 4339 | error.Overflow => return error.OutOfMemory, | 4331 | error.Overflow => return error.OutOfMemory, |
| 4340 | }; | 4332 | }; |
| 4341 | var aps_int = int; | 4333 | var aps_int = int; |
| 4342 | const is_negative = ZigClangAPSInt_isSigned(int) and ZigClangAPSInt_isNegative(int); | 4334 | const is_negative = int.isSigned() and int.isNegative(); |
| 4343 | if (is_negative) aps_int = ZigClangAPSInt_negate(aps_int); | 4335 | if (is_negative) aps_int = aps_int.negate(); |
| 4344 | defer if (is_negative) { | 4336 | defer if (is_negative) { |
| 4345 | ZigClangAPSInt_free(aps_int); | 4337 | aps_int.free(); |
| 4346 | }; | 4338 | }; |
| 4347 | 4339 | ||
| 4348 | const limbs = try c.arena.alloc(math.big.Limb, num_limbs); | 4340 | const limbs = try c.arena.alloc(math.big.Limb, num_limbs); |
| 4349 | defer c.arena.free(limbs); | 4341 | defer c.arena.free(limbs); |
| 4350 | 4342 | ||
| 4351 | const data = ZigClangAPSInt_getRawData(aps_int); | 4343 | const data = aps_int.getRawData(); |
| 4352 | switch (@sizeOf(math.big.Limb)) { | 4344 | switch (@sizeOf(math.big.Limb)) { |
| 4353 | 8 => { | 4345 | 8 => { |
| 4354 | var i: usize = 0; | 4346 | var i: usize = 0; |
| ... | @@ -4438,10 +4430,18 @@ fn transCreateNodeFloat(c: *Context, int: anytype) !*ast.Node { | ... | @@ -4438,10 +4430,18 @@ fn transCreateNodeFloat(c: *Context, int: anytype) !*ast.Node { |
| 4438 | } | 4430 | } |
| 4439 | 4431 | ||
| 4440 | fn transCreateNodeOpaqueType(c: *Context) !*ast.Node { | 4432 | fn transCreateNodeOpaqueType(c: *Context) !*ast.Node { |
| 4441 | const call_node = try c.createBuiltinCall("@Type", 1); | 4433 | const container_tok = try appendToken(c, .Keyword_opaque, "opaque"); |
| 4442 | call_node.params()[0] = try transCreateNodeEnumLiteral(c, "Opaque"); | 4434 | const lbrace_token = try appendToken(c, .LBrace, "{"); |
| 4443 | call_node.rparen_token = try appendToken(c, .RParen, ")"); | 4435 | const container_node = try ast.Node.ContainerDecl.alloc(c.arena, 0); |
| 4444 | return &call_node.base; | 4436 | container_node.* = .{ |
| 4437 | .kind_token = container_tok, | ||
| 4438 | .layout_token = null, | ||
| 4439 | .lbrace_token = lbrace_token, | ||
| 4440 | .rbrace_token = try appendToken(c, .RBrace, "}"), | ||
| 4441 | .fields_and_decls_len = 0, | ||
| 4442 | .init_arg_expr = .None, | ||
| 4443 | }; | ||
| 4444 | return &container_node.base; | ||
| 4445 | } | 4445 | } |
| 4446 | 4446 | ||
| 4447 | fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: *ast.Node, proto_alias: *ast.Node.FnProto) !*ast.Node { | 4447 | fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: *ast.Node, proto_alias: *ast.Node.FnProto) !*ast.Node { |
| ... | @@ -4689,23 +4689,23 @@ fn transCreateNodeSwitchElse(c: *Context) !*ast.Node { | ... | @@ -4689,23 +4689,23 @@ fn transCreateNodeSwitchElse(c: *Context) !*ast.Node { |
| 4689 | fn transCreateNodeShiftOp( | 4689 | fn transCreateNodeShiftOp( |
| 4690 | rp: RestorePoint, | 4690 | rp: RestorePoint, |
| 4691 | scope: *Scope, | 4691 | scope: *Scope, |
| 4692 | stmt: *const ZigClangBinaryOperator, | 4692 | stmt: *const clang.BinaryOperator, |
| 4693 | op: ast.Node.Tag, | 4693 | op: ast.Node.Tag, |
| 4694 | op_tok_id: std.zig.Token.Id, | 4694 | op_tok_id: std.zig.Token.Id, |
| 4695 | bytes: []const u8, | 4695 | bytes: []const u8, |
| 4696 | ) !*ast.Node { | 4696 | ) !*ast.Node { |
| 4697 | std.debug.assert(op == .BitShiftLeft or op == .BitShiftRight); | 4697 | std.debug.assert(op == .BitShiftLeft or op == .BitShiftRight); |
| 4698 | 4698 | ||
| 4699 | const lhs_expr = ZigClangBinaryOperator_getLHS(stmt); | 4699 | const lhs_expr = stmt.getLHS(); |
| 4700 | const rhs_expr = ZigClangBinaryOperator_getRHS(stmt); | 4700 | const rhs_expr = stmt.getRHS(); |
| 4701 | const rhs_location = ZigClangExpr_getBeginLoc(rhs_expr); | 4701 | const rhs_location = rhs_expr.getBeginLoc(); |
| 4702 | // lhs >> @as(u5, rh) | 4702 | // lhs >> @as(u5, rh) |
| 4703 | 4703 | ||
| 4704 | const lhs = try transExpr(rp, scope, lhs_expr, .used, .l_value); | 4704 | const lhs = try transExpr(rp, scope, lhs_expr, .used, .l_value); |
| 4705 | const op_token = try appendToken(rp.c, op_tok_id, bytes); | 4705 | const op_token = try appendToken(rp.c, op_tok_id, bytes); |
| 4706 | 4706 | ||
| 4707 | const cast_node = try rp.c.createBuiltinCall("@intCast", 2); | 4707 | const cast_node = try rp.c.createBuiltinCall("@intCast", 2); |
| 4708 | const rhs_type = try qualTypeToLog2IntRef(rp, ZigClangBinaryOperator_getType(stmt), rhs_location); | 4708 | const rhs_type = try qualTypeToLog2IntRef(rp, stmt.getType(), rhs_location); |
| 4709 | cast_node.params()[0] = rhs_type; | 4709 | cast_node.params()[0] = rhs_type; |
| 4710 | _ = try appendToken(rp.c, .Comma, ","); | 4710 | _ = try appendToken(rp.c, .Comma, ","); |
| 4711 | const rhs = try transExprCoercing(rp, scope, rhs_expr, .used, .r_value); | 4711 | const rhs = try transExprCoercing(rp, scope, rhs_expr, .used, .r_value); |
| ... | @@ -4764,11 +4764,11 @@ fn makeRestorePoint(c: *Context) RestorePoint { | ... | @@ -4764,11 +4764,11 @@ fn makeRestorePoint(c: *Context) RestorePoint { |
| 4764 | }; | 4764 | }; |
| 4765 | } | 4765 | } |
| 4766 | 4766 | ||
| 4767 | fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSourceLocation) TypeError!*ast.Node { | 4767 | fn transType(rp: RestorePoint, ty: *const clang.Type, source_loc: clang.SourceLocation) TypeError!*ast.Node { |
| 4768 | switch (ZigClangType_getTypeClass(ty)) { | 4768 | switch (ty.getTypeClass()) { |
| 4769 | .Builtin => { | 4769 | .Builtin => { |
| 4770 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 4770 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 4771 | return transCreateNodeIdentifier(rp.c, switch (ZigClangBuiltinType_getKind(builtin_ty)) { | 4771 | return transCreateNodeIdentifier(rp.c, switch (builtin_ty.getKind()) { |
| 4772 | .Void => "c_void", | 4772 | .Void => "c_void", |
| 4773 | .Bool => "bool", | 4773 | .Bool => "bool", |
| 4774 | .Char_U, .UChar, .Char_S, .Char8 => "u8", | 4774 | .Char_U, .UChar, .Char_S, .Char8 => "u8", |
| ... | @@ -4792,32 +4792,32 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -4792,32 +4792,32 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 4792 | }); | 4792 | }); |
| 4793 | }, | 4793 | }, |
| 4794 | .FunctionProto => { | 4794 | .FunctionProto => { |
| 4795 | const fn_proto_ty = @ptrCast(*const ZigClangFunctionProtoType, ty); | 4795 | const fn_proto_ty = @ptrCast(*const clang.FunctionProtoType, ty); |
| 4796 | const fn_proto = try transFnProto(rp, null, fn_proto_ty, source_loc, null, false); | 4796 | const fn_proto = try transFnProto(rp, null, fn_proto_ty, source_loc, null, false); |
| 4797 | return &fn_proto.base; | 4797 | return &fn_proto.base; |
| 4798 | }, | 4798 | }, |
| 4799 | .FunctionNoProto => { | 4799 | .FunctionNoProto => { |
| 4800 | const fn_no_proto_ty = @ptrCast(*const ZigClangFunctionType, ty); | 4800 | const fn_no_proto_ty = @ptrCast(*const clang.FunctionType, ty); |
| 4801 | const fn_proto = try transFnNoProto(rp, fn_no_proto_ty, source_loc, null, false); | 4801 | const fn_proto = try transFnNoProto(rp, fn_no_proto_ty, source_loc, null, false); |
| 4802 | return &fn_proto.base; | 4802 | return &fn_proto.base; |
| 4803 | }, | 4803 | }, |
| 4804 | .Paren => { | 4804 | .Paren => { |
| 4805 | const paren_ty = @ptrCast(*const ZigClangParenType, ty); | 4805 | const paren_ty = @ptrCast(*const clang.ParenType, ty); |
| 4806 | return transQualType(rp, ZigClangParenType_getInnerType(paren_ty), source_loc); | 4806 | return transQualType(rp, paren_ty.getInnerType(), source_loc); |
| 4807 | }, | 4807 | }, |
| 4808 | .Pointer => { | 4808 | .Pointer => { |
| 4809 | const child_qt = ZigClangType_getPointeeType(ty); | 4809 | const child_qt = ty.getPointeeType(); |
| 4810 | if (qualTypeChildIsFnProto(child_qt)) { | 4810 | if (qualTypeChildIsFnProto(child_qt)) { |
| 4811 | const optional_node = try transCreateNodeSimplePrefixOp(rp.c, .OptionalType, .QuestionMark, "?"); | 4811 | const optional_node = try transCreateNodeSimplePrefixOp(rp.c, .OptionalType, .QuestionMark, "?"); |
| 4812 | optional_node.rhs = try transQualType(rp, child_qt, source_loc); | 4812 | optional_node.rhs = try transQualType(rp, child_qt, source_loc); |
| 4813 | return &optional_node.base; | 4813 | return &optional_node.base; |
| 4814 | } | 4814 | } |
| 4815 | if (typeIsOpaque(rp.c, ZigClangQualType_getTypePtr(child_qt), source_loc)) { | 4815 | if (typeIsOpaque(rp.c, child_qt.getTypePtr(), source_loc)) { |
| 4816 | const optional_node = try transCreateNodeSimplePrefixOp(rp.c, .OptionalType, .QuestionMark, "?"); | 4816 | const optional_node = try transCreateNodeSimplePrefixOp(rp.c, .OptionalType, .QuestionMark, "?"); |
| 4817 | const pointer_node = try transCreateNodePtrType( | 4817 | const pointer_node = try transCreateNodePtrType( |
| 4818 | rp.c, | 4818 | rp.c, |
| 4819 | ZigClangQualType_isConstQualified(child_qt), | 4819 | child_qt.isConstQualified(), |
| 4820 | ZigClangQualType_isVolatileQualified(child_qt), | 4820 | child_qt.isVolatileQualified(), |
| 4821 | .Asterisk, | 4821 | .Asterisk, |
| 4822 | ); | 4822 | ); |
| 4823 | optional_node.rhs = &pointer_node.base; | 4823 | optional_node.rhs = &pointer_node.base; |
| ... | @@ -4826,83 +4826,83 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour | ... | @@ -4826,83 +4826,83 @@ fn transType(rp: RestorePoint, ty: *const ZigClangType, source_loc: ZigClangSour |
| 4826 | } | 4826 | } |
| 4827 | const pointer_node = try transCreateNodePtrType( | 4827 | const pointer_node = try transCreateNodePtrType( |
| 4828 | rp.c, | 4828 | rp.c, |
| 4829 | ZigClangQualType_isConstQualified(child_qt), | 4829 | child_qt.isConstQualified(), |
| 4830 | ZigClangQualType_isVolatileQualified(child_qt), | 4830 | child_qt.isVolatileQualified(), |
| 4831 | .Identifier, | 4831 | .Identifier, |
| 4832 | ); | 4832 | ); |
| 4833 | pointer_node.rhs = try transQualType(rp, child_qt, source_loc); | 4833 | pointer_node.rhs = try transQualType(rp, child_qt, source_loc); |
| 4834 | return &pointer_node.base; | 4834 | return &pointer_node.base; |
| 4835 | }, | 4835 | }, |
| 4836 | .ConstantArray => { | 4836 | .ConstantArray => { |
| 4837 | const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, ty); | 4837 | const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, ty); |
| 4838 | 4838 | ||
| 4839 | const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty); | 4839 | const size_ap_int = const_arr_ty.getSize(); |
| 4840 | const size = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize)); | 4840 | const size = size_ap_int.getLimitedValue(math.maxInt(usize)); |
| 4841 | const elem_ty = ZigClangQualType_getTypePtr(ZigClangConstantArrayType_getElementType(const_arr_ty)); | 4841 | const elem_ty = const_arr_ty.getElementType().getTypePtr(); |
| 4842 | return try transCreateNodeArrayType(rp, source_loc, elem_ty, size); | 4842 | return try transCreateNodeArrayType(rp, source_loc, elem_ty, size); |
| 4843 | }, | 4843 | }, |
| 4844 | .IncompleteArray => { | 4844 | .IncompleteArray => { |
| 4845 | const incomplete_array_ty = @ptrCast(*const ZigClangIncompleteArrayType, ty); | 4845 | const incomplete_array_ty = @ptrCast(*const clang.IncompleteArrayType, ty); |
| 4846 | 4846 | ||
| 4847 | const child_qt = ZigClangIncompleteArrayType_getElementType(incomplete_array_ty); | 4847 | const child_qt = incomplete_array_ty.getElementType(); |
| 4848 | var node = try transCreateNodePtrType( | 4848 | var node = try transCreateNodePtrType( |
| 4849 | rp.c, | 4849 | rp.c, |
| 4850 | ZigClangQualType_isConstQualified(child_qt), | 4850 | child_qt.isConstQualified(), |
| 4851 | ZigClangQualType_isVolatileQualified(child_qt), | 4851 | child_qt.isVolatileQualified(), |
| 4852 | .Identifier, | 4852 | .Identifier, |
| 4853 | ); | 4853 | ); |
| 4854 | node.rhs = try transQualType(rp, child_qt, source_loc); | 4854 | node.rhs = try transQualType(rp, child_qt, source_loc); |
| 4855 | return &node.base; | 4855 | return &node.base; |
| 4856 | }, | 4856 | }, |
| 4857 | .Typedef => { | 4857 | .Typedef => { |
| 4858 | const typedef_ty = @ptrCast(*const ZigClangTypedefType, ty); | 4858 | const typedef_ty = @ptrCast(*const clang.TypedefType, ty); |
| 4859 | 4859 | ||
| 4860 | const typedef_decl = ZigClangTypedefType_getDecl(typedef_ty); | 4860 | const typedef_decl = typedef_ty.getDecl(); |
| 4861 | return (try transTypeDef(rp.c, typedef_decl, false)) orelse | 4861 | return (try transTypeDef(rp.c, typedef_decl, false)) orelse |
| 4862 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to translate typedef declaration", .{}); | 4862 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to translate typedef declaration", .{}); |
| 4863 | }, | 4863 | }, |
| 4864 | .Record => { | 4864 | .Record => { |
| 4865 | const record_ty = @ptrCast(*const ZigClangRecordType, ty); | 4865 | const record_ty = @ptrCast(*const clang.RecordType, ty); |
| 4866 | 4866 | ||
| 4867 | const record_decl = ZigClangRecordType_getDecl(record_ty); | 4867 | const record_decl = record_ty.getDecl(); |
| 4868 | return (try transRecordDecl(rp.c, record_decl)) orelse | 4868 | return (try transRecordDecl(rp.c, record_decl)) orelse |
| 4869 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to resolve record declaration", .{}); | 4869 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to resolve record declaration", .{}); |
| 4870 | }, | 4870 | }, |
| 4871 | .Enum => { | 4871 | .Enum => { |
| 4872 | const enum_ty = @ptrCast(*const ZigClangEnumType, ty); | 4872 | const enum_ty = @ptrCast(*const clang.EnumType, ty); |
| 4873 | 4873 | ||
| 4874 | const enum_decl = ZigClangEnumType_getDecl(enum_ty); | 4874 | const enum_decl = enum_ty.getDecl(); |
| 4875 | return (try transEnumDecl(rp.c, enum_decl)) orelse | 4875 | return (try transEnumDecl(rp.c, enum_decl)) orelse |
| 4876 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to translate enum declaration", .{}); | 4876 | revertAndWarn(rp, error.UnsupportedType, source_loc, "unable to translate enum declaration", .{}); |
| 4877 | }, | 4877 | }, |
| 4878 | .Elaborated => { | 4878 | .Elaborated => { |
| 4879 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ty); | 4879 | const elaborated_ty = @ptrCast(*const clang.ElaboratedType, ty); |
| 4880 | return transQualType(rp, ZigClangElaboratedType_getNamedType(elaborated_ty), source_loc); | 4880 | return transQualType(rp, elaborated_ty.getNamedType(), source_loc); |
| 4881 | }, | 4881 | }, |
| 4882 | .Decayed => { | 4882 | .Decayed => { |
| 4883 | const decayed_ty = @ptrCast(*const ZigClangDecayedType, ty); | 4883 | const decayed_ty = @ptrCast(*const clang.DecayedType, ty); |
| 4884 | return transQualType(rp, ZigClangDecayedType_getDecayedType(decayed_ty), source_loc); | 4884 | return transQualType(rp, decayed_ty.getDecayedType(), source_loc); |
| 4885 | }, | 4885 | }, |
| 4886 | .Attributed => { | 4886 | .Attributed => { |
| 4887 | const attributed_ty = @ptrCast(*const ZigClangAttributedType, ty); | 4887 | const attributed_ty = @ptrCast(*const clang.AttributedType, ty); |
| 4888 | return transQualType(rp, ZigClangAttributedType_getEquivalentType(attributed_ty), source_loc); | 4888 | return transQualType(rp, attributed_ty.getEquivalentType(), source_loc); |
| 4889 | }, | 4889 | }, |
| 4890 | .MacroQualified => { | 4890 | .MacroQualified => { |
| 4891 | const macroqualified_ty = @ptrCast(*const ZigClangMacroQualifiedType, ty); | 4891 | const macroqualified_ty = @ptrCast(*const clang.MacroQualifiedType, ty); |
| 4892 | return transQualType(rp, ZigClangMacroQualifiedType_getModifiedType(macroqualified_ty), source_loc); | 4892 | return transQualType(rp, macroqualified_ty.getModifiedType(), source_loc); |
| 4893 | }, | 4893 | }, |
| 4894 | else => { | 4894 | else => { |
| 4895 | const type_name = rp.c.str(ZigClangType_getTypeClassName(ty)); | 4895 | const type_name = rp.c.str(ty.getTypeClassName()); |
| 4896 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name}); | 4896 | return revertAndWarn(rp, error.UnsupportedType, source_loc, "unsupported type: '{}'", .{type_name}); |
| 4897 | }, | 4897 | }, |
| 4898 | } | 4898 | } |
| 4899 | } | 4899 | } |
| 4900 | 4900 | ||
| 4901 | fn isCVoid(qt: ZigClangQualType) bool { | 4901 | fn isCVoid(qt: clang.QualType) bool { |
| 4902 | const ty = ZigClangQualType_getTypePtr(qt); | 4902 | const ty = qt.getTypePtr(); |
| 4903 | if (ZigClangType_getTypeClass(ty) == .Builtin) { | 4903 | if (ty.getTypeClass() == .Builtin) { |
| 4904 | const builtin_ty = @ptrCast(*const ZigClangBuiltinType, ty); | 4904 | const builtin_ty = @ptrCast(*const clang.BuiltinType, ty); |
| 4905 | return ZigClangBuiltinType_getKind(builtin_ty) == .Void; | 4905 | return builtin_ty.getKind() == .Void; |
| 4906 | } | 4906 | } |
| 4907 | return false; | 4907 | return false; |
| 4908 | } | 4908 | } |
| ... | @@ -4910,16 +4910,16 @@ fn isCVoid(qt: ZigClangQualType) bool { | ... | @@ -4910,16 +4910,16 @@ fn isCVoid(qt: ZigClangQualType) bool { |
| 4910 | const FnDeclContext = struct { | 4910 | const FnDeclContext = struct { |
| 4911 | fn_name: []const u8, | 4911 | fn_name: []const u8, |
| 4912 | has_body: bool, | 4912 | has_body: bool, |
| 4913 | storage_class: ZigClangStorageClass, | 4913 | storage_class: clang.StorageClass, |
| 4914 | is_export: bool, | 4914 | is_export: bool, |
| 4915 | }; | 4915 | }; |
| 4916 | 4916 | ||
| 4917 | fn transCC( | 4917 | fn transCC( |
| 4918 | rp: RestorePoint, | 4918 | rp: RestorePoint, |
| 4919 | fn_ty: *const ZigClangFunctionType, | 4919 | fn_ty: *const clang.FunctionType, |
| 4920 | source_loc: ZigClangSourceLocation, | 4920 | source_loc: clang.SourceLocation, |
| 4921 | ) !CallingConvention { | 4921 | ) !CallingConvention { |
| 4922 | const clang_cc = ZigClangFunctionType_getCallConv(fn_ty); | 4922 | const clang_cc = fn_ty.getCallConv(); |
| 4923 | switch (clang_cc) { | 4923 | switch (clang_cc) { |
| 4924 | .C => return CallingConvention.C, | 4924 | .C => return CallingConvention.C, |
| 4925 | .X86StdCall => return CallingConvention.Stdcall, | 4925 | .X86StdCall => return CallingConvention.Stdcall, |
| ... | @@ -4940,22 +4940,22 @@ fn transCC( | ... | @@ -4940,22 +4940,22 @@ fn transCC( |
| 4940 | 4940 | ||
| 4941 | fn transFnProto( | 4941 | fn transFnProto( |
| 4942 | rp: RestorePoint, | 4942 | rp: RestorePoint, |
| 4943 | fn_decl: ?*const ZigClangFunctionDecl, | 4943 | fn_decl: ?*const clang.FunctionDecl, |
| 4944 | fn_proto_ty: *const ZigClangFunctionProtoType, | 4944 | fn_proto_ty: *const clang.FunctionProtoType, |
| 4945 | source_loc: ZigClangSourceLocation, | 4945 | source_loc: clang.SourceLocation, |
| 4946 | fn_decl_context: ?FnDeclContext, | 4946 | fn_decl_context: ?FnDeclContext, |
| 4947 | is_pub: bool, | 4947 | is_pub: bool, |
| 4948 | ) !*ast.Node.FnProto { | 4948 | ) !*ast.Node.FnProto { |
| 4949 | const fn_ty = @ptrCast(*const ZigClangFunctionType, fn_proto_ty); | 4949 | const fn_ty = @ptrCast(*const clang.FunctionType, fn_proto_ty); |
| 4950 | const cc = try transCC(rp, fn_ty, source_loc); | 4950 | const cc = try transCC(rp, fn_ty, source_loc); |
| 4951 | const is_var_args = ZigClangFunctionProtoType_isVariadic(fn_proto_ty); | 4951 | const is_var_args = fn_proto_ty.isVariadic(); |
| 4952 | return finishTransFnProto(rp, fn_decl, fn_proto_ty, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub); | 4952 | return finishTransFnProto(rp, fn_decl, fn_proto_ty, fn_ty, source_loc, fn_decl_context, is_var_args, cc, is_pub); |
| 4953 | } | 4953 | } |
| 4954 | 4954 | ||
| 4955 | fn transFnNoProto( | 4955 | fn transFnNoProto( |
| 4956 | rp: RestorePoint, | 4956 | rp: RestorePoint, |
| 4957 | fn_ty: *const ZigClangFunctionType, | 4957 | fn_ty: *const clang.FunctionType, |
| 4958 | source_loc: ZigClangSourceLocation, | 4958 | source_loc: clang.SourceLocation, |
| 4959 | fn_decl_context: ?FnDeclContext, | 4959 | fn_decl_context: ?FnDeclContext, |
| 4960 | is_pub: bool, | 4960 | is_pub: bool, |
| 4961 | ) !*ast.Node.FnProto { | 4961 | ) !*ast.Node.FnProto { |
| ... | @@ -4966,10 +4966,10 @@ fn transFnNoProto( | ... | @@ -4966,10 +4966,10 @@ fn transFnNoProto( |
| 4966 | 4966 | ||
| 4967 | fn finishTransFnProto( | 4967 | fn finishTransFnProto( |
| 4968 | rp: RestorePoint, | 4968 | rp: RestorePoint, |
| 4969 | fn_decl: ?*const ZigClangFunctionDecl, | 4969 | fn_decl: ?*const clang.FunctionDecl, |
| 4970 | fn_proto_ty: ?*const ZigClangFunctionProtoType, | 4970 | fn_proto_ty: ?*const clang.FunctionProtoType, |
| 4971 | fn_ty: *const ZigClangFunctionType, | 4971 | fn_ty: *const clang.FunctionType, |
| 4972 | source_loc: ZigClangSourceLocation, | 4972 | source_loc: clang.SourceLocation, |
| 4973 | fn_decl_context: ?FnDeclContext, | 4973 | fn_decl_context: ?FnDeclContext, |
| 4974 | is_var_args: bool, | 4974 | is_var_args: bool, |
| 4975 | cc: CallingConvention, | 4975 | cc: CallingConvention, |
| ... | @@ -4995,19 +4995,19 @@ fn finishTransFnProto( | ... | @@ -4995,19 +4995,19 @@ fn finishTransFnProto( |
| 4995 | 4995 | ||
| 4996 | var fn_params = std.ArrayList(ast.Node.FnProto.ParamDecl).init(rp.c.gpa); | 4996 | var fn_params = std.ArrayList(ast.Node.FnProto.ParamDecl).init(rp.c.gpa); |
| 4997 | defer fn_params.deinit(); | 4997 | defer fn_params.deinit(); |
| 4998 | const param_count: usize = if (fn_proto_ty != null) ZigClangFunctionProtoType_getNumParams(fn_proto_ty.?) else 0; | 4998 | const param_count: usize = if (fn_proto_ty != null) fn_proto_ty.?.getNumParams() else 0; |
| 4999 | try fn_params.ensureCapacity(param_count + 1); // +1 for possible var args node | 4999 | try fn_params.ensureCapacity(param_count + 1); // +1 for possible var args node |
| 5000 | 5000 | ||
| 5001 | var i: usize = 0; | 5001 | var i: usize = 0; |
| 5002 | while (i < param_count) : (i += 1) { | 5002 | while (i < param_count) : (i += 1) { |
| 5003 | const param_qt = ZigClangFunctionProtoType_getParamType(fn_proto_ty.?, @intCast(c_uint, i)); | 5003 | const param_qt = fn_proto_ty.?.getParamType(@intCast(c_uint, i)); |
| 5004 | 5004 | ||
| 5005 | const noalias_tok = if (ZigClangQualType_isRestrictQualified(param_qt)) try appendToken(rp.c, .Keyword_noalias, "noalias") else null; | 5005 | const noalias_tok = if (param_qt.isRestrictQualified()) try appendToken(rp.c, .Keyword_noalias, "noalias") else null; |
| 5006 | 5006 | ||
| 5007 | const param_name_tok: ?ast.TokenIndex = blk: { | 5007 | const param_name_tok: ?ast.TokenIndex = blk: { |
| 5008 | if (fn_decl) |decl| { | 5008 | if (fn_decl) |decl| { |
| 5009 | const param = ZigClangFunctionDecl_getParamDecl(decl, @intCast(c_uint, i)); | 5009 | const param = decl.getParamDecl(@intCast(c_uint, i)); |
| 5010 | const param_name: []const u8 = try rp.c.str(ZigClangNamedDecl_getName_bytes_begin(@ptrCast(*const ZigClangNamedDecl, param))); | 5010 | const param_name: []const u8 = try rp.c.str(@ptrCast(*const clang.NamedDecl, param).getName_bytes_begin()); |
| 5011 | if (param_name.len < 1) | 5011 | if (param_name.len < 1) |
| 5012 | break :blk null; | 5012 | break :blk null; |
| 5013 | 5013 | ||
| ... | @@ -5045,7 +5045,7 @@ fn finishTransFnProto( | ... | @@ -5045,7 +5045,7 @@ fn finishTransFnProto( |
| 5045 | const linksection_expr = blk: { | 5045 | const linksection_expr = blk: { |
| 5046 | if (fn_decl) |decl| { | 5046 | if (fn_decl) |decl| { |
| 5047 | var str_len: usize = undefined; | 5047 | var str_len: usize = undefined; |
| 5048 | if (ZigClangFunctionDecl_getSectionAttribute(decl, &str_len)) |str_ptr| { | 5048 | if (decl.getSectionAttribute(&str_len)) |str_ptr| { |
| 5049 | _ = try appendToken(rp.c, .Keyword_linksection, "linksection"); | 5049 | _ = try appendToken(rp.c, .Keyword_linksection, "linksection"); |
| 5050 | _ = try appendToken(rp.c, .LParen, "("); | 5050 | _ = try appendToken(rp.c, .LParen, "("); |
| 5051 | const expr = try transCreateNodeStringLiteral( | 5051 | const expr = try transCreateNodeStringLiteral( |
| ... | @@ -5062,7 +5062,7 @@ fn finishTransFnProto( | ... | @@ -5062,7 +5062,7 @@ fn finishTransFnProto( |
| 5062 | 5062 | ||
| 5063 | const align_expr = blk: { | 5063 | const align_expr = blk: { |
| 5064 | if (fn_decl) |decl| { | 5064 | if (fn_decl) |decl| { |
| 5065 | const alignment = ZigClangFunctionDecl_getAlignedAttribute(decl, rp.c.clang_context); | 5065 | const alignment = decl.getAlignedAttribute(rp.c.clang_context); |
| 5066 | if (alignment != 0) { | 5066 | if (alignment != 0) { |
| 5067 | _ = try appendToken(rp.c, .Keyword_align, "align"); | 5067 | _ = try appendToken(rp.c, .Keyword_align, "align"); |
| 5068 | _ = try appendToken(rp.c, .LParen, "("); | 5068 | _ = try appendToken(rp.c, .LParen, "("); |
| ... | @@ -5085,10 +5085,10 @@ fn finishTransFnProto( | ... | @@ -5085,10 +5085,10 @@ fn finishTransFnProto( |
| 5085 | }; | 5085 | }; |
| 5086 | 5086 | ||
| 5087 | const return_type_node = blk: { | 5087 | const return_type_node = blk: { |
| 5088 | if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) { | 5088 | if (fn_ty.getNoReturnAttr()) { |
| 5089 | break :blk try transCreateNodeIdentifier(rp.c, "noreturn"); | 5089 | break :blk try transCreateNodeIdentifier(rp.c, "noreturn"); |
| 5090 | } else { | 5090 | } else { |
| 5091 | const return_qt = ZigClangFunctionType_getReturnType(fn_ty); | 5091 | const return_qt = fn_ty.getReturnType(); |
| 5092 | if (isCVoid(return_qt)) { | 5092 | if (isCVoid(return_qt)) { |
| 5093 | // convert primitive c_void to actual void (only for return type) | 5093 | // convert primitive c_void to actual void (only for return type) |
| 5094 | break :blk try transCreateNodeIdentifier(rp.c, "void"); | 5094 | break :blk try transCreateNodeIdentifier(rp.c, "void"); |
| ... | @@ -5136,7 +5136,7 @@ fn finishTransFnProto( | ... | @@ -5136,7 +5136,7 @@ fn finishTransFnProto( |
| 5136 | fn revertAndWarn( | 5136 | fn revertAndWarn( |
| 5137 | rp: RestorePoint, | 5137 | rp: RestorePoint, |
| 5138 | err: anytype, | 5138 | err: anytype, |
| 5139 | source_loc: ZigClangSourceLocation, | 5139 | source_loc: clang.SourceLocation, |
| 5140 | comptime format: []const u8, | 5140 | comptime format: []const u8, |
| 5141 | args: anytype, | 5141 | args: anytype, |
| 5142 | ) (@TypeOf(err) || error{OutOfMemory}) { | 5142 | ) (@TypeOf(err) || error{OutOfMemory}) { |
| ... | @@ -5145,12 +5145,12 @@ fn revertAndWarn( | ... | @@ -5145,12 +5145,12 @@ fn revertAndWarn( |
| 5145 | return err; | 5145 | return err; |
| 5146 | } | 5146 | } |
| 5147 | 5147 | ||
| 5148 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: anytype) !void { | 5148 | fn emitWarning(c: *Context, loc: clang.SourceLocation, comptime format: []const u8, args: anytype) !void { |
| 5149 | const args_prefix = .{c.locStr(loc)}; | 5149 | const args_prefix = .{c.locStr(loc)}; |
| 5150 | _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args); | 5150 | _ = try appendTokenFmt(c, .LineComment, "// {}: warning: " ++ format, args_prefix ++ args); |
| 5151 | } | 5151 | } |
| 5152 | 5152 | ||
| 5153 | pub fn failDecl(c: *Context, loc: ZigClangSourceLocation, name: []const u8, comptime format: []const u8, args: anytype) !void { | 5153 | pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, comptime format: []const u8, args: anytype) !void { |
| 5154 | // pub const name = @compileError(msg); | 5154 | // pub const name = @compileError(msg); |
| 5155 | const pub_tok = try appendToken(c, .Keyword_pub, "pub"); | 5155 | const pub_tok = try appendToken(c, .Keyword_pub, "pub"); |
| 5156 | const const_tok = try appendToken(c, .Keyword_const, "const"); | 5156 | const const_tok = try appendToken(c, .Keyword_const, "const"); |
| ... | @@ -5287,14 +5287,14 @@ fn transCreateNodeIdentifierUnchecked(c: *Context, name: []const u8) !*ast.Node | ... | @@ -5287,14 +5287,14 @@ fn transCreateNodeIdentifierUnchecked(c: *Context, name: []const u8) !*ast.Node |
| 5287 | } | 5287 | } |
| 5288 | 5288 | ||
| 5289 | pub fn freeErrors(errors: []ClangErrMsg) void { | 5289 | pub fn freeErrors(errors: []ClangErrMsg) void { |
| 5290 | ZigClangErrorMsg_delete(errors.ptr, errors.len); | 5290 | errors.ptr.delete(errors.len); |
| 5291 | } | 5291 | } |
| 5292 | 5292 | ||
| 5293 | const MacroCtx = struct { | 5293 | const MacroCtx = struct { |
| 5294 | source: []const u8, | 5294 | source: []const u8, |
| 5295 | list: []const CToken, | 5295 | list: []const CToken, |
| 5296 | i: usize = 0, | 5296 | i: usize = 0, |
| 5297 | loc: ZigClangSourceLocation, | 5297 | loc: clang.SourceLocation, |
| 5298 | name: []const u8, | 5298 | name: []const u8, |
| 5299 | 5299 | ||
| 5300 | fn peek(self: *MacroCtx) ?CToken.Id { | 5300 | fn peek(self: *MacroCtx) ?CToken.Id { |
| ... | @@ -5318,22 +5318,22 @@ const MacroCtx = struct { | ... | @@ -5318,22 +5318,22 @@ const MacroCtx = struct { |
| 5318 | } | 5318 | } |
| 5319 | }; | 5319 | }; |
| 5320 | 5320 | ||
| 5321 | fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { | 5321 | fn transPreprocessorEntities(c: *Context, unit: *clang.ASTUnit) Error!void { |
| 5322 | // TODO if we see #undef, delete it from the table | 5322 | // TODO if we see #undef, delete it from the table |
| 5323 | var it = ZigClangASTUnit_getLocalPreprocessingEntities_begin(unit); | 5323 | var it = unit.getLocalPreprocessingEntities_begin(); |
| 5324 | const it_end = ZigClangASTUnit_getLocalPreprocessingEntities_end(unit); | 5324 | const it_end = unit.getLocalPreprocessingEntities_end(); |
| 5325 | var tok_list = std.ArrayList(CToken).init(c.gpa); | 5325 | var tok_list = std.ArrayList(CToken).init(c.gpa); |
| 5326 | defer tok_list.deinit(); | 5326 | defer tok_list.deinit(); |
| 5327 | const scope = c.global_scope; | 5327 | const scope = c.global_scope; |
| 5328 | 5328 | ||
| 5329 | while (it.I != it_end.I) : (it.I += 1) { | 5329 | while (it.I != it_end.I) : (it.I += 1) { |
| 5330 | const entity = ZigClangPreprocessingRecord_iterator_deref(it); | 5330 | const entity = it.deref(); |
| 5331 | tok_list.items.len = 0; | 5331 | tok_list.items.len = 0; |
| 5332 | switch (ZigClangPreprocessedEntity_getKind(entity)) { | 5332 | switch (entity.getKind()) { |
| 5333 | .MacroDefinitionKind => { | 5333 | .MacroDefinitionKind => { |
| 5334 | const macro = @ptrCast(*ZigClangMacroDefinitionRecord, entity); | 5334 | const macro = @ptrCast(*clang.MacroDefinitionRecord, entity); |
| 5335 | const raw_name = ZigClangMacroDefinitionRecord_getName_getNameStart(macro); | 5335 | const raw_name = macro.getName_getNameStart(); |
| 5336 | const begin_loc = ZigClangMacroDefinitionRecord_getSourceRange_getBegin(macro); | 5336 | const begin_loc = macro.getSourceRange_getBegin(); |
| 5337 | 5337 | ||
| 5338 | const name = try c.str(raw_name); | 5338 | const name = try c.str(raw_name); |
| 5339 | // TODO https://github.com/ziglang/zig/issues/3756 | 5339 | // TODO https://github.com/ziglang/zig/issues/3756 |
| ... | @@ -5343,7 +5343,7 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { | ... | @@ -5343,7 +5343,7 @@ fn transPreprocessorEntities(c: *Context, unit: *ZigClangASTUnit) Error!void { |
| 5343 | continue; | 5343 | continue; |
| 5344 | } | 5344 | } |
| 5345 | 5345 | ||
| 5346 | const begin_c = ZigClangSourceManager_getCharacterData(c.source_manager, begin_loc); | 5346 | const begin_c = c.source_manager.getCharacterData(begin_loc); |
| 5347 | const slice = begin_c[0..mem.len(begin_c)]; | 5347 | const slice = begin_c[0..mem.len(begin_c)]; |
| 5348 | 5348 | ||
| 5349 | var tokenizer = std.c.Tokenizer{ | 5349 | var tokenizer = std.c.Tokenizer{ |
src/zig_clang.h+2-1| ... | @@ -68,16 +68,17 @@ struct ZigClangExprEvalResult { | ... | @@ -68,16 +68,17 @@ struct ZigClangExprEvalResult { |
| 68 | ZigClangAPValue Val; | 68 | ZigClangAPValue Val; |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | struct ZigClangAbstractConditionalOperator; | ||
| 71 | struct ZigClangAPFloat; | 72 | struct ZigClangAPFloat; |
| 72 | struct ZigClangAPInt; | 73 | struct ZigClangAPInt; |
| 73 | struct ZigClangAPSInt; | 74 | struct ZigClangAPSInt; |
| 74 | struct ZigClangAPValue; | ||
| 75 | struct ZigClangASTContext; | 75 | struct ZigClangASTContext; |
| 76 | struct ZigClangASTUnit; | 76 | struct ZigClangASTUnit; |
| 77 | struct ZigClangArraySubscriptExpr; | 77 | struct ZigClangArraySubscriptExpr; |
| 78 | struct ZigClangArrayType; | 78 | struct ZigClangArrayType; |
| 79 | struct ZigClangAttributedType; | 79 | struct ZigClangAttributedType; |
| 80 | struct ZigClangBinaryOperator; | 80 | struct ZigClangBinaryOperator; |
| 81 | struct ZigClangBinaryConditionalOperator; | ||
| 81 | struct ZigClangBreakStmt; | 82 | struct ZigClangBreakStmt; |
| 82 | struct ZigClangBuiltinType; | 83 | struct ZigClangBuiltinType; |
| 83 | struct ZigClangCStyleCastExpr; | 84 | struct ZigClangCStyleCastExpr; |
test/compile_errors.zig+55-32| ... | @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("array in c exported function", | ||
| 6 | \\export fn zig_array(x: [10]u8) void { | ||
| 7 | \\ expect(std.mem.eql(u8, &x, "1234567890")); | ||
| 8 | \\} | ||
| 9 | \\ | ||
| 10 | \\export fn zig_return_array() [10]u8 { | ||
| 11 | \\ return "1234567890".*; | ||
| 12 | \\} | ||
| 13 | , &[_][]const u8{ | ||
| 14 | "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'", | ||
| 15 | "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", | ||
| 16 | }); | ||
| 17 | |||
| 5 | cases.add("@Type for exhaustive enum with undefined tag type", | 18 | cases.add("@Type for exhaustive enum with undefined tag type", |
| 6 | \\const TypeInfo = @import("builtin").TypeInfo; | 19 | \\const TypeInfo = @import("builtin").TypeInfo; |
| 7 | \\const Tag = @Type(.{ | 20 | \\const Tag = @Type(.{ |
| ... | @@ -125,6 +138,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -125,6 +138,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 125 | "tmp.zig:15:23: error: enum field missing: 'arst'", | 138 | "tmp.zig:15:23: error: enum field missing: 'arst'", |
| 126 | "tmp.zig:27:24: note: referenced here", | 139 | "tmp.zig:27:24: note: referenced here", |
| 127 | }); | 140 | }); |
| 141 | |||
| 142 | cases.add("field access of opaque type", | ||
| 143 | \\const MyType = opaque {}; | ||
| 144 | \\ | ||
| 145 | \\export fn entry() bool { | ||
| 146 | \\ var x: i32 = 1; | ||
| 147 | \\ return bar(@ptrCast(*MyType, &x)); | ||
| 148 | \\} | ||
| 149 | \\ | ||
| 150 | \\fn bar(x: *MyType) bool { | ||
| 151 | \\ return x.blah; | ||
| 152 | \\} | ||
| 153 | , &[_][]const u8{ | ||
| 154 | "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", | ||
| 155 | }); | ||
| 156 | |||
| 157 | cases.add("opaque type with field", | ||
| 158 | \\const Opaque = opaque { foo: i32 }; | ||
| 159 | \\export fn entry() void { | ||
| 160 | \\ const foo: ?*Opaque = null; | ||
| 161 | \\} | ||
| 162 | , &[_][]const u8{ | ||
| 163 | "tmp.zig:1:25: error: opaque types cannot have fields", | ||
| 164 | }); | ||
| 165 | |||
| 128 | cases.add("@Type(.Fn) with is_generic = true", | 166 | cases.add("@Type(.Fn) with is_generic = true", |
| 129 | \\const Foo = @Type(.{ | 167 | \\const Foo = @Type(.{ |
| 130 | \\ .Fn = .{ | 168 | \\ .Fn = .{ |
| ... | @@ -180,7 +218,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -180,7 +218,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 180 | \\ .layout = .Auto, | 218 | \\ .layout = .Auto, |
| 181 | \\ .tag_type = null, | 219 | \\ .tag_type = null, |
| 182 | \\ .fields = &[_]TypeInfo.UnionField{ | 220 | \\ .fields = &[_]TypeInfo.UnionField{ |
| 183 | \\ .{ .name = "foo", .field_type = @Type(.Opaque), .alignment = 1 }, | 221 | \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, |
| 184 | \\ }, | 222 | \\ }, |
| 185 | \\ .decls = &[_]TypeInfo.Declaration{}, | 223 | \\ .decls = &[_]TypeInfo.Declaration{}, |
| 186 | \\ }, | 224 | \\ }, |
| ... | @@ -2287,7 +2325,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2287,7 +2325,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2287 | \\ return error.OutOfMemory; | 2325 | \\ return error.OutOfMemory; |
| 2288 | \\} | 2326 | \\} |
| 2289 | , &[_][]const u8{ | 2327 | , &[_][]const u8{ |
| 2290 | "tmp.zig:2:12: error: error is discarded", | 2328 | "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", |
| 2291 | }); | 2329 | }); |
| 2292 | 2330 | ||
| 2293 | cases.add("volatile on global assembly", | 2331 | cases.add("volatile on global assembly", |
| ... | @@ -2338,9 +2376,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2338,9 +2376,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2338 | \\ return error.Bad; | 2376 | \\ return error.Bad; |
| 2339 | \\} | 2377 | \\} |
| 2340 | , &[_][]const u8{ | 2378 | , &[_][]const u8{ |
| 2341 | "tmp.zig:2:24: error: expression value is ignored", | 2379 | "tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2342 | "tmp.zig:6:25: error: expression value is ignored", | 2380 | "tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2343 | "tmp.zig:10:25: error: expression value is ignored", | 2381 | "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 2344 | }); | 2382 | }); |
| 2345 | 2383 | ||
| 2346 | cases.add("empty while loop body", | 2384 | cases.add("empty while loop body", |
| ... | @@ -2613,7 +2651,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2613,7 +2651,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2613 | }); | 2651 | }); |
| 2614 | 2652 | ||
| 2615 | cases.add("directly embedding opaque type in struct and union", | 2653 | cases.add("directly embedding opaque type in struct and union", |
| 2616 | \\const O = @Type(.Opaque); | 2654 | \\const O = opaque {}; |
| 2617 | \\const Foo = struct { | 2655 | \\const Foo = struct { |
| 2618 | \\ o: O, | 2656 | \\ o: O, |
| 2619 | \\}; | 2657 | \\}; |
| ... | @@ -2628,7 +2666,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -2628,7 +2666,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2628 | \\ var bar: Bar = undefined; | 2666 | \\ var bar: Bar = undefined; |
| 2629 | \\} | 2667 | \\} |
| 2630 | \\export fn c() void { | 2668 | \\export fn c() void { |
| 2631 | \\ var baz: *@Type(.Opaque) = undefined; | 2669 | \\ var baz: *opaque {} = undefined; |
| 2632 | \\ const qux = .{baz.*}; | 2670 | \\ const qux = .{baz.*}; |
| 2633 | \\} | 2671 | \\} |
| 2634 | , &[_][]const u8{ | 2672 | , &[_][]const u8{ |
| ... | @@ -3592,7 +3630,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -3592,7 +3630,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3592 | }); | 3630 | }); |
| 3593 | 3631 | ||
| 3594 | cases.add("unknown length pointer to opaque", | 3632 | cases.add("unknown length pointer to opaque", |
| 3595 | \\export const T = [*]@Type(.Opaque); | 3633 | \\export const T = [*]opaque {}; |
| 3596 | , &[_][]const u8{ | 3634 | , &[_][]const u8{ |
| 3597 | "tmp.zig:1:21: error: unknown-length pointer to opaque", | 3635 | "tmp.zig:1:21: error: unknown-length pointer to opaque", |
| 3598 | }); | 3636 | }); |
| ... | @@ -6236,7 +6274,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6236,7 +6274,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6236 | \\} | 6274 | \\} |
| 6237 | \\fn bar() anyerror!i32 { return 0; } | 6275 | \\fn bar() anyerror!i32 { return 0; } |
| 6238 | , &[_][]const u8{ | 6276 | , &[_][]const u8{ |
| 6239 | "tmp.zig:2:14: error: expression value is ignored", | 6277 | "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", |
| 6240 | }); | 6278 | }); |
| 6241 | 6279 | ||
| 6242 | cases.add("dereference an array", | 6280 | cases.add("dereference an array", |
| ... | @@ -6827,8 +6865,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6827,8 +6865,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6827 | "tmp.zig:2:31: error: index 2 outside array of size 2", | 6865 | "tmp.zig:2:31: error: index 2 outside array of size 2", |
| 6828 | }); | 6866 | }); |
| 6829 | 6867 | ||
| 6830 | cases.add("wrong pointer coerced to pointer to @Type(.Opaque)", | 6868 | cases.add("wrong pointer coerced to pointer to opaque {}", |
| 6831 | \\const Derp = @Type(.Opaque); | 6869 | \\const Derp = opaque {}; |
| 6832 | \\extern fn bar(d: *Derp) void; | 6870 | \\extern fn bar(d: *Derp) void; |
| 6833 | \\export fn foo() void { | 6871 | \\export fn foo() void { |
| 6834 | \\ var x = @as(u8, 1); | 6872 | \\ var x = @as(u8, 1); |
| ... | @@ -6854,8 +6892,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6854,8 +6892,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6854 | \\export fn entry5() void { | 6892 | \\export fn entry5() void { |
| 6855 | \\ var d = null; | 6893 | \\ var d = null; |
| 6856 | \\} | 6894 | \\} |
| 6857 | \\export fn entry6(opaque: *Opaque) void { | 6895 | \\export fn entry6(opaque_: *Opaque) void { |
| 6858 | \\ var e = opaque.*; | 6896 | \\ var e = opaque_.*; |
| 6859 | \\} | 6897 | \\} |
| 6860 | \\export fn entry7() void { | 6898 | \\export fn entry7() void { |
| 6861 | \\ var f = i32; | 6899 | \\ var f = i32; |
| ... | @@ -6866,7 +6904,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6866,7 +6904,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6866 | \\export fn entry9() void { | 6904 | \\export fn entry9() void { |
| 6867 | \\ var z: noreturn = return; | 6905 | \\ var z: noreturn = return; |
| 6868 | \\} | 6906 | \\} |
| 6869 | \\const Opaque = @Type(.Opaque); | 6907 | \\const Opaque = opaque {}; |
| 6870 | \\const Foo = struct { | 6908 | \\const Foo = struct { |
| 6871 | \\ fn bar(self: *const Foo) void {} | 6909 | \\ fn bar(self: *const Foo) void {} |
| 6872 | \\}; | 6910 | \\}; |
| ... | @@ -7019,21 +7057,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7019,21 +7057,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7019 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", | 7057 | "tmp.zig:37:29: error: cannot store runtime value in compile time variable", |
| 7020 | }); | 7058 | }); |
| 7021 | 7059 | ||
| 7022 | cases.add("field access of opaque type", | ||
| 7023 | \\const MyType = @Type(.Opaque); | ||
| 7024 | \\ | ||
| 7025 | \\export fn entry() bool { | ||
| 7026 | \\ var x: i32 = 1; | ||
| 7027 | \\ return bar(@ptrCast(*MyType, &x)); | ||
| 7028 | \\} | ||
| 7029 | \\ | ||
| 7030 | \\fn bar(x: *MyType) bool { | ||
| 7031 | \\ return x.blah; | ||
| 7032 | \\} | ||
| 7033 | , &[_][]const u8{ | ||
| 7034 | "tmp.zig:9:13: error: type '*MyType' does not support field access", | ||
| 7035 | }); | ||
| 7036 | |||
| 7037 | cases.add("invalid legacy unicode escape", | 7060 | cases.add("invalid legacy unicode escape", |
| 7038 | \\export fn entry() void { | 7061 | \\export fn entry() void { |
| 7039 | \\ const a = '\U1234'; | 7062 | \\ const a = '\U1234'; |
| ... | @@ -7623,7 +7646,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7623,7 +7646,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7623 | }); | 7646 | }); |
| 7624 | 7647 | ||
| 7625 | cases.add("function returning opaque type", | 7648 | cases.add("function returning opaque type", |
| 7626 | \\const FooType = @Type(.Opaque); | 7649 | \\const FooType = opaque {}; |
| 7627 | \\export fn bar() !FooType { | 7650 | \\export fn bar() !FooType { |
| 7628 | \\ return error.InvalidValue; | 7651 | \\ return error.InvalidValue; |
| 7629 | \\} | 7652 | \\} |
| ... | @@ -7641,7 +7664,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7641,7 +7664,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7641 | }); | 7664 | }); |
| 7642 | 7665 | ||
| 7643 | cases.add("generic function returning opaque type", | 7666 | cases.add("generic function returning opaque type", |
| 7644 | \\const FooType = @Type(.Opaque); | 7667 | \\const FooType = opaque {}; |
| 7645 | \\fn generic(comptime T: type) !T { | 7668 | \\fn generic(comptime T: type) !T { |
| 7646 | \\ return undefined; | 7669 | \\ return undefined; |
| 7647 | \\} | 7670 | \\} |
| ... | @@ -7665,7 +7688,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -7665,7 +7688,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7665 | }); | 7688 | }); |
| 7666 | 7689 | ||
| 7667 | cases.add("function parameter is opaque", | 7690 | cases.add("function parameter is opaque", |
| 7668 | \\const FooType = @Type(.Opaque); | 7691 | \\const FooType = opaque {}; |
| 7669 | \\export fn entry1() void { | 7692 | \\export fn entry1() void { |
| 7670 | \\ const someFuncPtr: fn (FooType) void = undefined; | 7693 | \\ const someFuncPtr: fn (FooType) void = undefined; |
| 7671 | \\} | 7694 | \\} |
test/gen_h.zig+1-1| ... | @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.GenHContext) void { | ... | @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.GenHContext) void { |
| 74 | }); | 74 | }); |
| 75 | 75 | ||
| 76 | cases.add("declare opaque type", | 76 | cases.add("declare opaque type", |
| 77 | \\const Foo = @Type(.Opaque); | 77 | \\const Foo = opaque {}; |
| 78 | \\ | 78 | \\ |
| 79 | \\export fn entry(foo: ?*Foo) void { } | 79 | \\export fn entry(foo: ?*Foo) void { } |
| 80 | , &[_][]const u8{ | 80 | , &[_][]const u8{ |
test/stage1/behavior/misc.zig+3-3| ... | @@ -438,8 +438,8 @@ export fn writeToVRam() void { | ... | @@ -438,8 +438,8 @@ export fn writeToVRam() void { |
| 438 | vram[0] = 'X'; | 438 | vram[0] = 'X'; |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | const OpaqueA = @Type(.Opaque); | 441 | const OpaqueA = opaque {}; |
| 442 | const OpaqueB = @Type(.Opaque); | 442 | const OpaqueB = opaque {}; |
| 443 | test "opaque types" { | 443 | test "opaque types" { |
| 444 | expect(*OpaqueA != *OpaqueB); | 444 | expect(*OpaqueA != *OpaqueB); |
| 445 | expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); | 445 | expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); |
| ... | @@ -704,7 +704,7 @@ test "auto created variables have correct alignment" { | ... | @@ -704,7 +704,7 @@ test "auto created variables have correct alignment" { |
| 704 | comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | 704 | comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); |
| 705 | } | 705 | } |
| 706 | 706 | ||
| 707 | extern var opaque_extern_var: @Type(.Opaque); | 707 | extern var opaque_extern_var: opaque {}; |
| 708 | var var_to_export: u32 = 42; | 708 | var var_to_export: u32 = 42; |
| 709 | test "extern variable with non-pointer opaque type" { | 709 | test "extern variable with non-pointer opaque type" { |
| 710 | @export(var_to_export, .{ .name = "opaque_extern_var" }); | 710 | @export(var_to_export, .{ .name = "opaque_extern_var" }); |
test/stage1/behavior/type.zig+11-2| ... | @@ -190,8 +190,17 @@ test "Type.ErrorUnion" { | ... | @@ -190,8 +190,17 @@ test "Type.ErrorUnion" { |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | test "Type.Opaque" { | 192 | test "Type.Opaque" { |
| 193 | testing.expect(@Type(.Opaque) != @Type(.Opaque)); | 193 | const Opaque = @Type(.{ |
| 194 | testing.expect(@typeInfo(@Type(.Opaque)) == .Opaque); | 194 | .Opaque = .{ |
| 195 | .decls = &[_]TypeInfo.Declaration{}, | ||
| 196 | }, | ||
| 197 | }); | ||
| 198 | testing.expect(Opaque != opaque {}); | ||
| 199 | testing.expectEqualSlices( | ||
| 200 | TypeInfo.Declaration, | ||
| 201 | &[_]TypeInfo.Declaration{}, | ||
| 202 | @typeInfo(Opaque).Opaque.decls, | ||
| 203 | ); | ||
| 195 | } | 204 | } |
| 196 | 205 | ||
| 197 | test "Type.Vector" { | 206 | test "Type.Vector" { |
test/stage1/behavior/type_info.zig+16-1| ... | @@ -199,7 +199,7 @@ fn testUnion() void { | ... | @@ -199,7 +199,7 @@ fn testUnion() void { |
| 199 | expect(typeinfo_info.Union.tag_type.? == TypeId); | 199 | expect(typeinfo_info.Union.tag_type.? == TypeId); |
| 200 | expect(typeinfo_info.Union.fields.len == 25); | 200 | expect(typeinfo_info.Union.fields.len == 25); |
| 201 | expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); | 201 | expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); |
| 202 | expect(typeinfo_info.Union.decls.len == 21); | 202 | expect(typeinfo_info.Union.decls.len == 22); |
| 203 | 203 | ||
| 204 | const TestNoTagUnion = union { | 204 | const TestNoTagUnion = union { |
| 205 | Foo: void, | 205 | Foo: void, |
| ... | @@ -265,6 +265,21 @@ const TestStruct = packed struct { | ... | @@ -265,6 +265,21 @@ const TestStruct = packed struct { |
| 265 | const Self = @This(); | 265 | const Self = @This(); |
| 266 | }; | 266 | }; |
| 267 | 267 | ||
| 268 | test "type info: opaque info" { | ||
| 269 | testOpaque(); | ||
| 270 | comptime testOpaque(); | ||
| 271 | } | ||
| 272 | |||
| 273 | fn testOpaque() void { | ||
| 274 | const Foo = opaque { | ||
| 275 | const A = 1; | ||
| 276 | fn b() void {} | ||
| 277 | }; | ||
| 278 | |||
| 279 | const foo_info = @typeInfo(Foo); | ||
| 280 | expect(foo_info.Opaque.decls.len == 2); | ||
| 281 | } | ||
| 282 | |||
| 268 | test "type info: function type info" { | 283 | test "type info: function type info" { |
| 269 | // wasm doesn't support align attributes on functions | 284 | // wasm doesn't support align attributes on functions |
| 270 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; | 285 | if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; |
test/stage1/c_abi/cfuncs.c-18| ... | @@ -28,8 +28,6 @@ void zig_ptr(void *); | ... | @@ -28,8 +28,6 @@ void zig_ptr(void *); |
| 28 | 28 | ||
| 29 | void zig_bool(bool); | 29 | void zig_bool(bool); |
| 30 | 30 | ||
| 31 | void zig_array(uint8_t[10]); | ||
| 32 | |||
| 33 | struct BigStruct { | 31 | struct BigStruct { |
| 34 | uint64_t a; | 32 | uint64_t a; |
| 35 | uint64_t b; | 33 | uint64_t b; |
| ... | @@ -97,9 +95,6 @@ void run_c_tests(void) { | ... | @@ -97,9 +95,6 @@ void run_c_tests(void) { |
| 97 | 95 | ||
| 98 | zig_bool(true); | 96 | zig_bool(true); |
| 99 | 97 | ||
| 100 | uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; | ||
| 101 | zig_array(array); | ||
| 102 | |||
| 103 | { | 98 | { |
| 104 | struct BigStruct s = {1, 2, 3, 4, 5}; | 99 | struct BigStruct s = {1, 2, 3, 4, 5}; |
| 105 | zig_big_struct(s); | 100 | zig_big_struct(s); |
| ... | @@ -190,19 +185,6 @@ void c_five_floats(float a, float b, float c, float d, float e) { | ... | @@ -190,19 +185,6 @@ void c_five_floats(float a, float b, float c, float d, float e) { |
| 190 | assert_or_panic(e == 5.0); | 185 | assert_or_panic(e == 5.0); |
| 191 | } | 186 | } |
| 192 | 187 | ||
| 193 | void c_array(uint8_t x[10]) { | ||
| 194 | assert_or_panic(x[0] == '1'); | ||
| 195 | assert_or_panic(x[1] == '2'); | ||
| 196 | assert_or_panic(x[2] == '3'); | ||
| 197 | assert_or_panic(x[3] == '4'); | ||
| 198 | assert_or_panic(x[4] == '5'); | ||
| 199 | assert_or_panic(x[5] == '6'); | ||
| 200 | assert_or_panic(x[6] == '7'); | ||
| 201 | assert_or_panic(x[7] == '8'); | ||
| 202 | assert_or_panic(x[8] == '9'); | ||
| 203 | assert_or_panic(x[9] == '0'); | ||
| 204 | } | ||
| 205 | |||
| 206 | void c_big_struct(struct BigStruct x) { | 188 | void c_big_struct(struct BigStruct x) { |
| 207 | assert_or_panic(x.a == 1); | 189 | assert_or_panic(x.a == 1); |
| 208 | assert_or_panic(x.b == 2); | 190 | assert_or_panic(x.b == 2); |
test/stage1/c_abi/main.zig-11| ... | @@ -116,17 +116,6 @@ export fn zig_bool(x: bool) void { | ... | @@ -116,17 +116,6 @@ export fn zig_bool(x: bool) void { |
| 116 | expect(x); | 116 | expect(x); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | extern fn c_array([10]u8) void; | ||
| 120 | |||
| 121 | test "C ABI array" { | ||
| 122 | var array: [10]u8 = "1234567890".*; | ||
| 123 | c_array(array); | ||
| 124 | } | ||
| 125 | |||
| 126 | export fn zig_array(x: [10]u8) void { | ||
| 127 | expect(std.mem.eql(u8, &x, "1234567890")); | ||
| 128 | } | ||
| 129 | |||
| 130 | const BigStruct = extern struct { | 119 | const BigStruct = extern struct { |
| 131 | a: u64, | 120 | a: u64, |
| 132 | b: u64, | 121 | b: u64, |
test/translate_c.zig+7-7| ... | @@ -137,9 +137,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -137,9 +137,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 137 | \\struct foo { int x; int y[]; }; | 137 | \\struct foo { int x; int y[]; }; |
| 138 | \\struct bar { int x; int y[0]; }; | 138 | \\struct bar { int x; int y[0]; }; |
| 139 | , &[_][]const u8{ | 139 | , &[_][]const u8{ |
| 140 | \\pub const struct_foo = @Type(.Opaque); | 140 | \\pub const struct_foo = opaque {}; |
| 141 | , | 141 | , |
| 142 | \\pub const struct_bar = @Type(.Opaque); | 142 | \\pub const struct_bar = opaque {}; |
| 143 | }); | 143 | }); |
| 144 | 144 | ||
| 145 | cases.add("nested loops without blocks", | 145 | cases.add("nested loops without blocks", |
| ... | @@ -207,7 +207,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -207,7 +207,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 207 | \\pub const struct_arcan_shmif_page = // | 207 | \\pub const struct_arcan_shmif_page = // |
| 208 | , | 208 | , |
| 209 | \\warning: unsupported type: 'Atomic' | 209 | \\warning: unsupported type: 'Atomic' |
| 210 | \\ @Type(.Opaque); // | 210 | \\ opaque {}; // |
| 211 | , | 211 | , |
| 212 | \\ warning: struct demoted to opaque type - unable to translate type of field abufused | 212 | \\ warning: struct demoted to opaque type - unable to translate type of field abufused |
| 213 | , // TODO should be `addr: *struct_arcan_shmif_page` | 213 | , // TODO should be `addr: *struct_arcan_shmif_page` |
| ... | @@ -386,8 +386,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -386,8 +386,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 386 | \\ struct opaque_2 *cast = (struct opaque_2 *)opaque; | 386 | \\ struct opaque_2 *cast = (struct opaque_2 *)opaque; |
| 387 | \\} | 387 | \\} |
| 388 | , &[_][]const u8{ | 388 | , &[_][]const u8{ |
| 389 | \\pub const struct_opaque = @Type(.Opaque); | 389 | \\pub const struct_opaque = opaque {}; |
| 390 | \\pub const struct_opaque_2 = @Type(.Opaque); | 390 | \\pub const struct_opaque_2 = opaque {}; |
| 391 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { | 391 | \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { |
| 392 | \\ var opaque_1 = arg_opaque_1; | 392 | \\ var opaque_1 = arg_opaque_1; |
| 393 | \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); | 393 | \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); |
| ... | @@ -628,7 +628,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -628,7 +628,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 628 | \\ struct Foo *foo; | 628 | \\ struct Foo *foo; |
| 629 | \\}; | 629 | \\}; |
| 630 | , &[_][]const u8{ | 630 | , &[_][]const u8{ |
| 631 | \\pub const struct_Foo = @Type(.Opaque); | 631 | \\pub const struct_Foo = opaque {}; |
| 632 | , | 632 | , |
| 633 | \\pub const struct_Bar = extern struct { | 633 | \\pub const struct_Bar = extern struct { |
| 634 | \\ foo: ?*struct_Foo, | 634 | \\ foo: ?*struct_Foo, |
| ... | @@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 705 | \\struct Foo; | 705 | \\struct Foo; |
| 706 | \\struct Foo *some_func(struct Foo *foo, int x); | 706 | \\struct Foo *some_func(struct Foo *foo, int x); |
| 707 | , &[_][]const u8{ | 707 | , &[_][]const u8{ |
| 708 | \\pub const struct_Foo = @Type(.Opaque); | 708 | \\pub const struct_Foo = opaque {}; |
| 709 | , | 709 | , |
| 710 | \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; | 710 | \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; |
| 711 | , | 711 | , |
tools/update_clang_options.zig+27-1| ... | @@ -130,6 +130,10 @@ const known_options = [_]KnownOpt{ | ... | @@ -130,6 +130,10 @@ const known_options = [_]KnownOpt{ |
| 130 | .name = "assemble", | 130 | .name = "assemble", |
| 131 | .ident = "asm_only", | 131 | .ident = "asm_only", |
| 132 | }, | 132 | }, |
| 133 | .{ | ||
| 134 | .name = "O0", | ||
| 135 | .ident = "optimize", | ||
| 136 | }, | ||
| 133 | .{ | 137 | .{ |
| 134 | .name = "O1", | 138 | .name = "O1", |
| 135 | .ident = "optimize", | 139 | .ident = "optimize", |
| ... | @@ -138,10 +142,20 @@ const known_options = [_]KnownOpt{ | ... | @@ -138,10 +142,20 @@ const known_options = [_]KnownOpt{ |
| 138 | .name = "O2", | 142 | .name = "O2", |
| 139 | .ident = "optimize", | 143 | .ident = "optimize", |
| 140 | }, | 144 | }, |
| 145 | // O3 is only detected from the joined "-O" option | ||
| 146 | .{ | ||
| 147 | .name = "O4", | ||
| 148 | .ident = "optimize", | ||
| 149 | }, | ||
| 141 | .{ | 150 | .{ |
| 142 | .name = "Og", | 151 | .name = "Og", |
| 143 | .ident = "optimize", | 152 | .ident = "optimize", |
| 144 | }, | 153 | }, |
| 154 | .{ | ||
| 155 | .name = "Os", | ||
| 156 | .ident = "optimize", | ||
| 157 | }, | ||
| 158 | // Oz is only detected from the joined "-O" option | ||
| 145 | .{ | 159 | .{ |
| 146 | .name = "O", | 160 | .name = "O", |
| 147 | .ident = "optimize", | 161 | .ident = "optimize", |
| ... | @@ -154,6 +168,14 @@ const known_options = [_]KnownOpt{ | ... | @@ -154,6 +168,14 @@ const known_options = [_]KnownOpt{ |
| 154 | .name = "optimize", | 168 | .name = "optimize", |
| 155 | .ident = "optimize", | 169 | .ident = "optimize", |
| 156 | }, | 170 | }, |
| 171 | .{ | ||
| 172 | .name = "g1", | ||
| 173 | .ident = "debug", | ||
| 174 | }, | ||
| 175 | .{ | ||
| 176 | .name = "gline-tables-only", | ||
| 177 | .ident = "debug", | ||
| 178 | }, | ||
| 157 | .{ | 179 | .{ |
| 158 | .name = "g", | 180 | .name = "g", |
| 159 | .ident = "debug", | 181 | .ident = "debug", |
| ... | @@ -390,6 +412,10 @@ pub fn main() anyerror!void { | ... | @@ -390,6 +412,10 @@ pub fn main() anyerror!void { |
| 390 | // the only way. | 412 | // the only way. |
| 391 | try stdout.print("flagpsl(\"{}\"),\n", .{name}); | 413 | try stdout.print("flagpsl(\"{}\"),\n", .{name}); |
| 392 | } else if (knownOption(name)) |ident| { | 414 | } else if (knownOption(name)) |ident| { |
| 415 | |||
| 416 | // Workaround the fact that in 'Options.td' -Ofast is listed as 'joined' | ||
| 417 | const final_syntax = if (std.mem.eql(u8, name, "Ofast")) .flag else syntax; | ||
| 418 | |||
| 393 | try stdout.print( | 419 | try stdout.print( |
| 394 | \\.{{ | 420 | \\.{{ |
| 395 | \\ .name = "{}", | 421 | \\ .name = "{}", |
| ... | @@ -400,7 +426,7 @@ pub fn main() anyerror!void { | ... | @@ -400,7 +426,7 @@ pub fn main() anyerror!void { |
| 400 | \\ .psl = {}, | 426 | \\ .psl = {}, |
| 401 | \\}}, | 427 | \\}}, |
| 402 | \\ | 428 | \\ |
| 403 | , .{ name, syntax, ident, pd1, pd2, pslash }); | 429 | , .{ name, final_syntax, ident, pd1, pd2, pslash }); |
| 404 | } else if (pd1 and !pd2 and !pslash and syntax == .flag) { | 430 | } else if (pd1 and !pd2 and !pslash and syntax == .flag) { |
| 405 | try stdout.print("flagpd1(\"{}\"),\n", .{name}); | 431 | try stdout.print("flagpd1(\"{}\"),\n", .{name}); |
| 406 | } else if (!pd1 and !pd2 and pslash and syntax == .flag) { | 432 | } else if (!pd1 and !pd2 and pslash and syntax == .flag) { |