Separate C struct declaration and definition

This commit is contained in:
Nigel Tao committed 2018-10-06 09:45:03 +10:00
1 parent e26ba24fbf
commit 5b82dd905a
2 files changed
+216 -198

No files matched your search

+8 -4
View File
@@ -373,13 +373,10 @@ func (g *gen) genHeader(b *buffer) error {
return err
}
b.writes("// ---------------- Structs\n\n")
b.writes("// ---------------- Struct Declarations\n\n")
for _, n := range g.structList {
structName := n.QID().Str(g.tm)
b.printf("typedef struct %s%s__struct %s%s;\n\n", g.pkgPrefix, structName, g.pkgPrefix, structName)
if err := g.writeStruct(b, n); err != nil {
return err
}
}
b.writes("// ---------------- Public Initializer Prototypes\n\n")
@@ -396,6 +393,13 @@ func (g *gen) genHeader(b *buffer) error {
return err
}
b.writes("// ---------------- Struct Definitions\n\n")
for _, n := range g.structList {
if err := g.writeStruct(b, n); err != nil {
return err
}
}
b.writes("// ---------------- C++ Convenience Methods \n\n")
if err := g.writeCppImpls(b); err != nil {
return err
+208 -194
View File
@@ -2199,10 +2199,33 @@ extern "C" {
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_adler32__hasher__struct wuffs_adler32__hasher;
// ---------------- Public Initializer Prototypes
// wuffs_adler32__hasher__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_adler32__hasher__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_adler32__hasher();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC uint32_t //
wuffs_adler32__hasher__update(wuffs_adler32__hasher* self,
wuffs_base__slice_u8 a_x);
// ---------------- Struct Definitions
struct wuffs_adler32__hasher__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2226,27 +2249,6 @@ struct wuffs_adler32__hasher__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_adler32__hasher__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_adler32__hasher__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_adler32__hasher();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC uint32_t //
wuffs_adler32__hasher__update(wuffs_adler32__hasher* self,
wuffs_base__slice_u8 a_x);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -2281,10 +2283,33 @@ extern "C" {
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_crc32__ieee_hasher__struct wuffs_crc32__ieee_hasher;
// ---------------- Public Initializer Prototypes
// wuffs_crc32__ieee_hasher__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_crc32__ieee_hasher__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_crc32__ieee_hasher();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC uint32_t //
wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
wuffs_base__slice_u8 a_x);
// ---------------- Struct Definitions
struct wuffs_crc32__ieee_hasher__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2307,27 +2332,6 @@ struct wuffs_crc32__ieee_hasher__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_crc32__ieee_hasher__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_crc32__ieee_hasher__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_crc32__ieee_hasher();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC uint32_t //
wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
wuffs_base__slice_u8 a_x);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -2376,10 +2380,34 @@ extern const char* wuffs_deflate__error__no_huffman_codes;
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_deflate__decoder__struct wuffs_deflate__decoder;
// ---------------- Public Initializer Prototypes
// wuffs_deflate__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_deflate__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_deflate__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- Struct Definitions
struct wuffs_deflate__decoder__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2462,28 +2490,6 @@ struct wuffs_deflate__decoder__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_deflate__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_deflate__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_deflate__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -2528,10 +2534,37 @@ extern const char* wuffs_lzw__error__cyclical_prefix_chain;
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_lzw__decoder__struct wuffs_lzw__decoder;
// ---------------- Public Initializer Prototypes
// wuffs_lzw__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_lzw__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_lzw__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- Struct Definitions
struct wuffs_lzw__decoder__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2574,31 +2607,6 @@ struct wuffs_lzw__decoder__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_lzw__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_lzw__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_lzw__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -2645,10 +2653,60 @@ extern const char* wuffs_gif__error__too_much_pixel_data;
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_gif__decoder__struct wuffs_gif__decoder;
// ---------------- Public Initializer Prototypes
// wuffs_gif__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_gif__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_gif__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_reader a_src);
WUFFS_BASE__MAYBE_STATIC uint64_t //
wuffs_gif__decoder__num_decoded_frame_configs(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC uint64_t //
wuffs_gif__decoder__num_decoded_frames(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
wuffs_gif__decoder__workbuf_len(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__restart_frame(wuffs_gif__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_reader a_src);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_reader a_src,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- Struct Definitions
struct wuffs_gif__decoder__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2786,54 +2844,6 @@ struct wuffs_gif__decoder__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_gif__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_gif__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_gif__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_image_config(wuffs_gif__decoder* self,
wuffs_base__image_config* a_dst,
wuffs_base__io_reader a_src);
WUFFS_BASE__MAYBE_STATIC uint64_t //
wuffs_gif__decoder__num_decoded_frame_configs(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC uint64_t //
wuffs_gif__decoder__num_decoded_frames(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
wuffs_gif__decoder__workbuf_len(wuffs_gif__decoder* self);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__restart_frame(wuffs_gif__decoder* self,
uint64_t a_index,
uint64_t a_io_position);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_frame_config(wuffs_gif__decoder* self,
wuffs_base__frame_config* a_dst,
wuffs_base__io_reader a_src);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gif__decoder__decode_frame(wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_dst,
wuffs_base__io_reader a_src,
wuffs_base__slice_u8 a_workbuf,
wuffs_base__decode_frame_options* a_opts);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -2917,10 +2927,37 @@ extern const char* wuffs_gzip__error__bad_header;
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_gzip__decoder__struct wuffs_gzip__decoder;
// ---------------- Public Initializer Prototypes
// wuffs_gzip__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_gzip__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_gzip__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- Struct Definitions
struct wuffs_gzip__decoder__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -2959,31 +2996,6 @@ struct wuffs_gzip__decoder__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_gzip__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_gzip__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_gzip__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus
@@ -3037,10 +3049,37 @@ extern const char* wuffs_zlib__error__bad_parity_check;
// ---------------- Public Consts
// ---------------- Structs
// ---------------- Struct Declarations
typedef struct wuffs_zlib__decoder__struct wuffs_zlib__decoder;
// ---------------- Public Initializer Prototypes
// wuffs_zlib__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_zlib__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_zlib__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- Struct Definitions
struct wuffs_zlib__decoder__struct {
// Do not access the private_impl's fields directly. There is no API/ABI
// compatibility or safety guarantee if you do so. Instead, use the
@@ -3075,31 +3114,6 @@ struct wuffs_zlib__decoder__struct {
#endif // __cplusplus
};
// ---------------- Public Initializer Prototypes
// wuffs_zlib__decoder__check_wuffs_version is an initializer function.
//
// It should be called before any other wuffs_zlib__decoder__* function.
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
size_t sizeof_star_self,
uint64_t wuffs_version);
size_t //
sizeof__wuffs_zlib__decoder();
// ---------------- Public Function Prototypes
WUFFS_BASE__MAYBE_STATIC void //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic);
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
wuffs_base__io_reader a_src);
// ---------------- C++ Convenience Methods
#ifdef __cplusplus