1 /// Author: Aziz Köksal 2 /// License: GPL3 3 /// $(Maturity very high) 4 module dil.ast.Type; 5 6 import dil.ast.Node; 7 import dil.semantic.Types, 8 dil.semantic.Symbol; 9 10 /// The root class of all type nodes. 11 abstract class TypeNode : Node 12 { 13 TypeNode next; /// The next type in the type chain. 14 TypeNode parent; /// The parent TypeNode of this symbol. 15 Type type; /// The semantic type of this type node. 16 Symbol symbol; /// Semantic symbol. 17 18 this() 19 { 20 this(null); 21 } 22 23 this(TypeNode next) 24 { 25 addOptChild(next); 26 if (next !is null) 27 next.parent = this; 28 this.next = next; 29 } 30 31 /// Sets the member 'next'. This node becomes the parent of 'n'. 32 void setNext(TypeNode n) 33 { 34 assert(n !is null); 35 next = n; 36 n.parent = this; 37 if (children.length) 38 children[0] = next; 39 else 40 children ~= next; 41 } 42 43 /// Returns the end type of the type chain. 44 TypeNode baseType() 45 { 46 auto type = this; 47 while (type.next) 48 type = type.next; 49 return type; 50 } 51 52 /// Returns true if the member 'type' is not null. 53 bool hasType() 54 { 55 return type !is null; 56 } 57 58 /// Returns true if the member 'symbol' is not null. 59 bool hasSymbol() 60 { 61 return symbol !is null; 62 } 63 64 override abstract TypeNode copy(); 65 }