Mercurial > projects > dang
diff ast/Exp.d @ 172:01c2c49775ef
- Changed Parser to be more clean on type parsing.
- Parsing int function(int), and the like, types.(Function pointers)
- Fixed a design fault that made Symbol be wrong. Now Symbols are created with a factory with the help of types.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Thu, 24 Jul 2008 20:31:24 +0200 |
parents | 7982eb63c0eb |
children | dc9bf56b7ace |
line wrap: on
line diff
--- a/ast/Exp.d Thu Jul 24 12:27:34 2008 +0200 +++ b/ast/Exp.d Thu Jul 24 20:31:24 2008 +0200 @@ -24,14 +24,17 @@ MemberReference, Index, Identifier, - ArrayIdentifier, - StaticArrayIdentifier, - PointerIdentifier, AssignExp, CallExp, CastExp, StringExp, NewExp, + + IdentifierTypeExp, + ArrayTypeExp, + StaticArrayTypeExp, + PointerTypeExp, + FunctionTypeExp, } abstract class Exp @@ -523,63 +526,6 @@ Symbol callSym; } -class PointerIdentifier : Identifier -{ - this(Identifier pointerOf) - { - super(ExpType.PointerIdentifier, pointerOf.loc); - this.pointerOf = pointerOf; - this.name = pointerOf.name; - } - - override DType type() - { - return pointerOf.type.getPointerTo(); - } - - Identifier pointerOf; -} - -class StaticArrayIdentifier : Identifier -{ - this(Identifier arrayOf, IntegerLit size) - { - super(ExpType.StaticArrayIdentifier, arrayOf.loc); - this.arrayOf = arrayOf; - this.size = Integer.parse(size.get); - this.name = arrayOf.name; - } - - override DType type() - { - return arrayOf.type.getAsStaticArray(size); - } - - Identifier arrayOf; - int size; - - private DType myType; -} - -class ArrayIdentifier : Identifier -{ - this(Identifier arrayOf) - { - super(ExpType.ArrayIdentifier, arrayOf.loc); - this.arrayOf = arrayOf; - this.name = arrayOf.name; - } - - override DType type() - { - return arrayOf.type.getAsArray(); - } - - Identifier arrayOf; - - private DType myType; -} - class Identifier : Exp { this(SLoc loc, char[] name) @@ -667,3 +613,101 @@ private DType myType; } +class IdentifierTypeExp : Identifier +{ + this(SLoc loc, char[] name) + { + super(ExpType.IdentifierTypeExp, loc); + this.name = name; + } + + protected this(ExpType t, SLoc loc) + { + super(t, loc); + } +} + +class PointerTypeExp : IdentifierTypeExp +{ + this(IdentifierTypeExp pointerOf) + { + super(ExpType.PointerTypeExp, pointerOf.loc); + this.pointerOf = pointerOf; + this.name = pointerOf.name; + } + + override DType type() + { + return pointerOf.type.getPointerTo(); + } + + Identifier pointerOf; +} + +class StaticArrayTypeExp : IdentifierTypeExp +{ + this(IdentifierTypeExp arrayOf, IntegerLit size) + { + super(ExpType.StaticArrayTypeExp, arrayOf.loc); + this.arrayOf = arrayOf; + this.size = Integer.parse(size.get); + this.name = arrayOf.name; + } + + override DType type() + { + return arrayOf.type.getAsStaticArray(size); + } + + Identifier arrayOf; + int size; + + private DType myType; +} + +class ArrayTypeExp : IdentifierTypeExp +{ + this(IdentifierTypeExp arrayOf) + { + super(ExpType.ArrayTypeExp, arrayOf.loc); + this.arrayOf = arrayOf; + this.name = arrayOf.name; + } + + override DType type() + { + return arrayOf.type.getAsArray(); + } + + Identifier arrayOf; + + private DType myType; +} + +class FunctionTypeExp : IdentifierTypeExp +{ + this(IdentifierTypeExp returnType, VarDecl[] decls) + { + super(ExpType.FunctionTypeExp, returnType.loc); + this.returnType = returnType; + 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; +} +