diff --git a/gen/dvalue.cpp b/gen/dvalue.cpp index a00dfcb3..98300a9b 100644 --- a/gen/dvalue.cpp +++ b/gen/dvalue.cpp @@ -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 @@ LLValue* DSliceValue::getRVal() ///////////////////////////////////////////////////////////////////////////////////////////////// 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() { diff --git a/gen/dvalue.h b/gen/dvalue.h index eb29094d..d5caa96a 100644 --- a/gen/dvalue.h +++ b/gen/dvalue.h @@ -33,7 +33,10 @@ struct DSliceValue; // 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 @@ struct DValue : Object 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 @@ struct DNullValue : DConstValue // variable d-value struct DVarValue : DValue { - Type* type; VarDeclaration* var; LLValue* val; @@ -103,7 +101,6 @@ struct DVarValue : DValue virtual LLValue* getLVal(); virtual LLValue* getRVal(); - virtual Type*& getType() { assert(type); return type; } virtual DVarValue* isVar() { return this; } }; @@ -117,22 +114,19 @@ struct DFieldValue : DVarValue // 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 @@ struct DFuncValue : DValue virtual LLValue* getRVal(); - virtual Type*& getType() { assert(type); return type; } virtual DFuncValue* isFunc() { return this; } };