Skip to content

Commit d5272bd

Browse files
committed
udt-wstring: LSET/RSET statements will accept UDT as z|wstring
1 parent 9220036 commit d5272bd

File tree

6 files changed

+325
-0
lines changed

6 files changed

+325
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Version 1.07.0
1616
- INSTR/INSTRREV will accept UDT as Z|WSTRING
1717
- MID function will accept UDT as Z|WSTRING
1818
- SADD/STRPTR will accept UDT as Z|WSTRING to return Z|WSTRING ptr
19+
- LSET/RSET statements will accept UDT as Z|WSTRING
1920

2021
[fixed]
2122
- sf.net #881: C backend: support for varadic function parameters in gcc using __builtin_va_list type and related macros

src/compiler/parser-quirk-string.bas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ function cLRSetStmt(byval tk as FB_TOKEN) as integer
8080
dstexpr = CREATEFAKEID( )
8181
end if
8282

83+
astTryOvlStringCONV( dstexpr )
84+
8385
dtype1 = astGetDataType( dstexpr )
8486
select case as const dtype1
8587
case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
@@ -126,6 +128,8 @@ function cLRSetStmt(byval tk as FB_TOKEN) as integer
126128
'' Expression
127129
hMatchExpressionEx( srcexpr, dtype1 )
128130

131+
astTryOvlStringCONV( srcexpr )
132+
129133
dtype2 = astGetDataType( srcexpr )
130134
select case as const dtype2
131135
case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
@@ -163,6 +167,9 @@ function cLRSetStmt(byval tk as FB_TOKEN) as integer
163167
function = rtlMemCopyClear( dstexpr, symbGetLen( dst->subtype ), _
164168
srcexpr, symbGetLen( src->subtype ) )
165169
else
170+
'' !!! TODO !!! - if udt extends z|wstring, check if operator len()
171+
'' was overloaded and pass the length parameters to a separate
172+
'' rtlib function
166173
function = rtlStrLRSet( dstexpr, srcexpr, is_rset )
167174
end if
168175

src/compiler/rtl.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ end function
387387
'':::::
388388
'' note: this function must be called *before* astNewARG(e) because the
389389
'' expression 'e' can be changed inside the former (address-of string's etc)
390+
'' !!! TODO !!! - in places where rtlCalcStrLen() is called, if it is a UDT
391+
'' that overloads operator len(), then the value returned by operator len() should
392+
'' be prefered to calculating length in the run-time based on the null terminated
393+
'' length. Many fb_Wstr* functions will need alternate versions that accept a length
394+
'' parameter.
390395
function rtlCalcStrLen _
391396
( _
392397
byval expr as ASTNODE ptr, _

tests/udt-wstring/lrset.bas

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED_MUTABLE
6+
7+
SUITE( fbc_tests.udt_wstring_.lrset )
8+
9+
#macro check_lset( dst, src, length1, length2 )
10+
scope
11+
'' lset/rset
12+
dim w1 as wstring * 50 = left( dst, (length1) )
13+
dim w2 as wstring * 50 = left( src, (length2) )
14+
dim e1 as wstring * 50
15+
16+
dim u1 as ustring = w1
17+
dim u2 as ustring = w2
18+
19+
if( (length1) > (length2) ) then
20+
e1 = (w2) & wspace( (length1) - (length2) )
21+
else
22+
e1 = left( w2, (length1) )
23+
end if
24+
25+
CU_ASSERT( len(e1) = (length1) )
26+
27+
'' wstring are zero terminated and length
28+
'' is determined from the string data
29+
lset (w1) = (w2)
30+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
31+
32+
lset (w1) = (u2)
33+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
34+
35+
lset (u1) = (w2)
36+
dim r1 as wstring * 50 = u1
37+
CU_ASSERT_WSTRING_EQUAL( r1, e1 )
38+
39+
lset (u1) = (u2)
40+
dim r2 as wstring * 50 = u1
41+
CU_ASSERT_WSTRING_EQUAL( r2, e1 )
42+
end scope
43+
#endmacro
44+
45+
#macro check_rset( dst, src, length1, length2 )
46+
scope
47+
'' lset/rset
48+
dim w1 as wstring * 50 = left( dst, (length1) )
49+
dim w2 as wstring * 50 = left( src, (length2) )
50+
dim e1 as wstring * 50
51+
52+
dim u1 as ustring = w1
53+
dim u2 as ustring = w2
54+
55+
if( (length1) > (length2) ) then
56+
e1 = wspace( (length1) - (length2) ) & (w2)
57+
else
58+
e1 = left( w2, (length1) )
59+
end if
60+
61+
CU_ASSERT( len(e1) = (length1) )
62+
63+
'' wstring are zero terminated and length
64+
'' is determined from the string data
65+
rset (w1) = (w2)
66+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
67+
68+
rset (w1) = (u2)
69+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
70+
71+
rset (u1) = (w2)
72+
dim r1 as wstring * 50 = u1
73+
CU_ASSERT_WSTRING_EQUAL( r1, e1 )
74+
75+
rset (u1) = (u2)
76+
dim r2 as wstring * 50 = u1
77+
CU_ASSERT_WSTRING_EQUAL( r2, e1 )
78+
end scope
79+
#endmacro
80+
81+
TEST( ascii )
82+
83+
const MAX = 8
84+
dim dst as wstring * (MAX+1)
85+
dim src as wstring * (MAX+1)
86+
87+
dst = "12345678"
88+
src = "ABCDEFGH"
89+
90+
for i1 as integer = 0 to MAX
91+
for i2 as integer = 0 to MAX
92+
93+
check_lset( dst, src, i1, i2 )
94+
check_rset( dst, src, i1, i2 )
95+
96+
next i2
97+
next i1
98+
99+
END_TEST
100+
101+
TEST( ucs2 )
102+
103+
const MAX = 5
104+
dim dst as wstring * (MAX+1)
105+
dim src as wstring * (MAX+1)
106+
107+
dst = !"\u3041\u3043\u3045\u3047\u3049"
108+
src = !"\u3042\u3044\u3046\u3048\u3050"
109+
110+
for i1 as integer = 0 to MAX
111+
for i2 as integer = 0 to MAX
112+
113+
check_lset( dst, src, i1, i2 )
114+
check_rset( dst, src, i1, i2 )
115+
116+
next i2
117+
next i1
118+
119+
END_TEST
120+
121+
END_SUITE

tests/udt-zstring/lrset.bas

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "fbcunit.bi"
2+
#include once "uzstring-fixed.bi"
3+
#include once "chk-zstring.bi"
4+
5+
#define ustring UZSTRING_FIXED_MUTABLE
6+
7+
SUITE( fbc_tests.udt_zstring_.lrset )
8+
9+
#macro check_lset( dst, src, length1, length2 )
10+
scope
11+
'' lset/rset
12+
dim z1 as zstring * 50 = left( dst, (length1) )
13+
dim z2 as zstring * 50 = left( src, (length2) )
14+
dim e1 as zstring * 50
15+
16+
dim u1 as ustring = z1
17+
dim u2 as ustring = z2
18+
19+
if( (length1) > (length2) ) then
20+
e1 = (z2) & space( (length1) - (length2) )
21+
else
22+
e1 = left( z2, (length1) )
23+
end if
24+
25+
CU_ASSERT( len(e1) = (length1) )
26+
27+
'' zstring are zero terminated and length
28+
'' is determined from the string data
29+
lset (z1) = (z2)
30+
CU_ASSERT_ZSTRING_EQUAL( z1, e1 )
31+
32+
lset (z1) = (u2)
33+
CU_ASSERT_ZSTRING_EQUAL( z1, e1 )
34+
35+
lset (u1) = (z2)
36+
dim r1 as zstring * 50 = u1
37+
CU_ASSERT_ZSTRING_EQUAL( r1, e1 )
38+
39+
lset (u1) = (u2)
40+
dim r2 as zstring * 50 = u1
41+
CU_ASSERT_ZSTRING_EQUAL( r2, e1 )
42+
end scope
43+
#endmacro
44+
45+
#macro check_rset( dst, src, length1, length2 )
46+
scope
47+
'' lset/rset
48+
dim z1 as zstring * 50 = left( dst, (length1) )
49+
dim z2 as zstring * 50 = left( src, (length2) )
50+
dim e1 as zstring * 50
51+
52+
dim u1 as ustring = z1
53+
dim u2 as ustring = z2
54+
55+
if( (length1) > (length2) ) then
56+
e1 = wspace( (length1) - (length2) ) & (z2)
57+
else
58+
e1 = left( z2, (length1) )
59+
end if
60+
61+
CU_ASSERT( len(e1) = (length1) )
62+
63+
'' zstring are zero terminated and length
64+
'' is determined from the string data
65+
rset (z1) = (z2)
66+
CU_ASSERT_ZSTRING_EQUAL( z1, e1 )
67+
68+
rset (z1) = (u2)
69+
CU_ASSERT_ZSTRING_EQUAL( z1, e1 )
70+
71+
rset (u1) = (z2)
72+
dim r1 as zstring * 50 = u1
73+
CU_ASSERT_ZSTRING_EQUAL( r1, e1 )
74+
75+
rset (u1) = (u2)
76+
dim r2 as zstring * 50 = u1
77+
CU_ASSERT_ZSTRING_EQUAL( r2, e1 )
78+
end scope
79+
#endmacro
80+
81+
TEST( ascii )
82+
83+
const MAX = 8
84+
dim dst as zstring * (MAX+1)
85+
dim src as zstring * (MAX+1)
86+
87+
dst = "12345678"
88+
src = "ABCDEFGH"
89+
90+
for i1 as integer = 0 to MAX
91+
for i2 as integer = 0 to MAX
92+
93+
check_lset( dst, src, i1, i2 )
94+
check_rset( dst, src, i1, i2 )
95+
96+
next i2
97+
next i1
98+
99+
END_TEST
100+
101+
END_SUITE

tests/wstring/lrset.bas

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "fbcunit.bi"
2+
#include once "chk-wstring.bi"
3+
4+
SUITE( fbc_tests.wstring_.lrset )
5+
6+
#macro check_lset( dst, src, length1, length2 )
7+
scope
8+
'' lset/rset
9+
dim w1 as wstring * 50 = left( dst, (length1) )
10+
dim w2 as wstring * 50 = left( src, (length2) )
11+
dim e1 as wstring * 50
12+
13+
if( (length1) > (length2) ) then
14+
e1 = (w2) & wspace( (length1) - (length2) )
15+
else
16+
e1 = left( w2, (length1) )
17+
end if
18+
19+
CU_ASSERT( len(e1) = (length1) )
20+
21+
'' wstring are zero terminated and length
22+
'' is determined from the string data
23+
lset (w1) = (w2)
24+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
25+
end scope
26+
#endmacro
27+
28+
#macro check_rset( dst, src, length1, length2 )
29+
scope
30+
'' lset/rset
31+
dim w1 as wstring * 50 = left( dst, (length1) )
32+
dim w2 as wstring * 50 = left( src, (length2) )
33+
dim e1 as wstring * 50
34+
35+
if( (length1) > (length2) ) then
36+
e1 = wspace( (length1) - (length2) ) & (w2)
37+
else
38+
e1 = left( w2, (length1) )
39+
end if
40+
41+
CU_ASSERT( len(e1) = (length1) )
42+
43+
'' wstring are zero terminated and length
44+
'' is determined from the string data
45+
rset (w1) = (w2)
46+
CU_ASSERT_WSTRING_EQUAL( w1, e1 )
47+
end scope
48+
#endmacro
49+
50+
TEST( ascii )
51+
52+
const MAX = 8
53+
dim dst as wstring * (MAX+1)
54+
dim src as wstring * (MAX+1)
55+
56+
dst = "12345678"
57+
src = "ABCDEFGH"
58+
59+
for i1 as integer = 0 to MAX
60+
for i2 as integer = 0 to MAX
61+
62+
check_lset( dst, src, i1, i2 )
63+
check_rset( dst, src, i1, i2 )
64+
65+
next i2
66+
next i1
67+
68+
END_TEST
69+
70+
TEST( ucs2 )
71+
72+
const MAX = 5
73+
dim dst as wstring * (MAX+1)
74+
dim src as wstring * (MAX+1)
75+
76+
dst = !"\u3041\u3043\u3045\u3047\u3049"
77+
src = !"\u3042\u3044\u3046\u3048\u3050"
78+
79+
for i1 as integer = 0 to MAX
80+
for i2 as integer = 0 to MAX
81+
82+
check_lset( dst, src, i1, i2 )
83+
check_rset( dst, src, i1, i2 )
84+
85+
next i2
86+
next i1
87+
88+
END_TEST
89+
90+
END_SUITE

0 commit comments

Comments
 (0)