1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * Language base class functions. Default C++ handling is also implemented here.
8 * ----------------------------------------------------------------------------- */
10 char cvsroot_lang_cxx[] = "$Id: lang.cxx 11482 2009-07-30 18:48:14Z wsfulton $";
16 /* default mode settings */
17 static int director_mode = 0;
18 static int director_protected_mode = 1;
19 static int all_protected_mode = 0;
20 static int naturalvar_mode = 0;
21 Language* Language::this_ = 0;
23 /* Set director_protected_mode */
24 void Wrapper_director_mode_set(int flag) {
28 void Wrapper_director_protected_mode_set(int flag) {
29 director_protected_mode = flag;
32 void Wrapper_all_protected_mode_set(int flag) {
33 all_protected_mode = flag;
36 void Wrapper_naturalvar_mode_set(int flag) {
37 naturalvar_mode = flag;
41 int Swig_director_mode() {
44 int Swig_director_protected_mode() {
45 return director_protected_mode;
47 int Swig_all_protected_mode() {
48 return all_protected_mode;
50 void Language_replace_special_variables(String *method, String *tm, Parm *parm) {
51 Language::instance()->replaceSpecialVariables(method, tm, parm);
55 /* Some status variables used during parsing */
56 static int InClass = 0; /* Parsing C++ or not */
57 static String *ClassName = 0; /* This is the real name of the current class */
58 static String *ClassPrefix = 0; /* Class prefix */
59 static String *ClassType = 0; /* Fully qualified type name to use */
60 static String *DirectorClassName = 0; /* Director name of the current class */
64 static String *AttributeFunctionGet = 0;
65 static String *AttributeFunctionSet = 0;
66 static Node *CurrentClass = 0;
68 String *input_file = 0;
70 static Hash *classhash;
72 extern int GenerateDefault;
73 extern int ForceExtern;
79 #define IMPORT_MODULE 2
81 /* ----------------------------------------------------------------------
82 * Dispatcher::emit_one()
84 * Dispatch a single node
85 * ---------------------------------------------------------------------- */
87 int Dispatcher::emit_one(Node *n) {
91 char *tag = Char(nodeType(n));
93 /* Printf(stderr,"SWIG: Fatal internal error. Malformed parse tree
98 /* Do not proceed if marked with an error */
100 if (Getattr(n, "error"))
103 /* Look for warnings */
104 wrn = Getattr(n, "feature:warnfilter");
106 Swig_warnfilter(wrn, 1);
109 /* ============================================================
111 * ============================================================ */
113 if (strcmp(tag, "extern") == 0) {
114 ret = externDeclaration(n);
115 } else if (strcmp(tag, "cdecl") == 0) {
116 ret = cDeclaration(n);
117 } else if (strcmp(tag, "enum") == 0) {
118 ret = enumDeclaration(n);
119 } else if (strcmp(tag, "enumitem") == 0) {
120 ret = enumvalueDeclaration(n);
121 } else if (strcmp(tag, "enumforward") == 0) {
122 ret = enumforwardDeclaration(n);
123 } else if (strcmp(tag, "class") == 0) {
124 ret = classDeclaration(n);
125 } else if (strcmp(tag, "classforward") == 0) {
126 ret = classforwardDeclaration(n);
127 } else if (strcmp(tag, "constructor") == 0) {
128 ret = constructorDeclaration(n);
129 } else if (strcmp(tag, "destructor") == 0) {
130 ret = destructorDeclaration(n);
131 } else if (strcmp(tag, "access") == 0) {
132 ret = accessDeclaration(n);
133 } else if (strcmp(tag, "using") == 0) {
134 ret = usingDeclaration(n);
135 } else if (strcmp(tag, "namespace") == 0) {
136 ret = namespaceDeclaration(n);
137 } else if (strcmp(tag, "template") == 0) {
138 ret = templateDeclaration(n);
141 /* ===============================================================
143 * =============================================================== */
145 else if (strcmp(tag, "top") == 0) {
147 } else if (strcmp(tag, "extend") == 0) {
148 ret = extendDirective(n);
149 } else if (strcmp(tag, "apply") == 0) {
150 ret = applyDirective(n);
151 } else if (strcmp(tag, "clear") == 0) {
152 ret = clearDirective(n);
153 } else if (strcmp(tag, "constant") == 0) {
154 ret = constantDirective(n);
155 } else if (strcmp(tag, "fragment") == 0) {
156 ret = fragmentDirective(n);
157 } else if (strcmp(tag, "import") == 0) {
158 ret = importDirective(n);
159 } else if (strcmp(tag, "include") == 0) {
160 ret = includeDirective(n);
161 } else if (strcmp(tag, "insert") == 0) {
162 ret = insertDirective(n);
163 } else if (strcmp(tag, "module") == 0) {
164 ret = moduleDirective(n);
165 } else if (strcmp(tag, "native") == 0) {
166 ret = nativeDirective(n);
167 } else if (strcmp(tag, "pragma") == 0) {
168 ret = pragmaDirective(n);
169 } else if (strcmp(tag, "typemap") == 0) {
170 ret = typemapDirective(n);
171 } else if (strcmp(tag, "typemapcopy") == 0) {
172 ret = typemapcopyDirective(n);
173 } else if (strcmp(tag, "typemapitem") == 0) {
174 ret = typemapitemDirective(n);
175 } else if (strcmp(tag, "types") == 0) {
176 ret = typesDirective(n);
178 Printf(stderr, "%s:%d. Unrecognized parse tree node type '%s'\n", input_file, line_number, tag);
182 Swig_warnfilter(wrn, 0);
187 /* ----------------------------------------------------------------------
188 * Dispatcher::emit_children()
190 * Emit all children that match the given type. type = 0 means all types.
191 * ---------------------------------------------------------------------- */
193 int Dispatcher::emit_children(Node *n) {
195 char *eo = Char(Getattr(n, "feature:emitonlychildren"));
196 for (c = firstChild(n); c; c = nextSibling(c)) {
198 const char *tag = Char(nodeType(c));
199 if (strcmp(tag, "cdecl") == 0) {
200 if (checkAttribute(c, "storage", "typedef"))
203 if (strstr(eo, tag) == 0) {
213 /* Stubs for dispatcher class. We don't do anything by default---up to derived class
214 to fill in traversal code */
216 int Dispatcher::defaultHandler(Node *) {
219 int Dispatcher::extendDirective(Node *n) {
220 return defaultHandler(n);
222 int Dispatcher::applyDirective(Node *n) {
223 return defaultHandler(n);
225 int Dispatcher::clearDirective(Node *n) {
226 return defaultHandler(n);
228 int Dispatcher::constantDirective(Node *n) {
229 return defaultHandler(n);
231 int Dispatcher::fragmentDirective(Node *n) {
232 return defaultHandler(n);
234 int Dispatcher::importDirective(Node *n) {
235 return defaultHandler(n);
237 int Dispatcher::includeDirective(Node *n) {
238 return defaultHandler(n);
240 int Dispatcher::insertDirective(Node *n) {
241 return defaultHandler(n);
243 int Dispatcher::moduleDirective(Node *n) {
244 return defaultHandler(n);
246 int Dispatcher::nativeDirective(Node *n) {
247 return defaultHandler(n);
249 int Dispatcher::pragmaDirective(Node *n) {
250 return defaultHandler(n);
252 int Dispatcher::typemapDirective(Node *n) {
253 return defaultHandler(n);
255 int Dispatcher::typemapitemDirective(Node *n) {
256 return defaultHandler(n);
258 int Dispatcher::typemapcopyDirective(Node *n) {
259 return defaultHandler(n);
261 int Dispatcher::typesDirective(Node *n) {
262 return defaultHandler(n);
264 int Dispatcher::cDeclaration(Node *n) {
265 return defaultHandler(n);
267 int Dispatcher::externDeclaration(Node *n) {
268 return defaultHandler(n);
270 int Dispatcher::enumDeclaration(Node *n) {
271 return defaultHandler(n);
273 int Dispatcher::enumvalueDeclaration(Node *n) {
274 return defaultHandler(n);
276 int Dispatcher::enumforwardDeclaration(Node *n) {
277 return defaultHandler(n);
279 int Dispatcher::classDeclaration(Node *n) {
280 return defaultHandler(n);
282 int Dispatcher::templateDeclaration(Node *n) {
283 return defaultHandler(n);
285 int Dispatcher::classforwardDeclaration(Node *n) {
286 return defaultHandler(n);
288 int Dispatcher::constructorDeclaration(Node *n) {
289 return defaultHandler(n);
291 int Dispatcher::destructorDeclaration(Node *n) {
292 return defaultHandler(n);
294 int Dispatcher::accessDeclaration(Node *n) {
295 return defaultHandler(n);
297 int Dispatcher::usingDeclaration(Node *n) {
298 return defaultHandler(n);
300 int Dispatcher::namespaceDeclaration(Node *n) {
301 return defaultHandler(n);
306 Language::Language():
307 none_comparison(NewString("$arg != 0")),
308 director_ctor_code(NewString("")),
309 director_prot_ctor_code(0),
311 classtypes(NewHash()),
312 enumtypes(NewHash()),
317 argc_template_string = NewString("argc");
318 argv_template_string = NewString("argv[%d]");
320 /* Default director constructor code, passed to Swig_ConstructorToFunction */
321 Printv(director_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", "} else {\n", " $nondirector_new \n", "}\n", NIL);
324 Default director 'protected' constructor code, disabled by
325 default. Each language that needs it, has to define it.
327 director_prot_ctor_code = 0;
328 director_multiple_inheritance = 1;
329 director_language = 0;
334 Language::~Language() {
338 Delete(director_ctor_code);
339 Delete(none_comparison);
343 /* ----------------------------------------------------------------------
345 ---------------------------------------------------------------------- */
347 int Language::emit_one(Node *n) {
353 if (GetFlag(n, "feature:ignore")
354 && !Getattr(n, "feature:onlychildren"))
358 if (Getattr(n, "feature:extend"))
361 line_number = Getline(n);
362 input_file = Getfile(n);
365 symtab = Getattr(n,"symtab");
367 symtab = Swig_symbol_setscope(symtab);
370 ret = Dispatcher::emit_one(n);
373 Swig_symbol_setscope(symtab);
381 static Parm *nonvoid_parms(Parm *p) {
383 SwigType *t = Getattr(p, "type");
384 if (SwigType_type(t) == T_VOID)
390 /* -----------------------------------------------------------------------------
393 * Returns the alternative value type needed in C++ for class value
394 * types. When swig is not sure about using a plain $ltype value,
395 * since the class doesn't have a default constructor, or it can't be
396 * assigned, you will get back 'SwigValueWrapper<type >'.
398 * ----------------------------------------------------------------------------- */
400 SwigType *cplus_value_type(SwigType *t) {
401 return SwigType_alttype(t, 0);
404 static Node *first_nontemplate(Node *n) {
406 if (Strcmp(nodeType(n), "template") != 0)
408 n = Getattr(n, "sym:nextSibling");
415 /* --------------------------------------------------------------------------
418 * Handle swig pragma directives.
419 * -------------------------------------------------------------------------- */
421 void swig_pragma(char *lang, char *name, char *value) {
422 if (strcmp(lang, "swig") == 0) {
423 if ((strcmp(name, "make_default") == 0) || ((strcmp(name, "makedefault") == 0))) {
425 } else if ((strcmp(name, "no_default") == 0) || ((strcmp(name, "nodefault") == 0))) {
426 Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use %%nodefaultctor, %%nodefaultdtor instead.\n");
428 } else if (strcmp(name, "attributefunction") == 0) {
429 String *nvalue = NewString(value);
430 char *s = strchr(Char(nvalue), ':');
432 Swig_error(input_file, line_number, "Bad value for attributefunction. Expected \"fmtget:fmtset\".\n");
435 AttributeFunctionGet = NewString(Char(nvalue));
436 AttributeFunctionSet = NewString(s + 1);
439 } else if (strcmp(name, "noattributefunction") == 0) {
440 AttributeFunctionGet = 0;
441 AttributeFunctionSet = 0;
446 /* --------------------------------------------------------------------------
447 * use_naturalvar_mode()
448 * -------------------------------------------------------------------------- */
449 int use_naturalvar_mode(Node *n) {
450 if (Getattr(n, "unnamed"))
452 int nvar = naturalvar_mode || GetFlag(n, "feature:naturalvar");
454 /* look for feature in the class */
455 SwigType *ty = Getattr(n, "type");
456 SwigType *fullty = SwigType_typedef_resolve_all(ty);
457 if (SwigType_isclass(fullty)) {
459 SwigType *tys = SwigType_strip_qualifiers(fullty);
460 Swig_features_get(Swig_cparse_features(), 0, tys, 0, m);
461 nvar = GetFlag(m, "feature:naturalvar");
467 return nvar ? CWRAP_NATURAL_VAR : 0;
470 /* ----------------------------------------------------------------------
471 * Language::top() - Top of parsing tree
472 * ---------------------------------------------------------------------- */
474 int Language::top(Node *n) {
475 Node *mod = Getattr(n, "module");
477 Node *options = Getattr(mod, "options");
479 if (Getattr(options, "naturalvar")) {
482 if (Getattr(options, "nonaturalvar")) {
487 classhash = Getattr(n, "classes");
488 return emit_children(n);
491 /* ----------------------------------------------------------------------
492 * Language::extendDirective()
493 * ---------------------------------------------------------------------- */
495 int Language::extendDirective(Node *n) {
497 AccessMode oldmode = cplus_mode;
498 Extend = CWRAP_EXTEND;
504 cplus_mode = oldmode;
508 /* ----------------------------------------------------------------------
509 * Language::applyDirective()
510 * ---------------------------------------------------------------------- */
512 int Language::applyDirective(Node *n) {
514 Parm *pattern = Getattr(n, "pattern");
515 Node *c = firstChild(n);
517 Parm *apattern = Getattr(c, "pattern");
518 if (ParmList_len(pattern) != ParmList_len(apattern)) {
519 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));
521 if (!Swig_typemap_apply(pattern, apattern)) {
522 Swig_warning(WARN_TYPEMAP_APPLY_UNDEF, input_file, line_number, "Can't apply (%s). No typemaps are defined.\n", ParmList_str(pattern));
530 /* ----------------------------------------------------------------------
531 * Language::clearDirective()
532 * ---------------------------------------------------------------------- */
534 int Language::clearDirective(Node *n) {
536 for (p = firstChild(n); p; p = nextSibling(p)) {
537 ParmList *pattern = Getattr(p, "pattern");
538 Swig_typemap_clear_apply(pattern);
543 /* ----------------------------------------------------------------------
544 * Language::constantDirective()
545 * ---------------------------------------------------------------------- */
547 int Language::constantDirective(Node *n) {
549 if (CurrentClass && (cplus_mode != PUBLIC))
552 if (!GetFlag(n, "feature:allowexcept")) {
553 UnsetFlag(n, "feature:except");
555 if (Getattr(n, "feature:exceptvar")) {
556 Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
560 Swig_require("constantDirective", n, "name", "?value", NIL);
561 String *name = Getattr(n, "name");
562 String *value = Getattr(n, "value");
566 /* if (checkAttribute(n,"type","char")) {
567 value = NewString(value);
569 value = NewStringf("%(escape)s", value);
572 Setattr(n, "rawvalue", value);
573 value = NewStringf("%(escape)s", value);
575 Append(value, "\\0");
576 /* Printf(stdout,"'%s' = '%s'\n", name, value); */
578 Setattr(n, "value", value);
579 this->constantWrapper(n);
586 /* ----------------------------------------------------------------------
587 * Language::fragmentDirective()
588 * ---------------------------------------------------------------------- */
590 int Language::fragmentDirective(Node *n) {
591 Swig_fragment_register(n);
595 /* ----------------------------------------------------------------------
596 * Language::importDirective()
597 * ---------------------------------------------------------------------- */
599 int Language::importDirective(Node *n) {
600 int oldim = ImportMode;
601 ImportMode = IMPORT_MODE;
607 /* ----------------------------------------------------------------------
608 * Language::includeDirective()
609 * ---------------------------------------------------------------------- */
611 int Language::includeDirective(Node *n) {
616 /* ----------------------------------------------------------------------
617 * Language::insertDirective()
618 * ---------------------------------------------------------------------- */
620 int Language::insertDirective(Node *n) {
621 /* %insert directive */
622 if ((!ImportMode) || Getattr(n, "generated")) {
623 String *code = Getattr(n, "code");
624 String *section = Getattr(n, "section");
626 if (!section) { /* %{ ... %} */
627 f = Swig_filebyname("header");
629 f = Swig_filebyname(section);
632 Printf(f, "%s\n", code);
634 Swig_error(input_file, line_number, "Unknown target '%s' for %%insert directive.\n", section);
642 /* ----------------------------------------------------------------------
643 * Language::moduleDirective()
644 * ---------------------------------------------------------------------- */
646 int Language::moduleDirective(Node *n) {
648 /* %module directive */
652 /* ----------------------------------------------------------------------
653 * Language::nativeDirective()
654 * ---------------------------------------------------------------------- */
656 int Language::nativeDirective(Node *n) {
658 return nativeWrapper(n);
664 /* ----------------------------------------------------------------------
665 * Language::pragmaDirective()
666 * ---------------------------------------------------------------------- */
668 int Language::pragmaDirective(Node *n) {
669 /* %pragma directive */
671 String *lan = Getattr(n, "lang");
672 String *name = Getattr(n, "name");
673 String *value = Getattr(n, "value");
674 swig_pragma(Char(lan), Char(name), Char(value));
675 /* pragma(Char(lan),Char(name),Char(value)); */
681 /* ----------------------------------------------------------------------
682 * Language::typemapDirective()
683 * ---------------------------------------------------------------------- */
685 int Language::typemapDirective(Node *n) {
686 /* %typemap directive */
687 String *method = Getattr(n, "method");
688 String *code = Getattr(n, "code");
689 Parm *kwargs = Getattr(n, "kwargs");
690 Node *items = firstChild(n);
691 static int namewarn = 0;
694 if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) {
695 Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n");
697 Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\
698 For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\
699 $source by $input and $target by $1. For typemaps related to return values (out,\n\
700 argout,ret,except), replace $source by $1 and $target by $result. See the file\n\
701 Doc/Manual/Typemaps.html for complete details.\n");
706 if (Strcmp(method, "except") == 0) {
707 Swig_warning(WARN_DEPRECATED_EXCEPT_TM, Getfile(n), Getline(n), "%%typemap(except) is deprecated. Use the %%exception directive.\n");
710 if (Strcmp(method, "in") == 0) {
714 if (checkAttribute(k, "name", "numinputs")) {
715 if (!multiinput && (GetInt(k, "value") > 1)) {
716 Swig_error(Getfile(n), Getline(n), "Multiple-input typemaps (numinputs > 1) not supported by this target language module.\n");
725 Setattr(k, "name", "numinputs");
726 Setattr(k, "value", "1");
727 set_nextSibling(k, kwargs);
728 Setattr(n, "kwargs", k);
733 if (Strcmp(method, "ignore") == 0) {
734 Swig_warning(WARN_DEPRECATED_IGNORE_TM, Getfile(n), Getline(n), "%%typemap(ignore) has been replaced by %%typemap(in,numinputs=0).\n");
737 Append(method, "in");
739 Setattr(k, "name", "numinputs");
740 Setattr(k, "value", "0");
741 set_nextSibling(k, kwargs);
742 Setattr(n, "kwargs", k);
746 /* Replace $descriptor() macros */
749 Setfile(code, Getfile(n));
750 Setline(code, Getline(n));
751 Swig_cparse_replace_descriptor(code);
755 Parm *pattern = Getattr(items, "pattern");
756 Parm *parms = Getattr(items, "parms");
759 Swig_typemap_register(method, pattern, code, parms, kwargs);
761 Swig_typemap_clear(method, pattern);
763 items = nextSibling(items);
769 /* ----------------------------------------------------------------------
770 * Language::typemapcopyDirective()
771 * ---------------------------------------------------------------------- */
773 int Language::typemapcopyDirective(Node *n) {
774 String *method = Getattr(n, "method");
775 Parm *pattern = Getattr(n, "pattern");
776 Node *items = firstChild(n);
778 nsrc = ParmList_len(pattern);
780 ParmList *npattern = Getattr(items, "pattern");
781 if (nsrc != ParmList_len(npattern)) {
782 Swig_error(input_file, line_number, "Can't copy typemap. Number of types differ.\n");
784 if (Swig_typemap_copy(method, pattern, npattern) < 0) {
785 Swig_error(input_file, line_number, "Can't copy typemap.\n");
788 items = nextSibling(items);
793 /* ----------------------------------------------------------------------
794 * Language::typesDirective()
795 * ---------------------------------------------------------------------- */
797 int Language::typesDirective(Node *n) {
798 Parm *parms = Getattr(n, "parms");
799 String *convcode = Getattr(n, "convcode"); /* optional user supplied conversion code for custom casting */
801 SwigType *t = Getattr(parms, "type");
802 String *v = Getattr(parms, "value");
804 SwigType_remember(t);
806 if (SwigType_issimple(t)) {
807 SwigType_inherit(t, v, 0, convcode);
810 parms = nextSibling(parms);
815 /* ----------------------------------------------------------------------
816 * Language::cDeclaration()
817 * ---------------------------------------------------------------------- */
819 int Language::cDeclaration(Node *n) {
821 String *name = Getattr(n, "name");
822 String *symname = Getattr(n, "sym:name");
823 SwigType *type = Getattr(n, "type");
824 SwigType *decl = Getattr(n, "decl");
825 String *storage = Getattr(n, "storage");
828 SwigType *ty, *fullty;
830 /* discards nodes following the access control rules */
831 if (cplus_mode != PUBLIC || !is_public(n)) {
832 /* except for friends, they are not affected by access control */
833 int isfriend = storage && (Cmp(storage, "friend") == 0);
835 /* Check what the director needs. If the method is pure virtual, it is always needed.
836 * Also wrap non-virtual protected members if asked for (allprotected mode). */
837 if (!(directorsEnabled() && ((is_member_director(CurrentClass, n) && need_nonpublic_member(n)) || is_non_virtual_protected_access(n)))) {
840 // Prevent wrapping protected overloaded director methods more than once -
841 // This bit of code is only needed due to the cDeclaration call in classHandler()
842 String *wrapname = NewStringf("nonpublic_%s%s", symname, Getattr(n, "sym:overname"));
843 if (Getattr(CurrentClass, wrapname)) {
847 SetFlag(CurrentClass, wrapname);
852 if (Cmp(storage, "typedef") == 0) {
853 Swig_save("cDeclaration", n, "type", NIL);
854 SwigType *t = Copy(type);
856 SwigType_push(t, decl);
857 Setattr(n, "type", t);
864 /* If in import mode, we proceed no further */
868 /* If we're in extend mode and there is code, replace the $descriptor macros */
870 String *code = Getattr(n, "code");
872 Setfile(code, Getfile(n));
873 Setline(code, Getline(n));
874 Swig_cparse_replace_descriptor(code);
878 /* Overloaded symbol check */
879 over = Swig_symbol_isoverloaded(n);
882 over = first_nontemplate(over);
883 if (over && (over != n)) {
884 Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", Swig_name_decl(n));
885 Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", Swig_name_decl(over));
890 if (symname && !validIdentifier(symname)) {
891 Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname);
895 ty = NewString(type);
896 SwigType_push(ty, decl);
897 fullty = SwigType_typedef_resolve_all(ty);
898 if (SwigType_isfunction(fullty)) {
899 if (!SwigType_isfunction(ty)) {
903 ParmList *parms = SwigType_function_parms(ty);
904 Setattr(n, "parms", parms);
906 /* Transform the node into a 'function' node and emit */
908 f_header = Swig_filebyname("header");
912 if ((Cmp(storage, "extern") == 0) || (ForceExtern && !storage)) {
913 /* we don't need the 'extern' part in the C/C++ declaration,
914 and it produces some problems when namespace and SUN
917 Printf(f_header,"extern %s", SwigType_str(ty,name));
919 In fact generating extern declarations is quite error prone and is
920 no longer the default. Getting it right seems impossible with namespaces
921 and default arguments and when a method is declared with the various Windows
922 calling conventions - SWIG doesn't understand Windows (non standard) calling
923 conventions in the first place, so can't regenerate them.
925 String *str = SwigType_str(ty, name);
926 Printf(f_header, "%s", str);
929 DOH *t = Getattr(n, "throws");
931 Printf(f_header, " throw(");
933 Printf(f_header, "%s", Getattr(t, "type"));
936 Printf(f_header, ",");
938 Printf(f_header, ")");
941 Printf(f_header, ";\n");
942 } else if (Cmp(storage, "externc") == 0) {
943 /* here 'extern "C"' is needed */
944 String *str = SwigType_str(ty, name);
945 Printf(f_header, "extern \"C\" %s;\n", str);
951 /* This needs to check qualifiers */
952 if (SwigType_isqualifier(ty)) {
953 SwigType *qual = SwigType_pop(ty);
954 Setattr(n, "qualifier", qual);
957 Delete(SwigType_pop_function(ty));
959 Setattr(n, "type", ty);
960 if (GetFlag(n, "feature:onlychildren") && !GetFlag(n, "feature:ignore")) {
961 // Found an unignored templated method that has a an empty template instantiation (%template())
962 // Ignore it unless it has been %rename'd
963 if (Strncmp(symname, "__dummy_", 8) == 0) {
964 SetFlag(n, "feature:ignore");
965 Swig_warning(WARN_LANG_TEMPLATE_METHOD_IGNORE, input_file, line_number,
966 "%%template() contains no name. Template method ignored: %s\n", Swig_name_decl(n));
969 if (!GetFlag(n, "feature:ignore"))
971 Setattr(n, "type", type);
976 /* Some kind of variable declaration */
977 String *declaration = Copy(decl);
979 if (Getattr(n, "nested"))
980 SetFlag(n, "feature:immutable");
982 if ((Cmp(storage, "extern") == 0) || ForceExtern) {
983 f_header = Swig_filebyname("header");
986 String *str = SwigType_str(ty, name);
987 Printf(f_header, "extern %s;\n", str);
993 if (!SwigType_ismutable(ty)) {
994 SetFlag(n, "feature:immutable");
996 /* If an array and elements are const, then read-only */
997 if (SwigType_isarray(ty)) {
998 SwigType *tya = SwigType_array_type(ty);
999 if (SwigType_isconst(tya)) {
1000 SetFlag(n, "feature:immutable");
1005 Setattr(n, "type", ty);
1007 Setattr(n, "type", type);
1008 Setattr(n, "decl", declaration);
1016 /* ----------------------------------------------------------------------
1017 * Language::functionHandler()
1018 * ---------------------------------------------------------------------- */
1020 int Language::functionHandler(Node *n) {
1021 String *storage = Getattr(n, "storage");
1022 int isfriend = CurrentClass && Cmp(storage, "friend") == 0;
1023 int isstatic = CurrentClass && Cmp(storage, "static") == 0 && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"));
1024 Parm *p = Getattr(n, "parms");
1025 if (GetFlag(n, "feature:del")) {
1026 /* the method acts like a delete operator, ie, we need to disown the parameter */
1027 if (CurrentClass && !isstatic && !isfriend) {
1028 SetFlag(n, "feature:self:disown");
1031 SetFlag(p, "wrap:disown");
1034 if (!CurrentClass) {
1035 globalfunctionHandler(n);
1038 staticmemberfunctionHandler(n);
1039 } else if (isfriend) {
1040 globalfunctionHandler(n);
1042 Node *explicit_n = 0;
1043 if (directorsEnabled() && is_member_director(CurrentClass, n) && !extraDirectorProtectedCPPMethodsRequired()) {
1044 bool virtual_but_not_pure_virtual = (!(Cmp(storage, "virtual")) && (Cmp(Getattr(n, "value"), "0") != 0));
1045 if (virtual_but_not_pure_virtual) {
1046 // Add additional wrapper which makes an explicit call to the virtual method (ie not a virtual call)
1047 explicit_n = Copy(n);
1048 String *new_symname = Copy(Getattr(n, "sym:name"));
1049 String *suffix = Getattr(parentNode(n), "sym:name");
1050 Printv(new_symname, "SwigExplicit", suffix, NIL);
1051 Setattr(explicit_n, "sym:name", new_symname);
1052 Delattr(explicit_n, "storage");
1053 Delattr(explicit_n, "override");
1054 Delattr(explicit_n, "hides");
1055 SetFlag(explicit_n, "explicitcall");
1056 Setattr(n, "explicitcallnode", explicit_n);
1060 memberfunctionHandler(n);
1063 memberfunctionHandler(explicit_n);
1064 Delattr(explicit_n, "explicitcall");
1072 /* ----------------------------------------------------------------------
1073 * Language::globalfunctionHandler()
1074 * ---------------------------------------------------------------------- */
1076 int Language::globalfunctionHandler(Node *n) {
1078 Swig_require("globalfunctionHandler", n, "name", "sym:name", "type", "?parms", NIL);
1080 String *name = Getattr(n, "name");
1081 String *symname = Getattr(n, "sym:name");
1082 SwigType *type = Getattr(n, "type");
1083 ParmList *parms = Getattr(n, "parms");
1085 /* Check for callback mode */
1086 String *cb = GetFlagAttr(n, "feature:callback");
1088 String *cbname = Getattr(n, "feature:callback:name");
1090 cbname = NewStringf(cb, symname);
1091 Setattr(n, "feature:callback:name", cbname);
1094 callbackfunctionHandler(n);
1095 if (Cmp(cbname, symname) == 0) {
1102 Setattr(n, "parms", nonvoid_parms(parms));
1103 String *call = Swig_cfunction_call(name, parms);
1104 String *cres = Swig_cresult(type, "result", call);
1105 Setattr(n, "wrap:action", cres);
1114 /* ----------------------------------------------------------------------
1115 * Language::callbackfunctionHandler()
1116 * ---------------------------------------------------------------------- */
1118 int Language::callbackfunctionHandler(Node *n) {
1119 Swig_require("callbackfunctionHandler", n, "name", "*sym:name", "*type", "?value", NIL);
1120 String *symname = Getattr(n, "sym:name");
1121 String *type = Getattr(n, "type");
1122 String *name = Getattr(n, "name");
1123 String *parms = Getattr(n, "parms");
1124 String *cb = GetFlagAttr(n, "feature:callback");
1125 String *cbname = Getattr(n, "feature:callback:name");
1126 String *calltype = NewStringf("(%s (*)(%s))(%s)", SwigType_str(type, 0), ParmList_str(parms), SwigType_namestr(name));
1127 SwigType *cbty = Copy(type);
1128 SwigType_add_function(cbty, parms);
1129 SwigType_add_pointer(cbty);
1132 cbname = NewStringf(cb, symname);
1133 Setattr(n, "feature:callback:name", cbname);
1136 Setattr(n, "sym:name", cbname);
1137 Setattr(n, "type", cbty);
1138 Setattr(n, "value", calltype);
1140 Node *ns = Getattr(symbols, cbname);
1151 /* ----------------------------------------------------------------------
1152 * Language::memberfunctionHandler()
1153 * ---------------------------------------------------------------------- */
1155 int Language::memberfunctionHandler(Node *n) {
1157 Swig_require("memberfunctionHandler", n, "*name", "*sym:name", "*type", "?parms", "?value", NIL);
1159 String *storage = Getattr(n, "storage");
1160 String *name = Getattr(n, "name");
1161 String *symname = Getattr(n, "sym:name");
1162 SwigType *type = Getattr(n, "type");
1163 String *value = Getattr(n, "value");
1164 ParmList *parms = Getattr(n, "parms");
1165 String *cb = GetFlagAttr(n, "feature:callback");
1167 if (Cmp(storage, "virtual") == 0) {
1168 if (Cmp(value, "0") == 0) {
1169 IsVirtual = PURE_VIRTUAL;
1171 IsVirtual = PLAIN_VIRTUAL;
1177 Node *cbn = NewHash();
1178 String *cbname = Getattr(n, "feature:callback:name");
1180 cbname = NewStringf(cb, symname);
1183 SwigType *cbty = Copy(type);
1184 SwigType_add_function(cbty, parms);
1185 SwigType_add_memberpointer(cbty, ClassName);
1186 String *cbvalue = NewStringf("&%s::%s", ClassName, name);
1187 Setattr(cbn, "sym:name", cbname);
1188 Setattr(cbn, "type", cbty);
1189 Setattr(cbn, "value", cbvalue);
1190 Setattr(cbn, "name", name);
1192 memberconstantHandler(cbn);
1193 Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname));
1200 if (Cmp(cbname, symname) == 0) {
1206 String *fname = Swig_name_member(ClassPrefix, symname);
1207 if (Extend && SmartPointer) {
1208 if (!Getattr(n, "classname")) {
1209 Setattr(n, "classname", Getattr(CurrentClass, "allocate:smartpointerbase"));
1212 // Set up the type for the cast to this class for use when wrapping const director (virtual) methods.
1213 // Note: protected director methods or when allprotected mode turned on.
1214 String *director_type = 0;
1215 if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall") || is_non_virtual_protected_access(n))) {
1216 director_type = Copy(DirectorClassName);
1217 String *qualifier = Getattr(n, "qualifier");
1219 SwigType_push(director_type, qualifier);
1220 SwigType_add_pointer(director_type);
1223 int DirectorExtraCall = 0;
1224 if (directorsEnabled() && is_member_director(CurrentClass, n) && !SmartPointer)
1225 if (extraDirectorProtectedCPPMethodsRequired())
1226 DirectorExtraCall = CWRAP_DIRECTOR_TWO_CALLS;
1228 if (GetFlag(n, "explicitcall"))
1229 DirectorExtraCall = CWRAP_DIRECTOR_ONE_CALL;
1231 Swig_MethodToFunction(n, ClassType, Getattr(n, "template") ? SmartPointer : Extend | SmartPointer | DirectorExtraCall, director_type,
1232 is_member_director(CurrentClass, n));
1233 Setattr(n, "sym:name", fname);
1237 Delete(director_type);
1243 /* ----------------------------------------------------------------------
1244 * Language::staticmemberfunctionHandler()
1245 * ---------------------------------------------------------------------- */
1247 int Language::staticmemberfunctionHandler(Node *n) {
1249 Swig_require("staticmemberfunctionHandler", n, "*name", "*sym:name", "*type", NIL);
1250 Swig_save("staticmemberfunctionHandler", n, "storage", NIL);
1251 String *name = Getattr(n, "name");
1252 String *symname = Getattr(n, "sym:name");
1253 SwigType *type = Getattr(n, "type");
1254 ParmList *parms = Getattr(n, "parms");
1255 String *cb = GetFlagAttr(n, "feature:callback");
1256 String *cname, *mrename;
1259 Node *sb = Getattr(n, "cplus:staticbase");
1260 String *sname = Getattr(sb, "name");
1261 if (is_non_virtual_protected_access(n))
1262 cname = NewStringf("%s::%s", DirectorClassName, name);
1264 cname = NewStringf("%s::%s", sname, name);
1266 String *mname = Swig_name_mangle(ClassName);
1267 cname = Swig_name_member(mname, name);
1270 mrename = Swig_name_member(ClassPrefix, symname);
1273 String *code = Getattr(n, "code");
1274 String *defaultargs = Getattr(n, "defaultargs");
1275 String *mangled = Swig_name_mangle(mrename);
1279 if (Getattr(n, "sym:overloaded") && code) {
1280 Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname"));
1283 if (!defaultargs && code) {
1284 /* Hmmm. An added static member. We have to create a little wrapper for this */
1285 Swig_add_extension_code(n, cname, parms, type, code, CPlusPlus, 0);
1289 Setattr(n, "name", cname);
1290 Setattr(n, "sym:name", mrename);
1293 String *cbname = NewStringf(cb, symname);
1294 Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname));
1295 Setattr(n, "feature:callback:staticname", name);
1297 Delattr(n, "storage");
1299 globalfunctionHandler(n);
1307 /* ----------------------------------------------------------------------
1308 * Language::variableHandler()
1309 * ---------------------------------------------------------------------- */
1311 int Language::variableHandler(Node *n) {
1313 /* If not a smart-pointer access or added method. We clear
1314 feature:except. There is no way C++ or C would throw
1315 an exception merely for accessing a member data.
1317 Caveat: Some compilers seem to route attribute access through
1318 methods which can generate exceptions. The feature:allowexcept
1319 allows this. Also, the feature:exceptvar can be used to match
1322 if (!(Extend | SmartPointer)) {
1323 if (!GetFlag(n, "feature:allowexcept")) {
1324 UnsetFlag(n, "feature:except");
1326 if (Getattr(n, "feature:exceptvar")) {
1327 Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
1331 if (!CurrentClass) {
1332 globalvariableHandler(n);
1334 String *storage = Getattr(n, "storage");
1335 Swig_save("variableHandler", n, "feature:immutable", NIL);
1337 /* If a smart-pointer and it's a constant access, we have to set immutable */
1338 if (Getattr(CurrentClass, "allocate:smartpointerconst")) {
1339 SetFlag(n, "feature:immutable");
1342 if ((Cmp(storage, "static") == 0) && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"))) {
1343 staticmembervariableHandler(n);
1345 membervariableHandler(n);
1352 /* ----------------------------------------------------------------------
1353 * Language::globalvariableHandler()
1354 * ---------------------------------------------------------------------- */
1356 int Language::globalvariableHandler(Node *n) {
1361 /* ----------------------------------------------------------------------
1362 * Language::membervariableHandler()
1363 * ---------------------------------------------------------------------- */
1365 int Language::membervariableHandler(Node *n) {
1367 Swig_require("membervariableHandler", n, "*name", "*sym:name", "*type", NIL);
1368 Swig_save("membervariableHandler", n, "parms", NIL);
1370 String *name = Getattr(n, "name");
1371 String *symname = Getattr(n, "sym:name");
1372 SwigType *type = Getattr(n, "type");
1374 if (!AttributeFunctionGet) {
1375 String *mname = Swig_name_member(ClassPrefix, symname);
1376 String *mrename_get = Swig_name_get(mname);
1377 String *mrename_set = Swig_name_set(mname);
1380 /* Create a function to set the value of the variable */
1382 int assignable = is_assignable(n);
1385 if (Getattr(CurrentClass, "allocate:smartpointerconst")) {
1391 int make_set_wrapper = 1;
1396 if (checkAttribute(n, "storage", "static")) {
1397 Node *sn = Getattr(n, "cplus:staticbase");
1398 String *base = Getattr(sn, "name");
1399 target = NewStringf("%s::%s", base, name);
1401 String *pname = Swig_cparm_name(0, 0);
1402 target = NewStringf("(*%s)->%s", pname, name);
1406 String *pname = is_non_virtual_protected_access(n) ? NewString("darg") : Swig_cparm_name(0, 0);
1407 target = NewStringf("%s->%s", pname, name);
1411 target = NewStringf("$extendgetcall"); // member variable access expanded later
1413 tm = Swig_typemap_lookup("memberin", n, target, 0);
1414 int flags = Extend | SmartPointer | use_naturalvar_mode(n);
1415 if (is_non_virtual_protected_access(n))
1416 flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
1419 Swig_MembersetToFunction(n, ClassType, flags, &call);
1420 Setattr(n, "memberset", "1");
1423 if (SwigType_isarray(type)) {
1424 Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
1425 make_set_wrapper = 0;
1428 String *pname0 = Swig_cparm_name(0, 0);
1429 String *pname1 = Swig_cparm_name(0, 1);
1430 Replace(tm, "$source", pname1, DOH_REPLACE_ANY);
1431 Replace(tm, "$target", target, DOH_REPLACE_ANY);
1432 Replace(tm, "$input", pname1, DOH_REPLACE_ANY);
1433 Replace(tm, "$self", pname0, DOH_REPLACE_ANY);
1434 Replace(tm, "$extendgetcall", call, DOH_REPLACE_ANY);
1435 Setattr(n, "wrap:action", tm);
1443 if (make_set_wrapper) {
1444 Setattr(n, "sym:name", mrename_set);
1447 SetFlag(n, "feature:immutable");
1449 /* Restore parameters */
1450 Setattr(n, "type", type);
1451 Setattr(n, "name", name);
1452 Setattr(n, "sym:name", symname);
1454 /* Delete all attached typemaps and typemap attributes */
1456 for (ki = First(n); ki.key; ki = Next(ki)) {
1457 if (Strncmp(ki.key, "tmap:", 5) == 0)
1461 /* Emit get function */
1463 int flags = Extend | SmartPointer | use_naturalvar_mode(n);
1464 if (is_non_virtual_protected_access(n))
1465 flags = flags | CWRAP_ALL_PROTECTED_ACCESS;
1466 Swig_MembergetToFunction(n, ClassType, flags);
1467 Setattr(n, "sym:name", mrename_get);
1468 Setattr(n, "memberget", "1");
1471 Delete(mrename_get);
1472 Delete(mrename_set);
1476 /* This code is used to support the attributefunction directive
1477 where member variables are converted automagically to
1478 accessor functions */
1484 p = NewParm(type, 0);
1485 gname = NewStringf(AttributeFunctionGet, symname);
1487 ActionFunc = Copy(Swig_cmemberget_call(name, type));
1488 cpp_member_func(Char(gname), Char(gname), type, 0);
1491 String *cname = Swig_name_get(name);
1492 cpp_member_func(Char(cname), Char(gname), type, 0);
1496 if (!GetFlag(n, "feature:immutable")) {
1497 gname = NewStringf(AttributeFunctionSet, symname);
1498 vty = NewString("void");
1500 ActionFunc = Copy(Swig_cmemberset_call(name, type));
1501 cpp_member_func(Char(gname), Char(gname), vty, p);
1504 String *cname = Swig_name_set(name);
1505 cpp_member_func(Char(cname), Char(gname), vty, p);
1517 /* ----------------------------------------------------------------------
1518 * Language::staticmembervariableHandler()
1519 * ---------------------------------------------------------------------- */
1521 int Language::staticmembervariableHandler(Node *n) {
1522 Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL);
1523 String *value = Getattr(n, "value");
1524 String *classname = !SmartPointer ? (is_non_virtual_protected_access(n) ? DirectorClassName : ClassName) : Getattr(CurrentClass, "allocate:smartpointerbase");
1526 if (!value || !Getattr(n, "hasconsttype")) {
1527 String *name = Getattr(n, "name");
1528 String *symname = Getattr(n, "sym:name");
1529 String *cname, *mrename;
1531 /* Create the variable name */
1532 mrename = Swig_name_member(ClassPrefix, symname);
1533 cname = NewStringf("%s::%s", classname, name);
1535 Setattr(n, "sym:name", mrename);
1536 Setattr(n, "name", cname);
1538 /* Wrap as an ordinary global variable */
1545 /* This is a C++ static member declaration with an initializer and it's const.
1546 Certain C++ compilers optimize this out so that there is no linkage to a
1547 memory address. Example:
1551 static const int x = 3;
1554 Some discussion of this in section 9.4 of the C++ draft standard.
1556 Also, we have to manage the case:
1561 static const int x = 3;
1565 in which there's no actual Foo::x variable to refer to. In this case,
1566 the best we can do is to wrap the given value verbatim.
1570 String *name = Getattr(n, "name");
1571 String *cname = NewStringf("%s::%s", classname, name);
1573 /* the variable is a synthesized one.
1574 There's nothing we can do; we just keep the given value */
1576 /* we refer to the value as Foo::x */
1577 String *value = SwigType_namestr(cname);
1578 Setattr(n, "value", value);
1581 SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n, "type"));
1582 SwigType *t2 = SwigType_strip_qualifiers(t1);
1583 Setattr(n, "type", t2);
1586 SetFlag(n, "wrappedasconstant");
1587 memberconstantHandler(n);
1596 /* ----------------------------------------------------------------------
1597 * Language::externDeclaration()
1598 * ---------------------------------------------------------------------- */
1600 int Language::externDeclaration(Node *n) {
1601 return emit_children(n);
1604 /* ----------------------------------------------------------------------
1605 * Language::enumDeclaration()
1606 * ---------------------------------------------------------------------- */
1608 int Language::enumDeclaration(Node *n) {
1615 /* ----------------------------------------------------------------------
1616 * Language::enumvalueDeclaration()
1617 * ---------------------------------------------------------------------- */
1619 int Language::enumvalueDeclaration(Node *n) {
1620 if (CurrentClass && (cplus_mode != PUBLIC))
1623 Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL);
1624 String *value = Getattr(n, "value");
1625 String *name = Getattr(n, "name");
1629 tmpValue = NewString(value);
1631 tmpValue = NewString(name);
1632 Setattr(n, "value", tmpValue);
1634 if (!CurrentClass || !cparse_cplusplus) {
1635 Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */
1638 memberconstantHandler(n);
1646 /* ----------------------------------------------------------------------
1647 * Language::enumforwardDeclaration()
1648 * ---------------------------------------------------------------------- */
1650 int Language::enumforwardDeclaration(Node *n) {
1655 /* -----------------------------------------------------------------------------
1656 * Language::memberconstantHandler()
1657 * ----------------------------------------------------------------------------- */
1659 int Language::memberconstantHandler(Node *n) {
1661 Swig_require("memberconstantHandler", n, "*name", "*sym:name", "value", NIL);
1663 if (!GetFlag(n, "feature:allowexcept")) {
1664 UnsetFlag(n, "feature:except");
1666 if (Getattr(n, "feature:exceptvar")) {
1667 Setattr(n, "feature:except", Getattr(n, "feature:exceptvar"));
1670 String *name = Getattr(n, "name");
1671 String *symname = Getattr(n, "sym:name");
1672 String *value = Getattr(n, "value");
1674 String *mrename = Swig_name_member(ClassPrefix, symname);
1675 Setattr(n, "sym:name", mrename);
1677 String *new_name = 0;
1679 new_name = Copy(value);
1681 new_name = NewStringf("%s::%s", is_non_virtual_protected_access(n) ? DirectorClassName : ClassName, name);
1682 Setattr(n, "name", new_name);
1691 /* ----------------------------------------------------------------------
1692 * Language::typedefHandler()
1693 * ---------------------------------------------------------------------- */
1695 int Language::typedefHandler(Node *n) {
1696 /* since this is a recurring issue, we are going to remember the
1697 typedef pointer, if already it is not a pointer or reference, as
1703 see director_basic.i for example.
1705 SwigType *name = Getattr(n, "name");
1706 SwigType *decl = Getattr(n, "decl");
1707 if (!SwigType_ispointer(decl) && !SwigType_isreference(decl)) {
1708 SwigType *pname = Copy(name);
1709 SwigType_add_pointer(pname);
1710 SwigType_remember(pname);
1716 /* ----------------------------------------------------------------------
1717 * Language::classDirectorMethod()
1718 * ---------------------------------------------------------------------- */
1720 int Language::classDirectorMethod(Node *n, Node *parent, String *super) {
1727 /* ----------------------------------------------------------------------
1728 * Language::classDirectorConstructor()
1729 * ---------------------------------------------------------------------- */
1731 int Language::classDirectorConstructor(Node *n) {
1736 /* ----------------------------------------------------------------------
1737 * Language::classDirectorDefaultConstructor()
1738 * ---------------------------------------------------------------------- */
1740 int Language::classDirectorDefaultConstructor(Node *n) {
1745 static String *vtable_method_id(Node *n) {
1746 String *nodeType = Getattr(n, "nodeType");
1747 int is_destructor = (Cmp(nodeType, "destructor") == 0);
1750 String *name = Getattr(n, "name");
1751 String *decl = Getattr(n, "decl");
1752 String *local_decl = SwigType_typedef_resolve_all(decl);
1753 String *tmp = SwigType_pop_function(local_decl);
1756 Node *method_id = NewStringf("%s|%s", name, local_decl);
1762 /* ----------------------------------------------------------------------
1763 * Language::unrollVirtualMethods()
1764 * ---------------------------------------------------------------------- */
1765 int Language::unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase) {
1770 bool first_base = false;
1771 // recurse through all base classes to build the vtable
1772 List *bl = Getattr(n, "bases");
1775 for (bi = First(bl); bi.item; bi = Next(bi)) {
1776 if (first_base && !director_multiple_inheritance)
1778 unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor);
1782 // recurse through all protected base classes to build the vtable, as needed
1783 bl = Getattr(n, "protectedbases");
1786 for (bi = First(bl); bi.item; bi = Next(bi)) {
1787 if (first_base && !director_multiple_inheritance)
1789 unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor, 1);
1793 // find the methods that need directors
1794 classname = Getattr(n, "name");
1795 for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
1796 /* we only need to check the virtual members */
1797 if (!checkAttribute(ni, "storage", "virtual"))
1799 nodeType = Getattr(ni, "nodeType");
1800 /* we need to add methods(cdecl) and destructor (to check for throw decl) */
1801 int is_destructor = (Cmp(nodeType, "destructor") == 0);
1802 if ((Cmp(nodeType, "cdecl") == 0) || is_destructor) {
1803 decl = Getattr(ni, "decl");
1804 /* extra check for function type and proper access */
1805 if (SwigType_isfunction(decl) && (((!protectedbase || dirprot_mode()) && is_public(ni)) || need_nonpublic_member(ni))) {
1806 String *name = Getattr(ni, "name");
1807 Node *method_id = is_destructor ? NewStringf("~destructor") : vtable_method_id(ni);
1808 /* Make sure that the new method overwrites the existing: */
1810 const int DO_NOT_REPLACE = -1;
1811 int replace = DO_NOT_REPLACE;
1812 for (int i = 0; i < len; i++) {
1813 Node *item = Getitem(vm, i);
1814 String *check_vmid = Getattr(item, "vmid");
1816 if (Strcmp(method_id, check_vmid) == 0) {
1821 /* filling a new method item */
1822 String *fqdname = NewStringf("%s::%s", classname, name);
1823 Hash *item = NewHash();
1824 Setattr(item, "fqdname", fqdname);
1827 /* Store the complete return type - needed for non-simple return types (pointers, references etc.) */
1828 SwigType *ty = NewString(Getattr(m, "type"));
1829 SwigType_push(ty, decl);
1830 if (SwigType_isqualifier(ty)) {
1831 Delete(SwigType_pop(ty));
1833 Delete(SwigType_pop_function(ty));
1834 Setattr(m, "returntype", ty);
1836 String *mname = NewStringf("%s::%s", Getattr(parent, "name"), name);
1837 /* apply the features of the original method found in the base class */
1838 Swig_features_get(Swig_cparse_features(), 0, mname, Getattr(m, "decl"), m);
1839 Setattr(item, "methodNode", m);
1840 Setattr(item, "vmid", method_id);
1841 if (replace == DO_NOT_REPLACE)
1844 Setitem(vm, replace, item);
1848 if (is_destructor) {
1849 virtual_destructor = 1;
1855 We delete all the nodirector methods. This prevents the
1856 generation of 'empty' director classes.
1858 But this has to be done outside the previous 'for'
1859 an the recursive loop!.
1863 for (int i = 0; i < len; i++) {
1864 Node *item = Getitem(vm, i);
1865 Node *m = Getattr(item, "methodNode");
1866 /* retrieve the director features */
1867 int mdir = GetFlag(m, "feature:director");
1868 int mndir = GetFlag(m, "feature:nodirector");
1869 /* 'nodirector' has precedence over 'director' */
1870 int dir = (mdir || mndir) ? (mdir && !mndir) : 1;
1871 /* check if the method was found only in a base class */
1872 Node *p = Getattr(m, "parentNode");
1875 Setattr(c, "parentNode", n);
1876 int cdir = GetFlag(c, "feature:director");
1877 int cndir = GetFlag(c, "feature:nodirector");
1878 dir = (cdir || cndir) ? (cdir && !cndir) : dir;
1882 /* be sure the 'nodirector' feature is disabled */
1884 Delattr(m, "feature:nodirector");
1886 /* or just delete from the vm, since is not a director method */
1898 /* ----------------------------------------------------------------------
1899 * Language::classDirectorDisown()
1900 * ---------------------------------------------------------------------- */
1902 int Language::classDirectorDisown(Node *n) {
1903 Node *disown = NewHash();
1905 String *symname = Getattr(n, "sym:name");
1906 mrename = Swig_name_disown(symname); //Getattr(n, "name"));
1907 String *type = NewString(ClassType);
1908 String *name = NewString("self");
1909 SwigType_add_pointer(type);
1910 Parm *p = NewParm(type, name);
1913 type = NewString("void");
1914 String *action = NewString("");
1915 Printv(action, "{\n", "Swig::Director *director = dynamic_cast<Swig::Director *>(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL);
1916 Setattr(disown, "wrap:action", action);
1917 Setattr(disown, "name", mrename);
1918 Setattr(disown, "sym:name", mrename);
1919 Setattr(disown, "type", type);
1920 Setattr(disown, "parms", p);
1926 functionWrapper(disown);
1931 /* ----------------------------------------------------------------------
1932 * Language::classDirectorConstructors()
1933 * ---------------------------------------------------------------------- */
1935 int Language::classDirectorConstructors(Node *n) {
1938 Node *parent = Swig_methodclass(n);
1939 int default_ctor = Getattr(parent, "allocate:default_constructor") ? 1 : 0;
1940 int protected_ctor = 0;
1941 int constructor = 0;
1943 /* emit constructors */
1944 for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
1945 nodeType = Getattr(ni, "nodeType");
1946 if (Cmp(nodeType, "constructor") == 0) {
1947 Parm *parms = Getattr(ni, "parms");
1948 if (is_public(ni)) {
1949 /* emit public constructor */
1950 classDirectorConstructor(ni);
1953 default_ctor = !ParmList_numrequired(parms);
1955 /* emit protected constructor if needed */
1956 if (need_nonpublic_ctor(ni)) {
1957 classDirectorConstructor(ni);
1961 default_ctor = !ParmList_numrequired(parms);
1966 /* emit default constructor if needed */
1968 if (!default_ctor) {
1969 /* we get here because the class has no public, protected or
1970 default constructor, therefore, the director class can't be
1971 created, ie, is kind of abstract. */
1972 Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n), "Director class '%s' can't be constructed\n", SwigType_namestr(Getattr(n, "name")));
1975 classDirectorDefaultConstructor(n);
1978 /* this is just to support old java behavior, ie, the default
1979 constructor is always emitted, even when protected, and not
1980 needed, since there is a public constructor already defined.
1982 (scottm) This code is needed here to make the director_abstract +
1983 test generate compileable code (Example2 in director_abastract.i).
1985 (mmatus) This is very strange, since swig compiled with gcc3.2.3
1986 doesn't need it here....
1988 if (!default_ctor && !protected_ctor) {
1989 if (Getattr(parent, "allocate:default_base_constructor")) {
1990 classDirectorDefaultConstructor(n);
1997 /* ----------------------------------------------------------------------
1998 * Language::classDirectorMethods()
1999 * ---------------------------------------------------------------------- */
2001 int Language::classDirectorMethods(Node *n) {
2002 Node *vtable = Getattr(n, "vtable");
2004 int len = Len(vtable);
2005 for (int i = 0; i < len; i++) {
2006 Node *item = Getitem(vtable, i);
2007 String *method = Getattr(item, "methodNode");
2008 String *fqdname = Getattr(item, "fqdname");
2009 if (GetFlag(method, "feature:nodirector"))
2012 String *type = Getattr(method, "nodeType");
2013 if (!Cmp(type, "destructor")) {
2014 classDirectorDestructor(method);
2016 if (classDirectorMethod(method, n, fqdname) == SWIG_OK) {
2017 Setattr(item, "director", "1");
2025 /* ----------------------------------------------------------------------
2026 * Language::classDirectorInit()
2027 * ---------------------------------------------------------------------- */
2029 int Language::classDirectorInit(Node *n) {
2034 /* ----------------------------------------------------------------------
2035 * Language::classDirectorDestructor()
2036 * ---------------------------------------------------------------------- */
2038 int Language::classDirectorDestructor(Node *n) {
2040 Always emit the virtual destructor in the declaration and in the
2041 compilation unit. Been explicit here can't make any damage, and
2042 can solve some nasty C++ compiler problems.
2044 File *f_directors = Swig_filebyname("director");
2045 File *f_directors_h = Swig_filebyname("director_h");
2046 if (Getattr(n, "throw")) {
2047 Printf(f_directors_h, " virtual ~%s() throw ();\n", DirectorClassName);
2048 Printf(f_directors, "%s::~%s() throw () {\n}\n\n", DirectorClassName, DirectorClassName);
2050 Printf(f_directors_h, " virtual ~%s();\n", DirectorClassName);
2051 Printf(f_directors, "%s::~%s() {\n}\n\n", DirectorClassName, DirectorClassName);
2056 /* ----------------------------------------------------------------------
2057 * Language::classDirectorEnd()
2058 * ---------------------------------------------------------------------- */
2060 int Language::classDirectorEnd(Node *n) {
2065 /* ----------------------------------------------------------------------
2066 * Language::classDirector()
2067 * ---------------------------------------------------------------------- */
2069 int Language::classDirector(Node *n) {
2070 Node *module = Getattr(n, "module");
2071 String *classtype = Getattr(n, "classtype");
2072 Hash *directormap = 0;
2074 directormap = Getattr(module, "wrap:directormap");
2075 if (directormap == 0) {
2076 directormap = NewHash();
2077 Setattr(module, "wrap:directormap", directormap);
2080 List *vtable = NewList();
2081 int virtual_destructor = 0;
2082 unrollVirtualMethods(n, n, vtable, 0, virtual_destructor);
2084 // Emit all the using base::member statements for non virtual members (allprotected mode)
2086 String *using_protected_members_code = NewString("");
2087 for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
2088 Node *nodeType = Getattr(ni, "nodeType");
2089 bool cdeclaration = (Cmp(nodeType, "cdecl") == 0);
2090 if (cdeclaration && !GetFlag(ni, "feature:ignore")) {
2091 if (is_non_virtual_protected_access(ni)) {
2092 Node *overloaded = Getattr(ni, "sym:overloaded");
2093 // emit the using base::member statement (but only once if the method is overloaded)
2094 if (!overloaded || (overloaded && (overloaded == ni)))
2095 Printf(using_protected_members_code, " using %s::%s;\n", SwigType_namestr(ClassName), Getattr(ni, "name"));
2100 if (virtual_destructor || Len(vtable) > 0) {
2101 if (!virtual_destructor) {
2102 String *classtype = Getattr(n, "classtype");
2103 Swig_warning(WARN_LANG_DIRECTOR_VDESTRUCT, input_file, line_number, "Director base class %s has no virtual destructor.\n", classtype);
2106 Setattr(n, "vtable", vtable);
2107 if (directormap != 0) {
2108 Setattr(directormap, classtype, n);
2110 classDirectorInit(n);
2111 classDirectorConstructors(n);
2112 classDirectorMethods(n);
2114 File *f_directors_h = Swig_filebyname("director_h");
2115 Printv(f_directors_h, using_protected_members_code, NIL);
2117 classDirectorEnd(n);
2120 Delete(using_protected_members_code);
2124 /* ----------------------------------------------------------------------
2125 * Language::classDeclaration()
2126 * ---------------------------------------------------------------------- */
2128 static void addCopyConstructor(Node *n) {
2129 Node *cn = NewHash();
2130 set_nodeType(cn, "constructor");
2131 Setattr(cn, "access", "public");
2132 Setfile(cn, Getfile(n));
2133 Setline(cn, Getline(n));
2135 String *cname = Getattr(n, "name");
2136 SwigType *type = Copy(cname);
2137 String *last = Swig_scopename_last(cname);
2138 String *name = NewStringf("%s::%s", cname, last);
2139 String *cc = NewStringf("r.q(const).%s", type);
2140 String *decl = NewStringf("f(%s).", cc);
2141 String *csymname = Getattr(n, "sym:name");
2142 String *oldname = csymname;
2144 if (Getattr(n, "allocate:has_constructor")) {
2145 // to work properly with '%rename Class', we must look
2146 // for any other constructor in the class, which has not been
2147 // renamed, and use its name as oldname.
2149 for (c = firstChild(n); c; c = nextSibling(c)) {
2150 const char *tag = Char(nodeType(c));
2151 if (strcmp(tag, "constructor") == 0) {
2152 String *cname = Getattr(c, "name");
2153 String *csname = Getattr(c, "sym:name");
2154 String *clast = Swig_scopename_last(cname);
2155 if (Equal(csname, clast)) {
2163 String *symname = Swig_name_make(cn, cname, last, decl, oldname);
2164 if (Strcmp(symname, "$ignore") != 0) {
2166 symname = Copy(csymname);
2168 Parm *p = NewParm(cc, "other");
2170 Setattr(cn, "name", name);
2171 Setattr(cn, "sym:name", symname);
2172 SetFlag(cn, "feature:new");
2173 Setattr(cn, "decl", decl);
2174 Setattr(cn, "parentNode", n);
2175 Setattr(cn, "parms", p);
2176 Setattr(cn, "copy_constructor", "1");
2178 Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
2179 Node *on = Swig_symbol_add(symname, cn);
2180 Swig_symbol_setscope(oldscope);
2181 Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
2184 Node *access = NewHash();
2185 set_nodeType(access, "access");
2186 Setattr(access, "kind", "public");
2187 appendChild(n, access);
2189 Setattr(n, "has_copy_constructor", "1");
2190 Setattr(n, "copy_constructor_decl", decl);
2191 Setattr(n, "allocate:copy_constructor", "1");
2202 static void addDefaultConstructor(Node *n) {
2203 Node *cn = NewHash();
2204 set_nodeType(cn, "constructor");
2205 Setattr(cn, "access", "public");
2206 Setfile(cn, Getfile(n));
2207 Setline(cn, Getline(n));
2209 String *cname = Getattr(n, "name");
2210 String *last = Swig_scopename_last(cname);
2211 String *name = NewStringf("%s::%s", cname, last);
2212 String *decl = NewString("f().");
2213 String *csymname = Getattr(n, "sym:name");
2214 String *oldname = csymname;
2215 String *symname = Swig_name_make(cn, cname, last, decl, oldname);
2216 if (Strcmp(symname, "$ignore") != 0) {
2218 symname = Copy(csymname);
2221 Setattr(cn, "name", name);
2222 Setattr(cn, "sym:name", symname);
2223 SetFlag(cn, "feature:new");
2224 Setattr(cn, "decl", decl);
2225 Setattr(cn, "parentNode", n);
2226 Setattr(cn, "default_constructor", "1");
2228 Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
2229 Node *on = Swig_symbol_add(symname, cn);
2230 Swig_symbol_setscope(oldscope);
2231 Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
2234 Node *access = NewHash();
2235 set_nodeType(access, "access");
2236 Setattr(access, "kind", "public");
2237 appendChild(n, access);
2239 Setattr(n, "has_default_constructor", "1");
2240 Setattr(n, "allocate:default_constructor", "1");
2251 static void addDestructor(Node *n) {
2252 Node *cn = NewHash();
2253 set_nodeType(cn, "destructor");
2254 Setattr(cn, "access", "public");
2255 Setfile(cn, Getfile(n));
2256 Setline(cn, Getline(n));
2258 String *cname = Getattr(n, "name");
2259 String *last = Swig_scopename_last(cname);
2260 Insert(last, 0, "~");
2261 String *name = NewStringf("%s::%s", cname, last);
2262 String *decl = NewString("f().");
2263 String *symname = Swig_name_make(cn, cname, last, decl, 0);
2264 if (Strcmp(symname, "$ignore") != 0) {
2266 symname = NewStringf("~%s", Getattr(n, "sym:name"));
2269 Setattr(cn, "name", name);
2270 Setattr(cn, "sym:name", symname);
2271 Setattr(cn, "decl", "f().");
2272 Setattr(cn, "parentNode", n);
2274 Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab"));
2275 Node *on = Swig_symbol_add(symname, cn);
2276 Swig_symbol_setscope(oldscope);
2277 Swig_features_get(Swig_cparse_features(), 0, name, decl, cn);
2280 Node *access = NewHash();
2281 set_nodeType(access, "access");
2282 Setattr(access, "kind", "public");
2283 appendChild(n, access);
2285 Setattr(n, "has_destructor", "1");
2286 Setattr(n, "allocate:destructor", "1");
2297 int Language::classDeclaration(Node *n) {
2298 String *ochildren = Getattr(n, "feature:onlychildren");
2300 Setattr(n, "feature:emitonlychildren", ochildren);
2302 Delattr(n, "feature:emitonlychildren");
2303 SetFlag(n, "feature:ignore");
2307 String *kind = Getattr(n, "kind");
2308 String *name = Getattr(n, "name");
2309 String *tdname = Getattr(n, "tdname");
2310 String *symname = Getattr(n, "sym:name");
2312 char *classname = tdname ? Char(tdname) : Char(name);
2313 char *iname = Char(symname);
2314 int strip = (tdname || CPlusPlus) ? 1 : 0;
2318 Swig_warning(WARN_LANG_CLASS_UNNAMED, input_file, line_number, "Can't generate wrappers for unnamed struct/class.\n");
2322 /* Check symbol name for template. If not renamed. Issue a warning */
2323 if (!validIdentifier(symname)) {
2324 Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", SwigType_namestr(symname));
2328 Swig_save("classDeclaration", n, "name", NIL);
2329 Setattr(n, "name", classname);
2331 if (Cmp(kind, "class") == 0) {
2332 cplus_mode = PRIVATE;
2334 cplus_mode = PUBLIC;
2337 ClassName = NewString(classname);
2338 ClassPrefix = NewString(iname);
2340 ClassType = NewString(classname);
2342 ClassType = NewStringf("%s %s", kind, classname);
2344 Setattr(n, "classtypeobj", Copy(ClassType));
2345 Setattr(n, "classtype", SwigType_namestr(ClassType));
2351 /* Call classHandler() here */
2354 if (directorsEnabled()) {
2355 int ndir = GetFlag(n, "feature:director");
2356 int nndir = GetFlag(n, "feature:nodirector");
2357 /* 'nodirector' has precedence over 'director' */
2358 dir = (ndir || nndir) ? (ndir && !nndir) : 0;
2360 int abstract = !dir && abstractClassTest(n);
2361 int odefault = (GenerateDefault && !GetFlag(n, "feature:nodefault"));
2363 /* default constructor */
2364 if (!abstract && !GetFlag(n, "feature:nodefaultctor") && odefault) {
2365 if (!Getattr(n, "has_constructor") && !Getattr(n, "allocate:has_constructor") && (Getattr(n, "allocate:default_constructor"))) {
2366 addDefaultConstructor(n);
2369 /* copy constructor */
2370 if (CPlusPlus && !abstract && GetFlag(n, "feature:copyctor")) {
2371 if (!Getattr(n, "has_copy_constructor") && !Getattr(n, "allocate:has_copy_constructor")
2372 && (Getattr(n, "allocate:copy_constructor"))
2373 && (!GetFlag(n, "feature:ignore"))) {
2374 addCopyConstructor(n);
2377 /* default destructor */
2378 if (!GetFlag(n, "feature:nodefaultdtor") && odefault) {
2379 if (!Getattr(n, "has_destructor") && (!Getattr(n, "allocate:has_destructor"))
2380 && (Getattr(n, "allocate:default_destructor"))
2381 && (!GetFlag(n, "feature:ignore"))) {
2387 DirectorClassName = NewStringf("SwigDirector_%s", symname);
2390 /* check for abstract after resolving directors */
2391 Abstract = abstractClassTest(n);
2395 Abstract = abstractClassTest(n);
2396 Language::classHandler(n);
2403 Delete(ClassPrefix);
2407 Delete(DirectorClassName);
2408 DirectorClassName = 0;
2413 /* ----------------------------------------------------------------------
2414 * Language::classHandler()
2415 * ---------------------------------------------------------------------- */
2417 int Language::classHandler(Node *n) {
2419 bool hasDirector = Swig_directorclass(n) ? true : false;
2421 /* Emit all of the class members */
2424 /* Look for smart pointer handling */
2425 if (Getattr(n, "allocate:smartpointer")) {
2426 List *methods = Getattr(n, "allocate:smartpointer");
2427 cplus_mode = PUBLIC;
2428 SmartPointer = CWRAP_SMART_POINTER;
2430 for (c = First(methods); c.item; c = Next(c)) {
2436 cplus_mode = PUBLIC;
2438 /* emit director disown method */
2440 classDirectorDisown(n);
2442 /* Emit additional protected virtual methods - only needed if the language module
2443 * codes logic in the C++ layer instead of the director proxy class method - primarily
2444 * to catch public use of protected methods by the scripting languages. */
2445 if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) {
2446 Node *vtable = Getattr(n, "vtable");
2447 String *symname = Getattr(n, "sym:name");
2448 AccessMode old_mode = cplus_mode;
2449 cplus_mode = PROTECTED;
2450 int len = Len(vtable);
2451 for (int i = 0; i < len; i++) {
2452 Node *item = Getitem(vtable, i);
2453 Node *method = Getattr(item, "methodNode");
2454 SwigType *type = Getattr(method, "nodeType");
2455 if (Strcmp(type, "cdecl") != 0)
2457 if (GetFlag(method, "feature:ignore"))
2459 String *methodname = Getattr(method, "sym:name");
2460 String *wrapname = NewStringf("%s_%s", symname, methodname);
2461 if (!Getattr(symbols, wrapname) && (!is_public(method))) {
2462 Node *m = Copy(method);
2463 Setattr(m, "director", "1");
2464 Setattr(m, "parentNode", n);
2466 * There is a bug that needs fixing still...
2467 * This area of code is creating methods which have not been overidden in a derived class (director methods that are protected in the base)
2468 * If the method is overloaded, then Swig_overload_dispatch() incorrectly generates a call to the base wrapper, _wrap_xxx method
2469 * See director_protected_overloaded.i - Possibly sym:overname needs correcting here.
2470 Printf(stdout, "new method: %s::%s(%s)\n", Getattr(parentNode(m), "name"), Getattr(m, "name"), ParmList_str_defaultargs(Getattr(m, "parms")));
2477 cplus_mode = old_mode;
2484 /* ----------------------------------------------------------------------
2485 * Language::classforwardDeclaration()
2486 * ---------------------------------------------------------------------- */
2488 int Language::classforwardDeclaration(Node *n) {
2493 /* ----------------------------------------------------------------------
2494 * Language::constructorDeclaration()
2495 * ---------------------------------------------------------------------- */
2497 int Language::constructorDeclaration(Node *n) {
2498 String *name = Getattr(n, "name");
2499 String *symname = Getattr(n, "sym:name");
2509 /* extend default constructor can be safely ignored if there is already one */
2510 int num_required = ParmList_numrequired(Getattr(n, "parms"));
2511 if ((num_required == 0) && Getattr(CurrentClass, "has_default_constructor")) {
2514 if ((num_required == 1) && Getattr(CurrentClass, "has_copy_constructor")) {
2515 String *ccdecl = Getattr(CurrentClass, "copy_constructor_decl");
2516 if (ccdecl && (Strcmp(ccdecl, Getattr(n, "decl")) == 0)) {
2522 /* clean protected overloaded constructors, in case they are not needed anymore */
2523 Node *over = Swig_symbol_isoverloaded(n);
2524 if (over && !Getattr(CurrentClass, "sym:cleanconstructor")) {
2525 int dirclass = Swig_directorclass(CurrentClass);
2528 if (!is_public(nn)) {
2529 if (!dirclass || !need_nonpublic_ctor(nn)) {
2530 SetFlag(nn, "feature:ignore");
2533 nn = Getattr(nn, "sym:nextSibling");
2535 clean_overloaded(over);
2536 Setattr(CurrentClass, "sym:cleanconstructor", "1");
2539 if ((cplus_mode != PUBLIC)) {
2540 /* check only for director classes */
2541 if (!Swig_directorclass(CurrentClass) || !need_nonpublic_ctor(n))
2545 /* Name adjustment for %name */
2546 Swig_save("constructorDeclaration", n, "sym:name", NIL);
2549 String *base = Swig_scopename_last(name);
2550 if ((Strcmp(base, symname) == 0) && (Strcmp(symname, ClassPrefix) != 0)) {
2551 Setattr(n, "sym:name", ClassPrefix);
2556 /* Only create a constructor if the class is not abstract */
2559 over = Swig_symbol_isoverloaded(n);
2561 over = first_nontemplate(over);
2562 if ((over) && (!overloading)) {
2563 /* If the symbol is overloaded. We check to see if it is a copy constructor. If so,
2564 we invoke copyconstructorHandler() as a special case. */
2565 if (Getattr(n, "copy_constructor") && (!Getattr(CurrentClass, "has_copy_constructor"))) {
2566 copyconstructorHandler(n);
2567 Setattr(CurrentClass, "has_copy_constructor", "1");
2569 if (Getattr(over, "copy_constructor"))
2570 over = Getattr(over, "sym:nextSibling");
2572 Swig_warning(WARN_LANG_OVERLOAD_CONSTRUCT, input_file, line_number,
2573 "Overloaded constructor ignored. %s\n", Swig_name_decl(n));
2574 Swig_warning(WARN_LANG_OVERLOAD_CONSTRUCT, Getfile(over), Getline(over),
2575 "Previous declaration is %s\n", Swig_name_decl(over));
2577 constructorHandler(n);
2581 if (name && (Cmp(Swig_scopename_last(name), Swig_scopename_last(ClassName))) && !(Getattr(n, "template"))) {
2582 Swig_warning(WARN_LANG_RETURN_TYPE, input_file, line_number, "Function %s must have a return type.\n", SwigType_namestr(name));
2586 constructorHandler(n);
2589 Setattr(CurrentClass, "has_constructor", "1");
2595 /* ----------------------------------------------------------------------
2596 * get_director_ctor_code()
2597 * ---------------------------------------------------------------------- */
2599 static String *get_director_ctor_code(Node *n, String *director_ctor_code, String *director_prot_ctor_code, List *&abstract) {
2600 String *director_ctor = director_ctor_code;
2601 int use_director = Swig_directorclass(n);
2603 Node *pn = Swig_methodclass(n);
2604 abstract = Getattr(pn, "abstract");
2605 if (director_prot_ctor_code) {
2606 int is_notabstract = GetFlag(pn, "feature:notabstract");
2607 int is_abstract = abstract && !is_notabstract;
2608 if (is_protected(n) || is_abstract) {
2609 director_ctor = director_prot_ctor_code;
2610 Delattr(pn, "abstract");
2612 if (is_notabstract) {
2613 Delattr(pn, "abstract");
2620 return director_ctor;
2624 /* ----------------------------------------------------------------------
2625 * Language::constructorHandler()
2626 * ---------------------------------------------------------------------- */
2628 int Language::constructorHandler(Node *n) {
2629 Swig_require("constructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL);
2630 String *symname = Getattr(n, "sym:name");
2631 String *mrename = Swig_name_construct(symname);
2632 String *nodeType = Getattr(n, "nodeType");
2633 int constructor = (!Cmp(nodeType, "constructor"));
2635 String *director_ctor = get_director_ctor_code(n, director_ctor_code,
2636 director_prot_ctor_code,
2639 /* if not originally a constructor, still handle it as one */
2640 Setattr(n, "handled_as_constructor", "1");
2643 Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend);
2644 Setattr(n, "sym:name", mrename);
2649 Setattr(Swig_methodclass(n), "abstract", abstract);
2653 /* ----------------------------------------------------------------------
2654 * Language::copyconstructorHandler()
2655 * ---------------------------------------------------------------------- */
2657 int Language::copyconstructorHandler(Node *n) {
2658 Swig_require("copyconstructorHandler", n, "?name", "*sym:name", "?type", "?parms", NIL);
2659 String *symname = Getattr(n, "sym:name");
2660 String *mrename = Swig_name_copyconstructor(symname);
2662 String *director_ctor = get_director_ctor_code(n, director_ctor_code,
2663 director_prot_ctor_code,
2665 Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, CPlusPlus, Getattr(n, "template") ? 0 : Extend);
2666 Setattr(n, "sym:name", mrename);
2671 Setattr(Swig_methodclass(n), "abstract", abstract);
2675 /* ----------------------------------------------------------------------
2676 * Language::destructorDeclaration()
2677 * ---------------------------------------------------------------------- */
2679 int Language::destructorDeclaration(Node *n) {
2683 if (cplus_mode != PUBLIC)
2689 /* extend destructor can be safetly ignored if there is already one */
2690 if (Getattr(CurrentClass, "has_destructor")) {
2695 Swig_save("destructorDeclaration", n, "name", "sym:name", NIL);
2697 char *c = GetChar(n, "name");
2698 if (c && (*c == '~'))
2699 Setattr(n, "name", c + 1);
2701 c = GetChar(n, "sym:name");
2702 if (c && (*c == '~'))
2703 Setattr(n, "sym:name", c + 1);
2705 /* Name adjustment for %name */
2707 String *name = Getattr(n, "name");
2708 String *symname = Getattr(n, "sym:name");
2710 if ((Strcmp(name, symname) == 0) || (Strcmp(symname, ClassPrefix) != 0)) {
2711 Setattr(n, "sym:name", ClassPrefix);
2714 destructorHandler(n);
2716 Setattr(CurrentClass, "has_destructor", "1");
2721 /* ----------------------------------------------------------------------
2722 * Language::destructorHandler()
2723 * ---------------------------------------------------------------------- */
2725 int Language::destructorHandler(Node *n) {
2726 Swig_require("destructorHandler", n, "?name", "*sym:name", NIL);
2727 Swig_save("destructorHandler", n, "type", "parms", NIL);
2729 String *symname = Getattr(n, "sym:name");
2731 char *csymname = Char(symname);
2732 if (csymname && (*csymname == '~'))
2735 mrename = Swig_name_destroy(csymname);
2737 Swig_DestructorToFunction(n, ClassType, CPlusPlus, Extend);
2738 Setattr(n, "sym:name", mrename);
2745 /* ----------------------------------------------------------------------
2746 * Language::accessDeclaration()
2747 * ---------------------------------------------------------------------- */
2749 int Language::accessDeclaration(Node *n) {
2750 String *kind = Getattr(n, "kind");
2751 if (Cmp(kind, "public") == 0) {
2752 cplus_mode = PUBLIC;
2753 } else if (Cmp(kind, "private") == 0) {
2754 cplus_mode = PRIVATE;
2755 } else if (Cmp(kind, "protected") == 0) {
2756 cplus_mode = PROTECTED;
2761 /* -----------------------------------------------------------------------------
2762 * Language::namespaceDeclaration()
2763 * ----------------------------------------------------------------------------- */
2765 int Language::namespaceDeclaration(Node *n) {
2766 if (Getattr(n, "alias"))
2768 if (Getattr(n, "unnamed"))
2774 int Language::validIdentifier(String *s) {
2777 if (!(isalnum(*c) || (*c == '_')))
2784 /* -----------------------------------------------------------------------------
2785 * Language::usingDeclaration()
2786 * ----------------------------------------------------------------------------- */
2788 int Language::usingDeclaration(Node *n) {
2789 if ((cplus_mode == PUBLIC)) {
2792 for (c = firstChild(np); c; c = nextSibling(c)) {
2793 /* it seems for some cases this is needed, like A* A::boo() */
2795 Setattr(c, "parentNode", CurrentClass);
2803 /* Stubs. Language modules need to implement these */
2805 /* ----------------------------------------------------------------------
2806 * Language::constantWrapper()
2807 * ---------------------------------------------------------------------- */
2809 int Language::constantWrapper(Node *n) {
2810 String *name = Getattr(n, "sym:name");
2811 SwigType *type = Getattr(n, "type");
2812 String *value = Getattr(n, "value");
2813 String *str = SwigType_str(type, name);
2814 Printf(stdout, "constantWrapper : %s = %s\n", str, value);
2819 /* ----------------------------------------------------------------------
2820 * Language::variableWrapper()
2821 * ---------------------------------------------------------------------- */
2823 int Language::variableWrapper(Node *n) {
2824 Swig_require("variableWrapper", n, "*name", "*sym:name", "*type", "?parms", NIL);
2825 String *symname = Getattr(n, "sym:name");
2826 SwigType *type = Getattr(n, "type");
2827 String *name = Getattr(n, "name");
2829 /* If no way to set variables. We simply create functions */
2830 int assignable = is_assignable(n);
2831 int flags = use_naturalvar_mode(n);
2832 if (!GetFlag(n, "wrappedasconstant"))
2833 flags = flags | Extend;
2836 int make_set_wrapper = 1;
2837 String *tm = Swig_typemap_lookup("globalin", n, name, 0);
2839 Swig_VarsetToFunction(n, flags);
2840 String *sname = Swig_name_set(symname);
2841 Setattr(n, "sym:name", sname);
2845 if (SwigType_isarray(type)) {
2846 Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0));
2847 make_set_wrapper = 0;
2850 String *pname0 = Swig_cparm_name(0, 0);
2851 Replace(tm, "$source", pname0, DOH_REPLACE_ANY);
2852 Replace(tm, "$target", name, DOH_REPLACE_ANY);
2853 Replace(tm, "$input", pname0, DOH_REPLACE_ANY);
2854 Setattr(n, "wrap:action", tm);
2858 if (make_set_wrapper) {
2861 /* Restore parameters */
2862 Setattr(n, "sym:name", symname);
2863 Setattr(n, "type", type);
2864 Setattr(n, "name", name);
2866 /* Delete all attached typemaps and typemap attributes */
2868 for (ki = First(n); ki.key; ki = Next(ki)) {
2869 if (Strncmp(ki.key, "tmap:", 5) == 0)
2874 Swig_VargetToFunction(n, flags);
2875 String *gname = Swig_name_get(symname);
2876 Setattr(n, "sym:name", gname);
2883 /* ----------------------------------------------------------------------
2884 * Language::functionWrapper()
2885 * ---------------------------------------------------------------------- */
2887 int Language::functionWrapper(Node *n) {
2888 String *name = Getattr(n, "sym:name");
2889 SwigType *type = Getattr(n, "type");
2890 ParmList *parms = Getattr(n, "parms");
2892 Printf(stdout, "functionWrapper : %s\n", SwigType_str(type, NewStringf("%s(%s)", name, ParmList_str_defaultargs(parms))));
2893 Printf(stdout, " action : %s\n", Getattr(n, "wrap:action"));
2897 /* -----------------------------------------------------------------------------
2898 * Language::nativeWrapper()
2899 * ----------------------------------------------------------------------------- */
2901 int Language::nativeWrapper(Node *n) {
2906 void Language::main(int argc, char *argv[]) {
2911 /* -----------------------------------------------------------------------------
2912 * Language::addSymbol()
2914 * Adds a symbol entry. Returns 1 if the symbol is added successfully.
2915 * Prints an error message and returns 0 if a conflict occurs.
2916 * ----------------------------------------------------------------------------- */
2919 Language::addSymbol(const String *s, const Node *n) {
2920 Node *c = Getattr(symbols, s);
2921 if (c && (c != n)) {
2922 Swig_error(input_file, line_number, "'%s' is multiply defined in the generated module.\n", s);
2923 Swig_error(Getfile(c), Getline(c), "Previous declaration of '%s'\n", s);
2926 Setattr(symbols, s, n);
2930 /* -----------------------------------------------------------------------------
2931 * Language::symbolLookup()
2932 * ----------------------------------------------------------------------------- */
2934 Node *Language::symbolLookup(String *s) {
2935 return Getattr(symbols, s);
2938 /* -----------------------------------------------------------------------------
2939 * Language::classLookup()
2941 * Tries to locate a class from a type definition
2942 * ----------------------------------------------------------------------------- */
2944 Node *Language::classLookup(SwigType *s) {
2947 /* Look in hash of cached values */
2948 n = Getattr(classtypes, s);
2951 SwigType *ty1 = SwigType_typedef_resolve_all(s);
2952 SwigType *ty2 = SwigType_strip_qualifiers(ty1);
2956 String *base = SwigType_base(ty2);
2958 Replaceall(base, "class ", "");
2959 Replaceall(base, "struct ", "");
2960 Replaceall(base, "union ", "");
2962 if (strncmp(Char(base), "::", 2) == 0) {
2963 String *oldbase = base;
2964 base = NewString(Char(base) + 2);
2968 String *prefix = SwigType_prefix(ty2);
2970 /* Do a symbol table search on the base type */
2973 n = Swig_symbol_clookup(base, stab);
2976 if (Strcmp(nodeType(n), "class") == 0)
2981 nstab = Getattr(n, "sym:symtab");
2983 if ((!nstab) || (nstab == stab)) {
2989 /* Found a match. Look at the prefix. We only allow
2990 the cases where where we want a proxy class for the particular type */
2991 if ((Len(prefix) == 0) || // simple type (pass by value)
2992 (Strcmp(prefix, "p.") == 0) || // pointer
2993 (Strcmp(prefix, "r.") == 0) || // reference
2994 (Strcmp(prefix, "r.p.") == 0) || // pointer by reference
2995 SwigType_prefix_is_simple_1D_array(prefix)) { // Simple 1D array (not arrays of pointers/references)
2996 SwigType *cs = Copy(s);
2997 Setattr(classtypes, cs, n);
3007 if (n && (GetFlag(n, "feature:ignore") || Getattr(n, "feature:onlychildren"))) {
3014 /* -----------------------------------------------------------------------------
3015 * Language::enumLookup()
3017 * Finds and returns the Node containing the enum declaration for the (enum)
3019 * ----------------------------------------------------------------------------- */
3021 Node *Language::enumLookup(SwigType *s) {
3024 /* Look in hash of cached values */
3025 n = Getattr(enumtypes, s);
3028 SwigType *lt = SwigType_ltype(s);
3029 SwigType *ty1 = SwigType_typedef_resolve_all(lt);
3030 SwigType *ty2 = SwigType_strip_qualifiers(ty1);
3036 String *base = SwigType_base(ty2);
3038 Replaceall(base, "enum ", "");
3039 String *prefix = SwigType_prefix(ty2);
3041 if (strncmp(Char(base), "::", 2) == 0) {
3042 String *oldbase = base;
3043 base = NewString(Char(base) + 2);
3047 /* Look for type in symbol table */
3050 n = Swig_symbol_clookup(base, stab);
3053 if (Strcmp(nodeType(n), "enum") == 0)
3058 nstab = Getattr(n, "sym:symtab");
3060 if ((!nstab) || (nstab == stab)) {
3066 /* Found a match. Look at the prefix. We only allow simple types. */
3067 if (Len(prefix) == 0) { /* Simple type */
3068 Setattr(enumtypes, Copy(s), n);
3077 if (n && (GetFlag(n, "feature:ignore"))) {
3084 /* -----------------------------------------------------------------------------
3085 * Language::allow_overloading()
3086 * ----------------------------------------------------------------------------- */
3088 void Language::allow_overloading(int val) {
3092 /* -----------------------------------------------------------------------------
3093 * Language::allow_multiple_input()
3094 * ----------------------------------------------------------------------------- */
3096 void Language::allow_multiple_input(int val) {
3100 /* -----------------------------------------------------------------------------
3101 * Language::enable_cplus_runtime_mode()
3102 * ----------------------------------------------------------------------------- */
3104 void Language::enable_cplus_runtime_mode() {
3108 /* -----------------------------------------------------------------------------
3109 * Language::cplus_runtime_mode()
3110 * ----------------------------------------------------------------------------- */
3112 int Language::cplus_runtime_mode() {
3113 return cplus_runtime;
3116 /* -----------------------------------------------------------------------------
3117 * Language::allow_directors()
3118 * ----------------------------------------------------------------------------- */
3120 void Language::allow_directors(int val) {
3124 /* -----------------------------------------------------------------------------
3125 * Language::directorsEnabled()
3126 * ----------------------------------------------------------------------------- */
3128 int Language::directorsEnabled() const {
3129 return director_language && CPlusPlus && (directors || director_mode);
3132 /* -----------------------------------------------------------------------------
3133 * Language::allow_dirprot()
3134 * ----------------------------------------------------------------------------- */
3136 void Language::allow_dirprot(int val) {
3137 director_protected_mode = val;
3140 /* -----------------------------------------------------------------------------
3141 * Language::allow_allprotected()
3142 * ----------------------------------------------------------------------------- */
3144 void Language::allow_allprotected(int val) {
3145 all_protected_mode = val;
3148 /* -----------------------------------------------------------------------------
3149 * Language::dirprot_mode()
3150 * ----------------------------------------------------------------------------- */
3152 int Language::dirprot_mode() const {
3153 return directorsEnabled() ? director_protected_mode : 0;
3156 /* -----------------------------------------------------------------------------
3157 * Language::need_nonpublic_ctor()
3158 * ----------------------------------------------------------------------------- */
3160 int Language::need_nonpublic_ctor(Node *n) {
3162 detects when a protected constructor is needed, which is always
3163 the case if 'dirprot' mode is used. However, if that is not the
3164 case, we will try to strictly emit what is minimal to don't break
3165 the generated, while preserving compatibility with java, which
3166 always try to emit the default constructor.
3170 - when dirprot mode is used, the protected constructors are
3173 - the protected default constructor is always needed.
3175 - if dirprot mode is not used, the protected constructors will be
3178 - there is no any public constructor in the class, and
3179 - there is no protected default constructor
3181 In that case, all the declared protected constructors are
3182 needed since we don't know which one to pick up.
3184 Note: given all the complications here, I am always in favor to
3185 always enable 'dirprot', since is the C++ idea of protected
3186 members, and use %ignore for the method you don't whan to add in
3189 if (directorsEnabled()) {
3190 if (is_protected(n)) {
3191 if (dirprot_mode()) {
3192 /* when using dirprot mode, the protected constructors are
3196 int is_default_ctor = !ParmList_numrequired(Getattr(n, "parms"));
3197 if (is_default_ctor) {
3198 /* the default protected constructor is always needed, for java compatibility */
3201 /* check if there is a public constructor */
3202 Node *parent = Swig_methodclass(n);
3203 int public_ctor = Getattr(parent, "allocate:default_constructor")
3204 || Getattr(parent, "allocate:public_constructor");
3206 /* if not, the protected constructor will be needed only
3207 if there is no protected default constructor declared */
3208 int no_prot_default_ctor = !Getattr(parent, "allocate:default_base_constructor");
3209 return no_prot_default_ctor;
3218 /* -----------------------------------------------------------------------------
3219 * Language::need_nonpublic_member()
3220 * ----------------------------------------------------------------------------- */
3221 int Language::need_nonpublic_member(Node *n) {
3222 if (directorsEnabled()) {
3223 if (is_protected(n)) {
3224 if (dirprot_mode()) {
3225 /* when using dirprot mode, the protected members are always needed. */
3228 /* if the method is pure virtual, we need it. */
3229 int pure_virtual = (Cmp(Getattr(n, "value"), "0") == 0);
3230 return pure_virtual;
3238 /* -----------------------------------------------------------------------------
3239 * Language::is_smart_pointer()
3240 * ----------------------------------------------------------------------------- */
3242 int Language::is_smart_pointer() const {
3243 return SmartPointer;
3246 /* -----------------------------------------------------------------------------
3247 * Language::extraDirectorProtectedCPPMethodsRequired()
3248 * ----------------------------------------------------------------------------- */
3250 bool Language::extraDirectorProtectedCPPMethodsRequired() const {
3254 /* -----------------------------------------------------------------------------
3255 * Language::is_wrapping_class()
3256 * ----------------------------------------------------------------------------- */
3258 int Language::is_wrapping_class() {
3262 /* -----------------------------------------------------------------------------
3263 * Language::getCurrentClass()
3264 * ----------------------------------------------------------------------------- */
3266 Node *Language::getCurrentClass() const {
3267 return CurrentClass;
3270 /* -----------------------------------------------------------------------------
3271 * Language::getClassName()
3272 * ----------------------------------------------------------------------------- */
3274 String *Language::getClassName() const {
3278 /* -----------------------------------------------------------------------------
3279 * Language::getClassPrefix()
3280 * ----------------------------------------------------------------------------- */
3282 String *Language::getClassPrefix() const {
3286 /* -----------------------------------------------------------------------------
3287 * Language::getClassType()
3288 * ----------------------------------------------------------------------------- */
3290 String *Language::getClassType() const {
3294 /* -----------------------------------------------------------------------------
3295 * Language::abstractClassTest()
3296 * ----------------------------------------------------------------------------- */
3297 //#define SWIG_DEBUG
3298 int Language::abstractClassTest(Node *n) {
3299 /* check for non public operator new */
3300 if (GetFlag(n, "feature:notabstract"))
3302 if (Getattr(n, "allocate:nonew"))
3304 /* now check for the rest */
3305 List *abstract = Getattr(n, "abstract");
3308 int labs = Len(abstract);
3310 List *bases = Getattr(n, "allbases");
3311 Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(bases));
3314 return 0; /*strange, but need to be fixed */
3315 if (abstract && !directorsEnabled())
3317 if (!GetFlag(n, "feature:director"))
3320 Node *dirabstract = 0;
3321 Node *vtable = Getattr(n, "vtable");
3324 Printf(stderr, "vtable %s %d %d\n", Getattr(n, "name"), Len(vtable), labs);
3326 for (int i = 0; i < labs; i++) {
3327 Node *ni = Getitem(abstract, i);
3328 Node *method_id = vtable_method_id(ni);
3331 bool exists_item = false;
3332 int len = Len(vtable);
3333 for (int i = 0; i < len; i++) {
3334 Node *item = Getitem(vtable, i);
3335 String *check_item = Getattr(item, "vmid");
3336 if (Strcmp(method_id, check_item) == 0) {
3342 Printf(stderr, "method %s %d\n", method_id, exists_item ? 1 : 0);
3351 if (is_public(dirabstract)) {
3352 Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n),
3353 "Director class '%s' is abstract, abstract method '%s' is not accesible, maybe due to multiple inheritance or 'nodirector' feature\n",
3354 SwigType_namestr(Getattr(n, "name")), Getattr(dirabstract, "name"));
3356 Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n),
3357 "Director class '%s' is abstract, abstract method '%s' is private\n", SwigType_namestr(Getattr(n, "name")), Getattr(dirabstract, "name"));
3364 return dirabstract ? 1 : 0;
3367 void Language::setSubclassInstanceCheck(String *nc) {
3368 none_comparison = nc;
3371 void Language::setOverloadResolutionTemplates(String *argc, String *argv) {
3372 Delete(argc_template_string);
3373 argc_template_string = Copy(argc);
3374 Delete(argv_template_string);
3375 argv_template_string = Copy(argv);
3378 int Language::is_assignable(Node *n) {
3379 if (GetFlag(n, "feature:immutable"))
3381 SwigType *type = Getattr(n, "type");
3383 SwigType *ftd = SwigType_typedef_resolve_all(type);
3384 SwigType *td = SwigType_strip_qualifiers(ftd);
3385 if (SwigType_type(td) == T_USER) {
3386 cn = Swig_symbol_clookup(td, 0);
3388 if ((Strcmp(nodeType(cn), "class") == 0)) {
3389 if (Getattr(cn, "allocate:noassign")) {
3390 SetFlag(n, "feature:immutable");
3403 String *Language::runtimeCode() {
3404 return NewString("");
3407 String *Language::defaultExternalRuntimeFilename() {
3411 /* -----------------------------------------------------------------------------
3412 * Language::replaceSpecialVariables()
3413 * Language modules should implement this if special variables are to be handled
3414 * correctly in the $typemap(...) special variable macro.
3415 * method - typemap method name
3416 * tm - string containing typemap contents
3417 * parm - a parameter describing the typemap type to be handled
3418 * ----------------------------------------------------------------------------- */
3419 void Language::replaceSpecialVariables(String *method, String *tm, Parm *parm) {
3425 Language *Language::instance() {
3429 Hash *Language::getClassHash() const {