summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2006-12-17 11:40:40 +0000
committerBill Wendling <isanbard@gmail.com>2006-12-17 11:40:40 +0000
commit3307244ce90bc11f939623f6d367f30db06bddf2 (patch)
tree8d800f5db82d47c1dd126c02758702a0a9c851ed /llvm
parente33ce528da43c405e3dde456dd5ad07443dd7df8 (diff)
downloadbcm5719-llvm-3307244ce90bc11f939623f6d367f30db06bddf2.tar.gz
bcm5719-llvm-3307244ce90bc11f939623f6d367f30db06bddf2.zip
Added example of how to code print() methods so that they will disappear
from the code if "cnull" is passed into them. llvm-svn: 32641
Diffstat (limited to 'llvm')
-rw-r--r--llvm/docs/CodingStandards.html23
1 files changed, 18 insertions, 5 deletions
diff --git a/llvm/docs/CodingStandards.html b/llvm/docs/CodingStandards.html
index 5b65fbc637c..97e21fa65cc 100644
--- a/llvm/docs/CodingStandards.html
+++ b/llvm/docs/CodingStandards.html
@@ -509,7 +509,7 @@ library. There are two problems with this:</p>
more pressure on the VM system on low-memory machines.</li>
</ol>
-<table>
+<table align="center">
<tbody>
<tr>
<th>Old Way</th>
@@ -520,8 +520,10 @@ library. There are two problems with this:</p>
<td align="left"><pre>#include "llvm/Support/Streams.h"</pre></td>
</tr>
<tr>
- <td align="left"><pre>DEBUG(std::cerr &lt;&lt; ...);</pre></td>
- <td align="left"><pre>DOUT &lt;&lt; ...;</pre></td>
+ <td align="left"><pre>DEBUG(std::cerr &lt;&lt; ...);
+DEBUG(dump(std::cerr));</pre></td>
+ <td align="left"><pre>DOUT &lt;&lt; ...;
+dump(DOUT);</pre></td>
</tr>
<tr>
<td align="left"><pre>std::cerr &lt;&lt; "Hello world\n";</pre></td>
@@ -536,6 +538,12 @@ library. There are two problems with this:</p>
<td align="left"><pre>llvm::cin &gt;&gt; Var;</pre></td>
</tr>
<tr>
+ <td align="left"><em>N/A</em></td>
+ <td align="left"><pre>llvm::cnull &gt;&gt; Var;</pre>
+ <ul><i>N.B.</i> Eats up argument <tt>Var</tt> outputting
+ nothing.</ul></td>
+ </tr>
+ <tr>
<td align="left"><pre>std::ostream</pre></td>
<td align="left"><pre>llvm::OStream</pre></td>
</tr>
@@ -552,9 +560,14 @@ library. There are two problems with this:</p>
// ...
print(std::cerr);</pre></td>
<td align="left"><pre>void print(std::ostream &Out);
+void print(std::ostream *Out) { if (Out) print(*Out) }
// ...
-print(*llvm::cerr.stream());</pre></td>
- </tbody>
+print(llvm::cerr);</pre>
+
+<ul><i>N.B.</i> The second <tt>print</tt> method is called by the <tt>print</tt>
+expression. It prevents the execution of the first <tt>print</tt> method if the
+stream is <tt>cnull</tt>.</ul></td>
+ </tbody>
</table>
</div>
OpenPOWER on IntegriCloud