Mercurial > projects > dang
view sema/Declarations.d @ 24:2d28b21faad6 new_gen
New codegen!
Rewritten codegen to use the llvm bindings
Everything except struct are back to normal, and there a a few additions.
1. Correct code in more cases, return at the end of a while/if wont
generate a "ret" followed by a "br".
2. Better scope, "int x = x" now illegal
3. Probably more
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sat, 19 Apr 2008 18:29:42 +0200 |
parents | e331e4e816e4 |
children | 69464d465284 |
line wrap: on
line source
module sema.Declarations; import sema.Visitor; import tango.io.Stdout; import misc.Error; class Declarations : Visitor!(void) { int[char[]] types; this() { types = [ "byte"[]:0, "ubyte":1, "short":2, "ushort":3, "int":4, "uint":5, "long":6, "ulong":7, "bool":8, "void":9 ]; } override void visitIdentifier(Identifier i) { auto symbol = i.env.find(i); if(symbol is null && !isType(i.get)) throw new Error("Undefined identifier: '"~i.get~"'",i.token.location); } override void visitVarDecl(VarDecl d) { if(!isType(d.type.get) && d.env.findType(d.identifier)) throw new Error("Undefined type: '"~d.type.get~"'",d.type.token.location); visitExp(d.type); visitExp(d.identifier); if (d.init) visitExp(d.init); } bool isType(char[] s) { return (s in types? true : false); } }