llvm.org GIT mirror llvm / 7295eb4
Add support for newer cleaner isa, cast, dyn_cast git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@693 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
4 changed file(s) with 65 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
162162 // TODO: This is bad
163163 // Loop to ignore constant pool references
164164 while (It != BB->use_end() &&
165 ((!(*It)->isInstruction()) ||
165 ((!isa(*It)) ||
166166 !(((Instruction*)(*It))->isTerminator())))
167167 ++It;
168168 }
176176 inline bool operator!=(const _Self& x) const { return !operator==(x); }
177177
178178 inline pointer operator*() const {
179 return (*It)->castInstructionAsserting()->getParent();
179 return cast(*It)->getParent();
180180 }
181181 inline pointer *operator->() const { return &(operator*()); }
182182
8484 // and then drops all references to its operands.
8585 //
8686 void dropAllReferences();
87
88
89 // Methods for support type inquiry through isa, cast, and dyn_cast:
90 static inline bool isa(const Instruction *I) { return true; }
91 static inline bool isa(const Value *V) {
92 return V->getValueType() == Value::InstructionVal;
93 }
8794
8895 //----------------------------------------------------------------------
8996 // Exported enumerations...
192192 inline const DerivedType *castDerivedTypeAsserting() const {
193193 assert(isDerivedType());
194194 return (const DerivedType*)this;
195 }
196
197 // Methods for support type inquiry through isa, cast, and dyn_cast:
198 static inline bool isa(const Type *T) { return true; }
199 static inline bool isa(const Value *V) {
200 return V->getValueType() == Value::TypeVal;
195201 }
196202
197203 // Methods for determining the subtype of this Type. The cast*() methods are
11 //
22 // This file defines the very important Value class. This is subclassed by a
33 // bunch of other important classes, like Def, Method, Module, Type, etc...
4 //
5 // This file also defines the Use<> template for users of value.
6 //
7 // This file also defines the isa(), cast(), and dyn_cast() templates.
48 //
59 //===----------------------------------------------------------------------===//
610
155159 void killUse(User *I);
156160 };
157161
162
163 //===----------------------------------------------------------------------===//
164 // UseTy Class
165 //===----------------------------------------------------------------------===//
166
158167 // UseTy and it's friendly typedefs (Use) are here to make keeping the "use"
159168 // list of a definition node up-to-date really easy.
160169 //
195204 }
196205 };
197206
198 typedef UseTy Use;
207 typedef UseTy Use; // Provide Use as a common UseTy type
208
209
210 //===----------------------------------------------------------------------===//
211 // Type Checking Templates
212 //===----------------------------------------------------------------------===//
213
214 // isa - Return true if the parameter to the template is an instance of the
215 // template type argument. Used like this:
216 //
217 // if (isa(myVal)) { ... }
218 //
219 template
220 bool isa(Y *Val) { return X::isa(Val); }
221
222
223 // cast - Return the argument parameter cast to the specified type. This
224 // casting operator asserts that the type is correct, so it does not return null
225 // on failure. Used Like this:
226 //
227 // cast< Instruction>(myVal)->getParent()
228 // cast(myVal)->getParent()
229 //
230 template
231 X *cast(Y *Val) {
232 assert(isa(Val) && "Invalid cast argument type!");
233 return (X*)Val;
234 }
235
236
237 // dyn_cast - Return the argument parameter cast to the specified type. This
238 // casting operator returns null if the argument is of the wrong type, so it can
239 // be used to test for a type as well as cast if successful. This should be
240 // used in the context of an if statement like this:
241 //
242 // if (const Instruction *I = dyn_cast(myVal)) { ... }
243 //
244 template
245 X *dyn_cast(Y *Val) {
246 return isa(Val) ? (X*)Val : 0;
247 }
199248
200249 #endif