/
symb.bi
2723 lines (2161 loc) · 81.4 KB
/
symb.bi
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
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
''
'' symbol table protos
''
#include once "list.bi"
#include once "pool.bi"
#include once "ast-op.bi"
#include once "stack.bi"
''
enum FB_DATACLASS
FB_DATACLASS_INTEGER '' must be the first
FB_DATACLASS_FPOINT
FB_DATACLASS_STRING
FB_DATACLASS_UDT
FB_DATACLASS_PROC
FB_DATACLASS_UNKNOWN
end enum
'' if FB_DATATYPE changes, take care to update:
'' - ir-hlc.bas::dtypeName() array
'' - edbg_stab.bas::remapTB() array
'' - symb-mangling.bas::typecodeTB() array
'' - symb-data.bas::symb_dtypeTB() array
'' - emit_x86.bas::dtypeTB() array
enum FB_DATATYPE
FB_DATATYPE_VOID
FB_DATATYPE_BOOLEAN
FB_DATATYPE_BYTE
FB_DATATYPE_UBYTE
FB_DATATYPE_CHAR
FB_DATATYPE_SHORT
FB_DATATYPE_USHORT
FB_DATATYPE_WCHAR
FB_DATATYPE_INTEGER
FB_DATATYPE_UINT
FB_DATATYPE_ENUM
FB_DATATYPE_LONG
FB_DATATYPE_ULONG
FB_DATATYPE_LONGINT
FB_DATATYPE_ULONGINT
FB_DATATYPE_SINGLE
FB_DATATYPE_DOUBLE
FB_DATATYPE_STRING
FB_DATATYPE_FIXSTR
FB_DATATYPE_VA_LIST
FB_DATATYPE_STRUCT
FB_DATATYPE_NAMESPC
FB_DATATYPE_FUNCTION
FB_DATATYPE_FWDREF
FB_DATATYPE_POINTER
FB_DATATYPE_XMMWORD
end enum
const FB_DATATYPE_FIRST_NUMERIC = FB_DATATYPE_BOOLEAN
const FB_DATATYPE_LAST_NUMERIC = FB_DATATYPE_DOUBLE
const FB_DATATYPES = (FB_DATATYPE_XMMWORD - FB_DATATYPE_VOID) + 1
const FB_DT_TYPEMASK = &b00000000000000000000000000011111 '' max 32 built-in datatypes
const FB_DT_PTRMASK = &b00000000000000000000000111100000 '' level of pointer indirection
const FB_DT_CONSTMASK = &b00000000000000111111111000000000 '' PTRLEVELS + 1 bit-masks
const FB_DATATYPE_REFERENCE = &b00000000000010000000000000000000 '' used for mangling BYREF parameters
const FB_DT_MANGLEMASK = &b00000001111100000000000000000000 '' used to modify mangling for builtin types
const FB_DATATYPE_INVALID = &b10000000000000000000000000000000
const FB_DT_PTRLEVELS = 8 '' max levels of pointer indirection
const FB_DT_PTRPOS = 5
const FB_DT_CONSTPOS = FB_DT_PTRPOS + 4
const FB_DT_MANGLEPOS = 20
const FB_OVLPROC_MINORSCALE = 10
#define OvlMatchScore(major, minor) (((major) * FB_OVLPROC_MINORSCALE) + (minor))
enum FB_OVLPROC_MATCH_SCORE
FB_OVLPROC_NO_MATCH = 0
FB_OVLPROC_LOWEST_MATCH = 1
FB_OVLPROC_CONVMATCH = OvlMatchScore( FB_DATATYPES * 1, 0 )
FB_OVLPROC_CASTMATCH = OvlMatchScore( FB_DATATYPES * 2, 0 )
FB_OVLPROC_HALFMATCH = OvlMatchScore( FB_DATATYPES * 3, 0 )
FB_OVLPROC_TYPEMATCH = OvlMatchScore( FB_DATATYPES * 4, 0 )
FB_OVLPROC_FULLMATCH = OvlMatchScore( FB_DATATYPES * 5, 0 )
end enum
enum
FB_SIZETYPE_BOOLEAN = 0
FB_SIZETYPE_INT8
FB_SIZETYPE_UINT8
FB_SIZETYPE_INT16
FB_SIZETYPE_UINT16
FB_SIZETYPE_INT32
FB_SIZETYPE_UINT32
FB_SIZETYPE_INT64
FB_SIZETYPE_UINT64
FB_SIZETYPE_FLOAT32
FB_SIZETYPE_FLOAT64
end enum
'' symbol classes
'' When changing, update symb.bas:classnames() and symb.bas:classnamesPretty()
enum FB_SYMBCLASS
FB_SYMBCLASS_VAR = 1
FB_SYMBCLASS_CONST
FB_SYMBCLASS_PROC
FB_SYMBCLASS_PARAM
FB_SYMBCLASS_DEFINE
FB_SYMBCLASS_KEYWORD
FB_SYMBCLASS_LABEL
FB_SYMBCLASS_NAMESPACE
FB_SYMBCLASS_ENUM
FB_SYMBCLASS_STRUCT
FB_SYMBCLASS_CLASS
FB_SYMBCLASS_FIELD
FB_SYMBCLASS_TYPEDEF
FB_SYMBCLASS_FWDREF '' forward definition
FB_SYMBCLASS_SCOPE
FB_SYMBCLASS_RESERVED '' reserved symbol
FB_SYMBCLASS_NSIMPORT '' namespace import (an USING)
end enum
'' symbol state mask
enum FB_SYMBSTATS
'' ''= &h00000001 '' not-used
FB_SYMBSTATS_ACCESSED = &h00000002
FB_SYMBSTATS_CTORINITED = &h00000004 '' ctor method procs only
FB_SYMBSTATS_DECLARED = &h00000008
FB_SYMBSTATS_IMPLICIT = &h00000010 '' VARs only: implicitly generated by compiler (symbAddImplicitVar()), not explicitly defined in source code
FB_SYMBSTATS_RTL = &h00000020
FB_SYMBSTATS_THROWABLE = &h00000040
FB_SYMBSTATS_PARSED = &h00000080
FB_SYMBSTATS_RTTITABLE = &h00000100 '' VARs only: it's an rtti table (used for name mangling)
FB_SYMBSTATS_HASALIAS = &h00000200
FB_SYMBSTATS_VTABLE = &h00000400 '' VARs only: it's a vtable (used for name mangling)
FB_SYMBSTATS_DONTINIT = &h00000800
FB_SYMBSTATS_MAINPROC = &H00001000
FB_SYMBSTATS_MODLEVELPROC = &h00002000
FB_SYMBSTATS_FUNCPTR = &h00004000 '' needed to demangle
FB_SYMBSTATS_JUMPTB = &h00008000 '' ASM backend's fake jumptb vars only
FB_SYMBSTATS_GLOBALCTOR = &h00010000
FB_SYMBSTATS_GLOBALDTOR = &h00020000
FB_SYMBSTATS_CANTDUP = &h00040000
FB_SYMBSTATS_CANBECLONED = &h00080000 '' procedures: It's safe to duplicate CALLs to procedures with this flag, no problems with side effects. Useful for RTL procedures where we can be sure about this.
FB_SYMBSTATS_CANREDEFINE = &h00100000 '' CONSTs: implicitly generated by compiler (symbKeywordConstsInit()), may be redefined
FB_SYMBSTATS_FIXLENSTR = &h00200000 '' TYPEDEFs: to differentiate between Zstring and Zstring * 1 (same for Wstring)
FB_SYMBSTATS_HASRTTI = &h00400000
FB_SYMBSTATS_CANTUNDEF = &h00800000
FB_SYMBSTATS_UNIONFIELD = &h01000000 '' fields only
FB_SYMBSTATS_TEMPORARY = &h01000000 '' variables: String and Wstring - a pointer that needs deallocating at scope breaks/end
'' ''= &h02000000 '' not-used
FB_SYMBSTATS_EMITTED = &h04000000 '' needed by high-level IRs, to avoid emitting structs etc twice
FB_SYMBSTATS_BEINGEMITTED = &h08000000 '' ditto, for circular dependencies with structs
'' reuse - take care
FB_SYMBSTATS_PROCEMITTED = FB_SYMBSTATS_UNIONFIELD '' procs only
FB_SYMBSTATS_EXCLPARENT = FB_SYMBSTATS_DONTINIT '' procs only
FB_SYMBSTATS_ARGV = FB_SYMBSTATS_CANBECLONED '' params/paramvars only: is it main()'s argv? (helping the C backend to emit a clang-compatible main() signature)
end enum
'' symbol attributes mask
enum FB_SYMBATTRIB
FB_SYMBATTRIB_NONE = &h00000000
FB_SYMBATTRIB_SHARED = &h00000001 '' all symbols
FB_SYMBATTRIB_STATIC = &h00000002 '' all symbols
FB_SYMBATTRIB_DYNAMIC = &h00000004 '' all symbols
FB_SYMBATTRIB_COMMON = &h00000008 '' all symbols
FB_SYMBATTRIB_EXTERN = &h00000010 '' all symbols: extern's become public when DIM'ed
FB_SYMBATTRIB_PUBLIC = &h00000020 '' all symbols
FB_SYMBATTRIB_PRIVATE = &h00000040 '' all symbols
FB_SYMBATTRIB_LOCAL = &h00000080 '' all symbols
FB_SYMBATTRIB_EXPORT = &h00000100 '' all symbols
FB_SYMBATTRIB_IMPORT = &h00000200 '' all symbols
FB_SYMBATTRIB_LITERAL = &h00000400 '' literal value - typically implies CONST
FB_SYMBATTRIB_CONST = &h00000800 '' CONST value, expression, or method
FB_SYMBATTRIB_TEMP = &h00001000 '' VARs
FB_SYMBATTRIB_DESCRIPTOR = &h00002000 '' VARs (arrays)
FB_SYMBATTRIB_PARAMVARBYDESC = &h00004000 '' VARs (paramater variables)
FB_SYMBATTRIB_PARAMVARBYVAL = &h00008000 '' VARs (paramater variables)
FB_SYMBATTRIB_PARAMVARBYREF = &h00010000 '' VARs (paramater variables)
FB_SYMBATTRIB_FUNCRESULT = &h00020000
FB_SYMBATTRIB_REF = &h00040000 '' VARs/FIELDs (if declared with BYREF)
FB_SYMBATTRIB_INSTANCEPARAM = &h00080000
FB_SYMBATTRIB_SUFFIXED = &h00100000
FB_SYMBATTRIB_VIS_PRIVATE = &h00200000 '' UDT members only
FB_SYMBATTRIB_VIS_PROTECTED = &h00400000 '' UDT members only
FB_SYMBATTRIB_INTERNAL = &h00800000 '' default UDT members / vtable / rtti - affects name mangling
FB_SYMBATTRIB_ANONYMOUS = &h01000000 '' anonymous / unnamed id
end enum
'' proc symbol attributes mask
enum FB_PROCATTRIB
FB_PROCATTRIB_NONE = &h00000000
FB_PROCATTRIB_OVERLOADED = &h00000001 '' PROCs / METHODs only
FB_PROCATTRIB_METHOD = &h00000002 '' Non-STATIC UDT member procs, i.e. procs with implicit THIS ptr
FB_PROCATTRIB_CONSTRUCTOR = &h00000004 '' methods only
FB_PROCATTRIB_DESTRUCTOR1 = &h00000008 '' methods only - complete destructor
FB_PROCATTRIB_OPERATOR = &h00000010 '' methods only
FB_PROCATTRIB_PROPERTY = &h00000020 '' methods only
FB_PROCATTRIB_STATICLOCALS = &h00000040 '' PROCs only
FB_PROCATTRIB_NAKED = &h00000080 '' procedures only
FB_PROCATTRIB_VIRTUAL = &h00000100 '' methods only: all virtuals (normal and pure)
FB_PROCATTRIB_ABSTRACT = &h00000200 '' methods only: pure virtuals (only)
FB_PROCATTRIB_NOTHISCONSTNESS = &h00000400 '' PROCs only
FB_PROCATTRIB_RETURNBYREF = &h00000800 '' PROCs (functions/function pointers returning BYREF)
FB_PROCATTRIB_DESTRUCTOR0 = &h00001000 '' methods only - deleting destructor
end enum
'' parameter modes
enum FB_PARAMMODE
FB_PARAMMODE_BYVAL = 1 '' must start at 1! used for mangling
FB_PARAMMODE_BYREF
FB_PARAMMODE_BYDESC
FB_PARAMMODE_VARARG
end enum
'' call conventions
enum FB_FUNCMODE
FB_FUNCMODE_STDCALL = 1 '' ditto
FB_FUNCMODE_STDCALL_MS '' ms/vb-style: don't include the @n suffix
FB_FUNCMODE_CDECL
FB_FUNCMODE_PASCAL
FB_FUNCMODE_THISCALL '' x86 only
FB_FUNCMODE_FASTCALL '' x86 only
'' Symbolic constant to represent FBCALL, telling cProcCallingConv()
'' and the RTL procedure definitions to use env.target.fbcall which
'' will be the real FB_FUNCMODE_* implementing FBCALL depending on the
'' compilation target.
FB_FUNCMODE_FBCALL = -1
end enum
'' options when adding new symbols
enum FB_SYMBOPT
FB_SYMBOPT_NONE = &h00000000
FB_SYMBOPT_PRESERVECASE = &h00000001
FB_SYMBOPT_UNSCOPE = &h00000002
FB_SYMBOPT_DECLARING = &h00000004
FB_SYMBOPT_MOVETOGLOB = &h00000008
FB_SYMBOPT_RTL = &h00000010
FB_SYMBOPT_DOHASH = &h00000020
FB_SYMBOPT_CREATEALIAS = &h00000040
FB_SYMBOPT_NODUPCHECK = &h00000080
end enum
'' options when finding symbols
enum FB_SYMBFINDOPT
FB_SYMBFINDOPT_NONE = &h00000000
FB_SYMBFINDOPT_PROPGET = &h00000001 '' match property get and not property set
FB_SYMBFINDOPT_BOP_OVL = &h00000002 '' exact match at least one parameter
FB_SYMBFINDOPT_EXPLICIT = &h00000004 '' require explicit exact match
FB_SYMBFINDOPT_NO_ERROR = &h00000008 '' don't report errors, return to caller
FB_SYMBFINDOPT_NO_CTOR = &h00000010 '' don't find matching constructors
FB_SYMBFINDOPT_NO_CAST = &h00000020 '' don't find matching cast operators
end enum
''
enum FB_MANGLING
FB_MANGLING_BASIC
FB_MANGLING_CDECL
FB_MANGLING_STDCALL
FB_MANGLING_STDCALL_MS
FB_MANGLING_CPP
FB_MANGLING_PASCAL
FB_MANGLING_RTLIB
end enum
''
enum FB_MANGLEOPT
FB_MANGLEOPT_NONE = 0 '' no special options
FB_MANGLEOPT_KEEPTOPCONST = 1 '' keep the top-level const when mangling
FB_MANGLEOPT_HASPTR = 2 '' mangled type has/is a pointer type
FB_MANGLEOPT_HASREF = 4 '' mangled type has/is reference type
FB_MANGLEOPT_NESTED = 8 '' mangled type is nested in another type
end enum
enum FB_STRUCT_INREG
FB_STRUCT_NONE ''(default, not used)
FB_STRUCT_R ''RAX
FB_STRUCT_RR ''RAX/RDX
FB_STRUCT_RX ''RAX/XMM0
FB_STRUCT_X ''XMM0
FB_STRUCT_XR ''XMM0/RAX
FB_STRUCT_XX ''XMM0/XMM1
end enum
''for analyzing structures Linux only
#define KPARTNOTDEF 0
#define KPART1FLOAT 2
#define KPART2FLOAT 8
#define KPART1INTEGER 1
#define KPART2INTEGER 4
#define KLOW8BYTES 1
#define KHIGH8BYTES 2
#define KSTRUCT_R KPART1INTEGER
#define KSTRUCT_X KPART1FLOAT
#define KSTRUCT_RR KPART1INTEGER + KPART2INTEGER
#define KSTRUCT_RX KPART1INTEGER + KPART2FLOAT
#define KSTRUCT_XR KPART1FLOAT + KPART2INTEGER
#define KSTRUCT_XX KPART1FLOAT + KPART2FLOAT
type FBSYMBOL_ as FBSYMBOL
#ifndef ASTNODE_
type ASTNODE_ as ASTNODE
#endif
#ifndef EMIT_NODE_
type EMIT_NODE_ as EMIT_NODE
#endif
''
type FBSYMLIST
head as FBSYMBOL_ ptr
tail as FBSYMBOL_ ptr
end type
type FBARRAYDIM
lower as longint
upper as longint
end type
'' Special value to represent the case where '...' ellipsis was given as ubound
const FB_ARRAYDIM_UNKNOWN = &h8000000000000000ll
''
type FBSYMCHAIN
sym as FBSYMBOL_ ptr '' first symbol
next as FBSYMCHAIN ptr
isimport as integer
'' all fields below are only set when importing (with USING) a ns
prev as FBSYMCHAIN ptr
item as HASHITEM ptr
imp_next as FBSYMCHAIN ptr
end type
''
type FBHASHTB
owner as FBSYMBOL_ ptr '' back link
tb as THASH
prev as FBHASHTB ptr '' prev node in the current hash tbs lookup list
next as FBHASHTB ptr '' next //
end type
type FBSYMHASH
tb as FBHASHTB ptr '' parent's hash tb
item as HASHITEM ptr '' hash item, for fast deletion
index as uinteger '' ditto
prev as FBSYMBOL_ ptr '' prev duplicated symbol
next as FBSYMBOL_ ptr '' next //
end type
''
type FBSYMBOLTB
owner as FBSYMBOL_ ptr '' back link
head as FBSYMBOL_ ptr '' first node
tail as FBSYMBOL_ ptr '' last node
end type
''
type FBNAMESPC_EXT
implist as FBSYMLIST '' all namespaces imported by this ns
explist as FBSYMLIST '' all namespaces importing this ns
cnt as integer '' times this ns was imported/nested
impsym_head as FBSYMCHAIN ptr '' imported symbols by the last USING
impsym_tail as FBSYMCHAIN ptr '' /
end type
type FBNAMESPC
symtb as FBSYMBOLTB
hashtb as FBHASHTB
ext as FBNAMESPC_EXT ptr
end type
union FBVALUE
s as FBSYMBOL_ ptr
i as longint
f as double
end union
'' keyword
type FBS_KEYWORD
id as integer
tkclass as FB_TKCLASS
end type
'' define or macro
type FB_DEFPARAM
name as zstring ptr
num as integer
next as FB_DEFPARAM ptr
end type
enum FB_DEFTOK_TYPE
FB_DEFTOK_TYPE_PARAM
FB_DEFTOK_TYPE_PARAMSTR
FB_DEFTOK_TYPE_TEX
FB_DEFTOK_TYPE_TEXW
end enum
type FB_DEFTOK
type as FB_DEFTOK_TYPE
union
text as zstring ptr
textw as wstring ptr
paramnum as integer
end union
prev as FB_DEFTOK ptr
next as FB_DEFTOK ptr
end type
enum FB_DEFINE_FLAGS
FB_DEFINE_FLAGS_NONE = &h00000000
FB_DEFINE_FLAGS_STR = &h00000001
FB_DEFINE_FLAGS_NOGCC = &h00000002
FB_DEFINE_FLAGS_VARIADIC = &h00000004
FB_DEFINE_FLAGS_NEEDPARENS = &h00000008
end enum
type LEXPP_ARGTB_ as LEXPP_ARGTB ptr
type FBS_DEFINE_PROCZ as function( ) as string
type FBS_MACRO_PROCZ as function( byval argtb as LEXPP_ARGTB_, byval errnum as integer ptr ) as string
type FBS_MACRO_PROCW as function( byval argtb as LEXPP_ARGTB_, byval errnum as integer ptr ) as wstring ptr
type FBS_DEFINE
params as integer
paramhead as FB_DEFPARAM ptr
union
tokhead as FB_DEFTOK ptr '' only if args > 0
text as zstring ptr '' // = 0
textw as wstring ptr
end union
isargless as integer
flags as FB_DEFINE_FLAGS '' bit 0: 1=numeric, 0=string
union
dprocz as FBS_DEFINE_PROCZ
mprocz as FBS_MACRO_PROCZ
end union
union
mprocw as FBS_MACRO_PROCW
end union
end type
'' forward definition
type FBFWDREF
ref as FBSYMBOL_ ptr '' The user that has to be backpatched
prev as FBFWDREF ptr
end type
type FBS_FWDREF
tail as FBFWDREF ptr '' List of users of this fwdref
end type
'' label
type FBS_LABEL
parent as FBSYMBOL_ ptr '' parent block, not always a proc
declared as integer
stmtnum as integer '' can't use colnum as it's unreliable
gosub as boolean '' if label is used for gosub with gas64
end type
'' structure
enum FB_UDTOPT
FB_UDTOPT_ISUNION = &h00000001
FB_UDTOPT_ISANON = &h00000002
FB_UDTOPT_HASPTRFIELD = &h00000004
FB_UDTOPT_HASCTORFIELD = &h00000008
FB_UDTOPT_HASDTORFIELD = &h00000010
FB_UDTOPT_HASRECBYVALPARAM = &h00000020
FB_UDTOPT_HASRECBYVALRES = &h00000040
FB_UDTOPT_HASGETPROPERTY = &h00000080
FB_UDTOPT_HASSETPROPERTY = &h00000100
FB_UDTOPT_HASIDXGETPROPERTY = &h00000200
FB_UDTOPT_HASIDXSETPROPERTY = &h00000400
FB_UDTOPT_HASKWDFIELD = &h00000800
FB_UDTOPT_HASINITEDFIELD = &h00001000
FB_UDTOPT_HASANONUNION = &h00002000
FB_UDTOPT_HASSTATICVAR = &h00004000
FB_UDTOPT_HASBITFIELD = &h00008000
FB_UDTOPT_ISWSTRING = &h00010000
FB_UDTOPT_ISZSTRING = &h00020000
FB_UDTOPT_HASNESTED = &h00040000
FB_UDTOPT_HASZEROEDFIELD = &h00080000
FB_UDTOPT_HASFILLEDFIELD = &h00100000
FB_UDTOPT_VALISTTYPEMASK = &h00f00000
end enum
type FB_STRUCT_DBG
typenum as integer
end type
type FB_STRUCTEXT
ctorhead as FBSYMBOL_ ptr '' ctor head (first overload proc) or NULL
defctor as FBSYMBOL_ ptr '' default ctor or NULL
copyctor as FBSYMBOL_ ptr '' copy ctor or NULL
copyctorconst as FBSYMBOL_ ptr '' copy ctor with CONST param or NULL
dtor1 as FBSYMBOL_ ptr '' complete object destructor or NULL
dtor0 as FBSYMBOL_ ptr '' deleting destructor or NULL
copyletop as FBSYMBOL_ ptr '' copy LET overload proc or NULL
copyletopconst as FBSYMBOL_ ptr '' copy LET overload proc with CONST param or NULL
opovlTb(0 to AST_OP_SELFOPS-1) as FBSYMBOL_ ptr
vtableelements as integer '' vtable elements counter
vtable as FBSYMBOL_ ptr '' virtual-functions table struct
rtti as FBSYMBOL_ ptr '' Run-Time Type Info struct
abstractcount as integer '' ABSTRACT method counter (to determine abstract classes, which aren't allowed to be instantiated)
end type
type FBS_STRUCT
'' extends FBNAMESPC
ns as FBNAMESPC
base as FBSYMBOL_ ptr '' base class
anonparent as FBSYMBOL_ ptr
natalign as integer '' UDT's natural alignment based on largest natural field alignment
unpadlgt as longint '' unpadded len
options as long '' FB_UDTOPT
bitpos as ubyte
align as ubyte
'' real type used to return this UDT from functions
retdtype as FB_DATATYPE
retin2regs as FB_STRUCT_INREG ''for gas64
dbg as FB_STRUCT_DBG
ext as FB_STRUCTEXT ptr
end type
'' enumeration
type FBS_ENUM
'' extends FBNAMESPC
ns as FBNAMESPC
elements as integer
dbg as FB_STRUCT_DBG
end type
type FB_CALL_ARG '' used by overloaded function calls
expr as ASTNODE_ ptr
mode as FB_PARAMMODE
next as FB_CALL_ARG ptr
end type
type FB_CALL_ARG_LIST
args as integer
head as FB_CALL_ARG ptr
tail as FB_CALL_ARG ptr
end type
'' function param
type FBS_PARAM
mode as FB_PARAMMODE
var as FBSYMBOL_ ptr '' link to decl var in func bodies
optexpr as ASTNODE_ ptr '' default value
bydescdimensions as integer
bydescrealsubtype as FBSYMBOL_ ptr '' bydesc array descriptor type
regnum as integer '' register number (1 is first, 0 is not in register)
end type
'' function
type FBRTLCALLBACK as function( byval sym as FBSYMBOL_ ptr ) as integer
type FB_PROCOVL
minparams as short
maxparams as short
next as FBSYMBOL_ ptr
end type
'' used by x86 ASM emitter only
type FB_PROCSTK
argofs as integer
localofs as integer
localmax as integer
end type
type FB_PROCDBG
iniline as integer '' sub|function
endline as integer '' end sub|function
incfile as zstring ptr
end type
type FB_PROCERR
lasthnd as FBSYMBOL_ ptr '' last error handler
lastmod as FBSYMBOL_ ptr '' last module name
lastfun as FBSYMBOL_ ptr '' last function name
end type
type FB_PROCOPOVL
op as AST_OP
end type
type FB_DTORWRAPPER
proc as FBSYMBOL_ ptr
sym as FBSYMBOL_ ptr '' for symbol
end type
enum FB_PROCSTATS
FB_PROCSTATS_RETURNUSED = &h0001
FB_PROCSTATS_ASSIGNUSED = &h0002
FB_PROCSTATS_GOSUBUSED = &h0004
end enum
type FB_PROCGSB
ctx as FBSYMBOL_ ptr '' local pointer for gosub stack
end type
type FB_PROCEXT
res as FBSYMBOL_ ptr '' result, if any
stk as FB_PROCSTK '' to keep track of the stack frame
dbg as FB_PROCDBG '' debugging
err as FB_PROCERR
opovl as FB_PROCOPOVL
statdtor as TLIST ptr '' list of static instances with dtors
stats as FB_PROCSTATS
stmtnum as integer
priority as integer
gosub as FB_PROCGSB
base_initree as ASTNODE_ ptr '' base() ctorcall/initializer given in constructor bodies
'' virtual methods:
'' vtable array index, location of the procptr in the vtbl
'' methods that override a virtual method:
'' vtable index of the virtual method that's overridden by this one
'' other methods:
'' 0
'' A valid index must be >= 2 since the first two vtable elements are
'' the null pointer and the rtti pointer.
vtableindex as integer
'' For methods that override a virtual method: the method that's
'' overridden (if any); or else NULL.
overridden as FBSYMBOL_ ptr
end type
type FB_PROCRTL
callback as FBRTLCALLBACK
end type
enum FB_PROC_RETURN_METHOD
FB_RETURN_FPU
FB_RETURN_SSE
FB_RETURN_DEFAULT '' if none specified, take from the proto
end enum
type FBS_PROC
symtb as FBSYMBOLTB '' local symbols table
params as short
optparams as short '' number of optional/default params
paramtb as FBSYMBOLTB '' parameters symbol tb
mode as FB_FUNCMODE '' calling convention
'' result type remapped to what it will be emitted as, including CONSTs
realdtype as FB_DATATYPE
realsubtype as FBSYMBOL_ ptr
returnMethod as FB_PROC_RETURN_METHOD
rtl as FB_PROCRTL
ovl as FB_PROCOVL '' overloading
ext as FB_PROCEXT ptr '' extra fields, not used with prototypes
end type
'' scope
type FB_SCOPEDBG
iniline as integer '' scope
endline as integer '' end scope
inilabel as FBSYMBOL_ ptr
endlabel as FBSYMBOL_ ptr
end type
'' used by x86 ASM emitter only
type FB_SCOPEEMIT
baseofs as integer
end type
type FBS_SCOPE
backnode as ASTNODE_ ptr
symtb as FBSYMBOLTB
dbg as FB_SCOPEDBG
emit as FB_SCOPEEMIT
end type
enum FBARRAY_FLAGS
FBARRAY_FLAGS_DIMENSIONS = &h0000000f '' number of entries allocated in dimTb()
FBARRAY_FLAGS_FIXED_DIM = &h00000010 '' array points to fixed-length memory
FBARRAY_FLAGS_FIXED_LEN = &h00000020 '' array points to fixed-length memory
FBARRAY_FLAGS_RESERVED = &hffffffc0 '' reserved, do not use
end enum
'' variable
type FBS_ARRAY
'' 0 = none (not an array),
'' -1 = () = not yet known (should be filled in ASAP),
'' 1..n = known dimensions (fixed-size or dynamic arrays)
dimensions as integer
'' Dynamically allocated array of dimension bounds (static arrays only)
dimtb as FBARRAYDIM ptr
diff as longint
elements as longint
desc as FBSYMBOL_ ptr
'' Array descriptor type (useful especially for BYDESC param vars, which
'' don't have a descriptor var associated, but still need to know the
'' exact descriptor type sometimes)
desctype as FBSYMBOL_ ptr
end type
type FBVAR_DESC
array as FBSYMBOL_ ptr '' back-link
end type
type FBVAR_DATA
prev as FBSYMBOL_ ptr
end type
type FBS_CONST
union '' extends FBVALUE
value as FBVALUE
s as FBSYMBOL_ ptr
i as longint
f as double
end union
hassuffix as integer
end type
type FBS_VAR
union
littext as zstring ptr
littextw as wstring ptr
initree as ASTNODE_ ptr
end union
array as FBS_ARRAY
desc as FBVAR_DESC
stmtnum as integer '' can't use colnum as it's unreliable
align as integer '' 0 = use default alignment
data as FBVAR_DATA '' used with DATA stmts
bitpos as integer '' bitfields only: bit offset in container field
bits as integer '' bitfields only: size in bits
end type
'' namespace
type FBS_NAMESPACE
'' extends FBNAMESPC
ns as FBNAMESPC
cnt as integer '' times this ns was re-opened
last_tail as FBSYMBOL_ ptr '' point to last tail
end type
'' namespace import (USING)
type FBS_NSIMPORT
'' imported ns (src)
imp_ns as FBSYMBOL_ ptr
imp_prev as FBSYMBOL_ ptr
imp_next as FBSYMBOL_ ptr
'' exported ns (dst)
exp_ns as FBSYMBOL_ ptr
exp_prev as FBSYMBOL_ ptr
exp_next as FBSYMBOL_ ptr
end type
''
type FB_SYMBID
name as zstring ptr '' upper-cased name, shared by hash tb
alias as zstring ptr '' alias/preserved (if EXTERN was used) name
mangled as zstring ptr '' mangled name
end type
''
type FBSYMBOL
class as FB_SYMBCLASS
attrib as FB_SYMBATTRIB
pattrib as FB_PROCATTRIB
stats as FB_SYMBSTATS
id as FB_SYMBID
typ as FB_DATATYPE
subtype as FBSYMBOL ptr
scope as ushort
mangling as short '' FB_MANGLING
lgt as longint
ofs as longint '' for local vars, args, UDT's and fields
union
var_ as FBS_VAR
val as FBS_CONST '' constants
udt as FBS_STRUCT
enum_ as FBS_ENUM
proc as FBS_PROC
param as FBS_PARAM
lbl as FBS_LABEL
def as FBS_DEFINE
key as FBS_KEYWORD
fwd as FBS_FWDREF
scp as FBS_SCOPE
nspc as FBS_NAMESPACE
nsimp as FBS_NSIMPORT
end union
hash as FBSYMHASH '' hash tb (namespace) it's part of
symtb as FBSYMBOLTB ptr '' symbol tb it's part of
parent as FBSYMBOL Ptr
prev as FBSYMBOL ptr '' next in symbol tb list
next as FBSYMBOL ptr '' prev /
end type
type FBHASHTBLIST
head as FBHASHTB ptr
tail as FBHASHTB ptr
end type
type SYMB_DEF_PARAM
item as HASHITEM ptr
index as uinteger
end type
type SYMB_DEF_UniqueId_Elm
name as zstring ptr
prev as SYMB_DEF_UniqueId_Elm ptr
end type
type SYMB_DEF_UniqueId_Stack
top as SYMB_DEF_UniqueId_Elm ptr
end type
type SYMB_DEF_UniqueId
dict as THASH '' of SYMB_DEF_UniqueId_Stack
end type
type SYMB_DEF_CTX
paramlist as TLIST '' define parameters
toklist as TLIST '' define tokens
uniqueid as SYMB_DEF_UniqueId
'' macros only..
param as integer '' param count
paramhash as THASH
hash(0 to FB_MAXDEFINEARGS-1) as SYMB_DEF_PARAM
end type
type SYMB_OVLOP
head as FBSYMBOL ptr '' head proc
end type
type FB_GLOBCTORLIST_ITEM
sym as FBSYMBOL ptr
next as FB_GLOBCTORLIST_ITEM ptr
end type
type FB_GLOBCTORLIST
head as FB_GLOBCTORLIST_ITEM ptr
tail as FB_GLOBCTORLIST_ITEM ptr
list as TLIST
end type
type FB_RTTICTX
fb_rtti as FBSYMBOL ptr
fb_object as FBSYMBOL ptr
End Type
const CHAINPOOL_SIZE = 1 shl 12
type SYMBCTX
inited as integer
symlist as TLIST '' (of FBSYMBOL)
hashlist as FBHASHTBLIST
'' FBSYMCHAIN's are allocated from this buffer
chainpool(0 to (CHAINPOOL_SIZE - 1)) as FBSYMCHAIN
chainpoolhead as integer
globnspc as FBSYMBOL '' global namespace
namespc as FBSYMBOL ptr '' current ns
hashtb as FBHASHTB ptr '' current hash tb
symtb as FBSYMBOLTB ptr '' current symbol tb
neststk as TSTACK '' nest stack (namespace/class nesting)
imphashtb as THASH '' imported symbol (USING) tb
imphashlist as TLIST '' (of FBSYMHASH)
namepool as TPOOL
fwdlist as TLIST '' forward typedef refs
nsextlist as TLIST '' of FBNAMESPC_EXT
fwdrefcnt as integer
def as SYMB_DEF_CTX '' #define context
lastlbl as FBSYMBOL ptr
globctorlist as FB_GLOBCTORLIST '' global ctors list
globdtorlist as FB_GLOBCTORLIST '' global dtors list
globOpOvlTb ( _
0 to AST_OPCODES-1 _
) as SYMB_OVLOP '' global operator overloading
fbarray_data as integer '' offsetof( FBARRAY, data )
fbarray_ptr as integer '' offsetof( FBARRAY, ptr )
fbarray_size as integer '' offsetof( FBARRAY, size )
fbarray_dimtb as integer '' offsetof( FBARRAY, dimTB )
fbarraydim as FBSYMBOL ptr '' FBARRAYDIM (dimTB element structure)
fbarraydim_lbound as integer '' offsetof( FBARRAYDIM, lbound )
fbarraydim_ubound as integer '' offsetof( FBARRAYDIM, ubound )
rtti as FB_RTTICTX
end type
type SYMB_DATATYPE
class as FB_DATACLASS '' INTEGER, FPOINT
size as integer '' in bytes
signed as integer '' TRUE or FALSE
'' For basic integer types only: ranking value, to establish a proper
'' target-specific (32bit/64bit) order (the FB_DATATYPE enum order is
'' not enough because it's not target-specific)
intrank as integer
remaptype as FB_DATATYPE '' remapped type for ENUM, POINTER, etc
sizetype as integer '' FB_SIZETYPE_*
name as const zstring ptr
end type
'' Data passed from symbUdtDeclareDefaultMembers() to symbUdtImplementDefaultMembers()
type SYMBDEFAULTMEMBERS
defctor as FBSYMBOL ptr
dtor1 as FBSYMBOL ptr
dtor0 as FBSYMBOL ptr
copyctor as FBSYMBOL ptr
copyctorconst as FBSYMBOL ptr
copyletopconst as FBSYMBOL ptr
end type
#include once "ast.bi"
declare sub symbInit _
( _
byval ismain as integer _
)
declare sub symbEnd _
( _
_
)
declare sub symbDataInit( )
declare function symbNewChainpool _
( _
byval sym as FBSYMBOL ptr _
) as FBSYMCHAIN ptr
declare function symbLookup _
( _
byval id as zstring ptr, _
byref tk as FB_TOKEN, _
byref tk_class as FB_TKCLASS _
) as FBSYMCHAIN ptr
declare function symbLookupAt _
( _
byval ns as FBSYMBOL ptr, _
byval id as const zstring ptr, _
byval preserve_case as integer = FALSE, _
byval search_imports as integer = TRUE _
) as FBSYMCHAIN ptr
declare function symbFindByClass _
( _
byval chain as FBSYMCHAIN ptr, _
byval class as integer _
) as FBSYMBOL ptr
declare function symbFindVarBySuffix _
( _
byval chain as FBSYMCHAIN ptr, _
byval suffix as integer _