Debian Codegraph @

gcc/d/dmd/declaration.d

raw
1 /**
2 * Miscellaneous declarations, including typedef, alias, variable declarations including the
3 * implicit this declaration, type tuples, ClassInfo, ModuleInfo and various TypeInfos.
4 *
5 * Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved
6 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
7 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/declaration.d, _declaration.d)
9 * Documentation: https://dlang.org/phobos/dmd_declaration.html
10 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/declaration.d
11 */
12
13 module dmd.declaration;
14
15 import core.stdc.stdio;
16 import dmd.aggregate;
17 import dmd.arraytypes;
18 import dmd.astenums;
19 import dmd.ctorflow;
20 import dmd.dclass;
21 import dmd.delegatize;
22 import dmd.dscope;
23 import dmd.dstruct;
24 import dmd.dsymbol;
25 import dmd.dsymbolsem : dsymbolSemantic, aliasSemantic;
26 import dmd.dtemplate;
27 import dmd.errors;
28 import dmd.expression;
29 import dmd.func;
30 import dmd.funcsem : overloadApply, getLevelAndCheck;
31 import dmd.globals;
32 import dmd.gluelayer;
33 import dmd.hdrgen;
34 import dmd.id;
35 import dmd.identifier;
36 import dmd.init;
37 import dmd.initsem : initializerToExpression, initializerSemantic;
38 import dmd.intrange;
39 import dmd.location;
40 import dmd.mtype;
41 import dmd.common.outbuffer;
42 import dmd.rootobject;
43 import dmd.root.filename;
44 import dmd.target;
45 import dmd.tokens;
46 import dmd.typesem : toDsymbol, typeSemantic, size, hasPointers;
47 import dmd.visitor;
48
49 version (IN_GCC) {}
50 else version (IN_LLVM) {}
51 else version = MARS;
52
53 /******************************************
54 */
55 void ObjectNotFound(Loc loc, Identifier id)
56 {
57 global.gag = 0; // never gag the fatal error
58 error(loc, "`%s` not found. object.d may be incorrectly installed or corrupt.", id.toChars());
59 version (IN_LLVM)
60 {
61 errorSupplemental(loc, "ldc2 might not be correctly installed.");
62 errorSupplemental(loc, "Please check your ldc2.conf configuration file.");
63 errorSupplemental(loc, "Installation instructions can be found at http://wiki.dlang.org/LDC.");
64 }
65 else version (MARS)
66 {
67 errorSupplemental(loc, "dmd might not be correctly installed. Run 'dmd -man' for installation instructions.");
68 const dmdConfFile = global.inifilename.length ? FileName.canonicalName(global.inifilename) : "not found";
69 errorSupplemental(loc, "config file: %.*s", cast(int)dmdConfFile.length, dmdConfFile.ptr);
70 }
71 fatal();
72 }
73
74 /* Accumulator for successive matches.
75 */
76 struct MatchAccumulator
77 {
78 int count; // number of matches found so far
79 MATCH last = MATCH.nomatch; // match level of lastf
80 FuncDeclaration lastf; // last matching function we found
81 FuncDeclaration nextf; // if ambiguous match, this is the "other" function
82 }
83
84 /***********************************************************
85 */
86 extern (C++) abstract class Declaration : Dsymbol
87 {
88 Type type;
89 Type originalType; // before semantic analysis
90 STC storage_class = STC.none;
91 // overridden symbol with pragma(mangle, "...")
92 const(char)[] mangleOverride;
93 Visibility visibility;
94 short inuse; // used to detect cycles
95
96 private extern (D) static struct BitFields
97 {
98 LINK _linkage = LINK.default_; // may be `LINK.system`; use `resolvedLinkage()` to resolve it
99 bool wasRead; // set if AliasDeclaration was read
100 bool ignoreRead; // ignore any reads of AliasDeclaration
101 bool noUnderscore; // don't prepend _ to mangled name
102 bool hidden; // don't print this in .di files
103 bool nrvo; /// forward to fd.nrvo_var when generating code
104 }
105
106 import dmd.common.bitfields;
107 mixin(generateBitFields!(BitFields, ubyte));
108
109 final extern (D) this(DSYM tag, Identifier ident) @safe
110 {
111 super(tag, ident);
112 visibility = Visibility(Visibility.Kind.undefined);
113 }
114
115 final extern (D) this(DSYM tag, Loc loc, Identifier ident) @safe
116 {
117 super(tag, loc, ident);
118 visibility = Visibility(Visibility.Kind.undefined);
119 }
120
121 override const(char)* kind() const
122 {
123 return "declaration";
124 }
125
126 override final uinteger_t size(Loc loc)
127 {
128 assert(type);
129 const sz = type.size();
130 if (sz == SIZE_INVALID)
131 errors = true;
132 return sz;
133 }
134
135 final bool isStatic() const pure nothrow @nogc @safe
136 {
137 return (storage_class & STC.static_) != 0;
138 }
139
140 /// Returns the linkage, resolving the target-specific `System` one.
141 final LINK resolvedLinkage() const
142 {
143 return _linkage == LINK.system ? target.systemLinkage() : _linkage;
144 }
145
146 bool isDelete()
147 {
148 return false;
149 }
150
151 bool isDataseg()
152 {
153 return false;
154 }
155
156 bool isThreadlocal()
157 {
158 return false;
159 }
160
161 bool isCodeseg() const pure nothrow @nogc @safe
162 {
163 return false;
164 }
165
166 final bool isFinal() const pure nothrow @nogc @safe
167 {
168 return (storage_class & STC.final_) != 0;
169 }
170
171 bool isAbstract()
172 {
173 return (storage_class & STC.abstract_) != 0;
174 }
175
176 final bool isConst() const pure nothrow @nogc @safe
177 {
178 return (storage_class & STC.const_) != 0;
179 }
180
181 final bool isImmutable() const pure nothrow @nogc @safe
182 {
183 return (storage_class & STC.immutable_) != 0;
184 }
185
186 final bool isWild() const pure nothrow @nogc @safe
187 {
188 return (storage_class & STC.wild) != 0;
189 }
190
191 final bool isAuto() const pure nothrow @nogc @safe
192 {
193 return (storage_class & STC.auto_) != 0;
194 }
195
196 final bool isScope() const pure nothrow @nogc @safe
197 {
198 return (storage_class & STC.scope_) != 0;
199 }
200
201 final bool isReturn() const pure nothrow @nogc @safe
202 {
203 return (storage_class & STC.return_) != 0;
204 }
205
206 final bool isSynchronized() const pure nothrow @nogc @safe
207 {
208 return (storage_class & STC.synchronized_) != 0;
209 }
210
211 final bool isParameter() const pure nothrow @nogc @safe
212 {
213 return (storage_class & STC.parameter) != 0;
214 }
215
216 override final bool isDeprecated() const pure nothrow @nogc @safe
217 {
218 return (storage_class & STC.deprecated_) != 0;
219 }
220
221 final bool isDisabled() const pure nothrow @nogc @safe
222 {
223 return (storage_class & STC.disable) != 0;
224 }
225
226 final bool isOverride() const pure nothrow @nogc @safe
227 {
228 return (storage_class & STC.override_) != 0;
229 }
230
231 final bool isResult() const pure nothrow @nogc @safe
232 {
233 return (storage_class & STC.result) != 0;
234 }
235
236 final bool isField() const pure nothrow @nogc @safe
237 {
238 return (storage_class & STC.field) != 0;
239 }
240
241 final bool isIn() const pure nothrow @nogc @safe
242 {
243 return (storage_class & STC.in_) != 0;
244 }
245
246 final bool isOut() const pure nothrow @nogc @safe
247 {
248 return (storage_class & STC.out_) != 0;
249 }
250
251 final bool isRef() const pure nothrow @nogc @safe
252 {
253 return (storage_class & STC.ref_) != 0;
254 }
255
256 /// Returns: Whether the variable is a reference, annotated with `out` or `ref`
257 final bool isReference() const pure nothrow @nogc @safe
258 {
259 return (storage_class & (STC.ref_ | STC.out_)) != 0;
260 }
261
262 final bool isFuture() const pure nothrow @nogc @safe
263 {
264 return (storage_class & STC.future) != 0;
265 }
266
267 final extern(D) bool isSystem() const pure nothrow @nogc @safe
268 {
269 return (storage_class & STC.system) != 0;
270 }
271
272 override final Visibility visible() pure nothrow @nogc @safe
273 {
274 return visibility;
275 }
276
277 override void accept(Visitor v)
278 {
279 v.visit(this);
280 }
281 }
282
283 /***********************************************************
284 */
285 extern (C++) final class TupleDeclaration : Declaration
286 {
287 Objects* objects;
288 TypeTuple tupletype; // !=null if this is a type tuple
289 bool isexp; // true: expression tuple
290 bool building; // it's growing in AliasAssign semantic
291
292 extern (D) this(Loc loc, Identifier ident, Objects* objects) @safe
293 {
294 super(DSYM.tupleDeclaration, loc, ident);
295 this.objects = objects;
296 }
297
298 override TupleDeclaration syntaxCopy(Dsymbol s)
299 {
300 assert(0);
301 }
302
303 override const(char)* kind() const
304 {
305 return "sequence";
306 }
307
308 override Type getType()
309 {
310 /* If this tuple represents a type, return that type
311 */
312
313 //printf("TupleDeclaration::getType() %s\n", toChars());
314 if (isexp || building)
315 return null;
316 if (!tupletype)
317 {
318 /* It's only a type tuple if all the Object's are types
319 */
320 for (size_t i = 0; i < objects.length; i++)
321 {
322 RootObject o = (*objects)[i];
323 if (!o.isType())
324 {
325 //printf("\tnot[%d], %p, %d\n", i, o, o.dyncast());
326 return null;
327 }
328 }
329
330 /* We know it's a type tuple, so build the TypeTuple
331 */
332 Types* types = cast(Types*)objects;
333 auto args = new Parameters(objects.length);
334 OutBuffer buf;
335 int hasdeco = 1;
336 for (size_t i = 0; i < types.length; i++)
337 {
338 Type t = (*types)[i];
339 //printf("type = %s\n", t.toChars());
340 version (none)
341 {
342 buf.printf("_%s_%d", ident.toChars(), i);
343 auto id = Identifier.idPool(buf.extractSlice());
344 auto arg = new Parameter(Loc.initial, STC.in_, t, id, null);
345 }
346 else
347 {
348 auto arg = new Parameter(Loc.initial, STC.none, t, null, null, null);
349 }
350 (*args)[i] = arg;
351 if (!t.deco)
352 hasdeco = 0;
353 }
354
355 tupletype = new TypeTuple(args);
356 if (hasdeco)
357 return tupletype.typeSemantic(Loc.initial, null);
358 }
359 return tupletype;
360 }
361
362 override Dsymbol toAlias2()
363 {
364 //printf("TupleDeclaration::toAlias2() '%s' objects = %s\n", toChars(), objects.toChars());
365 for (size_t i = 0; i < objects.length; i++)
366 {
367 RootObject o = (*objects)[i];
368 if (Dsymbol s = isDsymbol(o))
369 {
370 s = s.toAlias2();
371 (*objects)[i] = s;
372 }
373 }
374 return this;
375 }
376
377 override bool needThis()
378 {
379 //printf("TupleDeclaration::needThis(%s)\n", toChars());
380 return isexp ? foreachVar((s) { return s.needThis(); }) != 0 : false;
381 }
382
383 /***********************************************************
384 * Calls dg(Dsymbol) for each Dsymbol, which should be a VarDeclaration
385 * inside VarExp (isexp == true).
386 * Params:
387 * dg = delegate to call for each Dsymbol
388 */
389 extern (D) void foreachVar(scope void delegate(Dsymbol) dg)
390 {
391 assert(isexp);
392 foreach (o; *objects)
393 {
394 if (auto e = o.isExpression())
395 if (auto ve = e.isVarExp())
396 dg(ve.var);
397 }
398 }
399
400 /***********************************************************
401 * Calls dg(Dsymbol) for each Dsymbol, which should be a VarDeclaration
402 * inside VarExp (isexp == true).
403 * If dg returns !=0, stops and returns that value else returns 0.
404 * Params:
405 * dg = delegate to call for each Dsymbol
406 * Returns:
407 * last value returned by dg()
408 */
409 extern (D) int foreachVar(scope int delegate(Dsymbol) dg)
410 {
411 assert(isexp);
412 foreach (o; *objects)
413 {
414 if (auto e = o.isExpression())
415 if (auto ve = e.isVarExp())
416 if(auto ret = dg(ve.var))
417 return ret;
418 }
419 return 0;
420 }
421
422 override void accept(Visitor v)
423 {
424 v.visit(this);
425 }
426 }
427
428 /***********************************************************
429 * https://dlang.org/spec/declaration.html#AliasDeclaration
430 */
431 extern (C++) final class AliasDeclaration : Declaration
432 {
433 Dsymbol aliassym; // alias ident = aliassym;
434
435 Dsymbol overnext; // next in overload list
436 Dsymbol _import; // !=null if unresolved internal alias for selective import
437
438 extern (D) this(Loc loc, Identifier ident, Type type) @safe
439 {
440 super(DSYM.aliasDeclaration, loc, ident);
441 //debug printf("AliasDeclaration(id = '%s', type = `%s`, %p)\n", ident.toChars(), dmd.hdrgen.toChars(type), type.isTypeIdentifier());
442 this.type = type;
443 assert(type);
444 }
445
446 extern (D) this(Loc loc, Identifier ident, Dsymbol s) @safe
447 {
448 super(DSYM.aliasDeclaration, loc, ident);
449 //debug printf("AliasDeclaration(id = '%s', s = `%s`)\n", ident.toChars(), s.toChars());
450 assert(s != this);
451 this.aliassym = s;
452 assert(s);
453 }
454
455 static AliasDeclaration create(Loc loc, Identifier id, Type type) @safe
456 {
457 return new AliasDeclaration(loc, id, type);
458 }
459
460 override AliasDeclaration syntaxCopy(Dsymbol s)
461 {
462 //printf("AliasDeclaration::syntaxCopy()\n");
463 assert(!s);
464 AliasDeclaration sa = type ? new AliasDeclaration(loc, ident, type.syntaxCopy()) : new AliasDeclaration(loc, ident, aliassym.syntaxCopy(null));
465 sa.comment = comment;
466 sa.storage_class = storage_class;
467 return sa;
468 }
469
470 override bool overloadInsert(Dsymbol s)
471 {
472 //printf("[%s] AliasDeclaration::overloadInsert('%s') s = %s %s @ [%s]\n",
473 // loc.toChars(), toChars(), s.kind(), s.toChars(), s.loc.toChars());
474
475 /** Aliases aren't overloadable themselves, but if their Aliasee is
476 * overloadable they are converted to an overloadable Alias (either
477 * FuncAliasDeclaration or OverDeclaration).
478 *
479 * This is done by moving the Aliasee into such an overloadable alias
480 * which is then used to replace the existing Aliasee. The original
481 * Alias (_this_) remains a useless shell.
482 *
483 * This is a horrible mess. It was probably done to avoid replacing
484 * existing AST nodes and references, but it needs a major
485 * simplification b/c it's too complex to maintain.
486 *
487 * A simpler approach might be to merge any colliding symbols into a
488 * simple Overload class (an array) and then later have that resolve
489 * all collisions.
490 */
491 if (semanticRun >= PASS.semanticdone)
492 {
493 /* Semantic analysis is already finished, and the aliased entity
494 * is not overloadable.
495 */
496 if (type)
497 {
498 /*
499 If type has been resolved already we could
500 still be inserting an alias from an import.
501
502 If we are handling an alias then pretend
503 it was inserting and return true, if not then
504 false since we didn't even pretend to insert something.
505 */
506 return this._import && this.equals(s);
507 }
508
509 // https://issues.dlang.org/show_bug.cgi?id=23865
510 // only insert if the symbol can be part of a set
511 const s1 = s.toAlias();
512 const isInsertCandidate = s1.isFuncDeclaration() || s1.isOverDeclaration() || s1.isTemplateDeclaration();
513
514 /* When s is added in member scope by static if, mixin("code") or others,
515 * aliassym is determined already. See the case in: test/compilable/test61.d
516 */
517 auto sa = aliassym.toAlias();
518
519 if (auto td = s.toAlias().isTemplateDeclaration())
520 s = td.funcroot ? td.funcroot : td;
521
522 if (auto fd = sa.isFuncDeclaration())
523 {
524 auto fa = new FuncAliasDeclaration(ident, fd);
525 fa.visibility = visibility;
526 fa.parent = parent;
527 aliassym = fa;
528 if (isInsertCandidate)
529 return aliassym.overloadInsert(s);
530 }
531 if (auto td = sa.isTemplateDeclaration())
532 {
533 auto od = new OverDeclaration(ident, td.funcroot ? td.funcroot : td);
534 od.visibility = visibility;
535 od.parent = parent;
536 aliassym = od;
537 if (isInsertCandidate)
538 return aliassym.overloadInsert(s);
539 }
540 if (auto od = sa.isOverDeclaration())
541 {
542 if (sa.ident != ident || sa.parent != parent)
543 {
544 od = new OverDeclaration(ident, od);
545 od.visibility = visibility;
546 od.parent = parent;
547 aliassym = od;
548 }
549 if (isInsertCandidate)
550 return od.overloadInsert(s);
551 }
552 if (auto os = sa.isOverloadSet())
553 {
554 if (sa.ident != ident || sa.parent != parent)
555 {
556 os = new OverloadSet(ident, os);
557 // TODO: visibility is lost here b/c OverloadSets have no visibility attribute
558 // Might no be a practical issue, b/c the code below fails to resolve the overload anyhow.
559 // ----
560 // module os1;
561 // import a, b;
562 // private alias merged = foo; // private alias to overload set of a.foo and b.foo
563 // ----
564 // module os2;
565 // import a, b;
566 // public alias merged = bar; // public alias to overload set of a.bar and b.bar
567 // ----
568 // module bug;
569 // import os1, os2;
570 // void test() { merged(123); } // should only look at os2.merged
571 //
572 // os.visibility = visibility;
573 os.parent = parent;
574 aliassym = os;
575 }
576 if (isInsertCandidate)
577 {
578 os.push(s);
579 return true;
580 }
581 }
582 return false;
583 }
584
585 /* Don't know yet what the aliased symbol is, so assume it can
586 * be overloaded and check later for correctness.
587 */
588 if (overnext)
589 return overnext.overloadInsert(s);
590 if (s is this)
591 return true;
592 overnext = s;
593 return true;
594 }
595
596 override const(char)* kind() const
597 {
598 return "alias";
599 }
600
601 override Type getType()
602 {
603 if (type)
604 return type;
605 return toAlias().getType();
606 }
607
608 override Dsymbol toAlias()
609 {
610 static if (0)
611 printf("[%s] AliasDeclaration::toAlias('%s', this = %p, aliassym: %s, kind: '%s', inuse = %d)\n",
612 loc.toChars(), toChars(), this, aliassym ? aliassym.toChars() : "", aliassym ? aliassym.kind() : "", inuse);
613 assert(this != aliassym);
614 //static int count; if (++count == 10) *(char*)0=0;
615
616 Dsymbol err()
617 {
618 // Avoid breaking "recursive alias" state during errors gagged
619 if (global.gag)
620 return this;
621 aliassym = new AliasDeclaration(loc, ident, Type.terror);
622 type = Type.terror;
623 return aliassym;
624 }
625 // Reading the AliasDeclaration
626 if (!this.ignoreRead)
627 this.wasRead = true; // can never assign to this AliasDeclaration again
628
629 if (inuse == 1 && type && _scope)
630 {
631 inuse = 2;
632 const olderrors = global.errors;
633 Dsymbol s = type.toDsymbol(_scope);
634 //printf("[%s] type = %s, s = %p, this = %p\n", loc.toChars(), type.toChars(), s, this);
635 if (global.errors != olderrors)
636 return err();
637 if (s)
638 {
639 s = s.toAlias();
640 if (global.errors != olderrors)
641 return err();
642 aliassym = s;
643 inuse = 0;
644 }
645 else
646 {
647 Type t = type.typeSemantic(loc, _scope);
648 if (t.ty == Terror)
649 return err();
650 if (global.errors != olderrors)
651 return err();
652 //printf("t = %s\n", t.toChars());
653 inuse = 0;
654 }
655 }
656 if (inuse)
657 {
658 .error(loc, "%s `%s` recursive alias declaration", kind, toPrettyChars);
659 return err();
660 }
661
662 if (semanticRun >= PASS.semanticdone)
663 {
664 // semantic is already done.
665
666 // Do not see aliassym !is null, because of lambda aliases.
667
668 // Do not see type.deco !is null, even so "alias T = const int;` needs
669 // semantic analysis to take the storage class `const` as type qualifier.
670 }
671 else
672 {
673 // stop AliasAssign tuple building
674 if (aliassym)
675 {
676 if (auto td = aliassym.isTupleDeclaration())
677 {
678 if (td.building)
679 {
680 td.building = false;
681 semanticRun = PASS.semanticdone;
682 return td;
683 }
684 }
685 }
686 if (_import && _import._scope)
687 {
688 /* If this is an internal alias for selective/renamed import,
689 * load the module first.
690 */
691 _import.dsymbolSemantic(null);
692 }
693 if (_scope)
694 {
695 aliasSemantic(this, _scope);
696 }
697 }
698
699 inuse = 1;
700 Dsymbol s = aliassym ? aliassym.toAlias() : this;
701 inuse = 0;
702 return s;
703 }
704
705 override Dsymbol toAlias2()
706 {
707 if (inuse)
708 {
709 .error(loc, "%s `%s` recursive alias declaration", kind, toPrettyChars);
710 return this;
711 }
712 inuse = 1;
713 Dsymbol s = aliassym ? aliassym.toAlias2() : this;
714 inuse = 0;
715 return s;
716 }
717
718 override bool isOverloadable() const
719 {
720 // assume overloadable until alias is resolved
721 return semanticRun < PASS.semanticdone ||
722 aliassym && aliassym.isOverloadable();
723 }
724
725 /** Returns: `true` if this instance was created to make a template parameter
726 visible in the scope of a template body, `false` otherwise */
727 extern (D) bool isAliasedTemplateParameter() const
728 {
729 return !!(storage_class & STC.templateparameter);
730 }
731
732 override void accept(Visitor v)
733 {
734 v.visit(this);
735 }
736 }
737
738 /***********************************************************
739 */
740 extern (C++) final class OverDeclaration : Declaration
741 {
742 Dsymbol overnext; // next in overload list
743 Dsymbol aliassym;
744
745 extern (D) this(Identifier ident, Dsymbol s) @safe
746 {
747 super(DSYM.overDeclaration, ident);
748 this.aliassym = s;
749 }
750
751 override const(char)* kind() const
752 {
753 return "overload alias"; // todo
754 }
755
756 override bool equals(const RootObject o) const
757 {
758 if (this == o)
759 return true;
760
761 auto s = isDsymbol(o);
762 if (!s)
763 return false;
764
765 if (auto od2 = s.isOverDeclaration())
766 return this.aliassym.equals(od2.aliassym);
767 return this.aliassym == s;
768 }
769
770 override bool overloadInsert(Dsymbol s)
771 {
772 //printf("OverDeclaration::overloadInsert('%s') aliassym = %p, overnext = %p\n", s.toChars(), aliassym, overnext);
773 if (overnext)
774 return overnext.overloadInsert(s);
775 if (s == this)
776 return true;
777 overnext = s;
778 return true;
779 }
780
781 override bool isOverloadable() const
782 {
783 return true;
784 }
785
786 Dsymbol isUnique()
787 {
788 Dsymbol result = null;
789 overloadApply(aliassym, (Dsymbol s)
790 {
791 if (result)
792 {
793 result = null;
794 return 1; // ambiguous, done
795 }
796 else
797 {
798 result = s;
799 return 0;
800 }
801 });
802 return result;
803 }
804
805 override void accept(Visitor v)
806 {
807 v.visit(this);
808 }
809 }
810
811 /***********************************************************
812 */
813 extern (C++) class VarDeclaration : Declaration
814 {
815 Initializer _init;
816 FuncDeclarations nestedrefs; // referenced by these lexically nested functions
817 TupleDeclaration aliasTuple; // when `this` is really a tuple of declarations
818 VarDeclaration lastVar; // Linked list of variables for goto-skips-init detection
819 Expression edtor; // if !=null, does the destruction of the variable
820 IntRange* range; // if !=null, the variable is known to be within the range
821
822 uint endlinnum; // line number of end of scope that this var lives in
823 uint offset;
824 uint sequenceNumber; // order the variables are declared
825 structalign_t alignment;
826
827 // When interpreting, these point to the value (NULL if value not determinable)
828 // The index of this variable on the CTFE stack, AdrOnStackNone if not allocated
829 enum AdrOnStackNone = ~0u;
830 uint ctfeAdrOnStack;
831
832 // `bool` fields that are compacted into bit fields in a string mixin
833 private extern (D) static struct BitFields
834 {
835 bool isargptr; /// if parameter that _argptr points to
836 bool ctorinit; /// it has been initialized in a ctor
837 bool iscatchvar; /// this is the exception object variable in catch() clause
838 bool isowner; /// this is an Owner, despite it being `scope`
839 bool setInCtorOnly; /// field can only be set in a constructor, as it is const or immutable
840
841 /// It is a class that was allocated on the stack
842 ///
843 /// This means the var is not rebindable once assigned,
844 /// and the destructor gets run when it goes out of scope
845 bool onstack;
846
847 bool overlapped; /// if it is a field and has overlapping
848 bool overlapUnsafe; /// if it is an overlapping field and the overlaps are unsafe
849 bool maybeScope; /// allow inferring 'scope' for this variable
850 bool doNotInferReturn; /// do not infer 'return' for this variable
851
852 bool isArgDtorVar; /// temporary created to handle scope destruction of a function argument
853 bool isCmacro; /// it is a C macro turned into a C declaration
854 bool dllImport; /// __declspec(dllimport)
855 bool dllExport; /// __declspec(dllexport)
856 version (MARS)
857 {
858 bool inClosure; /// is inserted into a GC allocated closure
859 bool inAlignSection; /// is inserted into an aligned section on stack
860 }
861 bool systemInferred; /// @system was inferred from initializer
862 }
863
864 import dmd.common.bitfields : generateBitFields;
865 mixin(generateBitFields!(BitFields, uint));
866
867 byte canassign; // it can be assigned to
868 ubyte isdataseg; // private data for isDataseg 0 unset, 1 true, 2 false
869
870 final extern (D) this(Loc loc, Type type, Identifier ident, Initializer _init, STC storage_class = STC.none)
871 in
872 {
873 assert(ident);
874 }
875 do
876 {
877 //printf("VarDeclaration('%s')\n", ident.toChars());
878 super(DSYM.varDeclaration, loc, ident);
879 debug
880 {
881 if (!type && !_init)
882 {
883 //printf("VarDeclaration('%s')\n", ident.toChars());
884 //*(char*)0=0;
885 }
886 }
887
888 assert(type || _init);
889 this.type = type;
890 this._init = _init;
891 ctfeAdrOnStack = AdrOnStackNone;
892 this.storage_class = storage_class;
893 }
894
895 static VarDeclaration create(Loc loc, Type type, Identifier ident, Initializer _init, StorageClass storage_class = STC.none)
896 {
897 return new VarDeclaration(loc, type, ident, _init, cast(STC) storage_class);
898 }
899
900 override VarDeclaration syntaxCopy(Dsymbol s)
901 {
902 //printf("VarDeclaration::syntaxCopy(%s)\n", toChars());
903 assert(!s);
904 auto v = new VarDeclaration(loc, type ? type.syntaxCopy() : null, ident, _init ? _init.syntaxCopy() : null, storage_class);
905 v.comment = comment;
906 return v;
907 }
908
909 override const(char)* kind() const
910 {
911 return "variable";
912 }
913
914 override final inout(AggregateDeclaration) isThis() inout
915 {
916 if (!(storage_class & (STC.static_ | STC.extern_ | STC.manifest | STC.templateparameter | STC.gshared | STC.ctfe)))
917 {
918 /* The casting is necessary because `s = s.parent` is otherwise rejected
919 */
920 for (auto s = cast(Dsymbol)this; s; s = s.parent)
921 {
922 if (auto ad = (cast(inout)s).isMember())
923 return ad;
924 if (!s.parent || !s.parent.isTemplateMixin())
925 break;
926 }
927 }
928 return null;
929 }
930
931 override final bool needThis()
932 {
933 //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class);
934 return isField();
935 }
936
937 override final bool isExport() const
938 {
939 return visibility.kind == Visibility.Kind.export_ || dllExport;
940 }
941
942 override final bool isImportedSymbol() const
943 {
944 /* If global variable has `export` and `extern` then it is imported
945 * export int sym1; // definition: exported
946 * export extern int sym2; // declaration: imported
947 * export extern int sym3 = 0; // error, extern cannot have initializer
948 */
949 bool result =
950 dllImport ||
951 visibility.kind == Visibility.Kind.export_ &&
952 storage_class & STC.extern_ &&
953 (storage_class & STC.static_ || parent.isModule());
954 //printf("isImportedSymbol() %s %d\n", toChars(), result);
955 return result;
956 }
957
958 final bool isCtorinit() const pure nothrow @nogc @safe
959 {
960 return setInCtorOnly;
961 }
962
963 /*******************************
964 * Does symbol go into data segment?
965 * Includes extern variables.
966 */
967 override final bool isDataseg()
968 {
969 version (none)
970 {
971 printf("VarDeclaration::isDataseg(%p, '%s')\n", this, toChars());
972 printf("%llx, isModule: %p, isTemplateInstance: %p, isNspace: %p\n",
973 storage_class & (STC.static_ | STC.const_), parent.isModule(), parent.isTemplateInstance(), parent.isNspace());
974 printf("parent = '%s'\n", parent.toChars());
975 }
976
977 if (isdataseg == 0) // the value is not cached
978 {
979 isdataseg = 2; // The Variables does not go into the datasegment
980
981 if (!canTakeAddressOf())
982 {
983 return false;
984 }
985
986 Dsymbol parent = toParent();
987 if (!parent && !(storage_class & STC.static_))
988 {
989 .error(loc, "%s `%s` forward referenced", kind, toPrettyChars);
990 type = Type.terror;
991 }
992 else if (storage_class & (STC.static_ | STC.extern_ | STC.gshared) ||
993 parent.isModule() || parent.isTemplateInstance() || parent.isNspace())
994 {
995 assert(!isParameter() && !isResult());
996 isdataseg = 1; // It is in the DataSegment
997 }
998 }
999
1000 return (isdataseg == 1);
1001 }
1002 /************************************
1003 * Does symbol go into thread local storage?
1004 */
1005 override final bool isThreadlocal()
1006 {
1007 //printf("VarDeclaration::isThreadlocal(%p, '%s')\n", this, toChars());
1008 /* Data defaults to being thread-local. It is not thread-local
1009 * if it is immutable, const or shared.
1010 */
1011 bool i = isDataseg() && !(storage_class & (STC.immutable_ | STC.const_ | STC.shared_ | STC.gshared));
1012 //printf("\treturn %d\n", i);
1013 return i;
1014 }
1015
1016 /********************************************
1017 * Can variable be read and written by CTFE?
1018 */
1019 final bool isCTFE()
1020 {
1021 return (storage_class & STC.ctfe) != 0; // || !isDataseg();
1022 }
1023
1024 final bool isOverlappedWith(VarDeclaration v)
1025 {
1026 const vsz = v.type.size();
1027 const tsz = type.size();
1028 assert(vsz != SIZE_INVALID && tsz != SIZE_INVALID);
1029
1030 // Overlap is checked by comparing bit offsets
1031 auto bitoffset = offset * 8;
1032 auto vbitoffset = v.offset * 8;
1033
1034 // Bitsize of types are overridden by any bit-field widths.
1035 ulong tbitsize;
1036 if (auto bf = isBitFieldDeclaration())
1037 {
1038 bitoffset += bf.bitOffset;
1039 tbitsize = bf.fieldWidth;
1040 }
1041 else
1042 tbitsize = tsz * 8;
1043
1044 ulong vbitsize;
1045 if (auto vbf = v.isBitFieldDeclaration())
1046 {
1047 vbitoffset += vbf.bitOffset;
1048 vbitsize = vbf.fieldWidth;
1049 }
1050 else
1051 vbitsize = vsz * 8;
1052
1053 return bitoffset < vbitoffset + vbitsize &&
1054 vbitoffset < bitoffset + tbitsize;
1055 }
1056
1057 override final bool hasPointers()
1058 {
1059 //printf("VarDeclaration::hasPointers() %s, ty = %d\n", toChars(), type.ty);
1060 return (!isDataseg() && type.hasPointers());
1061 }
1062
1063 /*************************************
1064 * Return true if we can take the address of this variable.
1065 */
1066 final bool canTakeAddressOf() @safe
1067 {
1068 return !(storage_class & STC.manifest);
1069 }
1070
1071 /******************************************
1072 * Return true if variable needs to call the destructor.
1073 */
1074 final bool needsScopeDtor() @safe
1075 {
1076 //printf("VarDeclaration::needsScopeDtor() %s %d\n", toChars(), edtor && !(storage_class & STC.nodtor));
1077 return edtor && !(storage_class & STC.nodtor);
1078 }
1079
1080 /*******************************************
1081 * If variable has a constant expression initializer, get it.
1082 * Otherwise, return null.
1083 */
1084 extern (D) final Expression getConstInitializer(bool needFullType = true)
1085 {
1086 assert(type && _init);
1087
1088 // Ungag errors when not speculative
1089 const oldgag = global.gag;
1090 if (global.gag)
1091 {
1092 Dsymbol sym = isMember();
1093 if (sym && !sym.isSpeculative())
1094 global.gag = 0;
1095 }
1096
1097 if (_scope)
1098 {
1099 inuse++;
1100 _init = _init.initializerSemantic(_scope, type, INITinterpret);
1101 import dmd.semantic2 : lowerStaticAAs;
1102 lowerStaticAAs(this, _scope);
1103 _scope = null;
1104 inuse--;
1105 }
1106
1107 Expression e = _init.initializerToExpression(needFullType ? type : null);
1108 global.gag = oldgag;
1109 return e;
1110 }
1111
1112 /************************************
1113 * Check to see if this variable is actually in an enclosing function
1114 * rather than the current one.
1115 * Update nestedrefs[], closureVars[] and outerVars[].
1116 * Returns: true if error occurs.
1117 */
1118 extern (D) final bool checkNestedReference(Scope* sc, Loc loc)
1119 {
1120 //printf("VarDeclaration::checkNestedReference() %s\n", toChars());
1121 if (sc.intypeof == 1 || sc.ctfe)
1122 return false;
1123 if (!parent || parent == sc.parent)
1124 return false;
1125 if (isDataseg() || (storage_class & STC.manifest))
1126 return false;
1127
1128 // The current function
1129 FuncDeclaration fdthis = sc.parent.isFuncDeclaration();
1130 if (!fdthis)
1131 return false; // out of function scope
1132
1133 Dsymbol p = toParent2();
1134
1135 // Function literals from fdthis to p must be delegates
1136 ensureStaticLinkTo(fdthis, p);
1137
1138 // The function that this variable is in
1139 FuncDeclaration fdv = p.isFuncDeclaration();
1140 if (!fdv || fdv == fdthis)
1141 return false;
1142
1143 // Add fdthis to nestedrefs[] if not already there
1144 if (!nestedrefs.contains(fdthis))
1145 nestedrefs.push(fdthis);
1146
1147 //printf("\tfdv = %s\n", fdv.toChars());
1148 //printf("\tfdthis = %s\n", fdthis.toChars());
1149 if (loc.isValid())
1150 {
1151 if (fdthis.getLevelAndCheck(loc, sc, fdv, this) == fdthis.LevelError)
1152 return true;
1153 }
1154
1155 // Add this VarDeclaration to fdv.closureVars[] if not already there
1156 if (!sc.intypeof && !sc.traitsCompiles &&
1157 // https://issues.dlang.org/show_bug.cgi?id=17605
1158 (fdv.skipCodegen || !fdthis.skipCodegen))
1159 {
1160 if (!fdv.closureVars.contains(this))
1161 fdv.closureVars.push(this);
1162 }
1163
1164 if (!fdthis.outerVars.contains(this))
1165 fdthis.outerVars.push(this);
1166
1167 //printf("fdthis is %s\n", fdthis.toChars());
1168 //printf("var %s in function %s is nested ref\n", toChars(), fdv.toChars());
1169 // __dollar creates problems because it isn't a real variable
1170 // https://issues.dlang.org/show_bug.cgi?id=3326
1171 if (ident == Id.dollar)
1172 {
1173 .error(loc, "cannnot use `$` inside a function literal");
1174 return true;
1175 }
1176 if (ident == Id.withSym) // https://issues.dlang.org/show_bug.cgi?id=1759
1177 {
1178 ExpInitializer ez = _init.isExpInitializer();
1179 assert(ez);
1180 Expression e = ez.exp;
1181 if (e.op == EXP.construct || e.op == EXP.blit)
1182 e = (cast(AssignExp)e).e2;
1183 return lambdaCheckForNestedRef(e, sc);
1184 }
1185
1186 return false;
1187 }
1188
1189 override final Dsymbol toAlias()
1190 {
1191 //printf("VarDeclaration::toAlias('%s', this = %p, aliassym = %p)\n", toChars(), this, aliassym);
1192 if ((!type || !type.deco) && _scope)
1193 dsymbolSemantic(this, _scope);
1194
1195 assert(this != aliasTuple);
1196 Dsymbol s = aliasTuple ? aliasTuple.toAlias() : this;
1197 return s;
1198 }
1199
1200 override void accept(Visitor v)
1201 {
1202 v.visit(this);
1203 }
1204 }
1205
1206 /*******************************************************
1207 * C11 6.7.2.1-4 bit fields
1208 */
1209 extern (C++) class BitFieldDeclaration : VarDeclaration
1210 {
1211 Expression width;
1212
1213 uint fieldWidth;
1214 uint bitOffset;
1215
1216 final extern (D) this(Loc loc, Type type, Identifier ident, Expression width)
1217 {
1218 super(loc, type, ident, null);
1219 this.dsym = DSYM.bitFieldDeclaration;
1220 this.width = width;
1221 this.storage_class |= STC.field;
1222 }
1223
1224 override BitFieldDeclaration syntaxCopy(Dsymbol s)
1225 {
1226 //printf("BitFieldDeclaration::syntaxCopy(%s)\n", toChars());
1227 assert(!s);
1228 auto bf = new BitFieldDeclaration(loc, type ? type.syntaxCopy() : null, ident, width.syntaxCopy());
1229 bf.comment = comment;
1230 return bf;
1231 }
1232
1233 override void accept(Visitor v)
1234 {
1235 v.visit(this);
1236 }
1237
1238 /***********************************
1239 * Retrieve the .min or .max values.
1240 * Only valid after semantic analysis.
1241 * Params:
1242 * id = Id.min or Id.max
1243 * Returns:
1244 * the min or max value
1245 */
1246 final ulong getMinMax(Identifier id)
1247 {
1248 const width = fieldWidth;
1249 const uns = type.isUnsigned();
1250 const min = id == Id.min;
1251 ulong v;
1252 assert(width != 0); // should have been rejected in semantic pass
1253 if (width == ulong.sizeof * 8)
1254 v = uns ? (min ? ulong.min : ulong.max)
1255 : (min ? long.min : long.max);
1256 else
1257 v = uns ? (min ? 0
1258 : (1L << width) - 1)
1259 : (min ? -(1L << (width - 1))
1260 : (1L << (width - 1)) - 1);
1261 return v;
1262 }
1263 }
1264
1265 /***********************************************************
1266 * This is a shell around a back end symbol
1267 */
1268 extern (C++) final class SymbolDeclaration : Declaration
1269 {
1270 AggregateDeclaration dsym;
1271
1272 extern (D) this(Loc loc, AggregateDeclaration dsym) @safe
1273 {
1274 super(DSYM.symbolDeclaration, loc, dsym.ident);
1275 this.dsym = dsym;
1276 storage_class |= STC.const_;
1277 }
1278
1279 override void accept(Visitor v)
1280 {
1281 v.visit(this);
1282 }
1283 }
1284
1285 /***********************************************************
1286 */
1287 private Identifier getTypeInfoIdent(Type t)
1288 {
1289 import dmd.mangle;
1290 import core.stdc.stdlib;
1291 import dmd.root.rmem;
1292 // _init_10TypeInfo_%s
1293 OutBuffer buf;
1294 buf.reserve(32);
1295 mangleToBuffer(t, buf);
1296
1297 const slice = buf[];
1298
1299 // Allocate buffer on stack, fail over to using malloc()
1300 char[128] namebuf;
1301 const namelen = 19 + size_t.sizeof * 3 + slice.length + 1;
1302 auto name = namelen <= namebuf.length ? namebuf.ptr : cast(char*)Mem.check(malloc(namelen));
1303
1304 const length = snprintf(name, namelen, "_D%lluTypeInfo_%.*s6__initZ",
1305 cast(ulong)(9 + slice.length), cast(int)slice.length, slice.ptr);
1306 //printf("%p %s, deco = %s, name = %s\n", this, toChars(), deco, name);
1307 assert(0 < length && length < namelen); // don't overflow the buffer
1308
1309 auto id = Identifier.idPool(name[0 .. length]);
1310
1311 if (name != namebuf.ptr)
1312 free(name);
1313 return id;
1314 }
1315
1316 extern (C++) class TypeInfoDeclaration : VarDeclaration
1317 {
1318 Type tinfo;
1319
1320 final extern (D) this(Type tinfo)
1321 {
1322 super(Loc.initial, Type.dtypeinfo.type, tinfo.getTypeInfoIdent(), null);
1323 this.dsym = DSYM.typeInfoDeclaration;
1324 this.tinfo = tinfo;
1325 storage_class = STC.static_ | STC.gshared;
1326 visibility = Visibility(Visibility.Kind.public_);
1327 _linkage = LINK.c;
1328 alignment.set(target.ptrsize);
1329 }
1330
1331 static TypeInfoDeclaration create(Type tinfo)
1332 {
1333 return new TypeInfoDeclaration(tinfo);
1334 }
1335
1336 override final TypeInfoDeclaration syntaxCopy(Dsymbol s)
1337 {
1338 assert(0); // should never be produced by syntax
1339 }
1340
1341 override void accept(Visitor v)
1342 {
1343 v.visit(this);
1344 }
1345 }
1346
1347 /***********************************************************
1348 */
1349 extern (C++) final class TypeInfoStructDeclaration : TypeInfoDeclaration
1350 {
1351 extern (D) this(Type tinfo)
1352 {
1353 super(tinfo);
1354 if (!Type.typeinfostruct)
1355 {
1356 ObjectNotFound(loc, Id.TypeInfo_Struct);
1357 }
1358 type = Type.typeinfostruct.type;
1359 }
1360
1361 static TypeInfoStructDeclaration create(Type tinfo)
1362 {
1363 return new TypeInfoStructDeclaration(tinfo);
1364 }
1365
1366 override void accept(Visitor v)
1367 {
1368 v.visit(this);
1369 }
1370 }
1371
1372 /***********************************************************
1373 */
1374 extern (C++) final class TypeInfoClassDeclaration : TypeInfoDeclaration
1375 {
1376 extern (D) this(Type tinfo)
1377 {
1378 super(tinfo);
1379 if (!Type.typeinfoclass)
1380 {
1381 ObjectNotFound(loc, Id.TypeInfo_Class);
1382 }
1383 type = Type.typeinfoclass.type;
1384 }
1385
1386 static TypeInfoClassDeclaration create(Type tinfo)
1387 {
1388 return new TypeInfoClassDeclaration(tinfo);
1389 }
1390
1391 override void accept(Visitor v)
1392 {
1393 v.visit(this);
1394 }
1395 }
1396
1397 /***********************************************************
1398 */
1399 extern (C++) final class TypeInfoInterfaceDeclaration : TypeInfoDeclaration
1400 {
1401 extern (D) this(Type tinfo)
1402 {
1403 super(tinfo);
1404 if (!Type.typeinfointerface)
1405 {
1406 ObjectNotFound(loc, Id.TypeInfo_Interface);
1407 }
1408 type = Type.typeinfointerface.type;
1409 }
1410
1411 static TypeInfoInterfaceDeclaration create(Type tinfo)
1412 {
1413 return new TypeInfoInterfaceDeclaration(tinfo);
1414 }
1415
1416 override void accept(Visitor v)
1417 {
1418 v.visit(this);
1419 }
1420 }
1421
1422 /***********************************************************
1423 */
1424 extern (C++) final class TypeInfoPointerDeclaration : TypeInfoDeclaration
1425 {
1426 extern (D) this(Type tinfo)
1427 {
1428 super(tinfo);
1429 if (!Type.typeinfopointer)
1430 {
1431 ObjectNotFound(loc, Id.TypeInfo_Pointer);
1432 }
1433 type = Type.typeinfopointer.type;
1434 }
1435
1436 static TypeInfoPointerDeclaration create(Type tinfo)
1437 {
1438 return new TypeInfoPointerDeclaration(tinfo);
1439 }
1440
1441 override void accept(Visitor v)
1442 {
1443 v.visit(this);
1444 }
1445 }
1446
1447 /***********************************************************
1448 */
1449 extern (C++) final class TypeInfoArrayDeclaration : TypeInfoDeclaration
1450 {
1451 extern (D) this(Type tinfo)
1452 {
1453 super(tinfo);
1454 if (!Type.typeinfoarray)
1455 {
1456 ObjectNotFound(loc, Id.TypeInfo_Array);
1457 }
1458 type = Type.typeinfoarray.type;
1459 }
1460
1461 static TypeInfoArrayDeclaration create(Type tinfo)
1462 {
1463 return new TypeInfoArrayDeclaration(tinfo);
1464 }
1465
1466 override void accept(Visitor v)
1467 {
1468 v.visit(this);
1469 }
1470 }
1471
1472 /***********************************************************
1473 */
1474 extern (C++) final class TypeInfoStaticArrayDeclaration : TypeInfoDeclaration
1475 {
1476 extern (D) this(Type tinfo)
1477 {
1478 super(tinfo);
1479 if (!Type.typeinfostaticarray)
1480 {
1481 ObjectNotFound(loc, Id.TypeInfo_StaticArray);
1482 }
1483 type = Type.typeinfostaticarray.type;
1484 }
1485
1486 static TypeInfoStaticArrayDeclaration create(Type tinfo)
1487 {
1488 return new TypeInfoStaticArrayDeclaration(tinfo);
1489 }
1490
1491 override void accept(Visitor v)
1492 {
1493 v.visit(this);
1494 }
1495 }
1496
1497 /***********************************************************
1498 */
1499 extern (C++) final class TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration
1500 {
1501 Type entry; // type of TypeInfo_AssociativeArray.Entry!(t.index, t.next)
1502
1503 extern (D) this(Type tinfo)
1504 {
1505 super(tinfo);
1506 if (!Type.typeinfoassociativearray)
1507 {
1508 ObjectNotFound(loc, Id.TypeInfo_AssociativeArray);
1509 }
1510 type = Type.typeinfoassociativearray.type;
1511 }
1512
1513 static TypeInfoAssociativeArrayDeclaration create(Type tinfo)
1514 {
1515 return new TypeInfoAssociativeArrayDeclaration(tinfo);
1516 }
1517
1518 override void accept(Visitor v)
1519 {
1520 v.visit(this);
1521 }
1522 }
1523
1524 /***********************************************************
1525 */
1526 extern (C++) final class TypeInfoEnumDeclaration : TypeInfoDeclaration
1527 {
1528 extern (D) this(Type tinfo)
1529 {
1530 super(tinfo);
1531 if (!Type.typeinfoenum)
1532 {
1533 ObjectNotFound(loc, Id.TypeInfo_Enum);
1534 }
1535 type = Type.typeinfoenum.type;
1536 }
1537
1538 static TypeInfoEnumDeclaration create(Type tinfo)
1539 {
1540 return new TypeInfoEnumDeclaration(tinfo);
1541 }
1542
1543 override void accept(Visitor v)
1544 {
1545 v.visit(this);
1546 }
1547 }
1548
1549 /***********************************************************
1550 */
1551 extern (C++) final class TypeInfoFunctionDeclaration : TypeInfoDeclaration
1552 {
1553 extern (D) this(Type tinfo)
1554 {
1555 super(tinfo);
1556 if (!Type.typeinfofunction)
1557 {
1558 ObjectNotFound(loc, Id.TypeInfo_Function);
1559 }
1560 type = Type.typeinfofunction.type;
1561 }
1562
1563 static TypeInfoFunctionDeclaration create(Type tinfo)
1564 {
1565 return new TypeInfoFunctionDeclaration(tinfo);
1566 }
1567
1568 override void accept(Visitor v)
1569 {
1570 v.visit(this);
1571 }
1572 }
1573
1574 /***********************************************************
1575 */
1576 extern (C++) final class TypeInfoDelegateDeclaration : TypeInfoDeclaration
1577 {
1578 extern (D) this(Type tinfo)
1579 {
1580 super(tinfo);
1581 if (!Type.typeinfodelegate)
1582 {
1583 ObjectNotFound(loc, Id.TypeInfo_Delegate);
1584 }
1585 type = Type.typeinfodelegate.type;
1586 }
1587
1588 static TypeInfoDelegateDeclaration create(Type tinfo)
1589 {
1590 return new TypeInfoDelegateDeclaration(tinfo);
1591 }
1592
1593 override void accept(Visitor v)
1594 {
1595 v.visit(this);
1596 }
1597 }
1598
1599 /***********************************************************
1600 */
1601 extern (C++) final class TypeInfoTupleDeclaration : TypeInfoDeclaration
1602 {
1603 extern (D) this(Type tinfo)
1604 {
1605 super(tinfo);
1606 if (!Type.typeinfotypelist)
1607 {
1608 ObjectNotFound(loc, Id.TypeInfo_Tuple);
1609 }
1610 type = Type.typeinfotypelist.type;
1611 }
1612
1613 static TypeInfoTupleDeclaration create(Type tinfo)
1614 {
1615 return new TypeInfoTupleDeclaration(tinfo);
1616 }
1617
1618 override void accept(Visitor v)
1619 {
1620 v.visit(this);
1621 }
1622 }
1623
1624 /***********************************************************
1625 */
1626 extern (C++) final class TypeInfoConstDeclaration : TypeInfoDeclaration
1627 {
1628 extern (D) this(Type tinfo)
1629 {
1630 super(tinfo);
1631 if (!Type.typeinfoconst)
1632 {
1633 ObjectNotFound(loc, Id.TypeInfo_Const);
1634 }
1635 type = Type.typeinfoconst.type;
1636 }
1637
1638 static TypeInfoConstDeclaration create(Type tinfo)
1639 {
1640 return new TypeInfoConstDeclaration(tinfo);
1641 }
1642
1643 override void accept(Visitor v)
1644 {
1645 v.visit(this);
1646 }
1647 }
1648
1649 /***********************************************************
1650 */
1651 extern (C++) final class TypeInfoInvariantDeclaration : TypeInfoDeclaration
1652 {
1653 extern (D) this(Type tinfo)
1654 {
1655 super(tinfo);
1656 if (!Type.typeinfoinvariant)
1657 {
1658 ObjectNotFound(loc, Id.TypeInfo_Invariant);
1659 }
1660 type = Type.typeinfoinvariant.type;
1661 }
1662
1663 static TypeInfoInvariantDeclaration create(Type tinfo)
1664 {
1665 return new TypeInfoInvariantDeclaration(tinfo);
1666 }
1667
1668 override void accept(Visitor v)
1669 {
1670 v.visit(this);
1671 }
1672 }
1673
1674 /***********************************************************
1675 */
1676 extern (C++) final class TypeInfoSharedDeclaration : TypeInfoDeclaration
1677 {
1678 extern (D) this(Type tinfo)
1679 {
1680 super(tinfo);
1681 if (!Type.typeinfoshared)
1682 {
1683 ObjectNotFound(loc, Id.TypeInfo_Shared);
1684 }
1685 type = Type.typeinfoshared.type;
1686 }
1687
1688 static TypeInfoSharedDeclaration create(Type tinfo)
1689 {
1690 return new TypeInfoSharedDeclaration(tinfo);
1691 }
1692
1693 override void accept(Visitor v)
1694 {
1695 v.visit(this);
1696 }
1697 }
1698
1699 /***********************************************************
1700 */
1701 extern (C++) final class TypeInfoWildDeclaration : TypeInfoDeclaration
1702 {
1703 extern (D) this(Type tinfo)
1704 {
1705 super(tinfo);
1706 if (!Type.typeinfowild)
1707 {
1708 ObjectNotFound(loc, Id.TypeInfo_Wild);
1709 }
1710 type = Type.typeinfowild.type;
1711 }
1712
1713 static TypeInfoWildDeclaration create(Type tinfo)
1714 {
1715 return new TypeInfoWildDeclaration(tinfo);
1716 }
1717
1718 override void accept(Visitor v)
1719 {
1720 v.visit(this);
1721 }
1722 }
1723
1724 /***********************************************************
1725 */
1726 extern (C++) final class TypeInfoVectorDeclaration : TypeInfoDeclaration
1727 {
1728 extern (D) this(Type tinfo)
1729 {
1730 super(tinfo);
1731 if (!Type.typeinfovector)
1732 {
1733 ObjectNotFound(loc, Id.TypeInfo_Vector);
1734 }
1735 type = Type.typeinfovector.type;
1736 }
1737
1738 static TypeInfoVectorDeclaration create(Type tinfo)
1739 {
1740 return new TypeInfoVectorDeclaration(tinfo);
1741 }
1742
1743 override void accept(Visitor v)
1744 {
1745 v.visit(this);
1746 }
1747 }
1748
1749 /***********************************************************
1750 * For the "this" parameter to member functions
1751 */
1752 extern (C++) final class ThisDeclaration : VarDeclaration
1753 {
1754 extern (D) this(Loc loc, Type t)
1755 {
1756 super(loc, t, Id.This, null);
1757 this.dsym = DSYM.thisDeclaration;
1758 storage_class |= STC.nodtor;
1759 }
1760
1761 override ThisDeclaration syntaxCopy(Dsymbol s)
1762 {
1763 assert(0); // should never be produced by syntax
1764 }
1765
1766 override void accept(Visitor v)
1767 {
1768 v.visit(this);
1769 }
1770 }