From f08be4173ea6955dda3c48c67bdcb39865133f13 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Thu, 26 Dec 2019 16:07:43 +0200 Subject: left/right-independent iterator for repeats in top-down loads Added an iterator for repeats that is independent of left/right recursion. Using it in colm load and tests. Allows us to remove the special case for repeat/list types in the export. The new iterator is implemented as a non-recursive generic tree iterator. refs #90 --- test/rlparse.d/load.cc | 90 ++++++++++++++++++++++++++++------------------- test/rlparse.d/reducer.cc | 7 ++-- 2 files changed, 58 insertions(+), 39 deletions(-) (limited to 'test/rlparse.d') diff --git a/test/rlparse.d/load.cc b/test/rlparse.d/load.cc index 2f5d363f..3d6e297b 100644 --- a/test/rlparse.d/load.cc +++ b/test/rlparse.d/load.cc @@ -318,9 +318,11 @@ struct LoadRagel InlineList *loadInlineBlock( InlineList *inlineList, ruby_inline::inline_block RubyInlineBlock ) { ruby_inline::_repeat_block_item BlockItemList = RubyInlineBlock._repeat_block_item(); - while ( !BlockItemList.end() ) { - loadBlockItem( inlineList, BlockItemList.value() ); - BlockItemList = BlockItemList.next(); + + RepeatIter BlockItemIter( BlockItemList ); + while ( !BlockItemIter.end() ) { + loadBlockItem( inlineList, BlockItemIter.value() ); + BlockItemIter.next(); } return inlineList; } @@ -362,10 +364,11 @@ struct LoadRagel { InlineList *inlineList = new InlineList; ruby_inline::_repeat_expr_item ExprItemList = InlineExpr._repeat_expr_item(); - while ( !ExprItemList.end() ) { - InlineItem *inlineItem = loadExprItem( ExprItemList.value() ); + RepeatIter ExprItemIter( ExprItemList ); + while ( !ExprItemIter.end() ) { + InlineItem *inlineItem = loadExprItem( ExprItemIter.value() ); inlineList->append( inlineItem ); - ExprItemList = ExprItemList.next(); + ExprItemIter.next(); } return inlineList; } @@ -529,9 +532,11 @@ struct LoadRagel InlineList *loadInlineBlock( InlineList *inlineList, ocaml_inline::inline_block OCamlInlineBlock ) { ocaml_inline::_repeat_block_item BlockItemList = OCamlInlineBlock._repeat_block_item(); - while ( !BlockItemList.end() ) { - loadBlockItem( inlineList, BlockItemList.value() ); - BlockItemList = BlockItemList.next(); + + RepeatIter BlockItemIter( BlockItemList ); + while ( !BlockItemIter.end() ) { + loadBlockItem( inlineList, BlockItemIter.value() ); + BlockItemIter.next(); } return inlineList; } @@ -573,10 +578,12 @@ struct LoadRagel { InlineList *inlineList = new InlineList; ocaml_inline::_repeat_expr_item ExprItemList = InlineExpr._repeat_expr_item(); - while ( !ExprItemList.end() ) { - InlineItem *inlineItem = loadExprItem( ExprItemList.value() ); + + RepeatIter ExprItemIter( ExprItemList ); + while ( !ExprItemIter.end() ) { + InlineItem *inlineItem = loadExprItem( ExprItemIter.value() ); inlineList->append( inlineItem ); - ExprItemList = ExprItemList.next(); + ExprItemIter.next(); } return inlineList; } @@ -740,9 +747,11 @@ struct LoadRagel InlineList *loadInlineBlock( InlineList *inlineList, crack_inline::inline_block CrackInlineBlock ) { crack_inline::_repeat_block_item BlockItemList = CrackInlineBlock._repeat_block_item(); - while ( !BlockItemList.end() ) { - loadBlockItem( inlineList, BlockItemList.value() ); - BlockItemList = BlockItemList.next(); + + RepeatIter BlockItemIter( BlockItemList ); + while ( !BlockItemIter.end() ) { + loadBlockItem( inlineList, BlockItemIter.value() ); + BlockItemIter.next(); } return inlineList; } @@ -784,10 +793,12 @@ struct LoadRagel { InlineList *inlineList = new InlineList; crack_inline::_repeat_expr_item ExprItemList = InlineExpr._repeat_expr_item(); - while ( !ExprItemList.end() ) { - InlineItem *inlineItem = loadExprItem( ExprItemList.value() ); + + RepeatIter ExprItemIter( ExprItemList ); + while ( !ExprItemIter.end() ) { + InlineItem *inlineItem = loadExprItem( ExprItemIter.value() ); inlineList->append( inlineItem ); - ExprItemList = ExprItemList.next(); + ExprItemIter.next(); } return inlineList; } @@ -2287,9 +2298,10 @@ struct LoadRagel inputItem->writeArgs.push_back( Cmd.text() ); - while ( !WordList.end() ) { - inputItem->writeArgs.push_back( WordList.value().text() ); - WordList = WordList.next(); + RepeatIter WordIter( WordList ); + while ( !WordIter.end() ) { + inputItem->writeArgs.push_back( WordIter.value().text() ); + WordIter.next(); } id.inputItems.append( inputItem ); @@ -2460,9 +2472,10 @@ struct LoadRagel void loadImportList( _repeat_import ImportList ) { - while ( !ImportList.end() ) { - loadImport( ImportList.value() ); - ImportList = ImportList.next(); + RepeatIter<_repeat_import, import> ImportIter( ImportList ); + while ( !ImportIter.end() ) { + loadImport( ImportIter.value() ); + ImportIter.next(); } } @@ -2588,11 +2601,13 @@ struct LoadRagel } ragel::_repeat_statement StmtList = RagelStart._repeat_statement(); - while ( !StmtList.end() ) { - bool stop = loadStatement( StmtList.value() ); + + RepeatIter StmtIter( StmtList ); + while ( !StmtIter.end() ) { + bool stop = loadStatement( StmtIter.value() ); if ( stop ) break; - StmtList = StmtList.next(); + StmtIter.next(); } } @@ -2691,26 +2706,29 @@ struct LoadRagel c_host::_repeat_section SectionList = Start.SectionList(); if ( SectionList ) { - while ( !SectionList.end() ) { - loadSection( SectionList.value(), targetMachine, searchMachine ); - SectionList = SectionList.next(); + RepeatIter SectionIter( SectionList ); + while ( !SectionIter.end() ) { + loadSection( SectionIter.value(), targetMachine, searchMachine ); + SectionIter.next(); } } else if ( Start.RSectionList() ) { ruby_host::_repeat_section RSectionList = Start.RSectionList(); if ( RSectionList ) { - while ( !RSectionList.end() ) { - loadSection( RSectionList.value(), targetMachine, searchMachine ); - RSectionList = RSectionList.next(); + RepeatIter RSectionIter( RSectionList ); + while ( !RSectionIter.end() ) { + loadSection( RSectionIter.value(), targetMachine, searchMachine ); + RSectionIter.next(); } } } else { ocaml_host::_repeat_section OSectionList = Start.OSectionList(); if ( OSectionList ) { - while ( !OSectionList.end() ) { - loadSection( OSectionList.value(), targetMachine, searchMachine ); - OSectionList = OSectionList.next(); + RepeatIter OSectionIter( OSectionList ); + while ( !OSectionIter.end() ) { + loadSection( OSectionIter.value(), targetMachine, searchMachine ); + OSectionIter.next(); } } } diff --git a/test/rlparse.d/reducer.cc b/test/rlparse.d/reducer.cc index d22b6622..b3bd32ba 100644 --- a/test/rlparse.d/reducer.cc +++ b/test/rlparse.d/reducer.cc @@ -248,8 +248,9 @@ void TopLevel::loadImport( std::string fileName ) return; } - while ( !ImportList.end() ) { - import Import = ImportList.value(); + RepeatIter<_repeat_import, import> ImportIter( ImportList ); + while ( !ImportIter.end() ) { + import Import = ImportIter.value(); InputLoc loc = Import.loc(); string name = Import.Name().text(); @@ -292,7 +293,7 @@ void TopLevel::loadImport( std::string fileName ) tryMachineDef( loc, name, machineDef, false ); machineDef->join->loc = loc; - ImportList = ImportList.next(); + ImportIter.next(); } id->streamFileNames.append( colm_extract_fns( program ) ); -- cgit v1.2.1