Mercurial > projects > dang
view ast/Exp.d @ 48:b6c1dc30ca4b new_gen
Only tests that dont pass now are structs and switches
As far as the parser is concerned assignments are binary expressions
Fixed a bug in codegen of if's - it is important to remember that the
builder might be positioned at a new block after generating sub-statements
author | Anders Halager <halager@gmail.com> |
---|---|
date | Thu, 24 Apr 2008 19:42:53 +0200 |
parents | 495188f9078e |
children | 79cb0afafabe |
line wrap: on
line source
module ast.Exp; import tango.text.Util : jhash; import lexer.Token; import sema.SymbolTable; enum ExpType { Binary, Negate, IntegerLit, MemberLookup, ArrayLookup, Identifier, AssignExp, CallExp, } class Exp { this(ExpType expType) { this.expType = expType; } ExpType expType; Scope env; } class CallExp : Exp { this(Exp exp, Exp[] args) { super(ExpType.CallExp); this.exp = exp; this.args = args; } Exp exp; Exp[] args; } class AssignExp : Exp { this(Exp identifier, Exp exp) { super(ExpType.AssignExp); this.identifier = identifier; this.exp = exp; } Exp identifier; Exp exp; } class BinaryExp : Exp { public enum Operator { Assign, Eq, Ne, Lt, Le, Gt, Ge, Add, Sub, Mul, Div, Mod, } this(Operator op, Exp left, Exp right) { super(ExpType.Binary); this.op = op; this.left = left; this.right = right; } char[] resultType() { if (op >= Operator.Eq && op <= Operator.Ge) return "bool"; return null; } Operator op; Exp left, right; } class NegateExp : Exp { this(Exp exp) { super(ExpType.Negate); this.exp = exp; } public Exp exp; } class IntegerLit : Exp { this(Token t) { super(ExpType.IntegerLit); this.token = t; } Token token; } class MemberLookup : Exp { this(Exp target, Identifier child) { super(ExpType.MemberLookup); this.target = target; this.child = child; } Identifier child; Exp target; } class ArrayLookup : Exp { this(Exp target, IntegerLit pos) { super(ExpType.ArrayLookup); this.target = target; this.pos = pos; } Exp target; IntegerLit pos; } class Identifier : Exp { this(Token t) { super(ExpType.Identifier); this.token = t; name = t.get; } char[] get() { return name; } hash_t toHash() { return jhash(name); } int opCmp(Object o) { if (auto id = cast(Identifier)o) return typeid(char[]).compare(&name, &id.name); return 0; } int opEquals(Object o) { if (auto id = cast(Identifier)o) return typeid(char[]).equals(&name, &id.name); return 0; } Token token; char[] name; }