Component definition files are allowed to define any valid C variable in a DECLARE section; such defined variables are then included in the generated component-type parameter struct as 'private' members.
Adding the definition to the struct is straightforward, as it can be copied verbatim (minus any static initialization).
But later accessing the struct member can be less straightforward due to complexities in identifying its name.
For example, a component could include a library that defines a labeled struct libDataStructure and aliases it to LibData like
Plus an attempt is made to identify stack arrays and pointer-valued variables, to ensure they are initialized safely, and with an eye toward possibly translating the user-defined C code into a different language in the future.
This is achieved by looking for "*", "[]", and r"\[[0-9]*\]" and converting the tuple[str, tuple[str, str | None]] to a NamedTuple with extra fields is_pointer and is_array.
Current limitations
The structured initialization of struct variables is valid C99 syntax, but is not currently supported in the mccode-antlr analysis.
Function pointers like compare_fun_ptr are valid C, but currently their variable identifier is not extracted correctly, and instead the initialization step above might include comp_parameters.(*compare_fun_ptr)(LibData*, LibData*)=NULL; at present.
Proposed improvement
Replace the tuple[str, tuple[str, str | None]] with a class object earlyier.
Current parsing requires the use of two such objects to keep track of whether a declaration includes function pointer.
Those objects should be augmented to take the place of the NamedTuple used presently.
Component definition files are allowed to define any valid C variable in a
DECLARE
section; such defined variables are then included in the generated component-type parameterstruct
as 'private' members.Adding the definition to the
struct
is straightforward, as it can be copied verbatim (minus any static initialization). But later accessing thestruct
member can be less straightforward due to complexities in identifying its name.For example, a component could include a library that defines a labeled
struct libDataStructure
and aliases it toLibData
likeand then have a
DECLARE
section likeWhich would need to produce a component parameters
struct
likeAnd later, each component instance will have its own
_class_comp_parameters
variable, with initialization like,Current implementation
The named type, variable identifier, and initialized value are all extracted from the
DECLARE
block lines as strings, and returned as, e.g,Plus an attempt is made to identify stack arrays and pointer-valued variables, to ensure they are initialized safely, and with an eye toward possibly translating the user-defined C code into a different language in the future. This is achieved by looking for
"*"
,"[]"
, andr"\[[0-9]*\]"
and converting thetuple[str, tuple[str, str | None]]
to aNamedTuple
with extra fieldsis_pointer
andis_array
.Current limitations
struct
variables is valid C99 syntax, but is not currently supported in themccode-antlr
analysis.compare_fun_ptr
are valid C, but currently their variable identifier is not extracted correctly, and instead the initialization step above might includecomp_parameters.(*compare_fun_ptr)(LibData*, LibData*)=NULL;
at present.Proposed improvement
Replace the
tuple[str, tuple[str, str | None]]
with a class object earlyier. Current parsing requires the use of two such objects to keep track of whether a declaration includes function pointer. Those objects should be augmented to take the place of theNamedTuple
used presently.