summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2019-12-26 16:07:43 +0200
committerAdrian Thurston <thurston@colm.net>2019-12-26 16:17:53 +0200
commitf08be4173ea6955dda3c48c67bdcb39865133f13 (patch)
tree42b73ee036065af4848841228fd23fd095a16a03 /test
parentc312dc1990f9bb4620264bcc486f75d18312e065 (diff)
downloadcolm-f08be4173ea6955dda3c48c67bdcb39865133f13.tar.gz
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
Diffstat (limited to 'test')
-rw-r--r--test/rlparse.d/load.cc90
-rw-r--r--test/rlparse.d/reducer.cc7
2 files changed, 58 insertions, 39 deletions
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<ruby_inline::_repeat_block_item, ruby_inline::block_item> 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<ruby_inline::_repeat_expr_item, ruby_inline::expr_item> 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<ocaml_inline::_repeat_block_item, ocaml_inline::block_item> 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<ocaml_inline::_repeat_expr_item, ocaml_inline::expr_item> 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<crack_inline::_repeat_block_item, crack_inline::block_item> 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<crack_inline::_repeat_expr_item, crack_inline::expr_item> 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<ragel::_repeat_write_arg, ragel::write_arg> 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<ragel::_repeat_statement, ragel::statement> 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<c_host::_repeat_section, c_host::section> 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<ruby_host::_repeat_section, ruby_host::section> 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<ocaml_host::_repeat_section, ocaml_host::section> 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 ) );