2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2007 by Digital Mars
5 // written by Walter Bright
6 // http://www.digitalmars.com
7 // License for redistribution is by either the Artistic License
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
9 // See the included readme.txt for details.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, December 2006
21 #include "declaration.h"
26 #include "aggregate.h"
29 #include "expression.h"
32 /********************************* Declaration ****************************/
34 Declaration::Declaration(Identifier
*id
)
39 storage_class
= STCundefined
;
40 protection
= PROTundefined
;
41 linkage
= LINKdefault
;
45 void Declaration::semantic(Scope
*sc
)
49 char *Declaration::kind()
54 target_size_t
Declaration::size(Loc loc
)
60 int Declaration::isStaticConstructor()
65 int Declaration::isStaticDestructor()
70 int Declaration::isDelete()
75 int Declaration::isDataseg()
80 int Declaration::isCodeseg()
85 enum PROT
Declaration::prot()
90 /********************************* TupleDeclaration ****************************/
92 TupleDeclaration::TupleDeclaration(Loc loc
, Identifier
*id
, Objects
*objects
)
96 this->objects
= objects
;
98 this->tupletype
= NULL
;
101 Dsymbol
*TupleDeclaration::syntaxCopy(Dsymbol
*s
)
107 char *TupleDeclaration::kind()
112 Type
*TupleDeclaration::getType()
114 /* If this tuple represents a type, return that type
117 //printf("TupleDeclaration::getType() %s\n", toChars());
122 /* It's only a type tuple if all the Object's are types
124 for (size_t i
= 0; i
< objects
->dim
; i
++)
125 { Object
*o
= (Object
*)objects
->data
[i
];
127 if (o
->dyncast() != DYNCAST_TYPE
)
129 //printf("\tnot[%d], %p, %d\n", i, o, o->dyncast());
134 /* We know it's a type tuple, so build the TypeTuple
136 Arguments
*args
= new Arguments();
137 args
->setDim(objects
->dim
);
139 for (size_t i
= 0; i
< objects
->dim
; i
++)
140 { Type
*t
= (Type
*)objects
->data
[i
];
142 //printf("type = %s\n", t->toChars());
144 buf
.printf("_%s_%d", ident
->toChars(), i
);
145 char *name
= (char *)buf
.extractData();
146 Identifier
*id
= new Identifier(name
, TOKidentifier
);
147 Argument
*arg
= new Argument(STCin
, t
, id
, NULL
);
149 Argument
*arg
= new Argument(STCin
, t
, NULL
, NULL
);
151 args
->data
[i
] = (void *)arg
;
154 tupletype
= new TypeTuple(args
);
160 int TupleDeclaration::needThis()
162 //printf("TupleDeclaration::needThis(%s)\n", toChars());
163 for (size_t i
= 0; i
< objects
->dim
; i
++)
164 { Object
*o
= (Object
*)objects
->data
[i
];
165 if (o
->dyncast() == DYNCAST_EXPRESSION
)
166 { Expression
*e
= (Expression
*)o
;
167 if (e
->op
== TOKdsymbol
)
168 { DsymbolExp
*ve
= (DsymbolExp
*)e
;
169 Declaration
*d
= ve
->s
->isDeclaration();
170 if (d
&& d
->needThis())
180 /********************************* TypedefDeclaration ****************************/
182 TypedefDeclaration::TypedefDeclaration(Loc loc
, Identifier
*id
, Type
*basetype
, Initializer
*init
)
185 this->type
= new TypeTypedef(this);
186 this->basetype
= basetype
->toBasetype();
190 this->hbasetype
= NULL
;
198 Dsymbol
*TypedefDeclaration::syntaxCopy(Dsymbol
*s
)
200 Type
*basetype
= this->basetype
->syntaxCopy();
202 Initializer
*init
= NULL
;
204 init
= this->init
->syntaxCopy();
207 TypedefDeclaration
*st
;
208 st
= new TypedefDeclaration(loc
, ident
, basetype
, init
);
210 // Syntax copy for header file
211 if (!htype
) // Don't overwrite original
212 { if (type
) // Make copy for both old and new instances
213 { htype
= type
->syntaxCopy();
214 st
->htype
= type
->syntaxCopy();
217 else // Make copy of original for new instance
218 st
->htype
= htype
->syntaxCopy();
221 { hbasetype
= basetype
->syntaxCopy();
222 st
->hbasetype
= basetype
->syntaxCopy();
226 st
->hbasetype
= hbasetype
->syntaxCopy();
231 void TypedefDeclaration::semantic(Scope
*sc
)
233 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
236 basetype
= basetype
->semantic(loc
, sc
);
238 type
= type
->semantic(loc
, sc
);
240 attributes
->append(sc
->attributes
);
242 attributes
= sc
->attributes
;
243 if (sc
->parent
->isFuncDeclaration() && init
)
248 error("circular definition");
252 void TypedefDeclaration::semantic2(Scope
*sc
)
254 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
259 init
= init
->semantic(sc
, basetype
);
261 ExpInitializer
*ie
= init
->isExpInitializer();
264 if (ie
->exp
->type
== basetype
)
265 ie
->exp
->type
= type
;
271 char *TypedefDeclaration::kind()
276 Type
*TypedefDeclaration::getType()
281 void TypedefDeclaration::toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
)
283 buf
->writestring("typedef ");
284 basetype
->toCBuffer(buf
, ident
, hgs
);
287 buf
->writestring(" = ");
288 init
->toCBuffer(buf
, hgs
);
294 /********************************* AliasDeclaration ****************************/
296 AliasDeclaration::AliasDeclaration(Loc loc
, Identifier
*id
, Type
*type
)
299 //printf("AliasDeclaration(id = '%s', type = %p)\n", id->toChars(), type);
300 //printf("type = '%s'\n", type->toChars());
303 this->aliassym
= NULL
;
306 this->haliassym
= NULL
;
308 this->overnext
= NULL
;
309 this->inSemantic
= 0;
313 AliasDeclaration::AliasDeclaration(Loc loc
, Identifier
*id
, Dsymbol
*s
)
316 //printf("AliasDeclaration(id = '%s', s = %p)\n", id->toChars(), s);
323 this->haliassym
= NULL
;
325 this->overnext
= NULL
;
326 this->inSemantic
= 0;
330 Dsymbol
*AliasDeclaration::syntaxCopy(Dsymbol
*s
)
333 AliasDeclaration
*sa
;
335 sa
= new AliasDeclaration(loc
, ident
, type
->syntaxCopy());
337 sa
= new AliasDeclaration(loc
, ident
, aliassym
->syntaxCopy(NULL
));
339 // Syntax copy for header file
340 if (!htype
) // Don't overwrite original
341 { if (type
) // Make copy for both old and new instances
342 { htype
= type
->syntaxCopy();
343 sa
->htype
= type
->syntaxCopy();
346 else // Make copy of original for new instance
347 sa
->htype
= htype
->syntaxCopy();
350 { haliassym
= aliassym
->syntaxCopy(s
);
351 sa
->haliassym
= aliassym
->syntaxCopy(s
);
355 sa
->haliassym
= haliassym
->syntaxCopy(s
);
360 void AliasDeclaration::semantic(Scope
*sc
)
362 //printf("AliasDeclaration::semantic() %s\n", toChars());
365 if (aliassym
->isTemplateInstance())
366 aliassym
->semantic(sc
);
369 this->inSemantic
= 1;
371 if (storage_class
& STCconst
)
372 error("cannot be const");
374 storage_class
|= sc
->stc
& STCdeprecated
;
377 // alias foo.bar.abc def;
378 // it is not knowable from the syntax whether this is an alias
379 // for a type or an alias for a symbol. It is up to the semantic()
380 // pass to distinguish.
381 // If it is a type, then type is set and getType() will return that
382 // type. If it is a symbol, then aliassym is set and type is NULL -
383 // toAlias() will return aliasssym.
389 /* This section is needed because resolve() will:
392 * try to alias y to 3.
394 s
= type
->toDsymbol(sc
);
396 goto L2
; // it's a symbolic alias
398 //printf("alias type is %s\n", type->toChars());
399 type
->resolve(loc
, sc
, &e
, &t
, &s
);
406 // Try to convert Expression to Dsymbol
408 { s
= ((VarExp
*)e
)->var
;
411 else if (e
->op
== TOKfunction
)
412 { s
= ((FuncExp
*)e
)->fd
;
416 { error("cannot alias an expression %s", e
->toChars());
423 ScopeDsymbol::multiplyDefined(0, this, overnext
);
424 this->inSemantic
= 0;
428 //printf("alias is a symbol %s %s\n", s->kind(), s->toChars());
430 VarDeclaration
*v
= s
->isVarDeclaration();
431 if (v
&& v
->linkage
== LINKdefault
)
433 error("forward reference of %s", v
->toChars());
438 FuncDeclaration
*f
= s
->toAlias()->isFuncDeclaration();
443 FuncAliasDeclaration
*fa
= new FuncAliasDeclaration(f
);
444 if (!fa
->overloadInsert(overnext
))
445 ScopeDsymbol::multiplyDefined(0, f
, overnext
);
448 s
->parent
= sc
->parent
;
452 ScopeDsymbol::multiplyDefined(0, s
, overnext
);
455 assert(global
.errors
);
460 this->inSemantic
= 0;
463 int AliasDeclaration::overloadInsert(Dsymbol
*s
)
465 /* Don't know yet what the aliased symbol is, so assume it can
466 * be overloaded and check later for correctness.
469 //printf("AliasDeclaration::overloadInsert('%s')\n", s->toChars());
470 if (overnext
== NULL
)
476 return overnext
->overloadInsert(s
);
480 char *AliasDeclaration::kind()
485 Type
*AliasDeclaration::getType()
490 Dsymbol
*AliasDeclaration::toAlias()
492 //printf("AliasDeclaration::toAlias('%s', this = %p, aliassym = %p, kind = '%s')\n", toChars(), this, aliassym, aliassym ? aliassym->kind() : "");
493 assert(this != aliassym
);
494 //static int count; if (++count == 10) *(char*)0=0;
496 { error("recursive alias declaration");
499 Dsymbol
*s
= aliassym
? aliassym
->toAlias() : this;
503 void AliasDeclaration::toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
)
505 buf
->writestring("alias ");
511 haliassym
->toCBuffer(buf
, hgs
);
513 buf
->writestring(ident
->toChars());
516 htype
->toCBuffer(buf
, ident
, hgs
);
523 aliassym
->toCBuffer(buf
, hgs
);
525 buf
->writestring(ident
->toChars());
528 type
->toCBuffer(buf
, ident
, hgs
);
534 /********************************* VarDeclaration ****************************/
536 VarDeclaration::VarDeclaration(Loc loc
, Type
*type
, Identifier
*id
, Initializer
*init
)
539 //printf("VarDeclaration('%s')\n", id->toChars());
542 { printf("VarDeclaration('%s')\n", id
->toChars());
546 assert(type
|| init
);
566 Dsymbol
*VarDeclaration::syntaxCopy(Dsymbol
*s
)
568 //printf("VarDeclaration::syntaxCopy(%s)\n", toChars());
572 { sv
= (VarDeclaration
*)s
;
576 Initializer
*init
= NULL
;
578 { init
= this->init
->syntaxCopy();
579 //init->isExpInitializer()->exp->print();
580 //init->isExpInitializer()->exp->dump(0);
583 sv
= new VarDeclaration(loc
, type
? type
->syntaxCopy() : NULL
, ident
, init
);
584 sv
->storage_class
= storage_class
;
587 // Syntax copy for header file
588 if (!htype
) // Don't overwrite original
589 { if (type
) // Make copy for both old and new instances
590 { htype
= type
->syntaxCopy();
591 sv
->htype
= type
->syntaxCopy();
594 else // Make copy of original for new instance
595 sv
->htype
= htype
->syntaxCopy();
598 { hinit
= init
->syntaxCopy();
599 sv
->hinit
= init
->syntaxCopy();
603 sv
->hinit
= hinit
->syntaxCopy();
608 void VarDeclaration::semantic(Scope
*sc
)
610 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars());
611 //printf("type = %s\n", type->toChars());
612 //printf("linkage = %d\n", sc->linkage);
613 //if (strcmp(toChars(), "mul") == 0) halt();
615 storage_class
|= sc
->stc
;
616 if (storage_class
& STCextern
&& init
)
617 error("extern symbols cannot have initializers");
619 /* If auto type inference, do the inference
624 type
= init
->inferType(sc
);
628 /* This is a kludge to support the existing syntax for RAII
631 storage_class
&= ~STCauto
;
637 type
= type
->semantic(loc
, sc
);
640 type
->checkDeprecated(loc
, sc
);
641 linkage
= sc
->linkage
;
642 this->parent
= sc
->parent
;
643 //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars());
644 protection
= sc
->protection
;
646 attributes
->append(sc
->attributes
);
648 attributes
= sc
->attributes
;
649 //printf("sc->stc = %x\n", sc->stc);
650 //printf("storage_class = %x\n", storage_class);
652 Dsymbol
*parent
= toParent();
653 FuncDeclaration
*fd
= parent
->isFuncDeclaration();
655 Type
*tb
= type
->toBasetype();
656 if (tb
->ty
== Tvoid
&& !(storage_class
& STClazy
))
657 { error("voids have no value");
661 if (tb
->ty
== Tfunction
)
662 { error("cannot be declared to be a function");
666 if (tb
->ty
== Tstruct
)
667 { TypeStruct
*ts
= (TypeStruct
*)tb
;
669 if (!ts
->sym
->members
)
671 error("no definition of struct %s", ts
->toChars());
675 if (tb
->ty
== Ttuple
)
676 { /* Instead, declare variables for each of the tuple elements
679 TypeTuple
*tt
= (TypeTuple
*)tb
;
680 size_t nelems
= Argument::dim(tt
->arguments
);
681 Objects
*exps
= new Objects();
682 exps
->setDim(nelems
);
683 Expression
*ie
= init
? init
->toExpression() : NULL
;
685 for (size_t i
= 0; i
< nelems
; i
++)
686 { Argument
*arg
= Argument::getNth(tt
->arguments
, i
);
689 buf
.printf("_%s_field_%"PRIuSIZE
, ident
->toChars(), i
);
691 char *name
= (char *)buf
.extractData();
692 Identifier
*id
= new Identifier(name
, TOKidentifier
);
694 Expression
*einit
= ie
;
695 if (ie
&& ie
->op
== TOKtuple
)
696 { einit
= (Expression
*)((TupleExp
*)ie
)->exps
->data
[i
];
698 Initializer
*ti
= init
;
700 { ti
= new ExpInitializer(einit
->loc
, einit
);
703 VarDeclaration
*v
= new VarDeclaration(loc
, arg
->type
, id
, ti
);
704 //printf("declaring field %s of type %s\n", v->toChars(), v->type->toChars());
708 { //printf("adding %s to %s\n", v->toChars(), sc->scopesym->toChars());
709 if (sc
->scopesym
->members
)
710 sc
->scopesym
->members
->push(v
);
713 Expression
*e
= new DsymbolExp(loc
, v
);
716 TupleDeclaration
*v2
= new TupleDeclaration(loc
, ident
, exps
);
722 if (storage_class
& STCconst
&& !init
&& !fd
)
723 // Initialize by constructor only
724 storage_class
= (storage_class
& ~STCconst
) | STCctorinit
;
732 else if (isSynchronized())
734 error("variable %s cannot be synchronized", toChars());
736 else if (isOverride())
738 error("override cannot be applied to variable");
740 else if (isAbstract())
742 error("abstract cannot be applied to variable");
744 else if (storage_class
& STCtemplateparameter
)
749 AggregateDeclaration
*aad
= sc
->anonAgg
;
751 aad
= parent
->isAggregateDeclaration();
754 aad
->addField(sc
, this);
757 InterfaceDeclaration
*id
= parent
->isInterfaceDeclaration();
760 error("field not allowed in interface");
763 TemplateInstance
*ti
= parent
->isTemplateInstance();
766 // Take care of nested templates
769 TemplateInstance
*ti2
= ti
->tempdecl
->parent
->isTemplateInstance();
775 // If it's a member template
776 AggregateDeclaration
*ad
= ti
->tempdecl
->isMember();
777 if (ad
&& storage_class
!= STCundefined
)
779 error("cannot use template to add field to aggregate '%s'", ad
->toChars());
784 if (type
->isauto() && !noauto
)
786 if (storage_class
& (STCfield
| STCout
| STCref
| STCstatic
) || !fd
)
788 error("globals, statics, fields, ref and out parameters cannot be auto");
791 if (!(storage_class
& (STCauto
| STCscope
)))
793 if (!(storage_class
& STCparameter
) && ident
!= Id::withSym
)
794 error("reference to scope class must be scope");
798 if (!init
&& !sc
->inunion
&& !isStatic() && !isConst() && fd
&&
799 !(storage_class
& (STCfield
| STCin
| STCforeach
)) &&
802 // Provide a default initializer
803 //printf("Providing default initializer for '%s'\n", toChars());
804 if (type
->ty
== Tstruct
&&
805 ((TypeStruct
*)type
)->sym
->zeroInit
== 1)
806 { /* If a struct is all zeros, as a special case
807 * set it's initializer to the integer 0.
808 * In AssignExp::toElem(), we check for this and issue
809 * a memset() to initialize the struct.
810 * Must do same check in interpreter.
812 Expression
*e
= new IntegerExp(loc
, 0, Type::tint32
);
814 e1
= new VarExp(loc
, this);
815 e
= new AssignExp(loc
, e1
, e
);
817 init
= new ExpInitializer(loc
, e
/*->type->defaultInit()*/);
820 else if (type
->ty
== Ttypedef
)
821 { TypeTypedef
*td
= (TypeTypedef
*)type
;
823 { init
= td
->sym
->init
;
824 ExpInitializer
*ie
= init
->isExpInitializer();
826 // Make copy so we can modify it
827 init
= new ExpInitializer(ie
->loc
, ie
->exp
);
830 init
= getExpInitializer();
834 init
= getExpInitializer();
840 ArrayInitializer
*ai
= init
->isArrayInitializer();
841 if (ai
&& tb
->ty
== Taarray
)
843 init
= ai
->toAssocArrayInitializer();
846 StructInitializer
*si
= init
->isStructInitializer();
847 ExpInitializer
*ei
= init
->isExpInitializer();
849 // See if we can allocate on the stack
850 if (ei
&& isScope() && ei
->exp
->op
== TOKnew
)
851 { NewExp
*ne
= (NewExp
*)ei
->exp
;
852 if (!(ne
->newargs
&& ne
->newargs
->dim
))
855 if (type
->isBaseOf(ne
->newtype
->semantic(loc
, sc
), NULL
))
860 // If inside function, there is no semantic3() call
863 // If local variable, use AssignExp to handle all the various
865 if (fd
&& !isStatic() && !isConst() && !init
->isVoidInitializer())
871 //printf("fd = '%s', var = '%s'\n", fd->toChars(), toChars());
874 Expression
*e
= init
->toExpression();
877 init
= init
->semantic(sc
, type
);
878 e
= init
->toExpression();
880 { error("is not a static and cannot have static initializer");
884 ei
= new ExpInitializer(init
->loc
, e
);
888 e1
= new VarExp(loc
, this);
890 t
= type
->toBasetype();
891 if (t
->ty
== Tsarray
)
893 ei
->exp
= ei
->exp
->semantic(sc
);
894 if (!ei
->exp
->implicitConvTo(type
))
896 dim
= ((TypeSArray
*)t
)->dim
->toInteger();
897 // If multidimensional static array, treat as one large array
900 t
= t
->nextOf()->toBasetype();
901 if (t
->ty
!= Tsarray
)
903 dim
*= ((TypeSArray
*)t
)->dim
->toInteger();
904 e1
->type
= new TypeSArray(t
->nextOf(), new IntegerExp(0, dim
, Type::tindex
));
907 e1
= new SliceExp(loc
, e1
, NULL
, NULL
);
909 else if (t
->ty
== Tstruct
)
911 ei
->exp
= ei
->exp
->semantic(sc
);
912 if (!ei
->exp
->implicitConvTo(type
))
913 ei
->exp
= new CastExp(loc
, ei
->exp
, type
);
915 ei
->exp
= new AssignExp(loc
, e1
, ei
->exp
);
916 ei
->exp
->op
= TOKconstruct
;
918 ei
->exp
= ei
->exp
->semantic(sc
);
920 ei
->exp
->optimize(WANTvalue
);
924 init
= init
->semantic(sc
, type
);
925 if (fd
&& isConst() && !isStatic())
927 storage_class
|= STCstatic
;
931 else if (isConst() || isFinal())
933 /* Because we may need the results of a const declaration in a
934 * subsequent type, such as an array dimension, before semantic2()
935 * gets ordinarily run, try to run semantic2() now.
939 if (!global
.errors
&& !inferred
)
941 unsigned errors
= global
.errors
;
945 Initializer
*i2
= init
;
949 e
= ei
->exp
->syntaxCopy();
951 e
= e
->implicitCastTo(sc
, type
);
954 { i2
= init
->syntaxCopy();
955 i2
= i2
->semantic(sc
, type
);
960 if (errors
!= global
.errors
) // if errors happened
963 global
.errors
= errors
; // act as if nothing happened
967 e
= e
->optimize(WANTvalue
| WANTinterpret
);
968 if (e
->op
== TOKint64
|| e
->op
== TOKstring
)
970 ei
->exp
= e
; // no errors, keep result
974 init
= i2
; // no errors, keep result
980 ExpInitializer
*VarDeclaration::getExpInitializer()
985 ei
= init
->isExpInitializer();
988 if ((type
->ty
== Tclass
|| type
->ty
== Tpointer
) && !skipnullcheck
)
989 error("missing initialiser for non-null variable %s", this->toChars());
991 Expression
*e
= type
->defaultInit();
993 ei
= new ExpInitializer(loc
, e
);
1000 void VarDeclaration::semantic2(Scope
*sc
)
1002 //printf("VarDeclaration::semantic2('%s')\n", toChars());
1003 if (init
&& !toParent()->isFuncDeclaration())
1006 ExpInitializer
*ei
= init
->isExpInitializer();
1010 printf("type = %p\n", ei
->exp
->type
);
1013 init
= init
->semantic(sc
, type
);
1018 char *VarDeclaration::kind()
1023 Dsymbol
*VarDeclaration::toAlias()
1025 //printf("VarDeclaration::toAlias('%s', this = %p, aliassym = %p)\n", toChars(), this, aliassym);
1026 assert(this != aliassym
);
1027 Dsymbol
*s
= aliassym
? aliassym
->toAlias() : this;
1031 void VarDeclaration::toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
)
1033 if (storage_class
& STCconst
)
1034 buf
->writestring("const ");
1035 if (storage_class
& STCstatic
)
1036 buf
->writestring("static ");
1038 type
->toCBuffer(buf
, ident
, hgs
);
1040 buf
->writestring(ident
->toChars());
1042 { buf
->writestring(" = ");
1043 init
->toCBuffer(buf
, hgs
);
1045 buf
->writeByte(';');
1049 int VarDeclaration::needThis()
1051 //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class);
1052 return storage_class
& STCfield
;
1055 int VarDeclaration::isImportedSymbol()
1057 if (protection
== PROTexport
&& !init
&& (isStatic() || isConst() || parent
->isModule()))
1062 void VarDeclaration::checkCtorConstInit()
1064 if (ctorinit
== 0 && isCtorinit() && !(storage_class
& STCfield
))
1065 error("missing initializer in static constructor for const variable");
1068 /************************************
1069 * Check to see if variable is a reference to an enclosing function
1073 void VarDeclaration::checkNestedReference(Scope
*sc
, Loc loc
)
1075 if (parent
&& !isDataseg() && parent
!= sc
->parent
)
1077 FuncDeclaration
*fdv
= toParent()->isFuncDeclaration();
1078 FuncDeclaration
*fdthis
= sc
->parent
->isFuncDeclaration();
1083 fdthis
->getLevel(loc
, fdv
);
1085 fdv
->nestedFrameRef
= 1;
1086 //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars());
1091 /*******************************
1092 * Does symbol go into data segment?
1095 int VarDeclaration::isDataseg()
1098 printf("VarDeclaration::isDataseg(%p, '%s')\n", this, toChars());
1099 printf("%x, %p, %p\n", storage_class
& (STCstatic
| STCconst
), parent
->isModule(), parent
->isTemplateInstance());
1100 printf("parent = '%s'\n", parent
->toChars());
1102 Dsymbol
*parent
= this->toParent();
1103 if (!parent
&& !(storage_class
& (STCstatic
| STCconst
)))
1104 { error("forward referenced");
1105 type
= Type::terror
;
1108 return (storage_class
& (STCstatic
| STCconst
) ||
1109 parent
->isModule() ||
1110 parent
->isTemplateInstance());
1113 int VarDeclaration::hasPointers()
1115 return (!isDataseg() && type
->hasPointers());
1118 /******************************************
1119 * If a variable has an auto destructor call, return call for it.
1120 * Otherwise, return NULL.
1123 Expression
*VarDeclaration::callAutoDtor()
1124 { Expression
*e
= NULL
;
1126 //printf("VarDeclaration::callAutoDtor() %s\n", toChars());
1127 if (storage_class
& (STCauto
| STCscope
) && !noauto
)
1129 for (ClassDeclaration
*cd
= type
->isClassHandle();
1133 /* We can do better if there's a way with onstack
1134 * classes to determine if there's no way the monitor
1137 //if (cd->isInterfaceDeclaration())
1138 //error("interface %s cannot be scope", cd->toChars());
1139 if (1 || onstack
|| cd
->dtors
.dim
) // if any destructors
1144 ec
= new VarExp(loc
, this);
1145 e
= new DeleteExp(loc
, ec
);
1146 e
->type
= Type::tvoid
;
1155 /********************************* ClassInfoDeclaration ****************************/
1157 ClassInfoDeclaration::ClassInfoDeclaration(ClassDeclaration
*cd
)
1158 : VarDeclaration(0, ClassDeclaration::classinfo
->type
, cd
->ident
, NULL
)
1161 storage_class
= STCstatic
;
1164 Dsymbol
*ClassInfoDeclaration::syntaxCopy(Dsymbol
*s
)
1166 assert(0); // should never be produced by syntax
1170 void ClassInfoDeclaration::semantic(Scope
*sc
)
1174 /********************************* ModuleInfoDeclaration ****************************/
1176 ModuleInfoDeclaration::ModuleInfoDeclaration(Module
*mod
)
1177 : VarDeclaration(0, Module::moduleinfo
->type
, mod
->ident
, NULL
)
1180 storage_class
= STCstatic
;
1183 Dsymbol
*ModuleInfoDeclaration::syntaxCopy(Dsymbol
*s
)
1185 assert(0); // should never be produced by syntax
1189 void ModuleInfoDeclaration::semantic(Scope
*sc
)
1193 /********************************* TypeInfoDeclaration ****************************/
1195 TypeInfoDeclaration::TypeInfoDeclaration(Type
*tinfo
, int internal
)
1196 : VarDeclaration(0, Type::typeinfo
->type
, tinfo
->getTypeInfoIdent(internal
), NULL
)
1198 this->tinfo
= tinfo
;
1199 storage_class
= STCstatic
;
1200 protection
= PROTpublic
;
1204 Dsymbol
*TypeInfoDeclaration::syntaxCopy(Dsymbol
*s
)
1206 assert(0); // should never be produced by syntax
1210 void TypeInfoDeclaration::semantic(Scope
*sc
)
1212 assert(linkage
== LINKc
);
1215 /***************************** TypeInfoConstDeclaration **********************/
1218 TypeInfoConstDeclaration::TypeInfoConstDeclaration(Type
*tinfo
)
1219 : TypeInfoDeclaration(tinfo
, 0)
1224 /***************************** TypeInfoInvariantDeclaration **********************/
1227 TypeInfoInvariantDeclaration::TypeInfoInvariantDeclaration(Type
*tinfo
)
1228 : TypeInfoDeclaration(tinfo
, 0)
1233 /***************************** TypeInfoStructDeclaration **********************/
1235 TypeInfoStructDeclaration::TypeInfoStructDeclaration(Type
*tinfo
)
1236 : TypeInfoDeclaration(tinfo
, 0)
1240 /***************************** TypeInfoClassDeclaration ***********************/
1242 TypeInfoClassDeclaration::TypeInfoClassDeclaration(Type
*tinfo
)
1243 : TypeInfoDeclaration(tinfo
, 0)
1247 /***************************** TypeInfoInterfaceDeclaration *******************/
1249 TypeInfoInterfaceDeclaration::TypeInfoInterfaceDeclaration(Type
*tinfo
)
1250 : TypeInfoDeclaration(tinfo
, 0)
1254 /***************************** TypeInfoTypedefDeclaration *********************/
1256 TypeInfoTypedefDeclaration::TypeInfoTypedefDeclaration(Type
*tinfo
)
1257 : TypeInfoDeclaration(tinfo
, 0)
1261 /***************************** TypeInfoPointerDeclaration *********************/
1263 TypeInfoPointerDeclaration::TypeInfoPointerDeclaration(Type
*tinfo
)
1264 : TypeInfoDeclaration(tinfo
, 0)
1268 /***************************** TypeInfoMaybeDeclaration *********************/
1270 TypeInfoMaybeDeclaration::TypeInfoMaybeDeclaration(Type
*tinfo
)
1271 : TypeInfoDeclaration(tinfo
, 0)
1275 /***************************** TypeInfoArrayDeclaration ***********************/
1277 TypeInfoArrayDeclaration::TypeInfoArrayDeclaration(Type
*tinfo
)
1278 : TypeInfoDeclaration(tinfo
, 0)
1282 /***************************** TypeInfoStaticArrayDeclaration *****************/
1284 TypeInfoStaticArrayDeclaration::TypeInfoStaticArrayDeclaration(Type
*tinfo
)
1285 : TypeInfoDeclaration(tinfo
, 0)
1289 /***************************** TypeInfoAssociativeArrayDeclaration ************/
1291 TypeInfoAssociativeArrayDeclaration::TypeInfoAssociativeArrayDeclaration(Type
*tinfo
)
1292 : TypeInfoDeclaration(tinfo
, 0)
1296 /***************************** TypeInfoEnumDeclaration ***********************/
1298 TypeInfoEnumDeclaration::TypeInfoEnumDeclaration(Type
*tinfo
)
1299 : TypeInfoDeclaration(tinfo
, 0)
1303 /***************************** TypeInfoFunctionDeclaration ********************/
1305 TypeInfoFunctionDeclaration::TypeInfoFunctionDeclaration(Type
*tinfo
)
1306 : TypeInfoDeclaration(tinfo
, 0)
1310 /***************************** TypeInfoDelegateDeclaration ********************/
1312 TypeInfoDelegateDeclaration::TypeInfoDelegateDeclaration(Type
*tinfo
)
1313 : TypeInfoDeclaration(tinfo
, 0)
1317 /***************************** TypeInfoTupleDeclaration **********************/
1319 TypeInfoTupleDeclaration::TypeInfoTupleDeclaration(Type
*tinfo
)
1320 : TypeInfoDeclaration(tinfo
, 0)
1324 /********************************* ThisDeclaration ****************************/
1326 // For the "this" parameter to member functions
1328 ThisDeclaration::ThisDeclaration(Type
*t
)
1329 : VarDeclaration(0, t
, Id::This
, NULL
)
1334 Dsymbol
*ThisDeclaration::syntaxCopy(Dsymbol
*s
)
1336 assert(0); // should never be produced by syntax