comparison gen/dvalue.h @ 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 3cf0066e6faf
children a5bfed1f6775
comparison
equal deleted inserted replaced
1179:71479f6e2a01 1180:f5729209a1d4
31 struct DSliceValue; 31 struct DSliceValue;
32 32
33 // base class for d-values 33 // base class for d-values
34 struct DValue : Object 34 struct DValue : Object
35 { 35 {
36 virtual Type*& getType() = 0; 36 Type* type;
37 DValue(Type* ty) : type(ty) {}
38
39 Type*& getType() { assert(type); return type; }
37 40
38 virtual LLValue* getLVal() { assert(0); return 0; } 41 virtual LLValue* getLVal() { assert(0); return 0; }
39 virtual LLValue* getRVal() { assert(0); return 0; } 42 virtual LLValue* getRVal() { assert(0); return 0; }
40 43
41 virtual bool isLVal() { return false; } 44 virtual bool isLVal() { return false; }
49 virtual DFuncValue* isFunc() { return NULL; } 52 virtual DFuncValue* isFunc() { return NULL; }
50 53
51 protected: 54 protected:
52 DValue() {} 55 DValue() {}
53 DValue(const DValue&) { } 56 DValue(const DValue&) { }
54 DValue& operator=(const DValue&) { return *this; } 57 DValue& operator=(const DValue& other) { type = other.type; return *this; }
55 }; 58 };
56 59
57 // immediate d-value 60 // immediate d-value
58 struct DImValue : DValue 61 struct DImValue : DValue
59 { 62 {
60 Type* type;
61 LLValue* val; 63 LLValue* val;
62 64
63 DImValue(Type* t, LLValue* v) : type(t), val(v) { } 65 DImValue(Type* t, LLValue* v) : DValue(t), val(v) { }
64 66
65 virtual LLValue* getRVal() { assert(val); return val; } 67 virtual LLValue* getRVal() { assert(val); return val; }
66 68
67 virtual Type*& getType() { assert(type); return type; }
68 virtual DImValue* isIm() { return this; } 69 virtual DImValue* isIm() { return this; }
69 }; 70 };
70 71
71 // constant d-value 72 // constant d-value
72 struct DConstValue : DValue 73 struct DConstValue : DValue
73 { 74 {
74 Type* type;
75 LLConstant* c; 75 LLConstant* c;
76 76
77 DConstValue(Type* t, LLConstant* con) { type = t; c = con; } 77 DConstValue(Type* t, LLConstant* con) : DValue(t), c(con) {}
78 78
79 virtual LLValue* getRVal(); 79 virtual LLValue* getRVal();
80 80
81 virtual Type*& getType() { assert(type); return type; }
82 virtual DConstValue* isConst() { return this; } 81 virtual DConstValue* isConst() { return this; }
83 }; 82 };
84 83
85 // null d-value 84 // null d-value
86 struct DNullValue : DConstValue 85 struct DNullValue : DConstValue
90 }; 89 };
91 90
92 // variable d-value 91 // variable d-value
93 struct DVarValue : DValue 92 struct DVarValue : DValue
94 { 93 {
95 Type* type;
96 VarDeclaration* var; 94 VarDeclaration* var;
97 LLValue* val; 95 LLValue* val;
98 96
99 DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue); 97 DVarValue(Type* t, VarDeclaration* vd, LLValue* llvmValue);
100 DVarValue(Type* t, LLValue* llvmValue); 98 DVarValue(Type* t, LLValue* llvmValue);
101 99
102 virtual bool isLVal() { return true; } 100 virtual bool isLVal() { return true; }
103 virtual LLValue* getLVal(); 101 virtual LLValue* getLVal();
104 virtual LLValue* getRVal(); 102 virtual LLValue* getRVal();
105 103
106 virtual Type*& getType() { assert(type); return type; }
107 virtual DVarValue* isVar() { return this; } 104 virtual DVarValue* isVar() { return this; }
108 }; 105 };
109 106
110 // field d-value 107 // field d-value
111 struct DFieldValue : DVarValue 108 struct DFieldValue : DVarValue
115 }; 112 };
116 113
117 // slice d-value 114 // slice d-value
118 struct DSliceValue : DValue 115 struct DSliceValue : DValue
119 { 116 {
120 Type* type;
121 LLValue* len; 117 LLValue* len;
122 LLValue* ptr; 118 LLValue* ptr;
123 119
124 DSliceValue(Type* t, LLValue* l, LLValue* p) { type=t; ptr=p; len=l; } 120 DSliceValue(Type* t, LLValue* l, LLValue* p) : DValue(t), len(l), ptr(p) {}
125 121
126 virtual LLValue* getRVal(); 122 virtual LLValue* getRVal();
127 123
128 virtual Type*& getType() { assert(type); return type; }
129 virtual DSliceValue* isSlice() { return this; } 124 virtual DSliceValue* isSlice() { return this; }
130 }; 125 };
131 126
132 // function d-value 127 // function d-value
133 struct DFuncValue : DValue 128 struct DFuncValue : DValue
134 { 129 {
135 Type* type;
136 FuncDeclaration* func; 130 FuncDeclaration* func;
137 LLValue* val; 131 LLValue* val;
138 LLValue* vthis; 132 LLValue* vthis;
139 133
140 DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0); 134 DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0);
141 135
142 virtual LLValue* getRVal(); 136 virtual LLValue* getRVal();
143 137
144 virtual Type*& getType() { assert(type); return type; }
145 virtual DFuncValue* isFunc() { return this; } 138 virtual DFuncValue* isFunc() { return this; }
146 }; 139 };
147 140
148 #endif // LDC_GEN_DVALUE_H 141 #endif // LDC_GEN_DVALUE_H