PageRenderTime 65ms CodeModel.GetById 15ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/phoenix/doc/html/phoenix/inside/expression/boilerplate_macros.html

http://hadesmem.googlecode.com/
HTML | 515 lines | 494 code | 21 blank | 0 comment | 0 complexity | b8f4d85b5b6a0f7f3ec3218b66e78c93 MD5 | raw file
  1<html>
  2<head>
  3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4<title>Boilerplate Macros</title>
  5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
  6<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
  7<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Phoenix 3.0">
  8<link rel="up" href="../expression.html" title="Phoenix Expressions">
  9<link rel="prev" href="../expression.html" title="Phoenix Expressions">
 10<link rel="next" href="../actions.html" title="More on Actions">
 11</head>
 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 13<table cellpadding="2" width="100%"><tr>
 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
 15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
 20</tr></table>
 21<hr>
 22<div class="spirit-nav">
 23<a accesskey="p" href="../expression.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../expression.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../actions.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
 24</div>
 25<div class="section">
 26<div class="titlepage"><div><div><h4 class="title">
 27<a name="phoenix.inside.expression.boilerplate_macros"></a><a class="link" href="boilerplate_macros.html" title="Boilerplate Macros">Boilerplate
 28        Macros</a>
 29</h4></div></div></div>
 30<div class="toc"><dl>
 31<dt><span class="section"><a href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression">BOOST_PHOENIX_DEFINE_EXPRESSION</a></span></dt>
 32<dt><span class="section"><a href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg">BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG</a></span></dt>
 33<dt><span class="section"><a href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT</a></span></dt>
 34<dt><span class="section"><a href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT_VARARG</a></span></dt>
 35</dl></div>
 36<p>
 37          When having more and more expressions, you start to realize that this is
 38          a very repetetive task. Phoenix provides boilerplate macros that make defining
 39          Phoenix Expressions as you have seen in the <a class="link" href="../expression.html" title="Phoenix Expressions">previous
 40          section</a> look like a piece of cake.
 41        </p>
 42<div class="section">
 43<div class="titlepage"><div><div><h5 class="title">
 44<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression"></a><a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression" title="BOOST_PHOENIX_DEFINE_EXPRESSION">BOOST_PHOENIX_DEFINE_EXPRESSION</a>
 45</h5></div></div></div>
 46<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.description"></a><h6>
 47<a name="id843517"></a>
 48            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.description">Description</a>
 49          </h6>
 50<p>
 51            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span></code>
 52            is a macro that can be used to generate all the necessary boilerplate
 53            to create Phoenix Expressions
 54          </p>
 55<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.synopsis"></a><h6>
 56<a name="id843552"></a>
 57            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.synopsis">Synopsis</a>
 58          </h6>
 59<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span><span class="special">(</span>
 60    <span class="special">(</span><span class="identifier">namespace_seq</span><span class="special">)(</span><span class="identifier">name</span><span class="special">)</span>
 61  <span class="special">,</span> <span class="special">(</span><span class="identifier">child_grammar0</span><span class="special">)</span>
 62    <span class="special">(</span><span class="identifier">child_grammar1</span><span class="special">)</span>
 63    <span class="special">...</span>
 64<span class="special">)</span>
 65</pre>
 66<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.semantics"></a><h6>
 67<a name="id843658"></a>
 68            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.semantics">Semantics</a>
 69          </h6>
 70<p>
 71            The above macro generates the necessary code for an expression <code class="computeroutput"><span class="identifier">name</span></code> in namespace <code class="computeroutput"><span class="identifier">namespace_seq</span></code>.
 72            The sequence of <code class="computeroutput"><span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span></code> declares how many children the expression
 73            will have and what <code class="computeroutput"><span class="identifier">proto</span><span class="special">::</span><span class="identifier">grammar</span></code>
 74            they match.
 75          </p>
 76<p>
 77            The macro should be used at global scope. <code class="computeroutput"><span class="identifier">namespace_seq</span></code>
 78            shall be the sequence of namespaces under which the following symbols
 79            will be defined:
 80          </p>
 81<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">tag</span>
 82<span class="special">{</span>
 83    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
 84<span class="special">}</span>
 85
 86<span class="keyword">namespace</span> <span class="identifier">expression</span>
 87<span class="special">{</span>
 88    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
 89    <span class="keyword">struct</span> <span class="identifier">name</span>
 90        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
 91            <span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span>
 92          <span class="special">,</span> <span class="identifier">A0</span>
 93          <span class="special">,</span> <span class="identifier">A1</span>
 94            <span class="special">...</span>
 95          <span class="special">,</span> <span class="identifier">AN</span>
 96        <span class="special">&gt;</span>
 97<span class="special">}</span>
 98
 99<span class="keyword">namespace</span> <span class="identifier">rule</span>
100<span class="special">{</span>
101    <span class="keyword">struct</span> <span class="identifier">name</span>
102        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
103            <span class="identifier">child_grammar0</span>
104          <span class="special">,</span> <span class="identifier">child_grammar1</span>
105            <span class="special">...</span>
106          <span class="special">,</span> <span class="identifier">child_grammarN</span>
107        <span class="special">&gt;</span>
108    <span class="special">{};</span>
109<span class="special">}</span>
110
111<span class="keyword">namespace</span> <span class="identifier">functional</span>
112<span class="special">{</span>
113    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// A polymorphic function object that can be called to create the expression node
114</span><span class="special">}</span>
115
116<span class="keyword">namespace</span> <span class="identifier">result_of</span>
117<span class="special">{</span>
118    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
119    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// The result type of the expression node
120</span><span class="special">}</span>
121
122<span class="comment">// convenience polymorphic function to create an expression node
123</span><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
124<span class="identifier">result_of</span><span class="special">::</span><span class="identifier">make_name</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="identifier">AN</span><span class="special">&gt;</span>
125<span class="identifier">make_name</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span> <span class="special">...</span> <span class="identifier">AN</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">an</span><span class="special">);</span>
126</pre>
127<p>
128            This macros also adds a specialization for <code class="computeroutput"><span class="identifier">meta_grammar</span><span class="special">::</span><span class="identifier">case_</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span><span class="special">&gt;</span></code> to enable the rule for further use
129            in actions.
130          </p>
131<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.header"></a><h6>
132<a name="id844495"></a>
133            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.header">Header</a>
134          </h6>
135<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">expression</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
136</pre>
137<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.example"></a><h6>
138<a name="id844579"></a>
139            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression.example">Example</a>
140          </h6>
141<p>
142            The example from the previous section can be rewritten as:
143          </p>
144<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span><span class="special">(</span>
145    <span class="special">(</span><span class="identifier">plus</span><span class="special">)</span>
146  <span class="special">,</span> <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>               <span class="comment">// Lhs
147</span>    <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>               <span class="comment">// Rhs
148</span><span class="special">)</span>
149
150<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Lhs</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Rhs</span><span class="special">&gt;</span>
151<span class="keyword">typename</span> <span class="identifier">plus</span><span class="special">&lt;</span><span class="identifier">Lhs</span><span class="special">,</span> <span class="identifier">Rhs</span><span class="special">&gt;::</span><span class="identifier">type</span>
152<span class="identifier">plus</span><span class="special">(</span><span class="identifier">Lhs</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">Rhs</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span>
153<span class="special">{</span>
154    <span class="keyword">return</span> <span class="identifier">expression</span><span class="special">::</span><span class="identifier">plus</span><span class="special">&lt;</span><span class="identifier">Lhs</span><span class="special">,</span> <span class="identifier">Rhs</span><span class="special">&gt;::</span><span class="identifier">make</span><span class="special">(</span><span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">rhs</span><span class="special">);</span>
155<span class="special">}</span>
156</pre>
157</div>
158<div class="section">
159<div class="titlepage"><div><div><h5 class="title">
160<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg"></a><a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg" title="BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG">BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG</a>
161</h5></div></div></div>
162<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.description"></a><h6>
163<a name="id844930"></a>
164            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.description">Description</a>
165          </h6>
166<p>
167            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG</span></code>
168            is a macro that can be used to generate all the necessary boilerplate
169            to create Phoenix Expressions
170          </p>
171<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.synopsis"></a><h6>
172<a name="id844966"></a>
173            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.synopsis">Synopsis</a>
174          </h6>
175<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG</span><span class="special">(</span>
176    <span class="special">(</span><span class="identifier">namespace_seq</span><span class="special">)(</span><span class="identifier">name</span><span class="special">)</span>
177  <span class="special">,</span> <span class="special">(</span><span class="identifier">child_grammar0</span><span class="special">)</span>
178    <span class="special">(</span><span class="identifier">child_grammar1</span><span class="special">)</span>
179    <span class="special">...</span>
180    <span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span>
181  <span class="special">,</span> <span class="identifier">N</span>
182<span class="special">)</span>
183</pre>
184<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.semantics"></a><h6>
185<a name="id845097"></a>
186            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.semantics">Semantics</a>
187          </h6>
188<p>
189            The above macro generates the necessary code for an expression <code class="computeroutput"><span class="identifier">name</span></code> in namespace <code class="computeroutput"><span class="identifier">namespace_seq</span></code>.
190            <code class="computeroutput"><span class="identifier">N</span></code> is the maximum number
191            of variable children. All but the last elements in the grammar sequence
192            are required children of the expression, and the last denotes a variable
193            number of children. The number of children an expression of this kind
194            can hold is therefor <code class="computeroutput"><span class="identifier">N</span><span class="special">-</span><span class="number">1</span></code> plus
195            the size of the sequence
196          </p>
197<p>
198            The macro should be used at global scope. <code class="computeroutput"><span class="identifier">namespace_seq</span></code>
199            shall be the sequence of namespaces under which the following symbols
200            will be defined:
201          </p>
202<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">tag</span>
203<span class="special">{</span>
204    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
205<span class="special">}</span>
206
207<span class="keyword">namespace</span> <span class="identifier">expression</span>
208<span class="special">{</span>
209    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
210    <span class="keyword">struct</span> <span class="identifier">name</span>
211        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
212            <span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span>
213          <span class="special">,</span> <span class="identifier">A0</span>
214          <span class="special">,</span> <span class="identifier">A1</span>
215            <span class="special">...</span>
216          <span class="special">,</span> <span class="identifier">AN</span>
217        <span class="special">&gt;</span>
218    <span class="special">{};</span>
219<span class="special">}</span>
220
221<span class="keyword">namespace</span> <span class="identifier">rule</span>
222<span class="special">{</span>
223    <span class="keyword">struct</span> <span class="identifier">name</span>
224        <span class="special">:</span> <span class="identifier">expression</span><span class="special">::</span><span class="identifier">name</span><span class="special">&lt;</span>
225            <span class="identifier">child_grammar0</span>
226          <span class="special">,</span> <span class="identifier">child_grammar1</span>
227            <span class="special">...</span>
228          <span class="special">,</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">vararg</span><span class="special">&lt;</span><span class="identifier">child_grammarN</span><span class="special">&gt;</span>
229        <span class="special">&gt;</span>
230    <span class="special">{};</span>
231<span class="special">}</span>
232
233<span class="keyword">namespace</span> <span class="identifier">functional</span>
234<span class="special">{</span>
235    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// A polymorphic function object that can be called to create the expression node
236</span><span class="special">}</span>
237
238<span class="keyword">namespace</span> <span class="identifier">result_of</span>
239<span class="special">{</span>
240    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
241    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// The result type of the expression node
242</span><span class="special">}</span>
243
244<span class="comment">// convenience polymorphic function to create an expression node
245</span><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
246<span class="identifier">result_of</span><span class="special">::</span><span class="identifier">make_name</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="identifier">AN</span><span class="special">&gt;</span>
247<span class="identifier">make_name</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span> <span class="special">...</span> <span class="identifier">AN</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">an</span><span class="special">);</span>
248</pre>
249<p>
250            This macros also adds a specialization for <code class="computeroutput"><span class="identifier">meta_grammar</span><span class="special">::</span><span class="identifier">case_</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span><span class="special">&gt;</span></code> to enable the rule for further use
251            in actions.
252          </p>
253<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.header"></a><h6>
254<a name="id845946"></a>
255            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.header">Header</a>
256          </h6>
257<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">expression</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
258</pre>
259<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.example"></a><h6>
260<a name="id846029"></a>
261            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_vararg.example">Example</a>
262          </h6>
263<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG</span><span class="special">(</span>
264    <span class="special">(</span><span class="identifier">boost</span><span class="special">)(</span><span class="identifier">phoenix</span><span class="special">)(</span><span class="identifier">mem_fun_ptr</span><span class="special">)</span>
265  <span class="special">,</span> <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>                <span class="comment">// Pointer to Object
266</span>    <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>                <span class="comment">// Member pointer
267</span>    <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>                <span class="comment">// Variable number of arguments
268</span>  <span class="special">,</span> <span class="identifier">BOOST_PHOENIX_LIMIT</span>
269<span class="special">)</span>
270</pre>
271<p>
272            This defines the member function pointer operator expression as described
273            in <a class="link" href="../../modules/operator.html" title="Operator">operators</a>.
274          </p>
275</div>
276<div class="section">
277<div class="titlepage"><div><div><h5 class="title">
278<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext"></a><a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext" title="BOOST_PHOENIX_DEFINE_EXPRESSION_EXT">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT</a>
279</h5></div></div></div>
280<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.description"></a><h6>
281<a name="id846209"></a>
282            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.description">Description</a>
283          </h6>
284<p>
285            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT</span></code>
286            is a macro that can be used to generate all the necessary boilerplate
287            to create Phoenix Expressions
288          </p>
289<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.synopsis"></a><h6>
290<a name="id846245"></a>
291            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.synopsis">Synopsis</a>
292          </h6>
293<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT</span><span class="special">(</span>
294    <span class="identifier">actor</span>
295  <span class="special">,</span> <span class="special">(</span><span class="identifier">namespace_seq</span><span class="special">)(</span><span class="identifier">name</span><span class="special">)</span>
296  <span class="special">,</span> <span class="special">(</span><span class="identifier">child_grammar0</span><span class="special">)</span>
297    <span class="special">(</span><span class="identifier">child_grammar1</span><span class="special">)</span>
298    <span class="special">...</span>
299    <span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span>
300  <span class="special">,</span> <span class="identifier">N</span>
301<span class="special">)</span>
302</pre>
303<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.semantics"></a><h6>
304<a name="id846388"></a>
305            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.semantics">Semantics</a>
306          </h6>
307<p>
308            The above macro generates the necessary code for an expression <code class="computeroutput"><span class="identifier">name</span></code> in namespace <code class="computeroutput"><span class="identifier">namespace_seq</span></code>.
309            The sequence of <code class="computeroutput"><span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span></code> declares how many children the expression
310            will have and what <code class="computeroutput"><span class="identifier">proto</span><span class="special">::</span><span class="identifier">grammar</span></code>
311            they match.
312          </p>
313<p>
314            The macro should be used at global scope. <code class="computeroutput"><span class="identifier">namespace_seq</span></code>
315            shall be the sequence of namespaces under which the following symbols
316            will be defined:
317          </p>
318<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">tag</span>
319<span class="special">{</span>
320    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
321<span class="special">}</span>
322
323<span class="keyword">namespace</span> <span class="identifier">expression</span>
324<span class="special">{</span>
325    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
326    <span class="keyword">struct</span> <span class="identifier">name</span>
327        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr_ext</span><span class="special">&lt;</span>
328            <span class="identifier">actor</span>
329          <span class="special">,</span> <span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span>
330          <span class="special">,</span> <span class="identifier">A0</span>
331          <span class="special">,</span> <span class="identifier">A1</span>
332            <span class="special">...</span>
333          <span class="special">,</span> <span class="identifier">AN</span>
334        <span class="special">&gt;</span>
335<span class="special">}</span>
336
337<span class="keyword">namespace</span> <span class="identifier">rule</span>
338<span class="special">{</span>
339    <span class="keyword">struct</span> <span class="identifier">name</span>
340        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
341            <span class="identifier">child_grammar0</span>
342          <span class="special">,</span> <span class="identifier">child_grammar1</span>
343            <span class="special">...</span>
344          <span class="special">,</span> <span class="identifier">child_grammarN</span>
345        <span class="special">&gt;</span>
346    <span class="special">{};</span>
347<span class="special">}</span>
348
349<span class="keyword">namespace</span> <span class="identifier">functional</span>
350<span class="special">{</span>
351    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// A polymorphic function object that can be called to create the expression node
352</span><span class="special">}</span>
353
354<span class="keyword">namespace</span> <span class="identifier">result_of</span>
355<span class="special">{</span>
356    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
357    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// The result type of the expression node
358</span><span class="special">}</span>
359
360<span class="comment">// convenience polymorphic function to create an expression node
361</span><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
362<span class="identifier">result_of</span><span class="special">::</span><span class="identifier">make_name</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="identifier">AN</span><span class="special">&gt;</span>
363<span class="identifier">make_name</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span> <span class="special">...</span> <span class="identifier">AN</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">an</span><span class="special">);</span>
364</pre>
365<p>
366            This macros also adds a specialization for <code class="computeroutput"><span class="identifier">meta_grammar</span><span class="special">::</span><span class="identifier">case_</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span><span class="special">&gt;</span></code> to enable the rule for further use
367            in actions.
368          </p>
369<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.header"></a><h6>
370<a name="id847236"></a>
371            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.header">Header</a>
372          </h6>
373<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">expression</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
374</pre>
375<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.example"></a><h6>
376<a name="id847320"></a>
377            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext.example">Example</a>
378          </h6>
379<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT</span><span class="special">(</span>
380    <span class="identifier">if_actor</span>
381  <span class="special">,</span> <span class="special">(</span><span class="identifier">boost</span><span class="special">)(</span><span class="identifier">phoenix</span><span class="special">)(</span><span class="identifier">if_</span><span class="special">)</span>
382  <span class="special">,</span> <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span> <span class="comment">// Cond
383</span>    <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span> <span class="comment">// Then
384</span><span class="special">)</span>
385</pre>
386<p>
387            This defines the if_ expression. The custom actor defines <code class="computeroutput"><span class="identifier">else_</span></code> as a member.
388          </p>
389</div>
390<div class="section">
391<div class="titlepage"><div><div><h5 class="title">
392<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg"></a><a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg" title="BOOST_PHOENIX_DEFINE_EXPRESSION_EXT_VARARG">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT_VARARG</a>
393</h5></div></div></div>
394<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.description"></a><h6>
395<a name="id847483"></a>
396            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.description">Description</a>
397          </h6>
398<p>
399            <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT_VARARG</span></code>
400            is a macro that can be used to generate all the necessary boilerplate
401            to create Phoenix Expressions
402          </p>
403<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.synopsis"></a><h6>
404<a name="id847519"></a>
405            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.synopsis">Synopsis</a>
406          </h6>
407<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION_EXT_VARARG</span><span class="special">(</span>
408    <span class="identifier">actor</span>
409  <span class="special">,</span> <span class="special">(</span><span class="identifier">namespace_seq</span><span class="special">)(</span><span class="identifier">name</span><span class="special">)</span>
410  <span class="special">,</span> <span class="special">(</span><span class="identifier">child_grammar0</span><span class="special">)</span>
411    <span class="special">(</span><span class="identifier">child_grammar1</span><span class="special">)</span>
412    <span class="special">...</span>
413    <span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span>
414  <span class="special">,</span> <span class="identifier">N</span>
415<span class="special">)</span>
416</pre>
417<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.semantics"></a><h6>
418<a name="id847663"></a>
419            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.semantics">Semantics</a>
420          </h6>
421<p>
422            The above macro generates the necessary code for an expression <code class="computeroutput"><span class="identifier">name</span></code> in namespace <code class="computeroutput"><span class="identifier">namespace_seq</span></code>.
423            <code class="computeroutput"><span class="identifier">N</span></code> is the maximum number
424            of variable children. All but the last elements in the grammar sequence
425            are required children of the expression, and the last denotes a variable
426            number of children. The number of children an expression of this kind
427            can hold is therefor <code class="computeroutput"><span class="identifier">N</span><span class="special">-</span><span class="number">1</span></code> plus
428            the size of the sequence
429          </p>
430<p>
431            The macro should be used at global scope. <code class="computeroutput"><span class="identifier">namespace_seq</span></code>
432            shall be the sequence of namespaces under which the following symbols
433            will be defined:
434          </p>
435<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">tag</span>
436<span class="special">{</span>
437    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
438<span class="special">}</span>
439
440<span class="keyword">namespace</span> <span class="identifier">expression</span>
441<span class="special">{</span>
442    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
443    <span class="keyword">struct</span> <span class="identifier">name</span>
444        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr_ext</span><span class="special">&lt;</span>
445            <span class="identifier">actor</span>
446          <span class="special">,</span> <span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span>
447          <span class="special">,</span> <span class="identifier">A0</span>
448          <span class="special">,</span> <span class="identifier">A1</span>
449            <span class="special">...</span>
450          <span class="special">,</span> <span class="identifier">AN</span>
451        <span class="special">&gt;</span>
452    <span class="special">{};</span>
453<span class="special">}</span>
454
455<span class="keyword">namespace</span> <span class="identifier">rule</span>
456<span class="special">{</span>
457    <span class="keyword">struct</span> <span class="identifier">name</span>
458        <span class="special">:</span> <span class="identifier">expression</span><span class="special">::</span><span class="identifier">name</span><span class="special">&lt;</span>
459            <span class="identifier">child_grammar0</span>
460          <span class="special">,</span> <span class="identifier">child_grammar1</span>
461            <span class="special">...</span>
462          <span class="special">,</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">vararg</span><span class="special">&lt;</span><span class="identifier">child_grammarN</span><span class="special">&gt;</span>
463        <span class="special">&gt;</span>
464    <span class="special">{};</span>
465<span class="special">}</span>
466
467<span class="keyword">namespace</span> <span class="identifier">functional</span>
468<span class="special">{</span>
469    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// A polymorphic function object that can be called to create the expression node
470</span><span class="special">}</span>
471
472<span class="keyword">namespace</span> <span class="identifier">result_of</span>
473<span class="special">{</span>
474    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
475    <span class="keyword">struct</span> <span class="identifier">make_name</span><span class="special">;</span> <span class="comment">// The result type of the expression node
476</span><span class="special">}</span>
477
478<span class="comment">// convenience polymorphic function to create an expression node
479</span><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
480<span class="identifier">result_of</span><span class="special">::</span><span class="identifier">make_name</span><span class="special">&lt;</span><span class="identifier">A0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="identifier">AN</span><span class="special">&gt;</span>
481<span class="identifier">make_name</span><span class="special">(</span><span class="identifier">A0</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a0</span><span class="special">,</span> <span class="identifier">A1</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">a1</span> <span class="special">...</span> <span class="identifier">AN</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">an</span><span class="special">);</span>
482</pre>
483<p>
484            This macros also adds a specialization for <code class="computeroutput"><span class="identifier">meta_grammar</span><span class="special">::</span><span class="identifier">case_</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span><span class="special">&gt;</span></code> to enable the rule for further use
485            in actions.
486          </p>
487<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.header"></a><h6>
488<a name="id848523"></a>
489            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.header">Header</a>
490          </h6>
491<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">expression</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
492</pre>
493<a name="phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.example"></a><h6>
494<a name="id848607"></a>
495            <a class="link" href="boilerplate_macros.html#phoenix.inside.expression.boilerplate_macros.boost_phoenix_define_expression_ext_vararg.example">Example</a>
496          </h6>
497<p>
498            TBD
499          </p>
500</div>
501</div>
502<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
503<td align="left"></td>
504<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2010 Joel de Guzman, Dan Marsden, Thomas Heller<p>
505        Distributed under the Boost Software License, Version 1.0. (See accompanying
506        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
507      </p>
508</div></td>
509</tr></table>
510<hr>
511<div class="spirit-nav">
512<a accesskey="p" href="../expression.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../expression.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../actions.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
513</div>
514</body>
515</html>