forked from swig/swig
-
Notifications
You must be signed in to change notification settings - Fork 19
/
lang.cxx
4234 lines (3677 loc) · 133 KB
/
lang.cxx
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
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* lang.cxx
*
* Language base class functions. Default C++ handling is also implemented here.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
#include <ctype.h>
/* default mode settings */
static int director_mode = 0;
static int director_protected_mode = 1;
static int all_protected_mode = 0;
static int naturalvar_mode = 0;
Language *Language::this_ = 0;
/* Set director_protected_mode */
void Wrapper_director_mode_set(int flag) {
director_mode = flag;
}
void Wrapper_director_protected_mode_set(int flag) {
director_protected_mode = flag;
}
void Wrapper_all_protected_mode_set(int flag) {
all_protected_mode = flag;
}
void Wrapper_naturalvar_mode_set(int flag) {
naturalvar_mode = flag;
}
extern "C" {
int Swig_director_mode() {
return director_mode;
}
int Swig_director_protected_mode() {
return director_protected_mode;
}
int Swig_all_protected_mode() {
return all_protected_mode;
}
void Language_replace_special_variables(String *method, String *tm, Parm *parm) {
Language::instance()->replaceSpecialVariables(method, tm, parm);
}
}
/* Some status variables used during parsing */
static int InClass = 0; /* Parsing C++ or not */
static String *ClassName = 0; /* This is the real name of the current class */
static String *EnumClassName = 0; /* Enum class name */
static String *ClassPrefix = 0; /* Class prefix */
static String *EnumClassPrefix = 0; /* Prefix for strongly typed enums (including ClassPrefix) */
static String *NSpace = 0; /* Namespace for the nspace feature */
static String *ClassType = 0; /* Fully qualified type name to use */
static String *DirectorClassName = 0; /* Director name of the current class */
int Abstract = 0;
int ImportMode = 0;
int IsVirtual = 0;
static String *AttributeFunctionGet = 0;
static String *AttributeFunctionSet = 0;
static Node *CurrentClass = 0;
int line_number = 0;
String *input_file = 0;
int SmartPointer = 0;
static Hash *classhash;
extern int GenerateDefault;
extern int ForceExtern;
extern int AddExtern;
/* import modes */
#define IMPORT_MODE 1
#define IMPORT_MODULE 2
/* ----------------------------------------------------------------------
* Dispatcher::emit_one()
*
* Dispatch a single node
* ---------------------------------------------------------------------- */
int Dispatcher::emit_one(Node *n) {
int ret = SWIG_OK;
char *tag = Char(nodeType(n));
if (!tag) {
/* Printf(stderr,"SWIG: Fatal internal error. Malformed parse tree
node!\n"); */
return SWIG_OK;
}
/* Do not proceed if marked with an error */
if (Getattr(n, "error"))
return SWIG_OK;
/* Look for warnings */
String *wrn = Getattr(n, "feature:warnfilter");
if (wrn)
Swig_warnfilter(wrn, 1);
/* ============================================================
* C/C++ parsing
* ============================================================ */
if (strcmp(tag, "extern") == 0) {
ret = externDeclaration(n);
} else if (strcmp(tag, "cdecl") == 0) {
ret = cDeclaration(n);
} else if (strcmp(tag, "enum") == 0) {
ret = enumDeclaration(n);
} else if (strcmp(tag, "enumitem") == 0) {
ret = enumvalueDeclaration(n);
} else if (strcmp(tag, "enumforward") == 0) {
ret = enumforwardDeclaration(n);
} else if (strcmp(tag, "class") == 0) {
ret = classDeclaration(n);
} else if (strcmp(tag, "classforward") == 0) {
ret = classforwardDeclaration(n);
} else if (strcmp(tag, "constructor") == 0) {
ret = constructorDeclaration(n);
} else if (strcmp(tag, "destructor") == 0) {
ret = destructorDeclaration(n);
} else if (strcmp(tag, "access") == 0) {
ret = accessDeclaration(n);
} else if (strcmp(tag, "using") == 0) {
ret = usingDeclaration(n);
} else if (strcmp(tag, "namespace") == 0) {
ret = namespaceDeclaration(n);
} else if (strcmp(tag, "template") == 0) {
ret = templateDeclaration(n);
} else if (strcmp(tag, "lambda") == 0) {
ret = lambdaDeclaration(n);
}
/* ===============================================================
* SWIG directives
* =============================================================== */
else if (strcmp(tag, "top") == 0) {
ret = top(n);
} else if (strcmp(tag, "extend") == 0) {
ret = extendDirective(n);
} else if (strcmp(tag, "apply") == 0) {
ret = applyDirective(n);
} else if (strcmp(tag, "clear") == 0) {
ret = clearDirective(n);
} else if (strcmp(tag, "constant") == 0) {
ret = constantDirective(n);
} else if (strcmp(tag, "fragment") == 0) {
ret = fragmentDirective(n);
} else if (strcmp(tag, "import") == 0) {
ret = importDirective(n);
} else if (strcmp(tag, "include") == 0) {
ret = includeDirective(n);
} else if (strcmp(tag, "insert") == 0) {
ret = insertDirective(n);
} else if (strcmp(tag, "module") == 0) {
ret = moduleDirective(n);
} else if (strcmp(tag, "native") == 0) {
ret = nativeDirective(n);
} else if (strcmp(tag, "pragma") == 0) {
ret = pragmaDirective(n);
} else if (strcmp(tag, "typemap") == 0) {
ret = typemapDirective(n);
} else if (strcmp(tag, "typemapcopy") == 0) {
ret = typemapcopyDirective(n);
} else if (strcmp(tag, "typemapitem") == 0) {
ret = typemapitemDirective(n);
} else if (strcmp(tag, "types") == 0) {
ret = typesDirective(n);
} else {
Swig_error(input_file, line_number, "Unrecognized parse tree node type '%s'\n", tag);
ret = SWIG_ERROR;
}
if (wrn)
Swig_warnfilter(wrn, 0);
return ret;
}
/* ----------------------------------------------------------------------
* Dispatcher::emit_children()
*
* Emit all children that match the given type. type = 0 means all types.
* ---------------------------------------------------------------------- */
int Dispatcher::emit_children(Node *n) {
Node *c;
char *eo = Char(Getattr(n, "feature:emitonlychildren"));
for (c = firstChild(n); c; c = nextSibling(c)) {
if (eo) {
const char *tag = Char(nodeType(c));
if (strcmp(tag, "cdecl") == 0) {
if (checkAttribute(c, "storage", "typedef"))
tag = "typedef";
}
if (strstr(eo, tag) == 0) {
continue;
}
}
emit_one(c);
}
return SWIG_OK;
}
/* Stubs for dispatcher class. We don't do anything by default---up to derived class
to fill in traversal code */
int Dispatcher::defaultHandler(Node *) {
return SWIG_OK;
}
int Dispatcher::extendDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::applyDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::clearDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::constantDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::fragmentDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::importDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::includeDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::insertDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::moduleDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::nativeDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::pragmaDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapitemDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typemapcopyDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::typesDirective(Node *n) {
return defaultHandler(n);
}
int Dispatcher::cDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::externDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumvalueDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::enumforwardDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::classDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::templateDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::lambdaDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::classforwardDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::constructorDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::destructorDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::accessDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::usingDeclaration(Node *n) {
return defaultHandler(n);
}
int Dispatcher::namespaceDeclaration(Node *n) {
return defaultHandler(n);
}
/* Allocators */
Language::Language():
none_comparison(NewString("$arg != 0")),
director_ctor_code(NewString("")),
director_prot_ctor_code(0),
symtabs(NewHash()),
classtypes(NewHash()),
enumtypes(NewHash()),
overloading(0),
multiinput(0),
cplus_runtime(0),
directors(0) {
symbolAddScope(""); // create top level/global symbol table scope
argc_template_string = NewString("argc");
argv_template_string = NewString("argv[%d]");
/* Default director constructor code, passed to Swig_ConstructorToFunction */
Printv(director_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", "} else {\n", " $nondirector_new \n", "}\n", NIL);
/*
Default director 'protected' constructor code, disabled by
default. Each language that needs it, has to define it.
*/
director_prot_ctor_code = 0;
director_multiple_inheritance = 1;
director_language = 0;
assert(!this_);
this_ = this;
}
Language::~Language() {
Delete(symtabs);
Delete(classtypes);
Delete(enumtypes);
Delete(director_ctor_code);
Delete(none_comparison);
this_ = 0;
}
/* -----------------------------------------------------------------------------
* directorClassName()
* ----------------------------------------------------------------------------- */
String *Language::directorClassName(Node *n) {
String *dirclassname;
String *nspace = NewString(Getattr(n, "sym:nspace"));
const char *attrib = "director:classname";
String *classname = getClassPrefix();
Replace(nspace, NSPACE_SEPARATOR, "_", DOH_REPLACE_ANY);
if (Len(nspace) > 0)
dirclassname = NewStringf("SwigDirector_%s_%s", nspace, classname);
else
dirclassname = NewStringf("SwigDirector_%s", classname);
Setattr(n, attrib, dirclassname);
Delete(nspace);
return dirclassname;
}
/* ----------------------------------------------------------------------
emit_one()
---------------------------------------------------------------------- */
int Language::emit_one(Node *n) {
int ret;
int oldext;
if (!n)
return SWIG_OK;
if (GetFlag(n, "feature:ignore")
&& !Getattr(n, "feature:onlychildren"))
return SWIG_OK;
oldext = Extend;
if (Getattr(n, "feature:extend"))
Extend = 1;
line_number = Getline(n);
input_file = Getfile(n);
/*
symtab = Getattr(n,"symtab");
if (symtab) {
symtab = Swig_symbol_setscope(symtab);
}
*/
ret = Dispatcher::emit_one(n);
/*
if (symtab) {
Swig_symbol_setscope(symtab);
}
*/
Extend = oldext;
return ret;
}
static Parm *nonvoid_parms(Parm *p) {
if (p) {
SwigType *t = Getattr(p, "type");
if (SwigType_type(t) == T_VOID)
return 0;
}
return p;
}
/* -----------------------------------------------------------------------------
* cplus_value_type()
*
* Returns the alternative value type needed in C++ for class value
* types. When swig is not sure about using a plain $ltype value,
* since the class doesn't have a default constructor, or it can't be
* assigned, you will get back 'SwigValueWrapper<type >'.
*
* ----------------------------------------------------------------------------- */
SwigType *cplus_value_type(SwigType *t) {
return SwigType_alttype(t, 0);
}
static Node *first_nontemplate(Node *n) {
while (n) {
if (Strcmp(nodeType(n), "template") != 0)
return n;
n = Getattr(n, "sym:nextSibling");
}
return n;
}
/* --------------------------------------------------------------------------
* swig_pragma()
*
* Handle swig pragma directives.
* -------------------------------------------------------------------------- */
void swig_pragma(char *lang, char *name, char *value) {
if (strcmp(lang, "swig") == 0) {
if ((strcmp(name, "make_default") == 0) || ((strcmp(name, "makedefault") == 0))) {
GenerateDefault = 1;
} else if ((strcmp(name, "no_default") == 0) || ((strcmp(name, "nodefault") == 0))) {
Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use %%nodefaultctor, %%nodefaultdtor instead.\n");
GenerateDefault = 0;
} else if (strcmp(name, "attributefunction") == 0) {
String *nvalue = NewString(value);
char *s = strchr(Char(nvalue), ':');
if (!s) {
Swig_error(input_file, line_number, "Bad value for attributefunction. Expected \"fmtget:fmtset\".\n");
} else {
*s = 0;
AttributeFunctionGet = NewString(Char(nvalue));
AttributeFunctionSet = NewString(s + 1);
}
Delete(nvalue);
} else if (strcmp(name, "noattributefunction") == 0) {
AttributeFunctionGet = 0;
AttributeFunctionSet = 0;
}
}
}
/* --------------------------------------------------------------------------
* Language::use_naturalvar_mode()
*
* Determine whether to use const ref typemaps instead of pointer typemaps
* for variable access.
* -------------------------------------------------------------------------- */
int Language::use_naturalvar_mode(Node *n) const {
if (Getattr(n, "unnamed"))
return 0;
// The naturalvar feature can be attached to either the variable name or the variable's type
// naturalvar on the variable name is more specific and overrides naturalvar on the variable's type
String *naturalvar = Getattr(n, "feature:naturalvar");
bool explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0;
int nvar = GetFlag(n, "feature:naturalvar");
if (!explicitly_off && !nvar) {
/* look for feature in the class */
SwigType *ty = Getattr(n, "type");
SwigType *fullty = SwigType_typedef_resolve_all(ty);
if (SwigType_isclass(fullty)) {
SwigType *tys = SwigType_strip_qualifiers(fullty);
if (!CPlusPlus) {
Replaceall(tys, "struct ", "");
Replaceall(tys, "union ", "");
Replaceall(tys, "class ", "");
}
Node *typenode = Swig_symbol_clookup(tys, 0);
if (typenode) {
naturalvar = Getattr(typenode, "feature:naturalvar");
explicitly_off = naturalvar && Strcmp(naturalvar, "0") == 0;
nvar = nvar || GetFlag(typenode, "feature:naturalvar");
}
Delete(tys);
}
Delete(fullty);
}
nvar = nvar || naturalvar_mode;
return explicitly_off ? 0 : nvar ? CWRAP_NATURAL_VAR : 0;
}
/* ----------------------------------------------------------------------
* Language::top() - Top of parsing tree
* ---------------------------------------------------------------------- */
int Language::top(Node *n) {
Node *mod = Getattr(n, "module");
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
if (Getattr(options, "naturalvar")) {
naturalvar_mode = 1;
}
}
}
classhash = Getattr(n, "classes");
return emit_children(n);
}
/* ----------------------------------------------------------------------
* Language::extendDirective()
* ---------------------------------------------------------------------- */
int Language::extendDirective(Node *n) {
save_value<int> oldam(Extend, CWRAP_EXTEND);
save_value<AccessMode> oldmode(cplus_mode, PUBLIC);
emit_children(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::applyDirective()
* ---------------------------------------------------------------------- */
int Language::applyDirective(Node *n) {
Parm *pattern = Getattr(n, "pattern");
Node *c = firstChild(n);
while (c) {
Parm *apattern = Getattr(c, "pattern");
if (ParmList_len(pattern) != ParmList_len(apattern)) {
Swig_error(input_file, line_number, "Can't apply (%s) to (%s). Number of arguments don't match.\n", ParmList_str(pattern), ParmList_str(apattern));
} else {
if (!Swig_typemap_apply(pattern, apattern)) {
Swig_warning(WARN_TYPEMAP_APPLY_UNDEF, input_file, line_number, "Can't apply (%s). No typemaps are defined.\n", ParmList_str(pattern));
}
}
c = nextSibling(c);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::clearDirective()
* ---------------------------------------------------------------------- */
int Language::clearDirective(Node *n) {
Node *p;
for (p = firstChild(n); p; p = nextSibling(p)) {
ParmList *pattern = Getattr(p, "pattern");
Swig_typemap_clear_apply(pattern);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::constantDirective()
* ---------------------------------------------------------------------- */
int Language::constantDirective(Node *n) {
if (CurrentClass && (cplus_mode != PUBLIC))
return SWIG_NOWRAP;
if (!GetFlag(n, "feature:allowexcept")) {
UnsetFlag(n, "feature:except");
}
if (Getattr(n, "feature:exceptvar")) {
Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
}
if (!ImportMode) {
Swig_require("constantDirective", n, "name", "?value", NIL);
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
if (!value) {
value = Copy(name);
} else {
/* if (checkAttribute(n,"type","char")) {
value = NewString(value);
} else {
value = NewStringf("%(escape)s", value);
}
*/
Setattr(n, "rawvalue", value);
value = NewStringf("%(escape)s", value);
if (!Len(value))
Append(value, "\\0");
/* Printf(stdout,"'%s' = '%s'\n", name, value); */
}
Setattr(n, "value", value);
this->constantWrapper(n);
Swig_restore(n);
return SWIG_OK;
}
return SWIG_NOWRAP;
}
/* ----------------------------------------------------------------------
* Language::fragmentDirective()
* ---------------------------------------------------------------------- */
int Language::fragmentDirective(Node *n) {
Swig_fragment_register(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::importDirective()
* ---------------------------------------------------------------------- */
int Language::importDirective(Node *n) {
int oldim = ImportMode;
ImportMode = IMPORT_MODE;
emit_children(n);
ImportMode = oldim;
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::includeDirective()
* ---------------------------------------------------------------------- */
int Language::includeDirective(Node *n) {
emit_children(n);
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::insertDirective()
* ---------------------------------------------------------------------- */
int Language::insertDirective(Node *n) {
/* %insert directive */
if ((!ImportMode) || Getattr(n, "generated")) {
String *code = Getattr(n, "code");
String *section = Getattr(n, "section");
File *f = 0;
if (!section) { /* %{ ... %} */
f = Swig_filebyname("header");
} else {
f = Swig_filebyname(section);
}
if (f) {
Printf(f, "%s\n", code);
} else {
Swig_error(input_file, line_number, "Unknown target '%s' for %%insert directive.\n", section);
}
return SWIG_OK;
} else {
return SWIG_NOWRAP;
}
}
/* ----------------------------------------------------------------------
* Language::moduleDirective()
* ---------------------------------------------------------------------- */
int Language::moduleDirective(Node *n) {
(void) n;
/* %module directive */
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::nativeDirective()
* ---------------------------------------------------------------------- */
int Language::nativeDirective(Node *n) {
if (!ImportMode) {
return nativeWrapper(n);
} else {
return SWIG_NOWRAP;
}
}
/* ----------------------------------------------------------------------
* Language::pragmaDirective()
* ---------------------------------------------------------------------- */
int Language::pragmaDirective(Node *n) {
/* %pragma directive */
if (!ImportMode) {
String *lan = Getattr(n, "lang");
String *name = Getattr(n, "name");
String *value = Getattr(n, "value");
swig_pragma(Char(lan), Char(name), Char(value));
/* pragma(Char(lan),Char(name),Char(value)); */
return SWIG_OK;
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typemapDirective()
* ---------------------------------------------------------------------- */
int Language::typemapDirective(Node *n) {
/* %typemap directive */
String *method = Getattr(n, "method");
String *code = Getattr(n, "code");
Parm *kwargs = Getattr(n, "kwargs");
Node *items = firstChild(n);
static int namewarn = 0;
if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n");
if (!namewarn) {
Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\
For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\
$source by $input and $target by $1. For typemaps related to return values (out,\n\
argout,ret,except), replace $source by $1 and $target by $result. See the file\n\
Doc/Manual/Typemaps.html for complete details.\n");
namewarn = 1;
}
}
if (Strcmp(method, "except") == 0) {
Swig_warning(WARN_DEPRECATED_EXCEPT_TM, Getfile(n), Getline(n), "%%typemap(except) is deprecated. Use the %%exception directive.\n");
}
if (Strcmp(method, "in") == 0) {
Hash *k;
k = kwargs;
while (k) {
if (checkAttribute(k, "name", "numinputs")) {
if (!multiinput && (GetInt(k, "value") > 1)) {
Swig_error(Getfile(n), Getline(n), "Multiple-input typemaps (numinputs > 1) not supported by this target language module.\n");
return SWIG_ERROR;
}
break;
}
k = nextSibling(k);
}
if (!k) {
k = NewHash();
Setattr(k, "name", "numinputs");
Setattr(k, "value", "1");
set_nextSibling(k, kwargs);
Setattr(n, "kwargs", k);
kwargs = k;
}
}
if (Strcmp(method, "ignore") == 0) {
Swig_warning(WARN_DEPRECATED_IGNORE_TM, Getfile(n), Getline(n), "%%typemap(ignore) has been replaced by %%typemap(in,numinputs=0).\n");
Clear(method);
Append(method, "in");
Hash *k = NewHash();
Setattr(k, "name", "numinputs");
Setattr(k, "value", "0");
set_nextSibling(k, kwargs);
Setattr(n, "kwargs", k);
kwargs = k;
}
/* Replace $descriptor() macros */
if (code) {
Setfile(code, Getfile(n));
Setline(code, Getline(n));
Swig_cparse_replace_descriptor(code);
}
while (items) {
Parm *pattern = Getattr(items, "pattern");
Parm *parms = Getattr(items, "parms");
if (code) {
Swig_typemap_register(method, pattern, code, parms, kwargs);
} else {
Swig_typemap_clear(method, pattern);
}
items = nextSibling(items);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typemapcopyDirective()
* ---------------------------------------------------------------------- */
int Language::typemapcopyDirective(Node *n) {
String *method = Getattr(n, "method");
Parm *pattern = Getattr(n, "pattern");
Node *items = firstChild(n);
int nsrc = 0;
nsrc = ParmList_len(pattern);
while (items) {
ParmList *npattern = Getattr(items, "pattern");
if (nsrc != ParmList_len(npattern)) {
Swig_error(input_file, line_number, "Can't copy typemap. Number of types differ.\n");
} else {
if (Swig_typemap_copy(method, pattern, npattern) < 0) {
Swig_error(input_file, line_number, "Can't copy typemap (%s) %s = %s\n", method, ParmList_str(pattern), ParmList_str(npattern));
}
}
items = nextSibling(items);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::typesDirective()
* ---------------------------------------------------------------------- */
int Language::typesDirective(Node *n) {
Parm *parms = Getattr(n, "parms");
String *convcode = Getattr(n, "convcode"); /* optional user supplied conversion code for custom casting */
while (parms) {
SwigType *t = Getattr(parms, "type");
String *v = Getattr(parms, "value");
if (!v) {
SwigType_remember(t);
} else {
if (SwigType_issimple(t)) {
SwigType_inherit(t, v, 0, convcode);
}
}
parms = nextSibling(parms);
}
return SWIG_OK;
}
/* ----------------------------------------------------------------------
* Language::cDeclaration()
* ---------------------------------------------------------------------- */
int Language::cDeclaration(Node *n) {
String *name = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
SwigType *type = Getattr(n, "type");
SwigType *decl = Getattr(n, "decl");
String *storage = Getattr(n, "storage");
Node *over;
File *f_header = 0;
SwigType *ty, *fullty;
if (Getattr(n, "feature:onlychildren")) {
if (GetFlag(n, "feature:ignore")) {
return SWIG_NOWRAP;
} else {
// Found an unignored templated method that has an empty template instantiation (%template())
// Ignore it unless it has been %rename'd
if (Strncmp(symname, "__dummy_", 8) == 0) {
SetFlag(n, "feature:ignore");
Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
"%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
return SWIG_NOWRAP;
}
}
}
/* discards nodes following the access control rules */
if (cplus_mode != PUBLIC || !is_public(n)) {
/* except for friends, they are not affected by access control */
int isfriend = Cmp(storage, "friend") == 0;
if (!isfriend) {
/* Check what the director needs. If the method is pure virtual, it is always needed.
* Also wrap non-virtual protected members if asked for (allprotected mode). */
if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || isNonVirtualProtectedAccess(n)))) {
return SWIG_NOWRAP;
}
// Prevent wrapping protected overloaded director methods more than once -
// This bit of code is only needed due to the cDeclaration call in classHandler()
String *wrapname = NewStringf("nonpublic_%s%s", symname, Getattr(n, "sym:overname"));
if (Getattr(CurrentClass, wrapname)) {
Delete(wrapname);
return SWIG_NOWRAP;
}
SetFlag(CurrentClass, wrapname);
Delete(wrapname);
}
}
if (Cmp(storage, "typedef") == 0) {
Swig_save("cDeclaration", n, "type", NIL);
SwigType *t = Copy(type);
if (t) {
SwigType_push(t, decl);
Setattr(n, "type", t);
typedefHandler(n);
}
Swig_restore(n);
return SWIG_OK;
}
/* If in import mode, we proceed no further */
if (ImportMode)
return SWIG_NOWRAP;
/* If we're in extend mode and there is code, replace the $descriptor macros */
if (Extend) {
String *code = Getattr(n, "code");
if (code) {
Setfile(code, Getfile(n));
Setline(code, Getline(n));
Swig_cparse_replace_descriptor(code);
}
}
/* Overloaded symbol check */
over = Swig_symbol_isoverloaded(n);
if (!overloading) {
if (over)
over = first_nontemplate(over);
if (over && (over != n)) {
Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", Swig_name_decl(n));
Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", Swig_name_decl(over));
return SWIG_NOWRAP;
}
}
if (!validIdentifier(symname)) {
Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", SwigType_namestr(symname));
return SWIG_NOWRAP;
}
ty = NewString(type);
SwigType_push(ty, decl);
fullty = SwigType_typedef_resolve_all(ty);
if (SwigType_isfunction(fullty)) {
if (!SwigType_isfunction(ty)) {
Delete(ty);
ty = fullty;
fullty = 0;
ParmList *parms = SwigType_function_parms(ty, n);
Setattr(n, "parms", parms);
}
/* Transform the node into a 'function' node and emit */
if (!CurrentClass) {
f_header = Swig_filebyname("header");
if (AddExtern) {
if (f_header) {
if (Swig_storage_isextern(n) || (ForceExtern && !storage)) {
/* we don't need the 'extern' part in the C/C++ declaration,
and it produces some problems when namespace and SUN
Studio is used.
Printf(f_header,"extern %s", SwigType_str(ty,name));
In fact generating extern declarations is quite error prone and is
no longer the default. Getting it right seems impossible with namespaces
and default arguments and when a method is declared with the various Windows
calling conventions - SWIG doesn't understand Windows (non standard) calling
conventions in the first place, so can't regenerate them.
*/
String *str = SwigType_str(ty, name);
Printf(f_header, "%s", str);
Delete(str);
{
DOH *t = Getattr(n, "throws");
if (t) {
Printf(f_header, " throw(");
while (t) {
Printf(f_header, "%s", Getattr(t, "type"));
t = nextSibling(t);
if (t)
Printf(f_header, ",");
}
Printf(f_header, ")");
}
}
Printf(f_header, ";\n");
} else if (Swig_storage_isexternc(n)) {
/* here 'extern "C"' is needed */
String *str = SwigType_str(ty, name);
Printf(f_header, "extern \"C\" %s;\n", str);
Delete(str);
}
}