-
-
Notifications
You must be signed in to change notification settings - Fork 608
/
cc.d
1511 lines (1304 loc) · 58.9 KB
/
cc.d
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
/**
* Common definitions
*
* Compiler implementation of the
* $(LINK2 https://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1985-1998 by Symantec
* Copyright (C) 2000-2024 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/cc.d, backend/_cc.d)
*/
module dmd.backend.cc;
// Online documentation: https://dlang.org/phobos/dmd_backend_cc.html
import dmd.backend.barray;
import dmd.backend.cdef; // host and target compiler definition
import dmd.backend.code_x86;
import dmd.backend.dlist;
import dmd.backend.dt;
import dmd.backend.el;
import dmd.backend.symtab;
import dmd.backend.type;
@nogc:
nothrow:
@safe:
enum GENOBJ = 1; // generating .obj file
uint mskl(uint i) { return 1 << i; } // convert int to mask
// Warnings
enum WM
{
WM_no_inline = 1, //function '%s' is too complicated to inline
WM_assignment = 2, //possible unintended assignment
WM_nestcomment = 3, //comments do not nest
WM_assignthis = 4, //assignment to 'this' is obsolete, use X::operator new/delete
WM_notagname = 5, //no tag name for struct or enum
WM_valuenotused = 6, //value of expression is not used
WM_extra_semi = 7, //possible extraneous ';'
WM_large_auto = 8, //very large automatic
WM_obsolete_del = 9, //use delete[] rather than delete[expr], expr ignored
WM_obsolete_inc = 10, //using operator++() (or --) instead of missing operator++(int)
WM_init2tmp = 11, //non-const reference initialized to temporary
WM_used_b4_set = 12, //variable '%s' used before set
WM_bad_op = 13, //Illegal type/size of operands for the %s instruction
WM_386_op = 14, //Reference to '%s' caused a 386 instruction to be generated
WM_ret_auto = 15, //returning address of automatic '%s'
WM_ds_ne_dgroup = 16, //DS is not equal to DGROUP
WM_unknown_pragma = 17, //unrecognized pragma
WM_implied_ret = 18, //implied return at closing '}' does not return value
WM_num_args = 19, //%d actual arguments expected for %s, had %d
WM_before_pch = 20, //symbols or macros defined before #include of precompiled header
WM_pch_first = 21, //precompiled header must be first #include when -H is used
WM_pch_config = 22,
WM_divby0 = 23,
WM_badnumber = 24,
WM_ccast = 25,
WM_obsolete = 26,
// Posix
WM_skip_attribute = 27, // skip GNUC attribute specification
WM_warning_message = 28, // preprocessor warning message
WM_bad_vastart = 29, // args for builtin va_start bad
WM_undefined_inline = 30, // static inline not expanded or defined
}
static if (MEMMODELS == 1)
{
enum LARGEDATA = 0; // don't want 48 bit pointers
enum LARGECODE = 0;
}
else
{
bool LARGEDATA() { return (config.memmodel & 6) != 0; }
bool LARGECODE() { return (config.memmodel & 5) != 0; }
}
enum IDMAX = 900; // identifier max (excluding terminating 0)
enum IDOHD = 4+1+int.sizeof*3; // max amount of overhead to ID added by
enum STRMAX = 65_000; // max length of string (determined by
// max ph size)
struct Thunk
{ Symbol *sfunc;
Symbol *sthunk;
targ_size_t d;
targ_size_t d2;
int i;
}
struct token_t;
alias Funcsym = Symbol;
struct blklst;
alias symlist_t = list_t;
alias vec_t = size_t*;
alias enum_TK = ubyte;
__gshared Config config;
@trusted
uint CPP() { return config.flags3 & CFG3cpp; }
/////////// Position in source file
struct Srcpos
{
nothrow:
uint Slinnum; // 0 means no info available
uint Scharnum; // 0 means no info available
const(char)* Sfilename;
const(char*) name() const { return Sfilename; }
static Srcpos create(const(char)* filename, uint linnum, uint charnum)
{
// Cannot have constructor because Srcpos is used in a union
Srcpos sp;
sp.Sfilename = filename;
sp.Slinnum = linnum;
sp.Scharnum = charnum;
return sp;
}
/*******
* Set fields of Srcpos
* Params:
* filename = file name
* linnum = line number
* charnum = character number
*/
void set(const(char)* filename, uint linnum, int charnum) pure
{
Sfilename = filename;
Slinnum = linnum;
Scharnum = charnum;
}
void print(const(char)* func) const { Srcpos_print(this, func); }
}
import dmd.backend.dout : Srcpos_print;
alias stflags_t = uint;
enum
{
PFLpreprocessor = 1, // in preprocessor
PFLmasm = 2, // in Microsoft-style inline assembler
PFLbasm = 4, // in Borland-style inline assembler
PFLsemi = 8, // ';' means start of comment
// PFLautogen = 0x10, // automatically generate HX ph file
PFLmftemp = 0x20, // if expanding member function template
PFLextdef = 0x40, // we had an external def
PFLhxwrote = 0x80, // already generated HX ph file
PFLhxdone = 0x100, // done with HX ph file
// if TX86
PFLhxread = 0x200, // have read in an HX ph file
PFLhxgen = 0x400, // need to generate HX ph file
PFLphread = 0x800, // read a ph file
PFLcomdef = 0x1000, // had a common block
PFLmacdef = 0x2000, // defined a macro in the source code
PFLsymdef = 0x4000, // declared a global Symbol in the source
PFLinclude = 0x8000, // read a .h file
PFLmfc = 0x10000, // something will affect MFC compatibility
}
alias sthflags_t = char;
enum
{
FLAG_INPLACE = 0, // in place hydration
FLAG_HX = 1, // HX file hydration
FLAG_SYM = 2, // .SYM file hydration
}
/**********************************
* Current 'state' of the compiler.
* Used to gather together most global variables.
* This struct is saved/restored during function body parsing.
*/
struct Pstate
{
ubyte STinopeq; // if in n2_createopeq()
ubyte STinarglist; // if !=0, then '>' is the end of a template
// argument list, not an operator
ubyte STinsizeof; // !=0 if in a sizeof expression. Useful to
// prevent <array of> being converted to
// <pointer to>.
ubyte STintemplate; // if !=0, then expanding a function template
// (do not expand template Symbols)
ubyte STdeferDefaultArg; // defer parsing of default arg for parameter
ubyte STnoexpand; // if !=0, don't expand template symbols
ubyte STignoretal; // if !=0 ignore template argument list
ubyte STexplicitInstantiation; // if !=0, then template explicit instantiation
ubyte STexplicitSpecialization; // if !=0, then template explicit specialization
ubyte STinconstexp; // if !=0, then parsing a constant expression
ubyte STisaddr; // is this a possible pointer to member expression?
uint STinexp; // if !=0, then in an expression
static if (NTEXCEPTIONS)
{
ubyte STinfilter; // if !=0 then in exception filter
ubyte STinexcept; // if !=0 then in exception handler
block *STbfilter; // current exception filter
}
Funcsym *STfuncsym_p; // if inside a function, then this is the
// function Symbol.
stflags_t STflags;
// should probably be inside #if HYDRATE, but unclear for the dmc source
sthflags_t SThflag; // FLAG_XXXX: hydration flag
Classsym *STclasssym; // if in the scope of this class
symlist_t STclasslist; // list of classes that have deferred inline
// functions to parse
Classsym *STstag; // returned by struct_searchmember() and with_search()
SYMIDX STmarksi; // to determine if temporaries are created
ubyte STnoparse; // add to classlist instead of parsing
ubyte STdeferparse; // defer member func parse
SC STgclass; // default function storage class
int STdefertemps; // defer allocation of temps
int STdeferaccesscheck; // defer access check for members (BUG: it
// never does get done later)
int STnewtypeid; // parsing new-type-id
int STdefaultargumentexpression; // parsing default argument expression
block *STbtry; // current try block
block *STgotolist; // threaded goto scoping list
int STtdbtimestamp; // timestamp of tdb file
Symbol *STlastfunc; // last function symbol parsed by ext_def()
// For "point of definition" vs "point of instantiation" template name lookup
uint STsequence; // sequence number (Ssequence) of next Symbol
uint STmaxsequence; // won't find Symbols with STsequence larger
// than STmaxsequence
}
@trusted
void funcsym_p(Funcsym* fp) { pstate.STfuncsym_p = fp; }
@trusted
Funcsym* funcsym_p() { return pstate.STfuncsym_p; }
@trusted
stflags_t preprocessor() { return pstate.STflags & PFLpreprocessor; }
@trusted
stflags_t inline_asm() { return pstate.STflags & (PFLmasm | PFLbasm); }
public import dmd.backend.var : pstate, cstate;
/****************************
* Global variables.
*/
struct Cstate
{
blklst* CSfilblk; // current source file we are parsing
Symbol* CSlinkage; // table of forward referenced linkage pragmas
list_t CSlist_freelist; // free list for list package
symtab_t* CSpsymtab; // pointer to current Symbol table
//#if MEMORYHX
// void **CSphx; // pointer to HX data block
//#endif
char* modname; // module unique identifier
}
/* Bits for sytab[] that give characteristics of storage classes */
enum
{
SCEXP = 1, // valid inside expressions
SCKEP = 2, // Symbol should be kept even when function is done
SCSCT = 4, // storage class is valid for use in static ctor
SCSS = 8, // storage class is on the stack
SCRD = 0x10, // we can do reaching definitions on these
}
// Determine if Symbol has a Ssymnum associated with it.
// (That is, it is allocated on the stack or has live variable analysis
// done on it, so it is stack and register variables.)
//char symbol_isintab(Symbol *s) { return sytab[s.Sclass] & SCSS; }
/******************************************
* Basic blocks:
* Basic blocks are a linked list of all the basic blocks
* in a function. startblock heads the list.
*/
alias ClassDeclaration_ = void*;
alias Declaration_ = void*;
alias Module_ = void*;
struct Blockx
{
block* startblock;
block* curblock;
Funcsym* funcsym;
Symbol* context; // eh frame context variable
int scope_index; // current scope index
int next_index; // value for next scope index
uint flags; // value to OR into Bflags
block* tryblock; // current enclosing try block
ClassDeclaration_ classdec;
Declaration_ member; // member we're compiling for
Module_ _module; // module we're in
}
alias bflags_t = ushort;
enum
{
BFLvisited = 1, // set if block is visited
BFLmark = 2, // set if block is visited
BFLjmpoptdone = 4, // set when no more jump optimizations
// are possible for this block
BFLnostackopt = 8, // set when stack elimination should not
// be done
// NTEXCEPTIONS
BFLehcode = 0x10, // BC_filter: need to load exception code
BFLunwind = 0x1000, // do local_unwind following block (unused)
BFLnomerg = 0x20, // do not merge with other blocks
BFLprolog = 0x80, // generate function prolog
BFLepilog = 0x100, // generate function epilog
BFLrefparam = 0x200, // referenced parameter
BFLreflocal = 0x400, // referenced local
BFLoutsideprolog = 0x800, // outside function prolog/epilog
BFLlabel = 0x2000, // block preceded by label
BFLvolatile = 0x4000, // block is volatile
BFLnounroll = 0x8000, // do not unroll loop
}
struct block
{
nothrow:
union
{
elem *Belem; // pointer to elem tree
list_t Blist; // list of expressions
}
block *Bnext; // pointer to next block in list
list_t Bsucc; // linked list of pointers to successors
// of this block
list_t Bpred; // and the predecessor list
int Bindex; // into created object stack
int Bendindex; // index at end of block
block *Btry; // BCtry,BC_try: enclosing try block, if any
// BC???: if in try-block, points to BCtry or BC_try
// note that can't have a BCtry and BC_try in
// the same function.
union
{
long[] Bswitch; // BCswitch: case expression values
struct
{
regm_t usIasmregs; // Registers modified
ubyte bIasmrefparam; // References parameters?
}
struct
{
Symbol* catchvar; // __throw() fills in this
} // BCtry
struct
{
Symbol* Bcatchtype; // one type for each catch block
Barray!uint* actionTable; // EH_DWARF: indices into typeTable
} // BCjcatch
struct
{
Symbol *jcatchvar; // __d_throw() fills in this
int Bscope_index; // index into scope table
int Blast_index; // enclosing index into scope table
} // BC_try
struct
{
Symbol *flag; // EH_DWARF: set to 'flag' symbol that encloses finally
block *b_ret; // EH_DWARF: associated BC_ret block
} // finally
// add member mimicking the largest of the other elements of this union, so it can be copied
struct _BS { Symbol *jcvar; int Bscope_idx, Blast_idx; }
_BS BS;
}
Srcpos Bsrcpos; // line number (0 if not known)
ubyte BC; // exit condition (enum BC)
ubyte Balign; // alignment
bflags_t Bflags; // flags (BFLxxxx)
code* Bcode; // code generated for this block
uint Bweight; // relative number of times this block
// is executed (optimizer and codegen)
uint Bdfoidx; // index of this block in dfo[]
uint Bnumber; // sequence number of block
union
{
uint _BLU; // start of the union
// CPP
struct
{
SYMIDX Bsymstart; // (symstart <= symnum < symend) Symbols
SYMIDX Bsymend; // are declared in this block
block* Bendscope; // block that forms the end of the
// scope for the declared Symbols
uint Bblknum; // position of block from startblock
Symbol* Binitvar; // !=NULL points to an auto variable with
// an explicit or implicit initializer
block* Bgotolist; // BCtry, BCcatch: backward list of try scopes
block* Bgotothread; // BCgoto: threaded list of goto's to
// unknown labels
}
// OPTIMIZER
struct
{
vec_t Bdom; // mask of dominators for this block
vec_t Binrd;
vec_t Boutrd; // IN and OUT for reaching definitions
vec_t Binlv;
vec_t Boutlv; // IN and OUT for live variables
vec_t Bin;
vec_t Bout; // IN and OUT for other flow analyses
vec_t Bgen;
vec_t Bkill; // pointers to bit vectors used by data
// flow analysis
// BCiftrue can have different vectors for the 2nd successor:
vec_t Bout2;
vec_t Bgen2;
vec_t Bkill2;
}
// CODGEN
struct
{
// For BCswitch, BCjmptab
targ_size_t Btablesize; // size of generated table
targ_size_t Btableoffset; // offset to start of table
targ_size_t Btablebase; // offset to instruction pointer base
targ_size_t Boffset; // code offset of start of this block
targ_size_t Bsize; // code size of this block
con_t Bregcon; // register state at block exit
targ_size_t Btryoff; // BCtry: offset of try block data
}
}
@trusted
void appendSucc(block* b) { list_append(&this.Bsucc, b); }
@trusted
void prependSucc(block* b) { list_prepend(&this.Bsucc, b); }
@trusted
int numSucc() { return list_nitems(this.Bsucc); }
@trusted
block* nthSucc(int n) { return cast(block*)list_ptr(list_nth(Bsucc, n)); }
@trusted
void setNthSucc(int n, block *b) { list_nth(Bsucc, n).ptr = b; }
}
@trusted
inout(block)* list_block(inout list_t lst) { return cast(inout(block)*)list_ptr(lst); }
/** Basic block control flow operators. **/
alias BC = int;
enum
{
BCgoto = 1, // goto Bsucc block
BCiftrue = 2, // if (Belem) goto Bsucc[0] else Bsucc[1]
BCret = 3, // return (no return value)
BCretexp = 4, // return with return value
BCexit = 5, // never reaches end of block (like exit() was called)
BCasm = 6, // inline assembler block (Belem is NULL, Bcode
// contains code generated).
// These blocks have one or more successors in Bsucc,
// never 0
BCswitch = 7, // switch statement
// Bswitch points to switch data
// Default is Bsucc
// Cases follow in linked list
BCifthen = 8, // a BCswitch is converted to if-then
// statements
BCjmptab = 9, // a BCswitch is converted to a jump
// table (switch value is index into
// the table)
BCtry = 10, // C++ try block
// first block in a try-block. The first block in
// Bsucc is the next one to go to, subsequent
// blocks are the catch blocks
BCcatch = 11, // C++ catch block
BCjump = 12, // Belem specifies (near) address to jump to
BC_try = 13, // SEH: first block of try-except or try-finally
// D: try-catch or try-finally
BC_filter = 14, // SEH exception-filter (always exactly one block)
BC_finally = 15, // first block of SEH termination-handler,
// or D finally block
BC_ret = 16, // last block of SEH termination-handler or D _finally block
BC_except = 17, // first block of SEH exception-handler
BCjcatch = 18, // D catch block
BC_lpad = 19, // EH_DWARF: landing pad for BC_except
BCMAX
}
/********************************
* Range for blocks.
*/
struct BlockRange
{
pure nothrow @nogc:
this(block* b)
{
this.b = b;
}
block* front() return { return b; }
void popFront() { b = b.Bnext; }
bool empty() const { return !b; }
private:
block* b;
}
/**********************************
* Functions
*/
alias func_flags_t = uint;
enum
{
Fpending = 1, // if function has been queued for being written
Foutput = 2, // if function has been written out
Foperator = 4, // if operator overload
Fcast = 8, // if cast overload
Finline = 0x10, // if SCinline, and function really is inline
Foverload = 0x20, // if function can be overloaded
Ftypesafe = 0x40, // if function name needs type appended
Fmustoutput = 0x80, // set for forward ref'd functions that
// must be output
Fvirtual = 0x100, // if function is a virtual function
Fctor = 0x200, // if function is a constructor
Fdtor = 0x400, // if function is a destructor
Fnotparent = 0x800, // if function is down Foversym chain
Finlinenest = 0x1000, // used as a marker to prevent nested
// inlines from expanding
Flinkage = 0x2000, // linkage is already specified
Fstatic = 0x4000, // static member function (no this)
Fbitcopy = 0x8000, // it's a simple bitcopy (op=() or X(X&))
Fpure = 0x10000, // pure function
Finstance = 0x20000, // function is an instance of a template
Ffixed = 0x40000, // ctor has had cpp_fixconstructor() run on it,
// dtor has had cpp_fixdestructor()
Fintro = 0x80000, // function doesn't hide a previous virtual function
// unused = 0x100000, // unused bit
Fkeeplink = 0x200000, // don't change linkage to default
Fnodebug = 0x400000, // do not generate debug info for this function
Fgen = 0x800000, // compiler generated function
Finvariant = 0x1000000, // __invariant function
Fexplicit = 0x2000000, // explicit constructor
Fsurrogate = 0x4000000, // surrogate call function
}
alias func_flags3_t = uint;
enum
{
Fvtblgen = 1, // generate vtbl[] when this function is defined
Femptyexc = 2, // empty exception specification (obsolete, use Tflags & TFemptyexc)
Fcppeh = 4, // uses C++ EH
Fnteh = 8, // uses NT Structured EH
Fdeclared = 0x10, // already declared function Symbol
Fmark = 0x20, // has unbalanced OPctor's
Fdoinline = 0x40, // do inline walk
Foverridden = 0x80, // ignore for overriding purposes
Fjmonitor = 0x100, // Mars synchronized function
Fnosideeff = 0x200, // function has no side effects
F3badoparrow = 0x400, // bad operator->()
Fmain = 0x800, // function is D main
Fnested = 0x1000, // D nested function with 'this'
Fmember = 0x2000, // D member function with 'this'
Fnotailrecursion = 0x4000, // no tail recursion optimizations
Ffakeeh = 0x8000, // allocate space for NT EH context sym anyway
Fnothrow = 0x10000, // function does not throw (even if not marked 'nothrow')
Feh_none = 0x20000, // ehmethod==EH_NONE for this function only
F3hiddenPtr = 0x40000, // function has hidden pointer to return value
F3safe = 0x80000, // function is @safe
}
struct func_t
{
symlist_t Fsymtree; // local Symbol table
block *Fstartblock; // list of blocks comprising function
symtab_t Flocsym; // local Symbol table
Srcpos Fstartline; // starting line # of function
Srcpos Fendline; // line # of closing brace of function
Symbol *F__func__; // symbol for __func__[] string
func_flags_t Fflags;
func_flags3_t Fflags3;
ubyte Foper; // operator number (OPxxxx) if Foperator
Symbol *Fparsescope; // use this scope to parse friend functions
// which are defined within a class, so the
// class is in scope, but are not members
// of the class
Classsym *Fclass; // if member of a class, this is the class
// (I think this is redundant with Sscope)
Funcsym *Foversym; // overloaded function at same scope
symlist_t Fclassfriends; // Symbol list of classes of which this
// function is a friend
block *Fbaseblock; // block where base initializers get attached
block *Fbaseendblock; // block where member destructors get attached
elem *Fbaseinit; // list of member initializers (meminit_t)
// this field has meaning only for
// functions which are constructors
token_t *Fbody; // if deferred parse, this is the list
// of tokens that make up the function
// body
// also used if SCfunctempl, SCftexpspec
uint Fsequence; // sequence number at point of definition
union
{
Symbol* Ftempl; // if Finstance this is the template that generated it
Thunk* Fthunk; // !=NULL if this function is actually a thunk
}
Funcsym *Falias; // SCfuncalias: function Symbol referenced
// by using-declaration
symlist_t Fthunks; // list of thunks off of this function
param_t *Farglist; // SCfunctempl: the template-parameter-list
param_t *Fptal; // Finstance: this is the template-argument-list
// SCftexpspec: for explicit specialization, this
// is the template-argument-list
list_t Ffwdrefinstances; // SCfunctempl: list of forward referenced instances
list_t Fexcspec; // List of types in the exception-specification
// (NULL if none or empty)
Funcsym *Fexplicitspec; // SCfunctempl, SCftexpspec: threaded list
// of SCftexpspec explicit specializations
Funcsym *Fsurrogatesym; // Fsurrogate: surrogate cast function
char *Fredirect; // redirect function name to this name in object
// Array of catch types for EH_DWARF Types Table generation
Barray!(Symbol*) typesTable;
union
{
uint LSDAoffset; // ELFOBJ: offset in LSDA segment of the LSDA data for this function
Symbol* LSDAsym; // MACHOBJ: GCC_except_table%d
}
}
//func_t* func_calloc() { return cast(func_t *) mem_fcalloc(func_t.sizeof); }
//void func_free(func_t *f) { mem_ffree(f); }
/**************************
* Item in list for member initializer.
*/
struct meminit_t
{
list_t MIelemlist; // arg list for initializer
Symbol *MIsym; // if NULL, then this initializer is
// for the base class. Otherwise, this
// is the member that needs the ctor
// called for it
}
alias baseclass_flags_t = uint;
enum
{
BCFpublic = 1, // base class is public
BCFprotected = 2, // base class is protected
BCFprivate = 4, // base class is private
BCFvirtual = 8, // base class is virtual
BCFvfirst = 0x10, // virtual base class, and this is the
// first virtual appearance of it
BCFnewvtbl = 0x20, // new vtbl generated for this base class
BCFvirtprim = 0x40, // Primary base class of a virtual base class
BCFdependent = 0x80, // base class is a dependent type
}
enum baseclass_flags_t BCFpmask = BCFpublic | BCFprotected | BCFprivate;
/************************************
* Base classes are a list of these.
*/
struct baseclass_t
{
Classsym* BCbase; // base class Symbol
baseclass_t* BCnext; // next base class
targ_size_t BCoffset; // offset from start of derived class to this
ushort BCvbtbloff; // for BCFvirtual, offset from start of
// vbtbl[] to entry for this virtual base.
// Valid in Sbase list
symlist_t BCpublics; // public members of base class (list is freeable)
list_t BCmptrlist; // (in Smptrbase only) this is the vtbl
// (NULL if not different from base class's vtbl
Symbol* BCvtbl; // Symbol for vtbl[] array (in Smptrbase list)
// Symbol for vbtbl[] array (in Svbptrbase list)
baseclass_flags_t BCflags; // base class flags
Classsym* BCparent; // immediate parent of this base class
// in Smptrbase
baseclass_t* BCpbase; // parent base, NULL if did not come from a parent
}
//baseclass_t* baseclass_malloc() { return cast(baseclass_t*) mem_fmalloc(baseclass_t.sizeof); }
void baseclass_free(baseclass_t *b) { }
/*************************
* For virtual tables.
*/
alias mptr_flags_t = char;
enum
{
MPTRvirtual = 1, // it's an offset to a virtual base
MPTRcovariant = 2, // need covariant return pointer adjustment
}
struct mptr_t
{
targ_short MPd;
targ_short MPi;
Symbol *MPf;
Symbol *MPparent; // immediate parent of this base class
// in Smptrbase
mptr_flags_t MPflags;
}
@trusted
inout(mptr_t)* list_mptr(inout(list_t) lst) { return cast(inout(mptr_t)*) list_ptr(lst); }
/***********************************
* Information gathered about externally defined template member functions,
* member data, and member classes.
*/
struct TMF
{
Classsym *stag; // if !=NULL, this is the enclosing class
token_t *tbody; // tokens making it up
token_t *to; // pointer within tbody where we left off in
// template_function_decl()
param_t *temp_arglist; // template parameter list
int member_class; // 1: it's a member class
// These are for member templates
int castoverload; // 1: it's a user defined cast
char *name; // name of template (NULL if castoverload)
int member_template; // 0: regular template
// 1: member template
param_t *temp_arglist2; // if member template,
// then member's template parameter list
param_t *ptal; // if explicit specialization, this is the
// explicit template-argument-list
Symbol *sclassfriend; // if member function is a friend of class X,
// this is class X
uint access_specifier;
}
/***********************************
* Information gathered about primary member template explicit specialization.
*/
struct TME
{
/* Given:
* template<> template<class T2> struct A<short>::B { };
* temp_arglist2 = <class T2>
* name = "B"
* ptal = <short>
*/
param_t *ptal; // explicit template-argument-list for enclosing
// template A
Symbol *stempl; // template symbol for B
}
/***********************************
* Information gathered about nested explicit specializations.
*/
struct TMNE
{
/* For:
* template<> template<> struct A<short>::B<double> { };
*/
enum_TK tk; // TKstruct / TKclass / TKunion
char *name; // name of template, i.e. "B"
param_t *ptal; // explicit template-argument-list for enclosing
// template A, i.e. "short"
token_t *tdecl; // the tokens "<double> { }"
}
/***********************************
* Information gathered about nested class friends.
*/
struct TMNF
{
/* Given:
* template<class T> struct A { struct B { }; };
* class C { template<class T> friend struct A<T>::B;
*/
token_t *tdecl; // the tokens "A<T>::B;"
param_t *temp_arglist; // <class T>
Classsym *stag; // the class symbol C
Symbol *stempl; // the template symbol A
}
/***********************************
* Special information for class templates.
*/
struct template_t
{
symlist_t TMinstances; // list of Symbols that are instances
param_t* TMptpl; // template-parameter-list
token_t* TMbody; // tokens making up class body
uint TMsequence; // sequence number at point of definition
list_t TMmemberfuncs; // templates for member functions (list of TMF's)
list_t TMexplicit; // list of TME's: primary member template explicit specializations
list_t TMnestedexplicit; // list of TMNE's: primary member template nested explicit specializations
Symbol* TMnext; // threaded list of template classes headed
// up by template_class_list
enum_TK TMtk; // TKstruct, TKclass or TKunion
int TMflags; // STRxxx flags
Symbol* TMprimary; // primary class template
Symbol* TMpartial; // next class template partial specialization
param_t* TMptal; // template-argument-list for partial specialization
// (NULL for primary class template)
list_t TMfriends; // list of Classsym's for which any instantiated
// classes of this template will be friends of
list_t TMnestedfriends; // list of TMNF's
int TMflags2; // !=0 means dummy template created by template_createargtab()
}
/***********************************
* Special information for enums.
*/
alias enum_flags_t = uint;
enum
{
SENnotagname = 1, // no tag name for enum
SENforward = 2, // forward referenced enum
}
struct enum_t
{
enum_flags_t SEflags;
Symbol* SEalias; // pointer to identifier E to use if
// enum was defined as:
// typedef enum { ... } E;
symlist_t SEenumlist; // all members of enum
}
/***********************************
* Special information for structs.
*/
alias struct_flags_t = uint;
enum
{
STRanonymous = 1, // set for unions with no tag names
STRglobal = 2, // defined at file scope
STRnotagname = 4, // struct/class with no tag name
STRoutdef = 8, // we've output the debug definition
STRbitfields = 0x10, // set if struct contains bit fields
STRabstract = 0x20, // abstract class
STRbitcopy = 0x40, // set if operator=() is merely a bit copy
STRanyctor = 0x80, // set if any constructors were defined
// by the user
STRnoctor = 0x100, // no constructors allowed
STRgen = 0x200, // if struct is an instantiation of a
// template class, and was generated by
// that template
STRvtblext = 0x400, // generate vtbl[] only when first member function
// definition is encountered (see Fvtblgen)
STRexport = 0x800, // all member functions are to be _export
STRpredef = 0x1000, // a predefined struct
STRunion = 0x2000, // actually, it's a union
STRclass = 0x4000, // it's a class, not a struct
STRimport = 0x8000, // imported class
STRstaticmems = 0x10000, // class has static members
STR0size = 0x20000, // zero sized struct
STRinstantiating = 0x40000, // if currently being instantiated
STRexplicit = 0x80000, // if explicit template instantiation
STRgenctor0 = 0x100000, // need to gen X::X()
STRnotpod = 0x200000, // struct is not POD
}
struct struct_t
{
targ_size_t Sstructsize; // size of struct
symlist_t Sfldlst; // all members of struct (list freeable)
Symbol *Sroot; // root of binary tree Symbol table
uint Salignsize; // size of struct for alignment purposes
ubyte Sstructalign; // struct member alignment in effect
struct_flags_t Sflags;
tym_t ptrtype; // type of pointer to refer to classes by
ushort access; // current access privilege, here so
// enum declarations can get at it
targ_size_t Snonvirtsize; // size of struct excluding virtual classes
list_t Svirtual; // freeable list of mptrs
// that go into vtbl[]
list_t *Spvirtder; // pointer into Svirtual that points to start
// of virtual functions for this (derived) class
symlist_t Sopoverload; // overloaded operator funcs (list freeable)
symlist_t Scastoverload; // overloaded cast funcs (list freeable)
symlist_t Sclassfriends; // list of classes of which this is a friend
// (list is freeable)
symlist_t Sfriendclass; // classes which are a friend to this class
// (list is freeable)
symlist_t Sfriendfuncs; // functions which are a friend to this class
// (list is freeable)
symlist_t Sinlinefuncs; // list of tokenized functions
baseclass_t *Sbase; // list of direct base classes
baseclass_t *Svirtbase; // list of all virtual base classes
baseclass_t *Smptrbase; // list of all base classes that have
// their own vtbl[]
baseclass_t *Sprimary; // if not NULL, then points to primary
// base class
Funcsym *Svecctor; // constructor for use by vec_new()
Funcsym *Sctor; // constructor function
Funcsym *Sdtor; // basic destructor
Funcsym *Sprimdtor; // primary destructor
Funcsym *Spriminv; // primary invariant
Funcsym *Sscaldeldtor; // scalar deleting destructor
Funcsym *Sinvariant; // basic invariant function
Symbol *Svptr; // Symbol of vptr
Symbol *Svtbl; // Symbol of vtbl[]
Symbol *Svbptr; // Symbol of pointer to vbtbl[]
Symbol *Svbptr_parent; // base class for which Svbptr is a member.
// NULL if Svbptr is a member of this class
targ_size_t Svbptr_off; // offset of Svbptr member
Symbol *Svbtbl; // virtual base offset table
baseclass_t *Svbptrbase; // list of all base classes in canonical
// order that have their own vbtbl[]
Funcsym *Sopeq; // X& X::operator =(X&)
Funcsym *Sopeq2; // Sopeq, but no copy of virtual bases
Funcsym *Scpct; // copy constructor
Funcsym *Sveccpct; // vector copy constructor
Symbol *Salias; // pointer to identifier S to use if
// struct was defined as:
// typedef struct { ... } S;
Symbol *Stempsym; // if this struct is an instantiation
// of a template class, this is the
// template class Symbol
// For 64 bit Elf function ABI
type *Sarg1type;
type *Sarg2type;
/* For:
* template<class T> struct A { };
* template<class T> struct A<T *> { };
*
* A<int> a; // primary
* Gives:
* Sarglist = <int>
* Spr_arglist = NULL;
*
* A<int*> a; // specialization
* Gives:
* Sarglist = <int>
* Spr_arglist = <int*>;
*/
param_t *Sarglist; // if this struct is an instantiation