aboutsummaryrefslogtreecommitdiff
path: root/src/translate_c/ast.zig
AgeCommit message (Collapse)Author
2024-02-28make aro-based translate-c lazily built from sourceAndrew Kelley
Part of #19063. Primarily, this moves Aro from deps/ to lib/compiler/ so that it can be lazily compiled from source. src/aro_translate_c.zig is moved to lib/compiler/aro_translate_c.zig and some of Zig CLI logic moved to a main() function there. aro_translate_c.zig becomes the "common" import for clang-based translate-c. Not all of the compiler was able to be detangled from Aro, however, so it still, for now, remains being compiled with the main compiler sources due to the clang-based translate-c depending on it. Once aro-based translate-c achieves feature parity with the clang-based translate-c implementation, the clang-based one can be removed from Zig. Aro made it unnecessarily difficult to depend on with these .def files and all these Zig module requirements. I looked at the .def files and made these observations: - The canonical source is llvm .def files. - Therefore there is an update process to sync with llvm that involves regenerating the .def files in Aro. - Therefore you might as well just regenerate the .zig files directly and check those into Aro. - Also with a small amount of tinkering, the file size on disk of these generated .zig files can be made many times smaller, without compromising type safety in the usage of the data. This would make things much easier on Zig as downstream project, particularly we could remove those pesky stubs when bootstrapping. I have gone ahead with these changes since they unblock me and I will have a chat with Vexu to see what he thinks.
2023-11-24translate-c: use struct_init_one for empty struct initializerGarrett
2023-11-19compiler: add error for unnecessary use of 'var'mlugg
When a local variable is never used as an lvalue, we can determine that `const` would be sufficient for this variable, so emit an error in this case. More sophisticated checking is unfortunately not possible with Zig's current analysis model, since whether an lvalue is actually mutated depends on semantic analysis, in which some code paths may not be analyzed, so attempting to determine this would result in false positive compile errors. It's worth noting that an unfortunate consequence of this is that any field call `a.b()` will allow `a` to be `var`, even if `b` does not take a pointer as its first parameter - this is again a necessary compromise because the parameter type is not known until semantic analysis. Also update `translate-c` to not trigger these errors. This is done by replacing the `_ = @TypeOf(x)` emitted with `_ = &x` - the reference there means that the local is permitted to be `var`. A similar strategy will be used to prevent compile errors in the behavior tests, where we sometimes want to force a value to be runtime-known. Resolves: #224
2023-10-17Fix rendering ast in zon mode (#17547)Tobias Simetsreiter
Co-authored-by: Tobias Simetsreiter <tobias.simetsreiter@wabtec.com>
2023-09-18translate-c: Struct fields default to zero valueJay Petacat
C99 introduced designated initializers for structs. Omitted fields are implicitly initialized to zero. Some C APIs are designed with this in mind. Defaulting to zero values for translated struct fields permits Zig code to comfortably use such an API. Closes #8165
2023-07-12Update translate-c to new splat syntaxantlilja
2023-06-29translate-c: Use `@constCast` and `@volatileCast` to remove CV-qualifiersEvan Haas
Instead of converting a pointer to an int and then back to a pointer.
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-24translate-c: update to new cast builtin syntaxmlugg
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite themEric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-06-01Use the word 'base' consistently instead of 'radix'Evin Yulo
2023-04-10std.MultiArrayList: add support for tagged unions.GethDW
2023-03-12translate-c: translate extern unknown-length arrays using @externmlugg
Resolves: #14743
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2022-12-17std.builtin: rename Type.UnionField and Type.StructField's field_type to typer00ster91
2022-12-06translate-c: fix wrong logic adjustmentAndrew Kelley
In ea9ad1e85dd5e2ba18e7d55f7a7f9694282159f1, I incorrectly applied boolean logic to one of the pieces of logic, resulting in a regression in translate-c.
2022-12-06remove `-fstage1` optionAndrew Kelley
After this commit, the self-hosted compiler does not offer the option to use stage1 as a backend anymore.
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-18fmt: canonicalize identifiersStevie Hryciw
2022-11-18translate-c: use .identifier tokens in .identifier AST nodesStevie Hryciw
2022-11-03Translate-C Remainder Macro FixNathan Bourgeois
2022-10-28translate-c: Better support for division in macrosEvan Haas
Perform C-style arithmetic conversions on operands to division operator in macros Closes #13162
2022-10-10translate-c: fix the remaining function pointer issuesTau
2022-10-10translate-c: Fix #12263Tau
2022-09-13validate number literals in AstGenVeikka Tuominen
2022-09-13translate-c: lower discards differentlyAndrew Kelley
This makes translate-c lower discards as `_ = @TypeOf(foo);` to avoid tripping the "pointless discard" error. Ideally, translate-c would avoid emitting pointless discards, in which case this commit can be reverted, however, that is a separate enhancement.
2022-07-30translate-c: use correct number of initializers for vectorsEvan Haas
Fixes #12264
2022-07-27translate-c: take address of functions before passing them to @ptrToIntEvan Haas
Fixes #12194
2022-04-15stage2: fix bugs preventing stage2 from building stage3 with LLVMVeikka Tuominen
2022-03-25translate-c: Use @Vector for vector expressionsEvan Haas
Removes translate-c usage of std.meta.Vector, which was deprecated in d42d31f72f
2022-03-11stage2: remove SPDX license header commentsAndrew Kelley
These were missed in d29871977f97b50fe5e3f16cd9c68ebeba02a562.
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-20translate-c: Allow negative denominator in remainder (%) operatorEvan Haas
Fixes #10176
2021-11-04Replace ArrayList.init/ensureTotalCapacity pairs with initCapacityRyan Liptak
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
2021-10-20translate-c: create `inline fn` for always_inlineStéphan Kochen
2021-10-10translate-c: fix logic for checking primitive namesAndrew Kelley
isZigPrimitiveType had a bug where it checked the integer names (e.g. u32) before primitives, leading it to incorrectly return `false` for `undefined` which starts with `u`. Related: #9928
2021-09-28saturating arithmetic modificationsAndrew Kelley
* Remove the builtins `@addWithSaturation`, `@subWithSaturation`, `@mulWithSaturation`, and `@shlWithSaturation` now that we have first-class syntax for saturating arithmetic. * langref: Clarify the behavior of `@shlExact`. * Ast: rename `bit_shift_left` to `shl` and `bit_shift_right` to `shr` for consistency. * Air: rename to include underscore separator with consistency with the rest of the ops. * Air: add shl_exact instruction * Use non-extended tags for saturating arithmetic, to keep it simple so that all the arithmetic operations can be done the same way. - Sema: unify analyzeArithmetic with analyzeSatArithmetic - implement comptime `+|`, `-|`, and `*|` - allow float operands to saturating arithmetic * `<<|` allows any integer type for the RHS. * C backend: fix rebase conflicts * LLVM backend: reduce the amount of branching for arithmetic ops * zig.h: fix magic number not matching actual size of C integer types
2021-09-20Address spaces: AstGenRobin Voetter
Adds AST generation for address spaces on pointers, function prototypes, function declarations and variable declarations. In the latter two cases, declaration properties were already stored more efficiently in a declaration structure. To accomodate these for address spaces, the bit indicating presence of a linksection attribute has been extended to include either linksection, address space, or both.
2021-09-20Address spaces: addrspace(A) parsingRobin Voetter
The grammar for function prototypes, (global) variable declarations, and pointer types now accepts an optional addrspace(A) modifier.
2021-09-19Update all ensureCapacity calls to the relevant non-deprecated versionRyan Liptak
2021-09-01translate-c: rename import_builtin to import_c_builtinEvan Haas
2021-09-01translate-c: improve handling of undefined identifiersEvan Haas
2021-09-01rename std.zig.ast to std.zig.Ast; use top-level fieldsAndrew Kelley
2021-08-29translate-c: remove now unnecessary mangling of primitive type shadowingVeikka Tuominen
Closes #6382
2021-08-28stage2: delete keywords `true`, `false`, `undefined`, `null`Andrew Kelley
The grammar does not need these as keywords; they are merely primitives provided by the language the same as `void`, `u32`, etc.
2021-08-21translate-c: avoid repeating string in type when making it mutableVeikka Tuominen
2021-08-21translate-c: allow string literals to be used as `char *`Evan Haas
In C the type of string literals is `char *`, so when using them in a non-const context we have to cast the const away. Fixes #9126
2021-07-22translate-c: add framework for special-casing macrosEvan Haas
Some macros (for example any macro that uses token pasting) cannot be directly translated to Zig, but may nevertheless still admit a Zig implementation. This provides a mechanism for matching macros against templates and mapping them to functions implemented in c_translation.zig. A macro matches a template if it contains the same sequence of tokens, except that the name and parameters may be renamed. No attempt is made to semantically analyze the macro. For example the following two macros are considered equivalent: ```C ``` But the following two are not: ```C ```