Skip to content

Commit 80665c2

Browse files
committed
basic-macros: more support for wstring, zstring conversions
- add support for zstring and wstring conversions to better support unicode source files - builtin macros __fb_query_symbol__, __fb_arg_extract__, __fb_iif__ internally will use hMacro_EvalZ() and hMacro_EvalW() to evaluate compile time expressions with appropriate string conversions - add additional tests for sf.net # 994 - but using utf-8 and utf16le encoding
1 parent 08fff05 commit 80665c2

14 files changed

+213
-34
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version 1.10.1
1111
- release: add recipes for building fbc distros using gcc-11.2 and gcc-12.2 Mingw-w64 project toolchains
1212
- release: add recipe for building fbc distros using winlibs-gcc-11.2/3/4 toolchain
1313
- fbc: '-fbgfx' command line option to link against correct libfbgfx variant, for platforms (emscripten) where it's not automatic due to missing objinfo support
14+
- basic-macros: better support for zstring and wstring conversion in evaluation of compile time arguments in __fb_query_symbol__, __fb_arg_extract__, __fb_iif__
1415

1516
[fixed]
1617
- sf.net #982: Array descriptors emitted incorrectly in gcc backend

src/compiler/symb-define.bas

Lines changed: 96 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,36 @@ private function hMacro_EvalZ( byval arg as zstring ptr, byval errnum as integer
345345
'' prevent cExpression from writing to .pp.bas file
346346
lex.ctx->reclevel += 1
347347

348-
DZstrAssign( lex.ctx->deftext, *arg )
349-
lex.ctx->defptr = lex.ctx->deftext.data
350-
lex.ctx->deflen += len( *arg )
348+
'' ascii
349+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
350+
DZstrAssign( lex.ctx->deftext, *arg )
351+
lex.ctx->defptr = lex.ctx->deftext.data
352+
lex.ctx->deflen += len( *arg )
353+
354+
'' Add an end of expression marker so that the parser
355+
'' doesn't read past the end of the expression text
356+
'' by appending an LFCHAR to the end of the expression
357+
'' It would be better to use the explicit EOF character,
358+
'' but we can't appened an extra NUL character to a zstring
359+
360+
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
361+
lex.ctx->defptr = lex.ctx->deftext.data
362+
lex.ctx->deflen += len( LFCHAR )
363+
364+
'' unicode
365+
else
366+
DWstrAssignA( lex.ctx->deftextw, *arg )
367+
lex.ctx->defptrw = lex.ctx->deftextw.data
368+
lex.ctx->deflen += len( *arg )
369+
370+
'' Add an end of expression marker so that the parser
371+
'' (see above)
351372

352-
'' Add an end of expression marker so that the parser
353-
'' doesn't read past the end of the expression text
354-
'' by appending an LFCHAR to the end of the expression
355-
'' It would be better to use the explicit EOF character,
356-
'' but we can't appened an extra NUL character to a zstring
373+
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
374+
lex.ctx->defptrw = lex.ctx->deftextw.data
375+
lex.ctx->deflen += len( LFCHAR )
357376

358-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
359-
lex.ctx->defptr = lex.ctx->deftext.data
360-
lex.ctx->deflen += len( LFCHAR )
377+
end if
361378

362379
dim expr as ASTNODE ptr = cExpression( )
363380
var errmsg = FB_ERRMSG_OK
@@ -432,19 +449,36 @@ private function hMacro_EvalW( byval arg as wstring ptr, byval errnum as integer
432449
'' prevent cExpression from writing to .pp.bas file
433450
lex.ctx->reclevel += 1
434451

435-
DWstrAssign( lex.ctx->deftextw, *arg )
436-
lex.ctx->defptrw = lex.ctx->deftextw.data
437-
lex.ctx->deflen += len( *arg )
452+
'' ascii
453+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
454+
DZstrAssignW( lex.ctx->deftext, *arg )
455+
lex.ctx->defptr = lex.ctx->deftext.data
456+
lex.ctx->deflen += len( *arg )
438457

439-
'' Add an end of expression marker so that the parser
440-
'' doesn't read past the end of the expression text
441-
'' by appending an LFCHAR to the end of the expression
442-
'' It would be better to use the explicit EOF character,
443-
'' but we can't appened an extra NUL character to a zstring
458+
'' Add an end of expression marker so that the parser
459+
'' doesn't read past the end of the expression text
460+
'' by appending an LFCHAR to the end of the expression
461+
'' It would be better to use the explicit EOF character,
462+
'' but we can't appened an extra NUL character to a zstring
463+
464+
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
465+
lex.ctx->defptr = lex.ctx->deftext.data
466+
lex.ctx->deflen += len( LFCHAR )
467+
468+
''unicode
469+
else
470+
DWstrAssign( lex.ctx->deftextw, *arg )
471+
lex.ctx->defptrw = lex.ctx->deftextw.data
472+
lex.ctx->deflen += len( *arg )
444473

445-
DWstrConcatAssign( lex.ctx->deftextw, LFCHAR )
446-
lex.ctx->defptrw = lex.ctx->deftextw.data
447-
lex.ctx->deflen += len( LFCHAR )
474+
'' Add an end of expression marker so that the parser
475+
'' (see above)
476+
477+
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
478+
lex.ctx->defptrw = lex.ctx->deftextw.data
479+
lex.ctx->deflen += len( LFCHAR )
480+
481+
end if
448482

449483
dim expr as ASTNODE ptr = cExpression( )
450484
var errmsg = FB_ERRMSG_OK
@@ -1037,13 +1071,27 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum
10371071
'' prevent cExpression from writing to .pp.bas file
10381072
lex.ctx->reclevel += 1
10391073

1040-
DZstrAssign( lex.ctx->deftext, *sexpr )
1041-
lex.ctx->defptr = lex.ctx->deftext.data
1042-
lex.ctx->deflen += len( *sexpr )
1074+
'' ascii
1075+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
1076+
DZstrAssign( lex.ctx->deftext, *sexpr )
1077+
lex.ctx->defptr = lex.ctx->deftext.data
1078+
lex.ctx->deflen += len( *sexpr )
10431079

1044-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1045-
lex.ctx->defptr = lex.ctx->deftext.data
1046-
lex.ctx->deflen += len( LFCHAR )
1080+
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1081+
lex.ctx->defptr = lex.ctx->deftext.data
1082+
lex.ctx->deflen += len( LFCHAR )
1083+
1084+
'' unicode
1085+
else
1086+
DWstrAssignA( lex.ctx->deftextw, *sexpr )
1087+
lex.ctx->defptrw = lex.ctx->deftextw.data
1088+
lex.ctx->deflen += len( *sexpr )
1089+
1090+
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
1091+
lex.ctx->defptrw = lex.ctx->deftextw.data
1092+
lex.ctx->deflen += len( LFCHAR )
1093+
1094+
end if
10471095

10481096
'' if filtervalue is zero then set the default methods to use for
10491097
'' look-up depending on what we are looking for
@@ -1133,13 +1181,27 @@ private function hDefQuerySymZ_cb( byval argtb as LEXPP_ARGTB ptr, byval errnum
11331181
'' reset the current lexer context and refresh the text to parse.
11341182
lexInit( FALSE, TRUE )
11351183

1136-
DZstrAssign( lex.ctx->deftext, *sexpr )
1137-
lex.ctx->defptr = lex.ctx->deftext.data
1138-
lex.ctx->deflen += len( *sexpr )
1184+
'' ascii
1185+
if( env.inf.format = FBFILE_FORMAT_ASCII ) then
1186+
DZstrAssign( lex.ctx->deftext, *sexpr )
1187+
lex.ctx->defptr = lex.ctx->deftext.data
1188+
lex.ctx->deflen += len( *sexpr )
11391189

1140-
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1141-
lex.ctx->defptr = lex.ctx->deftext.data
1142-
lex.ctx->deflen += len( LFCHAR )
1190+
DZstrConcatAssign( lex.ctx->deftext, LFCHAR )
1191+
lex.ctx->defptr = lex.ctx->deftext.data
1192+
lex.ctx->deflen += len( LFCHAR )
1193+
1194+
'' unicode
1195+
else
1196+
DWstrAssignA( lex.ctx->deftextw, *sexpr )
1197+
lex.ctx->defptrw = lex.ctx->deftextw.data
1198+
lex.ctx->deflen += len( *sexpr )
1199+
1200+
DWstrConcatAssignA( lex.ctx->deftextw, LFCHAR )
1201+
lex.ctx->defptrw = lex.ctx->deftextw.data
1202+
lex.ctx->deflen += len( LFCHAR )
1203+
1204+
end if
11431205
end if
11441206

11451207
end if
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
const fbc_FB_QUERY_SYMBOL_symbclass = 0
2+
#macro SomeLongishExpressionToHitTheBadSpot(longish_argument_name)
3+
longish_argument_name
4+
#endmacro
5+
'' Padding to fill the source file to 8Kb---------------------------------------
6+
'' Padding to fill the source file to 8Kb---------------------------------------
7+
'' Padding to fill the source file to 8Kb---------------------------------------
8+
'' Padding to fill the source file to 8Kb---------------------------------------
9+
'' Padding to fill the source file to 8Kb---------------------------------------
10+
'' Padding to fill the source file to 8Kb---------------------------------------
11+
'' Padding to fill the source file to 8Kb---------------------------------------
12+
'' Padding to fill the source file to 8Kb---------------------------------------
13+
'' Padding to fill the source file to 8Kb---------------------------------------
14+
'' Padding to fill the source file to 8Kb---------------------------------------
15+
'' Padding to fill the source file to 8Kb---------------------------------------
16+
'' Padding to fill the source file to 8Kb---------------------------------------
17+
'' Padding to fill the source file to 8Kb---------------------------------------
18+
'' Padding to fill the source file to 8Kb---------------------------------------
19+
'' Padding to fill the source file to 8Kb---------------------------------------
20+
'' Padding to fill the source file to 8Kb---------------------------------------
21+
'' Padding to fill the source file to 8Kb---------------------------------------
22+
'' Padding to fill the source file to 8Kb---------------------------------------
23+
'' Padding to fill the source file to 8Kb---------------------------------------
24+
'' Padding to fill the source file to 8Kb---------------------------------------
25+
'' Padding to fill the source file to 8Kb---------------------------------------
26+
'' Padding to fill the source file to 8Kb---------------------------------------
27+
'' Padding to fill the source file to 8Kb---------------------------------------
28+
'' Padding to fill the source file to 8Kb---------------------------------------
29+
'' Padding to fill the source file to 8Kb---------------------------------------
30+
'' Padding to fill the source file to 8Kb---------------------------------------
31+
'' Padding to fill the source file to 8Kb---------------------------------------
32+
'' Padding to fill the source file to 8Kb---------------------------------------
33+
'' Padding to fill the source file to 8Kb---------------------------------------
34+
'' Padding to fill the source file to 8Kb---------------------------------------
35+
'' Padding to fill the source file to 8Kb---------------------------------------
36+
'' Padding to fill the source file to 8Kb---------------------------------------
37+
'' Padding to fill the source file to 8Kb---------------------------------------
38+
'' Padding to fill the source file to 8Kb---------------------------------------
39+
'' Padding to fill the source file to 8Kb---------------------------------------
40+
'' Padding to fill the source file to 8Kb---------------------------------------
41+
'' Padding to fill the source file to 8Kb---------------------------------------
42+
'' Padding to fill the source file to 8Kb---------------------------------------
43+
'' Padding to fill the source file to 8Kb---------------------------------------
44+
'' Padding to fill the source file to 8Kb---------------------------------------
45+
'' Padding to fill the source file to 8Kb---------------------------------------
46+
'' Padding to fill the source file to 8Kb---------------------------------------
47+
'' Padding to fill the source file to 8Kb---------------------------------------
48+
'' Padding to fill the source file to 8Kb---------------------------------------
49+
'' Padding to fill the source file to 8Kb---------------------------------------
50+
'' Padding to fill the source file to 8Kb---------------------------------------
51+
'' Padding to fill the source file to 8Kb---------------------------------------
52+
'' Padding to fill the source file to 8Kb---------------------------------------
53+
'' Padding to fill the source file to 8Kb---------------------------------------
54+
'' Padding to fill the source file to 8Kb---------------------------------------
55+
'' Padding to fill the source file to 8Kb---------------------------------------
56+
'' Padding to fill the source file to 8Kb---------------------------------------
57+
'' Padding to fill the source file to 8Kb---------------------------------------
58+
'' Padding to fill the source file to 8Kb---------------------------------------
59+
'' Padding to fill the source file to 8Kb---------------------------------------
60+
'' Padding to fill the source file to 8Kb---------------------------------------
61+
'' Padding to fill the source file to 8Kb---------------------------------------
62+
'' Padding to fill the source file to 8Kb---------------------------------------
63+
'' Padding to fill the source file to 8Kb---------------------------------------
64+
'' Padding to fill the source file to 8Kb---------------------------------------
65+
'' Padding to fill the source file to 8Kb---------------------------------------
66+
'' Padding to fill the source file to 8Kb---------------------------------------
67+
'' Padding to fill the source file to 8Kb---------------------------------------
68+
'' Padding to fill the source file to 8Kb---------------------------------------
69+
'' Padding to fill the source file to 8Kb---------------------------------------
70+
'' Padding to fill the source file to 8Kb---------------------------------------
71+
'' Padding to fill the source file to 8Kb---------------------------------------
72+
'' Padding to fill the source file to 8Kb---------------------------------------
73+
'' Padding to fill the source file to 8Kb---------------------------------------
74+
'' Padding to fill the source file to 8Kb---------------------------------------
75+
'' Padding to fill the source file to 8Kb---------------------------------------
76+
'' Padding to fill the source file to 8Kb---------------------------------------
77+
'' Padding to fill the source file to 8Kb---------------------------------------
78+
'' Padding to fill the source file to 8Kb---------------------------------------
79+
'' Padding to fill the source file to 8Kb---------------------------------------
80+
'' Padding to fill the source file to 8Kb---------------------------------------
81+
'' Padding to fill the source file to 8Kb---------------------------------------
82+
'' Padding to fill the source file to 8Kb---------------------------------------
83+
'' Padding to fill the source file to 8Kb---------------------------------------
84+
'' Padding to fill the source file to 8Kb---------------------------------------
85+
'' Padding to fill the source file to 8Kb---------------------------------------
86+
'' Padding to fill the source file to 8Kb---------------------------------------
87+
'' Padding to fill the source file to 8Kb---------------------------------------
88+
'' Padding to fill the source file to 8Kb---------------------------------------
89+
'' Padding to fill the source file to 8Kb---------------------------------------
90+
'' Padding to fill the source file to 8Kb---------------------------------------
91+
'' Padding to fill the source file to 8Kb---------------------------------------
92+
'' Padding to fill the source file to 8Kb---------------------------------------
93+
'' Padding to fill the source file to 8Kb---------------------------------------
94+
'' Padding to fill the source file to 8Kb---------------------------------------
95+
'' Padding to fill the source file to 8Kb---------------------------------------
96+
'' Padding to fill the source file to 8Kb---------------------------------------
97+
'' Padding to fill the source file to 8Kb---------------------------------------
98+
'' That should be close enough
99+
print __FB_QUERY_SYMBOL__( _
100+
SomeLongishExpressionToHitTheBadSpot( fbc_FB_QUERY_SYMBOL_symbclass ), _
101+
SomeUndefinedSymbol )
102+
print "This is the last lines of the file - This is the last lines of the file"
103+
print "This is the last lines of the file - This is the last lines of the file"
104+
print "This is the last lines of the file - This is the last lines of the file"
105+
print "This is the last lines of the file - This is the last lines of the file"
106+
print "This is the last lines of the file - This is the last lines of the file"
16.3 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-2.bas(101) error 42: Variable not declared, SomeUndefinedSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-3.bas(101) error 42: Variable not declared, SomeUndefinedSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-2.bas(101) error 42: Variable not declared, SomeUndefinedSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-3.bas(101) error 42: Variable not declared, SomeUndefinedSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-2.bas(101) error 42: Variable not declared, SomeUndefinedSymbol
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb_query_symbol-error-3.bas(101) error 42: Variable not declared, SomeUndefinedSymbol

0 commit comments

Comments
 (0)