Mercurial > projects > dang
diff sema/SymbolTableBuilder.d @ 28:69464d465284 new_gen
Now supporting structs - both read and write. Still a few errors though, so watch out.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 11:20:28 +0200 |
parents | 9031487e97d7 |
children | 495188f9078e |
line wrap: on
line diff
--- a/sema/SymbolTableBuilder.d Sun Apr 20 01:08:50 2008 +0200 +++ b/sema/SymbolTableBuilder.d Sun Apr 20 11:20:28 2008 +0200 @@ -13,16 +13,16 @@ this() { table ~= new Scope; - types["void"] = DType.Void; - types["bool"] = DType.Bool; - types["byte"] = DType.Byte; - types["ubyte"] = DType.UByte; - types["short"] = DType.Short; - types["ushort"] = DType.UShort; - types["int"] = DType.Int; - types["uint"] = DType.UInt; - types["long"] = DType.Long; - types["ulong"] = DType.ULong; + table[0].types["void"] = DType.Void; + table[0].types["bool"] = DType.Bool; + table[0].types["byte"] = DType.Byte; + table[0].types["ubyte"] = DType.UByte; + table[0].types["short"] = DType.Short; + table[0].types["ushort"] = DType.UShort; + table[0].types["int"] = DType.Int; + table[0].types["uint"] = DType.UInt; + table[0].types["long"] = DType.Long; + table[0].types["ulong"] = DType.ULong; } override void visit(Decl[] decls) @@ -52,11 +52,11 @@ override void visitFuncDecl(FuncDecl d) { auto sym = current().add(d.identifier); - sym.type = typeOf(d.type); + auto sc = push(); + sym.type = typeOf(d.type, sc); visitExp(d.type); visitExp(d.identifier); d.env = current(); - auto sc = push(); sc.parentFunction = sym; foreach (arg; d.funcArgs) visitDecl(arg); @@ -77,7 +77,7 @@ auto sc = current(); auto sym = sc.add(d.identifier); - sym.type = typeOf(d.type); + sym.type = typeOf(d.type, sc); d.env = sc; visitExp(d.type); visitExp(d.identifier); @@ -87,7 +87,19 @@ { auto sc = current(); auto sym = sc.add(s.identifier); -// sym.type = Tok.Struct; + DType[char[]] types; + foreach(varDecl ; s.vars) + { + types[varDecl.identifier.get] = typeOf(varDecl.type, sc); + } + + auto type = new DStruct(s.identifier); + + type.setMembers(types); + + sc.types[s.identifier.get] = type; + sym.type = type; + s.env = sc; super.visitStructDecl(s); } @@ -149,13 +161,16 @@ return table[$ - 1]; } - DType typeOf(Identifier id) + DType typeOf(Identifier id, Scope sc) { + return sc.findType(id); + + /* if (auto type = id.get in types) return *type; DType res = new DType(id); types[id.get] = res; - return res; + return res;*/ } DType[char[]] types; }