@zigc/lib 0.16.0-test.1 → 0.17.0-dev.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/LICENSE +19 -0
  2. package/c/fcntl.zig +6 -1
  3. package/c/inttypes.zig +0 -10
  4. package/c/math.zig +138 -114
  5. package/c/pthread.zig +57 -0
  6. package/c/search.zig +1 -27
  7. package/c/stdlib/drand48.zig +0 -57
  8. package/c/stdlib.zig +0 -100
  9. package/c/string.zig +20 -7
  10. package/c/strings.zig +0 -38
  11. package/c/stropts.zig +17 -0
  12. package/c/unistd.zig +27 -26
  13. package/c/wchar.zig +10 -0
  14. package/c.zig +3 -2
  15. package/compiler/aro/aro/Attribute/names.zig +604 -589
  16. package/compiler/aro/aro/Attribute.zig +202 -116
  17. package/compiler/aro/aro/Builtins/common.zig +874 -863
  18. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  19. package/compiler/aro/aro/Builtins.zig +0 -1
  20. package/compiler/aro/aro/CodeGen.zig +8 -7
  21. package/compiler/aro/aro/Compilation.zig +137 -111
  22. package/compiler/aro/aro/Diagnostics.zig +21 -17
  23. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  24. package/compiler/aro/aro/Driver.zig +138 -63
  25. package/compiler/aro/aro/LangOpts.zig +12 -2
  26. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  27. package/compiler/aro/aro/Parser.zig +352 -153
  28. package/compiler/aro/aro/Pragma.zig +3 -2
  29. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  30. package/compiler/aro/aro/Preprocessor.zig +136 -62
  31. package/compiler/aro/aro/Target.zig +17 -12
  32. package/compiler/aro/aro/Tokenizer.zig +31 -14
  33. package/compiler/aro/aro/Toolchain.zig +4 -7
  34. package/compiler/aro/aro/Tree.zig +178 -148
  35. package/compiler/aro/aro/TypeStore.zig +82 -24
  36. package/compiler/aro/aro/Value.zig +13 -17
  37. package/compiler/aro/aro/features.zig +1 -0
  38. package/compiler/aro/aro/pragmas/message.zig +3 -2
  39. package/compiler/aro/aro/pragmas/once.zig +0 -1
  40. package/compiler/aro/aro/record_layout.zig +3 -3
  41. package/compiler/aro/aro/text_literal.zig +3 -2
  42. package/compiler/aro/assembly_backend/x86_64.zig +7 -8
  43. package/compiler/aro/backend/Assembly.zig +1 -2
  44. package/compiler/aro/backend/Interner.zig +2 -2
  45. package/compiler/aro/backend/Ir.zig +100 -92
  46. package/compiler/aro/include/ptrcheck.h +49 -0
  47. package/compiler/aro/main.zig +26 -10
  48. package/compiler/build_runner.zig +1 -2
  49. package/compiler/objdump.zig +93 -0
  50. package/compiler/reduce/Walk.zig +7 -7
  51. package/compiler/reduce.zig +5 -1
  52. package/compiler/resinator/compile.zig +2 -2
  53. package/compiler/resinator/main.zig +7 -1
  54. package/compiler/resinator/preprocess.zig +1 -3
  55. package/compiler/std-docs.zig +8 -1
  56. package/compiler/test_runner.zig +194 -62
  57. package/compiler/translate-c/MacroTranslator.zig +80 -11
  58. package/compiler/translate-c/PatternList.zig +1 -9
  59. package/compiler/translate-c/Scope.zig +43 -6
  60. package/compiler/translate-c/Translator.zig +369 -127
  61. package/compiler/translate-c/ast.zig +19 -11
  62. package/compiler/translate-c/main.zig +76 -17
  63. package/compiler_rt/cos.zig +140 -53
  64. package/compiler_rt/divmodei4.zig +40 -17
  65. package/compiler_rt/exp.zig +1 -6
  66. package/compiler_rt/exp2.zig +1 -6
  67. package/compiler_rt/exp_f128.zig +377 -0
  68. package/compiler_rt/fabs.zig +0 -2
  69. package/compiler_rt/fma.zig +0 -2
  70. package/compiler_rt/fmax.zig +0 -2
  71. package/compiler_rt/fmin.zig +0 -2
  72. package/compiler_rt/fmod.zig +0 -2
  73. package/compiler_rt/limb64.zig +1127 -0
  74. package/compiler_rt/log.zig +0 -2
  75. package/compiler_rt/log10.zig +0 -2
  76. package/compiler_rt/log2.zig +0 -2
  77. package/compiler_rt/long_double.zig +37 -0
  78. package/compiler_rt/mulXi3.zig +1 -1
  79. package/compiler_rt/mulo.zig +6 -1
  80. package/compiler_rt/rem_pio2l.zig +173 -0
  81. package/compiler_rt/round.zig +0 -2
  82. package/compiler_rt/sin.zig +139 -56
  83. package/compiler_rt/sincos.zig +277 -72
  84. package/compiler_rt/sqrt.zig +0 -2
  85. package/compiler_rt/ssp.zig +1 -1
  86. package/compiler_rt/tan.zig +117 -48
  87. package/compiler_rt/trig.zig +256 -6
  88. package/compiler_rt/trunc.zig +0 -2
  89. package/compiler_rt/udivmodei4.zig +28 -0
  90. package/compiler_rt.zig +2 -0
  91. package/fuzzer.zig +857 -307
  92. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  93. package/libc/musl/src/math/pow.c +343 -0
  94. package/package.json +1 -1
  95. package/std/Build/Cache.zig +6 -6
  96. package/std/Build/Fuzz.zig +6 -19
  97. package/std/Build/Module.zig +1 -1
  98. package/std/Build/Step/CheckObject.zig +3 -3
  99. package/std/Build/Step/Compile.zig +18 -1
  100. package/std/Build/Step/ConfigHeader.zig +49 -33
  101. package/std/Build/Step/InstallArtifact.zig +18 -0
  102. package/std/Build/Step/Run.zig +538 -89
  103. package/std/Build/Step/TranslateC.zig +0 -6
  104. package/std/Build/Step.zig +10 -19
  105. package/std/Build/WebServer.zig +31 -19
  106. package/std/Build/abi.zig +47 -11
  107. package/std/Build.zig +17 -17
  108. package/std/Io/Dir.zig +7 -2
  109. package/std/Io/Dispatch.zig +5 -13
  110. package/std/Io/File/Reader.zig +3 -1
  111. package/std/Io/File/Writer.zig +8 -6
  112. package/std/Io/File.zig +1 -0
  113. package/std/Io/Kqueue.zig +2 -2
  114. package/std/Io/Reader.zig +8 -9
  115. package/std/Io/Semaphore.zig +112 -17
  116. package/std/Io/Terminal.zig +1 -1
  117. package/std/Io/Threaded.zig +352 -180
  118. package/std/Io/Uring.zig +15 -16
  119. package/std/Io/Writer.zig +46 -42
  120. package/std/Io/net.zig +11 -11
  121. package/std/Io.zig +1052 -20
  122. package/std/SemanticVersion.zig +1 -1
  123. package/std/Target/Query.zig +2 -2
  124. package/std/Target.zig +53 -7
  125. package/std/Thread.zig +8 -3
  126. package/std/array_hash_map.zig +105 -573
  127. package/std/array_list.zig +22 -31
  128. package/std/bit_set.zig +22 -6
  129. package/std/builtin/assembly.zig +68 -0
  130. package/std/builtin.zig +4 -0
  131. package/std/c/haiku.zig +3 -0
  132. package/std/c/serenity.zig +1 -6
  133. package/std/c.zig +106 -24
  134. package/std/compress/flate/Compress.zig +3 -3
  135. package/std/compress/flate/Decompress.zig +2 -3
  136. package/std/compress/zstd/Decompress.zig +2 -4
  137. package/std/crypto/Certificate/Bundle.zig +15 -1
  138. package/std/crypto/Certificate.zig +13 -1
  139. package/std/crypto/ascon.zig +75 -33
  140. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  141. package/std/crypto/codecs/asn1.zig +33 -18
  142. package/std/crypto/codecs/base64_hex_ct.zig +16 -8
  143. package/std/crypto/ml_kem.zig +2 -9
  144. package/std/crypto/tls/Client.zig +79 -4
  145. package/std/crypto/tls.zig +1 -1
  146. package/std/crypto.zig +1 -0
  147. package/std/debug/Dwarf.zig +29 -9
  148. package/std/debug/Info.zig +4 -0
  149. package/std/debug/MachOFile.zig +46 -8
  150. package/std/debug/Pdb.zig +540 -37
  151. package/std/debug/SelfInfo/Elf.zig +19 -18
  152. package/std/debug/SelfInfo/MachO.zig +18 -7
  153. package/std/debug/SelfInfo/Windows.zig +138 -36
  154. package/std/debug.zig +181 -66
  155. package/std/enums.zig +25 -19
  156. package/std/fmt.zig +8 -3
  157. package/std/fs/path.zig +6 -4
  158. package/std/heap/ArenaAllocator.zig +145 -154
  159. package/std/heap/BufferFirstAllocator.zig +165 -0
  160. package/std/heap/debug_allocator.zig +7 -7
  161. package/std/heap.zig +2 -126
  162. package/std/http/Client.zig +31 -30
  163. package/std/http.zig +14 -13
  164. package/std/json/Scanner.zig +2 -2
  165. package/std/json/Stringify.zig +3 -3
  166. package/std/json/dynamic.zig +4 -4
  167. package/std/math/big/int.zig +16 -17
  168. package/std/mem/Allocator.zig +4 -5
  169. package/std/mem.zig +48 -0
  170. package/std/os/emscripten.zig +2 -18
  171. package/std/os/linux/IoUring.zig +2 -0
  172. package/std/os/linux/aarch64.zig +41 -12
  173. package/std/os/linux/arc.zig +173 -0
  174. package/std/os/linux/arm.zig +41 -12
  175. package/std/os/linux/hexagon.zig +33 -11
  176. package/std/os/linux/loongarch32.zig +41 -13
  177. package/std/os/linux/loongarch64.zig +41 -12
  178. package/std/os/linux/m68k.zig +41 -13
  179. package/std/os/linux/mips.zig +67 -36
  180. package/std/os/linux/mips64.zig +60 -29
  181. package/std/os/linux/mipsn32.zig +60 -29
  182. package/std/os/linux/or1k.zig +41 -12
  183. package/std/os/linux/powerpc.zig +41 -12
  184. package/std/os/linux/powerpc64.zig +41 -12
  185. package/std/os/linux/riscv32.zig +41 -12
  186. package/std/os/linux/riscv64.zig +41 -12
  187. package/std/os/linux/s390x.zig +44 -7
  188. package/std/os/linux/sparc64.zig +83 -52
  189. package/std/os/linux/thumb.zig +52 -36
  190. package/std/os/linux/x32.zig +41 -12
  191. package/std/os/linux/x86.zig +42 -13
  192. package/std/os/linux/x86_64.zig +41 -12
  193. package/std/os/linux.zig +419 -438
  194. package/std/os/uefi/tables/boot_services.zig +9 -8
  195. package/std/os/windows.zig +2 -2
  196. package/std/os.zig +41 -0
  197. package/std/pdb.zig +143 -4
  198. package/std/posix.zig +6 -12
  199. package/std/priority_dequeue.zig +13 -12
  200. package/std/priority_queue.zig +5 -4
  201. package/std/process/Child.zig +1 -1
  202. package/std/process/Environ.zig +1 -1
  203. package/std/process.zig +1 -1
  204. package/std/sort.zig +3 -3
  205. package/std/start.zig +17 -4
  206. package/std/std.zig +19 -6
  207. package/std/testing/FailingAllocator.zig +4 -4
  208. package/std/testing/Smith.zig +37 -2
  209. package/std/zig/Ast/Render.zig +187 -459
  210. package/std/zig/Ast.zig +0 -4
  211. package/std/zig/AstGen.zig +86 -103
  212. package/std/zig/AstRlAnnotate.zig +0 -11
  213. package/std/zig/AstSmith.zig +2602 -0
  214. package/std/zig/BuiltinFn.zig +0 -32
  215. package/std/zig/Client.zig +8 -3
  216. package/std/zig/LibCInstallation.zig +4 -3
  217. package/std/zig/Parse.zig +90 -81
  218. package/std/zig/Server.zig +26 -0
  219. package/std/zig/WindowsSdk.zig +13 -13
  220. package/std/zig/Zir.zig +66 -62
  221. package/std/zig/ZonGen.zig +6 -5
  222. package/std/zig/c_translation/helpers.zig +14 -9
  223. package/std/zig/llvm/Builder.zig +119 -60
  224. package/std/zig/system.zig +20 -4
  225. package/std/zig/tokenizer.zig +2 -1
  226. package/std/zig.zig +7 -10
  227. package/std/zip.zig +5 -5
  228. package/zig.h +340 -1
  229. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  230. package/libc/mingw/complex/cabs.c +0 -48
  231. package/libc/mingw/complex/cabsf.c +0 -48
  232. package/libc/mingw/complex/cacos.c +0 -50
  233. package/libc/mingw/complex/cacosf.c +0 -50
  234. package/libc/mingw/complex/carg.c +0 -48
  235. package/libc/mingw/complex/cargf.c +0 -48
  236. package/libc/mingw/complex/casin.c +0 -50
  237. package/libc/mingw/complex/casinf.c +0 -50
  238. package/libc/mingw/complex/catan.c +0 -50
  239. package/libc/mingw/complex/catanf.c +0 -50
  240. package/libc/mingw/complex/ccos.c +0 -50
  241. package/libc/mingw/complex/ccosf.c +0 -50
  242. package/libc/mingw/complex/cexp.c +0 -48
  243. package/libc/mingw/complex/cexpf.c +0 -48
  244. package/libc/mingw/complex/cimag.c +0 -48
  245. package/libc/mingw/complex/cimagf.c +0 -48
  246. package/libc/mingw/complex/clog.c +0 -48
  247. package/libc/mingw/complex/clog10.c +0 -49
  248. package/libc/mingw/complex/clog10f.c +0 -49
  249. package/libc/mingw/complex/clogf.c +0 -48
  250. package/libc/mingw/complex/conj.c +0 -48
  251. package/libc/mingw/complex/conjf.c +0 -48
  252. package/libc/mingw/complex/cpow.c +0 -48
  253. package/libc/mingw/complex/cpowf.c +0 -48
  254. package/libc/mingw/complex/cproj.c +0 -48
  255. package/libc/mingw/complex/cprojf.c +0 -48
  256. package/libc/mingw/complex/creal.c +0 -48
  257. package/libc/mingw/complex/crealf.c +0 -48
  258. package/libc/mingw/complex/csin.c +0 -50
  259. package/libc/mingw/complex/csinf.c +0 -50
  260. package/libc/mingw/complex/csqrt.c +0 -48
  261. package/libc/mingw/complex/csqrtf.c +0 -48
  262. package/libc/mingw/complex/ctan.c +0 -50
  263. package/libc/mingw/complex/ctanf.c +0 -50
  264. package/libc/mingw/math/arm/s_rint.c +0 -86
  265. package/libc/mingw/math/arm/s_rintf.c +0 -51
  266. package/libc/mingw/math/arm/sincos.S +0 -30
  267. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  268. package/libc/mingw/math/arm64/rint.c +0 -12
  269. package/libc/mingw/math/arm64/rintf.c +0 -12
  270. package/libc/mingw/math/arm64/sincos.S +0 -32
  271. package/libc/mingw/math/bsd_private_base.h +0 -148
  272. package/libc/mingw/math/fdiml.c +0 -24
  273. package/libc/mingw/math/frexpf.c +0 -13
  274. package/libc/mingw/math/frexpl.c +0 -71
  275. package/libc/mingw/math/x86/acosf.c +0 -29
  276. package/libc/mingw/math/x86/atanf.c +0 -23
  277. package/libc/mingw/math/x86/atanl.c +0 -18
  278. package/libc/mingw/math/x86/cos.def.h +0 -65
  279. package/libc/mingw/math/x86/cosl.c +0 -46
  280. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  281. package/libc/mingw/math/x86/ldexp.c +0 -23
  282. package/libc/mingw/math/x86/scalbn.S +0 -41
  283. package/libc/mingw/math/x86/scalbnf.S +0 -40
  284. package/libc/mingw/math/x86/sin.def.h +0 -65
  285. package/libc/mingw/math/x86/sinl.c +0 -46
  286. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  287. package/libc/mingw/math/x86/tanl.S +0 -62
  288. package/libc/mingw/misc/btowc.c +0 -28
  289. package/libc/mingw/misc/wcstof.c +0 -66
  290. package/libc/mingw/misc/wcstoimax.c +0 -132
  291. package/libc/mingw/misc/wcstoumax.c +0 -126
  292. package/libc/mingw/misc/wctob.c +0 -29
  293. package/libc/mingw/misc/winbs_uint64.c +0 -6
  294. package/libc/mingw/misc/winbs_ulong.c +0 -6
  295. package/libc/mingw/misc/winbs_ushort.c +0 -6
  296. package/libc/mingw/stdio/_Exit.c +0 -10
  297. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  298. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  299. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  300. package/libc/mingw/stdio/_stat64i32.c +0 -37
  301. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  302. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  303. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  304. package/libc/mingw/winpthreads/spinlock.c +0 -82
  305. package/libc/musl/src/legacy/isastream.c +0 -7
  306. package/libc/musl/src/legacy/valloc.c +0 -8
  307. package/libc/musl/src/linux/tee.c +0 -8
  308. package/libc/musl/src/math/__cosl.c +0 -96
  309. package/libc/musl/src/math/__sinl.c +0 -78
  310. package/libc/musl/src/math/__tanl.c +0 -143
  311. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  312. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  313. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  314. package/libc/musl/src/math/cosl.c +0 -39
  315. package/libc/musl/src/math/fdim.c +0 -10
  316. package/libc/musl/src/math/fdimf.c +0 -10
  317. package/libc/musl/src/math/fdiml.c +0 -18
  318. package/libc/musl/src/math/finite.c +0 -7
  319. package/libc/musl/src/math/finitef.c +0 -7
  320. package/libc/musl/src/math/frexp.c +0 -23
  321. package/libc/musl/src/math/frexpf.c +0 -23
  322. package/libc/musl/src/math/frexpl.c +0 -29
  323. package/libc/musl/src/math/i386/lrint.c +0 -8
  324. package/libc/musl/src/math/i386/lrintf.c +0 -8
  325. package/libc/musl/src/math/i386/rintf.c +0 -7
  326. package/libc/musl/src/math/lrint.c +0 -72
  327. package/libc/musl/src/math/lrintf.c +0 -8
  328. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  329. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  330. package/libc/musl/src/math/rintf.c +0 -30
  331. package/libc/musl/src/math/s390x/rintf.c +0 -15
  332. package/libc/musl/src/math/sincosl.c +0 -60
  333. package/libc/musl/src/math/sinl.c +0 -41
  334. package/libc/musl/src/math/tanl.c +0 -29
  335. package/libc/musl/src/math/x32/lrint.s +0 -5
  336. package/libc/musl/src/math/x32/lrintf.s +0 -5
  337. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  338. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  339. package/libc/musl/src/string/strdup.c +0 -10
  340. package/libc/musl/src/string/strndup.c +0 -12
  341. package/libc/musl/src/string/wcsdup.c +0 -10
  342. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  343. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  344. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  345. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  346. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  347. package/libc/musl/src/unistd/dup2.c +0 -20
  348. package/libc/musl/src/unistd/dup3.c +0 -26
  349. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
  350. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  351. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  352. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
@@ -212,8 +212,9 @@ pub const Diagnostic = struct {
212
212
  };
213
213
 
214
214
  pub fn err(pp: *Preprocessor, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {
215
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
216
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
215
+ var buf: [1024]u8 = undefined;
216
+ var bfa: std.heap.BufferFirstAllocator = .init(&buf, pp.comp.gpa);
217
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
217
218
  defer allocating.deinit();
218
219
 
219
220
  Diagnostics.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -472,3 +472,24 @@ pub const pragma_once_in_main_file: Diagnostic = .{
472
472
  .kind = .warning,
473
473
  .opt = .@"pragma-once-outside-header",
474
474
  };
475
+
476
+ pub const file_name_is_clang_extension: Diagnostic = .{
477
+ .fmt = "__FILE_NAME__ is a clang extension",
478
+ .opt = .@"file-name-extension",
479
+ .kind = .off,
480
+ .extension = true,
481
+ };
482
+
483
+ pub const base_file_is_clang_extension: Diagnostic = .{
484
+ .fmt = "__BASE_FILE__ is a clang extension",
485
+ .opt = .@"base-file-extension",
486
+ .kind = .off,
487
+ .extension = true,
488
+ };
489
+
490
+ pub const include_level_is_clang_extension: Diagnostic = .{
491
+ .fmt = "__INCLUDE_LEVEL__ is a clang extension",
492
+ .opt = .@"include-level-extension",
493
+ .kind = .off,
494
+ .extension = true,
495
+ };
@@ -1,6 +1,6 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const mem = std.mem;
3
+ const path = std.Io.Dir.path;
4
4
  const Allocator = mem.Allocator;
5
5
  const assert = std.debug.assert;
6
6
 
@@ -79,12 +79,15 @@ pub const Macro = struct {
79
79
  });
80
80
 
81
81
  const Object = enum {
82
+ base_file,
82
83
  file,
84
+ file_basename,
83
85
  line,
84
86
  counter,
85
87
  date,
86
88
  time,
87
89
  timestamp,
90
+ include_level,
88
91
  };
89
92
 
90
93
  const Func = enum {
@@ -216,8 +219,6 @@ pub const Macro = struct {
216
219
  }
217
220
  };
218
221
 
219
- const Preprocessor = @This();
220
-
221
222
  const ExpansionEntry = struct {
222
223
  idx: Tree.TokenIndex,
223
224
  locs: [*]Source.Location,
@@ -228,6 +229,8 @@ const TokenState = struct {
228
229
  expansion_entries_len: usize,
229
230
  };
230
231
 
232
+ const Preprocessor = @This();
233
+
231
234
  comp: *Compilation,
232
235
  diagnostics: *Diagnostics,
233
236
 
@@ -275,6 +278,12 @@ m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .empty,
275
278
  /// The dependency file tracking all includes and embeds.
276
279
  dep_file: ?*DepFile = null,
277
280
 
281
+ /// Path prefixes to replace when expanding __FILE__
282
+ path_replacements: []const struct { []const u8, []const u8 } = &.{},
283
+
284
+ /// File used for __BASE_FILE__ macro.
285
+ base_file: Source.Id,
286
+
278
287
  pub const parse = Parser.parse;
279
288
 
280
289
  pub const Linemarkers = enum {
@@ -286,21 +295,22 @@ pub const Linemarkers = enum {
286
295
  numeric_directives,
287
296
  };
288
297
 
289
- pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {
290
- const pp: Preprocessor = .{
291
- .comp = comp,
292
- .diagnostics = comp.diagnostics,
293
- .arena = .init(comp.gpa),
294
- .hideset = .{ .comp = comp },
295
- .source_epoch = source_epoch,
298
+ pub const InitOptions = struct {
299
+ base_file: Source.Id,
300
+
301
+ source_epoch: ?SourceEpoch = null,
302
+ add_builtin_macros: bool = true,
303
+ path_replacements: []const struct { []const u8, []const u8 } = &.{},
304
+
305
+ pub const testing: InitOptions = .{
306
+ .base_file = undefined,
307
+ .source_epoch = .default,
308
+ .add_builtin_macros = false,
296
309
  };
297
- comp.pragmaEvent(.before_preprocess);
298
- return pp;
299
- }
310
+ };
300
311
 
301
- /// Initialize Preprocessor with builtin macros.
302
- pub fn initDefault(comp: *Compilation) !Preprocessor {
303
- const source_epoch: SourceEpoch = comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
312
+ pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {
313
+ const source_epoch: SourceEpoch = options.source_epoch orelse comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
304
314
  error.InvalidEpoch => blk: {
305
315
  const diagnostic: Diagnostic = .invalid_source_epoch;
306
316
  try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });
@@ -308,9 +318,18 @@ pub fn initDefault(comp: *Compilation) !Preprocessor {
308
318
  },
309
319
  };
310
320
 
311
- var pp = init(comp, source_epoch);
321
+ var pp: Preprocessor = .{
322
+ .comp = comp,
323
+ .diagnostics = comp.diagnostics,
324
+ .arena = .init(comp.gpa),
325
+ .hideset = .{ .comp = comp },
326
+ .source_epoch = source_epoch,
327
+ .base_file = options.base_file,
328
+ .path_replacements = options.path_replacements,
329
+ };
312
330
  errdefer pp.deinit();
313
- try pp.addBuiltinMacros();
331
+ comp.pragmaEvent(.before_preprocess);
332
+ if (options.add_builtin_macros) try pp.addBuiltinMacros();
314
333
  return pp;
315
334
  }
316
335
 
@@ -339,7 +358,7 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {
339
358
  try pp.addBuiltinMacro("__is_identifier", .{ .func = .is_identifier });
340
359
  try pp.addBuiltinMacro("_Pragma", .{ .func = .pragma_operator });
341
360
 
342
- if (pp.comp.langopts.emulate == .clang) {
361
+ if (pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) {
343
362
  try pp.addBuiltinMacro("__is_target_arch", .{ .func = .is_target_arch });
344
363
  try pp.addBuiltinMacro("__is_target_vendor", .{ .func = .is_target_vendor });
345
364
  try pp.addBuiltinMacro("__is_target_os", .{ .func = .is_target_os });
@@ -359,6 +378,12 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {
359
378
  try pp.addBuiltinMacro("__DATE__", .{ .obj = .date });
360
379
  try pp.addBuiltinMacro("__TIME__", .{ .obj = .time });
361
380
  try pp.addBuiltinMacro("__TIMESTAMP__", .{ .obj = .timestamp });
381
+
382
+ if (pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) {
383
+ try pp.addBuiltinMacro("__BASE_FILE__", .{ .obj = .base_file });
384
+ try pp.addBuiltinMacro("__FILE_NAME__", .{ .obj = .file_basename });
385
+ try pp.addBuiltinMacro("__INCLUDE_LEVEL__", .{ .obj = .include_level });
386
+ }
362
387
  }
363
388
 
364
389
  pub fn deinit(pp: *Preprocessor) void {
@@ -395,7 +420,7 @@ fn mTime(pp: *Preprocessor, source_id: Source.Id) !u64 {
395
420
  return gop.value_ptr.*;
396
421
  }
397
422
 
398
- pub fn expansionSlice(pp: *Preprocessor, tok: Tree.TokenIndex) []Source.Location {
423
+ pub fn expansionSlice(pp: *const Preprocessor, tok: Tree.TokenIndex) []Source.Location {
399
424
  const S = struct {
400
425
  fn orderTokenIndex(context: Tree.TokenIndex, item: Tree.TokenIndex) std.math.Order {
401
426
  return std.math.order(context, item);
@@ -998,8 +1023,9 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C
998
1023
  defer pp.diagnostics.state.suppress_system_headers = old_suppress_system;
999
1024
  if (diagnostic.show_in_system_headers) pp.diagnostics.state.suppress_system_headers = false;
1000
1025
 
1001
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1002
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
1026
+ var bfa_buf: [1024]u8 = undefined;
1027
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1028
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
1003
1029
  defer allocating.deinit();
1004
1030
 
1005
1031
  Diagnostics.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -1027,8 +1053,9 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C
1027
1053
  }
1028
1054
 
1029
1055
  fn fatal(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) Compilation.Error {
1030
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1031
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
1056
+ var bfa_buf: [1024]u8 = undefined;
1057
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1058
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
1032
1059
  defer allocating.deinit();
1033
1060
 
1034
1061
  Diagnostics.formatArgs(&allocating.writer, fmt, args) catch return error.OutOfMemory;
@@ -1049,8 +1076,9 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
1049
1076
  pp.diagnostics.state.fatal_errors = true;
1050
1077
  defer pp.diagnostics.state.fatal_errors = old;
1051
1078
 
1052
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1053
- const allocator = sf.get();
1079
+ var bfa_buf: [1024]u8 = undefined;
1080
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1081
+ const allocator = bfa.allocator();
1054
1082
  var buf: std.ArrayList(u8) = .empty;
1055
1083
  defer buf.deinit(allocator);
1056
1084
 
@@ -1065,13 +1093,11 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
1065
1093
 
1066
1094
  fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) void {
1067
1095
  @branchHint(.cold);
1068
- const comp = pp.comp;
1069
- const io = comp.io;
1070
- const source = comp.getSource(raw.source);
1096
+ const source = pp.comp.getSource(raw.source);
1071
1097
  const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
1072
1098
 
1073
1099
  var stderr_buf: [4096]u8 = undefined;
1074
- var stderr = Io.File.stderr().writer(io, &stderr_buf);
1100
+ var stderr = std.Io.File.stderr().writer(pp.comp.io, &stderr_buf);
1075
1101
  const w = &stderr.interface;
1076
1102
 
1077
1103
  w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
@@ -1435,7 +1461,37 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1435
1461
  .file => {
1436
1462
  const start = pp.comp.generated_buf.items.len;
1437
1463
  const source = pp.comp.getSource(pp.expansion_source_loc.id);
1438
- try pp.comp.generated_buf.print(gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});
1464
+ for (pp.path_replacements) |replacement| {
1465
+ if (mem.cutPrefix(u8, source.path, replacement[0])) |rest| {
1466
+ try pp.comp.generated_buf.print(gpa, "\"{f}{f}\"", .{ fmtEscapes(replacement[1]), fmtEscapes(rest) });
1467
+ break;
1468
+ }
1469
+ } else {
1470
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});
1471
+ }
1472
+
1473
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1474
+ },
1475
+ .base_file => {
1476
+ try pp.err(pp.expansion_source_loc, .base_file_is_clang_extension, .{});
1477
+ const start = pp.comp.generated_buf.items.len;
1478
+ const base_file = pp.comp.getSource(pp.base_file);
1479
+ for (pp.path_replacements) |replacement| {
1480
+ if (mem.cutPrefix(u8, base_file.path, replacement[0])) |rest| {
1481
+ try pp.comp.generated_buf.print(gpa, "\"{f}{f}\"", .{ fmtEscapes(replacement[1]), fmtEscapes(rest) });
1482
+ }
1483
+ } else {
1484
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"", .{fmtEscapes(base_file.path)});
1485
+ }
1486
+
1487
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1488
+ },
1489
+ .file_basename => {
1490
+ try pp.err(pp.expansion_source_loc, .file_name_is_clang_extension, .{});
1491
+ const start = pp.comp.generated_buf.items.len;
1492
+ const source = pp.comp.getSource(pp.expansion_source_loc.id);
1493
+ const basename = path.basename(source.path);
1494
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"", .{fmtEscapes(basename)});
1439
1495
 
1440
1496
  buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1441
1497
  },
@@ -1472,6 +1528,13 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1472
1528
  try pp.writeDateTimeStamp(.fromBuiltin(builtin_kind), timestamp);
1473
1529
  buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1474
1530
  },
1531
+ .include_level => {
1532
+ try pp.err(pp.expansion_source_loc, .include_level_is_clang_extension, .{});
1533
+ const start = pp.comp.generated_buf.items.len;
1534
+ try pp.comp.generated_buf.print(gpa, "{d}\n", .{pp.include_depth});
1535
+
1536
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));
1537
+ },
1475
1538
  },
1476
1539
  else => buf.appendAssumeCapacity(tok),
1477
1540
  }
@@ -1828,7 +1891,11 @@ fn handleBuiltinMacro(pp: *Preprocessor, builtin: Macro.Builtin.Func, param_toks
1828
1891
  features.hasFeature(pp.comp, ident_str)
1829
1892
  else
1830
1893
  features.hasExtension(pp.comp, ident_str),
1831
- .has_builtin => Builtins.fromName(pp.comp, ident_str) != null or (pp.comp.langopts.emulate == .clang and Macro.Builtin.has_builtin_special_cases.has(ident_str)),
1894
+
1895
+ .has_builtin => Builtins.fromName(pp.comp, ident_str) != null or
1896
+ ((pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) and
1897
+ Macro.Builtin.has_builtin_special_cases.has(ident_str)),
1898
+
1832
1899
  .is_target_arch => pp.comp.isTargetArch(ident_str),
1833
1900
  .is_target_os => pp.comp.isTargetOs(ident_str),
1834
1901
  .is_target_vendor => pp.comp.isTargetVendor(ident_str),
@@ -1972,7 +2039,7 @@ fn expandFuncMacro(
1972
2039
  },
1973
2040
  .macro_param_no_expand => {
1974
2041
  if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {
1975
- hideset = pp.hideset.get(tokFromRaw(func_macro.tokens[tok_i + 1]).loc);
2042
+ hideset = .none;
1976
2043
  }
1977
2044
  const slice = getPasteArgs(args.items[raw.end]);
1978
2045
  const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
@@ -1980,7 +2047,7 @@ fn expandFuncMacro(
1980
2047
  },
1981
2048
  .macro_param => {
1982
2049
  if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {
1983
- hideset = pp.hideset.get(tokFromRaw(func_macro.tokens[tok_i + 1]).loc);
2050
+ hideset = .none;
1984
2051
  }
1985
2052
  const arg = expanded_args.items[raw.end];
1986
2053
  const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
@@ -2330,9 +2397,10 @@ fn expandFuncMacro(
2330
2397
  for (buf.items) |*tok| {
2331
2398
  try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2332
2399
  try tok.addExpansionLocation(gpa, macro_expansion_locs);
2333
- const tok_hidelist = pp.hideset.get(tok.loc);
2334
- const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hideset);
2335
- try pp.hideset.put(tok.loc, new_hidelist);
2400
+ if (tok.id.shouldTrackHideset(.func)) {
2401
+ const new_hideset = try pp.hideset.@"union"(pp.hideset.get(tok.loc), hideset);
2402
+ try pp.hideset.put(tok.loc, new_hideset);
2403
+ }
2336
2404
  }
2337
2405
 
2338
2406
  return buf;
@@ -2698,9 +2766,10 @@ fn expandMacroExhaustive(
2698
2766
  try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2699
2767
  try tok.addExpansionLocation(gpa, macro_expansion_locs);
2700
2768
 
2701
- const tok_hidelist = pp.hideset.get(tok.loc);
2702
- const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hs);
2703
- try pp.hideset.put(tok.loc, new_hidelist);
2769
+ if (tok.id.shouldTrackHideset(.obj)) {
2770
+ const new_hideset = try pp.hideset.@"union"(pp.hideset.get(tok.loc), hs);
2771
+ try pp.hideset.put(tok.loc, new_hideset);
2772
+ }
2704
2773
 
2705
2774
  if (tok.id == .keyword_defined and eval_ctx == .expr) {
2706
2775
  if (macro.is_func) {
@@ -2914,7 +2983,10 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2914
2983
  .placemarker
2915
2984
  else
2916
2985
  pasted_token.id;
2917
- try lhs_toks.append(gpa, try pp.makeGeneratedToken(start, pasted_id, lhs));
2986
+
2987
+ const hideset = try pp.hideset.intersection(pp.hideset.get(lhs.loc), pp.hideset.get(rhs.loc));
2988
+ const generated_token = try pp.makeGeneratedTokenExtra(start, pasted_id, lhs, hideset);
2989
+ try lhs_toks.append(gpa, generated_token);
2918
2990
 
2919
2991
  if (next.id != .nl and next.id != .eof) {
2920
2992
  try pp.err(lhs, .pasting_formed_invalid, .{pp.comp.generated_buf.items[start..end]});
@@ -2924,7 +2996,7 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2924
2996
  try bufCopyTokens(gpa, lhs_toks, rhs_toks[rhs_rest..], &.{});
2925
2997
  }
2926
2998
 
2927
- fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {
2999
+ fn makeGeneratedTokenExtra(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs, hideset: Hideset.Index) !TokenWithExpansionLocs {
2928
3000
  const gpa = pp.comp.gpa;
2929
3001
  var pasted_token = TokenWithExpansionLocs{ .id = id, .loc = .{
2930
3002
  .id = .generated,
@@ -2934,9 +3006,15 @@ fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: Tok
2934
3006
  pp.generated_line += 1;
2935
3007
  try pasted_token.addExpansionLocation(gpa, &.{source.loc});
2936
3008
  try pasted_token.addExpansionLocation(gpa, source.expansionSlice());
3009
+ try pp.hideset.put(pasted_token.loc, hideset);
3010
+
2937
3011
  return pasted_token;
2938
3012
  }
2939
3013
 
3014
+ fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {
3015
+ return pp.makeGeneratedTokenExtra(start, id, source, pp.hideset.get(source.loc));
3016
+ }
3017
+
2940
3018
  /// Defines a new macro and warns if it is a duplicate
2941
3019
  fn defineMacro(pp: *Preprocessor, define_tok: RawToken, name_tok: TokenWithExpansionLocs, macro: Macro) Error!void {
2942
3020
  const name_str = pp.expandedSlice(name_tok);
@@ -3898,16 +3976,14 @@ test "Preserve pragma tokens sometimes" {
3898
3976
  const gpa = std.testing.allocator;
3899
3977
  const Test = struct {
3900
3978
  fn runPreprocessor(source_text: []const u8) ![]const u8 {
3901
- var arena: std.heap.ArenaAllocator = .init(gpa);
3902
- defer arena.deinit();
3903
-
3904
3979
  var diagnostics: Diagnostics = .{ .output = .ignore };
3905
- var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
3980
+ var comp = try Compilation.init(.testing);
3981
+ comp.diagnostics = &diagnostics;
3906
3982
  defer comp.deinit();
3907
3983
 
3908
3984
  try comp.addDefaultPragmaHandlers();
3909
3985
 
3910
- var pp = Preprocessor.init(&comp, .default);
3986
+ var pp = try Preprocessor.init(&comp, .testing);
3911
3987
  defer pp.deinit();
3912
3988
 
3913
3989
  pp.preserve_whitespace = true;
@@ -3966,12 +4042,10 @@ test "destringify" {
3966
4042
  try std.testing.expectEqualStrings(destringified, pp.char_buf.items);
3967
4043
  }
3968
4044
  };
3969
- var arena: std.heap.ArenaAllocator = .init(gpa);
3970
- defer arena.deinit();
3971
- var diagnostics: Diagnostics = .{ .output = .ignore };
3972
- var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
4045
+ var comp = try Compilation.init(.testing);
3973
4046
  defer comp.deinit();
3974
- var pp = Preprocessor.init(&comp, .default);
4047
+
4048
+ var pp = try Preprocessor.init(&comp, .testing);
3975
4049
  defer pp.deinit();
3976
4050
 
3977
4051
  try Test.testDestringify(&pp, "hello\tworld\n", "hello\tworld\n");
@@ -4026,20 +4100,20 @@ test "Include guards" {
4026
4100
  };
4027
4101
  }
4028
4102
 
4029
- fn testIncludeGuard(gpa: std.mem.Allocator, comptime template: []const u8, tok_id: RawToken.Id, expected_guards: u32) !void {
4030
- var arena_state: std.heap.ArenaAllocator = .init(gpa);
4031
- defer arena_state.deinit();
4032
- const arena = arena_state.allocator();
4103
+ fn testIncludeGuard(comptime template: []const u8, tok_id: RawToken.Id, expected_guards: u32) !void {
4104
+ const gpa = std.testing.allocator;
4033
4105
 
4034
4106
  var diagnostics: Diagnostics = .{ .output = .ignore };
4035
- var comp = Compilation.init(gpa, arena, std.testing.io, &diagnostics, Io.Dir.cwd());
4107
+ var comp = try Compilation.init(.testing);
4108
+ comp.diagnostics = &diagnostics;
4036
4109
  defer comp.deinit();
4037
- var pp = Preprocessor.init(&comp, .default);
4110
+ var pp = try Preprocessor.init(&comp, .testing);
4038
4111
  defer pp.deinit();
4039
4112
 
4040
- const path = try std.fs.path.join(arena, &.{ ".", "bar.h" });
4113
+ const file_path = try path.join(gpa, &.{ ".", "bar.h" });
4114
+ defer gpa.free(file_path);
4041
4115
 
4042
- _ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");
4116
+ _ = try comp.addSourceFromBuffer(file_path, "int bar = 5;\n");
4043
4117
 
4044
4118
  var buf: std.ArrayList(u8) = .empty;
4045
4119
  defer buf.deinit(gpa);
@@ -4074,14 +4148,14 @@ test "Include guards" {
4074
4148
  \\#endif
4075
4149
  ;
4076
4150
  const expected_guards: u32 = if (Test.pairsWithIfndef(tag)) 0 else 1;
4077
- try Test.testIncludeGuard(std.testing.allocator, inside_ifndef_template, tag, expected_guards);
4151
+ try Test.testIncludeGuard(inside_ifndef_template, tag, expected_guards);
4078
4152
 
4079
4153
  const outside_ifndef_template =
4080
4154
  \\#ifndef FOO
4081
4155
  \\#endif
4082
4156
  \\#{s}{s}
4083
4157
  ;
4084
- try Test.testIncludeGuard(std.testing.allocator, outside_ifndef_template, tag, 0);
4158
+ try Test.testIncludeGuard(outside_ifndef_template, tag, 0);
4085
4159
  }
4086
4160
  }
4087
4161
  }
@@ -229,7 +229,7 @@ pub fn intMaxType(target: *const Target) QualType {
229
229
  => return .long,
230
230
 
231
231
  .x86_64 => switch (target.os.tag) {
232
- .windows, .openbsd => {},
232
+ .windows, .openbsd, .uefi => {},
233
233
  else => switch (target.abi) {
234
234
  .gnux32, .muslx32 => {},
235
235
  else => return .long,
@@ -546,18 +546,10 @@ pub fn systemCompiler(target: *const Target) LangOpts.Compiler {
546
546
  }
547
547
 
548
548
  pub fn hasFloat128(target: *const Target) bool {
549
- if (target.cpu.arch.isWasm()) return true;
550
549
  if (target.os.tag.isDarwin()) return false;
551
- if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
552
- return switch (target.os.tag) {
553
- .dragonfly,
554
- .haiku,
555
- .linux,
556
- .openbsd,
557
- .illumos,
558
- => target.cpu.arch.isX86(),
559
- else => false,
560
- };
550
+ if (target.os.tag == .windows) return false;
551
+ if (target.cpu.arch.isX86()) return true;
552
+ return target.cTypeBitSize(.longdouble) == 128;
561
553
  }
562
554
 
563
555
  pub fn hasInt128(target: *const Target) bool {
@@ -1238,6 +1230,7 @@ pub fn toLLVMTriple(target: *const Target, buf: []u8) []const u8 {
1238
1230
  .other,
1239
1231
  .plan9,
1240
1232
  .vita,
1233
+ .psp,
1241
1234
  => "unknown",
1242
1235
  };
1243
1236
  writer.writeAll(llvm_os) catch unreachable;
@@ -1356,6 +1349,18 @@ pub fn isPIEDefault(target: *const Target) DefaultPIStatus {
1356
1349
  };
1357
1350
  }
1358
1351
 
1352
+ pub fn ppcElfVersion(target: *const Target) u32 {
1353
+ std.debug.assert(target.cpu.arch.isPowerPC());
1354
+ return switch (target.cpu.arch) {
1355
+ .powerpc64le => 2,
1356
+ .powerpc64 => if ((target.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or target.os.tag == .openbsd or target.abi.isMusl())
1357
+ 2
1358
+ else
1359
+ 1,
1360
+ else => 1,
1361
+ };
1362
+ }
1363
+
1359
1364
  pub fn isPICdefault(target: *const Target) DefaultPIStatus {
1360
1365
  return switch (target.os.tag) {
1361
1366
  .haiku,
@@ -1,5 +1,4 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const assert = std.debug.assert;
4
3
 
5
4
  const Compilation = @import("Compilation.zig");
@@ -891,6 +890,14 @@ pub const Token = struct {
891
890
  else => false,
892
891
  };
893
892
  }
893
+
894
+ pub fn shouldTrackHideset(id: Id, context: enum { func, obj }) bool {
895
+ return switch (id) {
896
+ .identifier, .extended_identifier => true,
897
+ .r_paren => context == .func,
898
+ else => false,
899
+ };
900
+ }
894
901
  };
895
902
 
896
903
  /// double underscore and underscore + capital letter identifiers
@@ -938,6 +945,18 @@ pub const Token = struct {
938
945
  .keyword_unaligned,
939
946
  .keyword_unaligned2,
940
947
  => if (langopts.ms_extensions) kw else .identifier,
948
+
949
+ .keyword_float32,
950
+ .keyword_float64,
951
+ .keyword_float128,
952
+ .keyword_float32x,
953
+ .keyword_float64x,
954
+ .keyword_float128x,
955
+ .keyword_dfloat32,
956
+ .keyword_dfloat64,
957
+ .keyword_dfloat128,
958
+ .keyword_dfloat64x,
959
+ => if (langopts.emulate == .clang) .identifier else kw,
941
960
  else => kw,
942
961
  };
943
962
  }
@@ -2008,11 +2027,11 @@ test "operators" {
2008
2027
  test "keywords" {
2009
2028
  try expectTokens(
2010
2029
  \\auto __auto_type break case char const continue default do
2011
- \\double else enum extern float for goto if int
2012
- \\long register return short signed sizeof static
2013
- \\struct switch typedef union unsigned void volatile
2014
- \\while _Bool _Complex _Imaginary inline restrict _Alignas
2015
- \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
2030
+ \\double else enum extern float for goto if int
2031
+ \\long register return short signed sizeof static
2032
+ \\struct switch typedef union unsigned void volatile
2033
+ \\while _Bool _Complex _Imaginary inline restrict _Alignas
2034
+ \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
2016
2035
  \\__attribute __attribute__
2017
2036
  \\
2018
2037
  , &.{
@@ -2324,13 +2343,13 @@ test "Universal character names" {
2324
2343
 
2325
2344
  test "Tokenizer fuzz test" {
2326
2345
  const Context = struct {
2327
- fn testOne(_: @This(), input_bytes: []const u8) anyerror!void {
2328
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2329
- defer arena.deinit();
2330
- var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
2346
+ fn testOne(_: @This(), smith: *std.testing.Smith) anyerror!void {
2347
+ var comp = try Compilation.init(.testing);
2331
2348
  defer comp.deinit();
2332
2349
 
2333
- const source = try comp.addSourceFromBuffer("fuzz.c", input_bytes);
2350
+ var buf: [256]u8 = undefined;
2351
+ const contents_len = smith.slice(&buf);
2352
+ const source = try comp.addSourceFromBuffer("fuzz.c", buf[0..contents_len]);
2334
2353
 
2335
2354
  var tokenizer: Tokenizer = .{
2336
2355
  .buf = source.buf,
@@ -2350,9 +2369,7 @@ test "Tokenizer fuzz test" {
2350
2369
  }
2351
2370
 
2352
2371
  fn expectTokensExtra(contents: []const u8, expected_tokens: []const Token.Id, langopts: ?LangOpts) !void {
2353
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2354
- defer arena.deinit();
2355
- var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
2372
+ var comp = try Compilation.init(.testing);
2356
2373
  defer comp.deinit();
2357
2374
  if (langopts) |provided| {
2358
2375
  comp.langopts = provided;
@@ -495,9 +495,9 @@ pub fn addSystemIncludeDir(tc: *const Toolchain, path: []const u8) !void {
495
495
  pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
496
496
  const d = tc.driver;
497
497
  const comp = d.comp;
498
+ const io = comp.io;
498
499
  const gpa = comp.gpa;
499
500
  const arena = comp.arena;
500
- const io = comp.io;
501
501
  try d.includes.ensureUnusedCapacity(gpa, 1);
502
502
  if (d.resource_dir) |resource_dir| {
503
503
  const path = try std.fs.path.join(arena, &.{ resource_dir, "include" });
@@ -524,14 +524,12 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
524
524
  /// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned
525
525
  pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 {
526
526
  const comp = tc.driver.comp;
527
- const io = comp.io;
528
- return comp.cwd.readFile(io, path, buf) catch null;
527
+ return comp.cwd.readFile(comp.io, path, buf) catch null;
529
528
  }
530
529
 
531
530
  pub fn exists(tc: *const Toolchain, path: []const u8) bool {
532
531
  const comp = tc.driver.comp;
533
- const io = comp.io;
534
- comp.cwd.access(io, path, .{}) catch return false;
532
+ comp.cwd.access(comp.io, path, .{}) catch return false;
535
533
  return true;
536
534
  }
537
535
 
@@ -549,8 +547,7 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool {
549
547
  }
550
548
 
551
549
  const comp = tc.driver.comp;
552
- const io = comp.io;
553
- comp.cwd.access(io, path, .{ .execute = true }) catch return false;
550
+ comp.cwd.access(comp.io, path, .{ .execute = true }) catch return false;
554
551
  // Todo: ensure path is not a directory
555
552
  return true;
556
553
  }