MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / d / dmd / declaration.h
blob71f2baa525f22de52f6e267a466adc099a9793c5
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * https://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * https://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/dlang/dmd/blob/master/src/dmd/declaration.h
9 */
11 #pragma once
13 #include "dsymbol.h"
14 #include "mtype.h"
15 #include "objc.h"
16 #include "tokens.h"
18 class Expression;
19 class Statement;
20 class LabelDsymbol;
21 class Initializer;
22 class ForeachStatement;
23 struct Ensure
25 Identifier *id;
26 Statement *ensure;
28 class FuncDeclaration;
29 class StructDeclaration;
30 struct IntRange;
31 struct AttributeViolation;
33 //enum STC : ulong from astenums.d:
35 #define STCundefined 0ULL
37 #define STCstatic 1ULL /// `static`
38 #define STCextern 2ULL /// `extern`
39 #define STCconst 4ULL /// `const`
40 #define STCfinal 8ULL /// `final`
42 #define STCabstract 0x10ULL /// `abstract`
43 #define STCparameter 0x20ULL /// is function parameter
44 #define STCfield 0x40ULL /// is field of struct, union or class
45 #define STCoverride 0x80ULL /// `override`
47 #define STCauto 0x100ULL /// `auto`
48 #define STCsynchronized 0x200ULL /// `synchronized`
49 #define STCdeprecated 0x400ULL /// `deprecated`
50 #define STCin 0x800ULL /// `in` parameter
52 #define STCout 0x1000ULL /// `out` parameter
53 #define STClazy 0x2000ULL /// `lazy` parameter
54 #define STCforeach 0x4000ULL /// variable for foreach loop
55 #define STCvariadic 0x8000ULL /// the `variadic` parameter in: T foo(T a, U b, V variadic...)
57 // 0x10000ULL
58 #define STCtemplateparameter 0x20000ULL /// template parameter
59 #define STCref 0x40000ULL /// `ref`
60 #define STCscope 0x80000ULL /// `scope`
62 #define STCscopeinferred 0x200000ULL /// `scope` has been inferred and should not be part of mangling, `scope` must also be set
63 #define STCreturn 0x400000ULL /// 'return ref' or 'return scope' for function parameters
64 #define STCreturnScope 0x800000ULL /// if `ref return scope` then resolve to `ref` and `return scope`
66 #define STCreturninferred 0x1000000ULL /// `return` has been inferred and should not be part of mangling, `return` must also be set
67 #define STCimmutable 0x2000000ULL /// `immutable`
68 // 0x4000000ULL
69 #define STCmanifest 0x8000000ULL /// manifest constant
71 #define STCnodtor 0x10000000ULL /// do not run destructor
72 #define STCnothrow 0x20000000ULL /// `nothrow` meaning never throws exceptions
73 #define STCpure 0x40000000ULL /// `pure` function
75 #define STCalias 0x100000000ULL /// `alias` parameter
76 #define STCshared 0x200000000ULL /// accessible from multiple threads
77 #define STCgshared 0x400000000ULL /// accessible from multiple threads, but not typed as `shared`
78 #define STCwild 0x800000000ULL /// for wild type constructor
80 #define STCproperty 0x1000000000ULL /// `@property`
81 #define STCsafe 0x2000000000ULL /// `@safe`
82 #define STCtrusted 0x4000000000ULL /// `@trusted`
83 #define STCsystem 0x8000000000ULL /// `@system`
85 #define STCctfe 0x10000000000ULL /// can be used in CTFE, even if it is static
86 #define STCdisable 0x20000000000ULL /// for functions that are not callable
87 #define STCresult 0x40000000000ULL /// for result variables passed to out contracts
88 #define STCnodefaultctor 0x80000000000ULL /// must be set inside constructor
90 #define STCtemp 0x100000000000ULL /// temporary variable
91 #define STCrvalue 0x200000000000ULL /// force rvalue for variables
92 #define STCnogc 0x400000000000ULL /// `@nogc`
93 #define STCautoref 0x800000000000ULL /// Mark for the already deduced `auto ref` parameter
95 #define STCinference 0x1000000000000ULL /// do attribute inference
96 #define STCexptemp 0x2000000000000ULL /// temporary variable that has lifetime restricted to an expression
97 #define STCfuture 0x4000000000000ULL /// introducing new base class function
98 #define STClocal 0x8000000000000ULL /// do not forward (see dmd.dsymbol.ForwardingScopeDsymbol).
100 #define STClive 0x10000000000000ULL /// function `@live` attribute
101 #define STCregister 0x20000000000000ULL /// `register` storage class (ImportC)
102 #define STCvolatile 0x40000000000000ULL /// destined for volatile in the back end
104 #define STC_TYPECTOR (STCconst | STCimmutable | STCshared | STCwild)
105 #define STC_FUNCATTR (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem)
107 void ObjectNotFound(Identifier *id);
109 /**************************************************************/
111 class Declaration : public Dsymbol
113 public:
114 Type *type;
115 Type *originalType; // before semantic analysis
116 StorageClass storage_class;
117 Visibility visibility;
118 LINK _linkage; // may be `LINK::system`; use `resolvedLinkage()` to resolve it
119 short inuse; // used to detect cycles
120 uint8_t adFlags;
121 Symbol* isym; // import version of csym
122 DString mangleOverride; // overridden symbol with pragma(mangle, "...")
124 const char *kind() const override;
125 uinteger_t size(const Loc &loc) override final;
127 Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override final;
129 bool isStatic() const { return (storage_class & STCstatic) != 0; }
130 LINK resolvedLinkage() const; // returns the linkage, resolving the target-specific `System` one
131 virtual bool isDelete();
132 virtual bool isDataseg();
133 virtual bool isThreadlocal();
134 virtual bool isCodeseg() const;
135 bool isFinal() const { return (storage_class & STCfinal) != 0; }
136 virtual bool isAbstract() { return (storage_class & STCabstract) != 0; }
137 bool isConst() const { return (storage_class & STCconst) != 0; }
138 bool isImmutable() const { return (storage_class & STCimmutable) != 0; }
139 bool isWild() const { return (storage_class & STCwild) != 0; }
140 bool isAuto() const { return (storage_class & STCauto) != 0; }
141 bool isScope() const { return (storage_class & STCscope) != 0; }
142 bool isReturn() const { return (storage_class & STCreturn) != 0; }
143 bool isSynchronized() const { return (storage_class & STCsynchronized) != 0; }
144 bool isParameter() const { return (storage_class & STCparameter) != 0; }
145 bool isDeprecated() const override final { return (storage_class & STCdeprecated) != 0; }
146 bool isOverride() const { return (storage_class & STCoverride) != 0; }
147 bool isResult() const { return (storage_class & STCresult) != 0; }
148 bool isField() const { return (storage_class & STCfield) != 0; }
150 bool isIn() const { return (storage_class & STCin) != 0; }
151 bool isOut() const { return (storage_class & STCout) != 0; }
152 bool isRef() const { return (storage_class & STCref) != 0; }
153 bool isReference() const { return (storage_class & (STCref | STCout)) != 0; }
155 bool isFuture() const { return (storage_class & STCfuture) != 0; }
157 Visibility visible() override final;
159 Declaration *isDeclaration() override final { return this; }
160 void accept(Visitor *v) override { v->visit(this); }
163 /**************************************************************/
165 class TupleDeclaration final : public Declaration
167 public:
168 Objects *objects;
169 TypeTuple *tupletype; // !=NULL if this is a type tuple
170 d_bool isexp; // true: expression tuple
171 d_bool building; // it's growing in AliasAssign semantic
173 TupleDeclaration *syntaxCopy(Dsymbol *) override;
174 const char *kind() const override;
175 Type *getType() override;
176 Dsymbol *toAlias2() override;
177 bool needThis() override;
179 TupleDeclaration *isTupleDeclaration() override { return this; }
180 void accept(Visitor *v) override { v->visit(this); }
183 /**************************************************************/
185 class AliasDeclaration final : public Declaration
187 public:
188 Dsymbol *aliassym;
189 Dsymbol *overnext; // next in overload list
190 Dsymbol *_import; // !=NULL if unresolved internal alias for selective import
192 static AliasDeclaration *create(const Loc &loc, Identifier *id, Type *type);
193 AliasDeclaration *syntaxCopy(Dsymbol *) override;
194 bool overloadInsert(Dsymbol *s) override;
195 const char *kind() const override;
196 Type *getType() override;
197 Dsymbol *toAlias() override;
198 Dsymbol *toAlias2() override;
199 bool isOverloadable() const override;
201 AliasDeclaration *isAliasDeclaration() override { return this; }
202 void accept(Visitor *v) override { v->visit(this); }
205 /**************************************************************/
207 class OverDeclaration final : public Declaration
209 public:
210 Dsymbol *overnext; // next in overload list
211 Dsymbol *aliassym;
213 const char *kind() const override;
214 bool equals(const RootObject * const o) const override;
215 bool overloadInsert(Dsymbol *s) override;
217 Dsymbol *toAlias() override;
218 Dsymbol *isUnique();
219 bool isOverloadable() const override;
221 OverDeclaration *isOverDeclaration() override { return this; }
222 void accept(Visitor *v) override { v->visit(this); }
225 /**************************************************************/
227 class VarDeclaration : public Declaration
229 public:
230 Initializer *_init;
231 FuncDeclarations nestedrefs; // referenced by these lexically nested functions
232 TupleDeclaration *aliasTuple; // if `this` is really a tuple of declarations
233 VarDeclaration *lastVar; // Linked list of variables for goto-skips-init detection
234 Expression *edtor; // if !=NULL, does the destruction of the variable
235 IntRange *range; // if !NULL, the variable is known to be within the range
236 VarDeclarations *maybes; // STCmaybescope variables that are assigned to this STCmaybescope variable
238 unsigned endlinnum; // line number of end of scope that this var lives in
239 unsigned offset;
240 unsigned sequenceNumber; // order the variables are declared
241 structalign_t alignment;
243 // When interpreting, these point to the value (NULL if value not determinable)
244 // The index of this variable on the CTFE stack, ~0u if not allocated
245 unsigned ctfeAdrOnStack;
246 private:
247 uint32_t bitFields;
248 public:
249 int8_t canassign; // // it can be assigned to
250 uint8_t isdataseg; // private data for isDataseg
251 bool isargptr() const; // if parameter that _argptr points to
252 bool isargptr(bool v);
253 bool ctorinit() const; // it has been initialized in a ctor
254 bool ctorinit(bool v);
255 bool iscatchvar() const; // this is the exception object variable in catch() clause
256 bool iscatchvar(bool v);
257 bool isowner() const; // this is an Owner, despite it being `scope`
258 bool isowner(bool v);
259 bool setInCtorOnly() const; // field can only be set in a constructor, as it is const or immutable
260 bool setInCtorOnly(bool v);
261 bool onstack() const; // it is a class that was allocated on the stack
262 bool onstack(bool v);
263 bool overlapped() const; // if it is a field and has overlapping
264 bool overlapped(bool v);
265 bool overlapUnsafe() const; // if it is an overlapping field and the overlaps are unsafe
266 bool overlapUnsafe(bool v);
267 bool maybeScope() const; // allow inferring 'scope' for this variable
268 bool maybeScope(bool v);
269 bool doNotInferReturn() const; // do not infer 'return' for this variable
270 bool doNotInferReturn(bool v);
271 bool isArgDtorVar() const; // temporary created to handle scope destruction of a function argument
272 bool isArgDtorVar(bool v);
273 bool isCmacro() const; // if a C macro turned into a C variable
274 bool isCmacro(bool v);
275 #if MARS
276 bool inClosure() const; // is inserted into a GC allocated closure
277 bool inClosure(bool v);
278 bool inAlignSection() const; // is inserted into aligned section on stack
279 bool inAlignSection(bool v);
280 #endif
281 bool systemInferred() const;
282 bool systemInferred(bool v);
283 static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
284 VarDeclaration *syntaxCopy(Dsymbol *) override;
285 void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
286 const char *kind() const override;
287 AggregateDeclaration *isThis() override final;
288 bool needThis() override final;
289 bool isExport() const override final;
290 bool isImportedSymbol() const override final;
291 bool isCtorinit() const;
292 bool isDataseg() override final;
293 bool isThreadlocal() override final;
294 bool isCTFE();
295 bool isOverlappedWith(VarDeclaration *v);
296 bool hasPointers() override final;
297 bool canTakeAddressOf();
298 bool needsScopeDtor();
299 void checkCtorConstInit() override final;
300 Dsymbol *toAlias() override final;
301 // Eliminate need for dynamic_cast
302 VarDeclaration *isVarDeclaration() override final { return (VarDeclaration *)this; }
303 void accept(Visitor *v) override { v->visit(this); }
306 /**************************************************************/
308 class BitFieldDeclaration : public VarDeclaration
310 public:
311 Expression *width;
313 unsigned fieldWidth;
314 unsigned bitOffset;
316 BitFieldDeclaration *syntaxCopy(Dsymbol *) override;
317 BitFieldDeclaration *isBitFieldDeclaration() override final { return this; }
318 void accept(Visitor *v) override { v->visit(this); }
321 /**************************************************************/
323 // This is a shell around a back end symbol
325 class SymbolDeclaration final : public Declaration
327 public:
328 AggregateDeclaration *dsym;
330 // Eliminate need for dynamic_cast
331 SymbolDeclaration *isSymbolDeclaration() override { return (SymbolDeclaration *)this; }
332 void accept(Visitor *v) override { v->visit(this); }
335 class TypeInfoDeclaration : public VarDeclaration
337 public:
338 Type *tinfo;
340 static TypeInfoDeclaration *create(Type *tinfo);
341 TypeInfoDeclaration *syntaxCopy(Dsymbol *) override final;
342 const char *toChars() const override final;
344 TypeInfoDeclaration *isTypeInfoDeclaration() override final { return this; }
345 void accept(Visitor *v) override { v->visit(this); }
348 class TypeInfoStructDeclaration final : public TypeInfoDeclaration
350 public:
351 static TypeInfoStructDeclaration *create(Type *tinfo);
353 void accept(Visitor *v) override { v->visit(this); }
356 class TypeInfoClassDeclaration final : public TypeInfoDeclaration
358 public:
359 static TypeInfoClassDeclaration *create(Type *tinfo);
361 void accept(Visitor *v) override { v->visit(this); }
364 class TypeInfoInterfaceDeclaration final : public TypeInfoDeclaration
366 public:
367 static TypeInfoInterfaceDeclaration *create(Type *tinfo);
369 void accept(Visitor *v) override { v->visit(this); }
372 class TypeInfoPointerDeclaration final : public TypeInfoDeclaration
374 public:
375 static TypeInfoPointerDeclaration *create(Type *tinfo);
377 void accept(Visitor *v) override { v->visit(this); }
380 class TypeInfoArrayDeclaration final : public TypeInfoDeclaration
382 public:
383 static TypeInfoArrayDeclaration *create(Type *tinfo);
385 void accept(Visitor *v) override { v->visit(this); }
388 class TypeInfoStaticArrayDeclaration final : public TypeInfoDeclaration
390 public:
391 static TypeInfoStaticArrayDeclaration *create(Type *tinfo);
393 void accept(Visitor *v) override { v->visit(this); }
396 class TypeInfoAssociativeArrayDeclaration final : public TypeInfoDeclaration
398 public:
399 static TypeInfoAssociativeArrayDeclaration *create(Type *tinfo);
401 void accept(Visitor *v) override { v->visit(this); }
404 class TypeInfoEnumDeclaration final : public TypeInfoDeclaration
406 public:
407 static TypeInfoEnumDeclaration *create(Type *tinfo);
409 void accept(Visitor *v) override { v->visit(this); }
412 class TypeInfoFunctionDeclaration final : public TypeInfoDeclaration
414 public:
415 static TypeInfoFunctionDeclaration *create(Type *tinfo);
417 void accept(Visitor *v) override { v->visit(this); }
420 class TypeInfoDelegateDeclaration final : public TypeInfoDeclaration
422 public:
423 static TypeInfoDelegateDeclaration *create(Type *tinfo);
425 void accept(Visitor *v) override { v->visit(this); }
428 class TypeInfoTupleDeclaration final : public TypeInfoDeclaration
430 public:
431 static TypeInfoTupleDeclaration *create(Type *tinfo);
433 void accept(Visitor *v) override { v->visit(this); }
436 class TypeInfoConstDeclaration final : public TypeInfoDeclaration
438 public:
439 static TypeInfoConstDeclaration *create(Type *tinfo);
441 void accept(Visitor *v) override { v->visit(this); }
444 class TypeInfoInvariantDeclaration final : public TypeInfoDeclaration
446 public:
447 static TypeInfoInvariantDeclaration *create(Type *tinfo);
449 void accept(Visitor *v) override { v->visit(this); }
452 class TypeInfoSharedDeclaration final : public TypeInfoDeclaration
454 public:
455 static TypeInfoSharedDeclaration *create(Type *tinfo);
457 void accept(Visitor *v) override { v->visit(this); }
460 class TypeInfoWildDeclaration final : public TypeInfoDeclaration
462 public:
463 static TypeInfoWildDeclaration *create(Type *tinfo);
465 void accept(Visitor *v) override { v->visit(this); }
468 class TypeInfoVectorDeclaration final : public TypeInfoDeclaration
470 public:
471 static TypeInfoVectorDeclaration *create(Type *tinfo);
473 void accept(Visitor *v) override { v->visit(this); }
476 /**************************************************************/
478 class ThisDeclaration final : public VarDeclaration
480 public:
481 ThisDeclaration *syntaxCopy(Dsymbol *) override;
482 ThisDeclaration *isThisDeclaration() override { return this; }
483 void accept(Visitor *v) override { v->visit(this); }
486 enum class ILS : unsigned char
488 ILSuninitialized, // not computed yet
489 ILSno, // cannot inline
490 ILSyes // can inline
493 /**************************************************************/
495 enum class BUILTIN : unsigned char
497 unknown = 255, /// not known if this is a builtin
498 unimp = 0, /// this is not a builtin
499 gcc, /// this is a GCC builtin
500 llvm, /// this is an LLVM builtin
501 sin,
502 cos,
503 tan,
504 sqrt,
505 fabs,
506 ldexp,
507 log,
508 log2,
509 log10,
510 exp,
511 expm1,
512 exp2,
513 round,
514 floor,
515 ceil,
516 trunc,
517 copysign,
518 pow,
519 fmin,
520 fmax,
521 fma,
522 isnan,
523 isinfinity,
524 isfinite,
525 bsf,
526 bsr,
527 bswap,
528 popcnt,
529 yl2x,
530 yl2xp1,
531 toPrecFloat,
532 toPrecDouble,
533 toPrecReal
536 Expression *eval_builtin(const Loc &loc, FuncDeclaration *fd, Expressions *arguments);
537 BUILTIN isBuiltin(FuncDeclaration *fd);
539 struct ContractInfo;
541 class FuncDeclaration : public Declaration
543 public:
544 Statement *fbody;
546 FuncDeclarations foverrides; // functions this function overrides
548 private:
549 ContractInfo *contracts; // contract information
551 public:
552 const char *mangleString; // mangled symbol created from mangleExact()
554 VarDeclaration *vresult; // result variable for out contracts
555 LabelDsymbol *returnLabel; // where the return goes
557 void *isTypeIsolatedCache; // An AA on the D side to cache an expensive check result
559 // used to prevent symbols in different
560 // scopes from having the same name
561 DsymbolTable *localsymtab;
562 VarDeclaration *vthis; // 'this' parameter (member and nested)
563 VarDeclaration *v_arguments; // '_arguments' parameter
565 VarDeclaration *v_argptr; // '_argptr' variable
566 VarDeclarations *parameters; // Array of VarDeclaration's for parameters
567 DsymbolTable *labtab; // statement label symbol table
568 Dsymbol *overnext; // next in overload list
569 FuncDeclaration *overnext0; // next in overload list (only used during IFTI)
570 Loc endloc; // location of closing curly bracket
571 int vtblIndex; // for member functions, index into vtbl[]
573 ILS inlineStatusStmt;
574 ILS inlineStatusExp;
575 PINLINE inlining;
577 int inlineNest; // !=0 if nested inline
579 // true if errors in semantic3 this function's frame ptr
580 ForeachStatement *fes; // if foreach body, this is the foreach
581 BaseClass* interfaceVirtual; // if virtual, but only appears in interface vtbl[]
582 // if !=NULL, then this is the type
583 // of the 'introducing' function
584 // this one is overriding
585 Type *tintro;
586 StorageClass storage_class2; // storage class for template onemember's
588 // Things that should really go into Scope
590 // 1 if there's a return exp; statement
591 // 2 if there's a throw statement
592 // 4 if there's an assert(0)
593 // 8 if there's inline asm
594 // 16 if there are multiple return statements
595 int hasReturnExp;
597 VarDeclaration *nrvo_var; // variable to replace with shidden
598 Symbol *shidden; // hidden pointer passed to function
600 ReturnStatements *returns;
602 GotoStatements *gotos; // Gotos with forward references
604 // set if this is a known, builtin function we can evaluate at compile time
605 BUILTIN builtin;
607 // set if someone took the address of this function
608 int tookAddressOf;
609 d_bool requiresClosure; // this function needs a closure
611 // local variables in this function which are referenced by nested functions
612 VarDeclarations closureVars;
614 /** Outer variables which are referenced by this nested function
615 * (the inverse of closureVars)
617 VarDeclarations outerVars;
619 // Sibling nested functions which called this one
620 FuncDeclarations siblingCallers;
622 FuncDeclarations *inlinedNestedCallees;
624 AttributeViolation* safetyViolation;
625 AttributeViolation* nogcViolation;
626 AttributeViolation* pureViolation;
627 AttributeViolation* nothrowViolation;
629 // Formerly FUNCFLAGS
630 uint32_t flags;
631 bool purityInprocess() const;
632 bool purityInprocess(bool v);
633 bool safetyInprocess() const;
634 bool safetyInprocess(bool v);
635 bool nothrowInprocess() const;
636 bool nothrowInprocess(bool v);
637 bool nogcInprocess() const;
638 bool nogcInprocess(bool v);
639 bool returnInprocess() const;
640 bool returnInprocess(bool v);
641 bool inlineScanned() const;
642 bool inlineScanned(bool v);
643 bool inferScope() const;
644 bool inferScope(bool v);
645 bool hasCatches() const;
646 bool hasCatches(bool v);
647 bool skipCodegen() const;
648 bool skipCodegen(bool v);
649 bool printf() const;
650 bool printf(bool v);
651 bool scanf() const;
652 bool scanf(bool v);
653 bool noreturn() const;
654 bool noreturn(bool v);
655 bool isNRVO() const;
656 bool isNRVO(bool v);
657 bool isNaked() const;
658 bool isNaked(bool v);
659 bool isGenerated() const;
660 bool isGenerated(bool v);
661 bool isIntroducing() const;
662 bool isIntroducing(bool v);
663 bool hasSemantic3Errors() const;
664 bool hasSemantic3Errors(bool v);
665 bool hasNoEH() const;
666 bool hasNoEH(bool v);
667 bool inferRetType() const;
668 bool inferRetType(bool v);
669 bool hasDualContext() const;
670 bool hasDualContext(bool v);
671 bool hasAlwaysInlines() const;
672 bool hasAlwaysInlines(bool v);
673 bool isCrtCtor() const;
674 bool isCrtCtor(bool v);
675 bool isCrtDtor() const;
676 bool isCrtDtor(bool v);
677 bool dllImport() const;
678 bool dllImport(bool v);
679 bool dllExport() const;
680 bool dllExport(bool v);
682 // Data for a function declaration that is needed for the Objective-C
683 // integration.
684 ObjcFuncDeclaration objc;
686 static FuncDeclaration *create(const Loc &loc, const Loc &endloc, Identifier *id, StorageClass storage_class, Type *type, bool noreturn = false);
687 FuncDeclaration *syntaxCopy(Dsymbol *) override;
688 Statements *frequires();
689 Ensures *fensures();
690 Statement *frequire();
691 Statement *fensure();
692 FuncDeclaration *fdrequire();
693 FuncDeclaration *fdensure();
694 Expressions *fdrequireParams();
695 Expressions *fdensureParams();
696 Statements *frequires(Statements *frs);
697 Ensures *fensures(Statements *fes);
698 Statement *frequire(Statement *fr);
699 Statement *fensure(Statement *fe);
700 FuncDeclaration *fdrequire(FuncDeclaration *fdr);
701 FuncDeclaration *fdensure(FuncDeclaration *fde);
702 Expressions *fdrequireParams(Expressions *fdrp);
703 Expressions *fdensureParams(Expressions *fdep);
704 bool functionSemantic();
705 bool functionSemantic3();
706 bool equals(const RootObject * const o) const override final;
708 int overrides(FuncDeclaration *fd);
709 int findVtblIndex(Dsymbols *vtbl, int dim);
710 BaseClass *overrideInterface();
711 bool overloadInsert(Dsymbol *s) override;
712 bool inUnittest();
713 MATCH leastAsSpecialized(FuncDeclaration *g, Identifiers *names);
714 LabelDsymbol *searchLabel(Identifier *ident, const Loc &loc);
715 int getLevel(FuncDeclaration *fd, int intypeof); // lexical nesting level difference
716 int getLevelAndCheck(const Loc &loc, Scope *sc, FuncDeclaration *fd);
717 const char *toPrettyChars(bool QualifyTypes = false) override;
718 const char *toFullSignature(); // for diagnostics, e.g. 'int foo(int x, int y) pure'
719 bool isMain() const;
720 bool isCMain() const;
721 bool isWinMain() const;
722 bool isDllMain() const;
723 bool isExport() const override final;
724 bool isImportedSymbol() const override final;
725 bool isCodeseg() const override final;
726 bool isOverloadable() const override final;
727 bool isAbstract() override final;
728 PURE isPure();
729 PURE isPureBypassingInference();
730 bool isSafe();
731 bool isSafeBypassingInference();
732 bool isTrusted();
734 bool isNogc();
735 bool isNogcBypassingInference();
737 virtual bool isNested() const;
738 AggregateDeclaration *isThis() override;
739 bool needThis() override final;
740 bool isVirtualMethod();
741 virtual bool isVirtual() const;
742 bool isFinalFunc() const;
743 virtual bool addPreInvariant();
744 virtual bool addPostInvariant();
745 const char *kind() const override;
746 bool isUnique();
747 bool needsClosure();
748 bool checkClosure();
749 bool hasNestedFrameRefs();
750 ParameterList getParameterList();
752 static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name, StorageClass stc=0);
753 static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id, StorageClass stc=0);
755 bool checkNRVO();
757 FuncDeclaration *isFuncDeclaration() override final { return this; }
759 virtual FuncDeclaration *toAliasFunc() { return this; }
760 void accept(Visitor *v) override { v->visit(this); }
763 class FuncAliasDeclaration final : public FuncDeclaration
765 public:
766 FuncDeclaration *funcalias;
767 d_bool hasOverloads;
769 FuncAliasDeclaration *isFuncAliasDeclaration() override { return this; }
770 const char *kind() const override;
772 FuncDeclaration *toAliasFunc() override;
773 void accept(Visitor *v) override { v->visit(this); }
776 class FuncLiteralDeclaration final : public FuncDeclaration
778 public:
779 TOK tok; // TOKfunction or TOKdelegate
780 Type *treq; // target of return type inference
782 // backend
783 d_bool deferToObj;
785 FuncLiteralDeclaration *syntaxCopy(Dsymbol *) override;
786 bool isNested() const override;
787 AggregateDeclaration *isThis() override;
788 bool isVirtual() const override;
789 bool addPreInvariant() override;
790 bool addPostInvariant() override;
792 void modifyReturns(Scope *sc, Type *tret);
794 FuncLiteralDeclaration *isFuncLiteralDeclaration() override { return this; }
795 const char *kind() const override;
796 const char *toPrettyChars(bool QualifyTypes = false) override;
797 void accept(Visitor *v) override { v->visit(this); }
800 class CtorDeclaration final : public FuncDeclaration
802 public:
803 d_bool isCpCtor;
804 CtorDeclaration *syntaxCopy(Dsymbol *) override;
805 const char *kind() const override;
806 const char *toChars() const override;
807 bool isVirtual() const override;
808 bool addPreInvariant() override;
809 bool addPostInvariant() override;
811 CtorDeclaration *isCtorDeclaration() override { return this; }
812 void accept(Visitor *v) override { v->visit(this); }
815 class PostBlitDeclaration final : public FuncDeclaration
817 public:
818 PostBlitDeclaration *syntaxCopy(Dsymbol *) override;
819 bool isVirtual() const override;
820 bool addPreInvariant() override;
821 bool addPostInvariant() override;
822 bool overloadInsert(Dsymbol *s) override;
824 PostBlitDeclaration *isPostBlitDeclaration() override { return this; }
825 void accept(Visitor *v) override { v->visit(this); }
828 class DtorDeclaration final : public FuncDeclaration
830 public:
831 DtorDeclaration *syntaxCopy(Dsymbol *) override;
832 const char *kind() const override;
833 const char *toChars() const override;
834 bool isVirtual() const override;
835 bool addPreInvariant() override;
836 bool addPostInvariant() override;
837 bool overloadInsert(Dsymbol *s) override;
839 DtorDeclaration *isDtorDeclaration() override { return this; }
840 void accept(Visitor *v) override { v->visit(this); }
843 class StaticCtorDeclaration : public FuncDeclaration
845 public:
846 StaticCtorDeclaration *syntaxCopy(Dsymbol *) override;
847 AggregateDeclaration *isThis() override final;
848 bool isVirtual() const override final;
849 bool addPreInvariant() override final;
850 bool addPostInvariant() override final;
851 bool hasStaticCtorOrDtor() override final;
853 StaticCtorDeclaration *isStaticCtorDeclaration() override final { return this; }
854 void accept(Visitor *v) override { v->visit(this); }
857 class SharedStaticCtorDeclaration final : public StaticCtorDeclaration
859 public:
860 SharedStaticCtorDeclaration *syntaxCopy(Dsymbol *) override;
862 SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() override { return this; }
863 void accept(Visitor *v) override { v->visit(this); }
866 class StaticDtorDeclaration : public FuncDeclaration
868 public:
869 VarDeclaration *vgate; // 'gate' variable
871 StaticDtorDeclaration *syntaxCopy(Dsymbol *) override;
872 AggregateDeclaration *isThis() override final;
873 bool isVirtual() const override final;
874 bool hasStaticCtorOrDtor() override final;
875 bool addPreInvariant() override final;
876 bool addPostInvariant() override final;
878 StaticDtorDeclaration *isStaticDtorDeclaration() override final { return this; }
879 void accept(Visitor *v) override { v->visit(this); }
882 class SharedStaticDtorDeclaration final : public StaticDtorDeclaration
884 public:
885 SharedStaticDtorDeclaration *syntaxCopy(Dsymbol *) override;
887 SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() override { return this; }
888 void accept(Visitor *v) override { v->visit(this); }
891 class InvariantDeclaration final : public FuncDeclaration
893 public:
894 InvariantDeclaration *syntaxCopy(Dsymbol *) override;
895 bool isVirtual() const override;
896 bool addPreInvariant() override;
897 bool addPostInvariant() override;
899 InvariantDeclaration *isInvariantDeclaration() override { return this; }
900 void accept(Visitor *v) override { v->visit(this); }
903 class UnitTestDeclaration final : public FuncDeclaration
905 public:
906 char *codedoc; /** For documented unittest. */
908 // toObjFile() these nested functions after this one
909 FuncDeclarations deferredNested;
911 UnitTestDeclaration *syntaxCopy(Dsymbol *) override;
912 AggregateDeclaration *isThis() override;
913 bool isVirtual() const override;
914 bool addPreInvariant() override;
915 bool addPostInvariant() override;
917 UnitTestDeclaration *isUnitTestDeclaration() override { return this; }
918 void accept(Visitor *v) override { v->visit(this); }
921 class NewDeclaration final : public FuncDeclaration
923 public:
924 NewDeclaration *syntaxCopy(Dsymbol *) override;
925 const char *kind() const override;
926 bool isVirtual() const override;
927 bool addPreInvariant() override;
928 bool addPostInvariant() override;
930 NewDeclaration *isNewDeclaration() override { return this; }
931 void accept(Visitor *v) override { v->visit(this); }