summaryrefslogtreecommitdiff
path: root/src/input.h
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-06-17 16:57:52 +0700
committerAdrian Thurston <thurston@colm.net>2018-06-17 16:57:52 +0700
commit3f631f3739e65ee81b6e8ae23eb24a63465f7ddf (patch)
tree7ddd9a9ce06381fb3ae39e79a57ecb9bfd9cfbda /src/input.h
parent0299bce35ccf8d7c7feffdfa191aba130a1ff495 (diff)
downloadcolm-3f631f3739e65ee81b6e8ae23eb24a63465f7ddf.tar.gz
declare types for the stream funcs
Going to experiment with specializing the stream_impl struct to compile-time and run-time uses. Will cast the functions to so we don't need to ever cast the args. This makes for some convenient code, but we lose compiler support in checking the signature of the stream functions.
Diffstat (limited to 'src/input.h')
-rw-r--r--src/input.h92
1 files changed, 69 insertions, 23 deletions
diff --git a/src/input.h b/src/input.h
index 0226b508..efd47ecc 100644
--- a/src/input.h
+++ b/src/input.h
@@ -79,48 +79,94 @@ struct run_buf
struct run_buf *new_run_buf( int sz );
+typedef int (*get_parse_block_t)( struct stream_impl *si, int skip, char **pdp, int *copied );
+
+/* Probably this should be replaced with get_parse_block calls. */
+typedef int (*get_data_t)( struct stream_impl *si, char *dest, int length );
+
+/* Consuming data. */
+typedef int (*consume_data_t)( struct colm_program *prg, struct colm_tree **sp,
+ struct stream_impl *si, int length, struct colm_location *loc );
+typedef int (*undo_consume_data_t)( struct stream_impl *si, const char *data, int length );
+
+/* Consuming trees. */
+typedef struct colm_tree *(*consume_tree_t)( struct stream_impl *si );
+typedef void (*undo_consume_tree_t)( struct stream_impl *si,
+ struct colm_tree *tree, int ignore );
+
+/* Language elments (compile-time). */
+typedef struct LangEl *(*consume_lang_el_t)( struct stream_impl *si,
+ long *bind_id, char **data, long *length );
+typedef void (*undo_consume_lang_el_t)( struct stream_impl *si );
+
+/* Private implmentation for some shared get data functions. */
+typedef int (*get_data_source_t)( struct stream_impl *si, char *dest, int length );
+
+typedef void (*set_eof_t)( struct stream_impl *si );
+typedef void (*unset_eof_t)( struct stream_impl *si );
+
+/* Prepending to a stream. */
+typedef void (*prepend_data_t)( struct stream_impl *si, const char *data, long len );
+typedef void (*prepend_tree_t)( struct stream_impl *si, struct colm_tree *tree, int ignore );
+typedef void (*prepend_stream_t)( struct stream_impl *si, struct colm_stream *stream );
+
+/* Undoing prepend. */
+typedef int (*undo_prepend_data_t)( struct stream_impl *si, int length );
+typedef struct colm_tree *(*undo_prepend_tree_t)( struct stream_impl *si );
+typedef struct colm_tree *(*undo_prepend_stream_t)( struct stream_impl *si );
+
+/* Appending to a stream. */
+typedef void (*append_data_t)( struct stream_impl *si, const char *data, long len );
+typedef void (*append_tree_t)( struct stream_impl *si, struct colm_tree *tree );
+typedef void (*append_stream_t)( struct stream_impl *si, struct colm_stream *stream );
+
+/* Undoing append. */
+typedef struct colm_tree *(*undo_append_data_t)( struct stream_impl *si, int length );
+typedef struct colm_tree *(*undo_append_tree_t)( struct stream_impl *si );
+typedef struct colm_tree *(*undo_append_stream_t)( struct stream_impl *si );
+
struct stream_funcs
{
- int (*get_parse_block)( struct stream_impl *ss, int skip, char **pdp, int *copied );
+ int (*get_parse_block)( struct stream_impl *si, int skip, char **pdp, int *copied );
- int (*get_data)( struct stream_impl *ss, char *dest, int length );
+ int (*get_data)( struct stream_impl *si, char *dest, int length );
int (*consume_data)( struct colm_program *prg, struct colm_tree **sp,
- struct stream_impl *ss, int length, struct colm_location *loc );
- int (*undo_consume_data)( struct stream_impl *ss, const char *data, int length );
+ struct stream_impl *si, int length, struct colm_location *loc );
+ int (*undo_consume_data)( struct stream_impl *si, const char *data, int length );
- struct colm_tree *(*consume_tree)( struct stream_impl *ss );
- void (*undo_consume_tree)( struct stream_impl *ss,
+ struct colm_tree *(*consume_tree)( struct stream_impl *si );
+ void (*undo_consume_tree)( struct stream_impl *si,
struct colm_tree *tree, int ignore );
/* Language elments (compile-time). */
- struct LangEl *(*consume_lang_el)( struct stream_impl *ss,
+ struct LangEl *(*consume_lang_el)( struct stream_impl *si,
long *bind_id, char **data, long *length );
- void (*undo_consume_lang_el)( struct stream_impl *ss );
+ void (*undo_consume_lang_el)( struct stream_impl *si );
/* Private implmentation for some shared get data functions. */
- int (*get_data_source)( struct stream_impl *ss, char *dest, int length );
+ int (*get_data_source)( struct stream_impl *si, char *dest, int length );
- void (*set_eof)( struct stream_impl *is );
- void (*unset_eof)( struct stream_impl *is );
+ void (*set_eof)( struct stream_impl *si );
+ void (*unset_eof)( struct stream_impl *si );
/* Prepending to a stream. */
- void (*prepend_data)( struct stream_impl *in, const char *data, long len );
- void (*prepend_tree)( struct stream_impl *is, struct colm_tree *tree, int ignore );
- void (*prepend_stream)( struct stream_impl *in, struct colm_stream *stream );
+ void (*prepend_data)( struct stream_impl *si, const char *data, long len );
+ void (*prepend_tree)( struct stream_impl *si, struct colm_tree *tree, int ignore );
+ void (*prepend_stream)( struct stream_impl *si, struct colm_stream *stream );
- int (*undo_prepend_data)( struct stream_impl *is, int length );
- struct colm_tree *(*undo_prepend_tree)( struct stream_impl *is );
- struct colm_tree *(*undo_prepend_stream)( struct stream_impl *in );
+ int (*undo_prepend_data)( struct stream_impl *si, int length );
+ struct colm_tree *(*undo_prepend_tree)( struct stream_impl *si );
+ struct colm_tree *(*undo_prepend_stream)( struct stream_impl *si );
/* Appending to a stream. */
- void (*append_data)( struct stream_impl *in, const char *data, long len );
- void (*append_tree)( struct stream_impl *in, struct colm_tree *tree );
- void (*append_stream)( struct stream_impl *in, struct colm_stream *stream );
+ void (*append_data)( struct stream_impl *si, const char *data, long len );
+ void (*append_tree)( struct stream_impl *si, struct colm_tree *tree );
+ void (*append_stream)( struct stream_impl *si, struct colm_stream *stream );
- struct colm_tree *(*undo_append_data)( struct stream_impl *in, int length );
- struct colm_tree *(*undo_append_tree)( struct stream_impl *in );
- struct colm_tree *(*undo_append_stream)( struct stream_impl *in );
+ struct colm_tree *(*undo_append_data)( struct stream_impl *si, int length );
+ struct colm_tree *(*undo_append_tree)( struct stream_impl *si );
+ struct colm_tree *(*undo_append_stream)( struct stream_impl *si );
};
/* List of source streams. Enables streams to be pushed/popped. */