comparison gpf/util/sape/xslt/func-com.xsl @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:output method="text"/>
4 <!--named template to transform the Control element syntax into a similar C-like expression for pointers.-->
5 <xsl:template name="getPointers">
6 <xsl:param name="ctrlStr"/>
7 <xsl:if test='contains($ctrlStr, "PTR")'>
8 <xsl:text>*</xsl:text>
9 <xsl:call-template name="getPointers">
10 <xsl:with-param name="ctrlStr" select='substring-after($ctrlStr,"PTR")'/>
11 </xsl:call-template>
12 </xsl:if>
13 </xsl:template>
14
15 <!--named template to transform the Control element syntax into a similar C-like expression for arrays.-->
16 <xsl:template name="getArrays">
17 <xsl:param name="ctrlStr"/>
18 <xsl:if test='contains($ctrlStr, "[")'>
19 <xsl:text>[</xsl:text>
20 <xsl:value-of select='substring-after(substring-before($ctrlStr,"]"),"[")'/>
21 <xsl:text>]</xsl:text>
22 <xsl:call-template name="getArrays">
23 <xsl:with-param name="ctrlStr" select='substring-after($ctrlStr,"]")'/>
24 </xsl:call-template>
25 </xsl:if>
26 </xsl:template>
27
28 <!-- Named template to write a function prototype declaration as a function pointer. -->
29 <xsl:template name="writeFunctionAsPointer">
30 <xsl:call-template name="writeFuncRetDataType"/>
31 <xsl:text>( *</xsl:text>
32 <xsl:call-template name="writeFuncName"/>
33 <xsl:text> )( </xsl:text>
34 <xsl:call-template name="writeFuncArgList"/>
35 <xsl:text> )</xsl:text>
36 </xsl:template>
37
38 <!-- Named template to write out a regular function prototype declaration. -->
39 <xsl:template name="writeFunctionDeclaration">
40 <xsl:call-template name="writeFuncRetDataType"/>
41 <xsl:call-template name="writeFuncName"/>
42 <xsl:text> ( </xsl:text>
43 <xsl:call-template name="writeFuncArgList"/>
44 <xsl:text> );</xsl:text>
45 </xsl:template>
46
47 <!-- Named template to write out the name of a function prototype declaration. -->
48 <xsl:template name="writeFuncName">
49 <xsl:choose>
50 <xsl:when test="./FuncDef/Alias">
51 <xsl:value-of select="./FuncDef/Alias"/>
52 </xsl:when>
53 <xsl:otherwise>
54 <xsl:if test='/SAP/PragmasSection/Pragma[Name="PREFIX"]'>
55 <xsl:for-each select='/SAP/PragmasSection/Pragma[Name="PREFIX"]'>
56 <xsl:variable name="prefixName">
57 <xsl:call-template name="toLower">
58 <xsl:with-param name="str" select="./Value"/>
59 </xsl:call-template>
60 </xsl:variable>
61 <xsl:if test="$prefixName != 'none'">
62 <xsl:value-of select="$prefixName"/>
63 <xsl:text>_</xsl:text>
64 </xsl:if>
65 </xsl:for-each>
66 </xsl:if>
67 <xsl:value-of select="./FuncDef/Name"/>
68 </xsl:otherwise>
69 </xsl:choose>
70 </xsl:template>
71
72 <!-- Named template to write out the data type of the return value of a function prototype declaration. -->
73 <xsl:template name="writeFuncRetDataType">
74 <xsl:choose>
75 <xsl:when test="./FuncRet">
76 <xsl:choose>
77 <xsl:when test="./FuncRet/ExtType">
78 <xsl:value-of select="./FuncRet/ExtType/Type"/>
79 </xsl:when>
80 <xsl:otherwise>
81 <xsl:for-each select="./FuncRet[1]/ItemLink[1]">
82 <xsl:call-template name="writeItemLinkFuncType"/>
83 </xsl:for-each>
84 </xsl:otherwise>
85 </xsl:choose>
86 <xsl:value-of select="$space"/>
87 <xsl:call-template name="getPointers">
88 <xsl:with-param name="ctrlStr" select="./FuncRet/Control"/>
89 </xsl:call-template>
90 </xsl:when>
91 <xsl:otherwise>
92 <xsl:text>void</xsl:text>
93 <xsl:value-of select="$space"/>
94 </xsl:otherwise>
95 </xsl:choose>
96 </xsl:template>
97
98 <!-- Named template to write out the comma separated list of the arguments of a function prototype declaration. -->
99 <xsl:template name="writeFuncArgList">
100 <xsl:choose>
101 <xsl:when test="count( ./FuncArg ) &gt; 0 ">
102 <xsl:variable name="docName" select="/SAP/DocInfoSection/DocName"/>
103 <xsl:for-each select="./FuncArg">
104 <xsl:if test="position() &gt; 1">
105 <xsl:text>, </xsl:text>
106 </xsl:if>
107 <xsl:variable name="linkName" select="./ItemLink/Name"/>
108 <!-- Check if this element is a function pointer. -->
109 <!-- 0: no, 1: local, 2: extern -->
110 <xsl:variable name="isFuncPtr" >
111 <xsl:choose>
112 <xsl:when test="not(./ExtType)">
113 <xsl:choose>
114 <xsl:when test='./ItemLink/DocName = $docName and ./ItemLink/DocName[@DocType = "SAP"]'>
115 <xsl:variable name="numDefs" select="count(/*/FunctionsSection/Function/FuncDef[Name=$linkName])"/>
116 <xsl:choose>
117 <xsl:when test="$numDefs&lt;=0">
118 <xsl:value-of select="number(0)"/>
119 </xsl:when>
120 <xsl:when test="$numDefs&gt;=1">
121 <xsl:value-of select="number(1)"/>
122 </xsl:when>
123 <xsl:when test="$numDefs&gt;1">
124 <xsl:message terminate="no">
125 <xsl:call-template name="cmdLineMsg">
126 <xsl:with-param name="msgType" select="error"/>
127 <xsl:with-param name="msg">
128 <xsl:text>More than one function prototype with name: </xsl:text>
129 <xsl:value-of select="$linkName"/>
130 <xsl:text> exists in referenced document.</xsl:text>
131 </xsl:with-param>
132 </xsl:call-template>
133 </xsl:message>
134 </xsl:when>
135 </xsl:choose>
136 </xsl:when>
137 <xsl:otherwise>
138 <xsl:variable name="filename">
139 <xsl:call-template name="getDocumentName">
140 <xsl:with-param name="docName" select="./ItemLink/DocName"/>
141 <xsl:with-param name="docType" select="./ItemLink/DocName/@DocType"/>
142 </xsl:call-template>
143 </xsl:variable>
144 <xsl:variable name="numDefs" select="count(document($filename)/*/FunctionsSection/Function/FuncDef[Name=$linkName])"/>
145 <xsl:choose>
146 <xsl:when test="$numDefs&lt;=0">
147 <xsl:value-of select="number(0)"/>
148 </xsl:when>
149 <xsl:when test="$numDefs&gt;=1">
150 <xsl:value-of select="number(2)"/>
151 </xsl:when>
152 <xsl:when test="$numDefs&gt;1">
153 <xsl:message terminate="no">
154 <xsl:call-template name="cmdLineMsg">
155 <xsl:with-param name="msgType" select="error"/>
156 <xsl:with-param name="msg">
157 <xsl:text>More than one function prototype with name: </xsl:text>
158 <xsl:value-of select="$linkName"/>
159 <xsl:text> exists in referenced document.</xsl:text>
160 </xsl:with-param>
161 </xsl:call-template>
162 </xsl:message>
163 </xsl:when>
164 </xsl:choose>
165 </xsl:otherwise>
166 </xsl:choose>
167 </xsl:when>
168 <xsl:otherwise>
169 <xsl:value-of select="number(0)"/>
170 </xsl:otherwise>
171 </xsl:choose>
172 </xsl:variable>
173 <xsl:choose>
174 <xsl:when test="number($isFuncPtr)=number(1)">
175 <!-- Local function pointer. -->
176 <xsl:for-each select="/*/FunctionsSection/Function[FuncDef/Name=$linkName][1]">
177 <xsl:call-template name="writeFunctionAsPointer"/>
178 </xsl:for-each>
179 </xsl:when>
180 <xsl:when test="number($isFuncPtr)=number(2)">
181 <!-- Extern function pointer. -->
182 <xsl:variable name="filename">
183 <xsl:call-template name="getDocumentName">
184 <xsl:with-param name="docName" select="./ItemLink/DocName"/>
185 <xsl:with-param name="docType" select="./ItemLink/DocName/@DocType"/>
186 </xsl:call-template>
187 </xsl:variable>
188 <xsl:for-each select="document($filename)/*/FunctionsSection/Function[FuncDef/Name=$linkName][1]">
189 <xsl:call-template name="writeFunctionAsPointer"/>
190 </xsl:for-each>
191 </xsl:when>
192 <xsl:otherwise>
193 <!-- Basic or struct element. -->
194 <xsl:choose>
195 <xsl:when test="./ExtType">
196 <xsl:value-of select="./ExtType/Type"/>
197 </xsl:when>
198 <xsl:otherwise>
199 <xsl:for-each select="./ItemLink[1]">
200 <xsl:call-template name="writeItemLinkFuncType"/>
201 </xsl:for-each>
202 </xsl:otherwise>
203 </xsl:choose>
204 <xsl:value-of select="$space"/>
205 <xsl:call-template name="getPointers">
206 <xsl:with-param name="ctrlStr" select="./Control"/>
207 </xsl:call-template>
208 <xsl:choose>
209 <xsl:when test="./Alias">
210 <xsl:value-of select="./Alias"/>
211 </xsl:when>
212 <xsl:otherwise>
213 <xsl:value-of select="./ItemLink/Name"/>
214 </xsl:otherwise>
215 </xsl:choose>
216 <xsl:call-template name="getArrays">
217 <xsl:with-param name="ctrlStr" select="./Control"/>
218 </xsl:call-template>
219 </xsl:otherwise>
220 </xsl:choose>
221 </xsl:for-each>
222 </xsl:when>
223 <xsl:otherwise>
224 <xsl:text>void</xsl:text>
225 </xsl:otherwise>
226 </xsl:choose>
227 </xsl:template>
228
229 <!-- Named template that writes out the data type of a function sub structure from an item link. -->
230 <xsl:template name="writeItemLinkFuncType">
231 <xsl:variable name="docName" select="/SAP/DocInfoSection/DocName"/>
232 <xsl:choose>
233 <xsl:when test='./DocName = $docName and ./DocName[@DocType = "SAP"]'>
234 <xsl:apply-templates select="/SAP" mode="getTypeForName">
235 <xsl:with-param name="elemName" select="./Name"/>
236 <xsl:with-param name="transformType" select="'compAndEnumOnly'"/>
237 </xsl:apply-templates>
238 </xsl:when>
239 <xsl:otherwise>
240 <xsl:call-template name="getExternType">
241 <xsl:with-param name="elemName" select="./Name"/>
242 <xsl:with-param name="docType" select="./DocName/@DocType"/>
243 <xsl:with-param name="docName" select="./DocName"/>
244 <xsl:with-param name="transformType" select="'compAndEnumOnly'"/>
245 </xsl:call-template>
246 </xsl:otherwise>
247 </xsl:choose>
248 </xsl:template>
249
250 </xsl:stylesheet>