Mercurial > projects > dil
comparison trunk/src/dil/ast/Node.d @ 769:5e3ef1b2011c
Added and improved documentation.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 17 Feb 2008 02:21:55 +0100 |
parents | 19a34b69cc7d |
children | 3b34f6a95a27 |
comparison
equal
deleted
inserted
replaced
768:d84349a60f5c | 769:5e3ef1b2011c |
---|---|
7 import common; | 7 import common; |
8 | 8 |
9 public import dil.lexer.Token; | 9 public import dil.lexer.Token; |
10 public import dil.ast.NodesEnum; | 10 public import dil.ast.NodesEnum; |
11 | 11 |
12 /// This string is mixed into the constructor of a class that inherits from Node. | 12 /// The root class of all nodes that can form a D syntax tree. |
13 const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; | 13 abstract class Node |
14 { | |
15 NodeCategory category; /// The category of this node. | |
16 NodeKind kind; /// The kind of this node. | |
17 Node[] children; // Will be probably removed sometime. | |
18 Token* begin, end; /// The begin and end tokens of this node. | |
14 | 19 |
15 class Node | 20 /// Constructs a node object. |
16 { | |
17 NodeCategory category; | |
18 NodeKind kind; | |
19 Node[] children; // Will be probably removed sometime. | |
20 Token* begin, end; | |
21 | |
22 this(NodeCategory category) | 21 this(NodeCategory category) |
23 { | 22 { |
24 assert(category != NodeCategory.Undefined); | 23 assert(category != NodeCategory.Undefined); |
25 this.category = category; | 24 this.category = category; |
26 } | 25 } |
63 void addOptChildren(Node[] children) | 62 void addOptChildren(Node[] children) |
64 { | 63 { |
65 children is null || addChildren(children); | 64 children is null || addChildren(children); |
66 } | 65 } |
67 | 66 |
67 /// Returns a pointer to Class if this node can be cast to it. | |
68 Class Is(Class)() | 68 Class Is(Class)() |
69 { | 69 { |
70 if (kind == mixin("NodeKind." ~ typeof(Class).stringof)) | 70 if (kind == mixin("NodeKind." ~ typeof(Class).stringof)) |
71 return cast(Class)cast(void*)this; | 71 return cast(Class)cast(void*)this; |
72 return null; | 72 return null; |
73 } | 73 } |
74 | 74 |
75 /// Casts this node to Class. | |
75 Class to(Class)() | 76 Class to(Class)() |
76 { | 77 { |
77 return cast(Class)cast(void*)this; | 78 return cast(Class)cast(void*)this; |
78 } | 79 } |
79 } | 80 } |
81 | |
82 /// This string is mixed into the constructor of a class that inherits | |
83 /// from Node. It sets the member kind. | |
84 const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; |