diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bytecode.c | 32 | ||||
-rw-r--r-- | src/compiler.cc | 4 | ||||
-rw-r--r-- | src/ctinput.cc | 30 | ||||
-rw-r--r-- | src/input.c | 110 | ||||
-rw-r--r-- | src/input.h | 58 | ||||
-rw-r--r-- | src/pdarun.c | 76 | ||||
-rw-r--r-- | src/pdarun.h | 8 |
7 files changed, 159 insertions, 159 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 6c68135c..220812bc 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -136,12 +136,12 @@ static void flush_streams( program_t *prg ) { if ( prg->stdout_val != 0 ) { struct stream_impl *si = prg->stdout_val->impl; - si->funcs->flush_stream( si ); + si->funcs->flush_stream( prg, si ); } if ( prg->stderr_val != 0 ) { struct stream_impl *si = prg->stderr_val->impl; - si->funcs->flush_stream( si ); + si->funcs->flush_stream( prg, si ); } } @@ -233,7 +233,7 @@ static word_t stream_append_text( program_t *prg, tree_t **sp, stream_t *dest, t colm_print_tree_collect( prg, sp, &collect, input, false ); /* Load it into the input. */ - impl->funcs->append_data( impl, collect.data, collect.length ); + impl->funcs->append_data( prg, impl, collect.data, collect.length ); length = collect.length; str_collect_destroy( &collect ); } @@ -256,13 +256,13 @@ static word_t stream_append_tree( program_t *prg, tree_t **sp, stream_t *dest, t colm_print_tree_collect( prg, sp, &collect, input, false ); /* Load it into the input. */ - impl->funcs->append_data( impl, collect.data, collect.length ); + impl->funcs->append_data( prg, impl, collect.data, collect.length ); length = collect.length; str_collect_destroy( &collect ); } else { colm_tree_upref( prg, input ); - impl->funcs->append_tree( impl, input ); + impl->funcs->append_tree( prg, impl, input ); } return length; @@ -273,7 +273,7 @@ static word_t stream_append_stream( program_t *prg, tree_t **sp, stream_t *dest, long length = 0; struct stream_impl *impl = stream_to_impl( dest ); - impl->funcs->append_stream( impl, stream ); + impl->funcs->append_stream( prg, impl, stream ); return length; } @@ -284,16 +284,16 @@ static void stream_undo_append( program_t *prg, tree_t **sp, if ( input->id == LEL_ID_PTR ) assert(false); else if ( input->id == LEL_ID_STR ) - is->funcs->undo_append_data( is, length ); + is->funcs->undo_append_data( prg, is, length ); else { - is->funcs->undo_append_data( is, length ); + is->funcs->undo_append_data( prg, is, length ); } } static void stream_undo_append_stream( program_t *prg, tree_t **sp, struct stream_impl *is, tree_t *input, long length ) { - is->funcs->undo_append_stream( is ); + is->funcs->undo_append_stream( prg, is ); } static tree_t *stream_pull_bc( program_t *prg, tree_t **sp, struct pda_run *pda_run, @@ -310,7 +310,7 @@ static void undo_pull( program_t *prg, stream_t *stream, tree_t *str ) struct stream_impl *impl = stream_to_impl( stream ); const char *data = string_data( ( (str_t*)str )->value ); long length = string_length( ( (str_t*)str )->value ); - undo_stream_pull( impl, data, length ); + undo_stream_pull( prg, impl, data, length ); } static long stream_push( program_t *prg, tree_t **sp, struct stream_impl *in, tree_t *tree, int ignore ) @@ -329,14 +329,14 @@ static long stream_push( program_t *prg, tree_t **sp, struct stream_impl *in, tr init_str_collect( &collect ); colm_print_tree_collect( prg, sp, &collect, tree, false ); - colm_stream_push_text( in, collect.data, collect.length ); + colm_stream_push_text( prg, in, collect.data, collect.length ); length = collect.length; str_collect_destroy( &collect ); } else { colm_tree_upref( prg, tree ); - colm_stream_push_tree( in, tree, ignore ); + colm_stream_push_tree( prg, in, tree, ignore ); } return length; @@ -345,7 +345,7 @@ static long stream_push( program_t *prg, tree_t **sp, struct stream_impl *in, tr static long stream_push_stream( program_t *prg, tree_t **sp, struct stream_impl *in, stream_t *stream ) { - colm_stream_push_stream( in, stream ); + colm_stream_push_stream( prg, in, stream ); return -1; } @@ -2495,7 +2495,7 @@ again: si = stream_to_impl( stream ); if ( stream->parser != 0 ) - si->funcs->set_eof( si ); + si->funcs->set_eof( prg, si ); if ( exec->WV ) { rcode_unit_start( exec ); @@ -2521,7 +2521,7 @@ again: if ( stream->parser != 0 ) { struct stream_impl *si = stream_to_impl( stream ); - si->funcs->unset_eof( si ); + si->funcs->unset_eof( prg, si ); } break; } @@ -2532,7 +2532,7 @@ again: stream_t *stream = vm_pop_stream(); struct stream_impl *si = stream->impl; - si->funcs->close_stream( si ); + si->funcs->close_stream( prg, si ); vm_push_stream( stream ); break; diff --git a/src/compiler.cc b/src/compiler.cc index a560d1d4..1df9cda2 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -1002,8 +1002,8 @@ pda_run *Compiler::parsePattern( program_t *prg, tree_t **sp, const InputLoc &lo stream_t *stream = colm_stream_new_struct( prg ); stream->impl = sourceStream; - in->funcs->append_stream( in, stream ); - in->funcs->set_eof( in ); + in->funcs->append_stream( prg, in, stream ); + in->funcs->set_eof( prg, in ); long pcr = colm_parse_loop( prg, sp, pdaRun, in, PCR_START ); assert( pcr == PCR_DONE ); diff --git a/src/ctinput.cc b/src/ctinput.cc index e11d94b5..77b4ec9c 100644 --- a/src/ctinput.cc +++ b/src/ctinput.cc @@ -58,12 +58,12 @@ struct stream_impl_ct int offset; }; -char inputStreamGetEofSent( struct stream_impl_ct *si ) +char inputStreamGetEofSent( struct colm_program *prg, struct stream_impl_ct *si ) { return si->eof_sent; } -void inputStreamSetEofSent( struct stream_impl_ct *si, char eof_sent ) +void inputStreamSetEofSent( struct colm_program *prg, struct stream_impl_ct *si, char eof_sent ) { si->eof_sent = eof_sent; } @@ -91,7 +91,7 @@ struct stream_impl *colm_impl_new_pat( char *name, Pattern *pattern ) return (struct stream_impl*) ss; } -LangEl *inputStreamPatternGetLangEl( struct stream_impl_ct *ss, long *bindId, +LangEl *inputStreamPatternGetLangEl( struct colm_program *prg, struct stream_impl_ct *ss, long *bindId, char **data, long *length ) { LangEl *klangEl = ss->pat_item->prodEl->langEl; @@ -108,7 +108,7 @@ void inputStreamPatternDestructor( program_t *prg, tree_t **sp, struct stream_im { } -int inputStreamPatternGetParseBlock( struct stream_impl_ct *ss, int skip, +int inputStreamPatternGetParseBlock( struct colm_program *prg, struct stream_impl_ct *ss, int skip, char **pdp, int *copied ) { *copied = 0; @@ -156,7 +156,7 @@ int inputStreamPatternGetParseBlock( struct stream_impl_ct *ss, int skip, return INPUT_DATA; } -int inputStreamPatternGetData( struct stream_impl_ct *ss, char *dest, int length ) +int inputStreamPatternGetData( struct colm_program *prg, struct stream_impl_ct *ss, char *dest, int length ) { int copied = 0; @@ -201,13 +201,13 @@ void inputStreamPatternBackup( struct stream_impl_ct *ss ) ss->pat_item = ss->pat_item->prev; } -extern "C" void inputStreamPatternUndoConsumeLangEl( struct stream_impl_ct *ss ) +extern "C" void inputStreamPatternUndoConsumeLangEl( struct colm_program *prg, struct stream_impl_ct *ss ) { inputStreamPatternBackup( ss ); ss->offset = ss->pat_item->data.length(); } -int inputStreamPatternConsumeData( struct stream_impl_ct *ss, int length, location_t *loc ) +int inputStreamPatternConsumeData( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc ) { //debug( REALM_INPUT, "consuming %ld bytes\n", length ); @@ -241,7 +241,7 @@ int inputStreamPatternConsumeData( struct stream_impl_ct *ss, int length, locati return consumed; } -int inputStreamPatternUndoConsumeData( struct stream_impl_ct *ss, const char *data, int length ) +int inputStreamPatternUndoConsumeData( struct colm_program *prg, struct stream_impl_ct *ss, const char *data, int length ) { ss->offset -= length; return length; @@ -287,7 +287,7 @@ struct stream_impl *colm_impl_new_cons( char *name, Constructor *constructor ) return (struct stream_impl*)ss; } -LangEl *inputStreamConsGetLangEl( struct stream_impl_ct *ss, long *bindId, char **data, long *length ) +LangEl *inputStreamConsGetLangEl( struct colm_program *prg, struct stream_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; @@ -317,7 +317,7 @@ void inputStreamConsDestructor( program_t *prg, tree_t **sp, struct stream_impl_ { } -int inputStreamConsGetParseBlock( struct stream_impl_ct *ss, +int inputStreamConsGetParseBlock( struct colm_program *prg, struct stream_impl_ct *ss, int skip, char **pdp, int *copied ) { *copied = 0; @@ -365,7 +365,7 @@ int inputStreamConsGetParseBlock( struct stream_impl_ct *ss, return INPUT_DATA; } -int inputStreamConsGetData( struct stream_impl_ct *ss, char *dest, int length ) +int inputStreamConsGetData( struct colm_program *prg, struct stream_impl_ct *ss, char *dest, int length ) { int copied = 0; @@ -410,13 +410,13 @@ void inputStreamConsBackup( struct stream_impl_ct *ss ) ss->cons_item = ss->cons_item->prev; } -void inputStreamConsUndoConsumeLangEl( struct stream_impl_ct *ss ) +void inputStreamConsUndoConsumeLangEl( struct colm_program *prg, struct stream_impl_ct *ss ) { inputStreamConsBackup( ss ); ss->offset = ss->cons_item->data.length(); } -int inputStreamConsConsumeData( struct stream_impl_ct *ss, int length, location_t *loc ) +int inputStreamConsConsumeData( struct colm_program *prg, struct stream_impl_ct *ss, int length, location_t *loc ) { int consumed = 0; @@ -448,7 +448,7 @@ int inputStreamConsConsumeData( struct stream_impl_ct *ss, int length, location_ return consumed; } -int inputStreamConsUndoConsumeData( struct stream_impl_ct *ss, const char *data, int length ) +int inputStreamConsUndoConsumeData( struct colm_program *prg, struct stream_impl_ct *ss, const char *data, int length ) { int origLen = length; while ( true ) { @@ -508,7 +508,7 @@ extern "C" void internalSendNamedLangEl( program_t *prg, tree_t **sp, char *data; long length; - LangEl *klangEl = is->funcs->consume_lang_el( is, &bindId, &data, &length ); + LangEl *klangEl = is->funcs->consume_lang_el( prg, is, &bindId, &data, &length ); //cerr << "named langEl: " << prg->rtd->lelInfo[klangEl->id].name << endl; diff --git a/src/input.c b/src/input.c index be86f8f0..711d95ef 100644 --- a/src/input.c +++ b/src/input.c @@ -114,7 +114,7 @@ static void default_loc( location_t *loc ) loc->byte = 1; } -static void transfer_loc_seq( location_t *loc, struct stream_impl_seq *ss ) +static void transfer_loc_seq( struct colm_program *prg, location_t *loc, struct stream_impl_seq *ss ) { loc->name = ss->name; loc->line = ss->line; @@ -122,7 +122,7 @@ static void transfer_loc_seq( location_t *loc, struct stream_impl_seq *ss ) loc->byte = ss->byte; } -static void transfer_loc_data( location_t *loc, struct stream_impl_data *ss ) +static void transfer_loc_data( struct colm_program *prg, location_t *loc, struct stream_impl_data *ss ) { loc->name = ss->name; loc->line = ss->line; @@ -277,7 +277,7 @@ static void source_stream_data_prepend( struct stream_impl_data *ss, struct run_ * Data inputs: files, strings, etc. */ -static int data_get_data( struct stream_impl_data *ss, char *dest, int length ) +static int data_get_data( struct colm_program *prg, struct stream_impl_data *ss, char *dest, int length ) { int copied = 0; @@ -288,7 +288,7 @@ static int data_get_data( struct stream_impl_data *ss, char *dest, int length ) /* Got through the in-mem buffers without copying anything. */ struct run_buf *run_buf = new_run_buf( 0 ); source_stream_data_append( ss, run_buf ); - int received = ss->funcs->get_data_source( (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE ); + int received = ss->funcs->get_data_source( prg, (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE ); run_buf->length = received; if ( received == 0 ) break; @@ -341,18 +341,18 @@ static void data_destructor( program_t *prg, tree_t **sp, struct stream_impl_dat free( si ); } -static str_collect_t *data_get_collect( struct stream_impl_data *si ) +static str_collect_t *data_get_collect( struct colm_program *prg, struct stream_impl_data *si ) { return si->collect; } -static void data_flush_stream( struct stream_impl_data *si ) +static void data_flush_stream( struct colm_program *prg, struct stream_impl_data *si ) { if ( si->file != 0 ) fflush( si->file ); } -static void data_close_stream( struct stream_impl_data *si ) +static void data_close_stream( struct colm_program *prg, struct stream_impl_data *si ) { if ( si->file != 0 ) { colm_close_stream_file( si->file ); @@ -369,17 +369,17 @@ static void data_print_tree( struct colm_program *prg, tree_t **sp, colm_print_tree_collect( prg, sp, si->collect, tree, false ); } -char data_get_eof_sent( struct stream_impl_data *si ) +char data_get_eof_sent( struct colm_program *prg, struct stream_impl_data *si ) { return si->eof_sent; } -void data_set_eof_sent( struct stream_impl_data *si, char eof_sent ) +void data_set_eof_sent( struct colm_program *prg, struct stream_impl_data *si, char eof_sent ) { si->eof_sent = eof_sent; } -static int data_get_parse_block( struct stream_impl_data *ss, int skip, char **pdp, int *copied ) +static int data_get_parse_block( struct colm_program *prg, struct stream_impl_data *ss, int skip, char **pdp, int *copied ) { int ret = 0; *copied = 0; @@ -391,7 +391,7 @@ static int data_get_parse_block( struct stream_impl_data *ss, int skip, char **p /* Got through the in-mem buffers without copying anything. */ struct run_buf *run_buf = new_run_buf( 0 ); source_stream_data_append( ss, run_buf ); - int received = ss->funcs->get_data_source( (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE ); + int received = ss->funcs->get_data_source( prg, (struct stream_impl*)ss, run_buf->data, FSM_BUFSIZE ); if ( received == 0 ) { ret = INPUT_EOD; break; @@ -438,7 +438,7 @@ static int data_get_parse_block( struct stream_impl_data *ss, int skip, char **p return ret; } -static int data_consume_data( struct stream_impl_data *ss, int length, location_t *loc ) +static int data_consume_data( struct colm_program *prg, struct stream_impl_data *ss, int length, location_t *loc ) { int consumed = 0; @@ -455,7 +455,7 @@ static int data_consume_data( struct stream_impl_data *ss, int length, location_ break; else { if ( !loc_set( loc ) ) - transfer_loc_data( loc, ss ); + transfer_loc_data( prg, loc, ss ); /* Anything available in the current buffer. */ int avail = buf->length - buf->offset; @@ -480,7 +480,7 @@ static int data_consume_data( struct stream_impl_data *ss, int length, location_ return consumed; } -static int data_undo_consume_data( struct stream_impl_data *si, const char *data, int length ) +static int data_undo_consume_data( struct colm_program *prg, struct stream_impl_data *si, const char *data, int length ) { //printf( "data-undo-consume-data %p, undoing consume of %d bytes, consumed: %d\n", si, length, si->consumed ); @@ -503,7 +503,7 @@ static int data_undo_consume_data( struct stream_impl_data *si, const char *data * File Inputs */ -static int file_get_data_source( struct stream_impl_data *si, char *dest, int length ) +static int file_get_data_source( struct colm_program *prg, struct stream_impl_data *si, char *dest, int length ) { return fread( dest, 1, length, si->file ); } @@ -517,7 +517,7 @@ void init_file_funcs() * Text inputs */ -static int text_get_data_source( struct stream_impl_data *si, char *dest, int want ) +static int text_get_data_source( struct colm_program *prg, struct stream_impl_data *si, char *dest, int want ) { long avail = si->dlen - si->offset; long take = avail < want ? avail : want; @@ -635,12 +635,12 @@ static int is_source_stream( struct stream_impl_seq *is ) return false; } -static void stream_set_eof( struct stream_impl_seq *si ) +static void stream_set_eof( struct colm_program *prg, struct stream_impl_seq *si ) { si->eof = true; } -static void stream_unset_eof( struct stream_impl_seq *si ) +static void stream_unset_eof( struct colm_program *prg, struct stream_impl_seq *si ) { if ( is_source_stream( si ) ) { struct stream_impl_data *sid = (struct stream_impl_data*)si->queue->si; @@ -664,16 +664,16 @@ static void stream_destructor( program_t *prg, tree_t **sp, struct stream_impl_s free( si ); } -static str_collect_t *stream_get_collect( struct stream_impl_seq *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 stream_impl_seq *si ) +static void stream_flush_stream( struct colm_program *prg, struct stream_impl_seq *si ) { } -static void stream_close_stream( struct stream_impl_seq *si ) +static void stream_close_stream( struct colm_program *prg, struct stream_impl_seq *si ) { } @@ -682,17 +682,17 @@ static void stream_print_tree( struct colm_program *prg, tree_t **sp, { } -char stream_get_eof_sent( struct stream_impl_seq *si ) +char stream_get_eof_sent( struct colm_program *prg, struct stream_impl_seq *si ) { return si->eof_sent; } -void stream_set_eof_sent( struct stream_impl_seq *si, char eof_sent ) +void stream_set_eof_sent( struct colm_program *prg, struct stream_impl_seq *si, char eof_sent ) { si->eof_sent = eof_sent; } -static int stream_get_parse_block( struct stream_impl_seq *is, int skip, char **pdp, int *copied ) +static int stream_get_parse_block( struct colm_program *prg, struct stream_impl_seq *is, int skip, char **pdp, int *copied ) { int ret = 0; *copied = 0; @@ -708,7 +708,7 @@ static int stream_get_parse_block( struct stream_impl_seq *is, int skip, char ** if ( buf->type == RUN_BUF_SOURCE_TYPE ) { struct stream_impl *si = buf->si; - int type = si->funcs->get_parse_block( si, skip, pdp, copied ); + int type = si->funcs->get_parse_block( prg, si, skip, pdp, copied ); // if ( type == INPUT_EOD && !si->eosSent ) { // si->eosSent = 1; @@ -791,7 +791,7 @@ static int stream_get_parse_block( struct stream_impl_seq *is, int skip, char ** return ret; } -static int stream_get_data( struct stream_impl_seq *is, char *dest, int length ) +static int stream_get_data( struct colm_program *prg, struct stream_impl_seq *is, char *dest, int length ) { int copied = 0; @@ -805,7 +805,7 @@ static int stream_get_data( struct stream_impl_seq *is, char *dest, int length ) if ( buf->type == RUN_BUF_SOURCE_TYPE ) { struct stream_impl *si = buf->si; - int glen = si->funcs->get_data( si, dest+copied, length ); + int glen = si->funcs->get_data( prg, si, dest+copied, length ); if ( glen == 0 ) { //debug( REALM_INPUT, "skipping over input\n" ); @@ -847,7 +847,7 @@ static int stream_get_data( struct stream_impl_seq *is, char *dest, int length ) return copied; } -static int stream_consume_data( struct stream_impl_seq *is, int length, location_t *loc ) +static int stream_consume_data( struct colm_program *prg, struct stream_impl_seq *is, int length, location_t *loc ) { //debug( REALM_INPUT, "consuming %d bytes\n", length ); @@ -862,7 +862,7 @@ static int stream_consume_data( struct stream_impl_seq *is, int length, location if ( buf->type == RUN_BUF_SOURCE_TYPE ) { struct stream_impl *si = buf->si; - int slen = si->funcs->consume_data( si, length, loc ); + int slen = si->funcs->consume_data( prg, si, length, loc ); //debug( REALM_INPUT, " got %d bytes from source\n", slen ); consumed += slen; @@ -875,7 +875,7 @@ static int stream_consume_data( struct stream_impl_seq *is, int length, location else { if ( !loc_set( loc ) ) { if ( is->line > 0 ) - transfer_loc_seq( loc, is ); + transfer_loc_seq( prg, loc, is ); else default_loc( loc ); } @@ -906,18 +906,18 @@ static int stream_consume_data( struct stream_impl_seq *is, int length, location return consumed; } -static int stream_undo_consume_data( struct stream_impl_seq *is, const char *data, int length ) +static int stream_undo_consume_data( struct colm_program *prg, struct stream_impl_seq *is, const char *data, int length ) { //debug( REALM_INPUT, "stream %p, undoing consume of %ld bytes\n", is, length ); if ( is->consumed == 0 && is_source_stream( is ) ) { struct stream_impl *si = is->queue->si; - int pushed_back = si->funcs->undo_consume_data( si, data, length ); + int pushed_back = si->funcs->undo_consume_data( prg, si, data, length ); if ( pushed_back < length ) { struct seq_buf *b = input_stream_pop_stash( is ); input_stream_seq_prepend( is, b ); - pushed_back += stream_undo_consume_data( is, data + pushed_back, length - pushed_back ); + pushed_back += stream_undo_consume_data( prg, is, data + pushed_back, length - pushed_back ); } return pushed_back; @@ -933,7 +933,7 @@ static int stream_undo_consume_data( struct stream_impl_seq *is, const char *dat } } -static tree_t *stream_consume_tree( struct stream_impl_seq *is ) +static tree_t *stream_consume_tree( struct colm_program *prg, struct stream_impl_seq *is ) { while ( is->queue != 0 && ( is->queue->type == RUN_BUF_SOURCE_TYPE || is->queue->type == RUN_BUF_DATA_TYPE ) && is->queue->offset == is->queue->length ) @@ -956,7 +956,7 @@ static tree_t *stream_consume_tree( struct stream_impl_seq *is ) return 0; } -static void stream_undo_consume_tree( struct stream_impl_seq *is, tree_t *tree, int ignore ) +static void stream_undo_consume_tree( struct colm_program *prg, struct stream_impl_seq *is, tree_t *tree, int ignore ) { /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -966,30 +966,30 @@ static void stream_undo_consume_tree( struct stream_impl_seq *is, tree_t *tree, input_stream_seq_prepend( is, b ); } -static struct LangEl *stream_consume_lang_el( struct stream_impl_seq *is, long *bind_id, +static struct LangEl *stream_consume_lang_el( struct colm_program *prg, struct stream_impl_seq *is, long *bind_id, char **data, long *length ) { if ( is_source_stream( is ) ) { struct stream_impl *si = is->queue->si; - return si->funcs->consume_lang_el( si, bind_id, data, length ); + return si->funcs->consume_lang_el( prg, si, bind_id, data, length ); } else { assert( false ); } } -static void stream_undo_consume_lang_el( struct stream_impl_seq *is ) +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( si ); + return si->funcs->undo_consume_lang_el( prg, si ); } else { assert( false ); } } -static void stream_prepend_data( struct stream_impl_seq *si, const char *data, long length ) +static void stream_prepend_data( struct colm_program *prg, struct stream_impl_seq *si, const char *data, long length ) { struct stream_impl *sub_si = colm_impl_new_text( "<text>", data, length ); @@ -1000,7 +1000,7 @@ static void stream_prepend_data( struct stream_impl_seq *si, const char *data, l input_stream_seq_prepend( si, new_buf ); } -static void stream_append_data( struct stream_impl_seq *si, const char *data, long length ) +static void stream_append_data( struct colm_program *prg, struct stream_impl_seq *si, const char *data, long length ) { struct stream_impl *sub_si = colm_impl_new_text( "<text>", data, length ); @@ -1011,7 +1011,7 @@ static void stream_append_data( struct stream_impl_seq *si, const char *data, lo input_stream_seq_append( si, new_buf ); } -static void stream_prepend_tree( struct stream_impl_seq *is, tree_t *tree, int ignore ) +static void stream_prepend_tree( struct colm_program *prg, struct stream_impl_seq *is, tree_t *tree, int ignore ) { /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -1022,7 +1022,7 @@ static void stream_prepend_tree( struct stream_impl_seq *is, tree_t *tree, int i input_stream_seq_prepend( is, new_buf ); } -static void stream_prepend_stream( struct stream_impl_seq *in, struct colm_stream *stream ) +static void stream_prepend_stream( struct colm_program *prg, struct stream_impl_seq *in, struct colm_stream *stream ) { /* Create a new buffer for the data. This is the easy implementation. * Something better is needed here. It puts a max on the amount of @@ -1033,10 +1033,10 @@ static void stream_prepend_stream( struct stream_impl_seq *in, struct colm_strea input_stream_seq_prepend( in, new_buf ); } -static int stream_data_undo_prepend_data( struct stream_impl_data *is, int length ); -static int stream_seq_undo_prepend_data( struct stream_impl_seq *is, int length ); +static int stream_data_undo_prepend_data( struct colm_program *prg, struct stream_impl_data *is, int length ); +static int stream_seq_undo_prepend_data( struct colm_program *prg, struct stream_impl_seq *is, int length ); -static int stream_seq_undo_prepend_data( struct stream_impl_seq *is, int length ) +static int stream_seq_undo_prepend_data( struct colm_program *prg, struct stream_impl_seq *is, int length ) { //debug( REALM_INPUT, "consuming %d bytes\n", length ); @@ -1051,7 +1051,7 @@ static int stream_seq_undo_prepend_data( struct stream_impl_seq *is, int length if ( buf->type == RUN_BUF_SOURCE_TYPE ) { struct stream_impl *si = buf->si; - int slen = stream_data_undo_prepend_data( (struct stream_impl_data*)si, length ); + int slen = stream_data_undo_prepend_data( prg, (struct stream_impl_data*)si, length ); consumed += slen; length -= slen; @@ -1082,7 +1082,7 @@ static int stream_seq_undo_prepend_data( struct stream_impl_seq *is, int length return consumed; } -static int stream_data_undo_prepend_data( struct stream_impl_data *is, int length ) +static int stream_data_undo_prepend_data( struct colm_program *prg, struct stream_impl_data *is, int length ) { //debug( REALM_INPUT, "consuming %d bytes\n", length ); @@ -1121,7 +1121,7 @@ static int stream_data_undo_prepend_data( struct stream_impl_data *is, int lengt return consumed; } -static tree_t *stream_undo_prepend_tree( struct stream_impl_seq *is ) +static tree_t *stream_undo_prepend_tree( struct colm_program *prg, struct stream_impl_seq *is ) { while ( is->queue != 0 && ( is->queue->type == RUN_BUF_SOURCE_TYPE || is->queue->type == RUN_BUF_DATA_TYPE ) && is->queue->offset == is->queue->length ) @@ -1144,7 +1144,7 @@ static tree_t *stream_undo_prepend_tree( struct stream_impl_seq *is ) return 0; } -static tree_t *stream_undo_append_data( struct stream_impl_seq *is, int length ) +static tree_t *stream_undo_append_data( struct colm_program *prg, struct stream_impl_seq *is, int length ) { int consumed = 0; @@ -1181,7 +1181,7 @@ static tree_t *stream_undo_append_data( struct stream_impl_seq *is, int length ) return 0; } -static void stream_append_tree( struct stream_impl_seq *is, tree_t *tree ) +static void stream_append_tree( struct colm_program *prg, struct stream_impl_seq *is, tree_t *tree ) { struct seq_buf *ad = new_seq_buf( 0 ); @@ -1192,7 +1192,7 @@ static void stream_append_tree( struct stream_impl_seq *is, tree_t *tree ) ad->length = 0; } -static void stream_append_stream( struct stream_impl_seq *in, struct colm_stream *stream ) +static void stream_append_stream( struct colm_program *prg, struct stream_impl_seq *in, struct colm_stream *stream ) { struct seq_buf *ad = new_seq_buf( 0 ); @@ -1203,7 +1203,7 @@ static void stream_append_stream( struct stream_impl_seq *in, struct colm_stream ad->length = 0; } -static tree_t *stream_undo_append_tree( struct stream_impl_seq *is ) +static tree_t *stream_undo_append_tree( struct colm_program *prg, struct stream_impl_seq *is ) { struct seq_buf *seq_buf = input_stream_seq_pop_tail( is ); tree_t *tree = seq_buf->tree; @@ -1211,7 +1211,7 @@ static tree_t *stream_undo_append_tree( struct stream_impl_seq *is ) return tree; } -static tree_t *stream_undo_append_stream( struct stream_impl_seq *is ) +static tree_t *stream_undo_append_stream( struct colm_program *prg, struct stream_impl_seq *is ) { struct seq_buf *seq_buf = input_stream_seq_pop_tail( is ); tree_t *tree = seq_buf->tree; @@ -1411,7 +1411,7 @@ stream_t *colm_stream_new( program_t *prg ) str_t *collect_string( program_t *prg, stream_t *s ) { - str_collect_t *collect = s->impl->funcs->get_collect( s->impl ); + str_collect_t *collect = s->impl->funcs->get_collect( prg, s->impl ); head_t *head = string_alloc_full( prg, collect->data, collect->length ); str_t *str = (str_t*)construct_string( prg, head ); return str; diff --git a/src/input.h b/src/input.h index fbe2ec01..56d9b1f0 100644 --- a/src/input.h +++ b/src/input.h @@ -90,38 +90,38 @@ struct run_buf *new_run_buf( int sz ); #define DEF_STREAM_FUNCS( stream_funcs, stream_impl ) \ struct stream_funcs \ { \ - int (*get_parse_block)( struct stream_impl *si, int skip, char **pdp, int *copied ); \ - int (*get_data)( struct stream_impl *si, char *dest, int length ); \ - int (*consume_data)( struct stream_impl *si, int length, struct colm_location *loc ); \ - struct colm_tree *(*consume_tree)( struct stream_impl *si ); \ - struct LangEl *(*consume_lang_el)( struct stream_impl *si, long *bind_id, char **data, long *length ); \ - int (*undo_consume_data)( struct stream_impl *si, const char *data, int length ); \ - void (*undo_consume_tree)( struct stream_impl *si, struct colm_tree *tree, int ignore ); \ - void (*undo_consume_lang_el)( struct stream_impl *si ); \ - int (*get_data_source)( struct stream_impl *si, char *dest, int length ); \ - void (*set_eof)( struct stream_impl *si ); \ - void (*unset_eof)( struct stream_impl *si ); \ - 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 *si, int length ); \ - struct colm_tree *(*undo_prepend_tree)( struct stream_impl *si ); \ - struct colm_tree *(*undo_prepend_stream)( struct stream_impl *si ); \ - 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 *si, int length ); \ - struct colm_tree *(*undo_append_tree)( struct stream_impl *si ); \ - struct colm_tree *(*undo_append_stream)( struct stream_impl *si ); \ + int (*get_parse_block)( struct colm_program *prg, struct stream_impl *si, int skip, char **pdp, int *copied ); \ + int (*get_data)( 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 ); \ + struct colm_tree *(*consume_tree)( struct colm_program *prg, struct stream_impl *si ); \ + struct LangEl *(*consume_lang_el)( struct colm_program *prg, struct stream_impl *si, long *bind_id, char **data, long *length ); \ + int (*undo_consume_data)( struct colm_program *prg, struct stream_impl *si, const char *data, int length ); \ + void (*undo_consume_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \ + void (*undo_consume_lang_el)( struct colm_program *prg, struct stream_impl *si ); \ + int (*get_data_source)( struct colm_program *prg, struct stream_impl *si, char *dest, int length ); \ + void (*set_eof)( struct colm_program *prg, struct stream_impl *si ); \ + void (*unset_eof)( struct colm_program *prg, struct stream_impl *si ); \ + void (*prepend_data)( struct colm_program *prg, struct stream_impl *si, const char *data, long len ); \ + void (*prepend_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree, int ignore ); \ + void (*prepend_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \ + int (*undo_prepend_data)( struct colm_program *prg, struct stream_impl *si, int length ); \ + struct colm_tree *(*undo_prepend_tree)( struct colm_program *prg, struct stream_impl *si ); \ + 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 ); \ + void (*append_tree)( struct colm_program *prg, struct stream_impl *si, struct colm_tree *tree ); \ + void (*append_stream)( struct colm_program *prg, struct stream_impl *si, struct colm_stream *stream ); \ + struct colm_tree *(*undo_append_data)( struct colm_program *prg, struct stream_impl *si, int length ); \ + struct colm_tree *(*undo_append_tree)( struct colm_program *prg, struct stream_impl *si ); \ + struct colm_tree *(*undo_append_stream)( struct colm_program *prg, struct stream_impl *si ); \ void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct stream_impl *si ); \ - struct colm_str_collect *(*get_collect)( struct stream_impl *si ); \ - void (*flush_stream)( struct stream_impl *si ); \ - void (*close_stream)( struct stream_impl *si ); \ + struct colm_str_collect *(*get_collect)( struct colm_program *prg, struct stream_impl *si ); \ + void (*flush_stream)( struct colm_program *prg, struct stream_impl *si ); \ + void (*close_stream)( struct colm_program *prg, struct stream_impl *si ); \ void (*print_tree)( struct colm_program *prg, struct colm_tree **sp, \ struct stream_impl *impl, struct colm_tree *tree, int trim ); \ - char (*get_eof_sent)( struct stream_impl *si ); \ - void (*set_eof_sent)( struct stream_impl *si, char eof_sent ); \ - void (*transfer_loc)( struct colm_location *loc, struct stream_impl *si ); \ + char (*get_eof_sent)( struct colm_program *prg, struct stream_impl *si ); \ + void (*set_eof_sent)( struct colm_program *prg, struct stream_impl *si, char eof_sent ); \ + void (*transfer_loc)( struct colm_program *prg, struct colm_location *loc, struct stream_impl *si ); \ } DEF_STREAM_FUNCS( stream_funcs, stream_impl ); diff --git a/src/pdarun.c b/src/pdarun.c index 212e3a10..04acc1cd 100644 --- a/src/pdarun.c +++ b/src/pdarun.c @@ -114,9 +114,9 @@ head_t *colm_stream_pull( program_t *prg, tree_t **sp, struct pda_run *pda_run, char *dest = run_buf->data + run_buf->length; - is->funcs->get_data( is, dest, length ); + is->funcs->get_data( prg, is, dest, length ); location_t *loc = location_allocate( prg ); - is->funcs->consume_data( is, length, loc ); + is->funcs->consume_data( prg, is, length, loc ); run_buf->length += length; @@ -132,52 +132,52 @@ head_t *colm_stream_pull( program_t *prg, tree_t **sp, struct pda_run *pda_run, head_t *head = init_str_space( length ); char *dest = (char*)head->data; - is->funcs->get_data( is, dest, length ); + is->funcs->get_data( prg, is, dest, length ); location_t *loc = location_allocate( prg ); - is->funcs->consume_data( is, length, loc ); + is->funcs->consume_data( prg, is, length, loc ); head->location = loc; return head; } } -void undo_stream_pull( struct stream_impl *is, const char *data, long length ) +void undo_stream_pull( struct colm_program *prg, struct stream_impl *is, const char *data, long length ) { //debug( REALM_PARSE, "undoing stream pull\n" ); - is->funcs->prepend_data( is, data, length ); + is->funcs->prepend_data( prg, is, data, length ); } -void colm_stream_push_text( struct stream_impl *is, const char *data, long length ) +void colm_stream_push_text( struct colm_program *prg, struct stream_impl *is, const char *data, long length ) { - is->funcs->prepend_data( is, data, length ); + is->funcs->prepend_data( prg, is, data, length ); } -void colm_stream_push_tree( struct stream_impl *is, tree_t *tree, int ignore ) +void colm_stream_push_tree( struct colm_program *prg, struct stream_impl *is, tree_t *tree, int ignore ) { - is->funcs->prepend_tree( is, tree, ignore ); + is->funcs->prepend_tree( prg, is, tree, ignore ); } -void colm_stream_push_stream( struct stream_impl *is, stream_t *stream ) +void colm_stream_push_stream( struct colm_program *prg, struct stream_impl *is, stream_t *stream ) { - is->funcs->prepend_stream( is, stream ); + is->funcs->prepend_stream( prg, is, stream ); } void colm_undo_stream_push( program_t *prg, tree_t **sp, struct stream_impl *is, long length ) { if ( length < 0 ) { - tree_t *tree = is->funcs->undo_prepend_tree( is ); + tree_t *tree = is->funcs->undo_prepend_tree( prg, is ); colm_tree_downref( prg, sp, tree ); } else { - is->funcs->undo_prepend_data( is, length ); + is->funcs->undo_prepend_data( prg, is, length ); } } /* Should only be sending back whole tokens/ignores, therefore the send back * should never cross a buffer boundary. Either we slide back data, or we move to * a previous buffer and slide back data. */ -static void send_back_text( struct stream_impl *is, const char *data, long length ) +static void send_back_text( struct colm_program *prg, struct stream_impl *is, const char *data, long length ) { //debug( REALM_PARSE, "push back of %ld characters\n", length ); @@ -187,12 +187,12 @@ static void send_back_text( struct stream_impl *is, const char *data, long lengt //debug( REALM_PARSE, "sending back text: %.*s\n", // (int)length, data ); - is->funcs->undo_consume_data( is, data, length ); + is->funcs->undo_consume_data( prg, is, data, length ); } -static void send_back_tree( struct stream_impl *is, tree_t *tree ) +static void send_back_tree( struct colm_program *prg, struct stream_impl *is, tree_t *tree ) { - is->funcs->undo_consume_tree( is, tree, false ); + is->funcs->undo_consume_tree( prg, is, tree, false ); } /* @@ -213,7 +213,7 @@ static void send_back_ignore( program_t *prg, tree_t **sp, int artificial = parse_tree->flags & PF_ARTIFICIAL; if ( head != 0 && !artificial ) - send_back_text( is, string_data( head ), head->length ); + send_back_text( prg, is, string_data( head ), head->length ); colm_decrement_steps( pda_run ); @@ -254,7 +254,7 @@ static void send_back( program_t *prg, tree_t **sp, struct pda_run *pda_run, if ( parse_tree->flags & PF_NAMED ) { /* Send the named lang el back first, then send back any leading * whitespace. */ - is->funcs->undo_consume_lang_el( is ); + is->funcs->undo_consume_lang_el( prg, is ); } colm_decrement_steps( pda_run ); @@ -270,7 +270,7 @@ static void send_back( program_t *prg, tree_t **sp, struct pda_run *pda_run, colm_tree_upref( prg, parse_tree->shadow->tree ); - send_back_tree( is, parse_tree->shadow->tree ); + send_back_tree( prg, is, parse_tree->shadow->tree ); } else { /* Check for reverse code. */ @@ -281,12 +281,12 @@ static void send_back( program_t *prg, tree_t **sp, struct pda_run *pda_run, } /* Push back the token data. */ - send_back_text( is, string_data( parse_tree->shadow->tree->tokdata ), + send_back_text( prg, is, string_data( parse_tree->shadow->tree->tokdata ), string_length( parse_tree->shadow->tree->tokdata ) ); /* If eof was just sent back remember that it needs to be sent again. */ if ( parse_tree->id == prg->rtd->eof_lel_ids[pda_run->parser_id] ) - is->funcs->set_eof_sent( is, false ); + is->funcs->set_eof_sent( prg, is, false ); /* If the item is bound then store remove it from the bindings array. */ prg->rtd->pop_binding( pda_run, parse_tree ); @@ -741,9 +741,9 @@ static head_t *extract_match( program_t *prg, tree_t **sp, char *dest = run_buf->data + run_buf->length; - is->funcs->get_data( is, dest, length ); + is->funcs->get_data( prg, is, dest, length ); location_t *location = location_allocate( prg ); - is->funcs->consume_data( is, length, location ); + is->funcs->consume_data( prg, is, length, location ); run_buf->length += length; @@ -767,7 +767,7 @@ static head_t *extract_no_d( program_t *prg, tree_t **sp, /* Just a consume, no data allocate. */ location_t *location = location_allocate( prg ); - is->funcs->consume_data( is, length, location ); + is->funcs->consume_data( prg, is, length, location ); pda_run->p = pda_run->pe = 0; pda_run->toklen = 0; @@ -798,12 +798,12 @@ static head_t *extract_no_l( program_t *prg, tree_t **sp, char *dest = run_buf->data + run_buf->length; - is->funcs->get_data( is, dest, length ); + is->funcs->get_data( prg, is, dest, length ); /* Using a dummpy location. */ location_t location; memset( &location, 0, sizeof( location ) ); - is->funcs->consume_data( is, length, &location ); + is->funcs->consume_data( prg, is, length, &location ); run_buf->length += length; @@ -829,7 +829,7 @@ static head_t *consume_match( program_t *prg, tree_t **sp, /* No data or location returned. We just consume the data. */ location_t dummy_loc; memset( &dummy_loc, 0, sizeof(dummy_loc) ); - is->funcs->consume_data( is, length, &dummy_loc ); + is->funcs->consume_data( prg, is, length, &dummy_loc ); pda_run->p = pda_run->pe = 0; pda_run->toklen = 0; @@ -854,7 +854,7 @@ static head_t *peek_match( program_t *prg, struct pda_run *pda_run, struct strea char *dest = run_buf->data + run_buf->length; - is->funcs->get_data( is, dest, length ); + is->funcs->get_data( prg, is, dest, length ); pda_run->p = pda_run->pe = 0; pda_run->toklen = 0; @@ -862,7 +862,7 @@ static head_t *peek_match( program_t *prg, struct pda_run *pda_run, struct strea head_t *head = colm_string_alloc_pointer( prg, dest, length ); head->location = location_allocate( prg ); - is->funcs->transfer_loc( head->location, is ); + is->funcs->transfer_loc( prg, head->location, is ); debug( prg, REALM_PARSE, "location byte: %d\n", head->location->byte ); @@ -941,7 +941,7 @@ static void send_tree( program_t *prg, tree_t **sp, struct pda_run *pda_run, struct stream_impl *is ) { kid_t *input = kid_allocate( prg ); - input->tree = is->funcs->consume_tree( is ); + input->tree = is->funcs->consume_tree( prg, is ); colm_increment_steps( pda_run ); @@ -956,7 +956,7 @@ static void send_tree( program_t *prg, tree_t **sp, struct pda_run *pda_run, static void send_ignore_tree( program_t *prg, tree_t **sp, struct pda_run *pda_run, struct stream_impl *is ) { - tree_t *tree = is->funcs->consume_tree( is ); + tree_t *tree = is->funcs->consume_tree( prg, is ); ignore_tree_art( prg, pda_run, tree ); } @@ -970,7 +970,7 @@ static void send_collect_ignore( program_t *prg, tree_t **sp, /* Make the token data. */ head_t *tokdata = head_allocate( prg ); tokdata->location = location_allocate( prg ); - is->funcs->transfer_loc( tokdata->location, is ); + is->funcs->transfer_loc( prg, tokdata->location, is ); debug( prg, REALM_PARSE, "token: %s text: %.*s\n", prg->rtd->lel_info[id].name, @@ -1010,7 +1010,7 @@ static void send_eof( program_t *prg, tree_t **sp, struct pda_run *pda_run, stru head_t *head = head_allocate( prg ); head->location = location_allocate( prg ); - is->funcs->transfer_loc( head->location, is ); + is->funcs->transfer_loc( prg, head->location, is ); kid_t *input = kid_allocate( prg ); input->tree = tree_allocate( prg ); @@ -1097,7 +1097,7 @@ static long scan_token( program_t *prg, struct pda_run *pda_run, struct stream_i while ( true ) { char *pd = 0; int len = 0; - int type = is->funcs->get_parse_block( is, pda_run->toklen, &pd, &len ); + int type = is->funcs->get_parse_block( prg, is, pda_run->toklen, &pd, &len ); switch ( type ) { case INPUT_DATA: @@ -2003,7 +2003,7 @@ long colm_parse_loop( program_t *prg, tree_t **sp, struct pda_run *pda_run, /* Check for EOF. */ if ( pda_run->token_id == SCAN_EOF ) { - is->funcs->set_eof_sent( is, true ); + is->funcs->set_eof_sent( prg, is, true ); send_eof( prg, sp, pda_run, is ); pda_run->frame_id = prg->rtd->region_info[pda_run->region].eof_frame_id; @@ -2160,7 +2160,7 @@ skip_send: break; } - if ( is->funcs->get_eof_sent( is ) ) { + if ( is->funcs->get_eof_sent( prg, is ) ) { debug( prg, REALM_PARSE, "parsing stopped by EOF\n" ); break; } diff --git a/src/pdarun.h b/src/pdarun.h index 6e55dcd3..1ac564ca 100644 --- a/src/pdarun.h +++ b/src/pdarun.h @@ -70,7 +70,7 @@ struct fsm_tables long num_action_switch; }; -void undo_stream_pull( struct stream_impl *input_stream, const char *data, long length ); +void undo_stream_pull( struct colm_program *prg, struct stream_impl *input_stream, const char *data, long length ); #if SIZEOF_LONG != 4 && SIZEOF_LONG != 8 #error "SIZEOF_LONG contained an unexpected value" @@ -443,9 +443,9 @@ head_t *colm_stream_pull( struct colm_program *prg, struct colm_tree **sp, struct pda_run *pda_run, struct stream_impl *is, long length ); head_t *colm_string_alloc_pointer( struct colm_program *prg, const char *data, long length ); -void colm_stream_push_text( struct stream_impl *input_stream, const char *data, long length ); -void colm_stream_push_tree( struct stream_impl *input_stream, tree_t *tree, int ignore ); -void colm_stream_push_stream( struct stream_impl *input_stream, stream_t *stream ); +void colm_stream_push_text( struct colm_program *prg, struct stream_impl *input_stream, const char *data, long length ); +void colm_stream_push_tree( struct colm_program *prg, struct stream_impl *input_stream, tree_t *tree, int ignore ); +void colm_stream_push_stream( struct colm_program *prg, struct stream_impl *input_stream, stream_t *stream ); void colm_undo_stream_push( struct colm_program *prg, tree_t **sp, struct stream_impl *input_stream, long length ); |