void Swig_extend_merge(Node *cls, Node *am) { Node *n; Node *csym; n = firstChild(am); while (n) { String *symname; if (Strcmp(nodeType(n),"constructor") == 0) { symname = Getattr(n,"sym:name"); if (symname) { if (Strcmp(symname,Getattr(n,"name")) == 0) { /* If the name and the sym:name of a constructor are the same, then it hasn't been renamed. However---the name of the class itself might have been renamed so we need to do a consistency check here */ if (Getattr(cls,"sym:name")) { Setattr(n,"sym:name", Getattr(cls,"sym:name")); } } } } symname = Getattr(n,"sym:name"); DohIncref(symname); if ((symname) && (!Getattr(n,"error"))) { /* Remove node from its symbol table */ Swig_symbol_remove(n); csym = Swig_symbol_add(symname,n); if (csym != n) { /* Conflict with previous definition. Nuke previous definition */ String *e = NewStringEmpty(); String *en = NewStringEmpty(); String *ec = NewStringEmpty(); Printf(ec,"Identifier '%s' redefined by %%extend (ignored),",symname); Printf(en,"%%extend definition of '%s'.",symname); SWIG_WARN_NODE_BEGIN(n); Swig_warning(WARN_PARSE_REDEFINED,Getfile(csym),Getline(csym),"%s\n",ec); Swig_warning(WARN_PARSE_REDEFINED,Getfile(n),Getline(n),"%s\n",en); SWIG_WARN_NODE_END(n); Printf(e,"%s:%d:%s\n%s:%d:%s\n",Getfile(csym),Getline(csym),ec, Getfile(n),Getline(n),en); Setattr(csym,"error",e); Delete(e); Delete(en); Delete(ec); Swig_symbol_remove(csym); /* Remove class definition */ Swig_symbol_add(symname,n); /* Insert extend definition */ } } n = nextSibling(n); } }
String *Swig_stringify_with_location(DOH *object) { String *str = NewStringEmpty(); if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); if (object) { int line = Getline(object); String *formatted_filename = format_filename(Getfile(object)); if (line > 0) { Printf(str, diag_line_fmt, formatted_filename, line); } else { Printf(str, diag_eof_fmt, formatted_filename); } if (Len(object) == 0) { Printf(str, "[EMPTY]"); } else { Printf(str, "[%s]", object); } Delete(formatted_filename); } else { Printf(str, "[NULL]"); } return str; }
/* internal function for processing an encoding */ static DOH *encode(char *name, DOH *s) { DOH *handle, *ns; DOH *(*fn) (DOH *); long pos; char *cfmt = strchr(name, ':'); DOH *tmp = 0; if (cfmt) { tmp = NewString(cfmt + 1); Append(tmp, s); Setfile(tmp, Getfile((DOH *) s)); Setline(tmp, Getline((DOH *) s)); *cfmt = '\0'; } if (!encodings || !(handle = Getattr(encodings, name))) { return Copy(s); } if (tmp) s = tmp; pos = Tell(s); Seek(s, 0, SEEK_SET); fn = (DOH *(*)(DOH *)) Data(handle); ns = (*fn) (s); Seek(s, pos, SEEK_SET); if (tmp) Delete(tmp); return ns; }
Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl) { if (!namewarn_hash && !namewarn_list) return 0; if (n) { /* Return in the obvious cases */ if (!name || !Swig_need_name_warning(n)) { return 0; } else { String *access = Getattr(n, "access"); int is_public = !access || Equal(access, "public"); if (!is_public && !Swig_need_protected(n)) { return 0; } } } if (name) { /* Check to see if the name is in the hash */ Hash *wrn = Swig_name_object_get(Swig_name_namewarn_hash(), prefix, name, decl); if (wrn && !Swig_name_match_nameobj(wrn, n)) wrn = 0; if (!wrn) { wrn = Swig_name_nameobj_lget(Swig_name_namewarn_list(), n, prefix, name, decl); } if (wrn && Getattr(wrn, "error")) { if (n) { Swig_error(Getfile(n), Getline(n), "%s\n", Getattr(wrn, "name")); } else { Swig_error(cparse_file, cparse_line, "%s\n", Getattr(wrn, "name")); } } return wrn; } else { return 0; } }
int Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; char temp[512]; va_start(ap, n); name = va_arg(ap, char *); while (name) { int newref = 0; int opt = 0; if (*name == '*') { newref = 1; name++; } else if (*name == '?') { newref = 1; opt = 1; name++; } obj = Getattr(n,name); if (!opt && !obj) { Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", Getfile(n), Getline(n), name, nodeType(n)); assert(obj); } if (!obj) obj = DohNone; if (newref) { /* Save a copy of the attribute */ strcpy(temp,ns); strcat(temp,":"); strcat(temp,name); Setattr(n,temp,obj); } name = va_arg(ap, char *); } va_end(ap); /* Save the view */ { String *view = Getattr(n,"view"); if (view) { if (Strcmp(view,ns) != 0) { strcpy(temp,ns); strcat(temp,":view"); Setattr(n,temp,view); Setattr(n,"view",ns); } } else { Setattr(n,"view",ns); } } return 1; }
Node *copyNode(Node *n) { Iterator ki; Node *c = NewHash(); for (ki = First(n); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { Setattr(c, ki.key, Copy(ki.item)); } } Setfile(c, Getfile(n)); Setline(c, Getline(n)); return c; }
void Swig_extend_unused_check(void) { Iterator ki; if (!extendhash) return; for (ki = First(extendhash); ki.key; ki = Next(ki)) { if (!Strchr(ki.key,'<')) { SWIG_WARN_NODE_BEGIN(ki.item); Swig_warning(WARN_PARSE_EXTEND_UNDEF,Getfile(ki.item), Getline(ki.item), "%%extend defined for an undeclared class %s.\n", SwigType_namestr(ki.key)); SWIG_WARN_NODE_END(ki.item); } } }
void SwigScanner_skip_line(SwigScanner *s) { char c; int done = 0; Clear(s->text); Setfile(s->text,Getfile(s->str)); Setline(s->text,Getline(s->str)); while (!done) { if ((c = nextchar(s)) == 0) return; if (c == '\\') c = nextchar(s); else if (c == '\n') done = 1; } return; }
Parm *CopyParm(Parm *p) { Parm *np = NewHash(); Iterator ki; for (ki = First(p); ki.key; ki = Next(ki)) { if (DohIsString(ki.item)) { DOH *c = Copy(ki.item); Setattr(np,ki.key,c); Delete(c); } } Setfile(np, Getfile(p)); Setline(np, Getline(p)); return np; }
void Swig_cparse_replace_descriptor(String *s) { char tmp[512]; String *arg = 0; SwigType *t; char *c = 0; while ((c = strstr(Char(s), "$descriptor("))) { char *d = tmp; int level = 0; while (*c) { if (*c == '(') level++; if (*c == ')') { level--; if (level == 0) { break; } } *d = *c; d++; c++; } *d = 0; arg = NewString(tmp + 12); t = Swig_cparse_type(arg); Delete(arg); arg = 0; if (t) { String *mangle; String *descriptor; mangle = SwigType_manglestr(t); descriptor = NewStringf("SWIGTYPE%s", mangle); SwigType_remember(t); *d = ')'; d++; *d = 0; Replace(s, tmp, descriptor, DOH_REPLACE_ANY); Delete(mangle); Delete(descriptor); Delete(t); } else { Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n"); break; } } }
void Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; va_start(ap, n); name = va_arg(ap, char *); while (name) { int newref = 0; int opt = 0; if (*name == '*') { newref = 1; name++; } else if (*name == '?') { newref = 1; opt = 1; name++; } obj = Getattr(n, name); if (!opt && !obj) { Swig_error(Getfile(n), Getline(n), "Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", name, nodeType(n)); assert(obj); } if (!obj) obj = DohNone; if (newref) { /* Save a copy of the attribute */ Setattr(n, NewStringf("%s:%s", ns, name), obj); } name = va_arg(ap, char *); } va_end(ap); /* Save the view */ { String *view = Getattr(n, "view"); if (view) { if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); Setattr(n, "view", NewString(ns)); } } else { Setattr(n, "view", NewString(ns)); } } }
void Swig_fragment_emit(String *name) { String *code; if (!fragments) return; code = Getattr(fragments,name); if (code) { String *section = Getmeta(code,"section"); if (section) { File *f = Swig_filebyname(section); if (!f) { Swig_error(Getfile(code),Getline(code),"Bad section '%s' for code fragment '%s'\n", section,name); } else { Printf(f,"%s\n",code); } } Delattr(fragments,name); } }
void Swig_print_tags(DOH *obj, DOH *root) { DOH *croot, *newroot; DOH *cobj; if (!root) croot = NewString(""); else croot = root; while (obj) { Printf(stdout,"%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(obj)); cobj = firstChild(obj); if (cobj) { newroot = NewStringf("%s . %s",croot,nodeType(obj)); Swig_print_tags(cobj,newroot); Delete(newroot); } obj = nextSibling(obj); } if (!root) Delete(croot); }
void Swig_fragment_register(Node *fragment) { if (Getattr(fragment, "emitonly")) { Swig_fragment_emit(fragment); return; } else { String *name = Copy(Getattr(fragment, "value")); String *type = Getattr(fragment, "type"); if (type) { SwigType *rtype = SwigType_typedef_resolve_all(type); String *mangle = Swig_string_mangle(type); Append(name, mangle); Delete(mangle); Delete(rtype); if (debug) Printf(stdout, "register fragment %s %s\n", name, type); } if (!fragments) { fragments = NewHash(); } if (!Getattr(fragments, name)) { String *section = Copy(Getattr(fragment, "section")); String *ccode = Copy(Getattr(fragment, "code")); Hash *kwargs = Getattr(fragment, "kwargs"); Setmeta(ccode, "section", section); if (kwargs) { Setmeta(ccode, "kwargs", kwargs); } Setfile(ccode, Getfile(fragment)); Setline(ccode, Getline(fragment)); /* Replace $descriptor() macros */ Swig_cparse_replace_descriptor(ccode); Setattr(fragments, name, ccode); if (debug) Printf(stdout, "registering fragment %s %s\n", name, section); Delete(section); Delete(ccode); } Delete(name); } }
void Swig_print_tags(DOH *obj, DOH *root) { DOH *croot, *newroot; DOH *cobj; if (!root) croot = NewStringEmpty(); else croot = root; while (obj) { Swig_diagnostic(Getfile(obj), Getline(obj), "%s . %s\n", croot, nodeType(obj)); cobj = firstChild(obj); if (cobj) { newroot = NewStringf("%s . %s", croot, nodeType(obj)); Swig_print_tags(cobj, newroot); Delete(newroot); } obj = nextSibling(obj); } if (!root) Delete(croot); }
Parm *CopyParm(Parm *p) { SwigType *t; String *name; String *lname; String *value; String *ignore; String *alttype; String *byname; Parm *np = NewHash(); t = Getattr(p,"type"); name = Getattr(p,"name"); lname = Getattr(p,"lname"); value = Getattr(p,"value"); ignore = Getattr(p,"ignore"); alttype = Getattr(p,"alttype"); byname = Getattr(p, "arg:byname"); if (t) Setattr(np,"type",Copy(t)); if (name) Setattr(np,"name",Copy(name)); if (lname) Setattr(np,"lname", Copy(lname)); if (value) Setattr(np,"value", Copy(value)); if (ignore) Setattr(np,"ignore", Copy(ignore)); if (alttype) Setattr(np,"alttype", Copy(alttype)); if (byname) Setattr(np, "arg:byname", Copy(byname)); Setfile(np,Getfile(p)); Setline(np,Getline(p)); return np; }
Parm *NewParm(SwigType *type, const_String_or_char_ptr name, Node *file_line_node) { Parm *p = NewParmWithoutFileLineInfo(type, name); Setfile(p, Getfile(file_line_node)); Setline(p, Getline(file_line_node)); return p; }
String * SwigScanner_get_file(SwigScanner *s) { return Getfile(s->str); }
static int look(SwigScanner *s) { int state; int c = 0; state = 0; Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); while(1) { switch(state) { case 0 : if((c = nextchar(s)) == 0) return(0); /* Process delimeters */ if (c == '\n') { return SWIG_TOKEN_ENDLINE; } else if (!isspace(c)) { retract(s,1); state = 1000; Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); } break; case 1000: if ((c = nextchar(s)) == 0) return (0); if (c == '%') state = 4; /* Possibly a SWIG directive */ /* Look for possible identifiers */ else if ((isalpha(c)) || (c == '_') || (strchr(s->idstart,c))) state = 7; /* Look for single character symbols */ else if (c == '(') return SWIG_TOKEN_LPAREN; else if (c == ')') return SWIG_TOKEN_RPAREN; else if (c == ';') return SWIG_TOKEN_SEMI; else if (c == ',') return SWIG_TOKEN_COMMA; else if (c == '*') return SWIG_TOKEN_STAR; else if (c == '}') return SWIG_TOKEN_RBRACE; else if (c == '{') return SWIG_TOKEN_LBRACE; else if (c == '=') state = 33; else if (c == '+') return SWIG_TOKEN_PLUS; else if (c == '-') return SWIG_TOKEN_MINUS; else if (c == '&') state = 31; else if (c == '|') state = 32; else if (c == '^') return SWIG_TOKEN_XOR; else if (c == '<') state = 60; else if (c == '>') state = 61; else if (c == '~') return SWIG_TOKEN_NOT; else if (c == '!') state = 3; else if (c == '\\') return SWIG_TOKEN_BACKSLASH; else if (c == '[') return SWIG_TOKEN_LBRACKET; else if (c == ']') return SWIG_TOKEN_RBRACKET; else if (c == '@') return SWIG_TOKEN_AT; else if (c == '$') return SWIG_TOKEN_DOLLAR; else if (c == '#') return SWIG_TOKEN_POUND; /* Look for multi-character sequences */ else if (c == '/') state = 1; /* Comment (maybe) */ else if (c == '\"') { state = 2; /* Possibly a string */ s->string_start = s->line; } else if (c == ':') state = 5; /* maybe double colon */ else if (c == '0') state = 83; /* An octal or hex value */ else if (c == '\'') { s->string_start = s->line; state = 9; /* A character constant */ } else if (c == '`') { s->string_start = s->line; state = 900; } else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ else if (isdigit(c)) state = 8; /* A numerical value */ else state = 99; /* An error */ break; case 1: /* Comment block */ if ((c = nextchar(s)) == 0) return(0); if (c == '/') { state = 10; /* C++ style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text," "); } else if (c == '*') { state = 11; /* C style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text," "); } else { retract(s,1); return SWIG_TOKEN_SLASH; } break; case 10: /* C++ style comment */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated comment",comment_start); */ return 0; } if (c == '\n') { return SWIG_TOKEN_ENDLINE; } else { state = 10; } break; case 11: /* C style comment block */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated comment",comment_start); */ return 0; } if (c == '*') { state = 12; } else { state = 11; } break; case 12: /* Still in C style comment */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated comment",comment_start); */ return 0; } if (c == '*') { state = 12; } else if (c == '/') { Clear(s->text); state = 0; } else { state = 11; } break; case 2: /* Processing a string */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated string", string_start); */ return 0; } if (c == '\"') { return SWIG_TOKEN_STRING; } else if (c == '\\') { state = 21; /* Possibly an escape sequence. */ break; } else state = 2; break; case 21: /* An escape sequence. get next character, then go back to processing strings */ if ((c = nextchar(s)) == 0) return 0; state = 2; break; case 3: /* Maybe a not equals */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LNOT; else if (c == '=') return SWIG_TOKEN_NOTEQUAL; else { retract(s,1); return SWIG_TOKEN_LNOT; } break; case 31: /* AND or Logical AND */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_AND; else if (c == '&') return SWIG_TOKEN_LAND; else { retract(s,1); return SWIG_TOKEN_AND; } break; case 32: /* OR or Logical OR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_OR; else if (c == '|') return SWIG_TOKEN_LOR; else { retract(s,1); return SWIG_TOKEN_OR; } break; case 33: /* EQUAL or EQUALTO */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_EQUAL; else if (c == '=') return SWIG_TOKEN_EQUALTO; else { retract(s,1); return SWIG_TOKEN_EQUAL; } break; case 4: /* A wrapper generator directive (maybe) */ if (( c= nextchar(s)) == 0) return SWIG_TOKEN_PERCENT; if (c == '{') { state = 40; /* Include block */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); s->start_line = s->line; } else if (strchr(s->idstart,'%') && ((isalpha(c)) || (c == '_'))) state = 7; else { retract(s,1); return SWIG_TOKEN_PERCENT; } break; case 40: /* Process an include block */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated code block.", start_line); */ return 0; } if (c == '%') state = 41; break; case 41: /* Still processing include block */ if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated code block.", start_line); */ return 0; } if (c == '}') { Delitem(s->text,DOH_END); Delitem(s->text,DOH_END); return SWIG_TOKEN_CODEBLOCK; } else { state = 40; } break; case 5: /* Maybe a double colon */ if (( c = nextchar(s)) == 0) return SWIG_TOKEN_COLON; if ( c == ':') return SWIG_TOKEN_DCOLON; else { retract(s,1); return SWIG_TOKEN_COLON; } break; case 60: /* shift operators */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LESSTHAN; if (c == '<') return SWIG_TOKEN_LSHIFT; else if (c == '=') return SWIG_TOKEN_LTEQUAL; else { retract(s,1); return SWIG_TOKEN_LESSTHAN; } break; case 61: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_GREATERTHAN; if (c == '>') return SWIG_TOKEN_RSHIFT; else if (c == '=') return SWIG_TOKEN_GTEQUAL; else { retract(s,1); return SWIG_TOKEN_GREATERTHAN; } break; case 7: /* Identifier */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ID; if (isalnum(c) || (c == '_') || (c == '$')) { state = 7; } else { retract(s,1); return SWIG_TOKEN_ID; } break; case 8: /* A numerical digit */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (c == '.') {state = 81;} else if ((c == 'e') || (c == 'E')) {state = 86;} else if ((c == 'f') || (c == 'F')) { Delitem(s->text,DOH_END); return SWIG_TOKEN_FLOAT; } else if (isdigit(c)) { state = 8;} else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s,1); return SWIG_TOKEN_INT; } break; case 81: /* A floating pointer number of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 81; else if ((c == 'e') || (c == 'E')) state = 82; else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { Delitem(s->text,DOH_END); return SWIG_TOKEN_FLOAT; } else { retract(s,1); return(SWIG_TOKEN_DOUBLE); } break; case 82: if ((c = nextchar(s)) == 0) { retract(s,1); return SWIG_TOKEN_INT; } if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(s,2); return(SWIG_TOKEN_INT); } break; case 83: /* Might be a hexidecimal or octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'x') || (c == 'X')) state = 85; else if (c == '.') state = 81; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s,1); return SWIG_TOKEN_INT; } break; case 84: /* This is an octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s,1); return SWIG_TOKEN_INT; } break; case 85: /* This is an hex number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if ((isdigit(c)) || (c=='a') || (c=='b') || (c=='c') || (c=='d') || (c=='e') || (c=='f') || (c=='A') || (c=='B') || (c=='C') || (c=='D') || (c=='E') || (c=='F')) state = 85; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s,1); return SWIG_TOKEN_INT; } break; case 86: /* Rest of floating point number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 86; else if ((c == 'f') || (c == 'F')) { Delitem(s->text,DOH_END); return SWIG_TOKEN_FLOAT; } else if ((c == 'l') || (c == 'L')) { Delitem(s->text,DOH_END); return SWIG_TOKEN_DOUBLE; } else { retract(s,1); return SWIG_TOKEN_DOUBLE; } break; case 87 : /* A long integer of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONG; } else if ((c == 'l') || (c == 'L')) { state = 870; } else { retract(s,1); return SWIG_TOKEN_LONG; } break; /* A long long integer */ case 870: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONGLONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONGLONG; } else { retract(s,1); return SWIG_TOKEN_LONGLONG; } /* An unsigned number */ case 88: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_UINT; if ((c == 'l') || (c == 'L')) { state = 880; } else { retract(s,1); return SWIG_TOKEN_UINT; } break; /* Possibly an unsigned long long or unsigned long */ case 880: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ULONG; if ((c == 'l') || (c == 'L')) return SWIG_TOKEN_ULONGLONG; else { retract(s,1); return SWIG_TOKEN_ULONG; } /* A character constant */ case 9: if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated character constant", string_start); */ return 0; } if (c == '\'') { return(SWIG_TOKEN_CHAR); } else if (c == '\\') state = 91; break; case 91: if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated character constant", string_start); */ return 0; } state = 9; break; /* A period or maybe a floating point number */ case 100: if ((c = nextchar(s)) == 0) return (0); if (isdigit(c)) state = 81; else { retract(s,1); return SWIG_TOKEN_PERIOD; } break; /* An illegal character */ /* Reverse string */ case 900: if ((c = nextchar(s)) == 0) { /* add_error(0,"Unterminated character constant", string_start); */ return 0; } if (c == '`') { return(SWIG_TOKEN_RSTRING); } break; default: return SWIG_TOKEN_ILLEGAL; } } }
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; }
String *Scanner_file(Scanner *s) { return Getfile(s->str); }
int Scanner_skip_balanced(Scanner *s, int startchar, int endchar) { char c; int num_levels = 1; int state = 0; char temp[2] = { 0, 0 }; String *locator = 0; temp[0] = (char) startchar; Clear(s->text); Setfile(s->text, Getfile(s->str)); Setline(s->text, s->line); Append(s->text, temp); while (num_levels > 0) { if ((c = nextchar(s)) == 0) { Delete(locator); return -1; } switch (state) { case 0: if (c == startchar) num_levels++; else if (c == endchar) num_levels--; else if (c == '/') state = 10; else if (c == '\"') state = 20; else if (c == '\'') state = 30; break; case 10: if (c == '/') state = 11; else if (c == '*') state = 12; else if (c == startchar) { state = 0; num_levels++; } else state = 0; break; case 11: if (c == '\n') state = 0; else state = 11; break; case 12: /* first character inside C comment */ if (c == '*') state = 14; else if (c == '@') state = 40; else state = 13; break; case 13: if (c == '*') state = 14; break; case 14: /* possible end of C comment */ if (c == '*') state = 14; else if (c == '/') state = 0; else state = 13; break; case 20: if (c == '\"') state = 0; else if (c == '\\') state = 21; break; case 21: state = 20; break; case 30: if (c == '\'') state = 0; else if (c == '\\') state = 31; break; case 31: state = 30; break; /* 40-45 SWIG locator checks - a C comment with contents starting: @SWIG */ case 40: state = (c == 'S') ? 41 : (c == '*') ? 14 : 13; break; case 41: state = (c == 'W') ? 42 : (c == '*') ? 14 : 13; break; case 42: state = (c == 'I') ? 43 : (c == '*') ? 14 : 13; break; case 43: state = (c == 'G') ? 44 : (c == '*') ? 14 : 13; if (c == 'G') { Delete(locator); locator = NewString("/*@SWIG"); } break; case 44: if (c == '*') state = 45; Putc(c, locator); break; case 45: /* end of SWIG locator in C comment */ if (c == '/') { state = 0; Putc(c, locator); Scanner_locator(s, locator); } else { /* malformed locator */ state = (c == '*') ? 14 : 13; } break; default: break; } } Delete(locator); return 0; }
static int look(Scanner * s) { int state; int c = 0; state = 0; Clear(s->text); s->start_line = s->line; Setfile(s->text, Getfile(s->str)); while (1) { switch (state) { case 0: if ((c = nextchar(s)) == 0) return (0); /* Process delimiters */ if (c == '\n') { return SWIG_TOKEN_ENDLINE; } else if (!isspace(c)) { retract(s, 1); state = 1000; Clear(s->text); Setline(s->text, s->line); Setfile(s->text, Getfile(s->str)); } break; case 1000: if ((c = nextchar(s)) == 0) return (0); if (c == '%') state = 4; /* Possibly a SWIG directive */ /* Look for possible identifiers */ else if ((isalpha(c)) || (c == '_') || (s->idstart && strchr(s->idstart, c))) state = 7; /* Look for single character symbols */ else if (c == '(') return SWIG_TOKEN_LPAREN; else if (c == ')') return SWIG_TOKEN_RPAREN; else if (c == ';') return SWIG_TOKEN_SEMI; else if (c == ',') return SWIG_TOKEN_COMMA; else if (c == '*') state = 220; else if (c == '}') return SWIG_TOKEN_RBRACE; else if (c == '{') return SWIG_TOKEN_LBRACE; else if (c == '=') state = 33; else if (c == '+') state = 200; else if (c == '-') state = 210; else if (c == '&') state = 31; else if (c == '|') state = 32; else if (c == '^') state = 230; else if (c == '<') state = 60; else if (c == '>') state = 61; else if (c == '~') return SWIG_TOKEN_NOT; else if (c == '!') state = 3; else if (c == '\\') return SWIG_TOKEN_BACKSLASH; else if (c == '[') return SWIG_TOKEN_LBRACKET; else if (c == ']') return SWIG_TOKEN_RBRACKET; else if (c == '@') return SWIG_TOKEN_AT; else if (c == '$') state = 75; else if (c == '#') return SWIG_TOKEN_POUND; else if (c == '?') return SWIG_TOKEN_QUESTION; /* Look for multi-character sequences */ else if (c == '/') { state = 1; /* Comment (maybe) */ s->start_line = s->line; } else if (c == '\"') { state = 2; /* Possibly a string */ s->start_line = s->line; Clear(s->text); } else if (c == ':') state = 5; /* maybe double colon */ else if (c == '0') state = 83; /* An octal or hex value */ else if (c == '\'') { s->start_line = s->line; Clear(s->text); state = 9; /* A character constant */ } else if (c == '`') { s->start_line = s->line; Clear(s->text); state = 900; } else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ else if (isdigit(c)) state = 8; /* A numerical value */ else state = 99; /* An error */ break; case 1: /* Comment block */ if ((c = nextchar(s)) == 0) return (0); if (c == '/') { state = 10; /* C++ style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text, "//"); } else if (c == '*') { state = 11; /* C style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text, "/*"); } else if (c == '=') { return SWIG_TOKEN_DIVEQUAL; } else { retract(s, 1); return SWIG_TOKEN_SLASH; } break; case 10: /* C++ style comment */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '\n') { retract(s,1); return SWIG_TOKEN_COMMENT; } else { state = 10; } break; case 11: /* C style comment block */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '*') { state = 12; } else { state = 11; } break; case 12: /* Still in C style comment */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '*') { state = 12; } else if (c == '/') { return SWIG_TOKEN_COMMENT; } else { state = 11; } break; case 2: /* Processing a string */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } if (c == '\"') { Delitem(s->text, DOH_END); return SWIG_TOKEN_STRING; } else if (c == '\\') { Delitem(s->text, DOH_END); get_escape(s); } else state = 2; break; case 3: /* Maybe a not equals */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LNOT; else if (c == '=') return SWIG_TOKEN_NOTEQUAL; else { retract(s, 1); return SWIG_TOKEN_LNOT; } break; case 31: /* AND or Logical AND or ANDEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_AND; else if (c == '&') return SWIG_TOKEN_LAND; else if (c == '=') return SWIG_TOKEN_ANDEQUAL; else { retract(s, 1); return SWIG_TOKEN_AND; } break; case 32: /* OR or Logical OR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_OR; else if (c == '|') return SWIG_TOKEN_LOR; else if (c == '=') return SWIG_TOKEN_OREQUAL; else { retract(s, 1); return SWIG_TOKEN_OR; } break; case 33: /* EQUAL or EQUALTO */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_EQUAL; else if (c == '=') return SWIG_TOKEN_EQUALTO; else { retract(s, 1); return SWIG_TOKEN_EQUAL; } break; case 4: /* A wrapper generator directive (maybe) */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_PERCENT; if (c == '{') { state = 40; /* Include block */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); s->start_line = s->line; } else if (s->idstart && strchr(s->idstart, '%') && ((isalpha(c)) || (c == '_'))) { state = 7; } else if (c == '=') { return SWIG_TOKEN_MODEQUAL; } else { retract(s, 1); return SWIG_TOKEN_PERCENT; } break; case 40: /* Process an include block */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated block\n"); return SWIG_TOKEN_ERROR; } if (c == '%') state = 41; break; case 41: /* Still processing include block */ if ((c = nextchar(s)) == 0) { set_error(s,s->start_line,"Unterminated code block"); return 0; } if (c == '}') { Delitem(s->text, DOH_END); Delitem(s->text, DOH_END); Seek(s->text,0,SEEK_SET); return SWIG_TOKEN_CODEBLOCK; } else { state = 40; } break; case 5: /* Maybe a double colon */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_COLON; if (c == ':') state = 50; else { retract(s, 1); return SWIG_TOKEN_COLON; } break; case 50: /* DCOLON, DCOLONSTAR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DCOLON; else if (c == '*') return SWIG_TOKEN_DCOLONSTAR; else { retract(s, 1); return SWIG_TOKEN_DCOLON; } break; case 60: /* shift operators */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LESSTHAN; if (c == '<') state = 240; else if (c == '=') return SWIG_TOKEN_LTEQUAL; else { retract(s, 1); return SWIG_TOKEN_LESSTHAN; } break; case 61: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_GREATERTHAN; if (c == '>') state = 250; else if (c == '=') return SWIG_TOKEN_GTEQUAL; else { retract(s, 1); return SWIG_TOKEN_GREATERTHAN; } break; case 7: /* Identifier */ if ((c = nextchar(s)) == 0) state = 71; else if (isalnum(c) || (c == '_') || (c == '$')) { state = 7; } else { retract(s, 1); state = 71; } break; case 71: /* Identifier or true/false */ if (cparse_cplusplus) { if (Strcmp(s->text, "true") == 0) return SWIG_TOKEN_BOOL; else if (Strcmp(s->text, "false") == 0) return SWIG_TOKEN_BOOL; } return SWIG_TOKEN_ID; break; case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { state = 7; } else { retract(s,1); if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR; state = 71; } break; case 8: /* A numerical digit */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (c == '.') { state = 81; } else if ((c == 'e') || (c == 'E')) { state = 82; } else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if (isdigit(c)) { state = 8; } else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 81: /* A floating pointer number of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 81; else if ((c == 'e') || (c == 'E')) state = 820; else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if ((c == 'l') || (c == 'L')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_DOUBLE; } else { retract(s, 1); return (SWIG_TOKEN_DOUBLE); } break; case 82: if ((c = nextchar(s)) == 0) { retract(s, 1); return SWIG_TOKEN_INT; } if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(s, 2); return (SWIG_TOKEN_INT); } break; case 820: /* Like case 82, but we've seen a decimal point. */ if ((c = nextchar(s)) == 0) { retract(s, 1); return SWIG_TOKEN_DOUBLE; } if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(s, 2); return (SWIG_TOKEN_DOUBLE); } break; case 83: /* Might be a hexadecimal or octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'x') || (c == 'X')) state = 85; else if (c == '.') state = 81; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 84: /* This is an octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 85: /* This is an hex number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isxdigit(c)) state = 85; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 86: /* Rest of floating point number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 86; else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if ((c == 'l') || (c == 'L')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_DOUBLE; } else { retract(s, 1); return SWIG_TOKEN_DOUBLE; } break; case 87: /* A long integer of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONG; } else if ((c == 'l') || (c == 'L')) { state = 870; } else { retract(s, 1); return SWIG_TOKEN_LONG; } break; /* A long long integer */ case 870: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONGLONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONGLONG; } else { retract(s, 1); return SWIG_TOKEN_LONGLONG; } /* An unsigned number */ case 88: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_UINT; if ((c == 'l') || (c == 'L')) { state = 880; } else { retract(s, 1); return SWIG_TOKEN_UINT; } break; /* Possibly an unsigned long long or unsigned long */ case 880: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ULONG; if ((c == 'l') || (c == 'L')) return SWIG_TOKEN_ULONGLONG; else { retract(s, 1); return SWIG_TOKEN_ULONG; } /* A character constant */ case 9: if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); return SWIG_TOKEN_ERROR; } if (c == '\'') { Delitem(s->text, DOH_END); return (SWIG_TOKEN_CHAR); } else if (c == '\\') { Delitem(s->text, DOH_END); get_escape(s); } break; /* A period or maybe a floating point number */ case 100: if ((c = nextchar(s)) == 0) return (0); if (isdigit(c)) state = 81; else { retract(s, 1); return SWIG_TOKEN_PERIOD; } break; case 200: /* PLUS, PLUSPLUS, PLUSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_PLUS; else if (c == '+') return SWIG_TOKEN_PLUSPLUS; else if (c == '=') return SWIG_TOKEN_PLUSEQUAL; else { retract(s, 1); return SWIG_TOKEN_PLUS; } break; case 210: /* MINUS, MINUSMINUS, MINUSEQUAL, ARROW */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_MINUS; else if (c == '-') return SWIG_TOKEN_MINUSMINUS; else if (c == '=') return SWIG_TOKEN_MINUSEQUAL; else if (c == '>') state = 211; else { retract(s, 1); return SWIG_TOKEN_MINUS; } break; case 211: /* ARROW, ARROWSTAR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ARROW; else if (c == '*') return SWIG_TOKEN_ARROWSTAR; else { retract(s, 1); return SWIG_TOKEN_ARROW; } break; case 220: /* STAR, TIMESEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_STAR; else if (c == '=') return SWIG_TOKEN_TIMESEQUAL; else { retract(s, 1); return SWIG_TOKEN_STAR; } break; case 230: /* XOR, XOREQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_XOR; else if (c == '=') return SWIG_TOKEN_XOREQUAL; else { retract(s, 1); return SWIG_TOKEN_XOR; } break; case 240: /* LSHIFT, LSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LSHIFT; else if (c == '=') return SWIG_TOKEN_LSEQUAL; else { retract(s, 1); return SWIG_TOKEN_LSHIFT; } break; case 250: /* RSHIFT, RSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_RSHIFT; else if (c == '=') return SWIG_TOKEN_RSEQUAL; else { retract(s, 1); return SWIG_TOKEN_RSHIFT; } break; /* An illegal character */ /* Reverse string */ case 900: if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); return SWIG_TOKEN_ERROR; } if (c == '`') { Delitem(s->text, DOH_END); return (SWIG_TOKEN_RSTRING); } break; default: return SWIG_TOKEN_ILLEGAL; } } }
static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) { Node *n = 0; String *tname = 0; Node *templ; Symtab *primary_scope = 0; List *possiblepartials = 0; Parm *p; Parm *parms = 0; Parm *targs; ParmList *expandedparms; int *priorities_matrix = 0; int max_possible_partials = 0; int posslen = 0; /* Search for primary (unspecialized) template */ templ = Swig_symbol_clookup(name, 0); if (template_debug) { tname = Copy(name); SwigType_add_template(tname, tparms); Printf(stdout, "\n"); Swig_diagnostic(cparse_file, cparse_line, "template_debug: Searching for match to: '%s'\n", tname); Delete(tname); tname = 0; } if (templ) { tname = Copy(name); parms = CopyParmList(tparms); /* All template specializations must be in the primary template's scope, store the symbol table for this scope for specialization lookups */ primary_scope = Getattr(templ, "sym:symtab"); /* Add default values from primary template */ targs = Getattr(templ, "templateparms"); expandedparms = Swig_symbol_template_defargs(parms, targs, tscope, primary_scope); /* reduce the typedef */ p = expandedparms; while (p) { SwigType *ty = Getattr(p, "type"); if (ty) { SwigType *nt = Swig_symbol_type_qualify(ty, tscope); Setattr(p, "type", nt); Delete(nt); } p = nextSibling(p); } SwigType_add_template(tname, expandedparms); /* Search for an explicit (exact) specialization. Example: template<> class name<int> { ... } */ { if (template_debug) { Printf(stdout, " searching for : '%s' (explicit specialization)\n", tname); } n = Swig_symbol_clookup_local(tname, primary_scope); if (!n) { SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope); if (!Equal(rname, tname)) { if (template_debug) { Printf(stdout, " searching for : '%s' (explicit specialization with typedef reduction)\n", rname); } n = Swig_symbol_clookup_local(rname, primary_scope); } Delete(rname); } if (n) { Node *tn; String *nodeType = nodeType(n); if (Equal(nodeType, "template")) { if (template_debug) { Printf(stdout, " explicit specialization found: '%s'\n", Getattr(n, "name")); } goto success; } tn = Getattr(n, "template"); if (tn) { if (template_debug) { Printf(stdout, " previous instantiation found: '%s'\n", Getattr(n, "name")); } n = tn; goto success; /* Previously wrapped by a template instantiation */ } Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n)); Delete(tname); Delete(parms); return 0; /* Found a match, but it's not a template of any kind. */ } } /* Search for partial specializations. * Example: template<typename T> class name<T *> { ... } * There are 3 types of template arguments: * (1) Template type arguments * (2) Template non type arguments * (3) Template template arguments * only (1) is really supported for partial specializations */ /* Rank each template parameter against the desired template parameters then build a matrix of best matches */ possiblepartials = NewList(); { char tmp[32]; List *partials; partials = Getattr(templ, "partials"); /* note that these partial specializations do not include explicit specializations */ if (partials) { Iterator pi; int parms_len = ParmList_len(parms); int *priorities_row; max_possible_partials = Len(partials); priorities_matrix = (int *)malloc(sizeof(int) * max_possible_partials * parms_len); /* slightly wasteful allocation for max possible matches */ priorities_row = priorities_matrix; for (pi = First(partials); pi.item; pi = Next(pi)) { Parm *p = parms; int all_parameters_match = 1; int i = 1; Parm *partialparms = Getattr(pi.item, "partialparms"); Parm *pp = partialparms; String *templcsymname = Getattr(pi.item, "templcsymname"); if (template_debug) { Printf(stdout, " checking match: '%s' (partial specialization)\n", templcsymname); } if (ParmList_len(partialparms) == parms_len) { while (p && pp) { SwigType *t; sprintf(tmp, "$%d", i); t = Getattr(p, "type"); if (!t) t = Getattr(p, "value"); if (t) { EMatch match = does_parm_match(t, Getattr(pp, "type"), tmp, tscope, priorities_row + i - 1); if (match < (int)PartiallySpecializedMatch) { all_parameters_match = 0; break; } } i++; p = nextSibling(p); pp = nextSibling(pp); } if (all_parameters_match) { Append(possiblepartials, pi.item); priorities_row += parms_len; } } } } } posslen = Len(possiblepartials); if (template_debug) { int i; if (posslen == 0) Printf(stdout, " matched partials: NONE\n"); else if (posslen == 1) Printf(stdout, " chosen partial: '%s'\n", Getattr(Getitem(possiblepartials, 0), "templcsymname")); else { Printf(stdout, " possibly matched partials:\n"); for (i = 0; i < posslen; i++) { Printf(stdout, " '%s'\n", Getattr(Getitem(possiblepartials, i), "templcsymname")); } } } if (posslen > 1) { /* Now go through all the possibly matched partial specialization templates and look for a non-ambiguous match. * Exact matches rank the highest and deduced parameters are ranked by how specialized they are, eg looking for * a match to const int *, the following rank (highest to lowest): * const int * (exact match) * const T * * T * * T * * An ambiguous example when attempting to match as either specialization could match: %template() X<int *, double *>; * template<typename T1, typename T2> X class {}; // primary template * template<typename T1> X<T1, double *> class {}; // specialization (1) * template<typename T2> X<int *, T2> class {}; // specialization (2) */ if (template_debug) { int row, col; int parms_len = ParmList_len(parms); Printf(stdout, " parameter priorities matrix (%d parms):\n", parms_len); for (row = 0; row < posslen; row++) { int *priorities_row = priorities_matrix + row*parms_len; Printf(stdout, " "); for (col = 0; col < parms_len; col++) { Printf(stdout, "%5d ", priorities_row[col]); } Printf(stdout, "\n"); } } { int row, col; int parms_len = ParmList_len(parms); /* Printf(stdout, " parameter priorities inverse matrix (%d parms):\n", parms_len); */ for (col = 0; col < parms_len; col++) { int *priorities_col = priorities_matrix + col; int maxpriority = -1; /* Printf(stdout, "max_possible_partials: %d col:%d\n", max_possible_partials, col); Printf(stdout, " "); */ /* determine the highest rank for this nth parameter */ for (row = 0; row < posslen; row++) { int *element_ptr = priorities_col + row*parms_len; int priority = *element_ptr; if (priority > maxpriority) maxpriority = priority; /* Printf(stdout, "%5d ", priority); */ } /* Printf(stdout, "\n"); */ /* flag all the parameters which equal the highest rank */ for (row = 0; row < posslen; row++) { int *element_ptr = priorities_col + row*parms_len; int priority = *element_ptr; *element_ptr = (priority >= maxpriority) ? 1 : 0; } } } { int row, col; int parms_len = ParmList_len(parms); Iterator pi = First(possiblepartials); Node *chosenpartials = NewList(); if (template_debug) Printf(stdout, " priority flags matrix:\n"); for (row = 0; row < posslen; row++) { int *priorities_row = priorities_matrix + row*parms_len; int highest_count = 0; /* count of highest priority parameters */ for (col = 0; col < parms_len; col++) { highest_count += priorities_row[col]; } if (template_debug) { Printf(stdout, " "); for (col = 0; col < parms_len; col++) { Printf(stdout, "%5d ", priorities_row[col]); } Printf(stdout, "\n"); } if (highest_count == parms_len) { Append(chosenpartials, pi.item); } pi = Next(pi); } if (Len(chosenpartials) > 0) { /* one or more best match found */ Delete(possiblepartials); possiblepartials = chosenpartials; posslen = Len(possiblepartials); } else { /* no best match found */ Delete(chosenpartials); } } } if (posslen > 0) { String *s = Getattr(Getitem(possiblepartials, 0), "templcsymname"); n = Swig_symbol_clookup_local(s, primary_scope); if (posslen > 1) { int i; if (n) { Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname)); Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' used,\n", SwigType_namestr(Getattr(n, "name"))); } for (i = 1; i < posslen; i++) { String *templcsymname = Getattr(Getitem(possiblepartials, i), "templcsymname"); Node *ignored_node = Swig_symbol_clookup_local(templcsymname, primary_scope); assert(ignored_node); Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(ignored_node), Getline(ignored_node), " instantiation '%s' ignored.\n", SwigType_namestr(Getattr(ignored_node, "name"))); } } } if (!n) { if (template_debug) { Printf(stdout, " chosen primary template: '%s'\n", Getattr(templ, "name")); } n = templ; } } else { if (template_debug) { Printf(stdout, " primary template not found\n"); } /* Give up if primary (unspecialized) template not found as specializations will only exist if there is a primary template */ n = 0; } if (!n) { Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name); } else if (n) { String *nodeType = nodeType(n); if (!Equal(nodeType, "template")) { Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType); n = 0; } } success: Delete(tname); Delete(possiblepartials); if ((template_debug) && (n)) { /* Printf(stdout, "Node: %p\n", n); Swig_print_node(n); */ Printf(stdout, " chosen template:'%s'\n", Getattr(n, "name")); } Delete(parms); free(priorities_matrix); return n; }
int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) { char c; int num_levels = 1; int l; int state = 0; char temp[2] = { 0, 0 }; l = s->line; temp[0] = (char) startchar; Clear(s->text); Setfile(s->text, Getfile(s->str)); Setline(s->text, s->line); Append(s->text, temp); while (num_levels > 0) { if ((c = nextchar(s)) == 0) { return -1; } switch (state) { case 0: if (c == startchar) num_levels++; else if (c == endchar) num_levels--; else if (c == '/') state = 10; else if (c == '\"') state = 20; else if (c == '\'') state = 30; break; case 10: if (c == '/') state = 11; else if (c == '*') state = 12; else state = 0; break; case 11: if (c == '\n') state = 0; else state = 11; break; case 12: if (c == '*') state = 13; break; case 13: if (c == '*') state = 13; else if (c == '/') state = 0; else state = 12; break; case 20: if (c == '\"') state = 0; else if (c == '\\') state = 21; break; case 21: state = 20; break; case 30: if (c == '\'') state = 0; else if (c == '\\') state = 31; break; case 31: state = 30; break; default: break; } } return 0; }
String *Scanner_get_raw_text_balanced(Scanner *s, int startchar, int endchar) { String *result = 0; char c; int old_line = s->line; String *old_text = Copy(s->text); long position = Tell(s->str); int num_levels = 1; int state = 0; char temp[2] = { 0, 0 }; temp[0] = (char) startchar; Clear(s->text); Setfile(s->text, Getfile(s->str)); Setline(s->text, s->line); Append(s->text, temp); while (num_levels > 0) { if ((c = nextchar(s)) == 0) { Clear(s->text); Append(s->text, old_text); Delete(old_text); s->line = old_line; return 0; } switch (state) { case 0: if (c == startchar) num_levels++; else if (c == endchar) num_levels--; else if (c == '/') state = 10; else if (c == '\"') state = 20; else if (c == '\'') state = 30; break; case 10: if (c == '/') state = 11; else if (c == '*') state = 12; else if (c == startchar) { state = 0; num_levels++; } else state = 0; break; case 11: if (c == '\n') state = 0; else state = 11; break; case 12: /* first character inside C comment */ if (c == '*') state = 14; else state = 13; break; case 13: if (c == '*') state = 14; break; case 14: /* possible end of C comment */ if (c == '*') state = 14; else if (c == '/') state = 0; else state = 13; break; case 20: if (c == '\"') state = 0; else if (c == '\\') state = 21; break; case 21: state = 20; break; case 30: if (c == '\'') state = 0; else if (c == '\\') state = 31; break; case 31: state = 30; break; default: break; } } Seek(s->str, position, SEEK_SET); result = Copy(s->text); Clear(s->text); Append(s->text, old_text); Delete(old_text); s->line = old_line; return result; }
static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) { Node *n; String *tname, *rname = 0; Node *templ; List *mpartials = 0; Parm *p; Parm *parms; Parm *targs; ParmList *expandedparms; tname = Copy(name); parms = CopyParmList(tparms); /* Search for generic template */ templ = Swig_symbol_clookup(name, 0); /* Add default values from generic template */ if (templ) { Symtab *tsdecl = Getattr(templ, "sym:symtab"); targs = Getattr(templ, "templateparms"); expandedparms = Swig_symbol_template_defargs(parms, targs, tscope, tsdecl); } else { expandedparms = parms; } /* reduce the typedef */ p = expandedparms; while (p) { SwigType *ty = Getattr(p, "type"); if (ty) { SwigType *nt = Swig_symbol_type_qualify(ty, tscope); Setattr(p, "type", nt); Delete(nt); } p = nextSibling(p); } SwigType_add_template(tname, expandedparms); if (template_debug) { Printf(stdout, "\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname); } /* Search for an exact specialization. Example: template<> class name<int> { ... } */ { if (template_debug) { Printf(stdout, " searching: '%s' (exact specialization)\n", tname); } n = Swig_symbol_clookup_local(tname, 0); if (!n) { SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope); if (!Equal(rname, tname)) { if (template_debug) { Printf(stdout, " searching: '%s' (exact specialization)\n", rname); } n = Swig_symbol_clookup_local(rname, 0); } Delete(rname); } if (n) { Node *tn; String *nodeType = nodeType(n); if (Equal(nodeType, "template")) goto success; tn = Getattr(n, "template"); if (tn) { n = tn; goto success; /* Previously wrapped by a template return that */ } Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n)); Delete(tname); Delete(parms); return 0; /* Found a match, but it's not a template of any kind. */ } } /* Search for partial specialization. Example: template<typename T> class name<T *> { ... } */ /* Generate reduced template name (stripped of extraneous pointers, etc.) */ rname = NewStringf("%s<(", name); p = parms; while (p) { String *t; t = Getattr(p, "type"); if (!t) t = Getattr(p, "value"); if (t) { String *ty = Swig_symbol_typedef_reduce(t, tscope); String *tb = SwigType_base(ty); String *td = SwigType_default(ty); Replaceid(td, "enum SWIGTYPE", tb); Replaceid(td, "SWIGTYPE", tb); Append(rname, td); Delete(tb); Delete(ty); Delete(td); } p = nextSibling(p); if (p) { Append(rname, ","); } } Append(rname, ")>"); mpartials = NewList(); if (templ) { /* First, we search using an exact type prototype */ Parm *p; char tmp[32]; int i; List *partials; String *ss; Iterator pi; partials = Getattr(templ, "partials"); if (partials) { for (pi = First(partials); pi.item; pi = Next(pi)) { ss = Copy(pi.item); p = parms; i = 1; while (p) { String *t, *tn; sprintf(tmp, "$%d", i); t = Getattr(p, "type"); if (!t) t = Getattr(p, "value"); if (t) { String *ty = Swig_symbol_typedef_reduce(t, tscope); tn = SwigType_base(ty); Replaceid(ss, tmp, tn); Delete(tn); Delete(ty); } i++; p = nextSibling(p); } if (template_debug) { Printf(stdout, " searching: '%s' (partial specialization - %s)\n", ss, pi.item); } if ((Equal(ss, tname)) || (Equal(ss, rname))) { Append(mpartials, pi.item); } Delete(ss); } } } if (template_debug) { Printf(stdout, " Matched partials: %s\n", mpartials); } if (Len(mpartials)) { String *s = Getitem(mpartials, 0); n = Swig_symbol_clookup_local(s, 0); if (Len(mpartials) > 1) { if (n) { Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname)); Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' is used.\n", SwigType_namestr(Getattr(n, "name"))); } } } if (!n) { n = templ; } if (!n) { Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name); } else if (n) { String *nodeType = nodeType(n); if (!Equal(nodeType, "template")) { Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType); n = 0; } } success: Delete(tname); Delete(rname); Delete(mpartials); if ((template_debug) && (n)) { Printf(stdout, "Node: %p\n", n); Swig_print_node(n); } Delete(parms); return n; }
static int look(Scanner *s) { int state = 0; int c = 0; String *str_delimiter = 0; Clear(s->text); s->start_line = s->line; Setfile(s->text, Getfile(s->str)); while (1) { switch (state) { case 0: if ((c = nextchar(s)) == 0) return (0); /* Process delimiters */ if (c == '\n') { return SWIG_TOKEN_ENDLINE; } else if (!isspace(c)) { retract(s, 1); state = 1000; Clear(s->text); Setline(s->text, s->line); Setfile(s->text, Getfile(s->str)); } break; case 1000: if ((c = nextchar(s)) == 0) return (0); if (c == '%') state = 4; /* Possibly a SWIG directive */ /* Look for possible identifiers or unicode/delimiter strings */ else if ((isalpha(c)) || (c == '_') || (s->idstart && strchr(s->idstart, c))) { state = 7; } /* Look for single character symbols */ else if (c == '(') { brackets_push(s); return SWIG_TOKEN_LPAREN; } else if (c == ')') { brackets_pop(s); return SWIG_TOKEN_RPAREN; } else if (c == ';') { brackets_clear(s); return SWIG_TOKEN_SEMI; } else if (c == ',') return SWIG_TOKEN_COMMA; else if (c == '*') state = 220; else if (c == '}') return SWIG_TOKEN_RBRACE; else if (c == '{') { brackets_reset(s); return SWIG_TOKEN_LBRACE; } else if (c == '=') state = 33; else if (c == '+') state = 200; else if (c == '-') state = 210; else if (c == '&') state = 31; else if (c == '|') state = 32; else if (c == '^') state = 230; else if (c == '<') state = 60; else if (c == '>') state = 61; else if (c == '~') return SWIG_TOKEN_NOT; else if (c == '!') state = 3; else if (c == '\\') return SWIG_TOKEN_BACKSLASH; else if (c == '[') return SWIG_TOKEN_LBRACKET; else if (c == ']') return SWIG_TOKEN_RBRACKET; else if (c == '@') return SWIG_TOKEN_AT; else if (c == '$') state = 75; else if (c == '#') return SWIG_TOKEN_POUND; else if (c == '?') return SWIG_TOKEN_QUESTION; /* Look for multi-character sequences */ else if (c == '/') { state = 1; /* Comment (maybe) */ s->start_line = s->line; } else if (c == ':') state = 5; /* maybe double colon */ else if (c == '0') state = 83; /* An octal or hex value */ else if (c == '\"') { state = 2; /* A string constant */ s->start_line = s->line; Clear(s->text); } else if (c == '\'') { s->start_line = s->line; Clear(s->text); state = 9; /* A character constant */ } else if (c == '`') { s->start_line = s->line; Clear(s->text); state = 900; } else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ else if (isdigit(c)) state = 8; /* A numerical value */ else state = 99; /* An error */ break; case 1: /* Comment block */ if ((c = nextchar(s)) == 0) return (0); if (c == '/') { state = 10; /* C++ style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text, "//"); } else if (c == '*') { state = 11; /* C style comment */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); Append(s->text, "/*"); } else if (c == '=') { return SWIG_TOKEN_DIVEQUAL; } else { retract(s, 1); return SWIG_TOKEN_SLASH; } break; case 10: /* C++ style comment */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '\n') { retract(s,1); return SWIG_TOKEN_COMMENT; } else { state = 10; } break; case 11: /* C style comment block */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '*') { state = 12; } else { state = 11; } break; case 12: /* Still in C style comment */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated comment\n"); return SWIG_TOKEN_ERROR; } if (c == '*') { state = 12; } else if (c == '/') { return SWIG_TOKEN_COMMENT; } else { state = 11; } break; case 2: /* Processing a string */ if (!str_delimiter) { state=20; break; } if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } else if (c == '(') { state = 20; } else { char temp[2] = { 0, 0 }; temp[0] = c; Append( str_delimiter, temp ); } break; case 20: /* Inside the string */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated string\n"); return SWIG_TOKEN_ERROR; } if (!str_delimiter) { /* Ordinary string: "value" */ if (c == '\"') { Delitem(s->text, DOH_END); return SWIG_TOKEN_STRING; } else if (c == '\\') { Delitem(s->text, DOH_END); get_escape(s); } } else { /* Custom delimiter string: R"XXXX(value)XXXX" */ if (c==')') { int i=0; String *end_delimiter = NewStringEmpty(); while ((c = nextchar(s)) != 0 && c!='\"') { char temp[2] = { 0, 0 }; temp[0] = c; Append( end_delimiter, temp ); i++; } if (Strcmp( str_delimiter, end_delimiter )==0) { Delete( end_delimiter ); /* Correct end delimiter )XXXX" occured */ Delete( str_delimiter ); str_delimiter = 0; return SWIG_TOKEN_STRING; } else { /* Incorrect end delimiter occured */ if (c == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated raw string, started with R\"%s( is not terminated by )%s\"\n", str_delimiter, str_delimiter); return SWIG_TOKEN_ERROR; } retract( s, i ); Delete( end_delimiter ); } } } break; case 3: /* Maybe a not equals */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LNOT; else if (c == '=') return SWIG_TOKEN_NOTEQUAL; else { retract(s, 1); return SWIG_TOKEN_LNOT; } break; case 31: /* AND or Logical AND or ANDEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_AND; else if (c == '&') return SWIG_TOKEN_LAND; else if (c == '=') return SWIG_TOKEN_ANDEQUAL; else { retract(s, 1); return SWIG_TOKEN_AND; } break; case 32: /* OR or Logical OR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_OR; else if (c == '|') return SWIG_TOKEN_LOR; else if (c == '=') return SWIG_TOKEN_OREQUAL; else { retract(s, 1); return SWIG_TOKEN_OR; } break; case 33: /* EQUAL or EQUALTO */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_EQUAL; else if (c == '=') return SWIG_TOKEN_EQUALTO; else { retract(s, 1); return SWIG_TOKEN_EQUAL; } break; case 4: /* A wrapper generator directive (maybe) */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_PERCENT; if (c == '{') { state = 40; /* Include block */ Clear(s->text); Setline(s->text, Getline(s->str)); Setfile(s->text, Getfile(s->str)); s->start_line = s->line; } else if (s->idstart && strchr(s->idstart, '%') && ((isalpha(c)) || (c == '_'))) { state = 7; } else if (c == '=') { return SWIG_TOKEN_MODEQUAL; } else if (c == '}') { Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '%%}'\n"); exit(1); } else { retract(s, 1); return SWIG_TOKEN_PERCENT; } break; case 40: /* Process an include block */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated block\n"); return SWIG_TOKEN_ERROR; } if (c == '%') state = 41; break; case 41: /* Still processing include block */ if ((c = nextchar(s)) == 0) { set_error(s,s->start_line,"Unterminated code block"); return 0; } if (c == '}') { Delitem(s->text, DOH_END); Delitem(s->text, DOH_END); Seek(s->text,0,SEEK_SET); return SWIG_TOKEN_CODEBLOCK; } else { state = 40; } break; case 5: /* Maybe a double colon */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_COLON; if (c == ':') state = 50; else { retract(s, 1); return SWIG_TOKEN_COLON; } break; case 50: /* DCOLON, DCOLONSTAR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DCOLON; else if (c == '*') return SWIG_TOKEN_DCOLONSTAR; else { retract(s, 1); return SWIG_TOKEN_DCOLON; } break; case 60: /* shift operators */ if ((c = nextchar(s)) == 0) { brackets_increment(s); return SWIG_TOKEN_LESSTHAN; } if (c == '<') state = 240; else if (c == '=') return SWIG_TOKEN_LTEQUAL; else { retract(s, 1); brackets_increment(s); return SWIG_TOKEN_LESSTHAN; } break; case 61: if ((c = nextchar(s)) == 0) { brackets_decrement(s); return SWIG_TOKEN_GREATERTHAN; } if (c == '>' && brackets_allow_shift(s)) state = 250; else if (c == '=') return SWIG_TOKEN_GTEQUAL; else { retract(s, 1); brackets_decrement(s); return SWIG_TOKEN_GREATERTHAN; } break; case 7: /* Identifier or true/false or unicode/custom delimiter string */ if (c == 'R') { /* Possibly CUSTOM DELIMITER string */ state = 72; break; } else if (c == 'L') { /* Probably identifier but may be a wide string literal */ state = 77; break; } else if (c != 'u' && c != 'U') { /* Definitely an identifier */ state = 70; break; } if ((c = nextchar(s)) == 0) { state = 76; } else if (c == '\"') { /* Definitely u, U or L string */ retract(s, 1); state = 1000; } else if (c == 'R') { /* Possibly CUSTOM DELIMITER u, U, L string */ state = 73; } else if (c == '8') { /* Possibly u8 string */ state = 71; } else { retract(s, 1); /* Definitely an identifier */ state = 70; } break; case 70: /* Identifier */ if ((c = nextchar(s)) == 0) state = 76; else if (isalnum(c) || (c == '_') || (c == '$')) { state = 70; } else { retract(s, 1); state = 76; } break; case 71: /* Possibly u8 string */ if ((c = nextchar(s)) == 0) { state = 76; } else if (c=='\"') { retract(s, 1); /* Definitely u8 string */ state = 1000; } else if (c=='R') { state = 74; /* Possibly CUSTOM DELIMITER u8 string */ } else { retract(s, 2); /* Definitely an identifier. Retract 8" */ state = 70; } break; case 72: /* Possibly CUSTOM DELIMITER string */ case 73: case 74: if ((c = nextchar(s)) == 0) { state = 76; } else if (c=='\"') { retract(s, 1); /* Definitely custom delimiter u, U or L string */ str_delimiter = NewStringEmpty(); state = 1000; } else { if (state==72) { retract(s, 1); /* Definitely an identifier. Retract ? */ } else if (state==73) { retract(s, 2); /* Definitely an identifier. Retract R? */ } else if (state==74) { retract(s, 3); /* Definitely an identifier. Retract 8R? */ } state = 70; } break; case 75: /* Special identifier $ */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOLLAR; if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { state = 70; } else { retract(s,1); if (Len(s->text) == 1) return SWIG_TOKEN_DOLLAR; state = 76; } break; case 76: /* Identifier or true/false */ if (cparse_cplusplus) { if (Strcmp(s->text, "true") == 0) return SWIG_TOKEN_BOOL; else if (Strcmp(s->text, "false") == 0) return SWIG_TOKEN_BOOL; } return SWIG_TOKEN_ID; break; case 77: /*identifier or wide string literal*/ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ID; else if (c == '\"') { s->start_line = s->line; Clear(s->text); state = 78; } else if (c == '\'') { s->start_line = s->line; Clear(s->text); state = 79; } else if (isalnum(c) || (c == '_') || (c == '$')) state = 7; else { retract(s, 1); return SWIG_TOKEN_ID; } break; case 78: /* Processing a wide string literal*/ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); return SWIG_TOKEN_ERROR; } if (c == '\"') { Delitem(s->text, DOH_END); return SWIG_TOKEN_WSTRING; } else if (c == '\\') { if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated wide string\n"); return SWIG_TOKEN_ERROR; } } break; case 79: /* Processing a wide char literal */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated wide character constant\n"); return SWIG_TOKEN_ERROR; } if (c == '\'') { Delitem(s->text, DOH_END); return (SWIG_TOKEN_WCHAR); } else if (c == '\\') { if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated wide character literal\n"); return SWIG_TOKEN_ERROR; } } break; case 8: /* A numerical digit */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (c == '.') { state = 81; } else if ((c == 'e') || (c == 'E')) { state = 82; } else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if (isdigit(c)) { state = 8; } else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 81: /* A floating pointer number of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 81; else if ((c == 'e') || (c == 'E')) state = 820; else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if ((c == 'l') || (c == 'L')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_DOUBLE; } else { retract(s, 1); return (SWIG_TOKEN_DOUBLE); } break; case 82: if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n"); return SWIG_TOKEN_ERROR; } if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(s, 2); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n"); return SWIG_TOKEN_ERROR; } break; case 820: /* Like case 82, but we've seen a decimal point. */ if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n"); return SWIG_TOKEN_ERROR; } if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(s, 2); Swig_error(cparse_file, cparse_start_line, "Exponent does not have any digits\n"); return SWIG_TOKEN_ERROR; } break; case 83: /* Might be a hexadecimal or octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'x') || (c == 'X')) state = 85; else if (c == '.') state = 81; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 84: /* This is an octal number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isdigit(c)) state = 84; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 85: /* This is an hex number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_INT; if (isxdigit(c)) state = 85; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(s, 1); return SWIG_TOKEN_INT; } break; case 86: /* Rest of floating point number */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_DOUBLE; if (isdigit(c)) state = 86; else if ((c == 'f') || (c == 'F')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_FLOAT; } else if ((c == 'l') || (c == 'L')) { Delitem(s->text, DOH_END); return SWIG_TOKEN_DOUBLE; } else { retract(s, 1); return SWIG_TOKEN_DOUBLE; } break; case 87: /* A long integer of some sort */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONG; } else if ((c == 'l') || (c == 'L')) { state = 870; } else { retract(s, 1); return SWIG_TOKEN_LONG; } break; /* A long long integer */ case 870: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LONGLONG; if ((c == 'u') || (c == 'U')) { return SWIG_TOKEN_ULONGLONG; } else { retract(s, 1); return SWIG_TOKEN_LONGLONG; } /* An unsigned number */ case 88: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_UINT; if ((c == 'l') || (c == 'L')) { state = 880; } else { retract(s, 1); return SWIG_TOKEN_UINT; } break; /* Possibly an unsigned long long or unsigned long */ case 880: if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ULONG; if ((c == 'l') || (c == 'L')) return SWIG_TOKEN_ULONGLONG; else { retract(s, 1); return SWIG_TOKEN_ULONG; } /* A character constant */ case 9: if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); return SWIG_TOKEN_ERROR; } if (c == '\'') { Delitem(s->text, DOH_END); return (SWIG_TOKEN_CHAR); } else if (c == '\\') { Delitem(s->text, DOH_END); get_escape(s); } break; /* A period or maybe a floating point number */ case 100: if ((c = nextchar(s)) == 0) return (0); if (isdigit(c)) state = 81; else { retract(s, 1); return SWIG_TOKEN_PERIOD; } break; case 200: /* PLUS, PLUSPLUS, PLUSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_PLUS; else if (c == '+') return SWIG_TOKEN_PLUSPLUS; else if (c == '=') return SWIG_TOKEN_PLUSEQUAL; else { retract(s, 1); return SWIG_TOKEN_PLUS; } break; case 210: /* MINUS, MINUSMINUS, MINUSEQUAL, ARROW */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_MINUS; else if (c == '-') return SWIG_TOKEN_MINUSMINUS; else if (c == '=') return SWIG_TOKEN_MINUSEQUAL; else if (c == '>') state = 211; else { retract(s, 1); return SWIG_TOKEN_MINUS; } break; case 211: /* ARROW, ARROWSTAR */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_ARROW; else if (c == '*') return SWIG_TOKEN_ARROWSTAR; else { retract(s, 1); return SWIG_TOKEN_ARROW; } break; case 220: /* STAR, TIMESEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_STAR; else if (c == '=') return SWIG_TOKEN_TIMESEQUAL; else { retract(s, 1); return SWIG_TOKEN_STAR; } break; case 230: /* XOR, XOREQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_XOR; else if (c == '=') return SWIG_TOKEN_XOREQUAL; else { retract(s, 1); return SWIG_TOKEN_XOR; } break; case 240: /* LSHIFT, LSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_LSHIFT; else if (c == '=') return SWIG_TOKEN_LSEQUAL; else { retract(s, 1); return SWIG_TOKEN_LSHIFT; } break; case 250: /* RSHIFT, RSEQUAL */ if ((c = nextchar(s)) == 0) return SWIG_TOKEN_RSHIFT; else if (c == '=') return SWIG_TOKEN_RSEQUAL; else { retract(s, 1); return SWIG_TOKEN_RSHIFT; } break; /* An illegal character */ /* Reverse string */ case 900: if ((c = nextchar(s)) == 0) { Swig_error(cparse_file, cparse_start_line, "Unterminated character constant\n"); return SWIG_TOKEN_ERROR; } if (c == '`') { Delitem(s->text, DOH_END); return (SWIG_TOKEN_RSTRING); } break; default: return SWIG_TOKEN_ILLEGAL; } } }
void Swig_fragment_emit(Node *n) { String *code; char *pc, *tok; String *t; String *mangle = 0; String *name = 0; String *type = 0; if (!fragments) { Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name); return; } name = Getattr(n,k_value); if (!name) { name = n; } type = Getattr(n,k_type); if (type) { mangle = Swig_string_mangle(type); } if (debug) Printf(stdout,"looking fragment %s %s\n",name, type); t = Copy(name); tok = Char(t); pc = char_index(tok,','); if (pc) *pc = 0; while (tok) { String *name = NewString(tok); if (mangle) Append(name,mangle); if (looking_fragments && Getattr(looking_fragments,name)) { return; } code = Getattr(fragments,name); if (debug) Printf(stdout,"looking subfragment %s\n", name); if (code && (Strcmp(code,k_ignore) != 0)) { String *section = Getmeta(code,k_section); Hash *nn = Getmeta(code,k_kwargs); if (!looking_fragments) looking_fragments = NewHash(); Setattr(looking_fragments,name,"1"); while (nn) { if (Equal(Getattr(nn,k_name),k_fragment)) { if (debug) Printf(stdout,"emitting fragment %s %s\n",nn, type); Setfile(nn, Getfile(n)); Setline(nn, Getline(n)); Swig_fragment_emit(nn); } nn = nextSibling(nn); } if (section) { File *f = Swig_filebyname(section); if (!f) { Swig_error(Getfile(code),Getline(code), "Bad section '%s' for code fragment '%s'\n", section,name); } else { if (debug) Printf(stdout,"emitting subfragment %s %s\n",name, section); if (debug) Printf(f,"/* begin fragment %s */\n",name); Printf(f,"%s\n",code); if (debug) Printf(f,"/* end fragment %s */\n\n",name); Setattr(fragments,name,k_ignore); Delattr(looking_fragments,name); } } } else if (!code && type) { SwigType *rtype = SwigType_typedef_resolve_all(type); if (!Equal(type,rtype)) { String *name = Copy(Getattr(n,k_value)); String *mangle = Swig_string_mangle(type); Append(name,mangle); Setfile(name, Getfile(n)); Setline(name, Getline(n)); Swig_fragment_emit(name); Delete(mangle); Delete(name); } Delete(rtype); } if (!code) { Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name); } tok = pc ? pc + 1 : 0; if (tok) { pc = char_index(tok,','); if (pc) *pc = 0; } Delete(name); } Delete(t); }