12 sub hConstConv(
byval todtype
as integer,
byval l as ASTNODE
ptr )
13 dim as integer ldtype =
any
15 ldtype = astGetFullType(
l )
17 if( typeGetClass( ldtype ) = FB_DATACLASS_FPOINT )
then
18 select case as const( typeGetSizeType( todtype ) )
19 case FB_SIZETYPE_FLOAT32
22 if( typeGetDtAndPtrOnly( ldtype ) = FB_DATATYPE_DOUBLE )
then
30 case FB_SIZETYPE_FLOAT64
34 l->
val.i =
cbyte(
l->
val.f )
35 case FB_SIZETYPE_UINT8
36 l->
val.i =
cubyte(
l->
val.f )
37 case FB_SIZETYPE_INT16
38 l->
val.i =
cshort(
l->
val.f )
39 case FB_SIZETYPE_UINT16
40 l->
val.i =
cushort(
l->
val.f )
41 case FB_SIZETYPE_INT32
42 l->
val.i =
clng(
l->
val.f )
43 case FB_SIZETYPE_UINT32
44 l->
val.i =
culng(
l->
val.f )
45 case FB_SIZETYPE_INT64
46 l->
val.i =
clngint(
l->
val.f )
47 case FB_SIZETYPE_UINT64
48 l->
val.i = hCastFloatToULongint(
l->
val.f )
50 elseif( typeIsSigned( ldtype ) )
then
51 select case as const( typeGetSizeType( todtype ) )
52 case FB_SIZETYPE_FLOAT32
53 l->
val.f =
csng(
l->
val.i )
54 case FB_SIZETYPE_FLOAT64
55 l->
val.f =
cdbl(
l->
val.i )
57 l->
val.i =
cbyte(
l->
val.i )
58 case FB_SIZETYPE_UINT8
59 l->
val.i =
cubyte(
l->
val.i )
60 case FB_SIZETYPE_INT16
61 l->
val.i =
cshort(
l->
val.i )
62 case FB_SIZETYPE_UINT16
63 l->
val.i =
cushort(
l->
val.i )
64 case FB_SIZETYPE_INT32
65 l->
val.i =
clng(
l->
val.i )
66 case FB_SIZETYPE_UINT32
67 l->
val.i =
culng(
l->
val.i )
68 case FB_SIZETYPE_INT64
69 l->
val.i =
clngint(
l->
val.i )
70 case FB_SIZETYPE_UINT64
71 l->
val.i =
culngint(
l->
val.i )
74 select case as const( typeGetSizeType( todtype ) )
75 case FB_SIZETYPE_FLOAT32
76 l->
val.f =
csng( cunsg(
l->
val.i ) )
77 case FB_SIZETYPE_FLOAT64
78 l->
val.f =
cdbl( cunsg(
l->
val.i ) )
80 l->
val.i =
cbyte( cunsg(
l->
val.i ) )
81 case FB_SIZETYPE_UINT8
82 l->
val.i =
cubyte( cunsg(
l->
val.i ) )
83 case FB_SIZETYPE_INT16
84 l->
val.i =
cshort( cunsg(
l->
val.i ) )
85 case FB_SIZETYPE_UINT16
86 l->
val.i =
cushort( cunsg(
l->
val.i ) )
87 case FB_SIZETYPE_INT32
88 l->
val.i =
clng( cunsg(
l->
val.i ) )
89 case FB_SIZETYPE_UINT32
90 l->
val.i =
culng( cunsg(
l->
val.i ) )
91 case FB_SIZETYPE_INT64
92 l->
val.i =
clngint( cunsg(
l->
val.i ) )
93 case FB_SIZETYPE_UINT64
94 l->
val.i =
culngint( cunsg(
l->
val.i ) )
100 if( options
and AST_CONVOPT_PTRONLY )
then
101 function = FB_ERRMSG_EXPECTEDPOINTER
103 function = FB_ERRMSG_TYPEMISMATCH
109 byval to_dtype
as integer, _
110 byval to_subtype
as FBSYMBOL
ptr, _
111 byval expr_dtype
as integer, _
112 byval expr
as ASTNODE
ptr, _
113 byval options
as AST_CONVOPT _
116 function = FB_ERRMSG_OK
119 if( typeIsPtr( to_dtype ) )
then
120 select case as const typeGet( expr_dtype )
121 case FB_DATATYPE_INTEGER, FB_DATATYPE_UINT, FB_DATATYPE_ENUM, _
122 FB_DATATYPE_LONG, FB_DATATYPE_ULONG, _
123 FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT
125 if( typeGetSize( expr_dtype ) = env.pointersize )
then
131 case FB_DATATYPE_BYTE, FB_DATATYPE_UBYTE, _
132 FB_DATATYPE_SHORT, FB_DATATYPE_USHORT
133 if( astIsCONST( expr ) )
then
142 case FB_DATATYPE_POINTER
151 elseif( typeIsPtr( expr_dtype ) )
then
152 select case as const typeGet( to_dtype )
153 case FB_DATATYPE_INTEGER, FB_DATATYPE_UINT, FB_DATATYPE_ENUM, _
154 FB_DATATYPE_LONG, FB_DATATYPE_ULONG, _
155 FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT
157 if( typeGetSize( to_dtype ) = env.pointersize )
then
162 case FB_DATATYPE_POINTER
183 if( typeGetDtOnly( to_dtype ) = FB_DATATYPE_STRUCT )
then
184 if( to_subtype->udt.
base <> NULL )
then
185 if( typeGetDtOnly( expr_dtype ) <> FB_DATATYPE_STRUCT )
then
186 if( typeGetDtOnly( expr_dtype ) <> FB_DATATYPE_VOID )
then
187 return FB_ERRMSG_CASTDERIVEDPTRFROMINCOMPATIBLE
194 return FB_ERRMSG_CASTDERIVEDPTRFROMUNRELATED
202 if( typeGetDtOnly( expr_dtype ) = FB_DATATYPE_STRUCT )
then
203 if( expr->subtype->udt.
base <> NULL )
then
204 if( typeGetDtOnly( to_dtype ) <> FB_DATATYPE_STRUCT )
then
205 if( typeGetDtOnly( to_dtype ) <> FB_DATATYPE_VOID )
then
206 return FB_ERRMSG_CASTDERIVEDPTRTOINCOMPATIBLE
213 return FB_ERRMSG_CASTDERIVEDPTRTOUNRELATED
225 byval to_dtype
as integer, _
226 byval to_subtype
as FBSYMBOL
ptr, _
227 byval l as ASTNODE
ptr _
230 dim as integer ldtype =
any
234 ldtype = astGetFullType(
l )
237 if( (typeGet( to_dtype ) = FB_DATATYPE_STRUCT)
or _
238 (typeGet( ldtype ) = FB_DATATYPE_STRUCT) )
then
239 if( (typeGet( to_dtype ) = FB_DATATYPE_STRUCT)
and _
240 (typeGet( ldtype ) = FB_DATATYPE_STRUCT) )
then
247 if( typeGetClass( ldtype ) = FB_DATACLASS_STRING )
then
252 if(
hCheckPtr( to_dtype, to_subtype, ldtype,
l, 0 ) <> FB_ERRMSG_OK )
then
256 select case typeGet( ldtype )
258 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
260 if( astIsDEREF(
l ) = FALSE )
then
271 #macro hDoGlobOpOverload( to_dtype, to_subtype, node )
273 dim as FBSYMBOL
ptr proc =
any
274 dim as FB_ERRMSG err_num =
any
276 proc = symbFindCastOvlProc( to_dtype, to_subtype, node, @err_num )
277 if( proc <> NULL )
then
279 return astBuildCall( proc,
l )
281 if( err_num <> FB_ERRMSG_OK )
then
291 byval to_dtype
as integer, _
292 byval to_subtype
as FBSYMBOL
ptr, _
293 byval l as ASTNODE
ptr, _
294 byval options
as AST_CONVOPT, _
295 byval perrmsg
as integer ptr _
298 dim as ASTNODE
ptr n =
any
299 dim as integer ldclass =
any, ldtype =
any, errmsg =
any, doconv =
any
302 *perrmsg = FB_ERRMSG_OK
305 ldtype = astGetFullType(
l )
308 if( typeGetDtAndPtrOnly( ldtype ) = typeGetDtAndPtrOnly( to_dtype ) )
then
309 if(
l->subtype = to_subtype )
then
311 if( ldtype <> to_dtype )
then
313 if( astIsCONST(
l ) )
then
319 n =
astNewNode( AST_NODECLASS_CONV, to_dtype, to_subtype )
321 n->
cast.doconv = FALSE
322 n->
cast.do_convfd2fs = FALSE
333 hDoGlobOpOverload( to_dtype, to_subtype,
l )
335 select case as const typeGet( to_dtype )
336 case FB_DATATYPE_VOID, FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
337 FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
343 case FB_DATATYPE_STRUCT
345 if( typeGet( ldtype ) <> FB_DATATYPE_STRUCT )
then
356 if( typeGet( ldtype ) = FB_DATATYPE_STRUCT )
then
362 ldclass = typeGetClass( ldtype )
365 if( options
and AST_CONVOPT_SIGNCONV )
then
367 if( ldclass <> FB_DATACLASS_INTEGER )
then
372 if( (options
and AST_CONVOPT_DONTCHKPTR) = 0 )
then
374 errmsg =
hCheckPtr( to_dtype, to_subtype, ldtype,
l, options )
375 if( errmsg <> FB_ERRMSG_OK )
then
384 if( options
and AST_CONVOPT_CHECKSTR )
then
385 select case as const typeGet( ldtype )
386 case FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR, _
387 FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
391 if( ldclass = FB_DATACLASS_STRING )
then
395 select case typeGet( ldtype )
396 case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR
398 if( astIsDEREF(
l ) = FALSE )
then
406 if( astIsCONST(
l ) )
then
412 l->subtype = to_subtype
417 if( env.clopt.backend = FB_BACKEND_GCC )
then
419 if( (ldclass = FB_DATACLASS_FPOINT)
and (typeGetClass( to_dtype ) = FB_DATACLASS_INTEGER) )
then
422 select case( typeGetDtAndPtrOnly( to_dtype ) )
423 case FB_DATATYPE_STRUCT
434 if( ldclass = typeGetClass( to_dtype ) )
then
435 select case( typeGet( to_dtype ) )
436 case FB_DATATYPE_STRUCT
440 if( typeGetSize( ldtype ) = typeGetSize( to_dtype ) )
then
446 if( irGetOption( IR_OPT_FPUCONV ) )
then
447 if (ldclass = FB_DATACLASS_FPOINT)
and ( typeGetClass( to_dtype ) = FB_DATACLASS_FPOINT )
then
448 if( typeGetSize( ldtype ) <> typeGetSize( to_dtype ) )
then
455 if(
l->
class = AST_NODECLASS_CONV )
then
457 if(
l->
cast.doconv = FALSE )
then
458 if( doconv = FALSE )
then
460 astGetFullType(
l ) = to_dtype
461 l->subtype = to_subtype
468 n =
astNewNode( AST_NODECLASS_CONV, to_dtype, to_subtype )
471 n->
cast.doconv = doconv
472 n->
cast.do_convfd2fs = FALSE
474 if( env.clopt.backend = FB_BACKEND_GAS )
then
477 if( typeGet( ldtype ) = FB_DATATYPE_DOUBLE )
then
478 n->
cast.do_convfd2fs = (typeGet( to_dtype ) = FB_DATATYPE_SINGLE)
490 byval to_dtype
as integer, _
491 byval to_subtype
as FBSYMBOL
ptr, _
492 byval l as ASTNODE
ptr _
496 hDoGlobOpOverload( to_dtype, to_subtype,
l )
505 byval n
as ASTNODE
ptr, _
506 byval to_dtype
as integer, _
507 byval is_expr
as integer _
510 assert( n->
class = AST_NODECLASS_CONV )
513 if( n->
cast.do_convfd2fs = FALSE )
then
517 assert( env.clopt.backend = FB_BACKEND_GAS )
534 n->
cast.do_convfd2fs = (typeGetSize( to_dtype ) >= 4)
538 if( typeGet( to_dtype ) = FB_DATATYPE_SINGLE )
then
539 n->
cast.do_convfd2fs = is_expr
547 byval n
as ASTNODE
ptr _
550 dim as ASTNODE
ptr l =
any
551 dim as IRVREG
ptr vs =
any, vr =
any
561 if( ast.doemit )
then
562 vs->vector = n->vector
563 if( n->
cast.doconv )
then
564 vr = irAllocVreg( astGetDataType( n ), n->subtype )
565 vr->vector = n->vector
566 irEmitConvert( vr, vs )
568 if( n->
cast.do_convfd2fs )
then
570 if( vs->dtype = FB_DATATYPE_DOUBLE )
then
571 if( vr->dtype = FB_DATATYPE_SINGLE )
then
572 if( vr->regFamily = IR_REG_FPU_STACK )
then
574 irEmitUOP( AST_OP_CONVFD2FS, vr, NULL )
581 irSetVregDataType( vr, astGetDataType( n ), n->subtype )