@@ -317,44 +318,45 @@ file (note that you very rarely have to include this file directly).
checks to see if the operand is of the specified type, and if so, returns a
pointer to it (this operator does not work with references). If the operand is
not of the correct type, a null pointer is returned. Thus, this works very
- much like the
dynamic_cast operator in C++, and should be used in the
- same circumstances. Typically, the
dyn_cast<> operator is used
- in an
if statement or some other flow control statement like this:
+ much like the
dynamic_cast<> operator in C++, and should be
+ used in the same circumstances. Typically, the
dyn_cast<>
+ operator is used in an
if statement or some other flow control
+ statement like this:
-
+
if (AllocationInst *AI = dyn_cast<AllocationInst>(Val)) {
...
}
-
+
-
This form of the if statement effectively combines together a
- call to isa<> and a call to cast<> into one
- statement, which is very convenient.
+
This form of the if statement effectively combines together a call
+ to isa<> and a call to cast<> into one
+ statement, which is very convenient.
-
Note that the dyn_cast<> operator, like C++'s
- dynamic_cast or Java's instanceof operator, can be abused.
- In particular you should not use big chained if/then/else blocks to
- check for lots of different variants of classes. If you find yourself
- wanting to do this, it is much cleaner and more efficient to use the
- InstVisitor class to dispatch over the instruction type directly.
+
Note that the dyn_cast<> operator, like C++'s
+ dynamic_cast<> or Java's instanceof operator, can be
+ abused. In particular, you should not use big chained if/then/else
+ blocks to check for lots of different variants of classes. If you find
+ yourself wanting to do this, it is much cleaner and more efficient to use the
+ InstVisitor class to dispatch over the instruction type directly.
-
+
-
cast_or_null<>:
-
-
The cast_or_null<> operator works just like the
- cast<> operator, except that it allows for a null pointer as
- an argument (which it then propagates). This can sometimes be useful,
- allowing you to combine several null checks into one.
+
cast_or_null<>:
+
+
The cast_or_null<> operator works just like the
+ cast<> operator, except that it allows for a null pointer as an
+ argument (which it then propagates). This can sometimes be useful, allowing
+ you to combine several null checks into one.
-
dyn_cast_or_null<>:
+
dyn_cast_or_null<>:
-
The dyn_cast_or_null<> operator works just like the
- dyn_cast<> operator, except that it allows for a null pointer
- as an argument (which it then propagates). This can sometimes be useful,
- allowing you to combine several null checks into one.
+
The dyn_cast_or_null<> operator works just like the
+ dyn_cast<> operator, except that it allows for a null pointer
+ as an argument (which it then propagates). This can sometimes be useful,
+ allowing you to combine several null checks into one.
-
+
These five templates can be used with any classes, whether they have a
v-table or not. To add support for these templates, you simply need to add
@@ -366,7 +368,7 @@ are lots of examples in the LLVM source base.