comparison dmd/declaration.c @ 19:788401029ecf trunk

[svn r23] * Updated to DMD 1.021
author lindquist
date Thu, 04 Oct 2007 03:42:56 +0200
parents c53b6e3fe49a
children 8b0e809563df
comparison
equal deleted inserted replaced
18:c05ef76f1c20 19:788401029ecf
769 { 769 {
770 // Provide a default initializer 770 // Provide a default initializer
771 //printf("Providing default initializer for '%s'\n", toChars()); 771 //printf("Providing default initializer for '%s'\n", toChars());
772 if (type->ty == Tstruct && 772 if (type->ty == Tstruct &&
773 ((TypeStruct *)type)->sym->zeroInit == 1) 773 ((TypeStruct *)type)->sym->zeroInit == 1)
774 { 774 { /* If a struct is all zeros, as a special case
775 * set it's initializer to the integer 0.
776 * In AssignExp::toElem(), we check for this and issue
777 * a memset() to initialize the struct.
778 * Must do same check in interpreter.
779 */
775 Expression *e = new IntegerExp(loc, 0, Type::tint32); 780 Expression *e = new IntegerExp(loc, 0, Type::tint32);
776 Expression *e1; 781 Expression *e1;
777 e1 = new VarExp(loc, this); 782 e1 = new VarExp(loc, this);
778 e = new AssignExp(loc, e1, e); 783 e = new AssignExp(loc, e1, e);
779 e->type = e1->type; 784 e->type = e1->type;
799 } 804 }
800 805
801 if (init) 806 if (init)
802 { 807 {
803 ArrayInitializer *ai = init->isArrayInitializer(); 808 ArrayInitializer *ai = init->isArrayInitializer();
804 if (ai && type->toBasetype()->ty == Taarray) 809 if (ai && tb->ty == Taarray)
805 { 810 {
806 init = ai->toAssocArrayInitializer(); 811 init = ai->toAssocArrayInitializer();
807 } 812 }
808 813
814 StructInitializer *si = init->isStructInitializer();
809 ExpInitializer *ei = init->isExpInitializer(); 815 ExpInitializer *ei = init->isExpInitializer();
810 816
811 // See if we can allocate on the stack 817 // See if we can allocate on the stack
812 if (ei && isScope() && ei->exp->op == TOKnew) 818 if (ei && isScope() && ei->exp->op == TOKnew)
813 { NewExp *ne = (NewExp *)ei->exp; 819 { NewExp *ne = (NewExp *)ei->exp;
896 * subsequent type, such as an array dimension, before semantic2() 902 * subsequent type, such as an array dimension, before semantic2()
897 * gets ordinarily run, try to run semantic2() now. 903 * gets ordinarily run, try to run semantic2() now.
898 * Ignore failure. 904 * Ignore failure.
899 */ 905 */
900 906
901 if (ei && !global.errors && !inferred) 907 if (!global.errors && !inferred)
902 { 908 {
903 unsigned errors = global.errors; 909 unsigned errors = global.errors;
904 global.gag++; 910 global.gag++;
905 //printf("+gag\n"); 911 //printf("+gag\n");
906 Expression *e = ei->exp->syntaxCopy(); 912 Expression *e;
913 Initializer *i2 = init;
907 inuse++; 914 inuse++;
908 e = e->semantic(sc); 915 if (ei)
916 {
917 e = ei->exp->syntaxCopy();
918 e = e->semantic(sc);
919 e = e->implicitCastTo(sc, type);
920 }
921 else if (si || ai)
922 { i2 = init->syntaxCopy();
923 i2 = i2->semantic(sc, type);
924 }
909 inuse--; 925 inuse--;
910 e = e->implicitCastTo(sc, type);
911 global.gag--; 926 global.gag--;
912 //printf("-gag\n"); 927 //printf("-gag\n");
913 if (errors != global.errors) // if errors happened 928 if (errors != global.errors) // if errors happened
914 { 929 {
915 if (global.gag == 0) 930 if (global.gag == 0)
916 global.errors = errors; // act as if nothing happened 931 global.errors = errors; // act as if nothing happened
917 } 932 }
918 else 933 else if (ei)
919 { 934 {
920 e = e->optimize(WANTvalue | WANTinterpret); 935 e = e->optimize(WANTvalue | WANTinterpret);
921 if (e->op == TOKint64 || e->op == TOKstring) 936 if (e->op == TOKint64 || e->op == TOKstring)
922 { 937 {
923 ei->exp = e; // no errors, keep result 938 ei->exp = e; // no errors, keep result
924 } 939 }
925 } 940 }
941 else
942 init = i2; // no errors, keep result
926 } 943 }
927 } 944 }
928 } 945 }
929 } 946 }
930 947