From 53f72b3bab0e8b474f6ded9ee46957fd89d01cda Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 22 Apr 2005 04:49:59 +0000 Subject: remove 'another common example', which doesn't work with VC++, and indent another example properly git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21442 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'docs/ProgrammersManual.html') diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 0af3a9d..eb3bde9 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -292,8 +292,9 @@ file (note that you very rarely have to include this file directly).

if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V)) return true; - // Otherwise, it must be an instruction... - return !L->contains(cast<Instruction>(V)->getParent()); + // Otherwise, it must be an instruction... + return !L->contains(cast<Instruction>(V)->getParent()); + }

Note that you should not use an isa<> test followed @@ -322,21 +323,12 @@ file (note that you very rarely have to include this file directly).

call to isa<> and a call to cast<> into one statement, which is very convenient.

-

Another common example is:

- -
-     // Loop over all of the phi nodes in a basic block
-     BasicBlock::iterator BBI = BB->begin();
-     for (; PHINode *PN = dyn_cast<PHINode>(BBI); ++BBI)
-       std::cerr << *PN;
-   
-

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.

+ InstVisitor class to dispatch over the instruction type directly.

-- cgit v1.1