maxime-esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems

Home Page:https://www.thanassis.space/asn1.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Append Functions are not hierarchical

fschramka opened this issue · comments

All append functions in the C backend have their own implementation, instead of calling each other. I guess those grew historically, a cleanup would be welcome :)

Some examples:

BitStream_AppendBitOne --> could call BitStream_AppendBit
BitStream_AppendBitZero --> could call BitStream_AppendBit

These 3 share no common implementation, even though they do very similar things.
BitStream_AppendNBitZero
BitStream_AppendNBitOne
BitStream_AppendBits --> calls BitStream_EncodeOctetString_no_length (even though that should be a level above - convenience?)

BitStream_EncodeOctetString_no_length --> can memcpy directly into the bitstream even though the name suggests, that this func does not directly operate on the bitstream (all other encodeXXX do not access the bitstream directly, but through an appendXXX func).

These duplicate each others code, one could call the other. Even the return types are not the same - reason?
BitStream_AppendByte
BitStream_AppendByte0

BitStream_AppendPartialByte does not call BitStream_AppendBit, even though it could.

BitStream_AppendByteArray does not call BitStream_AppendByte.

The scala backend simplified this - this could be done for C as well. Most functions could be inlined after the hierarchical approach is implemented to satisfy performance requirements.