From f97bb9b5969fa17848c65452617d68789dedf91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 12 Nov 2017 11:23:29 +0100 Subject: [PATCH] Parser - Changes to AST for the if instruction The "else" case is now specific (to value 0), while the "then" case is the default. --- opparser.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/opparser.cc b/opparser.cc index f22c790..eca1e5f 100644 --- a/opparser.cc +++ b/opparser.cc @@ -1195,19 +1195,21 @@ M_INSTR_( If ) return; } - cond.setCase( 1 , parseBlock( cond , input[ 2 ] ) ); - if ( cond.hasCase( 1 ) ) { - cond.getCase( 1 ).location( ) = input[ 2 ].location( ); + cond.setDefaultCase( parseBlock( cond , input[ 2 ] ) ); + if ( cond.hasDefaultCase( ) ) { + cond.defaultCase( ).location( ) = input[ 2 ].location( ); } if ( input.size( ) > 3 ) { - cond.setDefaultCase( parseBlock( cond , input[ 3 ] ) ); - if ( cond.hasDefaultCase( ) ) { - cond.defaultCase( ).location( ) = input[ 3 ].location( ); + cond.setCase( 0 , parseBlock( cond , input[ 3 ] ) ); + if ( cond.hasCase( 0 ) ) { + cond.getCase( 0 ).location( ) = input[ 3 ].location( ); } if ( input.size( ) > 4 ) { errors.addNew( "too many arguments" , input[ 4 ].location( ) ); } + } else { + cond.setCase( 0 , NewOwned< T_InstrListNode >( cond ) ); } }