We have observed random segfaults when accessing last_exception.information,
which is apparently equal to null (while this is never supposed to happen).
Add defensive code to protect against this case.
Issue: eng/codepeer/infer#220
(cherry picked from commit e192fa0325)
In the generated C header, replace:
typedef void *X;
declarations ("opaque pointers") with:
typedef struct X__struct *X;
So that implicit conversions between them (generally a mistake) are
rejected. Also fix the issues in the rewriting API that can be found
thihs way.
Include the $.Rewriting_Impl unit to the "library interface" in the
generated project file, as that unit contains the definitions for
rewriting API C symbols. The rewriting C API testcase worked so far
because it links its test program to the generated *static* library.
Defining it as a "const" declaration in a header file is incorrect, as
it defines a symbol: two compilation units that include the header file
will then trigger link error due to conflicting symbol definitions.
Define it as a macro instead to avoid this kind of issue. No new
dedicated testcase for this as the next commit reworks C test helpers to
have multiple compilation units (several "*.c" sources in test
projects).
Putting the implementation of helper functions in headers (static
functions) yields inconvenient warnings about unused functions. Put
implementations in regular functions in "*.c" files instead.
This is necessary so that unparsing inserts a space between "var" and
"foo" in "var foo". That problem was undetected so far in our only
rewriting API test because all variable declaration nodes were rewritten
from sources (they were not synthetized), so formatting (which includes
that space) was preserved.
The $.Implementation package is already private: there is no need to
make its descendants private too in order to make them unreachable from
the users of generated libraries. On the contrary, we want
$.Implementation.C to be reachable from $.Rewriting_Implementation,
which will be necessary for the upcoming work to create C bindings for
the rewriting API.
Upcoming work will bind the rewriting API to C and thus add a
corresponding test in c_api/, so it makes more sense to have the Ada API
test in ada_api/.
Generic API users that need to browse parsing trees (i.e. handling
`Lk_Node` values) need a convenient way to get syntax fields:
`Eval_Member` and `Eval_Node_Member` both require various amounts of
conversions from/to `Value_Ref`. Introduce `Eval_Syntax_Field` to make
this process more convenient.