diff options
author | Adrian Thurston <thurston@colm.net> | 2018-07-10 09:55:05 +0800 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2018-07-10 09:55:05 +0800 |
commit | 2a65d8e4410570fc1f70a7c7679634c7725cd538 (patch) | |
tree | 26317076377d15cdd01f6379c59a32c67809ba79 | |
parent | a1e92870cc54d3daec9d94b38623167a5a653d9d (diff) | |
download | colm-2a65d8e4410570fc1f70a7c7679634c7725cd538.tar.gz |
more separation of input and stream
-rw-r--r-- | src/bytecode.c | 10 | ||||
-rw-r--r-- | src/bytecode.h | 2 | ||||
-rw-r--r-- | src/ctinput.cc | 88 | ||||
-rw-r--r-- | src/input.c | 156 | ||||
-rw-r--r-- | src/input.h | 32 | ||||
-rw-r--r-- | src/pdarun.h | 1 | ||||
-rw-r--r-- | src/synthesis.cc | 2 |
7 files changed, 93 insertions, 198 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 706cc63d..c9a51141 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -2352,15 +2352,15 @@ again: break; } - case IN_PRINT_TREE_W: { - debug( prg, REALM_BYTECODE, "IN_PRINT_TREE_W\n" ); + case IN_PRINT_TREE: { + debug( prg, REALM_BYTECODE, "IN_PRINT_TREE\n" ); tree_t *to_send = vm_pop_tree(); - input_t *input = vm_pop_input(); + stream_t *stream = vm_pop_stream(); - struct input_impl *si = input_to_impl( input ); + struct stream_impl *si = stream_to_impl( stream ); si->funcs->print_tree( prg, sp, si, to_send, false ); - vm_push_input( input ); + vm_push_stream( stream ); colm_tree_downref( prg, sp, to_send ); break; } diff --git a/src/bytecode.h b/src/bytecode.h index 317a99d4..d1a529f8 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -265,7 +265,7 @@ typedef unsigned char uchar; #define IN_SEND_TEXT_W 0x89 #define IN_SEND_TEXT_BKT 0x8a -#define IN_PRINT_TREE_W 0xa3 +#define IN_PRINT_TREE 0xa3 #define IN_SEND_TREE_W 0xa9 #define IN_SEND_TREE_BKT 0xaa diff --git a/src/ctinput.cc b/src/ctinput.cc index 086bbf13..b89b030c 100644 --- a/src/ctinput.cc +++ b/src/ctinput.cc @@ -34,14 +34,14 @@ using std::cerr; using std::endl; -DEF_STREAM_FUNCS( stream_funcs_ct, stream_impl_ct ); +DEF_INPUT_FUNCS( input_funcs_ct, input_impl_ct ); -extern stream_funcs_ct pat_funcs; -extern stream_funcs_ct repl_funcs; +extern input_funcs_ct pat_funcs; +extern input_funcs_ct repl_funcs; -struct stream_impl_ct +struct input_impl_ct { - struct stream_funcs *funcs; + struct input_funcs *funcs; char *name; long line; @@ -59,16 +59,16 @@ struct stream_impl_ct int offset; }; -void ct_destructor( program_t *prg, tree_t **sp, struct stream_impl_ct *ss ) +void ct_destructor( program_t *prg, tree_t **sp, struct input_impl_ct *ss ) { } -char ct_get_eof_sent( struct colm_program *prg, struct stream_impl_ct *si ) +char ct_get_eof_sent( struct colm_program *prg, struct input_impl_ct *si ) { return si->eof_sent; } -void ct_set_eof_sent( struct colm_program *prg, struct stream_impl_ct *si, char eof_sent ) +void ct_set_eof_sent( struct colm_program *prg, struct input_impl_ct *si, char eof_sent ) { si->eof_sent = eof_sent; } @@ -79,15 +79,15 @@ void ct_set_eof_sent( struct colm_program *prg, struct stream_impl_ct *si, char struct input_impl *colm_impl_new_pat( char *name, Pattern *pattern ) { - struct stream_impl_ct *ss = (struct stream_impl_ct*)malloc(sizeof(struct stream_impl_ct)); - memset( ss, 0, sizeof(struct stream_impl_ct) ); + struct input_impl_ct *ss = (struct input_impl_ct*)malloc(sizeof(struct input_impl_ct)); + memset( ss, 0, sizeof(struct input_impl_ct) ); ss->pattern = pattern; ss->pat_item = pattern->list->head; - ss->funcs = (struct stream_funcs*)&pat_funcs; + ss->funcs = (struct input_funcs*)&pat_funcs; return (struct input_impl*) ss; } -int pat_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, int *pskip, +int pat_get_parse_block( struct colm_program *prg, struct input_impl_ct *ss, int *pskip, char **pdp, int *copied ) { *copied = 0; @@ -136,7 +136,7 @@ int pat_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, in } -int pat_get_data( struct colm_program *prg, struct stream_impl_ct *ss, char *dest, int length ) +int pat_get_data( struct colm_program *prg, struct input_impl_ct *ss, char *dest, int length ) { int copied = 0; @@ -173,7 +173,7 @@ int pat_get_data( struct colm_program *prg, struct stream_impl_ct *ss, char *des return copied; } -void pat_backup( struct stream_impl_ct *ss ) +void pat_backup( struct input_impl_ct *ss ) { if ( ss->pat_item == 0 ) ss->pat_item = ss->pattern->list->tail; @@ -181,7 +181,7 @@ void pat_backup( struct stream_impl_ct *ss ) ss->pat_item = ss->pat_item->prev; } -int pat_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc ) +int pat_consume_data( struct colm_program *prg, struct input_impl_ct *ss, int length, location_t *loc ) { //debug( REALM_INPUT, "consuming %ld bytes\n", length ); @@ -215,13 +215,13 @@ int pat_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, int l return consumed; } -int pat_undo_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, const char *data, int length ) +int pat_undo_consume_data( struct colm_program *prg, struct input_impl_ct *ss, const char *data, int length ) { ss->offset -= length; return length; } -LangEl *pat_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId, +LangEl *pat_consume_lang_el( struct colm_program *prg, struct input_impl_ct *ss, long *bindId, char **data, long *length ) { LangEl *klangEl = ss->pat_item->prodEl->langEl; @@ -234,23 +234,23 @@ LangEl *pat_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss return klangEl; } -void pat_undo_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss ) +void pat_undo_consume_lang_el( struct colm_program *prg, struct input_impl_ct *ss ) { pat_backup( ss ); ss->offset = ss->pat_item->data.length(); } -void ct_stream_set_eof( struct colm_program *prg, struct stream_impl_ct *si ) +void ct_set_eof( struct colm_program *prg, struct input_impl_ct *si ) { si->eof = true; } -void ct_stream_unset_eof( struct colm_program *prg, struct stream_impl_ct *si ) +void ct_unset_eof( struct colm_program *prg, struct input_impl_ct *si ) { si->eof = false; } -void ct_transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_ct *ss ) +void ct_transfer_loc_seq( struct colm_program *prg, location_t *loc, struct input_impl_ct *ss ) { loc->name = ss->name; loc->line = ss->line; @@ -258,13 +258,11 @@ void ct_transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stre loc->byte = ss->byte; } -stream_funcs_ct pat_funcs = +input_funcs_ct pat_funcs = { &pat_get_parse_block, &pat_get_data, - 0, /* get_data_source */ - &pat_consume_data, &pat_undo_consume_data, @@ -277,17 +275,12 @@ stream_funcs_ct pat_funcs = 0, 0, 0, 0, 0, 0, /* prepend funcs. */ 0, 0, 0, 0, 0, 0, /* append funcs */ - &ct_stream_set_eof, - &ct_stream_unset_eof, + &ct_set_eof, + &ct_unset_eof, &ct_get_eof_sent, &ct_set_eof_sent, &ct_transfer_loc_seq, - 0, /* get_collect */ - 0, /* flush_stream */ - 0, /* close_stream */ - 0, /* print_tree */ - &ct_destructor, }; @@ -298,15 +291,15 @@ stream_funcs_ct pat_funcs = struct input_impl *colm_impl_new_cons( char *name, Constructor *constructor ) { - struct stream_impl_ct *ss = (struct stream_impl_ct*)malloc(sizeof(struct stream_impl_ct)); - memset( ss, 0, sizeof(struct stream_impl_ct) ); + struct input_impl_ct *ss = (struct input_impl_ct*)malloc(sizeof(struct input_impl_ct)); + memset( ss, 0, sizeof(struct input_impl_ct) ); ss->constructor = constructor; ss->cons_item = constructor->list->head; - ss->funcs = (struct stream_funcs*)&repl_funcs; + ss->funcs = (struct input_funcs*)&repl_funcs; return (struct input_impl*)ss; } -LangEl *repl_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId, char **data, long *length ) +LangEl *repl_consume_lang_el( struct colm_program *prg, struct input_impl_ct *ss, long *bindId, char **data, long *length ) { LangEl *klangEl = ss->cons_item->type == ConsItem::ExprType ? ss->cons_item->langEl : ss->cons_item->prodEl->langEl; @@ -332,7 +325,7 @@ LangEl *repl_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *s return klangEl; } -int repl_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, +int repl_get_parse_block( struct colm_program *prg, struct input_impl_ct *ss, int *pskip, char **pdp, int *copied ) { *copied = 0; @@ -380,7 +373,7 @@ int repl_get_parse_block( struct colm_program *prg, struct stream_impl_ct *ss, return INPUT_DATA; } -int repl_get_data( struct colm_program *prg, struct stream_impl_ct *ss, char *dest, int length ) +int repl_get_data( struct colm_program *prg, struct input_impl_ct *ss, char *dest, int length ) { int copied = 0; @@ -417,7 +410,7 @@ int repl_get_data( struct colm_program *prg, struct stream_impl_ct *ss, char *de return copied; } -void repl_backup( struct stream_impl_ct *ss ) +void repl_backup( struct input_impl_ct *ss ) { if ( ss->cons_item == 0 ) ss->cons_item = ss->constructor->list->tail; @@ -425,14 +418,14 @@ void repl_backup( struct stream_impl_ct *ss ) ss->cons_item = ss->cons_item->prev; } -void repl_undo_consume_lang_el( struct colm_program *prg, struct stream_impl_ct *ss ) +void repl_undo_consume_lang_el( struct colm_program *prg, struct input_impl_ct *ss ) { repl_backup( ss ); ss->offset = ss->cons_item->data.length(); } -int repl_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc ) +int repl_consume_data( struct colm_program *prg, struct input_impl_ct *ss, int length, location_t *loc ) { int consumed = 0; @@ -464,7 +457,7 @@ int repl_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, int return consumed; } -int repl_undo_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, const char *data, int length ) +int repl_undo_consume_data( struct colm_program *prg, struct input_impl_ct *ss, const char *data, int length ) { int origLen = length; while ( true ) { @@ -485,13 +478,11 @@ int repl_undo_consume_data( struct colm_program *prg, struct stream_impl_ct *ss, return origLen; } -stream_funcs_ct repl_funcs = +input_funcs_ct repl_funcs = { &repl_get_parse_block, &repl_get_data, - 0, /* get_data_source */ - &repl_consume_data, &repl_undo_consume_data, @@ -504,17 +495,12 @@ stream_funcs_ct repl_funcs = 0, 0, 0, 0, 0, 0, /* prepend. */ 0, 0, 0, 0, 0, 0, /* append. */ - &ct_stream_set_eof, - &ct_stream_unset_eof, + &ct_set_eof, + &ct_unset_eof, &ct_get_eof_sent, &ct_set_eof_sent, &ct_transfer_loc_seq, - 0, /* get_collect */ - 0, /* flush_stream */ - 0, /* close_stream */ - 0, /* print_tree */ - &ct_destructor, }; diff --git a/src/input.c b/src/input.c index d1a688b1..a1846b05 100644 --- a/src/input.c +++ b/src/input.c @@ -90,15 +90,10 @@ struct run_buf *new_run_buf( int sz ) return rb; } -void init_fd_funcs(); -void init_file_funcs(); -void init_pat_funcs(); -void init_cons_funcs(); - -DEF_STREAM_FUNCS( stream_funcs_seq, stream_impl_seq ); +DEF_INPUT_FUNCS( input_funcs_seq, input_impl_seq ); DEF_STREAM_FUNCS( stream_funcs_data, stream_impl_data ); -extern struct stream_funcs_seq stream_funcs; +extern struct input_funcs_seq input_funcs; extern struct stream_funcs_data file_funcs; extern struct stream_funcs_data text_funcs; @@ -115,7 +110,7 @@ static void default_loc( location_t *loc ) loc->byte = 1; } -void transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_seq *ss ) +void transfer_loc_seq( struct colm_program *prg, location_t *loc, struct input_impl_seq *ss ) { loc->name = ss->name; loc->line = ss->line; @@ -131,8 +126,8 @@ static void transfer_loc_data( struct colm_program *prg, location_t *loc, struct loc->byte = ss->byte; } -void colm_clear_source_stream( struct colm_program *prg, - tree_t **sp, struct stream_impl_seq *si ) +static void colm_clear_source_stream( struct colm_program *prg, + tree_t **sp, struct input_impl_seq *si ) { struct seq_buf *buf = si->queue; while ( buf != 0 ) { @@ -178,7 +173,7 @@ void colm_stream_destroy( program_t *prg, tree_t **sp, struct_t *s ) } /* Keep the position up to date after consuming text. */ -void update_position_seq( struct stream_impl_seq *is, const char *data, long length ) +void update_position_seq( struct input_impl_seq *is, const char *data, long length ) { int i; for ( i = 0; i < length; i++ ) { @@ -194,7 +189,7 @@ void update_position_seq( struct stream_impl_seq *is, const char *data, long len } /* Keep the position up to date after sending back text. */ -void undo_position_seq( struct stream_impl_seq *is, const char *data, long length ) +void undo_position_seq( struct input_impl_seq *is, const char *data, long length ) { /* FIXME: this needs to fetch the position information from the parsed * token and restore based on that.. */ @@ -327,7 +322,7 @@ static int data_get_data( struct colm_program *prg, struct stream_impl_data *ss, static void data_destructor( program_t *prg, tree_t **sp, struct stream_impl_data *si ) { -// colm_clear_source_stream( prg, sp, (struct stream_impl_seq*)stream->impl ); +// colm_clear_source_stream( prg, sp, (struct input_impl_seq*)stream->impl ); if ( si->file != 0 ) colm_close_stream_file( si->file ); @@ -443,14 +438,14 @@ static int data_get_parse_block( struct colm_program *prg, struct stream_impl_da return ret; } -static void input_stream_stash_head( struct colm_program *prg, struct stream_impl_seq *si, struct seq_buf *seq_buf ) +static void input_stream_stash_head( struct colm_program *prg, struct input_impl_seq *si, struct seq_buf *seq_buf ) { debug( prg, REALM_INPUT, "stash_head: stream %p buf %p\n", si, seq_buf ); seq_buf->next = si->stash; si->stash = seq_buf; } -static struct seq_buf *input_stream_pop_stash( struct colm_program *prg, struct stream_impl_seq *si ) +static struct seq_buf *input_stream_pop_stash( struct colm_program *prg, struct input_impl_seq *si ) { struct seq_buf *seq_buf = si->stash; si->stash = si->stash->next; @@ -461,7 +456,7 @@ static struct seq_buf *input_stream_pop_stash( struct colm_program *prg, struct } -static void maybe_split( struct colm_program *prg, struct stream_impl_seq *si ) +static void maybe_split( struct colm_program *prg, struct input_impl_seq *si ) { if ( si->queue != 0 && si->queue->type == SEQ_BUF_SOURCE_TYPE ) { @@ -574,9 +569,9 @@ static int text_get_data_source( struct colm_program *prg, struct stream_impl_da * StreamImpl struct, this wraps the list of input streams. */ -void init_stream_impl_seq( struct stream_impl_seq *is, char *name ) +void init_input_impl_seq( struct input_impl_seq *is, char *name ) { - memset( is, 0, sizeof(struct stream_impl_seq) ); + memset( is, 0, sizeof(struct input_impl_seq) ); is->type = 'S'; is->name = name; @@ -599,7 +594,7 @@ void init_stream_impl_data( struct stream_impl_data *is, char *name ) is->level = COLM_INDENT_OFF; } -static struct seq_buf *input_stream_seq_pop_head( struct stream_impl_seq *is ) +static struct seq_buf *input_stream_seq_pop_head( struct input_impl_seq *is ) { struct seq_buf *ret = is->queue; is->queue = is->queue->next; @@ -610,7 +605,7 @@ static struct seq_buf *input_stream_seq_pop_head( struct stream_impl_seq *is ) return ret; } -static void input_stream_seq_append( struct stream_impl_seq *is, struct seq_buf *seq_buf ) +static void input_stream_seq_append( struct input_impl_seq *is, struct seq_buf *seq_buf ) { if ( is->queue == 0 ) { seq_buf->prev = seq_buf->next = 0; @@ -624,7 +619,7 @@ static void input_stream_seq_append( struct stream_impl_seq *is, struct seq_buf } } -static struct seq_buf *input_stream_seq_pop_tail( struct stream_impl_seq *is ) +static struct seq_buf *input_stream_seq_pop_tail( struct input_impl_seq *is ) { struct seq_buf *ret = is->queue_tail; is->queue_tail = is->queue_tail->prev; @@ -635,7 +630,7 @@ static struct seq_buf *input_stream_seq_pop_tail( struct stream_impl_seq *is ) return ret; } -static void input_stream_seq_prepend( struct stream_impl_seq *is, struct seq_buf *seq_buf ) +static void input_stream_seq_prepend( struct input_impl_seq *is, struct seq_buf *seq_buf ) { if ( is->queue == 0 ) { seq_buf->prev = seq_buf->next = 0; @@ -649,30 +644,17 @@ static void input_stream_seq_prepend( struct stream_impl_seq *is, struct seq_buf } } -static int is_source_stream( struct stream_impl_seq *is ) -{ - if ( is->queue != 0 && is->queue->type == SEQ_BUF_SOURCE_TYPE ) - return true; - return false; -} - -void stream_set_eof( struct colm_program *prg, struct stream_impl_seq *si ) +void stream_set_eof( struct colm_program *prg, struct input_impl_seq *si ) { si->eof = true; } -void stream_unset_eof( struct colm_program *prg, struct stream_impl_seq *si ) +void stream_unset_eof( struct colm_program *prg, struct input_impl_seq *si ) { -// if ( is_source_stream( si ) ) { -// struct stream_impl_data *sid = (struct stream_impl_data*)si->queue->si; -// sid->eof = false; -// } -// else { - si->eof = false; -// } + si->eof = false; } -static void stream_destructor( program_t *prg, tree_t **sp, struct stream_impl_seq *si ) +static void stream_destructor( program_t *prg, tree_t **sp, struct input_impl_seq *si ) { colm_clear_source_stream( prg, sp, si ); @@ -685,36 +667,18 @@ static void stream_destructor( program_t *prg, tree_t **sp, struct stream_impl_s free( si ); } -static str_collect_t *stream_get_collect( struct colm_program *prg, struct stream_impl_seq *si ) -{ - return 0; -} - -static void stream_flush_stream( struct colm_program *prg, struct stream_impl_seq *si ) -{ -} - -static void stream_close_stream( struct colm_program *prg, struct stream_impl_seq *si ) -{ -} - -static void stream_print_tree( struct colm_program *prg, tree_t **sp, - struct stream_impl_seq *si, tree_t *tree, int trim ) -{ -} - -char stream_get_eof_sent( struct colm_program *prg, struct stream_impl_seq *si ) +char stream_get_eof_sent( struct colm_program *prg, struct input_impl_seq *si ) { return si->eof_sent; } -void stream_set_eof_sent( struct colm_program *prg, struct stream_impl_seq *si, char eof_sent ) +void stream_set_eof_sent( struct colm_program *prg, struct input_impl_seq *si, char eof_sent ) { si->eof_sent = eof_sent; } -static int stream_get_parse_block( struct colm_program *prg, struct stream_impl_seq *is, int *pskip, char **pdp, int *copied ) +static int stream_get_parse_block( struct colm_program *prg, struct input_impl_seq *is, int *pskip, char **pdp, int *copied ) { int ret = 0; *copied = 0; @@ -792,7 +756,7 @@ static int stream_get_parse_block( struct colm_program *prg, struct stream_impl_ return ret; } -static int stream_get_data( struct colm_program *prg, struct stream_impl_seq *is, char *dest, int length ) +static int stream_get_data( struct colm_program *prg, struct input_impl_seq *is, char *dest, int length ) { int copied = 0; @@ -837,7 +801,7 @@ static int stream_get_data( struct colm_program *prg, struct stream_impl_seq *is * Consume */ -static int stream_consume_data( struct colm_program *prg, struct stream_impl_seq *si, int length, location_t *loc ) +static int stream_consume_data( struct colm_program *prg, struct input_impl_seq *si, int length, location_t *loc ) { debug( prg, REALM_INPUT, "stream_consume_data: stream %p consuming %d bytes\n", si, length ); @@ -883,7 +847,7 @@ static int stream_consume_data( struct colm_program *prg, struct stream_impl_seq return consumed; } -static int stream_undo_consume_data( struct colm_program *prg, struct stream_impl_seq *si, const char *data, int length ) +static int stream_undo_consume_data( struct colm_program *prg, struct input_impl_seq *si, const char *data, int length ) { /* When we push back data we need to move backwards through the block of * text. The source stream type will */ @@ -912,7 +876,7 @@ static int stream_undo_consume_data( struct colm_program *prg, struct stream_imp return tot; } -static tree_t *stream_consume_tree( struct colm_program *prg, struct stream_impl_seq *si ) +static tree_t *stream_consume_tree( struct colm_program *prg, struct input_impl_seq *si ) { debug( prg, REALM_INPUT, "stream_consume_tree: stream %p\n", si ); @@ -936,7 +900,7 @@ static tree_t *stream_consume_tree( struct colm_program *prg, struct stream_impl return 0; } -static void stream_undo_consume_tree( struct colm_program *prg, struct stream_impl_seq *si, tree_t *tree, int ignore ) +static void stream_undo_consume_tree( struct colm_program *prg, struct input_impl_seq *si, tree_t *tree, int ignore ) { debug( prg, REALM_INPUT, "stream_undo_consume_tree: stream %p undo consume tree %p\n", si, tree ); @@ -958,29 +922,10 @@ static void stream_undo_consume_tree( struct colm_program *prg, struct stream_im } } -static struct LangEl *stream_consume_lang_el( struct colm_program *prg, struct stream_impl_seq *is, long *bind_id, - char **data, long *length ) -{ - assert( is_source_stream( is ) ); - struct stream_impl *si = is->queue->si; - return si->funcs->consume_lang_el( prg, si, bind_id, data, length ); -} - -static void stream_undo_consume_lang_el( struct colm_program *prg, struct stream_impl_seq *is ) -{ - if ( is_source_stream( is ) ) { - struct stream_impl *si = is->queue->si; - return si->funcs->undo_consume_lang_el( prg, si ); - } - else { - assert( false ); - } -} - /* * Prepend */ -static void stream_prepend_data( struct colm_program *prg, struct stream_impl_seq *si, const char *data, long length ) +static void stream_prepend_data( struct colm_program *prg, struct input_impl_seq *si, const char *data, long length ) { debug( prg, REALM_INPUT, "stream_prepend_data: stream %p prepend data length %d\n", si, length ); @@ -995,7 +940,7 @@ static void stream_prepend_data( struct colm_program *prg, struct stream_impl_se input_stream_seq_prepend( si, new_buf ); } -static int stream_undo_prepend_data( struct colm_program *prg, struct stream_impl_seq *si, int length ) +static int stream_undo_prepend_data( struct colm_program *prg, struct input_impl_seq *si, int length ) { debug( prg, REALM_INPUT, "stream_undo_prepend_data: stream %p undo append data length %d\n", si, length ); @@ -1005,7 +950,7 @@ static int stream_undo_prepend_data( struct colm_program *prg, struct stream_imp return 0; } -static void stream_prepend_tree( struct colm_program *prg, struct stream_impl_seq *si, tree_t *tree, int ignore ) +static void stream_prepend_tree( struct colm_program *prg, struct input_impl_seq *si, tree_t *tree, int ignore ) { debug( prg, REALM_INPUT, "stream_prepend_tree: stream %p prepend tree %p\n", si, tree ); @@ -1020,7 +965,7 @@ static void stream_prepend_tree( struct colm_program *prg, struct stream_impl_se input_stream_seq_prepend( si, new_buf ); } -static tree_t *stream_undo_prepend_tree( struct colm_program *prg, struct stream_impl_seq *si ) +static tree_t *stream_undo_prepend_tree( struct colm_program *prg, struct input_impl_seq *si ) { debug( prg, REALM_INPUT, "stream_undo_prepend_tree: stream %p undo prepend tree\n", si ); @@ -1038,7 +983,7 @@ static tree_t *stream_undo_prepend_tree( struct colm_program *prg, struct stream } -static void stream_prepend_stream( struct colm_program *prg, struct stream_impl_seq *si, struct colm_stream *stream ) +static void stream_prepend_stream( struct colm_program *prg, struct input_impl_seq *si, struct colm_stream *stream ) { maybe_split( prg, si ); @@ -1053,14 +998,14 @@ static void stream_prepend_stream( struct colm_program *prg, struct stream_impl_ assert( ((struct stream_impl_data*)new_buf->si)->type == 'D' ); } -static tree_t *stream_undo_prepend_stream( struct colm_program *prg, struct stream_impl_seq *is ) +static tree_t *stream_undo_prepend_stream( struct colm_program *prg, struct input_impl_seq *is ) { struct seq_buf *seq_buf = input_stream_seq_pop_head( is ); free( seq_buf ); return 0; } -static void stream_append_data( struct colm_program *prg, struct stream_impl_seq *si, const char *data, long length ) +static void stream_append_data( struct colm_program *prg, struct input_impl_seq *si, const char *data, long length ) { debug( prg, REALM_INPUT, "stream_append_data: stream %p append data length %d\n", si, length ); @@ -1073,7 +1018,7 @@ static void stream_append_data( struct colm_program *prg, struct stream_impl_seq input_stream_seq_append( si, new_buf ); } -static tree_t *stream_undo_append_data( struct colm_program *prg, struct stream_impl_seq *si, int length ) +static tree_t *stream_undo_append_data( struct colm_program *prg, struct input_impl_seq *si, int length ) { debug( prg, REALM_INPUT, "stream_undo append_data: stream %p undo append data length %d\n", si, length ); @@ -1083,7 +1028,7 @@ static tree_t *stream_undo_append_data( struct colm_program *prg, struct stream_ return 0; } -static void stream_append_tree( struct colm_program *prg, struct stream_impl_seq *si, tree_t *tree ) +static void stream_append_tree( struct colm_program *prg, struct input_impl_seq *si, tree_t *tree ) { debug( prg, REALM_INPUT, "stream_append_tree: stream %p append tree %p\n", si, tree ); @@ -1095,7 +1040,7 @@ static void stream_append_tree( struct colm_program *prg, struct stream_impl_seq ad->tree = tree; } -static tree_t *stream_undo_append_tree( struct colm_program *prg, struct stream_impl_seq *si ) +static tree_t *stream_undo_append_tree( struct colm_program *prg, struct input_impl_seq *si ) { debug( prg, REALM_INPUT, "stream_undo_append_tree: stream %p undo append tree\n", si ); @@ -1105,7 +1050,7 @@ static tree_t *stream_undo_append_tree( struct colm_program *prg, struct stream_ return tree; } -static void stream_append_stream( struct colm_program *prg, struct stream_impl_seq *si, struct colm_stream *stream ) +static void stream_append_stream( struct colm_program *prg, struct input_impl_seq *si, struct colm_stream *stream ) { debug( prg, REALM_INPUT, "stream_append_stream: stream %p append stream %p\n", si, stream ); @@ -1119,7 +1064,7 @@ static void stream_append_stream( struct colm_program *prg, struct stream_impl_s assert( ((struct stream_impl_data*)ad->si)->type == 'D' ); } -static tree_t *stream_undo_append_stream( struct colm_program *prg, struct stream_impl_seq *si ) +static tree_t *stream_undo_append_stream( struct colm_program *prg, struct input_impl_seq *si ) { debug( prg, REALM_INPUT, "stream_undo_append_stream: stream %p undo append stream\n", si ); @@ -1128,11 +1073,10 @@ static tree_t *stream_undo_append_stream( struct colm_program *prg, struct strea return 0; } -struct stream_funcs_seq stream_funcs = +struct input_funcs_seq input_funcs = { &stream_get_parse_block, &stream_get_data, - 0 /* get_data_source */, /* Consume. */ &stream_consume_data, @@ -1141,8 +1085,8 @@ struct stream_funcs_seq stream_funcs = &stream_consume_tree, &stream_undo_consume_tree, - &stream_consume_lang_el, - &stream_undo_consume_lang_el, + 0, /* consume_lang_el */ + 0, /* undo_consume_lang_el */ /* Prepend */ &stream_prepend_data, @@ -1170,13 +1114,7 @@ struct stream_funcs_seq stream_funcs = &stream_get_eof_sent, &stream_set_eof_sent, - /* Util. */ &transfer_loc_seq, - &stream_get_collect, - &stream_flush_stream, - &stream_close_stream, - &stream_print_tree, - &stream_destructor, }; @@ -1282,9 +1220,9 @@ struct stream_impl *colm_impl_new_collect( char *name ) struct input_impl *colm_impl_new_generic( char *name ) { - struct stream_impl_seq *ss = (struct stream_impl_seq*)malloc(sizeof(struct stream_impl_seq)); - init_stream_impl_seq( ss, name ); - ss->funcs = (struct stream_funcs*)&stream_funcs; + struct input_impl_seq *ss = (struct input_impl_seq*)malloc(sizeof(struct input_impl_seq)); + init_input_impl_seq( ss, name ); + ss->funcs = (struct input_funcs*)&input_funcs; return (struct input_impl*)ss; } diff --git a/src/input.h b/src/input.h index 0dfa4c0f..2bafedbf 100644 --- a/src/input.h +++ b/src/input.h @@ -85,7 +85,6 @@ struct input_funcs \ { \ int (*get_parse_block)( struct colm_program *prg, struct input_impl *si, int *pskip, char **pdp, int *copied ); \ int (*get_data)( struct colm_program *prg, struct input_impl *si, char *dest, int length ); \ - int (*get_data_source)( struct colm_program *prg, struct input_impl *si, char *dest, int length ); \ int (*consume_data)( struct colm_program *prg, struct input_impl *si, int length, struct colm_location *loc ); \ int (*undo_consume_data)( struct colm_program *prg, struct input_impl *si, const char *data, int length ); \ struct colm_tree *(*consume_tree)( struct colm_program *prg, struct input_impl *si ); \ @@ -109,11 +108,6 @@ struct input_funcs \ char (*get_eof_sent)( struct colm_program *prg, struct input_impl *si ); \ void (*set_eof_sent)( struct colm_program *prg, struct input_impl *si, char eof_sent ); \ void (*transfer_loc)( struct colm_program *prg, struct colm_location *loc, struct input_impl *si ); \ - struct colm_str_collect *(*get_collect)( struct colm_program *prg, struct input_impl *si ); \ - void (*flush_stream)( struct colm_program *prg, struct input_impl *si ); \ - void (*close_stream)( struct colm_program *prg, struct input_impl *si ); \ - void (*print_tree)( struct colm_program *prg, struct colm_tree **sp, \ - struct input_impl *impl, struct colm_tree *tree, int trim ); \ void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct input_impl *si ); \ } @@ -125,22 +119,6 @@ struct stream_funcs \ int (*get_data_source)( struct colm_program *prg, struct stream_impl *si, char *dest, int length ); \ int (*consume_data)( struct colm_program *prg, struct stream_impl *si, int length, struct colm_location *loc ); \ int (*undo_consume_data)( struct colm_program *prg, struct stream_impl *si, const char *data, int length ); \ - struct colm_tree *(*consume_tree)( struct colm_program *prg, struct stream_impl *si ); \ - void (*undo_consume_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \ - struct LangEl *(*consume_lang_el)( struct colm_program *prg, struct stream_impl *si, long *bind_id, char **data, long *length ); \ - void (*undo_consume_lang_el)( struct colm_program *prg, struct stream_impl *si ); \ - void (*prepend_data)( struct colm_program *prg, struct stream_impl *si, const char *data, long len ); \ - int (*undo_prepend_data)( struct colm_program *prg, struct stream_impl *si, int length ); \ - void (*prepend_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \ - struct colm_tree *(*undo_prepend_tree)( struct colm_program *prg, struct stream_impl *si ); \ - void (*prepend_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \ - struct colm_tree *(*undo_prepend_stream)( struct colm_program *prg, struct stream_impl *si ); \ - void (*append_data)( struct colm_program *prg, struct stream_impl *si, const char *data, long len ); \ - struct colm_tree *(*undo_append_data)( struct colm_program *prg, struct stream_impl *si, int length ); \ - void (*append_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree ); \ - struct colm_tree *(*undo_append_tree)( struct colm_program *prg, struct stream_impl *si ); \ - void (*append_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \ - struct colm_tree *(*undo_append_stream)( struct colm_program *prg, struct stream_impl *si ); \ void (*set_eof)( struct colm_program *prg, struct stream_impl *si ); \ void (*unset_eof)( struct colm_program *prg, struct stream_impl *si ); \ char (*get_eof_sent)( struct colm_program *prg, struct stream_impl *si ); \ @@ -169,11 +147,10 @@ struct stream_impl struct stream_funcs *funcs; }; - /* List of source streams. Enables streams to be pushed/popped. */ -struct stream_impl_seq +struct input_impl_seq { - struct stream_funcs *funcs; + struct input_funcs *funcs; char type; char eof_sent; @@ -240,11 +217,6 @@ struct colm_stream *colm_stream_open_collect( struct colm_program *prg ); void colm_close_stream_file( FILE *file ); -void stream_set_eof( struct colm_program *prg, struct stream_impl_seq *si ); -void stream_unset_eof( struct colm_program *prg, struct stream_impl_seq *si ); - -void transfer_loc_seq( struct colm_program *prg, struct colm_location *loc, struct stream_impl_seq *ss ); - #ifdef __cplusplus } #endif diff --git a/src/pdarun.h b/src/pdarun.h index e86aeb4c..45b28e26 100644 --- a/src/pdarun.h +++ b/src/pdarun.h @@ -427,7 +427,6 @@ void colm_increment_steps( struct pda_run *pda_run ); void colm_decrement_steps( struct pda_run *pda_run ); void colm_clear_stream_impl( struct colm_program *prg, tree_t **sp, struct stream_impl *input_stream ); -void colm_clear_source_stream( struct colm_program *prg, tree_t **sp, struct stream_impl_seq *source_stream ); #define PCR_START 1 #define PCR_DONE 2 diff --git a/src/synthesis.cc b/src/synthesis.cc index 5a718a23..8a5d1cb5 100644 --- a/src/synthesis.cc +++ b/src/synthesis.cc @@ -1682,7 +1682,7 @@ void LangTerm::evaluateSendStream( Compiler *pd, CodeVect &code ) const break; }} - code.append( IN_PRINT_TREE_W ); + code.append( IN_PRINT_TREE ); } } |