From 36347c02fe7263cc9dcec2a29004062275236bbd Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 2 Jan 2025 16:48:05 +0100 Subject: [PATCH] gac: improve handling of Assert & Info ... by having the comments generated for them be faithful to the source code, just like for all other statements. --- src/compiler.c | 18 +++++++++++++++--- tst/test-compile/assert.g.dynamic.c | 18 +++++++++--------- tst/test-compile/info.g.dynamic.c | 10 +++++----- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/compiler.c b/src/compiler.c index d79ca6fd8c..8db16aa276 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -4915,7 +4915,11 @@ static void CompInfo(Stat stat) Int narg; Int i; - Emit( "\n/* Info( ... ); */\n" ); + // print a comment + if ( CompPass == 2 ) { + Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" ); + } + sel = CompExpr( ARGI_INFO( stat, 1 ) ); lev = CompExpr( ARGI_INFO( stat, 2 ) ); lst = CVAR_TEMP( NewTemp( "lst" ) ); @@ -4951,7 +4955,11 @@ static void CompAssert2(Stat stat) CVar lev; // the level CVar cnd; // the condition - Emit( "\n/* Assert( ... ); */\n" ); + // print a comment + if ( CompPass == 2 ) { + Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" ); + } + lev = CompExpr(READ_STAT(stat, 0)); Emit( "if ( STATE(CurrentAssertionLevel) >= %i ) {\n", lev ); cnd = CompBoolExpr(READ_STAT(stat, 1)); @@ -4976,7 +4984,11 @@ static void CompAssert3(Stat stat) CVar cnd; // the condition CVar msg; // the message - Emit( "\n/* Assert( ... ); */\n" ); + // print a comment + if ( CompPass == 2 ) { + Emit( "\n/* " ); PrintStat( stat ); Emit( " */\n" ); + } + lev = CompExpr(READ_STAT(stat, 0)); Emit( "if ( STATE(CurrentAssertionLevel) >= %i ) {\n", lev ); cnd = CompBoolExpr(READ_STAT(stat, 1)); diff --git a/tst/test-compile/assert.g.dynamic.c b/tst/test-compile/assert.g.dynamic.c index d51834c2c5..044e833066 100644 --- a/tst/test-compile/assert.g.dynamic.c +++ b/tst/test-compile/assert.g.dynamic.c @@ -47,7 +47,7 @@ static Obj HdlrFunc2 ( DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) ); } - /* Assert( ... ); */ + /* Assert( 1, false, "fail-A" ); */ if ( STATE(CurrentAssertionLevel) >= 1 ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); @@ -62,7 +62,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 1, false ); */ if ( STATE(CurrentAssertionLevel) >= 1 ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); @@ -71,7 +71,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 0, true, "fail-B" ); */ if ( STATE(CurrentAssertionLevel) >= 0 ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); @@ -86,7 +86,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 0, true ); */ if ( STATE(CurrentAssertionLevel) >= 0 ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); @@ -122,7 +122,7 @@ static Obj HdlrFunc2 ( DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) ); } - /* Assert( ... ); */ + /* Assert( 3, false, "fail-C" ); */ if ( STATE(CurrentAssertionLevel) >= 3 ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); @@ -137,7 +137,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 3, false ); */ if ( STATE(CurrentAssertionLevel) >= 3 ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); @@ -146,7 +146,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 2, true, "fail-D" ); */ if ( STATE(CurrentAssertionLevel) >= 2 ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); @@ -161,7 +161,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 2, true ); */ if ( STATE(CurrentAssertionLevel) >= 2 ) { t_2 = True; t_1 = (Obj)(UInt)(t_2 != False); @@ -170,7 +170,7 @@ static Obj HdlrFunc2 ( } } - /* Assert( ... ); */ + /* Assert( 2, false, "pass!\n" ); */ if ( STATE(CurrentAssertionLevel) >= 2 ) { t_2 = False; t_1 = (Obj)(UInt)(t_2 != False); diff --git a/tst/test-compile/info.g.dynamic.c b/tst/test-compile/info.g.dynamic.c index c0a459ffa6..fbf25d42f7 100644 --- a/tst/test-compile/info.g.dynamic.c +++ b/tst/test-compile/info.g.dynamic.c @@ -52,7 +52,7 @@ static Obj HdlrFunc2 ( DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) ); } - /* Info( ... ); */ + /* Info( InfoDebug, 2, "Do not print" ); */ t_1 = GC_InfoDebug; CHECK_BOUND( t_1, "InfoDebug" ); t_3 = InfoCheckLevel( t_1, INTOBJ_INT(2) ); @@ -65,7 +65,7 @@ static Obj HdlrFunc2 ( InfoDoPrint( t_1, INTOBJ_INT(2), t_2 ); } - /* Info( ... ); */ + /* Info( InfoDebug, 1, "print this A" ); */ t_1 = GC_InfoDebug; CHECK_BOUND( t_1, "InfoDebug" ); t_3 = InfoCheckLevel( t_1, INTOBJ_INT(1) ); @@ -109,7 +109,7 @@ static Obj HdlrFunc2 ( DoOperation2Args( CallFuncListOper, t_1, NewPlistFromArgs( t_2, t_3 ) ); } - /* Info( ... ); */ + /* Info( InfoDebug, 3, "Do not print" ); */ t_1 = GC_InfoDebug; CHECK_BOUND( t_1, "InfoDebug" ); t_3 = InfoCheckLevel( t_1, INTOBJ_INT(3) ); @@ -122,7 +122,7 @@ static Obj HdlrFunc2 ( InfoDoPrint( t_1, INTOBJ_INT(3), t_2 ); } - /* Info( ... ); */ + /* Info( InfoDebug, 2, "print this B" ); */ t_1 = GC_InfoDebug; CHECK_BOUND( t_1, "InfoDebug" ); t_3 = InfoCheckLevel( t_1, INTOBJ_INT(2) ); @@ -135,7 +135,7 @@ static Obj HdlrFunc2 ( InfoDoPrint( t_1, INTOBJ_INT(2), t_2 ); } - /* Info( ... ); */ + /* Info( InfoDebug, 1, "print ", "this ", "C" ); */ t_1 = GC_InfoDebug; CHECK_BOUND( t_1, "InfoDebug" ); t_3 = InfoCheckLevel( t_1, INTOBJ_INT(1) );