diff src/ast/Expr.d @ 206:d3c148ca429b

Major moving of files. all src now goes into src, all docs in docs.
author Anders Johnsen <skabet@gmail.com>
date Tue, 12 Aug 2008 18:14:56 +0200
parents
children 42e663451371
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ast/Expr.d	Tue Aug 12 18:14:56 2008 +0200
@@ -0,0 +1,203 @@
+module ast.Expr;
+
+/**
+  The base class for all Expressions.
+  */
+class Expr
+{
+    /// Get the type of the Expr
+    Object getType() 
+    {
+        assert(0, "Unimplemented");
+        return null;
+    }
+
+    /// Set the type of the Expr
+    void setType(Object type) 
+    {
+        assert(0, "Unimplemented");
+    }
+
+    /// Returns true if the Expr can be compile-time evaluated.
+    bool isConstantExpr() { return false; }
+
+    NumberLiteral asNumberLiteral() { return null; }
+    bool isNumberLiteral() { return false; }
+
+    StringLiteral asStringLiteral() { return null; }
+    bool isStringLiteral() { return false; }
+
+    ArrayLiteral asArrayLiteral() { return null; }
+    bool isArrayLiteral() { return false; }
+
+    Assign asAssign() { return null; }
+    bool isAssign() { return false; }
+
+    Binary asBinary() { return null; }
+    bool isBinary() { return false; }
+
+    Negate asNegate() { return null; }
+    bool isNegate() { return false; }
+
+    Deref asDeref() { return null; }
+    bool isDeref() { return false; }
+
+    AddressOf asAddressOf() { return null; }
+    bool isAddressOf() { return false; }
+
+    Index asIndex() { return null; }
+    bool isIndex() { return false; }
+
+    Identifier asIdentifier() { return null; }
+    bool isIdentifier() { return false; }
+
+    Member asMember() { return null; }
+    bool isMember() { return false; }
+
+private:
+/// FIXME: Add DType? here
+}
+
+/**
+  NumberLiteral
+  */
+/// FIXME: Should there be an IntegerLiteral and FloatLiteral instead?
+class NumberLiteral : Expr
+{
+    override bool isConstantExpr() { return true; }
+
+    override NumberLiteral asNumberLiteral() { return this; }
+    override bool isNumberLiteral() { return true; }
+}
+
+/**
+  StringLiteral
+  */
+class StringLiteral : Expr
+{
+    override bool isConstantExpr() { return true; }
+
+    override StringLiteral asStringLiteral() { return this; }
+    override bool isStringLiteral() { return true; }
+}
+
+/**
+  ArrayLiteral
+  */
+class ArrayLiteral : Expr
+{
+    /// Return the arguments for the ArrayLiteral
+    Expr[] getArguments() { return arguments; }
+
+    /// Return a given argument for the ArrayLiteral
+    Expr getArgument(int index) { return arguments[index]; }
+
+    /// Get the count of arguments for the ArrayLiteral
+    int getArgumentCount() { return arguments.length; }
+
+    override bool isConstantExpr() 
+    {
+        /**
+          If all the arguments to the ArrayLiteral is an constant Expr, then
+          this ArrayLiteral can be considered an constant Expr aswell.
+          */
+        // FIXME: consider if it should save the result
+        foreach (arg; arguments)
+            if (!arg.isConstantExpr())
+                return false;
+        return true; 
+    }
+
+    override ArrayLiteral asArrayLiteral() { return this; }
+    override bool isArrayLiteral() { return true; }
+
+private:
+    Expr[] arguments;
+}
+
+/**
+  The Assign expression contains two expression, a left and a right side, 
+  left being a lvalue, right being a rvalue. 
+
+  If the right side ain't the same type as the left type, the right side will
+  try to be promoted through an implicit cast. If this failes, an error must
+  be given.
+  */
+class Assign : Expr
+{
+    override Assign asAssign() { return this; }
+    override bool isAssign() { return true; }
+
+private:
+    Expr left, right;
+}
+
+/**
+  Binary
+  */
+class Binary : Expr
+{
+    override Binary asBinary() { return this; }
+    override bool isBinary() { return true; }
+
+private:
+    Expr left, right;
+}
+
+/**
+  Negate
+  */
+class Negate : Expr
+{
+    override Negate asNegate() { return this; }
+    override bool isNegate() { return true; }
+
+private:
+    Expr expr;
+}
+
+/**
+  Deref
+  */
+class Deref : Expr
+{
+    override Deref asDeref() { return this; }
+    override bool isDeref() { return true; }
+}
+
+/**
+  AddressOf
+  */
+class AddressOf : Expr
+{
+    override AddressOf asAddressOf() { return this; }
+    override bool isAddressOf() { return true; }
+}
+
+/**
+  Index
+  */
+class Index : Expr
+{
+    override Index asIndex() { return this; }
+    override bool isIndex() { return true; }
+}
+
+/**
+  Identifier
+  */
+class Identifier : Expr
+{
+    override Identifier asIdentifier() { return this; }
+    override bool isIdentifier() { return true; }
+}
+
+/**
+  Member
+  */
+class Member : Expr
+{
+    override Member asMember() { return this; }
+    override bool isMember() { return true; }
+}
+