-
Notifications
You must be signed in to change notification settings - Fork 104
/
zproject_class.gsl
850 lines (758 loc) · 25.5 KB
/
zproject_class.gsl
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
# Generate project API
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/zeromq/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
.macro generate_project_api
.#
.# Build the project header file
.#
.directory.create ("include")
.if !file.exists ("include/$(project.header:)") & count (class, class.name = project.name) = 0
. echo "Generating skeleton for include/$(project.header)"
. output "include/$(project.header)"
/* =========================================================================
$(project.name) - $(project.description?'':)
. for project.license
$(string.trim (license.):block )
. endfor
=========================================================================
*/
#ifndef $(PROJECT.HEADER:c)_H_INCLUDED
#define $(PROJECT.HEADER:c)_H_INCLUDED
// Include the project library file
#include "$(project.prefix)_library.$(project.header_ext)"
// Add your own public definitions here, if you need them
#endif
.else
. echo "NOT regenerating an existing include/$(project.header) skeleton file; but you probably should not care"
.endif
.output "include/$(project.prefix)_library.$(project.header_ext)"
/* =========================================================================
$(project.name) - generated layer of public API
. for project.license
$(string.trim (license.):block )
. endfor
$(project.GENERATED_WARNING_HEADER:)
=========================================================================
*/
#ifndef $(PROJECT.PREFIX)_LIBRARY_H_INCLUDED
#define $(PROJECT.PREFIX)_LIBRARY_H_INCLUDED
// Set up environment for the application
.if file.exists ("include/$(project.prelude)")
#include "$(project.prelude)"
.endif
// External dependencies
.for use where !implied & !private
. if (use.optional = 1)
.# TODO: Fix up GSL to only reference same macro once (e.g. if variants are
.# defined for OS packages named vastly different in various distros, like lua)
#if defined (HAVE_$(USE.AM_LIB_MACRO))
#include <$(use.header:)>
#endif
. else
#include <$(use.header:)>
. endif
.endfor
// $(PROJECT.PREFIX) version macros for compile-time API detection
#define $(PROJECT.PREFIX)_VERSION_MAJOR $(project->version.major)
#define $(PROJECT.PREFIX)_VERSION_MINOR $(project->version.minor)
#define $(PROJECT.PREFIX)_VERSION_PATCH $(project->version.patch)
#define $(PROJECT.PREFIX)_MAKE_VERSION(major, minor, patch) \\
((major) * 10000 + (minor) * 100 + (patch))
#define $(PROJECT.PREFIX)_VERSION \\
$(PROJECT.PREFIX)_MAKE_VERSION($(PROJECT.PREFIX)_VERSION_MAJOR, $(PROJECT.PREFIX)_VERSION_MINOR, $(PROJECT.PREFIX)_VERSION_PATCH)
.if project.prefix <> "czmq" & project.has_czmq <> 1
// czmq_prelude.h bits
#if !defined (__WINDOWS__)
# if (defined WIN32 || defined _WIN32 || defined WINDOWS || defined _WINDOWS)
# undef __WINDOWS__
# define __WINDOWS__
# endif
#endif
// Windows MSVS doesn't have stdbool
#if (defined (_MSC_VER) && !defined (true))
# if (!defined (__cplusplus) && (!defined (true)))
# define true 1
# define false 0
typedef char bool;
# endif
#else
# include <stdbool.h>
#endif
// czmq_prelude.h bits
.endif
#if defined (__WINDOWS__)
# if defined $(PROJECT.PREFIX)_STATIC
# define $(PROJECT.PREFIX)_EXPORT
# elif defined $(PROJECT.PREFIX)_INTERNAL_BUILD
# if defined DLL_EXPORT
# define $(PROJECT.PREFIX)_EXPORT __declspec(dllexport)
# else
# define $(PROJECT.PREFIX)_EXPORT
# endif
# elif defined $(PROJECT.PREFIX)_EXPORTS
# define $(PROJECT.PREFIX)_EXPORT __declspec(dllexport)
# else
# define $(PROJECT.PREFIX)_EXPORT __declspec(dllimport)
# endif
# define $(PROJECT.PREFIX)_PRIVATE
#elif defined (__CYGWIN__)
# define $(PROJECT.PREFIX)_EXPORT
# define $(PROJECT.PREFIX)_PRIVATE
#else
# if (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
# define $(PROJECT.PREFIX)_PRIVATE __attribute__ ((visibility ("hidden")))
# define $(PROJECT.PREFIX)_EXPORT __attribute__ ((visibility ("default")))
# else
# define $(PROJECT.PREFIX)_PRIVATE
# define $(PROJECT.PREFIX)_EXPORT
# endif
#endif
.if !project.stable
// Project has no stable classes, so we build the draft API
#undef $(PROJECT.PREFIX)_BUILD_DRAFT_API
#define $(PROJECT.PREFIX)_BUILD_DRAFT_API
.endif
// Opaque class structures to allow forward references
// These classes are stable or legacy and built in all releases
.for project.class where scope = "public" & !draft
typedef struct _$(class.c_name:)_t $(class.c_name:)_t;
#define $(CLASS.C_NAME:c)_T_DEFINED
.endfor
.for project.class where scope = "public" & draft
. if first ()
// Draft classes are by default not built in stable releases
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
typedef struct _$(class.c_name:)_t $(class.c_name:)_t;
#define $(CLASS.C_NAME:c)_T_DEFINED
. if last ()
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
.for constant
. resolve_c_constant (constant, "draft")
.endfor
.if count (constant, scope = "public")
// Public constants
.endif
.for constant where scope = "public" & !draft
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CONSTANT.NAME:c)\t$(constant.value)
.endfor
.for constant where scope = "public" & draft
. if first ()
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CONSTANT.NAME:c)\t$(constant.value)
. if last ()
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
// Public classes, each with its own header file
.for header where scope = "public"
#include "$(header.name:$(project.filename_prettyprint)).$(project.header_ext)"
.endfor
.for class where scope = "public" & class.c_name <> "$(project.name)" & !draft
#include "$(class.name:$(project.filename_prettyprint)).$(project.header_ext)"
.endfor
.for class where scope = "public" & class.c_name <> "$(project.name)" & draft
. if first ()
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
#include "$(class.name:$(project.filename_prettyprint)).$(project.header_ext)"
. if last ()
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
#ifdef __cplusplus
extern "C" {
#endif
// Self test for private classes
$(PROJECT.PREFIX)_EXPORT void
$(project.prefix)_private_selftest (bool verbose, const char *subtest);
#ifdef __cplusplus
}
#endif
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
#endif
/*
$(project.GENERATED_WARNING_HEADER:)
*/
.#
.# Build the project selftest program
.#
.if project.use_cxx
.output "src/$(project.prefix)_selftest.$(project.source_ext)"
.else
.output "src/$(project.prefix)_selftest.$(project.source_ext)"
.endif
/* =========================================================================
$(project.prefix)_selftest.c - run selftests
Runs all selftests.
-------------------------------------------------------------------------
. for project.license
$(string.trim (license.):block )
. endfor
$(project.GENERATED_WARNING_HEADER:)
=========================================================================
*/
#include "$(project.prefix)_classes.$(project.header_ext)"
typedef struct {
const char *testname; // test name, can be called from command line this way
void (*test) (bool); // function to run the test (or NULL for private tests)
bool stable; // true if class is declared as stable
bool pub; // true if class is declared as public
const char *subtest; // name of private subtest to run
} test_item_t;
static test_item_t
all_tests [] = {
.for class where selftest & private ?= 1 & (!defined (type) | type <> "cucumber")
. if first ()
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
// Tests for stable/draft private classes:
// Now built only with --enable-drafts, so even stable builds are hidden behind the flag
. endif
. if class.draft = 1
{ "$(class.c_name)", NULL, false, false, "$(class.c_name)_test" },
. else
{ "$(class.c_name)", NULL, true, false, "$(class.c_name)_test" },
. endif
. if last ()
{ "private_classes", NULL, false, false, "$ALL" }, // compat option for older projects
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
.for class where !draft & selftest & private ?<> 1
. if first ()
// Tests for stable public classes:
. endif
{ "$(class.c_name)", $(class.c_name)_test, true, true, NULL },
.endfor
.for class where draft & selftest & private ?<> 1
. if first ()
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
// Tests for draft public classes:
. endif
{ "$(class.c_name)", $(class.c_name)_test, false, true, NULL },
. if last ()
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
{NULL, NULL, 0, 0, NULL} // Sentinel
};
// -------------------------------------------------------------------------
// Test whether a test is available.
// Return a pointer to a test_item_t if available, NULL otherwise.
//
test_item_t *
test_available (const char *testname)
{
test_item_t *item;
for (item = all_tests; item->testname; item++) {
if (streq (testname, item->testname))
return item;
}
return NULL;
}
// -------------------------------------------------------------------------
// Run all tests.
//
static void
test_runall (bool verbose)
{
test_item_t *item;
printf ("Running $(project.name) selftests...\\n");
for (item = all_tests; item->testname; item++) {
if (streq (item->testname, "private_classes"))
continue;
if (!item->subtest)
item->test (verbose);
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API // selftest is still in draft
else
$(project.prefix)_private_selftest (verbose, item->subtest);
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
}
printf ("Tests passed OK\\n");
}
static void
test_list (void)
{
test_item_t *item;
puts ("Available tests:");
for (item = all_tests; item->testname; item++)
printf (" %-40s - %s\t%s\\n",
item->testname,
item->stable ? "stable" : "draft",
item->pub ? "public" : "private"
);
}
static void
test_number (void)
{
int n = 0;
test_item_t *item;
for (item = all_tests; item->testname; item++) {
if (! streq (item->testname, "private_classes"))
n++;
}
printf ("%d\\n", n);
}
int
main (int argc, char **argv)
{
bool verbose = false;
test_item_t *test = 0;
int argn;
for (argn = 1; argn < argc; argn++) {
if (streq (argv [argn], "--help")
|| streq (argv [argn], "-h")) {
puts ("$(project.prefix)_selftest.c [options] ...");
puts (" --verbose / -v verbose test output");
puts (" --number / -n report number of tests");
puts (" --list / -l list all tests");
puts (" --test / -t [name] run only test 'name'");
puts (" --continue / -c continue on exception (on Windows)");
return 0;
}
if (streq (argv [argn], "--verbose")
|| streq (argv [argn], "-v"))
verbose = true;
else
if (streq (argv [argn], "--number")
|| streq (argv [argn], "-n")) {
test_number ();
return 0;
}
else
if (streq (argv [argn], "--list")
|| streq (argv [argn], "-l")) {
test_list ();
return 0;
}
else
if (streq (argv [argn], "--test")
|| streq (argv [argn], "-t")) {
argn++;
if (argn >= argc) {
fprintf (stderr, "--test needs an argument\\n");
return 1;
}
test = test_available (argv [argn]);
if (!test) {
fprintf (stderr, "%s not valid, use --list to show tests\\n", argv [argn]);
return 1;
}
}
else
if (streq (argv [argn], "--continue")
|| streq (argv [argn], "-c")) {
#ifdef _MSC_VER
// When receiving an abort signal, only print to stderr (no dialog)
_set_abort_behavior (0, _WRITE_ABORT_MSG);
#endif
}
else {
printf ("Unknown option: %s\\n", argv [argn]);
return 1;
}
}
#ifdef NDEBUG
printf(" !!! 'assert' macro is disabled, remove NDEBUG from your compilation definitions.\\n");
printf(" tests will be meaningless.\\n");
#endif //
if (test) {
printf ("Running $(project.name) test '%s'...\\n", test->testname);
if (!test->subtest)
test->test (verbose);
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API // selftest is still in draft
else
$(project.prefix)_private_selftest (verbose, test->subtest);
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
}
else
test_runall (verbose);
return 0;
}
/*
$(project.GENERATED_WARNING_HEADER:)
*/
.#
.# Build the project private classes selftest module
.#
.if project.use_cxx
.output "src/$(project.prefix)_private_selftest.$(project.source_ext)"
.else
.output "src/$(project.prefix)_private_selftest.$(project.source_ext)"
.endif
/* =========================================================================
$(project.prefix)_private_selftest.c - run private classes selftests
Runs all private classes selftests.
-------------------------------------------------------------------------
. for project.license
$(string.trim (license.):block )
. endfor
$(project.GENERATED_WARNING_HEADER:)
=========================================================================
*/
#include "$(project.prefix)_classes.$(project.header_ext)"
// -------------------------------------------------------------------------
// Run all private classes tests.
//
void
$(project.prefix)_private_selftest (bool verbose, const char *subtest)
{
.for class where !draft & selftest & private ?= 1 & (!defined (type) | type <> "cucumber")
. if first ()
// Tests for stable private classes:
. endif
if (streq (subtest, "$ALL") || streq (subtest, "$(class.c_name)_test"))
$(class.c_name)_test (verbose);
.endfor
.for class where draft & selftest & private ?= 1 & (!defined (type) | type <> "cucumber")
. if first ()
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
// Tests for draft private classes:
. endif
if (streq (subtest, "$ALL") || streq (subtest, "$(class.c_name)_test")
$(class.c_name)_test (verbose);
. if last ()
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
.endfor
}
/*
$(project.GENERATED_WARNING_HEADER:)
*/
.-
.- Build the classes header for private header files and constants
.-
.output "src/$(project.prefix)_classes.$(project.header_ext)"
/* =========================================================================
$(project.prefix)_classes - private header file
. for project.license
$(string.trim (license.):block )
. endfor
$(project.GENERATED_WARNING_HEADER:)
=========================================================================
*/
#ifndef $(PROJECT.PREFIX)_CLASSES_H_INCLUDED
#define $(PROJECT.PREFIX)_CLASSES_H_INCLUDED
// Platform definitions, must come first
#include "platform.h"
// Asserts check the invariants of methods. If they're not
// fulfilled the program should fail fast. Therefore enforce them!
#ifdef NDEBUG
#undef NDEBUG
#include <assert.h>
#define NDEBUG
#else
#include <assert.h>
#endif
// External API
#include "../include/$(project.header:)"
// Private external dependencies
.for use where !implied & private
. if (use.optional = 1)
#if defined (HAVE_$(USE.AM_LIB_MACRO))
#include <$(use.header:)>
#endif
. else
#include <$(use.header:)>
. endif
.endfor
// Opaque class structures to allow forward references
.for class where scope = "private"
#ifndef $(CLASS.C_NAME:c)_T_DEFINED
typedef struct _$(class.c_name:)_t $(class.c_name:)_t;
#define $(CLASS.C_NAME:c)_T_DEFINED
#endif
.endfor
// Extra headers
.for header where scope = "private"
#include "$(header.name:$(project.filename_prettyprint)).$(project.header_ext)"
.endfor
// Internal API
.if project.prefix <> "czmq" & project.has_czmq <> 1
// common definitions and idioms from czmq_prelude.h, which are used in generated code
#if ! defined(__CZMQ_PRELUDE_H_INCLUDED__)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define streq(s1,s2) (!strcmp ((s1), (s2)))
#define strneq(s1,s2) (strcmp ((s1), (s2)))
// Replacement for malloc() which asserts if we run out of heap, and
// which zeroes the allocated block.
static inline void *
safe_malloc (size_t size, const char *file, unsigned line)
{
// printf ("%s:%u %08d\\n", file, line, (int) size);
void *mem = calloc (1, size);
if (mem == NULL) {
fprintf (stderr, "FATAL ERROR at %s:%u\\n", file, line);
fprintf (stderr, "OUT OF MEMORY (malloc returned NULL)\\n");
fflush (stderr);
abort ();
}
return mem;
}
// Define _ZMALLOC_DEBUG if you need to trace memory leaks using e.g. mtrace,
// otherwise all allocations will claim to come from czmq_prelude.h. For best
// results, compile all classes so you see dangling object allocations.
// _ZMALLOC_PEDANTIC does the same thing, but its intention is to propagate
// out of memory condition back up the call stack.
#if defined (_ZMALLOC_DEBUG) || defined (_ZMALLOC_PEDANTIC)
# define zmalloc(size) calloc(1,(size))
#else
# define zmalloc(size) safe_malloc((size), __FILE__, __LINE__)
#endif
#endif // __CZMQ_PRELUDE_H_INCLUDED__
.endif
.for class where scope = "public"
. visibility = "$(PROJECT.PREFIX)_PRIVATE"
. for class.method where private
// $(method.description:no,block)
. if method->return.fresh
// Caller owns return value and must destroy it when done.
. endif
$(VISIBILITY) $(c_method_signature (method):)\
. if defined(method.format_index)
CHECK_PRINTF ($(method.format_index));
. else
;
. endif
. endfor
.endfor
.for class where scope = "private"
#include "$(class.name:$(project.filename_prettyprint)).$(project.header_ext)"
.endfor
// *** To avoid double-definitions, only define if building without draft ***
#ifndef $(PROJECT.PREFIX)_BUILD_DRAFT_API
.for constant where scope = "public" & draft
. if first ()
// *** Draft global constants, defined for internal use only ***
. endif
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CONSTANT.NAME:c)\t$(constant.value)
.endfor
.for class where draft = 0
. for constant where draft = 1
. if first ()
// *** Draft constants, defined for internal use only ***
. endif
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CLASS.NAME:c)_$(NAME:c) $(value)
. endfor
. for class.callback_type where draft = 1
. if first ()
// *** Draft callbacks, defined for internal use only ***
. endif
// $(callback_type.description:no,block)
$(c_callback_typedef (callback_type))
. endfor
. for . as method where draft = 1
. if name () = "constructor" | name () = "method" | name () = "destructor"
// *** Draft method, defined for internal use only ***
// $(.description:no,block)
. if ->return.fresh
// Caller owns return value and must destroy it when done.
. endif
$(PROJECT.PREFIX)_PRIVATE $(c_method_signature (method):)\
. if defined(method.format_index)
CHECK_PRINTF ($(method.format_index));
. else
;
. endif
. endif
. endfor
.endfor
// Self test for private classes
$(PROJECT.PREFIX)_PRIVATE void
$(project.prefix)_private_selftest (bool verbose, const char *subtest);
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
.for constant where scope = "private"
. if first ()
// Private constants
. endif
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CONSTANT.NAME:c)\t$(constant.value)
.endfor
#endif
.close
.# Generate API interface
.macro method_state_comment (state)
. if my.state = "draft"
// *** Draft method, for development use, may change without warning ***
. elsif my.state = "legacy"
// *** Deprecated method, slated for removal: avoid using it ***
. endif
.endmacro
.macro generate_interface (draft)
. if class.scope = "private"
. visibility = "$(PROJECT.PREFIX)_PRIVATE"
. else
. visibility = "$(PROJECT.PREFIX)_EXPORT"
. endif
. for class.constant where draft = my.draft
. if ("$(constant.description)" <> "")
// $(constant.description:no,block)
. endif
#define $(CLASS.NAME:c)_$(NAME:c) $(value:)
. if last ()
. endif
. endfor
. for class.callback_type where draft = my.draft
// $(callback_type.description:no,block)
$(c_callback_typedef (callback_type))
. endfor
. for class.constructor where draft = my.draft
. method_state_comment (state)
// $(constructor.description:no,block)
$(VISIBILITY) $(c_method_signature (constructor):)\
. if defined(constructor.format_index)
CHECK_PRINTF ($(constructor.format_index));
. else
;
. endif
. endfor
. for class.destructor where draft = my.draft
. method_state_comment (state)
// $(destructor.description:no,block)
$(VISIBILITY) $(c_method_signature (destructor):)\
. if defined(destructor.format_index)
CHECK_PRINTF ($(destructor.format_index));
. else
;
. endif
. endfor
. for class.actor where draft = my.draft
// $(actor.description:no,block)
$(VISIBILITY) void
$(actor.name:c) (zsock_t *pipe, void *args);
. endfor
. for class.method where draft = my.draft & !private
. method_state_comment (state)
// $(method.description:no,block)
. if method->return.fresh
// Caller owns return value and must destroy it when done.
. endif
$(VISIBILITY) $(c_method_signature (method):)\
. if defined(method.format_index)
CHECK_PRINTF ($(method.format_index));
. else
;
. endif
. endfor
.endmacro
.template 0
#
# Regenerate the @interface for the class if it has an API model
#
for class
skeleton_class_header ()
skeleton_class_source ()
if !defined (class.api)
resolve_c_class (class)
endif
if defined (class.api)
handle = file.open (class.header, "ra")
current_loc = "prefix"
error = # undefined
HEADER_FILE_PREFIX = "" # All lines preceding the @interface line
HEADER_FILE_SUFFIX = "" # All lines following the @end line
# Read each line from the file and pull out the prefix and suffix blocks
while defined (handle)
this_line = handle.read (error)? ""
if defined (error)
handle.close ()
handle = # undefined
elsif current_loc = "prefix"
if regexp.match ("//\\s*@interface", this_line)
current_loc = "interface"
elsif regexp.match ("//\\s*@warning", this_line)
# ignore the warning line - do not copy it
else
HEADER_FILE_PREFIX += this_line
endif
elsif current_loc = "interface"
if regexp.match ("//\\s*@end", this_line)
current_loc = "suffix"
endif
elsif current_loc = "suffix"
HEADER_FILE_SUFFIX += this_line
endif
endwhile
# Now output the file with stored prefix, generated interface,
# and stored suffix
output class.header
template 1
$(HEADER_FILE_PREFIX:)\
// @warning THE FOLLOWING @INTERFACE BLOCK IS AUTO-GENERATED BY ZPROJECT
// @warning Please edit the model at "$(class.api)" to make changes.
// @interface
. if !project.stable
// This API is a draft, and may change without notice.
. elsif class.state = "draft"
// This is a draft class, and may change without notice. It is disabled in
// stable builds by default. If you use this in applications, please ask
// for it to be pushed to stable state. Use --enable-drafts to enable.
. elsif class.state = "stable"
// This is a stable class, and may not change except for emergencies. It
// is provided in stable builds.
. if count (class.method, method.state = "draft")
// This class has draft methods, which may change over time. They are not
// in stable releases, by default. Use --enable-drafts to enable.
. endif
. if count (class.method, method.state = "legacy")
// This class has legacy methods, which will be removed over time. You
// should not use them, and migrate any code that is still using them.
. endif
. elsif class.state = "legacy"
// This is a deprecated class, and will be removed over time. It is
// provided in stable builds to support old applications. You should
// stop using this class, and migrate any code that is still using it.
. endif
. generate_interface (0)
. if count (class., count.draft ?= 1)
#ifdef $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
. generate_interface (1)
. if count (class., count.draft ?= 1)
#endif // $(PROJECT.PREFIX)_BUILD_DRAFT_API
. endif
// @end
$(HEADER_FILE_SUFFIX:)\
. endtemplate
close
endif
endfor
.endtemplate
.endmacro
if count (class)
for project.class
if !defined (class.api)
resolve_c_class (class)
endif
endfor
generate_project_api ()
endif