comparison dmd/VarDeclaration.d @ 98:5c859d5fbe27

and more
author Trass3r
date Tue, 31 Aug 2010 03:53:49 +0200
parents 23280d154c5b
children e6090d1aea7c
comparison
equal deleted inserted replaced
96:acd69f84627e 98:5c859d5fbe27
72 { 72 {
73 Initializer init; 73 Initializer init;
74 uint offset; 74 uint offset;
75 bool noauto; // no auto semantics 75 bool noauto; // no auto semantics
76 version (DMDV2) { 76 version (DMDV2) {
77 FuncDeclarations nestedrefs; // referenced by these lexically nested functions 77 FuncDeclarations nestedrefs; // referenced by these lexically nested functions
78 bool isargptr = false; // if parameter that _argptr points to
78 } else { 79 } else {
79 int nestedref; // referenced by a lexically nested function 80 int nestedref; // referenced by a lexically nested function
80 } 81 }
81 int ctorinit; // it has been initialized in a ctor 82 int ctorinit; // it has been initialized in a ctor
82 int onstack; // 1: it has been allocated on the stack 83 int onstack; // 1: it has been allocated on the stack
93 94
94 this(Loc loc, Type type, Identifier id, Initializer init) 95 this(Loc loc, Type type, Identifier id, Initializer init)
95 { 96 {
96 super(id); 97 super(id);
97 98
98 debug { 99 debug
100 {
99 if (!type && !init) 101 if (!type && !init)
100 { 102 {
101 writef("VarDeclaration('%s')\n", id.toChars()); 103 writef("VarDeclaration('%s')\n", id.toChars());
102 //*(char*)0=0; 104 //*(char*)0=0;
103 } 105 }
104 } 106 }
105 assert(type || init); 107 assert(type || init);
106 this.type = type; 108 this.type = type;
107 this.init = init; 109 this.init = init;
110 version(_DH)
111 {
112 this.htype = null;
113 this.hinit = null;
114 }
108 this.loc = loc; 115 this.loc = loc;
109 116
117 /* TODO:
118 #if DMDV1
119 nestedref = 0;
120 #endif
121 ctorinit = 0;
122 aliassym = NULL;
123 onstack = 0;
124 canassign = 0;
125 value = NULL;
126 rundtor = NULL;
127 */
110 nestedrefs = new FuncDeclarations(); 128 nestedrefs = new FuncDeclarations();
111 } 129 }
112 130
113 override Dsymbol syntaxCopy(Dsymbol s) 131 override Dsymbol syntaxCopy(Dsymbol s)
114 { 132 {
519 e1 = new SliceExp(loc, e1, null, null); 537 e1 = new SliceExp(loc, e1, null, null);
520 } 538 }
521 else if (t.ty == TY.Tstruct) 539 else if (t.ty == TY.Tstruct)
522 { 540 {
523 ei.exp = ei.exp.semantic(sc); 541 ei.exp = ei.exp.semantic(sc);
524 version (DMDV2) { 542 ei.exp = resolveProperties(sc, ei.exp);
543 StructDeclaration sd = (cast(TypeStruct)t).sym;
544 version (DMDV2)
545 {
525 /* Look to see if initializer is a call to the constructor 546 /* Look to see if initializer is a call to the constructor
526 */ 547 */
527 StructDeclaration sd = (cast(TypeStruct)t).sym;
528 if (sd.ctor && // there are constructors 548 if (sd.ctor && // there are constructors
529 ei.exp.type.ty == TY.Tstruct && // rvalue is the same struct 549 ei.exp.type.ty == TY.Tstruct && // rvalue is the same struct
530 (cast(TypeStruct)ei.exp.type).sym == sd && 550 (cast(TypeStruct)ei.exp.type).sym == sd &&
531 ei.exp.op == TOK.TOKstar) 551 ei.exp.op == TOK.TOKstar)
532 { 552 {
560 } 580 }
561 } 581 }
562 } 582 }
563 if (!ei.exp.implicitConvTo(type)) 583 if (!ei.exp.implicitConvTo(type))
564 { 584 {
585 Type *ti = ei.exp.type.toBasetype();
586 // Look for constructor first
587 if (sd.ctor &&
588 /* Initializing with the same type is done differently
589 */
590 !(ti.ty == Tstruct && t.toDsymbol(sc) == ti.toDsymbol(sc)))
591 {
592 // Rewrite as e1.ctor(arguments)
593 Expression ector = new DotIdExp(loc, e1, Id.ctor);
594 ei.exp = new CallExp(loc, ector, ei.exp);
595 }
596 else
565 /* Look for opCall 597 /* Look for opCall
566 * See bugzilla 2702 for more discussion 598 * See bugzilla 2702 for more discussion
567 */ 599 */
568 Type ti = ei.exp.type.toBasetype(); 600
569 // Don't cast away invariant or mutability in initializer 601 // Don't cast away invariant or mutability in initializer
570 if (search_function(sd, Id.call) && 602 if (search_function(sd, Id.call) &&
571 /* Initializing with the same type is done differently 603 /* Initializing with the same type is done differently
572 */ 604 */
573 !(ti.ty == Tstruct && t.toDsymbol(sc) == ti.toDsymbol(sc))) 605 !(ti.ty == Tstruct && t.toDsymbol(sc) == ti.toDsymbol(sc)))
588 { 620 {
589 init = init.semantic(sc, type); 621 init = init.semantic(sc, type);
590 } 622 }
591 } 623 }
592 else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) || 624 else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) ||
593 type.isConst() || type.isInvariant()) 625 type.isConst() || type.isInvariant() ||
626 parent.isAggregateDeclaration())
594 { 627 {
595 /* Because we may need the results of a const declaration in a 628 /* Because we may need the results of a const declaration in a
596 * subsequent type, such as an array dimension, before semantic2() 629 * subsequent type, such as an array dimension, before semantic2()
597 * gets ordinarily run, try to run semantic2() now. 630 * gets ordinarily run, try to run semantic2() now.
598 * Ignore failure. 631 * Ignore failure.