Mercurial > projects > dang
view sema/Declarations.d @ 88:eb5b2c719a39 new_gen
Major change to locations, tokens and expressions.
A location (now SourceLocation or SLoc) is only 32 bit in size -
disadvantage is that it can't find its own text. You have to go through the
new SourceManager to do that.
This has caused changes to a lot of stuff and removal of DataSource and the
old Location
Additionally Exp has gotten some location stuff, so we can give proper
error messages. Not in Decl and Stmt yet, but thats coming too.
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 04 May 2008 18:13:46 +0200 |
parents | 381975d76baf |
children |
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.varType)) throw error(__LINE__, "Undefined type: '%0'") .arg(d.varType.get); //.loc(d.varType.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 visitCastExp(CastExp exp) { visitExp(exp.exp); } override void visitMemberReference(MemberReference 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.MemberReference: break; } } private bool isType(char[] s) { return (s in types? true : false); } }