Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/dvalue.h

Revision 1206:a5bfed1f6775, 3.2 kB (checked in by Frits van Bommel <fvbommel wxs.nl>, 3 years ago)

Reduce include-order dependencies

Line 
1 #ifndef LDC_GEN_DVALUE_H
2 #define LDC_GEN_DVALUE_H
3
4 /*
5 These classes are used for generating the IR. They encapsulate D values and
6 provide a common interface to the most common operations. When more specialized
7 handling is necessary, they hold enough information to do-the-right-thing (TM)
8 */
9
10 #include <cassert>
11 #include "root.h"
12
13 struct Type;
14 struct Dsymbol;
15 struct VarDeclaration;
16 struct FuncDeclaration;
17
18 namespace llvm
19 {
20     class Value;
21     class Type;
22     class Constant;
23 }
24
25 struct DImValue;
26 struct DConstValue;
27 struct DNullValue;
28 struct DVarValue;
29 struct DFieldValue;
30 struct DFuncValue;
31 struct DSliceValue;
32
33 // base class for d-values
34 struct DValue : Object
35 {
36     Type* type;
37     DValue(Type* ty) : type(ty) {}
38
39     Type*& getType() { assert(type); return type; }
40
41     virtual llvm::Value* getLVal() { assert(0); return 0; }
42     virtual llvm::Value* getRVal() { assert(0); return 0; }
43
44     virtual bool isLVal() { return false; }
45
46     virtual DImValue* isIm() { return NULL; }
47     virtual DConstValue* isConst() { return NULL; }
48     virtual DNullValue* isNull() { return NULL; }
49     virtual DVarValue* isVar() { return NULL; }
50     virtual DFieldValue* isField() { return NULL; }
51     virtual DSliceValue* isSlice() { return NULL; }
52     virtual DFuncValue* isFunc() { return NULL; }
53
54 protected:
55     DValue() {}
56     DValue(const DValue&) { }
57     DValue& operator=(const DValue& other) { type = other.type; return *this; }
58 };
59
60 // immediate d-value
61 struct DImValue : DValue
62 {
63     llvm::Value* val;
64
65     DImValue(Type* t, llvm::Value* v) : DValue(t), val(v) { }
66
67     virtual llvm::Value* getRVal() { assert(val); return val; }
68
69     virtual DImValue* isIm() { return this; }
70 };
71
72 // constant d-value
73 struct DConstValue : DValue
74 {
75     llvm::Constant* c;
76
77     DConstValue(Type* t, llvm::Constant* con) : DValue(t), c(con) {}
78
79     virtual llvm::Value* getRVal();
80
81     virtual DConstValue* isConst() { return this; }
82 };
83
84 // null d-value
85 struct DNullValue : DConstValue
86 {
87     DNullValue(Type* t, llvm::Constant* con) : DConstValue(t,con) {}
88     virtual DNullValue* isNull() { return this; }
89 };
90
91 // variable d-value
92 struct DVarValue : DValue
93 {
94     VarDeclaration* var;
95     llvm::Value* val;
96
97     DVarValue(Type* t, VarDeclaration* vd, llvm::Value* llvmValue);
98     DVarValue(Type* t, llvm::Value* llvmValue);
99
100     virtual bool isLVal() { return true; }
101     virtual llvm::Value* getLVal();
102     virtual llvm::Value* getRVal();
103
104     virtual DVarValue* isVar() { return this; }
105 };
106
107 // field d-value
108 struct DFieldValue : DVarValue
109 {
110     DFieldValue(Type* t, llvm::Value* llvmValue) : DVarValue(t, llvmValue) {}
111     virtual DFieldValue* isField() { return this; }
112 };
113
114 // slice d-value
115 struct DSliceValue : DValue
116 {
117     llvm::Value* len;
118     llvm::Value* ptr;
119
120     DSliceValue(Type* t, llvm::Value* l, llvm::Value* p) : DValue(t), len(l), ptr(p) {}
121
122     virtual llvm::Value* getRVal();
123
124     virtual DSliceValue* isSlice() { return this; }
125 };
126
127 // function d-value
128 struct DFuncValue : DValue
129 {
130     FuncDeclaration* func;
131     llvm::Value* val;
132     llvm::Value* vthis;
133
134     DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt = 0);
135
136     virtual llvm::Value* getRVal();
137
138     virtual DFuncValue* isFunc() { return this; }
139 };
140
141 #endif // LDC_GEN_DVALUE_H
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.