String *Swig_filename_escape(String *filename) { String *adjusted_filename = Copy(filename); #if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */ Replaceall(adjusted_filename, "\\", "\\\\"); #endif return adjusted_filename; }
String *Swig_ref_call(Node *n, const String *lname) { Node *cn = Swig_methodclass(n); String *ref = Swig_rflag_search(cn, "feature:ref", "feature:noref"); if (ref) { ref = NewString(ref); Replaceall(ref, "$this", lname); Replaceall(ref, "$self", lname); } return ref; }
void Swig_filename_correct(String *filename) { (void)filename; #if defined(_WIN32) || defined(MACSWIG) /* accept Unix path separator on non-Unix systems */ Replaceall(filename, "/", SWIG_FILE_DELIMITER); #endif #if defined(__CYGWIN__) /* accept Windows path separator in addition to Unix path separator */ Replaceall(filename, "\\", SWIG_FILE_DELIMITER); #endif }
SwigType *SwigType_remove_global_scope_prefix(const SwigType *t) { SwigType *result; const char *type = Char(t); if (strncmp(type, "::", 2) == 0) type += 2; result = NewString(type); Replaceall(result, ".::", "."); Replaceall(result, "(::", "("); Replaceall(result, "enum ::", "enum "); return result; }
String *Swig_unref_call(Node *n) { Node *cn = Swig_methodclass(n); String *unref = Swig_rflag_search(cn, "feature:unref", "feature:nounref"); if (unref) { String *pname = Swig_cparm_name(0, 0); unref = NewString(unref); Replaceall(unref, "$this", pname); Replaceall(unref, "$self", pname); Delete(pname); } return unref; }
String * Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self) { String *func, *nname; int i = 0; Parm *p = parms; SwigType *pt; int comma = 0; if (!self) self = (char *) "(this)->"; func = NewString(""); nname = SwigType_namestr(name); if (!p) return func; Append(func,self); pt = Getattr(p,"type"); /* If the method is invoked through a dereferenced pointer, we don't add any casts (needed for smart pointers). Otherwise, we cast to the appropriate type */ if (Strstr(func,"*this")) { Replaceall(func,"this", Swig_cparm_name(p,0)); } else { Replaceall(func,"this", SwigType_rcaststr(pt, Swig_cparm_name(p,0))); } if (SwigType_istemplate(name)) { Printf(func,"template %s(", nname); } else { Printf(func,"%s(", nname); } i++; p = nextSibling(p); while (p) { String *pname; pt = Getattr(p,"type"); if ((SwigType_type(pt) != T_VOID)) { if (comma) Printf(func,","); pname = Swig_cparm_name(p,i); Printf(func,"%s", SwigType_rcaststr(pt, pname)); comma = 1; i++; } p = nextSibling(p); } Printf(func,")"); Delete(nname); return func; }
/* ----------------------------------------------------------------------------- * format_filename() * * Remove double backslashes in Windows filename paths for display * ----------------------------------------------------------------------------- */ static String *format_filename(const String_or_char *filename) { String *formatted_filename = NewString(filename); #if defined(_WIN32) Replaceall(formatted_filename, "\\\\", "\\"); #endif return formatted_filename; }
String *Swig_filename_escape(String *filename) { String *adjusted_filename = Copy(filename); Swig_filename_correct(adjusted_filename); #if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ Replaceall(adjusted_filename, "\\", "\\\\"); #endif return adjusted_filename; }
static void replace_nspace(String *name, const_String_or_char_ptr nspace) { if (nspace) { String *namspace = NewStringf("%s_", nspace); Replaceall(namspace, NSPACE_SEPARATOR, "_"); Replace(name, "%n", namspace, DOH_REPLACE_ANY); Delete(namspace); } else { Replace(name, "%n", "", DOH_REPLACE_ANY); } }
String * Swig_cmemberget_call(String_or_char *name, SwigType *t, String_or_char *self) { String *func; if (!self) self = NewString("(this)->"); else self = NewString(self); Replaceall(self,"this",Swig_cparm_name(0,0)); func = NewString(""); Printf(func,"%s (%s%s)", Swig_wrapped_var_assign(t,""),self, name); Delete(self); return func; }
void cparse_normalize_void(Node *n) { String *decl = Getattr(n, "decl"); Parm *parms = Getattr(n, "parms"); if (SwigType_isfunction(decl)) { if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms, "type")) == T_VOID)) { Replaceall(decl, "f(void).", "f()."); Delattr(n, "parms"); } } }
String * Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self) { String *func; func = NewString(""); if (!self) self = NewString("(this)->"); else self = NewString(self); Replaceall(self,"this",Swig_cparm_name(0,0)); if (SwigType_type(type) != T_ARRAY) { Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name, Swig_wrapped_var_deref(type, Swig_cparm_name(0,1))); } Delete(self); return(func); }
/* ----------------------------------------------------------------------------- * extension_code() * * Generates an extension function (a function defined in %extend) * * return_type function_name(parms) code * * ----------------------------------------------------------------------------- */ static String *extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus, const String *self) { String *parms_str = cplusplus ? ParmList_str_defaultargs(parms) : ParmList_str(parms); String *sig = NewStringf("%s(%s)", function_name, parms_str); String *rt_sig = SwigType_str(return_type, sig); String *body = NewStringf("SWIGINTERN %s", rt_sig); Printv(body, code, "\n", NIL); if (self) Replaceall(body, "$self", self); Delete(parms_str); Delete(sig); Delete(rt_sig); return body; }
void Swig_filename_correct(String *filename) { int network_path = 0; if (Len(filename) >= 2) { const char *fname = Char(filename); if (fname[0] == '\\' && fname[1] == '\\') network_path = 1; if (fname[0] == '/' && fname[1] == '/') network_path = 1; } #if defined(_WIN32) || defined(MACSWIG) /* accept Unix path separator on non-Unix systems */ Replaceall(filename, "/", SWIG_FILE_DELIMITER); #endif #if defined(__CYGWIN__) /* accept Windows path separator in addition to Unix path separator */ Replaceall(filename, "\\", SWIG_FILE_DELIMITER); #endif /* remove all duplicate file name delimiters */ while (Replaceall(filename, SWIG_FILE_DELIMITER SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER)) { } /* Network paths can start with a double slash on Windows - unremove the duplicate slash we just removed */ if (network_path) Insert(filename, 0, SWIG_FILE_DELIMITER); }
String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref) { String *func; String *call; String *pname0 = Swig_cparm_name(0, 0); if (!self) self = NewString("(this)->"); else self = NewString(self); Replaceall(self, "this", pname0); func = NewStringEmpty(); call = Swig_wrapped_var_assign(t, "", varcref); Printf(func, "%s (%s%s)", call, self, name); Delete(self); Delete(call); Delete(pname0); return func; }
String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref) { String *func; String *pname0 = Swig_cparm_name(0, 0); String *pname1 = Swig_cparm_name(0, 1); func = NewStringEmpty(); if (!self) self = NewString("(this)->"); else self = NewString(self); Replaceall(self, "this", pname0); if (SwigType_type(type) != T_ARRAY) { if (!Strstr(type, "enum $unnamed")) { String *dref = Swig_wrapped_var_deref(type, pname1, varcref); Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref); Delete(dref); } else { Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1); } } Delete(self); Delete(pname0); Delete(pname1); return (func); }
void Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *node) { char *ncdecl = 0; String *rdecl = 0; String *rname = 0; if (!features) return; /* MM: This removed to more tightly control feature/name matching */ /* if ((decl) && (SwigType_isqualifier(decl))) { ncdecl = strchr(Char(decl),'.'); ncdecl++; } */ /* very specific hack for template constructors/destructors */ if (name && SwigType_istemplate(name)) { String *nodetype = nodeType(node); if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { Append(nprefix, "::"); Append(nprefix, tprefix); Delete(tprefix); rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); Replaceall(rdecl, name, rname); decl = rdecl; name = rname; } } #ifdef SWIG_DEBUG Printf(stdout, "Swig_features_get: '%s' '%s' '%s'\n", prefix, name, decl); #endif /* Global features */ features_get(features, "", 0, 0, node); if (name) { String *tname = NewStringEmpty(); /* add features for 'root' template */ String *dname = SwigType_istemplate_templateprefix(name); if (dname) { features_get(features, dname, decl, ncdecl, node); } /* Catch-all */ features_get(features, name, decl, ncdecl, node); /* Perform a class-based lookup (if class prefix supplied) */ if (prefix) { /* A class-generic feature */ if (Len(prefix)) { Printf(tname, "%s::", prefix); features_get(features, tname, decl, ncdecl, node); } /* A wildcard-based class lookup */ Clear(tname); Printf(tname, "*::%s", name); features_get(features, tname, decl, ncdecl, node); /* A specific class lookup */ if (Len(prefix)) { /* A template-based class lookup */ String *tprefix = SwigType_istemplate_templateprefix(prefix); if (tprefix) { Clear(tname); Printf(tname, "%s::%s", tprefix, name); features_get(features, tname, decl, ncdecl, node); } Clear(tname); Printf(tname, "%s::%s", prefix, name); features_get(features, tname, decl, ncdecl, node); Delete(tprefix); } } else { /* Lookup in the global namespace only */ Clear(tname); Printf(tname, "::%s", name); features_get(features, tname, decl, ncdecl, node); } Delete(tname); Delete(dname); } if (name && SwigType_istemplate(name)) { /* add features for complete template type */ String *dname = Swig_symbol_template_deftype(name, 0); if (!Equal(dname, name)) { Swig_features_get(features, prefix, dname, decl, node); } Delete(dname); } if (rname) Delete(rname); if (rdecl) Delete(rdecl); }
static String *Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, String *explicit_qualifier, SwigType *director_type) { String *func, *nname; int i = 0; Parm *p = parms; SwigType *pt; int comma = 0; func = NewStringEmpty(); if (!p) return func; if (!self) self = (char *) "(this)->"; Append(func, self); if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) { /* fix for template + operators and compilers like gcc 3.3.5 */ String *tprefix = SwigType_templateprefix(name); nname = tprefix; } else { nname = SwigType_namestr(name); } if (director_type) { const char *pname = "darg"; String *rcaststr = SwigType_rcaststr(director_type, pname); Replaceall(func, "this", rcaststr); Delete(rcaststr); } else { pt = Getattr(p, k_type); /* If the method is invoked through a dereferenced pointer, we don't add any casts (needed for smart pointers). Otherwise, we cast to the appropriate type */ if (Strstr(func, "*this")) { String *pname = Swig_cparm_name(p, 0); Replaceall(func, "this", pname); Delete(pname); } else { String *pname = Swig_cparm_name(p, 0); String *rcaststr = SwigType_rcaststr(pt, pname); Replaceall(func, "this", rcaststr); Delete(rcaststr); Delete(pname); } /* SWIGTEMPLATEDESIMBUAGATOR is compiler dependent (swiglabels.swg), - SUN Studio 9 requires 'template', - gcc-3.4 forbids the use of 'template' (correctly implementing the ISO C++ standard) the others don't seem to care, */ if (SwigType_istemplate(name)) Printf(func, "SWIGTEMPLATEDISAMBIGUATOR "); if (explicit_qualifier) { Printv(func, explicit_qualifier, "::", NIL); } } Printf(func, "%s(", nname); i++; p = nextSibling(p); while (p) { pt = Getattr(p, k_type); if ((SwigType_type(pt) != T_VOID)) { String *pname = Swig_cparm_name(p, i); String *rcaststr = SwigType_rcaststr(pt, pname); if (comma) Append(func, ","); Append(func, rcaststr); Delete(rcaststr); Delete(pname); comma = 1; i++; } p = nextSibling(p); } Append(func, ")"); Delete(nname); return func; }
int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { ParmList *parms; Parm *prefix_args; Parm *p; ParmList *directorparms; SwigType *type; Node *classNode; int use_director; classNode = Swig_methodclass(n); use_director = Swig_directorclass(n); parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms))); /* Prepend the list of prefix_args (if any) */ prefix_args = Getattr(n, k_directorprefixargs); if (prefix_args != NIL) { Parm *p2, *p3; directorparms = CopyParmList(prefix_args); for (p = directorparms; nextSibling(p); p = nextSibling(p)); for (p2 = parms; p2; p2 = nextSibling(p2)) { p3 = CopyParm(p2); set_nextSibling(p, p3); Delete(p3); p = p3; } } else directorparms = parms; type = NewString(classname); SwigType_add_pointer(type); if (flags & CWRAP_EXTEND) { /* Constructors with default arguments are wrapped with additional constructor methods for each default argument, * however, only one extra %extend method is generated. */ String *call; String *cres; String *defaultargs = Getattr(n, k_defaultargs); String *code = Getattr(n, k_code); String *membername = Swig_name_construct(classname); String *mangled = Swig_name_mangle(membername); /* Check if the constructor is overloaded. If so, and it has code attached, we append an extra suffix to avoid a name-clash in the generated wrappers. This allows overloaded constructors to be defined in C. */ if (Getattr(n, k_symoverloaded) && code) { Append(mangled, Getattr(defaultargs ? defaultargs : n, k_symovername)); } /* See if there is any code that we need to emit */ if (!defaultargs && code) { Swig_add_extension_code(n, mangled, parms, type, code, cparse_cplusplus, k_self); } call = Swig_cfunction_call(mangled, parms); cres = Swig_cresult(type, k_result, call); Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); Delete(membername); Delete(mangled); } else { if (cplus) { /* if a C++ director class exists, create it rather than the original class */ if (use_director) { Node *parent = Swig_methodclass(n); int abstract = Getattr(parent, k_abstract) != 0; String *name = Getattr(parent, k_symname); String *directorname = NewStringf("SwigDirector_%s", name); String *action = NewStringEmpty(); String *tmp_none_comparison = Copy(none_comparison); String *director_call; String *nodirector_call; Replaceall(tmp_none_comparison, "$arg", "arg1"); director_call = Swig_cppconstructor_director_call(directorname, directorparms); nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms); if (abstract) { /* whether or not the abstract class has been subclassed in python, * create a director instance (there's no way to create a normal * instance). if any of the pure virtual methods haven't been * implemented in the target language, calls to those methods will * generate Swig::DirectorPureVirtualException exceptions. */ String *cres = Swig_cresult(type, k_result, director_call); Append(action, cres); Delete(cres); } else { /* (scottm): The code for creating a new director is now a string template that gets passed in via the director_ctor argument. $comparison : an 'if' comparison from none_comparison $director_new: Call new for director class $nondirector_new: Call new for non-director class */ String *cres; Append(action, director_ctor); Replaceall(action, "$comparison", tmp_none_comparison); cres = Swig_cresult(type, k_result, director_call); Replaceall(action, "$director_new", cres); Delete(cres); cres = Swig_cresult(type, k_result, nodirector_call); Replaceall(action, "$nondirector_new", cres); Delete(cres); } Setattr(n, k_wrapaction, action); Delete(tmp_none_comparison); Delete(action); Delete(directorname); } else { String *call = Swig_cppconstructor_call(classname, parms); String *cres = Swig_cresult(type, k_result, call); Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); } } else { String *call = Swig_cconstructor_call(classname); String *cres = Swig_cresult(type, k_result, call); Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); } } Setattr(n, k_type, type); Setattr(n, k_parms, parms); Delete(type); if (directorparms != parms) Delete(directorparms); Delete(parms); return SWIG_OK; }
String *Swig_string_schemify(String *s) { String *ns = NewString(s); Replaceall(ns, "_", "-"); return ns; }
int yylex(void) { int l; if (!scan_init) { scanner_init(); } if (next_token) { l = next_token; next_token = 0; return l; } /* Printf(stdout,"%d\n", last_id);*/ l = yylook(); if (l == NONID) { last_id = 1; } else { last_id = 0; } /* yytext[yylen]= 0; Printf(stdout,"%d '%s' %d\n", l, yytext, last_id); */ /* We got some sort of non-white space object. We set the start_line variable unless it has already been set */ if (!cparse_start_line) { cparse_start_line = cparse_line; } /* Copy the lexene */ yytext[yylen] = 0; switch(l) { case NUM_INT: case NUM_FLOAT: case NUM_ULONG: case NUM_LONG: case NUM_UNSIGNED: case NUM_LONGLONG: case NUM_ULONGLONG: if (l == NUM_INT) yylval.dtype.type = T_INT; if (l == NUM_FLOAT) yylval.dtype.type = T_DOUBLE; if (l == NUM_ULONG) yylval.dtype.type = T_ULONG; if (l == NUM_LONG) yylval.dtype.type = T_LONG; if (l == NUM_UNSIGNED) yylval.dtype.type = T_UINT; if (l == NUM_LONGLONG) yylval.dtype.type = T_LONGLONG; if (l == NUM_ULONGLONG) yylval.dtype.type = T_ULONGLONG; yylval.dtype.val = NewString(yytext); yylval.dtype.bitfield = 0; yylval.dtype.throws = 0; return(l); break; case ID: if (yytext[0] != '%') { /* Look for keywords now */ if (strcmp(yytext,"int") == 0) { yylval.type = NewSwigType(T_INT); return(TYPE_INT); } if (strcmp(yytext,"double") == 0) { yylval.type = NewSwigType(T_DOUBLE); return(TYPE_DOUBLE); } if (strcmp(yytext,"void") == 0) { yylval.type = NewSwigType(T_VOID); return(TYPE_VOID); } if (strcmp(yytext,"char") == 0) { yylval.type = NewSwigType(T_CHAR); return(TYPE_CHAR); } if (strcmp(yytext,"short") == 0) { yylval.type = NewSwigType(T_SHORT); return(TYPE_SHORT); } if (strcmp(yytext,"long") == 0) { yylval.type = NewSwigType(T_LONG); return(TYPE_LONG); } if (strcmp(yytext,"float") == 0) { yylval.type = NewSwigType(T_FLOAT); return(TYPE_FLOAT); } if (strcmp(yytext,"signed") == 0) { yylval.type = NewSwigType(T_INT); return(TYPE_SIGNED); } if (strcmp(yytext,"unsigned") == 0) { yylval.type = NewSwigType(T_UINT); return(TYPE_UNSIGNED); } if (strcmp(yytext,"bool") == 0) { yylval.type = NewSwigType(T_BOOL); return(TYPE_BOOL); } /* C++ keywords */ if (cparse_cplusplus) { if (strcmp(yytext,"class") == 0) return(CLASS); if (strcmp(yytext,"private") == 0) return(PRIVATE); if (strcmp(yytext,"public") == 0) return(PUBLIC); if (strcmp(yytext,"protected") == 0) return(PROTECTED); if (strcmp(yytext,"friend") == 0) return(FRIEND); if (strcmp(yytext,"virtual") == 0) return(VIRTUAL); if (strcmp(yytext,"operator") == 0) { String *s = NewString("operator"); int c; int state = 0; int sticky = 0; int isconversion = 0; int count = 0; while ((c = nextchar())) { if (((c == '(') || (c == ';')) && state) { retract(1); break; } count++; if (!isspace(c)) { if ((!state) && (isalpha(c))) isconversion = 1; if (!state && !sticky) Putc(' ',s); Putc(c,s); sticky = 0; state = 1; } else { if (!sticky) Putc(' ',s); sticky = 1; } } Chop(s); yylval.str = s; while(Replaceall(s,"[ ", "[")); if (isconversion) { String *ns = Swig_symbol_string_qualify(s,0); yylval.str = ns; } if (isconversion && !rename_active) { char *t = Char(s) + 9; if (!((strcmp(t,"new") == 0) || (strcmp(t,"delete") == 0) || (strcmp(t,"new[]") == 0) || (strcmp(t,"delete[]") == 0))) { /* retract(strlen(t));*/ retract(count); return COPERATOR; } } return(OPERATOR); } if (strcmp(yytext,"throw") == 0) return(THROW); if (strcmp(yytext,"try") == 0) return (yylex()); if (strcmp(yytext,"catch") == 0) return (CATCH); if (strcmp(yytext,"inline") == 0) return(yylex()); if (strcmp(yytext,"mutable") == 0) return(yylex()); if (strcmp(yytext,"explicit") == 0) return(yylex()); if (strcmp(yytext,"export") == 0) return(yylex()); if (strcmp(yytext,"typename") == 0) return (TYPENAME); if (strcmp(yytext,"template") == 0) { yylval.ivalue = cparse_line; return(TEMPLATE); } if (strcmp(yytext,"delete") == 0) { return(DELETE); } if (strcmp(yytext,"using") == 0) { return(USING); } if (strcmp(yytext,"namespace") == 0) { return(NAMESPACE); } } else { if (strcmp(yytext,"class") == 0) { Swig_warning(WARN_PARSE_CLASS_KEYWORD,cparse_file,cparse_line, "class keyword used, but not in C++ mode.\n"); } } /* Objective-C keywords */ #ifdef OBJECTIVEC if ((ObjC) && (yytext[0] == '@')) { if (strcmp(yytext,"@interface") == 0) return (OC_INTERFACE); if (strcmp(yytext,"@end") == 0) return (OC_END); if (strcmp(yytext,"@public") == 0) return (OC_PUBLIC); if (strcmp(yytext,"@private") == 0) return (OC_PRIVATE); if (strcmp(yytext,"@protected") == 0) return (OC_PROTECTED); if (strcmp(yytext,"@class") == 0) return(OC_CLASS); if (strcmp(yytext,"@implementation") == 0) return(OC_IMPLEMENT); if (strcmp(yytext,"@protocol") == 0) return(OC_PROTOCOL); } #endif /* Misc keywords */ if (strcmp(yytext,"extern") == 0) return(EXTERN); if (strcmp(yytext,"const") == 0) return(CONST); if (strcmp(yytext,"static") == 0) return(STATIC); if (strcmp(yytext,"struct") == 0) return(STRUCT); if (strcmp(yytext,"union") == 0) return(UNION); if (strcmp(yytext,"enum") == 0) return(ENUM); if (strcmp(yytext,"sizeof") == 0) return(SIZEOF); if (strcmp(yytext,"typedef") == 0) { yylval.ivalue = 0; return(TYPEDEF); } /* Ignored keywords */ if (strcmp(yytext,"volatile") == 0) return(VOLATILE); /* SWIG directives */ } else { if (strcmp(yytext,"%module") == 0) return(MODULE); if (strcmp(yytext,"%insert") == 0) return(INSERT); if (strcmp(yytext,"%name") == 0) return(NAME); if (strcmp(yytext,"%rename") == 0) { rename_active = 1; return(RENAME); } if (strcmp(yytext,"%namewarn") == 0) { rename_active = 1; return (NAMEWARN); } if (strcmp(yytext,"%includefile") == 0) return(INCLUDE); if (strcmp(yytext,"%val") == 0) { Swig_warning(WARN_DEPRECATED_VAL, cparse_file, cparse_line, "%%val directive deprecated (ignored).\n"); return (yylex()); } if (strcmp(yytext,"%out") == 0) { Swig_warning(WARN_DEPRECATED_OUT, cparse_file, cparse_line, "%%out directive deprecated (ignored).\n"); return(yylex()); } if (strcmp(yytext,"%constant") == 0) return(CONSTANT); if (strcmp(yytext,"%typedef") == 0) { yylval.ivalue = 1; return(TYPEDEF); } if (strcmp(yytext,"%native") == 0) return(NATIVE); if (strcmp(yytext,"%pragma") == 0) return(PRAGMA); if (strcmp(yytext,"%extend") == 0) return(EXTEND); if (strcmp(yytext,"%fragment") == 0) return(FRAGMENT); if (strcmp(yytext,"%inline") == 0) return(INLINE); if (strcmp(yytext,"%typemap") == 0) return(TYPEMAP); if (strcmp(yytext,"%feature") == 0) return(FEATURE); if (strcmp(yytext,"%except") == 0) return(EXCEPT); if (strcmp(yytext,"%importfile") == 0) return(IMPORT); if (strcmp(yytext,"%echo") == 0) return(ECHO); if (strcmp(yytext,"%apply") == 0) return(APPLY); if (strcmp(yytext,"%clear") == 0) return(CLEAR); if (strcmp(yytext,"%types") == 0) return(TYPES); if (strcmp(yytext,"%parms") == 0) return(PARMS); if (strcmp(yytext,"%varargs") == 0) return(VARARGS); if (strcmp(yytext,"%template") == 0) return (SWIGTEMPLATE); if (strcmp(yytext,"%warn") == 0) return(WARN); } /* Have an unknown identifier, as a last step, we'll do a typedef lookup on it. */ /* Need to fix this */ if (check_typedef) { if (SwigType_istypedef(yytext)) { yylval.type = NewString(yytext); return(TYPE_TYPEDEF); } } yylval.id = Swig_copy_string(yytext); last_id = 1; return(ID); case POUND: return yylex(); default: return(l); } }
static int name_mangle(String *r) { char *c; int special; special = 0; Replaceall(r,"::","_"); c = Char(r); while (*c) { if (!isalnum((int) *c) && (*c != '_')) { special = 1; switch(*c) { case '+': *c = 'a'; break; case '-': *c = 's'; break; case '*': *c = 'm'; break; case '/': *c = 'd'; break; case '<': *c = 'l'; break; case '>': *c = 'g'; break; case '=': *c = 'e'; break; case ',': *c = 'c'; break; case '(': *c = 'p'; break; case ')': *c = 'P'; break; case '[': *c = 'b'; break; case ']': *c = 'B'; break; case '^': *c = 'x'; break; case '&': *c = 'A'; break; case '|': *c = 'o'; break; case '~': *c = 'n'; break; case '!': *c = 'N'; break; case '%': *c = 'M'; break; case '.': *c = 'f'; break; case '?': *c = 'q'; break; default: *c = '_'; break; } } c++; } if (special) Append(r,"___"); return special; }
String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname, SwigType *decl, String *oldname) { String *nname = 0; String *result = 0; String *name = NewString(cname); Hash *wrn = 0; String *rdecl = 0; String *rname = 0; /* very specific hack for template constructors/destructors */ #ifdef SWIG_DEBUG Printf(stdout, "Swig_name_make: looking for %s %s %s %s\n", prefix, name, decl, oldname); #endif if (name && n && SwigType_istemplate(name)) { String *nodetype = nodeType(n); if (nodetype && (Equal(nodetype, "constructor") || Equal(nodetype, "destructor"))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { Append(nprefix, "::"); Append(nprefix, tprefix); Delete(tprefix); rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); Replaceall(rdecl, name, rname); #ifdef SWIG_DEBUG Printf(stdout, "SWIG_name_make: use new name %s %s : %s %s\n", name, decl, rname, rdecl); #endif decl = rdecl; Delete(name); name = rname; } } if (rename_hash || rename_list || namewarn_hash || namewarn_list) { Hash *rn = Swig_name_object_get(Swig_name_rename_hash(), prefix, name, decl); if (!rn || !Swig_name_match_nameobj(rn, n)) { rn = Swig_name_nameobj_lget(Swig_name_rename_list(), n, prefix, name, decl); if (rn) { String *sfmt = Getattr(rn, "sourcefmt"); int fullname = GetFlag(rn, "fullname"); if (fullname && prefix) { String *sname = NewStringf("%s::%s", prefix, name); Delete(name); name = sname; prefix = 0; } if (sfmt) { String *sname = NewStringf(sfmt, name); Delete(name); name = sname; } } } if (rn) { String *newname = Getattr(rn, "name"); int fullname = GetFlag(rn, "fullname"); result = apply_rename(newname, fullname, prefix, name); } if (result && !Equal(result, name)) { /* operators in C++ allow aliases, we look for them */ char *cresult = Char(result); if (cresult && (strncmp(cresult, "operator ", 9) == 0)) { String *nresult = Swig_name_make(n, prefix, result, decl, oldname); if (!Equal(nresult, result)) { Delete(result); result = nresult; } else { Delete(nresult); } } } nname = result ? result : name; wrn = Swig_name_namewarn_get(n, prefix, nname, decl); if (wrn) { String *rename = Getattr(wrn, "rename"); if (rename) { String *msg = Getattr(wrn, "name"); int fullname = GetFlag(wrn, "fullname"); if (result) Delete(result); result = apply_rename(rename, fullname, prefix, name); if ((msg) && (Len(msg))) { if (!Getmeta(nname, "already_warned")) { if (n) { SWIG_WARN_NODE_BEGIN(n); Swig_warning(0, Getfile(n), Getline(n), "%s\n", msg); SWIG_WARN_NODE_END(n); } else { Swig_warning(0, Getfile(name), Getline(name), "%s\n", msg); } Setmeta(nname, "already_warned", "1"); } } } } } if (!result || !Len(result)) { if (result) Delete(result); if (oldname) { result = NewString(oldname); } else { result = NewString(cname); } } Delete(name); #ifdef SWIG_DEBUG Printf(stdout, "Swig_name_make: result '%s' '%s'\n", cname, result); #endif return result; }
int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { ParmList *parms; Parm *prefix_args; Parm *postfix_args; Parm *p; ParmList *directorparms; SwigType *type; String *membername; String *mangled; Node *classNode; int use_director; classNode = Swig_methodclass(n); use_director = Swig_directorclass(n); membername = Swig_name_construct(classname); mangled = Swig_name_mangle(membername); parms = CopyParmList(nonvoid_parms(Getattr(n,"parms"))); /* Prepend the list of prefix_args (if any) */ prefix_args = Getattr(n,"director:prefix_args"); if (prefix_args != NIL) { Parm *p2, *p3; directorparms = CopyParmList(prefix_args); for (p = directorparms; nextSibling(p); p = nextSibling(p)); for (p2 = parms; p2; p2 = nextSibling(p2)) { p3 = CopyParm(p2); set_nextSibling(p, p3); p = p3; } } else directorparms = parms; postfix_args = Getattr(n,"director:postfix_args"); if (postfix_args != NIL) { Parm *p2, *p3, *p4; if (prefix_args == NIL) /* no prefix args from above. */ directorparms = CopyParmList(parms); if (directorparms != NIL) { p2 = directorparms; for ( ; nextSibling(p2); p2 = nextSibling(p2)); for (p3 = postfix_args; p3; p3 = nextSibling(p3)) { p4 = CopyParm(p3); set_nextSibling(p2, p4); p2 = p4; } } else directorparms = CopyParmList(postfix_args); } type = NewString(classname); SwigType_add_pointer(type); if (flags & CWRAP_EXTEND) { String *code = Getattr(n,"code"); if (code) { String *wrap, *s; if (Getattr(n,"sym:overloaded") && code) { Append(mangled,Getattr(n,"sym:overname")); } s = NewStringf("%s(%s)", mangled, ParmList_str(parms)); wrap = SwigType_str(type,s); Delete(s); Printv(wrap,code,"\n",NIL); Setattr(n,"wrap:code",wrap); Delete(wrap); } Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cfunction_call(mangled,parms))); } else { if (cplus) { /* if a C++ director class exists, create it rather than the original class */ if (use_director) { int abstract = Getattr(n, "abstract") != 0; Node *parent = Swig_methodclass(n); String *name = Getattr(parent, "sym:name"); String* directorname = NewStringf("SwigDirector_%s", name); String* action = NewString(""); String* tmp_none_comparison = Copy(none_comparison); String* director_call; String* nodirector_call; Replaceall( tmp_none_comparison, "$arg", "arg1" ); director_call = Swig_cppconstructor_director_call(directorname, directorparms); nodirector_call = Swig_cppconstructor_nodirector_call(classname, parms); if (abstract) { /* whether or not the abstract class has been subclassed in python, * create a director instance (there's no way to create a normal * instance). if any of the pure virtual methods haven't been * implemented in the target language, calls to those methods will * generate Swig::DirectorPureVirtualException exceptions. */ Printv(action, Swig_cresult(type, "result", director_call), NIL); } else { /* (scottm): The code for creating a new director is now a string template that gets passed in via the director_ctor argument. $comparison : an 'if' comparison from none_comparison $director_new: Call new for director class $nondirector_new: Call new for non-director class */ Printv(action, director_ctor, NIL); Replaceall( action, "$comparison", tmp_none_comparison); Replaceall( action, "$director_new", Swig_cresult(type, "result", director_call) ); Replaceall( action, "$nondirector_new", Swig_cresult(type, "result", nodirector_call) ); } Setattr(n, "wrap:action", action); Delete(tmp_none_comparison); Delete(action); Delete(directorname); } else { Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cppconstructor_call(classname,parms))); } } else { Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cconstructor_call(classname))); } } Setattr(n,"type",type); Setattr(n,"parms", parms); Delete(type); if (directorparms != parms) Delete(directorparms); Delete(parms); Delete(mangled); Delete(membername); return SWIG_OK; }
void Swig_filename_unescape(String *filename) { (void)filename; #if defined(_WIN32) Replaceall(filename, "\\\\", "\\"); #endif }
String *Swig_string_rxspencer(String *s) { String *res = 0; if (Len(s)) { const char *cs = Char(s); const char *cb; const char *ce; if (*cs == '[') { int retval; regex_t compiled; cb = ++cs; ce = skip_delim('[', ']', cb); if (ce) { char bregexp[512]; strncpy(bregexp, cb, ce - cb); bregexp[ce - cb] = '\0'; ++ce; retval = regcomp(&compiled, bregexp, REG_EXTENDED); if (retval == 0) { cs = ce; if (*cs == '[') { cb = ++cs; ce = skip_delim('[', ']', cb); if (ce) { const char *cvalue = ce + 1; int nsub = (int) compiled.re_nsub + 1; regmatch_t *pmatch = (regmatch_t *) malloc(sizeof(regmatch_t) * (nsub)); retval = regexec(&compiled, cvalue, nsub, pmatch, 0); if (retval != REG_NOMATCH) { char *spos = 0; res = NewStringWithSize(cb, ce - cb); spos = Strchr(res, '@'); while (spos) { char cd = *(++spos); if (isdigit(cd)) { char arg[8]; size_t len; int i = cd - '0'; sprintf(arg, "@%d", i); if (i < nsub && (len = pmatch[i].rm_eo - pmatch[i].rm_so)) { char value[256]; strncpy(value, cvalue + pmatch[i].rm_so, len); value[len] = 0; Replaceall(res, arg, value); } else { Replaceall(res, arg, ""); } spos = Strchr(res, '@'); } else if (cd == '@') { spos = strchr(spos + 1, '@'); } } } free(pmatch); } } } regfree(&compiled); } } } if (!res) res = NewStringEmpty(); return res; }