Skip to content

Commit e1d15cb

Browse files
authored
Merge pull request #326 from jayrm/basic-macros
Wide character support for '__FB_EVAL__' and fix constant folding for ASC() with embedded NUL characters
2 parents 0e37087 + b09b506 commit e1d15cb

22 files changed

+612
-203
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ Version 1.09.0
88
- crt headers: add const qualifiers in crt/stdlib.bi
99
- crt headers: add const qualifiers in crt/stdio.bi, crt/sys/stat.bi, crt/wchar.bi
1010
- crt headers: add const qualifiers in crt/sys/win32/stat.bi, crt/win32/stdio.bi
11+
- github #325, #326: fbc: internal changes for string processing functions
1112

1213
[added]
1314
- fbc: add '-z fbrt' command line option to link against libfbrt*.a instead of libfb*.a
1415
- makefile: add target for fbrt, fb runtime library written in fbc. Bulid libfbrt*.a and merge any missing object modules from libfb*.a
16+
- github #325, #326: fbc: add support for wstrings used with __FB_EVAL__()
1517

1618
[fixed]
1719
- github #315: set parameters when calling SCREENCONTROL (was broken in fbc 1.08.0 due to new LONG/LONGINT SCREENCONTROL API's)
@@ -22,6 +24,7 @@ Version 1.09.0
2224
- github #323: gas64: When the target variable is const variable, code cannot be generated for variable assignment of different length. (Skyfish)
2325
- github #324: fbc: When converting a wide character escape sequence to an internal format, the escaped value is incorrect. (Skyfish)
2426
- fbc: remove warning on function suffix in '-lang qb'
27+
- github #325, #326: fbc: constant folding ASC() on constant strings with embedded NUL characters - previously ASC returned 0 for anything past the first embedded NUL char, for example ASC(!"A\000B",3) incorrectly returned 0 and should return 66
2528

2629

2730
Version 1.08.0

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,6 @@ ifeq ($(TARGET_OS),js)
632632
RTL_LIBS += $(libdir)/fb_shell.html
633633
endif
634634

635-
# allow optionally including config-post
636-
-include config-post.mk
637-
638635
#
639636
# Build rules
640637
#
@@ -654,6 +651,9 @@ ifndef V
654651
QUIET = @
655652
endif
656653

654+
# allow optionally including config-post
655+
-include config-post.mk
656+
657657
################################################################################
658658

659659
.PHONY: all

src/compiler/ast-node-bop.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ private function hStrLiteralCompare _
7878
static as DZSTRING ltext, rtext
7979
dim as integer res = any
8080

81+
'' !!!FIXME!!! - embedded NUL CHARs incorrectly end the string
82+
'' !!!TODO!!! - use textlen returned from hUnescape() to get proper comparison length
83+
8184
DZstrAssign( ltext, hUnescape( symbGetVarLitText( astGetSymbol( l ) ) ) )
8285
DZstrAssign( rtext, hUnescape( symbGetVarLitText( astGetSymbol( r ) ) ) )
8386

@@ -119,6 +122,9 @@ private function hWStrLiteralCompare _
119122
ls = astGetSymbol( l )
120123
rs = astGetSymbol( r )
121124

125+
'' !!!FIXME!!! - embedded NUL CHARs incorrectly end the string
126+
'' !!!TODO!!! - use textlen returned from hUnescape[W]() to get proper comparison length
127+
122128
'' left operand not a wstring?
123129
if( symbGetType( ls ) <> FB_DATATYPE_WCHAR ) then
124130
DZstrAssign( textz, hUnescape( symbGetVarLitText( ls ) ) )

src/compiler/ast-node-call.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function astLoadCALL( byval n as ASTNODE ptr ) as IRVREG ptr
204204

205205
'' cdecl: pushed arguments must be popped by caller
206206
'' pascal/stdcall: callee does it instead
207-
'' thiscall: could be either depending on target !!! TODO !!!
207+
'' thiscall: could be either depending on target !!!TODO!!!
208208
argbytes = symbCalcArgLen( l->dtype, l->subtype, arg->arg.mode )
209209
if( symbGetProcMode( proc ) = FB_FUNCMODE_CDECL ) then
210210
bytestopop += argbytes

src/compiler/ast-node-conv.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ function astNewCONV _
387387
end if
388388

389389
'' UDT? check if it is z|wstring?
390-
'' !!! TODO !!! make this block in to a function
390+
'' !!!TODO!!! make this block in to a function
391391
'' re-use in astNewOvlCONV()
392392
'' rewrite hDoGlobOpOverload() as astTry* function
393393
if( typeGet( ldtype ) = FB_DATATYPE_STRUCT ) then

src/compiler/ast-node-data.bas

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ sub astDataStmtInit( )
2121
end sub
2222

2323
function astDataStmtBegin( ) as ASTNODE ptr
24-
dim as ASTNODE ptr n = any
24+
dim as ASTNODE ptr n = any
2525

2626
'' alloc new node
2727
n = astNewNode( AST_NODECLASS_DATASTMT, FB_DATATYPE_INVALID )
@@ -37,7 +37,7 @@ function astDataStmtStore _
3737
byval expr as ASTNODE ptr _
3838
) as ASTNODE ptr
3939

40-
dim as ASTNODE ptr n = any
40+
dim as ASTNODE ptr n = any
4141

4242
'' alloc new node
4343
n = astNewNode( AST_NODECLASS_DATASTMT, FB_DATATYPE_INVALID )
@@ -69,21 +69,21 @@ function astDataStmtStore _
6969

7070
'' string?
7171
if( litsym <> NULL ) then
72-
'' not a wstring?
73-
if( astGetDataType( expr ) <> FB_DATATYPE_WCHAR ) then
74-
n->data.id = FB_DATASTMT_ID_ZSTR
72+
'' not a wstring?
73+
if( astGetDataType( expr ) <> FB_DATATYPE_WCHAR ) then
74+
n->data.id = FB_DATASTMT_ID_ZSTR
7575
'' wstring..
76-
else
77-
n->data.id = FB_DATASTMT_ID_WSTR
78-
end if
76+
else
77+
n->data.id = FB_DATASTMT_ID_WSTR
78+
end if
7979

8080
'' scalar..
8181
else
8282
'' address of?
8383
if( astIsOFFSET( expr ) ) then
84-
n->data.id = FB_DATASTMT_ID_OFFSET
84+
n->data.id = FB_DATASTMT_ID_OFFSET
8585
else
86-
n->data.id = FB_DATASTMT_ID_CONST
86+
n->data.id = FB_DATASTMT_ID_CONST
8787
end if
8888
end if
8989
end if
@@ -96,13 +96,13 @@ end function
9696

9797
sub astDataStmtEnd( byval tree as ASTNODE ptr )
9898

99-
dim as FBSYMBOL ptr array = any, elm = any
100-
dim as integer i = any, id = any
101-
dim as ASTNODE ptr n = any, expr = any, initree = any
102-
dim as string littext
99+
dim as FBSYMBOL ptr array = any, elm = any
100+
dim as integer i = any, id = any
101+
dim as ASTNODE ptr n = any, expr = any, initree = any
102+
dim as string littext
103103

104-
'' add the last node: the link
105-
astDataStmtStore( tree, NULL )
104+
'' add the last node: the link
105+
astDataStmtStore( tree, NULL )
106106

107107
'' create/lookup the datadesc array symbol for the last symbol
108108

@@ -147,42 +147,42 @@ sub astDataStmtEnd( byval tree as ASTNODE ptr )
147147
astNewCONSTi( id, FB_DATATYPE_SHORT ), _
148148
elm )
149149

150-
elm = symbGetNext( elm )
150+
elm = symbGetNext( elm )
151151

152-
'' .node = expr
152+
'' .node = expr
153153
astTypeIniAddAssign( initree, expr, elm )
154154

155155
astTypeIniScopeEnd( initree, array )
156156

157-
'' next
157+
'' next
158158
dim as ASTNODE ptr nxt = n->r
159159
astDelNode( n )
160160
n = nxt
161161
next
162162

163-
''
163+
''
164164
astTypeIniScopeEnd( initree, array )
165165

166-
astTypeIniEnd( initree, TRUE )
166+
astTypeIniEnd( initree, TRUE )
167167

168-
symbSetTypeIniTree( array, initree )
168+
symbSetTypeIniTree( array, initree )
169169

170170
'' Link the previous DATA stmt to this new one
171171
if( ast.data.lastsym <> NULL ) then
172-
'' lastarray(ubound(lastarray)).next = @array(0)
173-
initree = symbGetTypeIniTree( astGetLastDataStmtSymbol( ) )
174-
175-
n = initree->l
176-
var tn = n
177-
do while( n->r <> NULL )
178-
if( n->class = AST_NODECLASS_TYPEINI_ASSIGN ) then
179-
tn = n
180-
end if
181-
n = n->r
182-
loop
172+
'' lastarray(ubound(lastarray)).next = @array(0)
173+
initree = symbGetTypeIniTree( astGetLastDataStmtSymbol( ) )
174+
175+
n = initree->l
176+
var tn = n
177+
do while( n->r <> NULL )
178+
if( n->class = AST_NODECLASS_TYPEINI_ASSIGN ) then
179+
tn = n
180+
end if
181+
n = n->r
182+
loop
183183

184-
'' del the NULL expr
185-
astDelNode( tn->l )
184+
'' del the NULL expr
185+
astDelNode( tn->l )
186186

187187
'' replace the node
188188
tn->l = astNewADDROF( astNewVAR( array ) )
@@ -234,8 +234,8 @@ function astDataStmtAdd _
234234
'' Called for RESTORE <label>
235235
'' static datadesc array id specifically for that label
236236
'' (if <label> is a forward reference, then this datadesc array
237-
'' may be looked up by astDataStmtEnd() later,
238-
'' when the corresponding DATA is found)
237+
'' may be looked up by astDataStmtEnd() later,
238+
'' when the corresponding DATA is found)
239239
id = FB_DATASTMT_PREFIX + *symbGetName( label )
240240
dTB(0).upper = 0
241241
end if

src/compiler/dstr.bas

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ end sub
9696
sub DZstrAssign _
9797
( _
9898
byref dst as DZSTRING, _
99-
byval src as zstring ptr _
99+
byval src as const zstring ptr _
100100
)
101101

102102
dim as integer src_len = CALC_LEN( src )
@@ -113,7 +113,7 @@ end sub
113113
sub DZstrAssignW _
114114
( _
115115
byref dst as DZSTRING, _
116-
byval src as wstring ptr _
116+
byval src as const wstring ptr _
117117
)
118118

119119
dim as integer src_len = CALC_LEN( src )
@@ -148,7 +148,7 @@ end sub
148148
sub DZstrConcatAssign _
149149
( _
150150
byref dst as DZSTRING, _
151-
byval src as zstring ptr _
151+
byval src as const zstring ptr _
152152
)
153153

154154
dim as integer src_len = CALC_LEN( src )
@@ -166,7 +166,7 @@ end sub
166166
sub DZstrConcatAssignW _
167167
( _
168168
byref dst as DZSTRING, _
169-
byval src as wstring ptr _
169+
byval src as const wstring ptr _
170170
)
171171

172172
dim as integer src_len = CALC_LEN( src )
@@ -244,7 +244,7 @@ end sub
244244
sub DWstrAssign _
245245
( _
246246
byref dst as DWSTRING, _
247-
byval src as wstring ptr _
247+
byval src as const wstring ptr _
248248
)
249249

250250
dim as integer src_len = CALC_LEN( src )
@@ -261,7 +261,7 @@ end sub
261261
sub DWstrAssignA _
262262
( _
263263
byref dst as DWSTRING, _
264-
byval src as zstring ptr _
264+
byval src as const zstring ptr _
265265
)
266266

267267
dim as integer src_len = CALC_LEN( src )
@@ -296,7 +296,7 @@ end sub
296296
sub DWstrConcatAssign _
297297
( _
298298
byref dst as DWSTRING, _
299-
byval src as wstring ptr _
299+
byval src as const wstring ptr _
300300
)
301301

302302
dim as integer src_len = CALC_LEN( src )
@@ -314,7 +314,7 @@ end sub
314314
sub DWstrConcatAssignA _
315315
( _
316316
byref dst as DWSTRING, _
317-
byval src as zstring ptr _
317+
byval src as const zstring ptr _
318318
)
319319

320320
dim as integer src_len = CALC_LEN( src )

src/compiler/dstr.bi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ declare sub DZstrReset _
3131
declare sub DZstrAssign _
3232
( _
3333
byref dst as DZSTRING, _
34-
byval src as zstring ptr _
34+
byval src as const zstring ptr _
3535
)
3636

3737
declare sub DZstrAssignW _
3838
( _
3939
byref dst as DZSTRING, _
40-
byval src as wstring ptr _
40+
byval src as const wstring ptr _
4141
)
4242

4343
declare sub DZstrAssignC _
@@ -49,13 +49,13 @@ declare sub DZstrAssignC _
4949
declare sub DZstrConcatAssign _
5050
( _
5151
byref dst as DZSTRING, _
52-
byval src as zstring ptr _
52+
byval src as const zstring ptr _
5353
)
5454

5555
declare sub DZstrConcatAssignW _
5656
( _
5757
byref dst as DZSTRING, _
58-
byval src as wstring ptr _
58+
byval src as const wstring ptr _
5959
)
6060

6161
declare sub DZstrConcatAssignC _
@@ -83,13 +83,13 @@ declare sub DWstrReset _
8383
declare sub DWstrAssign _
8484
( _
8585
byref dst as DWSTRING, _
86-
byval src as wstring ptr _
86+
byval src as const wstring ptr _
8787
)
8888

8989
declare sub DWstrAssignA _
9090
( _
9191
byref dst as DWSTRING, _
92-
byval src as zstring ptr _
92+
byval src as const zstring ptr _
9393
)
9494

9595
declare sub DWstrAssignC _
@@ -101,13 +101,13 @@ declare sub DWstrAssignC _
101101
declare sub DWstrConcatAssign _
102102
( _
103103
byref dst as DWSTRING, _
104-
byval src as wstring ptr _
104+
byval src as const wstring ptr _
105105
)
106106

107107
declare sub DWstrConcatAssignA _
108108
( _
109109
byref dst as DWSTRING, _
110-
byval src as zstring ptr _
110+
byval src as const zstring ptr _
111111
)
112112

113113
declare sub DWstrConcatAssignC _

src/compiler/fbc.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,7 @@ private sub hPrintOptions( byval verbose as integer )
36893689
print " -strip Omit all symbol information from the output file"
36903690
print " -t <value> Set .exe stack size in kbytes, default: 1024 (win32/dos)"
36913691
if( verbose ) then
3692-
'' !!! TODO !!! provide more examples of available targets
3692+
'' !!!TODO!!! provide more examples of available targets
36933693
print " -target <name> Set cross-compilation target"
36943694
else
36953695
print " -target <name> Set cross-compilation target"

0 commit comments

Comments
 (0)