-
Notifications
You must be signed in to change notification settings - Fork 1
/
srcMLXPathCount.cpp.xml
78 lines (66 loc) · 8.18 KB
/
srcMLXPathCount.cpp.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<unit xmlns="http://www.srcML.org/srcML/src" xmlns:cpp="http://www.srcML.org/srcML/cpp" revision="1.0.0" language="C++" filename="srcMLXPathCount.cpp"><comment type="block">/*
srcMLXPathCount.cpp
Implementation file for srcMLXPathCount()
*/</comment>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file>"srcMLXPathCount.hpp"</cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><memory></cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><string_view></cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><libxml/xpath.h></cpp:file></cpp:include>
<cpp:include>#<cpp:directive>include</cpp:directive> <cpp:file><libxml/xpathInternals.h></cpp:file></cpp:include>
<comment type="block" format="doxygen">/** Count of the result of applying the xpath to the srcML file
*
* XPath expression must result in a numeric, integer result.
* In general, this means it needs to use the XPath count() function
*
* @param srcMLfile filename of srcML file
* @param xpath XPath expression as string
* @retval Number of conditions in the srcMLfile
* @retval -1 Error in XPath
* @retval -2 Invalid argument
*/</comment>
<function><type><name>int</name></type> <name>srcMLXPathCount</name><parameter_list>(<parameter><decl><type><name><name>std</name><operator>::</operator><name>string_view</name></name></type> <name>srcMLfile</name></decl></parameter>, <parameter><decl><type><name><name>std</name><operator>::</operator><name>string_view</name></name></type> <name>xpath</name></decl></parameter>)</parameter_list> <block>{<block_content>
<expr_stmt><expr><call><name>xmlInitParser</name><argument_list>()</argument_list></call></expr>;</expr_stmt>
<comment type="line">// open the srcML file with no encoding change and no options</comment>
<decl_stmt><decl><type><name>xmlDoc</name><modifier>*</modifier></type> <name>srcMLdoc</name><argument_list>(<argument><expr><call><name>xmlReadFile</name><argument_list>(<argument><expr><call><name><name>srcMLfile</name><operator>.</operator><name>data</name></name><argument_list>()</argument_list></call></expr></argument>, <argument><expr><literal type="null">nullptr</literal></expr></argument>, <argument><expr><literal type="number">0</literal></expr></argument>)</argument_list></call></expr></argument>)</argument_list></decl>;</decl_stmt>
<if_stmt><if>if <condition>(<expr><operator>!</operator><name>srcMLdoc</name></expr>)</condition> <block>{<block_content>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<comment type="line">// create xpath evaluation context</comment>
<decl_stmt><decl><type><name>xmlXPathContext</name><modifier>*</modifier></type> <name>xpathCtx</name><argument_list>(<argument><expr><call><name>xmlXPathNewContext</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr></argument>)</argument_list></decl>;</decl_stmt>
<if_stmt><if>if <condition>(<expr><operator>!</operator><name>xpathCtx</name></expr>)</condition> <block>{<block_content>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<comment type="line">// register srcML namespaces</comment>
<if_stmt><if>if <condition>(<expr><call><name>xmlXPathRegisterNs</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>, <argument><expr><name>BAD_CAST</name> <literal type="string">"src"</literal></expr></argument>, <argument><expr><name>BAD_CAST</name> <literal type="string">"http://www.srcML.org/srcML/src"</literal></expr></argument>)</argument_list></call></expr>)</condition> <block>{<block_content>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeContext</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<if_stmt><if>if <condition>(<expr><call><name>xmlXPathRegisterNs</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>, <argument><expr><name>BAD_CAST</name> <literal type="string">"cpp"</literal></expr></argument>, <argument><expr><name>BAD_CAST</name> <literal type="string">"http://www.srcML.org/srcML/cpp"</literal></expr></argument>)</argument_list></call></expr>)</condition> <block>{<block_content>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeContext</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<comment type="line">// evaluate xpath expression</comment>
<decl_stmt><decl><type><name>xmlXPathObject</name><modifier>*</modifier></type> <name>xpathResults</name><argument_list>(<argument><expr><macro><name>xmlXPathEvalExpression</name><argument_list>(<argument>BAD_CAST xpath.data()</argument>, <argument>xpathCtx</argument>)</argument_list></macro></expr></argument>)</argument_list></decl>;</decl_stmt>
<if_stmt><if>if <condition>(<expr><operator>!</operator><name>xpathResults</name></expr>)</condition> <block>{<block_content>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeContext</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<comment type="line">// extract the count</comment>
<decl_stmt><decl><type><name>int</name></type> <name>count</name> <init>= <expr><call><name>xmlXPathCastToNumber</name><argument_list>(<argument><expr><name>xpathResults</name></expr></argument>)</argument_list></call></expr></init></decl>;</decl_stmt>
<if_stmt><if>if <condition>(<expr><name>count</name> <operator><</operator> <literal type="number">0</literal></expr>)</condition> <block>{<block_content>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeContext</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeObject</name><argument_list>(<argument><expr><name>xpathResults</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><operator>-</operator><literal type="number">1</literal></expr>;</return>
</block_content>}</block></if></if_stmt>
<expr_stmt><expr><call><name>xmlFreeDoc</name><argument_list>(<argument><expr><name>srcMLdoc</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeContext</name><argument_list>(<argument><expr><name>xpathCtx</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<expr_stmt><expr><call><name>xmlXPathFreeObject</name><argument_list>(<argument><expr><name>xpathResults</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
<return>return <expr><name>count</name></expr>;</return>
</block_content>}</block></function>
</unit>