Mercurial > projects > dil
view trunk/src/dil/ast/Node.d @ 681:95a3c28c0f64
Renamed AsmStatement->AsmBlockStatement and AsnInstruction->AsmStatement.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 19 Jan 2008 00:10:57 +0100 |
parents | c4e3a34e40f1 |
children | 19a34b69cc7d |
line wrap: on
line source
/++ Author: Aziz Köksal License: GPL3 +/ module dil.ast.Node; import common; public import dil.lexer.Token; public import dil.ast.NodesEnum; /// This string is mixed into the constructor of a class that inherits from Node. const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; class Node { NodeCategory category; NodeKind kind; Node[] children; Token* begin, end; this(NodeCategory category) { assert(category != NodeCategory.Undefined); this.category = category; } void setTokens(Token* begin, Token* end) { this.begin = begin; this.end = end; } Class setToks(Class)(Class node) { node.setTokens(this.begin, this.end); return node; } void addChild(Node child) { assert(child !is null, "failed in " ~ this.classinfo.name); this.children ~= child; } void addOptChild(Node child) { child is null || addChild(child); } void addChildren(Node[] children) { assert(children !is null && delegate{ foreach (child; children) if (child is null) return false; return true; }(), "failed in " ~ this.classinfo.name ); this.children ~= children; } void addOptChildren(Node[] children) { children is null || addChildren(children); } Class Is(Class)() { if (kind == mixin("NodeKind." ~ typeof(Class).stringof)) return cast(Class)cast(void*)this; return null; } Class to(Class)() { return cast(Class)cast(void*)this; } }