Mercurial > projects > dang
diff ast/Exp.d @ 195:4e1a7265d620
Made a BuildTypes pass, to give all exp's a type.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 29 Jul 2008 15:50:24 +0200 |
parents | 08f68d684047 |
children |
line wrap: on
line diff
--- a/ast/Exp.d Tue Jul 29 13:54:44 2008 +0200 +++ b/ast/Exp.d Tue Jul 29 15:50:24 2008 +0200 @@ -66,7 +66,7 @@ Symbol getSymbol() { return null; } /// Get the type of the expression - abstract DType type(); + DType type; /// Indicates which type the expression is - to avoid a lot of casts ExpType expType; @@ -74,8 +74,6 @@ /// The environment of the expression Scope env; - Symbol symbol; - int stmtIndex; /** @@ -104,13 +102,6 @@ this.args = args; } - override DType type() - { - DFunction f = exp.type.asCallable(); - assert(f !is null, "Can only call functions"); - return f.returnType; - } - DType callerType() { DFunction f = new DFunction(new Identifier("function")); @@ -165,8 +156,6 @@ return identifier.sourceRange + exp.sourceRange; } - override DType type() { return identifier.type(); } - Exp identifier; Exp exp; } @@ -213,35 +202,6 @@ this.right = right; } - override DType type() - { - if (myType) - return myType; - - if (op == Operator.Eq || - op == Operator.Ne || - op == Operator.Lt || - op == Operator.Le || - op == Operator.Gt || - op == Operator.Ge) - { - myType = DType.Bool; - return myType; - } - - DType l = left.type; - DType r = right.type; - if (l is r) - myType = l; - else if (l.hasImplicitConversionTo(r)) - myType = r; - else if (r.hasImplicitConversionTo(l)) - myType = l; - else - return null; - return myType; - } - override SLoc startLoc() { return left.startLoc(); } override SourceRange sourceRange() @@ -265,7 +225,6 @@ Operator op; Exp left, right; - private DType myType; } class NegateExp : Exp @@ -282,8 +241,6 @@ return this; } - override DType type() { return exp.type(); } - override SourceRange sourceRange() { return SourceRange(loc) + exp.sourceRange; @@ -306,19 +263,11 @@ return this; } - override DType type() - { - if (_type) - return _type; - return exp.type().asPointer().pointerOf; - } - override SourceRange sourceRange() { return SourceRange(loc) + exp.sourceRange; } - DType _type; public Exp exp; } @@ -336,11 +285,6 @@ return this; } - override DType type() - { - return exp.type().getPointerTo; - } - override SourceRange sourceRange() { return SourceRange(loc) + exp.sourceRange; @@ -368,23 +312,6 @@ return this; } - override DType type() - { - switch(number.type) - { - case NumberType.Int: - return DType.Int; - case NumberType.Long: - return DType.Long; - case NumberType.ULong: - return DType.ULong; - case NumberType.Double: - return DType.Double; - case NumberType.Real: - return DType.Real; - } - } - override SourceRange sourceRange() { return range; @@ -429,32 +356,6 @@ return this; } - override DType type() - { - if (myType) - return myType; - - if ( target.type.isStruct ) - { - Symbol st = target.getSymbol; - if (auto t = st.findMembers(child.name)) - myType = t[0].type; -// else assert(0, "Referencing non-existant member"); - } - else if ( target.type.isClass ) - { - Symbol cl = target.getSymbol; - if (auto t = cl.findMembers(child.name)) - myType = t[0].type; -// else assert(0, "Referencing non-existant member"); - } - else - assert(0, "Only structs and classes have members"); - // no error reporting here - - return myType; - } - override SLoc startLoc() { return target.startLoc(); } override SourceRange sourceRange() @@ -464,7 +365,6 @@ Identifier child; Exp target; - private DType myType; } class IndexExp : Exp @@ -478,16 +378,6 @@ this.right_bracket = right_bracket; } - override DType type() - { - DType type = target.type(); - if (type.isStaticArray()) - return type.asStaticArray().arrayOf; - else if (type.isPointer()) - return type.asPointer().pointerOf; - else assert(0, "Can only index pointers and arrays"); - } - override SourceRange sourceRange() { return target.sourceRange + SourceRange(right_bracket); @@ -514,11 +404,6 @@ this.exp = exp; } - override DType type() - { - return env.findType(this.castType.get); - } - override CastExp simplify() { castType = castType.simplify(); @@ -543,19 +428,6 @@ this.str = str; } - override DType type() - { - switch (data.type) - { - case StringType.Char: - return DType.Char.getAsStaticArray(data.data.length); - case StringType.WChar: - return DType.WChar.getAsStaticArray(data.data.length/2); - case StringType.DChar: - return DType.DChar.getAsStaticArray(data.data.length/4); - } - } - char[] str; String data; } @@ -570,11 +442,6 @@ this.c_args = c_args; } - override DType type() - { - return env.findType(this.newType.get); - } - Exp[] a_args, c_args; Identifier newType; Symbol callSym; @@ -586,11 +453,6 @@ { super(ExpType.NullExp, loc); } - - override DType type() - { - return new DPointer(DType.Int); - } } class Identifier : Exp @@ -618,24 +480,14 @@ override Symbol getSymbol() { + if (!env) + return null; if (auto decl = env.find(this.get)) if(decl.length) return decl[$-1].sym; return null; } - override DType type() - { - if (myType !is null) - return myType; - else if (auto sym = getSymbol) - myType = sym.type; - else - myType = DType.Int; - - return myType; - } - this(char[] name) { super(ExpType.Identifier, SLoc.Invalid); @@ -671,18 +523,12 @@ return this; } - void setType(DType myType) - { - this.myType = myType; - } - override SourceRange sourceRange() { return SourceRange(loc, loc + name.length); } char[] name; - private DType myType; } class IdentifierTypeExp : Identifier @@ -708,11 +554,6 @@ this.name = pointerOf.name; } - override DType type() - { - return pointerOf.type.getPointerTo(); - } - Identifier pointerOf; } @@ -726,15 +567,8 @@ this.name = arrayOf.name; } - override DType type() - { - return arrayOf.type.getAsStaticArray(size); - } - Identifier arrayOf; int size; - - private DType myType; } class ArrayTypeExp : IdentifierTypeExp @@ -746,14 +580,7 @@ this.name = arrayOf.name; } - override DType type() - { - return arrayOf.type.getAsArray(); - } - Identifier arrayOf; - - private DType myType; } class FunctionTypeExp : IdentifierTypeExp @@ -765,22 +592,8 @@ this.decls = decls; } - override DType type() - { - if (myType) - return myType; - auto t = new DFunction(returnType); - t.returnType = returnType.type; - foreach (decl ; decls) - t.params ~= decl.identifier.type; - - myType = t.getPointerTo; - return myType; - } - VarDecl[] decls; IdentifierTypeExp returnType; - private DType myType; } class ArrayLiteralExp : Exp @@ -793,11 +606,6 @@ this.end = end; } - override DType type() - { - return exps[0].type.getAsStaticArray(exps.length); - } - Exp[] exps; SLoc begin, end; }