aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/declaration.h
blob: bc8db441e60d007ec702c08d1349d28827823d0a (plain)
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

/* Compiler implementation of the D programming language
 * Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
 * written by Walter Bright
 * https://www.digitalmars.com
 * Distributed under the Boost Software License, Version 1.0.
 * https://www.boost.org/LICENSE_1_0.txt
 * https://github.com/dlang/dmd/blob/master/src/dmd/declaration.h
 */

#pragma once

#include "dsymbol.h"
#include "mtype.h"
#include "objc.h"
#include "tokens.h"

class Expression;
class Statement;
class LabelDsymbol;
class Initializer;
class ForeachStatement;
struct Ensure
{
    Identifier *id;
    Statement *ensure;
};
class FuncDeclaration;
class StructDeclaration;
struct IntRange;
struct AttributeViolation;

//enum STC : ulong from astenums.d:

    #define STCundefined          0ULL

    #define STCstatic             1ULL    /// `static`
    #define STCextern             2ULL    /// `extern`
    #define STCconst              4ULL    /// `const`
    #define STCfinal              8ULL    /// `final`

    #define STCabstract           0x10ULL    /// `abstract`
    #define STCparameter          0x20ULL    /// is function parameter
    #define STCfield              0x40ULL    /// is field of struct, union or class
    #define STCoverride           0x80ULL    /// `override`

    #define STCauto               0x100ULL    /// `auto`
    #define STCsynchronized       0x200ULL    /// `synchronized`
    #define STCdeprecated         0x400ULL    /// `deprecated`
    #define STCin                 0x800ULL    /// `in` parameter

    #define STCout                0x1000ULL    /// `out` parameter
    #define STClazy               0x2000ULL    /// `lazy` parameter
    #define STCforeach            0x4000ULL    /// variable for foreach loop
    #define STCvariadic           0x8000ULL    /// the `variadic` parameter in: T foo(T a, U b, V variadic...)

    //                            0x10000ULL
    #define STCtemplateparameter  0x20000ULL    /// template parameter
    #define STCref                0x40000ULL    /// `ref`
    #define STCscope              0x80000ULL    /// `scope`

    #define STCscopeinferred      0x200000ULL    /// `scope` has been inferred and should not be part of mangling, `scope` must also be set
    #define STCreturn             0x400000ULL    /// 'return ref' or 'return scope' for function parameters
    #define STCreturnScope        0x800000ULL    /// if `ref return scope` then resolve to `ref` and `return scope`

    #define STCreturninferred     0x1000000ULL    /// `return` has been inferred and should not be part of mangling, `return` must also be set
    #define STCimmutable          0x2000000ULL    /// `immutable`
    //                            0x4000000ULL
    #define STCmanifest           0x8000000ULL    /// manifest constant

    #define STCnodtor             0x10000000ULL    /// do not run destructor
    #define STCnothrow            0x20000000ULL    /// `nothrow` meaning never throws exceptions
    #define STCpure               0x40000000ULL    /// `pure` function

    #define STCalias              0x100000000ULL    /// `alias` parameter
    #define STCshared             0x200000000ULL    /// accessible from multiple threads
    #define STCgshared            0x400000000ULL    /// accessible from multiple threads, but not typed as `shared`
    #define STCwild               0x800000000ULL    /// for wild type constructor

    #define STCproperty           0x1000000000ULL    /// `@property`
    #define STCsafe               0x2000000000ULL    /// `@safe`
    #define STCtrusted            0x4000000000ULL    /// `@trusted`
    #define STCsystem             0x8000000000ULL    /// `@system`

    #define STCctfe               0x10000000000ULL    /// can be used in CTFE, even if it is static
    #define STCdisable            0x20000000000ULL    /// for functions that are not callable
    #define STCresult             0x40000000000ULL    /// for result variables passed to out contracts
    #define STCnodefaultctor      0x80000000000ULL    /// must be set inside constructor

    #define STCtemp               0x100000000000ULL    /// temporary variable
    #define STCrvalue             0x200000000000ULL    /// force rvalue for variables
    #define STCnogc               0x400000000000ULL    /// `@nogc`
    #define STCautoref            0x800000000000ULL    /// Mark for the already deduced `auto ref` parameter

    #define STCinference          0x1000000000000ULL    /// do attribute inference
    #define STCexptemp            0x2000000000000ULL    /// temporary variable that has lifetime restricted to an expression
    #define STCfuture             0x4000000000000ULL    /// introducing new base class function
    #define STClocal              0x8000000000000ULL    /// do not forward (see dmd.dsymbol.ForwardingScopeDsymbol).

    #define STClive               0x10000000000000ULL    /// function `@live` attribute
    #define STCregister           0x20000000000000ULL    /// `register` storage class (ImportC)
    #define STCvolatile           0x40000000000000ULL    /// destined for volatile in the back end

#define STC_TYPECTOR    (STCconst | STCimmutable | STCshared | STCwild)
#define STC_FUNCATTR    (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem)

void ObjectNotFound(Identifier *id);

/**************************************************************/

class Declaration : public Dsymbol
{
public:
    Type *type;
    Type *originalType;         // before semantic analysis
    StorageClass storage_class;
    Visibility visibility;
    LINK _linkage;              // may be `LINK::system`; use `resolvedLinkage()` to resolve it
    short inuse;                // used to detect cycles
    uint8_t adFlags;
    Symbol* isym;               // import version of csym
    DString mangleOverride;     // overridden symbol with pragma(mangle, "...")

    const char *kind() const override;
    uinteger_t size(const Loc &loc) override final;

    Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override final;

    bool isStatic() const { return (storage_class & STCstatic) != 0; }
    LINK resolvedLinkage() const; // returns the linkage, resolving the target-specific `System` one
    virtual bool isDelete();
    virtual bool isDataseg();
    virtual bool isThreadlocal();
    virtual bool isCodeseg() const;
    bool isFinal() const        { return (storage_class & STCfinal) != 0; }
    virtual bool isAbstract()   { return (storage_class & STCabstract) != 0; }
    bool isConst() const        { return (storage_class & STCconst) != 0; }
    bool isImmutable() const    { return (storage_class & STCimmutable) != 0; }
    bool isWild() const         { return (storage_class & STCwild) != 0; }
    bool isAuto() const         { return (storage_class & STCauto) != 0; }
    bool isScope() const        { return (storage_class & STCscope) != 0; }
    bool isSynchronized() const { return (storage_class & STCsynchronized) != 0; }
    bool isParameter() const    { return (storage_class & STCparameter) != 0; }
    bool isDeprecated() const override final { return (storage_class & STCdeprecated) != 0; }
    bool isOverride() const     { return (storage_class & STCoverride) != 0; }
    bool isResult() const       { return (storage_class & STCresult) != 0; }
    bool isField() const        { return (storage_class & STCfield) != 0; }

    bool isIn()  const  { return (storage_class & STCin) != 0; }
    bool isOut() const  { return (storage_class & STCout) != 0; }
    bool isRef() const  { return (storage_class & STCref) != 0; }
    bool isReference() const { return (storage_class & (STCref | STCout)) != 0; }

    bool isFuture() const { return (storage_class & STCfuture) != 0; }

    Visibility visible() override final;

    Declaration *isDeclaration() override final { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class TupleDeclaration final : public Declaration
{
public:
    Objects *objects;
    TypeTuple *tupletype;       // !=NULL if this is a type tuple
    bool isexp;                 // true: expression tuple
    bool building;              // it's growing in AliasAssign semantic

    TupleDeclaration *syntaxCopy(Dsymbol *) override;
    const char *kind() const override;
    Type *getType() override;
    Dsymbol *toAlias2() override;
    bool needThis() override;

    TupleDeclaration *isTupleDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class AliasDeclaration final : public Declaration
{
public:
    Dsymbol *aliassym;
    Dsymbol *overnext;          // next in overload list
    Dsymbol *_import;           // !=NULL if unresolved internal alias for selective import

    static AliasDeclaration *create(const Loc &loc, Identifier *id, Type *type);
    AliasDeclaration *syntaxCopy(Dsymbol *) override;
    bool overloadInsert(Dsymbol *s) override;
    const char *kind() const override;
    Type *getType() override;
    Dsymbol *toAlias() override;
    Dsymbol *toAlias2() override;
    bool isOverloadable() const override;

    AliasDeclaration *isAliasDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class OverDeclaration final : public Declaration
{
public:
    Dsymbol *overnext;          // next in overload list
    Dsymbol *aliassym;

    const char *kind() const override;
    bool equals(const RootObject *o) const override;
    bool overloadInsert(Dsymbol *s) override;

    Dsymbol *toAlias() override;
    Dsymbol *isUnique();
    bool isOverloadable() const override;

    OverDeclaration *isOverDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class VarDeclaration : public Declaration
{
public:
    Initializer *_init;
    FuncDeclarations nestedrefs; // referenced by these lexically nested functions
    Dsymbol *aliassym;          // if redone as alias to another symbol
    VarDeclaration *lastVar;    // Linked list of variables for goto-skips-init detection
    Expression *edtor;          // if !=NULL, does the destruction of the variable
    IntRange *range;            // if !NULL, the variable is known to be within the range
    VarDeclarations *maybes;    // STCmaybescope variables that are assigned to this STCmaybescope variable

    unsigned endlinnum;         // line number of end of scope that this var lives in
    unsigned offset;
    unsigned sequenceNumber;     // order the variables are declared
    structalign_t alignment;

    // When interpreting, these point to the value (NULL if value not determinable)
    // The index of this variable on the CTFE stack, ~0u if not allocated
    unsigned ctfeAdrOnStack;
private:
    uint16_t bitFields;
public:
    int8_t canassign; // // it can be assigned to
    uint8_t isdataseg; // private data for isDataseg
    bool isargptr() const; // if parameter that _argptr points to
    bool isargptr(bool v);
    bool ctorinit() const; // it has been initialized in a ctor
    bool ctorinit(bool v);
    bool iscatchvar() const; // this is the exception object variable in catch() clause
    bool iscatchvar(bool v);
    bool isowner() const; // this is an Owner, despite it being `scope`
    bool isowner(bool v);
    bool setInCtorOnly() const; // field can only be set in a constructor, as it is const or immutable
    bool setInCtorOnly(bool v);
    bool onstack() const; // it is a class that was allocated on the stack
    bool onstack(bool v);
    bool overlapped() const; // if it is a field and has overlapping
    bool overlapped(bool v);
    bool overlapUnsafe() const; // if it is an overlapping field and the overlaps are unsafe
    bool overlapUnsafe(bool v);
    bool maybeScope() const; // allow inferring 'scope' for this variable
    bool maybeScope(bool v);
    bool doNotInferReturn() const; // do not infer 'return' for this variable
    bool doNotInferReturn(bool v);
    bool isArgDtorVar() const; // temporary created to handle scope destruction of a function argument
    bool isArgDtorVar(bool v);
    static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
    VarDeclaration *syntaxCopy(Dsymbol *) override;
    void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
    const char *kind() const override;
    AggregateDeclaration *isThis() override final;
    bool needThis() override final;
    bool isExport() const override final;
    bool isImportedSymbol() const override final;
    bool isCtorinit() const;
    bool isDataseg() override final;
    bool isThreadlocal() override final;
    bool isCTFE();
    bool isOverlappedWith(VarDeclaration *v);
    bool hasPointers() override final;
    bool canTakeAddressOf();
    bool needsScopeDtor();
    void checkCtorConstInit() override final;
    Dsymbol *toAlias() override final;
    // Eliminate need for dynamic_cast
    VarDeclaration *isVarDeclaration() override final { return (VarDeclaration *)this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class BitFieldDeclaration : public VarDeclaration
{
public:
    Expression *width;

    unsigned fieldWidth;
    unsigned bitOffset;

    BitFieldDeclaration *syntaxCopy(Dsymbol *) override;
    BitFieldDeclaration *isBitFieldDeclaration() override final { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

// This is a shell around a back end symbol

class SymbolDeclaration final : public Declaration
{
public:
    AggregateDeclaration *dsym;

    // Eliminate need for dynamic_cast
    SymbolDeclaration *isSymbolDeclaration() override { return (SymbolDeclaration *)this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoDeclaration : public VarDeclaration
{
public:
    Type *tinfo;

    static TypeInfoDeclaration *create(Type *tinfo);
    TypeInfoDeclaration *syntaxCopy(Dsymbol *) override final;
    const char *toChars() const override final;

    TypeInfoDeclaration *isTypeInfoDeclaration() override final { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoStructDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoStructDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoClassDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoClassDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoInterfaceDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoInterfaceDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoPointerDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoPointerDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoArrayDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoArrayDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoStaticArrayDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoStaticArrayDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoAssociativeArrayDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoAssociativeArrayDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoEnumDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoEnumDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoFunctionDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoFunctionDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoDelegateDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoDelegateDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoTupleDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoTupleDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoConstDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoConstDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoInvariantDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoInvariantDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoSharedDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoSharedDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoWildDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoWildDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

class TypeInfoVectorDeclaration final : public TypeInfoDeclaration
{
public:
    static TypeInfoVectorDeclaration *create(Type *tinfo);

    void accept(Visitor *v) override { v->visit(this); }
};

/**************************************************************/

class ThisDeclaration final : public VarDeclaration
{
public:
    ThisDeclaration *syntaxCopy(Dsymbol *) override;
    ThisDeclaration *isThisDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

enum class ILS : unsigned char
{
    ILSuninitialized,   // not computed yet
    ILSno,              // cannot inline
    ILSyes              // can inline
};

/**************************************************************/

enum class BUILTIN : unsigned char
{
    unknown = 255,   /// not known if this is a builtin
    unimp = 0,       /// this is not a builtin
    gcc,             /// this is a GCC builtin
    llvm,            /// this is an LLVM builtin
    sin,
    cos,
    tan,
    sqrt,
    fabs,
    ldexp,
    log,
    log2,
    log10,
    exp,
    expm1,
    exp2,
    round,
    floor,
    ceil,
    trunc,
    copysign,
    pow,
    fmin,
    fmax,
    fma,
    isnan,
    isinfinity,
    isfinite,
    bsf,
    bsr,
    bswap,
    popcnt,
    yl2x,
    yl2xp1,
    toPrecFloat,
    toPrecDouble,
    toPrecReal
};

Expression *eval_builtin(const Loc &loc, FuncDeclaration *fd, Expressions *arguments);
BUILTIN isBuiltin(FuncDeclaration *fd);

class FuncDeclaration : public Declaration
{
public:
    Statements *frequires;              // in contracts
    Ensures *fensures;                  // out contracts
    Statement *frequire;                // lowered in contract
    Statement *fensure;                 // lowered out contract
    Statement *fbody;

    FuncDeclarations foverrides;        // functions this function overrides
    FuncDeclaration *fdrequire;         // function that does the in contract
    FuncDeclaration *fdensure;          // function that does the out contract

    Expressions *fdrequireParams;       // argument list for __require
    Expressions *fdensureParams;        // argument list for __ensure

    const char *mangleString;           // mangled symbol created from mangleExact()

    VarDeclaration *vresult;            // result variable for out contracts
    LabelDsymbol *returnLabel;          // where the return goes

    void *isTypeIsolatedCache;          // An AA on the D side to cache an expensive check result

    // used to prevent symbols in different
    // scopes from having the same name
    DsymbolTable *localsymtab;
    VarDeclaration *vthis;              // 'this' parameter (member and nested)
    VarDeclaration *v_arguments;        // '_arguments' parameter

    VarDeclaration *v_argptr;           // '_argptr' variable
    VarDeclarations *parameters;        // Array of VarDeclaration's for parameters
    DsymbolTable *labtab;               // statement label symbol table
    Dsymbol *overnext;                  // next in overload list
    FuncDeclaration *overnext0;         // next in overload list (only used during IFTI)
    Loc endloc;                         // location of closing curly bracket
    int vtblIndex;                      // for member functions, index into vtbl[]

    ILS inlineStatusStmt;
    ILS inlineStatusExp;
    PINLINE inlining;

    int inlineNest;                     // !=0 if nested inline

    // true if errors in semantic3 this function's frame ptr
    ForeachStatement *fes;              // if foreach body, this is the foreach
    BaseClass* interfaceVirtual;        // if virtual, but only appears in interface vtbl[]
    // if !=NULL, then this is the type
    // of the 'introducing' function
    // this one is overriding
    Type *tintro;
    StorageClass storage_class2;        // storage class for template onemember's

    // Things that should really go into Scope

    // 1 if there's a return exp; statement
    // 2 if there's a throw statement
    // 4 if there's an assert(0)
    // 8 if there's inline asm
    // 16 if there are multiple return statements
    int hasReturnExp;

    VarDeclaration *nrvo_var;           // variable to replace with shidden
    Symbol *shidden;                    // hidden pointer passed to function

    ReturnStatements *returns;

    GotoStatements *gotos;              // Gotos with forward references

    // set if this is a known, builtin function we can evaluate at compile time
    BUILTIN builtin;

    // set if someone took the address of this function
    int tookAddressOf;
    bool requiresClosure;               // this function needs a closure

    // local variables in this function which are referenced by nested functions
    VarDeclarations closureVars;

    /** Outer variables which are referenced by this nested function
     * (the inverse of closureVars)
     */
    VarDeclarations outerVars;

    // Sibling nested functions which called this one
    FuncDeclarations siblingCallers;

    FuncDeclarations *inlinedNestedCallees;

    AttributeViolation* safetyViolation;

    unsigned flags;                     // FUNCFLAGxxxxx

    // Data for a function declaration that is needed for the Objective-C
    // integration.
    ObjcFuncDeclaration objc;

    static FuncDeclaration *create(const Loc &loc, const Loc &endloc, Identifier *id, StorageClass storage_class, Type *type, bool noreturn = false);
    FuncDeclaration *syntaxCopy(Dsymbol *) override;
    bool functionSemantic();
    bool functionSemantic3();
    bool equals(const RootObject *o) const override final;

    int overrides(FuncDeclaration *fd);
    int findVtblIndex(Dsymbols *vtbl, int dim);
    BaseClass *overrideInterface();
    bool overloadInsert(Dsymbol *s) override;
    bool inUnittest();
    MATCH leastAsSpecialized(FuncDeclaration *g);
    LabelDsymbol *searchLabel(Identifier *ident, const Loc &loc);
    int getLevel(FuncDeclaration *fd, int intypeof); // lexical nesting level difference
    int getLevelAndCheck(const Loc &loc, Scope *sc, FuncDeclaration *fd);
    const char *toPrettyChars(bool QualifyTypes = false) override;
    const char *toFullSignature();  // for diagnostics, e.g. 'int foo(int x, int y) pure'
    bool isMain() const;
    bool isCMain() const;
    bool isWinMain() const;
    bool isDllMain() const;
    bool isExport() const override final;
    bool isImportedSymbol() const override final;
    bool isCodeseg() const override final;
    bool isOverloadable() const override final;
    bool isAbstract() override final;
    PURE isPure();
    PURE isPureBypassingInference();
    bool isSafe();
    bool isSafeBypassingInference();
    bool isTrusted();

    bool isNogc();
    bool isNogcBypassingInference();
    bool isNRVO() const;
    void isNRVO(bool v);
    bool isNaked() const;
    void isNaked(bool v);
    bool isGenerated() const;
    void isGenerated(bool v);
    bool isIntroducing() const;
    bool hasSemantic3Errors() const;
    bool hasNoEH() const;
    bool inferRetType() const;
    bool hasDualContext() const;
    bool hasAlwaysInlines() const;
    bool isCrtCtor() const;
    void isCrtCtor(bool v);
    bool isCrtDtor() const;
    void isCrtDtor(bool v);

    virtual bool isNested() const;
    AggregateDeclaration *isThis() override;
    bool needThis() override final;
    bool isVirtualMethod();
    virtual bool isVirtual() const;
    bool isFinalFunc() const;
    virtual bool addPreInvariant();
    virtual bool addPostInvariant();
    const char *kind() const override;
    bool isUnique();
    bool needsClosure();
    bool checkClosure();
    bool hasNestedFrameRefs();
    ParameterList getParameterList();

    static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name, StorageClass stc=0);
    static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id, StorageClass stc=0);

    bool checkNRVO();

    FuncDeclaration *isFuncDeclaration() override final { return this; }

    virtual FuncDeclaration *toAliasFunc() { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class FuncAliasDeclaration final : public FuncDeclaration
{
public:
    FuncDeclaration *funcalias;
    bool hasOverloads;

    FuncAliasDeclaration *isFuncAliasDeclaration() override { return this; }
    const char *kind() const override;

    FuncDeclaration *toAliasFunc() override;
    void accept(Visitor *v) override { v->visit(this); }
};

class FuncLiteralDeclaration final : public FuncDeclaration
{
public:
    TOK tok;                       // TOKfunction or TOKdelegate
    Type *treq;                         // target of return type inference

    // backend
    bool deferToObj;

    FuncLiteralDeclaration *syntaxCopy(Dsymbol *) override;
    bool isNested() const override;
    AggregateDeclaration *isThis() override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;

    void modifyReturns(Scope *sc, Type *tret);

    FuncLiteralDeclaration *isFuncLiteralDeclaration() override { return this; }
    const char *kind() const override;
    const char *toPrettyChars(bool QualifyTypes = false) override;
    void accept(Visitor *v) override { v->visit(this); }
};

class CtorDeclaration final : public FuncDeclaration
{
public:
    bool isCpCtor;
    CtorDeclaration *syntaxCopy(Dsymbol *) override;
    const char *kind() const override;
    const char *toChars() const override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;

    CtorDeclaration *isCtorDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class PostBlitDeclaration final : public FuncDeclaration
{
public:
    PostBlitDeclaration *syntaxCopy(Dsymbol *) override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;
    bool overloadInsert(Dsymbol *s) override;

    PostBlitDeclaration *isPostBlitDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class DtorDeclaration final : public FuncDeclaration
{
public:
    DtorDeclaration *syntaxCopy(Dsymbol *) override;
    const char *kind() const override;
    const char *toChars() const override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;
    bool overloadInsert(Dsymbol *s) override;

    DtorDeclaration *isDtorDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class StaticCtorDeclaration : public FuncDeclaration
{
public:
    StaticCtorDeclaration *syntaxCopy(Dsymbol *) override;
    AggregateDeclaration *isThis() override final;
    bool isVirtual() const override final;
    bool addPreInvariant() override final;
    bool addPostInvariant() override final;
    bool hasStaticCtorOrDtor() override final;

    StaticCtorDeclaration *isStaticCtorDeclaration() override final { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class SharedStaticCtorDeclaration final : public StaticCtorDeclaration
{
public:
    SharedStaticCtorDeclaration *syntaxCopy(Dsymbol *) override;

    SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class StaticDtorDeclaration : public FuncDeclaration
{
public:
    VarDeclaration *vgate;      // 'gate' variable

    StaticDtorDeclaration *syntaxCopy(Dsymbol *) override;
    AggregateDeclaration *isThis() override final;
    bool isVirtual() const override final;
    bool hasStaticCtorOrDtor() override final;
    bool addPreInvariant() override final;
    bool addPostInvariant() override final;

    StaticDtorDeclaration *isStaticDtorDeclaration() override final { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class SharedStaticDtorDeclaration final : public StaticDtorDeclaration
{
public:
    SharedStaticDtorDeclaration *syntaxCopy(Dsymbol *) override;

    SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class InvariantDeclaration final : public FuncDeclaration
{
public:
    InvariantDeclaration *syntaxCopy(Dsymbol *) override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;

    InvariantDeclaration *isInvariantDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class UnitTestDeclaration final : public FuncDeclaration
{
public:
    char *codedoc; /** For documented unittest. */

    // toObjFile() these nested functions after this one
    FuncDeclarations deferredNested;

    UnitTestDeclaration *syntaxCopy(Dsymbol *) override;
    AggregateDeclaration *isThis() override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;

    UnitTestDeclaration *isUnitTestDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};

class NewDeclaration final : public FuncDeclaration
{
public:
    NewDeclaration *syntaxCopy(Dsymbol *) override;
    const char *kind() const override;
    bool isVirtual() const override;
    bool addPreInvariant() override;
    bool addPostInvariant() override;

    NewDeclaration *isNewDeclaration() override { return this; }
    void accept(Visitor *v) override { v->visit(this); }
};