This reworks NameBuilder to ease the transition to the system where
the model will be guaranteed to never contain any name collisions, both
between user-specified names and the automatic ones.
This is due to the fact that type inlining currently is broken in some
corner cases involving recursive types.
The bugs are caused by the fact that TypeInlineHelper uses its own
custom graph instead of using the DependencyGraph used by ModelToHeader,
causing different decisions about the order of emission of types.
As a result, the generated C types are not valid C, and they fail to
compile because a field of a struct has a type that is defined later
than its use.
After refactoring TypeInlineHelper to use DependencyGraph like
ModelToHeader, this can be reverted.
When running ModelToHeader in HeaderToModel, all types need to be
defined in the header for clang to successfully parse the file. Add an
option to `ModelToHeaderOptions` that forces all types to be printed
regardless of stack or inlining rules.
This commit makes some of the dependencies among types in
HeadersGeneration stricter than they were before.
The patch is a temporary workaround to the problem of pointers to arrays
of struct/union in C.
Basically, in C, `struct X (*ptr_to_array)[2];` declares a variable
`ptr_to_array` that points to an array with two elements of type `struct
X`. The problem is that, because of a quirk of paragraph 6.7.6.2 of the
C11 standard (Array declarators), to declare `ptr_to_array` it is required
to see the copmlete definition of `struct X`.
Even if MSVC seems to compile it just fine, clang and gcc don't.
In principle this could be worked around by doing the following two
things:
1) introducing wrapper structs around arrays of struct/union that are used
as pointees
2) postpone the complete definition of the wrapper to after the element
type of the array is complete.
However for now we just inject a stronger dependency to enforce ordering.
This is actually stricter than necessary and can yield to be unable to
print valid C code for model that was otherwise perfectly valid and could
have been fixed by injecting the wrapper structs properly.
This particular handling of pointers to array is more strict than actually
necessary. It has been implemented as a workaround, instead of handling
the emission of wrapper structs. This latter solution of emitting structs
has already been used in other places but, in all the other places where we
currently do it, it is possible to do it on-the-fly, locally.
On the other hand, for dealing with this case properly we'd have to keep
track of dependencies between the forward declaration of the wrapper, and
the full definition of the element type of the wrapped array.
The emission of the full definition of the wrapper must be postponed until
the element type of the wrapped type is fully defined, otherwise it would
fail compilation. So fow now we've put this forced dependency, that could
be relaxed if we properly handle the array wrappers.
This commit reorders the argument passed to various `printDeclaration`
and `printDefinition` helper functions, to make them more uniform across
each other, and to accept the same arguments in the same order.
This commit:
* Introduces `_` as a prefix for all non-user entities we emit in
decompiled code.
Also, some names have been changed to be more concise.
Specifically, the following entities have changed:
`_ENUM_UNDERLYING`, `_ABI`, `_REG`, `_padding_at_`,
`_artificial_struct_`, `_artificial_wrapper_`, `_stack`,
`_break_from_loop_`, `_var_`, `_stack_arguments`,
`_artificial_struct_returned_`, `_enum_max_value_`.
* Introduce _PACKED for `__attribute__((packed))`.
* `EnumEntry` name: drop the `EnumType` name prefix.