comparison dmd/VarDeclaration.d @ 135:af1bebfd96a4 dmd2037

dmd 2.038
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 13 Sep 2010 22:19:42 +0100
parents 60bb0fe4563e
children b7b61140701d
comparison
equal deleted inserted replaced
134:4251f96733f4 135:af1bebfd96a4
341 if (type.isConst()) 341 if (type.isConst())
342 { storage_class |= STC.STCconst; 342 { storage_class |= STC.STCconst;
343 if (type.isShared()) 343 if (type.isShared())
344 storage_class |= STC.STCshared; 344 storage_class |= STC.STCshared;
345 } 345 }
346 else if (type.isInvariant()) 346 else if (type.isImmutable())
347 storage_class |= STC.STCimmutable; 347 storage_class |= STC.STCimmutable;
348 else if (type.isShared()) 348 else if (type.isShared())
349 storage_class |= STC.STCshared; 349 storage_class |= STC.STCshared;
350 else if (type.isWild())
351 storage_class |= STC.STCwild;
350 352
351 if (isSynchronized()) 353 if (isSynchronized())
352 { 354 {
353 error("variable %s cannot be synchronized", toChars()); 355 error("variable %s cannot be synchronized", toChars());
354 } 356 }
420 version (DMDV2) { 422 version (DMDV2) {
421 if ((storage_class & (STC.STCref | STC.STCparameter | STC.STCforeach)) == STC.STCref && ident != Id.This) 423 if ((storage_class & (STC.STCref | STC.STCparameter | STC.STCforeach)) == STC.STCref && ident != Id.This)
422 { 424 {
423 error("only parameters or foreach declarations can be ref"); 425 error("only parameters or foreach declarations can be ref");
424 } 426 }
427
428 if ((storage_class & (STCstatic | STCextern | STCtls | STCgshared | STCmanifest) ||
429 isDataseg()) &&
430 type.hasWild())
431 {
432 error("only fields, parameters or stack based variables can be inout");
433 }
425 } 434 }
426 435
427 if (type.isauto() && !noauto) 436 if (type.isauto() && !noauto)
428 { 437 {
429 if (storage_class & (STC.STCfield | STC.STCout | STC.STCref | STC.STCstatic | STC.STCmanifest | STC.STCtls | STC.STCgshared) || !fd) 438 if (storage_class & (STC.STCfield | STC.STCout | STC.STCref | STC.STCstatic | STC.STCmanifest | STC.STCtls | STC.STCgshared) || !fd)
436 if (!(storage_class & STC.STCparameter) && ident != Id.withSym) 445 if (!(storage_class & STC.STCparameter) && ident != Id.withSym)
437 error("reference to scope class must be scope"); 446 error("reference to scope class must be scope");
438 } 447 }
439 } 448 }
440 449
441 if ((isConst() || isInvariant()) && !init && !fd) 450 if ((isConst() || isImmutable()) && !init && !fd)
442 { 451 {
443 // Initialize by constructor only 452 // Initialize by constructor only
444 storage_class |= STC.STCctorinit; 453 storage_class |= STC.STCctorinit;
445 } 454 }
446 455
650 { 659 {
651 init = init.semantic(sc, type); 660 init = init.semantic(sc, type);
652 } 661 }
653 } 662 }
654 else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) || 663 else if (storage_class & (STC.STCconst | STC.STCimmutable | STC.STCmanifest) ||
655 type.isConst() || type.isInvariant() || 664 type.isConst() || type.isImmutable() ||
656 parent.isAggregateDeclaration()) 665 parent.isAggregateDeclaration())
657 { 666 {
658 /* Because we may need the results of a const declaration in a 667 /* Because we may need the results of a const declaration in a
659 * subsequent type, such as an array dimension, before semantic2() 668 * subsequent type, such as an array dimension, before semantic2()
660 * gets ordinarily run, try to run semantic2() now. 669 * gets ordinarily run, try to run semantic2() now.
793 802
794 override bool isDataseg() 803 override bool isDataseg()
795 { 804 {
796 static if (false) { 805 static if (false) {
797 printf("VarDeclaration.isDataseg(%p, '%s')\n", this, toChars()); 806 printf("VarDeclaration.isDataseg(%p, '%s')\n", this, toChars());
798 printf("%x, %p, %p\n", storage_class & (STC.STCstatic | STC.STCconst), parent.isModule(), parent.isTemplateInstance()); 807 printf("%llx, isModule: %p, isTemplateInstance: %p\n", storage_class & (STC.STCstatic | STC.STCconst), parent.isModule(), parent.isTemplateInstance());
799 printf("parent = '%s'\n", parent.toChars()); 808 printf("parent = '%s'\n", parent.toChars());
800 } 809 }
801 if (storage_class & STC.STCmanifest) 810 if (storage_class & STC.STCmanifest)
802 return false; 811 return false;
803 812
828 //printf("\treturn %d\n", i); 837 //printf("\treturn %d\n", i);
829 return i; 838 return i;
830 } 839 }
831 } 840 }
832 841
842 /********************************************
843 * Can variable be read and written by CTFE?
844 */
845
846 int isCTFE()
847 {
848 return (storage_class & STCctfe) || !isDataseg();
849 }
850
833 override bool hasPointers() 851 override bool hasPointers()
834 { 852 {
835 //printf("VarDeclaration.hasPointers() %s, ty = %d\n", toChars(), type.ty); 853 //printf("VarDeclaration.hasPointers() %s, ty = %d\n", toChars(), type.ty);
836 return (!isDataseg() && type.hasPointers()); 854 return (!isDataseg() && type.hasPointers());
837 } 855 }
842 static if (false) { 860 static if (false) {
843 /* Global variables and struct/class fields of the form: 861 /* Global variables and struct/class fields of the form:
844 * const int x = 3; 862 * const int x = 3;
845 * are not stored and hence cannot have their address taken. 863 * are not stored and hence cannot have their address taken.
846 */ 864 */
847 if ((isConst() || isInvariant()) && (storage_class & STC.STCinit) && (!(storage_class & (STC.STCstatic | STC.STCextern)) || (storage_class & STC.STCfield)) && 865 if ((isConst() || isImmutable()) && (storage_class & STC.STCinit) && (!(storage_class & (STC.STCstatic | STC.STCextern)) || (storage_class & STC.STCfield)) &&
848 (!parent || toParent().isModule() || toParent().isTemplateInstance()) && type.toBasetype().isTypeBasic()) 866 (!parent || toParent().isModule() || toParent().isTemplateInstance()) && type.toBasetype().isTypeBasic())
849 { 867 {
850 return false; 868 return false;
851 } 869 }
852 } else { 870 } else {
990 * If variable has a constant expression initializer, get it. 1008 * If variable has a constant expression initializer, get it.
991 * Otherwise, return null. 1009 * Otherwise, return null.
992 */ 1010 */
993 Expression getConstInitializer() 1011 Expression getConstInitializer()
994 { 1012 {
995 if ((isConst() || isInvariant() || storage_class & STC.STCmanifest) && storage_class & STC.STCinit) 1013 if ((isConst() || isImmutable() || storage_class & STC.STCmanifest) && storage_class & STC.STCinit)
996 { 1014 {
997 ExpInitializer ei = getExpInitializer(); 1015 ExpInitializer ei = getExpInitializer();
998 if (ei) 1016 if (ei)
999 return ei.exp; 1017 return ei.exp;
1000 } 1018 }