/
parser-expr-unary.bas
814 lines (662 loc) · 20.1 KB
/
parser-expr-unary.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
'' unary operators (NOT, @, *, ...) parsing
''
'' chng: sep/2004 written [v1ctor]
#include once "fb.bi"
#include once "fbint.bi"
#include once "parser.bi"
#include once "ast.bi"
#include once "pp.bi"
declare function hCast( byval options as AST_CONVOPT ) as ASTNODE ptr
private function hPPDefinedExpr( ) as ASTNODE ptr
dim as integer is_defined = any
'' DEFINED
lexSkipToken( LEXCHECK_NODEFINE or LEXCHECK_POST_SUFFIX )
'' '('
if( lexGetToken( ) <> CHAR_LPRNT ) then
errReport( FB_ERRMSG_EXPECTEDLPRNT )
else
lexSkipToken( LEXCHECK_NODEFINE )
end if
'' Identifier
is_defined = (cIdentifierOrUDTMember( ) <> NULL)
'' ')'
if( hMatch( CHAR_RPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
'' error recovery: skip until ')'
hSkipUntil( CHAR_RPRNT, TRUE )
end if
function = astNewCONSTi( is_defined )
end function
'':::::
''NegNotExpression= ('-'|'+'|) ExpExpression
'' | NOT RelExpression
'' | HighestPresExpr .
''
function cNegNotExpression _
( _
_
) as ASTNODE ptr
dim as ASTNODE ptr negexpr = any
select case lexGetToken( )
'' '-'
case CHAR_MINUS
lexSkipToken( )
'' ExpExpression
negexpr = cExpExpression( )
if( negexpr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
else
negexpr = astNewUOP( AST_OP_NEG, negexpr )
end if
if( negexpr = NULL ) Then
errReport( FB_ERRMSG_TYPEMISMATCH )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
end if
return negexpr
'' '+'
case CHAR_PLUS
lexSkipToken( )
'' ExpExpression
negexpr = cExpExpression( )
if( negexpr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
else
negexpr = astNewUOP( AST_OP_PLUS, negexpr )
end if
if( negexpr = NULL ) Then
errReport( FB_ERRMSG_TYPEMISMATCH )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
end if
return negexpr
'' NOT
case FB_TK_NOT
lexSkipToken( LEXCHECK_POST_SUFFIX )
'' RelExpression
negexpr = cRelExpression( )
if( negexpr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
else
negexpr = astNewUOP( AST_OP_NOT, negexpr )
end if
if( negexpr = NULL ) Then
errReport( FB_ERRMSG_TYPEMISMATCH )
'' error recovery: fake a new node
negexpr = astNewCONSTi( 0 )
end if
return negexpr
end select
function = cHighestPrecExpr( NULL, NULL )
end function
''::::
function cStrIdxOrMemberDeref _
( _
byval expr as ASTNODE ptr _
) as ASTNODE ptr
dim as FBSYMBOL ptr subtype = any
dim as integer dtype = any
if( expr = NULL ) then exit function
dtype = astGetFullType( expr )
subtype = astGetSubType( expr )
select case as const typeGet( dtype )
'' zstring indexing?
case FB_DATATYPE_CHAR, FB_DATATYPE_WCHAR, FB_DATATYPE_STRING, FB_DATATYPE_FIXSTR
'' '['?
if( lexGetToken( ) = CHAR_LBRACKET ) then
expr = cMemberDeref( dtype, subtype, expr, TRUE )
end if
return expr
'' udt '.' ?
case FB_DATATYPE_STRUCT ', FB_DATATYPE_CLASS
select case( lexGetToken( ) )
case CHAR_DOT
lexSkipToken( LEXCHECK_NOPERIOD )
expr = cMemberAccess( dtype, subtype, expr )
if( expr = NULL ) then
return NULL
end if
dtype = astGetFullType( expr )
subtype = astGetSubType( expr )
'' ('->' | '[')? (possible on non-pointer UDT types due to operator overloading)
case FB_TK_FIELDDEREF, CHAR_LBRACKET
expr = cMemberDeref( dtype, subtype, expr, TRUE )
end select
end select
'' FuncPtrOrMemberDeref?
if( typeIsPtr( dtype ) ) then
dim as integer isfuncptr = FALSE, isfield = FALSE
select case lexGetToken( )
'' function ptr '(' ?
case CHAR_LPRNT
isfuncptr = (typeGetDtAndPtrOnly( dtype ) = typeAddrOf( FB_DATATYPE_FUNCTION ))
isfield = isfuncptr
'' ptr ('->' | '[') ?
case FB_TK_FIELDDEREF, CHAR_LBRACKET
isfield = TRUE
'' '.'?
case CHAR_DOT
errReport( FB_ERRMSG_EXPECTEDUDT, TRUE )
end select
if( isfield ) then
expr = cFuncPtrOrMemberDeref( dtype, _
subtype, _
expr, _
isfuncptr, _
TRUE )
end if
end if
function = expr
end function
''::::
'' HighestPrecExpr= AddrOfExpression
'' | ( DerefExpr
'' | CastingExpr
'' | PtrTypeCastingExpr
'' | ParentExpression
'' ) FuncPtrOrMemberDeref?
'' | AnonType
'' | Atom .
''
function cHighestPrecExpr _
( _
byval base_parent as FBSYMBOL ptr, _
byval chain_ as FBSYMCHAIN ptr _
) as ASTNODE ptr
dim as ASTNODE ptr expr = any
select case lexGetToken( )
'' AddrOfExpression
case FB_TK_ADDROFCHAR
'' '@' starts an expression and any `()` seen next is handled
'' as not optional and the closing ')' should not end the expression
fbSetPrntOptional( FALSE )
return cAddrOfExpression( )
'' DerefExpr
case FB_TK_DEREFCHAR
'' '*' starts an expression and any `()` seen next is handled
'' as not optional and the closing ')' should not end the expression
fbSetPrntOptional( FALSE )
return cDerefExpression( )
'' ParentExpression
case CHAR_LPRNT
dim as integer is_opt = fbGetPrntOptional( )
expr = cParentExpression( )
'' if parsing a SUB, don't call StrIdxOrMemberDeref() twice
if( is_opt ) then
return expr
end if
case else
select case as const lexGetToken( )
'' AddrOfExpression
case FB_TK_VARPTR, FB_TK_PROCPTR, FB_TK_SADD, FB_TK_STRPTR
return cAddrOfExpression( )
'' CAST '(' DataType ',' Expression ')'
case FB_TK_CAST
'' CAST
lexSkipToken( LEXCHECK_POST_SUFFIX )
expr = hCast( 0 )
'' CPTR '(' DataType ',' Expression{int|uint|ptr} ')'
case FB_TK_CPTR
'' CPTR
lexSkipToken( LEXCHECK_POST_SUFFIX )
expr = hCast( AST_CONVOPT_PTRONLY )
'' OperatorNew
case FB_TK_NEW
expr = cOperatorNew( )
'' Atom
case else
'' PP expression?
if( fbGetIsPP( ) ) then
select case( lexGetToken( ) )
'' TYPEOF '(' Expression ')'
case FB_TK_TYPEOF
return astNewCONSTstr( ppTypeOf( ) )
'' DEFINED '(' Identifier ')'
case FB_TK_DEFINED
return hPPDefinedExpr( )
end select
end if
'' We are at the highest precedence level for expressions so we
'' must be in an expression, any `()` seen next is handled
'' as not optional and the closing ')' should not end the expression
'' Optional parentheses will be enabled again on the next call in
'' to cProcCall().
fbSetPrntOptional( FALSE )
return cAtom( base_parent, chain_ )
end select
end select
function = cStrIdxOrMemberDeref( expr )
end function
'' '(' DataType ',' Expression ')'
private function hCast( byval options as AST_CONVOPT ) as ASTNODE ptr
dim as integer dtype = any, errmsg = any
dim as FBSYMBOL ptr subtype = any
dim as ASTNODE ptr expr = any
'' '('
if( lexGetToken( ) <> CHAR_LPRNT ) then
errReport( FB_ERRMSG_EXPECTEDLPRNT )
'' error recovery: skip until ')', fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
lexSkipToken( )
'' DataType
if( cSymbolType( dtype, subtype ) = FALSE ) then
errReport( FB_ERRMSG_SYNTAXERROR )
'' error recovery: skip until ',', create a fake type
hSkipUntil( CHAR_COMMA )
if( options and AST_CONVOPT_PTRONLY ) then
dtype = typeAddrOf( FB_DATATYPE_VOID )
else
dtype = FB_DATATYPE_INTEGER
end if
subtype = NULL
end if
'' check for invalid types
select case as const( typeGet( dtype ) )
case FB_DATATYPE_VOID, FB_DATATYPE_FIXSTR
errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
'' error recovery: create a fake type
if( options and AST_CONVOPT_PTRONLY ) then
dtype = typeAddrOf( FB_DATATYPE_VOID )
else
dtype = FB_DATATYPE_INTEGER
end if
subtype = NULL
case FB_DATATYPE_INTEGER, FB_DATATYPE_UINT, _
FB_DATATYPE_LONG, FB_DATATYPE_ULONG, _
FB_DATATYPE_LONGINT, FB_DATATYPE_ULONGINT, _
FB_DATATYPE_ENUM
if( options and AST_CONVOPT_PTRONLY ) then
if( fbPdCheckIsSet( FB_PDCHECK_CASTTONONPTR ) ) then
errReportWarn( FB_WARNINGMSG_CASTTONONPTR )
end if
end if
case FB_DATATYPE_POINTER
options or= AST_CONVOPT_PTRONLY
case else
if( options and AST_CONVOPT_PTRONLY ) then
errReportWarn( FB_WARNINGMSG_CASTTONONPTR )
end if
end select
'' ','
if( lexGetToken( ) <> CHAR_COMMA ) then
errReport( FB_ERRMSG_EXPECTEDCOMMA )
else
lexSkipToken( )
end if
'' Expression
expr = cExpression( )
if( expr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
'' error recovery: create a fake node
expr = astNewCONSTz( dtype, subtype )
end if
options or= AST_CONVOPT_CHECKSTR
'' -w constness implies -w funcptr
if( (fbPdCheckIsSet( FB_PDCHECK_CASTFUNCPTR ) = FALSE) _
and (fbPdCheckIsSet( FB_PDCHECK_CONSTNESS ) = FALSE) ) then
options or= AST_CONVOPT_DONTWARNFUNCPTR
end if
expr = astNewCONV( dtype, subtype, expr, options or AST_CONVOPT_EXACT_CAST, @errmsg )
if( expr = NULL ) then
if( errmsg = FB_ERRMSG_OK ) then
if( options and AST_CONVOPT_PTRONLY ) then
errmsg = FB_ERRMSG_EXPECTEDPOINTER
else
errmsg = FB_ERRMSG_TYPEMISMATCH
end if
end if
errReport( errmsg, TRUE )
'' error recovery: create a fake node
expr = astNewCONSTz( dtype, subtype )
end if
'' ')'
if( lexGetToken( ) <> CHAR_RPRNT ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
'' error recovery: skip until next ')'
hSkipUntil( CHAR_RPRNT, TRUE )
else
lexSkipToken( )
end if
function = expr
end function
'':::::
''DerefExpression = DREF+ HighestPresExpr .
''
function cDerefExpression( ) as ASTNODE ptr
dim as integer derefcnt = any
dim as ASTNODE ptr expr = any
'' DREF?
if( lexGetToken( ) <> FB_TK_DEREFCHAR ) then
return NULL
end if
'' DREF+
derefcnt = 0
do
lexSkipToken( )
derefcnt += 1
loop while( lexGetToken( ) = FB_TK_DEREFCHAR )
'' HighestPresExpr
expr = cHighestPrecExpr( NULL, NULL )
if( expr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDEXPRESSION )
'' error recovery: fake a node
return astNewCONSTi( 0 )
end if
function = astBuildMultiDeref( derefcnt, expr, astGetFullType( expr ), astGetSubType( expr ) )
end function
private function hProcPtrResolveOverload _
( _
byval ovl_head_proc as FBSYMBOL ptr, _
byval proc as FBSYMBOL ptr, _
byval check_exact as boolean = FALSE _
) as FBSYMBOL ptr
dim as FBSYMBOL ptr sym = ovl_head_proc
if( symbIsOperator( ovl_head_proc ) ) then
dim as AST_OP op = any
op = symbGetProcOpOvl( ovl_head_proc )
sym = symbFindOpOvlProc( op, ovl_head_proc, proc )
elseif( symbIsProc( proc ) ) then
dim findopts as FB_SYMBFINDOPT = FB_SYMBFINDOPT_NONE
'' if it is a property then let the function pointer decide
'' if we are looking for the set or get procedure where
'' get is expected to have a return type
if( symbIsProperty( ovl_head_proc ) ) then
if( symbGetType( proc ) <> FB_DATATYPE_VOID ) then
findopts = FB_SYMBFINDOPT_PROPGET
end if
end if
sym = symbFindOverloadProc( ovl_head_proc, proc, findopts )
end if
return sym
end function
private sub hCheckEmptyProcParens()
'' '('')'?
if( lexGetToken( ) = CHAR_LPRNT ) then
lexSkipToken( )
if( hMatch( CHAR_RPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
hSkipUntil( CHAR_RPRNT, TRUE )
end if
end if
end sub
private function hProcPtrBody _
( _
byval base_parent as FBSYMBOL ptr, _
byref proc as FBSYMBOL ptr, _
byval check_exact as boolean _
) as ASTNODE ptr
assert( proc <> NULL )
assert( symbIsProc( proc ) )
'' resolve overloaded procs
if( parser.ctxsym <> NULL ) then
if( symbIsOverloaded( proc ) or check_exact ) then
dim as FBSYMBOL ptr sym = any
sym = hProcPtrResolveOverload( proc, parser.ctxsym )
if( sym ) then
proc = sym
elseif( check_exact ) then
errReport( FB_ERRMSG_NOMATCHINGPROC, TRUE )
return astNewCONSTi( 0 )
end if
end if
end if
'' Check visibility of the proc
if( symbCheckAccess( proc ) = FALSE ) then
errReportEx( FB_ERRMSG_ILLEGALMEMBERACCESS, symbGetFullProcName( proc ) )
end if
'' call any necessary rtl callbacks...
dim as FBRTLCALLBACK callback = symbGetProcCallback( proc )
if( callback <> NULL ) then
callback( proc )
end if
function = astBuildProcAddrof( proc )
end function
private function hVarPtrBody _
( _
byval base_parent as FBSYMBOL ptr, _
byval chain_ as FBSYMCHAIN ptr _
) as ASTNODE ptr
dim as ASTNODE ptr expr = cHighestPrecExpr( base_parent, chain_ )
if( expr = NULL ) then
errReport( FB_ERRMSG_EXPECTEDIDENTIFIER )
'' error recovery: fake a node
return astNewCONSTi( 0 )
end if
'' skip any casting if they won't do any conversion
'' TODO: replace astSkipNoConvCast() with astSkipConstCASTs()
'' where applicable. Need to verify. On one hand, we
'' probably don't care about CONST anymore, on the other
'' hand, we need to make sure we don't prematurely optimize
'' the CONST specifier away in the event that it is needed
'' to be known with AST type checking later.
dim as ASTNODE ptr t = astSkipConstCASTs( expr )
select case as const astGetClass( t )
case AST_NODECLASS_VAR, AST_NODECLASS_IDX, AST_NODECLASS_DEREF, _
AST_NODECLASS_TYPEINI, AST_NODECLASS_CALLCTOR
case AST_NODECLASS_FIELD
'' can't take address of bitfields..
if( symbFieldIsBitfield( t->sym ) ) then
errReport( FB_ERRMSG_INVALIDDATATYPES )
'' error recovery: fake a node
astDelTree( expr )
return astNewCONSTi( 0 )
end if
case else
errReportEx( FB_ERRMSG_INVALIDDATATYPES, "for @ or VARPTR" )
'' error recovery: fake a node
astDelTree( expr )
return astNewCONSTi( 0 )
end select
'' check op overloading
scope
dim as FBSYMBOL ptr proc = any
dim as FB_ERRMSG err_num = any
proc = symbFindSelfUopOvlProc( AST_OP_ADDROF, expr, @err_num )
if( proc <> NULL ) then
'' build a proc call
expr = astBuildCall( proc, expr )
if( expr = NULL ) then
expr = astNewCONSTi( 0 )
end if
return expr
else
if( err_num <> FB_ERRMSG_OK ) then
return astNewCONSTi( 0 )
end if
end if
end scope
function = astNewADDROF( expr )
end function
'':::::
''AddrOfExpression = VARPTR '(' HighPrecExpr ')'
'' | PROCPTR '(' Proc ('('')')? ')'
'' | '@' (Proc ('('')')? | HighPrecExpr)
'' | SADD|STRPTR '(' Variable{str}|Const{str}|Literal{str} ')' .
''
function cAddrOfExpression( ) as ASTNODE ptr
dim as ASTNODE ptr expr = NULL
'' '@' (Proc ('('')')? | Variable)
if( lexGetToken( ) = FB_TK_ADDROFCHAR ) then
lexSkipToken( )
'' not inside a WITH block?
dim as integer check_id = TRUE
if( parser.stmt.with ) then
if( lexGetToken( ) = CHAR_DOT ) then
'' not a '..'?
check_id = (lexGetLookAhead( 1, LEXCHECK_NOPERIOD ) = CHAR_DOT)
end if
end if
'' check if the address of function is being taken
dim as FBSYMCHAIN ptr chain_ = NULL
dim as FBSYMBOL ptr sym = NULL, base_parent = NULL
if( check_id ) then
chain_ = cIdentifier( base_parent, FB_IDOPT_DEFAULT or FB_IDOPT_ALLOWSTRUCT )
sym = symbFindByClass( chain_, FB_SYMBCLASS_PROC )
end if
'' proc?
if( sym <> NULL ) then
lexSkipToken( LEXCHECK_POST_LANG_SUFFIX )
hCheckEmptyProcParens()
return hProcPtrBody( base_parent, sym, FALSE )
'' anything else..
else
return hVarPtrBody( base_parent, chain_ )
end if
end if
select case as const lexGetToken( )
'' VARPTR '(' Variable ')'
case FB_TK_VARPTR
lexSkipToken( LEXCHECK_POST_SUFFIX )
'' '('
if( hMatch( CHAR_LPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDLPRNT )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
expr = hVarPtrBody( NULL, NULL )
'' ')'
if( hMatch( CHAR_RPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
'' error recovery: skip until ')'
hSkipUntil( CHAR_RPRNT, TRUE )
end if
'' PROCPTR '(' Proc ('('')')? ')'
case FB_TK_PROCPTR
lexSkipToken( LEXCHECK_POST_SUFFIX )
'' '('
if( hMatch( CHAR_LPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDLPRNT )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
'' proc?
dim as FBSYMCHAIN ptr chain_ = any
dim as FBSYMBOL ptr sym = any, base_parent = any
chain_ = cIdentifier( base_parent, _
FB_IDOPT_CHECKSTATIC or _
FB_IDOPT_ALLOWSTRUCT or _
FB_IDOPT_ALLOWOPERATOR )
sym = cIdentifierOrUDTMember( base_parent, chain_ )
if( sym = NULL ) then
errReport( FB_ERRMSG_UNDEFINEDSYMBOL )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
hCheckEmptyProcParens()
'' ',' ?
if( hMatch( CHAR_COMMA ) ) then
dim dtype as integer
dim subtype as FBSYMBOL ptr
if( cSymbolType( dtype, subtype ) = FALSE ) then
errReport( FB_ERRMSG_INVALIDDATATYPES, TRUE )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
else
if( typeGetDtAndPtrOnly( dtype ) = typeAddrOf( FB_DATATYPE_FUNCTION ) ) then
dim oldsym as FBSYMBOL ptr = parser.ctxsym
dim old_dtype as integer = parser.ctx_dtype
parser.ctxsym = subtype
parser.ctx_dtype = dtype
expr = hProcPtrBody( base_parent, sym, TRUE )
parser.ctxsym = oldsym
parser.ctx_dtype = old_dtype
else
errReport( FB_ERRMSG_SYNTAXERROR, TRUE )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
end if
else
expr = hProcPtrBody( base_parent, sym, FALSE )
end if
'' ')'
if( hMatch( CHAR_RPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
'' error recovery: skip until ')'
hSkipUntil( CHAR_RPRNT, TRUE )
end if
'' SADD|STRPTR '(' Variable{str} ')'
case FB_TK_SADD, FB_TK_STRPTR
lexSkipToken( LEXCHECK_POST_SUFFIX )
'' '('
if( hMatch( CHAR_LPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDLPRNT )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
expr = cHighestPrecExpr( NULL, NULL )
if( expr = NULL ) then
errReport( FB_ERRMSG_INVALIDDATATYPES )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
return astNewCONSTi( 0 )
end if
dim as integer dtype = astGetDataType( expr )
'' UDT? it might be a kind of z|wstring
if( typeGet( dtype ) = FB_DATATYPE_STRUCT ) then
var sym = astGetSubType( expr )
if( symbGetUdtIsZstring( sym ) or symbGetUdtIsWstring( sym ) ) then
astTryOvlStringCONV( expr )
dtype = astGetDataType( expr )
end if
end if
if( symbIsString( dtype ) = FALSE ) then
errReport( FB_ERRMSG_INVALIDDATATYPES )
'' error recovery: skip until ')' and fake a node
hSkipUntil( CHAR_RPRNT, TRUE )
astDelTree( expr )
return astNewCONSTi( 0 )
end if
'' check for invalid classes (functions, etc)
'' skip any casting if they won't do any conversion
dim as ASTNODE ptr t = astSkipNoConvCAST( expr )
select case as const astGetClass( t )
case AST_NODECLASS_VAR, AST_NODECLASS_IDX, _
AST_NODECLASS_DEREF, AST_NODECLASS_TYPEINI, _
AST_NODECLASS_FIELD
case else
errReportEx( FB_ERRMSG_INVALIDDATATYPES, "for STRPTR" )
end select
'' varlen? do: *cast( [const] zstring const ptr ptr, @expr )
select case dtype
case FB_DATATYPE_STRING
expr = astBuildStrPtr( expr )
case FB_DATATYPE_WCHAR
expr = astNewCONV( typeAddrOf( FB_DATATYPE_WCHAR ), _
NULL, _
astNewADDROF( expr ) )
'' anything else: do cast( zstring ptr, @expr )
case else
expr = astNewCONV( typeAddrOf( FB_DATATYPE_CHAR ), _
NULL, _
astNewADDROF( expr ) )
end select
'' ')'
if( hMatch( CHAR_RPRNT ) = FALSE ) then
errReport( FB_ERRMSG_EXPECTEDRPRNT )
'' error recovery: skip until ')'
hSkipUntil( CHAR_RPRNT, TRUE )
end if
end select
'' Allow indexing on VARPTR()/STRPTR()/etc. directly, they look
'' like functions so this isn't ambigious, while for @ it would
'' mess up the operator precedence:
'' @expr[i] should be @(expr[i]), not (@expr)[i]
'' but for
'' varptr(expr)[i], that problem doesn't exist.
function = cStrIdxOrMemberDeref( expr )
end function