Skip to content

Commit ff66fc1

Browse files
committed
udt-wstring: IIF function will accept UDT as Z|WSTRING
1 parent d9a09d7 commit ff66fc1

File tree

5 files changed

+511
-0
lines changed

5 files changed

+511
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Version 1.07.0
2222
- STR/WSTR function will accept UDT as Z|WSTRING to return a Z|WSTRING
2323
- SELECT statement will accept UDT as Z|WSTRING to return a Z|WSTRING
2424
- SWAP statement will accept UDT as Z|WSTRING
25+
- IIF function will accept UDT as Z|WSTRING
2526

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

src/compiler/ast-node-iif.bas

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,35 @@ function astNewIIF _
199199
dtype = FB_DATATYPE_INVALID
200200
subtype = NULL
201201

202+
'' Maybe UDT extends Z|WSTRING? Check for string conversions...
203+
if( truexpr->dtype <> falsexpr->dtype ) then
204+
if( truexpr->dtype = FB_DATATYPE_STRUCT ) then
205+
if( symbGetUdtIsZstring( truexpr->subtype ) ) then
206+
if( falsexpr->dtype = FB_DATATYPE_CHAR ) then
207+
astTryOvlStringCONV( truexpr )
208+
truexpr->dtype = astGetDataType( truexpr )
209+
end if
210+
elseif( symbGetUdtIsWstring( truexpr->subtype ) ) then
211+
if( falsexpr->dtype = FB_DATATYPE_WCHAR ) then
212+
astTryOvlStringCONV( truexpr )
213+
truexpr->dtype = astGetDataType( truexpr )
214+
end if
215+
end if
216+
elseif( falsexpr->dtype = FB_DATATYPE_STRUCT ) then
217+
if( symbGetUdtIsZstring( falsexpr->subtype ) ) then
218+
if( truexpr->dtype = FB_DATATYPE_CHAR ) then
219+
astTryOvlStringCONV( falsexpr )
220+
falsexpr->dtype = astGetDataType( falsexpr )
221+
end if
222+
elseif( symbGetUdtIsWstring( falsexpr->subtype ) ) then
223+
if( truexpr->dtype = FB_DATATYPE_WCHAR ) then
224+
astTryOvlStringCONV( falsexpr )
225+
falsexpr->dtype = astGetDataType( falsexpr )
226+
end if
227+
end if
228+
end if
229+
end if
230+
202231
'' check types & find the iif() result type
203232
if( hCheckTypes( truexpr->dtype, truexpr->subtype, _
204233
falsexpr->dtype, falsexpr->subtype, _

tests/udt-wstring/iif.bas

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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_.iif_ )
8+
9+
#macro check_wstring( expr, true_expr, false_expr )
10+
scope
11+
dim t1 as wstring * 50 = true_expr
12+
dim t2 as wstring * 50 = false_expr
13+
14+
dim u1 as ustring = true_expr
15+
dim u2 as ustring = false_expr
16+
17+
'' WSTRING = iif( expr, LITERAL1, LITERAL2 )
18+
scope
19+
dim a as wstring * 50 = iif( expr, true_expr, false_expr )
20+
if( expr ) then
21+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
22+
else
23+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
24+
endif
25+
end scope
26+
27+
'' WSTRING = iif( expr, WSTRING1, LITERAL2 )
28+
scope
29+
dim a as wstring * 50 = iif( expr, t1, false_expr )
30+
if( expr ) then
31+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
32+
else
33+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
34+
endif
35+
end scope
36+
37+
'' WSTRING = iif( expr, LITERAL1, WSTRING2 )
38+
scope
39+
dim a as wstring * 50 = iif( expr, true_expr, t2 )
40+
if( expr ) then
41+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
42+
else
43+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
44+
endif
45+
end scope
46+
47+
'' WSTRING = iif( expr, WSTRING1, WSTRING2 )
48+
scope
49+
dim a as wstring * 50 = iif( expr, t1, t2 )
50+
if( expr ) then
51+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
52+
else
53+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
54+
endif
55+
end scope
56+
57+
'' WSTRING = iif( expr, USTRING1, LITERAL2 )
58+
scope
59+
dim a as wstring * 50 = iif( expr, u1, false_expr )
60+
if( expr ) then
61+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
62+
else
63+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
64+
endif
65+
end scope
66+
67+
'' WSTRING = iif( expr, LITERAL1, USTRING2 )
68+
scope
69+
dim a as wstring * 50 = iif( expr, true_expr, u2 )
70+
if( expr ) then
71+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
72+
else
73+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
74+
endif
75+
end scope
76+
77+
'' WSTRING = iif( expr, USTRING1, USTRING2 )
78+
scope
79+
dim a as wstring * 50 = iif( expr, u1, u2 )
80+
if( expr ) then
81+
CU_ASSERT_WSTRING_EQUAL( a, t1 )
82+
else
83+
CU_ASSERT_WSTRING_EQUAL( a, t2 )
84+
endif
85+
end scope
86+
end scope
87+
#endmacro
88+
89+
#macro check_ustring( expr, true_expr, false_expr )
90+
scope
91+
dim t1 as wstring * 50 = true_expr
92+
dim t2 as wstring * 50 = false_expr
93+
94+
dim u1 as ustring = true_expr
95+
dim u2 as ustring = false_expr
96+
97+
'' USTRING = iif( expr, LITERAL1, LITERAL2 )
98+
scope
99+
dim a as ustring = iif( expr, true_expr, false_expr )
100+
dim r as wstring * 50 = a
101+
if( expr ) then
102+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
103+
else
104+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
105+
endif
106+
end scope
107+
108+
'' USTRING = iif( expr, WSTRING1, LITERAL2 )
109+
scope
110+
dim a as ustring = iif( expr, t1, false_expr )
111+
dim r as wstring * 50 = a
112+
if( expr ) then
113+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
114+
else
115+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
116+
endif
117+
end scope
118+
119+
'' USTRING = iif( expr, LITERAL1, WSTRING2 )
120+
scope
121+
dim a as ustring = iif( expr, true_expr, t2 )
122+
dim r as wstring * 50 = a
123+
if( expr ) then
124+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
125+
else
126+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
127+
endif
128+
end scope
129+
130+
'' USTRING = iif( expr, WSTRING1, WSTRING2 )
131+
scope
132+
dim a as ustring = iif( expr, t1, t2 )
133+
dim r as wstring * 50 = a
134+
if( expr ) then
135+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
136+
else
137+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
138+
endif
139+
end scope
140+
141+
'' USTRING = iif( expr, USTRING1, LITERAL2 )
142+
scope
143+
dim a as ustring = iif( expr, u1, false_expr )
144+
dim r as wstring * 50 = a
145+
if( expr ) then
146+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
147+
else
148+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
149+
endif
150+
end scope
151+
152+
'' USTRING = iif( expr, LITERAL1, USTRING2 )
153+
scope
154+
dim a as ustring = iif( expr, true_expr, u2 )
155+
dim r as wstring * 50 = a
156+
if( expr ) then
157+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
158+
else
159+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
160+
endif
161+
end scope
162+
163+
'' USTRING = iif( expr, USTRING1, USTRING2 )
164+
scope
165+
dim a as ustring = iif( expr, u1, u2 )
166+
dim r as wstring * 50 = a
167+
if( expr ) then
168+
CU_ASSERT_WSTRING_EQUAL( r, t1 )
169+
else
170+
CU_ASSERT_WSTRING_EQUAL( r, t2 )
171+
endif
172+
end scope
173+
174+
end scope
175+
#endmacro
176+
177+
TEST( wstring_iif )
178+
179+
check_wstring( 0, "", "a" )
180+
check_wstring( -1, "", "a" )
181+
182+
check_wstring( 0, "a", "xyz" )
183+
check_wstring( -1, "a", "xyz" )
184+
185+
check_wstring( 0, !"\u3041\u3043\u3045", "a" )
186+
check_wstring( -1, !"\u3041\u3043\u3045", "a" )
187+
188+
check_wstring( 0, "a", !"\u3041\u3043\u3045" )
189+
check_wstring( -1, "a", !"\u3041\u3043\u3045" )
190+
191+
check_wstring( 0, !"\u3047", !"\u3041\u3043\u3045" )
192+
check_wstring( -1, !"\u3047", !"\u3041\u3043\u3045" )
193+
194+
END_TEST
195+
196+
TEST( ustring_iif )
197+
198+
check_ustring( 0, "", "a" )
199+
check_ustring( -1, "", "a" )
200+
201+
check_ustring( 0, "a", "xyz" )
202+
check_ustring( -1, "a", "xyz" )
203+
204+
check_ustring( 0, !"\u3041\u3043\u3045", "a" )
205+
check_ustring( -1, !"\u3041\u3043\u3045", "a" )
206+
207+
check_ustring( 0, "a", !"\u3041\u3043\u3045" )
208+
check_ustring( -1, "a", !"\u3041\u3043\u3045" )
209+
210+
check_ustring( 0, !"\u3047", !"\u3041\u3043\u3045" )
211+
check_ustring( -1, !"\u3047", !"\u3041\u3043\u3045" )
212+
213+
END_TEST
214+
215+
END_SUITE

0 commit comments

Comments
 (0)