changeset 1180:f5729209a1d4

Remove some redundancy from the DValue hierarchy: all subclasses had a 'type' field and identical implementations of virtual function getType(). Move these to DValue itself, and make getType() non-virtual.
author Frits van Bommel <fvbommel wxs.nl>
date Tue, 31 Mar 2009 01:18:35 +0200
parents 71479f6e2a01
children 204197eb9eb5
files gen/dvalue.cpp gen/dvalue.h
diffstat 2 files changed, 14 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/gen/dvalue.cpp	Mon Mar 30 16:34:36 2009 +0200
+++ b/gen/dvalue.cpp	Tue Mar 31 01:18:35 2009 +0200
@@ -12,18 +12,12 @@
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
 DVarValue::DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue)
-{
-    var = vd;
-    val = llvmValue;
-    type = t;
-}
+: DValue(t), var(vd), val(llvmValue)
+{}
 
 DVarValue::DVarValue(Type* t, LLValue* llvmValue)
-{
-    var = 0;
-    val = llvmValue;
-    type = t;
-}
+: DValue(t), var(0), val(llvmValue)
+{}
 
 LLValue* DVarValue::getLVal()
 {
@@ -54,12 +48,8 @@
 /////////////////////////////////////////////////////////////////////////////////////////////////
 
 DFuncValue::DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt)
-{
-    func = fd;
-    type = func->type;
-    val = v;
-    vthis = vt;
-}
+: DValue(fd->type), func(fd), val(v), vthis(vt)
+{}
 
 LLValue* DFuncValue::getRVal()
 {
--- a/gen/dvalue.h	Mon Mar 30 16:34:36 2009 +0200
+++ b/gen/dvalue.h	Tue Mar 31 01:18:35 2009 +0200
@@ -33,7 +33,10 @@
 // base class for d-values
 struct DValue : Object
 {
-    virtual Type*& getType() = 0;
+    Type* type;
+    DValue(Type* ty) : type(ty) {}
+
+    Type*& getType() { assert(type); return type; }
 
     virtual LLValue* getLVal() { assert(0); return 0; }
     virtual LLValue* getRVal() { assert(0); return 0; }
@@ -51,34 +54,30 @@
 protected:
     DValue() {}
     DValue(const DValue&) { }
-    DValue& operator=(const DValue&) { return *this; }
+    DValue& operator=(const DValue& other) { type = other.type; return *this; }
 };
 
 // immediate d-value
 struct DImValue : DValue
 {
-    Type* type;
     LLValue* val;
 
-    DImValue(Type* t, LLValue* v) : type(t), val(v) { }
+    DImValue(Type* t, LLValue* v) : DValue(t), val(v) { }
 
     virtual LLValue* getRVal() { assert(val); return val; }
 
-    virtual Type*& getType() { assert(type); return type; }
     virtual DImValue* isIm() { return this; }
 };
 
 // constant d-value
 struct DConstValue : DValue
 {
-    Type* type;
     LLConstant* c;
 
-    DConstValue(Type* t, LLConstant* con) { type = t; c = con; }
+    DConstValue(Type* t, LLConstant* con) : DValue(t), c(con) {}
 
     virtual LLValue* getRVal();
 
-    virtual Type*& getType() { assert(type); return type; }
     virtual DConstValue* isConst() { return this; }
 };
 
@@ -92,7 +91,6 @@
 // variable d-value
 struct DVarValue : DValue
 {
-    Type* type;
     VarDeclaration* var;
     LLValue* val;
 
@@ -103,7 +101,6 @@
     virtual LLValue* getLVal();
     virtual LLValue* getRVal();
 
-    virtual Type*& getType() { assert(type); return type; }
     virtual DVarValue* isVar() { return this; }
 };
 
@@ -117,22 +114,19 @@
 // slice d-value
 struct DSliceValue : DValue
 {
-    Type* type;
     LLValue* len;
     LLValue* ptr;
 
-    DSliceValue(Type* t, LLValue* l, LLValue* p) { type=t; ptr=p; len=l; }
+    DSliceValue(Type* t, LLValue* l, LLValue* p) : DValue(t), len(l), ptr(p) {}
 
     virtual LLValue* getRVal();
 
-    virtual Type*& getType() { assert(type); return type; }
     virtual DSliceValue* isSlice() { return this; }
 };
 
 // function d-value
 struct DFuncValue : DValue
 {
-    Type* type;
     FuncDeclaration* func;
     LLValue* val;
     LLValue* vthis;
@@ -141,7 +135,6 @@
 
     virtual LLValue* getRVal();
 
-    virtual Type*& getType() { assert(type); return type; }
     virtual DFuncValue* isFunc() { return this; }
 };