Mercurial > projects > dang
view sema/Declarations.d @ 39:1a7a308f75b2 new_gen
Added some struct tests, and implemented a wrong struct assignment
It assumes 8 bytes for all struct, we have no DType available at that point
Slight improvement to an error message (Member access to unknown members)
author | Anders Halager <halager@gmail.com> |
---|---|
date | Mon, 21 Apr 2008 22:47:12 +0200 |
parents | d14705a06bdd |
children | 79cb0afafabe |
line wrap: on
line source
module sema.Declarations; import sema.Visitor, sema.DType; import tango.io.Stdout; import misc.Error; class Declarations : Visitor!(void) { int[char[]] types; private Error error(uint line, char[] msg) { return new Error(msg); } override void visitIdentifier(Identifier i) { auto symbol = i.env.find(i); if(symbol is null) throw error(__LINE__, "Undefined identifier: '%0'") .arg(i.get) .loc(i.token.location); } override void visitVarDecl(VarDecl d) { if(!d.env.findType(d.type)) throw error(__LINE__, "Undefined type: '%0'") .arg(d.type.get) .loc(d.type.token.location); visitExp(d.identifier); if (d.init) visitExp(d.init); } override void visitFuncDecl(FuncDecl f) { visitExp(f.identifier); foreach (stmt; f.statements) visitStmt(stmt); } override void visitMemberLookup(MemberLookup m) { switch(m.target.expType) { case ExpType.Identifier: auto target = cast(Identifier)m.target; auto child = m.child; auto st = cast(DStruct)(target.env.find(target).type); if((child.get in st.members) is null) throw error(__LINE__, "%0 %1 has no member %2") .arg(st.name) .arg(target.get) .arg(child.get) .tok(child.token); break; case ExpType.MemberLookup: break; } } bool isType(char[] s) { return (s in types? true : false); } }