Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > bbf8b69a7c5792df8049c96b78d19811 > files > 792

doxygen-1.7.4-2.fc14.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Doxygen manual: Preprocessing</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Doxygen manual</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">Preprocessing </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p>Source files that are used as input to doxygen can be parsed by doxygen's built-in C-preprocessor.</p>
<p>By default doxygen does only partial preprocessing. That is, it evaluates conditional compilation statements (like #if) and evaluates macro definitions, but it does not perform macro expansion.</p>
<p>So if you have the following code fragment </p>
<div class="fragment"><pre class="fragment">
#define VERSION 200
#define CONST_STRING const char *

#if VERSION &gt;= 200
  static CONST_STRING version = "2.xx";
#else
  static CONST_STRING version = "1.xx";
#endif
</pre></div><p>Then by default doxygen will feed the following to its parser:</p>
<div class="fragment"><pre class="fragment">
#define VERSION
#define CONST_STRING

  static CONST_STRING version = "2.xx";
</pre></div><p>You can disable all preprocessing by setting <a class="el" href="config.html#cfg_enable_preprocessing">ENABLE_PREPROCESSING</a> to <code>NO</code> in the configuration file. In the case above doxygen will then read both statements, i.e:</p>
<div class="fragment"><pre class="fragment">
  static CONST_STRING version = "2.xx";
  static CONST_STRING version = "1.xx";
</pre></div><p>In case you want to expand the <code>CONST_STRING</code> macro, you should set the <a class="el" href="config.html#cfg_macro_expansion">MACRO_EXPANSION</a> tag in the config file to <code>YES</code>. Then the result after preprocessing becomes:</p>
<div class="fragment"><pre class="fragment">
#define VERSION
#define CONST_STRING

  static const char * version = "1.xx";
</pre></div><p>Note that doxygen will now expand <em>all</em> macro definitions (recursively if needed). This is often too much. Therefore, doxygen also allows you to expand only those defines that you explicitly specify. For this you have to set the <a class="el" href="config.html#cfg_expand_only_predef">EXPAND_ONLY_PREDEF</a> tag to <code>YES</code> and specify the macro definitions after the <a class="el" href="config.html#cfg_predefined">PREDEFINED</a> or <a class="el" href="config.html#cfg_expand_as_defined">EXPAND_AS_DEFINED</a> tag.</p>
<p>A typically example where some help from the preprocessor is needed is when dealing with Microsoft's __declspec language extension. Here is an example function.</p>
<div class="fragment"><pre class="fragment">
extern "C" void __declspec(dllexport) ErrorMsg( String aMessage,...);
</pre></div><p>When nothing is done, doxygen will be confused and see __declspec as some sort of function. To help doxygen one typically uses the following preprocessor settings:</p>
<div class="fragment"><pre class="fragment">
ENABLE_PREPROCESSING   = YES
MACRO_EXPANSION        = YES
EXPAND_ONLY_PREDEF     = YES
PREDEFINED             = __declspec(x)=
</pre></div><p>This will make sure the __declspec(dllexport) is removed before doxygen parses the source code.</p>
<p>For a more complex example, suppose you have the following obfuscated code fragment of an abstract base class called <code>IUnknown:</code> </p>
<div class="fragment"><pre class="fragment">
/*! A reference to an IID */
#ifdef __cplusplus
#define REFIID const IID &amp;
#else
#define REFIID const IID *
#endif


/*! The IUnknown interface */
DECLARE_INTERFACE(IUnknown)
{
  STDMETHOD(HRESULT,QueryInterface) (THIS_ REFIID iid, void **ppv) PURE;
  STDMETHOD(ULONG,AddRef) (THIS) PURE;
  STDMETHOD(ULONG,Release) (THIS) PURE;
};
</pre></div><p>without macro expansion doxygen will get confused, but we may not want to expand the REFIID macro, because it is documented and the user that reads the documentation should use it when implementing the interface.</p>
<p>By setting the following in the config <a href="file:">file:</a></p>
<div class="fragment"><pre class="fragment">
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION      = YES
EXPAND_ONLY_PREDEF   = YES
PREDEFINED           = "DECLARE_INTERFACE(name)=class name" \
                       "STDMETHOD(result,name)=virtual result name" \
                       "PURE= = 0" \
                       THIS_= \
                       THIS= \
		       __cplusplus
</pre></div><p>we can make sure that the proper result is fed to doxygen's parser: </p>
<div class="fragment"><pre class="fragment">
/*! A reference to an IID */
#define REFIID

/*! The IUnknown interface */
class  IUnknown
{
  virtual  HRESULT   QueryInterface ( REFIID iid, void **ppv) = 0;
  virtual  ULONG   AddRef () = 0;
  virtual  ULONG   Release () = 0;
};
</pre></div><p>Note that the <a class="el" href="config.html#cfg_predefined">PREDEFINED</a> tag accepts function like macro definitions (like <code>DECLARE_INTERFACE</code> ), normal macro substitutions (like <code>PURE</code> and <code>THIS</code>) and plain defines (like <code>__cplusplus</code>).</p>
<p>Note also that preprocessor definitions that are normally defined automatically by the preprocessor (like <code>__cplusplus</code>), have to be defined by hand with doxygen's parser (this is done because these defines are often platform/compiler specific).</p>
<p>In some cases you may want to substitute a macro name or function by something else without exposing the result to further macro substitution. You can do this but using the <code>:=</code> operator instead of <code>=</code></p>
<p>As an example suppose we have the following piece of code: </p>
<div class="fragment"><pre class="fragment">
#define QList QListT
class QListT
{
};
</pre></div><p>Then the only way to get doxygen interpret this as a class definition for class QList is to define: </p>
<div class="fragment"><pre class="fragment">
PREDEFINED = QListT:=QList
</pre></div><p>Here is an example provided by Valter Minute and Reyes Ponce that helps doxygen to wade through the boilerplate code in Microsoft's ATL &amp; MFC libraries:</p>
<div class="fragment"><pre class="fragment">
PREDEFINED           = "DECLARE_INTERFACE(name)=class name" \
                       "STDMETHOD(result,name)=virtual result name" \
                       "PURE= = 0" \
                       THIS_= \
                       THIS= \
                       DECLARE_REGISTRY_RESOURCEID=// \
                       DECLARE_PROTECT_FINAL_CONSTRUCT=// \
                       "DECLARE_AGGREGATABLE(Class)= " \
                       "DECLARE_REGISTRY_RESOURCEID(Id)= " \
                       DECLARE_MESSAGE_MAP= \
                       BEGIN_MESSAGE_MAP=/* \
                       END_MESSAGE_MAP=*/// \
                       BEGIN_COM_MAP=/* \
                       END_COM_MAP=*/// \
                       BEGIN_PROP_MAP=/* \
                       END_PROP_MAP=*/// \
                       BEGIN_MSG_MAP=/* \
                       END_MSG_MAP=*/// \
                       BEGIN_PROPERTY_MAP=/* \
                       END_PROPERTY_MAP=*/// \
                       BEGIN_OBJECT_MAP=/* \
                       END_OBJECT_MAP()=*/// \
                       DECLARE_VIEW_STATUS=// \
                       "STDMETHOD(a)=HRESULT a" \
                       "ATL_NO_VTABLE= " \
                       "__declspec(a)= " \
                       BEGIN_CONNECTION_POINT_MAP=/* \
                       END_CONNECTION_POINT_MAP=*/// \
                       "DECLARE_DYNAMIC(class)= " \
                       "IMPLEMENT_DYNAMIC(class1, class2)= " \
                       "DECLARE_DYNCREATE(class)= " \
                       "IMPLEMENT_DYNCREATE(class1, class2)= " \
                       "IMPLEMENT_SERIAL(class1, class2, class3)= " \
                       "DECLARE_MESSAGE_MAP()= " \
                       TRY=try \
                       "CATCH_ALL(e)= catch(...)" \
                       END_CATCH_ALL= \
                       "THROW_LAST()= throw"\
                       "RUNTIME_CLASS(class)=class" \
                       "MAKEINTRESOURCE(nId)=nId" \
                       "IMPLEMENT_REGISTER(v, w, x, y, z)= " \
                       "ASSERT(x)=assert(x)" \
                       "ASSERT_VALID(x)=assert(x)" \
                       "TRACE0(x)=printf(x)" \
                       "OS_ERR(A,B)={ #A, B }" \
                       __cplusplus \
                       "DECLARE_OLECREATE(class)= " \
                       "BEGIN_DISPATCH_MAP(class1, class2)= " \
                       "BEGIN_INTERFACE_MAP(class1, class2)= " \
                       "INTERFACE_PART(class, id, name)= " \
                       "END_INTERFACE_MAP()=" \
                       "DISP_FUNCTION(class, name, function, result, id)=" \
                       "END_DISPATCH_MAP()=" \
                       "IMPLEMENT_OLECREATE2(class, name, id1, id2, id3, id4,\
                        id5, id6, id7, id8, id9, id10, id11)="
</pre></div><p>As you can see doxygen's preprocessor is quite powerful, but if you want even more flexibility you can always write an input filter and specify it after the <a class="el" href="config.html#cfg_input_filter">INPUT_FILTER</a> tag.</p>
<p>If you are unsure what the effect of doxygen's preprocessing will be you can run doxygen as follows: </p>
<div class="fragment"><pre class="fragment">
  doxygen -d Preprocessor
</pre></div><p> This will instruct doxygen to dump the input sources to standard output after preprocessing has been done (Hint: set <code>QUIET = YES</code> and <code>WARNINGS = NO</code> in the configuration file to disable any other output).</p>
 
Go to the <a href="external.html">next</a> section or return to the
 <a href="index.html">index</a>.
 </div></div>
<hr class="footer"/><address class="footer"><small>Generated on Mon Jun 27 2011 for Doxygen manual by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>