C Preprocessor srcML
Language Element | Elements | Subelements |
---|---|---|
C Preprocessor | ||
#define | <cpp:define> | <cpp:directive>, <cpp:macro>, <cpp:value> |
#undef | <cpp:undef> | <cpp:directive>, <name> |
#if | <cpp:if> | <cpp:directive>, <expr> |
#ifdef | <cpp:ifdef> | <cpp:directive>, <expr> |
#ifndef | <cpp:ifndef> | <cpp:directive>, <expr> |
#else | <cpp:else> | <cpp:directive> |
#elif | <cpp:elif> | <cpp:directive>, <expr> |
#endif | <cpp:if> | <cpp:directive> |
#include | <cpp:include> | <cpp:directive>, <cpp:file> |
#pragma | <cpp:pragma> | <cpp:directive> |
#error | <cpp:error> | <cpp:value> |
#line | <cpp:line> | <cpp:directive>, <cpp:number> |
#define
Element
- <cpp:define>
SubElements
- <cpp:directive>
- <cpp:macro>
- <cpp:value>
Examples
Trivial #define
#define WIDTH 80
#define LENGTH ( WIDTH + 10 )
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>WIDTH</name></cpp:macro> <cpp:value>80</cpp:value></cpp:define>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>LENGTH</name></cpp:macro> <cpp:value>( WIDTH + 10 )</cpp:value></cpp:define>
XPath Query Examples
Description:
Find all of the uses of #define
.
XPath
//cpp:define
Description:
Find all macro definitions of a macro with the name LENGTH
.
XPath
//cpp:define[cpp:macro/src:name[. = 'LENGTH']]
Description:
Find all values of all macro definitions.
XPath
//cpp:define/cpp:value
#define used like a function
#define multiply( f1, f2 ) ( f1 * f2 )
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>multiply</name><parameter_list>( <param><type><name>f1</name></type></param>, <param><type><name>f2</name></type></param> )</parameter_list></cpp:macro> <cpp:value>( f1 * f2 )</cpp:value></cpp:define>
XPath Query Examples
Description:
Find all macro definitions which have parameters.
XPath
//cpp:define[src:parameter_list]
Description:
Get the names of all parameters within all macro declarations.
XPath
//cpp:define/src:parameter_list/src:param
#define a variadic macro
#define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__)
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>eprintf</name><parameter_list>(<param><type><name>format</name></type></param>, <param><type><type:modifier>...</type:modifier></type></param>)</parameter_list></cpp:macro> <cpp:value>fprintf (stderr, format, __VA_ARGS__)</cpp:value></cpp:define>
XPath Query Example
Description:
Find all variadic macro definitions.
XPath
//cpp:define[src:parameter_list[ .//type:modifier = '...']]
#undef
Element
- <cpp:undef>
SubElements
- <cpp:directive>
- <name>
Example
#define multiply( f1, f2 ) ( f1 * f2 )
#undef multiply
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>multiply</name><parameter_list>( <param><type><name>f1</name></type></param>, <param><type><name>f2</name></type></param> )</parameter_list></cpp:macro> <cpp:value>( f1 * f2 )</cpp:value></cpp:define>
<cpp:undef>#<cpp:directive>undef</cpp:directive> <name>multiply</name></cpp:undef>
XPath Query Examples
Description:
Find all uses of #undef
.
XPath
//cpp:undef
Description:
Find the name of all undefined macros.
XPath
//cpp:undef/src:name
Description:
Find all macro names which are defined and undefined.
XPath
//cpp:undef/src:name[.= //cpp:define/src:macro/src:name]
#if
Element
- <cpp:if>
SubElements
- <cpp:directive>
- <expr>
Example
#if DLEVEL > 5
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><name>DLEVEL</name> <op:operator>></op:operator> <lit:literal type="number">5</lit:literal></expr></cpp:if>
XPath Query Examples
Description:
Find all uses of #if
.
XPath
//cpp:if
Description:
Find all conditions used by #if
.
XPath
//cpp:if/src:expr
#ifdef
Element
- <cpp:ifdef>
SubElements
- <cpp:directive>
- <expr>
Example
#ifdef NDEBUG
if(x >20) {
abort();
}
#endif
<cpp:ifdef>#<cpp:directive>ifdef</cpp:directive> <name>NDEBUG</name></cpp:ifdef>
<if>if<condition>(<expr><name>x</name> <op:operator>></op:operator><lit:literal type="number">20</lit:literal></expr>)</condition><then> <block>{
<expr_stmt><expr><call><name>abort</name><argument_list>()</argument_list></call></expr>;</expr_stmt>
}
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif></block></then></if>
XPath Query Example
Description:
Find all uses of #ifdef
.
XPath
//cpp:ifdef
#ifndef
Element
- <cpp:ifndef>
SubElements
- <cpp:directive>
- <expr>
Example
#ifndef test
#define final
#endif
<cpp:ifndef>#<cpp:directive>ifndef</cpp:directive> <name>test</name></cpp:ifndef>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>final</name></cpp:macro></cpp:define>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>
XPath Query Example
Description:
Find all uses of #ifndef
.
XPath
//cpp:ifndef
#else
Element
- <cpp:else>
SubElement
- <cpp:directive>
Example
#if DLEVEL > 5
#define SIGNAL 1
#else
#define SIGNAL 0
#endif
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><name>DLEVEL</name> <op:operator>></op:operator> <lit:literal type="number">5</lit:literal></expr></cpp:if>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>SIGNAL</name></cpp:macro> <cpp:value>1</cpp:value></cpp:define>
<cpp:else>#<cpp:directive>else</cpp:directive></cpp:else>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>SIGNAL</name></cpp:macro> <cpp:value>0</cpp:value></cpp:define>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>
XPath Query Example
Description:
Find all uses of #else
.
XPath
//cpp:else
#elif
Element
- <cpp:elif>
SubElements
- <cpp:directive>
- <expr>
Example
#if DLEVEL == 0
#define STACK 0
#elif DLEVEL == 1
#define STACK 100
#elif DLEVEL > 5
display( debugptr );
#else
#define STACK 200
#endif
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><name>DLEVEL</name> <op:operator>==</op:operator> <lit:literal type="number">0</lit:literal></expr></cpp:if>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>STACK</name></cpp:macro> <cpp:value>0</cpp:value></cpp:define>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><name>DLEVEL</name> <op:operator>==</op:operator> <lit:literal type="number">1</lit:literal></expr></cpp:elif>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>STACK</name></cpp:macro> <cpp:value>100</cpp:value></cpp:define>
<cpp:elif>#<cpp:directive>elif</cpp:directive> <expr><name>DLEVEL</name> <op:operator>></op:operator> <lit:literal type="number">5</lit:literal></expr></cpp:elif>
<expr_stmt><expr><call><name>display</name><argument_list>( <argument><expr><name>debugptr</name></expr></argument> )</argument_list></call></expr>;
<cpp:else>#<cpp:directive>else</cpp:directive></cpp:else>
<cpp:define>#<cpp:directive>define</cpp:directive> <cpp:macro><name>STACK</name></cpp:macro> <cpp:value>200</cpp:value></cpp:define>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif></expr_stmt>
XPath Query Examples
Description:
Find all uses of #elif
.
XPath
//cpp:elif
Description:
Find all conditional expressions used with #elif
.
XPath
//cpp:elif/src:expr
#endif
Element
- <cpp:if>
SubElement
- <cpp:directive>
Example
#endif
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>
XPath Query Example
Description:
Find all uses of #endif
.
XPath
//cpp:endif
#include
Element
- <cpp:include>
SubElements
- <cpp:directive>
- <cpp:file>
Example
#include <FileName>
#include "fileName"
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><FileName></cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><lit:literal type="string">"fileName"</lit:literal></cpp:file></cpp:include>
XPath Query Examples
Description:
Find all includes.
XPath
//cpp:include
Description:
Find all include that use quotations.
XPath
//cpp:include[cpp:file/lit:literal[@type ='string']]
Description:
Find the names of all included files.
XPath
//cpp:include/cpp:file//text()
#pragma
Element
- <cpp:pragma>
SubElement
- <cpp:directive>
Example
// #pragma example
#pragma warning( once : 4385 )
#pragma ms_struct on
<comment type="line">// #pragma example</comment>
<cpp:pragma>#<cpp:directive>pragma</cpp:directive> warning( once : 4385 )</cpp:pragma>
<cpp:pragma>#<cpp:directive>pragma</cpp:directive> ms_struct on</cpp:pragma>
XPath Query Example
Description:
Find all uses of #pragma
.
XPath
//cpp:pragma
#error
Element
- <cpp:error>
SubElement
- <cpp:value>
Example
// #error message example
#if !defined(__cplusplus)
#error "C++ compiler required."
#endif
<comment type="line">// #error message example</comment>
<cpp:if>#<cpp:directive>if</cpp:directive> <expr><op:operator>!</op:operator><call><name>defined</name><argument_list>(<argument><expr><name>__cplusplus</name></expr></argument>)</argument_list></call></expr></cpp:if>
<cpp:error>#<cpp:directive>error</cpp:directive> "C++ compiler required."</cpp:error>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>
XPath Query Example
Description:
Find all uses of #error
.
XPath
//cpp:error
#line
Element
- <cpp:line>
SubElements
- <cpp:directive>
- <cpp:number>
Example
// #line directive example
#line 151 "copy.c"
<comment type="line">// #line directive example</comment>
<cpp:line>#<cpp:directive>line</cpp:directive> <cpp:number><lit:literal type="number">151</lit:literal></cpp:number> <cpp:file><lit:literal type="string">"copy.c"</lit:literal></cpp:file></cpp:line>
XPath Query Example
Description:
Find all uses of #line
.
XPath
//cpp:line