Skip to content

Commit 57360ed

Browse files
committed
udt-wstring: SADD/STRPTR will accept UDT as Z|WSTRING
- SADD/STRPTR will accept UDT as Z|WSTRING to return Z|WSTRING ptr - SADD/STRPTR(wstring) returns WSTRING PTR
1 parent 47b461e commit 57360ed

File tree

6 files changed

+199
-5
lines changed

6 files changed

+199
-5
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Version 1.07.0
22

33
[changed]
4+
- SADD/STRPTR(wstring) returns WSTRING PTR
45

56
[added]
67
- CVA_LIST type, CVA_START(), CVA_COPY() CVA_END(), CVA_ARG() macros will map to gcc's __builtin_va_list and __builtin_va_* macros in gcc backend
@@ -14,6 +15,7 @@ Version 1.07.0
1415
- Cxxx() conversion functions will accept UDT as Z|WSTRING
1516
- INSTR/INSTRREV will accept UDT as Z|WSTRING
1617
- MID function will accept UDT as Z|WSTRING
18+
- SADD/STRPTR will accept UDT as Z|WSTRING to return Z|WSTRING ptr
1719

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

src/compiler/parser-expr-unary.bas

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,15 @@ function cAddrOfExpression( ) as ASTNODE ptr
655655

656656
dim as integer dtype = astGetDataType( expr )
657657

658+
'' UDT? it might be a kind of z|wstring
659+
if( typeGet( dtype ) = FB_DATATYPE_STRUCT ) then
660+
var sym = astGetSubType( expr )
661+
if( symbGetUdtIsZstring( sym ) or symbGetUdtIsWstring( sym ) ) then
662+
astTryOvlStringCONV( expr )
663+
dtype = astGetDataType( expr )
664+
end if
665+
end if
666+
658667
if( symbIsString( dtype ) = FALSE ) then
659668
errReport( FB_ERRMSG_INVALIDDATATYPES )
660669
'' error recovery: skip until ')' and fake a node
@@ -678,15 +687,21 @@ function cAddrOfExpression( ) as ASTNODE ptr
678687
end select
679688

680689
'' varlen? do: *cast( [const] zstring const ptr ptr, @expr )
681-
if( dtype = FB_DATATYPE_STRING ) then
690+
select case dtype
691+
case FB_DATATYPE_STRING
682692
expr = astBuildStrPtr( expr )
683693

694+
case FB_DATATYPE_WCHAR
695+
expr = astNewCONV( typeAddrOf( FB_DATATYPE_WCHAR ), _
696+
NULL, _
697+
astNewADDROF( expr ) )
698+
684699
'' anything else: do cast( zstring ptr, @expr )
685-
else
700+
case else
686701
expr = astNewCONV( typeAddrOf( FB_DATATYPE_CHAR ), _
687702
NULL, _
688703
astNewADDROF( expr ) )
689-
end if
704+
end select
690705

691706
'' ')'
692707
if( hMatch( CHAR_RPRNT ) = FALSE ) then

tests/string/strptr.bas

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SUITE( fbc_tests.string_.strptr_ )
44

5-
TEST( all )
5+
TEST( deref )
66
dim as string ptr foo
77
dim as string bar = "1234"
88
dim as zstring ptr p
@@ -11,5 +11,36 @@ SUITE( fbc_tests.string_.strptr_ )
1111
p = strptr( *foo )
1212
CU_ASSERT_EQUAL( *p, "1234" )
1313
END_TEST
14-
14+
15+
TEST( ptr_size )
16+
17+
dim s1 as zstring * 50 = "1234"
18+
dim as zstring ptr p0 = @s1
19+
20+
scope
21+
dim as zstring ptr p1 = strptr(s1)
22+
dim as zstring ptr p2 = (strptr(s1) + 1)
23+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
24+
end scope
25+
26+
scope
27+
dim as zstring ptr p1 = strptr(s1)
28+
dim as zstring ptr p2 = @(strptr(s1)[1])
29+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
30+
end scope
31+
32+
scope
33+
dim as zstring ptr p1 = sadd(s1)
34+
dim as zstring ptr p2 = (sadd(s1) + 1)
35+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
36+
end scope
37+
38+
scope
39+
dim as zstring ptr p1 = sadd(s1)
40+
dim as zstring ptr p2 = @(sadd(s1)[1])
41+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
42+
end scope
43+
44+
END_TEST
45+
1546
END_SUITE

tests/udt-wstring/strptr.bas

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "fbcunit.bi"
2+
#include once "uwstring-fixed.bi"
3+
#include once "chk-wstring.bi"
4+
5+
#define ustring UWSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_wstring_.strptr_ )
8+
9+
TEST( deref )
10+
dim s1 as wstring * 50 = "1234"
11+
dim u1 as ustring = s1
12+
13+
dim as wstring ptr p1 = strptr( u1 )
14+
15+
CU_ASSERT_WSTRING_EQUAL( (*p1), s1 )
16+
END_TEST
17+
18+
TEST( ptr_size )
19+
20+
dim s as wstring * 50 = "1234"
21+
dim s1 as ustring = s
22+
23+
scope
24+
dim as wstring ptr p1 = strptr(s1)
25+
dim as wstring ptr p2 = (strptr(s1) + 1)
26+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
27+
end scope
28+
29+
scope
30+
dim as wstring ptr p1 = strptr(s1)
31+
dim as wstring ptr p2 = @(strptr(s1)[1])
32+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
33+
end scope
34+
35+
scope
36+
dim as wstring ptr p1 = sadd(s1)
37+
dim as wstring ptr p2 = (sadd(s1) + 1)
38+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
39+
end scope
40+
41+
scope
42+
dim as wstring ptr p1 = sadd(s1)
43+
dim as wstring ptr p2 = @(sadd(s1)[1])
44+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
45+
end scope
46+
47+
END_TEST
48+
49+
END_SUITE

tests/udt-zstring/strptr.bas

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "fbcunit.bi"
2+
#include once "uzstring-fixed.bi"
3+
#include once "chk-zstring.bi"
4+
5+
#define ustring UZSTRING_FIXED
6+
7+
SUITE( fbc_tests.udt_zstring_.strptr_ )
8+
9+
TEST( deref )
10+
dim s1 as zstring * 50 = "1234"
11+
dim u1 as ustring = s1
12+
13+
dim as zstring ptr p1 = strptr( u1 )
14+
15+
CU_ASSERT_zstring_EQUAL( (*p1), s1 )
16+
END_TEST
17+
18+
TEST( ptr_size )
19+
20+
dim s as zstring * 50 = "1234"
21+
dim s1 as ustring = s
22+
23+
scope
24+
dim as zstring ptr p1 = strptr(s1)
25+
dim as zstring ptr p2 = (strptr(s1) + 1)
26+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
27+
end scope
28+
29+
scope
30+
dim as zstring ptr p1 = strptr(s1)
31+
dim as zstring ptr p2 = @(strptr(s1)[1])
32+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
33+
end scope
34+
35+
scope
36+
dim as zstring ptr p1 = sadd(s1)
37+
dim as zstring ptr p2 = (sadd(s1) + 1)
38+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
39+
end scope
40+
41+
scope
42+
dim as zstring ptr p1 = sadd(s1)
43+
dim as zstring ptr p2 = @(sadd(s1)[1])
44+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( zstring ) )
45+
end scope
46+
47+
END_TEST
48+
49+
END_SUITE

tests/wstring/strptr.bas

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "fbcunit.bi"
2+
#include once "chk-wstring.bi"
3+
4+
SUITE( fbc_tests.wstring_.strptr_ )
5+
6+
TEST( deref )
7+
dim s1 as wstring * 50 = "1234"
8+
dim s2 as wstring * 50 = s1
9+
10+
dim as wstring ptr p1 = @s1
11+
CU_ASSERT( p1 <> strptr( s2 ) )
12+
13+
CU_ASSERT_WSTRING_EQUAL( s1, s2 )
14+
CU_ASSERT_WSTRING_EQUAL( (*p1), s2 )
15+
16+
END_TEST
17+
18+
TEST( ptr_size )
19+
20+
dim s1 as wstring * 50 = "1234"
21+
22+
scope
23+
dim as wstring ptr p1 = strptr(s1)
24+
dim as wstring ptr p2 = (strptr(s1) + 1)
25+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
26+
end scope
27+
28+
scope
29+
dim as wstring ptr p1 = strptr(s1)
30+
dim as wstring ptr p2 = @(strptr(s1)[1])
31+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
32+
end scope
33+
34+
scope
35+
dim as wstring ptr p1 = sadd(s1)
36+
dim as wstring ptr p2 = (sadd(s1) + 1)
37+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
38+
end scope
39+
40+
scope
41+
dim as wstring ptr p1 = sadd(s1)
42+
dim as wstring ptr p2 = @(sadd(s1)[1])
43+
CU_ASSERT_EQUAL( cint(p2) - cint(p1), sizeof( wstring ) )
44+
end scope
45+
46+
END_TEST
47+
48+
END_SUITE

0 commit comments

Comments
 (0)