File: xml2cppbase.xsl

package info (click to toggle)
actiona 3.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 54,580 kB
  • sloc: cpp: 969,398; xml: 52,881; javascript: 32,914; python: 23,909; sh: 550; ansic: 90; makefile: 9
file content (1201 lines) | stat: -rw-r--r-- 34,965 bytes parent folder | download
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
    xmlns:qsrc="http://qcad.org/namespaces/src" 
    xmlns:qc="http://qcad.org/namespaces/xsl"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:func="http://exslt.org/functions"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:str="http://exslt.org/strings"
    xmlns:com="http://exslt.org/common"
    extension-element-prefixes="func date str">

<xsl:include href="shared.xsl"/>

<xsl:output method="text" />

<xsl:param name="mode" />
<xsl:param name="module" />

<!--
<xsl:param name="qobject">
  <xsl:value-of select="boolean(/qsrc:unit/qsrc:class/qsrc:super_list/qsrc:super[@name='QObject'])" />
  < ! - -
  <xsl:value-of select="boolean(/qsrc:unit/qsrc:class/qsrc:super_list/qsrc:super[@name='QObject' or @name='QWidget'])" />
  - - >
</xsl:param>
-->


<!--
<xsl:param name="class-name">
  <xsl:value-of select="qsrc:unit/qsrc:class/@name" />
</xsl:param>
-->


<xsl:template match="text()" />


<xsl:template match="/">
  <!--
  <xsl:variable name="class-name">
    <xsl:value-of select="qsrc:unit/qsrc:class/@name"/>
  </xsl:variable>
  -->

  // Auto generated
  // Adds public versions for event handlers to be called from 
  // JS implementation of these event handlers.
  <!--
  <xsl:choose>
    <xsl:when test="$qobject='true'">
      // Class inherited from QObject
    </xsl:when>
    <xsl:otherwise>
      // Class not inherited from QObject
    </xsl:otherwise>
  </xsl:choose>
  -->

  <xsl:if test="$mode='h'">
  #ifndef <xsl:value-of select="qc:include_guard(qsrc:unit/@filename)" />
  #define <xsl:value-of select="qc:include_guard(qsrc:unit/@filename)" />

  // include header:
  //#include "header_h.h"
    <xsl:choose>
      <xsl:when test="$module!=''">
        #include "RJSHelper.h"
        #include "../RJSHelper_<xsl:value-of select="$module"/>.h"
      </xsl:when>
      <xsl:otherwise>
        #include "../RJSHelper.h"
      </xsl:otherwise>
    </xsl:choose>

  </xsl:if>

  <xsl:if test="$mode='cpp'">
  // include header:
  #include "<xsl:value-of select="qc:lowercase(qc:replace(qsrc:unit/@filename, '.h', '_base.h'))" />"
  //#include "<xsl:value-of select="qc:replace(qsrc:unit/@filename, '.h', '_wrapper.h')" />"
  //#include "header_cpp.h"
    <!--
    <xsl:if test="$qobject='true'">
      #include "<xsl:value-of select="qc:replace(qsrc:unit/@filename, '.h', '_base.h')" />"
    </xsl:if>
    -->
  </xsl:if>


  <xsl:apply-templates />


  <xsl:if test="$mode='h'">
  #endif
  </xsl:if>
</xsl:template>


<xsl:template match="qsrc:unit">
  <xsl:apply-templates select="qsrc:class_decl" />
  <xsl:apply-templates select="qsrc:class" />
</xsl:template>


<xsl:template match="qsrc:class_decl">
  <xsl:if test="$mode='h' and not(starts-with(@name, 'R'))">
    #include &lt;<xsl:value-of select="@name" />&gt;
  </xsl:if>
</xsl:template>


<xsl:template match="qsrc:class">
  <!--
  <xsl:variable name="base">
    <xsl:choose>
      <xsl:when test="$qobject='true'">
        <xsl:text>RJSWrapper</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>RJSWrapperObj</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  -->

  <xsl:if test="$mode='h'">
    #include &lt;QQmlEngine&gt;

    <xsl:choose>
      <xsl:when test="starts-with(@name, 'R')">
        #include "<xsl:value-of select="@name" />.h"
      </xsl:when>
      <xsl:otherwise>
        #include &lt;<xsl:value-of select="@name" />&gt;
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>

  <xsl:variable name="class-name">
    <xsl:value-of select="@name"/>
  </xsl:variable>

  <xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or @inheritable='true'">
    // Base class for <xsl:value-of select="@name" />

    <xsl:if test="$mode='h'">
      <!--
      QObject base class needs to be fist in list:
      -->
      <!--
      <xsl:choose>
        <xsl:when test="$qobject='true'">
          // QObject based class:
          // inherit from class directly:
          class <xsl:value-of select="@name" />_Wrapper : public <xsl:value-of select="@name" />, public <xsl:value-of select="$base" /> {
        </xsl:when>
        <xsl:otherwise>
          // Wrapped class is not derrived from QObject, 
          // add QObject to wrapper and encapsulate object as member variable:
          class <xsl:value-of select="@name" />_Wrapper : public <xsl:value-of select="$base" /> {
        </xsl:otherwise>
      </xsl:choose>
      -->
      class <xsl:value-of select="@name" />_Base : public <xsl:value-of select="@name" /> {

      <!--
      <xsl:if test="$base='RJSWrapper'">
      -->
        //Q_OBJECT
      <!--
      </xsl:if>
      -->

      public:
    </xsl:if>

    <!--
    <xsl:choose>

      <xsl:when test="$qobject='false'">
        // constructors:
        <xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />

        // non-static functions:
        <xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" />
        < ! - - 20210702
        <xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" mode="public" />
        - - >
      </xsl:when>

      <xsl:otherwise>
        // constructors:
        <xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />

        // public non-static functions:
        < ! - -
        <xsl:apply-templates select="qsrc:function/qsrc:variant[@access='public' and not(../@static)] | qsrc:preproc" />
        - - >
        <xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" mode="public" />
      </xsl:otherwise>

    </xsl:choose>
    -->

    // constructors:
    <xsl:choose>
      <xsl:when test="qsrc:constructor/qsrc:variant">
        <xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />
      </xsl:when>
      <xsl:when test="qsrc:constructor">
        <xsl:if test="$mode='h'">
          // default constructor (there are constructors but not scriptable ones):
          <xsl:value-of select="@name" />_Base(RJSApi&amp; h) : handler(h) { }
        </xsl:if>
      </xsl:when>
        // no constructor
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>


    <xsl:if test="$mode='h'">
    // destructor:
    virtual ~<xsl:value-of select="@name" />_Base() { }

    public:
      // set handler:
      //void setHandler(RJSApi* h) {
      //  handler = h;
      //}
    </xsl:if>

    <!-- 
      no constructor means class is pure virtual, cannot be instantiated and does not offer any functions 
      note: the class might be a base class for other classes which do implement wrappers for these functions
    --> 
    <xsl:if test="qsrc:constructor">
      // protected overwritten functions / events and their public invokable counterparts:
      <xsl:apply-templates select="qsrc:function/qsrc:variant[@access='protected']" mode="protected" />
      <!--
      <xsl:apply-templates select="qsrc:function/qsrc:variant[@access='protected' or @access='public']" mode="protected" />
      -->

      // public virtual overwritten functions / events:
      <xsl:apply-templates select="qsrc:function/qsrc:variant[@access='public' and @virtual='true' and @overridable='true']" mode="virtual" />

      // public pure-virtual functions:
      <xsl:apply-templates select="qsrc:function/qsrc:variant[@access='public' and @pure-virtual='true']" mode="pure-virtual" />
    </xsl:if>

    <xsl:if test="$mode='h'">

    public:
      //void setRecFlag(bool on) {
      //  recFlag = on;
      //}

    public:
      QJSValue self;

    private:
      <xsl:if test="qsrc:constructor">
        RJSApi&amp; handler;
      </xsl:if>
      //bool recFlag;

    };
    </xsl:if>
  </xsl:if>

</xsl:template>


<xsl:template match="qsrc:preproc">
  <xsl:text>&#xa;</xsl:text>
  <xsl:value-of select="@plain" />
  <xsl:text>&#xa;</xsl:text>
</xsl:template>


<xsl:template match="qsrc:constructor">
  <!--
  <xsl:variable name="class" >
    <xsl:copy-of select="ancestor::qsrc:class[1]" />
    <!- -
    <xsl:value-of select="ancestor::qsrc:class/@name" />
    - ->
  </xsl:variable>

  <xsl:variable name="sorted_variants">
  <!- -
    <xsl:for-each select="com:node-set($class)/qsrc:constructor/qsrc:variant">
  - ->
    <xsl:for-each select="qsrc:variant">
      <xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending"/>
      <xsl:copy-of select="." />
    </xsl:for-each>
  </xsl:variable>

  <!- -
  <xsl:message>Function name: <xsl:copy-of select="com:node-set($sorted_variants)" /></xsl:message>
  - ->

  <xsl:for-each select="com:node-set($sorted_variants)">
    // applying variant with <xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" /> parameters for constructor
    <xsl:apply-templates select="qsrc:variant">
      <xsl:with-param name="class" select="com:node-set($class)" />
      <xsl:with-param name="function" select="ancestor::qsrc:function[1]" />
    </xsl:apply-templates>
  </xsl:for-each>
  -->

  <xsl:apply-templates select="qsrc:variant">
    <xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending" />
    <xsl:with-param name="constructor" select="true" />
  </xsl:apply-templates>
</xsl:template>



  <!--
  <xsl:variable name="base">
    <xsl:choose>
      <xsl:when test="ancestor::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
        <xsl:text>RJSWrapper</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>RJSWrapperObj</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:if test="$mode='h'">
    <xsl:choose>
      <xsl:when test="$base='RJSWrapperObj'">
        // constructor
        Q_INVOKABLE <xsl:value-of select="../@name" />_Wrapper(
          <!- - constructor parameters - ->
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
        ) {
          wrapped = new <xsl:value-of select="../@name" />(
            <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
          );
        }
      </xsl:when>
      <xsl:otherwise>
        // constructor
        Q_INVOKABLE <xsl:value-of select="../@name" />_Wrapper(
          <!- - constructor parameters - ->
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
        ) : <xsl:value-of select="../@name" />(
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
        ) {
        }
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>

</xsl:template>
-->


<xsl:template match="qsrc:function" mode="public">
  // function <xsl:value-of select="@name" />
  <!--
    apply variant template in order of parameter count (most parameters first).
    we only apply the template with the most paramters
  -->
  <xsl:apply-templates select="qsrc:variant[@access='public']">
    <xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending" />
  </xsl:apply-templates>
</xsl:template>


<!--
<xsl:template match="qsrc:variant">
-->
<xsl:template match="qsrc:variant">
  <xsl:variable name="class-name">
    <xsl:value-of select="ancestor::qsrc:class[1]/@name" />
  </xsl:variable>

  <xsl:variable name="wrapper-class-name">
    <xsl:value-of select="concat($class-name, '_Base')" />
  </xsl:variable>

  <xsl:variable name="num-param">
    <xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" />
  </xsl:variable>

  <xsl:variable name="num-prev-param">
    <xsl:choose>
    <xsl:when test="preceding-sibling::*">
      <xsl:value-of select="count(preceding-sibling::*[1]/qsrc:parameters/qsrc:parameter)" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="-1" />
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!--
  <xsl:param name="function" />
  -->

    <!--
    Class: <xsl:value-of select="com:node-set($class)/@name" />
    Function: <xsl:value-of select="com:node-set($function)/@name" />
    Class: <xsl:value-of select="ancestor::qsrc:class[1]/@name" />
    Function: <xsl:value-of select="../@name" />
    // Class: <xsl:value-of select="com:node-set($class)/@name" />
    // Function: <xsl:value-of select="$function" />
    -->
  // Class: <xsl:value-of select="$class-name" />
  // Function: <xsl:value-of select="../@name" />
  // Parameters: <xsl:value-of select="$num-param"/>
  // preceding Parameters: <xsl:value-of select="$num-prev-param"/>
  <xsl:text>&#10;</xsl:text>

  <!--
    only one function / constructor per parameter count:
  -->
  <xsl:if test="$num-param != $num-prev-param">
  <!--
  <xsl:if test="position()=1">
  -->
    <!--
    <xsl:variable name="specifier">
      <xsl:choose>
        <xsl:when test="@virtual='true' and $mode='h'">
          <xsl:value-of select="'virtual '" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="''" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    -->

    <!--
    <xsl:variable name="wrapped-return-type">
      <xsl:value-of select="qc:get-wrapper-return-type(@return-type)" />
    </xsl:variable>
    -->


    <!--
    <xsl:if test="$mode='h'">
      <xsl:choose>
        <xsl:when test="@signal='true'">
          Q_SIGNALS:
        </xsl:when>
        <xsl:otherwise>
          public:
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    -->

    <xsl:if test="$mode='h'">
      <xsl:if test="ancestor::qsrc:function">
        Q_INVOKABLE
      </xsl:if>
      <!--
      <xsl:if test="$mode='h' and @static='true'">
        static
      </xsl:if>
      -->
      <!--
      <xsl:value-of select="concat($specifier, $wrapped-return-type, ' ', @name)" />(
      -->
      <xsl:choose>
        <xsl:when test="ancestor::qsrc:function">
          <!-- function -->
          //QJSValue 
          <!--
          <xsl:value-of select="ancestor::qsrc:function/@name" />
          -->
        </xsl:when>
        <xsl:otherwise>
          <!-- constructor -->
          <xsl:value-of select="$class-name" />_Base
        </xsl:otherwise>
      </xsl:choose>
      (

        <!--
        <xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" />
        -->
        <xsl:if test="ancestor::qsrc:constructor">
          RJSApi&amp; _h
          <xsl:if test="qsrc:parameters/qsrc:parameter">
            ,
          </xsl:if>
        </xsl:if>

        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
      )
      <xsl:if test="@const='true'">
        const
      </xsl:if>
      <xsl:if test="ancestor::qsrc:constructor">
        : <xsl:value-of select="$class-name" />(
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
        ) 
        <xsl:if test="ancestor::qsrc:constructor">
          , handler(_h) /*, recFlag(false)*/
        </xsl:if>
        {}
      </xsl:if>
    </xsl:if>
  </xsl:if>
</xsl:template>


<!--
<xsl:template match="qsrc:function" mode="protected">
  <xsl:apply-templates select="qsrc:variant" mode="protected" />
</xsl:template>
-->


<!--
  Implementation of protected functions that call into JS and ...Public 
  functions that can be called from JS.
-->
<xsl:template match="qsrc:function/qsrc:variant" mode="protected">
  <xsl:variable name="specifier">
    <xsl:choose>
      <xsl:when test="@virtual='true' and $mode='h'">
        <xsl:value-of select="'virtual '" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="''" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:if test="$mode='h'">
    protected:
    // implementation of protected function
    // calls JS implementation if available
    <xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    );
  </xsl:if>

  <xsl:if test="$mode='h'">
    public:
    // this can be called from JS to call the parent implementation (e.g. Parent.prototype.call(this, ...)):
    // TODO: convert arguments to QJSValue:
    Q_INVOKABLE <xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />Public(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    ) {
      //qDebug() &lt;&lt; "<xsl:value-of select="ancestor::qsrc:class/@name" />_Base::<xsl:value-of select="../@name" />Public()";
      <xsl:if test="@return-type!='void'">
        // TODO: convert return value to QJSValue:
        return
      </xsl:if>
      <xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />(
        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
      );
    }
  </xsl:if>

  <xsl:if test="$mode='cpp'">
    <xsl:value-of select="concat($specifier, @return-type, ' ', ancestor::qsrc:class/@name, '_Base::' ,../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    ) {

      //qDebug() &lt;&lt; "<xsl:value-of select="ancestor::qsrc:class/@name" />_Base::<xsl:value-of select="../@name" />()";

      //QJSValue f = self.prototype().property("<xsl:value-of select="../@name" />");
      QJSValue f = self.property("<xsl:value-of select="../@name" />");
      if (f.isCallable() /*&amp;&amp; !recFlag*/) {
        <!--
        QJSValueList args;
        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="toqjsvaluelist" />
        QJSValue err = f.callWithInstance(self, args);
        if (err.isError()) {
          qWarning() &lt;&lt; "Error while calling <xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />:" &lt;&lt; err.toString();
          handler.trace();
        }
        -->


        QJSEngine* engine = handler.getEngine();

        QJSValueList args;
        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="toqjsvaluelist" />

        QJSValue argsValue = engine->newArray(args.length());
        for (int i=0; i&lt;args.length(); i++) {
          argsValue.setProperty(i, args[i]);
        }

        engine->globalObject().setProperty("__self__", self);
        engine->globalObject().setProperty("__args__", argsValue);
        QStringList trace;
        QJSValue res = engine->evaluate("__self__.<xsl:value-of select="../@name" />.apply(__self__, __args__);", "", 1, &amp;trace);

        if (res.isError()) {
          qWarning() &lt;&lt; "exception: " &lt;&lt; res.toString();
          for (int i=0; i&lt;trace.length(); i++) {
            qWarning() &lt;&lt; trace[i];
          }
        }


        <xsl:choose>
          <xsl:when test="@return-type='void'">
            return;
          </xsl:when>
          <xsl:otherwise>
            // convert return value js2cpp and return:
            return <xsl:value-of select="qc:type-to-function-js2cpp(@return-type, '')" />(handler, res);
          </xsl:otherwise>
        </xsl:choose>
      }
      else {
        <xsl:if test="@return-type!='void'">
          return
        </xsl:if>
        <xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />(
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
        );
      }
    }

  </xsl:if>
</xsl:template>



<!--
<xsl:template match="qsrc:function" mode="virtual">
  <xsl:apply-templates select="qsrc:variant" mode="virtual" />
</xsl:template>
-->



<!--
  Overridable functions:
-->
<xsl:template match="qsrc:function/qsrc:variant" mode="virtual">
  <xsl:variable name="specifier">
    <xsl:choose>
      <xsl:when test="@virtual='true' and $mode='h'">
        <xsl:value-of select="'virtual '" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="''" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:if test="$mode='h'">
    public:
    // implementation of virtual public function
    // calls JS implementation if available
    <xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    )
    <xsl:if test="@const='true'">
      const
    </xsl:if>
    ;

    <xsl:if test="not(@pure='true')">
      // implementation of virtual public function
      // always calls super implementation
      <xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />Sup(
        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
      )
      <xsl:if test="@const='true'">
        const
      </xsl:if>
      {
        <xsl:if test="@return-type!='void'">
          return
        </xsl:if>
        <xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />(
          <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
        );
      }
    </xsl:if>
  </xsl:if>

  <xsl:if test="$mode='cpp'">
    <xsl:value-of select="concat($specifier, @return-type, ' ', ancestor::qsrc:class/@name, '_Base::' ,../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    ) 
    <xsl:if test="@const='true'">
      const
    </xsl:if>
    {

      //qDebug() &lt;&lt; "<xsl:value-of select="ancestor::qsrc:class/@name" />_Base::<xsl:value-of select="../@name" />()";

      // make sure we don't call same function (recursion):
      // only call JS function implementation

      QJSEngine* engine = handler.getEngine();

      //QJSValue f = self.prototype().property("<xsl:value-of select="../@name" />");
      QJSValue f = self.property("<xsl:value-of select="../@name" />");
      if (f.isCallable() /*&amp;&amp; !recFlag*/) {
        QJSValueList args;
        <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="toqjsvaluelist" />

        QJSValue argsValue = engine->newArray(args.length());
        for (int i=0; i&lt;args.length(); i++) {
          argsValue.setProperty(i, args[i]);
        }

        engine->globalObject().setProperty("__self__", self);
        engine->globalObject().setProperty("__args__", argsValue);
        //engine->evaluate("__self__.<xsl:value-of select="../@name" />();");
        QStringList trace;
        QJSValue res = engine->evaluate("__self__.<xsl:value-of select="../@name" />.apply(__self__, __args__);", "", 1, &amp;trace);

        if (res.isError()) {
          qWarning() &lt;&lt; "exception: " &lt;&lt; res.toString();
          for (int i=0; i&lt;trace.length(); i++) {
            qWarning() &lt;&lt; trace[i];
          }
        }

        // does not provide back trace in case of error:
        //QJSValue res = f.callWithInstance(self, args);
        //if (res.isError()) {
        //  qWarning() &lt;&lt; "Error while calling <xsl:value-of select="../@name" />:" &lt;&lt; res.toString();
        //  engine->throwError("exception in: <xsl:value-of select="concat(ancestor::qsrc:class/@name, '::' , ../@name)" />:" + res.toString());
        //}

        <xsl:variable name="mod">
          <xsl:if test="qc:ends-with(@return-type, '*')">
            <xsl:value-of select="'*'" />
          </xsl:if>
        </xsl:variable>

        <xsl:choose>
          <xsl:when test="@return-type='void'">
            // void:
            return;
          </xsl:when>
          <xsl:when test="qc:ends-with(@return-type, '&amp;')">
            return *<xsl:value-of select="qc:type-to-function-js2cpp(@return-type, $mod)" />(handler, res);
          </xsl:when>
          <xsl:otherwise>
            return <xsl:value-of select="qc:type-to-function-js2cpp(@return-type, $mod)" />(handler, res);
          </xsl:otherwise>
        </xsl:choose>
      }

      //if (!recFlag) {
        // function not implemented in JS: exception
        engine->throwError(QString("function not implemented in JS class: <xsl:value-of select="concat(ancestor::qsrc:class/@name, '::' , ../@name)" />"));
      //}

      <xsl:choose>
        <xsl:when test="@pure='true'">
          // pure virtual function:
          // return default value:
          <xsl:choose>
            <xsl:when test="@return-type='void'">
              // void
              return;
            </xsl:when>
            <xsl:when test="@return-type='int'">
              // int
              return 0;
            </xsl:when>
            <xsl:when test="@return-type='double'">
              // double
              return RNANDOUBLE;
            </xsl:when>
            <xsl:when test="@return-type='QSize'">
              // QSize
              return QSize();
            </xsl:when>
            <xsl:when test="qc:ends-with(@return-type, '*')">
              // pointer:
              return nullptr;
            </xsl:when>
            <xsl:otherwise>
              MUST_FIX;
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>

        <xsl:otherwise>
          // call implementation of original class:
          return <xsl:value-of select="concat(ancestor::qsrc:class/@name, '::' ,../@name)" />(
            <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
          );
        </xsl:otherwise>
      </xsl:choose>


      <!--
      -->
    }

  </xsl:if>
</xsl:template>




<xsl:template match="qsrc:function/qsrc:variant" mode="pure-virtual">
  // TODO: fix (<xsl:value-of select="../@name" />)
  <!--
  <xsl:if test="$mode='h'">
    public:
    // implementation of pure-virtual function
    <xsl:value-of select="concat('virtual ', @return-type, ' ', ../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    )
    <xsl:if test="@const='true'">
      const
    </xsl:if>
    ;
  </xsl:if>

  <xsl:if test="$mode='cpp'">
    <xsl:value-of select="concat(@return-type, ' ', ancestor::qsrc:class/@name, '_Base::' ,../@name)" />(
      <xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
    ) 
    <xsl:if test="@const='true'">
      const
    </xsl:if>
    {

      // TODO: call into JS class (self):

      <xsl:choose>
        <xsl:when test="@return-type='void'">
          // void
        </xsl:when>
        <xsl:when test="@return-type='int'">
          // int
          return 0;
        </xsl:when>
        <xsl:when test="@return-type='double'">
          // double
          return RNANDOUBLE;
        </xsl:when>
        <xsl:otherwise>
          MUST_FIX;
        </xsl:otherwise>
      </xsl:choose>
    }

  </xsl:if>
  -->
</xsl:template>



<!--
  Parameter as list of values with original C++ types.
-->
<xsl:template match="qsrc:parameter">

  <!-- e.g. const QWidget* -->
  <xsl:if test="@const='true'">
    <xsl:value-of select="'const'" />
    <xsl:value-of select="' '" />
  </xsl:if>
  <xsl:value-of select="@type" />
  <xsl:value-of select="@modifier" />
  <xsl:value-of select="' '" />

  <!-- e.g. parent = nullptr -->
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />

      <!-- default value for argument (header only) -->
      <xsl:if test="$mode='h'">
        <xsl:if test="@default!=''">
          <xsl:value-of select="'='" />
          <xsl:value-of select="@default" />
        </xsl:if>
      </xsl:if>

    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>


<xsl:template match="qsrc:parameter" mode="toqjsvaluelist">
  <xsl:variable name="name">
    <xsl:choose>
      <xsl:when test="@name!=''">
        <xsl:value-of select="@name" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat('a', position())" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <!--
  args &lt;&lt; RJSHelper::cpp2js_<xsl:value-of select="@type" />(engine, <xsl:value-of select="$name" />);
  -->

  args &lt;&lt; <xsl:value-of select="qc:type-to-function-cpp2js(@type)" />(
    handler, 
    // non-copyable: <xsl:value-of select="qc:is-non-copyable(@type)='true'" />
    <xsl:text>&#xa;</xsl:text>
    <xsl:choose>
      <xsl:when test="qc:ends-with(@type, '*') and qc:is-non-copyable(@type)='false'">
        <!--
          return type is pointer, type is copyable:
          dereference pointer:
        -->
        *<xsl:value-of select="$name" />
      </xsl:when>
      <xsl:when test="@modifier='&amp;' and qc:is-non-copyable(@type)='true'">
        <!-- 
          return type is reference, type is not copyable:
          convert using pointer:
        -->
        &amp;<xsl:value-of select="$name" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$name" />
      </xsl:otherwise>
    </xsl:choose>
  );
</xsl:template>

<!--
  Parameter as list of const QJSValue& v1
-->
<xsl:template match="qsrc:parameter" mode="qjsvalue">
  const QJSValue&amp; 
  <!--
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>
  -->

  <xsl:value-of select="concat('a', position())" />

  <!--
  < ! - - e.g. const QWidget* - - >
  <xsl:if test="@const='true'">
    <xsl:value-of select="'const'" />
    <xsl:value-of select="' '" />
  </xsl:if>
  <xsl:value-of select="@type" />
  <xsl:value-of select="@modifier" />
  <xsl:value-of select="' '" />

  < ! - - e.g. parent = nullptr - - >
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />

      < ! - - default value for argument (header only) - - >
      <xsl:if test="$mode='h'">
        <xsl:if test="@default!=''">
          <xsl:value-of select="'='" />
          <xsl:value-of select="@default" />
        </xsl:if>
      </xsl:if>

    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>
  -->

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>


<xsl:template match="qsrc:parameter" mode="towrapper">
  <!-- e.g. const QWidgetWrapper* -->
  <xsl:if test="@const='true'">
    <xsl:value-of select="'const'" />
    <xsl:value-of select="' '" />
  </xsl:if>
  <xsl:choose>
    <xsl:when test="starts-with(@type, 'Q')">
      <xsl:value-of select="@type" />_Wrapper
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="@type" />
    </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="@modifier" />
  <xsl:value-of select="' '" />

  <!-- parameter name or a1, a2, ... -->
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>


<xsl:template match="qsrc:parameter" mode="towrappercall">

  <!-- parameter name or a1, a2, ... -->
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:if test="starts-with(@type, 'Q')">
    <xsl:text>-&gt;getWrapped()</xsl:text>
  </xsl:if>

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>


<xsl:template match="qsrc:parameter" mode="names">
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="concat('a', position())" />
    </xsl:otherwise>
  </xsl:choose>

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>

<xsl:template match="qsrc:parameter" mode="cppnames">
  <!--
  <xsl:choose>
    <xsl:when test="@name!=''">
      <xsl:value-of select="@name" />_cpp
    </xsl:when>
    <xsl:otherwise>
    -->
      <xsl:value-of select="concat('a', position())" />_cpp
    <!--
    </xsl:otherwise>
  </xsl:choose>
  -->

  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>

<!--
  Converts the list of parameters from QSValue to native types (int, RVector, ...).
-->
<xsl:template match="qsrc:parameter" mode="tocpp">
  // parameter: <xsl:value-of select="@name" />
  <xsl:text>&#xa;</xsl:text>

  <xsl:variable name="type">
    <xsl:value-of select="@type" />
  </xsl:variable>

  <xsl:variable name="name">
    <!--
    <xsl:choose>
      <xsl:when test="@name!=''">
        <xsl:value-of select="@name" />
      </xsl:when>
      <xsl:otherwise>
      -->
        <xsl:value-of select="concat('a', position())" />
      <!--
      </xsl:otherwise>
    </xsl:choose>
    -->
  </xsl:variable>
  
  <xsl:variable name="modifier">
    <xsl:choose>
      <xsl:when test="@modifier='*'">
        <xsl:value-of select="'*'" />
      </xsl:when>
      <xsl:when test="qc:is-non-copyable($type)='true'">
        <xsl:value-of select="'*'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="''" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:value-of select="concat(@type, $modifier)" /><xsl:text> </xsl:text><xsl:value-of select="$name" />_cpp = <xsl:value-of select="qc:type-to-function-js2cpp(@type, @modifier)" />(handler, <xsl:value-of select="$name" />);

</xsl:template>


<!--
  Converts the list of parameters from QSValue to native types for use in calling the base constructor:
  RJSHelper::js2cpp_xy(engine, a1), ...
-->
<!--
<xsl:template match="qsrc:parameter" mode="tocppcontr">
  <xsl:variable name="name">
    <xsl:value-of select="concat('a', position())" />
  </xsl:variable>

  RJSHelper::js2cpp_<xsl:value-of select="qc:type-to-function-postfix(@type)" />(engine, <xsl:value-of select="$name" />)
  <xsl:if test="position() &lt; last()">, </xsl:if>
</xsl:template>
-->





<func:function name="qc:include_guard">
  <xsl:param name="filename" />
  <func:result>
      <xsl:value-of select="concat(qc:uppercase(translate($filename, '.', '_')), '_BASE')" />
  </func:result>
</func:function>

<!--
<func:function name="qc:get-wrapper-return-type">
  <xsl:param name="type" />
  <func:result>
    <xsl:choose>
      <xsl:when test="$type='RVector'">
        <xsl:value-of select="'RVectorWrapper*'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$type" />
      </xsl:otherwise>
    </xsl:choose>
  </func:result>
</func:function>
-->

<!--
<func:function name="qc:get-wrapper-type">
  <xsl:param name="type" />
  <func:result>
    <xsl:choose>
      <xsl:when test="$type='RVector'">
        <xsl:value-of select="'RVectorWrapper'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$type" />
      </xsl:otherwise>
    </xsl:choose>
  </func:result>
</func:function>
-->

<func:function name="qc:type-to-function-postfix">
  <xsl:param name="type" />
  <func:result>
    <xsl:value-of 
      select="qc:replace(
              qc:replace(
              qc:replace(
              qc:replace(
              qc:replace(
              qc:replace(
              qc:replace(
                $type, '&gt;', ''
              ), '&lt;', '_'
              ), '::', '_'
              ), 'const', ''
              ), '&amp;', ''
              ), '*', ''
              ), ' ', ''
              )" />
  </func:result>
</func:function>

</xsl:stylesheet>