changeset 82:e95073e26356

fixed a hack I used as a lack of copy ctor in D
author korDen
date Mon, 30 Aug 2010 18:38:35 +0400
parents 722df8e7509c
children ee670dd808a8
files dmd/AttribDeclaration.d dmd/Scope.d
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/AttribDeclaration.d	Mon Aug 30 15:40:51 2010 +0200
+++ b/dmd/AttribDeclaration.d	Mon Aug 30 18:38:35 2010 +0400
@@ -47,9 +47,7 @@
 			if (stc != sc.stc || linkage != sc.linkage || protection != sc.protection || explicitProtection != sc.explicitProtection || structalign != sc.structalign)
 			{
 				// create new one for changes
-				newsc = new Scope(sc);
-				newsc.offset = sc.offset;
-				newsc.scopesym = sc.scopesym;
+				newsc = sc.clone();				
 				newsc.flags &= ~SCOPE.SCOPEfree;
 				newsc.stc = stc;
 				newsc.linkage = linkage;
@@ -75,9 +73,7 @@
 			if (stc != sc.stc || linkage != sc.linkage || protection != sc.protection || explicitProtection != sc.explicitProtection || structalign != sc.structalign)
 			{
 				// create new one for changes
-				newsc = new Scope(sc);
-				newsc.offset = sc.offset;
-				newsc.scopesym = sc.scopesym;
+				newsc = sc.clone();
 				newsc.flags &= ~SCOPE.SCOPEfree;
 				newsc.stc = stc;
 				newsc.linkage = linkage;
--- a/dmd/Scope.d	Mon Aug 30 15:40:51 2010 +0200
+++ b/dmd/Scope.d	Mon Aug 30 18:38:35 2010 +0400
@@ -165,6 +165,17 @@
 		this.docbuf = enclosing.docbuf;
 		assert(this !is enclosing);	/// huh?
 	}
+	
+	Scope clone()
+	{
+		// similar code is used in Type.clone()
+		// TODO: move to Util or something...
+		size_t size = __traits(classInstanceSize, typeof(this));
+		void* mem = malloc(size);
+		memcpy(mem, this, size);
+		
+		return cast(typeof(this))mem;
+	}
 
     Scope push()
 	{