zig/test
mlugg 9ea2076663 translate-c: prevent variable names conflicting with type names
This introduces the concept of a "weak global name" into translate-c.

translate-c consists of two passes. The first is important, because it
discovers all global names, which are used to prevent naming conflicts:
whenever we see an identifier in the second pass, we can mangle it if it
conflicts with any global or any other in-scope identifier.

Unfortunately, this is a bit tricky for structs, unions, and enums. In
C, these types are not represented by normal identifers, but by separate
tags - `struct foo` does not prevent an unrelated identifier `foo`
existing. In general, we want to translate type names to user-friendly
ones such as `struct_foo` and `foo` where possible, but we can't
guarantee such names will not conflict with real variable names.

This is where weak global names come in. In the initial pass, when a
global type declaration is seen, `struct_foo` and `foo` are both added
as weak global names. This essentially means that we will use these
names for the type *if possible*, but if there is another global with
the same name, we will mangle the type name instead. Then, when actually
translating the declaration, we check whether there's a "true" global
with a conflicting name, in which case we mangle our name. If the
user-friendly alias `foo` conflicts, we do not attempt to mangle it: we
just don't emit it, because a mangled alias isn't particularly helpful.
2023-09-18 14:12:33 +03:00
..
behavior std.zig.c_translation.zig: fix L suffix with sized ints 2023-09-18 13:27:32 +03:00
c_abi c-abi: enable passing tests 2023-07-28 19:27:08 -04:00
cases compiler: implement destructuring syntax 2023-09-15 11:33:53 -07:00
link darwin: move inference of SDK version into the linker 2023-08-29 06:43:41 +02:00
src change uses of std.builtin.Mode to OptimizeMode (#16745) 2023-08-09 14:39:34 -04:00
standalone std.http: allow for arbitrary http methods 2023-08-30 13:05:45 -05:00
assemble_and_link.zig
behavior.zig compiler: implement destructuring syntax 2023-09-15 11:33:53 -07:00
cases.zig llvm: fix data layout calculation for experimental llvm targets 2023-08-01 19:20:22 -07:00
cbe.zig std.cstr: deprecate namespace 2023-06-25 14:51:03 -07:00
compare_output.zig std.cstr: deprecate namespace 2023-06-25 14:51:03 -07:00
compile_errors.zig cases: modify error wording to match new errors 2023-08-10 10:00:37 +01:00
gen_h.zig all: zig fmt and rename "@XToY" to "@YFromX" 2023-06-19 12:34:42 -07:00
link.zig macho: add smoke test for re-exports in static libs 2023-08-16 12:19:34 +02:00
llvm_targets.zig llvm: fix data layout calculation for experimental llvm targets 2023-08-01 19:20:22 -07:00
nvptx.zig all: migrate code to new cast builtin syntax 2023-06-24 16:56:39 -07:00
run_translated_c.zig translate-c: prevent variable names conflicting with type names 2023-09-18 14:12:33 +03:00
stack_traces.zig zig fmt: fix extra whitespace with multiline strings 2022-12-17 00:24:58 +02:00
standalone.zig Merge pull request #16885 from squeek502/windows-selfExePath-symlink 2023-08-19 21:24:36 -07:00
tests.zig build: add build test check for availability of IOS SDK on the host 2023-08-18 11:57:12 +02:00
translate_c.zig translate-c: prevent variable names conflicting with type names 2023-09-18 14:12:33 +03:00