diff --git a/changelog.txt b/changelog.txt index 04c786554..1552b3ea7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -23,6 +23,7 @@ Version 1.10.1 - rtlib: emscripten: CURDIR and EXEPATH always returned "" - emscripten/fbc: -sASYNCIFY wasn't passed to emcc at link-time as needed by recent Emscripten - sf.net #993: ignore (parse) single line comments for macros invoked with optional parentheses instead of passing as an argument to macro +- sf.net #994: Bad handling of macro argument evaluation - reset file pointers after evaluating arguments in __fb_query_symbol__, __fb_eval__, __fb_arg_extract__, __fb_iif__ Version 1.10.0 diff --git a/src/compiler/lex-utf.bas b/src/compiler/lex-utf.bas index 294678fa1..e4571c20f 100644 --- a/src/compiler/lex-utf.bas +++ b/src/compiler/lex-utf.bas @@ -300,7 +300,8 @@ end function private function hUTF16LEToUTF16LE( ) as integer static if( get( #env.inf.num, , lex.ctx->buffw ) = 0 ) then - function = cunsg(seek( env.inf.num ) - lex.ctx->filepos) \ len( ushort ) + lex.ctx->physfilepos = seek( env.inf.num ) + function = cunsg(lex.ctx->physfilepos - lex.ctx->filepos) \ len( ushort ) else function = 0 end if @@ -600,7 +601,8 @@ end function private function hUTF32LEToUTF32LE( ) as integer static if( get( #env.inf.num, , lex.ctx->buffw ) = 0 ) then - function = cunsg(seek( env.inf.num ) - lex.ctx->filepos) \ sizeof( ulong ) + lex.ctx->physfilepos = seek( env.inf.num ) + function = cunsg(lex.ctx->physfilepos - lex.ctx->filepos) \ sizeof( ulong ) else function = 0 end if diff --git a/src/compiler/lex.bas b/src/compiler/lex.bas index 316221ea6..183502826 100644 --- a/src/compiler/lex.bas +++ b/src/compiler/lex.bas @@ -60,6 +60,13 @@ sub lexPopCtx( ) DWstrAllocate( lex.ctx->deftextw, 0 ) end if + '' restore file pointer position if current context is different from previous + if( (lex.ctx-1)->physfilepos > 0 ) then + if( (lex.ctx-1)->physfilepos <> lex.ctx->physfilepos ) then + seek #env.inf.num, lex.ctx->physfilepos + end if + end if + lex.ctx -= 1 end sub @@ -133,9 +140,11 @@ sub lexInit _ if( is_fb_eval ) then lex.ctx->filepos = (lex.ctx-1)->filepos lex.ctx->lastfilepos = (lex.ctx-1)->lastfilepos + lex.ctx->physfilepos = (lex.ctx-1)->physfilepos else lex.ctx->filepos = 0 lex.ctx->lastfilepos = 0 + lex.ctx->physfilepos = 0 end if '' only if it's not on an inc file @@ -227,7 +236,8 @@ private function hReadChar _ select case as const env.inf.format case FBFILE_FORMAT_ASCII if( get( #env.inf.num, , lex.ctx->buff ) = 0 ) then - lex.ctx->bufflen = seek( env.inf.num ) - lex.ctx->filepos + lex.ctx->physfilepos = seek( env.inf.num ) + lex.ctx->bufflen = lex.ctx->physfilepos - lex.ctx->filepos lex.ctx->buffptr = @lex.ctx->buff end if diff --git a/src/compiler/lex.bi b/src/compiler/lex.bi index 00f8de5ea..b47cf39d0 100644 --- a/src/compiler/lex.bi +++ b/src/compiler/lex.bi @@ -129,6 +129,7 @@ type LEX_TKCTX filepos as integer lastfilepos as integer + physfilepos as integer currline as DZSTRING '' current line in text form diff --git a/src/compiler/symb-define.bas b/src/compiler/symb-define.bas index 01fb448bc..bbecaf199 100644 --- a/src/compiler/symb-define.bas +++ b/src/compiler/symb-define.bas @@ -1041,6 +1041,10 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum lex.ctx->defptr = lex.ctx->deftext.data lex.ctx->deflen += len( *sexpr ) + DZstrConcatAssign( lex.ctx->deftext, LFCHAR ) + lex.ctx->defptr = lex.ctx->deftext.data + lex.ctx->deflen += len( LFCHAR ) + '' if filtervalue is zero then set the default methods to use for '' look-up depending on what we are looking for if( filtervalue = 0 ) then @@ -1073,6 +1077,9 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum FB_TKCLASS_QUIRKWD, FB_TKCLASS_OPERATOR sym = cIdentifierOrUDTMember( ) + if( sym = NULL ) then + retry = TRUE + end if end select '' for some symbols, we maybe want to reset and try a TYPEOF below @@ -1129,6 +1136,10 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum DZstrAssign( lex.ctx->deftext, *sexpr ) lex.ctx->defptr = lex.ctx->deftext.data lex.ctx->deflen += len( *sexpr ) + + DZstrConcatAssign( lex.ctx->deftext, LFCHAR ) + lex.ctx->defptr = lex.ctx->deftext.data + lex.ctx->deflen += len( LFCHAR ) end if end if @@ -1183,6 +1194,12 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum res = str( -1 ) end select + if( *errnum <> FB_ERRMSG_OK ) then + errReport( *errnum ) + '' error recovery: skip until next line (in the buffer) + hSkipUntil( FB_TK_EOL, TRUE ) + end if + lex.ctx->reclevel -= 1 lexPopCtx() diff --git a/tests/syntax/fb_query_symbol-error-1.bas b/tests/syntax/fb_query_symbol-error-1.bas new file mode 100644 index 000000000..8aafd841b --- /dev/null +++ b/tests/syntax/fb_query_symbol-error-1.bas @@ -0,0 +1,106 @@ +const fbc_FB_QUERY_SYMBOL_symbclass = 0 +#macro SomeLongishExpressionToHitTheBadSpot(longish_argument_name) +longish_argument_name +#endmacro +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' Padding to fill the source file to 8Kb--------------------------------------- +'' That should be close enough +print __FB_QUERY_SYMBOL__( _ +SomeLongishExpressionToHitTheBadSpot( fbc_FB_QUERY_SYMBOL_symbclass ), _ +SomeUndefinedSymbol ) +print "This is the last lines of the file - This is the last lines of the file" +print "This is the last lines of the file - This is the last lines of the file" +print "This is the last lines of the file - This is the last lines of the file" +print "This is the last lines of the file - This is the last lines of the file" +print "This is the last lines of the file - This is the last lines of the file" diff --git a/tests/syntax/r/dos/fb_query_symbol-error-1.txt b/tests/syntax/r/dos/fb_query_symbol-error-1.txt new file mode 100644 index 000000000..2c0ecbf20 --- /dev/null +++ b/tests/syntax/r/dos/fb_query_symbol-error-1.txt @@ -0,0 +1 @@ +fb_query_symbol-error-1.bas(101) error 42: Variable not declared, SomeUndefinedSymbol in 'SomeUndefinedSymbol )' diff --git a/tests/syntax/r/linux-x86/fb_query_symbol-error-1.txt b/tests/syntax/r/linux-x86/fb_query_symbol-error-1.txt new file mode 100644 index 000000000..2c0ecbf20 --- /dev/null +++ b/tests/syntax/r/linux-x86/fb_query_symbol-error-1.txt @@ -0,0 +1 @@ +fb_query_symbol-error-1.bas(101) error 42: Variable not declared, SomeUndefinedSymbol in 'SomeUndefinedSymbol )' diff --git a/tests/syntax/r/linux-x86_64/fb_query_symbol-error-1.txt b/tests/syntax/r/linux-x86_64/fb_query_symbol-error-1.txt new file mode 100644 index 000000000..2c0ecbf20 --- /dev/null +++ b/tests/syntax/r/linux-x86_64/fb_query_symbol-error-1.txt @@ -0,0 +1 @@ +fb_query_symbol-error-1.bas(101) error 42: Variable not declared, SomeUndefinedSymbol in 'SomeUndefinedSymbol )' diff --git a/tests/syntax/r/win32/fb_query_symbol-error-1.txt b/tests/syntax/r/win32/fb_query_symbol-error-1.txt new file mode 100644 index 000000000..2c0ecbf20 --- /dev/null +++ b/tests/syntax/r/win32/fb_query_symbol-error-1.txt @@ -0,0 +1 @@ +fb_query_symbol-error-1.bas(101) error 42: Variable not declared, SomeUndefinedSymbol in 'SomeUndefinedSymbol )' diff --git a/tests/syntax/r/win64/fb_query_symbol-error-1.txt b/tests/syntax/r/win64/fb_query_symbol-error-1.txt new file mode 100644 index 000000000..2c0ecbf20 --- /dev/null +++ b/tests/syntax/r/win64/fb_query_symbol-error-1.txt @@ -0,0 +1 @@ +fb_query_symbol-error-1.bas(101) error 42: Variable not declared, SomeUndefinedSymbol in 'SomeUndefinedSymbol )'