Thousands of changes to correct incorrect HTML. HTML is now valid (transitional 4.01).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6074 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7cb896a5f4
commit
aa4d1d907d
31 changed files with 6754 additions and 4801 deletions
|
|
@ -5,17 +5,18 @@
|
|||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
<a name="n1"></a><H1>6 Preprocessing</H1>
|
||||
<H1><a name="Preprocessor"></a>7 Preprocessing</H1>
|
||||
<!-- INDEX -->
|
||||
<ul>
|
||||
<li><a href="#n2">File inclusion</a>
|
||||
<li><a href="#n3">File imports</a>
|
||||
<li><a href="#n4">Conditional Compilation</a>
|
||||
<li><a href="#n5">Macro Expansion</a>
|
||||
<li><a href="#n6">SWIG Macros</a>
|
||||
<li><a href="#n7">C99 and GNU Extensions</a>
|
||||
<li><a href="#n8">Preprocessing and %{ ... %} blocks</a>
|
||||
<li><a href="#n9">Preprocessing and { ... }</a>
|
||||
<li><a href="#Preprocessor_nn2">File inclusion</a>
|
||||
<li><a href="#Preprocessor_nn3">File imports</a>
|
||||
<li><a href="#Preprocessor_nn4">Conditional Compilation</a>
|
||||
<li><a href="#Preprocessor_nn5">Macro Expansion</a>
|
||||
<li><a href="#Preprocessor_nn6">SWIG Macros</a>
|
||||
<li><a href="#Preprocessor_nn7">C99 and GNU Extensions</a>
|
||||
<li><a href="#Preprocessor_nn8">Preprocessing and %{ ... %} blocks</a>
|
||||
<li><a href="#Preprocessor_nn9">Preprocessing and { ... }</a>
|
||||
<li><a href="#Preprocessor_nn10">Viewing preprocessor output</a>
|
||||
</ul>
|
||||
<!-- INDEX -->
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ supports the standard preprocessor directives and macro expansion rules.
|
|||
However, a number of modifications and enhancements have been made. This
|
||||
chapter describes some of these modifications.
|
||||
|
||||
<a name="n2"></a><H2>6.1 File inclusion</H2>
|
||||
<H2><a name="Preprocessor_nn2"></a>7.1 File inclusion</H2>
|
||||
|
||||
|
||||
To include another file into a SWIG interface, use the <tt>%include</tt> directive
|
||||
|
|
@ -48,7 +49,7 @@ By default, the <tt>#include</tt> is ignored unless you run SWIG with the
|
|||
is that you often don't want SWIG to try and wrap everything included
|
||||
in standard header system headers and auxilliary files.
|
||||
|
||||
<a name="n3"></a><H2>6.2 File imports</H2>
|
||||
<H2><a name="Preprocessor_nn3"></a>7.2 File imports</H2>
|
||||
|
||||
|
||||
SWIG provides another file inclusion directive with the <tt>%import</tt> directive.
|
||||
|
|
@ -73,15 +74,16 @@ The <tt>-importall</tt> directive tells SWIG to follow all <tt>#include</tt> sta
|
|||
as imports. This might be useful if you want to extract type definitions from system
|
||||
header files without generating any wrappers.
|
||||
|
||||
<a name="n4"></a><H2>6.3 Conditional Compilation</H2>
|
||||
<H2><a name="Preprocessor_nn4"></a>7.3 Conditional Compilation</H2>
|
||||
|
||||
|
||||
<p>
|
||||
SWIG fully supports the use of <tt>#if</tt>, <tt>#ifdef</tt>,
|
||||
<tt>#ifndef</tt>, <tt>#else</tt>, <tt>#endif</tt> to conditionally
|
||||
include parts of an interface. The following symbols are predefined
|
||||
by SWIG when it is parsing the interface:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<blockquote><pre>
|
||||
SWIG Always defined when SWIG is processing a file
|
||||
SWIGMAC Defined when running SWIG on the Macintosh
|
||||
|
|
@ -116,13 +118,15 @@ __cplusplus Defined when -c++ option used
|
|||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
Interface files can look at these symbols as necessary to change the
|
||||
way in which an interface is generated or to mix SWIG directives with
|
||||
C code. These symbols are also defined within the C code generated by
|
||||
SWIG (except for the symbol `<tt>SWIG</tt>' which is only defined
|
||||
within the SWIG compiler).<p>
|
||||
within the SWIG compiler).
|
||||
</p>
|
||||
|
||||
<a name="n5"></a><H2>6.4 Macro Expansion</H2>
|
||||
<H2><a name="Preprocessor_nn5"></a>7.4 Macro Expansion</H2>
|
||||
|
||||
|
||||
Traditional preprocessor macros can be used in SWIG interfaces. Be aware that the <tt>#define</tt> statement
|
||||
|
|
@ -140,6 +144,7 @@ you may get some extra constants such as <tt>_FOO_H</tt> showing up in the scrip
|
|||
|
||||
<p>
|
||||
More complex macros can be defined in the standard way. For example:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
|
|
@ -157,18 +162,19 @@ The following operators can appear in macro definitions:
|
|||
<ul>
|
||||
<li><tt>#x</tt><br>
|
||||
Converts macro argument <tt>x</tt> to a string surrounded by double quotes ("x").
|
||||
</li>
|
||||
|
||||
<p>
|
||||
<li><tt>x ## y</tt><br>
|
||||
Concatenates x and y together to form <tt>xy</tt>.
|
||||
</li>
|
||||
|
||||
<p>
|
||||
<li><tt>`x`</tt><br>
|
||||
If <tt>x</tt> is a string surrounded by double quotes, do nothing. Otherwise, turn into a string
|
||||
like <tt>#x</tt>. This is a non-standard SWIG extension.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<a name="n6"></a><H2>6.5 SWIG Macros</H2>
|
||||
<H2><a name="Preprocessor_nn6"></a>7.5 SWIG Macros</H2>
|
||||
|
||||
|
||||
SWIG provides an enhanced macro capability with the <tt>%define</tt> and <tt>%enddef</tt> directives.
|
||||
|
|
@ -208,8 +214,9 @@ directives except for nested <tt>%define</tt> statements.
|
|||
The SWIG macro capability is a very quick and easy way to generate large amounts of code. In fact,
|
||||
many of SWIG's advanced features and libraries are built using this mechanism (such as C++ template
|
||||
support).
|
||||
</p>
|
||||
|
||||
<a name="n7"></a><H2>6.6 C99 and GNU Extensions</H2>
|
||||
<H2><a name="Preprocessor_nn7"></a>7.6 C99 and GNU Extensions</H2>
|
||||
|
||||
|
||||
SWIG-1.3.12 and newer releases support variadic preprocessor macros. For example:
|
||||
|
|
@ -227,10 +234,11 @@ macros defined using <tt>%define</tt>.
|
|||
<p>
|
||||
SWIG allows a variable number of arguments to be empty. However, this often results
|
||||
in an extra comma (,) and syntax error in the resulting expansion. For example:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
DEBUGF("hello"); --> fprintf(stderr,"hello",);
|
||||
DEBUGF("hello"); --> fprintf(stderr,"hello",);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
|
|
@ -244,6 +252,7 @@ To get rid of the extra comma, use <tt>##</tt> like this:
|
|||
|
||||
<p>
|
||||
SWIG also supports GNU-style variadic macros. For example:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
|
|
@ -255,7 +264,7 @@ SWIG also supports GNU-style variadic macros. For example:
|
|||
interface building. However, they are used internally to implement a number of
|
||||
SWIG directives and are provided to make SWIG more compatible with C99 code.
|
||||
|
||||
<a name="n8"></a><H2>6.7 Preprocessing and %{ ... %} blocks</H2>
|
||||
<H2><a name="Preprocessor_nn8"></a>7.7 Preprocessing and %{ ... %} blocks</H2>
|
||||
|
||||
|
||||
The SWIG preprocessor does not process any text enclosed in a code block %{ ... %}. Therefore,
|
||||
|
|
@ -276,7 +285,7 @@ int blah() {
|
|||
the contents of the <tt>%{ ... %}</tt> block are copied without
|
||||
modification to the output (including all preprocessor directives).
|
||||
|
||||
<a name="n9"></a><H2>6.8 Preprocessing and { ... }</H2>
|
||||
<H2><a name="Preprocessor_nn9"></a>7.8 Preprocessing and { ... }</H2>
|
||||
|
||||
|
||||
SWIG always runs the preprocessor on text appearing inside <tt>{ ... }</tt>. However,
|
||||
|
|
@ -310,17 +319,21 @@ to actually go into the wrapper file, prefix the preprocessor directives with <t
|
|||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
SWIG will strip the extra <tt>%</tt> and leave the preprocessor directive in the code.
|
||||
</p>
|
||||
|
||||
<H2><a name="Preprocessor_nn10"></a>7.9 Viewing preprocessor output</H2>
|
||||
|
||||
|
||||
<p>
|
||||
|
||||
<a name="n5"></a><H2>6.4 Viewing preprocessor output</H2>
|
||||
Like many compilers, SWIG supports a <tt>-E</tt> command line option to display the output from the preprocessor.
|
||||
When the <tt>-E</tt> switch is used, SWIG will not generate any wrappers.
|
||||
Instead the results after the preprocessor has run are displayed.
|
||||
This might be useful as an aid to debugging and viewing the results of macro expansions.
|
||||
</p>
|
||||
|
||||
<p><hr>
|
||||
<hr>
|
||||
|
||||
<address>SWIG 1.3 - Last Modified : March 9, 2003</address>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue