1 /// Author: Aziz Köksal 2 /// License: GPL3 3 /// $(Maturity very high) 4 module dil.ast.NodeCopier; 5 6 /// Provides a copy() method for subclasses of Node. 7 mixin template copyMethod() 8 { 9 override typeof(this) copy() 10 { // First do a shallow copy. 11 auto n = cast(typeof(this))cast(void*)this.dup; 12 // Then copy each subnode. 13 with (n) foreach (i, T; CTTI_Types) 14 { 15 mixin("alias member = "~CTTI_Members[i]~";"); 16 static if (is(T : Node)) // A Node? 17 { 18 if (!CTTI_MayBeNull[i] || member !is null) 19 member = member.copy(); 20 } 21 else 22 static if (is(T : E[], E : Node)) // A Node array? 23 { 24 foreach (ref x; member) 25 if (!CTTI_MayBeNull[i] || x !is null) 26 x = x.copy(); 27 } 28 } 29 return n; 30 } 31 }