diff --git a/SWIG/Source/CParse/cparse.h b/SWIG/Source/CParse/cparse.h index 81821784b..747f6b1dc 100644 --- a/SWIG/Source/CParse/cparse.h +++ b/SWIG/Source/CParse/cparse.h @@ -20,55 +20,51 @@ extern "C" { #endif /* cscanner.c */ -extern char *cparse_file; -extern int cparse_line; -extern int cparse_cplusplus; -extern int cparse_start_line; + extern char *cparse_file; + extern int cparse_line; + extern int cparse_cplusplus; + extern int cparse_start_line; -extern void Swig_cparse_cplusplus(int); -extern void scanner_file(File *); -extern void scanner_next_token(int); -extern void skip_balanced(int startchar, int endchar); -extern void skip_decl(void); -extern void scanner_check_typedef(void); -extern void scanner_ignore_typedef(void); -extern void scanner_last_id(int); -extern void scanner_clear_rename(void); -extern void start_inline(char *, int); -extern String *scanner_ccode; -extern int yylex(); + extern void Swig_cparse_cplusplus(int); + extern void scanner_file(File *); + extern void scanner_next_token(int); + extern void skip_balanced(int startchar, int endchar); + extern void skip_decl(void); + extern void scanner_check_typedef(void); + extern void scanner_ignore_typedef(void); + extern void scanner_last_id(int); + extern void scanner_clear_rename(void); + extern void start_inline(char *, int); + extern String *scanner_ccode; + extern int yylex(); /* parser.y */ -extern SwigType *Swig_cparse_type(String *); -extern Node *Swig_cparse(File *); -extern Hash *Swig_cparse_features(); -extern void SWIG_cparse_set_compact_default_args(int defargs); -extern int SWIG_cparse_template_reduce(int treduce); + extern SwigType *Swig_cparse_type(String *); + extern Node *Swig_cparse(File *); + extern Hash *Swig_cparse_features(); + extern void SWIG_cparse_set_compact_default_args(int defargs); + extern int SWIG_cparse_template_reduce(int treduce); /* util.c */ -extern void Swig_cparse_replace_descriptor(String *s); -extern void cparse_normalize_void(Node *); -extern Parm *Swig_cparse_parm(String *s); -extern ParmList *Swig_cparse_parms(String *s); + extern void Swig_cparse_replace_descriptor(String *s); + extern void cparse_normalize_void(Node *); + extern Parm *Swig_cparse_parm(String *s); + extern ParmList *Swig_cparse_parms(String *s); /* templ.c */ -extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope); -extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope); -extern void Swig_cparse_debug_templates(int); + extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope); + extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope); + extern void Swig_cparse_debug_templates(int); #ifdef __cplusplus } #endif - #define SWIG_WARN_NODE_BEGIN(Node) \ { \ String *wrnfilter = Node ? Getattr(Node,"feature:warnfilter") : 0; \ - if (wrnfilter) Swig_warnfilter(wrnfilter,1) - + if (wrnfilter) Swig_warnfilter(wrnfilter,1) #define SWIG_WARN_NODE_END(Node) \ if (wrnfilter) Swig_warnfilter(wrnfilter,0); \ } - - #endif diff --git a/SWIG/Source/CParse/cscanner.c b/SWIG/Source/CParse/cscanner.c index 89c47e950..91547cf03 100644 --- a/SWIG/Source/CParse/cscanner.c +++ b/SWIG/Source/CParse/cscanner.c @@ -18,40 +18,39 @@ char cvsroot_cscanner_c[] = "$Header$"; typedef struct InFile { DOHFile *f; - int line_number; - char *in_file; + int line_number; + char *in_file; struct InFile *prev; } InFile; -static InFile *in_head; +static InFile *in_head; DOHFile *LEX_in = 0; -static DOHString *header = 0; -static DOHString *comment = 0; -DOHString *scanner_ccode = 0; /* String containing C code */ -static char *yybuffer = 0; +static DOHString *header = 0; +static DOHString *comment = 0; +DOHString *scanner_ccode = 0; /* String containing C code */ +static char *yybuffer = 0; -static char yytext[YYBSIZE]; -static int yylen = 0; -int cparse_line = 1; -char *cparse_file; -int cparse_start_line = 0; +static char yytext[YYBSIZE]; +static int yylen = 0; +int cparse_line = 1; +char *cparse_file; +int cparse_start_line = 0; -static int comment_start; -static int scan_init = 0; -static int num_brace = 0; -static int last_brace = 0; -static int last_id = 0; -static int rename_active = 0; -static int swigtemplate_active = 0; - int cparse_cplusplus = 0; -static int expanding_macro = 0; +static int comment_start; +static int scan_init = 0; +static int num_brace = 0; +static int last_brace = 0; +static int last_id = 0; +static int rename_active = 0; +static int swigtemplate_active = 0; +int cparse_cplusplus = 0; +static int expanding_macro = 0; /* ----------------------------------------------------------------------------- * Swig_cparse_cplusplus() * ----------------------------------------------------------------------------- */ -void -Swig_cparse_cplusplus(int v) { +void Swig_cparse_cplusplus(int v) { cparse_cplusplus = v; } @@ -66,11 +65,11 @@ Swig_cparse_cplusplus(int v) { /* we just use the locator to mark when active/deactive the linecounting */ -static void -scanner_locator(String *loc) { - if (Equal(loc,"@SWIG@")) { +static void scanner_locator(String *loc) { + if (Equal(loc, "@SWIG@")) { /* End locator. */ - if (expanding_macro) --expanding_macro; + if (expanding_macro) + --expanding_macro; } else { /* Begin locator. */ ++expanding_macro; @@ -80,18 +79,17 @@ scanner_locator(String *loc) { #else typedef struct Locator { - char *filename; - int line_number; + char *filename; + int line_number; struct Locator *next; } Locator; static Locator *locs = 0; - -static void -scanner_locator(String *loc) { + +static void scanner_locator(String *loc) { int c; Locator *l; - Seek(loc,1,SEEK_SET); + Seek(loc, 1, SEEK_SET); c = Getc(loc); if (c == '@') { /* Empty locator. We pop the last location off */ @@ -102,7 +100,7 @@ scanner_locator(String *loc) { free(locs); locs = l; } - /* Printf(stderr,"location: %s:%d\n",cparse_file,cparse_line);*/ + /* Printf(stderr,"location: %s:%d\n",cparse_file,cparse_line); */ return; } @@ -112,15 +110,16 @@ scanner_locator(String *loc) { l->line_number = cparse_line; l->next = locs; locs = l; - + /* Now, parse the new location out of the locator string */ { String *fn = NewStringEmpty(); - Putc(c,fn); - + Putc(c, fn); + while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) break; - Putc(c,fn); + if ((c == '@') || (c == ',')) + break; + Putc(c, fn); } cparse_file = Swig_copy_string(Char(fn)); @@ -129,8 +128,9 @@ scanner_locator(String *loc) { cparse_line = 1; /* Get the line number */ while ((c = Getc(loc)) != EOF) { - if ((c == '@') || (c == ',')) break; - Putc(c,fn); + if ((c == '@') || (c == ',')) + break; + Putc(c, fn); } cparse_line = atoi(Char(fn)); @@ -138,8 +138,9 @@ scanner_locator(String *loc) { /* Get the rest of it */ while ((c = Getc(loc)) != EOF) { - if (c == '@') break; - Putc(c,fn); + if (c == '@') + break; + Putc(c, fn); } /* Printf(stderr,"location: %s:%d\n",cparse_file,cparse_line); */ Delete(fn); @@ -166,15 +167,17 @@ void scanner_init() { * * Start reading from new file * ------------------------------------------------------------------------- */ -void scanner_file(DOHFile *f) { +void scanner_file(DOHFile * f) { InFile *in; in = (InFile *) malloc(sizeof(InFile)); in->f = f; in->in_file = cparse_file; in->line_number = 1; - if (!in_head) in->prev = 0; - else in->prev = in_head; + if (!in_head) + in->prev = 0; + else + in->prev = in_head; in_head = in; LEX_in = f; cparse_line = 1; @@ -188,7 +191,8 @@ void scanner_file(DOHFile *f) { void scanner_close() { InFile *p; - if (!in_head) return; + if (!in_head) + return; Delete(LEX_in); p = in_head->prev; if (p != 0) { @@ -213,27 +217,29 @@ void scanner_close() { * ------------------------------------------------------------------------- */ unsigned char nextchar() { - int c = 0; + int c = 0; - while (LEX_in) { - c = Getc(LEX_in); - if (c == EOF) { - scanner_close(); - } else { - break; - } + while (LEX_in) { + c = Getc(LEX_in); + if (c == EOF) { + scanner_close(); + } else { + break; } - if (!LEX_in) return 0; - if (yylen >= YYBSIZE) { - Printf(stderr,"** FATAL ERROR. Buffer overflow in scanner.c.\nPlease report to the SWIG developers.\n"); - exit (EXIT_FAILURE); - } - yytext[yylen] = c; - yylen++; - if (c == '\n') { - if (!expanding_macro) cparse_line++; - } - return c; + } + if (!LEX_in) + return 0; + if (yylen >= YYBSIZE) { + Printf(stderr, "** FATAL ERROR. Buffer overflow in scanner.c.\nPlease report to the SWIG developers.\n"); + exit(EXIT_FAILURE); + } + yytext[yylen] = c; + yylen++; + if (c == '\n') { + if (!expanding_macro) + cparse_line++; + } + return c; } void retract(int n) { @@ -241,13 +247,15 @@ void retract(int n) { for (i = 0; i < n; i++) { yylen--; if (yylen >= 0) { - Ungetc(yytext[yylen],LEX_in); + Ungetc(yytext[yylen], LEX_in); if (yytext[yylen] == '\n') { - if (!expanding_macro) cparse_line--; + if (!expanding_macro) + cparse_line--; } } } - if (yylen < 0) yylen = 0; + if (yylen < 0) + yylen = 0; } /* ---------------------------------------------------------------------------- @@ -264,14 +272,15 @@ void retract(int n) { void start_inline(char *text, int line) { InFile *in; - if (!in_head) return; + if (!in_head) + return; /* Save current state */ in_head->line_number = cparse_line; in_head->in_file = cparse_file; in = (InFile *) malloc(sizeof(InFile)); in->f = NewString(text); - Seek(in->f,0,SEEK_SET); + Seek(in->f, 0, SEEK_SET); in->in_file = Swig_copy_string(cparse_file); in->line_number = line; in->prev = in_head; @@ -298,68 +307,86 @@ void yycomment(char *a, int b, int c) { * (...). Ignores symbols inside comments or strings. * ----------------------------------------------------------------------------- */ -void -skip_balanced(int startchar, int endchar) { - int c; - int num_levels = 1; - int state = 0; - int start_line = cparse_line; +void skip_balanced(int startchar, int endchar) { + int c; + int num_levels = 1; + int state = 0; + int start_line = cparse_line; - Clear(scanner_ccode); - Putc(startchar,scanner_ccode); - while (num_levels > 0) { - c = nextchar(); - if (c == 0) { - Swig_error(cparse_file, start_line, "Missing '%c'. Reached end of input.\n", endchar); - return; - } - Putc(c,scanner_ccode); - 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; - } - yylen = 0; + Clear(scanner_ccode); + Putc(startchar, scanner_ccode); + while (num_levels > 0) { + c = nextchar(); + if (c == 0) { + Swig_error(cparse_file, start_line, "Missing '%c'. Reached end of input.\n", endchar); + return; } - if (endchar == '}') num_brace--; - return; + Putc(c, scanner_ccode); + 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; + } + yylen = 0; + } + if (endchar == '}') + num_brace--; + return; } /* ---------------------------------------------------------------------------- @@ -382,9 +409,9 @@ void skip_decl(void) { while (!done) { if ((c = nextchar()) == 0) { if (!Swig_error_count()) { - Swig_error(cparse_file,start_line - 1,"Missing semicolon. Reached end of input.\n"); + Swig_error(cparse_file, start_line - 1, "Missing semicolon. Reached end of input.\n"); } - + return; } if (c == '{') { @@ -393,18 +420,21 @@ void skip_decl(void) { break; } yylen = 0; - if (c == ';') done = 1; + if (c == ';') + done = 1; } if (!done) { while (num_brace > last_brace) { if ((c = nextchar()) == 0) { if (!Swig_error_count()) { - Swig_error(cparse_file,start_line - 1,"Missing '}'. Reached end of input.\n"); + Swig_error(cparse_file, start_line - 1, "Missing '}'. Reached end of input.\n"); } return; } - if (c == '{') num_brace++; - if (c == '}') num_brace--; + if (c == '{') + num_brace++; + if (c == '}') + num_brace--; yylen = 0; } } @@ -416,53 +446,54 @@ static void get_escape() { int state = 0; int c; - while(1) { + while (1) { c = nextchar(); - if (c == 0) break; - switch(state) { + if (c == 0) + break; + switch (state) { case 0: if (c == 'n') { - yytext[yylen-1] = '\n'; + yytext[yylen - 1] = '\n'; return; } if (c == 'r') { - yytext[yylen-1] = '\r'; + yytext[yylen - 1] = '\r'; return; } if (c == 't') { - yytext[yylen-1] = '\t'; + yytext[yylen - 1] = '\t'; return; } if (c == 'a') { - yytext[yylen-1] = '\a'; + yytext[yylen - 1] = '\a'; return; } if (c == 'b') { - yytext[yylen-1] = '\b'; + yytext[yylen - 1] = '\b'; return; } if (c == 'f') { - yytext[yylen-1] = '\f'; + yytext[yylen - 1] = '\f'; return; } if (c == '\\') { - yytext[yylen-1] = '\\'; + yytext[yylen - 1] = '\\'; return; } if (c == 'v') { - yytext[yylen-1] = '\v'; + yytext[yylen - 1] = '\v'; return; } if (c == 'e') { - yytext[yylen-1] = '\033'; + yytext[yylen - 1] = '\033'; return; } if (c == '\'') { - yytext[yylen-1] = '\''; + yytext[yylen - 1] = '\''; return; } if (c == '\"') { - yytext[yylen-1] = '\"'; + yytext[yylen - 1] = '\"'; return; } if (c == '\n') { @@ -471,12 +502,11 @@ static void get_escape() { } if (isdigit(c)) { state = 10; - result = (c-'0'); - } - else if (c == 'x') { + result = (c - '0'); + } else if (c == 'x') { state = 20; } else { - yytext[yylen-1] = '\\'; + yytext[yylen - 1] = '\\'; yytext[yylen] = c; yylen++; return; @@ -485,7 +515,7 @@ static void get_escape() { case 10: if (!isdigit(c)) { retract(1); - yytext[yylen-1] = (char) result; + yytext[yylen - 1] = (char) result; return; } result = (result << 3) + (c - '0'); @@ -494,7 +524,7 @@ static void get_escape() { case 20: if (!isxdigit(c)) { retract(1); - yytext[yylen-1] = (char) result; + yytext[yylen - 1] = (char) result; return; } if (isdigit(c)) @@ -517,510 +547,581 @@ static void get_escape() { int yylook(void) { - int state; - int c = 0; + int state; + int c = 0; - state = 0; - yylen = 0; - while(1) { + state = 0; + yylen = 0; + while (1) { /* printf("State = %d\n", state); */ - switch(state) { + switch (state) { - case 0 : - if ((c = nextchar()) == 0) return (0); + case 0: + if ((c = nextchar()) == 0) + return (0); - /* Process delimiters */ + /* Process delimiters */ - if (c == '\n') { - state = 0; - yylen = 0; - /* last_id = 0;*/ - } else if (isspace(c) || (c=='\\')) { - state = 0; - yylen = 0; - /* last_id = 0; */ - } + if (c == '\n') { + state = 0; + yylen = 0; + /* last_id = 0; */ + } else if (isspace(c) || (c == '\\')) { + state = 0; + yylen = 0; + /* last_id = 0; */ + } - else if ((isalpha(c)) || (c == '_')) state = 7; - else if (c == '$') state = 75; + else if ((isalpha(c)) || (c == '_')) + state = 7; + else if (c == '$') + state = 75; - /* Look for single character symbols */ + /* Look for single character symbols */ - else if (c == '(') return (LPAREN); - else if (c == ')') return (RPAREN); - else if (c == ';') { - swigtemplate_active = 0; - return (SEMI); - } - - else if (c == ',') return (COMMA); - else if (c == '*') return (STAR); - else if (c == '}') { - num_brace--; - if (num_brace < 0) { - Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n"); - state = 0; - num_brace = 0; - } else { - return (RBRACE); - } - } - else if (c == '{') { - cparse_start_line = cparse_line; - last_brace = num_brace; - num_brace++; - return (LBRACE); - } - else if (c == '=') state = 63; - else if (c == '+') return (PLUS); - else if (c == '-') return (MINUS); - else if (c == '&') { - state = 300; - } - else if (c == '|') { - state = 301; - } - else if (c == '^') return (XOR); - else if (c == '<') state = 60; - else if (c == '>') state = 61; - else if (c == '~') { - return (NOT); - } - else if (c == '!') state = 62; - else if (c == '\\') { - state = 99; - } - else if (c == '[') return (LBRACKET); - else if (c == ']') return (RBRACKET); + else if (c == '(') + return (LPAREN); + else if (c == ')') + return (RPAREN); + else if (c == ';') { + swigtemplate_active = 0; + return (SEMI); + } - /* Look for multi-character sequences */ - - else if (c == '/') state = 1; /* Comment (maybe) */ - else if (c == '\"') state = 2; /* Possibly a string */ - else if (c == '#') state = 3; /* CPP */ - else if (c == '%') state = 4; /* Directive */ - else if (c == '@') state = 4; /* Objective C keyword */ - else if (c == ':') state = 5; /* maybe double colon */ - else if (c == '0') state = 83; /* An octal or hex value */ - else if (c == '\'') state = 9; /* A character constant */ - else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ - else if (c == '?') return (QUESTIONMARK); /* Ternary conditional operator */ - else if (c == '`') { - state = 200; /* Back-tick type */ - yylen = 0; - } - else if (isdigit(c)) state = 8; /* A numerical value */ - - else state = 99; - break; - case 1: /* Comment block */ - if ((c = nextchar()) == 0) return(0); - if (c == '/') { - comment_start = cparse_line; - Clear(comment); - state = 10; /* C++ style comment */ - } else if (c == '*') { - comment_start = cparse_line; - Clear(comment); - state = 12; /* C style comment */ - } else { - retract(1); - return(SLASH); - } - break; - case 300: /* & or && */ - if ((c = nextchar()) == 0) return(AND); - if (c == '&') return(LAND); - else { - retract(1); - return(AND); - } - - case 301: /* | or || */ - if ((c = nextchar()) == 0) return(OR); - if (c == '|') return(LOR); - else { - retract(1); - return(OR); - } - case 10: /* C++ style comment */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1, "Unterminated comment detected.\n"); - return 0; - } - if (c == '\n') { - Putc(c,comment); - /* Add the comment to documentation */ - /* yycomment(Char(comment),comment_start, column_start);*/ - yylen = 0; - state = 0; - } else { - state = 10; - Putc(c,comment); - yylen = 0; - } - break; - - case 12: /* C style comment block */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1,"Unterminated comment detected.\n"); - return 0; - } - if (c == '*') { - state = 13; - } else { - Putc(c,comment); - yylen = 0; - state = 12; - } - break; - case 13: /* Still in C style comment */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1,"Unterminated comment detected.\n"); - return 0; - } - if (c == '*') { - Putc(c,comment); - state = 13; - } else if (c == '/') { - /* Look for locator markers */ - char *loc = Char(comment); - if (loc && (strncmp(loc,"@SWIG",4) == 0)&& (*(loc+Len(comment)-1) == '@')) { - /* Locator */ - scanner_locator(comment); - yylen = 0; - state = 0; - } else { - yylen = 0; - state = 0; - } - } else { - Putc('*',comment); - Putc(c,comment); - yylen = 0; - state = 12; - } - break; - - case 2: /* Processing a string */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1, "Unterminated string detected.\n"); - return 0; - } - if (c == '\"') { - yytext[yylen-1] = 0; - yylval.id = Swig_copy_string(yytext+1); - return(STRING); - } else if (c == '\\') { - yylen--; - get_escape(); - break; - } else state = 2; - break; - - case 3: /* a CPP directive */ - if ((c = nextchar()) == 0) return 0; - if (c == '\n') { - retract(1); - yytext[yylen] = 0; - yylval.id = yytext; - return(POUND); - } - break; - - case 4: /* A wrapper generator directive (maybe) */ - if ((c = nextchar()) == 0) return 0; - if (c == '{') { - state = 40; /* Include block */ - Clear(header); - cparse_start_line = cparse_line; - } else if ((isalpha(c)) || (c == '_')) state = 7; - else if (c == '}') { - Swig_error(cparse_file,cparse_line, "Misplaced %%}.\n"); - return 0; - } else { - retract(1); - return(MODULO); - } - break; - - case 40: /* Process an include block */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1, "Unterminated include block detected.\n"); - return 0; - } - yylen = 0; - if (c == '%') state = 41; - else { - Putc(c,header); - yylen = 0; - state = 40; - } - break; - case 41: /* Still processing include block */ - if ((c = nextchar()) == 0) { - Swig_error(cparse_file,-1, "Unterminated include block detected.\n"); - return 0; - } - if (c == '}') { - yylval.str = NewString(header); - return(HBLOCK); - } else { - Putc('%',header); - Putc(c,header); - yylen = 0; - state = 40; - } - break; - - case 5: /* Maybe a double colon */ - - if ((c = nextchar()) == 0) return 0; - if ( c == ':') { - state = 51; - } else { - retract(1); - return COLON; - } - break; - case 51: /* Maybe a ::*, ::~, or :: */ - if ((c = nextchar()) == 0) return 0; - if (c == '*') { - return DSTAR; - } else if (c == '~') { - return DCNOT; - } else if (isspace(c)) { - /* Keep scanning ahead. Might be :: * or :: ~ */ - } else { - retract(1); - if (!last_id) { - retract(2); - return NONID; - } else { - return DCOLON; - } - } - break; - - case 60: /* < - less than or less than or equal to or left shift operator */ - if ((c = nextchar()) == 0) return (0); - if (c == '<') return LSHIFT; - if (c == '=') return LESSTHANOREQUALTO; - else { - retract(1); - return LESSTHAN; - } - case 61: /* > - greater than or greater or equal to or right shift operator */ - if ((c = nextchar()) == 0) return (0); - if (c == '>') return RSHIFT; - if (c == '=') return GREATERTHANOREQUALTO; - else { - retract(1); - return GREATERTHAN; - } - case 62: /* ! - logical not or not equal to */ - if ((c = nextchar()) == 0) return (0); - if (c == '=') return NOTEQUALTO; - retract(1); - return LNOT; - case 63: /* = - equal (assignment) or equal to */ - if ((c = nextchar()) == 0) return (0); - if (c == '=') return EQUALTO; - retract(1); - return EQUAL; - case 7: /* Identifier */ - if ((c = nextchar()) == 0) return(0); - if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) { - state = 7; - } else { - retract(1); - return(ID); - } - break; - case 75: /* Special identifier $*/ - if ((c = nextchar()) == 0) return(0); - if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { - state = 7; - } else { - retract(1); - return(ID); - } - break; - - case 8: /* A numerical digit */ - if ((c = nextchar()) == 0) return(0); - if (c == '.') {state = 81;} - else if ((c == 'e') || (c == 'E')) {state = 86;} - else if ((c == 'f') || (c == 'F')) { - return(NUM_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(1); - return(NUM_INT); - } - break; - case 81: /* A floating pointer number of some sort */ - if ((c = nextchar()) == 0) return(0); - if (isdigit(c)) state = 81; - else if ((c == 'e') || (c == 'E')) state = 82; - else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { - return(NUM_FLOAT); - } else { - retract(1); - return(NUM_FLOAT); - } - break; - case 82: - if ((c = nextchar()) == 0) return(0); - if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; - else { - retract(2); - yytext[yylen-1] = 0; - return(NUM_INT); - } - break; - case 83: - /* Might be a hexadecimal or octal number */ - if ((c = nextchar()) == 0) return(0); - 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(1); - return(NUM_INT); - } - break; - case 84: - /* This is an octal number */ - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 84; - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - return(NUM_INT); - } - break; - case 85: - /* This is an hex number */ - if ((c = nextchar()) == 0) return (0); - if (isxdigit(c)) - state = 85; - else if ((c == 'l') || (c == 'L')) { - state = 87; - } else if ((c == 'u') || (c == 'U')) { - state = 88; - } else { - retract(1); - return(NUM_INT); - } - break; - - case 86: - /* Rest of floating point number */ - - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 86; - else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { - return(NUM_FLOAT); - } else { - retract(1); - return(NUM_FLOAT); - } - break; - - case 87 : - /* A long integer of some sort */ - if ((c = nextchar()) == 0) return (NUM_LONG); - if ((c == 'u') || (c == 'U')) { - return(NUM_ULONG); - } else if ((c == 'l') || (c == 'L')) { - state = 870; - } else { - retract(1); - return(NUM_LONG); - } - break; - - case 870: - if ((c = nextchar()) == 0) return (NUM_LONGLONG); - if ((c == 'u') || (c == 'U')) { - return (NUM_ULONGLONG); - } else { - retract(1); - return(NUM_LONGLONG); - } - - case 88: - /* An unsigned integer of some sort */ - if ((c = nextchar()) == 0) return (NUM_UNSIGNED); - if ((c == 'l') || (c == 'L')) { - state = 880; - } else { - retract(1); - return(NUM_UNSIGNED); - } - break; - - case 880: - if ((c = nextchar()) == 0) return (NUM_ULONG); - if ((c == 'l') || (c == 'L')) return (NUM_ULONGLONG); - else { - retract(1); - return(NUM_ULONG); - } - - case 9: - /* Parse a character constant. ie. 'a' */ - if ((c = nextchar()) == 0) return (0); - if (c == '\\') { - yylen--; - get_escape(); - } else if (c == '\'') { - yytext[yylen-1] = 0; - yylval.str = NewString(yytext+1); - if (yylen == 2) { - Swig_error(cparse_file, cparse_line, "Empty character constant\n"); - } - return(CHARCONST); - } - break; - - case 100: - if ((c = nextchar()) == 0) return (0); - if (isdigit(c)) state = 81; - else { - retract(1); - return(PERIOD); - } - break; - case 200: - if ((c = nextchar()) == 0) return (0); - if (c == '`') { - yytext[yylen-1] = 0; - yylval.type = NewString(yytext); - return(TYPE_RAW); - } - break; - - default: - Swig_error(cparse_file, cparse_line, "Illegal character '%c'=%d.\n",c,c); + else if (c == ',') + return (COMMA); + else if (c == '*') + return (STAR); + else if (c == '}') { + num_brace--; + if (num_brace < 0) { + Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n"); state = 0; - return(ILLEGAL); + num_brace = 0; + } else { + return (RBRACE); } + } else if (c == '{') { + cparse_start_line = cparse_line; + last_brace = num_brace; + num_brace++; + return (LBRACE); + } else if (c == '=') + state = 63; + else if (c == '+') + return (PLUS); + else if (c == '-') + return (MINUS); + else if (c == '&') { + state = 300; + } else if (c == '|') { + state = 301; + } else if (c == '^') + return (XOR); + else if (c == '<') + state = 60; + else if (c == '>') + state = 61; + else if (c == '~') { + return (NOT); + } else if (c == '!') + state = 62; + else if (c == '\\') { + state = 99; + } else if (c == '[') + return (LBRACKET); + else if (c == ']') + return (RBRACKET); + + /* Look for multi-character sequences */ + + else if (c == '/') + state = 1; /* Comment (maybe) */ + else if (c == '\"') + state = 2; /* Possibly a string */ + else if (c == '#') + state = 3; /* CPP */ + else if (c == '%') + state = 4; /* Directive */ + else if (c == '@') + state = 4; /* Objective C keyword */ + else if (c == ':') + state = 5; /* maybe double colon */ + else if (c == '0') + state = 83; /* An octal or hex value */ + else if (c == '\'') + state = 9; /* A character constant */ + else if (c == '.') + state = 100; /* Maybe a number, maybe just a period */ + else if (c == '?') + return (QUESTIONMARK); /* Ternary conditional operator */ + else if (c == '`') { + state = 200; /* Back-tick type */ + yylen = 0; + } else if (isdigit(c)) + state = 8; /* A numerical value */ + + else + state = 99; + break; + case 1: /* Comment block */ + if ((c = nextchar()) == 0) + return (0); + if (c == '/') { + comment_start = cparse_line; + Clear(comment); + state = 10; /* C++ style comment */ + } else if (c == '*') { + comment_start = cparse_line; + Clear(comment); + state = 12; /* C style comment */ + } else { + retract(1); + return (SLASH); + } + break; + case 300: /* & or && */ + if ((c = nextchar()) == 0) + return (AND); + if (c == '&') + return (LAND); + else { + retract(1); + return (AND); + } + + case 301: /* | or || */ + if ((c = nextchar()) == 0) + return (OR); + if (c == '|') + return (LOR); + else { + retract(1); + return (OR); + } + case 10: /* C++ style comment */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated comment detected.\n"); + return 0; + } + if (c == '\n') { + Putc(c, comment); + /* Add the comment to documentation */ + /* yycomment(Char(comment),comment_start, column_start); */ + yylen = 0; + state = 0; + } else { + state = 10; + Putc(c, comment); + yylen = 0; + } + break; + + case 12: /* C style comment block */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated comment detected.\n"); + return 0; + } + if (c == '*') { + state = 13; + } else { + Putc(c, comment); + yylen = 0; + state = 12; + } + break; + case 13: /* Still in C style comment */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated comment detected.\n"); + return 0; + } + if (c == '*') { + Putc(c, comment); + state = 13; + } else if (c == '/') { + /* Look for locator markers */ + char *loc = Char(comment); + if (loc && (strncmp(loc, "@SWIG", 4) == 0) && (*(loc + Len(comment) - 1) == '@')) { + /* Locator */ + scanner_locator(comment); + yylen = 0; + state = 0; + } else { + yylen = 0; + state = 0; + } + } else { + Putc('*', comment); + Putc(c, comment); + yylen = 0; + state = 12; + } + break; + + case 2: /* Processing a string */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated string detected.\n"); + return 0; + } + if (c == '\"') { + yytext[yylen - 1] = 0; + yylval.id = Swig_copy_string(yytext + 1); + return (STRING); + } else if (c == '\\') { + yylen--; + get_escape(); + break; + } else + state = 2; + break; + + case 3: /* a CPP directive */ + if ((c = nextchar()) == 0) + return 0; + if (c == '\n') { + retract(1); + yytext[yylen] = 0; + yylval.id = yytext; + return (POUND); + } + break; + + case 4: /* A wrapper generator directive (maybe) */ + if ((c = nextchar()) == 0) + return 0; + if (c == '{') { + state = 40; /* Include block */ + Clear(header); + cparse_start_line = cparse_line; + } else if ((isalpha(c)) || (c == '_')) + state = 7; + else if (c == '}') { + Swig_error(cparse_file, cparse_line, "Misplaced %%}.\n"); + return 0; + } else { + retract(1); + return (MODULO); + } + break; + + case 40: /* Process an include block */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated include block detected.\n"); + return 0; + } + yylen = 0; + if (c == '%') + state = 41; + else { + Putc(c, header); + yylen = 0; + state = 40; + } + break; + case 41: /* Still processing include block */ + if ((c = nextchar()) == 0) { + Swig_error(cparse_file, -1, "Unterminated include block detected.\n"); + return 0; + } + if (c == '}') { + yylval.str = NewString(header); + return (HBLOCK); + } else { + Putc('%', header); + Putc(c, header); + yylen = 0; + state = 40; + } + break; + + case 5: /* Maybe a double colon */ + + if ((c = nextchar()) == 0) + return 0; + if (c == ':') { + state = 51; + } else { + retract(1); + return COLON; + } + break; + case 51: /* Maybe a ::*, ::~, or :: */ + if ((c = nextchar()) == 0) + return 0; + if (c == '*') { + return DSTAR; + } else if (c == '~') { + return DCNOT; + } else if (isspace(c)) { + /* Keep scanning ahead. Might be :: * or :: ~ */ + } else { + retract(1); + if (!last_id) { + retract(2); + return NONID; + } else { + return DCOLON; + } + } + break; + + case 60: /* < - less than or less than or equal to or left shift operator */ + if ((c = nextchar()) == 0) + return (0); + if (c == '<') + return LSHIFT; + if (c == '=') + return LESSTHANOREQUALTO; + else { + retract(1); + return LESSTHAN; + } + case 61: /* > - greater than or greater or equal to or right shift operator */ + if ((c = nextchar()) == 0) + return (0); + if (c == '>') + return RSHIFT; + if (c == '=') + return GREATERTHANOREQUALTO; + else { + retract(1); + return GREATERTHAN; + } + case 62: /* ! - logical not or not equal to */ + if ((c = nextchar()) == 0) + return (0); + if (c == '=') + return NOTEQUALTO; + retract(1); + return LNOT; + case 63: /* = - equal (assignment) or equal to */ + if ((c = nextchar()) == 0) + return (0); + if (c == '=') + return EQUALTO; + retract(1); + return EQUAL; + case 7: /* Identifier */ + if ((c = nextchar()) == 0) + return (0); + if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) { + state = 7; + } else { + retract(1); + return (ID); + } + break; + case 75: /* Special identifier $ */ + if ((c = nextchar()) == 0) + return (0); + if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { + state = 7; + } else { + retract(1); + return (ID); + } + break; + + case 8: /* A numerical digit */ + if ((c = nextchar()) == 0) + return (0); + if (c == '.') { + state = 81; + } else if ((c == 'e') || (c == 'E')) { + state = 86; + } else if ((c == 'f') || (c == 'F')) { + return (NUM_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(1); + return (NUM_INT); + } + break; + case 81: /* A floating pointer number of some sort */ + if ((c = nextchar()) == 0) + return (0); + if (isdigit(c)) + state = 81; + else if ((c == 'e') || (c == 'E')) + state = 82; + else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { + return (NUM_FLOAT); + } else { + retract(1); + return (NUM_FLOAT); + } + break; + case 82: + if ((c = nextchar()) == 0) + return (0); + if ((isdigit(c)) || (c == '-') || (c == '+')) + state = 86; + else { + retract(2); + yytext[yylen - 1] = 0; + return (NUM_INT); + } + break; + case 83: + /* Might be a hexadecimal or octal number */ + if ((c = nextchar()) == 0) + return (0); + 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(1); + return (NUM_INT); + } + break; + case 84: + /* This is an octal number */ + if ((c = nextchar()) == 0) + return (0); + if (isdigit(c)) + state = 84; + else if ((c == 'l') || (c == 'L')) { + state = 87; + } else if ((c == 'u') || (c == 'U')) { + state = 88; + } else { + retract(1); + return (NUM_INT); + } + break; + case 85: + /* This is an hex number */ + if ((c = nextchar()) == 0) + return (0); + if (isxdigit(c)) + state = 85; + else if ((c == 'l') || (c == 'L')) { + state = 87; + } else if ((c == 'u') || (c == 'U')) { + state = 88; + } else { + retract(1); + return (NUM_INT); + } + break; + + case 86: + /* Rest of floating point number */ + + if ((c = nextchar()) == 0) + return (0); + if (isdigit(c)) + state = 86; + else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { + return (NUM_FLOAT); + } else { + retract(1); + return (NUM_FLOAT); + } + break; + + case 87: + /* A long integer of some sort */ + if ((c = nextchar()) == 0) + return (NUM_LONG); + if ((c == 'u') || (c == 'U')) { + return (NUM_ULONG); + } else if ((c == 'l') || (c == 'L')) { + state = 870; + } else { + retract(1); + return (NUM_LONG); + } + break; + + case 870: + if ((c = nextchar()) == 0) + return (NUM_LONGLONG); + if ((c == 'u') || (c == 'U')) { + return (NUM_ULONGLONG); + } else { + retract(1); + return (NUM_LONGLONG); + } + + case 88: + /* An unsigned integer of some sort */ + if ((c = nextchar()) == 0) + return (NUM_UNSIGNED); + if ((c == 'l') || (c == 'L')) { + state = 880; + } else { + retract(1); + return (NUM_UNSIGNED); + } + break; + + case 880: + if ((c = nextchar()) == 0) + return (NUM_ULONG); + if ((c == 'l') || (c == 'L')) + return (NUM_ULONGLONG); + else { + retract(1); + return (NUM_ULONG); + } + + case 9: + /* Parse a character constant. ie. 'a' */ + if ((c = nextchar()) == 0) + return (0); + if (c == '\\') { + yylen--; + get_escape(); + } else if (c == '\'') { + yytext[yylen - 1] = 0; + yylval.str = NewString(yytext + 1); + if (yylen == 2) { + Swig_error(cparse_file, cparse_line, "Empty character constant\n"); + } + return (CHARCONST); + } + break; + + case 100: + if ((c = nextchar()) == 0) + return (0); + if (isdigit(c)) + state = 81; + else { + retract(1); + return (PERIOD); + } + break; + case 200: + if ((c = nextchar()) == 0) + return (0); + if (c == '`') { + yytext[yylen - 1] = 0; + yylval.type = NewString(yytext); + return (TYPE_RAW); + } + break; + + default: + Swig_error(cparse_file, cparse_line, "Illegal character '%c'=%d.\n", c, c); + state = 0; + return (ILLEGAL); } + } } static int check_typedef = 0; @@ -1055,367 +1156,438 @@ void scanner_next_token(int tok) { int yylex(void) { - int l; + int l; - if (!scan_init) { - scanner_init(); - } + 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 (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); - */ + 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 */ + /* 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; - } + if (!cparse_start_line) { + cparse_start_line = cparse_line; + } - /* Copy the lexene */ + /* Copy the lexene */ - yytext[yylen] = 0; - switch(l) { + 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); - - case ID: + 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); - 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,"wchar_t") == 0) { - yylval.type = NewSwigType(T_WCHAR); - return(TYPE_WCHAR); - } - 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); - } + case ID: - /* Non ISO (Windows) C extensions */ - if (strcmp(yytext,"__int8") == 0) { - yylval.type = NewString(yytext); - return(TYPE_NON_ISO_INT8); - } - if (strcmp(yytext,"__int16") == 0) { - yylval.type = NewString(yytext); - return(TYPE_NON_ISO_INT16); - } - if (strcmp(yytext,"__int32") == 0) { - yylval.type = NewString(yytext); - return(TYPE_NON_ISO_INT32); - } - if (strcmp(yytext,"__int64") == 0) { - yylval.type = NewString(yytext); - return(TYPE_NON_ISO_INT64); - } + if (yytext[0] != '%') { + /* Look for keywords now */ - /* C++ keywords */ - if (cparse_cplusplus) { - if (strcmp(yytext,"and") == 0) return(LAND); - if (strcmp(yytext,"or") == 0) return(LOR); - if (strcmp(yytext,"not") == 0) return(LNOT); - 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; - int start_template = 0; - int end_template = 0; - while ((c = nextchar())) { - if (((c == '(') || (c == ';')) && state) { - retract(1); - break; - } - if ((c == '<') && !start_template) { - int fcount = 1; - int c2 = nextchar(); - while (isspace(c2)) {c2 = nextchar(); ++fcount;} - if (isalpha(c2) || c2 == ':') { - start_template = count; - } - retract(fcount); - } - if ((c == '>') && start_template) end_template = count; - 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; - } + 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, "wchar_t") == 0) { + yylval.type = NewSwigType(T_WCHAR); + return (TYPE_WCHAR); + } + 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); + } + + /* Non ISO (Windows) C extensions */ + if (strcmp(yytext, "__int8") == 0) { + yylval.type = NewString(yytext); + return (TYPE_NON_ISO_INT8); + } + if (strcmp(yytext, "__int16") == 0) { + yylval.type = NewString(yytext); + return (TYPE_NON_ISO_INT16); + } + if (strcmp(yytext, "__int32") == 0) { + yylval.type = NewString(yytext); + return (TYPE_NON_ISO_INT32); + } + if (strcmp(yytext, "__int64") == 0) { + yylval.type = NewString(yytext); + return (TYPE_NON_ISO_INT64); + } + + /* C++ keywords */ + if (cparse_cplusplus) { + if (strcmp(yytext, "and") == 0) + return (LAND); + if (strcmp(yytext, "or") == 0) + return (LOR); + if (strcmp(yytext, "not") == 0) + return (LNOT); + 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; + int start_template = 0; + int end_template = 0; + while ((c = nextchar())) { + if (((c == '(') || (c == ';')) && state) { + retract(1); + break; + } + if ((c == '<') && !start_template) { + int fcount = 1; + int c2 = nextchar(); + while (isspace(c2)) { + c2 = nextchar(); + ++fcount; + } + if (isalpha(c2) || c2 == ':') { + start_template = count; + } + retract(fcount); + } + if ((c == '>') && start_template) + end_template = count; + count++; + if (!isspace(c)) { + if ((!state) && (isalpha(c))) { + isconversion = 1; } - Chop(s); - if (swigtemplate_active && start_template && end_template) { - /* - Manage the case: - %template(foo) operator(); - - ie, don't count as part of the operator. - */ - int len = Len(s); - char *end = Char(s); - int tlen = end_template - start_template + 1; - int nlen = len - tlen; - if (nlen) { - String *ns = 0; - while (isspace((unsigned char)end[--nlen])); - ns = NewStringWithSize(s, nlen + 1); - retract(count - start_template); - Delete(s); - s = ns; - count = start_template; - isconversion = 0; - } - } - - 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) - || (strcmp(t,"and") == 0) - || (strcmp(t,"and_eq") == 0) - || (strcmp(t,"bitand") == 0) - || (strcmp(t,"bitor") == 0) - || (strcmp(t,"compl") == 0) - || (strcmp(t,"not") == 0) - || (strcmp(t,"not_eq") == 0) - || (strcmp(t,"or") == 0) - || (strcmp(t,"or_eq") == 0) - || (strcmp(t,"xor") == 0) - || (strcmp(t,"xor_eq") == 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,"restrict") == 0) return(yylex()); - if (strcmp(yytext,"explicit") == 0) return(EXPLICIT); - 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_KW); - } - 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"); - } - if (strcmp(yytext,"complex") == 0) { - yylval.type = NewSwigType(T_COMPLEX); - return(TYPE_COMPLEX); + if (!state && !sticky) + Putc(' ', s); + Putc(c, s); + sticky = 0; + state = 1; + } else { + if (!sticky) + Putc(' ', s); + sticky = 1; } } - - /* Objective-C keywords */ + Chop(s); + if (swigtemplate_active && start_template && end_template) { + /* + Manage the case: + + %template(foo) operator(); + + ie, don't count as part of the operator. + */ + int len = Len(s); + char *end = Char(s); + int tlen = end_template - start_template + 1; + int nlen = len - tlen; + if (nlen) { + String *ns = 0; + while (isspace((unsigned char) end[--nlen])); + ns = NewStringWithSize(s, nlen + 1); + retract(count - start_template); + Delete(s); + s = ns; + count = start_template; + isconversion = 0; + } + } + + 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) + || (strcmp(t, "and") == 0) + || (strcmp(t, "and_eq") == 0) + || (strcmp(t, "bitand") == 0) + || (strcmp(t, "bitor") == 0) + || (strcmp(t, "compl") == 0) + || (strcmp(t, "not") == 0) + || (strcmp(t, "not_eq") == 0) + || (strcmp(t, "or") == 0) + || (strcmp(t, "or_eq") == 0) + || (strcmp(t, "xor") == 0) + || (strcmp(t, "xor_eq") == 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, "restrict") == 0) + return (yylex()); + if (strcmp(yytext, "explicit") == 0) + return (EXPLICIT); + 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_KW); + } + 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"); + } + if (strcmp(yytext, "complex") == 0) { + yylval.type = NewSwigType(T_COMPLEX); + return (TYPE_COMPLEX); + } + } + + /* 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); - } + 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_QUAL); - 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); - if (strcmp(yytext,"register") == 0) return(REGISTER); - if (strcmp(yytext,"inline") == 0) return(yylex()); - if (strcmp(yytext,"restrict") == 0) return(yylex()); - - /* 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) { - swigtemplate_active = 1; - 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); + /* Misc keywords */ + + if (strcmp(yytext, "extern") == 0) + return (EXTERN); + if (strcmp(yytext, "const") == 0) + return (CONST_QUAL); + 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); + if (strcmp(yytext, "register") == 0) + return (REGISTER); + if (strcmp(yytext, "inline") == 0) + return (yylex()); + if (strcmp(yytext, "restrict") == 0) + return (yylex()); + + /* 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) { + swigtemplate_active = 1; + 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); + } } diff --git a/SWIG/Source/CParse/templ.c b/SWIG/Source/CParse/templ.c index 295f2b072..5338c9712 100644 --- a/SWIG/Source/CParse/templ.c +++ b/SWIG/Source/CParse/templ.c @@ -18,8 +18,7 @@ static int template_debug = 0; String *baselists[3]; -void SwigType_template_init() -{ +void SwigType_template_init() { baselists[0] = k_baselist; baselists[1] = k_protectedbaselist; baselists[2] = k_privatebaselist; @@ -28,17 +27,17 @@ void SwigType_template_init() static void add_parms(ParmList *p, List *patchlist, List *typelist) { while (p) { - SwigType *ty = Getattr(p,k_type); - SwigType *val = Getattr(p,k_value); - Append(typelist,ty); - Append(typelist,val); - Append(patchlist,val); + SwigType *ty = Getattr(p, k_type); + SwigType *val = Getattr(p, k_value); + Append(typelist, ty); + Append(typelist, val); + Append(patchlist, val); p = nextSibling(p); } } void Swig_cparse_debug_templates(int x) { - template_debug = x; + template_debug = x; } /* ----------------------------------------------------------------------------- @@ -49,69 +48,70 @@ void Swig_cparse_debug_templates(int x) { * template parameters * ----------------------------------------------------------------------------- */ -static int -cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) { +static int cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) { static int expanded = 0; int ret; - String *nodeType = Getattr(n,k_nodetype); - if (!n) return 0; - if (Getattr(n,k_error)) return 0; + String *nodeType = Getattr(n, k_nodetype); + if (!n) + return 0; + if (Getattr(n, k_error)) + return 0; - if (StringEqual(nodeType,k_template)) { + if (StringEqual(nodeType, k_template)) { /* Change the node type back to normal */ if (!expanded) { expanded = 1; - Setattr(n,k_nodetype,Getattr(n,k_templatetype)); - ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist); + Setattr(n, k_nodetype, Getattr(n, k_templatetype)); + ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); expanded = 0; return ret; } else { - /* Called when template appears inside another template */ - /* Member templates */ + /* Called when template appears inside another template */ + /* Member templates */ - Setattr(n,k_nodetype,Getattr(n,k_templatetype)); - ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist); - Setattr(n,k_nodetype,k_template); + Setattr(n, k_nodetype, Getattr(n, k_templatetype)); + ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); + Setattr(n, k_nodetype, k_template); return ret; } - } else if (StringEqual(nodeType,k_cdecl)) { + } else if (StringEqual(nodeType, k_cdecl)) { /* A simple C declaration */ SwigType *t, *v, *d; - String *code; - t = Getattr(n,k_type); - v = Getattr(n,k_value); - d = Getattr(n,k_decl); + String *code; + t = Getattr(n, k_type); + v = Getattr(n, k_value); + d = Getattr(n, k_decl); - code = Getattr(n,k_code); - - Append(typelist,t); - Append(typelist,d); - Append(patchlist,v); - Append(cpatchlist,code); - - if (Getattr(n,k_conversionoperator)) { - Append(cpatchlist, Getattr(n,k_name)); - if (Getattr(n,k_symname)) { - Append(cpatchlist, Getattr(n,k_symname)); + code = Getattr(n, k_code); + + Append(typelist, t); + Append(typelist, d); + Append(patchlist, v); + Append(cpatchlist, code); + + if (Getattr(n, k_conversionoperator)) { + Append(cpatchlist, Getattr(n, k_name)); + if (Getattr(n, k_symname)) { + Append(cpatchlist, Getattr(n, k_symname)); } } - - add_parms(Getattr(n,k_parms), cpatchlist, typelist); - add_parms(Getattr(n,k_throws), cpatchlist, typelist); - } else if (StringEqual(nodeType,k_class)) { + add_parms(Getattr(n, k_parms), cpatchlist, typelist); + add_parms(Getattr(n, k_throws), cpatchlist, typelist); + + } else if (StringEqual(nodeType, k_class)) { /* Patch base classes */ { int b = 0; for (b = 0; b < 3; ++b) { - List *bases = Getattr(n,baselists[b]); + List *bases = Getattr(n, baselists[b]); if (bases) { int i; - int ilen = Len(bases); + int ilen = Len(bases); for (i = 0; i < ilen; i++) { - String *name = Copy(Getitem(bases,i)); - Setitem(bases,i,name); - Append(typelist,name); + String *name = Copy(Getitem(bases, i)); + Setitem(bases, i, name); + Append(typelist, name); } } } @@ -120,90 +120,90 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear { Node *cn = firstChild(n); while (cn) { - cparse_template_expand(cn,tname, rname, templateargs, patchlist,typelist,cpatchlist); + cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist); cn = nextSibling(cn); } } - } else if (StringEqual(nodeType,k_constructor)) { - String *name = Getattr(n,k_name); - if (!(Getattr(n,k_templatetype))) { + } else if (StringEqual(nodeType, k_constructor)) { + String *name = Getattr(n, k_name); + if (!(Getattr(n, k_templatetype))) { String *symname; String *stripped_name = SwigType_templateprefix(name); - if (Strstr(tname,stripped_name)) { - Replaceid(name,stripped_name,tname); + if (Strstr(tname, stripped_name)) { + Replaceid(name, stripped_name, tname); } Delete(stripped_name); - symname = Getattr(n,k_symname); + symname = Getattr(n, k_symname); if (symname) { stripped_name = SwigType_templateprefix(symname); - if (Strstr(tname,stripped_name)) { - Replaceid(symname,stripped_name,tname); + if (Strstr(tname, stripped_name)) { + Replaceid(symname, stripped_name, tname); } Delete(stripped_name); } - if (strchr(Char(name),'<')) { - Append(patchlist,Getattr(n,k_name)); + if (strchr(Char(name), '<')) { + Append(patchlist, Getattr(n, k_name)); } else { - Append(name,templateargs); + Append(name, templateargs); } - name = Getattr(n,k_symname); + name = Getattr(n, k_symname); if (name) { - if (strchr(Char(name),'<')) { + if (strchr(Char(name), '<')) { Clear(name); - Append(name,rname); + Append(name, rname); } else { String *tmp = Copy(name); - Replace(tmp,tname,rname, DOH_REPLACE_ANY); + Replace(tmp, tname, rname, DOH_REPLACE_ANY); Clear(name); - Append(name,tmp); + Append(name, tmp); Delete(tmp); } } /* Setattr(n,k_symname,name); */ } - Append(cpatchlist,Getattr(n,k_code)); - Append(typelist, Getattr(n,k_decl)); - add_parms(Getattr(n,k_parms), cpatchlist, typelist); - add_parms(Getattr(n,k_throws), cpatchlist, typelist); - } else if (StringEqual(nodeType,k_destructor)) { - String *name = Getattr(n,k_name); - if (name && strchr(Char(name),'<')) { - Append(patchlist,Getattr(n,k_name)); + Append(cpatchlist, Getattr(n, k_code)); + Append(typelist, Getattr(n, k_decl)); + add_parms(Getattr(n, k_parms), cpatchlist, typelist); + add_parms(Getattr(n, k_throws), cpatchlist, typelist); + } else if (StringEqual(nodeType, k_destructor)) { + String *name = Getattr(n, k_name); + if (name && strchr(Char(name), '<')) { + Append(patchlist, Getattr(n, k_name)); } else { - Append(name,templateargs); + Append(name, templateargs); } - name = Getattr(n,k_symname); - if (name && strchr(Char(name),'<')) { + name = Getattr(n, k_symname); + if (name && strchr(Char(name), '<')) { String *sn = Copy(tname); - Setattr(n,k_symname, sn); + Setattr(n, k_symname, sn); Delete(sn); } else { - Replace(name,tname,rname, DOH_REPLACE_ANY); + Replace(name, tname, rname, DOH_REPLACE_ANY); } /* Setattr(n,k_symname,name); */ - Append(cpatchlist,Getattr(n,k_code)); - } else if (StringEqual(nodeType,k_using)) { - String *uname = Getattr(n,k_uname); - if (uname && strchr(Char(uname),'<')) { + Append(cpatchlist, Getattr(n, k_code)); + } else if (StringEqual(nodeType, k_using)) { + String *uname = Getattr(n, k_uname); + if (uname && strchr(Char(uname), '<')) { Append(patchlist, uname); } - if (Getattr(n,k_namespace)) { + if (Getattr(n, k_namespace)) { /* Namespace link. This is nasty. Is other namespace defined? */ } } else { /* Look for obvious parameters */ Node *cn; - Append(cpatchlist,Getattr(n,k_code)); - Append(typelist, Getattr(n,k_type)); - Append(typelist, Getattr(n,k_decl)); - add_parms(Getattr(n,k_parms), cpatchlist, typelist); - add_parms(Getattr(n,k_kwargs), cpatchlist, typelist); - add_parms(Getattr(n,k_pattern), cpatchlist, typelist); - add_parms(Getattr(n,k_throws), cpatchlist, typelist); + Append(cpatchlist, Getattr(n, k_code)); + Append(typelist, Getattr(n, k_type)); + Append(typelist, Getattr(n, k_decl)); + add_parms(Getattr(n, k_parms), cpatchlist, typelist); + add_parms(Getattr(n, k_kwargs), cpatchlist, typelist); + add_parms(Getattr(n, k_pattern), cpatchlist, typelist); + add_parms(Getattr(n, k_throws), cpatchlist, typelist); cn = firstChild(n); while (cn) { - cparse_template_expand(cn,tname, rname, templateargs, patchlist, typelist, cpatchlist); + cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist); cn = nextSibling(cn); } } @@ -219,19 +219,18 @@ String *partial_arg(String *s, String *p) { /* Find the prefix on the partial argument */ - c = strchr(cp,'$'); + c = strchr(cp, '$'); if (!c) { return Copy(s); } - prefix = NewStringWithSize(cp,c-cp); + prefix = NewStringWithSize(cp, c - cp); newarg = Copy(s); - Replace(newarg,prefix,"",DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); Delete(prefix); return newarg; } -int -Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) { +int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) { List *patchlist, *cpatchlist, *typelist; String *templateargs; String *tname; @@ -244,31 +243,31 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts { String *tmp = NewStringEmpty(); if (tparms) { - SwigType_add_template(tmp,tparms); + SwigType_add_template(tmp, tparms); } templateargs = Copy(tmp); Delete(tmp); } - tname = Copy(Getattr(n,k_name)); + tname = Copy(Getattr(n, k_name)); tbase = Swig_scopename_last(tname); /* Look for partial specialization matching */ - if (Getattr(n,k_partialargs)) { + if (Getattr(n, k_partialargs)) { Parm *p, *tp; - ParmList *ptargs = SwigType_function_parms(Getattr(n,k_partialargs)); + ParmList *ptargs = SwigType_function_parms(Getattr(n, k_partialargs)); p = ptargs; tp = tparms; while (p && tp) { SwigType *ptype; SwigType *tptype; SwigType *partial_type; - ptype = Getattr(p,k_type); - tptype = Getattr(tp,k_type); + ptype = Getattr(p, k_type); + tptype = Getattr(tp, k_type); if (ptype && tptype) { - partial_type = partial_arg(tptype,ptype); - /* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */ - Setattr(tp,k_type,partial_type); + partial_type = partial_arg(tptype, ptype); + /* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */ + Setattr(tp, k_type, partial_type); Delete(partial_type); } p = nextSibling(p); @@ -281,93 +280,94 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts if (0) { Parm *p = tparms; while (p) { - Printf(stdout,"tparm: '%s' '%s' '%s'\n", Getattr(p,k_name), Getattr(p,k_type), Getattr(p,k_value)); + Printf(stdout, "tparm: '%s' '%s' '%s'\n", Getattr(p, k_name), Getattr(p, k_type), Getattr(p, k_value)); p = nextSibling(p); } } /* Printf(stdout,"targs = '%s'\n", templateargs); - Printf(stdout,"rname = '%s'\n", rname); - Printf(stdout,"tname = '%s'\n", tname); */ - cparse_template_expand(n,tname, rname, templateargs, patchlist, typelist, cpatchlist); + Printf(stdout,"rname = '%s'\n", rname); + Printf(stdout,"tname = '%s'\n", tname); */ + cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist); /* Set the name */ { - String *name = Getattr(n,k_name); + String *name = Getattr(n, k_name); if (name) { - Append(name,templateargs); + Append(name, templateargs); } iname = name; } /* Patch all of the types */ { - Parm *tp = Getattr(n,k_templateparms); - Parm *p = tparms; + Parm *tp = Getattr(n, k_templateparms); + Parm *p = tparms; /* Printf(stdout,"%s\n", ParmList_str_defaultargs(tp)); */ if (tp) { - Symtab *tsdecl = Getattr(n,k_symsymtab); + Symtab *tsdecl = Getattr(n, k_symsymtab); while (p && tp) { String *name, *value, *valuestr, *tydef, *tmp, *tmpr; - int sz, i; + int sz, i; String *dvalue = 0; String *qvalue = 0; - - name = Getattr(tp,k_name); - value = Getattr(p,k_value); - tydef = Getattr(p,k_typedef); + + name = Getattr(tp, k_name); + value = Getattr(p, k_value); + tydef = Getattr(p, k_typedef); if (name) { - if (!value) value = Getattr(p,k_type); + if (!value) + value = Getattr(p, k_type); qvalue = Swig_symbol_typedef_reduce(value, tsdecl); - dvalue = Swig_symbol_type_qualify(qvalue,tsdecl); + dvalue = Swig_symbol_type_qualify(qvalue, tsdecl); if (SwigType_istemplate(dvalue)) { String *ty = Swig_symbol_template_deftype(dvalue, tscope); Delete(dvalue); dvalue = ty; } - + assert(dvalue); - valuestr = SwigType_str(dvalue,0); + valuestr = SwigType_str(dvalue, 0); /* Need to patch default arguments */ { Parm *rp = nextSibling(p); while (rp) { - String *rvalue = Getattr(rp,k_value); + String *rvalue = Getattr(rp, k_value); if (rvalue) { - Replace(rvalue,name,dvalue, DOH_REPLACE_ID); + Replace(rvalue, name, dvalue, DOH_REPLACE_ID); } rp = nextSibling(rp); } } sz = Len(patchlist); for (i = 0; i < sz; i++) { - String *s = Getitem(patchlist,i); - Replace(s,name,dvalue, DOH_REPLACE_ID); + String *s = Getitem(patchlist, i); + Replace(s, name, dvalue, DOH_REPLACE_ID); } sz = Len(typelist); for (i = 0; i < sz; i++) { - String *s = Getitem(typelist,i); - /* Replace(s,name,value, DOH_REPLACE_ID); */ - /* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */ - SwigType_typename_replace(s,name,dvalue); - SwigType_typename_replace(s,tbase,iname); - /* Printf(stdout,"'%s'\n", s);*/ + String *s = Getitem(typelist, i); + /* Replace(s,name,value, DOH_REPLACE_ID); */ + /* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */ + SwigType_typename_replace(s, name, dvalue); + SwigType_typename_replace(s, tbase, iname); + /* Printf(stdout,"'%s'\n", s); */ } - + if (!tydef) { tydef = dvalue; } - tmp = NewStringf("#%s",name); + tmp = NewStringf("#%s", name); tmpr = NewStringf("\"%s\"", valuestr); - + sz = Len(cpatchlist); for (i = 0; i < sz; i++) { - String *s = Getitem(cpatchlist,i); - Replace(s,tmp,tmpr, DOH_REPLACE_ID); - /* Replace(s,name,tydef, DOH_REPLACE_ID); */ - Replace(s,name,valuestr, DOH_REPLACE_ID); + String *s = Getitem(cpatchlist, i); + Replace(s, tmp, tmpr, DOH_REPLACE_ID); + /* Replace(s,name,tydef, DOH_REPLACE_ID); */ + Replace(s, name, valuestr, DOH_REPLACE_ID); } Delete(tmp); Delete(tmpr); @@ -377,28 +377,29 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts } p = nextSibling(p); tp = nextSibling(tp); - if (!p) p = tp; + if (!p) + p = tp; } } else { /* No template parameters at all. This could be a specialization */ int i, sz; sz = Len(typelist); for (i = 0; i < sz; i++) { - String *s = Getitem(typelist,i); - SwigType_typename_replace(s,tbase,iname); + String *s = Getitem(typelist, i); + SwigType_typename_replace(s, tbase, iname); } } } /* Patch bases */ { - List *bases = Getattr(n,k_baselist); + List *bases = Getattr(n, k_baselist); if (bases) { Iterator b; for (b = First(bases); b.item; b = Next(b)) { - String *qn = Swig_symbol_type_qualify(b.item,tscope); + String *qn = Swig_symbol_type_qualify(b.item, tscope); Clear(b.item); - Append(b.item,qn); + Append(b.item, qn); Delete(qn); } } @@ -410,7 +411,7 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts Delete(tname); Delete(templateargs); - /* set_nodeType(n,k_template);*/ + /* set_nodeType(n,k_template); */ return 0; } @@ -420,168 +421,166 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts * Search for a template that matches name with given parameters. * ----------------------------------------------------------------------------- */ -static Node * -template_locate(String *name, Parm *tparms, Symtab *tscope) { - Node *n; +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; + Node *templ; + List *mpartials = 0; + Parm *p; + Parm *parms; + Parm *targs; tname = Copy(name); parms = CopyParmList(tparms); /* Search for generic template */ - templ = Swig_symbol_clookup(name,0); + templ = Swig_symbol_clookup(name, 0); /* Add default values from generic template */ if (templ) { - Symtab *tsdecl = Getattr(templ,k_symsymtab); + Symtab *tsdecl = Getattr(templ, k_symsymtab); - targs = Getattr(templ,k_templateparms); + targs = Getattr(templ, k_templateparms); Swig_symbol_template_defargs(parms, targs, tscope, tsdecl); } - + /* reduce the typedef */ p = parms; while (p) { - SwigType *ty = Getattr(p,k_type); + SwigType *ty = Getattr(p, k_type); if (ty) { - SwigType *nt = Swig_symbol_type_qualify(ty,tscope); - Setattr(p,k_type,nt); + SwigType *nt = Swig_symbol_type_qualify(ty, tscope); + Setattr(p, k_type, nt); Delete(nt); } p = nextSibling(p); } - SwigType_add_template(tname,parms); + SwigType_add_template(tname, parms); if (template_debug) { - Printf(stdout,"\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname); + 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 { ... } */ { if (template_debug) { - Printf(stdout," searching: '%s' (exact specialization)\n", tname); + Printf(stdout, " searching: '%s' (exact specialization)\n", tname); } - n = Swig_symbol_clookup_local(tname,0); + n = Swig_symbol_clookup_local(tname, 0); if (!n) { - SwigType *rname = Swig_symbol_typedef_reduce(tname,tscope); - if (!StringEqual(rname,tname)) { + SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope); + if (!StringEqual(rname, tname)) { if (template_debug) { - Printf(stdout," searching: '%s' (exact specialization)\n", rname); + Printf(stdout, " searching: '%s' (exact specialization)\n", rname); } - n = Swig_symbol_clookup_local(rname,0); + n = Swig_symbol_clookup_local(rname, 0); } Delete(rname); } if (n) { Node *tn; - String *nodeType = Getattr(n,k_nodetype); - if (StringEqual(nodeType,k_template)) goto success; - tn = Getattr(n,k_template); + String *nodeType = Getattr(n, k_nodetype); + if (StringEqual(nodeType, k_template)) + goto success; + tn = Getattr(n, k_template); if (tn) { n = tn; - goto success; /* Previously wrapped by a template return that */ + 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, Getattr(n,k_nodetype)); + Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, Getattr(n, k_nodetype)); Delete(tname); Delete(parms); - return 0; /* Found a match, but it's not a template of any kind. */ + return 0; /* Found a match, but it's not a template of any kind. */ } } - + /* Search for partial specialization. Example: template class name { ... } */ /* Generate reduced template name (stripped of extraneous pointers, etc.) */ - rname = NewStringf("%s<(",name); + rname = NewStringf("%s<(", name); p = parms; while (p) { String *t; - t = Getattr(p,k_type); - if (!t) t = Getattr(p,k_value); + t = Getattr(p, k_type); + if (!t) + t = Getattr(p, k_value); if (t) { - String *ty = Swig_symbol_typedef_reduce(t,tscope); - String *tb = SwigType_base(ty); + 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); + 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, ","); } } - 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; + /* First, we search using an exact type prototype */ + Parm *p; + char tmp[32]; + int i; + List *partials; + String *ss; + Iterator pi; - partials = Getattr(templ,k_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,k_type); - if (!t) t = Getattr(p,k_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); + partials = Getattr(templ, k_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, k_type); + if (!t) + t = Getattr(p, k_value); + if (t) { + String *ty = Swig_symbol_typedef_reduce(t, tscope); + tn = SwigType_base(ty); + Replaceid(ss, tmp, tn); + Delete(tn); + Delete(ty); } - if (template_debug) { - Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, pi.item); - } - if ((StringEqual(ss,tname)) || (StringEqual(ss,rname))) { - Append(mpartials,pi.item); - } - Delete(ss); + i++; + p = nextSibling(p); } + if (template_debug) { + Printf(stdout, " searching: '%s' (partial specialization - %s)\n", ss, pi.item); + } + if ((StringEqual(ss, tname)) || (StringEqual(ss, rname))) { + Append(mpartials, pi.item); + } + Delete(ss); } + } } if (template_debug) { - Printf(stdout," Matched partials: %s\n", mpartials); + Printf(stdout, " Matched partials: %s\n", mpartials); } if (Len(mpartials)) { - String *s = Getitem(mpartials,0); - n = Swig_symbol_clookup_local(s,0); + 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,k_name))); + 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, k_name))); } } } @@ -591,20 +590,20 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) { } if (!n) { Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name); - } else if (n) { - String *nodeType = Getattr(n,k_nodetype); - if (!StringEqual(nodeType,k_template)) { - Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType); + } else if (n) { + String *nodeType = Getattr(n, k_nodetype); + if (!StringEqual(nodeType, k_template)) { + Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType); n = 0; } } - success: +success: Delete(tname); Delete(rname); Delete(mpartials); if ((template_debug) && (n)) { - Printf(stdout,"Node: %p\n", n); - Swig_print_node(n); + Printf(stdout, "Node: %p\n", n); + Swig_print_node(n); } Delete(parms); return n; @@ -620,15 +619,14 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) { * template exists. * ----------------------------------------------------------------------------- */ -Node * -Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) { - Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */ +Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) { + Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */ if (n) { - String *nodeType = Getattr(n,k_nodetype); + String *nodeType = Getattr(n, k_nodetype); int isclass = 0; - assert(StringEqual(nodeType,k_template)); - isclass = (StringEqual(Getattr(n,k_templatetype),k_class)); + assert(StringEqual(nodeType, k_template)); + isclass = (StringEqual(Getattr(n, k_templatetype), k_class)); if (!isclass) { /* If not a templated class we must have a templated function. The template found is not necessarily the one we want when dealing with templated @@ -638,31 +636,30 @@ Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) { templated function with different numbers of template parameters. */ if (template_debug) { - Printf(stdout," Not a templated class, seeking most appropriate templated function\n"); + Printf(stdout, " Not a templated class, seeking most appropriate templated function\n"); } - n = Swig_symbol_clookup_local(name,0); + n = Swig_symbol_clookup_local(name, 0); while (n) { - Parm *tparmsfound = Getattr(n,k_templateparms); - if (ParmList_len(tparms) == ParmList_len(tparmsfound)) { - /* successful match */ - break; - } - /* repeat until we find a match with correct number of templated parameters */ - n = Getattr(n,k_symnextSibling); + Parm *tparmsfound = Getattr(n, k_templateparms); + if (ParmList_len(tparms) == ParmList_len(tparmsfound)) { + /* successful match */ + break; + } + /* repeat until we find a match with correct number of templated parameters */ + n = Getattr(n, k_symnextSibling); } - + if (!n) { - Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name); + Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name); } if ((template_debug) && (n)) { - Printf(stdout,"Templated function found: %p\n", n); - Swig_print_node(n); + Printf(stdout, "Templated function found: %p\n", n); + Swig_print_node(n); } } } return n; } - diff --git a/SWIG/Source/CParse/util.c b/SWIG/Source/CParse/util.c index 423088e6b..c70883bbd 100644 --- a/SWIG/Source/CParse/util.c +++ b/SWIG/Source/CParse/util.c @@ -21,16 +21,17 @@ char cvsroot_util_c[] = "$Header$"; * ----------------------------------------------------------------------------- */ void Swig_cparse_replace_descriptor(String *s) { - char tmp[512]; + char tmp[512]; String *arg = 0; SwigType *t; char *c = 0; - while ((c = strstr(Char(s),"$descriptor("))) { + while ((c = strstr(Char(s), "$descriptor("))) { char *d = tmp; - int level = 0; + int level = 0; while (*c) { - if (*c == '(') level++; + if (*c == '(') + level++; if (*c == ')') { level--; if (level == 0) { @@ -42,7 +43,7 @@ void Swig_cparse_replace_descriptor(String *s) { c++; } *d = 0; - arg = NewString(tmp+12); + arg = NewString(tmp + 12); t = Swig_cparse_type(arg); Delete(arg); arg = 0; @@ -50,19 +51,19 @@ void Swig_cparse_replace_descriptor(String *s) { if (t) { String *mangle; String *descriptor; - + mangle = SwigType_manglestr(t); - descriptor = NewStringf("SWIGTYPE%s",mangle); + descriptor = NewStringf("SWIGTYPE%s", mangle); SwigType_remember(t); *d = ')'; d++; *d = 0; - Replace(s,tmp,descriptor,DOH_REPLACE_ANY); + Replace(s, tmp, descriptor, DOH_REPLACE_ANY); Delete(mangle); Delete(descriptor); Delete(t); } else { - Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n"); + Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n"); break; } } @@ -76,15 +77,13 @@ void Swig_cparse_replace_descriptor(String *s) { * ----------------------------------------------------------------------------- */ void cparse_normalize_void(Node *n) { - String *decl = Getattr(n,k_decl); - Parm *parms = Getattr(n,k_parms); + String *decl = Getattr(n, k_decl); + Parm *parms = Getattr(n, k_parms); if (SwigType_isfunction(decl)) { - if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms,k_type)) == T_VOID)) { - Replaceall(decl,"f(void).","f()."); - Delattr(n,k_parms); + if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms, k_type)) == T_VOID)) { + Replaceall(decl, "f(void).", "f()."); + Delattr(n, k_parms); } } } - - diff --git a/SWIG/Source/DOH/base.c b/SWIG/Source/DOH/base.c index 6e3964612..7e669b268 100644 --- a/SWIG/Source/DOH/base.c +++ b/SWIG/Source/DOH/base.c @@ -22,27 +22,29 @@ char cvsroot_base_c[] = "$Header$"; #define SWIG_DEBUG_DELETE 0 #endif -void -DohDelete(DOH *obj) { +void DohDelete(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!obj) return; + if (!obj) + return; #if SWIG_DEBUG_DELETE if (!DohCheck(b)) { - fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n",stderr); + fputs("DOH: Fatal error. Attempt to delete a non-doh object.\n", stderr); abort(); } #endif - if (b->flag_intern) return; + if (b->flag_intern) + return; assert(b->refcount > 0); b->refcount--; if (b->refcount <= 0) { objinfo = b->type; if (objinfo->doh_del) { - (objinfo->doh_del)(b); + (objinfo->doh_del) (b); } else { - if (b->data) DohFree(b->data); + if (b->data) + DohFree(b->data); } DohObjFree(b); } @@ -52,15 +54,15 @@ DohDelete(DOH *obj) { * DohCopy() * ----------------------------------------------------------------------------- */ -DOH * -DohCopy(const DOH *obj) { +DOH *DohCopy(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!obj) return 0; + if (!obj) + return 0; objinfo = b->type; if (objinfo->doh_copy) { - DohBase *bc = (DohBase *) (objinfo->doh_copy)(b); + DohBase *bc = (DohBase *) (objinfo->doh_copy) (b); if ((bc) && b->meta) { bc->meta = Copy(b->meta); } @@ -69,8 +71,7 @@ DohCopy(const DOH *obj) { return 0; } -void -DohIncref(DOH *obj) { +void DohIncref(DOH *obj) { Incref(obj); } @@ -78,29 +79,27 @@ DohIncref(DOH *obj) { * DohClear() * ----------------------------------------------------------------------------- */ -void -DohClear(DOH *obj) { +void DohClear(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_clear) - (objinfo->doh_clear)(b); + (objinfo->doh_clear) (b); } /* ----------------------------------------------------------------------------- * DohStr() * ----------------------------------------------------------------------------- */ -DOH * -DohStr(const DOH *obj) { +DOH *DohStr(const DOH *obj) { char buffer[512]; DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(b)) { objinfo = b->type; if (objinfo->doh_str) { - return (objinfo->doh_str)(b); + return (objinfo->doh_str) (b); } - sprintf(buffer,"", objinfo->objname, (void *)b); + sprintf(buffer, "", objinfo->objname, (void *) b); return NewString(buffer); } else { return NewString(obj); @@ -111,12 +110,11 @@ DohStr(const DOH *obj) { * DohDump() * ----------------------------------------------------------------------------- */ -int -DohDump(const DOH *obj, DOH *out) { +int DohDump(const DOH *obj, DOH *out) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_dump) { - return (objinfo->doh_dump)(b,out); + return (objinfo->doh_dump) (b, out); } return 0; } @@ -124,15 +122,15 @@ DohDump(const DOH *obj, DOH *out) { /* ----------------------------------------------------------------------------- * DohLen() - Defaults to strlen() if not a DOH object * ----------------------------------------------------------------------------- */ -int -DohLen(const DOH *obj) { +int DohLen(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!b) return 0; + if (!b) + return 0; if (DohCheck(b)) { objinfo = b->type; if (objinfo->doh_len) { - return (objinfo->doh_len)(b); + return (objinfo->doh_len) (b); } return 0; } else { @@ -144,8 +142,7 @@ DohLen(const DOH *obj) { * DohHashVal() * ----------------------------------------------------------------------------- */ -int -DohHashval(const DOH *obj) { +int DohHashval(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; /* obj is already checked and/or converted into DohBase* */ @@ -153,7 +150,7 @@ DohHashval(const DOH *obj) { { objinfo = b->type; if (objinfo->doh_hashval) { - return (objinfo->doh_hashval)(b); + return (objinfo->doh_hashval) (b); } } return 0; @@ -163,14 +160,13 @@ DohHashval(const DOH *obj) { * DohData() * ----------------------------------------------------------------------------- */ -void * -DohData(const DOH *obj) { +void *DohData(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if (objinfo->doh_data) { - return (objinfo->doh_data)(b); + return (objinfo->doh_data) (b); } return 0; } @@ -181,10 +177,9 @@ DohData(const DOH *obj) { * RawData() * ----------------------------------------------------------------------------- */ -static void * -RawData(DohBase *b) { +static void *RawData(DohBase *b) { DohObjInfo *objinfo = b->type; - return (objinfo->doh_data) ? (objinfo->doh_data)(b) : 0; + return (objinfo->doh_data) ? (objinfo->doh_data) (b) : 0; } @@ -192,8 +187,7 @@ RawData(DohBase *b) { * DohCmp() * ----------------------------------------------------------------------------- */ -int -DohCmp(const DOH *obj1, const DOH *obj2) { +int DohCmp(const DOH *obj1, const DOH *obj2) { DohBase *b1, *b2; DohObjInfo *b1info, *b2info; int c1, c2; @@ -201,18 +195,20 @@ DohCmp(const DOH *obj1, const DOH *obj2) { b2 = (DohBase *) obj2; c1 = DohCheck(b1); c2 = DohCheck(b2); - /* most of the times, obj2 is a plain c string */ + /* most of the times, obj2 is a plain c string */ if (!c1 || !c2) { - if ((b1 == 0) && (b2 == 0)) return 0; - if (b1 && !b2) return 1; - if (!b1 && b2) return -1; - return strcmp((char *) (c1 ? RawData(b1) : (void*) obj1), - (char *) (c2 ? RawData(b2) : (void*) obj2)); + if ((b1 == 0) && (b2 == 0)) + return 0; + if (b1 && !b2) + return 1; + if (!b1 && b2) + return -1; + return strcmp((char *) (c1 ? RawData(b1) : (void *) obj1), (char *) (c2 ? RawData(b2) : (void *) obj2)); } b1info = b1->type; b2info = b2->type; - if ((b1info == b2info) && (b1info->doh_cmp)) - return (b1info->doh_cmp)(b1,b2); + if ((b1info == b2info) && (b1info->doh_cmp)) + return (b1info->doh_cmp) (b1, b2); return 1; } @@ -220,8 +216,7 @@ DohCmp(const DOH *obj1, const DOH *obj2) { * DohEqual() * ----------------------------------------------------------------------------- */ -int -DohEqual(const DOH *obj1, const DOH *obj2) { +int DohEqual(const DOH *obj1, const DOH *obj2) { DohBase *b1 = (DohBase *) obj1; DohBase *b2 = (DohBase *) obj2; if (!b1) { @@ -236,23 +231,22 @@ DohEqual(const DOH *obj1, const DOH *obj2) { if (DohCheck(b2)) { b2info = b2->type; } else { - int len = (b1info->doh_len)(b1); + int len = (b1info->doh_len) (b1); char *cobj = (char *) obj2; - return len == (int)strlen(cobj) ? (memcmp(RawData(b1), cobj, len) == 0) : 0; + return len == (int) strlen(cobj) ? (memcmp(RawData(b1), cobj, len) == 0) : 0; } } else if (DohCheck(b2)) { - int len = (b2->type->doh_len)(b2); + int len = (b2->type->doh_len) (b2); char *cobj = (char *) obj1; - return len == (int)strlen(cobj) ? (memcmp(RawData(b2), cobj, len) == 0) : 0; + return len == (int) strlen(cobj) ? (memcmp(RawData(b2), cobj, len) == 0) : 0; } else { - return strcmp((char*) obj1, (char*) obj2) == 0; + return strcmp((char *) obj1, (char *) obj2) == 0; } - + if (!b1info) { return obj1 == obj2; } else if ((b1info == b2info)) { - return b1info->doh_equal ? (b1info->doh_equal)(b1,b2) : - (b1info->doh_cmp ? (b1info->doh_cmp)(b1,b2) == 0 : (b1 == b2)); + return b1info->doh_equal ? (b1info->doh_equal) (b1, b2) : (b1info->doh_cmp ? (b1info->doh_cmp) (b1, b2) == 0 : (b1 == b2)); } else { return 0; } @@ -263,24 +257,23 @@ DohEqual(const DOH *obj1, const DOH *obj2) { * DohFirst() * ----------------------------------------------------------------------------- */ -DohIterator -DohFirst(DOH *obj) { +DohIterator DohFirst(DOH *obj) { DohIterator iter; - DohBase *b; - DohObjInfo *binfo; + DohBase *b; + DohObjInfo *binfo; b = (DohBase *) obj; if (DohCheck(b)) { binfo = b->type; if (binfo->doh_first) { - return (binfo->doh_first)(b); + return (binfo->doh_first) (b); } } - iter.object = 0; - iter.item = 0; - iter.key = 0; - iter._current= 0; - iter._index = 0; + iter.object = 0; + iter.item = 0; + iter.key = 0; + iter._current = 0; + iter._index = 0; return iter; } @@ -288,18 +281,17 @@ DohFirst(DOH *obj) { * DohNext() * ----------------------------------------------------------------------------- */ -DohIterator -DohNext(DohIterator iter) { +DohIterator DohNext(DohIterator iter) { DohIterator niter; if (iter.object) { DohBase *b; DohObjInfo *binfo; - + b = (DohBase *) iter.object; binfo = b->type; if (binfo->doh_next) { - return (binfo->doh_next)(iter); + return (binfo->doh_next) (iter); } } niter = iter; @@ -309,26 +301,27 @@ DohNext(DohIterator iter) { /* ----------------------------------------------------------------------------- * DohIsMapping() * ----------------------------------------------------------------------------- */ -int -DohIsMapping(const DOH *obj) { +int DohIsMapping(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!DohCheck(b)) return 0; + if (!DohCheck(b)) + return 0; objinfo = b->type; - if (objinfo->doh_hash) return 1; - else return 0; + if (objinfo->doh_hash) + return 1; + else + return 0; } /* ----------------------------------------------------------------------------- * DohGetattr() * ----------------------------------------------------------------------------- */ -DOH * -DohGetattr(DOH *obj, const DOH *name) { +DOH *DohGetattr(DOH *obj, const DOH *name) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_hash && objinfo->doh_hash->doh_getattr) { - DOH *r = (objinfo->doh_hash->doh_getattr)(b,(DOH *) name); + DOH *r = (objinfo->doh_hash->doh_getattr) (b, (DOH *) name); return (r == DohNone) ? 0 : r; } return 0; @@ -338,12 +331,11 @@ DohGetattr(DOH *obj, const DOH *name) { * DohSetattr() * ----------------------------------------------------------------------------- */ -int -DohSetattr(DOH *obj, const DOH *name, const DOH *value) { +int DohSetattr(DOH *obj, const DOH *name, const DOH *value) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_hash && objinfo->doh_hash->doh_setattr) { - return (objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value); + return (objinfo->doh_hash->doh_setattr) (b, (DOH *) name, (DOH *) value); } return 0; } @@ -352,12 +344,11 @@ DohSetattr(DOH *obj, const DOH *name, const DOH *value) { * DohDelattr() * ----------------------------------------------------------------------------- */ -int -DohDelattr(DOH *obj, const DOH *name) { +int DohDelattr(DOH *obj, const DOH *name) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_hash && objinfo->doh_hash->doh_delattr) { - return (objinfo->doh_hash->doh_delattr)(b,(DOH *) name); + return (objinfo->doh_hash->doh_delattr) (b, (DOH *) name); } return 0; } @@ -366,12 +357,11 @@ DohDelattr(DOH *obj, const DOH *name) { * DohKeys() * ----------------------------------------------------------------------------- */ -DOH * -DohKeys(DOH *obj) { +DOH *DohKeys(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo && objinfo->doh_hash->doh_keys) { - return (objinfo->doh_hash->doh_keys)(b); + return (objinfo->doh_hash->doh_keys) (b); } return 0; } @@ -380,11 +370,11 @@ DohKeys(DOH *obj) { * DohGetInt() * ----------------------------------------------------------------------------- */ -int -DohGetInt(DOH *obj, const DOH *name) { +int DohGetInt(DOH *obj, const DOH *name) { DOH *val; - val = Getattr(obj,(DOH *) name); - if (!val) return 0; + val = Getattr(obj, (DOH *) name); + if (!val) + return 0; if (DohIsString(val)) { return atoi((char *) Data(val)); } @@ -395,11 +385,11 @@ DohGetInt(DOH *obj, const DOH *name) { * DohGetDouble() * ----------------------------------------------------------------------------- */ -double -DohGetDouble(DOH *obj, const DOH *name) { +double DohGetDouble(DOH *obj, const DOH *name) { DOH *val; - val = Getattr(obj,(DOH *) name); - if (!val) return 0; + val = Getattr(obj, (DOH *) name); + if (!val) + return 0; if (DohIsString(val)) { return atof((char *) Data(val)); } @@ -410,11 +400,11 @@ DohGetDouble(DOH *obj, const DOH *name) { * DohGetChar() * ----------------------------------------------------------------------------- */ -char * -DohGetChar(DOH *obj, const DOH *name) { +char *DohGetChar(DOH *obj, const DOH *name) { DOH *val; - val = Getattr(obj,(DOH *) name); - if (!val) return 0; + val = Getattr(obj, (DOH *) name); + if (!val) + return 0; if (DohIsString(val)) { return (char *) Data(val); } @@ -432,21 +422,20 @@ DohGetChar(DOH *obj, const DOH *name) { * ----------------------------------------------------------------------------- */ -DOH * -DohGetFlagAttr(DOH *obj, const DOH *name) { - DOH *val = Getattr(obj,(DOH *) name); +DOH *DohGetFlagAttr(DOH *obj, const DOH *name) { + DOH *val = Getattr(obj, (DOH *) name); if (!val) { return NULL; } else { const char *cval = Char(val); - if (!cval) return val; + if (!cval) + return val; return (strcmp(cval, "0") != 0) ? val : NULL; } } -int -DohGetFlag(DOH *obj, const DOH *name) { - return DohGetFlagAttr(obj, name) ? 1: 0; +int DohGetFlag(DOH *obj, const DOH *name) { + return DohGetFlagAttr(obj, name) ? 1 : 0; } @@ -454,11 +443,11 @@ DohGetFlag(DOH *obj, const DOH *name) { * DohGetVoid() * ----------------------------------------------------------------------------- */ -void * -DohGetVoid(DOH *obj, const DOH *name) { +void *DohGetVoid(DOH *obj, const DOH *name) { DOH *val; - val = Getattr(obj,(DOH *) name); - if (!val) return 0; + val = Getattr(obj, (DOH *) name); + if (!val) + return 0; return (void *) Data(val); } @@ -466,82 +455,77 @@ DohGetVoid(DOH *obj, const DOH *name) { * DohSetInt() * ----------------------------------------------------------------------------- */ -void -DohSetInt(DOH *obj, const DOH *name, int value) { +void DohSetInt(DOH *obj, const DOH *name, int value) { DOH *temp; temp = NewStringEmpty(); - Printf(temp,"%d",value); - Setattr(obj,(DOH *) name,temp); + Printf(temp, "%d", value); + Setattr(obj, (DOH *) name, temp); } /* ----------------------------------------------------------------------------- * DohSetDouble() * ----------------------------------------------------------------------------- */ -void -DohSetDouble(DOH *obj, const DOH *name, double value) { +void DohSetDouble(DOH *obj, const DOH *name, double value) { DOH *temp; temp = NewStringEmpty(); - Printf(temp,"%0.17f",value); - Setattr(obj,(DOH *) name,temp); + Printf(temp, "%0.17f", value); + Setattr(obj, (DOH *) name, temp); } /* ----------------------------------------------------------------------------- * DohSetChar() * ----------------------------------------------------------------------------- */ -void -DohSetChar(DOH *obj, const DOH *name, char *value) { - Setattr(obj,(DOH *) name,NewString(value)); +void DohSetChar(DOH *obj, const DOH *name, char *value) { + Setattr(obj, (DOH *) name, NewString(value)); } /* ----------------------------------------------------------------------------- * DohSetFlag() * ----------------------------------------------------------------------------- */ -void -DohSetFlagAttr(DOH *obj, const DOH *name, const DOH* attr) { - Setattr(obj,(DOH *) name, attr ? attr : NewString("0")); +void DohSetFlagAttr(DOH *obj, const DOH *name, const DOH *attr) { + Setattr(obj, (DOH *) name, attr ? attr : NewString("0")); } -void -DohSetFlag(DOH *obj, const DOH *name) { - Setattr(obj,(DOH *) name, NewString("1")); +void DohSetFlag(DOH *obj, const DOH *name) { + Setattr(obj, (DOH *) name, NewString("1")); } /* ----------------------------------------------------------------------------- * DohSetVoid() * ----------------------------------------------------------------------------- */ -void -DohSetVoid(DOH *obj, const DOH *name, void *value) { - Setattr(obj,(DOH *) name,NewVoid(value,0)); +void DohSetVoid(DOH *obj, const DOH *name, void *value) { + Setattr(obj, (DOH *) name, NewVoid(value, 0)); } /* ----------------------------------------------------------------------------- * DohIsSequence() * ----------------------------------------------------------------------------- */ -int -DohIsSequence(const DOH *obj) { +int DohIsSequence(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!DohCheck(b)) return 0; + if (!DohCheck(b)) + return 0; objinfo = b->type; - if (objinfo->doh_list) return 1; - else return 0; + if (objinfo->doh_list) + return 1; + else + return 0; } /* ----------------------------------------------------------------------------- * DohGetitem() * ----------------------------------------------------------------------------- */ -DOH * -DohGetitem(DOH *obj, int index) { +DOH *DohGetitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_list && objinfo->doh_list->doh_getitem) { - return (objinfo->doh_list->doh_getitem)(b,index); + return (objinfo->doh_list->doh_getitem) (b, index); } return 0; } @@ -550,12 +534,11 @@ DohGetitem(DOH *obj, int index) { * DohSetitem() * ----------------------------------------------------------------------------- */ -int -DohSetitem(DOH *obj, int index, const DOH *value) { +int DohSetitem(DOH *obj, int index, const DOH *value) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_list && objinfo->doh_list->doh_setitem) { - return (objinfo->doh_list->doh_setitem)(b,index,(DOH *) value); + return (objinfo->doh_list->doh_setitem) (b, index, (DOH *) value); } return -1; } @@ -564,12 +547,11 @@ DohSetitem(DOH *obj, int index, const DOH *value) { * DohDelitem() * ----------------------------------------------------------------------------- */ -int -DohDelitem(DOH *obj, int index) { +int DohDelitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_list && objinfo->doh_list->doh_delitem) { - return (objinfo->doh_list->doh_delitem)(b,index); + return (objinfo->doh_list->doh_delitem) (b, index); } return -1; } @@ -578,12 +560,11 @@ DohDelitem(DOH *obj, int index) { * DohInsertitem() * ----------------------------------------------------------------------------- */ -int -DohInsertitem(DOH *obj, int index, const DOH *value) { +int DohInsertitem(DOH *obj, int index, const DOH *value) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_list && objinfo->doh_list->doh_insitem) { - return (objinfo->doh_list->doh_insitem)(b,index,(DOH *) value); + return (objinfo->doh_list->doh_insitem) (b, index, (DOH *) value); } return -1; } @@ -593,12 +574,11 @@ DohInsertitem(DOH *obj, int index, const DOH *value) { * DohDelslice() * ----------------------------------------------------------------------------- */ -int -DohDelslice(DOH *obj, int sindex, int eindex) { +int DohDelslice(DOH *obj, int sindex, int eindex) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo = b->type; if (objinfo->doh_list && objinfo->doh_list->doh_delslice) { - return (objinfo->doh_list->doh_delslice)(b,sindex,eindex); + return (objinfo->doh_list->doh_delslice) (b, sindex, eindex); } return -1; } @@ -607,66 +587,65 @@ DohDelslice(DOH *obj, int sindex, int eindex) { * DohIsFile() * ----------------------------------------------------------------------------- */ -int -DohIsFile(const DOH *obj) { +int DohIsFile(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!DohCheck(b)) return 0; + if (!DohCheck(b)) + return 0; objinfo = b->type; - if (objinfo->doh_file) return 1; - else return 0; + if (objinfo->doh_file) + return 1; + else + return 0; } /* ----------------------------------------------------------------------------- * DohRead() * ----------------------------------------------------------------------------- */ -int -DohRead(DOH *obj, void *buffer, int length) { +int DohRead(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if ((objinfo->doh_file) && (objinfo->doh_file->doh_read)) { - return (objinfo->doh_file->doh_read)(b,buffer,length); + return (objinfo->doh_file->doh_read) (b, buffer, length); } return -1; } /* Hmmm. Not a file. Maybe it's a real FILE */ - return fread(buffer,1,length,(FILE *) b); + return fread(buffer, 1, length, (FILE *) b); } /* ----------------------------------------------------------------------------- * DohWrite() * ----------------------------------------------------------------------------- */ -int -DohWrite(DOH *obj, void *buffer, int length) { +int DohWrite(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) { - return (objinfo->doh_file->doh_write)(b,buffer,length); + return (objinfo->doh_file->doh_write) (b, buffer, length); } return -1; } /* Hmmm. Not a file. Maybe it's a real FILE */ - return fwrite(buffer,1,length,(FILE *) b); + return fwrite(buffer, 1, length, (FILE *) b); } /* ----------------------------------------------------------------------------- * DohSeek() * ----------------------------------------------------------------------------- */ -int -DohSeek(DOH *obj, long offset, int whence) { +int DohSeek(DOH *obj, long offset, int whence) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) { - return (objinfo->doh_file->doh_seek)(b,offset,whence); + return (objinfo->doh_file->doh_seek) (b, offset, whence); } return -1; } @@ -677,14 +656,13 @@ DohSeek(DOH *obj, long offset, int whence) { * DohTell() * ----------------------------------------------------------------------------- */ -long -DohTell(DOH *obj) { +long DohTell(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) { - return (objinfo->doh_file->doh_tell)(b); + return (objinfo->doh_file->doh_tell) (b); } return -1; } @@ -695,20 +673,19 @@ DohTell(DOH *obj) { * DohGetc() * ----------------------------------------------------------------------------- */ -int -DohGetc(DOH *obj) { +int DohGetc(DOH *obj) { static DOH *lastdoh = 0; DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (obj == lastdoh) { objinfo = b->type; - return (objinfo->doh_file->doh_getc)(b); + return (objinfo->doh_file->doh_getc) (b); } if (DohCheck(obj)) { objinfo = b->type; if (objinfo->doh_file->doh_getc) { lastdoh = obj; - return (objinfo->doh_file->doh_getc)(b); + return (objinfo->doh_file->doh_getc) (b); } return EOF; } @@ -719,57 +696,54 @@ DohGetc(DOH *obj) { * DohPutc() * ----------------------------------------------------------------------------- */ -int -DohPutc(int ch, DOH *obj) { +int DohPutc(int ch, DOH *obj) { static DOH *lastdoh = 0; DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (obj == lastdoh) { objinfo = b->type; - return (objinfo->doh_file->doh_putc)(b,ch); + return (objinfo->doh_file->doh_putc) (b, ch); } if (DohCheck(obj)) { objinfo = b->type; if (objinfo->doh_file->doh_putc) { lastdoh = obj; - return (objinfo->doh_file->doh_putc)(b,ch); + return (objinfo->doh_file->doh_putc) (b, ch); } return EOF; } - return fputc(ch,(FILE *) b); + return fputc(ch, (FILE *) b); } /* ----------------------------------------------------------------------------- * DohUngetc() * ----------------------------------------------------------------------------- */ -int -DohUngetc(int ch, DOH *obj) { +int DohUngetc(int ch, DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if (objinfo->doh_file->doh_ungetc) { - return (objinfo->doh_file->doh_ungetc)(b,ch); + return (objinfo->doh_file->doh_ungetc) (b, ch); } return EOF; } - return ungetc(ch,(FILE *) b); + return ungetc(ch, (FILE *) b); } /* ----------------------------------------------------------------------------- * DohClose() * ----------------------------------------------------------------------------- */ -int -DohClose(DOH *obj) { +int DohClose(DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; if (DohCheck(obj)) { objinfo = b->type; if (objinfo->doh_file->doh_close) { - return (objinfo->doh_file->doh_close)(b); + return (objinfo->doh_file->doh_close) (b); } return 0; } @@ -780,30 +754,33 @@ DohClose(DOH *obj) { * DohIsString() * ----------------------------------------------------------------------------- */ -int -DohIsString(const DOH *obj) { +int DohIsString(const DOH *obj) { DohBase *b = (DohBase *) obj; DohObjInfo *objinfo; - if (!DohCheck(b)) return 0; + if (!DohCheck(b)) + return 0; objinfo = b->type; - if (objinfo->doh_string) return 1; - else return 0; + if (objinfo->doh_string) + return 1; + else + return 0; } /* ----------------------------------------------------------------------------- * DohReplace() * ----------------------------------------------------------------------------- */ -int -DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) { +int DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) { DohBase *b = (DohBase *) src; DohObjInfo *objinfo; - if (!token) return 0; - if (!rep) rep = ""; + if (!token) + return 0; + if (!rep) + rep = ""; if (DohIsString(src)) { objinfo = b->type; if (objinfo->doh_string->doh_replace) { - return (objinfo->doh_string->doh_replace)(b,(DOH *) token, (DOH *) rep,flags); + return (objinfo->doh_string->doh_replace) (b, (DOH *) token, (DOH *) rep, flags); } } return 0; @@ -813,14 +790,13 @@ DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) { * DohChop() * ----------------------------------------------------------------------------- */ -void -DohChop(DOH *src) { +void DohChop(DOH *src) { DohBase *b = (DohBase *) src; DohObjInfo *objinfo; if (DohIsString(src)) { objinfo = b->type; if (objinfo->doh_string->doh_chop) { - (objinfo->doh_string->doh_chop)(b); + (objinfo->doh_string->doh_chop) (b); } } } @@ -828,54 +804,54 @@ DohChop(DOH *src) { /* ----------------------------------------------------------------------------- * DohSetFile() * ----------------------------------------------------------------------------- */ -void -DohSetfile(DOH *ho, DOH *file) { +void DohSetfile(DOH *ho, DOH *file) { DohBase *h = (DohBase *) ho; DohObjInfo *objinfo; - if (!h) return; + if (!h) + return; objinfo = h->type; if (objinfo->doh_setfile) - (objinfo->doh_setfile)(h,file); + (objinfo->doh_setfile) (h, file); } /* ----------------------------------------------------------------------------- * DohGetFile() * ----------------------------------------------------------------------------- */ -DOH * -DohGetfile(DOH *ho) { +DOH *DohGetfile(DOH *ho) { DohBase *h = (DohBase *) ho; DohObjInfo *objinfo; - if (!h) return 0; + if (!h) + return 0; objinfo = h->type; - if (objinfo->doh_getfile) - return (objinfo->doh_getfile)(h); + if (objinfo->doh_getfile) + return (objinfo->doh_getfile) (h); return 0; } /* ----------------------------------------------------------------------------- * DohSetLine() * ----------------------------------------------------------------------------- */ -void -DohSetline(DOH *ho, int l) { +void DohSetline(DOH *ho, int l) { DohBase *h = (DohBase *) ho; DohObjInfo *objinfo; - if (!h) return; + if (!h) + return; objinfo = h->type; - if (objinfo->doh_setline) - (objinfo->doh_setline)(h,l); + if (objinfo->doh_setline) + (objinfo->doh_setline) (h, l); } /* ----------------------------------------------------------------------------- * DohGetLine() * ----------------------------------------------------------------------------- */ -int -DohGetline(DOH *ho) { +int DohGetline(DOH *ho) { DohBase *h = (DohBase *) ho; DohObjInfo *objinfo; - if (!h) return 0; + if (!h) + return 0; objinfo = h->type; - if (objinfo->doh_getline) - return (objinfo->doh_getline)(h); + if (objinfo->doh_getline) + return (objinfo->doh_getline) (h); return 0; } @@ -883,35 +859,38 @@ DohGetline(DOH *ho) { * DohGetmeta() * ----------------------------------------------------------------------------- */ -DOH * -DohGetmeta(DOH *ho, const DOH *name) { +DOH *DohGetmeta(DOH *ho, const DOH *name) { DohBase *h = (DohBase *) ho; - if (!DohCheck(ho)) return 0; - if (!h->meta) return 0; - return DohGetattr(h->meta,name); + if (!DohCheck(ho)) + return 0; + if (!h->meta) + return 0; + return DohGetattr(h->meta, name); } /* ----------------------------------------------------------------------------- * DohGetmeta() * ----------------------------------------------------------------------------- */ -int -DohSetmeta(DOH *ho, const DOH *name, const DOH *value) { +int DohSetmeta(DOH *ho, const DOH *name, const DOH *value) { DohBase *h = (DohBase *) ho; - if (!DohCheck(ho)) return 0; - if (!h->meta) h->meta = NewHash(); + if (!DohCheck(ho)) + return 0; + if (!h->meta) + h->meta = NewHash(); return DohSetattr(h->meta, name, value); } /* ----------------------------------------------------------------------------- * DohDelmeta() - * ----------------------------------------------------------------------------- */ + * ----------------------------------------------------------------------------- */ -int -DohDelmeta(DOH *ho, const DOH *name) { +int DohDelmeta(DOH *ho, const DOH *name) { DohBase *h = (DohBase *) ho; - if (!DohCheck(ho)) return 0; - if (!h->meta) return 0; + if (!DohCheck(ho)) + return 0; + if (!h->meta) + return 0; return DohDelattr(h->meta, name); } @@ -919,14 +898,12 @@ DohDelmeta(DOH *ho, const DOH *name) { * DohSetmark() * ----------------------------------------------------------------------------- */ -void -DohSetmark(DOH *ho, int x) { +void DohSetmark(DOH *ho, int x) { DohBase *h = (DohBase *) ho; h->flag_usermark = x; } -int -DohGetmark(DOH *ho) { +int DohGetmark(DOH *ho) { DohBase *h = (DohBase *) ho; return h->flag_usermark; } @@ -944,14 +921,13 @@ DohGetmark(DOH *ho) { * Returns a DOH object with result on success. Returns NULL on error * ----------------------------------------------------------------------------- */ -DOH * -DohCall(DOH *func, DOH *args) { +DOH *DohCall(DOH *func, DOH *args) { DOH *result; - DOH *(*builtin)(DOH *); + DOH *(*builtin) (DOH *); - builtin = (DOH *(*)(DOH *)) GetVoid(func,"builtin"); - if (!builtin) return 0; - result = (*builtin)(args); + builtin = (DOH *(*)(DOH *)) GetVoid(func, "builtin"); + if (!builtin) + return 0; + result = (*builtin) (args); return result; } - diff --git a/SWIG/Source/DOH/doh.h b/SWIG/Source/DOH/doh.h index 513c98b4e..777234b0d 100644 --- a/SWIG/Source/DOH/doh.h +++ b/SWIG/Source/DOH/doh.h @@ -165,11 +165,11 @@ typedef void DOH; /* Iterator objects */ typedef struct { - void *key; /* Current key (if any) */ - void *item; /* Current item */ - void *object; /* Object being iterated over */ - void *_current; /* Internal use */ - int _index; /* Internal use */ + void *key; /* Current key (if any) */ + void *item; /* Current item */ + void *object; /* Object being iterated over */ + void *_current; /* Internal use */ + int _index; /* Internal use */ } DohIterator; /* Memory management */ @@ -184,77 +184,77 @@ typedef struct { #define DohFree free #endif -extern int DohCheck(const DOH *ptr); /* Check if a DOH object */ -extern void DohIntern(DOH *); /* Intern an object */ +extern int DohCheck(const DOH *ptr); /* Check if a DOH object */ +extern void DohIntern(DOH *); /* Intern an object */ /* Basic object methods. Common to most objects */ -extern void DohDelete(DOH *obj); /* Delete an object */ -extern DOH *DohCopy(const DOH *obj); -extern void DohClear(DOH *obj); -extern DOHString *DohStr(const DOH *obj); -extern void *DohData(const DOH *obj); -extern int DohDump(const DOH *obj, DOHFile *out); -extern int DohLen(const DOH *obj); -extern int DohHashval(const DOH *obj); -extern int DohCmp(const DOH *obj1, const DOH *obj2); -extern int DohEqual(const DOH *obj1, const DOH *obj2); -extern void DohIncref(DOH *obj); +extern void DohDelete(DOH *obj); /* Delete an object */ +extern DOH *DohCopy(const DOH *obj); +extern void DohClear(DOH *obj); +extern DOHString *DohStr(const DOH *obj); +extern void *DohData(const DOH *obj); +extern int DohDump(const DOH *obj, DOHFile * out); +extern int DohLen(const DOH *obj); +extern int DohHashval(const DOH *obj); +extern int DohCmp(const DOH *obj1, const DOH *obj2); +extern int DohEqual(const DOH *obj1, const DOH *obj2); +extern void DohIncref(DOH *obj); /* Mapping methods */ -extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name); -extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value); -extern int DohDelattr(DOH *obj, const DOHString_or_char *name); -extern DOH *DohKeys(DOH *obj); -extern int DohGetInt(DOH *obj, const DOHString_or_char *name); -extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int); -extern double DohGetDouble(DOH *obj, const DOHString_or_char *name); -extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); -extern char *DohGetChar(DOH *obj, const DOHString_or_char *name); -extern void DohSetChar(DOH *obj, const DOH *name, char *value); -extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name); -extern int DohGetFlag(DOH *obj, const DOHString_or_char *name); -extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr); -extern void DohSetFlag(DOH *obj, const DOHString_or_char *name); -extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); -extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); +extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name); +extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char * value); +extern int DohDelattr(DOH *obj, const DOHString_or_char *name); +extern DOH *DohKeys(DOH *obj); +extern int DohGetInt(DOH *obj, const DOHString_or_char *name); +extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int); +extern double DohGetDouble(DOH *obj, const DOHString_or_char *name); +extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); +extern char *DohGetChar(DOH *obj, const DOHString_or_char *name); +extern void DohSetChar(DOH *obj, const DOH *name, char *value); +extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name); +extern int DohGetFlag(DOH *obj, const DOHString_or_char *name); +extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr); +extern void DohSetFlag(DOH *obj, const DOHString_or_char *name); +extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); +extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); /* Sequence methods */ -extern DOH *DohGetitem(DOH *obj, int index); -extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value); -extern int DohDelitem(DOH *obj, int index); -extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value); -extern int DohDelslice(DOH *obj, int sindex, int eindex); +extern DOH *DohGetitem(DOH *obj, int index); +extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char * value); +extern int DohDelitem(DOH *obj, int index); +extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char * value); +extern int DohDelslice(DOH *obj, int sindex, int eindex); /* File methods */ -extern int DohWrite(DOHFile *obj, void *buffer, int length); -extern int DohRead(DOHFile *obj, void *buffer, int length); -extern int DohSeek(DOHFile *obj, long offset, int whence); -extern long DohTell(DOHFile *obj); -extern int DohGetc(DOHFile *obj); -extern int DohPutc(int ch, DOHFile *obj); -extern int DohUngetc(int ch, DOHFile *obj); +extern int DohWrite(DOHFile * obj, void *buffer, int length); +extern int DohRead(DOHFile * obj, void *buffer, int length); +extern int DohSeek(DOHFile * obj, long offset, int whence); +extern long DohTell(DOHFile * obj); +extern int DohGetc(DOHFile * obj); +extern int DohPutc(int ch, DOHFile * obj); +extern int DohUngetc(int ch, DOHFile * obj); /* Iterators */ -extern DohIterator DohFirst(DOH *obj); -extern DohIterator DohNext(DohIterator x); +extern DohIterator DohFirst(DOH *obj); +extern DohIterator DohNext(DohIterator x); /* Positional */ -extern int DohGetline(DOH *obj); -extern void DohSetline(DOH *obj, int line); -extern DOH *DohGetfile(DOH *obj); -extern void DohSetfile(DOH *obj, DOH *file); +extern int DohGetline(DOH *obj); +extern void DohSetline(DOH *obj, int line); +extern DOH *DohGetfile(DOH *obj); +extern void DohSetfile(DOH *obj, DOH *file); /* String Methods */ -extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags); -extern void DohChop(DOHString *src); +extern int DohReplace(DOHString * src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags); +extern void DohChop(DOHString * src); extern int DohString_putc(DOH *so, int ch); extern int DohString_getc(DOH *so); @@ -274,39 +274,39 @@ extern int DohString_delslice(DOH *so, int sindex, int eindex); #define DohStringEqual(s1,s2) DohString_equal((DOH *)s1, (DOH *)s2) /* Meta-variables */ -extern DOH *DohGetmeta(DOH *, const DOH *); -extern int DohSetmeta(DOH *, const DOH *, const DOH *value); -extern int DohDelmeta(DOH *, const DOH *); +extern DOH *DohGetmeta(DOH *, const DOH *); +extern int DohSetmeta(DOH *, const DOH *, const DOH *value); +extern int DohDelmeta(DOH *, const DOH *); /* Utility functions */ -extern void DohEncoding(char *name, DOH *(*fn)(DOH *s)); -extern int DohPrintf(DOHFile *obj, const char *format, ...); -extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap); -extern int DohPrintv(DOHFile *obj, ...); -extern DOH *DohReadline(DOHFile *in); +extern void DohEncoding(char *name, DOH *(*fn) (DOH *s)); +extern int DohPrintf(DOHFile * obj, const char *format, ...); +extern int DohvPrintf(DOHFile * obj, const char *format, va_list ap); +extern int DohPrintv(DOHFile * obj, ...); +extern DOH *DohReadline(DOHFile * in); /* Miscellaneous */ -extern int DohIsMapping(const DOH *obj); -extern int DohIsSequence(const DOH *obj); -extern int DohIsString(const DOH *obj); -extern int DohIsFile(const DOH *obj); +extern int DohIsMapping(const DOH *obj); +extern int DohIsSequence(const DOH *obj); +extern int DohIsString(const DOH *obj); +extern int DohIsFile(const DOH *obj); -extern void DohSetmark(DOH *obj, int x); -extern int DohGetmark(DOH *obj); +extern void DohSetmark(DOH *obj, int x); +extern int DohGetmark(DOH *obj); /* ----------------------------------------------------------------------------- * Strings. * ----------------------------------------------------------------------------- */ -extern DOHString *DohNewStringEmpty(); -extern DOHString *DohNewString(const DOH *c); -extern DOHString *DohNewStringWithSize(const DOH *c, int len); -extern DOHString *DohNewStringf(const DOH *fmt, ...); +extern DOHString *DohNewStringEmpty(); +extern DOHString *DohNewString(const DOH *c); +extern DOHString *DohNewStringWithSize(const DOH *c, int len); +extern DOHString *DohNewStringf(const DOH *fmt, ...); -extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2); -extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n); +extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2); +extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n); extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2); extern char *DohStrchr(const DOHString_or_char *s1, int ch); @@ -329,36 +329,36 @@ extern char *DohStrchr(const DOHString_or_char *s1, int ch); extern DOHFile *DohNewFile(DOH *file, const char *mode); extern DOHFile *DohNewFileFromFile(FILE *f); extern DOHFile *DohNewFileFromFd(int fd); -extern void DohFileErrorDisplay(DOHString *filename); -extern int DohClose(DOH *file); -extern int DohCopyto(DOHFile *input, DOHFile *output); +extern void DohFileErrorDisplay(DOHString * filename); +extern int DohClose(DOH *file); +extern int DohCopyto(DOHFile * input, DOHFile * output); /* ----------------------------------------------------------------------------- * List * ----------------------------------------------------------------------------- */ -extern DOHList *DohNewList(); -extern void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *)); +extern DOHList *DohNewList(); +extern void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)); /* ----------------------------------------------------------------------------- * Hash * ----------------------------------------------------------------------------- */ -extern DOHHash *DohNewHash(); -extern DOH *DohHashGetAttr(DOH *hash, const DOH *key); -extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value); +extern DOHHash *DohNewHash(); +extern DOH *DohHashGetAttr(DOH *hash, const DOH *key); +extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value); /* ----------------------------------------------------------------------------- * Void * ----------------------------------------------------------------------------- */ -extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *)); -extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits); -extern DOHList *DohSplitLines(DOHFile *input); -extern DOH *DohNone; +extern DOHVoid *DohNewVoid(void *ptr, void (*del) (void *)); +extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits); +extern DOHList *DohSplitLines(DOHFile * input); +extern DOH *DohNone; -extern void DohMemoryDebug(void); +extern void DohMemoryDebug(void); #ifndef DOH_LONG_NAMES /* Macros to invoke the above functions. Includes the location of @@ -468,8 +468,4 @@ extern void DohMemoryDebug(void); #define NIL (char *) NULL -#endif /* DOH_H */ - - - - +#endif /* DOH_H */ diff --git a/SWIG/Source/DOH/dohint.h b/SWIG/Source/DOH/dohint.h index 609491615..9c217e067 100644 --- a/SWIG/Source/DOH/dohint.h +++ b/SWIG/Source/DOH/dohint.h @@ -26,37 +26,37 @@ /* Hash objects */ typedef struct { - DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */ - int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */ - int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */ - DOH *(*doh_keys)(DOH *obj); /* All keys as a list */ + DOH *(*doh_getattr) (DOH *obj, DOH *name); /* Get attribute */ + int (*doh_setattr) (DOH *obj, DOH *name, DOH *value); /* Set attribute */ + int (*doh_delattr) (DOH *obj, DOH *name); /* Del attribute */ + DOH *(*doh_keys) (DOH *obj); /* All keys as a list */ } DohHashMethods; /* List objects */ typedef struct { - DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */ - int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */ - int (*doh_delitem)(DOH *obj, int index); /* Delete item */ - int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */ - int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */ + DOH *(*doh_getitem) (DOH *obj, int index); /* Get item */ + int (*doh_setitem) (DOH *obj, int index, DOH *value); /* Set item */ + int (*doh_delitem) (DOH *obj, int index); /* Delete item */ + int (*doh_insitem) (DOH *obj, int index, DOH *value); /* Insert item */ + int (*doh_delslice) (DOH *obj, int sindex, int eindex); /* Delete slice */ } DohListMethods; /* File methods */ typedef struct { - int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */ - int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */ - int (*doh_putc)(DOH *obj, int ch); /* Put character */ - int (*doh_getc)(DOH *obj); /* Get character */ - int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */ - int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */ - long (*doh_tell)(DOH *obj); /* Tell */ - int (*doh_close)(DOH *obj); /* Close */ + int (*doh_read) (DOH *obj, void *buffer, int nbytes); /* Read bytes */ + int (*doh_write) (DOH *obj, void *buffer, int nbytes); /* Write bytes */ + int (*doh_putc) (DOH *obj, int ch); /* Put character */ + int (*doh_getc) (DOH *obj); /* Get character */ + int (*doh_ungetc) (DOH *obj, int ch); /* Unget character */ + int (*doh_seek) (DOH *obj, long offset, int whence); /* Seek */ + long (*doh_tell) (DOH *obj); /* Tell */ + int (*doh_close) (DOH *obj); /* Close */ } DohFileMethods; /* String methods */ typedef struct { - int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags); - void (*doh_chop)(DOH *obj); + int (*doh_replace) (DOH *obj, DOH *old, DOH *rep, int flags); + void (*doh_chop) (DOH *obj); } DohStringMethods; /* ----------------------------------------------------------------------------- @@ -64,55 +64,55 @@ typedef struct { * ----------------------------------------------------------------------------- */ typedef struct DohObjInfo { - char *objname; /* Object name */ + char *objname; /* Object name */ /* Basic object methods */ - void (*doh_del)(DOH *obj); /* Delete object */ - DOH *(*doh_copy)(DOH *obj); /* Copy and object */ - void (*doh_clear)(DOH *obj); /* Clear an object */ + void (*doh_del) (DOH *obj); /* Delete object */ + DOH *(*doh_copy) (DOH *obj); /* Copy and object */ + void (*doh_clear) (DOH *obj); /* Clear an object */ /* I/O methods */ - DOH *(*doh_str)(DOH *obj); /* Make a full string */ - void *(*doh_data)(DOH *obj); /* Return raw data */ - int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */ + DOH *(*doh_str) (DOH *obj); /* Make a full string */ + void *(*doh_data) (DOH *obj); /* Return raw data */ + int (*doh_dump) (DOH *obj, DOH *out); /* Serialize on out */ /* Length and hash values */ - int (*doh_len)(DOH *obj); - int (*doh_hashval)(DOH *obj); + int (*doh_len) (DOH *obj); + int (*doh_hashval) (DOH *obj); /* Compare */ - int (*doh_cmp)(DOH *obj1, DOH *obj2); + int (*doh_cmp) (DOH *obj1, DOH *obj2); /* Equal */ - int (*doh_equal)(DOH *obj1, DOH *obj2); + int (*doh_equal) (DOH *obj1, DOH *obj2); /* Iterators */ - DohIterator (*doh_first)(DOH *obj); - DohIterator (*doh_next)(DohIterator ); + DohIterator (*doh_first) (DOH *obj); + DohIterator (*doh_next) (DohIterator); /* Positional */ - void (*doh_setfile)(DOH *obj, DOHString_or_char *file); - DOH *(*doh_getfile)(DOH *obj); - void (*doh_setline)(DOH *obj, int line); - int (*doh_getline)(DOH *obj); + void (*doh_setfile) (DOH *obj, DOHString_or_char *file); + DOH *(*doh_getfile) (DOH *obj); + void (*doh_setline) (DOH *obj, int line); + int (*doh_getline) (DOH *obj); - DohHashMethods *doh_hash; /* Hash methods */ - DohListMethods *doh_list; /* List methods */ - DohFileMethods *doh_file; /* File methods */ - DohStringMethods *doh_string; /* String methods */ - void *doh_reserved; /* Reserved */ - void *clientdata; /* User data */ + DohHashMethods *doh_hash; /* Hash methods */ + DohListMethods *doh_list; /* List methods */ + DohFileMethods *doh_file; /* File methods */ + DohStringMethods *doh_string; /* String methods */ + void *doh_reserved; /* Reserved */ + void *clientdata; /* User data */ } DohObjInfo; typedef struct { - void *data; /* Data pointer */ - DohObjInfo *type; - void *meta; /* Meta data */ - unsigned int flag_intern : 1; /* Interned object */ - unsigned int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */ - unsigned int flag_user : 1; /* User flag */ - unsigned int flag_usermark : 1; /* User marked */ - unsigned int refcount : 28; /* Reference count (max 16 million) */ + void *data; /* Data pointer */ + DohObjInfo *type; + void *meta; /* Meta data */ + unsigned int flag_intern:1; /* Interned object */ + unsigned int flag_marked:1; /* Mark flag. Used to avoid recursive loops in places */ + unsigned int flag_user:1; /* User flag */ + unsigned int flag_usermark:1; /* User marked */ + unsigned int refcount:28; /* Reference count (max 16 million) */ } DohBase; /* Macros for decrefing and increfing (safe for null objects). */ @@ -127,12 +127,7 @@ typedef struct { #define ObjGetMark(a) ((DohBase *)a)->flag_marked #define ObjType(a) ((DohBase *)a)->type -extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */ -extern void DohObjFree(DOH *ptr); /* Free a DOH object */ - -#endif /* DOHINT_H */ - - - - +extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */ +extern void DohObjFree(DOH *ptr); /* Free a DOH object */ +#endif /* DOHINT_H */ diff --git a/SWIG/Source/DOH/file.c b/SWIG/Source/DOH/file.c index 44c72191e..bdd7a7e4c 100644 --- a/SWIG/Source/DOH/file.c +++ b/SWIG/Source/DOH/file.c @@ -20,17 +20,16 @@ char cvsroot_file_c[] = "$Header$"; #include typedef struct { - FILE *filep; - int fd; - int closeondel; + FILE *filep; + int fd; + int closeondel; } DohFile; /* ----------------------------------------------------------------------------- * DelFile() * ----------------------------------------------------------------------------- */ -static void -DelFile(DOH *fo) { +static void DelFile(DOH *fo) { DohFile *f = (DohFile *) ObjData(fo); if (f->closeondel) { if (f->filep) { @@ -49,15 +48,14 @@ DelFile(DOH *fo) { * File_read() * ----------------------------------------------------------------------------- */ -static int -File_read(DOH *fo, void *buffer, int len) { +static int File_read(DOH *fo, void *buffer, int len) { DohFile *f = (DohFile *) ObjData(fo); - + if (f->filep) { - return fread(buffer,1,len,f->filep); + return fread(buffer, 1, len, f->filep); } else if (f->fd) { #ifdef DOH_INTFILE - return read(f->fd,buffer,len); + return read(f->fd, buffer, len); #endif } return -1; @@ -67,16 +65,15 @@ File_read(DOH *fo, void *buffer, int len) { * File_write() * ----------------------------------------------------------------------------- */ -static int -File_write(DOH *fo, void *buffer, int len) { +static int File_write(DOH *fo, void *buffer, int len) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { int ret = (int) fwrite(buffer, 1, len, f->filep); int err = (ret != len) ? ferror(f->filep) : 0; - return err ? -1: ret; + return err ? -1 : ret; } else if (f->fd) { #ifdef DOH_INTFILE - return write(f->fd,buffer,len); + return write(f->fd, buffer, len); #endif } return -1; @@ -86,11 +83,10 @@ File_write(DOH *fo, void *buffer, int len) { * File_seek() * ----------------------------------------------------------------------------- */ -static int -File_seek(DOH *fo, long offset, int whence) { +static int File_seek(DOH *fo, long offset, int whence) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { - return fseek(f->filep,offset,whence); + return fseek(f->filep, offset, whence); } else if (f->fd) { #ifdef DOH_INTFILE return lseek(f->fd, offset, whence); @@ -103,8 +99,7 @@ File_seek(DOH *fo, long offset, int whence) { * File_tell() * ----------------------------------------------------------------------------- */ -static long -File_tell(DOH *fo) { +static long File_tell(DOH *fo) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { return ftell(f->filep); @@ -120,16 +115,15 @@ File_tell(DOH *fo) { * File_putc() * ----------------------------------------------------------------------------- */ -static int -File_putc(DOH *fo, int ch) { +static int File_putc(DOH *fo, int ch) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { - return fputc(ch,f->filep); + return fputc(ch, f->filep); } else if (f->fd) { #ifdef DOH_INTFILE char c; c = (char) ch; - return write(f->fd,&c,1); + return write(f->fd, &c, 1); #endif } return -1; @@ -139,15 +133,15 @@ File_putc(DOH *fo, int ch) { * File_getc() * ----------------------------------------------------------------------------- */ -static int -File_getc(DOH *fo) { +static int File_getc(DOH *fo) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { return fgetc(f->filep); } else if (f->fd) { #ifdef DOH_INTFILE char c; - if (read(f->fd,&c,1) < 0) return EOF; + if (read(f->fd, &c, 1) < 0) + return EOF; return c; #endif } @@ -160,8 +154,7 @@ File_getc(DOH *fo) { * Put a character back onto the input * ----------------------------------------------------------------------------- */ -static int -File_ungetc(DOH *fo, int ch) { +static int File_ungetc(DOH *fo, int ch) { DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { return ungetc(ch, f->filep); @@ -179,8 +172,7 @@ File_ungetc(DOH *fo, int ch) { * Close the file * ----------------------------------------------------------------------------- */ -static int -File_close(DOH *fo) { +static int File_close(DOH *fo) { int ret = 0; DohFile *f = (DohFile *) ObjData(fo); if (f->filep) { @@ -196,40 +188,40 @@ File_close(DOH *fo) { } static DohFileMethods FileFileMethods = { - File_read, + File_read, File_write, File_putc, File_getc, File_ungetc, File_seek, File_tell, - File_close, /* close */ + File_close, /* close */ }; static DohObjInfo DohFileType = { - "DohFile", /* objname */ - DelFile, /* doh_del */ - 0, /* doh_copy */ - 0, /* doh_clear */ - 0, /* doh_str */ - 0, /* doh_data */ - 0, /* doh_dump */ - 0, /* doh_len */ - 0, /* doh_hash */ - 0, /* doh_cmp */ - 0, /* doh_equal */ - 0, /* doh_first */ - 0, /* doh_next */ - 0, /* doh_setfile */ - 0, /* doh_getfile */ - 0, /* doh_setline */ - 0, /* doh_getline */ - 0, /* doh_mapping */ - 0, /* doh_sequence */ - &FileFileMethods,/* doh_file */ - 0, /* doh_string */ - 0, /* doh_callable */ - 0, /* doh_position */ + "DohFile", /* objname */ + DelFile, /* doh_del */ + 0, /* doh_copy */ + 0, /* doh_clear */ + 0, /* doh_str */ + 0, /* doh_data */ + 0, /* doh_dump */ + 0, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_equal */ + 0, /* doh_first */ + 0, /* doh_next */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ + 0, /* doh_mapping */ + 0, /* doh_sequence */ + &FileFileMethods, /* doh_file */ + 0, /* doh_string */ + 0, /* doh_callable */ + 0, /* doh_position */ }; /* ----------------------------------------------------------------------------- @@ -238,16 +230,15 @@ static DohObjInfo DohFileType = { * Create a new file from a given filename and mode. * ----------------------------------------------------------------------------- */ -DOH * -DohNewFile(DOH *fn, const char *mode) -{ +DOH *DohNewFile(DOH *fn, const char *mode) { DohFile *f; FILE *file; char *filename; filename = Char(fn); - file = fopen(filename,mode); - if (!file) return 0; + file = fopen(filename, mode); + if (!file) + return 0; f = (DohFile *) DohMalloc(sizeof(DohFile)); if (!f) { @@ -257,7 +248,7 @@ DohNewFile(DOH *fn, const char *mode) f->filep = file; f->fd = 0; f->closeondel = 1; - return DohObjMalloc(&DohFileType,f); + return DohObjMalloc(&DohFileType, f); } /* ----------------------------------------------------------------------------- @@ -266,16 +257,15 @@ DohNewFile(DOH *fn, const char *mode) * Create a file object from an already open FILE *. * ----------------------------------------------------------------------------- */ -DOH * -DohNewFileFromFile(FILE *file) -{ +DOH *DohNewFileFromFile(FILE *file) { DohFile *f; f = (DohFile *) DohMalloc(sizeof(DohFile)); - if (!f) return 0; + if (!f) + return 0; f->filep = file; f->fd = 0; f->closeondel = 0; - return DohObjMalloc(&DohFileType,f); + return DohObjMalloc(&DohFileType, f); } /* ----------------------------------------------------------------------------- @@ -284,16 +274,15 @@ DohNewFileFromFile(FILE *file) * Create a file object from an already open FILE *. * ----------------------------------------------------------------------------- */ -DOH * -DohNewFileFromFd(int fd) -{ +DOH *DohNewFileFromFd(int fd) { DohFile *f; f = (DohFile *) DohMalloc(sizeof(DohFile)); - if (!f) return 0; + if (!f) + return 0; f->filep = 0; f->fd = fd; f->closeondel = 0; - return DohObjMalloc(&DohFileType,f); + return DohObjMalloc(&DohFileType, f); } /* ----------------------------------------------------------------------------- @@ -302,9 +291,6 @@ DohNewFileFromFd(int fd) * Display cause of one of the NewFile functions failing. * ----------------------------------------------------------------------------- */ -void -DohFileErrorDisplay(DOHString *filename) -{ +void DohFileErrorDisplay(DOHString * filename) { Printf(stderr, "Unable to open file %s: %s\n", filename, strerror(errno)); } - diff --git a/SWIG/Source/DOH/fio.c b/SWIG/Source/DOH/fio.c index e8fc025bb..abc05bf1f 100644 --- a/SWIG/Source/DOH/fio.c +++ b/SWIG/Source/DOH/fio.c @@ -16,7 +16,7 @@ char cvsroot_fio_c[] = "$Header$"; #define OBUFLEN 512 -static DOH *encodings = 0; /* Encoding hash */ +static DOH *encodings = 0; /* Encoding hash */ /* ----------------------------------------------------------------------------- * Writen() @@ -29,8 +29,9 @@ static int Writen(DOH *out, void *buffer, int len) { int nw = len, ret; char *cb = (char *) buffer; while (nw) { - ret = Write(out,cb,nw); - if (ret < 0) return -1; + ret = Write(out, cb, nw); + if (ret < 0) + return -1; nw = nw - ret; cb += ret; } @@ -44,36 +45,38 @@ static int Writen(DOH *out, void *buffer, int len) { * two file-like objects and operate as a filter. * ----------------------------------------------------------------------------- */ -void -DohEncoding(char *name, DOH *(*fn)(DOH *s)) { - if (!encodings) encodings = NewHash(); - Setattr(encodings,(void *) name, NewVoid((void *)fn,0)); +void DohEncoding(char *name, DOH *(*fn) (DOH *s)) { + if (!encodings) + encodings = NewHash(); + Setattr(encodings, (void *) name, NewVoid((void *) fn, 0)); } /* internal function for processing an encoding */ -static DOH *encode(char *name, DOH *s) { +static DOH *encode(char *name, DOH *s) { DOH *handle, *ns; - DOH *(*fn)(DOH *); - long pos; - char *cfmt = strchr(name,':'); - DOH *tmp = 0; + 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)); + Append(tmp, s); + Setfile(tmp, Getfile((DOH *) s)); + Setline(tmp, Getline((DOH *) s)); *cfmt = '\0'; } - if (!encodings || !(handle = Getattr(encodings,name))) { + if (!encodings || !(handle = Getattr(encodings, name))) { return Copy(s); } - if (tmp) s = tmp; + if (tmp) + s = tmp; pos = Tell(s); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); fn = (DOH *(*)(DOH *)) Data(handle); - ns = (*fn)(s); - Seek(s,pos,SEEK_SET); - if (tmp) Delete(tmp); + ns = (*fn) (s); + Seek(s, pos, SEEK_SET); + if (tmp) + Delete(tmp); return ns; } @@ -95,37 +98,35 @@ static DOH *encode(char *name, DOH *s) { * It's better to use Dump() or some other method instead. * ----------------------------------------------------------------------------- */ -int -DohvPrintf(DOH *so, const char *format, va_list ap) -{ +int DohvPrintf(DOH *so, const char *format, va_list ap) { static char *fmt_codes = "dioxXucsSfeEgGpn"; int state = 0; const char *p = format; - char newformat[256]; - char obuffer[OBUFLEN]; + char newformat[256]; + char obuffer[OBUFLEN]; char *fmt = 0; - char temp[64]; - int widthval = 0; - int precval = 0; - int maxwidth; - char *w = 0; - int ivalue; + char temp[64]; + int widthval = 0; + int precval = 0; + int maxwidth; + char *w = 0; + int ivalue; double dvalue; - void *pvalue; - char *stemp; - int nbytes = 0; - char encoder[128], *ec = 0; - int plevel = 0; + void *pvalue; + char *stemp; + int nbytes = 0; + char encoder[128], *ec = 0; + int plevel = 0; - memset (newformat, 0, sizeof (newformat)); + memset(newformat, 0, sizeof(newformat)); while (*p) { - switch(state) { - case 0: /* Ordinary text */ + switch (state) { + case 0: /* Ordinary text */ if (*p != '%') { - Putc(*p,so); + Putc(*p, so); nbytes++; - } else{ + } else { fmt = newformat; widthval = 0; precval = 0; @@ -134,26 +135,26 @@ DohvPrintf(DOH *so, const char *format, va_list ap) state = 10; } break; - case 10: /* Look for a width and precision */ - if (isdigit((int)*p) && (*p != '0')) { + case 10: /* Look for a width and precision */ + if (isdigit((int) *p) && (*p != '0')) { w = temp; *(w++) = *p; *(fmt++) = *p; state = 20; - } else if (strchr(fmt_codes,*p)) { + } else if (strchr(fmt_codes, *p)) { /* Got one of the formatting codes */ p--; state = 100; } else if (*p == '*') { /* Width field is specified in the format list */ - widthval = va_arg(ap,int); - sprintf(temp,"%d",widthval); + widthval = va_arg(ap, int); + sprintf(temp, "%d", widthval); for (w = temp; *w; w++) { *(fmt++) = *w; } state = 30; } else if (*p == '%') { - Putc(*p,so); + Putc(*p, so); fmt = newformat; nbytes++; state = 0; @@ -165,12 +166,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap) *(fmt++) = *p; } break; - - case 20: /* Hmmm. At the start of a width field */ - if (isdigit((int)*p)) { + + case 20: /* Hmmm. At the start of a width field */ + if (isdigit((int) *p)) { *(w++) = *p; *(fmt++) = *p; - } else if (strchr(fmt_codes,*p)) { + } else if (strchr(fmt_codes, *p)) { /* Got one of the formatting codes */ /* Figure out width */ *w = 0; @@ -191,12 +192,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap) } break; - case 30: /* Parsed a width from an argument. Look for a . */ + case 30: /* Parsed a width from an argument. Look for a . */ if (*p == '.') { w = temp; *(fmt++) = *p; state = 40; - } else if (strchr(fmt_codes,*p)) { + } else if (strchr(fmt_codes, *p)) { /* Got one of the formatting codes */ /* Figure out width */ p--; @@ -209,19 +210,19 @@ DohvPrintf(DOH *so, const char *format, va_list ap) case 40: /* Start of precision expected */ - if (isdigit((int)*p) && (*p != '0')) { + if (isdigit((int) *p) && (*p != '0')) { *(fmt++) = *p; *(w++) = *p; state = 41; } else if (*p == '*') { /* Precision field is specified in the format list */ - precval = va_arg(ap,int); - sprintf(temp,"%d",precval); + precval = va_arg(ap, int); + sprintf(temp, "%d", precval); for (w = temp; *w; w++) { *(fmt++) = *w; } state = 50; - } else if (strchr(fmt_codes,*p)) { + } else if (strchr(fmt_codes, *p)) { p--; state = 100; } else { @@ -230,10 +231,10 @@ DohvPrintf(DOH *so, const char *format, va_list ap) } break; case 41: - if (isdigit((int)*p)) { + if (isdigit((int) *p)) { *(fmt++) = *p; *(w++) = *p; - } else if (strchr(fmt_codes,*p)) { + } else if (strchr(fmt_codes, *p)) { /* Got one of the formatting codes */ /* Figure out width */ *w = 0; @@ -249,7 +250,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap) break; /* Hang out, wait for format specifier */ case 50: - if (strchr(fmt_codes,*p)) { + if (strchr(fmt_codes, *p)) { p--; state = 100; } else { @@ -279,43 +280,47 @@ DohvPrintf(DOH *so, const char *format, va_list ap) break; case 100: /* Got a formatting code */ - if (widthval < precval) maxwidth = precval; - else maxwidth = widthval; - if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */ - DOH *doh; - DOH *Sval; - DOH *enc = 0; + if (widthval < precval) + maxwidth = precval; + else + maxwidth = widthval; + if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */ + DOH *doh; + DOH *Sval; + DOH *enc = 0; doh = va_arg(ap, DOH *); if (DohCheck(doh)) { /* Is a DOH object. */ - if (DohIsString(doh)) { + if (DohIsString(doh)) { Sval = doh; } else { Sval = Str(doh); } if (strlen(encoder)) { - enc = encode(encoder,Sval); - maxwidth = maxwidth+strlen(newformat)+Len(enc); + enc = encode(encoder, Sval); + maxwidth = maxwidth + strlen(newformat) + Len(enc); } else { - maxwidth = maxwidth+strlen(newformat)+Len(Sval); + maxwidth = maxwidth + strlen(newformat) + Len(Sval); } *(fmt++) = 's'; *fmt = 0; if ((maxwidth + 1) < OBUFLEN) { stemp = obuffer; } else { - stemp = (char *) DohMalloc(maxwidth+1); + stemp = (char *) DohMalloc(maxwidth + 1); } if (enc) { - nbytes+=sprintf(stemp,newformat,Data(enc)); + nbytes += sprintf(stemp, newformat, Data(enc)); } else { - nbytes+=sprintf(stemp,newformat,Data(Sval)); + nbytes += sprintf(stemp, newformat, Data(Sval)); } - if (Writen(so,stemp,strlen(stemp)) < 0) return -1; + if (Writen(so, stemp, strlen(stemp)) < 0) + return -1; if ((DOH *) Sval != doh) { Delete(Sval); } - if (enc) Delete(enc); + if (enc) + Delete(enc); if (*p == 'S') { Delete(doh); } @@ -323,45 +328,48 @@ DohvPrintf(DOH *so, const char *format, va_list ap) DohFree(stemp); } } else { - if (!doh) doh = (char *)""; - + if (!doh) + doh = (char *) ""; + if (strlen(encoder)) { DOH *s = NewString(doh); - Seek(s,0, SEEK_SET); - enc = encode(encoder,s); + Seek(s, 0, SEEK_SET); + enc = encode(encoder, s); Delete(s); doh = Char(enc); } else { enc = 0; } - maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh); + maxwidth = maxwidth + strlen(newformat) + strlen((char *) doh); *(fmt++) = 's'; *fmt = 0; - if ((maxwidth+1) < OBUFLEN) { + if ((maxwidth + 1) < OBUFLEN) { stemp = obuffer; } else { stemp = (char *) DohMalloc(maxwidth + 1); } - nbytes+=sprintf(stemp,newformat,doh); - if (Writen(so,stemp,strlen(stemp)) < 0) return -1; + nbytes += sprintf(stemp, newformat, doh); + if (Writen(so, stemp, strlen(stemp)) < 0) + return -1; if (stemp != obuffer) { DohFree(stemp); } - if (enc) Delete(enc); + if (enc) + Delete(enc); } } else { *(fmt++) = *p; *fmt = 0; - maxwidth = maxwidth+strlen(newformat)+64; - + maxwidth = maxwidth + strlen(newformat) + 64; + /* Only allocate a buffer if it is too big to fit. Shouldn't have to do - this very often */ + this very often */ if (maxwidth < OBUFLEN) stemp = obuffer; - else - stemp = (char *) DohMalloc(maxwidth+1); - switch(*p) { + else + stemp = (char *) DohMalloc(maxwidth + 1); + switch (*p) { case 'd': case 'i': case 'o': @@ -369,26 +377,28 @@ DohvPrintf(DOH *so, const char *format, va_list ap) case 'x': case 'X': case 'c': - ivalue = va_arg(ap,int); - nbytes+=sprintf(stemp,newformat,ivalue); + ivalue = va_arg(ap, int); + nbytes += sprintf(stemp, newformat, ivalue); break; case 'f': case 'g': case 'e': case 'E': case 'G': - dvalue = va_arg(ap,double); - nbytes+=sprintf(stemp,newformat,dvalue); + dvalue = va_arg(ap, double); + nbytes += sprintf(stemp, newformat, dvalue); break; case 'p': - pvalue = va_arg(ap,void *); - nbytes+=sprintf(stemp,newformat,pvalue); + pvalue = va_arg(ap, void *); + nbytes += sprintf(stemp, newformat, pvalue); break; default: break; } - if (Writen(so,stemp,strlen(stemp)) < 0) return -1; - if (stemp != obuffer) DohFree(stemp); + if (Writen(so, stemp, strlen(stemp)) < 0) + return -1; + if (stemp != obuffer) + DohFree(stemp); } state = 0; break; @@ -398,8 +408,9 @@ DohvPrintf(DOH *so, const char *format, va_list ap) if (state) { int r; *fmt = 0; - r = Writen(so,fmt,strlen(fmt)); - if (r < 0) return -1; + r = Writen(so, fmt, strlen(fmt)); + if (r < 0) + return -1; nbytes += r; } return nbytes; @@ -411,12 +422,11 @@ DohvPrintf(DOH *so, const char *format, va_list ap) * Variable length argument entry point to Printf * ----------------------------------------------------------------------------- */ -int -DohPrintf(DOH *obj, const char *format, ...) { +int DohPrintf(DOH *obj, const char *format, ...) { va_list ap; int ret; - va_start(ap,format); - ret = DohvPrintf(obj,format,ap); + va_start(ap, format); + ret = DohvPrintf(obj, format, ap); va_end(ap); return ret; } @@ -427,18 +437,19 @@ DohPrintf(DOH *obj, const char *format, ...) { * Print a null-terminated variable length list of DOH objects * ----------------------------------------------------------------------------- */ -int DohPrintv(DOHFile *f, ...) { +int DohPrintv(DOHFile * f, ...) { va_list ap; int ret = 0; DOH *obj; - va_start(ap,f); - while(1) { - obj = va_arg(ap,void *); - if ((!obj) || (obj == DohNone)) break; + va_start(ap, f); + while (1) { + obj = va_arg(ap, void *); + if ((!obj) || (obj == DohNone)) + break; if (DohCheck(obj)) { - ret += DohDump(obj,f); + ret += DohDump(obj, f); } else { - ret += DohWrite(f,obj,strlen((char *) obj)); + ret += DohWrite(f, obj, strlen((char *) obj)); } } va_end(ap); @@ -452,22 +463,23 @@ int DohPrintv(DOHFile *f, ...) { * number of bytes copied. * ----------------------------------------------------------------------------- */ -int -DohCopyto(DOH *in, DOH *out) { +int DohCopyto(DOH *in, DOH *out) { int nbytes = 0, ret; int nwrite = 0, wret; char *cw; char buffer[16384]; - if ((!in) || (!out)) return 0; + if ((!in) || (!out)) + return 0; while (1) { - ret = Read(in,buffer,16384); + ret = Read(in, buffer, 16384); if (ret > 0) { nwrite = ret; cw = buffer; while (nwrite) { - wret = Write(out,cw,nwrite); - if (wret < 0) return -1; + wret = Write(out, cw, nwrite); + if (wret < 0) + return -1; nwrite = nwrite - wret; cw += wret; } @@ -486,16 +498,15 @@ DohCopyto(DOH *in, DOH *out) { * character. Optionally accepts a maximum number of splits to perform. * ----------------------------------------------------------------------------- */ -DOH * -DohSplit(DOH *in, char ch, int nsplits) { +DOH *DohSplit(DOH *in, char ch, int nsplits) { DOH *list; DOH *str; int c; - + list = NewList(); if (DohIsString(in)) { - Seek(in,0,SEEK_SET); + Seek(in, 0, SEEK_SET); } while (1) { @@ -504,17 +515,19 @@ DohSplit(DOH *in, char ch, int nsplits) { c = Getc(in); } while ((c != EOF) && (c == ch)); if (c != EOF) { - Putc(c,str); + Putc(c, str); while (1) { c = Getc(in); - if ((c == EOF) || ((c == ch) && (nsplits != 0))) break; - Putc(c,str); + if ((c == EOF) || ((c == ch) && (nsplits != 0))) + break; + Putc(c, str); } nsplits--; } - Append(list,str); + Append(list, str); Delete(str); - if (c == EOF) break; + if (c == EOF) + break; } return list; } @@ -525,16 +538,15 @@ DohSplit(DOH *in, char ch, int nsplits) { * Split an input stream into a list of strings delimited by newline characters. * ----------------------------------------------------------------------------- */ -DOH * -DohSplitLines(DOH *in) { +DOH *DohSplitLines(DOH *in) { DOH *list; DOH *str; - int c = 0; + int c = 0; list = NewList(); if (DohIsString(in)) { - Seek(in,0,SEEK_SET); + Seek(in, 0, SEEK_SET); } while (c != EOF) { @@ -542,7 +554,7 @@ DohSplitLines(DOH *in) { while ((c = Getc(in)) != '\n' && c != EOF) { Putc(c, str); } - Append(list,str); + Append(list, str); Delete(str); } return list; @@ -555,24 +567,23 @@ DohSplitLines(DOH *in) { * Read a single input line and return it as a string. * ----------------------------------------------------------------------------- */ -DOH * -DohReadline(DOH *in) { +DOH *DohReadline(DOH *in) { char c; int n = 0; DOH *s = NewStringEmpty(); while (1) { - if (Read(in,&c,1) < 0) { + if (Read(in, &c, 1) < 0) { if (n == 0) { Delete(s); return 0; } return s; } - if (c == '\n') return s; - if (c == '\r') continue; - Putc(c,s); + if (c == '\n') + return s; + if (c == '\r') + continue; + Putc(c, s); n++; } } - - diff --git a/SWIG/Source/DOH/hash.c b/SWIG/Source/DOH/hash.c index 03df97646..0c1a8f37a 100644 --- a/SWIG/Source/DOH/hash.c +++ b/SWIG/Source/DOH/hash.c @@ -17,59 +17,65 @@ extern DohObjInfo DohHashType; /* Hash node */ typedef struct HashNode { - DOH *key; - DOH *object; - struct HashNode *next; + DOH *key; + DOH *object; + struct HashNode *next; } HashNode; /* Hash object */ typedef struct Hash { - DOH *file; - int line; - HashNode **hashtable; - int hashsize; - int nitems; + DOH *file; + int line; + HashNode **hashtable; + int hashsize; + int nitems; } Hash; /* Key interning structure */ typedef struct KeyValue { - char *cstr; - DOH *sstr; - struct KeyValue *left; - struct KeyValue *right; + char *cstr; + DOH *sstr; + struct KeyValue *left; + struct KeyValue *right; } KeyValue; static KeyValue *root = 0; /* Find or create a key in the interned key table */ -static DOH *find_key (DOH *doh_c) { +static DOH *find_key(DOH *doh_c) { char *c = (char *) doh_c; KeyValue *r, *s; int d = 0; /* OK, sure, we use a binary tree for maintaining interned symbols. Then we use their hash values for accessing secondary - hash tables. */ + hash tables. */ r = root; s = 0; while (r) { s = r; - d = strcmp(r->cstr,c); - if (d == 0) return r->sstr; - if (d < 0) r = r->left; - else r = r->right; + d = strcmp(r->cstr, c); + if (d == 0) + return r->sstr; + if (d < 0) + r = r->left; + else + r = r->right; } - /* fprintf(stderr,"Interning '%s'\n", c);*/ + /* fprintf(stderr,"Interning '%s'\n", c); */ r = (KeyValue *) DohMalloc(sizeof(KeyValue)); - r->cstr = (char *) DohMalloc(strlen(c)+1); - strcpy(r->cstr,c); + r->cstr = (char *) DohMalloc(strlen(c) + 1); + strcpy(r->cstr, c); r->sstr = NewString(c); DohIntern(r->sstr); r->left = 0; r->right = 0; - if (!s) { root = r; } - else { - if (d < 0) s->left = r; - else s->right = r; + if (!s) { + root = r; + } else { + if (d < 0) + s->left = r; + else + s->right = r; } return r->sstr; } @@ -78,20 +84,20 @@ static DOH *find_key (DOH *doh_c) { /* Create a new hash node */ static HashNode *NewNode(DOH *k, void *obj) { - HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode)); - hn->key = k; - Incref(hn->key); - hn->object = obj; - Incref(obj); - hn->next = 0; - return hn; + HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode)); + hn->key = k; + Incref(hn->key); + hn->object = obj; + Incref(obj); + hn->next = 0; + return hn; } /* Delete a hash node */ static void DelNode(HashNode *hn) { - Delete(hn->key); - Delete(hn->object); - DohFree(hn); + Delete(hn->key); + Delete(hn->object); + DohFree(hn); } /* ----------------------------------------------------------------------------- @@ -100,25 +106,24 @@ static void DelNode(HashNode *hn) { * Delete a hash table. * ----------------------------------------------------------------------------- */ -static void -DelHash(DOH *ho) { - Hash *h = (Hash *) ObjData(ho); - HashNode *n,*next; - int i; +static void DelHash(DOH *ho) { + Hash *h = (Hash *) ObjData(ho); + HashNode *n, *next; + int i; - for (i = 0; i < h->hashsize; i++) { - if ((n = h->hashtable[i])) { - while (n) { - next = n->next; - DelNode(n); - n = next; - } - } + for (i = 0; i < h->hashsize; i++) { + if ((n = h->hashtable[i])) { + while (n) { + next = n->next; + DelNode(n); + n = next; + } } - DohFree(h->hashtable); - h->hashtable = 0; - h->hashsize = 0; - DohFree(h); + } + DohFree(h->hashtable); + h->hashtable = 0; + h->hashsize = 0; + DohFree(h); } /* ----------------------------------------------------------------------------- @@ -127,67 +132,67 @@ DelHash(DOH *ho) { * Clear all of the entries in the hash table. * ----------------------------------------------------------------------------- */ -static void -Hash_clear(DOH *ho) { - Hash *h = (Hash *) ObjData(ho); - HashNode *n,*next; - int i; +static void Hash_clear(DOH *ho) { + Hash *h = (Hash *) ObjData(ho); + HashNode *n, *next; + int i; - for (i = 0; i < h->hashsize; i++) { - if ((n = h->hashtable[i])) { - while (n) { - next = n->next; - DelNode(n); - n = next; - } - } - h->hashtable[i] = 0; + for (i = 0; i < h->hashsize; i++) { + if ((n = h->hashtable[i])) { + while (n) { + next = n->next; + DelNode(n); + n = next; + } } - h->nitems = 0; + h->hashtable[i] = 0; + } + h->nitems = 0; } /* resize the hash table */ static void resize(Hash *h) { - HashNode *n, *next, **table; - int oldsize, newsize; - int i, p, hv; + HashNode *n, *next, **table; + int oldsize, newsize; + int i, p, hv; - if (h->nitems < 2*h->hashsize) return; + if (h->nitems < 2 * h->hashsize) + return; - /* Too big. We have to rescale everything now */ - oldsize = h->hashsize; + /* Too big. We have to rescale everything now */ + oldsize = h->hashsize; - /* Calculate a new size */ - newsize = 2*oldsize+1; - p = 3; - while (p < (newsize >> 1)) { - if (((newsize/p)*p) == newsize) { - newsize+=2; - p = 3; - continue; - } - p = p + 2; + /* Calculate a new size */ + newsize = 2 * oldsize + 1; + p = 3; + while (p < (newsize >> 1)) { + if (((newsize / p) * p) == newsize) { + newsize += 2; + p = 3; + continue; } + p = p + 2; + } - table = (HashNode **) DohMalloc(newsize*sizeof(HashNode *)); - for (i = 0; i < newsize; i++ ) { - table[i] = 0; - } + table = (HashNode **) DohMalloc(newsize * sizeof(HashNode *)); + for (i = 0; i < newsize; i++) { + table[i] = 0; + } - /* Walk down the old set of nodes and re-place */ - h->hashsize = newsize; - for (i = 0; i < oldsize; i++) { - n = h->hashtable[i]; - while (n) { - hv = Hashval(n->key) % newsize; - next = n->next; - n->next = table[hv]; - table[hv] = n; - n = next; - } + /* Walk down the old set of nodes and re-place */ + h->hashsize = newsize; + for (i = 0; i < oldsize; i++) { + n = h->hashtable[i]; + while (n) { + hv = Hashval(n->key) % newsize; + next = n->next; + n->next = table[hv]; + table[hv] = n; + n = next; } - DohFree(h->hashtable); - h->hashtable = table; + } + DohFree(h->hashtable); + h->hashtable = table; } /* ----------------------------------------------------------------------------- @@ -197,46 +202,48 @@ static void resize(Hash *h) { * exists. * ----------------------------------------------------------------------------- */ -static int -Hash_setattr(DOH *ho, DOH *k, DOH *obj) { - int hv; - HashNode *n, *prev; - Hash *h = (Hash *) ObjData(ho); - - if (!obj) { - return DohDelattr(ho,k); - } - if (!DohCheck(k)) k = find_key(k); - if (!DohCheck(obj)) { - obj = NewString((char *) obj); - Decref(obj); - } - hv = (Hashval(k)) % h->hashsize; - n = h->hashtable[hv]; - prev = 0; - while (n) { - if (Cmp(n->key,k) == 0) { - /* Node already exists. Just replace its contents */ - if (n->object == obj) { - /* Whoa. Same object. Do nothing */ - return 1; - } - Delete(n->object); - n->object = obj; - Incref(obj); - return 1; /* Return 1 to indicate a replacement */ - } else { - prev = n; - n = n->next; +static int Hash_setattr(DOH *ho, DOH *k, DOH *obj) { + int hv; + HashNode *n, *prev; + Hash *h = (Hash *) ObjData(ho); + + if (!obj) { + return DohDelattr(ho, k); + } + if (!DohCheck(k)) + k = find_key(k); + if (!DohCheck(obj)) { + obj = NewString((char *) obj); + Decref(obj); + } + hv = (Hashval(k)) % h->hashsize; + n = h->hashtable[hv]; + prev = 0; + while (n) { + if (Cmp(n->key, k) == 0) { + /* Node already exists. Just replace its contents */ + if (n->object == obj) { + /* Whoa. Same object. Do nothing */ + return 1; } + Delete(n->object); + n->object = obj; + Incref(obj); + return 1; /* Return 1 to indicate a replacement */ + } else { + prev = n; + n = n->next; } - /* Add this to the table */ - n = NewNode(k,obj); - if (prev) prev->next = n; - else h->hashtable[hv] = n; - h->nitems++; - resize(h); - return 0; + } + /* Add this to the table */ + n = NewNode(k, obj); + if (prev) + prev->next = n; + else + h->hashtable[hv] = n; + h->nitems++; + resize(h); + return 0; } /* ----------------------------------------------------------------------------- @@ -244,7 +251,7 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) { * * Get an attribute from the hash table. Returns 0 if it doesn't exist. * ----------------------------------------------------------------------------- */ -typedef int (*binop)(DOH *obj1, DOH *obj2); +typedef int (*binop) (DOH *obj1, DOH *obj2); #define _Hash_getattr(h, k, o) \ int hv = Hashval(k) % h->hashsize; \ @@ -267,8 +274,7 @@ typedef int (*binop)(DOH *obj1, DOH *obj2); } -static DOH * -Hash_getattr(DOH *h, DOH *k) { +static DOH *Hash_getattr(DOH *h, DOH *k) { DOH *obj = 0; Hash *ho = (Hash *) ObjData(h); DOH *ko = DohCheck(k) ? k : find_key(k); @@ -276,8 +282,7 @@ Hash_getattr(DOH *h, DOH *k) { return obj; } -DOH * -DohHashGetAttr(DOH *h, const DOH *k) { +DOH *DohHashGetAttr(DOH *h, const DOH *k) { DOH *obj = 0; Hash *ho = (Hash *) ObjData(h); _Hash_getattr(ho, (DOH *) k, obj); @@ -291,14 +296,13 @@ DohHashGetAttr(DOH *h, const DOH *k) { * Check an attribute from the hash table. * ----------------------------------------------------------------------------- */ -int -DohHashCheckAttr(DOH *h, DOH *k, DOH *v) { +int DohHashCheckAttr(DOH *h, DOH *k, DOH *v) { DOH *obj = 0; Hash *ho = (Hash *) ObjData(h); _Hash_getattr(ho, k, obj); if (obj) { - DohObjInfo *o_type = ((DohBase*)obj)->type; - if (o_type == ((DohBase*)v)->type) { + DohObjInfo *o_type = ((DohBase *) obj)->type; + if (o_type == ((DohBase *) v)->type) { binop equal = o_type->doh_equal; return equal ? equal(obj, v) : (o_type->doh_cmp(obj, v) == 0); } @@ -312,44 +316,43 @@ DohHashCheckAttr(DOH *h, DOH *k, DOH *v) { * Delete an object from the hash table. * ----------------------------------------------------------------------------- */ -static int -Hash_delattr(DOH *ho, DOH *k) { - HashNode *n, *prev; - int hv; - Hash *h = (Hash *) ObjData(ho); +static int Hash_delattr(DOH *ho, DOH *k) { + HashNode *n, *prev; + int hv; + Hash *h = (Hash *) ObjData(ho); - if (!DohCheck(k)) k = find_key(k); - hv = Hashval(k) % h->hashsize; - n = h->hashtable[hv]; - prev = 0; - while (n) { - if (Cmp(n->key, k) == 0) { - /* Found it, kill it */ + if (!DohCheck(k)) + k = find_key(k); + hv = Hashval(k) % h->hashsize; + n = h->hashtable[hv]; + prev = 0; + while (n) { + if (Cmp(n->key, k) == 0) { + /* Found it, kill it */ - if (prev) { - prev->next = n->next; - } else { - h->hashtable[hv] = n->next; - } - DelNode(n); - h->nitems--; - return 1; - } - prev = n; - n = n->next; + if (prev) { + prev->next = n->next; + } else { + h->hashtable[hv] = n->next; + } + DelNode(n); + h->nitems--; + return 1; } - return 0; + prev = n; + n = n->next; + } + return 0; } -static DohIterator -Hash_firstiter(DOH *ho) { +static DohIterator Hash_firstiter(DOH *ho) { DohIterator iter; Hash *h = (Hash *) ObjData(ho); iter.object = ho; iter._current = 0; iter.item = 0; iter.key = 0; - iter._index = 0; /* Index in hash table */ + iter._index = 0; /* Index in hash table */ while ((iter._index < h->hashsize) && !h->hashtable[iter._index]) iter._index++; @@ -359,15 +362,14 @@ Hash_firstiter(DOH *ho) { iter._current = h->hashtable[iter._index]; iter.item = ((HashNode *) iter._current)->object; iter.key = ((HashNode *) iter._current)->key; - + /* Actually save the next slot in the hash. This makes it possible to delete the item being iterated over without trashing the universe */ - iter._current = ((HashNode*)iter._current)->next; + iter._current = ((HashNode *) iter._current)->next; return iter; } -static DohIterator -Hash_nextiter(DohIterator iter) { +static DohIterator Hash_nextiter(DohIterator iter) { Hash *h = (Hash *) ObjData(iter.object); if (!iter._current) { iter._index++; @@ -386,7 +388,7 @@ Hash_nextiter(DohIterator iter) { iter.item = ((HashNode *) iter._current)->object; /* Store the next node to iterator on */ - iter._current = ((HashNode*)iter._current)->next; + iter._current = ((HashNode *) iter._current)->next; return iter; } @@ -396,14 +398,13 @@ Hash_nextiter(DohIterator iter) { * Return a list of keys * ----------------------------------------------------------------------------- */ -static DOH * -Hash_keys(DOH *so) { +static DOH *Hash_keys(DOH *so) { DOH *keys; Iterator i; keys = NewList(); for (i = First(so); i.key; i = Next(i)) { - Append(keys,i.key); + Append(keys, i.key); } return keys; } @@ -414,35 +415,36 @@ Hash_keys(DOH *so) { * Create a string representation of a hash table (mainly for debugging). * ----------------------------------------------------------------------------- */ -static DOH * -Hash_str(DOH *ho) { - int i,j; - HashNode *n; - DOH *s; - static int indent = 4; - Hash *h = (Hash *) ObjData(ho); +static DOH *Hash_str(DOH *ho) { + int i, j; + HashNode *n; + DOH *s; + static int indent = 4; + Hash *h = (Hash *) ObjData(ho); - s = NewStringEmpty(); - if (ObjGetMark(ho)) { - Printf(s,"Hash(0x%x)",ho); - return s; - } - ObjSetMark(ho,1); - Printf(s,"Hash {\n"); - for (i = 0; i < h->hashsize; i++) { - n = h->hashtable[i]; - while (n) { - for (j = 0; j < indent; j++) Putc(' ',s); - indent+=4; - Printf(s,"'%s' : %s, \n", n->key, n->object); - indent-=4; - n = n->next; - } - } - for (j = 0; j < (indent-4); j++) Putc(' ',s); - Printf(s,"}\n"); - ObjSetMark(ho,0); + s = NewStringEmpty(); + if (ObjGetMark(ho)) { + Printf(s, "Hash(0x%x)", ho); return s; + } + ObjSetMark(ho, 1); + Printf(s, "Hash {\n"); + for (i = 0; i < h->hashsize; i++) { + n = h->hashtable[i]; + while (n) { + for (j = 0; j < indent; j++) + Putc(' ', s); + indent += 4; + Printf(s, "'%s' : %s, \n", n->key, n->object); + indent -= 4; + n = n->next; + } + } + for (j = 0; j < (indent - 4); j++) + Putc(' ', s); + Printf(s, "}\n"); + ObjSetMark(ho, 0); + return s; } /* ----------------------------------------------------------------------------- @@ -451,8 +453,7 @@ Hash_str(DOH *ho) { * Return number of entries in the hash table. * ----------------------------------------------------------------------------- */ -static int -Hash_len(DOH *ho) { +static int Hash_len(DOH *ho) { Hash *h = (Hash *) ObjData(ho); return h->nitems; } @@ -463,67 +464,64 @@ Hash_len(DOH *ho) { * Make a copy of a hash table. Note: this is a shallow copy. * ----------------------------------------------------------------------------- */ -static DOH * -CopyHash(DOH *ho) { - Hash *h, *nh; - HashNode *n; - DOH *nho; - - int i; - h = (Hash *) ObjData(ho); - nh = (Hash *) DohMalloc(sizeof(Hash)); - nh->hashsize = h->hashsize; - nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *)); - for (i = 0; i < nh->hashsize; i++) { - nh->hashtable[i] = 0; - } - nh->nitems = 0; - nh->line = h->line; - nh->file = h->file; - if (nh->file) Incref(nh->file); +static DOH *CopyHash(DOH *ho) { + Hash *h, *nh; + HashNode *n; + DOH *nho; - nho = DohObjMalloc(&DohHashType, nh); - for (i = 0; i < h->hashsize; i++) { - if ((n = h->hashtable[i])) { - while (n) { - Hash_setattr(nho, n->key, n->object); - n = n->next; - } - } + int i; + h = (Hash *) ObjData(ho); + nh = (Hash *) DohMalloc(sizeof(Hash)); + nh->hashsize = h->hashsize; + nh->hashtable = (HashNode **) DohMalloc(nh->hashsize * sizeof(HashNode *)); + for (i = 0; i < nh->hashsize; i++) { + nh->hashtable[i] = 0; + } + nh->nitems = 0; + nh->line = h->line; + nh->file = h->file; + if (nh->file) + Incref(nh->file); + + nho = DohObjMalloc(&DohHashType, nh); + for (i = 0; i < h->hashsize; i++) { + if ((n = h->hashtable[i])) { + while (n) { + Hash_setattr(nho, n->key, n->object); + n = n->next; + } } - return nho; + } + return nho; } -static void -Hash_setfile(DOH *ho, DOH *file) { +static void Hash_setfile(DOH *ho, DOH *file) { DOH *fo; Hash *h = (Hash *) ObjData(ho); if (!DohCheck(file)) { fo = NewString(file); Decref(fo); - } else fo = file; + } else + fo = file; Incref(fo); Delete(h->file); h->file = fo; } -static DOH * -Hash_getfile(DOH *ho) { +static DOH *Hash_getfile(DOH *ho) { Hash *h = (Hash *) ObjData(ho); return h->file; } -static void -Hash_setline(DOH *ho, int line) { +static void Hash_setline(DOH *ho, int line) { Hash *h = (Hash *) ObjData(ho); h->line = line; } -static int -Hash_getline(DOH *ho) { +static int Hash_getline(DOH *ho) { Hash *h = (Hash *) ObjData(ho); return h->line; } @@ -540,29 +538,29 @@ static DohHashMethods HashHashMethods = { }; DohObjInfo DohHashType = { - "Hash", /* objname */ - DelHash, /* doh_del */ - CopyHash, /* doh_copy */ - Hash_clear, /* doh_clear */ - Hash_str, /* doh_str */ - 0, /* doh_data */ - 0, /* doh_dump */ - Hash_len, /* doh_len */ - 0, /* doh_hash */ - 0, /* doh_cmp */ - 0, /* doh_equal */ - Hash_firstiter, /* doh_first */ - Hash_nextiter, /* doh_next */ - Hash_setfile, /* doh_setfile */ - Hash_getfile, /* doh_getfile */ - Hash_setline, /* doh_setline */ - Hash_getline, /* doh_getline */ - &HashHashMethods, /* doh_mapping */ - 0, /* doh_sequence */ - 0, /* doh_file */ - 0, /* doh_string */ - 0, /* doh_positional */ - 0, + "Hash", /* objname */ + DelHash, /* doh_del */ + CopyHash, /* doh_copy */ + Hash_clear, /* doh_clear */ + Hash_str, /* doh_str */ + 0, /* doh_data */ + 0, /* doh_dump */ + Hash_len, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_equal */ + Hash_firstiter, /* doh_first */ + Hash_nextiter, /* doh_next */ + Hash_setfile, /* doh_setfile */ + Hash_getfile, /* doh_getfile */ + Hash_setline, /* doh_setline */ + Hash_getline, /* doh_getline */ + &HashHashMethods, /* doh_mapping */ + 0, /* doh_sequence */ + 0, /* doh_file */ + 0, /* doh_string */ + 0, /* doh_positional */ + 0, }; /* ----------------------------------------------------------------------------- @@ -571,18 +569,17 @@ DohObjInfo DohHashType = { * Create a new hash table. * ----------------------------------------------------------------------------- */ -DOH * -DohNewHash() { - Hash *h; - int i; - h = (Hash *) DohMalloc(sizeof(Hash)); - h->hashsize = HASH_INIT_SIZE; - h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *)); - for (i = 0; i < h->hashsize; i++) { - h->hashtable[i] = 0; - } - h->nitems = 0; - h->file = 0; - h->line = 0; - return DohObjMalloc(&DohHashType,h); +DOH *DohNewHash() { + Hash *h; + int i; + h = (Hash *) DohMalloc(sizeof(Hash)); + h->hashsize = HASH_INIT_SIZE; + h->hashtable = (HashNode **) DohMalloc(h->hashsize * sizeof(HashNode *)); + for (i = 0; i < h->hashsize; i++) { + h->hashtable[i] = 0; + } + h->nitems = 0; + h->file = 0; + h->line = 0; + return DohObjMalloc(&DohHashType, h); } diff --git a/SWIG/Source/DOH/list.c b/SWIG/Source/DOH/list.c index 69fe6ba87..59fba52ac 100644 --- a/SWIG/Source/DOH/list.c +++ b/SWIG/Source/DOH/list.c @@ -14,21 +14,21 @@ char cvsroot_list_c[] = "$Header$"; #include "dohint.h" typedef struct List { - int maxitems; /* Max size */ - int nitems; /* Num items */ - DOH *file; - int line; - DOH **items; + int maxitems; /* Max size */ + int nitems; /* Num items */ + DOH *file; + int line; + DOH **items; } List; extern DohObjInfo DohListType; /* Doubles amount of memory in a list */ -static +static void more(List *l) { - l->items = (void **) DohRealloc(l->items, l->maxitems*2*sizeof(void *)); - assert(l->items); - l->maxitems *= 2; + l->items = (void **) DohRealloc(l->items, l->maxitems * 2 * sizeof(void *)); + assert(l->items); + l->maxitems *= 2; } /* ----------------------------------------------------------------------------- @@ -36,23 +36,23 @@ void more(List *l) { * * Make a shallow copy of a list. * ----------------------------------------------------------------------------- */ -static DOH * -CopyList(DOH *lo) { - List *l,*nl; - int i; - l = (List *) ObjData(lo); - nl = (List *) DohMalloc(sizeof(List)); - nl->nitems = l->nitems; - nl->maxitems = l->maxitems; - nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); - for (i = 0; i < l->nitems; i++) { - nl->items[i] = l->items[i]; - Incref(nl->items[i]); - } - nl->file = l->file; - if (nl->file) Incref(nl->file); - nl->line = l->line; - return DohObjMalloc(&DohListType, nl); +static DOH *CopyList(DOH *lo) { + List *l, *nl; + int i; + l = (List *) ObjData(lo); + nl = (List *) DohMalloc(sizeof(List)); + nl->nitems = l->nitems; + nl->maxitems = l->maxitems; + nl->items = (void **) DohMalloc(l->maxitems * sizeof(void *)); + for (i = 0; i < l->nitems; i++) { + nl->items[i] = l->items[i]; + Incref(nl->items[i]); + } + nl->file = l->file; + if (nl->file) + Incref(nl->file); + nl->line = l->line; + return DohObjMalloc(&DohListType, nl); } /* ----------------------------------------------------------------------------- @@ -61,14 +61,13 @@ CopyList(DOH *lo) { * Delete a list. * ----------------------------------------------------------------------------- */ -static void -DelList(DOH *lo) { - List *l = (List *) ObjData(lo); - int i; - for (i = 0; i < l->nitems; i++) - Delete(l->items[i]); - DohFree(l->items); - DohFree(l); +static void DelList(DOH *lo) { + List *l = (List *) ObjData(lo); + int i; + for (i = 0; i < l->nitems; i++) + Delete(l->items[i]); + DohFree(l->items); + DohFree(l); } /* ----------------------------------------------------------------------------- @@ -77,14 +76,13 @@ DelList(DOH *lo) { * Remove all of the list entries, but keep the list object intact. * ----------------------------------------------------------------------------- */ -static void -List_clear(DOH *lo) { - List *l = (List *) ObjData(lo); - int i; - for (i = 0; i < l->nitems; i++) { - Delete(l->items[i]); - } - l->nitems = 0; +static void List_clear(DOH *lo) { + List *l = (List *) ObjData(lo); + int i; + for (i = 0; i < l->nitems; i++) { + Delete(l->items[i]); + } + l->nitems = 0; } /* ----------------------------------------------------------------------------- @@ -94,22 +92,26 @@ List_clear(DOH *lo) { * to be a 'char *' and is used to construct an equivalent string object. * ----------------------------------------------------------------------------- */ -static int -List_insert(DOH *lo, int pos, DOH *item) { +static int List_insert(DOH *lo, int pos, DOH *item) { List *l = (List *) ObjData(lo); int i; - - if (!item) return -1; + + if (!item) + return -1; if (!DohCheck(item)) { item = NewString(item); Decref(item); } - if (pos == DOH_END) pos = l->nitems; - if (pos < 0) pos = 0; - if (pos > l->nitems) pos = l->nitems; - if (l->nitems == l->maxitems) more(l); + if (pos == DOH_END) + pos = l->nitems; + if (pos < 0) + pos = 0; + if (pos > l->nitems) + pos = l->nitems; + if (l->nitems == l->maxitems) + more(l); for (i = l->nitems; i > pos; i--) { - l->items[i] = l->items[i-1]; + l->items[i] = l->items[i - 1]; } l->items[pos] = item; Incref(item); @@ -122,20 +124,21 @@ List_insert(DOH *lo, int pos, DOH *item) { * * Remove an item from a list. * ----------------------------------------------------------------------------- */ - -static int -List_remove(DOH *lo, int pos) { - List *l = (List *) ObjData(lo); - int i; - if (pos == DOH_END) pos = l->nitems-1; - if (pos == DOH_BEGIN) pos = 0; - assert(!((pos < 0) || (pos >= l->nitems))); - Delete(l->items[pos]); - for (i = pos; i < l->nitems-1; i++) { - l->items[i] = l->items[i+1]; - } - l->nitems--; - return 0; + +static int List_remove(DOH *lo, int pos) { + List *l = (List *) ObjData(lo); + int i; + if (pos == DOH_END) + pos = l->nitems - 1; + if (pos == DOH_BEGIN) + pos = 0; + assert(!((pos < 0) || (pos >= l->nitems))); + Delete(l->items[pos]); + for (i = pos; i < l->nitems - 1; i++) { + l->items[i] = l->items[i + 1]; + } + l->nitems--; + return 0; } /* ----------------------------------------------------------------------------- @@ -144,8 +147,7 @@ List_remove(DOH *lo, int pos) { * Return the number of elements in the list * ----------------------------------------------------------------------------- */ -static int -List_len(DOH *lo) { +static int List_len(DOH *lo) { List *l = (List *) ObjData(lo); return l->nitems; } @@ -156,13 +158,14 @@ List_len(DOH *lo) { * Get the nth item from the list. * ----------------------------------------------------------------------------- */ -static DOH * -List_get(DOH *lo, int n) { - List *l = (List *) ObjData(lo); - if (n == DOH_END) n = l->nitems-1; - if (n == DOH_BEGIN) n = 0; - assert(!((n < 0) || (n >= l->nitems))); - return l->items[n]; +static DOH *List_get(DOH *lo, int n) { + List *l = (List *) ObjData(lo); + if (n == DOH_END) + n = l->nitems - 1; + if (n == DOH_BEGIN) + n = 0; + assert(!((n < 0) || (n >= l->nitems))); + return l->items[n]; } /* ----------------------------------------------------------------------------- @@ -171,20 +174,20 @@ List_get(DOH *lo, int n) { * Set the nth item in the list replacing any previous item. * ----------------------------------------------------------------------------- */ -static int -List_set(DOH *lo, int n, DOH *val) { - List *l = (List *) ObjData(lo); - if (!val) return -1; - assert(!((n < 0) || (n >= l->nitems))); - if (!DohCheck(val)) { - val = NewString(val); - Decref(val); - } - Delete(l->items[n]); - l->items[n] = val; - Incref(val); - Delete(val); - return 0; +static int List_set(DOH *lo, int n, DOH *val) { + List *l = (List *) ObjData(lo); + if (!val) + return -1; + assert(!((n < 0) || (n >= l->nitems))); + if (!DohCheck(val)) { + val = NewString(val); + Decref(val); + } + Delete(l->items[n]); + l->items[n] = val; + Incref(val); + Delete(val); + return 0; } /* ----------------------------------------------------------------------------- @@ -193,8 +196,7 @@ List_set(DOH *lo, int n, DOH *val) { * Return the first item in the list. * ----------------------------------------------------------------------------- */ -static DohIterator -List_first(DOH *lo) { +static DohIterator List_first(DOH *lo) { DohIterator iter; List *l = (List *) ObjData(lo); iter.object = lo; @@ -215,8 +217,7 @@ List_first(DOH *lo) { * Return the next item in the list. * ----------------------------------------------------------------------------- */ -static DohIterator -List_next(DohIterator iter) { +static DohIterator List_next(DohIterator iter) { List *l = (List *) ObjData(iter.object); iter._index = iter._index + 1; if (iter._index >= l->nitems) { @@ -233,26 +234,25 @@ List_next(DohIterator iter) { * * Create a string representation of the list. * ----------------------------------------------------------------------------- */ -static DOH * -List_str(DOH *lo) { - DOH *s; - int i; - List *l = (List *) ObjData(lo); - s = NewStringEmpty(); - if (ObjGetMark(lo)) { - Printf(s,"List(%x)", lo); - return s; - } - ObjSetMark(lo,1); - Printf(s,"List[ "); - for (i = 0; i < l->nitems; i++) { - Printf(s, "%s", l->items[i]); - if ((i+1) < l->nitems) - Printf(s,", "); - } - Printf(s," ]\n"); - ObjSetMark(lo,0); +static DOH *List_str(DOH *lo) { + DOH *s; + int i; + List *l = (List *) ObjData(lo); + s = NewStringEmpty(); + if (ObjGetMark(lo)) { + Printf(s, "List(%x)", lo); return s; + } + ObjSetMark(lo, 1); + Printf(s, "List[ "); + for (i = 0; i < l->nitems; i++) { + Printf(s, "%s", l->items[i]); + if ((i + 1) < l->nitems) + Printf(s, ", "); + } + Printf(s, " ]\n"); + ObjSetMark(lo, 0); + return s; } /* ----------------------------------------------------------------------------- @@ -261,41 +261,39 @@ List_str(DOH *lo) { * Dump the items to an output stream. * ----------------------------------------------------------------------------- */ -static int -List_dump(DOH *lo, DOH *out) { +static int List_dump(DOH *lo, DOH *out) { int nsent = 0; - int i,ret; + int i, ret; List *l = (List *) ObjData(lo); for (i = 0; i < l->nitems; i++) { - ret = Dump(l->items[i],out); - if (ret < 0) return -1; + ret = Dump(l->items[i], out); + if (ret < 0) + return -1; nsent += ret; } return nsent; } -static void -List_setfile(DOH *lo, DOH *file) { +static void List_setfile(DOH *lo, DOH *file) { DOH *fo; List *l = (List *) ObjData(lo); if (!DohCheck(file)) { fo = NewString(file); Decref(fo); - } else fo = file; + } else + fo = file; Incref(fo); Delete(l->file); l->file = fo; } -static DOH * -List_getfile(DOH *lo) { +static DOH *List_getfile(DOH *lo) { List *l = (List *) ObjData(lo); return l->file; } -static void -List_setline(DOH *lo, int line) { +static void List_setline(DOH *lo, int line) { List *l = (List *) ObjData(lo); l->line = line; } @@ -310,33 +308,33 @@ static DohListMethods ListListMethods = { List_set, List_remove, List_insert, - 0, /* delslice */ + 0, /* delslice */ }; DohObjInfo DohListType = { - "List", /* objname */ - DelList, /* doh_del */ - CopyList, /* doh_copy */ - List_clear, /* doh_clear */ - List_str, /* doh_str */ - 0, /* doh_data */ - List_dump, /* doh_dump */ - List_len, /* doh_len */ - 0, /* doh_hash */ - 0, /* doh_cmp */ - 0, /* doh_equal */ - List_first, /* doh_first */ - List_next, /* doh_next */ - List_setfile, /* doh_setfile */ - List_getfile, /* doh_getfile */ - List_setline, /* doh_setline */ - List_getline, /* doh_getline */ - 0, /* doh_mapping */ - &ListListMethods, /* doh_sequence */ - 0, /* doh_file */ - 0, /* doh_string */ - 0, /* doh_callable */ - 0, /* doh_position */ + "List", /* objname */ + DelList, /* doh_del */ + CopyList, /* doh_copy */ + List_clear, /* doh_clear */ + List_str, /* doh_str */ + 0, /* doh_data */ + List_dump, /* doh_dump */ + List_len, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_equal */ + List_first, /* doh_first */ + List_next, /* doh_next */ + List_setfile, /* doh_setfile */ + List_getfile, /* doh_getfile */ + List_setline, /* doh_setline */ + List_getline, /* doh_getline */ + 0, /* doh_mapping */ + &ListListMethods, /* doh_sequence */ + 0, /* doh_file */ + 0, /* doh_string */ + 0, /* doh_callable */ + 0, /* doh_position */ }; /* ----------------------------------------------------------------------------- @@ -347,29 +345,28 @@ DohObjInfo DohListType = { #define MAXLISTITEMS 8 -DOH * -DohNewList() { - List *l; - int i; - l = (List *) DohMalloc(sizeof(List)); - l->nitems = 0; - l->maxitems = MAXLISTITEMS; - l->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); - for (i = 0; i < MAXLISTITEMS; i++) { - l->items[i] = 0; - } - l->file = 0; - l->line = 0; - return DohObjMalloc(&DohListType,l); +DOH *DohNewList() { + List *l; + int i; + l = (List *) DohMalloc(sizeof(List)); + l->nitems = 0; + l->maxitems = MAXLISTITEMS; + l->items = (void **) DohMalloc(l->maxitems * sizeof(void *)); + for (i = 0; i < MAXLISTITEMS; i++) { + l->items[i] = 0; + } + l->file = 0; + l->line = 0; + return DohObjMalloc(&DohListType, l); } -static int (*List_sort_compare_func)(const DOH *, const DOH *); +static int (*List_sort_compare_func) (const DOH *, const DOH *); static int List_qsort_compare(const void *a, const void *b) { - return List_sort_compare_func(*((DOH **)a), *((DOH **)b)); + return List_sort_compare_func(*((DOH **) a), *((DOH **) b)); } /* Sort a list */ -void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *)) { +void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)) { List *l = (List *) ObjData(lo); if (cmp) { List_sort_compare_func = cmp; diff --git a/SWIG/Source/DOH/memory.c b/SWIG/Source/DOH/memory.c index ca23fcdf5..73d5c8a3c 100644 --- a/SWIG/Source/DOH/memory.c +++ b/SWIG/Source/DOH/memory.c @@ -18,40 +18,39 @@ char cvsroot_memory_c[] = "$Header$"; #define DOH_POOL_SIZE 16384 #endif -static int PoolSize = DOH_POOL_SIZE; +static int PoolSize = DOH_POOL_SIZE; -DOH *DohNone = 0; /* The DOH None object */ +DOH *DohNone = 0; /* The DOH None object */ typedef struct pool { - DohBase *ptr; /* Start of pool */ - int len; /* Length of pool */ - int blen; /* Byte length of pool */ - int current; /* Current position for next allocation */ - char* pbeg; /* Beg of pool */ - char* pend; /* End of pool */ - struct pool *next; /* Next pool */ + DohBase *ptr; /* Start of pool */ + int len; /* Length of pool */ + int blen; /* Byte length of pool */ + int current; /* Current position for next allocation */ + char *pbeg; /* Beg of pool */ + char *pend; /* End of pool */ + struct pool *next; /* Next pool */ } Pool; -static DohBase *FreeList = 0; /* List of free objects */ -static Pool *Pools = 0; -static int pools_initialized = 0; +static DohBase *FreeList = 0; /* List of free objects */ +static Pool *Pools = 0; +static int pools_initialized = 0; /* ---------------------------------------------------------------------- * CreatePool() - Create a new memory pool * ---------------------------------------------------------------------- */ -static void -CreatePool() { +static void CreatePool() { Pool *p = 0; p = (Pool *) DohMalloc(sizeof(Pool)); assert(p); - p->ptr = (DohBase *) DohMalloc(sizeof(DohBase)*PoolSize); + p->ptr = (DohBase *) DohMalloc(sizeof(DohBase) * PoolSize); assert(p->ptr); - memset(p->ptr,0,sizeof(DohBase)*PoolSize); + memset(p->ptr, 0, sizeof(DohBase) * PoolSize); p->len = PoolSize; - p->blen = PoolSize*sizeof(DohBase); + p->blen = PoolSize * sizeof(DohBase); p->current = 0; - p->pbeg = ((char *)p->ptr); + p->pbeg = ((char *) p->ptr); p->pend = p->pbeg + p->blen; p->next = Pools; Pools = p; @@ -61,12 +60,12 @@ CreatePool() { * InitPools() - Initialize the memory allocator * ---------------------------------------------------------------------- */ -static void -InitPools() { - if (pools_initialized) return; - CreatePool(); /* Create initial pool */ +static void InitPools() { + if (pools_initialized) + return; + CreatePool(); /* Create initial pool */ pools_initialized = 1; - DohNone = NewVoid(0,0); /* Create the None object */ + DohNone = NewVoid(0, 0); /* Create the None object */ DohIntern(DohNone); } @@ -76,15 +75,15 @@ InitPools() { * Returns 1 if an arbitrary pointer is a DOH object. * ---------------------------------------------------------------------- */ -int -DohCheck(const DOH *ptr) { +int DohCheck(const DOH *ptr) { register Pool *p = Pools; register char *cptr = (char *) ptr; while (p) { - if ((cptr >= p->pbeg) && (cptr < p->pend)) return 1; + if ((cptr >= p->pbeg) && (cptr < p->pend)) + return 1; /* - pptr = (char *) p->ptr; - if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */ + pptr = (char *) p->ptr; + if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */ p = p->next; } return 0; @@ -94,8 +93,7 @@ DohCheck(const DOH *ptr) { * DohIntern() * ----------------------------------------------------------------------------- */ -void -DohIntern(DOH *obj) { +void DohIntern(DOH *obj) { DohBase *b = (DohBase *) obj; b->flag_intern = 1; } @@ -106,10 +104,10 @@ DohIntern(DOH *obj) { * Allocate memory for a new object. * ---------------------------------------------------------------------- */ -DOH * -DohObjMalloc(DohObjInfo *type, void *data) { +DOH *DohObjMalloc(DohObjInfo *type, void *data) { DohBase *obj; - if (!pools_initialized) InitPools(); + if (!pools_initialized) + InitPools(); if (FreeList) { obj = FreeList; FreeList = (DohBase *) obj->data; @@ -135,12 +133,12 @@ DohObjMalloc(DohObjInfo *type, void *data) { * DohObjFree() - Free a DOH object * ---------------------------------------------------------------------- */ -void -DohObjFree(DOH *ptr) { - DohBase *b, *meta; +void DohObjFree(DOH *ptr) { + DohBase *b, *meta; b = (DohBase *) ptr; - if (b->flag_intern) return; - meta = (DohBase *)b->meta; + if (b->flag_intern) + return; + meta = (DohBase *) b->meta; b->data = (void *) FreeList; b->meta = 0; b->type = 0; @@ -156,42 +154,45 @@ DohObjFree(DOH *ptr) { * Display memory usage statistics * ---------------------------------------------------------------------- */ -void -DohMemoryDebug(void) { +void DohMemoryDebug(void) { extern DohObjInfo DohStringType; extern DohObjInfo DohListType; extern DohObjInfo DohHashType; Pool *p; - int totsize = 0; - int totused = 0; - int totfree = 0; + int totsize = 0; + int totused = 0; + int totfree = 0; - int numstring = 0; - int numlist = 0; - int numhash = 0; + int numstring = 0; + int numlist = 0; + int numhash = 0; printf("Memory statistics:\n\n"); printf("Pools:\n"); - + p = Pools; - while(p) { + while (p) { /* Calculate number of used, free items */ int i; int nused = 0, nfree = 0; for (i = 0; i < p->len; i++) { - if (p->ptr[i].refcount <= 0) nfree++; + if (p->ptr[i].refcount <= 0) + nfree++; else { nused++; - if (p->ptr[i].type == &DohStringType) numstring++; - else if (p->ptr[i].type == &DohListType) numlist++; - else if (p->ptr[i].type == &DohHashType) numhash++; + if (p->ptr[i].type == &DohStringType) + numstring++; + else if (p->ptr[i].type == &DohListType) + numlist++; + else if (p->ptr[i].type == &DohHashType) + numhash++; } } - printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *)p, p->len, nused, nfree); + printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *) p, p->len, nused, nfree); totsize += p->len; - totused+= nused; - totfree+= nfree; + totused += nused; + totfree += nfree; p = p->next; } printf("\n Total: size = %10d, used = %10d, free = %10d\n", totsize, totused, totfree); @@ -203,12 +204,12 @@ DohMemoryDebug(void) { #if 0 p = Pools; - while(p) { + while (p) { int i; for (i = 0; i < p->len; i++) { if (p->ptr[i].refcount > 0) { if (p->ptr[i].type == &DohStringType) { - Printf(stdout,"%s\n", p->ptr+i); + Printf(stdout, "%s\n", p->ptr + i); } } } diff --git a/SWIG/Source/DOH/string.c b/SWIG/Source/DOH/string.c index f5ffa3983..134d50a26 100644 --- a/SWIG/Source/DOH/string.c +++ b/SWIG/Source/DOH/string.c @@ -17,28 +17,26 @@ char cvsroot_string_c[] = "$Header$"; extern DohObjInfo DohStringType; typedef struct String { - DOH *file; - int line; - int maxsize; /* Max size allocated */ - int len; /* Current length */ - int hashkey; /* Hash key value */ - int sp; /* Current position */ - char *str; /* String data */ + DOH *file; + int line; + int maxsize; /* Max size allocated */ + int len; /* Current length */ + int hashkey; /* Hash key value */ + int sp; /* Current position */ + char *str; /* String data */ } String; /* ----------------------------------------------------------------------------- * void *String_data() - Return as a 'void *' * ----------------------------------------------------------------------------- */ -static void * -String_data(DOH *so) { +static void *String_data(DOH *so) { String *s = (String *) ObjData(so); s->str[s->len] = 0; return (void *) s->str; } -char * -DohString_char(DOH *so) { +char *DohString_char(DOH *so) { return (char *) String_data(so); } @@ -46,15 +44,15 @@ DohString_char(DOH *so) { * int String_dump() - Serialize a string onto out * ----------------------------------------------------------------------------- */ -static int -String_dump(DOH *so, DOH *out) { +static int String_dump(DOH *so, DOH *out) { int nsent; int ret; String *s = (String *) ObjData(so); nsent = 0; while (nsent < s->len) { - ret = Write(out,s->str+nsent,(s->len-nsent)); - if (ret < 0) return ret; + ret = Write(out, s->str + nsent, (s->len - nsent)); + if (ret < 0) + return ret; nsent += ret; } return nsent; @@ -64,8 +62,7 @@ String_dump(DOH *so, DOH *out) { * CopyString() - Copy a string * ----------------------------------------------------------------------------- */ -static DOH * -CopyString(DOH *so) { +static DOH *CopyString(DOH *so) { int max; String *str; String *s = (String *) ObjData(so); @@ -74,23 +71,23 @@ CopyString(DOH *so) { str->sp = s->sp; str->line = s->line; str->file = s->file; - if (str->file) Incref(str->file); + if (str->file) + Incref(str->file); max = s->maxsize; - str->str = (char *) DohMalloc(max+1); + str->str = (char *) DohMalloc(max + 1); memmove(str->str, s->str, max); - str->maxsize= max; + str->maxsize = max; str->len = s->len; str->str[str->len] = 0; - - return DohObjMalloc(&DohStringType,str); + + return DohObjMalloc(&DohStringType, str); } /* ----------------------------------------------------------------------------- * DelString() - Delete a string * ----------------------------------------------------------------------------- */ -static void -DelString(DOH *so) { +static void DelString(DOH *so) { String *s = (String *) ObjData(so); DohFree(s->str); DohFree(s); @@ -100,8 +97,7 @@ DelString(DOH *so) { * DohString_len() - Length of a string * ----------------------------------------------------------------------------- */ -int -DohString_len(DOH *so) { +int DohString_len(DOH *so) { String *s = (String *) ObjData(so); return s->len; } @@ -111,27 +107,31 @@ DohString_len(DOH *so) { * int String_cmp() - Compare two strings * ----------------------------------------------------------------------------- */ -static int -String_cmp(DOH *so1, DOH *so2) -{ +static int String_cmp(DOH *so1, DOH *so2) { String *s1, *s2; char *c1, *c2; - int maxlen,i; + int maxlen, i; s1 = (String *) ObjData(so1); s2 = (String *) ObjData(so2); maxlen = s1->len; - if (s2->len < maxlen) maxlen = s2->len; + if (s2->len < maxlen) + maxlen = s2->len; c1 = s1->str; c2 = s2->str; - for (i = maxlen; i; --i,c1++,c2++) { - if (*c1 != *c2) break; + for (i = maxlen; i; --i, c1++, c2++) { + if (*c1 != *c2) + break; } if (i != 0) { - if (*c1 < *c2) return -1; - else return 1; + if (*c1 < *c2) + return -1; + else + return 1; } - if (s1->len == s2->len) return 0; - if (s1->len > s2->len) return 1; + if (s1->len == s2->len) + return 0; + if (s1->len > s2->len) + return 1; return -1; } @@ -139,9 +139,7 @@ String_cmp(DOH *so1, DOH *so2) * int String_equal() - Say if two string are equal * ----------------------------------------------------------------------------- */ -int -DohString_equal(DOH *so1, DOH *so2) -{ +int DohString_equal(DOH *so1, DOH *so2) { String *s1 = (String *) ObjData(so1); String *s2 = (String *) ObjData(so2); register int len = s1->len; @@ -154,13 +152,18 @@ DohString_equal(DOH *so1, DOH *so2) register int mlen = len >> 2; register int i = mlen; for (; i; --i) { - if (*(c1++) != *(c2++)) return 0; - if (*(c1++) != *(c2++)) return 0; - if (*(c1++) != *(c2++)) return 0; - if (*(c1++) != *(c2++)) return 0; + if (*(c1++) != *(c2++)) + return 0; + if (*(c1++) != *(c2++)) + return 0; + if (*(c1++) != *(c2++)) + return 0; + if (*(c1++) != *(c2++)) + return 0; } for (i = len - (mlen << 2); i; --i) { - if (*(c1++) != *(c2++)) return 0; + if (*(c1++) != *(c2++)) + return 0; } return 1; #else @@ -173,8 +176,7 @@ DohString_equal(DOH *so1, DOH *so2) * int String_hash() - Compute string hash value * ----------------------------------------------------------------------------- */ -static int -String_hash(DOH *so) { +static int String_hash(DOH *so) { String *s = (String *) ObjData(so); if (s->hashkey >= 0) { return s->hashkey; @@ -197,49 +199,51 @@ String_hash(DOH *so) { s->hashkey = h; return h; } -} +} /* ----------------------------------------------------------------------------- * DohString_append(String *s, const char *newstr) - Append to s * ----------------------------------------------------------------------------- */ -void -DohString_append(DOH *so, DOH *str) { - int oldlen, newlen, newmaxsize, l, sp; +void DohString_append(DOH *so, DOH *str) { + int oldlen, newlen, newmaxsize, l, sp; char *tc; String *s = (String *) ObjData(so); char *newstr = 0; if (DohCheck(str)) { String *ss = (String *) ObjData(str); - newstr = (char*) String_data((DOH*)str); + newstr = (char *) String_data((DOH *) str); l = ss->len; } else { newstr = (char *) (str); l = (int) strlen(newstr); } - if (!newstr) return; + if (!newstr) + return; s->hashkey = -1; oldlen = s->len; - newlen = oldlen+l + 1; - if (newlen >= s->maxsize-1) { - newmaxsize = 2*s->maxsize; - if (newlen >= newmaxsize -1) newmaxsize = newlen + 1; - s->str = (char *) DohRealloc(s->str,newmaxsize); + newlen = oldlen + l + 1; + if (newlen >= s->maxsize - 1) { + newmaxsize = 2 * s->maxsize; + if (newlen >= newmaxsize - 1) + newmaxsize = newlen + 1; + s->str = (char *) DohRealloc(s->str, newmaxsize); assert(s->str); s->maxsize = newmaxsize; } tc = s->str; - memcpy(tc+oldlen,newstr,l+1); + memcpy(tc + oldlen, newstr, l + 1); sp = s->sp; if (sp >= oldlen) { - int i = oldlen + l - sp; + int i = oldlen + l - sp; tc += sp; - for (; i ; --i) { - if (*(tc++) == '\n') s->line++; + for (; i; --i) { + if (*(tc++) == '\n') + s->line++; } - s->sp = oldlen+l; + s->sp = oldlen + l; } s->len += l; } @@ -249,9 +253,7 @@ DohString_append(DOH *so, DOH *str) { * void String_clear() - Clear a string * ----------------------------------------------------------------------------- */ -static void -String_clear(DOH *so) -{ +static void String_clear(DOH *so) { String *s = (String *) ObjData(so); s->hashkey = -1; s->len = 0; @@ -264,12 +266,10 @@ String_clear(DOH *so) * void String_insert() - Insert a string * ----------------------------------------------------------------------------- */ -static int -String_insert(DOH *so, int pos, DOH *str) -{ +static int String_insert(DOH *so, int pos, DOH *str) { String *s; char *nstr; - int len; + int len; char *data; if (pos == DOH_END) { @@ -282,7 +282,7 @@ String_insert(DOH *so, int pos, DOH *str) s->hashkey = -1; if (DohCheck(str)) { String *ss = (String *) ObjData(str); - data = (char *)String_data(str); + data = (char *) String_data(str); len = ss->len; } else { data = (char *) (str); @@ -290,50 +290,55 @@ String_insert(DOH *so, int pos, DOH *str) } nstr = s->str; - if (pos < 0) pos = 0; - else if (pos > s->len) pos = s->len; - + if (pos < 0) + pos = 0; + else if (pos > s->len) + pos = s->len; + /* See if there is room to insert the new data */ - while (s->maxsize <= s->len+len) { - int newsize = 2*s->maxsize; - s->str = (char *) DohRealloc(s->str,newsize); + while (s->maxsize <= s->len + len) { + int newsize = 2 * s->maxsize; + s->str = (char *) DohRealloc(s->str, newsize); assert(s->str); s->maxsize = newsize; } - memmove(s->str+pos+len, s->str+pos, (s->len - pos)); - memcpy(s->str+pos,data,len); + memmove(s->str + pos + len, s->str + pos, (s->len - pos)); + memcpy(s->str + pos, data, len); if (s->sp >= pos) { int i; - + for (i = 0; i < len; i++) { - if (data[i] == '\n') s->line++; + if (data[i] == '\n') + s->line++; } - s->sp+=len; + s->sp += len; } s->len += len; s->str[s->len] = 0; return 0; -} +} /* ----------------------------------------------------------------------------- * int String_delitem() - Delete a character * ----------------------------------------------------------------------------- */ -static int -String_delitem(DOH *so, int pos) -{ +static int String_delitem(DOH *so, int pos) { String *s = (String *) ObjData(so); s->hashkey = -1; - if (pos == DOH_END) pos = s->len-1; - if (pos == DOH_BEGIN) pos = 0; - if (s->len == 0) return 0; + if (pos == DOH_END) + pos = s->len - 1; + if (pos == DOH_BEGIN) + pos = 0; + if (s->len == 0) + return 0; if (s->sp > pos) { s->sp--; - assert (s->sp >= 0); - if (s->str[pos] == '\n') s->line--; + assert(s->sp >= 0); + if (s->str[pos] == '\n') + s->line--; } - memmove(s->str+pos, s->str+pos+1, ((s->len-1) - pos)); + memmove(s->str + pos, s->str + pos + 1, ((s->len - 1) - pos)); s->len--; s->str[s->len] = 0; return 0; @@ -343,32 +348,35 @@ String_delitem(DOH *so, int pos) * int String_delslice() - Delete a range * ----------------------------------------------------------------------------- */ -static int -String_delslice(DOH *so, int sindex, int eindex) { +static int String_delslice(DOH *so, int sindex, int eindex) { String *s = (String *) ObjData(so); - int size; - if (s->len == 0) return 0; + int size; + if (s->len == 0) + return 0; s->hashkey = -1; - if (eindex == DOH_END) eindex = s->len; - if (sindex == DOH_BEGIN) sindex = 0; + if (eindex == DOH_END) + eindex = s->len; + if (sindex == DOH_BEGIN) + sindex = 0; size = eindex - sindex; if (s->sp > sindex) { /* Adjust the file pointer and line count */ int i, end; if (s->sp > eindex) { - end = eindex; - s->sp -= size; + end = eindex; + s->sp -= size; } else { - end = s->sp; - s->sp = sindex; + end = s->sp; + s->sp = sindex; } for (i = sindex; i < end; i++) { - if (s->str[i] == '\n') s->line--; + if (s->str[i] == '\n') + s->line--; } assert(s->sp >= 0); } - memmove(s->str+sindex, s->str+eindex, s->len-eindex); + memmove(s->str + sindex, s->str + eindex, s->len - eindex); s->len -= size; s->str[s->len] = 0; return 0; @@ -378,9 +386,7 @@ String_delslice(DOH *so, int sindex, int eindex) { * DOH *String_str() - Returns a string (used by printing commands) * ----------------------------------------------------------------------------- */ -static DOH * -String_str(DOH *so) -{ +static DOH *String_str(DOH *so) { String *s = (String *) ObjData(so); s->str[s->len] = 0; return NewString(s->str); @@ -390,20 +396,20 @@ String_str(DOH *so) * int String_read() - Read data from a string * ----------------------------------------------------------------------------- */ -static int -String_read(DOH *so, void *buffer, int len) -{ - int reallen, retlen; - char *cb; +static int String_read(DOH *so, void *buffer, int len) { + int reallen, retlen; + char *cb; String *s = (String *) ObjData(so); - if ((s->sp + len) > s->len) reallen = (s->len - s->sp); - else reallen = len; + if ((s->sp + len) > s->len) + reallen = (s->len - s->sp); + else + reallen = len; cb = (char *) buffer; retlen = reallen; if (reallen > 0) { - memmove(cb, s->str+s->sp, reallen); + memmove(cb, s->str + s->sp, reallen); s->sp += reallen; } return retlen; @@ -412,22 +418,22 @@ String_read(DOH *so, void *buffer, int len) /* ----------------------------------------------------------------------------- * int String_write() - Write data to a string * ----------------------------------------------------------------------------- */ -static int -String_write(DOH *so, void *buffer, int len) -{ - int newlen; +static int String_write(DOH *so, void *buffer, int len) { + int newlen; String *s = (String *) ObjData(so); s->hashkey = -1; - if (s->sp > s->len) s->sp = s->len; - newlen = s->sp + len+1; + if (s->sp > s->len) + s->sp = s->len; + newlen = s->sp + len + 1; if (newlen > s->maxsize) { - s->str = (char *) DohRealloc(s->str,newlen); + s->str = (char *) DohRealloc(s->str, newlen); assert(s->str); s->maxsize = newlen; s->len = s->sp + len; } - if ((s->sp+len) > s->len) s->len = s->sp + len; - memmove(s->str+s->sp,buffer,len); + if ((s->sp + len) > s->len) + s->len = s->sp + len; + memmove(s->str + s->sp, buffer, len); s->sp += len; s->str[s->len] = 0; return len; @@ -437,18 +443,18 @@ String_write(DOH *so, void *buffer, int len) * int String_seek() - Seek to a new position * ----------------------------------------------------------------------------- */ -static int -String_seek(DOH *so, long offset, int whence) -{ - int pos, nsp, inc; +static int String_seek(DOH *so, long offset, int whence) { + int pos, nsp, inc; String *s = (String *) ObjData(so); - if (whence == SEEK_SET) pos = 0; - else if (whence == SEEK_CUR) pos = s->sp; + if (whence == SEEK_SET) + pos = 0; + else if (whence == SEEK_CUR) + pos = s->sp; else if (whence == SEEK_END) { pos = s->len; offset = -offset; - } - else pos = s->sp; + } else + pos = s->sp; nsp = pos + offset; if (nsp < 0) @@ -465,9 +471,9 @@ String_seek(DOH *so, long offset, int whence) register int len = s->len; while (sp != nsp) { int prev = sp + inc; - if (prev>=0 && prev<=len && tc[prev] == '\n') + if (prev >= 0 && prev <= len && tc[prev] == '\n') s->line += inc; - sp+=inc; + sp += inc; } #else register int sp = s->sp; @@ -486,7 +492,7 @@ String_seek(DOH *so, long offset, int whence) #endif s->sp = sp; } - assert (s->sp >= 0); + assert(s->sp >= 0); return 0; } @@ -494,9 +500,7 @@ String_seek(DOH *so, long offset, int whence) * long String_tell() - Return current position * ----------------------------------------------------------------------------- */ -static long -String_tell(DOH *so) -{ +static long String_tell(DOH *so) { String *s = (String *) ObjData(so); return (long) (s->sp); } @@ -505,9 +509,7 @@ String_tell(DOH *so) * int String_putc() * ----------------------------------------------------------------------------- */ -int -DohString_putc(DOH *so, int ch) -{ +int DohString_putc(DOH *so, int ch) { String *s = (String *) ObjData(so); register int len = s->len; register int sp = s->sp; @@ -515,20 +517,22 @@ DohString_putc(DOH *so, int ch) if (sp >= len) { register int maxsize = s->maxsize; register char *tc = s->str; - if (len > (maxsize-2)) { + if (len > (maxsize - 2)) { maxsize *= 2; tc = (char *) DohRealloc(tc, maxsize); assert(tc); - s->maxsize = (int)maxsize; + s->maxsize = (int) maxsize; s->str = tc; } tc += sp; - *tc = (char) ch; *(++tc) = 0; + *tc = (char) ch; + *(++tc) = 0; s->len = s->sp = sp + 1; } else { s->str[s->sp++] = (char) ch; } - if (ch == '\n') s->line++; + if (ch == '\n') + s->line++; return ch; } @@ -536,16 +540,15 @@ DohString_putc(DOH *so, int ch) * int String_getc() * ----------------------------------------------------------------------------- */ -int -DohString_getc(DOH *so) -{ +int DohString_getc(DOH *so) { int c; String *s = (String *) ObjData(so); if (s->sp >= s->len) c = EOF; else c = (int) s->str[s->sp++]; - if (c == '\n') s->line++; + if (c == '\n') + s->line++; return c; } @@ -553,14 +556,15 @@ DohString_getc(DOH *so) * int String_ungetc() * ----------------------------------------------------------------------------- */ -int -DohString_ungetc(DOH *so, int ch) -{ +int DohString_ungetc(DOH *so, int ch) { String *s = (String *) ObjData(so); - if (ch == EOF) return ch; - if (s->sp <= 0) return EOF; + if (ch == EOF) + return ch; + if (s->sp <= 0) + return EOF; s->sp--; - if (ch == '\n') s->line--; + if (ch == '\n') + s->line--; return ch; } @@ -570,22 +574,20 @@ DohString_ungetc(DOH *so, int ch) * Replaces count non-overlapping occurrences of token with rep in a string. * ----------------------------------------------------------------------------- */ -static char * -end_quote(char *s) -{ +static char *end_quote(char *s) { char *qs; - char qc; - char *q; - char *nl; + char qc; + char *q; + char *nl; qc = *s; qs = s; while (1) { - q = strpbrk(s+1,"\"\'"); - nl = strchr(s+1,'\n'); + q = strpbrk(s + 1, "\"\'"); + nl = strchr(s + 1, '\n'); if (nl && (nl < q)) { /* A new line appears before the end of the string */ - if (*(nl-1) == '\\') { - s = nl+1; + if (*(nl - 1) == '\\') { + s = nl + 1; continue; } /* String was terminated by a newline. Wing it */ @@ -594,31 +596,30 @@ end_quote(char *s) if (!q && nl) { return qs; } - if (!q) return 0; - if ((*q == qc) && (*(q-1) != '\\')) return q; + if (!q) + return 0; + if ((*q == qc) && (*(q - 1) != '\\')) + return q; s = q; } } -static char * -match_simple(char *base, char *s, char *token, int tokenlen) -{ - (void)base; - (void)tokenlen; - return strstr(s,token); +static char *match_simple(char *base, char *s, char *token, int tokenlen) { + (void) base; + (void) tokenlen; + return strstr(s, token); } -static char * -match_identifier(char *base, char *s, char *token, int tokenlen) -{ +static char *match_identifier(char *base, char *s, char *token, int tokenlen) { while (s) { - s = strstr(s,token); - if (!s) return 0; - if ((s > base) && (isalnum((int) *(s-1)) || (*(s-1) == '_'))) { + s = strstr(s, token); + if (!s) + return 0; + if ((s > base) && (isalnum((int) *(s - 1)) || (*(s - 1) == '_'))) { s += tokenlen; continue; } - if (isalnum((int)*(s+tokenlen)) || (*(s+tokenlen) == '_')) { + if (isalnum((int) *(s + tokenlen)) || (*(s + tokenlen) == '_')) { s += tokenlen; continue; } @@ -628,13 +629,12 @@ match_identifier(char *base, char *s, char *token, int tokenlen) } -static char * -match_identifier_begin(char *base, char *s, char *token, int tokenlen) -{ +static char *match_identifier_begin(char *base, char *s, char *token, int tokenlen) { while (s) { - s = strstr(s,token); - if (!s) return 0; - if ((s > base) && (isalnum((int)*(s-1)) || (*(s-1) == '_'))) { + s = strstr(s, token); + if (!s) + return 0; + if ((s > base) && (isalnum((int) *(s - 1)) || (*(s - 1) == '_'))) { s += tokenlen; continue; } @@ -643,14 +643,13 @@ match_identifier_begin(char *base, char *s, char *token, int tokenlen) return 0; } -static char * -match_identifier_end(char *base, char *s, char *token, int tokenlen) -{ - (void)base; +static char *match_identifier_end(char *base, char *s, char *token, int tokenlen) { + (void) base; while (s) { - s = strstr(s,token); - if (!s) return 0; - if (isalnum((int)*(s+tokenlen)) || (*(s+tokenlen) == '_')) { + s = strstr(s, token); + if (!s) + return 0; + if (isalnum((int) *(s + tokenlen)) || (*(s + tokenlen) == '_')) { s += tokenlen; continue; } @@ -659,11 +658,9 @@ match_identifier_end(char *base, char *s, char *token, int tokenlen) return 0; } -static int -replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int)) -{ - int tokenlen; /* Length of the token */ - int replen; /* Length of the replacement */ +static int replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match) (char *, char *, char *, int)) { + int tokenlen; /* Length of the token */ + int replen; /* Length of the replacement */ int delta, expand = 0; int ic; int rcount = 0; @@ -674,23 +671,26 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * int i; /* Figure out if anything gets replaced */ - if (!strlen(token)) return 0; + if (!strlen(token)) + return 0; base = str->str; tokenlen = strlen(token); - s = (*match)(base,base,token,tokenlen); + s = (*match) (base, base, token, tokenlen); - if (!s) return 0; /* No matches. Who cares */ + if (!s) + return 0; /* No matches. Who cares */ str->hashkey = -1; - if (flags & DOH_REPLACE_NOQUOTE) noquote = 1; + if (flags & DOH_REPLACE_NOQUOTE) + noquote = 1; /* If we are not replacing inside quotes, we need to do a little extra work */ if (noquote) { - q = strpbrk(base,"\"\'"); + q = strpbrk(base, "\"\'"); if (!q) { - noquote = 0; /* Well, no quotes to worry about. Oh well */ + noquote = 0; /* Well, no quotes to worry about. Oh well */ } else { while (q && (q < s)) { /* First match was found inside a quote. Try to find another match */ @@ -700,11 +700,13 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * } if (q2 > s) { /* Find next match */ - s = (*match)(base,q2+1,token,tokenlen); + s = (*match) (base, q2 + 1, token, tokenlen); } - if (!s) return 0; /* Oh well, no matches */ - q = strpbrk(q2+1,"\"\'"); - if (!q) noquote = 0; /* No more quotes */ + if (!s) + return 0; /* Oh well, no matches */ + q = strpbrk(q2 + 1, "\"\'"); + if (!q) + noquote = 0; /* No more quotes */ } } } @@ -718,21 +720,22 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * /* String is either shrinking or staying the same size */ /* In this case, we do the replacement in place without memory reallocation */ ic = count; - t = s; /* Target of memory copies */ + t = s; /* Target of memory copies */ while (ic && s) { if (replen) { - memcpy(t,rep,replen); + memcpy(t, rep, replen); t += replen; } rcount++; expand += delta; /* Find the next location */ s += tokenlen; - if (ic == 1) break; - c = (*match)(base,s,token,tokenlen); - + if (ic == 1) + break; + c = (*match) (base, s, token, tokenlen); + if (noquote) { - q = strpbrk(s,"\"\'"); + q = strpbrk(s, "\"\'"); if (!q) { noquote = 0; } else { @@ -744,46 +747,49 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * break; } if (q2 > c) - c = (*match)(base,q2+1,token,tokenlen); - if (!c) break; - q = strpbrk(q2+1,"\"\'"); - if (!q) noquote = 0; /* No more quotes */ + c = (*match) (base, q2 + 1, token, tokenlen); + if (!c) + break; + q = strpbrk(q2 + 1, "\"\'"); + if (!q) + noquote = 0; /* No more quotes */ } } } if (delta) { if (c) { - memmove(t,s,c-s); - t += (c-s); + memmove(t, s, c - s); + t += (c - s); } else { - memmove(t,s,(str->str + str->len) - s + 1); + memmove(t, s, (str->str + str->len) - s + 1); } } else { - t += (c-s); + t += (c - s); } s = c; ic--; } if (s && delta) { - memmove(t,s,(str->str + str->len) - s + 1); + memmove(t, s, (str->str + str->len) - s + 1); } str->len += expand; str->str[str->len] = 0; - if (str->sp >= str->len) str->sp += expand; /* Fix the end of file pointer */ + if (str->sp >= str->len) + str->sp += expand; /* Fix the end of file pointer */ return rcount; } /* The string is expanding as a result of the replacement */ /* Figure out how much expansion is going to occur and allocate a new string */ { char *ns; - int newsize; + int newsize; rcount++; - ic = count -1; + ic = count - 1; s += tokenlen; - while (ic && (c = (*match)(base,s,token,tokenlen))) { + while (ic && (c = (*match) (base, s, token, tokenlen))) { if (noquote) { - q = strpbrk(s,"\"\'"); + q = strpbrk(s, "\"\'"); if (!q) { break; } else { @@ -795,11 +801,13 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * break; } if (q2 > c) { - c = (*match)(base,q2+1,token,tokenlen); - if (!c) break; + c = (*match) (base, q2 + 1, token, tokenlen); + if (!c) + break; } - q = strpbrk(q2+1,"\"\'"); - if (!q) noquote = 0; + q = strpbrk(q2 + 1, "\"\'"); + if (!q) + noquote = 0; } } } @@ -812,9 +820,10 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * } } - expand = delta*rcount; /* Total amount of expansion for the replacement */ + expand = delta * rcount; /* Total amount of expansion for the replacement */ newsize = str->maxsize; - while ((str->len + expand) >= newsize) newsize *= 2; + while ((str->len + expand) >= newsize) + newsize *= 2; ns = (char *) DohMalloc(newsize); assert(ns); @@ -823,16 +832,16 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * /* Copy the first part of the string */ if (first > str->str) { - memcpy(t,str->str,(first - str->str)); - t += (first-str->str); + memcpy(t, str->str, (first - str->str)); + t += (first - str->str); } for (i = 0; i < rcount; i++) { - memcpy(t,rep,replen); + memcpy(t, rep, replen); t += replen; s += tokenlen; - c = (*match)(base,s,token,tokenlen); + c = (*match) (base, s, token, tokenlen); if (noquote) { - q = strpbrk(s,"\"\'"); + q = strpbrk(s, "\"\'"); if (!q) { noquote = 0; } else { @@ -844,25 +853,28 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * break; } if (q2 > c) { - c = (*match)(base,q2+1,token,tokenlen); - if (!c) break; + c = (*match) (base, q2 + 1, token, tokenlen); + if (!c) + break; } - q = strpbrk(q2+1,"\"\'"); - if (!q) noquote = 0; /* No more quotes */ + q = strpbrk(q2 + 1, "\"\'"); + if (!q) + noquote = 0; /* No more quotes */ } } } if (i < (rcount - 1)) { - memcpy(t,s,c-s); - t += (c-s); + memcpy(t, s, c - s); + t += (c - s); } else { - memcpy(t,s,(str->str + str->len) - s + 1); + memcpy(t, s, (str->str + str->len) - s + 1); } s = c; } c = str->str; str->str = ns; - if (str->sp >= str->len) str->sp += expand; + if (str->sp >= str->len) + str->sp += expand; str->len += expand; str->str[str->len] = 0; str->maxsize = newsize; @@ -875,91 +887,82 @@ replace_simple(String *str, char *token, char *rep, int flags, int count, char * * int String_replace() * ----------------------------------------------------------------------------- */ -static int -String_replace(DOH *stro, DOH *token, DOH *rep, int flags) -{ - int count = -1; - String *str = (String *) ObjData(stro); +static int String_replace(DOH *stro, DOH *token, DOH *rep, int flags) { + int count = -1; + String *str = (String *) ObjData(stro); - if (flags & DOH_REPLACE_FIRST) count = 1; + if (flags & DOH_REPLACE_FIRST) + count = 1; - if (flags & DOH_REPLACE_ID_END) { - return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier_end); - } else if (flags & DOH_REPLACE_ID_BEGIN) { - return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier_begin); - } else if (flags & DOH_REPLACE_ID) { - return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier); - } else { - return replace_simple(str,Char(token), Char(rep), flags, count, match_simple); - } + if (flags & DOH_REPLACE_ID_END) { + return replace_simple(str, Char(token), Char(rep), flags, count, match_identifier_end); + } else if (flags & DOH_REPLACE_ID_BEGIN) { + return replace_simple(str, Char(token), Char(rep), flags, count, match_identifier_begin); + } else if (flags & DOH_REPLACE_ID) { + return replace_simple(str, Char(token), Char(rep), flags, count, match_identifier); + } else { + return replace_simple(str, Char(token), Char(rep), flags, count, match_simple); + } } /* ----------------------------------------------------------------------------- * void String_chop(DOH *str) * ----------------------------------------------------------------------------- */ -static void -String_chop(DOH *so) -{ +static void String_chop(DOH *so) { char *c; String *str = (String *) ObjData(so); /* Replace trailing whitespace */ c = str->str + str->len - 1; - while ((str->len > 0) && (isspace((int)*c))) { + while ((str->len > 0) && (isspace((int) *c))) { if (str->sp >= str->len) { str->sp--; - if (*c == '\n') str->line--; + if (*c == '\n') + str->line--; } str->len--; c--; } - str->str[str->len] = 0; - assert (str->sp >= 0); + str->str[str->len] = 0; + assert(str->sp >= 0); str->hashkey = -1; } -static void -String_setfile(DOH *so, DOH *file) -{ +static void String_setfile(DOH *so, DOH *file) { DOH *fo; String *str = (String *) ObjData(so); if (!DohCheck(file)) { fo = NewString(file); Decref(fo); - } else fo = file; + } else + fo = file; Incref(fo); Delete(str->file); str->file = fo; } -static DOH * -String_getfile(DOH *so) -{ +static DOH *String_getfile(DOH *so) { String *str = (String *) ObjData(so); return str->file; } -static void -String_setline(DOH *so, int line) -{ +static void String_setline(DOH *so, int line) { String *str = (String *) ObjData(so); str->line = line; } -static int -String_getline(DOH *so) -{ +static int String_getline(DOH *so) { String *str = (String *) ObjData(so); return str->line; } static DohListMethods StringListMethods = { - 0, /* doh_getitem */ - 0, /* doh_setitem */ - String_delitem, /* doh_delitem */ - String_insert, /* doh_insitem */ - String_delslice, /* doh_delslice */ + 0, /* doh_getitem */ + 0, /* doh_setitem */ + String_delitem, /* doh_delitem */ + String_insert, /* doh_insitem */ + String_delslice, /* doh_delslice */ }; static DohFileMethods StringFileMethods = { @@ -970,7 +973,7 @@ static DohFileMethods StringFileMethods = { DohString_ungetc, String_seek, String_tell, - 0, /* close */ + 0, /* close */ }; static DohStringMethods StringStringMethods = { @@ -979,29 +982,29 @@ static DohStringMethods StringStringMethods = { }; DohObjInfo DohStringType = { - "String", /* objname */ - DelString, /* doh_del */ - CopyString, /* doh_copy */ - String_clear, /* doh_clear */ - String_str, /* doh_str */ - String_data, /* doh_data */ - String_dump, /* doh_dump */ - DohString_len, /* doh_len */ - String_hash, /* doh_hash */ - String_cmp, /* doh_cmp */ - DohString_equal, /* doh_equal */ - 0, /* doh_first */ - 0, /* doh_next */ - String_setfile, /* doh_setfile */ - String_getfile, /* doh_getfile */ - String_setline, /* doh_setline */ - String_getline, /* doh_getline */ - 0, /* doh_mapping */ - &StringListMethods, /* doh_sequence */ - &StringFileMethods, /* doh_file */ - &StringStringMethods, /* doh_string */ - 0, /* doh_position */ - 0 + "String", /* objname */ + DelString, /* doh_del */ + CopyString, /* doh_copy */ + String_clear, /* doh_clear */ + String_str, /* doh_str */ + String_data, /* doh_data */ + String_dump, /* doh_dump */ + DohString_len, /* doh_len */ + String_hash, /* doh_hash */ + String_cmp, /* doh_cmp */ + DohString_equal, /* doh_equal */ + 0, /* doh_first */ + 0, /* doh_next */ + String_setfile, /* doh_setfile */ + String_getfile, /* doh_getfile */ + String_setline, /* doh_setline */ + String_getline, /* doh_getline */ + 0, /* doh_mapping */ + &StringListMethods, /* doh_sequence */ + &StringFileMethods, /* doh_file */ + &StringStringMethods, /* doh_string */ + 0, /* doh_position */ + 0 }; @@ -1011,43 +1014,42 @@ DohObjInfo DohStringType = { * NewString(const char *c) - Create a new string * ----------------------------------------------------------------------------- */ -DOHString * -DohNewString(const DOH *so) -{ - int l = 0, max; - String *str; - char *s; - int hashkey = -1; - if (DohCheck(so)) { - str = (String *) ObjData(so); - s = (char *)String_data((String *)so); - l = s ? str->len : 0; - hashkey = str->hashkey; - } else { - s = (char *) so; - l = s ? (int) strlen(s) : 0; - } - - str = (String *) DohMalloc(sizeof(String)); - str->hashkey = hashkey; - str->sp = 0; - str->line = 1; - str->file = 0; - max = INIT_MAXSIZE; - if (s) { - if ((l+1) > max) max = l+1; - } - str->str = (char *) DohMalloc(max); - str->maxsize = max; - if (s) { - strcpy(str->str,s); - str->len = l; - str->sp = l; - } else { - str->str[0] = 0; - str->len = 0; - } - return DohObjMalloc(&DohStringType,str); +DOHString *DohNewString(const DOH *so) { + int l = 0, max; + String *str; + char *s; + int hashkey = -1; + if (DohCheck(so)) { + str = (String *) ObjData(so); + s = (char *) String_data((String *) so); + l = s ? str->len : 0; + hashkey = str->hashkey; + } else { + s = (char *) so; + l = s ? (int) strlen(s) : 0; + } + + str = (String *) DohMalloc(sizeof(String)); + str->hashkey = hashkey; + str->sp = 0; + str->line = 1; + str->file = 0; + max = INIT_MAXSIZE; + if (s) { + if ((l + 1) > max) + max = l + 1; + } + str->str = (char *) DohMalloc(max); + str->maxsize = max; + if (s) { + strcpy(str->str, s); + str->len = l; + str->sp = l; + } else { + str->str[0] = 0; + str->len = 0; + } + return DohObjMalloc(&DohStringType, str); } @@ -1055,9 +1057,7 @@ DohNewString(const DOH *so) * NewStringEmpty() - Create a new string * ----------------------------------------------------------------------------- */ -DOHString * -DohNewStringEmpty() -{ +DOHString *DohNewStringEmpty() { int max = INIT_MAXSIZE; String *str = (String *) DohMalloc(sizeof(String)); str->hashkey = 0; @@ -1068,47 +1068,45 @@ DohNewStringEmpty() str->maxsize = max; str->str[0] = 0; str->len = 0; - return DohObjMalloc(&DohStringType,str); + return DohObjMalloc(&DohStringType, str); } /* ----------------------------------------------------------------------------- * NewStringWithSize(const char *c, int len) - Create a new string * ----------------------------------------------------------------------------- */ -DOHString * -DohNewStringWithSize(const DOH *so, int len) -{ - int l = 0, max; - String *str; - char *s; - if (DohCheck(so)) { - s = (char *)String_data((String *)so); - } - else { - s = (char *) so; - } - - str = (String *) DohMalloc(sizeof(String)); - str->hashkey = -1; - str->sp = 0; - str->line = 1; - str->file = 0; - max = INIT_MAXSIZE; - if (s) { - l = (int) len; - if ((l+1) > max) max = l+1; - } - str->str = (char *) DohMalloc(max); - str->maxsize = max; - if (s) { - strncpy(str->str,s,len); - str->len = l; - str->sp = l; - } else { - str->str[0] = 0; - str->len = 0; - } - return DohObjMalloc(&DohStringType,str); +DOHString *DohNewStringWithSize(const DOH *so, int len) { + int l = 0, max; + String *str; + char *s; + if (DohCheck(so)) { + s = (char *) String_data((String *) so); + } else { + s = (char *) so; + } + + str = (String *) DohMalloc(sizeof(String)); + str->hashkey = -1; + str->sp = 0; + str->line = 1; + str->file = 0; + max = INIT_MAXSIZE; + if (s) { + l = (int) len; + if ((l + 1) > max) + max = l + 1; + } + str->str = (char *) DohMalloc(max); + str->maxsize = max; + if (s) { + strncpy(str->str, s, len); + str->len = l; + str->sp = l; + } else { + str->str[0] = 0; + str->len = 0; + } + return DohObjMalloc(&DohStringType, str); } /* ----------------------------------------------------------------------------- @@ -1117,14 +1115,12 @@ DohNewStringWithSize(const DOH *so, int len) * Create a new string from a list of objects. * ----------------------------------------------------------------------------- */ -DOHString * -DohNewStringf(const DOH *fmt, ...) -{ +DOHString *DohNewStringf(const DOH *fmt, ...) { va_list ap; DOH *r; - va_start(ap,fmt); + va_start(ap, fmt); r = NewStringEmpty(); - DohvPrintf(r,Char(fmt),ap); + DohvPrintf(r, Char(fmt), ap); va_end(ap); return (DOHString *) r; } @@ -1149,15 +1145,15 @@ int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) { } int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) { - return strncmp(Char(s1),Char(s2),n); + return strncmp(Char(s1), Char(s2), n); } char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2) { - char* p1 = Char(s1); - char* p2 = Char(s2); - return p1 == 0 || p2 == 0 || *p2 == '\0' ? p1 : strstr(p1,p2); + char *p1 = Char(s1); + char *p2 = Char(s2); + return p1 == 0 || p2 == 0 || *p2 == '\0' ? p1 : strstr(p1, p2); } char *DohStrchr(const DOHString_or_char *s1, int ch) { - return strchr(Char(s1),ch); + return strchr(Char(s1), ch); } diff --git a/SWIG/Source/DOH/void.c b/SWIG/Source/DOH/void.c index 6bf3090d6..6e0632181 100644 --- a/SWIG/Source/DOH/void.c +++ b/SWIG/Source/DOH/void.c @@ -15,8 +15,8 @@ char cvsroot_void_c[] = "$Header$"; #include "dohint.h" typedef struct { - void *ptr; - void (*del)(void *); + void *ptr; + void (*del) (void *); } VoidObj; /* ----------------------------------------------------------------------------- @@ -25,11 +25,10 @@ typedef struct { * Delete a void object. Invokes the destructor supplied at the time of creation. * ----------------------------------------------------------------------------- */ -static void -Void_delete(DOH *vo) { +static void Void_delete(DOH *vo) { VoidObj *v = (VoidObj *) ObjData(vo); if (v->del) - (*v->del)(v->ptr); + (*v->del) (v->ptr); DohFree(v); } @@ -40,10 +39,9 @@ Void_delete(DOH *vo) { * function is not copied in order to avoid potential double-free problems. * ----------------------------------------------------------------------------- */ -static DOH * -Void_copy(DOH *vo) { +static DOH *Void_copy(DOH *vo) { VoidObj *v = (VoidObj *) ObjData(vo); - return NewVoid(v->ptr,0); + return NewVoid(v->ptr, 0); } /* ----------------------------------------------------------------------------- @@ -52,36 +50,35 @@ Void_copy(DOH *vo) { * Returns the void * stored in the object. * ----------------------------------------------------------------------------- */ -static void * -Void_data(DOH *vo) { +static void *Void_data(DOH *vo) { VoidObj *v = (VoidObj *) ObjData(vo); return v->ptr; } static DohObjInfo DohVoidType = { - "VoidObj", /* objname */ - Void_delete, /* doh_del */ - Void_copy, /* doh_copy */ - 0, /* doh_clear */ - 0, /* doh_str */ - Void_data, /* doh_data */ - 0, /* doh_dump */ - 0, /* doh_len */ - 0, /* doh_hash */ - 0, /* doh_cmp */ - 0, /* doh_equal */ - 0, /* doh_first */ - 0, /* doh_next */ - 0, /* doh_setfile */ - 0, /* doh_getfile */ - 0, /* doh_setline */ - 0, /* doh_getline */ - 0, /* doh_mapping */ - 0, /* doh_sequence */ - 0, /* doh_file */ - 0, /* doh_string */ - 0, /* doh_reserved */ - 0, /* clientdata */ + "VoidObj", /* objname */ + Void_delete, /* doh_del */ + Void_copy, /* doh_copy */ + 0, /* doh_clear */ + 0, /* doh_str */ + Void_data, /* doh_data */ + 0, /* doh_dump */ + 0, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_equal */ + 0, /* doh_first */ + 0, /* doh_next */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ + 0, /* doh_mapping */ + 0, /* doh_sequence */ + 0, /* doh_file */ + 0, /* doh_string */ + 0, /* doh_reserved */ + 0, /* clientdata */ }; /* ----------------------------------------------------------------------------- @@ -90,11 +87,10 @@ static DohObjInfo DohVoidType = { * Creates a new Void object given a void * and an optional destructor function. * ----------------------------------------------------------------------------- */ -DOH * -DohNewVoid(void *obj, void (*del)(void *)) { +DOH *DohNewVoid(void *obj, void (*del) (void *)) { VoidObj *v; v = (VoidObj *) DohMalloc(sizeof(VoidObj)); v->ptr = obj; v->del = del; - return DohObjMalloc(&DohVoidType,v); + return DohObjMalloc(&DohVoidType, v); } diff --git a/SWIG/Source/Include/swigwarn.h b/SWIG/Source/Include/swigwarn.h index ad71ca98b..2d6a80029 100644 --- a/SWIG/Source/Include/swigwarn.h +++ b/SWIG/Source/Include/swigwarn.h @@ -84,53 +84,53 @@ #define WARN_PARSE_REDUNDANT 322 #define WARN_PARSE_REC_INHERITANCE 323 -#define WARN_IGNORE_OPERATOR_NEW 350 /* new */ -#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */ -#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */ -#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */ -#define WARN_IGNORE_OPERATOR_MUL 354 /* * */ -#define WARN_IGNORE_OPERATOR_DIV 355 /* / */ -#define WARN_IGNORE_OPERATOR_MOD 356 /* % */ -#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */ -#define WARN_IGNORE_OPERATOR_AND 358 /* & */ -#define WARN_IGNORE_OPERATOR_OR 359 /* | */ -#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */ -#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */ -#define WARN_IGNORE_OPERATOR_EQ 362 /* = */ -#define WARN_IGNORE_OPERATOR_LT 363 /* < */ -#define WARN_IGNORE_OPERATOR_GT 364 /* > */ -#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */ -#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */ -#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */ -#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */ -#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */ -#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */ -#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */ -#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */ -#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */ -#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */ -#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */ -#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */ -#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */ -#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */ -#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */ -#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */ -#define WARN_IGNORE_OPERATOR_LAND 381 /* && */ -#define WARN_IGNORE_OPERATOR_LOR 382 /* || */ -#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */ -#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */ -#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */ -#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */ -#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */ -#define WARN_IGNORE_OPERATOR_CALL 388 /* () */ -#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */ -#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */ -#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */ -#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */ -#define WARN_IGNORE_OPERATOR_UAND 393 /* & */ -#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */ -#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */ -#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */ +#define WARN_IGNORE_OPERATOR_NEW 350 /* new */ +#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */ +#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */ +#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */ +#define WARN_IGNORE_OPERATOR_MUL 354 /* * */ +#define WARN_IGNORE_OPERATOR_DIV 355 /* / */ +#define WARN_IGNORE_OPERATOR_MOD 356 /* % */ +#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */ +#define WARN_IGNORE_OPERATOR_AND 358 /* & */ +#define WARN_IGNORE_OPERATOR_OR 359 /* | */ +#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */ +#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */ +#define WARN_IGNORE_OPERATOR_EQ 362 /* = */ +#define WARN_IGNORE_OPERATOR_LT 363 /* < */ +#define WARN_IGNORE_OPERATOR_GT 364 /* > */ +#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */ +#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */ +#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */ +#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */ +#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */ +#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */ +#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */ +#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */ +#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */ +#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */ +#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */ +#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */ +#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */ +#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */ +#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */ +#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */ +#define WARN_IGNORE_OPERATOR_LAND 381 /* && */ +#define WARN_IGNORE_OPERATOR_LOR 382 /* || */ +#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */ +#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */ +#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */ +#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */ +#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */ +#define WARN_IGNORE_OPERATOR_CALL 388 /* () */ +#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */ +#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */ +#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */ +#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */ +#define WARN_IGNORE_OPERATOR_UAND 393 /* & */ +#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */ +#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */ +#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */ /* 394-399 are reserved */ @@ -157,10 +157,10 @@ #define WARN_TYPEMAP_TYPECHECK 467 #define WARN_TYPEMAP_THROW 468 #define WARN_TYPEMAP_DIRECTORIN_UNDEF 469 -#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */ +#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */ #define WARN_TYPEMAP_DIRECTOROUT_UNDEF 471 #define WARN_TYPEMAP_TYPECHECK_UNDEF 472 -#define WARN_TYPEMAP_DIRECTOROUT_PTR 473 +#define WARN_TYPEMAP_DIRECTOROUT_PTR 473 /* -- Fragments -- */ #define WARN_FRAGMENT_NOT_FOUND 490 @@ -171,7 +171,7 @@ #define WARN_LANG_OVERLOAD_CONSTRUCT 502 #define WARN_LANG_IDENTIFIER 503 #define WARN_LANG_RETURN_TYPE 504 -#define WARN_LANG_VARARGS 505 +#define WARN_LANG_VARARGS 505 #define WARN_LANG_VARARGS_KEYWORD 506 #define WARN_LANG_NATIVE_UNIMPL 507 #define WARN_LANG_DEREF_SHADOW 508 @@ -254,6 +254,3 @@ add an entry here */ #endif - - - diff --git a/SWIG/Source/Modules/allegrocl.cxx b/SWIG/Source/Modules/allegrocl.cxx index 0decb90bf..10af6e93f 100644 --- a/SWIG/Source/Modules/allegrocl.cxx +++ b/SWIG/Source/Modules/allegrocl.cxx @@ -18,42 +18,42 @@ char cvsroot_allegrocl_cxx[] = "$Header$"; // #define ALLEGROCL_TYPE_DEBUG // #define ALLEGROCL_CLASS_DEBUG -static File *f_cl=0; +static File *f_cl = 0; String *f_clhead = NewString(""); String *f_clwrap = NewString("(swig-in-package ())\n\n"); static File *f_cxx; -static File *f_cxx_header=0; -static File *f_cxx_wrapper=0; +static File *f_cxx_header = 0; +static File *f_cxx_wrapper = 0; -static String *module_name=0; -static String *swig_package=0; +static String *module_name = 0; +static String *swig_package = 0; -const char *identifier_converter="identifier-convert-null"; +const char *identifier_converter = "identifier-convert-null"; -static bool CWrap = true; // generate wrapper file for C code by default. most correct. +static bool CWrap = true; // generate wrapper file for C code by default. most correct. static bool Generate_Wrapper = false; static bool unique_swig_package = false; -static String *current_namespace=NewString(""); -static String *current_package=NewString(""); -static Hash *defined_namespace_packages=NewHash(); +static String *current_namespace = NewString(""); +static String *current_package = NewString(""); +static Hash *defined_namespace_packages = NewHash(); static Node *in_class = 0; -static Node *first_linked_type=0; -static Hash *defined_foreign_types=NewHash(); -static Hash *defined_foreign_ltypes=NewHash(); +static Node *first_linked_type = 0; +static Hash *defined_foreign_types = NewHash(); +static Hash *defined_foreign_ltypes = NewHash(); -static String *anon_type_name=NewString("anontype"); -static int anon_type_count=0; +static String *anon_type_name = NewString("anontype"); +static int anon_type_count = 0; // stub -String * convert_literal(String *num_param, String *type, bool try_to_split = true); +String *convert_literal(String *num_param, String *type, bool try_to_split = true); -class ALLEGROCL : public Language { +class ALLEGROCL:public Language { public: virtual void main(int argc, char *argv[]); virtual int top(Node *n); - virtual int functionWrapper(Node *n); + virtual int functionWrapper(Node *n); virtual int namespaceDeclaration(Node *n); virtual int constructorHandler(Node *n); virtual int destructorHandler(Node *n); @@ -71,17 +71,17 @@ public: virtual int templateDeclaration(Node *n); virtual int validIdentifier(String *s); private: - int emit_defun(Node *n, File* f_cl); + int emit_defun(Node *n, File *f_cl); int emit_dispatch_defun(Node *n); int emit_buffered_defuns(Node *n); int cClassHandler(Node *n); int cppClassHandler(Node *n); }; -static ALLEGROCL* allegrocl = 0; +static ALLEGROCL *allegrocl = 0; static String *trim(String *str) { char *c = Char(str); - while (*c != '\0' && isspace((int)*c)) + while (*c != '\0' && isspace((int) *c)) ++c; String *result = NewString(c); Chop(result); @@ -90,10 +90,12 @@ static String *trim(String *str) { int is_integer(String *s) { char *c = Char(s); - if(c[0] == '#' && (c[1] == 'x' || c[1] == 'o')) c+= 2; + if (c[0] == '#' && (c[1] == 'x' || c[1] == 'o')) + c += 2; - while(*c) { - if(!isdigit(*c)) return 0; + while (*c) { + if (!isdigit(*c)) + return 0; c++; } return 1; @@ -101,12 +103,13 @@ int is_integer(String *s) { String *class_from_class_or_class_ref(String *type) { SwigType *stripped = SwigType_strip_qualifiers(type); - if(SwigType_isclass(stripped)) return stripped; + if (SwigType_isclass(stripped)) + return stripped; - if(SwigType_ispointer(stripped) || SwigType_isreference(stripped)) { + if (SwigType_ispointer(stripped) || SwigType_isreference(stripped)) { // Printf(stderr,"It is a pointer/reference. Is it a class?\n"); SwigType_pop(stripped); - if(SwigType_isclass(stripped)) { + if (SwigType_isclass(stripped)) { return stripped; } } @@ -116,15 +119,13 @@ String *class_from_class_or_class_ref(String *type) { String *lookup_defined_foreign_type(String *k) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, "Looking up defined type '%s'.\n Found: '%s'\n", - k, Getattr(defined_foreign_types, k)); + Printf(stderr, "Looking up defined type '%s'.\n Found: '%s'\n", k, Getattr(defined_foreign_types, k)); #endif - + return Getattr(defined_foreign_types, k); } -String *listify_namespace(String *namespaze) -{ +String *listify_namespace(String *namespaze) { if (Len(namespaze) == 0) return NewString("()"); String *result = NewStringf("(\"%s\")", namespaze); @@ -134,18 +135,15 @@ String *listify_namespace(String *namespaze) String *namespaced_name(Node *n, String *ns = current_namespace) { - return NewStringf("%s%s%s", - ns, (Len(ns) != 0) ? "::" : "", - Getattr(n,"sym:name")); + return NewStringf("%s%s%s", ns, (Len(ns) != 0) ? "::" : "", Getattr(n, "sym:name")); } // "Namespace::Nested::Class2::Baz" -> "Baz" -static String *strip_namespaces(String *str) -{ +static String *strip_namespaces(String *str) { char *result = Char(str); String *stripped_one; while ((stripped_one = Strstr(result, "::"))) - result = Char(stripped_one)+2; + result = Char(stripped_one) + 2; return NewString(result); } @@ -156,86 +154,82 @@ static String *namespace_of(String *str) { String *stripped_one; while ((stripped_one = Strstr(p, "::"))) { - p = Char(stripped_one)+2; + p = Char(stripped_one) + 2; } - if(p > start) { + if (p > start) { int len = p - start - 1; - result = (char *)malloc(len); - strncpy(result, start, len-1); - result[len-1] = 0; + result = (char *) malloc(len); + strncpy(result, start, len - 1); + result[len - 1] = 0; } return Char(result); } void add_linked_type(Node *n) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), - Getattr(n,"storage"), Getattr(n,"name"),n); + Printf(stderr, "Adding linked node of type: %s(%s) %s(%x)\n\n", nodeType(n), Getattr(n, "storage"), Getattr(n, "name"), n); #endif - if(!first_linked_type) { + if (!first_linked_type) { first_linked_type = n; - Setattr(n,"allegrocl:last_linked_type",n); + Setattr(n, "allegrocl:last_linked_type", n); } else { - Node *t = Getattr(first_linked_type,"allegrocl:last_linked_type"); - Setattr(t,"allegrocl:next_linked_type",n); - Setattr(first_linked_type,"allegrocl:last_linked_type",n); + Node *t = Getattr(first_linked_type, "allegrocl:last_linked_type"); + Setattr(t, "allegrocl:next_linked_type", n); + Setattr(first_linked_type, "allegrocl:last_linked_type", n); } } void replace_linked_type(Node *old, Node *new_node) { - Node *prev = Getattr(old,"allegrocl:prev_linked_type"); - - Setattr(new_node,"allegrocl:next_linked_type", - Getattr(old,"allegrocl:next_linked_type")); - if(prev) Setattr(prev,"allegrocl:next_linked_type",new_node); - Delattr(old,"allegrocl:next_linked_type"); - Delattr(old,"allegrocl:prev_linked_type"); + Node *prev = Getattr(old, "allegrocl:prev_linked_type"); + + Setattr(new_node, "allegrocl:next_linked_type", Getattr(old, "allegrocl:next_linked_type")); + if (prev) + Setattr(prev, "allegrocl:next_linked_type", new_node); + Delattr(old, "allegrocl:next_linked_type"); + Delattr(old, "allegrocl:prev_linked_type"); // check if we're replacing the first link. - if(first_linked_type == old) { + if (first_linked_type == old) { first_linked_type = new_node; - Setattr(first_linked_type,"allegrocl:last_linked_type", - Getattr(old,"allegrocl:last_linked_type")); + Setattr(first_linked_type, "allegrocl:last_linked_type", Getattr(old, "allegrocl:last_linked_type")); } - // check if we're replacing the last link. - if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old) - Setattr(first_linked_type,"allegrocl:last_linked_type",new_node); + if (Getattr(first_linked_type, "allegrocl:last_linked_type") == old) + Setattr(first_linked_type, "allegrocl:last_linked_type", new_node); } void insert_linked_type_at(Node *old, Node *new_node, int before = 1) { Node *p = 0; - if(!first_linked_type) { + if (!first_linked_type) { add_linked_type(new_node); return; } - if(!before) { - Setattr(new_node,"allegrocl:next_linked_type", - Getattr(old,"allegrocl:next_linked_type")); - Setattr(old,"allegrocl:next_linked_type",new_node); - if(Getattr(first_linked_type,"allegrocl:last_linked_type") == old) - Setattr(first_linked_type,"allegrocl:last_linked_type",new_node); + if (!before) { + Setattr(new_node, "allegrocl:next_linked_type", Getattr(old, "allegrocl:next_linked_type")); + Setattr(old, "allegrocl:next_linked_type", new_node); + if (Getattr(first_linked_type, "allegrocl:last_linked_type") == old) + Setattr(first_linked_type, "allegrocl:last_linked_type", new_node); } else { Node *c = first_linked_type; - while(c) { - if(c == old) { + while (c) { + if (c == old) { break; } else { p = c; - c = Getattr(c,"allegrocl:next_linked_type"); + c = Getattr(c, "allegrocl:next_linked_type"); } } - if(c == old) { - Setattr(new_node,"allegrocl:next_linked_type",c); - if(first_linked_type == c) { + if (c == old) { + Setattr(new_node, "allegrocl:next_linked_type", c); + if (first_linked_type == c) { first_linked_type = new_node; - Setattr(first_linked_type,"allegrocl:last_linked_type", - Getattr(c,"allegrocl:last_linked_type")); - Delattr(c,"allegrocl:last_linked_type"); + Setattr(first_linked_type, "allegrocl:last_linked_type", Getattr(c, "allegrocl:last_linked_type")); + Delattr(c, "allegrocl:last_linked_type"); } - if(p) Setattr(p,"allegrocl:next_linked_type",new_node); + if (p) + Setattr(p, "allegrocl:next_linked_type", new_node); } } } @@ -245,58 +239,56 @@ Node *find_linked_type_by_name(String *name) { Node *c = first_linked_type; // Printf(stderr,"in find_linked_type_by_name '%s'...", name); - while(c) { - String *key = Getattr(c,"name"); - if(!Strcmp(key,name)) { + while (c) { + String *key = Getattr(c, "name"); + if (!Strcmp(key, name)) { break; } else { p = c; - c = Getattr(c,"allegrocl:next_linked_type"); + c = Getattr(c, "allegrocl:next_linked_type"); } } // Printf(stderr,"exit find_linked_type_by_name.\n"); - if(p && c) Setattr(c,"allegrocl:prev_linked_type",p); + if (p && c) + Setattr(c, "allegrocl:prev_linked_type", p); // Printf(stderr,"find_linked_type_by_name: DONE\n"); return c; } Node *get_primary_synonym_of(Node *n) { - Node *p = Getattr(n,"allegrocl:synonym-of"); + Node *p = Getattr(n, "allegrocl:synonym-of"); Node *prim = n; // Printf(stderr, "getting primary synonym of %x\n", n); - while(p) { + while (p) { // Printf(stderr, " found one! %x\n", p); prim = p; - p = Getattr(p,"allegrocl:synonym-of"); + p = Getattr(p, "allegrocl:synonym-of"); } // Printf(stderr,"get_primary_syn: DONE. returning %s(%x)\n", Getattr(prim,"name"),prim); return prim; } -void add_forward_referenced_type(Node *n, int overwrite = 0) -{ - String *k = Getattr(n,"name"); +void add_forward_referenced_type(Node *n, int overwrite = 0) { + String *k = Getattr(n, "name"); String *name = Getattr(n, "sym:name"); String *ns = listify_namespace(current_namespace); String *val = Getattr(defined_foreign_types, k); - if(!val || overwrite) { + if (!val || overwrite) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"Adding forward reference for %s (overwrite=%d)\n", - k, overwrite); -#endif - Setattr(defined_foreign_types,Copy(k),NewString("forward-reference")); + Printf(stderr, "Adding forward reference for %s (overwrite=%d)\n", k, overwrite); +#endif + Setattr(defined_foreign_types, Copy(k), NewString("forward-reference")); - String *mangled_lname_gen = - NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns); + String *mangled_lname_gen = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns); - Setattr(defined_foreign_ltypes,Copy(k),mangled_lname_gen); + Setattr(defined_foreign_ltypes, Copy(k), mangled_lname_gen); // Printf(f_cl, ";; forward reference stub\n" // "(swig-def-foreign-class \"%s\" (ff:foreign-pointer) (:class ))\n\n" - // , name); + // , name); #ifdef ALLEGROCL_CLASS_DEBUG Printf(stderr, "Linking forward reference type = %s(%x)\n", k, n); @@ -305,98 +297,93 @@ void add_forward_referenced_type(Node *n, int overwrite = 0) } } -void add_defined_foreign_type(Node *n, - int overwrite=0, - String *k=0, - String *name=0, - String *ns=current_namespace) { +void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0, String *name = 0, String *ns = current_namespace) { String *val; String *ns_list = listify_namespace(ns); - String *templated = n ? Getattr(n,"template") : 0; - String *cDeclName = n ? Getattr(n,"classDeclaration:name") : 0; + String *templated = n ? Getattr(n, "template") : 0; + String *cDeclName = n ? Getattr(n, "classDeclaration:name") : 0; #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", - n, overwrite, k, name, ns); - Printf(stderr," templated = '%x', classDecl = '%x'\n", templated, cDeclName); + Printf(stderr, "IN A-D-F-T. (n=%x, ow=%d, k=%s, name=%s, ns=%s\n", n, overwrite, k, name, ns); + Printf(stderr, " templated = '%x', classDecl = '%x'\n", templated, cDeclName); #endif - if(n) { - if(!name) name=Getattr(n,"sym:name"); - if(!name) name = Getattr(n,"name"); - if(templated) { + if (n) { + if (!name) + name = Getattr(n, "sym:name"); + if (!name) + name = Getattr(n, "name"); + if (templated) { k = namespaced_name(n); } else { - String *kind_of_type = Getattr(n,"kind"); + String *kind_of_type = Getattr(n, "kind"); /* - For typedefs of the form: + For typedefs of the form: - typedef __xxx { ... } xxx; + typedef __xxx { ... } xxx; - add_defined_foreign_type will be called once via classHandler - to define the type for 'struct __xxx', and once via typedefHandler - to associate xxx with 'struct __xxx'. + add_defined_foreign_type will be called once via classHandler + to define the type for 'struct __xxx', and once via typedefHandler + to associate xxx with 'struct __xxx'. - We create the following type to identifier mappings: + We create the following type to identifier mappings: - struct __xxx -> (swig-insert-id "xxx") via classHand - xxx -> (swig-insert-id "xxx") via typedefHand + struct __xxx -> (swig-insert-id "xxx") via classHand + xxx -> (swig-insert-id "xxx") via typedefHand - and all references to this typedef'd struct will appear in - generated code as 'xxx'. For non-typedef'd structs, the - classHand mapping will be + and all references to this typedef'd struct will appear in + generated code as 'xxx'. For non-typedef'd structs, the + classHand mapping will be - struct __xxx -> (swig-insert-id "__xxx") - */ + struct __xxx -> (swig-insert-id "__xxx") + */ // Swig_print_node(n); - String *unnamed = Getattr(n,"unnamed"); - if(kind_of_type && (!Strcmp(kind_of_type,"struct") - || !Strcmp(kind_of_type,"union")) && cDeclName - && !unnamed) { + String *unnamed = Getattr(n, "unnamed"); + if (kind_of_type && (!Strcmp(kind_of_type, "struct") + || !Strcmp(kind_of_type, "union")) && cDeclName && !unnamed) { k = NewStringf("%s %s", kind_of_type, cDeclName); } else { - if (!Strcmp(nodeType(n),"enum") && unnamed) { + if (!Strcmp(nodeType(n), "enum") && unnamed) { name = NewStringf("%s%d", anon_type_name, anon_type_count++); k = NewStringf("enum %s", name); - Setattr(n,"allegrocl:name",name); + Setattr(n, "allegrocl:name", name); } else { - k = k ? k : Getattr(n,"name"); + k = k ? k : Getattr(n, "name"); } } } // Swig_print_node(n); } - if(SwigType_istemplate(name)) { + if (SwigType_istemplate(name)) { String *temp = strip_namespaces(SwigType_templateprefix(name)); name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name)); } - + val = lookup_defined_foreign_type(k); int is_fwd_ref = 0; - if(val) is_fwd_ref = !Strcmp(val,"forward-reference"); + if (val) + is_fwd_ref = !Strcmp(val, "forward-reference"); - if(!val || overwrite || is_fwd_ref) { + if (!val || overwrite || is_fwd_ref) { #ifdef ALLEGROCL_CLASS_DEBUG Printf(stderr, "Adding defined type '%s' = '%s' '%s' (overwrite=%d, in-class=%d)\n", k, ns, name, overwrite, in_class); #endif - String *mangled_name_gen = - NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", name, ns_list); - String *mangled_lname_gen = - NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns_list); + String *mangled_name_gen = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", name, ns_list); + String *mangled_lname_gen = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", name, ns_list); - Setattr(defined_foreign_types,Copy(k),Copy(mangled_name_gen)); - Setattr(defined_foreign_ltypes,Copy(k),Copy(mangled_lname_gen)); + Setattr(defined_foreign_types, Copy(k), Copy(mangled_name_gen)); + Setattr(defined_foreign_ltypes, Copy(k), Copy(mangled_lname_gen)); - if(CPlusPlus) { + if (CPlusPlus) { bool cpp_struct = Strstr(k, "struct ") ? true : false; - bool cpp_union = Strstr(k, "union ") ? true : false; + bool cpp_union = Strstr(k, "union ") ? true : false; String *cpp_type = 0; - if(cpp_struct) { + if (cpp_struct) { cpp_type = Copy(k); Replaceall(cpp_type, "struct ", ""); } else if (cpp_union) { @@ -404,210 +391,207 @@ void add_defined_foreign_type(Node *n, Replaceall(cpp_type, "union ", ""); } - if(cpp_struct || cpp_union) { + if (cpp_struct || cpp_union) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, " Also adding defined type '%s' = '%s' '%s' (overwrite=%d)\n", - cpp_type, ns, name, overwrite); + Printf(stderr, " Also adding defined type '%s' = '%s' '%s' (overwrite=%d)\n", cpp_type, ns, name, overwrite); #endif - Setattr(defined_foreign_types,Copy(cpp_type),Copy(mangled_name_gen)); - Setattr(defined_foreign_ltypes,Copy(cpp_type),Copy(mangled_lname_gen)); + Setattr(defined_foreign_types, Copy(cpp_type), Copy(mangled_name_gen)); + Setattr(defined_foreign_ltypes, Copy(cpp_type), Copy(mangled_lname_gen)); } } #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"looking to add %s/%s(%x) to linked_type_list...\n", k, name, n); + Printf(stderr, "looking to add %s/%s(%x) to linked_type_list...\n", k, name, n); #endif - if(is_fwd_ref) { - // Printf(stderr,"*** 1\n"); - add_linked_type(n); - } else { - // Printf(stderr,"*** 1-a\n"); - if(SwigType_istemplate(k)) { - SwigType *resolved = SwigType_typedef_resolve_all(k); - // Printf(stderr,"*** 1-b\n"); - Node *match = find_linked_type_by_name(resolved); - Node *new_node = 0; - // Printf(stderr, "*** temp-1\n"); - if (n) { - new_node = n; - } else { + if (is_fwd_ref) { + // Printf(stderr,"*** 1\n"); + add_linked_type(n); + } else { + // Printf(stderr,"*** 1-a\n"); + if (SwigType_istemplate(k)) { + SwigType *resolved = SwigType_typedef_resolve_all(k); + // Printf(stderr,"*** 1-b\n"); + Node *match = find_linked_type_by_name(resolved); + Node *new_node = 0; + // Printf(stderr, "*** temp-1\n"); + if (n) { + new_node = n; + } else { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"Creating a new templateInst:\n"); - Printf(stderr," name = %s\n", resolved); - Printf(stderr," sym:name = %s\n", name); - Printf(stderr," real-name = %s\n", k); - Printf(stderr," type = %s\n", resolved); - Printf(stderr," ns = %s\n\n", ns); + Printf(stderr, "Creating a new templateInst:\n"); + Printf(stderr, " name = %s\n", resolved); + Printf(stderr, " sym:name = %s\n", name); + Printf(stderr, " real-name = %s\n", k); + Printf(stderr, " type = %s\n", resolved); + Printf(stderr, " ns = %s\n\n", ns); #endif - new_node = NewHash(); - Setattr(new_node,"nodeType","templateInst"); - Setattr(new_node,"name",Copy(resolved)); - Setattr(new_node,"sym:name",Copy(name)); - Setattr(new_node,"real-name",Copy(k)); - Setattr(new_node,"type",Copy(resolved)); - Setattr(new_node,"allegrocl:namespace",ns); - Setattr(new_node,"allegrocl:package",ns); - } + new_node = NewHash(); + Setattr(new_node, "nodeType", "templateInst"); + Setattr(new_node, "name", Copy(resolved)); + Setattr(new_node, "sym:name", Copy(name)); + Setattr(new_node, "real-name", Copy(k)); + Setattr(new_node, "type", Copy(resolved)); + Setattr(new_node, "allegrocl:namespace", ns); + Setattr(new_node, "allegrocl:package", ns); + } - if(!match) { - if(!Strcmp(nodeType(new_node),"templateInst") && in_class) { - /* this is an implicit template instantiation found while - walking a class. need to insert this into the - linked_type list before the current class definition */ + if (!match) { + if (!Strcmp(nodeType(new_node), "templateInst") && in_class) { + /* this is an implicit template instantiation found while + walking a class. need to insert this into the + linked_type list before the current class definition */ #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"trying to insert a templateInst before a class\n"); + Printf(stderr, "trying to insert a templateInst before a class\n"); #endif - insert_linked_type_at(in_class,new_node); + insert_linked_type_at(in_class, new_node); #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"DID IT!\n"); + Printf(stderr, "DID IT!\n"); #endif - } else { - // Printf(stderr,"*** 3\n"); - add_linked_type(new_node); - } - Setattr(new_node,"allegrocl:synonym:is-primary","1"); } else { - // a synonym type was found (held in variable 'match') - // Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match); - if(new_node == match) Printf(stderr,"Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node,"name")); - Setattr(new_node,"allegrocl:synonym-of",match); - // Printf(stderr,"*** 4\n"); + // Printf(stderr,"*** 3\n"); add_linked_type(new_node); } + Setattr(new_node, "allegrocl:synonym:is-primary", "1"); } else { - Node *match; + // a synonym type was found (held in variable 'match') + // Printf(stderr, "setting primary synonym of %x to %x\n", new_node, match); + if (new_node == match) + Printf(stderr, "Hey-4 * - '%s' is a synonym of iteself!\n", Getattr(new_node, "name")); + Setattr(new_node, "allegrocl:synonym-of", match); + // Printf(stderr,"*** 4\n"); + add_linked_type(new_node); + } + } else { + Node *match; - if(!Strcmp(nodeType(n),"cdecl") && - !Strcmp(Getattr(n,"storage"),"typedef")) { - SwigType *type = SwigType_strip_qualifiers(Getattr(n,"type")); + if (!Strcmp(nodeType(n), "cdecl") && !Strcmp(Getattr(n, "storage"), "typedef")) { + SwigType *type = SwigType_strip_qualifiers(Getattr(n, "type")); #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"Examining typedef '%s' for class references.\n", type); + Printf(stderr, "Examining typedef '%s' for class references.\n", type); #endif - if(SwigType_isclass(type)) { + if (SwigType_isclass(type)) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"Found typedef of a class '%s'\n", type); + Printf(stderr, "Found typedef of a class '%s'\n", type); #endif - /* - For the following parsed expression: + /* + For the following parsed expression: - typedef struct __xxx { ... } xxx; + typedef struct __xxx { ... } xxx; - if n is of kind "class" (defining the class 'struct __xxx' - then we add n to the linked type list. + if n is of kind "class" (defining the class 'struct __xxx' + then we add n to the linked type list. - if n is "cdecl" node of storage "typedef" (to note - that xxx is equivalent to 'struct __xxx' then we don't - want to add this node to the linked type list. - */ - String *defined_type = lookup_defined_foreign_type(type); - String *defined_key_type = lookup_defined_foreign_type(k); + if n is "cdecl" node of storage "typedef" (to note + that xxx is equivalent to 'struct __xxx' then we don't + want to add this node to the linked type list. + */ + String *defined_type = lookup_defined_foreign_type(type); + String *defined_key_type = lookup_defined_foreign_type(k); - if((Strstr(type,"struct ") || Strstr(type,"union ")) - && defined_type && !Strcmp(defined_type,defined_key_type)) { - // mark as a synonym but don't add to linked_type list - // Printf(stderr,"*** 4.8\n"); - Setattr(n,"allegrocl:synonym","1"); - } else { - SwigType *lookup_type = SwigType_istemplate(type) ? - SwigType_typedef_resolve_all(type) : Copy(type); - match = find_linked_type_by_name(lookup_type); - if(match) { - Setattr(n,"allegrocl:synonym","1"); - Setattr(n,"allegrocl:synonym-of",match); - Setattr(n,"real-name",Copy(lookup_type)); - - // Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match); - // if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match); - // Printf(stderr,"*** 5\n"); - add_linked_type(n); - } else { -#ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"Creating classfoward node for struct stub in typedef.\n"); -#endif - Node *new_node = NewHash(); - String *symname = Copy(type); - Replaceall(symname,"struct ",""); - Setattr(new_node,"nodeType","classforward"); - Setattr(new_node,"name",Copy(type)); - Setattr(new_node,"sym:name",symname); - Setattr(new_node,"allegrocl:namespace",ns); - Setattr(new_node,"allegrocl:package",ns); - - String *mangled_new_name = - NewStringf("#.(swig-insert-id \"%s\" %s)", symname, ns_list); - String *mangled_new_lname = - NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", symname, ns_list); - Setattr(defined_foreign_types,Copy(symname),Copy(mangled_new_name)); - Setattr(defined_foreign_ltypes,Copy(symname),Copy(mangled_new_lname)); - - // Printf(stderr,"Weird! Can't find the type!\n"); - add_forward_referenced_type(new_node); - add_linked_type(new_node); - - Setattr(n,"allegrocl:synonym","1"); - Setattr(n,"allegrocl:synonym-of",new_node); - - add_linked_type(n); - } - Delete(lookup_type); - } + if ((Strstr(type, "struct ") || Strstr(type, "union ")) + && defined_type && !Strcmp(defined_type, defined_key_type)) { + // mark as a synonym but don't add to linked_type list + // Printf(stderr,"*** 4.8\n"); + Setattr(n, "allegrocl:synonym", "1"); } else { - // check if it's a pointer or reference to a class. - // Printf(stderr,"Checking if '%s' is a p. or r. to a class\n", type); - String *class_ref = class_from_class_or_class_ref(type); - if(class_ref) { - match = find_linked_type_by_name(class_ref); - Setattr(n,"allegrocl:synonym","1"); - Setattr(n,"allegrocl:synonym-of",match); + SwigType *lookup_type = SwigType_istemplate(type) ? SwigType_typedef_resolve_all(type) : Copy(type); + match = find_linked_type_by_name(lookup_type); + if (match) { + Setattr(n, "allegrocl:synonym", "1"); + Setattr(n, "allegrocl:synonym-of", match); + Setattr(n, "real-name", Copy(lookup_type)); + + // Printf(stderr, "*** pre-5: found match of '%s'(%x)\n", Getattr(match,"name"),match); + // if(n == match) Printf(stderr, "Hey-5 *** setting synonym of %x to %x\n", n, match); + // Printf(stderr,"*** 5\n"); + add_linked_type(n); + } else { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, "Creating classfoward node for struct stub in typedef.\n"); +#endif + Node *new_node = NewHash(); + String *symname = Copy(type); + Replaceall(symname, "struct ", ""); + Setattr(new_node, "nodeType", "classforward"); + Setattr(new_node, "name", Copy(type)); + Setattr(new_node, "sym:name", symname); + Setattr(new_node, "allegrocl:namespace", ns); + Setattr(new_node, "allegrocl:package", ns); + + String *mangled_new_name = NewStringf("#.(swig-insert-id \"%s\" %s)", symname, ns_list); + String *mangled_new_lname = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", symname, ns_list); + Setattr(defined_foreign_types, Copy(symname), Copy(mangled_new_name)); + Setattr(defined_foreign_ltypes, Copy(symname), Copy(mangled_new_lname)); + + // Printf(stderr,"Weird! Can't find the type!\n"); + add_forward_referenced_type(new_node); + add_linked_type(new_node); + + Setattr(n, "allegrocl:synonym", "1"); + Setattr(n, "allegrocl:synonym-of", new_node); + add_linked_type(n); } - } - Delete(type); - // synonym types have already been added. - // Printf(stderr,"*** 10\n"); - if(!Getattr(n,"allegrocl:synonym")) add_linked_type(n); - } else if(Getattr(n,"template")) { - // Printf(stderr, "this is a class template node(%s)\n", nodeType(n)); - String *resolved = SwigType_typedef_resolve_all(Getattr(n,"name")); - -#ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, " looking up %s for linked type match with %s...\n", Getattr(n,"sym:name"), resolved); -#endif - match = find_linked_type_by_name(resolved); - if (!match) { -#ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n,"name"),n); -#endif - add_linked_type(n); - } else { - Node *primary = get_primary_synonym_of(match); - - Setattr(n,"allegrocl:synonym:is-primary","1"); - Delattr(primary,"allegrocl:synonym:is-primary"); - if(n == match) Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match); - Setattr(primary,"allegrocl:synonym-of",n); - // Printf(stderr,"*** 7\n"); - add_linked_type(n); + Delete(lookup_type); } } else { + // check if it's a pointer or reference to a class. + // Printf(stderr,"Checking if '%s' is a p. or r. to a class\n", type); + String *class_ref = class_from_class_or_class_ref(type); + if (class_ref) { + match = find_linked_type_by_name(class_ref); + Setattr(n, "allegrocl:synonym", "1"); + Setattr(n, "allegrocl:synonym-of", match); + add_linked_type(n); + } + } + Delete(type); + // synonym types have already been added. + // Printf(stderr,"*** 10\n"); + if (!Getattr(n, "allegrocl:synonym")) + add_linked_type(n); + } else if (Getattr(n, "template")) { + // Printf(stderr, "this is a class template node(%s)\n", nodeType(n)); + String *resolved = SwigType_typedef_resolve_all(Getattr(n, "name")); + #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "linking type '%s'(%x)\n", k, n); + Printf(stderr, " looking up %s for linked type match with %s...\n", Getattr(n, "sym:name"), resolved); #endif - // Printf(stderr,"*** 8\n"); + match = find_linked_type_by_name(resolved); + if (!match) { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, "found no implicit instantiation of %%template node %s(%x)\n", Getattr(n, "name"), n); +#endif + add_linked_type(n); + } else { + Node *primary = get_primary_synonym_of(match); + + Setattr(n, "allegrocl:synonym:is-primary", "1"); + Delattr(primary, "allegrocl:synonym:is-primary"); + if (n == match) + Printf(stderr, "Hey-7 * setting synonym of %x to %x\n (match = %x)", primary, n, match); + Setattr(primary, "allegrocl:synonym-of", n); + // Printf(stderr,"*** 7\n"); add_linked_type(n); } + } else { +#ifdef ALLEGROCL_CLASS_DEBUG + Printf(stderr, "linking type '%s'(%x)\n", k, n); +#endif + // Printf(stderr,"*** 8\n"); + add_linked_type(n); } } - Delete(mangled_name_gen); - Delete(mangled_lname_gen); + } + Delete(mangled_name_gen); + Delete(mangled_lname_gen); } else { - Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), - "Attempting to store a foreign type that exists: %s (%s)\n", k, val); + Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Attempting to store a foreign type that exists: %s (%s)\n", k, val); } Delete(ns_list); #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"OUT A-D-F-T\n"); + Printf(stderr, "OUT A-D-F-T\n"); #endif } @@ -615,7 +599,7 @@ void note_implicit_template_instantiation(SwigType *t) { // the namespace of the implicit instantiation is not necessarily // current_namespace. Attempt to cull this from the type. #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr,"culling namespace of '%s' from '%s'\n", t, SwigType_templateprefix(t)); + Printf(stderr, "culling namespace of '%s' from '%s'\n", t, SwigType_templateprefix(t)); #endif String *implicit_ns = namespace_of(SwigType_templateprefix(t)); add_defined_foreign_type(0, 0, t, t, implicit_ns ? implicit_ns : current_namespace); @@ -625,7 +609,7 @@ String *get_ffi_type(SwigType *ty, const String_or_char *name) { /* lookup defined foreign type. if it exists, it will return a form suitable for placing into lisp code to generate the def-foreign-type name */ - + #ifdef ALLEGROCL_TYPE_DEBUG Printf(stderr, "inside g_f_t: looking up '%s' '%s'\n", ty, name); #endif @@ -636,8 +620,7 @@ String *get_ffi_type(SwigType *ty, const String_or_char *name) { #ifdef ALLEGROCL_TYPE_DEBUG Printf(stderr, "found_type '%s'\n", found_type); #endif - return (Strcmp(found_type,"forward-reference") ? - Copy(found_type) : NewString(":void")); + return (Strcmp(found_type, "forward-reference") ? Copy(found_type) : NewString(":void")); } else { Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); @@ -645,12 +628,12 @@ String *get_ffi_type(SwigType *ty, const String_or_char *name) { String *typespec = Getattr(typemap, "code"); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, "found typemap '%s'\n", typespec); + Printf(stderr, "found typemap '%s'\n", typespec); #endif return NewString(typespec); - } + } - if(SwigType_istemplate(ty)) { + if (SwigType_istemplate(ty)) { note_implicit_template_instantiation(ty); return Copy(lookup_defined_foreign_type(ty)); } @@ -661,8 +644,7 @@ String *get_ffi_type(SwigType *ty, const String_or_char *name) { String *lookup_defined_foreign_ltype(String *l) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, "Looking up defined ltype '%s'.\n Found: '%s'\n", - l, Getattr(defined_foreign_ltypes, l)); + Printf(stderr, "Looking up defined ltype '%s'.\n Found: '%s'\n", l, Getattr(defined_foreign_ltypes, l)); #endif return Getattr(defined_foreign_ltypes, l); } @@ -675,22 +657,22 @@ String *internal_compose_foreign_type(SwigType *ty) { String *ffiType = NewString(""); // for a function type, need to walk the parm list. - while(Len(ty) != 0) { + while (Len(ty) != 0) { tok = SwigType_pop(ty); - if(SwigType_isfunction(tok)) { + if (SwigType_isfunction(tok)) { // Generate Function wrapper Printf(ffiType, "(:function "); // walk parm list List *pl = SwigType_parmlist(tok); - Printf(ffiType, "("); // start parm list - for (Iterator i=First(pl); i.item; i = Next(i)) { - SwigType *f_arg = SwigType_strip_qualifiers(i.item); - Printf(ffiType, "%s ", internal_compose_foreign_type(f_arg)); - Delete(f_arg); + Printf(ffiType, "("); // start parm list + for (Iterator i = First(pl); i.item; i = Next(i)) { + SwigType *f_arg = SwigType_strip_qualifiers(i.item); + Printf(ffiType, "%s ", internal_compose_foreign_type(f_arg)); + Delete(f_arg); } - Printf(ffiType, ")"); // end parm list. + Printf(ffiType, ")"); // end parm list. // do function return type. Printf(ffiType, " %s)", internal_compose_foreign_type(ty)); @@ -700,52 +682,51 @@ String *internal_compose_foreign_type(SwigType *ty) { } else if (SwigType_isarray(tok)) { Printf(ffiType, "(:array %s", internal_compose_foreign_type(ty)); String *atype = NewString("int"); - String *dim = convert_literal(SwigType_array_getdim(tok, 0),atype); + String *dim = convert_literal(SwigType_array_getdim(tok, 0), atype); Delete(atype); - if(is_integer(dim)) { + if (is_integer(dim)) { Printf(ffiType, " %s)", dim); - } else { - Printf(ffiType, " #| %s |#)", SwigType_array_getdim(tok,0)); - } + } else { + Printf(ffiType, " #| %s |#)", SwigType_array_getdim(tok, 0)); + } } else if (SwigType_ismemberpointer(tok)) { // temp Printf(ffiType, "(* %s)", internal_compose_foreign_type(ty)); } else { String *res = get_ffi_type(tok, ""); if (res) { - Printf(ffiType, "%s", res); + Printf(ffiType, "%s", res); } else { - SwigType *resolved_type = SwigType_typedef_resolve(tok); - if(resolved_type) { + SwigType *resolved_type = SwigType_typedef_resolve(tok); + if (resolved_type) { res = get_ffi_type(resolved_type, ""); - if(res) { + if (res) { } else { res = internal_compose_foreign_type(resolved_type); } - if(res) Printf(ffiType, "%s", res); + if (res) + Printf(ffiType, "%s", res); } - // while(resolved_type) { -// // the resolved_type may expand into something like p.NS1::NS2::SomeType -// // for which get_ffi_type will not find any match (due to the p.). -// // Printf(stderr, "\n in resolved type loop on '%s'\n", resolved_type); +// // the resolved_type may expand into something like p.NS1::NS2::SomeType +// // for which get_ffi_type will not find any match (due to the p.). +// // Printf(stderr, "\n in resolved type loop on '%s'\n", resolved_type); // res = get_ffi_type(resolved_type, ""); // if (res) { // Printf(ffiType, "%s", res); // break; // } else { -// resolved_type = SwigType_typedef_resolve(resolved_type); +// resolved_type = SwigType_typedef_resolve(resolved_type); // } // } - if(!res) { - if (Strstr(tok,"struct ")) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(tok), Getline(tok), - "Unable to find definition of '%s', assuming forward reference.\n", tok); + if (!res) { + if (Strstr(tok, "struct ")) { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(tok), Getline(tok), "Unable to find definition of '%s', assuming forward reference.\n", tok); } else { - Printf(stderr,"Unable to compose foreign type of: '%s'\n", tok); + Printf(stderr, "Unable to compose foreign type of: '%s'\n", tok); } - Printf(ffiType, "(* :void)"); - } + Printf(ffiType, "(* :void)"); + } } } } @@ -755,7 +736,7 @@ String *internal_compose_foreign_type(SwigType *ty) { String *compose_foreign_type(SwigType *ty) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"compose_foreign_type: ENTER (%s)...\n ", ty); + Printf(stderr, "compose_foreign_type: ENTER (%s)...\n ", ty); #endif /* should we allow named lookups in the typemap here? */ SwigType *temp = SwigType_strip_qualifiers(ty); @@ -763,7 +744,7 @@ String *compose_foreign_type(SwigType *ty) { Delete(temp); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"compose_foreign_type: EXIT (%s)\n ", res); + Printf(stderr, "compose_foreign_type: EXIT (%s)\n ", res); #endif return res; @@ -773,29 +754,26 @@ void update_package_if_needed(Node *n, File *f = f_clwrap) { #ifdef ALLEGROCL_DEBUG Printf(stderr, "update_package: ENTER... \n"); Printf(stderr, " current_package = '%s'\n", current_package); - Printf(stderr, " node_package = '%s'\n", Getattr(n,"allegrocl:package")); - Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n,"name")); + Printf(stderr, " node_package = '%s'\n", Getattr(n, "allegrocl:package")); + Printf(stderr, " node(%x) = '%s'\n", n, Getattr(n, "name")); #endif - String *node_package = Getattr(n,"allegrocl:package"); - if(Strcmp(current_package,node_package)) { + String *node_package = Getattr(n, "allegrocl:package"); + if (Strcmp(current_package, node_package)) { String *lispy_package = listify_namespace(node_package); Delete(current_package); current_package = Copy(node_package); - Printf(f,"\n(swig-in-package %s)\n", lispy_package); + Printf(f, "\n(swig-in-package %s)\n", lispy_package); Delete(lispy_package); } #ifdef ALLEGROCL_DEBUG - Printf(stderr,"update_package: EXIT.\n"); + Printf(stderr, "update_package: EXIT.\n"); #endif } -static String *mangle_name(Node *n, char const *prefix = "ACL", - String *ns = current_namespace) -{ - String* suffix = Getattr(n, "sym:overname"); - String *pre_mangled_name = - NewStringf("%s_%s__%s%s", prefix, ns, Getattr(n, "sym:name"), suffix); +static String *mangle_name(Node *n, char const *prefix = "ACL", String *ns = current_namespace) { + String *suffix = Getattr(n, "sym:overname"); + String *pre_mangled_name = NewStringf("%s_%s__%s%s", prefix, ns, Getattr(n, "sym:name"), suffix); String *mangled_name = Swig_name_mangle(pre_mangled_name); Delete(pre_mangled_name); return mangled_name; @@ -809,31 +787,31 @@ String *strip_parens(String *string) { Replaceall(string, ")", ""); return string; /* - char *s=Char(string), *p; - int len=Len(string); - String *res; - - if (len==0 || s[0] != '(' || s[len-1] != ')') { - return NewString(string); - } - - p=(char *)malloc(len-2+1); - if (!p) { - Printf(stderr, "Malloc failed\n"); - SWIG_exit(EXIT_FAILURE); - } - - strncpy(p, s+1, len-1); - p[len-2]=0; // null terminate - - res=NewString(p); - free(p); - - return res; -*/ + char *s=Char(string), *p; + int len=Len(string); + String *res; + + if (len==0 || s[0] != '(' || s[len-1] != ')') { + return NewString(string); + } + + p=(char *)malloc(len-2+1); + if (!p) { + Printf(stderr, "Malloc failed\n"); + SWIG_exit(EXIT_FAILURE); + } + + strncpy(p, s+1, len-1); + p[len-2]=0; // null terminate + + res=NewString(p); + free(p); + + return res; + */ } -int ALLEGROCL :: validIdentifier(String *s) { +int ALLEGROCL::validIdentifier(String *s) { char *c = Char(s); bool got_dot = false; @@ -851,7 +829,8 @@ int ALLEGROCL :: validIdentifier(String *s) { } else { only_dots = false; } - if (!isgraph(*c)) return 0; + if (!isgraph(*c)) + return 0; c++; } @@ -862,22 +841,21 @@ String *infix_to_prefix(String *val, char split_op, const String *op, String *ty List *ored = Split(val, split_op, -1); // some float hackery - if ( ((split_op == '+') || (split_op == '-')) && Len(ored) == 2 && - (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || - SwigType_type(type) == T_LONGDOUBLE) ) { + if (((split_op == '+') || (split_op == '-')) && Len(ored) == 2 && + (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || SwigType_type(type) == T_LONGDOUBLE)) { // check that we're not splitting a float String *possible_result = convert_literal(val, type, false); - if (possible_result) return possible_result; - - } + if (possible_result) + return possible_result; + } // try parsing the split results. if any part fails, kick out. bool part_failed = false; if (Len(ored) > 1) { String *result = NewStringf("(%s", op); for (Iterator i = First(ored); i.item; i = Next(i)) { String *converted = convert_literal(i.item, type); - if(converted) { + if (converted) { Printf(result, " %s", converted); Delete(converted); } else { @@ -888,8 +866,7 @@ String *infix_to_prefix(String *val, char split_op, const String *op, String *ty Printf(result, ")"); Delete(ored); return part_failed ? 0 : result; - } - else { + } else { Delete(ored); } return 0; @@ -901,40 +878,45 @@ String *infix_to_prefix(String *val, char split_op, const String *op, String *ty try_to_split defaults to true (see stub above). */ -String * convert_literal(String *literal, String *type, bool try_to_split) { +String *convert_literal(String *literal, String *type, bool try_to_split) { String *num_param = Copy(literal); String *trimmed = trim(num_param); - String *num=strip_parens(trimmed), *res=0; - char *s=Char(num); + String *num = strip_parens(trimmed), *res = 0; + char *s = Char(num); String *ns = listify_namespace(current_namespace); // very basic parsing of infix expressions. - if(try_to_split) { - if( (res = infix_to_prefix(num, '|', "logior", type)) ) return res; - if( (res = infix_to_prefix(num, '&', "logand", type)) ) return res; - if( (res = infix_to_prefix(num, '^', "logxor", type)) ) return res; - if( (res = infix_to_prefix(num, '*', "*", type)) ) return res; - if( (res = infix_to_prefix(num, '/', "/", type)) ) return res; - if( (res = infix_to_prefix(num, '+', "+", type)) ) return res; - if( (res = infix_to_prefix(num, '-', "-", type)) ) return res; + if (try_to_split) { + if ((res = infix_to_prefix(num, '|', "logior", type))) + return res; + if ((res = infix_to_prefix(num, '&', "logand", type))) + return res; + if ((res = infix_to_prefix(num, '^', "logxor", type))) + return res; + if ((res = infix_to_prefix(num, '*', "*", type))) + return res; + if ((res = infix_to_prefix(num, '/', "/", type))) + return res; + if ((res = infix_to_prefix(num, '+', "+", type))) + return res; + if ((res = infix_to_prefix(num, '-', "-", type))) + return res; // if( (res = infix_to_prefix(num, '<<', "ash", type)) ) return res; } - if (SwigType_type(type) == T_FLOAT || - SwigType_type(type) == T_DOUBLE || - SwigType_type(type) == T_LONGDOUBLE) { + if (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || SwigType_type(type) == T_LONGDOUBLE) { // Use CL syntax for float literals String *oldnum = Copy(num); // careful. may be a float identifier or float constant. char *num_start = Char(num); - char *num_end = num_start + strlen(num_start) -1; + char *num_end = num_start + strlen(num_start) - 1; bool is_literal = isdigit(*num_start) || (*num_start == '.'); String *lisp_exp = 0; - if(is_literal) { + if (is_literal) { if (*num_end == 'f' || *num_end == 'F') { lisp_exp = NewString("f"); } else { @@ -946,13 +928,12 @@ String * convert_literal(String *literal, String *type, bool try_to_split) { num_end--; } - int exponents = Replaceall(num, "e", lisp_exp) + - Replaceall(num, "E", lisp_exp); + int exponents = Replaceall(num, "e", lisp_exp) + Replaceall(num, "E", lisp_exp); if (!exponents) Printf(num, "%s0", lisp_exp); - if (exponents > 1 || (exponents + Replaceall(num,".",".") == 0)) { + if (exponents > 1 || (exponents + Replaceall(num, ".", ".") == 0)) { // Printf(stderr, "Can't parse '%s' as type '%s'.\n", oldnum, type); Delete(num); num = 0; @@ -964,20 +945,21 @@ String * convert_literal(String *literal, String *type, bool try_to_split) { num = id; } - Delete(oldnum); Delete(trimmed); Delete(ns); + Delete(oldnum); + Delete(trimmed); + Delete(ns); return num; - } - else if (SwigType_type(type) == T_CHAR) { + } else if (SwigType_type(type) == T_CHAR) { /* Use CL syntax for character literals */ - Delete(num); Delete(trimmed); + Delete(num); + Delete(trimmed); return NewStringf("#\\%s", num_param); - } - else if (SwigType_type(type) == T_STRING) { + } else if (SwigType_type(type) == T_STRING) { /* Use CL syntax for string literals */ - Delete(num); Delete(trimmed); + Delete(num); + Delete(trimmed); return NewStringf("\"%s\"", num_param); - } - else if (Len(num) >= 1 && (isdigit(s[0]) || s[0] == '+' || s[0] == '-')) { + } else if (Len(num) >= 1 && (isdigit(s[0]) || s[0] == '+' || s[0] == '-')) { /* use CL syntax for numbers */ String *oldnum = Copy(num); int usuffixes = Replaceall(num, "u", "") + Replaceall(num, "U", ""); @@ -989,22 +971,20 @@ String * convert_literal(String *literal, String *type, bool try_to_split) { s = Char(num); if (s[0] == '0' && Len(num) >= 2) { /*octal or hex */ - res=NewStringf("#%c%s", - tolower(s[1]) == 'x' ? 'x' : 'o', - s+2); + res = NewStringf("#%c%s", tolower(s[1]) == 'x' ? 'x' : 'o', s + 2); Delete(num); + } else { + res = num; } - else - { - res=num; - } - Delete(oldnum); Delete(trimmed); + Delete(oldnum); + Delete(trimmed); return res; - } - else if (allegrocl->validIdentifier(num)) { + } else if (allegrocl->validIdentifier(num)) { /* convert C/C++ identifiers to CL symbols */ res = NewStringf("#.(swig-insert-id \"%s\" %s :type :constant)", num, ns); - Delete(num); Delete(trimmed); Delete(ns); + Delete(num); + Delete(trimmed); + Delete(ns); return res; } else { Delete(trimmed); @@ -1016,19 +996,18 @@ String * convert_literal(String *literal, String *type, bool try_to_split) { void emit_stub_class(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_stub_class: ENTER... '%s'(%x)\n", Getattr(n,"sym:name"),n); + Printf(stderr, "emit_stub_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); #endif - String *name = Getattr(n,"sym:name"); + String *name = Getattr(n, "sym:name"); - if(Getattr(n,"allegrocl:synonym:already-been-stubbed")) return; + if (Getattr(n, "allegrocl:synonym:already-been-stubbed")) + return; - if(SwigType_istemplate(name)) { + if (SwigType_istemplate(name)) { String *temp = strip_namespaces(SwigType_templateprefix(name)); - name = NewStringf("%s%s%s", temp, - SwigType_templateargs(name), - SwigType_templatesuffix(name)); + name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name)); Delete(temp); } else { @@ -1036,51 +1015,49 @@ void emit_stub_class(Node *n) { } // Printf(f_clhead, ";; from emit-stub-class\n"); - update_package_if_needed(n,f_clhead); + update_package_if_needed(n, f_clhead); Printf(f_clhead, ";; class template stub.\n"); - Printf(f_clhead,"(swig-def-foreign-stub \"%s\")\n", name); + Printf(f_clhead, "(swig-def-foreign-stub \"%s\")\n", name); - Setattr(n,"allegrocl:synonym:already-been-stubbed","1"); + Setattr(n, "allegrocl:synonym:already-been-stubbed", "1"); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_stub_class: EXIT\n"); + Printf(stderr, "emit_stub_class: EXIT\n"); #endif } void emit_synonym(Node *synonym) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_synonym: ENTER... \n"); + Printf(stderr, "emit_synonym: ENTER... \n"); #endif // Printf(stderr,"in emit_synonym for %s(%x)\n", Getattr(synonym,"name"),synonym); - int is_tempInst = !Strcmp(nodeType(synonym),"templateInst"); + int is_tempInst = !Strcmp(nodeType(synonym), "templateInst"); String *synonym_type; Node *of = get_primary_synonym_of(synonym); - - if(is_tempInst) { + + if (is_tempInst) { // Printf(stderr, "*** using real-name '%s'\n", Getattr(synonym,"real-name")); - synonym_type = Getattr(synonym,"real-name"); + synonym_type = Getattr(synonym, "real-name"); } else { // Printf(stderr, "*** using name '%s'\n", Getattr(synonym,"name")); - synonym_type = Getattr(synonym,"name"); + synonym_type = Getattr(synonym, "name"); } - String *synonym_ns = listify_namespace(Getattr(synonym,"allegrocl:namespace")); + String *synonym_ns = listify_namespace(Getattr(synonym, "allegrocl:namespace")); String *syn_ltype, *syn_type, *of_ltype; // String *of_cdeclname = Getattr(of,"allegrocl:classDeclarationName"); - String *of_ns = Getattr(of,"allegrocl:namespace"); + String *of_ns = Getattr(of, "allegrocl:namespace"); String *of_ns_list = listify_namespace(of_ns); // String *of_name = of_cdeclname ? NewStringf("struct %s", Getattr(of,"name")) : NewStringf("%s::%s", of_ns, Getattr(of,"sym:name")); // String *of_name = NewStringf("%s::%s", of_ns, Getattr(of,"sym:name")); String *of_name = namespaced_name(of, of_ns); - if(CPlusPlus && !Strcmp(nodeType(synonym),"cdecl")) { - syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", - Getattr(synonym,"real-name"),synonym_ns); - syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", - Getattr(synonym,"real-name"),synonym_ns); + if (CPlusPlus && !Strcmp(nodeType(synonym), "cdecl")) { + syn_ltype = NewStringf("#.(swig-insert-id \"%s\" %s :type :class)", Getattr(synonym, "real-name"), synonym_ns); + syn_type = NewStringf("#.(swig-insert-id \"%s\" %s :type :type)", Getattr(synonym, "real-name"), synonym_ns); } else { syn_ltype = lookup_defined_foreign_ltype(synonym_type); syn_type = lookup_defined_foreign_type(synonym_type); @@ -1089,56 +1066,56 @@ void emit_synonym(Node *synonym) { of_ltype = lookup_defined_foreign_ltype(of_name); // Printf(f_clhead,";; from emit-synonym\n"); - Printf(f_clhead,"(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type); + Printf(f_clhead, "(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type); Delete(synonym_ns); Delete(of_ns_list); Delete(of_name); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_synonym: EXIT\n"); + Printf(stderr, "emit_synonym: EXIT\n"); #endif } void emit_full_class(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_full_class: ENTER... \n"); + Printf(stderr, "emit_full_class: ENTER... \n"); #endif - String *name=Getattr(n, "sym:name"); - String *kind = Getattr(n,"kind"); + String *name = Getattr(n, "sym:name"); + String *kind = Getattr(n, "kind"); // Printf(stderr,"in emit_full_class: '%s'(%x).", Getattr(n,"name"),n); - if(Getattr(n,"allegrocl:synonym-of")) { + if (Getattr(n, "allegrocl:synonym-of")) { // Printf(stderr,"but it's a synonym of something.\n"); - update_package_if_needed(n,f_clhead); + update_package_if_needed(n, f_clhead); emit_synonym(n); return; } - // collect superclasses - String *bases = Getattr(n,"bases"); + String *bases = Getattr(n, "bases"); String *supers = NewString("("); - if(bases) { - int first=1; - for (Iterator i=First(bases); i.item; i = Next(i)) { - if (!first) Printf(supers," "); - String *s = lookup_defined_foreign_ltype(Getattr(i.item,"name")); + if (bases) { + int first = 1; + for (Iterator i = First(bases); i.item; i = Next(i)) { + if (!first) + Printf(supers, " "); + String *s = lookup_defined_foreign_ltype(Getattr(i.item, "name")); // String *name = Getattr(i.item,"name"); - if(s) { - Printf(supers,"%s",s); + if (s) { + Printf(supers, "%s", s); } else { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"emit_templ_inst: did not find ltype for base class %s (%s)", Getattr(i.item,"name"), Getattr(n,"allegrocl:namespace")); + Printf(stderr, "emit_templ_inst: did not find ltype for base class %s (%s)", Getattr(i.item, "name"), Getattr(n, "allegrocl:namespace")); #endif } } } else { - Printf(supers,"ff:foreign-pointer"); + Printf(supers, "ff:foreign-pointer"); } - Printf(supers,")"); + Printf(supers, ")"); // Walk children to generate type definition. String *slotdefs = NewString(" "); @@ -1148,57 +1125,51 @@ void emit_full_class(Node *n) { #endif Node *c; - for (c=firstChild(n); c; c=nextSibling(c)) { - String *storage_type = Getattr(c,"storage"); - if((!Strcmp(nodeType(c),"cdecl") && - (!storage_type || Strcmp(storage_type,"typedef")))) { - String *access = Getattr(c,"access"); + for (c = firstChild(n); c; c = nextSibling(c)) { + String *storage_type = Getattr(c, "storage"); + if ((!Strcmp(nodeType(c), "cdecl") && (!storage_type || Strcmp(storage_type, "typedef")))) { + String *access = Getattr(c, "access"); // hack. why would decl have a value of "variableHandler" and now "0"? - String *childDecl = Getattr(c,"decl"); + String *childDecl = Getattr(c, "decl"); // Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view")); - if(!Strcmp(childDecl,"0")) + if (!Strcmp(childDecl, "0")) childDecl = NewString(""); - SwigType *childType=NewStringf("%s%s", childDecl, - Getattr(c,"type")); - String *cname = (access && Strcmp(access,"public")) ? - NewString("nil") : Copy(Getattr(c,"name")); + SwigType *childType = NewStringf("%s%s", childDecl, + Getattr(c, "type")); + String *cname = (access && Strcmp(access, "public")) ? NewString("nil") : Copy(Getattr(c, "name")); - if(!SwigType_isfunction(childType)) { - // Printf(slotdefs, ";;; member functions don't appear as slots.\n "); - // Printf(slotdefs, ";; "); - String *ns = listify_namespace(Getattr(n, "allegrocl:package")); + if (!SwigType_isfunction(childType)) { + // Printf(slotdefs, ";;; member functions don't appear as slots.\n "); + // Printf(slotdefs, ";; "); + String *ns = listify_namespace(Getattr(n, "allegrocl:package")); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", - cname, ns, name, childType); + Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType); #endif - Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", - cname, ns, name, compose_foreign_type(childType)); - Delete(ns); - if(access && Strcmp(access,"public")) - Printf(slotdefs, " ;; %s member", access); + Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, compose_foreign_type(childType)); + Delete(ns); + if (access && Strcmp(access, "public")) + Printf(slotdefs, " ;; %s member", access); - Printf(slotdefs, "\n "); + Printf(slotdefs, "\n "); } Delete(childType); Delete(cname); } } - String *ns_list = listify_namespace(Getattr(n,"allegrocl:namespace")); - update_package_if_needed(n,f_clhead); - Printf(f_clhead, - "(swig-def-foreign-class \"%s\"\n %s\n (:%s\n%s))\n\n", - name, supers, kind, slotdefs); + String *ns_list = listify_namespace(Getattr(n, "allegrocl:namespace")); + update_package_if_needed(n, f_clhead); + Printf(f_clhead, "(swig-def-foreign-class \"%s\"\n %s\n (:%s\n%s))\n\n", name, supers, kind, slotdefs); Delete(supers); Delete(ns_list); - Setattr(n,"allegrocl:synonym:already-been-stubbed","1"); + Setattr(n, "allegrocl:synonym:already-been-stubbed", "1"); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_full_class: EXIT\n"); + Printf(stderr, "emit_full_class: EXIT\n"); #endif } @@ -1206,28 +1177,26 @@ void emit_full_class(Node *n) { void emit_class(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_class: ENTER... '%s'(%x)\n", Getattr(n,"sym:name"), n); + Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); #endif - int is_tempInst = !Strcmp(nodeType(n),"templateInst"); + int is_tempInst = !Strcmp(nodeType(n), "templateInst"); - String *ns_list = listify_namespace(Getattr(n,"allegrocl:namespace")); - String *name = Getattr(n,is_tempInst ? "real-name" : "name"); + String *ns_list = listify_namespace(Getattr(n, "allegrocl:namespace")); + String *name = Getattr(n, is_tempInst ? "real-name" : "name"); - if(SwigType_istemplate(name)) { + if (SwigType_istemplate(name)) { String *temp = strip_namespaces(SwigType_templateprefix(name)); - name = NewStringf("%s%s%s", temp, - SwigType_templateargs(name), - SwigType_templatesuffix(name)); + name = NewStringf("%s%s%s", temp, SwigType_templateargs(name), SwigType_templatesuffix(name)); Delete(temp); } else { name = strip_namespaces(name); } - if(Getattr(n,"allegrocl:synonym:is-primary")) { + if (Getattr(n, "allegrocl:synonym:is-primary")) { // Printf(stderr," is primary... "); - if(is_tempInst) { + if (is_tempInst) { emit_stub_class(n); } else { emit_full_class(n); @@ -1235,10 +1204,10 @@ void emit_class(Node *n) { } else { // Node *primary = Getattr(n,"allegrocl:synonym-of"); Node *primary = get_primary_synonym_of(n); - if(primary && (primary != n)) { + if (primary && (primary != n)) { // Printf(stderr," emitting synonym... "); emit_stub_class(primary); - update_package_if_needed(n,f_clhead); + update_package_if_needed(n, f_clhead); emit_synonym(n); } else { emit_full_class(n); @@ -1249,44 +1218,42 @@ void emit_class(Node *n) { Delete(ns_list); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_class: EXIT\n"); + Printf(stderr, "emit_class: EXIT\n"); #endif } void emit_typedef(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_typedef: ENTER... \n"); + Printf(stderr, "emit_typedef: ENTER... \n"); #endif String *name; - String *sym_name = Getattr(n,"sym:name"); - String *type = NewStringf("%s%s", Getattr(n,"decl"), Getattr(n,"type")); + String *sym_name = Getattr(n, "sym:name"); + String *type = NewStringf("%s%s", Getattr(n, "decl"), Getattr(n, "type")); String *lisp_type = compose_foreign_type(type); Delete(type); - Node *in_class = Getattr(n,"allegrocl:typedef:in-class"); + Node *in_class = Getattr(n, "allegrocl:typedef:in-class"); // Printf(stderr,"in emit_typedef: '%s'(%x).",Getattr(n,"name"),n); - if(Getattr(n,"allegrocl:synonym-of")) { + if (Getattr(n, "allegrocl:synonym-of")) { // Printf(stderr," but it's a synonym of something.\n"); emit_synonym(n); return; } - if(in_class) { - String *class_name = Getattr(in_class,"name"); - if(SwigType_istemplate(class_name)) { + if (in_class) { + String *class_name = Getattr(in_class, "name"); + if (SwigType_istemplate(class_name)) { String *temp = strip_namespaces(SwigType_templateprefix(class_name)); - class_name = NewStringf("%s%s%s", temp, - SwigType_templateargs(class_name), - SwigType_templatesuffix(class_name)); + class_name = NewStringf("%s%s%s", temp, SwigType_templateargs(class_name), SwigType_templatesuffix(class_name)); Delete(temp); } - name = NewStringf("%s__%s",class_name,sym_name); - Setattr(n,"allegrocl:in-class",in_class); + name = NewStringf("%s__%s", class_name, sym_name); + Setattr(n, "allegrocl:in-class", in_class); } else { - name = sym_name ? Copy(sym_name) : Copy(Getattr(n,"name")); + name = sym_name ? Copy(sym_name) : Copy(Getattr(n, "name")); } // leave these in for now. might want to change these to def-foreign-class at some point. @@ -1297,21 +1264,21 @@ void emit_typedef(Node *n) { Delete(name); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_typedef: EXIT\n"); + Printf(stderr, "emit_typedef: EXIT\n"); #endif } void emit_enum_type_no_wrap(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_enum_type_no_wrap: ENTER... \n"); + Printf(stderr, "emit_enum_type_no_wrap: ENTER... \n"); #endif - String *unnamed = Getattr(n,"unnamed"); + String *unnamed = Getattr(n, "unnamed"); String *name; // SwigType *enumtype; - name = unnamed ? Getattr(n,"allegrocl:name") : Getattr(n,"sym:name"); + name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name"); SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name); Hash *typemap = Swig_typemap_search("ffitype", tmp, 0, 0); @@ -1319,36 +1286,36 @@ void emit_enum_type_no_wrap(Node *n) { // enumtype = compose_foreign_type(tmp); Delete(tmp); - if(name) { + if (name) { String *ns = listify_namespace(current_namespace); - Printf(f_clhead,"(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); + Printf(f_clhead, "(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); Delete(ns); - + // walk children. Node *c; - for(c = firstChild(n); c; c=nextSibling(c)) { - if(!Getattr(c,"error")) { - String *val = Getattr(c,"enumvalue"); - if(!val) val = Getattr(c,"enumvalueex"); - String *converted_val = convert_literal(val,Getattr(c,"type")); - String *valname = Getattr(c,"sym:name"); + for (c = firstChild(n); c; c = nextSibling(c)) { + if (!Getattr(c, "error")) { + String *val = Getattr(c, "enumvalue"); + if (!val) + val = Getattr(c, "enumvalueex"); + String *converted_val = convert_literal(val, Getattr(c, "type")); + String *valname = Getattr(c, "sym:name"); - if(converted_val) { - Printf(f_clhead,"(swig-defconstant \"%s\" %s)\n", valname, converted_val); + if (converted_val) { + Printf(f_clhead, "(swig-defconstant \"%s\" %s)\n", valname, converted_val); Delete(converted_val); } else { - Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n), - "Unable to parse enum value '%s'. Setting to NIL\n", val); - Printf(f_clhead,"(swig-defconstant \"%s\" nil #| %s |#)\n", valname, val); + Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n), "Unable to parse enum value '%s'. Setting to NIL\n", val); + Printf(f_clhead, "(swig-defconstant \"%s\" nil #| %s |#)\n", valname, val); } } } } - Printf(f_clhead,"\n"); + Printf(f_clhead, "\n"); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_enum_type_no_wrap: EXIT\n"); + Printf(stderr, "emit_enum_type_no_wrap: EXIT\n"); #endif } @@ -1356,19 +1323,19 @@ void emit_enum_type_no_wrap(Node *n) { void emit_enum_type(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_enum_type: ENTER... \n"); + Printf(stderr, "emit_enum_type: ENTER... \n"); #endif - if(!Generate_Wrapper) { + if (!Generate_Wrapper) { emit_enum_type_no_wrap(n); return; } - String *unnamed = Getattr(n,"unnamed"); + String *unnamed = Getattr(n, "unnamed"); String *name; // SwigType *enumtype; - name = unnamed ? Getattr(n,"allegrocl:name") : Getattr(n,"sym:name"); + name = unnamed ? Getattr(n, "allegrocl:name") : Getattr(n, "sym:name"); SwigType *tmp = NewStringf("enum %s", unnamed ? unnamed : name); // SwigType *tmp = NewStringf("enum ACL_SWIG_ENUM_NAME"); @@ -1378,24 +1345,22 @@ void emit_enum_type(Node *n) { // enumtype = compose_foreign_type(tmp); Delete(tmp); - if(name) { + if (name) { String *ns = listify_namespace(current_namespace); - Printf(f_clhead,"(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); + Printf(f_clhead, "(swig-def-foreign-type \"%s\" %s)\n", name, enumtype); Delete(ns); - + // walk children. Node *c; - for(c = firstChild(n); c; c=nextSibling(c)) { - String *mangled_name = mangle_name(c, "ACL_ENUM", Getattr(c,"allegrocl:package")); - Printf(f_clhead, "(swig-defvar \"%s\" \"%s\" :type :constant)\n", - Getattr(c, "sym:name"), mangled_name); + for (c = firstChild(n); c; c = nextSibling(c)) { + String *mangled_name = mangle_name(c, "ACL_ENUM", Getattr(c, "allegrocl:package")); + Printf(f_clhead, "(swig-defvar \"%s\" \"%s\" :type :constant)\n", Getattr(c, "sym:name"), mangled_name); Delete(mangled_name); } } - #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_enum_type: EXIT\n"); + Printf(stderr, "emit_enum_type: EXIT\n"); #endif } @@ -1403,23 +1368,21 @@ void emit_enum_type(Node *n) { void emit_default_linked_type(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_default_linked_type: ENTER... \n"); + Printf(stderr, "emit_default_linked_type: ENTER... \n"); #endif // catchall for non class types. - if(!Strcmp(nodeType(n),"classforward")) { - Printf(f_clhead,";; forward referenced stub.\n"); - Printf(f_clhead,"(swig-def-foreign-class \"%s\" (ff:foreign-pointer) (:class ))\n\n", - Getattr(n,"sym:name")); - } else if(!Strcmp(nodeType(n),"enum")) { + if (!Strcmp(nodeType(n), "classforward")) { + Printf(f_clhead, ";; forward referenced stub.\n"); + Printf(f_clhead, "(swig-def-foreign-class \"%s\" (ff:foreign-pointer) (:class ))\n\n", Getattr(n, "sym:name")); + } else if (!Strcmp(nodeType(n), "enum")) { emit_enum_type(n); } else { - Printf(stderr,"Don't know how to emit node type '%s' named '%s'\n", - nodeType(n), Getattr(n,"name")); + Printf(stderr, "Don't know how to emit node type '%s' named '%s'\n", nodeType(n), Getattr(n, "name")); } #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_default_linked_type: EXIT\n"); + Printf(stderr, "emit_default_linked_type: EXIT\n"); #endif } @@ -1427,48 +1390,48 @@ void emit_default_linked_type(Node *n) { void dump_linked_types(File *f) { Node *n = first_linked_type; int i = 0; - while(n) { - Printf(f,"%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n,"sym:name")); + while (n) { + Printf(f, "%d: (%x) node '%s' name '%s'\n", i++, n, nodeType(n), Getattr(n, "sym:name")); - Node *t = Getattr(n,"allegrocl:synonym-of"); - if(t) - Printf(f," synonym-of %s(%x)\n",Getattr(t,"name"),t); - n = Getattr(n,"allegrocl:next_linked_type"); + Node *t = Getattr(n, "allegrocl:synonym-of"); + if (t) + Printf(f, " synonym-of %s(%x)\n", Getattr(t, "name"), t); + n = Getattr(n, "allegrocl:next_linked_type"); } } void emit_linked_types() { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_linked_types: ENTER... "); + Printf(stderr, "emit_linked_types: ENTER... "); #endif Node *n = first_linked_type; - while(n) { + while (n) { String *node_type = nodeType(n); // Printf(stderr,"emitting node %s(%x) of type %s.", Getattr(n,"name"),n, nodeType(n)); - if(!Strcmp(node_type,"class") || !Strcmp(node_type,"templateInst")) { + if (!Strcmp(node_type, "class") || !Strcmp(node_type, "templateInst")) { // may need to emit a stub, so it will update the package itself. // Printf(stderr," Passing to emit_class."); emit_class(n); - } else if(!Strcmp(nodeType(n),"cdecl")) { + } else if (!Strcmp(nodeType(n), "cdecl")) { // Printf(stderr," Passing to emit_typedef."); - update_package_if_needed(n,f_clhead); + update_package_if_needed(n, f_clhead); emit_typedef(n); } else { // Printf(stderr," Passing to default_emitter."); - update_package_if_needed(n,f_clhead); + update_package_if_needed(n, f_clhead); emit_default_linked_type(n); } - n = Getattr(n,"allegrocl:next_linked_type"); + n = Getattr(n, "allegrocl:next_linked_type"); // Printf(stderr,"returned.\n"); } #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_linked_types: EXIT\n"); + Printf(stderr, "emit_linked_types: EXIT\n"); #endif } @@ -1476,33 +1439,33 @@ extern "C" Language *swig_allegrocl(void) { return (allegrocl = new ALLEGROCL()); } -void ALLEGROCL :: main(int argc, char *argv[]) { +void ALLEGROCL::main(int argc, char *argv[]) { int i; - SWIG_library_directory("allegrocl"); + SWIG_library_directory("allegrocl"); SWIG_config_file("allegrocl.swg"); - for(i=1; i\n" - "\tSpecifies the type of conversion to do on C identifiers to convert\n" - "\tthem to symbols. There are two built-in converters: 'null' and\n" - "\t 'lispify'. The default is 'null'. If you supply a name other\n" - "\tthan one of the built-ins, then a function by that name will be\n" - "\tcalled to convert identifiers to symbols.\n" + fprintf(stdout, + " -identifier-converter \n" + "\tSpecifies the type of conversion to do on C identifiers to convert\n" + "\tthem to symbols. There are two built-in converters: 'null' and\n" + "\t 'lispify'. The default is 'null'. If you supply a name other\n" + "\tthan one of the built-ins, then a function by that name will be\n" + "\tcalled to convert identifiers to symbols.\n" "\n" " -[no]cwrap\n" - "\tTurn on or turn off generation of an intermediate C file when\n" - "\tcreating a C interface. By default this is only done for C++ code.\n"); + "\tTurn on or turn off generation of an intermediate C file when\n" "\tcreating a C interface. By default this is only done for C++ code.\n"); } - + } allow_overloading(); } -int ALLEGROCL :: top(Node *n) { - module_name=Getattr(n, "name"); - String *cxx_filename=Getattr(n, "outfile"); - String *cl_filename=NewString(""); +int ALLEGROCL::top(Node *n) { + module_name = Getattr(n, "name"); + String *cxx_filename = Getattr(n, "outfile"); + String *cl_filename = NewString(""); - swig_package = unique_swig_package ? - NewStringf("swig.%s", module_name) : NewString("swig"); + swig_package = unique_swig_package ? NewStringf("swig.%s", module_name) : NewString("swig"); Printf(cl_filename, "%s%s.cl", SWIG_output_directory(), module_name); - f_cl=NewFile(cl_filename, "w"); + f_cl = NewFile(cl_filename, "w"); if (!f_cl) { Printf(stderr, "Unable to open %s for writing\n", cl_filename); SWIG_exit(EXIT_FAILURE); @@ -1554,40 +1515,37 @@ int ALLEGROCL :: top(Node *n) { Generate_Wrapper = CPlusPlus || CWrap; - if (Generate_Wrapper) - { - f_cxx=NewFile(cxx_filename, "w"); + if (Generate_Wrapper) { + f_cxx = NewFile(cxx_filename, "w"); if (!f_cxx) { - Close(f_cl); Delete(f_cl); + Close(f_cl); + Delete(f_cl); Printf(stderr, "Unable to open %s for writing\n", cxx_filename); SWIG_exit(EXIT_FAILURE); } - } - else f_cxx=NewString(""); + } else + f_cxx = NewString(""); f_cxx_header = f_cxx; - f_cxx_wrapper=NewString(""); - - Swig_register_filebyname("header",f_cxx_header); - Swig_register_filebyname("wrapper",f_cxx_wrapper); - Swig_register_filebyname("runtime",f_cxx); + f_cxx_wrapper = NewString(""); + + Swig_register_filebyname("header", f_cxx_header); + Swig_register_filebyname("wrapper", f_cxx_wrapper); + Swig_register_filebyname("runtime", f_cxx); Swig_register_filebyname("lisp", f_clwrap); Swig_register_filebyname("lisphead", f_cl); Printf(f_cl, ";; This is an automatically generated file. Make changes in\n" - ";; the definition file, not here.\n\n" - "(defpackage :%s\n" - " (:use :common-lisp :ff :excl)\n" - " (:export #:*swig-identifier-converter* #:*swig-module-name*\n" - " #:*void* #:*swig-expoert-list*))\n" - "(in-package :%s)\n\n" - "(eval-when (compile load eval)\n" - " (defparameter *swig-identifier-converter* '%s)\n" - " (defparameter *swig-module-name* :%s))\n\n", - swig_package, swig_package, identifier_converter, module_name); - Printf(f_cl, "(defpackage :%s\n" - " (:use :common-lisp :%s :ff :excl))\n\n", - module_name, swig_package); + ";; the definition file, not here.\n\n" + "(defpackage :%s\n" + " (:use :common-lisp :ff :excl)\n" + " (:export #:*swig-identifier-converter* #:*swig-module-name*\n" + " #:*void* #:*swig-expoert-list*))\n" + "(in-package :%s)\n\n" + "(eval-when (compile load eval)\n" + " (defparameter *swig-identifier-converter* '%s)\n" + " (defparameter *swig-module-name* :%s))\n\n", swig_package, swig_package, identifier_converter, module_name); + Printf(f_cl, "(defpackage :%s\n" " (:use :common-lisp :%s :ff :excl))\n\n", module_name, swig_package); Printf(f_clhead, "(in-package :%s)\n", module_name); @@ -1616,7 +1574,7 @@ int ALLEGROCL :: top(Node *n) { Printf(stderr, "All done now!\n"); Close(f_cl); - Delete(f_cl); // Delete the handle, not the file + Delete(f_cl); // Delete the handle, not the file Delete(f_clhead); Delete(f_clwrap); @@ -1641,10 +1599,10 @@ int ALLEGROCL :: top(Node *n) { // String *argc_template_string; struct Overloaded { - Node *n; /* Node */ - int argc; /* Argument count */ - ParmList *parms; /* Parameters used for overload check */ - int error; /* Ambiguity error */ + Node *n; /* Node */ + int argc; /* Argument count */ + ParmList *parms; /* Parameters used for overload check */ + int error; /* Ambiguity error */ }; /* ----------------------------------------------------------------------------- @@ -1664,234 +1622,228 @@ struct Overloaded { * languages ignore the first method parsed. * ----------------------------------------------------------------------------- */ -static List * -Swig_overload_rank(Node *n, bool script_lang_wrapping) { - Overloaded nodes[MAX_OVERLOAD]; - int nnodes = 0; - Node *o = Getattr(n,"sym:overloaded"); +static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { + Overloaded nodes[MAX_OVERLOAD]; + int nnodes = 0; + Node *o = Getattr(n, "sym:overloaded"); Node *c; - if (!o) return 0; + if (!o) + return 0; c = o; while (c) { - if (Getattr(c,"error")) { - c = Getattr(c,"sym:nextSibling"); + if (Getattr(c, "error")) { + c = Getattr(c, "sym:nextSibling"); continue; } /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } */ + c = Getattr(c,"sym:nextSibling"); + continue; + } */ /* Make a list of all the declarations (methods) that are overloaded with * this one particular method name */ - if (Getattr(c,"wrap:name")) { + if (Getattr(c, "wrap:name")) { nodes[nnodes].n = c; - nodes[nnodes].parms = Getattr(c,"wrap:parms"); + nodes[nnodes].parms = Getattr(c, "wrap:parms"); nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); nodes[nnodes].error = 0; nnodes++; } - c = Getattr(c,"sym:nextSibling"); + c = Getattr(c, "sym:nextSibling"); } - + /* Sort the declarations by required argument count */ { - int i,j; + int i, j; for (i = 0; i < nnodes; i++) { - for (j = i+1; j < nnodes; j++) { - if (nodes[i].argc > nodes[j].argc) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } + for (j = i + 1; j < nnodes; j++) { + if (nodes[i].argc > nodes[j].argc) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } } } } /* Sort the declarations by argument types */ { - int i,j; - for (i = 0; i < nnodes-1; i++) { - if (nodes[i].argc == nodes[i+1].argc) { - for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { - Parm *p1 = nodes[i].parms; - Parm *p2 = nodes[j].parms; - int differ = 0; - int num_checked = 0; - while (p1 && p2 && (num_checked < nodes[i].argc)) { - // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); - if (checkAttribute(p1,"tmap:in:numinputs","0")) { - p1 = Getattr(p1,"tmap:in:next"); - continue; - } - if (checkAttribute(p2,"tmap:in:numinputs","0")) { - p2 = Getattr(p2,"tmap:in:next"); - continue; - } - String *t1 = Getattr(p1,"tmap:typecheck:precedence"); - String *t2 = Getattr(p2,"tmap:typecheck:precedence"); - if ((!t1) && (!nodes[i].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", - Getattr(nodes[i].n,"name"),ParmList_str_defaultargs(Getattr(nodes[i].n,"parms")), - SwigType_str(Getattr(p1,"type"),0)); - nodes[i].error = 1; - } else if ((!t2) && (!nodes[j].error)) { - Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", - Getattr(nodes[j].n,"name"),ParmList_str_defaultargs(Getattr(nodes[j].n,"parms")), - SwigType_str(Getattr(p2,"type"),0)); - nodes[j].error = 1; - } - if (t1 && t2) { - int t1v, t2v; - t1v = atoi(Char(t1)); - t2v = atoi(Char(t2)); - differ = t1v-t2v; - } - else if (!t1 && t2) differ = 1; - else if (t2 && !t1) differ = -1; - else if (!t1 && !t2) differ = -1; - num_checked++; - if (differ > 0) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - break; - } else if ((differ == 0) && (Strcmp(t1,"0") == 0)) { - t1 = Getattr(p1,"ltype"); - if (!t1) { - t1 = SwigType_ltype(Getattr(p1,"type")); - if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t1); - } - Setattr(p1,"ltype",t1); - } - t2 = Getattr(p2,"ltype"); - if (!t2) { - t2 = SwigType_ltype(Getattr(p2,"type")); - if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) { - SwigType_add_pointer(t2); - } - Setattr(p2,"ltype",t2); - } + int i, j; + for (i = 0; i < nnodes - 1; i++) { + if (nodes[i].argc == nodes[i + 1].argc) { + for (j = i + 1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { + Parm *p1 = nodes[i].parms; + Parm *p2 = nodes[j].parms; + int differ = 0; + int num_checked = 0; + while (p1 && p2 && (num_checked < nodes[i].argc)) { + // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); + if (checkAttribute(p1, "tmap:in:numinputs", "0")) { + p1 = Getattr(p1, "tmap:in:next"); + continue; + } + if (checkAttribute(p2, "tmap:in:numinputs", "0")) { + p2 = Getattr(p2, "tmap:in:next"); + continue; + } + String *t1 = Getattr(p1, "tmap:typecheck:precedence"); + String *t2 = Getattr(p2, "tmap:typecheck:precedence"); + if ((!t1) && (!nodes[i].error)) { + Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[i].n, "name"), ParmList_str_defaultargs(Getattr(nodes[i].n, "parms")), SwigType_str(Getattr(p1, "type"), 0)); + nodes[i].error = 1; + } else if ((!t2) && (!nodes[j].error)) { + Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[j].n, "name"), ParmList_str_defaultargs(Getattr(nodes[j].n, "parms")), SwigType_str(Getattr(p2, "type"), 0)); + nodes[j].error = 1; + } + if (t1 && t2) { + int t1v, t2v; + t1v = atoi(Char(t1)); + t2v = atoi(Char(t2)); + differ = t1v - t2v; + } else if (!t1 && t2) + differ = 1; + else if (t2 && !t1) + differ = -1; + else if (!t1 && !t2) + differ = -1; + num_checked++; + if (differ > 0) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + break; + } else if ((differ == 0) && (Strcmp(t1, "0") == 0)) { + t1 = Getattr(p1, "ltype"); + if (!t1) { + t1 = SwigType_ltype(Getattr(p1, "type")); + if (Getattr(p1, "tmap:typecheck:SWIGTYPE")) { + SwigType_add_pointer(t1); + } + Setattr(p1, "ltype", t1); + } + t2 = Getattr(p2, "ltype"); + if (!t2) { + t2 = SwigType_ltype(Getattr(p2, "type")); + if (Getattr(p2, "tmap:typecheck:SWIGTYPE")) { + SwigType_add_pointer(t2); + } + Setattr(p2, "ltype", t2); + } - /* Need subtype check here. If t2 is a subtype of t1, then we need to change the - order */ + /* Need subtype check here. If t2 is a subtype of t1, then we need to change the + order */ - if (SwigType_issubtype(t2,t1)) { - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } + if (SwigType_issubtype(t2, t1)) { + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } - if (Strcmp(t1,t2) != 0) { - differ = 1; - break; - } - } else if (differ) { - break; - } - if (Getattr(p1,"tmap:in:next")) { - p1 = Getattr(p1,"tmap:in:next"); - } else { - p1 = nextSibling(p1); - } - if (Getattr(p2,"tmap:in:next")) { - p2 = Getattr(p2,"tmap:in:next"); - } else { - p2 = nextSibling(p2); - } - } - if (!differ) { - /* See if declarations differ by const only */ - String *d1 = Getattr(nodes[i].n,"decl"); - String *d2 = Getattr(nodes[j].n,"decl"); - if (d1 && d2) { - String *dq1 = Copy(d1); - String *dq2 = Copy(d2); - if (SwigType_isconst(d1)) { - Delete(SwigType_pop(dq1)); - } - if (SwigType_isconst(d2)) { - Delete(SwigType_pop(dq2)); - } - if (Strcmp(dq1,dq2) == 0) { - - if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { - if (script_lang_wrapping) { - // Swap nodes so that the const method gets ignored (shadowed by the non-const method) - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } - } - nodes[j].error = 1; - } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { - differ = 1; - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } - } - nodes[j].error = 1; - } - } - Delete(dq1); - Delete(dq2); - } - } - if (!differ) { - if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", - Getfile(nodes[i].n),Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", - Getfile(nodes[i].n),Getline(nodes[i].n)); - } - nodes[j].error = 1; - } - } - } + if (Strcmp(t1, t2) != 0) { + differ = 1; + break; + } + } else if (differ) { + break; + } + if (Getattr(p1, "tmap:in:next")) { + p1 = Getattr(p1, "tmap:in:next"); + } else { + p1 = nextSibling(p1); + } + if (Getattr(p2, "tmap:in:next")) { + p2 = Getattr(p2, "tmap:in:next"); + } else { + p2 = nextSibling(p2); + } + } + if (!differ) { + /* See if declarations differ by const only */ + String *d1 = Getattr(nodes[i].n, "decl"); + String *d2 = Getattr(nodes[j].n, "decl"); + if (d1 && d2) { + String *dq1 = Copy(d1); + String *dq2 = Copy(d2); + if (SwigType_isconst(d1)) { + Delete(SwigType_pop(dq1)); + } + if (SwigType_isconst(d2)) { + Delete(SwigType_pop(dq2)); + } + if (Strcmp(dq1, dq2) == 0) { + + if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { + if (script_lang_wrapping) { + // Swap nodes so that the const method gets ignored (shadowed by the non-const method) + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } + differ = 1; + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } + } + nodes[j].error = 1; + } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { + differ = 1; + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } + } + nodes[j].error = 1; + } + } + Delete(dq1); + Delete(dq2); + } + } + if (!differ) { + if (!nodes[j].error) { + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "", + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + "Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n", + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "", + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n)); + } + nodes[j].error = 1; + } + } + } } } } @@ -1900,8 +1852,8 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { int i; for (i = 0; i < nnodes; i++) { if (nodes[i].error) - Setattr(nodes[i].n, "overload:ignore", "1"); - Append(result,nodes[i].n); + Setattr(nodes[i].n, "overload:ignore", "1"); + Append(result, nodes[i].n); // Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms)); // Swig_print_node(nodes[i].n); } @@ -1913,8 +1865,8 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { int any_varargs(ParmList *pl) { Parm *p; - - for(p=pl; p; p=nextSibling(p)) { + + for (p = pl; p; p = nextSibling(p)) { if (SwigType_isvarargs(Getattr(p, "type"))) return 1; } @@ -1922,21 +1874,18 @@ int any_varargs(ParmList *pl) { return 0; } -String *get_lisp_type(SwigType *ty, const String_or_char *name) -{ +String *get_lisp_type(SwigType *ty, const String_or_char *name) { Hash *typemap = Swig_typemap_search("lisptype", ty, name, 0); if (typemap) { String *typespec = Getattr(typemap, "code"); return NewString(typespec); - } - else { + } else { return NewString(""); } } -Node *parent_node_skipping_extends(Node* n) -{ - Node* result = n; +Node *parent_node_skipping_extends(Node *n) { + Node *result = n; do { result = parentNode(result); } @@ -1954,13 +1903,13 @@ Node *parent_node_skipping_extends(Node* n) int emit_num_lin_arguments(ParmList *parms) { Parm *p = parms; - int nargs = 0; + int nargs = 0; while (p) { // Printf(stderr,"enla: '%s' lin='%x'\n", Getattr(p,"name"), Getattr(p,"tmap:lin")); - if (Getattr(p,"tmap:lin")) { - nargs += GetInt(p,"tmap:lin:numinputs"); - p = Getattr(p,"tmap:lin:next"); + if (Getattr(p, "tmap:lin")) { + nargs += GetInt(p, "tmap:lin:numinputs"); + p = Getattr(p, "tmap:lin:next"); } else { p = nextSibling(p); } @@ -1968,241 +1917,215 @@ int emit_num_lin_arguments(ParmList *parms) { /* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */ /* - if (parms && (p = Getattr(parms,"emit:varargs"))) { - if (!nextSibling(p)) { - nargs--; - } - } - */ + if (parms && (p = Getattr(parms,"emit:varargs"))) { + if (!nextSibling(p)) { + nargs--; + } + } + */ return nargs; } -String *id_converter_type(SwigType const *type) -{ +String *id_converter_type(SwigType const *type) { SwigType *t = Copy(type); String *result = 0; - - if (SwigType_ispointer(t)) - { + + if (SwigType_ispointer(t)) { SwigType_pop(t); String *pointee = id_converter_type(t); result = NewStringf("(:* %s)", pointee); Delete(pointee); - } - else if (SwigType_ismemberpointer(t)) - { + } else if (SwigType_ismemberpointer(t)) { String *klass = SwigType_parm(t); SwigType_pop(t); String *member = id_converter_type(t); result = NewStringf("(:member \"%s\" %s)", klass, member); Delete(klass); Delete(member); - } - else if (SwigType_isreference(t)) - { + } else if (SwigType_isreference(t)) { SwigType_pop(t); String *referencee = id_converter_type(t); result = NewStringf("(:& %s)", referencee); Delete(referencee); - } - else if (SwigType_isarray(t)) - { + } else if (SwigType_isarray(t)) { String *size = SwigType_parm(t); SwigType_pop(t); String *element_type = id_converter_type(t); result = NewStringf("(:array %s \"%s\")", element_type, size); Delete(size); Delete(element_type); - } - else if (SwigType_isfunction(t)) - { + } else if (SwigType_isfunction(t)) { result = NewString("(:function ("); String *parmlist_str = SwigType_parm(t); List *parms = SwigType_parmlist(parmlist_str); - - for (Iterator i = First(parms); i.item; ) - { - String *parm = id_converter_type((SwigType *)i.item); + + for (Iterator i = First(parms); i.item;) { + String *parm = id_converter_type((SwigType *) i.item); Printf(result, "%s", parm); i = Next(i); - if (i.item) Printf(result, " "); + if (i.item) + Printf(result, " "); Delete(parm); } SwigType_pop(t); String *ret = id_converter_type(t); Printf(result, ") %s)", ret); - + Delete(parmlist_str); Delete(parms); Delete(ret); - } - else if (SwigType_isqualifier(t)) - { + } else if (SwigType_isqualifier(t)) { result = NewString("(:qualified ("); - String *qualifiers_str = Copy(SwigType_parm(t)); // ?! - // Replaceall below SEGVs if we don't put the Copy here... + String *qualifiers_str = Copy(SwigType_parm(t)); // ?! + // Replaceall below SEGVs if we don't put the Copy here... SwigType_pop(t); String *qualifiee = id_converter_type(t); Replaceall(qualifiers_str, " ", " :"); - if (Len(qualifiers_str) > 0) Printf(result, ":"); + if (Len(qualifiers_str) > 0) + Printf(result, ":"); Printf(result, "%s) %s)", qualifiers_str, qualifiee); - + Delete(qualifiers_str); Delete(qualifiee); - } - else if (SwigType_istemplate(t)) - { + } else if (SwigType_istemplate(t)) { result = NewStringf("(:template \"%s\")", t); - } - else /* if (SwigType_issimple(t)) */ - { - if (Strstr(Char(t), "::")) - { + } else { /* if (SwigType_issimple(t)) */ + + if (Strstr(Char(t), "::")) { result = listify_namespace(t); - } - else - { + } else { result = NewStringf("\"%s\"", t); } } - + Delete(t); return result; } -static ParmList *parmlist_with_names(ParmList *pl) -{ - ParmList* pl2 = CopyParmList(pl); - for (Parm *p = pl, *p2 = pl2; p2; - p=nextSibling(p), p2=nextSibling(p2)) - { +static ParmList *parmlist_with_names(ParmList *pl) { + ParmList *pl2 = CopyParmList(pl); + for (Parm *p = pl, *p2 = pl2; p2; p = nextSibling(p), p2 = nextSibling(p2)) { if (!Getattr(p2, "name")) Setattr(p2, "name", Getattr(p2, "lname")); Setattr(p2, "name", strip_namespaces(Getattr(p2, "name"))); Setattr(p2, "tmap:ctype", Getattr(p, "tmap:ctype")); - - String *temp = Getattr(p,"tmap:lin"); + + String *temp = Getattr(p, "tmap:lin"); if (temp) { Setattr(p2, "tmap:lin", temp); - Setattr(p2, "tmap:lin:next", Getattr(p,"tmap:lin:next")); + Setattr(p2, "tmap:lin:next", Getattr(p, "tmap:lin:next")); } } return pl2; } -static String *parmlist_str_id_converter(ParmList *pl) -{ +static String *parmlist_str_id_converter(ParmList *pl) { String *result = NewString(""); - for (Parm *p = pl; p; ) - { - String *lispy_type = id_converter_type(Getattr(p, "type")); + for (Parm *p = pl; p;) { + String *lispy_type = id_converter_type(Getattr(p, "type")); Printf(result, "(\"%s\" %s)", Getattr(p, "name"), lispy_type); Delete(lispy_type); - if ((p=nextSibling(p))) Printf(result, " "); + if ((p = nextSibling(p))) + Printf(result, " "); } return result; } String *collect_others_args(Node *overload) { - String *overloaded_from = Getattr(overload,"sym:overloaded"); + String *overloaded_from = Getattr(overload, "sym:overloaded"); String *others_args = NewString(""); int first_overload = 1; - - for (Node *overload2 = overloaded_from; - overload2; - overload2 = Getattr(overload2,"sym:nextSibling")) - { - if (overload2 == overload || - GetInt(overload2, "overload:ignore")) - continue; - ParmList *opl = parmlist_with_names(Getattr(overload2, "wrap:parms")); - String *args = parmlist_str_id_converter(opl); - if (!first_overload) - Printf(others_args, "\n "); - Printf(others_args, "(%s)", args); - Delete(args); - Delete(opl); - first_overload = 0; - } + for (Node *overload2 = overloaded_from; overload2; overload2 = Getattr(overload2, "sym:nextSibling")) { + if (overload2 == overload || GetInt(overload2, "overload:ignore")) + continue; + + ParmList *opl = parmlist_with_names(Getattr(overload2, "wrap:parms")); + String *args = parmlist_str_id_converter(opl); + if (!first_overload) + Printf(others_args, "\n "); + Printf(others_args, "(%s)", args); + Delete(args); + Delete(opl); + first_overload = 0; + } return others_args; } struct IDargs { - String* name; - String* type; - String* klass; - String* arity; + String *name; + String *type; + String *klass; + String *arity; - IDargs() : name(0), type(0), klass(0), arity(0) {} - - String* full_quoted_str() { + IDargs():name(0), type(0), klass(0), arity(0) { + } String *full_quoted_str() { String *result = no_others_quoted_str(); - if (arity) Printf(result, " :arity %s", arity); + if (arity) + Printf(result, " :arity %s", arity); return result; } - String* no_others_quoted_str() { + String *no_others_quoted_str() { String *result = NewString(""); Printf(result, "\"%s\" :type :%s", name, type); - if (klass) Printf(result, " :class \"%s\"", klass); + if (klass) + Printf(result, " :class \"%s\"", klass); return result; } - String* noname_str() { + String *noname_str() { String *result = NewString(""); Printf(result, " :type :%s", type); - if (klass) Printf(result, " :class \"%s\"", klass); - if (arity) Printf(result, " :arity %s", arity); + if (klass) + Printf(result, " :class \"%s\"", klass); + if (arity) + Printf(result, " :arity %s", arity); return result; } }; -IDargs* id_converter_arguments(Node *n) -{ - IDargs* result = (IDargs*)GetVoid(n, "allegrocl:id-converter-args"); - if (!result) result = new IDargs; +IDargs *id_converter_arguments(Node *n) { + IDargs *result = (IDargs *) GetVoid(n, "allegrocl:id-converter-args"); + if (!result) + result = new IDargs; // Base name if (!result->name) { result->name = Getattr(n, "allegrocl:old-sym:name"); - if (!result->name) result->name = Getattr(n, "sym:name"); + if (!result->name) + result->name = Getattr(n, "sym:name"); result->name = Copy(result->name); } - // :type - if (result->type) Delete(result->type); + if (result->type) + Delete(result->type); if (!Getattr(n, "allegrocl:kind")) Setattr(n, "allegrocl:kind", "function"); if (Strstr(Getattr(n, "name"), "operator ")) Replaceall(Getattr(n, "allegrocl:kind"), "function", "operator"); - if (Strstr(Getattr(n, "allegrocl:kind"), "variable")) - { + if (Strstr(Getattr(n, "allegrocl:kind"), "variable")) { int name_end = Len(Getattr(n, "sym:name")) - 4; char *str = Char(Getattr(n, "sym:name")); - String *get_set = NewString(str+name_end+1); + String *get_set = NewString(str + name_end + 1); result->type = Copy(Getattr(n, "allegrocl:kind")); Replaceall(result->type, "variable", ""); Printf(result->type, "%ster", get_set); Delete(get_set); - } - else - { + } else { result->type = Copy(Getattr(n, "allegrocl:kind")); } // :class - if (Strstr(result->type, "member ")) - { + if (Strstr(result->type, "member ")) { Replaceall(result->type, "member ", ""); if (!result->klass) - result->klass = Copy(Getattr(parent_node_skipping_extends(n), - "sym:name")); + result->klass = Copy(Getattr(parent_node_skipping_extends(n), "sym:name")); } - // :arity if (Getattr(n, "sym:overloaded")) { - if(result->arity) Delete(result->arity); + if (result->arity) + Delete(result->arity); result->arity = NewStringf("%d", // emit_num_arguments(Getattr(n, "wrap:parms"))); emit_num_lin_arguments(Getattr(n, "wrap:parms"))); @@ -2212,57 +2135,55 @@ IDargs* id_converter_arguments(Node *n) return result; } -int ALLEGROCL :: emit_buffered_defuns(Node *n) { +int ALLEGROCL::emit_buffered_defuns(Node *n) { - Node *overloaded_from = Getattr(n,"sym:overloaded"); + Node *overloaded_from = Getattr(n, "sym:overloaded"); String *wrap; if (!overloaded_from) { - wrap = Getattr(n,"allegrocl:lisp-wrap"); + wrap = Getattr(n, "allegrocl:lisp-wrap"); - Printf(f_clwrap,"%s\n",wrap); - Delattr(n,"allegrocl:lisp-wrap"); + Printf(f_clwrap, "%s\n", wrap); + Delattr(n, "allegrocl:lisp-wrap"); Delete(wrap); } else { - for (Node *overload = overloaded_from; - overload; - overload = Getattr(overload,"sym:nextSibling")) - { - String *others_args = collect_others_args(overload); - wrap = Getattr(overload, "allegrocl:lisp-wrap"); + for (Node *overload = overloaded_from; overload; overload = Getattr(overload, "sym:nextSibling")) { + String *others_args = collect_others_args(overload); + wrap = Getattr(overload, "allegrocl:lisp-wrap"); - Replaceall(wrap, "@@OTHERS-ARGS-GO-HERE@@", others_args); + Replaceall(wrap, "@@OTHERS-ARGS-GO-HERE@@", others_args); // IDargs* id_args = id_converter_arguments(overload); // Replaceall(id_args->others_args, "@@OTHERS-ARGS-GO-HERE@@", others_args); - if (!GetInt(overload, "overload:ignore")) - Printf(f_clwrap, "%s", wrap); + if (!GetInt(overload, "overload:ignore")) + Printf(f_clwrap, "%s", wrap); - Delattr(overload, "allegrocl:lisp-wrap"); - Delete(wrap); - } + Delattr(overload, "allegrocl:lisp-wrap"); + Delete(wrap); + } } return SWIG_OK; } -String *dispatching_type(Parm* p) { +String *dispatching_type(Parm *p) { String *result = 0; - String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype")); + String *parsed = Getattr(p, "type"); //Swig_cparse_type(Getattr(p,"tmap:ctype")); String *cl_t = SwigType_typedef_resolve_all(parsed); Hash *typemap = Swig_typemap_search("lispclass", parsed, Getattr(p, "name"), 0); // Printf(stderr,"inspecting type '%s' for class\n", parsed); // Printf(stderr," cfcocr = '%s' res_all = '%s'\n", - // class_from_class_or_class_ref(parsed), cl_t); + // class_from_class_or_class_ref(parsed), cl_t); if (typemap) { result = Copy(Getattr(typemap, "code")); } else { String *lookup_type = class_from_class_or_class_ref(parsed); - if(lookup_type) result = lookup_defined_foreign_ltype(lookup_type); + if (lookup_type) + result = lookup_defined_foreign_ltype(lookup_type); } - + // if (!result && SwigType_ispointer(cl_t)) { // SwigType_pop(cl_t); // result = lookup_defined_foreign_ltype(cl_t); @@ -2276,15 +2197,16 @@ String *dispatching_type(Parm* p) { return result; } -String *defmethod_lambda_list(Node* overload) { +String *defmethod_lambda_list(Node *overload) { String *result = NewString(""); ParmList *parms = Getattr(overload, "wrap:parms"); Parm *p; int a; - - for (a=0, p=parms; p; p=nextSibling(p),++a) { - if (a!=0) Printf(result, " "); + + for (a = 0, p = parms; p; p = nextSibling(p), ++a) { + if (a != 0) + Printf(result, " "); Printf(result, "(arg%d ", a); Printf(result, "%s", dispatching_type(p)); Printf(result, ")"); @@ -2293,11 +2215,11 @@ String *defmethod_lambda_list(Node* overload) { return result; } -int ALLEGROCL :: emit_dispatch_defun(Node *n) { +int ALLEGROCL::emit_dispatch_defun(Node *n) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_dispatch_defun: ENTER... "); + Printf(stderr, "emit_dispatch_defun: ENTER... "); #endif - List *overloads = Swig_overload_rank(n,true); + List *overloads = Swig_overload_rank(n, true); String *id_args = id_converter_arguments(n)->no_others_quoted_str(); Printf(f_clwrap, "(swig-dispatcher (%s :arities (", id_args); @@ -2305,71 +2227,68 @@ int ALLEGROCL :: emit_dispatch_defun(Node *n) { int last_arity = -1; for (Iterator i = First(overloads); i.item; i = Next(i)) { int arity = emit_num_lin_arguments(Getattr(i.item, "wrap:parms")); - if (arity == last_arity) continue; + if (arity == last_arity) + continue; Printf(f_clwrap, "%s%d", last_arity == -1 ? "" : " ", arity); last_arity = arity; } Printf(f_clwrap, ")))\n"); - + Delete(id_args); Delete(overloads); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_dispatch_defun: EXIT\n"); + Printf(stderr, "emit_dispatch_defun: EXIT\n"); #endif return SWIG_OK; } -int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { +int ALLEGROCL::emit_defun(Node *n, File *f_cl) { #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_defun: ENTER... "); + Printf(stderr, "emit_defun: ENTER... "); #endif #ifdef ALLEGROCL_DEBUG int auto_generated = Cmp(Getattr(n, "view"), "globalfunctionHandler"); - Printf(stderr, "%s%sfunction %s%s%s\n", - auto_generated ? "> " : "", Getattr(n, "sym:overloaded") - ? "overloaded " : "", current_namespace, - (current_namespace) > 0 ? "::" : "", Getattr(n, "sym:name")); + Printf(stderr, "%s%sfunction %s%s%s\n", auto_generated ? "> " : "", Getattr(n, "sym:overloaded") + ? "overloaded " : "", current_namespace, (current_namespace) > 0 ? "::" : "", Getattr(n, "sym:name")); Printf(stderr, " (view: %s)\n", Getattr(n, "view")); #endif String *funcname = Getattr(n, "allegrocl:old-sym:name"); - if (!funcname) funcname = Getattr(n, "sym:name"); - String *mangled_name = Getattr(n,"wrap:name"); + if (!funcname) + funcname = Getattr(n, "sym:name"); + String *mangled_name = Getattr(n, "wrap:name"); ParmList *pl = parmlist_with_names(Getattr(n, "wrap:parms")); // attach typemap info. Wrapper *wrap = NewWrapper(); Swig_typemap_attach_parms("lin", pl, wrap); - Swig_typemap_lookup_new("lout",n,"result",0); + Swig_typemap_lookup_new("lout", n, "result", 0); - SwigType *result_type = Swig_cparse_type(Getattr(n,"tmap:ctype")); + SwigType *result_type = Swig_cparse_type(Getattr(n, "tmap:ctype")); // prime the pump, with support for OUTPUT, INOUT typemaps. - Printf(wrap->code,"(cl::let ((ACL_ffresult %s:*void*)\n ACL_result)\n $body\n (cl::if (cl::eq ACL_ffresult %s:*void*)\n (cl::values-list ACL_result)\n (cl::values-list (cl::cons ACL_ffresult ACL_result))))", swig_package, swig_package); + Printf(wrap->code, + "(cl::let ((ACL_ffresult %s:*void*)\n ACL_result)\n $body\n (cl::if (cl::eq ACL_ffresult %s:*void*)\n (cl::values-list ACL_result)\n (cl::values-list (cl::cons ACL_ffresult ACL_result))))", + swig_package, swig_package); Parm *p; - int largnum = 0, argnum=0, first=1; + int largnum = 0, argnum = 0, first = 1; // int varargs=0; - if (Generate_Wrapper) - { + if (Generate_Wrapper) { String *extra_parms = id_converter_arguments(n)->noname_str(); if (Getattr(n, "sym:overloaded")) - Printf(f_cl, "(swig-defmethod (\"%s\" \"%s\"%s)\n", - funcname, mangled_name, extra_parms); + Printf(f_cl, "(swig-defmethod (\"%s\" \"%s\"%s)\n", funcname, mangled_name, extra_parms); else - Printf(f_cl, "(swig-defun (\"%s\" \"%s\"%s)\n", - funcname, mangled_name, extra_parms); + Printf(f_cl, "(swig-defun (\"%s\" \"%s\"%s)\n", funcname, mangled_name, extra_parms); Delete(extra_parms); } // Just C - else - { - Printf(f_cl, "(swig-defun (\"%s\" \"%s\")\n", funcname, - Generate_Wrapper ? mangled_name : funcname); + else { + Printf(f_cl, "(swig-defun (\"%s\" \"%s\")\n", funcname, Generate_Wrapper ? mangled_name : funcname); } ////////////////////////////////////// @@ -2378,7 +2297,7 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { Printf(f_cl, " ("); /* Special cases */ - + if (ParmList_len(pl) == 0) { Printf(f_cl, ":void"); /* } else if (any_varargs(pl)) { @@ -2387,24 +2306,24 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { } else { String *largs = NewString(""); - for (p=pl; p; p=nextSibling(p), argnum++, largnum++) { + for (p = pl; p; p = nextSibling(p), argnum++, largnum++) { // SwigType *argtype=Getattr(p, "type"); - SwigType *argtype = Swig_cparse_type(Getattr(p,"tmap:ctype")); + SwigType *argtype = Swig_cparse_type(Getattr(p, "tmap:ctype")); if (!first) { Printf(f_cl, "\n "); } - if(SwigType_isvarargs(argtype)) { - Printf(stderr, "Function %s (line %d) contains varargs, which is not directly supported. Use %varargs instead.\n", Getattr(n,"name"), Getline(n)); + if (SwigType_isvarargs(argtype)) { + Printf(stderr, "Function %s (line %d) contains varargs, which is not directly supported. Use %varargs instead.\n", Getattr(n, "name"), Getline(n)); } else { - String *argname=NewStringf("PARM%d_%s", largnum, Getattr(p, "name")); + String *argname = NewStringf("PARM%d_%s", largnum, Getattr(p, "name")); String *ffitype = compose_foreign_type(argtype); String *deref_ffitype; String *temp = Copy(argtype); - if(SwigType_ispointer(temp)) { + if (SwigType_ispointer(temp)) { SwigType_pop(temp); deref_ffitype = compose_foreign_type(temp); } else { @@ -2414,41 +2333,38 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { Delete(temp); // String *lisptype=get_lisp_type(argtype, argname); - String *lisptype=get_lisp_type(Getattr(p,"type"), Getattr(p,"name")); - + String *lisptype = get_lisp_type(Getattr(p, "type"), Getattr(p, "name")); + #ifdef ALLEGROCL_DEBUG - Printf(stderr,"lisptype of '%s' '%s' = '%s'\n", Getattr(p,"type"), Getattr(p,"name"), lisptype); + Printf(stderr, "lisptype of '%s' '%s' = '%s'\n", Getattr(p, "type"), Getattr(p, "name"), lisptype); #endif - + // while we're walking the parameters, generating LIN // wrapper code... - Setattr(p,"lname",NewStringf("SWIG_arg%d", largnum)); + Setattr(p, "lname", NewStringf("SWIG_arg%d", largnum)); - String *parm_code = Getattr(p,"tmap:lin"); + String *parm_code = Getattr(p, "tmap:lin"); if (parm_code) { - String *lname = Getattr(p,"lname"); + String *lname = Getattr(p, "lname"); - Printf(largs," %s",lname); - Replaceall(parm_code,"$in", argname); - Replaceall(parm_code,"$out", lname); - Replaceall(parm_code,"$in_fftype", ffitype); - Replaceall(parm_code,"$*in_fftype", deref_ffitype); - Replaceall(wrap->code,"$body", parm_code); + Printf(largs, " %s", lname); + Replaceall(parm_code, "$in", argname); + Replaceall(parm_code, "$out", lname); + Replaceall(parm_code, "$in_fftype", ffitype); + Replaceall(parm_code, "$*in_fftype", deref_ffitype); + Replaceall(wrap->code, "$body", parm_code); } - - String *dispatchtype=Getattr(n, "sym:overloaded") ? - dispatching_type(p) : - NewString(""); + + String *dispatchtype = Getattr(n, "sym:overloaded") ? dispatching_type(p) : NewString(""); // if this parameter has been removed from the C/++ wrapper // it shouldn't be in the lisp wrapper either. - if(!checkAttribute(p,"tmap:in:numinputs","0")) { - Printf(f_cl, "(%s %s %s %s %s)", + if (!checkAttribute(p, "tmap:in:numinputs", "0")) { + Printf(f_cl, "(%s %s %s %s %s)", // parms in the ff wrapper, but not in the lisp wrapper. - (checkAttribute(p,"tmap:lin:numinputs","0") ? ":p-" : ":p+"), - argname, dispatchtype, ffitype, lisptype); - - first=0; + (checkAttribute(p, "tmap:lin:numinputs", "0") ? ":p-" : ":p+"), argname, dispatchtype, ffitype, lisptype); + + first = 0; } Delete(ffitype); @@ -2456,39 +2372,38 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { } } - Printf(wrap->locals,"%s",largs); + Printf(wrap->locals, "%s", largs); } - String *lout = Getattr(n,"tmap:lout"); + String *lout = Getattr(n, "tmap:lout"); Replaceall(lout, "$owner", GetFlag(n, "feature:new") ? "t" : "nil"); - Replaceall(wrap->code,"$body", lout); + Replaceall(wrap->code, "$body", lout); // $lclass handling. - String *lclass = (String *)0; - SwigType *parsed = Swig_cparse_type(Getattr(n,"tmap:ctype")); + String *lclass = (String *) 0; + SwigType *parsed = Swig_cparse_type(Getattr(n, "tmap:ctype")); // SwigType *cl_t = SwigType_typedef_resolve_all(parsed); SwigType *cl_t = class_from_class_or_class_ref(parsed); String *out_ffitype = compose_foreign_type(parsed); String *deref_out_ffitype; String *out_temp = Copy(parsed); - if(SwigType_ispointer(out_temp)) { + if (SwigType_ispointer(out_temp)) { SwigType_pop(out_temp); deref_out_ffitype = compose_foreign_type(out_temp); } else { deref_out_ffitype = Copy(out_ffitype); } - + Delete(out_temp); Delete(parsed); int isPtrReturn = 0; - if(cl_t) { + if (cl_t) { lclass = lookup_defined_foreign_ltype(cl_t); isPtrReturn = 1; } - // if (SwigType_ispointer(cl_t)) { // isPtrReturn = 1; // SwigType_pop(cl_t); @@ -2496,67 +2411,63 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { // } int ff_foreign_ptr = 0; - if(!lclass) { + if (!lclass) { ff_foreign_ptr = 1; lclass = NewStringf("ff:foreign-pointer"); } - #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"for output wrapping %s: type=%s, ctype=%s\n", - Getattr(n,"name"), Getattr(n,"type"), - Swig_cparse_type(Getattr(n,"tmap:ctype"))); -#endif + Printf(stderr, "for output wrapping %s: type=%s, ctype=%s\n", Getattr(n, "name"), Getattr(n, "type"), Swig_cparse_type(Getattr(n, "tmap:ctype"))); +#endif - if(lclass) Replaceall(wrap->code,"$lclass", lclass); - if(out_ffitype) Replaceall(wrap->code,"$out_fftype", out_ffitype); - if(deref_out_ffitype) Replaceall(wrap->code,"$*out_fftype", deref_out_ffitype); + if (lclass) + Replaceall(wrap->code, "$lclass", lclass); + if (out_ffitype) + Replaceall(wrap->code, "$out_fftype", out_ffitype); + if (deref_out_ffitype) + Replaceall(wrap->code, "$*out_fftype", deref_out_ffitype); // if(Replaceall(wrap->code,"$lclass", lclass) && !isPtrReturn) { // Swig_warning(WARN_LANG_RETURN_TYPE,Getfile(n), Getline(n), // "While Wrapping %s, replaced a $lclass reference when return type is non-pointer %s!\n", // Getattr(n,"name"), cl_t); // } - Replaceall(wrap->code,"$body", NewStringf("(swig-ff-call%s)", wrap->locals)); + Replaceall(wrap->code, "$body", NewStringf("(swig-ff-call%s)", wrap->locals)); // Replaceall(wrap->code,"$body", -// (!Strcmp(result_type,"void") ? -// NewStringf("(swig-ff-call%s)", wrap->locals) : -// NewStringf("(push (swig-ff-call%s) ACL_result)", wrap->locals))); - String* ldestructor = Copy(lclass); +// (!Strcmp(result_type,"void") ? +// NewStringf("(swig-ff-call%s)", wrap->locals) : +// NewStringf("(push (swig-ff-call%s) ACL_result)", wrap->locals))); + String *ldestructor = Copy(lclass); if (ff_foreign_ptr) Replaceall(ldestructor, ldestructor, "identity"); else Replaceall(ldestructor, ":type :class", ":type :destructor"); - if (Replaceall(wrap->code,"$ldestructor", ldestructor) > 0 && - ff_foreign_ptr) { + if (Replaceall(wrap->code, "$ldestructor", ldestructor) > 0 && ff_foreign_ptr) { Swig_warning(WARN_LANG_RETURN_TYPE, Getfile(n), Getline(n), - "While wrapping %s, replaced an $ldestructor reference " - "when there was no Lisp class.\n", - Getattr(n,"name")); + "While wrapping %s, replaced an $ldestructor reference " "when there was no Lisp class.\n", Getattr(n, "name")); } Delete(ldestructor); - - Printf(f_cl, ")\n"); /* finish arg list */ + + Printf(f_cl, ")\n"); /* finish arg list */ ///////////////////////////////////////////////////// // Lisp foreign call return type and optimizations // ///////////////////////////////////////////////////// - Printf(f_cl, " (:returning (%s %s)", - compose_foreign_type(result_type), - get_lisp_type(Getattr(n, "type"), "result")); - + Printf(f_cl, " (:returning (%s %s)", compose_foreign_type(result_type), get_lisp_type(Getattr(n, "type"), "result")); + for (Iterator option = First(n); option.item; option = Next(option)) { - if (Strncmp("feature:ffargs:", option.key, 15)) continue; + if (Strncmp("feature:ffargs:", option.key, 15)) + continue; String *option_val = option.item; String *option_name = NewString(Char(option.key) + 14); Replaceall(option_name, "_", "-"); - + // TODO: varargs vs call-direct ? Printf(f_cl, "\n %s %s", option_name, option_val); - + Delete(option_name); } - Printf(f_cl,")\n %s)\n\n", wrap->code); + Printf(f_cl, ")\n %s)\n\n", wrap->code); // Wrapper_print(wrap, stderr); Delete(result_type); @@ -2564,29 +2475,27 @@ int ALLEGROCL :: emit_defun(Node *n, File *f_cl) { Delete(pl); #ifdef ALLEGROCL_WRAP_DEBUG - Printf(stderr,"emit_defun: EXIT\n"); + Printf(stderr, "emit_defun: EXIT\n"); #endif return SWIG_OK; } -int ALLEGROCL :: functionWrapper(Node *n) { +int ALLEGROCL::functionWrapper(Node *n) { - ParmList *parms = CopyParmList(Getattr(n,"parms")); + ParmList *parms = CopyParmList(Getattr(n, "parms")); Wrapper *wrap = NewWrapper(); - String *raw_return_type = Swig_typemap_lookup_new("ctype",n,"",0); + String *raw_return_type = Swig_typemap_lookup_new("ctype", n, "", 0); SwigType *return_type = Swig_cparse_type(raw_return_type); SwigType *resolved = SwigType_typedef_resolve_all(return_type); int is_void_return = (Cmp(resolved, "void") == 0); Delete(resolved); - if (!is_void_return) - { + if (!is_void_return) { String *lresult_init = NewStringf("lresult = (%s)0", raw_return_type); - Wrapper_add_localv(wrap,"lresult", raw_return_type, lresult_init, NIL); + Wrapper_add_localv(wrap, "lresult", raw_return_type, lresult_init, NIL); Delete(lresult_init); } - // Emit all of the local variables for holding arguments. emit_args(Getattr(n, "type"), parms, wrap); @@ -2596,11 +2505,11 @@ int ALLEGROCL :: functionWrapper(Node *n) { emit_attach_parmmaps(parms, wrap); String *mangled = mangle_name(n); - Node *overloaded = Getattr(n,"sym:overloaded"); + Node *overloaded = Getattr(n, "sym:overloaded"); // Parameter overloading - Setattr(n,"wrap:parms", parms); - Setattr(n,"wrap:name", mangled); + Setattr(n, "wrap:parms", parms); + Setattr(n, "wrap:name", mangled); if (overloaded) { // emit warnings when overloading is impossible on the lisp side. @@ -2610,61 +2519,62 @@ int ALLEGROCL :: functionWrapper(Node *n) { if (Getattr(n, "overload:ignore")) { // if we're the last overload, make sure to force the emit // of the rest of the overloads before we leave. - Printf(stderr, "ignored overload %s(%x)\n", Getattr(n,"name"), - Getattr(n,"sym:nextSibling")); - if(!Getattr(n,"sym:nextSibling")) { + Printf(stderr, "ignored overload %s(%x)\n", Getattr(n, "name"), Getattr(n, "sym:nextSibling")); + if (!Getattr(n, "sym:nextSibling")) { update_package_if_needed(n); - emit_buffered_defuns(n); - emit_dispatch_defun(n); + emit_buffered_defuns(n); + emit_dispatch_defun(n); } return SWIG_OK; } } - // Get number of required and total arguments int num_arguments = emit_num_arguments(parms); int gencomma = 0; #ifdef ALLEGROCL_DEBUG - Printf(stderr,"Walking parameters for %s '%s'\n", Getattr(n,"allegrocl:kind"), Getattr(n,"name")); + Printf(stderr, "Walking parameters for %s '%s'\n", Getattr(n, "allegrocl:kind"), Getattr(n, "name")); #endif // Now walk the function parameter list and generate code to get arguments String *name_and_parms = NewStringf("%s (", mangled); - int i; Parm *p; - for (i = 0, p=parms; i < num_arguments; i++) { + int i; + Parm *p; + for (i = 0, p = parms; i < num_arguments; i++) { - while (p && checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (p && checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - if(!p) break; + if (!p) + break; SwigType *c_parm_type = Swig_cparse_type(Getattr(p, "tmap:ctype")); - String *arg = NewStringf("l%s", Getattr(p,"lname")); + String *arg = NewStringf("l%s", Getattr(p, "lname")); // Emit parameter declaration - if (gencomma) Printf(name_and_parms, ", "); + if (gencomma) + Printf(name_and_parms, ", "); String *parm_decl = SwigType_str(c_parm_type, arg); Printf(name_and_parms, "%s", parm_decl); #ifdef ALLEGROCL_DEBUG - Printf(stderr," param: %s\n", parm_decl); + Printf(stderr, " param: %s\n", parm_decl); #endif Delete(parm_decl); gencomma = 1; // Emit parameter conversion code - String *parm_code = Getattr(p,"tmap:in"); + String *parm_code = Getattr(p, "tmap:in"); //if (!parm_code) { // Swig_warning(...); // p = nextSibling(p); - /*} else*/ { + /*} else */ { // canThrow(n, "in", p); - Replaceall(parm_code,"$input", arg); - Setattr(p,"emit:input", arg); - Printf(wrap->code,"%s\n", parm_code); - p = Getattr(p,"tmap:in:next"); + Replaceall(parm_code, "$input", arg); + Setattr(p, "emit:input", arg); + Printf(wrap->code, "%s\n", parm_code); + p = Getattr(p, "tmap:in:next"); } - + Delete(arg); } Printf(name_and_parms, ")"); @@ -2673,32 +2583,31 @@ int ALLEGROCL :: functionWrapper(Node *n) { String *signature = SwigType_str(return_type, name_and_parms); Printf(wrap->def, "EXPORT %s {", signature); if (CPlusPlus) - Printf(wrap->code," try {\n"); + Printf(wrap->code, " try {\n"); emit_action(n, wrap); - if (!is_void_return) - { - String *result_convert = Swig_typemap_lookup_new("out",n,"result",0); + if (!is_void_return) { + String *result_convert = Swig_typemap_lookup_new("out", n, "result", 0); Replaceall(result_convert, "$result", "lresult"); Printf(wrap->code, "%s\n", result_convert); Printf(wrap->code, " return lresult;\n"); Delete(result_convert); } if (CPlusPlus) { - Printf(wrap->code," } catch (...) {\n"); + Printf(wrap->code, " } catch (...) {\n"); if (!is_void_return) - Printf(wrap->code," return (%s)0;\n", raw_return_type); - Printf(wrap->code," }\n"); + Printf(wrap->code, " return (%s)0;\n", raw_return_type); + Printf(wrap->code, " }\n"); } - Printf(wrap->code,"}\n"); + Printf(wrap->code, "}\n"); /* print this when in C mode? make this a command-line arg? */ - if (Generate_Wrapper) + if (Generate_Wrapper) Wrapper_print(wrap, f_cxx); - String *f_buffer = NewString(""); - - emit_defun(n,f_buffer); - Setattr(n,"allegrocl:lisp-wrap",f_buffer); + String *f_buffer = NewString(""); + + emit_defun(n, f_buffer); + Setattr(n, "allegrocl:lisp-wrap", f_buffer); if (!overloaded || !Getattr(n, "sym:nextSibling")) { update_package_if_needed(n); @@ -2712,16 +2621,17 @@ int ALLEGROCL :: functionWrapper(Node *n) { return SWIG_OK; } -int ALLEGROCL :: namespaceDeclaration(Node *n) { +int ALLEGROCL::namespaceDeclaration(Node *n) { // Empty namespaces are not worth DEFPACKAGEing. // Swig_print_node(n); #ifdef ALLEGROCL_DEBUG Printf(stderr, "namespaceDecl: '%s'(0x%x) (fc=0x%x)\n", Getattr(n, "sym:name"), n, firstChild(n)); #endif - if (!firstChild(n)) return SWIG_OK; - - String *name=Getattr(n, "sym:name"); + if (!firstChild(n)) + return SWIG_OK; + + String *name = Getattr(n, "sym:name"); String *old_namespace = current_namespace; if (Cmp(current_namespace, "") == 0) @@ -2729,8 +2639,7 @@ int ALLEGROCL :: namespaceDeclaration(Node *n) { else current_namespace = NewStringf("%s::%s", current_namespace, name); - if (!GetInt(defined_namespace_packages, current_namespace)) - { + if (!GetInt(defined_namespace_packages, current_namespace)) { SetInt(defined_namespace_packages, current_namespace, 1); String *lispy_namespace = listify_namespace(current_namespace); Printf(f_clhead, "(swig-defpackage %s)\n", lispy_namespace); @@ -2744,124 +2653,118 @@ int ALLEGROCL :: namespaceDeclaration(Node *n) { return SWIG_OK; } -int ALLEGROCL :: constructorHandler(Node *n) -{ +int ALLEGROCL::constructorHandler(Node *n) { #ifdef ALLEGROCL_DEBUG Printf(stderr, "constructor %s\n", Getattr(n, "name")); #endif // Swig_print_node(n); Setattr(n, "allegrocl:kind", "constructor"); Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); - + // Let SWIG generate a global forwarding function. return Language::constructorHandler(n); } -int ALLEGROCL :: destructorHandler(Node *n) -{ +int ALLEGROCL::destructorHandler(Node *n) { #ifdef ALLEGROCL_DEBUG Printf(stderr, "destructor %s\n", Getattr(n, "name")); #endif - + Setattr(n, "allegrocl:kind", "destructor"); Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); - + // Let SWIG generate a global forwarding function. return Language::destructorHandler(n); } -int ALLEGROCL :: constantWrapper(Node *n) { +int ALLEGROCL::constantWrapper(Node *n) { #ifdef ALLEGROCL_DEBUG Printf(stderr, "constant %s\n", Getattr(n, "name")); #endif - if(Generate_Wrapper) { + if (Generate_Wrapper) { // Setattr(n,"wrap:name",mangle_name(n, "ACLPP")); - String *const_type = Getattr(n,"type"); + String *const_type = Getattr(n, "type"); String *const_val = 0; - String *raw_const = Getattr(n,"value"); + String *raw_const = Getattr(n, "value"); - if(SwigType_type(const_type) == T_STRING) { - const_val = NewStringf("\"%s\"",raw_const); + if (SwigType_type(const_type) == T_STRING) { + const_val = NewStringf("\"%s\"", raw_const); } else if (SwigType_type(const_type) == T_CHAR) { - const_val = NewStringf("'%s'",raw_const); + const_val = NewStringf("'%s'", raw_const); } else { const_val = Copy(raw_const); } - SwigType_add_qualifier(const_type,"const"); - SwigType_add_qualifier(const_type,"static"); - - String *ppcname = NewStringf("ACLppc_%s",Getattr(n,"name")); - Printf(f_cxx,"static const %s = %s;\n", SwigType_lstr(const_type,ppcname), - const_val); + SwigType_add_qualifier(const_type, "const"); + SwigType_add_qualifier(const_type, "static"); - Setattr(n,"name",ppcname); - SetFlag(n,"feature:immutable"); + String *ppcname = NewStringf("ACLppc_%s", Getattr(n, "name")); + Printf(f_cxx, "static const %s = %s;\n", SwigType_lstr(const_type, ppcname), const_val); + + Setattr(n, "name", ppcname); + SetFlag(n, "feature:immutable"); Delete(const_val); return variableWrapper(n); } - String *type=Getattr(n, "type"); - String *value = Getattr(n,"value"); - String *converted_value=convert_literal(value, type); - String *name=Getattr(n, "sym:name"); + String *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + String *converted_value = convert_literal(value, type); + String *name = Getattr(n, "sym:name"); Setattr(n, "allegrocl:kind", "constant"); Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); - + #if 0 - Printf(stdout, "constant %s is of type %s. value: %s\n", - name, type, converted_value); + Printf(stdout, "constant %s is of type %s. value: %s\n", name, type, converted_value); #endif - if(converted_value) { - Printf(f_clwrap, "(swig-defconstant \"%s\" %s)\n", - name, converted_value); + if (converted_value) { + Printf(f_clwrap, "(swig-defconstant \"%s\" %s)\n", name, converted_value); } else { - Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n), - "Unable to parse constant value '%s'. Setting to NIL\n", value); + Swig_warning(WARN_LANG_DISCARD_CONST, Getfile(n), Getline(n), "Unable to parse constant value '%s'. Setting to NIL\n", value); Printf(f_clwrap, "(swig-defconstant \"%s\" nil #| %s |#)\n", name, value); } Delete(converted_value); - + return SWIG_OK; } -int ALLEGROCL :: globalvariableHandler(Node *n) { - if(Generate_Wrapper) return Language::globalvariableHandler(n); +int ALLEGROCL::globalvariableHandler(Node *n) { + if (Generate_Wrapper) + return Language::globalvariableHandler(n); // String *name = Getattr(n, "name"); - SwigType *type = Getattr(n,"type"); + SwigType *type = Getattr(n, "type"); SwigType *ctype; SwigType *rtype = SwigType_typedef_resolve_all(type); int pointer_added = 0; - if(SwigType_isclass(rtype)) { + if (SwigType_isclass(rtype)) { SwigType_add_pointer(type); SwigType_add_pointer(rtype); pointer_added = 1; } - ctype = SwigType_str(type,0); + ctype = SwigType_str(type, 0); // EXPORT ; // = ; // Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, - // ctype, mangled_name, (pointer_added ? "&" : ""), name); + // ctype, mangled_name, (pointer_added ? "&" : ""), name); Printf(f_clwrap, "(swig-defvar \"%s\" \"%s\" :type %s)\n", - Getattr(n,"sym:name"), Getattr(n,"sym:name"), - ((SwigType_isconst(type)) ? ":constant" : ":variable")); + Getattr(n, "sym:name"), Getattr(n, "sym:name"), ((SwigType_isconst(type)) ? ":constant" : ":variable")); return SWIG_OK; } -int ALLEGROCL :: variableWrapper(Node *n) { +int ALLEGROCL::variableWrapper(Node *n) { #ifdef ALLEGROCL_DEBUG Printf(stderr, "variable %s\n", Getattr(n, "name")); #endif @@ -2869,10 +2772,11 @@ int ALLEGROCL :: variableWrapper(Node *n) { Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); // Let SWIG generate a get/set function pair. - if(Generate_Wrapper) return Language::variableWrapper(n); + if (Generate_Wrapper) + return Language::variableWrapper(n); String *name = Getattr(n, "name"); - SwigType *type = Getattr(n,"type"); + SwigType *type = Getattr(n, "type"); SwigType *ctype; SwigType *rtype = SwigType_typedef_resolve_all(type); @@ -2880,35 +2784,31 @@ int ALLEGROCL :: variableWrapper(Node *n) { int pointer_added = 0; - if(SwigType_isclass(rtype)) { + if (SwigType_isclass(rtype)) { SwigType_add_pointer(type); SwigType_add_pointer(rtype); pointer_added = 1; } - ctype = SwigType_str(type,0); + ctype = SwigType_str(type, 0); // EXPORT ; // = ; - Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, - ctype, mangled_name, (pointer_added ? "&" : ""), name); + Printf(f_cxx, "EXPORT %s %s;\n%s %s = %s%s;\n", ctype, mangled_name, ctype, mangled_name, (pointer_added ? "&" : ""), name); - Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", - mangled_name, - ((SwigType_isconst(type)) ? ":constant" : ":variable")); + Printf(f_cl, "(swig-defvar \"%s\" :type %s)\n", mangled_name, ((SwigType_isconst(type)) ? ":constant" : ":variable")); /* - Printf(f_cxx, "// swigtype: %s\n", SwigType_typedef_resolve_all(Getattr(n,"type"))); - Printf(f_cxx, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype)))); - */ + Printf(f_cxx, "// swigtype: %s\n", SwigType_typedef_resolve_all(Getattr(n,"type"))); + Printf(f_cxx, "// vwrap: %s\n", compose_foreign_type(SwigType_strip_qualifiers(Copy(rtype)))); + */ Delete(mangled_name); return SWIG_OK; } -int ALLEGROCL :: memberfunctionHandler(Node *n) { +int ALLEGROCL::memberfunctionHandler(Node *n) { #ifdef ALLEGROCL_DEBUG - Printf(stderr, "member function %s::%s\n", - Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); + Printf(stderr, "member function %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); #endif Setattr(n, "allegrocl:kind", "member function"); Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); @@ -2917,10 +2817,9 @@ int ALLEGROCL :: memberfunctionHandler(Node *n) { return Language::memberfunctionHandler(n); } -int ALLEGROCL :: membervariableHandler(Node *n) { +int ALLEGROCL::membervariableHandler(Node *n) { #ifdef ALLEGROCL_DEBUG - Printf(stderr, "member variable %s::%s\n", - Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); + Printf(stderr, "member variable %s::%s\n", Getattr(parent_node_skipping_extends(n), "name"), Getattr(n, "name")); #endif Setattr(n, "allegrocl:kind", "member variable"); Setattr(n, "allegrocl:old-sym:name", Getattr(n, "sym:name")); @@ -2929,86 +2828,79 @@ int ALLEGROCL :: membervariableHandler(Node *n) { return Language::membervariableHandler(n); } -int ALLEGROCL :: typedefHandler(Node *n) { +int ALLEGROCL::typedefHandler(Node *n) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"In typedefHAND\n"); + Printf(stderr, "In typedefHAND\n"); // Swig_print_node(n); -#endif +#endif // has the side-effect of noting any implicit // template instantiations in type. - Delete(compose_foreign_type(Getattr(n,"type"))); + Delete(compose_foreign_type(Getattr(n, "type"))); - String *sym_name = Getattr(n,"sym:name"); + String *sym_name = Getattr(n, "sym:name"); String *name; String *type_ref; - if(in_class) { + if (in_class) { #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class,"sym:name"),in_class); -#endif - Setattr(n,"allegrocl:typedef:in-class",in_class); + Printf(stderr, " typedef in class '%s'(%x)\n", Getattr(in_class, "sym:name"), in_class); +#endif + Setattr(n, "allegrocl:typedef:in-class", in_class); } - if(in_class) { - String *class_name = Getattr(in_class,"name"); - name = NewStringf("%s__%s",class_name,sym_name); + if (in_class) { + String *class_name = Getattr(in_class, "name"); + name = NewStringf("%s__%s", class_name, sym_name); type_ref = NewStringf("%s::%s", class_name, sym_name); - Setattr(n,"allegrocl:in-class",in_class); + Setattr(n, "allegrocl:in-class", in_class); } else { name = Copy(sym_name); - type_ref = Copy(Getattr(n,"name")); + type_ref = Copy(Getattr(n, "name")); } - Setattr(n,"allegrocl:namespace",current_namespace); + Setattr(n, "allegrocl:namespace", current_namespace); add_defined_foreign_type(n, 0, type_ref, name); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"Out typedefHAND\n"); -#endif + Printf(stderr, "Out typedefHAND\n"); +#endif return SWIG_OK; } // forward referenced classes are added specially to defined_foreign_types -int ALLEGROCL :: classforwardDeclaration(Node *n) { +int ALLEGROCL::classforwardDeclaration(Node *n) { add_forward_referenced_type(n); return SWIG_OK; } -int ALLEGROCL :: classHandler(Node *n) { +int ALLEGROCL::classHandler(Node *n) { #ifdef ALLEGROCL_DEBUG - Printf(stderr, "class %s::%s\n", current_namespace, - Getattr(n, "sym:name")); + Printf(stderr, "class %s::%s\n", current_namespace, Getattr(n, "sym:name")); #endif - String *name=Getattr(n, "sym:name"); - String *kind = Getattr(n,"kind"); - + String *name = Getattr(n, "sym:name"); + String *kind = Getattr(n, "kind"); + // maybe just remove this check and get rid of the else clause below. - if (Strcmp(kind, "struct") == 0 || - Strcmp(kind, "class") == 0 || - Strcmp(kind, "union") == 0) - { + if (Strcmp(kind, "struct") == 0 || Strcmp(kind, "class") == 0 || Strcmp(kind, "union") == 0) { if (Generate_Wrapper) return cppClassHandler(n); else return cClassHandler(n); - } - else - { - Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", - kind); + } else { + Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind); Printf(stderr, " (name: %s)\n", name); SWIG_exit(EXIT_FAILURE); return SWIG_OK; } - + return SWIG_OK; } -int ALLEGROCL :: cClassHandler(Node *n) { +int ALLEGROCL::cClassHandler(Node *n) { // String *cDeclName = Getattr(n,"classDeclaration:name"); // String *name= Getattr(n, "sym:name"); // String *kind = Getattr(n,"kind"); @@ -3019,21 +2911,21 @@ int ALLEGROCL :: cClassHandler(Node *n) { String *ns = listify_namespace(current_namespace); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"In cClassHAND\n"); -#endif + Printf(stderr, "In cClassHAND\n"); +#endif add_defined_foreign_type(n); Delete(ns); #ifdef ALLEGROCL_TYPE_DEBUG - Printf(stderr,"Out cClassHAND\n"); -#endif + Printf(stderr, "Out cClassHAND\n"); +#endif return SWIG_OK; } -int ALLEGROCL :: cppClassHandler(Node *n) { +int ALLEGROCL::cppClassHandler(Node *n) { // String *name=Getattr(n, "sym:name"); // String *kind = Getattr(n,"kind"); @@ -3046,37 +2938,37 @@ int ALLEGROCL :: cppClassHandler(Node *n) { The %template directive results in a templated class instantiation that will actually be seen by :: classHandler(). - + In this case, we don't want to error if the type already exists; the point is to force the creation of wrappers for the templated class. - */ - String *templated = Getattr(n,"template"); + */ + String *templated = Getattr(n, "template"); String *t_name; // String *ns = listify_namespace(current_namespace); - if(templated) { + if (templated) { t_name = namespaced_name(n); // t_name = Getattr(n,"name"); } else { - t_name = Getattr(n,"name"); + t_name = Getattr(n, "name"); } - Setattr(n,"allegrocl:namespace",current_namespace); - + Setattr(n, "allegrocl:namespace", current_namespace); + /* Add this structure to the known lisp types. Class may contain references to the type currently being defined */ - if(!templated || !lookup_defined_foreign_type(t_name)) { + if (!templated || !lookup_defined_foreign_type(t_name)) { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "Adding %s foreign type\n", Getattr(n,"sym:name")); -#endif + Printf(stderr, "Adding %s foreign type\n", Getattr(n, "sym:name")); +#endif add_defined_foreign_type(n); } else { #ifdef ALLEGROCL_CLASS_DEBUG - Printf(stderr, "cppClassHand: type %s already exists. Assuming %%template instantiation for wrapping purposes.\n", Getattr(n,"sym:name")); + Printf(stderr, "cppClassHand: type %s already exists. Assuming %%template instantiation for wrapping purposes.\n", Getattr(n, "sym:name")); #endif - add_defined_foreign_type(n,1); + add_defined_foreign_type(n, 1); } // mjb - for real fun, generate wrappers for class slot access. @@ -3090,12 +2982,12 @@ int ALLEGROCL :: cppClassHandler(Node *n) { #ifdef ALLEGROCL_CLASS_DEBUG Printf(stderr, " MANUALLY walking class members... \n"); #endif - for(c=firstChild(n); c; c=nextSibling(c)) { + for (c = firstChild(n); c; c = nextSibling(c)) { // ping the types of all children--even protected and private // so their types can be added to the linked_type_list. - SwigType *childType = NewStringf("%s%s", Getattr(c,"decl"), - Getattr(c,"type")); - if(!SwigType_isfunction(childType)) + SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), + Getattr(c, "type")); + if (!SwigType_isfunction(childType)) Delete(compose_foreign_type(childType)); Delete(childType); @@ -3117,14 +3009,11 @@ int ALLEGROCL :: cppClassHandler(Node *n) { return SWIG_OK; } -int ALLEGROCL :: emit_one(Node *n) -{ +int ALLEGROCL::emit_one(Node *n) { // When the current package does not correspond with the current // namespace we need to generate an IN-PACKAGE form, unless the // current node is another namespace node. - if (Cmp(nodeType(n), "namespace") != 0 && - Cmp(current_package, current_namespace) != 0) - { + if (Cmp(nodeType(n), "namespace") != 0 && Cmp(current_package, current_namespace) != 0) { String *lispy_namespace = listify_namespace(current_namespace); Printf(f_clwrap, "(swig-in-package %s)\n", lispy_namespace); Delete(lispy_namespace); @@ -3132,36 +3021,35 @@ int ALLEGROCL :: emit_one(Node *n) current_package = NewStringf("%s", current_namespace); } - Setattr(n,"allegrocl:package",current_package); + Setattr(n, "allegrocl:package", current_package); return Language::emit_one(n); } -int ALLEGROCL :: enumDeclaration(Node *n) { +int ALLEGROCL::enumDeclaration(Node *n) { - if(Getattr(n,"sym:name")) { + if (Getattr(n, "sym:name")) { add_defined_foreign_type(n); } Node *c; - for(c = firstChild(n); c; c=nextSibling(c)) { + for (c = firstChild(n); c; c = nextSibling(c)) { ALLEGROCL::enumvalueDeclaration(c); // since we walk our own children, we need to add // the current package ourselves. - Setattr(c,"allegrocl:package",current_package); + Setattr(c, "allegrocl:package", current_package); } return SWIG_OK; } -int ALLEGROCL :: enumvalueDeclaration(Node *n) { +int ALLEGROCL::enumvalueDeclaration(Node *n) { /* print this when in C mode? make this a command-line arg? */ - if(Generate_Wrapper) { + if (Generate_Wrapper) { String *mangled_name = mangle_name(n, "ACL_ENUM"); - Printf(f_cxx, "EXPORT const %s %s = %s;\n", Getattr(n, "type"), - mangled_name, Getattr(n, "value")); + Printf(f_cxx, "EXPORT const %s %s = %s;\n", Getattr(n, "type"), mangled_name, Getattr(n, "value")); Delete(mangled_name); } @@ -3169,20 +3057,20 @@ int ALLEGROCL :: enumvalueDeclaration(Node *n) { return SWIG_OK; } -int ALLEGROCL :: templateDeclaration(Node *n) { +int ALLEGROCL::templateDeclaration(Node *n) { - String *type = Getattr(n,"templatetype"); + String *type = Getattr(n, "templatetype"); // Printf(stderr, "tempDecl: %s %s\n", Getattr(n,"name"), // type); // Swig_print_node(n); - if(!Strcmp(type,"cdecl")) { - SwigType *ty = NewStringf("%s%s",Getattr(n,"decl"), - Getattr(n,"type")); + if (!Strcmp(type, "cdecl")) { + SwigType *ty = NewStringf("%s%s", Getattr(n, "decl"), + Getattr(n, "type")); Delete(ty); } - + Delete(type); return SWIG_OK; diff --git a/SWIG/Source/Modules/allocate.cxx b/SWIG/Source/Modules/allocate.cxx index b6bdca6ac..e4f2d9e0c 100644 --- a/SWIG/Source/Modules/allocate.cxx +++ b/SWIG/Source/Modules/allocate.cxx @@ -16,7 +16,7 @@ char cvsroot_allocate_cxx[] = "$Header$"; #include "swigmod.h" #include "cparse.h" -static int virtual_elimination_mode = 0; /* set to 0 on default */ +static int virtual_elimination_mode = 0; /* set to 0 on default */ /* Set virtual_elimination_mode */ void Wrapper_virtual_elimination_mode_set(int flag) { @@ -27,35 +27,36 @@ void Wrapper_virtual_elimination_mode_set(int flag) { This is a major hack. Sorry. */ extern "C" { -static String *search_decl = 0; /* Declarator being searched */ -static int check_implemented(Node *n) { - String *decl; - if (!n) return 0; - while (n) { - if (Strcmp(nodeType(n), "cdecl") == 0) { - decl = Getattr(n,"decl"); - if (SwigType_isfunction(decl)) { - SwigType *decl1 = SwigType_typedef_resolve_all(decl); - SwigType *decl2 = SwigType_pop_function(decl1); - if (Strcmp(decl2, search_decl) == 0) { - if (!Getattr(n,"abstract")) { - Delete(decl1); - Delete(decl2); - return 1; + static String *search_decl = 0; /* Declarator being searched */ + static int check_implemented(Node *n) { + String *decl; + if (!n) + return 0; + while (n) { + if (Strcmp(nodeType(n), "cdecl") == 0) { + decl = Getattr(n, "decl"); + if (SwigType_isfunction(decl)) { + SwigType *decl1 = SwigType_typedef_resolve_all(decl); + SwigType *decl2 = SwigType_pop_function(decl1); + if (Strcmp(decl2, search_decl) == 0) { + if (!Getattr(n, "abstract")) { + Delete(decl1); + Delete(decl2); + return 1; + } } + Delete(decl1); + Delete(decl2); } - Delete(decl1); - Delete(decl2); } + n = Getattr(n, "csym:nextSibling"); } - n = Getattr(n,"csym:nextSibling"); + return 0; } - return 0; -} } -class Allocate : public Dispatcher { - Node *inclass; +class Allocate:public Dispatcher { + Node *inclass; int extendmode; /* Checks if a function, n, is the same as any in the base class, ie if the method is polymorphic. @@ -68,7 +69,7 @@ class Allocate : public Dispatcher { String *this_decl = Getattr(n, "decl"); if (!this_decl) - return 0; + return 0; String *name = Getattr(n, "name"); String *this_type = Getattr(n, "type"); @@ -76,10 +77,10 @@ class Allocate : public Dispatcher { // Search all base classes for methods with same signature for (int i = 0; i < Len(bases); i++) { - Node *b = Getitem(bases,i); - Node *base = firstChild (b); + Node *b = Getitem(bases, i); + Node *base = firstChild(b); while (base) { - if (Strcmp(nodeType(base),"extend") == 0) { + if (Strcmp(nodeType(base), "extend") == 0) { // Loop through all the %extend methods Node *extend = firstChild(base); while (extend) { @@ -89,7 +90,7 @@ class Allocate : public Dispatcher { } extend = nextSibling(extend); } - } else if (Strcmp(nodeType(base),"using") == 0) { + } else if (Strcmp(nodeType(base), "using") == 0) { // Loop through all the using declaration methods Node *usingdecl = firstChild(base); while (usingdecl) { @@ -112,7 +113,7 @@ class Allocate : public Dispatcher { Delete(resolved_decl); resolved_decl = 0; for (int j = 0; j < Len(bases); j++) { - Node *b = Getitem(bases,j); + Node *b = Getitem(bases, j); if (function_is_defined_in_bases(n, Getattr(b, "allbases"))) return 1; } @@ -128,7 +129,7 @@ class Allocate : public Dispatcher { if (checkAttribute(base, "name", name) && !GetFlag(b, "feature:ignore") /* whole class is ignored */ ) { if (SwigType_isfunction(resolved_decl) && SwigType_isfunction(base_decl)) { // We have found a method that has the same name as one in a base class - bool covariant_returntype = false; + bool covariant_returntype = false; bool returntype_match = Strcmp(base_type, this_type) == 0 ? true : false; bool decl_match = Strcmp(base_decl, this_decl) == 0 ? true : false; if (returntype_match && decl_match) { @@ -154,13 +155,12 @@ class Allocate : public Dispatcher { Delete(this_returntype); Delete(base_returntype); } - // The return types must match at this point, for the whole method to match if (returntype_match && !decl_match) { // Now need to check the parameter list // First do an inexpensive parameter count - ParmList *this_parms = Getattr(n,"parms"); - ParmList *base_parms = Getattr(base,"parms"); + ParmList *this_parms = Getattr(n, "parms"); + ParmList *base_parms = Getattr(base, "parms"); if (ParmList_len(this_parms) == ParmList_len(base_parms)) { // Number of parameters are the same, now check that all the parameters match SwigType *base_fn = NewString(""); @@ -186,8 +186,8 @@ class Allocate : public Dispatcher { if (decl_match && returntype_match) { // Found an identical method in the base class - bool this_wrapping_protected_members = is_member_director(n) ? true : false; // This should really check for dirprot rather than just being a director method - bool base_wrapping_protected_members = is_member_director(base) ? true : false; // This should really check for dirprot rather than just being a director method + bool this_wrapping_protected_members = is_member_director(n) ? true : false; // This should really check for dirprot rather than just being a director method + bool base_wrapping_protected_members = is_member_director(base) ? true : false; // This should really check for dirprot rather than just being a director method bool both_have_public_access = is_public(n) && is_public(base); bool both_have_protected_access = (is_protected(n) && this_wrapping_protected_members) && (is_protected(base) && base_wrapping_protected_members); bool both_have_private_access = is_private(n) && is_private(base); @@ -197,15 +197,14 @@ class Allocate : public Dispatcher { Setattr(n, "storage", "virtual"); if (both_have_public_access || both_have_protected_access) { - if (!is_non_public_base(inclass, b)) - Setattr(n, "override", base); // Note C# definition of override, ie access must be the same + if (!is_non_public_base(inclass, b)) + Setattr(n, "override", base); // Note C# definition of override, ie access must be the same } else if (!both_have_private_access) { // Different access if (this_wrapping_protected_members || base_wrapping_protected_members) if (!is_non_public_base(inclass, b)) - Setattr(n, "hides", base); // Note C# definition of hiding, ie hidden if access is different + Setattr(n, "hides", base); // Note C# definition of hiding, ie hidden if access is different } - // Try and find the most base's covariant return type SwigType *most_base_covariant_type = Getattr(base, "covariant"); if (!most_base_covariant_type && covariant_returntype) @@ -217,9 +216,9 @@ class Allocate : public Dispatcher { if (both_have_public_access) if (!is_non_public_base(inclass, b)) if (!Swig_symbol_isoverloaded(n)) { - // Don't eliminate if an overloaded method as this hides the method + // Don't eliminate if an overloaded method as this hides the method // in the scripting languages: the dispatch function will hide the base method if ignored. - SetFlag(n,"feature:ignore"); + SetFlag(n, "feature:ignore"); } } else { // Some languages need to know about covariant return types @@ -229,8 +228,8 @@ class Allocate : public Dispatcher { } else { // Found an identical method in the base class, but it is not polymorphic. if (both_have_public_access || both_have_protected_access) - if (!is_non_public_base(inclass, b)) - Setattr(n, "hides", base); + if (!is_non_public_base(inclass, b)) + Setattr(n, "hides", base); } if (both_have_public_access || both_have_protected_access) return 1; @@ -248,17 +247,17 @@ class Allocate : public Dispatcher { Node *bases = Getattr(n, "privatebases"); if (bases) { for (int i = 0; i < Len(bases); i++) { - Node *base = Getitem(bases,i); - if (base == b) - non_public_base = true; + Node *base = Getitem(bases, i); + if (base == b) + non_public_base = true; } } bases = Getattr(n, "protectedbases"); if (bases) { for (int i = 0; i < Len(bases); i++) { - Node *base = Getitem(bases,i); - if (base == b) - non_public_base = true; + Node *base = Getitem(bases, i); + if (base == b) + non_public_base = true; } } return non_public_base; @@ -269,9 +268,9 @@ class Allocate : public Dispatcher { Caller is responsible for deleting returned string. */ String *function_return_type(Node *n, bool resolve = true) { String *decl = Getattr(n, "decl"); - SwigType *type = Getattr(n,"type"); + SwigType *type = Getattr(n, "type"); String *ty = NewString(type); - SwigType_push(ty,decl); + SwigType_push(ty, decl); if (SwigType_isqualifier(ty)) Delete(SwigType_pop(ty)); Delete(SwigType_pop_function(ty)); @@ -285,81 +284,89 @@ class Allocate : public Dispatcher { /* Checks if a class member is the same as inherited from the class bases */ int class_member_is_defined_in_bases(Node *member, Node *classnode) { - Node *bases; /* bases is the closest ancestors of classnode */ + Node *bases; /* bases is the closest ancestors of classnode */ int defined = 0; bases = Getattr(classnode, "allbases"); - if (!bases) return 0; + if (!bases) + return 0; { int old_mode = virtual_elimination_mode; if (is_member_director(classnode, member)) virtual_elimination_mode = 0; - + if (function_is_defined_in_bases(member, bases)) { defined = 1; } - + virtual_elimination_mode = old_mode; } if (defined) return 1; - else return 0; + else + return 0; } /* Checks to see if a class is abstract through inheritance, and saves the first node that seems to be abstract. */ int is_abstract_inherit(Node *n, Node *base = 0, int first = 0) { - if (!first && (base == n)) return 0; + if (!first && (base == n)) + return 0; if (!base) { /* Root node */ - Symtab *stab = Getattr(n,"symtab"); /* Get symbol table for node */ + Symtab *stab = Getattr(n, "symtab"); /* Get symbol table for node */ Symtab *oldtab = Swig_symbol_setscope(stab); - int ret = is_abstract_inherit(n,n,1); + int ret = is_abstract_inherit(n, n, 1); Swig_symbol_setscope(oldtab); return ret; } - List *abstract = Getattr(base,"abstract"); + List *abstract = Getattr(base, "abstract"); if (abstract) { int dabstract = 0; int len = Len(abstract); for (int i = 0; i < len; i++) { - Node *nn = Getitem(abstract,i); - String *name = Getattr(nn,"name"); - if (!name) continue; - String *base_decl = Getattr(nn,"decl"); - if (base_decl) base_decl = SwigType_typedef_resolve_all(base_decl); - if (Strchr(name,'~')) continue; /* Don't care about destructors */ + Node *nn = Getitem(abstract, i); + String *name = Getattr(nn, "name"); + if (!name) + continue; + String *base_decl = Getattr(nn, "decl"); + if (base_decl) + base_decl = SwigType_typedef_resolve_all(base_decl); + if (Strchr(name, '~')) + continue; /* Don't care about destructors */ if (SwigType_isfunction(base_decl)) { search_decl = SwigType_pop_function(base_decl); } - Node *dn = Swig_symbol_clookup_local_check(name,0,check_implemented); + Node *dn = Swig_symbol_clookup_local_check(name, 0, check_implemented); Delete(search_decl); Delete(base_decl); if (!dn) { - List *nabstract = Getattr(n,"abstract"); + List *nabstract = Getattr(n, "abstract"); if (!nabstract) { nabstract = NewList(); - Setattr(n,"abstract",nabstract); + Setattr(n, "abstract", nabstract); Delete(nabstract); } - Append(nabstract,nn); - if (!Getattr(n,"abstract:firstnode")) { - Setattr(n,"abstract:firstnode",nn); + Append(nabstract, nn); + if (!Getattr(n, "abstract:firstnode")) { + Setattr(n, "abstract:firstnode", nn); } dabstract = base != n; } } - if (dabstract) return 1; + if (dabstract) + return 1; } - List *bases = Getattr(base,"allbases"); - if (!bases) return 0; + List *bases = Getattr(base, "allbases"); + if (!bases) + return 0; for (int i = 0; i < Len(bases); i++) { - if (is_abstract_inherit(n,Getitem(bases,i))) { + if (is_abstract_inherit(n, Getitem(bases, i))) { return 1; } } @@ -369,47 +376,46 @@ class Allocate : public Dispatcher { /* Grab methods used by smart pointers */ - List *smart_pointer_methods(Node *cls, List *methods, int isconst, - String *classname=0) { + List *smart_pointer_methods(Node *cls, List *methods, int isconst, String *classname = 0) { if (!methods) { methods = NewList(); } - + Node *c = firstChild(cls); - String *kind = Getattr(cls,"kind"); + String *kind = Getattr(cls, "kind"); int mode = PUBLIC; - if (kind && (Strcmp(kind,"class") == 0)) mode = PRIVATE; - + if (kind && (Strcmp(kind, "class") == 0)) + mode = PRIVATE; + while (c) { - if (Getattr(c,"error") || GetFlag(c,"feature:ignore")) { + if (Getattr(c, "error") || GetFlag(c, "feature:ignore")) { c = nextSibling(c); continue; } - if (!isconst && (Strcmp(nodeType(c),"extend") == 0)) { - methods = smart_pointer_methods(c, methods, isconst, Getattr(cls,"name")); - } else if (Strcmp(nodeType(c),"cdecl") == 0) { - if (!GetFlag(c,"feature:ignore")) { - String *storage = Getattr(c,"storage"); - if (!((Cmp(storage,"typedef") == 0)) - && !((Cmp(storage,"friend") == 0))) { - String *name = Getattr(c,"name"); - String *symname = Getattr(c,"sym:name"); - Node *e = Swig_symbol_clookup_local(name,0); - if (e && is_public(e) && !GetFlag(e,"feature:ignore") && (Cmp(symname, Getattr(e,"sym:name")) == 0)) { - Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(e),Getline(e),"Declaration of '%s' shadows declaration accessible via operator->(),\n", - name); - Swig_warning(WARN_LANG_DEREF_SHADOW,Getfile(c),Getline(c),"previous declaration of '%s'.\n", name); + if (!isconst && (Strcmp(nodeType(c), "extend") == 0)) { + methods = smart_pointer_methods(c, methods, isconst, Getattr(cls, "name")); + } else if (Strcmp(nodeType(c), "cdecl") == 0) { + if (!GetFlag(c, "feature:ignore")) { + String *storage = Getattr(c, "storage"); + if (!((Cmp(storage, "typedef") == 0)) + && !((Cmp(storage, "friend") == 0))) { + String *name = Getattr(c, "name"); + String *symname = Getattr(c, "sym:name"); + Node *e = Swig_symbol_clookup_local(name, 0); + if (e && is_public(e) && !GetFlag(e, "feature:ignore") && (Cmp(symname, Getattr(e, "sym:name")) == 0)) { + Swig_warning(WARN_LANG_DEREF_SHADOW, Getfile(e), Getline(e), "Declaration of '%s' shadows declaration accessible via operator->(),\n", name); + Swig_warning(WARN_LANG_DEREF_SHADOW, Getfile(c), Getline(c), "previous declaration of '%s'.\n", name); } else { /* Make sure node with same name doesn't already exist */ int k; int match = 0; for (k = 0; k < Len(methods); k++) { - e = Getitem(methods,k); - if (Cmp(symname,Getattr(e,"sym:name")) == 0) { + e = Getitem(methods, k); + if (Cmp(symname, Getattr(e, "sym:name")) == 0) { match = 1; break; } - if ((!symname || (!Getattr(e,"sym:name"))) && (Cmp(name,Getattr(e,"name")) == 0)) { + if ((!symname || (!Getattr(e, "sym:name"))) && (Cmp(name, Getattr(e, "name")) == 0)) { match = 1; break; } @@ -419,27 +425,27 @@ class Allocate : public Dispatcher { while (cc) { Node *cp = cc; if (classname) { - Setattr(cp,"classname",classname); + Setattr(cp, "classname", classname); } - Setattr(cp,"allocate:smartpointeraccess","1"); + Setattr(cp, "allocate:smartpointeraccess", "1"); /* If constant, we have to be careful */ if (isconst) { - SwigType *decl = Getattr(cp,"decl"); + SwigType *decl = Getattr(cp, "decl"); if (decl) { - if (SwigType_isfunction(decl)) { /* If method, we only add if it's a const method */ + if (SwigType_isfunction(decl)) { /* If method, we only add if it's a const method */ if (SwigType_isconst(decl)) { - Append(methods,cp); + Append(methods, cp); } } else { - Append(methods,cp); + Append(methods, cp); } } else { - Append(methods,cp); + Append(methods, cp); } } else { - Append(methods,cp); + Append(methods, cp); } - cc = Getattr(cc,"sym:nextSibling"); + cc = Getattr(cc, "sym:nextSibling"); } } } @@ -447,27 +453,29 @@ class Allocate : public Dispatcher { } } - if (Strcmp(nodeType(c),"access") == 0) { - kind = Getattr(c,"kind"); - if (Strcmp(kind,"public") == 0) mode = PUBLIC; - else mode = PRIVATE; + if (Strcmp(nodeType(c), "access") == 0) { + kind = Getattr(c, "kind"); + if (Strcmp(kind, "public") == 0) + mode = PUBLIC; + else + mode = PRIVATE; } c = nextSibling(c); } /* Look for methods in base classes */ { - Node *bases = Getattr(cls,"bases"); + Node *bases = Getattr(cls, "bases"); int k; for (k = 0; k < Len(bases); k++) { - smart_pointer_methods(Getitem(bases,k),methods,isconst); + smart_pointer_methods(Getitem(bases, k), methods, isconst); } } /* Remove protected/private members */ { - for (int i = 0; i < Len(methods); ) { - Node *n = Getitem(methods,i); + for (int i = 0; i < Len(methods);) { + Node *n = Getitem(methods, i); if (!is_public(n)) { - Delitem(methods,i); + Delitem(methods, i); continue; } i++; @@ -476,63 +484,62 @@ class Allocate : public Dispatcher { return methods; } - void mark_exception_classes(ParmList *p) - { - while(p) { - SwigType *ty = Getattr(p,"type"); + void mark_exception_classes(ParmList *p) { + while (p) { + SwigType *ty = Getattr(p, "type"); SwigType *t = SwigType_typedef_resolve_all(ty); if (SwigType_isreference(t) || SwigType_ispointer(t) || SwigType_isarray(t)) { Delete(SwigType_pop(t)); } - Node *c = Swig_symbol_clookup(t,0); + Node *c = Swig_symbol_clookup(t, 0); if (c) { - if (!GetFlag(c,"feature:exceptionclass")) { - SetFlag(c,"feature:exceptionclass"); + if (!GetFlag(c, "feature:exceptionclass")) { + SetFlag(c, "feature:exceptionclass"); } } p = nextSibling(p); Delete(t); } } - + void process_exceptions(Node *n) { - ParmList *catchlist = 0; + ParmList *catchlist = 0; /* the "catchlist" attribute is used to emit the block try {$action;} catch ; - + in emit.cxx and is either constructued from the "feature:catches" feature or copied from the node "throws" list. - */ - String *scatchlist = Getattr(n,"feature:catches"); + */ + String *scatchlist = Getattr(n, "feature:catches"); if (scatchlist) { catchlist = Swig_cparse_parms(scatchlist); if (catchlist) { - Setattr(n,"catchlist",catchlist); + Setattr(n, "catchlist", catchlist); mark_exception_classes(catchlist); Delete(catchlist); } } - ParmList *throws = Getattr(n,"throws"); + ParmList *throws = Getattr(n, "throws"); if (throws) { /* if there is no an explicit catchlist, - we catch everything in the throwlist */ + we catch everything in the throwlist */ if (!catchlist) { - Setattr(n,"catchlist",throws); + Setattr(n, "catchlist", throws); } - mark_exception_classes(throws); + mark_exception_classes(throws); } } public: - Allocate() : - inclass(NULL), - extendmode(0) {} +Allocate(): + inclass(NULL), extendmode(0) { + } virtual int top(Node *n) { cplus_mode = PUBLIC; @@ -542,44 +549,53 @@ public: return SWIG_OK; } - virtual int importDirective(Node *n) { return emit_children(n); } - virtual int includeDirective(Node *n) { return emit_children(n); } - virtual int externDeclaration(Node *n) { return emit_children(n); } - virtual int namespaceDeclaration(Node *n) { return emit_children(n); } + virtual int importDirective(Node *n) { + return emit_children(n); + } + virtual int includeDirective(Node *n) { + return emit_children(n); + } + virtual int externDeclaration(Node *n) { + return emit_children(n); + } + virtual int namespaceDeclaration(Node *n) { + return emit_children(n); + } virtual int extendDirective(Node *n) { - extendmode = 1; - emit_children(n); - extendmode = 0; - return SWIG_OK; + extendmode = 1; + emit_children(n); + extendmode = 0; + return SWIG_OK; } virtual int classDeclaration(Node *n) { Symtab *symtab = Swig_symbol_current(); - Swig_symbol_setscope(Getattr(n,"symtab")); + Swig_symbol_setscope(Getattr(n, "symtab")); if (!CPlusPlus) { /* Always have default constructors/destructors in C */ - Setattr(n,"allocate:default_constructor","1"); - Setattr(n,"allocate:default_destructor","1"); + Setattr(n, "allocate:default_constructor", "1"); + Setattr(n, "allocate:default_destructor", "1"); } - if (Getattr(n,"allocate:visit")) return SWIG_OK; - Setattr(n,"allocate:visit","1"); - + if (Getattr(n, "allocate:visit")) + return SWIG_OK; + Setattr(n, "allocate:visit", "1"); + /* Always visit base classes first */ { - List *bases = Getattr(n,"bases"); + List *bases = Getattr(n, "bases"); if (bases) { for (int i = 0; i < Len(bases); i++) { - Node *b = Getitem(bases,i); + Node *b = Getitem(bases, i); classDeclaration(b); } } } inclass = n; - String *kind = Getattr(n,"kind"); - if (Strcmp(kind,"class") == 0) { + String *kind = Getattr(n, "kind"); + if (Strcmp(kind, "class") == 0) { cplus_mode = PRIVATE; } else { cplus_mode = PUBLIC; @@ -590,22 +606,18 @@ public: /* Check if the class is abstract via inheritance. This might occur if a class didn't have any pure virtual methods of its own, but it didn't implement all of the pure methods in a base class */ - if (!Getattr(n,"abstract") && is_abstract_inherit(n)) { - if (((Getattr(n,"allocate:public_constructor") || (!GetFlag(n,"feature:nodefault") && !Getattr(n,"allocate:has_constructor"))))) { - if (!GetFlag(n,"feature:notabstract")) { - Node *na = Getattr(n,"abstract:firstnode"); + if (!Getattr(n, "abstract") && is_abstract_inherit(n)) { + if (((Getattr(n, "allocate:public_constructor") || (!GetFlag(n, "feature:nodefault") && !Getattr(n, "allocate:has_constructor"))))) { + if (!GetFlag(n, "feature:notabstract")) { + Node *na = Getattr(n, "abstract:firstnode"); if (na) { Swig_warning(WARN_TYPE_ABSTRACT, Getfile(n), Getline(n), - "Class '%s' might be abstract, " - "no constructors generated,\n", - SwigType_namestr(Getattr(n,"name"))); - Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), - " method '%s' might not be implemented.", - SwigType_namestr(Getattr(na,"name"))); - if (!Getattr(n,"abstract")) { + "Class '%s' might be abstract, " "no constructors generated,\n", SwigType_namestr(Getattr(n, "name"))); + Swig_warning(WARN_TYPE_ABSTRACT, Getfile(na), Getline(na), " method '%s' might not be implemented.", SwigType_namestr(Getattr(na, "name"))); + if (!Getattr(n, "abstract")) { List *abstract = NewList(); - Append(abstract,na); - Setattr(n,"abstract",abstract); + Append(abstract, na); + Setattr(n, "abstract", abstract); Delete(abstract); } } @@ -613,133 +625,133 @@ public: } } - if (!Getattr(n,"allocate:has_constructor")) { + if (!Getattr(n, "allocate:has_constructor")) { /* No constructor is defined. We need to check a few things */ /* If class is abstract. No default constructor. Sorry */ - if (Getattr(n,"abstract")) { - Delattr(n,"allocate:default_constructor"); + if (Getattr(n, "abstract")) { + Delattr(n, "allocate:default_constructor"); } - if (!Getattr(n,"allocate:default_constructor")) { + if (!Getattr(n, "allocate:default_constructor")) { /* Check base classes */ - List *bases = Getattr(n,"allbases"); - int allows_default = 1; - + List *bases = Getattr(n, "allbases"); + int allows_default = 1; + for (int i = 0; i < Len(bases); i++) { - Node *n = Getitem(bases,i); + Node *n = Getitem(bases, i); /* If base class does not allow default constructor, we don't allow it either */ - if (!Getattr(n,"allocate:default_constructor") && (!Getattr(n,"allocate:default_base_constructor"))) { + if (!Getattr(n, "allocate:default_constructor") && (!Getattr(n, "allocate:default_base_constructor"))) { allows_default = 0; } } if (allows_default) { - Setattr(n,"allocate:default_constructor","1"); + Setattr(n, "allocate:default_constructor", "1"); } } - } - if (!Getattr(n,"allocate:has_copy_constructor")) { - if (Getattr(n,"abstract")) { - Delattr(n,"allocate:copy_constructor"); + } + if (!Getattr(n, "allocate:has_copy_constructor")) { + if (Getattr(n, "abstract")) { + Delattr(n, "allocate:copy_constructor"); } - if (!Getattr(n,"allocate:copy_constructor")) { + if (!Getattr(n, "allocate:copy_constructor")) { /* Check base classes */ - List *bases = Getattr(n,"allbases"); - int allows_copy = 1; - + List *bases = Getattr(n, "allbases"); + int allows_copy = 1; + for (int i = 0; i < Len(bases); i++) { - Node *n = Getitem(bases,i); + Node *n = Getitem(bases, i); /* If base class does not allow copy constructor, we don't allow it either */ - if (!Getattr(n,"allocate:copy_constructor") && (!Getattr(n,"allocate:copy_base_constructor"))) { + if (!Getattr(n, "allocate:copy_constructor") && (!Getattr(n, "allocate:copy_base_constructor"))) { allows_copy = 0; } } if (allows_copy) { - Setattr(n,"allocate:copy_constructor","1"); + Setattr(n, "allocate:copy_constructor", "1"); } } } - - if (!Getattr(n,"allocate:has_destructor")) { + + if (!Getattr(n, "allocate:has_destructor")) { /* No destructor was defined. We need to check a few things here too */ - List *bases = Getattr(n,"allbases"); + List *bases = Getattr(n, "allbases"); int allows_destruct = 1; for (int i = 0; i < Len(bases); i++) { - Node *n = Getitem(bases,i); + Node *n = Getitem(bases, i); /* If base class does not allow default destructor, we don't allow it either */ - if (!Getattr(n,"allocate:default_destructor") && (!Getattr(n,"allocate:default_base_destructor"))) { + if (!Getattr(n, "allocate:default_destructor") && (!Getattr(n, "allocate:default_base_destructor"))) { allows_destruct = 0; } } if (allows_destruct) { - Setattr(n,"allocate:default_destructor","1"); + Setattr(n, "allocate:default_destructor", "1"); } } - if (!Getattr(n,"allocate:has_assign")) { + if (!Getattr(n, "allocate:has_assign")) { /* No destructor was defined. We need to check a few things here too */ - List *bases = Getattr(n,"allbases"); + List *bases = Getattr(n, "allbases"); int allows_assign = 1; for (int i = 0; i < Len(bases); i++) { - Node *n = Getitem(bases,i); + Node *n = Getitem(bases, i); /* If base class does not allow default destructor, we don't allow it either */ - if (Getattr(n,"allocate:has_assign")) { - allows_assign = !Getattr(n,"allocate:noassign"); + if (Getattr(n, "allocate:has_assign")) { + allows_assign = !Getattr(n, "allocate:noassign"); } } if (!allows_assign) { - Setattr(n,"allocate:noassign","1"); + Setattr(n, "allocate:noassign", "1"); } } - if (!Getattr(n,"allocate:has_new")) { + if (!Getattr(n, "allocate:has_new")) { /* No destructor was defined. We need to check a few things here too */ - List *bases = Getattr(n,"allbases"); + List *bases = Getattr(n, "allbases"); int allows_new = 1; for (int i = 0; i < Len(bases); i++) { - Node *n = Getitem(bases,i); + Node *n = Getitem(bases, i); /* If base class does not allow default destructor, we don't allow it either */ - if (Getattr(n,"allocate:has_new")) { - allows_new = !Getattr(n,"allocate:nonew"); + if (Getattr(n, "allocate:has_new")) { + allows_new = !Getattr(n, "allocate:nonew"); } } if (!allows_new) { - Setattr(n,"allocate:nonew","1"); + Setattr(n, "allocate:nonew", "1"); } } /* Check if base classes allow smart pointers, but might be hidden */ - if (!Getattr(n,"allocate:smartpointer")) { - Node *sp = Swig_symbol_clookup((char*)"operator ->",0); + if (!Getattr(n, "allocate:smartpointer")) { + Node *sp = Swig_symbol_clookup((char *) "operator ->", 0); if (sp) { - /* Look for parent */ + /* Look for parent */ Node *p = parentNode(sp); - if (Strcmp(nodeType(p),"extend") == 0) { + if (Strcmp(nodeType(p), "extend") == 0) { p = parentNode(p); } - if (Strcmp(nodeType(p),"class") == 0) { - if (GetFlag(p,"feature:ignore")) { - Setattr(n,"allocate:smartpointer",Getattr(p,"allocate:smartpointer")); + if (Strcmp(nodeType(p), "class") == 0) { + if (GetFlag(p, "feature:ignore")) { + Setattr(n, "allocate:smartpointer", Getattr(p, "allocate:smartpointer")); } } } } /* Only care about default behavior. Remove temporary values */ - Setattr(n,"allocate:visit","1"); + Setattr(n, "allocate:visit", "1"); inclass = 0; Swig_symbol_setscope(symtab); return SWIG_OK; } virtual int accessDeclaration(Node *n) { - String *kind = Getattr(n,"kind"); - if (Cmp(kind,"public") == 0) { + String *kind = Getattr(n, "kind"); + if (Cmp(kind, "public") == 0) { cplus_mode = PUBLIC; - } else if (Cmp(kind,"private") == 0) { + } else if (Cmp(kind, "private") == 0) { cplus_mode = PRIVATE; - } else if (Cmp(kind,"protected") == 0) { + } else if (Cmp(kind, "protected") == 0) { cplus_mode = PROTECTED; } return SWIG_OK; @@ -749,7 +761,7 @@ public: Node *c = 0; for (c = firstChild(n); c; c = nextSibling(c)) { - if (Strcmp(nodeType(c),"cdecl") == 0) { + if (Strcmp(nodeType(c), "cdecl") == 0) { process_exceptions(c); if (inclass) @@ -761,7 +773,7 @@ public: } virtual int cDeclaration(Node *n) { - + process_exceptions(n); if (inclass) { @@ -769,59 +781,59 @@ public: class_member_is_defined_in_bases(n, inclass); /* Check to see if this is a static member or not. If so, we add an attribute - cplus:staticbase that saves the current class */ + cplus:staticbase that saves the current class */ - if (checkAttribute(n,"storage","static")) { - Setattr(n,"cplus:staticbase", inclass); + if (checkAttribute(n, "storage", "static")) { + Setattr(n, "cplus:staticbase", inclass); } - String *name = Getattr(n,"name"); + String *name = Getattr(n, "name"); if (cplus_mode != PUBLIC) { - if (Strcmp(name,"operator =") == 0) { + if (Strcmp(name, "operator =") == 0) { /* Look for a private assignment operator */ - Setattr(inclass,"allocate:has_assign","1"); - Setattr(inclass,"allocate:noassign","1"); - } else if (Strcmp(name,"operator new") == 0) { + Setattr(inclass, "allocate:has_assign", "1"); + Setattr(inclass, "allocate:noassign", "1"); + } else if (Strcmp(name, "operator new") == 0) { /* Look for a private new operator */ - Setattr(inclass,"allocate:has_new","1"); - Setattr(inclass,"allocate:nonew","1"); + Setattr(inclass, "allocate:has_new", "1"); + Setattr(inclass, "allocate:nonew", "1"); } } else { - if (Strcmp(name,"operator =") == 0) { - Setattr(inclass,"allocate:has_assign","1"); - } else if (Strcmp(name,"operator new") == 0) { - Setattr(inclass,"allocate:has_new","1"); + if (Strcmp(name, "operator =") == 0) { + Setattr(inclass, "allocate:has_assign", "1"); + } else if (Strcmp(name, "operator new") == 0) { + Setattr(inclass, "allocate:has_new", "1"); } /* Look for smart pointer operator */ - if ((Strcmp(name,"operator ->") == 0) && (!GetFlag(n,"feature:ignore"))) { + if ((Strcmp(name, "operator ->") == 0) && (!GetFlag(n, "feature:ignore"))) { /* Look for version with no parameters */ Node *sn = n; while (sn) { - if (!Getattr(sn,"parms")) { - SwigType *type = SwigType_typedef_resolve_all(Getattr(sn,"type")); - SwigType_push(type,Getattr(sn,"decl")); + if (!Getattr(sn, "parms")) { + SwigType *type = SwigType_typedef_resolve_all(Getattr(sn, "type")); + SwigType_push(type, Getattr(sn, "decl")); Delete(SwigType_pop_function(type)); SwigType *base = SwigType_base(type); Node *sc = Swig_symbol_clookup(base, 0); - if ((sc) && (Strcmp(nodeType(sc),"class") == 0)) { - if (SwigType_check_decl(type,"p.")) { + if ((sc) && (Strcmp(nodeType(sc), "class") == 0)) { + if (SwigType_check_decl(type, "p.")) { /* Need to check if type is a const pointer */ int isconst = 0; Delete(SwigType_pop(type)); if (SwigType_isconst(type)) { isconst = 1; - Setattr(inclass,"allocate:smartpointerconst","1"); + Setattr(inclass, "allocate:smartpointerconst", "1"); } - List *methods = smart_pointer_methods(sc,0,isconst); - Setattr(inclass,"allocate:smartpointer",methods); - Setattr(inclass,"allocate:smartpointerbase",base); + List *methods = smart_pointer_methods(sc, 0, isconst); + Setattr(inclass, "allocate:smartpointer", methods); + Setattr(inclass, "allocate:smartpointerbase", base); } else { /* Hmmm. The return value is not a pointer. If the type is a value or reference. We're going to chase it to see if another operator->() can be found */ - - if ((SwigType_check_decl(type,"")) || (SwigType_check_decl(type,"r."))) { - Node *nn = Swig_symbol_clookup((char*)"operator ->", Getattr(sc,"symtab")); + + if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) { + Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab")); if (nn) { Delete(base); Delete(type); @@ -833,7 +845,7 @@ public: } Delete(base); Delete(type); - break; + break; } } } @@ -843,39 +855,40 @@ public: } virtual int constructorDeclaration(Node *n) { - if (!inclass) return SWIG_OK; - Parm *parms = Getattr(n,"parms"); + if (!inclass) + return SWIG_OK; + Parm *parms = Getattr(n, "parms"); process_exceptions(n); if (!extendmode) { - if (!ParmList_numrequired(parms)) { - /* Class does define a default constructor */ - /* However, we had better see where it is defined */ - if (cplus_mode == PUBLIC) { - Setattr(inclass,"allocate:default_constructor","1"); - } else if (cplus_mode == PROTECTED) { - Setattr(inclass,"allocate:default_base_constructor","1"); - } - } - /* Class defines some kind of constructor. May or may not be public */ - Setattr(inclass,"allocate:has_constructor","1"); + if (!ParmList_numrequired(parms)) { + /* Class does define a default constructor */ + /* However, we had better see where it is defined */ if (cplus_mode == PUBLIC) { - Setattr(inclass,"allocate:public_constructor","1"); + Setattr(inclass, "allocate:default_constructor", "1"); + } else if (cplus_mode == PROTECTED) { + Setattr(inclass, "allocate:default_base_constructor", "1"); } + } + /* Class defines some kind of constructor. May or may not be public */ + Setattr(inclass, "allocate:has_constructor", "1"); + if (cplus_mode == PUBLIC) { + Setattr(inclass, "allocate:public_constructor", "1"); + } } else { - Setattr(inclass,"allocate:has_constructor","1"); - Setattr(inclass,"allocate:public_constructor","1"); + Setattr(inclass, "allocate:has_constructor", "1"); + Setattr(inclass, "allocate:public_constructor", "1"); } - + /* See if this is a copy constructor */ if (parms && (ParmList_numrequired(parms) == 1)) { /* Look for a few cases. X(const X &), X(X &), X(X *) */ int copy_constructor = 0; - SwigType *type = Getattr(inclass,"name"); + SwigType *type = Getattr(inclass, "name"); String *tn = NewStringf("r.q(const).%s", type); String *cc = SwigType_typedef_resolve_all(tn); - SwigType *rt = SwigType_typedef_resolve_all(Getattr(parms,"type")); + SwigType *rt = SwigType_typedef_resolve_all(Getattr(parms, "type")); if (SwigType_istemplate(type)) { String *tmp = Swig_symbol_template_deftype(cc, 0); Delete(cc); @@ -883,19 +896,19 @@ public: tmp = Swig_symbol_template_deftype(rt, 0); Delete(rt); rt = tmp; - } - if (Strcmp(cc,rt) == 0) { + } + if (Strcmp(cc, rt) == 0) { copy_constructor = 1; } else { Delete(cc); - cc = NewStringf("r.%s", Getattr(inclass,"name")); - if (Strcmp(cc,Getattr(parms,"type")) == 0) { + cc = NewStringf("r.%s", Getattr(inclass, "name")); + if (Strcmp(cc, Getattr(parms, "type")) == 0) { copy_constructor = 1; } else { Delete(cc); - cc = NewStringf("p.%s", Getattr(inclass,"name")); - String *ty = SwigType_strip_qualifiers(Getattr(parms,"type")); - if (Strcmp(cc,ty) == 0) { + cc = NewStringf("p.%s", Getattr(inclass, "name")); + String *ty = SwigType_strip_qualifiers(Getattr(parms, "type")); + if (Strcmp(cc, ty) == 0) { copy_constructor = 1; } Delete(ty); @@ -904,14 +917,14 @@ public: Delete(cc); Delete(rt); Delete(tn); - + if (copy_constructor) { - Setattr(n,"copy_constructor","1"); - Setattr(inclass,"allocate:has_copy_constructor","1"); + Setattr(n, "copy_constructor", "1"); + Setattr(inclass, "allocate:has_copy_constructor", "1"); if (cplus_mode == PUBLIC) { - Setattr(inclass,"allocate:copy_constructor","1"); + Setattr(inclass, "allocate:copy_constructor", "1"); } else if (cplus_mode == PROTECTED) { - Setattr(inclass,"allocate:copy_base_constructor","1"); + Setattr(inclass, "allocate:copy_base_constructor", "1"); } } } @@ -919,29 +932,25 @@ public: } virtual int destructorDeclaration(Node *n) { - (void)n; - if (!inclass) return SWIG_OK; + (void) n; + if (!inclass) + return SWIG_OK; if (!extendmode) { - Setattr(inclass,"allocate:has_destructor","1"); - if (cplus_mode == PUBLIC) { - Setattr(inclass,"allocate:default_destructor","1"); - } else if (cplus_mode == PROTECTED) { - Setattr(inclass,"allocate:default_base_destructor","1"); - } + Setattr(inclass, "allocate:has_destructor", "1"); + if (cplus_mode == PUBLIC) { + Setattr(inclass, "allocate:default_destructor", "1"); + } else if (cplus_mode == PROTECTED) { + Setattr(inclass, "allocate:default_base_destructor", "1"); + } } return SWIG_OK; } }; void Swig_default_allocators(Node *n) { - if (!n) return; + if (!n) + return; Allocate *a = new Allocate; a->top(n); delete a; } - - - - - - diff --git a/SWIG/Source/Modules/browser.cxx b/SWIG/Source/Modules/browser.cxx index ef6d450e6..317426f9c 100644 --- a/SWIG/Source/Modules/browser.cxx +++ b/SWIG/Source/Modules/browser.cxx @@ -15,62 +15,60 @@ char cvsroot_browser_cxx[] = "$Header$"; #ifdef SWIG_SWILL extern "C" { #include "swill.h" -} - -static FILE *out = 0; +} static FILE *out = 0; static Node *view_top = 0; - -class Browser : public Dispatcher { + +class Browser:public Dispatcher { void show_checkbox(Node *t, Node *n) { int v = 0; - if (Getmeta(n,"visible")) { + if (Getmeta(n, "visible")) { v = 1; } if (v) { - Printf(out,"[-] ", n, t, n,n); + Printf(out, "[-] ", n, t, n, n); } else { - Printf(out,"[+] ", n, t, n,n); + Printf(out, "[+] ", n, t, n, n); } } void show_attributes(Node *obj) { - if (!Getmeta(obj,"visible")) return; + if (!Getmeta(obj, "visible")) + return; String *os = NewString(""); String *k; Iterator ki; ki = First(obj); while (ki.key) { k = ki.key; - if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) || - (Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) || - (Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) { + if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) || + (Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) { /* Do nothing */ - } else if (Cmp(k,"parms") == 0) { + } else if (Cmp(k, "parms") == 0) { String *o = NewString(""); - Printf(o,"%s", ParmList_protostr(Getattr(obj,k))); - Replaceall(o,"&","&"); - Replaceall(o,"<","<"); - Replaceall(o,">",">"); - Printf(os,"? %-12s - %s\n", Getattr(obj,k), k, o); + Printf(o, "%s", ParmList_protostr(Getattr(obj, k))); + Replaceall(o, "&", "&"); + Replaceall(o, "<", "<"); + Replaceall(o, ">", ">"); + Printf(os, "? %-12s - %s\n", Getattr(obj, k), k, o); Delete(o); } else { DOH *o; char *trunc = ""; - if (DohIsString(Getattr(obj,k))) { - o = Str(Getattr(obj,k)); + if (DohIsString(Getattr(obj, k))) { + o = Str(Getattr(obj, k)); if (Len(o) > 70) { trunc = "..."; } - Replaceall(o,"&","&"); - Replaceall(o,"<","<"); - Printf(os,"? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc); + Replaceall(o, "&", "&"); + Replaceall(o, "<", "<"); + Printf(os, "? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); Delete(o); } else { - Printf(os,"? %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k)); + Printf(os, "? %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k)); } } ki = Next(ki); } - Printf(out,"
\n%s
\n", Char(os)); + Printf(out, "
\n%s
\n", Char(os)); Delete(os); } @@ -78,24 +76,24 @@ public: virtual int emit_one(Node *n) { char *tag = Char(nodeType(n)); char *file = Char(Getfile(n)); - int line = Getline(n); - char *name = GetChar(n,"name"); + int line = Getline(n); + char *name = GetChar(n, "name"); show_checkbox(view_top, n); - Printf(out,"%s", n, tag); + Printf(out, "%s", n, tag); if (name) { - Printf(out," (%s)", name); + Printf(out, " (%s)", name); } - Printf(out,". %s:%d\n", file, line); - Printf(out,"
"); + Printf(out, ". %s:%d\n", file, line); + Printf(out, "
"); Dispatcher::emit_one(n); return SWIG_OK; } virtual int emit_children(Node *n) { - if (Getmeta(n,"visible")) { - Printf(out,"
\n"); + if (Getmeta(n, "visible")) { + Printf(out, "
\n"); Dispatcher::emit_children(n); - Printf(out,"
\n"); + Printf(out, "
\n"); } return SWIG_OK; } @@ -169,7 +167,7 @@ static Browser *browse = 0; void exit_handler(FILE *f) { browser_exit = 1; - Printf(f,"Terminated.\n"); + Printf(f, "Terminated.\n"); } /* ---------------------------------------------------------------------- @@ -178,23 +176,23 @@ void exit_handler(FILE *f) { static void display(FILE *f, Node *n) { /* Print standard HTML header */ - - Printf(f,"SWIG-%s\n", PACKAGE_VERSION); - Printf(f,"SWIG-%s
\n", PACKAGE_VERSION); - Printf(f,"[ Exit ]"); - Printf(f," [ Top ]", tree_top); + + Printf(f, "SWIG-%s\n", PACKAGE_VERSION); + Printf(f, "SWIG-%s
\n", PACKAGE_VERSION); + Printf(f, "[ Exit ]"); + Printf(f, " [ Top ]", tree_top); if (n != tree_top) { - Printf(f," [ Up ]", parentNode(n)); + Printf(f, " [ Up ]", parentNode(n)); } - Printf(f," [ Symbols ]"); - Printf(f,"

\n"); + Printf(f, " [ Symbols ]"); + Printf(f, "


\n"); out = f; browse->emit_one(n); /* Print standard footer */ - Printf(f,"


\n"); + Printf(f, "

\n"); } @@ -204,7 +202,7 @@ void node_handler(FILE *f) { n = tree_top; } view_top = n; - display(f,n); + display(f, n); } @@ -218,7 +216,7 @@ void hide_handler(FILE *f) { n = 0; } if (n) { - Delmeta(n,"visible"); + Delmeta(n, "visible"); } node_handler(f); } @@ -229,65 +227,66 @@ void show_handler(FILE *f) { n = 0; } if (n) { - Setmeta(n,"visible","1"); + Setmeta(n, "visible", "1"); } node_handler(f); } void raw_data(FILE *out, Node *obj) { - if (!obj) return; + if (!obj) + return; if (DohIsMapping(obj)) { String *k; Iterator ki; String *os = NewString(""); - Printf(os,"Hash {\n"); + Printf(os, "Hash {\n"); ki = First(obj); while (ki.key) { k = ki.key; DOH *o; const char *trunc = ""; - if (DohIsString(Getattr(obj,k))) { - o = Str(Getattr(obj,k)); + if (DohIsString(Getattr(obj, k))) { + o = Str(Getattr(obj, k)); if (Len(o) > 70) { trunc = "..."; } - Replaceall(o,"<","<"); - Printf(os," ? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc); + Replaceall(o, "<", "<"); + Printf(os, " ? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc); Delete(o); } else { - Printf(os," ? %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k)); + Printf(os, " ? %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k)); } ki = Next(ki); } - Printf(os,"}\n"); - Printf(out,"
\n%s
\n", Char(os)); + Printf(os, "}\n"); + Printf(out, "
\n%s
\n", Char(os)); Delete(os); } else if (DohIsString(obj)) { String *o = Str(obj); - Replaceall(o,"<","<"); - Printf(out,"
\n%s
\n", Char(o)); + Replaceall(o, "<", "<"); + Printf(out, "
\n%s
\n", Char(o)); Delete(o); } else if (DohIsSequence(obj)) { int i; String *os = NewString(""); - Printf(os,"List [\n"); + Printf(os, "List [\n"); for (i = 0; i < Len(obj); i++) { - DOH *o = Getitem(obj,i); + DOH *o = Getitem(obj, i); const char *trunc = ""; if (DohIsString(o)) { String *s = Str(o); if (Len(s) > 70) { trunc = "..."; } - Replaceall(o,"<","<"); - Printf(os," ? [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc); + Replaceall(o, "<", "<"); + Printf(os, " ? [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc); Delete(s); } else { - Printf(os," ? [%d] - 0x%x\n", o, i, o); + Printf(os, " ? [%d] - 0x%x\n", o, i, o); } } - Printf(os,"\n]\n"); - Printf(out,"
\n%s
\n", Char(os)); + Printf(os, "\n]\n"); + Printf(out, "
\n%s
\n", Char(os)); Delete(os); } } @@ -297,86 +296,85 @@ void data_handler(FILE *f) { if (!swill_getargs("p(n)", &n)) { n = 0; } - Printf(f,"SWIG-%s\n", PACKAGE_VERSION); - Printf(f,"SWIG-%s
\n", PACKAGE_VERSION); - Printf(f,"[ Exit ]"); - Printf(f," [ Top ]", tree_top); - Printf(f,"

\n"); + Printf(f, "SWIG-%s\n", PACKAGE_VERSION); + Printf(f, "SWIG-%s
\n", PACKAGE_VERSION); + Printf(f, "[ Exit ]"); + Printf(f, " [ Top ]", tree_top); + Printf(f, "


\n"); if (n) { - raw_data(f,n); + raw_data(f, n); } /* Print standard footer */ - Printf(f,"


\n"); + Printf(f, "

\n"); } void symbol_handler(FILE *f) { Symtab *sym; - char *name = 0; + char *name = 0; + + Printf(f, "SWIG-%s\n", PACKAGE_VERSION); + Printf(f, "SWIG-%s
\n", PACKAGE_VERSION); + Printf(f, "[ Exit ]"); + Printf(f, " [ Top ]", tree_top); + Printf(f, " [ Symbols ]"); + Printf(f, "

\n"); - Printf(f,"SWIG-%s\n", PACKAGE_VERSION); - Printf(f,"SWIG-%s
\n", PACKAGE_VERSION); - Printf(f,"[ Exit ]"); - Printf(f," [ Top ]", tree_top); - Printf(f," [ Symbols ]"); - Printf(f,"


\n"); - if (!swill_getargs("p(sym)|s(name)", &sym, &name)) { sym = Swig_symbol_getscope(""); name = 0; } if (!sym) { - Printf(f,"No symbol table specified!\n"); + Printf(f, "No symbol table specified!\n"); return; } { String *q = Swig_symbol_qualifiedscopename(sym); if (!Len(q)) { - Printf(f,"Symbol table: :: (global)
\n"); + Printf(f, "Symbol table: :: (global)
\n"); } else { - Printf(f,"Symbol table: %s
\n", q); + Printf(f, "Symbol table: %s
\n", q); } Delete(q); } - - fprintf(f,"

\n"); - fprintf(f,"Symbol lookup:
\n"); - fprintf(f,"\n", sym); - fprintf(f,"Submit : \n"); - fprintf(f,"
"); + + fprintf(f, "

\n"); + fprintf(f, "Symbol lookup:
\n"); + fprintf(f, "\n", sym); + fprintf(f, "Submit : \n"); + fprintf(f, "
"); if (name) { - Node *n = Swig_symbol_clookup(name,sym); - Printf(f,"Symbol '%s':\n", name); - Printf(f,"
\n"); + Node *n = Swig_symbol_clookup(name, sym); + Printf(f, "Symbol '%s':\n", name); + Printf(f, "
\n"); if (!n) { - Printf(f,"Not defined!\n"); + Printf(f, "Not defined!\n"); } else { - raw_data(f,n); + raw_data(f, n); } - Printf(f,"
\n"); + Printf(f, "
\n"); } - Printf(f,"

Nested scopes
\n"); - Printf(f,"

\n");
+  Printf(f, "

Nested scopes
\n"); + Printf(f, "

\n");
   {
-    Hash   *h;
+    Hash *h;
     h = firstChild(sym);
     while (h) {
-      Printf(f,"%s\n", h, Getattr(h,"name"));
+      Printf(f, "%s\n", h, Getattr(h, "name"));
       h = nextSibling(h);
     }
   }
-  Printf(f,"
\n"); - - Printf(f,"

Symbol table contents
\n"); - raw_data(f,Getattr(sym,"symtab")); - Printf(f,"


\n"); + Printf(f, "
\n"); + + Printf(f, "

Symbol table contents
\n"); + raw_data(f, Getattr(sym, "symtab")); + Printf(f, "


\n"); } #endif -void -Swig_browser(Node *top, int port) { +void Swig_browser(Node *top, int port) { #ifdef SWIG_SWILL int sport; browser_exit = 0; @@ -384,37 +382,32 @@ Swig_browser(Node *top, int port) { /* Initialize the server */ sport = swill_init(port); if (sport < 0) { - Printf(stderr,"Couldn't open socket on port %d. Sorry.\n", port); + Printf(stderr, "Couldn't open socket on port %d. Sorry.\n", port); return; } browse = new Browser(); - Setmeta(top,"visible","1"); + Setmeta(top, "visible", "1"); tree_top = top; - Printf(stderr,"SWIG: Tree browser listening on port %d\n", sport); + Printf(stderr, "SWIG: Tree browser listening on port %d\n", sport); - swill_handle("exit.html", exit_handler,0); + swill_handle("exit.html", exit_handler, 0); swill_handle("index.html", node_handler, 0); - swill_handle("hide.html", hide_handler,0); - swill_handle("show.html", show_handler,0); - swill_handle("data.html", data_handler,0); + swill_handle("hide.html", hide_handler, 0); + swill_handle("show.html", show_handler, 0); + swill_handle("data.html", data_handler, 0); swill_handle("symbol.html", symbol_handler, 0); swill_netscape("index.html"); while (!browser_exit) { swill_serve(); } - Printf(stderr,"Browser terminated.\n"); + Printf(stderr, "Browser terminated.\n"); swill_close(); delete browse; return; #else - (void)top; - (void)port; + (void) top; + (void) port; #endif } - - - - - diff --git a/SWIG/Source/Modules/cffi.cxx b/SWIG/Source/Modules/cffi.cxx index e653f03f1..06cee7a8b 100644 --- a/SWIG/Source/Modules/cffi.cxx +++ b/SWIG/Source/Modules/cffi.cxx @@ -16,12 +16,12 @@ char cvsroot_cffi_cxx[] = "$Header$"; //#define CFFI_DEBUG //#define CFFI_WRAP_DEBUG -class CFFI : public Language { +class CFFI:public Language { public: String *f_cl; String *f_clhead; String *f_clwrap; - bool CWrap; // generate wrapper file for C code? + bool CWrap; // generate wrapper file for C code? File *f_cxx; File *f_cxx_header; File *f_cxx_wrapper; @@ -31,7 +31,7 @@ public: virtual void main(int argc, char *argv[]); virtual int top(Node *n); virtual int functionWrapper(Node *n); - virtual int variableWrapper(Node *n); + virtual int variableWrapper(Node *n); virtual int constantWrapper(Node *n); // virtual int classDeclaration(Node *n); virtual int enumDeclaration(Node *n); @@ -51,51 +51,46 @@ private: void emit_setter(Node *n); void emit_class(Node *n); void emit_struct_union(Node *n, bool un); - void emit_export(Node *n,String *name); - void emit_inline(Node *n,String *name); - String* lispy_name(char *name); - String* lispify_name(Node* n,String *ty,const char* flag,bool kw=false); - String* convert_literal(String *num_param, String *type, bool try_to_split = true); - String* infix_to_prefix(String *val, char split_op, const String *op, String *type); - String* strip_parens(String *string); - String* trim(String *string); + void emit_export(Node *n, String *name); + void emit_inline(Node *n, String *name); + String *lispy_name(char *name); + String *lispify_name(Node *n, String *ty, const char *flag, bool kw = false); + String *convert_literal(String *num_param, String *type, bool try_to_split = true); + String *infix_to_prefix(String *val, char split_op, const String *op, String *type); + String *strip_parens(String *string); + String *trim(String *string); int generate_typedef_flag; bool no_swig_lisp; }; -void CFFI :: main(int argc, char *argv[]) { +void CFFI::main(int argc, char *argv[]) { int i; - SWIG_library_directory("cffi"); + SWIG_library_directory("cffi"); SWIG_config_file("cffi.swg"); generate_typedef_flag = 0; no_swig_lisp = false; CWrap = false; - for(i=1; i 0) + if (Len(ffitype) > 0) Printf(args_placeholder, " (%s %s)", argname, ffitype); else Printf(args_placeholder, " %s", argname, ffitype); - if(Strcmp(ffitype,lispify_name(parent,lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0) + if (Strcmp(ffitype, lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'classname")) == 0) Printf(args_call, " (ff-pointer %s)", argname); else Printf(args_call, " %s", argname); - + Delete(ffitype); - if (tempargname) + if (tempargname) Delete(argname); } String *method_name = Getattr(n, "name"); - int x = Replace(method_name,"operator ","",DOH_REPLACE_FIRST); // + int x = Replace(method_name, "operator ", "", DOH_REPLACE_FIRST); // - if(x==1) - Printf(f_clos, "(cl:shadow \"%s\")\n",method_name); + if (x == 1) + Printf(f_clos, "(cl:shadow \"%s\")\n", method_name); - Printf(f_clos,"(clos:defmethod %s ((obj %s)%s)\n (%s (ff-pointer obj)%s))\n\n", - lispify_name(n,lispy_name(Char(method_name)),"'method"), - lispify_name(parent,lispy_name(Char(Getattr(parent, "sym:name"))),"'class"),args_placeholder, - lispify_name(n, Getattr(n, "sym:name"), "'function"),args_call); + Printf(f_clos, "(clos:defmethod %s ((obj %s)%s)\n (%s (ff-pointer obj)%s))\n\n", + lispify_name(n, lispy_name(Char(method_name)), "'method"), + lispify_name(parent, lispy_name(Char(Getattr(parent, "sym:name"))), "'class"), args_placeholder, + lispify_name(n, Getattr(n, "sym:name"), "'function"), args_call); } -void CFFI::emit_setter(Node*n) { +void CFFI::emit_setter(Node *n) { Node *p = parentNode(n); - Printf(f_clos,"(clos:defmethod (cl:setf %s) (arg0 (obj %s))\n (%s (ff-pointer obj) arg0))\n\n", - lispify_name(n, Getattr(n, "name"), "'method"), - lispify_name(p,lispy_name(Char(Getattr(p, "sym:name"))),"'class"), - lispify_name(n, Getattr(n, "sym:name"), "'function")); + Printf(f_clos, "(clos:defmethod (cl:setf %s) (arg0 (obj %s))\n (%s (ff-pointer obj) arg0))\n\n", + lispify_name(n, Getattr(n, "name"), "'method"), + lispify_name(p, lispy_name(Char(Getattr(p, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function")); } -void CFFI::emit_getter(Node*n) { +void CFFI::emit_getter(Node *n) { Node *p = parentNode(n); - Printf(f_clos,"(clos:defmethod %s ((obj %s))\n (%s (ff-pointer obj)))\n\n", - lispify_name(n, Getattr(n, "name"), "'method"), - lispify_name(p,lispy_name(Char(Getattr(p, "sym:name"))),"'class"), - lispify_name(n, Getattr(n, "sym:name"), "'function")); + Printf(f_clos, "(clos:defmethod %s ((obj %s))\n (%s (ff-pointer obj)))\n\n", + lispify_name(n, Getattr(n, "name"), "'method"), + lispify_name(p, lispy_name(Char(Getattr(p, "sym:name"))), "'class"), lispify_name(n, Getattr(n, "sym:name"), "'function")); } -int CFFI :: memberfunctionHandler(Node *n) { +int CFFI::memberfunctionHandler(Node *n) { // Let SWIG generate a global forwarding function. - Setattr(n,"cffi:memberfunction","1"); + Setattr(n, "cffi:memberfunction", "1"); return Language::memberfunctionHandler(n); } -int CFFI :: membervariableHandler(Node *n) { +int CFFI::membervariableHandler(Node *n) { // Let SWIG generate a get/set function pair. - Setattr(n,"cffi:membervariable","1"); + Setattr(n, "cffi:membervariable", "1"); return Language::membervariableHandler(n); } -int CFFI :: functionWrapper(Node *n) { +int CFFI::functionWrapper(Node *n) { - ParmList *parms = Getattr(n,"parms"); - String *iname = Getattr(n,"sym:name"); + ParmList *parms = Getattr(n, "parms"); + String *iname = Getattr(n, "sym:name"); Wrapper *wrap = NewWrapper(); - String *raw_return_type = Swig_typemap_lookup_new("ctype",n,"",0); + String *raw_return_type = Swig_typemap_lookup_new("ctype", n, "", 0); SwigType *return_type = Swig_cparse_type(raw_return_type); SwigType *resolved = SwigType_typedef_resolve_all(return_type); int is_void_return = (Cmp(resolved, "void") == 0); Delete(resolved); - if (!is_void_return) - { - String *lresult_init = NewStringf("lresult = (%s)0", raw_return_type); - Wrapper_add_localv(wrap,"lresult", raw_return_type, lresult_init, NIL); - Delete(lresult_init); - } + if (!is_void_return) { + String *lresult_init = NewStringf("lresult = (%s)0", raw_return_type); + Wrapper_add_localv(wrap, "lresult", raw_return_type, lresult_init, NIL); + Delete(lresult_init); + } String *overname = 0; - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) + if (!addSymbol(iname, n)) return SWIG_ERROR; } @@ -353,7 +335,6 @@ int CFFI :: functionWrapper(Node *n) { if (overname) { StringAppend(wname, overname); } - // Emit all of the local variables for holding arguments. emit_args(Getattr(n, "type"), parms, wrap); @@ -363,41 +344,43 @@ int CFFI :: functionWrapper(Node *n) { int num_arguments = emit_num_arguments(parms); String *name_and_parms = NewStringf("%s (", wname); - int i; Parm *p; + int i; + Parm *p; int gencomma = 0; #ifdef CFFI_DEBUG - Printf(stderr, "function - %s - %d\n", Getattr(n, "name"),num_arguments); + Printf(stderr, "function - %s - %d\n", Getattr(n, "name"), num_arguments); #endif - - for (i = 0, p=parms; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + for (i = 0, p = parms; i < num_arguments; i++) { + + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } SwigType *c_parm_type = Swig_cparse_type(Getattr(p, "tmap:ctype")); - String *arg = NewStringf("l%s", Getattr(p,"lname")); + String *arg = NewStringf("l%s", Getattr(p, "lname")); // Emit parameter declaration - if (gencomma) Printf(name_and_parms, ", "); + if (gencomma) + Printf(name_and_parms, ", "); String *parm_decl = SwigType_str(c_parm_type, arg); Printf(name_and_parms, "%s", parm_decl); #ifdef CFFI_DEBUG - Printf(stderr," param: %s\n", parm_decl); + Printf(stderr, " param: %s\n", parm_decl); #endif Delete(parm_decl); gencomma = 1; // Emit parameter conversion code - String *parm_code = Getattr(p,"tmap:in"); + String *parm_code = Getattr(p, "tmap:in"); { - Replaceall(parm_code,"$input", arg); - Setattr(p,"emit:input", arg); - Printf(wrap->code,"%s\n", parm_code); - p = Getattr(p,"tmap:in:next"); + Replaceall(parm_code, "$input", arg); + Setattr(p, "emit:input", arg); + Printf(wrap->code, "%s\n", parm_code); + p = Getattr(p, "tmap:in:next"); } - + Delete(arg); } Printf(name_and_parms, ")"); @@ -405,39 +388,37 @@ int CFFI :: functionWrapper(Node *n) { // Emit the function definition String *signature = SwigType_str(return_type, name_and_parms); Printf(wrap->def, "EXPORT %s {", signature); - Printf(wrap->code," try {\n"); + Printf(wrap->code, " try {\n"); emit_action(n, wrap); + if (!is_void_return) { + String *result_convert = Swig_typemap_lookup_new("out", n, "result", 0); + Replaceall(result_convert, "$result", "lresult"); + Printf(wrap->code, "%s\n", result_convert); + Printf(wrap->code, " return lresult;\n"); + Delete(result_convert); + } + + Printf(wrap->code, " } catch (...) {\n"); if (!is_void_return) - { - String *result_convert = Swig_typemap_lookup_new("out",n,"result",0); - Replaceall(result_convert, "$result", "lresult"); - Printf(wrap->code, "%s\n", result_convert); - Printf(wrap->code, " return lresult;\n"); - Delete(result_convert); - } - - Printf(wrap->code," } catch (...) {\n"); - if (!is_void_return) - Printf(wrap->code," return (%s)0;\n", raw_return_type); - Printf(wrap->code," }\n"); - Printf(wrap->code,"}\n"); + Printf(wrap->code, " return (%s)0;\n", raw_return_type); + Printf(wrap->code, " }\n"); + Printf(wrap->code, "}\n"); if (CPlusPlus) Wrapper_print(wrap, f_cxx); if (CPlusPlus) { - emit_defun(n,wname); - if(Getattr(n,"cffi:memberfunction")) + emit_defun(n, wname); + if (Getattr(n, "cffi:memberfunction")) emit_defmethod(n); - else if(Getattr(n,"cffi:membervariable")) { - if(Getattr(n,"memberget")) - emit_getter(n); - else if(Getattr(n,"memberset")) - emit_setter(n); + else if (Getattr(n, "cffi:membervariable")) { + if (Getattr(n, "memberget")) + emit_getter(n); + else if (Getattr(n, "memberset")) + emit_setter(n); } - } - else - emit_defun(n,iname); + } else + emit_defun(n, iname); // if (!overloaded || !Getattr(n, "sym:nextSibling")) { // update_package_if_needed(n); @@ -454,72 +435,70 @@ int CFFI :: functionWrapper(Node *n) { } -void CFFI::emit_defun(Node *n,String *name) -{ +void CFFI::emit_defun(Node *n, String *name) { // String *storage=Getattr(n,"storage"); // if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))) // return SWIG_OK; - - String *func_name=Getattr(n, "sym:name"); - ParmList *pl=Getattr(n, "parms"); + String *func_name = Getattr(n, "sym:name"); - int argnum=0; + ParmList *pl = Getattr(n, "parms"); + + int argnum = 0; + + func_name = lispify_name(n, func_name, "'function"); - func_name=lispify_name(n, func_name, "'function"); - emit_inline(n, func_name); - + Printf(f_cl, "\n(cffi:defcfun (\"%s\" %s)", name, func_name); - String *ffitype= Swig_typemap_lookup_new("cout",n,":pointer",0); + String *ffitype = Swig_typemap_lookup_new("cout", n, ":pointer", 0); Printf(f_cl, " %s", ffitype); Delete(ffitype); - - for (Parm *p=pl; p; p=nextSibling(p), argnum++) { - if (SwigType_isvarargs(Getattr(p, "type"))){ - Printf(f_cl,"\n %s",NewString("&rest")); + for (Parm *p = pl; p; p = nextSibling(p), argnum++) { + + if (SwigType_isvarargs(Getattr(p, "type"))) { + Printf(f_cl, "\n %s", NewString("&rest")); continue; } - String *argname=Getattr(p, "name"); - - ffitype = Swig_typemap_lookup_new("cin",p, "",0); + String *argname = Getattr(p, "name"); - int tempargname=0; + ffitype = Swig_typemap_lookup_new("cin", p, "", 0); + + int tempargname = 0; if (!argname) { - - argname=NewStringf("arg%d", argnum); - tempargname=1; + + argname = NewStringf("arg%d", argnum); + tempargname = 1; + } else if (Strcmp(argname, "t") == 0 || Strcmp(argname, "T") == 0) { + argname = NewStringf("t_arg%d", argnum); + tempargname = 1; } - else if(Strcmp(argname,"t")==0 || Strcmp(argname,"T")==0) { - argname=NewStringf("t_arg%d", argnum); - tempargname=1; - } - + Printf(f_cl, "\n (%s %s)", argname, ffitype); - + Delete(ffitype); - if (tempargname) + if (tempargname) Delete(argname); } - Printf(f_cl, ")\n"); /* finish arg list */ + Printf(f_cl, ")\n"); /* finish arg list */ emit_export(n, func_name); } -int CFFI :: constantWrapper(Node *n) { - String *type=Getattr(n, "type"); - String *converted_value=convert_literal(Getattr(n, "value"), type); - String *name=lispify_name(n, Getattr(n, "sym:name"), "'constant"); - - if(Strcmp(name,"t")==0 || Strcmp(name,"T")==0) - name=NewStringf("t_var"); - +int CFFI::constantWrapper(Node *n) { + String *type = Getattr(n, "type"); + String *converted_value = convert_literal(Getattr(n, "value"), type); + String *name = lispify_name(n, Getattr(n, "sym:name"), "'constant"); + + if (Strcmp(name, "t") == 0 || Strcmp(name, "T") == 0) + name = NewStringf("t_var"); + Printf(f_cl, "\n(cl:defconstant %s %s)\n", name, converted_value); Delete(converted_value); @@ -527,21 +506,21 @@ int CFFI :: constantWrapper(Node *n) { return SWIG_OK; } -int CFFI :: variableWrapper(Node *n) { +int CFFI::variableWrapper(Node *n) { // String *storage=Getattr(n,"storage"); // Printf(stdout,"\"%s\" %s)\n",storage,Getattr(n, "sym:name")); - + // if(!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc"))) // return SWIG_OK; - String *var_name=Getattr(n, "sym:name"); - String *lisp_type = Swig_typemap_lookup_new("cin",n, "",0); - String* lisp_name = lispify_name(n, var_name, "'variable"); - - if(Strcmp(lisp_name,"t")==0 || Strcmp(lisp_name,"T")==0) - lisp_name=NewStringf("t_var"); + String *var_name = Getattr(n, "sym:name"); + String *lisp_type = Swig_typemap_lookup_new("cin", n, "", 0); + String *lisp_name = lispify_name(n, var_name, "'variable"); - Printf(f_cl,"\n(cffi:defcvar (\"%s\" %s)\n %s)\n",var_name,lisp_name,lisp_type); + if (Strcmp(lisp_name, "t") == 0 || Strcmp(lisp_name, "T") == 0) + lisp_name = NewStringf("t_var"); + + Printf(f_cl, "\n(cffi:defcvar (\"%s\" %s)\n %s)\n", var_name, lisp_name, lisp_type); Delete(lisp_type); @@ -549,116 +528,112 @@ int CFFI :: variableWrapper(Node *n) { return SWIG_OK; } -int CFFI :: typedefHandler(Node *n) { - if(generate_typedef_flag && strncmp(Char(Getattr(n,"type")),"enum",4)) { - String *lisp_name = lispify_name(n,Getattr(n,"name"),"'typename"); - Printf(f_cl,"\n(cffi:defctype %s %s)\n", - lisp_name, - Swig_typemap_lookup_new("cin",n, "",0)); +int CFFI::typedefHandler(Node *n) { + if (generate_typedef_flag && strncmp(Char(Getattr(n, "type")), "enum", 4)) { + String *lisp_name = lispify_name(n, Getattr(n, "name"), "'typename"); + Printf(f_cl, "\n(cffi:defctype %s %s)\n", lisp_name, Swig_typemap_lookup_new("cin", n, "", 0)); emit_export(n, lisp_name); } return Language::typedefHandler(n); } -int CFFI :: enumDeclaration(Node *n) { +int CFFI::enumDeclaration(Node *n) { String *name = Getattr(n, "sym:name"); bool slot_name_keywords; String *lisp_name = 0; - if(name && Len(name)!=0) { + if (name && Len(name) != 0) { lisp_name = lispify_name(n, name, "'enumname"); - if (GetFlag(n,"feature:bitfield")){ - Printf(f_cl,"\n(cffi:defbitfield %s",lisp_name); - } - else{ - Printf(f_cl,"\n(cffi:defcenum %s",lisp_name); + if (GetFlag(n, "feature:bitfield")) { + Printf(f_cl, "\n(cffi:defbitfield %s", lisp_name); + } else { + Printf(f_cl, "\n(cffi:defcenum %s", lisp_name); } slot_name_keywords = true; //Registering the enum name to the cin and cout typemaps - Parm *pattern = NewParm(name,NULL); - Swig_typemap_register("cin",pattern,lisp_name,NULL,NULL); - Swig_typemap_register("cout",pattern,lisp_name,NULL,NULL); + Parm *pattern = NewParm(name, NULL); + Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL); + Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL); Delete(pattern); //Registering with the kind, i.e., enum - pattern = NewParm(NewStringf("enum %s",name),NULL); - Swig_typemap_register("cin",pattern,lisp_name,NULL,NULL); - Swig_typemap_register("cout",pattern,lisp_name,NULL,NULL); + pattern = NewParm(NewStringf("enum %s", name), NULL); + Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL); + Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL); Delete(pattern); - } - else { - Printf(f_cl,"\n(defanonenum %s",name); + } else { + Printf(f_cl, "\n(defanonenum %s", name); slot_name_keywords = false; } - for (Node *c=firstChild(n); c; c=nextSibling(c)) { + for (Node *c = firstChild(n); c; c = nextSibling(c)) { String *slot_name = lispify_name(c, Getattr(c, "name"), "'enumvalue", slot_name_keywords); String *value = Getattr(c, "enumvalue"); - if(!value || GetFlag(n,"feature:bitfield:ignore_values")) - Printf(f_cl,"\n\t%s",slot_name); + if (!value || GetFlag(n, "feature:bitfield:ignore_values")) + Printf(f_cl, "\n\t%s", slot_name); else { - String *type=Getattr(c, "type"); - String *converted_value=convert_literal(value, type); - Printf(f_cl,"\n\t(%s %s)",slot_name, converted_value); + String *type = Getattr(c, "type"); + String *converted_value = convert_literal(value, type); + Printf(f_cl, "\n\t(%s %s)", slot_name, converted_value); Delete(converted_value); } Delete(value); } - + Printf(f_cl, ")\n"); // No need to export keywords - if (lisp_name && Len(lisp_name)!=0) { + if (lisp_name && Len(lisp_name) != 0) { emit_export(n, lisp_name); - } - else { - for (Node *c=firstChild(n); c; c=nextSibling(c)) + } else { + for (Node *c = firstChild(n); c; c = nextSibling(c)) emit_export(c, lispify_name(c, Getattr(c, "name"), "'enumvalue")); } return SWIG_OK; } -void CFFI :: emit_class(Node *n) { - +void CFFI::emit_class(Node *n) { + #ifdef CFFI_WRAP_DEBUG - Printf(stderr,"emit_class: ENTER... '%s'(%x)\n", Getattr(n,"sym:name"), n); + Printf(stderr, "emit_class: ENTER... '%s'(%x)\n", Getattr(n, "sym:name"), n); #endif String *name = Getattr(n, "sym:name"); String *lisp_name = lispify_name(n, lispy_name(Char(name)), "'classname"); - String *bases = Getattr(n,"bases"); + String *bases = Getattr(n, "bases"); String *supers = NewString("("); - if(bases) { - int first=1; - for (Iterator i=First(bases); i.item; i = Next(i)) { - if (!first) Printf(supers," "); - String *s = Getattr(i.item,"name"); - Printf(supers,"%s",lispify_name(i.item, s, "'classname")); + if (bases) { + int first = 1; + for (Iterator i = First(bases); i.item; i = Next(i)) { + if (!first) + Printf(supers, " "); + String *s = Getattr(i.item, "name"); + Printf(supers, "%s", lispify_name(i.item, s, "'classname")); } } else { // Printf(supers,"ff:foreign-pointer"); } - Printf(supers,")"); - Printf(f_clos,"\n(clos:defclass %s%s",lisp_name,supers); - Printf(f_clos,"\n ((ff :reader ff-pointer)))\n\n"); + Printf(supers, ")"); + Printf(f_clos, "\n(clos:defclass %s%s", lisp_name, supers); + Printf(f_clos, "\n ((ff :reader ff-pointer)))\n\n"); + + Parm *pattern = NewParm(Getattr(n, "name"), NULL); + + Swig_typemap_register("lispclass", pattern, lisp_name, NULL, NULL); + SwigType_add_pointer(Getattr(pattern, "type")); + Swig_typemap_register("lispclass", pattern, lisp_name, NULL, NULL); + SwigType_add_qualifier(Getattr(pattern, "type"), "const"); + Swig_typemap_register("lispclass", pattern, lisp_name, NULL, NULL); + SwigType_del_pointer(Getattr(pattern, "type")); + SwigType_add_reference(Getattr(pattern, "type")); + Swig_typemap_register("lispclass", pattern, lisp_name, NULL, NULL); - Parm *pattern = NewParm(Getattr(n, "name"),NULL); - - Swig_typemap_register("lispclass",pattern,lisp_name,NULL,NULL); - SwigType_add_pointer(Getattr(pattern,"type")); - Swig_typemap_register("lispclass",pattern,lisp_name,NULL,NULL); - SwigType_add_qualifier(Getattr(pattern,"type"), "const"); - Swig_typemap_register("lispclass",pattern,lisp_name,NULL,NULL); - SwigType_del_pointer(Getattr(pattern,"type")); - SwigType_add_reference(Getattr(pattern,"type")); - Swig_typemap_register("lispclass",pattern,lisp_name,NULL,NULL); - #ifdef CFFI_WRAP_DEBUG - Printf(stderr, " pattern %s name %s .. ... %s .\n",pattern,lisp_name); + Printf(stderr, " pattern %s name %s .. ... %s .\n", pattern, lisp_name); #endif Delete(pattern); @@ -671,39 +646,35 @@ void CFFI :: emit_class(Node *n) { #endif Node *c; - for (c=firstChild(n); c; c=nextSibling(c)) { - String *storage_type = Getattr(c,"storage"); - if((!Strcmp(nodeType(c),"cdecl") && - (!storage_type || Strcmp(storage_type,"typedef")))) { - String *access = Getattr(c,"access"); + for (c = firstChild(n); c; c = nextSibling(c)) { + String *storage_type = Getattr(c, "storage"); + if ((!Strcmp(nodeType(c), "cdecl") && (!storage_type || Strcmp(storage_type, "typedef")))) { + String *access = Getattr(c, "access"); // hack. why would decl have a value of "variableHandler" and now "0"? - String *childDecl = Getattr(c,"decl"); + String *childDecl = Getattr(c, "decl"); // Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view")); - if(!Strcmp(childDecl,"0")) - childDecl = NewString(""); + if (!Strcmp(childDecl, "0")) + childDecl = NewString(""); - SwigType *childType=NewStringf("%s%s", childDecl, - Getattr(c,"type")); - String *cname = (access && Strcmp(access,"public")) ? - NewString("nil") : Copy(Getattr(c,"name")); + SwigType *childType = NewStringf("%s%s", childDecl, + Getattr(c, "type")); + String *cname = (access && Strcmp(access, "public")) ? NewString("nil") : Copy(Getattr(c, "name")); - if(!SwigType_isfunction(childType)) { - // Printf(slotdefs, ";;; member functions don't appear as slots.\n "); - // Printf(slotdefs, ";; "); - // String *ns = listify_namespace(Getattr(n, "cffi:package")); - String *ns = NewString(""); + if (!SwigType_isfunction(childType)) { + // Printf(slotdefs, ";;; member functions don't appear as slots.\n "); + // Printf(slotdefs, ";; "); + // String *ns = listify_namespace(Getattr(n, "cffi:package")); + String *ns = NewString(""); #ifdef CFFI_WRAP_DEBUG - Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", - cname, ns, name, childType); + Printf(stderr, "slot name = '%s' ns = '%s' class-of '%s' and type = '%s'\n", cname, ns, name, childType); #endif - Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", - cname, ns, name, childType); //compose_foreign_type(childType) - Delete(ns); - if(access && Strcmp(access,"public")) - Printf(slotdefs, " ;; %s member", access); + Printf(slotdefs, "(#.(swig-insert-id \"%s\" %s :type :slot :class \"%s\") %s)", cname, ns, name, childType); //compose_foreign_type(childType) + Delete(ns); + if (access && Strcmp(access, "public")) + Printf(slotdefs, " ;; %s member", access); - Printf(slotdefs, "\n "); + Printf(slotdefs, "\n "); } Delete(childType); Delete(cname); @@ -726,53 +697,49 @@ void CFFI :: emit_class(Node *n) { //Delete(pattern); #ifdef CFFI_WRAP_DEBUG - Printf(stderr,"emit_class: EXIT\n"); + Printf(stderr, "emit_class: EXIT\n"); #endif } // Includes structs -void CFFI :: emit_struct_union(Node *n, bool un=false) { +void CFFI::emit_struct_union(Node *n, bool un = false) { #ifdef CFFI_DEBUG Printf(stderr, "struct/union %s\n", Getattr(n, "name")); - Printf(stderr, "struct/union %s\n and %s", - Getattr(n,"kind"),Getattr(n,"sym:name")); + Printf(stderr, "struct/union %s\n and %s", Getattr(n, "kind"), Getattr(n, "sym:name")); #endif String *name = Getattr(n, "sym:name"); - String *kind = Getattr(n,"kind"); - - if (Strcmp(kind, "struct")!=0 && Strcmp(kind, "union")!=0) { - Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", - kind); + String *kind = Getattr(n, "kind"); + + if (Strcmp(kind, "struct") != 0 && Strcmp(kind, "union") != 0) { + Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind); Printf(stderr, " (name: %s)\n", name); SWIG_exit(EXIT_FAILURE); } String *lisp_name = lispify_name(n, name, "'classname"); //Register the struct/union name to the cin and cout typemaps - - Parm *pattern = NewParm(name,NULL); - Swig_typemap_register("cin",pattern,lisp_name,NULL,NULL); - Swig_typemap_register("cout",pattern,lisp_name,NULL,NULL); + + Parm *pattern = NewParm(name, NULL); + Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL); + Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL); Delete(pattern); //Registering with the kind, i.e., struct or union - pattern = NewParm(NewStringf("%s %s",kind,name),NULL); - Swig_typemap_register("cin",pattern,lisp_name,NULL,NULL); - Swig_typemap_register("cout",pattern,lisp_name,NULL,NULL); + pattern = NewParm(NewStringf("%s %s", kind, name), NULL); + Swig_typemap_register("cin", pattern, lisp_name, NULL, NULL); + Swig_typemap_register("cout", pattern, lisp_name, NULL, NULL); Delete(pattern); - - if(un) { - Printf(f_cl,"\n(cffi:defcunion %s",lisp_name); - } - else - Printf(f_cl,"\n(cffi:defcstruct %s",lisp_name); - - for (Node *c=firstChild(n); c; c=nextSibling(c)) { + if (un) { + Printf(f_cl, "\n(cffi:defcunion %s", lisp_name); + } else + Printf(f_cl, "\n(cffi:defcstruct %s", lisp_name); + + + for (Node *c = firstChild(n); c; c = nextSibling(c)) { #ifdef CFFI_DEBUG Printf(stderr, "struct/union %s\n", Getattr(c, "name")); - Printf(stderr, "struct/union %s and %s \n", - Getattr(c,"kind"),Getattr(c,"sym:name")); + Printf(stderr, "struct/union %s and %s \n", Getattr(c, "kind"), Getattr(c, "sym:name")); #endif if (Strcmp(nodeType(c), "cdecl")) { @@ -784,31 +751,30 @@ void CFFI :: emit_struct_union(Node *n, bool un=false) { // Getattr(c, "name"), // Getattr(c, "type")); // SWIG_exit(EXIT_FAILURE); - } - else{ - SwigType *childType=NewStringf("%s%s", Getattr(c,"decl"), - Getattr(c,"type")); + } else { + SwigType *childType = NewStringf("%s%s", Getattr(c, "decl"), + Getattr(c, "type")); - Hash *typemap = Swig_typemap_search("cin", childType,"", 0); + Hash *typemap = Swig_typemap_search("cin", childType, "", 0); String *typespec = NewString(""); if (typemap) { - typespec = NewString(Getattr(typemap, "code")); + typespec = NewString(Getattr(typemap, "code")); } String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname"); - if(Strcmp(slot_name,"t")==0 || Strcmp(slot_name,"T")==0) - slot_name=NewStringf("t_var"); + if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0) + slot_name = NewStringf("t_var"); - Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); + Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); Delete(typespec); } } - + Printf(f_cl, ")\n"); emit_export(n, lisp_name); - for (Node *c=firstChild(n); c; c=nextSibling(c)) { + for (Node *c = firstChild(n); c; c = nextSibling(c)) { if (!Strcmp(nodeType(c), "cdecl")) { emit_export(c, lispify_name(c, Getattr(c, "sym:name"), "'slotname")); } @@ -817,100 +783,98 @@ void CFFI :: emit_struct_union(Node *n, bool un=false) { /* Add this structure to the known lisp types */ //Printf(stdout, "Adding %s foreign type\n", name); // add_defined_foreign_type(name); - + } -void CFFI :: emit_export(Node *n,String *name) { +void CFFI::emit_export(Node *n, String *name) { if (GetInt(n, "feature:export")) Printf(f_cl, "\n(cl:export '%s)\n", name); } -void CFFI :: emit_inline(Node *n,String *name) { +void CFFI::emit_inline(Node *n, String *name) { if (GetInt(n, "feature:inline")) Printf(f_cl, "\n(cl:declaim (cl:inline %s))\n", name); } -String* CFFI ::lispify_name(Node *n, String* ty, const char* flag, bool kw) { - String* intern_func = Getattr(n, "feature:intern_function"); +String *CFFI::lispify_name(Node *n, String *ty, const char *flag, bool kw) { + String *intern_func = Getattr(n, "feature:intern_function"); if (intern_func) { - if(Strcmp(intern_func,"1") == 0) + if (Strcmp(intern_func, "1") == 0) intern_func = NewStringf("swig-lispify"); - return NewStringf("#.(%s \"%s\" %s%s)", intern_func, ty, flag, kw ? " :keyword":""); - } - else if(kw) - return NewStringf(":%s",ty); + return NewStringf("#.(%s \"%s\" %s%s)", intern_func, ty, flag, kw ? " :keyword" : ""); + } else if (kw) + return NewStringf(":%s", ty); else return ty; } /* utilities */ /* returns new string w/ parens stripped */ -String* CFFI::strip_parens(String *string) { - char *s=Char(string), *p; - int len=Len(string); +String *CFFI::strip_parens(String *string) { + char *s = Char(string), *p; + int len = Len(string); String *res; - - if (len==0 || s[0] != '(' || s[len-1] != ')') { + + if (len == 0 || s[0] != '(' || s[len - 1] != ')') { return NewString(string); } - - p=(char *)malloc(len-2+1); + + p = (char *) malloc(len - 2 + 1); if (!p) { Printf(stderr, "Malloc failed\n"); SWIG_exit(EXIT_FAILURE); } - - strncpy(p, s+1, len-1); - p[len-2]=0; /* null terminate */ - - res=NewString(p); + + strncpy(p, s + 1, len - 1); + p[len - 2] = 0; /* null terminate */ + + res = NewString(p); free(p); - + return res; } -String* CFFI::trim(String *str) { +String *CFFI::trim(String *str) { char *c = Char(str); - while (*c != '\0' && isspace((int)*c)) + while (*c != '\0' && isspace((int) *c)) ++c; String *result = NewString(c); Chop(result); return result; } -String * CFFI::infix_to_prefix(String *val, char split_op, const String *op, String *type) { +String *CFFI::infix_to_prefix(String *val, char split_op, const String *op, String *type) { List *ored = Split(val, split_op, -1); // some float hackery //i don't understand it, if you do then please explain // if ( ((split_op == '+') || (split_op == '-')) && Len(ored) == 2 && // (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || - // SwigType_type(type) == T_LONGDOUBLE) ) { + // SwigType_type(type) == T_LONGDOUBLE) ) { // // check that we're not splitting a float // String *possible_result = convert_literal(val, type, false); // if (possible_result) return possible_result; - + // } // try parsing the split results. if any part fails, kick out. bool part_failed = false; if (Len(ored) > 1) { String *result = NewStringf("(%s", op); - for(Iterator i = First(ored); i.item; i = Next(i)) { + for (Iterator i = First(ored); i.item; i = Next(i)) { String *converted = convert_literal(i.item, type); - if(converted) { - Printf(result, " %s", converted); - Delete(converted); + if (converted) { + Printf(result, " %s", converted); + Delete(converted); } else { - part_failed = true; - break; + part_failed = true; + break; } } Printf(result, ")"); Delete(ored); return part_failed ? 0 : result; - } - else { + } else { Delete(ored); } return 0; @@ -922,22 +886,29 @@ String * CFFI::infix_to_prefix(String *val, char split_op, const String *op, Str try_to_split defaults to true (see stub above). */ -String * CFFI::convert_literal(String *literal, String *type, bool try_to_split) { +String *CFFI::convert_literal(String *literal, String *type, bool try_to_split) { String *num_param = Copy(literal); String *trimmed = trim(num_param); - String *num=strip_parens(trimmed), *res=0; + String *num = strip_parens(trimmed), *res = 0; Delete(trimmed); - char *s=Char(num); + char *s = Char(num); // very basic parsing of infix expressions. - if(try_to_split) { - if( (res = infix_to_prefix(num, '|', "cl:logior", type)) ) return res; - if( (res = infix_to_prefix(num, '&', "cl:logand", type)) ) return res; - if( (res = infix_to_prefix(num, '^', "cl:logxor", type)) ) return res; - if( (res = infix_to_prefix(num, '*', "cl:*", type)) ) return res; - if( (res = infix_to_prefix(num, '/', "cl:/", type)) ) return res; - if( (res = infix_to_prefix(num, '+', "cl:+", type)) ) return res; - if( (res = infix_to_prefix(num, '-', "cl:-", type)) ) return res; + if (try_to_split) { + if ((res = infix_to_prefix(num, '|', "cl:logior", type))) + return res; + if ((res = infix_to_prefix(num, '&', "cl:logand", type))) + return res; + if ((res = infix_to_prefix(num, '^', "cl:logxor", type))) + return res; + if ((res = infix_to_prefix(num, '*', "cl:*", type))) + return res; + if ((res = infix_to_prefix(num, '/', "cl:/", type))) + return res; + if ((res = infix_to_prefix(num, '+', "cl:+", type))) + return res; + if ((res = infix_to_prefix(num, '-', "cl:-", type))) + return res; } if (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || SwigType_type(type) == T_LONGDOUBLE) { @@ -950,84 +921,80 @@ String * CFFI::convert_literal(String *literal, String *type, bool try_to_split) bool is_literal = isdigit(*num_start) || (*num_start == '.') || (*num_start == '+') || (*num_start == '-'); String *lisp_exp = 0; - if(is_literal) { + if (is_literal) { if (*num_end == 'f' || *num_end == 'F') { - lisp_exp = NewString("f"); + lisp_exp = NewString("f"); } else { - lisp_exp = NewString("d"); + lisp_exp = NewString("d"); } if (*num_end == 'l' || *num_end == 'L' || *num_end == 'f' || *num_end == 'F') { - *num_end = '\0'; - num_end--; + *num_end = '\0'; + num_end--; } int exponents = Replaceall(num, "e", lisp_exp) + Replaceall(num, "E", lisp_exp); if (!exponents) - Printf(num, "%s0", lisp_exp); + Printf(num, "%s0", lisp_exp); - if (exponents > 1 || (exponents + Replaceall(num,".",".") == 0)) { - Delete(num); - num = 0; + if (exponents > 1 || (exponents + Replaceall(num, ".", ".") == 0)) { + Delete(num); + num = 0; } } return num; - } - else if (SwigType_type(type) == T_CHAR) { + } else if (SwigType_type(type) == T_CHAR) { /* Use CL syntax for character literals */ Delete(num); // Printf(stderr, "%s %c %d", s, s[2], s); return NewStringf("#\\%c", s[2]); - } - else if (SwigType_type(type) == T_STRING) { + } else if (SwigType_type(type) == T_STRING) { /* Use CL syntax for string literals */ Delete(num); return NewStringf("\"%s\"", num_param); - } - else if (SwigType_type(type) == T_INT){ - Replaceall(num, "u", ""); Replaceall(num, "U", ""); - Replaceall(num, "l", ""); Replaceall(num, "L", ""); - - int i,j; - if (sscanf (s,"%d >> %d",&i,&j) == 2){ + } else if (SwigType_type(type) == T_INT) { + Replaceall(num, "u", ""); + Replaceall(num, "U", ""); + Replaceall(num, "l", ""); + Replaceall(num, "L", ""); + + int i, j; + if (sscanf(s, "%d >> %d", &i, &j) == 2) { Delete(num); - return NewStringf("(cl:ash %d -%d)",i,j); - } - else if (sscanf(s,"%d << %d",&i,&j) == 2){ + return NewStringf("(cl:ash %d -%d)", i, j); + } else if (sscanf(s, "%d << %d", &i, &j) == 2) { Delete(num); - return NewStringf("(cl:ash %d %d)",i,j); + return NewStringf("(cl:ash %d %d)", i, j); } } - if (Len(num) >= 2 && s[0] == '0') { /* octal or hex */ + if (Len(num) >= 2 && s[0] == '0') { /* octal or hex */ Delete(num); - if(s[1] == 'x') - return NewStringf("#x%s", s+2); + if (s[1] == 'x') + return NewStringf("#x%s", s + 2); else - return NewStringf("#o%s", s+1); + return NewStringf("#o%s", s + 1); } return num; } //less flexible as it does the conversion in C, the lispify name does the conversion in lisp -String* CFFI::lispy_name(char *name) { - bool helper=false; - String *new_name=NewString(""); - for(unsigned int i=0;i < strlen(name);i++) { - if(name[i] =='_' || name[i] =='-') { - Printf(new_name,"%c",'-'); - helper=false; - } - else if(name[i]>='A' && name[i]<='Z') { - if(helper) - Printf(new_name,"%c",'-'); - Printf(new_name,"%c",('a' + (name[i] - 'A'))); +String *CFFI::lispy_name(char *name) { + bool helper = false; + String *new_name = NewString(""); + for (unsigned int i = 0; i < strlen(name); i++) { + if (name[i] == '_' || name[i] == '-') { + Printf(new_name, "%c", '-'); helper = false; - } - else { + } else if (name[i] >= 'A' && name[i] <= 'Z') { + if (helper) + Printf(new_name, "%c", '-'); + Printf(new_name, "%c", ('a' + (name[i] - 'A'))); + helper = false; + } else { helper = true; - Printf(new_name,"%c",name[i]); + Printf(new_name, "%c", name[i]); } } return new_name; @@ -1036,5 +1003,3 @@ String* CFFI::lispy_name(char *name) { extern "C" Language *swig_cffi(void) { return new CFFI(); } - - diff --git a/SWIG/Source/Modules/chicken.cxx b/SWIG/Source/Modules/chicken.cxx index 4b912759e..c501db98a 100644 --- a/SWIG/Source/Modules/chicken.cxx +++ b/SWIG/Source/Modules/chicken.cxx @@ -13,7 +13,7 @@ char cvsroot_chicken_cxx[] = "$Header$"; #include -static const char *chicken_usage = (char*)"\ +static const char *chicken_usage = (char *) "\ \ CHICKEN Options (available with -chicken)\n\ -proxy - Export TinyCLOS class definitions\n\ @@ -24,83 +24,82 @@ CHICKEN Options (available with -chicken)\n\ -noclosuses - Do not (declare (uses ...)) in scheme file\n\ -nocollection - Do not register pointers with chicken garbage\n\ collector and export destructors\n\ -\n" -; +\n"; -static char *module = 0; -static char *chicken_path=(char*)"chicken"; -static int num_methods = 0; +static char *module = 0; +static char *chicken_path = (char *) "chicken"; +static int num_methods = 0; -static File *f_runtime = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_init = 0; -static String *chickentext = 0; -static String *closprefix = 0; -static String *swigtype_ptr = 0; +static File *f_runtime = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_init = 0; +static String *chickentext = 0; +static String *closprefix = 0; +static String *swigtype_ptr = 0; -static String *f_sym_size = 0; +static String *f_sym_size = 0; /* some options */ -static int declare_unit = 1; -static int no_collection = 0; -static int clos_uses = 1; +static int declare_unit = 1; +static int no_collection = 0; +static int clos_uses = 1; /* C++ Support + Clos Classes */ -static int clos = 0; -static String *c_class_name = 0; -static String *class_name = 0; -static String *short_class_name = 0; +static int clos = 0; +static String *c_class_name = 0; +static String *class_name = 0; +static String *short_class_name = 0; -static int in_class = 0; -static int have_constructor = 0; -static bool exporting_destructor = false; -static bool exporting_constructor = false; -static String *constructor_name = 0; -static String *member_name = 0; +static int in_class = 0; +static int have_constructor = 0; +static bool exporting_destructor = false; +static bool exporting_constructor = false; +static String *constructor_name = 0; +static String *member_name = 0; /* sections of the .scm code */ -static String *scm_const_defs = 0; -static String *clos_class_defines = 0; -static String *clos_methods = 0; +static String *scm_const_defs = 0; +static String *clos_class_defines = 0; +static String *clos_methods = 0; /* Some clos options */ -static int useclassprefix = 0; -static String *clossymnameprefix = 0; -static int hide_primitive = 1; -static Hash *primitive_names = 0; +static int useclassprefix = 0; +static String *clossymnameprefix = 0; +static int hide_primitive = 1; +static Hash *primitive_names = 0; /* Used for overloading constructors */ -static int has_constructor_args = 0; -static List *constructor_arg_types = 0; -static String *constructor_dispatch = 0; +static int has_constructor_args = 0; +static List *constructor_arg_types = 0; +static String *constructor_dispatch = 0; -static Hash *overload_parameter_lists = 0; +static Hash *overload_parameter_lists = 0; -class CHICKEN : public Language { +class CHICKEN:public Language { public: virtual void main(int argc, char *argv[]); - virtual int top(Node *n); - virtual int functionWrapper(Node *n); - virtual int variableWrapper(Node *n); - virtual int constantWrapper(Node *n); - virtual int classHandler(Node *n); - virtual int memberfunctionHandler(Node *n); - virtual int membervariableHandler(Node *n); - virtual int constructorHandler(Node *n); - virtual int destructorHandler(Node *n); - virtual int validIdentifier(String *s); - virtual int staticmembervariableHandler(Node *n); - virtual int staticmemberfunctionHandler(Node *n); - virtual int importDirective(Node *n); + virtual int top(Node *n); + virtual int functionWrapper(Node *n); + virtual int variableWrapper(Node *n); + virtual int constantWrapper(Node *n); + virtual int classHandler(Node *n); + virtual int memberfunctionHandler(Node *n); + virtual int membervariableHandler(Node *n); + virtual int constructorHandler(Node *n); + virtual int destructorHandler(Node *n); + virtual int validIdentifier(String *s); + virtual int staticmembervariableHandler(Node *n); + virtual int staticmemberfunctionHandler(Node *n); + virtual int importDirective(Node *n); protected: - void addMethod(String *scheme_name, String *function); + void addMethod(String *scheme_name, String *function); /* Return true iff T is a pointer type */ - int isPointer(SwigType *t); - void dispatchFunction(Node *n); + int isPointer(SwigType *t); + void dispatchFunction(Node *n); String *chickenNameMapping(String *, String_or_char *); String *chickenPrimitiveName(String *); @@ -114,86 +113,82 @@ protected: * swig_chicken() - Instantiate module * ----------------------------------------------------------------------- */ -static Language * new_swig_chicken() { +static Language *new_swig_chicken() { return new CHICKEN(); } -extern "C" { - Language * swig_chicken(void) { +extern "C" { + Language *swig_chicken(void) { return new_swig_chicken(); } } -void -CHICKEN::main(int argc, char *argv[]) -{ +void CHICKEN::main(int argc, char *argv[]) { int i; - + SWIG_library_directory(chicken_path); - + // Look for certain command line options for (i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-help") == 0) { - fputs(chicken_usage, stdout); - SWIG_exit(0); - } - else if (strcmp(argv[i],"-proxy") == 0) { - clos = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-closprefix") == 0) { - if (argv[i+1]) { - clossymnameprefix = NewString(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-useclassprefix") == 0) { - useclassprefix = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-unhideprimitive") == 0) { - hide_primitive = 0; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nounit") == 0) { - declare_unit = 0; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noclosuses") == 0) { - clos_uses = 0; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocollection") == 0) { - no_collection = 1; - Swig_mark_arg(i); + fputs(chicken_usage, stdout); + SWIG_exit(0); + } else if (strcmp(argv[i], "-proxy") == 0) { + clos = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-closprefix") == 0) { + if (argv[i + 1]) { + clossymnameprefix = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-useclassprefix") == 0) { + useclassprefix = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-unhideprimitive") == 0) { + hide_primitive = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nounit") == 0) { + declare_unit = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noclosuses") == 0) { + clos_uses = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocollection") == 0) { + no_collection = 1; + Swig_mark_arg(i); } } } - if (!clos) hide_primitive = 0; + if (!clos) + hide_primitive = 0; // Add a symbol for this module - Preprocessor_define("SWIGCHICKEN 1",0); - + Preprocessor_define("SWIGCHICKEN 1", 0); + // Set name of typemaps - + SWIG_typemap_lang("chicken"); // Read in default typemaps */ SWIG_config_file("chicken.swg"); allow_overloading(); } - -int -CHICKEN::top(Node *n) -{ + +int CHICKEN::top(Node *n) { String *chicken_filename = NewString(""); File *f_scm; String *scmmodule; - + /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - - f_runtime = NewFile(outfile,"w"); + String *outfile = Getattr(n, "outfile"); + + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); @@ -206,16 +201,16 @@ CHICKEN::top(Node *n) f_sym_size = NewString(""); primitive_names = NewHash(); overload_parameter_lists = NewHash(); - + /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); Swig_register_filebyname("chicken", chickentext); Swig_register_filebyname("closprefix", closprefix); - + clos_class_defines = NewString(""); clos_methods = NewString(""); scm_const_defs = NewString(""); @@ -227,64 +222,61 @@ CHICKEN::top(Node *n) if (no_collection) Printf(f_runtime, "#define SWIG_CHICKEN_NO_COLLECTION 1\n"); - + /* Set module name */ module = Swig_copy_string(Char(Getattr(n, "name"))); scmmodule = NewString(module); Replaceall(scmmodule, "_", "-"); - - Printf(f_header,"#define SWIG_init swig_%s_init\n", module); - Printf(f_header,"#define SWIG_name \"%s\"\n", scmmodule); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"extern \"C\" {\n"); - Printf(f_wrappers,"#endif\n\n"); + Printf(f_header, "#define SWIG_init swig_%s_init\n", module); + Printf(f_header, "#define SWIG_name \"%s\"\n", scmmodule); + + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "extern \"C\" {\n"); + Printf(f_wrappers, "#endif\n\n"); Language::top(n); SwigType_emit_type_table(f_runtime, f_wrappers); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"}\n"); - Printf(f_wrappers,"#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "}\n"); + Printf(f_wrappers, "#endif\n"); Printf(f_init, "C_kontinue (continuation, ret);\n"); Printf(f_init, "}\n\n"); - Printf(f_init,"#ifdef __cplusplus\n"); - Printf(f_init,"}\n"); - Printf(f_init,"#endif\n"); + Printf(f_init, "#ifdef __cplusplus\n"); + Printf(f_init, "}\n"); + Printf(f_init, "#endif\n"); - Printf(chicken_filename,"%s%s.scm", SWIG_output_directory(), module); - if ((f_scm = NewFile(chicken_filename,"w")) == 0) { + Printf(chicken_filename, "%s%s.scm", SWIG_output_directory(), module); + if ((f_scm = NewFile(chicken_filename, "w")) == 0) { FileErrorDisplay(chicken_filename); SWIG_exit(EXIT_FAILURE); } Printv(f_scm, - ";; -*- buffer-read-only: t -*- vi: set ro:\n", - ";; This file was created automatically by SWIG.\n", - ";; Don't modify this file, modify the SWIG interface instead.\n", - NIL); + ";; -*- buffer-read-only: t -*- vi: set ro:\n", + ";; This file was created automatically by SWIG.\n", ";; Don't modify this file, modify the SWIG interface instead.\n", NIL); if (declare_unit) - Printv(f_scm,"(declare (unit ", scmmodule, "))\n\n", NIL); - Printv(f_scm,"(declare \n", - tab4, "(hide swig-init swig-init-return)\n", - tab4, "(foreign-declare \"C_extern void swig_", module, "_init(C_word,C_word,C_word) C_noret;\"))\n", NIL); - Printv(f_scm,"(define swig-init (##core#primitive \"swig_", module, - "_init\"))\n", NIL); - Printv(f_scm,"(define swig-init-return (swig-init))\n\n", NIL); + Printv(f_scm, "(declare (unit ", scmmodule, "))\n\n", NIL); + Printv(f_scm, "(declare \n", + tab4, "(hide swig-init swig-init-return)\n", + tab4, "(foreign-declare \"C_extern void swig_", module, "_init(C_word,C_word,C_word) C_noret;\"))\n", NIL); + Printv(f_scm, "(define swig-init (##core#primitive \"swig_", module, "_init\"))\n", NIL); + Printv(f_scm, "(define swig-init-return (swig-init))\n\n", NIL); if (clos) { //Printf (f_scm, "(declare (uses tinyclos))\n"); //New chicken versions have tinyclos as an egg Printf(f_scm, "(require-extension tinyclos)\n"); - Replaceall(closprefix,"$module", scmmodule); - Printf (f_scm, "%s\n", closprefix); - Printf (f_scm, "%s\n", clos_class_defines); - Printf (f_scm, "%s\n", clos_methods); + Replaceall(closprefix, "$module", scmmodule); + Printf(f_scm, "%s\n", closprefix); + Printf(f_scm, "%s\n", clos_class_defines); + Printf(f_scm, "%s\n", clos_methods); } else { - Printf (f_scm, "%s\n", scm_const_defs); + Printf(f_scm, "%s\n", scm_const_defs); } Printf(f_scm, "%s\n", chickentext); @@ -315,9 +307,9 @@ CHICKEN::top(Node *n) /* Close all of the files */ Delete(primitive_names); Delete(scmmodule); - Dump(f_header,f_runtime); - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_header, f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_sym_size); @@ -327,17 +319,15 @@ CHICKEN::top(Node *n) return SWIG_OK; } -int -CHICKEN::functionWrapper(Node *n) -{ - - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); +int CHICKEN::functionWrapper(Node *n) { - Parm *p; - int i; + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + + Parm *p; + int i; String *wname; String *source; Wrapper *f; @@ -352,127 +342,118 @@ CHICKEN::functionWrapper(Node *n) bool any_specialized_arg = false; List *function_arg_types = NewList(); - int num_required; - int num_arguments; - int have_argout; + int num_required; + int num_arguments; + int have_argout; Printf(mangle, "\"%s\"", SwigType_manglestr(d)); - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } f = NewWrapper(); - wname = NewString(""); + wname = NewString(""); get_pointers = NewString(""); - cleanup = NewString(""); - argout = NewString(""); - declfunc = NewString(""); - scmname = NewString(iname); + cleanup = NewString(""); + argout = NewString(""); + declfunc = NewString(""); + scmname = NewString(iname); Replaceall(scmname, "_", "-"); /* Local vars */ - Wrapper_add_local(f,"resultobj", "C_word resultobj"); + Wrapper_add_local(f, "resultobj", "C_word resultobj"); /* Write code to extract function parameters. */ emit_args(d, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); Append(wname, Swig_name_wrapper(iname)); if (overname) { Append(wname, overname); } - // Check for interrupts - Printv (f->code, "C_trace(\"",scmname,"\");\n", NIL); + Printv(f->code, "C_trace(\"", scmname, "\");\n", NIL); - Printv(f->def, - "static ", - "void ", wname, - " (C_word argc, C_word closure, C_word continuation", - NIL); - Printv(declfunc, - "void ", wname, - "(C_word,C_word,C_word", - NIL); + Printv(f->def, "static ", "void ", wname, " (C_word argc, C_word closure, C_word continuation", NIL); + Printv(declfunc, "void ", wname, "(C_word,C_word,C_word", NIL); /* Generate code for argument marshalling */ - for (i = 0, p=l; i < num_arguments; i++) { - - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + for (i = 0, p = l; i < num_arguments; i++) { + + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); - source = NewStringf("scm%d",i+1); + source = NewStringf("scm%d", i + 1); - Printf(f->def, ", C_word scm%d", i+1); - Printf(declfunc,",C_word"); + Printf(f->def, ", C_word scm%d", i + 1); + Printf(declfunc, ",C_word"); /* Look for an input typemap */ - if ((tm = Getattr(p,"tmap:in"))) { - String *parse = Getattr(p,"tmap:in:parse"); + if ((tm = Getattr(p, "tmap:in"))) { + String *parse = Getattr(p, "tmap:in:parse"); if (!parse) { - Replaceall(tm,"$source",source); - Replaceall(tm,"$target",ln); - Replaceall(tm,"$input", source); - Setattr(p,"emit:input", source); /* Save the location of - the object */ - - if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm,"$disown","0"); - } + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); /* Save the location of + the object */ - if (i >= num_required) - Printf(get_pointers, "if (argc-2>%i && (%s)) {\n", i, source); - Printv(get_pointers,tm,"\n", NIL); - if (i >= num_required) - Printv(get_pointers, "}\n", NIL); + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + + if (i >= num_required) + Printf(get_pointers, "if (argc-2>%i && (%s)) {\n", i, source); + Printv(get_pointers, tm, "\n", NIL); + if (i >= num_required) + Printv(get_pointers, "}\n", NIL); + + if (clos) { + if (i < num_required) { + if (strcmp("void", Char(pt)) != 0) { + Node *class_node = 0; + String *clos_code = Getattr(p, "tmap:in:closcode"); + class_node = classLookup(pt); + if (clos_code && class_node) { + String *class_name = NewStringf("<%s>", Getattr(class_node, "sym:name")); + Replaceall(class_name, "_", "-"); + Append(function_arg_types, class_name); + Append(function_arg_types, Copy(clos_code)); + any_specialized_arg = true; + Delete(class_name); + } else { + Append(function_arg_types, ""); + Append(function_arg_types, "$input"); + } + } + } + } - if (clos) { - if (i < num_required) { - if (strcmp("void", Char(pt)) != 0) { - Node *class_node = 0; - String *clos_code = Getattr(p, "tmap:in:closcode"); - class_node = classLookup(pt); - if (clos_code && class_node) { - String *class_name = NewStringf("<%s>", Getattr(class_node, "sym:name")); - Replaceall(class_name, "_", "-"); - Append(function_arg_types, class_name); - Append(function_arg_types, Copy(clos_code)); - any_specialized_arg = true; - Delete(class_name); - } else { - Append(function_arg_types, ""); - Append(function_arg_types, "$input"); - } - } - } - } - } else { } - - p = Getattr(p,"tmap:in:next"); + + p = Getattr(p, "tmap:in:next"); continue; } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n", - SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); break; } @@ -482,7 +463,7 @@ CHICKEN::functionWrapper(Node *n) /* finish argument marshalling */ - Printf(f->def, ") {"); + Printf(f->def, ") {"); Printf(declfunc, ")"); if (num_required != num_arguments) { @@ -491,174 +472,165 @@ CHICKEN::functionWrapper(Node *n) /* First check the number of arguments is correct */ if (num_arguments != num_required) - Printf(f->code, "if (argc-2<%i || argc-2>%i) C_bad_argc(argc,%i);\n", num_required, num_arguments, num_required+2); + Printf(f->code, "if (argc-2<%i || argc-2>%i) C_bad_argc(argc,%i);\n", num_required, num_arguments, num_required + 2); else - Printf(f->code, "if (argc!=%i) C_bad_argc(argc,%i);\n", num_arguments+2, num_arguments+2); + Printf(f->code, "if (argc!=%i) C_bad_argc(argc,%i);\n", num_arguments + 2, num_arguments + 2); /* Now piece together the first part of the wrapper function */ Printv(f->code, get_pointers, NIL); /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } } /* Emit the function call */ - emit_action(n,f); + emit_action(n, f); /* Insert argument output code */ have_argout = 0; for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - + if ((tm = Getattr(p, "tmap:argout"))) { + if (!have_argout) { - have_argout = 1; - // Print initial argument output code - Printf(f->code,"SWIG_Chicken_SetupArgout\n"); + have_argout = 1; + // Print initial argument output code + Printf(f->code, "SWIG_Chicken_SetupArgout\n"); } - - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); + + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); Printf(argout, "%s", tm); - p = Getattr(p,"tmap:argout:next"); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } /* Return the function value */ - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - Replaceall(tm,"$source", "result"); - Replaceall(tm,"$target", "resultobj"); - Replaceall(tm,"$result", "resultobj"); - if (GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","1"); + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "1"); } else { - Replaceall(tm,"$owner","0"); + Replaceall(tm, "$owner", "0"); } Printf(f->code, "%s", tm); if (have_argout) Printf(f->code, "\nSWIG_APPEND_VALUE(resultobj);\n"); - + } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", - SwigType_str(d,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } /* Insert the argumetn output code */ Printv(f->code, argout, NIL); /* Output cleanup code */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } if (have_argout) { Printf(f->code, "C_kontinue(continuation,C_SCHEME_END_OF_LIST);\n"); } else { - if (exporting_constructor && clos && hide_primitive) { - /* Don't return a proxy, the wrapped CLOS class is the proxy */ - Printf(f->code, "C_kontinue(continuation,resultobj);\n"); - } else { - // make the continuation the proxy creation function, if one exists - Printv(f->code,"{\n", - "C_word func;\n", - "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", - "if (C_swig_is_closurep(func))\n", - " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", - "else\n", - " C_kontinue(continuation, resultobj);\n", - "}\n", NIL); - } + if (exporting_constructor && clos && hide_primitive) { + /* Don't return a proxy, the wrapped CLOS class is the proxy */ + Printf(f->code, "C_kontinue(continuation,resultobj);\n"); + } else { + // make the continuation the proxy creation function, if one exists + Printv(f->code, "{\n", + "C_word func;\n", + "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", + "if (C_swig_is_closurep(func))\n", + " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", + "else\n", " C_kontinue(continuation, resultobj);\n", "}\n", NIL); + } } /* Error handling code */ #ifdef USE_FAIL - Printf(f->code,"fail:\n"); - Printv(f->code,cleanup,NIL); - Printf(f->code,"swig_panic (\"failure in " - "'$symname' SWIG function wrapper\");\n"); + Printf(f->code, "fail:\n"); + Printv(f->code, cleanup, NIL); + Printf(f->code, "swig_panic (\"failure in " "'$symname' SWIG function wrapper\");\n"); #endif - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); - Replaceall(f->code,"$result","resultobj"); + Replaceall(f->code, "$symname", iname); + Replaceall(f->code, "$result", "resultobj"); /* Dump the function out */ - Printv(f_wrappers, - "static ", - declfunc, " C_noret;\n", NIL); - Wrapper_print(f,f_wrappers); + Printv(f_wrappers, "static ", declfunc, " C_noret;\n", NIL); + Wrapper_print(f, f_wrappers); - Setattr(n,"wrap:name", wname); + Setattr(n, "wrap:name", wname); /* Now register the function with the interpreter. */ - if (!Getattr(n,"sym:overloaded")) { + if (!Getattr(n, "sym:overloaded")) { if (exporting_destructor && !no_collection) { - Printf(f_init, - "((swig_chicken_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (swig_chicken_destructor) %s;\n", - swigtype_ptr, wname); + Printf(f_init, "((swig_chicken_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (swig_chicken_destructor) %s;\n", swigtype_ptr, wname); } else { addMethod(scmname, wname); } /* Only export if we are not in a class, or if in a class memberfunction */ if (!in_class || member_name) { - String *method_def; - String *clos_name; - if (in_class) - clos_name = NewString(member_name); - else - clos_name = chickenNameMapping(scmname, (char *)""); + String *method_def; + String *clos_name; + if (in_class) + clos_name = NewString(member_name); + else + clos_name = chickenNameMapping(scmname, (char *) ""); - if (!any_specialized_arg) { - method_def = NewString(""); - Printv(method_def, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")", NIL); - } else { - method_def = buildClosFunctionCall(function_arg_types, clos_name, chickenPrimitiveName(scmname)); - } - Printv(clos_methods, method_def, "\n", NIL); - Delete(clos_name); - Delete(method_def); + if (!any_specialized_arg) { + method_def = NewString(""); + Printv(method_def, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")", NIL); + } else { + method_def = buildClosFunctionCall(function_arg_types, clos_name, chickenPrimitiveName(scmname)); + } + Printv(clos_methods, method_def, "\n", NIL); + Delete(clos_name); + Delete(method_def); } if (have_constructor && !has_constructor_args && any_specialized_arg) { @@ -675,7 +647,7 @@ CHICKEN::functionWrapper(Node *n) Append(flist, Copy(function_arg_types)); - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { dispatchFunction(n); } } @@ -691,12 +663,11 @@ CHICKEN::functionWrapper(Node *n) return SWIG_OK; } -int -CHICKEN::variableWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); +int CHICKEN::variableWrapper(Node *n) { + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); String *wname = NewString(""); String *mangle = NewString(""); @@ -704,149 +675,132 @@ CHICKEN::variableWrapper(Node *n) { String *tm2 = NewString("");; String *argnum = NewString("0"); String *arg = NewString("argv[0]"); - Wrapper *f; + Wrapper *f; String *overname = 0; String *scmname; - int num_required; - int num_arguments; + int num_required; + int num_arguments; - scmname = NewString(iname); + scmname = NewString(iname); Replaceall(scmname, "_", "-"); Printf(mangle, "\"%s\"", SwigType_manglestr(t)); - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } f = NewWrapper(); - + /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); // evaluation function names Append(wname, Swig_name_wrapper(iname)); if (overname) { Append(wname, overname); } - // Check for interrupts - Printv (f->code, "C_trace(\"",scmname,"\");\n", NIL); + Printv(f->code, "C_trace(\"", scmname, "\");\n", NIL); if (1 || (SwigType_type(t) != T_USER) || (isPointer(t))) { - - Printv(f->def, - "static ", - "void ",wname,"(C_word, C_word, C_word, C_word) C_noret;\n", - NIL); - Printv(f->def, - "static " - "void ",wname,"(C_word argc, C_word closure, " - "C_word continuation, C_word value) {\n", - NIL); - + + Printv(f->def, "static ", "void ", wname, "(C_word, C_word, C_word, C_word) C_noret;\n", NIL); + Printv(f->def, "static " "void ", wname, "(C_word argc, C_word closure, " "C_word continuation, C_word value) {\n", NIL); + Wrapper_add_local(f, "resultobj", "C_word resultobj"); Printf(f->code, "if (argc!=2 && argc!=3) C_bad_argc(argc,2);\n"); /* Check for a setting of the variable value */ - if (!GetFlag(n,"feature:immutable")) { + if (!GetFlag(n, "feature:immutable")) { Printf(f->code, "if (argc > 2) {\n"); - if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { - Replaceall(tm,"$source","value"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","value"); - /* Printv(f->code, tm, "\n",NIL); */ + if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { + Replaceall(tm, "$source", "value"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "value"); + /* Printv(f->code, tm, "\n",NIL); */ emit_action_code(n, f, tm); - } - else { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, - "Unable to set variable of type %s.\n", - SwigType_str(t,0)); + } else { + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); } Printf(f->code, "}\n"); } String *varname; - if (SwigType_istemplate((char*)name)) { - varname = SwigType_namestr((char *)name); + if (SwigType_istemplate((char *) name)) { + varname = SwigType_namestr((char *) name); } else { varname = name; } - + // Now return the value of the variable - regardless // of evaluating or setting. - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source",varname); - Replaceall(tm,"$varname",varname); - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$result","resultobj"); + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", varname); + Replaceall(tm, "$varname", varname); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); /* Printf(f->code, "%s\n", tm); */ emit_action_code(n, f, tm); - } - else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + } else { + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); } - Printv(f->code,"{\n", - "C_word func;\n", - "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", - "if (C_swig_is_closurep(func))\n", - " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", - "else\n", - " C_kontinue(continuation, resultobj);\n", - "}\n", NIL); + Printv(f->code, "{\n", + "C_word func;\n", + "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", + "if (C_swig_is_closurep(func))\n", + " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", + "else\n", " C_kontinue(continuation, resultobj);\n", "}\n", NIL); /* Error handling code */ #ifdef USE_FAIL - Printf(f->code,"fail:\n"); - Printf(f->code,"swig_panic (\"failure in " - "'%s' SWIG wrapper\");\n", proc_name); + Printf(f->code, "fail:\n"); + Printf(f->code, "swig_panic (\"failure in " "'%s' SWIG wrapper\");\n", proc_name); #endif - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); Wrapper_print(f, f_wrappers); - + /* Now register the variable with the interpreter. */ addMethod(scmname, wname); if (!in_class || member_name) { - String *clos_name; - if (in_class) - clos_name = NewString(member_name); - else - clos_name = chickenNameMapping(scmname, (char *)""); + String *clos_name; + if (in_class) + clos_name = NewString(member_name); + else + clos_name = chickenNameMapping(scmname, (char *) ""); - Node *class_node = classLookup(t); - String *clos_code = Getattr(n, "tmap:varin:closcode"); - if (class_node && clos_code && !GetFlag(n, "feature:immutable")) { - Replaceall(clos_code,"$input", "(car lst)"); - Printv(clos_methods, "(define (", clos_name, " . lst) (if (null? lst) (", chickenPrimitiveName(scmname), ") (", - chickenPrimitiveName(scmname), " ", clos_code, ")))\n", NIL); - } else { - /* Simply re-export the procedure */ - if (GetFlag(n, "feature:immutable") && GetFlag(n, "feature:constasvar")) { - Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL); - Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL); - } else { - Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL); - } - } - Delete(clos_name); + Node *class_node = classLookup(t); + String *clos_code = Getattr(n, "tmap:varin:closcode"); + if (class_node && clos_code && !GetFlag(n, "feature:immutable")) { + Replaceall(clos_code, "$input", "(car lst)"); + Printv(clos_methods, "(define (", clos_name, " . lst) (if (null? lst) (", chickenPrimitiveName(scmname), ") (", + chickenPrimitiveName(scmname), " ", clos_code, ")))\n", NIL); + } else { + /* Simply re-export the procedure */ + if (GetFlag(n, "feature:immutable") && GetFlag(n, "feature:constasvar")) { + Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL); + Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL); + } else { + Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL); + } + } + Delete(clos_name); } } else { - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, - "Unsupported variable type %s (ignored).\n", - SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported variable type %s (ignored).\n", SwigType_str(t, 0)); } Delete(wname); @@ -862,15 +816,13 @@ CHICKEN::variableWrapper(Node *n) { * constantWrapper() * ------------------------------------------------------------ */ -int -CHICKEN::constantWrapper(Node *n) -{ +int CHICKEN::constantWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *value = Getattr(n,"value"); + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *value = Getattr(n, "value"); String *proc_name = NewString(""); String *wname = NewString(""); @@ -880,16 +832,16 @@ CHICKEN::constantWrapper(Node *n) String *source = NewString(""); String *argnum = NewString("0"); String *arg = NewString("argv[0]"); - Wrapper *f; + Wrapper *f; String *overname = 0; String *scmname; String *rvalue; SwigType *nctype; - int num_required; - int num_arguments; + int num_required; + int num_arguments; - scmname = NewString(iname); + scmname = NewString(iname); Replaceall(scmname, "_", "-"); Printf(source, "swig_const_%s", iname); @@ -897,10 +849,11 @@ CHICKEN::constantWrapper(Node *n) Printf(mangle, "\"%s\"", SwigType_manglestr(t)); - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } Append(wname, Swig_name_wrapper(iname)); @@ -923,110 +876,94 @@ CHICKEN::constantWrapper(Node *n) /* Special hook for member pointer */ if (SwigType_type(t) == T_MPOINTER) { - Printf(f_header, "static %s = %s;\n", SwigType_str(t,wname), rvalue); + Printf(f_header, "static %s = %s;\n", SwigType_str(t, wname), rvalue); value = wname; } if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) { - Replaceall(tm,"$source",rvalue); - Replaceall(tm,"$target",source); - Replaceall(tm,"$result",source); - Replaceall(tm,"$value",rvalue); + Replaceall(tm, "$source", rvalue); + Replaceall(tm, "$target", source); + Replaceall(tm, "$result", source); + Replaceall(tm, "$value", rvalue); Printf(f_header, "%s\n", tm); - } - else { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value.\n"); + } else { + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } f = NewWrapper(); - + /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); // evaluation function names // Check for interrupts - Printv (f->code, "C_trace(\"",scmname,"\");\n", NIL); + Printv(f->code, "C_trace(\"", scmname, "\");\n", NIL); if (1 || (SwigType_type(t) != T_USER) || (isPointer(t))) { - - Printv(f->def, - "static ", - "void ",wname,"(C_word, C_word, C_word) C_noret;\n", - NIL); - Printv(f->def, - "static ", - "void ",wname,"(C_word argc, C_word closure, " - "C_word continuation) {\n", - NIL); - + Printv(f->def, "static ", "void ", wname, "(C_word, C_word, C_word) C_noret;\n", NIL); + + Printv(f->def, "static ", "void ", wname, "(C_word argc, C_word closure, " "C_word continuation) {\n", NIL); + Wrapper_add_local(f, "resultobj", "C_word resultobj"); Printf(f->code, "if (argc!=2) C_bad_argc(argc,2);\n"); // Return the value of the variable - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { - Replaceall(tm,"$source",source); - Replaceall(tm,"$varname",source); - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$result","resultobj"); + Replaceall(tm, "$source", source); + Replaceall(tm, "$varname", source); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); /* Printf(f->code, "%s\n", tm); */ emit_action_code(n, f, tm); - } - else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + } else { + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); } - Printv(f->code,"{\n", - "C_word func;\n", - "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", - "if (C_swig_is_closurep(func))\n", - " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", - "else\n", - " C_kontinue(continuation, resultobj);\n", - "}\n", NIL); + Printv(f->code, "{\n", + "C_word func;\n", + "SWIG_Chicken_FindCreateProxy(func, resultobj)\n", + "if (C_swig_is_closurep(func))\n", + " ((C_proc4)(void *)C_block_item(func, 0))(4,func,continuation,resultobj,C_SCHEME_FALSE);\n", + "else\n", " C_kontinue(continuation, resultobj);\n", "}\n", NIL); /* Error handling code */ #ifdef USE_FAIL - Printf(f->code,"fail:\n"); - Printf(f->code,"swig_panic (\"failure in " - "'%s' SWIG wrapper\");\n", proc_name); + Printf(f->code, "fail:\n"); + Printf(f->code, "swig_panic (\"failure in " "'%s' SWIG wrapper\");\n", proc_name); #endif - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); Wrapper_print(f, f_wrappers); - + /* Now register the variable with the interpreter. */ addMethod(scmname, wname); if (!in_class || member_name) { String *clos_name; if (in_class) - clos_name = NewString(member_name); + clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *)""); - if (GetFlag(n,"feature:constasvar")) { - Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL); - Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL); + clos_name = chickenNameMapping(scmname, (char *) ""); + if (GetFlag(n, "feature:constasvar")) { + Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL); + Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL); } else { - Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL); + Printv(clos_methods, "(define ", clos_name, " ", chickenPrimitiveName(scmname), ")\n", NIL); } Delete(clos_name); } } else { - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, - "Unsupported variable type %s (ignored).\n", - SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported variable type %s (ignored).\n", SwigType_str(t, 0)); } Delete(wname); @@ -1042,62 +979,59 @@ CHICKEN::constantWrapper(Node *n) return SWIG_OK; } -int -CHICKEN::classHandler(Node *n) -{ +int CHICKEN::classHandler(Node *n) { /* Create new strings for building up a wrapper function */ have_constructor = 0; constructor_dispatch = 0; constructor_name = 0; - - c_class_name = NewString(Getattr(n,"sym:name")); + + c_class_name = NewString(Getattr(n, "sym:name")); class_name = NewString(""); short_class_name = NewString(""); Printv(class_name, "<", c_class_name, ">", NIL); Printv(short_class_name, c_class_name, NIL); Replaceall(class_name, "_", "-"); Replaceall(short_class_name, "_", "-"); - - if (!addSymbol(class_name,n)) return SWIG_ERROR; + + if (!addSymbol(class_name, n)) + return SWIG_ERROR; /* Handle inheritance */ String *base_class = NewString(""); - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator base = First(baselist); while (base.item) { if (!Getattr(base.item, "feature:ignore")) - Printv(base_class, "<", Getattr(base.item, "sym:name"), "> ", NIL); + Printv(base_class, "<", Getattr(base.item, "sym:name"), "> ", NIL); base = Next(base); } } - Replaceall(base_class, "_", "-"); + Replaceall(base_class, "_", "-"); - String *scmmod = NewString(module); - Replaceall(scmmod, "_", "-"); + String *scmmod = NewString(module); + Replaceall(scmmod, "_", "-"); - Printv(clos_class_defines,"(define ", class_name, "\n", - " (make 'name \"", short_class_name, "\"\n", NIL); - Delete(scmmod); + Printv(clos_class_defines, "(define ", class_name, "\n", " (make 'name \"", short_class_name, "\"\n", NIL); + Delete(scmmod); - if (Len(base_class)) { - Printv(clos_class_defines," 'direct-supers (list ", base_class, ")\n", NIL); - } else { - Printv(clos_class_defines," 'direct-supers (list )\n", NIL); - } + if (Len(base_class)) { + Printv(clos_class_defines, " 'direct-supers (list ", base_class, ")\n", NIL); + } else { + Printv(clos_class_defines, " 'direct-supers (list )\n", NIL); + } - Printf(clos_class_defines, " 'direct-slots (list 'swig-this\n"); + Printf(clos_class_defines, " 'direct-slots (list 'swig-this\n"); - String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name")); + String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name")); - SwigType *ct = NewStringf("p.%s", Getattr(n, "name")); - swigtype_ptr = SwigType_manglestr(ct); + SwigType *ct = NewStringf("p.%s", Getattr(n, "name")); + swigtype_ptr = SwigType_manglestr(ct); - Printf(f_runtime, "static swig_chicken_clientdata _swig_chicken_clientdata%s = { 0 };\n", - mangled_classname); - Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr,", (void *) &_swig_chicken_clientdata", mangled_classname, ");\n", NIL); - SwigType_remember(ct); + Printf(f_runtime, "static swig_chicken_clientdata _swig_chicken_clientdata%s = { 0 };\n", mangled_classname); + Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_chicken_clientdata", mangled_classname, ");\n", NIL); + SwigType_remember(ct); /* Emit all of the members */ @@ -1108,62 +1042,56 @@ CHICKEN::classHandler(Node *n) Printf(clos_class_defines, ")))\n\n"); if (have_constructor) { - Printv(clos_methods, "(define-method (initialize (obj ", class_name, ") initargs)\n", - " (swig-initialize obj initargs ", NIL); - if (constructor_arg_types) { - String *initfunc_name = NewStringf("%s@@SWIG@initmethod", class_name); - String *func_call = buildClosFunctionCall(constructor_arg_types, initfunc_name, chickenPrimitiveName(constructor_name)); - Printf(clos_methods, "%s)\n)\n", initfunc_name); - Printf(clos_methods, "(declare (hide %s))\n", initfunc_name); - Printf(clos_methods, "%s\n", func_call); - Delete(func_call); - Delete(initfunc_name); - Delete(constructor_arg_types); - constructor_arg_types = 0; - } else if (constructor_dispatch) { - Printf(clos_methods, "%s)\n)\n", constructor_dispatch); - Delete(constructor_dispatch); - constructor_dispatch = 0; - } else { - Printf(clos_methods, "%s)\n)\n", chickenPrimitiveName(constructor_name)); - } - Delete(constructor_name); - constructor_name = 0; + Printv(clos_methods, "(define-method (initialize (obj ", class_name, ") initargs)\n", " (swig-initialize obj initargs ", NIL); + if (constructor_arg_types) { + String *initfunc_name = NewStringf("%s@@SWIG@initmethod", class_name); + String *func_call = buildClosFunctionCall(constructor_arg_types, initfunc_name, chickenPrimitiveName(constructor_name)); + Printf(clos_methods, "%s)\n)\n", initfunc_name); + Printf(clos_methods, "(declare (hide %s))\n", initfunc_name); + Printf(clos_methods, "%s\n", func_call); + Delete(func_call); + Delete(initfunc_name); + Delete(constructor_arg_types); + constructor_arg_types = 0; + } else if (constructor_dispatch) { + Printf(clos_methods, "%s)\n)\n", constructor_dispatch); + Delete(constructor_dispatch); + constructor_dispatch = 0; + } else { + Printf(clos_methods, "%s)\n)\n", chickenPrimitiveName(constructor_name)); + } + Delete(constructor_name); + constructor_name = 0; } else { - Printv(clos_methods, "(define-method (initialize (obj ", class_name, ") initargs)\n", - " (swig-initialize obj initargs (lambda x #f)))\n", - NIL); + Printv(clos_methods, "(define-method (initialize (obj ", class_name, ") initargs)\n", " (swig-initialize obj initargs (lambda x #f)))\n", NIL); } /* export class initialization function */ if (clos) { - String *funcname = NewString(mangled_classname); - Printf(funcname, "_swig_chicken_setclosclass"); - String *closfuncname = NewString(funcname); - Replaceall(closfuncname, "_", "-"); + String *funcname = NewString(mangled_classname); + Printf(funcname, "_swig_chicken_setclosclass"); + String *closfuncname = NewString(funcname); + Replaceall(closfuncname, "_", "-"); - Printv(f_wrappers, "static void ", funcname, "(C_word,C_word,C_word,C_word) C_noret;\n", - "static void ", funcname, "(C_word argc, C_word closure, C_word continuation, C_word cl) {\n", - " C_trace(\"", funcname, "\");\n", - " if (argc!=3) C_bad_argc(argc,3);\n", - " swig_chicken_clientdata *cdata = (swig_chicken_clientdata *) SWIGTYPE", swigtype_ptr,"->clientdata;\n", - " cdata->gc_proxy_create = CHICKEN_new_gc_root();\n", - " CHICKEN_gc_root_set(cdata->gc_proxy_create, cl);\n", - " C_kontinue(continuation, C_SCHEME_UNDEFINED);\n", - "}\n", NIL); - addMethod(closfuncname, funcname); + Printv(f_wrappers, "static void ", funcname, "(C_word,C_word,C_word,C_word) C_noret;\n", + "static void ", funcname, "(C_word argc, C_word closure, C_word continuation, C_word cl) {\n", + " C_trace(\"", funcname, "\");\n", + " if (argc!=3) C_bad_argc(argc,3);\n", + " swig_chicken_clientdata *cdata = (swig_chicken_clientdata *) SWIGTYPE", swigtype_ptr, "->clientdata;\n", + " cdata->gc_proxy_create = CHICKEN_new_gc_root();\n", + " CHICKEN_gc_root_set(cdata->gc_proxy_create, cl);\n", " C_kontinue(continuation, C_SCHEME_UNDEFINED);\n", "}\n", NIL); + addMethod(closfuncname, funcname); - Printv(clos_methods, "(", chickenPrimitiveName(closfuncname), " (lambda (x lst) (if lst ", - "(cons (make ", class_name, " 'swig-this x) lst) ", - "(make ", class_name, " 'swig-this x))))\n\n", NIL); - Delete(closfuncname); - Delete(funcname); + Printv(clos_methods, "(", chickenPrimitiveName(closfuncname), " (lambda (x lst) (if lst ", + "(cons (make ", class_name, " 'swig-this x) lst) ", "(make ", class_name, " 'swig-this x))))\n\n", NIL); + Delete(closfuncname); + Delete(funcname); } Delete(mangled_classname); Delete(swigtype_ptr); swigtype_ptr = 0; - + Delete(class_name); Delete(short_class_name); Delete(c_class_name); @@ -1174,48 +1102,42 @@ CHICKEN::classHandler(Node *n) return SWIG_OK; } -int -CHICKEN::memberfunctionHandler(Node *n) -{ - String *iname = Getattr(n, "sym:name"); - String *proc = NewString(iname); - Replaceall(proc, "_", "-"); +int CHICKEN::memberfunctionHandler(Node *n) { + String *iname = Getattr(n, "sym:name"); + String *proc = NewString(iname); + Replaceall(proc, "_", "-"); - member_name = chickenNameMapping(proc, short_class_name); - Language::memberfunctionHandler(n); - Delete(member_name); - member_name = NULL; - Delete(proc); + member_name = chickenNameMapping(proc, short_class_name); + Language::memberfunctionHandler(n); + Delete(member_name); + member_name = NULL; + Delete(proc); - return SWIG_OK; + return SWIG_OK; } -int -CHICKEN::staticmemberfunctionHandler(Node *n) -{ - String *iname = Getattr(n, "sym:name"); - String *proc = NewString(iname); - Replaceall(proc, "_", "-"); +int CHICKEN::staticmemberfunctionHandler(Node *n) { + String *iname = Getattr(n, "sym:name"); + String *proc = NewString(iname); + Replaceall(proc, "_", "-"); - member_name = NewStringf("%s-%s", short_class_name, proc); - Language::staticmemberfunctionHandler(n); - Delete(member_name); - member_name = NULL; - Delete(proc); + member_name = NewStringf("%s-%s", short_class_name, proc); + Language::staticmemberfunctionHandler(n); + Delete(member_name); + member_name = NULL; + Delete(proc); - return SWIG_OK; + return SWIG_OK; } -int -CHICKEN::membervariableHandler(Node *n) -{ - String *iname = Getattr(n,"sym:name"); +int CHICKEN::membervariableHandler(Node *n) { + String *iname = Getattr(n, "sym:name"); //String *pb = SwigType_typedef_resolve_all(SwigType_base(Getattr(n, "type"))); Language::membervariableHandler(n); String *proc = NewString(iname); - Replaceall(proc,"_","-"); + Replaceall(proc, "_", "-"); //Node *class_node = Swig_symbol_clookup(pb, Getattr(n, "sym:symtab")); Node *class_node = classLookup(Getattr(n, "type")); @@ -1223,45 +1145,41 @@ CHICKEN::membervariableHandler(Node *n) //String *getfunc = NewStringf("%s-%s-get", short_class_name, proc); //String *setfunc = NewStringf("%s-%s-set", short_class_name, proc); String *getfunc = Swig_name_get(Swig_name_member(c_class_name, iname)); - Replaceall(getfunc, "_","-"); + Replaceall(getfunc, "_", "-"); String *setfunc = Swig_name_set(Swig_name_member(c_class_name, iname)); - Replaceall(setfunc, "_","-"); + Replaceall(setfunc, "_", "-"); - Printv(clos_class_defines," (list '", proc, " ':swig-virtual ':swig-get ", chickenPrimitiveName(getfunc), NIL); + Printv(clos_class_defines, " (list '", proc, " ':swig-virtual ':swig-get ", chickenPrimitiveName(getfunc), NIL); - if (!GetFlag(n,"feature:immutable")) { - if (class_node) { - Printv(clos_class_defines, " ':swig-set (lambda (x y) (", chickenPrimitiveName(setfunc), " x (slot-ref y 'swig-this))))\n", NIL); - } else { - Printv(clos_class_defines, " ':swig-set ", chickenPrimitiveName(setfunc), ")\n", NIL); - } + if (!GetFlag(n, "feature:immutable")) { + if (class_node) { + Printv(clos_class_defines, " ':swig-set (lambda (x y) (", chickenPrimitiveName(setfunc), " x (slot-ref y 'swig-this))))\n", NIL); + } else { + Printv(clos_class_defines, " ':swig-set ", chickenPrimitiveName(setfunc), ")\n", NIL); + } } else { - Printf(clos_class_defines, ")\n"); + Printf(clos_class_defines, ")\n"); } Delete(proc); return SWIG_OK; } -int -CHICKEN::staticmembervariableHandler(Node *n) -{ - String *iname = Getattr(n, "sym:name"); - String *proc = NewString(iname); - Replaceall(proc, "_", "-"); +int CHICKEN::staticmembervariableHandler(Node *n) { + String *iname = Getattr(n, "sym:name"); + String *proc = NewString(iname); + Replaceall(proc, "_", "-"); - member_name = NewStringf("%s-%s", short_class_name, proc); - Language::staticmembervariableHandler(n); - Delete(member_name); - member_name = NULL; - Delete(proc); + member_name = NewStringf("%s-%s", short_class_name, proc); + Language::staticmembervariableHandler(n); + Delete(member_name); + member_name = NULL; + Delete(proc); - return SWIG_OK; + return SWIG_OK; } -int -CHICKEN::constructorHandler(Node *n) -{ +int CHICKEN::constructorHandler(Node *n) { have_constructor = 1; has_constructor_args = 0; @@ -1272,7 +1190,7 @@ CHICKEN::constructorHandler(Node *n) has_constructor_args = 1; - String *iname = Getattr(n,"sym:name"); + String *iname = Getattr(n, "sym:name"); constructor_name = Swig_name_construct(iname); Replaceall(constructor_name, "_", "-"); return SWIG_OK; @@ -1298,17 +1216,17 @@ int CHICKEN::destructorHandler(Node *n) { int CHICKEN::importDirective(Node *n) { String *modname = Getattr(n, "module"); if (modname && clos_uses) { - + // Find the module node for this imported module. It should be the // first child but search just in case. - Node* mod = firstChild(n); + Node *mod = firstChild(n); while (mod && Strcmp(nodeType(mod), "module") != 0) mod = nextSibling(mod); if (mod) { String *name = Getattr(mod, "name"); if (name) { - Printf(closprefix, "(declare (uses %s))\n", name); + Printf(closprefix, "(declare (uses %s))\n", name); } } } @@ -1331,7 +1249,8 @@ String *CHICKEN::buildClosFunctionCall(List *types, String_or_char *closname, St } else { Printf(method_signature, " (arg%i %s)", arg_count, arg_type.item); arg_type = Next(arg_type); - if (!arg_type.item) break; + if (!arg_type.item) + break; String *arg = NewStringf("arg%i", arg_count); String *access_arg = Copy(arg_type.item); @@ -1346,11 +1265,9 @@ String *CHICKEN::buildClosFunctionCall(List *types, String_or_char *closname, St } if (optional_arguments) { - Printf(func_call, "(define-method (%s %s . args) (apply %s %s args))", - closname, method_signature, funcname, func_args); + Printf(func_call, "(define-method (%s %s . args) (apply %s %s args))", closname, method_signature, funcname, func_args); } else { - Printf(func_call, "(define-method (%s %s) (%s %s))", - closname, method_signature, funcname, func_args); + Printf(func_call, "(define-method (%s %s) (%s %s))", closname, method_signature, funcname, func_args); } Delete(method_signature); @@ -1371,12 +1288,11 @@ extern "C" { while (ia.item && ib.item) { int ret = Strcmp(ia.item, ib.item); - if (ret) return ret; + if (ret) + return ret; ia = Next(Next(ia)); ib = Next(Next(ib)); - } - - if (opt_equal && ia.item && Strcmp(ia.item, "^^##optional$$") == 0) + } if (opt_equal && ia.item && Strcmp(ia.item, "^^##optional$$") == 0) return 0; if (ia.item) return -1; @@ -1393,76 +1309,59 @@ extern "C" { } } -void -CHICKEN::dispatchFunction(Node *n) -{ +void CHICKEN::dispatchFunction(Node *n) { /* Last node in overloaded chain */ int maxargs; String *tmp = NewString(""); - String *dispatch = - Swig_overload_dispatch(n,"%s (2+$numargs,closure," - "continuation$commaargs);", &maxargs); - + String *dispatch = Swig_overload_dispatch(n, "%s (2+$numargs,closure," "continuation$commaargs);", &maxargs); + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *f = NewWrapper(); - String *iname = Getattr(n,"sym:name"); - String *wname = NewString(""); - String *scmname = NewString(iname); + Wrapper *f = NewWrapper(); + String *iname = Getattr(n, "sym:name"); + String *wname = NewString(""); + String *scmname = NewString(iname); Replaceall(scmname, "_", "-"); Append(wname, Swig_name_wrapper(iname)); - Printv(f->def, "static void real_", wname, - "(C_word, C_word, C_word, C_word) C_noret;\n", NIL); + Printv(f->def, "static void real_", wname, "(C_word, C_word, C_word, C_word) C_noret;\n", NIL); - Printv(f->def, - "static void real_", - wname, - "(C_word oldargc, C_word closure, C_word continuation, C_word args) {", - NIL); - - Wrapper_add_local(f,"argc","int argc"); - Printf(tmp,"C_word argv[%d]", maxargs+1); - Wrapper_add_local(f,"argv",tmp); - Wrapper_add_local(f,"ii","int ii"); - Wrapper_add_local(f,"t","C_word t = args"); - Printf(f->code,"if (!C_swig_is_list (args)) {\n"); - Printf(f->code," swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, " - "\"Argument #1 must be a list of overloaded arguments\");\n"); - Printf(f->code,"}\n"); - Printf(f->code,"argc = C_unfix (C_i_length (args));\n"); - Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++, t = C_block_item (t, 1)) {\n",maxargs); - Printf(f->code,"argv[ii] = C_block_item (t, 0);\n"); - Printf(f->code,"}\n"); - - Printv(f->code,dispatch,"\n",NIL); - Printf(f->code,"swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE," - "\"No matching function for overloaded '%s'\");\n", iname); - Printv(f->code,"}\n",NIL); - Wrapper_print(f,f_wrappers); + Printv(f->def, "static void real_", wname, "(C_word oldargc, C_word closure, C_word continuation, C_word args) {", NIL); + + Wrapper_add_local(f, "argc", "int argc"); + Printf(tmp, "C_word argv[%d]", maxargs + 1); + Wrapper_add_local(f, "argv", tmp); + Wrapper_add_local(f, "ii", "int ii"); + Wrapper_add_local(f, "t", "C_word t = args"); + Printf(f->code, "if (!C_swig_is_list (args)) {\n"); + Printf(f->code, " swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, " "\"Argument #1 must be a list of overloaded arguments\");\n"); + Printf(f->code, "}\n"); + Printf(f->code, "argc = C_unfix (C_i_length (args));\n"); + Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++, t = C_block_item (t, 1)) {\n", maxargs); + Printf(f->code, "argv[ii] = C_block_item (t, 0);\n"); + Printf(f->code, "}\n"); + + Printv(f->code, dispatch, "\n", NIL); + Printf(f->code, "swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE," "\"No matching function for overloaded '%s'\");\n", iname); + Printv(f->code, "}\n", NIL); + Wrapper_print(f, f_wrappers); addMethod(scmname, wname); DelWrapper(f); f = NewWrapper(); /* varargs */ - Printv(f->def, "void ", wname, - "(C_word, C_word, C_word, ...) C_noret;\n", NIL); - Printv(f->def, "void ", wname, - "(C_word c, C_word t0, C_word t1, ...) {", - NIL); - Printv(f->code, - "C_word t2;\n", - "va_list v;\n", - "C_word *a, c2 = c;\n", - "C_save_rest (t1, c2, 2);\n", - "a = C_alloc((c-2)*3);\n", - "t2 = C_restore_rest (a, C_rest_count (0));\n", - "real_", wname, " (3, t0, t1, t2);\n", NIL); - Printv(f->code,"}\n",NIL); - Wrapper_print(f,f_wrappers); + Printv(f->def, "void ", wname, "(C_word, C_word, C_word, ...) C_noret;\n", NIL); + Printv(f->def, "void ", wname, "(C_word c, C_word t0, C_word t1, ...) {", NIL); + Printv(f->code, + "C_word t2;\n", + "va_list v;\n", + "C_word *a, c2 = c;\n", + "C_save_rest (t1, c2, 2);\n", "a = C_alloc((c-2)*3);\n", "t2 = C_restore_rest (a, C_rest_count (0));\n", "real_", wname, " (3, t0, t1, t2);\n", NIL); + Printv(f->code, "}\n", NIL); + Wrapper_print(f, f_wrappers); /* Now deal with overloaded function when exporting clos */ if (clos) { @@ -1475,16 +1374,16 @@ CHICKEN::dispatchFunction(Node *n) String *clos_name; int construct = 0; if (have_constructor && !has_constructor_args) { - has_constructor_args = 1; - constructor_dispatch = NewStringf("%s@SWIG@new@dispatch", short_class_name); - clos_name = Copy(constructor_dispatch); - construct = 1; - Printf(clos_methods, "(declare (hide %s))\n", clos_name); + has_constructor_args = 1; + constructor_dispatch = NewStringf("%s@SWIG@new@dispatch", short_class_name); + clos_name = Copy(constructor_dispatch); + construct = 1; + Printf(clos_methods, "(declare (hide %s))\n", clos_name); } else if (in_class) - clos_name = NewString(member_name); + clos_name = NewString(member_name); else - clos_name = chickenNameMapping(scmname, (char *)""); - + clos_name = chickenNameMapping(scmname, (char *) ""); + Iterator f; List *prev = 0; int all_primitive = 1; @@ -1492,76 +1391,65 @@ CHICKEN::dispatchFunction(Node *n) /* first check for duplicates and an empty call */ String *newlist = NewList(); for (f = First(flist); f.item; f = Next(f)) { - /* check if cur is a duplicate of prev */ - if (prev && compareTypeListsHelper(f.item, prev, 1) == 0) { - Delete(f.item); - } else { - Append(newlist, f.item); - prev = f.item; - Iterator j; - for (j = First(f.item); j.item; j = Next(j)) { - if (Strcmp(j.item, "^^##optional$$") != 0 && Strcmp(j.item, "") != 0) - all_primitive = 0; - } - } + /* check if cur is a duplicate of prev */ + if (prev && compareTypeListsHelper(f.item, prev, 1) == 0) { + Delete(f.item); + } else { + Append(newlist, f.item); + prev = f.item; + Iterator j; + for (j = First(f.item); j.item; j = Next(j)) { + if (Strcmp(j.item, "^^##optional$$") != 0 && Strcmp(j.item, "") != 0) + all_primitive = 0; + } + } } Delete(flist); flist = newlist; - + if (all_primitive) { - Printf(clos_methods, "(define %s %s)\n", clos_name, chickenPrimitiveName(scmname)); + Printf(clos_methods, "(define %s %s)\n", clos_name, chickenPrimitiveName(scmname)); } else { - for (f = First(flist); f.item; f = Next(f)) { - /* now export clos code for argument */ - String *func_call = buildClosFunctionCall(f.item, clos_name, chickenPrimitiveName(scmname)); - Printf(clos_methods, "%s\n", func_call); - Delete(f.item); - Delete(func_call); - } + for (f = First(flist); f.item; f = Next(f)) { + /* now export clos code for argument */ + String *func_call = buildClosFunctionCall(f.item, clos_name, chickenPrimitiveName(scmname)); + Printf(clos_methods, "%s\n", func_call); + Delete(f.item); + Delete(func_call); + } } Delete(clos_name); Delete(flist); } } - + DelWrapper(f); Delete(dispatch); Delete(tmp); Delete(wname); } -int -CHICKEN::isPointer(SwigType *t) -{ +int CHICKEN::isPointer(SwigType *t) { return SwigType_ispointer(SwigType_typedef_resolve_all(t)); } -void -CHICKEN::addMethod(String *scheme_name, String *function) -{ +void CHICKEN::addMethod(String *scheme_name, String *function) { String *sym = NewString(""); if (clos) { - Append(sym, "primitive:"); + Append(sym, "primitive:"); } Append(sym, scheme_name); /* add symbol to Chicken internal symbol table */ if (hide_primitive) { Printv(f_init, "{\n", - " C_word *p0 = a;\n", - " *(a++)=C_CLOSURE_TYPE|1;\n", - " *(a++)=(C_word)", function, ";\n", - " C_mutate(return_vec++, (C_word)p0);\n", - "}\n", NIL); + " C_word *p0 = a;\n", " *(a++)=C_CLOSURE_TYPE|1;\n", " *(a++)=(C_word)", function, ";\n", " C_mutate(return_vec++, (C_word)p0);\n", "}\n", NIL); } else { - Printf(f_sym_size, "+C_SIZEOF_INTERNED_SYMBOL(%d)", Len(sym)); - Printf(f_init, "sym = C_intern (&a, %d, \"%s\");\n", - Len(sym), sym); - Printv(f_init, - "C_mutate ((C_word*)sym+1, (*a=C_CLOSURE_TYPE|1, a[1]=(C_word)", - function, ", tmp=(C_word)a, a+=2, tmp));\n", NIL); - } + Printf(f_sym_size, "+C_SIZEOF_INTERNED_SYMBOL(%d)", Len(sym)); + Printf(f_init, "sym = C_intern (&a, %d, \"%s\");\n", Len(sym), sym); + Printv(f_init, "C_mutate ((C_word*)sym+1, (*a=C_CLOSURE_TYPE|1, a[1]=(C_word)", function, ", tmp=(C_word)a, a+=2, tmp));\n", NIL); + } if (hide_primitive) { Setattr(primitive_names, scheme_name, NewStringf("(vector-ref swig-init-return %i)", num_methods)); @@ -1574,8 +1462,7 @@ CHICKEN::addMethod(String *scheme_name, String *function) Delete(sym); } -String * -CHICKEN::chickenPrimitiveName(String *name) { +String *CHICKEN::chickenPrimitiveName(String *name) { String *value = Getattr(primitive_names, name); if (value) return value; @@ -1584,31 +1471,31 @@ CHICKEN::chickenPrimitiveName(String *name) { return NewString("#f"); } } - -int -CHICKEN::validIdentifier(String *s) -{ + +int CHICKEN::validIdentifier(String *s) { char *c = Char(s); - /* Check whether we have an R5RS identifier.*/ + /* Check whether we have an R5RS identifier. */ /* --> * | */ /* --> | */ if (!(isalpha(*c) || (*c == '!') || (*c == '$') || (*c == '%') - || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') - || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') - || (*c == '^') || (*c == '_') || (*c == '~'))) { + || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') + || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') + || (*c == '^') || (*c == '_') || (*c == '~'))) { /* --> + | - | ... */ if ((strcmp(c, "+") == 0) - || strcmp(c, "-") == 0 - || strcmp(c, "...") == 0) return 1; - else return 0; + || strcmp(c, "-") == 0 || strcmp(c, "...") == 0) + return 1; + else + return 0; } /* --> | | */ while (*c) { if (!(isalnum(*c) || (*c == '!') || (*c == '$') || (*c == '%') - || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') - || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') - || (*c == '^') || (*c == '_') || (*c == '~') || (*c == '+') - || (*c == '-') || (*c == '.') || (*c == '@'))) return 0; + || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') + || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') + || (*c == '^') || (*c == '_') || (*c == '~') || (*c == '+') + || (*c == '-') || (*c == '.') || (*c == '@'))) + return 0; c++; } return 1; @@ -1621,39 +1508,39 @@ CHICKEN::validIdentifier(String *s) * If class_name = "" that means the mapping is for a function or * variable not attached to any class. * ------------------------------------------------------------ */ - String *CHICKEN::chickenNameMapping(String *name, String_or_char *class_name) { - String *n = NewString(""); - - if (Strcmp(class_name, "") == 0) { - // not part of a class, so no class name to prefix - if (clossymnameprefix) { - Printf(n, "%s%s", clossymnameprefix, name); - } else { - Printf(n, "%s", name); - } +String *CHICKEN::chickenNameMapping(String *name, String_or_char *class_name) { + String *n = NewString(""); + + if (Strcmp(class_name, "") == 0) { + // not part of a class, so no class name to prefix + if (clossymnameprefix) { + Printf(n, "%s%s", clossymnameprefix, name); } else { - if (useclassprefix) { - Printf(n, "%s-%s", class_name, name); + Printf(n, "%s", name); + } + } else { + if (useclassprefix) { + Printf(n, "%s-%s", class_name, name); + } else { + if (clossymnameprefix) { + Printf(n, "%s%s", clossymnameprefix, name); } else { - if (clossymnameprefix) { - Printf(n, "%s%s", clossymnameprefix, name); - } else { - Printf(n, "%s", name); - } + Printf(n, "%s", name); } } - return n; } + return n; +} - String *CHICKEN::runtimeCode() { - String *s = Swig_include_sys("chickenrun.swg"); - if (!s) { - Printf(stderr, "*** Unable to open 'chickenrun.swg'\n"); - s = NewString(""); - } - return s; +String *CHICKEN::runtimeCode() { + String *s = Swig_include_sys("chickenrun.swg"); + if (!s) { + Printf(stderr, "*** Unable to open 'chickenrun.swg'\n"); + s = NewString(""); } + return s; +} - String *CHICKEN::defaultExternalRuntimeFilename() { - return NewString("swigchickenrun.h"); - } +String *CHICKEN::defaultExternalRuntimeFilename() { + return NewString("swigchickenrun.h"); +} diff --git a/SWIG/Source/Modules/clisp.cxx b/SWIG/Source/Modules/clisp.cxx index 49f555aaf..0a34c46e4 100644 --- a/SWIG/Source/Modules/clisp.cxx +++ b/SWIG/Source/Modules/clisp.cxx @@ -11,343 +11,335 @@ char cvsroot_clisp_cxx[] = "$Header$"; #include "swigmod.h" -class CLISP : public Language { +class CLISP:public Language { public: File *f_cl; String *module; virtual void main(int argc, char *argv[]); virtual int top(Node *n); virtual int functionWrapper(Node *n); - virtual int variableWrapper(Node *n); + virtual int variableWrapper(Node *n); virtual int constantWrapper(Node *n); virtual int classDeclaration(Node *n); virtual int enumDeclaration(Node *n); virtual int typedefHandler(Node *n); List *entries; private: - String* get_ffi_type(SwigType *ty); - String* convert_literal(String *num_param, String *type); - String* strip_parens(String *string); + String *get_ffi_type(SwigType *ty); + String *convert_literal(String *num_param, String *type); + String *strip_parens(String *string); int extern_all_flag; int generate_typedef_flag; int is_function; }; -void CLISP :: main(int argc, char *argv[]) { +void CLISP::main(int argc, char *argv[]) { int i; - SWIG_library_directory("clisp"); + SWIG_library_directory("clisp"); SWIG_config_file("clisp.swg"); generate_typedef_flag = 0; - extern_all_flag=0; - - for(i=1; i 0) { - Printf(header,"\n (:export"); + long len = Len(entries); + if (len > 0) { + Printf(header, "\n (:export"); } //else nothing to export - - for (i = First(entries); i.item; i = Next(i)) { - Printf(header,"\n\t:%s", i.item); - } - - if(len > 0) { - Printf(header,")"); - } - - Printf(header, ")\n"); - Printf(header,"\n(in-package :%s)\n",module); - Printf(header,"\n(default-foreign-language :stdc)\n"); - - len= Tell(f_cl); - Printf(f_cl,"%s",header); + for (i = First(entries); i.item; i = Next(i)) { + Printf(header, "\n\t:%s", i.item); + } + + if (len > 0) { + Printf(header, ")"); + } + + Printf(header, ")\n"); + Printf(header, "\n(in-package :%s)\n", module); + Printf(header, "\n(default-foreign-language :stdc)\n"); + + len = Tell(f_cl); + + Printf(f_cl, "%s", header); long end = Tell(f_cl); - for(len--;len >=0 ; len --) { + for (len--; len >= 0; len--) { end--; - Seek(f_cl,len,SEEK_SET); - int ch=Getc(f_cl); - Seek(f_cl,end,SEEK_SET); - Putc(ch,f_cl); + Seek(f_cl, len, SEEK_SET); + int ch = Getc(f_cl); + Seek(f_cl, end, SEEK_SET); + Putc(ch, f_cl); } - - Seek(f_cl,0,SEEK_SET); - Write(f_cl,Char(header), Len(header)); + + Seek(f_cl, 0, SEEK_SET); + Write(f_cl, Char(header), Len(header)); Close(f_cl); - Delete(f_cl); // Deletes the handle, not the file + Delete(f_cl); // Deletes the handle, not the file return SWIG_OK; } -int CLISP :: functionWrapper(Node *n) { - is_function=1; - String *storage=Getattr(n,"storage"); - if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) +int CLISP::functionWrapper(Node *n) { + is_function = 1; + String *storage = Getattr(n, "storage"); + if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc")))) return SWIG_OK; - - String *func_name=Getattr(n, "sym:name"); - ParmList *pl=Getattr(n, "parms"); + String *func_name = Getattr(n, "sym:name"); - int argnum=0, first=1; + ParmList *pl = Getattr(n, "parms"); - Printf(f_cl, "\n(ffi:def-call-out %s\n\t(:name \"%s\")\n", func_name,func_name); - - Append(entries,func_name); + int argnum = 0, first = 1; + + Printf(f_cl, "\n(ffi:def-call-out %s\n\t(:name \"%s\")\n", func_name, func_name); + + Append(entries, func_name); if (ParmList_len(pl) != 0) { Printf(f_cl, "\t(:arguments "); } - for (Parm *p=pl; p; p=nextSibling(p), argnum++) { + for (Parm *p = pl; p; p = nextSibling(p), argnum++) { - String *argname=Getattr(p, "name"); + String *argname = Getattr(p, "name"); // SwigType *argtype; - - String *ffitype=get_ffi_type(Getattr(p, "type")); - - int tempargname=0; - + + String *ffitype = get_ffi_type(Getattr(p, "type")); + + int tempargname = 0; + if (!argname) { - argname=NewStringf("arg%d", argnum); - tempargname=1; + argname = NewStringf("arg%d", argnum); + tempargname = 1; } - + if (!first) { Printf(f_cl, "\n\t\t"); } Printf(f_cl, "(%s %s)", argname, ffitype); - first=0; - + first = 0; + Delete(ffitype); - if (tempargname) + if (tempargname) Delete(argname); } if (ParmList_len(pl) != 0) { - Printf(f_cl, ")\n"); /* finish arg list */ + Printf(f_cl, ")\n"); /* finish arg list */ } - String *ffitype=get_ffi_type(Getattr(n, "type")); - if(Strcmp(ffitype,"NIL")) { //when return type is not nil + String *ffitype = get_ffi_type(Getattr(n, "type")); + if (Strcmp(ffitype, "NIL")) { //when return type is not nil Printf(f_cl, "\t(:return-type %s)\n", ffitype); } Printf(f_cl, "\t(:library +library-name+))\n"); - + return SWIG_OK; } -int CLISP :: constantWrapper(Node *n) { - is_function=0; - String *type=Getattr(n, "type"); - String *converted_value=convert_literal(Getattr(n, "value"), type); - String *name=Getattr(n, "sym:name"); +int CLISP::constantWrapper(Node *n) { + is_function = 0; + String *type = Getattr(n, "type"); + String *converted_value = convert_literal(Getattr(n, "value"), type); + String *name = Getattr(n, "sym:name"); Printf(f_cl, "\n(defconstant %s %s)\n", name, converted_value); - Append(entries,name); + Append(entries, name); Delete(converted_value); - + return SWIG_OK; } -int CLISP :: variableWrapper(Node *n) { - is_function=0; +int CLISP::variableWrapper(Node *n) { + is_function = 0; // SwigType *type=; - String *storage=Getattr(n,"storage"); - - if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) + String *storage = Getattr(n, "storage"); + + if (!extern_all_flag && (!storage || (Strcmp(storage, "extern") && Strcmp(storage, "externc")))) return SWIG_OK; - String *var_name=Getattr(n, "sym:name"); - String *lisp_type=get_ffi_type(Getattr(n, "type")); - Printf(f_cl,"\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n",var_name,var_name,lisp_type); + String *var_name = Getattr(n, "sym:name"); + String *lisp_type = get_ffi_type(Getattr(n, "type")); + Printf(f_cl, "\n(ffi:def-c-var %s\n (:name \"%s\")\n (:type %s)\n", var_name, var_name, lisp_type); Printf(f_cl, "\t(:library +library-name+))\n"); - Append(entries,var_name); + Append(entries, var_name); Delete(lisp_type); return SWIG_OK; } -int CLISP :: typedefHandler(Node *n) { - if(generate_typedef_flag) { - is_function=0; - Printf(f_cl,"\n(ffi:def-c-type %s %s)\n",Getattr(n,"name"),get_ffi_type(Getattr(n,"type"))); +int CLISP::typedefHandler(Node *n) { + if (generate_typedef_flag) { + is_function = 0; + Printf(f_cl, "\n(ffi:def-c-type %s %s)\n", Getattr(n, "name"), get_ffi_type(Getattr(n, "type"))); } - + return Language::typedefHandler(n); } -int CLISP :: enumDeclaration(Node *n) { - is_function=0; - String *name=Getattr(n, "sym:name"); - - Printf(f_cl,"\n(ffi:def-c-enum %s ",name); +int CLISP::enumDeclaration(Node *n) { + is_function = 0; + String *name = Getattr(n, "sym:name"); - for (Node *c=firstChild(n); c; c=nextSibling(c)) { + Printf(f_cl, "\n(ffi:def-c-enum %s ", name); + + for (Node *c = firstChild(n); c; c = nextSibling(c)) { String *slot_name = Getattr(c, "name"); String *value = Getattr(c, "enumvalue"); - - Printf(f_cl,"(%s %s)",slot_name,value); - Append(entries,slot_name); - + Printf(f_cl, "(%s %s)", slot_name, value); + + Append(entries, slot_name); + Delete(value); } - + Printf(f_cl, ")\n"); return SWIG_OK; } // Includes structs -int CLISP :: classDeclaration(Node *n) { - is_function=0; - String *name=Getattr(n, "sym:name"); - String *kind = Getattr(n,"kind"); - +int CLISP::classDeclaration(Node *n) { + is_function = 0; + String *name = Getattr(n, "sym:name"); + String *kind = Getattr(n, "kind"); + if (Strcmp(kind, "struct")) { - Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", - kind); + Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind); Printf(stderr, " (name: %s)\n", name); SWIG_exit(EXIT_FAILURE); } - - Printf(f_cl,"\n(ffi:def-c-struct %s",name); - Append(entries,NewStringf("make-%s",name)); - - for (Node *c=firstChild(n); c; c=nextSibling(c)) { + Printf(f_cl, "\n(ffi:def-c-struct %s", name); + + Append(entries, NewStringf("make-%s", name)); + + for (Node *c = firstChild(n); c; c = nextSibling(c)) { if (Strcmp(nodeType(c), "cdecl")) { - Printf(stderr, "Structure %s has a slot that we can't deal with.\n", - name); - Printf(stderr, "nodeType: %s, name: %s, type: %s\n", - nodeType(c), - Getattr(c, "name"), - Getattr(c, "type")); + Printf(stderr, "Structure %s has a slot that we can't deal with.\n", name); + Printf(stderr, "nodeType: %s, name: %s, type: %s\n", nodeType(c), Getattr(c, "name"), Getattr(c, "type")); SWIG_exit(EXIT_FAILURE); } - String *temp=Copy(Getattr(c,"decl")); - Append(temp,Getattr(c,"type")); //appending type to the end, otherwise wrong type - String *lisp_type=get_ffi_type(temp); + String *temp = Copy(Getattr(c, "decl")); + Append(temp, Getattr(c, "type")); //appending type to the end, otherwise wrong type + String *lisp_type = get_ffi_type(temp); Delete(temp); String *slot_name = Getattr(c, "sym:name"); - Printf(f_cl, - "\n\t(%s %s)", - slot_name, - lisp_type); + Printf(f_cl, "\n\t(%s %s)", slot_name, lisp_type); + + Append(entries, NewStringf("%s-%s", name, slot_name)); - Append(entries,NewStringf("%s-%s",name,slot_name)); - Delete(lisp_type); } - + Printf(f_cl, ")\n"); /* Add this structure to the known lisp types */ //Printf(stdout, "Adding %s foreign type\n", name); // add_defined_foreign_type(name); - + return SWIG_OK; } /* utilities */ /* returns new string w/ parens stripped */ -String* CLISP::strip_parens(String *string) { - char *s=Char(string), *p; - int len=Len(string); +String *CLISP::strip_parens(String *string) { + char *s = Char(string), *p; + int len = Len(string); String *res; - - if (len==0 || s[0] != '(' || s[len-1] != ')') { + + if (len == 0 || s[0] != '(' || s[len - 1] != ')') { return NewString(string); } - - p=(char *)malloc(len-2+1); + + p = (char *) malloc(len - 2 + 1); if (!p) { Printf(stderr, "Malloc failed\n"); SWIG_exit(EXIT_FAILURE); } - - strncpy(p, s+1, len-1); - p[len-2]=0; /* null terminate */ - - res=NewString(p); + + strncpy(p, s + 1, len - 1); + p[len - 2] = 0; /* null terminate */ + + res = NewString(p); free(p); - + return res; } -String* CLISP::convert_literal(String *num_param, String *type) { - String *num=strip_parens(num_param), *res; - char *s=Char(num); - +String *CLISP::convert_literal(String *num_param, String *type) { + String *num = strip_parens(num_param), *res; + char *s = Char(num); + /* Make sure doubles use 'd' instead of 'e' */ if (!Strcmp(type, "double")) { - String *updated=Copy(num); + String *updated = Copy(num); if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) { Printf(stderr, "Weird!! number %s looks invalid.\n", num); SWIG_exit(EXIT_FAILURE); @@ -359,154 +351,145 @@ String* CLISP::convert_literal(String *num_param, String *type) { if (SwigType_type(type) == T_CHAR) { /* Use CL syntax for character literals */ return NewStringf("#\\%s", num_param); - } - else if (SwigType_type(type) == T_STRING) { + } else if (SwigType_type(type) == T_STRING) { /* Use CL syntax for string literals */ return NewStringf("\"%s\"", num_param); } - + if (Len(num) < 2 || s[0] != '0') { return num; } - + /* octal or hex */ - - res=NewStringf("#%c%s", - s[1] == 'x' ? 'x' : 'o', - s+2); + + res = NewStringf("#%c%s", s[1] == 'x' ? 'x' : 'o', s + 2); Delete(num); return res; } -String* CLISP::get_ffi_type(SwigType *ty) { - Hash *typemap =Swig_typemap_search("in", ty,"", 0); +String *CLISP::get_ffi_type(SwigType *ty) { + Hash *typemap = Swig_typemap_search("in", ty, "", 0); if (typemap) { String *typespec = Getattr(typemap, "code"); return NewString(typespec); - } - else if(SwigType_ispointer(ty)) { + } else if (SwigType_ispointer(ty)) { SwigType *cp = Copy(ty); SwigType_del_pointer(cp); - String *inner_type=get_ffi_type(cp); + String *inner_type = get_ffi_type(cp); - if(SwigType_isfunction(cp)) { + if (SwigType_isfunction(cp)) { return inner_type; } - - SwigType *base=SwigType_base(ty); - String *base_name=SwigType_str(base,0); + + SwigType *base = SwigType_base(ty); + String *base_name = SwigType_str(base, 0); String *str; - if(!Strcmp(base_name,"int") || !Strcmp(base_name,"float") || !Strcmp(base_name,"short") - || !Strcmp(base_name,"double") || !Strcmp(base_name,"long") || !Strcmp(base_name,"char")) { - - str = NewStringf("(ffi:c-ptr %s)",inner_type); - } - else { - str = NewStringf("(ffi:c-pointer %s)",inner_type); + if (!Strcmp(base_name, "int") || !Strcmp(base_name, "float") || !Strcmp(base_name, "short") + || !Strcmp(base_name, "double") || !Strcmp(base_name, "long") || !Strcmp(base_name, "char")) { + + str = NewStringf("(ffi:c-ptr %s)", inner_type); + } else { + str = NewStringf("(ffi:c-pointer %s)", inner_type); } Delete(base_name); Delete(base); Delete(cp); Delete(inner_type); return str; - } - else if(SwigType_isarray(ty)) { + } else if (SwigType_isarray(ty)) { SwigType *cp = Copy(ty); - String *array_dim=SwigType_array_getdim(ty,0); + String *array_dim = SwigType_array_getdim(ty, 0); - if(!Strcmp(array_dim,"")) { //dimension less array convert to pointer + if (!Strcmp(array_dim, "")) { //dimension less array convert to pointer Delete(array_dim); SwigType_del_array(cp); SwigType_add_pointer(cp); - String *str =get_ffi_type(cp); + String *str = get_ffi_type(cp); Delete(cp); return str; - } - else { + } else { SwigType_pop_arrays(cp); String *inner_type = get_ffi_type(cp); Delete(cp); - - int ndim=SwigType_array_ndim(ty); + + int ndim = SwigType_array_ndim(ty); String *dimension; - if(ndim == 1) { - dimension=array_dim; - } - else { + if (ndim == 1) { dimension = array_dim; - for(int i=1;i // for INT_MAX +#include // for INT_MAX #include "cparse.h" #include /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -class CSHARP : public Language { +class CSHARP:public Language { static const char *usage; - const String *empty_string; - const String *public_string; - const String *protected_string; + const String *empty_string; + const String *public_string; + const String *protected_string; - Hash *swig_types_hash; - File *f_runtime; - File *f_runtime_h; - File *f_header; - File *f_wrappers; - File *f_init; - File *f_directors; - File *f_directors_h; - List *filenames_list; + Hash *swig_types_hash; + File *f_runtime; + File *f_runtime_h; + File *f_header; + File *f_wrappers; + File *f_init; + File *f_directors; + File *f_directors_h; + List *filenames_list; - bool proxy_flag; // Flag for generating proxy classes - bool native_function_flag; // Flag for when wrapping a native function - bool enum_constant_flag; // Flag for when wrapping an enum or constant - bool static_flag; // Flag for when wrapping a static functions or member variables - bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable - bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const - bool global_variable_flag; // Flag for when wrapping a global variable - bool old_variable_names; // Flag for old style variable names in the intermediary class - bool generate_property_declaration_flag; // Flag for generating properties + bool proxy_flag; // Flag for generating proxy classes + bool native_function_flag; // Flag for when wrapping a native function + bool enum_constant_flag; // Flag for when wrapping an enum or constant + bool static_flag; // Flag for when wrapping a static functions or member variables + bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable + bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const + bool global_variable_flag; // Flag for when wrapping a global variable + bool old_variable_names; // Flag for old style variable names in the intermediary class + bool generate_property_declaration_flag; // Flag for generating properties - String *imclass_name; // intermediary class name - String *module_class_name; // module class name - String *imclass_class_code; // intermediary class code + String *imclass_name; // intermediary class name + String *module_class_name; // module class name + String *imclass_class_code; // intermediary class code String *proxy_class_def; String *proxy_class_code; String *module_class_code; String *proxy_class_name; - String *variable_name; //Name of a variable being wrapped + String *variable_name; //Name of a variable being wrapped String *proxy_class_constants_code; String *module_class_constants_code; String *enum_code; - String *dllimport; // DllImport attribute name - String *namespce; // Optional namespace name - String *imclass_imports; //intermediary class imports from %pragma - String *module_imports; //module imports from %pragma - String *imclass_baseclass; //inheritance for intermediary class class from %pragma - String *module_baseclass; //inheritance for module class from %pragma - String *imclass_interfaces; //interfaces for intermediary class class from %pragma - String *module_interfaces; //interfaces for module class from %pragma - String *imclass_class_modifiers; //class modifiers for intermediary class overriden by %pragma - String *module_class_modifiers; //class modifiers for module class overriden by %pragma - String *upcasts_code; //C++ casts for inheritance hierarchies C++ code - String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code - String *director_callback_typedefs; // Director function pointer typedefs for callbacks - String *director_callbacks; // Director callback function pointer member variables - String *director_delegate_callback; // Director callback method that delegates are set to call - String *director_delegate_definitions; // Director delegates definitions in proxy class - String *director_delegate_instances; // Director delegates member variables in proxy class - String *director_method_types; // Director method types - String *director_connect_parms; // Director delegates parameter list for director connect call - String *destructor_call; //C++ destructor call if any + String *dllimport; // DllImport attribute name + String *namespce; // Optional namespace name + String *imclass_imports; //intermediary class imports from %pragma + String *module_imports; //module imports from %pragma + String *imclass_baseclass; //inheritance for intermediary class class from %pragma + String *module_baseclass; //inheritance for module class from %pragma + String *imclass_interfaces; //interfaces for intermediary class class from %pragma + String *module_interfaces; //interfaces for module class from %pragma + String *imclass_class_modifiers; //class modifiers for intermediary class overriden by %pragma + String *module_class_modifiers; //class modifiers for module class overriden by %pragma + String *upcasts_code; //C++ casts for inheritance hierarchies C++ code + String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code + String *director_callback_typedefs; // Director function pointer typedefs for callbacks + String *director_callbacks; // Director callback function pointer member variables + String *director_delegate_callback; // Director callback method that delegates are set to call + String *director_delegate_definitions; // Director delegates definitions in proxy class + String *director_delegate_instances; // Director delegates member variables in proxy class + String *director_method_types; // Director method types + String *director_connect_parms; // Director delegates parameter list for director connect call + String *destructor_call; //C++ destructor call if any // Director method stuff: - List *dmethods_seq; - Hash *dmethods_table; - int n_dmethods; - int n_directors; - int first_class_dmethod; - int curr_class_dmethod; + List *dmethods_seq; + Hash *dmethods_table; + int n_dmethods; + int n_directors; + int first_class_dmethod; + int curr_class_dmethod; enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum }; - public: +public: /* ----------------------------------------------------------------------------- * CSHARP() * ----------------------------------------------------------------------------- */ - CSHARP() : - empty_string(NewString("")), - public_string(NewString("public")), - protected_string(NewString("protected")), - - swig_types_hash(NULL), - f_runtime(NULL), - f_runtime_h(NULL), - f_header(NULL), - f_wrappers(NULL), - f_init(NULL), - f_directors(NULL), - f_directors_h(NULL), - filenames_list(NULL), - - proxy_flag(true), - native_function_flag(false), - enum_constant_flag(false), - static_flag(false), - variable_wrapper_flag(false), - wrapping_member_flag(false), - global_variable_flag(false), - old_variable_names (false), - generate_property_declaration_flag(false), - - imclass_name(NULL), - module_class_name(NULL), - imclass_class_code(NULL), - proxy_class_def(NULL), - proxy_class_code(NULL), - module_class_code(NULL), - proxy_class_name(NULL), - variable_name(NULL), - proxy_class_constants_code(NULL), - module_class_constants_code(NULL), - enum_code(NULL), - dllimport(NULL), - namespce(NULL), - imclass_imports(NULL), - module_imports(NULL), - imclass_baseclass(NULL), - module_baseclass(NULL), - imclass_interfaces(NULL), - module_interfaces(NULL), - imclass_class_modifiers(NULL), - module_class_modifiers(NULL), - upcasts_code(NULL), - imclass_cppcasts_code(NULL), - director_callback_typedefs(NULL), - director_callbacks(NULL), - director_delegate_callback(NULL), - director_delegate_definitions(NULL), - director_delegate_instances(NULL), - director_method_types(NULL), - director_connect_parms(NULL), - destructor_call(NULL), - - dmethods_seq(NULL), - dmethods_table(NULL), - n_dmethods(0), - n_directors(0) - { - /* for now, multiple inheritance in directors is disabled, this - should be easy to implement though */ - director_multiple_inheritance = 0; - director_language = 1; - } + CSHARP():empty_string(NewString("")), + public_string(NewString("public")), + protected_string(NewString("protected")), + swig_types_hash(NULL), + f_runtime(NULL), + f_runtime_h(NULL), + f_header(NULL), + f_wrappers(NULL), + f_init(NULL), + f_directors(NULL), + f_directors_h(NULL), + filenames_list(NULL), + proxy_flag(true), + native_function_flag(false), + enum_constant_flag(false), + static_flag(false), + variable_wrapper_flag(false), + wrapping_member_flag(false), + global_variable_flag(false), + old_variable_names(false), + generate_property_declaration_flag(false), + imclass_name(NULL), + module_class_name(NULL), + imclass_class_code(NULL), + proxy_class_def(NULL), + proxy_class_code(NULL), + module_class_code(NULL), + proxy_class_name(NULL), + variable_name(NULL), + proxy_class_constants_code(NULL), + module_class_constants_code(NULL), + enum_code(NULL), + dllimport(NULL), + namespce(NULL), + imclass_imports(NULL), + module_imports(NULL), + imclass_baseclass(NULL), + module_baseclass(NULL), + imclass_interfaces(NULL), + module_interfaces(NULL), + imclass_class_modifiers(NULL), + module_class_modifiers(NULL), + upcasts_code(NULL), + imclass_cppcasts_code(NULL), + director_callback_typedefs(NULL), + director_callbacks(NULL), + director_delegate_callback(NULL), + director_delegate_definitions(NULL), + director_delegate_instances(NULL), + director_method_types(NULL), + director_connect_parms(NULL), + destructor_call(NULL), + dmethods_seq(NULL), + dmethods_table(NULL), + n_dmethods(0), + n_directors(0) { + /* for now, multiple inheritance in directors is disabled, this + should be easy to implement though */ + director_multiple_inheritance = 0; + director_language = 1; + } /* ----------------------------------------------------------------------------- * getProxyName() @@ -165,12 +159,12 @@ class CSHARP : public Language { * Test to see if a type corresponds to something wrapped with a proxy class * Return NULL if not otherwise the proxy class name * ----------------------------------------------------------------------------- */ - - String *getProxyName(SwigType *t) { + + String *getProxyName(SwigType *t) { if (proxy_flag) { Node *n = classLookup(t); if (n) { - return Getattr(n,"sym:name"); + return Getattr(n, "sym:name"); } } return NULL; @@ -205,40 +199,40 @@ class CSHARP : public Language { // Look for certain command line options for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i],"-dllimport") == 0) { - if (argv[i+1]) { - dllimport = NewString(""); - Printf(dllimport, argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-namespace") == 0) { - if (argv[i+1]) { - namespce = NewString(""); - Printf(namespce, argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if ((strcmp(argv[i],"-noproxy") == 0)) { - Swig_mark_arg(i); - proxy_flag = false; - } else if (strcmp(argv[i],"-oldvarnames") == 0) { - Swig_mark_arg(i); + if (strcmp(argv[i], "-dllimport") == 0) { + if (argv[i + 1]) { + dllimport = NewString(""); + Printf(dllimport, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-namespace") == 0) { + if (argv[i + 1]) { + namespce = NewString(""); + Printf(namespce, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if ((strcmp(argv[i], "-noproxy") == 0)) { + Swig_mark_arg(i); + proxy_flag = false; + } else if (strcmp(argv[i], "-oldvarnames") == 0) { + Swig_mark_arg(i); old_variable_names = true; - } else if (strcmp(argv[i],"-help") == 0) { - Printf(stdout,"%s\n", usage); - } + } else if (strcmp(argv[i], "-help") == 0) { + Printf(stdout, "%s\n", usage); + } } } // Add a symbol to the parser for conditional compilation - Preprocessor_define("SWIGCSHARP 1",0); + Preprocessor_define("SWIGCSHARP 1", 0); // Add typemap definitions SWIG_typemap_lang("csharp"); @@ -254,11 +248,11 @@ class CSHARP : public Language { virtual int top(Node *n) { // Get any options set in the module directive - Node* optionsnode = Getattr( Getattr(n,"module"), "options"); + Node *optionsnode = Getattr(Getattr(n, "module"), "options"); if (optionsnode) { - if (Getattr(optionsnode,"imclassname")) - imclass_name = Copy(Getattr(optionsnode,"imclassname")); + if (Getattr(optionsnode, "imclassname")) + imclass_name = Copy(Getattr(optionsnode, "imclassname")); /* check if directors are enabled for this module. note: this * is a "master" switch, without which no director code will be * emitted. %feature("director") statements are also required @@ -268,28 +262,28 @@ class CSHARP : public Language { * interface file to enable director generation. */ if (Getattr(optionsnode, "directors")) { - allow_directors(); + allow_directors(); } if (Getattr(optionsnode, "dirprot")) { - allow_dirprot(); + allow_dirprot(); } } /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); + String *outfile = Getattr(n, "outfile"); String *outfile_h = Getattr(n, "outfile_h"); - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); } if (directorsEnabled()) { - f_runtime_h = NewFile(outfile_h,"w"); + f_runtime_h = NewFile(outfile_h, "w"); if (!f_runtime_h) { - FileErrorDisplay(outfile_h); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(outfile_h); + SWIG_exit(EXIT_FAILURE); } } @@ -300,26 +294,26 @@ class CSHARP : public Language { f_directors = NewString(""); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - Swig_register_filebyname("director",f_directors); - Swig_register_filebyname("director_h",f_directors_h); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); swig_types_hash = NewHash(); filenames_list = NewList(); // Make the intermediary class and module class names. The intermediary class name can be set in the module directive. if (!imclass_name) { - imclass_name = NewStringf("%sPINVOKE", Getattr(n,"name")); - module_class_name = Copy(Getattr(n,"name")); + imclass_name = NewStringf("%sPINVOKE", Getattr(n, "name")); + module_class_name = Copy(Getattr(n, "name")); } else { // Rename the module name if it is the same as intermediary class name - a backwards compatibility solution - if (Cmp(imclass_name, Getattr(n,"name")) == 0) - module_class_name = NewStringf("%sModule", Getattr(n,"name")); + if (Cmp(imclass_name, Getattr(n, "name")) == 0) + module_class_name = NewStringf("%sModule", Getattr(n, "name")); else - module_class_name = Copy(Getattr(n,"name")); + module_class_name = Copy(Getattr(n, "name")); } imclass_class_code = NewString(""); @@ -342,13 +336,15 @@ class CSHARP : public Language { dmethods_table = NewHash(); n_dmethods = 0; n_directors = 0; - if (!namespce) namespce = NewString(""); - if (!dllimport) dllimport = Copy(module_class_name); + if (!namespce) + namespce = NewString(""); + if (!dllimport) + dllimport = Copy(module_class_name); - Swig_banner(f_runtime); // Print the SWIG banner message + Swig_banner(f_runtime); // Print the SWIG banner message if (directorsEnabled()) { - Printf(f_runtime,"#define SWIG_DIRECTORS\n"); + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); /* Emit initial director header and director code: */ Swig_banner(f_directors_h); @@ -366,17 +362,17 @@ class CSHARP : public Language { String *wrapper_name = NewString(""); Printf(wrapper_name, "CSharp_%%f", imclass_name); - Swig_name_register((char*)"wrapper", Char(wrapper_name)); + Swig_name_register((char *) "wrapper", Char(wrapper_name)); if (old_variable_names) { - Swig_name_register((char*)"set", (char*)"set_%v"); - Swig_name_register((char*)"get", (char*)"get_%v"); + Swig_name_register((char *) "set", (char *) "set_%v"); + Swig_name_register((char *) "get", (char *) "get_%v"); } Delete(wrapper_name); - Printf(f_wrappers,"\n#ifdef __cplusplus\n"); - Printf(f_wrappers,"extern \"C\" {\n"); - Printf(f_wrappers,"#endif\n\n"); + Printf(f_wrappers, "\n#ifdef __cplusplus\n"); + Printf(f_wrappers, "extern \"C\" {\n"); + Printf(f_wrappers, "#endif\n\n"); /* Emit code */ Language::top(n); @@ -385,34 +381,34 @@ class CSHARP : public Language { // Insert director runtime into the f_runtime file (make it occur before %header section) Swig_insert_file("director.swg", f_runtime); } - // Generate the intermediary class { String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), imclass_name); - File *f_im = NewFile(filen,"w"); - if(!f_im) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + File *f_im = NewFile(filen, "w"); + if (!f_im) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the intermediary class file emitBanner(f_im); addOpenNamespace(namespce, f_im); - if(imclass_imports) - Printf(f_im, "%s\n", imclass_imports); + if (imclass_imports) + Printf(f_im, "%s\n", imclass_imports); if (Len(imclass_class_modifiers) > 0) - Printf(f_im, "%s ", imclass_class_modifiers); + Printf(f_im, "%s ", imclass_class_modifiers); Printf(f_im, "%s ", imclass_name); if (imclass_baseclass && *Char(imclass_baseclass)) - Printf(f_im, ": %s ", imclass_baseclass); + Printf(f_im, ": %s ", imclass_baseclass); if (Len(imclass_interfaces) > 0) - Printv(f_im, "implements ", imclass_interfaces, " ", NIL); + Printv(f_im, "implements ", imclass_interfaces, " ", NIL); Printf(f_im, "{\n"); // Add the intermediary class methods @@ -432,30 +428,31 @@ class CSHARP : public Language { // Generate the C# module class { String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), module_class_name); - File *f_module = NewFile(filen,"w"); - if(!f_module) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + File *f_module = NewFile(filen, "w"); + if (!f_module) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the module class file emitBanner(f_module); addOpenNamespace(namespce, f_module); - if(module_imports) - Printf(f_module, "%s\n", module_imports); + if (module_imports) + Printf(f_module, "%s\n", module_imports); if (Len(module_class_modifiers) > 0) - Printf(f_module, "%s ", module_class_modifiers); + Printf(f_module, "%s ", module_class_modifiers); Printf(f_module, "%s ", module_class_name); if (module_baseclass && *Char(module_baseclass)) - Printf(f_module, ": %s ", module_baseclass); + Printf(f_module, ": %s ", module_baseclass); if (Len(module_interfaces) > 0) - Printv(f_module, "implements ", module_interfaces, " ", NIL); + Printv(f_module, "implements ", module_interfaces, " ", NIL); Printf(f_module, "{\n"); Replaceall(module_class_code, "$module", module_class_name); @@ -480,12 +477,12 @@ class CSHARP : public Language { Close(f_module); } - if(upcasts_code) - Printv(f_wrappers,upcasts_code,NIL); + if (upcasts_code) + Printv(f_wrappers, upcasts_code, NIL); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"}\n"); - Printf(f_wrappers,"#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "}\n"); + Printf(f_wrappers, "#endif\n"); // Output a C# type wrapper class for each SWIG type for (Iterator swig_type = First(swig_types_hash); swig_type.key; swig_type = Next(swig_type)) { @@ -498,45 +495,67 @@ class CSHARP : public Language { for (it1 = First(filenames_list); it1.item; it1 = Next(it1)) { String *item1_lower = Swig_string_lower(it1.item); for (it2 = Next(it1); it2.item; it2 = Next(it2)) { - String *item2_lower = Swig_string_lower(it2.item); - if (it1.item && it2.item) { - if (Strcmp(item1_lower, item2_lower) == 0) { - Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number, - "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as " - "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item); - } - } - Delete(item2_lower); + String *item2_lower = Swig_string_lower(it2.item); + if (it1.item && it2.item) { + if (Strcmp(item1_lower, item2_lower) == 0) { + Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number, + "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as " + "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item); + } + } + Delete(item2_lower); } Delete(item1_lower); } - Delete(swig_types_hash); swig_types_hash = NULL; - Delete(filenames_list); filenames_list = NULL; - Delete(imclass_name); imclass_name = NULL; - Delete(imclass_class_code); imclass_class_code = NULL; - Delete(proxy_class_def); proxy_class_def = NULL; - Delete(proxy_class_code); proxy_class_code = NULL; - Delete(module_class_constants_code); module_class_constants_code = NULL; - Delete(imclass_baseclass); imclass_baseclass = NULL; - Delete(imclass_interfaces); imclass_interfaces = NULL; - Delete(imclass_class_modifiers); imclass_class_modifiers = NULL; - Delete(module_class_name); module_class_name = NULL; - Delete(module_class_code); module_class_code = NULL; - Delete(module_baseclass); module_baseclass = NULL; - Delete(module_interfaces); module_interfaces = NULL; - Delete(module_imports); module_imports = NULL; - Delete(module_class_modifiers); module_class_modifiers = NULL; - Delete(imclass_imports); imclass_imports = NULL; - Delete(imclass_cppcasts_code); imclass_cppcasts_code = NULL; - Delete(upcasts_code); upcasts_code = NULL; - Delete(dmethods_seq); dmethods_seq = NULL; - Delete(dmethods_table); dmethods_table = NULL; - Delete(namespce); namespce = NULL; + Delete(swig_types_hash); + swig_types_hash = NULL; + Delete(filenames_list); + filenames_list = NULL; + Delete(imclass_name); + imclass_name = NULL; + Delete(imclass_class_code); + imclass_class_code = NULL; + Delete(proxy_class_def); + proxy_class_def = NULL; + Delete(proxy_class_code); + proxy_class_code = NULL; + Delete(module_class_constants_code); + module_class_constants_code = NULL; + Delete(imclass_baseclass); + imclass_baseclass = NULL; + Delete(imclass_interfaces); + imclass_interfaces = NULL; + Delete(imclass_class_modifiers); + imclass_class_modifiers = NULL; + Delete(module_class_name); + module_class_name = NULL; + Delete(module_class_code); + module_class_code = NULL; + Delete(module_baseclass); + module_baseclass = NULL; + Delete(module_interfaces); + module_interfaces = NULL; + Delete(module_imports); + module_imports = NULL; + Delete(module_class_modifiers); + module_class_modifiers = NULL; + Delete(imclass_imports); + imclass_imports = NULL; + Delete(imclass_cppcasts_code); + imclass_cppcasts_code = NULL; + Delete(upcasts_code); + upcasts_code = NULL; + Delete(dmethods_seq); + dmethods_seq = NULL; + Delete(dmethods_table); + dmethods_table = NULL; + Delete(namespce); + namespce = NULL; n_dmethods = 0; /* Close all of the files */ - Dump(f_header,f_runtime); + Dump(f_header, f_runtime); if (directorsEnabled()) { Dump(f_directors, f_runtime); @@ -546,13 +565,16 @@ class CSHARP : public Language { Printf(f_runtime_h, "#endif\n"); Close(f_runtime_h); - Delete(f_runtime_h); f_runtime_h = NULL; - Delete(f_directors); f_directors = NULL; - Delete(f_directors_h); f_directors_h = NULL; + Delete(f_runtime_h); + f_runtime_h = NULL; + Delete(f_directors); + f_directors = NULL; + Delete(f_directors_h); + f_directors_h = NULL; } - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); @@ -579,13 +601,13 @@ class CSHARP : public Language { * Add new director upcall signature *----------------------------------------------------------------------*/ - UpcallData * addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name) { - UpcallData *udata; - String *imclass_methodidx; - String *class_methodidx; - Hash *new_udata; - String *key = NewStringf("%s|%s", imclass_method, decl); - + UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *decl, String *overloaded_name) { + UpcallData *udata; + String *imclass_methodidx; + String *class_methodidx; + Hash *new_udata; + String *key = NewStringf("%s|%s", imclass_method, decl); + ++curr_class_dmethod; /* Do we know about this director class already? */ @@ -620,33 +642,34 @@ class CSHARP : public Language { *----------------------------------------------------------------------*/ /* - UpcallData * getUpcallMethodData(String *director_class, String *decl) { - String *key = NewStringf("%s|%s", director_class, decl); - UpcallData *udata = Getattr(dmethods_table, key); + UpcallData * getUpcallMethodData(String *director_class, String *decl) { + String *key = NewStringf("%s|%s", director_class, decl); + UpcallData *udata = Getattr(dmethods_table, key); - Delete(key); - return udata; - } - */ + Delete(key); + return udata; + } + */ /* ---------------------------------------------------------------------- * nativeWrapper() * ---------------------------------------------------------------------- */ virtual int nativeWrapper(Node *n) { - String *wrapname = Getattr(n,"wrap:name"); + String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname,n)) return SWIG_ERROR; + if (!addSymbol(wrapname, n)) + return SWIG_ERROR; - if (Getattr(n,"type")) { - Swig_save("nativeWrapper",n,"name",NIL); - Setattr(n,"name", wrapname); + if (Getattr(n, "type")) { + Swig_save("nativeWrapper", n, "name", NIL); + Setattr(n, "name", wrapname); native_function_flag = true; functionWrapper(n); Swig_restore(n); native_function_flag = false; } else { - Printf(stderr,"%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n,"wrap:name")); + Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); } return SWIG_OK; @@ -657,32 +680,33 @@ class CSHARP : public Language { * ---------------------------------------------------------------------- */ virtual int functionWrapper(Node *n) { - String *symname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - int i; - String *c_return_type = NewString(""); - String *im_return_type = NewString(""); - String *cleanup = NewString(""); - String *outarg = NewString(""); - String *body = NewString(""); - String *im_outattribute = 0; - int num_arguments = 0; - int num_required = 0; - bool is_void_return; - String *overloaded_name = getOverloadedName(n); + String *symname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + int i; + String *c_return_type = NewString(""); + String *im_return_type = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); + String *body = NewString(""); + String *im_outattribute = 0; + int num_arguments = 0; + int num_required = 0; + bool is_void_return; + String *overloaded_name = getOverloadedName(n); - if (!Getattr(n,"sym:overloaded")) { - if (!addSymbol(Getattr(n,"sym:name"),n)) return SWIG_ERROR; + if (!Getattr(n, "sym:overloaded")) { + if (!addSymbol(Getattr(n, "sym:name"), n)) + return SWIG_ERROR; } /* The rest of this function deals with generating the intermediary class wrapper function (that wraps a c/c++ function) and generating the PInvoke c code. Each C# wrapper function has a matching PInvoke c function call. - */ + */ // A new wrapper function object Wrapper *f = NewWrapper(); @@ -695,53 +719,50 @@ class CSHARP : public Language { Swig_typemap_attach_parms("imtype", l, f); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("ctype",n,"",0))) { - String *ctypeout = Getattr(n,"tmap:ctype:out"); // the type in the ctype typemap's out attribute overrides the type in the typemap + if ((tm = Swig_typemap_lookup_new("ctype", n, "", 0))) { + String *ctypeout = Getattr(n, "tmap:ctype:out"); // the type in the ctype typemap's out attribute overrides the type in the typemap if (ctypeout) - tm = ctypeout; - Printf(c_return_type,"%s", tm); + tm = ctypeout; + Printf(c_return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, - "No ctype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(t, 0)); } - if ((tm = Swig_typemap_lookup_new("imtype",n,"",0))) { - String *imtypeout = Getattr(n,"tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap + if ((tm = Swig_typemap_lookup_new("imtype", n, "", 0))) { + String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap if (imtypeout) - tm = imtypeout; - Printf(im_return_type,"%s", tm); - im_outattribute = Getattr(n,"tmap:imtype:outattributes"); + tm = imtypeout; + Printf(im_return_type, "%s", tm); + im_outattribute = Getattr(n, "tmap:imtype:outattributes"); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, - "No imtype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(t, 0)); } is_void_return = (Cmp(c_return_type, "void") == 0); if (!is_void_return) - Wrapper_add_localv(f,"jresult", c_return_type, "jresult",NIL); + Wrapper_add_localv(f, "jresult", c_return_type, "jresult", NIL); Printv(f->def, " SWIGEXPORT ", c_return_type, " SWIGSTDCALL ", wname, "(", NIL); // Emit all of the local variables for holding arguments. - emit_args(t,l,f); + emit_args(t, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); + emit_attach_parmmaps(l, f); // Parameter overloading - Setattr(n,"wrap:parms",l); - Setattr(n,"wrap:name", wname); + Setattr(n, "wrap:parms", l); + Setattr(n, "wrap:name", wname); // Wrappers not wanted for some methods where the parameters cannot be overloaded in C# - if (Getattr(n,"sym:overloaded")) { + if (Getattr(n, "sym:overloaded")) { // Emit warnings for the few cases that can't be overloaded in C# and give up on generating wrapper - Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) - return SWIG_OK; + Swig_overload_check(n); + if (Getattr(n, "overload:ignore")) + return SWIG_OK; } - Printv(imclass_class_code, - "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", overloaded_name, "\")]\n", NIL); + Printv(imclass_class_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", overloaded_name, "\")]\n", NIL); if (im_outattribute) Printf(imclass_class_code, " %s\n", im_outattribute); @@ -751,64 +772,62 @@ class CSHARP : public Language { /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); int gencomma = 0; // Now walk the function parameter list and generate code to get arguments - for (i = 0, p=l; i < num_arguments; i++) { + for (i = 0, p = l; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); - String *im_param_type = NewString(""); - String *c_param_type = NewString(""); - String *arg = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + String *im_param_type = NewString(""); + String *c_param_type = NewString(""); + String *arg = NewString(""); - Printf(arg,"j%s", ln); + Printf(arg, "j%s", ln); /* Get the ctype types of the parameter */ - if ((tm = Getattr(p,"tmap:ctype"))) { - Printv(c_param_type, tm, NIL); + if ((tm = Getattr(p, "tmap:ctype"))) { + Printv(c_param_type, tm, NIL); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, - "No ctype typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(pt, 0)); } /* Get the intermediary class parameter types of the parameter */ - if ((tm = Getattr(p,"tmap:imtype"))) { - String *inattributes = Getattr(p,"tmap:imtype:inattributes"); - Printf(im_param_type, "%s%s", inattributes ? (const String *)inattributes : empty_string, tm); + if ((tm = Getattr(p, "tmap:imtype"))) { + String *inattributes = Getattr(p, "tmap:imtype:inattributes"); + Printf(im_param_type, "%s%s", inattributes ? (const String *) inattributes : empty_string, tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, - "No imtype typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(pt, 0)); } /* Add parameter to intermediary class method */ - if(gencomma) Printf(imclass_class_code, ", "); + if (gencomma) + Printf(imclass_class_code, ", "); Printf(imclass_class_code, "%s %s", im_param_type, arg); // Add parameter to C function - Printv(f->def, gencomma?", ":"", c_param_type, " ", arg, NIL); + Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL); gencomma = 1; - + // Get typemap for this argument - if ((tm = Getattr(p,"tmap:in"))) { - canThrow(n, "in", p); - Replaceall(tm,"$source",arg); /* deprecated */ - Replaceall(tm,"$target",ln); /* deprecated */ - Replaceall(tm,"$arg",arg); /* deprecated? */ - Replaceall(tm,"$input", arg); - Setattr(p,"emit:input", arg); - Printf(f->code,"%s\n", tm); - p = Getattr(p,"tmap:in:next"); + if ((tm = Getattr(p, "tmap:in"))) { + canThrow(n, "in", p); + Replaceall(tm, "$source", arg); /* deprecated */ + Replaceall(tm, "$target", ln); /* deprecated */ + Replaceall(tm, "$arg", arg); /* deprecated? */ + Replaceall(tm, "$input", arg); + Setattr(p, "emit:input", arg); + Printf(f->code, "%s\n", tm); + p = Getattr(p, "tmap:in:next"); } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); - p = nextSibling(p); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); + p = nextSibling(p); } Delete(im_param_type); Delete(c_param_type); @@ -817,114 +836,112 @@ class CSHARP : public Language { /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - canThrow(n, "check", p); - Replaceall(tm,"$target",Getattr(p,"lname")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + canThrow(n, "check", p); + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Insert cleanup code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - canThrow(n, "freearg", p); - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + canThrow(n, "freearg", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Insert argument output code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - canThrow(n, "argout", p); - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* deprecated */ - Replaceall(tm,"$target",Getattr(p,"lname")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$result","jresult"); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + if ((tm = Getattr(p, "tmap:argout"))) { + canThrow(n, "argout", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } // Get any C# exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n,"throws"))) { + if ((throw_parm_list = Getattr(n, "throws"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { - canThrow(n, "throws", p); - } + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + canThrow(n, "throws", p); + } } } if (Cmp(nodeType(n), "constant") == 0) { // Wrapping a constant hack - Swig_save("functionWrapper",n,"wrap:action",NIL); + Swig_save("functionWrapper", n, "wrap:action", NIL); // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"), use_naturalvar_mode(n)); - Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value"))); + SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); + Setattr(n, "wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty, 0), Getattr(n, "value"))); } - // Now write code to make the function call - if(!native_function_flag) - emit_action(n,f); + if (!native_function_flag) + emit_action(n, f); if (Cmp(nodeType(n), "constant") == 0) Swig_restore(n); /* Return value if necessary */ String *null_attribute = 0; - if(!native_function_flag) { - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - canThrow(n, "out", n); - Replaceall(tm,"$source", "result"); /* deprecated */ - Replaceall(tm,"$target", "jresult"); /* deprecated */ - Replaceall(tm,"$result","jresult"); - Printf(f->code,"%s", tm); - null_attribute = Getattr(n, "tmap:out:null"); - if (Len(tm)) - Printf(f->code,"\n"); + if (!native_function_flag) { + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + canThrow(n, "out", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Replaceall(tm, "$target", "jresult"); /* deprecated */ + Replaceall(tm, "$result", "jresult"); + Printf(f->code, "%s", tm); + null_attribute = Getattr(n, "tmap:out:null"); + if (Len(tm)) + Printf(f->code, "\n"); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(t,0), Getattr(n,"name")); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name")); } } /* Output argument output code */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - canThrow(n, "newfree", n); - Replaceall(tm,"$source","result"); /* deprecated */ - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + canThrow(n, "newfree", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ - if(!native_function_flag) { + if (!native_function_flag) { if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - canThrow(n, "ret", n); - Replaceall(tm,"$source","result"); /* deprecated */ - Printf(f->code,"%s\n",tm); + canThrow(n, "ret", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } @@ -932,52 +949,52 @@ class CSHARP : public Language { Printf(imclass_class_code, ")"); Printf(imclass_class_code, ";\n"); - Printf(f->def,") {"); + Printf(f->def, ") {"); - if(!is_void_return) + if (!is_void_return) Printv(f->code, " return jresult;\n", NIL); Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",symname); + Replaceall(f->code, "$symname", symname); /* Contract macro modification */ if (Replaceall(f->code, "SWIG_contract_assert(", "SWIG_contract_assert($null, ") > 0) { - Setattr(n,"csharp:canthrow","1"); + Setattr(n, "csharp:canthrow", "1"); } - if(!null_attribute) - Replaceall(f->code,"$null","0"); + if (!null_attribute) + Replaceall(f->code, "$null", "0"); else - Replaceall(f->code,"$null",null_attribute); + Replaceall(f->code, "$null", null_attribute); /* Dump the function out */ - if(!native_function_flag) { - Wrapper_print(f,f_wrappers); + if (!native_function_flag) { + Wrapper_print(f, f_wrappers); // Handle %csexception which sets the canthrow attribute - if (Getattr(n,"feature:except:canthrow")) - Setattr(n,"csharp:canthrow","1"); + if (Getattr(n, "feature:except:canthrow")) + Setattr(n, "csharp:canthrow", "1"); // A very simple check (it is not foolproof) to help typemap/feature writers for // throwing C# exceptions from unmanaged code. It checks for the common methods which // set a pending C# exception... the 'canthrow' typemap/feature attribute must be set // so that code which checks for pending exceptions is added in the C# proxy method. - if (!Getattr(n,"csharp:canthrow")) { - if(Strstr(f->code, "SWIG_exception")) { - Swig_warning(WARN_CSHARP_CANTHROW, input_file, line_number, - "Unmanaged code contains a call to SWIG_exception and C# code does not handle pending exceptions via the canthrow attribute.\n"); - } else if(Strstr(f->code, "SWIG_CSharpSetPendingException")) { - Swig_warning(WARN_CSHARP_CANTHROW, input_file, line_number, - "Unmanaged code contains a call to a SWIG_CSharpSetPendingException method and C# code does not handle pending exceptions via the canthrow attribute.\n"); - } + if (!Getattr(n, "csharp:canthrow")) { + if (Strstr(f->code, "SWIG_exception")) { + Swig_warning(WARN_CSHARP_CANTHROW, input_file, line_number, + "Unmanaged code contains a call to SWIG_exception and C# code does not handle pending exceptions via the canthrow attribute.\n"); + } else if (Strstr(f->code, "SWIG_CSharpSetPendingException")) { + Swig_warning(WARN_CSHARP_CANTHROW, input_file, line_number, + "Unmanaged code contains a call to a SWIG_CSharpSetPendingException method and C# code does not handle pending exceptions via the canthrow attribute.\n"); + } } } - if(!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) { + if (!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) { moduleClassFunctionHandler(n); } @@ -985,20 +1002,20 @@ class CSHARP : public Language { * Generate the proxy class properties for public member variables. * Not for enums and constants. */ - if(proxy_flag && wrapping_member_flag && !enum_constant_flag) { + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Capitalize the first letter in the variable in the getter/setter function name bool getter_flag = Cmp(symname, Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) != 0; String *getter_setter_name = NewString(""); - if(!getter_flag) - Printf(getter_setter_name,"set"); - else - Printf(getter_setter_name,"get"); + if (!getter_flag) + Printf(getter_setter_name, "set"); + else + Printf(getter_setter_name, "get"); Putc(toupper((int) *Char(variable_name)), getter_setter_name); - Printf(getter_setter_name, "%s", Char(variable_name)+1); + Printf(getter_setter_name, "%s", Char(variable_name) + 1); - Setattr(n,"proxyfuncname", getter_setter_name); - Setattr(n,"imfuncname", symname); + Setattr(n, "proxyfuncname", getter_setter_name); + Setattr(n, "imfuncname", symname); proxyClassFunctionHandler(n); Delete(getter_setter_name); @@ -1030,7 +1047,7 @@ class CSHARP : public Language { virtual int globalvariableHandler(Node *n) { generate_property_declaration_flag = true; - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); global_variable_flag = true; int ret = Language::globalvariableHandler(n); global_variable_flag = false; @@ -1055,115 +1072,99 @@ class CSHARP : public Language { virtual int enumDeclaration(Node *n) { if (!ImportMode) { - if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (getCurrentClass() && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; enum_code = NewString(""); - String *symname = Getattr(n,"sym:name"); - String *constants_code = (proxy_flag && is_wrapping_class()) ? proxy_class_constants_code : module_class_constants_code; + String *symname = Getattr(n, "sym:name"); + String *constants_code = (proxy_flag && is_wrapping_class())? proxy_class_constants_code : module_class_constants_code; EnumFeature enum_feature = decodeEnumFeature(n); - String *typemap_lookup_type = Getattr(n,"name"); + String *typemap_lookup_type = Getattr(n, "name"); if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { - // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum + // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum - // Pure C# baseclass and interfaces - const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE); - const String *pure_interfaces = typemapLookup("csinterfaces", typemap_lookup_type, WARN_NONE); + // Pure C# baseclass and interfaces + const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE); + const String *pure_interfaces = typemapLookup("csinterfaces", typemap_lookup_type, WARN_NONE); - // Class attributes - const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE); - if (csattributes && *Char(csattributes)) - Printf(enum_code, "%s\n", csattributes); + // Class attributes + const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE); + if (csattributes && *Char(csattributes)) + Printf(enum_code, "%s\n", csattributes); - // Emit the enum - Printv(enum_code, - typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) - " ", - symname, - (*Char(pure_baseclass) || *Char(pure_interfaces)) ? - " : " : - "", - pure_baseclass, - ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces - ", " : - "", - pure_interfaces, - " {\n", - NIL); + // Emit the enum + Printv(enum_code, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) + " ", symname, (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces + ", " : "", pure_interfaces, " {\n", NIL); } else { - // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort - if (symname && !Getattr(n,"unnamedinstance")) - Printf(constants_code, " // %s \n", symname); + // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort + if (symname && !Getattr(n, "unnamedinstance")) + Printf(constants_code, " // %s \n", symname); } // Emit each enum item Language::enumDeclaration(n); if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { - // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum - // Finish the enum declaration - // Typemaps are used to generate the enum definition in a similar manner to proxy classes. - Printv(enum_code, - (enum_feature == ProperEnum) ? - "\n" : - typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class - typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code - "}", - NIL); + // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum + // Finish the enum declaration + // Typemaps are used to generate the enum definition in a similar manner to proxy classes. + Printv(enum_code, (enum_feature == ProperEnum) ? "\n" : typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class + typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code + "}", NIL); - Replaceall(enum_code, "$csclassname", symname); + Replaceall(enum_code, "$csclassname", symname); - // Substitute $enumvalues - intended usage is for typesafe enums - if (Getattr(n,"enumvalues")) - Replaceall(enum_code, "$enumvalues", Getattr(n,"enumvalues")); - else - Replaceall(enum_code, "$enumvalues", ""); + // Substitute $enumvalues - intended usage is for typesafe enums + if (Getattr(n, "enumvalues")) + Replaceall(enum_code, "$enumvalues", Getattr(n, "enumvalues")); + else + Replaceall(enum_code, "$enumvalues", ""); - if (proxy_flag && is_wrapping_class()) { - // Enums defined within the C++ class are defined within the proxy class + if (proxy_flag && is_wrapping_class()) { + // Enums defined within the C++ class are defined within the proxy class - // Add extra indentation - Replaceall(enum_code, "\n", "\n "); - Replaceall(enum_code, " \n", "\n"); + // Add extra indentation + Replaceall(enum_code, "\n", "\n "); + Replaceall(enum_code, " \n", "\n"); - Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); - } else { - // Global enums are defined in their own file - String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), symname); - File *f_enum = NewFile(filen,"w"); - if(!f_enum) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); + } else { + // Global enums are defined in their own file + String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), symname); + File *f_enum = NewFile(filen, "w"); + if (!f_enum) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + filen = NULL; - // Start writing out the enum file - emitBanner(f_enum); + // Start writing out the enum file + emitBanner(f_enum); addOpenNamespace(namespce, f_enum); - Printv(f_enum, - typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements - "\n", - enum_code, - "\n", - NIL); + Printv(f_enum, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements + "\n", enum_code, "\n", NIL); addCloseNamespace(namespce, f_enum); - Close(f_enum); - } + Close(f_enum); + } } else { - // Wrap C++ enum with simple constant - Printf(enum_code, "\n"); - if (proxy_flag && is_wrapping_class()) - Printv(proxy_class_constants_code, enum_code, NIL); - else - Printv(module_class_constants_code, enum_code, NIL); + // Wrap C++ enum with simple constant + Printf(enum_code, "\n"); + if (proxy_flag && is_wrapping_class()) + Printv(proxy_class_constants_code, enum_code, NIL); + else + Printv(module_class_constants_code, enum_code, NIL); } - Delete(enum_code); enum_code = NULL; + Delete(enum_code); + enum_code = NULL; } return SWIG_OK; } @@ -1173,12 +1174,13 @@ class CSHARP : public Language { * ---------------------------------------------------------------------- */ virtual int enumvalueDeclaration(Node *n) { - if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (getCurrentClass() && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration",n,"*name", "?value",NIL); - String *symname = Getattr(n,"sym:name"); - String *value = Getattr(n,"value"); - String *name = Getattr(n,"name"); + Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + String *symname = Getattr(n, "sym:name"); + String *value = Getattr(n, "value"); + String *name = Getattr(n, "name"); String *tmpValue; // Strange hack from parent method @@ -1192,60 +1194,61 @@ class CSHARP : public Language { { EnumFeature enum_feature = decodeEnumFeature(parentNode(n)); - if ((enum_feature == ProperEnum) && Getattr(parentNode(n),"sym:name") && !Getattr(parentNode(n),"unnamedinstance")) { - // Wrap (non-anonymous) C/C++ enum with a proper C# enum - // Emit the enum item. - if (!Getattr(n,"_last")) // Only the first enum item has this attribute set - Printf(enum_code, ",\n"); - Printf(enum_code, " %s", symname); + if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) { + // Wrap (non-anonymous) C/C++ enum with a proper C# enum + // Emit the enum item. + if (!Getattr(n, "_last")) // Only the first enum item has this attribute set + Printf(enum_code, ",\n"); + Printf(enum_code, " %s", symname); - // Check for the %csconstvalue feature - String *value = Getattr(n,"feature:cs:constvalue"); + // Check for the %csconstvalue feature + String *value = Getattr(n, "feature:cs:constvalue"); - // Note that the enum value must be a true constant and cannot be set from a PINVOKE call, thus no support for %csconst(0) - value = value ? value : Getattr(n,"enumvalue"); - if (value) { - Printf(enum_code, " = %s", value); - } + // Note that the enum value must be a true constant and cannot be set from a PINVOKE call, thus no support for %csconst(0) + value = value ? value : Getattr(n, "enumvalue"); + if (value) { + Printf(enum_code, " = %s", value); + } } else { - // Wrap C/C++ enums with constant integers or use the typesafe enum pattern - const String *parent_name = Getattr(parentNode(n),"name"); - String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); - const String *tm = typemapLookup("cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF); - String *return_type = Copy(tm); - Delete(typemap_lookup_type); typemap_lookup_type = NULL; + // Wrap C/C++ enums with constant integers or use the typesafe enum pattern + const String *parent_name = Getattr(parentNode(n), "name"); + String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); + const String *tm = typemapLookup("cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF); + String *return_type = Copy(tm); + Delete(typemap_lookup_type); + typemap_lookup_type = NULL; - // The %csconst feature determines how the constant value is obtained - int const_feature_flag = GetFlag(n,"feature:cs:const"); + // The %csconst feature determines how the constant value is obtained + int const_feature_flag = GetFlag(n, "feature:cs:const"); - if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n),"sym:name") && !Getattr(parentNode(n),"unnamedinstance")) { - // Wrap (non-anonymouse) enum using the typesafe enum pattern - if (Getattr(n,"enumvalue")) { - String *value = enumValue(n); - Printf(enum_code, " public static readonly %s %s = new %s(\"%s\", %s);\n", return_type, symname, return_type, symname, value); - Delete(value); - } else { - Printf(enum_code, " public static readonly %s %s = new %s(\"%s\");\n", return_type, symname, return_type, symname); - } - } else { - // Simple integer constants - // Note these are always generated for anonymous enums, no matter what enum_feature is specified - // Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later - const char *const_readonly = const_feature_flag ? "const" : "static readonly"; - String *value = enumValue(n); - Printf(enum_code, " public %s %s %s = %s;\n", const_readonly, return_type, symname, value); - Delete(value); - } + if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) { + // Wrap (non-anonymouse) enum using the typesafe enum pattern + if (Getattr(n, "enumvalue")) { + String *value = enumValue(n); + Printf(enum_code, " public static readonly %s %s = new %s(\"%s\", %s);\n", return_type, symname, return_type, symname, value); + Delete(value); + } else { + Printf(enum_code, " public static readonly %s %s = new %s(\"%s\");\n", return_type, symname, return_type, symname); + } + } else { + // Simple integer constants + // Note these are always generated for anonymous enums, no matter what enum_feature is specified + // Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later + const char *const_readonly = const_feature_flag ? "const" : "static readonly"; + String *value = enumValue(n); + Printf(enum_code, " public %s %s %s = %s;\n", const_readonly, return_type, symname, value); + Delete(value); + } } // Add the enum value to the comma separated list being constructed in the enum declaration. String *enumvalues = Getattr(parentNode(n), "enumvalues"); if (!enumvalues) - Setattr(parentNode(n), "enumvalues", Copy(symname)); + Setattr(parentNode(n), "enumvalues", Copy(symname)); else - Printv(enumvalues, ", ", symname, NIL); + Printv(enumvalues, ", ", symname, NIL); } - + Delete(tmpValue); Swig_restore(n); return SWIG_OK; @@ -1263,25 +1266,26 @@ class CSHARP : public Language { * ------------------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - String *symname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *symname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); String *tm; String *return_type = NewString(""); String *constants_code = NewString(""); - if (!addSymbol(symname,n)) return SWIG_ERROR; + if (!addSymbol(symname, n)) + return SWIG_ERROR; bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); // The %csconst feature determines how the constant value is obtained - int const_feature_flag = GetFlag(n,"feature:cs:const"); + int const_feature_flag = GetFlag(n, "feature:cs:const"); /* Adjust the enum type for the Swig_typemap_lookup. * We want the same jstype typemap for all the enum items so we use the enum type (parent node). */ if (is_enum_item) { - t = Getattr(parentNode(n),"enumtype"); - Setattr(n,"type", t); + t = Getattr(parentNode(n), "enumtype"); + Setattr(n, "type", t); } /* Attach the non-standard typemaps to the parameter list. */ @@ -1289,74 +1293,71 @@ class CSHARP : public Language { /* Get C# return types */ bool classname_substituted_flag = false; - - if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { - String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap + + if ((tm = Swig_typemap_lookup_new("cstype", n, "", 0))) { + String *cstypeout = Getattr(n, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap if (cstypeout) - tm = cstypeout; + tm = cstypeout; classname_substituted_flag = substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t, 0)); } // Add the stripped quotes back in String *new_value = NewString(""); - Swig_save("constantWrapper",n,"value",NIL); - if(SwigType_type(t) == T_STRING) { + Swig_save("constantWrapper", n, "value", NIL); + if (SwigType_type(t) == T_STRING) { Printf(new_value, "\"%s\"", Copy(Getattr(n, "value"))); Setattr(n, "value", new_value); - } - else if(SwigType_type(t) == T_CHAR) { + } else if (SwigType_type(t) == T_CHAR) { Printf(new_value, "\'%s\'", Copy(Getattr(n, "value"))); Setattr(n, "value", new_value); } - const String *outattributes = Getattr(n,"tmap:cstype:outattributes"); + const String *outattributes = Getattr(n, "tmap:cstype:outattributes"); if (outattributes) Printf(constants_code, " %s\n", outattributes); const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname; Printf(constants_code, " public %s %s %s = ", (const_feature_flag ? "const" : "static readonly"), return_type, itemname); // Check for the %csconstvalue feature - String *value = Getattr(n,"feature:cs:constvalue"); + String *value = Getattr(n, "feature:cs:constvalue"); if (value) { Printf(constants_code, "%s;\n", value); } else if (!const_feature_flag) { // Default enum and constant handling will work with any type of C constant and initialises the C# variable from C through a PINVOKE call. - if(classname_substituted_flag) { - if (SwigType_isenum(t)) { - // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(symname)); - } else { - // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); - } + if (classname_substituted_flag) { + if (SwigType_isenum(t)) { + // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) + Printf(constants_code, "(%s)%s.%s();\n", return_type, imclass_name, Swig_name_get(symname)); + } else { + // This handles function pointers using the %constant directive + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); + } } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); + Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); // Each constant and enum value is wrapped with a separate PInvoke function call - SetFlag(n,"feature:immutable"); + SetFlag(n, "feature:immutable"); enum_constant_flag = true; variableWrapper(n); enum_constant_flag = false; } else { // Alternative constant handling will use the C syntax to make a true C# constant and hope that it compiles as C# code - Printf(constants_code, "%s;\n", Getattr(n,"value")); + Printf(constants_code, "%s;\n", Getattr(n, "value")); } // Emit the generated code to appropriate place // Enums only emit the intermediate and PINVOKE methods, so no proxy or module class wrapper methods needed if (!is_enum_item) { - if(proxy_flag && wrapping_member_flag) - Printv(proxy_class_constants_code, constants_code, NIL); + if (proxy_flag && wrapping_member_flag) + Printv(proxy_class_constants_code, constants_code, NIL); else - Printv(module_class_constants_code, constants_code, NIL); + Printv(module_class_constants_code, constants_code, NIL); } - // Cleanup Swig_restore(n); Delete(new_value); @@ -1370,7 +1371,7 @@ class CSHARP : public Language { * ----------------------------------------------------------------------------- */ virtual int insertDirective(Node *n) { - String *code = Getattr(n,"code"); + String *code = Getattr(n, "code"); Replaceall(code, "$module", module_class_name); Replaceall(code, "$imclassname", imclass_name); Replaceall(code, "$dllimport", dllimport); @@ -1397,56 +1398,47 @@ class CSHARP : public Language { virtual int pragmaDirective(Node *n) { if (!ImportMode) { - String *lang = Getattr(n,"lang"); - String *code = Getattr(n,"name"); - String *value = Getattr(n,"value"); + String *lang = Getattr(n, "lang"); + String *code = Getattr(n, "name"); + String *value = Getattr(n, "value"); - if(Strcmp(lang, "csharp") == 0) { + if (Strcmp(lang, "csharp") == 0) { - String *strvalue = NewString(value); - Replaceall(strvalue,"\\\"", "\""); + String *strvalue = NewString(value); + Replaceall(strvalue, "\\\"", "\""); - if(Strcmp(code, "imclassbase") == 0) { - Delete(imclass_baseclass); - imclass_baseclass = Copy(strvalue); - } - else if(Strcmp(code, "imclassclassmodifiers") == 0) { - Delete(imclass_class_modifiers); - imclass_class_modifiers = Copy(strvalue); - } - else if(Strcmp(code, "imclasscode") == 0) { - Printf(imclass_class_code, "%s\n", strvalue); - } - else if(Strcmp(code, "imclassimports") == 0) { - Delete(imclass_imports); - imclass_imports = Copy(strvalue); - } - else if(Strcmp(code, "imclassinterfaces") == 0) { - Delete(imclass_interfaces); - imclass_interfaces = Copy(strvalue); - } - else if(Strcmp(code, "modulebase") == 0) { - Delete(module_baseclass); - module_baseclass = Copy(strvalue); - } - else if(Strcmp(code, "moduleclassmodifiers") == 0) { - Delete(module_class_modifiers); - module_class_modifiers = Copy(strvalue); - } - else if(Strcmp(code, "modulecode") == 0) { - Printf(module_class_code, "%s\n", strvalue); - } - else if(Strcmp(code, "moduleimports") == 0) { - Delete(module_imports); - module_imports = Copy(strvalue); - } - else if(Strcmp(code, "moduleinterfaces") == 0) { - Delete(module_interfaces); - module_interfaces = Copy(strvalue); - } else { - Printf(stderr,"%s : Line %d. Unrecognized pragma.\n", input_file, line_number); - } - Delete(strvalue); + if (Strcmp(code, "imclassbase") == 0) { + Delete(imclass_baseclass); + imclass_baseclass = Copy(strvalue); + } else if (Strcmp(code, "imclassclassmodifiers") == 0) { + Delete(imclass_class_modifiers); + imclass_class_modifiers = Copy(strvalue); + } else if (Strcmp(code, "imclasscode") == 0) { + Printf(imclass_class_code, "%s\n", strvalue); + } else if (Strcmp(code, "imclassimports") == 0) { + Delete(imclass_imports); + imclass_imports = Copy(strvalue); + } else if (Strcmp(code, "imclassinterfaces") == 0) { + Delete(imclass_interfaces); + imclass_interfaces = Copy(strvalue); + } else if (Strcmp(code, "modulebase") == 0) { + Delete(module_baseclass); + module_baseclass = Copy(strvalue); + } else if (Strcmp(code, "moduleclassmodifiers") == 0) { + Delete(module_class_modifiers); + module_class_modifiers = Copy(strvalue); + } else if (Strcmp(code, "modulecode") == 0) { + Printf(module_class_code, "%s\n", strvalue); + } else if (Strcmp(code, "moduleimports") == 0) { + Delete(module_imports); + module_imports = Copy(strvalue); + } else if (Strcmp(code, "moduleinterfaces") == 0) { + Delete(module_interfaces); + module_interfaces = Copy(strvalue); + } else { + Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + } + Delete(strvalue); } } return Language::pragmaDirective(n); @@ -1457,41 +1449,40 @@ class CSHARP : public Language { * ----------------------------------------------------------------------------- */ void emitProxyClassDefAndCPPCasts(Node *n) { - String *c_classname = SwigType_namestr(Getattr(n,"name")); + String *c_classname = SwigType_namestr(Getattr(n, "name")); String *c_baseclass = NULL; String *baseclass = NULL; String *c_baseclassname = NULL; - String *typemap_lookup_type = Getattr(n,"classtypeobj"); - bool feature_director = Swig_directorclass(n) ? true : false; + String *typemap_lookup_type = Getattr(n, "classtypeobj"); + bool feature_director = Swig_directorclass(n) ? true : false; /* Deal with inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist) { Iterator base = First(baselist); - while(base.item && GetFlag(base.item,"feature:ignore")) { + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } if (base.item) { - c_baseclassname = Getattr(base.item,"name"); + c_baseclassname = Getattr(base.item, "name"); baseclass = Copy(getProxyName(c_baseclassname)); if (baseclass) - c_baseclass = SwigType_namestr(Getattr(base.item,"name")); + c_baseclass = SwigType_namestr(Getattr(base.item, "name")); base = Next(base); /* Warn about multiple inheritance for additional base class(es) */ while (base.item) { - if (GetFlag(base.item,"feature:ignore")) { + if (GetFlag(base.item, "feature:ignore")) { base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0); - String *baseclassname = SwigType_str(Getattr(base.item,"name"),0); - Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname); + String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); + String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); + Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", proxyclassname, baseclassname); base = Next(base); } } } - // Inheritance from pure C# classes Node *attributes = NewHash(); const String *pure_baseclass = typemapLookup("csbase", typemap_lookup_type, WARN_NONE, attributes); @@ -1504,39 +1495,26 @@ class CSHARP : public Language { Delete(baseclass); baseclass = NULL; } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) { - Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", typemap_lookup_type, pure_baseclass); + Swig_warning(WARN_CSHARP_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in C#.\n", typemap_lookup_type, pure_baseclass); } - // Pure C# interfaces const String *pure_interfaces = typemapLookup(derived ? "csinterfaces_derived" : "csinterfaces", typemap_lookup_type, WARN_NONE); // Start writing the proxy class - Printv(proxy_class_def, - typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements - "\n", - NIL); + Printv(proxy_class_def, typemapLookup("csimports", typemap_lookup_type, WARN_NONE), // Import statements + "\n", NIL); // Class attributes const String *csattributes = typemapLookup("csattributes", typemap_lookup_type, WARN_NONE); if (csattributes && *Char(csattributes)) Printf(proxy_class_def, "%s\n", csattributes); - Printv(proxy_class_def, - typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " $csclassname", // Class name and base class - (*Char(wanted_base) || *Char(pure_interfaces)) ? - " : " : - "", - wanted_base, - (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces - ", " : - "", - pure_interfaces, - " {", - derived ? - typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class - typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class - NIL); + Printv(proxy_class_def, typemapLookup("csclassmodifiers", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " $csclassname", // Class name and base class + (*Char(wanted_base) || *Char(pure_interfaces)) ? " : " : "", wanted_base, (*Char(wanted_base) && *Char(pure_interfaces)) ? // Interfaces + ", " : "", pure_interfaces, " {", derived ? typemapLookup("csbody_derived", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF) : // main body of class + typemapLookup("csbody", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class + NIL); // C++ destructor is wrapped by the Dispose method // Note that the method name is specified in a typemap attribute called methodname @@ -1556,31 +1534,28 @@ class CSHARP : public Language { } if (*Char(tm)) { if (!destruct_methodname) { - Swig_error(input_file, line_number, - "No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(input_file, line_number, "No methodname attribute defined in csdestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } if (!destruct_methodmodifiers) { - Swig_error(input_file, line_number, - "No methodmodifiers attribute defined in csdestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(input_file, line_number, + "No methodmodifiers attribute defined in csdestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); } } - // Emit the Finalize and Dispose methods if (tm) { // Finalize method if (*Char(destructor_call)) { - Printv(proxy_class_def, - typemapLookup("csfinalize", typemap_lookup_type, WARN_NONE), - NIL); + Printv(proxy_class_def, typemapLookup("csfinalize", typemap_lookup_type, WARN_NONE), NIL); } // Dispose method Printv(destruct, tm, NIL); if (*Char(destructor_call)) - Replaceall(destruct, "$imcall", destructor_call); + Replaceall(destruct, "$imcall", destructor_call); else - Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")"); + Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")"); if (*Char(destruct)) - Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL); + Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", + NIL); } if (feature_director) { @@ -1589,17 +1564,17 @@ class CSHARP : public Language { Printf(proxy_class_code, " private void SwigDirectorConnect() {\n"); for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) { - UpcallData *udata = Getitem(dmethods_seq, i); - String *method = Getattr(udata, "method"); - String *methid = Getattr(udata, "class_methodidx"); - Printf(proxy_class_code, " if (SwigDerivedClassHasMethod(\"%s\", swigMethodTypes%s))\n", method, methid); - Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, method); + UpcallData *udata = Getitem(dmethods_seq, i); + String *method = Getattr(udata, "method"); + String *methid = Getattr(udata, "class_methodidx"); + Printf(proxy_class_code, " if (SwigDerivedClassHasMethod(\"%s\", swigMethodTypes%s))\n", method, methid); + Printf(proxy_class_code, " swigDelegate%s = new SwigDelegate%s_%s(SwigDirector%s);\n", methid, proxy_class_name, methid, method); } Printf(proxy_class_code, " %s.%s_director_connect(swigCPtr", imclass_name, proxy_class_name); for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) { - UpcallData *udata = Getitem(dmethods_seq, i); - String *methid = Getattr(udata, "class_methodidx"); - Printf(proxy_class_code, ", swigDelegate%s", methid); + UpcallData *udata = Getitem(dmethods_seq, i); + String *methid = Getattr(udata, "class_methodidx"); + Printf(proxy_class_code, ", swigDelegate%s", methid); } Printf(proxy_class_code, ");\n"); Printf(proxy_class_code, " }\n"); @@ -1608,89 +1583,91 @@ class CSHARP : public Language { // Only emit if there is at least one director method Printf(proxy_class_code, "\n"); Printf(proxy_class_code, " private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {\n"); - Printf(proxy_class_code, " System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n"); + Printf(proxy_class_code, + " System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, methodTypes, null);\n"); Printf(proxy_class_code, " bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(%s));\n", proxy_class_name); /* Could add this code to cover corner case where the GetMethod() returns a method which allows type * promotion, eg it will return foo(double), if looking for foo(int). - if (hasDerivedMethod) { - hasDerivedMethod = false; - if (methodInfo != null) - { - hasDerivedMethod = true; - ParameterInfo[] parameterArray1 = methodInfo.GetParameters(); - for (int i=0; i 0) - Printv(proxy_class_code, director_delegate_callback, NIL); + Printv(proxy_class_code, director_delegate_callback, NIL); if (Len(director_delegate_definitions) > 0) - Printv(proxy_class_code, "\n", director_delegate_definitions, NIL); + Printv(proxy_class_code, "\n", director_delegate_definitions, NIL); if (Len(director_delegate_instances) > 0) - Printv(proxy_class_code, "\n", director_delegate_instances, NIL); + Printv(proxy_class_code, "\n", director_delegate_instances, NIL); if (Len(director_method_types) > 0) - Printv(proxy_class_code, "\n", director_method_types, NIL); + Printv(proxy_class_code, "\n", director_method_types, NIL); - Delete(director_callback_typedefs); director_callback_typedefs = NULL; - Delete(director_callbacks); director_callbacks = NULL; - Delete(director_delegate_callback); director_delegate_callback = NULL; - Delete(director_delegate_definitions); director_delegate_definitions = NULL; - Delete(director_delegate_instances); director_delegate_instances = NULL; - Delete(director_method_types); director_method_types = NULL; - Delete(director_connect_parms); director_connect_parms = NULL; + Delete(director_callback_typedefs); + director_callback_typedefs = NULL; + Delete(director_callbacks); + director_callbacks = NULL; + Delete(director_delegate_callback); + director_delegate_callback = NULL; + Delete(director_delegate_definitions); + director_delegate_definitions = NULL; + Delete(director_delegate_instances); + director_delegate_instances = NULL; + Delete(director_method_types); + director_method_types = NULL; + Delete(director_connect_parms); + director_connect_parms = NULL; } Delete(attributes); Delete(destruct); // Emit extra user code - Printv(proxy_class_def, - typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code - "\n", - NIL); + Printv(proxy_class_def, typemapLookup("cscode", typemap_lookup_type, WARN_NONE), // extra C# code + "\n", NIL); // Substitute various strings into the above template Replaceall(proxy_class_code, "$csclassname", proxy_class_name); - Replaceall(proxy_class_def, "$csclassname", proxy_class_name); + Replaceall(proxy_class_def, "$csclassname", proxy_class_name); - Replaceall(proxy_class_def, "$module", module_class_name); + Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", imclass_name); Replaceall(proxy_class_code, "$imclassname", imclass_name); - Replaceall(proxy_class_def, "$dllimport", dllimport); + Replaceall(proxy_class_def, "$dllimport", dllimport); Replaceall(proxy_class_code, "$dllimport", dllimport); // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) - if(derived){ - Printv(imclass_cppcasts_code,"\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", proxy_class_name ,"Upcast", "\")]\n", NIL); - Printf(imclass_cppcasts_code," public static extern IntPtr $csclassnameUpcast(IntPtr objectRef);\n"); + if (derived) { + Printv(imclass_cppcasts_code, "\n [DllImport(\"", dllimport, "\", EntryPoint=\"CSharp_", proxy_class_name, "Upcast", "\")]\n", NIL); + Printf(imclass_cppcasts_code, " public static extern IntPtr $csclassnameUpcast(IntPtr objectRef);\n"); Replaceall(imclass_cppcasts_code, "$csclassname", proxy_class_name); Printv(upcasts_code, - "SWIGEXPORT $cbaseclass * SWIGSTDCALL CSharp_$imclazznameUpcast", - "($cclass *objectRef) {\n", - " return ($cbaseclass *)objectRef;\n" - "}\n", - "\n", - NIL); + "SWIGEXPORT $cbaseclass * SWIGSTDCALL CSharp_$imclazznameUpcast", + "($cclass *objectRef) {\n", " return ($cbaseclass *)objectRef;\n" "}\n", "\n", NIL); - Replaceall(upcasts_code, "$cbaseclass", c_baseclass); + Replaceall(upcasts_code, "$cbaseclass", c_baseclass); Replaceall(upcasts_code, "$imclazzname", proxy_class_name); - Replaceall(upcasts_code, "$cclass", c_classname); + Replaceall(upcasts_code, "$cclass", c_classname); } Delete(baseclass); } @@ -1703,28 +1680,30 @@ class CSHARP : public Language { File *f_proxy = NULL; if (proxy_flag) { - proxy_class_name = NewString(Getattr(n,"sym:name")); + proxy_class_name = NewString(Getattr(n, "sym:name")); - if (!addSymbol(proxy_class_name,n)) return SWIG_ERROR; + if (!addSymbol(proxy_class_name, n)) + return SWIG_ERROR; if (Cmp(proxy_class_name, imclass_name) == 0) { - Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); + Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } if (Cmp(proxy_class_name, module_class_name) == 0) { - Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); + Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), proxy_class_name); - f_proxy = NewFile(filen,"w"); - if(!f_proxy) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + f_proxy = NewFile(filen, "w"); + if (!f_proxy) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the proxy class file emitBanner(f_proxy); @@ -1757,8 +1736,8 @@ class CSHARP : public Language { Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); // Write out all the constants - if (Len(proxy_class_constants_code) != 0 ) - Printv(f_proxy, proxy_class_constants_code, NIL); + if (Len(proxy_class_constants_code) != 0) + Printv(f_proxy, proxy_class_constants_code, NIL); Printf(f_proxy, "}\n"); addCloseNamespace(namespce, f_proxy); @@ -1770,32 +1749,34 @@ class CSHARP : public Language { downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ if (GetFlag(n, "feature:javadowncast")) { - String *norm_name = SwigType_namestr(Getattr(n, "name")); + String *norm_name = SwigType_namestr(Getattr(n, "name")); - Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", - proxy_class_name, proxy_class_name); + Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, proxy_class_name); - Wrapper *dcast_wrap = NewWrapper(); + Wrapper *dcast_wrap = NewWrapper(); - Printf(dcast_wrap->def, "SWIGEXPORT jobject SWIGSTDCALL CSharp_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", - proxy_class_name); - Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); - Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); - Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); - Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); - Printf(dcast_wrap->code, " return jresult;\n"); - Printf(dcast_wrap->code, "}\n"); + Printf(dcast_wrap->def, "SWIGEXPORT jobject SWIGSTDCALL CSharp_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", + proxy_class_name); + Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); + Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); + Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); + Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); + Printf(dcast_wrap->code, " return jresult;\n"); + Printf(dcast_wrap->code, "}\n"); - Wrapper_print(dcast_wrap, f_wrappers); - DelWrapper(dcast_wrap); + Wrapper_print(dcast_wrap, f_wrappers); + DelWrapper(dcast_wrap); } emitDirectorExtraMethods(n); - Delete(proxy_class_name); proxy_class_name = NULL; - Delete(destructor_call); destructor_call = NULL; - Delete(proxy_class_constants_code); proxy_class_constants_code = NULL; + Delete(proxy_class_name); + proxy_class_name = NULL; + Delete(destructor_call); + destructor_call = NULL; + Delete(proxy_class_constants_code); + proxy_class_constants_code = NULL; } return SWIG_OK; @@ -1811,8 +1792,8 @@ class CSHARP : public Language { if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); - Setattr(n,"proxyfuncname", Getattr(n, "sym:name")); - Setattr(n,"imfuncname", intermediary_function_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); Delete(overloaded_name); } @@ -1831,8 +1812,8 @@ class CSHARP : public Language { if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); - Setattr(n,"proxyfuncname", Getattr(n,"sym:name")); - Setattr(n,"imfuncname", intermediary_function_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); Delete(overloaded_name); } @@ -1854,30 +1835,33 @@ class CSHARP : public Language { * ----------------------------------------------------------------------------- */ void proxyClassFunctionHandler(Node *n) { - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *intermediary_function_name = Getattr(n,"imfuncname"); - String *proxy_function_name = Getattr(n,"proxyfuncname"); - String *tm; - Parm *p; - Parm *last_parm = 0; - int i; - String *imcall = NewString(""); - String *return_type = NewString(""); - String *function_code = NewString(""); - bool setter_flag = false; + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *intermediary_function_name = Getattr(n, "imfuncname"); + String *proxy_function_name = Getattr(n, "proxyfuncname"); + String *tm; + Parm *p; + Parm *last_parm = 0; + int i; + String *imcall = NewString(""); + String *return_type = NewString(""); + String *function_code = NewString(""); + bool setter_flag = false; - if(!proxy_flag) return; + if (!proxy_flag) + return; // Wrappers not wanted for some methods where the parameters cannot be overloaded in C# - if (Getattr(n, "overload:ignore")) return; + if (Getattr(n, "overload:ignore")) + return; // Don't generate proxy method for additional explicitcall method used in directors - if (GetFlag(n, "explicitcall")) return; + if (GetFlag(n, "explicitcall")) + return; if (l) { - if (SwigType_type(Getattr(l,"type")) == T_VOID) { - l = nextSibling(l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } @@ -1887,59 +1871,58 @@ class CSHARP : public Language { Swig_typemap_attach_parms("csin", l, NULL); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { + if ((tm = Swig_typemap_lookup_new("cstype", n, "", 0))) { // Note that in the case of polymorphic (covariant) return types, the method's return type is changed to be the base of the C++ return type - SwigType *covariant = Getattr(n,"covariant"); - String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap + SwigType *covariant = Getattr(n, "covariant"); + String *cstypeout = Getattr(n, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap if (cstypeout) - tm = cstypeout; + tm = cstypeout; substituteClassname(covariant ? covariant : t, tm); Printf(return_type, "%s", tm); if (covariant) - Swig_warning(WARN_CSHARP_COVARIANT_RET, input_file, line_number, - "Covariant return types not supported in C#. Proxy method will return %s.\n", SwigType_str(covariant,0)); + Swig_warning(WARN_CSHARP_COVARIANT_RET, input_file, line_number, + "Covariant return types not supported in C#. Proxy method will return %s.\n", SwigType_str(covariant, 0)); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t, 0)); } - if(proxy_flag && wrapping_member_flag && !enum_constant_flag) { + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Properties setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0); } /* Start generating the proxy function */ - const String *outattributes = Getattr(n,"tmap:cstype:outattributes"); + const String *outattributes = Getattr(n, "tmap:cstype:outattributes"); if (outattributes) Printf(function_code, " %s\n", outattributes); - const String *csattributes = Getattr(n,"feature:cs:attributes"); + const String *csattributes = Getattr(n, "feature:cs:attributes"); if (csattributes) Printf(function_code, " %s\n", csattributes); - const String *methodmods = Getattr(n,"feature:cs:methodmodifiers"); + const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); if (methodmods) { if (is_smart_pointer()) { - // Smart pointer classes do not mirror the inheritance hierarchy of the underlying pointer type, so no virtual/override/new required. + // Smart pointer classes do not mirror the inheritance hierarchy of the underlying pointer type, so no virtual/override/new required. String *mmods = Copy(methodmods); - Replaceall(mmods, "override", ""); - Replaceall(mmods, "virtual", ""); - Replaceall(mmods, "new", ""); - Chop(mmods); // remove trailing whitespace - Printf(function_code, " %s ", mmods); + Replaceall(mmods, "override", ""); + Replaceall(mmods, "virtual", ""); + Replaceall(mmods, "new", ""); + Chop(mmods); // remove trailing whitespace + Printf(function_code, " %s ", mmods); Delete(mmods); } else { - Printf(function_code, " %s ", methodmods); + Printf(function_code, " %s ", methodmods); } } else { methodmods = (is_public(n) ? public_string : protected_string); Printf(function_code, " %s ", methodmods); if (!is_smart_pointer()) { - // Smart pointer classes do not mirror the inheritance hierarchy of the underlying pointer type, so no virtual/override/new required. - if (Getattr(n,"override")) - Printf(function_code, "override "); - else if (checkAttribute(n, "storage", "virtual")) - Printf(function_code, "virtual "); - if (Getattr(n, "hides")) - Printf(function_code, "new "); + // Smart pointer classes do not mirror the inheritance hierarchy of the underlying pointer type, so no virtual/override/new required. + if (Getattr(n, "override")) + Printf(function_code, "override "); + else if (checkAttribute(n, "storage", "virtual")) + Printf(function_code, "virtual "); + if (Getattr(n, "hides")) + Printf(function_code, "new "); } } if (static_flag) @@ -1955,162 +1938,155 @@ class CSHARP : public Language { int gencomma = !static_flag; /* Output each parameter */ - for (i = 0, p=l; p; i++) { + for (i = 0, p = l; p; i++) { /* Ignored varargs */ - if (checkAttribute(p,"varargs:ignore","1")) { - p = nextSibling(p); - continue; + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; } /* Ignored parameters */ - if (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); - continue; + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; } /* Ignore the 'this' argument for variable wrappers */ - if (!(variable_wrapper_flag && i==0)) - { - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); - last_parm = p; + if (!(variable_wrapper_flag && i == 0)) { + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); + last_parm = p; - /* Get the C# parameter type */ - if ((tm = Getattr(p,"tmap:cstype"))) { - substituteClassname(pt, tm); - String *inattributes = Getattr(p,"tmap:cstype:inattributes"); - Printf(param_type, "%s%s", inattributes ? (const String *)inattributes : empty_string, tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(pt,0)); - } + /* Get the C# parameter type */ + if ((tm = Getattr(p, "tmap:cstype"))) { + substituteClassname(pt, tm); + String *inattributes = Getattr(p, "tmap:cstype:inattributes"); + Printf(param_type, "%s%s", inattributes ? (const String *) inattributes : empty_string, tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0)); + } - if (gencomma) - Printf(imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = makeParameterName(n, p, i, setter_flag); + String *arg = makeParameterName(n, p, i, setter_flag); - // Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) - if ((tm = Getattr(p,"tmap:csin"))) { - substituteClassname(pt, tm); - Replaceall(tm, "$csinput", arg); - Printv(imcall, tm, NIL); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, - "No csin typemap defined for %s\n", SwigType_str(pt,0)); - } + // Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) + if ((tm = Getattr(p, "tmap:csin"))) { + substituteClassname(pt, tm); + Replaceall(tm, "$csinput", arg); + Printv(imcall, tm, NIL); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0)); + } - /* Add parameter to proxy function */ - if (gencomma >= 2) - Printf(function_code, ", "); - gencomma = 2; - Printf(function_code, "%s %s", param_type, arg); + /* Add parameter to proxy function */ + if (gencomma >= 2) + Printf(function_code, ", "); + gencomma = 2; + Printf(function_code, "%s %s", param_type, arg); - Delete(arg); - Delete(param_type); + Delete(arg); + Delete(param_type); } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } Printf(imcall, ")"); Printf(function_code, ")"); // Transform return type used in PInvoke function (in intermediary class) to type used in C# wrapper function (in proxy class) - if ((tm = Swig_typemap_lookup_new("csout",n,"",0))) { - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); + if ((tm = Swig_typemap_lookup_new("csout", n, "", 0))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); else - Replaceall(tm,"$owner","false"); + Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); // For director methods: generate code to selectively make a normal polymorphic call or // an explicit method call - needed to prevent infinite recursion calls in director methods. - Node *explicit_n = Getattr(n,"explicitcallnode"); + Node *explicit_n = Getattr(n, "explicitcallnode"); if (explicit_n) { String *ex_overloaded_name = getOverloadedName(explicit_n); String *ex_intermediary_function_name = Swig_name_member(proxy_class_name, ex_overloaded_name); - String *ex_imcall = Copy(imcall); - Replaceall(ex_imcall, intermediary_function_name, ex_intermediary_function_name); + String *ex_imcall = Copy(imcall); + Replaceall(ex_imcall, intermediary_function_name, ex_intermediary_function_name); - String *excode = NewString(""); - if (!Cmp(return_type, "void")) - Printf(excode, "if (this.GetType() == typeof(%s)) %s; else %s", proxy_class_name, imcall, ex_imcall); - else - Printf(excode, "((this.GetType() == typeof(%s)) ? %s : %s)", proxy_class_name, imcall, ex_imcall); + String *excode = NewString(""); + if (!Cmp(return_type, "void")) + Printf(excode, "if (this.GetType() == typeof(%s)) %s; else %s", proxy_class_name, imcall, ex_imcall); + else + Printf(excode, "((this.GetType() == typeof(%s)) ? %s : %s)", proxy_class_name, imcall, ex_imcall); - Clear(imcall); - Printv(imcall, excode, NIL); + Clear(imcall); + Printv(imcall, excode, NIL); Delete(ex_overloaded_name); - Delete(excode); + Delete(excode); } Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csout", n); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csout typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0)); } - if(proxy_flag && wrapping_member_flag && !enum_constant_flag) { + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Properties - if (generate_property_declaration_flag) { // Ensure the declaration is generated just once should the property contain both a set and get + if (generate_property_declaration_flag) { // Ensure the declaration is generated just once should the property contain both a set and get // Get the C# variable type - obtained differently depending on whether a setter is required. String *variable_type = return_type; if (setter_flag) { - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p,"type"); - if ((tm = Getattr(p,"tmap:cstype"))) { + p = last_parm; // (last parameter is the only parameter for properties) + SwigType *pt = Getattr(p, "type"); + if ((tm = Getattr(p, "tmap:cstype"))) { substituteClassname(pt, tm); variable_type = tm; } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarin typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); } } - const String *csattributes = Getattr(n,"feature:cs:attributes"); - if (csattributes) - Printf(proxy_class_code, " %s\n", csattributes); - const String *methodmods = Getattr(n,"feature:cs:methodmodifiers"); + const String *csattributes = Getattr(n, "feature:cs:attributes"); + if (csattributes) + Printf(proxy_class_code, " %s\n", csattributes); + const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); if (!methodmods) methodmods = (is_public(n) ? public_string : protected_string); Printf(proxy_class_code, " %s %s%s %s {", methodmods, static_flag ? "static " : "", variable_type, variable_name); } generate_property_declaration_flag = false; - if(setter_flag) { - // Setter method - Swig_typemap_attach_parms("csvarin", l, NULL); - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p,"type"); - if ((tm = Getattr(p,"tmap:csvarin"))) { - substituteClassname(pt, tm); - Replaceall(tm, "$imcall", imcall); - excodeSubstitute(n, tm, "csvarin", p); - Printf(proxy_class_code, "%s", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarin typemap defined for %s\n", SwigType_str(pt,0)); - } + if (setter_flag) { + // Setter method + Swig_typemap_attach_parms("csvarin", l, NULL); + p = last_parm; // (last parameter is the only parameter for properties) + SwigType *pt = Getattr(p, "type"); + if ((tm = Getattr(p, "tmap:csvarin"))) { + substituteClassname(pt, tm); + Replaceall(tm, "$imcall", imcall); + excodeSubstitute(n, tm, "csvarin", p); + Printf(proxy_class_code, "%s", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); + } } else { - // Getter method - if ((tm = Swig_typemap_lookup_new("csvarout",n,"",0))) { - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); - else - Replaceall(tm,"$owner","false"); - substituteClassname(t, tm); - Replaceall(tm, "$imcall", imcall); - excodeSubstitute(n, tm, "csvarout", n); - Printf(proxy_class_code, "%s", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarout typemap defined for %s\n", SwigType_str(t,0)); - } + // Getter method + if ((tm = Swig_typemap_lookup_new("csvarout", n, "", 0))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); + else + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$imcall", imcall); + excodeSubstitute(n, tm, "csvarout", n); + Printf(proxy_class_code, "%s", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarout typemap defined for %s\n", SwigType_str(t, 0)); + } } } else { // Normal function call - Printf(function_code, " %s\n\n", tm ? (const String *)tm : empty_string); + Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string); Printv(proxy_class_code, function_code, NIL); } @@ -2125,12 +2101,12 @@ class CSHARP : public Language { virtual int constructorHandler(Node *n) { - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - int i; - String *function_code = NewString(""); - bool feature_director = (parentNode(n) && Swig_directorclass(n)); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + int i; + String *function_code = NewString(""); + bool feature_director = (parentNode(n) && Swig_directorclass(n)); Language::constructorHandler(n); @@ -2138,15 +2114,15 @@ class CSHARP : public Language { if (Getattr(n, "overload:ignore")) return SWIG_OK; - if(proxy_flag) { + if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *mangled_overname = Swig_name_construct(overloaded_name); String *imcall = NewString(""); - const String *csattributes = Getattr(n,"feature:cs:attributes"); + const String *csattributes = Getattr(n, "feature:cs:attributes"); if (csattributes) - Printf(function_code, " %s\n", csattributes); - const String *methodmods = Getattr(n,"feature:cs:methodmodifiers"); + Printf(function_code, " %s\n", csattributes); + const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string); Printf(function_code, " %s %s(", methodmods, proxy_class_name); Printv(imcall, imclass_name, ".", mangled_overname, "(", NIL); @@ -2161,57 +2137,55 @@ class CSHARP : public Language { int gencomma = 0; /* Output each parameter */ - for (i = 0, p=l; p; i++) { + for (i = 0, p = l; p; i++) { - /* Ignored varargs */ - if (checkAttribute(p,"varargs:ignore","1")) { - p = nextSibling(p); - continue; - } + /* Ignored varargs */ + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; + } - /* Ignored parameters */ - if (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); - continue; - } + /* Ignored parameters */ + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); - /* Get the C# parameter type */ - if ((tm = Getattr(p,"tmap:cstype"))) { - substituteClassname(pt, tm); - String *inattributes = Getattr(p,"tmap:cstype:inattributes"); - Printf(param_type, "%s%s", inattributes ? (const String *)inattributes : empty_string, tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(pt,0)); - } + /* Get the C# parameter type */ + if ((tm = Getattr(p, "tmap:cstype"))) { + substituteClassname(pt, tm); + String *inattributes = Getattr(p, "tmap:cstype:inattributes"); + Printf(param_type, "%s%s", inattributes ? (const String *) inattributes : empty_string, tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0)); + } - if (gencomma) - Printf(imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = makeParameterName(n, p, i, false); + String *arg = makeParameterName(n, p, i, false); - // Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) - if ((tm = Getattr(p,"tmap:csin"))) { - substituteClassname(pt, tm); - Replaceall(tm, "$csinput", arg); - Printv(imcall, tm, NIL); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, - "No csin typemap defined for %s\n", SwigType_str(pt,0)); - } + // Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) + if ((tm = Getattr(p, "tmap:csin"))) { + substituteClassname(pt, tm); + Replaceall(tm, "$csinput", arg); + Printv(imcall, tm, NIL); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0)); + } - /* Add parameter to proxy function */ - if(gencomma) - Printf(function_code, ", "); - Printf(function_code, "%s %s", param_type, arg); - ++gencomma; + /* Add parameter to proxy function */ + if (gencomma) + Printf(function_code, ", "); + Printf(function_code, "%s %s", param_type, arg); + ++gencomma; - Delete(arg); - Delete(param_type); - p = Getattr(p,"tmap:in:next"); + Delete(arg); + Delete(param_type); + p = Getattr(p, "tmap:in:next"); } Printf(imcall, ")"); @@ -2220,23 +2194,24 @@ class CSHARP : public Language { /* Insert the csconstruct typemap, doing the replacement for $directorconnect, as needed */ Hash *attributes = NewHash(); - String *construct_tm = Copy(typemapLookup("csconstruct", Getattr(n,"name"), - WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes)); + String *construct_tm = Copy(typemapLookup("csconstruct", Getattr(n, "name"), + WARN_CSHARP_TYPEMAP_CSCONSTRUCT_UNDEF, attributes)); if (construct_tm) { - if (!feature_director) { - Replaceall(construct_tm, "$directorconnect", ""); - } else { - String *connect_attr = Getattr(attributes, "tmap:csconstruct:directorconnect"); + if (!feature_director) { + Replaceall(construct_tm, "$directorconnect", ""); + } else { + String *connect_attr = Getattr(attributes, "tmap:csconstruct:directorconnect"); - if (connect_attr) { - Replaceall(construct_tm, "$directorconnect", connect_attr); - } else { - Swig_warning(WARN_CSHARP_NO_DIRECTORCONNECT_ATTR, input_file, line_number, "\"directorconnect\" attribute missing in %s \"csconstruct\" typemap.\n", Getattr(n,"name")); - Replaceall(construct_tm, "$directorconnect", ""); - } - } + if (connect_attr) { + Replaceall(construct_tm, "$directorconnect", connect_attr); + } else { + Swig_warning(WARN_CSHARP_NO_DIRECTORCONNECT_ATTR, input_file, line_number, "\"directorconnect\" attribute missing in %s \"csconstruct\" typemap.\n", + Getattr(n, "name")); + Replaceall(construct_tm, "$directorconnect", ""); + } + } - Printv(function_code, " ", construct_tm, NIL); + Printv(function_code, " ", construct_tm, NIL); } Replaceall(function_code, "$imcall", imcall); @@ -2258,9 +2233,9 @@ class CSHARP : public Language { virtual int destructorHandler(Node *n) { Language::destructorHandler(n); - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); - if(proxy_flag) { + if (proxy_flag) { Printv(destructor_call, imclass_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); } return SWIG_OK; @@ -2273,7 +2248,7 @@ class CSHARP : public Language { virtual int membervariableHandler(Node *n) { generate_property_declaration_flag = true; - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; variable_wrapper_flag = true; Language::membervariableHandler(n); @@ -2295,7 +2270,7 @@ class CSHARP : public Language { bool static_const_member_flag = (Getattr(n, "value") == 0); generate_property_declaration_flag = true; - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; static_flag = true; Language::staticmembervariableHandler(n); @@ -2303,7 +2278,7 @@ class CSHARP : public Language { static_flag = false; generate_property_declaration_flag = false; - if(static_const_member_flag) + if (static_const_member_flag) Printf(proxy_class_code, "\n }\n\n"); return SWIG_OK; @@ -2314,7 +2289,7 @@ class CSHARP : public Language { * ---------------------------------------------------------------------- */ virtual int memberconstantHandler(Node *n) { - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; Language::memberconstantHandler(n); wrapping_member_flag = false; @@ -2330,10 +2305,10 @@ class CSHARP : public Language { /* A C# HandleRef is used for all classes in the SWIG intermediary class. * The intermediary class methods are thus mangled when overloaded to give * a unique name. */ - String *overloaded_name = NewStringf("%s", Getattr(n,"sym:name")); + String *overloaded_name = NewStringf("%s", Getattr(n, "sym:name")); - if (Getattr(n,"sym:overloaded")) { - Printv(overloaded_name, Getattr(n,"sym:overname"), NIL); + if (Getattr(n, "sym:overloaded")) { + Printv(overloaded_name, Getattr(n, "sym:overname"), NIL); } return overloaded_name; @@ -2344,24 +2319,24 @@ class CSHARP : public Language { * ----------------------------------------------------------------------------- */ void moduleClassFunctionHandler(Node *n) { - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - Parm *last_parm = 0; - int i; - String *imcall = NewString(""); - String *return_type = NewString(""); - String *function_code = NewString(""); - int num_arguments = 0; - int num_required = 0; - String *overloaded_name = getOverloadedName(n); - String *func_name = NULL; - bool setter_flag = false; + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + Parm *last_parm = 0; + int i; + String *imcall = NewString(""); + String *return_type = NewString(""); + String *function_code = NewString(""); + int num_arguments = 0; + int num_required = 0; + String *overloaded_name = getOverloadedName(n); + String *func_name = NULL; + bool setter_flag = false; if (l) { - if (SwigType_type(Getattr(l,"type")) == T_VOID) { - l = nextSibling(l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } @@ -2370,94 +2345,91 @@ class CSHARP : public Language { Swig_typemap_attach_parms("csin", l, NULL); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("cstype",n,"",0))) { - String *cstypeout = Getattr(n,"tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap + if ((tm = Swig_typemap_lookup_new("cstype", n, "", 0))) { + String *cstypeout = Getattr(n, "tmap:cstype:out"); // the type in the cstype typemap's out attribute overrides the type in the typemap if (cstypeout) - tm = cstypeout; + tm = cstypeout; substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(t, 0)); } /* Change function name for global variables */ if (proxy_flag && global_variable_flag) { // Capitalize the first letter in the variable to create the getter/setter function name func_name = NewString(""); - setter_flag = (Cmp(Getattr(n,"sym:name"), Swig_name_set(variable_name)) == 0); - if(setter_flag) - Printf(func_name,"set"); - else - Printf(func_name,"get"); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(variable_name)) == 0); + if (setter_flag) + Printf(func_name, "set"); + else + Printf(func_name, "get"); Putc(toupper((int) *Char(variable_name)), func_name); - Printf(func_name, "%s", Char(variable_name)+1); + Printf(func_name, "%s", Char(variable_name) + 1); } else { - func_name = Copy(Getattr(n,"sym:name")); + func_name = Copy(Getattr(n, "sym:name")); } /* Start generating the function */ - const String *outattributes = Getattr(n,"tmap:cstype:outattributes"); + const String *outattributes = Getattr(n, "tmap:cstype:outattributes"); if (outattributes) Printf(function_code, " %s\n", outattributes); - const String *csattributes = Getattr(n,"feature:cs:attributes"); + const String *csattributes = Getattr(n, "feature:cs:attributes"); if (csattributes) Printf(function_code, " %s\n", csattributes); - const String *methodmods = Getattr(n,"feature:cs:methodmodifiers"); + const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string); Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name); Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); int gencomma = 0; /* Output each parameter */ - for (i = 0, p=l; i < num_arguments; i++) { + for (i = 0, p = l; i < num_arguments; i++) { /* Ignored parameters */ - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); last_parm = p; /* Get the C# parameter type */ - if ((tm = Getattr(p,"tmap:cstype"))) { - substituteClassname(pt, tm); - String *inattributes = Getattr(p,"tmap:cstype:inattributes"); - Printf(param_type, "%s%s", inattributes ? (const String *)inattributes : empty_string, tm); + if ((tm = Getattr(p, "tmap:cstype"))) { + substituteClassname(pt, tm); + String *inattributes = Getattr(p, "tmap:cstype:inattributes"); + Printf(param_type, "%s%s", inattributes ? (const String *) inattributes : empty_string, tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0)); } if (gencomma) - Printf(imcall, ", "); + Printf(imcall, ", "); String *arg = makeParameterName(n, p, i, setter_flag); // Use typemaps to transform type used in C# wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) - if ((tm = Getattr(p,"tmap:csin"))) { - substituteClassname(pt, tm); - Replaceall(tm, "$csinput", arg); - Printv(imcall, tm, NIL); + if ((tm = Getattr(p, "tmap:csin"))) { + substituteClassname(pt, tm); + Replaceall(tm, "$csinput", arg); + Printv(imcall, tm, NIL); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, - "No csin typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSIN_UNDEF, input_file, line_number, "No csin typemap defined for %s\n", SwigType_str(pt, 0)); } /* Add parameter to module class function */ if (gencomma >= 2) - Printf(function_code, ", "); + Printf(function_code, ", "); gencomma = 2; Printf(function_code, "%s %s", param_type, arg); - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); Delete(arg); Delete(param_type); } @@ -2466,78 +2438,74 @@ class CSHARP : public Language { Printf(function_code, ")"); // Transform return type used in PInvoke function (in intermediary class) to type used in C# wrapper function (in module class) - if ((tm = Swig_typemap_lookup_new("csout",n,"",0))) { - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); + if ((tm = Swig_typemap_lookup_new("csout", n, "", 0))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); else - Replaceall(tm,"$owner","false"); + Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); Replaceall(tm, "$imcall", imcall); excodeSubstitute(n, tm, "csout", n); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csout typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csout typemap defined for %s\n", SwigType_str(t, 0)); } if (proxy_flag && global_variable_flag) { // Properties - if (generate_property_declaration_flag) { // Ensure the declaration is generated just once should the property contain both a set and get + if (generate_property_declaration_flag) { // Ensure the declaration is generated just once should the property contain both a set and get // Get the C# variable type - obtained differently depending on whether a setter is required. String *variable_type = return_type; if (setter_flag) { - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p,"type"); - if ((tm = Getattr(p,"tmap:cstype"))) { + p = last_parm; // (last parameter is the only parameter for properties) + SwigType *pt = Getattr(p, "type"); + if ((tm = Getattr(p, "tmap:cstype"))) { substituteClassname(pt, tm); variable_type = tm; } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarin typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); } } - const String *csattributes = Getattr(n,"feature:cs:attributes"); - if (csattributes) - Printf(module_class_code, " %s\n", csattributes); - const String *methodmods = Getattr(n,"feature:cs:methodmodifiers"); + const String *csattributes = Getattr(n, "feature:cs:attributes"); + if (csattributes) + Printf(module_class_code, " %s\n", csattributes); + const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); if (!methodmods) methodmods = (is_public(n) ? public_string : protected_string); Printf(module_class_code, " %s static %s %s {", methodmods, variable_type, variable_name); } generate_property_declaration_flag = false; - if(setter_flag) { - // Setter method - Swig_typemap_attach_parms("csvarin", l, NULL); - p = last_parm; // (last parameter is the only parameter for properties) - SwigType *pt = Getattr(p,"type"); - if ((tm = Getattr(p,"tmap:csvarin"))) { - substituteClassname(pt, tm); - Replaceall(tm, "$imcall", imcall); - excodeSubstitute(n, tm, "csvarin", p); - Printf(module_class_code, "%s", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarin typemap defined for %s\n", SwigType_str(pt,0)); - } + if (setter_flag) { + // Setter method + Swig_typemap_attach_parms("csvarin", l, NULL); + p = last_parm; // (last parameter is the only parameter for properties) + SwigType *pt = Getattr(p, "type"); + if ((tm = Getattr(p, "tmap:csvarin"))) { + substituteClassname(pt, tm); + Replaceall(tm, "$imcall", imcall); + excodeSubstitute(n, tm, "csvarin", p); + Printf(module_class_code, "%s", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarin typemap defined for %s\n", SwigType_str(pt, 0)); + } } else { - // Getter method - if ((tm = Swig_typemap_lookup_new("csvarout",n,"",0))) { - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); - else - Replaceall(tm,"$owner","false"); - substituteClassname(t, tm); - Replaceall(tm, "$imcall", imcall); - excodeSubstitute(n, tm, "csvarout", n); - Printf(module_class_code, "%s", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, - "No csvarout typemap defined for %s\n", SwigType_str(t,0)); - } + // Getter method + if ((tm = Swig_typemap_lookup_new("csvarout", n, "", 0))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); + else + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$imcall", imcall); + excodeSubstitute(n, tm, "csvarout", n); + Printf(module_class_code, "%s", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No csvarout typemap defined for %s\n", SwigType_str(t, 0)); + } } } else { // Normal function call - Printf(function_code, " %s\n\n", tm ? (const String *)tm : empty_string); + Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string); Printv(module_class_code, function_code, NIL); } @@ -2557,17 +2525,17 @@ class CSHARP : public Language { *--------------------------------------------------------------------*/ EnumFeature decodeEnumFeature(Node *n) { - EnumFeature enum_feature = TypeunsafeEnum; - String *feature = Getattr(n,"feature:cs:enum"); - if (feature) { - if (Cmp(feature, "simple") == 0) - enum_feature = SimpleEnum; - else if (Cmp(feature, "typesafe") == 0) - enum_feature = TypesafeEnum; - else if (Cmp(feature, "proper") == 0) - enum_feature = ProperEnum; - } - return enum_feature; + EnumFeature enum_feature = TypeunsafeEnum; + String *feature = Getattr(n, "feature:cs:enum"); + if (feature) { + if (Cmp(feature, "simple") == 0) + enum_feature = SimpleEnum; + else if (Cmp(feature, "typesafe") == 0) + enum_feature = TypesafeEnum; + else if (Cmp(feature, "proper") == 0) + enum_feature = ProperEnum; + } + return enum_feature; } /* ----------------------------------------------------------------------- @@ -2582,29 +2550,29 @@ class CSHARP : public Language { * ------------------------------------------------------------------------ */ String *enumValue(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); // Check for the %csconstvalue feature - String *value = Getattr(n,"feature:cs:constvalue"); + String *value = Getattr(n, "feature:cs:constvalue"); if (!value) { // The %csconst feature determines how the constant value is obtained - int const_feature_flag = GetFlag(n,"feature:cs:const"); + int const_feature_flag = GetFlag(n, "feature:cs:const"); if (const_feature_flag) { - // Use the C syntax to make a true C# constant and hope that it compiles as C# code - value = Getattr(n,"enumvalue") ? Copy(Getattr(n,"enumvalue")) : Copy(Getattr(n,"enumvalueex")); + // Use the C syntax to make a true C# constant and hope that it compiles as C# code + value = Getattr(n, "enumvalue") ? Copy(Getattr(n, "enumvalue")) : Copy(Getattr(n, "enumvalueex")); } else { - // Get the enumvalue from a PINVOKE call - if (!getCurrentClass() || !cparse_cplusplus) { - // Strange hack to change the name - Setattr(n,"name",Getattr(n,"value")); /* for wrapping of enums in a namespace when emit_action is used */ - constantWrapper(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); - } else { - memberconstantHandler(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); - } + // Get the enumvalue from a PINVOKE call + if (!getCurrentClass() || !cparse_cplusplus) { + // Strange hack to change the name + Setattr(n, "name", Getattr(n, "value")); /* for wrapping of enums in a namespace when emit_action is used */ + constantWrapper(n); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); + } else { + memberconstantHandler(n); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); + } } } return value; @@ -2618,19 +2586,19 @@ class CSHARP : public Language { Node *enum_name = NULL; Node *n = enumLookup(t); if (n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); if (symname) { - // Add in class scope when referencing enum if not a global enum - String *scopename_prefix = Swig_scopename_prefix(Getattr(n,"name")); - String *proxyname = 0; - if (scopename_prefix) { - proxyname = getProxyName(scopename_prefix); - } - if (proxyname) - enum_name = NewStringf("%s.%s", proxyname, symname); - else - enum_name = NewStringf("%s", symname); - Delete(scopename_prefix); + // Add in class scope when referencing enum if not a global enum + String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + String *proxyname = 0; + if (scopename_prefix) { + proxyname = getProxyName(scopename_prefix); + } + if (proxyname) + enum_name = NewStringf("%s.%s", proxyname, symname); + else + enum_name = NewStringf("%s", symname); + Delete(scopename_prefix); } } @@ -2693,21 +2661,20 @@ class CSHARP : public Language { if (SwigType_isenum(classnametype)) { String *enumname = getEnumName(classnametype); if (enumname) - Replaceall(tm, classnamespecialvariable, enumname); + Replaceall(tm, classnamespecialvariable, enumname); else - Replaceall(tm, classnamespecialvariable, NewStringf("int")); + Replaceall(tm, classnamespecialvariable, NewStringf("int")); } else { String *classname = getProxyName(classnametype); if (classname) { - Replaceall(tm, classnamespecialvariable, classname); // getProxyName() works for pointers to classes too - } - else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. - String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); - Replaceall(tm, classnamespecialvariable, descriptor); + Replaceall(tm, classnamespecialvariable, classname); // getProxyName() works for pointers to classes too + } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. + String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); + Replaceall(tm, classnamespecialvariable, descriptor); - // Add to hash table so that the type wrapper classes can be created later - Setattr(swig_types_hash, descriptor, classnametype); - Delete(descriptor); + // Add to hash table so that the type wrapper classes can be created later + Setattr(swig_types_hash, descriptor, classnametype); + Delete(descriptor); } } } @@ -2727,21 +2694,21 @@ class CSHARP : public Language { String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) { String *arg = 0; - String *pn = Getattr(p,"name"); + String *pn = Getattr(p, "name"); if (setter) { // Note that in C# property setter names must always be called 'value' arg = NewString("value"); } else { // Use C parameter name unless it is a duplicate or an empty parameter name int count = 0; - ParmList *plist = Getattr(n,"parms"); + ParmList *plist = Getattr(n, "parms"); while (plist) { - if ((Cmp(pn, Getattr(plist,"name")) == 0)) - count++; - plist = nextSibling(plist); + if ((Cmp(pn, Getattr(plist, "name")) == 0)) + count++; + plist = nextSibling(plist); } - String *wrn = pn ? Swig_name_warning(p,0,pn,0) : 0; - arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d",arg_num) : Copy(pn); + String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; + arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); } return arg; @@ -2754,13 +2721,14 @@ class CSHARP : public Language { void emitTypeWrapperClass(String *classname, SwigType *type) { String *swigtype = NewString(""); String *filen = NewStringf("%s%s.cs", SWIG_output_directory(), classname); - File *f_swigtype = NewFile(filen,"w"); - if(!f_swigtype) { + File *f_swigtype = NewFile(filen, "w"); + if (!f_swigtype) { FileErrorDisplay(filen); SWIG_exit(EXIT_FAILURE); - } + } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the type wrapper class file emitBanner(f_swigtype); @@ -2772,32 +2740,20 @@ class CSHARP : public Language { const String *pure_interfaces = typemapLookup("csinterfaces", type, WARN_NONE); // Emit the class - Printv(swigtype, - typemapLookup("csimports", type, WARN_NONE), // Import statements - "\n", - NIL); + Printv(swigtype, typemapLookup("csimports", type, WARN_NONE), // Import statements + "\n", NIL); // Class attributes const String *csattributes = typemapLookup("csattributes", type, WARN_NONE); if (csattributes && *Char(csattributes)) Printf(swigtype, "%s\n", csattributes); - Printv(swigtype, - typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " $csclassname", // Class name and base class - (*Char(pure_baseclass) || *Char(pure_interfaces)) ? - " : " : - "", - pure_baseclass, - ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces - ", " : - "", - pure_interfaces, - " {", - typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class - typemapLookup("cscode", type, WARN_NONE), // extra C# code - "}\n", - NIL); + Printv(swigtype, typemapLookup("csclassmodifiers", type, WARN_CSHARP_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " $csclassname", // Class name and base class + (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass, ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces + ", " : "", pure_interfaces, " {", typemapLookup("csbody", type, WARN_CSHARP_TYPEMAP_CSBODY_UNDEF), // main body of class + typemapLookup("cscode", type, WARN_NONE), // extra C# code + "}\n", NIL); Replaceall(swigtype, "$csclassname", classname); Replaceall(swigtype, "$module", module_class_name); @@ -2816,20 +2772,20 @@ class CSHARP : public Language { * typemapLookup() * ----------------------------------------------------------------------------- */ - const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes=NULL) { + const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { String *tm = NULL; const String *code = NULL; - if((tm = Swig_typemap_search(op, type, NULL, NULL))) { - code = Getattr(tm,"code"); + if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { + code = Getattr(tm, "code"); if (typemap_attributes) - Swig_typemap_attach_kwargs(tm,op,typemap_attributes); + Swig_typemap_attach_kwargs(tm, op, typemap_attributes); } if (!code) { code = empty_string; if (warning != WARN_NONE) - Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); + Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); } return code ? code : empty_string; @@ -2837,7 +2793,7 @@ class CSHARP : public Language { /* ----------------------------------------------------------------------------- * addThrows() - // TODO: remove + // TODO: remove * ----------------------------------------------------------------------------- */ void addThrows(Node *, const String *, Node *) { } @@ -2850,9 +2806,9 @@ class CSHARP : public Language { void canThrow(Node *n, const String *typemap, Node *parameter) { String *canthrow_attribute = NewStringf("tmap:%s:canthrow", typemap); - String *canthrow = Getattr(parameter,canthrow_attribute); + String *canthrow = Getattr(parameter, canthrow_attribute); if (canthrow) - Setattr(n,"csharp:canthrow", "1"); + Setattr(n, "csharp:canthrow", "1"); Delete(canthrow_attribute); } @@ -2867,11 +2823,11 @@ class CSHARP : public Language { void excodeSubstitute(Node *n, String *code, const String *typemap, Node *parameter) { String *excode_attribute = NewStringf("tmap:%s:excode", typemap); String *excode = Getattr(parameter, excode_attribute); - if (Getattr(n,"csharp:canthrow")) { + if (Getattr(n, "csharp:canthrow")) { int count = Replaceall(code, "$excode", excode); if (count < 1 || !excode) { - Swig_warning(WARN_CSHARP_EXCODE, input_file, line_number, - "C# exception may not be thrown - no $excode or excode attribute in '%s' typemap.\n", typemap); + Swig_warning(WARN_CSHARP_EXCODE, input_file, line_number, + "C# exception may not be thrown - no $excode or excode attribute in '%s' typemap.\n", typemap); } } else { Replaceall(code, "$excode", empty_string); @@ -2885,7 +2841,7 @@ class CSHARP : public Language { void addOpenNamespace(String *namspace, File *file) { if (namspace) - if(Len(namspace) > 0) + if (Len(namspace) > 0) Printf(file, "namespace %s {\n", namspace); } @@ -2895,7 +2851,7 @@ class CSHARP : public Language { void addCloseNamespace(String *namspace, File *file) { if (namspace) - if(Len(namspace) > 0) + if (Len(namspace) > 0) Printf(file, "\n}\n"); } @@ -2910,22 +2866,22 @@ class CSHARP : public Language { void emitDirectorUpcalls() { if (n_dmethods) { - Wrapper *w = NewWrapper(); - String *dmethod_data = NewString(""); - int n_methods = 0; - Iterator udata_iter; + Wrapper *w = NewWrapper(); + String *dmethod_data = NewString(""); + int n_methods = 0; + Iterator udata_iter; udata_iter = First(dmethods_seq); while (udata_iter.item) { - UpcallData *udata = udata_iter.item; - Printf(dmethod_data, " { \"%s\", \"%s\" }", Getattr(udata, "imclass_method"), Getattr(udata, "imclass_fdesc")); - ++n_methods; + UpcallData *udata = udata_iter.item; + Printf(dmethod_data, " { \"%s\", \"%s\" }", Getattr(udata, "imclass_method"), Getattr(udata, "imclass_fdesc")); + ++n_methods; - udata_iter = Next(udata_iter); + udata_iter = Next(udata_iter); - if (udata_iter.item) - Putc(',', dmethod_data); - Putc('\n', dmethod_data); + if (udata_iter.item) + Putc(',', dmethod_data); + Putc('\n', dmethod_data); } @@ -2943,8 +2899,7 @@ class CSHARP : public Language { * This is where the director connect method is * generated. *--------------------------------------------------------------------*/ - void emitDirectorExtraMethods(Node *n) - { + void emitDirectorExtraMethods(Node *n) { if (!Swig_directorclass(n)) return; @@ -2961,8 +2916,7 @@ class CSHARP : public Language { Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL CSharp_%s(void *objarg", swig_director_connect); Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", - sym_name, sym_name); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); // TODO: if statement not needed?? - Java too Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director("); @@ -2973,7 +2927,7 @@ class CSHARP : public Language { Printf(code_wrap->def, ", "); if (i != first_class_dmethod) - Printf(code_wrap->code, ", "); + Printf(code_wrap->code, ", "); Printf(code_wrap->def, "SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid); Printf(code_wrap->code, "callback%s", methid); Printf(imclass_class_code, ", %s.SwigDelegate%s_%s delegate%s", sym_name, sym_name, methid, methid); @@ -3000,41 +2954,41 @@ class CSHARP : public Language { * --------------------------------------------------------------- */ int classDirectorMethod(Node *n, Node *parent, String *super) { - String *empty_str = NewString(""); - String *classname = Getattr(parent, "sym:name"); - String *c_classname = Getattr(parent, "name"); - String *name = Getattr(n, "name"); - String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - SwigType *returntype = Getattr(n,"returntype"); - String *overloaded_name = getOverloadedName(n); - String *storage = Getattr(n, "storage"); - String *value = Getattr(n, "value"); - String *decl = Getattr(n, "decl"); - String *declaration = NewString(""); - String *tm; - Parm *p; - int i; - Wrapper *w = NewWrapper(); - ParmList *l = Getattr(n, "parms"); - bool is_void = !(Cmp(returntype, "void")); - String *qualified_return = NewString(""); - bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); - int status = SWIG_OK; - bool output_director = true; - String *dirclassname = directorClassName(parent); - String *qualified_name = NewStringf("%s::%s", dirclassname, name); - SwigType *c_ret_type = NULL; - String *jupcall_args = NewString(""); - String *imclass_dmethod; - String *callback_typedef_parms = NewString(""); - String *delegate_parms = NewString(""); - String *proxy_method_types = NewString(""); - String *callback_def = NewString(""); - String *callback_code = NewString(""); - String *imcall_args = NewString(""); - int gencomma = 0; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + String *empty_str = NewString(""); + String *classname = Getattr(parent, "sym:name"); + String *c_classname = Getattr(parent, "name"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + SwigType *returntype = Getattr(n, "returntype"); + String *overloaded_name = getOverloadedName(n); + String *storage = Getattr(n, "storage"); + String *value = Getattr(n, "value"); + String *decl = Getattr(n, "decl"); + String *declaration = NewString(""); + String *tm; + Parm *p; + int i; + Wrapper *w = NewWrapper(); + ParmList *l = Getattr(n, "parms"); + bool is_void = !(Cmp(returntype, "void")); + String *qualified_return = NewString(""); + bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); + int status = SWIG_OK; + bool output_director = true; + String *dirclassname = directorClassName(parent); + String *qualified_name = NewStringf("%s::%s", dirclassname, name); + SwigType *c_ret_type = NULL; + String *jupcall_args = NewString(""); + String *imclass_dmethod; + String *callback_typedef_parms = NewString(""); + String *delegate_parms = NewString(""); + String *proxy_method_types = NewString(""); + String *callback_def = NewString(""); + String *callback_code = NewString(""); + String *imcall_args = NewString(""); + int gencomma = 0; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; // Kludge Alert: functionWrapper sets sym:overload properly, but it // isn't at this point, so we have to manufacture it ourselves. At least @@ -3048,49 +3002,48 @@ class CSHARP : public Language { qualified_return = SwigType_rcaststr(returntype, "c_result"); if (!is_void && !ignored_method) { - if (!SwigType_isclass(returntype)) { - if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); - } else { - String *base_typename = SwigType_base(returntype); - String *resolved_typename = SwigType_typedef_resolve_all(base_typename); - Symtab *symtab = Getattr(n, "sym:symtab"); - Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + String *base_typename = SwigType_base(returntype); + String *resolved_typename = SwigType_typedef_resolve_all(base_typename); + Symtab *symtab = Getattr(n, "sym:symtab"); + Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { - /* initialize pointers to something sane. Same for abstract - classes when a reference is returned. */ - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); - } else { - /* If returning a reference, initialize the pointer to a sane - default - if a C# exception occurs, then the pointer returns - something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + /* initialize pointers to something sane. Same for abstract + classes when a reference is returned. */ + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } else { + /* If returning a reference, initialize the pointer to a sane + default - if a C# exception occurs, then the pointer returns + something other than a NULL-initialized reference. */ + String *non_ref_type = Copy(returntype); - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), - "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); + /* Remove reference and const qualifiers */ + Replaceall(non_ref_type, "r.", ""); + Replaceall(non_ref_type, "q(const).", ""); + Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - Delete(non_ref_type); - } + Delete(non_ref_type); + } - Delete(base_typename); - Delete(resolved_typename); - } - } else { - SwigType *vt; + Delete(base_typename); + Delete(resolved_typename); + } + } else { + SwigType *vt; - vt = cplus_value_type(returntype); - if (!vt) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); - } else { - Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); - Delete(vt); - } - } + vt = cplus_value_type(returntype); + if (!vt) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); + Delete(vt); + } + } } /* Create the intermediate class wrapper */ @@ -3098,45 +3051,43 @@ class CSHARP : public Language { tm = Swig_typemap_lookup_new("imtype", tp, "", 0); if (tm) { - String *imtypeout = Getattr(tp,"tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap + String *imtypeout = Getattr(tp, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap if (imtypeout) tm = imtypeout; Printf(callback_def, " private %s SwigDirector%s(", tm, symname); if (!ignored_method) Printf(director_delegate_definitions, " public delegate %s", tm); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, - "No imtype typemap defined for %s\n", SwigType_str(returntype,0)); + Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0)); } - Parm *retpm = NewParmFromNode(returntype, empty_str, n); - + Parm *retpm = NewParmFromNode(returntype, empty_str, n); + if ((c_ret_type = Swig_typemap_lookup_new("ctype", retpm, "", 0))) { - if (!is_void && !ignored_method) { - String *jretval_decl = NewStringf("%s jresult", c_ret_type); - Wrapper_add_localv(w, "jresult", jretval_decl, " = 0", NIL); - Delete(jretval_decl); - } + if (!is_void && !ignored_method) { + String *jretval_decl = NewStringf("%s jresult", c_ret_type); + Wrapper_add_localv(w, "jresult", jretval_decl, " = 0", NIL); + Delete(jretval_decl); + } } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, - "No ctype typemap defined for %s\n", SwigType_str(returntype,0)); - output_director = false; + Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(returntype, 0)); + output_director = false; } Delete(retpm); } /* Go through argument list, attach lnames for arguments */ - for (i = 0, p=l; p; p = nextSibling(p), ++i) { + for (i = 0, p = l; p; p = nextSibling(p), ++i) { String *arg = Getattr(p, "name"); String *lname = NewString(""); if (!arg && Cmp(Getattr(p, "type"), "void")) { - lname = NewStringf("arg%d", i); - Setattr(p, "name", lname); + lname = NewStringf("arg%d", i); + Setattr(p, "name", lname); } else - lname = arg; + lname = arg; Setattr(p, "lname", lname); } @@ -3156,11 +3107,11 @@ class CSHARP : public Language { if (!pure_virtual) { String *super_call = Swig_method_call(super, l); if (is_void) { - Printf(w->code, "%s;\n", super_call); + Printf(w->code, "%s;\n", super_call); if (!ignored_method) Printf(w->code, "return;\n"); } else { - Printf(w->code, "return %s;\n", super_call); + Printf(w->code, "return %s;\n", super_call); } Delete(super_call); } else { @@ -3171,17 +3122,17 @@ class CSHARP : public Language { Printf(w->code, "} else {\n"); /* Go through argument list, convert from native to Java */ - for (p=l; p; /* empty */) { + for (p = l; p; /* empty */ ) { /* Is this superfluous? */ - while (checkAttribute(p,"tmap:directorin:numinputs","0")) { - p = Getattr(p,"tmap:directorin:next"); + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Copy(Getattr(p,"name")); - String *c_param_type = NULL; - String *c_decl = NewString(""); - String *arg = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *ln = Copy(Getattr(p, "name")); + String *c_param_type = NULL; + String *c_decl = NewString(""); + String *arg = NewString(""); Printf(arg, "j%s", ln); @@ -3191,110 +3142,106 @@ class CSHARP : public Language { /* And add to the upcall args */ if (gencomma > 0) - Printf(jupcall_args, ", "); + Printf(jupcall_args, ", "); Printf(jupcall_args, "%s", arg); /* Get parameter's intermediary C type */ if ((c_param_type = Getattr(p, "tmap:ctype"))) { - String *ctypeout = Getattr(p,"tmap:ctype:out"); // the type in the ctype typemap's out attribute overrides the type in the typemap - if (ctypeout) - c_param_type = ctypeout; + String *ctypeout = Getattr(p, "tmap:ctype:out"); // the type in the ctype typemap's out attribute overrides the type in the typemap + if (ctypeout) + c_param_type = ctypeout; - Parm *tp = NewParmFromNode(c_param_type, empty_str, n); - String *desc_tm = NULL; + Parm *tp = NewParmFromNode(c_param_type, empty_str, n); + String *desc_tm = NULL; - /* Add to local variables */ - Printf(c_decl, "%s %s", c_param_type, arg); + /* Add to local variables */ + Printf(c_decl, "%s %s", c_param_type, arg); if (!ignored_method) Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL); - /* Add input marshalling code */ - if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) - && (tm = Getattr(p, "tmap:directorin"))) { + /* Add input marshalling code */ + if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) + && (tm = Getattr(p, "tmap:directorin"))) { - Replaceall(tm,"$input", arg); + Replaceall(tm, "$input", arg); - if (Len(tm)) + if (Len(tm)) if (!ignored_method) - Printf(w->code,"%s\n", tm); + Printf(w->code, "%s\n", tm); - Delete(tm); + Delete(tm); - /* Add C type to callback typedef */ - if (gencomma > 0) - Printf(callback_typedef_parms, ", "); - Printf(callback_typedef_parms, "%s", c_param_type); + /* Add C type to callback typedef */ + if (gencomma > 0) + Printf(callback_typedef_parms, ", "); + Printf(callback_typedef_parms, "%s", c_param_type); - /* Add parameter to the intermediate class code if generating the - * intermediate's upcall code */ - if ((tm = Getattr(p, "tmap:imtype"))) { + /* Add parameter to the intermediate class code if generating the + * intermediate's upcall code */ + if ((tm = Getattr(p, "tmap:imtype"))) { - String *imtypeout = Getattr(p,"tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap - if (imtypeout) - tm = imtypeout; + String *imtypeout = Getattr(p, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap + if (imtypeout) + tm = imtypeout; - String *din = Copy(Getattr(p, "tmap:csdirectorin")); + String *din = Copy(Getattr(p, "tmap:csdirectorin")); - if (din) { - Replaceall(din, "$module", module_class_name); - Replaceall(din, "$imclassname", imclass_name); - substituteClassname(pt, din); - Replaceall(din, "$iminput", ln); + if (din) { + Replaceall(din, "$module", module_class_name); + Replaceall(din, "$imclassname", imclass_name); + substituteClassname(pt, din); + Replaceall(din, "$iminput", ln); - if (gencomma > 0) { - Printf(delegate_parms, ", "); - Printf(proxy_method_types, ", "); - Printf(imcall_args, ", "); - } - Printf(delegate_parms, "%s %s", tm, ln); + if (gencomma > 0) { + Printf(delegate_parms, ", "); + Printf(proxy_method_types, ", "); + Printf(imcall_args, ", "); + } + Printf(delegate_parms, "%s %s", tm, ln); - if (Cmp(din, ln)) { - Printv(imcall_args, din, NIL); - } else - Printv(imcall_args, ln, NIL); + if (Cmp(din, ln)) { + Printv(imcall_args, din, NIL); + } else + Printv(imcall_args, ln, NIL); - /* Get the C# parameter type */ - if ((tm = Getattr(p,"tmap:cstype"))) { - substituteClassname(pt, tm); - Printf(proxy_method_types, "typeof(%s)", tm); - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, - "No cstype typemap defined for %s\n", SwigType_str(pt,0)); - } - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, - "No csdirectorin typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - } - } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, - "No imtype typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - } + /* Get the C# parameter type */ + if ((tm = Getattr(p, "tmap:cstype"))) { + substituteClassname(pt, tm); + Printf(proxy_method_types, "typeof(%s)", tm); + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(pt, 0)); + } + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, "No csdirectorin typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + } + } else { + Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + } - p = Getattr(p, "tmap:directorin:next"); + p = Getattr(p, "tmap:directorin:next"); - Delete(desc_tm); - } else { - if (!desc_tm) { - Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); - p = nextSibling(p); - } else if (!tm) { - Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0)); - p = nextSibling(p); - } + Delete(desc_tm); + } else { + if (!desc_tm) { + Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); + p = nextSibling(p); + } else if (!tm) { + Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0)); + p = nextSibling(p); + } - output_director = false; - } + output_director = false; + } - Delete(tp); + Delete(tp); } else { - Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, - "No ctype typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - p = nextSibling(p); + Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + p = nextSibling(p); } gencomma++; @@ -3327,28 +3274,29 @@ class CSHARP : public Language { // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((tm = Swig_typemap_lookup_new("out",n,"",0))) + if ((tm = Swig_typemap_lookup_new("out", n, "", 0))) addThrows(n, "tmap:out", n); - if ((throw_parm_list = Getattr(n,"throws")) || Getattr(n,"throw")) { - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + int gencomma = 0; Append(w->def, " throw("); Append(declaration, " throw("); - if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { - addThrows(n, "tmap:throws", p); + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + addThrows(n, "tmap:throws", p); - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } - Printf(w->def, "%s", SwigType_str(Getattr(p, "type"),0)); - Printf(declaration, "%s", SwigType_str(Getattr(p, "type"),0)); - } + Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0)); + Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0)); + } } Append(w->def, ")"); @@ -3362,7 +3310,7 @@ class CSHARP : public Language { Printf(callback_def, "%s)", delegate_parms); Printf(callback_def, " {\n"); - + /* Emit the intermediate class's upcall to the actual class */ String *upcall = NewStringf("%s(%s)", symname, imcall_args); @@ -3372,10 +3320,10 @@ class CSHARP : public Language { tm = Swig_typemap_lookup_new("csdirectorout", tp, "", 0); if (tm) { - substituteClassname(returntype, tm); - Replaceall(tm, "$cscall", upcall); + substituteClassname(returntype, tm); + Replaceall(tm, "$cscall", upcall); - Printf(callback_code, " return %s;\n", tm); + Printf(callback_code, " return %s;\n", tm); } Delete(tm); @@ -3387,10 +3335,10 @@ class CSHARP : public Language { Delete(upcall); if (!ignored_method) { - if (!is_void) Printf(w->code, "jresult = (%s) ", c_ret_type); - - Printf(w->code, "swig_callback%s(%s);\n", - overloaded_name, jupcall_args); + if (!is_void) + Printf(w->code, "jresult = (%s) ", c_ret_type); + + Printf(w->code, "swig_callback%s(%s);\n", overloaded_name, jupcall_args); if (!is_void) { String *jresult_str = NewString("jresult"); @@ -3400,12 +3348,13 @@ class CSHARP : public Language { /* Copy jresult into c_result... */ if ((tm = Swig_typemap_lookup_new("directorout", tp, result_str, w))) { addThrows(n, "tmap:directorout", tp); - Replaceall(tm,"$input", jresult_str); - Replaceall(tm,"$result", result_str); + Replaceall(tm, "$input", jresult_str); + Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } @@ -3424,8 +3373,7 @@ class CSHARP : public Language { // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) - { + if (dirprot_mode() && !is_public(n) && !pure_virtual) { Printv(inline_extra_method, declaration, NIL); String *extra_method_name = NewStringf("%sSwigPublic", name); Replaceall(inline_extra_method, name, extra_method_name); @@ -3440,17 +3388,17 @@ class CSHARP : public Language { /* emit code */ if (status == SWIG_OK && output_director) { - if(!is_void) { - Replaceall(w->code,"$null", qualified_return); + if (!is_void) { + Replaceall(w->code, "$null", qualified_return); } else { - Replaceall(w->code,"$null",""); + Replaceall(w->code, "$null", ""); } if (!ignored_method) Printv(director_delegate_callback, "\n", callback_def, callback_code, NIL); - if (!Getattr(n,"defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); } } @@ -3499,39 +3447,39 @@ class CSHARP : public Language { /* Assign arguments to superclass's parameters, if not already done */ for (p = superparms; p; p = nextSibling(p)) { - String *pname = Getattr(p, "name"); + String *pname = Getattr(p, "name"); if (!pname) { - pname = NewStringf("arg%d", argidx++); - Setattr(p, "name", pname); + pname = NewStringf("arg%d", argidx++); + Setattr(p, "name", pname); } } // TODO: Is this copy needed? parms = CopyParmList(superparms); - if (!Getattr(n,"defaultargs")) { + if (!Getattr(n, "defaultargs")) { /* constructor */ { - String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); - String *call = Swig_csuperclass_call(0, basetype, superparms); - String *classtype = SwigType_namestr(Getattr(n, "name")); + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *call = Swig_csuperclass_call(0, basetype, superparms); + String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); - Printf(f_directors, " swig_init_callbacks();\n"); - Printf(f_directors, "}\n\n"); + Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, " swig_init_callbacks();\n"); + Printf(f_directors, "}\n\n"); - Delete(classtype); - Delete(target); - Delete(call); + Delete(classtype); + Delete(target); + Delete(call); } /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); - Printf(f_directors_h, " %s;\n", target); - Delete(target); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); } } @@ -3544,14 +3492,13 @@ class CSHARP : public Language { /* ------------------------------------------------------------ * classDirectorDefaultConstructor() * ------------------------------------------------------------ */ - + int classDirectorDefaultConstructor(Node *n) { String *classname = Swig_class_name(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", - classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); @@ -3569,7 +3516,7 @@ class CSHARP : public Language { int classDirectorInit(Node *n) { Delete(none_comparison); - none_comparison = NewString(""); // not used + none_comparison = NewString(""); // not used Delete(director_ctor_code); director_ctor_code = NewString("$director_new"); @@ -3581,7 +3528,7 @@ class CSHARP : public Language { /* Keep track of the director methods for this class */ first_class_dmethod = curr_class_dmethod = n_dmethods; - + director_callback_typedefs = NewString(""); director_callbacks = NewString(""); director_delegate_callback = NewString(""); @@ -3600,10 +3547,10 @@ class CSHARP : public Language { int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); String *full_classname = Getattr(current_class, "name"); - String *classname= Swig_class_name(current_class); + String *classname = Swig_class_name(current_class); Wrapper *w = NewWrapper(); - if (Getattr(n,"throw")) { + if (Getattr(n, "throw")) { Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); } else { @@ -3621,9 +3568,7 @@ class CSHARP : public Language { disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr); disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname"); - Printv(w->code, - "}\n", - NIL); + Printv(w->code, "}\n", NIL); Wrapper_print(w, f_directors); @@ -3659,8 +3604,8 @@ class CSHARP : public Language { Printf(w->def, "SWIG_Callback%s_t callback%s", methid, overname); Printf(w->code, "swig_callback%s = callback%s;\n", overname, overname); if (i != curr_class_dmethod - 1) { - Printf(f_directors_h, ", "); - Printf(w->def, ", "); + Printf(f_directors_h, ", "); + Printf(w->def, ", "); } } @@ -3694,30 +3639,31 @@ class CSHARP : public Language { * classDirectorDisown() * ------------------------------------------------------------------*/ virtual int classDirectorDisown(Node *n) { - (void)n; + (void) n; return SWIG_OK; } - - /* ----------------------------------------------------------------------------- + + /*---------------------------------------------------------------------- * extraDirectorProtectedCPPMethodsRequired() - * ----------------------------------------------------------------------------- */ + *--------------------------------------------------------------------*/ bool extraDirectorProtectedCPPMethodsRequired() const { - return false; + return false; } - /* -------------------------------------------------------------------- + /*---------------------------------------------------------------------- * Java_director_declaration() * * Generate the director class's declaration * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" - * ------------------------------------------------------------------*/ - + *--------------------------------------------------------------------*/ + void Java_director_declaration(Node *n) { + String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director()"); - String* classname = Swig_class_name(n); + String *classname = Swig_class_name(n); String *directorname = NewStringf("SwigDirector_%s", classname); String *declaration = Swig_class_declaration(n, directorname); @@ -3728,16 +3674,16 @@ class CSHARP : public Language { Setattr(n, "director:ctor", class_ctor); } -}; /* class CSHARP */ +}; /* class CSHARP */ /* ----------------------------------------------------------------------------- * swig_csharp() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_csharp() { +static Language *new_swig_csharp() { return new CSHARP(); } -extern "C" Language * swig_csharp(void) { +extern "C" Language *swig_csharp(void) { return new_swig_csharp(); } @@ -3745,7 +3691,7 @@ extern "C" Language * swig_csharp(void) { * Static member variables * ----------------------------------------------------------------------------- */ -const char *CSHARP::usage = (char*)"\ +const char *CSHARP::usage = (char *) "\ C# Options (available with -csharp)\n\ -dllimport
- Override DllImport attribute name to
\n\ -namespace - Generate wrappers into C# namespace \n\ @@ -3753,4 +3699,3 @@ C# Options (available with -csharp)\n\ of proxy classes\n\ -oldvarnames - old intermediary method names for variable wrappers\n\ \n"; - diff --git a/SWIG/Source/Modules/directors.cxx b/SWIG/Source/Modules/directors.cxx index dc08ef0be..d8881a5a7 100644 --- a/SWIG/Source/Modules/directors.cxx +++ b/SWIG/Source/Modules/directors.cxx @@ -20,7 +20,7 @@ char cvsroot_directors_cxx[] = "$Header"; * */ -String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { +String *Swig_csuperclass_call(String *base, String *method, ParmList *l) { String *call = NewString(""); int arg_idx = 0; Parm *p; @@ -28,13 +28,14 @@ String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { Printf(call, "%s::", base); } Printf(call, "%s(", method); - for (p=l; p; p = nextSibling(p)) { + for (p = l; p; p = nextSibling(p)) { String *pname = Getattr(p, "name"); - if (!pname && Cmp(Getattr(p,"type"), "void")) { + if (!pname && Cmp(Getattr(p, "type"), "void")) { pname = NewString(""); Printf(pname, "arg%d", arg_idx++); } - if (p != l) Printf(call, ", "); + if (p != l) + Printf(call, ", "); Printv(call, pname, NIL); } Printf(call, ")"); @@ -47,7 +48,7 @@ String *Swig_csuperclass_call(String* base, String* method, ParmList* l) { * e.g. "class myclass" * */ - + String *Swig_class_declaration(Node *n, String *name) { if (!name) { name = Getattr(n, "sym:name"); @@ -63,7 +64,7 @@ String *Swig_class_name(Node *n) { name = Copy(Getattr(n, "sym:name")); return name; } - + /* Swig_director_declaration() * * Generate the full director class declaration, complete with base classes. @@ -72,7 +73,7 @@ String *Swig_class_name(Node *n) { */ String *Swig_director_declaration(Node *n) { - String* classname = Swig_class_name(n); + String *classname = Swig_class_name(n); String *directorname = NewStringf("SwigDirector_%s", classname); String *base = Getattr(n, "classtype"); String *declaration = Swig_class_declaration(n, directorname); @@ -89,24 +90,25 @@ String *Swig_method_call(String_or_char *name, ParmList *parms) { int comma = 0; Parm *p = parms; SwigType *pt; - String *nname; + String *nname; func = NewString(""); nname = SwigType_namestr(name); - Printf(func,"%s(", nname); + Printf(func, "%s(", nname); while (p) { String *pname; - pt = Getattr(p,"type"); + pt = Getattr(p, "type"); if ((SwigType_type(pt) != T_VOID)) { - if (comma) Printf(func,","); + if (comma) + Printf(func, ","); pname = Getattr(p, "name"); - Printf(func,"%s", pname); + Printf(func, "%s", pname); comma = 1; i++; } p = nextSibling(p); } - Printf(func,")"); + Printf(func, ")"); return func; } @@ -148,7 +150,7 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int } for (i = 0; i < nelements; i++) { if (i < (nelements - 1)) { - nextelement = Getitem(elements, i+1); + nextelement = Getitem(elements, i + 1); } else { nextelement = 0; } @@ -160,74 +162,75 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int if (!Cmp(q, "const")) { is_const = 1; is_func = SwigType_isfunction(nextelement); - if (is_func) skip = 1; + if (is_func) + skip = 1; skip = 1; } if (!skip) { - Insert(result,0," "); - Insert(result,0,q); + Insert(result, 0, " "); + Insert(result, 0, q); } Delete(q); } } else if (SwigType_ispointer(element)) { - Insert(result,0,"*"); + Insert(result, 0, "*"); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - Append(result,")"); + Insert(result, 0, "("); + Append(result, ")"); } } else if (SwigType_ismemberpointer(element)) { String *q; q = SwigType_parm(element); - Insert(result,0,"::*"); - Insert(result,0,q); + Insert(result, 0, "::*"); + Insert(result, 0, q); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - Append(result,")"); + Insert(result, 0, "("); + Append(result, ")"); } Delete(q); - } - else if (SwigType_isreference(element)) { - Insert(result,0,"&"); - } else if (SwigType_isarray(element)) { + } else if (SwigType_isreference(element)) { + Insert(result, 0, "&"); + } else if (SwigType_isarray(element)) { DOH *size; - Append(result,"["); + Append(result, "["); size = SwigType_parm(element); - Append(result,size); - Append(result,"]"); + Append(result, size); + Append(result, "]"); Delete(size); } else if (SwigType_isfunction(element)) { Parm *parm; String *p; - Append(result,"("); + Append(result, "("); parm = args; while (parm != 0) { - String *type = Getattr(parm, "type"); - String* name = Getattr(parm, "name"); - if (!name && Cmp(type, "void")) { - name = NewString(""); - Printf(name, "arg%d", arg_idx++); - Setattr(parm, "name", name); + String *type = Getattr(parm, "type"); + String *name = Getattr(parm, "name"); + if (!name && Cmp(type, "void")) { + name = NewString(""); + Printf(name, "arg%d", arg_idx++); + Setattr(parm, "name", name); } if (!name) { - name = NewString(""); + name = NewString(""); } p = SwigType_str(type, name); - Append(result,p); - String* value = Getattr(parm, "value"); - if (values && (value != 0)) { - Printf(result, " = %s", value); - } + Append(result, p); + String *value = Getattr(parm, "value"); + if (values && (value != 0)) { + Printf(result, " = %s", value); + } parm = nextSibling(parm); - if (parm != 0) Append(result,", "); + if (parm != 0) + Append(result, ", "); } - Append(result,")"); + Append(result, ")"); } else { - if (Strcmp(element,"v(...)") == 0) { - Insert(result,0,"..."); + if (Strcmp(element, "v(...)") == 0) { + Insert(result, 0, "..."); } else { String *bs = SwigType_namestr(element); - Insert(result,0," "); - Insert(result,0,bs); + Insert(result, 0, " "); + Insert(result, 0, bs); Delete(bs); } } @@ -245,4 +248,3 @@ String *Swig_method_decl(SwigType *s, const String_or_char *id, List *args, int Chop(result); return result; } - diff --git a/SWIG/Source/Modules/emit.cxx b/SWIG/Source/Modules/emit.cxx index d545cdc3d..ae274c2e9 100644 --- a/SWIG/Source/Modules/emit.cxx +++ b/SWIG/Source/Modules/emit.cxx @@ -34,11 +34,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) { SwigType *vt = cplus_value_type(rt); SwigType *tt = vt ? vt : rt; SwigType *lt = SwigType_ltype(tt); - String *lstr = SwigType_str(lt,"result"); + String *lstr = SwigType_str(lt, "result"); if (SwigType_ispointer(lt)) { - Wrapper_add_localv(f,"result", lstr, "= 0", NULL); - } else{ - Wrapper_add_local(f,"result", lstr); + Wrapper_add_localv(f, "result", lstr, "= 0", NULL); + } else { + Wrapper_add_local(f, "result", lstr); } if (vt) { Delete(vt); @@ -46,21 +46,21 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) { Delete(lt); Delete(lstr); } - + /* Attach typemaps to parameters */ /* Swig_typemap_attach_parms("ignore",l,f); */ - Swig_typemap_attach_parms("default",l,f); - Swig_typemap_attach_parms("arginit",l,f); + Swig_typemap_attach_parms("default", l, f); + Swig_typemap_attach_parms("arginit", l, f); /* Apply the arginit and default */ p = l; while (p) { - tm = Getattr(p,"tmap:arginit"); + tm = Getattr(p, "tmap:arginit"); if (tm) { - Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:arginit:next"); + Replace(tm, "$target", Getattr(p, "lname"), DOH_REPLACE_ANY); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:arginit:next"); } else { p = nextSibling(p); } @@ -69,11 +69,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) { /* Apply the default typemap */ p = l; while (p) { - tm = Getattr(p,"tmap:default"); + tm = Getattr(p, "tmap:default"); if (tm) { - Replace(tm,"$target", Getattr(p,"lname"), DOH_REPLACE_ANY); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:default:next"); + Replace(tm, "$target", Getattr(p, "lname"), DOH_REPLACE_ANY); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:default:next"); } else { p = nextSibling(p); } @@ -88,11 +88,11 @@ void emit_args(SwigType *rt, ParmList *l, Wrapper *f) { * ----------------------------------------------------------------------------- */ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { - Swig_typemap_attach_parms("in",l,f); - Swig_typemap_attach_parms("typecheck",l,0); - Swig_typemap_attach_parms("argout",l,f); - Swig_typemap_attach_parms("check",l,f); - Swig_typemap_attach_parms("freearg",l,f); + Swig_typemap_attach_parms("in", l, f); + Swig_typemap_attach_parms("typecheck", l, 0); + Swig_typemap_attach_parms("argout", l, f); + Swig_typemap_attach_parms("check", l, f); + Swig_typemap_attach_parms("freearg", l, f); { /* This is compatibility code to deal with the deprecated "ignore" typemap */ @@ -100,17 +100,17 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { Parm *np; String *tm; while (p) { - tm = Getattr(p,"tmap:in"); - if (tm && checkAttribute(p,"tmap:in:numinputs","0")) { - Replaceall(tm,"$target", Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - np = Getattr(p,"tmap:in:next"); + tm = Getattr(p, "tmap:in"); + if (tm && checkAttribute(p, "tmap:in:numinputs", "0")) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + np = Getattr(p, "tmap:in:next"); while (p && (p != np)) { - Setattr(p,"ignore","1"); + Setattr(p, "ignore", "1"); p = nextSibling(p); } } else if (tm) { - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } else { p = nextSibling(p); } @@ -125,22 +125,22 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { Parm *p = l; Parm *npin, *npfreearg; while (p) { - npin = Getattr(p,"tmap:in:next"); - - /* - if (Getattr(p,"tmap:ignore")) { - npin = Getattr(p,"tmap:ignore:next"); - } else if (Getattr(p,"tmap:in")) { - npin = Getattr(p,"tmap:in:next"); - } - */ + npin = Getattr(p, "tmap:in:next"); - if (Getattr(p,"tmap:freearg")) { - npfreearg = Getattr(p,"tmap:freearg:next"); + /* + if (Getattr(p,"tmap:ignore")) { + npin = Getattr(p,"tmap:ignore:next"); + } else if (Getattr(p,"tmap:in")) { + npin = Getattr(p,"tmap:in:next"); + } + */ + + if (Getattr(p, "tmap:freearg")) { + npfreearg = Getattr(p, "tmap:freearg:next"); if (npin != npfreearg) { while (p != npin) { - Delattr(p,"tmap:freearg"); - Delattr(p,"tmap:freearg:next"); + Delattr(p, "tmap:freearg"); + Delattr(p, "tmap:freearg:next"); p = nextSibling(p); } } @@ -148,7 +148,7 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { p = npin; } } - + /* Check for variable length arguments with no input typemap. If no input is defined, we set this to ignore and print a message. @@ -157,25 +157,25 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { Parm *p = l; Parm *lp = 0; while (p) { - if (!checkAttribute(p,"tmap:in:numinputs","0")) { + if (!checkAttribute(p, "tmap:in:numinputs", "0")) { lp = p; - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); continue; } - if (SwigType_isvarargs(Getattr(p,"type"))) { - Swig_warning(WARN_LANG_VARARGS,input_file,line_number,"Variable length arguments discarded.\n"); - Setattr(p,"tmap:in",""); + if (SwigType_isvarargs(Getattr(p, "type"))) { + Swig_warning(WARN_LANG_VARARGS, input_file, line_number, "Variable length arguments discarded.\n"); + Setattr(p, "tmap:in", ""); } lp = 0; p = nextSibling(p); } - + /* Check if last input argument is variable length argument */ if (lp) { p = lp; while (p) { - if (SwigType_isvarargs(Getattr(p,"type"))) { - Setattr(l,"emit:varargs",lp); + if (SwigType_isvarargs(Getattr(p, "type"))) { + Setattr(l, "emit:varargs", lp); break; } p = nextSibling(p); @@ -194,12 +194,12 @@ void emit_attach_parmmaps(ParmList *l, Wrapper *f) { int emit_num_arguments(ParmList *parms) { Parm *p = parms; - int nargs = 0; + int nargs = 0; while (p) { - if (Getattr(p,"tmap:in")) { - nargs += GetInt(p,"tmap:in:numinputs"); - p = Getattr(p,"tmap:in:next"); + if (Getattr(p, "tmap:in")) { + nargs += GetInt(p, "tmap:in:numinputs"); + p = Getattr(p, "tmap:in:next"); } else { p = nextSibling(p); } @@ -207,12 +207,12 @@ int emit_num_arguments(ParmList *parms) { /* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */ /* - if (parms && (p = Getattr(parms,"emit:varargs"))) { - if (!nextSibling(p)) { - nargs--; - } - } - */ + if (parms && (p = Getattr(parms,"emit:varargs"))) { + if (!nextSibling(p)) { + nargs--; + } + } + */ return nargs; } @@ -227,23 +227,25 @@ int emit_num_arguments(ParmList *parms) { int emit_num_required(ParmList *parms) { Parm *p = parms; - int nargs = 0; + int nargs = 0; Parm *first_default_arg = 0; - int compactdefargs = ParmList_is_compactdefargs(p); + int compactdefargs = ParmList_is_compactdefargs(p); while (p) { - if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + if (Getattr(p, "tmap:in") && checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } else { - if (Getattr(p,"tmap:default")) break; - if (Getattr(p,"value")) { - if (!first_default_arg) - first_default_arg = p; - if (compactdefargs) break; + if (Getattr(p, "tmap:default")) + break; + if (Getattr(p, "value")) { + if (!first_default_arg) + first_default_arg = p; + if (compactdefargs) + break; } - nargs+= GetInt(p,"tmap:in:numinputs"); - if (Getattr(p,"tmap:in")) { - p = Getattr(p,"tmap:in:next"); + nargs += GetInt(p, "tmap:in:numinputs"); + if (Getattr(p, "tmap:in")) { + p = Getattr(p, "tmap:in:next"); } else { p = nextSibling(p); } @@ -255,29 +257,29 @@ int emit_num_required(ParmList *parms) { if (first_default_arg) { p = first_default_arg; while (p) { - if (Getattr(p,"tmap:in") && checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + if (Getattr(p, "tmap:in") && checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } else { - if (!Getattr(p,"value") && (!Getattr(p,"tmap:default"))) { - Swig_error(Getfile(p),Getline(p),"Non-optional argument '%s' follows an optional argument.\n",Getattr(p,"name")); - } - if (Getattr(p,"tmap:in")) { - p = Getattr(p,"tmap:in:next"); - } else { - p = nextSibling(p); - } + if (!Getattr(p, "value") && (!Getattr(p, "tmap:default"))) { + Swig_error(Getfile(p), Getline(p), "Non-optional argument '%s' follows an optional argument.\n", Getattr(p, "name")); + } + if (Getattr(p, "tmap:in")) { + p = Getattr(p, "tmap:in:next"); + } else { + p = nextSibling(p); + } } } } /* DB 04/02/2003: Not sure this is necessary with tmap:in:numinputs */ /* - if (parms && (p = Getattr(parms,"emit:varargs"))) { - if (!nextSibling(p)) { - nargs--; - } - } - */ + if (parms && (p = Getattr(parms,"emit:varargs"))) { + if (!nextSibling(p)) { + nargs--; + } + } + */ return nargs; } @@ -287,10 +289,11 @@ int emit_num_required(ParmList *parms) { * Checks if a function is a varargs function * ----------------------------------------------------------------------------- */ -int -emit_isvarargs(ParmList *p) { - if (!p) return 0; - if (Getattr(p,"emit:varargs")) return 1; +int emit_isvarargs(ParmList *p) { + if (!p) + return 0; + if (Getattr(p, "emit:varargs")) + return 1; return 0; } @@ -305,9 +308,9 @@ emit_isvarargs(ParmList *p) { void emit_mark_varargs(ParmList *l) { Parm *p = l; while (p) { - if (SwigType_isvarargs(Getattr(p,"type"))) - if (!Getattr(p,"tmap:in")) - Setattr(p,"varargs:ignore","1"); + if (SwigType_isvarargs(Getattr(p, "type"))) + if (!Getattr(p, "tmap:in")) + Setattr(p, "varargs:ignore", "1"); p = nextSibling(p); } } @@ -316,12 +319,11 @@ void emit_mark_varargs(ParmList *l) { /* replace_contract_args. This function replaces argument names in contract specifications. Used in conjunction with the %contract directive. */ -static -void replace_contract_args(Parm *cp, Parm *rp, String *s) { +static void replace_contract_args(Parm *cp, Parm *rp, String *s) { while (cp && rp) { - String *n = Getattr(cp,"name"); + String *n = Getattr(cp, "name"); if (n) { - Replace(s,n,Getattr(rp,"lname"), DOH_REPLACE_ID); + Replace(s, n, Getattr(rp, "lname"), DOH_REPLACE_ID); } cp = nextSibling(cp); rp = nextSibling(rp); @@ -336,18 +338,19 @@ void replace_contract_args(Parm *cp, Parm *rp, String *s) { * ----------------------------------------------------------------------------- */ int emit_action_code(Node *n, Wrapper *f, String *eaction) { /* Look for except feature */ - String *tm = GetFlagAttr(n,"feature:except"); - if (tm) tm = Copy(tm); - if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) { - Replaceall(tm,"$name",Getattr(n,"name")); - Replaceall(tm,"$symname", Getattr(n,"sym:name")); - Replaceall(tm,"$function", eaction); - Replaceall(tm,"$action", eaction); - Printv(f->code,tm,"\n", NIL); + String *tm = GetFlagAttr(n, "feature:except"); + if (tm) + tm = Copy(tm); + if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { + Replaceall(tm, "$name", Getattr(n, "name")); + Replaceall(tm, "$symname", Getattr(n, "sym:name")); + Replaceall(tm, "$function", eaction); + Replaceall(tm, "$action", eaction); + Printv(f->code, tm, "\n", NIL); Delete(tm); return 1; } else { - Printv(f->code,eaction,"\n", NIL); + Printv(f->code, eaction, "\n", NIL); return 0; } } @@ -357,120 +360,118 @@ void emit_action(Node *n, Wrapper *f) { String *action; String *wrap; SwigType *rt; - ParmList *catchlist = Getattr(n,"catchlist"); + ParmList *catchlist = Getattr(n, "catchlist"); /* Look for fragments */ { String *f; - f = Getattr(n,"feature:fragment"); + f = Getattr(n, "feature:fragment"); if (f) { - char *c, *tok; + char *c, *tok; String *t = Copy(f); c = Char(t); - tok = strtok(c,","); + tok = strtok(c, ","); while (tok) { String *fname = NewString(tok); Setfile(fname, Getfile(n)); Setline(fname, Getline(n)); Swig_fragment_emit(fname); Delete(fname); - tok = strtok(NULL,","); + tok = strtok(NULL, ","); } Delete(t); } } /* Emit wrapper code (if any) */ - wrap = Getattr(n,"wrap:code"); - if (wrap && Swig_filebyname("header")!=Getattr(n,"wrap:code:done") ) { + wrap = Getattr(n, "wrap:code"); + if (wrap && Swig_filebyname("header") != Getattr(n, "wrap:code:done")) { File *f_code = Swig_filebyname("header"); if (f_code) { - Printv(f_code,wrap,NIL); + Printv(f_code, wrap, NIL); } - Setattr(n,"wrap:code:done",f_code); + Setattr(n, "wrap:code:done", f_code); } - action = Getattr(n,"feature:action"); + action = Getattr(n, "feature:action"); if (!action) - action = Getattr(n,"wrap:action"); + action = Getattr(n, "wrap:action"); assert(action != 0); if (!is_public(n) && (is_member_director(n) || GetFlag(n, "explicitcall"))) { /* In order to call protected virtual director methods from the target language, we need * to add an extra dynamic_cast to call the public C++ wrapper in the director class. */ - Node* parent = Getattr(n,"parentNode"); - String* symname = Getattr(parent, "sym:name"); - String* dirname = NewStringf("SwigDirector_%s", symname); - String* dirdecl = NewStringf("%s *darg = 0", dirname); + Node *parent = Getattr(n, "parentNode"); + String *symname = Getattr(parent, "sym:name"); + String *dirname = NewStringf("SwigDirector_%s", symname); + String *dirdecl = NewStringf("%s *darg = 0", dirname); Wrapper_add_local(f, "darg", dirdecl); - Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n",dirname); + Printf(f->code, "darg = dynamic_cast<%s *>(arg1);\n", dirname); Delete(dirname); Delete(dirdecl); } /* Get the return type */ - rt = Getattr(n,"type"); + rt = Getattr(n, "type"); /* Emit contract code (if any) */ if (Swig_contract_mode_get()) { /* Preassertion */ tm = Getattr(n, "contract:preassert"); if (Len(tm)) { - Printv(f->code,tm,"\n",NIL); + Printv(f->code, tm, "\n", NIL); } } /* Exception handling code */ /* saves action -> eaction for postcatching exception */ String *eaction = NewString(""); - + /* If we are in C++ mode and there is an exception specification. We're going to enclose the block in a try block */ if (catchlist) { - Printf(eaction,"try {\n"); + Printf(eaction, "try {\n"); } Printv(eaction, action, NIL); if (catchlist) { int unknown_catch = 0; - Printf(eaction,"}\n"); + Printf(eaction, "}\n"); for (Parm *ep = catchlist; ep; ep = nextSibling(ep)) { - String *em = Swig_typemap_lookup_new("throws",ep,"_e",0); + String *em = Swig_typemap_lookup_new("throws", ep, "_e", 0); if (em) { - SwigType *et = Getattr(ep,"type"); - SwigType *etr = SwigType_typedef_resolve_all(et); - if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) { - Printf(eaction,"catch(%s) {", SwigType_str(et, "_e")); - } else if (SwigType_isvarargs(etr)) { - Printf(eaction,"catch(...) {"); + SwigType *et = Getattr(ep, "type"); + SwigType *etr = SwigType_typedef_resolve_all(et); + if (SwigType_isreference(etr) || SwigType_ispointer(etr) || SwigType_isarray(etr)) { + Printf(eaction, "catch(%s) {", SwigType_str(et, "_e")); + } else if (SwigType_isvarargs(etr)) { + Printf(eaction, "catch(...) {"); } else { - Printf(eaction,"catch(%s) {", SwigType_str(et, "&_e")); - } - Printv(eaction,em,"\n",NIL); - Printf(eaction,"}\n"); + Printf(eaction, "catch(%s) {", SwigType_str(et, "&_e")); + } + Printv(eaction, em, "\n", NIL); + Printf(eaction, "}\n"); } else { - Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n), - "No 'throws' typemap defined for exception type '%s'\n", - SwigType_str(Getattr(ep,"type"),0)); + Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n), "No 'throws' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep, "type"), 0)); unknown_catch = 1; } } if (unknown_catch) { - Printf(eaction,"catch(...) { throw; }\n"); + Printf(eaction, "catch(...) { throw; }\n"); } } /* Look for except typemap (Deprecated) */ - tm = Swig_typemap_lookup_new("except",n,"result",0); + tm = Swig_typemap_lookup_new("except", n, "result", 0); if (tm) { - Setattr(n,"feature:except", tm); + Setattr(n, "feature:except", tm); tm = 0; } - + /* emit the except feature code */ emit_action_code(n, f, eaction); - + Delete(eaction); /* Emit contract code (if any) */ @@ -478,10 +479,8 @@ void emit_action(Node *n, Wrapper *f) { /* Postassertion */ tm = Getattr(n, "contract:postassert"); if (Len(tm)) { - Printv(f->code,tm,"\n",NIL); + Printv(f->code, tm, "\n", NIL); } } } - - diff --git a/SWIG/Source/Modules/guile.cxx b/SWIG/Source/Modules/guile.cxx index 4eb01642a..2f1709fbe 100644 --- a/SWIG/Source/Modules/guile.cxx +++ b/SWIG/Source/Modules/guile.cxx @@ -14,7 +14,7 @@ char cvsroot_guile_cxx[] = "$Header$"; #include // Note string broken in half for compilers that can't handle long strings -static const char *guile_usage = (char*)"\ +static const char *guile_usage = (char *) "\ Guile Options (available with -guile)\n\ -prefix - Use as prefix [default \"gswig_\"]\n\ -package - Set the path of the module to \n\ @@ -47,27 +47,27 @@ Guile Options (available with -guile)\n\ -exportprimitive - Add the (export ...) code from scmstub into the\n\ GOOPS file.\n"; -static File *f_runtime = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_init = 0; +static File *f_runtime = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_init = 0; -static char *prefix = (char *) "gswig_"; -static char *module = 0; -static char *package = 0; +static char *prefix = (char *) "gswig_"; +static char *module = 0; +static char *package = 0; static enum { - GUILE_LSTYLE_SIMPLE, // call `SWIG_init()' - GUILE_LSTYLE_PASSIVE, // passive linking (no module code) - GUILE_LSTYLE_MODULE, // native guile module linking (Guile >= 1.4.1) - GUILE_LSTYLE_LTDLMOD_1_4, // old (Guile <= 1.4) dynamic module convention - GUILE_LSTYLE_HOBBIT // use (hobbit4d link) + GUILE_LSTYLE_SIMPLE, // call `SWIG_init()' + GUILE_LSTYLE_PASSIVE, // passive linking (no module code) + GUILE_LSTYLE_MODULE, // native guile module linking (Guile >= 1.4.1) + GUILE_LSTYLE_LTDLMOD_1_4, // old (Guile <= 1.4) dynamic module convention + GUILE_LSTYLE_HOBBIT // use (hobbit4d link) } linkage = GUILE_LSTYLE_SIMPLE; -static File *procdoc = 0; -static bool scmstub = false; +static File *procdoc = 0; +static bool scmstub = false; static String *scmtext; -static bool goops = false; +static bool goops = false; static String *goopstext; static String *goopscode; static String *goopsexport; @@ -78,10 +78,10 @@ static enum { TEXINFO } docformat = GUILE_1_4; -static int emit_setters = 0; -static int only_setters = 0; -static int emit_slot_accessors = 0; -static int struct_member = 0; +static int emit_setters = 0; +static int only_setters = 0; +static int emit_slot_accessors = 0; +static int struct_member = 0; static String *beforereturn = 0; static String *return_nothing_doc = 0; @@ -90,8 +90,8 @@ static String *return_multi_doc = 0; static String *exported_symbols = 0; -static int use_scm_interface = 1; -static int exporting_destructor = 0; +static int use_scm_interface = 1; +static int exporting_destructor = 0; static String *swigtype_ptr = 0; /* GOOPS stuff */ @@ -99,172 +99,152 @@ static String *primsuffix = 0; static String *class_name = 0; static String *short_class_name = 0; static String *goops_class_methods; -static int in_class = 0; -static int have_constructor = 0; -static int useclassprefix = 0; // -useclassprefix argument -static String *goopsprefix = 0; // -goopsprefix argument -static int primRenamer = 0; // if (use-modules ((...) :renamer ...) is exported to GOOPS file -static int exportprimitive = 0; // -exportprimitive argument +static int in_class = 0; +static int have_constructor = 0; +static int useclassprefix = 0; // -useclassprefix argument +static String *goopsprefix = 0; // -goopsprefix argument +static int primRenamer = 0; // if (use-modules ((...) :renamer ...) is exported to GOOPS file +static int exportprimitive = 0; // -exportprimitive argument static String *memberfunction_name = 0; extern "C" { - static int has_classname(Node *class_node) - { + static int has_classname(Node *class_node) { return Getattr(class_node, "guile:goopsclassname") != NULL; } } - -class GUILE : public Language { + +class GUILE:public Language { public: /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ - virtual void main (int argc, char *argv[]) { + virtual void main(int argc, char *argv[]) { int i, orig_len; - - SWIG_library_directory("guile"); - SWIG_typemap_lang("guile"); - // Look for certain command line options + SWIG_library_directory("guile"); + SWIG_typemap_lang("guile"); + + // Look for certain command line options for (i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp (argv[i], "-help") == 0) { - fputs (guile_usage, stdout); - SWIG_exit (EXIT_SUCCESS); - } - else if (strcmp (argv[i], "-prefix") == 0) { + if (strcmp(argv[i], "-help") == 0) { + fputs(guile_usage, stdout); + SWIG_exit(EXIT_SUCCESS); + } else if (strcmp(argv[i], "-prefix") == 0) { if (argv[i + 1]) { - prefix = new char[strlen (argv[i + 1]) + 2]; - strcpy (prefix, argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + prefix = new char[strlen(argv[i + 1]) + 2]; + strcpy(prefix, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } - else if (strcmp (argv[i], "-package") == 0) { + } else if (strcmp(argv[i], "-package") == 0) { if (argv[i + 1]) { - package = new char[strlen (argv[i + 1]) + 2]; - strcpy (package, argv [i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + package = new char[strlen(argv[i + 1]) + 2]; + strcpy(package, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } - else if (strcmp (argv[i], "-Linkage") == 0 - || strcmp (argv[i], "-linkage") == 0) { + } else if (strcmp(argv[i], "-Linkage") == 0 || strcmp(argv[i], "-linkage") == 0) { if (argv[i + 1]) { - if (0 == strcmp (argv[i + 1], "ltdlmod")) + if (0 == strcmp(argv[i + 1], "ltdlmod")) linkage = GUILE_LSTYLE_LTDLMOD_1_4; - else if (0 == strcmp (argv[i + 1], "hobbit")) + else if (0 == strcmp(argv[i + 1], "hobbit")) linkage = GUILE_LSTYLE_HOBBIT; - else if (0 == strcmp (argv[i + 1], "simple")) + else if (0 == strcmp(argv[i + 1], "simple")) linkage = GUILE_LSTYLE_SIMPLE; - else if (0 == strcmp (argv[i + 1], "passive")) + else if (0 == strcmp(argv[i + 1], "passive")) linkage = GUILE_LSTYLE_PASSIVE; - else if (0 == strcmp (argv[i + 1], "module")) + else if (0 == strcmp(argv[i + 1], "module")) linkage = GUILE_LSTYLE_MODULE; else - Swig_arg_error (); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + Swig_arg_error(); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } - else if (strcmp (argv[i], "-procdoc") == 0) { + } else if (strcmp(argv[i], "-procdoc") == 0) { if (argv[i + 1]) { procdoc = NewFile(argv[i + 1], (char *) "w"); if (!procdoc) { FileErrorDisplay(argv[i + 1]); SWIG_exit(EXIT_FAILURE); } - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } - else if (strcmp (argv[i], "-procdocformat") == 0) { - if (strcmp(argv[i+1], "guile-1.4") == 0) + } else if (strcmp(argv[i], "-procdocformat") == 0) { + if (strcmp(argv[i + 1], "guile-1.4") == 0) docformat = GUILE_1_4; - else if (strcmp(argv[i+1], "plain") == 0) + else if (strcmp(argv[i + 1], "plain") == 0) docformat = PLAIN; - else if (strcmp(argv[i+1], "texinfo") == 0) + else if (strcmp(argv[i + 1], "texinfo") == 0) docformat = TEXINFO; - else Swig_arg_error(); + else + Swig_arg_error(); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; - } - else if (strcmp (argv[i], "-emit-setters") == 0 - || strcmp (argv[i], "-emitsetters") == 0) { + } else if (strcmp(argv[i], "-emit-setters") == 0 || strcmp(argv[i], "-emitsetters") == 0) { emit_setters = 1; - Swig_mark_arg (i); - } - else if (strcmp (argv[i], "-only-setters") == 0 - || strcmp (argv[i], "-onlysetters") == 0) { + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-only-setters") == 0 || strcmp(argv[i], "-onlysetters") == 0) { emit_setters = 1; only_setters = 1; - Swig_mark_arg (i); - } - else if (strcmp (argv[i], "-emit-slot-accessors") == 0 - || strcmp (argv[i], "-emitslotaccessors") == 0) { + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-emit-slot-accessors") == 0 || strcmp(argv[i], "-emitslotaccessors") == 0) { emit_slot_accessors = 1; - Swig_mark_arg (i); - } - else if (strcmp (argv[i], "-scmstub") == 0) { - scmstub = true; - Swig_mark_arg(i); - } - else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) { - goops = true; - Swig_mark_arg(i); - } - else if (strcmp(argv[i], "-gh") == 0) { - use_scm_interface = 0; - Swig_mark_arg(i); - } - else if (strcmp(argv[i], "-scm") == 0) { - use_scm_interface = 1; - Swig_mark_arg(i); - } - else if (strcmp(argv[i], "-primsuffix") == 0) { - if (argv[i+1]) { - primsuffix = NewString(argv[i+1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-scmstub") == 0) { + scmstub = true; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-shadow") == 0) || ((strcmp(argv[i], "-proxy") == 0))) { + goops = true; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-gh") == 0) { + use_scm_interface = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-scm") == 0) { + use_scm_interface = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-primsuffix") == 0) { + if (argv[i + 1]) { + primsuffix = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; - } else { - Swig_arg_error(); - } - } - else if (strcmp(argv[i], "-goopsprefix") == 0) { - if (argv[i+1]) { - goopsprefix = NewString(argv[i+1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-goopsprefix") == 0) { + if (argv[i + 1]) { + goopsprefix = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; - } else { - Swig_arg_error(); - } - } - else if (strcmp(argv[i], "-useclassprefix") == 0) { - useclassprefix = 1; - Swig_mark_arg(i); - } - else if (strcmp(argv[i], "-exportprimitive") == 0) { - exportprimitive = 1; - // should use Swig_warning() here? - Swig_mark_arg(i); - } + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-useclassprefix") == 0) { + useclassprefix = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-exportprimitive") == 0) { + exportprimitive = 1; + // should use Swig_warning() here? + Swig_mark_arg(i); + } } } @@ -275,8 +255,8 @@ public: //goops support can only be enabled if passive or module linkage is used if (goops) { if (linkage != GUILE_LSTYLE_PASSIVE && linkage != GUILE_LSTYLE_MODULE) { - Printf(stderr, "guile: GOOPS support requires passive or module linkage\n"); - exit(1); + Printf(stderr, "guile: GOOPS support requires passive or module linkage\n"); + exit(1); } } @@ -290,38 +270,36 @@ public: if (exportprimitive && primRenamer) { // should use Swig_warning() ? - Printf(stderr, - "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n"); + Printf(stderr, "guile: Warning: -exportprimitive only makes sense with passive linkage without a scmstub.\n"); } - // Make sure `prefix' ends in an underscore - orig_len = strlen (prefix); + orig_len = strlen(prefix); if (prefix[orig_len - 1] != '_') { prefix[1 + orig_len] = 0; prefix[orig_len] = '_'; } /* Add a symbol for this module */ - Preprocessor_define ("SWIGGUILE 1",0); + Preprocessor_define("SWIGGUILE 1", 0); /* Read in default typemaps */ if (use_scm_interface) SWIG_config_file("guile_scm.swg"); else SWIG_config_file("guile_gh.swg"); allow_overloading(); - + } /* ------------------------------------------------------------ * top() * ------------------------------------------------------------ */ - virtual int top(Node *n) { + virtual int top(Node *n) { /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - - f_runtime = NewFile(outfile,"w"); + String *outfile = Getattr(n, "outfile"); + + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); @@ -329,13 +307,13 @@ public: f_init = NewString(""); f_header = NewString(""); f_wrappers = NewString(""); - + /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + scmtext = NewString(""); Swig_register_filebyname("scheme", scmtext); exported_symbols = NewString(""); @@ -343,68 +321,68 @@ public: Swig_register_filebyname("goops", goopstext); goopscode = NewString(""); goopsexport = NewString(""); - + Printf(f_runtime, "/* -*- buffer-read-only: t -*- vi: set ro: */\n"); - Swig_banner (f_runtime); - - Printf (f_runtime, "/* Implementation : GUILE */\n\n"); + Swig_banner(f_runtime); + + Printf(f_runtime, "/* Implementation : GUILE */\n\n"); if (!use_scm_interface) { if (SwigRuntime == 1) Printf(f_runtime, "#define SWIG_GLOBAL\n"); if (SwigRuntime == 2) - Printf(f_runtime, "#define SWIG_NOINCLUDE\n"); + Printf(f_runtime, "#define SWIG_NOINCLUDE\n"); } - + /* Write out directives and declarations */ - - module = Swig_copy_string(Char(Getattr(n,"name"))); - + + module = Swig_copy_string(Char(Getattr(n, "name"))); + switch (linkage) { case GUILE_LSTYLE_SIMPLE: /* Simple linkage; we have to export the SWIG_init function. The user can - rename the function by a #define. */ - Printf (f_runtime, "#define SWIG_GUILE_INIT_STATIC extern\n"); + rename the function by a #define. */ + Printf(f_runtime, "#define SWIG_GUILE_INIT_STATIC extern\n"); break; default: /* Other linkage; we make the SWIG_init function static */ - Printf (f_runtime, "#define SWIG_GUILE_INIT_STATIC static\n"); + Printf(f_runtime, "#define SWIG_GUILE_INIT_STATIC static\n"); break; } if (CPlusPlus) { Printf(f_runtime, "extern \"C\" {\n\n"); } - Printf (f_runtime, "SWIG_GUILE_INIT_STATIC void\nSWIG_init (void);\n"); + Printf(f_runtime, "SWIG_GUILE_INIT_STATIC void\nSWIG_init (void);\n"); if (CPlusPlus) { Printf(f_runtime, "\n}\n"); } - + Language::top(n); - + /* Close module */ - - Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - - SwigType_emit_type_table (f_runtime, f_wrappers); - - Printf (f_init, "}\n\n"); - Printf (f_init, "#ifdef __cplusplus\n}\n#endif\n"); + + Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + + SwigType_emit_type_table(f_runtime, f_wrappers); + + Printf(f_init, "}\n\n"); + Printf(f_init, "#ifdef __cplusplus\n}\n#endif\n"); String *module_name = NewString(""); - + if (!module) Printv(module_name, "swig", NIL); else { if (package) - Printf(module_name,"%s/%s", package, module); + Printf(module_name, "%s/%s", package, module); else - Printv(module_name,module,NIL); + Printv(module_name, module, NIL); } - emit_linkage (module_name); + emit_linkage(module_name); Delete(module_name); - + if (procdoc) { Delete(procdoc); procdoc = NULL; @@ -414,9 +392,9 @@ public: Delete(goopstext); /* Close all of the files */ - Dump(f_header,f_runtime); - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_header, f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); @@ -424,102 +402,99 @@ public: Delete(f_runtime); return SWIG_OK; } - - void emit_linkage (String *module_name) { + + void emit_linkage(String *module_name) { String *module_func = NewString(""); - + if (CPlusPlus) { Printf(f_init, "extern \"C\" {\n\n"); } - - Printv(module_func,module_name,NIL); - Replaceall(module_func,"-", "_"); - + + Printv(module_func, module_name, NIL); + Replaceall(module_func, "-", "_"); + switch (linkage) { case GUILE_LSTYLE_SIMPLE: - Printf (f_init, "\n/* Linkage: simple */\n"); + Printf(f_init, "\n/* Linkage: simple */\n"); break; case GUILE_LSTYLE_PASSIVE: - Printf (f_init, "\n/* Linkage: passive */\n"); - Replaceall(module_func,"/", "_"); - Insert(module_func,0, "scm_init_"); - Append(module_func,"_module"); - - Printf (f_init, "SCM\n%s (void)\n{\n", module_func); - Printf (f_init, " SWIG_init();\n"); - Printf (f_init, " return SCM_UNSPECIFIED;\n"); - Printf (f_init, "}\n"); + Printf(f_init, "\n/* Linkage: passive */\n"); + Replaceall(module_func, "/", "_"); + Insert(module_func, 0, "scm_init_"); + Append(module_func, "_module"); + + Printf(f_init, "SCM\n%s (void)\n{\n", module_func); + Printf(f_init, " SWIG_init();\n"); + Printf(f_init, " return SCM_UNSPECIFIED;\n"); + Printf(f_init, "}\n"); break; case GUILE_LSTYLE_LTDLMOD_1_4: - Printf (f_init, "\n/* Linkage: ltdlmod */\n"); - Replaceall(module_func,"/", "_"); - Insert(module_func,0, "scm_init_"); - Append(module_func,"_module"); - Printf (f_init, "SCM\n%s (void)\n{\n", module_func); + Printf(f_init, "\n/* Linkage: ltdlmod */\n"); + Replaceall(module_func, "/", "_"); + Insert(module_func, 0, "scm_init_"); + Append(module_func, "_module"); + Printf(f_init, "SCM\n%s (void)\n{\n", module_func); { String *mod = NewString(module_name); - Replaceall(mod,"/", " "); - Printf (f_init, " scm_register_module_xxx (\"%s\", (void *) SWIG_init);\n", - mod); - Printf (f_init, " return SCM_UNSPECIFIED;\n"); + Replaceall(mod, "/", " "); + Printf(f_init, " scm_register_module_xxx (\"%s\", (void *) SWIG_init);\n", mod); + Printf(f_init, " return SCM_UNSPECIFIED;\n"); Delete(mod); } - Printf (f_init, "}\n"); + Printf(f_init, "}\n"); break; case GUILE_LSTYLE_MODULE: - Printf (f_init, "\n/* Linkage: module */\n"); - Replaceall(module_func,"/", "_"); - Insert(module_func,0, "scm_init_"); - Append(module_func,"_module"); - - Printf (f_init, "static void SWIG_init_helper(void *data)\n"); - Printf (f_init, "{\n SWIG_init();\n"); + Printf(f_init, "\n/* Linkage: module */\n"); + Replaceall(module_func, "/", "_"); + Insert(module_func, 0, "scm_init_"); + Append(module_func, "_module"); + + Printf(f_init, "static void SWIG_init_helper(void *data)\n"); + Printf(f_init, "{\n SWIG_init();\n"); if (Len(exported_symbols) > 0) - Printf (f_init, " scm_c_export(%sNULL);", - exported_symbols); - Printf (f_init, "\n}\n\n"); - - Printf (f_init, "SCM\n%s (void)\n{\n", module_func); + Printf(f_init, " scm_c_export(%sNULL);", exported_symbols); + Printf(f_init, "\n}\n\n"); + + Printf(f_init, "SCM\n%s (void)\n{\n", module_func); { String *mod = NewString(module_name); - if (goops) - Printv(mod,"-",primsuffix,NIL); - Replaceall(mod,"/", " "); + if (goops) + Printv(mod, "-", primsuffix, NIL); + Replaceall(mod, "/", " "); Printf(f_init, " scm_c_define_module(\"%s\",\n", mod); Printf(f_init, " SWIG_init_helper, NULL);\n"); Printf(f_init, " return SCM_UNSPECIFIED;\n"); Delete(mod); } - Printf (f_init, "}\n"); + Printf(f_init, "}\n"); break; case GUILE_LSTYLE_HOBBIT: - Printf (f_init, "\n/* Linkage: hobbit */\n"); - Replaceall(module_func,"/", "_slash_"); - Insert(module_func,0, "scm_init_"); - Printf (f_init, "SCM\n%s (void)\n{\n", module_func); + Printf(f_init, "\n/* Linkage: hobbit */\n"); + Replaceall(module_func, "/", "_slash_"); + Insert(module_func, 0, "scm_init_"); + Printf(f_init, "SCM\n%s (void)\n{\n", module_func); { String *mod = NewString(module_name); - Replaceall(mod,"/", " "); - Printf (f_init, " scm_register_module_xxx (\"%s\", (void *) SWIG_init);\n", - mod); - Printf (f_init, " return SCM_UNSPECIFIED;\n"); + Replaceall(mod, "/", " "); + Printf(f_init, " scm_register_module_xxx (\"%s\", (void *) SWIG_init);\n", mod); + Printf(f_init, " return SCM_UNSPECIFIED;\n"); Delete(mod); } - Printf (f_init, "}\n"); + Printf(f_init, "}\n"); break; default: - abort(); // for now + abort(); // for now } - + if (scmstub) { /* Emit Scheme stub if requested */ String *primitive_name = NewString(module_name); if (goops) - Printv(primitive_name,"-",primsuffix,NIL); - + Printv(primitive_name, "-", primsuffix, NIL); + String *mod = NewString(primitive_name); Replaceall(mod, "/", " "); - + String *fname = NewStringf("%s%s.scm", SWIG_output_directory(), primitive_name); @@ -528,25 +503,23 @@ public: if (!scmstubfile) { FileErrorDisplay(fname); SWIG_exit(EXIT_FAILURE); - } + } Delete(fname); - - Printf (scmstubfile, ";;; -*- buffer-read-only: t -*- vi: set ro: */\n"); - Printf (scmstubfile, ";;; Automatically generated by SWIG; do not edit.\n\n"); - if (linkage == GUILE_LSTYLE_SIMPLE - || linkage == GUILE_LSTYLE_PASSIVE) - Printf (scmstubfile, "(define-module (%s))\n\n", mod); + + Printf(scmstubfile, ";;; -*- buffer-read-only: t -*- vi: set ro: */\n"); + Printf(scmstubfile, ";;; Automatically generated by SWIG; do not edit.\n\n"); + if (linkage == GUILE_LSTYLE_SIMPLE || linkage == GUILE_LSTYLE_PASSIVE) + Printf(scmstubfile, "(define-module (%s))\n\n", mod); Delete(mod); - Printf (scmstubfile, "%s", scmtext); - if ((linkage == GUILE_LSTYLE_SIMPLE - || linkage == GUILE_LSTYLE_PASSIVE) - && Len(exported_symbols) > 0) { - String *ex = NewString(exported_symbols); - Replaceall(ex, ", ", "\n "); - Replaceall(ex, "\"", ""); - Chop(ex); - Printf(scmstubfile, "\n(export %s)\n", ex); - Delete(ex); + Printf(scmstubfile, "%s", scmtext); + if ((linkage == GUILE_LSTYLE_SIMPLE || linkage == GUILE_LSTYLE_PASSIVE) + && Len(exported_symbols) > 0) { + String *ex = NewString(exported_symbols); + Replaceall(ex, ", ", "\n "); + Replaceall(ex, "\"", ""); + Chop(ex); + Printf(scmstubfile, "\n(export %s)\n", ex); + Delete(ex); } Delete(scmstubfile); } @@ -554,37 +527,36 @@ public: if (goops) { String *mod = NewString(module_name); Replaceall(mod, "/", " "); - + String *fname = NewStringf("%s%s.scm", SWIG_output_directory(), module_name); - File *goopsfile = NewFile(fname, (char *)"w"); + File *goopsfile = NewFile(fname, (char *) "w"); if (!goopsfile) { FileErrorDisplay(fname); SWIG_exit(EXIT_FAILURE); - } - Delete(fname); - Printf (goopsfile, ";;; -*- buffer-read-only: t -*- vi: set ro: */\n"); - Printf (goopsfile, ";;; Automatically generated by SWIG; do not edit.\n\n"); - Printf (goopsfile, "(define-module (%s))\n", mod); - Printf (goopsfile, "%s\n", goopstext); - Printf (goopsfile, "(use-modules (oop goops) (Swig common))\n"); - if (primRenamer) { - Printf (goopsfile, "(use-modules ((%s-%s) :renamer (symbol-prefix-proc 'primitive:)))\n", - mod, primsuffix); } - Printf (goopsfile, "%s\n(export %s)", goopscode, goopsexport); + Delete(fname); + Printf(goopsfile, ";;; -*- buffer-read-only: t -*- vi: set ro: */\n"); + Printf(goopsfile, ";;; Automatically generated by SWIG; do not edit.\n\n"); + Printf(goopsfile, "(define-module (%s))\n", mod); + Printf(goopsfile, "%s\n", goopstext); + Printf(goopsfile, "(use-modules (oop goops) (Swig common))\n"); + if (primRenamer) { + Printf(goopsfile, "(use-modules ((%s-%s) :renamer (symbol-prefix-proc 'primitive:)))\n", mod, primsuffix); + } + Printf(goopsfile, "%s\n(export %s)", goopscode, goopsexport); if (exportprimitive) { - String *ex = NewString(exported_symbols); - Replaceall(ex, ", ", "\n "); - Replaceall(ex, "\"", ""); - Chop(ex); - Printf(goopsfile, "\n(export %s)", ex); - Delete(ex); + String *ex = NewString(exported_symbols); + Replaceall(ex, ", ", "\n "); + Replaceall(ex, "\"", ""); + Chop(ex); + Printf(goopsfile, "\n(export %s)", ex); + Delete(ex); } Delete(mod); Delete(goopsfile); } - + Delete(module_func); if (CPlusPlus) { Printf(f_init, "\n}\n"); @@ -593,23 +565,19 @@ public: /* Return true iff T is a pointer type */ - int is_a_pointer (SwigType *t) { + int is_a_pointer(SwigType *t) { return SwigType_ispointer(SwigType_typedef_resolve_all(t)); } /* Report an error handling the given type. */ - void throw_unhandled_guile_type_error (SwigType *d) { - Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, - "Unable to handle type %s.\n", SwigType_str(d,0)); + void throw_unhandled_guile_type_error(SwigType *d) { + Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, "Unable to handle type %s.\n", SwigType_str(d, 0)); } - + /* Write out procedure documentation */ - void write_doc(const String *proc_name, - const String *signature, - const String *doc, - const String *signature2 = NULL) { + void write_doc(const String *proc_name, const String *signature, const String *doc, const String *signature2 = NULL) { switch (docformat) { case GUILE_1_4: Printv(procdoc, "\f\n", NIL); @@ -638,12 +606,7 @@ public: /* returns false if the typemap is an empty string */ bool handle_documentation_typemap(String *output, - const String *maybe_delimiter, - Parm *p, - const String *typemap, - const String *default_doc, - const String *name = NULL) - { + const String *maybe_delimiter, Parm *p, const String *typemap, const String *default_doc, const String *name = NULL) { String *tmp = NewString(""); String *tm; if (!(tm = Getattr(p, typemap))) { @@ -654,31 +617,32 @@ public: if (maybe_delimiter && Len(output) > 0 && Len(tm) > 0) { Printv(output, maybe_delimiter, NIL); } - const String *pn = (name == NULL) ? (const String *)Getattr(p,"name") : name; - String *pt = Getattr(p,"type"); - Replaceall(tm, "$name", pn); // legacy for $parmname - Replaceall(tm, "$type", SwigType_str(pt,0)); + const String *pn = (name == NULL) ? (const String *) Getattr(p, "name") : name; + String *pt = Getattr(p, "type"); + Replaceall(tm, "$name", pn); // legacy for $parmname + Replaceall(tm, "$type", SwigType_str(pt, 0)); /* $NAME is like $name, but marked-up as a variable. */ String *ARGNAME = NewString(""); if (docformat == TEXINFO) Printf(ARGNAME, "@var{%s}", pn); - else Printf(ARGNAME, "%(upper)s", pn); + else + Printf(ARGNAME, "%(upper)s", pn); Replaceall(tm, "$NAME", ARGNAME); Replaceall(tm, "$PARMNAME", ARGNAME); - Printv(output,tm,NIL); + Printv(output, tm, NIL); Delete(tmp); return result; - } - + } + /* ------------------------------------------------------------ * functionWrapper() * Create a function declaration and register it with the interpreter. * ------------------------------------------------------------ */ - + virtual int functionWrapper(Node *n) { - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); Parm *p; String *proc_name = 0; char source[256]; @@ -701,99 +665,103 @@ public: int args_passed_as_array = 0; int scheme_argnum = 0; bool any_specialized_arg = false; - + // Make a wrapper name for this String *wname = Swig_name_wrapper(iname); - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); args_passed_as_array = 1; } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } if (overname) { Append(wname, overname); } - Setattr(n,"wrap:name",wname); - + Setattr(n, "wrap:name", wname); + // Build the name for scheme. proc_name = NewString(iname); - Replaceall(proc_name,"_", "-"); - + Replaceall(proc_name, "_", "-"); + /* Emit locals etc. into f->code; figure out which args to ignore */ - emit_args (d, l, f); - + emit_args(d, l, f); + /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); - + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); + /* Get number of required and total arguments */ numargs = emit_num_arguments(l); - numreq = emit_num_required(l); - + numreq = emit_num_required(l); + /* Declare return variable */ - - Wrapper_add_local (f,"gswig_result", "SCM gswig_result"); - Wrapper_add_local (f,"gswig_list_p", "SWIGUNUSED int gswig_list_p = 0"); - + + Wrapper_add_local(f, "gswig_result", "SCM gswig_result"); + Wrapper_add_local(f, "gswig_list_p", "SWIGUNUSED int gswig_list_p = 0"); + /* Get the output typemap so we can start generating documentation. Don't worry, the returned string is saved as 'tmap:out' */ - - Swig_typemap_lookup_new("out",n,"result",0); - - if ((tm = Getattr(n,"tmap:out:doc"))) { - Printv(returns,tm,NIL); - if (Len(tm) > 0) num_results = 1; - else num_results = 0; + + Swig_typemap_lookup_new("out", n, "result", 0); + + if ((tm = Getattr(n, "tmap:out:doc"))) { + Printv(returns, tm, NIL); + if (Len(tm) > 0) + num_results = 1; + else + num_results = 0; } else { - String *s = SwigType_str(d,0); + String *s = SwigType_str(d, 0); Chop(s); - Printf(returns,"<%s>",s); + Printf(returns, "<%s>", s); Delete(s); num_results = 1; } - + /* Open prototype and signature */ - - Printv(f->def, "static SCM\n", wname," (", NIL); + + Printv(f->def, "static SCM\n", wname, " (", NIL); if (args_passed_as_array) { Printv(f->def, "int argc, SCM *argv", NIL); } Printv(signature, proc_name, NIL); - + /* Now write code to extract the parameters */ - + for (i = 0, p = l; i < numargs; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - - SwigType *pt = Getattr(p,"type"); + + SwigType *pt = Getattr(p, "type"); int opt_p = (i >= numreq); - + // Produce names of source and target if (args_passed_as_array) sprintf(source, "argv[%d]", i); else - sprintf(source,"s_%d",i); - String *target = Getattr(p,"lname"); + sprintf(source, "s_%d", i); + String *target = Getattr(p, "lname"); if (!args_passed_as_array) { - if (i!=0) Printf(f->def,", "); - Printf(f->def,"SCM s_%d", i); + if (i != 0) + Printf(f->def, ", "); + Printf(f->def, "SCM s_%d", i); } if (opt_p) { - Printf(f->code," if (%s != SCM_UNDEFINED) {\n", source); + Printf(f->code, " if (%s != SCM_UNDEFINED) {\n", source); } - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$source",source); - Replaceall(tm,"$target",target); - Replaceall(tm,"$input",source); - Setattr(p,"emit:input", source); - Printv(f->code,tm,"\n",NIL); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", target); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + Printv(f->code, tm, "\n", NIL); SwigType *pb = SwigType_typedef_resolve_all(SwigType_base(pt)); - SwigType *pn = Getattr(p,"name"); + SwigType *pn = Getattr(p, "name"); String *argname; scheme_argnum++; if (pn && !Getattr(scheme_arg_names, pn)) @@ -802,18 +770,16 @@ public: /* Anonymous arg or re-used argument name -- choose a name that cannot clash */ argname = NewStringf("%%arg%d", scheme_argnum); } - + if (procdoc) { if (i == numreq) { /* First optional argument */ Printf(signature, " #:optional"); } /* Add to signature (arglist) */ - handle_documentation_typemap(signature, " ", p, "tmap:in:arglist", - "$name", argname); + handle_documentation_typemap(signature, " ", p, "tmap:in:arglist", "$name", argname); /* Document the type of the arg in the documentation body */ - handle_documentation_typemap(doc_body, ", ", p, "tmap:in:doc", - "$NAME is of type <$type>", argname); + handle_documentation_typemap(doc_body, ", ", p, "tmap:in:doc", "$NAME is of type <$type>", argname); } if (goops) { @@ -821,8 +787,7 @@ public: if (strcmp("void", Char(pt)) != 0) { Node *class_node = Swig_symbol_clookup_check(pb, Getattr(n, "sym:symtab"), has_classname); - String *goopsclassname = (class_node == NULL) ? NULL : - Getattr(class_node, "guile:goopsclassname"); + String *goopsclassname = (class_node == NULL) ? NULL : Getattr(class_node, "guile:goopsclassname"); /* do input conversion */ if (goopsclassname) { Printv(method_signature, " (", argname, " ", goopsclassname, ")", NIL); @@ -835,63 +800,61 @@ public: } } } - + if (!pn) { Delete(argname); } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } else { - throw_unhandled_guile_type_error (pt); + throw_unhandled_guile_type_error(pt); p = nextSibling(p); } if (opt_p) - Printf(f->code," }\n"); + Printf(f->code, " }\n"); } if (Len(doc_body) > 0) Printf(doc_body, ".\n"); - + /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } /* Pass output arguments back to the caller. */ - + /* Insert argument output code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target",Getattr(p,"lname")); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", Getattr(p, "lname")); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); if (procdoc) { - if (handle_documentation_typemap(returns, ", ", - p, "tmap:argout:doc", - "$NAME (of type $type)")) { + if (handle_documentation_typemap(returns, ", ", p, "tmap:argout:doc", "$NAME (of type $type)")) { /* A documentation typemap that is not the empty string indicates that a value is returned to Scheme. */ num_results++; } } - p = Getattr(p,"tmap:argout:next"); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -900,224 +863,197 @@ public: if (use_scm_interface && exporting_destructor) { /* Mark the destructor's argument as destroyed. */ String *tm = NewString("SWIG_Guile_MarkPointerDestroyed($input);"); - Replaceall(tm,"$input",Getattr(l,"emit:input")); + Replaceall(tm, "$input", Getattr(l, "emit:input")); Printv(cleanup, tm, "\n", NIL); Delete(tm); } - + /* Close prototype */ - + Printf(f->def, ")\n{\n"); - + /* Define the scheme name in C. This define is used by several Guile macros. */ Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - + // Now write code to make the function call if (!use_scm_interface) Printv(f->code, tab4, "gh_defer_ints();\n", NIL); - emit_action(n,f); + emit_action(n, f); if (!use_scm_interface) Printv(f->code, tab4, "gh_allow_ints();\n", NIL); - + // Now have return value, figure out what to do with it. - - if ((tm = Getattr(n,"tmap:out"))) { - Replaceall(tm,"$result","gswig_result"); - Replaceall(tm,"$target","gswig_result"); - Replaceall(tm,"$source","result"); + + if ((tm = Getattr(n, "tmap:out"))) { + Replaceall(tm, "$result", "gswig_result"); + Replaceall(tm, "$target", "gswig_result"); + Replaceall(tm, "$source", "result"); if (GetFlag(n, "feature:new")) - Replaceall(tm, "$owner", "1"); - else - Replaceall(tm, "$owner", "0"); - Printv(f->code,tm,"\n",NIL); + Replaceall(tm, "$owner", "1"); + else + Replaceall(tm, "$owner", "0"); + Printv(f->code, tm, "\n", NIL); + } else { + throw_unhandled_guile_type_error(d); } - else { - throw_unhandled_guile_type_error (d); - } - + // Dump the argument output code - Printv(f->code,outarg,NIL); - + Printv(f->code, outarg, NIL); + // Dump the argument cleanup code - Printv(f->code,cleanup,NIL); - + Printv(f->code, cleanup, NIL); + // Look for any remaining cleanup - - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printv(f->code,tm,"\n",NIL); + + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); } } - // Free any memory allocated by the function being wrapped.. - if ((tm = Swig_typemap_lookup_new("ret",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printv(f->code,tm,"\n",NIL); + if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); } - // Wrap things up (in a manner of speaking) - + if (beforereturn) Printv(f->code, beforereturn, "\n", NIL); Printv(f->code, "return gswig_result;\n", NIL); - + /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); + Replaceall(f->code, "$symname", iname); // Undefine the scheme name - + Printf(f->code, "#undef FUNC_NAME\n"); Printf(f->code, "}\n"); - - Wrapper_print (f, f_wrappers); - + + Wrapper_print(f, f_wrappers); + if (!Getattr(n, "sym:overloaded")) { - if (numargs > 10) { - int i; - /* gh_new_procedure would complain: too many args */ - /* Build a wrapper wrapper */ - Printv(f_wrappers, "static SCM\n", wname,"_rest (SCM rest)\n", NIL); - Printv(f_wrappers, "{\n", NIL); - Printf(f_wrappers, "SCM arg[%d];\n", numargs); - Printf(f_wrappers, "SWIG_Guile_GetArgs (arg, rest, %d, %d, \"%s\");\n", - numreq, numargs-numreq, proc_name); - Printv(f_wrappers, "return ", wname, "(", NIL); - Printv(f_wrappers, "arg[0]", NIL); - for (i = 1; i3) { - int len = Len(proc_name); - const char *pc = Char(proc_name); - /* MEMBER-set and MEMBER-get functions. */ - int is_setter = (pc[len - 3] == 's'); - if (is_setter) { - Printf(f_init, "SCM setter = "); - struct_member = 2; /* have a setter */ - } - else Printf(f_init, "SCM getter = "); - if (use_scm_interface) { - /* GOOPS support uses the MEMBER-set and MEMBER-get functions, - so ignore only_setters in this case. */ - if (only_setters && !goops) - Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", - proc_name, numreq, numargs-numreq, wname); - else - Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", - proc_name, numreq, numargs-numreq, wname); - } else { - if (only_setters && !goops) - Printf(f_init, "scm_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", - proc_name, numreq, numargs-numreq, wname); - else - Printf (f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", - proc_name, wname, numreq, numargs-numreq); - } - if (!is_setter) { - /* Strip off "-get" */ - char *pws_name = (char*) malloc(sizeof(char) * (len - 3)); - strncpy(pws_name, pc, len - 3); - pws_name[len - 4] = 0; - if (struct_member==2) { - /* There was a setter, so create a procedure with setter */ - if (use_scm_interface) { - Printf(f_init, "scm_c_define"); - } else { - Printf(f_init, "gh_define"); - } - Printf (f_init, "(\"%s\", " - "scm_make_procedure_with_setter(getter, setter));\n", - pws_name); + if (numargs > 10) { + int i; + /* gh_new_procedure would complain: too many args */ + /* Build a wrapper wrapper */ + Printv(f_wrappers, "static SCM\n", wname, "_rest (SCM rest)\n", NIL); + Printv(f_wrappers, "{\n", NIL); + Printf(f_wrappers, "SCM arg[%d];\n", numargs); + Printf(f_wrappers, "SWIG_Guile_GetArgs (arg, rest, %d, %d, \"%s\");\n", numreq, numargs - numreq, proc_name); + Printv(f_wrappers, "return ", wname, "(", NIL); + Printv(f_wrappers, "arg[0]", NIL); + for (i = 1; i < numargs; i++) + Printf(f_wrappers, ", arg[%d]", i); + Printv(f_wrappers, ");\n", NIL); + Printv(f_wrappers, "}\n", NIL); + /* Register it */ + if (use_scm_interface) { + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s_rest);\n", proc_name, wname); + } else { + Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s_rest, 0, 0, 1);\n", proc_name, wname, numreq, numargs - numreq); } - else { - /* There was no setter, so make an alias to the getter */ - if (use_scm_interface) { - Printf(f_init, "scm_c_define"); - } else { - Printf(f_init, "gh_define"); - } - Printf (f_init, "(\"%s\", getter);\n", - pws_name); + } else if (emit_setters && struct_member && strlen(Char(proc_name)) > 3) { + int len = Len(proc_name); + const char *pc = Char(proc_name); + /* MEMBER-set and MEMBER-get functions. */ + int is_setter = (pc[len - 3] == 's'); + if (is_setter) { + Printf(f_init, "SCM setter = "); + struct_member = 2; /* have a setter */ + } else + Printf(f_init, "SCM getter = "); + if (use_scm_interface) { + /* GOOPS support uses the MEMBER-set and MEMBER-get functions, + so ignore only_setters in this case. */ + if (only_setters && !goops) + Printf(f_init, "scm_c_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + else + Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + } else { + if (only_setters && !goops) + Printf(f_init, "scm_make_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + else + Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq); + } + if (!is_setter) { + /* Strip off "-get" */ + char *pws_name = (char *) malloc(sizeof(char) * (len - 3)); + strncpy(pws_name, pc, len - 3); + pws_name[len - 4] = 0; + if (struct_member == 2) { + /* There was a setter, so create a procedure with setter */ + if (use_scm_interface) { + Printf(f_init, "scm_c_define"); + } else { + Printf(f_init, "gh_define"); + } + Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(getter, setter));\n", pws_name); + } else { + /* There was no setter, so make an alias to the getter */ + if (use_scm_interface) { + Printf(f_init, "scm_c_define"); + } else { + Printf(f_init, "gh_define"); + } + Printf(f_init, "(\"%s\", getter);\n", pws_name); + } + Printf(exported_symbols, "\"%s\", ", pws_name); + free(pws_name); } - Printf (exported_symbols, "\"%s\", ", pws_name); - free(pws_name); - } - } - else { - /* Register the function */ - if (use_scm_interface) { - if (exporting_destructor) { - Printf(f_init, - "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", - swigtype_ptr, wname); - //Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); - } - Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", - proc_name, numreq, numargs-numreq, wname); } else { - Printf (f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", - proc_name, wname, numreq, numargs-numreq); + /* Register the function */ + if (use_scm_interface) { + if (exporting_destructor) { + Printf(f_init, "((swig_guile_clientdata *)(SWIGTYPE%s->clientdata))->destroy = (guile_destructor) %s;\n", swigtype_ptr, wname); + //Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); + } + Printf(f_init, "scm_c_define_gsubr(\"%s\", %d, %d, 0, (swig_guile_proc) %s);\n", proc_name, numreq, numargs - numreq, wname); + } else { + Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, %d, %d, 0);\n", proc_name, wname, numreq, numargs - numreq); + } } - } - } - else { /* overloaded function; don't export the single methods */ - if (!Getattr(n,"sym:nextSibling")) { + } else { /* overloaded function; don't export the single methods */ + if (!Getattr(n, "sym:nextSibling")) { /* Emit overloading dispatch function */ int maxargs; - String *dispatch = Swig_overload_dispatch(n,"return %s(argc,argv);",&maxargs); - + String *dispatch = Swig_overload_dispatch(n, "return %s(argc,argv);", &maxargs); + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *df = NewWrapper(); - String *dname = Swig_name_wrapper(iname); + Wrapper *df = NewWrapper(); + String *dname = Swig_name_wrapper(iname); - Printv(df->def, - "static SCM\n", dname, - "(SCM rest)\n{\n", - NIL); + Printv(df->def, "static SCM\n", dname, "(SCM rest)\n{\n", NIL); Printf(df->code, "#define FUNC_NAME \"%s\"\n", proc_name); Printf(df->code, "SCM argv[%d];\n", maxargs); - Printf(df->code, "int argc = SWIG_Guile_GetArgs (argv, rest, %d, %d, \"%s\");\n", - 0, maxargs, proc_name); - Printv(df->code,dispatch,"\n",NIL); - Printf(df->code,"scm_misc_error(\"%s\", \"No matching method for generic function `%s'\", SCM_EOL);\n", proc_name, iname); + Printf(df->code, "int argc = SWIG_Guile_GetArgs (argv, rest, %d, %d, \"%s\");\n", 0, maxargs, proc_name); + Printv(df->code, dispatch, "\n", NIL); + Printf(df->code, "scm_misc_error(\"%s\", \"No matching method for generic function `%s'\", SCM_EOL);\n", proc_name, iname); Printf(df->code, "#undef FUNC_NAME\n"); - Printv(df->code,"}\n",NIL); - Wrapper_print(df,f_wrappers); - if (use_scm_interface) { - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", - proc_name, dname); - } else { - Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 0, 1);\n", - proc_name, dname); - } + Printv(df->code, "}\n", NIL); + Wrapper_print(df, f_wrappers); + if (use_scm_interface) { + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, 0, 1, (swig_guile_proc) %s);\n", proc_name, dname); + } else { + Printf(f_init, "gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 0, 1);\n", proc_name, dname); + } DelWrapper(df); Delete(dispatch); Delete(dname); } } - Printf (exported_symbols, "\"%s\", ", proc_name); + Printf(exported_symbols, "\"%s\", ", proc_name); if (!in_class || memberfunction_name) { - // export wrapper into goops file + // export wrapper into goops file String *method_def = NewString(""); String *goops_name; if (in_class) goops_name = NewString(memberfunction_name); else - goops_name = goopsNameMapping(proc_name, (char *)""); + goops_name = goopsNameMapping(proc_name, (char *) ""); String *primitive_name = NewString(""); if (primRenamer) Printv(primitive_name, "primitive:", proc_name, NIL); @@ -1129,24 +1065,20 @@ public: /* If there would not be any specialized argument in the method declaration, we simply re-export the function. This is a performance optimization. */ - Printv(method_def, "(define ", goops_name, " ", - primitive_name, ")\n", NIL); - } - else if (numreq == numargs) { + Printv(method_def, "(define ", goops_name, " ", primitive_name, ")\n", NIL); + } else if (numreq == numargs) { Printv(method_def, "(define-method (", goops_name, method_signature, ")\n", NIL); - Printv(method_def, " (", primitive_name, primitive_args, "))\n", NIL); - } - else { + Printv(method_def, " (", primitive_name, primitive_args, "))\n", NIL); + } else { /* Handle optional args. For the rest argument, use a name - that cannot clash.*/ + that cannot clash. */ Printv(method_def, "(define-method (", goops_name, method_signature, " . %args)\n", NIL); Printv(method_def, " (apply ", primitive_name, primitive_args, " %args))\n", NIL); } if (in_class) { /* Defer method definition till end of class definition. */ Printv(goops_class_methods, method_def, NIL); - } - else { + } else { Printv(goopscode, method_def, NIL); } Printf(goopsexport, "%s ", goops_name); @@ -1154,17 +1086,21 @@ public: Delete(goops_name); Delete(method_def); } - + if (procdoc) { String *returns_text = NewString(""); - if (num_results == 0) Printv(returns_text, return_nothing_doc, NIL); - else if (num_results == 1) Printv(returns_text, return_one_doc, NIL); - else Printv(returns_text, return_multi_doc, NIL); + if (num_results == 0) + Printv(returns_text, return_nothing_doc, NIL); + else if (num_results == 1) + Printv(returns_text, return_one_doc, NIL); + else + Printv(returns_text, return_multi_doc, NIL); /* Substitute documentation variables */ - static const char *numbers[] = {"zero", "one", "two", "three", - "four", "five", "six", "seven", - "eight", "nine", "ten", "eleven", - "twelve"}; + static const char *numbers[] = { "zero", "one", "two", "three", + "four", "five", "six", "seven", + "eight", "nine", "ten", "eleven", + "twelve" + }; if (num_results <= 12) Replaceall(returns_text, "$num_values", numbers[num_results]); else { @@ -1177,7 +1113,7 @@ public: write_doc(proc_name, signature, doc_body); Delete(returns_text); } - + Delete(proc_name); Delete(outarg); Delete(cleanup); @@ -1191,7 +1127,7 @@ public: DelWrapper(f); return SWIG_OK; } - + /* ------------------------------------------------------------ * variableWrapper() * @@ -1205,16 +1141,17 @@ public: virtual int variableWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + String *proc_name; Wrapper *f; - String *tm; - - if (!addSymbol(iname,n)) return SWIG_ERROR; - + String *tm; + + if (!addSymbol(iname, n)) + return SWIG_ERROR; + f = NewWrapper(); // evaluation function names @@ -1222,190 +1159,172 @@ public: // Build the name for scheme. proc_name = NewString(iname); - Replaceall(proc_name,"_", "-"); - + Replaceall(proc_name, "_", "-"); + if (1 || (SwigType_type(t) != T_USER) || (is_a_pointer(t))) { - - Printf (f->def, "static SCM\n%s(SCM s_0)\n{\n", var_name); - + + Printf(f->def, "static SCM\n%s(SCM s_0)\n{\n", var_name); + /* Define the scheme name in C. This define is used by several Guile - macros. */ + macros. */ Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - - Wrapper_add_local (f, "gswig_result", "SCM gswig_result"); - - if (!GetFlag(n,"feature:immutable")) { + + Wrapper_add_local(f, "gswig_result", "SCM gswig_result"); + + if (!GetFlag(n, "feature:immutable")) { /* Check for a setting of the variable value */ - Printf (f->code, "if (s_0 != SCM_UNDEFINED) {\n"); - if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { - Replaceall(tm,"$source","s_0"); - Replaceall(tm,"$input","s_0"); - Replaceall(tm,"$target",name); + Printf(f->code, "if (s_0 != SCM_UNDEFINED) {\n"); + if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { + Replaceall(tm, "$source", "s_0"); + Replaceall(tm, "$input", "s_0"); + Replaceall(tm, "$target", name); /* Printv(f->code,tm,"\n",NIL); */ emit_action_code(n, f, tm); + } else { + throw_unhandled_guile_type_error(t); } - else { - throw_unhandled_guile_type_error (t); - } - Printf (f->code, "}\n"); + Printf(f->code, "}\n"); } - // Now return the value of the variable (regardless // of evaluating or setting) - - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source",name); - Replaceall(tm,"$target","gswig_result"); - Replaceall(tm,"$result", "gswig_result"); + + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "gswig_result"); + Replaceall(tm, "$result", "gswig_result"); /* Printv(f->code,tm,"\n",NIL); */ emit_action_code(n, f, tm); + } else { + throw_unhandled_guile_type_error(t); } - else { - throw_unhandled_guile_type_error (t); - } - Printf (f->code, "\nreturn gswig_result;\n"); - Printf (f->code, "#undef FUNC_NAME\n"); - Printf (f->code, "}\n"); - - Wrapper_print (f, f_wrappers); - + Printf(f->code, "\nreturn gswig_result;\n"); + Printf(f->code, "#undef FUNC_NAME\n"); + Printf(f->code, "}\n"); + + Wrapper_print(f, f_wrappers); + // Now add symbol to the Guile interpreter - - if (!emit_setters - || GetFlag(n,"feature:immutable")) { + + if (!emit_setters || GetFlag(n, "feature:immutable")) { /* Read-only variables become a simple procedure returning the value; read-write variables become a simple procedure with an optional argument. */ - if (use_scm_interface) { + if (use_scm_interface) { - if (!goops && GetFlag(n, "feature:constasvar")) { - /* need to export this function as a variable instead of a procedure */ - if (scmstub) { - /* export the function in the wrapper, and (set!) it in scmstub */ - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", - proc_name, !GetFlag(n, "feature:immutable"), var_name); - Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name); - } else { - /* export the variable directly */ - Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name); - } + if (!goops && GetFlag(n, "feature:constasvar")) { + /* need to export this function as a variable instead of a procedure */ + if (scmstub) { + /* export the function in the wrapper, and (set!) it in scmstub */ + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name); + Printf(scmtext, "(set! %s (%s))\n", proc_name, proc_name); + } else { + /* export the variable directly */ + Printf(f_init, "scm_c_define(\"%s\", %s(SCM_UNDEFINED));\n", proc_name, var_name); + } - } else { - /* Export the function as normal */ - Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", - proc_name, !GetFlag(n, "feature:immutable"), var_name); - } - - } else { - Printf (f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", - proc_name, var_name, !GetFlag(n,"feature:immutable")); - } - } - else { + } else { + /* Export the function as normal */ + Printf(f_init, "scm_c_define_gsubr(\"%s\", 0, %d, 0, (swig_guile_proc) %s);\n", proc_name, !GetFlag(n, "feature:immutable"), var_name); + } + + } else { + Printf(f_init, "\t gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, %d, 0);\n", proc_name, var_name, !GetFlag(n, "feature:immutable")); + } + } else { /* Read/write variables become a procedure with setter. */ - if (use_scm_interface) { - Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", - proc_name, var_name); - Printf(f_init, "scm_c_define"); - } else { - Printf (f_init, "\t{ SCM p = gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 1, 0);\n", - proc_name, var_name); - Printf(f_init, "gh_define"); - } - Printf (f_init, "(\"%s\", " - "scm_make_procedure_with_setter(p, p)); }\n", - proc_name); + if (use_scm_interface) { + Printf(f_init, "{ SCM p = scm_c_define_gsubr(\"%s\", 0, 1, 0, (swig_guile_proc) %s);\n", proc_name, var_name); + Printf(f_init, "scm_c_define"); + } else { + Printf(f_init, "\t{ SCM p = gh_new_procedure(\"%s\", (swig_guile_proc) %s, 0, 1, 0);\n", proc_name, var_name); + Printf(f_init, "gh_define"); + } + Printf(f_init, "(\"%s\", " "scm_make_procedure_with_setter(p, p)); }\n", proc_name); } - Printf (exported_symbols, "\"%s\", ", proc_name); + Printf(exported_symbols, "\"%s\", ", proc_name); // export wrapper into goops file - if (!in_class) { // only if the variable is not part of a class - String *class_name = SwigType_typedef_resolve_all(SwigType_base(t)); - String *goops_name = goopsNameMapping(proc_name, (char*)""); + if (!in_class) { // only if the variable is not part of a class + String *class_name = SwigType_typedef_resolve_all(SwigType_base(t)); + String *goops_name = goopsNameMapping(proc_name, (char *) ""); String *primitive_name = NewString(""); - if (primRenamer) + if (primRenamer) Printv(primitive_name, "primitive:", NIL); Printv(primitive_name, proc_name, NIL); /* Simply re-export the procedure */ - if ( (!emit_setters || GetFlag(n, "feature:immutable")) - && GetFlag(n, "feature:constasvar")) { - Printv(goopscode, "(define ", goops_name, " (", primitive_name, "))\n", NIL); - } else { - Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL); - } - Printf(goopsexport, "%s ", goops_name); + if ((!emit_setters || GetFlag(n, "feature:immutable")) + && GetFlag(n, "feature:constasvar")) { + Printv(goopscode, "(define ", goops_name, " (", primitive_name, "))\n", NIL); + } else { + Printv(goopscode, "(define ", goops_name, " ", primitive_name, ")\n", NIL); + } + Printf(goopsexport, "%s ", goops_name); Delete(primitive_name); - Delete(class_name); - Delete(goops_name); + Delete(class_name); + Delete(goops_name); } - + if (procdoc) { /* Compute documentation */ String *signature = NewString(""); String *signature2 = NULL; String *doc = NewString(""); - - if (GetFlag(n,"feature:immutable")) { + + if (GetFlag(n, "feature:immutable")) { Printv(signature, proc_name, NIL); - if (GetFlag(n, "feature:constasvar")) { - Printv(doc, "Is constant ", NIL); - } else { - Printv(doc, "Returns constant ", NIL); - } - if ((tm = Getattr(n,"tmap:varout:doc"))) { - Printv(doc,tm,NIL); + if (GetFlag(n, "feature:constasvar")) { + Printv(doc, "Is constant ", NIL); } else { - String *s = SwigType_str(t,0); + Printv(doc, "Returns constant ", NIL); + } + if ((tm = Getattr(n, "tmap:varout:doc"))) { + Printv(doc, tm, NIL); + } else { + String *s = SwigType_str(t, 0); Chop(s); - Printf(doc,"<%s>",s); + Printf(doc, "<%s>", s); Delete(s); } - } - else if (emit_setters) { + } else if (emit_setters) { Printv(signature, proc_name, NIL); signature2 = NewString(""); Printv(signature2, "set! (", proc_name, ") ", NIL); - handle_documentation_typemap(signature2, NIL, n, "tmap:varin:arglist", - "new-value"); + handle_documentation_typemap(signature2, NIL, n, "tmap:varin:arglist", "new-value"); Printv(doc, "Get or set the value of the C variable, \n", NIL); Printv(doc, "which is of type ", NIL); - handle_documentation_typemap(doc, NIL, n, "tmap:varout:doc", - "$1_type"); + handle_documentation_typemap(doc, NIL, n, "tmap:varout:doc", "$1_type"); Printv(doc, "."); - } - else { - Printv(signature, proc_name, - " #:optional ", NIL); - if ((tm = Getattr(n,"tmap:varin:doc"))) { - Printv(signature,tm,NIL); + } else { + Printv(signature, proc_name, " #:optional ", NIL); + if ((tm = Getattr(n, "tmap:varin:doc"))) { + Printv(signature, tm, NIL); } else { - String *s = SwigType_str(t,0); + String *s = SwigType_str(t, 0); Chop(s); - Printf(signature,"new-value <%s>",s); + Printf(signature, "new-value <%s>", s); Delete(s); } - - Printv(doc, "If NEW-VALUE is provided, " - "set C variable to this value.\n", NIL); + + Printv(doc, "If NEW-VALUE is provided, " "set C variable to this value.\n", NIL); Printv(doc, "Returns variable value ", NIL); - if ((tm = Getattr(n,"tmap:varout:doc"))) { - Printv(doc,tm,NIL); + if ((tm = Getattr(n, "tmap:varout:doc"))) { + Printv(doc, tm, NIL); } else { - String *s = SwigType_str(t,0); + String *s = SwigType_str(t, 0); Chop(s); - Printf(doc,"<%s>",s); + Printf(doc, "<%s>", s); Delete(s); } } write_doc(proc_name, signature, doc, signature2); Delete(signature); - if (signature2) Delete(signature2); + if (signature2) + Delete(signature2); Delete(doc); } - + } else { - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, - "Unsupported variable type %s (ignored).\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported variable type %s (ignored).\n", SwigType_str(t, 0)); } Delete(var_name); Delete(proc_name); @@ -1420,45 +1339,42 @@ public: * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *value = Getattr(n,"value"); - int constasvar = GetFlag(n, "feature:constasvar"); + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + int constasvar = GetFlag(n, "feature:constasvar"); + - String *proc_name; String *var_name; String *rvalue; Wrapper *f; SwigType *nctype; - String *tm; - + String *tm; + f = NewWrapper(); // Make a static variable; var_name = NewStringf("%sconst_%s", prefix, iname); // Strip const qualifier from type if present - + nctype = NewString(type); if (SwigType_isconst(nctype)) { Delete(SwigType_pop(nctype)); } - // Build the name for scheme. proc_name = NewString(iname); - Replaceall(proc_name,"_", "-"); - + Replaceall(proc_name, "_", "-"); + if ((SwigType_type(nctype) == T_USER) && (!is_a_pointer(nctype))) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); Delete(var_name); return SWIG_NOWRAP; } - // See if there's a typemap - + if (SwigType_type(nctype) == T_STRING) { rvalue = NewStringf("\"%s\"", value); } else if (SwigType_type(nctype) == T_CHAR) { @@ -1466,26 +1382,25 @@ public: } else { rvalue = NewString(value); } - - if ((tm = Swig_typemap_lookup_new("constant",n,name,0))) { - Replaceall(tm,"$source",rvalue); - Replaceall(tm,"$value",rvalue); - Replaceall(tm,"$target",name); - Printv(f_header,tm,"\n",NIL); + + if ((tm = Swig_typemap_lookup_new("constant", n, name, 0))) { + Replaceall(tm, "$source", rvalue); + Replaceall(tm, "$value", rvalue); + Replaceall(tm, "$target", name); + Printv(f_header, tm, "\n", NIL); } else { // Create variable and assign it a value - Printf (f_header, "static %s = %s;\n", SwigType_lstr(nctype,var_name), - rvalue); + Printf(f_header, "static %s = %s;\n", SwigType_lstr(nctype, var_name), rvalue); } { /* Hack alert: will cleanup later -- Dave */ Node *n = NewHash(); - Setattr(n,"name",var_name); - Setattr(n,"sym:name",iname); - Setattr(n,"type", nctype); - SetFlag(n,"feature:immutable"); + Setattr(n, "name", var_name); + Setattr(n, "sym:name", iname); + Setattr(n, "type", nctype); + SetFlag(n, "feature:immutable"); if (constasvar) { - SetFlag(n,"feature:constasvar"); + SetFlag(n, "feature:constasvar"); } variableWrapper(n); Delete(n); @@ -1513,39 +1428,40 @@ public: virtual int classHandler(Node *n) { /* Create new strings for building up a wrapper function */ have_constructor = 0; - + class_name = NewString(""); short_class_name = NewString(""); - Printv(class_name, "<", Getattr(n,"sym:name"), ">", NIL); - Printv(short_class_name, Getattr(n,"sym:name"), NIL); + Printv(class_name, "<", Getattr(n, "sym:name"), ">", NIL); + Printv(short_class_name, Getattr(n, "sym:name"), NIL); Replaceall(class_name, "_", "-"); Replaceall(short_class_name, "_", "-"); - - if (!addSymbol(class_name,n)) return SWIG_ERROR; + + if (!addSymbol(class_name, n)) + return SWIG_ERROR; /* Handle inheritance */ String *base_class = NewString("<"); - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator i = First(baselist); while (i.item) { - Printv(base_class,Getattr(i.item, "sym:name"),NIL); - i = Next(i); - if (i.item) { - Printf(base_class, "> <"); - } + Printv(base_class, Getattr(i.item, "sym:name"), NIL); + i = Next(i); + if (i.item) { + Printf(base_class, "> <"); + } } } Printf(base_class, ">"); Replaceall(base_class, "_", "-"); - Printv(goopscode,"(define-class ", class_name, " ", NIL); + Printv(goopscode, "(define-class ", class_name, " ", NIL); Printf(goopsexport, "%s ", class_name); if (Len(base_class) > 2) { - Printv(goopscode,"(", base_class, ")\n", NIL); + Printv(goopscode, "(", base_class, ")\n", NIL); } else { - Printv(goopscode,"()\n", NIL); + Printv(goopscode, "()\n", NIL); } SwigType *ct = NewStringf("p.%s", Getattr(n, "name")); swigtype_ptr = SwigType_manglestr(ct); @@ -1553,11 +1469,9 @@ public: String *mangled_classname = Swig_name_mangle(Getattr(n, "sym:name")); /* Export clientdata structure */ if (use_scm_interface) { - Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", - mangled_classname); + Printf(f_runtime, "static swig_guile_clientdata _swig_guile_clientdata%s = { NULL, SCM_EOL };\n", mangled_classname); - Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, - ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL); + Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", swigtype_ptr, ", (void *) &_swig_guile_clientdata", mangled_classname, ");\n", NIL); SwigType_remember(ct); } Delete(ct); @@ -1569,13 +1483,12 @@ public: Language::classHandler(n); in_class = 0; - Printv(goopscode," #:metaclass \n",NIL); - + Printv(goopscode, " #:metaclass \n", NIL); + if (have_constructor) - Printv(goopscode," #:new-function ", primRenamer ? "primitive:" : "", - "new-", short_class_name, "\n", NIL); - - Printf(goopscode,")\n%s\n", goops_class_methods); + Printv(goopscode, " #:new-function ", primRenamer ? "primitive:" : "", "new-", short_class_name, "\n", NIL); + + Printf(goopscode, ")\n%s\n", goops_class_methods); Delete(goops_class_methods); goops_class_methods = 0; @@ -1590,13 +1503,11 @@ public: Printv(f_wrappers, "static SCM ", funcName, "(SCM cl) \n", NIL); Printf(f_wrappers, "#define FUNC_NAME %s\n{\n", guileFuncName); - Printv(f_wrappers, " ((swig_guile_clientdata *)(SWIGTYPE", swigtype_ptr, - "->clientdata))->goops_class = cl;\n", NIL); + Printv(f_wrappers, " ((swig_guile_clientdata *)(SWIGTYPE", swigtype_ptr, "->clientdata))->goops_class = cl;\n", NIL); Printf(f_wrappers, " return SCM_UNSPECIFIED;\n"); Printf(f_wrappers, "}\n#undef FUNC_NAME\n\n"); - Printf(f_init, "scm_c_define_gsubr(\"%s\", 1, 0, 0, (swig_guile_proc) %s);\n", - guileFuncName, funcName); + Printf(f_init, "scm_c_define_gsubr(\"%s\", 1, 0, 0, (swig_guile_proc) %s);\n", guileFuncName, funcName); Printf(exported_symbols, "\"%s\", ", guileFuncName); /* export the call to the wrapper function */ @@ -1623,9 +1534,9 @@ public: * memberfunctionHandler() * ------------------------------------------------------------ */ int memberfunctionHandler(Node *n) { - String *iname = Getattr(n,"sym:name"); + String *iname = Getattr(n, "sym:name"); String *proc = NewString(iname); - Replaceall(proc,"_", "-"); + Replaceall(proc, "_", "-"); memberfunction_name = goopsNameMapping(proc, short_class_name); Language::memberfunctionHandler(n); @@ -1638,9 +1549,8 @@ public: /* ------------------------------------------------------------ * membervariableHandler() * ------------------------------------------------------------ */ - int membervariableHandler(Node *n) - { - String *iname = Getattr(n,"sym:name"); + int membervariableHandler(Node *n) { + String *iname = Getattr(n, "sym:name"); if (emit_setters) { struct_member = 1; @@ -1655,7 +1565,7 @@ public: } String *proc = NewString(iname); - Replaceall(proc,"_", "-"); + Replaceall(proc, "_", "-"); String *goops_name = goopsNameMapping(proc, short_class_name); /* The slot name is never qualified with the class, @@ -1663,21 +1573,17 @@ public: Printv(goopscode, " (", proc, " #:allocation #:virtual", NIL); /* GOOPS (at least in Guile 1.6.3) only accepts closures, not primitive procedures for slot-ref and slot-set. */ - Printv(goopscode, "\n #:slot-ref (lambda (obj) (", - primRenamer ? "primitive:" : "", - short_class_name, "-", proc, "-get", " obj))", NIL); - if (!GetFlag(n,"feature:immutable")) { - Printv(goopscode, "\n #:slot-set! (lambda (obj value) (", - primRenamer ? "primitive:" : "", - short_class_name, "-", proc, "-set", " obj value))", NIL); + Printv(goopscode, "\n #:slot-ref (lambda (obj) (", primRenamer ? "primitive:" : "", short_class_name, "-", proc, "-get", " obj))", NIL); + if (!GetFlag(n, "feature:immutable")) { + Printv(goopscode, "\n #:slot-set! (lambda (obj value) (", primRenamer ? "primitive:" : "", short_class_name, "-", proc, "-set", " obj value))", NIL); } else { Printf(goopscode, "\n #:slot-set! (lambda (obj value) (error \"Immutable slot\"))"); } if (emit_slot_accessors) { if (GetFlag(n, "feature:immutable")) { - Printv(goopscode, "\n #:getter ", goops_name, NIL); + Printv(goopscode, "\n #:getter ", goops_name, NIL); } else { - Printv(goopscode, "\n #:accessor ", goops_name, NIL); + Printv(goopscode, "\n #:accessor ", goops_name, NIL); } Printf(goopsexport, "%s ", goops_name); } @@ -1710,31 +1616,30 @@ public: * pragmaDirective() * ------------------------------------------------------------ */ - virtual int pragmaDirective(Node *n) - { + virtual int pragmaDirective(Node *n) { if (!ImportMode) { - String *lang = Getattr(n,"lang"); - String *cmd = Getattr(n,"name"); - String *value = Getattr(n,"value"); - + String *lang = Getattr(n, "lang"); + String *cmd = Getattr(n, "name"); + String *value = Getattr(n, "value"); + # define store_pragma(PRAGMANAME) \ if (Strcmp(cmd, #PRAGMANAME) == 0) { \ if (PRAGMANAME) Delete(PRAGMANAME); \ PRAGMANAME = value ? NewString(value) : NULL; \ } - - if (Strcmp(lang,"guile") == 0) { + + if (Strcmp(lang, "guile") == 0) { store_pragma(beforereturn) - store_pragma(return_nothing_doc) - store_pragma(return_one_doc) - store_pragma(return_multi_doc); + store_pragma(return_nothing_doc) + store_pragma(return_one_doc) + store_pragma(return_multi_doc); # undef store_pragma } } return Language::pragmaDirective(n); } - + /* ------------------------------------------------------------ * goopsNameMapping() * Maps the identifier from C++ to the GOOPS based * on command @@ -1744,23 +1649,23 @@ public: * ------------------------------------------------------------ */ String *goopsNameMapping(String *name, String_or_char *class_name) { String *n = NewString(""); - + if (Strcmp(class_name, "") == 0) { // not part of a class, so no class name to prefix if (goopsprefix) { - Printf(n, "%s%s", goopsprefix, name); + Printf(n, "%s%s", goopsprefix, name); } else { - Printf(n, "%s", name); + Printf(n, "%s", name); } } else { if (useclassprefix) { - Printf(n, "%s-%s", class_name, name); + Printf(n, "%s-%s", class_name, name); } else { - if (goopsprefix) { - Printf(n, "%s%s", goopsprefix, name); - } else { - Printf(n, "%s", name); - } + if (goopsprefix) { + Printf(n, "%s%s", goopsprefix, name); + } else { + Printf(n, "%s", name); + } } } return n; @@ -1784,9 +1689,10 @@ public: || (*c == '^') || (*c == '_') || (*c == '~'))) { /* --> + | - | ... */ if ((strcmp(c, "+") == 0) - || strcmp(c, "-") == 0 - || strcmp(c, "...") == 0) return 1; - else return 0; + || strcmp(c, "-") == 0 || strcmp(c, "...") == 0) + return 1; + else + return 0; } /* --> | | */ while (*c) { @@ -1794,7 +1700,8 @@ public: || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') || (*c == '^') || (*c == '_') || (*c == '~') || (*c == '+') - || (*c == '-') || (*c == '.') || (*c == '@'))) return 0; + || (*c == '-') || (*c == '.') || (*c == '@'))) + return 0; c++; } return 1; @@ -1805,14 +1712,14 @@ public: if (use_scm_interface) { s = Swig_include_sys("guile_scm_run.swg"); if (!s) { - Printf(stderr, "*** Unable to open 'guile_scm_run.swg"); - s = NewString(""); + Printf(stderr, "*** Unable to open 'guile_scm_run.swg"); + s = NewString(""); } } else { s = Swig_include_sys("guile_gh_run.swg"); if (!s) { - Printf(stderr, "*** Unable to open 'guile_gh_run.swg"); - s = NewString(""); + Printf(stderr, "*** Unable to open 'guile_gh_run.swg"); + s = NewString(""); } } return s; @@ -1831,9 +1738,9 @@ public: * swig_guile() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_guile() { +static Language *new_swig_guile() { return new GUILE(); } -extern "C" Language * swig_guile(void) { +extern "C" Language *swig_guile(void) { return new_swig_guile(); } diff --git a/SWIG/Source/Modules/java.cxx b/SWIG/Source/Modules/java.cxx index 96f700702..b4e0ccad8 100644 --- a/SWIG/Source/Modules/java.cxx +++ b/SWIG/Source/Modules/java.cxx @@ -10,145 +10,139 @@ char cvsroot_java_cxx[] = "$Header$"; #include "swigmod.h" -#include // for INT_MAX +#include // for INT_MAX #include "cparse.h" #include /* Hash type used for upcalls from C/C++ */ typedef DOH UpcallData; -class JAVA : public Language { +class JAVA:public Language { static const char *usage; - const String *empty_string; - const String *public_string; - const String *protected_string; + const String *empty_string; + const String *public_string; + const String *protected_string; - Hash *swig_types_hash; - File *f_runtime; - File *f_runtime_h; - File *f_header; - File *f_wrappers; - File *f_init; - File *f_directors; - File *f_directors_h; - List *filenames_list; + Hash *swig_types_hash; + File *f_runtime; + File *f_runtime_h; + File *f_header; + File *f_wrappers; + File *f_init; + File *f_directors; + File *f_directors_h; + List *filenames_list; - bool proxy_flag; // Flag for generating proxy classes - bool nopgcpp_flag; // Flag for suppressing the premature garbage collection prevention parameter - bool native_function_flag; // Flag for when wrapping a native function - bool enum_constant_flag; // Flag for when wrapping an enum or constant - bool static_flag; // Flag for when wrapping a static functions or member variables - bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable - bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const - bool global_variable_flag; // Flag for when wrapping a global variable - bool old_variable_names; // Flag for old style variable names in the intermediary class - bool member_func_flag; // flag set when wrapping a member function + bool proxy_flag; // Flag for generating proxy classes + bool nopgcpp_flag; // Flag for suppressing the premature garbage collection prevention parameter + bool native_function_flag; // Flag for when wrapping a native function + bool enum_constant_flag; // Flag for when wrapping an enum or constant + bool static_flag; // Flag for when wrapping a static functions or member variables + bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable + bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const + bool global_variable_flag; // Flag for when wrapping a global variable + bool old_variable_names; // Flag for old style variable names in the intermediary class + bool member_func_flag; // flag set when wrapping a member function - String *imclass_name; // intermediary class name - String *module_class_name; // module class name - String *imclass_class_code; // intermediary class code + String *imclass_name; // intermediary class name + String *module_class_name; // module class name + String *imclass_class_code; // intermediary class code String *proxy_class_def; String *proxy_class_code; String *module_class_code; String *proxy_class_name; - String *variable_name; //Name of a variable being wrapped + String *variable_name; //Name of a variable being wrapped String *proxy_class_constants_code; String *module_class_constants_code; String *enum_code; - String *package; // Optional package name - String *jnipackage; // Package name used in the JNI code - String *package_path; // Package name used internally by JNI (slashes) - String *imclass_imports; //intermediary class imports from %pragma - String *module_imports; //module imports from %pragma - String *imclass_baseclass; //inheritance for intermediary class class from %pragma - String *module_baseclass; //inheritance for module class from %pragma - String *imclass_interfaces; //interfaces for intermediary class class from %pragma - String *module_interfaces; //interfaces for module class from %pragma - String *imclass_class_modifiers; //class modifiers for intermediary class overriden by %pragma - String *module_class_modifiers; //class modifiers for module class overriden by %pragma - String *upcasts_code; //C++ casts for inheritance hierarchies C++ code - String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code - String *imclass_directors; // Intermediate class director code - String *destructor_call; //C++ destructor call if any + String *package; // Optional package name + String *jnipackage; // Package name used in the JNI code + String *package_path; // Package name used internally by JNI (slashes) + String *imclass_imports; //intermediary class imports from %pragma + String *module_imports; //module imports from %pragma + String *imclass_baseclass; //inheritance for intermediary class class from %pragma + String *module_baseclass; //inheritance for module class from %pragma + String *imclass_interfaces; //interfaces for intermediary class class from %pragma + String *module_interfaces; //interfaces for module class from %pragma + String *imclass_class_modifiers; //class modifiers for intermediary class overriden by %pragma + String *module_class_modifiers; //class modifiers for module class overriden by %pragma + String *upcasts_code; //C++ casts for inheritance hierarchies C++ code + String *imclass_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code + String *imclass_directors; // Intermediate class director code + String *destructor_call; //C++ destructor call if any // Director method stuff: - List *dmethods_seq; - Hash *dmethods_table; - int n_dmethods; - int n_directors; - int first_class_dmethod; - int curr_class_dmethod; + List *dmethods_seq; + Hash *dmethods_table; + int n_dmethods; + int n_directors; + int first_class_dmethod; + int curr_class_dmethod; enum EnumFeature { SimpleEnum, TypeunsafeEnum, TypesafeEnum, ProperEnum }; - public: +public: /* ----------------------------------------------------------------------------- * JAVA() * ----------------------------------------------------------------------------- */ - JAVA() : - empty_string(NewString("")), - public_string(NewString("public")), - protected_string(NewString("protected")), - - swig_types_hash(NULL), - f_runtime(NULL), - f_runtime_h(NULL), - f_header(NULL), - f_wrappers(NULL), - f_init(NULL), - f_directors(NULL), - f_directors_h(NULL), - filenames_list(NULL), - - proxy_flag(true), - nopgcpp_flag(false), - native_function_flag(false), - enum_constant_flag(false), - static_flag(false), - variable_wrapper_flag(false), - wrapping_member_flag(false), - global_variable_flag(false), - old_variable_names (false), - member_func_flag(false), - - imclass_name(NULL), - module_class_name(NULL), - imclass_class_code(NULL), - proxy_class_def(NULL), - proxy_class_code(NULL), - module_class_code(NULL), - proxy_class_name(NULL), - variable_name(NULL), - proxy_class_constants_code(NULL), - module_class_constants_code(NULL), - package(NULL), - jnipackage(NULL), - package_path(NULL), - imclass_imports(NULL), - module_imports(NULL), - imclass_baseclass(NULL), - module_baseclass(NULL), - imclass_interfaces(NULL), - module_interfaces(NULL), - imclass_class_modifiers(NULL), - module_class_modifiers(NULL), - upcasts_code(NULL), - imclass_cppcasts_code(NULL), - imclass_directors(NULL), - destructor_call(NULL), - - dmethods_seq(NULL), - dmethods_table(NULL), - n_dmethods(0), - n_directors(0) - { - /* for now, multiple inheritance in directors is disabled, this - should be easy to implement though */ - director_multiple_inheritance = 0; - director_language = 1; - } + JAVA():empty_string(NewString("")), + public_string(NewString("public")), + protected_string(NewString("protected")), + swig_types_hash(NULL), + f_runtime(NULL), + f_runtime_h(NULL), + f_header(NULL), + f_wrappers(NULL), + f_init(NULL), + f_directors(NULL), + f_directors_h(NULL), + filenames_list(NULL), + proxy_flag(true), + nopgcpp_flag(false), + native_function_flag(false), + enum_constant_flag(false), + static_flag(false), + variable_wrapper_flag(false), + wrapping_member_flag(false), + global_variable_flag(false), + old_variable_names(false), + member_func_flag(false), + imclass_name(NULL), + module_class_name(NULL), + imclass_class_code(NULL), + proxy_class_def(NULL), + proxy_class_code(NULL), + module_class_code(NULL), + proxy_class_name(NULL), + variable_name(NULL), + proxy_class_constants_code(NULL), + module_class_constants_code(NULL), + package(NULL), + jnipackage(NULL), + package_path(NULL), + imclass_imports(NULL), + module_imports(NULL), + imclass_baseclass(NULL), + module_baseclass(NULL), + imclass_interfaces(NULL), + module_interfaces(NULL), + imclass_class_modifiers(NULL), + module_class_modifiers(NULL), + upcasts_code(NULL), + imclass_cppcasts_code(NULL), + imclass_directors(NULL), + destructor_call(NULL), + dmethods_seq(NULL), + dmethods_table(NULL), + n_dmethods(0), + n_directors(0) { + /* for now, multiple inheritance in directors is disabled, this + should be easy to implement though */ + director_multiple_inheritance = 0; + director_language = 1; + } /* ----------------------------------------------------------------------------- * getProxyName() @@ -156,12 +150,12 @@ class JAVA : public Language { * Test to see if a type corresponds to something wrapped with a proxy class * Return NULL if not otherwise the proxy class name * ----------------------------------------------------------------------------- */ - - String *getProxyName(SwigType *t) { + + String *getProxyName(SwigType *t) { if (proxy_flag) { Node *n = classLookup(t); if (n) { - return Getattr(n,"sym:name"); + return Getattr(n, "sym:name"); } } return NULL; @@ -173,7 +167,7 @@ class JAVA : public Language { String *makeValidJniName(const String *name) { String *valid_jni_name = NewString(name); - Replaceall(valid_jni_name,"_","_1"); + Replaceall(valid_jni_name, "_", "_1"); return valid_jni_name; } @@ -206,46 +200,46 @@ class JAVA : public Language { // Look for certain command line options for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i],"-package") == 0) { - if (argv[i+1]) { - package = NewString(""); - Printf(package, argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) { - Printf(stderr,"Deprecated command line option: %s. Proxy classes are now generated by default.\n", argv[i]); - Swig_mark_arg(i); - proxy_flag = true; - } else if ((strcmp(argv[i],"-noproxy") == 0)) { - Swig_mark_arg(i); - proxy_flag = false; - } else if (strcmp(argv[i],"-nopgcpp") == 0) { - Swig_mark_arg(i); + if (strcmp(argv[i], "-package") == 0) { + if (argv[i + 1]) { + package = NewString(""); + Printf(package, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if ((strcmp(argv[i], "-shadow") == 0) || ((strcmp(argv[i], "-proxy") == 0))) { + Printf(stderr, "Deprecated command line option: %s. Proxy classes are now generated by default.\n", argv[i]); + Swig_mark_arg(i); + proxy_flag = true; + } else if ((strcmp(argv[i], "-noproxy") == 0)) { + Swig_mark_arg(i); + proxy_flag = false; + } else if (strcmp(argv[i], "-nopgcpp") == 0) { + Swig_mark_arg(i); nopgcpp_flag = true; - } else if (strcmp(argv[i],"-oldvarnames") == 0) { - Swig_mark_arg(i); + } else if (strcmp(argv[i], "-oldvarnames") == 0) { + Swig_mark_arg(i); old_variable_names = true; - } else if (strcmp(argv[i],"-jnic") == 0) { - Swig_mark_arg(i); - Printf(stderr,"Deprecated command line option: -jnic. C JNI calling convention now used when -c++ not specified.\n"); - } else if (strcmp(argv[i],"-nofinalize") == 0) { - Swig_mark_arg(i); - Printf(stderr,"Deprecated command line option: -nofinalize. Use the new javafinalize typemap instead.\n"); - } else if (strcmp(argv[i],"-jnicpp") == 0) { - Swig_mark_arg(i); - Printf(stderr,"Deprecated command line option: -jnicpp. C++ JNI calling convention now used when -c++ specified.\n"); - } else if (strcmp(argv[i],"-help") == 0) { - Printf(stdout,"%s\n", usage); - } + } else if (strcmp(argv[i], "-jnic") == 0) { + Swig_mark_arg(i); + Printf(stderr, "Deprecated command line option: -jnic. C JNI calling convention now used when -c++ not specified.\n"); + } else if (strcmp(argv[i], "-nofinalize") == 0) { + Swig_mark_arg(i); + Printf(stderr, "Deprecated command line option: -nofinalize. Use the new javafinalize typemap instead.\n"); + } else if (strcmp(argv[i], "-jnicpp") == 0) { + Swig_mark_arg(i); + Printf(stderr, "Deprecated command line option: -jnicpp. C++ JNI calling convention now used when -c++ specified.\n"); + } else if (strcmp(argv[i], "-help") == 0) { + Printf(stdout, "%s\n", usage); + } } } // Add a symbol to the parser for conditional compilation - Preprocessor_define("SWIGJAVA 1",0); + Preprocessor_define("SWIGJAVA 1", 0); // Add typemap definitions SWIG_typemap_lang("java"); @@ -261,11 +255,11 @@ class JAVA : public Language { virtual int top(Node *n) { // Get any options set in the module directive - Node* optionsnode = Getattr( Getattr(n,"module"), "options"); + Node *optionsnode = Getattr(Getattr(n, "module"), "options"); if (optionsnode) { - if (Getattr(optionsnode,"jniclassname")) - imclass_name = Copy(Getattr(optionsnode,"jniclassname")); + if (Getattr(optionsnode, "jniclassname")) + imclass_name = Copy(Getattr(optionsnode, "jniclassname")); /* check if directors are enabled for this module. note: this * is a "master" switch, without which no director code will be * emitted. %feature("director") statements are also required @@ -275,28 +269,28 @@ class JAVA : public Language { * interface file to enable director generation. */ if (Getattr(optionsnode, "directors")) { - allow_directors(); + allow_directors(); } if (Getattr(optionsnode, "dirprot")) { - allow_dirprot(); + allow_dirprot(); } } /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); + String *outfile = Getattr(n, "outfile"); String *outfile_h = Getattr(n, "outfile_h"); - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); } if (directorsEnabled()) { - f_runtime_h = NewFile(outfile_h,"w"); + f_runtime_h = NewFile(outfile_h, "w"); if (!f_runtime_h) { - FileErrorDisplay(outfile_h); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(outfile_h); + SWIG_exit(EXIT_FAILURE); } } @@ -307,26 +301,26 @@ class JAVA : public Language { f_directors = NewString(""); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - Swig_register_filebyname("director",f_directors); - Swig_register_filebyname("director_h",f_directors_h); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); swig_types_hash = NewHash(); filenames_list = NewList(); // Make the intermediary class and module class names. The intermediary class name can be set in the module directive. if (!imclass_name) { - imclass_name = NewStringf("%sJNI", Getattr(n,"name")); - module_class_name = Copy(Getattr(n,"name")); + imclass_name = NewStringf("%sJNI", Getattr(n, "name")); + module_class_name = Copy(Getattr(n, "name")); } else { // Rename the module name if it is the same as intermediary class name - a backwards compatibility solution - if (Cmp(imclass_name, Getattr(n,"name")) == 0) - module_class_name = NewStringf("%sModule", Getattr(n,"name")); + if (Cmp(imclass_name, Getattr(n, "name")) == 0) + module_class_name = NewStringf("%sModule", Getattr(n, "name")); else - module_class_name = Copy(Getattr(n,"name")); + module_class_name = Copy(Getattr(n, "name")); } imclass_class_code = NewString(""); @@ -349,14 +343,15 @@ class JAVA : public Language { dmethods_table = NewHash(); n_dmethods = 0; n_directors = 0; - if (!package) package = NewString(""); + if (!package) + package = NewString(""); jnipackage = NewString(""); package_path = NewString(""); - Swig_banner(f_runtime); // Print the SWIG banner message + Swig_banner(f_runtime); // Print the SWIG banner message if (directorsEnabled()) { - Printf(f_runtime,"#define SWIG_DIRECTORS\n"); + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); /* Emit initial director header and director code: */ Swig_banner(f_directors_h); @@ -373,11 +368,11 @@ class JAVA : public Language { String *wrapper_name = NewString(""); - if(Len(package)) { + if (Len(package)) { String *jniname = makeValidJniName(package); Printv(jnipackage, jniname, NIL); Delete(jniname); - Replaceall(jnipackage,".","_"); + Replaceall(jnipackage, ".", "_"); Append(jnipackage, "_"); Printv(package_path, package, NIL); Replaceall(package_path, ".", "/"); @@ -386,17 +381,17 @@ class JAVA : public Language { Printf(wrapper_name, "Java_%s%s_%%f", Char(jnipackage), jniname); Delete(jniname); - Swig_name_register((char*)"wrapper", Char(wrapper_name)); + Swig_name_register((char *) "wrapper", Char(wrapper_name)); if (old_variable_names) { - Swig_name_register((char*)"set", (char*)"set_%v"); - Swig_name_register((char*)"get", (char*)"get_%v"); + Swig_name_register((char *) "set", (char *) "set_%v"); + Swig_name_register((char *) "get", (char *) "get_%v"); } Delete(wrapper_name); - Printf(f_wrappers,"\n#ifdef __cplusplus\n"); - Printf(f_wrappers,"extern \"C\" {\n"); - Printf(f_wrappers,"#endif\n\n"); + Printf(f_wrappers, "\n#ifdef __cplusplus\n"); + Printf(f_wrappers, "extern \"C\" {\n"); + Printf(f_wrappers, "#endif\n\n"); /* Emit code */ Language::top(n); @@ -405,35 +400,35 @@ class JAVA : public Language { // Insert director runtime into the f_runtime file (make it occur before %header section) Swig_insert_file("director.swg", f_runtime); } - // Generate the intermediary class { String *filen = NewStringf("%s%s.java", SWIG_output_directory(), imclass_name); - File *f_im = NewFile(filen,"w"); - if(!f_im) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + File *f_im = NewFile(filen, "w"); + if (!f_im) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the intermediary class file emitBanner(f_im); - if(Len(package) > 0) - Printf(f_im, "package %s;\n", package); + if (Len(package) > 0) + Printf(f_im, "package %s;\n", package); - if(imclass_imports) - Printf(f_im, "%s\n", imclass_imports); + if (imclass_imports) + Printf(f_im, "%s\n", imclass_imports); if (Len(imclass_class_modifiers) > 0) - Printf(f_im, "%s ", imclass_class_modifiers); + Printf(f_im, "%s ", imclass_class_modifiers); Printf(f_im, "%s ", imclass_name); if (imclass_baseclass && *Char(imclass_baseclass)) - Printf(f_im, "extends %s ", imclass_baseclass); + Printf(f_im, "extends %s ", imclass_baseclass); if (Len(imclass_interfaces) > 0) - Printv(f_im, "implements ", imclass_interfaces, " ", NIL); + Printv(f_im, "implements ", imclass_interfaces, " ", NIL); Printf(f_im, "{\n"); // Add the intermediary class methods @@ -442,16 +437,15 @@ class JAVA : public Language { Printv(f_im, imclass_class_code, NIL); Printv(f_im, imclass_cppcasts_code, NIL); if (Len(imclass_directors) > 0) - Printv(f_im, "\n", imclass_directors, NIL); + Printv(f_im, "\n", imclass_directors, NIL); if (n_dmethods > 0) { - Putc('\n', f_im); - Printf(f_im, " private final static native void swig_module_init();\n"); - Printf(f_im, " static {\n"); - Printf(f_im, " swig_module_init();\n"); - Printf(f_im, " }\n"); + Putc('\n', f_im); + Printf(f_im, " private final static native void swig_module_init();\n"); + Printf(f_im, " static {\n"); + Printf(f_im, " swig_module_init();\n"); + Printf(f_im, " }\n"); } - // Finish off the class Printf(f_im, "}\n"); Close(f_im); @@ -460,37 +454,38 @@ class JAVA : public Language { // Generate the Java module class { String *filen = NewStringf("%s%s.java", SWIG_output_directory(), module_class_name); - File *f_module = NewFile(filen,"w"); - if(!f_module) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + File *f_module = NewFile(filen, "w"); + if (!f_module) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the module class file emitBanner(f_module); - if(Len(package) > 0) - Printf(f_module, "package %s;\n", package); + if (Len(package) > 0) + Printf(f_module, "package %s;\n", package); - if(module_imports) - Printf(f_module, "%s\n", module_imports); + if (module_imports) + Printf(f_module, "%s\n", module_imports); if (Len(module_class_modifiers) > 0) - Printf(f_module, "%s ", module_class_modifiers); + Printf(f_module, "%s ", module_class_modifiers); Printf(f_module, "%s ", module_class_name); if (module_baseclass && *Char(module_baseclass)) - Printf(f_module, "extends %s ", module_baseclass); + Printf(f_module, "extends %s ", module_baseclass); if (Len(module_interfaces) > 0) { - if (Len(module_class_constants_code) != 0 ) - Printv(f_module, "implements ", Getattr(n, "name"), "Constants, ", module_interfaces, " ", NIL); - else - Printv(f_module, "implements ", module_interfaces, " ", NIL); + if (Len(module_class_constants_code) != 0) + Printv(f_module, "implements ", Getattr(n, "name"), "Constants, ", module_interfaces, " ", NIL); + else + Printv(f_module, "implements ", module_interfaces, " ", NIL); } else { - if (Len(module_class_constants_code) != 0 ) - Printv(f_module, "implements ", Getattr(n, "name"), "Constants ", NIL); + if (Len(module_class_constants_code) != 0) + Printv(f_module, "implements ", Getattr(n, "name"), "Constants ", NIL); } Printf(f_module, "{\n"); @@ -509,24 +504,25 @@ class JAVA : public Language { } // Generate the Java constants interface - if (Len(module_class_constants_code) != 0 ) { + if (Len(module_class_constants_code) != 0) { String *filen = NewStringf("%s%sConstants.java", SWIG_output_directory(), module_class_name); - File *f_module = NewFile(filen,"w"); - if(!f_module) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + File *f_module = NewFile(filen, "w"); + if (!f_module) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the Java constants interface file emitBanner(f_module); - if(Len(package) > 0) - Printf(f_module, "package %s;\n", package); + if (Len(package) > 0) + Printf(f_module, "package %s;\n", package); - if(module_imports) - Printf(f_module, "%s\n", module_imports); + if (module_imports) + Printf(f_module, "%s\n", module_imports); Printf(f_module, "public interface %sConstants {\n", module_class_name); @@ -538,14 +534,14 @@ class JAVA : public Language { Close(f_module); } - if(upcasts_code) - Printv(f_wrappers,upcasts_code,NIL); + if (upcasts_code) + Printv(f_wrappers, upcasts_code, NIL); emitDirectorUpcalls(); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"}\n"); - Printf(f_wrappers,"#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "}\n"); + Printf(f_wrappers, "#endif\n"); // Output a Java type wrapper class for each SWIG type for (Iterator swig_type = First(swig_types_hash); swig_type.key; swig_type = Next(swig_type)) { @@ -558,48 +554,73 @@ class JAVA : public Language { for (it1 = First(filenames_list); it1.item; it1 = Next(it1)) { String *item1_lower = Swig_string_lower(it1.item); for (it2 = Next(it1); it2.item; it2 = Next(it2)) { - String *item2_lower = Swig_string_lower(it2.item); - if (it1.item && it2.item) { - if (Strcmp(item1_lower, item2_lower) == 0) { - Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number, - "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as " - "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item); - } - } - Delete(item2_lower); + String *item2_lower = Swig_string_lower(it2.item); + if (it1.item && it2.item) { + if (Strcmp(item1_lower, item2_lower) == 0) { + Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number, + "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as " + "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item); + } + } + Delete(item2_lower); } Delete(item1_lower); } - Delete(swig_types_hash); swig_types_hash = NULL; - Delete(filenames_list); filenames_list = NULL; - Delete(imclass_name); imclass_name = NULL; - Delete(imclass_class_code); imclass_class_code = NULL; - Delete(proxy_class_def); proxy_class_def = NULL; - Delete(proxy_class_code); proxy_class_code = NULL; - Delete(module_class_constants_code); module_class_constants_code = NULL; - Delete(imclass_baseclass); imclass_baseclass = NULL; - Delete(imclass_interfaces); imclass_interfaces = NULL; - Delete(imclass_class_modifiers); imclass_class_modifiers = NULL; - Delete(module_class_name); module_class_name = NULL; - Delete(module_class_code); module_class_code = NULL; - Delete(module_baseclass); module_baseclass = NULL; - Delete(module_interfaces); module_interfaces = NULL; - Delete(module_imports); module_imports = NULL; - Delete(module_class_modifiers); module_class_modifiers = NULL; - Delete(imclass_imports); imclass_imports = NULL; - Delete(imclass_cppcasts_code); imclass_cppcasts_code = NULL; - Delete(imclass_directors); imclass_directors = NULL; - Delete(upcasts_code); upcasts_code = NULL; - Delete(package); package = NULL; - Delete(jnipackage); jnipackage = NULL; - Delete(package_path); package_path = NULL; - Delete(dmethods_seq); dmethods_seq = NULL; - Delete(dmethods_table); dmethods_table = NULL; + Delete(swig_types_hash); + swig_types_hash = NULL; + Delete(filenames_list); + filenames_list = NULL; + Delete(imclass_name); + imclass_name = NULL; + Delete(imclass_class_code); + imclass_class_code = NULL; + Delete(proxy_class_def); + proxy_class_def = NULL; + Delete(proxy_class_code); + proxy_class_code = NULL; + Delete(module_class_constants_code); + module_class_constants_code = NULL; + Delete(imclass_baseclass); + imclass_baseclass = NULL; + Delete(imclass_interfaces); + imclass_interfaces = NULL; + Delete(imclass_class_modifiers); + imclass_class_modifiers = NULL; + Delete(module_class_name); + module_class_name = NULL; + Delete(module_class_code); + module_class_code = NULL; + Delete(module_baseclass); + module_baseclass = NULL; + Delete(module_interfaces); + module_interfaces = NULL; + Delete(module_imports); + module_imports = NULL; + Delete(module_class_modifiers); + module_class_modifiers = NULL; + Delete(imclass_imports); + imclass_imports = NULL; + Delete(imclass_cppcasts_code); + imclass_cppcasts_code = NULL; + Delete(imclass_directors); + imclass_directors = NULL; + Delete(upcasts_code); + upcasts_code = NULL; + Delete(package); + package = NULL; + Delete(jnipackage); + jnipackage = NULL; + Delete(package_path); + package_path = NULL; + Delete(dmethods_seq); + dmethods_seq = NULL; + Delete(dmethods_table); + dmethods_table = NULL; n_dmethods = 0; /* Close all of the files */ - Dump(f_header,f_runtime); + Dump(f_header, f_runtime); if (directorsEnabled()) { Dump(f_directors, f_runtime); @@ -609,13 +630,16 @@ class JAVA : public Language { Printf(f_runtime_h, "#endif\n"); Close(f_runtime_h); - Delete(f_runtime_h); f_runtime_h = NULL; - Delete(f_directors); f_directors = NULL; - Delete(f_directors_h); f_directors_h = NULL; + Delete(f_runtime_h); + f_runtime_h = NULL; + Delete(f_directors); + f_directors = NULL; + Delete(f_directors_h); + f_directors_h = NULL; } - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); @@ -642,13 +666,13 @@ class JAVA : public Language { * Add new director upcall signature *----------------------------------------------------------------------*/ - UpcallData * addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) { - UpcallData *udata; - String *imclass_methodidx; - String *class_methodidx; - Hash *new_udata; - String *key = NewStringf("%s|%s", imclass_method, decl); - + UpcallData *addUpcallMethod(String *imclass_method, String *class_method, String *imclass_desc, String *class_desc, String *decl) { + UpcallData *udata; + String *imclass_methodidx; + String *class_methodidx; + Hash *new_udata; + String *key = NewStringf("%s|%s", imclass_method, decl); + ++curr_class_dmethod; /* Do we know about this director class already? */ @@ -681,9 +705,9 @@ class JAVA : public Language { * Get director upcall signature *----------------------------------------------------------------------*/ - UpcallData * getUpcallMethodData(String *director_class, String *decl) { - String *key = NewStringf("%s|%s", director_class, decl); - UpcallData *udata = Getattr(dmethods_table, key); + UpcallData *getUpcallMethodData(String *director_class, String *decl) { + String *key = NewStringf("%s|%s", director_class, decl); + UpcallData *udata = Getattr(dmethods_table, key); Delete(key); return udata; @@ -694,19 +718,20 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int nativeWrapper(Node *n) { - String *wrapname = Getattr(n,"wrap:name"); + String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname,n)) return SWIG_ERROR; + if (!addSymbol(wrapname, n)) + return SWIG_ERROR; - if (Getattr(n,"type")) { - Swig_save("nativeWrapper",n,"name",NIL); - Setattr(n,"name", wrapname); + if (Getattr(n, "type")) { + Swig_save("nativeWrapper", n, "name", NIL); + Setattr(n, "name", wrapname); native_function_flag = true; functionWrapper(n); Swig_restore(n); native_function_flag = false; } else { - Printf(stderr,"%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n,"wrap:name")); + Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); } return SWIG_OK; @@ -717,34 +742,35 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int functionWrapper(Node *n) { - String *symname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - int i; - String *c_return_type = NewString(""); - String *im_return_type = NewString(""); - String *cleanup = NewString(""); - String *outarg = NewString(""); - String *body = NewString(""); - int num_arguments = 0; - int num_required = 0; - int gencomma = 0; - bool is_void_return; - String *overloaded_name = getOverloadedName(n); - String *nondir_args = NewString(""); - bool is_destructor = (Cmp(Getattr(n, "nodeType"), "destructor") == 0); + String *symname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + int i; + String *c_return_type = NewString(""); + String *im_return_type = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); + String *body = NewString(""); + int num_arguments = 0; + int num_required = 0; + int gencomma = 0; + bool is_void_return; + String *overloaded_name = getOverloadedName(n); + String *nondir_args = NewString(""); + bool is_destructor = (Cmp(Getattr(n, "nodeType"), "destructor") == 0); - if (!Getattr(n,"sym:overloaded")) { - if (!addSymbol(Getattr(n,"sym:name"),n)) return SWIG_ERROR; + if (!Getattr(n, "sym:overloaded")) { + if (!addSymbol(Getattr(n, "sym:name"), n)) + return SWIG_ERROR; } /* The rest of this function deals with generating the intermediary class wrapper function (that wraps a c/c++ function) and generating the JNI c code. Each Java wrapper function has a matching JNI c function call. - */ + */ // A new wrapper function object Wrapper *f = NewWrapper(); @@ -760,94 +786,91 @@ class JAVA : public Language { Swig_typemap_attach_parms("jtype", l, f); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("jni",n,"",0))) { - Printf(c_return_type,"%s", tm); + if ((tm = Swig_typemap_lookup_new("jni", n, "", 0))) { + Printf(c_return_type, "%s", tm); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, - "No jni typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(t, 0)); } - if ((tm = Swig_typemap_lookup_new("jtype",n,"",0))) { - Printf(im_return_type,"%s", tm); + if ((tm = Swig_typemap_lookup_new("jtype", n, "", 0))) { + Printf(im_return_type, "%s", tm); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, - "No jtype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(t, 0)); } is_void_return = (Cmp(c_return_type, "void") == 0); if (!is_void_return) - Wrapper_add_localv(f,"jresult", c_return_type, "jresult = 0",NIL); + Wrapper_add_localv(f, "jresult", c_return_type, "jresult = 0", NIL); Printv(f->def, "SWIGEXPORT ", c_return_type, " JNICALL ", wname, "(JNIEnv *jenv, jclass jcls", NIL); // Usually these function parameters are unused - The code below ensures // that compilers do not issue such a warning if configured to do so. - Printv(f->code," (void)jenv;\n",NIL); - Printv(f->code," (void)jcls;\n",NIL); + Printv(f->code, " (void)jenv;\n", NIL); + Printv(f->code, " (void)jcls;\n", NIL); // Emit all of the local variables for holding arguments. - emit_args(t,l,f); + emit_args(t, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); + emit_attach_parmmaps(l, f); // Parameter overloading - Setattr(n,"wrap:parms",l); - Setattr(n,"wrap:name", wname); + Setattr(n, "wrap:parms", l); + Setattr(n, "wrap:name", wname); // Wrappers not wanted for some methods where the parameters cannot be overloaded in Java - if (Getattr(n,"sym:overloaded")) { + if (Getattr(n, "sym:overloaded")) { // Emit warnings for the few cases that can't be overloaded in Java and give up on generating wrapper - Swig_overload_check(n); - if (Getattr(n, "overload:ignore")) - return SWIG_OK; + Swig_overload_check(n); + if (Getattr(n, "overload:ignore")) + return SWIG_OK; } Printf(imclass_class_code, " public final static native %s %s(", im_return_type, overloaded_name); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); // Now walk the function parameter list and generate code to get arguments - for (i = 0, p=l; i < num_arguments; i++) { + for (i = 0, p = l; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); - String *im_param_type = NewString(""); - String *c_param_type = NewString(""); - String *arg = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + String *im_param_type = NewString(""); + String *c_param_type = NewString(""); + String *arg = NewString(""); - Printf(arg,"j%s", ln); + Printf(arg, "j%s", ln); /* Get the JNI C types of the parameter */ - if ((tm = Getattr(p,"tmap:jni"))) { - Printv(c_param_type, tm, NIL); + if ((tm = Getattr(p, "tmap:jni"))) { + Printv(c_param_type, tm, NIL); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, - "No jni typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(pt, 0)); } /* Get the intermediary class parameter types of the parameter */ - if ((tm = Getattr(p,"tmap:jtype"))) { - Printv(im_param_type, tm, NIL); + if ((tm = Getattr(p, "tmap:jtype"))) { + Printv(im_param_type, tm, NIL); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, - "No jtype typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(pt, 0)); } /* Add parameter to intermediary class method */ - if(gencomma) Printf(imclass_class_code, ", "); + if (gencomma) + Printf(imclass_class_code, ", "); Printf(imclass_class_code, "%s %s", im_param_type, arg); // Add parameter to C function Printv(f->def, ", ", c_param_type, " ", arg, NIL); - + ++gencomma; // Premature garbage collection prevention parameter @@ -856,26 +879,24 @@ class JAVA : public Language { if (pgc_parameter) { Printf(imclass_class_code, ", %s %s_", pgc_parameter, arg); Printf(f->def, ", jobject %s_", arg); - Printf(f->code," (void)%s_;\n", arg); + Printf(f->code, " (void)%s_;\n", arg); } } - // Get typemap for this argument - if ((tm = Getattr(p,"tmap:in"))) { - addThrows(n, "tmap:in", p); - Replaceall(tm,"$source",arg); /* deprecated */ - Replaceall(tm,"$target",ln); /* deprecated */ - Replaceall(tm,"$arg",arg); /* deprecated? */ - Replaceall(tm,"$input", arg); - Setattr(p,"emit:input", arg); + if ((tm = Getattr(p, "tmap:in"))) { + addThrows(n, "tmap:in", p); + Replaceall(tm, "$source", arg); /* deprecated */ + Replaceall(tm, "$target", ln); /* deprecated */ + Replaceall(tm, "$arg", arg); /* deprecated? */ + Replaceall(tm, "$input", arg); + Setattr(p, "emit:input", arg); - Printf(nondir_args,"%s\n", tm); + Printf(nondir_args, "%s\n", tm); - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); - p = nextSibling(p); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); + p = nextSibling(p); } Delete(im_param_type); @@ -888,71 +909,70 @@ class JAVA : public Language { /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - addThrows(n, "tmap:check", p); - Replaceall(tm,"$target",Getattr(p,"lname")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + addThrows(n, "tmap:check", p); + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Insert cleanup code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - addThrows(n, "tmap:freearg", p); - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + addThrows(n, "tmap:freearg", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Insert argument output code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - addThrows(n, "tmap:argout", p); - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* deprecated */ - Replaceall(tm,"$target",Getattr(p,"lname")); /* deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); /* deprecated? */ - Replaceall(tm,"$result","jresult"); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + if ((tm = Getattr(p, "tmap:argout"))) { + addThrows(n, "tmap:argout", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$result", "jresult"); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n,"throws"))) { + if ((throw_parm_list = Getattr(n, "throws"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { - addThrows(n, "tmap:throws", p); - } + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + addThrows(n, "tmap:throws", p); + } } } if (Cmp(nodeType(n), "constant") == 0) { // Wrapping a constant hack - Swig_save("functionWrapper",n,"wrap:action",NIL); + Swig_save("functionWrapper", n, "wrap:action", NIL); // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type(Getattr(n,"type"), use_naturalvar_mode(n)); - Setattr(n,"wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty,0), Getattr(n, "value"))); + SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); + Setattr(n, "wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty, 0), Getattr(n, "value"))); } - // Now write code to make the function call - if(!native_function_flag) { - emit_action(n,f); + if (!native_function_flag) { + emit_action(n, f); // Handle exception classes specified in the "except" feature's "throws" attribute addThrows(n, "feature:except", n); } @@ -961,42 +981,41 @@ class JAVA : public Language { Swig_restore(n); /* Return value if necessary */ - if(!native_function_flag) { - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - addThrows(n, "tmap:out", n); - Replaceall(tm,"$source", "result"); /* deprecated */ - Replaceall(tm,"$target", "jresult"); /* deprecated */ - Replaceall(tm,"$result","jresult"); - Printf(f->code,"%s", tm); - if (Len(tm)) - Printf(f->code,"\n"); + if (!native_function_flag) { + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + addThrows(n, "tmap:out", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Replaceall(tm, "$target", "jresult"); /* deprecated */ + Replaceall(tm, "$result", "jresult"); + Printf(f->code, "%s", tm); + if (Len(tm)) + Printf(f->code, "\n"); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(t,0), Getattr(n,"name")); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name")); } } /* Output argument output code */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - addThrows(n, "tmap:newfree", n); - Replaceall(tm,"$source","result"); /* deprecated */ - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + addThrows(n, "tmap:newfree", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ - if(!native_function_flag) { + if (!native_function_flag) { if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - addThrows(n, "tmap:ret", n); - Replaceall(tm,"$source","result"); /* deprecated */ - Printf(f->code,"%s\n",tm); + addThrows(n, "tmap:ret", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } @@ -1005,31 +1024,31 @@ class JAVA : public Language { generateThrowsClause(n, imclass_class_code); Printf(imclass_class_code, ";\n"); - Printf(f->def,") {"); + Printf(f->def, ") {"); - if(!is_void_return) + if (!is_void_return) Printv(f->code, " return jresult;\n", NIL); Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",symname); + Replaceall(f->code, "$symname", symname); /* Contract macro modification */ Replaceall(f->code, "SWIG_contract_assert(", "SWIG_contract_assert($null, "); - if(!is_void_return) - Replaceall(f->code,"$null","0"); + if (!is_void_return) + Replaceall(f->code, "$null", "0"); else - Replaceall(f->code,"$null",""); + Replaceall(f->code, "$null", ""); /* Dump the function out */ - if(!native_function_flag) - Wrapper_print(f,f_wrappers); + if (!native_function_flag) + Wrapper_print(f, f_wrappers); - if(!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) { + if (!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) { moduleClassFunctionHandler(n); } @@ -1037,20 +1056,20 @@ class JAVA : public Language { * Generate the proxy class getters/setters for public member variables. * Not for enums and constants. */ - if(proxy_flag && wrapping_member_flag && !enum_constant_flag) { + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Capitalize the first letter in the variable to create a JavaBean type getter/setter function name bool getter_flag = Cmp(symname, Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) != 0; String *getter_setter_name = NewString(""); - if(!getter_flag) - Printf(getter_setter_name,"set"); - else - Printf(getter_setter_name,"get"); + if (!getter_flag) + Printf(getter_setter_name, "set"); + else + Printf(getter_setter_name, "get"); Putc(toupper((int) *Char(variable_name)), getter_setter_name); - Printf(getter_setter_name, "%s", Char(variable_name)+1); + Printf(getter_setter_name, "%s", Char(variable_name) + 1); - Setattr(n,"proxyfuncname", getter_setter_name); - Setattr(n,"imfuncname", symname); + Setattr(n, "proxyfuncname", getter_setter_name); + Setattr(n, "imfuncname", symname); proxyClassFunctionHandler(n); Delete(getter_setter_name); @@ -1072,7 +1091,7 @@ class JAVA : public Language { virtual int variableWrapper(Node *n) { variable_wrapper_flag = true; - Language::variableWrapper(n); /* Default to functions */ + Language::variableWrapper(n); /* Default to functions */ variable_wrapper_flag = false; return SWIG_OK; } @@ -1083,7 +1102,7 @@ class JAVA : public Language { virtual int globalvariableHandler(Node *n) { - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); global_variable_flag = true; int ret = Language::globalvariableHandler(n); global_variable_flag = false; @@ -1104,115 +1123,99 @@ class JAVA : public Language { virtual int enumDeclaration(Node *n) { if (!ImportMode) { - if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (getCurrentClass() && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; enum_code = NewString(""); - String *symname = Getattr(n,"sym:name"); - String *constants_code = (proxy_flag && is_wrapping_class()) ? proxy_class_constants_code : module_class_constants_code; + String *symname = Getattr(n, "sym:name"); + String *constants_code = (proxy_flag && is_wrapping_class())? proxy_class_constants_code : module_class_constants_code; EnumFeature enum_feature = decodeEnumFeature(n); - String *typemap_lookup_type = Getattr(n,"name"); + String *typemap_lookup_type = Getattr(n, "name"); if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { - // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum + // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum - // Pure Java baseclass and interfaces - const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE); - const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE); + // Pure Java baseclass and interfaces + const String *pure_baseclass = typemapLookup("javabase", typemap_lookup_type, WARN_NONE); + const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE); - // Emit the enum - Printv(enum_code, - typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) - " ", - symname, - *Char(pure_baseclass) ? // Bases - " extends " : - "", - pure_baseclass, - *Char(pure_interfaces) ? // Interfaces - " implements " : - "", - pure_interfaces, - " {\n", - NIL); - if (proxy_flag && is_wrapping_class()) - Replaceall(enum_code, "$static ", "static "); - else - Replaceall(enum_code, "$static ", ""); + // Emit the enum + Printv(enum_code, typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers (enum modifiers really) + " ", symname, *Char(pure_baseclass) ? // Bases + " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces + " implements " : "", pure_interfaces, " {\n", NIL); + if (proxy_flag && is_wrapping_class()) + Replaceall(enum_code, "$static ", "static "); + else + Replaceall(enum_code, "$static ", ""); } else { - // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort - if (symname && !Getattr(n,"unnamedinstance")) - Printf(constants_code, " // %s \n", symname); + // Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort + if (symname && !Getattr(n, "unnamedinstance")) + Printf(constants_code, " // %s \n", symname); } // Emit each enum item Language::enumDeclaration(n); if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { - // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum - // Finish the enum declaration - // Typemaps are used to generate the enum definition in a similar manner to proxy classes. - Printv(enum_code, - (enum_feature == ProperEnum) ? - ";\n" : - "", - typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class - typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code - "}", - NIL); + // Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper Java enum + // Finish the enum declaration + // Typemaps are used to generate the enum definition in a similar manner to proxy classes. + Printv(enum_code, (enum_feature == ProperEnum) ? ";\n" : "", typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class + typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code + "}", NIL); - Replaceall(enum_code, "$javaclassname", symname); + Replaceall(enum_code, "$javaclassname", symname); - // Substitute $enumvalues - intended usage is for typesafe enums - if (Getattr(n,"enumvalues")) - Replaceall(enum_code, "$enumvalues", Getattr(n,"enumvalues")); - else - Replaceall(enum_code, "$enumvalues", ""); + // Substitute $enumvalues - intended usage is for typesafe enums + if (Getattr(n, "enumvalues")) + Replaceall(enum_code, "$enumvalues", Getattr(n, "enumvalues")); + else + Replaceall(enum_code, "$enumvalues", ""); - if (proxy_flag && is_wrapping_class()) { - // Enums defined within the C++ class are defined within the proxy class + if (proxy_flag && is_wrapping_class()) { + // Enums defined within the C++ class are defined within the proxy class - // Add extra indentation - Replaceall(enum_code, "\n", "\n "); - Replaceall(enum_code, " \n", "\n"); + // Add extra indentation + Replaceall(enum_code, "\n", "\n "); + Replaceall(enum_code, " \n", "\n"); - Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); - } else { - // Global enums are defined in their own file - String *filen = NewStringf("%s%s.java", SWIG_output_directory(), symname); - File *f_enum = NewFile(filen,"w"); - if(!f_enum) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); - } - Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL); + } else { + // Global enums are defined in their own file + String *filen = NewStringf("%s%s.java", SWIG_output_directory(), symname); + File *f_enum = NewFile(filen, "w"); + if (!f_enum) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); + } + Append(filenames_list, Copy(filen)); + Delete(filen); + filen = NULL; - // Start writing out the enum file - emitBanner(f_enum); + // Start writing out the enum file + emitBanner(f_enum); - if(Len(package) > 0) - Printf(f_enum, "package %s;\n", package); + if (Len(package) > 0) + Printf(f_enum, "package %s;\n", package); - Printv(f_enum, - typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements - "\n", - enum_code, - "\n", - NIL); + Printv(f_enum, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements + "\n", enum_code, "\n", NIL); - Printf(f_enum, "\n"); - Close(f_enum); - } + Printf(f_enum, "\n"); + Close(f_enum); + } } else { - // Wrap C++ enum with simple constant - Printf(enum_code, "\n"); - if (proxy_flag && is_wrapping_class()) - Printv(proxy_class_constants_code, enum_code, NIL); - else - Printv(module_class_constants_code, enum_code, NIL); + // Wrap C++ enum with simple constant + Printf(enum_code, "\n"); + if (proxy_flag && is_wrapping_class()) + Printv(proxy_class_constants_code, enum_code, NIL); + else + Printv(module_class_constants_code, enum_code, NIL); } - Delete(enum_code); enum_code = NULL; + Delete(enum_code); + enum_code = NULL; } return SWIG_OK; } @@ -1222,12 +1225,13 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int enumvalueDeclaration(Node *n) { - if (getCurrentClass() && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (getCurrentClass() && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration",n,"*name", "?value",NIL); - String *symname = Getattr(n,"sym:name"); - String *value = Getattr(n,"value"); - String *name = Getattr(n,"name"); + Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + String *symname = Getattr(n, "sym:name"); + String *value = Getattr(n, "value"); + String *name = Getattr(n, "name"); String *tmpValue; // Strange hack from parent method @@ -1241,52 +1245,53 @@ class JAVA : public Language { { EnumFeature enum_feature = decodeEnumFeature(parentNode(n)); - if ((enum_feature == ProperEnum) && Getattr(parentNode(n),"sym:name") && !Getattr(parentNode(n),"unnamedinstance")) { - // Wrap (non-anonymous) C/C++ enum with a proper Java enum - // Emit the enum item. - if (!Getattr(n,"_last")) // Only the first enum item has this attribute set - Printf(enum_code, ",\n"); - Printf(enum_code, " %s", symname); - if (Getattr(n,"enumvalue")) { - String *value = enumValue(n); - Printf(enum_code, "(%s)", value); - Delete(value); - } + if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) { + // Wrap (non-anonymous) C/C++ enum with a proper Java enum + // Emit the enum item. + if (!Getattr(n, "_last")) // Only the first enum item has this attribute set + Printf(enum_code, ",\n"); + Printf(enum_code, " %s", symname); + if (Getattr(n, "enumvalue")) { + String *value = enumValue(n); + Printf(enum_code, "(%s)", value); + Delete(value); + } } else { - // Wrap C/C++ enums with constant integers or use the typesafe enum pattern - const String *parent_name = Getattr(parentNode(n),"name"); - String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); - const String *tm = typemapLookup("jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF); - String *return_type = Copy(tm); - Delete(typemap_lookup_type); typemap_lookup_type = NULL; + // Wrap C/C++ enums with constant integers or use the typesafe enum pattern + const String *parent_name = Getattr(parentNode(n), "name"); + String *typemap_lookup_type = parent_name ? Copy(parent_name) : NewString("int"); + const String *tm = typemapLookup("jstype", typemap_lookup_type, WARN_JAVA_TYPEMAP_JSTYPE_UNDEF); + String *return_type = Copy(tm); + Delete(typemap_lookup_type); + typemap_lookup_type = NULL; - if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n),"sym:name") && !Getattr(parentNode(n),"unnamedinstance")) { - // Wrap (non-anonymouse) enum using the typesafe enum pattern - if (Getattr(n,"enumvalue")) { - String *value = enumValue(n); - Printf(enum_code, " public final static %s %s = new %s(\"%s\", %s);\n", return_type, symname, return_type, symname, value); - Delete(value); - } else { - Printf(enum_code, " public final static %s %s = new %s(\"%s\");\n", return_type, symname, return_type, symname); - } - } else { - // Simple integer constants - // Note these are always generated for anonymous enums, no matter what enum_feature is specified - // Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later - String *value = enumValue(n); - Printf(enum_code, " public final static %s %s = %s;\n", return_type, symname, value); - Delete(value); - } + if ((enum_feature == TypesafeEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) { + // Wrap (non-anonymouse) enum using the typesafe enum pattern + if (Getattr(n, "enumvalue")) { + String *value = enumValue(n); + Printf(enum_code, " public final static %s %s = new %s(\"%s\", %s);\n", return_type, symname, return_type, symname, value); + Delete(value); + } else { + Printf(enum_code, " public final static %s %s = new %s(\"%s\");\n", return_type, symname, return_type, symname); + } + } else { + // Simple integer constants + // Note these are always generated for anonymous enums, no matter what enum_feature is specified + // Code generated is the same for SimpleEnum and TypeunsafeEnum -> the class it is generated into is determined later + String *value = enumValue(n); + Printf(enum_code, " public final static %s %s = %s;\n", return_type, symname, value); + Delete(value); + } } // Add the enum value to the comma separated list being constructed in the enum declaration. String *enumvalues = Getattr(parentNode(n), "enumvalues"); if (!enumvalues) - Setattr(parentNode(n), "enumvalues", Copy(symname)); + Setattr(parentNode(n), "enumvalues", Copy(symname)); else - Printv(enumvalues, ", ", symname, NIL); + Printv(enumvalues, ", ", symname, NIL); } - + Delete(tmpValue); Swig_restore(n); return SWIG_OK; @@ -1304,25 +1309,26 @@ class JAVA : public Language { * ------------------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - String *symname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *symname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); String *tm; String *return_type = NewString(""); String *constants_code = NewString(""); - if (!addSymbol(symname,n)) return SWIG_ERROR; + if (!addSymbol(symname, n)) + return SWIG_ERROR; bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); // The %javaconst feature determines how the constant value is obtained - int const_feature_flag = GetFlag(n,"feature:java:const"); + int const_feature_flag = GetFlag(n, "feature:java:const"); /* Adjust the enum type for the Swig_typemap_lookup. * We want the same jstype typemap for all the enum items so we use the enum type (parent node). */ if (is_enum_item) { - t = Getattr(parentNode(n),"enumtype"); - Setattr(n,"type", t); + t = Getattr(parentNode(n), "enumtype"); + Setattr(n, "type", t); } /* Attach the non-standard typemaps to the parameter list. */ @@ -1330,23 +1336,21 @@ class JAVA : public Language { /* Get Java return types */ bool classname_substituted_flag = false; - - if ((tm = Swig_typemap_lookup_new("jstype",n,"",0))) { + + if ((tm = Swig_typemap_lookup_new("jstype", n, "", 0))) { classname_substituted_flag = substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(t, 0)); } // Add the stripped quotes back in String *new_value = NewString(""); - Swig_save("constantWrapper",n,"value",NIL); - if(SwigType_type(t) == T_STRING) { + Swig_save("constantWrapper", n, "value", NIL); + if (SwigType_type(t) == T_STRING) { Printf(new_value, "\"%s\"", Copy(Getattr(n, "value"))); Setattr(n, "value", new_value); - } - else if(SwigType_type(t) == T_CHAR) { + } else if (SwigType_type(t) == T_CHAR) { Printf(new_value, "\'%s\'", Copy(Getattr(n, "value"))); Setattr(n, "value", new_value); } @@ -1355,43 +1359,42 @@ class JAVA : public Language { Printf(constants_code, " public final static %s %s = ", return_type, itemname); // Check for the %javaconstvalue feature - String *value = Getattr(n,"feature:java:constvalue"); + String *value = Getattr(n, "feature:java:constvalue"); if (value) { Printf(constants_code, "%s;\n", value); } else if (!const_feature_flag) { // Default enum and constant handling will work with any type of C constant and initialises the Java variable from C through a JNI call. - if(classname_substituted_flag) { - if (SwigType_isenum(t)) { - // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) - Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, imclass_name, Swig_name_get(symname)); - } else { - // This handles function pointers using the %constant directive - Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); - } + if (classname_substituted_flag) { + if (SwigType_isenum(t)) { + // This handles wrapping of inline initialised const enum static member variables (not when wrapping enum items - ignored later on) + Printf(constants_code, "%s.swigToEnum(%s.%s());\n", return_type, imclass_name, Swig_name_get(symname)); + } else { + // This handles function pointers using the %constant directive + Printf(constants_code, "new %s(%s.%s(), false);\n", return_type, imclass_name, Swig_name_get(symname)); + } } else - Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); + Printf(constants_code, "%s.%s();\n", imclass_name, Swig_name_get(symname)); // Each constant and enum value is wrapped with a separate JNI function call - SetFlag(n,"feature:immutable"); + SetFlag(n, "feature:immutable"); enum_constant_flag = true; variableWrapper(n); enum_constant_flag = false; } else { // Alternative constant handling will use the C syntax to make a true Java constant and hope that it compiles as Java code - Printf(constants_code, "%s;\n", Getattr(n,"value")); + Printf(constants_code, "%s;\n", Getattr(n, "value")); } // Emit the generated code to appropriate place // Enums only emit the intermediate and JNI methods, so no proxy or module class wrapper methods needed if (!is_enum_item) { - if(proxy_flag && wrapping_member_flag) - Printv(proxy_class_constants_code, constants_code, NIL); + if (proxy_flag && wrapping_member_flag) + Printv(proxy_class_constants_code, constants_code, NIL); else - Printv(module_class_constants_code, constants_code, NIL); + Printv(module_class_constants_code, constants_code, NIL); } - // Cleanup Swig_restore(n); Delete(new_value); @@ -1405,7 +1408,7 @@ class JAVA : public Language { * ----------------------------------------------------------------------------- */ virtual int insertDirective(Node *n) { - String *code = Getattr(n,"code"); + String *code = Getattr(n, "code"); Replaceall(code, "$module", module_class_name); Replaceall(code, "$imclassname", imclass_name); return Language::insertDirective(n); @@ -1431,99 +1434,77 @@ class JAVA : public Language { virtual int pragmaDirective(Node *n) { if (!ImportMode) { - String *lang = Getattr(n,"lang"); - String *code = Getattr(n,"name"); - String *value = Getattr(n,"value"); + String *lang = Getattr(n, "lang"); + String *code = Getattr(n, "name"); + String *value = Getattr(n, "value"); - if(Strcmp(lang, "java") == 0) { + if (Strcmp(lang, "java") == 0) { - String *strvalue = NewString(value); - Replaceall(strvalue,"\\\"", "\""); + String *strvalue = NewString(value); + Replaceall(strvalue, "\\\"", "\""); - if(Strcmp(code, "jniclassbase") == 0) { - Delete(imclass_baseclass); - imclass_baseclass = Copy(strvalue); - } - else if(Strcmp(code, "jniclassclassmodifiers") == 0) { - Delete(imclass_class_modifiers); - imclass_class_modifiers = Copy(strvalue); - } - else if(Strcmp(code, "jniclasscode") == 0) { - Printf(imclass_class_code, "%s\n", strvalue); - } - else if(Strcmp(code, "jniclassimports") == 0) { - Delete(imclass_imports); - imclass_imports = Copy(strvalue); - } - else if(Strcmp(code, "jniclassinterfaces") == 0) { - Delete(imclass_interfaces); - imclass_interfaces = Copy(strvalue); - } - else if(Strcmp(code, "modulebase") == 0) { - Delete(module_baseclass); - module_baseclass = Copy(strvalue); - } - else if(Strcmp(code, "moduleclassmodifiers") == 0) { - Delete(module_class_modifiers); - module_class_modifiers = Copy(strvalue); - } - else if(Strcmp(code, "modulecode") == 0) { - Printf(module_class_code, "%s\n", strvalue); - } - else if(Strcmp(code, "moduleimports") == 0) { - Delete(module_imports); - module_imports = Copy(strvalue); - } - else if(Strcmp(code, "moduleinterfaces") == 0) { - Delete(module_interfaces); - module_interfaces = Copy(strvalue); - } - else if(Strcmp(code, "moduleimport") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use the moduleimports pragma.\n", input_file, line_number); - } - else if(Strcmp(code, "moduleinterface") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use the moduleinterfaces pragma.\n", input_file, line_number); - } - else if(Strcmp(code, "modulemethodmodifiers") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %javamethodmodifiers.\n", input_file, line_number); - } - else if(Strcmp(code, "allshadowimport") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaimports).\n", input_file, line_number); - } - else if(Strcmp(code, "allshadowcode") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javacode).\n", input_file, line_number); - } - else if(Strcmp(code, "allshadowbase") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javabase).\n", input_file, line_number); - } - else if(Strcmp(code, "allshadowinterface") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javainterfaces).\n", input_file, line_number); - } - else if(Strcmp(code, "allshadowclassmodifiers") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaclassmodifiers).\n", input_file, line_number); - } - else if (proxy_flag) { - if (Strcmp(code,"shadowcode") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javacode).\n", input_file, line_number); - } - else if (Strcmp(code,"shadowimport") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaimports).\n", input_file, line_number); - } - else if (Strcmp(code,"shadowbase") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javabase).\n", input_file, line_number); - } - else if (Strcmp(code,"shadowinterface") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javainterfaces).\n", input_file, line_number); - } - else if (Strcmp(code,"shadowclassmodifiers") == 0) { - Printf(stderr,"%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaclassmodifiers).\n", input_file, line_number); - } else { - Printf(stderr,"%s : Line %d. Unrecognized pragma.\n", input_file, line_number); - } - } else { - Printf(stderr,"%s : Line %d. Unrecognized pragma.\n", input_file, line_number); - } - Delete(strvalue); + if (Strcmp(code, "jniclassbase") == 0) { + Delete(imclass_baseclass); + imclass_baseclass = Copy(strvalue); + } else if (Strcmp(code, "jniclassclassmodifiers") == 0) { + Delete(imclass_class_modifiers); + imclass_class_modifiers = Copy(strvalue); + } else if (Strcmp(code, "jniclasscode") == 0) { + Printf(imclass_class_code, "%s\n", strvalue); + } else if (Strcmp(code, "jniclassimports") == 0) { + Delete(imclass_imports); + imclass_imports = Copy(strvalue); + } else if (Strcmp(code, "jniclassinterfaces") == 0) { + Delete(imclass_interfaces); + imclass_interfaces = Copy(strvalue); + } else if (Strcmp(code, "modulebase") == 0) { + Delete(module_baseclass); + module_baseclass = Copy(strvalue); + } else if (Strcmp(code, "moduleclassmodifiers") == 0) { + Delete(module_class_modifiers); + module_class_modifiers = Copy(strvalue); + } else if (Strcmp(code, "modulecode") == 0) { + Printf(module_class_code, "%s\n", strvalue); + } else if (Strcmp(code, "moduleimports") == 0) { + Delete(module_imports); + module_imports = Copy(strvalue); + } else if (Strcmp(code, "moduleinterfaces") == 0) { + Delete(module_interfaces); + module_interfaces = Copy(strvalue); + } else if (Strcmp(code, "moduleimport") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use the moduleimports pragma.\n", input_file, line_number); + } else if (Strcmp(code, "moduleinterface") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use the moduleinterfaces pragma.\n", input_file, line_number); + } else if (Strcmp(code, "modulemethodmodifiers") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %javamethodmodifiers.\n", input_file, line_number); + } else if (Strcmp(code, "allshadowimport") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaimports).\n", input_file, line_number); + } else if (Strcmp(code, "allshadowcode") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javacode).\n", input_file, line_number); + } else if (Strcmp(code, "allshadowbase") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javabase).\n", input_file, line_number); + } else if (Strcmp(code, "allshadowinterface") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javainterfaces).\n", input_file, line_number); + } else if (Strcmp(code, "allshadowclassmodifiers") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaclassmodifiers).\n", input_file, line_number); + } else if (proxy_flag) { + if (Strcmp(code, "shadowcode") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javacode).\n", input_file, line_number); + } else if (Strcmp(code, "shadowimport") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaimports).\n", input_file, line_number); + } else if (Strcmp(code, "shadowbase") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javabase).\n", input_file, line_number); + } else if (Strcmp(code, "shadowinterface") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javainterfaces).\n", input_file, line_number); + } else if (Strcmp(code, "shadowclassmodifiers") == 0) { + Printf(stderr, "%s : Line %d. Ignored: Deprecated pragma. Please use %typemap(javaclassmodifiers).\n", input_file, line_number); + } else { + Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + } + } else { + Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); + } + Delete(strvalue); } } return Language::pragmaDirective(n); @@ -1534,36 +1515,36 @@ class JAVA : public Language { * ----------------------------------------------------------------------------- */ void emitProxyClassDefAndCPPCasts(Node *n) { - String *c_classname = SwigType_namestr(Getattr(n,"name")); + String *c_classname = SwigType_namestr(Getattr(n, "name")); String *c_baseclass = NULL; String *baseclass = NULL; String *c_baseclassname = NULL; - String *typemap_lookup_type = Getattr(n,"classtypeobj"); - bool feature_director = Swig_directorclass(n) ? true : false; + String *typemap_lookup_type = Getattr(n, "classtypeobj"); + bool feature_director = Swig_directorclass(n) ? true : false; /* Deal with inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist) { Iterator base = First(baselist); - while(base.item && GetFlag(base.item,"feature:ignore")) { + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } if (base.item) { - c_baseclassname = Getattr(base.item,"name"); + c_baseclassname = Getattr(base.item, "name"); baseclass = Copy(getProxyName(c_baseclassname)); if (baseclass) - c_baseclass = SwigType_namestr(Getattr(base.item,"name")); + c_baseclass = SwigType_namestr(Getattr(base.item, "name")); base = Next(base); /* Warn about multiple inheritance for additional base class(es) */ while (base.item) { - if (GetFlag(base.item,"feature:ignore")) { + if (GetFlag(base.item, "feature:ignore")) { base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0); - String *baseclassname = SwigType_str(Getattr(base.item,"name"),0); - Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", proxyclassname, baseclassname); + String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); + String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); + Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", proxyclassname, baseclassname); base = Next(base); } } @@ -1581,8 +1562,8 @@ class JAVA : public Language { Delete(baseclass); baseclass = NULL; } else if (Len(pure_baseclass) > 0 && Len(baseclass) > 0) { - Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", typemap_lookup_type, pure_baseclass); + Swig_warning(WARN_JAVA_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Java.\n", typemap_lookup_type, pure_baseclass); } Delete(attributes); @@ -1590,24 +1571,13 @@ class JAVA : public Language { const String *pure_interfaces = typemapLookup("javainterfaces", typemap_lookup_type, WARN_NONE); // Start writing the proxy class - Printv(proxy_class_def, - typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements - "\n", - typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " $javaclassname", // Class name and bases - (*Char(wanted_base)) ? - " extends " : - "", - wanted_base, - *Char(pure_interfaces) ? // Pure Java interfaces - " implements " : - "", - pure_interfaces, - " {", - derived ? - typemapLookup("javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class - typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class - NIL); + Printv(proxy_class_def, typemapLookup("javaimports", typemap_lookup_type, WARN_NONE), // Import statements + "\n", typemapLookup("javaclassmodifiers", typemap_lookup_type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " $javaclassname", // Class name and bases + (*Char(wanted_base)) ? " extends " : "", wanted_base, *Char(pure_interfaces) ? // Pure Java interfaces + " implements " : "", pure_interfaces, " {", derived ? typemapLookup("javabody_derived", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF) : // main body of class + typemapLookup("javabody", typemap_lookup_type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class + NIL); // C++ destructor is wrapped by the delete method // Note that the method name is specified in a typemap attribute called methodname @@ -1627,31 +1597,28 @@ class JAVA : public Language { } if (*Char(tm)) { if (!destruct_methodname) { - Swig_error(input_file, line_number, - "No methodname attribute defined in javadestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(input_file, line_number, + "No methodname attribute defined in javadestruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } if (!destruct_methodmodifiers) { - Swig_error(input_file, line_number, - "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); + Swig_error(input_file, line_number, + "No methodmodifiers attribute defined in javadestruct%s typemap for %s.\n", (derived ? "_derived" : ""), proxy_class_name); } } - // Emit the finalize and delete methods if (tm) { // Finalize method if (*Char(destructor_call)) { - Printv(proxy_class_def, - typemapLookup("javafinalize", typemap_lookup_type, WARN_NONE), - NIL); + Printv(proxy_class_def, typemapLookup("javafinalize", typemap_lookup_type, WARN_NONE), NIL); } // delete method Printv(destruct, tm, NIL); if (*Char(destructor_call)) - Replaceall(destruct, "$jnicall", destructor_call); + Replaceall(destruct, "$jnicall", destructor_call); else - Replaceall(destruct, "$jnicall", "throw new UnsupportedOperationException(\"C++ destructor does not have public access\")"); + Replaceall(destruct, "$jnicall", "throw new UnsupportedOperationException(\"C++ destructor does not have public access\")"); if (*Char(destruct)) - Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " void ", destruct_methodname, "() ", destruct, "\n", NIL); + Printv(proxy_class_def, "\n ", destruct_methodmodifiers, " void ", destruct_methodname, "() ", destruct, "\n", NIL); } /* Insert directordisconnect typemap, if this class has directors enabled */ @@ -1660,10 +1627,8 @@ class JAVA : public Language { String *destruct_jnicall, *release_jnicall, *take_jnicall; destruct_jnicall = NewStringf("%s()", destruct_methodname); - release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, - proxy_class_name); - take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", - imclass_name, proxy_class_name); + release_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, false)", imclass_name, proxy_class_name); + take_jnicall = NewStringf("%s.%s_change_ownership(this, swigCPtr, true)", imclass_name, proxy_class_name); emitCodeTypemap(false, typemap_lookup_type, "directordisconnect", "methodname", destruct_jnicall); emitCodeTypemap(false, typemap_lookup_type, "directorowner_release", "methodname", release_jnicall); @@ -1678,46 +1643,38 @@ class JAVA : public Language { Delete(destruct); // Emit extra user code - Printv(proxy_class_def, - typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code - "\n", - NIL); + Printv(proxy_class_def, typemapLookup("javacode", typemap_lookup_type, WARN_NONE), // extra Java code + "\n", NIL); // Substitute various strings into the above template Replaceall(proxy_class_code, "$javaclassname", proxy_class_name); - Replaceall(proxy_class_def, "$javaclassname", proxy_class_name); + Replaceall(proxy_class_def, "$javaclassname", proxy_class_name); - Replaceall(proxy_class_def, "$module", module_class_name); + Replaceall(proxy_class_def, "$module", module_class_name); Replaceall(proxy_class_code, "$module", module_class_name); - Replaceall(proxy_class_def, "$imclassname", imclass_name); + Replaceall(proxy_class_def, "$imclassname", imclass_name); Replaceall(proxy_class_code, "$imclassname", imclass_name); // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) - if(derived){ - Printv(imclass_cppcasts_code," public final static native long SWIG$javaclassnameUpcast(long jarg1);\n", NIL); + if (derived) { + Printv(imclass_cppcasts_code, " public final static native long SWIG$javaclassnameUpcast(long jarg1);\n", NIL); Replaceall(imclass_cppcasts_code, "$javaclassname", proxy_class_name); Printv(upcasts_code, - "SWIGEXPORT jlong JNICALL Java_$jnipackage$imimclass_SWIG$imclazznameUpcast", - "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", - " jlong baseptr = 0;\n" - " (void)jenv;\n" - " (void)jcls;\n" - " *($cbaseclass **)&baseptr = *($cclass **)&jarg1;\n" - " return baseptr;\n" - "}\n", - "\n", - NIL); + "SWIGEXPORT jlong JNICALL Java_$jnipackage$imimclass_SWIG$imclazznameUpcast", + "(JNIEnv *jenv, jclass jcls, jlong jarg1) {\n", + " jlong baseptr = 0;\n" + " (void)jenv;\n" " (void)jcls;\n" " *($cbaseclass **)&baseptr = *($cclass **)&jarg1;\n" " return baseptr;\n" "}\n", "\n", NIL); - String *imimclass = makeValidJniName(imclass_name); + String *imimclass = makeValidJniName(imclass_name); String *imclazzname = makeValidJniName(proxy_class_name); - Replaceall(upcasts_code, "$cbaseclass", c_baseclass); + Replaceall(upcasts_code, "$cbaseclass", c_baseclass); Replaceall(upcasts_code, "$imclazzname", imclazzname); - Replaceall(upcasts_code, "$cclass", c_classname); - Replaceall(upcasts_code, "$jnipackage", jnipackage); - Replaceall(upcasts_code, "$imimclass", imimclass); + Replaceall(upcasts_code, "$cclass", c_classname); + Replaceall(upcasts_code, "$jnipackage", jnipackage); + Replaceall(upcasts_code, "$imimclass", imimclass); Delete(imclazzname); Delete(imimclass); @@ -1733,34 +1690,36 @@ class JAVA : public Language { File *f_proxy = NULL; if (proxy_flag) { - proxy_class_name = NewString(Getattr(n,"sym:name")); + proxy_class_name = NewString(Getattr(n, "sym:name")); - if (!addSymbol(proxy_class_name,n)) return SWIG_ERROR; + if (!addSymbol(proxy_class_name, n)) + return SWIG_ERROR; if (Cmp(proxy_class_name, imclass_name) == 0) { - Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); + Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } if (Cmp(proxy_class_name, module_class_name) == 0) { - Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); - SWIG_exit(EXIT_FAILURE); + Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } String *filen = NewStringf("%s%s.java", SWIG_output_directory(), proxy_class_name); - f_proxy = NewFile(filen,"w"); - if(!f_proxy) { - FileErrorDisplay(filen); - SWIG_exit(EXIT_FAILURE); + f_proxy = NewFile(filen, "w"); + if (!f_proxy) { + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the proxy class file emitBanner(f_proxy); - if(Len(package) > 0) - Printf(f_proxy, "package %s;\n", package); + if (Len(package) > 0) + Printf(f_proxy, "package %s;\n", package); Clear(proxy_class_def); Clear(proxy_class_code); @@ -1784,8 +1743,8 @@ class JAVA : public Language { Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); // Write out all the constants - if (Len(proxy_class_constants_code) != 0 ) - Printv(f_proxy, proxy_class_constants_code, NIL); + if (Len(proxy_class_constants_code) != 0) + Printv(f_proxy, proxy_class_constants_code, NIL); Printf(f_proxy, "}\n"); Close(f_proxy); @@ -1796,34 +1755,36 @@ class JAVA : public Language { downcasts, making the constructorHandler() a bad place (because ABCs don't get to have constructors emitted.) */ if (GetFlag(n, "feature:javadowncast")) { - String *jni_imclass_name = makeValidJniName(imclass_name); - String *jni_class_name = makeValidJniName(proxy_class_name); - String *norm_name = SwigType_namestr(Getattr(n, "name")); + String *jni_imclass_name = makeValidJniName(imclass_name); + String *jni_class_name = makeValidJniName(proxy_class_name); + String *norm_name = SwigType_namestr(Getattr(n, "name")); - Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", - proxy_class_name, proxy_class_name); + Printf(imclass_class_code, " public final static native %s downcast%s(long cPtrBase, boolean cMemoryOwn);\n", proxy_class_name, proxy_class_name); - Wrapper *dcast_wrap = NewWrapper(); + Wrapper *dcast_wrap = NewWrapper(); - Printf(dcast_wrap->def, "SWIGEXPORT jobject JNICALL Java_%s%s_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", - jnipackage, jni_imclass_name, jni_class_name); - Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); - Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); - Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); - Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); - Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); - Printf(dcast_wrap->code, " return jresult;\n"); - Printf(dcast_wrap->code, "}\n"); + Printf(dcast_wrap->def, "SWIGEXPORT jobject JNICALL Java_%s%s_downcast%s(JNIEnv *jenv, jclass jcls, jlong jCPtrBase, jboolean cMemoryOwn) {", + jnipackage, jni_imclass_name, jni_class_name); + Printf(dcast_wrap->code, " Swig::Director *director = (Swig::Director *) 0;\n"); + Printf(dcast_wrap->code, " jobject jresult = (jobject) 0;\n"); + Printf(dcast_wrap->code, " %s *obj = *((%s **)&jCPtrBase);\n", norm_name, norm_name); + Printf(dcast_wrap->code, " if (obj) director = dynamic_cast(obj);\n"); + Printf(dcast_wrap->code, " if (director) jresult = director->swig_get_self(jenv);\n"); + Printf(dcast_wrap->code, " return jresult;\n"); + Printf(dcast_wrap->code, "}\n"); - Wrapper_print(dcast_wrap, f_wrappers); - DelWrapper(dcast_wrap); + Wrapper_print(dcast_wrap, f_wrappers); + DelWrapper(dcast_wrap); } emitDirectorExtraMethods(n); - Delete(proxy_class_name); proxy_class_name = NULL; - Delete(destructor_call); destructor_call = NULL; - Delete(proxy_class_constants_code); proxy_class_constants_code = NULL; + Delete(proxy_class_name); + proxy_class_name = NULL; + Delete(destructor_call); + destructor_call = NULL; + Delete(proxy_class_constants_code); + proxy_class_constants_code = NULL; } return SWIG_OK; @@ -1840,8 +1801,8 @@ class JAVA : public Language { if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); - Setattr(n,"proxyfuncname", Getattr(n, "sym:name")); - Setattr(n,"imfuncname", intermediary_function_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); Delete(overloaded_name); } @@ -1862,8 +1823,8 @@ class JAVA : public Language { if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); - Setattr(n,"proxyfuncname", Getattr(n,"sym:name")); - Setattr(n,"imfuncname", intermediary_function_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); proxyClassFunctionHandler(n); Delete(overloaded_name); } @@ -1885,29 +1846,32 @@ class JAVA : public Language { * ----------------------------------------------------------------------------- */ void proxyClassFunctionHandler(Node *n) { - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *intermediary_function_name = Getattr(n,"imfuncname"); - String *proxy_function_name = Getattr(n,"proxyfuncname"); - String *tm; - Parm *p; - int i; - String *imcall = NewString(""); - String *return_type = NewString(""); - String *function_code = NewString(""); - bool setter_flag = false; + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *intermediary_function_name = Getattr(n, "imfuncname"); + String *proxy_function_name = Getattr(n, "proxyfuncname"); + String *tm; + Parm *p; + int i; + String *imcall = NewString(""); + String *return_type = NewString(""); + String *function_code = NewString(""); + bool setter_flag = false; - if(!proxy_flag) return; + if (!proxy_flag) + return; // Wrappers not wanted for some methods where the parameters cannot be overloaded in Java - if (Getattr(n, "overload:ignore")) return; + if (Getattr(n, "overload:ignore")) + return; // Don't generate proxy method for additional explicitcall method used in directors - if (GetFlag(n, "explicitcall")) return; + if (GetFlag(n, "explicitcall")) + return; if (l) { - if (SwigType_type(Getattr(l,"type")) == T_VOID) { - l = nextSibling(l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } @@ -1918,26 +1882,25 @@ class JAVA : public Language { Swig_typemap_attach_parms("javain", l, NULL); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("jstype",n,"",0))) { + if ((tm = Swig_typemap_lookup_new("jstype", n, "", 0))) { // Note that in the case of polymorphic (covariant) return types, the method's return type is changed to be the base of the C++ return type - SwigType *covariant = Getattr(n,"covariant"); + SwigType *covariant = Getattr(n, "covariant"); substituteClassname(covariant ? covariant : t, tm); Printf(return_type, "%s", tm); if (covariant) - Swig_warning(WARN_JAVA_COVARIANT_RET, input_file, line_number, - "Covariant return types not supported in Java. Proxy method will return %s.\n", SwigType_str(covariant,0)); + Swig_warning(WARN_JAVA_COVARIANT_RET, input_file, line_number, + "Covariant return types not supported in Java. Proxy method will return %s.\n", SwigType_str(covariant, 0)); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(t, 0)); } - if(proxy_flag && wrapping_member_flag && !enum_constant_flag) { + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // For wrapping member variables (Javabean setter) setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) == 0); } /* Start generating the proxy function */ - const String *methodmods = Getattr(n,"feature:java:methodmodifiers"); + const String *methodmods = Getattr(n, "feature:java:methodmodifiers"); methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string); Printf(function_code, " %s ", methodmods); if (static_flag) @@ -1970,108 +1933,104 @@ class JAVA : public Language { int gencomma = !static_flag; /* Output each parameter */ - for (i = 0, p=l; p; i++) { + for (i = 0, p = l; p; i++) { /* Ignored varargs */ - if (checkAttribute(p,"varargs:ignore","1")) { - p = nextSibling(p); - continue; + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; } /* Ignored parameters */ - if (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); - continue; + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; } /* Ignore the 'this' argument for variable wrappers */ - if (!(variable_wrapper_flag && i==0) || static_flag) - { - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); + if (!(variable_wrapper_flag && i == 0) || static_flag) { + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); - /* Get the Java parameter type */ - if ((tm = Getattr(p,"tmap:jstype"))) { - substituteClassname(pt, tm); - Printf(param_type, "%s", tm); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(pt,0)); - } + /* Get the Java parameter type */ + if ((tm = Getattr(p, "tmap:jstype"))) { + substituteClassname(pt, tm); + Printf(param_type, "%s", tm); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(pt, 0)); + } - if (gencomma) - Printf(imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = makeParameterName(n, p, i, setter_flag); + String *arg = makeParameterName(n, p, i, setter_flag); - // Use typemaps to transform type used in Java proxy wrapper (in proxy class) to type used in JNI function (in intermediary class) - if ((tm = Getattr(p,"tmap:javain"))) { - addThrows(n, "tmap:javain", p); - substituteClassname(pt, tm); - Replaceall(tm, "$javainput", arg); - Printv(imcall, tm, NIL); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, - "No javain typemap defined for %s\n", SwigType_str(pt,0)); - } + // Use typemaps to transform type used in Java proxy wrapper (in proxy class) to type used in JNI function (in intermediary class) + if ((tm = Getattr(p, "tmap:javain"))) { + addThrows(n, "tmap:javain", p); + substituteClassname(pt, tm); + Replaceall(tm, "$javainput", arg); + Printv(imcall, tm, NIL); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, "No javain typemap defined for %s\n", SwigType_str(pt, 0)); + } - /* Add parameter to proxy function */ - if (gencomma >= 2) - Printf(function_code, ", "); - gencomma = 2; - Printf(function_code, "%s %s", param_type, arg); + /* Add parameter to proxy function */ + if (gencomma >= 2) + Printf(function_code, ", "); + gencomma = 2; + Printf(function_code, "%s %s", param_type, arg); if (prematureGarbageCollectionPreventionParameter(pt, p)) Printf(imcall, ", %s", arg); - Delete(arg); - Delete(param_type); + Delete(arg); + Delete(param_type); } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } Printf(imcall, ")"); Printf(function_code, ")"); // Transform return type used in JNI function (in intermediary class) to type used in Java wrapper function (in proxy class) - if ((tm = Swig_typemap_lookup_new("javaout",n,"",0))) { + if ((tm = Swig_typemap_lookup_new("javaout", n, "", 0))) { addThrows(n, "tmap:javaout", n); - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); else - Replaceall(tm,"$owner","false"); + Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); // For director methods: generate code to selectively make a normal polymorphic call or // an explicit method call - needed to prevent infinite recursion calls in director methods. - Node *explicit_n = Getattr(n,"explicitcallnode"); + Node *explicit_n = Getattr(n, "explicitcallnode"); if (explicit_n) { String *ex_overloaded_name = getOverloadedName(explicit_n); String *ex_intermediary_function_name = Swig_name_member(proxy_class_name, ex_overloaded_name); - String *ex_imcall = Copy(imcall); - Replaceall(ex_imcall, intermediary_function_name, ex_intermediary_function_name); + String *ex_imcall = Copy(imcall); + Replaceall(ex_imcall, intermediary_function_name, ex_intermediary_function_name); - String *excode = NewString(""); - if (!Cmp(return_type, "void")) - Printf(excode, "if (getClass() == %s.class) %s; else %s", proxy_class_name, imcall, ex_imcall); - else - Printf(excode, "(getClass() == %s.class) ? %s : %s", proxy_class_name, imcall, ex_imcall); + String *excode = NewString(""); + if (!Cmp(return_type, "void")) + Printf(excode, "if (getClass() == %s.class) %s; else %s", proxy_class_name, imcall, ex_imcall); + else + Printf(excode, "(getClass() == %s.class) ? %s : %s", proxy_class_name, imcall, ex_imcall); - Clear(imcall); - Printv(imcall, excode, NIL); + Clear(imcall); + Printv(imcall, excode, NIL); Delete(ex_overloaded_name); - Delete(excode); + Delete(excode); } Replaceall(tm, "$jnicall", imcall); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, - "No javaout typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0)); } generateThrowsClause(n, function_code); - Printf(function_code, " %s\n\n", tm ? (const String *)tm : empty_string); + Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string); Printv(proxy_class_code, function_code, NIL); Delete(function_code); @@ -2085,12 +2044,12 @@ class JAVA : public Language { virtual int constructorHandler(Node *n) { - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - int i; - String *function_code = NewString(""); - bool feature_director = (parentNode(n) && Swig_directorclass(n)); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + int i; + String *function_code = NewString(""); + bool feature_director = (parentNode(n) && Swig_directorclass(n)); Language::constructorHandler(n); @@ -2098,12 +2057,12 @@ class JAVA : public Language { if (Getattr(n, "overload:ignore")) return SWIG_OK; - if(proxy_flag) { + if (proxy_flag) { String *overloaded_name = getOverloadedName(n); String *mangled_overname = Swig_name_construct(overloaded_name); String *imcall = NewString(""); - const String *methodmods = Getattr(n,"feature:java:methodmodifiers"); + const String *methodmods = Getattr(n, "feature:java:methodmodifiers"); methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string); Printf(function_code, " %s %s(", methodmods, proxy_class_name); Printv(imcall, imclass_name, ".", mangled_overname, "(", NIL); @@ -2119,60 +2078,58 @@ class JAVA : public Language { int gencomma = 0; /* Output each parameter */ - for (i = 0, p=l; p; i++) { + for (i = 0, p = l; p; i++) { - /* Ignored varargs */ - if (checkAttribute(p,"varargs:ignore","1")) { - p = nextSibling(p); - continue; - } + /* Ignored varargs */ + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; + } - /* Ignored parameters */ - if (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); - continue; - } + /* Ignored parameters */ + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); - /* Get the Java parameter type */ - if ((tm = Getattr(p,"tmap:jstype"))) { - substituteClassname(pt, tm); - Printf(param_type, "%s", tm); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(pt,0)); - } + /* Get the Java parameter type */ + if ((tm = Getattr(p, "tmap:jstype"))) { + substituteClassname(pt, tm); + Printf(param_type, "%s", tm); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(pt, 0)); + } - if (gencomma) - Printf(imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = makeParameterName(n, p, i, false); + String *arg = makeParameterName(n, p, i, false); - // Use typemaps to transform type used in Java wrapper function (in proxy class) to type used in JNI function (in intermediary class) - if ((tm = Getattr(p,"tmap:javain"))) { - addThrows(n, "tmap:javain", p); - substituteClassname(pt, tm); - Replaceall(tm, "$javainput", arg); - Printv(imcall, tm, NIL); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, - "No javain typemap defined for %s\n", SwigType_str(pt,0)); - } + // Use typemaps to transform type used in Java wrapper function (in proxy class) to type used in JNI function (in intermediary class) + if ((tm = Getattr(p, "tmap:javain"))) { + addThrows(n, "tmap:javain", p); + substituteClassname(pt, tm); + Replaceall(tm, "$javainput", arg); + Printv(imcall, tm, NIL); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, "No javain typemap defined for %s\n", SwigType_str(pt, 0)); + } - /* Add parameter to proxy function */ - if(gencomma) - Printf(function_code, ", "); - Printf(function_code, "%s %s", param_type, arg); - ++gencomma; + /* Add parameter to proxy function */ + if (gencomma) + Printf(function_code, ", "); + Printf(function_code, "%s %s", param_type, arg); + ++gencomma; if (prematureGarbageCollectionPreventionParameter(pt, p)) Printf(imcall, ", %s", arg); - Delete(arg); - Delete(param_type); - p = Getattr(p,"tmap:in:next"); + Delete(arg); + Delete(param_type); + p = Getattr(p, "tmap:in:next"); } Printf(imcall, ")"); @@ -2182,23 +2139,24 @@ class JAVA : public Language { /* Insert the javaconstruct typemap, doing the replacement for $directorconnect, as needed */ Hash *attributes = NewHash(); - String *construct_tm = Copy(typemapLookup("javaconstruct", Getattr(n,"name"), - WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF, attributes)); + String *construct_tm = Copy(typemapLookup("javaconstruct", Getattr(n, "name"), + WARN_JAVA_TYPEMAP_JAVACONSTRUCT_UNDEF, attributes)); if (construct_tm) { - if (!feature_director) { - Replaceall(construct_tm, "$directorconnect", ""); - } else { - String *connect_attr = Getattr(attributes, "tmap:javaconstruct:directorconnect"); + if (!feature_director) { + Replaceall(construct_tm, "$directorconnect", ""); + } else { + String *connect_attr = Getattr(attributes, "tmap:javaconstruct:directorconnect"); - if (connect_attr) { - Replaceall(construct_tm, "$directorconnect", connect_attr); - } else { - Swig_warning(WARN_JAVA_NO_DIRECTORCONNECT_ATTR, input_file, line_number, "\"directorconnect\" attribute missing in %s \"javaconstruct\" typemap.\n", Getattr(n,"name")); - Replaceall(construct_tm, "$directorconnect", ""); - } - } + if (connect_attr) { + Replaceall(construct_tm, "$directorconnect", connect_attr); + } else { + Swig_warning(WARN_JAVA_NO_DIRECTORCONNECT_ATTR, input_file, line_number, "\"directorconnect\" attribute missing in %s \"javaconstruct\" typemap.\n", + Getattr(n, "name")); + Replaceall(construct_tm, "$directorconnect", ""); + } + } - Printv(function_code, " ", construct_tm, "\n", NIL); + Printv(function_code, " ", construct_tm, "\n", NIL); } Replaceall(function_code, "$imcall", imcall); @@ -2220,9 +2178,9 @@ class JAVA : public Language { virtual int destructorHandler(Node *n) { Language::destructorHandler(n); - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); - if(proxy_flag) { + if (proxy_flag) { Printv(destructor_call, imclass_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); } return SWIG_OK; @@ -2233,7 +2191,7 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int membervariableHandler(Node *n) { - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; variable_wrapper_flag = true; Language::membervariableHandler(n); @@ -2247,7 +2205,7 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int staticmembervariableHandler(Node *n) { - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; static_flag = true; Language::staticmembervariableHandler(n); @@ -2261,7 +2219,7 @@ class JAVA : public Language { * ---------------------------------------------------------------------- */ virtual int memberconstantHandler(Node *n) { - variable_name = Getattr(n,"sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; Language::memberconstantHandler(n); wrapping_member_flag = false; @@ -2278,10 +2236,10 @@ class JAVA : public Language { * a Java long is used for all classes in the SWIG intermediary class. * The intermediary class methods are thus mangled when overloaded to give * a unique name. */ - String *overloaded_name = NewStringf("%s", Getattr(n,"sym:name")); + String *overloaded_name = NewStringf("%s", Getattr(n, "sym:name")); - if (Getattr(n,"sym:overloaded")) { - Printv(overloaded_name, Getattr(n,"sym:overname"), NIL); + if (Getattr(n, "sym:overloaded")) { + Printv(overloaded_name, Getattr(n, "sym:overname"), NIL); } return overloaded_name; @@ -2292,23 +2250,23 @@ class JAVA : public Language { * ----------------------------------------------------------------------------- */ void moduleClassFunctionHandler(Node *n) { - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *tm; - Parm *p; - int i; - String *imcall = NewString(""); - String *return_type = NewString(""); - String *function_code = NewString(""); - int num_arguments = 0; - int num_required = 0; - String *overloaded_name = getOverloadedName(n); - String *func_name = NULL; - bool setter_flag = false; + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *tm; + Parm *p; + int i; + String *imcall = NewString(""); + String *return_type = NewString(""); + String *function_code = NewString(""); + int num_arguments = 0; + int num_required = 0; + String *overloaded_name = getOverloadedName(n); + String *func_name = NULL; + bool setter_flag = false; if (l) { - if (SwigType_type(Getattr(l,"type")) == T_VOID) { - l = nextSibling(l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } @@ -2317,87 +2275,84 @@ class JAVA : public Language { Swig_typemap_attach_parms("javain", l, NULL); /* Get return types */ - if ((tm = Swig_typemap_lookup_new("jstype",n,"",0))) { + if ((tm = Swig_typemap_lookup_new("jstype", n, "", 0))) { substituteClassname(t, tm); Printf(return_type, "%s", tm); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(t, 0)); } /* Change function name for global variables */ if (proxy_flag && global_variable_flag) { // Capitalize the first letter in the variable to create a JavaBean type getter/setter function name func_name = NewString(""); - setter_flag = (Cmp(Getattr(n,"sym:name"), Swig_name_set(variable_name)) == 0); - if(setter_flag) - Printf(func_name,"set"); - else - Printf(func_name,"get"); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(variable_name)) == 0); + if (setter_flag) + Printf(func_name, "set"); + else + Printf(func_name, "get"); Putc(toupper((int) *Char(variable_name)), func_name); - Printf(func_name, "%s", Char(variable_name)+1); + Printf(func_name, "%s", Char(variable_name) + 1); } else { - func_name = Copy(Getattr(n,"sym:name")); + func_name = Copy(Getattr(n, "sym:name")); } /* Start generating the function */ - const String *methodmods = Getattr(n,"feature:java:methodmodifiers"); + const String *methodmods = Getattr(n, "feature:java:methodmodifiers"); methodmods = methodmods ? methodmods : (!is_public(n) ? protected_string : public_string); Printf(function_code, " %s static %s %s(", methodmods, return_type, func_name); Printv(imcall, imclass_name, ".", overloaded_name, "(", NIL); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); + num_required = emit_num_required(l); int gencomma = 0; /* Output each parameter */ - for (i = 0, p=l; i < num_arguments; i++) { + for (i = 0, p = l; i < num_arguments; i++) { /* Ignored parameters */ - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *param_type = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); /* Get the Java parameter type */ - if ((tm = Getattr(p,"tmap:jstype"))) { - substituteClassname(pt, tm); - Printf(param_type, "%s", tm); + if ((tm = Getattr(p, "tmap:jstype"))) { + substituteClassname(pt, tm); + Printf(param_type, "%s", tm); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, - "No jstype typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JSTYPE_UNDEF, input_file, line_number, "No jstype typemap defined for %s\n", SwigType_str(pt, 0)); } if (gencomma) - Printf(imcall, ", "); + Printf(imcall, ", "); String *arg = makeParameterName(n, p, i, setter_flag); // Use typemaps to transform type used in Java wrapper function (in proxy class) to type used in JNI function (in intermediary class) - if ((tm = Getattr(p,"tmap:javain"))) { - addThrows(n, "tmap:javain", p); - substituteClassname(pt, tm); - Replaceall(tm, "$javainput", arg); - Printv(imcall, tm, NIL); + if ((tm = Getattr(p, "tmap:javain"))) { + addThrows(n, "tmap:javain", p); + substituteClassname(pt, tm); + Replaceall(tm, "$javainput", arg); + Printv(imcall, tm, NIL); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, - "No javain typemap defined for %s\n", SwigType_str(pt,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JAVAIN_UNDEF, input_file, line_number, "No javain typemap defined for %s\n", SwigType_str(pt, 0)); } /* Add parameter to module class function */ if (gencomma >= 2) - Printf(function_code, ", "); + Printf(function_code, ", "); gencomma = 2; Printf(function_code, "%s %s", param_type, arg); if (prematureGarbageCollectionPreventionParameter(pt, p)) Printf(imcall, ", %s", arg); - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); Delete(arg); Delete(param_type); } @@ -2406,21 +2361,20 @@ class JAVA : public Language { Printf(function_code, ")"); // Transform return type used in JNI function (in intermediary class) to type used in Java wrapper function (in module class) - if ((tm = Swig_typemap_lookup_new("javaout",n,"",0))) { + if ((tm = Swig_typemap_lookup_new("javaout", n, "", 0))) { addThrows(n, "tmap:javaout", n); - if (GetFlag(n,"feature:new")) - Replaceall(tm,"$owner","true"); + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); else - Replaceall(tm,"$owner","false"); + Replaceall(tm, "$owner", "false"); substituteClassname(t, tm); Replaceall(tm, "$jnicall", imcall); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, - "No javaout typemap defined for %s\n", SwigType_str(t,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JAVAOUT_UNDEF, input_file, line_number, "No javaout typemap defined for %s\n", SwigType_str(t, 0)); } generateThrowsClause(n, function_code); - Printf(function_code, " %s\n\n", tm ? (const String *)tm : empty_string); + Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string); Printv(module_class_code, function_code, NIL); Delete(function_code); @@ -2439,17 +2393,17 @@ class JAVA : public Language { *--------------------------------------------------------------------*/ EnumFeature decodeEnumFeature(Node *n) { - EnumFeature enum_feature = TypeunsafeEnum; - String *feature = Getattr(n,"feature:java:enum"); - if (feature) { - if (Cmp(feature, "simple") == 0) - enum_feature = SimpleEnum; - else if (Cmp(feature, "typesafe") == 0) - enum_feature = TypesafeEnum; - else if (Cmp(feature, "proper") == 0) - enum_feature = ProperEnum; - } - return enum_feature; + EnumFeature enum_feature = TypeunsafeEnum; + String *feature = Getattr(n, "feature:java:enum"); + if (feature) { + if (Cmp(feature, "simple") == 0) + enum_feature = SimpleEnum; + else if (Cmp(feature, "typesafe") == 0) + enum_feature = TypesafeEnum; + else if (Cmp(feature, "proper") == 0) + enum_feature = ProperEnum; + } + return enum_feature; } /* ----------------------------------------------------------------------- @@ -2464,29 +2418,29 @@ class JAVA : public Language { * ------------------------------------------------------------------------ */ String *enumValue(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); // Check for the %javaconstvalue feature - String *value = Getattr(n,"feature:java:constvalue"); + String *value = Getattr(n, "feature:java:constvalue"); if (!value) { // The %javaconst feature determines how the constant value is obtained - int const_feature_flag = GetFlag(n,"feature:java:const"); + int const_feature_flag = GetFlag(n, "feature:java:const"); if (const_feature_flag) { - // Use the C syntax to make a true Java constant and hope that it compiles as Java code - value = Getattr(n,"enumvalue") ? Copy(Getattr(n,"enumvalue")) : Copy(Getattr(n,"enumvalueex")); + // Use the C syntax to make a true Java constant and hope that it compiles as Java code + value = Getattr(n, "enumvalue") ? Copy(Getattr(n, "enumvalue")) : Copy(Getattr(n, "enumvalueex")); } else { - // Get the enumvalue from a JNI call - if (!getCurrentClass() || !cparse_cplusplus) { - // Strange hack to change the name - Setattr(n,"name",Getattr(n,"value")); /* for wrapping of enums in a namespace when emit_action is used */ - constantWrapper(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); - } else { - memberconstantHandler(n); - value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); - } + // Get the enumvalue from a JNI call + if (!getCurrentClass() || !cparse_cplusplus) { + // Strange hack to change the name + Setattr(n, "name", Getattr(n, "value")); /* for wrapping of enums in a namespace when emit_action is used */ + constantWrapper(n); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(symname)); + } else { + memberconstantHandler(n); + value = NewStringf("%s.%s()", imclass_name, Swig_name_get(Swig_name_member(proxy_class_name, symname))); + } } } return value; @@ -2502,21 +2456,21 @@ class JAVA : public Language { Node *enum_name = NULL; Node *n = enumLookup(t); if (n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); if (symname) { - // Add in class scope when referencing enum if not a global enum - String *scopename_prefix = Swig_scopename_prefix(Getattr(n,"name")); - String *proxyname = 0; - if (scopename_prefix) { - proxyname = getProxyName(scopename_prefix); - } - if (proxyname) { - const char *class_separator = jnidescriptor ? "$" : "."; - enum_name = NewStringf("%s%s%s", proxyname, class_separator, symname); - } else { - enum_name = NewStringf("%s", symname); - } - Delete(scopename_prefix); + // Add in class scope when referencing enum if not a global enum + String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name")); + String *proxyname = 0; + if (scopename_prefix) { + proxyname = getProxyName(scopename_prefix); + } + if (proxyname) { + const char *class_separator = jnidescriptor ? "$" : "."; + enum_name = NewStringf("%s%s%s", proxyname, class_separator, symname); + } else { + enum_name = NewStringf("%s", symname); + } + Delete(scopename_prefix); } } @@ -2580,21 +2534,20 @@ class JAVA : public Language { if (SwigType_isenum(classnametype)) { String *enumname = getEnumName(classnametype, jnidescriptor); if (enumname) - Replaceall(tm, classnamespecialvariable, enumname); + Replaceall(tm, classnamespecialvariable, enumname); else - Replaceall(tm, classnamespecialvariable, NewStringf("int")); + Replaceall(tm, classnamespecialvariable, NewStringf("int")); } else { String *classname = getProxyName(classnametype); if (classname) { - Replaceall(tm, classnamespecialvariable, classname); // getProxyName() works for pointers to classes too - } - else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. - String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); - Replaceall(tm, classnamespecialvariable, descriptor); + Replaceall(tm, classnamespecialvariable, classname); // getProxyName() works for pointers to classes too + } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. + String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype)); + Replaceall(tm, classnamespecialvariable, descriptor); - // Add to hash table so that the type wrapper classes can be created later - Setattr(swig_types_hash, descriptor, classnametype); - Delete(descriptor); + // Add to hash table so that the type wrapper classes can be created later + Setattr(swig_types_hash, descriptor, classnametype); + Delete(descriptor); } } } @@ -2614,22 +2567,22 @@ class JAVA : public Language { String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) { String *arg = 0; - String *pn = Getattr(p,"name"); + String *pn = Getattr(p, "name"); if (setter) { // Note that for setters the parameter name is always set but sometimes includes C++ // scope resolution, so we need to strip off the scope resolution to make a valid name. - arg = NewString("value"); //Swig_scopename_last(pn); + arg = NewString("value"); //Swig_scopename_last(pn); } else { // Use C parameter name unless it is a duplicate or an empty parameter name int count = 0; - ParmList *plist = Getattr(n,"parms"); + ParmList *plist = Getattr(n, "parms"); while (plist) { - if ((Cmp(pn, Getattr(plist,"name")) == 0)) - count++; - plist = nextSibling(plist); + if ((Cmp(pn, Getattr(plist, "name")) == 0)) + count++; + plist = nextSibling(plist); } String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0; - arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d",arg_num) : Copy(pn); + arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn); } return arg; @@ -2642,18 +2595,19 @@ class JAVA : public Language { void emitTypeWrapperClass(String *classname, SwigType *type) { String *swigtype = NewString(""); String *filen = NewStringf("%s%s.java", SWIG_output_directory(), classname); - File *f_swigtype = NewFile(filen,"w"); - if(!f_swigtype) { + File *f_swigtype = NewFile(filen, "w"); + if (!f_swigtype) { FileErrorDisplay(filen); SWIG_exit(EXIT_FAILURE); - } + } Append(filenames_list, Copy(filen)); - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; // Start writing out the type wrapper class file emitBanner(f_swigtype); - if(Len(package) > 0) + if (Len(package) > 0) Printf(f_swigtype, "package %s;\n", package); // Pure Java baseclass and interfaces @@ -2661,25 +2615,13 @@ class JAVA : public Language { const String *pure_interfaces = typemapLookup("javainterfaces", type, WARN_NONE); // Emit the class - Printv(swigtype, - typemapLookup("javaimports", type, WARN_NONE), // Import statements - "\n", - typemapLookup("javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " $javaclassname", // Class name and bases - *Char(pure_baseclass) ? - " extends " : - "", - pure_baseclass, - *Char(pure_interfaces) ? // Interfaces - " implements " : - "", - pure_interfaces, - " {", - typemapLookup("javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class - typemapLookup("javacode", type, WARN_NONE), // extra Java code - "}\n", - "\n", - NIL); + Printv(swigtype, typemapLookup("javaimports", type, WARN_NONE), // Import statements + "\n", typemapLookup("javaclassmodifiers", type, WARN_JAVA_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " $javaclassname", // Class name and bases + *Char(pure_baseclass) ? " extends " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces + " implements " : "", pure_interfaces, " {", typemapLookup("javabody", type, WARN_JAVA_TYPEMAP_JAVABODY_UNDEF), // main body of class + typemapLookup("javacode", type, WARN_NONE), // extra Java code + "}\n", "\n", NIL); Replaceall(swigtype, "$javaclassname", classname); Replaceall(swigtype, "$module", module_class_name); @@ -2694,20 +2636,20 @@ class JAVA : public Language { * typemapLookup() * ----------------------------------------------------------------------------- */ - const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes=NULL) { + const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { String *tm = NULL; const String *code = NULL; - if((tm = Swig_typemap_search(op, type, NULL, NULL))) { - code = Getattr(tm,"code"); + if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { + code = Getattr(tm, "code"); if (typemap_attributes) - Swig_typemap_attach_kwargs(tm,op,typemap_attributes); + Swig_typemap_attach_kwargs(tm, op, typemap_attributes); } if (!code) { code = empty_string; if (warning != WARN_NONE) - Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); + Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); } return code ? code : empty_string; @@ -2723,43 +2665,42 @@ class JAVA : public Language { void addThrows(Node *n, const String *attribute, Node *parameter) { // Get the comma separated exception classes for the throws clause - held in typemap/feature's "throws" attribute String *throws_attribute = NewStringf("%s:throws", attribute); - String *throws = Getattr(parameter,throws_attribute); + String *throws = Getattr(parameter, throws_attribute); if (throws) { - String *throws_list = Getattr(n,"java:throwslist"); + String *throws_list = Getattr(n, "java:throwslist"); if (!throws_list) { - throws_list = NewList(); - Setattr(n,"java:throwslist", throws_list); + throws_list = NewList(); + Setattr(n, "java:throwslist", throws_list); } - // Put the exception classes in the throws clause into a temporary List - List *temp_classes_list = Split(throws,',',INT_MAX); + List *temp_classes_list = Split(throws, ',', INT_MAX); // Add the exception classes to the node throws list, but don't duplicate if already in list if (temp_classes_list && Len(temp_classes_list) > 0) { - for (Iterator cls = First(temp_classes_list); cls.item; cls = Next(cls)) { - String *exception_class = NewString(cls.item); - Replaceall(exception_class," ",""); // remove spaces - Replaceall(exception_class,"\t",""); // remove tabs - if (Len(exception_class) > 0) { - // $javaclassname substitution - SwigType *pt = Getattr(parameter,"type"); - substituteClassname(pt, exception_class); + for (Iterator cls = First(temp_classes_list); cls.item; cls = Next(cls)) { + String *exception_class = NewString(cls.item); + Replaceall(exception_class, " ", ""); // remove spaces + Replaceall(exception_class, "\t", ""); // remove tabs + if (Len(exception_class) > 0) { + // $javaclassname substitution + SwigType *pt = Getattr(parameter, "type"); + substituteClassname(pt, exception_class); - // Don't duplicate the Java exception class in the throws clause - bool found_flag = false; - for (Iterator item = First(throws_list); item.item; item = Next(item)) { - if (Strcmp(item.item, exception_class) == 0) - found_flag = true; - } - if (!found_flag) - Append(throws_list, exception_class); - } - Delete(exception_class); - } + // Don't duplicate the Java exception class in the throws clause + bool found_flag = false; + for (Iterator item = First(throws_list); item.item; item = Next(item)) { + if (Strcmp(item.item, exception_class) == 0) + found_flag = true; + } + if (!found_flag) + Append(throws_list, exception_class); + } + Delete(exception_class); + } } Delete(temp_classes_list); - } + } Delete(throws_attribute); } @@ -2771,12 +2712,12 @@ class JAVA : public Language { void generateThrowsClause(Node *n, String *code) { // Add the throws clause into code - List *throws_list = Getattr(n,"java:throwslist"); + List *throws_list = Getattr(n, "java:throwslist"); if (throws_list) { Iterator cls = First(throws_list); Printf(code, " throws %s", cls.item); - while ( (cls = Next(cls)).item) - Printf(code, ", %s", cls.item); + while ((cls = Next(cls)).item) + Printf(code, ", %s", cls.item); } } @@ -2790,12 +2731,12 @@ class JAVA : public Language { * ----------------------------------------------------------------------------- */ String *prematureGarbageCollectionPreventionParameter(SwigType *t, Parm *p) { - String *jtype = Getattr(p,"tmap:jtype"); + String *jtype = Getattr(p, "tmap:jtype"); if (Cmp(jtype, "long") == 0) { if (proxy_flag) { Node *n = classLookup(t); if (n && !GetFlag(p, "tmap:jtype:nopgcpp") && !nopgcpp_flag) { - return Getattr(n,"sym:name"); + return Getattr(n, "sym:name"); } } } @@ -2810,31 +2751,32 @@ class JAVA : public Language { * getUpcallJNIMethod() *--------------------------------------------------------------------*/ - String * getUpcallJNIMethod(String *descrip) { + String *getUpcallJNIMethod(String *descrip) { static struct { - char code; + char code; const char *method; } upcall_methods[] = { - { 'B', "CallStaticByteMethod" }, - { 'C', "CallStaticCharMethod" }, - { 'D', "CallStaticDoubleMethod" }, - { 'F', "CallStaticFloatMethod" }, - { 'I', "CallStaticIntMethod" }, - { 'J', "CallStaticLongMethod" }, - { 'L', "CallStaticObjectMethod" }, - { 'S', "CallStaticShortMethod" }, - { 'V', "CallStaticVoidMethod" }, - { 'Z', "CallStaticBooleanMethod" }, - { '[', "CallStaticObjectMethod" } + { + 'B', "CallStaticByteMethod"}, { + 'C', "CallStaticCharMethod"}, { + 'D', "CallStaticDoubleMethod"}, { + 'F', "CallStaticFloatMethod"}, { + 'I', "CallStaticIntMethod"}, { + 'J', "CallStaticLongMethod"}, { + 'L', "CallStaticObjectMethod"}, { + 'S', "CallStaticShortMethod"}, { + 'V', "CallStaticVoidMethod"}, { + 'Z', "CallStaticBooleanMethod"}, { + '[', "CallStaticObjectMethod"} }; char code; int i; code = *Char(descrip); - for (i = 0; i < (int) (sizeof(upcall_methods)/sizeof(upcall_methods[0])); ++i) + for (i = 0; i < (int) (sizeof(upcall_methods) / sizeof(upcall_methods[0])); ++i) if (code == upcall_methods[i].code) - return NewString(upcall_methods[i].method); + return NewString(upcall_methods[i].method); return NULL; } @@ -2844,25 +2786,25 @@ class JAVA : public Language { void emitDirectorUpcalls() { if (n_dmethods) { - Wrapper *w = NewWrapper(); - String *jni_imclass_name = makeValidJniName(imclass_name); - String *swig_module_init = NewString("swig_module_init"); - String *swig_module_init_jni = makeValidJniName(swig_module_init); - String *dmethod_data = NewString(""); - int n_methods = 0; - Iterator udata_iter; + Wrapper *w = NewWrapper(); + String *jni_imclass_name = makeValidJniName(imclass_name); + String *swig_module_init = NewString("swig_module_init"); + String *swig_module_init_jni = makeValidJniName(swig_module_init); + String *dmethod_data = NewString(""); + int n_methods = 0; + Iterator udata_iter; udata_iter = First(dmethods_seq); while (udata_iter.item) { - UpcallData *udata = udata_iter.item; - Printf(dmethod_data, " { \"%s\", \"%s\" }", Getattr(udata, "imclass_method"), Getattr(udata, "imclass_fdesc")); - ++n_methods; + UpcallData *udata = udata_iter.item; + Printf(dmethod_data, " { \"%s\", \"%s\" }", Getattr(udata, "imclass_method"), Getattr(udata, "imclass_fdesc")); + ++n_methods; - udata_iter = Next(udata_iter); + udata_iter = Next(udata_iter); - if (udata_iter.item) - Putc(',', dmethod_data); - Putc('\n', dmethod_data); + if (udata_iter.item) + Putc(',', dmethod_data); + Putc('\n', dmethod_data); } Printf(f_runtime, "namespace Swig {\n"); @@ -2870,8 +2812,7 @@ class JAVA : public Language { Printf(f_runtime, " static jmethodID director_methids[%d];\n", n_methods); Printf(f_runtime, "}\n"); - Printf(w->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls) {", - jnipackage, jni_imclass_name, swig_module_init_jni); + Printf(w->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls) {", jnipackage, jni_imclass_name, swig_module_init_jni); Printf(w->code, "static struct {\n"); Printf(w->code, " const char *method;\n"); Printf(w->code, " const char *signature;\n"); @@ -2905,8 +2846,7 @@ class JAVA : public Language { * This is where the $javaclassname_director_connect is * generated. *--------------------------------------------------------------------*/ - void emitDirectorExtraMethods(Node *n) - { + void emitDirectorExtraMethods(Node *n) { if (!Swig_directorclass(n)) return; @@ -2924,12 +2864,10 @@ class JAVA : public Language { code_wrap = NewWrapper(); Printf(code_wrap->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, " - "jboolean jweak_global) {\n", - jnipackage, jni_imclass_name, swig_director_connect_jni); + "jboolean jweak_global) {\n", jnipackage, jni_imclass_name, swig_director_connect_jni); Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); Printf(code_wrap->code, " (void)jcls;\n"); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", - sym_name, sym_name); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), " "(jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));\n"); @@ -2946,16 +2884,14 @@ class JAVA : public Language { String *changeown_method_name = NewStringf("%s_change_ownership", proxy_class_name); String *changeown_jnimethod_name = makeValidJniName(changeown_method_name); - Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean take_or_release);\n", - changeown_method_name, proxy_class_name); + Printf(imclass_class_code, " public final static native void %s(%s obj, long cptr, boolean take_or_release);\n", changeown_method_name, proxy_class_name); code_wrap = NewWrapper(); Printf(code_wrap->def, "SWIGEXPORT void JNICALL Java_%s%s_%s(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {\n", - jnipackage, jni_imclass_name, changeown_jnimethod_name); + jnipackage, jni_imclass_name, changeown_jnimethod_name); Printf(code_wrap->code, " %s *obj = *((%s **)&objarg);\n", norm_name, norm_name); - Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", - sym_name, sym_name); + Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name); Printf(code_wrap->code, " (void)jcls;\n"); Printf(code_wrap->code, " if (director) {\n"); Printf(code_wrap->code, " director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);\n"); @@ -2980,8 +2916,7 @@ class JAVA : public Language { *--------------------------------------------------------------------*/ void - emitCodeTypemap(bool derived, String *lookup_type, const String *typemap, const String *methodname, const String *jnicall) - { + emitCodeTypemap(bool derived, String *lookup_type, const String *typemap, const String *methodname, const String *jnicall) { const String *tm = NULL; Node *tmattrs = NewHash(); String *lookup_tmname = NewString(typemap); @@ -2998,18 +2933,16 @@ class JAVA : public Language { if (*Char(tm)) { if (method_attr) { - String *codebody = Copy(tm); - Replaceall(codebody, "$methodname", method_attr); - Replaceall(codebody, "$jnicall", jnicall); - Append(proxy_class_def, codebody); - Delete(codebody); + String *codebody = Copy(tm); + Replaceall(codebody, "$methodname", method_attr); + Replaceall(codebody, "$jnicall", jnicall); + Append(proxy_class_def, codebody); + Delete(codebody); } else { - Swig_error(input_file, line_number, - "No %s method name attribute for %s\n", lookup_tmname, proxy_class_name); + Swig_error(input_file, line_number, "No %s method name attribute for %s\n", lookup_tmname, proxy_class_name); } } else { - Swig_error(input_file, line_number, - "No %s typemap for %s\n", lookup_tmname, proxy_class_name); + Swig_error(input_file, line_number, "No %s typemap for %s\n", lookup_tmname, proxy_class_name); } Delete(tmattrs); @@ -3032,7 +2965,7 @@ class JAVA : public Language { String *canonicalizeJNIDescriptor(String *descriptor_in, Parm *p) { String *pkg_path = Swig_typemap_lookup_new("javapackage", p, "", 0); - SwigType *type = Getattr(p,"type"); + SwigType *type = Getattr(p, "type"); if (pkg_path && Len(pkg_path) != 0) { Replaceall(pkg_path, ".", "/"); @@ -3065,43 +2998,43 @@ class JAVA : public Language { * --------------------------------------------------------------- */ int classDirectorMethod(Node *n, Node *parent, String *super) { - String *empty_str = NewString(""); - String *classname = Getattr(parent, "sym:name"); - String *c_classname = Getattr(parent, "name"); - String *name = Getattr(n, "name"); - String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - SwigType *returntype = Getattr(n,"returntype"); - String *overloaded_name = getOverloadedName(n); - String *storage = Getattr(n, "storage"); - String *value = Getattr(n, "value"); - String *decl = Getattr(n, "decl"); - String *declaration = NewString(""); - String *tm; - Parm *p; - int i; - Wrapper *w = NewWrapper(); - ParmList *l = Getattr(n, "parms"); - bool is_void = !(Cmp(returntype, "void")); - String *qualified_return = NewString(""); - bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); - int status = SWIG_OK; - bool output_director = true; - String *dirclassname = directorClassName(parent); - String *qualified_name = NewStringf("%s::%s", dirclassname, name); - String *jnidesc = NewString(""); - String *classdesc = NewString(""); - String *jniret_desc = NewString(""); - String *classret_desc = NewString(""); - SwigType *c_ret_type = NULL; - String *jupcall_args = NewString("jobj"); - String *imclass_dmethod; - String *callback_def = NewString(""); - String *callback_code = NewString(""); - String *imcall_args = NewString(""); - int gencomma = 0; - int classmeth_off = curr_class_dmethod - first_class_dmethod; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + String *empty_str = NewString(""); + String *classname = Getattr(parent, "sym:name"); + String *c_classname = Getattr(parent, "name"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + SwigType *returntype = Getattr(n, "returntype"); + String *overloaded_name = getOverloadedName(n); + String *storage = Getattr(n, "storage"); + String *value = Getattr(n, "value"); + String *decl = Getattr(n, "decl"); + String *declaration = NewString(""); + String *tm; + Parm *p; + int i; + Wrapper *w = NewWrapper(); + ParmList *l = Getattr(n, "parms"); + bool is_void = !(Cmp(returntype, "void")); + String *qualified_return = NewString(""); + bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0"))); + int status = SWIG_OK; + bool output_director = true; + String *dirclassname = directorClassName(parent); + String *qualified_name = NewStringf("%s::%s", dirclassname, name); + String *jnidesc = NewString(""); + String *classdesc = NewString(""); + String *jniret_desc = NewString(""); + String *classret_desc = NewString(""); + SwigType *c_ret_type = NULL; + String *jupcall_args = NewString("jobj"); + String *imclass_dmethod; + String *callback_def = NewString(""); + String *callback_code = NewString(""); + String *imcall_args = NewString(""); + int gencomma = 0; + int classmeth_off = curr_class_dmethod - first_class_dmethod; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; // Kludge Alert: functionWrapper sets sym:overload properly, but it // isn't at this point, so we have to manufacture it ourselves. At least @@ -3115,49 +3048,48 @@ class JAVA : public Language { qualified_return = SwigType_rcaststr(returntype, "c_result"); if (!is_void && (!ignored_method || pure_virtual)) { - if (!SwigType_isclass(returntype)) { - if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); - } else { - String *base_typename = SwigType_base(returntype); - String *resolved_typename = SwigType_typedef_resolve_all(base_typename); - Symtab *symtab = Getattr(n, "sym:symtab"); - Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); + if (!SwigType_isclass(returntype)) { + if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + String *base_typename = SwigType_base(returntype); + String *resolved_typename = SwigType_typedef_resolve_all(base_typename); + Symtab *symtab = Getattr(n, "sym:symtab"); + Node *typenode = Swig_symbol_clookup(resolved_typename, symtab); - if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { - /* initialize pointers to something sane. Same for abstract - classes when a reference is returned. */ - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); - } else { - /* If returning a reference, initialize the pointer to a sane - default - if a Java exception occurs, then the pointer returns - something other than a NULL-initialized reference. */ - String *non_ref_type = Copy(returntype); + if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) { + /* initialize pointers to something sane. Same for abstract + classes when a reference is returned. */ + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL); + } else { + /* If returning a reference, initialize the pointer to a sane + default - if a Java exception occurs, then the pointer returns + something other than a NULL-initialized reference. */ + String *non_ref_type = Copy(returntype); - /* Remove reference and const qualifiers */ - Replaceall(non_ref_type, "r.", ""); - Replaceall(non_ref_type, "q(const).", ""); - Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), - "=", SwigType_str(non_ref_type, "()"), NIL); - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); + /* Remove reference and const qualifiers */ + Replaceall(non_ref_type, "r.", ""); + Replaceall(non_ref_type, "q(const).", ""); + Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL); + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL); - Delete(non_ref_type); - } + Delete(non_ref_type); + } - Delete(base_typename); - Delete(resolved_typename); - } - } else { - SwigType *vt; + Delete(base_typename); + Delete(resolved_typename); + } + } else { + SwigType *vt; - vt = cplus_value_type(returntype); - if (!vt) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); - } else { - Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); - Delete(vt); - } - } + vt = cplus_value_type(returntype); + if (!vt) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL); + } else { + Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL); + Delete(vt); + } + } } /* Create the intermediate class wrapper */ @@ -3167,66 +3099,63 @@ class JAVA : public Language { if (tm) { Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, classname); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, - "No jtype typemap defined for %s\n", SwigType_str(returntype,0)); + Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0)); } String *cdesc = NULL; - SwigType *covariant = Getattr(n,"covariant"); + SwigType *covariant = Getattr(n, "covariant"); SwigType *adjustedreturntype = covariant ? covariant : returntype; Parm *adjustedreturntypeparm = NewParmFromNode(adjustedreturntype, empty_str, n); if ((tm = Swig_typemap_lookup_new("directorin", adjustedreturntypeparm, "", 0)) - && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { + && (cdesc = Getattr(adjustedreturntypeparm, "tmap:directorin:descriptor"))) { - // Note that in the case of polymorphic (covariant) return types, the - // method's return type is changed to be the base of the C++ return - // type - String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm); - Append(classret_desc, jnidesc_canon); - Delete(jnidesc_canon); + // Note that in the case of polymorphic (covariant) return types, the + // method's return type is changed to be the base of the C++ return + // type + String *jnidesc_canon = canonicalizeJNIDescriptor(cdesc, adjustedreturntypeparm); + Append(classret_desc, jnidesc_canon); + Delete(jnidesc_canon); } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for %s\n", SwigType_str(returntype,0)); - output_director = false; + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, "No or improper directorin typemap defined for %s\n", SwigType_str(returntype, 0)); + output_director = false; } /* Get the JNI field descriptor for this return type, add the JNI field descriptor to jniret_desc */ - Parm *retpm = NewParmFromNode(returntype, empty_str, n); + Parm *retpm = NewParmFromNode(returntype, empty_str, n); if ((c_ret_type = Swig_typemap_lookup_new("jni", retpm, "", 0))) { - Parm *tp = NewParmFromNode(c_ret_type, empty_str, n); + Parm *tp = NewParmFromNode(c_ret_type, empty_str, n); - if (!is_void && !ignored_method) { - String *jretval_decl = NewStringf("%s jresult", c_ret_type); - Wrapper_add_localv(w, "jresult", jretval_decl, " = 0", NIL); - Delete(jretval_decl); - } + if (!is_void && !ignored_method) { + String *jretval_decl = NewStringf("%s jresult", c_ret_type); + Wrapper_add_localv(w, "jresult", jretval_decl, " = 0", NIL); + Delete(jretval_decl); + } String *jdesc = NULL; - if ((tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) - && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { + if ((tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) + && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { // Objects marshalled passing a Java class across JNI boundary use jobject - the nouse flag indicates this // We need the specific Java class name instead of the generic 'Ljava/lang/Object;' if (GetFlag(tp, "tmap:directorin:nouse")) jdesc = cdesc; - String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp); - Append(jniret_desc, jnidesc_canon); - Delete(jnidesc_canon); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for %s\n", SwigType_str(c_ret_type,0)); - output_director = false; - } + String *jnidesc_canon = canonicalizeJNIDescriptor(jdesc, tp); + Append(jniret_desc, jnidesc_canon); + Delete(jnidesc_canon); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for %s\n", SwigType_str(c_ret_type, 0)); + output_director = false; + } - Delete(tp); + Delete(tp); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, - "No jni typemap defined for %s\n", SwigType_str(returntype,0)); - output_director = false; + Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(returntype, 0)); + output_director = false; } Delete(adjustedreturntypeparm); @@ -3234,15 +3163,15 @@ class JAVA : public Language { } /* Go through argument list, attach lnames for arguments */ - for (i = 0, p=l; p; p = nextSibling(p), ++i) { + for (i = 0, p = l; p; p = nextSibling(p), ++i) { String *arg = Getattr(p, "name"); String *lname = NewString(""); if (!arg && Cmp(Getattr(p, "type"), "void")) { - lname = NewStringf("arg%d", i); - Setattr(p, "name", lname); + lname = NewStringf("arg%d", i); + Setattr(p, "name", lname); } else - lname = arg; + lname = arg; Setattr(p, "lname", lname); } @@ -3272,11 +3201,11 @@ class JAVA : public Language { if (!pure_virtual) { String *super_call = Swig_method_call(super, l); if (is_void) { - Printf(w->code, "%s;\n", super_call); + Printf(w->code, "%s;\n", super_call); if (!ignored_method) Printf(w->code, "return;\n"); } else { - Printf(w->code, "return %s;\n", super_call); + Printf(w->code, "return %s;\n", super_call); } Delete(super_call); } else { @@ -3286,10 +3215,9 @@ class JAVA : public Language { /* Make sure that we return something in the case of a pure * virtual method call for syntactical reasons. */ if (!is_void) - Printf(w->code, "return %s;", qualified_return); - else - if (!ignored_method) - Printf(w->code, "return;\n"); + Printf(w->code, "return %s;", qualified_return); + else if (!ignored_method) + Printf(w->code, "return;\n"); } if (!ignored_method) { @@ -3303,31 +3231,32 @@ class JAVA : public Language { String *jdesc; if ((tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) - && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { + && (jdesc = Getattr(tp, "tmap:directorin:descriptor"))) { String *jni_canon = canonicalizeJNIDescriptor(jdesc, tp); Append(jnidesc, jni_canon); Delete(jni_canon); Delete(tm); } else { Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap for type %s used in director method %s::%s\n", SwigType_str(type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + "No or improper directorin typemap for type %s used in director method %s::%s\n", SwigType_str(type, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); output_director = false; } Delete(tp); /* Go through argument list, convert from native to Java */ - for (p=l; p; /* empty */) { + for (p = l; p; /* empty */ ) { /* Is this superfluous? */ - while (checkAttribute(p,"tmap:directorin:numinputs","0")) { - p = Getattr(p,"tmap:directorin:next"); + while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { + p = Getattr(p, "tmap:directorin:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Copy(Getattr(p,"name")); - String *c_param_type = NULL; - String *c_decl = NewString(""); - String *arg = NewString(""); + SwigType *pt = Getattr(p, "type"); + String *ln = Copy(Getattr(p, "name")); + String *c_param_type = NULL; + String *c_decl = NewString(""); + String *arg = NewString(""); Printf(arg, "j%s", ln); @@ -3340,102 +3269,98 @@ class JAVA : public Language { /* Get parameter's intermediary C type */ if ((c_param_type = Getattr(p, "tmap:jni"))) { - Parm *tp = NewParmFromNode(c_param_type, empty_str, n); - String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL; + Parm *tp = NewParmFromNode(c_param_type, empty_str, n); + String *desc_tm = NULL, *jdesc = NULL, *cdesc = NULL; - /* Add to local variables */ - Printf(c_decl, "%s %s", c_param_type, arg); + /* Add to local variables */ + Printf(c_decl, "%s %s", c_param_type, arg); if (!ignored_method) Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL); - /* Add input marshalling code and update JNI field descriptor */ - if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) - && (jdesc = Getattr(tp, "tmap:directorin:descriptor")) - && (tm = Getattr(p, "tmap:directorin")) - && (cdesc = Getattr(p, "tmap:directorin:descriptor"))) { - + /* Add input marshalling code and update JNI field descriptor */ + if ((desc_tm = Swig_typemap_lookup_new("directorin", tp, "", 0)) + && (jdesc = Getattr(tp, "tmap:directorin:descriptor")) + && (tm = Getattr(p, "tmap:directorin")) + && (cdesc = Getattr(p, "tmap:directorin:descriptor"))) { + // Objects marshalled by passing a Java class across the JNI boundary use jobject as the JNI type - // the nouse flag indicates this. We need the specific Java class name instead of the generic 'Ljava/lang/Object;' if (GetFlag(tp, "tmap:directorin:nouse")) jdesc = cdesc; - String *jni_canon = canonicalizeJNIDescriptor(jdesc, tp); - Append(jnidesc, jni_canon); - Delete(jni_canon); + String *jni_canon = canonicalizeJNIDescriptor(jdesc, tp); + Append(jnidesc, jni_canon); + Delete(jni_canon); - Replaceall(tm,"$input", arg); + Replaceall(tm, "$input", arg); - if (Len(tm)) + if (Len(tm)) if (!ignored_method) - Printf(w->code,"%s\n", tm); + Printf(w->code, "%s\n", tm); - Delete(tm); + Delete(tm); - /* Add parameter to the intermediate class code if generating the - * intermediate's upcall code */ - if ((tm = Getattr(p, "tmap:jtype"))) { - String *din = Copy(Getattr(p, "tmap:javadirectorin")); + /* Add parameter to the intermediate class code if generating the + * intermediate's upcall code */ + if ((tm = Getattr(p, "tmap:jtype"))) { + String *din = Copy(Getattr(p, "tmap:javadirectorin")); - if (din) { - Replaceall(din, "$module", module_class_name); - Replaceall(din, "$imclassname", imclass_name); - substituteClassname(pt, din); - Replaceall(din, "$jniinput", ln); + if (din) { + Replaceall(din, "$module", module_class_name); + Replaceall(din, "$imclassname", imclass_name); + substituteClassname(pt, din); + Replaceall(din, "$jniinput", ln); - if (++gencomma > 1) - Printf(imcall_args, ", "); - Printf(callback_def, ", %s %s", tm, ln); + if (++gencomma > 1) + Printf(imcall_args, ", "); + Printf(callback_def, ", %s %s", tm, ln); - if (Cmp(din, ln)) { - Printv(imcall_args, din, NIL); - } else - Printv(imcall_args, ln, NIL); + if (Cmp(din, ln)) { + Printv(imcall_args, din, NIL); + } else + Printv(imcall_args, ln, NIL); - jni_canon = canonicalizeJNIDescriptor(cdesc, p); - Append(classdesc, jni_canon); - Delete(jni_canon); - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, - "No javadirectorin typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - } - } else { - Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, - "No jtype typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - } + jni_canon = canonicalizeJNIDescriptor(cdesc, p); + Append(classdesc, jni_canon); + Delete(jni_canon); + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, "No javadirectorin typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + } + } else { + Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + } - p = Getattr(p, "tmap:directorin:next"); + p = Getattr(p, "tmap:directorin:next"); - Delete(desc_tm); - } else { - if (!desc_tm) { - Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); - p = nextSibling(p); - } else if (!jdesc) { - Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number, - "Missing JNI descriptor in directorin typemap defined for %s\n", - SwigType_str(c_param_type, 0)); - p = Getattr(p, "tmap:directorin:next"); - } else if (!tm) { - Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, - "No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0)); - p = nextSibling(p); - } else if (!cdesc) { - Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number, - "Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(pt, 0)); - p = Getattr(p, "tmap:directorin:next"); - } + Delete(desc_tm); + } else { + if (!desc_tm) { + Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); + p = nextSibling(p); + } else if (!jdesc) { + Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number, + "Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(c_param_type, 0)); + p = Getattr(p, "tmap:directorin:next"); + } else if (!tm) { + Swig_warning(WARN_JAVA_TYPEMAP_JAVADIRECTORIN_UNDEF, input_file, line_number, + "No or improper directorin typemap defined for argument %s\n", SwigType_str(pt, 0)); + p = nextSibling(p); + } else if (!cdesc) { + Swig_warning(WARN_JAVA_TYPEMAP_DIRECTORIN_NODESC, input_file, line_number, + "Missing JNI descriptor in directorin typemap defined for %s\n", SwigType_str(pt, 0)); + p = Getattr(p, "tmap:directorin:next"); + } - output_director = false; - } + output_director = false; + } - Delete(tp); + Delete(tp); } else { - Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, - "No jni typemap defined for %s\n", SwigType_str(pt,0)); - output_director = false; - p = nextSibling(p); + Swig_warning(WARN_JAVA_TYPEMAP_JNI_UNDEF, input_file, line_number, "No jni typemap defined for %s\n", SwigType_str(pt, 0)); + output_director = false; + p = nextSibling(p); } Delete(arg); @@ -3467,28 +3392,29 @@ class JAVA : public Language { // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((tm = Swig_typemap_lookup_new("out",n,"",0))) + if ((tm = Swig_typemap_lookup_new("out", n, "", 0))) addThrows(n, "tmap:out", n); - if ((throw_parm_list = Getattr(n,"throws")) || Getattr(n,"throw")) { - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + int gencomma = 0; Append(w->def, " throw("); Append(declaration, " throw("); - if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { - addThrows(n, "tmap:throws", p); + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + addThrows(n, "tmap:throws", p); - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } - Printf(w->def, "%s", SwigType_str(Getattr(p, "type"),0)); - Printf(declaration, "%s", SwigType_str(Getattr(p, "type"),0)); - } + Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0)); + Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0)); + } } Append(w->def, ")"); @@ -3503,7 +3429,7 @@ class JAVA : public Language { Putc(')', callback_def); generateThrowsClause(n, callback_def); Printf(callback_def, " {\n"); - + /* Emit the intermediate class's upcall to the actual class */ String *upcall = NewStringf("self.%s(%s)", symname, imcall_args); @@ -3513,10 +3439,10 @@ class JAVA : public Language { tm = Swig_typemap_lookup_new("javadirectorout", tp, "", 0); if (tm) { - substituteClassname(returntype, tm); - Replaceall(tm, "$javacall", upcall); + substituteClassname(returntype, tm); + Replaceall(tm, "$javacall", upcall); - Printf(callback_code, " return %s;\n", tm); + Printf(callback_code, " return %s;\n", tm); } Delete(tm); @@ -3535,10 +3461,10 @@ class JAVA : public Language { String *methid = Getattr(udata, "imclass_methodidx"); String *methop = getUpcallJNIMethod(jniret_desc); - if (!is_void) Printf(w->code, "jresult = (%s) ", c_ret_type); + if (!is_void) + Printf(w->code, "jresult = (%s) ", c_ret_type); - Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", - methop, imclass_name, methid, jupcall_args); + Printf(w->code, "jenv->%s(Swig::jclass_%s, Swig::director_methids[%s], %s);\n", methop, imclass_name, methid, jupcall_args); Printf(w->code, "if (jenv->ExceptionOccurred()) return $null;\n"); @@ -3550,12 +3476,13 @@ class JAVA : public Language { /* Copy jresult into c_result... */ if ((tm = Swig_typemap_lookup_new("directorout", tp, result_str, w))) { addThrows(n, "tmap:directorout", tp); - Replaceall(tm,"$input", jresult_str); - Replaceall(tm,"$result", result_str); + Replaceall(tm, "$input", jresult_str); + Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); output_director = false; } @@ -3573,8 +3500,8 @@ class JAVA : public Language { Printf(w->code, "}\n"); /* This makes all the director methods segfault on Solaris 8 - Printf(w->code, "if (jobj) jenv->DeleteLocalRef(jobj);\n"); - */ + Printf(w->code, "if (jobj) jenv->DeleteLocalRef(jobj);\n"); + */ if (!is_void) Printf(w->code, "return %s;", qualified_return); @@ -3584,8 +3511,7 @@ class JAVA : public Language { // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) - { + if (dirprot_mode() && !is_public(n) && !pure_virtual) { Printv(inline_extra_method, declaration, NIL); String *extra_method_name = NewStringf("%sSwigPublic", name); Replaceall(inline_extra_method, name, extra_method_name); @@ -3600,17 +3526,17 @@ class JAVA : public Language { /* emit code */ if (status == SWIG_OK && output_director) { - if(!is_void) { - Replaceall(w->code,"$null", qualified_return); + if (!is_void) { + Replaceall(w->code, "$null", qualified_return); } else { - Replaceall(w->code,"$null",""); + Replaceall(w->code, "$null", ""); } if (!GetFlag(n, "feature:ignore")) Printv(imclass_directors, callback_def, callback_code, NIL); - if (!Getattr(n,"defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); } } @@ -3632,11 +3558,11 @@ class JAVA : public Language { * ------------------------------------------------------------ */ void directorPrefixArgs(Node *n) { - Parm *p; + Parm *p; /* Need to prepend 'jenv' to the director constructor's argument list */ - String *jenv_type = NewString("JNIEnv"); + String *jenv_type = NewString("JNIEnv"); SwigType_add_pointer(jenv_type); @@ -3664,18 +3590,18 @@ class JAVA : public Language { /* Assign arguments to superclass's parameters, if not already done */ for (p = superparms; p; p = nextSibling(p)) { - String *pname = Getattr(p, "name"); + String *pname = Getattr(p, "name"); if (!pname) { - pname = NewStringf("arg%d", argidx++); - Setattr(p, "name", pname); + pname = NewStringf("arg%d", argidx++); + Setattr(p, "name", pname); } } /* insert jenv prefix argument */ parms = CopyParmList(superparms); - String *jenv_type = NewString("JNIEnv"); + String *jenv_type = NewString("JNIEnv"); SwigType_add_pointer(jenv_type); p = NewParmFromNode(jenv_type, NewString("jenv"), n); set_nextSibling(p, parms); @@ -3683,27 +3609,27 @@ class JAVA : public Language { directorPrefixArgs(n); - if (!Getattr(n,"defaultargs")) { + if (!Getattr(n, "defaultargs")) { /* constructor */ { - String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); - String *call = Swig_csuperclass_call(0, basetype, superparms); - String *classtype = SwigType_namestr(Getattr(n, "name")); + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); + String *call = Swig_csuperclass_call(0, basetype, superparms); + String *classtype = SwigType_namestr(Getattr(n, "name")); - Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); - Printf(f_directors, "}\n\n"); + Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor")); + Printf(f_directors, "}\n\n"); - Delete(classtype); - Delete(target); - Delete(call); + Delete(classtype); + Delete(target); + Delete(call); } /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); - Printf(f_directors_h, " %s;\n", target); - Delete(target); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); } } @@ -3717,14 +3643,13 @@ class JAVA : public Language { /* ------------------------------------------------------------ * classDirectorDefaultConstructor() * ------------------------------------------------------------ */ - + int classDirectorDefaultConstructor(Node *n) { String *classname = Swig_class_name(n); String *classtype = SwigType_namestr(Getattr(n, "name")); Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", - classname, classname, Getattr(n, "director:ctor")); + Printf(w->def, "SwigDirector_%s::SwigDirector_%s(JNIEnv *jenv) : %s {", classname, classname, Getattr(n, "director:ctor")); Printf(w->code, "}\n"); Wrapper_print(w, f_directors); @@ -3743,7 +3668,7 @@ class JAVA : public Language { int classDirectorInit(Node *n) { Delete(none_comparison); - none_comparison = NewString(""); // not used + none_comparison = NewString(""); // not used Delete(director_ctor_code); director_ctor_code = NewString("$director_new"); @@ -3756,7 +3681,7 @@ class JAVA : public Language { /* Keep track of the director methods for this class */ first_class_dmethod = curr_class_dmethod = n_dmethods; - + return Language::classDirectorInit(n); } @@ -3767,10 +3692,10 @@ class JAVA : public Language { int classDirectorDestructor(Node *n) { Node *current_class = getCurrentClass(); String *full_classname = Getattr(current_class, "name"); - String *classname= Swig_class_name(current_class); + String *classname = Swig_class_name(current_class); Wrapper *w = NewWrapper(); - if (Getattr(n,"throw")) { + if (Getattr(n, "throw")) { Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname); Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname); } else { @@ -3788,10 +3713,7 @@ class JAVA : public Language { disconn_tm = typemapLookup("directordisconnect", full_classname, WARN_NONE, disconn_attr); disconn_methodname = Getattr(disconn_attr, "tmap:directordisconnect:methodname"); - Printv(w->code, - " swig_disconnect_director_self(\"", disconn_methodname, "\");\n", - "}\n", - NIL); + Printv(w->code, " swig_disconnect_director_self(\"", disconn_methodname, "\");\n", "}\n", NIL); Wrapper_print(w, f_directors); @@ -3828,12 +3750,12 @@ class JAVA : public Language { Printf(w->def, "} methods[] = {\n"); for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) { - UpcallData *udata = Getitem(dmethods_seq, i); + UpcallData *udata = Getitem(dmethods_seq, i); - Printf(w->def, "{ \"%s\", \"%s\", NULL }", Getattr(udata, "method"), Getattr(udata, "fdesc")); - if (i != curr_class_dmethod - 1) - Putc(',', w->def); - Putc('\n', w->def); + Printf(w->def, "{ \"%s\", \"%s\", NULL }", Getattr(udata, "method"), Getattr(udata, "fdesc")); + if (i != curr_class_dmethod - 1) + Putc(',', w->def); + Putc('\n', w->def); } Printf(w->def, "};\n"); @@ -3894,31 +3816,31 @@ class JAVA : public Language { /* -------------------------------------------------------------------- * classDirectorDisown() * ------------------------------------------------------------------*/ + virtual int classDirectorDisown(Node *n) { - (void)n; + (void) n; return SWIG_OK; } - - /* ----------------------------------------------------------------------------- - * extraDirectorProtectedCPPMethodsRequired() - * ----------------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * extraDirectorProtectedCPPMethodsRequired() + *--------------------------------------------------------------------*/ bool extraDirectorProtectedCPPMethodsRequired() const { - return false; + return false; } - /* -------------------------------------------------------------------- + /*---------------------------------------------------------------------- * Java_director_declaration() * * Generate the director class's declaration * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" - * ------------------------------------------------------------------*/ + *--------------------------------------------------------------------*/ void Java_director_declaration(Node *n) { String *base = Getattr(n, "classtype"); String *class_ctor = NewString("Swig::Director(jenv)"); - String* classname = Swig_class_name(n); + String *classname = Swig_class_name(n); String *directorname = NewStringf("SwigDirector_%s", classname); String *declaration = Swig_class_declaration(n, directorname); @@ -3929,16 +3851,16 @@ class JAVA : public Language { Setattr(n, "director:ctor", class_ctor); } -}; /* class JAVA */ +}; /* class JAVA */ /* ----------------------------------------------------------------------------- * swig_java() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_java() { +static Language *new_swig_java() { return new JAVA(); } -extern "C" Language * swig_java(void) { +extern "C" Language *swig_java(void) { return new_swig_java(); } @@ -3946,7 +3868,7 @@ extern "C" Language * swig_java(void) { * Static member variables * ----------------------------------------------------------------------------- */ -const char *JAVA::usage = (char*)"\ +const char *JAVA::usage = (char *) "\ Java Options (available with -java)\n\ -nopgcpp - Suppress premature garbage collection prevention parameter\n\ -noproxy - Generate the low-level functional interface instead\n\ @@ -3954,4 +3876,3 @@ Java Options (available with -java)\n\ -oldvarnames - old intermediary method names for variable wrappers\n\ -package - set name of the Java package to \n\ \n"; - diff --git a/SWIG/Source/Modules/lang.cxx b/SWIG/Source/Modules/lang.cxx index c780c873e..88743f856 100644 --- a/SWIG/Source/Modules/lang.cxx +++ b/SWIG/Source/Modules/lang.cxx @@ -13,8 +13,8 @@ char cvsroot_lang_cxx[] = "$Header$"; #include "cparse.h" #include -static int director_mode = 0; /* set to 0 on default */ -static int director_protected_mode = 1; /* set to 1 on default */ +static int director_mode = 0; /* set to 0 on default */ +static int director_protected_mode = 1; /* set to 1 on default */ static int naturalvar_mode = 0; /* Set director_protected_mode */ @@ -31,35 +31,31 @@ void Wrapper_naturalvar_mode_set(int flag) { } extern "C" { - int Swig_director_mode() - { + int Swig_director_mode() { return director_mode; } } - - /* Some status variables used during parsing */ +static int InClass = 0; /* Parsing C++ or not */ +static String *ClassName = 0; /* This is the real name of the current class */ +static String *ClassPrefix = 0; /* Class prefix */ +static String *ClassType = 0; /* Fully qualified type name to use */ +static String *DirectorClassName = 0; /* Director name of the current class */ +int Abstract = 0; +int ImportMode = 0; +int IsVirtual = 0; +static String *AttributeFunctionGet = 0; +static String *AttributeFunctionSet = 0; +static Node *CurrentClass = 0; +int line_number = 0; +char *input_file = 0; +int SmartPointer = 0; +static Hash *classhash; -static int InClass = 0; /* Parsing C++ or not */ -static String *ClassName = 0; /* This is the real name of the current class */ -static String *ClassPrefix = 0; /* Class prefix */ -static String *ClassType = 0; /* Fully qualified type name to use */ -static String *DirectorClassName = 0;/* Director name of the current class */ -int Abstract = 0; -int ImportMode = 0; -int IsVirtual = 0; -static String *AttributeFunctionGet = 0; -static String *AttributeFunctionSet = 0; -static Node *CurrentClass = 0; -int line_number = 0; -char *input_file = 0; -int SmartPointer = 0; -static Hash *classhash; - -extern int GenerateDefault; -extern int ForceExtern; -extern int AddExtern; +extern int GenerateDefault; +extern int ForceExtern; +extern int AddExtern; /* import modes */ @@ -74,7 +70,7 @@ extern int AddExtern; int Dispatcher::emit_one(Node *n) { String *wrn; - int ret = SWIG_OK; + int ret = SWIG_OK; char *tag = Char(nodeType(n)); if (!tag) { @@ -82,91 +78,92 @@ int Dispatcher::emit_one(Node *n) { node!\n"); */ return SWIG_OK; } - + /* Do not proceed if marked with an error */ - - if (Getattr(n,"error")) return SWIG_OK; + + if (Getattr(n, "error")) + return SWIG_OK; /* Look for warnings */ - wrn = Getattr(n,"feature:warnfilter"); + wrn = Getattr(n, "feature:warnfilter"); if (wrn) { - Swig_warnfilter(wrn,1); + Swig_warnfilter(wrn, 1); } /* ============================================================ * C/C++ parsing * ============================================================ */ - - if (strcmp(tag,"extern") == 0) { + + if (strcmp(tag, "extern") == 0) { ret = externDeclaration(n); - } else if (strcmp(tag,"cdecl") == 0) { + } else if (strcmp(tag, "cdecl") == 0) { ret = cDeclaration(n); - } else if (strcmp(tag,"enum") == 0) { + } else if (strcmp(tag, "enum") == 0) { ret = enumDeclaration(n); - } else if (strcmp(tag,"enumitem") == 0) { + } else if (strcmp(tag, "enumitem") == 0) { ret = enumvalueDeclaration(n); - } else if (strcmp(tag,"enumforward") == 0) { + } else if (strcmp(tag, "enumforward") == 0) { ret = enumforwardDeclaration(n); - } else if (strcmp(tag,"class") == 0) { + } else if (strcmp(tag, "class") == 0) { ret = classDeclaration(n); - } else if (strcmp(tag,"classforward") == 0) { + } else if (strcmp(tag, "classforward") == 0) { ret = classforwardDeclaration(n); - } else if (strcmp(tag,"constructor") == 0) { + } else if (strcmp(tag, "constructor") == 0) { ret = constructorDeclaration(n); - } else if (strcmp(tag,"destructor") == 0) { + } else if (strcmp(tag, "destructor") == 0) { ret = destructorDeclaration(n); - } else if (strcmp(tag,"access") == 0) { + } else if (strcmp(tag, "access") == 0) { ret = accessDeclaration(n); - } else if (strcmp(tag,"using") == 0) { + } else if (strcmp(tag, "using") == 0) { ret = usingDeclaration(n); - } else if (strcmp(tag,"namespace") == 0) { + } else if (strcmp(tag, "namespace") == 0) { ret = namespaceDeclaration(n); - } else if (strcmp(tag,"template") == 0) { + } else if (strcmp(tag, "template") == 0) { ret = templateDeclaration(n); } - + /* =============================================================== * SWIG directives * =============================================================== */ - else if (strcmp(tag,"top") == 0) { + else if (strcmp(tag, "top") == 0) { ret = top(n); - } else if (strcmp(tag,"extend") == 0) { + } else if (strcmp(tag, "extend") == 0) { ret = extendDirective(n); - } else if (strcmp(tag,"apply") == 0) { + } else if (strcmp(tag, "apply") == 0) { ret = applyDirective(n); - } else if (strcmp(tag,"clear") == 0) { + } else if (strcmp(tag, "clear") == 0) { ret = clearDirective(n); - } else if (strcmp(tag,"constant") == 0) { + } else if (strcmp(tag, "constant") == 0) { ret = constantDirective(n); - } else if (strcmp(tag,"fragment") == 0) { + } else if (strcmp(tag, "fragment") == 0) { ret = fragmentDirective(n); - } else if (strcmp(tag,"import") == 0) { + } else if (strcmp(tag, "import") == 0) { ret = importDirective(n); - } else if (strcmp(tag,"include") == 0) { + } else if (strcmp(tag, "include") == 0) { ret = includeDirective(n); - } else if (strcmp(tag,"insert") == 0) { + } else if (strcmp(tag, "insert") == 0) { ret = insertDirective(n); - } else if (strcmp(tag,"module") == 0) { + } else if (strcmp(tag, "module") == 0) { ret = moduleDirective(n); - } else if (strcmp(tag,"native") == 0) { + } else if (strcmp(tag, "native") == 0) { ret = nativeDirective(n); - } else if (strcmp(tag,"pragma") == 0) { + } else if (strcmp(tag, "pragma") == 0) { ret = pragmaDirective(n); - } else if (strcmp(tag,"typemap") == 0) { + } else if (strcmp(tag, "typemap") == 0) { ret = typemapDirective(n); - } else if (strcmp(tag,"typemapcopy") == 0) { + } else if (strcmp(tag, "typemapcopy") == 0) { ret = typemapcopyDirective(n); - } else if (strcmp(tag,"typemapitem") == 0) { + } else if (strcmp(tag, "typemapitem") == 0) { ret = typemapitemDirective(n); - } else if (strcmp(tag,"types") == 0) { + } else if (strcmp(tag, "types") == 0) { ret = typesDirective(n); } else { - Printf(stderr,"%s:%d. Unrecognized parse tree node type '%s'\n", input_file, line_number, tag); + Printf(stderr, "%s:%d. Unrecognized parse tree node type '%s'\n", input_file, line_number, tag); ret = SWIG_ERROR; } if (wrn) { - Swig_warnfilter(wrn,0); + Swig_warnfilter(wrn, 0); } return ret; } @@ -179,19 +176,19 @@ int Dispatcher::emit_one(Node *n) { int Dispatcher::emit_children(Node *n) { Node *c; - char *eo = Char(Getattr(n,"feature:emitonlychildren")); + char *eo = Char(Getattr(n, "feature:emitonlychildren")); for (c = firstChild(n); c; c = nextSibling(c)) { if (eo) { const char *tag = Char(nodeType(c)); - if (strcmp(tag,"cdecl") == 0) { + if (strcmp(tag, "cdecl") == 0) { if (checkAttribute(c, "storage", "typedef")) tag = "typedef"; } - if (strstr(eo,tag) == 0) { + if (strstr(eo, tag) == 0) { continue; } } - emit_one(c); + emit_one(c); } return SWIG_OK; } @@ -200,64 +197,116 @@ int Dispatcher::emit_children(Node *n) { /* Stubs for dispatcher class. We don't do anything by default---up to derived class to fill in traversal code */ -int Dispatcher::defaultHandler(Node *) { return SWIG_OK; } -int Dispatcher::extendDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::applyDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::clearDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::constantDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::fragmentDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::importDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::includeDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::insertDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::moduleDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::nativeDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::pragmaDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::typemapDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::typemapitemDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::typemapcopyDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::typesDirective(Node *n) { return defaultHandler(n); } -int Dispatcher::cDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::externDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::enumDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::enumvalueDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::enumforwardDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::classDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::templateDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::classforwardDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::constructorDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::destructorDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::accessDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::usingDeclaration(Node *n) { return defaultHandler(n); } -int Dispatcher::namespaceDeclaration(Node *n) { return defaultHandler(n); } +int Dispatcher::defaultHandler(Node *) { + return SWIG_OK; +} +int Dispatcher::extendDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::applyDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::clearDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::constantDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::fragmentDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::importDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::includeDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::insertDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::moduleDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::nativeDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::pragmaDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::typemapDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::typemapitemDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::typemapcopyDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::typesDirective(Node *n) { + return defaultHandler(n); +} +int Dispatcher::cDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::externDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::enumDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::enumvalueDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::enumforwardDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::classDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::templateDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::classforwardDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::constructorDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::destructorDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::accessDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::usingDeclaration(Node *n) { + return defaultHandler(n); +} +int Dispatcher::namespaceDeclaration(Node *n) { + return defaultHandler(n); +} /* Allocators */ -Language::Language() : - none_comparison(NewString("$arg != 0")), - director_ctor_code(NewString("")), - director_prot_ctor_code(0), - symbols(NewHash()), - classtypes(NewHash()), - enumtypes(NewHash()), - overloading(0), - multiinput(0), - directors(0) -{ +Language::Language(): +none_comparison(NewString("$arg != 0")), +director_ctor_code(NewString("")), +director_prot_ctor_code(0), +symbols(NewHash()), +classtypes(NewHash()), +enumtypes(NewHash()), +overloading(0), +multiinput(0), +directors(0) { argc_template_string = NewString("argc"); argv_template_string = NewString("argv[%d]"); /* Default director constructor code, passed to Swig_ConstructorToFunction */ - Printv(director_ctor_code, - "if ( $comparison ) { /* subclassed */\n", - " $director_new \n", - "} else {\n", - " $nondirector_new \n", - "}\n", NIL); + Printv(director_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", "} else {\n", " $nondirector_new \n", "}\n", NIL); /* - Default director 'protected' constructor code, disabled by - default. Each language that needs it, has to define it. - */ + Default director 'protected' constructor code, disabled by + default. Each language that needs it, has to define it. + */ director_prot_ctor_code = 0; director_multiple_inheritance = 1; director_language = 0; @@ -278,29 +327,32 @@ Language::~Language() { int Language::emit_one(Node *n) { int ret; int oldext; - if (!n) return SWIG_OK; + if (!n) + return SWIG_OK; - if (GetFlag(n,"feature:ignore") - && !Getattr(n,"feature:onlychildren")) return SWIG_OK; + if (GetFlag(n, "feature:ignore") + && !Getattr(n, "feature:onlychildren")) + return SWIG_OK; oldext = Extend; - if (Getattr(n,"feature:extend")) Extend = 1; - + if (Getattr(n, "feature:extend")) + Extend = 1; + line_number = Getline(n); input_file = Char(Getfile(n)); /* - symtab = Getattr(n,"symtab"); - if (symtab) { - symtab = Swig_symbol_setscope(symtab); - } - */ + symtab = Getattr(n,"symtab"); + if (symtab) { + symtab = Swig_symbol_setscope(symtab); + } + */ ret = Dispatcher::emit_one(n); /* - if (symtab) { - Swig_symbol_setscope(symtab); - } - */ + if (symtab) { + Swig_symbol_setscope(symtab); + } + */ Extend = oldext; return ret; } @@ -308,8 +360,9 @@ int Language::emit_one(Node *n) { static Parm *nonvoid_parms(Parm *p) { if (p) { - SwigType *t = Getattr(p,"type"); - if (SwigType_type(t) == T_VOID) return 0; + SwigType *t = Getattr(p, "type"); + if (SwigType_type(t) == T_VOID) + return 0; } return p; } @@ -330,14 +383,15 @@ SwigType *cplus_value_type(SwigType *t) { static Node *first_nontemplate(Node *n) { while (n) { - if (Strcmp(nodeType(n),"template") != 0) return n; - n = Getattr(n,"sym:nextSibling"); + if (Strcmp(nodeType(n), "template") != 0) + return n; + n = Getattr(n, "sym:nextSibling"); } return n; } - + /* -------------------------------------------------------------------------- * swig_pragma() * @@ -345,25 +399,24 @@ static Node *first_nontemplate(Node *n) { * -------------------------------------------------------------------------- */ void swig_pragma(char *lang, char *name, char *value) { - if (strcmp(lang,"swig") == 0) { - if ((strcmp(name,"make_default") == 0) || ((strcmp(name,"makedefault") == 0))) { + if (strcmp(lang, "swig") == 0) { + if ((strcmp(name, "make_default") == 0) || ((strcmp(name, "makedefault") == 0))) { GenerateDefault = 1; - } else if ((strcmp(name,"no_default") == 0) || ((strcmp(name,"nodefault") == 0))) { - Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG",1, - "dangerous, use %%nodefaultctor, %%nodefaultdtor instead.\n"); + } else if ((strcmp(name, "no_default") == 0) || ((strcmp(name, "nodefault") == 0))) { + Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use %%nodefaultctor, %%nodefaultdtor instead.\n"); GenerateDefault = 0; - } else if (strcmp(name,"attributefunction") == 0) { + } else if (strcmp(name, "attributefunction") == 0) { String *nvalue = NewString(value); - char *s = strchr(Char(nvalue),':'); + char *s = strchr(Char(nvalue), ':'); if (!s) { Swig_error(input_file, line_number, "Bad value for attributefunction. Expected \"fmtget:fmtset\".\n"); } else { *s = 0; AttributeFunctionGet = NewString(Char(nvalue)); - AttributeFunctionSet = NewString(s+1); + AttributeFunctionSet = NewString(s + 1); } Delete(nvalue); - } else if (strcmp(name,"noattributefunction") == 0) { + } else if (strcmp(name, "noattributefunction") == 0) { AttributeFunctionGet = 0; AttributeFunctionSet = 0; } @@ -376,16 +429,17 @@ void swig_pragma(char *lang, char *name, char *value) { * Handle swig pragma directives. * -------------------------------------------------------------------------- */ int use_naturalvar_mode(Node *n) { - if (Getattr(n,"unnamed")) return 0; + if (Getattr(n, "unnamed")) + return 0; int nvar = naturalvar_mode || GetFlag(n, "feature:naturalvar"); if (!nvar) { /* look for feature in the class */ - SwigType *ty = Getattr(n,"type"); + SwigType *ty = Getattr(n, "type"); if (SwigType_isclass(ty)) { Node *m = Copy(n); SwigType *tys = SwigType_strip_qualifiers(ty); Swig_features_get(Swig_cparse_features(), 0, tys, 0, m); - nvar = GetFlag(m,"feature:naturalvar"); + nvar = GetFlag(m, "feature:naturalvar"); Delete(tys); Delete(m); } @@ -410,7 +464,7 @@ int Language::top(Node *n) { } } } - classhash = Getattr(n,"classes"); + classhash = Getattr(n, "classes"); return emit_children(n); } @@ -437,16 +491,15 @@ int Language::extendDirective(Node *n) { int Language::applyDirective(Node *n) { - Parm *pattern = Getattr(n,"pattern"); - Node *c = firstChild(n); + Parm *pattern = Getattr(n, "pattern"); + Node *c = firstChild(n); while (c) { - Parm *apattern = Getattr(c,"pattern"); + Parm *apattern = Getattr(c, "pattern"); if (ParmList_len(pattern) != ParmList_len(apattern)) { - Swig_error(input_file, line_number, "Can't apply (%s) to (%s). Number of arguments don't match.\n", - ParmList_str(pattern), ParmList_str(apattern)); + Swig_error(input_file, line_number, "Can't apply (%s) to (%s). Number of arguments don't match.\n", ParmList_str(pattern), ParmList_str(apattern)); } else { - if (!Swig_typemap_apply(pattern,apattern)) { - Swig_warning(WARN_TYPEMAP_APPLY_UNDEF,input_file,line_number,"Can't apply (%s). No typemaps are defined.\n", ParmList_str(pattern)); + if (!Swig_typemap_apply(pattern, apattern)) { + Swig_warning(WARN_TYPEMAP_APPLY_UNDEF, input_file, line_number, "Can't apply (%s). No typemaps are defined.\n", ParmList_str(pattern)); } } c = nextSibling(c); @@ -461,7 +514,7 @@ int Language::applyDirective(Node *n) { int Language::clearDirective(Node *n) { Node *p; for (p = firstChild(n); p; p = nextSibling(p)) { - ParmList *pattern = Getattr(p,"pattern"); + ParmList *pattern = Getattr(p, "pattern"); Swig_typemap_clear_apply(pattern); } return SWIG_OK; @@ -473,34 +526,36 @@ int Language::clearDirective(Node *n) { int Language::constantDirective(Node *n) { - if (CurrentClass && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (CurrentClass && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; - if (!GetFlag(n,"feature:allowexcept")) { - UnsetFlag(n,"feature:except"); - } - if (Getattr(n,"feature:exceptvar")) { - Setattr(n,"feature:except",Getattr(n,"feature:exceptvar")); + if (!GetFlag(n, "feature:allowexcept")) { + UnsetFlag(n, "feature:except"); } - + if (Getattr(n, "feature:exceptvar")) { + Setattr(n, "feature:except", Getattr(n, "feature:exceptvar")); + } + if (!ImportMode) { - Swig_require("constantDirective",n,"name", "?value",NIL); - String *name = Getattr(n,"name"); - String *value = Getattr(n,"value"); + Swig_require("constantDirective", n, "name", "?value", NIL); + String *name = Getattr(n, "name"); + String *value = Getattr(n, "value"); if (!value) { value = Copy(name); } else { /* if (checkAttribute(n,"type","char")) { - value = NewString(value); - } else { - value = NewStringf("%(escape)s", value); - } - */ - Setattr(n,"rawvalue",value); + value = NewString(value); + } else { + value = NewStringf("%(escape)s", value); + } + */ + Setattr(n, "rawvalue", value); value = NewStringf("%(escape)s", value); - if (!Len(value)) Append(value,"\\0"); + if (!Len(value)) + Append(value, "\\0"); /* Printf(stdout,"'%s' = '%s'\n", name, value); */ } - Setattr(n,"value", value); + Setattr(n, "value", value); this->constantWrapper(n); Swig_restore(n); return SWIG_OK; @@ -544,19 +599,19 @@ int Language::includeDirective(Node *n) { int Language::insertDirective(Node *n) { /* %insert directive */ - if ((!ImportMode) || Getattr(n,"generated")) { - String *code = Getattr(n,"code"); - String *section = Getattr(n,"section"); + if ((!ImportMode) || Getattr(n, "generated")) { + String *code = Getattr(n, "code"); + String *section = Getattr(n, "section"); File *f = 0; - if (!section) { /* %{ ... %} */ + if (!section) { /* %{ ... %} */ f = Swig_filebyname("header"); } else { f = Swig_filebyname(section); } if (f) { - Printf(f,"%s\n",code); + Printf(f, "%s\n", code); } else { - Swig_error(input_file,line_number,"Unknown target '%s' for %%insert directive.\n", section); + Swig_error(input_file, line_number, "Unknown target '%s' for %%insert directive.\n", section); } return SWIG_OK; } else { @@ -569,7 +624,7 @@ int Language::insertDirective(Node *n) { * ---------------------------------------------------------------------- */ int Language::moduleDirective(Node *n) { - (void)n; + (void) n; /* %module directive */ return SWIG_OK; } @@ -593,11 +648,11 @@ int Language::nativeDirective(Node *n) { int Language::pragmaDirective(Node *n) { /* %pragma directive */ if (!ImportMode) { - String *lan = Getattr(n,"lang"); - String *name = Getattr(n,"name"); - String *value = Getattr(n,"value"); - swig_pragma(Char(lan),Char(name),Char(value)); - /* pragma(Char(lan),Char(name),Char(value)); */ + String *lan = Getattr(n, "lang"); + String *name = Getattr(n, "name"); + String *value = Getattr(n, "value"); + swig_pragma(Char(lan), Char(name), Char(value)); + /* pragma(Char(lan),Char(name),Char(value)); */ return SWIG_OK; } return SWIG_OK; @@ -609,18 +664,17 @@ int Language::pragmaDirective(Node *n) { int Language::typemapDirective(Node *n) { /* %typemap directive */ - String *method = Getattr(n,"method"); - String *code = Getattr(n,"code"); - Parm *kwargs = Getattr(n,"kwargs"); - Node *items = firstChild(n); - static int namewarn = 0; - + String *method = Getattr(n, "method"); + String *code = Getattr(n, "code"); + Parm *kwargs = Getattr(n, "kwargs"); + Node *items = firstChild(n); + static int namewarn = 0; - if (code && (Strstr(code,"$source") || (Strstr(code,"$target")))) { - Swig_warning(WARN_TYPEMAP_SOURCETARGET,Getfile(n),Getline(n),"Deprecated typemap feature ($source/$target).\n"); + + if (code && (Strstr(code, "$source") || (Strstr(code, "$target")))) { + Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "Deprecated typemap feature ($source/$target).\n"); if (!namewarn) { - Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), - "The use of $source and $target in a typemap declaration is deprecated.\n\ + Swig_warning(WARN_TYPEMAP_SOURCETARGET, Getfile(n), Getline(n), "The use of $source and $target in a typemap declaration is deprecated.\n\ For typemaps related to argument input (in,ignore,default,arginit,check), replace\n\ $source by $input and $target by $1. For typemaps related to return values (out,\n\ argout,ret,except), replace $source by $1 and $target by $result. See the file\n\ @@ -629,18 +683,17 @@ Doc/Manual/Typemaps.html for complete details.\n"); } } - if (Strcmp(method,"except") == 0) { - Swig_warning(WARN_DEPRECATED_EXCEPT_TM, Getfile(n), Getline(n), - "%%typemap(except) is deprecated. Use the %%exception directive.\n"); + if (Strcmp(method, "except") == 0) { + Swig_warning(WARN_DEPRECATED_EXCEPT_TM, Getfile(n), Getline(n), "%%typemap(except) is deprecated. Use the %%exception directive.\n"); } - if (Strcmp(method,"in") == 0) { + if (Strcmp(method, "in") == 0) { Hash *k; k = kwargs; while (k) { - if (checkAttribute(k,"name","numinputs")) { - if (!multiinput && (GetInt(k,"value") > 1)) { - Swig_error(Getfile(n),Getline(n),"Multiple-input typemaps (numinputs > 1) not supported by this target language module.\n"); + if (checkAttribute(k, "name", "numinputs")) { + if (!multiinput && (GetInt(k, "value") > 1)) { + Swig_error(Getfile(n), Getline(n), "Multiple-input typemaps (numinputs > 1) not supported by this target language module.\n"); return SWIG_ERROR; } break; @@ -649,44 +702,43 @@ Doc/Manual/Typemaps.html for complete details.\n"); } if (!k) { k = NewHash(); - Setattr(k,"name","numinputs"); - Setattr(k,"value","1"); - set_nextSibling(k,kwargs); - Setattr(n,"kwargs",k); + Setattr(k, "name", "numinputs"); + Setattr(k, "value", "1"); + set_nextSibling(k, kwargs); + Setattr(n, "kwargs", k); kwargs = k; } } - if (Strcmp(method,"ignore") == 0) { - Swig_warning(WARN_DEPRECATED_IGNORE_TM, Getfile(n), Getline(n), - "%%typemap(ignore) has been replaced by %%typemap(in,numinputs=0).\n"); - + if (Strcmp(method, "ignore") == 0) { + Swig_warning(WARN_DEPRECATED_IGNORE_TM, Getfile(n), Getline(n), "%%typemap(ignore) has been replaced by %%typemap(in,numinputs=0).\n"); + Clear(method); - Append(method,"in"); + Append(method, "in"); Hash *k = NewHash(); - Setattr(k,"name","numinputs"); - Setattr(k,"value","0"); - set_nextSibling(k,kwargs); - Setattr(n,"kwargs",k); + Setattr(k, "name", "numinputs"); + Setattr(k, "value", "0"); + set_nextSibling(k, kwargs); + Setattr(n, "kwargs", k); kwargs = k; } /* Replace $descriptor() macros */ if (code) { - Setfile(code,Getfile(n)); - Setline(code,Getline(n)); + Setfile(code, Getfile(n)); + Setline(code, Getline(n)); Swig_cparse_replace_descriptor(code); } while (items) { - Parm *pattern = Getattr(items,"pattern"); - Parm *parms = Getattr(items,"parms"); - + Parm *pattern = Getattr(items, "pattern"); + Parm *parms = Getattr(items, "parms"); + if (code) { - Swig_typemap_register(method,pattern,code,parms,kwargs); + Swig_typemap_register(method, pattern, code, parms, kwargs); } else { - Swig_typemap_clear(method,pattern); + Swig_typemap_clear(method, pattern); } items = nextSibling(items); } @@ -699,17 +751,17 @@ Doc/Manual/Typemaps.html for complete details.\n"); * ---------------------------------------------------------------------- */ int Language::typemapcopyDirective(Node *n) { - String *method = Getattr(n,"method"); - Parm *pattern = Getattr(n,"pattern"); - Node *items = firstChild(n); - int nsrc = 0; + String *method = Getattr(n, "method"); + Parm *pattern = Getattr(n, "pattern"); + Node *items = firstChild(n); + int nsrc = 0; nsrc = ParmList_len(pattern); while (items) { - ParmList *npattern = Getattr(items,"pattern"); + ParmList *npattern = Getattr(items, "pattern"); if (nsrc != ParmList_len(npattern)) { - Swig_error(input_file,line_number,"Can't copy typemap. Number of types differ.\n"); + Swig_error(input_file, line_number, "Can't copy typemap. Number of types differ.\n"); } else { - if (Swig_typemap_copy(method,pattern,npattern) < 0) { + if (Swig_typemap_copy(method, pattern, npattern) < 0) { Swig_error(input_file, line_number, "Can't copy typemap.\n"); } } @@ -723,15 +775,15 @@ int Language::typemapcopyDirective(Node *n) { * ---------------------------------------------------------------------- */ int Language::typesDirective(Node *n) { - Parm *parms = Getattr(n,"parms"); + Parm *parms = Getattr(n, "parms"); while (parms) { - SwigType *t = Getattr(parms,"type"); - String *v = Getattr(parms,"value"); + SwigType *t = Getattr(parms, "type"); + String *v = Getattr(parms, "value"); if (!v) { SwigType_remember(t); } else { if (SwigType_issimple(t)) { - SwigType_inherit(t,v,0); + SwigType_inherit(t, v, 0); } } parms = nextSibling(parms); @@ -745,42 +797,42 @@ int Language::typesDirective(Node *n) { int Language::cDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - SwigType *decl = Getattr(n,"decl"); - String *storage = Getattr(n,"storage"); - Node *over; - File *f_header = 0; + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + SwigType *decl = Getattr(n, "decl"); + String *storage = Getattr(n, "storage"); + Node *over; + File *f_header = 0; SwigType *ty, *fullty; /* discards nodes following the access control rules */ if (cplus_mode != PUBLIC || !is_public(n)) { /* except for friends, they are not affected by access control */ - int isfriend = storage && (Cmp(storage,"friend") == 0); - if (!isfriend ) { + int isfriend = storage && (Cmp(storage, "friend") == 0); + if (!isfriend) { /* we check what the director needs. If the method is pure virtual, - it is always needed. */ - if (!(directorsEnabled() && is_member_director(CurrentClass,n) && need_nonpublic_member(n))) { + it is always needed. */ + if (!(directorsEnabled() && is_member_director(CurrentClass, n) && need_nonpublic_member(n))) { return SWIG_NOWRAP; } /* prevent wrapping the method twice due to overload */ - String *wrapname = NewStringf("nonpublic_%s%s",Getattr(n,"sym:name"), Getattr(n,"sym:overname")); - if (Getattr(CurrentClass,wrapname)) { + String *wrapname = NewStringf("nonpublic_%s%s", Getattr(n, "sym:name"), Getattr(n, "sym:overname")); + if (Getattr(CurrentClass, wrapname)) { Delete(wrapname); - return SWIG_NOWRAP; + return SWIG_NOWRAP; } - SetFlag(CurrentClass,wrapname); + SetFlag(CurrentClass, wrapname); Delete(wrapname); } } - if (Cmp(storage,"typedef") == 0) { - Swig_save("cDeclaration",n,"type",NIL); + if (Cmp(storage, "typedef") == 0) { + Swig_save("cDeclaration", n, "type", NIL); SwigType *t = Copy(type); if (t) { - SwigType_push(t,decl); - Setattr(n,"type",t); + SwigType_push(t, decl); + Setattr(n, "type", t); typedefHandler(n); } Swig_restore(n); @@ -788,14 +840,15 @@ int Language::cDeclaration(Node *n) { } /* If in import mode, we proceed no further */ - if (ImportMode) return SWIG_NOWRAP; + if (ImportMode) + return SWIG_NOWRAP; /* If we're in extend mode and there is code, replace the $descriptor macros */ if (Extend) { - String *code = Getattr(n,"code"); + String *code = Getattr(n, "code"); if (code) { - Setfile(code,Getfile(n)); - Setline(code,Getline(n)); + Setfile(code, Getfile(n)); + Setline(code, Getline(n)); Swig_cparse_replace_descriptor(code); } } @@ -803,26 +856,27 @@ int Language::cDeclaration(Node *n) { /* Overloaded symbol check */ over = Swig_symbol_isoverloaded(n); if (!overloading) { - if (over) over = first_nontemplate(over); + if (over) + over = first_nontemplate(over); if (over && (over != n)) { SwigType *tc = Copy(decl); SwigType *td = SwigType_pop_function(tc); - String *oname; - String *cname; + String *oname; + String *cname; if (CurrentClass) { - oname = NewStringf("%s::%s",ClassName,name); - cname = NewStringf("%s::%s",ClassName,Getattr(over,"name")); + oname = NewStringf("%s::%s", ClassName, name); + cname = NewStringf("%s::%s", ClassName, Getattr(over, "name")); } else { oname = NewString(name); - cname = NewString(Getattr(over,"name")); + cname = NewString(Getattr(over, "name")); } - - SwigType *tc2 = Copy(Getattr(over,"decl")); + + SwigType *tc2 = Copy(Getattr(over, "decl")); SwigType *td2 = SwigType_pop_function(tc2); - - Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", SwigType_str(td,SwigType_namestr(oname))); - Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over),"Previous declaration is %s\n", SwigType_str(td2,SwigType_namestr(cname))); - + + Swig_warning(WARN_LANG_OVERLOAD_DECL, input_file, line_number, "Overloaded declaration ignored. %s\n", SwigType_str(td, SwigType_namestr(oname))); + Swig_warning(WARN_LANG_OVERLOAD_DECL, Getfile(over), Getline(over), "Previous declaration is %s\n", SwigType_str(td2, SwigType_namestr(cname))); + Delete(tc2); Delete(td2); Delete(tc); @@ -834,13 +888,12 @@ int Language::cDeclaration(Node *n) { } if (symname && !validIdentifier(symname)) { - Swig_warning(WARN_LANG_IDENTIFIER,input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", - symname); + Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap '%s' unless renamed to a valid identifier.\n", symname); return SWIG_NOWRAP; } ty = NewString(type); - SwigType_push(ty,decl); + SwigType_push(ty, decl); fullty = SwigType_typedef_resolve_all(ty); if (SwigType_isfunction(fullty)) { if (!SwigType_isfunction(ty)) { @@ -848,7 +901,7 @@ int Language::cDeclaration(Node *n) { ty = fullty; fullty = 0; ParmList *parms = SwigType_function_parms(ty); - Setattr(n,"parms",parms); + Setattr(n, "parms", parms); } /* Transform the node into a 'function' node and emit */ if (!CurrentClass) { @@ -856,38 +909,39 @@ int Language::cDeclaration(Node *n) { if (AddExtern) { if (f_header) { - if ((Cmp(storage,"extern") == 0) || (ForceExtern && !storage)) { + if ((Cmp(storage, "extern") == 0) || (ForceExtern && !storage)) { /* we don't need the 'extern' part in the C/C++ declaration, and it produces some problems when namespace and SUN Studio is used. Printf(f_header,"extern %s", SwigType_str(ty,name)); - + In fact generating extern declarations is quite error prone and is no longer the default. Getting it right seems impossible with namespaces and default arguments and when a method is declared with the various Windows calling conventions - SWIG doesn't understand Windows (non standard) calling conventions in the first place, so can't regenerate them. - */ - String *str = SwigType_str(ty,name); - Printf(f_header,"%s", str); + */ + String *str = SwigType_str(ty, name); + Printf(f_header, "%s", str); Delete(str); { - DOH *t = Getattr(n,"throws"); + DOH *t = Getattr(n, "throws"); if (t) { - Printf(f_header," throw("); + Printf(f_header, " throw("); while (t) { - Printf(f_header,"%s", Getattr(t,"type")); + Printf(f_header, "%s", Getattr(t, "type")); t = nextSibling(t); - if (t) Printf(f_header,","); + if (t) + Printf(f_header, ","); } - Printf(f_header,")"); + Printf(f_header, ")"); } } - Printf(f_header,";\n"); - } else if (Cmp(storage,"externc") == 0) { + Printf(f_header, ";\n"); + } else if (Cmp(storage, "externc") == 0) { /* here 'extern "C"' is needed */ - String *str = SwigType_str(ty,name); + String *str = SwigType_str(ty, name); Printf(f_header, "extern \"C\" %s;\n", str); Delete(str); } @@ -897,49 +951,50 @@ int Language::cDeclaration(Node *n) { /* This needs to check qualifiers */ if (SwigType_isqualifier(ty)) { SwigType *qual = SwigType_pop(ty); - Setattr(n,"qualifier", qual); + Setattr(n, "qualifier", qual); Delete(qual); } Delete(SwigType_pop_function(ty)); DohIncref(type); - Setattr(n,"type",ty); + Setattr(n, "type", ty); functionHandler(n); - Setattr(n,"type",type); + Setattr(n, "type", type); Delete(ty); Delete(type); return SWIG_OK; } else { /* Some kind of variable declaration */ - Delattr(n,"decl"); - if (Getattr(n,"nested")) SetFlag(n,"feature:immutable"); + Delattr(n, "decl"); + if (Getattr(n, "nested")) + SetFlag(n, "feature:immutable"); if (!CurrentClass) { - if ((Cmp(storage,"extern") == 0) || ForceExtern) { + if ((Cmp(storage, "extern") == 0) || ForceExtern) { f_header = Swig_filebyname("header"); if (AddExtern) { if (f_header) { - String *str = SwigType_str(ty,name); - Printf(f_header,"extern %s;\n", str); + String *str = SwigType_str(ty, name); + Printf(f_header, "extern %s;\n", str); Delete(str); } } } } if (!SwigType_ismutable(ty)) { - SetFlag(n,"feature:immutable"); + SetFlag(n, "feature:immutable"); } /* If an array and elements are const, then read-only */ if (SwigType_isarray(ty)) { SwigType *tya = SwigType_array_type(ty); if (SwigType_isconst(tya)) { - SetFlag(n,"feature:immutable"); + SetFlag(n, "feature:immutable"); } Delete(tya); } DohIncref(type); - Setattr(n,"type",ty); + Setattr(n, "type", ty); variableHandler(n); - Setattr(n,"type",type); - Setattr(n,"decl",decl); + Setattr(n, "type", type); + Setattr(n, "decl", decl); Delete(ty); Delete(type); Delete(fullty); @@ -951,19 +1006,18 @@ int Language::cDeclaration(Node *n) { * Language::functionHandler() * ---------------------------------------------------------------------- */ -int -Language::functionHandler(Node *n) { - String *storage = Getattr(n,"storage"); - int isfriend = CurrentClass && Cmp(storage,"friend") == 0; - int isstatic = CurrentClass && Cmp(storage,"static") == 0 && - !(SmartPointer && Getattr(n,"allocate:smartpointeraccess")); - Parm *p= Getattr(n,"parms"); - if (GetFlag(n,"feature:del")) { +int Language::functionHandler(Node *n) { + String *storage = Getattr(n, "storage"); + int isfriend = CurrentClass && Cmp(storage, "friend") == 0; + int isstatic = CurrentClass && Cmp(storage, "static") == 0 && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess")); + Parm *p = Getattr(n, "parms"); + if (GetFlag(n, "feature:del")) { /* the method acts like a delete operator, ie, we need to disown the parameter */ if (CurrentClass && !isstatic && !isfriend) { - SetFlag(n,"feature:self:disown"); + SetFlag(n, "feature:self:disown"); } else { - if (p) SetFlag(p,"wrap:disown"); + if (p) + SetFlag(p, "wrap:disown"); } } if (!CurrentClass) { @@ -974,20 +1028,20 @@ Language::functionHandler(Node *n) { } else if (isfriend) { globalfunctionHandler(n); } else { - Node* explicit_n = 0; - if (directorsEnabled() && is_member_director(CurrentClass,n) && !extraDirectorProtectedCPPMethodsRequired()) { + Node *explicit_n = 0; + if (directorsEnabled() && is_member_director(CurrentClass, n) && !extraDirectorProtectedCPPMethodsRequired()) { bool virtual_but_not_pure_virtual = (!(Cmp(storage, "virtual")) && (Cmp(Getattr(n, "value"), "0") != 0)); if (virtual_but_not_pure_virtual) { // Add additional wrapper which makes an explicit call to the virtual method (ie not a virtual call) explicit_n = Copy(n); - String *new_symname = Copy(Getattr(n,"sym:name")); - String *suffix = Getattr(parentNode(n),"sym:name"); + String *new_symname = Copy(Getattr(n, "sym:name")); + String *suffix = Getattr(parentNode(n), "sym:name"); Printv(new_symname, "SwigExplicit", suffix, NIL); - Setattr(explicit_n,"sym:name", new_symname); - Delattr(explicit_n,"storage"); - Delattr(explicit_n,"override"); - Delattr(explicit_n,"hides"); - SetFlag(explicit_n,"explicitcall"); + Setattr(explicit_n, "sym:name", new_symname); + Delattr(explicit_n, "storage"); + Delattr(explicit_n, "override"); + Delattr(explicit_n, "hides"); + SetFlag(explicit_n, "explicitcall"); Setattr(n, "explicitcallnode", explicit_n); } } @@ -996,8 +1050,8 @@ Language::functionHandler(Node *n) { if (explicit_n) { memberfunctionHandler(explicit_n); - Delattr(explicit_n,"explicitcall"); - Delete(explicit_n); + Delattr(explicit_n, "explicitcall"); + Delete(explicit_n); } } } @@ -1008,30 +1062,29 @@ Language::functionHandler(Node *n) { * Language::globalfunctionHandler() * ---------------------------------------------------------------------- */ -int -Language::globalfunctionHandler(Node *n) { +int Language::globalfunctionHandler(Node *n) { - Swig_require("globalfunctionHandler",n,"name","sym:name","type","?parms",NIL); + Swig_require("globalfunctionHandler", n, "name", "sym:name", "type", "?parms", NIL); - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *storage = Getattr(n,"storage"); - ParmList *parms = Getattr(n,"parms"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *storage = Getattr(n, "storage"); + ParmList *parms = Getattr(n, "parms"); - if (0 && (Cmp(storage,"static") == 0)) { + if (0 && (Cmp(storage, "static") == 0)) { Swig_restore(n); - return SWIG_NOWRAP; /* Can't wrap static functions */ + return SWIG_NOWRAP; /* Can't wrap static functions */ } else { /* Check for callback mode */ - String *cb = GetFlagAttr(n,"feature:callback"); + String *cb = GetFlagAttr(n, "feature:callback"); if (cb) { - String *cbname = Getattr(n,"feature:callback:name"); + String *cbname = Getattr(n, "feature:callback:name"); if (!cbname) { - cbname = NewStringf(cb,symname); - Setattr(n,"feature:callback:name",cbname); + cbname = NewStringf(cb, symname); + Setattr(n, "feature:callback:name", cbname); } - + callbackfunctionHandler(n); if (Cmp(cbname, symname) == 0) { Delete(cbname); @@ -1040,10 +1093,10 @@ Language::globalfunctionHandler(Node *n) { } Delete(cbname); } - Setattr(n,"parms",nonvoid_parms(parms)); - String *call = Swig_cfunction_call(name,parms); - String *cres = Swig_cresult(type,"result", call); - Setattr(n,"wrap:action", cres); + Setattr(n, "parms", nonvoid_parms(parms)); + String *call = Swig_cfunction_call(name, parms); + String *cres = Swig_cresult(type, "result", call); + Setattr(n, "wrap:action", cres); Delete(cres); Delete(call); functionWrapper(n); @@ -1056,31 +1109,31 @@ Language::globalfunctionHandler(Node *n) { * Language::callbackfunctionHandler() * ---------------------------------------------------------------------- */ -int -Language::callbackfunctionHandler(Node *n) { - Swig_require("callbackfunctionHandler",n,"name","*sym:name","*type","?value",NIL); - String *symname = Getattr(n,"sym:name"); - String *type = Getattr(n,"type"); - String *name = Getattr(n,"name"); - String *parms = Getattr(n,"parms"); - String *cb = GetFlagAttr(n,"feature:callback"); - String *cbname = Getattr(n,"feature:callback:name"); - String *calltype= NewStringf("(%s (*)(%s))(%s)", SwigType_str(type,0), ParmList_str(parms), SwigType_namestr(name)); +int Language::callbackfunctionHandler(Node *n) { + Swig_require("callbackfunctionHandler", n, "name", "*sym:name", "*type", "?value", NIL); + String *symname = Getattr(n, "sym:name"); + String *type = Getattr(n, "type"); + String *name = Getattr(n, "name"); + String *parms = Getattr(n, "parms"); + String *cb = GetFlagAttr(n, "feature:callback"); + String *cbname = Getattr(n, "feature:callback:name"); + String *calltype = NewStringf("(%s (*)(%s))(%s)", SwigType_str(type, 0), ParmList_str(parms), SwigType_namestr(name)); SwigType *cbty = Copy(type); - SwigType_add_function(cbty,parms); + SwigType_add_function(cbty, parms); SwigType_add_pointer(cbty); if (!cbname) { - cbname = NewStringf(cb,symname); - Setattr(n,"feature:callback:name",cbname); + cbname = NewStringf(cb, symname); + Setattr(n, "feature:callback:name", cbname); } - Setattr(n,"sym:name", cbname); - Setattr(n,"type", cbty); - Setattr(n,"value", calltype); + Setattr(n, "sym:name", cbname); + Setattr(n, "type", cbty); + Setattr(n, "value", calltype); - Node *ns = Getattr(symbols,cbname); - if (!ns) constantWrapper(n); + Node *ns = Getattr(symbols, cbname); + if (!ns) + constantWrapper(n); Delete(cbname); Delete(cbty); @@ -1093,21 +1146,20 @@ Language::callbackfunctionHandler(Node *n) { * Language::memberfunctionHandler() * ---------------------------------------------------------------------- */ -int -Language::memberfunctionHandler(Node *n) { +int Language::memberfunctionHandler(Node *n) { - Swig_require("memberfunctionHandler",n,"*name","*sym:name","*type","?parms","?value",NIL); + Swig_require("memberfunctionHandler", n, "*name", "*sym:name", "*type", "?parms", "?value", NIL); - String *storage = Getattr(n,"storage"); - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *value = Getattr(n,"value"); - ParmList *parms = Getattr(n,"parms"); - String *cb = GetFlagAttr(n,"feature:callback"); + String *storage = Getattr(n, "storage"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + ParmList *parms = Getattr(n, "parms"); + String *cb = GetFlagAttr(n, "feature:callback"); - if (Cmp(storage,"virtual") == 0) { - if (Cmp(value,"0") == 0) { + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { IsVirtual = PURE_VIRTUAL; } else { IsVirtual = PLAIN_VIRTUAL; @@ -1116,30 +1168,30 @@ Language::memberfunctionHandler(Node *n) { IsVirtual = 0; } if (cb) { - Node *cbn = NewHash(); - String *cbname = Getattr(n,"feature:callback:name"); + Node *cbn = NewHash(); + String *cbname = Getattr(n, "feature:callback:name"); if (!cbname) { - cbname = NewStringf(cb,symname); + cbname = NewStringf(cb, symname); } SwigType *cbty = Copy(type); - SwigType_add_function(cbty,parms); - SwigType_add_memberpointer(cbty,ClassName); - String *cbvalue = NewStringf("&%s::%s",ClassName,name); - Setattr(cbn,"sym:name", cbname); - Setattr(cbn,"type", cbty); - Setattr(cbn,"value", cbvalue); - Setattr(cbn,"name", name); + SwigType_add_function(cbty, parms); + SwigType_add_memberpointer(cbty, ClassName); + String *cbvalue = NewStringf("&%s::%s", ClassName, name); + Setattr(cbn, "sym:name", cbname); + Setattr(cbn, "type", cbty); + Setattr(cbn, "value", cbvalue); + Setattr(cbn, "name", name); memberconstantHandler(cbn); - Setattr(n,"feature:callback:name",Swig_name_member(ClassPrefix, cbname)); + Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname)); Delete(cb); Delete(cbn); Delete(cbvalue); Delete(cbty); Delete(cbname); - if (Cmp(cbname,symname) == 0) { + if (Cmp(cbname, symname) == 0) { Swig_restore(n); return SWIG_NOWRAP; } @@ -1147,32 +1199,32 @@ Language::memberfunctionHandler(Node *n) { String *fname = Swig_name_member(ClassPrefix, symname); if (Extend && SmartPointer) { - if (!Getattr(n,"classname")) { - Setattr(n,"classname",Getattr(CurrentClass,"allocate:smartpointerbase")); + if (!Getattr(n, "classname")) { + Setattr(n, "classname", Getattr(CurrentClass, "allocate:smartpointerbase")); } } - // Set up the type for the cast to this class for use when wrapping const director (virtual) methods. // Note: protected director methods only. - String* director_type = 0; - if (!is_public(n) && (is_member_director(CurrentClass,n) || GetFlag(n, "explicitcall"))) { + String *director_type = 0; + if (!is_public(n) && (is_member_director(CurrentClass, n) || GetFlag(n, "explicitcall"))) { director_type = Copy(DirectorClassName); - String *qualifier = Getattr(n,k_qualifier); + String *qualifier = Getattr(n, k_qualifier); if (qualifier) - SwigType_push(director_type,qualifier); + SwigType_push(director_type, qualifier); SwigType_add_pointer(director_type); } int DirectorExtraCall = 0; - if (directorsEnabled() && is_member_director(CurrentClass,n) && !SmartPointer) + if (directorsEnabled() && is_member_director(CurrentClass, n) && !SmartPointer) if (extraDirectorProtectedCPPMethodsRequired()) DirectorExtraCall = CWRAP_DIRECTOR_TWO_CALLS; if (GetFlag(n, "explicitcall")) DirectorExtraCall = CWRAP_DIRECTOR_ONE_CALL; - Swig_MethodToFunction(n, ClassType, Getattr(n,"template") ? 0 : Extend | SmartPointer | DirectorExtraCall, director_type, is_member_director(CurrentClass,n)); - Setattr(n,"sym:name",fname); + Swig_MethodToFunction(n, ClassType, Getattr(n, "template") ? 0 : Extend | SmartPointer | DirectorExtraCall, director_type, + is_member_director(CurrentClass, n)); + Setattr(n, "sym:name", fname); functionWrapper(n); Delete(director_type); @@ -1185,42 +1237,41 @@ Language::memberfunctionHandler(Node *n) { * Language::staticmemberfunctionHandler() * ---------------------------------------------------------------------- */ -int -Language::staticmemberfunctionHandler(Node *n) { +int Language::staticmemberfunctionHandler(Node *n) { - Swig_require("staticmemberfunctionHandler",n,"*name","*sym:name","*type",NIL); - Swig_save("staticmemberfunctionHandler",n,"storage",NIL); - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - ParmList *parms = Getattr(n,"parms"); - String *cb = GetFlagAttr(n,"feature:callback"); - String *cname, *mrename; + Swig_require("staticmemberfunctionHandler", n, "*name", "*sym:name", "*type", NIL); + Swig_save("staticmemberfunctionHandler", n, "storage", NIL); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + ParmList *parms = Getattr(n, "parms"); + String *cb = GetFlagAttr(n, "feature:callback"); + String *cname, *mrename; if (!Extend) { - Node *sb = Getattr(n,"cplus:staticbase"); - String *sname = sb ? Getattr(sb,"name") : 0; + Node *sb = Getattr(n, "cplus:staticbase"); + String *sname = sb ? Getattr(sb, "name") : 0; if (sname) { - cname = NewStringf("%s::%s",sname,name); + cname = NewStringf("%s::%s", sname, name); } else { - cname = NewStringf("%s::%s",ClassName,name); + cname = NewStringf("%s::%s", ClassName, name); } } else { String *mname = Swig_name_mangle(ClassName); - cname = Swig_name_member(mname,name); + cname = Swig_name_member(mname, name); Delete(mname); } mrename = Swig_name_member(ClassPrefix, symname); if (Extend) { - String *code = Getattr(n,"code"); - String *defaultargs = Getattr(n,"defaultargs"); + String *code = Getattr(n, "code"); + String *defaultargs = Getattr(n, "defaultargs"); String *mangled = Swig_name_mangle(mrename); Delete(mrename); mrename = mangled; - if (Getattr(n,"sym:overloaded") && code) { - Append(cname, Getattr(defaultargs ? defaultargs : n,"sym:overname")); + if (Getattr(n, "sym:overloaded") && code) { + Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname")); } if (!defaultargs && code) { @@ -1229,16 +1280,16 @@ Language::staticmemberfunctionHandler(Node *n) { } } - Setattr(n,"name",cname); - Setattr(n,"sym:name",mrename); + Setattr(n, "name", cname); + Setattr(n, "sym:name", mrename); if (cb) { - String *cbname = NewStringf(cb,symname); - Setattr(n,"feature:callback:name", Swig_name_member(ClassPrefix, cbname)); - Setattr(n,"feature:callback:staticname", name); + String *cbname = NewStringf(cb, symname); + Setattr(n, "feature:callback:name", Swig_name_member(ClassPrefix, cbname)); + Setattr(n, "feature:callback:staticname", name); } - Delattr(n,"storage"); - + Delattr(n, "storage"); + globalfunctionHandler(n); Delete(cname); @@ -1251,8 +1302,7 @@ Language::staticmemberfunctionHandler(Node *n) { * Language::variableHandler() * ---------------------------------------------------------------------- */ -int -Language::variableHandler(Node *n) { +int Language::variableHandler(Node *n) { /* If not a smart-pointer access or added method. We clear feature:except. There is no way C++ or C would throw @@ -1262,29 +1312,29 @@ Language::variableHandler(Node *n) { methods which can generate exceptions. The feature:allowexcept allows this. Also, the feature:exceptvar can be used to match only variables. - */ + */ if (!(Extend | SmartPointer)) { - if (!GetFlag(n,"feature:allowexcept")) { - UnsetFlag(n,"feature:except"); - } - if (Getattr(n,"feature:exceptvar")) { - Setattr(n,"feature:except",Getattr(n,"feature:exceptvar")); + if (!GetFlag(n, "feature:allowexcept")) { + UnsetFlag(n, "feature:except"); + } + if (Getattr(n, "feature:exceptvar")) { + Setattr(n, "feature:except", Getattr(n, "feature:exceptvar")); } } if (!CurrentClass) { globalvariableHandler(n); } else { - String *storage = Getattr(n,"storage"); - Swig_save("variableHandler",n,"feature:immutable",NIL); + String *storage = Getattr(n, "storage"); + Swig_save("variableHandler", n, "feature:immutable", NIL); if (SmartPointer) { /* If a smart-pointer and it's a constant access, we have to set immutable */ - if (Getattr(CurrentClass,"allocate:smartpointerconst")) { - SetFlag(n,"feature:immutable"); + if (Getattr(CurrentClass, "allocate:smartpointerconst")) { + SetFlag(n, "feature:immutable"); } } - if ((Cmp(storage,"static") == 0) - && !(SmartPointer && Getattr(n,"allocate:smartpointeraccess"))) { + if ((Cmp(storage, "static") == 0) + && !(SmartPointer && Getattr(n, "allocate:smartpointeraccess"))) { staticmembervariableHandler(n); } else { membervariableHandler(n); @@ -1298,10 +1348,10 @@ Language::variableHandler(Node *n) { * Language::globalvariableHandler() * ---------------------------------------------------------------------- */ -int -Language::globalvariableHandler(Node *n) { - String *storage = Getattr(n,"storage"); - if (0 && (Cmp(storage,"static") == 0)) return SWIG_NOWRAP; +int Language::globalvariableHandler(Node *n) { + String *storage = Getattr(n, "storage"); + if (0 && (Cmp(storage, "static") == 0)) + return SWIG_NOWRAP; variableWrapper(n); return SWIG_OK; } @@ -1310,15 +1360,14 @@ Language::globalvariableHandler(Node *n) { * Language::membervariableHandler() * ---------------------------------------------------------------------- */ -int -Language::membervariableHandler(Node *n) { +int Language::membervariableHandler(Node *n) { - Swig_require("membervariableHandler",n,"*name","*sym:name","*type",NIL); - Swig_save("membervariableHandler",n,"parms",NIL); + Swig_require("membervariableHandler", n, "*name", "*sym:name", "*type", NIL); + Swig_save("membervariableHandler", n, "parms", NIL); - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); if (!AttributeFunctionGet) { String *mname = Swig_name_member(ClassPrefix, symname); @@ -1327,58 +1376,57 @@ Language::membervariableHandler(Node *n) { Delete(mname); /* Create a function to set the value of the variable */ - + int assignable = is_assignable(n); if (SmartPointer) { - if (Getattr(CurrentClass,"allocate:smartpointerconst")) { + if (Getattr(CurrentClass, "allocate:smartpointerconst")) { assignable = 0; } } if (assignable) { - int make_set_wrapper = 1; + int make_set_wrapper = 1; String *tm = 0; String *target = 0; if (!Extend) { if (SmartPointer) { if (checkAttribute(n, "storage", "static")) { - Node *sn = Getattr(n,"cplus:staticbase"); - String *base = Getattr(sn,"name"); - target = NewStringf("%s::%s", base,name); + Node *sn = Getattr(n, "cplus:staticbase"); + String *base = Getattr(sn, "name"); + target = NewStringf("%s::%s", base, name); } else { - String *pname = Swig_cparm_name(0,0); - target = NewStringf("(*%s)->%s",pname,name); + String *pname = Swig_cparm_name(0, 0); + target = NewStringf("(*%s)->%s", pname, name); Delete(pname); } } else { - String *pname = Swig_cparm_name(0,0); - target = NewStringf("%s->%s", pname,name); + String *pname = Swig_cparm_name(0, 0); + target = NewStringf("%s->%s", pname, name); Delete(pname); - } - tm = Swig_typemap_lookup_new("memberin",n,target,0); + } + tm = Swig_typemap_lookup_new("memberin", n, target, 0); } int flags = Extend | SmartPointer | use_naturalvar_mode(n); - Swig_MembersetToFunction(n,ClassType, flags); - Setattr(n,"memberset", "1"); + Swig_MembersetToFunction(n, ClassType, flags); + Setattr(n, "memberset", "1"); if (!Extend) { /* Check for a member in typemap here */ if (!tm) { if (SwigType_isarray(type)) { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, - "Unable to set variable of type %s.\n", SwigType_str(type,0)); + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0)); make_set_wrapper = 0; } - } else { - String *pname0 = Swig_cparm_name(0,0); - String *pname1 = Swig_cparm_name(0,1); - Replace(tm,"$source", pname1, DOH_REPLACE_ANY); - Replace(tm,"$target", target, DOH_REPLACE_ANY); - Replace(tm,"$input",pname1,DOH_REPLACE_ANY); - Replace(tm,"$self",pname0,DOH_REPLACE_ANY); - Setattr(n,"wrap:action", tm); + } else { + String *pname0 = Swig_cparm_name(0, 0); + String *pname1 = Swig_cparm_name(0, 1); + Replace(tm, "$source", pname1, DOH_REPLACE_ANY); + Replace(tm, "$target", target, DOH_REPLACE_ANY); + Replace(tm, "$input", pname1, DOH_REPLACE_ANY); + Replace(tm, "$self", pname0, DOH_REPLACE_ANY); + Setattr(n, "wrap:action", tm); Delete(tm); Delete(pname0); Delete(pname1); @@ -1386,15 +1434,15 @@ Language::membervariableHandler(Node *n) { Delete(target); } if (make_set_wrapper) { - Setattr(n,"sym:name", mrename_set); + Setattr(n, "sym:name", mrename_set); functionWrapper(n); } else { - SetFlag(n,"feature:immutable"); + SetFlag(n, "feature:immutable"); } /* Restore parameters */ - Setattr(n,"type",type); - Setattr(n,"name",name); - Setattr(n,"sym:name",symname); + Setattr(n, "type", type); + Setattr(n, "name", name); + Setattr(n, "sym:name", symname); /* Delete all attached typemaps and typemap attributes */ Iterator ki; @@ -1406,9 +1454,9 @@ Language::membervariableHandler(Node *n) { /* Emit get function */ { int flags = Extend | SmartPointer | use_naturalvar_mode(n); - Swig_MembergetToFunction(n,ClassType, flags); - Setattr(n,"sym:name", mrename_get); - Setattr(n,"memberget", "1"); + Swig_MembergetToFunction(n, ClassType, flags); + Setattr(n, "sym:name", mrename_get); + Setattr(n, "memberget", "1"); functionWrapper(n); } Delete(mrename_get); @@ -1420,32 +1468,32 @@ Language::membervariableHandler(Node *n) { where member variables are converted automagically to accessor functions */ -#if 0 +#if 0 Parm *p; String *gname; SwigType *vty; - p = NewParm(type,0); - gname = NewStringf(AttributeFunctionGet,symname); + p = NewParm(type, 0); + gname = NewStringf(AttributeFunctionGet, symname); if (!Extend) { - ActionFunc = Copy(Swig_cmemberget_call(name,type)); - cpp_member_func(Char(gname),Char(gname),type,0); + ActionFunc = Copy(Swig_cmemberget_call(name, type)); + cpp_member_func(Char(gname), Char(gname), type, 0); Delete(ActionFunc); } else { String *cname = Swig_name_get(name); - cpp_member_func(Char(cname),Char(gname),type,0); + cpp_member_func(Char(cname), Char(gname), type, 0); Delete(cname); } Delete(gname); - if (!GetFlag(n,"feature:immutable")) { - gname = NewStringf(AttributeFunctionSet,symname); + if (!GetFlag(n, "feature:immutable")) { + gname = NewStringf(AttributeFunctionSet, symname); vty = NewString("void"); if (!Extend) { - ActionFunc = Copy(Swig_cmemberset_call(name,type)); - cpp_member_func(Char(gname),Char(gname),vty,p); + ActionFunc = Copy(Swig_cmemberset_call(name, type)); + cpp_member_func(Char(gname), Char(gname), vty, p); Delete(ActionFunc); } else { String *cname = Swig_name_set(name); - cpp_member_func(Char(cname),Char(gname),vty,p); + cpp_member_func(Char(cname), Char(gname), vty, p); Delete(cname); } Delete(gname); @@ -1461,27 +1509,25 @@ Language::membervariableHandler(Node *n) { * Language::staticmembervariableHandler() * ---------------------------------------------------------------------- */ -int -Language::staticmembervariableHandler(Node *n) -{ - Swig_require("staticmembervariableHandler",n,"*name","*sym:name","*type", "?value", NIL); - String *value = Getattr(n,"value"); - String *classname = !SmartPointer ? ClassName : Getattr(CurrentClass,"allocate:smartpointerbase"); - if (!value || !Getattr(n,"hasconsttype")) { - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); +int Language::staticmembervariableHandler(Node *n) { + Swig_require("staticmembervariableHandler", n, "*name", "*sym:name", "*type", "?value", NIL); + String *value = Getattr(n, "value"); + String *classname = !SmartPointer ? ClassName : Getattr(CurrentClass, "allocate:smartpointerbase"); + if (!value || !Getattr(n, "hasconsttype")) { + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); String *cname, *mrename; - + /* Create the variable name */ mrename = Swig_name_member(ClassPrefix, symname); - cname = NewStringf("%s::%s", classname,name); - - Setattr(n,"sym:name",mrename); - Setattr(n,"name", cname); - + cname = NewStringf("%s::%s", classname, name); + + Setattr(n, "sym:name", mrename); + Setattr(n, "name", cname); + /* Wrap as an ordinary global variable */ variableWrapper(n); - + Delete(mrename); Delete(cname); } else { @@ -1490,48 +1536,48 @@ Language::staticmembervariableHandler(Node *n) Certain C++ compilers optimize this out so that there is no linkage to a memory address. Example: - class Foo { - public: - static const int x = 3; - }; + class Foo { + public: + static const int x = 3; + }; - Some discussion of this in section 9.4 of the C++ draft standard. + Some discussion of this in section 9.4 of the C++ draft standard. - Also, we have to manage the case: + Also, we have to manage the case: - class Foo { - public: - %extend { - static const int x = 3; - } - }; + class Foo { + public: + %extend { + static const int x = 3; + } + }; - in which there's no actual Foo::x variable to refer to. In this case, - the best we can do is to wrap the given value verbatim. - */ + in which there's no actual Foo::x variable to refer to. In this case, + the best we can do is to wrap the given value verbatim. + */ - String *name = Getattr(n,"name"); - String *cname = NewStringf("%s::%s", classname,name); + String *name = Getattr(n, "name"); + String *cname = NewStringf("%s::%s", classname, name); if (Extend) { - /* the variable is a synthesized one. - There's nothing we can do; we just keep the given value */ + /* the variable is a synthesized one. + There's nothing we can do; we just keep the given value */ } else { - /* we refer to the value as Foo::x */ - String* value = SwigType_namestr(cname); - Setattr(n, "value", value); + /* we refer to the value as Foo::x */ + String *value = SwigType_namestr(cname); + Setattr(n, "value", value); } - SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n,"type")); - SwigType *t2 = SwigType_strip_qualifiers(t1); + SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n, "type")); + SwigType *t2 = SwigType_strip_qualifiers(t1); Setattr(n, "type", t2); Delete(t1); Delete(t2); - SetFlag(n,"wrappedasconstant"); + SetFlag(n, "wrappedasconstant"); memberconstantHandler(n); Delete(cname); - } - + } + Swig_restore(n); return SWIG_OK; } @@ -1561,13 +1607,14 @@ int Language::enumDeclaration(Node *n) { * ---------------------------------------------------------------------- */ int Language::enumvalueDeclaration(Node *n) { - if (CurrentClass && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (CurrentClass && (cplus_mode != PUBLIC)) + return SWIG_NOWRAP; - Swig_require("enumvalueDeclaration",n,"*name", "?value",NIL); - String *value = Getattr(n,"value"); - String *name = Getattr(n,"name"); + Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL); + String *value = Getattr(n, "value"); + String *name = Getattr(n, "name"); String *tmpValue; - + if (value) tmpValue = NewString(value); else @@ -1575,12 +1622,12 @@ int Language::enumvalueDeclaration(Node *n) { Setattr(n, "value", tmpValue); if (!CurrentClass || !cparse_cplusplus) { - Setattr(n,"name",tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ + Setattr(n, "name", tmpValue); /* for wrapping of enums in a namespace when emit_action is used */ constantWrapper(n); } else { memberconstantHandler(n); } - + Delete(tmpValue); Swig_restore(n); return SWIG_OK; @@ -1591,7 +1638,7 @@ int Language::enumvalueDeclaration(Node *n) { * ---------------------------------------------------------------------- */ int Language::enumforwardDeclaration(Node *n) { - (void)n; + (void) n; return SWIG_OK; } @@ -1601,28 +1648,28 @@ int Language::enumforwardDeclaration(Node *n) { int Language::memberconstantHandler(Node *n) { - Swig_require("memberconstantHandler",n,"*name","*sym:name","value",NIL); + Swig_require("memberconstantHandler", n, "*name", "*sym:name", "value", NIL); - if (!GetFlag(n,"feature:allowexcept")) { - UnsetFlag(n,"feature:except"); - } - if (Getattr(n,"feature:exceptvar")) { - Setattr(n,"feature:except",Getattr(n,"feature:exceptvar")); + if (!GetFlag(n, "feature:allowexcept")) { + UnsetFlag(n, "feature:except"); + } + if (Getattr(n, "feature:exceptvar")) { + Setattr(n, "feature:except", Getattr(n, "feature:exceptvar")); } - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - String *value = Getattr(n,"value"); + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + String *value = Getattr(n, "value"); String *mrename = Swig_name_member(ClassPrefix, symname); - Setattr(n,"sym:name", mrename); + Setattr(n, "sym:name", mrename); String *new_name = 0; if (Extend) new_name = Copy(value); else new_name = NewStringf("%s::%s", ClassName, name); - Setattr(n,"name", new_name); + Setattr(n, "name", new_name); constantWrapper(n); Delete(mrename); @@ -1640,13 +1687,13 @@ int Language::typedefHandler(Node *n) { typedef pointer, if already it is not a pointer or reference, as in - typedef void NT; - int func(NT *p); - + typedef void NT; + int func(NT *p); + see director_basic.i for example. - */ - SwigType *name = Getattr(n,"name"); - SwigType *decl = Getattr(n,"decl"); + */ + SwigType *name = Getattr(n, "name"); + SwigType *decl = Getattr(n, "decl"); if (!SwigType_ispointer(decl) && !SwigType_isreference(decl)) { SwigType *pname = Copy(name); SwigType_add_pointer(pname); @@ -1660,10 +1707,10 @@ int Language::typedefHandler(Node *n) { * Language::classDirectorMethod() * ---------------------------------------------------------------------- */ -int Language::classDirectorMethod(Node *n, Node *parent, String* super) { - (void)n; - (void)parent; - (void)super; +int Language::classDirectorMethod(Node *n, Node *parent, String *super) { + (void) n; + (void) parent; + (void) super; return SWIG_OK; } @@ -1672,7 +1719,7 @@ int Language::classDirectorMethod(Node *n, Node *parent, String* super) { * ---------------------------------------------------------------------- */ int Language::classDirectorConstructor(Node *n) { - (void)n; + (void) n; return SWIG_OK; } @@ -1681,25 +1728,22 @@ int Language::classDirectorConstructor(Node *n) { * ---------------------------------------------------------------------- */ int Language::classDirectorDefaultConstructor(Node *n) { - (void)n; + (void) n; return SWIG_OK; } - - -static -String *vtable_method_id(Node *n) -{ +static String *vtable_method_id(Node *n) { String *nodeType = Getattr(n, "nodeType"); int is_destructor = (Cmp(nodeType, "destructor") == 0); - if (is_destructor) return 0; + if (is_destructor) + return 0; String *name = Getattr(n, "name"); String *decl = Getattr(n, "decl"); String *local_decl = SwigType_typedef_resolve_all(decl); String *tmp = SwigType_pop_function(local_decl); Delete(local_decl); local_decl = tmp; - Node *method_id = NewStringf("%s|%s", name, local_decl); + Node *method_id = NewStringf("%s|%s", name, local_decl); Delete(local_decl); return method_id; } @@ -1708,23 +1752,19 @@ String *vtable_method_id(Node *n) /* ---------------------------------------------------------------------- * Language::unrollVirtualMethods() * ---------------------------------------------------------------------- */ -int Language::unrollVirtualMethods(Node *n, - Node *parent, - List *vm, - int default_director, - int &virtual_destructor, - int protectedbase) { +int Language::unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase) { Node *ni; String *nodeType; String *classname; String *decl; bool first_base = false; // recurse through all base classes to build the vtable - List* bl = Getattr(n, "bases"); + List *bl = Getattr(n, "bases"); if (bl) { Iterator bi; for (bi = First(bl); bi.item; bi = Next(bi)) { - if (first_base && !director_multiple_inheritance) break; + if (first_base && !director_multiple_inheritance) + break; unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor); first_base = true; } @@ -1734,7 +1774,8 @@ int Language::unrollVirtualMethods(Node *n, if (bl) { Iterator bi; for (bi = First(bl); bi.item; bi = Next(bi)) { - if (first_base && !director_multiple_inheritance) break; + if (first_base && !director_multiple_inheritance) + break; unrollVirtualMethods(bi.item, parent, vm, default_director, virtual_destructor, 1); first_base = true; } @@ -1743,22 +1784,23 @@ int Language::unrollVirtualMethods(Node *n, classname = Getattr(n, "name"); for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) { /* we only need to check the virtual members */ - if (!checkAttribute(ni, "storage", "virtual")) continue; + if (!checkAttribute(ni, "storage", "virtual")) + continue; nodeType = Getattr(ni, "nodeType"); /* we need to add methods(cdecl) and destructor (to check for throw decl) */ int is_destructor = (Cmp(nodeType, "destructor") == 0); - if ((Cmp(nodeType, "cdecl") == 0)|| is_destructor) { + if ((Cmp(nodeType, "cdecl") == 0) || is_destructor) { decl = Getattr(ni, "decl"); /* extra check for function type and proper access */ if (SwigType_isfunction(decl) && (((!protectedbase || dirprot_mode()) && is_public(ni)) || need_nonpublic_member(ni))) { String *name = Getattr(ni, "name"); - Node *method_id = is_destructor ? NewStringf("~destructor") : vtable_method_id(ni); + Node *method_id = is_destructor ? NewStringf("~destructor") : vtable_method_id(ni); /* Make sure that the new method overwrites the existing: */ int len = Len(vm); const int DO_NOT_REPLACE = -1; int replace = DO_NOT_REPLACE; - for (int i=0; i(arg1);\n", - "if (director) director->swig_disown();\n", - "}\n", - NULL); + Printv(action, "{\n", "Swig::Director *director = dynamic_cast(arg1);\n", "if (director) director->swig_disown();\n", "}\n", NULL); Setattr(disown, "wrap:action", action); - Setattr(disown,"name", mrename); - Setattr(disown,"sym:name", mrename); - Setattr(disown,"type",type); - Setattr(disown,"parms", p); + Setattr(disown, "name", mrename); + Setattr(disown, "sym:name", mrename); + Setattr(disown, "type", type); + Setattr(disown, "parms", p); Delete(action); Delete(mrename); Delete(type); Delete(p); - + functionWrapper(disown); Delete(disown); return SWIG_OK; @@ -1887,20 +1926,20 @@ int Language::classDirectorConstructors(Node *n) { Node *ni; String *nodeType; Node *parent = Swig_methodclass(n); - int default_ctor = Getattr(parent,"allocate:default_constructor") ? 1 : 0; + int default_ctor = Getattr(parent, "allocate:default_constructor") ? 1 : 0; int protected_ctor = 0; int constructor = 0; /* emit constructors */ for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) { nodeType = Getattr(ni, "nodeType"); - if (Cmp(nodeType, "constructor") == 0) { - Parm *parms = Getattr(ni,"parms"); + if (Cmp(nodeType, "constructor") == 0) { + Parm *parms = Getattr(ni, "parms"); if (is_public(ni)) { /* emit public constructor */ - classDirectorConstructor(ni); - constructor = 1; - if (default_ctor) + classDirectorConstructor(ni); + constructor = 1; + if (default_ctor) default_ctor = !ParmList_numrequired(parms); } else { /* emit protected constructor if needed */ @@ -1908,7 +1947,7 @@ int Language::classDirectorConstructors(Node *n) { classDirectorConstructor(ni); constructor = 1; protected_ctor = 1; - if (default_ctor) + if (default_ctor) default_ctor = !ParmList_numrequired(parms); } } @@ -1918,11 +1957,9 @@ int Language::classDirectorConstructors(Node *n) { if (!constructor) { if (!default_ctor) { /* we get here because the class has no public, protected or - default constructor, therefore, the director class can't be - created, ie, is kind of abstract. */ - Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT,Getfile(n),Getline(n), - "Director class '%s' can't be constructed\n", - SwigType_namestr(Getattr(n,"name"))); + default constructor, therefore, the director class can't be + created, ie, is kind of abstract. */ + Swig_warning(WARN_LANG_DIRECTOR_ABSTRACT, Getfile(n), Getline(n), "Director class '%s' can't be constructed\n", SwigType_namestr(Getattr(n, "name"))); return SWIG_OK; } classDirectorDefaultConstructor(n); @@ -1937,9 +1974,9 @@ int Language::classDirectorConstructors(Node *n) { (mmatus) This is very strange, since swig compiled with gcc3.2.3 doesn't need it here.... - */ + */ if (!default_ctor && !protected_ctor) { - if (Getattr(parent,"allocate:default_base_constructor")) { + if (Getattr(parent, "allocate:default_base_constructor")) { classDirectorDefaultConstructor(n); } } @@ -1955,15 +1992,15 @@ int Language::classDirectorMethods(Node *n) { Node *vtable = Getattr(n, "vtable"); int len = Len(vtable); - for (int i=0; i 0) { if (!virtual_destructor) { String *classtype = Getattr(n, "classtype"); - Swig_warning(WARN_LANG_DIRECTOR_VDESTRUCT, input_file, line_number, - "Director base class %s has no virtual destructor.\n", - classtype); + Swig_warning(WARN_LANG_DIRECTOR_VDESTRUCT, input_file, line_number, "Director base class %s has no virtual destructor.\n", classtype); } Setattr(n, "vtable", vtable); @@ -2057,34 +2092,34 @@ int Language::classDirector(Node *n) { /* ---------------------------------------------------------------------- * Language::classDeclaration() * ---------------------------------------------------------------------- */ -static void addCopyConstructor(Node *n) -{ - Node *cn = NewHash(); - set_nodeType(cn,"constructor"); - Setattr(cn,"access","public"); - Setfile(cn,Getfile(n)); - Setline(cn,Getline(n)); - String *cname = Getattr(n,"name"); +static void addCopyConstructor(Node *n) { + Node *cn = NewHash(); + set_nodeType(cn, "constructor"); + Setattr(cn, "access", "public"); + Setfile(cn, Getfile(n)); + Setline(cn, Getline(n)); + + String *cname = Getattr(n, "name"); SwigType *type = Copy(cname); String *last = Swig_scopename_last(cname); - String *name = NewStringf("%s::%s",cname,last); + String *name = NewStringf("%s::%s", cname, last); String *cc = NewStringf("r.q(const).%s", type); - String *decl = NewStringf("f(%s).",cc); - String *csymname = Getattr(n,"sym:name"); + String *decl = NewStringf("f(%s).", cc); + String *csymname = Getattr(n, "sym:name"); String *oldname = csymname; - if (Getattr(n,"allocate:has_constructor")) { + if (Getattr(n, "allocate:has_constructor")) { // to work properly with '%rename Class', we must look // for any other constructor in the class, which has not been // renamed, and use its name as oldname. Node *c; for (c = firstChild(n); c; c = nextSibling(c)) { const char *tag = Char(nodeType(c)); - if (strcmp(tag,"constructor") == 0) { - String *cname = Getattr(c,k_name); - String *csname = Getattr(c,k_symname); - String *clast = Swig_scopename_last(cname); + if (strcmp(tag, "constructor") == 0) { + String *cname = Getattr(c, k_name); + String *csname = Getattr(c, k_symname); + String *clast = Swig_scopename_last(cname); if (Equal(csname, clast)) { oldname = csname; break; @@ -2097,30 +2132,30 @@ static void addCopyConstructor(Node *n) if (!symname) { symname = Copy(csymname); } - Parm *p = NewParm(cc,"other"); + Parm *p = NewParm(cc, "other"); - Setattr(cn,"name",name); - Setattr(cn,"sym:name",symname); - SetFlag(cn,"feature:new"); - Setattr(cn,"decl",decl); - Setattr(cn,"parentNode",n); - Setattr(cn,"parms",p); - Setattr(cn,"copy_constructor","1"); + Setattr(cn, "name", name); + Setattr(cn, "sym:name", symname); + SetFlag(cn, "feature:new"); + Setattr(cn, "decl", decl); + Setattr(cn, "parentNode", n); + Setattr(cn, "parms", p); + Setattr(cn, "copy_constructor", "1"); - Symtab *oldscope = Swig_symbol_setscope(Getattr(n,"symtab")); + Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *on = Swig_symbol_add(symname, cn); Swig_symbol_setscope(oldscope); Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { Node *access = NewHash(); - set_nodeType(access,"access"); - Setattr(access,"kind","public"); - appendChild(n,access); - appendChild(n,cn); - Setattr(n,"has_copy_constructor","1"); - Setattr(n,"copy_constructor_decl",decl); - Setattr(n,"allocate:copy_constructor","1"); + set_nodeType(access, "access"); + Setattr(access, "kind", "public"); + appendChild(n, access); + appendChild(n, cn); + Setattr(n, "has_copy_constructor", "1"); + Setattr(n, "copy_constructor_decl", decl); + Setattr(n, "allocate:copy_constructor", "1"); Delete(access); } Delete(cn); @@ -2130,45 +2165,44 @@ static void addCopyConstructor(Node *n) Delete(symname); } -static void addDefaultConstructor(Node *n) -{ +static void addDefaultConstructor(Node *n) { Node *cn = NewHash(); - set_nodeType(cn,"constructor"); - Setattr(cn,"access","public"); - Setfile(cn,Getfile(n)); - Setline(cn,Getline(n)); + set_nodeType(cn, "constructor"); + Setattr(cn, "access", "public"); + Setfile(cn, Getfile(n)); + Setline(cn, Getline(n)); - String *cname = Getattr(n,"name"); + String *cname = Getattr(n, "name"); String *last = Swig_scopename_last(cname); - String *name = NewStringf("%s::%s",cname,last); + String *name = NewStringf("%s::%s", cname, last); String *decl = NewString("f()."); - String *csymname = Getattr(n,"sym:name"); + String *csymname = Getattr(n, "sym:name"); String *oldname = csymname; String *symname = Swig_name_make(cn, cname, last, decl, oldname); if (!symname) { symname = Copy(csymname); } - - Setattr(cn,"name",name); - Setattr(cn,"sym:name",symname); - SetFlag(cn,"feature:new"); - Setattr(cn,"decl",decl); - Setattr(cn,"parentNode",n); - Setattr(cn,"default_constructor","1"); - Symtab *oldscope = Swig_symbol_setscope(Getattr(n,"symtab")); + Setattr(cn, "name", name); + Setattr(cn, "sym:name", symname); + SetFlag(cn, "feature:new"); + Setattr(cn, "decl", decl); + Setattr(cn, "parentNode", n); + Setattr(cn, "default_constructor", "1"); + + Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *on = Swig_symbol_add(symname, cn); Swig_symbol_setscope(oldscope); Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { Node *access = NewHash(); - set_nodeType(access,"access"); - Setattr(access,"kind","public"); - appendChild(n,access); - appendChild(n,cn); - Setattr(n,"has_default_constructor","1"); - Setattr(n,"allocate:default_constructor","1"); + set_nodeType(access, "access"); + Setattr(access, "kind", "public"); + appendChild(n, access); + appendChild(n, cn); + Setattr(n, "has_default_constructor", "1"); + Setattr(n, "allocate:default_constructor", "1"); Delete(access); } Delete(cn); @@ -2178,42 +2212,41 @@ static void addDefaultConstructor(Node *n) Delete(symname); } -static void addDestructor(Node *n) -{ +static void addDestructor(Node *n) { Node *cn = NewHash(); - set_nodeType(cn,"destructor"); - Setattr(cn,"access","public"); - Setfile(cn,Getfile(n)); - Setline(cn,Getline(n)); + set_nodeType(cn, "destructor"); + Setattr(cn, "access", "public"); + Setfile(cn, Getfile(n)); + Setline(cn, Getline(n)); - String *cname = Getattr(n,"name"); + String *cname = Getattr(n, "name"); String *last = Swig_scopename_last(cname); - Insert(last,0,"~"); - String *name = NewStringf("%s::%s",cname,last); + Insert(last, 0, "~"); + String *name = NewStringf("%s::%s", cname, last); String *decl = NewString("f()."); String *symname = Swig_name_make(cn, cname, last, decl, 0); if (!symname) { - symname = NewStringf("~%s",Getattr(n,"sym:name")); + symname = NewStringf("~%s", Getattr(n, "sym:name")); } - Setattr(cn,"name",name); - Setattr(cn,"sym:name",symname); - Setattr(cn,"decl","f()."); - Setattr(cn,"parentNode",n); + Setattr(cn, "name", name); + Setattr(cn, "sym:name", symname); + Setattr(cn, "decl", "f()."); + Setattr(cn, "parentNode", n); - Symtab *oldscope = Swig_symbol_setscope(Getattr(n,"symtab")); + Symtab *oldscope = Swig_symbol_setscope(Getattr(n, "symtab")); Node *on = Swig_symbol_add(symname, cn); Swig_symbol_setscope(oldscope); Swig_features_get(Swig_cparse_features(), 0, name, decl, cn); if (on == cn) { Node *access = NewHash(); - set_nodeType(access,"access"); - Setattr(access,"kind","public"); - appendChild(n,access); - appendChild(n,cn); - Setattr(n,"has_destructor","1"); - Setattr(n,"allocate:destructor","1"); + set_nodeType(access, "access"); + Setattr(access, "kind", "public"); + appendChild(n, access); + appendChild(n, cn); + Setattr(n, "has_destructor", "1"); + Setattr(n, "allocate:destructor", "1"); Delete(access); } Delete(cn); @@ -2224,23 +2257,23 @@ static void addDestructor(Node *n) } int Language::classDeclaration(Node *n) { - String *ochildren = Getattr(n,"feature:onlychildren"); + String *ochildren = Getattr(n, "feature:onlychildren"); if (ochildren) { - Setattr(n,"feature:emitonlychildren",ochildren); + Setattr(n, "feature:emitonlychildren", ochildren); emit_children(n); - Delattr(n,"feature:emitonlychildren"); - SetFlag(n,"feature:ignore"); + Delattr(n, "feature:emitonlychildren"); + SetFlag(n, "feature:ignore"); return SWIG_NOWRAP; } - String *kind = Getattr(n,"kind"); - String *name = Getattr(n,"name"); - String *tdname = Getattr(n,"tdname"); - String *symname = Getattr(n,"sym:name"); + String *kind = Getattr(n, "kind"); + String *name = Getattr(n, "name"); + String *tdname = Getattr(n, "tdname"); + String *symname = Getattr(n, "sym:name"); char *classname = tdname ? Char(tdname) : Char(name); char *iname = Char(symname); - int strip = (tdname || CPlusPlus) ? 1 : 0; + int strip = (tdname || CPlusPlus) ? 1 : 0; if (!classname) { @@ -2252,15 +2285,14 @@ int Language::classDeclaration(Node *n) { /* Printf(stdout,"sym:name = %s\n", symname); */ if (!validIdentifier(symname)) { - Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", - SwigType_namestr(symname)); + Swig_warning(WARN_LANG_IDENTIFIER, input_file, line_number, "Can't wrap class %s unless renamed to a valid identifier.\n", SwigType_namestr(symname)); return SWIG_NOWRAP; } - Swig_save("classDeclaration",n,"name",NIL); - Setattr(n,"name",classname); + Swig_save("classDeclaration", n, "name", NIL); + Setattr(n, "name", classname); - if (Cmp(kind,"class") == 0) { + if (Cmp(kind, "class") == 0) { cplus_mode = PRIVATE; } else { cplus_mode = PUBLIC; @@ -2273,8 +2305,8 @@ int Language::classDeclaration(Node *n) { } else { ClassType = NewStringf("%s %s", kind, classname); } - Setattr(n,"classtypeobj", Copy(ClassType)); - Setattr(n,"classtype", SwigType_namestr(ClassType)); + Setattr(n, "classtypeobj", Copy(ClassType)); + Setattr(n, "classtype", SwigType_namestr(ClassType)); InClass = 1; CurrentClass = n; @@ -2289,28 +2321,28 @@ int Language::classDeclaration(Node *n) { /* 'nodirector' has precedence over 'director' */ dir = (ndir || nndir) ? (ndir && !nndir) : 0; } - int abstract = !dir && abstractClassTest(n); - int odefault = (GenerateDefault && !GetFlag(n,"feature:nodefault")); + int abstract = !dir && abstractClassTest(n); + int odefault = (GenerateDefault && !GetFlag(n, "feature:nodefault")); /* default constructor */ - if (!abstract && !GetFlag(n,"feature:nodefaultctor") && odefault) { - if (!Getattr(n,"has_constructor") && !Getattr(n,"allocate:has_constructor") && (Getattr(n,"allocate:default_constructor"))) { + if (!abstract && !GetFlag(n, "feature:nodefaultctor") && odefault) { + if (!Getattr(n, "has_constructor") && !Getattr(n, "allocate:has_constructor") && (Getattr(n, "allocate:default_constructor"))) { addDefaultConstructor(n); } } /* copy constructor */ - if (CPlusPlus && !abstract && GetFlag(n,"feature:copyctor")) { - if (!Getattr(n,"has_copy_constructor") && !Getattr(n,"allocate:has_copy_constructor") - && (Getattr(n,"allocate:copy_constructor")) - && (!GetFlag(n,"feature:ignore"))) { + if (CPlusPlus && !abstract && GetFlag(n, "feature:copyctor")) { + if (!Getattr(n, "has_copy_constructor") && !Getattr(n, "allocate:has_copy_constructor") + && (Getattr(n, "allocate:copy_constructor")) + && (!GetFlag(n, "feature:ignore"))) { addCopyConstructor(n); } } /* default destructor */ - if (!GetFlag(n,"feature:nodefaultdtor") && odefault) { - if (!Getattr(n,"has_destructor") && (!Getattr(n,"allocate:has_destructor")) - && (Getattr(n,"allocate:default_destructor")) - && (!GetFlag(n,"feature:ignore"))) { + if (!GetFlag(n, "feature:nodefaultdtor") && odefault) { + if (!Getattr(n, "has_destructor") && (!Getattr(n, "allocate:has_destructor")) + && (Getattr(n, "allocate:default_destructor")) + && (!GetFlag(n, "feature:ignore"))) { addDestructor(n); } } @@ -2321,7 +2353,7 @@ int Language::classDeclaration(Node *n) { } /* check for abstract after resolving directors */ Abstract = abstractClassTest(n); - + classHandler(n); } else { Abstract = abstractClassTest(n); @@ -2330,10 +2362,14 @@ int Language::classDeclaration(Node *n) { InClass = 0; CurrentClass = 0; - Delete(ClassType); ClassType = 0; - Delete(ClassPrefix); ClassPrefix = 0; - Delete(ClassName); ClassName = 0; - Delete(DirectorClassName); DirectorClassName = 0; + Delete(ClassType); + ClassType = 0; + Delete(ClassPrefix); + ClassPrefix = 0; + Delete(ClassName); + ClassName = 0; + Delete(DirectorClassName); + DirectorClassName = 0; Swig_restore(n); return SWIG_OK; } @@ -2346,18 +2382,16 @@ int Language::classHandler(Node *n) { bool hasDirector = Swig_directorclass(n) ? true : false; - - /* Emit all of the class members */ emit_children(n); /* Look for smart pointer handling */ - if (Getattr(n,"allocate:smartpointer")) { - List *methods = Getattr(n,"allocate:smartpointer"); + if (Getattr(n, "allocate:smartpointer")) { + List *methods = Getattr(n, "allocate:smartpointer"); cplus_mode = PUBLIC; SmartPointer = CWRAP_SMART_POINTER; Iterator c; - for (c = First(methods); c.item; c= Next(c)) { + for (c = First(methods); c.item; c = Next(c)) { emit_one(c.item); } SmartPointer = 0; @@ -2374,24 +2408,24 @@ int Language::classHandler(Node *n) { * to catch public use of protected methods by the scripting languages. */ if (dirprot_mode() && extraDirectorProtectedCPPMethodsRequired()) { Node *vtable = Getattr(n, "vtable"); - String* symname = Getattr(n, "sym:name"); + String *symname = Getattr(n, "sym:name"); AccessMode old_mode = cplus_mode; cplus_mode = PROTECTED; int len = Len(vtable); - for (int i=0; i\n", it.key); - else if (DohIsSequence(it.item)) - Printf(stdout, " %s = \n", it.key); - else - Printf(stdout, " %s = \n", it.key); - } +void display_mapping(DOH *d) { + if (d == 0 || !DohIsMapping(d)) + return; + for (DohIterator it = DohFirst(d); it.item; it = DohNext(it)) { + if (DohIsString(it.item)) + Printf(stdout, " %s = %s\n", it.key, it.item); + else if (DohIsMapping(it.item)) + Printf(stdout, " %s = \n", it.key); + else if (DohIsSequence(it.item)) + Printf(stdout, " %s = \n", it.key); + else + Printf(stdout, " %s = \n", it.key); + } } - + /* NEW LANGUAGE NOTE:*********************************************** @@ -77,7 +76,7 @@ void display_mapping(DOH* d) you can add new ones here (though for now I have not bothered) NEW LANGUAGE NOTE:END ************************************************/ -static const char *usage = (char*)"\ +static const char *usage = (char *) "\ Lua Options (available with -lua)\n\ (coming soon.)\n\n"; @@ -89,7 +88,7 @@ Lua Options (available with -lua)\n\ (more on this as I figure it out) NEW LANGUAGE NOTE:END ************************************************/ -class LUA : public Language { +class LUA:public Language { private: File *f_runtime; @@ -98,16 +97,16 @@ private: File *f_init; File *f_initbeforefunc; String *PrefixPlusUnderscore; - String *s_cmd_tab; // table of command names - String *s_var_tab; // table of global variables - String *s_const_tab; // table of global constants - String *s_methods_tab; // table of class methods - String *s_attr_tab; // table of class atributes + String *s_cmd_tab; // table of command names + String *s_var_tab; // table of global variables + String *s_const_tab; // table of global constants + String *s_methods_tab; // table of class methods + String *s_attr_tab; // table of class atributes int have_constructor; int have_destructor; - String* destructor_action; - String* class_name; + String *destructor_action; + String *class_name; public: @@ -118,7 +117,7 @@ public: * Initialize member data * --------------------------------------------------------------------- */ - LUA() { + LUA() { f_runtime = 0; f_header = 0; f_wrappers = 0; @@ -126,22 +125,23 @@ public: f_initbeforefunc = 0; PrefixPlusUnderscore = 0; - s_cmd_tab=s_var_tab=s_const_tab=0; + s_cmd_tab = s_var_tab = s_const_tab = 0; } -/* NEW LANGUAGE NOTE:*********************************************** - This is called to initalise the system & read any command line args - most of this is boilerplate code, except the command line args - which depends upon what args your code supports -NEW LANGUAGE NOTE:END ************************************************/ - /* --------------------------------------------------------------------- + /* NEW LANGUAGE NOTE:*********************************************** + This is called to initalise the system & read any command line args + most of this is boilerplate code, except the command line args + which depends upon what args your code supports + NEW LANGUAGE NOTE:END ************************************************/ + + /* --------------------------------------------------------------------- * main() * * Parse command line options and initializes variables. * --------------------------------------------------------------------- */ - - virtual void main(int argc, char *argv[]) { + + virtual void main(int argc, char *argv[]) { /* Set location of SWIG library */ SWIG_library_directory("lua"); @@ -149,9 +149,9 @@ NEW LANGUAGE NOTE:END ************************************************/ /* Look for certain command line options */ for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp (argv[i], "-help") == 0) { // usage flags - fputs(usage,stderr); - } + if (strcmp(argv[i], "-help") == 0) { // usage flags + fputs(usage, stderr); + } } } @@ -224,10 +224,10 @@ NEW LANGUAGE NOTE:END ************************************************/ just before it is written to file NEW LANGUAGE NOTE:END ************************************************/ // Initialize some variables for the object interface - s_cmd_tab = NewString(""); - s_var_tab = NewString(""); + s_cmd_tab = NewString(""); + s_var_tab = NewString(""); // s_methods_tab = NewString(""); - s_const_tab = NewString(""); + s_const_tab = NewString(""); /* Standard stuff for the SWIG runtime section */ Swig_banner(f_runtime); @@ -235,34 +235,34 @@ NEW LANGUAGE NOTE:END ************************************************/ // Printf(f_runtime, "#define SWIG_NOINCLUDE\n"); // } - String *init_name = NewStringf("%(title)s_Init",module); + String *init_name = NewStringf("%(title)s_Init", module); Printf(f_header, "#define SWIG_init %s\n", init_name); Printf(f_header, "#define SWIG_name \"%s\"\n", module); /* SWIG_import is a special function name for importing within Lua5.1 */ Printf(f_header, "#define SWIG_import luaopen_%s\n\n", module); - Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n"); - Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n"); + Printf(s_cmd_tab, "\nstatic const struct luaL_reg swig_commands[] = {\n"); + Printf(s_var_tab, "\nstatic swig_lua_var_info swig_variables[] = {\n"); Printf(s_const_tab, "\nstatic swig_lua_const_info swig_constants[] = {\n"); - Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); /* Change naming scheme for constructors and destructors */ // Swig_name_register("construct","%c_create"); // Swig_name_register("destroy","%c_destroy"); /* %init code inclusion, effectively in the SWIG_init function */ - Printf(f_init,"#ifdef __cplusplus\nextern \"C\"\n#endif\n"); + Printf(f_init, "#ifdef __cplusplus\nextern \"C\"\n#endif\n"); Printf(f_init, "void SWIG_init_user(lua_State* L)\n{\n"); Language::top(n); - Printf(f_init, "}\n" ); + Printf(f_init, "}\n"); - Printf(f_wrappers,"#ifdef __cplusplus\n}\n#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); // Done. Close up the module & write to the wrappers - Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n",NIL); - Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n",NIL); + Printv(s_cmd_tab, tab4, "{0,0}\n", "};\n", NIL); + Printv(s_var_tab, tab4, "{0,0,0}\n", "};\n", NIL); Printv(s_const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL); - Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab,NIL); + Printv(f_wrappers, s_cmd_tab, s_var_tab, s_const_tab, NIL); SwigType_emit_type_table(f_runtime, f_wrappers); // @@ -317,21 +317,22 @@ NEW LANGUAGE NOTE:END ************************************************/ virtual int functionWrapper(Node *n) { // REPORT("functionWrapper",n); - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); Parm *p; String *tm; int i; -// int returnval=0; // number of arguments returned +// int returnval=0; // number of arguments returned String *overname = 0; - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } /* NEW LANGUAGE NOTE:*********************************************** @@ -339,12 +340,12 @@ NEW LANGUAGE NOTE:END ************************************************/ we need to add a couple of local variables NEW LANGUAGE NOTE:END ************************************************/ Wrapper *f = NewWrapper(); - Wrapper_add_local(f,"SWIG_arg", "int SWIG_arg = -1"); + Wrapper_add_local(f, "SWIG_arg", "int SWIG_arg = -1"); String *wname = Swig_name_wrapper(iname); if (overname) { - Append(wname,overname); + Append(wname, overname); } /* NEW LANGUAGE NOTE:*********************************************** @@ -352,9 +353,7 @@ NEW LANGUAGE NOTE:END ************************************************/ static int wrap_XXX(lua_State* L){...} this line adds this into the wrappering code NEW LANGUAGE NOTE:END ************************************************/ - Printv(f->def, - "static int ", wname, "(lua_State* L) {", - NIL); + Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL); /* NEW LANGUAGE NOTE:*********************************************** this prints the list of args, eg for a C fn @@ -368,12 +367,12 @@ NEW LANGUAGE NOTE:END ************************************************/ emit_args(d, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ int num_arguments = emit_num_arguments(l); - int num_required = emit_num_required(l); + int num_required = emit_num_required(l); int varargs = emit_isvarargs(l); /* Which input argument to start with? */ @@ -398,25 +397,25 @@ NEW LANGUAGE NOTE:END ************************************************/ NEW LANGUAGE NOTE:END ************************************************/ String *argument_check = NewString(""); String *argument_parse = NewString(""); - String *checkfn=NULL; + String *checkfn = NULL; // String *numoutputs=NULL; char source[64]; for (i = 0, p = l; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); - /* Look for an input typemap */ - sprintf(source, "%d", i+1); - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm, "$source", source); - Replaceall(tm, "$target", ln); - Replaceall(tm, "$input", source); - Setattr(p, "emit:input", source); + /* Look for an input typemap */ + sprintf(source, "%d", i + 1); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); /* NEW LANGUAGE NOTE:*********************************************** look for a 'checkfn' typemap @@ -425,61 +424,55 @@ NEW LANGUAGE NOTE:END ************************************************/ this will result in code either in the argument_check or argument_parse string NEW LANGUAGE NOTE:END ************************************************/ - if ((checkfn=Getattr(p,"tmap:in:checkfn"))){ - if (i=%s && !%s(L,%s))",source,checkfn,source); - } - Printf(argument_check," SWIG_fail_arg(%s);\n",source); - } + if ((checkfn = Getattr(p, "tmap:in:checkfn"))) { + if (i < num_required) { + Printf(argument_check, "if(!%s(L,%s))", checkfn, source); + } else { + Printf(argument_check, "if(lua_gettop(L)>=%s && !%s(L,%s))", source, checkfn, source); + } + Printf(argument_check, " SWIG_fail_arg(%s);\n", source); + } /* NEW LANGUAGE NOTE:*********************************************** lua states the number of arguments passed to a function using the fn lua_gettop() we can use this to deal with default arguments NEW LANGUAGE NOTE:END ************************************************/ - if (i=%s){%s}\n",source,tm); - } - p = Getattr(p,"tmap:in:next"); - continue; - } else { + if (i < num_required) { + Printf(argument_parse, "%s\n", tm); + } else { + Printf(argument_parse, "if(lua_gettop(L)>=%s){%s}\n", source, tm); + } + p = Getattr(p, "tmap:in:next"); + continue; + } else { /* NEW LANGUAGE NOTE:*********************************************** // why is this code not called when I dont have a typemap? // instead of giving a warning, no code is generated NEW LANGUAGE NOTE:END ************************************************/ - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); - break; - } + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); + break; + } p = nextSibling(p); } // add all argcheck code - Printv(f->code,argument_check,argument_parse,NIL); + Printv(f->code, argument_check, argument_parse, NIL); /* Check for trailing varargs */ if (varargs) { - if (p && (tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$input", "varargs"); - Printv(f->code,tm,"\n",NIL); + if (p && (tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$input", "varargs"); + Printv(f->code, tm, "\n", NIL); } } /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } @@ -488,10 +481,10 @@ NEW LANGUAGE NOTE:END ************************************************/ /* Insert cleanup code */ String *cleanup = NewString(""); for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -500,109 +493,108 @@ NEW LANGUAGE NOTE:END ************************************************/ /* Insert argument output code */ String *outarg = NewString(""); for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { -// // managing the number of returning variables + if ((tm = Getattr(p, "tmap:argout"))) { +// // managing the number of returning variables // if (numoutputs=Getattr(p,"tmap:argout:numoutputs")){ -// int i=GetInt(p,"tmap:argout:numoutputs"); -// printf("got argout:numoutputs of %d\n",i); -// returnval+=GetInt(p,"tmap:argout:numoutputs"); +// int i=GetInt(p,"tmap:argout:numoutputs"); +// printf("got argout:numoutputs of %d\n",i); +// returnval+=GetInt(p,"tmap:argout:numoutputs"); // } // else returnval++; - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","result"); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "result"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Emit the function call */ - emit_action(n,f); + emit_action(n, f); /* NEW LANGUAGE NOTE:*********************************************** FIXME: returns 1 if there is a void return type this is because there is a typemap for void NEW LANGUAGE NOTE:END ************************************************/ - Printv(f->code,"SWIG_arg=0;\n",NIL); + Printv(f->code, "SWIG_arg=0;\n", NIL); // Return value if necessary - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { // managing the number of returning variables // if (numoutputs=Getattr(tm,"numoutputs")){ -// int i=GetInt(tm,"numoutputs"); -// printf("return numoutputs %d\n",i); -// returnval+=GetInt(tm,"numoutputs"); +// int i=GetInt(tm,"numoutputs"); +// printf("return numoutputs %d\n",i); +// returnval+=GetInt(tm,"numoutputs"); // } // else returnval++; - Replaceall(tm,"$source", "result"); - if (GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","1"); - } else { - Replaceall(tm,"$owner","0"); - } - Printf(f->code,"%s\n", tm); + Replaceall(tm, "$source", "result"); + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "1"); + } else { + Replaceall(tm, "$owner", "0"); + } + Printf(f->code, "%s\n", tm); // returnval++; } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(d,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } /* Output argument output code */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } /* Close the function */ - Printv(f->code, "return SWIG_arg;\n",NIL); + Printv(f->code, "return SWIG_arg;\n", NIL); // add the failure cleanup code: - Printv(f->code, "\nfail:\n",NIL); - Printv(f->code, "$cleanup","lua_error(L);\n",NIL); - Printv(f->code, "return SWIG_arg;\n",NIL); + Printv(f->code, "\nfail:\n", NIL); + Printv(f->code, "$cleanup", "lua_error(L);\n", NIL); + Printv(f->code, "return SWIG_arg;\n", NIL); Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); - Replaceall(f->code,"$result","result"); + Replaceall(f->code, "$symname", iname); + Replaceall(f->code, "$result", "result"); /* Dump the function out */ - Wrapper_print(f,f_wrappers); + Wrapper_print(f, f_wrappers); - Setattr(n,"wrap:name", wname); // you need this to make the overloading work + Setattr(n, "wrap:name", wname); // you need this to make the overloading work /* NEW LANGUAGE NOTE:*********************************************** register the function in SWIG different language mappings seem to use different ideas NEW LANGUAGE NOTE:END ************************************************/ /* Now register the function with the interpreter. */ - if (!Getattr(n,"sym:overloaded")) { + if (!Getattr(n, "sym:overloaded")) { // add_method(n, iname, wname, description); Printv(s_cmd_tab, tab4, "{ \"", iname, "\", ", Swig_name_wrapper(iname), "},\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), "},\n", NIL); } else { // Setattr(n,"wrap:name", wname); - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { dispatchFunction(n); } } @@ -636,37 +628,34 @@ NEW LANGUAGE NOTE:END ************************************************/ int maxargs; String *tmp = NewString(""); - String *dispatch = Swig_overload_dispatch(n,"return %s(L);",&maxargs); + String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs); /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *f = NewWrapper(); - String *symname = Getattr(n,"sym:name"); - String *wname = Swig_name_wrapper(symname); + Wrapper *f = NewWrapper(); + String *symname = Getattr(n, "sym:name"); + String *wname = Swig_name_wrapper(symname); //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); - Printv(f->def, - "static int ", wname, "(lua_State* L) {", - NIL); - Wrapper_add_local(f,"argc","int argc"); - Printf(tmp,"int argv[%d]={1", maxargs+1); - for(int i=1;i<=maxargs;i++) - { - Printf(tmp,",%d",i+1); - } - Printf(tmp,"}"); - Wrapper_add_local(f,"argv",tmp); - Printf(f->code,"argc = lua_gettop(L);\n"); + Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL); + Wrapper_add_local(f, "argc", "int argc"); + Printf(tmp, "int argv[%d]={1", maxargs + 1); + for (int i = 1; i <= maxargs; i++) { + Printf(tmp, ",%d", i + 1); + } + Printf(tmp, "}"); + Wrapper_add_local(f, "argv", tmp); + Printf(f->code, "argc = lua_gettop(L);\n"); - Replaceall(dispatch,"$args","self,args"); - Printv(f->code,dispatch,"\n",NIL); - Printf(f->code,"lua_pushstring(L,\"No matching function for overloaded '%s'\");\n", symname); - Printf(f->code,"lua_error(L);return 0;\n"); - Printv(f->code,"}\n",NIL); - Wrapper_print(f,f_wrappers); + Replaceall(dispatch, "$args", "self,args"); + Printv(f->code, dispatch, "\n", NIL); + Printf(f->code, "lua_pushstring(L,\"No matching function for overloaded '%s'\");\n", symname); + Printf(f->code, "lua_error(L);return 0;\n"); + Printv(f->code, "}\n", NIL); + Wrapper_print(f, f_wrappers); //add_method(symname,wname,0); - Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); + Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wname, "},\n", NIL); DelWrapper(f); Delete(dispatch); @@ -687,68 +676,68 @@ so we will just add these into the variable lists ideally we should not have registered these as functions, only WRT this variable will look into this later. NEW LANGUAGE NOTE:END ************************************************/ - REPORT("variableWrapper",n); - String *iname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); + REPORT("variableWrapper", n); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); // let SWIG generate the wrappers - int result=Language::variableWrapper(n); + int result = Language::variableWrapper(n); // normally SWIG will generate 2 wrappers, a get and a set // but in certain scenarios (immutable, or if its arrays), it will not - String *getName=Swig_name_wrapper(Swig_name_get(iname)); - String *setName=0; - if (is_assignable(n)==false || SwigType_isarray(type)) { - // TODO: how about calling a 'this is not settable' error message? - setName=NewString("0"); + String *getName = Swig_name_wrapper(Swig_name_get(iname)); + String *setName = 0; + if (is_assignable(n) == false || SwigType_isarray(type)) { + // TODO: how about calling a 'this is not settable' error message? + setName = NewString("0"); } else { - setName=Swig_name_wrapper(Swig_name_set(iname)); + setName = Swig_name_wrapper(Swig_name_set(iname)); } // register the variable - Printf(s_var_tab,"%s{ \"%s\", %s, %s },\n",tab4,iname,getName,setName); + Printf(s_var_tab, "%s{ \"%s\", %s, %s },\n", tab4, iname, getName, setName); Delete(getName); Delete(setName); - return result; + return result; } /* ------------------------------------------------------------ * constantWrapper() * ------------------------------------------------------------ */ -virtual int constantWrapper(Node *n) { - REPORT("constantWrapper",n); - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); + virtual int constantWrapper(Node *n) { + REPORT("constantWrapper", n); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); //String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s",ns_name,iname); - String *nsname = Copy(iname); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); + String *nsname = Copy(iname); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; //if (nspace) Setattr(n,"sym:name",nsname); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(iname); - Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type,wname), value); + Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } - - if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) { - Replaceall(tm,"$source",value); - Replaceall(tm,"$target",name); - Replaceall(tm,"$value",value); - Replaceall(tm,"$nsname",nsname); - Printf(s_const_tab,"%s,\n", tm); + + if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); + Printf(s_const_tab, "%s,\n", tm); } else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) { - Replaceall(tm,"$source", value); - Replaceall(tm,"$target", name); - Replaceall(tm,"$value",value); - Replaceall(tm,"$nsname",nsname); + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); Printf(f_init, "%s\n", tm); } else { Delete(nsname); - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, - input_file, line_number, "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } Delete(nsname); @@ -760,10 +749,11 @@ virtual int constantWrapper(Node *n) { * ------------------------------------------------------------ */ virtual int nativeWrapper(Node *n) { - REPORT("nativeWrapper",n); - String *symname = Getattr(n,"sym:name"); - String *wrapname = Getattr(n,"wrap:name"); - if (!addSymbol(wrapname,n)) return SWIG_ERROR; + REPORT("nativeWrapper", n); + String *symname = Getattr(n, "sym:name"); + String *wrapname = Getattr(n, "wrap:name"); + if (!addSymbol(wrapname, n)) + return SWIG_ERROR; Printv(s_cmd_tab, tab4, "{ \"", symname, "\",", wrapname, "},\n", NIL); // return Language::nativeWrapper(n); // this does nothing... @@ -798,20 +788,21 @@ virtual int constantWrapper(Node *n) { * classHandler() * ------------------------------------------------------------ */ - virtual int classHandler(Node *n) { - REPORT("classHandler",n); + virtual int classHandler(Node *n) { + REPORT("classHandler", n); - String *mangled_classname = 0; - String *real_classname = 0; + String *mangled_classname = 0; + String *real_classname = 0; have_constructor = 0; have_destructor = 0; destructor_action = 0; - class_name = Getattr(n,"sym:name"); - if (!addSymbol(class_name,n)) return SWIG_ERROR; + class_name = Getattr(n, "sym:name"); + if (!addSymbol(class_name, n)) + return SWIG_ERROR; - real_classname = Getattr(n,"name"); + real_classname = Getattr(n, "name"); mangled_classname = Swig_name_mangle(real_classname); // note: tcl has a static hashtable of all classes emitted, I wonder why? @@ -825,21 +816,21 @@ virtual int constantWrapper(Node *n) { Printv(s_attr_tab, mangled_classname, "_attributes[] = {\n", NIL); s_methods_tab = NewString(""); - Printf(s_methods_tab,"static swig_lua_method swig_"); + Printf(s_methods_tab, "static swig_lua_method swig_"); Printv(s_methods_tab, mangled_classname, "_methods[] = {\n", NIL); - // Generate normal wrappers + // Generate normal wrappers //return SWIG_OK; Language::classHandler(n); //return SWIG_OK; - SwigType *t = Copy(Getattr(n,"name")); + SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname); - SwigType_remember_clientdata(t,wrap_class); + SwigType_remember_clientdata(t, wrap_class); - String *rt = Copy(Getattr(n,"classtype")); + String *rt = Copy(Getattr(n, "classtype")); SwigType_add_pointer(rt); // Register the class structure with the type checker @@ -847,39 +838,39 @@ virtual int constantWrapper(Node *n) { if (have_destructor) { Printv(f_wrappers, "static void swig_delete_", class_name, "(void *obj) {\n", NIL); if (destructor_action) { - Printv(f_wrappers, SwigType_str(rt,"arg1"), " = (", SwigType_str(rt,0), ") obj;\n", NIL); + Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); Printv(f_wrappers, destructor_action, NIL); } else { if (CPlusPlus) { - Printv(f_wrappers," delete (", SwigType_str(rt,0), ") obj;\n",NIL); + Printv(f_wrappers, " delete (", SwigType_str(rt, 0), ") obj;\n", NIL); } else { - Printv(f_wrappers," free((char *) obj);\n",NIL); + Printv(f_wrappers, " free((char *) obj);\n", NIL); } } - Printf(f_wrappers,"}\n"); + Printf(f_wrappers, "}\n"); } Printf(s_methods_tab, " {0,0}\n};\n"); - Printv(f_wrappers,s_methods_tab,NIL); + Printv(f_wrappers, s_methods_tab, NIL); Printf(s_attr_tab, " {0,0,0}\n};\n"); - Printv(f_wrappers,s_attr_tab,NIL); + Printv(f_wrappers, s_attr_tab, NIL); - Delete(s_methods_tab); - Delete(s_attr_tab); + Delete(s_methods_tab); + Delete(s_attr_tab); // Handle inheritance String *base_class = NewString(""); - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator b; int index = 0; b = First(baselist); while (b.item) { String *bname = Getattr(b.item, "name"); - if ((!bname) || GetFlag(b.item,"feature:ignore") || (!Getattr(b.item,"module"))) { + if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) { b = Next(b); continue; } @@ -889,15 +880,15 @@ virtual int constantWrapper(Node *n) { Printv( base_class_init , " ", bname, "Ptr::constructor $ptr\n", NIL ); }*/ String *bmangle = Swig_name_mangle(bname); - // Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL); - Printf(base_class,"&_wrap_class_%s",bmangle); + // Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL); + Printf(base_class, "&_wrap_class_%s", bmangle); // Put code to register base classes in init function -// Printf(f_init,"/* Register base : %s */\n", bmangle); -// Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n", mangled_classname, index, SwigType_namestr(bname)); +// Printf(f_init,"/* Register base : %s */\n", bmangle); +// Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n", mangled_classname, index, SwigType_namestr(bname)); b = Next(b); index++; - Putc(',',base_class); + Putc(',', base_class); Delete(bmangle); } } @@ -919,23 +910,22 @@ virtual int constantWrapper(Node *n) { } }*/ - Printv(f_wrappers,"static swig_lua_class *swig_",mangled_classname,"_bases[] = {", base_class,"0};\n", NIL); + Printv(f_wrappers, "static swig_lua_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL); Delete(base_class); - Printv(f_wrappers, "swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, - "\", &SWIGTYPE", SwigType_manglestr(t), ",",NIL); + Printv(f_wrappers, "swig_lua_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); if (have_constructor) { - Printf(f_wrappers,"%s", Swig_name_wrapper(Swig_name_construct(class_name))); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(class_name))); } else { - Printf(f_wrappers,"0"); + Printf(f_wrappers, "0"); } if (have_destructor) { - Printv(f_wrappers, ", swig_delete_", class_name,NIL); + Printv(f_wrappers, ", swig_delete_", class_name, NIL); } else { - Printf(f_wrappers,",0"); + Printf(f_wrappers, ",0"); } - Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname,"_bases };\n\n", NIL); + Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases };\n\n", NIL); // Printv(s_cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, &_wrap_class_", mangled_classname, "},\n", NIL); Delete(t); Delete(mangled_classname); @@ -947,16 +937,16 @@ virtual int constantWrapper(Node *n) { * ------------------------------------------------------------ */ virtual int memberfunctionHandler(Node *n) { - String *name = Getattr(n,"name"); - String *iname = GetChar(n,"sym:name"); + String *name = Getattr(n, "name"); + String *iname = GetChar(n, "sym:name"); - String *realname, *rname; + String *realname, *rname; Language::memberfunctionHandler(n); realname = iname ? iname : name; rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { Printv(s_methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); } Delete(rname); @@ -969,17 +959,17 @@ virtual int constantWrapper(Node *n) { virtual int membervariableHandler(Node *n) { // REPORT("membervariableHandler",n); - String *symname = Getattr(n,"sym:name"); - String *rname; + String *symname = Getattr(n, "sym:name"); + String *rname; Language::membervariableHandler(n); Printv(s_attr_tab, tab4, "{ \"", symname, "\",", NIL); - rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name,symname))); + rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); Printv(s_attr_tab, rname, ", ", NIL); Delete(rname); - if (!GetFlag(n,"feature:immutable")) { - rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name,symname))); - Printv(s_attr_tab, rname, "},\n",NIL); + if (!GetFlag(n, "feature:immutable")) { + rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + Printv(s_attr_tab, rname, "},\n", NIL); Delete(rname); } else { Printf(s_attr_tab, "0 },\n"); @@ -993,7 +983,7 @@ virtual int constantWrapper(Node *n) { * Method for adding C++ member constructor * ------------------------------------------------------------ */ - virtual int constructorHandler(Node *n) { + virtual int constructorHandler(Node *n) { Language::constructorHandler(n); have_constructor = 1; return SWIG_OK; @@ -1006,7 +996,7 @@ virtual int constantWrapper(Node *n) { virtual int destructorHandler(Node *n) { Language::destructorHandler(n); have_destructor = 1; - destructor_action = Getattr(n,"wrap:action"); + destructor_action = Getattr(n, "wrap:action"); return SWIG_OK; } @@ -1043,28 +1033,28 @@ virtual int constantWrapper(Node *n) { /* --------------------------------------------------------------------- * external runtime generation * --------------------------------------------------------------------- */ - + /* This is to support the usage - SWIG -external-runtime + SWIG -external-runtime The code consists of two functions: - String *runtimeCode() // returns a large string with all the runtimes in - String *defaultExternalRuntimeFilename() // returns the default filename + String *runtimeCode() // returns a large string with all the runtimes in + String *defaultExternalRuntimeFilename() // returns the default filename I am writing a generic solution, even though SWIG-Lua only has one file right now... - */ + */ String *runtimeCode() { String *s = NewString(""); - const char* filenames[]={"luarun.swg",0}; // must be 0 termiated + const char *filenames[] = { "luarun.swg", 0 }; // must be 0 termiated String *sfile; - for (int i=0;filenames[i]!=0;i++) { + for (int i = 0; filenames[i] != 0; i++) { sfile = Swig_include_sys(filenames[i]); if (!sfile) { - Printf(stderr, "*** Unable to open '%s'\n",filenames[i]); + Printf(stderr, "*** Unable to open '%s'\n", filenames[i]); } else { - Append(s, sfile); - Delete(sfile); + Append(s, sfile); + Delete(sfile); } } - + return s; } @@ -1107,8 +1097,6 @@ NEW LANGUAGE NOTE:END ************************************************/ * swig_lua() - Instantiate module * ----------------------------------------------------------------------------- */ -extern "C" Language * -swig_lua(void) { +extern "C" Language *swig_lua(void) { return new LUA(); } - diff --git a/SWIG/Source/Modules/main.cxx b/SWIG/Source/Modules/main.cxx index 868808d07..3fccfbb99 100644 --- a/SWIG/Source/Modules/main.cxx +++ b/SWIG/Source/Modules/main.cxx @@ -24,24 +24,23 @@ char cvsroot_main_cxx[] = "$Header$"; // Global variables - Language *lang; // Language method - int CPlusPlus = 0; - int Extend = 0; // Extend flag - int ForceExtern = 0; // Force extern mode - int GenerateDefault = 1; // Generate default constructors - int Verbose = 0; - int AddExtern = 0; - int NoExcept = 0; - int SwigRuntime = 0; // 0 = no option, 1 = -c or -runtime, 2 = -noruntime +Language *lang; // Language method +int CPlusPlus = 0; +int Extend = 0; // Extend flag +int ForceExtern = 0; // Force extern mode +int GenerateDefault = 1; // Generate default constructors +int Verbose = 0; +int AddExtern = 0; +int NoExcept = 0; +int SwigRuntime = 0; // 0 = no option, 1 = -c or -runtime, 2 = -noruntime extern "C" { -extern String *ModuleName; + extern String *ModuleName; } /* usage string split into multiple parts otherwise string is too big for some compilers */ - -static const char *usage1 = (const char*)"\ +static const char *usage1 = (const char *) "\ \nGeneral Options\n\ -addextern - Add extra extern declarations\n\ -c++ - Enable C++ processing\n\ @@ -70,7 +69,7 @@ static const char *usage1 = (const char*)"\ If no explicit value is given to the feature, a default of 1 is used\n\ "; -static const char *usage2 = (const char*)"\ +static const char *usage2 = (const char *) "\ -fastdispatch - Enable fast dispatch mode to produce faster overload dispatcher code\n\ -Fmicrosoft - Display error/warning messages in Microsoft format\n\ -Fstandard - Display error/warning messages in commonly used format\n\ @@ -100,7 +99,7 @@ static const char *usage2 = (const char*)"\ -nopreprocess - Skip the preprocessor step\n\ "; -static const char *usage3 = (const char*)"\ +static const char *usage3 = (const char *) "\ -notemplatereduce - Disable reduction of the typedefs in templates\n\ -O - Enable the optimizations options: \n\ -fastdispatch -fvirtual \n\ @@ -130,47 +129,46 @@ is equivalent to: \n\ \n"; // Local variables -static String *LangSubDir = 0; // Target language library subdirectory -static char *SwigLib = 0; // Library directory -static String *SwigLibWin = 0; // Extra Library directory for Windows -static int freeze = 0; -static String *lang_config = 0; -static char *hpp_extension = (char *) "h"; -static char *cpp_extension = (char *) "cxx"; -static char *depends_extension = (char *) "d"; -static String *outdir = 0; -static String *xmlout = 0; -static int help = 0; -static int checkout = 0; -static int cpp_only = 0; -static int no_cpp = 0; -static char *outfile_name = 0; -static char *outfile_name_h = 0; -static int tm_debug = 0; -static int dump_tags = 0; -static int dump_top = 0; -static int dump_module = 0; -static int dump_parse_module = 0; -static int dump_parse_top = 0; -static int dump_xml = 0; -static int browse = 0; -static int dump_typedef = 0; -static int dump_classes = 0; -static int werror = 0; -static int depend = 0; -static int depend_only = 0; -static int memory_debug = 0; -static int allkw = 0; -static DOH *libfiles = 0; -static DOH *cpps = 0 ; -static String *dependencies_file = 0; -static File *f_dependencies_file = 0; -static int external_runtime = 0; +static String *LangSubDir = 0; // Target language library subdirectory +static char *SwigLib = 0; // Library directory +static String *SwigLibWin = 0; // Extra Library directory for Windows +static int freeze = 0; +static String *lang_config = 0; +static char *hpp_extension = (char *) "h"; +static char *cpp_extension = (char *) "cxx"; +static char *depends_extension = (char *) "d"; +static String *outdir = 0; +static String *xmlout = 0; +static int help = 0; +static int checkout = 0; +static int cpp_only = 0; +static int no_cpp = 0; +static char *outfile_name = 0; +static char *outfile_name_h = 0; +static int tm_debug = 0; +static int dump_tags = 0; +static int dump_top = 0; +static int dump_module = 0; +static int dump_parse_module = 0; +static int dump_parse_top = 0; +static int dump_xml = 0; +static int browse = 0; +static int dump_typedef = 0; +static int dump_classes = 0; +static int werror = 0; +static int depend = 0; +static int depend_only = 0; +static int memory_debug = 0; +static int allkw = 0; +static DOH *libfiles = 0; +static DOH *cpps = 0; +static String *dependencies_file = 0; +static File *f_dependencies_file = 0; +static int external_runtime = 0; static String *external_runtime_name = 0; -static char *fake_version = 0; +static char *fake_version = 0; -static const char *swig_package_version() -{ +static const char *swig_package_version() { return fake_version ? fake_version : PACKAGE_VERSION; } @@ -184,14 +182,11 @@ static const char *swig_package_version() static int check_suffix(char *name) { char *c; - if (!name) return 0; + if (!name) + return 0; c = Swig_file_suffix(name); - if ((strcmp(c,".c") == 0) || - (strcmp(c,".C") == 0) || - (strcmp(c,".cc") == 0) || - (strcmp(c,".cxx") == 0) || - (strcmp(c,".c++") == 0) || - (strcmp(c,".cpp") == 0)) { + if ((strcmp(c, ".c") == 0) || + (strcmp(c, ".C") == 0) || (strcmp(c, ".cc") == 0) || (strcmp(c, ".cxx") == 0) || (strcmp(c, ".c++") == 0) || (strcmp(c, ".cpp") == 0)) { return 1; } return 0; @@ -206,11 +201,11 @@ static void install_opts(int argc, char *argv[]) { int i; int noopt = 0; char *c; - for (i = 1; i < (argc-1); i++) { + for (i = 1; i < (argc - 1); i++) { if (argv[i]) { - if ((*argv[i] == '-') && (!isupper(*(argv[i]+1)))) { + if ((*argv[i] == '-') && (!isupper(*(argv[i] + 1)))) { String *opt = NewStringf("SWIGOPT%(upper)s", argv[i]); - Replaceall(opt,"-","_"); + Replaceall(opt, "-", "_"); c = Char(opt); noopt = 0; while (*c) { @@ -220,14 +215,14 @@ static void install_opts(int argc, char *argv[]) { } c++; } - if (((i+1) < (argc-1)) && (argv[i+1]) && (*argv[i+1] != '-')) { - Printf(opt," %s", argv[i+1]); + if (((i + 1) < (argc - 1)) && (argv[i + 1]) && (*argv[i + 1] != '-')) { + Printf(opt, " %s", argv[i + 1]); i++; } else { - Printf(opt," 1"); + Printf(opt, " 1"); } if (!noopt) { - /* Printf(stdout,"%s\n", opt); */ + /* Printf(stdout,"%s\n", opt); */ Preprocessor_define(opt, 0); } Delete(opt); @@ -243,15 +238,15 @@ static void install_opts(int argc, char *argv[]) { static void set_outdir(const String *c_wrapper_file_dir) { - // Add file delimiter if not present in output directory name - if (outdir && Len(outdir) != 0) { - const char* outd = Char(outdir); - if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMETER), SWIG_FILE_DELIMETER) != 0) - Printv(outdir, SWIG_FILE_DELIMETER, NIL); - } - // Use the C wrapper file's directory if the output directory has not been set by user - if (!outdir) - outdir = NewString(c_wrapper_file_dir); + // Add file delimiter if not present in output directory name + if (outdir && Len(outdir) != 0) { + const char *outd = Char(outdir); + if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMETER), SWIG_FILE_DELIMETER) != 0) + Printv(outdir, SWIG_FILE_DELIMETER, NIL); + } + // Use the C wrapper file's directory if the output directory has not been set by user + if (!outdir) + outdir = NewString(c_wrapper_file_dir); } //----------------------------------------------------------------- @@ -273,29 +268,27 @@ void SWIG_library_directory(const char *subdirectory) { // Returns the directory for generating language specific files (non C/C++ files) const String *SWIG_output_directory() { - assert(outdir); - return outdir; + assert(outdir); + return outdir; } void SWIG_config_cppext(const char *ext) { cpp_extension = (char *) ext; } -void SWIG_setfeature(const char *cfeature, const char *cvalue) -{ +void SWIG_setfeature(const char *cfeature, const char *cvalue) { Hash *features_hash = Swig_cparse_features(); String *name = NewString(""); String *fname = NewString(cfeature); String *fvalue = NewString(cvalue); - Swig_feature_set(features_hash,name,0,fname,fvalue,0); + Swig_feature_set(features_hash, name, 0, fname, fvalue, 0); Delete(name); Delete(fname); Delete(fvalue); } -void SWIG_setfeatures(const char *c) -{ +void SWIG_setfeatures(const char *c) { char feature[64]; char *fb = feature; char *fe = fb + 63; @@ -310,21 +303,21 @@ void SWIG_setfeatures(const char *c) *(f++) = *(c++); } *f = 0; - Printf(fname,"%s",feature); + Printf(fname, "%s", feature); if (*c && *(c++) == '=') { char value[64]; char *v = value; char *ve = v + 63; - while ((v != ve) && *c != ',' && *c && !isspace(*c)) { + while ((v != ve) && *c != ',' && *c && !isspace(*c)) { *(v++) = *(c++); } *v = 0; - Printf(fvalue,"%s",value); + Printf(fvalue, "%s", value); } else { - Printf(fvalue,"1"); - } + Printf(fvalue, "1"); + } /* Printf(stderr,"%s %s\n", fname, fvalue); */ - Swig_feature_set(features_hash,name,0,fname,fvalue,0); + Swig_feature_set(features_hash, name, 0, fname, fvalue, 0); Delete(fname); Delete(fvalue); } @@ -362,7 +355,7 @@ static void SWIG_dump_runtime() { } Printf(runtime, "%s", s); Delete(s); - + s = Swig_include_sys("swigerrors.swg"); if (!s) { Printf(stderr, "*** Unable to open 'swigerrors.swg'\n"); @@ -371,7 +364,7 @@ static void SWIG_dump_runtime() { } Printf(runtime, "%s", s); Delete(s); - + s = Swig_include_sys("swigerrors.swg"); if (!s) { Printf(stderr, "*** Unable to open 'swigerrors.swg'\n"); @@ -400,336 +393,333 @@ static void SWIG_dump_runtime() { } Printf(runtime, "%s", s); Delete(s); - + Close(runtime); Delete(runtime); SWIG_exit(EXIT_SUCCESS); } -void SWIG_getoptions(int argc, char *argv[]) -{ - int i; +void SWIG_getoptions(int argc, char *argv[]) { + int i; // Get options for (i = 1; i < argc; i++) { - if (argv[i] && !Swig_check_marked(i)) { - if (strncmp(argv[i],"-I-",3) == 0) { - // Don't push/pop directories - Swig_set_push_dir(0); - Swig_mark_arg(i); - } else if (strncmp(argv[i],"-I",2) == 0) { - // Add a new directory search path - Swig_add_directory((DOH *) Swig_copy_string(argv[i]+2)); - Swig_mark_arg(i); - } else if (strncmp(argv[i],"-D",2) == 0) { - String *d = NewString(argv[i]+2); - Replace(d,(char*)"=",(char*)" ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); - Preprocessor_define((DOH *) d,0); - Delete(d); - // Create a symbol - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-E") == 0) { - cpp_only = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nopreprocess") == 0) { - no_cpp = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-verbose") == 0) || - (strcmp(argv[i],"-v") == 0)) { - Verbose = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-c++") == 0) { - CPlusPlus=1; - Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); - Swig_cparse_cplusplus(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fcompact") == 0) { - Wrapper_compact_print_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fvirtual") == 0) { - Wrapper_virtual_elimination_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fastdispatch") == 0) { - Wrapper_fast_dispatch_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nofastdispatch") == 0) { - Wrapper_fast_dispatch_mode_set(0); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-naturalvar") == 0) { - Wrapper_naturalvar_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nonaturalvar") == 0) { - Wrapper_naturalvar_mode_set(0); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-directors") == 0) { - SWIG_setfeature("feature:director","1"); - Wrapper_director_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dirprot") == 0) { - Wrapper_director_protected_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nodirprot") == 0) { - Wrapper_director_protected_mode_set(0); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-small") == 0) { - Wrapper_compact_print_mode_set(1); - Wrapper_virtual_elimination_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i], "-runtime") == 0) { - Swig_mark_arg(i); - Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n"); - SwigRuntime = 1; - } else if ((strcmp(argv[i],"-c") == 0) || (strcmp(argv[i],"-noruntime") == 0)) { - Swig_mark_arg(i); - Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n"); - SwigRuntime = 2; - } else if (strcmp(argv[i], "-external-runtime") == 0) { - external_runtime = 1; - Swig_mark_arg(i); - if (argv[i+1]) { - external_runtime_name = NewString(argv[i+1]); - Swig_mark_arg(i+1); - i++; - } - } else if ((strcmp(argv[i],"-make_default") == 0) || (strcmp(argv[i],"-makedefault") == 0)) { - GenerateDefault = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-no_default") == 0) || (strcmp(argv[i],"-nodefault") == 0)) { - GenerateDefault = 0; - Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG",1, - "dangerous, use -nodefaultctor, -nodefaultdtor instead.\n"); - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-nodefaultctor") == 0)) { - SWIG_setfeature("feature:nodefaultctor","1"); - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-nodefaultdtor") == 0)) { - SWIG_setfeature("feature:nodefaultdtor","1"); - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-copyctor") == 0)) { - SWIG_setfeature("feature:copyctor","1"); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noexcept") == 0) { - NoExcept = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noextern") == 0) { - Swig_warning(WARN_DEPRECATED_NOEXTERN, "SWIG",1, "-noextern command line option is deprecated; extern is no longer generated by default.\n"); - AddExtern = 0; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-addextern") == 0) { - AddExtern = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-show_templates") == 0) || (strcmp(argv[i],"-debug_template") == 0)) { - Swig_cparse_debug_templates(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-templatereduce") == 0) { - SWIG_cparse_template_reduce(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-notemplatereduce") == 0) { - SWIG_cparse_template_reduce(0); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-swiglib") == 0) { - if (SwigLibWin) - printf("%s\n", Char(SwigLibWin)); - printf("%s\n", SwigLib); - SWIG_exit (EXIT_SUCCESS); - } else if (strcmp(argv[i],"-o") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - outfile_name = Swig_copy_string(argv[i+1]); - if (!outfile_name_h || !dependencies_file) { - char *ext = strrchr(outfile_name, '.'); - String *basename = ext ? NewStringWithSize(outfile_name,ext-outfile_name) : NewString(outfile_name); - if (!dependencies_file) { - dependencies_file = NewStringf("%s.%s", basename, depends_extension); - } - if (!outfile_name_h) { - Printf(basename, ".%s", hpp_extension); - outfile_name_h = Swig_copy_string(Char(basename)); - } - Delete(basename); - } - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); + if (argv[i] && !Swig_check_marked(i)) { + if (strncmp(argv[i], "-I-", 3) == 0) { + // Don't push/pop directories + Swig_set_push_dir(0); + Swig_mark_arg(i); + } else if (strncmp(argv[i], "-I", 2) == 0) { + // Add a new directory search path + Swig_add_directory((DOH *) Swig_copy_string(argv[i] + 2)); + Swig_mark_arg(i); + } else if (strncmp(argv[i], "-D", 2) == 0) { + String *d = NewString(argv[i] + 2); + Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Preprocessor_define((DOH *) d, 0); + Delete(d); + // Create a symbol + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-E") == 0) { + cpp_only = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nopreprocess") == 0) { + no_cpp = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-verbose") == 0) || (strcmp(argv[i], "-v") == 0)) { + Verbose = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-c++") == 0) { + CPlusPlus = 1; + Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); + Swig_cparse_cplusplus(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-fcompact") == 0) { + Wrapper_compact_print_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-fvirtual") == 0) { + Wrapper_virtual_elimination_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-fastdispatch") == 0) { + Wrapper_fast_dispatch_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nofastdispatch") == 0) { + Wrapper_fast_dispatch_mode_set(0); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-naturalvar") == 0) { + Wrapper_naturalvar_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nonaturalvar") == 0) { + Wrapper_naturalvar_mode_set(0); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-directors") == 0) { + SWIG_setfeature("feature:director", "1"); + Wrapper_director_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dirprot") == 0) { + Wrapper_director_protected_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nodirprot") == 0) { + Wrapper_director_protected_mode_set(0); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-small") == 0) { + Wrapper_compact_print_mode_set(1); + Wrapper_virtual_elimination_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-runtime") == 0) { + Swig_mark_arg(i); + Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-c, -runtime, -noruntime command line options are deprecated.\n"); + SwigRuntime = 1; + } else if ((strcmp(argv[i], "-c") == 0) || (strcmp(argv[i], "-noruntime") == 0)) { + Swig_mark_arg(i); + Swig_warning(WARN_DEPRECATED_OPTC, "SWIG", 1, "-c, -runtime, -noruntime command line options are deprecated.\n"); + SwigRuntime = 2; + } else if (strcmp(argv[i], "-external-runtime") == 0) { + external_runtime = 1; + Swig_mark_arg(i); + if (argv[i + 1]) { + external_runtime_name = NewString(argv[i + 1]); + Swig_mark_arg(i + 1); + i++; + } + } else if ((strcmp(argv[i], "-make_default") == 0) || (strcmp(argv[i], "-makedefault") == 0)) { + GenerateDefault = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-no_default") == 0) || (strcmp(argv[i], "-nodefault") == 0)) { + GenerateDefault = 0; + Swig_warning(WARN_DEPRECATED_NODEFAULT, "SWIG", 1, "dangerous, use -nodefaultctor, -nodefaultdtor instead.\n"); + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-nodefaultctor") == 0)) { + SWIG_setfeature("feature:nodefaultctor", "1"); + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-nodefaultdtor") == 0)) { + SWIG_setfeature("feature:nodefaultdtor", "1"); + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-copyctor") == 0)) { + SWIG_setfeature("feature:copyctor", "1"); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noexcept") == 0) { + NoExcept = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noextern") == 0) { + Swig_warning(WARN_DEPRECATED_NOEXTERN, "SWIG", 1, "-noextern command line option is deprecated; extern is no longer generated by default.\n"); + AddExtern = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-addextern") == 0) { + AddExtern = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-show_templates") == 0) || (strcmp(argv[i], "-debug_template") == 0)) { + Swig_cparse_debug_templates(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-templatereduce") == 0) { + SWIG_cparse_template_reduce(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-notemplatereduce") == 0) { + SWIG_cparse_template_reduce(0); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-swiglib") == 0) { + if (SwigLibWin) + printf("%s\n", Char(SwigLibWin)); + printf("%s\n", SwigLib); + SWIG_exit(EXIT_SUCCESS); + } else if (strcmp(argv[i], "-o") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + outfile_name = Swig_copy_string(argv[i + 1]); + if (!outfile_name_h || !dependencies_file) { + char *ext = strrchr(outfile_name, '.'); + String *basename = ext ? NewStringWithSize(outfile_name, ext - outfile_name) : NewString(outfile_name); + if (!dependencies_file) { + dependencies_file = NewStringf("%s.%s", basename, depends_extension); } - } else if (strcmp(argv[i],"-oh") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - outfile_name_h = Swig_copy_string(argv[i+1]); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); + if (!outfile_name_h) { + Printf(basename, ".%s", hpp_extension); + outfile_name_h = Swig_copy_string(Char(basename)); } - } else if (strcmp(argv[i],"-fakeversion") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - fake_version = Swig_copy_string(argv[i+1]); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-version") == 0) { - fprintf(stdout,"\nSWIG Version %s\n", swig_package_version()); - fprintf(stdout,"\nCompiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM); - fprintf(stdout,"Please see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT); - SWIG_exit (EXIT_SUCCESS); - } else if (strcmp(argv[i],"-copyright") == 0) { - fprintf(stdout,"\nSWIG Version %s\n", swig_package_version()); - fprintf(stdout,"Copyright (c) 1995-1998\n"); - fprintf(stdout,"University of Utah and the Regents of the University of California\n"); - fprintf(stdout,"Copyright (c) 1998-2005\n"); - fprintf(stdout,"University of Chicago\n"); - fprintf(stdout,"Copyright (c) 2005-2006\n"); - fprintf(stdout,"Arizona Board of Regents (University of Arizona)\n"); - SWIG_exit (EXIT_SUCCESS); - } else if (strncmp(argv[i],"-l",2) == 0) { - // Add a new directory search path - Append(libfiles,argv[i]+2); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-co") == 0) { - checkout = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-features") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - SWIG_setfeatures(argv[i+1]); - Swig_mark_arg(i+1); - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-freeze") == 0) { - freeze = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-includeall") == 0) { - Preprocessor_include_all(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-importall") == 0) { - Preprocessor_import_all(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-ignoremissing") == 0) { - Preprocessor_ignore_missing(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-cpperraswarn") == 0) { - Preprocessor_error_as_warning(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocpperraswarn") == 0) { - Preprocessor_error_as_warning(0); - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-tm_debug") == 0) || (strcmp(argv[i],"-debug_typemap") == 0)) { - tm_debug = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-module") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - ModuleName = NewString(argv[i+1]); - Swig_mark_arg(i+1); - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-M") == 0) { - depend = 1; - depend_only = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-MM") == 0) { - depend = 2; - depend_only = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-MF") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - dependencies_file = NewString(argv[i+1]); - Swig_mark_arg(i+1); - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-MD") == 0) { - depend = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-MMD") == 0) { - depend = 2; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-outdir") == 0) { - Swig_mark_arg(i); - if (argv[i+1]) { - outdir = NewString(argv[i+1]); - Swig_mark_arg(i+1); - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-Wall") == 0) { - Swig_mark_arg(i); - Swig_warnall(); - } else if (strcmp(argv[i],"-Wallkw") == 0) { - allkw = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-Werror") == 0) { - werror = 1; - Swig_mark_arg(i); - } else if (strncmp(argv[i],"-w",2) == 0) { - Swig_mark_arg(i); - Swig_warnfilter(argv[i]+2,1); - } else if (strcmp(argv[i],"-dump_tags") == 0) { - dump_tags = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-dump_tree") == 0) || (strcmp(argv[i],"-dump_top") == 0)) { - dump_top = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_module") == 0) { - dump_module = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_parse_module") == 0) { - dump_parse_module = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_parse_top") == 0) { - dump_parse_top = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_xml") == 0) { - dump_xml = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-xmlout") == 0) { - dump_xml = 1; - Swig_mark_arg(i); - if (argv[i+1]) { - xmlout = NewString(argv[i+1]); - Swig_mark_arg(i+1); - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-nocontract") == 0) { - Swig_mark_arg(i); - Swig_contract_mode_set(0); - } else if (strcmp(argv[i],"-browse") == 0) { - browse = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_typedef") == 0) { - dump_typedef = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_classes") == 0) { - dump_classes = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dump_memory") == 0) { - memory_debug =1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-Fstandard") == 0) { - Swig_error_msg_format(EMF_STANDARD); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-Fmicrosoft") == 0) { - Swig_error_msg_format(EMF_MICROSOFT); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-O") == 0) { - Wrapper_virtual_elimination_mode_set(1); - Wrapper_fast_dispatch_mode_set(1); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-help") == 0) { - fputs(usage1,stdout); - fputs(usage2,stdout); - fputs(usage3,stdout); - Swig_mark_arg(i); - help = 1; + Delete(basename); } + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-oh") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + outfile_name_h = Swig_copy_string(argv[i + 1]); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-fakeversion") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + fake_version = Swig_copy_string(argv[i + 1]); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-version") == 0) { + fprintf(stdout, "\nSWIG Version %s\n", swig_package_version()); + fprintf(stdout, "\nCompiled with %s [%s]\n", SWIG_CXX, SWIG_PLATFORM); + fprintf(stdout, "Please see %s for reporting bugs and further information\n", PACKAGE_BUGREPORT); + SWIG_exit(EXIT_SUCCESS); + } else if (strcmp(argv[i], "-copyright") == 0) { + fprintf(stdout, "\nSWIG Version %s\n", swig_package_version()); + fprintf(stdout, "Copyright (c) 1995-1998\n"); + fprintf(stdout, "University of Utah and the Regents of the University of California\n"); + fprintf(stdout, "Copyright (c) 1998-2005\n"); + fprintf(stdout, "University of Chicago\n"); + fprintf(stdout, "Copyright (c) 2005-2006\n"); + fprintf(stdout, "Arizona Board of Regents (University of Arizona)\n"); + SWIG_exit(EXIT_SUCCESS); + } else if (strncmp(argv[i], "-l", 2) == 0) { + // Add a new directory search path + Append(libfiles, argv[i] + 2); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-co") == 0) { + checkout = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-features") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + SWIG_setfeatures(argv[i + 1]); + Swig_mark_arg(i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-freeze") == 0) { + freeze = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-includeall") == 0) { + Preprocessor_include_all(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-importall") == 0) { + Preprocessor_import_all(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-ignoremissing") == 0) { + Preprocessor_ignore_missing(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-cpperraswarn") == 0) { + Preprocessor_error_as_warning(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-nocpperraswarn") == 0) { + Preprocessor_error_as_warning(0); + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-tm_debug") == 0) || (strcmp(argv[i], "-debug_typemap") == 0)) { + tm_debug = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-module") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + ModuleName = NewString(argv[i + 1]); + Swig_mark_arg(i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-M") == 0) { + depend = 1; + depend_only = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-MM") == 0) { + depend = 2; + depend_only = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-MF") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + dependencies_file = NewString(argv[i + 1]); + Swig_mark_arg(i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-MD") == 0) { + depend = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-MMD") == 0) { + depend = 2; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-outdir") == 0) { + Swig_mark_arg(i); + if (argv[i + 1]) { + outdir = NewString(argv[i + 1]); + Swig_mark_arg(i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-Wall") == 0) { + Swig_mark_arg(i); + Swig_warnall(); + } else if (strcmp(argv[i], "-Wallkw") == 0) { + allkw = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-Werror") == 0) { + werror = 1; + Swig_mark_arg(i); + } else if (strncmp(argv[i], "-w", 2) == 0) { + Swig_mark_arg(i); + Swig_warnfilter(argv[i] + 2, 1); + } else if (strcmp(argv[i], "-dump_tags") == 0) { + dump_tags = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-dump_tree") == 0) || (strcmp(argv[i], "-dump_top") == 0)) { + dump_top = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_module") == 0) { + dump_module = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_parse_module") == 0) { + dump_parse_module = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_parse_top") == 0) { + dump_parse_top = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_xml") == 0) { + dump_xml = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-xmlout") == 0) { + dump_xml = 1; + Swig_mark_arg(i); + if (argv[i + 1]) { + xmlout = NewString(argv[i + 1]); + Swig_mark_arg(i + 1); + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-nocontract") == 0) { + Swig_mark_arg(i); + Swig_contract_mode_set(0); + } else if (strcmp(argv[i], "-browse") == 0) { + browse = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_typedef") == 0) { + dump_typedef = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_classes") == 0) { + dump_classes = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dump_memory") == 0) { + memory_debug = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-Fstandard") == 0) { + Swig_error_msg_format(EMF_STANDARD); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-Fmicrosoft") == 0) { + Swig_error_msg_format(EMF_MICROSOFT); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-O") == 0) { + Wrapper_virtual_elimination_mode_set(1); + Wrapper_fast_dispatch_mode_set(1); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage1, stdout); + fputs(usage2, stdout); + fputs(usage3, stdout); + Swig_mark_arg(i); + help = 1; } + } } } @@ -738,11 +728,11 @@ void SWIG_getoptions(int argc, char *argv[]) int SWIG_main(int argc, char *argv[], Language *l) { - char *c; + char *c; /* Initialize the SWIG core */ Swig_init(); - + /* Suppress warning messages for private inheritance, preprocessor evaluation, might be abstract, overloaded const, and ... @@ -752,8 +742,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { WARN_LANG_OVERLOAD_CONST 512 WARN_PARSE_BUILTIN_NAME 321 WARN_PARSE_REDUNDANT 322 - */ - Swig_warnfilter("202,309,403,512,321,322",1); + */ + Swig_warnfilter("202,309,403,512,321,322", 1); // Initialize the preprocessor Preprocessor_init(); @@ -785,12 +775,12 @@ int SWIG_main(int argc, char *argv[], Language *l) { count++; } Delete(package_version); - assert(count == 3); // Check version format is correct + assert(count == 3); // Check version format is correct /* Turn on contracts */ Swig_contract_mode_set(1); - Preprocessor_define(vers,0); + Preprocessor_define(vers, 0); /* Turn off directors mode */ Wrapper_director_mode_set(0); @@ -801,18 +791,18 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Check for SWIG_LIB environment variable if ((c = getenv("SWIG_LIB")) == (char *) 0) { #if defined(_WIN32) - char buf[MAX_PATH]; - char *p; - if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) { - *(p+1) = '\0'; - SwigLibWin = NewStringf("%sLib", buf); // Native windows installation path - } - SwigLib = Swig_copy_string(SWIG_LIB_WIN_UNIX); // Unix installation path using a drive letter (for msys/mingw) + char buf[MAX_PATH]; + char *p; + if (!(GetModuleFileName(0, buf, MAX_PATH) == 0 || (p = strrchr(buf, '\\')) == 0)) { + *(p + 1) = '\0'; + SwigLibWin = NewStringf("%sLib", buf); // Native windows installation path + } + SwigLib = Swig_copy_string(SWIG_LIB_WIN_UNIX); // Unix installation path using a drive letter (for msys/mingw) #else - SwigLib = Swig_copy_string(SWIG_LIB); + SwigLib = Swig_copy_string(SWIG_LIB); #endif } else { - SwigLib = Swig_copy_string(c); + SwigLib = Swig_copy_string(c); } libfiles = NewList(); @@ -826,13 +816,12 @@ int SWIG_main(int argc, char *argv[], Language *l) { Preprocessor_define((DOH *) "__cplusplus __cplusplus", 0); // Parse language dependent options - lang->main(argc,argv); + lang->main(argc, argv); if (help) { - Printf(stdout,"\nNote: 'swig - -help' displays options for a specific target language.\n\n"); - SWIG_exit (EXIT_SUCCESS); // Exit if we're in help mode + Printf(stdout, "\nNote: 'swig - -help' displays options for a specific target language.\n\n"); + SWIG_exit(EXIT_SUCCESS); // Exit if we're in help mode } - // Check all of the options to make sure we're cool. // Don't check for an input file if -external-runtime is passed Swig_check_options(external_runtime ? 0 : 1); @@ -842,15 +831,15 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Add language dependent directory to the search path { String *rl = NewString(""); - Printf(rl,".%sswig_lib%s%s", SWIG_FILE_DELIMETER, SWIG_FILE_DELIMETER, LangSubDir); + Printf(rl, ".%sswig_lib%s%s", SWIG_FILE_DELIMETER, SWIG_FILE_DELIMETER, LangSubDir); Swig_add_directory(rl); if (SwigLibWin) { rl = NewString(""); - Printf(rl,"%s%s%s", SwigLibWin, SWIG_FILE_DELIMETER, LangSubDir); + Printf(rl, "%s%s%s", SwigLibWin, SWIG_FILE_DELIMETER, LangSubDir); Swig_add_directory(rl); } rl = NewString(""); - Printf(rl,"%s%s%s", SwigLib, SWIG_FILE_DELIMETER, LangSubDir); + Printf(rl, "%s%s%s", SwigLib, SWIG_FILE_DELIMETER, LangSubDir); Swig_add_directory(rl); } @@ -860,22 +849,21 @@ int SWIG_main(int argc, char *argv[], Language *l) { Swig_add_directory((String *) SwigLib); if (Verbose) { - printf ("LangSubDir: %s\n", Char(LangSubDir)); - printf ("Search paths:\n"); + printf("LangSubDir: %s\n", Char(LangSubDir)); + printf("Search paths:\n"); List *sp = Swig_search_path(); Iterator s; for (s = First(sp); s.item; s = Next(s)) { - Printf(stdout," %s\n", s.item); + Printf(stdout, " %s\n", s.item); } } - // handle the -external-runtime argument if (external_runtime) SWIG_dump_runtime(); // If we made it this far, looks good. go for it.... - input_file = argv[argc-1]; + input_file = argv[argc - 1]; // If the user has requested to check out a file, handle that if (checkout) { @@ -885,24 +873,24 @@ int SWIG_main(int argc, char *argv[], Language *l) { outfile = outfile_name; if (Verbose) - printf ("Handling checkout...\n"); + printf("Handling checkout...\n"); s = Swig_include(input_file); if (!s) { - fprintf(stderr,"Unable to locate '%s' in the SWIG library.\n", input_file); + fprintf(stderr, "Unable to locate '%s' in the SWIG library.\n", input_file); } else { - FILE *f = fopen(outfile,"r"); + FILE *f = fopen(outfile, "r"); if (f) { fclose(f); - fprintf(stderr,"File '%s' already exists. Checkout aborted.\n", outfile); + fprintf(stderr, "File '%s' already exists. Checkout aborted.\n", outfile); } else { - f = fopen(outfile,"w"); + f = fopen(outfile, "w"); if (!f) { - fprintf(stderr,"Unable to create file '%s'\n", outfile); + fprintf(stderr, "Unable to create file '%s'\n", outfile); } else { if (Verbose) - fprintf(stdout,"'%s' checked out from the SWIG library.\n", input_file); - fputs(Char(s),f); + fprintf(stdout, "'%s' checked out from the SWIG library.\n", input_file); + fputs(Char(s), f); fclose(f); } } @@ -915,7 +903,7 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Run the preprocessor if (Verbose) - printf ("Preprocessing...\n"); + printf("Preprocessing...\n"); { int i; String *fs = NewString(""); @@ -923,46 +911,46 @@ int SWIG_main(int argc, char *argv[], Language *l) { if (!df) { char *cfile = Char(input_file); if (cfile && cfile[0] == '-') { - Printf(stderr,"Unable to find option or file '%s', ", input_file); - Printf(stderr,"use 'swig -help' for more information.\n", input_file); - } else { - Printf(stderr,"Unable to find file '%s'.\n", input_file); + Printf(stderr, "Unable to find option or file '%s', ", input_file); + Printf(stderr, "use 'swig -help' for more information.\n", input_file); + } else { + Printf(stderr, "Unable to find file '%s'.\n", input_file); } - SWIG_exit (EXIT_FAILURE); + SWIG_exit(EXIT_FAILURE); } fclose(df); - if(!no_cpp) { - Printf(fs,"%%include \n"); - if (allkw) { - Printf(fs,"%%include \n"); - } - if (lang_config) { - Printf(fs,"\n%%include <%s>\n", lang_config); - } - Printf(fs,"%%include \"%s\"\n", Swig_last_file()); - for (i = 0; i < Len(libfiles); i++) { - Printf(fs,"\n%%include \"%s\"\n", Getitem(libfiles,i)); - } - Seek(fs,0,SEEK_SET); - cpps = Preprocessor_parse(fs); + if (!no_cpp) { + Printf(fs, "%%include \n"); + if (allkw) { + Printf(fs, "%%include \n"); + } + if (lang_config) { + Printf(fs, "\n%%include <%s>\n", lang_config); + } + Printf(fs, "%%include \"%s\"\n", Swig_last_file()); + for (i = 0; i < Len(libfiles); i++) { + Printf(fs, "\n%%include \"%s\"\n", Getitem(libfiles, i)); + } + Seek(fs, 0, SEEK_SET); + cpps = Preprocessor_parse(fs); Delete(fs); } else { - df = Swig_open(input_file); - cpps = NewFileFromFile(df); + df = Swig_open(input_file); + cpps = NewFileFromFile(df); } if (Swig_error_count()) { - SWIG_exit(EXIT_FAILURE); + SWIG_exit(EXIT_FAILURE); } if (cpp_only) { - Printf(stdout,"%s", cpps); + Printf(stdout, "%s", cpps); while (freeze); - SWIG_exit (EXIT_SUCCESS); + SWIG_exit(EXIT_SUCCESS); } if (depend) { String *outfile; if (!outfile_name) { if (CPlusPlus) { - outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension); + outfile = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension); } else { outfile = NewStringf("%s_wrap.c", Swig_file_basename(input_file)); } @@ -970,29 +958,28 @@ int SWIG_main(int argc, char *argv[], Language *l) { outfile = NewString(outfile_name); } if (dependencies_file && Len(dependencies_file) != 0) { - f_dependencies_file = NewFile(dependencies_file,"w"); + f_dependencies_file = NewFile(dependencies_file, "w"); if (!f_dependencies_file) { FileErrorDisplay(dependencies_file); SWIG_exit(EXIT_FAILURE); } } else if (!depend_only) { String *filename = NewStringf("%s_wrap.%s", Swig_file_basename(input_file), depends_extension); - f_dependencies_file = NewFile(filename,"w"); + f_dependencies_file = NewFile(filename, "w"); if (!f_dependencies_file) { FileErrorDisplay(filename); SWIG_exit(EXIT_FAILURE); } - } - else + } else f_dependencies_file = stdout; - Printf(f_dependencies_file,"%s: ", outfile); + Printf(f_dependencies_file, "%s: ", outfile); List *files = Preprocessor_depend(); for (int i = 0; i < Len(files); i++) { - if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files,i), SwigLib, Len(SwigLib)) != 0))) { - Printf(f_dependencies_file,"\\\n %s ", Getitem(files,i)); + if ((depend != 2) || ((depend == 2) && (Strncmp(Getitem(files, i), SwigLib, Len(SwigLib)) != 0))) { + Printf(f_dependencies_file, "\\\n %s ", Getitem(files, i)); } } - Printf(f_dependencies_file,"\n"); + Printf(f_dependencies_file, "\n"); if (f_dependencies_file != stdout) Close(f_dependencies_file); if (depend_only) @@ -1006,8 +993,8 @@ int SWIG_main(int argc, char *argv[], Language *l) { // Pass control over to the specific language interpreter if (Verbose) { - fprintf (stdout, "Starting language-specific parse...\n"); - fflush (stdout); + fprintf(stdout, "Starting language-specific parse...\n"); + fflush(stdout); } Node *top = Swig_cparse(cpps); @@ -1016,33 +1003,33 @@ int SWIG_main(int argc, char *argv[], Language *l) { Swig_print_tree(top); } if (dump_parse_module) { - Swig_print_tree(Getattr(top,"module")); + Swig_print_tree(Getattr(top, "module")); } if (Verbose) { - Printf(stdout,"Processing types...\n"); + Printf(stdout, "Processing types...\n"); } Swig_process_types(top); if (Verbose) { - Printf(stdout,"C++ analysis...\n"); + Printf(stdout, "C++ analysis...\n"); } Swig_default_allocators(top); if (Verbose) { - Printf(stdout,"Generating wrappers...\n"); + Printf(stdout, "Generating wrappers...\n"); } if (dump_classes) { - Hash *classes = Getattr(top,"classes"); + Hash *classes = Getattr(top, "classes"); if (classes) { - Printf(stdout,"Classes\n"); - Printf(stdout,"------------\n"); + Printf(stdout, "Classes\n"); + Printf(stdout, "------------\n"); Iterator ki; for (ki = First(classes); ki.key; ki = Next(ki)) { - Printf(stdout,"%s\n", ki.key); + Printf(stdout, "%s\n", ki.key); } - } + } } if (dump_typedef) { @@ -1050,36 +1037,36 @@ int SWIG_main(int argc, char *argv[], Language *l) { } if (dump_tags) { - Swig_print_tags(top,0); + Swig_print_tags(top, 0); } if (top) { - if (!Getattr(top,"name")) { - Printf(stderr,"*** No module name specified using %%module or -module.\n"); + if (!Getattr(top, "name")) { + Printf(stderr, "*** No module name specified using %%module or -module.\n"); SWIG_exit(EXIT_FAILURE); } else { /* Set some filename information on the object */ - Setattr(top,"infile", input_file); + Setattr(top, "infile", input_file); if (!outfile_name) { if (CPlusPlus) { - Setattr(top,"outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file),cpp_extension)); + Setattr(top, "outfile", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), cpp_extension)); } else { - Setattr(top,"outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file))); + Setattr(top, "outfile", NewStringf("%s_wrap.c", Swig_file_basename(input_file))); } } else { - Setattr(top,"outfile", outfile_name); + Setattr(top, "outfile", outfile_name); } if (!outfile_name_h) { - Setattr(top,"outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file),hpp_extension)); + Setattr(top, "outfile_h", NewStringf("%s_wrap.%s", Swig_file_basename(input_file), hpp_extension)); } else { - Setattr(top,"outfile_h", outfile_name_h); + Setattr(top, "outfile_h", outfile_name_h); } - set_outdir(Swig_file_dirname(Getattr(top,"outfile"))); + set_outdir(Swig_file_dirname(Getattr(top, "outfile"))); if (Swig_contract_mode_get()) { Swig_contracts(top); } lang->top(top); if (browse) { - Swig_browser(top,0); + Swig_browser(top, 0); } } } @@ -1087,15 +1074,17 @@ int SWIG_main(int argc, char *argv[], Language *l) { Swig_print_tree(top); } if (dump_module) { - Swig_print_tree(Getattr(top,"module")); + Swig_print_tree(Getattr(top, "module")); } if (dump_xml) { Swig_print_xml(top, xmlout); } Delete(top); } - if (tm_debug) Swig_typemap_debug(); - if (memory_debug) DohMemoryDebug(); + if (tm_debug) + Swig_typemap_debug(); + if (memory_debug) + DohMemoryDebug(); // Deletes Delete(libfiles); @@ -1118,6 +1107,5 @@ int SWIG_main(int argc, char *argv[], Language *l) { void SWIG_exit(int exit_code) { while (freeze); - exit (exit_code); + exit(exit_code); } - diff --git a/SWIG/Source/Modules/modula3.cxx b/SWIG/Source/Modules/modula3.cxx index 9cbccc202..680983d73 100644 --- a/SWIG/Source/Modules/modula3.cxx +++ b/SWIG/Source/Modules/modula3.cxx @@ -124,33 +124,27 @@ char cvsroot_modula3_cxx[] = "$Header$"; #include "swigmod.h" -#include // for INT_MAX +#include // for INT_MAX #include -const char usageArgDir[] = - "m3wrapargdir typemap expect values: in, out, inout\n"; +const char usageArgDir[] = "m3wrapargdir typemap expect values: in, out, inout\n"; -class MODULA3:public Language -{ +class MODULA3:public Language { public: - enum block_type - { no_block, constant, variable, blocktype, revelation }; + enum block_type { no_block, constant, variable, blocktype, revelation }; private: - struct M3File - { + struct M3File { String *f; Hash *import; block_type bt; /* VC++ 6 doesn't allow the access to 'no_block' if it is a private member of MODULA3 class */ - M3File ():f (NewString ("")), import (NewHash ()), bt (no_block) - { + M3File():f(NewString("")), import(NewHash()), bt(no_block) { }; - ~M3File () - { - Delete (f); - Delete (import); + ~M3File() { + Delete(f); + Delete(import); }; /* ----------------------------------------------------------------------------- @@ -159,18 +153,16 @@ private: * Make sure that a given declaration is written to the right declaration block, * that is constants are written after "CONST" and so on ... * ----------------------------------------------------------------------------- */ - void enterBlock (block_type newbt) - { - static const char *ident[] = - { "", "\nCONST\n", "\nVAR\n", "\nTYPE\n", "\nREVEAL\n" }; + void enterBlock(block_type newbt) { + static const char *ident[] = { "", "\nCONST\n", "\nVAR\n", "\nTYPE\n", "\nREVEAL\n" }; #ifdef DEBUG if ((bt < 0) || (4 < bt)) { - printf ("bt %d out of range\n", bt); + printf("bt %d out of range\n", bt); }; #endif if (newbt != bt) { - Append (f, ident[newbt]); - bt = newbt; + Append(f, ident[newbt]); + bt = newbt; }; }; @@ -185,21 +177,21 @@ private: File *f_wrappers; File *f_init; - bool proxy_flag; // Flag for generating proxy classes + bool proxy_flag; // Flag for generating proxy classes bool have_default_constructor_flag; - bool native_function_flag; // Flag for when wrapping a native function - bool enum_constant_flag; // Flag for when wrapping an enum or constant - bool static_flag; // Flag for when wrapping a static functions or member variables - bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable - bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const - bool global_variable_flag; // Flag for when wrapping a global variable - bool old_variable_names; // Flag for old style variable names in the intermediary class + bool native_function_flag; // Flag for when wrapping a native function + bool enum_constant_flag; // Flag for when wrapping an enum or constant + bool static_flag; // Flag for when wrapping a static functions or member variables + bool variable_wrapper_flag; // Flag for when wrapping a nonstatic member variable + bool wrapping_member_flag; // Flag for when wrapping a member variable/enum/const + bool global_variable_flag; // Flag for when wrapping a global variable + bool old_variable_names; // Flag for old style variable names in the intermediary class bool unsafe_module; - String *m3raw_name; // raw interface name - M3File m3raw_intf; // raw interface - M3File m3raw_impl; // raw implementation (usually empty) - String *m3wrap_name; // wrapper module + String *m3raw_name; // raw interface name + M3File m3raw_intf; // raw interface + M3File m3raw_impl; // raw implementation (usually empty) + String *m3wrap_name; // wrapper module M3File m3wrap_intf; M3File m3wrap_impl; String *m3makefile; @@ -207,12 +199,12 @@ private: String *proxy_class_def; String *proxy_class_code; String *proxy_class_name; - String *variable_name; //Name of a variable being wrapped - String *variable_type; //Type of this variable - String *enumeration_name; //Name of the current enumeration type - Hash *enumeration_items; //and its members + String *variable_name; //Name of a variable being wrapped + String *variable_type; //Type of this variable + String *enumeration_name; //Name of the current enumeration type + Hash *enumeration_items; //and its members int enumeration_max; - Hash *enumeration_coll; //Collection of all enumerations. + Hash *enumeration_coll; //Collection of all enumerations. /* The items are nodes with members: "items" - hash of with key 'itemname' and content 'itemvalue' "max" - maximum value in item list @@ -221,21 +213,20 @@ private: String *constantfilename; String *renamefilename; String *typemapfilename; - String *m3raw_imports; //intermediary class imports from %pragma - String *module_imports; //module imports from %pragma - String *m3raw_baseclass; //inheritance for intermediary class class from %pragma - String *module_baseclass; //inheritance for module class from %pragma - String *m3raw_interfaces; //interfaces for intermediary class class from %pragma - String *module_interfaces; //interfaces for module class from %pragma - String *m3raw_class_modifiers; //class modifiers for intermediary class overriden by %pragma - String *m3wrap_modifiers; //class modifiers for module class overriden by %pragma - String *upcasts_code; //C++ casts for inheritance hierarchies C++ code - String *m3raw_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code - String *destructor_call; //C++ destructor call if any + String *m3raw_imports; //intermediary class imports from %pragma + String *module_imports; //module imports from %pragma + String *m3raw_baseclass; //inheritance for intermediary class class from %pragma + String *module_baseclass; //inheritance for module class from %pragma + String *m3raw_interfaces; //interfaces for intermediary class class from %pragma + String *module_interfaces; //interfaces for module class from %pragma + String *m3raw_class_modifiers; //class modifiers for intermediary class overriden by %pragma + String *m3wrap_modifiers; //class modifiers for module class overriden by %pragma + String *upcasts_code; //C++ casts for inheritance hierarchies C++ code + String *m3raw_cppcasts_code; //C++ casts up inheritance hierarchies intermediary class code + String *destructor_call; //C++ destructor call if any String *outfile; - enum type_additions - { none, pointer, reference }; + enum type_additions { none, pointer, reference }; public: @@ -243,54 +234,56 @@ public: * MODULA3() * ----------------------------------------------------------------------------- */ -MODULA3 (): - empty_string (NewString ("")), - swig_types_hash (NULL), - f_runtime (NULL), - f_header (NULL), - f_wrappers (NULL), - f_init (NULL), - proxy_flag (true), - have_default_constructor_flag (false), - native_function_flag (false), - enum_constant_flag (false), - static_flag (false), - variable_wrapper_flag (false), - wrapping_member_flag (false), - global_variable_flag (false), - old_variable_names (false), - unsafe_module (false), - m3raw_name (NULL), - m3raw_intf (), - m3raw_impl (), - m3wrap_name (NULL), - m3wrap_intf (), - m3wrap_impl (), - m3makefile (NULL), - targetlibrary (NULL), - proxy_class_def (NULL), - proxy_class_code (NULL), - proxy_class_name (NULL), - variable_name (NULL), - variable_type (NULL), - enumeration_name (NULL), - enumeration_items (NULL), - enumeration_max (0), - enumeration_coll (NULL), - constant_values (NULL), - constantfilename (NULL), - renamefilename (NULL), - typemapfilename (NULL), - m3raw_imports (NULL), - module_imports (NULL), - m3raw_baseclass (NULL), - module_baseclass (NULL), - m3raw_interfaces (NULL), - module_interfaces (NULL), - m3raw_class_modifiers (NULL), - m3wrap_modifiers (NULL), - upcasts_code (NULL), - m3raw_cppcasts_code (NULL), destructor_call (NULL), outfile (NULL) { +MODULA3(): + empty_string(NewString("")), + swig_types_hash(NULL), + f_runtime(NULL), + f_header(NULL), + f_wrappers(NULL), + f_init(NULL), + proxy_flag(true), + have_default_constructor_flag(false), + native_function_flag(false), + enum_constant_flag(false), + static_flag(false), + variable_wrapper_flag(false), + wrapping_member_flag(false), + global_variable_flag(false), + old_variable_names(false), + unsafe_module(false), + m3raw_name(NULL), + m3raw_intf(), + m3raw_impl(), + m3wrap_name(NULL), + m3wrap_intf(), + m3wrap_impl(), + m3makefile(NULL), + targetlibrary(NULL), + proxy_class_def(NULL), + proxy_class_code(NULL), + proxy_class_name(NULL), + variable_name(NULL), + variable_type(NULL), + enumeration_name(NULL), + enumeration_items(NULL), + enumeration_max(0), + enumeration_coll(NULL), + constant_values(NULL), + constantfilename(NULL), + renamefilename(NULL), + typemapfilename(NULL), + m3raw_imports(NULL), + module_imports(NULL), + m3raw_baseclass(NULL), + module_baseclass(NULL), + m3raw_interfaces(NULL), + module_interfaces(NULL), + m3raw_class_modifiers(NULL), + m3wrap_modifiers(NULL), + upcasts_code(NULL), + m3raw_cppcasts_code(NULL), + destructor_call(NULL), + outfile(NULL) { } /************** some utility functions ***************/ @@ -302,18 +295,16 @@ MODULA3 (): * Print a standard warning if 'p' can't be mapped. * ----------------------------------------------------------------------------- */ - String *getMappedType (Node * p, const char *map) - { - String *mapattr = NewString ("tmap:"); - Append (mapattr, map); + String *getMappedType(Node *p, const char *map) { + String *mapattr = NewString("tmap:"); + Append(mapattr, map); - String *tm = Getattr (p, mapattr); + String *tm = Getattr(p, mapattr); if (tm == NIL) { - Swig_warning (WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number, - "No '%s' typemap defined for type '%s'\n", - map, SwigType_str (Getattr (p, "type"), 0)); + Swig_warning(WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number, + "No '%s' typemap defined for type '%s'\n", map, SwigType_str(Getattr(p, "type"), 0)); } - Delete (mapattr); + Delete(mapattr); return tm; } @@ -323,13 +314,11 @@ MODULA3 (): * Similar to getMappedType but uses Swig_type_lookup_new. * ----------------------------------------------------------------------------- */ - String *getMappedTypeNew (Node * n, const char *map, const char *lname = - "", bool warn = true) { - String *tm = Swig_typemap_lookup_new (map, n, lname, 0); + String *getMappedTypeNew(Node *n, const char *map, const char *lname = "", bool warn = true) { + String *tm = Swig_typemap_lookup_new(map, n, lname, 0); if ((tm == NIL) && warn) { - Swig_warning (WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number, - "No '%s' typemap defined for type '%s'\n", - map, SwigType_str (Getattr (n, "type"), 0)); + Swig_warning(WARN_MODULA3_TYPEMAP_TYPE_UNDEF, input_file, line_number, + "No '%s' typemap defined for type '%s'\n", map, SwigType_str(Getattr(n, "type"), 0)); } return tm; } @@ -340,12 +329,12 @@ MODULA3 (): * Obtain the type mapped by 'map' and attach it to the node * ----------------------------------------------------------------------------- */ - void attachMappedType (Node * n, const char *map, const char *lname = "") { - String *tm = Swig_typemap_lookup_new (map, n, lname, 0); + void attachMappedType(Node *n, const char *map, const char *lname = "") { + String *tm = Swig_typemap_lookup_new(map, n, lname, 0); if (tm != NIL) { - String *attr = NewStringf ("tmap:%s", map); - Setattr (n, attr, tm); - Delete (attr); + String *attr = NewStringf("tmap:%s", map); + Setattr(n, attr, tm); + Delete(attr); } } @@ -356,17 +345,16 @@ MODULA3 (): * with respect to a given typemap. * ----------------------------------------------------------------------------- */ - Node *skipIgnored (Node * p, const char *map) - { - String *niattr = NewStringf ("tmap:%s:numinputs", map); - String *nextattr = NewStringf ("tmap:%s:next", map); + Node *skipIgnored(Node *p, const char *map) { + String *niattr = NewStringf("tmap:%s:numinputs", map); + String *nextattr = NewStringf("tmap:%s:next", map); - while ((p != NIL) && checkAttribute (p, niattr, "0")) { - p = Getattr (p, nextattr); + while ((p != NIL) && checkAttribute(p, niattr, "0")) { + p = Getattr(p, nextattr); } - Delete (nextattr); - Delete (niattr); + Delete(nextattr); + Delete(niattr); return p; } @@ -377,30 +365,28 @@ MODULA3 (): * Check if the parameter is intended for input or for output. * ----------------------------------------------------------------------------- */ - bool isInParam (Node * p) - { - String *dir = Getattr (p, "tmap:m3wrapargdir"); + bool isInParam(Node *p) { + String *dir = Getattr(p, "tmap:m3wrapargdir"); //printf("dir for %s: %s\n", Char(Getattr(p,"name")), Char(dir)); - if ((dir == NIL) || (Strcmp (dir, "in") == 0) - || (Strcmp (dir, "inout") == 0)) { + if ((dir == NIL) || (Strcmp(dir, "in") == 0) + || (Strcmp(dir, "inout") == 0)) { return true; - } else if (Strcmp (dir, "out") == 0) { + } else if (Strcmp(dir, "out") == 0) { return false; } else { - printf (usageArgDir); + printf(usageArgDir); return false; } } - bool isOutParam (Node * p) - { - String *dir = Getattr (p, "tmap:m3wrapargdir"); - if ((dir == NIL) || (Strcmp (dir, "in") == 0)) { + bool isOutParam(Node *p) { + String *dir = Getattr(p, "tmap:m3wrapargdir"); + if ((dir == NIL) || (Strcmp(dir, "in") == 0)) { return false; - } else if ((Strcmp (dir, "out") == 0) || (Strcmp (dir, "inout") == 0)) { + } else if ((Strcmp(dir, "out") == 0) || (Strcmp(dir, "inout") == 0)) { return true; } else { - printf (usageArgDir); + printf(usageArgDir); return false; } } @@ -410,11 +396,10 @@ MODULA3 (): * * For debugging: Show all attributes of a node and their values. * ----------------------------------------------------------------------------- */ - void printAttrs (Node * n) - { + void printAttrs(Node *n) { Iterator it; - for (it = First (n); it.key != NIL; it = Next (it)) { - printf ("%s = %s\n", Char (it.key), Char (Getattr (n, it.key))); + for (it = First(n); it.key != NIL; it = Next(it)) { + printf("%s = %s\n", Char(it.key), Char(Getattr(n, it.key))); } } @@ -423,11 +408,10 @@ MODULA3 (): * * Check if a string have a given prefix. * ----------------------------------------------------------------------------- */ - bool hasPrefix (const String * str, const String * prefix) - { - int len_prefix = Len (prefix); - return (Len (str) > len_prefix) - && (Strncmp (str, prefix, len_prefix) == 0); + bool hasPrefix(const String *str, const String *prefix) { + int len_prefix = Len(prefix); + return (Len(str) > len_prefix) + && (Strncmp(str, prefix, len_prefix) == 0); } /* ----------------------------------------------------------------------------- @@ -437,33 +421,29 @@ MODULA3 (): * ----------------------------------------------------------------------------- */ #if 0 // Swig_symbol_qualified returns NIL for enumeration nodes - String *getQualifiedName (Node * n) - { - String *qual = Swig_symbol_qualified (n); - String *name = Getattr (n, "name"); - if (hasContent (qual)) { - return NewStringf ("%s::%s", qual, name); + String *getQualifiedName(Node *n) { + String *qual = Swig_symbol_qualified(n); + String *name = Getattr(n, "name"); + if (hasContent(qual)) { + return NewStringf("%s::%s", qual, name); } else { return name; } } #else - String *getQualifiedName (Node * n) - { - String *name = Copy (Getattr (n, "name")); - n = parentNode (n); + String *getQualifiedName(Node *n) { + String *name = Copy(Getattr(n, "name")); + n = parentNode(n); while (n != NIL) { - const String *type = nodeType (n); - if ((Strcmp (type, "class") == 0) || - (Strcmp (type, "struct") == 0) || - (Strcmp (type, "namespace") == 0)) { - String *newname = NewStringf ("%s::%s", Getattr (n, "name"), name); - Delete (name); - //name = newname; - // Hmpf, the class name is already qualified. - return newname; + const String *type = nodeType(n); + if ((Strcmp(type, "class") == 0) || (Strcmp(type, "struct") == 0) || (Strcmp(type, "namespace") == 0)) { + String *newname = NewStringf("%s::%s", Getattr(n, "name"), name); + Delete(name); + //name = newname; + // Hmpf, the class name is already qualified. + return newname; } - n = parentNode (n); + n = parentNode(n); } //printf("qualified name: %s\n", Char(name)); return name; @@ -476,34 +456,33 @@ MODULA3 (): * Turn usual C identifiers like "this_is_an_identifier" * into usual Modula 3 identifier like "thisIsAnIdentifier" * ----------------------------------------------------------------------------- */ - String *nameToModula3 (const String * sym, bool leadingCap) - { - int len_sym = Len (sym); - char *csym = Char (sym); + String *nameToModula3(const String *sym, bool leadingCap) { + int len_sym = Len(sym); + char *csym = Char(sym); char *m3sym = new char[len_sym + 1]; int i, j; bool cap = leadingCap; for (i = 0, j = 0; j < len_sym; j++) { char c = csym[j]; if ((c == '_') || (c == ':')) { - cap = true; + cap = true; } else { - if (isdigit (c)) { - m3sym[i] = c; - cap = true; - } else { - if (cap) { - m3sym[i] = toupper (c); - } else { - m3sym[i] = tolower (c); - } - cap = false; - } - i++; + if (isdigit(c)) { + m3sym[i] = c; + cap = true; + } else { + if (cap) { + m3sym[i] = toupper(c); + } else { + m3sym[i] = tolower(c); + } + cap = false; + } + i++; } } m3sym[i] = 0; - String *result = NewString (m3sym); + String *result = NewString(m3sym); delete[]m3sym; return result; } @@ -513,9 +492,8 @@ MODULA3 (): * * Make the first character upper case. * ----------------------------------------------------------------------------- */ - String *capitalizeFirst (const String * str) - { - return NewStringf ("%c%s", toupper (*Char (str)), Char (str) + 1); + String *capitalizeFirst(const String *str) { + return NewStringf("%c%s", toupper(*Char(str)), Char(str) + 1); } /* ----------------------------------------------------------------------------- @@ -526,27 +504,24 @@ MODULA3 (): * then it is replaced by the 'newprefix'. * The rest is converted to Modula style. * ----------------------------------------------------------------------------- */ - String *prefixedNameToModula3 (Node * n, const String * sym, - bool leadingCap) - { - String *oldPrefix = Getattr (n, "feature:modula3:oldprefix"); - String *newPrefix = Getattr (n, "feature:modula3:newprefix"); - String *result = NewString (""); - char *short_sym = Char (sym); + String *prefixedNameToModula3(Node *n, const String *sym, bool leadingCap) { + String *oldPrefix = Getattr(n, "feature:modula3:oldprefix"); + String *newPrefix = Getattr(n, "feature:modula3:newprefix"); + String *result = NewString(""); + char *short_sym = Char(sym); // if at least one prefix feature is present // the replacement takes place if ((oldPrefix != NIL) || (newPrefix != NIL)) { - if ((oldPrefix == NIL) || hasPrefix (sym, oldPrefix)) { - short_sym += Len (oldPrefix); - if (newPrefix != NIL) { - Append (result, newPrefix); - } + if ((oldPrefix == NIL) || hasPrefix(sym, oldPrefix)) { + short_sym += Len(oldPrefix); + if (newPrefix != NIL) { + Append(result, newPrefix); + } } } - String *suffix = nameToModula3 (short_sym, leadingCap - || hasContent (newPrefix)); - Append (result, suffix); - Delete (suffix); + String *suffix = nameToModula3(short_sym, leadingCap || hasContent(newPrefix)); + Append(result, suffix); + Delete(suffix); return result; } @@ -555,9 +530,8 @@ MODULA3 (): * * Check if the string exists and contains something. * ----------------------------------------------------------------------------- */ - bool hasContent (const String * str) - { - return (str != NIL) && (Strcmp (str, "") != 0); + bool hasContent(const String *str) { + return (str != NIL) && (Strcmp(str, "") != 0); } /* ----------------------------------------------------------------------------- @@ -567,14 +541,13 @@ MODULA3 (): * by this routine. * ----------------------------------------------------------------------------- */ - File *openWriteFile (String * name) - { - File *file = NewFile (name, "w"); + File *openWriteFile(String *name) { + File *file = NewFile(name, "w"); if (!file) { - FileErrorDisplay (name); - SWIG_exit (EXIT_FAILURE); + FileErrorDisplay(name); + SWIG_exit(EXIT_FAILURE); } - Delete (name); + Delete(name); return file; } @@ -584,14 +557,11 @@ MODULA3 (): * like atol but with additional user warning * ----------------------------------------------------------------------------- */ - long aToL (const String * value) - { + long aToL(const String *value) { char *endptr; - long numvalue = strtol (Char (value), &endptr, 0); + long numvalue = strtol(Char(value), &endptr, 0); if (*endptr != 0) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "The string <%s> does not denote a numeric value.\n", - value); + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The string <%s> does not denote a numeric value.\n", value); } return numvalue; } @@ -602,10 +572,9 @@ MODULA3 (): * like strtol but returns if the conversion was successful * ----------------------------------------------------------------------------- */ - bool strToL (const String * value, long &numvalue) - { + bool strToL(const String *value, long &numvalue) { char *endptr; - numvalue = strtol (Char (value), &endptr, 0); + numvalue = strtol(Char(value), &endptr, 0); return (*endptr == 0); } @@ -615,26 +584,25 @@ MODULA3 (): * Evaluate simple expression as they may occur in "enumvalue" attributes. * ----------------------------------------------------------------------------- */ - bool evalExpr (String * value, long &numvalue) - { + bool evalExpr(String *value, long &numvalue) { // Split changes file status of String and thus cannot receive 'const' strings //printf("evaluate <%s>\n", Char(value)); - List *summands = Split (value, '+', INT_MAX); - Iterator sm = First (summands); + List *summands = Split(value, '+', INT_MAX); + Iterator sm = First(summands); numvalue = 0; - for (; sm.item != NIL; sm = Next (sm)) { - String *smvalue = Getattr (constant_values, sm.item); + for (; sm.item != NIL; sm = Next(sm)) { + String *smvalue = Getattr(constant_values, sm.item); long smnumvalue; if (smvalue != NIL) { - if (!strToL (smvalue, smnumvalue)) { + if (!strToL(smvalue, smnumvalue)) { //printf("evaluation: abort 0 <%s>\n", Char(smvalue)); - return false; - } + return false; + } } else { - if (!strToL (sm.item, smnumvalue)) { + if (!strToL(sm.item, smnumvalue)) { //printf("evaluation: abort 1 <%s>\n", Char(sm)); - return false; - } + return false; + } } numvalue += smnumvalue; } @@ -649,12 +617,11 @@ MODULA3 (): * Returns true if the given number is a power of two. * ----------------------------------------------------------------------------- */ - bool log2 (long n, long &exp) - { + bool log2(long n, long &exp) { exp = 0; while (n > 0) { if ((n & 1) != 0) { - return n == 1; + return n == 1; } exp++; n >>= 1; @@ -670,56 +637,47 @@ MODULA3 (): * 'name.next==NIL' denotes the end of the entry or argument list. * ----------------------------------------------------------------------------- */ - bool equalNilStr (const String * str0, const String * str1) - { + bool equalNilStr(const String *str0, const String *str1) { if (str0 == NIL) { return (str1 == NIL); //return (str0==NIL) == (str1==NIL); } else { - return (str1 != NIL) && (Cmp (str0, str1) == 0); + return (str1 != NIL) && (Cmp(str0, str1) == 0); //return Cmp(str0,str1)==0; } } - struct writeArgState - { + struct writeArgState { String *mode, *name, *type, *value; bool hold; - writeArgState ():mode (NIL), name (NIL), type (NIL), value (NIL), - hold (false) - { + writeArgState():mode(NIL), name(NIL), type(NIL), value(NIL), hold(false) { }; }; - void writeArg (File * f, writeArgState & state, - String * mode, String * name, String * type, String * value) - { + void writeArg(File *f, writeArgState & state, String *mode, String *name, String *type, String *value) { /* skip the first argument, only store the information for the next call in this case */ if (state.name != NIL) { if ((!state.hold) && (state.mode != NIL)) { - Printf (f, "%s ", state.mode); + Printf(f, "%s ", state.mode); } - if ((name != NIL) && - equalNilStr (state.mode, mode) && - equalNilStr (state.type, type) && - (state.value == NIL) && (value == NIL) - /* the same expression may have different values - due to side effects of the called function */ - /*equalNilStr(state.value,value) */ - ) { - Printf (f, "%s, ", state.name); - state.hold = true; + if ((name != NIL) && equalNilStr(state.mode, mode) && equalNilStr(state.type, type) && (state.value == NIL) && (value == NIL) + /* the same expression may have different values + due to side effects of the called function */ + /*equalNilStr(state.value,value) */ + ) { + Printf(f, "%s, ", state.name); + state.hold = true; } else { - Append (f, state.name); - if (state.type != NIL) { - Printf (f, ": %s", state.type); - } - if (state.value != NIL) { - Printf (f, ":= %s", state.value); - } - Append (f, ";\n"); - state.hold = false; + Append(f, state.name); + if (state.type != NIL) { + Printf(f, ": %s", state.type); + } + if (state.value != NIL) { + Printf(f, ":= %s", state.value); + } + Append(f, ";\n"); + state.hold = false; } } /* at the next call the current argument will be the previous one */ @@ -736,12 +694,11 @@ MODULA3 (): * Return NULL if not otherwise the proxy class name * ----------------------------------------------------------------------------- */ - String *getProxyName (SwigType * t) - { + String *getProxyName(SwigType *t) { if (proxy_flag) { - Node *n = classLookup (t); + Node *n = classLookup(t); if (n) { - return Getattr (n, "sym:name"); + return Getattr(n, "sym:name"); } } return NULL; @@ -753,478 +710,452 @@ MODULA3 (): * main() * ------------------------------------------------------------ */ - virtual void main (int argc, char *argv[]) - { + virtual void main(int argc, char *argv[]) { - SWIG_library_directory ("modula3"); + SWIG_library_directory("modula3"); // Look for certain command line options for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp (argv[i], "-generateconst") == 0) { - if (argv[i + 1]) { - constantfilename = NewString (argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); - i++; - } else { - Swig_arg_error (); - } - } else if (strcmp (argv[i], "-generaterename") == 0) { - if (argv[i + 1]) { - renamefilename = NewString (argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); - i++; - } else { - Swig_arg_error (); - } - } else if (strcmp (argv[i], "-generatetypemap") == 0) { - if (argv[i + 1]) { - typemapfilename = NewString (argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); - i++; - } else { - Swig_arg_error (); - } - } else if (strcmp (argv[i], "-noproxy") == 0) { - Swig_mark_arg (i); - proxy_flag = false; - } else if (strcmp (argv[i], "-oldvarnames") == 0) { - Swig_mark_arg (i); - old_variable_names = true; - } else if (strcmp (argv[i], "-help") == 0) { - Printf (stdout, "%s\n", usage); - } + if (strcmp(argv[i], "-generateconst") == 0) { + if (argv[i + 1]) { + constantfilename = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-generaterename") == 0) { + if (argv[i + 1]) { + renamefilename = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-generatetypemap") == 0) { + if (argv[i + 1]) { + typemapfilename = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-noproxy") == 0) { + Swig_mark_arg(i); + proxy_flag = false; + } else if (strcmp(argv[i], "-oldvarnames") == 0) { + Swig_mark_arg(i); + old_variable_names = true; + } else if (strcmp(argv[i], "-help") == 0) { + Printf(stdout, "%s\n", usage); + } } } // Add a symbol to the parser for conditional compilation - Preprocessor_define ("SWIGMODULA3 1", 0); + Preprocessor_define("SWIGMODULA3 1", 0); // Add typemap definitions - SWIG_typemap_lang ("modula3"); - SWIG_config_file ("modula3.swg"); + SWIG_typemap_lang("modula3"); + SWIG_config_file("modula3.swg"); - allow_overloading (); + allow_overloading(); } /* --------------------------------------------------------------------- * top() * --------------------------------------------------------------------- */ - virtual int top (Node * n) - { - if (hasContent (constantfilename) || - hasContent (renamefilename) || hasContent (typemapfilename)) { + virtual int top(Node *n) { + if (hasContent(constantfilename) || hasContent(renamefilename) || hasContent(typemapfilename)) { int result = SWIG_OK; - if (hasContent (constantfilename)) { - result = generateConstantTop (n) && result; + if (hasContent(constantfilename)) { + result = generateConstantTop(n) && result; } - if (hasContent (renamefilename)) { - result = generateRenameTop (n) && result; + if (hasContent(renamefilename)) { + result = generateRenameTop(n) && result; } - if (hasContent (typemapfilename)) { - result = generateTypemapTop (n) && result; + if (hasContent(typemapfilename)) { + result = generateTypemapTop(n) && result; } return result; } else { - return generateM3Top (n); + return generateM3Top(n); } } - void scanConstant (File * file, Node * n) - { - Node *child = firstChild (n); + void scanConstant(File *file, Node *n) { + Node *child = firstChild(n); while (child != NIL) { String *constname = NIL; - String *type = nodeType (child); - if ((Strcmp (type, "enumitem") == 0) - || (Strcmp (type, "constant") == 0)) { + String *type = nodeType(child); + if ((Strcmp(type, "enumitem") == 0) + || (Strcmp(type, "constant") == 0)) { #if 1 - constname = getQualifiedName (child); + constname = getQualifiedName(child); #else - constname = Getattr (child, "value"); - if ((!hasContent (constname)) - || (('0' <= *Char (constname)) && (*Char (constname) <= '9'))) { - constname = Getattr (child, "name"); - } + constname = Getattr(child, "value"); + if ((!hasContent(constname)) + || (('0' <= *Char(constname)) && (*Char(constname) <= '9'))) { + constname = Getattr(child, "name"); + } #endif } if (constname != NIL) { - Printf (file, - " printf(\"%%%%constnumeric(%%Lg) %s;\\n\", (long double)%s);\n", - constname, constname); + Printf(file, " printf(\"%%%%constnumeric(%%Lg) %s;\\n\", (long double)%s);\n", constname, constname); } - scanConstant (file, child); - child = nextSibling (child); + scanConstant(file, child); + child = nextSibling(child); } } - int generateConstantTop (Node * n) - { - File *file = openWriteFile (NewStringf ("%s.c", constantfilename)); + int generateConstantTop(Node *n) { + File *file = openWriteFile(NewStringf("%s.c", constantfilename)); if (CPlusPlus) { - Printf (file, "#include \n"); + Printf(file, "#include \n"); } else { - Printf (file, "#include \n"); + Printf(file, "#include \n"); } - Printf (file, "#include \"%s\"\n", input_file); - Printf (file, "\n"); - Printf (file, "int main (int argc, char *argv[]) {\n"); - Printf (file, "\ + Printf(file, "#include \"%s\"\n", input_file); + Printf(file, "\n"); + Printf(file, "int main (int argc, char *argv[]) {\n"); + Printf(file, "\ /*This progam must work for floating point numbers and integers.\n\ Thus all numbers are converted to double precision floating point format.*/\n"); - scanConstant (file, n); - Printf (file, " return 0;\n"); - Printf (file, "}\n"); - Close (file); + scanConstant(file, n); + Printf(file, " return 0;\n"); + Printf(file, "}\n"); + Close(file); return SWIG_OK; } - void scanRename (File * file, Node * n) - { - Node *child = firstChild (n); + void scanRename(File *file, Node *n) { + Node *child = firstChild(n); while (child != NIL) { - String *type = nodeType (child); - if (Strcmp (type, "cdecl") == 0) { - ParmList *p = Getattr (child, "parms"); - if (p != NIL) { - String *name = getQualifiedName (child); - String *m3name = nameToModula3 (name, true); - /*don't know how to get the original C type identifiers */ - //String *arguments = createCSignature (child); - Printf (file, "%%rename(\"%s\") %s;\n", m3name, name); - /*Printf(file, "%%rename(\"%s\") %s %s(%s);\n", - m3name, Getattr(n,"type"), name, arguments); */ - Delete (name); - Delete (m3name); - //Delete (arguments); - } + String *type = nodeType(child); + if (Strcmp(type, "cdecl") == 0) { + ParmList *p = Getattr(child, "parms"); + if (p != NIL) { + String *name = getQualifiedName(child); + String *m3name = nameToModula3(name, true); + /*don't know how to get the original C type identifiers */ + //String *arguments = createCSignature (child); + Printf(file, "%%rename(\"%s\") %s;\n", m3name, name); + /*Printf(file, "%%rename(\"%s\") %s %s(%s);\n", + m3name, Getattr(n,"type"), name, arguments); */ + Delete(name); + Delete(m3name); + //Delete (arguments); + } } - scanRename (file, child); - child = nextSibling (child); + scanRename(file, child); + child = nextSibling(child); } } - int generateRenameTop (Node * n) - { - File *file = openWriteFile (NewStringf ("%s.i", renamefilename)); - Printf (file, "\ + int generateRenameTop(Node *n) { + File *file = openWriteFile(NewStringf("%s.i", renamefilename)); + Printf(file, "\ /* This file was generated from %s\n\ by SWIG with option -generaterename. */\n\ \n", input_file); - scanRename (file, n); - Close (file); + scanRename(file, n); + Close(file); return SWIG_OK; } - void scanTypemap (File * file, Node * n) - { - Node *child = firstChild (n); + void scanTypemap(File *file, Node *n) { + Node *child = firstChild(n); while (child != NIL) { - String *type = nodeType (child); + String *type = nodeType(child); //printf("nodetype %s\n", Char(type)); - String *storage = Getattr (child, "storage"); - if ((Strcmp (type, "class") == 0) || - ((Strcmp (type, "cdecl") == 0) && (storage != NIL) - && (Strcmp (storage, "typedef") == 0))) { - String *name = getQualifiedName (child); - String *m3name = nameToModula3 (name, true); - Printf (file, "%%typemap(\"m3wrapintype\") %s %%{%s%%}\n", name, - m3name); - Printf (file, "%%typemap(\"m3rawintype\") %s %%{%s%%}\n", name, - m3name); - Printf (file, "\n"); + String *storage = Getattr(child, "storage"); + if ((Strcmp(type, "class") == 0) || ((Strcmp(type, "cdecl") == 0) && (storage != NIL) + && (Strcmp(storage, "typedef") == 0))) { + String *name = getQualifiedName(child); + String *m3name = nameToModula3(name, true); + Printf(file, "%%typemap(\"m3wrapintype\") %s %%{%s%%}\n", name, m3name); + Printf(file, "%%typemap(\"m3rawintype\") %s %%{%s%%}\n", name, m3name); + Printf(file, "\n"); } - scanTypemap (file, child); - child = nextSibling (child); + scanTypemap(file, child); + child = nextSibling(child); } } - int generateTypemapTop (Node * n) - { - File *file = openWriteFile (NewStringf ("%s.i", typemapfilename)); - Printf (file, "\ + int generateTypemapTop(Node *n) { + File *file = openWriteFile(NewStringf("%s.i", typemapfilename)); + Printf(file, "\ /* This file was generated from %s\n\ by SWIG with option -generatetypemap. */\n\ \n", input_file); - scanTypemap (file, n); - Close (file); + scanTypemap(file, n); + Close(file); return SWIG_OK; } - int generateM3Top (Node * n) - { + int generateM3Top(Node *n) { /* Initialize all of the output files */ - outfile = Getattr (n, "outfile"); + outfile = Getattr(n, "outfile"); - f_runtime = NewFile (outfile, "w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { - FileErrorDisplay (outfile); - SWIG_exit (EXIT_FAILURE); + FileErrorDisplay(outfile); + SWIG_exit(EXIT_FAILURE); } - f_init = NewString (""); - f_header = NewString (""); - f_wrappers = NewString (""); + f_init = NewString(""); + f_header = NewString(""); + f_wrappers = NewString(""); - m3makefile = NewString (""); + m3makefile = NewString(""); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname ("header", f_header); - Swig_register_filebyname ("wrapper", f_wrappers); - Swig_register_filebyname ("runtime", f_runtime); - Swig_register_filebyname ("init", f_init); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); - Swig_register_filebyname ("m3rawintf", m3raw_intf.f); - Swig_register_filebyname ("m3rawimpl", m3raw_impl.f); - Swig_register_filebyname ("m3wrapintf", m3wrap_intf.f); - Swig_register_filebyname ("m3wrapimpl", m3wrap_impl.f); - Swig_register_filebyname ("m3makefile", m3makefile); + Swig_register_filebyname("m3rawintf", m3raw_intf.f); + Swig_register_filebyname("m3rawimpl", m3raw_impl.f); + Swig_register_filebyname("m3wrapintf", m3wrap_intf.f); + Swig_register_filebyname("m3wrapimpl", m3wrap_impl.f); + Swig_register_filebyname("m3makefile", m3makefile); - swig_types_hash = NewHash (); + swig_types_hash = NewHash(); - String *name = Getattr (n, "name"); + String *name = Getattr(n, "name"); // Make the intermediary class and module class names. The intermediary class name can be set in the module directive. - Node *optionsnode = Getattr (Getattr (n, "module"), "options"); + Node *optionsnode = Getattr(Getattr(n, "module"), "options"); if (optionsnode != NIL) { - String *m3raw_name_tmp = Getattr (optionsnode, "m3rawname"); + String *m3raw_name_tmp = Getattr(optionsnode, "m3rawname"); if (m3raw_name_tmp != NIL) { - m3raw_name = Copy (m3raw_name_tmp); + m3raw_name = Copy(m3raw_name_tmp); } } if (m3raw_name == NIL) { - m3raw_name = NewStringf ("%sRaw", name); + m3raw_name = NewStringf("%sRaw", name); } - Setattr (m3wrap_impl.import, m3raw_name, ""); + Setattr(m3wrap_impl.import, m3raw_name, ""); - m3wrap_name = Copy (name); + m3wrap_name = Copy(name); - proxy_class_def = NewString (""); - proxy_class_code = NewString (""); - m3raw_baseclass = NewString (""); - m3raw_interfaces = NewString (""); - m3raw_class_modifiers = NewString (""); // package access only to the intermediary class by default - m3raw_imports = NewString (""); - m3raw_cppcasts_code = NewString (""); - m3wrap_modifiers = NewString ("public"); - module_baseclass = NewString (""); - module_interfaces = NewString (""); - module_imports = NewString (""); - upcasts_code = NewString (""); + proxy_class_def = NewString(""); + proxy_class_code = NewString(""); + m3raw_baseclass = NewString(""); + m3raw_interfaces = NewString(""); + m3raw_class_modifiers = NewString(""); // package access only to the intermediary class by default + m3raw_imports = NewString(""); + m3raw_cppcasts_code = NewString(""); + m3wrap_modifiers = NewString("public"); + module_baseclass = NewString(""); + module_interfaces = NewString(""); + module_imports = NewString(""); + upcasts_code = NewString(""); - Swig_banner (f_runtime); // Print the SWIG banner message + Swig_banner(f_runtime); // Print the SWIG banner message - String *wrapper_name = NewString (""); + String *wrapper_name = NewString(""); - Printf (wrapper_name, "Modula3_%%f", m3raw_name); - Swig_name_register ((char *) "wrapper", Char (wrapper_name)); + Printf(wrapper_name, "Modula3_%%f", m3raw_name); + Swig_name_register((char *) "wrapper", Char(wrapper_name)); if (old_variable_names) { - Swig_name_register ((char *) "set", (char *) "set_%v"); - Swig_name_register ((char *) "get", (char *) "get_%v"); + Swig_name_register((char *) "set", (char *) "set_%v"); + Swig_name_register((char *) "get", (char *) "get_%v"); } - Delete (wrapper_name); + Delete(wrapper_name); - Printf (f_wrappers, "\n#ifdef __cplusplus\n"); - Printf (f_wrappers, "extern \"C\" {\n"); - Printf (f_wrappers, "#endif\n\n"); + Printf(f_wrappers, "\n#ifdef __cplusplus\n"); + Printf(f_wrappers, "extern \"C\" {\n"); + Printf(f_wrappers, "#endif\n\n"); - constant_values = NewHash (); - scanForConstPragmas (n); - enumeration_coll = NewHash (); - collectEnumerations (enumeration_coll, n); + constant_values = NewHash(); + scanForConstPragmas(n); + enumeration_coll = NewHash(); + collectEnumerations(enumeration_coll, n); /* Emit code */ - Language::top (n); + Language::top(n); // Generate m3makefile // This will be unnecessary if SWIG is invoked from Quake. { - File *file = - openWriteFile (NewStringf - ("%sm3makefile", Swig_file_dirname (outfile))); + File *file = openWriteFile(NewStringf("%sm3makefile", Swig_file_dirname(outfile))); - Printf (file, "%% automatically generated quake file for %s\n\n", name); + Printf(file, "%% automatically generated quake file for %s\n\n", name); /* Write the fragments written by '%insert' collected while 'top' processed the parse tree */ - Printv (file, m3makefile, NIL); + Printv(file, m3makefile, NIL); - Printf (file, "import(\"libm3\")\n"); + Printf(file, "import(\"libm3\")\n"); //Printf(file, "import_lib(\"%s\",\"/usr/lib\")\n", name); - Printf (file, "module(\"%s\")\n", m3raw_name); - Printf (file, "module(\"%s\")\n\n", m3wrap_name); + Printf(file, "module(\"%s\")\n", m3raw_name); + Printf(file, "module(\"%s\")\n\n", m3wrap_name); if (targetlibrary != NIL) { - Printf (file, "library(\"%s\")\n", targetlibrary); + Printf(file, "library(\"%s\")\n", targetlibrary); } else { - Printf (file, "library(\"m3%s\")\n", name); + Printf(file, "library(\"m3%s\")\n", name); } - Close (file); + Close(file); } // Generate the raw interface { - File *file = - openWriteFile (NewStringf - ("%s%s.i3", Swig_file_dirname (outfile), m3raw_name)); + File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3raw_name)); - emitBanner (file); + emitBanner(file); - Printf (file, "INTERFACE %s;\n\n", m3raw_name); + Printf(file, "INTERFACE %s;\n\n", m3raw_name); - emitImportStatements (m3raw_intf.import, file); - Printf (file, "\n"); + emitImportStatements(m3raw_intf.import, file); + Printf(file, "\n"); // Write the interface generated within 'top' - Printv (file, m3raw_intf.f, NIL); + Printv(file, m3raw_intf.f, NIL); - Printf (file, "\nEND %s.\n", m3raw_name); - Close (file); + Printf(file, "\nEND %s.\n", m3raw_name); + Close(file); } // Generate the raw module { - File *file = - openWriteFile (NewStringf - ("%s%s.m3", Swig_file_dirname (outfile), m3raw_name)); + File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3raw_name)); - emitBanner (file); + emitBanner(file); - Printf (file, "MODULE %s;\n\n", m3raw_name); + Printf(file, "MODULE %s;\n\n", m3raw_name); - emitImportStatements (m3raw_impl.import, file); - Printf (file, "\n"); + emitImportStatements(m3raw_impl.import, file); + Printf(file, "\n"); // will be empty usually - Printv (file, m3raw_impl.f, NIL); + Printv(file, m3raw_impl.f, NIL); - Printf (file, "BEGIN\nEND %s.\n", m3raw_name); - Close (file); + Printf(file, "BEGIN\nEND %s.\n", m3raw_name); + Close(file); } // Generate the interface for the comfort wrappers { - File *file = - openWriteFile (NewStringf - ("%s%s.i3", Swig_file_dirname (outfile), m3wrap_name)); + File *file = openWriteFile(NewStringf("%s%s.i3", Swig_file_dirname(outfile), m3wrap_name)); - emitBanner (file); + emitBanner(file); - Printf (file, "INTERFACE %s;\n", m3wrap_name); + Printf(file, "INTERFACE %s;\n", m3wrap_name); - emitImportStatements (m3wrap_intf.import, file); - Printf (file, "\n"); + emitImportStatements(m3wrap_intf.import, file); + Printf(file, "\n"); { - Iterator it = First (enumeration_coll); - if (it.key != NIL) { - Printf (file, "TYPE\n"); - } - for (; it.key != NIL; it = Next (it)) { - Printf (file, "\n"); - emitEnumeration (file, it.key, it.item); - } + Iterator it = First(enumeration_coll); + if (it.key != NIL) { + Printf(file, "TYPE\n"); + } + for (; it.key != NIL; it = Next(it)) { + Printf(file, "\n"); + emitEnumeration(file, it.key, it.item); + } } // Add the wrapper methods - Printv (file, m3wrap_intf.f, NIL); + Printv(file, m3wrap_intf.f, NIL); // Finish off the class - Printf (file, "\nEND %s.\n", m3wrap_name); - Close (file); + Printf(file, "\nEND %s.\n", m3wrap_name); + Close(file); } // Generate the wrapper routines implemented in Modula 3 { - File *file = - openWriteFile (NewStringf - ("%s%s.m3", Swig_file_dirname (outfile), m3wrap_name)); + File *file = openWriteFile(NewStringf("%s%s.m3", Swig_file_dirname(outfile), m3wrap_name)); - emitBanner (file); + emitBanner(file); if (unsafe_module) { - Printf (file, "UNSAFE "); + Printf(file, "UNSAFE "); } - Printf (file, "MODULE %s;\n\n", m3wrap_name); + Printf(file, "MODULE %s;\n\n", m3wrap_name); - emitImportStatements (m3wrap_impl.import, file); - Printf (file, "\n"); + emitImportStatements(m3wrap_impl.import, file); + Printf(file, "\n"); // Add the wrapper methods - Printv (file, m3wrap_impl.f, NIL); + Printv(file, m3wrap_impl.f, NIL); - Printf (file, "\nBEGIN\nEND %s.\n", m3wrap_name); - Close (file); + Printf(file, "\nBEGIN\nEND %s.\n", m3wrap_name); + Close(file); } if (upcasts_code) - Printv (f_wrappers, upcasts_code, NIL); + Printv(f_wrappers, upcasts_code, NIL); - Printf (f_wrappers, "#ifdef __cplusplus\n"); - Printf (f_wrappers, "}\n"); - Printf (f_wrappers, "#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "}\n"); + Printf(f_wrappers, "#endif\n"); // Output a Modula 3 type wrapper class for each SWIG type - for (Iterator swig_type = First (swig_types_hash); swig_type.item != NIL; - swig_type = Next (swig_type)) { - emitTypeWrapperClass (swig_type.key, swig_type.item); + for (Iterator swig_type = First(swig_types_hash); swig_type.item != NIL; swig_type = Next(swig_type)) { + emitTypeWrapperClass(swig_type.key, swig_type.item); } - Delete (swig_types_hash); + Delete(swig_types_hash); swig_types_hash = NULL; - Delete (constant_values); + Delete(constant_values); constant_values = NULL; - Delete (enumeration_coll); + Delete(enumeration_coll); enumeration_coll = NULL; - Delete (m3raw_name); + Delete(m3raw_name); m3raw_name = NULL; - Delete (m3raw_baseclass); + Delete(m3raw_baseclass); m3raw_baseclass = NULL; - Delete (m3raw_interfaces); + Delete(m3raw_interfaces); m3raw_interfaces = NULL; - Delete (m3raw_class_modifiers); + Delete(m3raw_class_modifiers); m3raw_class_modifiers = NULL; - Delete (m3raw_imports); + Delete(m3raw_imports); m3raw_imports = NULL; - Delete (m3raw_cppcasts_code); + Delete(m3raw_cppcasts_code); m3raw_cppcasts_code = NULL; - Delete (proxy_class_def); + Delete(proxy_class_def); proxy_class_def = NULL; - Delete (proxy_class_code); + Delete(proxy_class_code); proxy_class_code = NULL; - Delete (m3wrap_name); + Delete(m3wrap_name); m3wrap_name = NULL; - Delete (m3wrap_modifiers); + Delete(m3wrap_modifiers); m3wrap_modifiers = NULL; - Delete (targetlibrary); + Delete(targetlibrary); targetlibrary = NULL; - Delete (module_baseclass); + Delete(module_baseclass); module_baseclass = NULL; - Delete (module_interfaces); + Delete(module_interfaces); module_interfaces = NULL; - Delete (module_imports); + Delete(module_imports); module_imports = NULL; - Delete (upcasts_code); + Delete(upcasts_code); upcasts_code = NULL; - Delete (constantfilename); + Delete(constantfilename); constantfilename = NULL; - Delete (renamefilename); + Delete(renamefilename); renamefilename = NULL; - Delete (typemapfilename); + Delete(typemapfilename); typemapfilename = NULL; /* Close all of the files */ - Dump (f_header, f_runtime); - Dump (f_wrappers, f_runtime); - Wrapper_pretty_print (f_init, f_runtime); - Delete (f_header); - Delete (f_wrappers); - Delete (f_init); - Close (f_runtime); - Delete (f_runtime); + Dump(f_header, f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); + Delete(f_header); + Delete(f_wrappers); + Delete(f_init); + Close(f_runtime); + Delete(f_runtime); return SWIG_OK; } @@ -1232,9 +1163,8 @@ MODULA3 (): * emitBanner() * ----------------------------------------------------------------------------- */ - void emitBanner (File * f) - { - Printf (f, "\ + void emitBanner(File *f) { + Printf(f, "\ (*******************************************************************************\n\ * This file was automatically generated by SWIG (http://www.swig.org/).\n\ * Version %s\n\ @@ -1248,24 +1178,21 @@ MODULA3 (): * nativeWrapper() * ---------------------------------------------------------------------- */ - virtual int nativeWrapper (Node * n) - { - String *wrapname = Getattr (n, "wrap:name"); + virtual int nativeWrapper(Node *n) { + String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol (wrapname, n)) + if (!addSymbol(wrapname, n)) return SWIG_ERROR; - if (Getattr (n, "type")) { - Swig_save ("nativeWrapper", n, "name", NIL); - Setattr (n, "name", wrapname); + if (Getattr(n, "type")) { + Swig_save("nativeWrapper", n, "name", NIL); + Setattr(n, "name", wrapname); native_function_flag = true; - functionWrapper (n); - Swig_restore (n); + functionWrapper(n); + Swig_restore(n); native_function_flag = false; } else { - Printf (stderr, - "%s : Line %d. No return type for %%native method %s.\n", - input_file, line_number, Getattr (n, "wrap:name")); + Printf(stderr, "%s : Line %d. No return type for %%native method %s.\n", input_file, line_number, Getattr(n, "wrap:name")); } return SWIG_OK; @@ -1275,68 +1202,65 @@ MODULA3 (): * functionWrapper() * ---------------------------------------------------------------------- */ - virtual int functionWrapper (Node * n) - { - String *type = nodeType (n); - String *funcType = Getattr (n, "modula3:functype"); - String *rawname = Getattr (n, "name"); - String *symname = Getattr (n, "sym:name"); - String *capname = capitalizeFirst (symname); + virtual int functionWrapper(Node *n) { + String *type = nodeType(n); + String *funcType = Getattr(n, "modula3:functype"); + String *rawname = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + String *capname = capitalizeFirst(symname); //String *wname = Swig_name_wrapper(symname); //printf("function: %s\n", Char(symname)); //printf(" purpose: %s\n", Char(funcType)); - if (Strcmp (type, "cdecl") == 0) { + if (Strcmp(type, "cdecl") == 0) { if (funcType == NIL) { - // no wrapper needed for plain functions - emitM3RawPrototype (n, rawname, symname); - emitM3Wrapper (n, symname); - } else if (Strcmp (funcType, "method") == 0) { - Setattr (n, "modula3:funcname", capname); - emitCWrapper (n, capname); - emitM3RawPrototype (n, capname, capname); - emitM3Wrapper (n, capname); - } else if (Strcmp (funcType, "accessor") == 0) { - /* - * Generate the proxy class properties for public member variables. - * Not for enums and constants. - */ - if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { - // Capitalize the first letter in the function name - Setattr (n, "proxyfuncname", capname); - Setattr (n, "imfuncname", symname); - if (hasPrefix (capname, "Set")) { - Setattr (n, "modula3:setname", capname); - } else { - Setattr (n, "modula3:getname", capname); - } + // no wrapper needed for plain functions + emitM3RawPrototype(n, rawname, symname); + emitM3Wrapper(n, symname); + } else if (Strcmp(funcType, "method") == 0) { + Setattr(n, "modula3:funcname", capname); + emitCWrapper(n, capname); + emitM3RawPrototype(n, capname, capname); + emitM3Wrapper(n, capname); + } else if (Strcmp(funcType, "accessor") == 0) { + /* + * Generate the proxy class properties for public member variables. + * Not for enums and constants. + */ + if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { + // Capitalize the first letter in the function name + Setattr(n, "proxyfuncname", capname); + Setattr(n, "imfuncname", symname); + if (hasPrefix(capname, "Set")) { + Setattr(n, "modula3:setname", capname); + } else { + Setattr(n, "modula3:getname", capname); + } - emitCWrapper (n, capname); - emitM3RawPrototype (n, capname, capname); - emitM3Wrapper (n, capname); - //proxyClassFunctionHandler(n); - } + emitCWrapper(n, capname); + emitM3RawPrototype(n, capname, capname); + emitM3Wrapper(n, capname); + //proxyClassFunctionHandler(n); + } #ifdef DEBUG } else { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "Function type <%s> unknown.\n", Char (funcType)); + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Function type <%s> unknown.\n", Char(funcType)); #endif } - } else if ((Strcmp (type, "constructor") == 0) || - (Strcmp (type, "destructor") == 0)) { - emitCWrapper (n, capname); - emitM3RawPrototype (n, capname, capname); - emitM3Wrapper (n, capname); + } else if ((Strcmp(type, "constructor") == 0) || (Strcmp(type, "destructor") == 0)) { + emitCWrapper(n, capname); + emitM3RawPrototype(n, capname, capname); + emitM3Wrapper(n, capname); } // a Java relict #if 0 - if (!(proxy_flag && is_wrapping_class ()) && !enum_constant_flag) { - emitM3Wrapper (n, capname); + if (!(proxy_flag && is_wrapping_class()) && !enum_constant_flag) { + emitM3Wrapper(n, capname); } #endif - Delete (capname); + Delete(capname); return SWIG_OK; } @@ -1347,79 +1271,78 @@ MODULA3 (): * Generate the wrapper in C which calls C++ methods. * ---------------------------------------------------------------------- */ - virtual int emitCWrapper (Node * n, const String * wname) - { - String *rawname = Getattr (n, "name"); - String *c_return_type = NewString (""); - String *cleanup = NewString (""); - String *outarg = NewString (""); - String *body = NewString (""); - Hash *throws_hash = NewHash (); - ParmList *l = Getattr (n, "parms"); - SwigType *t = Getattr (n, "type"); - String *symname = Getattr(n,"sym:name"); + virtual int emitCWrapper(Node *n, const String *wname) { + String *rawname = Getattr(n, "name"); + String *c_return_type = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); + String *body = NewString(""); + Hash *throws_hash = NewHash(); + ParmList *l = Getattr(n, "parms"); + SwigType *t = Getattr(n, "type"); + String *symname = Getattr(n, "sym:name"); - if (!Getattr (n, "sym:overloaded")) { - if (!addSymbol (wname, n)) { - return SWIG_ERROR; + if (!Getattr(n, "sym:overloaded")) { + if (!addSymbol(wname, n)) { + return SWIG_ERROR; } } // A new wrapper function object - Wrapper *f = NewWrapper (); + Wrapper *f = NewWrapper(); /* Attach the non-standard typemaps to the parameter list. */ - Swig_typemap_attach_parms ("ctype", l, f); + Swig_typemap_attach_parms("ctype", l, f); /* Get return types */ { - String *tm = getMappedTypeNew (n, "ctype", ""); + String *tm = getMappedTypeNew(n, "ctype", ""); if (tm != NIL) { - Printf (c_return_type, "%s", tm); + Printf(c_return_type, "%s", tm); } } - bool is_void_return = (Cmp (c_return_type, "void") == 0); + bool is_void_return = (Cmp(c_return_type, "void") == 0); if (!is_void_return) { - Wrapper_add_localv (f, "cresult", c_return_type, "cresult = 0", NIL); + Wrapper_add_localv(f, "cresult", c_return_type, "cresult = 0", NIL); } - Printv (f->def, " SWIGEXPORT ", c_return_type, " ", wname, "(", NIL); + Printv(f->def, " SWIGEXPORT ", c_return_type, " ", wname, "(", NIL); // Emit all of the local variables for holding arguments. - emit_args (t, l, f); + emit_args(t, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps (l, f); - Setattr (n, "wrap:parms", l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); // Generate signature and argument conversion for C wrapper { Parm *p; - attachParameterNames (n, "tmap:name", "c:wrapname", "m3arg%d"); + attachParameterNames(n, "tmap:name", "c:wrapname", "m3arg%d"); bool gencomma = false; - for (p = skipIgnored (l, "in"); p != NULL; p = skipIgnored (p, "in")) { + for (p = skipIgnored(l, "in"); p != NULL; p = skipIgnored(p, "in")) { - String *arg = Getattr (p, "c:wrapname"); - { - /* Get the ctype types of the parameter */ - String *c_param_type = getMappedType (p, "ctype"); - // Add parameter to C function - Printv (f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL); - Delete (c_param_type); - gencomma = true; - } + String *arg = Getattr(p, "c:wrapname"); + { + /* Get the ctype types of the parameter */ + String *c_param_type = getMappedType(p, "ctype"); + // Add parameter to C function + Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL); + Delete(c_param_type); + gencomma = true; + } - // Get typemap for this argument - String *tm = getMappedType (p, "in"); - if (tm != NIL) { - addThrows (throws_hash, "in", p); - Replaceall (tm, "$input", arg); - Setattr (p, "emit:input", arg); /*??? */ - Printf (f->code, "%s\n", tm); - p = Getattr (p, "tmap:in:next"); - } else { - p = nextSibling (p); - } + // Get typemap for this argument + String *tm = getMappedType(p, "in"); + if (tm != NIL) { + addThrows(throws_hash, "in", p); + Replaceall(tm, "$input", arg); + Setattr(p, "emit:input", arg); /*??? */ + Printf(f->code, "%s\n", tm); + p = Getattr(p, "tmap:in:next"); + } else { + p = nextSibling(p); + } } } @@ -1427,17 +1350,17 @@ MODULA3 (): { Parm *p; for (p = l; p;) { - String *tm = Getattr (p, "tmap:check"); - if (tm != NIL) { - addThrows (throws_hash, "check", p); - Replaceall (tm, "$target", Getattr (p, "lname")); /* deprecated */ - Replaceall (tm, "$arg", Getattr (p, "emit:input")); /* deprecated? */ - Replaceall (tm, "$input", Getattr (p, "emit:input")); - Printv (f->code, tm, "\n", NIL); - p = Getattr (p, "tmap:check:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:check"); + if (tm != NIL) { + addThrows(throws_hash, "check", p); + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); + } else { + p = nextSibling(p); + } } } @@ -1445,17 +1368,17 @@ MODULA3 (): { Parm *p; for (p = l; p;) { - String *tm = Getattr (p, "tmap:freearg"); - if (tm != NIL) { - addThrows (throws_hash, "freearg", p); - Replaceall (tm, "$source", Getattr (p, "emit:input")); /* deprecated */ - Replaceall (tm, "$arg", Getattr (p, "emit:input")); /* deprecated? */ - Replaceall (tm, "$input", Getattr (p, "emit:input")); - Printv (cleanup, tm, "\n", NIL); - p = Getattr (p, "tmap:freearg:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:freearg"); + if (tm != NIL) { + addThrows(throws_hash, "freearg", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); + } else { + p = nextSibling(p); + } } } @@ -1463,126 +1386,122 @@ MODULA3 (): { Parm *p; for (p = l; p;) { - String *tm = Getattr (p, "tmap:argout"); - if (tm != NIL) { - addThrows (throws_hash, "argout", p); - Replaceall (tm, "$source", Getattr (p, "emit:input")); /* deprecated */ - Replaceall (tm, "$target", Getattr (p, "lname")); /* deprecated */ - Replaceall (tm, "$arg", Getattr (p, "emit:input")); /* deprecated? */ - Replaceall (tm, "$result", "cresult"); - Replaceall (tm, "$input", Getattr (p, "emit:input")); - Printv (outarg, tm, "\n", NIL); - p = Getattr (p, "tmap:argout:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:argout"); + if (tm != NIL) { + addThrows(throws_hash, "argout", p); + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* deprecated */ + Replaceall(tm, "$target", Getattr(p, "lname")); /* deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); /* deprecated? */ + Replaceall(tm, "$result", "cresult"); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); + } else { + p = nextSibling(p); + } } } // Get any Modula 3 exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr (n, "throws"))) { - Swig_typemap_attach_parms ("throws", throw_parm_list, f); + if ((throw_parm_list = Getattr(n, "throws"))) { + Swig_typemap_attach_parms("throws", throw_parm_list, f); Parm *p; - for (p = throw_parm_list; p; p = nextSibling (p)) { - addThrows (throws_hash, "throws", p); + for (p = throw_parm_list; p; p = nextSibling(p)) { + addThrows(throws_hash, "throws", p); } } - if (Cmp (nodeType (n), "constant") == 0) { + if (Cmp(nodeType(n), "constant") == 0) { // Wrapping a constant hack - Swig_save ("functionWrapper", n, "wrap:action", NIL); + Swig_save("functionWrapper", n, "wrap:action", NIL); // below based on Swig_VargetToFunction() - SwigType *ty = Swig_wrapped_var_type (Getattr (n, "type"), use_naturalvar_mode(n)); - Setattr (n, "wrap:action", - NewStringf ("result = (%s) %s;\n", SwigType_lstr (ty, 0), - Getattr (n, "value"))); + SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n)); + Setattr(n, "wrap:action", NewStringf("result = (%s) %s;\n", SwigType_lstr(ty, 0), Getattr(n, "value"))); } // Now write code to make the function call if (!native_function_flag) { - emit_action (n, f); + emit_action(n, f); } - if (Cmp (nodeType (n), "constant") == 0) { - Swig_restore (n); + if (Cmp(nodeType(n), "constant") == 0) { + Swig_restore(n); } /* Return value if necessary */ if (!native_function_flag) { - String *tm = getMappedTypeNew (n, "out", "result"); + String *tm = getMappedTypeNew(n, "out", "result"); if (tm != NIL) { - addThrows (throws_hash, "out", n); - Replaceall (tm, "$source", "result"); /* deprecated */ - Replaceall (tm, "$target", "cresult"); /* deprecated */ - Replaceall (tm, "$result", "cresult"); - Printf (f->code, "%s", tm); - if (hasContent (tm)) - Printf (f->code, "\n"); + addThrows(throws_hash, "out", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Replaceall(tm, "$target", "cresult"); /* deprecated */ + Replaceall(tm, "$result", "cresult"); + Printf(f->code, "%s", tm); + if (hasContent(tm)) + Printf(f->code, "\n"); } else { - Swig_warning (WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", - SwigType_str (t, 0), rawname); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), rawname); } } /* Output argument output code */ - Printv (f->code, outarg, NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ - Printv (f->code, cleanup, NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag (n, "feature:new")) { - String *tm = Swig_typemap_lookup_new ("newfree", n, "result", 0); + if (GetFlag(n, "feature:new")) { + String *tm = Swig_typemap_lookup_new("newfree", n, "result", 0); if (tm != NIL) { - addThrows (throws_hash, "newfree", n); - Replaceall (tm, "$source", "result"); /* deprecated */ - Printf (f->code, "%s\n", tm); + addThrows(throws_hash, "newfree", n); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ if (!native_function_flag) { - String *tm = Swig_typemap_lookup_new ("ret", n, "result", 0); + String *tm = Swig_typemap_lookup_new("ret", n, "result", 0); if (tm != NIL) { - Replaceall (tm, "$source", "result"); /* deprecated */ - Printf (f->code, "%s\n", tm); + Replaceall(tm, "$source", "result"); /* deprecated */ + Printf(f->code, "%s\n", tm); } } /* Finish C wrapper */ - Printf (f->def, ") {"); + Printf(f->def, ") {"); if (!is_void_return) - Printv (f->code, " return cresult;\n", NIL); - Printf (f->code, "}\n"); + Printv(f->code, " return cresult;\n", NIL); + Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall (f->code, "$cleanup", cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",symname); + Replaceall(f->code, "$symname", symname); if (!is_void_return) { - Replaceall (f->code, "$null", "0"); + Replaceall(f->code, "$null", "0"); } else { - Replaceall (f->code, "$null", ""); + Replaceall(f->code, "$null", ""); } /* Dump the function out */ if (!native_function_flag) { - Wrapper_print (f, f_wrappers); + Wrapper_print(f, f_wrappers); } - Setattr (n, "wrap:name", wname); + Setattr(n, "wrap:name", wname); - Delete (c_return_type); - Delete (cleanup); - Delete (outarg); - Delete (body); - Delete (throws_hash); - DelWrapper (f); + Delete(c_return_type); + Delete(cleanup); + Delete(outarg); + Delete(body); + Delete(throws_hash); + DelWrapper(f); return SWIG_OK; } @@ -1593,67 +1512,63 @@ MODULA3 (): * which is the interface to an existing C routine or a C wrapper. * ---------------------------------------------------------------------- */ - virtual int emitM3RawPrototype (Node * n, const String * cname, - const String * m3name) - { - String *im_return_type = NewString (""); + virtual int emitM3RawPrototype(Node *n, const String *cname, const String *m3name) { + String *im_return_type = NewString(""); //String *symname = Getattr(n,"sym:name"); - ParmList *l = Getattr (n, "parms"); + ParmList *l = Getattr(n, "parms"); /* Attach the non-standard typemaps to the parameter list. */ - Swig_typemap_attach_parms ("m3rawinmode", l, NULL); - Swig_typemap_attach_parms ("m3rawintype", l, NULL); + Swig_typemap_attach_parms("m3rawinmode", l, NULL); + Swig_typemap_attach_parms("m3rawintype", l, NULL); /* Get return types */ bool has_return; { - String *tm = getMappedTypeNew (n, "m3rawrettype", ""); + String *tm = getMappedTypeNew(n, "m3rawrettype", ""); if (tm != NIL) { - Printf (im_return_type, "%s", tm); + Printf(im_return_type, "%s", tm); } - has_return = hasContent (tm); + has_return = hasContent(tm); } /* cname is the original name if 'n' denotes a C function and it is the relabeled name (sym:name) if 'n' denotes a C++ method or similar */ - m3raw_intf.enterBlock (no_block); - Printf (m3raw_intf.f, "\n<* EXTERNAL %s *>\nPROCEDURE %s (", - cname, m3name); + m3raw_intf.enterBlock(no_block); + Printf(m3raw_intf.f, "\n<* EXTERNAL %s *>\nPROCEDURE %s (", cname, m3name); // Generate signature for raw interface { Parm *p; writeArgState state; - attachParameterNames (n, "tmap:rawinname", "modula3:rawname", "arg%d"); - for (p = skipIgnored (l, "m3rawintype"); p != NULL; - p = skipIgnored (p, "m3rawintype")) { + attachParameterNames(n, "tmap:rawinname", "modula3:rawname", "arg%d"); + for (p = skipIgnored(l, "m3rawintype"); p != NULL; p = skipIgnored(p, "m3rawintype")) { - /* Get argument passing mode, should be one of VALUE, VAR, READONLY */ - String *mode = Getattr (p, "tmap:m3rawinmode"); - String *argname = Getattr (p, "modula3:rawname"); - String *im_param_type = getMappedType (p, "m3rawintype"); - addImports (m3raw_intf.import, "m3rawintype", p); + /* Get argument passing mode, should be one of VALUE, VAR, READONLY */ + String *mode = Getattr(p, "tmap:m3rawinmode"); + String *argname = Getattr(p, "modula3:rawname"); + String *im_param_type = getMappedType(p, "m3rawintype"); + addImports(m3raw_intf.import, "m3rawintype", p); - writeArg (m3raw_intf.f, state, mode, argname, im_param_type, NIL); - if (im_param_type != NIL) { - p = Getattr (p, "tmap:m3rawintype:next"); - } else { - p = nextSibling (p); - } + writeArg(m3raw_intf.f, state, mode, argname, im_param_type, NIL); + if (im_param_type != NIL) { + p = Getattr(p, "tmap:m3rawintype:next"); + } else { + p = nextSibling(p); + } } - writeArg (m3raw_intf.f, state, NIL, NIL, NIL, NIL); + writeArg(m3raw_intf.f, state, NIL, NIL, NIL, NIL); } /* Finish M3 raw prototype */ - Printf (m3raw_intf.f, ")"); + Printf(m3raw_intf.f, ")"); // neither a C wrapper nor a plain C function may throw an exception //generateThrowsClause(throws_hash, m3raw_intf.f); if (has_return) { - Printf (m3raw_intf.f, ": %s", im_return_type); + Printf(m3raw_intf.f, ": %s", im_return_type); } - Printf (m3raw_intf.f, ";\n"); + Printf(m3raw_intf.f, ";\n"); - Delete (im_return_type); + Delete(im_return_type); return SWIG_OK; } @@ -1661,9 +1576,8 @@ MODULA3 (): * variableWrapper() * ----------------------------------------------------------------------- */ - virtual int variableWrapper (Node * n) - { - Language::variableWrapper (n); + virtual int variableWrapper(Node *n) { + Language::variableWrapper(n); return SWIG_OK; } @@ -1671,24 +1585,22 @@ MODULA3 (): * globalvariableHandler() * ----------------------------------------------------------------------- */ - virtual int globalvariableHandler (Node * n) - { - SwigType *t = Getattr (n, "type"); + virtual int globalvariableHandler(Node *n) { + SwigType *t = Getattr(n, "type"); String *tm; // Get the variable type - if ((tm = getMappedTypeNew (n, "m3wraptype", ""))) { - substituteClassname (t, tm); + if ((tm = getMappedTypeNew(n, "m3wraptype", ""))) { + substituteClassname(t, tm); } - variable_name = Getattr (n, "sym:name"); - variable_type = Copy (tm); + variable_name = Getattr(n, "sym:name"); + variable_type = Copy(tm); // Get the variable type expressed in terms of Modula 3 equivalents of C types - if ((tm = getMappedTypeNew (n, "m3rawtype", ""))) { - m3raw_intf.enterBlock (no_block); - Printf (m3raw_intf.f, "\n<* EXTERNAL *> VAR %s: %s;\n", variable_name, - tm); + if ((tm = getMappedTypeNew(n, "m3rawtype", ""))) { + m3raw_intf.enterBlock(no_block); + Printf(m3raw_intf.f, "\n<* EXTERNAL *> VAR %s: %s;\n", variable_name, tm); } // Output the property's accessor methods /* @@ -1697,26 +1609,22 @@ MODULA3 (): global_variable_flag = false; */ - Printf (m3wrap_impl.f, "\n\n"); + Printf(m3wrap_impl.f, "\n\n"); //return ret; return 1; } - long getConstNumeric (Node * n) - { - String *constnumeric = Getfeature (n, "constnumeric"); - String *name = Getattr (n, "name"); + long getConstNumeric(Node *n) { + String *constnumeric = Getfeature(n, "constnumeric"); + String *name = Getattr(n, "name"); long numvalue; if (constnumeric == NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "Feature 'constnumeric' is necessary to obtain value of %s.\n", - name); + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Feature 'constnumeric' is necessary to obtain value of %s.\n", name); return 0; - } else if (!strToL (constnumeric, numvalue)) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "The feature 'constnumeric' of %s specifies value <%s> which is not an integer constant.\n", - name, constnumeric); + } else if (!strToL(constnumeric, numvalue)) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, + "The feature 'constnumeric' of %s specifies value <%s> which is not an integer constant.\n", name, constnumeric); return 0; } else { return numvalue; @@ -1729,59 +1637,56 @@ MODULA3 (): * Considers node as an integer constant definition * and generate a Modula 3 constant definition. * ------------------------------------------------------------------------ */ - void generateIntConstant (Node * n, String * name) - { - String *value = Getattr (n, "value"); - String *type = Getfeature (n, "modula3:constint:type"); - String *conv = Getfeature (n, "modula3:constint:conv"); + void generateIntConstant(Node *n, String *name) { + String *value = Getattr(n, "value"); + String *type = Getfeature(n, "modula3:constint:type"); + String *conv = Getfeature(n, "modula3:constint:conv"); if (name == NIL) { - name = Getattr (n, "sym:name"); + name = Getattr(n, "sym:name"); } long numvalue; - bool isSimpleNum = strToL (value, numvalue); + bool isSimpleNum = strToL(value, numvalue); if (!isSimpleNum) { - numvalue = getConstNumeric (n); + numvalue = getConstNumeric(n); } String *m3value; - if ((conv == NIL) || - ((Strcmp (conv, "set:int") != 0) && - (Strcmp (conv, "int:set") != 0))) { + if ((conv == NIL) || ((Strcmp(conv, "set:int") != 0) && (Strcmp(conv, "int:set") != 0))) { /* The original value of the constant has precedence over 'constnumeric' feature since we like to keep the style (that is the base) of simple numeric constants */ if (isSimpleNum) { - if (hasPrefix (value, "0x")) { - m3value = NewStringf ("16_%s", Char (value) + 2); - } else if ((Len (value) > 1) && (*Char (value) == '0')) { - m3value = NewStringf ("8_%s", Char (value) + 1); - } else { - m3value = Copy (value); - } - /* If we cannot easily obtain the value of a numeric constant, - we use the results given by a C compiler. */ + if (hasPrefix(value, "0x")) { + m3value = NewStringf("16_%s", Char(value) + 2); + } else if ((Len(value) > 1) && (*Char(value) == '0')) { + m3value = NewStringf("8_%s", Char(value) + 1); + } else { + m3value = Copy(value); + } + /* If we cannot easily obtain the value of a numeric constant, + we use the results given by a C compiler. */ } else { - m3value = Copy (Getfeature (n, "constnumeric")); + m3value = Copy(Getfeature(n, "constnumeric")); } } else { // if the value can't be converted, it is ignored - if (convertInt (numvalue, numvalue, conv)) { - m3value = NewStringf ("%d", numvalue); + if (convertInt(numvalue, numvalue, conv)) { + m3value = NewStringf("%d", numvalue); } else { - m3value = NIL; + m3value = NIL; } } if (m3value != NIL) { - m3wrap_intf.enterBlock (constant); - Printf (m3wrap_intf.f, "%s", name); - if (hasContent (type)) { - Printf (m3wrap_intf.f, ": %s", type); + m3wrap_intf.enterBlock(constant); + Printf(m3wrap_intf.f, "%s", name); + if (hasContent(type)) { + Printf(m3wrap_intf.f, ": %s", type); } - Printf (m3wrap_intf.f, " = %s;\n", m3value); - Delete (m3value); + Printf(m3wrap_intf.f, " = %s;\n", m3value); + Delete(m3value); } } @@ -1791,39 +1696,36 @@ MODULA3 (): * Considers node as a set constant definition * and generate a Modula 3 constant definition. * ------------------------------------------------------------------------ */ - void generateSetConstant (Node * n, String * name) - { - String *value = Getattr (n, "value"); - String *type = Getfeature (n, "modula3:constset:type"); - String *setname = Getfeature (n, "modula3:constset:set"); - String *basename = Getfeature (n, "modula3:constset:base"); - String *conv = Getfeature (n, "modula3:constset:conv"); + void generateSetConstant(Node *n, String *name) { + String *value = Getattr(n, "value"); + String *type = Getfeature(n, "modula3:constset:type"); + String *setname = Getfeature(n, "modula3:constset:set"); + String *basename = Getfeature(n, "modula3:constset:base"); + String *conv = Getfeature(n, "modula3:constset:conv"); - m3wrap_intf.enterBlock (constant); + m3wrap_intf.enterBlock(constant); - Printf (m3wrap_intf.f, "%s", name); + Printf(m3wrap_intf.f, "%s", name); if (type != NIL) { - Printf (m3wrap_intf.f, ":%s ", type); + Printf(m3wrap_intf.f, ":%s ", type); } - Printf (m3wrap_intf.f, " = %s{", setname); + Printf(m3wrap_intf.f, " = %s{", setname); long numvalue = 0; - if (!strToL (value, numvalue)) { - numvalue = getConstNumeric (n); + if (!strToL(value, numvalue)) { + numvalue = getConstNumeric(n); } - convertInt (numvalue, numvalue, conv); + convertInt(numvalue, numvalue, conv); - bool isIntType = Strcmp (basename, "CARDINAL") == 0; + bool isIntType = Strcmp(basename, "CARDINAL") == 0; Hash *items = NIL; if (!isIntType) { - Hash *enumeration = Getattr (enumeration_coll, basename); + Hash *enumeration = Getattr(enumeration_coll, basename); if (enumeration == NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "There is no enumeration <%s> as needed for the set.\n", - setname); - isIntType = true; + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "There is no enumeration <%s> as needed for the set.\n", setname); + isIntType = true; } else { - items = Getattr (enumeration, "items"); + items = Getattr(enumeration, "items"); } } @@ -1831,101 +1733,91 @@ MODULA3 (): int bitpos = 0; while (numvalue > 0) { if ((numvalue & 1) != 0) { - if (isIntType) { - if (gencomma) { - Printv (m3wrap_intf.f, ",", NIL); - } - gencomma = true; - Printf (m3wrap_intf.f, "%d", bitpos); - } else { - char bitval[15]; - sprintf (bitval, "%d", bitpos); - String *bitname = Getattr (items, bitval); - if (bitname == NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, - "Enumeration <%s> has no value <%s>.\n", setname, - bitval); - } else { - if (gencomma) { - Printv (m3wrap_intf.f, ",", NIL); - } - gencomma = true; - Printf (m3wrap_intf.f, "%s.%s", basename, bitname); - } - } + if (isIntType) { + if (gencomma) { + Printv(m3wrap_intf.f, ",", NIL); + } + gencomma = true; + Printf(m3wrap_intf.f, "%d", bitpos); + } else { + char bitval[15]; + sprintf(bitval, "%d", bitpos); + String *bitname = Getattr(items, bitval); + if (bitname == NIL) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Enumeration <%s> has no value <%s>.\n", setname, bitval); + } else { + if (gencomma) { + Printv(m3wrap_intf.f, ",", NIL); + } + gencomma = true; + Printf(m3wrap_intf.f, "%s.%s", basename, bitname); + } + } } numvalue >>= 1; bitpos++; } - Printf (m3wrap_intf.f, "};\n"); + Printf(m3wrap_intf.f, "};\n"); } - void generateConstant (Node * n) - { + void generateConstant(Node *n) { // any of the special interpretation disables the default behaviour - String *enumitem = Getfeature (n, "modula3:enumitem:name"); - String *constset = Getfeature (n, "modula3:constset:name"); - String *constint = Getfeature (n, "modula3:constint:name"); - if (hasContent (enumitem) || - hasContent (constset) || hasContent (constint)) { - if (hasContent (constset)) { - generateSetConstant (n, constset); + String *enumitem = Getfeature(n, "modula3:enumitem:name"); + String *constset = Getfeature(n, "modula3:constset:name"); + String *constint = Getfeature(n, "modula3:constint:name"); + if (hasContent(enumitem) || hasContent(constset) || hasContent(constint)) { + if (hasContent(constset)) { + generateSetConstant(n, constset); } - if (hasContent (constint)) { - generateIntConstant (n, constint); + if (hasContent(constint)) { + generateIntConstant(n, constint); } } else { - String *value = Getattr (n, "value"); - String *name = Getattr (n, "sym:name"); + String *value = Getattr(n, "value"); + String *name = Getattr(n, "sym:name"); if (name == NIL) { - name = Getattr (n, "name"); + name = Getattr(n, "name"); } - m3wrap_intf.enterBlock (constant); - Printf (m3wrap_intf.f, "%s = %s;\n", name, value); + m3wrap_intf.enterBlock(constant); + Printf(m3wrap_intf.f, "%s = %s;\n", name, value); } } #if 0 - void generateEnumerationItem (const String * name, const String * value, - int numvalue) - { - String *oldsymname = Getattr (enumeration_items, value); + void generateEnumerationItem(const String *name, const String *value, int numvalue) { + String *oldsymname = Getattr(enumeration_items, value); if (oldsymname != NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "The value <%s> is already assigned to <%s>.\n", value, - oldsymname); + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldsymname); } - Setattr (enumeration_items, value, name); + Setattr(enumeration_items, value, name); if (enumeration_max < numvalue) { enumeration_max = numvalue; } } #endif - void emitEnumeration (File * file, String * name, Node * n) - { - Printf (file, "%s = {", name); + void emitEnumeration(File *file, String *name, Node *n) { + Printf(file, "%s = {", name); int i; bool gencomma = false; - int max = aToL (Getattr (n, "max")); - Hash *items = Getattr (n, "items"); + int max = aToL(Getattr(n, "max")); + Hash *items = Getattr(n, "items"); for (i = 0; i <= max; i++) { if (gencomma) { - Printf (file, ","); + Printf(file, ","); } - Printf (file, "\n"); + Printf(file, "\n"); gencomma = true; char numstr[15]; - sprintf (numstr, "%d", i); - String *name = Getattr (items, numstr); + sprintf(numstr, "%d", i); + String *name = Getattr(items, numstr); if (name != NIL) { - Printv (file, name, NIL); + Printv(file, name, NIL); } else { - Printf (file, "Dummy%d", i); + Printf(file, "Dummy%d", i); } } - Printf (file, "\n};\n"); + Printf(file, "\n};\n"); } /* ----------------------------------------------------------------------- @@ -1934,9 +1826,8 @@ MODULA3 (): * Handles constants and enumeration items. * ------------------------------------------------------------------------ */ - virtual int constantWrapper (Node * n) - { - generateConstant (n); + virtual int constantWrapper(Node *n) { + generateConstant(n); return SWIG_OK; } @@ -1946,13 +1837,12 @@ MODULA3 (): * enumDeclaration() * ----------------------------------------------------------------------------- */ - virtual int enumDeclaration (Node * n) - { - String *symname = nameToModula3 (Getattr (n, "sym:name"), true); - enumerationStart (symname); - int result = Language::enumDeclaration (n); - enumerationStop (); - Delete (symname); + virtual int enumDeclaration(Node *n) { + String *symname = nameToModula3(Getattr(n, "sym:name"), true); + enumerationStart(symname); + int result = Language::enumDeclaration(n); + enumerationStop(); + Delete(symname); return result; } #endif @@ -1961,9 +1851,8 @@ MODULA3 (): * enumvalueDeclaration() * ----------------------------------------------------------------------------- */ - virtual int enumvalueDeclaration (Node * n) - { - generateConstant (n); + virtual int enumvalueDeclaration(Node *n) { + generateConstant(n); /* This call would continue processing in the constantWrapper which cannot handle values like "RED+1". @@ -1990,360 +1879,320 @@ MODULA3 (): * * ----------------------------------------------------------------------------- */ - virtual int pragmaDirective (Node * n) - { + virtual int pragmaDirective(Node *n) { if (!ImportMode) { - String *lang = Getattr (n, "lang"); - String *code = Getattr (n, "name"); - String *value = Getattr (n, "value"); + String *lang = Getattr(n, "lang"); + String *code = Getattr(n, "name"); + String *value = Getattr(n, "value"); - if (Strcmp (lang, "modula3") == 0) { + if (Strcmp(lang, "modula3") == 0) { - String *strvalue = NewString (value); - Replaceall (strvalue, "\\\"", "\""); + String *strvalue = NewString(value); + Replaceall(strvalue, "\\\"", "\""); /* bool isEnumItem = Strcmp(code, "enumitem") == 0; bool isSetItem = Strcmp(code, "setitem") == 0; */ - if (Strcmp (code, "imclassbase") == 0) { - Delete (m3raw_baseclass); - m3raw_baseclass = Copy (strvalue); - } else if (Strcmp (code, "imclassclassmodifiers") == 0) { - Delete (m3raw_class_modifiers); - m3raw_class_modifiers = Copy (strvalue); - } else if (Strcmp (code, "imclasscode") == 0) { - Printf (m3raw_intf.f, "%s\n", strvalue); - } else if (Strcmp (code, "imclassimports") == 0) { - Delete (m3raw_imports); - m3raw_imports = Copy (strvalue); - } else if (Strcmp (code, "imclassinterfaces") == 0) { - Delete (m3raw_interfaces); - m3raw_interfaces = Copy (strvalue); - } else if (Strcmp (code, "modulebase") == 0) { - Delete (module_baseclass); - module_baseclass = Copy (strvalue); - } else if (Strcmp (code, "moduleclassmodifiers") == 0) { - Delete (m3wrap_modifiers); - m3wrap_modifiers = Copy (strvalue); - } else if (Strcmp (code, "modulecode") == 0) { - Printf (m3wrap_impl.f, "%s\n", strvalue); - } else if (Strcmp (code, "moduleimports") == 0) { - Delete (module_imports); - module_imports = Copy (strvalue); - } else if (Strcmp (code, "moduleinterfaces") == 0) { - Delete (module_interfaces); - module_interfaces = Copy (strvalue); - } else if (Strcmp (code, "unsafe") == 0) { - unsafe_module = true; - } else if (Strcmp (code, "library") == 0) { - if (targetlibrary != NULL) { - Delete (targetlibrary); - } - targetlibrary = Copy (strvalue); - } else if (Strcmp (code, "enumitem") == 0) { - } else if (Strcmp (code, "constset") == 0) { - } else if (Strcmp (code, "constint") == 0) { - } else if (Strcmp (code, "makesetofenum") == 0) { - m3wrap_intf.enterBlock (blocktype); - Printf (m3wrap_intf.f, "%sSet = SET OF %s;\n", value, value); - } else { - Swig_warning (WARN_MODULA3_UNKNOWN_PRAGMA, input_file, line_number, - "Unrecognized pragma <%s>.\n", code); - } - Delete (strvalue); + if (Strcmp(code, "imclassbase") == 0) { + Delete(m3raw_baseclass); + m3raw_baseclass = Copy(strvalue); + } else if (Strcmp(code, "imclassclassmodifiers") == 0) { + Delete(m3raw_class_modifiers); + m3raw_class_modifiers = Copy(strvalue); + } else if (Strcmp(code, "imclasscode") == 0) { + Printf(m3raw_intf.f, "%s\n", strvalue); + } else if (Strcmp(code, "imclassimports") == 0) { + Delete(m3raw_imports); + m3raw_imports = Copy(strvalue); + } else if (Strcmp(code, "imclassinterfaces") == 0) { + Delete(m3raw_interfaces); + m3raw_interfaces = Copy(strvalue); + } else if (Strcmp(code, "modulebase") == 0) { + Delete(module_baseclass); + module_baseclass = Copy(strvalue); + } else if (Strcmp(code, "moduleclassmodifiers") == 0) { + Delete(m3wrap_modifiers); + m3wrap_modifiers = Copy(strvalue); + } else if (Strcmp(code, "modulecode") == 0) { + Printf(m3wrap_impl.f, "%s\n", strvalue); + } else if (Strcmp(code, "moduleimports") == 0) { + Delete(module_imports); + module_imports = Copy(strvalue); + } else if (Strcmp(code, "moduleinterfaces") == 0) { + Delete(module_interfaces); + module_interfaces = Copy(strvalue); + } else if (Strcmp(code, "unsafe") == 0) { + unsafe_module = true; + } else if (Strcmp(code, "library") == 0) { + if (targetlibrary != NULL) { + Delete(targetlibrary); + } + targetlibrary = Copy(strvalue); + } else if (Strcmp(code, "enumitem") == 0) { + } else if (Strcmp(code, "constset") == 0) { + } else if (Strcmp(code, "constint") == 0) { + } else if (Strcmp(code, "makesetofenum") == 0) { + m3wrap_intf.enterBlock(blocktype); + Printf(m3wrap_intf.f, "%sSet = SET OF %s;\n", value, value); + } else { + Swig_warning(WARN_MODULA3_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", code); + } + Delete(strvalue); } } - return Language::pragmaDirective (n); + return Language::pragmaDirective(n); } - void Setfeature (Node * n, const char *feature, const String * value, - bool warn = false) { + void Setfeature(Node *n, const char *feature, const String *value, bool warn = false) { //printf("tag feature <%s> with value <%s>\n", feature, Char(value)); - String *attr = NewStringf ("feature:%s", feature); - if ((Setattr (n, attr, value) != 0) && warn) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "Feature <%s> of %s did already exist.\n", feature, - Getattr (n, "name")); + String *attr = NewStringf("feature:%s", feature); + if ((Setattr(n, attr, value) != 0) && warn) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Feature <%s> of %s did already exist.\n", feature, Getattr(n, "name")); } - Delete (attr); + Delete(attr); } - String *Getfeature (Node * n, const char *feature) - { + String *Getfeature(Node *n, const char *feature) { //printf("retrieve feature <%s> with value <%s>\n", feature, Char(value)); - String *attr = NewStringf ("feature:%s", feature); - String *result = Getattr (n, attr); - Delete (attr); + String *attr = NewStringf("feature:%s", feature); + String *result = Getattr(n, attr); + Delete(attr); return result; } - bool convertInt (long in, long &out, const String * mode) - { - if ((mode == NIL) || - (Strcmp (mode, "int:int") == 0) || (Strcmp (mode, "set:set") == 0)) { + bool convertInt(long in, long &out, const String *mode) { + if ((mode == NIL) || (Strcmp(mode, "int:int") == 0) || (Strcmp(mode, "set:set") == 0)) { out = in; return true; - } else if (Strcmp (mode, "set:int") == 0) { - return log2 (in, out); - } else if (Strcmp (mode, "int:set") == 0) { + } else if (Strcmp(mode, "set:int") == 0) { + return log2(in, out); + } else if (Strcmp(mode, "int:set") == 0) { out = 1L << in; - return unsigned (in) < (sizeof (out) * 8); + return unsigned (in) < (sizeof(out) * 8); } else { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, - "Unknown integer conversion method <%s>.\n", mode); + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Unknown integer conversion method <%s>.\n", mode); return false; } } - void collectEnumerations (Hash * enums, Node * n) - { - Node *child = firstChild (n); + void collectEnumerations(Hash *enums, Node *n) { + Node *child = firstChild(n); while (child != NIL) { - String *name = Getattr (child, "name"); - const bool isConstant = Strcmp (nodeType (child), "constant") == 0; - const bool isEnumItem = Strcmp (nodeType (child), "enumitem") == 0; + String *name = Getattr(child, "name"); + const bool isConstant = Strcmp(nodeType(child), "constant") == 0; + const bool isEnumItem = Strcmp(nodeType(child), "enumitem") == 0; if (isConstant || isEnumItem) { //printf("%s%s name %s\n", isConstant?"constant":"", isEnumItem?"enumitem":"", Char(name)); - { - String *m3name = Getfeature (child, "modula3:enumitem:name"); - String *m3enum = Getfeature (child, "modula3:enumitem:enum"); - String *conv = Getfeature (child, "modula3:enumitem:conv"); + { + String *m3name = Getfeature(child, "modula3:enumitem:name"); + String *m3enum = Getfeature(child, "modula3:enumitem:enum"); + String *conv = Getfeature(child, "modula3:enumitem:conv"); - if (m3enum != NIL) { + if (m3enum != NIL) { //printf("m3enum %s\n", Char(m3enum)); - if (m3name == NIL) { - m3name = name; - } + if (m3name == NIL) { + m3name = name; + } - long max = -1; - Hash *items; - Hash *enumnode = Getattr (enums, m3enum); - if (enumnode == NIL) { - enumnode = NewHash (); - items = NewHash (); - Setattr (enumnode, "items", items); - Setattr (enums, m3enum, enumnode); - } else { - String *maxstr = Getattr (enumnode, "max"); - if (maxstr != NIL) { - max = aToL (maxstr); - } - items = Getattr (enumnode, "items"); - } - long numvalue; - String *value = Getattr (child, "value"); + long max = -1; + Hash *items; + Hash *enumnode = Getattr(enums, m3enum); + if (enumnode == NIL) { + enumnode = NewHash(); + items = NewHash(); + Setattr(enumnode, "items", items); + Setattr(enums, m3enum, enumnode); + } else { + String *maxstr = Getattr(enumnode, "max"); + if (maxstr != NIL) { + max = aToL(maxstr); + } + items = Getattr(enumnode, "items"); + } + long numvalue; + String *value = Getattr(child, "value"); //printf("value: %s\n", Char(value)); - if ((value == NIL) || (!strToL (value, numvalue))) { - value = Getattr (child, "enumvalue"); - if ((value == NIL) || (!evalExpr (value, numvalue))) { - numvalue = getConstNumeric (child); - } + if ((value == NIL) || (!strToL(value, numvalue))) { + value = Getattr(child, "enumvalue"); + if ((value == NIL) || (!evalExpr(value, numvalue))) { + numvalue = getConstNumeric(child); + } //printf("constnumeric: %s\n", Char(value)); - } - Setattr (constant_values, name, NewStringf ("%d", numvalue)); - if (convertInt (numvalue, numvalue, conv)) { - String *newvalue = NewStringf ("%d", numvalue); - String *oldname = Getattr (items, newvalue); - if (oldname != NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, - "The value <%s> is already assigned to <%s>.\n", - value, oldname); - } + } + Setattr(constant_values, name, NewStringf("%d", numvalue)); + if (convertInt(numvalue, numvalue, conv)) { + String *newvalue = NewStringf("%d", numvalue); + String *oldname = Getattr(items, newvalue); + if (oldname != NIL) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "The value <%s> is already assigned to <%s>.\n", value, oldname); + } //printf("items %lx, set %s = %s\n", (long) items, Char(newvalue), Char(m3name)); - Setattr (items, newvalue, m3name); - if (max < numvalue) { - max = numvalue; - } - Setattr (enumnode, "max", NewStringf ("%d", max)); - } - } - } + Setattr(items, newvalue, m3name); + if (max < numvalue) { + max = numvalue; + } + Setattr(enumnode, "max", NewStringf("%d", max)); + } + } + } } - collectEnumerations (enums, child); - child = nextSibling (child); + collectEnumerations(enums, child); + child = nextSibling(child); } } - enum const_pragma_type - { cpt_none, cpt_constint, cpt_constset, cpt_enumitem }; + enum const_pragma_type { cpt_none, cpt_constint, cpt_constset, cpt_enumitem }; - struct const_id_pattern - { + struct const_id_pattern { String *prefix, *parentEnum; }; - void tagConstants (Node * first, String * parentEnum, - const const_id_pattern & pat, const String * pragma, - List * convdesc) - { + void tagConstants(Node *first, String *parentEnum, const const_id_pattern & pat, const String *pragma, List *convdesc) { Node *n = first; while (n != NIL) { - String *name = getQualifiedName (n); - bool isConstant = Strcmp (nodeType (n), "constant") == 0; - bool isEnumItem = Strcmp (nodeType (n), "enumitem") == 0; - if ((isConstant || isEnumItem) && - ((pat.prefix == NIL) || (hasPrefix (name, pat.prefix))) && - ((pat.parentEnum == NIL) || ((parentEnum != NIL) - && (Strcmp (pat.parentEnum, parentEnum) - == 0)))) { - //printf("tag %s\n", Char(name)); - String *srctype = Getitem (convdesc, 1); - String *relationstr = Getitem (convdesc, 3); - List *relationdesc = Split (relationstr, ',', 2); + String *name = getQualifiedName(n); + bool isConstant = Strcmp(nodeType(n), "constant") == 0; + bool isEnumItem = Strcmp(nodeType(n), "enumitem") == 0; + if ((isConstant || isEnumItem) && ((pat.prefix == NIL) || (hasPrefix(name, pat.prefix))) && ((pat.parentEnum == NIL) || ((parentEnum != NIL) + && + (Strcmp + (pat.parentEnum, parentEnum) + == 0)))) { + //printf("tag %s\n", Char(name)); + String *srctype = Getitem(convdesc, 1); + String *relationstr = Getitem(convdesc, 3); + List *relationdesc = Split(relationstr, ',', 2); - // transform name from C to Modula3 style - String *srcstyle = NIL; - String *newprefix = NIL; - { - //printf("name conversion <%s>\n", Char(Getitem(convdesc,2))); - List *namedesc = Split (Getitem (convdesc, 2), ',', INT_MAX); - Iterator nameit = First (namedesc); - for (; nameit.item != NIL; nameit = Next (nameit)) { - List *nameassign = Split (nameit.item, '=', 2); - String *tag = Getitem (nameassign, 0); - String *data = Getitem (nameassign, 1); - //printf("name conv <%s> = <%s>\n", Char(tag), Char(data)); - if (Strcmp (tag, "srcstyle") == 0) { - srcstyle = Copy (data); - } else if (Strcmp (tag, "prefix") == 0) { - newprefix = Copy (data); - } else { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, - "Unknown name conversion tag <%s> with value <%s>.\n", - tag, data); - } - Delete (nameassign); - }; - Delete (namedesc); - } - const char *stem = Char (name); - if (pat.prefix != NIL) { - //printf("pat.prefix %s for %s\n", Char(pat.prefix), Char(name)); - stem += Len (pat.prefix); - } - String *newname; - if (Strcmp (srcstyle, "underscore") == 0) { - if (newprefix != NIL) { - String *newstem = nameToModula3 (stem, true); - newname = NewStringf ("%s%s", newprefix, newstem); - Delete (newstem); - } else { - newname = nameToModula3 (stem, true); - } - } else { - if (srcstyle != NIL) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, "Unknown C identifier style <%s>.\n", - srcstyle); - } - newname = Copy (name); - } + // transform name from C to Modula3 style + String *srcstyle = NIL; + String *newprefix = NIL; + { + //printf("name conversion <%s>\n", Char(Getitem(convdesc,2))); + List *namedesc = Split(Getitem(convdesc, 2), ',', INT_MAX); + Iterator nameit = First(namedesc); + for (; nameit.item != NIL; nameit = Next(nameit)) { + List *nameassign = Split(nameit.item, '=', 2); + String *tag = Getitem(nameassign, 0); + String *data = Getitem(nameassign, 1); + //printf("name conv <%s> = <%s>\n", Char(tag), Char(data)); + if (Strcmp(tag, "srcstyle") == 0) { + srcstyle = Copy(data); + } else if (Strcmp(tag, "prefix") == 0) { + newprefix = Copy(data); + } else { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Unknown name conversion tag <%s> with value <%s>.\n", tag, data); + } + Delete(nameassign); + }; + Delete(namedesc); + } + const char *stem = Char(name); + if (pat.prefix != NIL) { + //printf("pat.prefix %s for %s\n", Char(pat.prefix), Char(name)); + stem += Len(pat.prefix); + } + String *newname; + if (Strcmp(srcstyle, "underscore") == 0) { + if (newprefix != NIL) { + String *newstem = nameToModula3(stem, true); + newname = NewStringf("%s%s", newprefix, newstem); + Delete(newstem); + } else { + newname = nameToModula3(stem, true); + } + } else { + if (srcstyle != NIL) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Unknown C identifier style <%s>.\n", srcstyle); + } + newname = Copy(name); + } - if (Strcmp (pragma, "enumitem") == 0) { - if (Len (relationdesc) != 1) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, "Expected , got <%s>.\n", - relationstr); - } - Setfeature (n, "modula3:enumitem:name", newname, true); - Setfeature (n, "modula3:enumitem:enum", relationstr, true); - Setfeature (n, "modula3:enumitem:conv", - NewStringf ("%s:int", srctype), true); - } else if (Strcmp (pragma, "constint") == 0) { - if (Len (relationdesc) != 1) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, "Expected , got <%s>.\n", - relationstr); - } - Setfeature (n, "modula3:constint:name", newname, true); - Setfeature (n, "modula3:constint:type", Getitem (relationdesc, 0), - true); - Setfeature (n, "modula3:constint:conv", - NewStringf ("%s:int", srctype), true); - } else if (Strcmp (pragma, "constset") == 0) { - if (Len (relationdesc) != 2) { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, - "Expected , got <%s>.\n", - relationstr); - } - String *settype = Getitem (relationdesc, 0); - Setfeature (n, "modula3:constset:name", newname, true); - //Setfeature(n,"modula3:constset:type",settype,true); - Setfeature (n, "modula3:constset:set", settype, true); - Setfeature (n, "modula3:constset:base", Getitem (relationdesc, 1), - true); - Setfeature (n, "modula3:constset:conv", - NewStringf ("%s:set", srctype), true); - } + if (Strcmp(pragma, "enumitem") == 0) { + if (Len(relationdesc) != 1) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Expected , got <%s>.\n", relationstr); + } + Setfeature(n, "modula3:enumitem:name", newname, true); + Setfeature(n, "modula3:enumitem:enum", relationstr, true); + Setfeature(n, "modula3:enumitem:conv", NewStringf("%s:int", srctype), true); + } else if (Strcmp(pragma, "constint") == 0) { + if (Len(relationdesc) != 1) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Expected , got <%s>.\n", relationstr); + } + Setfeature(n, "modula3:constint:name", newname, true); + Setfeature(n, "modula3:constint:type", Getitem(relationdesc, 0), true); + Setfeature(n, "modula3:constint:conv", NewStringf("%s:int", srctype), true); + } else if (Strcmp(pragma, "constset") == 0) { + if (Len(relationdesc) != 2) { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Expected , got <%s>.\n", relationstr); + } + String *settype = Getitem(relationdesc, 0); + Setfeature(n, "modula3:constset:name", newname, true); + //Setfeature(n,"modula3:constset:type",settype,true); + Setfeature(n, "modula3:constset:set", settype, true); + Setfeature(n, "modula3:constset:base", Getitem(relationdesc, 1), true); + Setfeature(n, "modula3:constset:conv", NewStringf("%s:set", srctype), true); + } - Delete (newname); - Delete (relationdesc); + Delete(newname); + Delete(relationdesc); } - if (Strcmp (nodeType (n), "enum") == 0) { - //printf("explore enum %s, qualification %s\n", Char(name), Char(Swig_symbol_qualified(n))); - tagConstants (firstChild (n), name, pat, pragma, convdesc); + if (Strcmp(nodeType(n), "enum") == 0) { + //printf("explore enum %s, qualification %s\n", Char(name), Char(Swig_symbol_qualified(n))); + tagConstants(firstChild(n), name, pat, pragma, convdesc); } else { - tagConstants (firstChild (n), NIL, pat, pragma, convdesc); + tagConstants(firstChild(n), NIL, pat, pragma, convdesc); } - n = nextSibling (n); + n = nextSibling(n); } } - void scanForConstPragmas (Node * n) - { - Node *child = firstChild (n); + void scanForConstPragmas(Node *n) { + Node *child = firstChild(n); while (child != NIL) { - const String *type = nodeType (child); - if (Strcmp (type, "pragma") == 0) { - const String *lang = Getattr (child, "lang"); - const String *code = Getattr (child, "name"); - String *value = Getattr (child, "value"); + const String *type = nodeType(child); + if (Strcmp(type, "pragma") == 0) { + const String *lang = Getattr(child, "lang"); + const String *code = Getattr(child, "name"); + String *value = Getattr(child, "value"); - if (Strcmp (lang, "modula3") == 0) { - const_pragma_type cpt = cpt_none; - if (Strcmp (code, "constint") == 0) { - cpt = cpt_constint; - } else if (Strcmp (code, "constset") == 0) { - cpt = cpt_constset; - } else if (Strcmp (code, "enumitem") == 0) { - cpt = cpt_enumitem; - } - if (cpt != cpt_none) { - const_id_pattern pat = { NIL, NIL }; + if (Strcmp(lang, "modula3") == 0) { + const_pragma_type cpt = cpt_none; + if (Strcmp(code, "constint") == 0) { + cpt = cpt_constint; + } else if (Strcmp(code, "constset") == 0) { + cpt = cpt_constset; + } else if (Strcmp(code, "enumitem") == 0) { + cpt = cpt_enumitem; + } + if (cpt != cpt_none) { + const_id_pattern pat = { NIL, NIL }; - List *convdesc = Split (value, ';', 4); - List *patterndesc = Split (Getitem (convdesc, 0), ',', INT_MAX); - Iterator patternit; - for (patternit = First (patterndesc); patternit.item != NIL; - patternit = Next (patternit)) { - List *patternassign = Split (patternit.item, '=', 2); - String *tag = Getitem (patternassign, 0); - String *data = Getitem (patternassign, 1); - if (Strcmp (tag, "prefix") == 0) { - pat.prefix = Copy (data); - } else if (Strcmp (tag, "enum") == 0) { - pat.parentEnum = Copy (data); - } else { - Swig_warning (WARN_MODULA3_BAD_ENUMERATION, input_file, - line_number, - "Unknown identification tag <%s> with value <%s>.\n", - tag, data); - } - Delete (patternassign); - } - tagConstants (child, NIL, pat, code, convdesc); + List *convdesc = Split(value, ';', 4); + List *patterndesc = Split(Getitem(convdesc, 0), ',', INT_MAX); + Iterator patternit; + for (patternit = First(patterndesc); patternit.item != NIL; patternit = Next(patternit)) { + List *patternassign = Split(patternit.item, '=', 2); + String *tag = Getitem(patternassign, 0); + String *data = Getitem(patternassign, 1); + if (Strcmp(tag, "prefix") == 0) { + pat.prefix = Copy(data); + } else if (Strcmp(tag, "enum") == 0) { + pat.parentEnum = Copy(data); + } else { + Swig_warning(WARN_MODULA3_BAD_ENUMERATION, input_file, line_number, "Unknown identification tag <%s> with value <%s>.\n", tag, data); + } + Delete(patternassign); + } + tagConstants(child, NIL, pat, code, convdesc); - Delete (patterndesc); - } - } + Delete(patterndesc); + } + } } - scanForConstPragmas (child); - child = nextSibling (child); + scanForConstPragmas(child); + child = nextSibling(child); } } @@ -2351,155 +2200,129 @@ MODULA3 (): * emitProxyClassDefAndCPPCasts() * ----------------------------------------------------------------------------- */ - void emitProxyClassDefAndCPPCasts (Node * n) - { - String *c_classname = SwigType_namestr (Getattr (n, "name")); + void emitProxyClassDefAndCPPCasts(Node *n) { + String *c_classname = SwigType_namestr(Getattr(n, "name")); String *c_baseclass = NULL; String *baseclass = NULL; String *c_baseclassname = NULL; - String *classDeclarationName = Getattr (n, "classDeclaration:name"); + String *classDeclarationName = Getattr(n, "classDeclaration:name"); /* Deal with inheritance */ - List *baselist = Getattr (n, "bases"); + List *baselist = Getattr(n, "bases"); if (baselist != NIL) { - Iterator base = First (baselist); - c_baseclassname = Getattr (base.item, "name"); - baseclass = Copy (getProxyName (c_baseclassname)); + Iterator base = First(baselist); + c_baseclassname = Getattr(base.item, "name"); + baseclass = Copy(getProxyName(c_baseclassname)); if (baseclass) { - c_baseclass = SwigType_namestr (Getattr (base.item, "name")); + c_baseclass = SwigType_namestr(Getattr(base.item, "name")); } - base = Next (base); + base = Next(base); if (base.item != NIL) { - Swig_warning (WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - classDeclarationName, Getattr (base.item, "name")); + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, + line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", + classDeclarationName, Getattr(base.item, "name")); } } - bool derived = baseclass && getProxyName (c_baseclassname); + bool derived = baseclass && getProxyName(c_baseclassname); if (!baseclass) - baseclass = NewString (""); + baseclass = NewString(""); // Inheritance from pure Modula 3 classes - const String *pure_baseclass = - typemapLookup ("m3base", classDeclarationName, WARN_NONE); - if (hasContent (pure_baseclass) && hasContent (baseclass)) { - Swig_warning (WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - classDeclarationName, pure_baseclass); + const String *pure_baseclass = typemapLookup("m3base", classDeclarationName, WARN_NONE); + if (hasContent(pure_baseclass) && hasContent(baseclass)) { + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, + line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", classDeclarationName, pure_baseclass); } // Pure Modula 3 interfaces - const String *pure_interfaces = - typemapLookup (derived ? "m3interfaces_derived" : "m3interfaces", - classDeclarationName, WARN_NONE); + const String *pure_interfaces = typemapLookup(derived ? "m3interfaces_derived" : "m3interfaces", + classDeclarationName, WARN_NONE); // Start writing the proxy class - Printv (proxy_class_def, typemapLookup ("m3imports", classDeclarationName, WARN_NONE), // Import statements - "\n", typemapLookup ("m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " class $m3classname", // Class name and bases - (derived || *Char (pure_baseclass) || *Char (pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char (pure_baseclass)) && *Char (pure_interfaces)) ? // Interfaces - ", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling - derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup ("m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers - " $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers - derived ? - ": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n" - : "{\n swigCMemOwn = cMemoryOwn;\n", " swigCPtr = cPtr;\n", - " }\n", NIL); + Printv(proxy_class_def, typemapLookup("m3imports", classDeclarationName, WARN_NONE), // Import statements + "\n", typemapLookup("m3classmodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " class $m3classname", // Class name and bases + (derived || *Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", baseclass, pure_baseclass, ((derived || *Char(pure_baseclass)) && *Char(pure_interfaces)) ? // Interfaces + ", " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", // Member variables for memory handling + derived ? "" : " protected bool swigCMemOwn;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", classDeclarationName, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers + " $m3classname(IntPtr cPtr, bool cMemoryOwn) ", // Constructor used for wrapping pointers + derived ? + ": base($imclassname.$m3classnameTo$baseclass(cPtr), cMemoryOwn) {\n" + : "{\n swigCMemOwn = cMemoryOwn;\n", " swigCPtr = cPtr;\n", " }\n", NIL); - if (!have_default_constructor_flag) { // All proxy classes need a constructor - Printv (proxy_class_def, - "\n", - " protected $m3classname() : this(IntPtr.Zero, false) {\n", - " }\n", NIL); + if (!have_default_constructor_flag) { // All proxy classes need a constructor + Printv(proxy_class_def, "\n", " protected $m3classname() : this(IntPtr.Zero, false) {\n", " }\n", NIL); } // C++ destructor is wrapped by the Dispose method // Note that the method name is specified in a typemap attribute called methodname - String *destruct = NewString (""); + String *destruct = NewString(""); const String *tm = NULL; - Node *attributes = NewHash (); + Node *attributes = NewHash(); String *destruct_methodname = NULL; if (derived) { - tm = - typemapLookup ("m3destruct_derived", classDeclarationName, WARN_NONE, - attributes); - destruct_methodname = - Getattr (attributes, "tmap:m3destruct_derived:methodname"); + tm = typemapLookup("m3destruct_derived", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:m3destruct_derived:methodname"); } else { - tm = - typemapLookup ("m3destruct", classDeclarationName, WARN_NONE, - attributes); - destruct_methodname = - Getattr (attributes, "tmap:m3destruct:methodname"); + tm = typemapLookup("m3destruct", classDeclarationName, WARN_NONE, attributes); + destruct_methodname = Getattr(attributes, "tmap:m3destruct:methodname"); } if (!destruct_methodname) { - Swig_error (input_file, line_number, - "No methodname attribute defined in m3destruct%s typemap for %s\n", - (derived ? "_derived" : ""), proxy_class_name); + Swig_error(input_file, line_number, "No methodname attribute defined in m3destruct%s typemap for %s\n", (derived ? "_derived" : ""), proxy_class_name); } // Emit the Finalize and Dispose methods if (tm) { // Finalize method - if (*Char (destructor_call)) { - Printv (proxy_class_def, - typemapLookup ("m3finalize", classDeclarationName, WARN_NONE), - NIL); + if (*Char(destructor_call)) { + Printv(proxy_class_def, typemapLookup("m3finalize", classDeclarationName, WARN_NONE), NIL); } // Dispose method - Printv (destruct, tm, NIL); - if (*Char (destructor_call)) - Replaceall (destruct, "$imcall", destructor_call); + Printv(destruct, tm, NIL); + if (*Char(destructor_call)) + Replaceall(destruct, "$imcall", destructor_call); else - Replaceall (destruct, "$imcall", - "throw new MethodAccessException(\"C++ destructor does not have public access\")"); - if (*Char (destruct)) - Printv (proxy_class_def, "\n public ", - derived ? "override" : "virtual", " void ", - destruct_methodname, "() ", destruct, "\n", NIL); + Replaceall(destruct, "$imcall", "throw new MethodAccessException(\"C++ destructor does not have public access\")"); + if (*Char(destruct)) + Printv(proxy_class_def, "\n public ", derived ? "override" : "virtual", " void ", destruct_methodname, "() ", destruct, "\n", NIL); } - Delete (attributes); - Delete (destruct); + Delete(attributes); + Delete(destruct); // Emit various other methods - Printv (proxy_class_def, typemapLookup ("m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method - typemapLookup ("m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code - "\n", NIL); + Printv(proxy_class_def, typemapLookup("m3getcptr", classDeclarationName, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method + typemapLookup("m3code", classDeclarationName, WARN_NONE), // extra Modula 3 code + "\n", NIL); // Substitute various strings into the above template - Replaceall (proxy_class_def, "$m3classname", proxy_class_name); - Replaceall (proxy_class_code, "$m3classname", proxy_class_name); + Replaceall(proxy_class_def, "$m3classname", proxy_class_name); + Replaceall(proxy_class_code, "$m3classname", proxy_class_name); - Replaceall (proxy_class_def, "$baseclass", baseclass); - Replaceall (proxy_class_code, "$baseclass", baseclass); + Replaceall(proxy_class_def, "$baseclass", baseclass); + Replaceall(proxy_class_code, "$baseclass", baseclass); - Replaceall (proxy_class_def, "$imclassname", m3raw_name); - Replaceall (proxy_class_code, "$imclassname", m3raw_name); + Replaceall(proxy_class_def, "$imclassname", m3raw_name); + Replaceall(proxy_class_code, "$imclassname", m3raw_name); // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy) if (derived) { - Printv (m3raw_cppcasts_code, "\n [DllImport(\"", m3wrap_name, - "\", EntryPoint=\"Modula3_", proxy_class_name, "To", baseclass, - "\")]\n", NIL); - Printv (m3raw_cppcasts_code, " public static extern IntPtr ", - "$m3classnameTo$baseclass(IntPtr objectRef);\n", NIL); + Printv(m3raw_cppcasts_code, "\n [DllImport(\"", m3wrap_name, "\", EntryPoint=\"Modula3_", proxy_class_name, "To", baseclass, "\")]\n", NIL); + Printv(m3raw_cppcasts_code, " public static extern IntPtr ", "$m3classnameTo$baseclass(IntPtr objectRef);\n", NIL); - Replaceall (m3raw_cppcasts_code, "$m3classname", proxy_class_name); - Replaceall (m3raw_cppcasts_code, "$baseclass", baseclass); + Replaceall(m3raw_cppcasts_code, "$m3classname", proxy_class_name); + Replaceall(m3raw_cppcasts_code, "$baseclass", baseclass); - Printv (upcasts_code, - "SWIGEXPORT long Modula3_$imclazznameTo$imbaseclass", - "(long objectRef) {\n", - " long baseptr = 0;\n" - " *($cbaseclass **)&baseptr = *($cclass **)&objectRef;\n" - " return baseptr;\n" "}\n", "\n", NIL); + Printv(upcasts_code, + "SWIGEXPORT long Modula3_$imclazznameTo$imbaseclass", + "(long objectRef) {\n", + " long baseptr = 0;\n" " *($cbaseclass **)&baseptr = *($cclass **)&objectRef;\n" " return baseptr;\n" "}\n", "\n", NIL); - Replaceall (upcasts_code, "$imbaseclass", baseclass); - Replaceall (upcasts_code, "$cbaseclass", c_baseclass); - Replaceall (upcasts_code, "$imclazzname", proxy_class_name); - Replaceall (upcasts_code, "$cclass", c_classname); + Replaceall(upcasts_code, "$imbaseclass", baseclass); + Replaceall(upcasts_code, "$cbaseclass", c_baseclass); + Replaceall(upcasts_code, "$imclazzname", proxy_class_name); + Replaceall(upcasts_code, "$cclass", c_classname); } - Delete (baseclass); + Delete(baseclass); } /* ---------------------------------------------------------------------- @@ -2509,12 +2332,11 @@ MODULA3 (): * associated with a certain attribute of 'n'. * ---------------------------------------------------------------------- */ - String *getAttrString (Node * n, const char *attr) - { - String *str = Getattr (n, attr); + String *getAttrString(Node *n, const char *attr) { + String *str = Getattr(n, attr); if (str == NIL) { - str = NewString (""); - Setattr (n, attr, str); + str = NewString(""); + Setattr(n, attr, str); } return str; } @@ -2527,17 +2349,16 @@ MODULA3 (): * 'n' must be a member of a struct or a class. * ---------------------------------------------------------------------- */ - String *getMethodDeclarations (Node * n) - { - String *acc_str = Getattr (n, "access"); + String *getMethodDeclarations(Node *n) { + String *acc_str = Getattr(n, "access"); String *methodattr; if (acc_str == NIL) { - methodattr = NewString ("modula3:method:public"); + methodattr = NewString("modula3:method:public"); } else { - methodattr = NewStringf ("modula3:method:%s", acc_str); + methodattr = NewStringf("modula3:method:%s", acc_str); } - String *methods = getAttrString (parentNode (n), Char (methodattr)); - Delete (methodattr); + String *methods = getAttrString(parentNode(n), Char(methodattr)); + Delete(methodattr); return methods; } @@ -2545,48 +2366,42 @@ MODULA3 (): * classHandler() * ---------------------------------------------------------------------- */ - virtual int classHandler (Node * n) - { + virtual int classHandler(Node *n) { File *f_proxy = NULL; - proxy_class_name = Copy (Getattr (n, "sym:name")); + proxy_class_name = Copy(Getattr(n, "sym:name")); //String *rawname = Getattr(n,"name"); if (proxy_flag) { - if (!addSymbol (proxy_class_name, n)) - return SWIG_ERROR; + if (!addSymbol(proxy_class_name, n)) + return SWIG_ERROR; - if (Cmp (proxy_class_name, m3raw_name) == 0) { - Printf (stderr, - "Class name cannot be equal to intermediary class name: %s\n", - proxy_class_name); - SWIG_exit (EXIT_FAILURE); + if (Cmp(proxy_class_name, m3raw_name) == 0) { + Printf(stderr, "Class name cannot be equal to intermediary class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } - if (Cmp (proxy_class_name, m3wrap_name) == 0) { - Printf (stderr, - "Class name cannot be equal to module class name: %s\n", - proxy_class_name); - SWIG_exit (EXIT_FAILURE); + if (Cmp(proxy_class_name, m3wrap_name) == 0) { + Printf(stderr, "Class name cannot be equal to module class name: %s\n", proxy_class_name); + SWIG_exit(EXIT_FAILURE); } - String *filen = - NewStringf ("%s%s.m3", Swig_file_dirname (outfile), proxy_class_name); - f_proxy = NewFile (filen, "w"); + String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), proxy_class_name); + f_proxy = NewFile(filen, "w"); if (!f_proxy) { - FileErrorDisplay (filen); - SWIG_exit (EXIT_FAILURE); + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } - Delete (filen); + Delete(filen); filen = NULL; - emitBanner (f_proxy); + emitBanner(f_proxy); - Clear (proxy_class_def); - Clear (proxy_class_code); + Clear(proxy_class_def); + Clear(proxy_class_code); have_default_constructor_flag = false; - destructor_call = NewString (""); + destructor_call = NewString(""); } /* This will invoke memberfunctionHandler, membervariableHandler ... @@ -2594,168 +2409,157 @@ MODULA3 (): for wrappers and member variable accessors. It will invoke Language:constructorDeclaration which decides whether to call MODULA3::constructorHandler */ - Language::classHandler (n); + Language::classHandler(n); { - String *kind = Getattr (n, "kind"); - if (Cmp (kind, "struct") == 0) { - String *entries = NewString (""); - Node *child; - writeArgState state; - for (child = firstChild (n); child != NIL; - child = nextSibling (child)) { - String *childType = nodeType (child); - if (Strcmp (childType, "cdecl") == 0) { - String *member = Getattr (child, "sym:name"); - ParmList *pl = Getattr (child, "parms"); - if (pl == NIL) { - // Get the variable type in Modula 3 type equivalents - String *m3ct = getMappedTypeNew (child, "m3rawtype", ""); + String *kind = Getattr(n, "kind"); + if (Cmp(kind, "struct") == 0) { + String *entries = NewString(""); + Node *child; + writeArgState state; + for (child = firstChild(n); child != NIL; child = nextSibling(child)) { + String *childType = nodeType(child); + if (Strcmp(childType, "cdecl") == 0) { + String *member = Getattr(child, "sym:name"); + ParmList *pl = Getattr(child, "parms"); + if (pl == NIL) { + // Get the variable type in Modula 3 type equivalents + String *m3ct = getMappedTypeNew(child, "m3rawtype", ""); - writeArg (entries, state, NIL, member, m3ct, NIL); - } - } - } - writeArg (entries, state, NIL, NIL, NIL, NIL); + writeArg(entries, state, NIL, member, m3ct, NIL); + } + } + } + writeArg(entries, state, NIL, NIL, NIL, NIL); - m3raw_intf.enterBlock (blocktype); - Printf (m3raw_intf.f, "%s =\nRECORD\n%sEND;\n", proxy_class_name, - entries); + m3raw_intf.enterBlock(blocktype); + Printf(m3raw_intf.f, "%s =\nRECORD\n%sEND;\n", proxy_class_name, entries); - Delete (entries); + Delete(entries); - } else if (Cmp (kind, "class") == 0) { - enum access_privilege - { acc_public, acc_protected, acc_private }; - int max_acc = acc_public; + } else if (Cmp(kind, "class") == 0) { + enum access_privilege { acc_public, acc_protected, acc_private }; + int max_acc = acc_public; - const char *acc_name[3] = { "public", "protected", "private" }; - String *methods[3]; - int acc; - for (acc = acc_public; acc <= acc_private; acc++) { - String *methodattr = - NewStringf ("modula3:method:%s", acc_name[acc]); - methods[acc] = Getattr (n, methodattr); - Delete (methodattr); - max_acc = max_acc > acc ? max_acc : acc; - } + const char *acc_name[3] = { "public", "protected", "private" }; + String *methods[3]; + int acc; + for (acc = acc_public; acc <= acc_private; acc++) { + String *methodattr = NewStringf("modula3:method:%s", acc_name[acc]); + methods[acc] = Getattr(n, methodattr); + Delete(methodattr); + max_acc = max_acc > acc ? max_acc : acc; + } - /* Determine the name of the base class */ - String *baseclassname = NewString (""); - { - List *baselist = Getattr (n, "bases"); - if (baselist) { - /* Look for the first (principal?) base class - - Modula 3 does not support multiple inheritance */ - Iterator base = First (baselist); - Append (baseclassname, Getattr (base.item, "sym:name")); - base = Next (base); - if (base.item != NIL) { - Swig_warning (WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, - line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", - proxy_class_name, Getattr (base.item, "name")); - } - } - } + /* Determine the name of the base class */ + String *baseclassname = NewString(""); + { + List *baselist = Getattr(n, "bases"); + if (baselist) { + /* Look for the first (principal?) base class - + Modula 3 does not support multiple inheritance */ + Iterator base = First(baselist); + Append(baseclassname, Getattr(base.item, "sym:name")); + base = Next(base); + if (base.item != NIL) { + Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, input_file, + line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", + proxy_class_name, Getattr(base.item, "name")); + } + } + } - /* the private class of the base class and only this - need a pointer to the C++ object */ - bool need_private = !hasContent (baseclassname); - max_acc = need_private ? acc_private : max_acc; + /* the private class of the base class and only this + need a pointer to the C++ object */ + bool need_private = !hasContent(baseclassname); + max_acc = need_private ? acc_private : max_acc; - /* Declare C++ object as abstract pointer in Modula 3 */ - /* The revelation system does not allow us - to imitate the whole class hierarchy of the C++ library, - but at least we can distinguish between classes of different roots. */ - if (hasContent (baseclassname)) { - m3raw_intf.enterBlock (blocktype); - Printf (m3raw_intf.f, "%s = %s;\n", proxy_class_name, - baseclassname); - } else { - m3raw_intf.enterBlock (blocktype); - Printf (m3raw_intf.f, "%s <: ADDRESS;\n", proxy_class_name); - m3raw_impl.enterBlock (revelation); - Printf (m3raw_impl.f, - "%s = UNTRACED BRANDED REF RECORD (*Dummy*) END;\n", - proxy_class_name); - } + /* Declare C++ object as abstract pointer in Modula 3 */ + /* The revelation system does not allow us + to imitate the whole class hierarchy of the C++ library, + but at least we can distinguish between classes of different roots. */ + if (hasContent(baseclassname)) { + m3raw_intf.enterBlock(blocktype); + Printf(m3raw_intf.f, "%s = %s;\n", proxy_class_name, baseclassname); + } else { + m3raw_intf.enterBlock(blocktype); + Printf(m3raw_intf.f, "%s <: ADDRESS;\n", proxy_class_name); + m3raw_impl.enterBlock(revelation); + Printf(m3raw_impl.f, "%s = UNTRACED BRANDED REF RECORD (*Dummy*) END;\n", proxy_class_name); + } - String *superclass; - m3wrap_intf.enterBlock (blocktype); - if (hasContent (methods[acc_public])) { - superclass = NewStringf ("%sPublic", proxy_class_name); - } else if (hasContent (baseclassname)) { - superclass = Copy (baseclassname); - } else { - superclass = NewString ("ROOT"); - } - Printf (m3wrap_intf.f, "%s <: %s;\n", proxy_class_name, superclass); - Delete (superclass); + String *superclass; + m3wrap_intf.enterBlock(blocktype); + if (hasContent(methods[acc_public])) { + superclass = NewStringf("%sPublic", proxy_class_name); + } else if (hasContent(baseclassname)) { + superclass = Copy(baseclassname); + } else { + superclass = NewString("ROOT"); + } + Printf(m3wrap_intf.f, "%s <: %s;\n", proxy_class_name, superclass); + Delete(superclass); - { - static const char *acc_m3suffix[] = - { "Public", "Protected", "Private" }; - int acc; - for (acc = acc_public; acc <= acc_private; acc++) { - bool process_private = (acc == acc_private) && need_private; - if (hasContent (methods[acc]) || process_private) { - String *subclass = - NewStringf ("%s%s", proxy_class_name, acc_m3suffix[acc]); - /* - m3wrap_intf.enterBlock(revelation); - Printf(m3wrap_intf.f, "%s <: %s;\n", proxy_class_name, subclass); - */ - if (acc == max_acc) { - m3wrap_intf.enterBlock (revelation); - Printf (m3wrap_intf.f, "%s =\n", proxy_class_name); - } else { - m3wrap_intf.enterBlock (blocktype); - Printf (m3wrap_intf.f, "%s =\n", subclass); - } - Printf (m3wrap_intf.f, "%s BRANDED OBJECT\n", baseclassname); - if (process_private) { - Setattr (m3wrap_intf.import, m3raw_name, ""); - Printf (m3wrap_intf.f, "cxxObj:%s.%s;\n", m3raw_name, - proxy_class_name); - } - if (hasContent (methods[acc])) { - Printf (m3wrap_intf.f, "METHODS\n%s", methods[acc]); - } - if (acc == max_acc) { - String *overrides = Getattr (n, "modula3:override"); - Printf (m3wrap_intf.f, "OVERRIDES\n%s", overrides); - } - Printf (m3wrap_intf.f, "END;\n"); - Delete (baseclassname); - baseclassname = subclass; - } - } - } + { + static const char *acc_m3suffix[] = { "Public", "Protected", "Private" }; + int acc; + for (acc = acc_public; acc <= acc_private; acc++) { + bool process_private = (acc == acc_private) && need_private; + if (hasContent(methods[acc]) || process_private) { + String *subclass = NewStringf("%s%s", proxy_class_name, acc_m3suffix[acc]); + /* + m3wrap_intf.enterBlock(revelation); + Printf(m3wrap_intf.f, "%s <: %s;\n", proxy_class_name, subclass); + */ + if (acc == max_acc) { + m3wrap_intf.enterBlock(revelation); + Printf(m3wrap_intf.f, "%s =\n", proxy_class_name); + } else { + m3wrap_intf.enterBlock(blocktype); + Printf(m3wrap_intf.f, "%s =\n", subclass); + } + Printf(m3wrap_intf.f, "%s BRANDED OBJECT\n", baseclassname); + if (process_private) { + Setattr(m3wrap_intf.import, m3raw_name, ""); + Printf(m3wrap_intf.f, "cxxObj:%s.%s;\n", m3raw_name, proxy_class_name); + } + if (hasContent(methods[acc])) { + Printf(m3wrap_intf.f, "METHODS\n%s", methods[acc]); + } + if (acc == max_acc) { + String *overrides = Getattr(n, "modula3:override"); + Printf(m3wrap_intf.f, "OVERRIDES\n%s", overrides); + } + Printf(m3wrap_intf.f, "END;\n"); + Delete(baseclassname); + baseclassname = subclass; + } + } + } - Delete (methods[acc_public]); - Delete (methods[acc_protected]); - Delete (methods[acc_private]); + Delete(methods[acc_public]); + Delete(methods[acc_protected]); + Delete(methods[acc_private]); } else { - Swig_warning (WARN_MODULA3_TYPECONSTRUCTOR_UNKNOWN, input_file, - line_number, "Unknown type constructor %s\n", kind); + Swig_warning(WARN_MODULA3_TYPECONSTRUCTOR_UNKNOWN, input_file, line_number, "Unknown type constructor %s\n", kind); } } if (proxy_flag) { - emitProxyClassDefAndCPPCasts (n); + emitProxyClassDefAndCPPCasts(n); - Printv (f_proxy, proxy_class_def, proxy_class_code, NIL); + Printv(f_proxy, proxy_class_def, proxy_class_code, NIL); - Printf (f_proxy, "}\n"); - Close (f_proxy); + Printf(f_proxy, "}\n"); + Close(f_proxy); f_proxy = NULL; - Delete (proxy_class_name); + Delete(proxy_class_name); proxy_class_name = NULL; - Delete (destructor_call); + Delete(destructor_call); destructor_call = NULL; } return SWIG_OK; @@ -2765,63 +2569,58 @@ MODULA3 (): * memberfunctionHandler() * ---------------------------------------------------------------------- */ - virtual int memberfunctionHandler (Node * n) - { + virtual int memberfunctionHandler(Node *n) { //printf("begin memberfunctionHandler(%s)\n", Char(Getattr(n,"name"))); - Setattr (n, "modula3:functype", "method"); - Language::memberfunctionHandler (n); + Setattr(n, "modula3:functype", "method"); + Language::memberfunctionHandler(n); { /* Language::memberfunctionHandler will remove the mapped types that emitM3Wrapper may attach */ - ParmList *pl = Getattr (n, "parms"); - Swig_typemap_attach_parms ("m3wrapinmode", pl, NULL); - Swig_typemap_attach_parms ("m3wrapinname", pl, NULL); - Swig_typemap_attach_parms ("m3wrapintype", pl, NULL); - Swig_typemap_attach_parms ("m3wrapindefault", pl, NULL); - attachParameterNames (n, "tmap:m3wrapinname", "autoname", "arg%d"); - String *rettype = getMappedTypeNew (n, "m3wrapouttype", ""); + ParmList *pl = Getattr(n, "parms"); + Swig_typemap_attach_parms("m3wrapinmode", pl, NULL); + Swig_typemap_attach_parms("m3wrapinname", pl, NULL); + Swig_typemap_attach_parms("m3wrapintype", pl, NULL); + Swig_typemap_attach_parms("m3wrapindefault", pl, NULL); + attachParameterNames(n, "tmap:m3wrapinname", "autoname", "arg%d"); + String *rettype = getMappedTypeNew(n, "m3wrapouttype", ""); - String *methodname = Getattr (n, "sym:name"); + String *methodname = Getattr(n, "sym:name"); /* if (methodname==NIL) { methodname = Getattr(n,"name"); } */ - String *arguments = createM3Signature (n); - String *storage = Getattr (n, "storage"); - String *overridden = Getattr (n, "override"); - bool isVirtual = (storage != NIL) && (Strcmp (storage, "virtual") == 0); + String *arguments = createM3Signature(n); + String *storage = Getattr(n, "storage"); + String *overridden = Getattr(n, "override"); + bool isVirtual = (storage != NIL) && (Strcmp(storage, "virtual") == 0); bool isOverridden = (overridden != NIL) - && (Strcmp (overridden, "1") == 0); + && (Strcmp(overridden, "1") == 0); if ((!isVirtual) || (!isOverridden)) { - { - String *methods = getMethodDeclarations (n); - Printf (methods, "%s(%s)%s%s;%s\n", - methodname, arguments, - hasContent (rettype) ? ": " : "", - hasContent (rettype) ? (const String *) rettype : "", - isVirtual ? " (* base method *)" : ""); - } - { - /* this was attached by functionWrapper - invoked by Language::memberfunctionHandler */ - String *fname = Getattr (n, "modula3:funcname"); - String *overrides = - getAttrString (parentNode (n), "modula3:override"); - Printf (overrides, "%s := %s;\n", methodname, fname); - } + { + String *methods = getMethodDeclarations(n); + Printf(methods, "%s(%s)%s%s;%s\n", + methodname, arguments, + hasContent(rettype) ? ": " : "", hasContent(rettype) ? (const String *) rettype : "", isVirtual ? " (* base method *)" : ""); + } + { + /* this was attached by functionWrapper + invoked by Language::memberfunctionHandler */ + String *fname = Getattr(n, "modula3:funcname"); + String *overrides = getAttrString(parentNode(n), "modula3:override"); + Printf(overrides, "%s := %s;\n", methodname, fname); + } } } if (proxy_flag) { - String *overloaded_name = getOverloadedName (n); - String *intermediary_function_name = - Swig_name_member (proxy_class_name, overloaded_name); - Setattr (n, "proxyfuncname", Getattr (n, "sym:name")); - Setattr (n, "imfuncname", intermediary_function_name); - proxyClassFunctionHandler (n); - Delete (overloaded_name); + String *overloaded_name = getOverloadedName(n); + String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); + proxyClassFunctionHandler(n); + Delete(overloaded_name); } //printf("end memberfunctionHandler(%s)\n", Char(Getattr(n,"name"))); return SWIG_OK; @@ -2831,20 +2630,18 @@ MODULA3 (): * staticmemberfunctionHandler() * ---------------------------------------------------------------------- */ - virtual int staticmemberfunctionHandler (Node * n) - { + virtual int staticmemberfunctionHandler(Node *n) { static_flag = true; - Language::staticmemberfunctionHandler (n); + Language::staticmemberfunctionHandler(n); if (proxy_flag) { - String *overloaded_name = getOverloadedName (n); - String *intermediary_function_name = - Swig_name_member (proxy_class_name, overloaded_name); - Setattr (n, "proxyfuncname", Getattr (n, "sym:name")); - Setattr (n, "imfuncname", intermediary_function_name); - proxyClassFunctionHandler (n); - Delete (overloaded_name); + String *overloaded_name = getOverloadedName(n); + String *intermediary_function_name = Swig_name_member(proxy_class_name, overloaded_name); + Setattr(n, "proxyfuncname", Getattr(n, "sym:name")); + Setattr(n, "imfuncname", intermediary_function_name); + proxyClassFunctionHandler(n); + Delete(overloaded_name); } static_flag = false; @@ -2862,67 +2659,62 @@ MODULA3 (): * the intermediary (PInvoke) function name in the intermediary class. * ----------------------------------------------------------------------------- */ - void proxyClassFunctionHandler (Node * n) - { - SwigType *t = Getattr (n, "type"); - ParmList *l = Getattr (n, "parms"); - Hash *throws_hash = NewHash (); - String *intermediary_function_name = Getattr (n, "imfuncname"); - String *proxy_function_name = Getattr (n, "proxyfuncname"); + void proxyClassFunctionHandler(Node *n) { + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + Hash *throws_hash = NewHash(); + String *intermediary_function_name = Getattr(n, "imfuncname"); + String *proxy_function_name = Getattr(n, "proxyfuncname"); String *tm; Parm *p; int i; - String *imcall = NewString (""); - String *return_type = NewString (""); - String *function_code = NewString (""); + String *imcall = NewString(""); + String *return_type = NewString(""); + String *function_code = NewString(""); bool setter_flag = false; if (!proxy_flag) return; if (l) { - if (SwigType_type (Getattr (l, "type")) == T_VOID) { - l = nextSibling (l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } /* Attach the non-standard typemaps to the parameter list */ - Swig_typemap_attach_parms ("in", l, NULL); - Swig_typemap_attach_parms ("m3wraptype", l, NULL); - Swig_typemap_attach_parms ("m3in", l, NULL); + Swig_typemap_attach_parms("in", l, NULL); + Swig_typemap_attach_parms("m3wraptype", l, NULL); + Swig_typemap_attach_parms("m3in", l, NULL); /* Get return types */ - if ((tm = getMappedTypeNew (n, "m3wraptype", ""))) { - substituteClassname (t, tm); - Printf (return_type, "%s", tm); + if ((tm = getMappedTypeNew(n, "m3wraptype", ""))) { + substituteClassname(t, tm); + Printf(return_type, "%s", tm); } if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Properties - setter_flag = - (Cmp - (Getattr (n, "sym:name"), - Swig_name_set (Swig_name_member (proxy_class_name, variable_name))) - == 0); + setter_flag = (Cmp(Getattr(n, "sym:name"), Swig_name_set(Swig_name_member(proxy_class_name, variable_name))) + == 0); } /* Start generating the proxy function */ - Printf (function_code, " %s ", - Getattr (n, "feature:modula3:methodmodifiers")); + Printf(function_code, " %s ", Getattr(n, "feature:modula3:methodmodifiers")); if (static_flag) - Printf (function_code, "static "); - if (Getattr (n, "override")) - Printf (function_code, "override "); - else if (checkAttribute (n, "storage", "virtual")) - Printf (function_code, "virtual "); + Printf(function_code, "static "); + if (Getattr(n, "override")) + Printf(function_code, "override "); + else if (checkAttribute(n, "storage", "virtual")) + Printf(function_code, "virtual "); - Printf (function_code, "%s %s(", return_type, proxy_function_name); + Printf(function_code, "%s %s(", return_type, proxy_function_name); - Printv (imcall, m3raw_name, ".", intermediary_function_name, "(", NIL); + Printv(imcall, m3raw_name, ".", intermediary_function_name, "(", NIL); if (!static_flag) - Printv (imcall, "swigCPtr", NIL); + Printv(imcall, "swigCPtr", NIL); - emit_mark_varargs (l); + emit_mark_varargs(l); int gencomma = !static_flag; @@ -2930,138 +2722,132 @@ MODULA3 (): for (i = 0, p = l; p; i++) { /* Ignored varargs */ - if (checkAttribute (p, "varargs:ignore", "1")) { - p = nextSibling (p); - continue; + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; } /* Ignored parameters */ - if (checkAttribute (p, "tmap:in:numinputs", "0")) { - p = Getattr (p, "tmap:in:next"); - continue; + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; } /* Ignore the 'this' argument for variable wrappers */ if (!(variable_wrapper_flag && i == 0)) { - SwigType *pt = Getattr (p, "type"); - String *param_type = NewString (""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); - /* Get the Modula 3 parameter type */ - if ((tm = getMappedType (p, "m3wraptype"))) { - substituteClassname (pt, tm); - Printf (param_type, "%s", tm); - } + /* Get the Modula 3 parameter type */ + if ((tm = getMappedType(p, "m3wraptype"))) { + substituteClassname(pt, tm); + Printf(param_type, "%s", tm); + } - if (gencomma) - Printf (imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = - variable_wrapper_flag ? NewString ("value") : makeParameterName (n, - p, - i); + String *arg = variable_wrapper_flag ? NewString("value") : makeParameterName(n, + p, + i); - // Use typemaps to transform type used in Modula 3 wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) - if ((tm = getMappedType (p, "in"))) { - addThrows (throws_hash, "in", p); - substituteClassname (pt, tm); - Replaceall (tm, "$input", arg); - Printv (imcall, tm, NIL); - } + // Use typemaps to transform type used in Modula 3 wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) + if ((tm = getMappedType(p, "in"))) { + addThrows(throws_hash, "in", p); + substituteClassname(pt, tm); + Replaceall(tm, "$input", arg); + Printv(imcall, tm, NIL); + } - /* Add parameter to proxy function */ - if (gencomma >= 2) - Printf (function_code, ", "); - gencomma = 2; - Printf (function_code, "%s %s", param_type, arg); + /* Add parameter to proxy function */ + if (gencomma >= 2) + Printf(function_code, ", "); + gencomma = 2; + Printf(function_code, "%s %s", param_type, arg); - Delete (arg); - Delete (param_type); + Delete(arg); + Delete(param_type); } - p = Getattr (p, "tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } - Printf (imcall, ")"); - Printf (function_code, ")"); + Printf(imcall, ")"); + Printf(function_code, ")"); // Transform return type used in PInvoke function (in intermediary class) to type used in Modula 3 wrapper function (in proxy class) - if ((tm = getMappedTypeNew (n, "m3out", ""))) { - addThrows (throws_hash, "m3out", n); - if (GetFlag (n, "feature:new")) - Replaceall (tm, "$owner", "true"); + if ((tm = getMappedTypeNew(n, "m3out", ""))) { + addThrows(throws_hash, "m3out", n); + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); else - Replaceall (tm, "$owner", "false"); - substituteClassname (t, tm); - Replaceall (tm, "$imcall", imcall); + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$imcall", imcall); } - generateThrowsClause (throws_hash, function_code); - Printf (function_code, " %s\n\n", - tm ? (const String *) tm : empty_string); + generateThrowsClause(throws_hash, function_code); + Printf(function_code, " %s\n\n", tm ? (const String *) tm : empty_string); if (proxy_flag && wrapping_member_flag && !enum_constant_flag) { // Properties if (setter_flag) { - // Setter method - if ((tm = getMappedTypeNew (n, "m3varin", ""))) { - if (GetFlag (n, "feature:new")) - Replaceall (tm, "$owner", "true"); - else - Replaceall (tm, "$owner", "false"); - substituteClassname (t, tm); - Replaceall (tm, "$imcall", imcall); - Printf (proxy_class_code, "%s", tm); - } + // Setter method + if ((tm = getMappedTypeNew(n, "m3varin", ""))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); + else + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$imcall", imcall); + Printf(proxy_class_code, "%s", tm); + } } else { - // Getter method - if ((tm = getMappedTypeNew (n, "m3varout", ""))) { - if (GetFlag (n, "feature:new")) - Replaceall (tm, "$owner", "true"); - else - Replaceall (tm, "$owner", "false"); - substituteClassname (t, tm); - Replaceall (tm, "$imcall", imcall); - Printf (proxy_class_code, "%s", tm); - } + // Getter method + if ((tm = getMappedTypeNew(n, "m3varout", ""))) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); + else + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$imcall", imcall); + Printf(proxy_class_code, "%s", tm); + } } } else { // Normal function call - Printv (proxy_class_code, function_code, NIL); + Printv(proxy_class_code, function_code, NIL); } - Delete (function_code); - Delete (return_type); - Delete (imcall); - Delete (throws_hash); + Delete(function_code); + Delete(return_type); + Delete(imcall); + Delete(throws_hash); } /* ---------------------------------------------------------------------- * constructorHandler() * ---------------------------------------------------------------------- */ - virtual int constructorHandler (Node * n) - { + virtual int constructorHandler(Node *n) { // this invokes functionWrapper - Language::constructorHandler (n); + Language::constructorHandler(n); if (proxy_flag) { - ParmList *l = Getattr (n, "parms"); + ParmList *l = Getattr(n, "parms"); - Hash *throws_hash = NewHash (); - String *overloaded_name = getOverloadedName (n); - String *imcall = NewString (""); + Hash *throws_hash = NewHash(); + String *overloaded_name = getOverloadedName(n); + String *imcall = NewString(""); - Printf (proxy_class_code, " %s %s(", - Getattr (n, "feature:modula3:methodmodifiers"), - proxy_class_name); - Printv (imcall, " : this(", m3raw_name, ".", - Swig_name_construct (overloaded_name), "(", NIL); + Printf(proxy_class_code, " %s %s(", Getattr(n, "feature:modula3:methodmodifiers"), proxy_class_name); + Printv(imcall, " : this(", m3raw_name, ".", Swig_name_construct(overloaded_name), "(", NIL); /* Attach the non-standard typemaps to the parameter list */ - Swig_typemap_attach_parms ("in", l, NULL); - Swig_typemap_attach_parms ("m3wraptype", l, NULL); - Swig_typemap_attach_parms ("m3in", l, NULL); + Swig_typemap_attach_parms("in", l, NULL); + Swig_typemap_attach_parms("m3wraptype", l, NULL); + Swig_typemap_attach_parms("m3in", l, NULL); - emit_mark_varargs (l); + emit_mark_varargs(l); int gencomma = 0; @@ -3072,65 +2858,65 @@ MODULA3 (): /* Output each parameter */ for (i = 0; p; i++) { - /* Ignored varargs */ - if (checkAttribute (p, "varargs:ignore", "1")) { - p = nextSibling (p); - continue; - } + /* Ignored varargs */ + if (checkAttribute(p, "varargs:ignore", "1")) { + p = nextSibling(p); + continue; + } - /* Ignored parameters */ - if (checkAttribute (p, "tmap:in:numinputs", "0")) { - p = Getattr (p, "tmap:in:next"); - continue; - } + /* Ignored parameters */ + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + continue; + } - SwigType *pt = Getattr (p, "type"); - String *param_type = NewString (""); + SwigType *pt = Getattr(p, "type"); + String *param_type = NewString(""); - /* Get the Modula 3 parameter type */ - if ((tm = getMappedType (p, "m3wraptype"))) { - substituteClassname (pt, tm); - Printf (param_type, "%s", tm); - } + /* Get the Modula 3 parameter type */ + if ((tm = getMappedType(p, "m3wraptype"))) { + substituteClassname(pt, tm); + Printf(param_type, "%s", tm); + } - if (gencomma) - Printf (imcall, ", "); + if (gencomma) + Printf(imcall, ", "); - String *arg = makeParameterName (n, p, i); + String *arg = makeParameterName(n, p, i); - // Use typemaps to transform type used in Modula 3 wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) - if ((tm = getMappedType (p, "in"))) { - addThrows (throws_hash, "in", p); - substituteClassname (pt, tm); - Replaceall (tm, "$input", arg); - Printv (imcall, tm, NIL); - } + // Use typemaps to transform type used in Modula 3 wrapper function (in proxy class) to type used in PInvoke function (in intermediary class) + if ((tm = getMappedType(p, "in"))) { + addThrows(throws_hash, "in", p); + substituteClassname(pt, tm); + Replaceall(tm, "$input", arg); + Printv(imcall, tm, NIL); + } - /* Add parameter to proxy function */ - if (gencomma) - Printf (proxy_class_code, ", "); - Printf (proxy_class_code, "%s %s", param_type, arg); - gencomma = 1; + /* Add parameter to proxy function */ + if (gencomma) + Printf(proxy_class_code, ", "); + Printf(proxy_class_code, "%s %s", param_type, arg); + gencomma = 1; - Delete (arg); - Delete (param_type); - p = Getattr (p, "tmap:in:next"); + Delete(arg); + Delete(param_type); + p = Getattr(p, "tmap:in:next"); } - Printf (imcall, "), true)"); + Printf(imcall, "), true)"); - Printf (proxy_class_code, ")"); - Printf (proxy_class_code, "%s", imcall); - generateThrowsClause (throws_hash, proxy_class_code); - Printf (proxy_class_code, " {\n"); - Printf (proxy_class_code, " }\n\n"); + Printf(proxy_class_code, ")"); + Printf(proxy_class_code, "%s", imcall); + generateThrowsClause(throws_hash, proxy_class_code); + Printf(proxy_class_code, " {\n"); + Printf(proxy_class_code, " }\n\n"); - if (!gencomma) // We must have a default constructor - have_default_constructor_flag = true; + if (!gencomma) // We must have a default constructor + have_default_constructor_flag = true; - Delete (overloaded_name); - Delete (imcall); - Delete (throws_hash); + Delete(overloaded_name); + Delete(imcall); + Delete(throws_hash); } return SWIG_OK; @@ -3140,14 +2926,12 @@ MODULA3 (): * destructorHandler() * ---------------------------------------------------------------------- */ - virtual int destructorHandler (Node * n) - { - Language::destructorHandler (n); - String *symname = Getattr (n, "sym:name"); + virtual int destructorHandler(Node *n) { + Language::destructorHandler(n); + String *symname = Getattr(n, "sym:name"); if (proxy_flag) { - Printv (destructor_call, m3raw_name, ".", Swig_name_destroy (symname), - "(swigCPtr)", NIL); + Printv(destructor_call, m3raw_name, ".", Swig_name_destroy(symname), "(swigCPtr)", NIL); } return SWIG_OK; } @@ -3156,66 +2940,63 @@ MODULA3 (): * membervariableHandler() * ---------------------------------------------------------------------- */ - virtual int membervariableHandler (Node * n) - { + virtual int membervariableHandler(Node *n) { //printf("begin membervariableHandler(%s)\n", Char(Getattr(n,"name"))); - SwigType *t = Getattr (n, "type"); + SwigType *t = Getattr(n, "type"); String *tm; // Get the variable type - if ((tm = getMappedTypeNew (n, "m3wraptype", ""))) { - substituteClassname (t, tm); + if ((tm = getMappedTypeNew(n, "m3wraptype", ""))) { + substituteClassname(t, tm); } - variable_name = Getattr (n, "sym:name"); + variable_name = Getattr(n, "sym:name"); //printf("member variable: %s\n", Char(variable_name)); // Output the property's field declaration and accessor methods - Printf (proxy_class_code, " public %s %s {", tm, variable_name); + Printf(proxy_class_code, " public %s %s {", tm, variable_name); - Setattr (n, "modula3:functype", "accessor"); + Setattr(n, "modula3:functype", "accessor"); wrapping_member_flag = true; variable_wrapper_flag = true; - Language::membervariableHandler (n); + Language::membervariableHandler(n); wrapping_member_flag = false; variable_wrapper_flag = false; - Printf (proxy_class_code, "\n }\n\n"); + Printf(proxy_class_code, "\n }\n\n"); { - String *methods = getMethodDeclarations (n); - String *overrides = getAttrString (parentNode (n), "modula3:override"); - SwigType *type = Getattr (n, "type"); - String *m3name = capitalizeFirst (variable_name); + String *methods = getMethodDeclarations(n); + String *overrides = getAttrString(parentNode(n), "modula3:override"); + SwigType *type = Getattr(n, "type"); + String *m3name = capitalizeFirst(variable_name); //String *m3name = nameToModula3(variable_name,true); - if (!SwigType_isconst (type)) { - { - String *inmode = getMappedTypeNew (n, "m3wrapinmode", "", false); - String *intype = getMappedTypeNew (n, "m3wrapintype", ""); - Printf (methods, "set%s(%s val:%s);\n", - m3name, (inmode != NIL) ? (const String *) inmode : "", - intype); - } - { - /* this was attached by functionWrapper - invoked by Language::memberfunctionHandler */ - String *fname = Getattr (n, "modula3:setname"); - Printf (overrides, "set%s := %s;\n", m3name, fname); - } + if (!SwigType_isconst(type)) { + { + String *inmode = getMappedTypeNew(n, "m3wrapinmode", "", false); + String *intype = getMappedTypeNew(n, "m3wrapintype", ""); + Printf(methods, "set%s(%s val:%s);\n", m3name, (inmode != NIL) ? (const String *) inmode : "", intype); + } + { + /* this was attached by functionWrapper + invoked by Language::memberfunctionHandler */ + String *fname = Getattr(n, "modula3:setname"); + Printf(overrides, "set%s := %s;\n", m3name, fname); + } } { - { - String *outtype = getMappedTypeNew (n, "m3wrapouttype", ""); - Printf (methods, "get%s():%s;\n", m3name, outtype); - } - { - /* this was attached by functionWrapper - invoked by Language::memberfunctionHandler */ - String *fname = Getattr (n, "modula3:getname"); - Printf (overrides, "get%s := %s;\n", m3name, fname); - } + { + String *outtype = getMappedTypeNew(n, "m3wrapouttype", ""); + Printf(methods, "get%s():%s;\n", m3name, outtype); + } + { + /* this was attached by functionWrapper + invoked by Language::memberfunctionHandler */ + String *fname = Getattr(n, "modula3:getname"); + Printf(overrides, "get%s := %s;\n", m3name, fname); + } } - Delete (m3name); + Delete(m3name); } //printf("end membervariableHandler(%s)\n", Char(Getattr(n,"name"))); @@ -3226,32 +3007,30 @@ MODULA3 (): * staticmembervariableHandler() * ---------------------------------------------------------------------- */ - virtual int staticmembervariableHandler (Node * n) - { + virtual int staticmembervariableHandler(Node *n) { - bool static_const_member_flag = (Getattr (n, "value") == 0); + bool static_const_member_flag = (Getattr(n, "value") == 0); if (static_const_member_flag) { - SwigType *t = Getattr (n, "type"); + SwigType *t = Getattr(n, "type"); String *tm; // Get the variable type - if ((tm = getMappedTypeNew (n, "m3wraptype", ""))) { - substituteClassname (t, tm); + if ((tm = getMappedTypeNew(n, "m3wraptype", ""))) { + substituteClassname(t, tm); } // Output the property's field declaration and accessor methods - Printf (proxy_class_code, " public static %s %s {", tm, - Getattr (n, "sym:name")); + Printf(proxy_class_code, " public static %s %s {", tm, Getattr(n, "sym:name")); } - variable_name = Getattr (n, "sym:name"); + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; static_flag = true; - Language::staticmembervariableHandler (n); + Language::staticmembervariableHandler(n); wrapping_member_flag = false; static_flag = false; if (static_const_member_flag) - Printf (proxy_class_code, "\n }\n\n"); + Printf(proxy_class_code, "\n }\n\n"); return SWIG_OK; } @@ -3260,11 +3039,10 @@ MODULA3 (): * memberconstantHandler() * ---------------------------------------------------------------------- */ - virtual int memberconstantHandler (Node * n) - { - variable_name = Getattr (n, "sym:name"); + virtual int memberconstantHandler(Node *n) { + variable_name = Getattr(n, "sym:name"); wrapping_member_flag = true; - Language::memberconstantHandler (n); + Language::memberconstantHandler(n); wrapping_member_flag = false; return SWIG_OK; } @@ -3273,12 +3051,11 @@ MODULA3 (): * getOverloadedName() * ----------------------------------------------------------------------------- */ - String *getOverloadedName (Node * n) - { - String *overloaded_name = Copy (Getattr (n, "sym:name")); + String *getOverloadedName(Node *n) { + String *overloaded_name = Copy(Getattr(n, "sym:name")); - if (Getattr (n, "sym:overloaded")) { - Printv (overloaded_name, Getattr (n, "sym:overname"), NIL); + if (Getattr(n, "sym:overloaded")) { + Printv(overloaded_name, Getattr(n, "sym:overname"), NIL); } return overloaded_name; @@ -3289,63 +3066,62 @@ MODULA3 (): * It is also used for set and get methods of global variables. * ----------------------------------------------------------------------------- */ - void emitM3Wrapper (Node * n, const String * func_name) - { - SwigType *t = Getattr (n, "type"); - ParmList *l = Getattr (n, "parms"); - Hash *throws_hash = NewHash (); + void emitM3Wrapper(Node *n, const String *func_name) { + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + Hash *throws_hash = NewHash(); int num_exceptions = 0; int num_returns = 0; - String *rawcall = NewString (""); - String *reccall = NewString (""); - String *local_variables = NewString (""); - String *local_constants = NewString (""); - String *incheck = NewString (""); - String *outcheck = NewString (""); - String *setup = NewString (""); - String *cleanup = NewString (""); - String *outarg = NewString (""); /* don't mix up with 'autark' :-] */ - String *storeout = NewString (""); - String *result_name = NewString (""); - String *return_variables = NewString (""); + String *rawcall = NewString(""); + String *reccall = NewString(""); + String *local_variables = NewString(""); + String *local_constants = NewString(""); + String *incheck = NewString(""); + String *outcheck = NewString(""); + String *setup = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); /* don't mix up with 'autark' :-] */ + String *storeout = NewString(""); + String *result_name = NewString(""); + String *return_variables = NewString(""); const char *result_return = "ret"; - String *function_code = NewString (""); + String *function_code = NewString(""); /*several names for the same function */ - String *raw_name = Getattr (n, "name"); /*original C function name */ + String *raw_name = Getattr(n, "name"); /*original C function name */ //String *func_name = Getattr(n,"sym:name"); /*final Modula3 name chosen by the user*/ bool setter_flag = false; - int multiretval = GetFlag (n, "feature:modula3:multiretval"); + int multiretval = GetFlag(n, "feature:modula3:multiretval"); if (l) { - if (SwigType_type (Getattr (l, "type")) == T_VOID) { - l = nextSibling (l); + if (SwigType_type(Getattr(l, "type")) == T_VOID) { + l = nextSibling(l); } } /* Attach the non-standard typemaps to the parameter list */ - Swig_typemap_attach_parms ("m3wrapargvar", l, NULL); - Swig_typemap_attach_parms ("m3wrapargconst", l, NULL); - Swig_typemap_attach_parms ("m3wrapargraw", l, NULL); - Swig_typemap_attach_parms ("m3wrapargdir", l, NULL); - Swig_typemap_attach_parms ("m3wrapinmode", l, NULL); - Swig_typemap_attach_parms ("m3wrapinname", l, NULL); - Swig_typemap_attach_parms ("m3wrapintype", l, NULL); - Swig_typemap_attach_parms ("m3wrapindefault", l, NULL); - Swig_typemap_attach_parms ("m3wrapinconv", l, NULL); - Swig_typemap_attach_parms ("m3wrapincheck", l, NULL); - Swig_typemap_attach_parms ("m3wrapoutname", l, NULL); - Swig_typemap_attach_parms ("m3wrapouttype", l, NULL); - Swig_typemap_attach_parms ("m3wrapoutconv", l, NULL); - Swig_typemap_attach_parms ("m3wrapoutcheck", l, NULL); + Swig_typemap_attach_parms("m3wrapargvar", l, NULL); + Swig_typemap_attach_parms("m3wrapargconst", l, NULL); + Swig_typemap_attach_parms("m3wrapargraw", l, NULL); + Swig_typemap_attach_parms("m3wrapargdir", l, NULL); + Swig_typemap_attach_parms("m3wrapinmode", l, NULL); + Swig_typemap_attach_parms("m3wrapinname", l, NULL); + Swig_typemap_attach_parms("m3wrapintype", l, NULL); + Swig_typemap_attach_parms("m3wrapindefault", l, NULL); + Swig_typemap_attach_parms("m3wrapinconv", l, NULL); + Swig_typemap_attach_parms("m3wrapincheck", l, NULL); + Swig_typemap_attach_parms("m3wrapoutname", l, NULL); + Swig_typemap_attach_parms("m3wrapouttype", l, NULL); + Swig_typemap_attach_parms("m3wrapoutconv", l, NULL); + Swig_typemap_attach_parms("m3wrapoutcheck", l, NULL); - attachMappedType (n, "m3wrapretraw"); - attachMappedType (n, "m3wrapretname"); - attachMappedType (n, "m3wraprettype"); - attachMappedType (n, "m3wrapretvar"); - attachMappedType (n, "m3wrapretconv"); - attachMappedType (n, "m3wrapretcheck"); + attachMappedType(n, "m3wrapretraw"); + attachMappedType(n, "m3wrapretname"); + attachMappedType(n, "m3wraprettype"); + attachMappedType(n, "m3wrapretvar"); + attachMappedType(n, "m3wrapretconv"); + attachMappedType(n, "m3wrapretcheck"); - Swig_typemap_attach_parms ("m3wrapfreearg", l, NULL); + Swig_typemap_attach_parms("m3wrapfreearg", l, NULL); /* Swig_typemap_attach_parms("m3wrapargvar:throws", l, NULL); @@ -3364,77 +3140,70 @@ MODULA3 (): /* Attach argument names to the parameter list */ /* should be a separate procedure making use of hashes */ - attachParameterNames (n, "tmap:m3wrapinname", "autoname", "arg%d"); + attachParameterNames(n, "tmap:m3wrapinname", "autoname", "arg%d"); /* Get return types */ - String *result_m3rawtype = - Copy (getMappedTypeNew (n, "m3rawrettype", "")); - String *result_m3wraptype = - Copy (getMappedTypeNew (n, "m3wraprettype", "")); - bool has_return_raw = hasContent (result_m3rawtype); - bool has_return_m3 = hasContent (result_m3wraptype); + String *result_m3rawtype = Copy(getMappedTypeNew(n, "m3rawrettype", "")); + String *result_m3wraptype = Copy(getMappedTypeNew(n, "m3wraprettype", "")); + bool has_return_raw = hasContent(result_m3rawtype); + bool has_return_m3 = hasContent(result_m3wraptype); if (has_return_m3) { num_returns++; //printf("%s: %s\n", Char(func_name),Char(result_m3wraptype)); } - String *arguments = createM3Signature (n); + String *arguments = createM3Signature(n); /* Create local variables or RECORD fields for return values and determine return type that might result from a converted VAR argument. */ { writeArgState state; if (multiretval && has_return_m3) { - writeArg (return_variables, state, NIL, NewString (result_return), - result_m3wraptype, NIL); + writeArg(return_variables, state, NIL, NewString(result_return), result_m3wraptype, NIL); } - Parm *p = skipIgnored (l, "m3wrapouttype"); + Parm *p = skipIgnored(l, "m3wrapouttype"); while (p != NIL) { - String *arg = Getattr (p, "tmap:m3wrapoutname"); - if (arg == NIL) { - arg = Getattr (p, "name"); - } + String *arg = Getattr(p, "tmap:m3wrapoutname"); + if (arg == NIL) { + arg = Getattr(p, "name"); + } - String *tm = Getattr (p, "tmap:m3wrapouttype"); - if (tm != NIL) { - if (isOutParam (p)) { - if (!multiretval) { - if (num_returns == 0) { - Printv (result_name, arg, NIL); - Clear (result_m3wraptype); - Printv (result_m3wraptype, tm, NIL); - } else { - Swig_warning (WARN_MODULA3_TYPEMAP_MULTIPLE_RETURN, - input_file, line_number, - "Typemap m3wrapargdir set to 'out' for %s implies a RETURN value, but the routine %s has already one.\nUse %%multiretval feature.\n", - SwigType_str (Getattr (p, "type"), 0), - raw_name); - } - } - num_returns++; - addImports (m3wrap_intf.import, "m3wrapouttype", p); - writeArg (return_variables, state, NIL, arg, tm, NIL); - } - p = - skipIgnored (Getattr (p, "tmap:m3wrapouttype:next"), - "m3wrapouttype"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapouttype"); + if (tm != NIL) { + if (isOutParam(p)) { + if (!multiretval) { + if (num_returns == 0) { + Printv(result_name, arg, NIL); + Clear(result_m3wraptype); + Printv(result_m3wraptype, tm, NIL); + } else { + Swig_warning(WARN_MODULA3_TYPEMAP_MULTIPLE_RETURN, + input_file, line_number, + "Typemap m3wrapargdir set to 'out' for %s implies a RETURN value, but the routine %s has already one.\nUse %%multiretval feature.\n", + SwigType_str(Getattr(p, "type"), 0), raw_name); + } + } + num_returns++; + addImports(m3wrap_intf.import, "m3wrapouttype", p); + writeArg(return_variables, state, NIL, arg, tm, NIL); + } + p = skipIgnored(Getattr(p, "tmap:m3wrapouttype:next"), "m3wrapouttype"); + } else { + p = nextSibling(p); + } } - writeArg (return_variables, state, NIL, NIL, NIL, NIL); + writeArg(return_variables, state, NIL, NIL, NIL, NIL); if (multiretval) { - Printv (result_name, "result", NIL); - Printf (result_m3wraptype, "%sResult", func_name); - m3wrap_intf.enterBlock (blocktype); - Printf (m3wrap_intf.f, "%s =\nRECORD\n%sEND;\n", - result_m3wraptype, return_variables); - Printf (local_variables, "%s: %s;\n", result_name, result_m3wraptype); + Printv(result_name, "result", NIL); + Printf(result_m3wraptype, "%sResult", func_name); + m3wrap_intf.enterBlock(blocktype); + Printf(m3wrap_intf.f, "%s =\nRECORD\n%sEND;\n", result_m3wraptype, return_variables); + Printf(local_variables, "%s: %s;\n", result_name, result_m3wraptype); } else { - Append (local_variables, return_variables); + Append(local_variables, return_variables); } } @@ -3443,47 +3212,47 @@ MODULA3 (): Parm *p = l; while (p != NIL) { - String *arg = Getattr (p, "autoname"); + String *arg = Getattr(p, "autoname"); - String *tm = Getattr (p, "tmap:m3wrapargconst"); - if (tm != NIL) { - addImports (m3wrap_impl.import, "m3wrapargconst", p); - Replaceall (tm, "$input", arg); - Printv (local_constants, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapargconst:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapargconst"); + if (tm != NIL) { + addImports(m3wrap_impl.import, "m3wrapargconst", p); + Replaceall(tm, "$input", arg); + Printv(local_constants, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapargconst:next"); + } else { + p = nextSibling(p); + } } } /* Declare local variables e.g. for converted input values. */ { - String *tm = getMappedTypeNew (n, "m3wrapretvar", "", false); + String *tm = getMappedTypeNew(n, "m3wrapretvar", "", false); if (tm != NIL) { - addImports (m3wrap_impl.import, "m3wrapretvar", n); - addThrows (throws_hash, "m3wrapretvar", n); - Printv (local_variables, tm, "\n", NIL); + addImports(m3wrap_impl.import, "m3wrapretvar", n); + addThrows(throws_hash, "m3wrapretvar", n); + Printv(local_variables, tm, "\n", NIL); } Parm *p = l; while (p != NIL) { - String *arg = Getattr (p, "autoname"); + String *arg = Getattr(p, "autoname"); - tm = Getattr (p, "tmap:m3wrapargvar"); - if (tm != NIL) { - /* exceptions that may be raised but can't be catched, - thus we won't count them in num_exceptions */ - addImports (m3wrap_impl.import, "m3wrapargvar", p); - addThrows (throws_hash, "m3wrapargvar", p); - Replaceall (tm, "$input", arg); - Printv (local_variables, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapargvar:next"); - } else { - p = nextSibling (p); - } + tm = Getattr(p, "tmap:m3wrapargvar"); + if (tm != NIL) { + /* exceptions that may be raised but can't be catched, + thus we won't count them in num_exceptions */ + addImports(m3wrap_impl.import, "m3wrapargvar", p); + addThrows(throws_hash, "m3wrapargvar", p); + Replaceall(tm, "$input", arg); + Printv(local_variables, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapargvar:next"); + } else { + p = nextSibling(p); + } } } @@ -3493,18 +3262,18 @@ MODULA3 (): Parm *p = l; while (p != NIL) { - String *arg = Getattr (p, "autoname"); + String *arg = Getattr(p, "autoname"); - String *tm = Getattr (p, "tmap:m3wrapinconv"); - if (tm != NIL) { - addImports (m3wrap_impl.import, "m3wrapinconv", p); - num_exceptions += addThrows (throws_hash, "m3wrapinconv", p); - Replaceall (tm, "$input", arg); - Printv (setup, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapinconv:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapinconv"); + if (tm != NIL) { + addImports(m3wrap_impl.import, "m3wrapinconv", p); + num_exceptions += addThrows(throws_hash, "m3wrapinconv", p); + Replaceall(tm, "$input", arg); + Printv(setup, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapinconv:next"); + } else { + p = nextSibling(p); + } } } @@ -3514,90 +3283,90 @@ MODULA3 (): Parm *p = l; while (p != NIL) { - String *arg = Getattr (p, "autoname"); + String *arg = Getattr(p, "autoname"); - String *tm = Getattr (p, "tmap:m3wrapincheck"); - if (tm != NIL) { - addImports (m3wrap_impl.import, "m3wrapincheck", p); - num_exceptions += addThrows (throws_hash, "m3wrapincheck", p); - Replaceall (tm, "$input", arg); - Printv (incheck, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapincheck:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapincheck"); + if (tm != NIL) { + addImports(m3wrap_impl.import, "m3wrapincheck", p); + num_exceptions += addThrows(throws_hash, "m3wrapincheck", p); + Replaceall(tm, "$input", arg); + Printv(incheck, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapincheck:next"); + } else { + p = nextSibling(p); + } } } - Printv (rawcall, m3raw_name, ".", func_name, "(", NIL); + Printv(rawcall, m3raw_name, ".", func_name, "(", NIL); /* Arguments to the raw C function */ { bool gencomma = false; Parm *p = l; while (p != NIL) { - if (gencomma) { - Printf (rawcall, ", "); - } - gencomma = true; - addImports (m3wrap_impl.import, "m3wrapargraw", p); - num_exceptions += addThrows (throws_hash, "m3wrapargraw", p); + if (gencomma) { + Printf(rawcall, ", "); + } + gencomma = true; + addImports(m3wrap_impl.import, "m3wrapargraw", p); + num_exceptions += addThrows(throws_hash, "m3wrapargraw", p); - String *arg = Getattr (p, "autoname"); - String *qualarg = NewString (""); - if (!isInParam (p)) { - String *tmparg = Getattr (p, "tmap:m3wrapoutname"); - if (tmparg != NIL) { - arg = tmparg; - } - if (multiretval /*&& isOutParam(p) - automatically fulfilled */ ) { - Printf (qualarg, "%s.", result_name); - } - } - Append (qualarg, arg); - Setattr (p, "m3outarg", qualarg); + String *arg = Getattr(p, "autoname"); + String *qualarg = NewString(""); + if (!isInParam(p)) { + String *tmparg = Getattr(p, "tmap:m3wrapoutname"); + if (tmparg != NIL) { + arg = tmparg; + } + if (multiretval /*&& isOutParam(p) - automatically fulfilled */ ) { + Printf(qualarg, "%s.", result_name); + } + } + Append(qualarg, arg); + Setattr(p, "m3outarg", qualarg); - String *tm = Getattr (p, "tmap:m3wrapargraw"); - if (tm != NIL) { - Replaceall (tm, "$input", arg); - Replaceall (tm, "$output", qualarg); - Printv (rawcall, tm, NIL); - p = Getattr (p, "tmap:m3wrapargraw:next"); - } else { - //Printv(rawcall, Getattr(p,"lname"), NIL); - Printv (rawcall, qualarg, NIL); - p = nextSibling (p); - } - Delete (qualarg); + String *tm = Getattr(p, "tmap:m3wrapargraw"); + if (tm != NIL) { + Replaceall(tm, "$input", arg); + Replaceall(tm, "$output", qualarg); + Printv(rawcall, tm, NIL); + p = Getattr(p, "tmap:m3wrapargraw:next"); + } else { + //Printv(rawcall, Getattr(p,"lname"), NIL); + Printv(rawcall, qualarg, NIL); + p = nextSibling(p); + } + Delete(qualarg); } } - Printf (rawcall, ")"); + Printf(rawcall, ")"); /* Check for error codes and integrity of results */ { - String *tm = getMappedTypeNew (n, "m3wrapretcheck", "", false); + String *tm = getMappedTypeNew(n, "m3wrapretcheck", "", false); if (tm != NIL) { - addImports (m3wrap_impl.import, "m3wrapretcheck", n); - num_exceptions += addThrows (throws_hash, "m3wrapretcheck", n); - Printv (outcheck, tm, "\n", NIL); + addImports(m3wrap_impl.import, "m3wrapretcheck", n); + num_exceptions += addThrows(throws_hash, "m3wrapretcheck", n); + Printv(outcheck, tm, "\n", NIL); } Parm *p = l; while (p != NIL) { - tm = Getattr (p, "tmap:m3wrapoutcheck"); - if (tm != NIL) { - String *arg = Getattr (p, "autoname"); - String *outarg = Getattr (p, "m3outarg"); - addImports (m3wrap_impl.import, "m3wrapoutcheck", p); - num_exceptions += addThrows (throws_hash, "m3wrapoutcheck", p); - //substituteClassname(Getattr(p,"type"), tm); - Replaceall (tm, "$input", arg); - Replaceall (tm, "$output", outarg); - Printv (outcheck, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapoutcheck:next"); - } else { - p = nextSibling (p); - } + tm = Getattr(p, "tmap:m3wrapoutcheck"); + if (tm != NIL) { + String *arg = Getattr(p, "autoname"); + String *outarg = Getattr(p, "m3outarg"); + addImports(m3wrap_impl.import, "m3wrapoutcheck", p); + num_exceptions += addThrows(throws_hash, "m3wrapoutcheck", p); + //substituteClassname(Getattr(p,"type"), tm); + Replaceall(tm, "$input", arg); + Replaceall(tm, "$output", outarg); + Printv(outcheck, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapoutcheck:next"); + } else { + p = nextSibling(p); + } } } @@ -3608,20 +3377,20 @@ MODULA3 (): when it is clear if there is some output conversion and checking code */ Parm *p = l; while (p != NIL) { - String *tm = Getattr (p, "tmap:m3wrapoutconv"); - if (tm != NIL) { - String *arg = Getattr (p, "autoname"); - String *outarg = Getattr (p, "m3outarg"); - addImports (m3wrap_impl.import, "m3wrapoutconv", n); - num_exceptions += addThrows (throws_hash, "m3wrapoutconv", p); - //substituteClassname(Getattr(p,"type"), tm); - Replaceall (tm, "$input", arg); - Replaceall (tm, "$output", outarg); - Printf (storeout, "%s := %s;\n", outarg, tm); - p = Getattr (p, "tmap:m3wrapoutconv:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapoutconv"); + if (tm != NIL) { + String *arg = Getattr(p, "autoname"); + String *outarg = Getattr(p, "m3outarg"); + addImports(m3wrap_impl.import, "m3wrapoutconv", n); + num_exceptions += addThrows(throws_hash, "m3wrapoutconv", p); + //substituteClassname(Getattr(p,"type"), tm); + Replaceall(tm, "$input", arg); + Replaceall(tm, "$output", outarg); + Printf(storeout, "%s := %s;\n", outarg, tm); + p = Getattr(p, "tmap:m3wrapoutconv:next"); + } else { + p = nextSibling(p); + } } } @@ -3629,20 +3398,20 @@ MODULA3 (): { Parm *p = l; while (p != NIL) { - String *tm = Getattr (p, "tmap:m3wrapfreearg"); - if (tm != NIL) { - String *arg = Getattr (p, "autoname"); - String *outarg = Getattr (p, "m3outarg"); - addImports (m3wrap_impl.import, "m3wrapfreearg", p); - num_exceptions += addThrows (throws_hash, "m3wrapfreearg", p); - //substituteClassname(Getattr(p,"type"), tm); - Replaceall (tm, "$input", arg); - Replaceall (tm, "$output", outarg); - Printv (cleanup, tm, "\n", NIL); - p = Getattr (p, "tmap:m3wrapfreearg:next"); - } else { - p = nextSibling (p); - } + String *tm = Getattr(p, "tmap:m3wrapfreearg"); + if (tm != NIL) { + String *arg = Getattr(p, "autoname"); + String *outarg = Getattr(p, "m3outarg"); + addImports(m3wrap_impl.import, "m3wrapfreearg", p); + num_exceptions += addThrows(throws_hash, "m3wrapfreearg", p); + //substituteClassname(Getattr(p,"type"), tm); + Replaceall(tm, "$input", arg); + Replaceall(tm, "$output", outarg); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:m3wrapfreearg:next"); + } else { + p = nextSibling(p); + } } } @@ -3651,169 +3420,166 @@ MODULA3 (): could help returning the return value. */ /* Receive result from call to raw library function */ if (!has_return_raw) { - /* - rawcall(arg1); - result.val := arg1; - RETURN result; - */ - /* - rawcall(arg1); - RETURN arg1; - */ - Printf (reccall, "%s;\n", rawcall); + /* + rawcall(arg1); + result.val := arg1; + RETURN result; + */ + /* + rawcall(arg1); + RETURN arg1; + */ + Printf(reccall, "%s;\n", rawcall); - if (hasContent (result_name)) { - Printf (outarg, "RETURN %s;\n", result_name); - } + if (hasContent(result_name)) { + Printf(outarg, "RETURN %s;\n", result_name); + } } else { - /* - arg0 := rawcall(arg1); - result.ret := Convert(arg0); - result.val := arg1; - RETURN result; - */ - /* - arg0 := rawcall(); - RETURN Convert(arg0); - */ - /* - RETURN rawcall(); - */ - String *return_raw = getMappedTypeNew (n, "m3wrapretraw", "", false); - String *return_conv = - getMappedTypeNew (n, "m3wrapretconv", "", false); + /* + arg0 := rawcall(arg1); + result.ret := Convert(arg0); + result.val := arg1; + RETURN result; + */ + /* + arg0 := rawcall(); + RETURN Convert(arg0); + */ + /* + RETURN rawcall(); + */ + String *return_raw = getMappedTypeNew(n, "m3wrapretraw", "", false); + String *return_conv = getMappedTypeNew(n, "m3wrapretconv", "", false); - /* immediate RETURN would skip result checking */ - if ((hasContent (outcheck) || hasContent (storeout) - || hasContent (cleanup)) && (!hasContent (result_name)) - && (return_raw == NIL)) { - Printv (result_name, "result", NIL); - Printf (local_variables, "%s: %s;\n", result_name, - result_m3wraptype); - } + /* immediate RETURN would skip result checking */ + if ((hasContent(outcheck) || hasContent(storeout) + || hasContent(cleanup)) && (!hasContent(result_name)) + && (return_raw == NIL)) { + Printv(result_name, "result", NIL); + Printf(local_variables, "%s: %s;\n", result_name, result_m3wraptype); + } - String *result_lvalue = Copy (result_name); - if (multiretval) { - Printf (result_lvalue, ".%s", result_return); - } - if (return_raw != NIL) { - Printf (reccall, "%s := %s;\n", return_raw, rawcall); - } else if (hasContent (result_name)) { - Printf (reccall, "%s := %s;\n", result_lvalue, rawcall); - } else { - Printf (outarg, "RETURN %s;\n", rawcall); - } - if (return_conv != NIL) { - addImports (m3wrap_impl.import, "m3wrapretconv", n); - num_exceptions += addThrows (throws_hash, "m3wrapretconv", n); - if (hasContent (result_name)) { - Printf (reccall, "%s := %s;\n", result_lvalue, return_conv); - Printf (outarg, "RETURN %s;\n", result_name); - } else { - Printf (outarg, "RETURN %s;\n", return_conv); - } - } else { - if (hasContent (result_name)) { - Printf (outarg, "RETURN %s;\n", result_name); - } - } + String *result_lvalue = Copy(result_name); + if (multiretval) { + Printf(result_lvalue, ".%s", result_return); + } + if (return_raw != NIL) { + Printf(reccall, "%s := %s;\n", return_raw, rawcall); + } else if (hasContent(result_name)) { + Printf(reccall, "%s := %s;\n", result_lvalue, rawcall); + } else { + Printf(outarg, "RETURN %s;\n", rawcall); + } + if (return_conv != NIL) { + addImports(m3wrap_impl.import, "m3wrapretconv", n); + num_exceptions += addThrows(throws_hash, "m3wrapretconv", n); + if (hasContent(result_name)) { + Printf(reccall, "%s := %s;\n", result_lvalue, return_conv); + Printf(outarg, "RETURN %s;\n", result_name); + } else { + Printf(outarg, "RETURN %s;\n", return_conv); + } + } else { + if (hasContent(result_name)) { + Printf(outarg, "RETURN %s;\n", result_name); + } + } } } /* Create procedure header */ { - String *header = NewStringf ("PROCEDURE %s (%s)", - func_name, arguments); + String *header = NewStringf("PROCEDURE %s (%s)", + func_name, arguments); if ((num_returns > 0) || multiretval) { - Printf (header, ": %s", result_m3wraptype); + Printf(header, ": %s", result_m3wraptype); } - generateThrowsClause (throws_hash, header); + generateThrowsClause(throws_hash, header); - Append (function_code, header); + Append(function_code, header); - m3wrap_intf.enterBlock (no_block); - Printf (m3wrap_intf.f, "%s;\n\n", header, NIL); + m3wrap_intf.enterBlock(no_block); + Printf(m3wrap_intf.f, "%s;\n\n", header, NIL); } { - String *body = NewStringf ("%s%s%s%s%s", - incheck, - setup, - reccall, - outcheck, - storeout); + String *body = NewStringf("%s%s%s%s%s", + incheck, + setup, + reccall, + outcheck, + storeout); String *exc_handler; - if (hasContent (cleanup) && (num_exceptions > 0)) { - exc_handler = NewStringf ("TRY\n%sFINALLY\n%sEND;\n", body, cleanup); + if (hasContent(cleanup) && (num_exceptions > 0)) { + exc_handler = NewStringf("TRY\n%sFINALLY\n%sEND;\n", body, cleanup); } else { - exc_handler = NewStringf ("%s%s", body, cleanup); + exc_handler = NewStringf("%s%s", body, cleanup); } - Printf (function_code, " =\n%s%s%s%sBEGIN\n%s%sEND %s;\n\n", - hasContent (local_constants) ? "CONST\n" : "", local_constants, - hasContent (local_variables) ? "VAR\n" : "", local_variables, - exc_handler, outarg, func_name); + Printf(function_code, " =\n%s%s%s%sBEGIN\n%s%sEND %s;\n\n", + hasContent(local_constants) ? "CONST\n" : "", local_constants, + hasContent(local_variables) ? "VAR\n" : "", local_variables, exc_handler, outarg, func_name); - Delete (exc_handler); - Delete (body); + Delete(exc_handler); + Delete(body); } - m3wrap_impl.enterBlock (no_block); + m3wrap_impl.enterBlock(no_block); if (proxy_flag && global_variable_flag) { // Properties if (setter_flag) { - // Setter method - String *tm = getMappedTypeNew (n, "m3varin", ""); - if (tm != NIL) { - if (GetFlag (n, "feature:new")) { - Replaceall (tm, "$owner", "true"); - } else { - Replaceall (tm, "$owner", "false"); - } - substituteClassname (t, tm); - Replaceall (tm, "$rawcall", rawcall); - Replaceall (tm, "$vartype", variable_type); /* $type is already replaced by some super class */ - Replaceall (tm, "$var", variable_name); - Printf (m3wrap_impl.f, "%s", tm); - } + // Setter method + String *tm = getMappedTypeNew(n, "m3varin", ""); + if (tm != NIL) { + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "true"); + } else { + Replaceall(tm, "$owner", "false"); + } + substituteClassname(t, tm); + Replaceall(tm, "$rawcall", rawcall); + Replaceall(tm, "$vartype", variable_type); /* $type is already replaced by some super class */ + Replaceall(tm, "$var", variable_name); + Printf(m3wrap_impl.f, "%s", tm); + } } else { - // Getter method - String *tm = getMappedTypeNew (n, "m3varout", ""); - if (tm != NIL) { - if (GetFlag (n, "feature:new")) - Replaceall (tm, "$owner", "true"); - else - Replaceall (tm, "$owner", "false"); - substituteClassname (t, tm); - Replaceall (tm, "$rawcall", rawcall); - Replaceall (tm, "$vartype", variable_type); - Replaceall (tm, "$var", variable_name); - Printf (m3wrap_impl.f, "%s", tm); - } + // Getter method + String *tm = getMappedTypeNew(n, "m3varout", ""); + if (tm != NIL) { + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "true"); + else + Replaceall(tm, "$owner", "false"); + substituteClassname(t, tm); + Replaceall(tm, "$rawcall", rawcall); + Replaceall(tm, "$vartype", variable_type); + Replaceall(tm, "$var", variable_name); + Printf(m3wrap_impl.f, "%s", tm); + } } } else { // Normal function call - Printv (m3wrap_impl.f, function_code, NIL); + Printv(m3wrap_impl.f, function_code, NIL); } - Delete (arguments); - Delete (return_variables); - Delete (local_variables); - Delete (local_constants); - Delete (outarg); - Delete (incheck); - Delete (outcheck); - Delete (setup); - Delete (cleanup); - Delete (storeout); - Delete (function_code); - Delete (result_name); - Delete (result_m3wraptype); - Delete (reccall); - Delete (rawcall); - Delete (throws_hash); + Delete(arguments); + Delete(return_variables); + Delete(local_variables); + Delete(local_constants); + Delete(outarg); + Delete(incheck); + Delete(outcheck); + Delete(setup); + Delete(cleanup); + Delete(storeout); + Delete(function_code); + Delete(result_name); + Delete(result_m3wraptype); + Delete(reccall); + Delete(rawcall); + Delete(throws_hash); } /* ----------------------------------------------------------------------------- @@ -3831,31 +3597,30 @@ MODULA3 (): * substitution_performed - flag indicating if a substitution was performed * ----------------------------------------------------------------------------- */ - bool substituteClassname (SwigType * pt, String * tm) - { + bool substituteClassname(SwigType *pt, String *tm) { bool substitution_performed = false; - if (Strstr (tm, "$m3classname") || Strstr (tm, "$&m3classname")) { - String *classname = getProxyName (pt); + if (Strstr(tm, "$m3classname") || Strstr(tm, "$&m3classname")) { + String *classname = getProxyName(pt); if (classname) { - Replaceall (tm, "$&m3classname", classname); // getProxyName() works for pointers to classes too - Replaceall (tm, "$m3classname", classname); - } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. - String *descriptor = NULL; - SwigType *type = Copy (SwigType_typedef_resolve_all (pt)); + Replaceall(tm, "$&m3classname", classname); // getProxyName() works for pointers to classes too + Replaceall(tm, "$m3classname", classname); + } else { // use $descriptor if SWIG does not know anything about this type. Note that any typedefs are resolved. + String *descriptor = NULL; + SwigType *type = Copy(SwigType_typedef_resolve_all(pt)); - if (Strstr (tm, "$&m3classname")) { - SwigType_add_pointer (type); - descriptor = NewStringf ("SWIGTYPE%s", SwigType_manglestr (type)); - Replaceall (tm, "$&m3classname", descriptor); - } else { // $m3classname - descriptor = NewStringf ("SWIGTYPE%s", SwigType_manglestr (type)); - Replaceall (tm, "$m3classname", descriptor); - } + if (Strstr(tm, "$&m3classname")) { + SwigType_add_pointer(type); + descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(type)); + Replaceall(tm, "$&m3classname", descriptor); + } else { // $m3classname + descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(type)); + Replaceall(tm, "$m3classname", descriptor); + } - // Add to hash table so that the type wrapper classes can be created later - Setattr (swig_types_hash, descriptor, type); - Delete (descriptor); - Delete (type); + // Add to hash table so that the type wrapper classes can be created later + Setattr(swig_types_hash, descriptor, type); + Delete(descriptor); + Delete(type); } substitution_performed = true; } @@ -3873,22 +3638,20 @@ MODULA3 (): * arg - a unique parameter name * ----------------------------------------------------------------------------- */ - String *makeParameterName (Node * n, Parm * p, int arg_num) - { + String *makeParameterName(Node *n, Parm *p, int arg_num) { // Use C parameter name unless it is a duplicate or an empty parameter name - String *pn = Getattr (p, "name"); + String *pn = Getattr(p, "name"); int count = 0; - ParmList *plist = Getattr (n, "parms"); + ParmList *plist = Getattr(n, "parms"); while (plist) { - if ((Cmp (pn, Getattr (plist, "name")) == 0)) - count++; - plist = nextSibling (plist); + if ((Cmp(pn, Getattr(plist, "name")) == 0)) + count++; + plist = nextSibling(plist); } - String *arg = (!pn || (count > 1)) ? NewStringf ("arg%d", - arg_num) : - Copy (Getattr (p, - "name")); + String *arg = (!pn || (count > 1)) ? NewStringf("arg%d", + arg_num) : Copy(Getattr(p, + "name")); return arg; } @@ -3907,35 +3670,32 @@ MODULA3 (): * e.g. "arg%d" * ----------------------------------------------------------------------------- */ - void attachParameterNames (Node * n, const char *tmid, const char *nameid, - const char *fmt) - { + void attachParameterNames(Node *n, const char *tmid, const char *nameid, const char *fmt) { /* Use C parameter name if present and unique, otherwise create an 'arg%d' name */ - Hash *hash = NewHash (); - Parm *p = Getattr (n, "parms"); + Hash *hash = NewHash(); + Parm *p = Getattr(n, "parms"); int count = 0; while (p != NIL) { - String *name = Getattr (p, tmid); + String *name = Getattr(p, tmid); if (name == NIL) { - name = Getattr (p, "name"); + name = Getattr(p, "name"); } String *newname; - if ((!hasContent (name)) || (Getattr (hash, name) != NIL)) { - newname = NewStringf (fmt, count); + if ((!hasContent(name)) || (Getattr(hash, name) != NIL)) { + newname = NewStringf(fmt, count); } else { - newname = Copy (name); + newname = Copy(name); } - if (1 == Setattr (hash, newname, "1")) { - Swig_warning (WARN_MODULA3_DOUBLE_ID, input_file, line_number, - "Argument '%s' twice.\n", newname); + if (1 == Setattr(hash, newname, "1")) { + Swig_warning(WARN_MODULA3_DOUBLE_ID, input_file, line_number, "Argument '%s' twice.\n", newname); } - Setattr (p, nameid, newname); + Setattr(p, nameid, newname); // Delete(newname); - p = nextSibling (p); + p = nextSibling(p); count++; } - Delete (hash); + Delete(hash); } /* ----------------------------------------------------------------------------- @@ -3946,34 +3706,32 @@ MODULA3 (): * m3wrapintype, m3wrapinmode, m3wrapindefault * ----------------------------------------------------------------------------- */ - String *createM3Signature (Node * n) - { - String *arguments = NewString (""); - Parm *p = skipIgnored (Getattr (n, "parms"), "m3wrapintype"); + String *createM3Signature(Node *n) { + String *arguments = NewString(""); + Parm *p = skipIgnored(Getattr(n, "parms"), "m3wrapintype"); writeArgState state; while (p != NIL) { /* Get the M3 parameter type */ - String *tm = getMappedType (p, "m3wrapintype"); + String *tm = getMappedType(p, "m3wrapintype"); if (tm != NIL) { - if (isInParam (p)) { - addImports (m3wrap_intf.import, "m3wrapintype", p); - addImports (m3wrap_impl.import, "m3wrapintype", p); - String *mode = Getattr (p, "tmap:m3wrapinmode"); - String *deflt = Getattr (p, "tmap:m3wrapindefault"); - String *arg = Getattr (p, "autoname"); - SwigType *pt = Getattr (p, "type"); - substituteClassname (pt, tm); /* do we need this ? */ + if (isInParam(p)) { + addImports(m3wrap_intf.import, "m3wrapintype", p); + addImports(m3wrap_impl.import, "m3wrapintype", p); + String *mode = Getattr(p, "tmap:m3wrapinmode"); + String *deflt = Getattr(p, "tmap:m3wrapindefault"); + String *arg = Getattr(p, "autoname"); + SwigType *pt = Getattr(p, "type"); + substituteClassname(pt, tm); /* do we need this ? */ - writeArg (arguments, state, mode, arg, tm, deflt); - } - p = - skipIgnored (Getattr (p, "tmap:m3wrapintype:next"), "m3wrapintype"); + writeArg(arguments, state, mode, arg, tm, deflt); + } + p = skipIgnored(Getattr(p, "tmap:m3wrapintype:next"), "m3wrapintype"); } else { - p = nextSibling (p); + p = nextSibling(p); } } - writeArg (arguments, state, NIL, NIL, NIL, NIL); + writeArg(arguments, state, NIL, NIL, NIL, NIL); return (arguments); } @@ -3986,19 +3744,18 @@ MODULA3 (): * Create signature of C function * ----------------------------------------------------------------------------- */ - String *createCSignature (Node * n) - { - String *arguments = NewString (""); + String *createCSignature(Node *n) { + String *arguments = NewString(""); bool gencomma = false; Node *p; - for (p = Getattr (n, "parms"); p != NIL; p = nextSibling (p)) { + for (p = Getattr(n, "parms"); p != NIL; p = nextSibling(p)) { if (gencomma) { - Append (arguments, ","); + Append(arguments, ","); } gencomma = true; - String *type = Getattr (p, "type"); - String *ctype = getMappedTypeNew (type, "ctype"); - Append (arguments, ctype); + String *type = Getattr(p, "type"); + String *ctype = getMappedTypeNew(type, "ctype"); + Append(arguments, ctype); } return arguments; } @@ -4008,65 +3765,60 @@ MODULA3 (): * emitTypeWrapperClass() * ----------------------------------------------------------------------------- */ - void emitTypeWrapperClass (String * classname, SwigType * type) - { - String *filen = - NewStringf ("%s%s.m3", Swig_file_dirname (outfile), classname); - File *f_swigtype = NewFile (filen, "w"); + void emitTypeWrapperClass(String *classname, SwigType *type) { + String *filen = NewStringf("%s%s.m3", Swig_file_dirname(outfile), classname); + File *f_swigtype = NewFile(filen, "w"); if (!f_swigtype) { - FileErrorDisplay (filen); - SWIG_exit (EXIT_FAILURE); + FileErrorDisplay(filen); + SWIG_exit(EXIT_FAILURE); } - String *swigtype = NewString (""); + String *swigtype = NewString(""); // Emit banner name - emitBanner (f_swigtype); + emitBanner(f_swigtype); // Pure Modula 3 baseclass and interfaces - const String *pure_baseclass = typemapLookup ("m3base", type, WARN_NONE); - const String *pure_interfaces = - typemapLookup ("m3interfaces", type, WARN_NONE); + const String *pure_baseclass = typemapLookup("m3base", type, WARN_NONE); + const String *pure_interfaces = typemapLookup("m3interfaces", type, WARN_NONE); // Emit the class - Printv (swigtype, typemapLookup ("m3imports", type, WARN_NONE), // Import statements - "\n", typemapLookup ("m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers - " class $m3classname", // Class name and bases - *Char (pure_baseclass) ? " : " : "", pure_baseclass, *Char (pure_interfaces) ? // Interfaces - " : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup ("m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers - " $m3classname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers - " swigCPtr = cPtr;\n", " }\n", "\n", " protected $m3classname() {\n", // Default constructor - " swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup ("m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method - typemapLookup ("m3code", type, WARN_NONE), // extra Modula 3 code - "}\n", "\n", NIL); + Printv(swigtype, typemapLookup("m3imports", type, WARN_NONE), // Import statements + "\n", typemapLookup("m3classmodifiers", type, WARN_MODULA3_TYPEMAP_CLASSMOD_UNDEF), // Class modifiers + " class $m3classname", // Class name and bases + *Char(pure_baseclass) ? " : " : "", pure_baseclass, *Char(pure_interfaces) ? // Interfaces + " : " : "", pure_interfaces, " {\n", " private IntPtr swigCPtr;\n", "\n", " ", typemapLookup("m3ptrconstructormodifiers", type, WARN_MODULA3_TYPEMAP_PTRCONSTMOD_UNDEF), // pointer constructor modifiers + " $m3classname(IntPtr cPtr, bool bFutureUse) {\n", // Constructor used for wrapping pointers + " swigCPtr = cPtr;\n", " }\n", "\n", " protected $m3classname() {\n", // Default constructor + " swigCPtr = IntPtr.Zero;\n", " }\n", typemapLookup("m3getcptr", type, WARN_MODULA3_TYPEMAP_GETCPTR_UNDEF), // getCPtr method + typemapLookup("m3code", type, WARN_NONE), // extra Modula 3 code + "}\n", "\n", NIL); - Replaceall (swigtype, "$m3classname", classname); - Printv (f_swigtype, swigtype, NIL); + Replaceall(swigtype, "$m3classname", classname); + Printv(f_swigtype, swigtype, NIL); - Close (f_swigtype); - Delete (filen); - Delete (swigtype); + Close(f_swigtype); + Delete(filen); + Delete(swigtype); } /* ----------------------------------------------------------------------------- * typemapLookup() * ----------------------------------------------------------------------------- */ - const String *typemapLookup (const String * op, String * type, int warning, - Node * typemap_attributes = NULL) { + const String *typemapLookup(const String *op, String *type, int warning, Node *typemap_attributes = NULL) { String *tm = NULL; const String *code = NULL; - if ((tm = Swig_typemap_search (op, type, NULL, NULL))) { - code = Getattr (tm, "code"); + if ((tm = Swig_typemap_search(op, type, NULL, NULL))) { + code = Getattr(tm, "code"); if (typemap_attributes) - Swig_typemap_attach_kwargs (tm, op, typemap_attributes); + Swig_typemap_attach_kwargs(tm, op, typemap_attributes); } if (!code) { code = empty_string; if (warning != WARN_NONE) - Swig_warning (warning, input_file, line_number, - "No %s typemap defined for %s\n", op, type); + Swig_warning(warning, input_file, line_number, "No %s typemap defined for %s\n", op, type); } return code ? code : empty_string; @@ -4079,45 +3831,42 @@ MODULA3 (): * Return number the number of these exceptions. * ----------------------------------------------------------------------------- */ - int addThrows (Hash * throws_hash, const String * typemap, Node * parameter) - { + int addThrows(Hash *throws_hash, const String *typemap, Node *parameter) { // Get the comma separated throws clause - held in "throws" attribute in the typemap passed in int len = 0; - String *throws_attribute = NewStringf ("%s:throws", typemap); + String *throws_attribute = NewStringf("%s:throws", typemap); - addImports (m3wrap_intf.import, throws_attribute, parameter); - addImports (m3wrap_impl.import, throws_attribute, parameter); + addImports(m3wrap_intf.import, throws_attribute, parameter); + addImports(m3wrap_impl.import, throws_attribute, parameter); - String *throws = - getMappedTypeNew (parameter, Char (throws_attribute), "", false); + String *throws = getMappedTypeNew(parameter, Char(throws_attribute), "", false); //printf("got exceptions %s for %s\n", Char(throws), Char(throws_attribute)); if (throws) { // Put the exception classes in the throws clause into a temporary List - List *temp_classes_list = Split (throws, ',', INT_MAX); - len = Len (temp_classes_list); + List *temp_classes_list = Split(throws, ',', INT_MAX); + len = Len(temp_classes_list); // Add the exception classes to the node throws list, but don't duplicate if already in list if (temp_classes_list /*&& hasContent(temp_classes_list) */ ) { - for (Iterator cls = First (temp_classes_list); cls.item != NIL; - cls = Next (cls)) { - String *exception_class = NewString (cls.item); - Replaceall (exception_class, " ", ""); // remove spaces - Replaceall (exception_class, "\t", ""); // remove tabs - if (hasContent (exception_class)) { - // $m3classname substitution - SwigType *pt = Getattr (parameter, "type"); - substituteClassname (pt, exception_class); - // Don't duplicate the exception class in the throws clause - //printf("add exception %s\n", Char(exception_class)); - Setattr (throws_hash, exception_class, "1"); - } - Delete (exception_class); - } + for (Iterator cls = First(temp_classes_list); cls.item != NIL; cls = Next(cls)) { + String *exception_class = NewString(cls.item); + Replaceall(exception_class, " ", ""); // remove spaces + Replaceall(exception_class, "\t", ""); // remove tabs + if (hasContent(exception_class)) { + // $m3classname substitution + SwigType *pt = Getattr(parameter, "type"); + substituteClassname(pt, exception_class); + // Don't duplicate the exception class in the throws clause + //printf("add exception %s\n", Char(exception_class)); + Setattr(throws_hash, exception_class, "1"); + } + Delete(exception_class); + } } - Delete (temp_classes_list); + Delete(temp_classes_list); } - Delete (throws_attribute); + Delete(throws_attribute); return len; } @@ -4125,16 +3874,15 @@ MODULA3 (): * generateThrowsClause() * ----------------------------------------------------------------------------- */ - void generateThrowsClause (Hash * throws_hash, String * code) - { + void generateThrowsClause(Hash *throws_hash, String *code) { // Add the throws clause into code - if (Len (throws_hash) > 0) { - Iterator cls = First (throws_hash); - Printf (code, " RAISES {%s", cls.key); - for (cls = Next (cls); cls.key != NIL; cls = Next (cls)) { - Printf (code, ", %s", cls.key); + if (Len(throws_hash) > 0) { + Iterator cls = First(throws_hash); + Printf(code, " RAISES {%s", cls.key); + for (cls = Next(cls); cls.key != NIL; cls = Next(cls)) { + Printf(code, ", %s", cls.key); } - Printf (code, "}"); + Printf(code, "}"); } } @@ -4144,70 +3892,62 @@ MODULA3 (): * Add all imports that are needed for contents of 'typemap'. * ----------------------------------------------------------------------------- */ - void addImports (Hash * imports_hash, const String * typemap, Node * node) - { + void addImports(Hash *imports_hash, const String *typemap, Node *node) { // Get the comma separated throws clause - held in "throws" attribute in the typemap passed in - String *imports_attribute = NewStringf ("%s:import", typemap); - String *imports = - getMappedTypeNew (node, Char (imports_attribute), "", false); + String *imports_attribute = NewStringf("%s:import", typemap); + String *imports = getMappedTypeNew(node, Char(imports_attribute), "", false); //printf("got imports %s for %s\n", Char(imports), Char(imports_attribute)); if (imports != NIL) { - List *import_list = Split (imports, ',', INT_MAX); + List *import_list = Split(imports, ',', INT_MAX); // Add the exception classes to the node imports list, but don't duplicate if already in list if (import_list != NIL) { - for (Iterator imp = First (import_list); imp.item != NIL; - imp = Next (imp)) { - List *import_pair = Split (imp.item, ' ', 3); - if (Len (import_pair) == 1) { - Setattr (imports_hash, Getitem (import_pair, 0), ""); - } else if ((Len (import_pair) == 3) - && Strcmp (Getitem (import_pair, 1), "AS") == 0) { - Setattr (imports_hash, Getitem (import_pair, 0), - Getitem (import_pair, 2)); - } else { - Swig_warning (WARN_MODULA3_BAD_IMPORT, input_file, line_number, - "Malformed import '%s' for typemap '%s' defined for type '%s'\n", - imp, typemap, SwigType_str (Getattr (node, "type"), - 0)); - } - Delete (import_pair); - } + for (Iterator imp = First(import_list); imp.item != NIL; imp = Next(imp)) { + List *import_pair = Split(imp.item, ' ', 3); + if (Len(import_pair) == 1) { + Setattr(imports_hash, Getitem(import_pair, 0), ""); + } else if ((Len(import_pair) == 3) + && Strcmp(Getitem(import_pair, 1), "AS") == 0) { + Setattr(imports_hash, Getitem(import_pair, 0), Getitem(import_pair, 2)); + } else { + Swig_warning(WARN_MODULA3_BAD_IMPORT, input_file, line_number, + "Malformed import '%s' for typemap '%s' defined for type '%s'\n", imp, typemap, SwigType_str(Getattr(node, "type"), 0)); + } + Delete(import_pair); + } } - Delete (import_list); + Delete(import_list); } - Delete (imports_attribute); + Delete(imports_attribute); } /* ----------------------------------------------------------------------------- * emitImportStatements() * ----------------------------------------------------------------------------- */ - void emitImportStatements (Hash * imports_hash, String * code) - { + void emitImportStatements(Hash *imports_hash, String *code) { // Add the imports statements into code - Iterator imp = First (imports_hash); + Iterator imp = First(imports_hash); while (imp.key != NIL) { - Printf (code, "IMPORT %s", imp.key); + Printf(code, "IMPORT %s", imp.key); String *imp_as = imp.item; - if (hasContent (imp_as)) { - Printf (code, " AS %s", imp_as); + if (hasContent(imp_as)) { + Printf(code, " AS %s", imp_as); } - Printf (code, ";\n"); - imp = Next (imp); + Printf(code, ";\n"); + imp = Next(imp); } } -}; /* class MODULA3 */ +}; /* class MODULA3 */ /* ----------------------------------------------------------------------------- * swig_modula3() - Instantiate module * ----------------------------------------------------------------------------- */ -extern "C" Language * swig_modula3 (void) -{ - return new MODULA3 (); +extern "C" Language *swig_modula3(void) { + return new MODULA3(); } /* ----------------------------------------------------------------------------- diff --git a/SWIG/Source/Modules/module.cxx b/SWIG/Source/Modules/module.cxx index 43f3ee1f1..0e7f8cfad 100644 --- a/SWIG/Source/Modules/module.cxx +++ b/SWIG/Source/Modules/module.cxx @@ -12,19 +12,16 @@ char cvsroot_module_cxx[] = "$Header$"; #include "swigmod.h" struct Module { - ModuleFactory fac; - char *name; - Module *next; - Module(const char *n, ModuleFactory f) { + ModuleFactory fac; + char *name; + Module *next; + Module(const char *n, ModuleFactory f) { fac = f; - name = new char[strlen(n)+1]; - strcpy(name, n); - next = 0; - } - - ~Module() - { - delete[] name; + name = new char[strlen(n) + 1]; + strcpy(name, n); + next = 0; + } ~Module() { + delete[]name; } }; @@ -37,7 +34,7 @@ static Module *modules = 0; * ----------------------------------------------------------------------------- */ void Swig_register_module(const char *n, ModuleFactory f) { - Module *m = new Module(n,f); + Module *m = new Module(n, f); m->next = modules; modules = m; } @@ -51,7 +48,7 @@ void Swig_register_module(const char *n, ModuleFactory f) { ModuleFactory Swig_find_module(const char *name) { Module *m = modules; while (m) { - if (strcmp(m->name,name) == 0) { + if (strcmp(m->name, name) == 0) { return m->fac; } m = m->next; diff --git a/SWIG/Source/Modules/mzscheme.cxx b/SWIG/Source/Modules/mzscheme.cxx index 11563c32c..b37ec357d 100644 --- a/SWIG/Source/Modules/mzscheme.cxx +++ b/SWIG/Source/Modules/mzscheme.cxx @@ -13,7 +13,7 @@ char cvsroot_mzscheme_cxx[] = "$Header$"; #include -static const char *usage = (char*)"\ +static const char *usage = (char *) "\ Mzscheme Options (available with -mzscheme)\n\ -prefix - Set a prefix to be prepended to all names\n\ -declaremodule - Create extension that declares a module\n\ @@ -23,95 +23,95 @@ Mzscheme Options (available with -mzscheme)\n\ them\n\ "; -static String *fieldnames_tab = 0; -static String *convert_tab = 0; -static String *convert_proto_tab = 0; -static String *struct_name = 0; -static String *mangled_struct_name = 0; +static String *fieldnames_tab = 0; +static String *convert_tab = 0; +static String *convert_proto_tab = 0; +static String *struct_name = 0; +static String *mangled_struct_name = 0; -static char *prefix=0; +static char *prefix = 0; static bool declaremodule = false; static bool noinit = false; //DLOPEN PATCH static char *load_libraries = NULL; //DLOPEN PATCH -static String *module=0; -static char *mzscheme_path=(char*)"mzscheme"; +static String *module = 0; +static char *mzscheme_path = (char *) "mzscheme"; static String *init_func_def = 0; -static File *f_runtime = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_init = 0; +static File *f_runtime = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_init = 0; // Used for garbage collection -static int exporting_destructor = 0; +static int exporting_destructor = 0; static String *swigtype_ptr = 0; static String *cls_swigtype = 0; -class MZSCHEME : public Language { +class MZSCHEME:public Language { public: /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ - virtual void main (int argc, char *argv[]) { + virtual void main(int argc, char *argv[]) { int i; - - SWIG_library_directory(mzscheme_path); - + + SWIG_library_directory(mzscheme_path); + // Look for certain command line options for (i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp (argv[i], "-help") == 0) { - fputs (usage, stdout); - SWIG_exit (0); - } else if (strcmp (argv[i], "-prefix") == 0) { + if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); + SWIG_exit(0); + } else if (strcmp(argv[i], "-prefix") == 0) { if (argv[i + 1]) { prefix = new char[strlen(argv[i + 1]) + 2]; strcpy(prefix, argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } else if (strcmp (argv[i], "-declaremodule") == 0) { - declaremodule = true; - Swig_mark_arg (i); - } else if (strcmp (argv[i], "-noinit") == 0) { + } else if (strcmp(argv[i], "-declaremodule") == 0) { + declaremodule = true; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-noinit") == 0) { noinit = true; - Swig_mark_arg (i); + Swig_mark_arg(i); } // DLOPEN PATCH - else if (strcmp(argv[i],"-dynamic-load") == 0) { - load_libraries=new char[strlen(argv[i+1])+2]; - strcpy(load_libraries,argv[i+1]); - Swig_mark_arg(i++); - Swig_mark_arg(i); - } + else if (strcmp(argv[i], "-dynamic-load") == 0) { + load_libraries = new char[strlen(argv[i + 1]) + 2]; + strcpy(load_libraries, argv[i + 1]); + Swig_mark_arg(i++); + Swig_mark_arg(i); + } // DLOPEN PATCH } } - + // If a prefix has been specified make sure it ends in a '_' - + if (prefix) { - if (prefix[strlen (prefix)] != '_') { - prefix[strlen (prefix) + 1] = 0; - prefix[strlen (prefix)] = '_'; + if (prefix[strlen(prefix)] != '_') { + prefix[strlen(prefix) + 1] = 0; + prefix[strlen(prefix)] = '_'; } } else - prefix = (char*)"swig_"; - + prefix = (char *) "swig_"; + // Add a symbol for this module - - Preprocessor_define ("SWIGMZSCHEME 1",0); - + + Preprocessor_define("SWIGMZSCHEME 1", 0); + // Set name of typemaps - + SWIG_typemap_lang("mzscheme"); // Read in default typemaps */ @@ -119,7 +119,7 @@ public: allow_overloading(); } - + /* ------------------------------------------------------------ * top() * ------------------------------------------------------------ */ @@ -127,9 +127,9 @@ public: virtual int top(Node *n) { /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - - f_runtime = NewFile(outfile,"w"); + String *outfile = Getattr(n, "outfile"); + + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); @@ -137,59 +137,58 @@ public: f_init = NewString(""); f_header = NewString(""); f_wrappers = NewString(""); - + /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + init_func_def = NewString(""); - Swig_register_filebyname("init",init_func_def); - + Swig_register_filebyname("init", init_func_def); + Printf(f_runtime, "/* -*- buffer-read-only: t -*- vi: set ro: */\n"); - Swig_banner (f_runtime); - - module = Getattr(n,"name"); - + Swig_banner(f_runtime); + + module = Getattr(n, "name"); + Language::top(n); - - SwigType_emit_type_table (f_runtime, f_wrappers); + + SwigType_emit_type_table(f_runtime, f_wrappers); if (!noinit) { if (declaremodule) { - Printf(f_init, "#define SWIG_MZSCHEME_CREATE_MENV(env) scheme_primitive_module(scheme_intern_symbol(\"%s\"), env)\n", module); - } - else { - Printf(f_init,"#define SWIG_MZSCHEME_CREATE_MENV(env) (env)\n"); + Printf(f_init, "#define SWIG_MZSCHEME_CREATE_MENV(env) scheme_primitive_module(scheme_intern_symbol(\"%s\"), env)\n", module); + } else { + Printf(f_init, "#define SWIG_MZSCHEME_CREATE_MENV(env) (env)\n"); } Printf(f_init, "%s\n", Char(init_func_def)); if (declaremodule) { - Printf(f_init, "\tscheme_finish_primitive_module(menv);\n"); + Printf(f_init, "\tscheme_finish_primitive_module(menv);\n"); } - Printf (f_init, "\treturn scheme_void;\n}\n"); + Printf(f_init, "\treturn scheme_void;\n}\n"); Printf(f_init, "Scheme_Object *scheme_initialize(Scheme_Env *env) {\n"); // DLOPEN PATCH if (load_libraries) { - Printf(f_init,"mz_set_dlopen_libraries(\"%s\");\n",load_libraries); + Printf(f_init, "mz_set_dlopen_libraries(\"%s\");\n", load_libraries); } // DLOPEN PATCH Printf(f_init, "\treturn scheme_reload(env);\n"); - Printf (f_init, "}\n"); - - Printf(f_init,"Scheme_Object *scheme_module_name(void) {\n"); + Printf(f_init, "}\n"); + + Printf(f_init, "Scheme_Object *scheme_module_name(void) {\n"); if (declaremodule) { - Printf(f_init, " return scheme_intern_symbol((char*)\"%s\");\n", module); + Printf(f_init, " return scheme_intern_symbol((char*)\"%s\");\n", module); } else { - Printf(f_init," return scheme_make_symbol((char*)\"%s\");\n", module); + Printf(f_init, " return scheme_make_symbol((char*)\"%s\");\n", module); } - Printf(f_init,"}\n"); + Printf(f_init, "}\n"); } /* Close all of the files */ - Dump(f_header,f_runtime); - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_header, f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); @@ -197,32 +196,29 @@ public: Delete(f_runtime); return SWIG_OK; } - + /* ------------------------------------------------------------ * functionWrapper() * Create a function declaration and register it with the interpreter. * ------------------------------------------------------------ */ - void throw_unhandled_mzscheme_type_error (SwigType *d) - { - Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, - "Unable to handle type %s.\n", SwigType_str(d,0)); + void throw_unhandled_mzscheme_type_error(SwigType *d) { + Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, "Unable to handle type %s.\n", SwigType_str(d, 0)); } /* Return true iff T is a pointer type */ int - is_a_pointer (SwigType *t) - { + is_a_pointer(SwigType *t) { return SwigType_ispointer(SwigType_typedef_resolve_all(t)); } virtual int functionWrapper(Node *n) { - char *iname = GetChar(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + char *iname = GetChar(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); Parm *p; - + Wrapper *f = NewWrapper(); String *proc_name = NewString(""); String *source = NewString(""); @@ -231,7 +227,7 @@ public: String *cleanup = NewString(""); String *outarg = NewString(""); String *build = NewString(""); - String *tm; + String *tm; int argout_set = 0; int i = 0; int numargs; @@ -240,250 +236,244 @@ public: // PATCH DLOPEN if (load_libraries) { - ParmList *parms=Getattr(n,"parms"); - SwigType *type=Getattr(n,"type"); - String *name=NewString("caller"); - Setattr(n,"wrap:action", Swig_cresult(type,"result", Swig_cfunction_call(name,parms))); + ParmList *parms = Getattr(n, "parms"); + SwigType *type = Getattr(n, "type"); + String *name = NewString("caller"); + Setattr(n, "wrap:action", Swig_cresult(type, "result", Swig_cfunction_call(name, parms))); } // PATCH DLOPEN // Make a wrapper name for this String *wname = Swig_name_wrapper(iname); - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } if (overname) { Append(wname, overname); } - Setattr(n,"wrap:name",wname); - + Setattr(n, "wrap:name", wname); + // Build the name for Scheme. - Printv(proc_name, iname,NIL); + Printv(proc_name, iname, NIL); Replaceall(proc_name, "_", "-"); - + // writing the function wrapper function - Printv(f->def, "static Scheme_Object *", wname, " (", NIL); + Printv(f->def, "static Scheme_Object *", wname, " (", NIL); Printv(f->def, "int argc, Scheme_Object **argv", NIL); Printv(f->def, ")\n{", NIL); - + /* Define the scheme name in C. This define is used by several macros. */ Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - + // Declare return variable and arguments // number of parameters // they are called arg0, arg1, ... // the return value is called result - + emit_args(d, l, f); - + /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); - + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); + numargs = emit_num_arguments(l); - numreq = emit_num_required(l); + numreq = emit_num_required(l); // DLOPEN PATCH /* Add the holder for the pointer to the function to be opened */ if (load_libraries) { - Wrapper_add_local(f, "_function_loaded","static int _function_loaded=(1==0)"); + Wrapper_add_local(f, "_function_loaded", "static int _function_loaded=(1==0)"); Wrapper_add_local(f, "_the_function", "static void *_the_function=NULL"); { - String *parms=ParmList_protostr(l); - String *func=NewStringf("(*caller)(%s)",parms); - Wrapper_add_local(f,"caller",SwigType_lstr(d,func)); /*"(*caller)()"));*/ + String *parms = ParmList_protostr(l); + String *func = NewStringf("(*caller)(%s)", parms); + Wrapper_add_local(f, "caller", SwigType_lstr(d, func)); /*"(*caller)()")); */ } } // DLOPEN PATCH - + // adds local variables Wrapper_add_local(f, "lenv", "int lenv = 1"); Wrapper_add_local(f, "values", "Scheme_Object *values[MAXVALUES]"); - + // DLOPEN PATCH if (load_libraries) { - Printf(f->code,"if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n",iname); - Printf(f->code,"if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n",iname); - Printf(f->code,"caller=_the_function;\n"); + Printf(f->code, "if (!_function_loaded) { _the_function=mz_load_function(\"%s\");_function_loaded=(1==1); }\n", iname); + Printf(f->code, "if (!_the_function) { scheme_signal_error(\"Cannot load C function '%s'\"); }\n", iname); + Printf(f->code, "caller=_the_function;\n"); } // DLOPEN PATCH - + // Now write code to extract the parameters (this is super ugly) - + for (i = 0, p = l; i < numargs; i++) { /* Skip ignored arguments */ - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); - + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + // Produce names of source and target Clear(source); Clear(target); Clear(arg); Printf(source, "argv[%d]", i); - Printf(target, "%s",ln); - Printv(arg, Getattr(p,"name"),NIL); - + Printf(target, "%s", ln); + Printv(arg, Getattr(p, "name"), NIL); + if (i >= numreq) { - Printf(f->code,"if (argc > %d) {\n",i); + Printf(f->code, "if (argc > %d) {\n", i); } // Handle parameter types. - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$source",source); - Replaceall(tm,"$target",target); - Replaceall(tm,"$input",source); - Setattr(p,"emit:input",source); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", target); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); Printv(f->code, tm, "\n", NIL); - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); } else { // no typemap found // check if typedef and resolve - throw_unhandled_mzscheme_type_error (pt); + throw_unhandled_mzscheme_type_error(pt); p = nextSibling(p); } if (i >= numreq) { - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); } } - + /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + // Pass output arguments back to the caller. - + for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* Deprecated */ - Replaceall(tm,"$target",Getattr(p,"lname")); /* Deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* Deprecated */ + Replaceall(tm, "$target", Getattr(p, "lname")); /* Deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); argout_set = 1; } else { p = nextSibling(p); } } - + // Free up any memory allocated for the arguments. - + /* Insert cleanup code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } } - + // Now write code to make the function call - - emit_action(n,f); - + + emit_action(n, f); + // Now have return value, figure out what to do with it. - - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - Replaceall(tm,"$source","result"); - Replaceall(tm,"$target","values[0]"); - Replaceall(tm,"$result","values[0]"); + + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "values[0]"); + Replaceall(tm, "$result", "values[0]"); if (GetFlag(n, "feature:new")) - Replaceall(tm, "$owner", "1"); + Replaceall(tm, "$owner", "1"); else - Replaceall(tm, "$owner", "0"); - Printv(f->code, tm, "\n",NIL); + Replaceall(tm, "$owner", "0"); + Printv(f->code, tm, "\n", NIL); } else { - throw_unhandled_mzscheme_type_error (d); + throw_unhandled_mzscheme_type_error(d); } - + // Dump the argument output code - Printv(f->code, Char(outarg),NIL); - + Printv(f->code, Char(outarg), NIL); + // Dump the argument cleanup code - Printv(f->code, Char(cleanup),NIL); - + Printv(f->code, Char(cleanup), NIL); + // Look for any remaining cleanup - - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printv(f->code, tm, "\n",NIL); + + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); } } - // Free any memory allocated by the function being wrapped.. - - if ((tm = Swig_typemap_lookup_new("ret",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printv(f->code, tm, "\n",NIL); + + if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); } - // Wrap things up (in a manner of speaking) - + Printv(f->code, tab4, "return SWIG_MzScheme_PackageValues(lenv, values);\n", NIL); Printf(f->code, "#undef FUNC_NAME\n"); - Printv(f->code, "}\n",NIL); - + Printv(f->code, "}\n", NIL); + /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); + Replaceall(f->code, "$symname", iname); Wrapper_print(f, f_wrappers); - - if (!Getattr(n,"sym:overloaded")) { - + + if (!Getattr(n, "sym:overloaded")) { + // Now register the function char temp[256]; sprintf(temp, "%d", numargs); if (exporting_destructor) { - Printf(init_func_def, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); + Printf(init_func_def, "SWIG_TypeClientData(SWIGTYPE%s, (void *) %s);\n", swigtype_ptr, wname); } else { - Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", - proc_name, wname, proc_name, numreq, numargs); + Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", proc_name, wname, proc_name, numreq, numargs); } } else { - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { /* Emit overloading dispatch function */ int maxargs; - String *dispatch = Swig_overload_dispatch(n,"return %s(argc,argv);",&maxargs); - + String *dispatch = Swig_overload_dispatch(n, "return %s(argc,argv);", &maxargs); + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *df = NewWrapper(); - String *dname = Swig_name_wrapper(iname); + Wrapper *df = NewWrapper(); + String *dname = Swig_name_wrapper(iname); - Printv(df->def, - "static Scheme_Object *\n", dname, - "(int argc, Scheme_Object **argv) {", - NIL); - Printv(df->code,dispatch,"\n",NIL); - Printf(df->code,"scheme_signal_error(\"No matching function for overloaded '%s'\");\n", iname); - Printv(df->code,"}\n",NIL); - Wrapper_print(df,f_wrappers); - Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", - proc_name, dname, proc_name, 0, maxargs); + Printv(df->def, "static Scheme_Object *\n", dname, "(int argc, Scheme_Object **argv) {", NIL); + Printv(df->code, dispatch, "\n", NIL); + Printf(df->code, "scheme_signal_error(\"No matching function for overloaded '%s'\");\n", iname); + Printv(df->code, "}\n", NIL); + Wrapper_print(df, f_wrappers); + Printf(init_func_def, "scheme_add_global(\"%s\", scheme_make_prim_w_arity(%s,\"%s\",%d,%d),menv);\n", proc_name, dname, proc_name, 0, maxargs); DelWrapper(df); Delete(dispatch); Delete(dname); } } - + Delete(proc_name); Delete(source); Delete(target); @@ -506,90 +496,77 @@ public: * value. * ------------------------------------------------------------ */ - virtual int variableWrapper(Node *n) { + virtual int variableWrapper(Node *n) { + + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - String *proc_name = NewString(""); String *tm; String *tm2 = NewString("");; String *argnum = NewString("0"); String *arg = NewString("argv[0]"); Wrapper *f; - - if (!addSymbol(iname,n)) return SWIG_ERROR; - + + if (!addSymbol(iname, n)) + return SWIG_ERROR; + f = NewWrapper(); // evaluation function names String *var_name = Swig_name_wrapper(iname); // Build the name for scheme. - Printv(proc_name, iname,NIL); + Printv(proc_name, iname, NIL); Replaceall(proc_name, "_", "-"); - + if ((SwigType_type(t) != T_USER) || (is_a_pointer(t))) { - - Printf (f->def, "static Scheme_Object *%s(int argc, Scheme_Object** argv) {\n", var_name); + + Printf(f->def, "static Scheme_Object *%s(int argc, Scheme_Object** argv) {\n", var_name); Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - - Wrapper_add_local (f, "swig_result", "Scheme_Object *swig_result"); - - if (!GetFlag(n,"feature:immutable")) { + + Wrapper_add_local(f, "swig_result", "Scheme_Object *swig_result"); + + if (!GetFlag(n, "feature:immutable")) { /* Check for a setting of the variable value */ - Printf (f->code, "if (argc) {\n"); - if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { - Replaceall(tm,"$source","argv[0]"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","argv[0]"); + Printf(f->code, "if (argc) {\n"); + if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { + Replaceall(tm, "$source", "argv[0]"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "argv[0]"); /* Printv(f->code, tm, "\n",NIL); */ emit_action_code(n, f, tm); + } else { + throw_unhandled_mzscheme_type_error(t); } - else { - throw_unhandled_mzscheme_type_error (t); - } - Printf (f->code, "}\n"); + Printf(f->code, "}\n"); } - // Now return the value of the variable (regardless // of evaluating or setting) - - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source",name); - Replaceall(tm,"$target","swig_result"); - Replaceall(tm,"$result","swig_result"); + + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "swig_result"); + Replaceall(tm, "$result", "swig_result"); /* Printf (f->code, "%s\n", tm); */ emit_action_code(n, f, tm); + } else { + throw_unhandled_mzscheme_type_error(t); } - else { - throw_unhandled_mzscheme_type_error (t); - } - Printf (f->code, "\nreturn swig_result;\n"); - Printf (f->code, "#undef FUNC_NAME\n"); - Printf (f->code, "}\n"); - - Wrapper_print (f, f_wrappers); - + Printf(f->code, "\nreturn swig_result;\n"); + Printf(f->code, "#undef FUNC_NAME\n"); + Printf(f->code, "}\n"); + + Wrapper_print(f, f_wrappers); + // Now add symbol to the MzScheme interpreter - + Printv(init_func_def, - "scheme_add_global(\"", - proc_name, - "\", scheme_make_prim_w_arity(", - var_name, - ", \"", - proc_name, - "\", ", - "0", - ", ", - "1", - "), menv);\n",NIL); - + "scheme_add_global(\"", proc_name, "\", scheme_make_prim_w_arity(", var_name, ", \"", proc_name, "\", ", "0", ", ", "1", "), menv);\n", NIL); + } else { - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, - "Unsupported variable type %s (ignored).\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported variable type %s (ignored).\n", SwigType_str(t, 0)); } Delete(var_name); Delete(proc_name); @@ -605,71 +582,69 @@ public: * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *value = Getattr(n,"value"); - + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + String *var_name = NewString(""); String *proc_name = NewString(""); String *rvalue = NewString(""); String *temp = NewString(""); String *tm; - + // Make a static variable; - - Printf (var_name, "_wrap_const_%s", Swig_name_mangle(Getattr(n,"sym:name"))); - + + Printf(var_name, "_wrap_const_%s", Swig_name_mangle(Getattr(n, "sym:name"))); + // Build the name for scheme. - Printv(proc_name, iname,NIL); + Printv(proc_name, iname, NIL); Replaceall(proc_name, "_", "-"); - + if ((SwigType_type(type) == T_USER) && (!is_a_pointer(type))) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } - // See if there's a typemap - - Printv(rvalue, value,NIL); + + Printv(rvalue, value, NIL); if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 1)) { temp = Copy(rvalue); Clear(rvalue); - Printv(rvalue, "\"", temp, "\"",NIL); + Printv(rvalue, "\"", temp, "\"", NIL); } if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 0)) { Delete(temp); temp = Copy(rvalue); Clear(rvalue); - Printv(rvalue, "'", temp, "'",NIL); + Printv(rvalue, "'", temp, "'", NIL); } - if ((tm = Swig_typemap_lookup_new("constant",n,name,0))) { - Replaceall(tm,"$source",rvalue); - Replaceall(tm,"$value",rvalue); - Replaceall(tm,"$target",name); - Printf (f_init, "%s\n", tm); + if ((tm = Swig_typemap_lookup_new("constant", n, name, 0))) { + Replaceall(tm, "$source", rvalue); + Replaceall(tm, "$value", rvalue); + Replaceall(tm, "$target", name); + Printf(f_init, "%s\n", tm); } else { // Create variable and assign it a value - - Printf (f_header, "static %s = ", SwigType_lstr(type,var_name)); + + Printf(f_header, "static %s = ", SwigType_lstr(type, var_name)); if ((SwigType_type(type) == T_STRING)) { - Printf (f_header, "\"%s\";\n", value); + Printf(f_header, "\"%s\";\n", value); } else if (SwigType_type(type) == T_CHAR) { - Printf (f_header, "\'%s\';\n", value); + Printf(f_header, "\'%s\';\n", value); } else { - Printf (f_header, "%s;\n", value); + Printf(f_header, "%s;\n", value); } - + // Now create a variable declaration - + { /* Hack alert: will cleanup later -- Dave */ Node *n = NewHash(); - Setattr(n,"name",var_name); - Setattr(n,"sym:name",iname); - Setattr(n,"type", type); - SetFlag(n,"feature:immutable"); + Setattr(n, "name", var_name); + Setattr(n, "sym:name", iname); + Setattr(n, "type", type); + SetFlag(n, "feature:immutable"); variableWrapper(n); Delete(n); } @@ -691,132 +666,115 @@ public: * classHandler() * ------------------------------------------------------------ */ virtual int classHandler(Node *n) { - String *mangled_classname = 0; - String *real_classname = 0; - String *scm_structname = NewString(""); - SwigType *ctype_ptr = NewStringf("p.%s", Getattr(n, "classtype")); - - SwigType *t = NewStringf("p.%s", Getattr(n, "name")); - swigtype_ptr = SwigType_manglestr(t); - Delete(t); + String *mangled_classname = 0; + String *real_classname = 0; + String *scm_structname = NewString(""); + SwigType *ctype_ptr = NewStringf("p.%s", Getattr(n, "classtype")); - cls_swigtype = SwigType_manglestr(Getattr(n, "name")); + SwigType *t = NewStringf("p.%s", Getattr(n, "name")); + swigtype_ptr = SwigType_manglestr(t); + Delete(t); + + cls_swigtype = SwigType_manglestr(Getattr(n, "name")); - fieldnames_tab = NewString(""); - convert_tab = NewString(""); - convert_proto_tab = NewString(""); + fieldnames_tab = NewString(""); + convert_tab = NewString(""); + convert_proto_tab = NewString(""); - struct_name = Getattr(n,"sym:name"); - mangled_struct_name = Swig_name_mangle(Getattr(n,"sym:name")); + struct_name = Getattr(n, "sym:name"); + mangled_struct_name = Swig_name_mangle(Getattr(n, "sym:name")); - Printv(scm_structname, struct_name, NIL); - Replaceall(scm_structname, "_", "-"); - - real_classname = Getattr(n,"name"); - mangled_classname = Swig_name_mangle(real_classname); + Printv(scm_structname, struct_name, NIL); + Replaceall(scm_structname, "_", "-"); - Printv(fieldnames_tab, "static const char *_swig_struct_", - cls_swigtype, "_field_names[] = { \n", NIL); + real_classname = Getattr(n, "name"); + mangled_classname = Swig_name_mangle(real_classname); - Printv(convert_proto_tab, "static Scheme_Object *_swig_convert_struct_", - cls_swigtype, "(", SwigType_str(ctype_ptr, "ptr"), ");\n", NIL); - - Printv(convert_tab, "static Scheme_Object *_swig_convert_struct_", - cls_swigtype, "(", SwigType_str(ctype_ptr, "ptr"), ")\n {\n", - NIL); + Printv(fieldnames_tab, "static const char *_swig_struct_", cls_swigtype, "_field_names[] = { \n", NIL); - Printv(convert_tab, - tab4, "Scheme_Object *obj;\n", - tab4, "Scheme_Object *fields[_swig_struct_", cls_swigtype, - "_field_names_cnt];\n", - tab4, "int i = 0;\n\n", NIL); + Printv(convert_proto_tab, "static Scheme_Object *_swig_convert_struct_", cls_swigtype, "(", SwigType_str(ctype_ptr, "ptr"), ");\n", NIL); - /* Generate normal wrappers */ - Language::classHandler(n); + Printv(convert_tab, "static Scheme_Object *_swig_convert_struct_", cls_swigtype, "(", SwigType_str(ctype_ptr, "ptr"), ")\n {\n", NIL); - Printv(convert_tab, tab4, "obj = scheme_make_struct_instance(", - "_swig_struct_type_", cls_swigtype, ", i, fields);\n", NIL); - Printv(convert_tab, tab4, "return obj;\n}\n\n", NIL); + Printv(convert_tab, + tab4, "Scheme_Object *obj;\n", tab4, "Scheme_Object *fields[_swig_struct_", cls_swigtype, "_field_names_cnt];\n", tab4, "int i = 0;\n\n", NIL); - Printv(fieldnames_tab, "};\n", NIL); + /* Generate normal wrappers */ + Language::classHandler(n); - Printv(f_header, "static Scheme_Object *_swig_struct_type_", - cls_swigtype, ";\n", NIL); + Printv(convert_tab, tab4, "obj = scheme_make_struct_instance(", "_swig_struct_type_", cls_swigtype, ", i, fields);\n", NIL); + Printv(convert_tab, tab4, "return obj;\n}\n\n", NIL); - Printv(f_header, fieldnames_tab, NIL); - Printv(f_header, "#define _swig_struct_", cls_swigtype, - "_field_names_cnt (sizeof(_swig_struct_", cls_swigtype, - "_field_names)/sizeof(char*))\n", NIL); + Printv(fieldnames_tab, "};\n", NIL); - Printv(f_header, convert_proto_tab, NIL); - Printv(f_wrappers, convert_tab, NIL); + Printv(f_header, "static Scheme_Object *_swig_struct_type_", cls_swigtype, ";\n", NIL); - Printv(init_func_def, "_swig_struct_type_", cls_swigtype, - " = SWIG_MzScheme_new_scheme_struct(menv, \"", scm_structname, "\", ", - "_swig_struct_", cls_swigtype, "_field_names_cnt,", - "(char**) _swig_struct_", cls_swigtype, "_field_names);\n", - NIL); - - Delete(mangled_classname); - Delete(swigtype_ptr); - swigtype_ptr = 0; - Delete(fieldnames_tab); - Delete(convert_tab); - Delete(ctype_ptr); - Delete(convert_proto_tab); - struct_name = 0; - mangled_struct_name = 0; - Delete(cls_swigtype); - cls_swigtype = 0; + Printv(f_header, fieldnames_tab, NIL); + Printv(f_header, "#define _swig_struct_", cls_swigtype, "_field_names_cnt (sizeof(_swig_struct_", cls_swigtype, "_field_names)/sizeof(char*))\n", NIL); - return SWIG_OK; + Printv(f_header, convert_proto_tab, NIL); + Printv(f_wrappers, convert_tab, NIL); + + Printv(init_func_def, "_swig_struct_type_", cls_swigtype, + " = SWIG_MzScheme_new_scheme_struct(menv, \"", scm_structname, "\", ", + "_swig_struct_", cls_swigtype, "_field_names_cnt,", "(char**) _swig_struct_", cls_swigtype, "_field_names);\n", NIL); + + Delete(mangled_classname); + Delete(swigtype_ptr); + swigtype_ptr = 0; + Delete(fieldnames_tab); + Delete(convert_tab); + Delete(ctype_ptr); + Delete(convert_proto_tab); + struct_name = 0; + mangled_struct_name = 0; + Delete(cls_swigtype); + cls_swigtype = 0; + + return SWIG_OK; } - - /* ------------------------------------------------------------ - * membervariableHandler() - * ------------------------------------------------------------ */ - virtual int membervariableHandler(Node *n) { - Language::membervariableHandler(n); + /* ------------------------------------------------------------ + * membervariableHandler() + * ------------------------------------------------------------ */ - if (!is_smart_pointer()) { - String *symname = Getattr(n, "sym:name"); - String *name = Getattr(n, "name"); - SwigType *type = Getattr(n, "type"); - String *swigtype = SwigType_manglestr(Getattr(n, "type")); - String *tm = 0; - String *access_mem = NewString(""); - SwigType *ctype_ptr = NewStringf("p.%s", Getattr(n, "type")); + virtual int membervariableHandler(Node *n) { + Language::membervariableHandler(n); - Printv(fieldnames_tab, tab4, "\"", symname, "\",\n", NIL); - Printv(access_mem, "(ptr)->", name, NIL); - if ((SwigType_type(type) == T_USER) && (!is_a_pointer(type))) { - Printv(convert_tab, tab4, "fields[i++] = ", NIL); - Printv(convert_tab, "_swig_convert_struct_", swigtype, - "((", SwigType_str(ctype_ptr, ""), ")&((ptr)->", - name, "));\n", NIL); - } else if ((tm = Swig_typemap_lookup_new("varout",n,access_mem,0))) { - Replaceall(tm,"$result","fields[i++]"); - Printv(convert_tab, tm, "\n", NIL); - } else - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, - "Unsupported member variable type %s (ignored).\n", - SwigType_str(type,0)); - - Delete(access_mem); - } - return SWIG_OK; + if (!is_smart_pointer()) { + String *symname = Getattr(n, "sym:name"); + String *name = Getattr(n, "name"); + SwigType *type = Getattr(n, "type"); + String *swigtype = SwigType_manglestr(Getattr(n, "type")); + String *tm = 0; + String *access_mem = NewString(""); + SwigType *ctype_ptr = NewStringf("p.%s", Getattr(n, "type")); + + Printv(fieldnames_tab, tab4, "\"", symname, "\",\n", NIL); + Printv(access_mem, "(ptr)->", name, NIL); + if ((SwigType_type(type) == T_USER) && (!is_a_pointer(type))) { + Printv(convert_tab, tab4, "fields[i++] = ", NIL); + Printv(convert_tab, "_swig_convert_struct_", swigtype, "((", SwigType_str(ctype_ptr, ""), ")&((ptr)->", name, "));\n", NIL); + } else if ((tm = Swig_typemap_lookup_new("varout", n, access_mem, 0))) { + Replaceall(tm, "$result", "fields[i++]"); + Printv(convert_tab, tm, "\n", NIL); + } else + Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported member variable type %s (ignored).\n", SwigType_str(type, 0)); + + Delete(access_mem); } + return SWIG_OK; + } /* ------------------------------------------------------------ * validIdentifer() * ------------------------------------------------------------ */ - + virtual int validIdentifier(String *s) { char *c = Char(s); - /* Check whether we have an R5RS identifier.*/ + /* Check whether we have an R5RS identifier. */ /* --> * | */ /* --> | */ if (!(isalpha(*c) || (*c == '!') || (*c == '$') || (*c == '%') @@ -825,9 +783,10 @@ public: || (*c == '^') || (*c == '_') || (*c == '~'))) { /* --> + | - | ... */ if ((strcmp(c, "+") == 0) - || strcmp(c, "-") == 0 - || strcmp(c, "...") == 0) return 1; - else return 0; + || strcmp(c, "-") == 0 || strcmp(c, "...") == 0) + return 1; + else + return 0; } /* --> | | */ while (*c) { @@ -835,7 +794,8 @@ public: || (*c == '&') || (*c == '*') || (*c == '/') || (*c == ':') || (*c == '<') || (*c == '=') || (*c == '>') || (*c == '?') || (*c == '^') || (*c == '_') || (*c == '~') || (*c == '+') - || (*c == '-') || (*c == '.') || (*c == '@'))) return 0; + || (*c == '-') || (*c == '.') || (*c == '@'))) + return 0; c++; } return 1; @@ -854,16 +814,14 @@ public: return NewString("swigmzrun.h"); } }; - + /* ----------------------------------------------------------------------------- * swig_mzscheme() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_mzscheme() { +static Language *new_swig_mzscheme() { return new MZSCHEME(); } -extern "C" Language * swig_mzscheme(void) { +extern "C" Language *swig_mzscheme(void) { return new_swig_mzscheme(); } - - diff --git a/SWIG/Source/Modules/ocaml.cxx b/SWIG/Source/Modules/ocaml.cxx index a086ad655..8e8ab70fe 100755 --- a/SWIG/Source/Modules/ocaml.cxx +++ b/SWIG/Source/Modules/ocaml.cxx @@ -13,1044 +13,965 @@ char cvsroot_ocaml_cxx[] = "$Header$"; #include -static const char *usage = (char*) +static const char *usage = (char *) ("Ocaml Options (available with -ocaml)\n" "-prefix - Set a prefix to be prepended to all names\n" "-where - Emit library location\n" - "-suffix - Change .cxx to something else\n" - "-oldvarnames - old intermediary method names for variable wrappers\n" - "\n"); + "-suffix - Change .cxx to something else\n" "-oldvarnames - old intermediary method names for variable wrappers\n" "\n"); static int classmode = 0; static int in_constructor = 0, in_destructor = 0, in_copyconst = 0; static int const_enum = 0; static int static_member_function = 0; static int generate_sizeof = 0; -static char *prefix=0; -static char *ocaml_path=(char*)"ocaml"; -static bool old_variable_names = false; -static String *classname=0; -static String *module=0; +static char *prefix = 0; +static char *ocaml_path = (char *) "ocaml"; +static bool old_variable_names = false; +static String *classname = 0; +static String *module = 0; static String *init_func_def = 0; static String *f_classtemplate = 0; static String *name_qualifier = 0; -static Hash *seen_enums = 0; -static Hash *seen_enumvalues = 0; -static Hash *seen_constructors = 0; +static Hash *seen_enums = 0; +static Hash *seen_enumvalues = 0; +static Hash *seen_constructors = 0; -static File *f_header = 0; -static File *f_runtime = 0; -static File *f_wrappers = 0; -static File *f_directors = 0; -static File *f_directors_h = 0; -static File *f_init = 0; -static File *f_mlout = 0; -static File *f_mliout = 0; -static File *f_mlbody = 0; -static File *f_mlibody = 0; -static File *f_mltail = 0; -static File *f_mlitail = 0; -static File *f_enumtypes_type = 0; -static File *f_enumtypes_value = 0; -static File *f_class_ctors = 0; -static File *f_class_ctors_end = 0; -static File *f_enum_to_int = 0; -static File *f_int_to_enum = 0; +static File *f_header = 0; +static File *f_runtime = 0; +static File *f_wrappers = 0; +static File *f_directors = 0; +static File *f_directors_h = 0; +static File *f_init = 0; +static File *f_mlout = 0; +static File *f_mliout = 0; +static File *f_mlbody = 0; +static File *f_mlibody = 0; +static File *f_mltail = 0; +static File *f_mlitail = 0; +static File *f_enumtypes_type = 0; +static File *f_enumtypes_value = 0; +static File *f_class_ctors = 0; +static File *f_class_ctors_end = 0; +static File *f_enum_to_int = 0; +static File *f_int_to_enum = 0; -class OCAML : public Language { +class OCAML:public Language { public: - OCAML() - { - director_prot_ctor_code = NewString(""); + OCAML() { + director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, "if ( $comparison ) { /* subclassed */\n", - " $director_new \n", - "} else {\n", - " failwith(\"accessing abstract class or protected constructor\"); \n", - "}\n", NIL); + " $director_new \n", "} else {\n", " failwith(\"accessing abstract class or protected constructor\"); \n", "}\n", NIL); director_multiple_inheritance = 1; director_language = 1; } - - - String *Swig_class_name(Node *n) { - String *name; - name = Copy(Getattr(n, "sym:name")); - return name; - } + + String *Swig_class_name(Node *n) { + String *name; + name = Copy(Getattr(n, "sym:name")); + return name; + } - void PrintIncludeArg() { - Printv(stdout,SWIG_LIB,SWIG_FILE_DELIMETER,ocaml_path, - "\n",NIL); - } + void PrintIncludeArg() { + Printv(stdout, SWIG_LIB, SWIG_FILE_DELIMETER, ocaml_path, "\n", NIL); + } - /* ------------------------------------------------------------ - * main() - * ------------------------------------------------------------ */ + /* ------------------------------------------------------------ + * main() + * ------------------------------------------------------------ */ - virtual void main (int argc, char *argv[]) { - int i; - - prefix = 0; + virtual void main(int argc, char *argv[]) { + int i; - SWIG_library_directory(ocaml_path); - - // Look for certain command line options - for (i = 1; i < argc; i++) { - if (argv[i]) { - if (strcmp (argv[i], "-help") == 0) { - fputs (usage, stdout); - SWIG_exit (0); - } else if (strcmp (argv[i], "-where") == 0) { - PrintIncludeArg(); - SWIG_exit (0); - } else if (strcmp (argv[i], "-prefix") == 0) { - if (argv[i + 1]) { - prefix = new char[strlen(argv[i + 1]) + 2]; - strcpy(prefix, argv[i + 1]); - Swig_mark_arg (i); - Swig_mark_arg (i + 1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp (argv[i], "-suffix") == 0) { - if (argv[i + 1]) { - SWIG_config_cppext( argv[i+1] ); - Swig_mark_arg (i); - Swig_mark_arg (i+1); - i++; - } else - Swig_arg_error(); - } else if (strcmp(argv[i],"-oldvarnames") == 0) { - Swig_mark_arg(i); - old_variable_names = true; - } - } + prefix = 0; + + SWIG_library_directory(ocaml_path); + + // Look for certain command line options + for (i = 1; i < argc; i++) { + if (argv[i]) { + if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); + SWIG_exit(0); + } else if (strcmp(argv[i], "-where") == 0) { + PrintIncludeArg(); + SWIG_exit(0); + } else if (strcmp(argv[i], "-prefix") == 0) { + if (argv[i + 1]) { + prefix = new char[strlen(argv[i + 1]) + 2]; + strcpy(prefix, argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-suffix") == 0) { + if (argv[i + 1]) { + SWIG_config_cppext(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else + Swig_arg_error(); + } else if (strcmp(argv[i], "-oldvarnames") == 0) { + Swig_mark_arg(i); + old_variable_names = true; } - - // If a prefix has been specified make sure it ends in a '_' - - if (prefix) { - if (prefix[strlen (prefix)] != '_') { - prefix[strlen (prefix) + 1] = 0; - prefix[strlen (prefix)] = '_'; - } - } else - prefix = (char*)"swig_"; - - // Add a symbol for this module - - Preprocessor_define ("SWIGOCAML 1",0); - // Set name of typemaps - - SWIG_typemap_lang("ocaml"); - - // Read in default typemaps */ - SWIG_config_file("ocaml.i"); - allow_overloading(); - + } } - /* Swig_director_declaration() - * - * Generate the full director class declaration, complete with base classes. - * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" + // If a prefix has been specified make sure it ends in a '_' + + if (prefix) { + if (prefix[strlen(prefix)] != '_') { + prefix[strlen(prefix) + 1] = 0; + prefix[strlen(prefix)] = '_'; + } + } else + prefix = (char *) "swig_"; + + // Add a symbol for this module + + Preprocessor_define("SWIGOCAML 1", 0); + // Set name of typemaps + + SWIG_typemap_lang("ocaml"); + + // Read in default typemaps */ + SWIG_config_file("ocaml.i"); + allow_overloading(); + + } + + /* Swig_director_declaration() + * + * Generate the full director class declaration, complete with base classes. + * e.g. "class SwigDirector_myclass : public myclass, public Swig::Director {" + * + */ + + String *Swig_director_declaration(Node *n) { + String *classname = Swig_class_name(n); + String *directorname = NewStringf("SwigDirector_%s", classname); + String *base = Getattr(n, "classtype"); + String *declaration = Swig_class_declaration(n, directorname); + Printf(declaration, " : public %s, public Swig::Director {\n", base); + Delete(classname); + Delete(directorname); + return declaration; + } + + /* ------------------------------------------------------------ + * top() + * + * Recognize the %module, and capture the module name. + * Create the default enum cases. + * Set up the named outputs: + * + * init + * ml + * mli + * wrapper + * header + * runtime + * directors + * directors_h + * ------------------------------------------------------------ */ + + virtual int top(Node *n) { + /* Set comparison with none for ConstructorToFunction */ + setSubclassInstanceCheck(NewString("caml_list_nth(args,0) != Val_unit")); + + /* check if directors are enabled for this module. note: this + * is a "master" switch, without which no director code will be + * emitted. %feature("director") statements are also required + * to enable directors for individual classes or methods. * + * use %module(directors="1") modulename at the start of the + * interface file to enable director generation. */ - - String *Swig_director_declaration(Node *n) { - String* classname = Swig_class_name(n); - String *directorname = NewStringf("SwigDirector_%s", classname); - String *base = Getattr(n, "classtype"); - String *declaration = Swig_class_declaration(n, directorname); - Printf(declaration, " : public %s, public Swig::Director {\n", base); - Delete(classname); - Delete(directorname); - return declaration; - } - - /* ------------------------------------------------------------ - * top() - * - * Recognize the %module, and capture the module name. - * Create the default enum cases. - * Set up the named outputs: - * - * init - * ml - * mli - * wrapper - * header - * runtime - * directors - * directors_h - * ------------------------------------------------------------ */ - - virtual int top(Node *n) { - /* Set comparison with none for ConstructorToFunction */ - setSubclassInstanceCheck(NewString("caml_list_nth(args,0) != Val_unit")); - - /* check if directors are enabled for this module. note: this - * is a "master" switch, without which no director code will be - * emitted. %feature("director") statements are also required - * to enable directors for individual classes or methods. - * - * use %module(directors="1") modulename at the start of the - * interface file to enable director generation. - */ - { - Node *module = Getattr(n, "module"); - if (module) { - Node *options = Getattr(module, "options"); - if (options) { - if (Getattr(options, "directors")) { - allow_directors(); - } - if (Getattr(options, "dirprot")) { - allow_dirprot(); - } - if (Getattr(options, "sizeof")) { - generate_sizeof = 1; - } - } - } + { + Node *module = Getattr(n, "module"); + if (module) { + Node *options = Getattr(module, "options"); + if (options) { + if (Getattr(options, "directors")) { + allow_directors(); + } + if (Getattr(options, "dirprot")) { + allow_dirprot(); + } + if (Getattr(options, "sizeof")) { + generate_sizeof = 1; + } } - - /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - - f_runtime = NewFile(outfile,"w"); - if (!f_runtime) { - FileErrorDisplay(outfile); - SWIG_exit(EXIT_FAILURE); - } - f_init = NewString(""); - f_header = NewString(""); - f_wrappers = NewString(""); - f_directors = NewString(""); - f_directors_h = NewString(""); - f_enumtypes_type = NewString(""); - f_enumtypes_value = NewString(""); - init_func_def = NewString(""); - f_mlbody = NewString(""); - f_mlibody = NewString(""); - f_mltail = NewString(""); - f_mlitail = NewString(""); - f_class_ctors = NewString(""); - f_class_ctors_end = NewString(""); - f_enum_to_int = NewString(""); - f_int_to_enum = NewString(""); - f_classtemplate = NewString(""); - - module = Getattr(n,"name"); - - seen_constructors = NewHash(); - seen_enums = NewHash(); - seen_enumvalues = NewHash(); - - /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("init",init_func_def); - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("mli",f_mlibody); - Swig_register_filebyname("ml",f_mlbody); - Swig_register_filebyname("mlitail",f_mlitail); - Swig_register_filebyname("mltail",f_mltail); - Swig_register_filebyname("director",f_directors); - Swig_register_filebyname("director_h",f_directors_h); - Swig_register_filebyname("classtemplate",f_classtemplate); - Swig_register_filebyname("class_ctors",f_class_ctors); - - if (old_variable_names) { - Swig_name_register("set","%v__set__"); - Swig_name_register("get","%v__get__"); - } - - Printf( f_runtime, - "/* -*- buffer-read-only: t -*- vi: set ro: */\n" ); - Printf( f_runtime, "#define SWIG_MODULE \"%s\"\n", module ); - /* Module name */ - Printf( f_mlbody, "let module_name = \"%s\"\n", module ); - Printf( f_mlibody, "val module_name : string\n" ); - Printf( f_enum_to_int, - "let enum_to_int x (v : c_obj) =\n" - " match v with\n" - " C_enum _y ->\n" - " (let y = _y in match (x : c_enum_type) with\n" - " `unknown -> " - " (match y with\n" - " `Int x -> (Swig.C_int x)\n" - " | _ -> raise (LabelNotFromThisEnum v))\n" ); - - Printf( f_int_to_enum, - "let int_to_enum x y =\n" - " match (x : c_enum_type) with\n" - " `unknown -> C_enum (`Int y)\n" ); - - Swig_banner (f_runtime); - - if( directorsEnabled() ) { - Printf( f_runtime, "#define SWIG_DIRECTORS\n"); - } - - /* Produce the enum_to_int and int_to_enum functions */ - - Printf(f_enumtypes_type,"open Swig\n" - "type c_enum_type = [ \n `unknown\n" ); - Printf(f_enumtypes_value,"type c_enum_value = [ \n `Int of int\n" ); - String *mlfile = NewString(""); - String *mlifile = NewString(""); - - Printv(mlfile,module,".ml",NIL); - Printv(mlifile,module,".mli",NIL); - - String *mlfilen = NewStringf("%s%s", SWIG_output_directory(),mlfile); - if ((f_mlout = NewFile(mlfilen,"w")) == 0) { - FileErrorDisplay(mlfilen); - SWIG_exit (EXIT_FAILURE); - } - String *mlifilen = NewStringf("%s%s", SWIG_output_directory(),mlifile); - if ((f_mliout = NewFile(mlifilen,"w")) == 0) { - FileErrorDisplay(mlifilen); - SWIG_exit (EXIT_FAILURE); - } - - Language::top(n); - - Printf( f_enum_to_int, - ") | _ -> (C_int (get_int v))\n" - "let _ = Callback.register \"%s_enum_to_int\" enum_to_int\n", - module ); - Printf( f_mlibody, - "val enum_to_int : c_enum_type -> c_obj -> Swig.c_obj\n" ); - - Printf( f_int_to_enum, - "let _ = Callback.register \"%s_int_to_enum\" int_to_enum\n", - module ); - Printf( f_mlibody, - "val int_to_enum : c_enum_type -> int -> c_obj\n" ); - Printf( f_init, - "#define SWIG_init f_%s_init\n" - "%s" - "}\n", - module, init_func_def ); - Printf( f_mlbody, - "external f_init : unit -> unit = \"f_%s_init\" ;;\n" - "let _ = f_init ()\n", - module, module ); - Printf( f_enumtypes_type, "]\n" ); - Printf( f_enumtypes_value, "]\n\n" - "type c_obj = c_enum_value c_obj_t\n" ); - - if (directorsEnabled()) { - // Insert director runtime into the f_runtime file (make it occur before %header section) - Swig_insert_file("director.swg", f_runtime); - } - - SwigType_emit_type_table (f_runtime, f_wrappers); - /* Close all of the files */ - Dump(f_directors_h,f_header); - Dump(f_header,f_runtime); - Dump(f_directors,f_wrappers); - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); - Delete(f_header); - Delete(f_wrappers); - Delete(f_init); - Close(f_runtime); - Delete(f_runtime); - - Dump(f_enumtypes_type,f_mlout); - Dump(f_enumtypes_value,f_mlout); - Dump(f_mlbody,f_mlout); - Dump(f_enum_to_int,f_mlout); - Dump(f_int_to_enum,f_mlout); - Delete(f_int_to_enum); - Delete(f_enum_to_int); - Dump(f_class_ctors,f_mlout); - Dump(f_class_ctors_end,f_mlout); - Dump(f_mltail,f_mlout); - Close(f_mlout); - Delete(f_mlout); - - Dump(f_enumtypes_type,f_mliout); - Dump(f_enumtypes_value,f_mliout); - Dump(f_mlibody,f_mliout); - Dump(f_mlitail,f_mliout); - Close(f_mliout); - Delete(f_mliout); - - return SWIG_OK; - } - - /* Produce an error for the given type */ - void throw_unhandled_ocaml_type_error (SwigType *d, const char *types) { - Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, - "Unable to handle type %s (%s).\n", SwigType_str(d,0), - types ); + } } - /* Return true iff T is a pointer type */ - int - is_a_pointer (SwigType *t) { - return SwigType_ispointer(SwigType_typedef_resolve_all(t)); + /* Initialize all of the output files */ + String *outfile = Getattr(n, "outfile"); + + f_runtime = NewFile(outfile, "w"); + if (!f_runtime) { + FileErrorDisplay(outfile); + SWIG_exit(EXIT_FAILURE); + } + f_init = NewString(""); + f_header = NewString(""); + f_wrappers = NewString(""); + f_directors = NewString(""); + f_directors_h = NewString(""); + f_enumtypes_type = NewString(""); + f_enumtypes_value = NewString(""); + init_func_def = NewString(""); + f_mlbody = NewString(""); + f_mlibody = NewString(""); + f_mltail = NewString(""); + f_mlitail = NewString(""); + f_class_ctors = NewString(""); + f_class_ctors_end = NewString(""); + f_enum_to_int = NewString(""); + f_int_to_enum = NewString(""); + f_classtemplate = NewString(""); + + module = Getattr(n, "name"); + + seen_constructors = NewHash(); + seen_enums = NewHash(); + seen_enumvalues = NewHash(); + + /* Register file targets with the SWIG file handler */ + Swig_register_filebyname("init", init_func_def); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("mli", f_mlibody); + Swig_register_filebyname("ml", f_mlbody); + Swig_register_filebyname("mlitail", f_mlitail); + Swig_register_filebyname("mltail", f_mltail); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); + Swig_register_filebyname("classtemplate", f_classtemplate); + Swig_register_filebyname("class_ctors", f_class_ctors); + + if (old_variable_names) { + Swig_name_register("set", "%v__set__"); + Swig_name_register("get", "%v__get__"); } - /* - * Delete one reference from a given type. - */ + Printf(f_runtime, "/* -*- buffer-read-only: t -*- vi: set ro: */\n"); + Printf(f_runtime, "#define SWIG_MODULE \"%s\"\n", module); + /* Module name */ + Printf(f_mlbody, "let module_name = \"%s\"\n", module); + Printf(f_mlibody, "val module_name : string\n"); + Printf(f_enum_to_int, + "let enum_to_int x (v : c_obj) =\n" + " match v with\n" + " C_enum _y ->\n" + " (let y = _y in match (x : c_enum_type) with\n" + " `unknown -> " " (match y with\n" " `Int x -> (Swig.C_int x)\n" " | _ -> raise (LabelNotFromThisEnum v))\n"); - void oc_SwigType_del_reference(SwigType *t) { - char *c = Char(t); - if (strncmp(c,"q(",2) == 0) { - Delete(SwigType_pop(t)); - c = Char(t); - } - if (strncmp(c,"r.",2)) { - printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n"); - abort(); - } - Replace(t,"r.","", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + Printf(f_int_to_enum, "let int_to_enum x y =\n" " match (x : c_enum_type) with\n" " `unknown -> C_enum (`Int y)\n"); + + Swig_banner(f_runtime); + + if (directorsEnabled()) { + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); } - void oc_SwigType_del_array(SwigType *t) { - char *c = Char(t); - if (strncmp(c,"q(",2) == 0) { - Delete(SwigType_pop(t)); - c = Char(t); - } - if (strncmp(c,"a(",2) == 0) { - Delete(SwigType_pop(t)); - } - } - - /* - * Return true iff T is a reference type - */ + /* Produce the enum_to_int and int_to_enum functions */ - int - is_a_reference (SwigType *t) { - return SwigType_isreference(SwigType_typedef_resolve_all(t)); + Printf(f_enumtypes_type, "open Swig\n" "type c_enum_type = [ \n `unknown\n"); + Printf(f_enumtypes_value, "type c_enum_value = [ \n `Int of int\n"); + String *mlfile = NewString(""); + String *mlifile = NewString(""); + + Printv(mlfile, module, ".ml", NIL); + Printv(mlifile, module, ".mli", NIL); + + String *mlfilen = NewStringf("%s%s", SWIG_output_directory(), mlfile); + if ((f_mlout = NewFile(mlfilen, "w")) == 0) { + FileErrorDisplay(mlfilen); + SWIG_exit(EXIT_FAILURE); + } + String *mlifilen = NewStringf("%s%s", SWIG_output_directory(), mlifile); + if ((f_mliout = NewFile(mlifilen, "w")) == 0) { + FileErrorDisplay(mlifilen); + SWIG_exit(EXIT_FAILURE); } - int - is_an_array (SwigType *t) { - return SwigType_isarray(SwigType_typedef_resolve_all(t)); + Language::top(n); + + Printf(f_enum_to_int, ") | _ -> (C_int (get_int v))\n" "let _ = Callback.register \"%s_enum_to_int\" enum_to_int\n", module); + Printf(f_mlibody, "val enum_to_int : c_enum_type -> c_obj -> Swig.c_obj\n"); + + Printf(f_int_to_enum, "let _ = Callback.register \"%s_int_to_enum\" int_to_enum\n", module); + Printf(f_mlibody, "val int_to_enum : c_enum_type -> int -> c_obj\n"); + Printf(f_init, "#define SWIG_init f_%s_init\n" "%s" "}\n", module, init_func_def); + Printf(f_mlbody, "external f_init : unit -> unit = \"f_%s_init\" ;;\n" "let _ = f_init ()\n", module, module); + Printf(f_enumtypes_type, "]\n"); + Printf(f_enumtypes_value, "]\n\n" "type c_obj = c_enum_value c_obj_t\n"); + + if (directorsEnabled()) { + // Insert director runtime into the f_runtime file (make it occur before %header section) + Swig_insert_file("director.swg", f_runtime); } - /* ------------------------------------------------------------ - * functionWrapper() - * Create a function declaration and register it with the interpreter. - * ------------------------------------------------------------ */ + SwigType_emit_type_table(f_runtime, f_wrappers); + /* Close all of the files */ + Dump(f_directors_h, f_header); + Dump(f_header, f_runtime); + Dump(f_directors, f_wrappers); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); + Delete(f_header); + Delete(f_wrappers); + Delete(f_init); + Close(f_runtime); + Delete(f_runtime); - virtual int functionWrapper(Node *n) { - char *iname = GetChar(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - String *return_type_normalized = normalizeTemplatedClassName(d); - ParmList *l = Getattr(n,"parms"); - int director_method = 0; - Parm *p; - - Wrapper *f = NewWrapper(); - String *proc_name = NewString(""); - String *source = NewString(""); - String *target = NewString(""); - String *arg = NewString(""); - String *cleanup = NewString(""); - String *outarg = NewString(""); - String *build = NewString(""); - String *tm; - int argout_set = 0; - int i = 0; - int numargs; - int numreq; - int newobj = GetFlag(n,"feature:new"); - String *nodeType = Getattr(n, "nodeType"); - int destructor = (!Cmp(nodeType, "destructor")); - String *overname = 0; - bool isOverloaded = Getattr(n,"sym:overloaded") ? true : false; + Dump(f_enumtypes_type, f_mlout); + Dump(f_enumtypes_value, f_mlout); + Dump(f_mlbody, f_mlout); + Dump(f_enum_to_int, f_mlout); + Dump(f_int_to_enum, f_mlout); + Delete(f_int_to_enum); + Delete(f_enum_to_int); + Dump(f_class_ctors, f_mlout); + Dump(f_class_ctors_end, f_mlout); + Dump(f_mltail, f_mlout); + Close(f_mlout); + Delete(f_mlout); - // Make a wrapper name for this - String *wname = Swig_name_wrapper(iname); - if (isOverloaded) { - overname = Getattr(n,"sym:overname"); + Dump(f_enumtypes_type, f_mliout); + Dump(f_enumtypes_value, f_mliout); + Dump(f_mlibody, f_mliout); + Dump(f_mlitail, f_mliout); + Close(f_mliout); + Delete(f_mliout); + + return SWIG_OK; + } + + /* Produce an error for the given type */ + void throw_unhandled_ocaml_type_error(SwigType *d, const char *types) { + Swig_warning(WARN_TYPEMAP_UNDEF, input_file, line_number, "Unable to handle type %s (%s).\n", SwigType_str(d, 0), types); + } + + /* Return true iff T is a pointer type */ + int + is_a_pointer(SwigType *t) { + return SwigType_ispointer(SwigType_typedef_resolve_all(t)); + } + + /* + * Delete one reference from a given type. + */ + + void oc_SwigType_del_reference(SwigType *t) { + char *c = Char(t); + if (strncmp(c, "q(", 2) == 0) { + Delete(SwigType_pop(t)); + c = Char(t); + } + if (strncmp(c, "r.", 2)) { + printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n"); + abort(); + } + Replace(t, "r.", "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST); + } + + void oc_SwigType_del_array(SwigType *t) { + char *c = Char(t); + if (strncmp(c, "q(", 2) == 0) { + Delete(SwigType_pop(t)); + c = Char(t); + } + if (strncmp(c, "a(", 2) == 0) { + Delete(SwigType_pop(t)); + } + } + + /* + * Return true iff T is a reference type + */ + + int + is_a_reference(SwigType *t) { + return SwigType_isreference(SwigType_typedef_resolve_all(t)); + } + + int + is_an_array(SwigType *t) { + return SwigType_isarray(SwigType_typedef_resolve_all(t)); + } + + /* ------------------------------------------------------------ + * functionWrapper() + * Create a function declaration and register it with the interpreter. + * ------------------------------------------------------------ */ + + virtual int functionWrapper(Node *n) { + char *iname = GetChar(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + String *return_type_normalized = normalizeTemplatedClassName(d); + ParmList *l = Getattr(n, "parms"); + int director_method = 0; + Parm *p; + + Wrapper *f = NewWrapper(); + String *proc_name = NewString(""); + String *source = NewString(""); + String *target = NewString(""); + String *arg = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); + String *build = NewString(""); + String *tm; + int argout_set = 0; + int i = 0; + int numargs; + int numreq; + int newobj = GetFlag(n, "feature:new"); + String *nodeType = Getattr(n, "nodeType"); + int destructor = (!Cmp(nodeType, "destructor")); + String *overname = 0; + bool isOverloaded = Getattr(n, "sym:overloaded") ? true : false; + + // Make a wrapper name for this + String *wname = Swig_name_wrapper(iname); + if (isOverloaded) { + overname = Getattr(n, "sym:overname"); + } else { + if (!addSymbol(iname, n)) + return SWIG_ERROR; + } + if (overname) { + Append(wname, overname); + } + /* Do this to disambiguate functions emitted from different modules */ + Append(wname, module); + + Setattr(n, "wrap:name", wname); + + // Build the name for Scheme. + Printv(proc_name, "_", iname, NIL); + String *mangled_name = mangleNameForCaml(proc_name); + + if (classmode && in_constructor) { // Emit constructor for object + String *mangled_name_nounder = NewString((char *) (Char(mangled_name)) + 1); + Printf(f_class_ctors_end, "let %s clst = _%s clst\n", mangled_name_nounder, mangled_name_nounder); + Printf(f_mlibody, "val %s : c_obj -> c_obj\n", mangled_name_nounder); + Delete(mangled_name_nounder); + } else if (classmode && in_destructor) { + Printf(f_class_ctors, " \"~\", %s ;\n", mangled_name); + } else if (classmode && !in_constructor && !in_destructor && !static_member_function) { + String *opname = Copy(Getattr(n, "name")); + + Replaceall(opname, "operator ", ""); + + if (strstr(Char(mangled_name), "__get__")) { + String *set_name = Copy(mangled_name); + if (!GetFlag(n, "feature:immutable")) { + Replaceall(set_name, "__get__", "__set__"); + Printf(f_class_ctors, " \"%s\", (fun args -> " "if args = (C_list [ raw_ptr ]) then %s args else %s args) ;\n", opname, mangled_name, set_name); + Delete(set_name); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + Printf(f_class_ctors, " \"%s\", (fun args -> " "if args = (C_list [ raw_ptr ]) then %s args else C_void) ;\n", opname, mangled_name); } - if (overname) { - Append(wname, overname); - } - /* Do this to disambiguate functions emitted from different modules */ + } else if (strstr(Char(mangled_name), "__set__")) { + ; /* Nothing ... handled by the case above */ + } else { + Printf(f_class_ctors, " \"%s\", %s ;\n", opname, mangled_name); + } + + Delete(opname); + } + + if (classmode && in_constructor) { + Setattr(seen_constructors, mangled_name, "true"); + } + // writing the function wrapper function + Printv(f->def, "SWIGEXT CAML_VALUE ", wname, " (", NIL); + Printv(f->def, "CAML_VALUE args", NIL); + Printv(f->def, ")\n{", NIL); + + /* Define the scheme name in C. This define is used by several + macros. */ + //Printv(f->def, "#define FUNC_NAME \"", mangled_name, "\"", NIL); + + // adds local variables + Wrapper_add_local(f, "args", "CAMLparam1(args)"); + Wrapper_add_local(f, "ret", "SWIG_CAMLlocal2(swig_result,rv)"); + Wrapper_add_local(f, "_v", "int _v = 0"); + if (isOverloaded) { + Wrapper_add_local(f, "i", "int i"); + Wrapper_add_local(f, "argc", "int argc = caml_list_length(args)"); + Wrapper_add_local(f, "argv", "CAML_VALUE *argv"); + + Printv(f->code, + "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n" + "for( i = 0; i < argc; i++ ) {\n" " argv[i] = caml_list_nth(args,i);\n" "}\n", NIL); + } + // Declare return variable and arguments + // number of parameters + // they are called arg0, arg1, ... + // the return value is called result + + d = SwigType_typedef_qualified(d); + emit_args(d, l, f); + + /* Attach the standard typemaps */ + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); + + numargs = emit_num_arguments(l); + numreq = emit_num_required(l); + + Printf(f->code, "swig_result = Val_unit;\n"); + + // Now write code to extract the parameters (this is super ugly) + + for (i = 0, p = l; i < numargs; i++) { + /* Skip ignored arguments */ + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); + } + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + pt = SwigType_typedef_qualified(pt); + + // Produce names of source and target + Clear(source); + Clear(target); + Clear(arg); + Printf(source, "caml_list_nth(args,%d)", i); + Printf(target, "%s", ln); + Printv(arg, Getattr(p, "name"), NIL); + + if (i >= numreq) { + Printf(f->code, "if (caml_list_length(args) > %d) {\n", i); + } + // Handle parameter types. + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", target); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:in:next"); + } else { + // no typemap found + // check if typedef and resolve + throw_unhandled_ocaml_type_error(pt, "in"); + p = nextSibling(p); + } + if (i >= numreq) { + Printf(f->code, "}\n"); + } + } + + /* Insert constraint checking code */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); + } else { + p = nextSibling(p); + } + } + + // Pass output arguments back to the caller. + + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "emit:input")); /* Deprecated */ + Replaceall(tm, "$target", Getattr(p, "lname")); /* Deprecated */ + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Replaceall(tm, "$ntype", normalizeTemplatedClassName(Getattr(p, "type"))); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); + argout_set = 1; + } else { + p = nextSibling(p); + } + } + + // Free up any memory allocated for the arguments. + + /* Insert cleanup code */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); + } else { + p = nextSibling(p); + } + } + + /* if the object is a director, and the method call originated from its + * underlying python object, resolve the call by going up the c++ + * inheritance chain. otherwise try to resolve the method in python. + * without this check an infinite loop is set up between the director and + * shadow class method calls. + */ + + // NOTE: this code should only be inserted if this class is the + // base class of a director class. however, in general we haven't + // yet analyzed all classes derived from this one to see if they are + // directors. furthermore, this class may be used as the base of + // a director class defined in a completely different module at a + // later time, so this test must be included whether or not directorbase + // is true. we do skip this code if directors have not been enabled + // at the command line to preserve source-level compatibility with + // non-polymorphic swig. also, if this wrapper is for a smart-pointer + // method, there is no need to perform the test since the calling object + // (the smart-pointer) and the director object (the "pointee") are + // distinct. + + director_method = is_member_director(n) && !is_smart_pointer() && !destructor; + if (director_method) { + Wrapper_add_local(f, "director", "Swig::Director *director = 0"); + Printf(f->code, "director = dynamic_cast(arg1);\n"); + Wrapper_add_local(f, "upcall", "bool upcall = false"); + Append(f->code, "upcall = (director);\n"); + } + // Now write code to make the function call + + emit_action(n, f); + + // Now have return value, figure out what to do with it. + + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + Replaceall(tm, "$source", "swig_result"); + Replaceall(tm, "$target", "rv"); + Replaceall(tm, "$result", "rv"); + Replaceall(tm, "$ntype", return_type_normalized); + Printv(f->code, tm, "\n", NIL); + } else { + throw_unhandled_ocaml_type_error(d, "out"); + } + + // Dump the argument output code + Printv(f->code, Char(outarg), NIL); + + // Dump the argument cleanup code + Printv(f->code, Char(cleanup), NIL); + + // Look for any remaining cleanup + + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "swig_result"); + Printv(f->code, tm, "\n", NIL); + } + } + // Free any memory allocated by the function being wrapped.. + + if ((tm = Swig_typemap_lookup_new("swig_result", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); + } + // Wrap things up (in a manner of speaking) + + Printv(f->code, tab4, "swig_result = caml_list_append(swig_result,rv);\n", NIL); + if (isOverloaded) + Printv(f->code, "free(argv);\n", NIL); + Printv(f->code, tab4, "CAMLreturn(swig_result);\n", NIL); + Printv(f->code, "}\n", NIL); + + /* Substitute the function name */ + Replaceall(f->code, "$symname", iname); + + Wrapper_print(f, f_wrappers); + + if (isOverloaded) { + if (!Getattr(n, "sym:nextSibling")) { + int maxargs; + Wrapper *df = NewWrapper(); + String *dispatch = Swig_overload_dispatch(n, + "free(argv);\n" "CAMLreturn(%s(args));\n", + &maxargs); + + Wrapper_add_local(df, "_v", "int _v = 0"); + Wrapper_add_local(df, "argv", "CAML_VALUE *argv"); + + /* Undifferentiate name .. this is the dispatch function */ + wname = Swig_name_wrapper(iname); + /* Do this to disambiguate functions emitted from different + * modules */ Append(wname, module); - Setattr(n,"wrap:name",wname); + Printv(df->def, + "SWIGEXT CAML_VALUE ", wname, "(CAML_VALUE args) {\n" " CAMLparam1(args);\n" " int i;\n" " int argc = caml_list_length(args);\n", NIL); + Printv(df->code, + "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n" + "for( i = 0; i < argc; i++ ) {\n" " argv[i] = caml_list_nth(args,i);\n" "}\n", NIL); + Printv(df->code, dispatch, "\n", NIL); + Printf(df->code, "failwith(\"No matching function for overloaded '%s'\");\n", iname); + Printv(df->code, "}\n", NIL); + Wrapper_print(df, f_wrappers); - // Build the name for Scheme. - Printv(proc_name,"_",iname,NIL); - String *mangled_name = mangleNameForCaml(proc_name); - - if( classmode && in_constructor ) { // Emit constructor for object - String *mangled_name_nounder = - NewString((char *)(Char(mangled_name))+1); - Printf( f_class_ctors_end, - "let %s clst = _%s clst\n", - mangled_name_nounder, mangled_name_nounder ); - Printf(f_mlibody, - "val %s : c_obj -> c_obj\n", - mangled_name_nounder ); - Delete(mangled_name_nounder); - } else if( classmode && in_destructor ) { - Printf(f_class_ctors, - " \"~\", %s ;\n", mangled_name ); - } else if( classmode && !in_constructor && !in_destructor && - !static_member_function ) { - String *opname = Copy(Getattr(n,"name")); - - Replaceall(opname,"operator ",""); - - if( strstr( Char(mangled_name), "__get__" ) ) { - String *set_name = Copy(mangled_name); - if( !GetFlag(n,"feature:immutable") ) { - Replaceall(set_name,"__get__","__set__"); - Printf(f_class_ctors, - " \"%s\", (fun args -> " - "if args = (C_list [ raw_ptr ]) then %s args else %s args) ;\n", - opname, mangled_name, set_name ); - Delete(set_name); - } else { - Printf(f_class_ctors, - " \"%s\", (fun args -> " - "if args = (C_list [ raw_ptr ]) then %s args else C_void) ;\n", - opname, mangled_name ); - } - } else if( strstr( Char(mangled_name), "__set__" ) ) { - ; /* Nothing ... handled by the case above */ - } else { - Printf(f_class_ctors, - " \"%s\", %s ;\n", - opname, mangled_name); - } - - Delete(opname); - } - - if( classmode && in_constructor ) { - Setattr(seen_constructors,mangled_name,"true"); - } - - // writing the function wrapper function - Printv(f->def, - "SWIGEXT CAML_VALUE ", wname, " (", NIL); - Printv(f->def, "CAML_VALUE args", NIL); - Printv(f->def, ")\n{", NIL); - - /* Define the scheme name in C. This define is used by several - macros. */ - //Printv(f->def, "#define FUNC_NAME \"", mangled_name, "\"", NIL); - - // adds local variables - Wrapper_add_local(f, "args", "CAMLparam1(args)"); - Wrapper_add_local(f, "ret" , "SWIG_CAMLlocal2(swig_result,rv)"); - Wrapper_add_local(f, "_v" , "int _v = 0"); - if( isOverloaded ) { - Wrapper_add_local(f, "i" , "int i"); - Wrapper_add_local(f, "argc", "int argc = caml_list_length(args)"); - Wrapper_add_local(f, "argv", "CAML_VALUE *argv"); - - Printv( f->code, - "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n" - "for( i = 0; i < argc; i++ ) {\n" - " argv[i] = caml_list_nth(args,i);\n" - "}\n", NIL ); - } - - // Declare return variable and arguments - // number of parameters - // they are called arg0, arg1, ... - // the return value is called result - - d = SwigType_typedef_qualified(d); - emit_args(d, l, f); - - /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); - - numargs = emit_num_arguments(l); - numreq = emit_num_required(l); - - Printf(f->code,"swig_result = Val_unit;\n" ); - - // Now write code to extract the parameters (this is super ugly) - - for (i = 0, p = l; i < numargs; i++) { - /* Skip ignored arguments */ - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); - } - - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); - pt = SwigType_typedef_qualified(pt); - - // Produce names of source and target - Clear(source); - Clear(target); - Clear(arg); - Printf(source, "caml_list_nth(args,%d)", i); - Printf(target, "%s",ln); - Printv(arg, Getattr(p,"name"),NIL); - - if (i >= numreq) { - Printf(f->code,"if (caml_list_length(args) > %d) {\n",i); - } - // Handle parameter types. - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$source",source); - Replaceall(tm,"$target",target); - Replaceall(tm,"$input",source); - Setattr(p,"emit:input",source); - Printv(f->code, tm, "\n", NIL); - p = Getattr(p,"tmap:in:next"); - } else { - // no typemap found - // check if typedef and resolve - throw_unhandled_ocaml_type_error (pt,"in"); - p = nextSibling(p); - } - if (i >= numreq) { - Printf(f->code,"}\n"); - } - } - - /* Insert constraint checking code */ - for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); - } else { - p = nextSibling(p); - } - } - - // Pass output arguments back to the caller. - - for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"emit:input")); /* Deprecated */ - Replaceall(tm,"$target",Getattr(p,"lname")); /* Deprecated */ - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Replaceall(tm,"$ntype", - normalizeTemplatedClassName(Getattr(p,"type"))); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); - argout_set = 1; - } else { - p = nextSibling(p); - } - } - - // Free up any memory allocated for the arguments. - - /* Insert cleanup code */ - for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); - } else { - p = nextSibling(p); - } - } - - /* if the object is a director, and the method call originated from its - * underlying python object, resolve the call by going up the c++ - * inheritance chain. otherwise try to resolve the method in python. - * without this check an infinite loop is set up between the director and - * shadow class method calls. - */ - - // NOTE: this code should only be inserted if this class is the - // base class of a director class. however, in general we haven't - // yet analyzed all classes derived from this one to see if they are - // directors. furthermore, this class may be used as the base of - // a director class defined in a completely different module at a - // later time, so this test must be included whether or not directorbase - // is true. we do skip this code if directors have not been enabled - // at the command line to preserve source-level compatibility with - // non-polymorphic swig. also, if this wrapper is for a smart-pointer - // method, there is no need to perform the test since the calling object - // (the smart-pointer) and the director object (the "pointee") are - // distinct. - - director_method = is_member_director(n) && !is_smart_pointer() && !destructor; - if (director_method) { - Wrapper_add_local(f, "director", "Swig::Director *director = 0"); - Printf(f->code, "director = dynamic_cast(arg1);\n"); - Wrapper_add_local(f, "upcall", "bool upcall = false"); - Append(f->code, "upcall = (director);\n"); - } - - // Now write code to make the function call - - emit_action(n,f); - - // Now have return value, figure out what to do with it. - - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - Replaceall(tm,"$source","swig_result"); - Replaceall(tm,"$target","rv"); - Replaceall(tm,"$result","rv"); - Replaceall(tm,"$ntype",return_type_normalized); - Printv(f->code, tm, "\n",NIL); - } else { - throw_unhandled_ocaml_type_error (d, "out"); - } - - // Dump the argument output code - Printv(f->code, Char(outarg),NIL); - - // Dump the argument cleanup code - Printv(f->code, Char(cleanup),NIL); - - // Look for any remaining cleanup - - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","swig_result"); - Printv(f->code, tm, "\n",NIL); - } - } - - // Free any memory allocated by the function being wrapped.. - - if ((tm = Swig_typemap_lookup_new("swig_result",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printv(f->code, tm, "\n",NIL); - } - - // Wrap things up (in a manner of speaking) - - Printv(f->code, - tab4, "swig_result = caml_list_append(swig_result,rv);\n", NIL); - if( isOverloaded ) - Printv(f->code, "free(argv);\n", NIL); - Printv(f->code, - tab4, "CAMLreturn(swig_result);\n", NIL ); - Printv(f->code, "}\n",NIL); - - /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); - - Wrapper_print(f, f_wrappers); - - if( isOverloaded ) { - if( !Getattr(n,"sym:nextSibling") ) { - int maxargs; - Wrapper *df = NewWrapper(); - String *dispatch = - Swig_overload_dispatch(n, - "free(argv);\n" - "CAMLreturn(%s(args));\n", - &maxargs); - - Wrapper_add_local(df, "_v", "int _v = 0"); - Wrapper_add_local(df, "argv", "CAML_VALUE *argv"); - - /* Undifferentiate name .. this is the dispatch function */ - wname = Swig_name_wrapper(iname); - /* Do this to disambiguate functions emitted from different - * modules */ - Append(wname, module); - - Printv(df->def, - "SWIGEXT CAML_VALUE ",wname,"(CAML_VALUE args) {\n" - " CAMLparam1(args);\n" - " int i;\n" - " int argc = caml_list_length(args);\n",NIL); - Printv( df->code, - "argv = (CAML_VALUE *)malloc( argc * sizeof( CAML_VALUE ) );\n" - "for( i = 0; i < argc; i++ ) {\n" - " argv[i] = caml_list_nth(args,i);\n" - "}\n", NIL ); - Printv(df->code,dispatch,"\n",NIL); - Printf(df->code,"failwith(\"No matching function for overloaded '%s'\");\n", iname); - Printv(df->code,"}\n",NIL); - Wrapper_print(df,f_wrappers); - - DelWrapper(df); - Delete(dispatch); - } - } - - Printf(f_mlbody, - "external %s_f : c_obj list -> c_obj list = \"%s\" ;;\n" - "let %s arg = match %s_f (fnhelper arg) with\n" - " [] -> C_void\n" - "| [x] -> (if %s then Gc.finalise \n" - " (fun x -> ignore ((invoke x) \"~\" C_void)) x) ; x\n" - "| lst -> C_list lst ;;\n", - mangled_name, wname, - mangled_name, mangled_name, newobj ? "true" : "false"); - - if( !classmode || in_constructor || in_destructor || - static_member_function ) - Printf(f_mlibody, - "val %s : c_obj -> c_obj\n", mangled_name ); - - Delete(proc_name); - Delete(source); - Delete(target); - Delete(arg); - Delete(outarg); - Delete(cleanup); - Delete(build); - DelWrapper(f); - return SWIG_OK; + DelWrapper(df); + Delete(dispatch); + } } - /* ------------------------------------------------------------ - * variableWrapper() - * - * Create a link to a C variable. - * This creates a single function _wrap_swig_var_varname(). - * This function takes a single optional argument. If supplied, it means - * we are setting this variable to some value. If omitted, it means we are - * simply evaluating this variable. In the set case we return C_void. - * - * symname is the name of the variable with respect to C. This - * may need to differ from the original name in the case of enums. - * enumvname is the name of the variable with respect to ocaml. This - * will vary if the variable has been renamed. - * ------------------------------------------------------------ */ + Printf(f_mlbody, + "external %s_f : c_obj list -> c_obj list = \"%s\" ;;\n" + "let %s arg = match %s_f (fnhelper arg) with\n" + " [] -> C_void\n" + "| [x] -> (if %s then Gc.finalise \n" + " (fun x -> ignore ((invoke x) \"~\" C_void)) x) ; x\n" + "| lst -> C_list lst ;;\n", mangled_name, wname, mangled_name, mangled_name, newobj ? "true" : "false"); - virtual int variableWrapper(Node *n) { - char *name = GetChar(n,"feature:symname"); - String *iname = Getattr(n,"feature:enumvname"); - String *mname = mangleNameForCaml(iname); - SwigType *t = Getattr(n,"type"); - - String *proc_name = NewString(""); - String *tm; - String *tm2 = NewString("");; - String *argnum = NewString("0"); - String *arg = NewString("SWIG_Field(args,0)"); - Wrapper *f; + if (!classmode || in_constructor || in_destructor || static_member_function) + Printf(f_mlibody, "val %s : c_obj -> c_obj\n", mangled_name); - if( !name ) { - name = GetChar(n,"name"); - } + Delete(proc_name); + Delete(source); + Delete(target); + Delete(arg); + Delete(outarg); + Delete(cleanup); + Delete(build); + DelWrapper(f); + return SWIG_OK; + } - if( !iname ) { - iname = Getattr(n,"sym:name"); - mname = mangleNameForCaml(NewString(iname)); - } + /* ------------------------------------------------------------ + * variableWrapper() + * + * Create a link to a C variable. + * This creates a single function _wrap_swig_var_varname(). + * This function takes a single optional argument. If supplied, it means + * we are setting this variable to some value. If omitted, it means we are + * simply evaluating this variable. In the set case we return C_void. + * + * symname is the name of the variable with respect to C. This + * may need to differ from the original name in the case of enums. + * enumvname is the name of the variable with respect to ocaml. This + * will vary if the variable has been renamed. + * ------------------------------------------------------------ */ - if (!iname || !addSymbol(iname,n)) return SWIG_ERROR; - - f = NewWrapper(); + virtual int variableWrapper(Node *n) { + char *name = GetChar(n, "feature:symname"); + String *iname = Getattr(n, "feature:enumvname"); + String *mname = mangleNameForCaml(iname); + SwigType *t = Getattr(n, "type"); - // evaluation function names - String *var_name = Swig_name_wrapper(iname); + String *proc_name = NewString(""); + String *tm; + String *tm2 = NewString("");; + String *argnum = NewString("0"); + String *arg = NewString("SWIG_Field(args,0)"); + Wrapper *f; - // Build the name for scheme. - Printv(proc_name, iname, NIL); - - Printf (f->def, - "SWIGEXT CAML_VALUE %s(CAML_VALUE args) {\n", var_name); - // Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - - Wrapper_add_local (f, "swig_result", "CAML_VALUE swig_result"); - - if (!GetFlag(n,"feature:immutable")) { - /* Check for a setting of the variable value */ - Printf (f->code, "if (args != Val_int(0)) {\n"); - if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { - Replaceall(tm,"$source","args"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","args"); - /* Printv(f->code, tm, "\n",NIL); */ - emit_action_code(n, f, tm); - } else if ((tm = Swig_typemap_lookup_new("in",n,name,0))) { - Replaceall(tm,"$source","args"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","args"); - Printv(f->code, tm, "\n",NIL); - } else { - throw_unhandled_ocaml_type_error (t, "varin/in"); - } - Printf (f->code, "}\n"); - } - - // Now return the value of the variable (regardless - // of evaluating or setting) - - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source",name); - Replaceall(tm,"$target","swig_result"); - Replaceall(tm,"$result","swig_result"); - /* Printf (f->code, "%s\n", tm); */ - emit_action_code(n, f, tm); - } else if ((tm = Swig_typemap_lookup_new("out",n,name,0))) { - Replaceall(tm,"$source",name); - Replaceall(tm,"$target","swig_result"); - Replaceall(tm,"$result","swig_result"); - Printf (f->code, "%s\n", tm); - - } else { - throw_unhandled_ocaml_type_error (t, "varout/out"); - } - - Printf (f->code, "\nreturn swig_result;\n"); - Printf (f->code, "}\n"); - - Wrapper_print (f, f_wrappers); - - // Now add symbol to the Ocaml interpreter - - if( GetFlag( n, "feature:immutable" ) ) { - Printf( f_mlbody, - "external _%s : c_obj -> Swig.c_obj = \"%s\" \n", - mname, var_name ); - Printf( f_mlibody, "val _%s : c_obj -> Swig.c_obj\n", iname ); - if( const_enum ) { - Printf( f_enum_to_int, - " | `%s -> _%s C_void\n", - mname, mname ); - Printf( f_int_to_enum, - " if y = (get_int (_%s C_void)) then `%s else\n", - mname, mname ); - } - } else { - Printf( f_mlbody, "external _%s : c_obj -> c_obj = \"%s\"\n", - mname, var_name ); - Printf( f_mlibody, "external _%s : c_obj -> c_obj = \"%s\"\n", - mname, var_name ); - } - - Delete(var_name); - Delete(proc_name); - Delete(argnum); - Delete(arg); - Delete(tm2); - DelWrapper(f); - return SWIG_OK; + if (!name) { + name = GetChar(n, "name"); } - /* ------------------------------------------------------------ - * staticmemberfunctionHandler -- - * Overridden to set static_member_function - * ------------------------------------------------------------ */ - - virtual int staticmemberfunctionHandler( Node *n ) { - int rv; - static_member_function = 1; - rv = Language::staticmemberfunctionHandler( n ); - static_member_function = 0; - return SWIG_OK; + if (!iname) { + iname = Getattr(n, "sym:name"); + mname = mangleNameForCaml(NewString(iname)); } - /* ------------------------------------------------------------ - * constantWrapper() - * - * The one trick here is that we have to make sure we rename the - * constant to something useful that doesn't collide with the - * original if any exists. - * ------------------------------------------------------------ */ + if (!iname || !addSymbol(iname, n)) + return SWIG_ERROR; - virtual int constantWrapper(Node *n) { - String *name = Getattr(n,"feature:symname"); - SwigType *type = Getattr(n,"type"); - String *value = Getattr(n,"value"); - String *qvalue = Getattr(n,"qualified:value"); - String *rvalue = NewString(""); - String *temp = 0; + f = NewWrapper(); - if( qvalue ) value = qvalue; + // evaluation function names + String *var_name = Swig_name_wrapper(iname); - if( !name ) { - name = mangleNameForCaml(Getattr(n,"name")); - Insert(name,0,"_swig_wrap_"); - Setattr(n,"feature:symname",name); - } + // Build the name for scheme. + Printv(proc_name, iname, NIL); - // See if there's a typemap - - Printv(rvalue, value,NIL); - if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 1)) { - temp = Copy(rvalue); - Clear(rvalue); - Printv(rvalue, "\"", temp, "\"",NIL); - Delete(temp); - } - if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 0)) { - temp = Copy(rvalue); - Clear(rvalue); - Printv(rvalue, "'", temp, "'",NIL); - Delete(temp); - } + Printf(f->def, "SWIGEXT CAML_VALUE %s(CAML_VALUE args) {\n", var_name); + // Printv(f->def, "#define FUNC_NAME \"", proc_name, "\"", NIL); - // Create variable and assign it a value - - Printf (f_header, "static %s = ", SwigType_lstr(type,name)); - if ((SwigType_type(type) == T_STRING)) { - Printf (f_header, "\"%s\";\n", value); - } else if (SwigType_type(type) == T_CHAR) { - Printf (f_header, "\'%s\';\n", value); - } else { - Printf (f_header, "%s;\n", value); - } + Wrapper_add_local(f, "swig_result", "CAML_VALUE swig_result"); - SetFlag(n,"feature:immutable"); - variableWrapper(n); - return SWIG_OK; + if (!GetFlag(n, "feature:immutable")) { + /* Check for a setting of the variable value */ + Printf(f->code, "if (args != Val_int(0)) {\n"); + if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { + Replaceall(tm, "$source", "args"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "args"); + /* Printv(f->code, tm, "\n",NIL); */ + emit_action_code(n, f, tm); + } else if ((tm = Swig_typemap_lookup_new("in", n, name, 0))) { + Replaceall(tm, "$source", "args"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "args"); + Printv(f->code, tm, "\n", NIL); + } else { + throw_unhandled_ocaml_type_error(t, "varin/in"); + } + Printf(f->code, "}\n"); } - - int constructorHandler(Node *n) { - int ret; + // Now return the value of the variable (regardless + // of evaluating or setting) - in_constructor = 1; - ret = Language::constructorHandler(n); - in_constructor = 0; + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "swig_result"); + Replaceall(tm, "$result", "swig_result"); + /* Printf (f->code, "%s\n", tm); */ + emit_action_code(n, f, tm); + } else if ((tm = Swig_typemap_lookup_new("out", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "swig_result"); + Replaceall(tm, "$result", "swig_result"); + Printf(f->code, "%s\n", tm); - return ret; + } else { + throw_unhandled_ocaml_type_error(t, "varout/out"); } - /* destructorHandler: - * Turn on destructor flag to inform decisions in functionWrapper - */ + Printf(f->code, "\nreturn swig_result;\n"); + Printf(f->code, "}\n"); - int destructorHandler(Node *n) { - int ret; + Wrapper_print(f, f_wrappers); - in_destructor = 1; - ret = Language::destructorHandler(n); - in_destructor = 0; - - return ret; + // Now add symbol to the Ocaml interpreter + + if (GetFlag(n, "feature:immutable")) { + Printf(f_mlbody, "external _%s : c_obj -> Swig.c_obj = \"%s\" \n", mname, var_name); + Printf(f_mlibody, "val _%s : c_obj -> Swig.c_obj\n", iname); + if (const_enum) { + Printf(f_enum_to_int, " | `%s -> _%s C_void\n", mname, mname); + Printf(f_int_to_enum, " if y = (get_int (_%s C_void)) then `%s else\n", mname, mname); + } + } else { + Printf(f_mlbody, "external _%s : c_obj -> c_obj = \"%s\"\n", mname, var_name); + Printf(f_mlibody, "external _%s : c_obj -> c_obj = \"%s\"\n", mname, var_name); } - /* copyconstructorHandler: - * Turn on constructor and copyconstructor flags for functionWrapper - */ + Delete(var_name); + Delete(proc_name); + Delete(argnum); + Delete(arg); + Delete(tm2); + DelWrapper(f); + return SWIG_OK; + } - int copyconstructorHandler(Node *n) { - int ret; + /* ------------------------------------------------------------ + * staticmemberfunctionHandler -- + * Overridden to set static_member_function + * ------------------------------------------------------------ */ - in_copyconst = 1; - in_constructor = 1; - ret = Language::copyconstructorHandler(n); - in_constructor = 0; - in_copyconst = 0; + virtual int staticmemberfunctionHandler(Node *n) { + int rv; + static_member_function = 1; + rv = Language::staticmemberfunctionHandler(n); + static_member_function = 0; + return SWIG_OK; + } - return ret; + /* ------------------------------------------------------------ + * constantWrapper() + * + * The one trick here is that we have to make sure we rename the + * constant to something useful that doesn't collide with the + * original if any exists. + * ------------------------------------------------------------ */ + + virtual int constantWrapper(Node *n) { + String *name = Getattr(n, "feature:symname"); + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + String *qvalue = Getattr(n, "qualified:value"); + String *rvalue = NewString(""); + String *temp = 0; + + if (qvalue) + value = qvalue; + + if (!name) { + name = mangleNameForCaml(Getattr(n, "name")); + Insert(name, 0, "_swig_wrap_"); + Setattr(n, "feature:symname", name); } + // See if there's a typemap + + Printv(rvalue, value, NIL); + if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 1)) { + temp = Copy(rvalue); + Clear(rvalue); + Printv(rvalue, "\"", temp, "\"", NIL); + Delete(temp); + } + if ((SwigType_type(type) == T_CHAR) && (is_a_pointer(type) == 0)) { + temp = Copy(rvalue); + Clear(rvalue); + Printv(rvalue, "'", temp, "'", NIL); + Delete(temp); + } + // Create variable and assign it a value + + Printf(f_header, "static %s = ", SwigType_lstr(type, name)); + if ((SwigType_type(type) == T_STRING)) { + Printf(f_header, "\"%s\";\n", value); + } else if (SwigType_type(type) == T_CHAR) { + Printf(f_header, "\'%s\';\n", value); + } else { + Printf(f_header, "%s;\n", value); + } + + SetFlag(n, "feature:immutable"); + variableWrapper(n); + return SWIG_OK; + } + + int constructorHandler(Node *n) { + int ret; + + in_constructor = 1; + ret = Language::constructorHandler(n); + in_constructor = 0; + + return ret; + } + + /* destructorHandler: + * Turn on destructor flag to inform decisions in functionWrapper + */ + + int destructorHandler(Node *n) { + int ret; + + in_destructor = 1; + ret = Language::destructorHandler(n); + in_destructor = 0; + + return ret; + } + + /* copyconstructorHandler: + * Turn on constructor and copyconstructor flags for functionWrapper + */ + + int copyconstructorHandler(Node *n) { + int ret; + + in_copyconst = 1; + in_constructor = 1; + ret = Language::copyconstructorHandler(n); + in_constructor = 0; + in_copyconst = 0; + + return ret; + } /** * A simple, somewhat general purpose function for writing to multiple @@ -1060,928 +981,898 @@ public: * fiddle with when I want to change methods, etc. */ - void Multiwrite( String *s ) { - char *find_marker = strstr(Char(s),"(*Stream:"); - while( find_marker ) { - char *next = strstr(find_marker,"*)"); - find_marker += strlen("(*Stream:"); + void Multiwrite(String *s) { + char *find_marker = strstr(Char(s), "(*Stream:"); + while (find_marker) { + char *next = strstr(find_marker, "*)"); + find_marker += strlen("(*Stream:"); - if( next ) { - int num_chars = next - find_marker; - String *stream_name = NewString(find_marker); - Delslice(stream_name,num_chars,Len(stream_name)); - File *fout = Swig_filebyname(stream_name); - if( fout ) { - next += strlen("*)"); - char *following = strstr(next,"(*Stream:"); - find_marker = following; - if( !following ) following = next + strlen(next); - String *chunk = NewString(next); - Delslice(chunk,following-next,Len(chunk)); - Printv(fout,chunk,NIL); - } - } + if (next) { + int num_chars = next - find_marker; + String *stream_name = NewString(find_marker); + Delslice(stream_name, num_chars, Len(stream_name)); + File *fout = Swig_filebyname(stream_name); + if (fout) { + next += strlen("*)"); + char *following = strstr(next, "(*Stream:"); + find_marker = following; + if (!following) + following = next + strlen(next); + String *chunk = NewString(next); + Delslice(chunk, following - next, Len(chunk)); + Printv(fout, chunk, NIL); } - } - - bool isSimpleType( String *name ) { - char *ch = Char(name); - - return - !(strchr(ch,'(') || strchr(ch,'<') || - strchr(ch,')') || strchr(ch,'>')); - } - - /* We accept all chars in identifiers because we use strings to index - * them. */ - int validIdentifier( String *name ) { - return Len(name) > 0 ? 1 : 0; - } - - /* classHandler - * - * Create a "class" definition for ocaml. I thought quite a bit about - * how I should do this part of it, and arrived here, using a function - * invocation to select a method, and dispatch. This can obviously be - * done better, but I can't see how, given that I want to support - * overloaded methods, out parameters, and operators. - * - * I needed a system that would do this: - * - * a Be able to call these methods: - * int foo( int x ); - * float foo( int x, int &out ); - * - * b Be typeable, even in the presence of mutually dependent classes. - * - * c Support some form of operator invocation. - * - * (c) I chose strings for the method names so that "+=" would be a - * valid method name, and the somewhat natural << (invoke x) "+=" y >> - * would work. - * - * (a) (b) Since the c_obj type exists, it's easy to return C_int in one - * case and C_list [ C_float ; C_int ] in the other. This makes tricky - * problems with out parameters disappear; they're simply appended to the - * return list. - * - * (b) Since every item that comes from C++ is the same type, there is no - * problem with the following: - * - * class Foo; - * class Bar { Foo *toFoo(); } - * class Foo { Bar *toBar(); } - * - * Since the Objective caml types of Foo and Bar are the same. Now that - * I correctly incorporate SWIG's typechecking, this isn't a big deal. - * - * The class is in the form of a function returning a c_obj. The c_obj - * is a C_obj containing a function which invokes a method on the - * underlying object given its type. - * - * The name emitted here is normalized before being sent to - * Callback.register, because we need this string to look up properly - * when the typemap passes the descriptor string. I've been considering - * some, possibly more forgiving method that would do some transformations - * on the $descriptor in order to find a potential match. This is for - * later. - * - * Important things to note: - * - * We rely on exception handling (BadMethodName) in order to call an - * ancestor. This can be improved. - * - * The method used to get :classof could be improved to look at the type - * info that the base pointer contains. It's really an error to have a - * SWIG-generated object that does not contain type info, since the - * existence of the object means that SWIG knows the type. - * - * :parents could use :classof to tell what class it is and make a better - * decision. This could be nice, (i.e. provide a run-time graph of C++ - * classes represented);. - * - * I can't think of a more elegant way of converting a C_obj fun to a - * pointer than "operator &"... - * - * Added a 'sizeof' that will allow you to do the expected thing. - * This should help users to fill buffer structs and the like (as is - * typical in windows-styled code). It's only enabled if you give - * %feature(sizeof) and then, only for simple types. - * - * Overall, carrying the list of methods and base classes has worked well. - * It allows me to give the Ocaml user introspection over their objects. - */ - - int classHandler( Node *n ) { - String *name = Getattr(n,"name"); - String *mangled_sym_name = mangleNameForCaml(name); - String *this_class_def = NewString( f_classtemplate ); - String *name_normalized = normalizeTemplatedClassName(name); - String *old_class_ctors = f_class_ctors; - String *base_classes = NewString(""); - f_class_ctors = NewString(""); - bool sizeof_feature = generate_sizeof && isSimpleType(name); - - if( !name ) return SWIG_OK; - - classname = mangled_sym_name; - classmode = true; - int rv = Language::classHandler(n); - classmode = false; - - if( sizeof_feature ) { - Printf( f_wrappers, - "SWIGEXT CAML_VALUE _wrap_%s_sizeof( CAML_VALUE args ) {\n" - " CAMLparam1(args);\n" - " CAMLreturn(Val_int(sizeof(%s)));\n" - "}\n", - mangled_sym_name, name_normalized ); - - Printf( f_mlbody, "external __%s_sizeof : unit -> int = " - "\"_wrap_%s_sizeof\"\n", - classname, mangled_sym_name ); - } - - - /* Insert sizeof operator for concrete classes */ - if( sizeof_feature ) { - Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__", - classname, "_sizeof ())) ;\n", NIL); - } - /* Handle up-casts in a nice way */ - List *baselist = Getattr(n,"bases"); - if (baselist && Len(baselist)) { - Iterator b; - b = First(baselist); - while (b.item) { - String *bname = Getattr(b.item, "name"); - if (bname) { - String *base_create = NewString(""); - Printv(base_create,"(create_class \"",bname,"\")",NIL); - Printv(f_class_ctors, - " \"::",bname,"\", (fun args -> ", - base_create," args) ;\n",NIL); - Printv( base_classes, base_create, " ;\n", NIL ); - } - b = Next(b); - } - } - - Replaceall(this_class_def,"$classname",classname); - Replaceall(this_class_def,"$normalized",name_normalized); - Replaceall(this_class_def,"$realname",name); - Replaceall(this_class_def,"$baselist",base_classes); - Replaceall(this_class_def,"$classbody",f_class_ctors); - - Delete(f_class_ctors); - f_class_ctors = old_class_ctors; - - // Actually write out the class definition - - Multiwrite( this_class_def ); - - Setattr(n,"ocaml:ctor",classname); - - return rv; - } - - String *normalizeTemplatedClassName( String *name ) { - String *name_normalized = SwigType_typedef_resolve_all(name); - bool took_action; - - do { - took_action = false; - - if( is_a_pointer(name_normalized) ) { - SwigType_del_pointer( name_normalized ); - took_action = true; - } - - if( is_a_reference(name_normalized) ) { - oc_SwigType_del_reference( name_normalized ); - took_action = true; - } - - if( is_an_array(name_normalized) ) { - oc_SwigType_del_array( name_normalized ); - took_action = true; - } - } while( took_action ); - - return SwigType_str(name_normalized,0); - } - - /* - * Produce the symbol name that ocaml will use when referring to the - * target item. I wonder if there's a better way to do this: - * - * I shudder to think about doing it with a hash lookup, but that would - * make a couple of things easier: - */ - - String *mangleNameForCaml( String *s ) { - String *out = Copy(s); - Replaceall(out," ","_xx"); - Replaceall(out,"::","_xx"); - Replaceall(out,",","_x"); - Replaceall(out,"+","_xx_plus"); - Replaceall(out,"-","_xx_minus"); - Replaceall(out,"<","_xx_ldbrace"); - Replaceall(out,">","_xx_rdbrace"); - Replaceall(out,"!","_xx_not"); - Replaceall(out,"%","_xx_mod"); - Replaceall(out,"^","_xx_xor"); - Replaceall(out,"*","_xx_star"); - Replaceall(out,"&","_xx_amp"); - Replaceall(out,"|","_xx_or"); - Replaceall(out,"(","_xx_lparen"); - Replaceall(out,")","_xx_rparen"); - Replaceall(out,"[","_xx_lbrace"); - Replaceall(out,"]","_xx_rbrace"); - Replaceall(out,"~","_xx_bnot"); - Replaceall(out,"=","_xx_equals"); - Replaceall(out,"/","_xx_slash"); - Replaceall(out,".","_xx_dot"); - return out; - } - - String *fully_qualify_enum_name( Node *n, String *name ) { - Node *parent = 0; - String *qualification = NewString(""); - String *fully_qualified_name = NewString(""); - String *parent_type = 0; - String *normalized_name; - - parent = parentNode(n); - while( parent ) { - parent_type = nodeType(parent); - if( Getattr(parent,"name") ) { - String *parent_copy = - NewStringf("%s::",Getattr(parent,"name")); - if( !Cmp(parent_type,"class") || - !Cmp(parent_type,"namespace") ) - Insert(qualification,0,parent_copy); - Delete(parent_copy); - } - if( !Cmp( parent_type, "class" ) ) break; - parent = parentNode(parent); - } - - Printf( fully_qualified_name, "%s%s", qualification, name ); - - normalized_name = normalizeTemplatedClassName(fully_qualified_name); - if( !strncmp(Char(normalized_name),"enum ",5) ) { - Insert(normalized_name,5,qualification); - } - - return normalized_name; - } - - /* Benedikt Grundmann inspired --> Enum wrap styles */ - - int enumvalueDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *qvalue = 0; - - if( name_qualifier ) { - qvalue = Copy(name_qualifier); - Printv( qvalue, name, NIL ); - } - - if( const_enum && name && !Getattr(seen_enumvalues,name) ) { - Setattr(seen_enumvalues,name,"true"); - SetFlag(n,"feature:immutable"); - Setattr(n,"feature:enumvalue","1"); // this does not appear to be used - - if( qvalue ) - Setattr(n,"qualified:value",qvalue); - - String *evname = SwigType_manglestr(qvalue); - Insert( evname, 0, "SWIG_ENUM_" ); - - Setattr(n,"feature:enumvname",name); - Setattr(n,"feature:symname",evname); - Delete( evname ); - Printf( f_enumtypes_value, "| `%s\n", name ); - - return Language::enumvalueDeclaration(n); - } else return SWIG_OK; - } - - /* ------------------------------------------------------------------- - * This function is a bit uglier than it deserves. - * - * I used to direct lookup the name of the enum. Now that certain fixes - * have been made in other places, the names of enums are now fully - * qualified, which is a good thing, overall, but requires me to do - * some legwork. - * - * The other thing that uglifies this function is the varying way that - * typedef enum and enum are handled. I need to produce consistent names, - * which means looking up and registering by typedef and enum name. */ - int enumDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *oname = name ? NewString(name) : NULL; - /* name is now fully qualified */ - String *fully_qualified_name = NewString(name); - bool seen_enum = false; - if( name_qualifier ) - Delete(name_qualifier); - char *strip_position; - name_qualifier = fully_qualify_enum_name(n,NewString("")); - - /* Recent changes have distrubed enum and template naming again. - * Will try to keep it consistent by can't guarantee much given - * that these things move around a lot. - * - * I need to figure out a way to isolate this module better. - */ - if( oname ) { - strip_position = strstr(Char(oname),"::"); - - while( strip_position ) { - strip_position += 2; - oname = NewString( strip_position ); - strip_position = strstr( Char(oname), "::" ); - } - } - - seen_enum = oname ? - (Getattr(seen_enums,fully_qualified_name) ? true : false) : false; - - if( oname && !seen_enum ) { - const_enum = true; - Printf( f_enum_to_int, "| `%s -> (match y with\n", oname ); - Printf( f_int_to_enum, "| `%s -> C_enum (\n", oname ); - /* * * * A note about enum name resolution * * * * - * This code should now work, but I think we can do a bit better. - * The problem I'm having is that swig isn't very precise about - * typedef name resolution. My opinion is that SwigType_typedef - * resolve_all should *always* return the enum tag if one exists, - * rather than the admittedly friendlier enclosing typedef. - * - * This would make one of the cases below unnecessary. - * * * */ - Printf( f_mlbody, - "let _ = Callback.register \"%s_marker\" (`%s)\n", - fully_qualified_name, oname ); - if( !strncmp(Char(fully_qualified_name),"enum ",5) ) { - String *fq_noenum = NewString(Char(fully_qualified_name) + 5); - Printf( f_mlbody, - "let _ = Callback.register \"%s_marker\" (`%s)\n" - "let _ = Callback.register \"%s_marker\" (`%s)\n", - fq_noenum, oname, - fq_noenum, name ); - } - - Printf( f_enumtypes_type,"| `%s\n", oname ); - Insert(fully_qualified_name,0,"enum "); - Setattr(seen_enums,fully_qualified_name,n); - } - - int ret = Language::enumDeclaration(n); - - if( const_enum ) { - Printf( f_int_to_enum, "`Int y)\n" ); - Printf( f_enum_to_int, - "| `Int x -> Swig.C_int x\n" - "| _ -> raise (LabelNotFromThisEnum v))\n" ); - } - - const_enum = false; - - return ret; - } - - /* ---------------------------------------------------------------------------- - * BEGIN C++ Director Class modifications - * ------------------------------------------------------------------------- */ - - /* - * Modified polymorphism code for Ocaml language module. - * Original: - * C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose - * - * - * TODO - * - * Move some boilerplate code generation to Swig_...() functions. - * - */ - - /* --------------------------------------------------------------- - * classDirectorMethod() - * - * Emit a virtual director method to pass a method call on to the - * underlying Python object. - * - * --------------------------------------------------------------- */ - - int classDirectorMethod(Node *n, Node *parent, String *super) { - int is_void = 0; - int is_pointer = 0; - String *storage; - String *value; - String *decl; - String *type; - String *name; - String *classname; - String *c_classname = Getattr(parent, "name"); - String *declaration; - ParmList *l; - Wrapper *w; - String *tm; - String *wrap_args = NewString(""); - String *return_type; - int status = SWIG_OK; - int idx; - bool pure_virtual = false; - bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - - storage = Getattr(n, "storage"); - value = Getattr(n, "value"); - classname = Getattr(parent, "sym:name"); - type = Getattr(n, "type"); - name = Getattr(n, "name"); - - if (Cmp(storage,"virtual") == 0) { - if (Cmp(value,"0") == 0) { - pure_virtual = true; - } - } - - w = NewWrapper(); - declaration = NewString(""); - Wrapper_add_local(w,"swig_result", - "CAMLparam0();\n" - "SWIG_CAMLlocal2(swig_result,args)"); - - /* determine if the method returns a pointer */ - decl = Getattr(n, "decl"); - is_pointer = SwigType_ispointer_return(decl); - is_void = (!Cmp(type, "void") && !is_pointer); - - /* form complete return type */ - return_type = Copy(type); - { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); - } - - /* virtual method definition */ - l = Getattr(n, "parms"); - String *target; - String *pclassname = NewStringf("SwigDirector_%s", classname); - String *qualified_name = NewStringf("%s::%s", pclassname, name); - target = Swig_method_decl(decl, qualified_name, l, 0, 0); - String *rtype = SwigType_str(type, 0); - if (Getattr(n, "conversion_operator")) - Printf(w->def, "%s {", target); - else - Printf(w->def, "%s %s {", rtype, target); - Delete(qualified_name); - Delete(target); - /* header declaration */ - target = Swig_method_decl(decl, name, l, 0, 1); - if (Getattr(n, "conversion_operator")) - Printf(declaration, " virtual %s;", target); - else - Printf(declaration, " virtual %s %s;\n", rtype, target); - Delete(target); - - /* declare method return value - * if the return value is a reference or const reference, a specialized typemap must - * handle it, including declaration of c_result ($result). - */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL); - } - } - - if (ignored_method) { - if (!pure_virtual) { - if (!is_void) - Printf(w->code, "return "); - String *super_call = Swig_method_call(super, l); - Printf(w->code, "%s;\n", super_call); - Delete(super_call); - } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name)); - } - } else { - /* attach typemaps to arguments (C/C++ -> Ocaml) */ - String *arglist = NewString(""); - - Swig_typemap_attach_parms("in", l, 0); - Swig_typemap_attach_parms("directorin", l, 0); - Swig_typemap_attach_parms("directorargout", l, w); - - Parm* p; - int num_arguments = emit_num_arguments(l); - int i; - char source[256]; - - int outputs = 0; - if (!is_void) outputs++; - - /* build argument list and type conversion string */ - for (i=0, idx=0, p = l; i < num_arguments; i++) { - - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - - if (Getattr(p, "tmap:directorargout") != 0) outputs++; - - String* pname = Getattr(p, "name"); - String* ptype = Getattr(p, "type"); - - Putc(',',arglist); - if ((tm = Getattr(p, "tmap:directorin")) != 0) { - Replaceall(tm, "$input", pname); - Replaceall(tm, "$owner", "0"); - if (Len(tm) == 0) Append(tm, pname); - Printv(wrap_args, tm, "\n", NIL); - p = Getattr(p, "tmap:directorin:next"); - continue; - } else - if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype)+2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname,0,"&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); - } else { - nonconst = Copy(ppname); - } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL); - Printf(wrap_args, "%s = dynamic_cast(%s);\n", director, nonconst); - Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - Printf(wrap_args, "} else {\n"); - Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); - Printf(wrap_args, "}\n"); - Delete(director); - Printv(arglist, source, NIL); - } else { - Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", - source, nonconst, mangle); - //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); - } - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; - } - } - p = nextSibling(p); - } - - Printv(w->code, "swig_result = Val_unit;\n",0); - Printf(w->code,"args = Val_unit;\n"); - - /* wrap complex arguments to values */ - Printv(w->code, wrap_args, NIL); - - /* pass the method call on to the Python object */ - Printv(w->code, - "swig_result = caml_swig_alloc(1,C_list);\n" - "SWIG_Store_field(swig_result,0,args);\n" - "args = swig_result;\n" - "swig_result = Val_unit;\n",0); - Printf(w->code, - "swig_result = " - "callback3(*caml_named_value(\"swig_runmethod\")," - "swig_get_self(),copy_string(\"%s\"),args);\n", - Getattr(n,"name")); - /* exception handling */ - tm = Swig_typemap_lookup_new("director:except", n, "result", 0); - if (!tm) { - tm = Getattr(n, "feature:director:except"); - } - if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { - Printf(w->code, "if (result == NULL) {\n"); - Printf(w->code, " CAML_VALUE error = *caml_named_value(\"director_except\");\n"); - Replaceall(tm, "$error", "error"); - Printv(w->code, Str(tm), "\n", NIL); - Printf(w->code, "}\n"); - } - - /* - * Python method may return a simple object, or a tuple. - * for in/out aruments, we have to extract the appropriate values from the - * argument list, then marshal everything back to C/C++ (return value and - * output arguments). - */ - - /* marshal return value and other outputs (if any) from value to C/C++ - * type */ - - String* cleanup = NewString(""); - String* outarg = NewString(""); - - idx = 0; - - /* this seems really silly. the node's type excludes - * qualifier/pointer/reference markers, which have to be retrieved - * from the decl field to construct return_type. but the typemap - * lookup routine uses the node's type, so we have to swap in and - * out the correct type. it's not just me, similar silliness also - * occurs in Language::cDeclaration(). - */ - Setattr(n, "type", return_type); - tm = Swig_typemap_lookup_new("directorout", n, "c_result", w); - Setattr(n, "type", type); - if (tm == 0) { - String *name = NewString("c_result"); - tm = Swig_typemap_search("directorout", return_type, name, NULL); - Delete(name); - } - if (tm != 0) { - Replaceall(tm, "$input", "swig_result"); - /* TODO check this */ - if (Getattr(n,"wrap:disown")) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); - } else { - Replaceall(tm,"$disown","0"); - } - Replaceall(tm, "$result", "c_result"); - Printv(w->code, tm, "\n", NIL); - } - - /* marshal outputs */ - for (p = l; p; ) { - if ((tm = Getattr(p, "tmap:directorargout")) != 0) { - Replaceall(tm, "$input", "swig_result"); - Replaceall(tm, "$result", Getattr(p, "name")); - Printv(w->code, tm, "\n", NIL); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } - - Delete(arglist); - Delete(cleanup); - Delete(outarg); - } - - /* any existing helper functions to handle this? */ - if (!is_void) { - if (!(ignored_method && !pure_virtual)) { - /* A little explanation: - * The director_enum test case makes a method whose return type - * is an enum type. return_type here is "int". gcc complains - * about an implicit enum conversion, and although i don't strictly - * agree with it, I'm working on fixing the error: - * - * Below is what I came up with. It's not great but it should - * always essentially work. - */ - if( !SwigType_isreference(return_type) ) { - Printf(w->code, "CAMLreturn((%s)c_result);\n", - SwigType_lstr(return_type, "")); - } else { - Printf(w->code, "CAMLreturn(*c_result);\n"); - } - } - } - - Printf(w->code, "}\n"); - - // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method - String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) - { - Printv(inline_extra_method, declaration, NIL); - String *extra_method_name = NewStringf("%sSwigPublic", name); - Replaceall(inline_extra_method, name, extra_method_name); - Replaceall(inline_extra_method, ";\n", " {\n "); - if (!is_void) - Printf(inline_extra_method, "return "); - String *methodcall = Swig_method_call(super, l); - Printv(inline_extra_method, methodcall, ";\n }\n", NIL); - Delete(methodcall); - Delete(extra_method_name); - } - - /* emit the director method */ - if (status == SWIG_OK) { - if (!Getattr(n,"defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); - Printv(f_directors_h, inline_extra_method, NIL); - } - } - - /* clean up */ - Delete(wrap_args); - Delete(rtype); - Delete(return_type); - Delete(pclassname); - DelWrapper(w); - return status; - } - - /* ------------------------------------------------------------ - * classDirectorConstructor() - * ------------------------------------------------------------ */ - - int classDirectorConstructor(Node *n) { - Node *parent = Getattr(n, "parentNode"); - String *sub = NewString(""); - String *decl = Getattr(n, "decl"); - String *supername = Swig_class_name(parent); - String *classname = NewString(""); - Printf(classname, "SwigDirector_%s", supername); - - /* insert self parameter */ - Parm *p, *q; - ParmList *superparms = Getattr(n, "parms"); - ParmList *parms = CopyParmList(superparms); - String *type = NewString("CAML_VALUE"); - p = NewParm(type, NewString("self")); - q = Copy(p); - set_nextSibling(q, superparms); - set_nextSibling(p, parms); - parms = p; - - if (!Getattr(n,"defaultargs")) { - /* constructor */ - { - Wrapper *w = NewWrapper(); - String *call; - String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); - call = Swig_csuperclass_call(0, basetype, superparms); - Printf( w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call ); - Delete(target); - Wrapper_print(w, f_directors); - Delete(call); - DelWrapper(w); - } - - /* constructor header */ - { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); - Printf(f_directors_h, " %s;\n", target); - Delete(target); - } - } - - Setattr(n,"parms",q); - Language::classDirectorConstructor(n); - - Delete(sub); - Delete(classname); - Delete(supername); - //Delete(parms); - - return SWIG_OK; - } - - /* ------------------------------------------------------------ - * classDirectorDefaultConstructor() - * ------------------------------------------------------------ */ - - int classDirectorDefaultConstructor(Node *n) { - String *classname; - classname = Swig_class_name(n); - - /* insert self parameter */ - Parm *p, *q; - ParmList *superparms = Getattr(n, "parms"); - ParmList *parms = CopyParmList(superparms); - String *type = NewString("CAML_VALUE"); - p = NewParm(type, NewString("self")); - q = Copy(p); - set_nextSibling(p, parms); - parms = p; - - { - Wrapper *w = NewWrapper(); - Printf(w->def, "SwigDirector_%s::SwigDirector_%s(CAML_VALUE self) : Swig::Director(self) { }", classname, classname); - Wrapper_print(w, f_directors); - DelWrapper(w); - } - Printf(f_directors_h, " SwigDirector_%s(CAML_VALUE self);\n", classname); - Delete(classname); - Setattr(n,"parms",q); - return Language::classDirectorDefaultConstructor(n); - } - - int classDirectorInit( Node *n ) { - String *declaration = Swig_director_declaration(n); - Printf( f_directors_h, - "\n" - "%s\n" - "public:\n", declaration ); - Delete( declaration ); - return Language::classDirectorInit( n ); - } - - int classDirectorEnd( Node *n ) { - Printf( f_directors_h, "};\n\n" ); - return Language::classDirectorEnd( n ); - } - - /* --------------------------------------------------------------------- - * typedefHandler - * - * This is here in order to maintain the correct association between - * typedef names and enum names. - * - * Since I implement enums as polymorphic variant tags, I need to call - * back into ocaml to evaluate them. This requires a string that can - * be generated in the typemaps, and also at SWIG time to be the same - * string. The problem that arises is that SWIG variously generates - * enum e_name_tag - * e_name_tag - * e_typedef_name - * for - * typedef enum e_name_tag { ... } e_typedef_name; - * - * Since I need these strings to be consistent, I must maintain a correct - * association list between typedef and enum names. - * --------------------------------------------------------------------- */ - int typedefHandler( Node *n ) { - String *type = Getattr(n,"type"); - Node *enum_node = type ? - Getattr(seen_enums,type) : 0; - if( enum_node ) { - String *name = Getattr(enum_node,"name"); - - Printf( f_mlbody, - "let _ = Callback.register \"%s_marker\" (`%s)\n", - Getattr(n,"name"), name ); - - } - return SWIG_OK; - } - - String *runtimeCode() { - String *s = Swig_include_sys("ocaml.swg"); - if (!s) { - Printf(stderr, "*** Unable to open 'ocaml.swg'\n"); - s = NewString(""); } - return s; + } + } + + bool isSimpleType(String *name) { + char *ch = Char(name); + + return !(strchr(ch, '(') || strchr(ch, '<') || strchr(ch, ')') || strchr(ch, '>')); + } + + /* We accept all chars in identifiers because we use strings to index + * them. */ + int validIdentifier(String *name) { + return Len(name) > 0 ? 1 : 0; + } + + /* classHandler + * + * Create a "class" definition for ocaml. I thought quite a bit about + * how I should do this part of it, and arrived here, using a function + * invocation to select a method, and dispatch. This can obviously be + * done better, but I can't see how, given that I want to support + * overloaded methods, out parameters, and operators. + * + * I needed a system that would do this: + * + * a Be able to call these methods: + * int foo( int x ); + * float foo( int x, int &out ); + * + * b Be typeable, even in the presence of mutually dependent classes. + * + * c Support some form of operator invocation. + * + * (c) I chose strings for the method names so that "+=" would be a + * valid method name, and the somewhat natural << (invoke x) "+=" y >> + * would work. + * + * (a) (b) Since the c_obj type exists, it's easy to return C_int in one + * case and C_list [ C_float ; C_int ] in the other. This makes tricky + * problems with out parameters disappear; they're simply appended to the + * return list. + * + * (b) Since every item that comes from C++ is the same type, there is no + * problem with the following: + * + * class Foo; + * class Bar { Foo *toFoo(); } + * class Foo { Bar *toBar(); } + * + * Since the Objective caml types of Foo and Bar are the same. Now that + * I correctly incorporate SWIG's typechecking, this isn't a big deal. + * + * The class is in the form of a function returning a c_obj. The c_obj + * is a C_obj containing a function which invokes a method on the + * underlying object given its type. + * + * The name emitted here is normalized before being sent to + * Callback.register, because we need this string to look up properly + * when the typemap passes the descriptor string. I've been considering + * some, possibly more forgiving method that would do some transformations + * on the $descriptor in order to find a potential match. This is for + * later. + * + * Important things to note: + * + * We rely on exception handling (BadMethodName) in order to call an + * ancestor. This can be improved. + * + * The method used to get :classof could be improved to look at the type + * info that the base pointer contains. It's really an error to have a + * SWIG-generated object that does not contain type info, since the + * existence of the object means that SWIG knows the type. + * + * :parents could use :classof to tell what class it is and make a better + * decision. This could be nice, (i.e. provide a run-time graph of C++ + * classes represented);. + * + * I can't think of a more elegant way of converting a C_obj fun to a + * pointer than "operator &"... + * + * Added a 'sizeof' that will allow you to do the expected thing. + * This should help users to fill buffer structs and the like (as is + * typical in windows-styled code). It's only enabled if you give + * %feature(sizeof) and then, only for simple types. + * + * Overall, carrying the list of methods and base classes has worked well. + * It allows me to give the Ocaml user introspection over their objects. + */ + + int classHandler(Node *n) { + String *name = Getattr(n, "name"); + String *mangled_sym_name = mangleNameForCaml(name); + String *this_class_def = NewString(f_classtemplate); + String *name_normalized = normalizeTemplatedClassName(name); + String *old_class_ctors = f_class_ctors; + String *base_classes = NewString(""); + f_class_ctors = NewString(""); + bool sizeof_feature = generate_sizeof && isSimpleType(name); + + if (!name) + return SWIG_OK; + + classname = mangled_sym_name; + classmode = true; + int rv = Language::classHandler(n); + classmode = false; + + if (sizeof_feature) { + Printf(f_wrappers, + "SWIGEXT CAML_VALUE _wrap_%s_sizeof( CAML_VALUE args ) {\n" + " CAMLparam1(args);\n" " CAMLreturn(Val_int(sizeof(%s)));\n" "}\n", mangled_sym_name, name_normalized); + + Printf(f_mlbody, "external __%s_sizeof : unit -> int = " "\"_wrap_%s_sizeof\"\n", classname, mangled_sym_name); } - String *defaultExternalRuntimeFilename() { - return NewString("swigocamlrun.h"); + + /* Insert sizeof operator for concrete classes */ + if (sizeof_feature) { + Printv(f_class_ctors, "\"sizeof\" , (fun args -> C_int (__", classname, "_sizeof ())) ;\n", NIL); } + /* Handle up-casts in a nice way */ + List *baselist = Getattr(n, "bases"); + if (baselist && Len(baselist)) { + Iterator b; + b = First(baselist); + while (b.item) { + String *bname = Getattr(b.item, "name"); + if (bname) { + String *base_create = NewString(""); + Printv(base_create, "(create_class \"", bname, "\")", NIL); + Printv(f_class_ctors, " \"::", bname, "\", (fun args -> ", base_create, " args) ;\n", NIL); + Printv(base_classes, base_create, " ;\n", NIL); + } + b = Next(b); + } + } + + Replaceall(this_class_def, "$classname", classname); + Replaceall(this_class_def, "$normalized", name_normalized); + Replaceall(this_class_def, "$realname", name); + Replaceall(this_class_def, "$baselist", base_classes); + Replaceall(this_class_def, "$classbody", f_class_ctors); + + Delete(f_class_ctors); + f_class_ctors = old_class_ctors; + + // Actually write out the class definition + + Multiwrite(this_class_def); + + Setattr(n, "ocaml:ctor", classname); + + return rv; + } + + String *normalizeTemplatedClassName(String *name) { + String *name_normalized = SwigType_typedef_resolve_all(name); + bool took_action; + + do { + took_action = false; + + if (is_a_pointer(name_normalized)) { + SwigType_del_pointer(name_normalized); + took_action = true; + } + + if (is_a_reference(name_normalized)) { + oc_SwigType_del_reference(name_normalized); + took_action = true; + } + + if (is_an_array(name_normalized)) { + oc_SwigType_del_array(name_normalized); + took_action = true; + } + } while (took_action); + + return SwigType_str(name_normalized, 0); + } + + /* + * Produce the symbol name that ocaml will use when referring to the + * target item. I wonder if there's a better way to do this: + * + * I shudder to think about doing it with a hash lookup, but that would + * make a couple of things easier: + */ + + String *mangleNameForCaml(String *s) { + String *out = Copy(s); + Replaceall(out, " ", "_xx"); + Replaceall(out, "::", "_xx"); + Replaceall(out, ",", "_x"); + Replaceall(out, "+", "_xx_plus"); + Replaceall(out, "-", "_xx_minus"); + Replaceall(out, "<", "_xx_ldbrace"); + Replaceall(out, ">", "_xx_rdbrace"); + Replaceall(out, "!", "_xx_not"); + Replaceall(out, "%", "_xx_mod"); + Replaceall(out, "^", "_xx_xor"); + Replaceall(out, "*", "_xx_star"); + Replaceall(out, "&", "_xx_amp"); + Replaceall(out, "|", "_xx_or"); + Replaceall(out, "(", "_xx_lparen"); + Replaceall(out, ")", "_xx_rparen"); + Replaceall(out, "[", "_xx_lbrace"); + Replaceall(out, "]", "_xx_rbrace"); + Replaceall(out, "~", "_xx_bnot"); + Replaceall(out, "=", "_xx_equals"); + Replaceall(out, "/", "_xx_slash"); + Replaceall(out, ".", "_xx_dot"); + return out; + } + + String *fully_qualify_enum_name(Node *n, String *name) { + Node *parent = 0; + String *qualification = NewString(""); + String *fully_qualified_name = NewString(""); + String *parent_type = 0; + String *normalized_name; + + parent = parentNode(n); + while (parent) { + parent_type = nodeType(parent); + if (Getattr(parent, "name")) { + String *parent_copy = NewStringf("%s::", Getattr(parent, "name")); + if (!Cmp(parent_type, "class") || !Cmp(parent_type, "namespace")) + Insert(qualification, 0, parent_copy); + Delete(parent_copy); + } + if (!Cmp(parent_type, "class")) + break; + parent = parentNode(parent); + } + + Printf(fully_qualified_name, "%s%s", qualification, name); + + normalized_name = normalizeTemplatedClassName(fully_qualified_name); + if (!strncmp(Char(normalized_name), "enum ", 5)) { + Insert(normalized_name, 5, qualification); + } + + return normalized_name; + } + + /* Benedikt Grundmann inspired --> Enum wrap styles */ + + int enumvalueDeclaration(Node *n) { + String *name = Getattr(n, "name"); + String *qvalue = 0; + + if (name_qualifier) { + qvalue = Copy(name_qualifier); + Printv(qvalue, name, NIL); + } + + if (const_enum && name && !Getattr(seen_enumvalues, name)) { + Setattr(seen_enumvalues, name, "true"); + SetFlag(n, "feature:immutable"); + Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used + + if (qvalue) + Setattr(n, "qualified:value", qvalue); + + String *evname = SwigType_manglestr(qvalue); + Insert(evname, 0, "SWIG_ENUM_"); + + Setattr(n, "feature:enumvname", name); + Setattr(n, "feature:symname", evname); + Delete(evname); + Printf(f_enumtypes_value, "| `%s\n", name); + + return Language::enumvalueDeclaration(n); + } else + return SWIG_OK; + } + + /* ------------------------------------------------------------------- + * This function is a bit uglier than it deserves. + * + * I used to direct lookup the name of the enum. Now that certain fixes + * have been made in other places, the names of enums are now fully + * qualified, which is a good thing, overall, but requires me to do + * some legwork. + * + * The other thing that uglifies this function is the varying way that + * typedef enum and enum are handled. I need to produce consistent names, + * which means looking up and registering by typedef and enum name. */ + int enumDeclaration(Node *n) { + String *name = Getattr(n, "name"); + String *oname = name ? NewString(name) : NULL; + /* name is now fully qualified */ + String *fully_qualified_name = NewString(name); + bool seen_enum = false; + if (name_qualifier) + Delete(name_qualifier); + char *strip_position; + name_qualifier = fully_qualify_enum_name(n, NewString("")); + + /* Recent changes have distrubed enum and template naming again. + * Will try to keep it consistent by can't guarantee much given + * that these things move around a lot. + * + * I need to figure out a way to isolate this module better. + */ + if (oname) { + strip_position = strstr(Char(oname), "::"); + + while (strip_position) { + strip_position += 2; + oname = NewString(strip_position); + strip_position = strstr(Char(oname), "::"); + } + } + + seen_enum = oname ? (Getattr(seen_enums, fully_qualified_name) ? true : false) : false; + + if (oname && !seen_enum) { + const_enum = true; + Printf(f_enum_to_int, "| `%s -> (match y with\n", oname); + Printf(f_int_to_enum, "| `%s -> C_enum (\n", oname); + /* * * * A note about enum name resolution * * * * + * This code should now work, but I think we can do a bit better. + * The problem I'm having is that swig isn't very precise about + * typedef name resolution. My opinion is that SwigType_typedef + * resolve_all should *always* return the enum tag if one exists, + * rather than the admittedly friendlier enclosing typedef. + * + * This would make one of the cases below unnecessary. + * * * */ + Printf(f_mlbody, "let _ = Callback.register \"%s_marker\" (`%s)\n", fully_qualified_name, oname); + if (!strncmp(Char(fully_qualified_name), "enum ", 5)) { + String *fq_noenum = NewString(Char(fully_qualified_name) + 5); + Printf(f_mlbody, + "let _ = Callback.register \"%s_marker\" (`%s)\n" "let _ = Callback.register \"%s_marker\" (`%s)\n", fq_noenum, oname, fq_noenum, name); + } + + Printf(f_enumtypes_type, "| `%s\n", oname); + Insert(fully_qualified_name, 0, "enum "); + Setattr(seen_enums, fully_qualified_name, n); + } + + int ret = Language::enumDeclaration(n); + + if (const_enum) { + Printf(f_int_to_enum, "`Int y)\n"); + Printf(f_enum_to_int, "| `Int x -> Swig.C_int x\n" "| _ -> raise (LabelNotFromThisEnum v))\n"); + } + + const_enum = false; + + return ret; + } + + /* ---------------------------------------------------------------------------- + * BEGIN C++ Director Class modifications + * ------------------------------------------------------------------------- */ + + /* + * Modified polymorphism code for Ocaml language module. + * Original: + * C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose + * + * + * TODO + * + * Move some boilerplate code generation to Swig_...() functions. + * + */ + + /* --------------------------------------------------------------- + * classDirectorMethod() + * + * Emit a virtual director method to pass a method call on to the + * underlying Python object. + * + * --------------------------------------------------------------- */ + + int classDirectorMethod(Node *n, Node *parent, String *super) { + int is_void = 0; + int is_pointer = 0; + String *storage; + String *value; + String *decl; + String *type; + String *name; + String *classname; + String *c_classname = Getattr(parent, "name"); + String *declaration; + ParmList *l; + Wrapper *w; + String *tm; + String *wrap_args = NewString(""); + String *return_type; + int status = SWIG_OK; + int idx; + bool pure_virtual = false; + bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; + + storage = Getattr(n, "storage"); + value = Getattr(n, "value"); + classname = Getattr(parent, "sym:name"); + type = Getattr(n, "type"); + name = Getattr(n, "name"); + + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; + } + } + + w = NewWrapper(); + declaration = NewString(""); + Wrapper_add_local(w, "swig_result", "CAMLparam0();\n" "SWIG_CAMLlocal2(swig_result,args)"); + + /* determine if the method returns a pointer */ + decl = Getattr(n, "decl"); + is_pointer = SwigType_ispointer_return(decl); + is_void = (!Cmp(type, "void") && !is_pointer); + + /* form complete return type */ + return_type = Copy(type); + { + SwigType *t = Copy(decl); + SwigType *f = 0; + f = SwigType_pop_function(t); + SwigType_push(return_type, t); + Delete(f); + Delete(t); + } + + /* virtual method definition */ + l = Getattr(n, "parms"); + String *target; + String *pclassname = NewStringf("SwigDirector_%s", classname); + String *qualified_name = NewStringf("%s::%s", pclassname, name); + target = Swig_method_decl(decl, qualified_name, l, 0, 0); + String *rtype = SwigType_str(type, 0); + if (Getattr(n, "conversion_operator")) + Printf(w->def, "%s {", target); + else + Printf(w->def, "%s %s {", rtype, target); + Delete(qualified_name); + Delete(target); + /* header declaration */ + target = Swig_method_decl(decl, name, l, 0, 1); + if (Getattr(n, "conversion_operator")) + Printf(declaration, " virtual %s;", target); + else + Printf(declaration, " virtual %s %s;\n", rtype, target); + Delete(target); + + /* declare method return value + * if the return value is a reference or const reference, a specialized typemap must + * handle it, including declaration of c_result ($result). + */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + Wrapper_add_localv(w, "c_result", SwigType_lstr(return_type, "c_result"), NIL); + } + } + + if (ignored_method) { + if (!pure_virtual) { + if (!is_void) + Printf(w->code, "return "); + String *super_call = Swig_method_call(super, l); + Printf(w->code, "%s;\n", super_call); + Delete(super_call); + } else { + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); + } + } else { + /* attach typemaps to arguments (C/C++ -> Ocaml) */ + String *arglist = NewString(""); + + Swig_typemap_attach_parms("in", l, 0); + Swig_typemap_attach_parms("directorin", l, 0); + Swig_typemap_attach_parms("directorargout", l, w); + + Parm *p; + int num_arguments = emit_num_arguments(l); + int i; + char source[256]; + + int outputs = 0; + if (!is_void) + outputs++; + + /* build argument list and type conversion string */ + for (i = 0, idx = 0, p = l; i < num_arguments; i++) { + + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); + + Putc(',', arglist); + if ((tm = Getattr(p, "tmap:directorin")) != 0) { + Replaceall(tm, "$input", pname); + Replaceall(tm, "$owner", "0"); + if (Len(tm) == 0) + Append(tm, pname); + Printv(wrap_args, tm, "\n", NIL); + p = Getattr(p, "tmap:directorin:next"); + continue; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); + } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(ptype, pname), + SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL); + Printf(wrap_args, "%s = dynamic_cast(%s);\n", director, nonconst); + Printf(wrap_args, "if (!%s) {\n", director); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(wrap_args, "} else {\n"); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "}\n"); + Delete(director); + Printv(arglist, source, NIL); + } else { + Wrapper_add_localv(w, source, "CAML_VALUE", source, "= Val_unit", NIL); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); + } + Delete(mangle); + Delete(nonconst); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; + } + } + p = nextSibling(p); + } + + Printv(w->code, "swig_result = Val_unit;\n", 0); + Printf(w->code, "args = Val_unit;\n"); + + /* wrap complex arguments to values */ + Printv(w->code, wrap_args, NIL); + + /* pass the method call on to the Python object */ + Printv(w->code, + "swig_result = caml_swig_alloc(1,C_list);\n" "SWIG_Store_field(swig_result,0,args);\n" "args = swig_result;\n" "swig_result = Val_unit;\n", 0); + Printf(w->code, "swig_result = " "callback3(*caml_named_value(\"swig_runmethod\")," "swig_get_self(),copy_string(\"%s\"),args);\n", Getattr(n, "name")); + /* exception handling */ + tm = Swig_typemap_lookup_new("director:except", n, "result", 0); + if (!tm) { + tm = Getattr(n, "feature:director:except"); + } + if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { + Printf(w->code, "if (result == NULL) {\n"); + Printf(w->code, " CAML_VALUE error = *caml_named_value(\"director_except\");\n"); + Replaceall(tm, "$error", "error"); + Printv(w->code, Str(tm), "\n", NIL); + Printf(w->code, "}\n"); + } + + /* + * Python method may return a simple object, or a tuple. + * for in/out aruments, we have to extract the appropriate values from the + * argument list, then marshal everything back to C/C++ (return value and + * output arguments). + */ + + /* marshal return value and other outputs (if any) from value to C/C++ + * type */ + + String *cleanup = NewString(""); + String *outarg = NewString(""); + + idx = 0; + + /* this seems really silly. the node's type excludes + * qualifier/pointer/reference markers, which have to be retrieved + * from the decl field to construct return_type. but the typemap + * lookup routine uses the node's type, so we have to swap in and + * out the correct type. it's not just me, similar silliness also + * occurs in Language::cDeclaration(). + */ + Setattr(n, "type", return_type); + tm = Swig_typemap_lookup_new("directorout", n, "c_result", w); + Setattr(n, "type", type); + if (tm == 0) { + String *name = NewString("c_result"); + tm = Swig_typemap_search("directorout", return_type, name, NULL); + Delete(name); + } + if (tm != 0) { + Replaceall(tm, "$input", "swig_result"); + /* TODO check this */ + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); + } + Replaceall(tm, "$result", "c_result"); + Printv(w->code, tm, "\n", NIL); + } + + /* marshal outputs */ + for (p = l; p;) { + if ((tm = Getattr(p, "tmap:directorargout")) != 0) { + Replaceall(tm, "$input", "swig_result"); + Replaceall(tm, "$result", Getattr(p, "name")); + Printv(w->code, tm, "\n", NIL); + p = Getattr(p, "tmap:directorargout:next"); + } else { + p = nextSibling(p); + } + } + + Delete(arglist); + Delete(cleanup); + Delete(outarg); + } + + /* any existing helper functions to handle this? */ + if (!is_void) { + if (!(ignored_method && !pure_virtual)) { + /* A little explanation: + * The director_enum test case makes a method whose return type + * is an enum type. return_type here is "int". gcc complains + * about an implicit enum conversion, and although i don't strictly + * agree with it, I'm working on fixing the error: + * + * Below is what I came up with. It's not great but it should + * always essentially work. + */ + if (!SwigType_isreference(return_type)) { + Printf(w->code, "CAMLreturn((%s)c_result);\n", SwigType_lstr(return_type, "")); + } else { + Printf(w->code, "CAMLreturn(*c_result);\n"); + } + } + } + + Printf(w->code, "}\n"); + + // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method + String *inline_extra_method = NewString(""); + if (dirprot_mode() && !is_public(n) && !pure_virtual) { + Printv(inline_extra_method, declaration, NIL); + String *extra_method_name = NewStringf("%sSwigPublic", name); + Replaceall(inline_extra_method, name, extra_method_name); + Replaceall(inline_extra_method, ";\n", " {\n "); + if (!is_void) + Printf(inline_extra_method, "return "); + String *methodcall = Swig_method_call(super, l); + Printv(inline_extra_method, methodcall, ";\n }\n", NIL); + Delete(methodcall); + Delete(extra_method_name); + } + + /* emit the director method */ + if (status == SWIG_OK) { + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); + Printv(f_directors_h, inline_extra_method, NIL); + } + } + + /* clean up */ + Delete(wrap_args); + Delete(rtype); + Delete(return_type); + Delete(pclassname); + DelWrapper(w); + return status; + } + + /* ------------------------------------------------------------ + * classDirectorConstructor() + * ------------------------------------------------------------ */ + + int classDirectorConstructor(Node *n) { + Node *parent = Getattr(n, "parentNode"); + String *sub = NewString(""); + String *decl = Getattr(n, "decl"); + String *supername = Swig_class_name(parent); + String *classname = NewString(""); + Printf(classname, "SwigDirector_%s", supername); + + /* insert self parameter */ + Parm *p, *q; + ParmList *superparms = Getattr(n, "parms"); + ParmList *parms = CopyParmList(superparms); + String *type = NewString("CAML_VALUE"); + p = NewParm(type, NewString("self")); + q = Copy(p); + set_nextSibling(q, superparms); + set_nextSibling(p, parms); + parms = p; + + if (!Getattr(n, "defaultargs")) { + /* constructor */ + { + Wrapper *w = NewWrapper(); + String *call; + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); + call = Swig_csuperclass_call(0, basetype, superparms); + Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call); + Delete(target); + Wrapper_print(w, f_directors); + Delete(call); + DelWrapper(w); + } + + /* constructor header */ + { + String *target = Swig_method_decl(decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); + } + } + + Setattr(n, "parms", q); + Language::classDirectorConstructor(n); + + Delete(sub); + Delete(classname); + Delete(supername); + //Delete(parms); + + return SWIG_OK; + } + + /* ------------------------------------------------------------ + * classDirectorDefaultConstructor() + * ------------------------------------------------------------ */ + + int classDirectorDefaultConstructor(Node *n) { + String *classname; + classname = Swig_class_name(n); + + /* insert self parameter */ + Parm *p, *q; + ParmList *superparms = Getattr(n, "parms"); + ParmList *parms = CopyParmList(superparms); + String *type = NewString("CAML_VALUE"); + p = NewParm(type, NewString("self")); + q = Copy(p); + set_nextSibling(p, parms); + parms = p; + + { + Wrapper *w = NewWrapper(); + Printf(w->def, "SwigDirector_%s::SwigDirector_%s(CAML_VALUE self) : Swig::Director(self) { }", classname, classname); + Wrapper_print(w, f_directors); + DelWrapper(w); + } + Printf(f_directors_h, " SwigDirector_%s(CAML_VALUE self);\n", classname); + Delete(classname); + Setattr(n, "parms", q); + return Language::classDirectorDefaultConstructor(n); + } + + int classDirectorInit(Node *n) { + String *declaration = Swig_director_declaration(n); + Printf(f_directors_h, "\n" "%s\n" "public:\n", declaration); + Delete(declaration); + return Language::classDirectorInit(n); + } + + int classDirectorEnd(Node *n) { + Printf(f_directors_h, "};\n\n"); + return Language::classDirectorEnd(n); + } + + /* --------------------------------------------------------------------- + * typedefHandler + * + * This is here in order to maintain the correct association between + * typedef names and enum names. + * + * Since I implement enums as polymorphic variant tags, I need to call + * back into ocaml to evaluate them. This requires a string that can + * be generated in the typemaps, and also at SWIG time to be the same + * string. The problem that arises is that SWIG variously generates + * enum e_name_tag + * e_name_tag + * e_typedef_name + * for + * typedef enum e_name_tag { ... } e_typedef_name; + * + * Since I need these strings to be consistent, I must maintain a correct + * association list between typedef and enum names. + * --------------------------------------------------------------------- */ + int typedefHandler(Node *n) { + String *type = Getattr(n, "type"); + Node *enum_node = type ? Getattr(seen_enums, type) : 0; + if (enum_node) { + String *name = Getattr(enum_node, "name"); + + Printf(f_mlbody, "let _ = Callback.register \"%s_marker\" (`%s)\n", Getattr(n, "name"), name); + + } + return SWIG_OK; + } + + String *runtimeCode() { + String *s = Swig_include_sys("ocaml.swg"); + if (!s) { + Printf(stderr, "*** Unable to open 'ocaml.swg'\n"); + s = NewString(""); + } + return s; + } + + String *defaultExternalRuntimeFilename() { + return NewString("swigocamlrun.h"); + } }; /* ------------------------------------------------------------------------- * swig_ocaml() - Instantiate module * ------------------------------------------------------------------------- */ -static Language * new_swig_ocaml() { - return new OCAML(); +static Language *new_swig_ocaml() { + return new OCAML(); } -extern "C" Language * swig_ocaml(void) { - return new_swig_ocaml(); +extern "C" Language *swig_ocaml(void) { + return new_swig_ocaml(); } - diff --git a/SWIG/Source/Modules/overload.cxx b/SWIG/Source/Modules/overload.cxx index ae83c1674..27e080d49 100644 --- a/SWIG/Source/Modules/overload.cxx +++ b/SWIG/Source/Modules/overload.cxx @@ -20,10 +20,10 @@ String *argv_template_string; String *argc_template_string; struct Overloaded { - Node *n; /* Node */ - int argc; /* Argument count */ - ParmList *parms; /* Parameters used for overload check */ - int error; /* Ambiguity error */ + Node *n; /* Node */ + int argc; /* Argument count */ + ParmList *parms; /* Parameters used for overload check */ + int error; /* Ambiguity error */ }; static int fast_dispatch_mode = 0; @@ -55,44 +55,44 @@ void Wrapper_cast_dispatch_mode_set(int flag) { * languages ignore the first method parsed. * ----------------------------------------------------------------------------- */ -static List * -Swig_overload_rank(Node *n, bool script_lang_wrapping) { - Overloaded nodes[MAX_OVERLOAD]; - int nnodes = 0; - Node *o = Getattr(n,"sym:overloaded"); +static List *Swig_overload_rank(Node *n, bool script_lang_wrapping) { + Overloaded nodes[MAX_OVERLOAD]; + int nnodes = 0; + Node *o = Getattr(n, "sym:overloaded"); Node *c; - if (!o) return 0; + if (!o) + return 0; c = o; while (c) { - if (Getattr(c,"error")) { - c = Getattr(c,"sym:nextSibling"); + if (Getattr(c, "error")) { + c = Getattr(c, "sym:nextSibling"); continue; } /* if (SmartPointer && Getattr(c,"cplus:staticbase")) { - c = Getattr(c,"sym:nextSibling"); - continue; - } */ + c = Getattr(c,"sym:nextSibling"); + continue; + } */ /* Make a list of all the declarations (methods) that are overloaded with * this one particular method name */ - if (Getattr(c,"wrap:name")) { + if (Getattr(c, "wrap:name")) { assert(nnodes < MAX_OVERLOAD); nodes[nnodes].n = c; - nodes[nnodes].parms = Getattr(c,"wrap:parms"); + nodes[nnodes].parms = Getattr(c, "wrap:parms"); nodes[nnodes].argc = emit_num_required(nodes[nnodes].parms); nodes[nnodes].error = 0; nnodes++; } - c = Getattr(c,"sym:nextSibling"); + c = Getattr(c, "sym:nextSibling"); } - + /* Sort the declarations by required argument count */ { - int i,j; + int i, j; for (i = 0; i < nnodes; i++) { - for (j = i+1; j < nnodes; j++) { + for (j = i + 1; j < nnodes; j++) { if (nodes[i].argc > nodes[j].argc) { Overloaded t = nodes[i]; nodes[i] = nodes[j]; @@ -104,103 +104,103 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { /* Sort the declarations by argument types */ { - int i,j; - for (i = 0; i < nnodes-1; i++) { - if (nodes[i].argc == nodes[i+1].argc) { - for (j = i+1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { + int i, j; + for (i = 0; i < nnodes - 1; i++) { + if (nodes[i].argc == nodes[i + 1].argc) { + for (j = i + 1; (j < nnodes) && (nodes[j].argc == nodes[i].argc); j++) { Parm *p1 = nodes[i].parms; Parm *p2 = nodes[j].parms; - int differ = 0; - int num_checked = 0; + int differ = 0; + int num_checked = 0; while (p1 && p2 && (num_checked < nodes[i].argc)) { - // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); - if (checkAttribute(p1,"tmap:in:numinputs","0")) { - p1 = Getattr(p1,"tmap:in:next"); + // Printf(stdout,"p1 = '%s', p2 = '%s'\n", Getattr(p1,"type"), Getattr(p2,"type")); + if (checkAttribute(p1, "tmap:in:numinputs", "0")) { + p1 = Getattr(p1, "tmap:in:next"); continue; } - if (checkAttribute(p2,"tmap:in:numinputs","0")) { - p2 = Getattr(p2,"tmap:in:next"); + if (checkAttribute(p2, "tmap:in:numinputs", "0")) { + p2 = Getattr(p2, "tmap:in:next"); continue; } - String *t1 = Getattr(p1,"tmap:typecheck:precedence"); - String *t2 = Getattr(p2,"tmap:typecheck:precedence"); + String *t1 = Getattr(p1, "tmap:typecheck:precedence"); + String *t2 = Getattr(p2, "tmap:typecheck:precedence"); if ((!t1) && (!nodes[i].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[i].n), Getline(nodes[i].n), - "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", - Getattr(nodes[i].n,"name"),ParmList_str_defaultargs(Getattr(nodes[i].n,"parms")), - SwigType_str(Getattr(p1,"type"),0)); + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[i].n, "name"), ParmList_str_defaultargs(Getattr(nodes[i].n, "parms")), SwigType_str(Getattr(p1, "type"), 0)); nodes[i].error = 1; } else if ((!t2) && (!nodes[j].error)) { Swig_warning(WARN_TYPEMAP_TYPECHECK, Getfile(nodes[j].n), Getline(nodes[j].n), - "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", - Getattr(nodes[j].n,"name"),ParmList_str_defaultargs(Getattr(nodes[j].n,"parms")), - SwigType_str(Getattr(p2,"type"),0)); + "Overloaded %s(%s) not supported (no type checking rule for '%s').\n", + Getattr(nodes[j].n, "name"), ParmList_str_defaultargs(Getattr(nodes[j].n, "parms")), SwigType_str(Getattr(p2, "type"), 0)); nodes[j].error = 1; } if (t1 && t2) { int t1v, t2v; t1v = atoi(Char(t1)); t2v = atoi(Char(t2)); - differ = t1v-t2v; - } - else if (!t1 && t2) differ = 1; - else if (t2 && !t1) differ = -1; - else if (!t1 && !t2) differ = -1; + differ = t1v - t2v; + } else if (!t1 && t2) + differ = 1; + else if (t2 && !t1) + differ = -1; + else if (!t1 && !t2) + differ = -1; num_checked++; if (differ > 0) { Overloaded t = nodes[i]; nodes[i] = nodes[j]; nodes[j] = t; break; - } else if ((differ == 0) && (Strcmp(t1,"0") == 0)) { - t1 = Getattr(p1,"ltype"); + } else if ((differ == 0) && (Strcmp(t1, "0") == 0)) { + t1 = Getattr(p1, "ltype"); if (!t1) { - t1 = SwigType_ltype(Getattr(p1,"type")); - if (Getattr(p1,"tmap:typecheck:SWIGTYPE")) { + t1 = SwigType_ltype(Getattr(p1, "type")); + if (Getattr(p1, "tmap:typecheck:SWIGTYPE")) { SwigType_add_pointer(t1); } - Setattr(p1,"ltype",t1); + Setattr(p1, "ltype", t1); } - t2 = Getattr(p2,"ltype"); + t2 = Getattr(p2, "ltype"); if (!t2) { - t2 = SwigType_ltype(Getattr(p2,"type")); - if (Getattr(p2,"tmap:typecheck:SWIGTYPE")) { + t2 = SwigType_ltype(Getattr(p2, "type")); + if (Getattr(p2, "tmap:typecheck:SWIGTYPE")) { SwigType_add_pointer(t2); } - Setattr(p2,"ltype",t2); + Setattr(p2, "ltype", t2); } /* Need subtype check here. If t2 is a subtype of t1, then we need to change the - order */ + order */ - if (SwigType_issubtype(t2,t1)) { + if (SwigType_issubtype(t2, t1)) { Overloaded t = nodes[i]; nodes[i] = nodes[j]; nodes[j] = t; } - if (Strcmp(t1,t2) != 0) { + if (Strcmp(t1, t2) != 0) { differ = 1; break; } } else if (differ) { break; } - if (Getattr(p1,"tmap:in:next")) { - p1 = Getattr(p1,"tmap:in:next"); + if (Getattr(p1, "tmap:in:next")) { + p1 = Getattr(p1, "tmap:in:next"); } else { p1 = nextSibling(p1); } - if (Getattr(p2,"tmap:in:next")) { - p2 = Getattr(p2,"tmap:in:next"); + if (Getattr(p2, "tmap:in:next")) { + p2 = Getattr(p2, "tmap:in:next"); } else { p2 = nextSibling(p2); } } if (!differ) { /* See if declarations differ by const only */ - String *d1 = Getattr(nodes[i].n,"decl"); - String *d2 = Getattr(nodes[j].n,"decl"); + String *d1 = Getattr(nodes[i].n, "decl"); + String *d2 = Getattr(nodes[j].n, "decl"); if (d1 && d2) { String *dq1 = Copy(d1); String *dq2 = Copy(d2); @@ -210,49 +210,45 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { if (SwigType_isconst(d2)) { Delete(SwigType_pop(dq2)); } - if (Strcmp(dq1,dq2) == 0) { - + if (Strcmp(dq1, dq2) == 0) { + if (SwigType_isconst(d1) && !SwigType_isconst(d2)) { - if (script_lang_wrapping) { - // Swap nodes so that the const method gets ignored (shadowed by the non-const method) - Overloaded t = nodes[i]; - nodes[i] = nodes[j]; - nodes[j] = t; - } + if (script_lang_wrapping) { + // Swap nodes so that the const method gets ignored (shadowed by the non-const method) + Overloaded t = nodes[i]; + nodes[i] = nodes[j]; + nodes[j] = t; + } differ = 1; if (!nodes[j].error) { - if (script_lang_wrapping) { + if (script_lang_wrapping) { Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded method %s(%s) ignored. Method %s(%s) const at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } } nodes[j].error = 1; } else if (!SwigType_isconst(d1) && SwigType_isconst(d2)) { differ = 1; if (!nodes[j].error) { - if (script_lang_wrapping) { + if (script_lang_wrapping) { Swig_warning(WARN_LANG_OVERLOAD_CONST, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded %s(%s) const ignored. Non-const method at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded method %s(%s) const ignored. Method %s(%s) at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - Getfile(nodes[i].n), Getline(nodes[i].n)); - } - } + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), Getfile(nodes[i].n), Getline(nodes[i].n)); + } + } nodes[j].error = 1; } } @@ -262,24 +258,22 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { } if (!differ) { if (!nodes[j].error) { - if (script_lang_wrapping) { - Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), + if (script_lang_wrapping) { + Swig_warning(WARN_LANG_OVERLOAD_SHADOW, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded %s(%s)%s is shadowed by %s(%s)%s at %s:%d.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", - Getfile(nodes[i].n),Getline(nodes[i].n)); - } else { - if (!Getattr(nodes[j].n, "overload:ignore")) - Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "", + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n)); + } else { + if (!Getattr(nodes[j].n, "overload:ignore")) + Swig_warning(WARN_LANG_OVERLOAD_IGNORED, Getfile(nodes[j].n), Getline(nodes[j].n), "Overloaded method %s(%s)%s ignored. Method %s(%s)%s at %s:%d used.\n", - Getattr(nodes[j].n,"name"), ParmList_protostr(nodes[j].parms), - SwigType_isconst(Getattr(nodes[j].n,"decl")) ? " const" : "", - Getattr(nodes[i].n,"name"), ParmList_protostr(nodes[i].parms), - SwigType_isconst(Getattr(nodes[i].n,"decl")) ? " const" : "", - Getfile(nodes[i].n),Getline(nodes[i].n)); - } + Getattr(nodes[j].n, "name"), ParmList_protostr(nodes[j].parms), + SwigType_isconst(Getattr(nodes[j].n, "decl")) ? " const" : "", + Getattr(nodes[i].n, "name"), ParmList_protostr(nodes[i].parms), + SwigType_isconst(Getattr(nodes[i].n, "decl")) ? " const" : "", Getfile(nodes[i].n), Getline(nodes[i].n)); + } nodes[j].error = 1; } } @@ -292,8 +286,8 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { int i; for (i = 0; i < nnodes; i++) { if (nodes[i].error) - Setattr(nodes[i].n, "overload:ignore", "1"); - Append(result,nodes[i].n); + Setattr(nodes[i].n, "overload:ignore", "1"); + Append(result, nodes[i].n); // Printf(stdout,"[ %d ] %s\n", i, ParmList_protostr(nodes[i].parms)); // Swig_print_node(nodes[i].n); } @@ -305,24 +299,22 @@ Swig_overload_rank(Node *n, bool script_lang_wrapping) { // * print_typecheck() // * ----------------------------------------------------------------------------- */ -static bool -print_typecheck(String *f, int j, Parm *pj) { +static bool print_typecheck(String *f, int j, Parm *pj) { char tmp[256]; - sprintf(tmp,Char(argv_template_string),j); - String *tm = Getattr(pj,"tmap:typecheck"); + sprintf(tmp, Char(argv_template_string), j); + String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { - Replaceid(tm,Getattr(pj,"lname"),"_v"); - String *conv = Getattr(pj,"implicitconv"); + Replaceid(tm, Getattr(pj, "lname"), "_v"); + String *conv = Getattr(pj, "implicitconv"); if (conv) { - Replaceall(tm,"$implicitconv", conv); + Replaceall(tm, "$implicitconv", conv); } else { - Replaceall(tm,"$implicitconv", "0"); + Replaceall(tm, "$implicitconv", "0"); } - Replaceall(tm,"$input", tmp); - Printv(f,tm,"\n",NIL); + Replaceall(tm, "$input", tmp); + Printv(f, tm, "\n", NIL); return true; - } - else + } else return false; } @@ -330,19 +322,18 @@ print_typecheck(String *f, int j, Parm *pj) { * ReplaceFormat() * ----------------------------------------------------------------------------- */ -static String * -ReplaceFormat (const String_or_char *fmt, int j) { - String *lfmt = NewString (fmt); +static String *ReplaceFormat(const String_or_char *fmt, int j) { + String *lfmt = NewString(fmt); char buf[50]; - sprintf (buf, "%d", j); - Replaceall (lfmt, "$numargs", buf); + sprintf(buf, "%d", j); + Replaceall(lfmt, "$numargs", buf); int i; - String *commaargs = NewString (""); - for (i=0; i < j; i++) { - Printv (commaargs, ", ", NIL); - Printf (commaargs, Char(argv_template_string), i); + String *commaargs = NewString(""); + for (i = 0; i < j; i++) { + Printv(commaargs, ", ", NIL); + Printf(commaargs, Char(argv_template_string), i); } - Replaceall (lfmt, "$commaargs", commaargs); + Replaceall(lfmt, "$commaargs", commaargs); return lfmt; } @@ -367,133 +358,135 @@ ReplaceFormat (const String_or_char *fmt, int j) { /* Cast dispatch mechanism. */ -String * -Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) { - int i,j; - +String *Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) { + int i, j; + *maxargs = 1; String *f = NewString(""); String *sw = NewString(""); - Printf(f,"{\n"); - Printf(f,"unsigned long _index = 0;\n"); - Printf(f,"SWIG_TypeRank _rank = 0; \n"); + Printf(f, "{\n"); + Printf(f, "unsigned long _index = 0;\n"); + Printf(f, "SWIG_TypeRank _rank = 0; \n"); /* Get a list of methods ranked by precedence values and argument count */ List *dispatch = Swig_overload_rank(n, true); - int nfunc = Len(dispatch); + int nfunc = Len(dispatch); /* Loop over the functions */ - bool emitcheck=1; + bool emitcheck = 1; for (i = 0; i < nfunc; i++) { int fn = 0; - Node *ni = Getitem(dispatch,i); - Parm *pi = Getattr(ni,"wrap:parms"); + Node *ni = Getitem(dispatch, i); + Parm *pi = Getattr(ni, "wrap:parms"); int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); - if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - + if (num_arguments > *maxargs) + *maxargs = num_arguments; + int varargs = emit_isvarargs(pi); + if (!varargs) { if (num_required == num_arguments) { - Printf(f,"if (%s == %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f,"if ((%s >= %d) && (%s <= %d)) {\n", - argc_template_string, num_required, - argc_template_string, num_arguments); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } } else { - Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); } - Printf(f,"SWIG_TypeRank _ranki = 0;\n"); - Printf(f,"SWIG_TypeRank _rankm = 0;\n"); - if (num_arguments) Printf(f,"SWIG_TypeRank _pi = 1;\n"); + Printf(f, "SWIG_TypeRank _ranki = 0;\n"); + Printf(f, "SWIG_TypeRank _rankm = 0;\n"); + if (num_arguments) + Printf(f, "SWIG_TypeRank _pi = 1;\n"); /* create a list with the wrappers that collide with the current one based on argument number */ - List *coll=NewList(); - for (int k=i+1; k=num_required && nrk<=num_arguments) || - (nak>=num_required && nak<=num_arguments) || - (nrk<=num_required && nak>=num_arguments)) + if ((nrk >= num_required && nrk <= num_arguments) || (nak >= num_required && nak <= num_arguments) || (nrk <= num_required && nak >= num_arguments)) Append(coll, nk); } // printf("overload: %s coll=%d\n", Char(Getattr(n, "sym:name")), Len(coll)); int num_braces = 0; - bool test=(num_arguments > 0); + bool test = (num_arguments > 0); if (test) { int need_v = 1; j = 0; Parm *pj = pi; while (pj) { - if (checkAttribute(pj,"tmap:in:numinputs","0")) { - pj = Getattr(pj,"tmap:in:next"); + if (checkAttribute(pj, "tmap:in:numinputs", "0")) { + pj = Getattr(pj, "tmap:in:next"); continue; } - String *tm = Getattr(pj,"tmap:typecheck"); + String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { - /* normalise for comparison later */ - Replaceid(tm,Getattr(pj,"lname"),"_v"); + /* normalise for comparison later */ + Replaceid(tm, Getattr(pj, "lname"), "_v"); /* if all the wrappers have the same type check on this argument we can optimize it out */ - for (int k=0; k %s\n\n", // Char(Getattr(nk, "sym:name")), // l, emitcheck, tml?Char(tml):0); } - Parm *pl1 = Getattr(pl,"tmap:in:next"); - if (pl1) pl = pl1; - else pl = nextSibling(pl); + Parm *pl1 = Getattr(pl, "tmap:in:next"); + if (pl1) + pl = pl1; + else + pl = nextSibling(pl); l++; } } if (emitcheck) { if (need_v) { - Printf(f,"int _v = 0;\n"); + Printf(f, "int _v = 0;\n"); need_v = 0; } if (j >= num_required) { Printf(f, "if (%s > %d) {\n", argc_template_string, j); num_braces++; } - String *tmp=NewStringf(argv_template_string, j); + String *tmp = NewStringf(argv_template_string, j); - String *conv = Getattr(pj,"implicitconv"); + String *conv = Getattr(pj, "implicitconv"); if (conv) { - Replaceall(tm,"$implicitconv", conv); + Replaceall(tm, "$implicitconv", conv); } else { - Replaceall(tm,"$implicitconv", "0"); + Replaceall(tm, "$implicitconv", "0"); } - Replaceall(tm,"$input", tmp); - Printv(f,"{\n",tm,"}\n",NIL); + Replaceall(tm, "$input", tmp); + Printv(f, "{\n", tm, "}\n", NIL); fn = i + 1; Printf(f, "if (!_v) goto check_%d;\n", fn); Printf(f, "_ranki += _v*_pi;\n", fn); @@ -501,287 +494,293 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) { Printf(f, "_pi *= SWIG_MAXCASTRANK;\n", fn); } } - if (!Getattr(pj,"tmap:in:SWIGTYPE") && Getattr(pj,"tmap:typecheck:SWIGTYPE")) { + if (!Getattr(pj, "tmap:in:SWIGTYPE") && Getattr(pj, "tmap:typecheck:SWIGTYPE")) { /* we emit a warning if the argument defines the 'in' typemap, but not the 'typecheck' one */ Swig_warning(WARN_TYPEMAP_TYPECHECK_UNDEF, Getfile(ni), Getline(ni), - "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", - Getattr(n,"name"),ParmList_str_defaultargs(pi), - j+1, SwigType_str(Getattr(pj,"type"),0)); + "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", + Getattr(n, "name"), ParmList_str_defaultargs(pi), j + 1, SwigType_str(Getattr(pj, "type"), 0)); } - Parm *pj1 = Getattr(pj,"tmap:in:next"); - if (pj1) pj = pj1; - else pj = nextSibling(pj); + Parm *pj1 = Getattr(pj, "tmap:in:next"); + if (pj1) + pj = pj1; + else + pj = nextSibling(pj); j++; } } /* close braces */ - for (/* empty */; num_braces > 0; num_braces--) Printf(f, "}\n"); + for ( /* empty */ ; num_braces > 0; num_braces--) + Printf(f, "}\n"); - Printf(f,"if (!_index || (_ranki < _rank)) {\n",i+1); - Printf(f," _rank = _ranki; _index = %d;\n",i+1); - Printf(f," if (_rank == _rankm) goto dispatch;\n",i+1); - Printf(f,"}\n",i+1); - String *lfmt = ReplaceFormat (fmt, num_arguments); - Printf(sw, "case %d:\n", i+1); - Printf(sw, Char(lfmt),Getattr(ni,"wrap:name")); + Printf(f, "if (!_index || (_ranki < _rank)) {\n", i + 1); + Printf(f, " _rank = _ranki; _index = %d;\n", i + 1); + Printf(f, " if (_rank == _rankm) goto dispatch;\n", i + 1); + Printf(f, "}\n", i + 1); + String *lfmt = ReplaceFormat(fmt, num_arguments); + Printf(sw, "case %d:\n", i + 1); + Printf(sw, Char(lfmt), Getattr(ni, "wrap:name")); Printf(sw, "\n"); - Printf(f,"}\n"); /* braces closes "if" for this method */ - if (fn) Printf(f, "check_%d:\n\n", fn); + Printf(f, "}\n"); /* braces closes "if" for this method */ + if (fn) + Printf(f, "check_%d:\n\n", fn); - Delete (lfmt); + Delete(lfmt); Delete(coll); } Delete(dispatch); - Printf(f,"dispatch:\n"); - Printf(f,"switch(_index) {\n"); - Printf(f,"%s",sw); - Printf(f,"}\n"); + Printf(f, "dispatch:\n"); + Printf(f, "switch(_index) {\n"); + Printf(f, "%s", sw); + Printf(f, "}\n"); - Printf(f,"}\n"); + Printf(f, "}\n"); return f; } /* Fast dispatch mechanism, provided by Salvador Fandi~no Garc'ia (#930586). */ -String * -Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *maxargs) { - int i,j; - +String *Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *maxargs) { + int i, j; + *maxargs = 1; String *f = NewString(""); /* Get a list of methods ranked by precedence values and argument count */ List *dispatch = Swig_overload_rank(n, true); - int nfunc = Len(dispatch); + int nfunc = Len(dispatch); /* Loop over the functions */ for (i = 0; i < nfunc; i++) { int fn = 0; - Node *ni = Getitem(dispatch,i); - Parm *pi = Getattr(ni,"wrap:parms"); + Node *ni = Getitem(dispatch, i); + Parm *pi = Getattr(ni, "wrap:parms"); int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); - if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - + if (num_arguments > *maxargs) + *maxargs = num_arguments; + int varargs = emit_isvarargs(pi); + if (!varargs) { if (num_required == num_arguments) { - Printf(f,"if (%s == %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f,"if ((%s >= %d) && (%s <= %d)) {\n", - argc_template_string, num_required, - argc_template_string, num_arguments); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } } else { - Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); } /* create a list with the wrappers that collide with the current one based on argument number */ - List *coll=NewList(); - for (int k=i+1; k=num_required && nrk<=num_arguments) || - (nak>=num_required && nak<=num_arguments) || - (nrk<=num_required && nak>=num_arguments)) + if ((nrk >= num_required && nrk <= num_arguments) || (nak >= num_required && nak <= num_arguments) || (nrk <= num_required && nak >= num_arguments)) Append(coll, nk); } // printf("overload: %s coll=%d\n", Char(Getattr(n, "sym:name")), Len(coll)); int num_braces = 0; - bool test=(Len(coll)>0 && num_arguments); + bool test = (Len(coll) > 0 && num_arguments); if (test) { int need_v = 1; j = 0; Parm *pj = pi; while (pj) { - if (checkAttribute(pj,"tmap:in:numinputs","0")) { - pj = Getattr(pj,"tmap:in:next"); + if (checkAttribute(pj, "tmap:in:numinputs", "0")) { + pj = Getattr(pj, "tmap:in:next"); continue; } - String *tm = Getattr(pj,"tmap:typecheck"); + String *tm = Getattr(pj, "tmap:typecheck"); if (tm) { - /* normalise for comparison later */ - Replaceid(tm,Getattr(pj,"lname"),"_v"); + /* normalise for comparison later */ + Replaceid(tm, Getattr(pj, "lname"), "_v"); /* if all the wrappers have the same type check on this argument we can optimize it out */ - bool emitcheck=0; - for (int k=0; k %s\n\n", // Char(Getattr(nk, "sym:name")), // l, emitcheck, tml?Char(tml):0); } - Parm *pl1 = Getattr(pl,"tmap:in:next"); - if (pl1) pl = pl1; - else pl = nextSibling(pl); + Parm *pl1 = Getattr(pl, "tmap:in:next"); + if (pl1) + pl = pl1; + else + pl = nextSibling(pl); l++; } } if (emitcheck) { if (need_v) { - Printf(f,"int _v = 0;\n"); + Printf(f, "int _v = 0;\n"); need_v = 0; } if (j >= num_required) { Printf(f, "if (%s > %d) {\n", argc_template_string, j); num_braces++; } - String *tmp=NewStringf(argv_template_string, j); + String *tmp = NewStringf(argv_template_string, j); - String *conv = Getattr(pj,"implicitconv"); + String *conv = Getattr(pj, "implicitconv"); if (conv) { - Replaceall(tm,"$implicitconv", conv); + Replaceall(tm, "$implicitconv", conv); } else { - Replaceall(tm,"$implicitconv", "0"); + Replaceall(tm, "$implicitconv", "0"); } - Replaceall(tm,"$input", tmp); - Printv(f,"{\n",tm,"}\n",NIL); + Replaceall(tm, "$input", tmp); + Printv(f, "{\n", tm, "}\n", NIL); fn = i + 1; Printf(f, "if (!_v) goto check_%d;\n", fn); } } - if (!Getattr(pj,"tmap:in:SWIGTYPE") && Getattr(pj,"tmap:typecheck:SWIGTYPE")) { + if (!Getattr(pj, "tmap:in:SWIGTYPE") && Getattr(pj, "tmap:typecheck:SWIGTYPE")) { /* we emit a warning if the argument defines the 'in' typemap, but not the 'typecheck' one */ Swig_warning(WARN_TYPEMAP_TYPECHECK_UNDEF, Getfile(ni), Getline(ni), - "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", - Getattr(n,"name"),ParmList_str_defaultargs(pi), - j+1, SwigType_str(Getattr(pj,"type"),0)); + "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", + Getattr(n, "name"), ParmList_str_defaultargs(pi), j + 1, SwigType_str(Getattr(pj, "type"), 0)); } - Parm *pj1 = Getattr(pj,"tmap:in:next"); - if (pj1) pj = pj1; - else pj = nextSibling(pj); + Parm *pj1 = Getattr(pj, "tmap:in:next"); + if (pj1) + pj = pj1; + else + pj = nextSibling(pj); j++; } } /* close braces */ - for (/* empty */; num_braces > 0; num_braces--) Printf(f, "}\n"); + for ( /* empty */ ; num_braces > 0; num_braces--) + Printf(f, "}\n"); - String *lfmt = ReplaceFormat (fmt, num_arguments); - Printf(f, Char(lfmt),Getattr(ni,"wrap:name")); + String *lfmt = ReplaceFormat(fmt, num_arguments); + Printf(f, Char(lfmt), Getattr(ni, "wrap:name")); - Printf(f,"}\n"); /* braces closes "if" for this method */ - if (fn) Printf(f, "check_%d:\n\n", fn); + Printf(f, "}\n"); /* braces closes "if" for this method */ + if (fn) + Printf(f, "check_%d:\n\n", fn); - Delete (lfmt); + Delete(lfmt); Delete(coll); } Delete(dispatch); return f; } -String * -Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) { +String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) { - if (fast_dispatch_mode || GetFlag(n,"feature:fastdispatch")) { + if (fast_dispatch_mode || GetFlag(n, "feature:fastdispatch")) { return Swig_overload_dispatch_fast(n, fmt, maxargs); } - - int i,j; - + + int i, j; + *maxargs = 1; String *f = NewString(""); /* Get a list of methods ranked by precedence values and argument count */ List *dispatch = Swig_overload_rank(n, true); - int nfunc = Len(dispatch); + int nfunc = Len(dispatch); /* Loop over the functions */ for (i = 0; i < nfunc; i++) { - Node *ni = Getitem(dispatch,i); - Parm *pi = Getattr(ni,"wrap:parms"); + Node *ni = Getitem(dispatch, i); + Parm *pi = Getattr(ni, "wrap:parms"); int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); - if (num_arguments > *maxargs) *maxargs = num_arguments; - int varargs = emit_isvarargs(pi); - + if (num_arguments > *maxargs) + *maxargs = num_arguments; + int varargs = emit_isvarargs(pi); + if (!varargs) { if (num_required == num_arguments) { - Printf(f,"if (%s == %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s == %d) {\n", argc_template_string, num_required); } else { - Printf(f,"if ((%s >= %d) && (%s <= %d)) {\n", - argc_template_string, num_required, - argc_template_string, num_arguments); + Printf(f, "if ((%s >= %d) && (%s <= %d)) {\n", argc_template_string, num_required, argc_template_string, num_arguments); } } else { - Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required); + Printf(f, "if (%s >= %d) {\n", argc_template_string, num_required); } if (num_arguments) { - Printf(f,"int _v;\n"); + Printf(f, "int _v;\n"); } - + int num_braces = 0; j = 0; Parm *pj = pi; while (pj) { - if (checkAttribute(pj,"tmap:in:numinputs","0")) { - pj = Getattr(pj,"tmap:in:next"); + if (checkAttribute(pj, "tmap:in:numinputs", "0")) { + pj = Getattr(pj, "tmap:in:next"); continue; } if (j >= num_required) { - String *lfmt = ReplaceFormat (fmt, num_arguments); + String *lfmt = ReplaceFormat(fmt, num_arguments); Printf(f, "if (%s <= %d) {\n", argc_template_string, j); - Printf(f, Char(lfmt),Getattr(ni,"wrap:name")); + Printf(f, Char(lfmt), Getattr(ni, "wrap:name")); Printf(f, "}\n"); - Delete (lfmt); + Delete(lfmt); } if (print_typecheck(f, j, pj)) { Printf(f, "if (_v) {\n"); num_braces++; - } - if (!Getattr(pj,"tmap:in:SWIGTYPE") && Getattr(pj,"tmap:typecheck:SWIGTYPE")) { + } + if (!Getattr(pj, "tmap:in:SWIGTYPE") && Getattr(pj, "tmap:typecheck:SWIGTYPE")) { /* we emit a warning if the argument defines the 'in' typemap, but not the 'typecheck' one */ Swig_warning(WARN_TYPEMAP_TYPECHECK_UNDEF, Getfile(ni), Getline(ni), - "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", - Getattr(n,"name"),ParmList_str_defaultargs(pi), - j+1, SwigType_str(Getattr(pj,"type"),0)); + "Overloaded %s(%s) with no explicit typecheck typemap for arg %d of type '%s'\n", + Getattr(n, "name"), ParmList_str_defaultargs(pi), j + 1, SwigType_str(Getattr(pj, "type"), 0)); } - Parm *pk = Getattr(pj,"tmap:in:next"); - if (pk) pj = pk; - else pj = nextSibling(pj); + Parm *pk = Getattr(pj, "tmap:in:next"); + if (pk) + pj = pk; + else + pj = nextSibling(pj); j++; } - String *lfmt = ReplaceFormat (fmt, num_arguments); - Printf(f, Char(lfmt),Getattr(ni,"wrap:name")); - Delete (lfmt); + String *lfmt = ReplaceFormat(fmt, num_arguments); + Printf(f, Char(lfmt), Getattr(ni, "wrap:name")); + Delete(lfmt); /* close braces */ - for (/* empty */; num_braces > 0; num_braces--) + for ( /* empty */ ; num_braces > 0; num_braces--) Printf(f, "}\n"); - Printf(f,"}\n"); /* braces closes "if" for this method */ + Printf(f, "}\n"); /* braces closes "if" for this method */ } Delete(dispatch); return f; @@ -791,6 +790,5 @@ Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *maxargs) { * Swig_overload_check() * ----------------------------------------------------------------------------- */ void Swig_overload_check(Node *n) { - Swig_overload_rank(n, false); + Swig_overload_rank(n, false); } - diff --git a/SWIG/Source/Modules/perl5.cxx b/SWIG/Source/Modules/perl5.cxx index a404c91b0..8a6f2509f 100644 --- a/SWIG/Source/Modules/perl5.cxx +++ b/SWIG/Source/Modules/perl5.cxx @@ -15,7 +15,7 @@ static int treduce = SWIG_cparse_template_reduce(0); #include -static const char *usage = (char*)"\ +static const char *usage = (char *) "\ Perl5 Options (available with -perl5)\n\ -static - Omit code related to dynamic loading\n\ -nopm - Do not generate the .pm file\n\ @@ -26,11 +26,11 @@ Perl5 Options (available with -perl5)\n\ -cppcast - Enable C++ casting operators\n\ -compat - Compatibility mode\n\n"; -static int compat = 0; +static int compat = 0; -static int no_pmfile = 0; +static int no_pmfile = 0; -static int export_all = 0; +static int export_all = 0; /* * pmfile @@ -43,7 +43,7 @@ static String *pmfile = 0; * set by the %module directive, e.g. "Xerces". It will determine * the name of the .pm file, and the dynamic library. */ -static String *module = 0; +static String *module = 0; /* * fullmodule @@ -51,57 +51,57 @@ static String *module = 0; * it will be used to set the package namespace in the .pm file, as * well as the name of the initialization methods in the glue library */ -static String *fullmodule = 0; +static String *fullmodule = 0; /* * cmodule * the namespace of the internal glue code, set to the value of * module with a 'c' appended */ -static String *cmodule = 0; +static String *cmodule = 0; -static String *command_tab = 0; -static String *constant_tab = 0; -static String *variable_tab = 0; +static String *command_tab = 0; +static String *constant_tab = 0; +static String *variable_tab = 0; -static File *f_runtime = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_init = 0; -static File *f_pm = 0; -static String *pm; /* Package initialization code */ -static String *magic; /* Magic variable wrappers */ +static File *f_runtime = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_init = 0; +static File *f_pm = 0; +static String *pm; /* Package initialization code */ +static String *magic; /* Magic variable wrappers */ -static int is_static = 0; +static int is_static = 0; /* The following variables are used to manage Perl5 classes */ -static int blessed = 1; /* Enable object oriented features */ -static int do_constants = 0; /* Constant wrapping */ -static List *classlist = 0; /* List of classes */ -static int have_constructor = 0; -static int have_destructor= 0; -static int have_data_members = 0; -static String *class_name = 0; /* Name of the class (what Perl thinks it is) */ -static String *real_classname = 0; /* Real name of C/C++ class */ -static String *fullclassname = 0; +static int blessed = 1; /* Enable object oriented features */ +static int do_constants = 0; /* Constant wrapping */ +static List *classlist = 0; /* List of classes */ +static int have_constructor = 0; +static int have_destructor = 0; +static int have_data_members = 0; +static String *class_name = 0; /* Name of the class (what Perl thinks it is) */ +static String *real_classname = 0; /* Real name of C/C++ class */ +static String *fullclassname = 0; -static String *pcode = 0; /* Perl code associated with each class */ -/* static String *blessedmembers = 0; */ /* Member data associated with each class */ -static int member_func = 0; /* Set to 1 when wrapping a member function */ -static String *func_stubs = 0; /* Function stubs */ -static String *const_stubs = 0; /* Constant stubs */ -static int num_consts = 0; /* Number of constants */ -static String *var_stubs = 0; /* Variable stubs */ -static String *exported = 0; /* Exported symbols */ -static String *pragma_include = 0; -static String *additional_perl_code = 0; /* Additional Perl code from %perlcode %{ ... %} */ -static Hash *operators = 0; -static int have_operators = 0; +static String *pcode = 0; /* Perl code associated with each class */ + /* static String *blessedmembers = 0; *//* Member data associated with each class */ +static int member_func = 0; /* Set to 1 when wrapping a member function */ +static String *func_stubs = 0; /* Function stubs */ +static String *const_stubs = 0; /* Constant stubs */ +static int num_consts = 0; /* Number of constants */ +static String *var_stubs = 0; /* Variable stubs */ +static String *exported = 0; /* Exported symbols */ +static String *pragma_include = 0; +static String *additional_perl_code = 0; /* Additional Perl code from %perlcode %{ ... %} */ +static Hash *operators = 0; +static int have_operators = 0; -class PERL5 : public Language { +class PERL5:public Language { public: - PERL5() : Language() { + PERL5():Language () { Clear(argc_template_string); Printv(argc_template_string, "items", NIL); Clear(argv_template_string); @@ -114,10 +114,10 @@ public: n = classLookup(t); /* Printf(stdout,"'%s' --> '%x'\n", t, n); */ if (n) { - if (!Getattr(n,"perl5:proxy")) { + if (!Getattr(n, "perl5:proxy")) { setclassname(n); } - return Getattr(n,"perl5:proxy"); + return Getattr(n, "perl5:proxy"); } return 0; } @@ -134,47 +134,49 @@ public: for (i = 1; i < argc; i++) { if (argv[i]) { - if(strcmp(argv[i],"-package") == 0) { - Printf(stderr,"*** -package is no longer supported\n*** use the directive '%module A::B::C' in your interface file instead\n*** see the Perl section in the manual for details.\n"); + if (strcmp(argv[i], "-package") == 0) { + Printf(stderr, + "*** -package is no longer supported\n*** use the directive '%module A::B::C' in your interface file instead\n*** see the Perl section in the manual for details.\n"); SWIG_exit(EXIT_FAILURE); - } else if(strcmp(argv[i],"-interface") == 0) { - Printf(stderr,"*** -interface is no longer supported\n*** use the directive '%module A::B::C' in your interface file instead\n*** see the Perl section in the manual for details.\n"); + } else if (strcmp(argv[i], "-interface") == 0) { + Printf(stderr, + "*** -interface is no longer supported\n*** use the directive '%module A::B::C' in your interface file instead\n*** see the Perl section in the manual for details.\n"); SWIG_exit(EXIT_FAILURE); - } else if (strcmp(argv[i],"-exportall") == 0) { + } else if (strcmp(argv[i], "-exportall") == 0) { export_all = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-static") == 0) { + } else if (strcmp(argv[i], "-static") == 0) { is_static = 1; Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) { + } else if ((strcmp(argv[i], "-shadow") == 0) || ((strcmp(argv[i], "-proxy") == 0))) { blessed = 1; Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-noproxy") == 0)) { - blessed =0; + } else if ((strcmp(argv[i], "-noproxy") == 0)) { + blessed = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-const") == 0) { + } else if (strcmp(argv[i], "-const") == 0) { do_constants = 1; blessed = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nopm") == 0) { - no_pmfile = 1; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-pm") == 0) { - Swig_mark_arg(i); - i++; - pmfile = NewString(argv[i]); - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-cppcast") == 0) { + } else if (strcmp(argv[i], "-nopm") == 0) { + no_pmfile = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-pm") == 0) { + Swig_mark_arg(i); + i++; + pmfile = NewString(argv[i]); + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-cppcast") == 0) { cppcast = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocppcast") == 0) { + } else if (strcmp(argv[i], "-nocppcast") == 0) { cppcast = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-compat") == 0) { + } else if (strcmp(argv[i], "-compat") == 0) { compat = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-help") == 0) { - fputs(usage,stdout); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); } } } @@ -197,9 +199,9 @@ public: virtual int top(Node *n) { /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); + String *outfile = Getattr(n, "outfile"); - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); @@ -208,47 +210,47 @@ public: f_header = NewString(""); f_wrappers = NewString(""); - /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); + /* Register file targets with the SWIG file handler */ + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); classlist = NewList(); - pm = NewString(""); - func_stubs = NewString(""); - var_stubs = NewString(""); - const_stubs = NewString(""); - exported = NewString(""); - magic = NewString(""); + pm = NewString(""); + func_stubs = NewString(""); + var_stubs = NewString(""); + const_stubs = NewString(""); + exported = NewString(""); + magic = NewString(""); pragma_include = NewString(""); additional_perl_code = NewString(""); - command_tab = NewString("static swig_command_info swig_commands[] = {\n"); - constant_tab = NewString("static swig_constant_info swig_constants[] = {\n"); - variable_tab = NewString("static swig_variable_info swig_variables[] = {\n"); + command_tab = NewString("static swig_command_info swig_commands[] = {\n"); + constant_tab = NewString("static swig_constant_info swig_constants[] = {\n"); + variable_tab = NewString("static swig_variable_info swig_variables[] = {\n"); Swig_banner(f_runtime); - - Printf(f_runtime,"#define SWIGPERL\n"); - Printf(f_runtime,"#define SWIG_CASTRANK_MODE\n"); + + Printf(f_runtime, "#define SWIGPERL\n"); + Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n"); - module = Copy(Getattr(n,"name")); + module = Copy(Getattr(n, "name")); - /* If we're in blessed mode, change the package name to "packagec" */ + /* If we're in blessed mode, change the package name to "packagec" */ if (blessed) { - cmodule = NewStringf("%sc",module); + cmodule = NewStringf("%sc", module); } else { cmodule = NewString(module); } fullmodule = NewString(module); - /* Create a .pm file - * Need to strip off any prefixes that might be found in - * the module name */ + /* Create a .pm file + * Need to strip off any prefixes that might be found in + * the module name */ if (no_pmfile) { f_pm = NewString(0); @@ -264,37 +266,36 @@ public: } pmfile = NewStringf("%s.pm", m); } - String *filen = NewStringf("%s%s", SWIG_output_directory(),pmfile); - if ((f_pm = NewFile(filen,"w")) == 0) { + String *filen = NewStringf("%s%s", SWIG_output_directory(), pmfile); + if ((f_pm = NewFile(filen, "w")) == 0) { FileErrorDisplay(filen); - SWIG_exit (EXIT_FAILURE); + SWIG_exit(EXIT_FAILURE); } - Delete(filen); filen = NULL; - Swig_register_filebyname("pm",f_pm); - Swig_register_filebyname("perl",f_pm); + Delete(filen); + filen = NULL; + Swig_register_filebyname("pm", f_pm); + Swig_register_filebyname("perl", f_pm); } { String *tmp = NewString(fullmodule); - Replaceall(tmp,":","_"); - Printf(f_header,"#define SWIG_init boot_%s\n\n", tmp); - Printf(f_header,"#define SWIG_name \"%s::boot_%s\"\n", cmodule, tmp); - Printf(f_header,"#define SWIG_prefix \"%s::\"\n", cmodule); + Replaceall(tmp, ":", "_"); + Printf(f_header, "#define SWIG_init boot_%s\n\n", tmp); + Printf(f_header, "#define SWIG_name \"%s::boot_%s\"\n", cmodule, tmp); + Printf(f_header, "#define SWIG_prefix \"%s::\"\n", cmodule); Delete(tmp); } Printv(f_pm, - "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", - "# Don't modify this file, modify the SWIG interface instead.\n", - NIL); + "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", "# Don't modify this file, modify the SWIG interface instead.\n", NIL); - Printf(f_pm,"package %s;\n",fullmodule); + Printf(f_pm, "package %s;\n", fullmodule); - Printf(f_pm,"require Exporter;\n"); + Printf(f_pm, "require Exporter;\n"); if (!is_static) { - Printf(f_pm,"require DynaLoader;\n"); - Printf(f_pm,"@ISA = qw(Exporter DynaLoader);\n"); + Printf(f_pm, "require DynaLoader;\n"); + Printf(f_pm, "@ISA = qw(Exporter DynaLoader);\n"); } else { - Printf(f_pm,"@ISA = qw(Exporter);\n"); + Printf(f_pm, "@ISA = qw(Exporter);\n"); } /* Start creating magic code */ @@ -308,100 +309,85 @@ public: "#define MAGIC_CLASS\n", "#endif\n", "SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *SWIGUNUSEDPARM(sv), MAGIC *SWIGUNUSEDPARM(mg)) {\n", - tab4, "MAGIC_PPERL\n", - tab4, "croak(\"Value is read-only.\");\n", - tab4, "return 0;\n", - "}\n", - NIL); + tab4, "MAGIC_PPERL\n", tab4, "croak(\"Value is read-only.\");\n", tab4, "return 0;\n", "}\n", NIL); - Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - /* emit wrappers */ + /* emit wrappers */ Language::top(n); String *base = NewString(""); - - /* Dump out variable wrappers */ - Printv(magic, - "\n\n#ifdef PERL_OBJECT\n", - "};\n", - "#endif\n", - NIL); + /* Dump out variable wrappers */ - Printf(f_header,"%s\n", magic); + Printv(magic, "\n\n#ifdef PERL_OBJECT\n", "};\n", "#endif\n", NIL); + + Printf(f_header, "%s\n", magic); String *type_table = NewString(""); - /* Patch the type table to reflect the names used by shadow classes */ + /* Patch the type table to reflect the names used by shadow classes */ if (blessed) { - Iterator cls; + Iterator cls; for (cls = First(classlist); cls.item; cls = Next(cls)) { - String *pname = Getattr(cls.item,"perl5:proxy"); + String *pname = Getattr(cls.item, "perl5:proxy"); if (pname) { - SwigType *type = Getattr(cls.item,"classtypeobj"); - if (!type) continue; /* If unnamed class, no type will be found */ + SwigType *type = Getattr(cls.item, "classtypeobj"); + if (!type) + continue; /* If unnamed class, no type will be found */ type = Copy(type); SwigType_add_pointer(type); String *mangled = SwigType_manglestr(type); - SwigType_remember_mangleddata(mangled, NewStringf("\"%s\"",pname)); + SwigType_remember_mangleddata(mangled, NewStringf("\"%s\"", pname)); Delete(type); Delete(mangled); } } } - SwigType_emit_type_table(f_runtime,type_table); + SwigType_emit_type_table(f_runtime, type_table); - Printf(f_wrappers,"%s",type_table); + Printf(f_wrappers, "%s", type_table); Delete(type_table); - Printf(constant_tab,"{0,0,0,0,0,0}\n};\n"); - Printv(f_wrappers,constant_tab,NIL); + Printf(constant_tab, "{0,0,0,0,0,0}\n};\n"); + Printv(f_wrappers, constant_tab, NIL); - Printf(f_wrappers,"#ifdef __cplusplus\n}\n#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); - Printf(f_init,"\t ST(0) = &PL_sv_yes;\n"); - Printf(f_init,"\t XSRETURN(1);\n"); - Printf(f_init,"}\n"); + Printf(f_init, "\t ST(0) = &PL_sv_yes;\n"); + Printf(f_init, "\t XSRETURN(1);\n"); + Printf(f_init, "}\n"); /* Finish off tables */ Printf(variable_tab, "{0,0,0,0}\n};\n"); - Printv(f_wrappers,variable_tab,NIL); + Printv(f_wrappers, variable_tab, NIL); - Printf(command_tab,"{0,0}\n};\n"); - Printv(f_wrappers,command_tab,NIL); + Printf(command_tab, "{0,0}\n};\n"); + Printv(f_wrappers, command_tab, NIL); - Printf(f_pm,"package %s;\n", cmodule); + Printf(f_pm, "package %s;\n", cmodule); if (!is_static) { - Printf(f_pm,"bootstrap %s;\n", fullmodule); + Printf(f_pm, "bootstrap %s;\n", fullmodule); } else { String *tmp = NewString(fullmodule); - Replaceall(tmp,":","_"); - Printf(f_pm,"boot_%s();\n", tmp); + Replaceall(tmp, ":", "_"); + Printf(f_pm, "boot_%s();\n", tmp); Delete(tmp); } - Printf(f_pm,"package %s;\n", fullmodule); - Printf(f_pm,"@EXPORT = qw( %s);\n",exported); - Printf(f_pm,"%s",pragma_include); + Printf(f_pm, "package %s;\n", fullmodule); + Printf(f_pm, "@EXPORT = qw( %s);\n", exported); + Printf(f_pm, "%s", pragma_include); if (blessed) { - Printv(base, - "\n# ---------- BASE METHODS -------------\n\n", - "package ", fullmodule, ";\n\n", - NIL); + Printv(base, "\n# ---------- BASE METHODS -------------\n\n", "package ", fullmodule, ";\n\n", NIL); /* Write out the TIE method */ - Printv(base, - "sub TIEHASH {\n", - tab4, "my ($classname,$obj) = @_;\n", - tab4, "return bless $obj, $classname;\n", - "}\n\n", - NIL); + Printv(base, "sub TIEHASH {\n", tab4, "my ($classname,$obj) = @_;\n", tab4, "return bless $obj, $classname;\n", "}\n\n", NIL); /* Output a CLEAR method. This is just a place-holder, but by providing it we * can make declarations such as @@ -409,7 +395,7 @@ public: * * Where x,y,z are the members of some C/C++ object. */ - Printf(base,"sub CLEAR { }\n\n"); + Printf(base, "sub CLEAR { }\n\n"); /* Output default firstkey/nextkey methods */ @@ -419,68 +405,56 @@ public: /* Output a FETCH method. This is actually common to all classes */ Printv(base, "sub FETCH {\n", - tab4, "my ($self,$field) = @_;\n", - tab4, "my $member_func = \"swig_${field}_get\";\n", - tab4, "$self->$member_func();\n", - "}\n\n", - NIL); + tab4, "my ($self,$field) = @_;\n", tab4, "my $member_func = \"swig_${field}_get\";\n", tab4, "$self->$member_func();\n", "}\n\n", NIL); /* Output a STORE method. This is also common to all classes (might move to base class) */ Printv(base, "sub STORE {\n", tab4, "my ($self,$field,$newval) = @_;\n", - tab4, "my $member_func = \"swig_${field}_set\";\n", - tab4, "$self->$member_func($newval);\n", - "}\n\n", - NIL); + tab4, "my $member_func = \"swig_${field}_set\";\n", tab4, "$self->$member_func($newval);\n", "}\n\n", NIL); /* Output a 'this' method */ - Printv(base, - "sub this {\n", - tab4, "my $ptr = shift;\n", - tab4, "return tied(%$ptr);\n", - "}\n\n", - NIL); + Printv(base, "sub this {\n", tab4, "my $ptr = shift;\n", tab4, "return tied(%$ptr);\n", "}\n\n", NIL); - Printf(f_pm,"%s",base); + Printf(f_pm, "%s", base); /* Emit function stubs for stand-alone functions */ - Printf(f_pm,"\n# ------- FUNCTION WRAPPERS --------\n\n"); - Printf(f_pm,"package %s;\n\n",fullmodule); - Printf(f_pm,"%s",func_stubs); + Printf(f_pm, "\n# ------- FUNCTION WRAPPERS --------\n\n"); + Printf(f_pm, "package %s;\n\n", fullmodule); + Printf(f_pm, "%s", func_stubs); /* Emit package code for different classes */ - Printf(f_pm,"%s",pm); + Printf(f_pm, "%s", pm); if (num_consts > 0) { /* Emit constant stubs */ - Printf(f_pm,"\n# ------- CONSTANT STUBS -------\n\n"); - Printf(f_pm,"package %s;\n\n",fullmodule); - Printf(f_pm,"%s",const_stubs); + Printf(f_pm, "\n# ------- CONSTANT STUBS -------\n\n"); + Printf(f_pm, "package %s;\n\n", fullmodule); + Printf(f_pm, "%s", const_stubs); } /* Emit variable stubs */ - Printf(f_pm,"\n# ------- VARIABLE STUBS --------\n\n"); - Printf(f_pm,"package %s;\n\n",fullmodule); - Printf(f_pm,"%s",var_stubs); + Printf(f_pm, "\n# ------- VARIABLE STUBS --------\n\n"); + Printf(f_pm, "package %s;\n\n", fullmodule); + Printf(f_pm, "%s", var_stubs); } /* Add additional Perl code at the end */ - Printf(f_pm,"%s",additional_perl_code); + Printf(f_pm, "%s", additional_perl_code); - Printf(f_pm,"1;\n"); + Printf(f_pm, "1;\n"); Close(f_pm); Delete(f_pm); Delete(base); /* Close all of the files */ - Dump(f_header,f_runtime); - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_header, f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); @@ -495,9 +469,9 @@ public: virtual int importDirective(Node *n) { if (blessed) { - String *modname = Getattr(n,"module"); + String *modname = Getattr(n, "module"); if (modname) { - Printf(f_pm,"require %s;\n", modname); + Printf(f_pm, "require %s;\n", modname); } } return Language::importDirective(n); @@ -507,135 +481,133 @@ public: * functionWrapper() * ------------------------------------------------------------ */ - virtual int functionWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); - String *overname = 0; + virtual int functionWrapper(Node *n) { + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); + String *overname = 0; Parm *p; - int i; + int i; Wrapper *f; - char source[256],temp[256]; - String *tm; + char source[256], temp[256]; + String *tm; String *cleanup, *outarg; - int num_saved = 0; - int num_arguments, num_required; - int varargs = 0; + int num_saved = 0; + int num_arguments, num_required; + int varargs = 0; - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } - f = NewWrapper(); + f = NewWrapper(); cleanup = NewString(""); - outarg = NewString(""); + outarg = NewString(""); String *wname = Swig_name_wrapper(iname); if (overname) { - Append(wname,overname); + Append(wname, overname); } - Setattr(n,"wrap:name",wname); - Printv(f->def, - "XS(", wname, ") {\n", - "{\n", /* scope to destroy C++ objects before croaking */ - NIL ); + Setattr(n, "wrap:name", wname); + Printv(f->def, "XS(", wname, ") {\n", "{\n", /* scope to destroy C++ objects before croaking */ + NIL); emit_args(d, l, f); - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); - varargs = emit_isvarargs(l); + num_required = emit_num_required(l); + varargs = emit_isvarargs(l); - Wrapper_add_local(f,"argvi","int argvi = 0"); + Wrapper_add_local(f, "argvi", "int argvi = 0"); /* Check the number of arguments */ if (!varargs) { - Printf(f->code," if ((items < %d) || (items > %d)) {\n", num_required, num_arguments); + Printf(f->code, " if ((items < %d) || (items > %d)) {\n", num_required, num_arguments); } else { - Printf(f->code," if (items < %d) {\n", num_required); + Printf(f->code, " if (items < %d) {\n", num_required); } - Printf(f->code," SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname),d,l)); - Printf(f->code,"}\n"); + Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, l)); + Printf(f->code, "}\n"); /* Write code to extract parameters. */ i = 0; for (i = 0, p = l; i < num_arguments; i++) { - + /* Skip ignored arguments */ - - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); + SwigType *pt = Getattr(p, "type"); /* Produce string representation of source and target arguments */ - sprintf(source,"ST(%d)",i); - String *target = Getattr(p,"lname"); + sprintf(source, "ST(%d)", i); + String *target = Getattr(p, "lname"); if (i >= num_required) { - Printf(f->code," if (items > %d) {\n", i); + Printf(f->code, " if (items > %d) {\n", i); } - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$target",target); - Replaceall(tm,"$source",source); - Replaceall(tm,"$input", source); - Setattr(p,"emit:input",source); /* Save input location */ + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$target", target); + Replaceall(tm, "$source", source); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); /* Save input location */ - if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); } else { - Replaceall(tm,"$disown","0"); + Replaceall(tm, "$disown", "0"); } - Printf(f->code,"%s\n",tm); - p = Getattr(p,"tmap:in:next"); + Printf(f->code, "%s\n", tm); + p = Getattr(p, "tmap:in:next"); } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); p = nextSibling(p); } if (i >= num_required) { - Printf(f->code," }\n"); + Printf(f->code, " }\n"); } } if (varargs) { - if (p && (tm = Getattr(p,"tmap:in"))) { - sprintf(source,"ST(%d)",i); - Replaceall(tm,"$input", source); - Setattr(p,"emit:input", source); - Printf(f->code,"if (items >= %d) {\n", i); + if (p && (tm = Getattr(p, "tmap:in"))) { + sprintf(source, "ST(%d)", i); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + Printf(f->code, "if (items >= %d) {\n", i); Printv(f->code, tm, "\n", NIL); - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); } } /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ for (i = 0, p = l; p; i++) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -643,28 +615,28 @@ public: /* Insert argument output code */ num_saved = 0; - for (i=0,p = l; p;i++) { - if ((tm = Getattr(p,"tmap:argout"))) { - SwigType *t = Getattr(p,"type"); - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","ST(argvi)"); - Replaceall(tm,"$result","ST(argvi)"); + for (i = 0, p = l; p; i++) { + if ((tm = Getattr(p, "tmap:argout"))) { + SwigType *t = Getattr(p, "type"); + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "ST(argvi)"); + Replaceall(tm, "$result", "ST(argvi)"); if (is_shadow(t)) { Replaceall(tm, "$shadow", "SWIG_SHADOW"); } else { Replaceall(tm, "$shadow", "0"); } - String *in = Getattr(p,"emit:input"); + String *in = Getattr(p, "emit:input"); if (in) { - sprintf(temp,"_saved[%d]", num_saved); - Replaceall(tm,"$arg",temp); - Replaceall(tm,"$input",temp); - Printf(f->code,"_saved[%d] = %s;\n", num_saved, in); + sprintf(temp, "_saved[%d]", num_saved); + Replaceall(tm, "$arg", temp); + Replaceall(tm, "$input", temp); + Printf(f->code, "_saved[%d] = %s;\n", num_saved, in); num_saved++; } - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } @@ -672,114 +644,106 @@ public: /* If there were any saved arguments, emit a local variable for them */ if (num_saved) { - sprintf(temp,"_saved[%d]",num_saved); - Wrapper_add_localv(f,"_saved","SV *",temp,NIL); + sprintf(temp, "_saved[%d]", num_saved); + Wrapper_add_localv(f, "_saved", "SV *", temp, NIL); } /* Now write code to make the function call */ - emit_action(n,f); + emit_action(n, f); - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - SwigType *t = Getattr(n,"type"); - Replaceall(tm,"$source","result"); - Replaceall(tm,"$target","ST(argvi)"); - Replaceall(tm,"$result", "ST(argvi)"); + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + SwigType *t = Getattr(n, "type"); + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "ST(argvi)"); + Replaceall(tm, "$result", "ST(argvi)"); if (is_shadow(t)) { Replaceall(tm, "$shadow", "SWIG_SHADOW"); } else { Replaceall(tm, "$shadow", "0"); } - if (GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","SWIG_OWNER"); + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "SWIG_OWNER"); } else { - Replaceall(tm,"$owner","0"); + Replaceall(tm, "$owner", "0"); } Printf(f->code, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(d,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } /* If there were any output args, take care of them. */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* If there was any cleanup, do that. */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } } - if ((tm = Swig_typemap_lookup_new("ret",n,"result", 0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n", tm); + if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } - Printv(f->code, - "XSRETURN(argvi);\n", - "fail:\n", - cleanup, - "SWIG_croak_null();\n" - "}\n" - "}\n", - NIL); - - /* Add the dXSARGS last */ + Printv(f->code, "XSRETURN(argvi);\n", "fail:\n", cleanup, "SWIG_croak_null();\n" "}\n" "}\n", NIL); - Wrapper_add_local(f,"dXSARGS","dXSARGS"); + /* Add the dXSARGS last */ + + Wrapper_add_local(f, "dXSARGS", "dXSARGS"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); - Replaceall(f->code,"$symname",iname); + Replaceall(f->code, "$cleanup", cleanup); + Replaceall(f->code, "$symname", iname); - /* Dump the wrapper function */ + /* Dump the wrapper function */ - Wrapper_print(f,f_wrappers); + Wrapper_print(f, f_wrappers); /* Now register the function */ - if (!Getattr(n,"sym:overloaded")) { - Printf(command_tab,"{\"%s::%s\", %s},\n", cmodule, iname, wname); - } else if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:overloaded")) { + Printf(command_tab, "{\"%s::%s\", %s},\n", cmodule, iname, wname); + } else if (!Getattr(n, "sym:nextSibling")) { /* Generate overloaded dispatch function */ int maxargs; - String *dispatch = Swig_overload_dispatch_cast(n,"++PL_markstack_ptr; SWIG_CALLXS(%s); return;",&maxargs); + String *dispatch = Swig_overload_dispatch_cast(n, "++PL_markstack_ptr; SWIG_CALLXS(%s); return;", &maxargs); /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *df = NewWrapper(); - String *dname = Swig_name_wrapper(iname); + Wrapper *df = NewWrapper(); + String *dname = Swig_name_wrapper(iname); Printv(df->def, "XS(", dname, ") {\n", NIL); - Wrapper_add_local(df,"dXSARGS", "dXSARGS"); - Printv(df->code,dispatch,"\n",NIL); - Printf(df->code,"croak(\"No matching function for overloaded '%s'\");\n", iname); - Printf(df->code,"XSRETURN(0);\n"); - Printv(df->code,"}\n",NIL); - Wrapper_print(df,f_wrappers); - Printf(command_tab,"{\"%s::%s\", %s},\n", cmodule, iname, dname); + Wrapper_add_local(df, "dXSARGS", "dXSARGS"); + Printv(df->code, dispatch, "\n", NIL); + Printf(df->code, "croak(\"No matching function for overloaded '%s'\");\n", iname); + Printf(df->code, "XSRETURN(0);\n"); + Printv(df->code, "}\n", NIL); + Wrapper_print(df, f_wrappers); + Printf(command_tab, "{\"%s::%s\", %s},\n", cmodule, iname, dname); DelWrapper(df); Delete(dispatch); Delete(dname); } - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { if (export_all) { - Printf(exported,"%s ", iname); + Printf(exported, "%s ", iname); } - + /* -------------------------------------------------------------------- * Create a stub for this function, provided it's not a member function * -------------------------------------------------------------------- */ - + if ((blessed) && (!member_func)) { - Printv(func_stubs,"*", iname, " = *", cmodule, "::", iname, ";\n", NIL); + Printv(func_stubs, "*", iname, " = *", cmodule, "::", iname, ";\n", NIL); } } @@ -793,92 +757,87 @@ public: * variableWrapper() * ------------------------------------------------------------ */ virtual int variableWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - Wrapper *getf, *setf; - String *tm; + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + Wrapper *getf, *setf; + String *tm; String *set_name = Swig_name_wrapper(Swig_name_set(iname)); String *val_name = Swig_name_wrapper(Swig_name_get(iname)); - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; getf = NewWrapper(); setf = NewWrapper(); /* Create a Perl function for setting the variable value */ - if (!GetFlag(n,"feature:immutable")) { - Printf(setf->def,"SWIGCLASS_STATIC int %s(pTHX_ SV* sv, MAGIC * SWIGUNUSEDPARM(mg)) {\n", set_name); - Printv(setf->code, - tab4, "MAGIC_PPERL\n", - NIL); + if (!GetFlag(n, "feature:immutable")) { + Printf(setf->def, "SWIGCLASS_STATIC int %s(pTHX_ SV* sv, MAGIC * SWIGUNUSEDPARM(mg)) {\n", set_name); + Printv(setf->code, tab4, "MAGIC_PPERL\n", NIL); /* Check for a few typemaps */ - tm = Swig_typemap_lookup_new("varin",n,name,0); + tm = Swig_typemap_lookup_new("varin", n, name, 0); if (tm) { - Replaceall(tm,"$source","sv"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","sv"); + Replaceall(tm, "$source", "sv"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "sv"); /* Printf(setf->code,"%s\n", tm); */ emit_action_code(n, setf, tm); } else { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, - "Unable to set variable of type %s.\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); return SWIG_NOWRAP; } - Printf(setf->code,"fail:\n"); - Printf(setf->code," return 1;\n}\n"); - Replaceall(setf->code,"$symname",iname); - Wrapper_print(setf,magic); + Printf(setf->code, "fail:\n"); + Printf(setf->code, " return 1;\n}\n"); + Replaceall(setf->code, "$symname", iname); + Wrapper_print(setf, magic); } /* Now write a function to evaluate the variable */ int addfail = 0; - Printf(getf->def,"SWIGCLASS_STATIC int %s(pTHX_ SV *sv, MAGIC *SWIGUNUSEDPARM(mg)) {\n", val_name); - Printv(getf->code, - tab4, "MAGIC_PPERL\n", - NIL); + Printf(getf->def, "SWIGCLASS_STATIC int %s(pTHX_ SV *sv, MAGIC *SWIGUNUSEDPARM(mg)) {\n", val_name); + Printv(getf->code, tab4, "MAGIC_PPERL\n", NIL); - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$target","sv"); - Replaceall(tm,"$result","sv"); - Replaceall(tm,"$source",name); + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$target", "sv"); + Replaceall(tm, "$result", "sv"); + Replaceall(tm, "$source", name); if (is_shadow(t)) { Replaceall(tm, "$shadow", "SWIG_SHADOW"); } else { Replaceall(tm, "$shadow", "0"); } - /* Printf(getf->code,"%s\n", tm);*/ + /* Printf(getf->code,"%s\n", tm); */ addfail = emit_action_code(n, getf, tm); } else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); return SWIG_NOWRAP; } - Printf(getf->code," return 1;\n"); + Printf(getf->code, " return 1;\n"); if (addfail) { - Append(getf->code,"fail:\n"); - Append(getf->code," return 0;\n"); + Append(getf->code, "fail:\n"); + Append(getf->code, " return 0;\n"); } - Append(getf->code,"}\n"); + Append(getf->code, "}\n"); - Replaceall(getf->code,"$symname",iname); - Wrapper_print(getf,magic); + Replaceall(getf->code, "$symname", iname); + Wrapper_print(getf, magic); - String *tt = Getattr(n,"tmap:varout:type"); + String *tt = Getattr(n, "tmap:varout:type"); if (tt) { String *tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(t)); - if (Replaceall(tt,"$1_descriptor", tm)) { + if (Replaceall(tt, "$1_descriptor", tm)) { SwigType_remember(t); } Delete(tm); SwigType *st = Copy(t); SwigType_add_pointer(st); tm = NewStringf("&SWIGTYPE%s", SwigType_manglestr(st)); - if (Replaceall(tt,"$&1_descriptor", tm)) { + if (Replaceall(tt, "$&1_descriptor", tm)) { SwigType_remember(st); } Delete(tm); @@ -887,33 +846,30 @@ public: tt = (String *) "0"; } /* Now add symbol to the PERL interpreter */ - if (GetFlag(n,"feature:immutable")) { - Printv(variable_tab, tab4, "{ \"", cmodule, "::", iname, "\", MAGIC_CLASS swig_magic_readonly, MAGIC_CLASS ", val_name,",", tt, " },\n",NIL); + if (GetFlag(n, "feature:immutable")) { + Printv(variable_tab, tab4, "{ \"", cmodule, "::", iname, "\", MAGIC_CLASS swig_magic_readonly, MAGIC_CLASS ", val_name, ",", tt, " },\n", NIL); } else { - Printv(variable_tab, tab4, "{ \"", cmodule, "::", iname, "\", MAGIC_CLASS ", set_name, ", MAGIC_CLASS ", val_name, ",", tt, " },\n",NIL); + Printv(variable_tab, tab4, "{ \"", cmodule, "::", iname, "\", MAGIC_CLASS ", set_name, ", MAGIC_CLASS ", val_name, ",", tt, " },\n", NIL); } /* If we're blessed, try to figure out what to do with the variable 1. If it's a Perl object of some sort, create a tied-hash - around it. - 2. Otherwise, just hack Perl's symbol table */ + around it. + 2. Otherwise, just hack Perl's symbol table */ if (blessed) { if (is_shadow(t)) { Printv(var_stubs, "\nmy %__", iname, "_hash;\n", "tie %__", iname, "_hash,\"", is_shadow(t), "\", $", - cmodule, "::", iname, ";\n", - "$", iname, "= \\%__", iname, "_hash;\n", - "bless $", iname, ", ", is_shadow(t), ";\n", - NIL); + cmodule, "::", iname, ";\n", "$", iname, "= \\%__", iname, "_hash;\n", "bless $", iname, ", ", is_shadow(t), ";\n", NIL); } else { Printv(var_stubs, "*", iname, " = *", cmodule, "::", iname, ";\n", NIL); } } if (export_all) - Printf(exported,"$%s ", iname); + Printf(exported, "$%s ", iname); DelWrapper(setf); DelWrapper(getf); @@ -927,36 +883,37 @@ public: * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); - String *tm; + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(iname); - Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type,wname), value); + Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } - if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) { - Replaceall(tm,"$source",value); - Replaceall(tm,"$target",name); - Replaceall(tm,"$value",value); + if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); if (is_shadow(type)) { Replaceall(tm, "$shadow", "SWIG_SHADOW"); } else { Replaceall(tm, "$shadow", "0"); } - Printf(constant_tab,"%s,\n", tm); + Printf(constant_tab, "%s,\n", tm); } else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) { - Replaceall(tm,"$source", value); - Replaceall(tm,"$target", name); - Replaceall(tm,"$value",value); + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); if (is_shadow(type)) { Replaceall(tm, "$shadow", "SWIG_SHADOW"); } else { @@ -964,8 +921,7 @@ public: } Printf(f_init, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } @@ -974,23 +930,19 @@ public: Printv(var_stubs, "\nmy %__", iname, "_hash;\n", "tie %__", iname, "_hash,\"", is_shadow(type), "\", $", - cmodule, "::", iname, ";\n", - "$", iname, "= \\%__", iname, "_hash;\n", - "bless $", iname, ", ", is_shadow(type), ";\n", - NIL); + cmodule, "::", iname, ";\n", "$", iname, "= \\%__", iname, "_hash;\n", "bless $", iname, ", ", is_shadow(type), ";\n", NIL); } else if (do_constants) { - Printv(const_stubs,"sub ", name, " () { $", - cmodule, "::", name, " }\n", NIL); + Printv(const_stubs, "sub ", name, " () { $", cmodule, "::", name, " }\n", NIL); num_consts++; } else { - Printv(var_stubs, "*",iname," = *", cmodule, "::", iname, ";\n", NIL); + Printv(var_stubs, "*", iname, " = *", cmodule, "::", iname, ";\n", NIL); } } if (export_all) { if (do_constants && !is_shadow(type)) { - Printf(exported,"%s ",name); + Printf(exported, "%s ", name); } else { - Printf(exported,"$%s ",iname); + Printf(exported, "$%s ", iname); } } return SWIG_OK; @@ -1001,59 +953,61 @@ public: * ------------------------------------------------------------ */ char *usage_func(char *iname, SwigType *, ParmList *l) { static String *temp = 0; - Parm *p; - int i; + Parm *p; + int i; - if (!temp) temp = NewString(""); + if (!temp) + temp = NewString(""); Clear(temp); - Printf(temp,"%s(",iname); + Printf(temp, "%s(", iname); /* Now go through and print parameters */ p = l; i = 0; while (p != 0) { - SwigType *pt = Getattr(p,"type"); - String *pn = Getattr(p,"name"); - if (!Getattr(p,"ignore")) { + SwigType *pt = Getattr(p, "type"); + String *pn = Getattr(p, "name"); + if (!Getattr(p, "ignore")) { /* If parameter has been named, use that. Otherwise, just print a type */ if (SwigType_type(pt) != T_VOID) { if (Len(pn) > 0) { - Printf(temp,"%s",pn); + Printf(temp, "%s", pn); } else { - Printf(temp,"%s",SwigType_str(pt,0)); + Printf(temp, "%s", SwigType_str(pt, 0)); } } i++; p = nextSibling(p); if (p) - if (!Getattr(p,"ignore")) - Putc(',',temp); + if (!Getattr(p, "ignore")) + Putc(',', temp); } else { p = nextSibling(p); if (p) - if ((i>0) && (!Getattr(p,"ignore"))) - Putc(',',temp); + if ((i > 0) && (!Getattr(p, "ignore"))) + Putc(',', temp); } } - Printf(temp,");"); + Printf(temp, ");"); return Char(temp); } /* ------------------------------------------------------------ * nativeWrapper() * ------------------------------------------------------------ */ - + virtual int nativeWrapper(Node *n) { - String *name = Getattr(n,"sym:name"); - String *funcname = Getattr(n,"wrap:name"); + String *name = Getattr(n, "sym:name"); + String *funcname = Getattr(n, "wrap:name"); - if (!addSymbol(funcname,n)) return SWIG_ERROR; + if (!addSymbol(funcname, n)) + return SWIG_ERROR; - Printf(command_tab,"{\"%s::%s\", %s},\n", cmodule,name,funcname); + Printf(command_tab, "{\"%s::%s\", %s},\n", cmodule, name, funcname); if (export_all) - Printf(exported,"%s ",name); + Printf(exported, "%s ", name); if (blessed) { - Printv(func_stubs,"*", name, " = *", cmodule, "::", name, ";\n", NIL); + Printv(func_stubs, "*", name, " = *", cmodule, "::", name, ";\n", NIL); } return SWIG_OK; } @@ -1090,44 +1044,44 @@ public: * in a tied hash. * * ------------------------------------------------------------------------- */ - - + + void setclassname(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); String *fullname; String *actualpackage; - Node *clsmodule = Getattr(n,"module"); - + Node *clsmodule = Getattr(n, "module"); + if (!clsmodule) { /* imported module does not define a module name. Oh well */ return; } /* Do some work on the class name */ - actualpackage = Getattr(clsmodule,"name"); - if ((!compat) && (!Strchr(symname,':'))) { - fullname = NewStringf("%s::%s",actualpackage,symname); + actualpackage = Getattr(clsmodule, "name"); + if ((!compat) && (!Strchr(symname, ':'))) { + fullname = NewStringf("%s::%s", actualpackage, symname); } else { fullname = NewString(symname); } - Setattr(n,"perl5:proxy", fullname); + Setattr(n, "perl5:proxy", fullname); } - + /* ------------------------------------------------------------ * classDeclaration() * ------------------------------------------------------------ */ virtual int classDeclaration(Node *n) { /* Do some work on the class name */ - if (!Getattr(n,"feature:onlychildren")) { + if (!Getattr(n, "feature:onlychildren")) { if (blessed) { setclassname(n); - Append(classlist,n); + Append(classlist, n); } } - + return Language::classDeclaration(n); } - + /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ @@ -1141,17 +1095,18 @@ public: have_data_members = 0; operators = NewHash(); - class_name = Getattr(n,"sym:name"); + class_name = Getattr(n, "sym:name"); - if (!addSymbol(class_name,n)) return SWIG_ERROR; + if (!addSymbol(class_name, n)) + return SWIG_ERROR; /* Use the fully qualified name of the Perl class */ if (!compat) { - fullclassname = NewStringf("%s::%s",fullmodule,class_name); + fullclassname = NewStringf("%s::%s", fullmodule, class_name); } else { fullclassname = NewString(class_name); } - real_classname = Getattr(n,"name"); + real_classname = Getattr(n, "name"); pcode = NewString(""); // blessedmembers = NewString(""); } @@ -1164,71 +1119,66 @@ public: if (blessed) { /* Generate a client-data entry */ SwigType *ct = NewStringf("p.%s", real_classname); - Printv(f_init,"SWIG_TypeClientData(SWIGTYPE", SwigType_manglestr(ct),", (void*) \"", - fullclassname, "\");\n", NIL); + Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", SwigType_manglestr(ct), ", (void*) \"", fullclassname, "\");\n", NIL); SwigType_remember(ct); Delete(ct); - Printv(pm, - "\n############# Class : ", fullclassname, " ##############\n", - "\npackage ", fullclassname, ";\n", - NIL); + Printv(pm, "\n############# Class : ", fullclassname, " ##############\n", "\npackage ", fullclassname, ";\n", NIL); if (have_operators) { Printf(pm, "use overload\n"); Iterator ki; for (ki = First(operators); ki.key; ki = Next(ki)) { char *name = Char(ki.key); - // fprintf(stderr,"found name: <%s>\n", name); + // fprintf(stderr,"found name: <%s>\n", name); if (strstr(name, "__eq__")) { - Printv(pm, tab4, "\"==\" => sub { $_[0]->__eq__($_[1])},\n",NIL); + Printv(pm, tab4, "\"==\" => sub { $_[0]->__eq__($_[1])},\n", NIL); } else if (strstr(name, "__ne__")) { - Printv(pm, tab4, "\"!=\" => sub { $_[0]->__ne__($_[1])},\n",NIL); + Printv(pm, tab4, "\"!=\" => sub { $_[0]->__ne__($_[1])},\n", NIL); } else if (strstr(name, "__assign__")) { - Printv(pm, tab4, "\"=\" => sub { $_[0]->__assign__($_[1])},\n",NIL); + Printv(pm, tab4, "\"=\" => sub { $_[0]->__assign__($_[1])},\n", NIL); } else if (strstr(name, "__str__")) { - Printv(pm, tab4, "'\"\"' => sub { $_[0]->__str__()},\n",NIL); + Printv(pm, tab4, "'\"\"' => sub { $_[0]->__str__()},\n", NIL); } else if (strstr(name, "__plusplus__")) { - Printv(pm, tab4, "\"++\" => sub { $_[0]->__plusplus__()},\n",NIL); + Printv(pm, tab4, "\"++\" => sub { $_[0]->__plusplus__()},\n", NIL); } else if (strstr(name, "__minmin__")) { - Printv(pm, tab4, "\"--\" => sub { $_[0]->__minmin__()},\n",NIL); + Printv(pm, tab4, "\"--\" => sub { $_[0]->__minmin__()},\n", NIL); } else if (strstr(name, "__add__")) { - Printv(pm, tab4, "\"+\" => sub { $_[0]->__add__($_[1])},\n",NIL); + Printv(pm, tab4, "\"+\" => sub { $_[0]->__add__($_[1])},\n", NIL); } else if (strstr(name, "__sub__")) { - Printv(pm, tab4, "\"-\" => sub { $_[0]->__sub__($_[1])},\n",NIL); + Printv(pm, tab4, "\"-\" => sub { $_[0]->__sub__($_[1])},\n", NIL); } else if (strstr(name, "__mul__")) { - Printv(pm, tab4, "\"*\" => sub { $_[0]->__mul__($_[1])},\n",NIL); + Printv(pm, tab4, "\"*\" => sub { $_[0]->__mul__($_[1])},\n", NIL); } else if (strstr(name, "__div__")) { - Printv(pm, tab4, "\"/\" => sub { $_[0]->__div__($_[1])},\n",NIL); + Printv(pm, tab4, "\"/\" => sub { $_[0]->__div__($_[1])},\n", NIL); } else if (strstr(name, "__mod__")) { - Printv(pm, tab4, "\"%\" => sub { $_[0]->__mod__($_[1])},\n",NIL); + Printv(pm, tab4, "\"%\" => sub { $_[0]->__mod__($_[1])},\n", NIL); } else if (strstr(name, "__and__")) { - Printv(pm, tab4, "\"&\" => sub { $_[0]->__and__($_[1])},\n",NIL); + Printv(pm, tab4, "\"&\" => sub { $_[0]->__and__($_[1])},\n", NIL); } else if (strstr(name, "__or__")) { - Printv(pm, tab4, "\"|\" => sub { $_[0]->__or__($_[1])},\n",NIL); + Printv(pm, tab4, "\"|\" => sub { $_[0]->__or__($_[1])},\n", NIL); } else if (strstr(name, "__gt__")) { - Printv(pm, tab4, "\">\" => sub { $_[0]->__gt__($_[1])},\n",NIL); - } else if (strstr(name, "__ge__")) { - Printv(pm, tab4, "\">=\" => sub { $_[0]->__ge__($_[1])},\n",NIL); + Printv(pm, tab4, "\">\" => sub { $_[0]->__gt__($_[1])},\n", NIL); + } else if (strstr(name, "__ge__")) { + Printv(pm, tab4, "\">=\" => sub { $_[0]->__ge__($_[1])},\n", NIL); } else if (strstr(name, "__not__")) { - Printv(pm, tab4, "\"!\" => sub { $_[0]->__not__()},\n",NIL); + Printv(pm, tab4, "\"!\" => sub { $_[0]->__not__()},\n", NIL); } else if (strstr(name, "__lt__")) { - Printv(pm, tab4, "\"<\" => sub { $_[0]->__lt__($_[1])},\n",NIL); - } else if (strstr(name, "__le__")) { - Printv(pm, tab4, "\"<=\" => sub { $_[0]->__le__($_[1])},\n",NIL); + Printv(pm, tab4, "\"<\" => sub { $_[0]->__lt__($_[1])},\n", NIL); + } else if (strstr(name, "__le__")) { + Printv(pm, tab4, "\"<=\" => sub { $_[0]->__le__($_[1])},\n", NIL); } else if (strstr(name, "__pluseq__")) { - Printv(pm, tab4, "\"+=\" => sub { $_[0]->__pluseq__($_[1])},\n",NIL); + Printv(pm, tab4, "\"+=\" => sub { $_[0]->__pluseq__($_[1])},\n", NIL); } else if (strstr(name, "__mineq__")) { - Printv(pm, tab4, "\"-=\" => sub { $_[0]->__mineq__($_[1])},\n",NIL); + Printv(pm, tab4, "\"-=\" => sub { $_[0]->__mineq__($_[1])},\n", NIL); } else if (strstr(name, "__neg__")) { - Printv(pm, tab4, "\"neg\" => sub { $_[0]->__neg__()},\n",NIL); + Printv(pm, tab4, "\"neg\" => sub { $_[0]->__neg__()},\n", NIL); } else { - fprintf(stderr,"Unknown operator: %s\n", name); + fprintf(stderr, "Unknown operator: %s\n", name); } } - Printv(pm, tab4, "\"fallback\" => 1;\n",NIL); + Printv(pm, tab4, "\"fallback\" => 1;\n", NIL); } - // make use strict happy Printv(pm, "use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);\n", NIL); @@ -1237,7 +1187,7 @@ public: Printv(pm, "@ISA = qw(", NIL); /* Handle inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator b; b = First(baselist); @@ -1247,14 +1197,14 @@ public: b = Next(b); continue; } - Printv(pm," ", bname, NIL); + Printv(pm, " ", bname, NIL); b = Next(b); } } /* Module comes last */ if (!compat || Cmp(fullmodule, fullclassname)) { - Printv(pm, " ", fullmodule, NIL); + Printv(pm, " ", fullmodule, NIL); } Printf(pm, " );\n"); @@ -1266,7 +1216,7 @@ public: /* Dump out the package methods */ - Printv(pm,pcode,NIL); + Printv(pm, pcode, NIL); Delete(pcode); /* Output methods for managing ownership */ @@ -1276,17 +1226,12 @@ public: tab4, "my $self = shift;\n", tab4, "my $ptr = tied(%$self);\n", tab4, "delete $OWNER{$ptr};\n", - "}\n\n", - "sub ACQUIRE {\n", - tab4, "my $self = shift;\n", - tab4, "my $ptr = tied(%$self);\n", - tab4, "$OWNER{$ptr} = 1;\n", - "}\n\n", - NIL); + "}\n\n", "sub ACQUIRE {\n", tab4, "my $self = shift;\n", tab4, "my $ptr = tied(%$self);\n", tab4, "$OWNER{$ptr} = 1;\n", "}\n\n", NIL); /* Only output the following methods if a class has member data */ - Delete(operators); operators = 0; + Delete(operators); + operators = 0; } return SWIG_OK; } @@ -1296,87 +1241,87 @@ public: * ------------------------------------------------------------ */ virtual int memberfunctionHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); member_func = 1; Language::memberfunctionHandler(n); member_func = 0; - if ((blessed) && (!Getattr(n,"sym:nextSibling"))) { - + if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { + if (Strstr(symname, "__eq__")) { - DohSetInt(operators,"__eq__",1); + DohSetInt(operators, "__eq__", 1); have_operators = 1; } else if (Strstr(symname, "__ne__")) { - DohSetInt(operators,"__ne__",1); + DohSetInt(operators, "__ne__", 1); have_operators = 1; } else if (Strstr(symname, "__assign__")) { - DohSetInt(operators,"__assign__",1); + DohSetInt(operators, "__assign__", 1); have_operators = 1; } else if (Strstr(symname, "__str__")) { - DohSetInt(operators,"__str__",1); + DohSetInt(operators, "__str__", 1); have_operators = 1; } else if (Strstr(symname, "__add__")) { - DohSetInt(operators,"__add__",1); + DohSetInt(operators, "__add__", 1); have_operators = 1; } else if (Strstr(symname, "__sub__")) { - DohSetInt(operators,"__sub__",1); + DohSetInt(operators, "__sub__", 1); have_operators = 1; } else if (Strstr(symname, "__mul__")) { - DohSetInt(operators,"__mul__",1); + DohSetInt(operators, "__mul__", 1); have_operators = 1; } else if (Strstr(symname, "__div__")) { - DohSetInt(operators,"__div__",1); + DohSetInt(operators, "__div__", 1); have_operators = 1; } else if (Strstr(symname, "__mod__")) { - DohSetInt(operators,"__mod__",1); + DohSetInt(operators, "__mod__", 1); have_operators = 1; } else if (Strstr(symname, "__and__")) { - DohSetInt(operators,"__and__",1); + DohSetInt(operators, "__and__", 1); have_operators = 1; } else if (Strstr(symname, "__or__")) { - DohSetInt(operators,"__or__",1); + DohSetInt(operators, "__or__", 1); have_operators = 1; } else if (Strstr(symname, "__not__")) { - DohSetInt(operators,"__not__",1); + DohSetInt(operators, "__not__", 1); have_operators = 1; } else if (Strstr(symname, "__gt__")) { - DohSetInt(operators,"__gt__",1); + DohSetInt(operators, "__gt__", 1); have_operators = 1; } else if (Strstr(symname, "__ge__")) { - DohSetInt(operators,"__ge__",1); + DohSetInt(operators, "__ge__", 1); have_operators = 1; } else if (Strstr(symname, "__lt__")) { - DohSetInt(operators,"__lt__",1); + DohSetInt(operators, "__lt__", 1); have_operators = 1; } else if (Strstr(symname, "__le__")) { - DohSetInt(operators,"__le__",1); + DohSetInt(operators, "__le__", 1); have_operators = 1; } else if (Strstr(symname, "__neg__")) { - DohSetInt(operators,"__neg__",1); + DohSetInt(operators, "__neg__", 1); have_operators = 1; } else if (Strstr(symname, "__plusplus__")) { - DohSetInt(operators,"__plusplus__",1); + DohSetInt(operators, "__plusplus__", 1); have_operators = 1; } else if (Strstr(symname, "__minmin__")) { - DohSetInt(operators,"__minmin__",1); + DohSetInt(operators, "__minmin__", 1); have_operators = 1; } else if (Strstr(symname, "__mineq__")) { - DohSetInt(operators,"__mineq__",1); + DohSetInt(operators, "__mineq__", 1); have_operators = 1; } else if (Strstr(symname, "__pluseq__")) { - DohSetInt(operators,"__pluseq__",1); + DohSetInt(operators, "__pluseq__", 1); have_operators = 1; } - if (Getattr(n,"feature:shadow")) { - String *plcode = perlcode(Getattr(n,"feature:shadow"),0); - String *plaction = NewStringf("%s::%s", cmodule, Swig_name_member(class_name,symname)); - Replaceall(plcode,"$action" ,plaction); + if (Getattr(n, "feature:shadow")) { + String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); + String *plaction = NewStringf("%s::%s", cmodule, Swig_name_member(class_name, symname)); + Replaceall(plcode, "$action", plaction); Delete(plaction); - Printv(pcode,plcode,NIL); + Printv(pcode, plcode, NIL); } else { - Printv(pcode,"*",symname," = *", cmodule, "::", Swig_name_member(class_name,symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); } } return SWIG_OK; @@ -1390,7 +1335,7 @@ public: virtual int membervariableHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); /* SwigType *t = Getattr(n,"type"); */ /* Emit a pair of get/set functions for the variable */ @@ -1401,21 +1346,21 @@ public: if (blessed) { - Printv(pcode,"*swig_", symname, "_get = *", cmodule, "::", Swig_name_get(Swig_name_member(class_name,symname)), ";\n", NIL); - Printv(pcode,"*swig_", symname, "_set = *", cmodule, "::", Swig_name_set(Swig_name_member(class_name,symname)), ";\n", NIL); + Printv(pcode, "*swig_", symname, "_get = *", cmodule, "::", Swig_name_get(Swig_name_member(class_name, symname)), ";\n", NIL); + Printv(pcode, "*swig_", symname, "_set = *", cmodule, "::", Swig_name_set(Swig_name_member(class_name, symname)), ";\n", NIL); /* Now we need to generate a little Perl code for this */ /* if (is_shadow(t)) { - *//* This is a Perl object that we have already seen. Add an - entry to the members list*//* - Printv(blessedmembers, - tab4, symname, " => '", is_shadow(t), "',\n", - NIL); + *//* This is a Perl object that we have already seen. Add an + entry to the members list *//* + Printv(blessedmembers, + tab4, symname, " => '", is_shadow(t), "',\n", + NIL); - } - */ + } + */ } have_data_members++; return SWIG_OK; @@ -1432,20 +1377,20 @@ public: virtual int constructorHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); member_func = 1; Language::constructorHandler(n); - if ((blessed) && (!Getattr(n,"sym:nextSibling"))) { - if (Getattr(n,"feature:shadow")) { - String *plcode = perlcode(Getattr(n,"feature:shadow"),0); - String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name,symname)); - Replaceall(plcode,"$action" ,plaction); - Delete(plaction); - Printv(pcode,plcode,NIL); + if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { + if (Getattr(n, "feature:shadow")) { + String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); + String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name, symname)); + Replaceall(plcode, "$action", plaction); + Delete(plaction); + Printv(pcode, plcode, NIL); } else { - if ((Cmp(symname,class_name) == 0)) { + if ((Cmp(symname, class_name) == 0)) { /* Emit a blessed constructor */ Printf(pcode, "sub new {\n"); } else { @@ -1455,10 +1400,7 @@ public: Printv(pcode, tab4, "my $pkg = shift;\n", - tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", - tab4, "bless $self, $pkg if defined($self);\n", - "}\n\n", - NIL); + tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); have_constructor = 1; } @@ -1470,18 +1412,18 @@ public: /* ------------------------------------------------------------ * destructorHandler() * ------------------------------------------------------------ */ - + virtual int destructorHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); member_func = 1; Language::destructorHandler(n); if (blessed) { - if (Getattr(n,"feature:shadow")) { - String *plcode = perlcode(Getattr(n,"feature:shadow"),0); - String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name,symname)); - Replaceall(plcode,"$action" ,plaction); - Delete(plaction); - Printv(pcode,plcode,NIL); + if (Getattr(n, "feature:shadow")) { + String *plcode = perlcode(Getattr(n, "feature:shadow"), 0); + String *plaction = NewStringf("%s::%s", module, Swig_name_member(class_name, symname)); + Replaceall(plcode, "$action", plaction); + Delete(plaction); + Printv(pcode, plcode, NIL); } else { Printv(pcode, "sub DESTROY {\n", @@ -1490,10 +1432,7 @@ public: tab4, "return unless defined $self;\n", tab4, "delete $ITERATORS{$self};\n", tab4, "if (exists $OWNER{$self}) {\n", - tab8, cmodule, "::", Swig_name_destroy(symname), "($self);\n", - tab8, "delete $OWNER{$self};\n", - tab4, "}\n}\n\n", - NIL); + tab8, cmodule, "::", Swig_name_destroy(symname), "($self);\n", tab8, "delete $OWNER{$self};\n", tab4, "}\n}\n\n", NIL); have_destructor = 1; } } @@ -1509,9 +1448,9 @@ public: member_func = 1; Language::staticmemberfunctionHandler(n); member_func = 0; - if ((blessed) && (!Getattr(n,"sym:nextSibling"))) { - String *symname = Getattr(n,"sym:name"); - Printv(pcode,"*",symname," = *", cmodule, "::", Swig_name_member(class_name,symname), ";\n", NIL); + if ((blessed) && (!Getattr(n, "sym:nextSibling"))) { + String *symname = Getattr(n, "sym:name"); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); } return SWIG_OK; } @@ -1523,27 +1462,27 @@ public: virtual int staticmembervariableHandler(Node *n) { Language::staticmembervariableHandler(n); if (blessed) { - String *symname = Getattr(n,"sym:name"); - Printv(pcode,"*",symname," = *", cmodule, "::", Swig_name_member(class_name,symname), ";\n", NIL); + String *symname = Getattr(n, "sym:name"); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); } return SWIG_OK; } - + /* ------------------------------------------------------------ * memberconstantHandler() * ------------------------------------------------------------ */ virtual int memberconstantHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); - int oldblessed = blessed; - + String *symname = Getattr(n, "sym:name"); + int oldblessed = blessed; + /* Create a normal constant */ blessed = 0; Language::memberconstantHandler(n); blessed = oldblessed; - + if (blessed) { - Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name,symname), ";\n", NIL); + Printv(pcode, "*", symname, " = *", cmodule, "::", Swig_name_member(class_name, symname), ";\n", NIL); } return SWIG_OK; } @@ -1562,30 +1501,30 @@ public: String *code; String *value; if (!ImportMode) { - lang = Getattr(n,"lang"); - code = Getattr(n,"name"); - value = Getattr(n,"value"); - if (Strcmp(lang,"perl5") == 0) { - if (Strcmp(code,"code") == 0) { + lang = Getattr(n, "lang"); + code = Getattr(n, "name"); + value = Getattr(n, "value"); + if (Strcmp(lang, "perl5") == 0) { + if (Strcmp(code, "code") == 0) { /* Dump the value string into the .pm file */ if (value) { Printf(pragma_include, "%s\n", value); } - } else if (Strcmp(code,"include") == 0) { + } else if (Strcmp(code, "include") == 0) { /* Include a file into the .pm file */ if (value) { FILE *f = Swig_open(value); if (!f) { - Printf(stderr,"%s : Line %d. Unable to locate file %s\n", input_file, line_number,value); + Printf(stderr, "%s : Line %d. Unable to locate file %s\n", input_file, line_number, value); } else { char buffer[4096]; - while (fgets(buffer,4095,f)) { - Printf(pragma_include,"%s",buffer); + while (fgets(buffer, 4095, f)) { + Printf(pragma_include, "%s", buffer); } } } } else { - Printf(stderr,"%s : Line %d. Unrecognized pragma.\n", input_file,line_number); + Printf(stderr, "%s : Line %d. Unrecognized pragma.\n", input_file, line_number); } } } @@ -1599,35 +1538,38 @@ public: String *perlcode(String *code, const String *indent) { String *out = NewString(""); String *temp; - char *t; - if (!indent) indent = ""; + char *t; + if (!indent) + indent = ""; temp = NewString(code); t = Char(temp); if (*t == '{') { - Delitem(temp,0); - Delitem(temp,DOH_END); + Delitem(temp, 0); + Delitem(temp, DOH_END); } /* Split the input text into lines */ List *clist = DohSplitLines(temp); Delete(temp); - int initial = 0; + int initial = 0; String *s = 0; Iterator si; /* Get the initial indentation */ - + for (si = First(clist); si.item; si = Next(si)) { s = si.item; if (Len(s)) { char *c = Char(s); while (*c) { - if (!isspace(*c)) break; + if (!isspace(*c)) + break; initial++; c++; } - if (*c && !isspace(*c)) break; + if (*c && !isspace(*c)) + break; else { initial = 0; } @@ -1638,16 +1580,16 @@ public: if (Len(s) > initial) { char *c = Char(s); c += initial; - Printv(out,indent,c,"\n",NIL); + Printv(out, indent, c, "\n", NIL); } else { - Printv(out,"\n",NIL); + Printv(out, "\n", NIL); } si = Next(si); } Delete(clist); return out; } - + /* ------------------------------------------------------------ * insertDirective() * @@ -1655,11 +1597,11 @@ public: * ------------------------------------------------------------ */ virtual int insertDirective(Node *n) { - String *code = Getattr(n,"code"); - String *section = Getattr(n,"section"); + String *code = Getattr(n, "code"); + String *section = Getattr(n, "section"); - if ((!ImportMode) && (Cmp(section,"perl") == 0)) { - Printv(additional_perl_code, code, NIL); + if ((!ImportMode) && (Cmp(section, "perl") == 0)) { + Printv(additional_perl_code, code, NIL); } else { Language::insertDirective(n); } @@ -1696,14 +1638,14 @@ public: return NewString("swigperlrun.h"); } }; - + /* ----------------------------------------------------------------------------- * swig_perl5() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_perl5() { +static Language *new_swig_perl5() { return new PERL5(); } -extern "C" Language * swig_perl5(void) { +extern "C" Language *swig_perl5(void) { return new_swig_perl5(); } diff --git a/SWIG/Source/Modules/php4.cxx b/SWIG/Source/Modules/php4.cxx index e28df7d44..e24bb30af 100644 --- a/SWIG/Source/Modules/php4.cxx +++ b/SWIG/Source/Modules/php4.cxx @@ -55,7 +55,7 @@ char cvsroot_php4_cxx[] = "$Header$"; #include #include -static const char *usage = (char*)"\ +static const char *usage = (char *) "\ PHP Options (available with -php4 or -php5)\n\ -cppext - cpp file extension (default to .cpp)\n\ -noproxy - Don't generate proxy classes.\n\ @@ -76,9 +76,9 @@ PHP Options (available with -php4 or -php5)\n\ */ #define SWIG_PTR "_cPtr" -static int constructors=0; -static String *NOTCLASS=NewString("Not a class"); -static Node *classnode=0; +static int constructors = 0; +static String *NOTCLASS = NewString("Not a class"); +static Node *classnode = 0; static String *module = 0; static String *cap_module = 0; static String *prefix = 0; @@ -89,48 +89,48 @@ static String *withcxx = 0; static String *shadow_classname = 0; -static int gen_extra = 0; -static int gen_make = 0; +static int gen_extra = 0; +static int gen_make = 0; -static File *f_runtime = 0; -static File *f_h = 0; -static File *f_phpcode = 0; -static String *phpfilename =0; +static File *f_runtime = 0; +static File *f_h = 0; +static File *f_phpcode = 0; +static String *phpfilename = 0; -static String *s_header; -static String *s_wrappers; -static String *s_init; -static String *r_init; // RINIT user code -static String *s_shutdown; // MSHUTDOWN user code -static String *r_shutdown; // RSHUTDOWN user code -static String *s_vinit; // varinit initialization code. -static String *s_vdecl; -static String *s_cinit; // consttab initialization code. -static String *s_oinit; -static String *s_entry; -static String *cs_entry; -static String *all_cs_entry; -static String *pragma_incl; -static String *pragma_code; -static String *pragma_phpinfo; -static String *s_oowrappers; -static String *s_fakeoowrappers; -static String *s_phpclasses; +static String *s_header; +static String *s_wrappers; +static String *s_init; +static String *r_init; // RINIT user code +static String *s_shutdown; // MSHUTDOWN user code +static String *r_shutdown; // RSHUTDOWN user code +static String *s_vinit; // varinit initialization code. +static String *s_vdecl; +static String *s_cinit; // consttab initialization code. +static String *s_oinit; +static String *s_entry; +static String *cs_entry; +static String *all_cs_entry; +static String *pragma_incl; +static String *pragma_code; +static String *pragma_phpinfo; +static String *s_oowrappers; +static String *s_fakeoowrappers; +static String *s_phpclasses; /* Variables for using PHP classes */ -static Node *current_class = 0; +static Node *current_class = 0; -static Hash *shadow_get_vars; -static Hash *shadow_set_vars; +static Hash *shadow_get_vars; +static Hash *shadow_set_vars; #define NATIVE_CONSTRUCTOR 1 #define ALTERNATIVE_CONSTRUCTOR 2 -static int native_constructor=0; -static Hash *zend_types = 0; +static int native_constructor = 0; +static Hash *zend_types = 0; -static int shadow = 1; +static int shadow = 1; -static bool class_has_ctor = false; -static String * wrapping_member_constant = NULL; +static bool class_has_ctor = false; +static String *wrapping_member_constant = NULL; // These static variables are used to pass some state from Handlers into functionWrapper static enum { @@ -144,182 +144,182 @@ static enum { } wrapperType = standard; extern "C" { -static void (*r_prevtracefunc)(SwigType *t, String *mangled, String *clientdata) = 0; + static void (*r_prevtracefunc) (SwigType *t, String *mangled, String *clientdata) = 0; } static const char *php_header = -"/*" -"\n +----------------------------------------------------------------------+" -"\n | PHP version 4.0 |" -"\n +----------------------------------------------------------------------+" -"\n | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |" -"\n +----------------------------------------------------------------------+" -"\n | This source file is subject to version 2.02 of the PHP license, |" -"\n | that is bundled with this package in the file LICENSE, and is |" -"\n | available at through the world-wide-web at |" -"\n | http://www.php.net/license/2_02.txt. |" -"\n | If you did not receive a copy of the PHP license and are unable to |" -"\n | obtain it through the world-wide-web, please send a note to |" -"\n | license@php.net so we can mail you a copy immediately. |" -"\n +----------------------------------------------------------------------+" -"\n | Authors: |" -"\n | |" -"\n +----------------------------------------------------------------------+" -"\n */\n"; + "/*" + "\n +----------------------------------------------------------------------+" + "\n | PHP version 4.0 |" + "\n +----------------------------------------------------------------------+" + "\n | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |" + "\n +----------------------------------------------------------------------+" + "\n | This source file is subject to version 2.02 of the PHP license, |" + "\n | that is bundled with this package in the file LICENSE, and is |" + "\n | available at through the world-wide-web at |" + "\n | http://www.php.net/license/2_02.txt. |" + "\n | If you did not receive a copy of the PHP license and are unable to |" + "\n | obtain it through the world-wide-web, please send a note to |" + "\n | license@php.net so we can mail you a copy immediately. |" + "\n +----------------------------------------------------------------------+" + "\n | Authors: |" + "\n | |" + "\n +----------------------------------------------------------------------+" "\n */\n"; -void -SwigPHP_emit_resource_registrations() { +void SwigPHP_emit_resource_registrations() { Iterator ki; - if (!zend_types) return; + if (!zend_types) + return; ki = First(zend_types); - if (ki.key) Printf(s_oinit,"\n/* Register resource destructors for pointer types */\n"); - while (ki.key) if (1 /* is pointer type*/) { - DOH *key = ki.key; - Node *class_node = ki.item; - String *human_name = key; + if (ki.key) + Printf(s_oinit, "\n/* Register resource destructors for pointer types */\n"); + while (ki.key) + if (1 /* is pointer type */ ) { + DOH *key = ki.key; + Node *class_node = ki.item; + String *human_name = key; - // Write out destructor function header - Printf(s_wrappers,"/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n",key); + // Write out destructor function header + Printf(s_wrappers, "/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n", key); - // write out body - if ((class_node!=NOTCLASS)) { - String *destructor = Getattr(class_node, "destructor"); - human_name = Getattr(class_node,"sym:name"); - if (!human_name) human_name = Getattr(class_node,"name"); - // Do we have a known destructor for this type? - if (destructor) { - Printf(s_wrappers," %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n",destructor,key); + // write out body + if ((class_node != NOTCLASS)) { + String *destructor = Getattr(class_node, "destructor"); + human_name = Getattr(class_node, "sym:name"); + if (!human_name) + human_name = Getattr(class_node, "name"); + // Do we have a known destructor for this type? + if (destructor) { + Printf(s_wrappers, " %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n", destructor, key); + } else { + Printf(s_wrappers, " /* No destructor for class %s */\n", human_name); + } } else { - Printf(s_wrappers," /* No destructor for class %s */\n", human_name); + Printf(s_wrappers, " /* No destructor for simple type %s */\n", key); } - } else { - Printf(s_wrappers," /* No destructor for simple type %s */\n", key); + + // close function + Printf(s_wrappers, "}\n"); + + // declare le_swig_ to store php registration + Printf(s_vdecl, "static int le_swig_%s=0; /* handle for %s */\n", key, human_name); + + // register with php + Printf(s_oinit, "le_swig_%s=zend_register_list_destructors_ex" "(_wrap_destroy%s,NULL,(char *)(SWIGTYPE%s->name),module_number);\n", key, key, key); + + // store php type in class struct + Printf(s_oinit, "SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", key, key); + + ki = Next(ki); } - - // close function - Printf(s_wrappers,"}\n"); - - // declare le_swig_ to store php registration - Printf(s_vdecl,"static int le_swig_%s=0; /* handle for %s */\n", key, human_name); - - // register with php - Printf(s_oinit,"le_swig_%s=zend_register_list_destructors_ex" - "(_wrap_destroy%s,NULL,(char *)(SWIGTYPE%s->name),module_number);\n", - key,key,key); - - // store php type in class struct - Printf(s_oinit,"SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", - key,key); - - ki = Next(ki); - } } -class PHP : public Language { +class PHP:public Language { int php_version; public: - PHP(int php_version_) : php_version(php_version_) { } + PHP(int php_version_):php_version(php_version_) { + } /* Test to see if a type corresponds to something wrapped with a shadow class. */ + String *is_shadow(SwigType *t) { String *r = 0; Node *n = classLookup(t); if (n) { - r = Getattr(n,"php:proxy"); // Set by classDeclaration() + r = Getattr(n, "php:proxy"); // Set by classDeclaration() if (!r) { - r = Getattr(n,"sym:name"); // Not seen by classDeclaration yet, but this is the name + r = Getattr(n, "sym:name"); // Not seen by classDeclaration yet, but this is the name } } return r; } - + /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ - + virtual void main(int argc, char *argv[]) { int i; SWIG_library_directory("php4"); SWIG_config_cppext("cpp"); - - for(i = 1; i < argc; i++) { + + for (i = 1; i < argc; i++) { if (argv[i]) { - if(strcmp(argv[i], "-phpfull") == 0) { - gen_extra = 1; - Swig_mark_arg(i); - } else if(strcmp(argv[i], "-dlname") == 0) { - Printf(stderr,"*** -dlname is no longer supported\n*** if you want to change the module name, use -module instead.\n"); + if (strcmp(argv[i], "-phpfull") == 0) { + gen_extra = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-dlname") == 0) { + Printf(stderr, "*** -dlname is no longer supported\n*** if you want to change the module name, use -module instead.\n"); SWIG_exit(EXIT_FAILURE); - } else if(strcmp(argv[i], "-prefix") == 0) { - if (argv[i+1]) { - prefix = NewString(argv[i+1]); + } else if (strcmp(argv[i], "-prefix") == 0) { + if (argv[i + 1]) { + prefix = NewString(argv[i + 1]); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } else if(strcmp(argv[i], "-withlibs") == 0) { - if (argv[i+1]) { - withlibs = NewString(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if(strcmp(argv[i], "-withincs") == 0) { - if (argv[i+1]) { - withincs = NewString(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if(strcmp(argv[i], "-withc") == 0) { - if (argv[i+1]) { - withc = NewString(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if(strcmp(argv[i], "-withcxx") == 0) { - if (argv[i+1]) { - withcxx = NewString(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if(strcmp(argv[i], "-cppext") == 0) { - if (argv[i+1]) { - SWIG_config_cppext(argv[i+1]); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if((strcmp(argv[i], "-noshadow") == 0) || - (strcmp(argv[i], "-noproxy") == 0)) { - shadow = 0; - Swig_mark_arg(i); - } else if(strcmp(argv[i], "-make") == 0) { - gen_make = 1; - Swig_mark_arg(i); - } else if(strcmp(argv[i], "-help") == 0) { - fputs(usage, stdout); - } + } else if (strcmp(argv[i], "-withlibs") == 0) { + if (argv[i + 1]) { + withlibs = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-withincs") == 0) { + if (argv[i + 1]) { + withincs = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-withc") == 0) { + if (argv[i + 1]) { + withc = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-withcxx") == 0) { + if (argv[i + 1]) { + withcxx = NewString(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-cppext") == 0) { + if (argv[i + 1]) { + SWIG_config_cppext(argv[i + 1]); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if ((strcmp(argv[i], "-noshadow") == 0) || (strcmp(argv[i], "-noproxy") == 0)) { + shadow = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-make") == 0) { + gen_make = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); + } } } - + Preprocessor_define((void *) "SWIGPHP 1", 0); if (php_version == 4) { Preprocessor_define((void *) "SWIGPHP4 1", 0); @@ -331,24 +331,25 @@ public: SWIG_config_file("php4.swg"); allow_overloading(); } - + void create_simple_make(void) { File *f_make; - - f_make = NewFile((void *)"makefile", "w"); + + f_make = NewFile((void *) "makefile", "w"); Printf(f_make, "CC=gcc\n"); Printf(f_make, "CXX=g++\n"); - Printf(f_make, "CXX_SOURCES=%s\n", withcxx ); - Printf(f_make, "C_SOURCES=%s\n", withc ); - Printf(f_make, "OBJS=%s_wrap.o $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cxx=.o)\n", module ); - Printf(f_make, "MODULE=%s.`php -r 'switch(PHP_SHLIB_SUFFIX){case\"PHP_SHLIB_SUFFIX\":case\"dylib\":echo\"so\";break;default:echo PHP_SHLIB_SUFFIX;}'`\n", module); - Printf(f_make, "CFLAGS=-fpic\n" ); + Printf(f_make, "CXX_SOURCES=%s\n", withcxx); + Printf(f_make, "C_SOURCES=%s\n", withc); + Printf(f_make, "OBJS=%s_wrap.o $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cxx=.o)\n", module); + Printf(f_make, "MODULE=%s.`php -r 'switch(PHP_SHLIB_SUFFIX){case\"PHP_SHLIB_SUFFIX\":case\"dylib\":echo\"so\";break;default:echo PHP_SHLIB_SUFFIX;}'`\n", + module); + Printf(f_make, "CFLAGS=-fpic\n"); Printf(f_make, "LDFLAGS=-shared\n"); Printf(f_make, "PHP_INC=`php-config --includes`\n"); Printf(f_make, "EXTRA_INC=\n"); - Printf(f_make, "EXTRA_LIB=\n\n" ); + Printf(f_make, "EXTRA_LIB=\n\n"); Printf(f_make, "$(MODULE): $(OBJS)\n"); - if ( CPlusPlus || (withcxx != NULL) ) { + if (CPlusPlus || (withcxx != NULL)) { Printf(f_make, "\t$(CXX) $(LDFLAGS) $(OBJS) -o $(PROG) $(EXTRA_LIB)\n\n"); } else { Printf(f_make, "\t$(CC) $(LDFLAGS) $(OBJS) -o $(PROG) $(EXTRA_LIB)\n\n"); @@ -362,13 +363,13 @@ public: Close(f_make); } - + void create_extra_files(String *outfile) { File *f_extra; - static String *configm4=0; - static String *makefilein=0; - static String *credits=0; + static String *configm4 = 0; + static String *makefilein = 0; + static String *credits = 0; configm4 = NewStringEmpty(); Printv(configm4, SWIG_output_directory(), "config.m4", NIL); @@ -380,52 +381,49 @@ public: Printv(credits, SWIG_output_directory(), "CREDITS", NIL); // are we a --with- or --enable- - int with=(withincs || withlibs)?1:0; + int with = (withincs || withlibs) ? 1 : 0; // Note Makefile.in only copes with one source file // also withincs and withlibs only take one name each now // the code they generate should be adapted to take multiple lines - + /* Write out Makefile.in */ f_extra = NewFile(makefilein, "w"); if (!f_extra) { FileErrorDisplay(makefilein); SWIG_exit(EXIT_FAILURE); } - - Printf(f_extra, - "# $Id$\n\n" - "LTLIBRARY_NAME = %s.la\n", - module); + + Printf(f_extra, "# $Id$\n\n" "LTLIBRARY_NAME = %s.la\n", module); // C++ has more and different entries to C in Makefile.in - if (! CPlusPlus) { - Printf(f_extra,"LTLIBRARY_SOURCES = %s %s\n", Swig_file_filename(outfile),withc); - Printf(f_extra,"LTLIBRARY_SOURCES_CPP = %s\n", withcxx); + if (!CPlusPlus) { + Printf(f_extra, "LTLIBRARY_SOURCES = %s %s\n", Swig_file_filename(outfile), withc); + Printf(f_extra, "LTLIBRARY_SOURCES_CPP = %s\n", withcxx); } else { - Printf(f_extra,"LTLIBRARY_SOURCES = %s\n", withc ); - Printf(f_extra,"LTLIBRARY_SOURCES_CPP = %s %s\n", Swig_file_filename(outfile),withcxx); - Printf(f_extra,"LTLIBRARY_OBJECTS_X = $(LTLIBRARY_SOURCES_CPP:.cpp=.lo) $(LTLIBRARY_SOURCES_CPP:.cxx=.lo)\n"); + Printf(f_extra, "LTLIBRARY_SOURCES = %s\n", withc); + Printf(f_extra, "LTLIBRARY_SOURCES_CPP = %s %s\n", Swig_file_filename(outfile), withcxx); + Printf(f_extra, "LTLIBRARY_OBJECTS_X = $(LTLIBRARY_SOURCES_CPP:.cpp=.lo) $(LTLIBRARY_SOURCES_CPP:.cxx=.lo)\n"); } - Printf(f_extra,"LTLIBRARY_SHARED_NAME = %s.la\n", module); - Printf(f_extra,"LTLIBRARY_SHARED_LIBADD = $(%s_SHARED_LIBADD)\n\n", cap_module); - Printf(f_extra,"include $(top_srcdir)/build/dynlib.mk\n"); + Printf(f_extra, "LTLIBRARY_SHARED_NAME = %s.la\n", module); + Printf(f_extra, "LTLIBRARY_SHARED_LIBADD = $(%s_SHARED_LIBADD)\n\n", cap_module); + Printf(f_extra, "include $(top_srcdir)/build/dynlib.mk\n"); - Printf(f_extra,"\n# patch in .cxx support to php build system to work like .cpp\n"); - Printf(f_extra,".SUFFIXES: .cxx\n\n"); + Printf(f_extra, "\n# patch in .cxx support to php build system to work like .cpp\n"); + Printf(f_extra, ".SUFFIXES: .cxx\n\n"); - Printf(f_extra,".cxx.o:\n"); - Printf(f_extra,"\t$(CXX_COMPILE) -c $<\n\n"); + Printf(f_extra, ".cxx.o:\n"); + Printf(f_extra, "\t$(CXX_COMPILE) -c $<\n\n"); - Printf(f_extra,".cxx.lo:\n"); - Printf(f_extra,"\t$(CXX_PHP_COMPILE)\n\n"); - Printf(f_extra,".cxx.slo:\n"); + Printf(f_extra, ".cxx.lo:\n"); + Printf(f_extra, "\t$(CXX_PHP_COMPILE)\n\n"); + Printf(f_extra, ".cxx.slo:\n"); - Printf(f_extra,"\t$(CXX_SHARED_COMPILE)\n\n"); + Printf(f_extra, "\t$(CXX_SHARED_COMPILE)\n\n"); - Printf(f_extra,"\n# make it easy to test module\n"); - Printf(f_extra,"testmodule:\n"); - Printf(f_extra,"\tphp -q -d extension_dir=modules %s\n\n",Swig_file_filename(phpfilename)); + Printf(f_extra, "\n# make it easy to test module\n"); + Printf(f_extra, "testmodule:\n"); + Printf(f_extra, "\tphp -q -d extension_dir=modules %s\n\n", Swig_file_filename(phpfilename)); Close(f_extra); @@ -433,7 +431,7 @@ public: // Note: # comments are OK in config.m4 if you don't mind them // appearing in the final ./configure file // (which can help with ./configure debugging) - + // NOTE2: phpize really ought to be able to write out a sample // config.m4 based on some simple data, I'll take this up with // the php folk! @@ -442,119 +440,120 @@ public: FileErrorDisplay(configm4); SWIG_exit(EXIT_FAILURE); } - - Printf(f_extra,"dnl $Id$\n"); - Printf(f_extra,"dnl ***********************************************************************\n"); - Printf(f_extra,"dnl ** THIS config.m4 is provided for PHPIZE and PHP's consumption NOT\n"); - Printf(f_extra,"dnl ** for any part of the rest of the %s build system\n",module); - Printf(f_extra,"dnl ***********************************************************************\n\n"); - - - if (! with) { // must be enable then - Printf(f_extra,"PHP_ARG_ENABLE(%s, whether to enable %s support,\n",module,module); - Printf(f_extra,"[ --enable-%s Enable %s support])\n\n",module,module); + + Printf(f_extra, "dnl $Id$\n"); + Printf(f_extra, "dnl ***********************************************************************\n"); + Printf(f_extra, "dnl ** THIS config.m4 is provided for PHPIZE and PHP's consumption NOT\n"); + Printf(f_extra, "dnl ** for any part of the rest of the %s build system\n", module); + Printf(f_extra, "dnl ***********************************************************************\n\n"); + + + if (!with) { // must be enable then + Printf(f_extra, "PHP_ARG_ENABLE(%s, whether to enable %s support,\n", module, module); + Printf(f_extra, "[ --enable-%s Enable %s support])\n\n", module, module); } else { - Printf(f_extra,"PHP_ARG_WITH(%s, for %s support,\n",module,module); - Printf(f_extra,"[ --with-%s[=DIR] Include %s support.])\n\n",module,module); + Printf(f_extra, "PHP_ARG_WITH(%s, for %s support,\n", module, module); + Printf(f_extra, "[ --with-%s[=DIR] Include %s support.])\n\n", module, module); // These tests try and file the library we need - Printf(f_extra,"dnl THESE TESTS try and find the library and header files\n"); - Printf(f_extra,"dnl your new php module needs. YOU MAY NEED TO EDIT THEM\n"); - Printf(f_extra,"dnl as written they assume your header files are all in the same place\n\n"); - - Printf(f_extra,"dnl ** are we looking for %s_lib.h or something else?\n",module); + Printf(f_extra, "dnl THESE TESTS try and find the library and header files\n"); + Printf(f_extra, "dnl your new php module needs. YOU MAY NEED TO EDIT THEM\n"); + Printf(f_extra, "dnl as written they assume your header files are all in the same place\n\n"); + + Printf(f_extra, "dnl ** are we looking for %s_lib.h or something else?\n", module); if (withincs) - Printf(f_extra,"HNAMES=\"%s\"\n\n",withincs); + Printf(f_extra, "HNAMES=\"%s\"\n\n", withincs); else - Printf(f_extra,"HNAMES=\"\"; # %s_lib.h ?\n\n",module); - - Printf(f_extra,"dnl ** Are we looking for lib%s.a or lib%s.so or something else?\n",module,module); - + Printf(f_extra, "HNAMES=\"\"; # %s_lib.h ?\n\n", module); + + Printf(f_extra, "dnl ** Are we looking for lib%s.a or lib%s.so or something else?\n", module, module); + if (withlibs) - Printf(f_extra,"LIBNAMES=\"%s\"\n\n",withlibs); + Printf(f_extra, "LIBNAMES=\"%s\"\n\n", withlibs); else - Printf(f_extra,"LIBNAMES=\"\"; # lib%s.so ?\n\n",module); - - Printf(f_extra,"dnl IF YOU KNOW one of the symbols in the library and you\n"); - Printf(f_extra,"dnl specify it below then we can have a link test to see if it works\n"); - Printf(f_extra,"LIBSYMBOL=\"\"\n\n"); + Printf(f_extra, "LIBNAMES=\"\"; # lib%s.so ?\n\n", module); + + Printf(f_extra, "dnl IF YOU KNOW one of the symbols in the library and you\n"); + Printf(f_extra, "dnl specify it below then we can have a link test to see if it works\n"); + Printf(f_extra, "LIBSYMBOL=\"\"\n\n"); } // Now write out tests to find thing.. they may need to extend tests - Printf(f_extra,"if test \"$PHP_%s\" != \"no\"; then\n\n", cap_module); + Printf(f_extra, "if test \"$PHP_%s\" != \"no\"; then\n\n", cap_module); // Ready for when we add libraries as we find them - Printf(f_extra," PHP_SUBST(%s_SHARED_LIBADD)\n\n", cap_module); + Printf(f_extra, " PHP_SUBST(%s_SHARED_LIBADD)\n\n", cap_module); - if (withlibs) { // find more than one library - Printf(f_extra," for LIBNAME in $LIBNAMES ; do\n"); - Printf(f_extra," LIBDIR=\"\"\n"); + if (withlibs) { // find more than one library + Printf(f_extra, " for LIBNAME in $LIBNAMES ; do\n"); + Printf(f_extra, " LIBDIR=\"\"\n"); // For each path element to try... - Printf(f_extra," for i in $PHP_%s $PHP_%s/lib /usr/lib /usr/local/lib ; do\n", cap_module, cap_module); - Printf(f_extra," if test -r $i/lib$LIBNAME.a -o -r $i/lib$LIBNAME.so ; then\n"); - Printf(f_extra," LIBDIR=\"$i\"\n"); - Printf(f_extra," break\n"); - Printf(f_extra," fi\n"); - Printf(f_extra," done\n\n"); - Printf(f_extra," dnl ** and $LIBDIR should be the library path\n"); - Printf(f_extra," if test \"$LIBNAME\" != \"\" -a -z \"$LIBDIR\" ; then\n"); - Printf(f_extra," AC_MSG_RESULT(Library files $LIBNAME not found)\n"); - Printf(f_extra," AC_MSG_ERROR(Is the %s distribution installed properly?)\n",module); - Printf(f_extra," else\n"); - Printf(f_extra," AC_MSG_RESULT(Library files $LIBNAME found in $LIBDIR)\n"); - Printf(f_extra," PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBDIR, %s_SHARED_LIBADD)\n", cap_module); - Printf(f_extra," fi\n"); - Printf(f_extra," done\n\n"); + Printf(f_extra, " for i in $PHP_%s $PHP_%s/lib /usr/lib /usr/local/lib ; do\n", cap_module, cap_module); + Printf(f_extra, " if test -r $i/lib$LIBNAME.a -o -r $i/lib$LIBNAME.so ; then\n"); + Printf(f_extra, " LIBDIR=\"$i\"\n"); + Printf(f_extra, " break\n"); + Printf(f_extra, " fi\n"); + Printf(f_extra, " done\n\n"); + Printf(f_extra, " dnl ** and $LIBDIR should be the library path\n"); + Printf(f_extra, " if test \"$LIBNAME\" != \"\" -a -z \"$LIBDIR\" ; then\n"); + Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME not found)\n"); + Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module); + Printf(f_extra, " else\n"); + Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME found in $LIBDIR)\n"); + Printf(f_extra, " PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBDIR, %s_SHARED_LIBADD)\n", cap_module); + Printf(f_extra, " fi\n"); + Printf(f_extra, " done\n\n"); } - - if (withincs) { // Find more than once include - Printf(f_extra," for HNAME in $HNAMES ; do\n"); - Printf(f_extra," INCDIR=\"\"\n"); + + if (withincs) { // Find more than once include + Printf(f_extra, " for HNAME in $HNAMES ; do\n"); + Printf(f_extra, " INCDIR=\"\"\n"); // For each path element to try... - Printf(f_extra," for i in $PHP_%s $PHP_%s/include $PHP_%s/includes $PHP_%s/inc $PHP_%s/incs /usr/local/include /usr/include; do\n", cap_module, cap_module, cap_module, cap_module, cap_module); + Printf(f_extra, " for i in $PHP_%s $PHP_%s/include $PHP_%s/includes $PHP_%s/inc $PHP_%s/incs /usr/local/include /usr/include; do\n", cap_module, + cap_module, cap_module, cap_module, cap_module); // Try and find header files - Printf(f_extra," if test \"$HNAME\" != \"\" -a -r $i/$HNAME ; then\n"); - Printf(f_extra," INCDIR=\"$i\"\n"); - Printf(f_extra," break\n"); - Printf(f_extra," fi\n"); - Printf(f_extra," done\n\n"); - - Printf(f_extra," dnl ** Now $INCDIR should be the include file path\n"); - Printf(f_extra," if test \"$HNAME\" != \"\" -a -z \"$INCDIR\" ; then\n"); - Printf(f_extra," AC_MSG_RESULT(Include files $HNAME not found)\n"); - Printf(f_extra," AC_MSG_ERROR(Is the %s distribution installed properly?)\n",module); - Printf(f_extra," else\n"); - Printf(f_extra," AC_MSG_RESULT(Include files $HNAME found in $INCDIR)\n"); - Printf(f_extra," PHP_ADD_INCLUDE($INCDIR)\n"); - Printf(f_extra," fi\n\n"); - Printf(f_extra," done\n\n"); - } - - if (CPlusPlus) { - Printf(f_extra," # As this is a C++ module..\n"); - } - - Printf(f_extra," PHP_REQUIRE_CXX\n"); - Printf(f_extra," AC_CHECK_LIB(stdc++, cin)\n"); - - if (with) { - Printf(f_extra," if test \"$LIBSYMBOL\" != \"\" ; then\n"); - Printf(f_extra," old_LIBS=\"$LIBS\"\n"); - Printf(f_extra," LIBS=\"$LIBS -L$TEST_DIR/lib -lm -ldl\"\n"); - Printf(f_extra," AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_TESTLIB,1, [ ])],\n"); - Printf(f_extra," [AC_MSG_ERROR(wrong test lib version or lib not found)])\n"); - Printf(f_extra," LIBS=\"$old_LIBS\"\n"); - Printf(f_extra," fi\n\n"); + Printf(f_extra, " if test \"$HNAME\" != \"\" -a -r $i/$HNAME ; then\n"); + Printf(f_extra, " INCDIR=\"$i\"\n"); + Printf(f_extra, " break\n"); + Printf(f_extra, " fi\n"); + Printf(f_extra, " done\n\n"); + + Printf(f_extra, " dnl ** Now $INCDIR should be the include file path\n"); + Printf(f_extra, " if test \"$HNAME\" != \"\" -a -z \"$INCDIR\" ; then\n"); + Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME not found)\n"); + Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module); + Printf(f_extra, " else\n"); + Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME found in $INCDIR)\n"); + Printf(f_extra, " PHP_ADD_INCLUDE($INCDIR)\n"); + Printf(f_extra, " fi\n\n"); + Printf(f_extra, " done\n\n"); } - Printf(f_extra," AC_DEFINE(HAVE_%s, 1, [ ])\n", cap_module); - Printf(f_extra,"dnl AC_DEFINE_UNQUOTED(PHP_%s_DIR, \"$%s_DIR\", [ ])\n", cap_module, cap_module); - Printf(f_extra," PHP_EXTENSION(%s, $ext_shared)\n",module); + if (CPlusPlus) { + Printf(f_extra, " # As this is a C++ module..\n"); + } + + Printf(f_extra, " PHP_REQUIRE_CXX\n"); + Printf(f_extra, " AC_CHECK_LIB(stdc++, cin)\n"); + + if (with) { + Printf(f_extra, " if test \"$LIBSYMBOL\" != \"\" ; then\n"); + Printf(f_extra, " old_LIBS=\"$LIBS\"\n"); + Printf(f_extra, " LIBS=\"$LIBS -L$TEST_DIR/lib -lm -ldl\"\n"); + Printf(f_extra, " AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_TESTLIB,1, [ ])],\n"); + Printf(f_extra, " [AC_MSG_ERROR(wrong test lib version or lib not found)])\n"); + Printf(f_extra, " LIBS=\"$old_LIBS\"\n"); + Printf(f_extra, " fi\n\n"); + } + + Printf(f_extra, " AC_DEFINE(HAVE_%s, 1, [ ])\n", cap_module); + Printf(f_extra, "dnl AC_DEFINE_UNQUOTED(PHP_%s_DIR, \"$%s_DIR\", [ ])\n", cap_module, cap_module); + Printf(f_extra, " PHP_EXTENSION(%s, $ext_shared)\n", module); // and thats all! - Printf(f_extra,"fi\n"); - + Printf(f_extra, "fi\n"); + Close(f_extra); - + /* CREDITS */ f_extra = NewFile(credits, "w"); if (!f_extra) { @@ -573,19 +572,19 @@ public: String *filen; String *s_type; - + /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - + String *outfile = Getattr(n, "outfile"); + /* main output file */ - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); } - + Swig_banner(f_runtime); - + /* sections of the output file */ s_init = NewString("/* init section */\n"); r_init = NewString("/* rinit section */\n"); @@ -603,18 +602,19 @@ public: s_phpclasses = NewString("/* PHP Proxy Classes */\n"); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",s_init); - Swig_register_filebyname("rinit",r_init); - Swig_register_filebyname("shutdown",s_shutdown); - Swig_register_filebyname("rshutdown",r_shutdown); - Swig_register_filebyname("header",s_header); - Swig_register_filebyname("wrapper",s_wrappers); - + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", s_init); + Swig_register_filebyname("rinit", r_init); + Swig_register_filebyname("shutdown", s_shutdown); + Swig_register_filebyname("rshutdown", r_shutdown); + Swig_register_filebyname("header", s_header); + Swig_register_filebyname("wrapper", s_wrappers); + /* Set the module name */ - module = Copy(Getattr(n,"name")); - cap_module = NewStringf("%(upper)s",module); - if (!prefix) prefix = NewStringEmpty(); + module = Copy(Getattr(n, "name")); + cap_module = NewStringf("%(upper)s", module); + if (!prefix) + prefix = NewStringEmpty(); /* PHP module file */ filen = NewStringEmpty(); @@ -631,20 +631,20 @@ public: Swig_banner(f_phpcode); - Printf(f_phpcode,"// Try to load our extension if it's not already loaded.\n"); - Printf(f_phpcode,"if (!extension_loaded(\"%s\")) {\n", module); - Printf(f_phpcode," if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {\n"); - Printf(f_phpcode," if (!dl('php_%s.dll')) return;\n", module); - Printf(f_phpcode," } else {\n"); - Printf(f_phpcode," // PHP_SHLIB_SUFFIX is available as of PHP 4.3.0, for older PHP assume 'so'.\n"); - Printf(f_phpcode," // It gives 'dylib' on MacOS X which is for libraries, modules are 'so'.\n"); - Printf(f_phpcode," if (PHP_SHLIB_SUFFIX === 'PHP_SHLIB_SUFFIX' || PHP_SHLIB_SUFFIX === 'dylib') {\n"); - Printf(f_phpcode," if (!dl('%s.so')) return;\n", module); - Printf(f_phpcode," } else {\n"); - Printf(f_phpcode," if (!dl('%s.'.PHP_SHLIB_SUFFIX)) return;\n", module); - Printf(f_phpcode," }\n"); - Printf(f_phpcode," }\n"); - Printf(f_phpcode,"}\n\n"); + Printf(f_phpcode, "// Try to load our extension if it's not already loaded.\n"); + Printf(f_phpcode, "if (!extension_loaded(\"%s\")) {\n", module); + Printf(f_phpcode, " if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {\n"); + Printf(f_phpcode, " if (!dl('php_%s.dll')) return;\n", module); + Printf(f_phpcode, " } else {\n"); + Printf(f_phpcode, " // PHP_SHLIB_SUFFIX is available as of PHP 4.3.0, for older PHP assume 'so'.\n"); + Printf(f_phpcode, " // It gives 'dylib' on MacOS X which is for libraries, modules are 'so'.\n"); + Printf(f_phpcode, " if (PHP_SHLIB_SUFFIX === 'PHP_SHLIB_SUFFIX' || PHP_SHLIB_SUFFIX === 'dylib') {\n"); + Printf(f_phpcode, " if (!dl('%s.so')) return;\n", module); + Printf(f_phpcode, " } else {\n"); + Printf(f_phpcode, " if (!dl('%s.'.PHP_SHLIB_SUFFIX)) return;\n", module); + Printf(f_phpcode, " }\n"); + Printf(f_phpcode, " }\n"); + Printf(f_phpcode, "}\n\n"); /* sub-sections of the php file */ pragma_code = NewStringEmpty(); @@ -652,29 +652,29 @@ public: /* Initialize the rest of the module */ - Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, %s_destroy_globals);\n",module,module,module); - + Printf(s_oinit, "ZEND_INIT_MODULE_GLOBALS(%s, %s_init_globals, %s_destroy_globals);\n", module, module, module); + /* start the header section */ Printf(s_header, php_header); Printf(s_header, "ZEND_BEGIN_MODULE_GLOBALS(%s)\n", module); Printf(s_header, "char *error_msg;\n"); Printf(s_header, "int error_code;\n"); - Printf(s_header, "ZEND_END_MODULE_GLOBALS(%s)\n", module ); - Printf(s_header, "ZEND_DECLARE_MODULE_GLOBALS(%s)\n",module ); - Printf(s_header, "#ifdef ZTS\n" ); - Printf(s_header, "#define SWIG_ErrorMsg() TSRMG(%s_globals_id, zend_%s_globals *, error_msg )\n",module,module); - Printf(s_header, "#define SWIG_ErrorCode() TSRMG(%s_globals_id, zend_%s_globals *, error_code )\n",module,module); - Printf(s_header, "#else\n" ); - Printf(s_header, "#define SWIG_ErrorMsg() (%s_globals.error_msg)\n",module); - Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n",module); - Printf(s_header, "#endif\n\n" ); + Printf(s_header, "ZEND_END_MODULE_GLOBALS(%s)\n", module); + Printf(s_header, "ZEND_DECLARE_MODULE_GLOBALS(%s)\n", module); + Printf(s_header, "#ifdef ZTS\n"); + Printf(s_header, "#define SWIG_ErrorMsg() TSRMG(%s_globals_id, zend_%s_globals *, error_msg )\n", module, module); + Printf(s_header, "#define SWIG_ErrorCode() TSRMG(%s_globals_id, zend_%s_globals *, error_code )\n", module, module); + Printf(s_header, "#else\n"); + Printf(s_header, "#define SWIG_ErrorMsg() (%s_globals.error_msg)\n", module); + Printf(s_header, "#define SWIG_ErrorCode() (%s_globals.error_code)\n", module); + Printf(s_header, "#endif\n\n"); - Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n",module,module); + Printf(s_header, "static void %s_init_globals(zend_%s_globals *globals ) {\n", module, module); Printf(s_header, " globals->error_msg = default_error_msg;\n"); Printf(s_header, " globals->error_code = default_error_code;\n"); Printf(s_header, "}\n"); - Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n",module,module); + Printf(s_header, "static void %s_destroy_globals(zend_%s_globals * globals) { (void)globals; }\n", module, module); Printf(s_header, "\n"); Printf(s_header, "static void SWIG_ResetError() {\n"); @@ -683,21 +683,21 @@ public: Printf(s_header, " SWIG_ErrorCode() = default_error_code;\n"); Printf(s_header, "}\n"); - Printf(s_header,"#define SWIG_name \"%s\"\n", module); + Printf(s_header, "#define SWIG_name \"%s\"\n", module); /* Printf(s_header,"#ifdef HAVE_CONFIG_H\n"); - Printf(s_header,"#include \"config.h\"\n"); - Printf(s_header,"#endif\n\n"); - */ - Printf(s_header,"#ifdef __cplusplus\n"); - Printf(s_header,"extern \"C\" {\n"); - Printf(s_header,"#endif\n"); - Printf(s_header,"#include \"php.h\"\n"); - Printf(s_header,"#include \"php_ini.h\"\n"); - Printf(s_header,"#include \"ext/standard/info.h\"\n"); - Printf(s_header,"#include \"php_%s.h\"\n", module); - Printf(s_header,"#ifdef __cplusplus\n"); - Printf(s_header,"}\n"); - Printf(s_header,"#endif\n\n"); + Printf(s_header,"#include \"config.h\"\n"); + Printf(s_header,"#endif\n\n"); + */ + Printf(s_header, "#ifdef __cplusplus\n"); + Printf(s_header, "extern \"C\" {\n"); + Printf(s_header, "#endif\n"); + Printf(s_header, "#include \"php.h\"\n"); + Printf(s_header, "#include \"php_ini.h\"\n"); + Printf(s_header, "#include \"ext/standard/info.h\"\n"); + Printf(s_header, "#include \"php_%s.h\"\n", module); + Printf(s_header, "#ifdef __cplusplus\n"); + Printf(s_header, "}\n"); + Printf(s_header, "#endif\n\n"); /* Create the .h file too */ filen = NewStringEmpty(); @@ -710,77 +710,74 @@ public: Swig_banner(f_h); Printf(f_h, php_header); - + Printf(f_h, "\n\n"); - Printf(f_h, "#ifndef PHP_%s_H\n", cap_module ); - Printf(f_h, "#define PHP_%s_H\n\n", cap_module ); - Printf(f_h, "extern zend_module_entry %s_module_entry;\n", module ); - Printf(f_h, "#define phpext_%s_ptr &%s_module_entry\n\n", module, module ); - Printf(f_h, "#ifdef PHP_WIN32\n" ); - Printf(f_h, "# define PHP_%s_API __declspec(dllexport)\n", cap_module ); - Printf(f_h, "#else\n" ); - Printf(f_h, "# define PHP_%s_API\n", cap_module ); - Printf(f_h, "#endif\n\n" ); - Printf(f_h, "#ifdef ZTS\n" ); - Printf(f_h, "#include \"TSRM.h\"\n" ); - Printf(f_h, "#endif\n\n" ); - Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module ); - Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module ); - Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module ); - Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module ); - Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module ); - + Printf(f_h, "#ifndef PHP_%s_H\n", cap_module); + Printf(f_h, "#define PHP_%s_H\n\n", cap_module); + Printf(f_h, "extern zend_module_entry %s_module_entry;\n", module); + Printf(f_h, "#define phpext_%s_ptr &%s_module_entry\n\n", module, module); + Printf(f_h, "#ifdef PHP_WIN32\n"); + Printf(f_h, "# define PHP_%s_API __declspec(dllexport)\n", cap_module); + Printf(f_h, "#else\n"); + Printf(f_h, "# define PHP_%s_API\n", cap_module); + Printf(f_h, "#endif\n\n"); + Printf(f_h, "#ifdef ZTS\n"); + Printf(f_h, "#include \"TSRM.h\"\n"); + Printf(f_h, "#endif\n\n"); + Printf(f_h, "PHP_MINIT_FUNCTION(%s);\n", module); + Printf(f_h, "PHP_MSHUTDOWN_FUNCTION(%s);\n", module); + Printf(f_h, "PHP_RINIT_FUNCTION(%s);\n", module); + Printf(f_h, "PHP_RSHUTDOWN_FUNCTION(%s);\n", module); + Printf(f_h, "PHP_MINFO_FUNCTION(%s);\n\n", module); + /* start the function entry section */ s_entry = NewString("/* entry subsection */\n"); /* holds all the per-class function entry sections */ all_cs_entry = NewString("/* class entry subsection */\n"); cs_entry = NULL; - - Printf(s_entry,"/* Every non-class user visible function must have an entry here */\n"); - Printf(s_entry,"static function_entry %s_functions[] = {\n", module); - + + Printf(s_entry, "/* Every non-class user visible function must have an entry here */\n"); + Printf(s_entry, "static function_entry %s_functions[] = {\n", module); + /* start the init section */ - Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" - "#if ZEND_MODULE_API_NO > 20010900\n" - " STANDARD_MODULE_HEADER,\n" - "#endif\n", NIL); + Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n" "#if ZEND_MODULE_API_NO > 20010900\n" " STANDARD_MODULE_HEADER,\n" "#endif\n", NIL); Printf(s_init, " \"%s\",\n", module); Printf(s_init, " %s_functions,\n", module); Printf(s_init, " PHP_MINIT(%s),\n", module); Printf(s_init, " PHP_MSHUTDOWN(%s),\n", module); Printf(s_init, " PHP_RINIT(%s),\n", module); Printf(s_init, " PHP_RSHUTDOWN(%s),\n", module); - Printf(s_init, " PHP_MINFO(%s),\n",module); + Printf(s_init, " PHP_MINFO(%s),\n", module); Printf(s_init, "#if ZEND_MODULE_API_NO > 20010900\n"); Printf(s_init, " NO_VERSION_YET,\n"); Printf(s_init, "#endif\n"); Printf(s_init, " STANDARD_MODULE_PROPERTIES\n"); Printf(s_init, "};\n"); - Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n",module); + Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module); if (gen_extra) { - Printf(s_init,"#ifdef COMPILE_DL_%s\n", cap_module); + Printf(s_init, "#ifdef COMPILE_DL_%s\n", cap_module); } - Printf(s_init,"#ifdef __cplusplus\n"); - Printf(s_init,"extern \"C\" {\n"); - Printf(s_init,"#endif\n"); + Printf(s_init, "#ifdef __cplusplus\n"); + Printf(s_init, "extern \"C\" {\n"); + Printf(s_init, "#endif\n"); // We want to write "SWIGEXPORT ZEND_GET_MODULE(%s)" but ZEND_GET_MODULE // in PHP5 has "extern "C" { ... }" around it so we can't do that. - Printf(s_init,"SWIGEXPORT zend_module_entry *get_module(void) { return &%s_module_entry; }\n", module); - Printf(s_init,"#ifdef __cplusplus\n"); - Printf(s_init,"}\n"); - Printf(s_init,"#endif\n\n"); + Printf(s_init, "SWIGEXPORT zend_module_entry *get_module(void) { return &%s_module_entry; }\n", module); + Printf(s_init, "#ifdef __cplusplus\n"); + Printf(s_init, "}\n"); + Printf(s_init, "#endif\n\n"); if (gen_extra) { - Printf(s_init,"#endif\n\n"); + Printf(s_init, "#endif\n\n"); } - + /* We have to register the constants before they are (possibly) used * by the pointer typemaps. This all needs re-arranging really as * things are being called in the wrong order */ - Printf(s_init,"#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module); + Printf(s_init, "#define SWIG_php_minit PHP_MINIT_FUNCTION(%s)\n", module); /* Emit all of the code */ Language::top(n); @@ -794,16 +791,16 @@ public: /* Constants generated during top call */ Printf(s_cinit, "/* end cinit subsection */\n"); - Printf(s_init,"%s\n",s_cinit); + Printf(s_init, "%s\n", s_cinit); Clear(s_cinit); Delete(s_cinit); Printf(s_init, " return SUCCESS;\n"); - Printf(s_init,"}\n\n"); + Printf(s_init, "}\n\n"); // Now do REQUEST init which holds any user specified %rinit, and also vinit - Printf(s_init,"PHP_RINIT_FUNCTION(%s)\n{\n",module); - Printf(s_init,"%s\n",r_init); + Printf(s_init, "PHP_RINIT_FUNCTION(%s)\n{\n", module); + Printf(s_init, "%s\n", r_init); /* finish our init section which will have been used by class wrappers */ Printf(s_vinit, "/* end vinit subsection */\n"); @@ -811,45 +808,43 @@ public: Clear(s_vinit); Delete(s_vinit); - Printf(s_init," return SUCCESS;\n"); - Printf(s_init,"}\n\n"); + Printf(s_init, " return SUCCESS;\n"); + Printf(s_init, "}\n\n"); - Printf(s_init,"PHP_MSHUTDOWN_FUNCTION(%s)\n{\n",module); - Printf(s_init,"%s\n",s_shutdown); - Printf(s_init," return SUCCESS;\n"); - Printf(s_init,"}\n\n"); + Printf(s_init, "PHP_MSHUTDOWN_FUNCTION(%s)\n{\n", module); + Printf(s_init, "%s\n", s_shutdown); + Printf(s_init, " return SUCCESS;\n"); + Printf(s_init, "}\n\n"); - Printf(s_init,"PHP_RSHUTDOWN_FUNCTION(%s)\n{\n",module); - Printf(s_init,"%s\n",r_shutdown); - Printf(s_init," return SUCCESS;\n"); - Printf(s_init,"}\n\n"); + Printf(s_init, "PHP_RSHUTDOWN_FUNCTION(%s)\n{\n", module); + Printf(s_init, "%s\n", r_shutdown); + Printf(s_init, " return SUCCESS;\n"); + Printf(s_init, "}\n\n"); - Printf(s_init,"PHP_MINFO_FUNCTION(%s)\n{\n",module); - Printf(s_init,"%s", pragma_phpinfo); - Printf(s_init,"}\n"); - Printf(s_init,"/* end init section */\n"); + Printf(s_init, "PHP_MINFO_FUNCTION(%s)\n{\n", module); + Printf(s_init, "%s", pragma_phpinfo); + Printf(s_init, "}\n"); + Printf(s_init, "/* end init section */\n"); - Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module); + Printf(f_h, "#endif /* PHP_%s_H */\n", cap_module); Close(f_h); String *type_table = NewStringEmpty(); - SwigType_emit_type_table(f_runtime,type_table); - Printf(s_header,"%s",type_table); + SwigType_emit_type_table(f_runtime, type_table); + Printf(s_header, "%s", type_table); Delete(type_table); /* Oh dear, more things being called in the wrong order. This whole * function really needs totally redoing. */ - + Printf(s_header, "/* end header section */\n"); Printf(s_wrappers, "/* end wrapper section */\n"); Printf(s_vdecl, "/* end vdecl subsection */\n"); - + Printv(f_runtime, s_header, s_vdecl, s_wrappers, NIL); - Printv(f_runtime, all_cs_entry, "\n\n", - s_entry, - "{NULL, NULL, NULL}\n};\n\n", NIL); + Printv(f_runtime, all_cs_entry, "\n\n", s_entry, "{NULL, NULL, NULL}\n};\n\n", NIL); Printv(f_runtime, s_init, NIL); Delete(s_header); Delete(s_wrappers); @@ -870,13 +865,12 @@ public: Printf(f_phpcode, "%s\n?>\n", s_phpclasses); Close(f_phpcode); - if ( gen_extra ) { + if (gen_extra) { create_extra_files(outfile); - } - else if( gen_make ) { + } else if (gen_make) { create_simple_make(); } - + return SWIG_OK; } @@ -884,13 +878,14 @@ public: void create_command(String *cname, String *iname) { // This is for the single main function_entry record if (shadow && php_version == 4) { - if (wrapperType != standard) return; + if (wrapperType != standard) + return; } Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", iname); if (cs_entry) { - Printf(cs_entry," ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname); + Printf(cs_entry, " ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname); } else { - Printf(s_entry," ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname); + Printf(s_entry, " ZEND_NAMED_FE(%(lower)s,%s,NULL)\n", cname, iname); } } @@ -902,45 +897,44 @@ public: int maxargs; String *tmp = NewStringEmpty(); - String *dispatch = Swig_overload_dispatch(n,"return %s(INTERNAL_FUNCTION_PARAM_PASSTHRU);",&maxargs); + String *dispatch = Swig_overload_dispatch(n, "return %s(INTERNAL_FUNCTION_PARAM_PASSTHRU);", &maxargs); - int has_this_ptr = (wrapperType==memberfn && shadow && php_version == 4); + int has_this_ptr = (wrapperType == memberfn && shadow && php_version == 4); /* Generate a dispatch wrapper for all overloaded functions */ - - Wrapper *f = NewWrapper(); - String *symname = Getattr(n,"sym:name"); - String *wname = Swig_name_wrapper(symname); - - create_command( symname, wname ); - Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL ); - - Wrapper_add_local(f,"argc","int argc"); - Printf(tmp,"zval **argv[%d]", maxargs); - Wrapper_add_local(f,"argv",tmp); + Wrapper *f = NewWrapper(); + String *symname = Getattr(n, "sym:name"); + String *wname = Swig_name_wrapper(symname); - Printf(f->code,"argc = ZEND_NUM_ARGS();\n"); + create_command(symname, wname); + Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL); - if ( has_this_ptr ) { - Printf(f->code,"argv[0] = &this_ptr;\n"); - Printf(f->code,"zend_get_parameters_array_ex(argc,argv+1);\n"); - Printf(f->code,"argc++;\n"); - } - else { - Printf(f->code,"zend_get_parameters_array_ex(argc,argv);\n"); + Wrapper_add_local(f, "argc", "int argc"); + + Printf(tmp, "zval **argv[%d]", maxargs); + Wrapper_add_local(f, "argv", tmp); + + Printf(f->code, "argc = ZEND_NUM_ARGS();\n"); + + if (has_this_ptr) { + Printf(f->code, "argv[0] = &this_ptr;\n"); + Printf(f->code, "zend_get_parameters_array_ex(argc,argv+1);\n"); + Printf(f->code, "argc++;\n"); + } else { + Printf(f->code, "zend_get_parameters_array_ex(argc,argv);\n"); } - Replaceall(dispatch,"$args","self,args"); + Replaceall(dispatch, "$args", "self,args"); - Printv(f->code,dispatch,"\n",NIL); + Printv(f->code, dispatch, "\n", NIL); - Printf(f->code,"SWIG_ErrorCode() = E_ERROR;\n"); - Printf(f->code,"SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname); - Printv(f->code,"zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());\n",NIL); + Printf(f->code, "SWIG_ErrorCode() = E_ERROR;\n"); + Printf(f->code, "SWIG_ErrorMsg() = \"No matching function for overloaded '%s'\";\n", symname); + Printv(f->code, "zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());\n", NIL); - Printv(f->code,"}\n",NIL); - Wrapper_print(f,s_wrappers); + Printv(f->code, "}\n", NIL); + Wrapper_print(f, s_wrappers); DelWrapper(f); Delete(dispatch); @@ -956,29 +950,31 @@ public: bool is_class(SwigType *t) { Node *n = classLookup(t); if (n) { - String *r = Getattr(n,"php:proxy"); // Set by classDeclaration() - if (!r) r = Getattr(n,"sym:name"); // Not seen by classDeclaration yet, but this is the name - if (r) return true; + String *r = Getattr(n, "php:proxy"); // Set by classDeclaration() + if (!r) + r = Getattr(n, "sym:name"); // Not seen by classDeclaration yet, but this is the name + if (r) + return true; } return false; } virtual int functionWrapper(Node *n) { - String *name = GetChar(n,"name"); - String *iname = GetChar(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *name = GetChar(n, "name"); + String *iname = GetChar(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); String *nodeType = Getattr(n, "nodeType"); - int newobject = GetFlag(n,"feature:new"); + int newobject = GetFlag(n, "feature:new"); Parm *p; - int i,numopt; + int i, numopt; String *tm; Wrapper *f; - bool mvr=(shadow && php_version == 4 && wrapperType == membervar); - bool mvrset=(mvr && (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name)))==0) ); + bool mvr = (shadow && php_version == 4 && wrapperType == membervar); + bool mvrset = (mvr && (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name))) == 0)); - String * wname; + String *wname; int overloaded = 0; String *overname = 0; @@ -988,77 +984,74 @@ public: // just do `$obj = null;' to remove a reference to an object. return CreateZendListDestructor(n); } - // Test for overloading; - if (Getattr(n,"sym:overloaded")) { + if (Getattr(n, "sym:overloaded")) { overloaded = 1; - overname = Getattr(n,"sym:overname"); + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) - return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } wname = Swig_name_wrapper(iname); if (overname) { Printf(wname, "%s", overname); } - // if PHP4, shadow and variable wrapper we want to snag the main contents // of this function to stick in to the property handler... if (mvr) { String *php_function_name = NewString(iname); - if (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name)))== 0) { - Setattr(shadow_set_vars, php_function_name, name); + if (Strcmp(iname, Swig_name_set(Swig_name_member(shadow_classname, name))) == 0) { + Setattr(shadow_set_vars, php_function_name, name); } if (Strcmp(iname, Swig_name_get(Swig_name_member(shadow_classname, name))) == 0) { - Setattr(shadow_get_vars, php_function_name, name); + Setattr(shadow_get_vars, php_function_name, name); } Delete(php_function_name); } - f = NewWrapper(); + f = NewWrapper(); numopt = 0; String *outarg = NewStringEmpty(); String *cleanup = NewStringEmpty(); - if (mvr) { // do prop[gs]et header + if (mvr) { // do prop[gs]et header if (mvrset) { - Printf(f->def, "static int _wrap_%s(zend_property_reference *property_reference, pval *value) {\n",iname); - } - else { - Printf(f->def, "static pval _wrap_%s(zend_property_reference *property_reference) {\n",iname); + Printf(f->def, "static int _wrap_%s(zend_property_reference *property_reference, pval *value) {\n", iname); + } else { + Printf(f->def, "static pval _wrap_%s(zend_property_reference *property_reference) {\n", iname); } } else { // regular header // Not issued for overloaded functions or static member variables. - if (!overloaded && wrapperType != staticmembervar ) { - create_command(iname, wname); + if (!overloaded && wrapperType != staticmembervar) { + create_command(iname, wname); } - Printv(f->def, "ZEND_NAMED_FUNCTION(" , wname, ") {\n", NIL); + Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL); } emit_args(d, l, f); /* Attach standard typemaps */ - emit_attach_parmmaps(l,f); + emit_attach_parmmaps(l, f); // wrap:parms is used by overload resolution. - Setattr(n,"wrap:parms",l); + Setattr(n, "wrap:parms", l); int num_arguments = emit_num_arguments(l); - int num_required = emit_num_required(l); + int num_required = emit_num_required(l); numopt = num_arguments - num_required; - int has_this_ptr = (wrapperType==memberfn && shadow && php_version == 4); + int has_this_ptr = (wrapperType == memberfn && shadow && php_version == 4); - if (num_arguments-has_this_ptr > 0) { - String * args = NewStringf("zval **args[%d]", num_arguments-has_this_ptr); - Wrapper_add_local(f, "args",args); - Delete(args); args = NULL; + if (num_arguments - has_this_ptr > 0) { + String *args = NewStringf("zval **args[%d]", num_arguments - has_this_ptr); + Wrapper_add_local(f, "args", args); + Delete(args); + args = NULL; } - // This generated code may be called: // 1) as an object method, or // 2) as a class-method/function (without a "this_ptr") @@ -1073,32 +1066,30 @@ public: Printf(f->code, "/* This function uses a this_ptr*/\n"); if (native_constructor) { - if (native_constructor==NATIVE_CONSTRUCTOR) { - Printf(f->code, "/* NATIVE Constructor */\n"); - } - else { - Printf(f->code, "/* ALTERNATIVE Constructor */\n"); + if (native_constructor == NATIVE_CONSTRUCTOR) { + Printf(f->code, "/* NATIVE Constructor */\n"); + } else { + Printf(f->code, "/* ALTERNATIVE Constructor */\n"); } } - if (mvr && ! mvrset) { + if (mvr && !mvrset) { Wrapper_add_local(f, "_return_value", "zval _return_value"); Wrapper_add_local(f, "return_value", "zval *return_value=&_return_value"); } - if(numopt > 0) { // membervariable wrappers do not have optional args + if (numopt > 0) { // membervariable wrappers do not have optional args Wrapper_add_local(f, "arg_count", "int arg_count"); - Printf(f->code,"arg_count = ZEND_NUM_ARGS();\n"); - Printf(f->code,"if(arg_count<%d || arg_count>%d ||\n",num_required, num_arguments); - Printf(f->code," zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)\n"); - Printf(f->code,"\tWRONG_PARAM_COUNT;\n\n"); + Printf(f->code, "arg_count = ZEND_NUM_ARGS();\n"); + Printf(f->code, "if(arg_count<%d || arg_count>%d ||\n", num_required, num_arguments); + Printf(f->code, " zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)\n"); + Printf(f->code, "\tWRONG_PARAM_COUNT;\n\n"); } else if (!mvr) { int num = num_arguments - has_this_ptr; if (num == 0) { Printf(f->code, "if(ZEND_NUM_ARGS() != 0) {\n"); } else { - Printf(f->code, "if(ZEND_NUM_ARGS() != %d || zend_get_parameters_array_ex(%d, args) != SUCCESS) {\n", - num, num); + Printf(f->code, "if(ZEND_NUM_ARGS() != %d || zend_get_parameters_array_ex(%d, args) != SUCCESS) {\n", num, num); } Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n"); } @@ -1114,206 +1105,200 @@ public: // This may mean looking at Language::memberfunctionHandler for (i = 0, p = l; i < num_arguments; i++) { - String * source; + String *source; /* Skip ignored arguments */ //while (Getattr(p,"tmap:ignore")) { p = Getattr(p,"tmap:ignore:next");} - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); + SwigType *pt = Getattr(p, "type"); - if (mvr) { // do we assert that numargs=2, that i<2 - if (i==0) { - source = NewString("&(property_reference->object)"); - } - else { - source = NewString("&value"); - } + if (mvr) { // do we assert that numargs=2, that i<2 + if (i == 0) { + source = NewString("&(property_reference->object)"); + } else { + source = NewString("&value"); + } } else { - if (i==0 && has_this_ptr) { - source = NewString("&this_ptr"); - } else { - source = NewStringf("args[%d]", i-has_this_ptr); - } + if (i == 0 && has_this_ptr) { + source = NewString("&this_ptr"); + } else { + source = NewStringf("args[%d]", i - has_this_ptr); + } } - String *ln = Getattr(p,"lname"); + String *ln = Getattr(p, "lname"); /* Check if optional */ - if(i >= num_required) { - Printf(f->code,"\tif(arg_count > %d) {\n", i); + if (i >= num_required) { + Printf(f->code, "\tif(arg_count > %d) {\n", i); } - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$source", source); - Replaceall(tm,"$target", ln); - Replaceall(tm,"$input", source); - Setattr(p,"emit:input", source); - Printf(f->code,"%s\n",tm); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + Printf(f->code, "%s\n", tm); if (i == 0 && HashGetAttr(p, k_self)) { - Printf(f->code,"\tif(!arg1) SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");\n"); + Printf(f->code, "\tif(!arg1) SWIG_PHP_Error(E_ERROR, \"this pointer is NULL\");\n"); } - p = Getattr(p,"tmap:in:next"); - if (i >= num_required) { - Printf(f->code,"}\n"); - } - continue; + p = Getattr(p, "tmap:in:next"); + if (i >= num_required) { + Printf(f->code, "}\n"); + } + continue; } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n", - SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); } - if (i>= num_required) { - Printf(f->code,"\t}\n"); + if (i >= num_required) { + Printf(f->code, "\t}\n"); } Delete(source); } - + /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } /* Insert cleanup code */ for (i = 0, p = l; p; i++) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } - + /* Insert argument output code */ - for (i=0,p = l; p;i++) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - // Replaceall(tm,"$input",Getattr(p,"lname")); - Replaceall(tm,"$target","return_value"); - Replaceall(tm,"$result","return_value"); - Replaceall(tm,"$arg", Getattr(p,"emit:input")); - Replaceall(tm,"$input", Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + for (i = 0, p = l; p; i++) { + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + // Replaceall(tm,"$input",Getattr(p,"lname")); + Replaceall(tm, "$target", "return_value"); + Replaceall(tm, "$result", "return_value"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { - p = nextSibling(p); + p = nextSibling(p); } } - - /* emit function call*/ - emit_action(n,f); - - if((tm = Swig_typemap_lookup_new("out",n,"result",0))) { + + /* emit function call */ + emit_action(n, f); + + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { Replaceall(tm, "$input", "result"); Replaceall(tm, "$source", "result"); Replaceall(tm, "$target", "return_value"); Replaceall(tm, "$result", "return_value"); - Replaceall(tm,"$owner", newobject ? "1" : "0"); + Replaceall(tm, "$owner", newobject ? "1" : "0"); Printf(f->code, "%s\n", tm); // are we returning a wrapable object? // I don't know if this test is complete, I nicked it - if(is_shadow(d) && (SwigType_type(d) != T_ARRAY)) { - Printf(f->code,"/* Wrap this return value */\n"); - if (native_constructor==NATIVE_CONSTRUCTOR) { - Printf(f->code, "if (this_ptr) {\n"); - Printf(f->code, "/* NATIVE Constructor, use this_ptr */\n"); - Printf(f->code, "zval *_cPtr; MAKE_STD_ZVAL(_cPtr);\n"); - Printf(f->code, "*_cPtr = *return_value;\n"); - Printf(f->code, "INIT_ZVAL(*return_value);\n"); - Printf(f->code, "add_property_zval(this_ptr,\""SWIG_PTR"\",_cPtr);\n"); - Printf(f->code, "} else if (! this_ptr) "); - } - { // THIS CODE only really needs writing out if the object to be returned - // Is being shadow-wrap-thingied - Printf(f->code, "{\n/* ALTERNATIVE Constructor, make an object wrapper */\n"); - // Make object - String *shadowrettype = NewStringEmpty(); - SwigToPhpType(d, iname, shadowrettype, (shadow && php_version == 4)); + if (is_shadow(d) && (SwigType_type(d) != T_ARRAY)) { + Printf(f->code, "/* Wrap this return value */\n"); + if (native_constructor == NATIVE_CONSTRUCTOR) { + Printf(f->code, "if (this_ptr) {\n"); + Printf(f->code, "/* NATIVE Constructor, use this_ptr */\n"); + Printf(f->code, "zval *_cPtr; MAKE_STD_ZVAL(_cPtr);\n"); + Printf(f->code, "*_cPtr = *return_value;\n"); + Printf(f->code, "INIT_ZVAL(*return_value);\n"); + Printf(f->code, "add_property_zval(this_ptr,\"" SWIG_PTR "\",_cPtr);\n"); + Printf(f->code, "} else if (! this_ptr) "); + } + { // THIS CODE only really needs writing out if the object to be returned + // Is being shadow-wrap-thingied + Printf(f->code, "{\n/* ALTERNATIVE Constructor, make an object wrapper */\n"); + // Make object + String *shadowrettype = NewStringEmpty(); + SwigToPhpType(d, iname, shadowrettype, (shadow && php_version == 4)); - Printf(f->code,"zval *obj, *_cPtr;\n"); - Printf(f->code,"MAKE_STD_ZVAL(obj);\n"); - Printf(f->code,"MAKE_STD_ZVAL(_cPtr);\n"); - Printf(f->code,"*_cPtr = *return_value;\n"); - Printf(f->code,"INIT_ZVAL(*return_value);\n"); + Printf(f->code, "zval *obj, *_cPtr;\n"); + Printf(f->code, "MAKE_STD_ZVAL(obj);\n"); + Printf(f->code, "MAKE_STD_ZVAL(_cPtr);\n"); + Printf(f->code, "*_cPtr = *return_value;\n"); + Printf(f->code, "INIT_ZVAL(*return_value);\n"); - if (shadow && php_version == 4) { - Printf(f->code,"object_init_ex(obj,ptr_ce_swig_%s);\n",shadowrettype); - Printf(f->code,"add_property_zval(obj,\""SWIG_PTR"\",_cPtr);\n"); - Printf(f->code,"*return_value=*obj;\n"); - } else { - Printf(f->code,"*return_value=*_cPtr;\n"); - } - Printf(f->code, "}\n"); - } - } // end of if-shadow lark + if (shadow && php_version == 4) { + Printf(f->code, "object_init_ex(obj,ptr_ce_swig_%s);\n", shadowrettype); + Printf(f->code, "add_property_zval(obj,\"" SWIG_PTR "\",_cPtr);\n"); + Printf(f->code, "*return_value=*obj;\n"); + } else { + Printf(f->code, "*return_value=*_cPtr;\n"); + } + Printf(f->code, "}\n"); + } + } // end of if-shadow lark } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", - SwigType_str(d,0), name); - } - - if(outarg) { - Printv(f->code,outarg,NIL); - } - - if(cleanup) { - Printv(f->code,cleanup,NIL); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } + if (outarg) { + Printv(f->code, outarg, NIL); + } + + if (cleanup) { + Printv(f->code, cleanup, NIL); + } // What's this bit for? - if((tm = Swig_typemap_lookup_new("ret",n,"result",0))) { - Printf(f->code,"%s\n", tm); + if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { + Printf(f->code, "%s\n", tm); } if (mvr) { - if (! mvrset) { - Printf(f->code,"return _return_value;\n"); + if (!mvrset) { + Printf(f->code, "return _return_value;\n"); + } else { + Printf(f->code, "return SUCCESS;\n"); } - else{ - Printf(f->code,"return SUCCESS;\n"); - } - } - else { - Printf(f->code,"return;\n"); + } else { + Printf(f->code, "return;\n"); } /* Error handling code */ - Printf(f->code,"fail:\n"); - Printv(f->code,cleanup,NIL); - Printv(f->code,"zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());",NIL); + Printf(f->code, "fail:\n"); + Printv(f->code, cleanup, NIL); + Printv(f->code, "zend_error(SWIG_ErrorCode(),SWIG_ErrorMsg());", NIL); Printf(f->code, "}\n"); - Replaceall(f->code,"$cleanup",cleanup); - Replaceall(f->code,"$symname",iname); + Replaceall(f->code, "$cleanup", cleanup); + Replaceall(f->code, "$symname", iname); - Wrapper_print(f,s_wrappers); + Wrapper_print(f, s_wrappers); // wrap:name is used by overload resolution - Setattr(n,"wrap:name",wname); - if (overloaded && !Getattr(n,"sym:nextSibling")) { + Setattr(n, "wrap:name", wname); + if (overloaded && !Getattr(n, "sym:nextSibling")) { dispatchFunction(n); } - Delete(wname); wname = NULL; + Delete(wname); + wname = NULL; - if (!(shadow && php_version == 5)) return SWIG_OK; + if (!(shadow && php_version == 5)) + return SWIG_OK; // Handle getters and setters. if (wrapperType == membervar) { - const char * p = Char(iname); + const char *p = Char(iname); if (strlen(p) > 4) { p += strlen(p) - 4; - String * varname = Getattr(n, "membervariableHandler:sym:name"); + String *varname = Getattr(n, "membervariableHandler:sym:name"); if (strcmp(p, "_get") == 0) { Setattr(shadow_get_vars, varname, iname); } else if (strcmp(p, "_set") == 0) { @@ -1321,21 +1306,22 @@ public: } } } - // Only look at non-overloaded methods and the last entry in each overload // chain (we check the last so that wrap:parms and wrap:name have been set // for them all). - if (overloaded && Getattr(n,"sym:nextSibling") != 0) return SWIG_OK; + if (overloaded && Getattr(n, "sym:nextSibling") != 0) + return SWIG_OK; - if (!s_oowrappers) s_oowrappers = NewStringEmpty(); + if (!s_oowrappers) + s_oowrappers = NewStringEmpty(); if (newobject || wrapperType == memberfn || wrapperType == staticmemberfn || wrapperType == standard) { bool handle_as_overload = false; - String ** arg_names; - String ** arg_values; - bool * arg_case = NULL; + String **arg_names; + String **arg_values; + bool *arg_case = NULL; // Method or static method or plain function. - const char * methodname = 0; - String * output = s_oowrappers; + const char *methodname = 0; + String *output = s_oowrappers; if (newobject) { class_has_ctor = true; methodname = "__construct"; @@ -1343,9 +1329,10 @@ public: methodname = Char(Getattr(n, "memberfunctionHandler:sym:name")); } else if (wrapperType == staticmemberfn) { methodname = Char(Getattr(n, "staticmemberfunctionHandler:sym:name")); - } else { // wrapperType == standard + } else { // wrapperType == standard methodname = Char(iname); - if (!s_fakeoowrappers) s_fakeoowrappers = NewStringEmpty(); + if (!s_fakeoowrappers) + s_fakeoowrappers = NewStringEmpty(); output = s_fakeoowrappers; } @@ -1354,18 +1341,18 @@ public: int max_num_of_arguments = emit_num_arguments(l); // For a function with default arguments, we end up with the fullest // parmlist in full_parmlist. - ParmList * full_parmlist = l; - Hash * ret_types = NewHash(); + ParmList *full_parmlist = l; + Hash *ret_types = NewHash(); Setattr(ret_types, d, d); if (overloaded) { // Look at all the overloaded versions of this method in turn to // decide if it's really an overloaded method, or just one where some // parameters have default values. - Node * o = Getattr(n, "sym:overloaded"); + Node *o = Getattr(n, "sym:overloaded"); while (o) { if (o == n) { - o = Getattr(o,"sym:nextSibling"); + o = Getattr(o, "sym:nextSibling"); continue; } @@ -1376,9 +1363,9 @@ public: Setattr(ret_types, d2, d2); } - ParmList *l2 = Getattr(o,"wrap:parms"); + ParmList *l2 = Getattr(o, "wrap:parms"); int num_arguments = emit_num_arguments(l2); - int num_required = emit_num_required(l2); + int num_required = emit_num_required(l2); if (num_required < min_num_of_arguments) min_num_of_arguments = num_required; @@ -1386,53 +1373,63 @@ public: max_num_of_arguments = num_arguments; full_parmlist = l2; } - o = Getattr(o,"sym:nextSibling"); + o = Getattr(o, "sym:nextSibling"); } o = Getattr(n, "sym:overloaded"); while (o) { if (o == n) { - o = Getattr(o,"sym:nextSibling"); + o = Getattr(o, "sym:nextSibling"); continue; } - ParmList *l2 = Getattr(o,"wrap:parms"); - Parm * p = l, * p2 = l2; + ParmList *l2 = Getattr(o, "wrap:parms"); + Parm *p = l, *p2 = l2; if (wrapperType == memberfn) { p = nextSibling(p); p2 = nextSibling(p2); } while (p && p2) { - if (Cmp(Getattr(p, "type"), Getattr(p2, "type")) != 0) break; - if (Cmp(Getattr(p, "name"), Getattr(p2, "name")) != 0) break; + if (Cmp(Getattr(p, "type"), Getattr(p2, "type")) != 0) + break; + if (Cmp(Getattr(p, "name"), Getattr(p2, "name")) != 0) + break; String *value = Getattr(p, "value"); String *value2 = Getattr(p2, "value"); - if (value && !value2) break; - if (!value && value2) break; + if (value && !value2) + break; + if (!value && value2) + break; if (value) { - if (Cmp(value, value2) != 0) break; + if (Cmp(value, value2) != 0) + break; } p = nextSibling(p); p2 = nextSibling(p2); } - if (p && p2) break; + if (p && p2) + break; // One parameter list is a prefix of the other, so check that all // remaining parameters of the longer list are optional. - if (p2) p = p2; - while (p && Getattr(p, "value")) p = nextSibling(p); - if (p) break; - o = Getattr(o,"sym:nextSibling"); + if (p2) + p = p2; + while (p && Getattr(p, "value")) + p = nextSibling(p); + if (p) + break; + o = Getattr(o, "sym:nextSibling"); } if (!o) { // This "overloaded method" is really just one with default args. really_overloaded = false; if (l != full_parmlist) { l = full_parmlist; - if (wrapperType == memberfn) l = nextSibling(l); + if (wrapperType == memberfn) + l = nextSibling(l); } } - arg_case = (bool*)malloc(max_num_of_arguments * sizeof(bool)); + arg_case = (bool *) malloc(max_num_of_arguments * sizeof(bool)); if (!arg_case) { /* FIXME: How should this be handled? The rest of SWIG just seems * to not bother checking for malloc failing! */ @@ -1445,9 +1442,9 @@ public: o = Getattr(n, "sym:overloaded"); while (o) { - ParmList *l2 = Getattr(o,"wrap:parms"); + ParmList *l2 = Getattr(o, "wrap:parms"); int num_arguments = emit_num_arguments(l2); - int num_required = emit_num_required(l2); + int num_required = emit_num_required(l2); if (wrapperType == memberfn) { --num_arguments; --num_required; @@ -1455,7 +1452,7 @@ public: for (int i = num_required; i <= num_arguments; ++i) { arg_case[i] = true; } - o = Getattr(o,"sym:nextSibling"); + o = Getattr(o, "sym:nextSibling"); } } @@ -1465,7 +1462,7 @@ public: --max_num_of_arguments; } - arg_names = (String**)malloc(max_num_of_arguments * sizeof(String *)); + arg_names = (String **) malloc(max_num_of_arguments * sizeof(String *)); if (!arg_names) { /* FIXME: How should this be handled? The rest of SWIG just seems * to not bother checking for malloc failing! */ @@ -1476,7 +1473,7 @@ public: arg_names[i] = NULL; } - arg_values = (String**)malloc(max_num_of_arguments * sizeof(String *)); + arg_values = (String **) malloc(max_num_of_arguments * sizeof(String *)); if (!arg_values) { /* FIXME: How should this be handled? The rest of SWIG just seems * to not bother checking for malloc failing! */ @@ -1487,7 +1484,7 @@ public: arg_values[i] = NULL; } - Node * o; + Node *o; if (overloaded) { o = Getattr(n, "sym:overloaded"); } else { @@ -1496,10 +1493,11 @@ public: while (o) { int argno = 0; Parm *p = Getattr(o, "wrap:parms"); - if (wrapperType == memberfn) p = nextSibling(p); + if (wrapperType == memberfn) + p = nextSibling(p); while (p) { assert(0 <= argno && argno < max_num_of_arguments); - String * & pname = arg_names[argno]; + String *&pname = arg_names[argno]; const char *pname_cstr = GetChar(p, "name"); if (!pname_cstr) { // Unnamed parameter, e.g. int foo(int); @@ -1511,28 +1509,29 @@ public: size_t len_pname = strlen(Char(pname)); while (spc + len <= len_pname) { if (strncmp(pname_cstr, Char(pname) + spc, len) == 0) { - char ch = ((char*)Char(pname))[spc + len]; + char ch = ((char *) Char(pname))[spc + len]; if (ch == '\0' || ch == ' ') { // Already have this pname_cstr. pname_cstr = NULL; break; } } - char * p = strchr(Char(pname) + spc, ' '); - if (!p) break; + char *p = strchr(Char(pname) + spc, ' '); + if (!p) + break; spc = (p + 4) - Char(pname); } if (pname_cstr) { Printf(pname, " or_%s", pname_cstr); } } - const char *value = GetChar(p,"value"); + const char *value = GetChar(p, "value"); if (value) { /* Check that value is a valid constant in PHP (and adjust it if * necessary, or replace it with "?" if it's just not valid). */ - SwigType *type = Getattr(p,"type"); + SwigType *type = Getattr(p, "type"); switch (SwigType_type(type)) { - case T_BOOL: { + case T_BOOL:{ if (strcmp(value, "true") == 0 || strcmp(value, "false") == 0) break; char *p; @@ -1546,56 +1545,60 @@ public: value = "false"; break; } - case T_CHAR: - case T_SCHAR: - case T_SHORT: - case T_INT: - case T_LONG: { + case T_CHAR: + case T_SCHAR: + case T_SHORT: + case T_INT: + case T_LONG:{ char *p; errno = 0; - (void)strtol(Char(value), &p, 0); - if (errno || *p) value = "?"; + (void) strtol(Char(value), &p, 0); + if (errno || *p) + value = "?"; break; } - case T_UCHAR: - case T_USHORT: - case T_UINT: - case T_ULONG: { + case T_UCHAR: + case T_USHORT: + case T_UINT: + case T_ULONG:{ char *p; errno = 0; - (void)strtoul(Char(value), &p, 0); - if (errno || *p) value = "?"; + (void) strtoul(Char(value), &p, 0); + if (errno || *p) + value = "?"; break; } - case T_FLOAT: - case T_DOUBLE: { + case T_FLOAT: + case T_DOUBLE:{ char *p; errno = 0; /* FIXME: strtod is locale dependent... */ - (void)strtod(Char(value), &p); - if (errno || *p) value = "?"; + (void) strtod(Char(value), &p); + if (errno || *p) + value = "?"; break; } - case T_REFERENCE: - case T_USER: - case T_ARRAY: + case T_REFERENCE: + case T_USER: + case T_ARRAY: + value = "?"; + break; + case T_STRING: + if (Len(value) < 2) { + // How can a string (including "" be less than 2 characters?) value = "?"; - break; - case T_STRING: - if (Len(value) < 2) { - // How can a string (including "" be less than 2 characters?) + } else { + const char *v = Char(value); + if (v[0] != '"' || v[Len(value) - 1] != '"') value = "?"; - } else { - const char *v = Char(value); - if (v[0] != '"' || v[Len(value) - 1] != '"') value = "?"; - // Strings containing "$" require special handling, but we do that later. - } - break; - case T_VOID: - assert(false); - break; - case T_POINTER: { - const char * v = value; + // Strings containing "$" require special handling, but we do that later. + } + break; + case T_VOID: + assert(false); + break; + case T_POINTER:{ + const char *v = value; if (v[0] == '(') { // Handle "(void*)0", "(TYPE*)0", "(char*)NULL", etc. v += strcspn(v + 1, "*()") + 1; @@ -1610,9 +1613,7 @@ public: } } } - if (strcmp(value, "NULL") == 0 || - strcmp(value, "0") == 0 || - strcmp(value, "0L") == 0) { + if (strcmp(value, "NULL") == 0 || strcmp(value, "0") == 0 || strcmp(value, "0L") == 0) { value = "null"; } else { value = "?"; @@ -1635,13 +1636,14 @@ public: p = nextSibling(p); ++argno; } - if (!really_overloaded) break; - o = Getattr(o,"sym:nextSibling"); + if (!really_overloaded) + break; + o = Getattr(o, "sym:nextSibling"); } /* Clean up any parameters which haven't yet got names, or whose * names clash. */ - Hash * seen = NewHash(); + Hash *seen = NewHash(); /* We need $this to refer to the current class, so can't allow it * to be used as a parameter. */ Setattr(seen, "this", seen); @@ -1653,7 +1655,7 @@ public: Setattr(seen, "r", seen); for (int argno = 0; argno < max_num_of_arguments; ++argno) { - String * & pname = arg_names[argno]; + String *&pname = arg_names[argno]; if (pname) { Replaceall(pname, " ", "_"); } else { @@ -1675,9 +1677,9 @@ public: Delete(seen); seen = NULL; - String * invoke = NewStringEmpty(); - String * prepare = NewStringEmpty(); - String * args = NewStringEmpty(); + String *invoke = NewStringEmpty(); + String *prepare = NewStringEmpty(); + String *args = NewStringEmpty(); if (!handle_as_overload && !(really_overloaded && max_num_of_arguments > min_num_of_arguments)) { Printf(invoke, "%s(", iname); @@ -1685,8 +1687,10 @@ public: Printf(invoke, "$this->%s", SWIG_PTR); } for (int i = 0; i < max_num_of_arguments; ++i) { - if (i) Printf(args, ","); - if (i || wrapperType == memberfn) Printf(invoke, ","); + if (i) + Printf(args, ","); + if (i || wrapperType == memberfn) + Printf(invoke, ","); String *value = arg_values[i]; if (value) { const char *v = Char(value); @@ -1704,22 +1708,26 @@ public: } else { int i; for (i = 0; i < min_num_of_arguments; ++i) { - if (i) Printf(args, ","); + if (i) + Printf(args, ","); Printf(args, "$%s", arg_names[i]); } String *invoke_args = NewStringEmpty(); if (wrapperType == memberfn) { Printf(invoke_args, "$this->%s", SWIG_PTR); - if (min_num_of_arguments > 0) Printf(invoke_args, ","); + if (min_num_of_arguments > 0) + Printf(invoke_args, ","); } Printf(invoke_args, "%s", args); bool had_a_case = false; int last_handled_i = i - 1; - for ( ; i < max_num_of_arguments; ++i) { - if (i) Printf(args, ","); + for (; i < max_num_of_arguments; ++i) { + if (i) + Printf(args, ","); const char *value = Char(arg_values[i]); bool non_php_default = (!value || strcmp(value, "?") == 0); - if (non_php_default) value = "null"; + if (non_php_default) + value = "null"; Printf(args, "$%s=%s", arg_names[i], value); if (non_php_default) { if (!had_a_case) { @@ -1730,17 +1738,22 @@ public: while (last_handled_i < i) { Printf(prepare, "case %d: ", ++last_handled_i); } - if (Cmp(d, "void") != 0) Printf(prepare, "$r="); + if (Cmp(d, "void") != 0) + Printf(prepare, "$r="); Printf(prepare, "%s(%s); break;\n", iname, invoke_args); } - if (i || wrapperType == memberfn) Printf(invoke_args, ","); + if (i || wrapperType == memberfn) + Printf(invoke_args, ","); Printf(invoke_args, "$%s", arg_names[i]); } Printf(prepare, "\t\t"); - if (had_a_case) Printf(prepare, "default: "); - if (Cmp(d, "void") != 0) Printf(prepare, "$r="); + if (had_a_case) + Printf(prepare, "default: "); + if (Cmp(d, "void") != 0) + Printf(prepare, "$r="); Printf(prepare, "%s(%s);\n", iname, invoke_args); - if (had_a_case) Printf(prepare, "\t\t}\n"); + if (had_a_case) + Printf(prepare, "\t\t}\n"); Delete(invoke_args); Printf(invoke, "$r"); } @@ -1786,7 +1799,7 @@ public: Printf(output, "\t\tswitch (get_resource_type($r)) {\n"); Iterator i = First(ret_types); while (i.item) { - SwigType * ret_type = i.item; + SwigType *ret_type = i.item; i = Next(i); Printf(output, "\t\t"); String *mangled = NewString("_p"); @@ -1797,8 +1810,9 @@ public: } else { Printf(output, "default: ", mangled); } - const char * classname = GetChar(class_node, "sym:name"); - if (!classname) classname = GetChar(class_node, "name"); + const char *classname = GetChar(class_node, "sym:name"); + if (!classname) + classname = GetChar(class_node, "name"); Printf(output, "return new %s%s($r);\n", prefix, classname); Delete(mangled); } @@ -1820,19 +1834,19 @@ public: * ------------------------------------------------------------ */ virtual int globalvariableHandler(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); String *tm; /* First do the wrappers such as name_set(), name_get() * as provided by the baseclass's implementation of variableWrapper */ - if (Language::globalvariableHandler(n) == SWIG_NOWRAP ) { + if (Language::globalvariableHandler(n) == SWIG_NOWRAP) { return SWIG_NOWRAP; } - if (!addSymbol(iname,n)) + if (!addSymbol(iname, n)) return SWIG_ERROR; SwigType_remember(t); @@ -1840,59 +1854,59 @@ public: /* First link C variables to PHP */ tm = Swig_typemap_lookup_new("varinit", n, name, 0); - if(tm) { + if (tm) { Replaceall(tm, "$target", name); Printf(s_vinit, "%s\n", tm); } else { - Printf(stderr,"%s: Line %d, Unable to link with type %s\n", - input_file, line_number, SwigType_str(t,0), name); + Printf(stderr, "%s: Line %d, Unable to link with type %s\n", input_file, line_number, SwigType_str(t, 0), name); } /* Now generate PHP -> C sync blocks */ /* - tm = Swig_typemap_lookup_new("varin", n, name, 0); - if(tm) { - Replaceall(tm, "$symname", iname); - Printf(f_c->code, "%s\n", tm); - } else { - Printf(stderr,"%s: Line %d, Unable to link with type %s\n", - input_file, line_number, SwigType_str(t, 0), name); - } - */ + tm = Swig_typemap_lookup_new("varin", n, name, 0); + if(tm) { + Replaceall(tm, "$symname", iname); + Printf(f_c->code, "%s\n", tm); + } else { + Printf(stderr,"%s: Line %d, Unable to link with type %s\n", + input_file, line_number, SwigType_str(t, 0), name); + } + */ /* Now generate C -> PHP sync blocks */ /* - if(!GetFlag(n,"feature:immutable")) { - - tm = Swig_typemap_lookup_new("varout", n, name, 0); - if(tm) { - Replaceall(tm, "$symname", iname); - Printf(f_php->code, "%s\n", tm); - } else { - Printf(stderr,"%s: Line %d, Unable to link with type %s\n", - input_file, line_number, SwigType_str(t, 0), name); - } - } - */ + if(!GetFlag(n,"feature:immutable")) { + + tm = Swig_typemap_lookup_new("varout", n, name, 0); + if(tm) { + Replaceall(tm, "$symname", iname); + Printf(f_php->code, "%s\n", tm); + } else { + Printf(stderr,"%s: Line %d, Unable to link with type %s\n", + input_file, line_number, SwigType_str(t, 0), name); + } + } + */ return SWIG_OK; } /* ------------------------------------------------------------ * constantWrapper() * ------------------------------------------------------------ */ - - virtual int constantWrapper(Node *n) { - String *name = GetChar(n,"name"); - String *iname = GetChar(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); - String *tm; - if (!addSymbol(iname,n)) return SWIG_ERROR; + virtual int constantWrapper(Node *n) { + String *name = GetChar(n, "name"); + String *iname = GetChar(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; + + if (!addSymbol(iname, n)) + return SWIG_ERROR; SwigType_remember(type); - if((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { + if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", name); Replaceall(tm, "$value", value); @@ -1901,10 +1915,12 @@ public: if (shadow && php_version == 5) { if (wrapping_member_constant) { - if (!s_oowrappers) s_oowrappers = NewStringEmpty(); + if (!s_oowrappers) + s_oowrappers = NewStringEmpty(); Printf(s_oowrappers, "\n\tconst %s = %s;\n", wrapping_member_constant, iname); } else { - if (!s_fakeoowrappers) s_fakeoowrappers = NewStringEmpty(); + if (!s_fakeoowrappers) + s_fakeoowrappers = NewStringEmpty(); Printf(s_fakeoowrappers, "\n\tconst %s = %s;\n", name, iname); } } @@ -1920,30 +1936,29 @@ public: * %pragma(php4) code="String" # Includes a string in the .php file * %pragma(php4) include="file.pl" # Includes a file in the .php file */ - + virtual int pragmaDirective(Node *n) { if (!ImportMode) { - String *lang = Getattr(n,"lang"); - String *type = Getattr(n,"name"); - String *value = Getattr(n,"value"); + String *lang = Getattr(n, "lang"); + String *type = Getattr(n, "name"); + String *value = Getattr(n, "value"); - if (Strcmp(lang,"php4") == 0) { - if (Strcmp(type, "code") == 0) { - if (value) { - Printf(pragma_code, "%s\n", value); - } - } else if (Strcmp(type, "include") == 0) { - if (value) { - Printf(pragma_incl, "include \"%s\";\n", value); - } - } else if (Strcmp(type, "phpinfo") == 0) { - if (value) { - Printf(pragma_phpinfo, "%s\n", value); - } - } else { - Swig_warning(WARN_PHP4_UNKNOWN_PRAGMA, input_file, line_number, - "Unrecognized pragma <%s>.\n", type); - } + if (Strcmp(lang, "php4") == 0) { + if (Strcmp(type, "code") == 0) { + if (value) { + Printf(pragma_code, "%s\n", value); + } + } else if (Strcmp(type, "include") == 0) { + if (value) { + Printf(pragma_incl, "include \"%s\";\n", value); + } + } else if (Strcmp(type, "phpinfo") == 0) { + if (value) { + Printf(pragma_phpinfo, "%s\n", value); + } + } else { + Swig_warning(WARN_PHP4_UNKNOWN_PRAGMA, input_file, line_number, "Unrecognized pragma <%s>.\n", type); + } } } return Language::pragmaDirective(n); @@ -1954,20 +1969,20 @@ public: * ------------------------------------------------------------ */ virtual int classDeclaration(Node *n) { - if (!Getattr(n,"feature:onlychildren")) { - String *symname = Getattr(n,"sym:name"); - Setattr(n,"php:proxy",symname); + if (!Getattr(n, "feature:onlychildren")) { + String *symname = Getattr(n, "sym:name"); + Setattr(n, "php:proxy", symname); } - + return Language::classDeclaration(n); } - + /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ virtual int classHandler(Node *n) { - constructors=0; + constructors = 0; //SwigType *t = Getattr(n, "classtype"); current_class = n; // String *use_class_name=SwigType_manglestr(SwigType_ltype(t)); @@ -1975,7 +1990,8 @@ public: if (shadow && php_version == 4) { char *rename = GetChar(n, "sym:name"); - if (!addSymbol(rename,n)) return SWIG_ERROR; + if (!addSymbol(rename, n)) + return SWIG_ERROR; shadow_classname = NewString(rename); cs_entry = NewStringEmpty(); Printf(cs_entry, "/* Function entries for %s */\n", shadow_classname); @@ -1990,122 +2006,118 @@ public: shadow_set_vars = NewHash(); /* Deal with inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist) { Iterator base = First(baselist); - while(base.item && GetFlag(base.item,"feature:ignore")) { + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } base = Next(base); if (base.item) { /* Warn about multiple inheritance for additional base class(es) */ while (base.item) { - if (GetFlag(base.item,"feature:ignore")) { + if (GetFlag(base.item, "feature:ignore")) { base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0); - String *baseclassname = SwigType_str(Getattr(base.item,"name"),0); - Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname); + String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); + String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); + Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname); base = Next(base); } } } /* Write out class init code */ - Printf(s_vdecl,"static zend_class_entry ce_swig_%s;\n",shadow_classname); - Printf(s_vdecl,"static zend_class_entry* ptr_ce_swig_%s=NULL;\n",shadow_classname); + Printf(s_vdecl, "static zend_class_entry ce_swig_%s;\n", shadow_classname); + Printf(s_vdecl, "static zend_class_entry* ptr_ce_swig_%s=NULL;\n", shadow_classname); } else if (shadow && php_version == 5) { char *rename = GetChar(n, "sym:name"); - if (!addSymbol(rename,n)) return SWIG_ERROR; + if (!addSymbol(rename, n)) + return SWIG_ERROR; shadow_classname = NewString(rename); shadow_get_vars = NewHash(); shadow_set_vars = NewHash(); /* Deal with inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist) { Iterator base = First(baselist); - while(base.item && GetFlag(base.item,"feature:ignore")) { + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } base = Next(base); if (base.item) { /* Warn about multiple inheritance for additional base class(es) */ while (base.item) { - if (GetFlag(base.item,"feature:ignore")) { + if (GetFlag(base.item, "feature:ignore")) { base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0); - String *baseclassname = SwigType_str(Getattr(base.item,"name"),0); - Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname); + String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); + String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); + Swig_warning(WARN_PHP4_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Php4.\n", proxyclassname, baseclassname); base = Next(base); } } } } - classnode=n; + classnode = n; Language::classHandler(n); - classnode=0; + classnode = 0; if (shadow && php_version == 4) { DOH *key; - String *s_propget = NewStringEmpty(); - String *s_propset = NewStringEmpty(); + String *s_propget = NewStringEmpty(); + String *s_propset = NewStringEmpty(); List *baselist = Getattr(n, "bases"); Iterator ki, base; // If no constructor was generated (abstract class) we had better // generate a constructor that raises an error about instantiating // abstract classes - if (Getattr(n,"abstract") && constructors==0 ) { - // have to write out fake constructor which raises an error when called - abstractConstructorHandler(n); + if (Getattr(n, "abstract") && constructors == 0) { + // have to write out fake constructor which raises an error when called + abstractConstructorHandler(n); } - Printf(s_oinit,"/* Define class %s */\n",shadow_classname); - Printf(s_oinit,"INIT_OVERLOADED_CLASS_ENTRY(ce_swig_%s,\"%(lower)s\",%s_functions,", - shadow_classname,shadow_classname, shadow_classname); - Printf(s_oinit,"NULL,_wrap_propget_%s,_wrap_propset_%s);\n",shadow_classname,shadow_classname); + Printf(s_oinit, "/* Define class %s */\n", shadow_classname); + Printf(s_oinit, "INIT_OVERLOADED_CLASS_ENTRY(ce_swig_%s,\"%(lower)s\",%s_functions,", shadow_classname, shadow_classname, shadow_classname); + Printf(s_oinit, "NULL,_wrap_propget_%s,_wrap_propset_%s);\n", shadow_classname, shadow_classname); // ******** Write property SET handlers - Printf(s_header,"static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value);\n", - shadow_classname); - Printf(s_header,"static int _propset_%s(zend_property_reference *property_reference, pval *value);\n", - shadow_classname); + Printf(s_header, "static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname); + Printf(s_header, "static int _propset_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname); - Printf(s_propset,"static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value) { \n", - shadow_classname); - Printf(s_propset," zval * _value;\n"); - Printf(s_propset," zend_llist_element *element = property_reference->elements_list->head;\n"); - Printf(s_propset," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); - Printf(s_propset," if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", shadow_classname); - Printf(s_propset," /* set it ourselves as it is %s */\n",shadow_classname); - Printf(s_propset," MAKE_STD_ZVAL(_value);\n"); - Printf(s_propset," *_value=*value;\n"); - Printf(s_propset," INIT_PZVAL(_value);\n"); - Printf(s_propset," zval_copy_ctor(_value);\n"); - Printf(s_propset," return add_property_zval_ex(property_reference->object,Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),_value);\n"); - Printf(s_propset,"}\n"); - Printf(s_propset,"static int _propset_%s(zend_property_reference *property_reference, pval *value) {\n", - shadow_classname); + Printf(s_propset, "static int _wrap_propset_%s(zend_property_reference *property_reference, pval *value) { \n", shadow_classname); + Printf(s_propset, " zval * _value;\n"); + Printf(s_propset, " zend_llist_element *element = property_reference->elements_list->head;\n"); + Printf(s_propset, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); + Printf(s_propset, " if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", shadow_classname); + Printf(s_propset, " /* set it ourselves as it is %s */\n", shadow_classname); + Printf(s_propset, " MAKE_STD_ZVAL(_value);\n"); + Printf(s_propset, " *_value=*value;\n"); + Printf(s_propset, " INIT_PZVAL(_value);\n"); + Printf(s_propset, " zval_copy_ctor(_value);\n"); + Printf(s_propset, + " return add_property_zval_ex(property_reference->object,Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),_value);\n"); + Printf(s_propset, "}\n"); + Printf(s_propset, "static int _propset_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname); if (baselist) { - base=First(baselist); - } - else { - base.item = NULL; + base = First(baselist); + } else { + base.item = NULL; } - while(base.item && GetFlag(base.item,"feature:ignore")) { - base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { + base = Next(base); } ki = First(shadow_set_vars); @@ -2113,79 +2125,75 @@ public: // Print function header; we only need to find property name if there // are properties for this class to look up... - if (key || ! base.item) { // or if we are base class and set it ourselves - Printf(s_propset," /* get the property name */\n"); - Printf(s_propset," zend_llist_element *element = property_reference->elements_list->head;\n"); - Printf(s_propset," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); - Printf(s_propset," char *propname=Z_STRVAL_P(&(property->element));\n"); + if (key || !base.item) { // or if we are base class and set it ourselves + Printf(s_propset, " /* get the property name */\n"); + Printf(s_propset, " zend_llist_element *element = property_reference->elements_list->head;\n"); + Printf(s_propset, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); + Printf(s_propset, " char *propname=Z_STRVAL_P(&(property->element));\n"); } else { - if (base.item) { - Printf(s_propset," /* No extra properties for subclass %s */\n",shadow_classname); - } else { - Printf(s_propset," /* No properties for base class %s */\n",shadow_classname); - } + if (base.item) { + Printf(s_propset, " /* No extra properties for subclass %s */\n", shadow_classname); + } else { + Printf(s_propset, " /* No properties for base class %s */\n", shadow_classname); + } } while (ki.key) { - key = ki.key; - Printf(s_propset," if (strcmp(propname,\"%s\")==0) return _wrap_%s(property_reference, value);\n", ki.item, key); + key = ki.key; + Printf(s_propset, " if (strcmp(propname,\"%s\")==0) return _wrap_%s(property_reference, value);\n", ki.item, key); - ki=Next(ki); + ki = Next(ki); } // If the property wasn't in this class, try the handlers of each base // class (if any) in turn until we succeed in setting the property or // have tried all base classes. if (base.item) { - Printf(s_propset, " /* Try base class(es) */\n"); - while (base.item) { - Printf(s_propset," if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", - GetChar(base.item, "sym:name")); + Printf(s_propset, " /* Try base class(es) */\n"); + while (base.item) { + Printf(s_propset, " if (_propset_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", GetChar(base.item, "sym:name")); - base=Next(base); - while (base.item && GetFlag(base.item,"feature:ignore")) { - base=Next(base); - } - } + base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { + base = Next(base); + } + } } - Printf(s_propset," return FAILURE;\n}\n\n"); + Printf(s_propset, " return FAILURE;\n}\n\n"); // ******** Write property GET handlers - Printf(s_header,"static pval _wrap_propget_%s(zend_property_reference *property_reference);\n", - shadow_classname); - Printf(s_header,"static int _propget_%s(zend_property_reference *property_reference, pval *value);\n", - shadow_classname); + Printf(s_header, "static pval _wrap_propget_%s(zend_property_reference *property_reference);\n", shadow_classname); + Printf(s_header, "static int _propget_%s(zend_property_reference *property_reference, pval *value);\n", shadow_classname); - Printf(s_propget,"static pval _wrap_propget_%s(zend_property_reference *property_reference) {\n", - shadow_classname); - Printf(s_propget," pval result;\n"); - Printf(s_propget," pval **_result;\n"); - Printf(s_propget," zend_llist_element *element = property_reference->elements_list->head;\n"); - Printf(s_propget," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); - Printf(s_propget," result.type = IS_NULL;\n"); - Printf(s_propget," if (_propget_%s(property_reference, &result)==SUCCESS) return result;\n", shadow_classname); - Printf(s_propget," /* return it ourselves */\n"); - Printf(s_propget," if (zend_hash_find(Z_OBJPROP_P(property_reference->object),Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),(void**)&_result)==SUCCESS) {\n"); - Printf(s_propget," zval *_value;\n"); - Printf(s_propget," MAKE_STD_ZVAL(_value);"); - Printf(s_propget," *_value=**_result;\n"); - Printf(s_propget," INIT_PZVAL(_value);\n"); - Printf(s_propget," zval_copy_ctor(_value);\n"); - Printf(s_propget," return *_value;\n"); - Printf(s_propget," }\n"); - Printf(s_propget," result.type = IS_NULL;\n"); - Printf(s_propget," return result;\n"); - Printf(s_propget,"}\n"); - Printf(s_propget,"static int _propget_%s(zend_property_reference *property_reference, pval *value) {\n", - shadow_classname); + Printf(s_propget, "static pval _wrap_propget_%s(zend_property_reference *property_reference) {\n", shadow_classname); + Printf(s_propget, " pval result;\n"); + Printf(s_propget, " pval **_result;\n"); + Printf(s_propget, " zend_llist_element *element = property_reference->elements_list->head;\n"); + Printf(s_propget, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); + Printf(s_propget, " result.type = IS_NULL;\n"); + Printf(s_propget, " if (_propget_%s(property_reference, &result)==SUCCESS) return result;\n", shadow_classname); + Printf(s_propget, " /* return it ourselves */\n"); + Printf(s_propget, + " if (zend_hash_find(Z_OBJPROP_P(property_reference->object),Z_STRVAL_P(&(property->element)),1+Z_STRLEN_P(&(property->element)),(void**)&_result)==SUCCESS) {\n"); + Printf(s_propget, " zval *_value;\n"); + Printf(s_propget, " MAKE_STD_ZVAL(_value);"); + Printf(s_propget, " *_value=**_result;\n"); + Printf(s_propget, " INIT_PZVAL(_value);\n"); + Printf(s_propget, " zval_copy_ctor(_value);\n"); + Printf(s_propget, " return *_value;\n"); + Printf(s_propget, " }\n"); + Printf(s_propget, " result.type = IS_NULL;\n"); + Printf(s_propget, " return result;\n"); + Printf(s_propget, "}\n"); + Printf(s_propget, "static int _propget_%s(zend_property_reference *property_reference, pval *value) {\n", shadow_classname); if (baselist) { - base=First(baselist); + base = First(baselist); } else { - base.item=NULL; + base.item = NULL; } - while(base.item && GetFlag(base.item,"feature:ignore")) { - base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { + base = Next(base); } ki = First(shadow_get_vars); @@ -2193,71 +2201,71 @@ public: // Print function header; we only need to find property name if there // are properties for this class to look up... - if (key || !base.item ) { // or if we are base class... - Printf(s_propget," /* get the property name */\n"); - Printf(s_propget," zend_llist_element *element = property_reference->elements_list->head;\n"); - Printf(s_propget," zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); - Printf(s_propget," char *propname=Z_STRVAL_P(&(property->element));\n"); + if (key || !base.item) { // or if we are base class... + Printf(s_propget, " /* get the property name */\n"); + Printf(s_propget, " zend_llist_element *element = property_reference->elements_list->head;\n"); + Printf(s_propget, " zend_overloaded_element *property=(zend_overloaded_element *)element->data;\n"); + Printf(s_propget, " char *propname=Z_STRVAL_P(&(property->element));\n"); } else { - if (base.item) { - Printf(s_propget," /* No extra properties for subclass %s */\n",shadow_classname); - } else { - Printf(s_propget," /* No properties for base class %s */\n",shadow_classname); - } + if (base.item) { + Printf(s_propget, " /* No extra properties for subclass %s */\n", shadow_classname); + } else { + Printf(s_propget, " /* No properties for base class %s */\n", shadow_classname); + } } while (ki.key) { - key = ki.key; - Printf(s_propget," if (strcmp(propname,\"%s\")==0) {\n", ki.item); - Printf(s_propget," *value=_wrap_%s(property_reference);\n",key); - Printf(s_propget," return SUCCESS;\n"); - Printf(s_propget," }\n"); + key = ki.key; + Printf(s_propget, " if (strcmp(propname,\"%s\")==0) {\n", ki.item); + Printf(s_propget, " *value=_wrap_%s(property_reference);\n", key); + Printf(s_propget, " return SUCCESS;\n"); + Printf(s_propget, " }\n"); - ki=Next(ki); + ki = Next(ki); } // If the property wasn't in this class, try the handlers of each base // class (if any) in turn until we succeed in setting the property or // have tried all base classes. if (base.item) { - Printf(s_propget, " /* Try base class(es). */\n"); - while (base.item) { - Printf(s_propget," if (_propget_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", - GetChar(base.item, "sym:name")); + Printf(s_propget, " /* Try base class(es). */\n"); + while (base.item) { + Printf(s_propget, " if (_propget_%s(property_reference, value)==SUCCESS) return SUCCESS;\n", GetChar(base.item, "sym:name")); - base=Next(base); - while (base.item && GetFlag(base.item,"feature:ignore")) { - base=Next(base); - } - } + base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { + base = Next(base); + } + } } - Printf(s_propget," return FAILURE;\n}\n\n"); + Printf(s_propget, " return FAILURE;\n}\n\n"); // wrappers generated now... // add wrappers to output code - Printf(s_wrappers,"/* property handler for class %s */\n",shadow_classname); - Printv(s_wrappers,s_propget,s_propset,NIL); + Printf(s_wrappers, "/* property handler for class %s */\n", shadow_classname); + Printv(s_wrappers, s_propget, s_propset, NIL); // Save class in class table if (baselist) { - base=First(baselist); + base = First(baselist); + } else { + base.item = NULL; } - else { - base.item=NULL; - } - while(base.item && GetFlag(base.item,"feature:ignore")) { - base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { + base = Next(base); } if (base.item) { - Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,&ce_swig_%s,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", - shadow_classname,shadow_classname,GetChar(base.item, "sym:name"), shadow_classname); + Printf(s_oinit, + "if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,&ce_swig_%s,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", + shadow_classname, shadow_classname, GetChar(base.item, "sym:name"), shadow_classname); } else { - Printf(s_oinit,"if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,NULL,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", - shadow_classname,shadow_classname, shadow_classname); + Printf(s_oinit, + "if (! (ptr_ce_swig_%s=zend_register_internal_class_ex(&ce_swig_%s,NULL,NULL))) zend_error(E_ERROR,\"Error registering wrapper for class %s\");\n", + shadow_classname, shadow_classname, shadow_classname); } - Printf(s_oinit,"\n"); + Printf(s_oinit, "\n"); // Write the enum initialisation code in a static block // These are all the enums defined within the C++ class. @@ -2265,8 +2273,10 @@ public: Delete(shadow_classname); shadow_classname = NULL; - Delete(shadow_set_vars); shadow_set_vars = NULL; - Delete(shadow_get_vars); shadow_get_vars = NULL; + Delete(shadow_set_vars); + shadow_set_vars = NULL; + Delete(shadow_get_vars); + shadow_get_vars = NULL; Printv(all_cs_entry, cs_entry, " { NULL, NULL, NULL}\n};\n", NIL); Delete(cs_entry); @@ -2277,12 +2287,12 @@ public: Iterator ki, base; if (baselist) { - base = First(baselist); - while (base.item && GetFlag(base.item,"feature:ignore")) { + base = First(baselist); + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } } else { - base.item = NULL; + base.item = NULL; } if (Getattr(n, "abstract")) { @@ -2292,7 +2302,8 @@ public: Printf(s_phpclasses, "class %s%s ", prefix, shadow_classname); if (base.item) { String *baseclass = Getattr(base.item, "sym:name"); - if (!baseclass) baseclass = Getattr(base.item, "name"); + if (!baseclass) + baseclass = Getattr(base.item, "name"); Printf(s_phpclasses, "extends %s%s ", prefix, baseclass); } Printf(s_phpclasses, "{\n\tpublic $%s=null;\n", SWIG_PTR); @@ -2309,20 +2320,16 @@ public: // Not many setters, so avoid call_user_func. while (ki.key) { key = ki.key; - Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s,$value);\n", - key, ki.item, SWIG_PTR); + Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s,$value);\n", key, ki.item, SWIG_PTR); ki = Next(ki); } } else { - Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", - shadow_classname); - Printf(s_phpclasses, "\t\tif (function_exists($func) call_user_func($func,$this->%s,$value);\n", - SWIG_PTR); + Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_set';\n", shadow_classname); + Printf(s_phpclasses, "\t\tif (function_exists($func) call_user_func($func,$this->%s,$value);\n", SWIG_PTR); } Printf(s_phpclasses, "\t}\n"); /* FIXME: also create __isset for PHP 5.1 and later? */ } - // Write property GET handlers ki = First(shadow_get_vars); @@ -2334,15 +2341,12 @@ public: // Not many getters, so avoid call_user_func. while (ki.key) { key = ki.key; - Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s);\n", - key, ki.item, SWIG_PTR); + Printf(s_phpclasses, "\t\tif ($var == '%s') return %s($this->%s);\n", key, ki.item, SWIG_PTR); ki = Next(ki); } } else { - Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", - shadow_classname); - Printf(s_phpclasses, "\t\tif (function_exists($func) return call_user_func($func,$this->%s);\n", - SWIG_PTR); + Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname); + Printf(s_phpclasses, "\t\tif (function_exists($func) return call_user_func($func,$this->%s);\n", SWIG_PTR); } // Reading an unknown property name gives null in PHP. Printf(s_phpclasses, "\t\treturn null;\n"); @@ -2367,8 +2371,10 @@ public: Delete(shadow_classname); shadow_classname = NULL; - Delete(shadow_set_vars); shadow_set_vars = NULL; - Delete(shadow_get_vars); shadow_get_vars = NULL; + Delete(shadow_set_vars); + shadow_set_vars = NULL; + Delete(shadow_get_vars); + shadow_get_vars = NULL; } return SWIG_OK; } @@ -2380,19 +2386,18 @@ public: virtual int memberfunctionHandler(Node *n) { char *name = GetChar(n, "name"); char *iname = GetChar(n, "sym:name"); - + wrapperType = memberfn; this->Language::memberfunctionHandler(n); wrapperType = standard; - + // Only declare the member function if // we are doing shadow classes, and the function // is not overloaded, or if it is overloaded, it is the dispatch function. - if (shadow && php_version == 4 && - (!Getattr(n,"sym:overloaded") || !Getattr(n,"sym:nextSibling"))) { + if (shadow && php_version == 4 && (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling"))) { char *realname = iname ? iname : name; String *php_function_name = Swig_name_member(shadow_classname, realname); - create_command(realname,Swig_name_wrapper(php_function_name)); + create_command(realname, Swig_name_wrapper(php_function_name)); } return SWIG_OK; } @@ -2402,11 +2407,11 @@ public: * ------------------------------------------------------------ */ virtual int membervariableHandler(Node *n) { - + wrapperType = membervar; Language::membervariableHandler(n); wrapperType = standard; - + return SWIG_OK; } @@ -2420,9 +2425,9 @@ public: Language::staticmembervariableHandler(n); wrapperType = standard; - SwigType* type = Getattr(n, "type" ); - String *name = Getattr(n, "name" ); - String *iname = Getattr(n, "sym:name" ); + SwigType *type = Getattr(n, "type"); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); /* A temporary(!) hack for static member variables. * Php currently supports class functions, but not class variables. @@ -2438,38 +2443,38 @@ public: */ // If the variable is const, then it's wrapped as a constant with set/get functions. - if ( SwigType_isconst(type) ) + if (SwigType_isconst(type)) return SWIG_OK; // This duplicates the logic from Language::variableWrapper() to test if the set wrapper // is made. int assignable = is_assignable(n); if (assignable) { - String *tm = Swig_typemap_lookup_new("globalin",n,name,0); + String *tm = Swig_typemap_lookup_new("globalin", n, name, 0); if (!tm && SwigType_isarray(type)) { - assignable = 0; + assignable = 0; } } String *class_iname = Swig_name_member(Getattr(current_class, "sym:name"), iname); - create_command( iname, Swig_name_wrapper(class_iname) ); + create_command(iname, Swig_name_wrapper(class_iname)); Wrapper *f = NewWrapper(); - Printv(f->def, "ZEND_NAMED_FUNCTION(",Swig_name_wrapper(class_iname), ") {\n", NIL ); + Printv(f->def, "ZEND_NAMED_FUNCTION(", Swig_name_wrapper(class_iname), ") {\n", NIL); String *mget = Swig_name_wrapper(Swig_name_get(class_iname)); String *mset = Swig_name_wrapper(Swig_name_set(class_iname)); - if ( assignable ) { - Printf(f->code, "if (ZEND_NUM_ARGS() > 0 ) {\n" ); - Printf(f->code, " %s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n", mset ); - Printf(f->code, " // need some error checking here?\n" ); + if (assignable) { + Printf(f->code, "if (ZEND_NUM_ARGS() > 0 ) {\n"); + Printf(f->code, " %s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n", mset); + Printf(f->code, " // need some error checking here?\n"); Printf(f->code, " // Set the argument count to 0 for the get call\n"); Printf(f->code, " ht = 0;\n"); - Printf(f->code, "}\n" ); + Printf(f->code, "}\n"); } - Printf(f->code, "%s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n",mget ); + Printf(f->code, "%s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n", mget); Printf(f->code, "}\n"); Wrapper_print(f, s_wrappers); @@ -2488,7 +2493,7 @@ public: virtual int staticmemberfunctionHandler(Node *n) { char *name = GetChar(n, "name"); char *iname = GetChar(n, "sym:name"); - + wrapperType = staticmemberfn; Language::staticmemberfunctionHandler(n); wrapperType = standard; @@ -2497,30 +2502,29 @@ public: String *symname = Getattr(n, "sym:name"); char *realname = iname ? iname : name; String *php_function_name = Swig_name_member(shadow_classname, realname); - create_command(symname, Swig_name_wrapper(php_function_name) ); + create_command(symname, Swig_name_wrapper(php_function_name)); } - + return SWIG_OK; } - - void SwigToPhpType(SwigType *t, String_or_char *pname, String* php_type, int shadow_flag) { + + void SwigToPhpType(SwigType *t, String_or_char *pname, String *php_type, int shadow_flag) { String *ptype = 0; - if(shadow_flag) { - ptype = PhpTypeFromTypemap((char*)"pstype", t, pname, (char*)""); + if (shadow_flag) { + ptype = PhpTypeFromTypemap((char *) "pstype", t, pname, (char *) ""); } - if(!ptype) { - ptype = PhpTypeFromTypemap((char*)"ptype", t, pname, (char*)""); + if (!ptype) { + ptype = PhpTypeFromTypemap((char *) "ptype", t, pname, (char *) ""); } - if(ptype) { + if (ptype) { Printf(php_type, "%s", ptype); Delete(ptype); - } - else { + } else { /* Map type here */ - switch(SwigType_type(t)) { + switch (SwigType_type(t)) { case T_CHAR: case T_SCHAR: case T_UCHAR: @@ -2535,24 +2539,23 @@ public: case T_BOOL: case T_STRING: case T_VOID: - Printf(php_type, ""); - break; + Printf(php_type, ""); + break; case T_POINTER: case T_REFERENCE: case T_USER: - if(shadow_flag && is_shadow(t)) { - Printf(php_type, Char(is_shadow(t))); - } - else { - Printf(php_type, ""); - } - break; + if (shadow_flag && is_shadow(t)) { + Printf(php_type, Char(is_shadow(t))); + } else { + Printf(php_type, ""); + } + break; case T_ARRAY: - /* TODO */ - break; + /* TODO */ + break; default: - Printf(stderr, "SwigToPhpType: unhandled data type: %s\n", SwigType_str(t,0)); - break; + Printf(stderr, "SwigToPhpType: unhandled data type: %s\n", SwigType_str(t, 0)); + break; } } } @@ -2560,17 +2563,17 @@ public: String *PhpTypeFromTypemap(char *op, SwigType *t, String_or_char *pname, String_or_char *lname) { String *tms; - tms = Swig_typemap_lookup(op, t, pname, lname, (char*)"", (char*)"", NULL); - if(!tms) { + tms = Swig_typemap_lookup(op, t, pname, lname, (char *) "", (char *) "", NULL); + if (!tms) { return NULL; } - char * start = Char(tms); - while(isspace(*start) || *start == '{') { + char *start = Char(tms); + while (isspace(*start) || *start == '{') { start++; } - char * end = start; - while(*end && *end != '}') { + char *end = start; + while (*end && *end != '}') { end++; } return NewStringWithSize(start, end - start); @@ -2581,14 +2584,13 @@ public: if (shadow && php_version == 4) { Wrapper *f = NewWrapper(); - String *wname = NewStringf( "_wrap_new_%s", iname ); - create_command( iname, wname ); + String *wname = NewStringf("_wrap_new_%s", iname); + create_command(iname, wname); Printf(f->def, "ZEND_NAMED_FUNCTION(_wrap_new_%s) {\n", iname); - Printf(f->def, " zend_error(E_ERROR,\"Cannot create swig object type: %s as the underlying class is abstract\");\n", - iname); + Printf(f->def, " zend_error(E_ERROR,\"Cannot create swig object type: %s as the underlying class is abstract\");\n", iname); Printf(f->def, "}\n\n"); - Wrapper_print(f,s_wrappers); + Wrapper_print(f, s_wrappers); DelWrapper(f); Delete(wname); } @@ -2608,9 +2610,8 @@ public: } else { native_constructor = ALTERNATIVE_CONSTRUCTOR; } - } - else { - native_constructor=0; + } else { + native_constructor = 0; } constructors++; wrapperType = constructor; @@ -2618,10 +2619,10 @@ public: wrapperType = standard; if (shadow && php_version == 4) { - if(!Getattr(n,"sym:overloaded") || !Getattr(n,"sym:nextSibling")) { - char *realname = iname ? iname : name; - String *php_function_name = Swig_name_construct(realname); - create_command(realname,Swig_name_wrapper(php_function_name)); + if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling")) { + char *realname = iname ? iname : name; + String *php_function_name = Swig_name_construct(realname); + create_command(realname, Swig_name_wrapper(php_function_name)); } } @@ -2635,52 +2636,51 @@ public: //virtual int destructorHandler(Node *n) { //} int CreateZendListDestructor(Node *n) { - String *name = GetChar(Swig_methodclass(n),"name"); - String *iname = GetChar(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *name = GetChar(Swig_methodclass(n), "name"); + String *iname = GetChar(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); String *destructorname = NewStringEmpty(); - Printf(destructorname,"_%s",Swig_name_wrapper(iname)); - Setattr(classnode,"destructor",destructorname); + Printf(destructorname, "_%s", Swig_name_wrapper(iname)); + Setattr(classnode, "destructor", destructorname); Wrapper *df = NewWrapper(); - Printf(df->def,"/* This function is designed to be called by the zend list destructors */\n"); - Printf(df->def,"/* to typecast and do the actual destruction */\n"); - Printf(df->def,"static void %s(zend_rsrc_list_entry *rsrc, const char *type_name TSRMLS_DC) {\n",destructorname); + Printf(df->def, "/* This function is designed to be called by the zend list destructors */\n"); + Printf(df->def, "/* to typecast and do the actual destruction */\n"); + Printf(df->def, "static void %s(zend_rsrc_list_entry *rsrc, const char *type_name TSRMLS_DC) {\n", destructorname); Wrapper_add_localv(df, "value", "swig_object_wrapper *value=(swig_object_wrapper *) rsrc->ptr", NIL); Wrapper_add_localv(df, "ptr", "void *ptr=value->ptr", NIL); Wrapper_add_localv(df, "newobject", "int newobject=value->newobject", NIL); emit_args(d, l, df); - emit_attach_parmmaps(l,df); + emit_attach_parmmaps(l, df); // Get type of first arg, thing to be destructed // Skip ignored arguments - Parm *p=l; + Parm *p = l; //while (Getattr(p,"tmap:ignore")) {p = Getattr(p,"tmap:ignore:next");} - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); + SwigType *pt = Getattr(p, "type"); - Printf(df->code," efree(value);\n"); - Printf(df->code," if (! newobject) return; /* can't delete it! */\n"); - Printf(df->code," arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n", - SwigType_lstr(pt, 0), SwigType_manglestr(pt)); - Printf(df->code," if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name)); + Printf(df->code, " efree(value);\n"); + Printf(df->code, " if (! newobject) return; /* can't delete it! */\n"); + Printf(df->code, " arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt)); + Printf(df->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name)); - emit_action(n,df); + emit_action(n, df); - Printf(df->code,"}\n"); + Printf(df->code, "}\n"); - Wrapper_print(df,s_wrappers); + Wrapper_print(df, s_wrappers); return SWIG_OK; } - + /* ------------------------------------------------------------ * memberconstantHandler() * ------------------------------------------------------------ */ @@ -2692,51 +2692,51 @@ public: return SWIG_OK; } -}; /* class PHP */ +}; /* class PHP */ /* ----------------------------------------------------------------------------- * swig_php() - Instantiate module * ----------------------------------------------------------------------------- */ -static PHP *maininstance=0; +static PHP *maininstance = 0; // We use this function to be able to write out zend_register_list_destructor_ex // lines for most things in the type table // NOTE: it's a function NOT A PHP::METHOD -extern "C" -void typetrace(SwigType *ty, String *mangled, String *clientdata) { +extern "C" void typetrace(SwigType *ty, String *mangled, String *clientdata) { Node *class_node; if (!zend_types) { - zend_types=NewHash(); + zend_types = NewHash(); } // we want to know if the type which reduced to this has a constructor - if ((class_node=maininstance->classLookup(ty))) { - if (! Getattr(zend_types,mangled)) { + if ((class_node = maininstance->classLookup(ty))) { + if (!Getattr(zend_types, mangled)) { // OK it may have been set before by a different SwigType but it would // have had the same underlying class node I think // - it is certainly required not to have different originating class // nodes for the same SwigType - Setattr(zend_types,mangled,class_node); + Setattr(zend_types, mangled, class_node); } - } else { // a non-class pointer - Setattr(zend_types,mangled,NOTCLASS); + } else { // a non-class pointer + Setattr(zend_types, mangled, NOTCLASS); } - if (r_prevtracefunc) (*r_prevtracefunc)(ty, mangled, (String *) clientdata); + if (r_prevtracefunc) + (*r_prevtracefunc) (ty, mangled, (String *) clientdata); } -static Language * new_swig_php(int php_version) { - maininstance=new PHP(php_version); - if (! r_prevtracefunc) { - r_prevtracefunc=SwigType_remember_trace(typetrace); +static Language *new_swig_php(int php_version) { + maininstance = new PHP(php_version); + if (!r_prevtracefunc) { + r_prevtracefunc = SwigType_remember_trace(typetrace); } else { - Printf(stderr,"php Typetrace vector already saved!\n"); + Printf(stderr, "php Typetrace vector already saved!\n"); assert(0); } return maininstance; } -extern "C" Language * swig_php4(void) { +extern "C" Language *swig_php4(void) { return new_swig_php(4); } -extern "C" Language * swig_php5(void) { +extern "C" Language *swig_php5(void) { return new_swig_php(5); } diff --git a/SWIG/Source/Modules/pike.cxx b/SWIG/Source/Modules/pike.cxx index 408c2e161..9225c653e 100644 --- a/SWIG/Source/Modules/pike.cxx +++ b/SWIG/Source/Modules/pike.cxx @@ -24,19 +24,19 @@ * address, etc. for extension objects. Should we do something here? * */ - + char cvsroot_pike_cxx[] = "$Header$"; #include "swigmod.h" -#include // for isalnum() +#include // for isalnum() -static const char *usage = (char *)"\ +static const char *usage = (char *) "\ Pike Options (available with -pike)\n\ [None]\n\ \n"; -class PIKE : public Language { +class PIKE:public Language { private: File *f_runtime; @@ -47,7 +47,7 @@ private: String *PrefixPlusUnderscore; int current; - + // Wrap modes enum { NO_CPP, @@ -68,7 +68,7 @@ public: * Initialize member data * --------------------------------------------------------------------- */ - PIKE() { + PIKE() { f_runtime = 0; f_header = 0; f_wrappers = 0; @@ -83,8 +83,8 @@ public: * * Parse command line options and initializes variables. * --------------------------------------------------------------------- */ - - virtual void main(int argc, char *argv[]) { + + virtual void main(int argc, char *argv[]) { /* Set location of SWIG library */ SWIG_library_directory("pike"); @@ -92,8 +92,8 @@ public: /* Look for certain command line options */ for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i],"-help") == 0) { - fputs(usage,stdout); + if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); } } } @@ -101,12 +101,12 @@ public: /* Add a symbol to the parser for conditional compilation */ Preprocessor_define("SWIGPIKE 1", 0); - /* Set language-specific configuration file */ + /* Set language-specific configuration file */ SWIG_config_file("pike.swg"); /* Set typemap language */ SWIG_typemap_lang("pike"); - + /* Enable overloaded methods support */ allow_overloading(); } @@ -118,10 +118,10 @@ public: virtual int top(Node *n) { /* Get the module name */ String *module = Getattr(n, "name"); - + /* Get the output file name */ String *outfile = Getattr(n, "outfile"); - + /* Open the output file */ f_runtime = NewFile(outfile, "w"); if (!f_runtime) { @@ -140,26 +140,26 @@ public: Swig_register_filebyname("init", f_init); Swig_register_filebyname("classInit", f_classInit); - /* Standard stuff for the SWIG runtime section */ + /* Standard stuff for the SWIG runtime section */ Swig_banner(f_runtime); Printf(f_header, "#define SWIG_init pike_module_init\n"); Printf(f_header, "#define SWIG_name \"%s\"\n\n", module); - + /* Change naming scheme for constructors and destructors */ - Swig_name_register("construct","%c_create"); - Swig_name_register("destroy","%c_destroy"); - + Swig_name_register("construct", "%c_create"); + Swig_name_register("destroy", "%c_destroy"); + /* Current wrap type */ current = NO_CPP; /* Emit code for children */ Language::top(n); - + /* Close the initialization function */ Printf(f_init, "}\n"); SwigType_emit_type_table(f_runtime, f_wrappers); - + /* Close all of the files */ Dump(f_header, f_runtime); Dump(f_wrappers, f_runtime); @@ -176,7 +176,7 @@ public: /* Done */ return SWIG_OK; } - + /* ------------------------------------------------------------ * validIdentifier() * ------------------------------------------------------------ */ @@ -187,10 +187,12 @@ public: const char *c1 = c0 + 1; while (*c) { if (*c == '`' && c == c0) { - c++; continue; + c++; + continue; } if ((*c == '+' || *c == '-' || *c == '*' || *c == '/') && c == c1) { - c++; continue; + c++; + continue; } if (!(isalnum(*c) || (*c == '_'))) return 0; @@ -198,19 +200,19 @@ public: } return 1; } - + /* ------------------------------------------------------------ * importDirective() * ------------------------------------------------------------ */ virtual int importDirective(Node *n) { - String *modname = Getattr(n,"module"); + String *modname = Getattr(n, "module"); if (modname) { - Printf(f_init,"pike_require(\"%s\");\n", modname); + Printf(f_init, "pike_require(\"%s\");\n", modname); } return Language::importDirective(n); } - + /* ------------------------------------------------------------ * strip() * @@ -235,26 +237,26 @@ public: void add_method(const DOHString_or_char *name, const DOHString_or_char *function, const DOHString_or_char *description) { String *rename = NULL; switch (current) { - case NO_CPP: - rename = NewString(name); - Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); - break; - case STATIC_FUNC: - case STATIC_VAR: - rename = NewString(name); - Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); - break; - case CONSTRUCTOR: - case DESTRUCTOR: - case MEMBER_FUNC: - case MEMBER_VAR: - rename = strip(name); - Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); - break; - case CLASS_CONST: - assert(false); // shouldn't have gotten here for CLASS_CONST nodes - default: - assert(false); // what is this? + case NO_CPP: + rename = NewString(name); + Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); + break; + case STATIC_FUNC: + case STATIC_VAR: + rename = NewString(name); + Printf(f_init, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); + break; + case CONSTRUCTOR: + case DESTRUCTOR: + case MEMBER_FUNC: + case MEMBER_VAR: + rename = strip(name); + Printf(f_classInit, "ADD_FUNCTION(\"%s\", %s, tFunc(%s), 0);\n", rename, function, description); + break; + case CLASS_CONST: + assert(false); // shouldn't have gotten here for CLASS_CONST nodes + default: + assert(false); // what is this? } Delete(rename); } @@ -267,83 +269,83 @@ public: virtual int functionWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); Parm *p; - String *tm; + String *tm; int i; String *overname = 0; - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } Wrapper *f = NewWrapper(); - + /* Write code to extract function parameters. */ emit_args(d, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ int num_arguments = emit_num_arguments(l); int varargs = emit_isvarargs(l); - + /* Which input argument to start with? */ int start = (current == MEMBER_FUNC || current == MEMBER_VAR || current == DESTRUCTOR) ? 1 : 0; - /* Offset to skip over the attribute name */ + /* Offset to skip over the attribute name */ // int offset = (current == MEMBER_VAR) ? 1 : 0; int offset = 0; - + String *wname = Swig_name_wrapper(iname); if (overname) { - Append(wname,overname); + Append(wname, overname); } - + Printv(f->def, "static void ", wname, "(INT32 args) {", NIL); - + /* Generate code for argument marshalling */ String *description = NewString(""); char source[64]; for (i = 0, p = l; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); if (i < start) { - String *lstr = SwigType_lstr(pt,0); - Printf(f->code, "%s = (%s) THIS;\n", ln, lstr); + String *lstr = SwigType_lstr(pt, 0); + Printf(f->code, "%s = (%s) THIS;\n", ln, lstr); Delete(lstr); - } else { + } else { /* Look for an input typemap */ - sprintf(source, "Pike_sp[%d-args]", i-start+offset); - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm, "$source", source); + sprintf(source, "Pike_sp[%d-args]", i - start + offset); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$source", source); Replaceall(tm, "$target", ln); Replaceall(tm, "$input", source); Setattr(p, "emit:input", source); Printf(f->code, "%s\n", tm); - String *pikedesc = Getattr(p, "tmap:in:pikedesc"); + String *pikedesc = Getattr(p, "tmap:in:pikedesc"); if (pikedesc) { Printv(description, pikedesc, " ", NIL); } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); continue; } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); break; } } @@ -352,30 +354,30 @@ public: /* Check for trailing varargs */ if (varargs) { - if (p && (tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$input", "varargs"); - Printv(f->code,tm,"\n",NIL); + if (p && (tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$input", "varargs"); + Printv(f->code, tm, "\n", NIL); } } /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ String *cleanup = NewString(""); for (p = l; p;) { - if ((tm = Getattr(p,"tmap:freearg"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); - p = Getattr(p,"tmap:freearg:next"); + if ((tm = Getattr(p, "tmap:freearg"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -384,20 +386,20 @@ public: /* Insert argument output code */ String *outarg = NewString(""); for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } /* Emit the function call */ - emit_action(n,f); + emit_action(n, f); /* Clear the return stack */ Printf(f->code, "pop_n_elems(args);\n"); @@ -411,65 +413,64 @@ public: } else { // Wrapper_add_local(f, "resultobj", "struct object *resultobj"); Printv(description, ", ", NIL); - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - Replaceall(tm,"$source", "result"); - Replaceall(tm,"$target", "resultobj"); - Replaceall(tm,"$result", "resultobj"); - if (GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","1"); + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "1"); } else { - Replaceall(tm,"$owner","0"); + Replaceall(tm, "$owner", "0"); } String *pikedesc = Getattr(n, "tmap:out:pikedesc"); if (pikedesc) { Printv(description, pikedesc, NIL); } - Printf(f->code,"%s\n", tm); + Printf(f->code, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(d,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } } /* Output argument output code */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } } /* See if there is any return cleanup code */ if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } - + /* Close the function */ Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); - + Replaceall(f->code, "$cleanup", cleanup); + /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); - Replaceall(f->code,"$result","resultobj"); + Replaceall(f->code, "$symname", iname); + Replaceall(f->code, "$result", "resultobj"); /* Dump the function out */ - Wrapper_print(f,f_wrappers); + Wrapper_print(f, f_wrappers); /* Now register the function with the interpreter. */ - if (!Getattr(n,"sym:overloaded")) { + if (!Getattr(n, "sym:overloaded")) { add_method(iname, wname, description); } else { - Setattr(n,"wrap:name", wname); - if (!Getattr(n,"sym:nextSibling")) { + Setattr(n, "wrap:name", wname); + if (!Getattr(n, "sym:nextSibling")) { dispatchFunction(n); } } @@ -495,32 +496,32 @@ public: int maxargs; String *tmp = NewString(""); String *dispatch = Swig_overload_dispatch(n, "%s(args); return;", &maxargs); - + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *f = NewWrapper(); - String *symname = Getattr(n,"sym:name"); - String *wname = Swig_name_wrapper(symname); + Wrapper *f = NewWrapper(); + String *symname = Getattr(n, "sym:name"); + String *wname = Swig_name_wrapper(symname); Printf(f->def, "static void %s(INT32 args) {", wname); - + Wrapper_add_local(f, "argc", "INT32 argc"); Printf(tmp, "struct svalue argv[%d]", maxargs); Wrapper_add_local(f, "argv", tmp); Wrapper_add_local(f, "ii", "INT32 ii"); - + Printf(f->code, "argc = args;\n"); Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs); Printf(f->code, "argv[ii] = Pike_sp[ii-args];\n"); Printf(f->code, "}\n"); - + Replaceall(dispatch, "$args", "self, args"); Printv(f->code, dispatch, "\n", NIL); Printf(f->code, "Pike_error(\"No matching function for overloaded '%s'.\");\n", symname); Printv(f->code, "}\n", NIL); - + Wrapper_print(f, f_wrappers); - + String *description = NewString(""); Printf(description, "tAny,"); if (current == CONSTRUCTOR || current == DESTRUCTOR) { @@ -553,12 +554,12 @@ public: virtual int constantWrapper(Node *n) { - Swig_require("constantWrapper",n, "*sym:name", "type", "value", NIL); - + Swig_require("constantWrapper", n, "*sym:name", "type", "value", NIL); + String *symname = Getattr(n, "sym:name"); - SwigType *type = Getattr(n, "type"); - String *value = Getattr(n, "value"); - + SwigType *type = Getattr(n, "type"); + String *value = Getattr(n, "value"); + /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(symname); @@ -575,12 +576,11 @@ public: Replaceall(tm, "$value", value); Printf(f_init, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value); } Swig_restore(n); - + return SWIG_OK; } @@ -590,19 +590,20 @@ public: virtual int nativeWrapper(Node *n) { // return Language::nativeWrapper(n); - String *name = Getattr(n,"sym:name"); - String *wrapname = Getattr(n,"wrap:name"); + String *name = Getattr(n, "sym:name"); + String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname,n)) return SWIG_ERROR; + if (!addSymbol(wrapname, n)) + return SWIG_ERROR; - add_method(name, wrapname,0); + add_method(name, wrapname, 0); return SWIG_OK; - } + } /* ------------------------------------------------------------ * enumDeclaration() * ------------------------------------------------------------ */ - + virtual int enumDeclaration(Node *n) { return Language::enumDeclaration(n); } @@ -610,7 +611,7 @@ public: /* ------------------------------------------------------------ * enumvalueDeclaration() * ------------------------------------------------------------ */ - + virtual int enumvalueDeclaration(Node *n) { return Language::enumvalueDeclaration(n); } @@ -622,7 +623,7 @@ public: virtual int classDeclaration(Node *n) { return Language::classDeclaration(n); } - + /* ------------------------------------------------------------ * classHandler() * ------------------------------------------------------------ */ @@ -632,45 +633,45 @@ public: String *symname = Getattr(n, "sym:name"); if (!addSymbol(symname, n)) return SWIG_ERROR; - + PrefixPlusUnderscore = NewStringf("%s_", getClassPrefix()); Printf(f_classInit, "start_new_program();\n"); /* Handle inheritance */ - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist) > 0) { Iterator base = First(baselist); while (base.item) { - String *basename = Getattr(base.item,"name"); - SwigType *basetype = NewString(basename); - SwigType_add_pointer(basetype); - SwigType_remember(basetype); - String *basemangle = SwigType_manglestr(basetype); - Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle); + String *basename = Getattr(base.item, "name"); + SwigType *basetype = NewString(basename); + SwigType_add_pointer(basetype); + SwigType_remember(basetype); + String *basemangle = SwigType_manglestr(basetype); + Printf(f_classInit, "low_inherit((struct program *) SWIGTYPE%s->clientdata, 0, 0, 0, 0, 0);\n", basemangle); Delete(basemangle); Delete(basetype); - base = Next(base); + base = Next(base); } } else { Printf(f_classInit, "ADD_STORAGE(swig_object_wrapper);\n"); } - + Language::classHandler(n); - + /* Accessors for member variables */ /* - List *membervariables = Getattr(n,"membervariables"); - if (membervariables && Len(membervariables) > 0) { - membervariableAccessors(membervariables); - } - */ - + List *membervariables = Getattr(n,"membervariables"); + if (membervariables && Len(membervariables) > 0) { + membervariableAccessors(membervariables); + } + */ + /* Done, close the class and dump its definition to the init function */ Printf(f_classInit, "add_program_constant(\"%s\", pr = end_program(), 0);\n", symname); Dump(f_classInit, f_init); Clear(f_classInit); - + SwigType *tt = NewString(symname); SwigType_add_pointer(tt); SwigType_remember(tt); @@ -678,8 +679,9 @@ public: Printf(f_init, "SWIG_TypeClientData(SWIGTYPE%s, (void *) pr);\n", tm); Delete(tm); Delete(tt); - - Delete(PrefixPlusUnderscore); PrefixPlusUnderscore = 0; + + Delete(PrefixPlusUnderscore); + PrefixPlusUnderscore = 0; return SWIG_OK; } @@ -720,7 +722,7 @@ public: current = NO_CPP; return SWIG_OK; } - + /* ------------------------------------------------------------ * membervariableAccessors() * ------------------------------------------------------------ */ @@ -730,18 +732,18 @@ public: Iterator i; bool need_setter; String *funcname; - + /* If at least one of them is mutable, we need a setter */ need_setter = false; i = First(membervariables); while (i.item) { if (!GetFlag(i.item, "feature:immutable")) { - need_setter = true; + need_setter = true; break; } i = Next(i); } - + /* Create a function to set the values of the (mutable) variables */ if (need_setter) { Wrapper *wrapper = NewWrapper(); @@ -749,7 +751,7 @@ public: String *wname = Swig_name_wrapper(setter); Printv(wrapper->def, "static void ", wname, "(INT32 args) {", NIL); Printf(wrapper->locals, "char *name = (char *) STR0(Pike_sp[0-args].u.string);\n"); - + i = First(membervariables); while (i.item) { if (!GetFlag(i.item, "feature:immutable")) { @@ -770,7 +772,7 @@ public: /* Dump wrapper code to the output file */ Wrapper_print(wrapper, f_wrappers); - + /* Register it with Pike */ String *description = NewString("tStr tFloat, tVoid"); add_method("`->=", wname, description); @@ -781,7 +783,7 @@ public: Delete(setter); DelWrapper(wrapper); } - + /* Create a function to get the values of the (mutable) variables */ Wrapper *wrapper = NewWrapper(); String *getter = Swig_name_member(getClassPrefix(), (char *) "`->"); @@ -807,12 +809,12 @@ public: /* Dump wrapper code to the output file */ Wrapper_print(wrapper, f_wrappers); - + /* Register it with Pike */ String *description = NewString("tStr, tMix"); add_method("`->", wname, description); Delete(description); - + /* Clean up */ Delete(wname); Delete(getter); @@ -824,12 +826,12 @@ public: * ------------------------------------------------------------ */ virtual int membervariableHandler(Node *n) { - List *membervariables = Getattr(getCurrentClass(),"membervariables"); + List *membervariables = Getattr(getCurrentClass(), "membervariables"); if (!membervariables) { membervariables = NewList(); - Setattr(getCurrentClass(),"membervariables",membervariables); + Setattr(getCurrentClass(), "membervariables", membervariables); } - Append(membervariables,n); + Append(membervariables, n); current = MEMBER_VAR; Language::membervariableHandler(n); current = NO_CPP; @@ -848,7 +850,7 @@ public: current = NO_CPP; return SWIG_OK; } - + /* ------------------------------------------------------------ * memberconstantHandler() * @@ -878,9 +880,9 @@ public: * swig_pike() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_pike() { +static Language *new_swig_pike() { return new PIKE(); } -extern "C" Language * swig_pike(void) { +extern "C" Language *swig_pike(void) { return new_swig_pike(); } diff --git a/SWIG/Source/Modules/python.cxx b/SWIG/Source/Modules/python.cxx index eb7b98383..c5025d569 100644 --- a/SWIG/Source/Modules/python.cxx +++ b/SWIG/Source/Modules/python.cxx @@ -21,66 +21,66 @@ static int treduce = SWIG_cparse_template_reduce(0); #define PYSHADOW_MEMBER 0x2 -static String *const_code = 0; -static String *module = 0; -static String *package = 0; -static String *mainmodule = 0; -static String *interface = 0; -static String *global_name = 0; -static int shadow = 1; -static int use_kw = 0; -static int director_method_index = 0; +static String *const_code = 0; +static String *module = 0; +static String *package = 0; +static String *mainmodule = 0; +static String *interface = 0; +static String *global_name = 0; +static int shadow = 1; +static int use_kw = 0; +static int director_method_index = 0; -static File *f_runtime = 0; -static File *f_runtime_h = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_directors = 0; -static File *f_directors_h = 0; -static File *f_init = 0; -static File *f_shadow_py = 0; -static String *f_shadow = 0; -static String *f_shadow_imports = 0; -static String *f_shadow_stubs = 0; +static File *f_runtime = 0; +static File *f_runtime_h = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_directors = 0; +static File *f_directors_h = 0; +static File *f_init = 0; +static File *f_shadow_py = 0; +static String *f_shadow = 0; +static String *f_shadow_imports = 0; +static String *f_shadow_stubs = 0; -static String *methods; -static String *class_name; -static String *shadow_indent = 0; -static int in_class = 0; -static int classic = 0; -static int modern = 0; -static int apply = 0; -static int new_repr = 1; -static int no_header_file = 0; +static String *methods; +static String *class_name; +static String *shadow_indent = 0; +static int in_class = 0; +static int classic = 0; +static int modern = 0; +static int apply = 0; +static int new_repr = 1; +static int no_header_file = 0; /* C++ Support + Shadow Classes */ -static int have_constructor; -static int have_repr; -static String *real_classname; +static int have_constructor; +static int have_repr; +static String *real_classname; /* Thread Support */ -static int threads = 0; -static int nothreads = 0; -static int classptr = 0; +static int threads = 0; +static int nothreads = 0; +static int classptr = 0; /* Other options */ -static int shadowimport = 1; -static int buildnone = 0; -static int nobuildnone = 0; -static int safecstrings = 0; -static int dirvtable = 0; -static int proxydel = 1; -static int fastunpack = 0; -static int fastproxy = 0; -static int fastquery = 0; -static int fastinit = 0; -static int olddefs = 0; -static int modernargs = 0; -static int aliasobj0 = 0; -static int castmode = 0; -static int extranative = 0; -static int outputtuple = 0; -static int nortti = 0; +static int shadowimport = 1; +static int buildnone = 0; +static int nobuildnone = 0; +static int safecstrings = 0; +static int dirvtable = 0; +static int proxydel = 1; +static int fastunpack = 0; +static int fastproxy = 0; +static int fastquery = 0; +static int fastinit = 0; +static int olddefs = 0; +static int modernargs = 0; +static int aliasobj0 = 0; +static int castmode = 0; +static int extranative = 0; +static int outputtuple = 0; +static int nortti = 0; /* flags for the make_autodoc function */ enum autodoc_t { @@ -93,11 +93,11 @@ enum autodoc_t { }; -static const char *usage1 = (char *)"\ +static const char *usage1 = (char *) "\ Python Options (available with -python)\n\ -aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\ -apply - Use apply() in proxy classes\n\ - -buildnone - Use Py_BuildValue("") to obtain Py_None (default in Windows)\n\ + -buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\ -castmode - Enable the casting mode, which allows implicit cast between types in python\n\ -classic - Use classic classes only\n\ -classptr - Generate shadow 'ClassPtr' as in older swig versions\n\ @@ -113,7 +113,7 @@ Python Options (available with -python)\n\ -keyword - Use keyword arguments\n\ -modern - Use modern python features only, without compatibility code\n\ -modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n"; -static const char *usage2 = (char *)"\ +static const char *usage2 = (char *) "\ -newrepr - Use more informative version of __repr__ in proxy classes (default) \n\ -newvwm - New value wrapper mode, use only when everything else fails \n\ -noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\ @@ -130,7 +130,7 @@ static const char *usage2 = (char *)"\ -noh - Don't generate the output header file\n\ -nomodern - Don't use modern python features which are not back compatible \n\ -nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n"; -static const char *usage3 = (char *)"\ +static const char *usage3 = (char *) "\ -noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\ -nooutputtuple - Use a PyList for appending output values (default) \n\ -noproxy - Don't generate proxy classes \n\ @@ -150,19 +150,15 @@ static const char *usage3 = (char *)"\ -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone \n\ \n"; -class PYTHON : public Language { +class PYTHON:public Language { public: - PYTHON() - { + PYTHON() { /* Add code to manage protected constructors and directors */ - director_prot_ctor_code = NewString(""); + director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", - "} else {\n", - " SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing abstract class or protected constructor\"); \n", - " SWIG_fail;\n", - "}\n", NIL); + "} else {\n", " SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing abstract class or protected constructor\"); \n", " SWIG_fail;\n", "}\n", NIL); director_multiple_inheritance = 1; director_language = 1; } @@ -170,33 +166,33 @@ public: /* ------------------------------------------------------------ * Thread Implementation * ------------------------------------------------------------ */ - + int threads_enable(Node *n) const { return threads && !GetFlagAttr(n, "feature:nothread"); } - + int initialize_threads(String *f_init) { if (!threads) { return SWIG_OK; } - Printf(f_init,"\n"); - Printf(f_init,"/* Initialize threading */\n"); - Printf(f_init,"SWIG_PYTHON_INITIALIZE_THREADS;\n"); - + Printf(f_init, "\n"); + Printf(f_init, "/* Initialize threading */\n"); + Printf(f_init, "SWIG_PYTHON_INITIALIZE_THREADS;\n"); + return SWIG_OK; } - + virtual void thread_begin_block(Node *n, String *f) { if (!GetFlag(n, "feature:nothreadblock")) { - String *bb = Getattr(n,"feature:threadbeginblock"); + String *bb = Getattr(n, "feature:threadbeginblock"); if (bb) { Append(f, bb); } else { - Append(f,"SWIG_PYTHON_THREAD_BEGIN_BLOCK;\n"); - } + Append(f, "SWIG_PYTHON_THREAD_BEGIN_BLOCK;\n"); + } } } - + virtual void thread_end_block(Node *n, String *f) { if (!GetFlag(n, "feature:nothreadblock")) { String *eb = Getattr(n, "feature:threadendblock"); @@ -218,7 +214,7 @@ public: } } } - + virtual void thread_end_allow(Node *n, String *f) { if (!GetFlag(n, "feature:nothreadallow")) { String *eb = Getattr(n, "feature:threadendallow"); @@ -229,189 +225,189 @@ public: } } } - + /* ------------------------------------------------------------ * main() * ------------------------------------------------------------ */ - + virtual void main(int argc, char *argv[]) { int cppcast = 1; SWIG_library_directory("python"); - + for (int i = 1; i < argc; i++) { if (argv[i]) { - if(strcmp(argv[i],"-interface") == 0) { - if (argv[i+1]) { - interface = NewString(argv[i+1]); + if (strcmp(argv[i], "-interface") == 0) { + if (argv[i + 1]) { + interface = NewString(argv[i + 1]); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } /* end added */ - } else if (strcmp(argv[i],"-globals") == 0) { - if (argv[i+1]) { - global_name = NewString(argv[i+1]); + } else if (strcmp(argv[i], "-globals") == 0) { + if (argv[i + 1]) { + global_name = NewString(argv[i + 1]); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } else if ((strcmp(argv[i],"-shadow") == 0) || ((strcmp(argv[i],"-proxy") == 0))) { + } else if ((strcmp(argv[i], "-shadow") == 0) || ((strcmp(argv[i], "-proxy") == 0))) { shadow = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-apply") == 0) { - apply = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-new_repr") == 0) || (strcmp(argv[i],"-newrepr") == 0)) { - new_repr = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-old_repr") == 0) || (strcmp(argv[i],"-oldrepr") == 0)) { - new_repr = 0; - Swig_mark_arg(i); - } else if (strcmp(argv[i],"-classptr") == 0) { - classptr = 1; - Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-noproxy") == 0)) { + } else if (strcmp(argv[i], "-apply") == 0) { + apply = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-new_repr") == 0) || (strcmp(argv[i], "-newrepr") == 0)) { + new_repr = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-old_repr") == 0) || (strcmp(argv[i], "-oldrepr") == 0)) { + new_repr = 0; + Swig_mark_arg(i); + } else if (strcmp(argv[i], "-classptr") == 0) { + classptr = 1; + Swig_mark_arg(i); + } else if ((strcmp(argv[i], "-noproxy") == 0)) { shadow = 0; Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-noproxyimport") == 0)) { + } else if ((strcmp(argv[i], "-noproxyimport") == 0)) { shadowimport = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-keyword") == 0) { + } else if (strcmp(argv[i], "-keyword") == 0) { use_kw = 1; - SWIG_cparse_set_compact_default_args(1); + SWIG_cparse_set_compact_default_args(1); Swig_mark_arg(i); - } else if (strcmp(argv[i],"-classic") == 0) { + } else if (strcmp(argv[i], "-classic") == 0) { classic = 1; - modernargs = 0; + modernargs = 0; apply = 1; modern = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-cppcast") == 0) { + } else if (strcmp(argv[i], "-cppcast") == 0) { cppcast = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocppcast") == 0) { + } else if (strcmp(argv[i], "-nocppcast") == 0) { cppcast = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-outputtuple") == 0) { + } else if (strcmp(argv[i], "-outputtuple") == 0) { outputtuple = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nooutputtuple") == 0) { + } else if (strcmp(argv[i], "-nooutputtuple") == 0) { outputtuple = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nortti") == 0) { + } else if (strcmp(argv[i], "-nortti") == 0) { nortti = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-threads") == 0) { + } else if (strcmp(argv[i], "-threads") == 0) { threads = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nothreads") == 0) { + } else if (strcmp(argv[i], "-nothreads") == 0) { /* Turn off thread suppor mode */ nothreads = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-safecstrings") == 0) { + } else if (strcmp(argv[i], "-safecstrings") == 0) { safecstrings = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nosafecstrings") == 0) { + } else if (strcmp(argv[i], "-nosafecstrings") == 0) { safecstrings = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-buildnone") == 0) { + } else if (strcmp(argv[i], "-buildnone") == 0) { buildnone = 1; nobuildnone = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nobuildnone") == 0) { + } else if (strcmp(argv[i], "-nobuildnone") == 0) { buildnone = 0; nobuildnone = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-dirvtable") == 0) { + } else if (strcmp(argv[i], "-dirvtable") == 0) { dirvtable = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nodirvtable") == 0) { + } else if (strcmp(argv[i], "-nodirvtable") == 0) { dirvtable = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fastunpack") == 0) { + } else if (strcmp(argv[i], "-fastunpack") == 0) { fastunpack = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nofastunpack") == 0) { + } else if (strcmp(argv[i], "-nofastunpack") == 0) { fastunpack = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fastproxy") == 0) { + } else if (strcmp(argv[i], "-fastproxy") == 0) { fastproxy = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nofastproxy") == 0) { + } else if (strcmp(argv[i], "-nofastproxy") == 0) { fastproxy = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fastquery") == 0) { + } else if (strcmp(argv[i], "-fastquery") == 0) { fastquery = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nofastquery") == 0) { + } else if (strcmp(argv[i], "-nofastquery") == 0) { fastquery = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-fastinit") == 0) { + } else if (strcmp(argv[i], "-fastinit") == 0) { fastinit = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nofastinit") == 0) { + } else if (strcmp(argv[i], "-nofastinit") == 0) { fastinit = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-olddefs") == 0) { + } else if (strcmp(argv[i], "-olddefs") == 0) { olddefs = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noolddefs") == 0) { + } else if (strcmp(argv[i], "-noolddefs") == 0) { olddefs = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-castmode") == 0) { + } else if (strcmp(argv[i], "-castmode") == 0) { castmode = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocastmode") == 0) { + } else if (strcmp(argv[i], "-nocastmode") == 0) { castmode = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-extranative") == 0) { + } else if (strcmp(argv[i], "-extranative") == 0) { extranative = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noextranative") == 0) { + } else if (strcmp(argv[i], "-noextranative") == 0) { extranative = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-modernargs") == 0) { + } else if (strcmp(argv[i], "-modernargs") == 0) { modernargs = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nomodernargs") == 0) { + } else if (strcmp(argv[i], "-nomodernargs") == 0) { modernargs = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-aliasobj0") == 0) { + } else if (strcmp(argv[i], "-aliasobj0") == 0) { aliasobj0 = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noaliasobj0") == 0) { + } else if (strcmp(argv[i], "-noaliasobj0") == 0) { aliasobj0 = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-proxydel") == 0) { + } else if (strcmp(argv[i], "-proxydel") == 0) { proxydel = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noproxydel") == 0) { + } else if (strcmp(argv[i], "-noproxydel") == 0) { proxydel = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-modern") == 0) { + } else if (strcmp(argv[i], "-modern") == 0) { apply = 0; classic = 0; - modern = 1; + modern = 1; modernargs = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nomodern") == 0) { - modern = 0; - modernargs = 0; + } else if (strcmp(argv[i], "-nomodern") == 0) { + modern = 0; + modernargs = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noh") == 0) { + } else if (strcmp(argv[i], "-noh") == 0) { no_header_file = 1; Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-new_vwm") == 0) || (strcmp(argv[i],"-newvwm") == 0)) { + } else if ((strcmp(argv[i], "-new_vwm") == 0) || (strcmp(argv[i], "-newvwm") == 0)) { /* Turn on new value wrapper mpde */ - Swig_value_wrapper_mode(1); + Swig_value_wrapper_mode(1); no_header_file = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-O") == 0) { + } else if (strcmp(argv[i], "-O") == 0) { apply = 0; classic = 0; modern = 1; @@ -429,10 +425,10 @@ public: Wrapper_fast_dispatch_mode_set(1); Wrapper_virtual_elimination_mode_set(1); Swig_mark_arg(i); - } else if (strcmp(argv[i],"-help") == 0) { - fputs(usage1,stdout); - fputs(usage2,stdout); - fputs(usage3,stdout); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage1, stdout); + fputs(usage2, stdout); + fputs(usage3, stdout); } } } @@ -441,7 +437,8 @@ public: Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); } - if (!global_name) global_name = NewString("cvar"); + if (!global_name) + global_name = NewString("cvar"); Preprocessor_define("SWIGPYTHON 1", 0); SWIG_typemap_lang("python"); SWIG_config_file("python.swg"); @@ -462,47 +459,48 @@ public: * use %module(directors="1") modulename at the start of the * interface file to enable director generation. */ - String* mod_docstring = NULL; + String *mod_docstring = NULL; { Node *mod = Getattr(n, "module"); if (mod) { - Node *options = Getattr(mod, "options"); - if (options) { - int dirprot = 0; - if (Getattr(options, "dirprot")) { + Node *options = Getattr(mod, "options"); + if (options) { + int dirprot = 0; + if (Getattr(options, "dirprot")) { dirprot = 1; - } - if (Getattr(options, "nodirprot")) { + } + if (Getattr(options, "nodirprot")) { dirprot = 0; - } - if (Getattr(options, "directors")) { - allow_directors(); - if (dirprot) allow_dirprot(); - } - if (Getattr(options, "threads")) { - threads = 1; - } - if (Getattr(options, "castmode")) { - castmode = 1; - } - if (Getattr(options, "nocastmode")) { - castmode = 0; - } - if (Getattr(options, "extranative")) { - extranative = 1; - } - if (Getattr(options, "noextranative")) { - extranative = 0; - } - if (Getattr(options, "outputtuple")) { - outputtuple = 1; - } - if (Getattr(options, "nooutputtuple")) { - outputtuple = 0; - } - mod_docstring = Getattr(options, "docstring"); - package = Getattr(options, "package"); - } + } + if (Getattr(options, "directors")) { + allow_directors(); + if (dirprot) + allow_dirprot(); + } + if (Getattr(options, "threads")) { + threads = 1; + } + if (Getattr(options, "castmode")) { + castmode = 1; + } + if (Getattr(options, "nocastmode")) { + castmode = 0; + } + if (Getattr(options, "extranative")) { + extranative = 1; + } + if (Getattr(options, "noextranative")) { + extranative = 0; + } + if (Getattr(options, "outputtuple")) { + outputtuple = 1; + } + if (Getattr(options, "nooutputtuple")) { + outputtuple = 0; + } + mod_docstring = Getattr(options, "docstring"); + package = Getattr(options, "package"); + } } } @@ -510,18 +508,18 @@ public: setSubclassInstanceCheck(NewString("$arg != Py_None")); /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - String *outfile_h = !no_header_file ? Getattr(n, "outfile_h"): 0; + String *outfile = Getattr(n, "outfile"); + String *outfile_h = !no_header_file ? Getattr(n, "outfile_h") : 0; - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); } - + if (directorsEnabled()) { if (!no_header_file) { - f_runtime_h = NewFile(outfile_h,"w"); + f_runtime_h = NewFile(outfile_h, "w"); if (!f_runtime_h) { FileErrorDisplay(outfile_h); SWIG_exit(EXIT_FAILURE); @@ -538,104 +536,104 @@ public: f_directors = NewString(""); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - Swig_register_filebyname("director",f_directors); - Swig_register_filebyname("director_h",f_directors_h); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); - const_code = NewString(""); - methods = NewString(""); + const_code = NewString(""); + methods = NewString(""); Swig_banner(f_runtime); - Printf(f_runtime,"#define SWIGPYTHON\n"); + Printf(f_runtime, "#define SWIGPYTHON\n"); if (directorsEnabled()) { - Printf(f_runtime,"#define SWIG_DIRECTORS\n"); + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); } if (nothreads) { - Printf(f_runtime,"#define SWIG_PYTHON_NO_THREADS\n"); + Printf(f_runtime, "#define SWIG_PYTHON_NO_THREADS\n"); } else if (threads) { - Printf(f_runtime,"#define SWIG_PYTHON_THREADS\n"); + Printf(f_runtime, "#define SWIG_PYTHON_THREADS\n"); } if (safecstrings) { - Printf(f_runtime,"#define SWIG_PYTHON_SAFE_CSTRINGS\n"); + Printf(f_runtime, "#define SWIG_PYTHON_SAFE_CSTRINGS\n"); } if (buildnone) { - Printf(f_runtime,"#define SWIG_PYTHON_BUILD_NONE\n"); + Printf(f_runtime, "#define SWIG_PYTHON_BUILD_NONE\n"); } if (nobuildnone) { - Printf(f_runtime,"#define SWIG_PYTHON_NO_BUILD_NONE\n"); + Printf(f_runtime, "#define SWIG_PYTHON_NO_BUILD_NONE\n"); } if (!dirvtable) { - Printf(f_runtime,"#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n"); + Printf(f_runtime, "#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n"); } if (outputtuple) { - Printf(f_runtime,"#define SWIG_PYTHON_OUTPUT_TUPLE\n"); + Printf(f_runtime, "#define SWIG_PYTHON_OUTPUT_TUPLE\n"); } if (nortti) { - Printf(f_runtime,"#ifndef SWIG_DIRECTOR_NORTTI\n"); - Printf(f_runtime,"#define SWIG_DIRECTOR_NORTTI\n"); - Printf(f_runtime,"#endif\n"); + Printf(f_runtime, "#ifndef SWIG_DIRECTOR_NORTTI\n"); + Printf(f_runtime, "#define SWIG_DIRECTOR_NORTTI\n"); + Printf(f_runtime, "#endif\n"); } if (castmode) { - Printf(f_runtime,"#define SWIG_CASTRANK_MODE\n"); - Printf(f_runtime,"#define SWIG_PYTHON_CAST_MODE\n"); + Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n"); + Printf(f_runtime, "#define SWIG_PYTHON_CAST_MODE\n"); } if (extranative) { - Printf(f_runtime,"#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS\n"); + Printf(f_runtime, "#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS\n"); } if (classic) { - Printf(f_runtime,"#define SWIG_PYTHON_CLASSIC\n"); + Printf(f_runtime, "#define SWIG_PYTHON_CLASSIC\n"); } - Printf(f_header,"#if (PY_VERSION_HEX <= 0x02000000)\n"); - Printf(f_header,"# if !defined(SWIG_PYTHON_CLASSIC)\n"); - Printf(f_header,"# error \"This python version requires swig to be run with the '-classic' option\"\n"); - Printf(f_header,"# endif\n"); - Printf(f_header,"#endif\n"); - + Printf(f_header, "#if (PY_VERSION_HEX <= 0x02000000)\n"); + Printf(f_header, "# if !defined(SWIG_PYTHON_CLASSIC)\n"); + Printf(f_header, "# error \"This python version requires swig to be run with the '-classic' option\"\n"); + Printf(f_header, "# endif\n"); + Printf(f_header, "#endif\n"); + if (modern) { - Printf(f_header,"#if (PY_VERSION_HEX <= 0x02020000)\n"); - Printf(f_header,"# error \"This python version requires swig to be run with the '-nomodern' option\"\n"); - Printf(f_header,"#endif\n"); + Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n"); + Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodern' option\"\n"); + Printf(f_header, "#endif\n"); } if (modernargs) { - Printf(f_header,"#if (PY_VERSION_HEX <= 0x02020000)\n"); - Printf(f_header,"# error \"This python version requires swig to be run with the '-nomodernargs' option\"\n"); - Printf(f_header,"#endif\n"); + Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n"); + Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodernargs' option\"\n"); + Printf(f_header, "#endif\n"); } - + if (fastunpack) { - Printf(f_header,"#ifndef METH_O\n"); - Printf(f_header,"# error \"This python version requires swig to be run with the '-nofastunpack' option\"\n"); - Printf(f_header,"#endif\n"); + Printf(f_header, "#ifndef METH_O\n"); + Printf(f_header, "# error \"This python version requires swig to be run with the '-nofastunpack' option\"\n"); + Printf(f_header, "#endif\n"); } if (fastquery) { - Printf(f_header,"#ifdef SWIG_TypeQuery\n"); - Printf(f_header,"# undef SWIG_TypeQuery\n"); - Printf(f_header,"#endif\n"); - Printf(f_header,"#define SWIG_TypeQuery SWIG_Python_TypeQuery\n"); + Printf(f_header, "#ifdef SWIG_TypeQuery\n"); + Printf(f_header, "# undef SWIG_TypeQuery\n"); + Printf(f_header, "#endif\n"); + Printf(f_header, "#define SWIG_TypeQuery SWIG_Python_TypeQuery\n"); } /* Set module name */ - module = Copy(Getattr(n,"name")); - mainmodule = Getattr(n,"name"); + module = Copy(Getattr(n, "name")); + mainmodule = Getattr(n, "name"); if (directorsEnabled()) { Swig_banner(f_directors_h); @@ -651,157 +649,123 @@ public: Printf(f_directors, " * C++ director class methods\n"); Printf(f_directors, " * --------------------------------------------------- */\n\n"); if (outfile_h) - Printf(f_directors, "#include \"%s\"\n\n",Swig_file_filename(outfile_h)); + Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h)); } /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (shadow) { String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module)); // If we don't have an interface then change the module name X to _X - if (interface) module = interface; - else Insert(module,0,"_"); - if ((f_shadow_py = NewFile(filen,"w")) == 0) { + if (interface) + module = interface; + else + Insert(module, 0, "_"); + if ((f_shadow_py = NewFile(filen, "w")) == 0) { FileErrorDisplay(filen); - SWIG_exit (EXIT_FAILURE); + SWIG_exit(EXIT_FAILURE); } - Delete(filen); filen = NULL; + Delete(filen); + filen = NULL; f_shadow = NewString(""); f_shadow_imports = NewString(""); f_shadow_stubs = NewString(""); - Swig_register_filebyname("shadow",f_shadow); - Swig_register_filebyname("python",f_shadow); + Swig_register_filebyname("shadow", f_shadow); + Swig_register_filebyname("python", f_shadow); Printv(f_shadow, - "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", - "# Don't modify this file, modify the SWIG interface instead.\n", - NIL); + "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", "# Don't modify this file, modify the SWIG interface instead.\n", NIL); - if (! modern) { - Printv(f_shadow, - "# This file is compatible with both classic and new-style classes.\n", - NIL); + if (!modern) { + Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL); } if (mod_docstring && Len(mod_docstring)) { - Printv(f_shadow, "\n\"\"\"\n", mod_docstring, "\n\"\"\"\n", NIL); - Delete(mod_docstring); mod_docstring = NULL; + Printv(f_shadow, "\n\"\"\"\n", mod_docstring, "\n\"\"\"\n", NIL); + Delete(mod_docstring); + mod_docstring = NULL; } - - Printf(f_shadow,"\nimport %s\n", module); - Printv(f_shadow,"import new\n",NULL); - Printv(f_shadow,"new_instancemethod = new.instancemethod\n",NULL); + Printf(f_shadow, "\nimport %s\n", module); + + Printv(f_shadow, "import new\n", NULL); + Printv(f_shadow, "new_instancemethod = new.instancemethod\n", NULL); if (modern || !classic) { - Printv(f_shadow, - "try:\n", - tab4, "_swig_property = property\n", - "except NameError:\n", - tab4, "pass # Python < 2.2 doesn't have 'property'.\n", - NULL); + Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL); } /* if (!modern) */ /* always needed, a class can be forced to be no-modern, such as an exception */ - { - // Python-2.2 object hack - Printv(f_shadow, - "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", - tab4, "if (name == \"thisown\"): return self.this.own(value)\n", - tab4, "if (name == \"this\"):\n", - tab4, tab4, "if type(value).__name__ == 'PySwigObject':\n", - tab4, tab8, "self.__dict__[name] = value\n", + { + // Python-2.2 object hack + Printv(f_shadow, + "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n", + tab4, "if (name == \"thisown\"): return self.this.own(value)\n", + tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'PySwigObject':\n", tab4, tab8, "self.__dict__[name] = value\n", #ifdef USE_THISOWN - tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", - tab4, tab8, "del value.thisown\n", + tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n", #endif - tab4, tab8, "return\n", - tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", - tab4, "if method: return method(self,value)\n", + tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n", #ifdef USE_THISOWN tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", #else tab4, "if (not static) or hasattr(self,name):\n", #endif - tab4, tab4, "self.__dict__[name] = value\n", + tab4, tab4, "self.__dict__[name] = value\n", tab4, "else:\n", tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", - "def _swig_setattr(self,class_type,name,value):\n", - tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", - NIL); + "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL); - Printv(f_shadow, - "def _swig_getattr(self,class_type,name):\n", - tab4, "if (name == \"thisown\"): return self.this.own()\n", - tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", - tab4, "if method: return method(self)\n", - tab4, "raise AttributeError,name\n\n", - NIL); + Printv(f_shadow, + "def _swig_getattr(self,class_type,name):\n", + tab4, "if (name == \"thisown\"): return self.this.own()\n", + tab4, "method = class_type.__swig_getmethods__.get(name,None)\n", + tab4, "if method: return method(self)\n", tab4, "raise AttributeError,name\n\n", NIL); - Printv(f_shadow, + Printv(f_shadow, "def _swig_repr(self):\n", tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n", - tab4, "except: strthis = \"\"\n", - tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", - NIL); + tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL); - if (!classic) { - Printv(f_shadow, - "import types\n", - "try:\n", - " _object = types.ObjectType\n", - " _newclass = 1\n", - "except AttributeError:\n", - " class _object : pass\n", - " _newclass = 0\n", - "del types\n", - "\n\n", - NIL); - } + if (!classic) { + Printv(f_shadow, + "import types\n", + "try:\n", + " _object = types.ObjectType\n", + " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n", "del types\n", "\n\n", NIL); + } } if (modern) { - Printv(f_shadow, - "def _swig_setattr_nondynamic_method(set):\n", - tab4, "def set_attr(self,name,value):\n", + Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n", #ifdef USE_THISOWN tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", #else - tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", - tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", + tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n", #endif tab4, tab4, tab4, "set(self,name,value)\n", tab4, tab4, "else:\n", - tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", - tab4, "return set_attr\n\n\n", - NIL); - } - - if (directorsEnabled()) { - // Try loading weakref.proxy, which is only available in Python 2.1 and higher - Printv(f_shadow, - "try:\n", - tab4, "import weakref\n", - tab4, "weakref_proxy = weakref.proxy\n", - "except:\n", - tab4, "weakref_proxy = lambda x: x\n", - "\n\n", - NIL); + tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL); } + if (directorsEnabled()) { + // Try loading weakref.proxy, which is only available in Python 2.1 and higher + Printv(f_shadow, + "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); + } // Include some information in the code - Printf(f_header,"\n/*-----------------------------------------------\n @(target):= %s.so\n\ + Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ ------------------------------------------------*/\n", module); } - Printf(f_header,"#define SWIG_init init%s\n\n", module); - Printf(f_header,"#define SWIG_name \"%s\"\n", module); + Printf(f_header, "#define SWIG_init init%s\n\n", module); + Printf(f_header, "#define SWIG_name \"%s\"\n", module); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"extern \"C\" {\n"); - Printf(f_wrappers,"#endif\n"); - Append(const_code,"static swig_const_info swig_const_table[] = {\n"); - Append(methods,"static PyMethodDef SwigMethods[] = {\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "extern \"C\" {\n"); + Printf(f_wrappers, "#endif\n"); + Append(const_code, "static swig_const_info swig_const_table[] = {\n"); + Append(methods, "static PyMethodDef SwigMethods[] = {\n"); /* emit code */ Language::top(n); @@ -812,46 +776,47 @@ public: } /* Close language module */ - Append(methods,"\t { NULL, NULL, 0, NULL }\n"); - Append(methods,"};\n"); - Printf(f_wrappers,"%s\n",methods); + Append(methods, "\t { NULL, NULL, 0, NULL }\n"); + Append(methods, "};\n"); + Printf(f_wrappers, "%s\n", methods); - SwigType_emit_type_table(f_runtime,f_wrappers); + SwigType_emit_type_table(f_runtime, f_wrappers); Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n"); - Printf(f_wrappers,"%s\n",const_code); + Printf(f_wrappers, "%s\n", const_code); initialize_threads(f_init); - Printf(f_init,"}\n"); + Printf(f_init, "}\n"); - Printf(f_wrappers,"#ifdef __cplusplus\n"); - Printf(f_wrappers,"}\n"); - Printf(f_wrappers,"#endif\n"); + Printf(f_wrappers, "#ifdef __cplusplus\n"); + Printf(f_wrappers, "}\n"); + Printf(f_wrappers, "#endif\n"); if (shadow) { /* - Printf(f_shadow_imports,"\nimport %s\n", module); - Printv(f_shadow_py, f_shadow_imports, "\n",NIL); - */ - Printv(f_shadow_py, f_shadow, "\n",NIL); - Printv(f_shadow_py, f_shadow_stubs, "\n",NIL); + Printf(f_shadow_imports,"\nimport %s\n", module); + Printv(f_shadow_py, f_shadow_imports, "\n",NIL); + */ + Printv(f_shadow_py, f_shadow, "\n", NIL); + Printv(f_shadow_py, f_shadow_stubs, "\n", NIL); Close(f_shadow_py); Delete(f_shadow_py); } /* Close all of the files */ - Dump(f_header,f_runtime); + Dump(f_header, f_runtime); if (directorsEnabled()) { Dump(f_directors_h, f_runtime_h); Printf(f_runtime_h, "\n"); Printf(f_runtime_h, "#endif\n"); - if (f_runtime_h != f_runtime) Close(f_runtime_h); + if (f_runtime_h != f_runtime) + Close(f_runtime_h); Dump(f_directors, f_runtime); } - Dump(f_wrappers,f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Dump(f_wrappers, f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); @@ -871,29 +836,28 @@ public: virtual int importDirective(Node *n) { if (shadow) { - String *modname = Getattr(n,"module"); + String *modname = Getattr(n, "module"); if (modname) { - String *import = NewString("import "); + String *import = NewString("import "); - // Find the module node for this imported module. It should be the - // first child but search just in case. - Node* mod = firstChild(n); - while (mod && Strcmp(nodeType(mod), "module") != 0) - mod = nextSibling(mod); - - // Is the imported module in another package? (IOW, does it use the - // %module(package="name") option and it's different than the package - // of this module.) - Node *options = Getattr(mod, "options"); - String* pkg = options ? Getattr(options, "package") : 0; + // Find the module node for this imported module. It should be the + // first child but search just in case. + Node *mod = firstChild(n); + while (mod && Strcmp(nodeType(mod), "module") != 0) + mod = nextSibling(mod); + + // Is the imported module in another package? (IOW, does it use the + // %module(package="name") option and it's different than the package + // of this module.) + Node *options = Getattr(mod, "options"); + String *pkg = options ? Getattr(options, "package") : 0; if (pkg && (!package || Strcmp(pkg, package) != 0)) { Printf(import, "%s.", pkg); - } - - // finally, output the name of the imported module + } + // finally, output the name of the imported module if (shadowimport) { - if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { + if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) { Printf(import, "_%s\n", modname); if (!Strstr(f_shadow_imports, import)) { Printf(f_shadow, "import %s\n", modname); @@ -901,7 +865,7 @@ public: } } } - + Delete(import); } } @@ -918,7 +882,7 @@ public: String *funcCallHelper(String *name, int kw) { String *str; - + str = NewString(""); if (apply) { Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL); @@ -935,35 +899,38 @@ public: String *pythoncode(String *code, const String *indent) { String *out = NewString(""); String *temp; - char *t; - if (!indent) indent = ""; + char *t; + if (!indent) + indent = ""; temp = NewString(code); t = Char(temp); if (*t == '{') { - Delitem(temp,0); - Delitem(temp,DOH_END); + Delitem(temp, 0); + Delitem(temp, DOH_END); } /* Split the input text into lines */ List *clist = DohSplitLines(temp); Delete(temp); - int initial = 0; + int initial = 0; String *s = 0; Iterator si; /* Get the initial indentation */ - + for (si = First(clist); si.item; si = Next(si)) { s = si.item; if (Len(s)) { char *c = Char(s); while (*c) { - if (!isspace(*c)) break; + if (!isspace(*c)) + break; initial++; c++; } - if (*c && !isspace(*c)) break; + if (*c && !isspace(*c)) + break; else { initial = 0; } @@ -974,9 +941,9 @@ public: if (Len(s) > initial) { char *c = Char(s); c += initial; - Printv(out,indent,c,"\n",NIL); + Printv(out, indent, c, "\n", NIL); } else { - Printv(out,"\n",NIL); + Printv(out, "\n", NIL); } si = Next(si); } @@ -990,24 +957,24 @@ public: * ------------------------------------------------------------ */ enum autodoc_l { - NO_AUTODOC = -2, // no autodoc - STRING_AUTODOC = -1, // use provided string - NAMES_AUTODOC = 0, // only parameter names - TYPES_AUTODOC = 1, // parameter names and types - EXTEND_AUTODOC = 2, // extended documentation and parameter names - EXTEND_TYPES_AUTODOC = 3 // extended documentation and parameter types + names + NO_AUTODOC = -2, // no autodoc + STRING_AUTODOC = -1, // use provided string + NAMES_AUTODOC = 0, // only parameter names + TYPES_AUTODOC = 1, // parameter names and types + EXTEND_AUTODOC = 2, // extended documentation and parameter names + EXTEND_TYPES_AUTODOC = 3 // extended documentation and parameter types + names }; - - + + autodoc_l autodoc_level(String *autodoc) { autodoc_l dlevel = NO_AUTODOC; if (autodoc) { - char *c = Char(autodoc); + char *c = Char(autodoc); if (c && isdigit(c[0])) { dlevel = (autodoc_l) atoi(c); } else { - if (strcmp(c,"extended")== 0) { - dlevel = EXTEND_AUTODOC; + if (strcmp(c, "extended") == 0) { + dlevel = EXTEND_AUTODOC; } else { dlevel = STRING_AUTODOC; } @@ -1015,7 +982,7 @@ public: } return dlevel; } - + /* ------------------------------------------------------------ * have_docstring() @@ -1024,11 +991,10 @@ public: * ------------------------------------------------------------ */ bool have_docstring(Node *n) { - String* str = Getattr(n, "feature:docstring"); - return (str != NULL && Len(str) > 0) || - (Getattr(n,"feature:autodoc") && !GetFlag(n, "feature:noautodoc")); + String *str = Getattr(n, "feature:docstring"); + return (str != NULL && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); } - + /* ------------------------------------------------------------ * docstring() * Get the docstring text, stripping off {} if neccessary, @@ -1036,28 +1002,26 @@ public: * set then it will build a combined docstring. * ------------------------------------------------------------ */ - String *docstring(Node *n, autodoc_t ad_type, const String* indent, - bool use_triple = true) { - String* str = Getattr(n, "feature:docstring"); + String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool use_triple = true) { + String *str = Getattr(n, "feature:docstring"); bool have_ds = (str != NULL && Len(str) > 0); - bool have_auto = (Getattr(n,"feature:autodoc") && !GetFlag(n, "feature:noautodoc")); - const char* triple_double = use_triple ? "\"\"\"" : ""; - String* autodoc = NULL; - String* doc = NULL; + bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); + const char *triple_double = use_triple ? "\"\"\"" : ""; + String *autodoc = NULL; + String *doc = NULL; - if ( have_ds ) { - char* t = Char(str); + if (have_ds) { + char *t = Char(str); if (*t == '{') { - Delitem(str ,0); - Delitem(str,DOH_END); + Delitem(str, 0); + Delitem(str, DOH_END); } } - if ( have_auto ) { + if (have_auto) { autodoc = make_autodoc(n, ad_type); have_auto = (autodoc != NULL && Len(autodoc) > 0); } - // If there is more than one line then make docstrings like this: // // """ @@ -1067,36 +1031,24 @@ public: // // otherwise, put it all on a single line // - if ( have_auto && have_ds ) { // Both autodoc and docstring are present + if (have_auto && have_ds) { // Both autodoc and docstring are present doc = NewString(""); - Printv(doc, triple_double, "\n", - pythoncode(autodoc, indent), "\n", - pythoncode(str, indent), - indent, triple_double, NIL); - } - else if ( !have_auto && have_ds ) { // only docstring + Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), "\n", pythoncode(str, indent), indent, triple_double, NIL); + } else if (!have_auto && have_ds) { // only docstring if (Strchr(str, '\n') == NULL) { - doc = NewStringf("%s%s%s", triple_double, str, triple_double); + doc = NewStringf("%s%s%s", triple_double, str, triple_double); + } else { + doc = NewString(""); + Printv(doc, triple_double, "\n", pythoncode(str, indent), indent, triple_double, NIL); } - else { - doc = NewString(""); - Printv(doc, triple_double, "\n", - pythoncode(str, indent), - indent, triple_double, NIL); - } - } - else if ( have_auto && !have_ds ) { // only autodoc + } else if (have_auto && !have_ds) { // only autodoc if (Strchr(autodoc, '\n') == NULL) { - doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); + doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double); + } else { + doc = NewString(""); + Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), indent, triple_double, NIL); } - else { - doc = NewString(""); - Printv(doc, triple_double, "\n", - pythoncode(autodoc, indent), - indent, triple_double, NIL); - } - } - else + } else doc = NewString(""); // Save the generated strings in the parse tree in case they are used later @@ -1111,91 +1063,94 @@ public: * Generate the documentation for the function parameters * ------------------------------------------------------------ */ - String* make_autodocParmList(Node* n, bool showTypes) { - String* doc = NewString(""); - String* pdocs = Copy(Getattr(n,"feature:pdocs")); - ParmList* plist = CopyParmList(Getattr(n,"parms")); - Parm* p; - Parm* pnext; - Node* lookup; - int lines = 0; + String *make_autodocParmList(Node *n, bool showTypes) { + String *doc = NewString(""); + String *pdocs = Copy(Getattr(n, "feature:pdocs")); + ParmList *plist = CopyParmList(Getattr(n, "parms")); + Parm *p; + Parm *pnext; + Node *lookup; + int lines = 0; const int maxwidth = 50; - if (pdocs) Append(pdocs, "\n"); + if (pdocs) + Append(pdocs, "\n"); - Swig_typemap_attach_parms("in",plist,0); - Swig_typemap_attach_parms("doc",plist,0); - + Swig_typemap_attach_parms("in", plist, 0); + Swig_typemap_attach_parms("doc", plist, 0); + for (p = plist; p; p = pnext) { - String* name = 0; - String* type = 0; - String* value = 0; - String* ptype = 0; - String* pdoc = Getattr(p, "tmap:doc"); + String *name = 0; + String *type = 0; + String *value = 0; + String *ptype = 0; + String *pdoc = Getattr(p, "tmap:doc"); if (pdoc) { name = Getattr(p, "tmap:doc:name"); type = Getattr(p, "tmap:doc:type"); value = Getattr(p, "tmap:doc:value"); ptype = Getattr(p, "tmap:doc:pytype"); } - - name = name ? name : Getattr(p,"name"); + + name = name ? name : Getattr(p, "name"); type = type ? type : Getattr(p, "type"); value = value ? value : Getattr(p, "value"); - String* tm = Getattr(p,"tmap:in"); + String *tm = Getattr(p, "tmap:in"); if (tm) { - pnext = Getattr(p,"tmap:in:next"); + pnext = Getattr(p, "tmap:in:next"); } else { pnext = nextSibling(p); } - if ( Len(doc) ) { - // add a comma to the previous one if any - Append(doc, ", "); + if (Len(doc)) { + // add a comma to the previous one if any + Append(doc, ", "); - // Do we need to wrap a long line? - if ((Len(doc) - lines*maxwidth) > maxwidth) { - Printf(doc, "\n%s", tab4); - lines += 1; - } + // Do we need to wrap a long line? + if ((Len(doc) - lines * maxwidth) > maxwidth) { + Printf(doc, "\n%s", tab4); + lines += 1; + } } - // Do the param type too? if (showTypes) { - type = SwigType_base(type); + type = SwigType_base(type); lookup = Swig_symbol_clookup(type, 0); - if (lookup) type = Getattr(lookup, "sym:name"); - Printf(doc, "%s ", type); + if (lookup) + type = Getattr(lookup, "sym:name"); + Printf(doc, "%s ", type); } if (name) { - Append(doc, name); + Append(doc, name); if (pdoc) { - if (!pdocs) pdocs = NewString("Parameters:\n"); + if (!pdocs) + pdocs = NewString("Parameters:\n"); Printf(pdocs, " %s\n", pdoc); } } else { - Append(doc, "?"); + Append(doc, "?"); } if (value) { - if (Strcmp(value, "NULL") == 0) - value = NewString("None"); - else if (Strcmp(value, "true") == 0 || Strcmp(value, "TRUE") == 0) - value = NewString("True"); + if (Strcmp(value, "NULL") == 0) + value = NewString("None"); + else if (Strcmp(value, "true") == 0 || Strcmp(value, "TRUE") == 0) + value = NewString("True"); else if (Strcmp(value, "false") == 0 || Strcmp(value, "FALSE") == 0) - value = NewString("False"); + value = NewString("False"); else { - lookup = Swig_symbol_clookup(value, 0); - if (lookup) - value = Getattr(lookup, "sym:name"); - } - Printf(doc, "=%s", value); + lookup = Swig_symbol_clookup(value, 0); + if (lookup) + value = Getattr(lookup, "sym:name"); + } + Printf(doc, "=%s", value); } } - if (pdocs) Setattr(n,"feature:pdocs", pdocs); + if (pdocs) + Setattr(n, "feature:pdocs", pdocs); Delete(plist); return doc; } @@ -1210,127 +1165,128 @@ public: * and use it directly. * ------------------------------------------------------------ */ - String* make_autodoc(Node *n, autodoc_t ad_type) { + String *make_autodoc(Node *n, autodoc_t ad_type) { int extended = 0; // If the function is overloaded then this funciton is called // for the last one. Rewind to the first so the docstrings are // in order. - while ( Getattr(n, "sym:previousSibling") ) + while (Getattr(n, "sym:previousSibling")) n = Getattr(n, "sym:previousSibling"); - - String* doc = NewString(""); + + String *doc = NewString(""); while (n) { bool showTypes = false; bool skipAuto = false; - String *autodoc = Getattr(n,"feature:autodoc"); + String *autodoc = Getattr(n, "feature:autodoc"); autodoc_l dlevel = autodoc_level(autodoc); switch (dlevel) { case NO_AUTODOC: break; case NAMES_AUTODOC: - showTypes = false; + showTypes = false; break; case TYPES_AUTODOC: - showTypes = true; + showTypes = true; break; case EXTEND_AUTODOC: extended = 1; - showTypes = false; + showTypes = false; break; case EXTEND_TYPES_AUTODOC: extended = 1; - showTypes = true; + showTypes = true; break; case STRING_AUTODOC: - Append(doc, autodoc); - skipAuto = true; + Append(doc, autodoc); + skipAuto = true; break; } if (!skipAuto) { - String* symname = Getattr(n, "sym:name"); - SwigType* type = Getattr(n, "type"); - - if (type) { - if (Strcmp(type, "void") == 0) - type = NULL; - else { - SwigType* qt = SwigType_typedef_resolve_all(type); - if (SwigType_isenum(qt)) - type = NewString("int"); - else { - type = SwigType_base(type); - Node* lookup = Swig_symbol_clookup(type, 0); - if (lookup) - type = Getattr(lookup, "sym:name"); - } - } - } - - switch ( ad_type ) { - case AUTODOC_CLASS: - { - // Only do the autodoc if there isn't a docstring for the class - String* str = Getattr(n, "feature:docstring"); - if (str == NULL || Len(str) == 0) { - if (CPlusPlus) { - Printf(doc, "Proxy of C++ %s class", class_name); - } else { - Printf(doc, "Proxy of C %s struct", class_name); - } - } - } - break; - case AUTODOC_CTOR: - if ( Strcmp(class_name, symname) == 0) { - String* paramList = make_autodocParmList(n, showTypes); - if (Len(paramList)) - Printf(doc, "__init__(self, %s) -> %s", paramList, class_name); - else - Printf(doc, "__init__(self) -> %s", class_name); - } - else - Printf(doc, "%s(%s) -> %s", symname, make_autodocParmList(n, showTypes), class_name); - break; - - case AUTODOC_DTOR: - Append(doc, "__del__(self)"); - break; - - case AUTODOC_STATICFUNC: - Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); - if (type) Printf(doc, " -> %s", type); - break; - - case AUTODOC_FUNC: - Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); - if (type) Printf(doc, " -> %s", type); - break; + String *symname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); - case AUTODOC_METHOD: - String* paramList = make_autodocParmList(n, showTypes); - if (Len(paramList)) - Printf(doc, "%s(self, %s)", symname, paramList); - else - Printf(doc, "%s(self)", symname); - if (type) Printf(doc, " -> %s", type); - break; - } - } - if (extended) { - String *pdocs = Getattr(n,"feature:pdocs"); - if (pdocs) { - Printv(doc, "\n", pdocs,NULL); + if (type) { + if (Strcmp(type, "void") == 0) + type = NULL; + else { + SwigType *qt = SwigType_typedef_resolve_all(type); + if (SwigType_isenum(qt)) + type = NewString("int"); + else { + type = SwigType_base(type); + Node *lookup = Swig_symbol_clookup(type, 0); + if (lookup) + type = Getattr(lookup, "sym:name"); + } + } + } + + switch (ad_type) { + case AUTODOC_CLASS: + { + // Only do the autodoc if there isn't a docstring for the class + String *str = Getattr(n, "feature:docstring"); + if (str == NULL || Len(str) == 0) { + if (CPlusPlus) { + Printf(doc, "Proxy of C++ %s class", class_name); + } else { + Printf(doc, "Proxy of C %s struct", class_name); + } + } + } + break; + case AUTODOC_CTOR: + if (Strcmp(class_name, symname) == 0) { + String *paramList = make_autodocParmList(n, showTypes); + if (Len(paramList)) + Printf(doc, "__init__(self, %s) -> %s", paramList, class_name); + else + Printf(doc, "__init__(self) -> %s", class_name); + } else + Printf(doc, "%s(%s) -> %s", symname, make_autodocParmList(n, showTypes), class_name); + break; + + case AUTODOC_DTOR: + Append(doc, "__del__(self)"); + break; + + case AUTODOC_STATICFUNC: + Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); + if (type) + Printf(doc, " -> %s", type); + break; + + case AUTODOC_FUNC: + Printf(doc, "%s(%s)", symname, make_autodocParmList(n, showTypes)); + if (type) + Printf(doc, " -> %s", type); + break; + + case AUTODOC_METHOD: + String *paramList = make_autodocParmList(n, showTypes); + if (Len(paramList)) + Printf(doc, "%s(self, %s)", symname, paramList); + else + Printf(doc, "%s(self)", symname); + if (type) + Printf(doc, " -> %s", type); + break; } } - - + if (extended) { + String *pdocs = Getattr(n, "feature:pdocs"); + if (pdocs) { + Printv(doc, "\n", pdocs, NULL); + } + } + // if it's overloaded then get the next decl and loop around again n = Getattr(n, "sym:nextSibling"); if (n) - Append(doc, "\n"); + Append(doc, "\n"); } - + return doc; } @@ -1340,49 +1296,51 @@ public: * ------------------------------------------------------------ */ bool have_pythonprepend(Node *n) { - String* str = Getattr(n, "feature:pythonprepend"); + String *str = Getattr(n, "feature:pythonprepend"); return (str != NULL && Len(str) > 0); } - + /* ------------------------------------------------------------ * pythonprepend() * Get the %pythonprepend code, stripping off {} if neccessary * ------------------------------------------------------------ */ String *pythonprepend(Node *n) { - String* str = Getattr(n, "feature:pythonprepend"); - char* t = Char(str); + String *str = Getattr(n, "feature:pythonprepend"); + char *t = Char(str); if (*t == '{') { - Delitem(str ,0); - Delitem(str,DOH_END); + Delitem(str, 0); + Delitem(str, DOH_END); } return str; } - + /* ------------------------------------------------------------ * have_pythonappend() * Check if there is a %pythonappend directive and it has text * ------------------------------------------------------------ */ bool have_pythonappend(Node *n) { - String* str = Getattr(n, "feature:pythonappend"); - if (!str) str = Getattr(n, "feature:addtofunc"); + String *str = Getattr(n, "feature:pythonappend"); + if (!str) + str = Getattr(n, "feature:addtofunc"); return (str != NULL && Len(str) > 0); } - + /* ------------------------------------------------------------ * pythonappend() * Get the %pythonappend code, stripping off {} if neccessary * ------------------------------------------------------------ */ String *pythonappend(Node *n) { - String* str = Getattr(n, "feature:pythonappend"); - if (!str) str = Getattr(n, "feature:addtofunc"); - - char* t = Char(str); + String *str = Getattr(n, "feature:pythonappend"); + if (!str) + str = Getattr(n, "feature:addtofunc"); + + char *t = Char(str); if (*t == '{') { - Delitem(str ,0); - Delitem(str,DOH_END); + Delitem(str, 0); + Delitem(str, DOH_END); } return str; } @@ -1395,7 +1353,7 @@ public: bool have_addtofunc(Node *n) { return have_pythonappend(n) || have_pythonprepend(n) || have_docstring(n); } - + /* ------------------------------------------------------------ * emitFunctionShadowHelper() @@ -1405,23 +1363,23 @@ public: * ------------------------------------------------------------ */ void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { - if (Getattr(n,"feature:python:callback") || ! have_addtofunc(n) ) { + if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) { /* If there is no addtofunc directive then just assign from the extension module */ Printv(f_dest, name, " = ", module, ".", name, "\n", NIL); } else { /* Otherwise make a wrapper function to insert the code into */ Printv(f_dest, "\ndef ", name, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); - if ( have_docstring(n) ) - Printv(f_dest, ctab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); - if ( have_pythonprepend(n) ) - Printv(f_dest, ctab4, pythonprepend(n), "\n", NIL); - if ( have_pythonappend(n) ) { - Printv(f_dest, ctab4, "val = ", funcCallHelper(name, kw), "\n", NIL); - Printv(f_dest, ctab4, pythonappend(n), "\n", NIL); - Printv(f_dest, ctab4, "return val\n", NIL); + if (have_docstring(n)) + Printv(f_dest, ctab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_dest, ctab4, pythonprepend(n), "\n", NIL); + if (have_pythonappend(n)) { + Printv(f_dest, ctab4, "val = ", funcCallHelper(name, kw), "\n", NIL); + Printv(f_dest, ctab4, pythonappend(n), "\n", NIL); + Printv(f_dest, ctab4, "return val\n", NIL); } else { - Printv(f_dest, ctab4, "return ", funcCallHelper(name, kw), "\n", NIL); - } + Printv(f_dest, ctab4, "return ", funcCallHelper(name, kw), "\n", NIL); + } } } @@ -1432,50 +1390,47 @@ public: * ------------------------------------------------------------ */ int check_kwargs(Node *n) { - return (use_kw || GetFlag(n,"feature:kwargs")) - && !GetFlag(n,"memberset") && !GetFlag(n,"memberget"); + return (use_kw || GetFlag(n, "feature:kwargs")) + && !GetFlag(n, "memberset") && !GetFlag(n, "memberget"); } - + /* ------------------------------------------------------------ * add_method() * ------------------------------------------------------------ */ - void add_method(String *name, String *function, int kw, Node *n = 0, - int funpack = 0, int num_required = -1, int num_arguments = -1) { + void add_method(String *name, String *function, int kw, Node *n = 0, int funpack = 0, int num_required = -1, int num_arguments = -1) { if (!kw) { if (n && funpack) { if (num_required == 0 && num_arguments == 0) { - Printf(methods,"\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); - } else if (num_required == 1 && num_arguments == 1) { - Printf(methods,"\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); + Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); + } else if (num_required == 1 && num_arguments == 1) { + Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); } else { - Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); - } + Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + } } else { - Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); + Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); } } else { - Printf(methods,"\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); + Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); } - - if (n && Getattr(n,"feature:callback")) { - if (have_docstring(n)) { - String* ds = docstring(n, AUTODOC_FUNC, "", false); - Replaceall(ds, "\n", "\\n"); - Printf(methods,"(char *)\"%s\\nswig_ptr: %s\"", - ds, - Getattr(n,"feature:callback:name")); - } else { - Printf(methods,"(char *)\"swig_ptr: %s\"",Getattr(n,"feature:callback:name")); - } - } else { - Append(methods,"NULL"); - } - - Append(methods,"},\n"); + if (n && Getattr(n, "feature:callback")) { + if (have_docstring(n)) { + String *ds = docstring(n, AUTODOC_FUNC, "", false); + Replaceall(ds, "\n", "\\n"); + Printf(methods, "(char *)\"%s\\nswig_ptr: %s\"", ds, Getattr(n, "feature:callback:name")); + } else { + Printf(methods, "(char *)\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); + } + } else { + Append(methods, "NULL"); + } + + + Append(methods, "},\n"); } /* ------------------------------------------------------------ @@ -1492,79 +1447,75 @@ public: const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; if (castmode) { - dispatch = Swig_overload_dispatch_cast(n,dispatch_code,&maxargs); + dispatch = Swig_overload_dispatch_cast(n, dispatch_code, &maxargs); } else { - dispatch = Swig_overload_dispatch(n,dispatch_code,&maxargs); + dispatch = Swig_overload_dispatch(n, dispatch_code, &maxargs); } - + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *f = NewWrapper(); - String *symname = Getattr(n,"sym:name"); - String *wname = Swig_name_wrapper(symname); + Wrapper *f = NewWrapper(); + String *symname = Getattr(n, "sym:name"); + String *wname = Swig_name_wrapper(symname); - Printv(f->def, - "SWIGINTERN PyObject *", wname, - "(PyObject *self, PyObject *args) {", - NIL); - - Wrapper_add_local(f,"argc","int argc"); - Printf(tmp,"PyObject *argv[%d]", maxargs+1); - Wrapper_add_local(f,"argv",tmp); - if (allow_thread) thread_begin_block(n, f->code); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); + + Wrapper_add_local(f, "argc", "int argc"); + Printf(tmp, "PyObject *argv[%d]", maxargs + 1); + Wrapper_add_local(f, "argv", tmp); + if (allow_thread) + thread_begin_block(n, f->code); if (!fastunpack) { - Wrapper_add_local(f,"ii","int ii"); - Append(f->code,"if (!PyTuple_Check(args)) SWIG_fail;\n"); - Append(f->code,"argc = PyObject_Length(args);\n"); - Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs); - Append(f->code,"argv[ii] = PyTuple_GET_ITEM(args,ii);\n"); - Append(f->code,"}\n"); + Wrapper_add_local(f, "ii", "int ii"); + Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n"); + Append(f->code, "argc = PyObject_Length(args);\n"); + Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs); + Append(f->code, "argv[ii] = PyTuple_GET_ITEM(args,ii);\n"); + Append(f->code, "}\n"); } else { - String *iname = Getattr(n,"sym:name"); - Printf(f->code,"if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); - Append(f->code,"--argc;\n"); + String *iname = Getattr(n, "sym:name"); + Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); + Append(f->code, "--argc;\n"); } - - Replaceall(dispatch,"$args","self,args"); + + Replaceall(dispatch, "$args", "self,args"); if (allow_thread) { String *ret = NewStringEmpty(); thread_end_block(n, ret); Append(ret, "return "); - Replaceall(dispatch,"return ",ret); + Replaceall(dispatch, "return ", ret); Delete(ret); } - Printv(f->code,dispatch,"\n",NIL); + Printv(f->code, dispatch, "\n", NIL); - if (allow_thread) thread_end_block(n, f->code); + if (allow_thread) + thread_end_block(n, f->code); - if (GetFlag(n,"feature:python:maybecall")) { - Append(f->code,"fail:\n"); - Append(f->code,"Py_INCREF(Py_NotImplemented);\n"); - Append(f->code,"return Py_NotImplemented;\n"); + if (GetFlag(n, "feature:python:maybecall")) { + Append(f->code, "fail:\n"); + Append(f->code, "Py_INCREF(Py_NotImplemented);\n"); + Append(f->code, "return Py_NotImplemented;\n"); } else { Node *sibl = n; - while (Getattr(sibl,"sym:previousSibling")) - sibl = Getattr(sibl,"sym:previousSibling"); // go all the way up + while (Getattr(sibl, "sym:previousSibling")) + sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up String *protoTypes = NewString(""); do { - Printf(protoTypes, " %s(%s)\\n", - Getattr(sibl,"name"),ParmList_protostr(Getattr(sibl,"wrap:parms"))); - } while ((sibl = Getattr(sibl,"sym:nextSibling"))); - Append(f->code,"fail:\n"); + Printf(protoTypes, " %s(%s)\\n", Getattr(sibl, "name"), ParmList_protostr(Getattr(sibl, "wrap:parms"))); + } while ((sibl = Getattr(sibl, "sym:nextSibling"))); + Append(f->code, "fail:\n"); Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError," - "\"Wrong number of arguments for overloaded function '%s'.\\n" - " Possible C/C++ prototypes are:\\n%s\");\n", - symname, protoTypes); - Append(f->code,"return NULL;\n"); + "\"Wrong number of arguments for overloaded function '%s'.\\n" " Possible C/C++ prototypes are:\\n%s\");\n", symname, protoTypes); + Append(f->code, "return NULL;\n"); Delete(protoTypes); } - Printv(f->code,"}\n",NIL); - Wrapper_print(f,f_wrappers); + Printv(f->code, "}\n", NIL); + Wrapper_print(f, f_wrappers); Node *p = Getattr(n, "sym:previousSibling"); - add_method(symname,wname,0,p); + add_method(symname, wname, 0, p); /* Create a shadow for this function (if enabled and not in a member function) */ if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { @@ -1579,29 +1530,28 @@ public: /* ------------------------------------------------------------ * functionWrapper() * ------------------------------------------------------------ */ - - const char *get_implicitconv_flag(Node *klass) - { + + const char *get_implicitconv_flag(Node *klass) { int conv = 0; - if (klass && GetFlag(klass,"feature:implicitconv")) { - conv = 1; + if (klass && GetFlag(klass, "feature:implicitconv")) { + conv = 1; } return conv ? "SWIG_POINTER_IMPLICIT_CONV" : "0"; } - + virtual int functionWrapper(Node *n) { - - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *d = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *d = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); int director_method = 0; - Parm *p; - int i; - char source[64]; + Parm *p; + int i; + char source[64]; Wrapper *f; String *parse_args; String *arglist; @@ -1612,58 +1562,60 @@ public: String *tm; String *overname = 0; - int num_required; - int num_arguments; - int varargs = 0; - int allow_kwargs = check_kwargs(n); + int num_required; + int num_arguments; + int varargs = 0; + int allow_kwargs = check_kwargs(n); String *nodeType = Getattr(n, "nodeType"); - int constructor = (!Cmp(nodeType, "constructor")); - int destructor = (!Cmp(nodeType, "destructor")); - String *storage = Getattr(n,"storage"); + int constructor = (!Cmp(nodeType, "constructor")); + int destructor = (!Cmp(nodeType, "destructor")); + String *storage = Getattr(n, "storage"); /* Only the first constructor is handled as init method. Others constructor can be emitted via %rename */ int handled_as_init = 0; - if (!have_constructor &&(constructor || Getattr(n,"handled_as_constructor")) + if (!have_constructor && (constructor || Getattr(n, "handled_as_constructor")) && ((shadow & PYSHADOW_MEMBER))) { - String *nname = Getattr(n,"sym:name"); - String *sname = Getattr(getCurrentClass(),"sym:name"); + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); String *cname = Swig_name_construct(sname); - handled_as_init = (Strcmp(nname,sname) == 0) || (Strcmp(nname,cname) == 0); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } - - - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + + + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } f = NewWrapper(); - parse_args = NewString(""); - arglist = NewString(""); + parse_args = NewString(""); + arglist = NewString(""); get_pointers = NewString(""); - cleanup = NewString(""); - outarg = NewString(""); - kwargs = NewString(""); + cleanup = NewString(""); + outarg = NewString(""); + kwargs = NewString(""); int allow_thread = threads_enable(n); - if (allow_thread) thread_begin_block(n, f->code); - - Wrapper_add_local(f,"resultobj", "PyObject *resultobj = 0"); + if (allow_thread) + thread_begin_block(n, f->code); - /* Write code to extract function parameters. */ + Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0"); + + /* Write code to extract function parameters. */ emit_args(d, l, f); /* Attach the standard typemaps */ - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); /* Get number of required and total arguments */ num_arguments = emit_num_arguments(l); - num_required = emit_num_required(l); - if (((num_arguments == 0) && (num_required == 0)) || - ((num_arguments == 1) && (num_required == 1) && Getattr(l,"self"))) allow_kwargs = 0; + num_required = emit_num_required(l); + if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self"))) + allow_kwargs = 0; varargs = emit_isvarargs(l); String *wname = Swig_name_wrapper(iname); @@ -1671,38 +1623,31 @@ public: Append(wname, overname); } - if (!allow_kwargs || Getattr(n,"sym:overloaded")) { + if (!allow_kwargs || Getattr(n, "sym:overloaded")) { if (!varargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", - "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL); } if (allow_kwargs) { - Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, - "Can't use keyword arguments with overloaded functions.\n"); + Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions.\n"); allow_kwargs = 0; } } else { if (varargs) { - Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, - "Can't wrap varargs with keyword arguments enabled\n"); + Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n"); varargs = 0; } - Printv(f->def, - "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {", - NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {", NIL); } if (!allow_kwargs) { - Append(parse_args," if (!PyArg_ParseTuple(args,(char *)\""); + Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\""); } else { - Append(parse_args," if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); - Append(arglist,",kwnames"); + Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); + Append(arglist, ",kwnames"); } - int funpack = modernargs && fastunpack && !varargs && !allow_kwargs ; + int funpack = modernargs && fastunpack && !varargs && !allow_kwargs; int noargs = funpack && (num_required == 0 && num_arguments == 0); int onearg = funpack && (num_required == 1 && num_arguments == 1); @@ -1713,7 +1658,7 @@ public: Append(f->code, "#define obj0 (swig_obj[0])\n"); } } else if (num_arguments) { - sprintf(source,"PyObject *swig_obj[%d]",num_arguments); + sprintf(source, "PyObject *swig_obj[%d]", num_arguments); Wrapper_add_localv(f, "swig_obj", source, NIL); if (aliasobj0) { Append(f->code, "#define obj0 (swig_obj[0])\n"); @@ -1723,10 +1668,10 @@ public: if (constructor && num_arguments == 1 && num_required == 1) { - if (Cmp(storage,"explicit") == 0) { + if (Cmp(storage, "explicit") == 0) { Node *parent = Swig_methodclass(n); - if (GetFlag(parent,"feature:implicitconv")) { - String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n,"type"))); + if (GetFlag(parent, "feature:implicitconv")) { + String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type"))); Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc); Delete(desc); } @@ -1734,105 +1679,106 @@ public: } int use_parse = 0; - Append(kwargs,"{"); - for (i = 0, p=l; i < num_arguments; i++) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + Append(kwargs, "{"); + for (i = 0, p = l; i < num_arguments; i++) { + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p,"type"); - String *pn = Getattr(p,"name"); - String *ln = Getattr(p,"lname"); + SwigType *pt = Getattr(p, "type"); + String *pn = Getattr(p, "name"); + String *ln = Getattr(p, "lname"); if (funpack) { - sprintf(source,"swig_obj[%d]",i); + sprintf(source, "swig_obj[%d]", i); } else { - sprintf(source,"obj%d",i); + sprintf(source, "obj%d", i); } - - - Putc(',',arglist); - if (i == num_required) Putc('|', parse_args); /* Optional argument separator */ + + + Putc(',', arglist); + if (i == num_required) + Putc('|', parse_args); /* Optional argument separator */ /* Keyword argument handling */ if (allow_kwargs) { if (Len(pn)) { String *tmp = 0; - String *name = pn; - if (!Getattr(p,"hidden")) { - name = tmp = Swig_name_make(p,0,pn,0, 0); - } - Printf(kwargs,"(char *) \"%s\",", name); - if (tmp) Delete(tmp); + String *name = pn; + if (!Getattr(p, "hidden")) { + name = tmp = Swig_name_make(p, 0, pn, 0, 0); + } + Printf(kwargs, "(char *) \"%s\",", name); + if (tmp) + Delete(tmp); } else { - Printf(kwargs,"(char *)\"arg%d\",", i+1); + Printf(kwargs, "(char *)\"arg%d\",", i + 1); } } /* Look for an input typemap */ - if ((tm = Getattr(p,"tmap:in"))) { - String *parse = Getattr(p,"tmap:in:parse"); + if ((tm = Getattr(p, "tmap:in"))) { + String *parse = Getattr(p, "tmap:in:parse"); if (!parse) { if (funpack) { - Replaceall(tm,"$self","swig_obj[0]"); - } else{ - Replaceall(tm,"$self","obj0"); - } - Replaceall(tm,"$source",source); - Replaceall(tm,"$target",ln); - Replaceall(tm,"$input", source); - Setattr(p,"emit:input", source); /* Save the location of the object */ - - if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); + Replaceall(tm, "$self", "swig_obj[0]"); } else { - Replaceall(tm,"$disown","0"); + Replaceall(tm, "$self", "obj0"); } - - if (Getattr(p,"tmap:in:implicitconv")) { - const char *convflag = "0"; - if (!Getattr(p,"hidden")) { - SwigType *ptype = Getattr(p,"type"); - convflag = get_implicitconv_flag(classLookup(ptype)); - } - Replaceall(tm,"$implicitconv", convflag); - Setattr(p,"implicitconv",convflag); + Replaceall(tm, "$source", source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); /* Save the location of the object */ + + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); } - Putc('O',parse_args); + if (Getattr(p, "tmap:in:implicitconv")) { + const char *convflag = "0"; + if (!Getattr(p, "hidden")) { + SwigType *ptype = Getattr(p, "type"); + convflag = get_implicitconv_flag(classLookup(ptype)); + } + Replaceall(tm, "$implicitconv", convflag); + Setattr(p, "implicitconv", convflag); + } + + Putc('O', parse_args); if (!funpack) { - Wrapper_add_localv(f, source, "PyObject *",source, "= 0", NIL); - Printf(arglist,"&%s",source); + Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL); + Printf(arglist, "&%s", source); } if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); - Printv(get_pointers,tm,"\n", NIL); + Printv(get_pointers, tm, "\n", NIL); if (i >= num_required) Printv(get_pointers, "}\n", NIL); } else { use_parse = 1; - Append(parse_args,parse); - Printf(arglist,"&%s", ln); + Append(parse_args, parse); + Printf(arglist, "&%s", ln); } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); continue; } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n",SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); break; } p = nextSibling(p); } /* finish argument marshalling */ - Append(kwargs," NULL }"); + Append(kwargs, " NULL }"); if (allow_kwargs) { - Printv(f->locals,ctab4, "char * kwnames[] = ", kwargs, ";\n", NIL); + Printv(f->locals, ctab4, "char * kwnames[] = ", kwargs, ";\n", NIL); } if (use_parse || allow_kwargs || !modernargs) { - Printf(parse_args,":%s\"", iname); - Printv(parse_args,arglist, ")) SWIG_fail;\n",NIL); + Printf(parse_args, ":%s\"", iname); + Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); funpack = 0; } else { Clear(parse_args); @@ -1840,35 +1786,29 @@ public: Clear(f->def); if (overname) { if (noargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); - } else{ - Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {", NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); + } else { + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {", NIL); } - Printf(parse_args,"if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); + Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); } else { if (noargs) { - Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); } else { - Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); } if (onearg) { - Printf(parse_args,"if (!args) SWIG_fail;\n"); - Printf(parse_args,"swig_obj[0] = args;\n"); + Printf(parse_args, "if (!args) SWIG_fail;\n"); + Printf(parse_args, "swig_obj[0] = args;\n"); } else if (!noargs) { - Printf(parse_args,"if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", - iname, num_required, num_arguments); + Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", iname, num_required, num_arguments); } else if (noargs) { - Printf(parse_args,"if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", - iname, num_required, num_arguments); + Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_required, num_arguments); } } - } else { - Printf(parse_args,"if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments); - Printv(parse_args,arglist, ")) SWIG_fail;\n",NIL); + } else { + Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments); + Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL); } } @@ -1877,42 +1817,42 @@ public: /* Check for trailing varargs */ if (varargs) { - if (p && (tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$input", "varargs"); - Printv(f->code,tm,"\n",NIL); + if (p && (tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$input", "varargs"); + Printv(f->code, tm, "\n", NIL); } } /* Insert constraint checking code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ for (p = l; p;) { // if (!checkAttribute(p,"tmap:in:numinputs","0") && !Getattr(p,"tmap:in:parse")) { - if (!Getattr(p,"tmap:in:parse") && (tm = Getattr(p,"tmap:freearg"))) { - if (Getattr(p,"tmap:freearg:implicitconv")) { + if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { + if (Getattr(p, "tmap:freearg:implicitconv")) { const char *convflag = "0"; - if (!Getattr(p,"hidden")) { - SwigType *ptype = Getattr(p,"type"); + if (!Getattr(p, "hidden")) { + SwigType *ptype = Getattr(p, "type"); convflag = get_implicitconv_flag(classLookup(ptype)); } - if (strcmp(convflag,"0") == 0) { + if (strcmp(convflag, "0") == 0) { tm = 0; } } if (tm && (Len(tm) != 0)) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); } - p = Getattr(p,"tmap:freearg:next"); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -1920,18 +1860,18 @@ public: /* Insert argument output code */ for (p = l; p;) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } - + /* if the object is a director, and the method call originated from its * underlying python object, resolve the call by going up the c++ * inheritance chain. otherwise try to resolve the method in python. @@ -1956,7 +1896,7 @@ public: if (director_method) { Wrapper_add_local(f, "director", "Swig::Director *director = 0"); Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n"); - if (dirprot_mode() && !is_public(n)) { + if (dirprot_mode() && !is_public(n)) { Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name); Printf(f->code, "SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing protected member %s\");\n", name); Append(f->code, "SWIG_fail;\n"); @@ -1975,12 +1915,12 @@ public: */ /* MOVED TO Swig_ConstructorToFunction() */ /* - if (constructor && (Getattr(n, "wrap:self") != 0)) { - Wrapper_add_local(f, "subclassed", "int subclassed = 0"); - Append(f->code, "subclassed = (arg1 != Py_None);\n"); - } - */ - + if (constructor && (Getattr(n, "wrap:self") != 0)) { + Wrapper_add_local(f, "subclassed", "int subclassed = 0"); + Append(f->code, "subclassed = (arg1 != Py_None);\n"); + } + */ + /* Emit the function call */ if (director_method) { Append(f->code, "try {\n"); @@ -1990,8 +1930,8 @@ public: thread_begin_allow(n, f->code); } } - - emit_action(n,f); + + emit_action(n, f); if (director_method) { Append(f->code, "} catch (Swig::DirectorException&) {\n"); @@ -2007,22 +1947,22 @@ public: /* This part below still needs cleanup */ /* Return the function value */ - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { if (funpack) { - Replaceall(tm,"$self","swig_obj[0]"); - } else{ - Replaceall(tm,"$self","obj0"); + Replaceall(tm, "$self", "swig_obj[0]"); + } else { + Replaceall(tm, "$self", "obj0"); } - Replaceall(tm,"$source", "result"); - Replaceall(tm,"$target", "resultobj"); - Replaceall(tm,"$result", "resultobj"); + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); if (handled_as_init) { - Replaceall(tm,"$owner","SWIG_POINTER_NEW"); - } else { - if (GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","SWIG_POINTER_OWN"); + Replaceall(tm, "$owner", "SWIG_POINTER_NEW"); + } else { + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "SWIG_POINTER_OWN"); } else { - Replaceall(tm,"$owner","0"); + Replaceall(tm, "$owner", "0"); } } // FIXME: this will not try to unwrap directors returned as non-director @@ -2037,81 +1977,83 @@ public: int is_pointer = SwigType_ispointer_return(decl); int is_reference = SwigType_isreference_return(decl); if (is_pointer || is_reference) { - String *type = Getattr(n, "type"); - //Node *classNode = Swig_methodclass(n); - //Node *module = Getattr(classNode, "module"); + String *type = Getattr(n, "type"); + //Node *classNode = Swig_methodclass(n); + //Node *module = Getattr(classNode, "module"); Node *parent = Swig_methodclass(n); - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, type); - if (target) unwrap = 1; + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, type); + if (target) + unwrap = 1; } if (unwrap) { - Wrapper_add_local(f, "director", "Swig::Director *director = 0"); + Wrapper_add_local(f, "director", "Swig::Director *director = 0"); Append(f->code, "director = SWIG_DIRECTOR_CAST(result);\n"); Append(f->code, "if (director) {\n"); Append(f->code, " resultobj = director->swig_get_self();\n"); Append(f->code, " Py_INCREF(resultobj);\n"); - Append(f->code, "} else {\n"); - Printf(f->code,"%s\n", tm); - Append(f->code, "}\n"); + Append(f->code, "} else {\n"); + Printf(f->code, "%s\n", tm); + Append(f->code, "}\n"); } else { - Printf(f->code,"%s\n", tm); + Printf(f->code, "%s\n", tm); } #else - Printf(f->code,"%s\n", tm); + Printf(f->code, "%s\n", tm); #endif Delete(tm); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(d,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name); } /* Output argument output code */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Output cleanup code */ int need_cleanup = Len(cleanup) != 0; if (need_cleanup) { - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); } /* Look to see if there is any newfree cleanup code */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); Delete(tm); } } /* See if there is any return cleanup code */ if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n",tm); + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); Delete(tm); } if (director_method) { - if ((tm = Swig_typemap_lookup_new("directorfree",n,"result",0))) { - Replaceall(tm,"$input","result"); - Replaceall(tm,"$result","resultobj"); - Printf(f->code,"%s\n",tm); + if ((tm = Swig_typemap_lookup_new("directorfree", n, "result", 0))) { + Replaceall(tm, "$input", "result"); + Replaceall(tm, "$result", "resultobj"); + Printf(f->code, "%s\n", tm); Delete(tm); } } - if (allow_thread) thread_end_block(n, f->code); - Append(f->code," return resultobj;\n"); + if (allow_thread) + thread_end_block(n, f->code); + Append(f->code, " return resultobj;\n"); /* Error handling code */ - Append(f->code,"fail:\n"); + Append(f->code, "fail:\n"); if (need_cleanup) { - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); } - if (allow_thread) thread_end_block(n, f->code); - Printv(f->code,ctab4,"return NULL;\n",NIL); - + if (allow_thread) + thread_end_block(n, f->code); + Printv(f->code, ctab4, "return NULL;\n", NIL); + if (funpack) { if (aliasobj0) { @@ -2120,59 +2062,56 @@ public: Append(f->code, "#endif\n"); } } - - - Append(f->code,"}\n"); + + + Append(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",iname); - Replaceall(f->code,"$result","resultobj"); + Replaceall(f->code, "$symname", iname); + Replaceall(f->code, "$result", "resultobj"); if (funpack) { - Replaceall(f->code,"$self","swig_obj[0]"); - } else{ - Replaceall(f->code,"$self","obj0"); + Replaceall(f->code, "$self", "swig_obj[0]"); + } else { + Replaceall(f->code, "$self", "obj0"); } /* Dump the function out */ - Wrapper_print(f,f_wrappers); + Wrapper_print(f, f_wrappers); /* If varargs. Need to emit a varargs stub */ if (varargs) { DelWrapper(f); f = NewWrapper(); - Printv(f->def, - "SWIGINTERN PyObject *", wname, - "(PyObject *self, PyObject *args) {", - NIL); - Wrapper_add_local(f,"resultobj", "PyObject *resultobj"); - Wrapper_add_local(f,"varargs", "PyObject *varargs"); - Wrapper_add_local(f,"newargs", "PyObject *newargs"); - Printf(f->code,"newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments); - Printf(f->code,"varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments); - Printf(f->code,"resultobj = %s__varargs__(self,newargs,varargs);\n", wname); - Append(f->code,"Py_XDECREF(newargs);\n"); - Append(f->code,"Py_XDECREF(varargs);\n"); - Append(f->code,"return resultobj;\n"); - Append(f->code,"}\n"); - Wrapper_print(f,f_wrappers); + Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL); + Wrapper_add_local(f, "resultobj", "PyObject *resultobj"); + Wrapper_add_local(f, "varargs", "PyObject *varargs"); + Wrapper_add_local(f, "newargs", "PyObject *newargs"); + Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments); + Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments); + Printf(f->code, "resultobj = %s__varargs__(self,newargs,varargs);\n", wname); + Append(f->code, "Py_XDECREF(newargs);\n"); + Append(f->code, "Py_XDECREF(varargs);\n"); + Append(f->code, "return resultobj;\n"); + Append(f->code, "}\n"); + Wrapper_print(f, f_wrappers); } - Setattr(n,"wrap:name", wname); + Setattr(n, "wrap:name", wname); /* Now register the function with the interpreter. */ - if (!Getattr(n,"sym:overloaded")) { + if (!Getattr(n, "sym:overloaded")) { add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); /* Create a shadow for this function (if enabled and not in a member function) */ if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { - emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs); + emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs); } } else { - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { dispatchFunction(n, funpack); } } @@ -2194,36 +2133,37 @@ public: * ------------------------------------------------------------ */ virtual int variableWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); - + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); + String *getnamef; String *setnamef; static int have_globals = 0; - String *tm; + String *tm; Wrapper *getf, *setf; - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; getf = NewWrapper(); setf = NewWrapper(); - /* If this is our first call, add the globals variable to the - Python dictionary. */ + /* If this is our first call, add the globals variable to the + Python dictionary. */ if (!have_globals) { - Printf(f_init,"\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n",global_name); - have_globals=1; + Printf(f_init, "\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n", global_name); + have_globals = 1; if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { - Printf(f_shadow_stubs,"%s = %s.%s\n", global_name, module, global_name); + Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name); } } int assignable = is_assignable(n); if ((shadow) && !assignable) { if (!in_class) { - Printf(f_shadow_stubs,"%s = %s.%s\n", iname, global_name, iname); + Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname); } } @@ -2232,64 +2172,59 @@ public: /* Create a function for setting the value of the variable */ if (assignable) { - Printf(setf->def,"SWIGINTERN int %s(PyObject *_val) {", setnamef); - if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { - Replaceall(tm,"$source","_val"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input","_val"); - if (Getattr(n,"tmap:varin:implicitconv")) { - Replaceall(tm,"$implicitconv", get_implicitconv_flag(n)); + Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", setnamef); + if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { + Replaceall(tm, "$source", "_val"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "_val"); + if (Getattr(n, "tmap:varin:implicitconv")) { + Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); } emit_action_code(n, setf, tm); Delete(tm); } else { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, - "Unable to set variable of type %s.\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); } - Printv(setf->code,ctab4,"return 0;\n",NULL); - Append(setf->code,"fail:\n"); - Printv(setf->code,ctab4,"return 1;\n",NULL); + Printv(setf->code, ctab4, "return 0;\n", NULL); + Append(setf->code, "fail:\n"); + Printv(setf->code, ctab4, "return 1;\n", NULL); } else { /* Is a readonly variable. Issue an error */ if (CPlusPlus) { - Printf(setf->def,"SWIGINTERN int %s(PyObject *) {", setnamef); + Printf(setf->def, "SWIGINTERN int %s(PyObject *) {", setnamef); } else { - Printf(setf->def,"SWIGINTERN int %s(PyObject *_val SWIGUNUSED) {", setnamef); + Printf(setf->def, "SWIGINTERN int %s(PyObject *_val SWIGUNUSED) {", setnamef); } - Printv(setf->code, - ctab4, "SWIG_Error(SWIG_AttributeError,\"Variable ", iname," is read-only.\");\n", - ctab4, "return 1;\n", - NIL); + Printv(setf->code, ctab4, "SWIG_Error(SWIG_AttributeError,\"Variable ", iname, " is read-only.\");\n", ctab4, "return 1;\n", NIL); } - Append(setf->code,"}\n"); - Wrapper_print(setf,f_wrappers); + Append(setf->code, "}\n"); + Wrapper_print(setf, f_wrappers); /* Create a function for getting the value of a variable */ int addfail = 0; - Printf(getf->def,"SWIGINTERN PyObject *%s(void) {", getnamef); - Wrapper_add_local(getf,"pyobj", "PyObject *pyobj = 0"); - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source",name); - Replaceall(tm,"$target","pyobj"); - Replaceall(tm,"$result","pyobj"); + Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", getnamef); + Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0"); + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "pyobj"); + Replaceall(tm, "$result", "pyobj"); addfail = emit_action_code(n, getf, tm); Delete(tm); } else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); } - Append(getf->code," return pyobj;\n"); + Append(getf->code, " return pyobj;\n"); if (addfail) { - Append(getf->code,"fail:\n"); - Append(getf->code," return NULL;\n"); + Append(getf->code, "fail:\n"); + Append(getf->code, " return NULL;\n"); } - Append(getf->code,"}\n"); + Append(getf->code, "}\n"); - Wrapper_print(getf,f_wrappers); + Wrapper_print(getf, f_wrappers); /* Now add this to the variable linking mechanism */ - Printf(f_init,"\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, getnamef, setnamef); + Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, getnamef, setnamef); Delete(getnamef); Delete(setnamef); @@ -2303,51 +2238,51 @@ public: * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); - String *tm; - int have_tm = 0; + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + String *tm; + int have_tm = 0; - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; - /* Special hook for member pointer */ + /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(iname); - String *str = SwigType_str(type,wname); + String *str = SwigType_str(type, wname); Printf(f_header, "static %s = %s;\n", str, value); Delete(str); value = wname; } - if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) { - Replaceall(tm,"$source",value); - Replaceall(tm,"$target",name); - Replaceall(tm,"$value", value); - Printf(const_code,"%s,\n", tm); + if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Printf(const_code, "%s,\n", tm); Delete(tm); have_tm = 1; } if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) { - Replaceall(tm,"$source",value); - Replaceall(tm,"$target",name); - Replaceall(tm,"$value",value); + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); Printf(f_init, "%s\n", tm); Delete(tm); have_tm = 1; } if (!have_tm) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) { if (!in_class) { - Printv(f_shadow,iname, " = ", module, ".", iname, "\n", NIL); + Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL); } else { - if (!(Getattr(n,"feature:python:callback"))) { - Printv(f_shadow_stubs,iname, " = ", module, ".", iname, "\n", NIL); + if (!(Getattr(n, "feature:python:callback"))) { + Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL); } } } @@ -2360,12 +2295,13 @@ public: * ------------------------------------------------------------ */ virtual int nativeWrapper(Node *n) { - String *name = Getattr(n,"sym:name"); - String *wrapname = Getattr(n,"wrap:name"); + String *name = Getattr(n, "sym:name"); + String *wrapname = Getattr(n, "wrap:name"); - if (!addSymbol(wrapname,n)) return SWIG_ERROR; + if (!addSymbol(wrapname, n)) + return SWIG_ERROR; - add_method(name, wrapname,0); + add_method(name, wrapname, 0); if (shadow) { Printv(f_shadow_stubs, name, " = ", module, ".", name, "\n", NIL); } @@ -2397,7 +2333,7 @@ public: int classDirectorMethods(Node *n); int classDirectorMethod(Node *n, Node *parent, String *super); - + /* ------------------------------------------------------------ * classDirectorConstructor() * ------------------------------------------------------------ */ @@ -2420,28 +2356,28 @@ public: set_nextSibling(p, parms); parms = p; - if (!Getattr(n,"defaultargs")) { + if (!Getattr(n, "defaultargs")) { /* constructor */ { - Wrapper *w = NewWrapper(); - String *call; - String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); - call = Swig_csuperclass_call(0, basetype, superparms); - Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call); - Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); - Append(w->def, "}\n"); - Delete(target); - Wrapper_print(w, f_directors); - Delete(call); - DelWrapper(w); + Wrapper *w = NewWrapper(); + String *call; + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); + call = Swig_csuperclass_call(0, basetype, superparms); + Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call); + Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); + Append(w->def, "}\n"); + Delete(target); + Wrapper_print(w, f_directors); + Delete(call); + DelWrapper(w); } /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); - Printf(f_directors_h, " %s;\n", target); - Delete(target); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); } } @@ -2496,55 +2432,55 @@ public: if (dirprot_mode()) { /* - This implementation uses a std::map. + This implementation uses a std::map. - It should be possible to rewrite it using a more elegant way, - like copying the Java approach for the 'override' array. + It should be possible to rewrite it using a more elegant way, + like copying the Java approach for the 'override' array. - But for know, this seems to be the least intrusive way. - */ - Printf(f_directors_h,"\n\n"); - Printf(f_directors_h,"/* Internal Director utilities */\n"); - Printf(f_directors_h,"public:\n"); - Printf(f_directors_h," bool swig_get_inner(const char* name) const {\n"); - Printf(f_directors_h," std::map::const_iterator iv = inner.find(name);\n"); - Printf(f_directors_h," return (iv != inner.end() ? iv->second : false);\n"); - Printf(f_directors_h," }\n\n"); - - Printf(f_directors_h," void swig_set_inner(const char* name, bool val) const\n"); - Printf(f_directors_h," { inner[name] = val;}\n\n"); - Printf(f_directors_h,"private:\n"); - Printf(f_directors_h," mutable std::map inner;\n"); + But for know, this seems to be the least intrusive way. + */ + Printf(f_directors_h, "\n\n"); + Printf(f_directors_h, "/* Internal Director utilities */\n"); + Printf(f_directors_h, "public:\n"); + Printf(f_directors_h, " bool swig_get_inner(const char* name) const {\n"); + Printf(f_directors_h, " std::map::const_iterator iv = inner.find(name);\n"); + Printf(f_directors_h, " return (iv != inner.end() ? iv->second : false);\n"); + Printf(f_directors_h, " }\n\n"); + + Printf(f_directors_h, " void swig_set_inner(const char* name, bool val) const\n"); + Printf(f_directors_h, " { inner[name] = val;}\n\n"); + Printf(f_directors_h, "private:\n"); + Printf(f_directors_h, " mutable std::map inner;\n"); } if (director_method_index) { - Printf(f_directors_h,"\n\n"); - Printf(f_directors_h,"#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); - Printf(f_directors_h,"/* VTable implementation */\n"); - Printf(f_directors_h," PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n"); - Printf(f_directors_h," PyObject *method = vtable[method_index];\n"); - Printf(f_directors_h," if (!method) {\n"); - Printf(f_directors_h," swig::PyObject_var name = PyString_FromString(method_name);\n"); - Printf(f_directors_h," method = PyObject_GetAttr(swig_get_self(), name);\n"); - Printf(f_directors_h," if (method == NULL) {\n"); - Printf(f_directors_h," std::string msg = \"Method in class %s doesn't exist, undefined \";\n", classname); - Printf(f_directors_h," msg += method_name;\n"); - Printf(f_directors_h," Swig::DirectorMethodException::raise(msg.c_str());\n"); - Printf(f_directors_h," }\n"); - Printf(f_directors_h," vtable[method_index] = method;\n"); - Printf(f_directors_h," };\n"); - Printf(f_directors_h," return method;\n"); - Printf(f_directors_h," }\n"); - Printf(f_directors_h,"private:\n"); - Printf(f_directors_h," mutable swig::PyObject_var vtable[%d];\n", director_method_index); - Printf(f_directors_h,"#endif\n\n"); + Printf(f_directors_h, "\n\n"); + Printf(f_directors_h, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); + Printf(f_directors_h, "/* VTable implementation */\n"); + Printf(f_directors_h, " PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n"); + Printf(f_directors_h, " PyObject *method = vtable[method_index];\n"); + Printf(f_directors_h, " if (!method) {\n"); + Printf(f_directors_h, " swig::PyObject_var name = PyString_FromString(method_name);\n"); + Printf(f_directors_h, " method = PyObject_GetAttr(swig_get_self(), name);\n"); + Printf(f_directors_h, " if (method == NULL) {\n"); + Printf(f_directors_h, " std::string msg = \"Method in class %s doesn't exist, undefined \";\n", classname); + Printf(f_directors_h, " msg += method_name;\n"); + Printf(f_directors_h, " Swig::DirectorMethodException::raise(msg.c_str());\n"); + Printf(f_directors_h, " }\n"); + Printf(f_directors_h, " vtable[method_index] = method;\n"); + Printf(f_directors_h, " };\n"); + Printf(f_directors_h, " return method;\n"); + Printf(f_directors_h, " }\n"); + Printf(f_directors_h, "private:\n"); + Printf(f_directors_h, " mutable swig::PyObject_var vtable[%d];\n", director_method_index); + Printf(f_directors_h, "#endif\n\n"); } - + Printf(f_directors_h, "};\n\n"); return Language::classDirectorEnd(n); } - - + + /* ------------------------------------------------------------ * classDirectorDisown() * ------------------------------------------------------------ */ @@ -2553,19 +2489,20 @@ public: int result; int oldshadow = shadow; /* disable shadowing */ - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; result = Language::classDirectorDisown(n); shadow = oldshadow; if (shadow) { - String *symname = Getattr(n,"sym:name"); - String *mrename = Swig_name_disown(symname); //Getattr(n, "name")); + String *symname = Getattr(n, "sym:name"); + String *mrename = Swig_name_disown(symname); //Getattr(n, "name")); Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); #ifdef USE_THISOWN Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); #else Printv(f_shadow, tab8, "self.this.disown()\n", NIL); #endif - Printv(f_shadow, tab8, module, ".", mrename,"(self)\n", NIL); + Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL); Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); Delete(mrename); } @@ -2575,29 +2512,29 @@ public: /* ---------------------------------------------------------------------------- * END of C++ Director Class modifications * ------------------------------------------------------------------------- */ - + /* ------------------------------------------------------------ * classDeclaration() * ------------------------------------------------------------ */ virtual int classDeclaration(Node *n) { - if (shadow && !Getattr(n,"feature:onlychildren")) { - Node *mod = Getattr(n,"module"); + if (shadow && !Getattr(n, "feature:onlychildren")) { + Node *mod = Getattr(n, "module"); if (mod) { String *importname = NewString(""); - String *modname = Getattr(mod,"name"); - if (Strcmp(modname,mainmodule) != 0) { - // check if the module has a package option - Node *options = Getattr(mod, "options"); - String* pkg = options ? Getattr(options, "package") : 0; - if (pkg && (!package || Strcmp(pkg, package) != 0)) { - Printf(importname,"%s.", pkg); + String *modname = Getattr(mod, "name"); + if (Strcmp(modname, mainmodule) != 0) { + // check if the module has a package option + Node *options = Getattr(mod, "options"); + String *pkg = options ? Getattr(options, "package") : 0; + if (pkg && (!package || Strcmp(pkg, package) != 0)) { + Printf(importname, "%s.", pkg); } - Printf(importname,"%s.", modname); + Printf(importname, "%s.", modname); } - Append(importname,Getattr(n,"sym:name")); - Setattr(n,"python:proxy",importname); + Append(importname, Getattr(n, "sym:name")); + Setattr(n, "python:proxy", importname); } } return Language::classDeclaration(n); @@ -2609,113 +2546,105 @@ public: virtual int classHandler(Node *n) { int oldclassic = classic; - int oldmodern = modern; - File *f_shadow_file = f_shadow; + int oldmodern = modern; + File *f_shadow_file = f_shadow; if (shadow) { /* Create new strings for building up a wrapper function */ have_constructor = 0; have_repr = 0; - - if (GetFlag(n,"feature:classic")) { - classic = 1; - modern = 0; - } - if (GetFlag(n,"feature:modern")) { - classic = 0; - modern = 1; - } - if (GetFlag(n,"feature:exceptionclass")) { + + if (GetFlag(n, "feature:classic")) { classic = 1; - modern = 0; + modern = 0; + } + if (GetFlag(n, "feature:modern")) { + classic = 0; + modern = 1; + } + if (GetFlag(n, "feature:exceptionclass")) { + classic = 1; + modern = 0; } shadow_indent = (String *) tab4; - - class_name = Getattr(n,"sym:name"); - real_classname = Getattr(n,"name"); - - if (!addSymbol(class_name,n)) return SWIG_ERROR; - + + class_name = Getattr(n, "sym:name"); + real_classname = Getattr(n, "name"); + + if (!addSymbol(class_name, n)) + return SWIG_ERROR; + /* Handle inheritance */ String *base_class = NewString(""); - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator b; b = First(baselist); while (b.item) { String *bname = Getattr(b.item, "python:proxy"); - if (!bname || GetFlag(b.item,"feature:ignore")) { + if (!bname || GetFlag(b.item, "feature:ignore")) { b = Next(b); continue; } - Printv(base_class,bname,NIL); + Printv(base_class, bname, NIL); b = Next(b); if (b.item) { - Putc(',',base_class); + Putc(',', base_class); } } } - Printv(f_shadow,"class ", class_name, NIL); + Printv(f_shadow, "class ", class_name, NIL); if (Len(base_class)) { - Printf(f_shadow,"(%s)", base_class); + Printf(f_shadow, "(%s)", base_class); } else { if (!classic) { Printf(f_shadow, modern ? "(object)" : "(_object)"); } } - Printf(f_shadow,":\n"); - if ( have_docstring(n) ) { - String* str = docstring(n, AUTODOC_CLASS, tab4); - if (str != NULL && Len(str)) - Printv(f_shadow, tab4, str, "\n", NIL); + Printf(f_shadow, ":\n"); + if (have_docstring(n)) { + String *str = docstring(n, AUTODOC_CLASS, tab4); + if (str != NULL && Len(str)) + Printv(f_shadow, tab4, str, "\n", NIL); } if (!modern) { - Printv(f_shadow,tab4,"__swig_setmethods__ = {}\n",NIL); - if (Len(base_class)) { - Printf(f_shadow,"%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n",tab4,base_class); - } + Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(_s.__swig_setmethods__)\n", tab4, base_class); + } - if (!GetFlag(n,"feature:python:nondynamic")) { - Printv(f_shadow, - tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", - NIL); + if (!GetFlag(n, "feature:python:nondynamic")) { + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL); } else { - Printv(f_shadow, - tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", - NIL); - } + Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL); + } - Printv(f_shadow,tab4,"__swig_getmethods__ = {}\n",NIL); - if (Len(base_class)) { - Printf(f_shadow,"%sfor _s in [%s]: __swig_getmethods__.update(_s.__swig_getmethods__)\n",tab4,base_class); - } - - Printv(f_shadow, - tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", - NIL); + Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL); + if (Len(base_class)) { + Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(_s.__swig_getmethods__)\n", tab4, base_class); + } + + Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL); } else { - Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", - "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); + Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL); /* Add static attribute */ - if (GetFlag(n,"feature:python:nondynamic")) { + if (GetFlag(n, "feature:python:nondynamic")) { Printv(f_shadow_file, tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n", - tab4, "class __metaclass__(type):\n", - tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", - NIL); - } + tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL); + } } } - + /* Emit all of the members */ in_class = 1; /* Overide the shadow file so we can capture its methods */ - f_shadow = NewString(""); + f_shadow = NewString(""); Language::classHandler(n); in_class = 0; @@ -2724,10 +2653,9 @@ public: if (shadow) { /* Generate a class registration function */ { - SwigType *ct = NewStringf("p.%s", real_classname); + SwigType *ct = NewStringf("p.%s", real_classname); SwigType_remember(ct); - Printv(f_wrappers, - "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, ctab4, "PyObject *obj;\n", NIL); if (modernargs) { if (fastunpack) { @@ -2740,21 +2668,19 @@ public: } Printv(f_wrappers, - ctab4, "SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct),", SWIG_NewClientData(obj));\n", - ctab4, "return SWIG_Py_Void();\n", - "}\n\n",NIL); + ctab4, "SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", + ctab4, "return SWIG_Py_Void();\n", "}\n\n", NIL); String *cname = NewStringf("%s_swigregister", class_name); add_method(cname, cname, 0); Delete(cname); Delete(ct); } if (!have_constructor) { - Printv(f_shadow_file, tab4,"def __init__(self): raise AttributeError, \"No constructor defined\"\n", NIL); + Printv(f_shadow_file, tab4, "def __init__(self): raise AttributeError, \"No constructor defined\"\n", NIL); } else if (fastinit) { - + Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); - Printv(f_wrappers, ctab4, "return SWIG_Python_InitShadowInstance(args);\n", - "}\n\n",NIL); + Printv(f_wrappers, ctab4, "return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL); String *cname = NewStringf("%s_swiginit", class_name); add_method(cname, cname, 0); Delete(cname); @@ -2763,15 +2689,9 @@ public: /* Supply a repr method for this class */ String *rname = SwigType_namestr(real_classname); if (new_repr) { - Printv(f_shadow_file, - tab4, "__repr__ = _swig_repr\n", - NIL); - } - else { - Printv(f_shadow_file, - tab4, "def __repr__(self):\n", - tab8, "return \"\" % (self.this,)\n", - NIL); + Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL); + } else { + Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL); } Delete(rname); } @@ -2782,41 +2702,34 @@ public: /* Now the Ptr class */ if (classptr) { - Printv(f_shadow_file, - "\nclass ", class_name, "Ptr(", class_name, "):\n", - tab4, "def __init__(self, this):\n", NIL); + Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL); if (!modern) { Printv(f_shadow_file, tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", - tab8, "self.this.own(0)\n", - tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } else { Printv(f_shadow_file, tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", - tab8, "self.this.own(0)\n", - tab8, "self.__class__ = ", class_name, "\n\n", NIL); + tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL); } } - + if (fastproxy) { - List *shadow_list = Getattr(n,"shadow_methods"); + List *shadow_list = Getattr(n, "shadow_methods"); for (int i = 0; i < Len(shadow_list); ++i) { - String *symname = Getitem(shadow_list,i); - Printf(f_shadow_file,"%s.%s = new_instancemethod(%s.%s,None,%s)\n", - class_name, symname, module, Swig_name_member(class_name,symname), class_name); + String *symname = Getitem(shadow_list, i); + Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(class_name, symname), class_name); } } - Printf(f_shadow_file,"%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); - Printf(f_shadow_file,"%s_swigregister(%s)\n", class_name, class_name,0); - + Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); + Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name, 0); + shadow_indent = 0; - Printf(f_shadow_file,"%s\n", f_shadow_stubs); + Printf(f_shadow_file, "%s\n", f_shadow_stubs); Clear(f_shadow_stubs); } classic = oldclassic; - modern = oldmodern; + modern = oldmodern; /* Restore shadow file back to original version */ Delete(f_shadow); @@ -2830,80 +2743,81 @@ public: * ------------------------------------------------------------ */ virtual int functionHandler(Node *n) { - String *pcb = GetFlagAttr(n,"feature:python:callback"); + String *pcb = GetFlagAttr(n, "feature:python:callback"); if (pcb) { - if (Strcmp(pcb,"1") == 0) { - SetFlagAttr(n,"feature:callback","%s_cb_ptr"); + if (Strcmp(pcb, "1") == 0) { + SetFlagAttr(n, "feature:callback", "%s_cb_ptr"); } else { - SetFlagAttr(n,"feature:callback",pcb); + SetFlagAttr(n, "feature:callback", pcb); } autodoc_l dlevel = autodoc_level(Getattr(n, "feature:autodoc")); if (dlevel != NO_AUTODOC && dlevel > TYPES_AUTODOC) { - Setattr(n,"feature:autodoc","1"); + Setattr(n, "feature:autodoc", "1"); } } return Language::functionHandler(n); - } + } /* ------------------------------------------------------------ * memberfunctionHandler() * ------------------------------------------------------------ */ virtual int memberfunctionHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); - int oldshadow; + String *symname = Getattr(n, "sym:name"); + int oldshadow; /* Create the default member function */ - oldshadow = shadow; /* Disable shadowing when wrapping member functions */ - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + oldshadow = shadow; /* Disable shadowing when wrapping member functions */ + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; Language::memberfunctionHandler(n); shadow = oldshadow; - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { if (shadow) { - int allow_kwargs = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0; + int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; int fproxy = fastproxy; - if (Strcmp(symname,"__repr__") == 0) { + if (Strcmp(symname, "__repr__") == 0) { have_repr = 1; } - if (Getattr(n,"feature:shadow")) { - String *pycode = pythoncode(Getattr(n,"feature:shadow"),tab4); - String *pyaction = NewStringf("%s.%s", module, Swig_name_member(class_name,symname)); - Replaceall(pycode,"$action", pyaction); + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_member(class_name, symname)); + Replaceall(pycode, "$action", pyaction); Delete(pyaction); - Printv(f_shadow,pycode,"\n",NIL); + Printv(f_shadow, pycode, "\n", NIL); Delete(pycode); fproxy = 0; } else { if (!have_addtofunc(n)) { if (!fastproxy || olddefs) { Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):", NIL); - Printv(f_shadow, " return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); + Printv(f_shadow, " return ", funcCallHelper(Swig_name_member(class_name, symname), allow_kwargs), "\n", NIL); } } else { Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):", NIL); - Printv(f_shadow, "\n", NIL); - if ( have_docstring(n) ) - Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); - if ( have_pythonprepend(n) ) { + Printv(f_shadow, "\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); + if (have_pythonprepend(n)) { fproxy = 0; - Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); } - if ( have_pythonappend(n) ) { + if (have_pythonappend(n)) { fproxy = 0; - Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); - Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n\n", NIL); - } + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), allow_kwargs), "\n", NIL); + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), allow_kwargs), "\n\n", NIL); + } } } if (fproxy) { - List *shadow_list = Getattr(getCurrentClass(),"shadow_methods"); + List *shadow_list = Getattr(getCurrentClass(), "shadow_methods"); if (!shadow_list) { shadow_list = NewList(); - Setattr(getCurrentClass(),"shadow_methods", shadow_list); + Setattr(getCurrentClass(), "shadow_methods", shadow_list); Delete(shadow_list); } Append(shadow_list, symname); @@ -2916,45 +2830,42 @@ public: /* ------------------------------------------------------------ * staticmemberfunctionHandler() * ------------------------------------------------------------ */ - + virtual int staticmemberfunctionHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); Language::staticmemberfunctionHandler(n); - if (Getattr(n,"sym:nextSibling")) { + if (Getattr(n, "sym:nextSibling")) { return SWIG_OK; } - - if (shadow) { - if ( !classic && !Getattr(n,"feature:python:callback") && have_addtofunc(n)) { - int kw = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0; - Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); - if ( have_docstring(n) ) - Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); - if ( have_pythonprepend(n) ) - Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); - if ( have_pythonappend(n) ) { - Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); - Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); - Printv(f_shadow, tab8, "return val\n\n", NIL); - } else { - Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n\n", NIL); - } - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, - " = staticmethod(", symname, ")\n", NIL); - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); - } - + if (shadow) { + if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { + int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; + Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); + if (have_pythonappend(n)) { + Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL); + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); + Printv(f_shadow, tab8, "return val\n\n", NIL); + } else { + Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n\n", NIL); + } + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL); + + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL); + } + } else { - if (!modern) { - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(class_name, symname), "\n", NIL); - } - if (!classic) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, - " = staticmethod(", module, ".", - Swig_name_member(class_name, symname), ")\n", NIL); + if (!modern) { + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(class_name, symname), "\n", NIL); + } + if (!classic) { + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(class_name, symname), ")\n", NIL); } } } @@ -2966,59 +2877,61 @@ public: * ------------------------------------------------------------ */ virtual int constructorHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); - int oldshadow = shadow; - int use_director = Swig_directorclass(n); + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + int use_director = Swig_directorclass(n); /* * If we're wrapping the constructor of a C++ director class, prepend a new parameter * to receive the scripting language object (e.g. 'self') * */ - Swig_save("python:constructorHandler",n,"parms",NIL); + Swig_save("python:constructorHandler", n, "parms", NIL); if (use_director) { - Parm *parms = Getattr(n, "parms"); - Parm *self; - String *name = NewString("self"); - String *type = NewString("PyObject"); - SwigType_add_pointer(type); - self = NewParm(type, name); - Delete(type); - Delete(name); - Setattr(self, "lname", "O"); - if (parms) set_nextSibling(self, parms); - Setattr(n, "parms", self); - Setattr(n, "wrap:self", "1"); - Setattr(n, "hidden", "1"); - Delete(self); + Parm *parms = Getattr(n, "parms"); + Parm *self; + String *name = NewString("self"); + String *type = NewString("PyObject"); + SwigType_add_pointer(type); + self = NewParm(type, name); + Delete(type); + Delete(name); + Setattr(self, "lname", "O"); + if (parms) + set_nextSibling(self, parms); + Setattr(n, "parms", self); + Setattr(n, "wrap:self", "1"); + Setattr(n, "hidden", "1"); + Delete(self); } - - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; Language::constructorHandler(n); shadow = oldshadow; Delattr(n, "wrap:self"); Swig_restore(n); - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { if (shadow) { - int allow_kwargs = (check_kwargs(n) && (!Getattr(n,"sym:overloaded"))) ? 1 : 0; + int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0; int handled_as_init = 0; if (!have_constructor) { - String *nname = Getattr(n,"sym:name"); - String *sname = Getattr(getCurrentClass(),"sym:name"); + String *nname = Getattr(n, "sym:name"); + String *sname = Getattr(getCurrentClass(), "sym:name"); String *cname = Swig_name_construct(sname); - handled_as_init = (Strcmp(nname,sname) == 0) || (Strcmp(nname,cname) == 0); + handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0); Delete(cname); } if (!have_constructor && handled_as_init) { - if (Getattr(n,"feature:shadow")) { - String *pycode = pythoncode(Getattr(n,"feature:shadow"),tab4); - String *pyaction = NewStringf("%s.%s",module, Swig_name_construct(symname)); - Replaceall(pycode,"$action", pyaction); + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); + String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(symname)); + Replaceall(pycode, "$action", pyaction); Delete(pyaction); - Printv(f_shadow,pycode,"\n",NIL); + Printv(f_shadow, pycode, "\n", NIL); Delete(pycode); } else { String *pass_self = NewString(""); @@ -3026,63 +2939,56 @@ public: String *classname = Swig_class_name(parent); String *rclassname = Swig_class_name(getCurrentClass()); assert(rclassname); - if (use_director) { - Printv(pass_self, tab8, NIL); + if (use_director) { + Printv(pass_self, tab8, NIL); Printf(pass_self, "if self.__class__ == %s:\n", classname); - Printv(pass_self, tab8, tab4, "args = (None,) + args\n", - tab8, "else:\n", - tab8, tab4, "args = (self,) + args\n", - NIL); - } - - Printv(f_shadow, tab4, "def __init__(self, *args",(allow_kwargs ? ", **kwargs" : ""),"): \n", NIL); - if ( have_docstring(n) ) - Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8),"\n",NIL); - if ( have_pythonprepend(n) ) - Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); - Printv(f_shadow, pass_self, NIL); - if (fastinit) { - Printv(f_shadow, - tab8, module, ".", class_name, "_swiginit(self,", funcCallHelper(Swig_name_construct(symname), allow_kwargs),")\n", NIL); - } else { - Printv(f_shadow, - tab8, "this = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs),"\n", - tab8, "try: self.this.append(this)\n", - tab8, "except: self.this = this\n", NIL); + Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL); } - if ( have_pythonappend(n) ) - Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL); - Delete(pass_self); - } + + Printv(f_shadow, tab4, "def __init__(self, *args", (allow_kwargs ? ", **kwargs" : ""), "): \n", NIL); + if (have_docstring(n)) + Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); + Printv(f_shadow, pass_self, NIL); + if (fastinit) { + Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL); + } else { + Printv(f_shadow, + tab8, "this = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", + tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL); + } + if (have_pythonappend(n)) + Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL); + Delete(pass_self); + } have_constructor = 1; } else { /* Hmmm. We seem to be creating a different constructor. We're just going to create a function for it. */ - if (Getattr(n,"feature:shadow")) { - String *pycode = pythoncode(Getattr(n,"feature:shadow"),""); + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), ""); String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(symname)); - Replaceall(pycode,"$action", pyaction); + Replaceall(pycode, "$action", pyaction); Delete(pyaction); - Printv(f_shadow_stubs,pycode,"\n",NIL); + Printv(f_shadow_stubs, pycode, "\n", NIL); Delete(pycode); } else { - Printv(f_shadow_stubs, "\ndef ", symname, "(*args", - (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); - if ( have_docstring(n) ) - Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); - if ( have_pythonprepend(n) ) - Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL); - Printv(f_shadow_stubs, tab4, "val = ", - funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); + Printv(f_shadow_stubs, "\ndef ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL); + if (have_docstring(n)) + Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL); + if (have_pythonprepend(n)) + Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL); + Printv(f_shadow_stubs, tab4, "val = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); #ifdef USE_THISOWN Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); #endif - if ( have_pythonappend(n) ) - Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); - Printv(f_shadow_stubs, tab4, "return val\n", NIL); - } + if (have_pythonappend(n)) + Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); + Printv(f_shadow_stubs, tab4, "return val\n", NIL); + } } } } @@ -3094,20 +3000,21 @@ public: * ------------------------------------------------------------ */ virtual int destructorHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); int oldshadow = shadow; - - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; //Setattr(n,"emit:dealloc","1"); Language::destructorHandler(n); shadow = oldshadow; if (shadow) { - if (Getattr(n,"feature:shadow")) { - String *pycode = pythoncode(Getattr(n,"feature:shadow"), tab4); + if (Getattr(n, "feature:shadow")) { + String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4); String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(symname)); Replaceall(pycode, "$action", pyaction); Delete(pyaction); - Printv(f_shadow,pycode,"\n", NIL); + Printv(f_shadow, pycode, "\n", NIL); Delete(pycode); } else { Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(symname), "\n", NIL); @@ -3118,20 +3025,20 @@ public: return SWIG_OK; } Printv(f_shadow, tab4, "def __del__(self):\n", NIL); - if ( have_docstring(n) ) + if (have_docstring(n)) Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); - if ( have_pythonprepend(n) ) + if (have_pythonprepend(n)) Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); #ifdef USE_THISOWN Printv(f_shadow, tab8, "try:\n", NIL); - Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(symname),"(self)\n", NIL); + Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(symname), "(self)\n", NIL); Printv(f_shadow, tab8, "except: pass\n", NIL); #else #endif - if ( have_pythonappend(n) ) + if (have_pythonappend(n)) Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); Printv(f_shadow, tab8, "pass\n", NIL); - Printv(f_shadow, "\n", NIL); + Printv(f_shadow, "\n", NIL); } } return SWIG_OK; @@ -3142,30 +3049,31 @@ public: * ------------------------------------------------------------ */ virtual int membervariableHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); + String *symname = Getattr(n, "sym:name"); - int oldshadow = shadow; - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; Language::membervariableHandler(n); shadow = oldshadow; if (shadow) { - String *mname = Swig_name_member(class_name,symname); + String *mname = Swig_name_member(class_name, symname); String *sname = Swig_name_set(mname); String *gname = Swig_name_get(mname); if (shadow) { int assignable = is_assignable(n); if (!modern) { if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname,"\n", NIL); + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); + } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname, "\n", NIL); } if (!classic) { if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = _swig_property(", module, ".", gname,")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ")\n", NIL); } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = _swig_property(", module, ".", gname,", ", module, ".", sname,")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ", ", module, ".", sname, ")\n", NIL); } } } @@ -3173,7 +3081,7 @@ public: Delete(sname); Delete(gname); } - + return SWIG_OK; } @@ -3184,55 +3092,55 @@ public: virtual int staticmembervariableHandler(Node *n) { Language::staticmembervariableHandler(n); - if (shadow && !GetFlag(n,"wrappedasconstant")) { - String *symname = Getattr(n,"sym:name"); - if (GetFlag(n,"hasconsttype")) { - String *mname = Swig_name_member(class_name,symname); - Printf(f_shadow_stubs,"%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); + if (shadow && !GetFlag(n, "wrappedasconstant")) { + String *symname = Getattr(n, "sym:name"); + if (GetFlag(n, "hasconsttype")) { + String *mname = Swig_name_member(class_name, symname); + Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname); Delete(mname); } else { - String *mname = Swig_name_member(class_name,symname); + String *mname = Swig_name_member(class_name, symname); String *gname = Swig_name_get(mname); String *wgname = Swig_name_wrapper(gname); String *sname = Swig_name_set(mname); String *wsname = Swig_name_wrapper(sname); - + Wrapper *f = NewWrapper(); Printv(f->def, "SWIGINTERN PyObject *", wgname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); - Printv(f->code," return ", gname,"();\n", NIL); - Append(f->code,"}\n"); + Printv(f->code, " return ", gname, "();\n", NIL); + Append(f->code, "}\n"); add_method(gname, wgname, 0); - Wrapper_print(f,f_wrappers); + Wrapper_print(f, f_wrappers); Delete(f); int assignable = is_assignable(n); if (assignable) { Wrapper *f = NewWrapper(); Printv(f->def, "SWIGINTERN PyObject *", wsname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); - Wrapper_add_local(f,"value","PyObject *value"); - Wrapper_add_local(f,"res","int res"); - Append(f->code,"if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); - Printv(f->code,"res = ", sname,"(value);\n", NIL); - Append(f->code,"return !res ? SWIG_Py_Void() : NULL;\n"); - Append(f->code,"}\n"); - Wrapper_print(f,f_wrappers); + Wrapper_add_local(f, "value", "PyObject *value"); + Wrapper_add_local(f, "res", "int res"); + Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n"); + Printv(f->code, "res = ", sname, "(value);\n", NIL); + Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n"); + Append(f->code, "}\n"); + Wrapper_print(f, f_wrappers); add_method(sname, wsname, 0); Delete(f); } if (!modern) { if (assignable) { - Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); - } - Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname,"\n", NIL); + Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", sname, "\n", NIL); + } + Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", gname, "\n", NIL); } if (!classic) { if (!assignable) { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = _swig_property(", module, ".", gname,")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ")\n", NIL); } else { - Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname," = _swig_property(", module, ".", gname,", ", module, ".", sname,")\n", NIL); + Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", gname, ", ", module, ".", sname, ")\n", NIL); } } Delete(mname); - Delete(gname); + Delete(gname); Delete(wgname); Delete(sname); Delete(wsname); @@ -3246,14 +3154,15 @@ public: * ------------------------------------------------------------ */ virtual int memberconstantHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); - int oldshadow = shadow; - if (shadow) shadow = shadow | PYSHADOW_MEMBER; + String *symname = Getattr(n, "sym:name"); + int oldshadow = shadow; + if (shadow) + shadow = shadow | PYSHADOW_MEMBER; Language::memberconstantHandler(n); shadow = oldshadow; if (shadow) { - Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(class_name,symname), "\n", NIL); + Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(class_name, symname), "\n", NIL); } return SWIG_OK; } @@ -3266,12 +3175,12 @@ public: * ------------------------------------------------------------ */ virtual int insertDirective(Node *n) { - String *code = Getattr(n,"code"); - String *section = Getattr(n,"section"); + String *code = Getattr(n, "code"); + String *section = Getattr(n, "section"); - if ((!ImportMode) && ((Cmp(section,"python") == 0) || (Cmp(section,"shadow") == 0))) { + if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) { if (shadow) { - String *pycode = pythoncode(code,shadow_indent); + String *pycode = pythoncode(code, shadow_indent); Printv(f_shadow, pycode, NIL); Delete(pycode); } @@ -3324,7 +3233,7 @@ public: virtual String *defaultExternalRuntimeFilename() { return NewString("swigpyrun.h"); } - + }; /* --------------------------------------------------------------- @@ -3336,7 +3245,7 @@ public: * ** Moved it here due to internal error on gcc-2.96 ** * --------------------------------------------------------------- */ int PYTHON::classDirectorMethods(Node *n) { - director_method_index = 0; + director_method_index = 0; return Language::classDirectorMethods(n); } @@ -3356,14 +3265,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { String *wrap_args = NewString(""); String *return_type; String *value = Getattr(n, "value"); - String *storage = Getattr(n,"storage"); + String *storage = Getattr(n, "storage"); bool pure_virtual = false; int status = SWIG_OK; int idx; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - if (Cmp(storage,"virtual") == 0) { - if (Cmp(value,"0") == 0) { + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { pure_virtual = true; } } @@ -3374,7 +3283,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { w = NewWrapper(); declaration = NewString(""); - + /* determine if the method returns a pointer */ decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); @@ -3411,25 +3320,26 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { else Printf(declaration, " virtual %s %s", rtype, target); Delete(target); - + // Get any exception classes in the throws typemap ParmList *throw_parm_list = 0; - if ((throw_parm_list = Getattr(n,"throws")) || Getattr(n,"throw")) { - Parm *p; - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; Append(w->def, " throw("); Append(declaration, " throw("); - if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); } - String *str = SwigType_str(Getattr(p, "type"),0); + String *str = SwigType_str(Getattr(p, "type"), 0); Append(w->def, str); Append(declaration, str); Delete(str); @@ -3458,160 +3368,164 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (ignored_method) { if (!pure_virtual) { if (!is_void) - Printf(w->code, "return "); + Printf(w->code, "return "); String *super_call = Swig_method_call(super, l); Printf(w->code, "%s;\n", super_call); Delete(super_call); } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name)); + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); } } else { /* attach typemaps to arguments (C/C++ -> Python) */ String *arglist = NewString(""); - String* parse_args = NewString(""); + String *parse_args = NewString(""); /* remove the wrapper 'w' since it was producing spurious temps */ Swig_typemap_attach_parms("in", l, 0); Swig_typemap_attach_parms("directorin", l, 0); Swig_typemap_attach_parms("directorargout", l, w); - Parm* p; + Parm *p; char source[256]; int outputs = 0; - if (!is_void) outputs++; - + if (!is_void) + outputs++; + /* build argument list and type conversion string */ idx = 0; p = l; int use_parse = 0; while (p != NULL) { - if (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + if (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); continue; } /* old style? caused segfaults without the p!=0 check - in the for() condition, and seems dangerous in the - while loop as well. - while (Getattr(p, "tmap:ignore")) { - p = Getattr(p, "tmap:ignore:next"); - } - */ + in the for() condition, and seems dangerous in the + while loop as well. + while (Getattr(p, "tmap:ignore")) { + p = Getattr(p, "tmap:ignore:next"); + } + */ - if (Getattr(p, "tmap:directorargout") != 0) outputs++; - - String* pname = Getattr(p, "name"); - String* ptype = Getattr(p, "type"); - - Putc(',',arglist); + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *pname = Getattr(p, "name"); + String *ptype = Getattr(p, "type"); + + Putc(',', arglist); if ((tm = Getattr(p, "tmap:directorin")) != 0) { - String* parse = Getattr(p, "tmap:directorin:parse"); + String *parse = Getattr(p, "tmap:directorin:parse"); if (!parse) { sprintf(source, "obj%d", idx++); String *input = NewString(source); Replaceall(tm, "$input", input); Delete(input); Replaceall(tm, "$owner", "0"); - /* Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL);*/ + /* Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL); */ Printv(wrap_args, "swig::PyObject_var ", source, ";\n", NIL); - + Printv(wrap_args, tm, "\n", NIL); - Printv(arglist, "(PyObject *)",source, NIL); + Printv(arglist, "(PyObject *)", source, NIL); Putc('O', parse_args); } else { use_parse = 1; Append(parse_args, parse); Replaceall(tm, "$input", pname); Replaceall(tm, "$owner", "0"); - if (Len(tm) == 0) Append(tm, pname); + if (Len(tm) == 0) + Append(tm, pname); Append(arglist, tm); } p = Getattr(p, "tmap:directorin:next"); continue; - } else - if (Cmp(ptype, "void")) { - /* special handling for pointers to other C++ director classes. - * ideally this would be left to a typemap, but there is currently no - * way to selectively apply the dynamic_cast<> to classes that have - * directors. in other words, the type "SwigDirector_$1_lname" only exists - * for classes with directors. we avoid the problem here by checking - * module.wrap::directormap, but it's not clear how to get a typemap to - * do something similar. perhaps a new default typemap (in addition - * to SWIGTYPE) called DIRECTORTYPE? - */ - if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { - Node *module = Getattr(parent, "module"); - Node *target = Swig_directormap(module, ptype); - sprintf(source, "obj%d", idx++); - String *nonconst = 0; - /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(ptype)+2); - /* name as pointer */ - String *ppname = Copy(pname); - if (SwigType_isreference(ptype)) { - Insert(ppname,0,"&"); - } - /* if necessary, cast away const since Python doesn't support it! */ - if (SwigType_isconst(nptype)) { - nonconst = NewStringf("nc_tmp_%s", pname); - String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); - Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); - Delete(nonconst_i); - Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", - SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); - } else { - nonconst = Copy(ppname); - } - Delete(nptype); - Delete(ppname); - String *mangle = SwigType_manglestr(ptype); - if (target) { - String *director = NewStringf("director_%s", mangle); - Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); - Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); - Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); - Append(wrap_args, "} else {\n"); - Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); - Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); - Append(wrap_args, "}\n"); - Delete(director); - Printv(arglist, source, NIL); - } else { - Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", - source, nonconst, mangle); - //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", - // source, nonconst, base); - Printv(arglist, source, NIL); - } - Putc('O', parse_args); - Delete(mangle); - Delete(nonconst); - } else { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); - status = SWIG_NOWRAP; - break; + } else if (Cmp(ptype, "void")) { + /* special handling for pointers to other C++ director classes. + * ideally this would be left to a typemap, but there is currently no + * way to selectively apply the dynamic_cast<> to classes that have + * directors. in other words, the type "SwigDirector_$1_lname" only exists + * for classes with directors. we avoid the problem here by checking + * module.wrap::directormap, but it's not clear how to get a typemap to + * do something similar. perhaps a new default typemap (in addition + * to SWIGTYPE) called DIRECTORTYPE? + */ + if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { + Node *module = Getattr(parent, "module"); + Node *target = Swig_directormap(module, ptype); + sprintf(source, "obj%d", idx++); + String *nonconst = 0; + /* strip pointer/reference --- should move to Swig/stype.c */ + String *nptype = NewString(Char(ptype) + 2); + /* name as pointer */ + String *ppname = Copy(pname); + if (SwigType_isreference(ptype)) { + Insert(ppname, 0, "&"); } + /* if necessary, cast away const since Python doesn't support it! */ + if (SwigType_isconst(nptype)) { + nonconst = NewStringf("nc_tmp_%s", pname); + String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname); + Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); + Delete(nonconst_i); + Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, + "Target language argument '%s' discards const in director method %s::%s.\n", + SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); + } else { + nonconst = Copy(ppname); + } + Delete(nptype); + Delete(ppname); + String *mangle = SwigType_manglestr(ptype); + if (target) { + String *director = NewStringf("director_%s", mangle); + Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); + Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); + Printf(wrap_args, "if (!%s) {\n", director); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Append(wrap_args, "} else {\n"); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); + Append(wrap_args, "}\n"); + Delete(director); + Printv(arglist, source, NIL); + } else { + Wrapper_add_localv(w, source, "swig::PyObject_var", source, "= 0", NIL); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", + // source, nonconst, base); + Printv(arglist, source, NIL); + } + Putc('O', parse_args); + Delete(mangle); + Delete(nonconst); + } else { + Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); + status = SWIG_NOWRAP; + break; } + } p = nextSibling(p); } /* add the method name as a PyString */ - String *pyname = Getattr(n,"sym:name"); + String *pyname = Getattr(n, "sym:name"); int allow_thread = threads_enable(n); - if (allow_thread) thread_begin_block(n, w->code); + if (allow_thread) + thread_begin_block(n, w->code); if (allow_thread) { Append(w->code, "{\n"); } - + /* wrap complex arguments to PyObjects */ Printv(w->code, wrap_args, NIL); @@ -3619,12 +3533,12 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (dirprot_mode() && !is_public(n)) { Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); } - + Append(w->code, "if (!swig_get_self()) {\n"); Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname); - Append(w->code, "}\n"); - Append(w->code,"#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); + Append(w->code, "}\n"); + Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); @@ -3643,25 +3557,24 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Printf(w->code, "swig::PyObject_var result = PyObject_CallFunction(method, NULL, NULL);\n"); } } - Append(w->code,"#else\n"); + Append(w->code, "#else\n"); if (Len(parse_args) > 0) { if (use_parse || !modernargs) { - Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", + Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", pyname, parse_args, arglist); } else { Printf(w->code, "swig::PyObject_var swig_method_name = PyString_FromString((char *)\"%s\");\n", pyname); - Printf(w->code, "swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", - arglist); + Printf(w->code, "swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist); } } else { if (!modernargs) { - Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); + Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); } else { Printf(w->code, "swig::PyObject_var swig_method_name = PyString_FromString((char *)\"%s\");\n", pyname); Append(w->code, "swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); } } - Append(w->code,"#endif\n"); + Append(w->code, "#endif\n"); if (dirprot_mode() && !is_public(n)) Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); @@ -3670,7 +3583,8 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { tm = Swig_typemap_lookup_new("director:except", n, "result", 0); if (!tm) { tm = Getattr(n, "feature:director:except"); - if (tm) tm = Copy(tm); + if (tm) + tm = Copy(tm); } Append(w->code, "if (result == NULL) {\n"); Append(w->code, " PyObject *error = PyErr_Occurred();\n"); @@ -3679,8 +3593,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Printv(w->code, Str(tm), "\n", NIL); } else { Append(w->code, " if (error != NULL) {\n"); - Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", - classname, pyname); + Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname); Append(w->code, " }\n"); } Append(w->code, "}\n"); @@ -3695,14 +3608,13 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* marshal return value and other outputs (if any) from PyObject to C/C++ type */ - String* cleanup = NewString(""); - String* outarg = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); if (outputs > 1) { Wrapper_add_local(w, "output", "PyObject *output"); Append(w->code, "if (!PyTuple_Check(result)) {\n"); - Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", - classname, pyname); + Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname); Append(w->code, "}\n"); } @@ -3733,30 +3645,31 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { Replaceall(tm, "$input", "result"); } char temp[24]; - sprintf(temp,"%d",idx); - Replaceall(tm,"$argnum",temp); + sprintf(temp, "%d", idx); + Replaceall(tm, "$argnum", temp); /* TODO check this */ - if (Getattr(n,"wrap:disown")) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); } else { - Replaceall(tm,"$disown","0"); + Replaceall(tm, "$disown", "0"); } - if (Getattr(n,"tmap:directorout:implicitconv")) { - Replaceall(tm,"$implicitconv", get_implicitconv_flag(n)); + if (Getattr(n, "tmap:directorout:implicitconv")) { + Replaceall(tm, "$implicitconv", get_implicitconv_flag(n)); } Replaceall(tm, "$result", "c_result"); Printv(w->code, tm, "\n", NIL); Delete(tm); } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), + SwigType_namestr(name)); status = SWIG_ERROR; } } - + /* marshal outputs */ - for (p = l; p; ) { + for (p = l; p;) { if ((tm = Getattr(p, "tmap:directorargout")) != 0) { if (outputs > 1) { Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++); @@ -3786,7 +3699,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String* rettype = SwigType_str(return_type, 0); + String *rettype = SwigType_str(return_type, 0); if (!SwigType_isreference(return_type)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { @@ -3800,8 +3713,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) - { + if (dirprot_mode() && !is_public(n) && !pure_virtual) { Printv(inline_extra_method, declaration, NIL); String *extra_method_name = NewStringf("%sSwigPublic", name); Replaceall(inline_extra_method, name, extra_method_name); @@ -3816,7 +3728,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { /* emit the director method */ if (status == SWIG_OK) { - if (!Getattr(n,"defaultargs")) { + if (!Getattr(n, "defaultargs")) { Wrapper_print(w, f_directors); Printv(f_directors_h, declaration, NIL); Printv(f_directors_h, inline_extra_method, NIL); @@ -3836,10 +3748,9 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) { * swig_python() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_python() { +static Language *new_swig_python() { return new PYTHON(); } -extern "C" Language * swig_python(void) { +extern "C" Language *swig_python(void) { return new_swig_python(); } - diff --git a/SWIG/Source/Modules/r.cxx b/SWIG/Source/Modules/r.cxx index e9993e9ea..4a0b65b0a 100644 --- a/SWIG/Source/Modules/r.cxx +++ b/SWIG/Source/Modules/r.cxx @@ -320,10 +320,9 @@ public: return status; } - - // Grab the name of the current class being processed so that we can - // deal with members of that class. - int classHandler(Node *n){ + /* Grab the name of the current class being processed so that we can + deal with members of that class. */ + int classHandler(Node *n){ if(!ClassMemberTable) ClassMemberTable = NewHash(); @@ -333,6 +332,7 @@ public: class_name = NULL; return status; }; + // Not used: String *runtimeCode(); @@ -362,6 +362,7 @@ protected: namespaceFunctions = NewList(); Append(namespaceFunctions, name); } + void addNamespaceMethod(String *name) { if(!namespaceMethods) namespaceMethods = NewList(); @@ -474,8 +475,7 @@ static int getFunctionPointerNumArgs(Node *n, SwigType *tt) { } -void -R::addSMethodInfo(String *name, String *argType, int nargs) { +void R::addSMethodInfo(String *name, String *argType, int nargs) { (void) argType; if(!SMethodInfo) @@ -2953,8 +2953,7 @@ void R::main(int argc, char *argv[]) { Could make this work for String or File and then just store the resulting string rather than the collection of arguments and argc. */ -int -R::outputCommandLineArguments(File *out) +int R::outputCommandLineArguments(File *out) { if(argc < 1 || !argv || !argv[0]) return(-1); @@ -2973,8 +2972,7 @@ R::outputCommandLineArguments(File *out) /* How SWIG instantiates an object from this module. See swigmain.cxx */ extern "C" -Language *swig_r(void) -{ +Language *swig_r(void) { return new R(); } diff --git a/SWIG/Source/Modules/ruby.cxx b/SWIG/Source/Modules/ruby.cxx index 14d76c88f..1292cfbf0 100644 --- a/SWIG/Source/Modules/ruby.cxx +++ b/SWIG/Source/Modules/ruby.cxx @@ -17,16 +17,16 @@ static int treduce = SWIG_cparse_template_reduce(0); #include #include -#include /* for INT_MAX */ +#include /* for INT_MAX */ class RClass { - private: +private: String *temp; - public: - String *name; /* class name (renamed) */ - String *cname; /* original C class/struct name */ - String *mname; /* Mangled name */ - +public: + String *name; /* class name (renamed) */ + String *cname; /* original C class/struct name */ + String *mname; /* Mangled name */ + /** * The C variable name used in the SWIG-generated wrapper code to refer to * this class; usually it is of the form "cClassName.klass", where cClassName @@ -50,7 +50,7 @@ class RClass { int constructor_defined; int destructor_defined; - RClass() { + RClass() { temp = NewString(""); name = NewString(""); cname = NewString(""); @@ -79,7 +79,7 @@ class RClass { void set_name(const String_or_char *cn, const String_or_char *rn, const String_or_char *valn) { /* Original C/C++ class (or struct) name */ Clear(cname); - Append(cname,cn); + Append(cname, cn); /* Mangled name */ Delete(mname); @@ -87,34 +87,33 @@ class RClass { /* Renamed class name */ Clear(name); - Append(name,valn); + Append(name, valn); /* Variable name for the VALUE that refers to the Ruby Class object */ Clear(vname); Printf(vname, "c%s.klass", name); - + /* Variable name for the VALUE that refers to the Ruby Class object */ Clear(mImpl); Printf(mImpl, "c%s.mImpl", name); /* Prefix */ Clear(prefix); - Printv(prefix,(rn ? rn : cn), "_", NIL); + Printv(prefix, (rn ? rn : cn), "_", NIL); } char *strip(const String_or_char *s) { Clear(temp); Append(temp, s); if (Strncmp(s, prefix, Len(prefix)) == 0) { - Replaceall(temp,prefix,""); + Replaceall(temp, prefix, ""); } return Char(temp); } }; -static const char * -usage = "\ +static const char *usage = "\ Ruby Options (available with -ruby)\n\ -globalmodule - Wrap everything into the global module\n\ -minherit - Attempt to support multiple inheritance\n\ @@ -129,7 +128,7 @@ Ruby Options (available with -ruby)\n\ #define RCLASS(hash, name) (RClass*)(Getattr(hash, name) ? Data(Getattr(hash, name)) : 0) #define SET_RCLASS(hash, name, klass) Setattr(hash, name, NewVoid(klass, 0)) -class RUBY : public Language { +class RUBY:public Language { private: String *module; @@ -175,7 +174,7 @@ public: * Initialize member data * --------------------------------------------------------------------- */ - RUBY() { + RUBY() { module = 0; modvar = 0; feature = 0; @@ -191,75 +190,73 @@ public: f_initbeforefunc = 0; useGlobalModule = false; multipleInheritance = false; - director_prot_ctor_code = NewString(""); + director_prot_ctor_code = NewString(""); Printv(director_prot_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", - "} else {\n", - " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", - " return Qnil;\n", - "}\n", NIL); + "} else {\n", " rb_raise(rb_eRuntimeError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL); director_multiple_inheritance = 0; director_language = 1; } - + /* --------------------------------------------------------------------- * main() * * Parse command line options and initializes variables. * --------------------------------------------------------------------- */ - + virtual void main(int argc, char *argv[]) { + int cppcast = 1; int autorename = 0; /* Set location of SWIG library */ SWIG_library_directory("ruby"); - + /* Look for certain command line options */ for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i],"-feature") == 0) { - if (argv[i+1]) { - char *name = argv[i+1]; + if (strcmp(argv[i], "-feature") == 0) { + if (argv[i + 1]) { + char *name = argv[i + 1]; feature = NewString(name); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; } else { Swig_arg_error(); } - } else if (strcmp(argv[i],"-globalmodule") == 0) { - useGlobalModule = true; + } else if (strcmp(argv[i], "-globalmodule") == 0) { + useGlobalModule = true; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-minherit") == 0) { - multipleInheritance = true; + } else if (strcmp(argv[i], "-minherit") == 0) { + multipleInheritance = true; director_multiple_inheritance = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-cppcast") == 0) { + } else if (strcmp(argv[i], "-cppcast") == 0) { cppcast = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocppcast") == 0) { + } else if (strcmp(argv[i], "-nocppcast") == 0) { cppcast = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-autorename") == 0) { + } else if (strcmp(argv[i], "-autorename") == 0) { autorename = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-noautorename") == 0) { + } else if (strcmp(argv[i], "-noautorename") == 0) { autorename = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-prefix") == 0) { - if (argv[i+1]) { - char *name = argv[i+1]; - prefix = NewString(name); - Swig_mark_arg(i); - Swig_mark_arg(i+1); - i++; - } else { - Swig_arg_error(); - } - } else if (strcmp(argv[i],"-help") == 0) { - Printf(stdout,"%s\n", usage); + } else if (strcmp(argv[i], "-prefix") == 0) { + if (argv[i + 1]) { + char *name = argv[i + 1]; + prefix = NewString(name); + Swig_mark_arg(i); + Swig_mark_arg(i + 1); + i++; + } else { + Swig_arg_error(); + } + } else if (strcmp(argv[i], "-help") == 0) { + Printf(stdout, "%s\n", usage); } } } @@ -276,7 +273,7 @@ public: /* Add a symbol to the parser for conditional compilation */ Preprocessor_define("SWIGRUBY 1", 0); - + /* Add typemap definitions */ SWIG_typemap_lang("ruby"); SWIG_config_file("ruby.swg"); @@ -288,19 +285,17 @@ public: * accounting for nested modules as necessary. */ void defineRubyModule() { - List *modules = Split(module,':',INT_MAX); + List *modules = Split(module, ':', INT_MAX); if (modules != 0 && Len(modules) > 0) { String *mv = 0; Iterator m; m = First(modules); while (m.item) { - if (Len(m.item) > 0) { + if (Len(m.item) > 0) { if (mv != 0) { - Printv(f_init, tab4, modvar, - " = rb_define_module_under(", modvar, ", \"", m.item, "\");\n", NIL); + Printv(f_init, tab4, modvar, " = rb_define_module_under(", modvar, ", \"", m.item, "\");\n", NIL); } else { - Printv(f_init, tab4, modvar, - " = rb_define_module(\"", m.item, "\");\n", NIL); + Printv(f_init, tab4, modvar, " = rb_define_module(\"", m.item, "\");\n", NIL); mv = NewString(modvar); } } @@ -322,15 +317,15 @@ public: Setattr(special_methods, "__cmp__", "<=>"); Setattr(special_methods, "__hash__", "hash"); Setattr(special_methods, "__nonzero__", "nonzero?"); - + /* Callable */ Setattr(special_methods, "__call__", "call"); - + /* Collection */ Setattr(special_methods, "__len__", "length"); Setattr(special_methods, "__getitem__", "[]"); Setattr(special_methods, "__setitem__", "[]="); - + /* Operators */ Setattr(special_methods, "__add__", "+"); Setattr(special_methods, "__pos__", "+@"); @@ -374,43 +369,43 @@ public: if (swigModule) { Node *options = Getattr(swigModule, "options"); if (options) { - if (Getattr(options, "directors")) { - allow_directors(); - } - if (Getattr(options, "dirprot")) { - allow_dirprot(); + if (Getattr(options, "directors")) { + allow_directors(); } - if (Getattr(options, "ruby_globalmodule")) { - useGlobalModule = true; - } - if (Getattr(options, "ruby_minherit")) { - multipleInheritance = true; + if (Getattr(options, "dirprot")) { + allow_dirprot(); + } + if (Getattr(options, "ruby_globalmodule")) { + useGlobalModule = true; + } + if (Getattr(options, "ruby_minherit")) { + multipleInheritance = true; director_multiple_inheritance = 1; - } + } } } /* Set comparison with none for ConstructorToFunction */ - - setSubclassInstanceCheck(NewStringf("strcmp(rb_obj_classname(self), classname) != 0")); + + setSubclassInstanceCheck(NewStringf("strcmp(rb_obj_classname(self), classname) != 0")); // setSubclassInstanceCheck(NewString("CLASS_OF(self) != cFoo.klass")); /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); + String *outfile = Getattr(n, "outfile"); String *outfile_h = Getattr(n, "outfile_h"); - f_runtime = NewFile(outfile,"w"); + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); } if (directorsEnabled()) { - f_runtime_h = NewFile(outfile_h,"w"); + f_runtime_h = NewFile(outfile_h, "w"); if (!f_runtime_h) { - FileErrorDisplay(outfile_h); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(outfile_h); + SWIG_exit(EXIT_FAILURE); } } @@ -423,42 +418,42 @@ public: f_initbeforefunc = NewString(""); /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - Swig_register_filebyname("director",f_directors); - Swig_register_filebyname("director_h",f_directors_h); - Swig_register_filebyname("director_helpers",f_directors_helpers); + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + Swig_register_filebyname("director", f_directors); + Swig_register_filebyname("director_h", f_directors_h); + Swig_register_filebyname("director_helpers", f_directors_helpers); Swig_register_filebyname("initbeforefunc", f_initbeforefunc); modvar = 0; current = NO_CPP; klass = 0; classes = NewHash(); - + registerMagicMethods(); Swig_banner(f_runtime); - Printf(f_runtime,"#define SWIGRUBY\n"); + Printf(f_runtime, "#define SWIGRUBY\n"); if (directorsEnabled()) { - Printf(f_runtime,"#define SWIG_DIRECTORS\n"); + Printf(f_runtime, "#define SWIG_DIRECTORS\n"); } /* typedef void *VALUE */ SwigType *value = NewSwigType(T_VOID); SwigType_add_pointer(value); - SwigType_typedef(value,(char*)"VALUE"); + SwigType_typedef(value, (char *) "VALUE"); Delete(value); /* Set module name */ - set_module(Char(Getattr(n,"name"))); + set_module(Char(Getattr(n, "name"))); if (directorsEnabled()) { /* Build a version of the module name for use in a C macro name. */ - String * module_macro = Copy(module); + String *module_macro = Copy(module); Replaceall(module_macro, "::", "__"); Swig_banner(f_directors_h); @@ -482,38 +477,24 @@ public: Delete(module_macro); } - Printf(f_header,"#define SWIG_init Init_%s\n", feature); - Printf(f_header,"#define SWIG_name \"%s\"\n\n", module); - Printf(f_header,"static VALUE %s;\n", modvar); + Printf(f_header, "#define SWIG_init Init_%s\n", feature); + Printf(f_header, "#define SWIG_name \"%s\"\n\n", module); + Printf(f_header, "static VALUE %s;\n", modvar); /* Start generating the initialization function */ - Printv(f_init, - "\n", - "#ifdef __cplusplus\n", - "extern \"C\"\n", - "#endif\n", - "SWIGEXPORT void Init_", feature, "(void) {\n", - "size_t i;\n", - "\n", - NIL); + Printv(f_init, "\n", "#ifdef __cplusplus\n", "extern \"C\"\n", "#endif\n", "SWIGEXPORT void Init_", feature, "(void) {\n", "size_t i;\n", "\n", NIL); Printv(f_init, tab4, "SWIG_InitRuntime();\n", NIL); if (!useGlobalModule) defineRubyModule(); - Printv(f_init, - "\n", - "SWIG_InitializeModule(0);\n", - "for (i = 0; i < swig_module.size; i++) {\n", - "SWIG_define_class(swig_module.types[i]);\n", - "}\n", - NIL); - Printf(f_init,"\n"); + Printv(f_init, "\n", "SWIG_InitializeModule(0);\n", "for (i = 0; i < swig_module.size; i++) {\n", "SWIG_define_class(swig_module.types[i]);\n", "}\n", NIL); + Printf(f_init, "\n"); /* Initialize code to keep track of objects */ - Printf(f_init,"SWIG_RubyInitializeTrackings();\n"); - + Printf(f_init, "SWIG_RubyInitializeTrackings();\n"); + Language::top(n); if (directorsEnabled()) { @@ -522,11 +503,11 @@ public: } /* Finish off our init function */ - Printf(f_init,"}\n"); - SwigType_emit_type_table(f_runtime,f_wrappers); + Printf(f_init, "}\n"); + SwigType_emit_type_table(f_runtime, f_wrappers); /* Close all of the files */ - Dump(f_header,f_runtime); + Dump(f_header, f_runtime); if (directorsEnabled()) { Dump(f_directors_helpers, f_runtime); @@ -537,9 +518,9 @@ public: Close(f_runtime_h); } - Dump(f_wrappers,f_runtime); + Dump(f_wrappers, f_runtime); Dump(f_initbeforefunc, f_runtime); - Wrapper_pretty_print(f_init,f_runtime); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); @@ -554,31 +535,31 @@ public: /* ----------------------------------------------------------------------------- * importDirective() * ----------------------------------------------------------------------------- */ - + virtual int importDirective(Node *n) { - String *modname = Getattr(n,"module"); + String *modname = Getattr(n, "module"); if (modname) { if (prefix) { - Insert(modname, 0, prefix); + Insert(modname, 0, prefix); } - - List *modules = Split(modname,':',INT_MAX); + + List *modules = Split(modname, ':', INT_MAX); if (modules && Len(modules) > 0) { - modname = NewString(""); - String *last = NULL; - Iterator m = First(modules); - while (m.item) { - if (Len(m.item) > 0) { - if (last) { - Append(modname, "/"); - } - Append(modname, m.item); - last = m.item; - } - m = Next(m); - } - Printf(f_init,"rb_require(\"%s\");\n", modname); - Delete(modname); + modname = NewString(""); + String *last = NULL; + Iterator m = First(modules); + while (m.item) { + if (Len(m.item) > 0) { + if (last) { + Append(modname, "/"); + } + Append(modname, m.item); + last = m.item; + } + m = Next(m); + } + Printf(f_init, "rb_require(\"%s\");\n", modname); + Delete(modname); } Delete(modules); } @@ -599,13 +580,13 @@ public: module = NewString(""); if (prefix) { - Insert(mod_name, 0, prefix); + Insert(mod_name, 0, prefix); } - + /* Account for nested modules */ - List *modules = Split(mod_name,':',INT_MAX); + List *modules = Split(mod_name, ':', INT_MAX); if (modules != 0 && Len(modules) > 0) { - String *last = 0; + String *last = 0; Iterator m = First(modules); while (m.item) { if (Len(m.item) > 0) { @@ -629,14 +610,13 @@ public: } Delete(mod_name); } - + /* -------------------------------------------------------------------------- * nativeWrapper() * -------------------------------------------------------------------------- */ virtual int nativeWrapper(Node *n) { - String *funcname = Getattr(n,"wrap:name"); - Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, - "Adding native function %s not supported (ignored).\n", funcname); + String *funcname = Getattr(n, "wrap:name"); + Swig_warning(WARN_LANG_NATIVE_UNIMPL, input_file, line_number, "Adding native function %s not supported (ignored).\n", funcname); return SWIG_NOWRAP; } @@ -644,14 +624,14 @@ public: * Process the comma-separated list of aliases (if any). */ void defineAliases(Node *n, const String_or_char *iname) { - String *aliasv = Getattr(n,"feature:alias"); + String *aliasv = Getattr(n, "feature:alias"); if (aliasv) { - List *aliases = Split(aliasv,',',INT_MAX); + List *aliases = Split(aliasv, ',', INT_MAX); if (aliases && Len(aliases) > 0) { Iterator alias = First(aliases); while (alias.item) { - if (Len(alias.item) > 0) { - Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); + if (Len(alias.item) > 0) { + Printv(klass->init, tab4, "rb_define_alias(", klass->vname, ", \"", alias.item, "\", \"", iname, "\");\n", NIL); } alias = Next(alias); } @@ -659,7 +639,7 @@ public: Delete(aliases); } } - + /* --------------------------------------------------------------------- * create_command(Node *n, char *iname) * @@ -682,88 +662,79 @@ public: String *alloc_func = Swig_name_wrapper(iname); String *wname = Swig_name_wrapper(iname); if (CPlusPlus) { - Insert(wname,0,"VALUEFUNC("); - Append(wname,")"); + Insert(wname, 0, "VALUEFUNC("); + Append(wname, ")"); } if (current != NO_CPP) iname = klass->strip(iname); if (Getattr(special_methods, iname)) { iname = GetChar(special_methods, iname); } - + String *s = NewString(""); String *temp = NewString(""); - + #ifdef SWIG_PROTECTED_TARGET_METHODS - const char* rb_define_method = is_public(n) ? - "rb_define_method" : "rb_define_protected_method" ; -#else - const char* rb_define_method = "rb_define_method"; -#endif + const char *rb_define_method = is_public(n) ? "rb_define_method" : "rb_define_protected_method"; +#else + const char *rb_define_method = "rb_define_method"; +#endif switch (current) { - case MEMBER_FUNC: + case MEMBER_FUNC: { if (multipleInheritance) { - Printv(klass->init, tab4, rb_define_method,"(", klass->mImpl, ", \"", - iname, "\", ", wname, ", -1);\n", NIL); + Printv(klass->init, tab4, rb_define_method, "(", klass->mImpl, ", \"", iname, "\", ", wname, ", -1);\n", NIL); } else { - Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"", - iname, "\", ", wname, ", -1);\n", NIL); + Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"", iname, "\", ", wname, ", -1);\n", NIL); } - } + } break; case CONSTRUCTOR_ALLOCATE: Printv(s, tab4, "rb_define_alloc_func(", klass->vname, ", ", alloc_func, ");\n", NIL); - Replaceall(klass->init,"$allocator", s); + Replaceall(klass->init, "$allocator", s); break; case CONSTRUCTOR_INITIALIZE: - Printv(s, tab4, rb_define_method,"(", klass->vname, - ", \"initialize\", ", wname, ", -1);\n", NIL); - Replaceall(klass->init,"$initializer", s); + Printv(s, tab4, rb_define_method, "(", klass->vname, ", \"initialize\", ", wname, ", -1);\n", NIL); + Replaceall(klass->init, "$initializer", s); break; case MEMBER_VAR: - Append(temp,iname); + Append(temp, iname); /* Check for _set or _get at the end of the name. */ if (Len(temp) > 4) { - const char *p = Char(temp) + (Len(temp) - 4); - if (strcmp(p, "_set") == 0) { - Delslice(temp, Len(temp) - 4, DOH_END); - Append(temp, "="); - } else if (strcmp(p, "_get") == 0) { - Delslice(temp, Len(temp) - 4, DOH_END); - } + const char *p = Char(temp) + (Len(temp) - 4); + if (strcmp(p, "_set") == 0) { + Delslice(temp, Len(temp) - 4, DOH_END); + Append(temp, "="); + } else if (strcmp(p, "_get") == 0) { + Delslice(temp, Len(temp) - 4, DOH_END); + } } if (multipleInheritance) { - Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"", - temp, "\", ", wname, ", -1);\n", NIL); + Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"", temp, "\", ", wname, ", -1);\n", NIL); } else { - Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"", - temp, "\", ", wname, ", -1);\n", NIL); + Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"", temp, "\", ", wname, ", -1);\n", NIL); } break; case STATIC_FUNC: - Printv(klass->init, tab4, "rb_define_singleton_method(", klass->vname, - ", \"", iname, "\", ", wname, ", -1);\n", NIL); + Printv(klass->init, tab4, "rb_define_singleton_method(", klass->vname, ", \"", iname, "\", ", wname, ", -1);\n", NIL); break; case NO_CPP: if (!useGlobalModule) { - Printv(s, tab4, "rb_define_module_function(", modvar, ", \"", - iname, "\", ", wname, ", -1);\n",NIL); - Printv(f_init,s,NIL); + Printv(s, tab4, "rb_define_module_function(", modvar, ", \"", iname, "\", ", wname, ", -1);\n", NIL); + Printv(f_init, s, NIL); } else { - Printv(s, tab4, "rb_define_global_function(\"", - iname, "\", ", wname, ", -1);\n",NIL); - Printv(f_init,s,NIL); + Printv(s, tab4, "rb_define_global_function(\"", iname, "\", ", wname, ", -1);\n", NIL); + Printv(f_init, s, NIL); } break; case DESTRUCTOR: case CLASS_CONST: case STATIC_VAR: - assert(false); // Should not have gotten here for these types + assert(false); // Should not have gotten here for these types default: assert(false); } - + defineAliases(n, iname); Delete(temp); @@ -771,7 +742,7 @@ public: Delete(wname); Delete(alloc_func); } - + /* --------------------------------------------------------------------- * applyInputTypemap() * @@ -782,34 +753,32 @@ public: Parm *applyInputTypemap(Parm *p, String *ln, String *source, Wrapper *f, String *symname) { String *tm; - SwigType *pt = Getattr(p,"type"); - if ((tm = Getattr(p,"tmap:in"))) { - Replaceall(tm,"$target",ln); - Replaceall(tm,"$source",source); - Replaceall(tm,"$input",source); - Replaceall(tm,"$symname", symname); + SwigType *pt = Getattr(p, "type"); + if ((tm = Getattr(p, "tmap:in"))) { + Replaceall(tm, "$target", ln); + Replaceall(tm, "$source", source); + Replaceall(tm, "$input", source); + Replaceall(tm, "$symname", symname); - if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); - } - else { - Replaceall(tm,"$disown","0"); + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); + } else { + Replaceall(tm, "$disown", "0"); } - Setattr(p,"emit:input",Copy(source)); - Printf(f->code,"%s\n", tm); - p = Getattr(p,"tmap:in:next"); + Setattr(p, "emit:input", Copy(source)); + Printf(f->code, "%s\n", tm); + p = Getattr(p, "tmap:in:next"); } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n", SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); p = nextSibling(p); } return p; } Parm *skipIgnoredArgs(Parm *p) { - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } return p; } @@ -821,7 +790,7 @@ public: * method and convert them into C/C++ function arguments using the * supplied typemaps. * --------------------------------------------------------------------- */ - + void marshalInputArgs(Node *n, ParmList *l, int numarg, int numreq, String *kwargs, bool allow_kwargs, Wrapper *f) { int i; Parm *p; @@ -845,65 +814,65 @@ public: int varargs = emit_isvarargs(l); - Printf(kwargs,"{ "); + Printf(kwargs, "{ "); for (i = 0, p = l; i < numarg; i++) { p = skipIgnoredArgs(p); - String *pn = Getattr(p,"name"); - String *ln = Getattr(p,"lname"); + String *pn = Getattr(p, "name"); + String *ln = Getattr(p, "lname"); /* Produce string representation of source argument */ Clear(source); /* First argument is a special case */ if (i == 0) { - Printv(source, (start == 0) ? "argv[0]" : "self", NIL); + Printv(source, (start == 0) ? "argv[0]" : "self", NIL); } else { - Printf(source,"argv[%d]",i-start); + Printf(source, "argv[%d]", i - start); } /* Produce string representation of target argument */ Clear(target); - Printf(target,"%s",Char(ln)); + Printf(target, "%s", Char(ln)); - if (i >= (numreq)) { /* Check if parsing an optional argument */ - Printf(f->code," if (argc > %d) {\n", i - start); + if (i >= (numreq)) { /* Check if parsing an optional argument */ + Printf(f->code, " if (argc > %d) {\n", i - start); } - + /* Record argument name for keyword argument handling */ if (Len(pn)) { - Printf(kwargs,"\"%s\",", pn); + Printf(kwargs, "\"%s\",", pn); } else { - Printf(kwargs,"\"arg%d\",", i+1); + Printf(kwargs, "\"arg%d\",", i + 1); } /* Look for an input typemap */ - p = applyInputTypemap(p, ln, source, f, Getattr(n,"name")); + p = applyInputTypemap(p, ln, source, f, Getattr(n, "name")); if (i >= numreq) { - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); } } - + /* Finish argument marshalling */ - Printf(kwargs," NULL }"); + Printf(kwargs, " NULL }"); if (allow_kwargs) { Printv(f->locals, tab4, "char *kwnames[] = ", kwargs, ";\n", NIL); } - + /* Trailing varargs */ if (varargs) { - if (p && (tm = Getattr(p,"tmap:in"))) { - Clear(source); - Printf(source,"argv[%d]",i-start); - Replaceall(tm,"$input",source); - Setattr(p,"emit:input",Copy(source)); - Printf(f->code,"if (argc > %d) {\n", i-start); - Printv(f->code,tm,"\n",NIL); - Printf(f->code,"}\n"); + if (p && (tm = Getattr(p, "tmap:in"))) { + Clear(source); + Printf(source, "argv[%d]", i - start); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", Copy(source)); + Printf(f->code, "if (argc > %d) {\n", i - start); + Printv(f->code, tm, "\n", NIL); + Printf(f->code, "}\n"); } } - + Delete(source); Delete(target); } @@ -915,15 +884,15 @@ public: * typemap and (if it finds one) inserts the typemapping code into * the function wrapper. * --------------------------------------------------------------------- */ - + void insertConstraintCheckingCode(ParmList *l, Wrapper *f) { Parm *p; String *tm; for (p = l; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } @@ -937,17 +906,17 @@ public: * typemap and (if it finds one) inserts the typemapping code into * the function wrapper. * --------------------------------------------------------------------- */ - + void insertCleanupCode(ParmList *l, String *cleanup) { String *tm; - for (Parm *p = l; p; ) { + for (Parm *p = l; p;) { // if (!checkAttribute(p,"tmap:in:numinputs","0") && (tm = Getattr(p,"tmap:freearg"))) { - if ((tm = Getattr(p,"tmap:freearg"))) { + if ((tm = Getattr(p, "tmap:freearg"))) { if (Len(tm) != 0) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); } - p = Getattr(p,"tmap:freearg:next"); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } @@ -961,26 +930,26 @@ public: * typemap and (if it finds one) inserts the typemapping code into * the function wrapper. * --------------------------------------------------------------------- */ - - void insertArgOutputCode(ParmList *l, String *outarg, int& need_result) { + + void insertArgOutputCode(ParmList *l, String *outarg, int &need_result) { String *tm; - for (Parm *p = l; p; ) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Replaceall(tm,"$target","vresult"); - Replaceall(tm,"$result","vresult"); - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - - Printv(outarg,tm,"\n",NIL); + for (Parm *p = l; p;) { + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); + Replaceall(tm, "$target", "vresult"); + Replaceall(tm, "$result", "vresult"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + + Printv(outarg, tm, "\n", NIL); need_result = 1; - p = Getattr(p,"tmap:argout:next"); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } } - + /* --------------------------------------------------------------------- * validIdentifier() * @@ -1002,12 +971,13 @@ public: virtual int validIdentifier(String *s) { char *c = Char(s); while (*c) { - if ( !( isalnum(*c) || (*c == '_') || (*c == '?') || (*c == '!') || (*c == '=') ) ) return 0; + if (!(isalnum(*c) || (*c == '_') || (*c == '?') || (*c == '!') || (*c == '='))) + return 0; c++; } return 1; } - + /* --------------------------------------------------------------------- * functionWrapper() * @@ -1020,38 +990,37 @@ public: bool destructor; String *storage; - String *symname = Copy(Getattr(n,"sym:name")); - SwigType *t = Getattr(n,"type"); - ParmList *l = Getattr(n,"parms"); + String *symname = Copy(Getattr(n, "sym:name")); + SwigType *t = Getattr(n, "type"); + ParmList *l = Getattr(n, "parms"); int director_method = 0; String *tm; - + int need_result = 0; - + /* Ruby needs no destructor wrapper */ if (current == DESTRUCTOR) return SWIG_NOWRAP; nodeType = Getattr(n, "nodeType"); - constructor = (!Cmp(nodeType, "constructor")); - destructor = (!Cmp(nodeType, "destructor")); - storage = Getattr(n, "storage"); + constructor = (!Cmp(nodeType, "constructor")); + destructor = (!Cmp(nodeType, "destructor")); + storage = Getattr(n, "storage"); /* If the C++ class constructor is overloaded, we only want to * write out the "new" singleton method once since it is always * the same. (It's the "initialize" method that will handle the * overloading). */ - if (current == CONSTRUCTOR_ALLOCATE && - Swig_symbol_isoverloaded(n) && - Getattr(n, "sym:nextSibling") != 0) return SWIG_OK; - + if (current == CONSTRUCTOR_ALLOCATE && Swig_symbol_isoverloaded(n) && Getattr(n, "sym:nextSibling") != 0) + return SWIG_OK; + String *overname = 0; if (Getattr(n, "sym:overloaded")) { overname = Getattr(n, "sym:overname"); } else { if (!addSymbol(symname, n)) - return SWIG_ERROR; + return SWIG_ERROR; } String *cleanup = NewString(""); @@ -1072,12 +1041,12 @@ public: /* Determine the name of the SWIG wrapper function */ String *wname = Swig_name_wrapper(symname); if (overname && current != CONSTRUCTOR_ALLOCATE) { - Append(wname,overname); + Append(wname, overname); } - + /* Emit arguments */ if (current != CONSTRUCTOR_ALLOCATE) { - emit_args(t,l,f); + emit_args(t, l, f); } /* Attach standard typemaps */ @@ -1087,16 +1056,16 @@ public: Setattr(n, "wrap:parms", l); /* Get number of arguments */ - int numarg = emit_num_arguments(l); - int numreq = emit_num_required(l); - int varargs = emit_isvarargs(l); - bool allow_kwargs = GetFlag(n,"feature:kwargs") ? true : false; - + int numarg = emit_num_arguments(l); + int numreq = emit_num_required(l); + int varargs = emit_isvarargs(l); + bool allow_kwargs = GetFlag(n, "feature:kwargs") ? true : false; + bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n)); int start = (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) ? 1 : 0; /* Now write the wrapper function itself */ - if (current == CONSTRUCTOR_ALLOCATE) { + if (current == CONSTRUCTOR_ALLOCATE) { Printf(f->def, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n"); Printv(f->def, "SWIGINTERN VALUE\n", wname, "(VALUE self) {", NIL); Printf(f->def, "#else\n"); @@ -1105,19 +1074,19 @@ public: } else if (current == CONSTRUCTOR_INITIALIZE) { Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL); if (!varargs) { - Printf(f->code,"if ((argc < %d) || (argc > %d)) ", numreq-start, numarg-start); + Printf(f->code, "if ((argc < %d) || (argc > %d)) ", numreq - start, numarg - start); } else { - Printf(f->code,"if (argc < %d) ", numreq-start); + Printf(f->code, "if (argc < %d) ", numreq - start); } - Printf(f->code,"{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n",numreq-start); + Printf(f->code, "{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n", numreq - start); } else { Printv(f->def, "SWIGINTERN VALUE\n", wname, "(int argc, VALUE *argv, VALUE self) {", NIL); if (!varargs) { - Printf(f->code,"if ((argc < %d) || (argc > %d)) ", numreq-start, numarg-start); + Printf(f->code, "if ((argc < %d) || (argc > %d)) ", numreq - start, numarg - start); } else { - Printf(f->code,"if (argc < %d) ", numreq-start); + Printf(f->code, "if (argc < %d) ", numreq - start); } - Printf(f->code,"{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n",numreq-start); + Printf(f->code, "{rb_raise(rb_eArgError, \"wrong # of arguments(%%d for %d)\",argc); SWIG_fail;}\n", numreq - start); } /* Now walk the function parameter list and generate code */ @@ -1125,7 +1094,6 @@ public: if (current != CONSTRUCTOR_ALLOCATE) { marshalInputArgs(n, l, numarg, numreq, kwargs, allow_kwargs, f); } - // FIXME? if (ctor_director) { numarg--; @@ -1134,7 +1102,7 @@ public: /* Insert constraint checking code */ insertConstraintCheckingCode(l, f); - + /* Insert cleanup code */ insertCleanupCode(l, cleanup); @@ -1173,16 +1141,16 @@ public: if (current != CONSTRUCTOR_ALLOCATE) { if (current == CONSTRUCTOR_INITIALIZE) { Node *pn = Swig_methodclass(n); - String *symname = Getattr(pn,"sym:name"); - String *action = Getattr(n,"wrap:action"); + String *symname = Getattr(pn, "sym:name"); + String *action = Getattr(n, "wrap:action"); if (directorsEnabled()) { String *classname = NewStringf("const char *classname SWIGUNUSED = \"%s::%s\"", module, symname); Wrapper_add_local(f, "classname", classname); } if (action) { - Append(action,"DATA_PTR(self) = result;\n"); - if (GetFlag(pn,"feature:trackobjects")) { - Append(action,"SWIG_RubyAddTracking(result, self);\n"); + Append(action, "DATA_PTR(self) = result;\n"); + if (GetFlag(pn, "feature:trackobjects")) { + Append(action, "SWIG_RubyAddTracking(result, self);\n"); } } } @@ -1191,9 +1159,9 @@ public: if (director_method) { Printf(f->code, "try {\n"); } - - emit_action(n,f); - + + emit_action(n, f); + if (director_method) { Printf(f->code, "} catch (Swig::DirectorException& e) {\n"); Printf(f->code, " rb_exc_raise(e.getError());\n"); @@ -1208,59 +1176,59 @@ public: if (GetFlag(n, "feature:predicate")) { Printv(f->code, tab4, "vresult = (result ? Qtrue : Qfalse);\n", NIL); } else { - tm = Swig_typemap_lookup_new("out",n,"result",0); + tm = Swig_typemap_lookup_new("out", n, "result", 0); if (tm) { - Replaceall(tm,"$result","vresult"); - Replaceall(tm,"$source","result"); - Replaceall(tm,"$target","vresult"); + Replaceall(tm, "$result", "vresult"); + Replaceall(tm, "$source", "result"); + Replaceall(tm, "$target", "vresult"); - if (GetFlag(n, "feature:new")) - Replaceall(tm,"$owner", "SWIG_POINTER_OWN"); - else - Replaceall(tm,"$owner", "0"); + if (GetFlag(n, "feature:new")) + Replaceall(tm, "$owner", "SWIG_POINTER_OWN"); + else + Replaceall(tm, "$owner", "0"); -#if 1 - // FIXME: this will not try to unwrap directors returned as non-director - // base class pointers! - - /* New addition to unwrap director return values so that the original - * Ruby object is returned instead. - */ - bool unwrap = false; - String *decl = Getattr(n, "decl"); - int is_pointer = SwigType_ispointer_return(decl); - int is_reference = SwigType_isreference_return(decl); - if (is_pointer || is_reference) { - String *type = Getattr(n, "type"); +#if 1 + // FIXME: this will not try to unwrap directors returned as non-director + // base class pointers! + + /* New addition to unwrap director return values so that the original + * Ruby object is returned instead. + */ + bool unwrap = false; + String *decl = Getattr(n, "decl"); + int is_pointer = SwigType_ispointer_return(decl); + int is_reference = SwigType_isreference_return(decl); + if (is_pointer || is_reference) { + String *type = Getattr(n, "type"); Node *parent = Swig_methodclass(n); - Node *modname = Getattr(parent, "module"); - Node *target = Swig_directormap(modname, type); - if (target) unwrap = true; - } - if (unwrap) { - Wrapper_add_local(f, "director", "Swig::Director *director = 0"); - Printf(f->code, "director = dynamic_cast(result);\n"); - Printf(f->code, "if (director) {\n"); - Printf(f->code, " vresult = director->swig_get_self();\n"); - Printf(f->code, "} else {\n"); - Printf(f->code,"%s\n", tm); - Printf(f->code, "}\n"); + Node *modname = Getattr(parent, "module"); + Node *target = Swig_directormap(modname, type); + if (target) + unwrap = true; + } + if (unwrap) { + Wrapper_add_local(f, "director", "Swig::Director *director = 0"); + Printf(f->code, "director = dynamic_cast(result);\n"); + Printf(f->code, "if (director) {\n"); + Printf(f->code, " vresult = director->swig_get_self();\n"); + Printf(f->code, "} else {\n"); + Printf(f->code, "%s\n", tm); + Printf(f->code, "}\n"); director_method = 0; - } else { - Printf(f->code,"%s\n", tm); - } + } else { + Printf(f->code, "%s\n", tm); + } #else - Printf(f->code,"%s\n", tm); + Printf(f->code, "%s\n", tm); #endif Delete(tm); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s.\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s.\n", SwigType_str(t, 0)); } } } - /* Extra code needed for new and initialize methods */ + /* Extra code needed for new and initialize methods */ if (current == CONSTRUCTOR_ALLOCATE) { need_result = 1; Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(t))); @@ -1273,38 +1241,38 @@ public: } /* Dump argument output code; */ - Printv(f->code,outarg,NIL); + Printv(f->code, outarg, NIL); /* Dump the argument cleanup code */ int need_cleanup = (current != CONSTRUCTOR_ALLOCATE) && (Len(cleanup) != 0); if (need_cleanup) { - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); } - + /* Look for any remaining cleanup. This processes the %new directive */ if (current != CONSTRUCTOR_ALLOCATE && GetFlag(n, "feature:new")) { - tm = Swig_typemap_lookup_new("newfree",n,"result",0); + tm = Swig_typemap_lookup_new("newfree", n, "result", 0); if (tm) { - Replaceall(tm,"$source","result"); - Printv(f->code,tm, "\n",NIL); + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, "\n", NIL); Delete(tm); } } /* Special processing on return value. */ - tm = Swig_typemap_lookup_new("ret",n,"result",0); + tm = Swig_typemap_lookup_new("ret", n, "result", 0); if (tm) { - Replaceall(tm,"$source","result"); - Printv(f->code,tm, NIL); + Replaceall(tm, "$source", "result"); + Printv(f->code, tm, NIL); Delete(tm); } if (director_method) { - if ((tm = Swig_typemap_lookup_new("directorfree",n,"result",0))) { - Replaceall(tm,"$input","result"); - Replaceall(tm,"$result","vresult"); - Printf(f->code,"%s\n",tm); + if ((tm = Swig_typemap_lookup_new("directorfree", n, "result", 0))) { + Replaceall(tm, "$input", "result"); + Replaceall(tm, "$result", "vresult"); + Printf(f->code, "%s\n", tm); } } @@ -1315,36 +1283,36 @@ public: Printv(f->code, tab4, "return vresult;\n", NIL); } else if (current == CONSTRUCTOR_INITIALIZE) { Printv(f->code, tab4, "return self;\n", NIL); - Printv(f->code,"fail:\n",NIL); + Printv(f->code, "fail:\n", NIL); if (need_cleanup) { - Printv(f->code,cleanup,NIL); - } + Printv(f->code, cleanup, NIL); + } Printv(f->code, tab4, "return Qnil;\n", NIL); } else { - Wrapper_add_local(f,"vresult","VALUE vresult = Qnil"); + Wrapper_add_local(f, "vresult", "VALUE vresult = Qnil"); Printv(f->code, tab4, "return vresult;\n", NIL); - Printv(f->code,"fail:\n",NIL); + Printv(f->code, "fail:\n", NIL); if (need_cleanup) { - Printv(f->code,cleanup,NIL); - } + Printv(f->code, cleanup, NIL); + } Printv(f->code, tab4, "return Qnil;\n", NIL); } } else { Printv(f->code, tab4, "return Qnil;\n", NIL); - Printv(f->code,"fail:\n",NIL); + Printv(f->code, "fail:\n", NIL); if (need_cleanup) { - Printv(f->code,cleanup,NIL); + Printv(f->code, cleanup, NIL); } Printv(f->code, tab4, "return Qnil;\n", NIL); } - Printf(f->code,"}\n"); + Printf(f->code, "}\n"); /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); + Replaceall(f->code, "$cleanup", cleanup); /* Substitute the function name */ - Replaceall(f->code,"$symname",symname); + Replaceall(f->code, "$symname", symname); /* Emit the function */ Wrapper_print(f, f_wrappers); @@ -1354,49 +1322,46 @@ public: create_command(n, symname); } else { if (current == CONSTRUCTOR_ALLOCATE) { - create_command(n, symname); + create_command(n, symname); } else { Setattr(n, "wrap:name", wname); if (!Getattr(n, "sym:nextSibling")) - dispatchFunction(n); + dispatchFunction(n); } } - + Delete(kwargs); Delete(cleanup); Delete(outarg); DelWrapper(f); Delete(symname); - + return SWIG_OK; } /* ------------------------------------------------------------ * dispatchFunction() * ------------------------------------------------------------ */ - + void dispatchFunction(Node *n) { /* Last node in overloaded chain */ int maxargs; String *tmp = NewString(""); String *dispatch = Swig_overload_dispatch(n, "return %s(nargs, args, self);", &maxargs); - + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *f = NewWrapper(); - String *symname = Getattr(n, "sym:name"); - String *wname = Swig_name_wrapper(symname); + Wrapper *f = NewWrapper(); + String *symname = Getattr(n, "sym:name"); + String *wname = Swig_name_wrapper(symname); + + Printv(f->def, "SWIGINTERN VALUE ", wname, "(int nargs, VALUE *args, VALUE self) {", NIL); - Printv(f->def, - "SWIGINTERN VALUE ", wname, - "(int nargs, VALUE *args, VALUE self) {", - NIL); - Wrapper_add_local(f, "argc", "int argc"); bool ctor_director = (current == CONSTRUCTOR_INITIALIZE && Swig_directorclass(n)); if (current == MEMBER_FUNC || current == MEMBER_VAR || ctor_director) { - Printf(tmp, "VALUE argv[%d]", maxargs+1); + Printf(tmp, "VALUE argv[%d]", maxargs + 1); } else { Printf(tmp, "VALUE argv[%d]", maxargs); } @@ -1417,12 +1382,12 @@ public: Printf(f->code, "argv[ii] = args[ii];\n"); Printf(f->code, "}\n"); } - + Replaceall(dispatch, "$args", "nargs, args, self"); Printv(f->code, dispatch, "\n", NIL); - Printf(f->code,"fail:\n"); + Printf(f->code, "fail:\n"); Printf(f->code, "rb_raise(rb_eArgError, \"No matching function for overloaded '%s'\");\n", symname); - Printf(f->code,"return Qnil;\n"); + Printf(f->code, "return Qnil;\n"); Printv(f->code, "}\n", NIL); Wrapper_print(f, f_wrappers); create_command(n, Char(symname)); @@ -1432,16 +1397,16 @@ public: Delete(tmp); Delete(wname); } - + /* --------------------------------------------------------------------- * variableWrapper() * --------------------------------------------------------------------- */ virtual int variableWrapper(Node *n) { - char *name = GetChar(n,"name"); - char *iname = GetChar(n,"sym:name"); - SwigType *t = Getattr(n,"type"); + char *name = GetChar(n, "name"); + char *iname = GetChar(n, "sym:name"); + SwigType *t = Getattr(n, "type"); String *tm; String *getfname, *setfname; Wrapper *getf, *setf; @@ -1455,27 +1420,26 @@ public: Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL); Printf(getf->def, "VALUE self"); Printf(getf->def, ") {"); - Wrapper_add_local(getf,"_val","VALUE _val"); + Wrapper_add_local(getf, "_val", "VALUE _val"); - tm = Swig_typemap_lookup_new("varout",n, name, 0); + tm = Swig_typemap_lookup_new("varout", n, name, 0); if (tm) { - Replaceall(tm,"$result","_val"); - Replaceall(tm,"$target","_val"); - Replaceall(tm,"$source",name); + Replaceall(tm, "$result", "_val"); + Replaceall(tm, "$target", "_val"); + Replaceall(tm, "$source", name); /* Printv(getf->code,tm, NIL); */ addfail = emit_action_code(n, getf, tm); } else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); } Printv(getf->code, tab4, "return _val;\n", NIL); if (addfail) { - Append(getf->code,"fail:\n"); - Append(getf->code," return Qnil;\n"); + Append(getf->code, "fail:\n"); + Append(getf->code, " return Qnil;\n"); } - Append(getf->code,"}\n"); + Append(getf->code, "}\n"); - Wrapper_print(getf,f_wrappers); + Wrapper_print(getf, f_wrappers); if (!is_assignable(n)) { setfname = NewString("NULL"); @@ -1483,77 +1447,58 @@ public: /* create setter */ setfname = Swig_name_set(iname); Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL); - Printf(setf->def, "VALUE _val) {"); - tm = Swig_typemap_lookup_new("varin",n,name,0); + Printf(setf->def, "VALUE _val) {"); + tm = Swig_typemap_lookup_new("varin", n, name, 0); if (tm) { - Replaceall(tm,"$input","_val"); - Replaceall(tm,"$source","_val"); - Replaceall(tm,"$target",name); + Replaceall(tm, "$input", "_val"); + Replaceall(tm, "$source", "_val"); + Replaceall(tm, "$target", name); /* Printv(setf->code,tm,"\n",NIL); */ emit_action_code(n, setf, tm); } else { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, - "Unable to set variable of type %s\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s\n", SwigType_str(t, 0)); } Printv(setf->code, tab4, "return _val;\n", NIL); Printf(setf->code, "fail:\n"); Printv(setf->code, tab4, "return Qnil;\n", NIL); - Printf(setf->code,"}\n"); - Wrapper_print(setf,f_wrappers); + Printf(setf->code, "}\n"); + Wrapper_print(setf, f_wrappers); } /* define accessor method */ if (CPlusPlus) { - Insert(getfname,0,"VALUEFUNC("); - Append(getfname,")"); - Insert(setfname,0,"VALUEFUNC("); - Append(setfname,")"); + Insert(getfname, 0, "VALUEFUNC("); + Append(getfname, ")"); + Insert(setfname, 0, "VALUEFUNC("); + Append(setfname, ")"); } String *s = NewString(""); switch (current) { case STATIC_VAR: /* C++ class variable */ - Printv(s, - tab4, "rb_define_singleton_method(", klass->vname, ", \"", - klass->strip(iname), "\", ", getfname, ", 0);\n", - NIL); - if (!GetFlag(n,"feature:immutable")) { - Printv(s, - tab4, "rb_define_singleton_method(", klass->vname, ", \"", - klass->strip(iname), "=\", ", setfname, ", 1);\n", - NIL); + Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "\", ", getfname, ", 0);\n", NIL); + if (!GetFlag(n, "feature:immutable")) { + Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "=\", ", setfname, ", 1);\n", NIL); } - Printv(klass->init,s,NIL); + Printv(klass->init, s, NIL); break; default: /* C global variable */ /* wrapped in Ruby module attribute */ assert(current == NO_CPP); if (!useGlobalModule) { - Printv(s, - tab4, "rb_define_singleton_method(", modvar, ", \"", - iname, "\", ", getfname, ", 0);\n", - NIL); - if (!GetFlag(n,"feature:immutable")) { - Printv(s, - tab4, "rb_define_singleton_method(", modvar, ", \"", - iname, "=\", ", setfname, ", 1);\n", - NIL); - } + Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "\", ", getfname, ", 0);\n", NIL); + if (!GetFlag(n, "feature:immutable")) { + Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "=\", ", setfname, ", 1);\n", NIL); + } } else { - Printv(s, - tab4, "rb_define_global_method(\"", - iname, "\", ", getfname, ", 0);\n", - NIL); - if (!GetFlag(n,"feature:immutable")) { - Printv(s, - tab4, "rb_define_global_method(\"", - iname, "=\", ", setfname, ", 1);\n", - NIL); - } + Printv(s, tab4, "rb_define_global_method(\"", iname, "\", ", getfname, ", 0);\n", NIL); + if (!GetFlag(n, "feature:immutable")) { + Printv(s, tab4, "rb_define_global_method(\"", iname, "=\", ", setfname, ", 1);\n", NIL); + } } - Printv(f_init,s,NIL); + Printv(f_init, s, NIL); Delete(s); break; } @@ -1571,45 +1516,42 @@ public: * Validate constant name. * --------------------------------------------------------------------- */ - char * - validate_const_name(char *name, const char *reason) { + char *validate_const_name(char *name, const char *reason) { if (!name || name[0] == '\0') return name; - + if (isupper(name[0])) return name; - + if (islower(name[0])) { name[0] = toupper(name[0]); - Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number, - "Wrong %s name (corrected to `%s')\n", reason, name); + Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number, "Wrong %s name (corrected to `%s')\n", reason, name); return name; } - - Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number, - "Wrong %s name %s\n", reason, name); - + + Swig_warning(WARN_RUBY_WRONG_NAME, input_file, line_number, "Wrong %s name %s\n", reason, name); + return name; } - + /* --------------------------------------------------------------------- * constantWrapper() * --------------------------------------------------------------------- */ virtual int constantWrapper(Node *n) { - Swig_require("constantWrapper",n, "*sym:name", "type", "value", NIL); - - char *iname = GetChar(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); - + Swig_require("constantWrapper", n, "*sym:name", "type", "value", NIL); + + char *iname = GetChar(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); + if (current == CLASS_CONST) { iname = klass->strip(iname); } validate_const_name(iname, "constant"); SetChar(n, "sym:name", iname); - + /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(iname); @@ -1617,36 +1559,36 @@ public: value = Char(wname); } String *tm = Swig_typemap_lookup_new("constant", n, value, 0); - if (!tm) tm = Swig_typemap_lookup_new("constcode", n, value, 0); + if (!tm) + tm = Swig_typemap_lookup_new("constcode", n, value, 0); if (tm) { Replaceall(tm, "$source", value); Replaceall(tm, "$target", iname); Replaceall(tm, "$symname", iname); Replaceall(tm, "$value", value); if (current == CLASS_CONST) { - if (multipleInheritance) { - Replaceall(tm, "$module", klass->mImpl); - Printv(klass->init, tm, "\n", NIL); - } else { - Replaceall(tm, "$module", klass->vname); - Printv(klass->init, tm, "\n", NIL); - } + if (multipleInheritance) { + Replaceall(tm, "$module", klass->mImpl); + Printv(klass->init, tm, "\n", NIL); + } else { + Replaceall(tm, "$module", klass->vname); + Printv(klass->init, tm, "\n", NIL); + } } else { - if (!useGlobalModule) { - Replaceall(tm, "$module", modvar); - } else { - Replaceall(tm, "$module", "rb_cObject"); - } + if (!useGlobalModule) { + Replaceall(tm, "$module", modvar); + } else { + Replaceall(tm, "$module", "rb_cObject"); + } Printf(f_init, "%s\n", tm); } } else { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, - "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value %s = %s\n", SwigType_str(type, 0), value); } Swig_restore(n); return SWIG_OK; } - + /* ----------------------------------------------------------------------------- * classDeclaration() * @@ -1655,11 +1597,11 @@ public: * ----------------------------------------------------------------------------- */ virtual int classDeclaration(Node *n) { - if (!Getattr(n,"feature:onlychildren")) { - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - String *tdname = Getattr(n,"tdname"); - + if (!Getattr(n, "feature:onlychildren")) { + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + String *tdname = Getattr(n, "tdname"); + name = tdname ? tdname : name; String *namestr = SwigType_namestr(name); klass = RCLASS(classes, Char(namestr)); @@ -1672,7 +1614,7 @@ public: Delete(valid_name); } Delete(namestr); - } + } return Language::classDeclaration(n); } @@ -1680,14 +1622,14 @@ public: * Process the comma-separated list of mixed-in module names (if any). */ void includeRubyModules(Node *n) { - String *mixin = Getattr(n,"feature:mixin"); + String *mixin = Getattr(n, "feature:mixin"); if (mixin) { - List *modules = Split(mixin,',',INT_MAX); + List *modules = Split(mixin, ',', INT_MAX); if (modules && Len(modules) > 0) { Iterator mod = First(modules); while (mod.item) { - if (Len(mod.item) > 0) { - Printf(klass->init, "rb_include_module(%s, rb_eval_string(\"%s\"));\n", klass->vname, mod.item); + if (Len(mod.item) > 0) { + Printf(klass->init, "rb_include_module(%s, rb_eval_string(\"%s\"));\n", klass->vname, mod.item); } mod = Next(mod); } @@ -1697,54 +1639,54 @@ public: } void handleBaseClasses(Node *n) { - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator base = First(baselist); - while(base.item && GetFlag(base.item,"feature:ignore")) { + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } while (base.item) { - String *basename = Getattr(base.item,"name"); - String *basenamestr = SwigType_namestr(basename); - RClass *super = RCLASS(classes, Char(basenamestr)); - Delete(basenamestr); - if (super) { - SwigType *btype = NewString(basename); - SwigType_add_pointer(btype); - SwigType_remember(btype); - if (multipleInheritance) { - String *bmangle = SwigType_manglestr(btype); - Insert(bmangle,0,"((swig_class *) SWIGTYPE"); - Append(bmangle,"->clientdata)->mImpl"); - Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL); - Delete(bmangle); - } else { - String *bmangle = SwigType_manglestr(btype); - Insert(bmangle,0,"((swig_class *) SWIGTYPE"); - Append(bmangle,"->clientdata)->klass"); - Replaceall(klass->init,"$super",bmangle); - Delete(bmangle); - } - Delete(btype); - } - base = Next(base); - while(base.item && GetFlag(base.item,"feature:ignore")) { + String *basename = Getattr(base.item, "name"); + String *basenamestr = SwigType_namestr(basename); + RClass *super = RCLASS(classes, Char(basenamestr)); + Delete(basenamestr); + if (super) { + SwigType *btype = NewString(basename); + SwigType_add_pointer(btype); + SwigType_remember(btype); + if (multipleInheritance) { + String *bmangle = SwigType_manglestr(btype); + Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); + Append(bmangle, "->clientdata)->mImpl"); + Printv(klass->init, "rb_include_module(", klass->mImpl, ", ", bmangle, ");\n", NIL); + Delete(bmangle); + } else { + String *bmangle = SwigType_manglestr(btype); + Insert(bmangle, 0, "((swig_class *) SWIGTYPE"); + Append(bmangle, "->clientdata)->klass"); + Replaceall(klass->init, "$super", bmangle); + Delete(bmangle); + } + Delete(btype); + } + base = Next(base); + while (base.item && GetFlag(base.item, "feature:ignore")) { base = Next(base); } - if (!multipleInheritance) { - /* Warn about multiple inheritance for additional base class(es) */ - while (base.item) { - if (GetFlag(base.item,"feature:ignore")) { + if (!multipleInheritance) { + /* Warn about multiple inheritance for additional base class(es) */ + while (base.item) { + if (GetFlag(base.item, "feature:ignore")) { base = Next(base); continue; } - String *proxyclassname = SwigType_str(Getattr(n,"classtypeobj"),0); - String *baseclassname = SwigType_str(Getattr(base.item,"name"),0); - Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, input_file, line_number, - "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname); - base = Next(base); - } - } + String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0); + String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0); + Swig_warning(WARN_RUBY_MULTIPLE_INHERITANCE, input_file, line_number, + "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Ruby.\n", proxyclassname, baseclassname); + base = Next(base); + } + } } } } @@ -1774,7 +1716,7 @@ public: } } } - + /** * Check to see if tracking is enabled for this class. */ @@ -1787,15 +1729,15 @@ public: } } - /* ---------------------------------------------------------------------- + /* ---------------------------------------------------------------------- * classHandler() * ---------------------------------------------------------------------- */ virtual int classHandler(Node *n) { - String *name = Getattr(n,"name"); - String *symname = Getattr(n,"sym:name"); - String *namestr = SwigType_namestr(name); // does template expansion + String *name = Getattr(n, "name"); + String *symname = Getattr(n, "sym:name"); + String *namestr = SwigType_namestr(name); // does template expansion klass = RCLASS(classes, Char(namestr)); assert(klass != 0); @@ -1804,25 +1746,21 @@ public: validate_const_name(Char(valid_name), "class"); Clear(klass->type); - Printv(klass->type, Getattr(n,"classtype"), NIL); + Printv(klass->type, Getattr(n, "classtype"), NIL); Printv(f_wrappers, "swig_class c", valid_name, ";\n\n", NIL); Printv(klass->init, "\n", tab4, NIL); if (multipleInheritance) { if (!useGlobalModule) { - Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, - ", \"", klass->name, "\", rb_cObject);\n", NIL); + Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", rb_cObject);\n", NIL); } else { - Printv(klass->init, klass->vname, " = rb_define_class(\"", - klass->name, "\", rb_cObject);\n", NIL); + Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", rb_cObject);\n", NIL); } Printv(klass->init, klass->mImpl, " = rb_define_module_under(", klass->vname, ", \"Impl\");\n", NIL); } else { if (!useGlobalModule) { - Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, - ", \"", klass->name, "\", $super);\n", NIL); + Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", $super);\n", NIL); } else { - Printv(klass->init, klass->vname, " = rb_define_class(\"", - klass->name, "\", $super);\n", NIL); + Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", $super);\n", NIL); } } @@ -1834,11 +1772,11 @@ public: Delete(tm); Delete(tt); Delete(valid_name); - + includeRubyModules(n); - Printv(klass->init, "$allocator",NIL); - Printv(klass->init, "$initializer",NIL); + Printv(klass->init, "$allocator", NIL); + Printv(klass->init, "$initializer", NIL); Language::classHandler(n); @@ -1846,25 +1784,24 @@ public: handleMarkFuncDirective(n); handleFreeFuncDirective(n); handleTrackDirective(n); - + if (multipleInheritance) { Printv(klass->init, "rb_include_module(", klass->vname, ", ", klass->mImpl, ");\n", NIL); } String *s = NewString(""); Printv(s, tab4, "rb_undef_alloc_func(", klass->vname, ");\n", NIL); - Replaceall(klass->init,"$allocator", s); - Replaceall(klass->init,"$initializer", ""); + Replaceall(klass->init, "$allocator", s); + Replaceall(klass->init, "$initializer", ""); - if (GetFlag(n,"feature:exceptionclass")) { - Replaceall(klass->init,"$super", "rb_eRuntimeError"); + if (GetFlag(n, "feature:exceptionclass")) { + Replaceall(klass->init, "$super", "rb_eRuntimeError"); + } else { + Replaceall(klass->init, "$super", "rb_cObject"); } - else { - Replaceall(klass->init,"$super", "rb_cObject"); - } Delete(s); - Printv(f_init,klass->init,NIL); + Printv(f_init, klass->init, NIL); klass = 0; return SWIG_OK; } @@ -1885,59 +1822,51 @@ public: * classname. * * --------------------------------------------------------------------- */ - + virtual int memberfunctionHandler(Node *n) { current = MEMBER_FUNC; Language::memberfunctionHandler(n); current = NO_CPP; return SWIG_OK; } - + /* --------------------------------------------------------------------- * constructorHandler() * * Method for adding C++ member constructor * -------------------------------------------------------------------- */ - void set_director_ctor_code(Node *n) - { + void set_director_ctor_code(Node *n) { /* director ctor code is specific for each class */ Delete(director_prot_ctor_code); director_prot_ctor_code = NewString(""); Node *pn = Swig_methodclass(n); - String *symname = Getattr(pn,"sym:name"); - String *name = Copy(symname); + String *symname = Getattr(pn, "sym:name"); + String *name = Copy(symname); char *cname = Char(name); - if(cname) cname[0] = toupper(cname[0]); + if (cname) + cname[0] = toupper(cname[0]); Printv(director_prot_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", - "} else {\n", - " rb_raise(rb_eNameError,\"accessing abstract class or protected constructor\"); \n", - " return Qnil;\n", - "}\n", NIL); + "} else {\n", " rb_raise(rb_eNameError,\"accessing abstract class or protected constructor\"); \n", " return Qnil;\n", "}\n", NIL); Delete(director_ctor_code); director_ctor_code = NewString(""); - Printv(director_ctor_code, - "if ( $comparison ) { /* subclassed */\n", - " $director_new \n", - "} else {\n", - " $nondirector_new \n", - "}\n", NIL); + Printv(director_ctor_code, "if ( $comparison ) { /* subclassed */\n", " $director_new \n", "} else {\n", " $nondirector_new \n", "}\n", NIL); Delete(name); } virtual int constructorHandler(Node *n) { - int use_director = Swig_directorclass(n); + int use_director = Swig_directorclass(n); if (use_director) { set_director_ctor_code(n); } - + /* First wrap the allocate method */ current = CONSTRUCTOR_ALLOCATE; Swig_name_register((String_or_char *) "construct", (String_or_char *) "%c_allocate"); - - + + Language::constructorHandler(n); /* @@ -1945,7 +1874,7 @@ public: * to receive the scripting language object (e.g. 'self') * */ - Swig_save("ruby:constructorHandler",n,"parms",NIL); + Swig_save("ruby:constructorHandler", n, "parms", NIL); if (use_director) { Parm *parms = Getattr(n, "parms"); Parm *self; @@ -1955,7 +1884,8 @@ public: Delete(type); Delete(name); Setattr(self, "lname", "Qnil"); - if (parms) set_nextSibling(self, parms); + if (parms) + set_nextSibling(self, parms); Setattr(n, "parms", self); Setattr(n, "wrap:self", "1"); Delete(self); @@ -1978,7 +1908,7 @@ public: } virtual int copyconstructorHandler(Node *n) { - int use_director = Swig_directorclass(n); + int use_director = Swig_directorclass(n); if (use_director) { set_director_ctor_code(n); } @@ -1986,10 +1916,10 @@ public: /* First wrap the allocate method */ current = CONSTRUCTOR_ALLOCATE; Swig_name_register((String_or_char *) "construct", (String_or_char *) "%c_allocate"); - + return Language::copyconstructorHandler(n); } - + /* --------------------------------------------------------------------- * destructorHandler() @@ -2001,33 +1931,31 @@ public: String *freefunc = NewString(""); String *freebody = NewString(""); - String *pname0 = Swig_cparm_name(0,0); - + String *pname0 = Swig_cparm_name(0, 0); + Printv(freefunc, "free_", klass->mname, NIL); - Printv(freebody, "SWIGINTERN void\n", - freefunc, "(", klass->type, " *", pname0, ") {\n", - tab4, NIL); + Printv(freebody, "SWIGINTERN void\n", freefunc, "(", klass->type, " *", pname0, ") {\n", tab4, NIL); /* Check to see if object tracking is activated for the class that owns this destructor. */ Node *pn = Swig_methodclass(n); - if (GetFlag(pn,"feature:trackobjects")) { + if (GetFlag(pn, "feature:trackobjects")) { Printf(freebody, "SWIG_RubyRemoveTracking(%s);\n", pname0); - Printv(freebody, tab4, NIL); + Printv(freebody, tab4, NIL); } if (Extend) { String *wrap = Getattr(n, "wrap:code"); if (wrap) { - Printv(f_wrappers, wrap, NIL); + Printv(f_wrappers, wrap, NIL); } /* Printv(freebody, Swig_name_destroy(name), "(", pname0, ")", NIL); */ - Printv(freebody,Getattr(n,"wrap:action"), NIL); + Printv(freebody, Getattr(n, "wrap:action"), NIL); } else { - String *action = Getattr(n,"wrap:action"); + String *action = Getattr(n, "wrap:action"); if (action) { Printv(freebody, action, NIL); - } else { + } else { /* In the case swig emits no destroy function. */ if (CPlusPlus) Printf(freebody, "delete %s;\n", pname0); @@ -2035,11 +1963,11 @@ public: Printf(freebody, "free((char*) %s);\n", pname0); } } - + Printv(freebody, "}\n\n", NIL); - + Printv(f_wrappers, freebody, NIL); - + klass->destructor_defined = 1; current = NO_CPP; Delete(freefunc); @@ -2073,7 +2001,7 @@ public: current = NO_CPP; return SWIG_OK; } - + /* ---------------------------------------------------------------------- * memberconstantHandler() * @@ -2086,7 +2014,7 @@ public: current = NO_CPP; return SWIG_OK; } - + /* --------------------------------------------------------------------- * staticmembervariableHandler() * --------------------------------------------------------------------- */ @@ -2102,7 +2030,7 @@ public: virtual int classDirector(Node *n) { return Language::classDirector(n); } - + virtual int classDirectorInit(Node *n) { String *declaration; declaration = Swig_director_declaration(n); @@ -2112,12 +2040,12 @@ public: Delete(declaration); return Language::classDirectorInit(n); } - + virtual int classDirectorEnd(Node *n) { Printf(f_directors_h, "};\n\n"); return Language::classDirectorEnd(n); } - + /* ------------------------------------------------------------ * classDirectorConstructor() * ------------------------------------------------------------ */ @@ -2138,27 +2066,27 @@ public: p = NewParm(type, NewString("self")); set_nextSibling(p, parms); parms = p; - - if (!Getattr(n,"defaultargs")) { + + if (!Getattr(n, "defaultargs")) { /* constructor */ { - Wrapper *w = NewWrapper(); - String *call; - String *basetype = Getattr(parent, "classtype"); - String *target = Swig_method_decl(decl, classname, parms, 0, 0); - call = Swig_csuperclass_call(0, basetype, superparms); - Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call); - Delete(target); - Wrapper_print(w, f_directors); - Delete(call); - DelWrapper(w); + Wrapper *w = NewWrapper(); + String *call; + String *basetype = Getattr(parent, "classtype"); + String *target = Swig_method_decl(decl, classname, parms, 0, 0); + call = Swig_csuperclass_call(0, basetype, superparms); + Printf(w->def, "%s::%s: %s, Swig::Director(self) { }", classname, target, call); + Delete(target); + Wrapper_print(w, f_directors); + Delete(call); + DelWrapper(w); } - + /* constructor header */ { - String *target = Swig_method_decl(decl, classname, parms, 0, 1); - Printf(f_directors_h, " %s;\n", target); - Delete(target); + String *target = Swig_method_decl(decl, classname, parms, 0, 1); + Printf(f_directors_h, " %s;\n", target); + Delete(target); } } @@ -2168,7 +2096,7 @@ public: Delete(parms); return Language::classDirectorConstructor(n); } - + /* ------------------------------------------------------------ * classDirectorDefaultConstructor() * ------------------------------------------------------------ */ @@ -2185,7 +2113,7 @@ public: Delete(classname); return Language::classDirectorDefaultConstructor(n); } - + /* --------------------------------------------------------------- * exceptionSafeMethodCall() * @@ -2210,10 +2138,9 @@ public: tm = Getattr(n, "feature:director:except"); } - if ((tm != 0) && (Len(tm) > 0) && (Strcmp(tm, "1") != 0)) - { + if ((tm != 0) && (Len(tm) > 0) && (Strcmp(tm, "1") != 0)) { // Declare a global to hold the depth count - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { Printf(body->def, "static int %s = 0;\n", depthCountName); // Function body @@ -2225,9 +2152,9 @@ public: Printf(body->code, "%s--;\n", depthCountName, NIL); Printv(body->code, "return result;\n", NIL); Printv(body->code, "}", NIL); - + // Exception handler - Printf(rescue->def, "VALUE %s(VALUE args, VALUE error) {\n", rescueName); + Printf(rescue->def, "VALUE %s(VALUE args, VALUE error) {\n", rescueName); Replaceall(tm, "$error", "error"); Printf(rescue->code, "if (%s == 1) ", depthCountName); Printv(rescue->code, Str(tm), "\n", NIL); @@ -2235,8 +2162,7 @@ public: Printv(rescue->code, "rb_exc_raise(error);\n", NIL); Printv(rescue->code, "}", NIL); } - - + // Main code Wrapper_add_localv(w, "args", "Swig::body_args", "args", NIL); Wrapper_add_localv(w, "status", "int", "status", NIL); @@ -2244,36 +2170,29 @@ public: Printf(w->code, "args.id = rb_intern(\"%s\");\n", methodName); Printf(w->code, "args.argc = %d;\n", argc); if (argc > 0) { - Printf(w->code, "args.argv = new VALUE[%d];\n", argc); - for (int i = 0; i < argc; i++) { - Printf(w->code, "args.argv[%d] = obj%d;\n", i, i); - } + Printf(w->code, "args.argv = new VALUE[%d];\n", argc); + for (int i = 0; i < argc; i++) { + Printf(w->code, "args.argv[%d] = obj%d;\n", i, i); + } } else { - Printv(w->code, "args.argv = 0;\n", NIL); + Printv(w->code, "args.argv = 0;\n", NIL); } - Printf(w->code, - "result = rb_protect(PROTECTFUNC(%s), reinterpret_cast(&args), &status);\n", bodyName, rescueName); - Printf(w->code, - "if (status) {\n"); - Printf(w->code, - "VALUE lastErr = rb_gv_get(\"$!\");\n"); - Printf(w->code, - "%s(reinterpret_cast(&args), lastErr);\n", rescueName); + Printf(w->code, "result = rb_protect(PROTECTFUNC(%s), reinterpret_cast(&args), &status);\n", bodyName, rescueName); + Printf(w->code, "if (status) {\n"); + Printf(w->code, "VALUE lastErr = rb_gv_get(\"$!\");\n"); + Printf(w->code, "%s(reinterpret_cast(&args), lastErr);\n", rescueName); Printf(w->code, "}\n"); if (argc > 0) { - Printv(w->code, "delete [] args.argv;\n", NIL); + Printv(w->code, "delete [] args.argv;\n", NIL); } - // Dump wrapper code Wrapper_print(body, f_directors_helpers); Wrapper_print(rescue, f_directors_helpers); - } - else - { + } else { if (argc > 0) { - Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), %d%s);\n", methodName, argc, args); + Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), %d%s);\n", methodName, argc, args); } else { - Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), 0, NULL);\n", methodName); + Printf(w->code, "result = rb_funcall(swig_get_self(), rb_intern(\"%s\"), 0, NULL);\n", methodName); } } @@ -2284,7 +2203,7 @@ public: DelWrapper(body); DelWrapper(rescue); } - + virtual int classDirectorMethod(Node *n, Node *parent, String *super) { int is_void = 0; int is_pointer = 0; @@ -2299,20 +2218,20 @@ public: String *tm; String *wrap_args = NewString(""); String *return_type; - Parm* p; + Parm *p; String *value = Getattr(n, "value"); - String *storage = Getattr(n,"storage"); + String *storage = Getattr(n, "storage"); bool pure_virtual = false; int status = SWIG_OK; int idx; bool ignored_method = GetFlag(n, "feature:ignore") ? true : false; - if (Cmp(storage,"virtual") == 0) { - if (Cmp(value,"0") == 0) { - pure_virtual = true; + if (Cmp(storage, "virtual") == 0) { + if (Cmp(value, "0") == 0) { + pure_virtual = true; } } - String *overnametmp = NewString(Getattr(n,"sym:name")); + String *overnametmp = NewString(Getattr(n, "sym:name")); if (Getattr(n, "sym:overloaded")) { Printf(overnametmp, "::%s", Getattr(n, "sym:overname")); } @@ -2323,7 +2242,7 @@ public: w = NewWrapper(); declaration = NewString(""); - + /* determine if the method returns a pointer */ decl = Getattr(n, "decl"); is_pointer = SwigType_ispointer_return(decl); @@ -2332,12 +2251,12 @@ public: /* form complete return type */ return_type = Copy(type); { - SwigType *t = Copy(decl); - SwigType *f = 0; - f = SwigType_pop_function(t); - SwigType_push(return_type, t); - Delete(f); - Delete(t); + SwigType *t = Copy(decl); + SwigType *f = 0; + f = SwigType_pop_function(t); + SwigType_push(return_type, t); + Delete(f); + Delete(t); } /* virtual method definition */ @@ -2364,24 +2283,25 @@ public: // Get any exception classes in the throws typemap ParmList *throw_parm_list = 0; - if ((throw_parm_list = Getattr(n,"throws")) || Getattr(n,"throw")) { - Parm *p; - int gencomma = 0; + if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { + Parm *p; + int gencomma = 0; Append(w->def, " throw("); Append(declaration, " throw("); - if (throw_parm_list) Swig_typemap_attach_parms("throws", throw_parm_list, 0); - for (p = throw_parm_list; p; p=nextSibling(p)) { - if ((tm = Getattr(p,"tmap:throws"))) { - if (gencomma++) { - Append(w->def, ", "); - Append(declaration, ", "); - } + if (throw_parm_list) + Swig_typemap_attach_parms("throws", throw_parm_list, 0); + for (p = throw_parm_list; p; p = nextSibling(p)) { + if ((tm = Getattr(p, "tmap:throws"))) { + if (gencomma++) { + Append(w->def, ", "); + Append(declaration, ", "); + } - Printf(w->def, "%s", SwigType_str(Getattr(p, "type"),0)); - Printf(declaration, "%s", SwigType_str(Getattr(p, "type"),0)); - } + Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0)); + Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0)); + } } Append(w->def, ")"); @@ -2409,7 +2329,8 @@ public: Printf(w->code, "%s;\n", super_call); Delete(super_call); } else { - Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name)); + Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), + SwigType_namestr(name)); } } else { /* attach typemaps to arguments (C/C++ -> Ruby) */ @@ -2422,7 +2343,7 @@ public: * Not sure if it's OK to leave it like this, but seems OK so far. */ typemap_copy_pname_to_lname(l); - + Swig_typemap_attach_parms("in", l, 0); Swig_typemap_attach_parms("directorin", l, 0); Swig_typemap_attach_parms("directorargout", l, w); @@ -2432,21 +2353,23 @@ public: char source[256]; int outputs = 0; - if (!is_void) outputs++; - + if (!is_void) + outputs++; + /* build argument list and type conversion string */ - for (i=0, idx=0, p = l; i < num_arguments; i++) { + for (i = 0, idx = 0, p = l; i < num_arguments; i++) { while (Getattr(p, "tmap:ignore")) { p = Getattr(p, "tmap:ignore:next"); } - if (Getattr(p, "tmap:directorargout") != 0) outputs++; - - String* parameterName = Getattr(p, "name"); - String* parameterType = Getattr(p, "type"); - - Putc(',',arglist); + if (Getattr(p, "tmap:directorargout") != 0) + outputs++; + + String *parameterName = Getattr(p, "name"); + String *parameterType = Getattr(p, "type"); + + Putc(',', arglist); if ((tm = Getattr(p, "tmap:directorin")) != 0) { sprintf(source, "obj%d", idx++); Replaceall(tm, "$input", source); @@ -2473,11 +2396,11 @@ public: sprintf(source, "obj%d", idx++); String *nonconst = 0; /* strip pointer/reference --- should move to Swig/stype.c */ - String *nptype = NewString(Char(parameterType)+2); + String *nptype = NewString(Char(parameterType) + 2); /* name as pointer */ String *ppname = Copy(parameterName); if (SwigType_isreference(parameterType)) { - Insert(ppname,0,"&"); + Insert(ppname, 0, "&"); } /* if necessary, cast away const since Ruby doesn't support it! */ if (SwigType_isconst(nptype)) { @@ -2486,7 +2409,8 @@ public: Wrapper_add_localv(w, nonconst, SwigType_lstr(parameterType, 0), nonconst, nonconst_i, NIL); Delete(nonconst_i); Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, - "Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(parameterType, parameterName), SwigType_namestr(c_classname), SwigType_namestr(name)); + "Target language argument '%s' discards const in director method %s::%s.\n", SwigType_str(parameterType, parameterName), + SwigType_namestr(c_classname), SwigType_namestr(name)); } else { nonconst = Copy(ppname); } @@ -2499,16 +2423,15 @@ public: Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL); Printf(wrap_args, "%s = dynamic_cast(%s);\n", director, nonconst); Printf(wrap_args, "if (!%s) {\n", director); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "} else {\n"); - Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); + Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); Printf(wrap_args, "}\n"); Delete(director); Printv(arglist, source, NIL); } else { Wrapper_add_localv(w, source, "VALUE", source, "= Qnil", NIL); - Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", - source, nonconst, mangle); + Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n", // source, nonconst, base); Printv(arglist, source, NIL); @@ -2517,7 +2440,8 @@ public: Delete(nonconst); } else { Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(parameterType, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(parameterType, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_NOWRAP; break; } @@ -2535,15 +2459,15 @@ public: exceptionSafeMethodCall(classname, n, w, idx, arglist); /* - * Ruby method may return a simple object, or an Array of objects. - * For in/out arguments, we have to extract the appropriate VALUEs from the Array, - * then marshal everything back to C/C++ (return value and output arguments). - */ + * Ruby method may return a simple object, or an Array of objects. + * For in/out arguments, we have to extract the appropriate VALUEs from the Array, + * then marshal everything back to C/C++ (return value and output arguments). + */ /* Marshal return value and other outputs (if any) from VALUE to C/C++ type */ - String* cleanup = NewString(""); - String* outarg = NewString(""); + String *cleanup = NewString(""); + String *outarg = NewString(""); if (outputs > 1) { Wrapper_add_local(w, "output", "VALUE output"); @@ -2577,22 +2501,23 @@ public: Replaceall(tm, "$input", "result"); } /* TODO check this */ - if (Getattr(n,"wrap:disown")) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); + if (Getattr(n, "wrap:disown")) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); } else { - Replaceall(tm,"$disown","0"); + Replaceall(tm, "$disown", "0"); } Replaceall(tm, "$result", "c_result"); Printv(w->code, tm, "\n", NIL); } else { Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name)); + "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), + SwigType_namestr(c_classname), SwigType_namestr(name)); status = SWIG_ERROR; } } - + /* Marshal outputs */ - for (p = l; p; ) { + for (p = l; p;) { if ((tm = Getattr(p, "tmap:directorargout")) != 0) { if (outputs > 1) { Printf(w->code, "output = rb_ary_entry(result, %d);\n", idx++); @@ -2616,7 +2541,7 @@ public: /* any existing helper functions to handle this? */ if (!is_void) { if (!(ignored_method && !pure_virtual)) { - String* rettype = SwigType_str(return_type, 0); + String *rettype = SwigType_str(return_type, 0); if (!SwigType_isreference(return_type)) { Printf(w->code, "return (%s) c_result;\n", rettype); } else { @@ -2630,8 +2555,7 @@ public: // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method String *inline_extra_method = NewString(""); - if (dirprot_mode() && !is_public(n) && !pure_virtual) - { + if (dirprot_mode() && !is_public(n) && !pure_virtual) { Printv(inline_extra_method, declaration, NIL); String *extra_method_name = NewStringf("%sSwigPublic", name); Replaceall(inline_extra_method, name, extra_method_name); @@ -2646,9 +2570,9 @@ public: /* emit the director method */ if (status == SWIG_OK) { - if (!Getattr(n,"defaultargs")) { - Wrapper_print(w, f_directors); - Printv(f_directors_h, declaration, NIL); + if (!Getattr(n, "defaultargs")) { + Wrapper_print(w, f_directors); + Printv(f_directors_h, declaration, NIL); Printv(f_directors_h, inline_extra_method, NIL); } } @@ -2661,30 +2585,29 @@ public: DelWrapper(w); return status; } - + virtual int classDirectorConstructors(Node *n) { return Language::classDirectorConstructors(n); } - + virtual int classDirectorMethods(Node *n) { return Language::classDirectorMethods(n); } - + virtual int classDirectorDisown(Node *n) { return Language::classDirectorDisown(n); } - void typemap_copy_pname_to_lname(ParmList *parms) - { + void typemap_copy_pname_to_lname(ParmList *parms) { Parm *p; String *pname; String *lname; p = parms; while (p) { - pname = Getattr(p,"name"); + pname = Getattr(p, "name"); lname = Copy(pname); - Setattr(p,"lname",lname); + Setattr(p, "lname", lname); p = nextSibling(p); } } @@ -2732,16 +2655,16 @@ public: String *defaultExternalRuntimeFilename() { return NewString("swigrubyrun.h"); } -}; /* class RUBY */ - +}; /* class RUBY */ + /* ----------------------------------------------------------------------------- * swig_ruby() - Instantiate module * ----------------------------------------------------------------------------- */ -static Language * new_swig_ruby() { +static Language *new_swig_ruby() { return new RUBY(); } -extern "C" Language * swig_ruby(void) { +extern "C" Language *swig_ruby(void) { return new_swig_ruby(); } @@ -2751,4 +2674,3 @@ extern "C" Language * swig_ruby(void) { * c-basic-offset: 2 * End: */ - diff --git a/SWIG/Source/Modules/s-exp.cxx b/SWIG/Source/Modules/s-exp.cxx index 3697304f0..ef2a2a50d 100644 --- a/SWIG/Source/Modules/s-exp.cxx +++ b/SWIG/Source/Modules/s-exp.cxx @@ -18,32 +18,33 @@ S-Exp Options (available with -sexp)\n\ //static Node *view_top = 0; static File *out = 0; - -class Sexp : public Language { + +class Sexp:public Language { public: int indent_level; - Sexp() : indent_level( 0 ) {} - virtual ~Sexp() {} + Sexp():indent_level(0) { + } + + virtual ~ Sexp() { + } + virtual void main(int argc, char *argv[]) { SWIG_typemap_lang("sexp"); - for( int iX = 0; iX < argc; iX++ ) - { - if( strcmp( argv[iX], "-typemaplang" ) == 0 ) - { - Swig_mark_arg (iX); - iX++; - SWIG_typemap_lang(argv[iX]); - Swig_mark_arg (iX); - continue; - } - if( strcmp( argv[iX], "-help" ) == 0 ) - { - fputs( usage, stdout ); - } + for (int iX = 0; iX < argc; iX++) { + if (strcmp(argv[iX], "-typemaplang") == 0) { + Swig_mark_arg(iX); + iX++; + SWIG_typemap_lang(argv[iX]); + Swig_mark_arg(iX); + continue; } + if (strcmp(argv[iX], "-help") == 0) { + fputs(usage, stdout); + } + } - // Add a symbol to the parser for conditional compilation - Preprocessor_define("SWIGSEXP 1",0); + // Add a symbol to the parser for conditional compilation + Preprocessor_define("SWIGSEXP 1", 0); } DOHHash *print_circle_hash; @@ -53,28 +54,25 @@ public: bool need_newline; /* Top of the parse tree */ - virtual int top(Node *n) - { - if( out == 0 ) - { - String *outfile = Getattr(n,"outfile"); - Replaceall(outfile,"_wrap.cxx", ".lisp"); - Replaceall(outfile,"_wrap.c", ".lisp"); - out = NewFile(outfile,"w"); - if (!out) - { - FileErrorDisplay(outfile); - SWIG_exit(EXIT_FAILURE); - } + virtual int top(Node *n) { + if (out == 0) { + String *outfile = Getattr(n, "outfile"); + Replaceall(outfile, "_wrap.cxx", ".lisp"); + Replaceall(outfile, "_wrap.c", ".lisp"); + out = NewFile(outfile, "w"); + if (!out) { + FileErrorDisplay(outfile); + SWIG_exit(EXIT_FAILURE); } + } String *f_sink = NewString(""); - Swig_register_filebyname("header",f_sink); - Swig_register_filebyname("wrapper",f_sink); - Swig_register_filebyname("runtime",f_sink); - Swig_register_filebyname("init",f_sink); - + Swig_register_filebyname("header", f_sink); + Swig_register_filebyname("wrapper", f_sink); + Swig_register_filebyname("runtime", f_sink); + Swig_register_filebyname("init", f_sink); + Language::top(n); - Printf( out, ";;; Lisp parse tree produced by SWIG\n" ); + Printf(out, ";;; Lisp parse tree produced by SWIG\n"); print_circle_hash = DohNewHash(); print_circle_count = 0; hanging_parens = 0; @@ -85,36 +83,32 @@ public: return SWIG_OK; } - void print_indent() - { + void print_indent() { int i; - for (i = 0; i < indent_level; i++) - { - Printf(out, " "); - } + for (i = 0; i < indent_level; i++) { + Printf(out, " "); + } } - void open_paren(const String *oper) - { + void open_paren(const String *oper) { flush_parens(); Printf(out, "("); - if (oper) Printf(out, "%s ", oper); + if (oper) + Printf(out, "%s ", oper); indent_level += 2; } - void close_paren(bool neednewline = false) - { + void close_paren(bool neednewline = false) { hanging_parens++; if (neednewline) print_lazy_whitespace(); indent_level -= 2; } - void flush_parens() - { + void flush_parens() { int i; if (hanging_parens) { - for (i = 0; iobjname, "List") == 0) { + } else if (strcmp(ObjType(obj)->objname, "List") == 0) { int i; open_paren(NIL); - for (i = 0; i", ObjType(obj)->objname, obj); + Printf(out, "#", ObjType(obj)->objname, obj); } } } } - void Sexp_print_as_keyword(const DOH *k) - { + void Sexp_print_as_keyword(const DOH *k) { /* Print key, replacing ":" with "-" because : is CL's package prefix */ flush_parens(); String *key = NewString(k); Replaceall(key, ":", "-"); Replaceall(key, "_", "-"); - Printf(out,":%s ", key); + Printf(out, ":%s ", key); Delete(key); } - void Sexp_print_plist_noparens(DOH *obj) - { + void Sexp_print_plist_noparens(DOH *obj) { /* attributes map names to objects */ Iterator k; bool first; - for (k = First(obj), first = true; k.key; k = Next(k), first=false) { + for (k = First(obj), first = true; k.key; k = Next(k), first = false) { if (!internal_key_p(k.key)) { DOH *value = Getattr(obj, k.key); flush_parens(); @@ -359,9 +335,8 @@ public: } } } - - void Sexp_print_plist(DOH *obj) - { + + void Sexp_print_plist(DOH *obj) { flush_parens(); if (print_circle(obj, true)) { open_paren(NIL); @@ -370,14 +345,12 @@ public: } } - void Sexp_print_attributes(Node * obj) - { + void Sexp_print_attributes(Node *obj) { Sexp_print_plist_noparens(obj); } - - void Sexp_print_node(Node *obj) - { - Node *cobj; + + void Sexp_print_node(Node *obj) { + Node *cobj; open_paren(nodeType(obj)); /* A node has an attribute list... */ Sexp_print_attributes(obj); @@ -397,21 +370,20 @@ public: } - virtual int functionWrapper(Node *n) - { - ParmList *l = Getattr(n,"parms"); + virtual int functionWrapper(Node *n) { + ParmList *l = Getattr(n, "parms"); Wrapper *f = NewWrapper(); - emit_attach_parmmaps(l,f); - Setattr(n,"wrap:parms",l); + emit_attach_parmmaps(l, f); + Setattr(n, "wrap:parms", l); return SWIG_OK; } - + }; -static Language * new_swig_sexp() { +static Language *new_swig_sexp() { return new Sexp(); } -extern "C" Language * swig_sexp( void ) { +extern "C" Language *swig_sexp(void) { return new_swig_sexp(); } diff --git a/SWIG/Source/Modules/swigmain.cxx b/SWIG/Source/Modules/swigmain.cxx index 47f4a46b0..09589a6a0 100644 --- a/SWIG/Source/Modules/swigmain.cxx +++ b/SWIG/Source/Modules/swigmain.cxx @@ -49,41 +49,41 @@ extern "C" { } struct swig_module { - const char *name; - ModuleFactory fac; - const char *help; + const char *name; + ModuleFactory fac; + const char *help; }; /* Association of command line options to language modules. Place an entry for new language modules here, keeping the list sorted alphabetically. */ -static swig_module modules[] = { +static swig_module modules[] = { {"-allegrocl", swig_allegrocl, "ALLEGROCL"}, - {"-chicken", swig_chicken, "CHICKEN"}, - {"-clisp", swig_clisp, "CLISP"}, - {"-cffi", swig_cffi, "CFFI"}, - {"-csharp", swig_csharp, "C#"}, - {"-guile", swig_guile, "Guile"}, - {"-java", swig_java, "Java"}, - {"-lua", swig_lua, "Lua"}, - {"-modula3", swig_modula3, "Modula 3"}, - {"-mzscheme", swig_mzscheme, "Mzscheme"}, - {"-ocaml", swig_ocaml, "Ocaml"}, - {"-perl", swig_perl5, "Perl"}, - {"-perl5", swig_perl5, 0}, - {"-php", swig_php4, 0}, - {"-php4", swig_php4, "PHP4"}, - {"-php5", swig_php5, "PHP5"}, - {"-pike", swig_pike, "Pike"}, - {"-python", swig_python, "Python"}, - {"-ruby", swig_ruby, "Ruby"}, - {"-sexp", swig_sexp, "Lisp S-Expressions"}, - {"-tcl", swig_tcl, "Tcl"}, - {"-tcl8", swig_tcl, 0}, - {"-uffi", swig_uffi, "Common Lisp / UFFI"}, - {"-xml", swig_xml, "XML"}, - {"-r", swig_r, "R (aka GNU S)"}, + {"-chicken", swig_chicken, "CHICKEN"}, + {"-clisp", swig_clisp, "CLISP"}, + {"-cffi", swig_cffi, "CFFI"}, + {"-csharp", swig_csharp, "C#"}, + {"-guile", swig_guile, "Guile"}, + {"-java", swig_java, "Java"}, + {"-lua", swig_lua, "Lua"}, + {"-modula3", swig_modula3, "Modula 3"}, + {"-mzscheme", swig_mzscheme, "Mzscheme"}, + {"-ocaml", swig_ocaml, "Ocaml"}, + {"-perl", swig_perl5, "Perl"}, + {"-perl5", swig_perl5, 0}, + {"-php", swig_php4, 0}, + {"-php4", swig_php4, "PHP4"}, + {"-php5", swig_php5, "PHP5"}, + {"-pike", swig_pike, "Pike"}, + {"-python", swig_python, "Python"}, + {"-ruby", swig_ruby, "Ruby"}, + {"-sexp", swig_sexp, "Lisp S-Expressions"}, + {"-tcl", swig_tcl, "Tcl"}, + {"-tcl8", swig_tcl, 0}, + {"-uffi", swig_uffi, "Common Lisp / UFFI"}, + {"-xml", swig_xml, "XML"}, + {"-r", swig_r, "R (aka GNU S)"}, {NULL, NULL, NULL} }; @@ -102,9 +102,7 @@ static swig_module modules[] = { // Main program. Initializes the files and starts the parser. //----------------------------------------------------------------- -void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], - int *nargc, char ***nargv) -{ +void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int *nargc, char ***nargv) { if (!env) { *nargc = oargc; *nargv = oargv; @@ -113,13 +111,14 @@ void SWIG_merge_envopt(const char *env, int oargc, char *oargv[], int argc = 1; int arge = oargc + 1024; - char **argv = (char **) malloc(sizeof(char*)*(arge)); - char *buffer = (char*) malloc(2048); + char **argv = (char **) malloc(sizeof(char *) * (arge)); + char *buffer = (char *) malloc(2048); char *b = buffer; char *be = b + 1023; const char *c = env; while ((b != be) && *c && (argc < arge)) { - while (isspace(*c) && *c) ++c; + while (isspace(*c) && *c) + ++c; if (*c) { argv[argc] = b; ++argc; @@ -159,33 +158,30 @@ int main(int margc, char **margv) { Swig_register_module(modules[i].name, modules[i].fac); } - Swig_init_args(argc,argv); + Swig_init_args(argc, argv); /* Get options */ for (i = 1; i < argc; i++) { if (argv[i]) { fac = Swig_find_module(argv[i]); if (fac) { - dl = (fac)(); + dl = (fac) (); Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nolang") == 0) { + } else if (strcmp(argv[i], "-nolang") == 0) { dl = new Language; Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-dnone") == 0) || - (strcmp(argv[i],"-dhtml") == 0) || - (strcmp(argv[i],"-dlatex") == 0) || - (strcmp(argv[i],"-dascii") == 0) || - (strcmp(argv[i],"-stat") == 0)) - { - Printf(stderr,"swig: Warning. %s option deprecated.\n",argv[i]); + } else if ((strcmp(argv[i], "-dnone") == 0) || + (strcmp(argv[i], "-dhtml") == 0) || + (strcmp(argv[i], "-dlatex") == 0) || (strcmp(argv[i], "-dascii") == 0) || (strcmp(argv[i], "-stat") == 0)) { + Printf(stderr, "swig: Warning. %s option deprecated.\n", argv[i]); Swig_mark_arg(i); - } else if ((strcmp(argv[i],"-help") == 0) || (strcmp(argv[i],"--help") == 0)) { - if (strcmp(argv[i],"--help") == 0) + } else if ((strcmp(argv[i], "-help") == 0) || (strcmp(argv[i], "--help") == 0)) { + if (strcmp(argv[i], "--help") == 0) strcpy(argv[i], "-help"); - Printf(stdout,"Target Language Options\n"); + Printf(stdout, "Target Language Options\n"); for (int j = 0; modules[j].name; j++) { if (modules[j].help) { - Printf(stdout," %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help); + Printf(stdout, " %-15s - Generate %s wrappers\n", modules[j].name, modules[j].help); } } // Swig_mark_arg not called as the general -help options also need to be displayed later on @@ -195,11 +191,10 @@ int main(int margc, char **margv) { if (!dl) { fac = Swig_find_module(SWIG_LANG); if (fac) { - dl = (fac)(); + dl = (fac) (); } } - int res = SWIG_main(argc,argv,dl); + int res = SWIG_main(argc, argv, dl); delete dl; - return res; + return res; } - diff --git a/SWIG/Source/Modules/swigmod.h b/SWIG/Source/Modules/swigmod.h index 22458c105..a95d55f22 100644 --- a/SWIG/Source/Modules/swigmod.h +++ b/SWIG/Source/Modules/swigmod.h @@ -26,18 +26,18 @@ typedef int bool; #define PLAIN_VIRTUAL 1 #define PURE_VIRTUAL 2 -extern char *input_file; -extern int line_number; -extern int start_line; -extern int CPlusPlus; // C++ mode -extern int Extend; // Extend mode -extern int Verbose; -extern int IsVirtual; -extern int ImportMode; -extern int NoExcept; // -no_except option -extern int Abstract; // abstract base class -extern int SmartPointer; // smart pointer methods being emitted -extern int SwigRuntime; +extern char *input_file; +extern int line_number; +extern int start_line; +extern int CPlusPlus; // C++ mode +extern int Extend; // Extend mode +extern int Verbose; +extern int IsVirtual; +extern int ImportMode; +extern int NoExcept; // -no_except option +extern int Abstract; // abstract base class +extern int SmartPointer; // smart pointer methods being emitted +extern int SwigRuntime; /* Overload "argc" and "argv" */ extern String *argv_template_string; @@ -50,18 +50,19 @@ extern String *argc_template_string; #define tab8 " " class Dispatcher { - public: +public: - Dispatcher() : cplus_mode(PUBLIC) {} - virtual ~Dispatcher() {} + Dispatcher ():cplus_mode(PUBLIC) { + } virtual ~ Dispatcher () { + } virtual int emit_one(Node *n); virtual int emit_children(Node *n); virtual int defaultHandler(Node *n); /* Top of the parse tree */ - virtual int top(Node *n) = 0; - + virtual int top(Node *n) = 0; + /* SWIG directives */ virtual int applyDirective(Node *n); @@ -81,7 +82,7 @@ class Dispatcher { virtual int typesDirective(Node *n); /* C/C++ parsing */ - + virtual int cDeclaration(Node *n); virtual int externDeclaration(Node *n); virtual int enumDeclaration(Node *n); @@ -110,10 +111,10 @@ protected: * functions to output different types of code for different languages. * ------------------------------------------------------------------------- */ -class Language : public Dispatcher { +class Language:public Dispatcher { public: - Language(); - virtual ~Language(); + Language (); + virtual ~ Language (); virtual int emit_one(Node *n); /* Parse command line options */ @@ -122,10 +123,10 @@ public: /* Top of the parse tree */ - virtual int top(Node *n); - + virtual int top(Node *n); + /* SWIG directives */ - + virtual int applyDirective(Node *n); virtual int clearDirective(Node *n); @@ -143,7 +144,7 @@ public: virtual int typesDirective(Node *n); /* C/C++ parsing */ - + virtual int cDeclaration(Node *n); virtual int externDeclaration(Node *n); virtual int enumDeclaration(Node *n); @@ -195,12 +196,7 @@ public: virtual int classDirector(Node *n); virtual int classDirectorInit(Node *n); virtual int classDirectorEnd(Node *n); - virtual int unrollVirtualMethods(Node *n, - Node *parent, - List *vm, - int default_director, - int &virtual_destructor, - int protectedbase = 0); + virtual int unrollVirtualMethods(Node *n, Node *parent, List *vm, int default_director, int &virtual_destructor, int protectedbase = 0); virtual int classDirectorConstructor(Node *n); virtual int classDirectorDefaultConstructor(Node *n); virtual int classDirectorMethod(Node *n, Node *parent, String *super); @@ -210,16 +206,16 @@ public: virtual int classDirectorDisown(Node *n); /* Miscellaneous */ - virtual int validIdentifier(String *s); /* valid identifier? */ - virtual int addSymbol(const String *s, const Node *n); /* Add symbol */ - virtual Node *symbolLookup(String *s); /* Symbol lookup */ - virtual Node *classLookup(SwigType *s); /* Class lookup */ - virtual Node *enumLookup(SwigType *s); /* Enum lookup */ - virtual int abstractClassTest(Node *n); /* Is class really abstract? */ - virtual int is_assignable(Node *n); /* Is variable assignable? */ - virtual String *runtimeCode(); /* returns the language specific runtime code */ - virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */ - + virtual int validIdentifier(String *s); /* valid identifier? */ + virtual int addSymbol(const String *s, const Node *n); /* Add symbol */ + virtual Node *symbolLookup(String *s); /* Symbol lookup */ + virtual Node *classLookup(SwigType *s); /* Class lookup */ + virtual Node *enumLookup(SwigType *s); /* Enum lookup */ + virtual int abstractClassTest(Node *n); /* Is class really abstract? */ + virtual int is_assignable(Node *n); /* Is variable assignable? */ + virtual String *runtimeCode(); /* returns the language specific runtime code */ + virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */ + /* Allow director related code generation */ void allow_directors(int val = 1); @@ -227,10 +223,10 @@ public: int directorsEnabled() const; /* Allow director protected members related code generation */ - void allow_dirprot(int val = 1); + void allow_dirprot(int val = 1); /* Returns the dirprot mode */ - int dirprot_mode() const; + int dirprot_mode() const; /* Check if the non public constructor is needed (for directors) */ int need_nonpublic_ctor(Node *n); @@ -246,10 +242,10 @@ public: protected: /* Allow multiple-input typemaps */ - void allow_multiple_input(int val = 1); + void allow_multiple_input(int val = 1); /* Allow overloaded functions */ - void allow_overloading(int val = 1); + void allow_overloading(int val = 1); /* Wrapping class query */ int is_wrapping_class(); @@ -281,7 +277,7 @@ protected: /* Director constructor "template" code */ String *director_ctor_code; - /* Director 'protected' constructor "template" code*/ + /* Director 'protected' constructor "template" code */ String *director_prot_ctor_code; /* Director allows multiple inheritance */ @@ -291,37 +287,37 @@ protected: int director_language; private: - Hash *symbols; - Hash *classtypes; - Hash *enumtypes; - int overloading; - int multiinput; - int directors; + Hash *symbols; + Hash *classtypes; + Hash *enumtypes; + int overloading; + int multiinput; + int directors; }; -int SWIG_main(int, char **, Language *); -void emit_args(SwigType *, ParmList *, Wrapper *f); -void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */ -void SWIG_config_file(const String_or_char *); +int SWIG_main(int, char **, Language *); +void emit_args(SwigType *, ParmList *, Wrapper *f); +void SWIG_exit(int); /* use EXIT_{SUCCESS,FAILURE} */ +void SWIG_config_file(const String_or_char *); const String *SWIG_output_directory(); -void SWIG_config_cppext(const char *ext); +void SWIG_config_cppext(const char *ext); -void SWIG_library_directory(const char *); -int emit_num_arguments(ParmList *); -int emit_num_required(ParmList *); -int emit_isvarargs(ParmList *); -void emit_attach_parmmaps(ParmList *, Wrapper *f); -void emit_mark_varargs(ParmList *l); -void emit_action(Node *n, Wrapper *f); -int emit_action_code(Node *n, Wrapper *f, String *action); -void Swig_overload_check(Node *n); +void SWIG_library_directory(const char *); +int emit_num_arguments(ParmList *); +int emit_num_required(ParmList *); +int emit_isvarargs(ParmList *); +void emit_attach_parmmaps(ParmList *, Wrapper *f); +void emit_mark_varargs(ParmList *l); +void emit_action(Node *n, Wrapper *f); +int emit_action_code(Node *n, Wrapper *f, String *action); +void Swig_overload_check(Node *n); String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *); String *Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *); String *Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *); SwigType *cplus_value_type(SwigType *t); /* directors.cxx start */ -String *Swig_csuperclass_call(String* base, String* method, ParmList* l); +String *Swig_csuperclass_call(String *base, String *method, ParmList *l); String *Swig_class_declaration(Node *n, String *name); String *Swig_class_name(Node *n); String *Swig_method_call(String_or_char *name, ParmList *parms); @@ -330,20 +326,18 @@ String *Swig_director_declaration(Node *n); /* directors.cxx end */ extern "C" { - void SWIG_typemap_lang(const char *); - typedef Language *(*ModuleFactory)(void); -} - -void Swig_register_module(const char *name, ModuleFactory fac); + void SWIG_typemap_lang(const char *); + typedef Language *(*ModuleFactory) (void); +} void Swig_register_module(const char *name, ModuleFactory fac); ModuleFactory Swig_find_module(const char *name); /* Utilities */ -int is_public(Node* n); -int is_private(Node* n); -int is_protected(Node* n); -int is_member_director(Node* parentnode, Node* member); -int is_member_director(Node* member); +int is_public(Node *n); +int is_private(Node *n); +int is_protected(Node *n); +int is_member_director(Node *parentnode, Node *member); +int is_member_director(Node *member); int use_naturalvar_mode(Node *n); void Wrapper_virtual_elimination_mode_set(int); @@ -360,7 +354,7 @@ void clean_overloaded(Node *n); void Swig_contracts(Node *n); void Swig_contract_mode_set(int flag); -int Swig_contract_mode_get(); +int Swig_contract_mode_get(); /* Browser */ @@ -370,7 +364,3 @@ void Swig_process_types(Node *n); #endif - - - - diff --git a/SWIG/Source/Modules/tcl8.cxx b/SWIG/Source/Modules/tcl8.cxx index 4dd04cd0f..4b8fd438f 100644 --- a/SWIG/Source/Modules/tcl8.cxx +++ b/SWIG/Source/Modules/tcl8.cxx @@ -13,7 +13,7 @@ char cvsroot_tcl8_cxx[] = "$Header$"; #include "cparse.h" static int treduce = SWIG_cparse_template_reduce(0); -static const char *usage = (char*)"\ +static const char *usage = (char *) "\ Tcl 8 Options (available with -tcl)\n\ -itcl - Enable ITcl support\n\ -nosafe - Leave out SafeInit module function.\n\ @@ -21,38 +21,38 @@ Tcl 8 Options (available with -tcl)\n\ -namespace - Build module into a Tcl 8 namespace\n\ -pkgversion - Set package version\n\n"; -static String *cmd_tab = 0; /* Table of command names */ -static String *var_tab = 0; /* Table of global variables */ -static String *const_tab = 0; /* Constant table */ -static String *methods_tab = 0; /* Methods table */ -static String *attr_tab = 0; /* Attribute table */ -static String *prefix = 0; -static String *module = 0; -static int nspace = 0; -static String *init_name = 0; -static String *ns_name = 0; -static int have_constructor; -static String *constructor_name; -static int have_destructor; -static int have_base_classes; -static String *destructor_action = 0; -static String *version = (String *) "0.0"; -static String *class_name = 0; +static String *cmd_tab = 0; /* Table of command names */ +static String *var_tab = 0; /* Table of global variables */ +static String *const_tab = 0; /* Constant table */ +static String *methods_tab = 0; /* Methods table */ +static String *attr_tab = 0; /* Attribute table */ +static String *prefix = 0; +static String *module = 0; +static int nspace = 0; +static String *init_name = 0; +static String *ns_name = 0; +static int have_constructor; +static String *constructor_name; +static int have_destructor; +static int have_base_classes; +static String *destructor_action = 0; +static String *version = (String *) "0.0"; +static String *class_name = 0; -static int have_attributes; -static int have_methods; -static int nosafe = 0; +static int have_attributes; +static int have_methods; +static int nosafe = 0; -static File *f_header = 0; -static File *f_wrappers = 0; -static File *f_init = 0; -static File *f_runtime = 0; +static File *f_header = 0; +static File *f_wrappers = 0; +static File *f_init = 0; +static File *f_runtime = 0; // Itcl support -static int itcl = 0; -static File *f_shadow = 0; -static File *f_shadow_stubs = 0; +static int itcl = 0; +static File *f_shadow = 0; +static File *f_shadow_stubs = 0; static String *constructor = 0; static String *destructor = 0; @@ -66,51 +66,52 @@ static String *iattribute_traces = 0; -class TCL8 : public Language { +class TCL8:public Language { public: - + /* ------------------------------------------------------------ * TCL8::main() * ------------------------------------------------------------ */ - + virtual void main(int argc, char *argv[]) { int cppcast = 1; - SWIG_library_directory("tcl"); - + SWIG_library_directory("tcl"); + for (int i = 1; i < argc; i++) { if (argv[i]) { - if (strcmp(argv[i],"-prefix") == 0) { - if (argv[i+1]) { - prefix = NewString(argv[i+1]); + if (strcmp(argv[i], "-prefix") == 0) { + if (argv[i + 1]) { + prefix = NewString(argv[i + 1]); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; - } else Swig_arg_error(); - } else if (strcmp(argv[i],"-pkgversion") == 0) { - if (argv[i+1]) { - version = NewString(argv[i+1]); + } else + Swig_arg_error(); + } else if (strcmp(argv[i], "-pkgversion") == 0) { + if (argv[i + 1]) { + version = NewString(argv[i + 1]); Swig_mark_arg(i); - Swig_mark_arg(i+1); + Swig_mark_arg(i + 1); i++; } - } else if (strcmp(argv[i],"-namespace") == 0) { + } else if (strcmp(argv[i], "-namespace") == 0) { nspace = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-itcl") == 0) { + } else if (strcmp(argv[i], "-itcl") == 0) { itcl = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nosafe") == 0) { + } else if (strcmp(argv[i], "-nosafe") == 0) { nosafe = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-cppcast") == 0) { + } else if (strcmp(argv[i], "-cppcast") == 0) { cppcast = 1; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-nocppcast") == 0) { + } else if (strcmp(argv[i], "-nocppcast") == 0) { cppcast = 0; Swig_mark_arg(i); - } else if (strcmp(argv[i],"-help") == 0) { - fputs(usage,stdout); + } else if (strcmp(argv[i], "-help") == 0) { + fputs(usage, stdout); } } } @@ -119,7 +120,7 @@ public: Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0); } - Preprocessor_define("SWIGTCL 1",0); + Preprocessor_define("SWIGTCL 1", 0); Preprocessor_define("SWIGTCL8 1", 0); SWIG_typemap_lang("tcl8"); SWIG_config_file("tcl8.swg"); @@ -133,9 +134,9 @@ public: virtual int top(Node *n) { /* Initialize all of the output files */ - String *outfile = Getattr(n,"outfile"); - - f_runtime = NewFile(outfile,"w"); + String *outfile = Getattr(n, "outfile"); + + f_runtime = NewFile(outfile, "w"); if (!f_runtime) { FileErrorDisplay(outfile); SWIG_exit(EXIT_FAILURE); @@ -143,397 +144,389 @@ public: f_init = NewString(""); f_header = NewString(""); f_wrappers = NewString(""); - + /* Register file targets with the SWIG file handler */ - Swig_register_filebyname("header",f_header); - Swig_register_filebyname("wrapper",f_wrappers); - Swig_register_filebyname("runtime",f_runtime); - Swig_register_filebyname("init",f_init); - + Swig_register_filebyname("header", f_header); + Swig_register_filebyname("wrapper", f_wrappers); + Swig_register_filebyname("runtime", f_runtime); + Swig_register_filebyname("init", f_init); + /* Initialize some variables for the object interface */ - - cmd_tab = NewString(""); - var_tab = NewString(""); - methods_tab = NewString(""); - const_tab = NewString(""); - + + cmd_tab = NewString(""); + var_tab = NewString(""); + methods_tab = NewString(""); + const_tab = NewString(""); + Swig_banner(f_runtime); - + /* Set the module name, namespace, and prefix */ - - module = NewStringf("%(lower)s", Getattr(n,"name")); - init_name = NewStringf("%(title)s_Init",module); - + + module = NewStringf("%(lower)s", Getattr(n, "name")); + init_name = NewStringf("%(title)s_Init", module); + ns_name = prefix ? Copy(prefix) : Copy(module); - if (prefix) Append(prefix,"_"); - + if (prefix) + Append(prefix, "_"); + /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (itcl) { String *filen; filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module); - Insert( module,0,"_" ); + Insert(module, 0, "_"); - if ((f_shadow = NewFile(filen,"w")) == 0) { + if ((f_shadow = NewFile(filen, "w")) == 0) { FileErrorDisplay(filen); - SWIG_exit (EXIT_FAILURE); + SWIG_exit(EXIT_FAILURE); } f_shadow_stubs = NewString(""); - Swig_register_filebyname("shadow",f_shadow); - Swig_register_filebyname("itcl",f_shadow); + Swig_register_filebyname("shadow", f_shadow); + Swig_register_filebyname("itcl", f_shadow); Printv(f_shadow, - "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", - "# Don't modify this file, modify the SWIG interface instead.\n", - NIL); + "# This file was created automatically by SWIG ", PACKAGE_VERSION, ".\n", "# Don't modify this file, modify the SWIG interface instead.\n", NIL); - Printv(f_shadow,"\npackage require Itcl\n\n", NIL); + Printv(f_shadow, "\npackage require Itcl\n\n", NIL); Delete(filen); } /* Generate some macros used throughout code generation */ - - Printf(f_header,"#define SWIG_init %s\n", init_name); - Printf(f_header,"#define SWIG_name \"%s\"\n", module); + + Printf(f_header, "#define SWIG_init %s\n", init_name); + Printf(f_header, "#define SWIG_name \"%s\"\n", module); if (nspace) { - Printf(f_header,"#define SWIG_prefix \"%s::\"\n", ns_name); - Printf(f_header,"#define SWIG_namespace \"%s\"\n\n", ns_name); + Printf(f_header, "#define SWIG_prefix \"%s::\"\n", ns_name); + Printf(f_header, "#define SWIG_namespace \"%s\"\n\n", ns_name); } else { - Printf(f_header,"#define SWIG_prefix \"%s\"\n", prefix); + Printf(f_header, "#define SWIG_prefix \"%s\"\n", prefix); } - Printf(f_header,"#define SWIG_version \"%s\"\n", version); - - Printf(cmd_tab, "\nstatic swig_command_info swig_commands[] = {\n"); - Printf(var_tab, "\nstatic swig_var_info swig_variables[] = {\n"); + Printf(f_header, "#define SWIG_version \"%s\"\n", version); + + Printf(cmd_tab, "\nstatic swig_command_info swig_commands[] = {\n"); + Printf(var_tab, "\nstatic swig_var_info swig_variables[] = {\n"); Printf(const_tab, "\nstatic swig_const_info swig_constants[] = {\n"); - - Printf(f_wrappers,"#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); - + + Printf(f_wrappers, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n"); + /* Start emitting code */ Language::top(n); - + /* Done. Close up the module */ - Printv(cmd_tab, tab4, "{0, 0, 0}\n", "};\n",NIL); - Printv(var_tab, tab4, "{0,0,0,0}\n", "};\n",NIL); + Printv(cmd_tab, tab4, "{0, 0, 0}\n", "};\n", NIL); + Printv(var_tab, tab4, "{0,0,0,0}\n", "};\n", NIL); Printv(const_tab, tab4, "{0,0,0,0,0,0}\n", "};\n", NIL); - - Printv(f_wrappers, cmd_tab, var_tab, const_tab,NIL); - + + Printv(f_wrappers, cmd_tab, var_tab, const_tab, NIL); + /* Dump the pointer equivalency table */ SwigType_emit_type_table(f_runtime, f_wrappers); - - Printf(f_wrappers,"#ifdef __cplusplus\n}\n#endif\n"); - + + Printf(f_wrappers, "#ifdef __cplusplus\n}\n#endif\n"); + /* Close the init function and quit */ - Printf(f_init,"return TCL_OK;\n}\n"); + Printf(f_init, "return TCL_OK;\n}\n"); if (!nosafe) { - Printf(f_init,"SWIGEXPORT int %(title)s_SafeInit(Tcl_Interp *interp) {\n", module ); - Printf(f_init," return SWIG_init(interp);\n"); - Printf(f_init,"}\n"); + Printf(f_init, "SWIGEXPORT int %(title)s_SafeInit(Tcl_Interp *interp) {\n", module); + Printf(f_init, " return SWIG_init(interp);\n"); + Printf(f_init, "}\n"); } if (itcl) { - Printv(f_shadow, f_shadow_stubs, "\n",NIL); + Printv(f_shadow, f_shadow_stubs, "\n", NIL); Close(f_shadow); Delete(f_shadow); } /* Close all of the files */ - Printv(f_runtime, f_header, f_wrappers,NIL); - Wrapper_pretty_print(f_init,f_runtime); + Printv(f_runtime, f_header, f_wrappers, NIL); + Wrapper_pretty_print(f_init, f_runtime); Delete(f_header); Delete(f_wrappers); Delete(f_init); Close(f_runtime); return SWIG_OK; } - + /* ------------------------------------------------------------ * functionWrapper() * ------------------------------------------------------------ */ virtual int functionWrapper(Node *n) { - String *name = Getattr(n,"name"); /* Like to get rid of this */ - String *iname = Getattr(n,"sym:name"); - SwigType *type = Getattr(n,"type"); - ParmList *parms = Getattr(n,"parms"); - String *overname = 0; + String *name = Getattr(n, "name"); /* Like to get rid of this */ + String *iname = Getattr(n, "sym:name"); + SwigType *type = Getattr(n, "type"); + ParmList *parms = Getattr(n, "parms"); + String *overname = 0; - Parm *p; - int i; - String *tm; - Wrapper *f; - String *incode, *cleanup, *outarg, *argstr, *args; - int num_arguments = 0; - int num_required = 0; - int varargs = 0; - - char source[64]; - - if (Getattr(n,"sym:overloaded")) { - overname = Getattr(n,"sym:overname"); + Parm *p; + int i; + String *tm; + Wrapper *f; + String *incode, *cleanup, *outarg, *argstr, *args; + int num_arguments = 0; + int num_required = 0; + int varargs = 0; + + char source[64]; + + if (Getattr(n, "sym:overloaded")) { + overname = Getattr(n, "sym:overname"); } else { - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; } - - incode = NewString(""); + + incode = NewString(""); cleanup = NewString(""); - outarg = NewString(""); - argstr = NewString("\""); - args = NewString(""); - + outarg = NewString(""); + argstr = NewString("\""); + args = NewString(""); + f = NewWrapper(); #ifdef SWIG_USE_RESULTOBJ - Wrapper_add_local(f,"resultobj", "Tcl_Obj *resultobj = NULL"); + Wrapper_add_local(f, "resultobj", "Tcl_Obj *resultobj = NULL"); #endif - String *wname = Swig_name_wrapper(iname); + String *wname = Swig_name_wrapper(iname); if (overname) { Append(wname, overname); } - Setattr(n,"wrap:name",wname); + Setattr(n, "wrap:name", wname); + + Printv(f->def, "SWIGINTERN int\n ", wname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", NIL); - Printv(f->def, - "SWIGINTERN int\n ", wname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", - NIL); - /* Print out variables for storing arguments. */ - emit_args(type,parms, f); - + emit_args(type, parms, f); + /* Attach standard typemaps */ - emit_attach_parmmaps(parms,f); - Setattr(n,"wrap:parms",parms); + emit_attach_parmmaps(parms, f); + Setattr(n, "wrap:parms", parms); /* Get number of require and total arguments */ num_arguments = emit_num_arguments(parms); - num_required = emit_num_required(parms); - varargs = emit_isvarargs(parms); - + num_required = emit_num_required(parms); + varargs = emit_isvarargs(parms); + /* Unmarshal parameters */ - + for (i = 0, p = parms; i < num_arguments; i++) { /* Skip ignored arguments */ - - while (checkAttribute(p,"tmap:in:numinputs","0")) { - p = Getattr(p,"tmap:in:next"); + + while (checkAttribute(p, "tmap:in:numinputs", "0")) { + p = Getattr(p, "tmap:in:next"); } - - SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); - + + SwigType *pt = Getattr(p, "type"); + String *ln = Getattr(p, "lname"); + /* Produce string representations of the source and target arguments */ - sprintf(source,"objv[%d]",i+1); - - if (i == num_required) Putc('|',argstr); - if ((tm = Getattr(p,"tmap:in"))) { - String *parse = Getattr(p,"tmap:in:parse"); + sprintf(source, "objv[%d]", i + 1); + + if (i == num_required) + Putc('|', argstr); + if ((tm = Getattr(p, "tmap:in"))) { + String *parse = Getattr(p, "tmap:in:parse"); if (!parse) { - Replaceall(tm,"$target",ln); - Replaceall(tm,"$source",source); - Replaceall(tm,"$input",source); - Setattr(p,"emit:input",source); + Replaceall(tm, "$target", ln); + Replaceall(tm, "$source", source); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); - if (Getattr(p,"wrap:disown") || (Getattr(p,"tmap:in:disown"))) { - Replaceall(tm,"$disown","SWIG_POINTER_DISOWN"); + if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) { + Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); } else { - Replaceall(tm,"$disown","0"); + Replaceall(tm, "$disown", "0"); } - Putc('o',argstr); - Printf(args,",(void *)0"); + Putc('o', argstr); + Printf(args, ",(void *)0"); if (i >= num_required) { - Printf(incode, "if (objc > %d) {\n", i+1); + Printf(incode, "if (objc > %d) {\n", i + 1); } - Printf(incode,"%s\n", tm); + Printf(incode, "%s\n", tm); if (i >= num_required) { Printf(incode, "}\n"); } } else { - Printf(argstr,"%s",parse); - Printf(args,",&%s",ln); - if (Strcmp(parse,"p") == 0) { + Printf(argstr, "%s", parse); + Printf(args, ",&%s", ln); + if (Strcmp(parse, "p") == 0) { SwigType *lt = SwigType_ltype(pt); SwigType_remember(pt); - if (Cmp(lt,"p.void") == 0) { - Printf(args,",(void *)0"); + if (Cmp(lt, "p.void") == 0) { + Printf(args, ",(void *)0"); } else { - Printf(args,",SWIGTYPE%s", SwigType_manglestr(pt)); + Printf(args, ",SWIGTYPE%s", SwigType_manglestr(pt)); } Delete(lt); } } - p = Getattr(p,"tmap:in:next"); + p = Getattr(p, "tmap:in:next"); continue; } else { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument.\n", SwigType_str(pt,0)); + Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); } p = nextSibling(p); } - + if (!varargs) { - Putc(':',argstr); + Putc(':', argstr); } else { - Putc(';',argstr); + Putc(';', argstr); /* If variable length arguments we need to emit the in typemap here */ - if (p && (tm = Getattr(p,"tmap:in"))) { - sprintf(source,"objv[%d]", i+1); - Printf(incode,"if (objc > %d) {\n", i); - Replaceall(tm,"$input",source); - Printv(incode,tm,"\n", NIL); - Printf(incode,"}\n"); + if (p && (tm = Getattr(p, "tmap:in"))) { + sprintf(source, "objv[%d]", i + 1); + Printf(incode, "if (objc > %d) {\n", i); + Replaceall(tm, "$input", source); + Printv(incode, tm, "\n", NIL); + Printf(incode, "}\n"); } } - - Printf(argstr,"%s\"",usage_string(Char(iname),type,parms)); - - Printv(f->code, - "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) SWIG_fail;\n", - NIL); - - Printv(f->code,incode,NIL); - + + Printf(argstr, "%s\"", usage_string(Char(iname), type, parms)); + + Printv(f->code, "if (SWIG_GetArgs(interp, objc, objv,", argstr, args, ") == TCL_ERROR) SWIG_fail;\n", NIL); + + Printv(f->code, incode, NIL); + /* Insert constraint checking code */ for (p = parms; p;) { - if ((tm = Getattr(p,"tmap:check"))) { - Replaceall(tm,"$target",Getattr(p,"lname")); - Printv(f->code,tm,"\n",NIL); - p = Getattr(p,"tmap:check:next"); + if ((tm = Getattr(p, "tmap:check"))) { + Replaceall(tm, "$target", Getattr(p, "lname")); + Printv(f->code, tm, "\n", NIL); + p = Getattr(p, "tmap:check:next"); } else { p = nextSibling(p); } } - + /* Insert cleanup code */ for (i = 0, p = parms; p; i++) { - if (!checkAttribute(p,"tmap:in:numinputs","0") - && !Getattr(p,"tmap:in:parse") && (tm = Getattr(p,"tmap:freearg"))) { + if (!checkAttribute(p, "tmap:in:numinputs", "0") + && !Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { if (Len(tm) != 0) { - Replaceall(tm,"$source",Getattr(p,"lname")); - Printv(cleanup,tm,"\n",NIL); + Replaceall(tm, "$source", Getattr(p, "lname")); + Printv(cleanup, tm, "\n", NIL); } - p = Getattr(p,"tmap:freearg:next"); + p = Getattr(p, "tmap:freearg:next"); } else { p = nextSibling(p); } } - + /* Insert argument output code */ - for (i=0,p = parms; p;i++) { - if ((tm = Getattr(p,"tmap:argout"))) { - Replaceall(tm,"$source",Getattr(p,"lname")); + for (i = 0, p = parms; p; i++) { + if ((tm = Getattr(p, "tmap:argout"))) { + Replaceall(tm, "$source", Getattr(p, "lname")); #ifdef SWIG_USE_RESULTOBJ - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$result","resultobj"); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); #else - Replaceall(tm,"$target","(Tcl_GetObjResult(interp))"); - Replaceall(tm,"$result","(Tcl_GetObjResult(interp))"); + Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))"); + Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))"); #endif - Replaceall(tm,"$arg",Getattr(p,"emit:input")); - Replaceall(tm,"$input",Getattr(p,"emit:input")); - Printv(outarg,tm,"\n",NIL); - p = Getattr(p,"tmap:argout:next"); + Replaceall(tm, "$arg", Getattr(p, "emit:input")); + Replaceall(tm, "$input", Getattr(p, "emit:input")); + Printv(outarg, tm, "\n", NIL); + p = Getattr(p, "tmap:argout:next"); } else { p = nextSibling(p); } } - + /* Now write code to make the function call */ - emit_action(n,f); - + emit_action(n, f); + /* Need to redo all of this code (eventually) */ - + /* Return value if necessary */ - if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { - Replaceall(tm,"$source", "result"); + if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) { + Replaceall(tm, "$source", "result"); #ifdef SWIG_USE_RESULTOBJ - Replaceall(tm,"$target","resultobj"); - Replaceall(tm,"$result","resultobj"); + Replaceall(tm, "$target", "resultobj"); + Replaceall(tm, "$result", "resultobj"); #else - Replaceall(tm,"$target","(Tcl_GetObjResult(interp))"); - Replaceall(tm,"$result","(Tcl_GetObjResult(interp))"); + Replaceall(tm, "$target", "(Tcl_GetObjResult(interp))"); + Replaceall(tm, "$result", "(Tcl_GetObjResult(interp))"); #endif - if(GetFlag(n,"feature:new")) { - Replaceall(tm,"$owner","SWIG_POINTER_OWN"); + if (GetFlag(n, "feature:new")) { + Replaceall(tm, "$owner", "SWIG_POINTER_OWN"); } else { - Replaceall(tm,"$owner","0"); + Replaceall(tm, "$owner", "0"); } - Printf(f->code,"%s\n", tm); + Printf(f->code, "%s\n", tm); } else { - Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, - "Unable to use return type %s in function %s.\n", SwigType_str(type,0), name); + Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(type, 0), name); } - + /* Dump output argument code */ - Printv(f->code,outarg,NIL); - + Printv(f->code, outarg, NIL); + /* Dump the argument cleanup code */ - Printv(f->code,cleanup,NIL); - + Printv(f->code, cleanup, NIL); + /* Look for any remaining cleanup */ - if (GetFlag(n,"feature:new")) { - if ((tm = Swig_typemap_lookup_new("newfree",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n", tm); + if (GetFlag(n, "feature:new")) { + if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } } - - if ((tm = Swig_typemap_lookup_new("ret",n,"result",0))) { - Replaceall(tm,"$source","result"); - Printf(f->code,"%s\n", tm); + + if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) { + Replaceall(tm, "$source", "result"); + Printf(f->code, "%s\n", tm); } #ifdef SWIG_USE_RESULTOBJ Printv(f->code, "if (resultobj) Tcl_SetObjResult(interp, resultobj);\n", NIL); #endif Printv(f->code, "return TCL_OK;\n", NIL); Printv(f->code, "fail:\n", cleanup, "return TCL_ERROR;\n", NIL); - Printv(f->code,"}\n", NIL); - + Printv(f->code, "}\n", NIL); + /* Substitute the cleanup code */ - Replaceall(f->code,"$cleanup",cleanup); - Replaceall(f->code,"$symname", iname); - + Replaceall(f->code, "$cleanup", cleanup); + Replaceall(f->code, "$symname", iname); + /* Dump out the function */ - Wrapper_print(f,f_wrappers); - - if (!Getattr(n,"sym:overloaded")) { + Wrapper_print(f, f_wrappers); + + if (!Getattr(n, "sym:overloaded")) { /* Register the function with Tcl */ Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", Swig_name_wrapper(iname), ", NULL},\n", NIL); } else { - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { /* Emit overloading dispatch function */ int maxargs; - String *dispatch = Swig_overload_dispatch(n,"return %s(clientData, interp, objc, argv - 1);",&maxargs); - + String *dispatch = Swig_overload_dispatch(n, "return %s(clientData, interp, objc, argv - 1);", &maxargs); + /* Generate a dispatch wrapper for all overloaded functions */ - Wrapper *df = NewWrapper(); - String *dname = Swig_name_wrapper(iname); + Wrapper *df = NewWrapper(); + String *dname = Swig_name_wrapper(iname); - Printv(df->def, - "SWIGINTERN int\n", dname, - "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", - NIL); - Printf(df->code,"Tcl_Obj *CONST *argv = objv+1;\n"); - Printf(df->code,"int argc = objc-1;\n"); - Printv(df->code,dispatch,"\n",NIL); - Printf(df->code,"Tcl_SetResult(interp,(char *) \"No matching function for overloaded '%s'\", TCL_STATIC);\n", iname); - Printf(df->code,"return TCL_ERROR;\n"); - Printv(df->code,"}\n",NIL); - Wrapper_print(df,f_wrappers); + Printv(df->def, "SWIGINTERN int\n", dname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {", NIL); + Printf(df->code, "Tcl_Obj *CONST *argv = objv+1;\n"); + Printf(df->code, "int argc = objc-1;\n"); + Printv(df->code, dispatch, "\n", NIL); + Printf(df->code, "Tcl_SetResult(interp,(char *) \"No matching function for overloaded '%s'\", TCL_STATIC);\n", iname); + Printf(df->code, "return TCL_ERROR;\n"); + Printv(df->code, "}\n", NIL); + Wrapper_print(df, f_wrappers); Printv(cmd_tab, tab4, "{ SWIG_prefix \"", iname, "\", (swig_wrapper_func) ", dname, ", NULL},\n", NIL); DelWrapper(df); Delete(dispatch); Delete(dname); } } - + Delete(incode); Delete(cleanup); Delete(outarg); @@ -549,9 +542,9 @@ public: virtual int variableWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - SwigType *t = Getattr(n,"type"); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + SwigType *t = Getattr(n, "type"); String *setname = 0; String *getname = 0; @@ -559,18 +552,19 @@ public: int readonly = 0; String *tm; - if (!addSymbol(iname,n)) return SWIG_ERROR; + if (!addSymbol(iname, n)) + return SWIG_ERROR; - /* Create a function for getting a variable */ + /* Create a function for getting a variable */ int addfail = 0; getf = NewWrapper(); getname = Swig_name_get(iname); - Printv(getf->def,"SWIGINTERN const char *",getname,"(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {",NIL); - Wrapper_add_local(getf,"value", "Tcl_Obj *value = 0"); - if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { - Replaceall(tm,"$source", name); - Replaceall(tm,"$target","value"); - Replaceall(tm,"$result", "value"); + Printv(getf->def, "SWIGINTERN const char *", getname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {", NIL); + Wrapper_add_local(getf, "value", "Tcl_Obj *value = 0"); + if ((tm = Swig_typemap_lookup_new("varout", n, name, 0))) { + Replaceall(tm, "$source", name); + Replaceall(tm, "$target", "value"); + Replaceall(tm, "$result", "value"); /* Printf(getf->code, "%s\n",tm); */ addfail = emit_action_code(n, getf, tm); Printf(getf->code, "if (value) {\n"); @@ -579,67 +573,68 @@ public: Printf(getf->code, "}\n"); Printf(getf->code, "return NULL;\n"); if (addfail) { - Append(getf->code,"fail:\n"); - Printf(getf->code,"return \"%s\";\n", iname); - } - Printf(getf->code,"}\n"); - Wrapper_print(getf,f_wrappers); + Append(getf->code, "fail:\n"); + Printf(getf->code, "return \"%s\";\n", iname); + } + Printf(getf->code, "}\n"); + Wrapper_print(getf, f_wrappers); } else { - Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, - "Unable to read variable of type %s\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t, 0)); DelWrapper(getf); return SWIG_NOWRAP; } DelWrapper(getf); - /* Try to create a function setting a variable */ + /* Try to create a function setting a variable */ if (is_assignable(n)) { setf = NewWrapper(); setname = Swig_name_set(iname); - Printv(setf->def,"SWIGINTERN const char *",setname, "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2 SWIGUNUSED, int flags) {",NIL); - Wrapper_add_local(setf,"value", "Tcl_Obj *value = 0"); - Wrapper_add_local(setf,"name1o", "Tcl_Obj *name1o = 0"); + Printv(setf->def, "SWIGINTERN const char *", setname, + "(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2 SWIGUNUSED, int flags) {", NIL); + Wrapper_add_local(setf, "value", "Tcl_Obj *value = 0"); + Wrapper_add_local(setf, "name1o", "Tcl_Obj *name1o = 0"); if ((tm = Swig_typemap_lookup_new("varin", n, name, 0))) { - Replaceall(tm,"$source","value"); - Replaceall(tm,"$target",name); - Replaceall(tm,"$input", "value"); - Printf(setf->code,"name1o = Tcl_NewStringObj(name1,-1);\n"); - Printf(setf->code,"value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n"); - Printf(setf->code,"Tcl_DecrRefCount(name1o);\n"); - Printf(setf->code,"if (!value) SWIG_fail;\n"); - /* Printf(setf->code,"%s\n", tm);*/ + Replaceall(tm, "$source", "value"); + Replaceall(tm, "$target", name); + Replaceall(tm, "$input", "value"); + Printf(setf->code, "name1o = Tcl_NewStringObj(name1,-1);\n"); + Printf(setf->code, "value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n"); + Printf(setf->code, "Tcl_DecrRefCount(name1o);\n"); + Printf(setf->code, "if (!value) SWIG_fail;\n"); + /* Printf(setf->code,"%s\n", tm); */ emit_action_code(n, setf, tm); - Printf(setf->code,"return NULL;\n"); - Printf(setf->code,"fail:\n"); - Printf(setf->code,"return \"%s\";\n", iname); - Printf(setf->code,"}\n"); - if (setf) Wrapper_print(setf,f_wrappers); + Printf(setf->code, "return NULL;\n"); + Printf(setf->code, "fail:\n"); + Printf(setf->code, "return \"%s\";\n", iname); + Printf(setf->code, "}\n"); + if (setf) + Wrapper_print(setf, f_wrappers); } else { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF,input_file, line_number, - "Unable to set variable of type %s.\n", SwigType_str(t,0)); + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t, 0)); readonly = 1; } DelWrapper(setf); } else { readonly = 1; } - - Printv(var_tab, tab4,"{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getname, ",", NIL); + + Printv(var_tab, tab4, "{ SWIG_prefix \"", iname, "\", 0, (swig_variable_func) ", getname, ",", NIL); if (readonly) { static int readonlywrap = 0; if (!readonlywrap) { Wrapper *ro = NewWrapper(); - Printf(ro->def, "SWIGINTERN const char *swig_readonly(ClientData clientData SWIGUNUSED, Tcl_Interp *interp SWIGUNUSED, char *name1 SWIGUNUSED, char *name2 SWIGUNUSED, int flags SWIGUNUSED) {"); + Printf(ro->def, + "SWIGINTERN const char *swig_readonly(ClientData clientData SWIGUNUSED, Tcl_Interp *interp SWIGUNUSED, char *name1 SWIGUNUSED, char *name2 SWIGUNUSED, int flags SWIGUNUSED) {"); Printv(ro->code, "return \"Variable is read-only\";\n", "}\n", NIL); - Wrapper_print(ro,f_wrappers); + Wrapper_print(ro, f_wrappers); readonlywrap = 1; DelWrapper(ro); } Printf(var_tab, "(swig_variable_func) swig_readonly},\n"); } else { - Printv(var_tab, "(swig_variable_func) ", setname, "},\n",NIL); + Printv(var_tab, "(swig_variable_func) ", setname, "},\n", NIL); } Delete(setname); Delete(getname); @@ -651,40 +646,41 @@ public: * ------------------------------------------------------------ */ virtual int constantWrapper(Node *n) { - String *name = Getattr(n,"name"); - String *iname = Getattr(n,"sym:name"); - String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s",ns_name,iname); - SwigType *type = Getattr(n,"type"); - String *rawval = Getattr(n,"rawval"); - String *value = rawval ? rawval : Getattr(n,"value"); + String *name = Getattr(n, "name"); + String *iname = Getattr(n, "sym:name"); + String *nsname = !nspace ? Copy(iname) : NewStringf("%s::%s", ns_name, iname); + SwigType *type = Getattr(n, "type"); + String *rawval = Getattr(n, "rawval"); + String *value = rawval ? rawval : Getattr(n, "value"); String *tm; - if (!addSymbol(iname,n)) return SWIG_ERROR; - if (nspace) Setattr(n,"sym:name",nsname); + if (!addSymbol(iname, n)) + return SWIG_ERROR; + if (nspace) + Setattr(n, "sym:name", nsname); /* Special hook for member pointer */ if (SwigType_type(type) == T_MPOINTER) { String *wname = Swig_name_wrapper(iname); - Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type,wname), value); + Printf(f_wrappers, "static %s = %s;\n", SwigType_str(type, wname), value); value = Char(wname); } - - if ((tm = Swig_typemap_lookup_new("consttab",n,name,0))) { - Replaceall(tm,"$source",value); - Replaceall(tm,"$target",name); - Replaceall(tm,"$value",value); - Replaceall(tm,"$nsname",nsname); - Printf(const_tab,"%s,\n", tm); + + if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) { + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); + Printf(const_tab, "%s,\n", tm); } else if ((tm = Swig_typemap_lookup_new("constcode", n, name, 0))) { - Replaceall(tm,"$source", value); - Replaceall(tm,"$target", name); - Replaceall(tm,"$value",value); - Replaceall(tm,"$nsname",nsname); + Replaceall(tm, "$source", value); + Replaceall(tm, "$target", name); + Replaceall(tm, "$value", value); + Replaceall(tm, "$nsname", nsname); Printf(f_init, "%s\n", tm); } else { Delete(nsname); - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, - input_file, line_number, "Unsupported constant value.\n"); + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); return SWIG_NOWRAP; } Delete(nsname); @@ -696,11 +692,13 @@ public: * ------------------------------------------------------------ */ virtual int nativeWrapper(Node *n) { - String *name = Getattr(n,"sym:name"); - String *funcname = Getattr(n,"wrap:name"); - if (!addSymbol(funcname,n)) return SWIG_ERROR; + String *name = Getattr(n, "sym:name"); + String *funcname = Getattr(n, "wrap:name"); + if (!addSymbol(funcname, n)) + return SWIG_ERROR; - Printf(f_init,"\t Tcl_CreateObjCommand(interp, SWIG_prefix \"%s\", (swig_wrapper_func) %s, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);\n",name, funcname); + Printf(f_init, "\t Tcl_CreateObjCommand(interp, SWIG_prefix \"%s\", (swig_wrapper_func) %s, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);\n", name, + funcname); return SWIG_OK; } @@ -709,9 +707,9 @@ public: * ------------------------------------------------------------ */ virtual int classHandler(Node *n) { - static Hash* emitted = NewHash(); - String *mangled_classname = 0; - String *real_classname = 0; + static Hash *emitted = NewHash(); + String *mangled_classname = 0; + String *real_classname = 0; have_constructor = 0; have_destructor = 0; @@ -719,11 +717,11 @@ public: if (itcl) { constructor = NewString(""); - destructor = NewString(""); + destructor = NewString(""); base_classes = NewString(""); base_class_init = NewString(""); - methods = NewString(""); - imethods = NewString(""); + methods = NewString(""); + imethods = NewString(""); attributes = NewString(""); attribute_traces = NewString(""); iattribute_traces = NewString(""); @@ -733,38 +731,40 @@ public: have_attributes = 0; } - class_name = Getattr(n,"sym:name"); - if (!addSymbol(class_name,n)) return SWIG_ERROR; + class_name = Getattr(n, "sym:name"); + if (!addSymbol(class_name, n)) + return SWIG_ERROR; - real_classname = Getattr(n,"name"); + real_classname = Getattr(n, "name"); mangled_classname = Swig_name_mangle(real_classname); - if (Getattr(emitted,mangled_classname)) return SWIG_NOWRAP; - Setattr(emitted,mangled_classname,"1"); + if (Getattr(emitted, mangled_classname)) + return SWIG_NOWRAP; + Setattr(emitted, mangled_classname, "1"); attr_tab = NewString(""); Printf(attr_tab, "static swig_attribute swig_"); Printv(attr_tab, mangled_classname, "_attributes[] = {\n", NIL); - + methods_tab = NewStringf(""); - Printf(methods_tab,"static swig_method swig_"); + Printf(methods_tab, "static swig_method swig_"); Printv(methods_tab, mangled_classname, "_methods[] = {\n", NIL); - /* Generate normal wrappers */ + /* Generate normal wrappers */ Language::classHandler(n); - SwigType *t = Copy(Getattr(n,"name")); + SwigType *t = Copy(Getattr(n, "name")); SwigType_add_pointer(t); - + // Catch all: eg. a class with only static functions and/or variables will not have 'remembered' // SwigType_remember(t); String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname); - SwigType_remember_clientdata(t,wrap_class); + SwigType_remember_clientdata(t, wrap_class); // t = Copy(Getattr(n,"classtype")); // SwigType_add_pointer(t); - String *rt = Copy(Getattr(n,"classtype")); + String *rt = Copy(Getattr(n, "classtype")); SwigType_add_pointer(rt); // Register the class structure with the type checker @@ -772,144 +772,133 @@ public: if (have_destructor) { Printv(f_wrappers, "SWIGINTERN void swig_delete_", class_name, "(void *obj) {\n", NIL); if (destructor_action) { - Printv(f_wrappers, SwigType_str(rt,"arg1"), " = (", SwigType_str(rt,0), ") obj;\n", NIL); + Printv(f_wrappers, SwigType_str(rt, "arg1"), " = (", SwigType_str(rt, 0), ") obj;\n", NIL); Printv(f_wrappers, destructor_action, NIL); } else { if (CPlusPlus) { - Printv(f_wrappers," delete (", SwigType_str(rt,0), ") obj;\n",NIL); + Printv(f_wrappers, " delete (", SwigType_str(rt, 0), ") obj;\n", NIL); } else { - Printv(f_wrappers," free((char *) obj);\n",NIL); + Printv(f_wrappers, " free((char *) obj);\n", NIL); } } - Printf(f_wrappers,"}\n"); + Printf(f_wrappers, "}\n"); } - + Printf(methods_tab, " {0,0}\n};\n"); - Printv(f_wrappers,methods_tab,NIL); - + Printv(f_wrappers, methods_tab, NIL); + Printf(attr_tab, " {0,0,0}\n};\n"); - Printv(f_wrappers,attr_tab,NIL); - + Printv(f_wrappers, attr_tab, NIL); + /* Handle inheritance */ - + String *base_class = NewString(""); String *base_class_names = NewString(""); - if( itcl ) { - base_classes = NewString(""); + if (itcl) { + base_classes = NewString(""); } - List *baselist = Getattr(n,"bases"); + List *baselist = Getattr(n, "bases"); if (baselist && Len(baselist)) { Iterator b; int index = 0; b = First(baselist); while (b.item) { String *bname = Getattr(b.item, "name"); - if ((!bname) || GetFlag(b.item,"feature:ignore") || (!Getattr(b.item,"module"))) { + if ((!bname) || GetFlag(b.item, "feature:ignore") || (!Getattr(b.item, "module"))) { b = Next(b); continue; } - if( itcl ) { - have_base_classes = 1; - Printv( base_classes, bname, " ", NIL ); - Printv( base_class_init , " ", bname, "Ptr::constructor $ptr\n", NIL ); - } + if (itcl) { + have_base_classes = 1; + Printv(base_classes, bname, " ", NIL); + Printv(base_class_init, " ", bname, "Ptr::constructor $ptr\n", NIL); + } String *bmangle = Swig_name_mangle(bname); - // Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL); - // Printf(base_class,"&_wrap_class_%s",bmangle); - Printf(base_class,"0"); - Printf(base_class_names,"\"%s *\",", SwigType_namestr(bname)); + // Printv(f_wrappers,"extern swig_class _wrap_class_", bmangle, ";\n", NIL); + // Printf(base_class,"&_wrap_class_%s",bmangle); + Printf(base_class, "0"); + Printf(base_class_names, "\"%s *\",", SwigType_namestr(bname)); /* Put code to register base classes in init function */ - + //Printf(f_init,"/* Register base : %s */\n", bmangle); //Printf(f_init,"swig_%s_bases[%d] = (swig_class *) SWIG_TypeQuery(\"%s *\")->clientdata;\n", mangled_classname, index, SwigType_namestr(bname)); b = Next(b); index++; - Putc(',',base_class); + Putc(',', base_class); Delete(bmangle); } } - - if( itcl ) { + + if (itcl) { String *ptrclass = NewString(""); // First, build the pointer base class - Printv( ptrclass, "itcl::class ", class_name,"Ptr {\n", NIL ); - if( have_base_classes ) - Printv( ptrclass, " inherit ", base_classes, "\n", NIL ); + Printv(ptrclass, "itcl::class ", class_name, "Ptr {\n", NIL); + if (have_base_classes) + Printv(ptrclass, " inherit ", base_classes, "\n", NIL); // Define protected variables for SWIG object pointer - Printv( ptrclass, " protected variable swigobj\n", - " protected variable thisown\n", NIL ); + Printv(ptrclass, " protected variable swigobj\n", " protected variable thisown\n", NIL); // Define public variables - if ( have_attributes ) { - Printv( ptrclass, attributes, NIL ); + if (have_attributes) { + Printv(ptrclass, attributes, NIL); - // base class swig_getset was being called for complex inheritance trees - if ( nspace ) { + // base class swig_getset was being called for complex inheritance trees + if (nspace) { - Printv( ptrclass, - " protected method ", class_name, "_swig_getset {var name1 name2 op} {\n" , NIL ); + Printv(ptrclass, " protected method ", class_name, "_swig_getset {var name1 name2 op} {\n", NIL); - Printv( ptrclass, - " switch -exact -- $op {\n", - " r {set $var [", ns_name, "::", class_name, "_[set var]_get $swigobj]}\n", - " w {", ns_name, "::", class_name, "_${var}_set $swigobj [set $var]}\n", - " }\n", - " }\n" , NIL ); - } else { - Printv( ptrclass, - " protected method ", class_name, "_swig_getset {var name1 name2 op} {\n", - " switch -exact -- $op {\n", - " r {set $var [", class_name, "_[set var]_get $swigobj]}\n", - " w {", class_name, "_${var}_set $swigobj [set $var]}\n", - " }\n", - " }\n", NIL ); - } + Printv(ptrclass, + " switch -exact -- $op {\n", + " r {set $var [", ns_name, "::", class_name, "_[set var]_get $swigobj]}\n", + " w {", ns_name, "::", class_name, "_${var}_set $swigobj [set $var]}\n", " }\n", " }\n", NIL); + } else { + Printv(ptrclass, + " protected method ", class_name, "_swig_getset {var name1 name2 op} {\n", + " switch -exact -- $op {\n", + " r {set $var [", class_name, "_[set var]_get $swigobj]}\n", + " w {", class_name, "_${var}_set $swigobj [set $var]}\n", " }\n", " }\n", NIL); + } } - // Add the constructor, which may include // calls to base class class constructors - Printv( ptrclass, " constructor { ptr } {\n", NIL ); - if( have_base_classes ) { - Printv( ptrclass, base_class_init, NIL ); - Printv( ptrclass, " } {\n", NIL ); + Printv(ptrclass, " constructor { ptr } {\n", NIL); + if (have_base_classes) { + Printv(ptrclass, base_class_init, NIL); + Printv(ptrclass, " } {\n", NIL); } - Printv( ptrclass, " set swigobj $ptr\n", - " set thisown 0\n", NIL ); + Printv(ptrclass, " set swigobj $ptr\n", " set thisown 0\n", NIL); - if( have_attributes ) { - Printv( ptrclass, attribute_traces, NIL ); + if (have_attributes) { + Printv(ptrclass, attribute_traces, NIL); } - Printv( ptrclass, " }\n", NIL ); + Printv(ptrclass, " }\n", NIL); // Add destructor - Printv( ptrclass, " destructor {\n", - " set d_func delete_", class_name, "\n", - " if { $thisown && ([info command $d_func] != \"\") } {\n" - " $d_func $swigobj\n", - " }\n", - " }\n", NIL ); + Printv(ptrclass, " destructor {\n", + " set d_func delete_", class_name, "\n", + " if { $thisown && ([info command $d_func] != \"\") } {\n" " $d_func $swigobj\n", " }\n", " }\n", NIL); // Add methods - if( have_methods ) { - Printv( ptrclass, imethods, NIL ); + if (have_methods) { + Printv(ptrclass, imethods, NIL); }; // Close out the pointer class - Printv( ptrclass, "}\n\n", NIL ); - Printv( f_shadow, ptrclass, NIL ); + Printv(ptrclass, "}\n\n", NIL); + Printv(f_shadow, ptrclass, NIL); // pointer class end - + // Create the "real" class. - Printv( f_shadow, "itcl::class ", class_name," {\n", NIL ); - Printv( f_shadow, " inherit ", class_name,"Ptr\n", NIL ); + Printv(f_shadow, "itcl::class ", class_name, " {\n", NIL); + Printv(f_shadow, " inherit ", class_name, "Ptr\n", NIL); // If we have a constructor, then use it. // If not, then we must have an abstract class without @@ -918,45 +907,45 @@ public: // classes). Note that the constructor must fail before // calling the ptrclass constructor. - if ( have_constructor ) { - Printv( f_shadow, constructor, NIL ); + if (have_constructor) { + Printv(f_shadow, constructor, NIL); } else { - Printv( f_shadow, " constructor { } {\n", NIL ); - Printv( f_shadow, " # This constructor will fail if called directly\n", NIL ); - Printv( f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL ); - Printv( f_shadow, " error \"No constructor for class ", class_name, "\"\n", NIL ); - Printv( f_shadow, " }\n", NIL ); - Printv( f_shadow, " }\n", NIL ); + Printv(f_shadow, " constructor { } {\n", NIL); + Printv(f_shadow, " # This constructor will fail if called directly\n", NIL); + Printv(f_shadow, " if { [info class] == \"::", class_name, "\" } {\n", NIL); + Printv(f_shadow, " error \"No constructor for class ", class_name, "\"\n", NIL); + Printv(f_shadow, " }\n", NIL); + Printv(f_shadow, " }\n", NIL); } - Printv( f_shadow, "}\n\n", NIL ); + Printv(f_shadow, "}\n\n", NIL); }; - Printv(f_wrappers,"static swig_class *swig_",mangled_classname,"_bases[] = {", base_class,"0};\n", NIL); - Printv(f_wrappers,"static char *swig_",mangled_classname,"_base_names[] = {", base_class_names,"0};\n", NIL); + Printv(f_wrappers, "static swig_class *swig_", mangled_classname, "_bases[] = {", base_class, "0};\n", NIL); + Printv(f_wrappers, "static char *swig_", mangled_classname, "_base_names[] = {", base_class_names, "0};\n", NIL); Delete(base_class); Delete(base_class_names); - Printv(f_wrappers, "static swig_class _wrap_class_", mangled_classname, " = { \"", class_name, - "\", &SWIGTYPE", SwigType_manglestr(t), ",",NIL); - + Printv(f_wrappers, "static swig_class _wrap_class_", mangled_classname, " = { \"", class_name, "\", &SWIGTYPE", SwigType_manglestr(t), ",", NIL); + if (have_constructor) { - Printf(f_wrappers,"%s", Swig_name_wrapper(Swig_name_construct(constructor_name))); + Printf(f_wrappers, "%s", Swig_name_wrapper(Swig_name_construct(constructor_name))); Delete(constructor_name); constructor_name = 0; } else { - Printf(f_wrappers,"0"); + Printf(f_wrappers, "0"); } if (have_destructor) { - Printv(f_wrappers, ", swig_delete_", class_name,NIL); + Printv(f_wrappers, ", swig_delete_", class_name, NIL); } else { - Printf(f_wrappers,",0"); + Printf(f_wrappers, ",0"); } - Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname,"_bases,", - "swig_", mangled_classname, "_base_names, &swig_module };\n", NIL); + Printv(f_wrappers, ", swig_", mangled_classname, "_methods, swig_", mangled_classname, "_attributes, swig_", mangled_classname, "_bases,", + "swig_", mangled_classname, "_base_names, &swig_module };\n", NIL); - if( !itcl ) { - Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname, "},\n", NIL); + if (!itcl) { + Printv(cmd_tab, tab4, "{ SWIG_prefix \"", class_name, "\", (swig_wrapper_func) SWIG_ObjectConstructor, (ClientData)&_wrap_class_", mangled_classname, + "},\n", NIL); }; Delete(t); @@ -970,90 +959,90 @@ public: * ------------------------------------------------------------ */ virtual int memberfunctionHandler(Node *n) { - String *name = Getattr(n,"name"); - String *iname = GetChar(n,"sym:name"); + String *name = Getattr(n, "name"); + String *iname = GetChar(n, "sym:name"); - String *realname, *rname; + String *realname, *rname; Language::memberfunctionHandler(n); realname = iname ? iname : name; rname = Swig_name_wrapper(Swig_name_member(class_name, realname)); - if (!Getattr(n,"sym:nextSibling")) { + if (!Getattr(n, "sym:nextSibling")) { Printv(methods_tab, tab4, "{\"", realname, "\", ", rname, "}, \n", NIL); } - if( itcl ) { - ParmList *l = Getattr(n,"parms"); - Parm *p = 0; - String *pname = NewString(""); + if (itcl) { + ParmList *l = Getattr(n, "parms"); + Parm *p = 0; + String *pname = NewString(""); // Add this member to our class handler function - Printv( imethods, tab2, "method ", realname, " [list ", NIL ); + Printv(imethods, tab2, "method ", realname, " [list ", NIL); int pnum = 0; for (p = l; p; p = nextSibling(p)) { - String *pn = Getattr(p,"name"); - String *dv = Getattr(p,"value"); - SwigType *pt = Getattr(p,"type"); + String *pn = Getattr(p, "name"); + String *dv = Getattr(p, "value"); + SwigType *pt = Getattr(p, "type"); - Printv( pname, ",(", pt, ")", NIL ); - Clear( pname ); + Printv(pname, ",(", pt, ")", NIL); + Clear(pname); - /* Only print an argument if not void */ - if (Cmp(pt,"void") != 0) { - if( Len( pn ) > 0 ) { - Printv( pname, pn, NIL ); - } else { - Printf( pname, "p%d", pnum ); - } + /* Only print an argument if not void */ + if (Cmp(pt, "void") != 0) { + if (Len(pn) > 0) { + Printv(pname, pn, NIL); + } else { + Printf(pname, "p%d", pnum); + } - if( Len( dv ) > 0 ) { - String *defval = NewString( dv ); - if( nspace ) { - Insert( defval, 0, "::"); - Insert( defval, 0, ns_name ); - } - if( Strncmp( dv, "(", 1 ) == 0 ) { - Insert( defval, 0, "$"); - Replaceall( defval, "(", ""); - Replaceall( defval, ")", ""); - } - Printv( imethods, "[list ", pname, " ", defval, "] ", NIL ); - } else { - Printv( imethods, pname, " ", NIL ); - } - } - ++pnum; + if (Len(dv) > 0) { + String *defval = NewString(dv); + if (nspace) { + Insert(defval, 0, "::"); + Insert(defval, 0, ns_name); + } + if (Strncmp(dv, "(", 1) == 0) { + Insert(defval, 0, "$"); + Replaceall(defval, "(", ""); + Replaceall(defval, ")", ""); + } + Printv(imethods, "[list ", pname, " ", defval, "] ", NIL); + } else { + Printv(imethods, pname, " ", NIL); + } + } + ++pnum; } - Printv( imethods, "] ", NIL ); + Printv(imethods, "] ", NIL); - if( nspace ) { - Printv( imethods,"{ ", ns_name, "::", class_name, "_", realname, " $swigobj" , NIL ); + if (nspace) { + Printv(imethods, "{ ", ns_name, "::", class_name, "_", realname, " $swigobj", NIL); } else { - Printv( imethods,"{ ", class_name, "_", realname, " $swigobj" , NIL ); + Printv(imethods, "{ ", class_name, "_", realname, " $swigobj", NIL); }; pnum = 0; for (p = l; p; p = nextSibling(p)) { - String *pn = Getattr(p,"name"); - SwigType *pt = Getattr(p,"type"); - Clear( pname ); + String *pn = Getattr(p, "name"); + SwigType *pt = Getattr(p, "type"); + Clear(pname); - /* Only print an argument if not void */ - if (Cmp(pt,"void") != 0) { - if( Len( pn ) > 0 ) { - Printv( pname, pn, NIL ); - } else { - Printf( pname, "p%d", pnum ); - } - Printv( imethods, " $", pname, NIL ); - } - ++pnum; + /* Only print an argument if not void */ + if (Cmp(pt, "void") != 0) { + if (Len(pn) > 0) { + Printv(pname, pn, NIL); + } else { + Printf(pname, "p%d", pnum); + } + Printv(imethods, " $", pname, NIL); + } + ++pnum; } - Printv( imethods, " }\n", NIL ); + Printv(imethods, " }\n", NIL); have_methods = 1; } @@ -1066,28 +1055,27 @@ public: * ------------------------------------------------------------ */ virtual int membervariableHandler(Node *n) { - String *symname = Getattr(n,"sym:name"); - String *rname; - + String *symname = Getattr(n, "sym:name"); + String *rname; + Language::membervariableHandler(n); Printv(attr_tab, tab4, "{ \"-", symname, "\",", NIL); - rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name,symname))); + rname = Swig_name_wrapper(Swig_name_get(Swig_name_member(class_name, symname))); Printv(attr_tab, rname, ", ", NIL); Delete(rname); - if (!GetFlag(n,"feature:immutable")) { - rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name,symname))); - Printv(attr_tab, rname, "},\n",NIL); + if (!GetFlag(n, "feature:immutable")) { + rname = Swig_name_wrapper(Swig_name_set(Swig_name_member(class_name, symname))); + Printv(attr_tab, rname, "},\n", NIL); Delete(rname); } else { Printf(attr_tab, "0 },\n"); } - if( itcl ) { - Printv( attributes, " public variable ", symname, "\n", NIL ); + if (itcl) { + Printv(attributes, " public variable ", symname, "\n", NIL); - Printv( attribute_traces, " trace variable ", symname, - " rw [list ", class_name, "_swig_getset ", symname, "]\n", NIL ); - Printv( attribute_traces, " set ", symname, "\n", NIL ); + Printv(attribute_traces, " trace variable ", symname, " rw [list ", class_name, "_swig_getset ", symname, "]\n", NIL); + Printv(attribute_traces, " set ", symname, "\n", NIL); have_attributes = 1; } @@ -1101,96 +1089,89 @@ public: virtual int constructorHandler(Node *n) { Language::constructorHandler(n); - if( itcl ) { - String *name = Getattr(n,"name"); - String *iname = GetChar(n,"sym:name"); + if (itcl) { + String *name = Getattr(n, "name"); + String *iname = GetChar(n, "sym:name"); - String *realname; + String *realname; - ParmList *l = Getattr(n,"parms"); - Parm *p = 0; + ParmList *l = Getattr(n, "parms"); + Parm *p = 0; String *pname = NewString(""); realname = iname ? iname : name; - if( !have_constructor ) { - // Add this member to our class handler function - Printf( constructor, " constructor { " ); + if (!have_constructor) { + // Add this member to our class handler function + Printf(constructor, " constructor { "); - // Add parameter list - int pnum = 0; - for (p = l; p; p = nextSibling(p)) - { + // Add parameter list + int pnum = 0; + for (p = l; p; p = nextSibling(p)) { - SwigType *pt = Getattr(p,"type"); - String *pn = Getattr(p,"name"); - String *dv = Getattr(p,"value"); - Clear( pname ); + SwigType *pt = Getattr(p, "type"); + String *pn = Getattr(p, "name"); + String *dv = Getattr(p, "value"); + Clear(pname); - /* Only print an argument if not void */ - if (Cmp(pt,"void") != 0) { - if( Len( pn ) > 0 ) { - Printv( pname, pn, NIL ); - } else { - Printf( pname, "p%d", pnum ); - } + /* Only print an argument if not void */ + if (Cmp(pt, "void") != 0) { + if (Len(pn) > 0) { + Printv(pname, pn, NIL); + } else { + Printf(pname, "p%d", pnum); + } - if( Len( dv ) > 0 ) { - Printv( constructor, "{", pname, " {", dv, "} } ", NIL ); - } else { - Printv( constructor, pname, " ", NIL ); - } - } - ++pnum; - } - Printf( constructor, "} { \n" ); + if (Len(dv) > 0) { + Printv(constructor, "{", pname, " {", dv, "} } ", NIL); + } else { + Printv(constructor, pname, " ", NIL); + } + } + ++pnum; + } + Printf(constructor, "} { \n"); - // [BRE] 08/17/00 Added test to see if we are instantiating this object - // type, or, if this constructor is being called as part of the itcl - // inheritance heirarchy. - // In the former case, we need to call the C++ constructor, in the - // latter we don't, or we end up with two C++ objects. - // Check to see if we are instantiating a 'realname' or something - // derived from it. - // - Printv( constructor, " if { [string equal -nocase \"", realname, - "\" \"[namespace tail [info class]]\" ] } {\n", NIL ); + // [BRE] 08/17/00 Added test to see if we are instantiating this object + // type, or, if this constructor is being called as part of the itcl + // inheritance heirarchy. + // In the former case, we need to call the C++ constructor, in the + // latter we don't, or we end up with two C++ objects. + // Check to see if we are instantiating a 'realname' or something + // derived from it. + // + Printv(constructor, " if { [string equal -nocase \"", realname, "\" \"[namespace tail [info class]]\" ] } {\n", NIL); - // Call to constructor wrapper and parent Ptr class - // [BRE] add -namespace/-prefix support - - if( nspace ) { - Printv( constructor, " ", realname, "Ptr::constructor [", - ns_name, "::new_", realname, NIL ); - } else { - Printv( constructor, " ", realname, "Ptr::constructor [new_", realname, NIL ); - } + // Call to constructor wrapper and parent Ptr class + // [BRE] add -namespace/-prefix support - pnum = 0; - for (p = l; p; p = nextSibling(p)) { + if (nspace) { + Printv(constructor, " ", realname, "Ptr::constructor [", ns_name, "::new_", realname, NIL); + } else { + Printv(constructor, " ", realname, "Ptr::constructor [new_", realname, NIL); + } - SwigType *pt = Getattr(p,"type"); - String *pn = Getattr(p,"name"); - Clear( pname ); + pnum = 0; + for (p = l; p; p = nextSibling(p)) { - /* Only print an argument if not void */ - if (Cmp(pt,"void") != 0) { - if( Len( pn ) > 0 ) { - Printv( pname, pn, NIL ); - } else { - Printf( pname, "p%d", pnum ); - } - Printv( constructor, " $", pname, NIL ); - } - ++pnum; - } + SwigType *pt = Getattr(p, "type"); + String *pn = Getattr(p, "name"); + Clear(pname); - Printv( constructor, "]\n", - " }\n", - " } {\n", - " set thisown 1\n", - " }\n", NIL ); + /* Only print an argument if not void */ + if (Cmp(pt, "void") != 0) { + if (Len(pn) > 0) { + Printv(pname, pn, NIL); + } else { + Printf(pname, "p%d", pnum); + } + Printv(constructor, " $", pname, NIL); + } + ++pnum; + } + + Printv(constructor, "]\n", " }\n", " } {\n", " set thisown 1\n", " }\n", NIL); } } @@ -1206,7 +1187,7 @@ public: virtual int destructorHandler(Node *n) { Language::destructorHandler(n); have_destructor = 1; - destructor_action = Getattr(n,"wrap:action"); + destructor_action = Getattr(n, "wrap:action"); return SWIG_OK; } @@ -1215,7 +1196,8 @@ public: * ------------------------------------------------------------ */ virtual int validIdentifier(String *s) { - if (Strchr(s,' ')) return 0; + if (Strchr(s, ' ')) + return 0; return 1; } @@ -1223,38 +1205,39 @@ public: * usage_string() * ------------------------------------------------------------ */ - char * - usage_string(char *iname, SwigType *, ParmList *l) { + char *usage_string(char *iname, SwigType *, ParmList *l) { static String *temp = 0; - Parm *p; - int i, numopt,pcount; - - if (!temp) temp = NewString(""); + Parm *p; + int i, numopt, pcount; + + if (!temp) + temp = NewString(""); Clear(temp); if (nspace) { - Printf(temp,"%s::%s ", ns_name,iname); + Printf(temp, "%s::%s ", ns_name, iname); } else { - Printf(temp,"%s ", iname); + Printf(temp, "%s ", iname); } /* Now go through and print parameters */ i = 0; pcount = emit_num_arguments(l); numopt = pcount - emit_num_required(l); for (p = l; p; p = nextSibling(p)) { - - SwigType *pt = Getattr(p,"type"); - String *pn = Getattr(p,"name"); - /* Only print an argument if not ignored */ - if (!checkAttribute(p,"tmap:in:numinputs","0")) { - if (i >= (pcount-numopt)) - Putc('?',temp); + + SwigType *pt = Getattr(p, "type"); + String *pn = Getattr(p, "name"); + /* Only print an argument if not ignored */ + if (!checkAttribute(p, "tmap:in:numinputs", "0")) { + if (i >= (pcount - numopt)) + Putc('?', temp); if (Len(pn) > 0) { - Printf(temp, "%s",pn); + Printf(temp, "%s", pn); } else { - Printf(temp,"%s", SwigType_str(pt,0)); + Printf(temp, "%s", SwigType_str(pt, 0)); } - if (i >= (pcount-numopt)) Putc('?',temp); - Putc(' ',temp); + if (i >= (pcount - numopt)) + Putc('?', temp); + Putc(' ', temp); i++; } } @@ -1284,7 +1267,7 @@ public: Append(s, srun); Delete(srun); } - + return s; } @@ -1297,13 +1280,9 @@ public: * swig_tcl() - Instantiate module * ---------------------------------------------------------------------- */ -static Language * new_swig_tcl() { +static Language *new_swig_tcl() { return new TCL8(); } -extern "C" Language * swig_tcl(void) { +extern "C" Language *swig_tcl(void) { return new_swig_tcl(); } - - - - diff --git a/SWIG/Source/Modules/typepass.cxx b/SWIG/Source/Modules/typepass.cxx index 2a5c2dc98..b4ac87411 100644 --- a/SWIG/Source/Modules/typepass.cxx +++ b/SWIG/Source/Modules/typepass.cxx @@ -18,48 +18,47 @@ char cvsroot_typepass_cxx[] = "$Header$"; #include "cparse.h" struct normal_node { - Symtab *symtab; - Hash *typescope; - List *normallist; - normal_node *next; + Symtab *symtab; + Hash *typescope; + List *normallist; + normal_node *next; }; static normal_node *patch_list = 0; /* Singleton class - all non-static methods in this class are private */ -class TypePass : private Dispatcher { - Node *inclass; - Node *module; - int importmode; +class TypePass:private Dispatcher { + Node *inclass; + Node *module; + int importmode; String *nsname; - Hash *classhash; - List *normalize; + Hash *classhash; + List *normalize; TypePass() { } /* Normalize a type. Replaces type with fully qualified version */ - void normalize_type(SwigType *ty) { SwigType *qty; if (CPlusPlus) { - Replaceall(ty,"struct ",""); - Replaceall(ty,"union ",""); - Replaceall(ty,"class ",""); + Replaceall(ty, "struct ", ""); + Replaceall(ty, "union ", ""); + Replaceall(ty, "class ", ""); } qty = SwigType_typedef_qualified(ty); /* Printf(stdout,"%s --> %s\n", ty, qty); */ Clear(ty); - Append(ty,qty); + Append(ty, qty); Delete(qty); } - + /* Normalize a parameter list */ - + void normalize_parms(ParmList *p) { while (p) { - SwigType *ty = Getattr(p,"type"); + SwigType *ty = Getattr(p, "type"); normalize_type(ty); /* This is a check for a function type */ { @@ -70,22 +69,22 @@ class TypePass : private Dispatcher { Delete(qty); } - String *value = Getattr(p,"value"); + String *value = Getattr(p, "value"); if (value) { - Node *n = Swig_symbol_clookup(value,0); + Node *n = Swig_symbol_clookup(value, 0); if (n) { String *q = Swig_symbol_qualified(n); if (q && Len(q)) { String *vb = Swig_scopename_last(value); Clear(value); - Printf(value,"%s::%s", SwigType_namestr(q), vb); + Printf(value, "%s::%s", SwigType_namestr(q), vb); Delete(q); } } } if (value && SwigType_istemplate(value)) { String *nv = SwigType_namestr(value); - Setattr(p,"value",nv); + Setattr(p, "value", nv); } p = nextSibling(p); } @@ -93,8 +92,8 @@ class TypePass : private Dispatcher { void normalize_later(ParmList *p) { while (p) { - SwigType *ty = Getattr(p,"type"); - Append(normalize,ty); + SwigType *ty = Getattr(p, "type"); + Append(normalize, ty); p = nextSibling(p); } } @@ -121,29 +120,29 @@ class TypePass : private Dispatcher { } /* generate C++ inheritance type-relationships */ - void cplus_inherit_types_impl(Node *first, Node *cls, String*clsname, - const char *bases, const char *baselist, - int ispublic, String *cast = 0) { - - if (first == cls) return; /* The Marcelo check */ - if (!cls) cls = first; + void cplus_inherit_types_impl(Node *first, Node *cls, String *clsname, const char *bases, const char *baselist, int ispublic, String *cast = 0) { + + if (first == cls) + return; /* The Marcelo check */ + if (!cls) + cls = first; List *alist = 0; - List *ilist = Getattr(cls,bases); + List *ilist = Getattr(cls, bases); if (!ilist) { - List *nlist = Getattr(cls,baselist); + List *nlist = Getattr(cls, baselist); if (nlist) { - int len = Len(nlist); + int len = Len(nlist); int i; for (i = 0; i < len; i++) { Node *bcls = 0; - int clsforward = 0; - String *bname = Getitem(nlist,i); + int clsforward = 0; + String *bname = Getitem(nlist, i); String *sname = bname; String *tname = 0; /* Try to locate the base class. We look in the symbol table and we chase typedef declarations to get to the base class if necessary */ - Symtab *st = Getattr(cls,"sym:symtab"); + Symtab *st = Getattr(cls, "sym:symtab"); if (SwigType_istemplate(bname)) { tname = SwigType_typedef_resolve_all(bname); @@ -151,76 +150,82 @@ class TypePass : private Dispatcher { } while (1) { String *qsname = SwigType_typedef_qualified(sname); - bcls = Swig_symbol_clookup(qsname,st); + bcls = Swig_symbol_clookup(qsname, st); Delete(qsname); if (bcls) { - if (Strcmp(nodeType(bcls),"class") != 0) { - /* Not a class. The symbol could be a typedef. */ - if (checkAttribute(bcls,"storage","typedef")) { - SwigType *decl = Getattr(bcls,"decl"); + if (Strcmp(nodeType(bcls), "class") != 0) { + /* Not a class. The symbol could be a typedef. */ + if (checkAttribute(bcls, "storage", "typedef")) { + SwigType *decl = Getattr(bcls, "decl"); if (!decl || !(Len(decl))) { - sname = Getattr(bcls,"type"); - st = Getattr(bcls,"sym:symtab"); + sname = Getattr(bcls, "type"); + st = Getattr(bcls, "sym:symtab"); if (SwigType_istemplate(sname)) { - if (tname) Delete(tname); + if (tname) + Delete(tname); tname = SwigType_typedef_resolve_all(sname); sname = tname; } continue; - } + } } - if (Strcmp(nodeType(bcls),"classforward") != 0) { - Swig_error(Getfile(cls),Getline(cls),"'%s' does not have a valid base class.\n", Getattr(cls,"name")); - Swig_error(Getfile(bcls),Getline(bcls),"'%s' is not a valid base class.\n", bname); + if (Strcmp(nodeType(bcls), "classforward") != 0) { + Swig_error(Getfile(cls), Getline(cls), "'%s' does not have a valid base class.\n", Getattr(cls, "name")); + Swig_error(Getfile(bcls), Getline(bcls), "'%s' is not a valid base class.\n", bname); } else { - Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(cls),Getline(cls),"Base class '%s' is incomplete.\n", bname); - Swig_warning(WARN_TYPE_INCOMPLETE,Getfile(bcls),Getline(bcls),"Only forward declaration '%s' was found.\n", bname); + Swig_warning(WARN_TYPE_INCOMPLETE, Getfile(cls), Getline(cls), "Base class '%s' is incomplete.\n", bname); + Swig_warning(WARN_TYPE_INCOMPLETE, Getfile(bcls), Getline(bcls), "Only forward declaration '%s' was found.\n", bname); clsforward = 1; } bcls = 0; } else { - if (Getattr(bcls,"typepass:visit")) { - if (!ilist) ilist = alist = NewList(); - Append(ilist,bcls); + if (Getattr(bcls, "typepass:visit")) { + if (!ilist) + ilist = alist = NewList(); + Append(ilist, bcls); } else { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(cls),Getline(cls),"Base class '%s' undefined.\n", bname); - Swig_warning(WARN_TYPE_UNDEFINED_CLASS,Getfile(bcls),Getline(bcls),"'%s' must be defined before it is used as a base class.\n", bname); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Base class '%s' undefined.\n", bname); + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(bcls), Getline(bcls), "'%s' must be defined before it is used as a base class.\n", bname); } } } break; } - if (tname) Delete(tname); + if (tname) + Delete(tname); if (!bcls) { if (!clsforward) { - if (ispublic && !Getmeta(bname,"already_warned")) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls),Getline(cls),"Nothing known about base class '%s'. Ignored.\n", SwigType_namestr(bname)); - if (Strchr(bname,'<')) { - Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Maybe you forgot to instantiate '%s' using %%template.\n", SwigType_namestr(bname)); + if (ispublic && !Getmeta(bname, "already_warned")) { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Nothing known about base class '%s'. Ignored.\n", SwigType_namestr(bname)); + if (Strchr(bname, '<')) { + Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(cls), Getline(cls), "Maybe you forgot to instantiate '%s' using %%template.\n", + SwigType_namestr(bname)); } - Setmeta(bname,"already_warned","1"); + Setmeta(bname, "already_warned", "1"); } } - SwigType_inherit(clsname,bname, cast); + SwigType_inherit(clsname, bname, cast); } } } if (ilist) { - Setattr(cls,bases,ilist); + Setattr(cls, bases, ilist); } } - if (alist) Delete(alist); + if (alist) + Delete(alist); - if (!ilist) return; + if (!ilist) + return; int len = Len(ilist); int i; for (i = 0; i < len; i++) { - Node *n = Getitem(ilist,i); - String *bname = Getattr(n,"name"); - Node *bclass = n; /* Getattr(n,"class"); */ - Hash *scopes = Getattr(bclass,"typescope"); - SwigType_inherit(clsname,bname, cast); + Node *n = Getitem(ilist, i); + String *bname = Getattr(n, "name"); + Node *bclass = n; /* Getattr(n,"class"); */ + Hash *scopes = Getattr(bclass, "typescope"); + SwigType_inherit(clsname, bname, cast); if (!importmode) { String *btype = Copy(bname); SwigType_add_pointer(btype); @@ -231,11 +236,10 @@ class TypePass : private Dispatcher { SwigType_inherit_scope(scopes); } /* Set up inheritance in the symbol table */ - Symtab *st = Getattr(cls,"symtab"); - Symtab *bst = Getattr(bclass,"symtab"); + Symtab *st = Getattr(cls, "symtab"); + Symtab *bst = Getattr(bclass, "symtab"); if (st == bst) { - Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls), - "Recursive scope inheritance of '%s'.\n", HashGetAttr(cls,k_name)); + Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(cls), Getline(cls), "Recursive scope inheritance of '%s'.\n", HashGetAttr(cls, k_name)); continue; } Symtab *s = Swig_symbol_current(); @@ -244,10 +248,10 @@ class TypePass : private Dispatcher { Swig_symbol_setscope(s); /* Recursively hit base classes */ - String *namestr = SwigType_namestr(Getattr(bclass,"name")); + String *namestr = SwigType_namestr(Getattr(bclass, "name")); String *newcast = NewStringf("(%s *)%s", namestr, cast); Delete(namestr); - cplus_inherit_types_impl(first,bclass,clsname,bases,baselist,ispublic,newcast); + cplus_inherit_types_impl(first, bclass, clsname, bases, baselist, ispublic, newcast); Delete(newcast); } } @@ -255,39 +259,40 @@ class TypePass : private Dispatcher { void append_list(List *lb, List *la) { if (la && lb) { for (Iterator bi = First(la); bi.item; bi = Next(bi)) { - Append(lb,bi.item); + Append(lb, bi.item); } } } void cplus_inherit_types(Node *first, Node *cls, String *clsname, String *cast = 0) { cplus_inherit_types_impl(first, cls, clsname, "bases", "baselist", 1, cast); - cplus_inherit_types_impl(first, cls, clsname, "protectedbases","protectedbaselist", 0, cast); - cplus_inherit_types_impl(first, cls, clsname, "privatebases" ,"privatebaselist", 0, cast); + cplus_inherit_types_impl(first, cls, clsname, "protectedbases", "protectedbaselist", 0, cast); + cplus_inherit_types_impl(first, cls, clsname, "privatebases", "privatebaselist", 0, cast); - if (!cls) cls = first; + if (!cls) + cls = first; List *allbases = NewList(); - append_list(allbases,Getattr(cls,"bases")); - append_list(allbases,Getattr(cls,"protectedbases")); - append_list(allbases,Getattr(cls,"privatebases")); + append_list(allbases, Getattr(cls, "bases")); + append_list(allbases, Getattr(cls, "protectedbases")); + append_list(allbases, Getattr(cls, "privatebases")); if (Len(allbases)) { - Setattr(cls,"allbases",allbases); + Setattr(cls, "allbases", allbases); } Delete(allbases); } /* ------------------------------------------------------------ * top() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int top(Node *n) { importmode = 0; - module = Getattr(n,"module"); + module = Getattr(n, "module"); inclass = 0; normalize = 0; nsname = 0; - classhash = Getattr(n,"classes"); + classhash = Getattr(n, "classes"); emit_children(n); normalize_list(); SwigType_set_scope(0); @@ -297,7 +302,7 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * moduleDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int moduleDirective(Node *n) { if (!module) { @@ -308,14 +313,14 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * importDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ - virtual int importDirective(Node *n) { + virtual int importDirective(Node *n) { String *oldmodule = module; int oldimport = importmode; importmode = 1; module = 0; - emit_children(n); + emit_children(n); importmode = oldimport; module = oldmodule; return SWIG_OK; @@ -325,24 +330,30 @@ class TypePass : private Dispatcher { * includeDirective() * externDirective() * extendDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ - virtual int includeDirective(Node *n) { return emit_children(n); } - virtual int externDeclaration(Node *n) { return emit_children(n); } - virtual int extendDirective(Node *n) { return emit_children(n); } + virtual int includeDirective(Node *n) { + return emit_children(n); + } + virtual int externDeclaration(Node *n) { + return emit_children(n); + } + virtual int extendDirective(Node *n) { + return emit_children(n); + } /* ------------------------------------------------------------ * classDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int classDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *tdname = Getattr(n,"tdname"); - String *unnamed = Getattr(n,"unnamed"); - String *storage = Getattr(n,"storage"); - String *kind = Getattr(n,"kind"); - Node *oldinclass = inclass; - List *olist = normalize; + String *name = Getattr(n, "name"); + String *tdname = Getattr(n, "tdname"); + String *unnamed = Getattr(n, "unnamed"); + String *storage = Getattr(n, "storage"); + String *kind = Getattr(n, "kind"); + Node *oldinclass = inclass; + List *olist = normalize; Symtab *symtab; String *nname = 0; String *fname = 0; @@ -355,25 +366,21 @@ class TypePass : private Dispatcher { // We need to fully resolve the name to make templates work correctly */ Node *cn; fname = SwigType_typedef_resolve_all(name); - if (Strcmp(fname,name) != 0 && (cn = Swig_symbol_clookup_local(fname,0))) { - if ((n == cn) - || (Strcmp(nodeType(cn),"template") == 0) - || (Getattr(cn,"feature:onlychildren") != 0) - || (Getattr(n,"feature:onlychildren") != 0)) { - Swig_symbol_cadd(fname,n); + if (Strcmp(fname, name) != 0 && (cn = Swig_symbol_clookup_local(fname, 0))) { + if ((n == cn) + || (Strcmp(nodeType(cn), "template") == 0) + || (Getattr(cn, "feature:onlychildren") != 0) + || (Getattr(n, "feature:onlychildren") != 0)) { + Swig_symbol_cadd(fname, n); SwigType_typedef_class(fname); scopename = Copy(fname); } else { - Swig_warning(WARN_TYPE_REDEFINED,Getfile(n),Getline(n), - "Template '%s' was already wrapped,\n", - SwigType_namestr(name)); - Swig_warning(WARN_TYPE_REDEFINED,Getfile(cn), Getline(cn), - "previous wrap of '%s'.\n", - SwigType_namestr(Getattr(cn,"name"))); + Swig_warning(WARN_TYPE_REDEFINED, Getfile(n), Getline(n), "Template '%s' was already wrapped,\n", SwigType_namestr(name)); + Swig_warning(WARN_TYPE_REDEFINED, Getfile(cn), Getline(cn), "previous wrap of '%s'.\n", SwigType_namestr(Getattr(cn, "name"))); scopename = 0; } } else { - Swig_symbol_cadd(fname,n); + Swig_symbol_cadd(fname, n); SwigType_typedef_class(fname); scopename = Copy(fname); } @@ -389,46 +396,46 @@ class TypePass : private Dispatcher { scopename = 0; } - Setattr(n,"typepass:visit","1"); + Setattr(n, "typepass:visit", "1"); /* Need to set up a typedef if unnamed */ - if (unnamed && tdname && (Cmp(storage,"typedef") == 0)) { - SwigType_typedef(unnamed,tdname); + if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) { + SwigType_typedef(unnamed, tdname); } if (nsname) { nname = NewStringf("%s::%s", nsname, name); - String *tdname = Getattr(n,"tdname"); + String *tdname = Getattr(n, "tdname"); if (tdname) { tdname = NewStringf("%s::%s", nsname, tdname); - Setattr(n,"tdname",tdname); + Setattr(n, "tdname", tdname); } - } + } SwigType_new_scope(scopename); - SwigType_attach_symtab(Getattr(n,"symtab")); + SwigType_attach_symtab(Getattr(n, "symtab")); /* Inherit type definitions into the class */ if (name) { cplus_inherit_types(n, 0, nname ? nname : (fname ? fname : name)); } - + inclass = n; - symtab = Swig_symbol_setscope(Getattr(n,"symtab")); + symtab = Swig_symbol_setscope(Getattr(n, "symtab")); emit_children(n); Swig_symbol_setscope(symtab); Hash *ts = SwigType_pop_scope(); - Setattr(n,"typescope",ts); + Setattr(n, "typescope", ts); Delete(ts); - Setattr(n,"module",module); + Setattr(n, "module", module); /* Normalize deferred types */ { normal_node *nn = new normal_node(); nn->normallist = normalize; - nn->symtab = Getattr(n,"symtab"); + nn->symtab = Getattr(n, "symtab"); nn->next = patch_list; - nn->typescope = Getattr(n,"typescope"); + nn->typescope = Getattr(n, "typescope"); patch_list = nn; } @@ -438,7 +445,7 @@ class TypePass : private Dispatcher { /* If in a namespace, patch the class name */ if (nname) { - Setattr(n,"name",nname); + Setattr(n, "name", nname); Delete(nname); } return SWIG_OK; @@ -446,41 +453,41 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * namespaceDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int templateDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *ttype = Getattr(n,"templatetype"); - if (Strcmp(ttype,"class") == 0) { + String *name = Getattr(n, "name"); + String *ttype = Getattr(n, "templatetype"); + if (Strcmp(ttype, "class") == 0) { String *rname = SwigType_typedef_resolve_all(name); SwigType_typedef_class(rname); Delete(rname); - } else if (Strcmp(ttype,"classforward") == 0) { + } else if (Strcmp(ttype, "classforward") == 0) { String *rname = SwigType_typedef_resolve_all(name); SwigType_typedef_class(rname); Delete(rname); - /* SwigType_typedef_class(name);*/ + /* SwigType_typedef_class(name); */ } return SWIG_OK; } /* ------------------------------------------------------------ * classforwardDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int classforwardDeclaration(Node *n) { /* Temporary hack. Can't do inside a class because it breaks C nested structure wrapping */ - if ((!inclass) || (CPlusPlus)) { - String *name = Getattr(n,"name"); + if ((!inclass) || (CPlusPlus)) { + String *name = Getattr(n, "name"); String *nname; SwigType_typedef_class(name); if (nsname) { nname = NewStringf("%s::%s", nsname, name); - Setattr(n,"name",nname); - } + Setattr(n, "name", nname); + } } return SWIG_OK; @@ -488,48 +495,48 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * namespaceDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int namespaceDeclaration(Node *n) { Symtab *symtab; - String *name = Getattr(n,"name"); - String *alias = Getattr(n,"alias"); - List *olist = normalize; - normalize = NewList(); + String *name = Getattr(n, "name"); + String *alias = Getattr(n, "alias"); + List *olist = normalize; + normalize = NewList(); if (alias) { - Typetab *ts = Getattr(n,"typescope"); + Typetab *ts = Getattr(n, "typescope"); if (!ts) { Node *ns; /* Create a empty scope for the alias */ - ns = Getattr(n,"namespace"); + ns = Getattr(n, "namespace"); if (ns) { - SwigType_scope_alias(name, Getattr(ns,"typescope")); + SwigType_scope_alias(name, Getattr(ns, "typescope")); } - ts = Getattr(ns,"typescope"); - Setattr(n,"typescope",ts); + ts = Getattr(ns, "typescope"); + Setattr(n, "typescope", ts); } /* Namespace alias */ return SWIG_OK; } else { if (name) { - Node *nn = Swig_symbol_clookup(name,n); - Hash *ts = Getattr(nn,"typescope"); + Node *nn = Swig_symbol_clookup(name, n); + Hash *ts = Getattr(nn, "typescope"); if (!ts) { SwigType_new_scope(name); - SwigType_attach_symtab(Getattr(n,"symtab")); + SwigType_attach_symtab(Getattr(n, "symtab")); } else { SwigType_set_scope(ts); } } String *oldnsname = nsname; - nsname = Swig_symbol_qualified(Getattr(n,"symtab")); - symtab = Swig_symbol_setscope(Getattr(n,"symtab")); + nsname = Swig_symbol_qualified(Getattr(n, "symtab")); + symtab = Swig_symbol_setscope(Getattr(n, "symtab")); emit_children(n); Swig_symbol_setscope(symtab); if (name) { Hash *ts = SwigType_pop_scope(); - Setattr(n,"typescope",ts); + Setattr(n, "typescope", ts); Delete(ts); } @@ -537,9 +544,9 @@ class TypePass : private Dispatcher { { normal_node *nn = new normal_node(); nn->normallist = normalize; - nn->symtab = Getattr(n,"symtab"); + nn->symtab = Getattr(n, "symtab"); nn->next = patch_list; - nn->typescope = Getattr(n,"typescope"); + nn->typescope = Getattr(n, "typescope"); patch_list = nn; } normalize = olist; @@ -552,57 +559,57 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * cDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int cDeclaration(Node *n) { if (NoExcept) { - Delattr(n,"throws"); + Delattr(n, "throws"); } /* Normalize types. */ - SwigType *ty = Getattr(n,"type"); + SwigType *ty = Getattr(n, "type"); normalize_type(ty); - SwigType *decl = Getattr(n,"decl"); + SwigType *decl = Getattr(n, "decl"); if (decl) { normalize_type(decl); } - normalize_parms(Getattr(n,"parms")); - normalize_parms(Getattr(n,"throws")); + normalize_parms(Getattr(n, "parms")); + normalize_parms(Getattr(n, "throws")); - if (checkAttribute(n,"storage","typedef")) { - String *name = Getattr(n,"name"); - ty = Getattr(n,"type"); - decl = Getattr(n,"decl"); + if (checkAttribute(n, "storage", "typedef")) { + String *name = Getattr(n, "name"); + ty = Getattr(n, "type"); + decl = Getattr(n, "decl"); SwigType *t = Copy(ty); { /* If the typename is qualified, make sure the scopename is fully qualified when making a typedef */ - if (Swig_scopename_check(t) && strncmp(Char(t),"::",2)) { + if (Swig_scopename_check(t) && strncmp(Char(t), "::", 2)) { String *base, *prefix, *qprefix; base = Swig_scopename_last(t); prefix = Swig_scopename_prefix(t); qprefix = SwigType_typedef_qualified(prefix); Delete(t); - t = NewStringf("%s::%s", qprefix,base); + t = NewStringf("%s::%s", qprefix, base); Delete(base); Delete(prefix); Delete(qprefix); } } - SwigType_push(t,decl); + SwigType_push(t, decl); if (CPlusPlus) { - Replaceall(t,"struct ",""); - Replaceall(t,"union ",""); - Replaceall(t,"class ",""); + Replaceall(t, "struct ", ""); + Replaceall(t, "union ", ""); + Replaceall(t, "class ", ""); } - SwigType_typedef(t,name); - } + SwigType_typedef(t, name); + } /* If namespaces are active. We need to patch the name with a namespace prefix */ if (nsname && !inclass) { - String *name = Getattr(n,"name"); + String *name = Getattr(n, "name"); if (name) { String *nname = NewStringf("%s::%s", nsname, name); - Setattr(n,"name", nname); + Setattr(n, "name", nname); Delete(nname); } } @@ -613,46 +620,46 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * constructorDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int constructorDeclaration(Node *n) { if (NoExcept) { - Delattr(n,"throws"); + Delattr(n, "throws"); } - normalize_parms(Getattr(n,"parms")); - normalize_parms(Getattr(n,"throws")); - + normalize_parms(Getattr(n, "parms")); + normalize_parms(Getattr(n, "throws")); + /* If in a namespace, patch the class name */ if (nsname) { - String *nname = NewStringf("%s::%s", nsname, Getattr(n,"name")); - Setattr(n,"name",nname); + String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name")); + Setattr(n, "name", nname); } clean_overloaded(n); return SWIG_OK; } - + /* ------------------------------------------------------------ * destructorDeclaration() - * ------------------------------------------------------------ */ - + * ------------------------------------------------------------ */ + virtual int destructorDeclaration(Node *n) { /* If in a namespace, patch the class name */ if (nsname) { - String *nname = NewStringf("%s::%s", nsname, Getattr(n,"name")); - Setattr(n,"name",nname); + String *nname = NewStringf("%s::%s", nsname, Getattr(n, "name")); + Setattr(n, "name", nname); } return SWIG_OK; } - + /* ------------------------------------------------------------ * constantDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int constantDirective(Node *n) { - SwigType *ty = Getattr(n,"type"); + SwigType *ty = Getattr(n, "type"); if (ty) { - Setattr(n,"type",SwigType_typedef_qualified(ty)); + Setattr(n, "type", SwigType_typedef_qualified(ty)); } return SWIG_OK; } @@ -660,10 +667,10 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * enumDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int enumDeclaration(Node *n) { - String *name = Getattr(n,"name"); + String *name = Getattr(n, "name"); if (name) { String *scope = 0; @@ -671,48 +678,48 @@ class TypePass : private Dispatcher { // Add a typedef to the type table so that we can use 'enum Name' as well as just 'Name' if (nsname || inclass) { - // But first correct the name and tdname to contain the fully qualified scopename - if (nsname && inclass) { - scope = NewStringf("%s::%s", nsname, Getattr(inclass,"name")); - } else if (nsname) { - scope = NewStringf("%s", nsname); - } else if (inclass) { - scope = NewStringf("%s", Getattr(inclass,"name")); - } + // But first correct the name and tdname to contain the fully qualified scopename + if (nsname && inclass) { + scope = NewStringf("%s::%s", nsname, Getattr(inclass, "name")); + } else if (nsname) { + scope = NewStringf("%s", nsname); + } else if (inclass) { + scope = NewStringf("%s", Getattr(inclass, "name")); + } - String *nname = NewStringf("%s::%s", scope, name); - Setattr(n,"name",nname); + String *nname = NewStringf("%s::%s", scope, name); + Setattr(n, "name", nname); - String *tdname = Getattr(n,"tdname"); - if (tdname) { - tdname = NewStringf("%s::%s", scope, tdname); - Setattr(n,"tdname",tdname); - } + String *tdname = Getattr(n, "tdname"); + if (tdname) { + tdname = NewStringf("%s::%s", scope, tdname); + Setattr(n, "tdname", tdname); + } - SwigType *t = NewStringf("enum %s", nname); - SwigType_typedef(t,name); + SwigType *t = NewStringf("enum %s", nname); + SwigType_typedef(t, name); } else { - SwigType *t = NewStringf("enum %s", name); - SwigType_typedef(t,name); + SwigType *t = NewStringf("enum %s", name); + SwigType_typedef(t, name); } Delete(scope); } - String *tdname = Getattr(n,"tdname"); - String *unnamed = Getattr(n,"unnamed"); - String *storage = Getattr(n,"storage"); + String *tdname = Getattr(n, "tdname"); + String *unnamed = Getattr(n, "unnamed"); + String *storage = Getattr(n, "storage"); // Construct enumtype - for declaring an enum of this type with SwigType_ltype() etc String *enumtype = 0; - if (unnamed && tdname && (Cmp(storage,"typedef") == 0)) { - enumtype = Copy(Getattr(n,"tdname")); + if (unnamed && tdname && (Cmp(storage, "typedef") == 0)) { + enumtype = Copy(Getattr(n, "tdname")); } else if (name) { - enumtype = NewStringf("%s%s", CPlusPlus ? "" : "enum ", Getattr(n,"name")); + enumtype = NewStringf("%s%s", CPlusPlus ? "" : "enum ", Getattr(n, "name")); } else { // anonymous enums - enumtype = Copy(Getattr(n,"type")); + enumtype = Copy(Getattr(n, "type")); } - Setattr(n,"enumtype",enumtype); + Setattr(n, "enumtype", enumtype); emit_children(n); return SWIG_OK; @@ -723,27 +730,27 @@ class TypePass : private Dispatcher { * ------------------------------------------------------------ */ virtual int enumvalueDeclaration(Node *n) { - String *name = Getattr(n,"name"); - String *value = Getattr(n,"value"); - if (!value) value = name; - if (Strcmp(value,name) == 0) { + String *name = Getattr(n, "name"); + String *value = Getattr(n, "value"); + if (!value) + value = name; + if (Strcmp(value, name) == 0) { String *new_value; - if (((nsname) || (inclass)) && cparse_cplusplus ) { + if (((nsname) || (inclass)) && cparse_cplusplus) { new_value = NewStringf("%s::%s", SwigType_namestr(Swig_symbol_qualified(n)), value); } else { new_value = NewString(value); } - Setattr(n,"value",new_value); + Setattr(n, "value", new_value); Delete(new_value); } - // Make up an enumvalue if one was not specified in the parsed code - if (Getattr(n,"_last") && !Getattr(n,"enumvalue")) { // Only the first enum item has _last set - Setattr(n,"enumvalueex", "0"); + if (Getattr(n, "_last") && !Getattr(n, "enumvalue")) { // Only the first enum item has _last set + Setattr(n, "enumvalueex", "0"); } Node *next = nextSibling(n); - if (next && !Getattr(next,"enumvalue")) { - Setattr(next,"enumvalueex", NewStringf("%s + 1", Getattr(n,"sym:name"))); + if (next && !Getattr(next, "enumvalue")) { + Setattr(next, "enumvalueex", NewStringf("%s + 1", Getattr(n, "sym:name"))); } return SWIG_OK; @@ -751,7 +758,7 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * enumforwardDeclaration() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int enumforwardDeclaration(Node *n) { @@ -765,13 +772,13 @@ class TypePass : private Dispatcher { * ------------------------------------------------------------ */ virtual int usingDeclaration(Node *n) { - if (Getattr(n,"namespace")) { + if (Getattr(n, "namespace")) { /* using namespace id */ /* For a namespace import. We set up inheritance in the type system */ - Node *ns = Getattr(n,"node"); + Node *ns = Getattr(n, "node"); if (ns) { - Typetab *ts = Getattr(ns,"typescope"); + Typetab *ts = Getattr(ns, "typescope"); if (ts) { SwigType_using_scope(ts); } @@ -780,15 +787,15 @@ class TypePass : private Dispatcher { } else { Node *ns; /* using id */ - Symtab *stab = Getattr(n,"sym:symtab"); + Symtab *stab = Getattr(n, "sym:symtab"); if (stab) { - String *uname = Getattr(n,"uname"); + String *uname = Getattr(n, "uname"); ns = Swig_symbol_clookup(uname, stab); if (!ns && SwigType_istemplate(uname)) { String *tmp = Swig_symbol_template_deftype(uname, 0); if (!Equal(tmp, uname)) { ns = Swig_symbol_clookup(tmp, stab); - } + } Delete(tmp); } } else { @@ -796,7 +803,7 @@ class TypePass : private Dispatcher { } if (!ns) { if (is_public(n)) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(n), Getline(n), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(n,"uname"))); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(n), Getline(n), "Nothing known about '%s'.\n", SwigType_namestr(Getattr(n, "uname"))); } } else { @@ -804,83 +811,84 @@ class TypePass : private Dispatcher { we actually care about. These are typedef, class declarations, and enum */ String *ntype = nodeType(ns); - if (Strcmp(ntype,"cdecl") == 0) { - if (checkAttribute(ns,"storage","typedef")) { + if (Strcmp(ntype, "cdecl") == 0) { + if (checkAttribute(ns, "storage", "typedef")) { /* A typedef declaration */ - String *uname = Getattr(n,"uname"); + String *uname = Getattr(n, "uname"); SwigType_typedef_using(uname); } else { /* A normal C declaration. */ - if ((inclass) && (!GetFlag(n,"feature:ignore")) && (Getattr(n,"sym:name"))) { + if ((inclass) && (!GetFlag(n, "feature:ignore")) && (Getattr(n, "sym:name"))) { Node *c = ns; Node *unodes = 0, *last_unodes = 0; - int ccount = 0; - String *symname = Getattr(n,"sym:name"); + int ccount = 0; + String *symname = Getattr(n, "sym:name"); while (c) { - if (Strcmp(nodeType(c),"cdecl") == 0) { - if (!(checkAttribute(c,"storage","static") - || checkAttribute(c,"storage","typedef") - || checkAttribute(c,"storage","friend") - || (Getattr(c,"feature:extend") && !Getattr(c,"code")) - || GetFlag(c,"feature:ignore"))) { - - String *csymname = Getattr(c,"sym:name"); - if (!csymname || (Strcmp(csymname,symname) == 0)) { + if (Strcmp(nodeType(c), "cdecl") == 0) { + if (!(checkAttribute(c, "storage", "static") + || checkAttribute(c, "storage", "typedef") + || checkAttribute(c, "storage", "friend") + || (Getattr(c, "feature:extend") && !Getattr(c, "code")) + || GetFlag(c, "feature:ignore"))) { + + String *csymname = Getattr(c, "sym:name"); + if (!csymname || (Strcmp(csymname, symname) == 0)) { /* Check for existence in overload list already */ { - String *decl = Getattr(c,"decl"); - Node *over = Getattr(n,"sym:overloaded"); - int match = 0; + String *decl = Getattr(c, "decl"); + Node *over = Getattr(n, "sym:overloaded"); + int match = 0; while (over) { - String *odecl = Getattr(over,"decl"); + String *odecl = Getattr(over, "decl"); if (Cmp(decl, odecl) == 0) { match = 1; break; } - over = Getattr(over,"sym:nextSibling"); + over = Getattr(over, "sym:nextSibling"); } if (match) { - c = Getattr(c,"csym:nextSibling"); + c = Getattr(c, "csym:nextSibling"); continue; } } Node *nn = copyNode(c); - Delattr(nn,"access"); // access might be different from the method in the base class - if (!Getattr(nn,"sym:name")) Setattr(nn,"sym:name", symname); + Delattr(nn, "access"); // access might be different from the method in the base class + if (!Getattr(nn, "sym:name")) + Setattr(nn, "sym:name", symname); - if (!GetFlag(nn,"feature:ignore")) { - ParmList *parms = CopyParmList(Getattr(c,"parms")); - int is_pointer = SwigType_ispointer_return(Getattr(nn,"decl")); - int is_void = checkAttribute(nn,"type", "void") && !is_pointer; - Setattr(nn,"parms",parms); + if (!GetFlag(nn, "feature:ignore")) { + ParmList *parms = CopyParmList(Getattr(c, "parms")); + int is_pointer = SwigType_ispointer_return(Getattr(nn, "decl")); + int is_void = checkAttribute(nn, "type", "void") && !is_pointer; + Setattr(nn, "parms", parms); Delete(parms); - if (Getattr(n,"feature:extend")) { - String *ucode = is_void ? NewStringf("{ self->%s(",Getattr(n,"uname")) : - NewStringf("{ return self->%s(",Getattr(n,"uname")); + if (Getattr(n, "feature:extend")) { + String *ucode = is_void ? NewStringf("{ self->%s(", Getattr(n, "uname")) : NewStringf("{ return self->%s(", Getattr(n, "uname")); for (ParmList *p = parms; p;) { - StringAppend(ucode,HashGetAttr(p,k_name)); + StringAppend(ucode, HashGetAttr(p, k_name)); p = nextSibling(p); - if (p) StringAppend(ucode,","); + if (p) + StringAppend(ucode, ","); } - StringAppend(ucode,"); }"); - Setattr(nn,"code",ucode); + StringAppend(ucode, "); }"); + Setattr(nn, "code", ucode); Delete(ucode); } - ParmList *throw_parm_list = Getattr(c,"throws"); + ParmList *throw_parm_list = Getattr(c, "throws"); if (throw_parm_list) - Setattr(nn,"throws",CopyParmList(throw_parm_list)); + Setattr(nn, "throws", CopyParmList(throw_parm_list)); ccount++; if (!last_unodes) { last_unodes = nn; unodes = nn; } else { - Setattr(nn,"previousSibling",last_unodes); - Setattr(last_unodes,"nextSibling", nn); - Setattr(nn,"sym:previousSibling", last_unodes); - Setattr(last_unodes,"sym:nextSibling", nn); - Setattr(nn,"sym:overloaded", unodes); - Setattr(unodes,"sym:overloaded", unodes); + Setattr(nn, "previousSibling", last_unodes); + Setattr(last_unodes, "nextSibling", nn); + Setattr(nn, "sym:previousSibling", last_unodes); + Setattr(last_unodes, "sym:nextSibling", nn); + Setattr(nn, "sym:overloaded", unodes); + Setattr(unodes, "sym:overloaded", unodes); last_unodes = nn; } } else { @@ -889,26 +897,26 @@ class TypePass : private Dispatcher { } } } - c = Getattr(c,"csym:nextSibling"); + c = Getattr(c, "csym:nextSibling"); } if (unodes) { - set_firstChild(n,unodes); + set_firstChild(n, unodes); if (ccount > 1) { - if (!Getattr(n,"sym:overloaded")) { - Setattr(n,"sym:overloaded",n); - Setattr(n,"sym:overname","_SWIG_0"); + if (!Getattr(n, "sym:overloaded")) { + Setattr(n, "sym:overloaded", n); + Setattr(n, "sym:overname", "_SWIG_0"); } } } } } - } else if ((Strcmp(ntype,"class") == 0) || ((Strcmp(ntype,"classforward") == 0))) { + } else if ((Strcmp(ntype, "class") == 0) || ((Strcmp(ntype, "classforward") == 0))) { /* We install the using class name as kind of a typedef back to the original class */ - String *uname = Getattr(n,"uname"); + String *uname = Getattr(n, "uname"); /* Import into current type scope */ SwigType_typedef_using(uname); - } else if (Strcmp(ntype,"enum") == 0) { - SwigType_typedef_using(Getattr(n,"uname")); + } else if (Strcmp(ntype, "enum") == 0) { + SwigType_typedef_using(Getattr(n, "uname")); } } } @@ -917,14 +925,14 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * typemapDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int typemapDirective(Node *n) { if (inclass || nsname) { Node *items = firstChild(n); while (items) { - Parm *pattern = Getattr(items,"pattern"); - Parm *parms = Getattr(items,"parms"); + Parm *pattern = Getattr(items, "pattern"); + Parm *parms = Getattr(items, "parms"); normalize_later(pattern); normalize_later(parms); items = nextSibling(items); @@ -936,15 +944,15 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * typemapcopyDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int typemapcopyDirective(Node *n) { if (inclass || nsname) { Node *items = firstChild(n); - ParmList *pattern = Getattr(n,"pattern"); + ParmList *pattern = Getattr(n, "pattern"); normalize_later(pattern); while (items) { - ParmList *npattern = Getattr(items,"pattern"); + ParmList *npattern = Getattr(items, "pattern"); normalize_later(npattern); items = nextSibling(items); } @@ -954,15 +962,15 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * applyDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int applyDirective(Node *n) { if (inclass || nsname) { - ParmList *pattern = Getattr(n,"pattern"); + ParmList *pattern = Getattr(n, "pattern"); normalize_later(pattern); Node *items = firstChild(n); while (items) { - Parm *apattern = Getattr(items,"pattern"); + Parm *apattern = Getattr(items, "pattern"); normalize_later(apattern); items = nextSibling(items); } @@ -972,13 +980,13 @@ class TypePass : private Dispatcher { /* ------------------------------------------------------------ * clearDirective() - * ------------------------------------------------------------ */ + * ------------------------------------------------------------ */ virtual int clearDirective(Node *n) { if (inclass || nsname) { Node *p; for (p = firstChild(n); p; p = nextSibling(p)) { - ParmList *pattern = Getattr(p,"pattern"); + ParmList *pattern = Getattr(p, "pattern"); normalize_later(pattern); } } @@ -993,13 +1001,7 @@ public: }; void Swig_process_types(Node *n) { - if (!n) return; + if (!n) + return; TypePass::pass(n); } - - - - - - - diff --git a/SWIG/Source/Modules/uffi.cxx b/SWIG/Source/Modules/uffi.cxx index 8f1b819fe..2a327d61d 100644 --- a/SWIG/Source/Modules/uffi.cxx +++ b/SWIG/Source/Modules/uffi.cxx @@ -13,32 +13,32 @@ char cvsroot_uffi_cxx[] = "$Header$"; #include "swigmod.h" -class UFFI : public Language { +class UFFI:public Language { public: virtual void main(int argc, char *argv[]); virtual int top(Node *n); - virtual int functionWrapper(Node *n); + virtual int functionWrapper(Node *n); virtual int constantWrapper(Node *n); virtual int classHandler(Node *n); virtual int membervariableHandler(Node *n); }; -static File *f_cl=0; -static File *f_null=0; +static File *f_cl = 0; +static File *f_null = 0; static struct { int count; String **entries; } defined_foreign_types; -static const char *identifier_converter="identifier-convert-null"; +static const char *identifier_converter = "identifier-convert-null"; static int any_varargs(ParmList *pl) { Parm *p; - - for(p=pl; p; p=nextSibling(p)) { + + for (p = pl; p; p = nextSibling(p)) { if (SwigType_isvarargs(Getattr(p, "type"))) return 1; } @@ -46,83 +46,79 @@ static int any_varargs(ParmList *pl) { return 0; } - + /* utilities */ /* returns new string w/ parens stripped */ static String *strip_parens(String *string) { - char *s=Char(string), *p; - int len=Len(string); - String *res; - - if (len==0 || s[0] != '(' || s[len-1] != ')') { - return NewString(string); - } - - p=(char *)malloc(len-2+1); - if (!p) { - Printf(stderr, "Malloc failed\n"); - SWIG_exit(EXIT_FAILURE); - } - - strncpy(p, s+1, len-1); - p[len-2]=0; /* null terminate */ - - res=NewString(p); - free(p); - - return res; + char *s = Char(string), *p; + int len = Len(string); + String *res; + + if (len == 0 || s[0] != '(' || s[len - 1] != ')') { + return NewString(string); + } + + p = (char *) malloc(len - 2 + 1); + if (!p) { + Printf(stderr, "Malloc failed\n"); + SWIG_exit(EXIT_FAILURE); + } + + strncpy(p, s + 1, len - 1); + p[len - 2] = 0; /* null terminate */ + + res = NewString(p); + free(p); + + return res; } static String *convert_literal(String *num_param, String *type) { - String *num=strip_parens(num_param), *res; - char *s=Char(num); - - /* Make sure doubles use 'd' instead of 'e' */ - if (!Strcmp(type, "double")) { - String *updated=Copy(num); - if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) { - Printf(stderr, "Weird!! number %s looks invalid.\n", num); - SWIG_exit(EXIT_FAILURE); - } - Delete(num); - return updated; - } + String *num = strip_parens(num_param), *res; + char *s = Char(num); - if (SwigType_type(type) == T_CHAR) { - /* Use CL syntax for character literals */ - return NewStringf("#\\%s", num_param); - } - else if (SwigType_type(type) == T_STRING) { - /* Use CL syntax for string literals */ - return NewStringf("\"%s\"", num_param); - } - - if (Len(num) < 2 || s[0] != '0') { - return num; - } - - /* octal or hex */ - - res=NewStringf("#%c%s", - s[1] == 'x' ? 'x' : 'o', - s+2); - Delete(num); + /* Make sure doubles use 'd' instead of 'e' */ + if (!Strcmp(type, "double")) { + String *updated = Copy(num); + if (Replace(updated, "e", "d", DOH_REPLACE_ANY) > 1) { + Printf(stderr, "Weird!! number %s looks invalid.\n", num); + SWIG_exit(EXIT_FAILURE); + } + Delete(num); + return updated; + } - return res; + if (SwigType_type(type) == T_CHAR) { + /* Use CL syntax for character literals */ + return NewStringf("#\\%s", num_param); + } else if (SwigType_type(type) == T_STRING) { + /* Use CL syntax for string literals */ + return NewStringf("\"%s\"", num_param); + } + + if (Len(num) < 2 || s[0] != '0') { + return num; + } + + /* octal or hex */ + + res = NewStringf("#%c%s", s[1] == 'x' ? 'x' : 'o', s + 2); + Delete(num); + + return res; } static void add_defined_foreign_type(String *type) { if (!defined_foreign_types.count) { /* Make fresh */ - defined_foreign_types.count=1; - defined_foreign_types.entries=(String **)malloc(sizeof(String *)); + defined_foreign_types.count = 1; + defined_foreign_types.entries = (String **) malloc(sizeof(String *)); } else { /* make room */ defined_foreign_types.count++; - defined_foreign_types.entries=(String **) - realloc(defined_foreign_types.entries, - defined_foreign_types.count*sizeof(String *)); + defined_foreign_types.entries = (String **) + realloc(defined_foreign_types.entries, defined_foreign_types.count * sizeof(String *)); } if (!defined_foreign_types.entries) { @@ -131,121 +127,110 @@ static void add_defined_foreign_type(String *type) { } /* Fill in the new data */ - defined_foreign_types.entries[defined_foreign_types.count-1]= - Copy(type); - + defined_foreign_types.entries[defined_foreign_types.count - 1] = Copy(type); + } static String *get_ffi_type(SwigType *ty, const String_or_char *name) { Hash *typemap = Swig_typemap_search("ffitype", ty, name, 0); if (typemap) { - String *typespec = Getattr(typemap, "code"); - return NewString(typespec); - } - else { - SwigType *tr=SwigType_typedef_resolve_all(ty); - char *type_reduced=Char(tr); - int i; + String *typespec = Getattr(typemap, "code"); + return NewString(typespec); + } else { + SwigType *tr = SwigType_typedef_resolve_all(ty); + char *type_reduced = Char(tr); + int i; - //Printf(stdout,"convert_type %s\n", ty); - if (SwigType_isconst(tr)) { - SwigType_pop(tr); - type_reduced=Char(tr); - } + //Printf(stdout,"convert_type %s\n", ty); + if (SwigType_isconst(tr)) { + SwigType_pop(tr); + type_reduced = Char(tr); + } - if (SwigType_ispointer(type_reduced) || SwigType_isarray(ty) || - !strncmp(type_reduced, "p.f", 3)) { - return NewString(":pointer-void"); - } - - for(i=0; i\n" "\tSpecifies the type of conversion to do on C identifiers to convert\n" "\tthem to symbols. There are two built-in converters: 'null' and\n" "\t 'lispify'. The default is 'null'. If you supply a name other\n" "\tthan one of the built-ins, then a function by that name will be\n" "\tcalled to convert identifiers to symbols.\n"); - } - } - - } -int UFFI :: top(Node *n) { - String *module=Getattr(n, "name"); - String *output_filename=NewString(""); - String *devnull=NewString("/dev/null"); +int UFFI::top(Node *n) { + String *module = Getattr(n, "name"); + String *output_filename = NewString(""); + String *devnull = NewString("/dev/null"); - f_null=NewFile(devnull, "w+"); + f_null = NewFile(devnull, "w+"); if (!f_null) { - FileErrorDisplay(devnull); - SWIG_exit(EXIT_FAILURE); + FileErrorDisplay(devnull); + SWIG_exit(EXIT_FAILURE); } Delete(devnull); @@ -253,166 +238,153 @@ int UFFI :: top(Node *n) { Printf(output_filename, "%s%s.cl", SWIG_output_directory(), module); - f_cl=NewFile(output_filename, "w"); + f_cl = NewFile(output_filename, "w"); if (!f_cl) { FileErrorDisplay(output_filename); SWIG_exit(EXIT_FAILURE); } - Swig_register_filebyname("header",f_null); - Swig_register_filebyname("runtime",f_null); + Swig_register_filebyname("header", f_null); + Swig_register_filebyname("runtime", f_null); Swig_register_filebyname("wrapper", f_cl); - Printf(f_cl, ";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\n;; This is an automatically generated file. Make changes in\n;; the definition file, not here.\n\n(defpackage :%s\n (:use :common-lisp :uffi))\n\n(in-package :%s)\n", module, module, module); + Printf(f_cl, + ";; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; package: %s -*-\n;; This is an automatically generated file. Make changes in\n;; the definition file, not here.\n\n(defpackage :%s\n (:use :common-lisp :uffi))\n\n(in-package :%s)\n", + module, module, module); Printf(f_cl, "(eval-when (compile load eval)\n (defparameter *swig-identifier-converter* '%s))\n", identifier_converter); - + Language::top(n); Close(f_cl); - Delete(f_cl); // Delete the handle, not the file + Delete(f_cl); // Delete the handle, not the file Close(f_null); Delete(f_null); - + return SWIG_OK; } -int UFFI :: functionWrapper(Node *n) { - String *funcname=Getattr(n, "sym:name"); - ParmList *pl=Getattr(n, "parms"); +int UFFI::functionWrapper(Node *n) { + String *funcname = Getattr(n, "sym:name"); + ParmList *pl = Getattr(n, "parms"); Parm *p; - int argnum=0, first=1, varargs=0; - + int argnum = 0, first = 1, varargs = 0; + //Language::functionWrapper(n); Printf(f_cl, "(swig-defun \"%s\"\n", funcname); Printf(f_cl, " ("); /* Special cases */ - + if (ParmList_len(pl) == 0) { Printf(f_cl, ":void"); } else if (any_varargs(pl)) { Printf(f_cl, "#| varargs |#"); - varargs=1; + varargs = 1; } else { - for (p=pl; p; p=nextSibling(p), argnum++) { - String *argname=Getattr(p, "name"); - SwigType *argtype=Getattr(p, "type"); - String *ffitype=get_ffi_type(argtype, argname); - String *lisptype=get_lisp_type(argtype, argname); - int tempargname=0; - + for (p = pl; p; p = nextSibling(p), argnum++) { + String *argname = Getattr(p, "name"); + SwigType *argtype = Getattr(p, "type"); + String *ffitype = get_ffi_type(argtype, argname); + String *lisptype = get_lisp_type(argtype, argname); + int tempargname = 0; + if (!argname) { - argname=NewStringf("arg%d", argnum); - tempargname=1; + argname = NewStringf("arg%d", argnum); + tempargname = 1; } - + if (!first) { Printf(f_cl, "\n "); } Printf(f_cl, "(%s %s %s)", argname, ffitype, lisptype); - first=0; - + first = 0; + Delete(ffitype); Delete(lisptype); - if (tempargname) + if (tempargname) Delete(argname); - + } } - Printf(f_cl, ")\n"); /* finish arg list */ + Printf(f_cl, ")\n"); /* finish arg list */ Printf(f_cl, " :returning %s\n" //" :strings-convert t\n" //" :call-direct %s\n" //" :optimize-for-space t" - ")\n", - get_ffi_type(Getattr(n, "type"), "result") + ")\n", get_ffi_type(Getattr(n, "type"), "result") //,varargs ? "nil" : "t" - ); + ); + - return SWIG_OK; } -int UFFI :: constantWrapper(Node *n) { - String *type=Getattr(n, "type"); - String *converted_value=convert_literal(Getattr(n, "value"), type); - String *name=Getattr(n, "sym:name"); +int UFFI::constantWrapper(Node *n) { + String *type = Getattr(n, "type"); + String *converted_value = convert_literal(Getattr(n, "value"), type); + String *name = Getattr(n, "sym:name"); #if 0 - Printf(stdout, "constant %s is of type %s. value: %s\n", - name, type, converted_value); + Printf(stdout, "constant %s is of type %s. value: %s\n", name, type, converted_value); #endif - Printf(f_cl, "(swig-defconstant \"%s\" %s)\n", - name, converted_value); + Printf(f_cl, "(swig-defconstant \"%s\" %s)\n", name, converted_value); Delete(converted_value); - + return SWIG_OK; } // Includes structs -int UFFI :: classHandler(Node *n) { +int UFFI::classHandler(Node *n) { - String *name=Getattr(n, "sym:name"); - String *kind = Getattr(n,"kind"); + String *name = Getattr(n, "sym:name"); + String *kind = Getattr(n, "kind"); Node *c; - + if (Strcmp(kind, "struct")) { - Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", - kind); + Printf(stderr, "Don't know how to deal with %s kind of class yet.\n", kind); Printf(stderr, " (name: %s)\n", name); SWIG_exit(EXIT_FAILURE); } - Printf(f_cl, - "(swig-def-struct \"%s\"\n \n", - name); + Printf(f_cl, "(swig-def-struct \"%s\"\n \n", name); - for (c=firstChild(n); c; c=nextSibling(c)) { - SwigType *type=Getattr(c, "type"); - SwigType *decl=Getattr(c, "decl"); + for (c = firstChild(n); c; c = nextSibling(c)) { + SwigType *type = Getattr(c, "type"); + SwigType *decl = Getattr(c, "decl"); type = Copy(type); SwigType_push(type, decl); String *lisp_type; if (Strcmp(nodeType(c), "cdecl")) { - Printf(stderr, "Structure %s has a slot that we can't deal with.\n", - name); - Printf(stderr, "nodeType: %s, name: %s, type: %s\n", - nodeType(c), - Getattr(c, "name"), - Getattr(c, "type")); + Printf(stderr, "Structure %s has a slot that we can't deal with.\n", name); + Printf(stderr, "nodeType: %s, name: %s, type: %s\n", nodeType(c), Getattr(c, "name"), Getattr(c, "type")); SWIG_exit(EXIT_FAILURE); } - - /* Printf(stdout, "Converting %s in %s\n", type, name); */ - lisp_type=get_ffi_type(type, Getattr(c, "sym:name")); - Printf(f_cl, - " (#.(%s \"%s\" :type :slot) %s)\n", - identifier_converter, - Getattr(c, "sym:name"), - lisp_type); + /* Printf(stdout, "Converting %s in %s\n", type, name); */ + lisp_type = get_ffi_type(type, Getattr(c, "sym:name")); + + Printf(f_cl, " (#.(%s \"%s\" :type :slot) %s)\n", identifier_converter, Getattr(c, "sym:name"), lisp_type); Delete(lisp_type); } // Language::classHandler(n); - + Printf(f_cl, " )\n"); /* Add this structure to the known lisp types */ //Printf(stdout, "Adding %s foreign type\n", name); add_defined_foreign_type(name); - + return SWIG_OK; } -int UFFI :: membervariableHandler(Node *n) -{ +int UFFI::membervariableHandler(Node *n) { Language::membervariableHandler(n); return SWIG_OK; } @@ -421,7 +393,3 @@ int UFFI :: membervariableHandler(Node *n) extern "C" Language *swig_uffi(void) { return new UFFI(); } - - - - diff --git a/SWIG/Source/Modules/utils.cxx b/SWIG/Source/Modules/utils.cxx index cfa64b24e..a5176b982 100644 --- a/SWIG/Source/Modules/utils.cxx +++ b/SWIG/Source/Modules/utils.cxx @@ -11,42 +11,38 @@ char cvsroot_utils_cxx[] = "$Header$"; #include -int is_public(Node* n) -{ - String* access = Getattr(n, "access"); +int is_public(Node *n) { + String *access = Getattr(n, "access"); return !access || !Cmp(access, "public"); } -int is_private(Node* n) -{ - String* access = Getattr(n, "access"); +int is_private(Node *n) { + String *access = Getattr(n, "access"); return access && !Cmp(access, "private"); } -int is_protected(Node* n) -{ - String* access = Getattr(n, "access"); +int is_protected(Node *n) { + String *access = Getattr(n, "access"); return access && !Cmp(access, "protected"); } -int is_member_director(Node* parentnode, Node* member) -{ +int is_member_director(Node *parentnode, Node *member) { int director_mode = Swig_director_mode(); if (parentnode && checkAttribute(member, "storage", "virtual")) { - int parent_nodirector = GetFlag(parentnode,"feature:nodirector"); - if (parent_nodirector) return 0; - int parent_director = director_mode && GetFlag(parentnode,"feature:director"); - int cdecl_director = parent_director || GetFlag(member,"feature:director"); - int cdecl_nodirector = GetFlag(member,"feature:nodirector"); + int parent_nodirector = GetFlag(parentnode, "feature:nodirector"); + if (parent_nodirector) + return 0; + int parent_director = director_mode && GetFlag(parentnode, "feature:director"); + int cdecl_director = parent_director || GetFlag(member, "feature:director"); + int cdecl_nodirector = GetFlag(member, "feature:nodirector"); return cdecl_director && !cdecl_nodirector && !GetFlag(member, "feature:extend"); } else { return 0; } } -int is_member_director(Node* member) -{ +int is_member_director(Node *member) { return is_member_director(Getattr(member, "parentNode"), member); } @@ -54,37 +50,36 @@ int is_member_director(Node* member) /* Clean overloaded list. Removes templates, ignored, and errors */ void clean_overloaded(Node *n) { - Node *nn = Getattr(n,"sym:overloaded"); + Node *nn = Getattr(n, "sym:overloaded"); Node *first = 0; - int cnt = 0; + int cnt = 0; while (nn) { String *ntype = nodeType(nn); - if ((GetFlag(nn,"feature:ignore")) || - (Getattr(nn,"error")) || - (Strcmp(ntype,"template") == 0) || - ((Strcmp(ntype,"cdecl") == 0) && is_protected(nn) && !is_member_director(nn)) || - ((Strcmp(ntype,"using") == 0) && !firstChild(nn))) { + if ((GetFlag(nn, "feature:ignore")) || + (Getattr(nn, "error")) || + (Strcmp(ntype, "template") == 0) || + ((Strcmp(ntype, "cdecl") == 0) && is_protected(nn) && !is_member_director(nn)) || ((Strcmp(ntype, "using") == 0) && !firstChild(nn))) { /* Remove from overloaded list */ - Node *ps = Getattr(nn,"sym:previousSibling"); - Node *ns = Getattr(nn,"sym:nextSibling"); + Node *ps = Getattr(nn, "sym:previousSibling"); + Node *ns = Getattr(nn, "sym:nextSibling"); if (ps) { - Setattr(ps,"sym:nextSibling",ns); - } - if (ns) { - Setattr(ns,"sym:previousSibling",ps); + Setattr(ps, "sym:nextSibling", ns); } - Delattr(nn,"sym:previousSibling"); - Delattr(nn,"sym:nextSibling"); - Delattr(nn,"sym:overloaded"); + if (ns) { + Setattr(ns, "sym:previousSibling", ps); + } + Delattr(nn, "sym:previousSibling"); + Delattr(nn, "sym:nextSibling"); + Delattr(nn, "sym:overloaded"); nn = ns; continue; - } else if ((Strcmp(ntype,"using") == 0)) { + } else if ((Strcmp(ntype, "using") == 0)) { /* A possibly dangerous parse tree hack. We're going to - cut the parse tree node out and stick in the resolved - using declarations */ - - Node *ps = Getattr(nn,"sym:previousSibling"); - Node *ns = Getattr(nn,"sym:nextSibling"); + cut the parse tree node out and stick in the resolved + using declarations */ + + Node *ps = Getattr(nn, "sym:previousSibling"); + Node *ns = Getattr(nn, "sym:nextSibling"); Node *un = firstChild(nn); Node *pn = un; @@ -92,32 +87,34 @@ void clean_overloaded(Node *n) { first = un; } while (pn) { - Node *ppn = Getattr(pn,"sym:nextSibling"); - Setattr(pn,"sym:overloaded",first); - Setattr(pn,"sym:overname", NewStringf("%s_%d", Getattr(nn,"sym:overname"), cnt++)); - if (ppn) pn = ppn; - else break; + Node *ppn = Getattr(pn, "sym:nextSibling"); + Setattr(pn, "sym:overloaded", first); + Setattr(pn, "sym:overname", NewStringf("%s_%d", Getattr(nn, "sym:overname"), cnt++)); + if (ppn) + pn = ppn; + else + break; } if (ps) { - Setattr(ps,"sym:nextSibling",un); - Setattr(un,"sym:previousSibling",ps); + Setattr(ps, "sym:nextSibling", un); + Setattr(un, "sym:previousSibling", ps); } if (ns) { - Setattr(ns,"sym:previousSibling", pn); - Setattr(pn,"sym:nextSibling",ns); + Setattr(ns, "sym:previousSibling", pn); + Setattr(pn, "sym:nextSibling", ns); } if (!first) { first = un; - Setattr(nn,"sym:overloaded",first); + Setattr(nn, "sym:overloaded", first); } } else { - if (!first) first = nn; - Setattr(nn,"sym:overloaded",first); + if (!first) + first = nn; + Setattr(nn, "sym:overloaded", first); } - nn = Getattr(nn,"sym:nextSibling"); + nn = Getattr(nn, "sym:nextSibling"); } - if (!first || (first && !Getattr(first,"sym:nextSibling"))) { - Delattr(n,"sym:overloaded"); + if (!first || (first && !Getattr(first, "sym:nextSibling"))) { + Delattr(n, "sym:overloaded"); } } - diff --git a/SWIG/Source/Modules/xml.cxx b/SWIG/Source/Modules/xml.cxx index 3f13f81ab..3f2fa3fd8 100644 --- a/SWIG/Source/Modules/xml.cxx +++ b/SWIG/Source/Modules/xml.cxx @@ -22,321 +22,266 @@ static File *out = 0; static int xmllite = 0; -class XML -: public Language -{ +class XML:public Language { public: - int indent_level; - long id; - XML() - : indent_level( 0 ) - , id( 0 ) - { - } + int indent_level; + long id; - virtual ~XML() - { - } + XML() :indent_level(0) , id(0) { + } + + virtual ~ XML() { + } - virtual void main(int argc, char *argv[]) - { - SWIG_typemap_lang("xml"); - for( int iX = 0; iX < argc; iX++ ) - { - if( strcmp( argv[iX], "-xml" ) == 0 ) - { - char * extension = 0; - if( iX + 1 >= argc ) - continue; - extension = argv[iX+1]+strlen(argv[iX+1])-4; - if( strcmp( extension, ".xml" ) ) - continue; - iX++; - Swig_mark_arg (iX); - String * outfile = NewString( argv[iX] ); - out = NewFile(outfile,"w"); - if (!out) - { - FileErrorDisplay(outfile); - SWIG_exit(EXIT_FAILURE); - } - continue; - } - if( strcmp( argv[iX], "-xmllang" ) == 0 ) - { - Swig_mark_arg (iX); - iX++; - SWIG_typemap_lang(argv[iX]); - Swig_mark_arg (iX); - continue; - } - if( strcmp( argv[iX], "-help" ) == 0 ) - { - fputs( usage, stdout ); - } - if( strcmp( argv[iX], "-xmllite" ) == 0 ) - { - Swig_mark_arg (iX); - xmllite = 1; - } - } - - // Add a symbol to the parser for conditional compilation - Preprocessor_define("SWIGXML 1",0); + virtual void main(int argc, char *argv[]) { + SWIG_typemap_lang("xml"); + for (int iX = 0; iX < argc; iX++) { + if (strcmp(argv[iX], "-xml") == 0) { + char *extension = 0; + if (iX + 1 >= argc) + continue; + extension = argv[iX + 1] + strlen(argv[iX + 1]) - 4; + if (strcmp(extension, ".xml")) + continue; + iX++; + Swig_mark_arg(iX); + String *outfile = NewString(argv[iX]); + out = NewFile(outfile, "w"); + if (!out) { + FileErrorDisplay(outfile); + SWIG_exit(EXIT_FAILURE); } + continue; + } + if (strcmp(argv[iX], "-xmllang") == 0) { + Swig_mark_arg(iX); + iX++; + SWIG_typemap_lang(argv[iX]); + Swig_mark_arg(iX); + continue; + } + if (strcmp(argv[iX], "-help") == 0) { + fputs(usage, stdout); + } + if (strcmp(argv[iX], "-xmllite") == 0) { + Swig_mark_arg(iX); + xmllite = 1; + } + } + + // Add a symbol to the parser for conditional compilation + Preprocessor_define("SWIGXML 1", 0); + } /* Top of the parse tree */ - virtual int top(Node *n) - { - if( out == 0 ) - { - String *outfile = Getattr(n,"outfile"); - Replaceall(outfile,".cxx", ".xml"); - Replaceall(outfile,".cpp", ".xml"); - Replaceall(outfile,".c", ".xml"); - out = NewFile(outfile,"w"); - if (!out) - { - FileErrorDisplay(outfile); - SWIG_exit(EXIT_FAILURE); - } - } - Printf( out, " \n" ); - Xml_print_tree(n); - return SWIG_OK; - } + virtual int top(Node *n) { + if (out == 0) { + String *outfile = Getattr(n, "outfile"); + Replaceall(outfile, ".cxx", ".xml"); + Replaceall(outfile, ".cpp", ".xml"); + Replaceall(outfile, ".c", ".xml"); + out = NewFile(outfile, "w"); + if (!out) { + FileErrorDisplay(outfile); + SWIG_exit(EXIT_FAILURE); + } + } + Printf(out, " \n"); + Xml_print_tree(n); + return SWIG_OK; + } + void print_indent(int l) { + int i; + for (i = 0; i < indent_level; i++) { + Printf(out, " "); + } + if (l) { + Printf(out, " "); + } + } + void Xml_print_tree(DOH *obj) { + while (obj) { + Xml_print_node(obj); + obj = nextSibling(obj); + } + } - void print_indent(int l) - { - int i; - for (i = 0; i < indent_level; i++) - { - Printf(out, " "); - } - if (l) - { - Printf(out, " "); - } + void Xml_print_attributes(Node *obj) { + String *k; + indent_level += 4; + print_indent(0); + Printf(out, "\n", ++id, obj); + indent_level += 4; + Iterator ki; + ki = First(obj); + while (ki.key) { + k = ki.key; + if ((Cmp(k, "nodeType") == 0) + || (Cmp(k, "firstChild") == 0) + || (Cmp(k, "lastChild") == 0) + || (Cmp(k, "parentNode") == 0) + || (Cmp(k, "nextSibling") == 0) + || (Cmp(k, "previousSibling") == 0) + || (*(Char(k)) == '$')) { + /* Do nothing */ + } else if (Cmp(k, "module") == 0) { + Xml_print_module(Getattr(obj, k)); + } else if (Cmp(k, "baselist") == 0) { + Xml_print_baselist(Getattr(obj, k)); + } else if (!xmllite && Cmp(k, "typescope") == 0) { + Xml_print_typescope(Getattr(obj, k)); + } else if (!xmllite && Cmp(k, "typetab") == 0) { + Xml_print_typetab(Getattr(obj, k)); + } else if (Cmp(k, "kwargs") == 0) { + Xml_print_kwargs(Getattr(obj, k)); + } else if (Cmp(k, "parms") == 0 || Cmp(k, "pattern") == 0) { + Xml_print_parmlist(Getattr(obj, k)); + } else { + DOH *o; + print_indent(0); + if (DohIsString(Getattr(obj, k))) { + String *ck = NewString(k); + o = Str(Getattr(obj, k)); + Replaceall(ck, ":", "_"); + Replaceall(ck, "<", "<"); + /* Do first to avoid aliasing errors. */ + Replaceall(o, "&", "&"); + Replaceall(o, "<", "<"); + Replaceall(o, "\"", """); + Replaceall(o, "\\", "\\\\"); + Replaceall(o, "\n", " "); + Printf(out, "\n", ck, o, ++id, o); + Delete(o); + Delete(ck); + } else { + o = Getattr(obj, k); + String *ck = NewString(k); + Replaceall(ck, ":", "_"); + Printf(out, "\n", ck, o, ++id, o); + Delete(ck); } + } + ki = Next(ki); + } + indent_level -= 4; + print_indent(0); + Printf(out, "\n"); + indent_level -= 4; + } - void Xml_print_tree(DOH *obj) - { - while (obj) - { - Xml_print_node(obj); - obj = nextSibling(obj); - } - } + void Xml_print_node(Node *obj) { + Node *cobj; - void Xml_print_attributes(Node * obj) - { - String *k; - indent_level += 4; - print_indent(0); - Printf( out, "\n", ++id, obj ); - indent_level += 4; - Iterator ki; - ki = First(obj); - while (ki.key) { - k = ki.key; - if ((Cmp(k,"nodeType") == 0) - || (Cmp(k,"firstChild") == 0) - || (Cmp(k,"lastChild") == 0) - || (Cmp(k,"parentNode") == 0) - || (Cmp(k,"nextSibling") == 0) - || (Cmp(k,"previousSibling") == 0) - || (*(Char(k)) == '$')) - { - /* Do nothing */ - } - else if (Cmp(k,"module") == 0) - { - Xml_print_module( Getattr(obj,k) ); - } - else if (Cmp(k,"baselist") == 0) - { - Xml_print_baselist( Getattr(obj,k) ); - } - else if (!xmllite && Cmp(k,"typescope") == 0) - { - Xml_print_typescope( Getattr(obj,k) ); - } - else if (!xmllite && Cmp(k,"typetab") == 0) - { - Xml_print_typetab( Getattr(obj,k) ); - } - else if (Cmp(k,"kwargs") == 0) - { - Xml_print_kwargs( Getattr(obj,k) ); - } - else if (Cmp(k,"parms") == 0 || Cmp(k, "pattern") == 0 ) - { - Xml_print_parmlist( Getattr(obj,k) ); - } - else - { - DOH *o; - print_indent(0); - if (DohIsString(Getattr(obj,k))) - { - String *ck = NewString(k); - o = Str(Getattr(obj,k)); - Replaceall( ck, ":", "_" ); - Replaceall( ck, "<", "<" ); - /* Do first to avoid aliasing errors. */ - Replaceall( o, "&", "&" ); - Replaceall( o, "<", "<" ); - Replaceall( o, "\"", """ ); - Replaceall( o, "\\", "\\\\" ); - Replaceall( o, "\n", " " ); - Printf(out,"\n", ck, o, ++id, o ); - Delete(o); - Delete(ck); - } - else - { - o = Getattr(obj,k); - String *ck = NewString(k); - Replaceall( ck, ":", "_" ); - Printf(out,"\n", ck, o, ++id, o ); - Delete(ck); - } - } - ki = Next(ki); - } - indent_level -= 4; - print_indent(0); - Printf( out, "\n" ); - indent_level -= 4; - } - - void Xml_print_node(Node *obj) - { - Node *cobj; - - print_indent(0); - Printf(out,"<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj); - Xml_print_attributes( obj ); - cobj = firstChild(obj); - if (cobj) - { - indent_level += 4; - Printf(out,"\n"); - Xml_print_tree(cobj); - indent_level -= 4; - } - else - { - print_indent(1); - Printf(out,"\n"); - } - print_indent(0); - Printf(out,"\n", nodeType(obj)); - } + print_indent(0); + Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", nodeType(obj), ++id, obj); + Xml_print_attributes(obj); + cobj = firstChild(obj); + if (cobj) { + indent_level += 4; + Printf(out, "\n"); + Xml_print_tree(cobj); + indent_level -= 4; + } else { + print_indent(1); + Printf(out, "\n"); + } + print_indent(0); + Printf(out, "\n", nodeType(obj)); + } - void Xml_print_parmlist(ParmList *p) - { + void Xml_print_parmlist(ParmList *p) { - print_indent(0); - Printf( out, "\n", ++id, p ); - indent_level += 4; - while(p) - { - print_indent(0); - Printf( out, "\n", ++id ); - Xml_print_attributes( p ); - print_indent(0); - Printf( out, "\n" ); - p = nextSibling(p); - } - indent_level -= 4; - print_indent(0); - Printf( out, "\n" ); - } + print_indent(0); + Printf(out, "\n", ++id, p); + indent_level += 4; + while (p) { + print_indent(0); + Printf(out, "\n", ++id); + Xml_print_attributes(p); + print_indent(0); + Printf(out, "\n"); + p = nextSibling(p); + } + indent_level -= 4; + print_indent(0); + Printf(out, "\n"); + } - void Xml_print_baselist(List *p) - { + void Xml_print_baselist(List *p) { - print_indent(0); - Printf( out, "\n", ++id, p ); - indent_level += 4; - Iterator s; - for (s = First(p); s.item; s = Next(s)) - { - print_indent(0); - String *item_name = Xml_escape_string(s.item); - Printf( out, "\n", item_name, ++id, s.item ); - Delete(item_name); - } - indent_level -= 4; - print_indent(0); - Printf( out, "\n" ); - } + print_indent(0); + Printf(out, "\n", ++id, p); + indent_level += 4; + Iterator s; + for (s = First(p); s.item; s = Next(s)) { + print_indent(0); + String *item_name = Xml_escape_string(s.item); + Printf(out, "\n", item_name, ++id, s.item); + Delete(item_name); + } + indent_level -= 4; + print_indent(0); + Printf(out, "\n"); + } - String *Xml_escape_string(String *str) { - String *escaped_str = 0; - if (str) { - escaped_str = NewString(str); - Replaceall( escaped_str, "&", "&" ); - Replaceall( escaped_str, "<", "<" ); - Replaceall( escaped_str, "\"", """ ); - Replaceall( escaped_str, "\\", "\\\\" ); - Replaceall( escaped_str, "\n", " " ); - } - return escaped_str; - } + String *Xml_escape_string(String *str) { + String *escaped_str = 0; + if (str) { + escaped_str = NewString(str); + Replaceall(escaped_str, "&", "&"); + Replaceall(escaped_str, "<", "<"); + Replaceall(escaped_str, "\"", """); + Replaceall(escaped_str, "\\", "\\\\"); + Replaceall(escaped_str, "\n", " "); + } + return escaped_str; + } - void Xml_print_module(Node *p) - { + void Xml_print_module(Node *p) { - print_indent(0); - Printf( out, "\n", Getattr( p, "name"), ++id, p ); - } + print_indent(0); + Printf(out, "\n", Getattr(p, "name"), ++id, p); + } - void Xml_print_kwargs(Hash *p) - { - Xml_print_hash( p, "kwargs" ); - } + void Xml_print_kwargs(Hash *p) { + Xml_print_hash(p, "kwargs"); + } - void Xml_print_typescope(Hash *p) - { + void Xml_print_typescope(Hash *p) { - Xml_print_hash( p, "typescope" ); - } + Xml_print_hash(p, "typescope"); + } - void Xml_print_typetab(Hash *p) - { + void Xml_print_typetab(Hash *p) { - Xml_print_hash( p, "typetab" ); - } + Xml_print_hash(p, "typetab"); + } - void Xml_print_hash(Hash *p, const char * markup) - { + void Xml_print_hash(Hash *p, const char *markup) { - print_indent(0); - Printf( out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p ); - Xml_print_attributes( p ); - indent_level += 4; - Iterator n = First(p); - while(n.key) - { - print_indent(0); - Printf( out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item ); - Xml_print_attributes( n.item ); - print_indent(0); - Printf( out, "\n", markup ); - n = Next(n); - } - indent_level -= 4; - print_indent(0); - Printf( out, "\n", markup ); - } + print_indent(0); + Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p); + Xml_print_attributes(p); + indent_level += 4; + Iterator n = First(p); + while (n.key) { + print_indent(0); + Printf(out, "<%ssitem id=\"%ld\" addr=\"%x\" >\n", markup, ++id, n.item); + Xml_print_attributes(n.item); + print_indent(0); + Printf(out, "\n", markup); + n = Next(n); + } + indent_level -= 4; + print_indent(0); + Printf(out, "\n", markup); + } }; @@ -349,29 +294,27 @@ public: * up being a post-processing version of the tree. * ----------------------------------------------------------------------------- */ -void Swig_print_xml(DOH *obj, String* filename) -{ - XML xml; - xmllite = 1; +void Swig_print_xml(DOH *obj, String *filename) { + XML xml; + xmllite = 1; - if (! filename) { - out = stdout; + if (!filename) { + out = stdout; + } else { + out = NewFile(filename, "w"); + if (!out) { + FileErrorDisplay(filename); + SWIG_exit(EXIT_FAILURE); } - else { - out = NewFile(filename, "w"); - if (!out) { - FileErrorDisplay(filename); - SWIG_exit(EXIT_FAILURE); - } - } - - Printf( out, " \n" ); - xml.Xml_print_tree(obj); + } + + Printf(out, " \n"); + xml.Xml_print_tree(obj); } -static Language * new_swig_xml() { - return new XML(); +static Language *new_swig_xml() { + return new XML(); } -extern "C" Language * swig_xml( void ) { - return new_swig_xml(); +extern "C" Language *swig_xml(void) { + return new_swig_xml(); } diff --git a/SWIG/Source/Preprocessor/cpp.c b/SWIG/Source/Preprocessor/cpp.c index cbea9e53a..9eb29248b 100644 --- a/SWIG/Source/Preprocessor/cpp.c +++ b/SWIG/Source/Preprocessor/cpp.c @@ -19,16 +19,16 @@ char cvsroot_cpp_c[] = "$Header$"; #include "preprocessor.h" #include -static Hash *cpp = 0; /* C preprocessor data */ -static int include_all = 0; /* Follow all includes */ -static int ignore_missing = 0; -static int import_all = 0; /* Follow all includes, but as %import statements */ -static int imported_depth = 0; /* Depth of %imported files */ -static int single_include = 1; /* Only include each file once */ -static Hash *included_files = 0; -static List *dependencies = 0; +static Hash *cpp = 0; /* C preprocessor data */ +static int include_all = 0; /* Follow all includes */ +static int ignore_missing = 0; +static int import_all = 0; /* Follow all includes, but as %import statements */ +static int imported_depth = 0; /* Depth of %imported files */ +static int single_include = 1; /* Only include each file once */ +static Hash *included_files = 0; +static List *dependencies = 0; static SwigScanner *id_scan = 0; -static int error_as_warning = 0; /* Understand the cpp #error directive as a special #warning */ +static int error_as_warning = 0; /* Understand the cpp #error directive as a special #warning */ /* Test a character to see if it starts an identifier */ #define isidentifier(c) ((isalpha(c)) || (c == '_') || (c == '$')) @@ -38,59 +38,61 @@ static int error_as_warning = 0; /* Understand the cpp #error directive /* Skip whitespace */ -static void -skip_whitespace(String *s, String *out) { +static void skip_whitespace(String *s, String *out) { int c; while ((c = StringGetc(s)) != EOF) { if (!isspace(c)) { - StringUngetc(c,s); + StringUngetc(c, s); break; - } else if (out) StringPutc(c,out); + } else if (out) + StringPutc(c, out); } } /* Skip to a specified character taking line breaks into account */ -static int -skip_tochar(String *s, int ch, String *out) { +static int skip_tochar(String *s, int ch, String *out) { int c; while ((c = StringGetc(s)) != EOF) { - if (out) StringPutc(c,out); - if (c == ch) break; + if (out) + StringPutc(c, out); + if (c == ch) + break; if (c == '\\') { c = StringGetc(s); - if ((c != EOF) && (out)) StringPutc(c,out); + if ((c != EOF) && (out)) + StringPutc(c, out); } } - if (c == EOF) return -1; + if (c == EOF) + return -1; return 0; } -static void -copy_location(const DOH *s1, DOH *s2) { - Setfile(s2,Getfile((DOH *)s1)); - Setline(s2,Getline((DOH *)s1)); +static void copy_location(const DOH *s1, DOH *s2) { + Setfile(s2, Getfile((DOH *) s1)); + Setline(s2, Getline((DOH *) s1)); } static String *cpp_include(String_or_char *fn, int sysfile) { String *s = sysfile ? Swig_include_sys(fn) : Swig_include(fn); if (s && single_include) { String *file = Getfile(s); - if (Getattr(included_files,file)) { + if (Getattr(included_files, file)) { Delete(s); return 0; } - Setattr(included_files,file,file); + Setattr(included_files, file, file); } if (!s) { - Seek(fn,0,SEEK_SET); + Seek(fn, 0, SEEK_SET); if (ignore_missing) { - Swig_warning(WARN_PP_MISSING_FILE,Getfile(fn),Getline(fn),"Unable to find '%s'\n", fn); + Swig_warning(WARN_PP_MISSING_FILE, Getfile(fn), Getline(fn), "Unable to find '%s'\n", fn); } else { - Swig_error(Getfile(fn),Getline(fn),"Unable to find '%s'\n", fn); + Swig_error(Getfile(fn), Getline(fn), "Unable to find '%s'\n", fn); } } else { String *lf; - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); if (!dependencies) { dependencies = NewList(); } @@ -177,10 +179,10 @@ void Preprocessor_init(void) { kpp_FILE = NewString("__FILE__"); cpp = NewHash(); - s = NewHash(); - Setattr(cpp,kpp_symbols,s); + s = NewHash(); + Setattr(cpp, kpp_symbols, s); Delete(s); - Preprocessor_expr_init(); /* Initialize the expression evaluator */ + Preprocessor_expr_init(); /* Initialize the expression evaluator */ included_files = NewHash(); id_scan = NewSwigScanner();; @@ -257,10 +259,8 @@ void Preprocessor_error_as_warning(int a) { * SWIG macro semantics. * ----------------------------------------------------------------------------- */ - -String_or_char *Macro_vararg_name(String_or_char *str, - String_or_char *line) -{ + +String_or_char *Macro_vararg_name(String_or_char *str, String_or_char *line) { String_or_char *argname, *varargname; char *s, *dots; @@ -271,15 +271,14 @@ String_or_char *Macro_vararg_name(String_or_char *str, Delete(argname); return NULL; } - + if (strcmp(dots, "...") != 0) { - Swig_error(Getfile(line), Getline(line), - "Illegal macro argument name '%s'\n", str); + Swig_error(Getfile(line), Getline(line), "Illegal macro argument name '%s'\n", str); Delete(argname); return NULL; } if (dots == s) { - varargname = NewString("__VA_ARGS__"); + varargname = NewString("__VA_ARGS__"); } else { *dots = '\0'; varargname = NewString(s); @@ -288,14 +287,13 @@ String_or_char *Macro_vararg_name(String_or_char *str, return varargname; } -Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) -{ +Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) { String *macroname = 0, *argstr = 0, *macrovalue = 0, *file = 0, *s = 0; - Hash *macro = 0, *symbols = 0, *m1; - List *arglist = 0; + Hash *macro = 0, *symbols = 0, *m1; + List *arglist = 0; int c, line; - int varargs = 0; - String_or_char *str = (String_or_char *)_str; + int varargs = 0; + String_or_char *str = (String_or_char *) _str; assert(cpp); assert(str); @@ -303,100 +301,102 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) /* First make sure that string is actually a string */ if (DohCheck(str)) { s = Copy(str); - copy_location(str,s); + copy_location(str, s); str = s; } else { str = NewString((char *) str); } - Seek(str,0,SEEK_SET); + Seek(str, 0, SEEK_SET); line = Getline(str); file = Getfile(str); /* Skip over any leading whitespace */ - skip_whitespace(str,0); + skip_whitespace(str, 0); /* Now look for a macro name */ macroname = NewStringEmpty(); while ((c = StringGetc(str)) != EOF) { if (c == '(') { argstr = NewStringEmpty(); - copy_location(str,argstr); + copy_location(str, argstr); /* It is a macro. Go extract its argument string */ while ((c = StringGetc(str)) != EOF) { - if (c == ')') break; - else StringPutc(c,argstr); + if (c == ')') + break; + else + StringPutc(c, argstr); } if (c != ')') { - Swig_error(Getfile(str),Getline(str), "Missing \')\' in macro parameters\n"); + Swig_error(Getfile(str), Getline(str), "Missing \')\' in macro parameters\n"); goto macro_error; } break; } else if (isidchar(c) || (c == '%')) { - StringPutc(c,macroname); + StringPutc(c, macroname); } else if (isspace(c)) { break; } else if (c == '\\') { c = StringGetc(str); if (c != '\n') { - StringUngetc(c,str); - StringUngetc('\\',str); + StringUngetc(c, str); + StringUngetc('\\', str); break; } } else { /*Swig_error(Getfile(str),Getline(str),"Illegal character in macro name\n"); - goto macro_error; */ - StringUngetc(c,str); + goto macro_error; */ + StringUngetc(c, str); break; } } if (!swigmacro) - skip_whitespace(str,0); + skip_whitespace(str, 0); macrovalue = NewStringEmpty(); while ((c = StringGetc(str)) != EOF) { - StringPutc(c,macrovalue); + StringPutc(c, macrovalue); } /* If there are any macro arguments, convert into a list */ if (argstr) { String *argname, *varargname; arglist = NewList(); - Seek(argstr,0,SEEK_SET); + Seek(argstr, 0, SEEK_SET); argname = NewStringEmpty(); while ((c = StringGetc(argstr)) != EOF) { if (c == ',') { varargname = Macro_vararg_name(argname, str); if (varargname) { Delete(varargname); - Swig_error(Getfile(str),Getline(str),"Variable-length macro argument must be last parameter\n"); + Swig_error(Getfile(str), Getline(str), "Variable-length macro argument must be last parameter\n"); } else { - Append(arglist,argname); + Append(arglist, argname); } Delete(argname); argname = NewStringEmpty(); } else if (isidchar(c) || (c == '.')) { - StringPutc(c,argname); + StringPutc(c, argname); } else if (!(isspace(c) || (c == '\\'))) { Delete(argname); - Swig_error(Getfile(str),Getline(str),"Illegal character in macro argument name\n"); + Swig_error(Getfile(str), Getline(str), "Illegal character in macro argument name\n"); goto macro_error; } - } + } if (Len(argname)) { /* Check for varargs */ varargname = Macro_vararg_name(argname, str); if (varargname) { - Append(arglist,varargname); + Append(arglist, varargname); Delete(varargname); varargs = 1; } else { - Append(arglist,argname); + Append(arglist, argname); } } Delete(argname); } if (!swigmacro) { - Replace(macrovalue,"\\\n"," ", DOH_REPLACE_NOQUOTE); + Replace(macrovalue, "\\\n", " ", DOH_REPLACE_NOQUOTE); } /* Look for special # substitutions. We only consider # that appears @@ -406,41 +406,55 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) int state = 0; char *cc = Char(macrovalue); while (*cc) { - switch(state) { + switch (state) { case 0: - if (*cc == '#') *cc = '\001'; - else if (*cc == '/') state = 10; - else if (*cc == '\'') state = 20; - else if (*cc == '\"') state = 30; + if (*cc == '#') + *cc = '\001'; + else if (*cc == '/') + state = 10; + else if (*cc == '\'') + state = 20; + else if (*cc == '\"') + state = 30; break; case 10: - if (*cc == '*') state = 11; - else if (*cc == '/') state = 15; + if (*cc == '*') + state = 11; + else if (*cc == '/') + state = 15; else { state = 0; cc--; } break; case 11: - if (*cc == '*') state = 12; + if (*cc == '*') + state = 12; break; case 12: - if (*cc == '/') state = 0; - else if (*cc != '*') state = 11; + if (*cc == '/') + state = 0; + else if (*cc != '*') + state = 11; break; case 15: - if (*cc == '\n') state = 0; + if (*cc == '\n') + state = 0; break; case 20: - if (*cc == '\'') state = 0; - if (*cc == '\\') state = 21; + if (*cc == '\'') + state = 0; + if (*cc == '\\') + state = 21; break; case 21: state = 20; break; case 30: - if (*cc == '\"') state = 0; - if (*cc == '\\') state = 31; + if (*cc == '\"') + state = 0; + if (*cc == '\\') + state = 31; break; case 31: state = 30; @@ -454,56 +468,56 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) /* Get rid of whitespace surrounding # */ /* Replace(macrovalue,"#","\001",DOH_REPLACE_NOQUOTE); */ - while(strstr(Char(macrovalue),"\001 ")) { - Replace(macrovalue,"\001 ","\001", DOH_REPLACE_ANY); + while (strstr(Char(macrovalue), "\001 ")) { + Replace(macrovalue, "\001 ", "\001", DOH_REPLACE_ANY); } - while(strstr(Char(macrovalue)," \001")) { - Replace(macrovalue," \001","\001", DOH_REPLACE_ANY); + while (strstr(Char(macrovalue), " \001")) { + Replace(macrovalue, " \001", "\001", DOH_REPLACE_ANY); } /* Replace '##' with a special token */ - Replace(macrovalue,"\001\001","\002", DOH_REPLACE_ANY); + Replace(macrovalue, "\001\001", "\002", DOH_REPLACE_ANY); /* Replace '#@' with a special token */ - Replace(macrovalue,"\001@","\004", DOH_REPLACE_ANY); + Replace(macrovalue, "\001@", "\004", DOH_REPLACE_ANY); /* Replace '##@' with a special token */ - Replace(macrovalue,"\002@","\005", DOH_REPLACE_ANY); + Replace(macrovalue, "\002@", "\005", DOH_REPLACE_ANY); /* Go create the macro */ macro = NewHash(); - Setattr(macro,kpp_name,macroname); + Setattr(macro, kpp_name, macroname); if (arglist) { - Setattr(macro,kpp_args,arglist); + Setattr(macro, kpp_args, arglist); Delete(arglist); if (varargs) { - Setattr(macro,kpp_varargs,"1"); + Setattr(macro, kpp_varargs, "1"); } } - Setattr(macro,kpp_value,macrovalue); - Setline(macro,line); - Setfile(macro,file); + Setattr(macro, kpp_value, macrovalue); + Setline(macro, line); + Setfile(macro, file); if (swigmacro) { - Setattr(macro,kpp_swigmacro,"1"); + Setattr(macro, kpp_swigmacro, "1"); } - symbols = HashGetAttr(cpp,kpp_symbols); - if ((m1 = HashGetAttr(symbols,macroname))) { - if (!HashCheckAttr(m1,kpp_value,macrovalue)) { - Swig_error(Getfile(str),Getline(str),"Macro '%s' redefined,\n",macroname); - Swig_error(Getfile(m1),Getline(m1),"previous definition of '%s'.\n",macroname); + symbols = HashGetAttr(cpp, kpp_symbols); + if ((m1 = HashGetAttr(symbols, macroname))) { + if (!HashCheckAttr(m1, kpp_value, macrovalue)) { + Swig_error(Getfile(str), Getline(str), "Macro '%s' redefined,\n", macroname); + Swig_error(Getfile(m1), Getline(m1), "previous definition of '%s'.\n", macroname); goto macro_error; } } else { - Setattr(symbols,macroname,macro); + Setattr(symbols, macroname, macro); Delete(macro); } - + Delete(macroname); Delete(macrovalue); - + Delete(str); Delete(argstr); return macro; - macro_error: +macro_error: Delete(str); Delete(argstr); Delete(arglist); @@ -517,12 +531,11 @@ Hash *Preprocessor_define(const String_or_char *_str, int swigmacro) * * Undefines a macro. * ----------------------------------------------------------------------------- */ -void Preprocessor_undef(const String_or_char *str) -{ +void Preprocessor_undef(const String_or_char *str) { Hash *symbols; assert(cpp); - symbols = HashGetAttr(cpp,kpp_symbols); - Delattr(symbols,str); + symbols = HashGetAttr(cpp, kpp_symbols); + Delattr(symbols, str); } /* ----------------------------------------------------------------------------- @@ -531,27 +544,25 @@ void Preprocessor_undef(const String_or_char *str) * Isolates macro arguments and returns them in a list. For each argument, * leading and trailing whitespace is stripped (ala K&R, pg. 230). * ----------------------------------------------------------------------------- */ -static List * -find_args(String *s) -{ - List *args; +static List *find_args(String *s) { + List *args; String *str; - int c, level; - long pos; + int c, level; + long pos; /* Create a new list */ args = NewList(); - copy_location(s,args); + copy_location(s, args); /* First look for a '(' */ pos = Tell(s); - skip_whitespace(s,0); + skip_whitespace(s, 0); /* Now see if the next character is a '(' */ c = StringGetc(s); if (c != '(') { /* Not a macro, bail out now! */ - Seek(s,pos, SEEK_SET); + Seek(s, pos, SEEK_SET); Delete(args); return 0; } @@ -559,29 +570,33 @@ find_args(String *s) /* Okay. This appears to be a macro so we will start isolating arguments */ while (c != EOF) { if (isspace(c)) { - skip_whitespace(s,0); /* Skip leading whitespace */ + skip_whitespace(s, 0); /* Skip leading whitespace */ c = StringGetc(s); } str = NewStringEmpty(); - copy_location(s,str); + copy_location(s, str); level = 0; while (c != EOF) { if (c == '\"') { - StringPutc(c,str); - skip_tochar(s,'\"',str); + StringPutc(c, str); + skip_tochar(s, '\"', str); c = StringGetc(s); continue; } else if (c == '\'') { - StringPutc(c,str); - skip_tochar(s,'\'',str); + StringPutc(c, str); + skip_tochar(s, '\'', str); c = StringGetc(s); continue; } - if ((c == ',') && (level == 0)) break; - if ((c == ')') && (level == 0)) break; - StringPutc(c,str); - if (c == '(') level++; - if (c == ')') level--; + if ((c == ',') && (level == 0)) + break; + if ((c == ')') && (level == 0)) + break; + StringPutc(c, str); + if (c == '(') + level++; + if (c == ')') + level--; c = StringGetc(s); } if (level > 0) { @@ -589,17 +604,18 @@ find_args(String *s) } Chop(str); if (Len(args) || Len(str)) - Append(args,str); + Append(args, str); Delete(str); /* if (Len(str) && (c != ')')) - Append(args,str); */ + Append(args,str); */ - if (c == ')') return args; + if (c == ')') + return args; c = StringGetc(s); } - unterm: - Swig_error(Getfile(args),Getline(args),"Unterminated macro call.\n"); +unterm: + Swig_error(Getfile(args), Getline(args), "Unterminated macro call.\n"); return args; } @@ -610,25 +626,28 @@ find_args(String *s) * or bare. * ----------------------------------------------------------------------------- */ -static String * -get_filename(String *str, int* sysfile) { +static String *get_filename(String *str, int *sysfile) { String *fn; - int c; + int c; - skip_whitespace(str,0); + skip_whitespace(str, 0); fn = NewStringEmpty(); - copy_location(str,fn); + copy_location(str, fn); c = StringGetc(str); *sysfile = 0; if (c == '\"') { - while (((c = StringGetc(str)) != EOF) && (c != '\"')) StringPutc(c,fn); + while (((c = StringGetc(str)) != EOF) && (c != '\"')) + StringPutc(c, fn); } else if (c == '<') { *sysfile = 1; - while (((c = StringGetc(str)) != EOF) && (c != '>')) StringPutc(c,fn); + while (((c = StringGetc(str)) != EOF) && (c != '>')) + StringPutc(c, fn); } else { - StringPutc(c,fn); - while (((c = StringGetc(str)) != EOF) && (!isspace(c))) StringPutc(c,fn); - if (isspace(c)) StringUngetc(c,str); + StringPutc(c, fn); + while (((c = StringGetc(str)) != EOF) && (!isspace(c))) + StringPutc(c, fn); + if (isspace(c)) + StringUngetc(c, str); } #if defined(_WIN32) || defined(MACSWIG) /* accept Unix path separator on non-Unix systems */ @@ -638,35 +657,37 @@ get_filename(String *str, int* sysfile) { /* accept Windows path separator in addition to Unix path separator */ Replaceall(fn, "\\", SWIG_FILE_DELIMETER); #endif - Seek(fn,0,SEEK_SET); + Seek(fn, 0, SEEK_SET); return fn; } -static String * -get_options(String *str) { +static String *get_options(String *str) { - int c; - skip_whitespace(str,0); + int c; + skip_whitespace(str, 0); c = StringGetc(str); if (c == '(') { String *opt; - int level = 1; + int level = 1; opt = NewString("("); while (((c = StringGetc(str)) != EOF)) { - StringPutc(c,opt); + StringPutc(c, opt); if (c == ')') { level--; - if (!level) return opt; + if (!level) + return opt; } - if (c == '(') level++; + if (c == '(') + level++; } Delete(opt); return 0; } else { - StringUngetc(c,str); + StringUngetc(c, str); return 0; } } + /* ----------------------------------------------------------------------------- * expand_macro() * @@ -674,74 +695,75 @@ get_options(String *str) { * of error occurred. * ----------------------------------------------------------------------------- */ -static String * -expand_macro(String *name, List *args) -{ +static String *expand_macro(String *name, List *args) { String *ns; DOH *symbols, *macro, *margs, *mvalue, *temp, *tempa, *e; DOH *Preprocessor_replace(DOH *); int i, l; int isvarargs = 0; - symbols = HashGetAttr(cpp,kpp_symbols); - if (!symbols) return 0; + symbols = HashGetAttr(cpp, kpp_symbols); + if (!symbols) + return 0; /* See if the name is actually defined */ - macro = HashGetAttr(symbols,name); - if (!macro) return 0; - if (HashGetAttr(macro,kpp_expanded)) { + macro = HashGetAttr(symbols, name); + if (!macro) + return 0; + if (HashGetAttr(macro, kpp_expanded)) { ns = NewStringEmpty(); - StringAppend(ns,name); + StringAppend(ns, name); if (args) { int lenargs = Len(args); if (lenargs) - StringPutc('(',ns); + StringPutc('(', ns); for (i = 0; i < lenargs; i++) { - StringAppend(ns,Getitem(args,i)); - if (i < (lenargs -1)) StringPutc(',',ns); + StringAppend(ns, Getitem(args, i)); + if (i < (lenargs - 1)) + StringPutc(',', ns); } if (i) - StringPutc(')',ns); + StringPutc(')', ns); } return ns; } /* Get macro arguments and value */ - mvalue = HashGetAttr(macro,kpp_value); + mvalue = HashGetAttr(macro, kpp_value); assert(mvalue); - margs = HashGetAttr(macro,kpp_args); + margs = HashGetAttr(macro, kpp_args); - if (args && HashGetAttr(macro,kpp_varargs)) { + if (args && HashGetAttr(macro, kpp_varargs)) { isvarargs = 1; /* Variable length argument macro. We need to collect all of the extra arguments into a single argument */ - if (Len(args) >= (Len(margs)-1)) { + if (Len(args) >= (Len(margs) - 1)) { int i; int vi, na; String *vararg = NewStringEmpty(); - vi = Len(margs)-1; + vi = Len(margs) - 1; na = Len(args); for (i = vi; i < na; i++) { - StringAppend(vararg,Getitem(args,i)); - if ((i+1) < na) { - StringAppend(vararg,","); + StringAppend(vararg, Getitem(args, i)); + if ((i + 1) < na) { + StringAppend(vararg, ","); } } /* Remove arguments */ for (i = vi; i < na; i++) { - Delitem(args,vi); + Delitem(args, vi); } - Append(args,vararg); + Append(args, vararg); Delete(vararg); } } /* If there are arguments, see if they match what we were given */ if (args && (margs) && (Len(margs) != Len(args))) { - if (Len(margs) > (1+isvarargs)) - Swig_error(Getfile(args),Getline(args),"Macro '%s' expects %d arguments\n", name, Len(margs)-isvarargs); - else if (Len(margs) == (1+isvarargs)) - Swig_error(Getfile(args),Getline(args),"Macro '%s' expects 1 argument\n", name); + if (Len(margs) > (1 + isvarargs)) + Swig_error(Getfile(args), Getline(args), "Macro '%s' expects %d arguments\n", name, Len(margs) - isvarargs); + else if (Len(margs) == (1 + isvarargs)) + Swig_error(Getfile(args), Getline(args), "Macro '%s' expects 1 argument\n", name); else - Swig_error(Getfile(args),Getline(args),"Macro '%s' expects no arguments\n", name); + Swig_error(Getfile(args), Getline(args), "Macro '%s' expects no arguments\n", name); return 0; } @@ -752,7 +774,7 @@ expand_macro(String *name, List *args) /* Copy the macro value */ ns = Copy(mvalue); - copy_location(mvalue,ns); + copy_location(mvalue, ns); /* Tag the macro as being expanded. This is to avoid recursion in macro expansion */ @@ -764,130 +786,132 @@ expand_macro(String *name, List *args) for (i = 0; i < l; i++) { DOH *arg, *aname; String *reparg; - arg = Getitem(args,i); /* Get an argument value */ + arg = Getitem(args, i); /* Get an argument value */ reparg = Preprocessor_replace(arg); - aname = Getitem(margs,i); /* Get macro argument name */ - if (strstr(StringChar(ns),"\001")) { + aname = Getitem(margs, i); /* Get macro argument name */ + if (strstr(StringChar(ns), "\001")) { /* Try to replace a quoted version of the argument */ Clear(temp); Clear(tempa); - Printf(temp,"\001%s", aname); - Printf(tempa,"\"%s\"",arg); + Printf(temp, "\001%s", aname); + Printf(tempa, "\"%s\"", arg); Replace(ns, temp, tempa, DOH_REPLACE_ID_END); } - if (strstr(StringChar(ns),"\002")) { + if (strstr(StringChar(ns), "\002")) { /* Look for concatenation tokens */ Clear(temp); Clear(tempa); - Printf(temp,"\002%s",aname); - StringAppend(tempa,"\002\003"); + Printf(temp, "\002%s", aname); + StringAppend(tempa, "\002\003"); Replace(ns, temp, tempa, DOH_REPLACE_ID_END); Clear(temp); Clear(tempa); - Printf(temp,"%s\002",aname); - StringAppend(tempa,"\003\002"); - Replace(ns,temp,tempa, DOH_REPLACE_ID_BEGIN); + Printf(temp, "%s\002", aname); + StringAppend(tempa, "\003\002"); + Replace(ns, temp, tempa, DOH_REPLACE_ID_BEGIN); } /* Non-standard macro expansion. The value `x` is replaced by a quoted - version of the argument except that if the argument is already quoted - nothing happens */ + version of the argument except that if the argument is already quoted + nothing happens */ - if (strchr(StringChar(ns),'`')) { + if (strchr(StringChar(ns), '`')) { String *rep; char *c; Clear(temp); - Printf(temp,"`%s`",aname); + Printf(temp, "`%s`", aname); c = Char(arg); if (*c == '\"') { rep = arg; } else { Clear(tempa); - Printf(tempa,"\"%s\"",arg); + Printf(tempa, "\"%s\"", arg); rep = tempa; } - Replace(ns,temp,rep, DOH_REPLACE_ANY); + Replace(ns, temp, rep, DOH_REPLACE_ANY); } /* Non-standard mangle expansions. - The #@Name is replaced by mangle_arg(Name). */ - if (strstr(StringChar(ns),"\004")) { - String* marg = Swig_string_mangle(arg); + The #@Name is replaced by mangle_arg(Name). */ + if (strstr(StringChar(ns), "\004")) { + String *marg = Swig_string_mangle(arg); Clear(temp); - Printf(temp,"\004%s", aname); + Printf(temp, "\004%s", aname); Replace(ns, temp, marg, DOH_REPLACE_ID_END); Delete(marg); } - if (strstr(StringChar(ns),"\005")) { - String* marg = Swig_string_mangle(arg); + if (strstr(StringChar(ns), "\005")) { + String *marg = Swig_string_mangle(arg); Clear(temp); Clear(tempa); - Printf(temp,"\005%s", aname); - Printf(tempa,"\"%s\"", marg); + Printf(temp, "\005%s", aname); + Printf(tempa, "\"%s\"", marg); Replace(ns, temp, tempa, DOH_REPLACE_ID_END); Delete(marg); } - if (isvarargs && i == l-1 && Len(arg) == 0) { + if (isvarargs && i == l - 1 && Len(arg) == 0) { /* Zero length varargs macro argument. We search for commas that might appear before and nuke them */ char *a, *s, *t, *name; - int namelen; + int namelen; s = StringChar(ns); - name = Char(aname); - namelen = Len(aname); - a = strstr(s,name); + name = Char(aname); + namelen = Len(aname); + a = strstr(s, name); while (a) { - char ca = a[namelen+1]; - if (!isidchar((int)ca)) { - /* Matched the entire vararg name, not just a prefix */ - t = a-1; + char ca = a[namelen + 1]; + if (!isidchar((int) ca)) { + /* Matched the entire vararg name, not just a prefix */ + t = a - 1; if (*t == '\002') { t--; while (t >= s) { - if (isspace((int) *t)) t--; + if (isspace((int) *t)) + t--; else if (*t == ',') { *t = ' '; - } else break; + } else + break; } } } - a = strstr(a+namelen,name); + a = strstr(a + namelen, name); } } /* Replace(ns, aname, arg, DOH_REPLACE_ID); */ - Replace(ns, aname, reparg, DOH_REPLACE_ID); /* Replace expanded args */ - Replace(ns, "\003", arg, DOH_REPLACE_ANY); /* Replace unexpanded arg */ + Replace(ns, aname, reparg, DOH_REPLACE_ID); /* Replace expanded args */ + Replace(ns, "\003", arg, DOH_REPLACE_ANY); /* Replace unexpanded arg */ Delete(reparg); } } - Replace(ns,"\002","",DOH_REPLACE_ANY); /* Get rid of concatenation tokens */ - Replace(ns,"\001","#",DOH_REPLACE_ANY); /* Put # back (non-standard C) */ - Replace(ns,"\004","#@",DOH_REPLACE_ANY); /* Put # back (non-standard C) */ + Replace(ns, "\002", "", DOH_REPLACE_ANY); /* Get rid of concatenation tokens */ + Replace(ns, "\001", "#", DOH_REPLACE_ANY); /* Put # back (non-standard C) */ + Replace(ns, "\004", "#@", DOH_REPLACE_ANY); /* Put # back (non-standard C) */ /* Expand this macro even further */ - Setattr(macro,kpp_expanded,"1"); + Setattr(macro, kpp_expanded, "1"); e = Preprocessor_replace(ns); - Delattr(macro,kpp_expanded); + Delattr(macro, kpp_expanded); Delete(ns); - if (HashGetAttr(macro,kpp_swigmacro)) { + if (HashGetAttr(macro, kpp_swigmacro)) { String *g; String *f = NewStringEmpty(); - Seek(e,0,SEEK_SET); - copy_location(macro,e); + Seek(e, 0, SEEK_SET); + copy_location(macro, e); g = Preprocessor_parse(e); #if 0 /* Drop the macro in place, but with a marker around it */ - Printf(f,"/*@%s,%d,%s@*/%s/*@@*/", Getfile(macro), Getline(macro), name, g); + Printf(f, "/*@%s,%d,%s@*/%s/*@@*/", Getfile(macro), Getline(macro), name, g); #else /* Use simplified around markers to properly count lines in cscanner.c */ - if (strchr(Char(g),'\n')) { - Printf(f,"/*@SWIG:%s@*/%s/*@SWIG@*/", name, g); + if (strchr(Char(g), '\n')) { + Printf(f, "/*@SWIG:%s@*/%s/*@SWIG@*/", name, g); } else { - StringAppend(f,g); + StringAppend(f, g); } #endif @@ -912,7 +936,7 @@ List *evaluate_args(List *x) { List *nl = NewList(); for (i = First(x); i.item; i = Next(i)) { - Append(nl,Preprocessor_replace(i.item)); + Append(nl, Preprocessor_replace(i.item)); } return nl; } @@ -928,20 +952,18 @@ List *evaluate_args(List *x) { /* #define SWIG_PUT_BUFF */ -DOH * -Preprocessor_replace(DOH *s) -{ - DOH *ns, *symbols, *m; - int c, i, state = 0; +DOH *Preprocessor_replace(DOH *s) { + DOH *ns, *symbols, *m; + int c, i, state = 0; + + String *id = NewStringEmpty(); - String *id = NewStringEmpty(); - assert(cpp); - symbols = HashGetAttr(cpp,kpp_symbols); + symbols = HashGetAttr(cpp, kpp_symbols); ns = NewStringEmpty(); - copy_location(s,ns); - Seek(s,0,SEEK_SET); + copy_location(s, ns); + Seek(s, 0, SEEK_SET); /* Try to locate identifiers in s and replace them with macro replacements */ while ((c = StringGetc(s)) != EOF) { @@ -949,92 +971,95 @@ Preprocessor_replace(DOH *s) case 0: if (isidentifier(c) || (c == '%')) { Clear(id); - StringPutc(c,id); + StringPutc(c, id); state = 1; } else if (c == '\"') { - StringPutc(c,ns); - skip_tochar(s,'\"',ns); + StringPutc(c, ns); + skip_tochar(s, '\"', ns); } else if (c == '\'') { - StringPutc(c,ns); - skip_tochar(s,'\'',ns); + StringPutc(c, ns); + skip_tochar(s, '\'', ns); } else if (c == '/') { - StringPutc(c,ns); + StringPutc(c, ns); state = 10; } else { - StringPutc(c,ns); + StringPutc(c, ns); } break; - case 1: /* An identifier */ + case 1: /* An identifier */ if (isidchar(c)) { - StringPutc(c,id); + StringPutc(c, id); state = 1; } else { /* We found the end of a valid identifier */ - StringUngetc(c,s); + StringUngetc(c, s); /* See if this is the special "defined" macro */ - if (StringEqual(kpp_defined,id)) { + if (StringEqual(kpp_defined, id)) { int lenargs = 0; DOH *args = 0; /* See whether or not a paranthesis has been used */ - skip_whitespace(s,0); + skip_whitespace(s, 0); c = StringGetc(s); if (c == '(') { - StringUngetc(c,s); + StringUngetc(c, s); args = find_args(s); } else if (isidchar(c)) { DOH *arg = NewStringEmpty(); args = NewList(); - StringPutc(c,arg); + StringPutc(c, arg); while (((c = StringGetc(s)) != EOF)) { if (!isidchar(c)) { - StringUngetc(c,s); + StringUngetc(c, s); break; } - StringPutc(c,arg); + StringPutc(c, arg); } - if (Len(arg)) Append(args,arg); + if (Len(arg)) + Append(args, arg); Delete(arg); } else { - Seek(s,-1,SEEK_CUR); + Seek(s, -1, SEEK_CUR); } lenargs = Len(args); if ((!args) || (!lenargs)) { /* This is not a defined() macro. */ - StringAppend(ns,id); + StringAppend(ns, id); state = 0; break; } for (i = 0; i < lenargs; i++) { - DOH *o = Getitem(args,i); - if (!HashGetAttr(symbols,o)) { + DOH *o = Getitem(args, i); + if (!HashGetAttr(symbols, o)) { break; } } - if (i < lenargs) StringPutc('0',ns); - else StringPutc('1',ns); + if (i < lenargs) + StringPutc('0', ns); + else + StringPutc('1', ns); Delete(args); state = 0; break; } - if (StringEqual(kpp_LINE,id)) { - Printf(ns,"%d",Getline(s)); + if (StringEqual(kpp_LINE, id)) { + Printf(ns, "%d", Getline(s)); state = 0; break; } - if (StringEqual(kpp_FILE,id)) { + if (StringEqual(kpp_FILE, id)) { String *fn = Copy(Getfile(s)); - Replaceall(fn,"\\","\\\\"); - Printf(ns,"\"%s\"",fn); + Replaceall(fn, "\\", "\\\\"); + Printf(ns, "\"%s\"", fn); Delete(fn); state = 0; break; } /* See if the macro is defined in the preprocessor symbol table */ - if ((m = HashGetAttr(symbols,id))) { + if ((m = HashGetAttr(symbols, id))) { DOH *args = 0; DOH *e; /* See if the macro expects arguments */ - if (HashGetAttr(m,kpp_args)) { + if (HashGetAttr(m, kpp_args)) { /* Yep. We need to go find the arguments and do a substitution */ args = find_args(s); if (!Len(args)) { @@ -1043,41 +1068,47 @@ Preprocessor_replace(DOH *s) } } else { args = 0; - } - e = expand_macro(id,args); + } + e = expand_macro(id, args); if (e) { - StringAppend(ns,e); + StringAppend(ns, e); } Delete(e); Delete(args); } else { - StringAppend(ns,id); + StringAppend(ns, id); } state = 0; } break; case 10: - if (c == '/') state = 11; - else if (c == '*') state = 12; + if (c == '/') + state = 11; + else if (c == '*') + state = 12; else { - StringUngetc(c,s); + StringUngetc(c, s); state = 0; break; } - StringPutc(c,ns); + StringPutc(c, ns); break; case 11: - StringPutc(c,ns); - if (c == '\n') state = 0; + StringPutc(c, ns); + if (c == '\n') + state = 0; break; case 12: - StringPutc(c,ns); - if (c == '*') state = 13; + StringPutc(c, ns); + if (c == '*') + state = 13; break; case 13: - StringPutc(c,ns); - if (c == '/') state = 0; - else if (c != '*') state = 12; + StringPutc(c, ns); + if (c == '/') + state = 0; + else if (c != '*') + state = 12; break; default: state = 0; @@ -1088,20 +1119,20 @@ Preprocessor_replace(DOH *s) /* Identifier at the end */ if (state == 1) { /* See if this is the special "defined" macro */ - if (StringEqual(kpp_defined,id)) { - Swig_error(Getfile(s),Getline(s),"No arguments given to defined()\n"); - } else if ((m = HashGetAttr(symbols,id))) { - DOH *e; - /* Yes. There is a macro here */ - /* See if the macro expects arguments */ - /* if (Getattr(m,"args")) { - Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n"); - } */ - e = expand_macro(id,0); - StringAppend(ns,e); - Delete(e); + if (StringEqual(kpp_defined, id)) { + Swig_error(Getfile(s), Getline(s), "No arguments given to defined()\n"); + } else if ((m = HashGetAttr(symbols, id))) { + DOH *e; + /* Yes. There is a macro here */ + /* See if the macro expects arguments */ + /* if (Getattr(m,"args")) { + Swig_error(Getfile(id),Getline(id),"Macro arguments expected.\n"); + } */ + e = expand_macro(id, 0); + StringAppend(ns, e); + Delete(e); } else { - StringAppend(ns,id); + StringAppend(ns, id); } } Delete(id); @@ -1116,37 +1147,36 @@ Preprocessor_replace(DOH *s) * function contains the heuristic that determines whether or not a macro * definition passes through the preprocessor as a constant declaration. * ----------------------------------------------------------------------------- */ -static int -checkpp_id(DOH *s) -{ +static int checkpp_id(DOH *s) { int c; int hastok = 0; SwigScanner *scan = id_scan; - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); SwigScanner_clear(scan); s = Copy(s); - Seek(s,SEEK_SET,0); - SwigScanner_push(scan,s); + Seek(s, SEEK_SET, 0); + SwigScanner_push(scan, s); while ((c = SwigScanner_token(scan))) { hastok = 1; - if ((c == SWIG_TOKEN_ID) || (c == SWIG_TOKEN_LBRACE) || (c == SWIG_TOKEN_RBRACE)) return 1; + if ((c == SWIG_TOKEN_ID) || (c == SWIG_TOKEN_LBRACE) || (c == SWIG_TOKEN_RBRACE)) + return 1; } - if (!hastok) return 1; + if (!hastok) + return 1; return 0; } /* addline(). Utility function for adding lines to a chunk */ -static void -addline(DOH *s1, DOH *s2, int allow) -{ +static void addline(DOH *s1, DOH *s2, int allow) { if (allow) { - StringAppend(s1,s2); + StringAppend(s1, s2); } else { char *c = Char(s2); while (*c) { - if (*c == '\n') StringPutc('\n',s1); + if (*c == '\n') + StringPutc('\n', s1); c++; } } @@ -1154,13 +1184,13 @@ addline(DOH *s1, DOH *s2, int allow) static void add_chunk(DOH *ns, DOH *chunk, int allow) { DOH *echunk; - Seek(chunk,0,SEEK_SET); + Seek(chunk, 0, SEEK_SET); if (allow) { echunk = Preprocessor_replace(chunk); - addline(ns,echunk,allow); + addline(ns, echunk, allow); Delete(echunk); } else { - addline(ns,chunk,0); + addline(ns, chunk, 0); } Clear(chunk); } @@ -1169,16 +1199,14 @@ static void add_chunk(DOH *ns, DOH *chunk, int allow) { push/pop_imported(): helper functions for defining and undefining SWIGIMPORTED (when %importing a file). */ -static void -push_imported() { +static void push_imported() { if (imported_depth == 0) { Preprocessor_define("SWIGIMPORTED 1", 0); } ++imported_depth; } -static void -pop_imported() { +static void pop_imported() { --imported_depth; if (imported_depth == 0) { Preprocessor_undef("SWIGIMPORTED"); @@ -1199,137 +1227,143 @@ pop_imported() { * included inline (with all preprocessor directives included). * ----------------------------------------------------------------------------- */ -String * -Preprocessor_parse(String *s) -{ - String *ns; /* New string containing the preprocessed text */ - String *chunk, *decl; - Hash *symbols; - String *id = 0, *value = 0, *comment = 0; - int i, state, e, c; - int start_line = 0; - int allow = 1; - int level = 0; - int dlevel = 0; - int mask = 0; - int start_level = 0; - int cpp_lines = 0; - int cond_lines[256]; +String *Preprocessor_parse(String *s) { + String *ns; /* New string containing the preprocessed text */ + String *chunk, *decl; + Hash *symbols; + String *id = 0, *value = 0, *comment = 0; + int i, state, e, c; + int start_line = 0; + int allow = 1; + int level = 0; + int dlevel = 0; + int mask = 0; + int start_level = 0; + int cpp_lines = 0; + int cond_lines[256]; /* Blow away all carriage returns */ - Replace(s,"\015","",DOH_REPLACE_ANY); + Replace(s, "\015", "", DOH_REPLACE_ANY); - ns = NewStringEmpty(); /* Return result */ + ns = NewStringEmpty(); /* Return result */ decl = NewStringEmpty(); id = NewStringEmpty(); value = NewStringEmpty(); comment = NewStringEmpty(); chunk = NewStringEmpty(); - copy_location(s,chunk); - copy_location(s,ns); - symbols = HashGetAttr(cpp,kpp_symbols); + copy_location(s, chunk); + copy_location(s, ns); + symbols = HashGetAttr(cpp, kpp_symbols); state = 0; while ((c = StringGetc(s)) != EOF) { - switch(state) { - case 0: /* Initial state - in first column */ + switch (state) { + case 0: /* Initial state - in first column */ /* Look for C preprocessor directives. Otherwise, go directly to state 1 */ if (c == '#') { - add_chunk(ns,chunk,allow); - copy_location(s,chunk); + add_chunk(ns, chunk, allow); + copy_location(s, chunk); cpp_lines = 1; state = 40; } else if (isspace(c)) { - StringPutc(c,chunk); - skip_whitespace(s,chunk); + StringPutc(c, chunk); + skip_whitespace(s, chunk); } else { state = 1; - StringUngetc(c,s); + StringUngetc(c, s); } break; - case 1: /* Non-preprocessor directive */ + case 1: /* Non-preprocessor directive */ /* Look for SWIG directives */ if (c == '%') { state = 100; break; } - StringPutc(c,chunk); - if (c == '\n') state = 0; + StringPutc(c, chunk); + if (c == '\n') + state = 0; else if (c == '\"') { start_line = Getline(s); - if (skip_tochar(s,'\"',chunk) < 0) { - Swig_error(Getfile(s),-1,"Unterminated string constant starting at line %d\n",start_line); + if (skip_tochar(s, '\"', chunk) < 0) { + Swig_error(Getfile(s), -1, "Unterminated string constant starting at line %d\n", start_line); } } else if (c == '\'') { start_line = Getline(s); - if (skip_tochar(s,'\'',chunk) < 0) { - Swig_error(Getfile(s),-1,"Unterminated character constant starting at line %d\n",start_line); + if (skip_tochar(s, '\'', chunk) < 0) { + Swig_error(Getfile(s), -1, "Unterminated character constant starting at line %d\n", start_line); } - } - else if (c == '/') state = 30; /* Comment */ + } else if (c == '/') + state = 30; /* Comment */ break; - case 30: /* Possibly a comment string of some sort */ + case 30: /* Possibly a comment string of some sort */ start_line = Getline(s); - StringPutc(c,chunk); - if (c == '/') state = 31; - else if (c == '*') state = 32; - else state = 1; + StringPutc(c, chunk); + if (c == '/') + state = 31; + else if (c == '*') + state = 32; + else + state = 1; break; case 31: - StringPutc(c,chunk); - if (c == '\n') state = 0; + StringPutc(c, chunk); + if (c == '\n') + state = 0; break; case 32: - StringPutc(c,chunk); - if (c == '*') state = 33; + StringPutc(c, chunk); + if (c == '*') + state = 33; break; case 33: - StringPutc(c,chunk); - if (c == '/') state = 1; - else if (c != '*') state = 32; + StringPutc(c, chunk); + if (c == '/') + state = 1; + else if (c != '*') + state = 32; break; - case 40: /* Start of a C preprocessor directive */ + case 40: /* Start of a C preprocessor directive */ if (c == '\n') { - StringPutc('\n',chunk); + StringPutc('\n', chunk); state = 0; } else if (isspace(c)) { state = 40; } else { /* Got the start of a preprocessor directive */ - StringUngetc(c,s); + StringUngetc(c, s); Clear(id); - copy_location(s,id); + copy_location(s, id); state = 41; } break; - case 41: /* Build up the name of the preprocessor directive */ + case 41: /* Build up the name of the preprocessor directive */ if ((isspace(c) || (!isalpha(c)))) { Clear(value); Clear(comment); if (c == '\n') { - StringUngetc(c,s); + StringUngetc(c, s); state = 50; } else { state = 42; if (!isspace(c)) { - StringUngetc(c,s); + StringUngetc(c, s); } } - copy_location(s,value); + copy_location(s, value); break; } - StringPutc(c,id); + StringPutc(c, id); break; - case 42: /* Strip any leading space before preprocessor value */ + case 42: /* Strip any leading space before preprocessor value */ if (isspace(c)) { if (c == '\n') { - StringUngetc(c,s); + StringUngetc(c, s); state = 50; } break; @@ -1340,28 +1374,29 @@ Preprocessor_parse(String *s) case 43: /* Get preprocessor value */ if (c == '\n') { - StringUngetc(c,s); + StringUngetc(c, s); state = 50; } else if (c == '/') { state = 45; } else if (c == '\"') { - StringPutc(c,value); - skip_tochar(s,'\"',value); + StringPutc(c, value); + skip_tochar(s, '\"', value); } else if (c == '\'') { - StringPutc(c,value); - skip_tochar(s,'\'',value); + StringPutc(c, value); + skip_tochar(s, '\'', value); } else { - StringPutc(c,value); - if (c == '\\') state = 44; + StringPutc(c, value); + if (c == '\\') + state = 44; } break; case 44: if (c == '\n') { - StringPutc(c,value); + StringPutc(c, value); cpp_lines++; } else { - StringUngetc(c,s); + StringUngetc(c, s); } state = 43; break; @@ -1370,59 +1405,66 @@ Preprocessor_parse(String *s) will be placed in the output in an alternative form */ case 45: - if (c == '/') state = 46; - else if (c == '*') state = 47; + if (c == '/') + state = 46; + else if (c == '*') + state = 47; else if (c == '\n') { - StringPutc('/',value); - StringUngetc(c,s); + StringPutc('/', value); + StringUngetc(c, s); cpp_lines++; state = 50; } else { - StringPutc('/',value); - StringPutc(c,value); + StringPutc('/', value); + StringPutc(c, value); state = 43; } break; case 46: if (c == '\n') { - StringUngetc(c,s); + StringUngetc(c, s); cpp_lines++; state = 50; - } else StringPutc(c,comment); + } else + StringPutc(c, comment); break; case 47: - if (c == '*') state = 48; - else StringPutc(c,comment); + if (c == '*') + state = 48; + else + StringPutc(c, comment); break; case 48: - if (c == '/') state = 43; - else if (c == '*') StringPutc(c,comment); + if (c == '/') + state = 43; + else if (c == '*') + StringPutc(c, comment); else { - StringPutc('*',comment); - StringPutc(c,comment); + StringPutc('*', comment); + StringPutc(c, comment); state = 47; } break; case 50: /* Check for various preprocessor directives */ Chop(value); - if (StringEqual(id,kpp_define)) { + if (StringEqual(id, kpp_define)) { if (allow) { DOH *m, *v, *v1; - Seek(value,0,SEEK_SET); - m = Preprocessor_define(value,0); - if ((m) && !(HashGetAttr(m,kpp_args))) { - v = Copy(HashGetAttr(m,kpp_value)); + Seek(value, 0, SEEK_SET); + m = Preprocessor_define(value, 0); + if ((m) && !(HashGetAttr(m, kpp_args))) { + v = Copy(HashGetAttr(m, kpp_value)); if (Len(v)) { Swig_error_silent(1); v1 = Preprocessor_replace(v); Swig_error_silent(0); - /* Printf(stdout,"checking '%s'\n", v1); */ + /* Printf(stdout,"checking '%s'\n", v1); */ if (!checkpp_id(v1)) { if (Len(comment) == 0) - Printf(ns,"%%constant %s = %s;\n", HashGetAttr(m,kpp_name), v1); + Printf(ns, "%%constant %s = %s;\n", HashGetAttr(m, kpp_name), v1); else - Printf(ns,"%%constant %s = %s; /*%s*/\n", HashGetAttr(m,kpp_name),v1,comment); + Printf(ns, "%%constant %s = %s; /*%s*/\n", HashGetAttr(m, kpp_name), v1, comment); cpp_lines--; } Delete(v1); @@ -1430,42 +1472,45 @@ Preprocessor_parse(String *s) Delete(v); } } - } else if (StringEqual(id,kpp_undef)) { - if (allow) Preprocessor_undef(value); - } else if (StringEqual(id,kpp_ifdef)) { + } else if (StringEqual(id, kpp_undef)) { + if (allow) + Preprocessor_undef(value); + } else if (StringEqual(id, kpp_ifdef)) { cond_lines[level] = Getline(id); level++; if (allow) { start_level = level; /* See if the identifier is in the hash table */ - if (!HashGetAttr(symbols,value)) allow = 0; + if (!HashGetAttr(symbols, value)) + allow = 0; mask = 1; } - } else if (StringEqual(id,kpp_ifndef)) { + } else if (StringEqual(id, kpp_ifndef)) { cond_lines[level] = Getline(id); level++; if (allow) { start_level = level; /* See if the identifier is in the hash table */ - if (HashGetAttr(symbols,value)) allow = 0; + if (HashGetAttr(symbols, value)) + allow = 0; mask = 1; } - } else if (StringEqual(id,kpp_else)) { + } else if (StringEqual(id, kpp_else)) { if (level <= 0) { - Swig_error(Getfile(s),Getline(id),"Misplaced #else.\n"); + Swig_error(Getfile(s), Getline(id), "Misplaced #else.\n"); } else { - cond_lines[level-1] = Getline(id); + cond_lines[level - 1] = Getline(id); if (allow) { allow = 0; mask = 0; } else if (level == start_level) { - allow = 1*mask; + allow = 1 * mask; } } - } else if (StringEqual(id,kpp_endif)) { + } else if (StringEqual(id, kpp_endif)) { level--; if (level < 0) { - Swig_error(Getfile(id),Getline(id),"Extraneous #endif.\n"); + Swig_error(Getfile(id), Getline(id), "Extraneous #endif.\n"); level = 0; } else { if (level < start_level) { @@ -1473,99 +1518,101 @@ Preprocessor_parse(String *s) start_level--; } } - } else if (StringEqual(id,kpp_if)) { + } else if (StringEqual(id, kpp_if)) { cond_lines[level] = Getline(id); level++; if (allow) { int val; String *sval = Preprocessor_replace(value); start_level = level; - Seek(sval,0,SEEK_SET); - /* Printf(stdout,"Evaluating '%s'\n", sval); */ - val = Preprocessor_expr(sval,&e); - if (e) { - char * msg = Preprocessor_expr_error(); - Seek(value,0,SEEK_SET); - Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Could not evaluate '%s'\n", value); + Seek(sval, 0, SEEK_SET); + /* Printf(stdout,"Evaluating '%s'\n", sval); */ + val = Preprocessor_expr(sval, &e); + if (e) { + char *msg = Preprocessor_expr_error(); + Seek(value, 0, SEEK_SET); + Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate '%s'\n", value); if (msg) - Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Error: '%s'\n", msg); - allow = 0; - } else { - if (val == 0) - allow = 0; - } - mask = 1; - } - } else if (StringEqual(id,kpp_elif)) { - if (level == 0) { - Swig_error(Getfile(s),Getline(id),"Misplaced #elif.\n"); - } else { - cond_lines[level-1] = Getline(id); - if (allow) { - allow = 0; - mask = 0; - } else if (level == start_level) { - int val; - String *sval = Preprocessor_replace(value); - Seek(sval,0,SEEK_SET); - val = Preprocessor_expr(sval,&e); - if (e) { - char * msg = Preprocessor_expr_error(); - Seek(value,0,SEEK_SET); - Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Could not evaluate '%s'\n", value); - if (msg) - Swig_warning(WARN_PP_EVALUATION,Getfile(value),Getline(value),"Error: '%s'\n", msg); - allow = 0; - } else { - if (val) - allow = 1*mask; - else - allow = 0; - } - } - } - } else if (StringEqual(id,kpp_warning)) { - if (allow) { - Swig_warning(WARN_PP_CPP_WARNING,Getfile(s),Getline(id),"CPP #warning, %s\n", value); + Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg); + allow = 0; + } else { + if (val == 0) + allow = 0; + } + mask = 1; } - } else if (StringEqual(id,kpp_error)) { + } else if (StringEqual(id, kpp_elif)) { + if (level == 0) { + Swig_error(Getfile(s), Getline(id), "Misplaced #elif.\n"); + } else { + cond_lines[level - 1] = Getline(id); + if (allow) { + allow = 0; + mask = 0; + } else if (level == start_level) { + int val; + String *sval = Preprocessor_replace(value); + Seek(sval, 0, SEEK_SET); + val = Preprocessor_expr(sval, &e); + if (e) { + char *msg = Preprocessor_expr_error(); + Seek(value, 0, SEEK_SET); + Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Could not evaluate '%s'\n", value); + if (msg) + Swig_warning(WARN_PP_EVALUATION, Getfile(value), Getline(value), "Error: '%s'\n", msg); + allow = 0; + } else { + if (val) + allow = 1 * mask; + else + allow = 0; + } + } + } + } else if (StringEqual(id, kpp_warning)) { + if (allow) { + Swig_warning(WARN_PP_CPP_WARNING, Getfile(s), Getline(id), "CPP #warning, %s\n", value); + } + } else if (StringEqual(id, kpp_error)) { if (allow) { if (error_as_warning) { - Swig_warning(WARN_PP_CPP_ERROR,Getfile(s),Getline(id),"CPP #error \"%s\".\n", value); + Swig_warning(WARN_PP_CPP_ERROR, Getfile(s), Getline(id), "CPP #error \"%s\".\n", value); } else { - Swig_error(Getfile(s),Getline(id),"CPP #error \"%s\". Use the -cpperraswarn option to continue swig processing.\n", value); + Swig_error(Getfile(s), Getline(id), "CPP #error \"%s\". Use the -cpperraswarn option to continue swig processing.\n", value); } } - } else if (StringEqual(id,kpp_line)) { - } else if (StringEqual(id,kpp_include)) { - if (((include_all) || (import_all)) && (allow)) { - String *s1, *s2, *fn; - char *dirname; int sysfile = 0; + } else if (StringEqual(id, kpp_line)) { + } else if (StringEqual(id, kpp_include)) { + if (((include_all) || (import_all)) && (allow)) { + String *s1, *s2, *fn; + char *dirname; + int sysfile = 0; if (include_all && import_all) { - Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL,Getfile(s),Getline(id),"Both includeall and importall are defined: using includeall"); + Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL, Getfile(s), Getline(id), "Both includeall and importall are defined: using includeall"); import_all = 0; } - Seek(value,0,SEEK_SET); - fn = get_filename(value, &sysfile); + Seek(value, 0, SEEK_SET); + fn = get_filename(value, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { - if (include_all) - Printf(ns,"%%includefile \"%s\" [\n", Swig_last_file()); + if (include_all) + Printf(ns, "%%includefile \"%s\" [\n", Swig_last_file()); else if (import_all) { - Printf(ns,"%%importfile \"%s\" [\n", Swig_last_file()); + Printf(ns, "%%importfile \"%s\" [\n", Swig_last_file()); push_imported(); } /* See if the filename has a directory component */ dirname = Swig_file_dirname(Swig_last_file()); - if (sysfile || !strlen(dirname)) dirname = 0; + if (sysfile || !strlen(dirname)) + dirname = 0; if (dirname) { - dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ + dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimeter */ Swig_push_directory(dirname); } - s2 = Preprocessor_parse(s1); - addline(ns,s2,allow); - StringAppend(ns,"\n]"); + s2 = Preprocessor_parse(s1); + addline(ns, s2, allow); + StringAppend(ns, "\n]"); if (dirname) { Swig_pop_directory(); } @@ -1573,85 +1620,85 @@ Preprocessor_parse(String *s) pop_imported(); } Delete(s2); - } + } Delete(s1); - Delete(fn); - } - } else if (StringEqual(id,kpp_pragma)) { - if (Strncmp(value,"SWIG ",5) == 0) { - char *c = Char(value)+5; - while (*c && (isspace((int)*c))) c++; + Delete(fn); + } + } else if (StringEqual(id, kpp_pragma)) { + if (Strncmp(value, "SWIG ", 5) == 0) { + char *c = Char(value) + 5; + while (*c && (isspace((int) *c))) + c++; if (*c) { - if (strncmp(c,"nowarn=",7) == 0) { - String *val = NewString(c+7); + if (strncmp(c, "nowarn=", 7) == 0) { + String *val = NewString(c + 7); String *nowarn = Preprocessor_replace(val); - Swig_warnfilter(nowarn,1); + Swig_warnfilter(nowarn, 1); Delete(nowarn); Delete(val); - } - else if (strncmp(c,"cpperraswarn=",7) == 0) { - error_as_warning = atoi(c+13); + } else if (strncmp(c, "cpperraswarn=", 7) == 0) { + error_as_warning = atoi(c + 13); } } } - } else if (StringEqual(id,kpp_level)) { - Swig_error(Getfile(s),Getline(id),"cpp debug: level = %d, startlevel = %d\n", level, start_level); + } else if (StringEqual(id, kpp_level)) { + Swig_error(Getfile(s), Getline(id), "cpp debug: level = %d, startlevel = %d\n", level, start_level); } for (i = 0; i < cpp_lines; i++) - StringPutc('\n',ns); + StringPutc('\n', ns); state = 0; break; - /* Swig directives */ + /* Swig directives */ case 100: /* %{,%} block */ if (c == '{') { - start_line = Getline(s); - add_chunk(ns,chunk,allow); - copy_location(s,chunk); - StringPutc('%',chunk); - StringPutc(c,chunk); - state = 105; + start_line = Getline(s); + add_chunk(ns, chunk, allow); + copy_location(s, chunk); + StringPutc('%', chunk); + StringPutc(c, chunk); + state = 105; } /* %#cpp - an embedded C preprocessor directive (we strip off the %) */ else if (c == '#') { - add_chunk(ns,chunk,allow); - StringPutc(c,chunk); - state = 107; + add_chunk(ns, chunk, allow); + StringPutc(c, chunk); + state = 107; } else if (isidentifier(c)) { - Clear(decl); - StringPutc('%',decl); - StringPutc(c,decl); - state = 110; + Clear(decl); + StringPutc('%', decl); + StringPutc(c, decl); + state = 110; } else { - StringPutc('%',chunk); - StringPutc(c,chunk); - state = 1; + StringPutc('%', chunk); + StringPutc(c, chunk); + state = 1; } break; case 105: - StringPutc(c,chunk); + StringPutc(c, chunk); if (c == '%') - state = 106; + state = 106; break; case 106: - StringPutc(c,chunk); + StringPutc(c, chunk); if (c == '}') { - state = 1; - addline(ns,chunk,allow); + state = 1; + addline(ns, chunk, allow); Clear(chunk); - copy_location(s,chunk); + copy_location(s, chunk); } else { - state = 105; + state = 105; } break; - + case 107: - StringPutc(c,chunk); + StringPutc(c, chunk); if (c == '\n') { - addline(ns,chunk,allow); + addline(ns, chunk, allow); Clear(chunk); state = 0; } else if (c == '\\') { @@ -1660,138 +1707,141 @@ Preprocessor_parse(String *s) break; case 108: - StringPutc(c,chunk); + StringPutc(c, chunk); state = 107; break; case 110: if (!isidchar(c)) { - StringUngetc(c,s); - /* Look for common Swig directives */ - if (StringEqual(decl,kpp_dinclude) || StringEqual(decl,kpp_dimport) || StringEqual(decl,kpp_dextern)) { - /* Got some kind of file inclusion directive */ - if (allow) { - DOH *s1, *s2, *fn, *opt; int sysfile = 0; + StringUngetc(c, s); + /* Look for common Swig directives */ + if (StringEqual(decl, kpp_dinclude) || StringEqual(decl, kpp_dimport) || StringEqual(decl, kpp_dextern)) { + /* Got some kind of file inclusion directive */ + if (allow) { + DOH *s1, *s2, *fn, *opt; + int sysfile = 0; - if (StringEqual(decl,kpp_dextern)) { - Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s),Getline(s),"%%extern is deprecated. Use %%import instead.\n"); + if (StringEqual(decl, kpp_dextern)) { + Swig_warning(WARN_DEPRECATED_EXTERN, Getfile(s), Getline(s), "%%extern is deprecated. Use %%import instead.\n"); Clear(decl); - StringAppend(decl,"%%import"); + StringAppend(decl, "%%import"); } opt = get_options(s); - fn = get_filename(s, &sysfile); + fn = get_filename(s, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { char *dirname; - add_chunk(ns,chunk,allow); - copy_location(s,chunk); - Printf(ns,"%sfile%s \"%s\" [\n", decl, opt, Swig_last_file()); - if (StringEqual(decl,kpp_dimport)) { + add_chunk(ns, chunk, allow); + copy_location(s, chunk); + Printf(ns, "%sfile%s \"%s\" [\n", decl, opt, Swig_last_file()); + if (StringEqual(decl, kpp_dimport)) { push_imported(); } dirname = Swig_file_dirname(Swig_last_file()); - if (sysfile || !strlen(dirname)) dirname = 0; + if (sysfile || !strlen(dirname)) + dirname = 0; if (dirname) { - dirname[strlen(dirname)-1] = 0; /* Kill trailing directory delimeter */ + dirname[strlen(dirname) - 1] = 0; /* Kill trailing directory delimeter */ Swig_push_directory(dirname); } - s2 = Preprocessor_parse(s1); + s2 = Preprocessor_parse(s1); if (dirname) { Swig_pop_directory(); } - if (StringEqual(decl,kpp_dimport)) { + if (StringEqual(decl, kpp_dimport)) { pop_imported(); } - addline(ns,s2,allow); - StringAppend(ns,"\n]"); + addline(ns, s2, allow); + StringAppend(ns, "\n]"); Delete(s2); Delete(s1); - } + } Delete(fn); - } - state = 1; - } else if (StringEqual(decl,kpp_dline)) { - /* Got a line directive */ - state = 1; - } else if (StringEqual(decl,kpp_ddefine)) { - /* Got a define directive */ - dlevel++; - add_chunk(ns,chunk,allow); - copy_location(s,chunk); - Clear(value); - copy_location(s,value); - state = 150; - } else { - StringAppend(chunk,decl); - state = 1; - } + } + state = 1; + } else if (StringEqual(decl, kpp_dline)) { + /* Got a line directive */ + state = 1; + } else if (StringEqual(decl, kpp_ddefine)) { + /* Got a define directive */ + dlevel++; + add_chunk(ns, chunk, allow); + copy_location(s, chunk); + Clear(value); + copy_location(s, value); + state = 150; + } else { + StringAppend(chunk, decl); + state = 1; + } } else { - StringPutc(c,decl); + StringPutc(c, decl); } break; - /* Searching for the end of a %define statement */ + /* Searching for the end of a %define statement */ case 150: - StringPutc(c,value); + StringPutc(c, value); if (c == '%') { - const char *ed = "enddef"; - const char *df = "define"; + const char *ed = "enddef"; + const char *df = "define"; char statement[7]; - int i = 0; - for (i = 0; i < 6; ) { - c = StringGetc(s); - StringPutc(c,value); + int i = 0; + for (i = 0; i < 6;) { + c = StringGetc(s); + StringPutc(c, value); statement[i++] = c; - if (strncmp(statement, ed, i) && strncmp(statement, df, i)) break; - } + if (strncmp(statement, ed, i) && strncmp(statement, df, i)) + break; + } c = StringGetc(s); - StringUngetc(c,s); - if ((i == 6) && (isspace(c))) { + StringUngetc(c, s); + if ((i == 6) && (isspace(c))) { if (strncmp(statement, df, i) == 0) { ++dlevel; } else { if (strncmp(statement, ed, i) == 0) { --dlevel; - if (!dlevel) { + if (!dlevel) { /* Got the macro */ for (i = 0; i < 7; i++) { - Delitem(value,DOH_END); + Delitem(value, DOH_END); } if (allow) { - Seek(value,0,SEEK_SET); - Preprocessor_define(value,1); + Seek(value, 0, SEEK_SET); + Preprocessor_define(value, 1); } - /* StringPutc('\n',ns);*/ - addline(ns,value,0); + /* StringPutc('\n',ns); */ + addline(ns, value, 0); state = 0; } } } - } + } } break; - default : - Printf(stderr,"cpp: Invalid parser state %d\n", state); + default: + Printf(stderr, "cpp: Invalid parser state %d\n", state); abort(); break; } } while (level > 0) { - Swig_error(Getfile(s),-1,"Missing #endif for conditional starting on line %d\n", cond_lines[level-1]); + Swig_error(Getfile(s), -1, "Missing #endif for conditional starting on line %d\n", cond_lines[level - 1]); level--; } if (state == 150) { - Seek(value,0,SEEK_SET); - Swig_error(Getfile(s),-1,"Missing %%enddef for macro starting on line %d\n",Getline(value)); + Seek(value, 0, SEEK_SET); + Swig_error(Getfile(s), -1, "Missing %%enddef for macro starting on line %d\n", Getline(value)); } if ((state >= 105) && (state < 107)) { - Swig_error(Getfile(s),-1,"Unterminated %%{ ... %%} block starting on line %d\n", start_line); + Swig_error(Getfile(s), -1, "Unterminated %%{ ... %%} block starting on line %d\n", start_line); } if ((state >= 30) && (state < 40)) { - Swig_error(Getfile(s),-1,"Unterminated comment starting on line %d\n", start_line); + Swig_error(Getfile(s), -1, "Unterminated comment starting on line %d\n", start_line); } - add_chunk(ns,chunk,allow); - copy_location(s,chunk); + add_chunk(ns, chunk, allow); + copy_location(s, chunk); /* DelScope(scp); */ Delete(decl); @@ -1803,7 +1853,3 @@ Preprocessor_parse(String *s) /* fprintf(stderr,"cpp: %d\n", Len(Getattr(cpp,"symbols"))); */ return ns; } - - - - diff --git a/SWIG/Source/Preprocessor/expr.c b/SWIG/Source/Preprocessor/expr.c index ce9b3d973..499a100bf 100644 --- a/SWIG/Source/Preprocessor/expr.c +++ b/SWIG/Source/Preprocessor/expr.c @@ -16,9 +16,9 @@ char cvsroot_expr_c[] = "$Header$"; static SwigScanner *scan = 0; typedef struct { - int op; - long value; - String *svalue; + int op; + long value; + String *svalue; } exprval; #define EXPR_TOP 1 @@ -27,11 +27,11 @@ typedef struct { #define EXPR_GROUP 4 #define EXPR_UMINUS 100 -static exprval stack[256]; /* Parsing stack */ -static int sp = 0; /* Stack pointer */ -static int prec[256]; /* Precedence rules */ -static int expr_init = 0; /* Initialization flag */ -static char *errmsg = 0; /* Parsing error */ +static exprval stack[256]; /* Parsing stack */ +static int sp = 0; /* Stack pointer */ +static int prec[256]; /* Precedence rules */ +static int expr_init = 0; /* Initialization flag */ +static char *errmsg = 0; /* Parsing error */ /* Initialize the precedence table for various operators. Low values have higher precedence */ static void init_precedence() { @@ -66,9 +66,9 @@ static void init_precedence() { /* Reduce a single operator on the stack */ /* return 0 on failure, 1 on success */ static int reduce_op() { - long op_token = stack[sp-1].value; + long op_token = stack[sp - 1].value; assert(sp > 0); - assert(stack[sp-1].op == EXPR_OP); + assert(stack[sp - 1].op == EXPR_OP); /* do some basic checking first: */ if (stack[sp].op != EXPR_VALUE) { errmsg = "Right-hand side is not value"; @@ -90,23 +90,23 @@ static int reduce_op() { errmsg = "Left-hand side of binary operator is not a value"; return 0; } - if ((!stack[sp-2].svalue) != (!stack[sp].svalue)) { + if ((!stack[sp - 2].svalue) != (!stack[sp].svalue)) { errmsg = "Can't mix strings and integers in expression"; return 0; } } if (stack[sp].svalue) { /* A binary string expression */ - switch(stack[sp-1].value) { + switch (stack[sp - 1].value) { case SWIG_TOKEN_EQUALTO: - stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) == 0); - Delete(stack[sp-2].svalue); + stack[sp - 2].value = (Strcmp(stack[sp - 2].svalue, stack[sp].svalue) == 0); + Delete(stack[sp - 2].svalue); Delete(stack[sp].svalue); sp -= 2; break; case SWIG_TOKEN_NOTEQUAL: - stack[sp-2].value = (Strcmp(stack[sp-2].svalue,stack[sp].svalue) != 0); - Delete(stack[sp-2].svalue); + stack[sp - 2].value = (Strcmp(stack[sp - 2].svalue, stack[sp].svalue) != 0); + Delete(stack[sp - 2].svalue); Delete(stack[sp].svalue); sp -= 2; break; @@ -116,89 +116,89 @@ static int reduce_op() { break; } } else { - switch(op_token) { + switch (op_token) { case SWIG_TOKEN_STAR: - stack[sp-2].value = stack[sp-2].value * stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value * stack[sp].value; sp -= 2; break; case SWIG_TOKEN_EQUALTO: - stack[sp-2].value = stack[sp-2].value == stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value == stack[sp].value; sp -= 2; break; case SWIG_TOKEN_NOTEQUAL: - stack[sp-2].value = stack[sp-2].value != stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value != stack[sp].value; sp -= 2; break; case SWIG_TOKEN_PLUS: - stack[sp-2].value = stack[sp-2].value + stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value + stack[sp].value; sp -= 2; break; case SWIG_TOKEN_MINUS: - stack[sp-2].value = stack[sp-2].value - stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value - stack[sp].value; sp -= 2; break; case SWIG_TOKEN_AND: - stack[sp-2].value = stack[sp-2].value & stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value & stack[sp].value; sp -= 2; break; case SWIG_TOKEN_LAND: - stack[sp-2].value = stack[sp-2].value && stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value && stack[sp].value; sp -= 2; break; case SWIG_TOKEN_OR: - stack[sp-2].value = stack[sp-2].value | stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value | stack[sp].value; sp -= 2; break; case SWIG_TOKEN_LOR: - stack[sp-2].value = stack[sp-2].value || stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value || stack[sp].value; sp -= 2; break; case SWIG_TOKEN_XOR: - stack[sp-2].value = stack[sp-2].value ^ stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value ^ stack[sp].value; sp -= 2; break; case SWIG_TOKEN_LESSTHAN: - stack[sp-2].value = stack[sp-2].value < stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value < stack[sp].value; sp -= 2; break; case SWIG_TOKEN_GREATERTHAN: - stack[sp-2].value = stack[sp-2].value > stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value > stack[sp].value; sp -= 2; break; case SWIG_TOKEN_LTEQUAL: - stack[sp-2].value = stack[sp-2].value <= stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value <= stack[sp].value; sp -= 2; break; case SWIG_TOKEN_GTEQUAL: - stack[sp-2].value = stack[sp-2].value >= stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value >= stack[sp].value; sp -= 2; break; case SWIG_TOKEN_NOT: - stack[sp-1].value = ~stack[sp].value; + stack[sp - 1].value = ~stack[sp].value; sp--; break; case SWIG_TOKEN_LNOT: - stack[sp-1].value = !stack[sp].value; + stack[sp - 1].value = !stack[sp].value; sp--; break; case EXPR_UMINUS: - stack[sp-1].value = -stack[sp].value; + stack[sp - 1].value = -stack[sp].value; sp--; break; case SWIG_TOKEN_SLASH: - stack[sp-2].value = stack[sp-2].value / stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value / stack[sp].value; sp -= 2; break; case SWIG_TOKEN_PERCENT: - stack[sp-2].value = stack[sp-2].value % stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value % stack[sp].value; sp -= 2; break; case SWIG_TOKEN_LSHIFT: - stack[sp-2].value = stack[sp-2].value << stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value << stack[sp].value; sp -= 2; break; case SWIG_TOKEN_RSHIFT: - stack[sp-2].value = stack[sp-2].value >> stack[sp].value; + stack[sp - 2].value = stack[sp - 2].value >> stack[sp].value; sp -= 2; break; default: @@ -218,14 +218,14 @@ static int reduce_op() { * Initialize the expression evaluator * ----------------------------------------------------------------------------- */ -void -Preprocessor_expr_init (void) { - if (!expr_init) init_precedence(); - if (!scan) scan = NewSwigScanner(); +void Preprocessor_expr_init(void) { + if (!expr_init) + init_precedence(); + if (!scan) + scan = NewSwigScanner(); } -void -Preprocessor_expr_delete (void) { +void Preprocessor_expr_delete(void) { SwigScanner_clear(scan); DelSwigScanner(scan); } @@ -235,11 +235,12 @@ Preprocessor_expr_delete (void) { * Tokenizer * ----------------------------------------------------------------------------- */ -static int expr_token(SwigScanner *s) { +static int expr_token(SwigScanner * s) { int t; - while(1) { + while (1) { t = SwigScanner_token(s); - if (!((t == SWIG_TOKEN_BACKSLASH) || (t == SWIG_TOKEN_ENDLINE))) break; + if (!((t == SWIG_TOKEN_BACKSLASH) || (t == SWIG_TOKEN_ENDLINE))) + break; } return t; } @@ -250,20 +251,19 @@ static int expr_token(SwigScanner *s) { * Evaluates an arithmetic expression. Returns the result and sets an error code. * ----------------------------------------------------------------------------- */ -int -Preprocessor_expr(DOH *s, int *error) { - int token = 0; - int op = 0; +int Preprocessor_expr(DOH *s, int *error) { + int token = 0; + int op = 0; sp = 0; assert(s); assert(scan); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); /* Printf(stdout,"evaluating : '%s'\n", s); */ *error = 0; SwigScanner_clear(scan); - SwigScanner_push(scan,s); + SwigScanner_push(scan, s); /* Put initial state onto the stack */ stack[sp].op = EXPR_TOP; @@ -271,7 +271,7 @@ Preprocessor_expr(DOH *s, int *error) { while (1) { /* Look at the top of the stack */ - switch(stack[sp].op) { + switch (stack[sp].op) { case EXPR_TOP: /* An expression. Can be a number or another expression enclosed in parens */ token = expr_token(scan); @@ -283,13 +283,14 @@ Preprocessor_expr(DOH *s, int *error) { if ((token == SWIG_TOKEN_INT) || (token == SWIG_TOKEN_UINT) || (token == SWIG_TOKEN_LONG) || (token == SWIG_TOKEN_ULONG)) { /* A number. Reduce EXPR_TOP to an EXPR_VALUE */ char *c = Char(SwigScanner_text(scan)); - stack[sp].value = (long) strtol(c,0,0); + stack[sp].value = (long) strtol(c, 0, 0); stack[sp].svalue = 0; - /* stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */ + /* stack[sp].value = (long) atol(Char(SwigScanner_text(scan))); */ stack[sp].op = EXPR_VALUE; - } else if (token == SWIG_TOKEN_PLUS) { } - else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token==SWIG_TOKEN_NOT)) { - if (token == SWIG_TOKEN_MINUS) token = EXPR_UMINUS; + } else if (token == SWIG_TOKEN_PLUS) { + } else if ((token == SWIG_TOKEN_MINUS) || (token == SWIG_TOKEN_LNOT) || (token == SWIG_TOKEN_NOT)) { + if (token == SWIG_TOKEN_MINUS) + token = EXPR_UMINUS; stack[sp].value = token; stack[sp++].op = EXPR_OP; stack[sp].op = EXPR_TOP; @@ -299,7 +300,7 @@ Preprocessor_expr(DOH *s, int *error) { stack[sp].op = EXPR_TOP; stack[sp].value = 0; stack[sp].svalue = 0; - } else if (token == SWIG_TOKEN_ENDLINE) { + } else if (token == SWIG_TOKEN_ENDLINE) { } else if ((token == SWIG_TOKEN_STRING)) { stack[sp].svalue = NewString(SwigScanner_text(scan)); stack[sp].op = EXPR_VALUE; @@ -307,7 +308,8 @@ Preprocessor_expr(DOH *s, int *error) { stack[sp].value = 0; stack[sp].svalue = 0; stack[sp].op = EXPR_VALUE; - } else goto syntax_error; + } else + goto syntax_error; break; case EXPR_VALUE: /* A value is on the stack. We may reduce or evaluate depending on what the next token is */ @@ -315,18 +317,20 @@ Preprocessor_expr(DOH *s, int *error) { if (!token) { /* End of input. Might have to reduce if an operator is on stack */ while (sp > 0) { - if (stack[sp-1].op == EXPR_OP) { - if (!reduce_op()) goto reduce_error; - } else if (stack[sp-1].op == EXPR_GROUP) { + if (stack[sp - 1].op == EXPR_OP) { + if (!reduce_op()) + goto reduce_error; + } else if (stack[sp - 1].op == EXPR_GROUP) { errmsg = "Missing \')\'"; *error = 1; return 0; - } else goto syntax_error; + } else + goto syntax_error; } return stack[sp].value; } /* Token must be an operator */ - switch(token) { + switch (token) { case SWIG_TOKEN_STAR: case SWIG_TOKEN_EQUALTO: case SWIG_TOKEN_NOTEQUAL: @@ -345,7 +349,7 @@ Preprocessor_expr(DOH *s, int *error) { case SWIG_TOKEN_PERCENT: case SWIG_TOKEN_LSHIFT: case SWIG_TOKEN_RSHIFT: - if ((sp == 0) || (stack[sp-1].op == EXPR_GROUP)) { + if ((sp == 0) || (stack[sp - 1].op == EXPR_GROUP)) { /* No possibility of reduce. Push operator and expression */ sp++; stack[sp].op = EXPR_OP; @@ -354,15 +358,17 @@ Preprocessor_expr(DOH *s, int *error) { stack[sp].op = EXPR_TOP; stack[sp].value = 0; } else { - if (stack[sp-1].op != EXPR_OP) goto syntax_error_expected_operator; - op = stack[sp-1].value; /* Previous operator */ + if (stack[sp - 1].op != EXPR_OP) + goto syntax_error_expected_operator; + op = stack[sp - 1].value; /* Previous operator */ /* Now, depending on the precedence relationship between the last operator and the current we will reduce or push */ if (prec[op] <= prec[token]) { /* Reduce the previous operator */ - if (!reduce_op()) goto reduce_error; + if (!reduce_op()) + goto reduce_error; } sp++; stack[sp].op = EXPR_OP; @@ -373,15 +379,18 @@ Preprocessor_expr(DOH *s, int *error) { } break; case SWIG_TOKEN_RPAREN: - if (sp == 0) goto extra_rparen; + if (sp == 0) + goto extra_rparen; /* Might have to reduce operators first */ - while ((sp > 0) && (stack[sp-1].op == EXPR_OP)) { - if (!reduce_op()) goto reduce_error; + while ((sp > 0) && (stack[sp - 1].op == EXPR_OP)) { + if (!reduce_op()) + goto reduce_error; } - if ((sp == 0) || (stack[sp-1].op != EXPR_GROUP)) goto extra_rparen; - stack[sp-1].op = EXPR_VALUE; - stack[sp-1].value = stack[sp].value; + if ((sp == 0) || (stack[sp - 1].op != EXPR_GROUP)) + goto extra_rparen; + stack[sp - 1].op = EXPR_VALUE; + stack[sp - 1].value = stack[sp].value; sp--; break; default: @@ -391,27 +400,27 @@ Preprocessor_expr(DOH *s, int *error) { break; default: - fprintf(stderr,"Internal error in expression evaluator.\n"); + fprintf(stderr, "Internal error in expression evaluator.\n"); abort(); } } - syntax_error: +syntax_error: errmsg = "Syntax error"; *error = 1; return 0; - syntax_error_expected_operator: +syntax_error_expected_operator: errmsg = "Syntax error: expected operator"; *error = 1; return 0; - reduce_error: +reduce_error: /* errmsg has been set by reduce_op */ *error = 1; return 0; - extra_rparen: +extra_rparen: errmsg = "Extra \')\'"; *error = 1; return 0; @@ -423,14 +432,6 @@ Preprocessor_expr(DOH *s, int *error) { * Return error message set by the evaluator (if any) * ----------------------------------------------------------------------------- */ -char * -Preprocessor_expr_error() { +char *Preprocessor_expr_error() { return errmsg; } - - - - - - - diff --git a/SWIG/Source/Preprocessor/preprocessor.h b/SWIG/Source/Preprocessor/preprocessor.h index b34ec8c5a..e6c3be05f 100644 --- a/SWIG/Source/Preprocessor/preprocessor.h +++ b/SWIG/Source/Preprocessor/preprocessor.h @@ -17,27 +17,22 @@ #ifdef __cplusplus extern "C" { #endif -extern int Preprocessor_expr(String *s, int *error); -extern char *Preprocessor_expr_error(void); -extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro); -extern void Preprocessor_undef(const String_or_char *name); -extern void Preprocessor_init(void); -extern void Preprocessor_delete(void); -extern String *Preprocessor_parse(String *s); -extern void Preprocessor_include_all(int); -extern void Preprocessor_import_all(int); -extern void Preprocessor_ignore_missing(int); -extern void Preprocessor_error_as_warning(int); -extern List *Preprocessor_depend(void); -extern void Preprocessor_expr_init(void); -extern void Preprocessor_expr_delete(void); + extern int Preprocessor_expr(String *s, int *error); + extern char *Preprocessor_expr_error(void); + extern Hash *Preprocessor_define(const String_or_char *str, int swigmacro); + extern void Preprocessor_undef(const String_or_char *name); + extern void Preprocessor_init(void); + extern void Preprocessor_delete(void); + extern String *Preprocessor_parse(String *s); + extern void Preprocessor_include_all(int); + extern void Preprocessor_import_all(int); + extern void Preprocessor_ignore_missing(int); + extern void Preprocessor_error_as_warning(int); + extern List *Preprocessor_depend(void); + extern void Preprocessor_expr_init(void); + extern void Preprocessor_expr_delete(void); #ifdef __cplusplus } #endif - #endif - - - - diff --git a/SWIG/Source/Swig/cwrap.c b/SWIG/Source/Swig/cwrap.c index d9a043261..69f22e024 100644 --- a/SWIG/Source/Swig/cwrap.c +++ b/SWIG/Source/Swig/cwrap.c @@ -13,12 +13,13 @@ char cvsroot_cwrap_c[] = "$Header$"; #include "swig.h" #include "swigkeys.h" -extern int cparse_cplusplus; +extern int cparse_cplusplus; static Parm *nonvoid_parms(Parm *p) { if (p) { - SwigType *t = Getattr(p,k_type); - if (SwigType_type(t) == T_VOID) return 0; + SwigType *t = Getattr(p, k_type); + if (SwigType_type(t) == T_VOID) + return 0; } return p; } @@ -29,11 +30,10 @@ static Parm *nonvoid_parms(Parm *p) { * Generates a name for the ith argument in an argument list * ----------------------------------------------------------------------------- */ -String * -Swig_cparm_name(Parm *p, int i) { - String *name = NewStringf("arg%d",i+1); +String *Swig_cparm_name(Parm *p, int i) { + String *name = NewStringf("arg%d", i + 1); if (p) { - Setattr(p,k_lname,name); + Setattr(p, k_lname, name); } return name; @@ -46,44 +46,43 @@ Swig_cparm_name(Parm *p, int i) { * and user defined types to pointers. * ----------------------------------------------------------------------------- */ -static String * -Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value) { +static String *Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value) { String *decl; decl = NewStringEmpty(); - switch(SwigType_type(t)) { + switch (SwigType_type(t)) { case T_REFERENCE: if (value) { - String *lstrname = SwigType_lstr(t,name); - String *lstr = SwigType_lstr(t,0); - Printf(decl,"%s = (%s) &%s_defvalue", lstrname, lstr, name); + String *lstrname = SwigType_lstr(t, name); + String *lstr = SwigType_lstr(t, 0); + Printf(decl, "%s = (%s) &%s_defvalue", lstrname, lstr, name); Delete(lstrname); Delete(lstr); } else { - String *lstrname = SwigType_lstr(t,name); - Printf(decl,"%s = 0", lstrname); + String *lstrname = SwigType_lstr(t, name); + Printf(decl, "%s = 0", lstrname); Delete(lstrname); } break; case T_VOID: break; case T_VARARGS: - Printf(decl,"void *%s = 0", name); + Printf(decl, "void *%s = 0", name); break; default: if (value) { - String *lcaststr = SwigType_lcaststr(t,value); - String *lstr = SwigType_lstr(t,0); - String *lstrn = SwigType_lstr(t,name); - Printf(decl,"%s = (%s) %s", lstrn, lstr, lcaststr); + String *lcaststr = SwigType_lcaststr(t, value); + String *lstr = SwigType_lstr(t, 0); + String *lstrn = SwigType_lstr(t, name); + Printf(decl, "%s = (%s) %s", lstrn, lstr, lcaststr); Delete(lcaststr); Delete(lstr); Delete(lstrn); } else { - String *lstrname = SwigType_lstr(t,name); - Append(decl,lstrname); + String *lstrname = SwigType_lstr(t, name); + Append(decl, lstrname); Delete(lstrname); } } @@ -97,11 +96,10 @@ Swig_clocal(SwigType *t, const String_or_char *name, const String_or_char *value * This function only converts user defined types to pointers. * ----------------------------------------------------------------------------- */ -String * -Swig_wrapped_var_type(SwigType *t, int varcref) { +String *Swig_wrapped_var_type(SwigType *t, int varcref) { SwigType *ty; - if (!Strstr(t,"enum $unnamed")) { + if (!Strstr(t, "enum $unnamed")) { ty = Copy(t); } else { /* Change the type for unnamed enum instance variables */ @@ -111,7 +109,8 @@ Swig_wrapped_var_type(SwigType *t, int varcref) { if (SwigType_isclass(t)) { if (varcref) { if (cparse_cplusplus) { - if (!SwigType_isconst(ty)) SwigType_add_qualifier(ty, "const"); + if (!SwigType_isconst(ty)) + SwigType_add_qualifier(ty, "const"); SwigType_add_reference(ty); } else { return Copy(ty); @@ -123,11 +122,10 @@ Swig_wrapped_var_type(SwigType *t, int varcref) { return ty; } -String * -Swig_wrapped_member_var_type(SwigType *t, int varcref) { +String *Swig_wrapped_member_var_type(SwigType *t, int varcref) { SwigType *ty; - if (!Strstr(t,"enum $unnamed")) { + if (!Strstr(t, "enum $unnamed")) { ty = Copy(t); } else { /* Change the type for unnamed enum instance variables */ @@ -136,7 +134,8 @@ Swig_wrapped_member_var_type(SwigType *t, int varcref) { if (SwigType_isclass(t)) { if (varcref) { if (cparse_cplusplus) { - if (!SwigType_isconst(ty)) SwigType_add_qualifier(ty, "const"); + if (!SwigType_isconst(ty)) + SwigType_add_qualifier(ty, "const"); SwigType_add_reference(ty); } else { return Copy(ty); @@ -149,33 +148,31 @@ Swig_wrapped_member_var_type(SwigType *t, int varcref) { } -static String * -Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) { +static String *Swig_wrapped_var_deref(SwigType *t, String_or_char *name, int varcref) { if (SwigType_isclass(t)) { if (varcref) { if (cparse_cplusplus) { - return NewStringf("*%s",name); - } else{ - return NewStringf("%s",name); - } + return NewStringf("*%s", name); + } else { + return NewStringf("%s", name); + } } else { - return NewStringf("*%s",name); + return NewStringf("*%s", name); } } else { - return SwigType_rcaststr(t,name); + return SwigType_rcaststr(t, name); } } -static String * -Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) { +static String *Swig_wrapped_var_assign(SwigType *t, const String_or_char *name, int varcref) { if (SwigType_isclass(t)) { if (varcref) { - return NewStringf("%s",name); + return NewStringf("%s", name); } else { - return NewStringf("&%s",name); + return NewStringf("&%s", name); } } else { - return SwigType_lcaststr(t,name); + return SwigType_lcaststr(t, name); } } @@ -192,14 +189,14 @@ int Swig_cargs(Wrapper *w, ParmList *p) { int compactdefargs = ParmList_is_compactdefargs(p); while (p != 0) { - String *lname = Swig_cparm_name(p,i); - SwigType *pt = Getattr(p,k_type); + String *lname = Swig_cparm_name(p, i); + SwigType *pt = Getattr(p, k_type); if ((SwigType_type(pt) != T_VOID)) { - String *local = 0; - String *type = Getattr(p,k_type); + String *local = 0; + String *type = Getattr(p, k_type); /* default values only emitted if in compact default args mode */ - String *pvalue = (compactdefargs) ? Getattr(p,k_value) : 0; - SwigType *altty = SwigType_alttype(type,0); + String *pvalue = (compactdefargs) ? Getattr(p, k_value) : 0; + SwigType *altty = SwigType_alttype(type, 0); int tycode = SwigType_type(type); if (tycode == T_REFERENCE) { if (pvalue) { @@ -213,39 +210,39 @@ int Swig_cargs(Wrapper *w, ParmList *p) { tycode = SwigType_type(tvalue); if (tycode != T_USER) { /* plain primitive type, we copy the the def value */ - String *lstr = SwigType_lstr(tvalue,defname); - defvalue = NewStringf("%s = %s", lstr,qvalue); + String *lstr = SwigType_lstr(tvalue, defname); + defvalue = NewStringf("%s = %s", lstr, qvalue); Delete(lstr); } else { /* user type, we copy the reference value */ - String *str = SwigType_str(type,defname); - defvalue = NewStringf("%s = %s",str,qvalue); + String *str = SwigType_str(type, defname); + defvalue = NewStringf("%s = %s", str, qvalue); Delete(str); } - Wrapper_add_localv(w,defname, defvalue, NIL); + Wrapper_add_localv(w, defname, defvalue, NIL); Delete(tvalue); Delete(rvalue); Delete(qvalue); Delete(defname); Delete(defvalue); } - } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) { + } else if (!pvalue && ((tycode == T_POINTER) || (tycode == T_STRING))) { pvalue = (String *) "0"; } if (!altty) { - local = Swig_clocal(pt,lname,pvalue); + local = Swig_clocal(pt, lname, pvalue); } else { - local = Swig_clocal(altty,lname,pvalue); + local = Swig_clocal(altty, lname, pvalue); Delete(altty); } - Wrapper_add_localv(w,lname,local,NIL); + Wrapper_add_localv(w, lname, local, NIL); Delete(local); i++; } Delete(lname); p = nextSibling(p); } - return(i); + return (i); } /* ----------------------------------------------------------------------------- @@ -257,35 +254,35 @@ int Swig_cargs(Wrapper *w, ParmList *p) { String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl) { String *fcall; - + fcall = NewStringEmpty(); - switch(SwigType_type(t)) { + switch (SwigType_type(t)) { case T_VOID: break; - case T_REFERENCE: + case T_REFERENCE: { - String *str = SwigType_str(t,"_result_ref"); - Printf(fcall,"{\n"); - Printf(fcall,"%s = ", str); + String *str = SwigType_str(t, "_result_ref"); + Printf(fcall, "{\n"); + Printf(fcall, "%s = ", str); Delete(str); } break; case T_USER: - Printf(fcall,"%s = ", name); + Printf(fcall, "%s = ", name); break; default: /* Normal return value */ { - String *lstr = SwigType_lstr(t,0); - Printf(fcall,"%s = (%s)", name, lstr); + String *lstr = SwigType_lstr(t, 0); + Printf(fcall, "%s = (%s)", name, lstr); Delete(lstr); } break; } /* Now print out function call */ - Append(fcall,decl); + Append(fcall, decl); /* A sick hack */ { @@ -295,9 +292,9 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch } if (SwigType_type(t) == T_REFERENCE) { - String *lstr = SwigType_lstr(t,0); - Printf(fcall,"\n%s = (%s) &_result_ref;\n", name, lstr); - Append(fcall,"}"); + String *lstr = SwigType_lstr(t, 0); + Printf(fcall, "\n%s = (%s) &_result_ref;\n", name, lstr); + Append(fcall, "}"); Delete(lstr); } return fcall; @@ -313,49 +310,48 @@ String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_ch * * ----------------------------------------------------------------------------- */ -String * -Swig_cfunction_call(String_or_char *name, ParmList *parms) { +String *Swig_cfunction_call(String_or_char *name, ParmList *parms) { String *func; int i = 0; int comma = 0; Parm *p = parms; - String *nname; + String *nname; func = NewStringEmpty(); nname = SwigType_namestr(name); /* - SWIGTEMPLATEDISAMBIGUATOR is compiler dependent (swiglabels.swg), - - SUN Studio 9 requires 'template', - - gcc-3.4 forbids the use of 'template'. - the rest seems not caring very much, - */ + SWIGTEMPLATEDISAMBIGUATOR is compiler dependent (swiglabels.swg), + - SUN Studio 9 requires 'template', + - gcc-3.4 forbids the use of 'template'. + the rest seems not caring very much, + */ if (SwigType_istemplate(name)) { String *prefix = Swig_scopename_prefix(nname); if (!prefix || Len(prefix) == 0) { - Printf(func,"%s(", nname); + Printf(func, "%s(", nname); } else { String *last = Swig_scopename_last(nname); - Printf(func,"%s::SWIGTEMPLATEDISAMBIGUATOR %s(", prefix, last); + Printf(func, "%s::SWIGTEMPLATEDISAMBIGUATOR %s(", prefix, last); Delete(last); } Delete(prefix); } else { - Printf(func,"%s(", nname); + Printf(func, "%s(", nname); } Delete(nname); while (p) { - SwigType *pt = Getattr(p,k_type); + SwigType *pt = Getattr(p, k_type); if ((SwigType_type(pt) != T_VOID)) { SwigType *rpt = SwigType_typedef_resolve_all(pt); - String *pname = Swig_cparm_name(p,i); + String *pname = Swig_cparm_name(p, i); String *rcaststr = SwigType_rcaststr(rpt, pname); if (comma) { Printv(func, ",", rcaststr, NIL); } else { - Append(func,rcaststr); + Append(func, rcaststr); } Delete(rpt); Delete(pname); @@ -363,9 +359,9 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) { comma = 1; i++; } - p = nextSibling(p); + p = nextSibling(p); } - Append(func,")"); + Append(func, ")"); return func; } @@ -381,8 +377,7 @@ Swig_cfunction_call(String_or_char *name, ParmList *parms) { * set to "(*this)->" or some similar sequence. * ----------------------------------------------------------------------------- */ -static String * -Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, String *explicit_qualifier, SwigType *director_type) { +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; @@ -390,12 +385,14 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, S int comma = 0; func = NewStringEmpty(); - if (!p) return func; + if (!p) + return func; - if (!self) self = (char *) "(this)->"; - Append(func,self); + if (!self) + self = (char *) "(this)->"; + Append(func, self); - if (SwigType_istemplate(name) && (strncmp(Char(name),"operator ",9) == 0)) { + 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; @@ -406,22 +403,22 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, S if (director_type) { const char *pname = "darg"; String *rcaststr = SwigType_rcaststr(director_type, pname); - Replaceall(func,"this", rcaststr); + Replaceall(func, "this", rcaststr); Delete(rcaststr); } else { - pt = Getattr(p,k_type); + 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); + 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 *pname = Swig_cparm_name(p, 0); String *rcaststr = SwigType_rcaststr(pt, pname); - Replaceall(func,"this", rcaststr); + Replaceall(func, "this", rcaststr); Delete(rcaststr); Delete(pname); } @@ -431,26 +428,27 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, S - 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 "); + Printf(func, "SWIGTEMPLATEDISAMBIGUATOR "); if (explicit_qualifier) { Printv(func, explicit_qualifier, "::", NIL); } } - Printf(func,"%s(", nname); + Printf(func, "%s(", nname); i++; p = nextSibling(p); while (p) { - pt = Getattr(p,k_type); + pt = Getattr(p, k_type); if ((SwigType_type(pt) != T_VOID)) { - String *pname = Swig_cparm_name(p,i); + String *pname = Swig_cparm_name(p, i); String *rcaststr = SwigType_rcaststr(pt, pname); - if (comma) Append(func,","); - Append(func,rcaststr); + if (comma) + Append(func, ","); + Append(func, rcaststr); Delete(rcaststr); Delete(pname); comma = 1; @@ -458,7 +456,7 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, S } p = nextSibling(p); } - Append(func,")"); + Append(func, ")"); Delete(nname); return func; } @@ -471,12 +469,11 @@ Swig_cmethod_call(String_or_char *name, ParmList *parms, String_or_char *self, S * (name *) calloc(1,sizeof(name)); * ----------------------------------------------------------------------------- */ -String * -Swig_cconstructor_call(String_or_char *name) { +String *Swig_cconstructor_call(String_or_char *name) { DOH *func; func = NewStringEmpty(); - Printf(func,"(%s *) calloc(1, sizeof(%s))", name, name); + Printf(func, "(%s *) calloc(1, sizeof(%s))", name, name); return func; } @@ -491,8 +488,7 @@ Swig_cconstructor_call(String_or_char *name) { * * ----------------------------------------------------------------------------- */ -String * -Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self) { +String *Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_self) { String *func; String *nname; int i = 0; @@ -500,20 +496,22 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se Parm *p = parms; SwigType *pt; if (skip_self) { - if (p) p = nextSibling(p); + if (p) + p = nextSibling(p); i++; } nname = SwigType_namestr(name); func = NewStringEmpty(); - Printf(func,"new %s(", nname); + Printf(func, "new %s(", nname); while (p) { - pt = Getattr(p,k_type); + pt = Getattr(p, k_type); if ((SwigType_type(pt) != T_VOID)) { String *rcaststr = 0; String *pname = 0; - if (comma) Append(func,","); + if (comma) + Append(func, ","); if (!Getattr(p, k_argbyname)) { - pname = Swig_cparm_name(p,i); + pname = Swig_cparm_name(p, i); i++; } else { if ((pname = Getattr(p, k_value))) @@ -522,30 +520,27 @@ Swig_cppconstructor_base_call(String_or_char *name, ParmList *parms, int skip_se pname = Copy(Getattr(p, k_name)); } rcaststr = SwigType_rcaststr(pt, pname); - Append(func,rcaststr); + Append(func, rcaststr); Delete(rcaststr); - comma = 1; + comma = 1; Delete(pname); } p = nextSibling(p); } - Append(func,")"); + Append(func, ")"); Delete(nname); return func; } -String * -Swig_cppconstructor_call(String_or_char *name, ParmList *parms) { +String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms) { return Swig_cppconstructor_base_call(name, parms, 0); } -String * -Swig_cppconstructor_nodirector_call(String_or_char *name, ParmList *parms) { +String *Swig_cppconstructor_nodirector_call(String_or_char *name, ParmList *parms) { return Swig_cppconstructor_base_call(name, parms, 1); } -String * -Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) { +String *Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) { return Swig_cppconstructor_base_call(name, parms, 0); } @@ -571,11 +566,9 @@ Swig_cppconstructor_director_call(String_or_char *name, ParmList *parms) { * ----------------------------------------------------------------------------- */ /* #define SWIG_FAST_REC_SEARCH 1 */ -String * -Swig_rflag_search(Node *n, const String *attr, const String *noattr) -{ +String *Swig_rflag_search(Node *n, const String *attr, const String *noattr) { String *f = 0; - n = Swig_methodclass(n); + n = Swig_methodclass(n); if (GetFlag(n, noattr)) { return 0; } @@ -583,7 +576,7 @@ Swig_rflag_search(Node *n, const String *attr, const String *noattr) if (f) { return f; } else { - List* bl = Getattr(n, k_bases); + List *bl = Getattr(n, k_bases); if (bl) { Iterator bi; for (bi = First(bl); bi.item; bi = Next(bi)) { @@ -609,15 +602,14 @@ Swig_rflag_search(Node *n, const String *attr, const String *noattr) * find the unref call, if any. * ----------------------------------------------------------------------------- */ -String * -Swig_unref_call(Node *n) { - Node *cn = Swig_methodclass(n); - String* unref = Swig_rflag_search(cn,"feature:unref","feature:nounref"); +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); + String *pname = Swig_cparm_name(0, 0); unref = NewString(unref); - Replaceall(unref,"$this",pname); - Replaceall(unref,"$self",pname); + Replaceall(unref, "$this", pname); + Replaceall(unref, "$self", pname); Delete(pname); } return unref; @@ -629,14 +621,13 @@ Swig_unref_call(Node *n) { * find the ref call, if any. * ----------------------------------------------------------------------------- */ -String * -Swig_ref_call(Node *n, const String* lname) { - Node *cn = Swig_methodclass(n); - String* ref = Swig_rflag_search(cn,"feature:ref","feature:noref"); +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); + Replaceall(ref, "$this", lname); + Replaceall(ref, "$self", lname); } return ref; } @@ -649,15 +640,14 @@ Swig_ref_call(Node *n, const String* lname) { * free((char *) arg0); * ----------------------------------------------------------------------------- */ -String * -Swig_cdestructor_call(Node *n) { - String* unref = Swig_unref_call(n); - - if (unref) { +String *Swig_cdestructor_call(Node *n) { + String *unref = Swig_unref_call(n); + + if (unref) { return unref; } else { - String *pname = Swig_cparm_name(0,0); - String *call = NewStringf("free((char *) %s);",pname); + String *pname = Swig_cparm_name(0, 0); + String *call = NewStringf("free((char *) %s);", pname); Delete(pname); return call; } @@ -672,17 +662,16 @@ Swig_cdestructor_call(Node *n) { * delete arg0; * ----------------------------------------------------------------------------- */ -String * -Swig_cppdestructor_call(Node *n) { - String* unref = Swig_unref_call(n); +String *Swig_cppdestructor_call(Node *n) { + String *unref = Swig_unref_call(n); if (unref) { return unref; } else { - String *pname = Swig_cparm_name(0,0); - String *call = NewStringf("delete %s;",pname); + String *pname = Swig_cparm_name(0, 0); + String *call = NewStringf("delete %s;", pname); Delete(pname); return call; - } + } } /* ----------------------------------------------------------------------------- @@ -694,29 +683,29 @@ Swig_cppdestructor_call(Node *n) { * * ----------------------------------------------------------------------------- */ -String * -Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref) { +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); + 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 (!self) + self = NewString("(this)->"); + else + self = NewString(self); + Replaceall(self, "this", pname0); if (SwigType_type(type) != T_ARRAY) { - if (!Strstr(type,"enum $unnamed")) { + 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); + 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); + 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); + return (func); } @@ -729,18 +718,18 @@ Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, * * ----------------------------------------------------------------------------- */ -String * -Swig_cmemberget_call(const String_or_char *name, SwigType *t, - String_or_char *self, int varcref) { +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); + 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); + call = Swig_wrapped_var_assign(t, "", varcref); + Printf(func, "%s (%s%s)", call, self, name); Delete(self); Delete(call); Delete(pname0); @@ -755,12 +744,10 @@ Swig_cmemberget_call(const String_or_char *name, SwigType *t, * return_type function_name(parms) code * * ----------------------------------------------------------------------------- */ -String * -Swig_extension_code(const String *function_name, ParmList *parms, - SwigType *return_type, const String *code, int cplusplus) { +String *Swig_extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus) { 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 *rt_sig = SwigType_str(return_type, sig); String *body = NewStringf("SWIGINTERN %s", rt_sig); Printv(body, code, "\n", NIL); Delete(parms_str); @@ -778,11 +765,9 @@ Swig_extension_code(const String *function_name, ParmList *parms, * See also Swig_extension_code() * * ----------------------------------------------------------------------------- */ -int -Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, - SwigType *return_type, const String *code, int cplusplus) { +int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus) { String *body = Swig_extension_code(function_name, parms, return_type, code, cplusplus); - Setattr(n,k_wrapcode,body); + Setattr(n, k_wrapcode, body); Delete(body); return SWIG_OK; } @@ -794,13 +779,12 @@ Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, * Converts a C++ method node to a function accessor function. * ----------------------------------------------------------------------------- */ -int -Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director) { - String *name, *qualifier; +int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director) { + String *name, *qualifier; ParmList *parms; SwigType *type; - Parm *p; - String *self = 0; + Parm *p; + String *self = 0; /* If smart pointer, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { @@ -808,76 +792,77 @@ Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_ } /* If node is a member template expansion, we don't allow added code */ - if (Getattr(n,k_templatetype)) flags &= ~(CWRAP_EXTEND); + if (Getattr(n, k_templatetype)) + flags &= ~(CWRAP_EXTEND); + + name = Getattr(n, k_name); + qualifier = Getattr(n, k_qualifier); + parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms))); - name = Getattr(n,k_name); - qualifier = Getattr(n,k_qualifier); - parms = CopyParmList(nonvoid_parms(Getattr(n,k_parms))); - type = NewString(classname); if (qualifier) { - SwigType_push(type,qualifier); + SwigType_push(type, qualifier); } SwigType_add_pointer(type); - p = NewParm(type,k_self); - Setattr(p,k_self,"1"); - Setattr(p,k_hidden,"1"); + p = NewParm(type, k_self); + Setattr(p, k_self, "1"); + Setattr(p, k_hidden, "1"); /* - Disable the 'this' ownership in 'self' to manage inplace - operations like: + Disable the 'this' ownership in 'self' to manage inplace + operations like: - A& A::operator+=(int i) { ...; return *this;} - - Here the 'self' parameter ownership needs to be disabled since - there could be two objects sharing the same 'this' pointer: the - input and the result one. And worse, the pointer could be deleted - in one of the objects (input), leaving the other (output) with - just a seg. fault to happen. + A& A::operator+=(int i) { ...; return *this;} - To avoid the previous problem, use + Here the 'self' parameter ownership needs to be disabled since + there could be two objects sharing the same 'this' pointer: the + input and the result one. And worse, the pointer could be deleted + in one of the objects (input), leaving the other (output) with + just a seg. fault to happen. - %feature("self:disown") *::operator+=; - %feature("new") *::operator+=; + To avoid the previous problem, use - These two lines just transfer the ownership of the 'this' pointer - from the input to the output wrapping object. - - This happens in python, but may also happens in other target - languages. - */ - if (GetFlag(n,"feature:self:disown")) { - Setattr(p,k_wrapdisown,"1"); + %feature("self:disown") *::operator+=; + %feature("new") *::operator+=; + + These two lines just transfer the ownership of the 'this' pointer + from the input to the output wrapping object. + + This happens in python, but may also happens in other target + languages. + */ + if (GetFlag(n, "feature:self:disown")) { + Setattr(p, k_wrapdisown, "1"); } - set_nextSibling(p,parms); + set_nextSibling(p, parms); Delete(type); - + /* Generate action code for the access */ if (!(flags & CWRAP_EXTEND)) { String *explicit_qualifier = 0; String *call = 0; String *cres = 0; String *explicitcall_name = 0; - int pure_virtual = !(Cmp(Getattr(n,k_storage), "virtual")) && !(Cmp(Getattr(n,k_value), "0")); + int pure_virtual = !(Cmp(Getattr(n, k_storage), "virtual")) && !(Cmp(Getattr(n, k_value), "0")); /* Call the explicit method rather than allow for a polymorphic call */ if ((flags & CWRAP_DIRECTOR_TWO_CALLS) || (flags & CWRAP_DIRECTOR_ONE_CALL)) { - String* access = Getattr(n, "access"); + String *access = Getattr(n, "access"); if (access && (Cmp(access, "protected") == 0)) { - /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ - String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n),"typescope"),k_qname)); - explicitcall_name = NewStringf("%sSwigPublic", name); - explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); - Delete(explicit_qualifier_tmp); + /* If protected access (can only be if a director method) then call the extra public accessor method (language module must provide this) */ + String *explicit_qualifier_tmp = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname)); + explicitcall_name = NewStringf("%sSwigPublic", name); + explicit_qualifier = NewStringf("SwigDirector_%s", explicit_qualifier_tmp); + Delete(explicit_qualifier_tmp); } else { - explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n),"typescope"),k_qname)); + explicit_qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname)); } } call = Swig_cmethod_call(explicitcall_name ? explicitcall_name : name, p, self, explicit_qualifier, director_type); - cres = Swig_cresult(Getattr(n,k_type),k_result, call); + cres = Swig_cresult(Getattr(n, k_type), k_result, call); if (pure_virtual && is_director && (flags & CWRAP_DIRECTOR_TWO_CALLS)) { - String *qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n),"typescope"),k_qname)); + String *qualifier = SwigType_namestr(Getattr(Getattr(parentNode(n), "typescope"), k_qname)); Delete(cres); cres = NewStringf("Swig::DirectorPureVirtualException::raise(\"%s::%s\");", qualifier, name); Delete(qualifier); @@ -887,14 +872,14 @@ Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_ /* Create two method calls, one to call the explicit method, the other a normal polymorphic function call */ String *cres_both_calls = NewStringf(""); String *call_extra = Swig_cmethod_call(name, p, self, 0, director_type); - String *cres_extra = Swig_cresult(Getattr(n,k_type),k_result, call_extra); + String *cres_extra = Swig_cresult(Getattr(n, k_type), k_result, call_extra); Printv(cres_both_calls, "if (upcall) {\n", cres, "\n", "} else {", cres_extra, "\n}", NIL); - Setattr(n,k_wrapaction, cres_both_calls); + Setattr(n, k_wrapaction, cres_both_calls); Delete(cres_extra); Delete(call_extra); Delete(cres_both_calls); } else { - Setattr(n,k_wrapaction, cres); + Setattr(n, k_wrapaction, cres); } Delete(explicitcall_name); @@ -905,24 +890,24 @@ Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_ /* Methods with default arguments are wrapped with additional methods for each default argument, * however, only one extra %extend method is generated. */ - String *defaultargs = Getattr(n,k_defaultargs); - String *code = Getattr(n,k_code); - String *cname = Getattr(n,k_classname) ? Getattr(n,k_classname) : classname; + String *defaultargs = Getattr(n, k_defaultargs); + String *code = Getattr(n, k_code); + String *cname = Getattr(n, k_classname) ? Getattr(n, k_classname) : classname; String *membername = Swig_name_member(cname, name); String *mangled = Swig_name_mangle(membername); int is_smart_pointer = flags & CWRAP_SMART_POINTER; - type = Getattr(n,k_type); + type = Getattr(n, k_type); /* Check if the method 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 methods to be defined in C. */ - if (Getattr(n,k_symoverloaded) && code) { - Append(mangled,Getattr(defaultargs ? defaultargs : n,k_symovername)); + 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 &&!is_smart_pointer) { + if (!defaultargs && code && !is_smart_pointer) { Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus); } @@ -931,47 +916,49 @@ Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_ Parm *pp = p; String *func = NewStringf("%s(", mangled); String *cres; - - if (Cmp(Getattr(n,k_storage),k_static) != 0) { - String *pname = Swig_cparm_name(pp,i); + + if (Cmp(Getattr(n, k_storage), k_static) != 0) { + String *pname = Swig_cparm_name(pp, i); String *fadd = NewStringf("(%s*)(%s)->operator ->()", cname, pname); - Append(func,fadd); + Append(func, fadd); Delete(fadd); Delete(pname); pp = nextSibling(pp); - if (pp) Append(func,","); - } else{ + if (pp) + Append(func, ","); + } else { pp = nextSibling(pp); } ++i; while (pp) { - SwigType *pt = Getattr(pp,k_type); + SwigType *pt = Getattr(pp, k_type); if ((SwigType_type(pt) != T_VOID)) { - String *pname = Swig_cparm_name(pp,i++); + String *pname = Swig_cparm_name(pp, i++); String *rcaststr = SwigType_rcaststr(pt, pname); - Append(func,rcaststr); + Append(func, rcaststr); Delete(rcaststr); Delete(pname); pp = nextSibling(pp); - if (pp) Append(func,","); + if (pp) + Append(func, ","); } } - Append(func,")"); - cres = Swig_cresult(Getattr(n,k_type),k_result, func); - Setattr(n,k_wrapaction, cres); + Append(func, ")"); + cres = Swig_cresult(Getattr(n, k_type), k_result, func); + Setattr(n, k_wrapaction, cres); Delete(cres); } else { - String *call = Swig_cfunction_call(mangled,p); - String *cres = Swig_cresult(Getattr(n,k_type),k_result, call); - Setattr(n,k_wrapaction, cres); + String *call = Swig_cfunction_call(mangled, p); + String *cres = Swig_cresult(Getattr(n, k_type), k_result, call); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } - + Delete(membername); Delete(mangled); } - Setattr(n,k_parms,p); + Setattr(n, k_parms, p); Delete(p); Delete(self); Delete(parms); @@ -984,27 +971,25 @@ Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_ * This function returns the class node for a given method or class. * ----------------------------------------------------------------------------- */ -Node* -Swig_methodclass(Node *n) { - Node* nodetype = Getattr(n, k_nodetype); - if (!Cmp(nodetype, "class")) return n; +Node *Swig_methodclass(Node *n) { + Node *nodetype = Getattr(n, k_nodetype); + if (!Cmp(nodetype, "class")) + return n; return GetFlag(n, "feature:extend") ? Getattr(Getattr(n, k_parentnode), k_parentnode) : Getattr(n, k_parentnode); } -int -Swig_directorclass(Node *n) { +int Swig_directorclass(Node *n) { Node *classNode = Swig_methodclass(n); assert(classNode != 0); return (Getattr(classNode, k_vtable) != 0); } -Node * -Swig_directormap(Node *module, String *type) { +Node *Swig_directormap(Node *module, String *type) { int is_void = !Cmp(type, "void"); if (!is_void && module) { /* ?? follow the inheritance hierarchy? */ - String* base = SwigType_base(type); + String *base = SwigType_base(type); Node *directormap = Getattr(module, k_wrapdirectormap); if (directormap) @@ -1013,32 +998,29 @@ Swig_directormap(Node *module, String *type) { return 0; } - + /* ----------------------------------------------------------------------------- * Swig_ConstructorToFunction() * * This function creates a C wrapper for a C constructor function. * ----------------------------------------------------------------------------- */ -int -Swig_ConstructorToFunction(Node *n, String *classname, - String *none_comparison, String *director_ctor, int cplus, int flags) -{ +int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags) { ParmList *parms; - Parm *prefix_args; - Parm *p; + Parm *prefix_args; + Parm *p; ParmList *directorparms; SwigType *type; - Node *classNode; - int use_director; - + Node *classNode; + int use_director; + classNode = Swig_methodclass(n); use_director = Swig_directorclass(n); - parms = CopyParmList(nonvoid_parms(Getattr(n,k_parms))); + parms = CopyParmList(nonvoid_parms(Getattr(n, k_parms))); /* Prepend the list of prefix_args (if any) */ - prefix_args = Getattr(n,k_directorprefixargs); + prefix_args = Getattr(n, k_directorprefixargs); if (prefix_args != NIL) { Parm *p2, *p3; @@ -1053,7 +1035,7 @@ Swig_ConstructorToFunction(Node *n, String *classname, } else directorparms = parms; - type = NewString(classname); + type = NewString(classname); SwigType_add_pointer(type); if (flags & CWRAP_EXTEND) { @@ -1061,26 +1043,26 @@ Swig_ConstructorToFunction(Node *n, String *classname, * 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 *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)); + 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); } - - call = Swig_cfunction_call(mangled,parms); - cres = Swig_cresult(type,k_result, call); - Setattr(n,k_wrapaction, cres); + + call = Swig_cfunction_call(mangled, parms); + cres = Swig_cresult(type, k_result, call); + Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); Delete(membername); @@ -1090,15 +1072,15 @@ Swig_ConstructorToFunction(Node *n, String *classname, /* 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; + 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" ); + 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); @@ -1123,37 +1105,37 @@ Swig_ConstructorToFunction(Node *n, String *classname, */ String *cres; Append(action, director_ctor); - Replaceall( action, "$comparison", tmp_none_comparison); + Replaceall(action, "$comparison", tmp_none_comparison); cres = Swig_cresult(type, k_result, director_call); - Replaceall( action, "$director_new",cres); + Replaceall(action, "$director_new", cres); Delete(cres); cres = Swig_cresult(type, k_result, nodirector_call); - Replaceall( action, "$nondirector_new", cres); + Replaceall(action, "$nondirector_new", cres); Delete(cres); } Setattr(n, k_wrapaction, action); Delete(tmp_none_comparison); Delete(action); - Delete(directorname); + Delete(directorname); } else { - String *call = Swig_cppconstructor_call(classname,parms); - String *cres = Swig_cresult(type,k_result, call); - Setattr(n,k_wrapaction, cres); + 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); + 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); + Setattr(n, k_type, type); + Setattr(n, k_parms, parms); Delete(type); if (directorparms != parms) Delete(directorparms); @@ -1167,18 +1149,16 @@ Swig_ConstructorToFunction(Node *n, String *classname, * This function creates a C wrapper for a destructor function. * ----------------------------------------------------------------------------- */ -int -Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) -{ +int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) { SwigType *type; - Parm *p; - - type = NewString(classname); + Parm *p; + + type = NewString(classname); SwigType_add_pointer(type); - p = NewParm(type,k_self); - Setattr(p,k_self,"1"); - Setattr(p,k_hidden,"1"); - Setattr(p,k_wrapdisown,"1"); + p = NewParm(type, k_self); + Setattr(p, k_self, "1"); + Setattr(p, k_hidden, "1"); + Setattr(p, k_wrapdisown, "1"); Delete(type); type = NewString("void"); @@ -1188,13 +1168,13 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) String *membername, *mangled, *code; membername = Swig_name_destroy(classname); mangled = Swig_name_mangle(membername); - code = Getattr(n,k_code); + code = Getattr(n, k_code); if (code) { Swig_add_extension_code(n, mangled, p, type, code, cparse_cplusplus); } - call = Swig_cfunction_call(mangled,p); + call = Swig_cfunction_call(mangled, p); cres = NewStringf("%s;\n", call); - Setattr(n,k_wrapaction, cres); + Setattr(n, k_wrapaction, cres); Delete(membername); Delete(mangled); Delete(call); @@ -1202,20 +1182,20 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) } else { if (cplus) { String *call = Swig_cppdestructor_call(n); - String *cres = NewStringf("%s\n",call); - Setattr(n,k_wrapaction, cres); + String *cres = NewStringf("%s\n", call); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } else { String *call = Swig_cdestructor_call(n); String *cres = NewStringf("%s\n", call); - Setattr(n,k_wrapaction, cres); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } } - Setattr(n,k_type,type); - Setattr(n,k_parms, p); + Setattr(n, k_type, type); + Setattr(n, k_parms, p); Delete(type); Delete(p); return SWIG_OK; @@ -1227,28 +1207,27 @@ Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) * This function creates a C wrapper for setting a structure member. * ----------------------------------------------------------------------------- */ -int -Swig_MembersetToFunction(Node *n, String *classname, int flags) { - String *name; +int Swig_MembersetToFunction(Node *n, String *classname, int flags) { + String *name; ParmList *parms; - Parm *p; + Parm *p; SwigType *t; SwigType *ty; SwigType *type; SwigType *void_type = NewString("void"); - String *membername; - String *mangled; - String *self= 0; - String *sname; - - int varcref = flags & CWRAP_NATURAL_VAR; + String *membername; + String *mangled; + String *self = 0; + String *sname; + + int varcref = flags & CWRAP_NATURAL_VAR; if (flags & CWRAP_SMART_POINTER) { self = NewString("(*this)->"); } - name = Getattr(n,k_name); - type = Getattr(n,k_type); + name = Getattr(n, k_name); + type = Getattr(n, k_type); sname = Swig_name_set(name); membername = Swig_name_member(classname, sname); @@ -1256,43 +1235,43 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) { t = NewString(classname); SwigType_add_pointer(t); - parms = NewParm(t,k_self); - Setattr(parms,k_self,"1"); - Setattr(parms,k_hidden,"1"); + parms = NewParm(t, k_self); + Setattr(parms, k_self, "1"); + Setattr(parms, k_hidden, "1"); Delete(t); ty = Swig_wrapped_member_var_type(type, varcref); - p = NewParm(ty,name); - Setattr(parms,k_hidden,"1"); - set_nextSibling(parms,p); + p = NewParm(ty, name); + Setattr(parms, k_hidden, "1"); + set_nextSibling(parms, p); /* If the type is a pointer or reference. We mark it with a special wrap:disown attribute */ - if (SwigType_check_decl(type,"p.")) { - Setattr(p,k_wrapdisown,"1"); + if (SwigType_check_decl(type, "p.")) { + Setattr(p, k_wrapdisown, "1"); } Delete(p); if (flags & CWRAP_EXTEND) { String *call; String *cres; - String *code = Getattr(n,k_code); + String *code = Getattr(n, k_code); if (code) { Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus); } - call = Swig_cfunction_call(mangled,parms); + call = Swig_cfunction_call(mangled, parms); cres = NewStringf("%s;\n", call); - Setattr(n,k_wrapaction, cres); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } else { - String *call = Swig_cmemberset_call(name,type,self, varcref); + String *call = Swig_cmemberset_call(name, type, self, varcref); String *cres = NewStringf("%s;\n", call); - Setattr(n,k_wrapaction, cres); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } - Setattr(n,k_type,void_type); - Setattr(n,k_parms, parms); + Setattr(n, k_type, void_type); + Setattr(n, k_parms, parms); Delete(parms); Delete(ty); Delete(void_type); @@ -1309,67 +1288,66 @@ Swig_MembersetToFunction(Node *n, String *classname, int flags) { * This function creates a C wrapper for getting a structure member. * ----------------------------------------------------------------------------- */ -int -Swig_MembergetToFunction(Node *n, String *classname, int flags) { - String *name; +int Swig_MembergetToFunction(Node *n, String *classname, int flags) { + String *name; ParmList *parms; SwigType *t; SwigType *ty; SwigType *type; - String *membername; - String *mangled; - String *self = 0; - String *gname; + String *membername; + String *mangled; + String *self = 0; + String *gname; - int varcref = flags & CWRAP_NATURAL_VAR; + int varcref = flags & CWRAP_NATURAL_VAR; if (flags & CWRAP_SMART_POINTER) { if (checkAttribute(n, k_storage, k_static)) { - Node *sn = Getattr(n,k_cplusstaticbase); - String *base = Getattr(sn,k_name); + Node *sn = Getattr(n, k_cplusstaticbase); + String *base = Getattr(sn, k_name); self = NewStringf("%s::", base); } else { self = NewString("(*this)->"); } } - name = Getattr(n,k_name); - type = Getattr(n,k_type); - + name = Getattr(n, k_name); + type = Getattr(n, k_type); + gname = Swig_name_get(name); membername = Swig_name_member(classname, gname); mangled = Swig_name_mangle(membername); t = NewString(classname); SwigType_add_pointer(t); - parms = NewParm(t,k_self); - Setattr(parms,k_self,"1"); - Setattr(parms,k_hidden,"1"); + parms = NewParm(t, k_self); + Setattr(parms, k_self, "1"); + Setattr(parms, k_hidden, "1"); Delete(t); ty = Swig_wrapped_member_var_type(type, varcref); if (flags & CWRAP_EXTEND) { String *call; String *cres; - - String *code = Getattr(n,k_code); + + String *code = Getattr(n, k_code); if (code) { Swig_add_extension_code(n, mangled, parms, ty, code, cparse_cplusplus); } - call = Swig_cfunction_call(mangled,parms); - cres = Swig_cresult(ty,k_result,call); - Setattr(n,k_wrapaction, cres); + call = Swig_cfunction_call(mangled, parms); + cres = Swig_cresult(ty, k_result, call); + Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); } else { - String *call = Swig_cmemberget_call(name,type,self, varcref); - String *cres = Swig_cresult(ty,k_result,call); - Setattr(n,k_wrapaction, cres); + String *call = Swig_cmemberget_call(name, type, self, varcref); + String *cres = Swig_cresult(ty, k_result, call); + Setattr(n, k_wrapaction, cres); Delete(call); Delete(cres); } - Setattr(n,k_type,ty); - Setattr(n,k_parms, parms); + Setattr(n, k_type, ty); + Setattr(n, k_parms, parms); Delete(parms); Delete(ty); Delete(membername); @@ -1385,39 +1363,38 @@ Swig_MembergetToFunction(Node *n, String *classname, int flags) { * This function creates a C wrapper for setting a global variable. * ----------------------------------------------------------------------------- */ -int -Swig_VarsetToFunction(Node *n, int flags) { - String *name,*nname; +int Swig_VarsetToFunction(Node *n, int flags) { + String *name, *nname; ParmList *parms; SwigType *type, *ty; - int varcref = flags & CWRAP_NATURAL_VAR; + int varcref = flags & CWRAP_NATURAL_VAR; - name = Getattr(n,k_name); - type = Getattr(n,k_type); + name = Getattr(n, k_name); + type = Getattr(n, k_type); nname = SwigType_namestr(name); ty = Swig_wrapped_var_type(type, varcref); - parms = NewParm(ty,name); + parms = NewParm(ty, name); Delete(ty); - - if (!Strstr(type,"enum $unnamed")) { - String *pname = Swig_cparm_name(0,0); - String *dref = Swig_wrapped_var_deref(type,pname, varcref); + + if (!Strstr(type, "enum $unnamed")) { + String *pname = Swig_cparm_name(0, 0); + String *dref = Swig_wrapped_var_deref(type, pname, varcref); String *call = NewStringf("%s = %s;\n", nname, dref); - Setattr(n,k_wrapaction, call); + Setattr(n, k_wrapaction, call); Delete(call); Delete(dref); Delete(pname); } else { - String *pname = Swig_cparm_name(0,0); + String *pname = Swig_cparm_name(0, 0); String *call = NewStringf("if (sizeof(int) == sizeof(%s)) *(int*)(void*)&(%s) = %s;\n", nname, nname, pname); - Setattr(n,k_wrapaction, call); + Setattr(n, k_wrapaction, call); Delete(call); } - Setattr(n,k_type,"void"); - Setattr(n,k_parms,parms); + Setattr(n, k_type, "void"); + Setattr(n, k_parms, parms); Delete(parms); Delete(nname); return SWIG_OK; @@ -1429,26 +1406,25 @@ Swig_VarsetToFunction(Node *n, int flags) { * This function creates a C wrapper for getting a global variable. * ----------------------------------------------------------------------------- */ -int -Swig_VargetToFunction(Node *n, int flags) { +int Swig_VargetToFunction(Node *n, int flags) { String *cres, *call; - String *name, *nname; + String *name, *nname; SwigType *type, *ty; - int varcref = flags & CWRAP_NATURAL_VAR; + int varcref = flags & CWRAP_NATURAL_VAR; - name = Getattr(n,k_name); - type = Getattr(n,k_type); + name = Getattr(n, k_name); + type = Getattr(n, k_type); nname = SwigType_namestr(name); ty = Swig_wrapped_var_type(type, varcref); - call = Swig_wrapped_var_assign(type,nname, varcref); - cres = Swig_cresult(ty,k_result,call); - Setattr(n,k_wrapaction, cres); + call = Swig_wrapped_var_assign(type, nname, varcref); + cres = Swig_cresult(ty, k_result, call); + Setattr(n, k_wrapaction, cres); Delete(cres); Delete(call); - Setattr(n,k_type,ty); - Delattr(n,k_parms); + Setattr(n, k_type, ty); + Delattr(n, k_parms); Delete(nname); Delete(ty); return SWIG_OK; diff --git a/SWIG/Source/Swig/error.c b/SWIG/Source/Swig/error.c index 365ea92c3..926bf5b50 100644 --- a/SWIG/Source/Swig/error.c +++ b/SWIG/Source/Swig/error.c @@ -38,8 +38,8 @@ char cvsroot_error_c[] = "$Header$"; # define DEFAULT_ERROR_MSG_FORMAT EMF_STANDARD #endif static ErrorMessageFormat msg_format = DEFAULT_ERROR_MSG_FORMAT; -static int silence = 0; /* Silent operation */ -static String *filter = 0; /* Warning filter */ +static int silence = 0; /* Silent operation */ +static String *filter = 0; /* Warning filter */ static int warnall = 0; static int nwarning = 0; static int nerrors = 0; @@ -58,22 +58,23 @@ static String *format_filename(const String_or_char *filename); * Issue a warning message * ----------------------------------------------------------------------------- */ -void -Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt, ...) { +void Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt, ...) { String *out; - char *msg; - int wrn = 1; + char *msg; + int wrn = 1; va_list ap; - if (silence) return; - if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); + if (silence) + return; + if (!init_fmt) + Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); - va_start(ap,fmt); + va_start(ap, fmt); out = NewStringEmpty(); - vPrintf(out,fmt,ap); + vPrintf(out, fmt, ap); msg = Char(out); - if (isdigit((unsigned char)*msg)) { + if (isdigit((unsigned char) *msg)) { unsigned long result = strtoul(msg, &msg, 10); if (msg != Char(out)) { msg++; @@ -83,13 +84,15 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt /* Check in the warning filter */ if (filter) { - char temp[32]; + char temp[32]; char *c; char *f = Char(filter); - sprintf(temp,"%d",wnum); - while(*f != '\0' && (c = strstr(f,temp))) { - if (*(c-1) == '-') wrn = 0; /* Warning disabled */ - if (*(c-1) == '+') wrn = 1; /* Warning enabled */ + sprintf(temp, "%d", wnum); + while (*f != '\0' && (c = strstr(f, temp))) { + if (*(c - 1) == '-') + wrn = 0; /* Warning disabled */ + if (*(c - 1) == '+') + wrn = 1; /* Warning enabled */ f += strlen(temp); } } @@ -100,7 +103,7 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt } else { Printf(stderr, wrn_nnum_fmt, formatted_filename, line); } - Printf(stderr,"%s",msg); + Printf(stderr, "%s", msg); nwarning++; Delete(formatted_filename); } @@ -114,22 +117,23 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt * Issue an error message * ----------------------------------------------------------------------------- */ -void -Swig_error(const String_or_char *filename, int line, const char *fmt, ...) { +void Swig_error(const String_or_char *filename, int line, const char *fmt, ...) { va_list ap; String *formatted_filename = NULL; - if (silence) return; - if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); - - va_start(ap,fmt); + if (silence) + return; + if (!init_fmt) + Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); + + va_start(ap, fmt); formatted_filename = format_filename(filename); if (line > 0) { Printf(stderr, err_line_fmt, formatted_filename, line); } else { Printf(stderr, err_eof_fmt, formatted_filename); } - vPrintf(stderr,fmt,ap); + vPrintf(stderr, fmt, ap); va_end(ap); nerrors++; Delete(formatted_filename); @@ -141,8 +145,7 @@ Swig_error(const String_or_char *filename, int line, const char *fmt, ...) { * Returns number of errors received. * ----------------------------------------------------------------------------- */ -int -Swig_error_count(void) { +int Swig_error_count(void) { return nerrors; } @@ -152,8 +155,7 @@ Swig_error_count(void) { * Set silent flag * ----------------------------------------------------------------------------- */ -void -Swig_error_silent(int s) { +void Swig_error_silent(int s) { silence = s; } @@ -164,14 +166,14 @@ Swig_error_silent(int s) { * Takes a comma separate list of warning numbers and puts in the filter. * ----------------------------------------------------------------------------- */ -void -Swig_warnfilter(const String_or_char *wlist, int add) { +void Swig_warnfilter(const String_or_char *wlist, int add) { char *c; char *cw; String *s; - if (!filter) filter = NewStringEmpty(); - + if (!filter) + filter = NewStringEmpty(); + s = NewString(""); Clear(s); cw = Char(wlist); @@ -182,31 +184,30 @@ Swig_warnfilter(const String_or_char *wlist, int add) { ++cw; } c = Char(s); - c = strtok(c,", "); + c = strtok(c, ", "); while (c) { if (isdigit((int) *c) || (*c == '+') || (*c == '-')) { if (add) { - Insert(filter,0,c); + Insert(filter, 0, c); if (isdigit((int) *c)) { - Insert(filter,0,"-"); + Insert(filter, 0, "-"); } } else { char temp[32]; if (isdigit((int) *c)) { - sprintf(temp,"-%s",c); + sprintf(temp, "-%s", c); } else { - strcpy(temp,c); + strcpy(temp, c); } - Replace(filter,temp,"", DOH_REPLACE_FIRST); + Replace(filter, temp, "", DOH_REPLACE_FIRST); } } - c = strtok(NULL,", "); + c = strtok(NULL, ", "); } Delete(s); } -void -Swig_warnall(void) { +void Swig_warnall(void) { warnall = 1; } @@ -217,8 +218,7 @@ Swig_warnall(void) { * Return the number of warnings * ----------------------------------------------------------------------------- */ -int -Swig_warn_count(void) { +int Swig_warn_count(void) { return nwarning; } @@ -228,31 +228,30 @@ Swig_warn_count(void) { * Set the type of error/warning message display * ----------------------------------------------------------------------------- */ -void -Swig_error_msg_format(ErrorMessageFormat format) { - const char* error = "Error"; - const char* warning = "Warning"; +void Swig_error_msg_format(ErrorMessageFormat format) { + const char *error = "Error"; + const char *warning = "Warning"; - const char* fmt_eof = 0; - const char* fmt_line = 0; + const char *fmt_eof = 0; + const char *fmt_line = 0; /* here 'format' could be directly a string instead of an enum, but by now a switch is used to translated into one. */ switch (format) { case EMF_MICROSOFT: fmt_line = "%s(%d)"; - fmt_eof = "%s(999999)"; /* Is there a special character for EOF? Just use a large number. */ + fmt_eof = "%s(999999)"; /* Is there a special character for EOF? Just use a large number. */ break; case EMF_STANDARD: default: fmt_line = "%s:%d"; - fmt_eof = "%s:EOF"; + fmt_eof = "%s:EOF"; } sprintf(wrn_wnum_fmt, "%s: %s(%%d): ", fmt_line, warning); - sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning); - sprintf(err_line_fmt, "%s: %s: ", fmt_line, error); - sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error); + sprintf(wrn_nnum_fmt, "%s: %s: ", fmt_line, warning); + sprintf(err_line_fmt, "%s: %s: ", fmt_line, error); + sprintf(err_eof_fmt, "%s: %s: ", fmt_eof, error); msg_format = format; init_fmt = 1; @@ -263,12 +262,10 @@ Swig_error_msg_format(ErrorMessageFormat format) { * * Remove double backslashes in Windows filename paths for display * ----------------------------------------------------------------------------- */ -static String * -format_filename(const String_or_char *filename) { +static String *format_filename(const String_or_char *filename) { String *formatted_filename = NewString(filename); #if defined(_WIN32) - Replaceall(formatted_filename,"\\\\","\\"); + Replaceall(formatted_filename, "\\\\", "\\"); #endif - return formatted_filename; + return formatted_filename; } - diff --git a/SWIG/Source/Swig/fragment.c b/SWIG/Source/Swig/fragment.c index 7cf137050..2ba58d0a5 100644 --- a/SWIG/Source/Swig/fragment.c +++ b/SWIG/Source/Swig/fragment.c @@ -30,35 +30,36 @@ static int debug = 0; * changed, lang.cxx doesn't nedd to be touched again. * ----------------------------------------------------------------------------- */ -void -Swig_fragment_register(Node* fragment) { - if (Getattr(fragment,k_emitonly)) { +void Swig_fragment_register(Node *fragment) { + if (Getattr(fragment, k_emitonly)) { Swig_fragment_emit(fragment); return; } else { - String *name = Copy(Getattr(fragment,k_value)); - String *type = Getattr(fragment,k_type); + String *name = Copy(Getattr(fragment, k_value)); + String *type = Getattr(fragment, k_type); if (type) { SwigType *rtype = SwigType_typedef_resolve_all(type); String *mangle = Swig_string_mangle(type); - Append(name,mangle); + Append(name, mangle); Delete(mangle); Delete(rtype); - if (debug) Printf(stdout,"register fragment %s %s\n",name,type); + if (debug) + Printf(stdout, "register fragment %s %s\n", name, type); } if (!fragments) { fragments = NewHash(); } - if (!Getattr(fragments,name)) { - String *section = Copy(Getattr(fragment,k_section)); - String *ccode = Copy(Getattr(fragment,k_code)); - Hash *kwargs = Getattr(fragment,k_kwargs); - Setmeta(ccode,k_section,section); + if (!Getattr(fragments, name)) { + String *section = Copy(Getattr(fragment, k_section)); + String *ccode = Copy(Getattr(fragment, k_code)); + Hash *kwargs = Getattr(fragment, k_kwargs); + Setmeta(ccode, k_section, section); if (kwargs) { - Setmeta(ccode,k_kwargs,kwargs); + Setmeta(ccode, k_kwargs, kwargs); } - Setattr(fragments,name,ccode); - if (debug) Printf(stdout,"registering fragment %s %s\n",name,section); + Setattr(fragments, name, ccode); + if (debug) + Printf(stdout, "registering fragment %s %s\n", name, section); Delete(section); Delete(ccode); } @@ -73,16 +74,15 @@ Swig_fragment_register(Node* fragment) { * ----------------------------------------------------------------------------- */ static -char* char_index(char* str, char c) -{ - while (*str && (c != *str)) ++str; +char *char_index(char *str, char c) { + while (*str && (c != *str)) + ++str; return (c == *str) ? str : 0; } -void -Swig_fragment_emit(Node *n) { +void Swig_fragment_emit(Node *n) { String *code; - char *pc, *tok; + char *pc, *tok; String *t; String *mangle = 0; String *name = 0; @@ -92,38 +92,44 @@ Swig_fragment_emit(Node *n) { Swig_warning(WARN_FRAGMENT_NOT_FOUND, Getfile(n), Getline(n), "Fragment '%s' not found.\n", name); return; } - - name = Getattr(n,k_value); + + name = Getattr(n, k_value); if (!name) { name = n; } - type = Getattr(n,k_type); + type = Getattr(n, k_type); if (type) { mangle = Swig_string_mangle(type); } - if (debug) Printf(stdout,"looking fragment %s %s\n",name, 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; + 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)) { + 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"); + } + 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); + 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); @@ -133,23 +139,25 @@ Swig_fragment_emit(Node *n) { 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); + 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); + 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)); + if (!Equal(type, rtype)) { + String *name = Copy(Getattr(n, k_value)); String *mangle = Swig_string_mangle(type); - Append(name,mangle); + Append(name, mangle); Setfile(name, Getfile(n)); Setline(name, Getline(n)); Swig_fragment_emit(name); @@ -158,17 +166,17 @@ Swig_fragment_emit(Node *n) { } 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; + pc = char_index(tok, ','); + if (pc) + *pc = 0; } Delete(name); } Delete(t); } - diff --git a/SWIG/Source/Swig/getopt.c b/SWIG/Source/Swig/getopt.c index e6bafe5b7..3b1cb1fb2 100644 --- a/SWIG/Source/Swig/getopt.c +++ b/SWIG/Source/Swig/getopt.c @@ -21,8 +21,8 @@ char cvsroot_getopt_c[] = "$Header$"; #include "swig.h" static char **args; -static int numargs; -static int *marked; +static int numargs; +static int *marked; /* ----------------------------------------------------------------------------- * Swig_init_args() @@ -30,8 +30,7 @@ static int *marked; * Initialize the argument list handler. * ----------------------------------------------------------------------------- */ -void -Swig_init_args(int argc, char **argv) { +void Swig_init_args(int argc, char **argv) { int i; assert(argc > 0); assert(argv); @@ -51,11 +50,10 @@ Swig_init_args(int argc, char **argv) { * Marks an argument as being parsed. * ----------------------------------------------------------------------------- */ -void -Swig_mark_arg(int n) { - assert(marked); - assert((n >= 0) && (n < numargs)); - marked[n] = 1; +void Swig_mark_arg(int n) { + assert(marked); + assert((n >= 0) && (n < numargs)); + marked[n] = 1; } /* ----------------------------------------------------------------------------- @@ -64,9 +62,8 @@ Swig_mark_arg(int n) { * Checks to see if argument has been picked up. * ----------------------------------------------------------------------------- */ -int -Swig_check_marked(int n) { - assert((n>=0) && (n < numargs)); +int Swig_check_marked(int n) { + assert((n >= 0) && (n < numargs)); return marked[n]; } @@ -75,27 +72,26 @@ Swig_check_marked(int n) { * * Checkers for unprocessed command line options and errors. * ----------------------------------------------------------------------------- */ - -void -Swig_check_options(int check_input) { - int error = 0; - int i; - int max = check_input ? numargs - 1 : numargs; - assert(marked); - for (i = 1; i < max; i++) { - if (!marked[i]) { - Printf(stderr,"swig error : Unrecognized option %s\n", args[i]); - error=1; - } - } - if (error) { - Printf(stderr,"Use 'swig -help' for available options.\n"); - exit(1); - } - if (check_input && marked[numargs-1]) { - Printf(stderr,"Must specify an input file. Use -help for available options.\n"); - exit(1); + +void Swig_check_options(int check_input) { + int error = 0; + int i; + int max = check_input ? numargs - 1 : numargs; + assert(marked); + for (i = 1; i < max; i++) { + if (!marked[i]) { + Printf(stderr, "swig error : Unrecognized option %s\n", args[i]); + error = 1; } + } + if (error) { + Printf(stderr, "Use 'swig -help' for available options.\n"); + exit(1); + } + if (check_input && marked[numargs - 1]) { + Printf(stderr, "Must specify an input file. Use -help for available options.\n"); + exit(1); + } } /* ----------------------------------------------------------------------------- @@ -104,13 +100,8 @@ Swig_check_options(int check_input) { * Generates a generic error message and exits. * ----------------------------------------------------------------------------- */ -void -Swig_arg_error() { - Printf(stderr,"SWIG : Unable to parse command line options.\n"); - Printf(stderr,"Use 'swig -help' for available options.\n"); +void Swig_arg_error() { + Printf(stderr, "SWIG : Unable to parse command line options.\n"); + Printf(stderr, "Use 'swig -help' for available options.\n"); exit(1); } - - - - diff --git a/SWIG/Source/Swig/include.c b/SWIG/Source/Swig/include.c index 9b56bdf0f..64f7288b6 100644 --- a/SWIG/Source/Swig/include.c +++ b/SWIG/Source/Swig/include.c @@ -16,11 +16,11 @@ char cvsroot_include_c[] = "$Header$"; /* Delimeter used in accessing files and directories */ -static List *directories = 0; /* List of include directories */ -static String *lastpath = 0; /* Last file that was included */ -static String *swiglib = 0; /* Location of SWIG library */ -static String *lang_config = 0; /* Language configuration file */ -static int dopush = 1; /* Whether to push directories */ +static List *directories = 0; /* List of include directories */ +static String *lastpath = 0; /* Last file that was included */ +static String *swiglib = 0; /* Location of SWIG library */ +static String *lang_config = 0; /* Language configuration file */ +static int dopush = 1; /* Whether to push directories */ /* This functions determine whether to push/pop dirs in the preprocessor */ void Swig_set_push_dir(int push) { @@ -51,13 +51,11 @@ String *Swig_get_config_file() { * include mechanism, but rather as a query interface for language modules. * ----------------------------------------------------------------------------- */ -void -Swig_swiglib_set(const String_or_char *sl) { +void Swig_swiglib_set(const String_or_char *sl) { swiglib = NewString(sl); } -String * -Swig_swiglib_get() { +String *Swig_swiglib_get() { return swiglib; } @@ -67,9 +65,9 @@ Swig_swiglib_get() { * Adds a directory to the SWIG search path. * ----------------------------------------------------------------------------- */ -List * -Swig_add_directory(const String_or_char *dirname) { - if (!directories) directories = NewList(); +List *Swig_add_directory(const String_or_char *dirname) { + if (!directories) + directories = NewList(); assert(directories); if (dirname) { String *sdir = NewString(dirname); @@ -93,21 +91,23 @@ Swig_add_directory(const String_or_char *dirname) { * the preprocessor to grab files in the same directory as other included files. * ----------------------------------------------------------------------------- */ -void -Swig_push_directory(const String_or_char *dirname) { +void Swig_push_directory(const String_or_char *dirname) { String *tmp = 0; - if (!Swig_get_push_dir()) return; - if (!directories) directories = NewList(); + if (!Swig_get_push_dir()) + return; + if (!directories) + directories = NewList(); assert(directories); if (!DohIsString(dirname)) { dirname = tmp = NewString(dirname); assert(dirname); - } + } if (dirname) { Hash *dir = NewHash(); Setattr(dir, k_name, dirname); Insert(directories, 0, dir); - if (tmp) Delete(tmp); + if (tmp) + Delete(tmp); } } @@ -118,11 +118,12 @@ Swig_push_directory(const String_or_char *dirname) { * the preprocessor. * ----------------------------------------------------------------------------- */ -void -Swig_pop_directory() { - if (!Swig_get_push_dir()) return; - if (!directories) return; - Delitem(directories,0); +void Swig_pop_directory() { + if (!Swig_get_push_dir()) + return; + if (!directories) + return; + Delitem(directories, 0); } /* ----------------------------------------------------------------------------- @@ -131,8 +132,7 @@ Swig_pop_directory() { * Returns the full pathname of the last file opened. * ----------------------------------------------------------------------------- */ -String * -Swig_last_file() { +String *Swig_last_file() { assert(lastpath); return lastpath; } @@ -143,11 +143,10 @@ Swig_last_file() { * Returns a list of the current search paths. * ----------------------------------------------------------------------------- */ -static List * -Swig_search_path_any(int syspath) { +static List *Swig_search_path_any(int syspath) { String *filename; String *dirname; - List *slist, *llist; + List *slist, *llist; int i, ilen; llist = 0; @@ -156,35 +155,35 @@ Swig_search_path_any(int syspath) { filename = NewStringEmpty(); assert(filename); #ifdef MACSWIG - Printf(filename,"%s",SWIG_FILE_DELIMETER); + Printf(filename, "%s", SWIG_FILE_DELIMETER); #else - Printf(filename,".%s", SWIG_FILE_DELIMETER); + Printf(filename, ".%s", SWIG_FILE_DELIMETER); #endif if (syspath) { llist = NewList(); assert(llist); - Append(llist,filename); + Append(llist, filename); } else { - Append(slist,filename); - } + Append(slist, filename); + } ilen = Len(directories); for (i = 0; i < ilen; i++) { int issimple = 0; - dirname = Getitem(directories,i); + dirname = Getitem(directories, i); filename = NewStringEmpty(); assert(filename); if (DohIsString(dirname)) { filename = Copy(dirname); issimple = 1; } else { - filename = Copy(Getattr(dirname,k_name)); + filename = Copy(Getattr(dirname, k_name)); } StringAppend(filename, SWIG_FILE_DELIMETER); - if (syspath && (issimple || !GetFlag(dirname,k_sysdir))) { - Append(llist,filename); + if (syspath && (issimple || !GetFlag(dirname, k_sysdir))) { + Append(llist, filename); } else { - Append(slist,filename); + Append(slist, filename); /* Insert(slist,0,filename); */ } Delete(filename); @@ -192,16 +191,15 @@ Swig_search_path_any(int syspath) { if (syspath) { int ilen = Len(llist); for (i = 0; i < ilen; i++) { - Append(slist,Getitem(llist,i)); + Append(slist, Getitem(llist, i)); } Delete(llist); } return slist; -} +} -List * -Swig_search_path() { +List *Swig_search_path() { return Swig_search_path_any(0); } @@ -213,36 +211,37 @@ Swig_search_path() { * Looks for a file and open it. Returns an open FILE * on success. * ----------------------------------------------------------------------------- */ -static FILE * -Swig_open_any(const String_or_char *name, int sysfile) { - FILE *f; - String *filename; - List *spath = 0; - char *cname; - int i, ilen; +static FILE *Swig_open_any(const String_or_char *name, int sysfile) { + FILE *f; + String *filename; + List *spath = 0; + char *cname; + int i, ilen; - if (!directories) directories = NewList(); + if (!directories) + directories = NewList(); assert(directories); cname = Char(name); filename = NewString(cname); assert(filename); - f = fopen(Char(filename),"r"); + f = fopen(Char(filename), "r"); if (!f) { - spath = Swig_search_path_any(sysfile); - ilen = Len(spath); - for (i = 0; i < ilen; i++) { - Clear(filename); - Printf(filename,"%s%s", Getitem(spath,i), cname); - f = fopen(Char(filename),"r"); - if (f) break; - } - Delete(spath); + spath = Swig_search_path_any(sysfile); + ilen = Len(spath); + for (i = 0; i < ilen; i++) { + Clear(filename); + Printf(filename, "%s%s", Getitem(spath, i), cname); + f = fopen(Char(filename), "r"); + if (f) + break; + } + Delete(spath); } if (f) { -#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ - Replaceall(filename,"\\\\","\\"); /* remove double '\' in case any already present */ - Replaceall(filename,"\\","\\\\"); +#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */ + Replaceall(filename, "\\\\", "\\"); /* remove double '\' in case any already present */ + Replaceall(filename, "\\", "\\\\"); #endif Delete(lastpath); lastpath = Copy(filename); @@ -251,8 +250,7 @@ Swig_open_any(const String_or_char *name, int sysfile) { return f; } -FILE * -Swig_open(const String_or_char *name) { +FILE *Swig_open(const String_or_char *name) { return Swig_open_any(name, 0); } @@ -264,24 +262,23 @@ Swig_open(const String_or_char *name) { * Reads data from an open FILE * and returns it as a string. * ----------------------------------------------------------------------------- */ -String * -Swig_read_file(FILE *f) { - int len; - char buffer[4096]; +String *Swig_read_file(FILE *f) { + int len; + char buffer[4096]; String *str = NewStringEmpty(); assert(str); - while (fgets(buffer,4095,f)) { - StringAppend(str,buffer); + while (fgets(buffer, 4095, f)) { + StringAppend(str, buffer); } len = StringLen(str); if (len) { char *cstr = Char(str); if (cstr[len - 1] != '\n') { StringAppend(str, "\n"); - } + } } - + return str; } @@ -291,31 +288,29 @@ Swig_read_file(FILE *f) { * Opens a file and returns it as a string. * ----------------------------------------------------------------------------- */ -static String * -Swig_include_any(const String_or_char *name, int sysfile) { - FILE *f; - String *str; - String *file; +static String *Swig_include_any(const String_or_char *name, int sysfile) { + FILE *f; + String *str; + String *file; f = Swig_open_any(name, sysfile); - if (!f) return 0; + if (!f) + return 0; str = Swig_read_file(f); fclose(f); - Seek(str,0,SEEK_SET); + Seek(str, 0, SEEK_SET); file = Copy(lastpath); - Setfile(str,file); + Setfile(str, file); Delete(file); - Setline(str,1); + Setline(str, 1); return str; } -String * -Swig_include(const String_or_char *name) { +String *Swig_include(const String_or_char *name) { return Swig_include_any(name, 0); } -String * -Swig_include_sys(const String_or_char *name) { +String *Swig_include_sys(const String_or_char *name) { return Swig_include_any(name, 1); } @@ -326,15 +321,15 @@ Swig_include_sys(const String_or_char *name) { * Copies the contents of a file into another file * ----------------------------------------------------------------------------- */ -int -Swig_insert_file(const String_or_char *filename, File *outfile) { +int Swig_insert_file(const String_or_char *filename, File *outfile) { char buffer[4096]; - int nbytes; + int nbytes; FILE *f = Swig_open(filename); - if (!f) return -1; - while ((nbytes = Read(f,buffer,4096)) > 0) { - Write(outfile,buffer,nbytes); + if (!f) + return -1; + while ((nbytes = Read(f, buffer, 4096)) > 0) { + Write(outfile, buffer, nbytes); } return 0; } @@ -350,9 +345,9 @@ Swig_insert_file(const String_or_char *filename, File *outfile) { static Hash *named_files = 0; -void -Swig_register_filebyname(const String_or_char *filename, File *outfile) { - if (!named_files) named_files = NewHash(); +void Swig_register_filebyname(const String_or_char *filename, File *outfile) { + if (!named_files) + named_files = NewHash(); Setattr(named_files, filename, outfile); } @@ -362,10 +357,10 @@ Swig_register_filebyname(const String_or_char *filename, File *outfile) { * Get a named file * ----------------------------------------------------------------------------- */ -File * -Swig_filebyname(const String_or_char *filename) { - if (!named_files) return 0; - return Getattr(named_files,filename); +File *Swig_filebyname(const String_or_char *filename) { + if (!named_files) + return 0; + return Getattr(named_files, filename); } /* ----------------------------------------------------------------------------- @@ -374,18 +369,18 @@ Swig_filebyname(const String_or_char *filename) { * Returns the suffix of a file * ----------------------------------------------------------------------------- */ -char * -Swig_file_suffix(const String_or_char *filename) { +char *Swig_file_suffix(const String_or_char *filename) { char *d; char *c = Char(filename); int len = Len(filename); if (strlen(c)) { d = c + len - 1; while (d != c) { - if (*d == '.') return d; + if (*d == '.') + return d; d--; } - return c+len; + return c + len; } return c; } @@ -396,12 +391,10 @@ Swig_file_suffix(const String_or_char *filename) { * Returns the filename with no suffix attached. * ----------------------------------------------------------------------------- */ -char * -Swig_file_basename(const String_or_char *filename) -{ +char *Swig_file_basename(const String_or_char *filename) { static char tmp[1024]; char *c; - strcpy(tmp,Char(filename)); + strcpy(tmp, Char(filename)); c = Swig_file_suffix(tmp); *c = 0; return tmp; @@ -412,16 +405,16 @@ Swig_file_basename(const String_or_char *filename) * * Return the file with any leading path stripped off * ----------------------------------------------------------------------------- */ -char * -Swig_file_filename(const String_or_char *filename) -{ +char *Swig_file_filename(const String_or_char *filename) { static char tmp[1024]; const char *delim = SWIG_FILE_DELIMETER; char *c; - strcpy(tmp,Char(filename)); - if ((c=strrchr(tmp,*delim))) return c+1; - else return tmp; + strcpy(tmp, Char(filename)); + if ((c = strrchr(tmp, *delim))) + return c + 1; + else + return tmp; } /* ----------------------------------------------------------------------------- @@ -429,22 +422,17 @@ Swig_file_filename(const String_or_char *filename) * * Return the name of the directory associated with a file * ----------------------------------------------------------------------------- */ -char * -Swig_file_dirname(const String_or_char *filename) -{ +char *Swig_file_dirname(const String_or_char *filename) { static char tmp[1024]; const char *delim = SWIG_FILE_DELIMETER; char *c; - strcpy(tmp,Char(filename)); - if (!strstr(tmp,delim)) { + strcpy(tmp, Char(filename)); + if (!strstr(tmp, delim)) { return ""; } - c = tmp + strlen(tmp) -1; - while (*c != *delim) c--; + c = tmp + strlen(tmp) - 1; + while (*c != *delim) + c--; *(++c) = 0; return tmp; } - - - - diff --git a/SWIG/Source/Swig/misc.c b/SWIG/Source/Swig/misc.c index bd012a619..3affdbc1e 100644 --- a/SWIG/Source/Swig/misc.c +++ b/SWIG/Source/Swig/misc.c @@ -22,12 +22,11 @@ char cvsroot_misc_c[] = "$Header$"; * Duplicate a NULL-terminate string given as a char *. * ----------------------------------------------------------------------------- */ -char * -Swig_copy_string(const char *s) { +char *Swig_copy_string(const char *s) { char *c = 0; if (s) { - c = (char *) malloc(strlen(s)+1); - strcpy(c,s); + c = (char *) malloc(strlen(s) + 1); + strcpy(c, s); } return c; } @@ -38,10 +37,8 @@ Swig_copy_string(const char *s) { * Emits the SWIG identifying banner. * ----------------------------------------------------------------------------- */ -void -Swig_banner(File *f) { - Printf(f, -"/* ----------------------------------------------------------------------------\n\ +void Swig_banner(File *f) { + Printf(f, "/* ----------------------------------------------------------------------------\n\ * This file was automatically generated by SWIG (http://www.swig.org).\n\ * Version %s\n\ * \n\ @@ -50,8 +47,7 @@ Swig_banner(File *f) { * changes to this file unless you know what you are doing--modify the SWIG \n\ * interface file instead. \n", PACKAGE_VERSION); /* String too long for ISO compliance */ - Printf(f, -" * ----------------------------------------------------------------------------- */\n\n"); + Printf(f, " * ----------------------------------------------------------------------------- */\n\n"); } @@ -65,27 +61,28 @@ String *Swig_string_escape(String *s) { String *ns; int c; ns = NewStringEmpty(); - + while ((c = Getc(s)) != EOF) { if (c == '\n') { - Printf(ns,"\\n"); + Printf(ns, "\\n"); } else if (c == '\r') { - Printf(ns,"\\r"); + Printf(ns, "\\r"); } else if (c == '\t') { - Printf(ns,"\\t"); + Printf(ns, "\\t"); } else if (c == '\\') { - Printf(ns,"\\\\"); + Printf(ns, "\\\\"); } else if (c == '\'') { - Printf(ns,"\\'"); + Printf(ns, "\\'"); } else if (c == '\"') { - Printf(ns,"\\\""); + Printf(ns, "\\\""); } else if (c == ' ') { - Putc(c,ns); + Putc(c, ns); } else if (!isgraph(c)) { - if (c < 0) c += UCHAR_MAX +1; - Printf(ns,"\\%o", c); + if (c < 0) + c += UCHAR_MAX + 1; + Printf(ns, "\\%o", c); } else { - Putc(c,ns); + Putc(c, ns); } } return ns; @@ -103,9 +100,9 @@ String *Swig_string_upper(String *s) { int c; ns = NewStringEmpty(); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { - Putc(toupper(c),ns); + Putc(toupper(c), ns); } return ns; } @@ -121,9 +118,9 @@ String *Swig_string_lower(String *s) { int c; ns = NewStringEmpty(); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { - Putc(tolower(c),ns); + Putc(tolower(c), ns); } return ns; } @@ -142,9 +139,9 @@ String *Swig_string_title(String *s) { int c; ns = NewStringEmpty(); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { - Putc(first ? toupper(c) : tolower(c),ns); + Putc(first ? toupper(c) : tolower(c), ns); first = 0; } return ns; @@ -166,9 +163,9 @@ String *Swig_string_ccase(String *s) { int c; ns = NewStringEmpty(); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { - if (c == '_') { + if (c == '_') { first = 1; continue; } @@ -196,7 +193,7 @@ String *Swig_string_lccase(String *s) { int c; ns = NewStringEmpty(); - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { if (c == '_') { after_underscore = 1; @@ -212,6 +209,7 @@ String *Swig_string_lccase(String *s) { } return ns; } + /* ----------------------------------------------------------------------------- * Swig_string_ucase() * @@ -224,31 +222,31 @@ String *Swig_string_ucase(String *s) { String *ns; int c; int lastC = 0; - int underscore = 0; + int underscore = 0; ns = NewStringEmpty(); /* We insert a underscore when: - 1. Lower case char followed by upper case char - getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo - 2. Number proceded by char - get2D > get_2d; get22D > get_22d; GET2D > get_2d */ + 1. Lower case char followed by upper case char + getFoo > get_foo; getFOo > get_foo; GETFOO > getfoo + 2. Number proceded by char + get2D > get_2d; get22D > get_22d; GET2D > get_2d */ - Seek(s,0,SEEK_SET); + Seek(s, 0, SEEK_SET); while ((c = Getc(s)) != EOF) { if (isdigit(c) && isalpha(lastC)) underscore = 1; else if (isupper(c) && isalpha(lastC) && !isupper(lastC)) underscore = 1; - + lastC = c; if (underscore) { - Putc('_',ns); + Putc('_', ns); underscore = 0; - } + } - Putc(tolower(c),ns); + Putc(tolower(c), ns); } return ns; } @@ -268,7 +266,7 @@ String *Swig_string_first_upper(String *s) { String *ns = NewStringEmpty(); char *cs = Char(s); if (cs && cs[0] != 0) { - Putc(toupper(cs[0]),ns); + Putc(toupper(cs[0]), ns); Append(ns, cs + 1); } return ns; @@ -289,7 +287,7 @@ String *Swig_string_first_lower(String *s) { String *ns = NewStringEmpty(); char *cs = Char(s); if (cs && cs[0] != 0) { - Putc(tolower(cs[0]),ns); + Putc(tolower(cs[0]), ns); Append(ns, cs + 1); } return ns; @@ -327,30 +325,33 @@ String *Swig_string_typecode(String *s) { String *str = 0; tc = NewStringEmpty(); while ((c = Getc(s)) != EOF) { - if (c == '`') break; - Putc(c,tc); + if (c == '`') + break; + Putc(c, tc); } - str = SwigType_str(tc,0); - Append(ns,str); + str = SwigType_str(tc, 0); + Append(ns, str); Delete(str); } else { - Putc(c,ns); + Putc(c, ns); if (c == '\'') { while ((c = Getc(s)) != EOF) { - Putc(c,ns); - if (c == '\'') break; + Putc(c, ns); + if (c == '\'') + break; if (c == '\\') { c = Getc(s); - Putc(c,ns); + Putc(c, ns); } } } else if (c == '\"') { while ((c = Getc(s)) != EOF) { - Putc(c,ns); - if (c == '\"') break; + Putc(c, ns); + if (c == '\"') + break; if (c == '\\') { c = Getc(s); - Putc(c,ns); + Putc(c, ns); } } } @@ -358,7 +359,7 @@ String *Swig_string_typecode(String *s) { } return ns; } - + /* ----------------------------------------------------------------------------- * Swig_string_mangle() * @@ -382,12 +383,13 @@ String *Swig_string_typecode(String *s) { * ----------------------------------------------------------------------------- */ String *Swig_string_mangle(const String *s) { -#if 0 +#if 0 /* old mangling, not suitable for using in macros */ String *t = Copy(s); char *c = Char(t); while (*c) { - if (!isalnum(*c)) *c = '_'; + if (!isalnum(*c)) + *c = '_'; c++; } return t; @@ -399,26 +401,26 @@ String *Swig_string_mangle(const String *s) { String *b = Copy(s); if (SwigType_istemplate(b)) { String *st = Swig_symbol_template_deftype(b, 0); - String *sq = Swig_symbol_type_qualify(st,0); + String *sq = Swig_symbol_type_qualify(st, 0); String *t = SwigType_namestr(sq); Delete(st); Delete(sq); Delete(b); - b = t ; + b = t; } pc = cb = StringChar(b); while (*pc) { char c = *pc; - if (isalnum((int)c) || (c == '_')) { + if (isalnum((int) c) || (c == '_')) { state = 1; if (space && (space == state)) { - StringAppend(result,"_SS_"); + StringAppend(result, "_SS_"); } space = 0; - Printf(result,"%c",(int)c); - + Printf(result, "%c", (int) c); + } else { - if (isspace((int)c)) { + if (isspace((int) c)) { space = state; ++pc; continue; @@ -426,10 +428,10 @@ String *Swig_string_mangle(const String *s) { state = 3; space = 0; } - switch(c) { + switch (c) { case '.': if ((cb != pc) && (*(pc - 1) == 'p')) { - StringAppend(result,"_"); + StringAppend(result, "_"); ++pc; continue; } else { @@ -438,8 +440,9 @@ String *Swig_string_mangle(const String *s) { break; case ':': if (*(pc + 1) == ':') { - StringAppend(result,"_"); - ++pc; ++pc; + StringAppend(result, "_"); + ++pc; + ++pc; continue; } break; @@ -503,10 +506,10 @@ String *Swig_string_mangle(const String *s) { default: break; } - if (isalpha((int)c)) { - Printf(result,"_S%c_",(int)c); - } else{ - Printf(result,"_S%02X_",(int)c); + if (isalpha((int) c)) { + Printf(result, "_S%c_", (int) c); + } else { + Printf(result, "_S%02X_", (int) c); } } ++pc; @@ -528,18 +531,17 @@ String *Swig_string_emangle(String *s) { * In this case, "A::B". Returns NULL if there is no base. * ----------------------------------------------------------------------------- */ -void -Swig_scopename_split(String *s, String **rprefix, String **rlast) { +void Swig_scopename_split(String *s, String **rprefix, String **rlast) { char *tmp = Char(s); char *c = tmp; char *cc = c; char *co = 0; - if (!strstr(c,"::")) { + if (!strstr(c, "::")) { *rprefix = 0; *rlast = Copy(s); } - - if ((co = strstr(cc,"operator "))) { + + if ((co = strstr(cc, "operator "))) { if (co == cc) { *rprefix = 0; *rlast = Copy(s); @@ -551,7 +553,7 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) { } } while (*c) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { cc = c; c += 2; } else { @@ -559,8 +561,10 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -580,14 +584,14 @@ Swig_scopename_split(String *s, String **rprefix, String **rlast) { } -String * -Swig_scopename_prefix(String *s) { +String *Swig_scopename_prefix(String *s) { char *tmp = Char(s); char *c = tmp; char *cc = c; char *co = 0; - if (!strstr(c,"::")) return 0; - if ((co = strstr(cc,"operator "))) { + if (!strstr(c, "::")) + return 0; + if ((co = strstr(cc, "operator "))) { if (co == cc) { return 0; } else { @@ -596,7 +600,7 @@ Swig_scopename_prefix(String *s) { } } while (*c) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { cc = c; c += 2; } else { @@ -604,8 +608,10 @@ Swig_scopename_prefix(String *s) { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -628,21 +634,21 @@ Swig_scopename_prefix(String *s) { * case, "C". * ----------------------------------------------------------------------------- */ -String * -Swig_scopename_last(String *s) { +String *Swig_scopename_last(String *s) { char *tmp = Char(s); char *c = tmp; char *cc = c; char *co = 0; - if (!strstr(c,"::")) return NewString(s); + if (!strstr(c, "::")) + return NewString(s); - if ((co = strstr(cc,"operator "))) { + if ((co = strstr(cc, "operator "))) { return NewString(co); } while (*c) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { cc = c; c += 2; } else { @@ -650,8 +656,10 @@ Swig_scopename_last(String *s) { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -659,7 +667,7 @@ Swig_scopename_last(String *s) { } } } - return NewString(cc+2); + return NewString(cc + 2); } /* ----------------------------------------------------------------------------- @@ -669,30 +677,32 @@ Swig_scopename_last(String *s) { * In this case, "A". Returns NULL if there is no base. * ----------------------------------------------------------------------------- */ -String * -Swig_scopename_first(String *s) { +String *Swig_scopename_first(String *s) { char *tmp = Char(s); - char *c = tmp; + char *c = tmp; char *co = 0; - if (!strstr(c,"::")) return 0; - if ((co = strstr(c,"operator "))) { + if (!strstr(c, "::")) + return 0; + if ((co = strstr(c, "operator "))) { if (co == c) { return 0; } } else { co = c + Len(s); } - + while (*c && (c != co)) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { break; } else { if (*c == '<') { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -715,25 +725,28 @@ Swig_scopename_first(String *s) { * In this case, "B::C". Returns NULL if there is no suffix. * ----------------------------------------------------------------------------- */ -String * -Swig_scopename_suffix(String *s) { +String *Swig_scopename_suffix(String *s) { char *tmp = Char(s); char *c = tmp; char *co = 0; - if (!strstr(c,"::")) return 0; - if ((co = strstr(c,"operator "))) { - if (co == c) return 0; + if (!strstr(c, "::")) + return 0; + if ((co = strstr(c, "operator "))) { + if (co == c) + return 0; } while (*c) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { break; } else { if (*c == '<') { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -742,11 +755,12 @@ Swig_scopename_suffix(String *s) { } } if (*c && (c != tmp)) { - return NewString(c+2); + return NewString(c + 2); } else { return 0; } } + /* ----------------------------------------------------------------------------- * Swig_scopename_check() * @@ -756,20 +770,24 @@ Swig_scopename_suffix(String *s) { int Swig_scopename_check(String *s) { char *c = Char(s); char *co = 0; - if ((co = strstr(c,"operator "))) { - if (co == c) return 0; + if ((co = strstr(c, "operator "))) { + if (co == c) + return 0; } - if (!strstr(c,"::")) return 0; + if (!strstr(c, "::")) + return 0; while (*c) { - if ((*c == ':') && (*(c+1) == ':')) { + if ((*c == ':') && (*(c + 1) == ':')) { return 1; } else { if (*c == '<') { int level = 1; c++; while (*c && level) { - if (*c == '<') level++; - if (*c == '>') level--; + if (*c == '<') + level++; + if (*c == '>') + level--; c++; } } else { @@ -809,15 +827,15 @@ String *Swig_string_command(String *s) { #if defined(HAVE_POPEN) if (Len(s)) { char *command = Char(s); - FILE *fp = popen(command,"r"); + FILE *fp = popen(command, "r"); if (fp) { char buffer[1025]; - while(fscanf(fp,"%1024s",buffer) != EOF) { - Append(res,buffer); + while (fscanf(fp, "%1024s", buffer) != EOF) { + Append(res, buffer); } pclose(fp); } else { - Swig_error("SWIG",Getline(s), "Command encoder fails attempting '%s'.\n", s); + Swig_error("SWIG", Getline(s), "Command encoder fails attempting '%s'.\n", s); exit(1); } } @@ -839,8 +857,7 @@ String *Swig_string_command(String *s) { #define USE_RXSPENCER #endif -const char *skip_delim(char pb, char pe, const char *ce) -{ +const char *skip_delim(char pb, char pe, const char *ce) { int end = 0; int lb = 0; while (!end && *ce != '\0') { @@ -872,45 +889,45 @@ String *Swig_string_rxspencer(String *s) { int retval; regex_t compiled; cb = ++cs; - ce = skip_delim('[',']', cb); + 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) { + if (retval == 0) { cs = ce; if (*cs == '[') { cb = ++cs; - ce = skip_delim('[',']', cb) ; + 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); + 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,'@'); + 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); + 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); + strncpy(value, cvalue + pmatch[i].rm_so, len); value[len] = 0; - Replaceall(res,arg,value); + Replaceall(res, arg, value); } else { - Replaceall(res,arg,""); + Replaceall(res, arg, ""); } - spos = Strchr(res,'@'); + spos = Strchr(res, '@'); } else if (cd == '@') { - spos = strchr(spos + 1,'@'); + spos = strchr(spos + 1, '@'); } } } @@ -922,12 +939,13 @@ String *Swig_string_rxspencer(String *s) { } } } - if (!res) res = NewStringEmpty(); + if (!res) + res = NewStringEmpty(); return res; } #else String *Swig_string_rxspencer(String *s) { - (void)s; + (void) s; return NewStringEmpty(); } #endif @@ -939,8 +957,7 @@ String *Swig_string_rxspencer(String *s) { * Initialize the SWIG core * ----------------------------------------------------------------------------- */ -void -Swig_init() { +void Swig_init() { /* Set some useful string encoding methods */ DohEncoding("escape", Swig_string_escape); DohEncoding("upper", Swig_string_upper); @@ -949,7 +966,7 @@ Swig_init() { DohEncoding("ctitle", Swig_string_ccase); DohEncoding("lctitle", Swig_string_lccase); DohEncoding("utitle", Swig_string_ucase); - DohEncoding("typecode",Swig_string_typecode); + DohEncoding("typecode", Swig_string_typecode); DohEncoding("mangle", Swig_string_emangle); DohEncoding("command", Swig_string_command); DohEncoding("rxspencer", Swig_string_rxspencer); diff --git a/SWIG/Source/Swig/naming.c b/SWIG/Source/Swig/naming.c index 26e7474ba..ece2963dd 100644 --- a/SWIG/Source/Swig/naming.c +++ b/SWIG/Source/Swig/naming.c @@ -19,7 +19,7 @@ char cvsroot_naming_c[] = "$Header$"; static Hash *naming_hash = 0; #if 0 -#define SWIG_DEBUG +#define SWIG_DEBUG #endif /* ----------------------------------------------------------------------------- @@ -28,29 +28,28 @@ static Hash *naming_hash = 0; * Register a new naming format. * ----------------------------------------------------------------------------- */ -void -Swig_name_register(const String_or_char *method, const String_or_char *format) { - if (!naming_hash) naming_hash = NewHash(); - Setattr(naming_hash,method,format); +void Swig_name_register(const String_or_char *method, const String_or_char *format) { + if (!naming_hash) + naming_hash = NewHash(); + Setattr(naming_hash, method, format); } -void -Swig_name_unregister(const String_or_char *method) { +void Swig_name_unregister(const String_or_char *method) { if (naming_hash) { - Delattr(naming_hash,method); + Delattr(naming_hash, method); } } static int name_mangle(String *r) { - char *c; - int special; + char *c; + int special; special = 0; - Replaceall(r,"::","_"); + Replaceall(r, "::", "_"); c = Char(r); while (*c) { if (!isalnum((int) *c) && (*c != '_')) { special = 1; - switch(*c) { + switch (*c) { case '+': *c = 'a'; break; @@ -118,7 +117,8 @@ static int name_mangle(String *r) { } c++; } - if (special) Append(r,"___"); + if (special) + Append(r, "___"); return special; } @@ -128,8 +128,7 @@ static int name_mangle(String *r) { * Converts all of the non-identifier characters of a string to underscores. * ----------------------------------------------------------------------------- */ -String * -Swig_name_mangle(const String_or_char *s) { +String *Swig_name_mangle(const String_or_char *s) { #if 0 String *r = NewString(s); name_mangle(r); @@ -145,20 +144,20 @@ Swig_name_mangle(const String_or_char *s) { * Returns the name of a wrapper function. * ----------------------------------------------------------------------------- */ -String * -Swig_name_wrapper(const String_or_char *fname) { +String *Swig_name_wrapper(const String_or_char *fname) { String *r; String *f; r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_wrapper); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_wrapper); if (!f) { - Append(r,"_wrap_%f"); + Append(r, "_wrap_%f"); } else { - Append(r,f); + Append(r, f); } - Replace(r,"%f",fname, DOH_REPLACE_ANY); + Replace(r, "%f", fname, DOH_REPLACE_ANY); name_mangle(r); return r; } @@ -170,31 +169,29 @@ Swig_name_wrapper(const String_or_char *fname) { * Returns the name of a class method. * ----------------------------------------------------------------------------- */ -String * -Swig_name_member(const String_or_char *classname, const String_or_char *mname) { +String *Swig_name_member(const String_or_char *classname, const String_or_char *mname) { String *r; String *f; String *rclassname; - char *cname; + char *cname; rclassname = SwigType_namestr(classname); r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_member); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_member); if (!f) { - Append(r,"%c_%m"); + Append(r, "%c_%m"); } else { - Append(r,f); + Append(r, f); } cname = Char(rclassname); - if ((strncmp(cname,"struct ", 7) == 0) || - ((strncmp(cname,"class ", 6) == 0)) || - ((strncmp(cname,"union ", 6) == 0))) { - cname = strchr(cname, ' ')+1; + if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { + cname = strchr(cname, ' ') + 1; } - Replace(r,"%c",cname, DOH_REPLACE_ANY); - Replace(r,"%m",mname, DOH_REPLACE_ANY); - /* name_mangle(r);*/ + Replace(r, "%c", cname, DOH_REPLACE_ANY); + Replace(r, "%m", mname, DOH_REPLACE_ANY); + /* name_mangle(r); */ Delete(rclassname); return r; } @@ -205,24 +202,24 @@ Swig_name_member(const String_or_char *classname, const String_or_char *mname) { * Returns the name of the accessor function used to get a variable. * ----------------------------------------------------------------------------- */ -String * -Swig_name_get(const String_or_char *vname) { +String *Swig_name_get(const String_or_char *vname) { String *r; String *f; #ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_get: '%s'\n", vname); + Printf(stderr, "Swig_name_get: '%s'\n", vname); #endif r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = Getattr(naming_hash,k_get); + if (!naming_hash) + naming_hash = NewHash(); + f = Getattr(naming_hash, k_get); if (!f) { - Append(r,"%v_get"); + Append(r, "%v_get"); } else { - Append(r,f); + Append(r, f); } - Replace(r,"%v",vname, DOH_REPLACE_ANY); + Replace(r, "%v", vname, DOH_REPLACE_ANY); /* name_mangle(r); */ return r; } @@ -233,20 +230,20 @@ Swig_name_get(const String_or_char *vname) { * Returns the name of the accessor function used to set a variable. * ----------------------------------------------------------------------------- */ -String * -Swig_name_set(const String_or_char *vname) { +String *Swig_name_set(const String_or_char *vname) { String *r; String *f; r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_set); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_set); if (!f) { - Append(r,"%v_set"); + Append(r, "%v_set"); } else { - Append(r,f); + Append(r, f); } - Replace(r,"%v",vname, DOH_REPLACE_ANY); + Replace(r, "%v", vname, DOH_REPLACE_ANY); /* name_mangle(r); */ return r; } @@ -257,8 +254,7 @@ Swig_name_set(const String_or_char *vname) { * Returns the name of the accessor function used to create an object. * ----------------------------------------------------------------------------- */ -String * -Swig_name_construct(const String_or_char *classname) { +String *Swig_name_construct(const String_or_char *classname) { String *r; String *f; String *rclassname; @@ -266,21 +262,20 @@ Swig_name_construct(const String_or_char *classname) { rclassname = SwigType_namestr(classname); r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_construct); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_construct); if (!f) { - Append(r,"new_%c"); + Append(r, "new_%c"); } else { - Append(r,f); + Append(r, f); } cname = Char(rclassname); - if ((strncmp(cname,"struct ", 7) == 0) || - ((strncmp(cname,"class ", 6) == 0)) || - ((strncmp(cname,"union ", 6) == 0))) { - cname = strchr(cname, ' ')+1; + if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { + cname = strchr(cname, ' ') + 1; } - Replace(r,"%c",cname, DOH_REPLACE_ANY); + Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; } @@ -292,8 +287,7 @@ Swig_name_construct(const String_or_char *classname) { * Returns the name of the accessor function used to copy an object. * ----------------------------------------------------------------------------- */ -String * -Swig_name_copyconstructor(const String_or_char *classname) { +String *Swig_name_copyconstructor(const String_or_char *classname) { String *r; String *f; String *rclassname; @@ -301,22 +295,21 @@ Swig_name_copyconstructor(const String_or_char *classname) { rclassname = SwigType_namestr(classname); r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_copy); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_copy); if (!f) { - Append(r,"copy_%c"); + Append(r, "copy_%c"); } else { - Append(r,f); + Append(r, f); } cname = Char(rclassname); - if ((strncmp(cname,"struct ", 7) == 0) || - ((strncmp(cname,"class ", 6) == 0)) || - ((strncmp(cname,"union ", 6) == 0))) { - cname = strchr(cname, ' ')+1; + if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { + cname = strchr(cname, ' ') + 1; } - Replace(r,"%c",cname, DOH_REPLACE_ANY); + Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; } @@ -334,21 +327,20 @@ String *Swig_name_destroy(const String_or_char *classname) { char *cname; rclassname = SwigType_namestr(classname); r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_destroy); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_destroy); if (!f) { - Append(r,"delete_%c"); + Append(r, "delete_%c"); } else { - Append(r,f); + Append(r, f); } cname = Char(rclassname); - if ((strncmp(cname,"struct ", 7) == 0) || - ((strncmp(cname,"class ", 6) == 0)) || - ((strncmp(cname,"union ", 6) == 0))) { - cname = strchr(cname, ' ')+1; + if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { + cname = strchr(cname, ' ') + 1; } - Replace(r,"%c",cname, DOH_REPLACE_ANY); + Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; } @@ -367,21 +359,20 @@ String *Swig_name_disown(const String_or_char *classname) { char *cname; rclassname = SwigType_namestr(classname); r = NewStringEmpty(); - if (!naming_hash) naming_hash = NewHash(); - f = HashGetAttr(naming_hash,k_disown); + if (!naming_hash) + naming_hash = NewHash(); + f = HashGetAttr(naming_hash, k_disown); if (!f) { - Append(r,"disown_%c"); + Append(r, "disown_%c"); } else { - Append(r,f); + Append(r, f); } cname = Char(rclassname); - if ((strncmp(cname,"struct ", 7) == 0) || - ((strncmp(cname,"class ", 6) == 0)) || - ((strncmp(cname,"union ", 6) == 0))) { - cname = strchr(cname, ' ')+1; + if ((strncmp(cname, "struct ", 7) == 0) || ((strncmp(cname, "class ", 6) == 0)) || ((strncmp(cname, "union ", 6) == 0))) { + cname = strchr(cname, ' ') + 1; } - Replace(r,"%c",cname, DOH_REPLACE_ANY); + Replace(r, "%c", cname, DOH_REPLACE_ANY); Delete(rclassname); return r; } @@ -393,25 +384,24 @@ String *Swig_name_disown(const String_or_char *classname) { * Sets an object associated with a name and optional declarators. * ----------------------------------------------------------------------------- */ -void -Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) { +void Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) { DOH *n; #ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_object_set: '%s', '%s'\n", name, decl); + Printf(stderr, "Swig_name_object_set: '%s', '%s'\n", name, decl); #endif - n = HashGetAttr(namehash,name); + n = HashGetAttr(namehash, name); if (!n) { n = NewHash(); - Setattr(namehash,name,n); + Setattr(namehash, name, n); Delete(n); } /* Add an object based on the declarator value */ if (!decl) { - Setattr(n,k_start,object); + Setattr(n, k_start, object); } else { SwigType *cd = Copy(decl); - Setattr(n,cd,object); + Setattr(n, cd, object); Delete(cd); } } @@ -427,57 +417,59 @@ Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) static DOH *get_object(Hash *n, String *decl) { DOH *rn = 0; - if (!n) return 0; + if (!n) + return 0; if (decl) { - rn = Getattr(n,decl); + rn = Getattr(n, decl); } else { - rn = Getattr(n,k_start); + rn = Getattr(n, k_start); } return rn; } static -DOH * -name_object_get(Hash *namehash, String *tname, SwigType *decl, SwigType *ncdecl) { - DOH* rn = 0; - Hash *n = Getattr(namehash,tname); +DOH *name_object_get(Hash *namehash, String *tname, SwigType *decl, SwigType *ncdecl) { + DOH *rn = 0; + Hash *n = Getattr(namehash, tname); if (n) { - rn = get_object(n,decl); - if ((!rn) && ncdecl) rn = get_object(n,ncdecl); - if (!rn) rn = get_object(n,0); + rn = get_object(n, decl); + if ((!rn) && ncdecl) + rn = get_object(n, ncdecl); + if (!rn) + rn = get_object(n, 0); } return rn; } -DOH * -Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl) { +DOH *Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl) { String *tname = NewStringEmpty(); - DOH *rn = 0; - char *ncdecl = 0; + DOH *rn = 0; + char *ncdecl = 0; - if (!namehash) return 0; + if (!namehash) + return 0; /* DB: This removed to more tightly control feature/name matching */ /* if ((decl) && (SwigType_isqualifier(decl))) { - ncdecl = strchr(Char(decl),'.'); - ncdecl++; - } - */ + ncdecl = strchr(Char(decl),'.'); + ncdecl++; + } + */ #ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_object_get: '%s', '%s'\n", name, decl); + Printf(stderr, "Swig_name_object_get: '%s', '%s'\n", name, decl); #endif /* Perform a class-based lookup (if class prefix supplied) */ if (prefix) { if (Len(prefix)) { - Printf(tname,"%s::%s", prefix, name); + Printf(tname, "%s::%s", prefix, name); rn = name_object_get(namehash, tname, decl, ncdecl); if (!rn) { String *cls = Swig_scopename_last(prefix); - if (!Equal(cls,prefix)) { + if (!Equal(cls, prefix)) { Clear(tname); - Printf(tname,"*::%s::%s",cls,name); + Printf(tname, "*::%s::%s", cls, name); rn = name_object_get(namehash, tname, decl, ncdecl); } Delete(cls); @@ -485,7 +477,7 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec /* A template-based class lookup, check name first */ if (!rn && SwigType_istemplate(name)) { String *t_name = SwigType_templateprefix(name); - if (!Equal(t_name,name)) { + if (!Equal(t_name, name)) { rn = Swig_name_object_get(namehash, prefix, t_name, decl); } Delete(t_name); @@ -493,24 +485,24 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec /* A template-based class lookup */ if (0 && !rn && SwigType_istemplate(prefix)) { String *t_prefix = SwigType_templateprefix(prefix); - if (Strcmp(t_prefix,prefix) != 0) { + if (Strcmp(t_prefix, prefix) != 0) { String *t_name = SwigType_templateprefix(name); rn = Swig_name_object_get(namehash, t_prefix, t_name, decl); Delete(t_name); } Delete(t_prefix); } - } + } /* A wildcard-based class lookup */ if (!rn) { Clear(tname); - Printf(tname,"*::%s",name); + Printf(tname, "*::%s", name); rn = name_object_get(namehash, tname, decl, ncdecl); } } else { /* Lookup in the global namespace only */ Clear(tname); - Printf(tname,"::%s",name); + Printf(tname, "::%s", name); rn = name_object_get(namehash, tname, decl, ncdecl); } /* Catch-all */ @@ -525,11 +517,11 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec Delete(nlast); Delete(nprefix); } - + Delete(tname); #ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_object_get: found %d\n", rn ? 1 : 0); + Printf(stderr, "Swig_name_object_get: found %d\n", rn ? 1 : 0); #endif return rn; @@ -541,36 +533,36 @@ Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *dec * Implements name-based inheritance scheme. * ----------------------------------------------------------------------------- */ -void -Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { +void Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { Iterator ki; String *bprefix; String *dprefix; char *cbprefix; - int plen; + int plen; - if (!namehash) return; - - bprefix = NewStringf("%s::",base); - dprefix = NewStringf("%s::",derived); + if (!namehash) + return; + + bprefix = NewStringf("%s::", base); + dprefix = NewStringf("%s::", derived); cbprefix = Char(bprefix); plen = strlen(cbprefix); for (ki = First(namehash); ki.key; ki = Next(ki)) { char *k = Char(ki.key); - if (strncmp(k,cbprefix,plen) == 0) { + if (strncmp(k, cbprefix, plen) == 0) { Iterator oi; - String *nkey = NewStringf("%s%s",dprefix,k+plen); + String *nkey = NewStringf("%s%s", dprefix, k + plen); Hash *n = ki.item; - Hash *newh = HashGetAttr(namehash,nkey); + Hash *newh = HashGetAttr(namehash, nkey); if (!newh) { newh = NewHash(); - Setattr(namehash,nkey,newh); + Setattr(namehash, nkey, newh); Delete(newh); } for (oi = First(n); oi.key; oi = Next(oi)) { - if (!Getattr(newh,oi.key)) { + if (!Getattr(newh, oi.key)) { String *ci = Copy(oi.item); - Setattr(newh,oi.key,ci); + Setattr(newh, oi.key, ci); Delete(ci); } } @@ -590,10 +582,11 @@ Swig_name_object_inherit(Hash *namehash, String *base, String *derived) { static void merge_features(Hash *features, Node *n) { Iterator ki; - if (!features) return; + if (!features) + return; for (ki = First(features); ki.key; ki = Next(ki)) { - String *ci = Copy(ki.item); - Setattr(n,ki.key,ci); + String *ci = Copy(ki.item); + Setattr(n, ki.key, ci); Delete(ci); } } @@ -605,64 +598,63 @@ static void merge_features(Hash *features, Node *n) { * the declaration, decl. * ----------------------------------------------------------------------------- */ -static -void features_get(Hash *features, String *tname, SwigType *decl, SwigType *ncdecl, Node *node) -{ - Node *n = Getattr(features,tname); +static +void features_get(Hash *features, String *tname, SwigType *decl, SwigType *ncdecl, Node *node) { + Node *n = Getattr(features, tname); #ifdef SWIG_DEBUG - Printf(stderr," features_get: %s\n", tname); + Printf(stderr, " features_get: %s\n", tname); #endif if (n) { - merge_features(get_object(n,0),node); - if (ncdecl) merge_features(get_object(n,ncdecl),node); - merge_features(get_object(n,decl),node); + merge_features(get_object(n, 0), node); + if (ncdecl) + merge_features(get_object(n, ncdecl), node); + merge_features(get_object(n, decl), node); } } -void -Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *node) { - char *ncdecl = 0; +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; + if (!features) + return; /* MM: This removed to more tightly control feature/name matching */ /* - if ((decl) && (SwigType_isqualifier(decl))) { - ncdecl = strchr(Char(decl),'.'); - ncdecl++; - } - */ + if ((decl) && (SwigType_isqualifier(decl))) { + ncdecl = strchr(Char(decl),'.'); + ncdecl++; + } + */ /* very specific hack for template constructors/destructors */ if (name && SwigType_istemplate(name)) { String *nodetype = Getattr(node, k_nodetype); - if (nodetype && (Equal(nodetype,k_constructor) || Equal(nodetype,k_destructor))) { + if (nodetype && (Equal(nodetype, k_constructor) || Equal(nodetype, k_destructor))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; - Swig_scopename_split(name, &nprefix, &nlast); + Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { - Append(nprefix,"::"); - Append(nprefix,tprefix); + Append(nprefix, "::"); + Append(nprefix, tprefix); Delete(tprefix); - rname = nprefix; + rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); - Replaceall(rdecl,name,rname); + Replaceall(rdecl, name, rname); decl = rdecl; name = rname; } } - #ifdef SWIG_DEBUG - Printf(stderr,"Swig_features_get: %s %s %s\n", prefix, name, decl); + Printf(stderr, "Swig_features_get: %s %s %s\n", prefix, name, decl); #endif /* Global features */ @@ -681,12 +673,12 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, if (prefix) { /* A class-generic feature */ if (Len(prefix)) { - Printf(tname,"%s::",prefix); + Printf(tname, "%s::", prefix); features_get(features, tname, decl, ncdecl, node); } /* A wildcard-based class lookup */ Clear(tname); - Printf(tname,"*::%s",name); + Printf(tname, "*::%s", name); features_get(features, tname, decl, ncdecl, node); /* A specific class lookup */ if (Len(prefix)) { @@ -694,33 +686,35 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, if (SwigType_istemplate(prefix)) { String *tprefix = SwigType_templateprefix(prefix); Clear(tname); - Printf(tname,"%s::%s",tprefix,name); + Printf(tname, "%s::%s", tprefix, name); features_get(features, tname, decl, ncdecl, node); Delete(tprefix); } Clear(tname); - Printf(tname,"%s::%s",prefix,name); + Printf(tname, "%s::%s", prefix, name); features_get(features, tname, decl, ncdecl, node); } } else { /* Lookup in the global namespace only */ Clear(tname); - Printf(tname,"::%s",name); + Printf(tname, "::%s", name); features_get(features, tname, decl, ncdecl, node); } Delete(tname); } if (name && SwigType_istemplate(name)) { /* add features for complete template type */ - String *dname = Swig_symbol_template_deftype(name,0); - if (!Equal(dname,name)) { + 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); + if (rname) + Delete(rname); + if (rdecl) + Delete(rdecl); } @@ -732,55 +726,54 @@ Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, * concatenating the feature name plus ':' plus the attribute name. * ----------------------------------------------------------------------------- */ -void -Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs) { +void Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs) { Hash *n; Hash *fhash; #ifdef SWIG_DEBUG - Printf(stderr,"Swig_feature_set: %s %s %s %s\n", name, decl, featurename,value); + Printf(stderr, "Swig_feature_set: %s %s %s %s\n", name, decl, featurename, value); #endif - n = Getattr(features,name); + n = Getattr(features, name); if (!n) { n = NewHash(); - Setattr(features,name,n); + Setattr(features, name, n); Delete(n); } if (!decl) { - fhash = Getattr(n,k_start); + fhash = Getattr(n, k_start); if (!fhash) { fhash = NewHash(); - Setattr(n,k_start,fhash); + Setattr(n, k_start, fhash); Delete(fhash); } } else { - fhash = Getattr(n,decl); + fhash = Getattr(n, decl); if (!fhash) { String *cdecl_ = Copy(decl); fhash = NewHash(); - Setattr(n,cdecl_,fhash); + Setattr(n, cdecl_, fhash); Delete(cdecl_); Delete(fhash); } } if (value) { - Setattr(fhash,featurename,value); + Setattr(fhash, featurename, value); } else { - Delattr(fhash,featurename); + Delattr(fhash, featurename); } { /* Add in the optional feature attributes */ Hash *attribs = featureattribs; - while(attribs) { - String *attribname = Getattr(attribs,k_name); + while (attribs) { + String *attribname = Getattr(attribs, k_name); String *featureattribname = NewStringf("%s:%s", featurename, attribname); if (value) { - String *attribvalue = Getattr(attribs,k_value); - Setattr(fhash,featureattribname,attribvalue); + String *attribvalue = Getattr(attribs, k_value); + Setattr(fhash, featureattribname, attribvalue); } else { - Delattr(fhash,featureattribname); + Delattr(fhash, featureattribname); } attribs = nextSibling(attribs); Delete(featureattribname); @@ -788,8 +781,8 @@ Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, con } if (name && SwigType_istemplate(name)) { - String *dname = Swig_symbol_template_deftype(name,0); - if (Strcmp(dname,name)) { + String *dname = Swig_symbol_template_deftype(name, 0); + if (Strcmp(dname, name)) { Swig_feature_set(features, dname, decl, featurename, value, featureattribs); } Delete(dname); @@ -802,27 +795,31 @@ Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, con * Code below was in parser.y for a while * ----------------------------------------------------------------------------- */ -static Hash *namewarn_hash = 0; +static Hash *namewarn_hash = 0; Hash *Swig_name_namewarn_hash() { - if (!namewarn_hash) namewarn_hash = NewHash(); + if (!namewarn_hash) + namewarn_hash = NewHash(); return namewarn_hash; } -static Hash *rename_hash = 0; +static Hash *rename_hash = 0; Hash *Swig_name_rename_hash() { - if (!rename_hash) rename_hash = NewHash(); + if (!rename_hash) + rename_hash = NewHash(); return rename_hash; } -static List *namewarn_list = 0; +static List *namewarn_list = 0; List *Swig_name_namewarn_list() { - if (!namewarn_list) namewarn_list = NewList(); + if (!namewarn_list) + namewarn_list = NewList(); return namewarn_list; } -static List *rename_list = 0; +static List *rename_list = 0; List *Swig_name_rename_list() { - if (!rename_list) rename_list = NewList(); + if (!rename_list) + rename_list = NewList(); return rename_list; } @@ -833,24 +830,23 @@ List *Swig_name_rename_list() { * * ----------------------------------------------------------------------------- */ -int Swig_need_name_warning(Node *n) -{ +int Swig_need_name_warning(Node *n) { int need = 1; /* we don't use name warnings for: - class forwards, no symbol is generated at the target language. - template declarations, only for real instances using %template(name). - typedefs, they have no effect at the target language. - */ - if (checkAttribute(n,k_nodetype,k_classforward)) { + */ + if (checkAttribute(n, k_nodetype, k_classforward)) { need = 0; - } else if (checkAttribute(n,k_storage,k_typedef)) { + } else if (checkAttribute(n, k_storage, k_typedef)) { need = 0; - } else if (Getattr(n,k_hidden)) { + } else if (Getattr(n, k_hidden)) { need = 0; - } else if (Getattr(n,k_ignore)) { + } else if (Getattr(n, k_ignore)) { need = 0; - } else if (Getattr(n,k_templatetype)) { + } else if (Getattr(n, k_templatetype)) { need = 0; } return need; @@ -863,80 +859,84 @@ int Swig_need_name_warning(Node *n) * * ----------------------------------------------------------------------------- */ -static int nodes_are_equivalent(Node* a, Node* b, int a_inclass) -{ +static int nodes_are_equivalent(Node *a, Node *b, int a_inclass) { /* they must have the same type */ - String *ta = Getattr(a,k_nodetype); - String *tb = Getattr(b,k_nodetype); - if (Cmp(ta, tb) != 0) return 0; - + String *ta = Getattr(a, k_nodetype); + String *tb = Getattr(b, k_nodetype); + if (Cmp(ta, tb) != 0) + return 0; + /* cdecl case */ if (Cmp(ta, k_cdecl) == 0) { /* typedef */ - String *a_storage = Getattr(a,k_storage); - String *b_storage = Getattr(b,k_storage); + String *a_storage = Getattr(a, k_storage); + String *b_storage = Getattr(b, k_storage); - if ((Cmp(a_storage,k_typedef) == 0) - || (Cmp(b_storage,k_typedef) == 0)) { + if ((Cmp(a_storage, k_typedef) == 0) + || (Cmp(b_storage, k_typedef) == 0)) { if (Cmp(a_storage, b_storage) == 0) { - String *a_type = (Getattr(a,k_type)); - String *b_type = (Getattr(b,k_type)); - if (Cmp(a_type, b_type) == 0) return 1; + String *a_type = (Getattr(a, k_type)); + String *b_type = (Getattr(b, k_type)); + if (Cmp(a_type, b_type) == 0) + return 1; } return 0; } /* static functions */ - if ((Cmp(a_storage, k_static) == 0) + if ((Cmp(a_storage, k_static) == 0) || (Cmp(b_storage, k_static) == 0)) { - if (Cmp(a_storage, b_storage) != 0) return 0; + if (Cmp(a_storage, b_storage) != 0) + return 0; } /* friend methods */ - - if (!a_inclass || (Cmp(a_storage,k_friend) == 0)) { + + if (!a_inclass || (Cmp(a_storage, k_friend) == 0)) { /* check declaration */ - String *a_decl = (Getattr(a,k_decl)); - String *b_decl = (Getattr(b,k_decl)); + String *a_decl = (Getattr(a, k_decl)); + String *b_decl = (Getattr(b, k_decl)); if (Cmp(a_decl, b_decl) == 0) { /* check return type */ - String *a_type = (Getattr(a,k_type)); - String *b_type = (Getattr(b,k_type)); + String *a_type = (Getattr(a, k_type)); + String *b_type = (Getattr(b, k_type)); if (Cmp(a_type, b_type) == 0) { /* check parameters */ - Parm *ap = (Getattr(a,k_parms)); - Parm *bp = (Getattr(b,k_parms)); + Parm *ap = (Getattr(a, k_parms)); + Parm *bp = (Getattr(b, k_parms)); while (ap && bp) { - SwigType *at = Getattr(ap,k_type); - SwigType *bt = Getattr(bp,k_type); - if (Cmp(at, bt) != 0) return 0; + SwigType *at = Getattr(ap, k_type); + SwigType *bt = Getattr(bp, k_type); + if (Cmp(at, bt) != 0) + return 0; ap = nextSibling(ap); bp = nextSibling(bp); } if (ap || bp) { return 0; } else { - Node *a_template = Getattr(a,k_template); - Node *b_template = Getattr(b,k_template); - /* Not equivalent if one is a template instantiation (via %template) and the other is a non-templated function */ - if ((a_template && !b_template) || (!a_template && b_template)) return 0; - } + Node *a_template = Getattr(a, k_template); + Node *b_template = Getattr(b, k_template); + /* Not equivalent if one is a template instantiation (via %template) and the other is a non-templated function */ + if ((a_template && !b_template) || (!a_template && b_template)) + return 0; + } return 1; } } } } else { - /* %constant case */ - String *a_storage = Getattr(a,k_storage); - String *b_storage = Getattr(b,k_storage); - if ((Cmp(a_storage, "%constant") == 0) + /* %constant case */ + String *a_storage = Getattr(a, k_storage); + String *b_storage = Getattr(b, k_storage); + if ((Cmp(a_storage, "%constant") == 0) || (Cmp(b_storage, "%constant") == 0)) { if (Cmp(a_storage, b_storage) == 0) { - String *a_type = (Getattr(a,k_type)); - String *b_type = (Getattr(b,k_type)); + String *a_type = (Getattr(a, k_type)); + String *b_type = (Getattr(b, k_type)); if ((Cmp(a_type, b_type) == 0) - && (Cmp(Getattr(a,k_value), Getattr(b,k_value)) == 0)) + && (Cmp(Getattr(a, k_value), Getattr(b, k_value)) == 0)) return 1; } return 0; @@ -945,20 +945,19 @@ static int nodes_are_equivalent(Node* a, Node* b, int a_inclass) return 0; } -int Swig_need_redefined_warn(Node* a, Node* b, int InClass) -{ - String *a_name = Getattr(a,k_name); - String *b_name = Getattr(b,k_name); - String *a_symname = Getattr(a,k_symname); - String *b_symname = Getattr(b,k_symname); +int Swig_need_redefined_warn(Node *a, Node *b, int InClass) { + String *a_name = Getattr(a, k_name); + String *b_name = Getattr(b, k_name); + String *a_symname = Getattr(a, k_symname); + String *b_symname = Getattr(b, k_symname); /* always send a warning if a 'rename' is involved */ - if ((a_symname && !Equal(a_symname,a_name)) - || (b_symname && !Equal(b_symname,b_name))) { - if (!Equal(a_name,b_name)) { + if ((a_symname && !Equal(a_symname, a_name)) + || (b_symname && !Equal(b_symname, b_name))) { + if (!Equal(a_name, b_name)) { return 1; } } - + return !nodes_are_equivalent(a, b, InClass); } @@ -971,17 +970,16 @@ int Swig_need_redefined_warn(Node* a, Node* b, int InClass) * * ----------------------------------------------------------------------------- */ -int Swig_need_protected(Node* n) -{ +int Swig_need_protected(Node *n) { /* First, 'n' looks like a function */ /* if (!Swig_director_mode()) return 0; */ - String *nodetype = Getattr(n,k_nodetype); - if ((Equal(nodetype,k_cdecl)) && SwigType_isfunction(Getattr(n,k_decl))) { - String *storage = Getattr(n,k_storage); + String *nodetype = Getattr(n, k_nodetype); + if ((Equal(nodetype, k_cdecl)) && SwigType_isfunction(Getattr(n, k_decl))) { + String *storage = Getattr(n, k_storage); /* and the function is declared like virtual, or it has no - storage. This eliminates typedef, static and so on. */ - return !storage || Equal(storage,k_virtual); - } else if (Equal(nodetype,k_constructor) || Equal(nodetype,k_destructor)) { + storage. This eliminates typedef, static and so on. */ + return !storage || Equal(storage, k_virtual); + } else if (Equal(nodetype, k_constructor) || Equal(nodetype, k_destructor)) { return 1; } @@ -997,60 +995,63 @@ int Swig_need_protected(Node* n) static List *Swig_make_attrlist(const char *ckey) { List *list = NewList(); - const char *cattr = strchr(ckey,'$'); + const char *cattr = strchr(ckey, '$'); if (cattr) { String *nattr; - const char *rattr = strchr(++cattr,'$'); + const char *rattr = strchr(++cattr, '$'); while (rattr) { - nattr = NewStringWithSize(cattr, rattr-cattr); - Append(list,nattr); + nattr = NewStringWithSize(cattr, rattr - cattr); + Append(list, nattr); Delete(nattr); cattr = rattr + 1; - rattr = strchr(cattr,'$'); + rattr = strchr(cattr, '$'); } nattr = NewString(cattr); - Append(list,nattr); + Append(list, nattr); Delete(nattr); } else { - Append(list,k_nodetype); + Append(list, k_nodetype); } return list; } -static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) -{ +static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) { Node *kw = nextSibling(nameobj); List *matchlist = 0; while (kw) { Node *next = nextSibling(kw); - String *kname = Getattr(kw,k_name); - char *ckey = kname ? Char(kname) : 0; + String *kname = Getattr(kw, k_name); + char *ckey = kname ? Char(kname) : 0; if (ckey) { const char **rkey; int isnotmatch = 0; - int isrxsmatch = 0; - if ((strncmp(ckey,"match",5) == 0) - || (isnotmatch = (strncmp(ckey,"notmatch",8) == 0)) - || (isrxsmatch = (strncmp(ckey,"rxsmatch",8) == 0)) - || (isnotmatch = isrxsmatch = (strncmp(ckey,"notrxsmatch",11) == 0))) { + int isrxsmatch = 0; + if ((strncmp(ckey, "match", 5) == 0) + || (isnotmatch = (strncmp(ckey, "notmatch", 8) == 0)) + || (isrxsmatch = (strncmp(ckey, "rxsmatch", 8) == 0)) + || (isnotmatch = isrxsmatch = (strncmp(ckey, "notrxsmatch", 11) == 0))) { Hash *mi = NewHash(); List *attrlist = Swig_make_attrlist(ckey); - if (!matchlist) matchlist = NewList(); - Setattr(mi,k_value,Getattr(kw,k_value)); - Setattr(mi,k_attrlist,attrlist); -#ifdef SWIG_DEBUG - if (isrxsmatch) Printf(stderr,"rxsmatch to use: %s %s %s\n", ckey, Getattr(kw,k_value), attrlist); + if (!matchlist) + matchlist = NewList(); + Setattr(mi, k_value, Getattr(kw, k_value)); + Setattr(mi, k_attrlist, attrlist); +#ifdef SWIG_DEBUG + if (isrxsmatch) + Printf(stderr, "rxsmatch to use: %s %s %s\n", ckey, Getattr(kw, k_value), attrlist); #endif - if (isnotmatch) SetFlag(mi,k_notmatch); - if (isrxsmatch) SetFlag(mi,k_rxsmatch); + if (isnotmatch) + SetFlag(mi, k_notmatch); + if (isrxsmatch) + SetFlag(mi, k_rxsmatch); Delete(attrlist); - Append(matchlist,mi); + Append(matchlist, mi); Delete(mi); deleteNode(kw); } else { for (rkey = keys; *rkey != 0; ++rkey) { - if (strcmp(ckey,*rkey) == 0) { - Setattr(nameobj, *rkey, Getattr(kw,k_value)); + if (strcmp(ckey, *rkey) == 0) { + Setattr(nameobj, *rkey, Getattr(kw, k_value)); deleteNode(kw); } } @@ -1059,36 +1060,35 @@ static void Swig_name_object_attach_keys(const char *keys[], Hash *nameobj) kw = next; } if (matchlist) { - Setattr(nameobj,k_matchlist,matchlist); + Setattr(nameobj, k_matchlist, matchlist); Delete(matchlist); } } -void Swig_name_nameobj_add(Hash *name_hash, List *name_list, - String *prefix, String *name, SwigType *decl, Hash *nameobj) { +void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, String *name, SwigType *decl, Hash *nameobj) { String *nname = 0; if (name && Len(name)) { - String *target_fmt = Getattr(nameobj,k_targetfmt); - nname = prefix ? NewStringf("%s::%s",prefix, name) : NewString(name); + String *target_fmt = Getattr(nameobj, k_targetfmt); + nname = prefix ? NewStringf("%s::%s", prefix, name) : NewString(name); if (target_fmt) { String *tmp = NewStringf(target_fmt, nname); Delete(nname); nname = tmp; } - } - - if (!nname || !Len(nname) || - Getattr(nameobj,k_fullname) || /* any of these options trigger a 'list' nameobj */ - Getattr(nameobj,k_sourcefmt) || - Getattr(nameobj,k_matchlist)) { - if (decl) Setattr(nameobj,k_decl, decl); - if (nname && Len(nname)) Setattr(nameobj,k_targetname, nname); + } + + if (!nname || !Len(nname) || Getattr(nameobj, k_fullname) || /* any of these options trigger a 'list' nameobj */ + Getattr(nameobj, k_sourcefmt) || Getattr(nameobj, k_matchlist)) { + if (decl) + Setattr(nameobj, k_decl, decl); + if (nname && Len(nname)) + Setattr(nameobj, k_targetname, nname); /* put the new nameobj at the beginnig of the list, such that the last inserted rule take precedence */ Insert(name_list, 0, nameobj); } else { /* here we add an old 'hash' nameobj, simple and fast */ - Swig_name_object_set(name_hash,nname,decl,nameobj); + Swig_name_object_set(name_hash, nname, decl, nameobj); } Delete(nname); } @@ -1100,19 +1100,18 @@ void Swig_name_nameobj_add(Hash *name_hash, List *name_list, * * ----------------------------------------------------------------------------- */ -static DOH *Swig_get_lattr(Node *n, List *lattr) -{ +static DOH *Swig_get_lattr(Node *n, List *lattr) { DOH *res = 0; int ilen = Len(lattr); int i; for (i = 0; n && (i < ilen); ++i) { - String *nattr = Getitem(lattr,i); - res = Getattr(n,nattr); -#ifdef SWIG_DEBUG + String *nattr = Getitem(lattr, i); + res = Getattr(n, nattr); +#ifdef SWIG_DEBUG if (!res) { - Printf(stderr,"missing %s %s %s\n",nattr, Getattr(n,k_name), Getattr(n,"member")); - } else { - Printf(stderr,"lattr %d %s %s\n",i, nattr, DohIsString(res) ? res : Getattr(res,k_name)); + Printf(stderr, "missing %s %s %s\n", nattr, Getattr(n, k_name), Getattr(n, "member")); + } else { + Printf(stderr, "lattr %d %s %s\n", i, nattr, DohIsString(res) ? res : Getattr(res, k_name)); } #endif n = res; @@ -1127,94 +1126,93 @@ static DOH *Swig_get_lattr(Node *n, List *lattr) #endif #if defined(USE_RXSPENCER) -int Swig_name_rxsmatch_value(String *mvalue, String *value) -{ +int Swig_name_rxsmatch_value(String *mvalue, String *value) { int match = 0; char *cvalue = Char(value); char *cmvalue = Char(mvalue); regex_t compiled; - int retval = regcomp(&compiled, cmvalue, REG_EXTENDED|REG_NOSUB); - if(retval != 0) return 0; - retval = regexec(&compiled,cvalue,0,0,0); + int retval = regcomp(&compiled, cmvalue, REG_EXTENDED | REG_NOSUB); + if (retval != 0) + return 0; + retval = regexec(&compiled, cvalue, 0, 0, 0); match = (retval == REG_NOMATCH) ? 0 : 1; #ifdef SWIG_DEBUG - Printf(stderr,"rxsmatch_value: %s %s %d\n",cvalue,cmvalue, match); + Printf(stderr, "rxsmatch_value: %s %s %d\n", cvalue, cmvalue, match); #endif regfree(&compiled); return match; } #else -int Swig_name_rxsmatch_value(String *mvalue, String *value) -{ - (void)mvalue; - (void)value; +int Swig_name_rxsmatch_value(String *mvalue, String *value) { + (void) mvalue; + (void) value; return 0; } #endif -int Swig_name_match_value(String *mvalue, String *value) -{ +int Swig_name_match_value(String *mvalue, String *value) { #if defined(SWIG_USE_SIMPLE_MATCHOR) int match = 0; char *cvalue = Char(value); char *cmvalue = Char(mvalue); - char *sep = strchr(cmvalue,'|'); + char *sep = strchr(cmvalue, '|'); while (sep && !match) { - match = strncmp(cvalue,cmvalue, sep - cmvalue) == 0; -#ifdef SWIG_DEBUG - Printf(stderr,"match_value: %s %s %d\n",cvalue,cmvalue, match); + match = strncmp(cvalue, cmvalue, sep - cmvalue) == 0; +#ifdef SWIG_DEBUG + Printf(stderr, "match_value: %s %s %d\n", cvalue, cmvalue, match); #endif cmvalue = sep + 1; - sep = strchr(cmvalue,'|'); + sep = strchr(cmvalue, '|'); } if (!match) { - match = strcmp(cvalue,cmvalue) == 0; -#ifdef SWIG_DEBUG - Printf(stderr,"match_value: %s %s %d\n",cvalue,cmvalue, match); + match = strcmp(cvalue, cmvalue) == 0; +#ifdef SWIG_DEBUG + Printf(stderr, "match_value: %s %s %d\n", cvalue, cmvalue, match); #endif } return match; #else - return StringEqual(mvalue,value); + return StringEqual(mvalue, value); #endif } int Swig_name_match_nameobj(Hash *rn, Node *n) { int match = 1; - List *matchlist = HashGetAttr(rn,k_matchlist); -#ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_match_nameobj: %s\n",Getattr(n,"name")); + List *matchlist = HashGetAttr(rn, k_matchlist); +#ifdef SWIG_DEBUG + Printf(stderr, "Swig_name_match_nameobj: %s\n", Getattr(n, "name")); #endif if (matchlist) { int ilen = Len(matchlist); int i; for (i = 0; match && (i < ilen); ++i) { - Node *mi = Getitem(matchlist,i); - List *lattr = Getattr(mi,k_attrlist); - String *nval = Swig_get_lattr(n,lattr); - int notmatch = GetFlag(mi,k_notmatch); - int rxsmatch = GetFlag(mi,k_rxsmatch); -#ifdef SWIG_DEBUG - Printf(stderr,"mi %d %s re %d not %d \n", i, nval, notmatch, rxsmatch); + Node *mi = Getitem(matchlist, i); + List *lattr = Getattr(mi, k_attrlist); + String *nval = Swig_get_lattr(n, lattr); + int notmatch = GetFlag(mi, k_notmatch); + int rxsmatch = GetFlag(mi, k_rxsmatch); +#ifdef SWIG_DEBUG + Printf(stderr, "mi %d %s re %d not %d \n", i, nval, notmatch, rxsmatch); if (rxsmatch) { - Printf(stderr,"rxsmatch %s\n",lattr); - } + Printf(stderr, "rxsmatch %s\n", lattr); + } #endif match = 0; if (nval) { - String *kwval = Getattr(mi,k_value); - match = rxsmatch ? Swig_name_rxsmatch_value(kwval, nval) - : Swig_name_match_value(kwval, nval); -#ifdef SWIG_DEBUG - Printf(stderr,"val %s %s %d %d \n",nval, kwval,match, ilen); + String *kwval = Getattr(mi, k_value); + match = rxsmatch ? Swig_name_rxsmatch_value(kwval, nval) + : Swig_name_match_value(kwval, nval); +#ifdef SWIG_DEBUG + Printf(stderr, "val %s %s %d %d \n", nval, kwval, match, ilen); #endif } - if (notmatch) match = !match; + if (notmatch) + match = !match; } } -#ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_match_nameobj: %d\n",match); +#ifdef SWIG_DEBUG + Printf(stderr, "Swig_name_match_nameobj: %d\n", match); #endif return match; } @@ -1233,20 +1231,20 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na int i; int match = 0; for (i = 0; !match && (i < len); i++) { - Hash *rn = Getitem(namelist,i); - String *rdecl = HashGetAttr(rn,k_decl); - if (rdecl && (!decl || !Equal(rdecl,decl))) { + Hash *rn = Getitem(namelist, i); + String *rdecl = HashGetAttr(rn, k_decl); + if (rdecl && (!decl || !Equal(rdecl, decl))) { continue; } else if (Swig_name_match_nameobj(rn, n)) { - String *tname = HashGetAttr(rn,k_targetname); + String *tname = HashGetAttr(rn, k_targetname); if (tname) { - String *sfmt = HashGetAttr(rn,k_sourcefmt); + String *sfmt = HashGetAttr(rn, k_sourcefmt); String *sname = 0; - int fullname = GetFlag(rn,k_fullname); - int rxstarget = GetFlag(rn,k_rxstarget); + int fullname = GetFlag(rn, k_fullname); + int rxstarget = GetFlag(rn, k_rxstarget); if (sfmt) { if (fullname && prefix) { - String *pname= NewStringf("%s::%s", prefix, name); + String *pname = NewStringf("%s::%s", prefix, name); sname = NewStringf(sfmt, pname); Delete(pname); } else { @@ -1260,8 +1258,7 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na DohIncref(name); } } - match = rxstarget ? Swig_name_rxsmatch_value(tname,sname) : - Swig_name_match_value(tname,sname); + match = rxstarget ? Swig_name_rxsmatch_value(tname, sname) : Swig_name_match_value(tname, sname); Delete(sname); } else { match = 1; @@ -1284,10 +1281,9 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na * ----------------------------------------------------------------------------- */ void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn) { - const char *namewrn_keys[] = {"rename", "error", "fullname", "sourcefmt", "targetfmt", 0}; + const char *namewrn_keys[] = { "rename", "error", "fullname", "sourcefmt", "targetfmt", 0 }; Swig_name_object_attach_keys(namewrn_keys, namewrn); - Swig_name_nameobj_add(Swig_name_namewarn_hash(), Swig_name_namewarn_list(), - prefix, name, decl, namewrn); + Swig_name_nameobj_add(Swig_name_namewarn_hash(), Swig_name_namewarn_list(), prefix, name, decl, namewrn); } /* ----------------------------------------------------------------------------- @@ -1297,15 +1293,16 @@ void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash * * * ----------------------------------------------------------------------------- */ -Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name,SwigType *decl) { - if (!namewarn_hash && !namewarn_list) return 0; +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,k_access); - int is_public = !access || Equal(access,k_public); + String *access = Getattr(n, k_access); + int is_public = !access || Equal(access, k_public); if (!is_public && !Swig_need_protected(n)) { return 0; } @@ -1313,18 +1310,19 @@ Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name,SwigType *dec } 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; + 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 && HashGetAttr(wrn,k_error)) { + if (wrn && HashGetAttr(wrn, k_error)) { if (n) { - Swig_error(Getfile(n), Getline(n), "%s\n", HashGetAttr(wrn,k_name)); + Swig_error(Getfile(n), Getline(n), "%s\n", HashGetAttr(wrn, k_name)); } else { - Swig_error(cparse_file, cparse_line,"%s\n", HashGetAttr(wrn,k_name)); + Swig_error(cparse_file, cparse_line, "%s\n", HashGetAttr(wrn, k_name)); } - } + } return wrn; } else { return 0; @@ -1338,9 +1336,9 @@ Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name,SwigType *dec * * ----------------------------------------------------------------------------- */ -String *Swig_name_warning(Node *n, String *prefix, String *name,SwigType *decl) { - Hash *wrn = Swig_name_namewarn_get(n, prefix, name,decl); - return (name && wrn) ? HashGetAttr(wrn,k_name) : 0; +String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl) { + Hash *wrn = Swig_name_namewarn_get(n, prefix, name, decl); + return (name && wrn) ? HashGetAttr(wrn, k_name) : 0; } /* ----------------------------------------------------------------------------- @@ -1351,44 +1349,42 @@ String *Swig_name_warning(Node *n, String *prefix, String *name,SwigType *decl) * ----------------------------------------------------------------------------- */ static void single_rename_add(String *prefix, String *name, SwigType *decl, Hash *newname) { - Swig_name_nameobj_add(Swig_name_rename_hash(), Swig_name_rename_list(), - prefix, name, decl, newname); + Swig_name_nameobj_add(Swig_name_rename_hash(), Swig_name_rename_list(), prefix, name, decl, newname); } /* Add a new rename. Works much like new_feature including default argument handling. */ -void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *newname, - ParmList *declaratorparms) { - +void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *newname, ParmList *declaratorparms) { + ParmList *declparms = declaratorparms; - - const char *rename_keys[] = {"fullname", "sourcefmt", "targetfmt", "continue", "rxstarget",0}; + + const char *rename_keys[] = { "fullname", "sourcefmt", "targetfmt", "continue", "rxstarget", 0 }; Swig_name_object_attach_keys(rename_keys, newname); - + /* Add the name */ single_rename_add(prefix, name, decl, newname); - + /* Add extra names if there are default parameters in the parameter list */ if (decl) { int constqualifier = SwigType_isconst(decl); while (declparms) { if (ParmList_has_defaultargs(declparms)) { - - /* Create a parameter list for the new rename by copying all - but the last (defaulted) parameter */ - ParmList* newparms = ParmList_copy_all_except_last_parm(declparms); - - /* Create new declaration - with the last parameter removed */ - SwigType *newdecl = Copy(decl); - Delete(SwigType_pop_function(newdecl)); /* remove the old parameter list from newdecl */ - SwigType_add_function(newdecl,newparms); - if (constqualifier) - SwigType_add_qualifier(newdecl,"const"); - - single_rename_add(prefix, name, newdecl, newname); - declparms = newparms; - Delete(newdecl); + + /* Create a parameter list for the new rename by copying all + but the last (defaulted) parameter */ + ParmList *newparms = ParmList_copy_all_except_last_parm(declparms); + + /* Create new declaration - with the last parameter removed */ + SwigType *newdecl = Copy(decl); + Delete(SwigType_pop_function(newdecl)); /* remove the old parameter list from newdecl */ + SwigType_add_function(newdecl, newparms); + if (constqualifier) + SwigType_add_qualifier(newdecl, "const"); + + single_rename_add(prefix, name, newdecl, newname); + declparms = newparms; + Delete(newdecl); } else { - declparms = 0; + declparms = 0; } } } @@ -1402,11 +1398,10 @@ void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *ne * ----------------------------------------------------------------------------- */ /* Create a name applying rename/namewarn if needed */ -static String *apply_rename(String *newname, int fullname, String *prefix, String *name) -{ +static String *apply_rename(String *newname, int fullname, String *prefix, String *name) { String *result = 0; if (newname && Len(newname)) { - if (Strcmp(newname,"$ignore") == 0) { + if (Strcmp(newname, "$ignore") == 0) { result = Copy(newname); } else { char *cnewname = Char(newname); @@ -1414,27 +1409,26 @@ static String *apply_rename(String *newname, int fullname, String *prefix, Strin int destructor = name && (*(Char(name)) == '~'); String *fmt = newname; /* use name as a fmt, but avoid C++ "%" and "%=" operators */ - if (Len(newname) > 1 && strchr(cnewname,'%') && !(strcmp(cnewname,"%=") == 0)) { - if (fullname && prefix) { - result = NewStringf(fmt,prefix,name); + if (Len(newname) > 1 && strchr(cnewname, '%') && !(strcmp(cnewname, "%=") == 0)) { + if (fullname && prefix) { + result = NewStringf(fmt, prefix, name); } else { - result = NewStringf(fmt,name); + result = NewStringf(fmt, name); } } else { result = Copy(newname); } if (destructor && result && (*(Char(result)) != '~')) { - Insert(result,0,"~"); + Insert(result, 0, "~"); } } } } - + return result; } -String * -Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname) { +String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname) { String *nname = 0; String *result = 0; String *name = NewString(cname); @@ -1444,46 +1438,46 @@ Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, S /* very specific hack for template constructors/destructors */ #ifdef SWIG_DEBUG - Printf(stderr,"SWIG_name_make: looking for %s %s %s %s\n", prefix, name, decl, oldname); + Printf(stderr, "SWIG_name_make: looking for %s %s %s %s\n", prefix, name, decl, oldname); #endif if (name && n && SwigType_istemplate(name)) { String *nodetype = Getattr(n, k_nodetype); - if (nodetype && (Equal(nodetype,k_constructor) || Equal(nodetype,k_destructor))) { + if (nodetype && (Equal(nodetype, k_constructor) || Equal(nodetype, k_destructor))) { String *nprefix = NewStringEmpty(); String *nlast = NewStringEmpty(); String *tprefix; - Swig_scopename_split(name, &nprefix, &nlast); + Swig_scopename_split(name, &nprefix, &nlast); tprefix = SwigType_templateprefix(nlast); Delete(nlast); if (Len(nprefix)) { - Append(nprefix,"::"); - Append(nprefix,tprefix); + Append(nprefix, "::"); + Append(nprefix, tprefix); Delete(tprefix); - rname = nprefix; + rname = nprefix; } else { rname = tprefix; Delete(nprefix); } rdecl = Copy(decl); - Replaceall(rdecl,name,rname); + Replaceall(rdecl, name, rname); #ifdef SWIG_DEBUG - Printf(stderr,"SWIG_name_make: use new name %s %s : %s %s\n",name, decl, rname, rdecl); + Printf(stderr, "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) { - Hash *rn = Swig_name_object_get(Swig_name_rename_hash(), prefix, name, decl); - if (!rn || !Swig_name_match_nameobj(rn,n)) { + 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 = HashGetAttr(rn,k_sourcefmt); - int fullname = GetFlag(rn,k_fullname); + String *sfmt = HashGetAttr(rn, k_sourcefmt); + int fullname = GetFlag(rn, k_fullname); if (fullname && prefix) { String *sname = NewStringf("%s::%s", prefix, name); Delete(name); @@ -1498,16 +1492,16 @@ Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, S } } if (rn) { - String *newname = HashGetAttr(rn,k_name); - int fullname = GetFlag(rn,k_fullname); + String *newname = HashGetAttr(rn, k_name); + int fullname = GetFlag(rn, k_fullname); result = apply_rename(newname, fullname, prefix, name); } - if (result && !Equal(result,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)) { + if (cresult && (strncmp(cresult, "operator ", 9) == 0)) { String *nresult = Swig_name_make(n, prefix, result, decl, oldname); - if (!Equal(nresult,result)) { + if (!Equal(nresult, result)) { Delete(result); result = nresult; } else { @@ -1518,29 +1512,31 @@ Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, S nname = result ? result : name; wrn = Swig_name_namewarn_get(n, prefix, nname, decl); if (wrn) { - String *rename = HashGetAttr(wrn,k_rename); + String *rename = HashGetAttr(wrn, k_rename); if (rename) { - String *msg = HashGetAttr(wrn,k_name); - int fullname = GetFlag(wrn,k_fullname); - if (result) Delete(result); + String *msg = HashGetAttr(wrn, k_name); + int fullname = GetFlag(wrn, k_fullname); + if (result) + Delete(result); result = apply_rename(rename, fullname, prefix, name); if ((msg) && (Len(msg))) { - if (!Getmeta(nname,"already_warned")) { - if (n) { + if (!Getmeta(nname, "already_warned")) { + if (n) { SWIG_WARN_NODE_BEGIN(n); - Swig_warning(0,Getfile(n), Getline(n), "%s\n", msg); + 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); + Swig_warning(0, Getfile(name), Getline(name), "%s\n", msg); } - Setmeta(nname,"already_warned","1"); + Setmeta(nname, "already_warned", "1"); } } } } } if (!result || !Len(result)) { - if (result) Delete(result); + if (result) + Delete(result); if (oldname) { result = NewString(oldname); } else { @@ -1548,9 +1544,9 @@ Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, S } } Delete(name); - + #ifdef SWIG_DEBUG - Printf(stderr,"Swig_name_make: result '%s' '%s'\n", cname, result); + Printf(stderr, "Swig_name_make: result '%s' '%s'\n", cname, result); #endif return result; @@ -1565,7 +1561,7 @@ Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, S void Swig_name_inherit(String *base, String *derived) { /* Printf(stderr,"base = '%s', derived = '%s'\n", base, derived); */ - Swig_name_object_inherit(Swig_name_rename_hash(),base,derived); - Swig_name_object_inherit(Swig_name_namewarn_hash(),base,derived); - Swig_name_object_inherit(Swig_cparse_features(),base,derived); + Swig_name_object_inherit(Swig_name_rename_hash(), base, derived); + Swig_name_object_inherit(Swig_name_namewarn_hash(), base, derived); + Swig_name_object_inherit(Swig_cparse_features(), base, derived); } diff --git a/SWIG/Source/Swig/parms.c b/SWIG/Source/Swig/parms.c index 243a4fbf0..a8fd679c6 100644 --- a/SWIG/Source/Swig/parms.c +++ b/SWIG/Source/Swig/parms.c @@ -20,13 +20,13 @@ char cvsroot_parms_c[] = "$Header$"; Parm *NewParm(SwigType *type, const String_or_char *name) { Parm *p = NewHash(); - Setattr(p,k_nodetype,k_parm); + Setattr(p, k_nodetype, k_parm); if (type) { SwigType *ntype = Copy(type); - Setattr(p,k_type,ntype); + Setattr(p, k_type, ntype); Delete(ntype); } - Setattr(p,k_name,name); + Setattr(p, k_name, name); return p; } @@ -42,7 +42,7 @@ Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n) { Parm *p = NewParm(type, name); Setfile(p, Getfile(n)); Setline(p, Getline(n)); - + return p; } @@ -51,45 +51,45 @@ Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n) { * ------------------------------------------------------------------------ */ Parm *CopyParm(Parm *p) { - Parm *np = NewHash(); - SwigType *t = HashGetAttr(p,k_type); - String *name = HashGetAttr(p,k_name); - String *lname = HashGetAttr(p,k_lname); - String *value = HashGetAttr(p,k_value); - String *ignore = HashGetAttr(p,k_ignore); - String *alttype = HashGetAttr(p,k_alttype); - String *byname = HashGetAttr(p, k_argbyname); - String *compactdefargs = HashGetAttr(p, k_compactdefargs); - String *self = HashGetAttr(p, k_self); + Parm *np = NewHash(); + SwigType *t = HashGetAttr(p, k_type); + String *name = HashGetAttr(p, k_name); + String *lname = HashGetAttr(p, k_lname); + String *value = HashGetAttr(p, k_value); + String *ignore = HashGetAttr(p, k_ignore); + String *alttype = HashGetAttr(p, k_alttype); + String *byname = HashGetAttr(p, k_argbyname); + String *compactdefargs = HashGetAttr(p, k_compactdefargs); + String *self = HashGetAttr(p, k_self); if (t) { SwigType *nt = Copy(t); - Setattr(np,k_type,nt); + Setattr(np, k_type, nt); Delete(nt); } if (name) { String *str = Copy(name); - Setattr(np,k_name,str); + Setattr(np, k_name, str); Delete(str); } if (lname) { String *str = Copy(lname); - Setattr(np,k_lname, str); + Setattr(np, k_lname, str); Delete(str); } if (value) { String *str = Copy(value); - Setattr(np,k_value, str); + Setattr(np, k_value, str); Delete(str); } if (ignore) { String *str = Copy(ignore); - Setattr(np,k_ignore, str); + Setattr(np, k_ignore, str); Delete(str); } if (alttype) { String *str = Copy(alttype); - Setattr(np,k_alttype, str); + Setattr(np, k_alttype, str); Delete(str); } if (byname) { @@ -98,7 +98,7 @@ Parm *CopyParm(Parm *p) { Delete(str); } if (compactdefargs) { - String *str = Copy(compactdefargs); + String *str = Copy(compactdefargs); Setattr(np, k_compactdefargs, str); Delete(str); } @@ -107,9 +107,9 @@ Parm *CopyParm(Parm *p) { Setattr(np, k_self, str); Delete(str); } - - Setfile(np,Getfile(p)); - Setline(np,Getline(p)); + + Setfile(np, Getfile(p)); + Setline(np, Getline(p)); return np; } @@ -118,19 +118,19 @@ Parm *CopyParm(Parm *p) { * CopyParmList() * ------------------------------------------------------------------ */ -ParmList * -CopyParmList(ParmList *p) { +ParmList *CopyParmList(ParmList *p) { Parm *np; Parm *pp = 0; Parm *fp = 0; - if (!p) return 0; + if (!p) + return 0; while (p) { np = CopyParm(p); if (pp) { - set_nextSibling(pp,np); - Delete(np); + set_nextSibling(pp, np); + Delete(np); } else { fp = np; } @@ -145,9 +145,10 @@ CopyParmList(ParmList *p) { * ------------------------------------------------------------------ */ int ParmList_numarg(ParmList *p) { - int n = 0; + int n = 0; while (p) { - if (!HashGetAttr(p,k_ignore)) n++; + if (!HashGetAttr(p, k_ignore)) + n++; p = nextSibling(p); } return n; @@ -160,11 +161,14 @@ int ParmList_numarg(ParmList *p) { int ParmList_numrequired(ParmList *p) { int i = 0; while (p) { - SwigType *t = HashGetAttr(p,k_type); - String *value = HashGetAttr(p,k_value); - if (value) return i; - if (!(SwigType_type(t) == T_VOID)) i++; - else break; + SwigType *t = HashGetAttr(p, k_type); + String *value = HashGetAttr(p, k_value); + if (value) + return i; + if (!(SwigType_type(t) == T_VOID)) + i++; + else + break; p = nextSibling(p); } return i; @@ -191,12 +195,12 @@ int ParmList_len(ParmList *p) { String *ParmList_str(ParmList *p) { String *out = NewStringEmpty(); - while(p) { - String *pstr = SwigType_str(HashGetAttr(p,k_type), HashGetAttr(p,k_name)); - StringAppend(out,pstr); + while (p) { + String *pstr = SwigType_str(HashGetAttr(p, k_type), HashGetAttr(p, k_name)); + StringAppend(out, pstr); p = nextSibling(p); if (p) { - StringAppend(out,","); + StringAppend(out, ","); } Delete(pstr); } @@ -211,18 +215,18 @@ String *ParmList_str(ParmList *p) { String *ParmList_str_defaultargs(ParmList *p) { String *out = NewStringEmpty(); - while(p) { - String *value = HashGetAttr(p,k_value); - String *pstr = SwigType_str(HashGetAttr(p,k_type), HashGetAttr(p,k_name)); - StringAppend(out,pstr); + while (p) { + String *value = HashGetAttr(p, k_value); + String *pstr = SwigType_str(HashGetAttr(p, k_type), HashGetAttr(p, k_name)); + StringAppend(out, pstr); if (value) { - Printf(out,"=%s", value); + Printf(out, "=%s", value); } p = nextSibling(p); if (p) { - StringAppend(out,","); + StringAppend(out, ","); } - Delete(pstr); + Delete(pstr); } return out; } @@ -235,15 +239,15 @@ String *ParmList_str_defaultargs(ParmList *p) { String *ParmList_protostr(ParmList *p) { String *out = NewStringEmpty(); - while(p) { - if (HashGetAttr(p,k_hidden)) { + while (p) { + if (HashGetAttr(p, k_hidden)) { p = nextSibling(p); } else { - String *pstr = SwigType_str(HashGetAttr(p,k_type), 0); - StringAppend(out,pstr); + String *pstr = SwigType_str(HashGetAttr(p, k_type), 0); + StringAppend(out, pstr); p = nextSibling(p); if (p) { - StringAppend(out,","); + StringAppend(out, ","); } Delete(pstr); } @@ -260,16 +264,16 @@ String *ParmList_protostr(ParmList *p) { int ParmList_is_compactdefargs(ParmList *p) { int compactdefargs = 0; - + if (p) { - compactdefargs = HashGetAttr(p,k_compactdefargs) ? 1 : 0; + compactdefargs = HashGetAttr(p, k_compactdefargs) ? 1 : 0; /* The "compactdefargs" attribute should only be set on the first parameter in the list. * However, sometimes an extra parameter is inserted at the beginning of the parameter list, * so we check the 2nd parameter too. */ if (!compactdefargs) { Parm *nextparm = nextSibling(p); - compactdefargs = (nextparm && HashGetAttr(nextparm,k_compactdefargs)) ? 1 : 0; + compactdefargs = (nextparm && HashGetAttr(nextparm, k_compactdefargs)) ? 1 : 0; } } @@ -285,15 +289,15 @@ int ParmList_is_compactdefargs(ParmList *p) { * ---------------------------------------------------------------------- */ int ParmList_has_defaultargs(ParmList *p) { - int default_args = 0; - while (p) { - if (HashGetAttr(p, k_value)) { - default_args = 1; - break; - } - p = nextSibling(p); + int default_args = 0; + while (p) { + if (HashGetAttr(p, k_value)) { + default_args = 1; + break; } - return default_args; + p = nextSibling(p); + } + return default_args; } /* --------------------------------------------------------------------- @@ -304,14 +308,14 @@ int ParmList_has_defaultargs(ParmList *p) { * ---------------------------------------------------------------------- */ ParmList *ParmList_copy_all_except_last_parm(ParmList *p) { - ParmList* newparms = 0; + ParmList *newparms = 0; Parm *newparm = 0; Parm *pp = 0; Parm *fp = 0; while (nextSibling(p)) { newparm = CopyParm(p); if (pp) { - set_nextSibling(pp,newparm); + set_nextSibling(pp, newparm); Delete(newparm); } else { fp = newparm; diff --git a/SWIG/Source/Swig/scanner.c b/SWIG/Source/Swig/scanner.c index d997164a8..977380f6d 100644 --- a/SWIG/Source/Swig/scanner.c +++ b/SWIG/Source/Swig/scanner.c @@ -16,16 +16,16 @@ char cvsroot_scanner_c[] = "$Header$"; #include struct SwigScanner { - String *text; /* Current token value */ - List *scanobjs; /* Objects being scanned */ - String *str; /* Current object being scanned */ - char *idstart; /* Optional identifier start characters */ - int nexttoken; /* Next token to be returned */ - int start_line; /* Starting line of certain declarations */ - int string_start; - int line; - int yylen; /* Length of text pushed into text */ - String *file; + String *text; /* Current token value */ + List *scanobjs; /* Objects being scanned */ + String *str; /* Current object being scanned */ + char *idstart; /* Optional identifier start characters */ + int nexttoken; /* Next token to be returned */ + int start_line; /* Starting line of certain declarations */ + int string_start; + int line; + int yylen; /* Length of text pushed into text */ + String *file; }; /* ----------------------------------------------------------------------------- @@ -34,8 +34,7 @@ struct SwigScanner { * Create a new scanner object * ----------------------------------------------------------------------------- */ -SwigScanner * -NewSwigScanner() { +SwigScanner *NewSwigScanner() { SwigScanner *s; s = (SwigScanner *) malloc(sizeof(SwigScanner)); s->line = 1; @@ -57,8 +56,7 @@ NewSwigScanner() { * Delete a scanner object. * ----------------------------------------------------------------------------- */ -void -DelSwigScanner(SwigScanner *s) { +void DelSwigScanner(SwigScanner * s) { assert(s); Delete(s->scanobjs); Delete(s->text); @@ -72,8 +70,7 @@ DelSwigScanner(SwigScanner *s) { * Clear the contents of a scanner object. * ----------------------------------------------------------------------------- */ -void -SwigScanner_clear(SwigScanner *s) { +void SwigScanner_clear(SwigScanner * s) { assert(s); Delete(s->str); Clear(s->text); @@ -92,11 +89,11 @@ SwigScanner_clear(SwigScanner *s) { * immediately before returning to the old text. * ----------------------------------------------------------------------------- */ -void -SwigScanner_push(SwigScanner *s, String *txt) { +void SwigScanner_push(SwigScanner * s, String *txt) { assert(s && txt); - Push(s->scanobjs,txt); - if (s->str) Delete(s->str); + Push(s->scanobjs, txt); + if (s->str) + Delete(s->str); s->str = txt; DohIncref(s->str); s->line = Getline(txt); @@ -109,8 +106,7 @@ SwigScanner_push(SwigScanner *s, String *txt) { * call to SwigScanner_token(). * ----------------------------------------------------------------------------- */ -void -SwigScanner_pushtoken(SwigScanner *s, int nt) { +void SwigScanner_pushtoken(SwigScanner * s, int nt) { assert(s); assert((nt >= 0) && (nt < SWIG_MAXTOKENS)); s->nexttoken = nt; @@ -122,10 +118,9 @@ SwigScanner_pushtoken(SwigScanner *s, int nt) { * Set the file and line number location of the scanner. * ----------------------------------------------------------------------------- */ -void -SwigScanner_set_location(SwigScanner *s, String *file, int line) { - Setline(s->str,line); - Setfile(s->str,file); +void SwigScanner_set_location(SwigScanner * s, String *file, int line) { + Setline(s->str, line); + Setfile(s->str, file); } /* ----------------------------------------------------------------------------- @@ -134,8 +129,7 @@ SwigScanner_set_location(SwigScanner *s, String *file, int line) { * Get the current file. * ----------------------------------------------------------------------------- */ -String * -SwigScanner_get_file(SwigScanner *s) { +String *SwigScanner_get_file(SwigScanner * s) { return Getfile(s->str); } @@ -144,8 +138,7 @@ SwigScanner_get_file(SwigScanner *s) { * * Get the current line number * ----------------------------------------------------------------------------- */ -int -SwigScanner_get_line(SwigScanner *s) { +int SwigScanner_get_line(SwigScanner * s) { return Getline(s->str); } @@ -155,8 +148,7 @@ SwigScanner_get_line(SwigScanner *s) { * Change the set of additional characters that can be used to start an identifier. * ----------------------------------------------------------------------------- */ -void -SwigScanner_idstart(SwigScanner *s, char *id) { +void SwigScanner_idstart(SwigScanner * s, char *id) { s->idstart = Swig_copy_string(id); } @@ -165,27 +157,28 @@ SwigScanner_idstart(SwigScanner *s, char *id) { * * Returns the next character from the scanner or 0 if end of the string. * ----------------------------------------------------------------------------- */ -static char -nextchar(SwigScanner *s) -{ - char c[2] = {0,0}; +static char nextchar(SwigScanner * s) { + char c[2] = { 0, 0 }; int nc; - if (!s->str) return 0; + if (!s->str) + return 0; while ((nc = Getc(s->str)) == EOF) { Delete(s->str); s->str = 0; - Delitem(s->scanobjs,0); - if (Len(s->scanobjs) == 0) return 0; - s->str = Getitem(s->scanobjs,0); + Delitem(s->scanobjs, 0); + if (Len(s->scanobjs) == 0) + return 0; + s->str = Getitem(s->scanobjs, 0); if (s->str) { s->line = Getline(s->str); DohIncref(s->str); } } - if (nc == '\n') s->line++; + if (nc == '\n') + s->line++; c[0] = (char) nc; c[1] = 0; - Append(s->text,c); + Append(s->text, c); return c[0]; } @@ -194,21 +187,20 @@ nextchar(SwigScanner *s) * * Retract n characters * ----------------------------------------------------------------------------- */ -static void -retract(SwigScanner *s, int n) { +static void retract(SwigScanner * s, int n) { int i, l; char *str; - + str = Char(s->text); l = Len(s->text); assert(n <= l); for (i = 0; i < n; i++) { - if (str[l-1] == '\n') { + if (str[l - 1] == '\n') { s->line--; } /* // Ungetc(str[l-1],s->str); */ - Seek(s->str,-1, SEEK_CUR); - Delitem(s->text,DOH_END); + Seek(s->str, -1, SEEK_CUR); + Delitem(s->text, DOH_END); } } @@ -218,468 +210,546 @@ retract(SwigScanner *s, int n) { * Return the raw value of the next token. * ----------------------------------------------------------------------------- */ -static int -look(SwigScanner *s) { - int state; - int c = 0; +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 delimiters */ + 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); - 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; + /* Process delimiters */ - case 1000: - if ((c = nextchar(s)) == 0) return (0); - if (c == '%') state = 4; /* Possibly a SWIG directive */ + 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; - /* Look for possible identifiers */ + case 1000: + if ((c = nextchar(s)) == 0) + return (0); + if (c == '%') + state = 4; /* Possibly a SWIG directive */ - 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 possible identifiers */ - /* 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 ((isalpha(c)) || (c == '_') || (strchr(s->idstart, c))) + state = 7; - 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; - } + /* Look for single character symbols */ - 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; + 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; - 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)); + /* Look for multi-character sequences */ - 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; + else if (c == '/') + state = 1; /* Comment (maybe) */ + else if (c == '\"') { + state = 2; /* Possibly a string */ + s->string_start = s->line; + } - 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; + 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; + } - 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; + 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 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 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)); - 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; + 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 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 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 5: /* Maybe a double colon */ + 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; - 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 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 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 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 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 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 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 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; + 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; - /* A long long integer */ + 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 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; - } + case 5: /* Maybe a double colon */ - /* An unsigned number */ - case 88: + if ((c = nextchar(s)) == 0) + return SWIG_TOKEN_COLON; + if (c == ':') + return SWIG_TOKEN_DCOLON; + else { + retract(s, 1); + return SWIG_TOKEN_COLON; + } + break; - 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; - } + 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 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; - /* 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 86: + /* Rest of floating point number */ - case 91: - if ((c = nextchar(s)) == 0) { - /* add_error(0,"Unterminated character constant", string_start); */ - return 0; - } - state = 9; - break; + 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; - /* A period or maybe a floating point number */ + 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; - 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; + /* A long long integer */ - default: - return SWIG_TOKEN_ILLEGAL; - } + 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; } + } } /* ----------------------------------------------------------------------------- @@ -688,17 +758,16 @@ look(SwigScanner *s) { * Real entry point to return the next token. Returns 0 if at end of input. * ----------------------------------------------------------------------------- */ -int -SwigScanner_token(SwigScanner *s) { - int t; - Clear(s->text); - if (s->nexttoken >= 0) { - t = s->nexttoken; - s->nexttoken = -1; - return t; - } - t = look(s); +int SwigScanner_token(SwigScanner * s) { + int t; + Clear(s->text); + if (s->nexttoken >= 0) { + t = s->nexttoken; + s->nexttoken = -1; return t; + } + t = look(s); + return t; } /* ----------------------------------------------------------------------------- @@ -707,9 +776,8 @@ SwigScanner_token(SwigScanner *s) { * Return the lexene associated with the last returned token. * ----------------------------------------------------------------------------- */ -String * -SwigScanner_text(SwigScanner *s) { - return s->text; +String *SwigScanner_text(SwigScanner * s) { + return s->text; } /* ----------------------------------------------------------------------------- @@ -718,19 +786,21 @@ SwigScanner_text(SwigScanner *s) { * Skips to the end of a line * ----------------------------------------------------------------------------- */ -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; +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; } /* ----------------------------------------------------------------------------- @@ -740,70 +810,83 @@ SwigScanner_skip_line(SwigScanner *s) { * (...). Ignores symbols inside comments or strings. * ----------------------------------------------------------------------------- */ -int -SwigScanner_skip_balanced(SwigScanner *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,Getline(s->str)); +int SwigScanner_skip_balanced(SwigScanner * 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, Getline(s->str)); - 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; - } + Append(s->text, temp); + while (num_levels > 0) { + if ((c = nextchar(s)) == 0) { + return -1; } - 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 + 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; } - - - - diff --git a/SWIG/Source/Swig/stype.c b/SWIG/Source/Swig/stype.c index 5f34fce38..cb614f028 100644 --- a/SWIG/Source/Swig/stype.c +++ b/SWIG/Source/Swig/stype.c @@ -86,7 +86,7 @@ char cvsroot_stype_c[] = "$Header$"; SwigType *NewSwigType(int t) { - switch(t) { + switch (t) { case T_BOOL: return NewString("bool"); break; @@ -102,7 +102,7 @@ SwigType *NewSwigType(int t) { case T_USHORT: return NewString("unsigned short"); break; - case T_LONG: + case T_LONG: return NewString("long"); break; case T_ULONG: @@ -126,12 +126,12 @@ SwigType *NewSwigType(int t) { case T_UCHAR: return NewString("unsigned char"); break; - case T_STRING: { - SwigType *t = NewString("char"); - SwigType_add_pointer(t); - return t; - break; - } + case T_STRING:{ + SwigType *t = NewString("char"); + SwigType_add_pointer(t); + return t; + break; + } case T_LONGLONG: return NewString("long long"); break; @@ -141,7 +141,7 @@ SwigType *NewSwigType(int t) { case T_VOID: return NewString("void"); break; - default : + default: break; } return NewStringEmpty(); @@ -153,17 +153,18 @@ SwigType *NewSwigType(int t) { * Push a type constructor onto the type * ----------------------------------------------------------------------------- */ -void SwigType_push(SwigType *t, String *cons) -{ - if (!cons) return; - if (!Len(cons)) return; +void SwigType_push(SwigType *t, String *cons) { + if (!cons) + return; + if (!Len(cons)) + return; if (Len(t)) { char *c = Char(cons); - if (c[strlen(c)-1] != '.') - Insert(t,0,"."); + if (c[strlen(c) - 1] != '.') + Insert(t, 0, "."); } - Insert(t,0,cons); + Insert(t, 0, cons); } /* ----------------------------------------------------------------------------- @@ -178,36 +179,39 @@ void SwigType_push(SwigType *t, String *cons) * ----------------------------------------------------------------------------- */ int SwigType_ispointer_return(SwigType *t) { - char* c; + char *c; int idx; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - idx = strlen(c)-4; + idx = strlen(c) - 4; if (idx >= 0) { - return (strcmp(c+idx, ").p.") == 0); + return (strcmp(c + idx, ").p.") == 0); } return 0; } int SwigType_isreference_return(SwigType *t) { - char* c; + char *c; int idx; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - idx = strlen(c)-4; + idx = strlen(c) - 4; if (idx >= 0) { - return (strcmp(c+idx, ").r.") == 0); + return (strcmp(c + idx, ").r.") == 0); } return 0; } int SwigType_isconst(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - if (strncmp(c,"q(",2) == 0) { + if (strncmp(c, "q(", 2) == 0) { String *q = SwigType_parm(t); - if (strstr(Char(q),"const")) { + if (strstr(Char(q), "const")) { Delete(q); return 1; } @@ -239,8 +243,9 @@ int SwigType_ismutable(SwigType *t) { int SwigType_isenum(SwigType *t) { char *c = Char(t); - if (!t) return 0; - if (strncmp(c,"enum ",5) == 0) { + if (!t) + return 0; + if (strncmp(c, "enum ", 5) == 0) { return 1; } return 0; @@ -248,19 +253,23 @@ int SwigType_isenum(SwigType *t) { int SwigType_issimple(SwigType *t) { char *c = Char(t); - if (!t) return 0; + if (!t) + return 0; while (*c) { if (*c == '<') { int nest = 1; c++; while (*c && nest) { - if (*c == '<') nest++; - if (*c == '>') nest--; + if (*c == '<') + nest++; + if (*c == '>') + nest--; c++; } c--; } - if (*c == '.') return 0; + if (*c == '.') + return 0; c++; } return 1; @@ -319,14 +328,13 @@ static Hash *default_cache = 0; p.SWIGTYPE -> SWIGTYPE */ -static -void SwigType_add_default(String *def, SwigType *nr) -{ - if (Strcmp(nr,"SWIGTYPE") == 0) { - StringAppend(def,"SWIGTYPE"); +static +void SwigType_add_default(String *def, SwigType *nr) { + if (Strcmp(nr, "SWIGTYPE") == 0) { + StringAppend(def, "SWIGTYPE"); } else { String *q = SwigType_isqualifier(nr) ? SwigType_pop(nr) : 0; - if (q && strstr(Char(nr),"SWIGTYPE")) { + if (q && strstr(Char(nr), "SWIGTYPE")) { StringAppend(def, nr); } else { String *nd = SwigType_default(nr); @@ -334,17 +342,17 @@ void SwigType_add_default(String *def, SwigType *nr) String *bdef = nd; if (q) { bdef = NewStringf("%s%s", q, nd); - if ((Strcmp(nr,bdef) == 0)) { + if ((Strcmp(nr, bdef) == 0)) { Delete(bdef); bdef = nd; } else { Delete(nd); } } - StringAppend(def,bdef); + StringAppend(def, bdef); Delete(bdef); } else { - StringAppend(def,nr); + StringAppend(def, nr); } } Delete(q); @@ -358,28 +366,31 @@ SwigType *SwigType_default(SwigType *t) { char *cr; #ifdef SWIG_DEFAULT_CACHE - if (!default_cache) default_cache = NewHash(); - - r = Getattr(default_cache,t); + if (!default_cache) + default_cache = NewHash(); + + r = Getattr(default_cache, t); if (r) { return Copy(r); } #endif - + if (SwigType_isvarargs(t)) { return 0; } r = t; while ((r1 = SwigType_typedef_resolve(r))) { - if (r != t) Delete(r); + if (r != t) + Delete(r); r = r1; } if (SwigType_isqualifier(r)) { String *q; - if (r == t) r = Copy(t); + if (r == t) + r = Copy(t); q = SwigType_pop(r); - if (strstr(Char(r),"SWIGTYPE")) { + if (strstr(Char(r), "SWIGTYPE")) { Delete(q); def = r; return def; @@ -387,20 +398,19 @@ SwigType *SwigType_default(SwigType *t) { Delete(q); } cr = Char(r); - if (strcmp(cr,"p.SWIGTYPE") == 0) { + if (strcmp(cr, "p.SWIGTYPE") == 0) { def = NewString("SWIGTYPE"); } else if (SwigType_ispointer(r)) { #ifdef SWIG_NEW_TYPE_DEFAULT SwigType *nr = Copy(r); SwigType_del_pointer(nr); - def = SwigType_isfunction(nr) ? - NewStringEmpty() : NewString("p."); + def = SwigType_isfunction(nr) ? NewStringEmpty() : NewString("p."); SwigType_add_default(def, nr); Delete(nr); #else def = NewString("p.SWIGTYPE"); #endif - } else if (strcmp(cr,"r.SWIGTYPE") == 0) { + } else if (strcmp(cr, "r.SWIGTYPE") == 0) { def = NewString("SWIGTYPE"); } else if (SwigType_isreference(r)) { #ifdef SWIG_NEW_TYPE_DEFAULT @@ -413,19 +423,19 @@ SwigType *SwigType_default(SwigType *t) { def = NewString("r.SWIGTYPE"); #endif } else if (SwigType_isarray(r)) { - if (strcmp(cr,"a().SWIGTYPE") == 0) { + if (strcmp(cr, "a().SWIGTYPE") == 0) { def = NewString("p.SWIGTYPE"); - } else if (strcmp(cr,"a(ANY).SWIGTYPE") == 0) { + } else if (strcmp(cr, "a(ANY).SWIGTYPE") == 0) { def = NewString("a().SWIGTYPE"); } else { int i, empty = 0; int ndim = SwigType_array_ndim(r); SwigType *nr = Copy(r); for (i = 0; i < ndim; i++) { - String *dim = SwigType_array_getdim(r,i); + String *dim = SwigType_array_getdim(r, i); if (!Len(dim)) { char *c = Char(nr); - empty = strstr(c,"a(ANY).") != c; + empty = strstr(c, "a(ANY).") != c; } Delete(dim); } @@ -438,24 +448,24 @@ SwigType *SwigType_default(SwigType *t) { SwigType_del_array(nr); SwigType_add_default(def, nr); #else - StringAppend(def,"SWIGTYPE"); + StringAppend(def, "SWIGTYPE"); #endif Delete(nr); } } else if (SwigType_ismemberpointer(r)) { - if (strcmp(cr,"m(CLASS).SWIGTYPE") == 0) { + if (strcmp(cr, "m(CLASS).SWIGTYPE") == 0) { def = NewString("p.SWIGTYPE"); } else { def = NewString("m(CLASS).SWIGTYPE"); } } else if (SwigType_isenum(r)) { - if (strcmp(cr,"enum SWIGTYPE") == 0) { + if (strcmp(cr, "enum SWIGTYPE") == 0) { def = NewString("SWIGTYPE"); } else { def = NewString("enum SWIGTYPE"); } } else if (SwigType_isfunction(r)) { - if (strcmp(cr,"f(ANY).SWIGTYPE") == 0) { + if (strcmp(cr, "f(ANY).SWIGTYPE") == 0) { def = NewString("p.SWIGTYPE"); } else { def = NewString("p.f(ANY).SWIGTYPE"); @@ -463,17 +473,17 @@ SwigType *SwigType_default(SwigType *t) { } else { def = NewString("SWIGTYPE"); } - if (r != t) Delete(r); - if (StringEqual(def,t)) { + if (r != t) + Delete(r); + if (StringEqual(def, t)) { Delete(def); def = 0; } - #ifdef SWIG_DEFAULT_CACHE /* The cache produces strange results, see enum_template.i case */ if (def) { - String *cdef = Copy(def); - Setattr(default_cache,t, cdef); + String *cdef = Copy(def); + Setattr(default_cache, t, cdef); Delete(cdef); } #endif @@ -489,35 +499,38 @@ SwigType *SwigType_default(SwigType *t) { * Returns a string of the base type. Takes care of template expansions * ----------------------------------------------------------------------------- */ -String * -SwigType_namestr(const SwigType *t) { +String *SwigType_namestr(const SwigType *t) { String *r; String *suffix; - List *p; - int i, sz; - char *d = Char(t); - char *c = strstr(d,"<("); + List *p; + int i, sz; + char *d = Char(t); + char *c = strstr(d, "<("); - if (!c || !strstr(c+2,")>")) return NewString(t); + if (!c || !strstr(c + 2, ")>")) + return NewString(t); r = NewStringWithSize(d, c - d); - if (*(c - 1) == '<') Putc(' ',r); - Putc('<',r); - - p = SwigType_parmlist(c+1); + if (*(c - 1) == '<') + Putc(' ', r); + Putc('<', r); + + p = SwigType_parmlist(c + 1); sz = Len(p); for (i = 0; i < sz; i++) { - String *str = SwigType_str(Getitem(p,i),0); + String *str = SwigType_str(Getitem(p, i), 0); /* Avoid creating a <: token, which is the same as [ in C++. */ - if (i == 0 && Len(str) && *Char(str) == ':') Putc(' ', r); - StringAppend(r,str); - if ((i+1) < sz) Putc(',',r); + if (i == 0 && Len(str) && *Char(str) == ':') + Putc(' ', r); + StringAppend(r, str); + if ((i + 1) < sz) + Putc(',', r); Delete(str); } - Putc(' ',r); - Putc('>',r); + Putc(' ', r); + Putc('>', r); suffix = SwigType_templatesuffix(t); - StringAppend(r,suffix); + StringAppend(r, suffix); Delete(suffix); Delete(p); return r; @@ -529,9 +542,7 @@ SwigType_namestr(const SwigType *t) { * Create a C string representation of a datatype. * ----------------------------------------------------------------------------- */ -String * -SwigType_str(SwigType *s, const String_or_char *id) -{ +String *SwigType_str(SwigType *s, const String_or_char *id) { String *result; String *element = 0, *nextelement; List *elements; @@ -547,71 +558,71 @@ SwigType_str(SwigType *s, const String_or_char *id) nelements = Len(elements); if (nelements > 0) { - element = Getitem(elements,0); + element = Getitem(elements, 0); } /* Now, walk the type list and start emitting */ for (i = 0; i < nelements; i++) { if (i < (nelements - 1)) { - nextelement = Getitem(elements,i+1); + nextelement = Getitem(elements, i + 1); } else { nextelement = 0; } if (SwigType_isqualifier(element)) { DOH *q = 0; q = SwigType_parm(element); - Insert(result,0," "); - Insert(result,0,q); + Insert(result, 0, " "); + Insert(result, 0, q); Delete(q); } else if (SwigType_ispointer(element)) { - Insert(result,0,"*"); + Insert(result, 0, "*"); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); + Insert(result, 0, "("); + StringAppend(result, ")"); } } else if (SwigType_ismemberpointer(element)) { String *q; q = SwigType_parm(element); - Insert(result,0,"::*"); - Insert(result,0,q); + Insert(result, 0, "::*"); + Insert(result, 0, q); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); + Insert(result, 0, "("); + StringAppend(result, ")"); } Delete(q); - } - else if (SwigType_isreference(element)) { - Insert(result,0,"&"); + } else if (SwigType_isreference(element)) { + Insert(result, 0, "&"); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); + Insert(result, 0, "("); + StringAppend(result, ")"); } - } else if (SwigType_isarray(element)) { + } else if (SwigType_isarray(element)) { DOH *size; - StringAppend(result,"["); + StringAppend(result, "["); size = SwigType_parm(element); - StringAppend(result,size); - StringAppend(result,"]"); + StringAppend(result, size); + StringAppend(result, "]"); Delete(size); } else if (SwigType_isfunction(element)) { DOH *parms, *p; int j, plen; - StringAppend(result,"("); + StringAppend(result, "("); parms = SwigType_parmlist(element); plen = Len(parms); for (j = 0; j < plen; j++) { - p = SwigType_str(Getitem(parms,j),0); - StringAppend(result,p); - if (j < (plen-1)) StringAppend(result,","); + p = SwigType_str(Getitem(parms, j), 0); + StringAppend(result, p); + if (j < (plen - 1)) + StringAppend(result, ","); } - StringAppend(result,")"); + StringAppend(result, ")"); Delete(parms); } else { - if (strcmp(Char(element),"v(...)") == 0) { - Insert(result,0,"..."); + if (strcmp(Char(element), "v(...)") == 0) { + Insert(result, 0, "..."); } else { String *bs = SwigType_namestr(element); - Insert(result,0," "); - Insert(result,0,bs); + Insert(result, 0, " "); + Insert(result, 0, bs); Delete(bs); } } @@ -628,8 +639,7 @@ SwigType_str(SwigType *s, const String_or_char *id) * Create a locally assignable type * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_ltype(SwigType *s) { +SwigType *SwigType_ltype(SwigType *s) { String *result; String *element; SwigType *td, *tc = 0; @@ -646,9 +656,9 @@ SwigType_ltype(SwigType *s) { } if (SwigType_issimple(tc)) { /* Resolve any typedef definitions */ - SwigType *tt = Copy(tc); + SwigType *tt = Copy(tc); td = 0; - while ((td = SwigType_typedef_resolve(tt))) { + while ((td = SwigType_typedef_resolve(tt))) { if (td && (SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) { /* We need to use the typedef type */ Delete(tt); @@ -661,7 +671,7 @@ SwigType_ltype(SwigType *s) { } if (td) { Delete(tc); - tc = td; + tc = td; } } elements = SwigType_split(tc); @@ -669,7 +679,7 @@ SwigType_ltype(SwigType *s) { /* Now, walk the type list and start emitting */ for (i = 0; i < nelements; i++) { - element = Getitem(elements,i); + element = Getitem(elements, i); /* when we see a function, we need to preserve the following types */ if (SwigType_isfunction(element)) { notypeconv = 1; @@ -677,34 +687,34 @@ SwigType_ltype(SwigType *s) { if (SwigType_isqualifier(element)) { /* Do nothing. Ignore */ } else if (SwigType_ispointer(element)) { - StringAppend(result,element); + StringAppend(result, element); firstarray = 0; } else if (SwigType_ismemberpointer(element)) { - StringAppend(result,element); + StringAppend(result, element); firstarray = 0; } else if (SwigType_isreference(element)) { if (notypeconv) { - StringAppend(result,element); + StringAppend(result, element); } else { - StringAppend(result,"p."); + StringAppend(result, "p."); } firstarray = 0; } else if (SwigType_isarray(element) && firstarray) { if (notypeconv) { - StringAppend(result,element); + StringAppend(result, element); } else { - StringAppend(result,"p."); + StringAppend(result, "p."); } firstarray = 0; } else if (SwigType_isenum(element)) { - int anonymous_enum = (Cmp(element,"enum ") == 0); + int anonymous_enum = (Cmp(element, "enum ") == 0); if (notypeconv || !anonymous_enum) { - StringAppend(result,element); + StringAppend(result, element); } else { - StringAppend(result,"int"); + StringAppend(result, "int"); } } else { - StringAppend(result,element); + StringAppend(result, element); } } Delete(elements); @@ -727,14 +737,12 @@ SwigType_ltype(SwigType *s) { * with an equivalent assignable version. * -------------------------------------------------------------------- */ -String * -SwigType_lstr(SwigType *s, const String_or_char *id) -{ +String *SwigType_lstr(SwigType *s, const String_or_char *id) { String *result; - SwigType *tc; + SwigType *tc; tc = SwigType_ltype(s); - result = SwigType_str(tc,id); + result = SwigType_str(tc, id); Delete(tc); return result; } @@ -751,11 +759,11 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) { String *element = 0, *nextelement; SwigType *td, *rs, *tc = 0; List *elements; - int nelements, i; - int clear = 1; - int firstarray = 1; - int isreference = 0; - int isarray = 0; + int nelements, i; + int clear = 1; + int firstarray = 1; + int isreference = 0; + int isarray = 0; result = NewStringEmpty(); @@ -772,70 +780,70 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) { } else { td = SwigType_typedef_resolve(rs); } - + if (td) { if ((SwigType_isconst(td) || SwigType_isarray(td) || SwigType_isreference(td))) { elements = SwigType_split(td); } else { elements = SwigType_split(rs); - } + } Delete(td); } else { elements = SwigType_split(rs); } nelements = Len(elements); if (nelements > 0) { - element = Getitem(elements,0); + element = Getitem(elements, 0); } /* Now, walk the type list and start emitting */ for (i = 0; i < nelements; i++) { if (i < (nelements - 1)) { - nextelement = Getitem(elements,i+1); + nextelement = Getitem(elements, i + 1); } else { nextelement = 0; } if (SwigType_isqualifier(element)) { DOH *q = 0; q = SwigType_parm(element); - Insert(result,0," "); - Insert(result,0,q); + Insert(result, 0, " "); + Insert(result, 0, q); Delete(q); clear = 0; } else if (SwigType_ispointer(element)) { - Insert(result,0,"*"); + Insert(result, 0, "*"); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); + Insert(result, 0, "("); + StringAppend(result, ")"); } firstarray = 0; - } else if (SwigType_ismemberpointer(element)) { + } else if (SwigType_ismemberpointer(element)) { String *q; - Insert(result,0,"::*"); + Insert(result, 0, "::*"); q = SwigType_parm(element); - Insert(result,0,q); + Insert(result, 0, q); Delete(q); if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); + Insert(result, 0, "("); + StringAppend(result, ")"); } firstarray = 0; } else if (SwigType_isreference(element)) { - Insert(result,0,"&"); - if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { - Insert(result,0,"("); - StringAppend(result,")"); - } - isreference = 1; + Insert(result, 0, "&"); + if ((nextelement) && ((SwigType_isfunction(nextelement) || (SwigType_isarray(nextelement))))) { + Insert(result, 0, "("); + StringAppend(result, ")"); + } + isreference = 1; } else if (SwigType_isarray(element)) { DOH *size; if (firstarray && !isreference) { - StringAppend(result,"(*)"); + StringAppend(result, "(*)"); firstarray = 0; } else { - StringAppend(result,"["); + StringAppend(result, "["); size = SwigType_parm(element); - StringAppend(result,size); - StringAppend(result,"]"); + StringAppend(result, size); + StringAppend(result, "]"); Delete(size); clear = 0; } @@ -843,21 +851,22 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) { } else if (SwigType_isfunction(element)) { DOH *parms, *p; int j, plen; - StringAppend(result,"("); + StringAppend(result, "("); parms = SwigType_parmlist(element); plen = Len(parms); for (j = 0; j < plen; j++) { - p = SwigType_str(Getitem(parms,j),0); - StringAppend(result,p); + p = SwigType_str(Getitem(parms, j), 0); + StringAppend(result, p); Delete(p); - if (j < (plen-1)) StringAppend(result,","); + if (j < (plen - 1)) + StringAppend(result, ","); } - StringAppend(result,")"); + StringAppend(result, ")"); Delete(parms); } else { String *bs = SwigType_namestr(element); - Insert(result,0," "); - Insert(result,0,bs); + Insert(result, 0, " "); + Insert(result, 0, bs); Delete(bs); } element = nextelement; @@ -866,14 +875,15 @@ String *SwigType_rcaststr(SwigType *s, const String_or_char *name) { if (clear) { cast = NewStringEmpty(); } else { - cast = NewStringf("(%s)",result); + cast = NewStringf("(%s)", result); } if (name) { if (isreference) { - if (isarray) Clear(cast); - StringAppend(cast,"*"); + if (isarray) + Clear(cast); + StringAppend(cast, "*"); } - StringAppend(cast,name); + StringAppend(cast, name); } Delete(result); Delete(tc); @@ -893,22 +903,22 @@ String *SwigType_lcaststr(SwigType *s, const String_or_char *name) { result = NewStringEmpty(); if (SwigType_isarray(s)) { - String *lstr = SwigType_lstr(s,0); - Printf(result,"(%s)%s", lstr,name); + String *lstr = SwigType_lstr(s, 0); + Printf(result, "(%s)%s", lstr, name); Delete(lstr); } else if (SwigType_isreference(s)) { - String *str = SwigType_str(s,0); - Printf(result,"(%s)", str); + String *str = SwigType_str(s, 0); + Printf(result, "(%s)", str); Delete(str); - if (name) - StringAppend(result,name); + if (name) + StringAppend(result, name); } else if (SwigType_isqualifier(s)) { - String *lstr = SwigType_lstr(s,0); - Printf(result,"(%s)%s", lstr,name); + String *lstr = SwigType_lstr(s, 0); + Printf(result, "(%s)%s", lstr, name); Delete(lstr); } else { if (name) - StringAppend(result,name); + StringAppend(result, name); } return result; } @@ -922,11 +932,11 @@ String *SwigType_manglestr_default(SwigType *s) { SwigType *lt; SwigType *sr = SwigType_typedef_qualified(s); SwigType *ss = SwigType_typedef_resolve_all(sr); - + s = ss; if (SwigType_istemplate(ss)) { - SwigType *ty = Swig_symbol_template_deftype(ss,0); + SwigType *ty = Swig_symbol_template_deftype(ss, 0); Delete(ss); ss = ty; s = ss; @@ -939,7 +949,8 @@ String *SwigType_manglestr_default(SwigType *s) { c = Char(result); while (*c) { - if (!isalnum((int)*c)) *c = '_'; + if (!isalnum((int) *c)) + *c = '_'; c++; } if (SwigType_istemplate(base)) { @@ -948,29 +959,39 @@ String *SwigType_manglestr_default(SwigType *s) { base = b; } - Replace(base,"struct ","", DOH_REPLACE_ANY); /* This might be problematic */ - Replace(base,"class ","", DOH_REPLACE_ANY); - Replace(base,"union ","", DOH_REPLACE_ANY); - Replace(base,"enum ","", DOH_REPLACE_ANY); + Replace(base, "struct ", "", DOH_REPLACE_ANY); /* This might be problematic */ + Replace(base, "class ", "", DOH_REPLACE_ANY); + Replace(base, "union ", "", DOH_REPLACE_ANY); + Replace(base, "enum ", "", DOH_REPLACE_ANY); c = Char(base); while (*c) { - if (*c == '<') *c = 'T'; - else if (*c == '>') *c = 't'; - else if (*c == '*') *c = 'p'; - else if (*c == '[') *c = 'a'; - else if (*c == ']') *c = 'A'; - else if (*c == '&') *c = 'R'; - else if (*c == '(') *c = 'f'; - else if (*c == ')') *c = 'F'; - else if (!isalnum((int)*c)) *c = '_'; + if (*c == '<') + *c = 'T'; + else if (*c == '>') + *c = 't'; + else if (*c == '*') + *c = 'p'; + else if (*c == '[') + *c = 'a'; + else if (*c == ']') + *c = 'A'; + else if (*c == '&') + *c = 'R'; + else if (*c == '(') + *c = 'f'; + else if (*c == ')') + *c = 'F'; + else if (!isalnum((int) *c)) + *c = '_'; c++; } - StringAppend(result,base); - Insert(result,0,"_"); + StringAppend(result, base); + Insert(result, 0, "_"); Delete(lt); Delete(base); - if (ss) Delete(ss); + if (ss) + Delete(ss); return result; } @@ -984,51 +1005,52 @@ String *SwigType_manglestr(SwigType *s) { * Replaces a typename in a type with something else. Needed for templates. * ----------------------------------------------------------------------------- */ -void -SwigType_typename_replace(SwigType *t, String *pat, String *rep) { +void SwigType_typename_replace(SwigType *t, String *pat, String *rep) { String *nt; - int i, ilen; - List *elem; + int i, ilen; + List *elem; - if (!Strstr(t,pat)) return; + if (!Strstr(t, pat)) + return; - if (StringEqual(t,pat)) { - Replace(t,pat,rep,DOH_REPLACE_ANY); + if (StringEqual(t, pat)) { + Replace(t, pat, rep, DOH_REPLACE_ANY); return; } nt = NewStringEmpty(); elem = SwigType_split(t); ilen = Len(elem); for (i = 0; i < ilen; i++) { - String *e = Getitem(elem,i); + String *e = Getitem(elem, i); if (SwigType_issimple(e)) { - if (StringEqual(e,pat)) { + if (StringEqual(e, pat)) { /* Replaces a type of the form 'pat' with 'rep' */ - Replace(e,pat,rep,DOH_REPLACE_ANY); + Replace(e, pat, rep, DOH_REPLACE_ANY); } else if (SwigType_istemplate(e)) { - /* Replaces a type of the form 'pat' with 'rep' */ - if (StringEqual(e,pat)) { + /* Replaces a type of the form 'pat' with 'rep' */ + if (StringEqual(e, pat)) { String *repbase = SwigType_templateprefix(rep); - Replace(e,pat,repbase,DOH_REPLACE_ID | DOH_REPLACE_FIRST); + Replace(e, pat, repbase, DOH_REPLACE_ID | DOH_REPLACE_FIRST); Delete(repbase); - } + } { String *tsuffix; List *tparms = SwigType_parmlist(e); int j, jlen; String *nt = SwigType_templateprefix(e); - StringAppend(nt,"<("); + StringAppend(nt, "<("); jlen = Len(tparms); for (j = 0; j < jlen; j++) { - SwigType_typename_replace(Getitem(tparms,j), pat, rep); - StringAppend(nt,Getitem(tparms,j)); - if (j < (jlen-1)) Putc(',',nt); + SwigType_typename_replace(Getitem(tparms, j), pat, rep); + StringAppend(nt, Getitem(tparms, j)); + if (j < (jlen - 1)) + Putc(',', nt); } tsuffix = SwigType_templatesuffix(e); - Printf(nt,")>%s", tsuffix); + Printf(nt, ")>%s", tsuffix); Delete(tsuffix); Clear(e); - StringAppend(e,nt); + StringAppend(e, nt); Delete(nt); Delete(tparms); } @@ -1036,10 +1058,10 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) { String *first, *rest; first = Swig_scopename_first(e); rest = Swig_scopename_suffix(e); - SwigType_typename_replace(rest,pat,rep); - SwigType_typename_replace(first,pat,rep); + SwigType_typename_replace(rest, pat, rep); + SwigType_typename_replace(first, pat, rep); Clear(e); - Printv(e,first,"::",rest,NIL); + Printv(e, first, "::", rest, NIL); Delete(first); Delete(rest); } @@ -1047,22 +1069,23 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) { int j, jlen; List *fparms = SwigType_parmlist(e); Clear(e); - StringAppend(e,"f("); + StringAppend(e, "f("); jlen = Len(fparms); for (j = 0; j < jlen; j++) { - SwigType_typename_replace(Getitem(fparms,j), pat, rep); - StringAppend(e,Getitem(fparms,j)); - if (j < (jlen-1)) Putc(',',e); + SwigType_typename_replace(Getitem(fparms, j), pat, rep); + StringAppend(e, Getitem(fparms, j)); + if (j < (jlen - 1)) + Putc(',', e); } - StringAppend(e,")."); + StringAppend(e, ")."); Delete(fparms); } else if (SwigType_isarray(e)) { - Replace(e,pat,rep, DOH_REPLACE_ID); + Replace(e, pat, rep, DOH_REPLACE_ID); } - StringAppend(nt,e); + StringAppend(nt, e); } Clear(t); - StringAppend(t,nt); + StringAppend(t, nt); Delete(nt); Delete(elem); } @@ -1073,14 +1096,13 @@ SwigType_typename_replace(SwigType *t, String *pat, String *rep) { * Checks type declarators for a match * ----------------------------------------------------------------------------- */ -int -SwigType_check_decl(SwigType *ty, const SwigType *decl) { - SwigType *t,*t1,*t2; +int SwigType_check_decl(SwigType *ty, const SwigType *decl) { + SwigType *t, *t1, *t2; int r; t = SwigType_typedef_resolve_all(ty); t1 = SwigType_strip_qualifiers(t); t2 = SwigType_prefix(t1); - r = Equal(t2,decl); + r = Equal(t2, decl); Delete(t); Delete(t1); Delete(t2); diff --git a/SWIG/Source/Swig/swig.h b/SWIG/Source/Swig/swig.h index 53266b7cc..d6ab58c0e 100644 --- a/SWIG/Source/Swig/swig.h +++ b/SWIG/Source/Swig/swig.h @@ -35,17 +35,17 @@ extern "C" { /* Short names for common data types */ -typedef DOH String; -typedef DOH Hash; -typedef DOH List; -typedef DOH String_or_char; -typedef DOH File; -typedef DOH Parm; -typedef DOH ParmList; -typedef DOH Node; -typedef DOH Symtab; -typedef DOH Typetab; -typedef DOH SwigType; + typedef DOH String; + typedef DOH Hash; + typedef DOH List; + typedef DOH String_or_char; + typedef DOH File; + typedef DOH Parm; + typedef DOH ParmList; + typedef DOH Node; + typedef DOH Symtab; + typedef DOH Typetab; + typedef DOH SwigType; /* --- Legacy DataType interface. These type codes are provided solely for backwards compatibility with older modules --- */ @@ -94,28 +94,28 @@ typedef DOH SwigType; /* --- File interface --- */ -extern List *Swig_add_directory(const String_or_char *dirname); -extern void Swig_push_directory(const String_or_char *dirname); -extern void Swig_pop_directory(); -extern String *Swig_last_file(); -extern List *Swig_search_path(); -extern FILE *Swig_open(const String_or_char *name); -extern String *Swig_read_file(FILE *f); -extern String *Swig_include(const String_or_char *name); -extern String *Swig_include_sys(const String_or_char *name); -extern int Swig_insert_file(const String_or_char *name, File *outfile); -extern void Swig_set_config_file(const String_or_char *filename); -extern String *Swig_get_config_file(void); -extern void Swig_set_push_dir(int dopush); -extern int Swig_get_push_dir(void); -extern void Swig_swiglib_set(const String_or_char *); -extern String *Swig_swiglib_get(); -extern void Swig_register_filebyname(const String_or_char *filename, File *outfile); -extern File *Swig_filebyname(const String_or_char *filename); -extern char *Swig_file_suffix(const String_or_char *filename); -extern char *Swig_file_basename(const String_or_char *filename); -extern char *Swig_file_filename(const String_or_char *filename); -extern char *Swig_file_dirname(const String_or_char *filename); + extern List *Swig_add_directory(const String_or_char *dirname); + extern void Swig_push_directory(const String_or_char *dirname); + extern void Swig_pop_directory(); + extern String *Swig_last_file(); + extern List *Swig_search_path(); + extern FILE *Swig_open(const String_or_char *name); + extern String *Swig_read_file(FILE *f); + extern String *Swig_include(const String_or_char *name); + extern String *Swig_include_sys(const String_or_char *name); + extern int Swig_insert_file(const String_or_char *name, File *outfile); + extern void Swig_set_config_file(const String_or_char *filename); + extern String *Swig_get_config_file(void); + extern void Swig_set_push_dir(int dopush); + extern int Swig_get_push_dir(void); + extern void Swig_swiglib_set(const String_or_char *); + extern String *Swig_swiglib_get(); + extern void Swig_register_filebyname(const String_or_char *filename, File *outfile); + extern File *Swig_filebyname(const String_or_char *filename); + extern char *Swig_file_suffix(const String_or_char *filename); + extern char *Swig_file_basename(const String_or_char *filename); + extern char *Swig_file_filename(const String_or_char *filename); + extern char *Swig_file_dirname(const String_or_char *filename); #if defined(MACSWIG) # define SWIG_FILE_DELIMETER ":" @@ -127,32 +127,32 @@ extern char *Swig_file_dirname(const String_or_char *filename); /* --- Command line parsing --- */ -extern void Swig_init_args(int argc, char **argv); -extern void Swig_mark_arg(int n); -extern int Swig_check_marked(int n); -extern void Swig_check_options(int check_input); -extern void Swig_arg_error(); + extern void Swig_init_args(int argc, char **argv); + extern void Swig_mark_arg(int n); + extern int Swig_check_marked(int n); + extern void Swig_check_options(int check_input); + extern void Swig_arg_error(); /* --- Scanner Interface --- */ -typedef struct SwigScanner SwigScanner; + typedef struct SwigScanner SwigScanner; -extern SwigScanner *NewSwigScanner(); -extern void DelSwigScanner(SwigScanner *); -extern void SwigScanner_clear(SwigScanner *); -extern void SwigScanner_push(SwigScanner *, String *); -extern void SwigScanner_pushtoken(SwigScanner *, int); -extern int SwigScanner_token(SwigScanner *); -extern String *SwigScanner_text(SwigScanner *); -extern void SwigScanner_skip_line(SwigScanner *); -extern int SwigScanner_skip_balanced(SwigScanner *, int startchar, int endchar); -extern void SwigScanner_set_location(SwigScanner *, String *file, int line); -extern String *SwigScanner_get_file(SwigScanner *); -extern int SwigScanner_get_line(SwigScanner *); -extern void SwigScanner_idstart(SwigScanner *, char *idchar); + extern SwigScanner *NewSwigScanner(); + extern void DelSwigScanner(SwigScanner *); + extern void SwigScanner_clear(SwigScanner *); + extern void SwigScanner_push(SwigScanner *, String *); + extern void SwigScanner_pushtoken(SwigScanner *, int); + extern int SwigScanner_token(SwigScanner *); + extern String *SwigScanner_text(SwigScanner *); + extern void SwigScanner_skip_line(SwigScanner *); + extern int SwigScanner_skip_balanced(SwigScanner *, int startchar, int endchar); + extern void SwigScanner_set_location(SwigScanner *, String *file, int line); + extern String *SwigScanner_get_file(SwigScanner *); + extern int SwigScanner_get_line(SwigScanner *); + extern void SwigScanner_idstart(SwigScanner *, char *idchar); #define SWIG_MAXTOKENS 512 -#define SWIG_TOKEN_LPAREN 1 +#define SWIG_TOKEN_LPAREN 1 #define SWIG_TOKEN_RPAREN 2 #define SWIG_TOKEN_SEMI 3 #define SWIG_TOKEN_COMMA 4 @@ -203,146 +203,146 @@ extern void SwigScanner_idstart(SwigScanner *, char *idchar); #define SWIG_TOKEN_LONGLONG 49 #define SWIG_TOKEN_ULONGLONG 50 #define SWIG_TOKEN_ILLEGAL 98 -#define SWIG_TOKEN_LAST 99 +#define SWIG_TOKEN_LAST 99 /* --- Functions for manipulating the string-based type encoding --- */ -extern SwigType *NewSwigType(int typecode); -extern SwigType *SwigType_del_element(SwigType *t); -extern SwigType *SwigType_add_pointer(SwigType *t); -extern SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *qual); -extern SwigType *SwigType_del_pointer(SwigType *t); -extern SwigType *SwigType_add_array(SwigType *t, const String_or_char *size); -extern SwigType *SwigType_del_array(SwigType *t); -extern SwigType *SwigType_pop_arrays(SwigType *t); -extern SwigType *SwigType_add_reference(SwigType *t); -extern SwigType *SwigType_del_reference(SwigType *t); -extern SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual); -extern SwigType *SwigType_del_qualifier(SwigType *t); -extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms); -extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms); -extern SwigType *SwigType_pop_function(SwigType *t); -extern ParmList *SwigType_function_parms(SwigType *t); -extern List *SwigType_split(const SwigType *t); -extern String *SwigType_pop(SwigType *t); -extern void SwigType_push(SwigType *t, SwigType *s); -extern List *SwigType_parmlist(const SwigType *p); -extern String *SwigType_parm(String *p); -extern String *SwigType_str(SwigType *s, const String_or_char *id); -extern String *SwigType_lstr(SwigType *s, const String_or_char *id); -extern String *SwigType_rcaststr(SwigType *s, const String_or_char *id); -extern String *SwigType_lcaststr(SwigType *s, const String_or_char *id); -extern String *SwigType_manglestr(SwigType *t); -extern SwigType *SwigType_ltype(SwigType *t); -extern int SwigType_ispointer(SwigType *t); -extern int SwigType_ispointer_return(SwigType *t); -extern int SwigType_ismemberpointer(SwigType *t); -extern int SwigType_isreference(SwigType *t); -extern int SwigType_isreference_return(SwigType *t); -extern int SwigType_isarray(SwigType *t); -extern int SwigType_isfunction(SwigType *t); -extern int SwigType_isqualifier(SwigType *t); -extern int SwigType_isconst(SwigType *t); -extern int SwigType_issimple(SwigType *t); -extern int SwigType_ismutable(SwigType *t); -extern int SwigType_isvarargs(const SwigType *t); -extern int SwigType_istemplate(const SwigType *t); -extern int SwigType_isenum(SwigType *t); -extern int SwigType_check_decl(SwigType *t, const String_or_char *decl); -extern SwigType *SwigType_strip_qualifiers(SwigType *t); -extern String *SwigType_base(const SwigType *t); -extern String *SwigType_namestr(const SwigType *t); -extern String *SwigType_templateprefix(const SwigType *t); -extern String *SwigType_templatesuffix(const SwigType *t); -extern String *SwigType_templateargs(const SwigType *t); -extern String *SwigType_prefix(const SwigType *t); -extern int SwigType_array_ndim(SwigType *t); -extern String *SwigType_array_getdim(SwigType *t, int n); -extern void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep); -extern SwigType *SwigType_array_type(SwigType *t); -extern String *SwigType_default(SwigType *t); -extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep); -extern SwigType *SwigType_alttype(SwigType *t, int ltmap); + extern SwigType *NewSwigType(int typecode); + extern SwigType *SwigType_del_element(SwigType *t); + extern SwigType *SwigType_add_pointer(SwigType *t); + extern SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *qual); + extern SwigType *SwigType_del_pointer(SwigType *t); + extern SwigType *SwigType_add_array(SwigType *t, const String_or_char *size); + extern SwigType *SwigType_del_array(SwigType *t); + extern SwigType *SwigType_pop_arrays(SwigType *t); + extern SwigType *SwigType_add_reference(SwigType *t); + extern SwigType *SwigType_del_reference(SwigType *t); + extern SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual); + extern SwigType *SwigType_del_qualifier(SwigType *t); + extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms); + extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms); + extern SwigType *SwigType_pop_function(SwigType *t); + extern ParmList *SwigType_function_parms(SwigType *t); + extern List *SwigType_split(const SwigType *t); + extern String *SwigType_pop(SwigType *t); + extern void SwigType_push(SwigType *t, SwigType *s); + extern List *SwigType_parmlist(const SwigType *p); + extern String *SwigType_parm(String *p); + extern String *SwigType_str(SwigType *s, const String_or_char *id); + extern String *SwigType_lstr(SwigType *s, const String_or_char *id); + extern String *SwigType_rcaststr(SwigType *s, const String_or_char *id); + extern String *SwigType_lcaststr(SwigType *s, const String_or_char *id); + extern String *SwigType_manglestr(SwigType *t); + extern SwigType *SwigType_ltype(SwigType *t); + extern int SwigType_ispointer(SwigType *t); + extern int SwigType_ispointer_return(SwigType *t); + extern int SwigType_ismemberpointer(SwigType *t); + extern int SwigType_isreference(SwigType *t); + extern int SwigType_isreference_return(SwigType *t); + extern int SwigType_isarray(SwigType *t); + extern int SwigType_isfunction(SwigType *t); + extern int SwigType_isqualifier(SwigType *t); + extern int SwigType_isconst(SwigType *t); + extern int SwigType_issimple(SwigType *t); + extern int SwigType_ismutable(SwigType *t); + extern int SwigType_isvarargs(const SwigType *t); + extern int SwigType_istemplate(const SwigType *t); + extern int SwigType_isenum(SwigType *t); + extern int SwigType_check_decl(SwigType *t, const String_or_char *decl); + extern SwigType *SwigType_strip_qualifiers(SwigType *t); + extern String *SwigType_base(const SwigType *t); + extern String *SwigType_namestr(const SwigType *t); + extern String *SwigType_templateprefix(const SwigType *t); + extern String *SwigType_templatesuffix(const SwigType *t); + extern String *SwigType_templateargs(const SwigType *t); + extern String *SwigType_prefix(const SwigType *t); + extern int SwigType_array_ndim(SwigType *t); + extern String *SwigType_array_getdim(SwigType *t, int n); + extern void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep); + extern SwigType *SwigType_array_type(SwigType *t); + extern String *SwigType_default(SwigType *t); + extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep); + extern SwigType *SwigType_alttype(SwigType *t, int ltmap); -extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl); -extern SwigType* SwigType_template_deftype(const SwigType *type, Symtab *tscope); + extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl); + extern SwigType *SwigType_template_deftype(const SwigType *type, Symtab *tscope); /* --- Type-system managment --- */ -extern void SwigType_typesystem_init(); -extern int SwigType_typedef(SwigType *type, String_or_char *name); -extern int SwigType_typedef_class(String_or_char *name); -extern int SwigType_typedef_using(String_or_char *qname); -extern void SwigType_inherit(String *subclass, String *baseclass, String *cast); -extern int SwigType_issubtype(SwigType *subtype, SwigType *basetype); -extern void SwigType_scope_alias(String *aliasname, Typetab *t); -extern void SwigType_using_scope(Typetab *t); -extern void SwigType_new_scope(const String_or_char *name); -extern void SwigType_inherit_scope(Typetab *scope); -extern Typetab *SwigType_pop_scope(); -extern Typetab *SwigType_set_scope(Typetab *h); -extern void SwigType_print_scope(Typetab *t); -extern SwigType *SwigType_typedef_resolve(SwigType *t); -extern SwigType *SwigType_typedef_resolve_all(SwigType *t); -extern SwigType *SwigType_typedef_qualified(SwigType *t); -extern int SwigType_istypedef(SwigType *t); -extern int SwigType_isclass(SwigType *t); -extern void SwigType_attach_symtab(Symtab *syms); -extern void SwigType_remember(SwigType *t); -extern void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata); -extern void SwigType_remember_mangleddata(String *mangled, const String_or_char *clientdata); -extern void (*SwigType_remember_trace(void (*tf)(SwigType *, String *, String *)))(SwigType *, String *, String *); -extern void SwigType_emit_type_table(File *f_headers, File *f_table); -extern int SwigType_type(SwigType *t); + extern void SwigType_typesystem_init(); + extern int SwigType_typedef(SwigType *type, String_or_char *name); + extern int SwigType_typedef_class(String_or_char *name); + extern int SwigType_typedef_using(String_or_char *qname); + extern void SwigType_inherit(String *subclass, String *baseclass, String *cast); + extern int SwigType_issubtype(SwigType *subtype, SwigType *basetype); + extern void SwigType_scope_alias(String *aliasname, Typetab *t); + extern void SwigType_using_scope(Typetab *t); + extern void SwigType_new_scope(const String_or_char *name); + extern void SwigType_inherit_scope(Typetab *scope); + extern Typetab *SwigType_pop_scope(); + extern Typetab *SwigType_set_scope(Typetab *h); + extern void SwigType_print_scope(Typetab *t); + extern SwigType *SwigType_typedef_resolve(SwigType *t); + extern SwigType *SwigType_typedef_resolve_all(SwigType *t); + extern SwigType *SwigType_typedef_qualified(SwigType *t); + extern int SwigType_istypedef(SwigType *t); + extern int SwigType_isclass(SwigType *t); + extern void SwigType_attach_symtab(Symtab *syms); + extern void SwigType_remember(SwigType *t); + extern void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata); + extern void SwigType_remember_mangleddata(String *mangled, const String_or_char *clientdata); + extern void (*SwigType_remember_trace(void (*tf) (SwigType *, String *, String *))) (SwigType *, String *, String *); + extern void SwigType_emit_type_table(File *f_headers, File *f_table); + extern int SwigType_type(SwigType *t); /* --- Symbol table module --- */ -extern void Swig_symbol_init(); -extern void Swig_symbol_setscopename(const String_or_char *name); -extern String *Swig_symbol_getscopename(); -extern String *Swig_symbol_qualifiedscopename(Symtab *symtab); -extern Symtab *Swig_symbol_newscope(); -extern Symtab *Swig_symbol_setscope(Symtab *); -extern Symtab *Swig_symbol_getscope(const String_or_char *symname); -extern Symtab *Swig_symbol_current(); -extern Symtab *Swig_symbol_popscope(); -extern Node *Swig_symbol_add(String_or_char *symname, Node *node); -extern void Swig_symbol_cadd(String_or_char *symname, Node *node); -extern Node *Swig_symbol_clookup(String_or_char *symname, Symtab *tab); -extern Node *Swig_symbol_clookup_check(String_or_char *symname, Symtab *tab, int (*check)(Node *)); -extern Symtab *Swig_symbol_cscope(String_or_char *symname, Symtab *tab); -extern Node *Swig_symbol_clookup_local(String_or_char *symname, Symtab *tab); -extern Node *Swig_symbol_clookup_local_check(String_or_char *symname, Symtab *tab, int (*check)(Node *)); -extern String *Swig_symbol_qualified(Node *node); -extern Node *Swig_symbol_isoverloaded(Node *node); -extern void Swig_symbol_remove(Node *node); -extern void Swig_symbol_alias(String_or_char *aliasname, Symtab *tab); -extern void Swig_symbol_inherit(Symtab *tab); -extern SwigType *Swig_symbol_type_qualify(const SwigType *ty, Symtab *tab); -extern String *Swig_symbol_string_qualify(String *s, Symtab *tab); -extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab); + extern void Swig_symbol_init(); + extern void Swig_symbol_setscopename(const String_or_char *name); + extern String *Swig_symbol_getscopename(); + extern String *Swig_symbol_qualifiedscopename(Symtab *symtab); + extern Symtab *Swig_symbol_newscope(); + extern Symtab *Swig_symbol_setscope(Symtab *); + extern Symtab *Swig_symbol_getscope(const String_or_char *symname); + extern Symtab *Swig_symbol_current(); + extern Symtab *Swig_symbol_popscope(); + extern Node *Swig_symbol_add(String_or_char *symname, Node *node); + extern void Swig_symbol_cadd(String_or_char *symname, Node *node); + extern Node *Swig_symbol_clookup(String_or_char *symname, Symtab *tab); + extern Node *Swig_symbol_clookup_check(String_or_char *symname, Symtab *tab, int (*check) (Node *)); + extern Symtab *Swig_symbol_cscope(String_or_char *symname, Symtab *tab); + extern Node *Swig_symbol_clookup_local(String_or_char *symname, Symtab *tab); + extern Node *Swig_symbol_clookup_local_check(String_or_char *symname, Symtab *tab, int (*check) (Node *)); + extern String *Swig_symbol_qualified(Node *node); + extern Node *Swig_symbol_isoverloaded(Node *node); + extern void Swig_symbol_remove(Node *node); + extern void Swig_symbol_alias(String_or_char *aliasname, Symtab *tab); + extern void Swig_symbol_inherit(Symtab *tab); + extern SwigType *Swig_symbol_type_qualify(const SwigType *ty, Symtab *tab); + extern String *Swig_symbol_string_qualify(String *s, Symtab *tab); + extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab); -extern void Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl); -extern SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope); -extern SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab); + extern void Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl); + extern SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope); + extern SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab); /* --- Parameters and Parameter Lists --- */ /* Parameters are really just hidden behind a DOH object. The following interface will probably be simplified even further. */ -extern Parm *NewParm(SwigType *type, const String_or_char *name); -extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n); -extern Parm *CopyParm(Parm *p); -extern ParmList *CopyParmList(ParmList *); -extern int ParmList_len(ParmList *); -extern int ParmList_numarg(ParmList *); -extern int ParmList_numrequired(ParmList *); -extern String *ParmList_str(ParmList *); -extern String *ParmList_str_defaultargs(ParmList *); -extern String *ParmList_protostr(ParmList *); -extern int ParmList_is_compactdefargs(ParmList *p); -extern int ParmList_has_defaultargs(ParmList *p); -extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p); + extern Parm *NewParm(SwigType *type, const String_or_char *name); + extern Parm *NewParmFromNode(SwigType *type, const String_or_char *name, Node *n); + extern Parm *CopyParm(Parm *p); + extern ParmList *CopyParmList(ParmList *); + extern int ParmList_len(ParmList *); + extern int ParmList_numarg(ParmList *); + extern int ParmList_numrequired(ParmList *); + extern String *ParmList_str(ParmList *); + extern String *ParmList_str_defaultargs(ParmList *); + extern String *ParmList_protostr(ParmList *); + extern int ParmList_is_compactdefargs(ParmList *p); + extern int ParmList_has_defaultargs(ParmList *p); + extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p); /* --- Parse tree support --- */ @@ -354,7 +354,7 @@ extern ParmList *ParmList_copy_all_except_last_parm(ParmList *p); #define nextSibling(x) Getattr(x,k_nextsibling) #define firstChild(x) Getattr(x,k_firstchild) #define lastChild(x) Getattr(x,k_lastchild) -extern int checkAttribute(Node *obj, const String_or_char *name, const String_or_char *value); + extern int checkAttribute(Node *obj, const String_or_char *name, const String_or_char *value); /* Macros to set up the DOM tree (mostly used by the parser) */ @@ -365,145 +365,142 @@ extern int checkAttribute(Node *obj, const String_or_char *name, const String_or #define set_firstChild(x,v) Setattr(x,"firstChild",v) #define set_lastChild(x,v) Setattr(x,"lastChild",v) -extern void appendChild(Node *node, Node *child); -extern void preppendChild(Node *node, Node *child); -extern void deleteNode(Node *node); -extern Node *copyNode(Node *node); + extern void appendChild(Node *node, Node *child); + extern void preppendChild(Node *node, Node *child); + extern void deleteNode(Node *node); + extern Node *copyNode(Node *node); -extern void Swig_tag_nodes(Node *node, const String_or_char *attrname, DOH *value); + extern void Swig_tag_nodes(Node *node, const String_or_char *attrname, DOH *value); -extern int Swig_require(const char *ns, Node *node, ...); -extern int Swig_save(const char *ns, Node *node,...); -extern void Swig_restore(Node *node); + extern int Swig_require(const char *ns, Node *node, ...); + extern int Swig_save(const char *ns, Node *node, ...); + extern void Swig_restore(Node *node); /* Debugging of parse trees */ -extern void Swig_print_tags(File *obj, Node *root); -extern void Swig_print_tree(Node *obj); -extern void Swig_print_node(Node *obj); + extern void Swig_print_tags(File *obj, Node *root); + extern void Swig_print_tree(Node *obj); + extern void Swig_print_node(Node *obj); -extern void Swig_print_xml(Node *obj, String* filename); + extern void Swig_print_xml(Node *obj, String *filename); /* -- Wrapper function Object */ -typedef struct { - Hash *localh; - String *def; - String *locals; - String *code; -} Wrapper; + typedef struct { + Hash *localh; + String *def; + String *locals; + String *code; + } Wrapper; -extern Wrapper *NewWrapper(); -extern void DelWrapper(Wrapper *w); -extern void Wrapper_compact_print_mode_set(int flag); -extern void Wrapper_pretty_print(String *str, File *f); -extern void Wrapper_compact_print(String *str, File *f); -extern void Wrapper_print(Wrapper *w, File *f); -extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); -extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...); -extern int Wrapper_check_local(Wrapper *w, const String_or_char *name); -extern char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); -extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...); + extern Wrapper *NewWrapper(); + extern void DelWrapper(Wrapper *w); + extern void Wrapper_compact_print_mode_set(int flag); + extern void Wrapper_pretty_print(String *str, File *f); + extern void Wrapper_compact_print(String *str, File *f); + extern void Wrapper_print(Wrapper *w, File *f); + extern int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); + extern int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...); + extern int Wrapper_check_local(Wrapper *w, const String_or_char *name); + extern char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl); + extern char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...); /* --- Naming functions --- */ -extern void Swig_name_register(const String_or_char *method, const String_or_char *format); -extern void Swig_name_unregister(const String_or_char *method); -extern String *Swig_name_mangle(const String_or_char *s); -extern String *Swig_name_wrapper(const String_or_char *fname); -extern String *Swig_name_member(const String_or_char *classname, const String_or_char *mname); -extern String *Swig_name_get(const String_or_char *vname); -extern String *Swig_name_set(const String_or_char *vname); -extern String *Swig_name_construct(const String_or_char *classname); -extern String *Swig_name_copyconstructor(const String_or_char *classname); -extern String *Swig_name_destroy(const String_or_char *classname); -extern String *Swig_name_disown(const String_or_char *classname); + extern void Swig_name_register(const String_or_char *method, const String_or_char *format); + extern void Swig_name_unregister(const String_or_char *method); + extern String *Swig_name_mangle(const String_or_char *s); + extern String *Swig_name_wrapper(const String_or_char *fname); + extern String *Swig_name_member(const String_or_char *classname, const String_or_char *mname); + extern String *Swig_name_get(const String_or_char *vname); + extern String *Swig_name_set(const String_or_char *vname); + extern String *Swig_name_construct(const String_or_char *classname); + extern String *Swig_name_copyconstructor(const String_or_char *classname); + extern String *Swig_name_destroy(const String_or_char *classname); + extern String *Swig_name_disown(const String_or_char *classname); -extern void Swig_naming_init(); -extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn); -extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name,SwigType *decl); -extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms); -extern void Swig_name_inherit(String *base, String *derived); -extern int Swig_need_protected(Node *n); -extern int Swig_need_name_warning(Node *n); -extern int Swig_need_redefined_warn(Node* a, Node* b, int InClass); + extern void Swig_naming_init(); + extern void Swig_name_namewarn_add(String *prefix, String *name, SwigType *decl, Hash *namewrn); + extern Hash *Swig_name_namewarn_get(Node *n, String *prefix, String *name, SwigType *decl); + extern void Swig_name_rename_add(String *prefix, String *name, SwigType *decl, Hash *namewrn, ParmList *declaratorparms); + extern void Swig_name_inherit(String *base, String *derived); + extern int Swig_need_protected(Node *n); + extern int Swig_need_name_warning(Node *n); + extern int Swig_need_redefined_warn(Node *a, Node *b, int InClass); -extern String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname); -extern String *Swig_name_warning(Node *n, String *prefix, String *name,SwigType *decl); + extern String *Swig_name_make(Node *n, String *prefix, String_or_char *cname, SwigType *decl, String *oldname); + extern String *Swig_name_warning(Node *n, String *prefix, String *name, SwigType *decl); /* --- parameterized rename functions --- */ -extern void Swig_name_object_set(Hash *namehash, String_or_char *name, SwigType *decl, DOH *object); -extern DOH *Swig_name_object_get(Hash *namehash, String_or_char *prefix, String_or_char *name, SwigType *decl); -extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived); -extern void Swig_features_get(Hash *features, String_or_char *prefix, String_or_char *name, SwigType *decl, Node *n); -extern void Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs); + extern void Swig_name_object_set(Hash *namehash, String_or_char *name, SwigType *decl, DOH *object); + extern DOH *Swig_name_object_get(Hash *namehash, String_or_char *prefix, String_or_char *name, SwigType *decl); + extern void Swig_name_object_inherit(Hash *namehash, String *base, String *derived); + extern void Swig_features_get(Hash *features, String_or_char *prefix, String_or_char *name, SwigType *decl, Node *n); + extern void Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, + Hash *featureattribs); /* --- Misc --- */ -extern char *Swig_copy_string(const char *c); -extern void Swig_banner(File *f); -extern String *Swig_string_escape(String *s); -extern String *Swig_string_mangle(const String *s); -extern void Swig_scopename_split(String *s, String **prefix, String **last); -extern String *Swig_scopename_prefix(String *s); -extern String *Swig_scopename_last(String *s); -extern String *Swig_scopename_first(String *s); -extern String *Swig_scopename_suffix(String *s); -extern int Swig_scopename_check(String *s); -extern String *Swig_string_lower(String *s); -extern String *Swig_string_upper(String *s); -extern String *Swig_string_title(String *s); + extern char *Swig_copy_string(const char *c); + extern void Swig_banner(File *f); + extern String *Swig_string_escape(String *s); + extern String *Swig_string_mangle(const String *s); + extern void Swig_scopename_split(String *s, String **prefix, String **last); + extern String *Swig_scopename_prefix(String *s); + extern String *Swig_scopename_last(String *s); + extern String *Swig_scopename_first(String *s); + extern String *Swig_scopename_suffix(String *s); + extern int Swig_scopename_check(String *s); + extern String *Swig_string_lower(String *s); + extern String *Swig_string_upper(String *s); + extern String *Swig_string_title(String *s); -extern void Swig_init(); -extern void Swig_warn(const char *filename, int line, const char *msg); + extern void Swig_init(); + extern void Swig_warn(const char *filename, int line, const char *msg); -extern int Swig_value_wrapper_mode(int mode); + extern int Swig_value_wrapper_mode(int mode); #define WARNING(msg) Swig_warn(__FILE__,__LINE__,msg) -typedef enum { EMF_STANDARD, EMF_MICROSOFT } ErrorMessageFormat; + typedef enum { EMF_STANDARD, EMF_MICROSOFT } ErrorMessageFormat; -extern void Swig_warning(int num, const String_or_char *filename, int line, const char *fmt, ...); -extern void Swig_error(const String_or_char *filename, int line, const char *fmt, ...); -extern int Swig_error_count(void); -extern void Swig_error_silent(int s); -extern void Swig_warnfilter(const String_or_char *wlist, int val); -extern void Swig_warnall(void); -extern int Swig_warn_count(void); -extern void Swig_error_msg_format(ErrorMessageFormat format); + extern void Swig_warning(int num, const String_or_char *filename, int line, const char *fmt, ...); + extern void Swig_error(const String_or_char *filename, int line, const char *fmt, ...); + extern int Swig_error_count(void); + extern void Swig_error_silent(int s); + extern void Swig_warnfilter(const String_or_char *wlist, int val); + extern void Swig_warnall(void); + extern int Swig_warn_count(void); + extern void Swig_error_msg_format(ErrorMessageFormat format); /* --- C Wrappers --- */ -extern String *Swig_cparm_name(Parm *p, int i); -extern String *Swig_wrapped_var_type(SwigType *t, int varcref); -extern int Swig_cargs(Wrapper *w, ParmList *l); -extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl); + extern String *Swig_cparm_name(Parm *p, int i); + extern String *Swig_wrapped_var_type(SwigType *t, int varcref); + extern int Swig_cargs(Wrapper *w, ParmList *l); + extern String *Swig_cresult(SwigType *t, const String_or_char *name, const String_or_char *decl); -extern String *Swig_cfunction_call(String_or_char *name, ParmList *parms); -extern String *Swig_cconstructor_call(String_or_char *name); -extern String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms); -extern String *Swig_unref_call(Node *n); -extern String *Swig_ref_call(Node *n, const String* lname); -extern String *Swig_cdestructor_call(Node *n); -extern String *Swig_cppdestructor_call(Node *n); -extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref); -extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref); + extern String *Swig_cfunction_call(String_or_char *name, ParmList *parms); + extern String *Swig_cconstructor_call(String_or_char *name); + extern String *Swig_cppconstructor_call(String_or_char *name, ParmList *parms); + extern String *Swig_unref_call(Node *n); + extern String *Swig_ref_call(Node *n, const String *lname); + extern String *Swig_cdestructor_call(Node *n); + extern String *Swig_cppdestructor_call(Node *n); + extern String *Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self, int varcref); + extern String *Swig_cmemberget_call(const String_or_char *name, SwigType *t, String_or_char *self, int varcref); -extern String *Swig_extension_code(const String *function_name, -ParmList *parms, SwigType* return_type, const String *code, int cplusplus); -extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType* return_type, const String *code, int cplusplus); + extern String *Swig_extension_code(const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus); + extern int Swig_add_extension_code(Node *n, const String *function_name, ParmList *parms, SwigType *return_type, const String *code, int cplusplus); /* --- Transformations --- */ -extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director); -extern int Swig_ConstructorToFunction(Node *n, String *classname, - String *none_comparison, - String *director_ctor, - int cplus, int flags); -extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags); -extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); -extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); -extern int Swig_VargetToFunction(Node *n, int flags); -extern int Swig_VarsetToFunction(Node *n, int flags); + extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director); + extern int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, int cplus, int flags); + extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags); + extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); + extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); + extern int Swig_VargetToFunction(Node *n, int flags); + extern int Swig_VarsetToFunction(Node *n, int flags); #define CWRAP_EXTEND 0x01 #define CWRAP_SMART_POINTER 0x02 @@ -512,49 +509,47 @@ extern int Swig_VarsetToFunction(Node *n, int flags); #define CWRAP_DIRECTOR_TWO_CALLS 0x10 /* --- Director Helpers --- */ -extern Node *Swig_methodclass(Node *n); -extern int Swig_directorclass(Node *n); -extern Node *Swig_directormap(Node *n, String *type); + extern Node *Swig_methodclass(Node *n); + extern int Swig_directorclass(Node *n); + extern Node *Swig_directormap(Node *n, String *type); /* --- Legacy Typemap API (somewhat simplified, ha!) --- */ -extern void Swig_typemap_init(); -extern void Swig_typemap_register(const String_or_char *op, ParmList *pattern, String_or_char *code, ParmList *locals, ParmList *kwargs); -extern int Swig_typemap_copy(const String_or_char *op, ParmList *srcpattern, ParmList *pattern); -extern void Swig_typemap_clear(const String_or_char *op, ParmList *pattern); -extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat); -extern void Swig_typemap_clear_apply(ParmList *pattern); -extern void Swig_typemap_debug(); + extern void Swig_typemap_init(); + extern void Swig_typemap_register(const String_or_char *op, ParmList *pattern, String_or_char *code, ParmList *locals, ParmList *kwargs); + extern int Swig_typemap_copy(const String_or_char *op, ParmList *srcpattern, ParmList *pattern); + extern void Swig_typemap_clear(const String_or_char *op, ParmList *pattern); + extern int Swig_typemap_apply(ParmList *srcpat, ParmList *destpat); + extern void Swig_typemap_clear_apply(ParmList *pattern); + extern void Swig_typemap_debug(); -extern Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_char *pname, SwigType **matchtype); -extern Hash *Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch); -extern String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, String_or_char *lname, - String_or_char *source, String_or_char *target, Wrapper *f); + extern Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_char *pname, SwigType **matchtype); + extern Hash *Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch); + extern String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, String_or_char *lname, + String_or_char *source, String_or_char *target, Wrapper *f); -extern String *Swig_typemap_lookup_new(const String_or_char *op, Node *n, const String_or_char *lname, Wrapper *f); -extern void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p); -extern void Swig_typemap_new_scope(); -extern Hash *Swig_typemap_pop_scope(); + extern String *Swig_typemap_lookup_new(const String_or_char *op, Node *n, const String_or_char *lname, Wrapper *f); + extern void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p); + extern void Swig_typemap_new_scope(); + extern Hash *Swig_typemap_pop_scope(); -extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f); + extern void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f); /* --- Code fragment support --- */ -extern void Swig_fragment_register(Node* fragment); -extern void Swig_fragment_emit(String *name); + extern void Swig_fragment_register(Node *fragment); + extern void Swig_fragment_emit(String *name); /* hacks defined in C++ ! */ -extern int Swig_director_mode(); -extern void Wrapper_director_mode_set(int); + extern int Swig_director_mode(); + extern void Wrapper_director_mode_set(int); /* -- template init -- */ -extern void SwigType_template_init(); + extern void SwigType_template_init(); #ifdef __cplusplus } #endif - #endif - diff --git a/SWIG/Source/Swig/swigkeys.c b/SWIG/Source/Swig/swigkeys.c index 91a03a3e7..f4faf4a65 100644 --- a/SWIG/Source/Swig/swigkeys.c +++ b/SWIG/Source/Swig/swigkeys.c @@ -261,6 +261,6 @@ void Swig_keys_init() { k_previoussibling = NewString("previousSibling"); k_nextsibling = NewString("nextSibling"); - k_firstchild = NewString("firstChild"); - k_lastchild = NewString("lastChild"); + k_firstchild = NewString("firstChild"); + k_lastchild = NewString("lastChild"); } diff --git a/SWIG/Source/Swig/swigkeys.h b/SWIG/Source/Swig/swigkeys.h index 2204bcbb0..c44126dd8 100644 --- a/SWIG/Source/Swig/swigkeys.h +++ b/SWIG/Source/Swig/swigkeys.h @@ -140,4 +140,4 @@ extern String *k_previoussibling; extern String *k_nextsibling; extern String *k_firstchild; extern String *k_lastchild; -#endif /* SWIG_SWIGKEYS_H_ */ +#endif /* SWIG_SWIGKEYS_H_ */ diff --git a/SWIG/Source/Swig/symbol.c b/SWIG/Source/Swig/symbol.c index dfa8ff3db..bf8acf86e 100644 --- a/SWIG/Source/Swig/symbol.c +++ b/SWIG/Source/Swig/symbol.c @@ -166,27 +166,26 @@ char cvsroot_symbol_c[] = "$Header$"; * so sym:symtab points to this symbol table (0xa064cc0). * * ----------------------------------------------------------------------------- */ - -static Hash *current = 0; /* The current symbol table hash */ -static Hash *ccurrent = 0; /* The current c symbol table hash */ -static Hash *current_symtab = 0; /* Current symbol table node */ -static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */ -static Hash *global_scope = 0; /* Global scope */ + +static Hash *current = 0; /* The current symbol table hash */ +static Hash *ccurrent = 0; /* The current c symbol table hash */ +static Hash *current_symtab = 0; /* Current symbol table node */ +static Hash *symtabs = 0; /* Hash of all symbol tables by fully-qualified name */ +static Hash *global_scope = 0; /* Global scope */ /* common attribute keys, to avoid calling find_key all the times */ #if 0 -void -Swig_symbol_dump_symtable() { +void Swig_symbol_dump_symtable() { Printf(stdout, "DUMPING SYMTABLE start =======================================\n"); { - Hash* cst = Getattr(current_symtab, k_csymtab); + Hash *cst = Getattr(current_symtab, k_csymtab); Swig_print_tree(cst); /* - Swig_print_tree(Getattr(cst, "NumSpace")); - */ + Swig_print_tree(Getattr(cst, "NumSpace")); + */ } Printf(stdout, "DUMPING SYMTABLE end =======================================\n"); } @@ -198,21 +197,20 @@ Swig_symbol_dump_symtable() { * Create a new symbol table object * ----------------------------------------------------------------------------- */ -void -Swig_symbol_init() { +void Swig_symbol_init() { current = NewHash(); current_symtab = NewHash(); ccurrent = NewHash(); - set_nodeType(current_symtab,k_symboltable); - Setattr(current_symtab,k_symtab,current); + set_nodeType(current_symtab, k_symboltable); + Setattr(current_symtab, k_symtab, current); Delete(current); - Setattr(current_symtab,k_csymtab, ccurrent); + Setattr(current_symtab, k_csymtab, ccurrent); Delete(ccurrent); /* Set the global scope */ symtabs = NewHash(); - Setattr(symtabs,empty_string,current_symtab); + Setattr(symtabs, empty_string, current_symtab); Delete(current_symtab); global_scope = current_symtab; } @@ -223,18 +221,17 @@ Swig_symbol_init() { * Set the C scopename of the current symbol table. * ----------------------------------------------------------------------------- */ -void -Swig_symbol_setscopename(const String_or_char *name) { +void Swig_symbol_setscopename(const String_or_char *name) { String *qname; /* assert(!Getattr(current_symtab,k_name)); */ - Setattr(current_symtab,k_name,name); + Setattr(current_symtab, k_name, name); /* Set nested scope in parent */ qname = Swig_symbol_qualifiedscopename(current_symtab); /* Save a reference to this scope */ - Setattr(symtabs,qname,current_symtab); + Setattr(symtabs, qname, current_symtab); Delete(qname); } @@ -244,9 +241,8 @@ Swig_symbol_setscopename(const String_or_char *name) { * Get the C scopename of the current symbol table * ----------------------------------------------------------------------------- */ -String * -Swig_symbol_getscopename() { - return HashGetAttr(current_symtab,k_name); +String *Swig_symbol_getscopename() { + return HashGetAttr(current_symtab, k_name); } /* ----------------------------------------------------------------------------- @@ -255,11 +251,12 @@ Swig_symbol_getscopename() { * Given a fully qualified C scopename, this function returns a symbol table * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_getscope(const String_or_char *name) { - if (!symtabs) return 0; - if (StringEqual(k_coloncolon,(String_or_char *)name)) name = empty_string; - return Getattr(symtabs,name); +Symtab *Swig_symbol_getscope(const String_or_char *name) { + if (!symtabs) + return 0; + if (StringEqual(k_coloncolon, (String_or_char *) name)) + name = empty_string; + return Getattr(symtabs, name); } /* ----------------------------------------------------------------------------- @@ -269,25 +266,25 @@ Swig_symbol_getscope(const String_or_char *name) { * to the C/C++ scope name. It is not affected by renaming. * ----------------------------------------------------------------------------- */ -String * -Swig_symbol_qualifiedscopename(Symtab *symtab) { +String *Swig_symbol_qualifiedscopename(Symtab *symtab) { String *result = 0; Hash *parent; String *name; - if (!symtab) symtab = current_symtab; - parent = HashGetAttr(symtab,k_parentnode); + if (!symtab) + symtab = current_symtab; + parent = HashGetAttr(symtab, k_parentnode); if (parent) { result = Swig_symbol_qualifiedscopename(parent); } - name = HashGetAttr(symtab,k_name); + name = HashGetAttr(symtab, k_name); if (name) { if (!result) { result = NewStringEmpty(); } if (StringLen(result)) { - Printv(result,"::",name, NIL); + Printv(result, "::", name, NIL); } else { - StringAppend(result,name); + StringAppend(result, name); } } return result; @@ -299,31 +296,29 @@ Swig_symbol_qualifiedscopename(Symtab *symtab) { * Create a new scope. Returns the newly created scope. * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_newscope() -{ +Symtab *Swig_symbol_newscope() { Hash *n; Hash *hsyms, *h; hsyms = NewHash(); h = NewHash(); - set_nodeType(h,k_symboltable); - Setattr(h,k_symtab,hsyms); + set_nodeType(h, k_symboltable); + Setattr(h, k_symtab, hsyms); Delete(hsyms); - set_parentNode(h,current_symtab); - + set_parentNode(h, current_symtab); + n = lastChild(current_symtab); if (!n) { - set_firstChild(current_symtab,h); + set_firstChild(current_symtab, h); } else { - set_nextSibling(n,h); + set_nextSibling(n, h); Delete(h); } - set_lastChild(current_symtab,h); + set_lastChild(current_symtab, h); current = hsyms; ccurrent = NewHash(); - Setattr(h,k_csymtab,ccurrent); + Setattr(h, k_csymtab, ccurrent); Delete(ccurrent); current_symtab = h; return h; @@ -335,13 +330,12 @@ Swig_symbol_newscope() * Set the current scope. Returns the previous current scope. * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_setscope(Symtab *sym) { +Symtab *Swig_symbol_setscope(Symtab *sym) { Symtab *ret = current_symtab; current_symtab = sym; - current = HashGetAttr(sym,k_symtab); + current = HashGetAttr(sym, k_symtab); assert(current); - ccurrent = HashGetAttr(sym,k_csymtab); + ccurrent = HashGetAttr(sym, k_csymtab); assert(ccurrent); return ret; } @@ -353,14 +347,13 @@ Swig_symbol_setscope(Symtab *sym) { * scope to the parent scope. * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_popscope() { +Symtab *Swig_symbol_popscope() { Hash *h = current_symtab; current_symtab = HashGetAttr(current_symtab, k_parentnode); assert(current_symtab); - current = HashGetAttr(current_symtab,k_symtab); + current = HashGetAttr(current_symtab, k_symtab); assert(current); - ccurrent = HashGetAttr(current_symtab,k_csymtab); + ccurrent = HashGetAttr(current_symtab, k_csymtab); assert(ccurrent); return h; } @@ -371,8 +364,7 @@ Swig_symbol_popscope() { * Return the current symbol table. * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_current() { +Symtab *Swig_symbol_current() { return current_symtab; } @@ -382,16 +374,15 @@ Swig_symbol_current() { * Makes an alias for a symbol in the global symbol table. * ----------------------------------------------------------------------------- */ -void -Swig_symbol_alias(String_or_char *aliasname, Symtab *s) { +void Swig_symbol_alias(String_or_char *aliasname, Symtab *s) { String *qname = Swig_symbol_qualifiedscopename(current_symtab); if (qname) { - Printf(qname,"::%s", aliasname); + Printf(qname, "::%s", aliasname); } else { qname = NewString(aliasname); } - if (!HashGetAttr(symtabs,qname)) { - Setattr(symtabs,qname,s); + if (!HashGetAttr(symtabs, qname)) { + Setattr(symtabs, qname, s); } Delete(qname); } @@ -404,25 +395,25 @@ Swig_symbol_alias(String_or_char *aliasname, Symtab *s) { void Swig_symbol_inherit(Symtab *s) { int i, ilen; - List *inherit = HashGetAttr(current_symtab,k_inherit); + List *inherit = HashGetAttr(current_symtab, k_inherit); if (!inherit) { inherit = NewList(); - Setattr(current_symtab,k_inherit, inherit); + Setattr(current_symtab, k_inherit, inherit); Delete(inherit); } if (s == current_symtab) { - Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(s), Getline(s), - "Recursive scope inheritance of '%s'.\n", HashGetAttr(s,k_name)); + Swig_warning(WARN_PARSE_REC_INHERITANCE, Getfile(s), Getline(s), "Recursive scope inheritance of '%s'.\n", HashGetAttr(s, k_name)); return; } assert(s != current_symtab); ilen = Len(inherit); for (i = 0; i < ilen; i++) { - Node *n = Getitem(inherit,i); - if (n == s) return; /* Already inherited */ + Node *n = Getitem(inherit, i); + if (n == s) + return; /* Already inherited */ } - Append(inherit,s); + Append(inherit, s); } /* ----------------------------------------------------------------------------- @@ -431,8 +422,7 @@ void Swig_symbol_inherit(Symtab *s) { * Adds a node to the C symbol table only. * ----------------------------------------------------------------------------- */ -void -Swig_symbol_cadd(String_or_char *name, Node *n) { +void Swig_symbol_cadd(String_or_char *name, Node *n) { Node *append = 0; Node *cn; @@ -445,84 +435,80 @@ Swig_symbol_cadd(String_or_char *name, Node *n) { symbols related to the C++ type-system and take precedence in the C symbol table. An example might be code like this: - template T foo(T x); - int foo(int); + template T foo(T x); + int foo(int); In this case, the template is marked with "sym:typename" so that it stays in the C symbol table (so that it can be expanded using %template). */ - if (!name) return; + if (!name) + return; if (SwigType_istemplate(name)) { String *cname = NewString(name); - String *dname = Swig_symbol_template_deftype(cname,0); - if (!StringEqual(dname,name)) { + String *dname = Swig_symbol_template_deftype(cname, 0); + if (!StringEqual(dname, name)) { Swig_symbol_cadd(dname, n); } Delete(dname); Delete(cname); } - #ifdef SWIG_DEBUG - Printf(stderr,"symbol_cadd %s %x\n", name, n); + Printf(stderr, "symbol_cadd %s %x\n", name, n); #endif - cn = Getattr(ccurrent,name); + cn = Getattr(ccurrent, name); - if (cn && (HashGetAttr(cn,k_symtypename))) { + if (cn && (HashGetAttr(cn, k_symtypename))) { /* The node in the C symbol table is a typename. Do nothing */ /* We might append the symbol at the end */ append = n; - } else if (cn && (HashGetAttr(cn,k_symweak))) { + } else if (cn && (HashGetAttr(cn, k_symweak))) { /* The node in the symbol table is weak. Replace it */ - if (checkAttribute(cn,k_nodetype,k_template) - && checkAttribute(cn,k_templatetype,k_classforward)) { + if (checkAttribute(cn, k_nodetype, k_template) + && checkAttribute(cn, k_templatetype, k_classforward)) { /* The node is a template classforward declaration, and the - default template parameters here take precedence. */ - ParmList *pc = Getattr(cn,k_templateparms); - ParmList *pn = Getattr(n,k_templateparms); + default template parameters here take precedence. */ + ParmList *pc = Getattr(cn, k_templateparms); + ParmList *pn = Getattr(n, k_templateparms); #ifdef SWIG_DEBUG - Printf(stderr,"found template classforward %s\n",Getattr(cn,k_name)); + Printf(stderr, "found template classforward %s\n", Getattr(cn, k_name)); #endif while (pc && pn) { - String *value = Getattr(pc,k_value); + String *value = Getattr(pc, k_value); if (value) { #ifdef SWIG_DEBUG - Printf(stderr,"add default template value %s %s\n",Getattr(pc,k_name), value); + Printf(stderr, "add default template value %s %s\n", Getattr(pc, k_name), value); #endif - Setattr(pn,k_value, value); - } - pc = nextSibling(pc); - pn = nextSibling(pn); + Setattr(pn, k_value, value); + } + pc = nextSibling(pc); + pn = nextSibling(pn); } - Setattr(n,k_templateparms,Getattr(cn,k_templateparms)); + Setattr(n, k_templateparms, Getattr(cn, k_templateparms)); } - Setattr(ccurrent,name, n); + Setattr(ccurrent, name, n); - } else if (cn && (HashGetAttr(n,k_symweak))) { + } else if (cn && (HashGetAttr(n, k_symweak))) { /* The node being added is weak. Don't worry about it */ - } else if (cn && (HashGetAttr(n,k_symtypename))) { + } else if (cn && (HashGetAttr(n, k_symtypename))) { /* The node being added is a typename. We definitely add it */ - Setattr(ccurrent,name,n); + Setattr(ccurrent, name, n); append = cn; } else if (cn && (HashCheckAttr(cn, k_nodetype, k_templateparm))) { - Swig_error(Getfile(n),Getline(n), - "Declaration of '%s' shadows template parameter,\n", - name); - Swig_error(Getfile(cn),Getline(cn), - "previous template parameter declaration '%s'.\n", - name); + Swig_error(Getfile(n), Getline(n), "Declaration of '%s' shadows template parameter,\n", name); + Swig_error(Getfile(cn), Getline(cn), "previous template parameter declaration '%s'.\n", name); return; } else if (cn) { append = n; } else if (!cn) { /* No conflict. Add the symbol */ - Setattr(ccurrent,name,n); + Setattr(ccurrent, name, n); } /* Multiple entries in the C symbol table. We append to to the symbol table */ if (append) { Node *fn, *pn = 0; - cn = Getattr(ccurrent,name); + cn = Getattr(ccurrent, name); fn = cn; while (fn) { pn = fn; @@ -530,10 +516,10 @@ Swig_symbol_cadd(String_or_char *name, Node *n) { /* already added. Bail */ return; } - fn = HashGetAttr(fn,k_csymnextSibling); + fn = HashGetAttr(fn, k_csymnextSibling); } if (pn) { - Setattr(pn,k_csymnextSibling,append); + Setattr(pn, k_csymnextSibling, append); } } @@ -541,55 +527,57 @@ Swig_symbol_cadd(String_or_char *name, Node *n) { might have to add a type alias. This would occur if the typedef mapped to another scope in the system. For example: - class Foo { - }; + class Foo { + }; - typedef Foo OtherFoo; + typedef Foo OtherFoo; In this case, OtherFoo becomes an alias for Foo. */ { Node *td = n; - while (td && HashCheckAttr(td,k_nodetype,k_cdecl) && HashCheckAttr(td,k_storage,k_typedef)) { + while (td && HashCheckAttr(td, k_nodetype, k_cdecl) && HashCheckAttr(td, k_storage, k_typedef)) { SwigType *type; Node *td1; - type = Copy(HashGetAttr(td,k_type)); - SwigType_push(type,HashGetAttr(td,k_decl)); - td1 = Swig_symbol_clookup(type,0); - - /* Fix pathetic case #1214313: - - class Foo - { - }; - - typedef Foo FooBar; - - class CBaz - { - public: - typedef FooBar Foo; - }; + type = Copy(HashGetAttr(td, k_type)); + SwigType_push(type, HashGetAttr(td, k_decl)); + td1 = Swig_symbol_clookup(type, 0); - ie, when Foo -> FooBar -> Foo, jump one scope up when possible. - - */ - if (td1 && HashCheckAttr(td1,k_storage,k_typedef)) { - String *st = HashGetAttr(td1,k_type); - String *sn = HashGetAttr(td,k_name); + /* Fix pathetic case #1214313: + + class Foo + { + }; + + typedef Foo FooBar; + + class CBaz + { + public: + typedef FooBar Foo; + }; + + ie, when Foo -> FooBar -> Foo, jump one scope up when possible. + + */ + if (td1 && HashCheckAttr(td1, k_storage, k_typedef)) { + String *st = HashGetAttr(td1, k_type); + String *sn = HashGetAttr(td, k_name); if (st && sn && StringEqual(st, sn)) { - Symtab *sc = HashGetAttr(current_symtab,k_parentnode); - if (sc) td1 = Swig_symbol_clookup(type,sc); + Symtab *sc = HashGetAttr(current_symtab, k_parentnode); + if (sc) + td1 = Swig_symbol_clookup(type, sc); } } Delete(type); - if (td1 == td) break; + if (td1 == td) + break; td = td1; if (td) { - Symtab *st = HashGetAttr(td,k_symtab); + Symtab *st = HashGetAttr(td, k_symtab); if (st) { - Swig_symbol_alias(HashGetAttr(n,k_name),st); + Swig_symbol_alias(HashGetAttr(n, k_name), st); break; } } @@ -607,15 +595,14 @@ Swig_symbol_cadd(String_or_char *name, Node *n) { * for namespace support, type resolution, and other issues. * ----------------------------------------------------------------------------- */ -Node * -Swig_symbol_add(String_or_char *symname, Node *n) { +Node *Swig_symbol_add(String_or_char *symname, Node *n) { Hash *c, *cn, *cl = 0; SwigType *decl, *ndecl; - String *cstorage, *nstorage; - int nt = 0, ct = 0; - int pn = 0; - int u1 = 0, u2 = 0; - String *name, *overname; + String *cstorage, *nstorage; + int nt = 0, ct = 0; + int pn = 0; + int u1 = 0, u2 = 0; + String *name, *overname; /* See if the node has a name. If so, we place in the C symbol table for this scope. We don't worry about overloading here---the primary purpose of this @@ -623,7 +610,7 @@ Swig_symbol_add(String_or_char *symname, Node *n) { in C namespaces are errors, but these will be caught by the C++ compiler when compiling the wrapper code */ - + /* There are a few options for weak symbols. A "weak" symbol is any symbol that can be replaced by another symbol in the C symbol table. An example would be a forward class declaration. A forward @@ -633,77 +620,81 @@ Swig_symbol_add(String_or_char *symname, Node *n) { symbols related to the C++ type-system and take precedence in the C symbol table. An example might be code like this: - template T foo(T x); - int foo(int); + template T foo(T x); + int foo(int); In this case, the template is marked with "sym:typename" so that it stays in the C symbol table (so that it can be expanded using %template). */ - name = HashGetAttr(n,k_name); + name = HashGetAttr(n, k_name); if (name && Len(name)) { - Swig_symbol_cadd(name,n); + Swig_symbol_cadd(name, n); } /* No symbol name defined. We return. */ if (!symname) { - Setattr(n,k_symsymtab,current_symtab); + Setattr(n, k_symsymtab, current_symtab); return n; } /* If node is ignored. We don't proceed any further */ - if (GetFlag(n,"feature:ignore")) return n; + if (GetFlag(n, "feature:ignore")) + return n; /* See if the symbol already exists in the table */ - c = Getattr(current,symname); + c = Getattr(current, symname); /* Check for a weak symbol. A weak symbol is allowed to be in the symbol table, but is silently overwritten by other symbols. An example would be a forward class declaration. For instance: - class Foo; + class Foo; In this case, "Foo" sits in the symbol table. However, the definition of Foo would replace the entry if it appeared later. */ - - if (c && HashGetAttr(c,k_symweak)) { + + if (c && HashGetAttr(c, k_symweak)) { c = 0; } if (c) { /* There is a symbol table conflict. There are a few cases to consider here: - (1) A conflict between a class/enum and a typedef declaration is okay. - In this case, the symbol table entry is set to the class/enum declaration - itself, not the typedef. + (1) A conflict between a class/enum and a typedef declaration is okay. + In this case, the symbol table entry is set to the class/enum declaration + itself, not the typedef. - (2) A conflict between namespaces is okay--namespaces are open + (2) A conflict between namespaces is okay--namespaces are open - (3) Otherwise, overloading is only allowed for functions - */ + (3) Otherwise, overloading is only allowed for functions + */ /* Check for namespaces */ - String *ntype = HashGetAttr(n, k_nodetype); - if ((StringEqual(ntype,HashGetAttr(c,k_nodetype))) && ((StringEqual(ntype,k_namespace)))) { + String *ntype = HashGetAttr(n, k_nodetype); + if ((StringEqual(ntype, HashGetAttr(c, k_nodetype))) && ((StringEqual(ntype, k_namespace)))) { Node *cl, *pcl = 0; cl = c; while (cl) { pcl = cl; - cl = HashGetAttr(cl,k_symnextSibling); + cl = HashGetAttr(cl, k_symnextSibling); } - Setattr(pcl,k_symnextSibling,n); - Setattr(n,k_symsymtab, current_symtab); - Setattr(n,k_symname, symname); - Setattr(n,k_sympreviousSibling, pcl); + Setattr(pcl, k_symnextSibling, n); + Setattr(n, k_symsymtab, current_symtab); + Setattr(n, k_symname, symname); + Setattr(n, k_sympreviousSibling, pcl); return n; } - if (HashGetAttr(n,k_allowstypedef)) nt = 1; - if (HashGetAttr(c,k_allowstypedef)) ct = 1; + if (HashGetAttr(n, k_allowstypedef)) + nt = 1; + if (HashGetAttr(c, k_allowstypedef)) + ct = 1; if (nt || ct) { Node *td, *other; String *s; /* At least one of the nodes allows typedef overloading. Make sure that both don't--this would be a conflict */ - if (nt && ct) return c; + if (nt && ct) + return c; /* Figure out which node allows the typedef */ if (nt) { @@ -714,32 +705,38 @@ Swig_symbol_add(String_or_char *symname, Node *n) { other = n; } /* Make sure the other node is a typedef */ - s = HashGetAttr(other,k_storage); - if (!s || (!StringEqual(s,k_typedef))) return c; /* No. This is a conflict */ - + s = HashGetAttr(other, k_storage); + if (!s || (!StringEqual(s, k_typedef))) + return c; /* No. This is a conflict */ + /* Hmmm. This appears to be okay. Make sure the symbol table refers to the allow_type node */ - + if (td != c) { - Setattr(current,symname, td); - Setattr(td,k_symsymtab, current_symtab); - Setattr(td,k_symname, symname); + Setattr(current, symname, td); + Setattr(td, k_symsymtab, current_symtab); + Setattr(td, k_symname, symname); } return n; } - - decl = HashGetAttr(c,k_decl); - ndecl = HashGetAttr(n,k_decl); + + decl = HashGetAttr(c, k_decl); + ndecl = HashGetAttr(n, k_decl); { String *nt1, *nt2; - nt1 = HashGetAttr(n,k_nodetype); - if (StringEqual(nt1,k_template)) nt1 = HashGetAttr(n,k_templatetype); - nt2 = HashGetAttr(c,k_nodetype); - if (StringEqual(nt2,k_template)) nt2 = HashGetAttr(c,k_templatetype); - if (StringEqual(nt1,k_using)) u1 = 1; - if (StringEqual(nt2,k_using)) u2 = 1; + nt1 = HashGetAttr(n, k_nodetype); + if (StringEqual(nt1, k_template)) + nt1 = HashGetAttr(n, k_templatetype); + nt2 = HashGetAttr(c, k_nodetype); + if (StringEqual(nt2, k_template)) + nt2 = HashGetAttr(c, k_templatetype); + if (StringEqual(nt1, k_using)) + u1 = 1; + if (StringEqual(nt2, k_using)) + u2 = 1; - if ((!StringEqual(nt1,nt2)) && !(u1 || u2)) return c; + if ((!StringEqual(nt1, nt2)) && !(u1 || u2)) + return c; } if (!(u1 || u2)) { if ((!SwigType_isfunction(decl)) || (!SwigType_isfunction(ndecl))) { @@ -747,73 +744,73 @@ Swig_symbol_add(String_or_char *symname, Node *n) { return c; } } - + /* Hmmm. Declarator seems to indicate that this is a function */ /* Look at storage class to see if compatible */ - cstorage = HashGetAttr(c,k_storage); - nstorage = HashGetAttr(n,k_storage); + cstorage = HashGetAttr(c, k_storage); + nstorage = HashGetAttr(n, k_storage); /* If either one is declared as typedef, forget it. We're hosed */ - if (Cmp(cstorage,k_typedef) == 0) { + if (Cmp(cstorage, k_typedef) == 0) { return c; } - if (Cmp(nstorage,k_typedef) == 0) { + if (Cmp(nstorage, k_typedef) == 0) { return c; } /* Okay. Walk down the list of symbols and see if we get a declarator match */ { - String *nt = HashGetAttr(n,k_nodetype); - int n_template = StringEqual(nt,k_template) && HashCheckAttr(n,k_templatetype,k_cdecl); - int n_plain_cdecl = StringEqual(nt,k_cdecl); + String *nt = HashGetAttr(n, k_nodetype); + int n_template = StringEqual(nt, k_template) && HashCheckAttr(n, k_templatetype, k_cdecl); + int n_plain_cdecl = StringEqual(nt, k_cdecl); cn = c; pn = 0; while (cn) { - decl = HashGetAttr(cn,k_decl); - if (!(u1 || u2)) { - if (Cmp(ndecl,decl) == 0) { - /* Declarator conflict */ - /* Now check we don't have a non-templated function overloaded by a templated function with same params, - * eg void foo(); template void foo(); */ - String *cnt = HashGetAttr(cn,k_nodetype); - int cn_template = StringEqual(cnt,k_template) && HashCheckAttr(cn,k_templatetype,k_cdecl); - int cn_plain_cdecl = StringEqual(cnt,k_cdecl); - if (!((n_template && cn_plain_cdecl) || (cn_template && n_plain_cdecl))) { - /* found a conflict */ - return cn; - } - } - } - cl = cn; - cn = HashGetAttr(cn,k_symnextSibling); - pn++; + decl = HashGetAttr(cn, k_decl); + if (!(u1 || u2)) { + if (Cmp(ndecl, decl) == 0) { + /* Declarator conflict */ + /* Now check we don't have a non-templated function overloaded by a templated function with same params, + * eg void foo(); template void foo(); */ + String *cnt = HashGetAttr(cn, k_nodetype); + int cn_template = StringEqual(cnt, k_template) && HashCheckAttr(cn, k_templatetype, k_cdecl); + int cn_plain_cdecl = StringEqual(cnt, k_cdecl); + if (!((n_template && cn_plain_cdecl) || (cn_template && n_plain_cdecl))) { + /* found a conflict */ + return cn; + } + } + } + cl = cn; + cn = HashGetAttr(cn, k_symnextSibling); + pn++; } } /* Well, we made it this far. Guess we can drop the symbol in place */ - Setattr(n,k_symsymtab,current_symtab); - Setattr(n,k_symname,symname); + Setattr(n, k_symsymtab, current_symtab); + Setattr(n, k_symname, symname); /* Printf(stdout,"%s %x\n", Getattr(n,k_symovername), current_symtab); */ - assert(!HashGetAttr(n,k_symovername)); + assert(!HashGetAttr(n, k_symovername)); overname = NewStringf("__SWIG_%d", pn); - Setattr(n,k_symovername, overname); + Setattr(n, k_symovername, overname); /*Printf(stdout,"%s %s %s\n", symname, Getattr(n,k_decl), Getattr(n,k_symovername)); */ - Setattr(cl,k_symnextSibling,n); - Setattr(n,k_sympreviousSibling,cl); - Setattr(cl,k_symoverloaded,c); - Setattr(n,k_symoverloaded,c); + Setattr(cl, k_symnextSibling, n); + Setattr(n, k_sympreviousSibling, cl); + Setattr(cl, k_symoverloaded, c); + Setattr(n, k_symoverloaded, c); Delete(overname); return n; } /* No conflict. Just add it */ - Setattr(n,k_symsymtab,current_symtab); - Setattr(n,k_symname,symname); + Setattr(n, k_symsymtab, current_symtab); + Setattr(n, k_symname, symname); /* Printf(stdout,"%s\n", Getattr(n,k_symovername)); */ overname = NewStringf("__SWIG_%d", pn); - Setattr(n,k_symovername, overname); + Setattr(n, k_symovername, overname); Delete(overname); /* Printf(stdout,"%s %s %s\n", symname, Getattr(n,k_decl), Getattr(n,k_symovername)); */ - Setattr(current,symname,n); + Setattr(current, symname, n); return n; } @@ -831,76 +828,76 @@ Swig_symbol_add(String_or_char *symname, Node *n) { * verifying that a class hierarchy implements all pure virtual methods. * ----------------------------------------------------------------------------- */ -static Node * -_symbol_lookup(String *name, Symtab *symtab, int (*check)(Node *n)) { +static Node *_symbol_lookup(String *name, Symtab *symtab, int (*check) (Node *n)) { Node *n; List *inherit; - Hash *sym = HashGetAttr(symtab,k_csymtab); - if (Getmark(symtab)) return 0; - Setmark(symtab,1); + Hash *sym = HashGetAttr(symtab, k_csymtab); + if (Getmark(symtab)) + return 0; + Setmark(symtab, 1); - n = HashGetAttr(sym,name); + n = HashGetAttr(sym, name); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_look %s %x %x %s\n", name, n, symtab, HashGetAttr(symtab,k_name)); + Printf(stderr, "symbol_look %s %x %x %s\n", name, n, symtab, HashGetAttr(symtab, k_name)); #endif - + if (n) { /* if a check-function is defined. Call it to determine a match */ if (check) { int c = check(n); if (c == 1) { - Setmark(symtab,0); + Setmark(symtab, 0); return n; } if (c < 0) { /* Terminate the search right away */ - Setmark(symtab,0); + Setmark(symtab, 0); return 0; } } else { - Setmark(symtab,0); + Setmark(symtab, 0); return n; } } if (!n && SwigType_istemplate(name)) { String *dname = 0; - Setmark(symtab,0); - dname = Swig_symbol_template_deftype(name,symtab); - if (!StringEqual(dname,name)) { + Setmark(symtab, 0); + dname = Swig_symbol_template_deftype(name, symtab); + if (!StringEqual(dname, name)) { n = _symbol_lookup(dname, symtab, check); } Delete(dname); - if (n) return n; + if (n) + return n; } - inherit = HashGetAttr(symtab,k_inherit); + inherit = HashGetAttr(symtab, k_inherit); if (inherit) { - int i,len; + int i, len; len = Len(inherit); for (i = 0; i < len; i++) { - n = _symbol_lookup(name, Getitem(inherit,i),check); + n = _symbol_lookup(name, Getitem(inherit, i), check); if (n) { - Setmark(symtab,0); + Setmark(symtab, 0); return n; } } } - Setmark(symtab,0); + Setmark(symtab, 0); return 0; } -static Node * -symbol_lookup(String_or_char *name, Symtab *symtab, int (*check)(Node *n)) { +static Node *symbol_lookup(String_or_char *name, Symtab *symtab, int (*check) (Node *n)) { Node *n = 0; if (DohCheck(name)) { n = _symbol_lookup(name, symtab, check); } else { String *sname = NewString(name); - n = _symbol_lookup(sname, symtab, check); + n = _symbol_lookup(sname, symtab, check); Delete(sname); } return n; @@ -912,17 +909,17 @@ symbol_lookup(String_or_char *name, Symtab *symtab, int (*check)(Node *n)) { * symbol_lookup_qualified() * ----------------------------------------------------------------------------- */ -static Node * -symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, int local, int (*checkfunc)(Node *n)) { +static Node *symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, int local, int (*checkfunc) (Node *n)) { /* This is a little funky, we search by fully qualified names */ - if (!symtab) return 0; + if (!symtab) + return 0; if (!prefix) { Node *n; String *bname; String *prefix; Swig_scopename_split(name, &prefix, &bname); - n = symbol_lookup_qualified(bname,symtab,prefix,local,checkfunc); + n = symbol_lookup_qualified(bname, symtab, prefix, local, checkfunc); Delete(bname); Delete(prefix); return n; @@ -932,10 +929,10 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in /* Make qualified name of current scope */ String *qalloc = 0; String *qname = Swig_symbol_qualifiedscopename(symtab); - if (qname){ + if (qname) { if (StringLen(qname)) { if (prefix && StringLen(prefix)) { - Printv(qname,k_coloncolon,prefix,NIL); + Printv(qname, k_coloncolon, prefix, NIL); } } else { StringAppend(qname, prefix); @@ -944,21 +941,24 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in } else { qname = prefix; } - st = HashGetAttr(symtabs,qname); + st = HashGetAttr(symtabs, qname); /* Found a scope match */ if (st) { if (!name) { - if (qalloc) Delete(qalloc); + if (qalloc) + Delete(qalloc); return st; } - n = symbol_lookup(name, st,checkfunc); + n = symbol_lookup(name, st, checkfunc); } - if (qalloc) Delete(qalloc); + if (qalloc) + Delete(qalloc); if (!n) { if (!local) { - Node *pn = HashGetAttr(symtab,k_parentnode); - if (pn) n = symbol_lookup_qualified(name,pn, prefix, local,checkfunc); + Node *pn = HashGetAttr(symtab, k_parentnode); + if (pn) + n = symbol_lookup_qualified(name, pn, prefix, local, checkfunc); } else { n = 0; } @@ -975,39 +975,38 @@ symbol_lookup_qualified(String_or_char *name, Symtab *symtab, String *prefix, in * to get the real node. * ----------------------------------------------------------------------------- */ -static +static SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab); -Node * -Swig_symbol_clookup(String_or_char *name, Symtab *n) { +Node *Swig_symbol_clookup(String_or_char *name, Symtab *n) { Hash *hsym = 0; Node *s = 0; - + if (!n) { hsym = current_symtab; } else { - if (!HashCheckAttr(n,k_nodetype,k_symboltable)) { - n = HashGetAttr(n,k_symsymtab); + if (!HashCheckAttr(n, k_nodetype, k_symboltable)) { + n = HashGetAttr(n, k_symsymtab); } assert(n); if (n) { hsym = n; } } - + if (Swig_scopename_check(name)) { char *cname = Char(name); - if (strncmp(cname,"::",2) == 0) { - String *nname = NewString(cname+2); + if (strncmp(cname, "::", 2) == 0) { + String *nname = NewString(cname + 2); if (Swig_scopename_check(nname)) { - s = symbol_lookup_qualified(nname,global_scope,0,0,0); + s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0); } Delete(nname); } else { String *prefix = Swig_scopename_prefix(name); if (prefix) { - s = symbol_lookup_qualified(name,hsym,0,0,0); + s = symbol_lookup_qualified(name, hsym, 0, 0, 0); Delete(prefix); if (!s) { return 0; @@ -1017,10 +1016,12 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { } if (!s) { while (hsym) { - s = symbol_lookup(name,hsym,0); - if (s) break; - hsym = HashGetAttr(hsym,k_parentnode); - if (!hsym) break; + s = symbol_lookup(name, hsym, 0); + if (s) + break; + hsym = HashGetAttr(hsym, k_parentnode); + if (!hsym) + break; } } @@ -1028,13 +1029,12 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { return 0; } /* Check if s is a 'using' node */ - while (s && HashCheckAttr(s,k_nodetype,k_using)) { - String *uname = HashGetAttr(s,k_uname); - Symtab *un = HashGetAttr(s,k_symsymtab); - Node *ss = (!StringEqual(name,uname) || (un != n)) ? - Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */ + while (s && HashCheckAttr(s, k_nodetype, k_using)) { + String *uname = HashGetAttr(s, k_uname); + Symtab *un = HashGetAttr(s, k_symsymtab); + Node *ss = (!StringEqual(name, uname) || (un != n)) ? Swig_symbol_clookup(uname, un) : 0; /* avoid infinity loop */ if (!ss) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s,k_uname)); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s, k_uname)); } s = ss; } @@ -1051,35 +1051,34 @@ Swig_symbol_clookup(String_or_char *name, Symtab *n) { * inheritance hierarchy. * ----------------------------------------------------------------------------- */ -Node * -Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node *n)) { +Node *Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc) (Node *n)) { Hash *hsym = 0; Node *s = 0; - + if (!n) { hsym = current_symtab; } else { - if (!HashCheckAttr(n,k_nodetype,k_symboltable)) { - n = HashGetAttr(n,k_symsymtab); + if (!HashCheckAttr(n, k_nodetype, k_symboltable)) { + n = HashGetAttr(n, k_symsymtab); } assert(n); if (n) { hsym = n; } } - + if (Swig_scopename_check(name)) { char *cname = Char(name); - if (strncmp(cname,"::",2) == 0) { - String *nname = NewString(cname+2); + if (strncmp(cname, "::", 2) == 0) { + String *nname = NewString(cname + 2); if (Swig_scopename_check(nname)) { - s = symbol_lookup_qualified(nname,global_scope,0,0,checkfunc); + s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc); } Delete(nname); } else { String *prefix = Swig_scopename_prefix(name); if (prefix) { - s = symbol_lookup_qualified(name,hsym,0,0,checkfunc); + s = symbol_lookup_qualified(name, hsym, 0, 0, checkfunc); Delete(prefix); if (!s) { return 0; @@ -1089,21 +1088,23 @@ Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node } if (!s) { while (hsym) { - s = symbol_lookup(name,hsym,checkfunc); - if (s) break; - hsym = HashGetAttr(hsym,k_parentnode); - if (!hsym) break; + s = symbol_lookup(name, hsym, checkfunc); + if (s) + break; + hsym = HashGetAttr(hsym, k_parentnode); + if (!hsym) + break; } } if (!s) { return 0; } /* Check if s is a 'using' node */ - while (s && HashCheckAttr(s,k_nodetype,k_using)) { + while (s && HashCheckAttr(s, k_nodetype, k_using)) { Node *ss; - ss = Swig_symbol_clookup(HashGetAttr(s,k_uname), HashGetAttr(s,k_symsymtab)); + ss = Swig_symbol_clookup(HashGetAttr(s, k_uname), HashGetAttr(s, k_symsymtab)); if (!ss && !checkfunc) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s,k_uname)); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s, k_uname)); } s = ss; } @@ -1114,8 +1115,7 @@ Swig_symbol_clookup_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node * Swig_symbol_clookup_local() * ----------------------------------------------------------------------------- */ -Node * -Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { +Node *Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { Hash *h, *hsym; Node *s = 0; @@ -1123,35 +1123,36 @@ Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { hsym = current_symtab; h = ccurrent; } else { - if (!HashCheckAttr(n,k_nodetype,k_symboltable)) { - n = HashGetAttr(n,k_symsymtab); + if (!HashCheckAttr(n, k_nodetype, k_symboltable)) { + n = HashGetAttr(n, k_symsymtab); } assert(n); hsym = n; - h = HashGetAttr(n,k_csymtab); + h = HashGetAttr(n, k_csymtab); } if (Swig_scopename_check(name)) { char *cname = Char(name); - if (strncmp(cname,"::",2) == 0) { - String *nname = NewString(cname+2); + if (strncmp(cname, "::", 2) == 0) { + String *nname = NewString(cname + 2); if (Swig_scopename_check(nname)) { - s = symbol_lookup_qualified(nname,global_scope,0,0,0); + s = symbol_lookup_qualified(nname, global_scope, 0, 0, 0); } Delete(nname); } else { - s = symbol_lookup_qualified(name,hsym,0,0,0); + s = symbol_lookup_qualified(name, hsym, 0, 0, 0); } } if (!s) { - s = symbol_lookup(name,hsym,0); + s = symbol_lookup(name, hsym, 0); } - if (!s) return 0; + if (!s) + return 0; /* Check if s is a 'using' node */ - while (s && HashCheckAttr(s,k_nodetype,k_using)) { - Node *ss = Swig_symbol_clookup_local(HashGetAttr(s,k_uname), HashGetAttr(s,k_symsymtab)); + while (s && HashCheckAttr(s, k_nodetype, k_using)) { + Node *ss = Swig_symbol_clookup_local(HashGetAttr(s, k_uname), HashGetAttr(s, k_symsymtab)); if (!ss) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s,k_uname)); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s, k_uname)); } s = ss; } @@ -1162,8 +1163,7 @@ Swig_symbol_clookup_local(String_or_char *name, Symtab *n) { * Swig_symbol_clookup_local_check() * ----------------------------------------------------------------------------- */ -Node * -Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc)(Node *)) { +Node *Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc) (Node *)) { Hash *h, *hsym; Node *s = 0; @@ -1171,35 +1171,36 @@ Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc hsym = current_symtab; h = ccurrent; } else { - if (!HashCheckAttr(n,k_nodetype,k_symboltable)) { - n = HashGetAttr(n,k_symsymtab); + if (!HashCheckAttr(n, k_nodetype, k_symboltable)) { + n = HashGetAttr(n, k_symsymtab); } assert(n); hsym = n; - h = HashGetAttr(n,k_csymtab); + h = HashGetAttr(n, k_csymtab); } if (Swig_scopename_check(name)) { char *cname = Char(name); - if (strncmp(cname,"::",2) == 0) { - String *nname = NewString(cname+2); + if (strncmp(cname, "::", 2) == 0) { + String *nname = NewString(cname + 2); if (Swig_scopename_check(nname)) { - s = symbol_lookup_qualified(nname,global_scope,0,0,checkfunc); + s = symbol_lookup_qualified(nname, global_scope, 0, 0, checkfunc); } Delete(nname); } else { - s = symbol_lookup_qualified(name,hsym,0,0,checkfunc); + s = symbol_lookup_qualified(name, hsym, 0, 0, checkfunc); } } if (!s) { - s = symbol_lookup(name,hsym,checkfunc); + s = symbol_lookup(name, hsym, checkfunc); } - if (!s) return 0; + if (!s) + return 0; /* Check if s is a 'using' node */ - while (s && HashCheckAttr(s,k_nodetype,k_using)) { - Node *ss = Swig_symbol_clookup_local_check(HashGetAttr(s,k_uname), HashGetAttr(s,k_symsymtab),checkfunc); + while (s && HashCheckAttr(s, k_nodetype, k_using)) { + Node *ss = Swig_symbol_clookup_local_check(HashGetAttr(s, k_uname), HashGetAttr(s, k_symsymtab), checkfunc); if (!ss && !checkfunc) { - Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s,k_uname)); + Swig_warning(WARN_PARSE_USING_UNDEF, Getfile(s), Getline(s), "Nothing known about '%s'.\n", HashGetAttr(s, k_uname)); } s = ss; } @@ -1213,11 +1214,11 @@ Swig_symbol_clookup_local_check(String_or_char *name, Symtab *n, int (*checkfunc * Look up a scope name. * ----------------------------------------------------------------------------- */ -Symtab * -Swig_symbol_cscope(String_or_char *name, Symtab *symtab) { +Symtab *Swig_symbol_cscope(String_or_char *name, Symtab *symtab) { char *cname = Char(name); - if (strncmp(cname,"::",2) == 0) return symbol_lookup_qualified(0, global_scope, name, 0,0); - return symbol_lookup_qualified(0,symtab,name,0,0); + if (strncmp(cname, "::", 2) == 0) + return symbol_lookup_qualified(0, global_scope, name, 0, 0); + return symbol_lookup_qualified(0, symtab, name, 0, 0); } /* ----------------------------------------------------------------------------- @@ -1228,51 +1229,50 @@ Swig_symbol_cscope(String_or_char *name, Symtab *symtab) { * names (sym:overname attribute) are changed to start from zero, eg __SWIG_0. * ----------------------------------------------------------------------------- */ -void -Swig_symbol_remove(Node *n) { - Symtab *symtab; - String *symname; - String *overname; - Node *symprev; - Node *symnext; - Node *fixovername = 0; - symtab = HashGetAttr(n,k_symsymtab); /* Get symbol table object */ - symtab = HashGetAttr(symtab,k_symtab); /* Get actual hash table of symbols */ - symname = HashGetAttr(n,k_symname); - symprev = HashGetAttr(n,k_sympreviousSibling); - symnext = HashGetAttr(n,k_symnextSibling); +void Swig_symbol_remove(Node *n) { + Symtab *symtab; + String *symname; + String *overname; + Node *symprev; + Node *symnext; + Node *fixovername = 0; + symtab = HashGetAttr(n, k_symsymtab); /* Get symbol table object */ + symtab = HashGetAttr(symtab, k_symtab); /* Get actual hash table of symbols */ + symname = HashGetAttr(n, k_symname); + symprev = HashGetAttr(n, k_sympreviousSibling); + symnext = HashGetAttr(n, k_symnextSibling); /* If previous symbol, just fix the links */ if (symprev) { if (symnext) { - Setattr(symprev,k_symnextSibling,symnext); - fixovername = symprev; /* fix as symbol to remove is somewhere in the middle of the linked list */ + Setattr(symprev, k_symnextSibling, symnext); + fixovername = symprev; /* fix as symbol to remove is somewhere in the middle of the linked list */ } else { - Delattr(symprev,k_symnextSibling); + Delattr(symprev, k_symnextSibling); } } else { /* If no previous symbol, see if there is a next symbol */ if (symnext) { - Setattr(symtab,symname,symnext); - fixovername = symnext; /* fix as symbol to remove is at head of linked list */ + Setattr(symtab, symname, symnext); + fixovername = symnext; /* fix as symbol to remove is at head of linked list */ } else { - Delattr(symtab,symname); + Delattr(symtab, symname); } } if (symnext) { if (symprev) { - Setattr(symnext,k_sympreviousSibling,symprev); + Setattr(symnext, k_sympreviousSibling, symprev); } else { - Delattr(symnext,k_sympreviousSibling); + Delattr(symnext, k_sympreviousSibling); } } - Delattr(n,k_symsymtab); - Delattr(n,k_sympreviousSibling); - Delattr(n,k_symnextSibling); - Delattr(n,k_csymnextSibling); - Delattr(n,k_symovername); - Delattr(n,k_csympreviousSibling); - Delattr(n,k_symoverloaded); + Delattr(n, k_symsymtab); + Delattr(n, k_sympreviousSibling); + Delattr(n, k_symnextSibling); + Delattr(n, k_csymnextSibling); + Delattr(n, k_symovername); + Delattr(n, k_csympreviousSibling); + Delattr(n, k_symoverloaded); n = 0; if (fixovername) { @@ -1289,13 +1289,13 @@ Swig_symbol_remove(Node *n) { /* adjust all the sym:overname strings to start from 0 and increment by one */ nn = head; while (nn) { - assert(HashGetAttr(nn,k_symovername)); - Delattr(nn,k_symovername); + assert(HashGetAttr(nn, k_symovername)); + Delattr(nn, k_symovername); overname = NewStringf("__SWIG_%d", pn); - Setattr(nn,k_symovername, overname); + Setattr(nn, k_symovername, overname); Delete(overname); pn++; - nn = HashGetAttr(nn,k_symnextSibling); + nn = HashGetAttr(nn, k_symnextSibling); } } } @@ -1306,17 +1306,17 @@ Swig_symbol_remove(Node *n) { * Return the qualified name of a symbol * ----------------------------------------------------------------------------- */ -String * -Swig_symbol_qualified(Node *n) { +String *Swig_symbol_qualified(Node *n) { Hash *symtab; - if (HashCheckAttr(n,k_nodetype,k_symboltable)) { + if (HashCheckAttr(n, k_nodetype, k_symboltable)) { symtab = n; } else { - symtab = HashGetAttr(n,k_symsymtab); + symtab = HashGetAttr(n, k_symsymtab); } - if (!symtab) return NewStringEmpty(); + if (!symtab) + return NewStringEmpty(); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_qscope %s %x %s\n", HashGetAttr(n,k_name), symtab,HashGetAttr(symtab,k_name)); + Printf(stderr, "symbol_qscope %s %x %s\n", HashGetAttr(n, k_name), symtab, HashGetAttr(symtab, k_name)); #endif return Swig_symbol_qualifiedscopename(symtab); } @@ -1327,9 +1327,8 @@ Swig_symbol_qualified(Node *n) { * Check if a symbol is overloaded. Returns the first symbol if so. * ----------------------------------------------------------------------------- */ -Node * -Swig_symbol_isoverloaded(Node *n) { - return HashGetAttr(n,k_symoverloaded); +Node *Swig_symbol_isoverloaded(Node *n) { + return HashGetAttr(n, k_symoverloaded); } /* ----------------------------------------------------------------------------- @@ -1344,18 +1343,17 @@ static int no_constructor(Node *n) { /* This cache produce problems with OSS, don't active it */ /* #define SWIG_TEMPLATE_QUALIFY_CACHE */ -static SwigType * -Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { +static SwigType *Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { String *tprefix, *tsuffix; SwigType *qprefix; - List *targs; + List *targs; Node *tempn; Symtab *tscope; Iterator ti; #ifdef SWIG_TEMPLATE_QUALIFY_CACHE static Hash *qualify_cache = 0; - String *scopetype = st ? NewStringf("%s::%s",Getattr(st,k_name),e) - : NewStringf("%s::%s",Swig_symbol_getscopename(),e); + String *scopetype = st ? NewStringf("%s::%s", Getattr(st, k_name), e) + : NewStringf("%s::%s", Swig_symbol_getscopename(), e); if (!qualify_cache) { qualify_cache = NewHash(); } @@ -1364,45 +1362,45 @@ Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { if (cres) { Delete(scopetype); return Copy(cres); - } + } } #endif tprefix = SwigType_templateprefix(e); tsuffix = SwigType_templatesuffix(e); - qprefix = Swig_symbol_type_qualify(tprefix,st); + qprefix = Swig_symbol_type_qualify(tprefix, st); targs = SwigType_parmlist(e); - tempn = Swig_symbol_clookup_local(tprefix,st); - tscope = tempn ? HashGetAttr(tempn,k_symsymtab) : 0; - StringAppend(qprefix,"<("); + tempn = Swig_symbol_clookup_local(tprefix, st); + tscope = tempn ? HashGetAttr(tempn, k_symsymtab) : 0; + StringAppend(qprefix, "<("); for (ti = First(targs); ti.item;) { String *vparm; - String *qparm = Swig_symbol_type_qualify(ti.item,st); + String *qparm = Swig_symbol_type_qualify(ti.item, st); if (tscope && (tscope != st)) { - String *ty = Swig_symbol_type_qualify(qparm,tscope); - Delete(qparm); + String *ty = Swig_symbol_type_qualify(qparm, tscope); + Delete(qparm); qparm = ty; } vparm = Swig_symbol_template_param_eval(qparm, st); - StringAppend(qprefix,vparm); + StringAppend(qprefix, vparm); ti = Next(ti); if (ti.item) { - StringPutc(',',qprefix); + StringPutc(',', qprefix); } Delete(qparm); Delete(vparm); } - StringAppend(qprefix,")>"); - StringAppend(qprefix,tsuffix); + StringAppend(qprefix, ")>"); + StringAppend(qprefix, tsuffix); Delete(tprefix); Delete(tsuffix); Delete(targs); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_temp_qual %s %s\n", e, qprefix); + Printf(stderr, "symbol_temp_qual %s %s\n", e, qprefix); #endif #ifdef SWIG_TEMPLATE_QUALIFY_CACHE - Setattr(qualify_cache,scopetype,qprefix); + Setattr(qualify_cache, scopetype, qprefix); Delete(scopetype); #endif @@ -1410,77 +1408,76 @@ Swig_symbol_template_qualify(const SwigType *e, Symtab *st) { } -SwigType * -Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { - List *elements; +SwigType *Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { + List *elements; String *result = NewStringEmpty(); - int i,len; - char *c = Char(t); - if (strncmp(c,"::",2) == 0) { + int i, len; + char *c = Char(t); + if (strncmp(c, "::", 2) == 0) { StringAppend(result, t); return result; - } + } elements = SwigType_split(t); len = Len(elements); for (i = 0; i < len; i++) { - String *e = Getitem(elements,i); + String *e = Getitem(elements, i); if (SwigType_issimple(e)) { - Node *n = Swig_symbol_clookup_check(e,st,no_constructor); + Node *n = Swig_symbol_clookup_check(e, st, no_constructor); if (n) { - String *name = HashGetAttr(n,k_name); + String *name = HashGetAttr(n, k_name); Clear(e); - StringAppend(e,name); + StringAppend(e, name); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_qual_ei %d %s %s %x\n", i, name, e, st); + Printf(stderr, "symbol_qual_ei %d %s %s %x\n", i, name, e, st); #endif if (!Swig_scopename_check(name)) { String *qname = Swig_symbol_qualified(n); if (qname && StringLen(qname)) { - Insert(e,0,k_coloncolon); - Insert(e,0,qname); + Insert(e, 0, k_coloncolon); + Insert(e, 0, qname); } #ifdef SWIG_DEBUG - Printf(stderr,"symbol_qual_sc %d %s %s %x\n", i, qname, e, st); + Printf(stderr, "symbol_qual_sc %d %s %s %x\n", i, qname, e, st); #endif Delete(qname); } } else if (SwigType_istemplate(e)) { - SwigType *ty = Swig_symbol_template_qualify(e,st); + SwigType *ty = Swig_symbol_template_qualify(e, st); Clear(e); - StringAppend(e,ty); - Delete(ty); + StringAppend(e, ty); + Delete(ty); } - if (strncmp(StringChar(e),"::",2) == 0) { - Delitem(e,0); - Delitem(e,0); + if (strncmp(StringChar(e), "::", 2) == 0) { + Delitem(e, 0); + Delitem(e, 0); } - StringAppend(result,e); + StringAppend(result, e); } else if (SwigType_isfunction(e)) { List *parms = SwigType_parmlist(e); String *s = NewString("f("); Iterator pi = First(parms); while (pi.item) { - String *pf = Swig_symbol_type_qualify(pi.item,st); - StringAppend(s,pf); + String *pf = Swig_symbol_type_qualify(pi.item, st); + StringAppend(s, pf); pi = Next(pi); if (pi.item) { - StringAppend(s,","); + StringAppend(s, ","); } Delete(pf); } - StringAppend(s,")."); - StringAppend(result,s); + StringAppend(s, ")."); + StringAppend(result, s); Delete(parms); Delete(s); } else { - StringAppend(result,e); + StringAppend(result, e); } } Delete(elements); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_qualify %s %s %x %s\n", t, result, st, st ?HashGetAttr(st,k_name): 0); + Printf(stderr, "symbol_qualify %s %s %x %s\n", t, result, st, st ? HashGetAttr(st, k_name) : 0); #endif return result; @@ -1492,47 +1489,46 @@ Swig_symbol_type_qualify(const SwigType *t, Symtab *st) { * Chase a typedef through symbol tables looking for a match. * ----------------------------------------------------------------------------- */ -static -SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) -{ +static +SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) { Parm *p; List *parms = SwigType_parmlist(qt); Iterator pi = First(parms); String *tprefix = SwigType_templateprefix(qt); String *tsuffix = SwigType_templatesuffix(qt); String *qprefix = SwigType_typedef_qualified(tprefix); - StringAppend(qprefix,"<("); + StringAppend(qprefix, "<("); while ((p = pi.item)) { String *np; String *tp = Swig_symbol_typedef_reduce(p, ntab); String *qp = Swig_symbol_type_qualify(tp, ntab); - Node *n = Swig_symbol_clookup(qp,ntab); + Node *n = Swig_symbol_clookup(qp, ntab); if (n) { String *qual = Swig_symbol_qualified(n); - np = Copy(HashGetAttr(n,k_name)); + np = Copy(HashGetAttr(n, k_name)); Delete(tp); tp = np; if (qual && StringLen(qual)) { - Insert(np,0,k_coloncolon); - Insert(np,0,qual); + Insert(np, 0, k_coloncolon); + Insert(np, 0, qual); } Delete(qual); } else { np = qp; } - StringAppend(qprefix,np); - pi= Next(pi); + StringAppend(qprefix, np); + pi = Next(pi); if (pi.item) { - StringAppend(qprefix,","); + StringAppend(qprefix, ","); } Delete(qp); Delete(tp); } - StringAppend(qprefix,")>"); - StringAppend(qprefix,tsuffix); - Delete(parms); - Delete(tprefix); - Delete(tsuffix); + StringAppend(qprefix, ")>"); + StringAppend(qprefix, tsuffix); + Delete(parms); + Delete(tprefix); + Delete(tsuffix); return qprefix; } @@ -1545,79 +1541,79 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { base = SwigType_base(ty); prefix = SwigType_prefix(ty); - n = Swig_symbol_clookup(base,tab); + n = Swig_symbol_clookup(base, tab); if (!n) { if (SwigType_istemplate(ty)) { - SwigType *qt = Swig_symbol_template_reduce(base,tab); - StringAppend(prefix,qt); + SwigType *qt = Swig_symbol_template_reduce(base, tab); + StringAppend(prefix, qt); Delete(qt); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_reduce %s %s\n", ty, prefix); + Printf(stderr, "symbol_reduce %s %s\n", ty, prefix); #endif Delete(base); return prefix; } else { Delete(prefix); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_reduce %s %s\n", ty, ty); + Printf(stderr, "symbol_reduce %s %s\n", ty, ty); #endif return Copy(ty); } } - nt = HashGetAttr(n,k_nodetype); - if (StringEqual(nt,k_using)) { - String *uname = HashGetAttr(n,k_uname); + nt = HashGetAttr(n, k_nodetype); + if (StringEqual(nt, k_using)) { + String *uname = HashGetAttr(n, k_uname); if (uname) { - n = Swig_symbol_clookup(base,HashGetAttr(n,k_symsymtab)); + n = Swig_symbol_clookup(base, HashGetAttr(n, k_symsymtab)); if (!n) { Delete(base); Delete(prefix); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_reduce %s %s\n", ty, ty); + Printf(stderr, "symbol_reduce %s %s\n", ty, ty); #endif return Copy(ty); } - } + } } - if (StringEqual(nt,k_cdecl)) { - String *storage = HashGetAttr(n,k_storage); - if (storage && (StringEqual(storage,k_typedef))) { + if (StringEqual(nt, k_cdecl)) { + String *storage = HashGetAttr(n, k_storage); + if (storage && (StringEqual(storage, k_typedef))) { SwigType *decl; SwigType *rt; SwigType *qt; Symtab *ntab; - SwigType *nt = Copy(HashGetAttr(n,k_type)); - + SwigType *nt = Copy(HashGetAttr(n, k_type)); + /* Fix for case 'typedef struct Hello hello;' */ - { - const char* dclass[3] = {"struct ", "union ", "class "}; + { + const char *dclass[3] = { "struct ", "union ", "class " }; int i; - char * c = StringChar(nt); - for (i=0; i<3; i++) { + char *c = StringChar(nt); + for (i = 0; i < 3; i++) { if (strstr(c, dclass[i]) == c) { - Replace(nt,dclass[i],"", DOH_REPLACE_FIRST); + Replace(nt, dclass[i], "", DOH_REPLACE_FIRST); } } } - decl = HashGetAttr(n,k_decl); + decl = HashGetAttr(n, k_decl); if (decl) { - SwigType_push(nt,decl); + SwigType_push(nt, decl); } - SwigType_push(nt,prefix); + SwigType_push(nt, prefix); Delete(base); Delete(prefix); - ntab = HashGetAttr(n,k_symsymtab); + ntab = HashGetAttr(n, k_symsymtab); rt = Swig_symbol_typedef_reduce(nt, ntab); qt = Swig_symbol_type_qualify(rt, ntab); if (SwigType_istemplate(qt)) { - SwigType *qtr = Swig_symbol_template_reduce(qt,ntab); + SwigType *qtr = Swig_symbol_template_reduce(qt, ntab); Delete(qt); qt = qtr; - } + } Delete(nt); Delete(rt); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_reduce %s %s\n", qt, ty); + Printf(stderr, "symbol_reduce %s %s\n", qt, ty); #endif return qt; } @@ -1625,7 +1621,7 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { Delete(base); Delete(prefix); #ifdef SWIG_DEBUG - Printf(stderr,"symbol_reduce %s %s\n", ty, ty); + Printf(stderr, "symbol_reduce %s %s\n", ty, ty); #endif return Copy(ty); } @@ -1639,31 +1635,30 @@ SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) { * and so forth. * ----------------------------------------------------------------------------- */ -String * -Swig_symbol_string_qualify(String *s, Symtab *st) { +String *Swig_symbol_string_qualify(String *s, Symtab *st) { int have_id = 0; String *id = NewStringEmpty(); String *r = NewStringEmpty(); char *c = StringChar(s); while (*c) { - if (isalpha((int)*c) || (*c == '_') || (*c == ':')) { - StringPutc(*c,id); + if (isalpha((int) *c) || (*c == '_') || (*c == ':')) { + StringPutc(*c, id); have_id = 1; } else { if (have_id) { - String *qid = Swig_symbol_type_qualify(id,st); - StringAppend(r,qid); + String *qid = Swig_symbol_type_qualify(id, st); + StringAppend(r, qid); Clear(id); Delete(qid); have_id = 0; } - StringPutc(*c,r); + StringPutc(*c, r); } c++; } if (have_id) { - String *qid = Swig_symbol_type_qualify(id,st); - StringAppend(r,qid); + String *qid = Swig_symbol_type_qualify(id, st); + StringAppend(r, qid); Delete(qid); } Delete(id); @@ -1678,48 +1673,48 @@ Swig_symbol_string_qualify(String *s, Symtab *st) { * ----------------------------------------------------------------------------- */ -void -Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl) { +void Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl) { if (Len(parms) < Len(targs)) { Parm *lp = parms; Parm *p = lp; Parm *tp = targs; - while(p && tp) { + while (p && tp) { p = nextSibling(p); tp = nextSibling(tp); - if (p) lp = p; + if (p) + lp = p; } while (tp) { - String *value = HashGetAttr(tp,k_value); + String *value = HashGetAttr(tp, k_value); if (value) { Parm *cp; Parm *ta = targs; Parm *p = parms; - SwigType *nt = Swig_symbol_string_qualify(value,tsdecl); + SwigType *nt = Swig_symbol_string_qualify(value, tsdecl); SwigType *ntq = 0; #ifdef SWIG_DEBUG - Printf(stderr,"value %s %s %s\n",value, nt,tsdecl ? HashGetAttr(tsdecl,k_name) : tsdecl); + Printf(stderr, "value %s %s %s\n", value, nt, tsdecl ? HashGetAttr(tsdecl, k_name) : tsdecl); #endif - while(p && ta) { - String *name = HashGetAttr(ta,k_name); - String *pvalue = HashGetAttr(p,k_value); - String *value = pvalue ? pvalue : HashGetAttr(p,k_type); - String *ttq = Swig_symbol_type_qualify(value,tscope); - /* value = SwigType_typedef_resolve_all(value);*/ + while (p && ta) { + String *name = HashGetAttr(ta, k_name); + String *pvalue = HashGetAttr(p, k_value); + String *value = pvalue ? pvalue : HashGetAttr(p, k_type); + String *ttq = Swig_symbol_type_qualify(value, tscope); + /* value = SwigType_typedef_resolve_all(value); */ Replaceid(nt, name, ttq); p = nextSibling(p); ta = nextSibling(ta); Delete(ttq); } - ntq = Swig_symbol_type_qualify(nt,tsdecl); + ntq = Swig_symbol_type_qualify(nt, tsdecl); if (SwigType_istemplate(ntq)) { String *ty = Swig_symbol_template_deftype(ntq, tscope); Delete(ntq); ntq = ty; } - /* Printf(stderr,"value %s %s %s\n",value,ntr,ntq);*/ - cp = NewParm(ntq,0); - set_nextSibling(lp,cp); + /* Printf(stderr,"value %s %s %s\n",value,ntr,ntq); */ + cp = NewParm(ntq, 0); + set_nextSibling(lp, cp); lp = cp; tp = nextSibling(tp); Delete(cp); @@ -1739,112 +1734,110 @@ Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *t * ----------------------------------------------------------------------------- */ #define SWIG_TEMPLATE_DEFTYPE_CACHE -SwigType* -Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) { - String *result = NewStringEmpty(); - List *elements = SwigType_split(type); - int len = Len(elements); - int i; +SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) { + String *result = NewStringEmpty(); + List *elements = SwigType_split(type); + int len = Len(elements); + int i; #ifdef SWIG_TEMPLATE_DEFTYPE_CACHE static Hash *deftype_cache = 0; - String *scopetype = tscope ? NewStringf("%s::%s",Getattr(tscope,k_name),type) - : NewStringf("%s::%s",Swig_symbol_getscopename(),type); + String *scopetype = tscope ? NewStringf("%s::%s", Getattr(tscope, k_name), type) + : NewStringf("%s::%s", Swig_symbol_getscopename(), type); if (!deftype_cache) { deftype_cache = NewHash(); } if (scopetype) { String *cres = Getattr(deftype_cache, scopetype); if (cres) { - Append(result,cres); + Append(result, cres); Delete(scopetype); return result; - } + } } #endif #ifdef SWIG_DEBUG - Printf(stderr,"finding deftype %s\n", type); + Printf(stderr, "finding deftype %s\n", type); #endif for (i = 0; i < len; i++) { - String *e = Getitem(elements,i); + String *e = Getitem(elements, i); if (SwigType_isfunction(e)) { String *s = NewString("f("); List *parms = SwigType_parmlist(e); Iterator pi = First(parms); while (pi.item) { - String *pf = SwigType_istemplate(e) ? - Swig_symbol_template_deftype(pi.item,tscope) - : Swig_symbol_type_qualify(pi.item,tscope); - StringAppend(s,pf); + String *pf = SwigType_istemplate(e) ? Swig_symbol_template_deftype(pi.item, tscope) + : Swig_symbol_type_qualify(pi.item, tscope); + StringAppend(s, pf); pi = Next(pi); if (pi.item) { - StringAppend(s,","); + StringAppend(s, ","); } Delete(pf); } - StringAppend(s,")."); - StringAppend(result,s); + StringAppend(s, ")."); + StringAppend(result, s); Delete(s); Delete(parms); } else if (SwigType_istemplate(e)) { - String *prefix = SwigType_prefix(e); - String *base = SwigType_base(e); - String *tprefix = SwigType_templateprefix(base); - String *targs = SwigType_templateargs(base); - String *tsuffix = SwigType_templatesuffix(base); + String *prefix = SwigType_prefix(e); + String *base = SwigType_base(e); + String *tprefix = SwigType_templateprefix(base); + String *targs = SwigType_templateargs(base); + String *tsuffix = SwigType_templatesuffix(base); ParmList *tparms = SwigType_function_parms(targs); - Node *tempn = Swig_symbol_clookup_local(tprefix,tscope); + Node *tempn = Swig_symbol_clookup_local(tprefix, tscope); if (!tempn && tsuffix && Len(tsuffix)) { - tempn = Swig_symbol_clookup(tprefix,0); + tempn = Swig_symbol_clookup(tprefix, 0); } - #ifdef SWIG_DEBUG - Printf(stderr,"deftype type %s %s %d\n", e, tprefix, (long) tempn); + Printf(stderr, "deftype type %s %s %d\n", e, tprefix, (long) tempn); #endif if (tempn) { - ParmList *tnargs = HashGetAttr(tempn,k_templateparms); + ParmList *tnargs = HashGetAttr(tempn, k_templateparms); Parm *p; - Symtab *tsdecl = HashGetAttr(tempn,k_symsymtab); - + Symtab *tsdecl = HashGetAttr(tempn, k_symsymtab); + #ifdef SWIG_DEBUG - Printf(stderr,"deftype type %s %s %s\n", tprefix, targs,tsuffix); + Printf(stderr, "deftype type %s %s %s\n", tprefix, targs, tsuffix); #endif - StringAppend(tprefix,"<("); - Swig_symbol_template_defargs(tparms, tnargs,tscope,tsdecl); + StringAppend(tprefix, "<("); + Swig_symbol_template_defargs(tparms, tnargs, tscope, tsdecl); p = tparms; tscope = tsdecl; while (p) { - SwigType *ptype = HashGetAttr(p,k_type); - SwigType *ttr = ptype ? ptype : HashGetAttr(p,k_value); - SwigType *ttf = Swig_symbol_type_qualify(ttr,tscope); - SwigType *ttq = Swig_symbol_template_param_eval(ttf,tscope); + SwigType *ptype = HashGetAttr(p, k_type); + SwigType *ttr = ptype ? ptype : HashGetAttr(p, k_value); + SwigType *ttf = Swig_symbol_type_qualify(ttr, tscope); + SwigType *ttq = Swig_symbol_template_param_eval(ttf, tscope); #ifdef SWIG_DEBUG - Printf(stderr,"arg type %s\n", ttq); + Printf(stderr, "arg type %s\n", ttq); #endif if (SwigType_istemplate(ttq)) { SwigType *ttd = Swig_symbol_template_deftype(ttq, tscope); Delete(ttq); ttq = ttd; #ifdef SWIG_DEBUG - Printf(stderr,"arg deftype %s\n", ttq); + Printf(stderr, "arg deftype %s\n", ttq); #endif - } - StringAppend(tprefix,ttq); + } + StringAppend(tprefix, ttq); p = nextSibling(p); - if (p) StringPutc(',',tprefix); + if (p) + StringPutc(',', tprefix); Delete(ttf); Delete(ttq); } - StringAppend(tprefix,")>"); - StringAppend(tprefix,tsuffix); - StringAppend(prefix,tprefix); + StringAppend(tprefix, ")>"); + StringAppend(tprefix, tsuffix); + StringAppend(prefix, tprefix); #ifdef SWIG_DEBUG - Printf(stderr,"deftype %s %s \n", type, tprefix); + Printf(stderr, "deftype %s %s \n", type, tprefix); #endif - StringAppend(result,prefix); + StringAppend(result, prefix); } else { - StringAppend(result,e); + StringAppend(result, e); } Delete(prefix); Delete(base); @@ -1853,34 +1846,34 @@ Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope) { Delete(targs); Delete(tparms); } else { - StringAppend(result,e); + StringAppend(result, e); } } Delete(elements); #ifdef SWIG_TEMPLATE_DEFTYPE_CACHE - Setattr(deftype_cache,scopetype,result); + Setattr(deftype_cache, scopetype, result); Delete(scopetype); #endif return result; } -SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) -{ +SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) { String *value = Copy(p); Node *lastnode = 0; while (1) { - Node *n = Swig_symbol_clookup(value,symtab); - if (n == lastnode) break; + Node *n = Swig_symbol_clookup(value, symtab); + if (n == lastnode) + break; lastnode = n; if (n) { - String *nt = HashGetAttr(n,k_nodetype); - if (StringEqual(nt,k_enumitem)) { + String *nt = HashGetAttr(n, k_nodetype); + if (StringEqual(nt, k_enumitem)) { /* An enum item. Generate a fully qualified name */ String *qn = Swig_symbol_qualified(n); if (qn && StringLen(qn)) { - StringAppend(qn,k_coloncolon); - StringAppend(qn,HashGetAttr(n,k_name)); + StringAppend(qn, k_coloncolon); + StringAppend(qn, HashGetAttr(n, k_name)); Delete(value); value = qn; continue; @@ -1888,8 +1881,8 @@ SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) Delete(qn); break; } - } else if ((StringEqual(nt,k_cdecl))) { - String *nv = HashGetAttr(n,k_value); + } else if ((StringEqual(nt, k_cdecl))) { + String *nv = HashGetAttr(n, k_value); if (nv) { Delete(value); value = Copy(nv); @@ -1901,6 +1894,3 @@ SwigType *Swig_symbol_template_param_eval(const SwigType *p, Symtab *symtab) } return value; } - - - diff --git a/SWIG/Source/Swig/tree.c b/SWIG/Source/Swig/tree.c index 7726784ef..7b0b62ac1 100644 --- a/SWIG/Source/Swig/tree.c +++ b/SWIG/Source/Swig/tree.c @@ -21,20 +21,21 @@ char cvsroot_tree_c[] = "$Header$"; * Dump the tag structure of a parse tree to standard output * ----------------------------------------------------------------------------- */ -void -Swig_print_tags(DOH *obj, DOH *root) { +void Swig_print_tags(DOH *obj, DOH *root) { DOH *croot, *newroot; DOH *cobj; - if (!root) croot = NewStringEmpty(); - else croot = root; + if (!root) + croot = NewStringEmpty(); + else + croot = root; while (obj) { - Printf(stdout,"%s . %s (%s:%d)\n", croot, nodeType(obj), Getfile(obj), Getline(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); + newroot = NewStringf("%s . %s", croot, nodeType(obj)); + Swig_print_tags(cobj, newroot); Delete(newroot); } obj = nextSibling(obj); @@ -61,36 +62,34 @@ static void print_indent(int l) { * Swig_print_node(Node *n) * ----------------------------------------------------------------------------- */ -void -Swig_print_node(Node *obj) { +void Swig_print_node(Node *obj) { Iterator ki; - Node *cobj; + Node *cobj; print_indent(0); - Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj)); + Printf(stdout, "+++ %s ----------------------------------------\n", nodeType(obj)); ki = First(obj); while (ki.key) { String *k = ki.key; - if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) || - (Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) || - (Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) { + if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) || + (Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) { /* Do nothing */ - } else if (Cmp(k,"parms") == 0) { + } else if (Cmp(k, "parms") == 0) { print_indent(2); - Printf(stdout,"%-12s - %s\n", k, ParmList_protostr(Getattr(obj,k))); + Printf(stdout, "%-12s - %s\n", k, ParmList_protostr(Getattr(obj, k))); } else { DOH *o; char *trunc = ""; print_indent(2); - if (DohIsString(Getattr(obj,k))) { - o = Str(Getattr(obj,k)); + if (DohIsString(Getattr(obj, k))) { + o = Str(Getattr(obj, k)); if (Len(o) > 40) { trunc = "..."; } - Printf(stdout,"%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc); + Printf(stdout, "%-12s - \"%(escape)-0.40s%s\"\n", k, o, trunc); Delete(o); } else { - Printf(stdout,"%-12s - 0x%x\n", k, Getattr(obj,k)); + Printf(stdout, "%-12s - 0x%x\n", k, Getattr(obj, k)); } } ki = Next(ki); @@ -98,12 +97,12 @@ Swig_print_node(Node *obj) { cobj = firstChild(obj); if (cobj) { indent_level += 6; - Printf(stdout,"\n"); + Printf(stdout, "\n"); Swig_print_tree(cobj); indent_level -= 6; } else { print_indent(1); - Printf(stdout,"\n"); + Printf(stdout, "\n"); } } @@ -113,8 +112,7 @@ Swig_print_node(Node *obj) { * Dump the tree structure of a parse tree to standard output * ----------------------------------------------------------------------------- */ -void -Swig_print_tree(DOH *obj) { +void Swig_print_tree(DOH *obj) { while (obj) { Swig_print_node(obj); obj = nextSibling(obj); @@ -127,25 +125,25 @@ Swig_print_tree(DOH *obj) { * Appends a new child to a node * ----------------------------------------------------------------------------- */ -void -appendChild(Node *node, Node *chd) { +void appendChild(Node *node, Node *chd) { Node *lc; - if (!chd) return; + if (!chd) + return; lc = lastChild(node); if (!lc) { - set_firstChild(node,chd); + set_firstChild(node, chd); } else { - set_nextSibling(lc,chd); - set_previousSibling(chd,lc); + set_nextSibling(lc, chd); + set_previousSibling(chd, lc); } while (chd) { lc = chd; - set_parentNode(chd,node); + set_parentNode(chd, node); chd = nextSibling(chd); } - set_lastChild(node,lc); + set_lastChild(node, lc); } /* ----------------------------------------------------------------------------- @@ -154,20 +152,20 @@ appendChild(Node *node, Node *chd) { * Preppends a new child to a node * ----------------------------------------------------------------------------- */ -void -preppendChild(Node *node, Node *chd) { +void preppendChild(Node *node, Node *chd) { Node *fc; - if (!chd) return; + if (!chd) + return; fc = firstChild(node); if (fc) { - set_nextSibling(chd,fc); - set_previousSibling(fc,chd); + set_nextSibling(chd, fc); + set_previousSibling(fc, chd); } - set_firstChild(node,chd); + set_firstChild(node, chd); while (chd) { - set_parentNode(chd,node); + set_parentNode(chd, node); chd = nextSibling(chd); } } @@ -178,8 +176,7 @@ preppendChild(Node *node, Node *chd) { * Deletes a node. * ----------------------------------------------------------------------------- */ -void -deleteNode(Node *n) { +void deleteNode(Node *n) { Node *parent; Node *prev; Node *next; @@ -188,17 +185,17 @@ deleteNode(Node *n) { prev = previousSibling(n); next = nextSibling(n); if (prev) { - set_nextSibling(prev,next); + set_nextSibling(prev, next); } else { if (parent) { - set_firstChild(parent,next); + set_firstChild(parent, next); } } if (next) { - set_previousSibling(next,prev); + set_previousSibling(next, prev); } else { if (parent) { - set_lastChild(parent,prev); + set_lastChild(parent, prev); } } } @@ -209,17 +206,16 @@ deleteNode(Node *n) { * Copies a node, but only copies simple attributes (no lists, hashes). * ----------------------------------------------------------------------------- */ -Node * -copyNode(Node *n) { +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)); + Setattr(c, ki.key, Copy(ki.item)); } } - Setfile(c,Getfile(n)); - Setline(c,Getline(n)); + Setfile(c, Getfile(n)); + Setline(c, Getline(n)); return c; } @@ -230,11 +226,10 @@ copyNode(Node *n) { * subtypes with extra information. * ----------------------------------------------------------------------------- */ -void -Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { +void Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { while (n) { - Setattr(n,attrname,value); - Swig_tag_nodes(firstChild(n),attrname, value); + Setattr(n, attrname, value); + Swig_tag_nodes(firstChild(n), attrname, value); n = nextSibling(n); } } @@ -243,10 +238,9 @@ Swig_tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { * checkAttribute() * ----------------------------------------------------------------------------- */ -int -checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) { - String *v = Getattr(n,name); - return v ? Equal(v,value) : 0; +int checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) { + String *v = Getattr(n, name); + return v ? Equal(v, value) : 0; } /* ----------------------------------------------------------------------------- @@ -263,8 +257,7 @@ checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) * This function can be called more than once with different namespaces. * ----------------------------------------------------------------------------- */ -int -Swig_require(const char *ns, Node *n, ...) { +int Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; @@ -282,13 +275,13 @@ Swig_require(const char *ns, Node *n, ...) { opt = 1; name++; } - obj = Getattr(n,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)); + 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 (!obj) + obj = DohNone; if (newref) { /* Save a copy of the attribute */ Setattr(n, NewStringf("%s:%s", ns, name), obj); @@ -299,14 +292,14 @@ Swig_require(const char *ns, Node *n, ...) { /* Save the view */ { - String *view = Getattr(n,k_view); + String *view = Getattr(n, k_view); if (view) { - if (Strcmp(view,ns) != 0) { + if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); - Setattr(n,k_view,ns); + Setattr(n, k_view, ns); } } else { - Setattr(n,k_view,ns); + Setattr(n, k_view, ns); } } @@ -320,8 +313,7 @@ Swig_require(const char *ns, Node *n, ...) { * are saved, ie behaves as if all the attribute names were prefixed by ?. * ----------------------------------------------------------------------------- */ -int -Swig_save(const char *ns, Node *n, ...) { +int Swig_save(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; @@ -334,12 +326,13 @@ Swig_save(const char *ns, Node *n, ...) { } else if (*name == '?') { name++; } - obj = Getattr(n,name); - if (!obj) obj = DohNone; + obj = Getattr(n, name); + if (!obj) + obj = DohNone; /* Save a copy of the attribute */ if (Setattr(n, NewStringf("%s:%s", ns, name), obj)) { - Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name); + Printf(stderr, "Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name); } name = va_arg(ap, char *); } @@ -347,14 +340,14 @@ Swig_save(const char *ns, Node *n, ...) { /* Save the view */ { - String *view = Getattr(n,k_view); + String *view = Getattr(n, k_view); if (view) { - if (Strcmp(view,ns) != 0) { + if (Strcmp(view, ns) != 0) { Setattr(n, NewStringf("%s:view", ns), view); - Setattr(n,k_view,ns); + Setattr(n, k_view, ns); } } else { - Setattr(n,k_view,ns); + Setattr(n, k_view, ns); } } @@ -366,15 +359,14 @@ Swig_save(const char *ns, Node *n, ...) { * Restores attributes saved by a previous call to Swig_require() or Swig_save(). * ----------------------------------------------------------------------------- */ -void -Swig_restore(Node *n) { +void Swig_restore(Node *n) { String *temp; - int len; - List *l; + int len; + List *l; String *ns; Iterator ki; - ns = Getattr(n,k_view); + ns = Getattr(n, k_view); assert(ns); l = NewList(); @@ -384,16 +376,14 @@ Swig_restore(Node *n) { for (ki = First(n); ki.key; ki = Next(ki)) { if (Strncmp(temp, ki.key, len) == 0) { - Append(l,ki.key); + Append(l, ki.key); } } for (ki = First(l); ki.item; ki = Next(ki)) { - DOH *obj = Getattr(n,ki.item); - Setattr(n,Char(ki.item)+len,obj); - Delattr(n,ki.item); + DOH *obj = Getattr(n, ki.item); + Setattr(n, Char(ki.item) + len, obj); + Delattr(n, ki.item); } Delete(l); Delete(temp); } - - diff --git a/SWIG/Source/Swig/typemap.c b/SWIG/Source/Swig/typemap.c index a5139c352..88e30362d 100644 --- a/SWIG/Source/Swig/typemap.c +++ b/SWIG/Source/Swig/typemap.c @@ -15,7 +15,7 @@ char cvsroot_typemap_c[] = "$Header$"; #include #if 0 -#define SWIG_DEBUG +#define SWIG_DEBUG #endif static void replace_embedded_typemap(String *s); @@ -47,50 +47,48 @@ static void replace_embedded_typemap(String *s); static Hash *typemaps[MAX_SCOPE]; -static int tm_scope = 0; +static int tm_scope = 0; -static Hash* get_typemap(int tm_scope, SwigType* type) -{ - Hash *tm = 0; - SwigType* dtype = 0; +static Hash *get_typemap(int tm_scope, SwigType *type) { + Hash *tm = 0; + SwigType *dtype = 0; if (SwigType_istemplate(type)) { - String *ty = Swig_symbol_template_deftype(type,0); - dtype = Swig_symbol_type_qualify(ty,0); - /* Printf(stderr,"gettm %s %s\n", type, dtype);*/ + String *ty = Swig_symbol_template_deftype(type, 0); + dtype = Swig_symbol_type_qualify(ty, 0); + /* Printf(stderr,"gettm %s %s\n", type, dtype); */ type = dtype; Delete(ty); } - tm = Getattr(typemaps[tm_scope],type); + tm = Getattr(typemaps[tm_scope], type); + - if (dtype) { if (!tm) { String *t_name = SwigType_templateprefix(type); - if (!Equal(t_name,type)) { - tm = Getattr(typemaps[tm_scope],t_name); + if (!Equal(t_name, type)) { + tm = Getattr(typemaps[tm_scope], t_name); } Delete(t_name); - } + } Delete(dtype); } - + return tm; } -static void set_typemap(int tm_scope, SwigType* type, Hash* tm) -{ - SwigType* dtype = 0; +static void set_typemap(int tm_scope, SwigType *type, Hash *tm) { + SwigType *dtype = 0; if (SwigType_istemplate(type)) { - String *ty = Swig_symbol_template_deftype(type,0); - dtype = Swig_symbol_type_qualify(ty,0); - /* Printf(stderr,"settm %s %s\n", type, dtype);*/ - type = dtype; + String *ty = Swig_symbol_template_deftype(type, 0); + dtype = Swig_symbol_type_qualify(ty, 0); + /* Printf(stderr,"settm %s %s\n", type, dtype); */ + type = dtype; Delete(ty); } else { dtype = Copy(type); type = dtype; } - Setattr(typemaps[tm_scope],type,tm); + Setattr(typemaps[tm_scope], type, tm); Delete(dtype); } @@ -116,21 +114,23 @@ static String *tmop_name(const String_or_char *op) { /* Due to "interesting" object-identity semantics of DOH, we have to make sure that we only intern strings without object identity into the hash table. - + (Swig_typemap_attach_kwargs calls tmop_name several times with the "same" String *op (i.e., same object identity) but differing string values.) Most other callers work around this by using char* rather than String *. - -- mkoeppe, Jun 17, 2003 - */ + -- mkoeppe, Jun 17, 2003 + */ const char *op_without_object_identity = Char(op); - if (!names) names = NewHash(); + if (!names) + names = NewHash(); s = Getattr(names, op_without_object_identity); - if (s) return s; - s = NewStringf("tmap:%s",op); - Setattr(names,op_without_object_identity,s); + if (s) + return s; + s = NewStringf("tmap:%s", op); + Setattr(names, op_without_object_identity, s); Delete(s); return s; } @@ -152,8 +152,7 @@ void Swig_typemap_new_scope() { * Pop the last typemap scope off * ----------------------------------------------------------------------------- */ -Hash * -Swig_typemap_pop_scope() { +Hash *Swig_typemap_pop_scope() { if (tm_scope > 0) { return typemaps[tm_scope--]; } @@ -166,47 +165,47 @@ Swig_typemap_pop_scope() { * Add a new multi-valued typemap * ----------------------------------------------------------------------------- */ -void -Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char *code, ParmList *locals, ParmList *kwargs) { +void Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char *code, ParmList *locals, ParmList *kwargs) { Hash *tm; Hash *tm1; Hash *tm2; Parm *np; String *tmop; SwigType *type; - String *pname; + String *pname; - if (!parms) return; + if (!parms) + return; tmop = tmop_name(op); /* Register the first type in the parameter list */ - type = Getattr(parms,k_type); - pname = Getattr(parms,k_name); + type = Getattr(parms, k_type); + pname = Getattr(parms, k_name); /* See if this type has been seen before */ - tm = get_typemap(tm_scope,type); + tm = get_typemap(tm_scope, type); if (!tm) { tm = NewHash(); - set_typemap(tm_scope,type,tm); + set_typemap(tm_scope, type, tm); Delete(tm); } if (pname) { /* See if parameter has been seen before */ - tm1 = Getattr(tm,pname); + tm1 = Getattr(tm, pname); if (!tm1) { tm1 = NewHash(); - Setattr(tm,pname,tm1); + Setattr(tm, pname, tm1); Delete(tm1); } tm = tm1; } /* Now see if this typemap op has been seen before */ - tm2 = Getattr(tm,tmop); + tm2 = Getattr(tm, tmop); if (!tm2) { tm2 = NewHash(); - Setattr(tm,tmop,tm2); + Setattr(tm, tmop, tm2); Delete(tm2); } @@ -217,46 +216,46 @@ Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char For example, consider this typemap - %typemap(in) (int foo, int *bar, char *blah[]) { - ... - } + %typemap(in) (int foo, int *bar, char *blah[]) { + ... + } To store it, we look at typemaps for the following: - operator type-name - ---------------------------------------------- - "in" int foo - "in-int+foo:" int *bar - "in-int+foo:-p.int+bar: char *blah[] + operator type-name + ---------------------------------------------- + "in" int foo + "in-int+foo:" int *bar + "in-int+foo:-p.int+bar: char *blah[] Notice how the operator expands to encode information about previous arguments. - */ + */ np = nextSibling(parms); if (np) { /* Make an entirely new operator key */ - String *newop = NewStringf("%s-%s+%s:",op,type,pname); + String *newop = NewStringf("%s-%s+%s:", op, type, pname); /* Now reregister on the remaining arguments */ - Swig_typemap_register(newop,np,code,locals,kwargs); - + Swig_typemap_register(newop, np, code, locals, kwargs); + /* Setattr(tm2,newop,newop); */ Delete(newop); } else { - String *str = SwigType_str(type,pname); + String *str = SwigType_str(type, pname); String *typemap = NewStringf("typemap(%s) %s", op, str); ParmList *clocals = CopyParmList(locals); ParmList *ckwargs = CopyParmList(kwargs); - - Setattr(tm2,k_code, code); - Setattr(tm2,k_type, type); - Setattr(tm2,k_typemap, typemap); + + Setattr(tm2, k_code, code); + Setattr(tm2, k_type, type); + Setattr(tm2, k_typemap, typemap); if (pname) { - Setattr(tm2,k_pname, pname); + Setattr(tm2, k_pname, pname); } - Setattr(tm2,k_locals, clocals); - Setattr(tm2,k_kwargs, ckwargs); + Setattr(tm2, k_locals, clocals); + Setattr(tm2, k_kwargs, ckwargs); Delete(clocals); Delete(ckwargs); @@ -272,12 +271,12 @@ Swig_typemap_register(const String_or_char *op, ParmList *parms, String_or_char * Retrieve typemap information from current scope. * ----------------------------------------------------------------------------- */ -static Hash * -Swig_typemap_get(SwigType *type, String_or_char *name, int scope) { +static Hash *Swig_typemap_get(SwigType *type, String_or_char *name, int scope) { Hash *tm, *tm1; /* See if this type has been seen before */ - if ((scope < 0) || (scope > tm_scope)) return 0; - tm = get_typemap(scope,type); + if ((scope < 0) || (scope > tm_scope)) + return 0; + tm = get_typemap(scope, type); if (!tm) { return 0; } @@ -294,8 +293,7 @@ Swig_typemap_get(SwigType *type, String_or_char *name, int scope) { * Copy a typemap * ----------------------------------------------------------------------------- */ -int -Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) { +int Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) { Hash *tm = 0; String *tmop; Parm *p; @@ -303,25 +301,28 @@ Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) SwigType *ptype; int ts = tm_scope; String *tmops, *newop; - if (ParmList_len(parms) != ParmList_len(srcparms)) return -1; + if (ParmList_len(parms) != ParmList_len(srcparms)) + return -1; tmop = tmop_name(op); while (ts >= 0) { p = srcparms; tmops = NewString(tmop); while (p) { - ptype = Getattr(p,k_type); - pname = Getattr(p,k_name); - + ptype = Getattr(p, k_type); + pname = Getattr(p, k_name); + /* Lookup the type */ - tm = Swig_typemap_get(ptype,pname,ts); - if (!tm) break; - - tm = Getattr(tm,tmops); - if (!tm) break; + tm = Swig_typemap_get(ptype, pname, ts); + if (!tm) + break; + + tm = Getattr(tm, tmops); + if (!tm) + break; /* Got a match. Look for next typemap */ - newop = NewStringf("%s-%s+%s:",tmops,ptype,pname); + newop = NewStringf("%s-%s+%s:", tmops, ptype, pname); Delete(tmops); tmops = newop; p = nextSibling(p); @@ -331,7 +332,7 @@ Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) if (!p && tm) { /* Got some kind of match */ - Swig_typemap_register(op,parms, Getattr(tm,k_code), Getattr(tm,k_locals),Getattr(tm,k_kwargs)); + Swig_typemap_register(op, parms, Getattr(tm, k_code), Getattr(tm, k_locals), Getattr(tm, k_kwargs)); return 0; } ts--; @@ -347,32 +348,32 @@ Swig_typemap_copy(const String_or_char *op, ParmList *srcparms, ParmList *parms) * Delete a multi-valued typemap * ----------------------------------------------------------------------------- */ -void -Swig_typemap_clear(const String_or_char *op, ParmList *parms) { +void Swig_typemap_clear(const String_or_char *op, ParmList *parms) { SwigType *type; - String *name; - Parm *p; - String *newop; + String *name; + Parm *p; + String *newop; Hash *tm = 0; /* This might not work */ newop = NewString(op); p = parms; while (p) { - type = Getattr(p,k_type); - name = Getattr(p,k_name); - tm = Swig_typemap_get(type,name,tm_scope); - if (!tm) return; + type = Getattr(p, k_type); + name = Getattr(p, k_name); + tm = Swig_typemap_get(type, name, tm_scope); + if (!tm) + return; p = nextSibling(p); - if (p) - Printf(newop,"-%s+%s:", type,name); + if (p) + Printf(newop, "-%s+%s:", type, name); } if (tm) { tm = Getattr(tm, tmop_name(newop)); if (tm) { - Delattr(tm,k_code); - Delattr(tm,k_locals); - Delattr(tm,k_kwargs); + Delattr(tm, k_code); + Delattr(tm, k_locals); + Delattr(tm, k_kwargs); } } Delete(newop); @@ -391,21 +392,21 @@ int count_args(String *s) { int na = 0; char *c = Char(s); while (*c) { - if (*c == '+') na++; + if (*c == '+') + na++; c++; } return na; } -int -Swig_typemap_apply(ParmList *src, ParmList *dest) { +int Swig_typemap_apply(ParmList *src, ParmList *dest) { String *ssig, *dsig; - Parm *p, *np, *lastp, *dp, *lastdp = 0; - int narg = 0; - int ts = tm_scope; + Parm *p, *np, *lastp, *dp, *lastdp = 0; + int narg = 0; + int ts = tm_scope; SwigType *type = 0, *name; - Hash *tm, *sm; - int match = 0; + Hash *tm, *sm; + int match = 0; /* Printf(stdout,"apply : %s --> %s\n", ParmList_str(src), ParmList_str(dest)); */ @@ -420,8 +421,8 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { lastdp = dp; np = nextSibling(p); if (np) { - Printf(ssig,"-%s+%s:", Getattr(p,k_type), Getattr(p,k_name)); - Printf(dsig,"-%s+%s:", Getattr(dp,k_type), Getattr(dp,k_name)); + Printf(ssig, "-%s+%s:", Getattr(p, k_type), Getattr(p, k_name)); + Printf(dsig, "-%s+%s:", Getattr(dp, k_type), Getattr(dp, k_name)); narg++; } p = np; @@ -429,19 +430,19 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { } /* make sure a typemap node exists for the last destination node */ - type = Getattr(lastdp,k_type); - tm = get_typemap(tm_scope,type); + type = Getattr(lastdp, k_type); + tm = get_typemap(tm_scope, type); if (!tm) { tm = NewHash(); - set_typemap(tm_scope,type,tm); + set_typemap(tm_scope, type, tm); Delete(tm); } - name = Getattr(lastdp,k_name); + name = Getattr(lastdp, k_name); if (name) { - Hash *tm1 = Getattr(tm,name); + Hash *tm1 = Getattr(tm, name); if (!tm1) { tm1 = NewHash(); - Setattr(tm,NewString(name),tm1); + Setattr(tm, NewString(name), tm1); Delete(tm1); } tm = tm1; @@ -450,57 +451,57 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { /* This is a little nasty. We need to go searching for all possible typemaps in the source and apply them to the target */ - type = Getattr(lastp,k_type); - name = Getattr(lastp,k_name); + type = Getattr(lastp, k_type); + name = Getattr(lastp, k_name); while (ts >= 0) { /* See if there is a matching typemap in this scope */ - sm = Swig_typemap_get(type,name,ts); + sm = Swig_typemap_get(type, name, ts); /* if there is not matching, look for a typemap in the original typedef, if any, like in: - typedef unsigned long size_t; - ... - %apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size}; - */ + typedef unsigned long size_t; + ... + %apply(size_t) {my_size}; ==> %apply(unsigned long) {my_size}; + */ if (!sm) { SwigType *ntype = SwigType_typedef_resolve(type); - if (ntype && (Cmp(ntype,type) != 0)) { - sm = Swig_typemap_get(ntype,name,ts); + if (ntype && (Cmp(ntype, type) != 0)) { + sm = Swig_typemap_get(ntype, name, ts); } Delete(ntype); } - + if (sm) { /* Got a typemap. Need to only merge attributes for methods that match our signature */ Iterator ki; match = 1; for (ki = First(sm); ki.key; ki = Next(ki)) { /* Check for a signature match with the source signature */ - if ((count_args(ki.key) == narg) && (Strstr(ki.key,ssig))) { + if ((count_args(ki.key) == narg) && (Strstr(ki.key, ssig))) { String *oldm; /* A typemap we have to copy */ String *nkey = Copy(ki.key); - Replace(nkey,ssig,dsig,DOH_REPLACE_ANY); + Replace(nkey, ssig, dsig, DOH_REPLACE_ANY); /* Make sure the typemap doesn't already exist in the target map */ - - oldm = Getattr(tm,nkey); - if (!oldm || (!Getattr(tm,k_code))) { + + oldm = Getattr(tm, nkey); + if (!oldm || (!Getattr(tm, k_code))) { String *code; ParmList *locals; ParmList *kwargs; Hash *sm1 = ki.item; - code = Getattr(sm1,k_code); - locals = Getattr(sm1,k_locals); - kwargs = Getattr(sm1,k_kwargs); + code = Getattr(sm1, k_code); + locals = Getattr(sm1, k_locals); + kwargs = Getattr(sm1, k_kwargs); if (code) { - Replace(nkey,dsig,"", DOH_REPLACE_ANY); - Replace(nkey,"tmap:","", DOH_REPLACE_ANY); - Swig_typemap_register(nkey,dest,code,locals,kwargs); + Replace(nkey, dsig, "", DOH_REPLACE_ANY); + Replace(nkey, "tmap:", "", DOH_REPLACE_ANY); + Swig_typemap_register(nkey, dest, code, locals, kwargs); } } Delete(nkey); @@ -521,12 +522,11 @@ Swig_typemap_apply(ParmList *src, ParmList *dest) { * ----------------------------------------------------------------------------- */ /* Multi-argument %clear directive */ -void -Swig_typemap_clear_apply(Parm *parms) { +void Swig_typemap_clear_apply(Parm *parms) { String *tsig; - Parm *p, *np, *lastp; - int narg = 0; - Hash *tm; + Parm *p, *np, *lastp; + int narg = 0; + Hash *tm; String *name; /* Create a type signature of the parameters */ @@ -537,19 +537,19 @@ Swig_typemap_clear_apply(Parm *parms) { lastp = p; np = nextSibling(p); if (np) { - Printf(tsig,"-%s+%s:", Getattr(p,k_type), Getattr(p,k_name)); + Printf(tsig, "-%s+%s:", Getattr(p, k_type), Getattr(p, k_name)); narg++; } p = np; } - tm = get_typemap(tm_scope,Getattr(lastp,k_type)); + tm = get_typemap(tm_scope, Getattr(lastp, k_type)); if (!tm) { Delete(tsig); return; } - name = Getattr(lastp,k_name); + name = Getattr(lastp, k_name); if (name) { - tm = Getattr(tm,name); + tm = Getattr(tm, name); } if (tm) { /* Clear typemaps that match our signature */ @@ -557,12 +557,12 @@ Swig_typemap_clear_apply(Parm *parms) { char *ctsig = Char(tsig); for (ki = First(tm); ki.key; ki = Next(ki)) { char *ckey = Char(ki.key); - if (strncmp(ckey,"tmap:",5) == 0) { + if (strncmp(ckey, "tmap:", 5) == 0) { int na = count_args(ki.key); - if ((na == narg) && strstr(ckey,ctsig)) { + if ((na == narg) && strstr(ckey, ctsig)) { Hash *h = ki.item; for (ki2 = First(h); ki2.key; ki2 = Next(ki2)) { - Delattr(h,ki2.key); + Delattr(h, ki2.key); } } } @@ -579,7 +579,7 @@ static SwigType *strip_arrays(SwigType *type) { t = Copy(type); ndim = SwigType_array_ndim(t); for (i = 0; i < ndim; i++) { - SwigType_array_setdim(t,i,"ANY"); + SwigType_array_setdim(t, i, "ANY"); } return t; } @@ -591,8 +591,7 @@ static SwigType *strip_arrays(SwigType *type) { * that includes a 'code' attribute. * ----------------------------------------------------------------------------- */ -Hash * -Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_char *name, SwigType **matchtype) { +Hash *Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_char *name, SwigType **matchtype) { Hash *result = 0, *tm, *tm1, *tma; Hash *backup = 0; SwigType *noarrays = 0; @@ -602,28 +601,33 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch int isarray; const String *cname = 0; SwigType *unstripped = 0; - String *tmop = tmop_name(op); + String *tmop = tmop_name(op); - if ((name) && Len(name)) cname = name; + if ((name) && Len(name)) + cname = name; ts = tm_scope; while (ts >= 0) { ctype = type; while (ctype) { /* Try to get an exact type-match */ - tm = get_typemap(ts,ctype); + tm = get_typemap(ts, ctype); if (tm && cname) { - tm1 = Getattr(tm,cname); + tm1 = Getattr(tm, cname); if (tm1) { - result = Getattr(tm1,tmop); /* See if there is a type-name match */ - if (result && Getattr(result,k_code)) goto ret_result; - if (result) backup = result; + result = Getattr(tm1, tmop); /* See if there is a type-name match */ + if (result && Getattr(result, k_code)) + goto ret_result; + if (result) + backup = result; } } if (tm) { - result = Getattr(tm,tmop); /* See if there is simply a type match */ - if (result && Getattr(result,k_code)) goto ret_result; - if (result) backup = result; + result = Getattr(tm, tmop); /* See if there is simply a type match */ + if (result && Getattr(result, k_code)) + goto ret_result; + if (result) + backup = result; } isarray = SwigType_isarray(ctype); if (isarray) { @@ -632,31 +636,36 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch if (!noarrays) { noarrays = strip_arrays(ctype); } - tma = get_typemap(ts,noarrays); + tma = get_typemap(ts, noarrays); if (tma && cname) { - tm1 = Getattr(tma,cname); + tm1 = Getattr(tma, cname); if (tm1) { - result = Getattr(tm1,tmop); /* type-name match */ - if (result && Getattr(result,k_code)) goto ret_result; - if (result) backup = result; + result = Getattr(tm1, tmop); /* type-name match */ + if (result && Getattr(result, k_code)) + goto ret_result; + if (result) + backup = result; } } if (tma) { - result = Getattr(tma,tmop); /* type match */ - if (result && Getattr(result,k_code)) goto ret_result; - if (result) backup = result; + result = Getattr(tma, tmop); /* type match */ + if (result && Getattr(result, k_code)) + goto ret_result; + if (result) + backup = result; } Delete(noarrays); noarrays = 0; } - + /* No match so far. If the type is unstripped, we'll strip its qualifiers and check. Otherwise, we'll try to resolve a typedef */ if (!unstripped) { unstripped = ctype; ctype = SwigType_strip_qualifiers(ctype); - if (!StringEqual(ctype,unstripped)) continue; /* Types are different */ + if (!StringEqual(ctype, unstripped)) + continue; /* Types are different */ Delete(ctype); ctype = unstripped; unstripped = 0; @@ -664,13 +673,14 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch { String *octype; if (unstripped) { - Delete(ctype); + Delete(ctype); ctype = unstripped; unstripped = 0; } octype = ctype; ctype = SwigType_typedef_resolve(ctype); - if (octype != type) Delete(octype); + if (octype != type) + Delete(octype); } } @@ -678,17 +688,19 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch primitive = SwigType_default(type); while (primitive) { - tm = get_typemap(ts,primitive); + tm = get_typemap(ts, primitive); if (tm && cname) { - tm1 = Getattr(tm,cname); + tm1 = Getattr(tm, cname); if (tm1) { - result = Getattr(tm1,tmop); /* See if there is a type-name match */ - if (result) goto ret_result; + result = Getattr(tm1, tmop); /* See if there is a type-name match */ + if (result) + goto ret_result; } } if (tm) { /* See if there is simply a type match */ - result = Getattr(tm,tmop); - if (result) goto ret_result; + result = Getattr(tm, tmop); + if (result) + goto ret_result; } { SwigType *nprim = SwigType_default(primitive); @@ -696,19 +708,26 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch primitive = nprim; } } - if (ctype != type) { Delete(ctype); ctype = 0; } - ts--; /* Hmmm. Nothing found in this scope. Guess we'll go try another scope */ + if (ctype != type) { + Delete(ctype); + ctype = 0; + } + ts--; /* Hmmm. Nothing found in this scope. Guess we'll go try another scope */ } result = backup; - ret_result: - if (noarrays) Delete(noarrays); - if (primitive) Delete(primitive); - if ((unstripped) && (unstripped != type)) Delete(unstripped); +ret_result: + if (noarrays) + Delete(noarrays); + if (primitive) + Delete(primitive); + if ((unstripped) && (unstripped != type)) + Delete(unstripped); if (matchtype) { *matchtype = Copy(ctype); } - if (type != ctype) Delete(ctype); + if (type != ctype) + Delete(ctype); return result; } @@ -719,32 +738,32 @@ Swig_typemap_search(const String_or_char *op, SwigType *type, const String_or_ch * Search for a multi-valued typemap. * ----------------------------------------------------------------------------- */ -Hash * -Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch) { +Hash *Swig_typemap_search_multi(const String_or_char *op, ParmList *parms, int *nmatch) { SwigType *type; SwigType *mtype = 0; - String *name; - String *newop; - Hash *tm, *tm1; + String *name; + String *newop; + Hash *tm, *tm1; if (!parms) { *nmatch = 0; return 0; } - type = Getattr(parms,k_type); - name = Getattr(parms,k_name); + type = Getattr(parms, k_type); + name = Getattr(parms, k_name); /* Try to find a match on the first type */ tm = Swig_typemap_search(op, type, name, &mtype); if (tm) { if (mtype && SwigType_isarray(mtype)) { - Setattr(parms,k_tmapmatch, mtype); + Setattr(parms, k_tmapmatch, mtype); } Delete(mtype); - newop = NewStringf("%s-%s+%s:", op, type,name); + newop = NewStringf("%s-%s+%s:", op, type, name); tm1 = Swig_typemap_search_multi(newop, nextSibling(parms), nmatch); - if (tm1) tm = tm1; - if (Getattr(tm,k_code)) { + if (tm1) + tm = tm1; + if (Getattr(tm, k_code)) { *(nmatch) = *nmatch + 1; } else { tm = 0; @@ -766,8 +785,8 @@ static void replace_local_types(ParmList *p, const String *name, const String *rep) { SwigType *t; while (p) { - t = Getattr(p,k_type); - Replace(t,name,rep,DOH_REPLACE_ANY); + t = Getattr(p, k_type); + Replace(t, name, rep, DOH_REPLACE_ANY); p = nextSibling(p); } } @@ -775,76 +794,81 @@ void replace_local_types(ParmList *p, const String *name, const String *rep) { static int check_locals(ParmList *p, const char *s) { while (p) { - char *c = GetChar(p,"type"); - if (strstr(c,s)) return 1; + char *c = GetChar(p, "type"); + if (strstr(c, s)) + return 1; p = nextSibling(p); } return 0; } static -void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType *rtype, String *pname, String *lname, int index) -{ +void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType *rtype, String *pname, String *lname, int index) { char var[512]; char *varname; SwigType *ftype; - Replaceall(s,"$typemap","$TYPEMAP"); + Replaceall(s, "$typemap", "$TYPEMAP"); ftype = SwigType_typedef_resolve_all(type); - if (!pname) pname = lname; + if (!pname) + pname = lname; { Parm *p; - int rep = 0; + int rep = 0; p = locals; while (p) { - if (Strchr(Getattr(p,k_type),'$')) rep = 1; + if (Strchr(Getattr(p, k_type), '$')) + rep = 1; p = nextSibling(p); } - if (!rep) locals = 0; + if (!rep) + locals = 0; } - - sprintf(var,"$%d_",index); + + sprintf(var, "$%d_", index); varname = &var[strlen(var)]; - + /* If the original datatype was an array. We're going to go through and substitute its array dimensions */ - + if (SwigType_isarray(type) || SwigType_isarray(ftype)) { String *size; int ndim; int i; - if (SwigType_array_ndim(type) != SwigType_array_ndim(ftype)) type = ftype; + if (SwigType_array_ndim(type) != SwigType_array_ndim(ftype)) + type = ftype; ndim = SwigType_array_ndim(type); size = NewStringEmpty(); for (i = 0; i < ndim; i++) { - String *dim = SwigType_array_getdim(type,i); + String *dim = SwigType_array_getdim(type, i); if (index == 1) { char t[32]; - sprintf(t,"$dim%d",i); - Replace(s,t,dim,DOH_REPLACE_ANY); - replace_local_types(locals,t,dim); + sprintf(t, "$dim%d", i); + Replace(s, t, dim, DOH_REPLACE_ANY); + replace_local_types(locals, t, dim); } - sprintf(varname,"dim%d",i); - Replace(s,var,dim,DOH_REPLACE_ANY); - replace_local_types(locals,var,dim); - if (Len(size)) Putc('*',size); - Append(size,dim); + sprintf(varname, "dim%d", i); + Replace(s, var, dim, DOH_REPLACE_ANY); + replace_local_types(locals, var, dim); + if (Len(size)) + Putc('*', size); + Append(size, dim); Delete(dim); } - sprintf(varname,"size"); - Replace(s,var,size,DOH_REPLACE_ANY); - replace_local_types(locals,var,size); + sprintf(varname, "size"); + Replace(s, var, size, DOH_REPLACE_ANY); + replace_local_types(locals, var, size); Delete(size); } /* Parameter name substitution */ if (index == 1) { - Replace(s,"$parmname",pname, DOH_REPLACE_ANY); + Replace(s, "$parmname", pname, DOH_REPLACE_ANY); } - strcpy(varname,"name"); - Replace(s,var,pname,DOH_REPLACE_ANY); + strcpy(varname, "name"); + Replace(s, var, pname, DOH_REPLACE_ANY); /* Type-related stuff */ { @@ -853,66 +877,66 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType String *mangle, *star_mangle, *amp_mangle, *base_mangle, *base_name; String *descriptor, *star_descriptor, *amp_descriptor; String *ts; - char *sc; + char *sc; sc = Char(s); - if (strstr(sc,"type") || check_locals(locals,"type")) { + if (strstr(sc, "type") || check_locals(locals, "type")) { /* Given type : $type */ - ts = SwigType_str(type,0); + ts = SwigType_str(type, 0); if (index == 1) { Replace(s, "$type", ts, DOH_REPLACE_ANY); - replace_local_types(locals,"$type",type); + replace_local_types(locals, "$type", type); } - strcpy(varname,"type"); - Replace(s,var,ts,DOH_REPLACE_ANY); - replace_local_types(locals,var,type); + strcpy(varname, "type"); + Replace(s, var, ts, DOH_REPLACE_ANY); + replace_local_types(locals, var, type); Delete(ts); sc = Char(s); } - if (strstr(sc,"ltype") || check_locals(locals,"ltype")) { + if (strstr(sc, "ltype") || check_locals(locals, "ltype")) { /* Local type: $ltype */ ltype = SwigType_ltype(type); - ts = SwigType_str(ltype,0); + ts = SwigType_str(ltype, 0); if (index == 1) { Replace(s, "$ltype", ts, DOH_REPLACE_ANY); - replace_local_types(locals,"$ltype",ltype); + replace_local_types(locals, "$ltype", ltype); } - strcpy(varname,"ltype"); - Replace(s,var,ts,DOH_REPLACE_ANY); - replace_local_types(locals,var,ltype); + strcpy(varname, "ltype"); + Replace(s, var, ts, DOH_REPLACE_ANY); + replace_local_types(locals, var, ltype); Delete(ts); Delete(ltype); sc = Char(s); } - if (strstr(sc,"mangle") || strstr(sc,"descriptor")) { + if (strstr(sc, "mangle") || strstr(sc, "descriptor")) { /* Mangled type */ - + mangle = SwigType_manglestr(type); if (index == 1) Replace(s, "$mangle", mangle, DOH_REPLACE_ANY); - strcpy(varname,"mangle"); - Replace(s,var,mangle,DOH_REPLACE_ANY); - + strcpy(varname, "mangle"); + Replace(s, var, mangle, DOH_REPLACE_ANY); + descriptor = NewStringf("SWIGTYPE%s", mangle); if (index == 1) if (Replace(s, "$descriptor", descriptor, DOH_REPLACE_ANY)) SwigType_remember(type); - - strcpy(varname,"descriptor"); - if (Replace(s,var,descriptor,DOH_REPLACE_ANY)) + + strcpy(varname, "descriptor"); + if (Replace(s, var, descriptor, DOH_REPLACE_ANY)) SwigType_remember(type); - + Delete(descriptor); Delete(mangle); } - + /* One pointer level removed */ /* This creates variables of the form - $*n_type - $*n_ltype - */ + $*n_type + $*n_ltype + */ if (SwigType_ispointer(ftype) || (SwigType_isarray(ftype)) || (SwigType_isreference(ftype))) { if (!(SwigType_isarray(type) || SwigType_ispointer(type) || SwigType_isreference(type))) { @@ -926,96 +950,93 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType } else { SwigType_del_pointer(star_type); } - ts = SwigType_str(star_type,0); + ts = SwigType_str(star_type, 0); if (index == 1) { Replace(s, "$*type", ts, DOH_REPLACE_ANY); - replace_local_types(locals,"$*type",star_type); + replace_local_types(locals, "$*type", star_type); } - sprintf(varname,"$*%d_type",index); - Replace(s,varname,ts,DOH_REPLACE_ANY); - replace_local_types(locals,varname,star_type); + sprintf(varname, "$*%d_type", index); + Replace(s, varname, ts, DOH_REPLACE_ANY); + replace_local_types(locals, varname, star_type); Delete(ts); } else { SwigType_del_element(star_type); } star_ltype = SwigType_ltype(star_type); - ts = SwigType_str(star_ltype,0); + ts = SwigType_str(star_ltype, 0); if (index == 1) { Replace(s, "$*ltype", ts, DOH_REPLACE_ANY); - replace_local_types(locals,"$*ltype",star_ltype); + replace_local_types(locals, "$*ltype", star_ltype); } - sprintf(varname,"$*%d_ltype",index); - Replace(s,varname,ts,DOH_REPLACE_ANY); - replace_local_types(locals,varname,star_ltype); + sprintf(varname, "$*%d_ltype", index); + Replace(s, varname, ts, DOH_REPLACE_ANY); + replace_local_types(locals, varname, star_ltype); Delete(ts); Delete(star_ltype); - + star_mangle = SwigType_manglestr(star_type); - if (index == 1) + if (index == 1) Replace(s, "$*mangle", star_mangle, DOH_REPLACE_ANY); - - sprintf(varname,"$*%d_mangle",index); - Replace(s,varname,star_mangle,DOH_REPLACE_ANY); - + + sprintf(varname, "$*%d_mangle", index); + Replace(s, varname, star_mangle, DOH_REPLACE_ANY); + star_descriptor = NewStringf("SWIGTYPE%s", star_mangle); if (index == 1) - if (Replace(s, "$*descriptor", - star_descriptor, DOH_REPLACE_ANY)) + if (Replace(s, "$*descriptor", star_descriptor, DOH_REPLACE_ANY)) SwigType_remember(star_type); - sprintf(varname,"$*%d_descriptor",index); - if (Replace(s,varname,star_descriptor,DOH_REPLACE_ANY)) + sprintf(varname, "$*%d_descriptor", index); + if (Replace(s, varname, star_descriptor, DOH_REPLACE_ANY)) SwigType_remember(star_type); - + Delete(star_descriptor); Delete(star_mangle); Delete(star_type); - } - else { + } else { /* TODO: Signal error if one of the $* substitutions is - requested */ + requested */ } /* One pointer level added */ amp_type = Copy(type); SwigType_add_pointer(amp_type); - ts = SwigType_str(amp_type,0); + ts = SwigType_str(amp_type, 0); if (index == 1) { Replace(s, "$&type", ts, DOH_REPLACE_ANY); - replace_local_types(locals,"$&type",amp_type); + replace_local_types(locals, "$&type", amp_type); } - sprintf(varname,"$&%d_type",index); - Replace(s,varname,ts,DOH_REPLACE_ANY); - replace_local_types(locals,varname,amp_type); + sprintf(varname, "$&%d_type", index); + Replace(s, varname, ts, DOH_REPLACE_ANY); + replace_local_types(locals, varname, amp_type); Delete(ts); - + amp_ltype = SwigType_ltype(type); SwigType_add_pointer(amp_ltype); - ts = SwigType_str(amp_ltype,0); - + ts = SwigType_str(amp_ltype, 0); + if (index == 1) { Replace(s, "$<ype", ts, DOH_REPLACE_ANY); replace_local_types(locals, "$<ype", amp_ltype); } - sprintf(varname,"$&%d_ltype",index); - Replace(s,varname,ts,DOH_REPLACE_ANY); - replace_local_types(locals,varname,amp_ltype); + sprintf(varname, "$&%d_ltype", index); + Replace(s, varname, ts, DOH_REPLACE_ANY); + replace_local_types(locals, varname, amp_ltype); Delete(ts); Delete(amp_ltype); - + amp_mangle = SwigType_manglestr(amp_type); - if (index == 1) + if (index == 1) Replace(s, "$&mangle", amp_mangle, DOH_REPLACE_ANY); - sprintf(varname,"$&%d_mangle",index); - Replace(s,varname,amp_mangle,DOH_REPLACE_ANY); - + sprintf(varname, "$&%d_mangle", index); + Replace(s, varname, amp_mangle, DOH_REPLACE_ANY); + amp_descriptor = NewStringf("SWIGTYPE%s", amp_mangle); - if (index == 1) - if (Replace(s, "$&descriptor", - amp_descriptor, DOH_REPLACE_ANY)) + if (index == 1) + if (Replace(s, "$&descriptor", amp_descriptor, DOH_REPLACE_ANY)) SwigType_remember(amp_type); - sprintf(varname,"$&%d_descriptor",index); - if (Replace(s,varname,amp_descriptor,DOH_REPLACE_ANY)) + sprintf(varname, "$&%d_descriptor", index); + if (Replace(s, varname, amp_descriptor, DOH_REPLACE_ANY)) SwigType_remember(amp_type); - + Delete(amp_descriptor); Delete(amp_mangle); Delete(amp_type); @@ -1024,7 +1045,7 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType if (SwigType_isarray(type)) { SwigType *bt = Copy(type); Delete(SwigType_pop_arrays(bt)); - base_type = SwigType_str(bt,0); + base_type = SwigType_str(bt, 0); Delete(bt); } else { base_type = SwigType_base(type); @@ -1032,41 +1053,41 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType base_name = SwigType_namestr(base_type); if (index == 1) { - Replace(s,"$basetype", base_name, DOH_REPLACE_ANY); - replace_local_types(locals,"$basetype", base_name); + Replace(s, "$basetype", base_name, DOH_REPLACE_ANY); + replace_local_types(locals, "$basetype", base_name); } - strcpy(varname,"basetype"); - Replace(s,var,base_type,DOH_REPLACE_ANY); - replace_local_types(locals,var,base_name); - + strcpy(varname, "basetype"); + Replace(s, var, base_type, DOH_REPLACE_ANY); + replace_local_types(locals, var, base_name); + base_mangle = SwigType_manglestr(base_type); if (index == 1) - Replace(s,"$basemangle", base_mangle, DOH_REPLACE_ANY); - strcpy(varname,"basemangle"); - Replace(s,var,base_mangle,DOH_REPLACE_ANY); + Replace(s, "$basemangle", base_mangle, DOH_REPLACE_ANY); + strcpy(varname, "basemangle"); + Replace(s, var, base_mangle, DOH_REPLACE_ANY); Delete(base_mangle); Delete(base_type); Delete(base_name); - + lex_type = SwigType_base(rtype); if (index == 1) - Replace(s,"$lextype", lex_type, DOH_REPLACE_ANY); - strcpy(varname,"lextype"); - Replace(s,var,lex_type,DOH_REPLACE_ANY); + Replace(s, "$lextype", lex_type, DOH_REPLACE_ANY); + strcpy(varname, "lextype"); + Replace(s, var, lex_type, DOH_REPLACE_ANY); Delete(lex_type); } - + /* Replace any $n. with (&n)-> */ { char temp[64]; - sprintf(var,"$%d.",index); - sprintf(temp,"(&$%d)->", index); - Replace(s,var,temp,DOH_REPLACE_ANY); + sprintf(var, "$%d.", index); + sprintf(temp, "(&$%d)->", index); + Replace(s, var, temp, DOH_REPLACE_ANY); } /* Replace the bare $n variable */ - sprintf(var,"$%d",index); - Replace(s,var,lname,DOH_REPLACE_ANY); + sprintf(var, "$%d", index); + Replace(s, var, lname, DOH_REPLACE_ANY); Delete(ftype); } @@ -1077,60 +1098,63 @@ void typemap_replace_vars(String *s, ParmList *locals, SwigType *type, SwigType * creates the local variables. * ------------------------------------------------------------------------ */ -static void typemap_locals(DOHString *s, ParmList *l, Wrapper *f, int argnum) { +static void typemap_locals(DOHString * s, ParmList *l, Wrapper *f, int argnum) { Parm *p; char *new_name; p = l; while (p) { - SwigType *pt = Getattr(p,k_type); + SwigType *pt = Getattr(p, k_type); SwigType *at = SwigType_alttype(pt, 1); - String *pn = Getattr(p,k_name); - String *value = Getattr(p,k_value); - if (at) pt = at; + String *pn = Getattr(p, k_name); + String *value = Getattr(p, k_value); + if (at) + pt = at; if (pn) { if (Len(pn) > 0) { String *str; - int isglobal = 0; + int isglobal = 0; str = NewStringEmpty(); - if (strncmp(Char(pn),"_global_",8) == 0) { - isglobal = 1; + if (strncmp(Char(pn), "_global_", 8) == 0) { + isglobal = 1; } /* If the user gave us $type as the name of the local variable, we'll use the passed datatype instead */ if ((argnum >= 0) && (!isglobal)) { - Printf(str,"%s%d",pn,argnum); + Printf(str, "%s%d", pn, argnum); } else { - StringAppend(str,pn); + StringAppend(str, pn); } - if (isglobal && Wrapper_check_local(f,str)) { - p = nextSibling(p); - Delete(str); - if (at) Delete(at); - continue; + if (isglobal && Wrapper_check_local(f, str)) { + p = nextSibling(p); + Delete(str); + if (at) + Delete(at); + continue; } if (value) { - String *pstr = SwigType_str(pt,str); - new_name = Wrapper_new_localv(f,str, pstr, "=", value, NIL); + String *pstr = SwigType_str(pt, str); + new_name = Wrapper_new_localv(f, str, pstr, "=", value, NIL); Delete(pstr); } else { - String *pstr = SwigType_str(pt,str); - new_name = Wrapper_new_localv(f,str, pstr, NIL); + String *pstr = SwigType_str(pt, str); + new_name = Wrapper_new_localv(f, str, pstr, NIL); Delete(pstr); } if (!isglobal) { - /* Substitute */ - Replace(s,pn,new_name,DOH_REPLACE_ID | DOH_REPLACE_NOQUOTE); + /* Substitute */ + Replace(s, pn, new_name, DOH_REPLACE_ID | DOH_REPLACE_NOQUOTE); } Delete(str); } } p = nextSibling(p); - if (at) Delete(at); + if (at) + Delete(at); } } @@ -1141,58 +1165,59 @@ static void typemap_locals(DOHString *s, ParmList *l, Wrapper *f, int argnum) { * ----------------------------------------------------------------------------- */ String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_char *pname, - String_or_char *lname, String_or_char *source, - String_or_char *target, Wrapper *f) -{ - Hash *tm; + String_or_char *lname, String_or_char *source, String_or_char *target, Wrapper *f) { + Hash *tm; String *s = 0; SwigType *mtype = 0; ParmList *locals; - tm = Swig_typemap_search(op,type,pname,&mtype); - if (!tm) return 0; + tm = Swig_typemap_search(op, type, pname, &mtype); + if (!tm) + return 0; - s = Getattr(tm,k_code); + s = Getattr(tm, k_code); if (!s) { - if (mtype) Delete(mtype); + if (mtype) + Delete(mtype); return 0; } - + /* Blocked */ - if (Cmp(s,"pass") == 0) { + if (Cmp(s, "pass") == 0) { Delete(mtype); return 0; } - s = Copy(s); /* Make a local copy of the typemap code */ + s = Copy(s); /* Make a local copy of the typemap code */ - locals = Getattr(tm,k_locals); - if (locals) locals = CopyParmList(locals); + locals = Getattr(tm, k_locals); + if (locals) + locals = CopyParmList(locals); /* This is wrong. It replaces locals in place. Need to fix this */ if (mtype && SwigType_isarray(mtype)) { - typemap_replace_vars(s,locals,mtype,type,pname,lname,1); + typemap_replace_vars(s, locals, mtype, type, pname, lname, 1); } else { - typemap_replace_vars(s,locals,type,type,pname,lname,1); + typemap_replace_vars(s, locals, type, type, pname, lname, 1); } if (locals && f) { - typemap_locals(s,locals,f,-1); + typemap_locals(s, locals, f, -1); } - replace_embedded_typemap(s); + replace_embedded_typemap(s); /* Now perform character replacements */ - Replace(s,"$source",source,DOH_REPLACE_ANY); - Replace(s,"$target",target,DOH_REPLACE_ANY); + Replace(s, "$source", source, DOH_REPLACE_ANY); + Replace(s, "$target", target, DOH_REPLACE_ANY); /* { - String *tmname = Getattr(tm,"typemap"); - if (tmname) Replace(s,"$typemap",tmname, DOH_REPLACE_ANY); - } - */ + String *tmname = Getattr(tm,"typemap"); + if (tmname) Replace(s,"$typemap",tmname, DOH_REPLACE_ANY); + } + */ - Replace(s,"$parmname",pname, DOH_REPLACE_ANY); + Replace(s, "$parmname", pname, DOH_REPLACE_ANY); /* Replace(s,"$name",pname,DOH_REPLACE_ANY); */ Delete(locals); @@ -1210,48 +1235,47 @@ String *Swig_typemap_lookup(const String_or_char *op, SwigType *type, String_or_ * f - * ----------------------------------------------------------------------------- */ -String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const String_or_char *lname, Wrapper *f) -{ +String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const String_or_char *lname, Wrapper *f) { SwigType *type; SwigType *mtype = 0; - String *pname; - Hash *tm = 0; - String *s = 0; - String *sdef = 0; + String *pname; + Hash *tm = 0; + String *s = 0; + String *sdef = 0; ParmList *locals; ParmList *kw; - char temp[256]; - String *symname; - String *cname = 0; - String *clname = 0; - char *cop = Char(op); + char temp[256]; + String *symname; + String *cname = 0; + String *clname = 0; + char *cop = Char(op); /* special case, we need to check for 'ref' call and set the default code 'sdef' */ - if (Cmp(op,"newfree") == 0) { + if (Cmp(op, "newfree") == 0) { sdef = Swig_ref_call(node, lname); } - type = Getattr(node,k_type); - if (!type) return sdef; + type = Getattr(node, k_type); + if (!type) + return sdef; - pname = Getattr(node,k_name); + pname = Getattr(node, k_name); #if 1 - if (pname && node && checkAttribute(node,k_kind,"function")) { + if (pname && node && checkAttribute(node, k_kind, "function")) { /* For functions, look qualified names first, such as - + struct Foo { - int *foo(int bar) -> Foo::foo + int *foo(int bar) -> Foo::foo }; - */ - Symtab *st = Getattr(node,k_symsymtab); + */ + Symtab *st = Getattr(node, k_symsymtab); String *qsn = st ? Swig_symbol_string_qualify(pname, st) : 0; if (qsn) { - if (StringLen(qsn) && !Equal(qsn,pname)) { - tm = Swig_typemap_search(op,type,qsn,&mtype); - if (tm && (!Getattr(tm,k_pname) || - strstr(Char(Getattr(tm,k_type)),"SWIGTYPE"))) { + if (StringLen(qsn) && !Equal(qsn, pname)) { + tm = Swig_typemap_search(op, type, qsn, &mtype); + if (tm && (!Getattr(tm, k_pname) || strstr(Char(Getattr(tm, k_type)), "SWIGTYPE"))) { tm = 0; } } @@ -1260,19 +1284,23 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri } if (!tm) #endif - tm = Swig_typemap_search(op,type,pname,&mtype); - if (!tm) return sdef; + tm = Swig_typemap_search(op, type, pname, &mtype); + if (!tm) + return sdef; - s = Getattr(tm,k_code); - if (!s) return sdef; + s = Getattr(tm, k_code); + if (!s) + return sdef; /* Empty typemap. No match */ - if (Cmp(s,"pass") == 0) return sdef; + if (Cmp(s, "pass") == 0) + return sdef; - s = Copy(s); /* Make a local copy of the typemap code */ + s = Copy(s); /* Make a local copy of the typemap code */ - locals = Getattr(tm,k_locals); - if (locals) locals = CopyParmList(locals); + locals = Getattr(tm, k_locals); + if (locals) + locals = CopyParmList(locals); if (pname) { if (SwigType_istemplate(pname)) { @@ -1280,58 +1308,58 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri pname = cname; } } - if (SwigType_istemplate((char*)lname)) { - clname = SwigType_namestr((char *)lname); + if (SwigType_istemplate((char *) lname)) { + clname = SwigType_namestr((char *) lname); lname = clname; } if (mtype && SwigType_isarray(mtype)) { - typemap_replace_vars(s,locals,mtype,type,pname,(char *) lname,1); + typemap_replace_vars(s, locals, mtype, type, pname, (char *) lname, 1); } else { - typemap_replace_vars(s,locals,type,type,pname,(char *) lname,1); + typemap_replace_vars(s, locals, type, type, pname, (char *) lname, 1); } if (locals && f) { - typemap_locals(s,locals,f,-1); + typemap_locals(s, locals, f, -1); } replace_embedded_typemap(s); /* { - String *tmname = Getattr(tm,"typemap"); - if (tmname) Replace(s,"$typemap",tmname, DOH_REPLACE_ANY); - }*/ + String *tmname = Getattr(tm,"typemap"); + if (tmname) Replace(s,"$typemap",tmname, DOH_REPLACE_ANY); + } */ - Replace(s,"$name",pname,DOH_REPLACE_ANY); - - symname = Getattr(node,k_symname); + Replace(s, "$name", pname, DOH_REPLACE_ANY); + + symname = Getattr(node, k_symname); if (symname) { - Replace(s,"$symname",symname, DOH_REPLACE_ANY); + Replace(s, "$symname", symname, DOH_REPLACE_ANY); } - Setattr(node,tmop_name(op),s); + Setattr(node, tmop_name(op), s); if (locals) { - sprintf(temp,"%s:locals", cop); - Setattr(node,tmop_name(temp), locals); - Delete(locals); + sprintf(temp, "%s:locals", cop); + Setattr(node, tmop_name(temp), locals); + Delete(locals); } - if (HashCheckAttr(tm,k_type,k_SWIGTYPE)) { - sprintf(temp,"%s:SWIGTYPE", cop); - Setattr(node,tmop_name(temp),k_1); + if (HashCheckAttr(tm, k_type, k_SWIGTYPE)) { + sprintf(temp, "%s:SWIGTYPE", cop); + Setattr(node, tmop_name(temp), k_1); } /* Attach kwargs */ - kw = Getattr(tm,k_kwargs); + kw = Getattr(tm, k_kwargs); while (kw) { - String *value = Copy(Getattr(kw,k_value)); - String *type = Getattr(kw,k_type); - char *ckwname = Char(Getattr(kw,k_name)); - if (type) { + String *value = Copy(Getattr(kw, k_value)); + String *type = Getattr(kw, k_type); + char *ckwname = Char(Getattr(kw, k_name)); + if (type) { String *mangle = Swig_string_mangle(type); - StringAppend(value,mangle); + StringAppend(value, mangle); Delete(mangle); } - sprintf(temp,"%s:%s",cop, ckwname); - Setattr(node,tmop_name(temp), value); + sprintf(temp, "%s:%s", cop, ckwname); + Setattr(node, tmop_name(temp), value); Delete(value); kw = nextSibling(kw); } @@ -1339,18 +1367,18 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri /* Look for warnings */ { String *w; - sprintf(temp,"%s:warning", cop); - w = Getattr(node,tmop_name(temp)); + sprintf(temp, "%s:warning", cop); + w = Getattr(node, tmop_name(temp)); if (w) { - Swig_warning(0,Getfile(node),Getline(node),"%s\n", w); + Swig_warning(0, Getfile(node), Getline(node), "%s\n", w); } } /* Look for code fragments */ { String *f; - sprintf(temp,"%s:fragment", cop); - f = Getattr(node,tmop_name(temp)); + sprintf(temp, "%s:fragment", cop); + f = Getattr(node, tmop_name(temp)); if (f) { String *fname = Copy(f); Setfile(fname, Getfile(node)); @@ -1359,11 +1387,14 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri Delete(fname); } } - - if (cname) Delete(cname); - if (clname) Delete(clname); - if (mtype) Delete(mtype); - if (sdef) { /* put 'ref' and 'newfree' codes together */ + + if (cname) + Delete(cname); + if (clname) + Delete(clname); + if (mtype) + Delete(mtype); + if (sdef) { /* put 'ref' and 'newfree' codes together */ String *p = NewStringf("%s\n%s", sdef, s); Delete(s); Delete(sdef); @@ -1383,29 +1414,28 @@ String *Swig_typemap_lookup_new(const String_or_char *op, Node *node, const Stri * A new attribute called "tmap:in:foo" with value "xyz" is attached to p. * ----------------------------------------------------------------------------- */ -void -Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) { +void Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) { String *temp = NewStringEmpty(); - Parm *kw = Getattr(tm,k_kwargs); + Parm *kw = Getattr(tm, k_kwargs); while (kw) { - String *value = Copy(Getattr(kw,k_value)); - String *type = Getattr(kw,k_type); + String *value = Copy(Getattr(kw, k_value)); + String *type = Getattr(kw, k_type); if (type) { Hash *v = NewHash(); - Setattr(v,k_type,type); - Setattr(v,k_value,value); + Setattr(v, k_type, type); + Setattr(v, k_value, value); Delete(value); value = v; } Clear(temp); - Printf(temp,"%s:%s",op,Getattr(kw,k_name)); - Setattr(p,tmop_name(temp),value); + Printf(temp, "%s:%s", op, Getattr(kw, k_name)); + Setattr(p, tmop_name(temp), value); Delete(value); kw = nextSibling(kw); } Clear(temp); - Printf(temp,"%s:match_type",op); - Setattr(p,tmop_name(temp),Getattr(tm,k_type)); + Printf(temp, "%s:match_type", op); + Setattr(p, tmop_name(temp), Getattr(tm, k_type)); Delete(temp); } @@ -1416,20 +1446,18 @@ Swig_typemap_attach_kwargs(Hash *tm, const String_or_char *op, Parm *p) { * attribute, print that warning message. * ----------------------------------------------------------------------------- */ -static void -Swig_typemap_warn(const String_or_char *op, Parm *p) { - String *temp = NewStringf("%s:warning",op); - String *w = Getattr(p,tmop_name(temp)); +static void Swig_typemap_warn(const String_or_char *op, Parm *p) { + String *temp = NewStringf("%s:warning", op); + String *w = Getattr(p, tmop_name(temp)); Delete(temp); if (w) { - Swig_warning(0,Getfile(p),Getline(p),"%s\n",w); + Swig_warning(0, Getfile(p), Getline(p), "%s\n", w); } } -static void -Swig_typemap_emit_code_fragments(const String_or_char *op, Parm *p) { - String *temp = NewStringf("%s:fragment",op); - String *f = Getattr(p,tmop_name(temp)); +static void Swig_typemap_emit_code_fragments(const String_or_char *op, Parm *p) { + String *temp = NewStringf("%s:fragment", op); + String *f = Getattr(p, tmop_name(temp)); if (f) { String *fname = Copy(f); Setfile(fname, Getfile(p)); @@ -1447,196 +1475,197 @@ Swig_typemap_emit_code_fragments(const String_or_char *op, Parm *p) { * given typemap type * ----------------------------------------------------------------------------- */ -String * -Swig_typemap_get_option(Hash *tm, String *name) -{ - Parm *kw = Getattr(tm,k_kwargs); +String *Swig_typemap_get_option(Hash *tm, String *name) { + Parm *kw = Getattr(tm, k_kwargs); while (kw) { - String *kname = Getattr(kw,k_name); - if (Equal(kname,name)) { - return Getattr(kw,k_value); + String *kname = Getattr(kw, k_name); + if (Equal(kname, name)) { + return Getattr(kw, k_value); } kw = nextSibling(kw); } return 0; } -void -Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) { +void Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) { Parm *p, *firstp; Hash *tm; - int nmatch = 0; - int i; + int nmatch = 0; + int i; String *s; ParmList *locals; - int argnum = 0; - char temp[256]; + int argnum = 0; + char temp[256]; char *cop = Char(op); String *kwmatch = 0; p = parms; #ifdef SWIG_DEBUG - Printf(stdout,"Swig_typemap_attach_parms: %s\n", op); + Printf(stdout, "Swig_typemap_attach_parms: %s\n", op); #endif while (p) { argnum++; nmatch = 0; #ifdef SWIG_DEBUG - Printf(stdout,"parms: %s %s %s\n", op, Getattr(p,k_name), Getattr(p,k_type)); + Printf(stdout, "parms: %s %s %s\n", op, Getattr(p, k_name), Getattr(p, k_type)); #endif - tm = Swig_typemap_search_multi(op,p,&nmatch); + tm = Swig_typemap_search_multi(op, p, &nmatch); #ifdef SWIG_DEBUG - if (tm) Printf(stdout,"found: %s\n", tm); + if (tm) + Printf(stdout, "found: %s\n", tm); #endif if (!tm) { p = nextSibling(p); continue; } /* - Check if the typemap requires to match the type of another - typemap, for example: + Check if the typemap requires to match the type of another + typemap, for example: - %typemap(in) SWIGTYPE * (int var) {...} - %typemap(freearg,match="in") SWIGTYPE * {if (var$argnum) ...} + %typemap(in) SWIGTYPE * (int var) {...} + %typemap(freearg,match="in") SWIGTYPE * {if (var$argnum) ...} - here, the freearg typemap requires the "in" typemap to match, - or the 'var$argnum' variable will not exist. - */ - kwmatch = Swig_typemap_get_option(tm,k_match); + here, the freearg typemap requires the "in" typemap to match, + or the 'var$argnum' variable will not exist. + */ + kwmatch = Swig_typemap_get_option(tm, k_match); if (kwmatch) { - String *tmname = NewStringf("tmap:%s",kwmatch); - String *tmin = Getattr(p,tmname); + String *tmname = NewStringf("tmap:%s", kwmatch); + String *tmin = Getattr(p, tmname); Delete(tmname); #ifdef SWIG_DEBUG - if (tm) Printf(stdout,"matching: %s\n", kwmatch); + if (tm) + Printf(stdout, "matching: %s\n", kwmatch); #endif if (tmin) { - String *tmninp = NewStringf("tmap:%s:numinputs",kwmatch); - String *ninp = Getattr(p,tmninp); + String *tmninp = NewStringf("tmap:%s:numinputs", kwmatch); + String *ninp = Getattr(p, tmninp); Delete(tmninp); if (ninp && Equal(ninp, "0")) { p = nextSibling(p); continue; } else { - SwigType *typetm = Getattr(tm,k_type); - String *temp = NewStringf("tmap:%s:match_type",kwmatch); - SwigType *typein = Getattr(p,temp); + SwigType *typetm = Getattr(tm, k_type); + String *temp = NewStringf("tmap:%s:match_type", kwmatch); + SwigType *typein = Getattr(p, temp); Delete(temp); - if (!Equal(typein,typetm)) { + if (!Equal(typein, typetm)) { p = nextSibling(p); continue; } else { int nnmatch; - Hash *tmapin = Swig_typemap_search_multi(kwmatch,p,&nnmatch); - String *tmname = Getattr(tm,k_pname); - String *tnname = Getattr(tmapin,k_pname); + Hash *tmapin = Swig_typemap_search_multi(kwmatch, p, &nnmatch); + String *tmname = Getattr(tm, k_pname); + String *tnname = Getattr(tmapin, k_pname); if (!(tmname && tnname && Equal(tmname, tnname)) && !(!tmname && !tnname)) { p = nextSibling(p); continue; } } - + } } else { p = nextSibling(p); continue; } } - - s = Getattr(tm,k_code); + + s = Getattr(tm, k_code); if (!s) { p = nextSibling(p); continue; } #ifdef SWIG_DEBUG - if (s) Printf(stdout,"code: %s\n", s); + if (s) + Printf(stdout, "code: %s\n", s); #endif - + /* Empty typemap. No match */ - if (Cmp(s,"pass") == 0) { + if (Cmp(s, "pass") == 0) { p = nextSibling(p); continue; } - + s = Copy(s); - locals = Getattr(tm,k_locals); - if (locals) locals = CopyParmList(locals); + locals = Getattr(tm, k_locals); + if (locals) + locals = CopyParmList(locals); firstp = p; #ifdef SWIG_DEBUG - Printf(stdout,"nmatch: %d\n", nmatch); + Printf(stdout, "nmatch: %d\n", nmatch); #endif for (i = 0; i < nmatch; i++) { SwigType *type; - String *pname; - String *lname; + String *pname; + String *lname; SwigType *mtype; - type = Getattr(p,k_type); - pname = Getattr(p,k_name); - lname = Getattr(p,k_lname); - mtype = Getattr(p,k_tmapmatch); + type = Getattr(p, k_type); + pname = Getattr(p, k_name); + lname = Getattr(p, k_lname); + mtype = Getattr(p, k_tmapmatch); if (mtype) { - typemap_replace_vars(s,locals,mtype,type,pname,lname,i+1); - Delattr(p,k_tmapmatch); + typemap_replace_vars(s, locals, mtype, type, pname, lname, i + 1); + Delattr(p, k_tmapmatch); } else { - typemap_replace_vars(s,locals,type,type,pname,lname,i+1); + typemap_replace_vars(s, locals, type, type, pname, lname, i + 1); } - if (HashCheckAttr(tm,k_type,k_SWIGTYPE)) { - sprintf(temp,"%s:SWIGTYPE", cop); - Setattr(p,tmop_name(temp),k_1); + if (HashCheckAttr(tm, k_type, k_SWIGTYPE)) { + sprintf(temp, "%s:SWIGTYPE", cop); + Setattr(p, tmop_name(temp), k_1); } p = nextSibling(p); } - + if (locals && f) { - typemap_locals(s,locals,f,argnum); + typemap_locals(s, locals, f, argnum); } - replace_embedded_typemap(s); + replace_embedded_typemap(s); /* Replace the argument number */ - sprintf(temp,"%d",argnum); - Replace(s,"$argnum",temp, DOH_REPLACE_ANY); + sprintf(temp, "%d", argnum); + Replace(s, "$argnum", temp, DOH_REPLACE_ANY); /* Attach attributes to object */ #ifdef SWIG_DEBUG - Printf(stdout,"attach: %s %s %s\n", Getattr(firstp,k_name), tmop_name(op), s); + Printf(stdout, "attach: %s %s %s\n", Getattr(firstp, k_name), tmop_name(op), s); #endif - Setattr(firstp,tmop_name(op),s); /* Code object */ + Setattr(firstp, tmop_name(op), s); /* Code object */ if (locals) { - sprintf(temp,"%s:locals", cop); - Setattr(firstp,tmop_name(temp), locals); + sprintf(temp, "%s:locals", cop); + Setattr(firstp, tmop_name(temp), locals); Delete(locals); } /* Attach a link to the next parameter. Needed for multimaps */ - sprintf(temp,"%s:next",cop); - Setattr(firstp,tmop_name(temp),p); + sprintf(temp, "%s:next", cop); + Setattr(firstp, tmop_name(temp), p); /* Attach kwargs */ - Swig_typemap_attach_kwargs(tm,op,firstp); - + Swig_typemap_attach_kwargs(tm, op, firstp); + /* Print warnings, if any */ - Swig_typemap_warn(op,firstp); + Swig_typemap_warn(op, firstp); /* Look for code fragments */ - Swig_typemap_emit_code_fragments(op,firstp); + Swig_typemap_emit_code_fragments(op, firstp); /* increase argnum to consider numinputs */ argnum += nmatch - 1; Delete(s); #ifdef SWIG_DEBUG - Printf(stdout,"res: %s %s %s\n", Getattr(firstp,k_name), tmop_name(op), Getattr(firstp,tmop_name(op))); + Printf(stdout, "res: %s %s %s\n", Getattr(firstp, k_name), tmop_name(op), Getattr(firstp, tmop_name(op))); #endif } #ifdef SWIG_DEBUG - Printf(stdout,"Swig_typemap_attach_parms: end\n"); + Printf(stdout, "Swig_typemap_attach_parms: end\n"); #endif } @@ -1659,12 +1688,12 @@ Swig_typemap_attach_parms(const String_or_char *op, ParmList *parms, Wrapper *f) /* Splits the arguments of an embedded typemap */ static List *split_embedded(String *s) { List *args = 0; - char *c,*start; - int level=0; - int leading = 1; + char *c, *start; + int level = 0; + int leading = 1; args = NewList(); - - c = strchr(Char(s),'('); + + c = strchr(Char(s), '('); c++; start = c; @@ -1675,25 +1704,31 @@ static List *split_embedded(String *s) { if (*c == '\\') { c++; } else { - if (*c == '\"') break; + if (*c == '\"') + break; } c++; } } if ((level == 0) && ((*c == ',') || (*c == ')'))) { - String *tmp = NewStringWithSize(start,c-start); - Append(args,tmp); + String *tmp = NewStringWithSize(start, c - start); + Append(args, tmp); Delete(tmp); - start = c+1; + start = c + 1; leading = 1; - if (*c == ')') break; + if (*c == ')') + break; c++; continue; } - if (*c == '(') level++; - if (*c == ')') level--; - if (isspace((int)*c) && leading) start++; - if (!isspace((int)*c)) leading = 0; + if (*c == '(') + level++; + if (*c == ')') + level--; + if (isspace((int) *c) && leading) + start++; + if (!isspace((int) *c)) + leading = 0; c++; } return args; @@ -1703,59 +1738,60 @@ static void split_var(String *s, String **name, String **value) { char *eq; char *c; - eq = strchr(Char(s),'='); + eq = strchr(Char(s), '='); if (!eq) { *name = 0; *value = 0; return; } c = Char(s); - *name = NewStringWithSize(c,eq-c); - + *name = NewStringWithSize(c, eq - c); + /* Look for $n variables */ - if (isdigit((int)*(c))) { + if (isdigit((int) *(c))) { /* Parse the value as a type */ String *v; Parm *p; - v = NewString(eq+1); + v = NewString(eq + 1); p = Swig_cparse_parm(v); Delete(v); *value = p; } else { - *value = NewString(eq+1); + *value = NewString(eq + 1); } } static void replace_embedded_typemap(String *s) { char *start = 0; - while ((start = strstr(Char(s),"$TYPEMAP("))) { + while ((start = strstr(Char(s), "$TYPEMAP("))) { /* Gather the argument */ - char *end=0,*c; - int level = 0; + char *end = 0, *c; + int level = 0; String *tmp; c = start; while (*c) { - if (*c == '(') level++; + if (*c == '(') + level++; if (*c == ')') { level--; if (level == 0) { - end = c+1; + end = c + 1; break; } } c++; } if (end) { - tmp = NewStringWithSize(start,(end-start)); + tmp = NewStringWithSize(start, (end - start)); } else { tmp = 0; } /* Got a substitution. Split it apart into pieces */ if (tmp) { - List *l; - Hash *vars; + List *l; + Hash *vars; String *method; int i, ilen; @@ -1764,40 +1800,41 @@ static void replace_embedded_typemap(String *s) { ilen = Len(l); for (i = 1; i < ilen; i++) { String *n, *v; - split_var(Getitem(l,i),&n,&v); + split_var(Getitem(l, i), &n, &v); if (n && v) { - Insert(n,0,"$"); - Setattr(vars,n,v); + Insert(n, 0, "$"); + Setattr(vars, n, v); } Delete(n); Delete(v); } - method = Getitem(l,0); + method = Getitem(l, 0); /* Generate the parameter list for matching typemaps */ { Parm *p = 0; Parm *first = 0; - char temp[32]; - int n = 1; + char temp[32]; + int n = 1; while (1) { Hash *v; - sprintf(temp,"$%d",n); - v = Getattr(vars,temp); + sprintf(temp, "$%d", n); + v = Getattr(vars, temp); if (v) { if (p) { - set_nextSibling(p,v); - set_previousSibling(v,p); + set_nextSibling(p, v); + set_previousSibling(v, p); } p = v; - Setattr(p,k_lname,Getattr(p,k_name)); - if (Getattr(p,k_value)) { - Setattr(p,k_name,Getattr(p,k_value)); + Setattr(p, k_lname, Getattr(p, k_name)); + if (Getattr(p, k_value)) { + Setattr(p, k_name, Getattr(p, k_value)); } - if (!first) first = p; + if (!first) + first = p; DohIncref(p); - Delattr(vars,temp); + Delattr(vars, temp); } else { break; } @@ -1806,41 +1843,41 @@ static void replace_embedded_typemap(String *s) { /* Perform a typemap search */ if (first) { #ifdef SWIG_DEBUG - Printf(stdout,"Swig_typemap_attach_parms: embedded\n"); -#endif - Swig_typemap_attach_parms(method,first,0); + Printf(stdout, "Swig_typemap_attach_parms: embedded\n"); +#endif + Swig_typemap_attach_parms(method, first, 0); { String *tm; - int match = 0; + int match = 0; char attr[64]; - sprintf(attr,"tmap:%s",Char(method)); - + sprintf(attr, "tmap:%s", Char(method)); + /* Look for the typemap code */ - tm = Getattr(first,attr); + tm = Getattr(first, attr); if (tm) { - sprintf(attr,"tmap:%s:next",Char(method)); - if (!Getattr(first,attr)) { + sprintf(attr, "tmap:%s:next", Char(method)); + if (!Getattr(first, attr)) { /* Should be no more matches. Hack??? */ /* Replace all of the remaining variables */ Iterator ki; for (ki = First(vars); ki.key; ki = Next(ki)) { - Replace(tm,ki.key,ki.item, DOH_REPLACE_ANY); + Replace(tm, ki.key, ki.item, DOH_REPLACE_ANY); } /* Do the replacement */ - Replace(s,tmp,tm, DOH_REPLACE_ANY); + Replace(s, tmp, tm, DOH_REPLACE_ANY); Delete(tm); match = 1; } } if (!match) { - Swig_error(Getfile(s),Getline(s),"No typemap found for %s\n", tmp); + Swig_error(Getfile(s), Getline(s), "No typemap found for %s\n", tmp); } } - } + } } - Replace(s,tmp,"", DOH_REPLACE_ANY); + Replace(s, tmp, "", DOH_REPLACE_ANY); Delete(vars); - Delete(tmp); + Delete(tmp); Delete(l); } } @@ -1852,15 +1889,13 @@ static void replace_embedded_typemap(String *s) { void Swig_typemap_debug() { int ts; - Printf(stdout,"---[ typemaps ]--------------------------------------------------------------\n"); - + Printf(stdout, "---[ typemaps ]--------------------------------------------------------------\n"); + ts = tm_scope; while (ts >= 0) { - Printf(stdout,"::: scope %d\n\n",ts); - Printf(stdout,"%s\n", typemaps[ts]); + Printf(stdout, "::: scope %d\n\n", ts); + Printf(stdout, "%s\n", typemaps[ts]); ts--; } - Printf(stdout,"-----------------------------------------------------------------------------\n"); + Printf(stdout, "-----------------------------------------------------------------------------\n"); } - - diff --git a/SWIG/Source/Swig/typeobj.c b/SWIG/Source/Swig/typeobj.c index dee4afd4f..e844efa81 100644 --- a/SWIG/Source/Swig/typeobj.c +++ b/SWIG/Source/Swig/typeobj.c @@ -111,8 +111,7 @@ char cvsroot_typeobj_c[] = "$Header$"; * ----------------------------------------------------------------------------- */ #ifdef NEW -SwigType * -NewSwigType(const String_or_char *initial) { +SwigType *NewSwigType(const String_or_char *initial) { return NewString(initial); } @@ -132,8 +131,7 @@ NewSwigType(const String_or_char *initial) { * substring, to chop the element off, or for other purposes). * ----------------------------------------------------------------------------- */ -static int -element_size(char *c) { +static int element_size(char *c) { int nparen; char *s = c; while (*c) { @@ -144,15 +142,18 @@ element_size(char *c) { nparen = 1; c++; while (*c) { - if (*c == '(') nparen++; + if (*c == '(') + nparen++; if (*c == ')') { nparen--; - if (nparen == 0) break; + if (nparen == 0) + break; } c++; } } - if (*c) c++; + if (*c) + c++; } return (int) (c - s); } @@ -163,10 +164,9 @@ element_size(char *c) { * Deletes one type element from the type. * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_del_element(SwigType *t) { +SwigType *SwigType_del_element(SwigType *t) { int sz = element_size(Char(t)); - Delslice(t,0,sz); + Delslice(t, 0, sz); return t; } @@ -176,21 +176,21 @@ SwigType_del_element(SwigType *t) { * Pop one type element off the type. * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_pop(SwigType *t) { - SwigType *result; - char *c; - int sz; +SwigType *SwigType_pop(SwigType *t) { + SwigType *result; + char *c; + int sz; c = Char(t); - if (!*c) return 0; + if (!*c) + return 0; sz = element_size(c); - result = NewStringWithSize(c,sz); - Delslice(t,0,sz); + result = NewStringWithSize(c, sz); + Delslice(t, 0, sz); c = Char(t); if (*c == '.') { - Delitem(t,0); + Delitem(t, 0); } return result; } @@ -201,26 +201,28 @@ SwigType_pop(SwigType *t) { * Returns the parameter of an operator as a string * ----------------------------------------------------------------------------- */ -String * -SwigType_parm(SwigType *t) { +String *SwigType_parm(SwigType *t) { char *start, *c; - int nparens = 0; + int nparens = 0; c = Char(t); - while (*c && (*c != '(') && (*c != '.')) c++; - if (!*c || (*c == '.')) return 0; + while (*c && (*c != '(') && (*c != '.')) + c++; + if (!*c || (*c == '.')) + return 0; c++; start = c; while (*c) { if (*c == ')') { - if (nparens == 0) break; + if (nparens == 0) + break; nparens--; } else if (*c == '(') { nparens++; } c++; } - return NewStringWithSize(start, (int) (c-start)); + return NewStringWithSize(start, (int) (c - start)); } /* ----------------------------------------------------------------------------- @@ -230,20 +232,21 @@ SwigType_parm(SwigType *t) { * ----------------------------------------------------------------------------- */ List *SwigType_split(const SwigType *t) { - DOH *item; - List *list; - char *c; - int len; + DOH *item; + List *list; + char *c; + int len; c = Char(t); list = NewList(); while (*c) { len = element_size(c); - item = NewStringWithSize(c,len); - Append(list,item); + item = NewStringWithSize(c, len); + Append(list, item); Delete(item); c = c + len; - if (*c == '.') c++; + if (*c == '.') + c++; } return list; } @@ -255,40 +258,45 @@ List *SwigType_split(const SwigType *t) { * ----------------------------------------------------------------------------- */ List *SwigType_parmlist(const String *p) { - DOH *item; + DOH *item; List *list; char *c, *itemstart; c = Char(p); - while (*c && (*c != '(') && (*c != '.')) c++; - if (!*c || (*c == '.')) return 0; + while (*c && (*c != '(') && (*c != '.')) + c++; + if (!*c || (*c == '.')) + return 0; c++; list = NewList(); itemstart = c; while (*c) { if (*c == ',') { item = NewStringWithSize(itemstart, (int) (c - itemstart)); - Append(list,item); + Append(list, item); Delete(item); - itemstart = c+1; + itemstart = c + 1; } else if (*c == '(') { int nparens = 1; c++; while (*c) { - if (*c == '(') nparens++; + if (*c == '(') + nparens++; if (*c == ')') { nparens--; - if (nparens == 0) break; + if (nparens == 0) + break; } c++; } } else if (*c == ')') { break; } - if (*c) c++; + if (*c) + c++; } - item = NewStringWithSize(itemstart,(int) (c - itemstart)); - Append(list,item); + item = NewStringWithSize(itemstart, (int) (c - itemstart)); + Append(list, item); Delete(item); return list; } @@ -304,43 +312,42 @@ List *SwigType_parmlist(const String *p) { * functions take into account qualifiers (if any). * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_pointer(SwigType *t) { - Insert(t,0,"p."); +SwigType *SwigType_add_pointer(SwigType *t) { + Insert(t, 0, "p."); return t; } -SwigType * -SwigType_del_pointer(SwigType *t) { +SwigType *SwigType_del_pointer(SwigType *t) { char *c, *s; c = Char(t); s = c; /* Skip qualifiers, if any */ - if (strncmp(c,"q(",2) == 0) { - c = strchr(c,'.'); + if (strncmp(c, "q(", 2) == 0) { + c = strchr(c, '.'); assert(c); c++; } - if (strncmp(c,"p.",2)) { + if (strncmp(c, "p.", 2)) { printf("Fatal error. SwigType_del_pointer applied to non-pointer.\n"); abort(); } - Delslice(t,0,(c-s)+2); + Delslice(t, 0, (c - s) + 2); return t; } -int -SwigType_ispointer(SwigType *t) { +int SwigType_ispointer(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); /* Skip qualifiers, if any */ - if (strncmp(c,"q(",2) == 0) { - c = strchr(c,'.'); - if (!c) return 0; + if (strncmp(c, "q(", 2) == 0) { + c = strchr(c, '.'); + if (!c) + return 0; c++; } - if (strncmp(c,"p.",2) == 0) { + if (strncmp(c, "p.", 2) == 0) { return 1; } return 0; @@ -357,29 +364,27 @@ SwigType_ispointer(SwigType *t) { * functions take into account qualifiers (if any). * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_reference(SwigType *t) { - Insert(t,0,"r."); - return t; -} - -SwigType * -SwigType_del_reference(SwigType *t) { - char *c = Char(t); - int check = strncmp(c,"r.",2); - assert(check == 0); - Delslice(t,0,2); +SwigType *SwigType_add_reference(SwigType *t) { + Insert(t, 0, "r."); return t; } -int -SwigType_isreference(SwigType *t) { +SwigType *SwigType_del_reference(SwigType *t) { + char *c = Char(t); + int check = strncmp(c, "r.", 2); + assert(check == 0); + Delslice(t, 0, 2); + return t; +} + +int SwigType_isreference(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - if (strncmp(c,"r.",2) == 0) { + if (strncmp(c, "r.", 2) == 0) { return 1; - } + } return 0; } @@ -397,20 +402,19 @@ SwigType_isreference(SwigType *t) { * stored in exactly the same way as "q(const volatile)". * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_qualifier(SwigType *t, const String_or_char *qual) { +SwigType *SwigType_add_qualifier(SwigType *t, const String_or_char *qual) { char temp[256], newq[256]; - int sz, added = 0; + int sz, added = 0; char *q, *cqual; char *c = Char(t); cqual = Char(qual); - if (!(strncmp(c,"q(",2) == 0)) { - sprintf(temp,"q(%s).",cqual); - Insert(t,0,temp); + if (!(strncmp(c, "q(", 2) == 0)) { + sprintf(temp, "q(%s).", cqual); + Insert(t, 0, temp); return t; - } + } /* The type already has a qualifier on it. In this case, we first check to see if the qualifier is already specified. In that case do nothing. @@ -418,58 +422,57 @@ SwigType_add_qualifier(SwigType *t, const String_or_char *qual) { order */ sz = element_size(c); - strncpy(temp,c, (sz < 256) ? sz : 256); + strncpy(temp, c, (sz < 256) ? sz : 256); - if (strstr(temp,cqual)) { + if (strstr(temp, cqual)) { /* Qualifier already added */ return t; } /* Add the qualifier to the existing list. */ - strcpy(newq,"q("); - q = temp+2; - q = strtok(q," )."); + strcpy(newq, "q("); + q = temp + 2; + q = strtok(q, " )."); while (q) { - if (strcmp(cqual,q) < 0) { + if (strcmp(cqual, q) < 0) { /* New qualifier is less that current qualifier. We need to insert it */ - strcat(newq,cqual); - strcat(newq," "); - strcat(newq,q); + strcat(newq, cqual); + strcat(newq, " "); + strcat(newq, q); added = 1; } else { - strcat(newq,q); + strcat(newq, q); } - q = strtok(NULL," )."); + q = strtok(NULL, " )."); if (q) { - strcat(newq," "); + strcat(newq, " "); } } if (!added) { - strcat(newq," "); - strcat(newq,cqual); + strcat(newq, " "); + strcat(newq, cqual); } - strcat(newq,")."); - Delslice(t,0,sz); - Insert(t,0,newq); + strcat(newq, ")."); + Delslice(t, 0, sz); + Insert(t, 0, newq); return t; } -SwigType * -SwigType_del_qualifier(SwigType *t) { +SwigType *SwigType_del_qualifier(SwigType *t) { char *c = Char(t); - int check = strncmp(c,"q(",2); + int check = strncmp(c, "q(", 2); assert(check == 0); - Delslice(t,0,element_size(c)); + Delslice(t, 0, element_size(c)); return t; } -int -SwigType_isqualifier(SwigType *t) { +int SwigType_isqualifier(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - if (strncmp(c,"q(",2) == 0) { + if (strncmp(c, "q(", 2) == 0) { return 1; } return 0; @@ -485,29 +488,27 @@ SwigType_isqualifier(SwigType *t) { * Add, remove, and test for C++ pointer to members. * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_memberpointer(SwigType *t, const String_or_char *name) { +SwigType *SwigType_add_memberpointer(SwigType *t, const String_or_char *name) { String *temp = NewStringf("m(%s).", name); - Insert(t,0,temp); + Insert(t, 0, temp); Delete(temp); return t; } -SwigType * -SwigType_del_memberpointer(SwigType *t) { +SwigType *SwigType_del_memberpointer(SwigType *t) { char *c = Char(t); - int check = strncmp(c,"m(",2); + int check = strncmp(c, "m(", 2); assert(check == 0); - Delslice(t,0,element_size(c)); + Delslice(t, 0, element_size(c)); return t; } -int -SwigType_ismemberpointer(SwigType *t) { +int SwigType_ismemberpointer(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - if (strncmp(c,"m(",2) == 0) { + if (strncmp(c, "m(", 2) == 0) { return 1; } return 0; @@ -529,57 +530,54 @@ SwigType_ismemberpointer(SwigType *t) { * SwigType_pop_arrays() - Remove all arrays * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_array(SwigType *t, const String_or_char *size) { +SwigType *SwigType_add_array(SwigType *t, const String_or_char *size) { char temp[512]; - strcpy(temp,"a("); - strcat(temp,Char(size)); - strcat(temp,")."); - Insert(t,0,temp); + strcpy(temp, "a("); + strcat(temp, Char(size)); + strcat(temp, ")."); + Insert(t, 0, temp); return t; } -SwigType * -SwigType_del_array(SwigType *t) { +SwigType *SwigType_del_array(SwigType *t) { char *c = Char(t); - int check = strncmp(c,"a(",2); + int check = strncmp(c, "a(", 2); assert(check == 0); - Delslice(t,0,element_size(c)); + Delslice(t, 0, element_size(c)); return t; } int SwigType_isarray(SwigType *t) { char *c; - if (!t) return 0; + if (!t) + return 0; c = Char(t); - if (strncmp(c,"a(",2) == 0) { + if (strncmp(c, "a(", 2) == 0) { return 1; } return 0; } /* Remove all arrays */ -SwigType * -SwigType_pop_arrays(SwigType *t) { +SwigType *SwigType_pop_arrays(SwigType *t) { String *ta; assert(SwigType_isarray(t)); ta = NewStringEmpty(); while (SwigType_isarray(t)) { SwigType *td = SwigType_pop(t); - Append(ta,td); + Append(ta, td); Delete(td); } return ta; } /* Return number of array dimensions */ -int -SwigType_array_ndim(SwigType *t) { +int SwigType_array_ndim(SwigType *t) { int ndim = 0; char *c = Char(t); - while (c && (strncmp(c,"a(",2) == 0)) { - c = strchr(c,'.'); + while (c && (strncmp(c, "a(", 2) == 0)) { + c = strchr(c, '.'); c++; ndim++; } @@ -587,25 +585,24 @@ SwigType_array_ndim(SwigType *t) { } /* Get nth array dimension */ -String * -SwigType_array_getdim(SwigType *t, int n) { +String *SwigType_array_getdim(SwigType *t, int n) { char *c = Char(t); - while (c && (strncmp(c,"a(",2) == 0) && (n > 0)) { - c = strchr(c,'.'); + while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) { + c = strchr(c, '.'); c++; n--; } if (n == 0) { - String *dim = SwigType_parm(c); + String *dim = SwigType_parm(c); if (SwigType_istemplate(dim)) { String *ndim = SwigType_namestr(dim); Delete(dim); dim = ndim; } - + return dim; } - + return 0; } @@ -617,10 +614,11 @@ void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep) { char *c = Char(t); start = c; - if (strncmp(c,"a(",2)) abort(); + if (strncmp(c, "a(", 2)) + abort(); - while (c && (strncmp(c,"a(",2) == 0) && (n > 0)) { - c = strchr(c,'.'); + while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) { + c = strchr(c, '.'); c++; n--; } @@ -628,19 +626,18 @@ void SwigType_array_setdim(SwigType *t, int n, const String_or_char *rep) { temp = *c; *c = 0; result = NewString(start); - Printf(result,"a(%s)",rep); + Printf(result, "a(%s)", rep); *c = temp; - c = strchr(c,'.'); - Append(result,c); + c = strchr(c, '.'); + Append(result, c); } Clear(t); - Append(t,result); + Append(t, result); Delete(result); } /* Return base type of an array */ -SwigType * -SwigType_array_type(SwigType *ty) { +SwigType *SwigType_array_type(SwigType *ty) { SwigType *t; t = Copy(ty); while (SwigType_isarray(t)) { @@ -662,72 +659,73 @@ SwigType_array_type(SwigType *ty) { * ----------------------------------------------------------------------------- */ /* Returns the function type, t, constructed from the parameters, parms */ -SwigType * -SwigType_add_function(SwigType *t, ParmList *parms) { +SwigType *SwigType_add_function(SwigType *t, ParmList *parms) { String *pstr; - Parm *p; + Parm *p; - Insert(t,0,")."); + Insert(t, 0, ")."); pstr = NewString("f("); p = parms; for (p = parms; p; p = nextSibling(p)) { - if (p != parms) Putc(',',pstr); - Append(pstr, Getattr(p,k_type)); + if (p != parms) + Putc(',', pstr); + Append(pstr, Getattr(p, k_type)); } - Insert(t,0,pstr); + Insert(t, 0, pstr); Delete(pstr); return t; } -SwigType * -SwigType_pop_function(SwigType *t) { +SwigType *SwigType_pop_function(SwigType *t) { SwigType *f = 0; SwigType *g = 0; char *c = Char(t); - if (strncmp(c,"q(",2) == 0) { + if (strncmp(c, "q(", 2) == 0) { f = SwigType_pop(t); c = Char(t); } - if (strncmp(c,"f(",2)) { + if (strncmp(c, "f(", 2)) { printf("Fatal error. SwigType_pop_function applied to non-function.\n"); abort(); } g = SwigType_pop(t); - if (f) SwigType_push(g,f); + if (f) + SwigType_push(g, f); Delete(f); return g; } -int -SwigType_isfunction(SwigType *t) { +int SwigType_isfunction(SwigType *t) { char *c; if (!t) { return 0; } c = Char(t); - if (strncmp(c,"q(",2) == 0) { + if (strncmp(c, "q(", 2) == 0) { /* Might be a 'const' function. Try to skip over the 'const' */ - c = strchr(c,'.'); - if (c) c++; - else return 0; + c = strchr(c, '.'); + if (c) + c++; + else + return 0; } - if (strncmp(c,"f(",2) == 0) { + if (strncmp(c, "f(", 2) == 0) { return 1; } return 0; } -ParmList * -SwigType_function_parms(SwigType *t) { +ParmList *SwigType_function_parms(SwigType *t) { List *l = SwigType_parmlist(t); Hash *p, *pp = 0, *firstp = 0; Iterator o; for (o = First(l); o.item; o = Next(o)) { - p = NewParm(o.item,0); - if (!firstp) firstp = p; + p = NewParm(o.item, 0); + if (!firstp) + firstp = p; if (pp) { - set_nextSibling(pp,p); + set_nextSibling(pp, p); Delete(p); } pp = p; @@ -737,7 +735,8 @@ SwigType_function_parms(SwigType *t) { } int SwigType_isvarargs(const SwigType *t) { - if (Strcmp(t,"v(...)") == 0) return 1; + if (Strcmp(t, "v(...)") == 0) + return 1; return 0; } @@ -758,24 +757,25 @@ int SwigType_isvarargs(const SwigType *t) { * vector ----> "vector<(p.int)>" * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_add_template(SwigType *t, ParmList *parms) { - Parm *p; +SwigType *SwigType_add_template(SwigType *t, ParmList *parms) { + Parm *p; - Append(t,"<("); + Append(t, "<("); p = parms; for (p = parms; p; p = nextSibling(p)) { String *v; - if (Getattr(p,k_default)) continue; - if (p != parms) Append(t,","); - v = Getattr(p,k_value); + if (Getattr(p, k_default)) + continue; + if (p != parms) + Append(t, ","); + v = Getattr(p, k_value); if (v) { - Append(t,v); + Append(t, v); } else { - Append(t,Getattr(p,k_type)); + Append(t, Getattr(p, k_type)); } } - Append(t,")>"); + Append(t, ")>"); return t; } @@ -791,11 +791,10 @@ SwigType_add_template(SwigType *t, ParmList *parms) { * Results in "Foo" * ----------------------------------------------------------------------------- */ -String * -SwigType_templateprefix(const SwigType *t) { +String *SwigType_templateprefix(const SwigType *t) { const char *s = Char(t); - const char *c = strstr(s,"<("); - return c ? NewStringWithSize(s, c-s) : NewString(s); + const char *c = strstr(s, "<("); + return c ? NewStringWithSize(s, c - s) : NewString(s); } /* ----------------------------------------------------------------------------- @@ -809,17 +808,18 @@ SwigType_templateprefix(const SwigType *t) { * returns "::bar" * ----------------------------------------------------------------------------- */ -String * -SwigType_templatesuffix(const SwigType *t) { +String *SwigType_templatesuffix(const SwigType *t) { const char *c; c = Char(t); while (*c) { - if ((*c == '<') && (*(c+1) == '(')) { + if ((*c == '<') && (*(c + 1) == '(')) { int nest = 1; c++; while (*c && nest) { - if (*c == '<') nest++; - if (*c == '>') nest--; + if (*c == '<') + nest++; + if (*c == '>') + nest--; c++; } return NewString(c); @@ -835,22 +835,23 @@ SwigType_templatesuffix(const SwigType *t) { * Returns the template part * ----------------------------------------------------------------------------- */ -String * -SwigType_templateargs(const SwigType *t) { +String *SwigType_templateargs(const SwigType *t) { const char *c; const char *start; c = Char(t); while (*c) { - if ((*c == '<') && (*(c+1) == '(')) { + if ((*c == '<') && (*(c + 1) == '(')) { int nest = 1; start = c; c++; while (*c && nest) { - if (*c == '<') nest++; - if (*c == '>') nest--; + if (*c == '<') + nest++; + if (*c == '>') + nest--; c++; } - return NewStringWithSize(start,c-start); + return NewStringWithSize(start, c - start); } c++; } @@ -863,10 +864,10 @@ SwigType_templateargs(const SwigType *t) { * Tests a type to see if it includes template parameters * ----------------------------------------------------------------------------- */ -int -SwigType_istemplate(const SwigType *t) { +int SwigType_istemplate(const SwigType *t) { char *ct = Char(t); - if ((ct = strstr(ct,"<(")) && (strstr(ct + 2,")>"))) return 1; + if ((ct = strstr(ct, "<(")) && (strstr(ct + 2, ")>"))) + return 1; return 0; } @@ -877,8 +878,7 @@ SwigType_istemplate(const SwigType *t) { * type "p.p.int", the function would return "int". * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_base(const SwigType *t) { +SwigType *SwigType_base(const SwigType *t) { char *c; char *lastop = 0; c = Char(t); @@ -888,8 +888,8 @@ SwigType_base(const SwigType *t) { /* Search for the last type constructor separator '.' */ while (*c) { if (*c == '.') { - if (*(c+1)) { - lastop = c+1; + if (*(c + 1)) { + lastop = c + 1; } c++; continue; @@ -899,11 +899,14 @@ SwigType_base(const SwigType *t) { int ntemp = 1; c++; while ((*c) && (ntemp > 0)) { - if (*c == '>') ntemp--; - else if (*c == '<') ntemp++; + if (*c == '>') + ntemp--; + else if (*c == '<') + ntemp++; c++; } - if (ntemp) break; + if (ntemp) + break; continue; } if (*c == '(') { @@ -911,11 +914,14 @@ SwigType_base(const SwigType *t) { int nparen = 1; c++; while ((*c) && (nparen > 0)) { - if (*c == '(') nparen++; - else if (*c == ')') nparen--; + if (*c == '(') + nparen++; + else if (*c == ')') + nparen--; c++; } - if (nparen) break; + if (nparen) + break; continue; } c++; @@ -930,8 +936,7 @@ SwigType_base(const SwigType *t) { * type "p.p.int" is "p.p.". * ----------------------------------------------------------------------------- */ -String * -SwigType_prefix(const SwigType *t) { +String *SwigType_prefix(const SwigType *t) { char *c, *d; String *r = 0; @@ -939,7 +944,8 @@ SwigType_prefix(const SwigType *t) { d = c + strlen(c); /* Check for a type constructor */ - if ((d > c) && (*(d-1) == '.')) d--; + if ((d > c) && (*(d - 1) == '.')) + d--; while (d > c) { d--; @@ -947,8 +953,10 @@ SwigType_prefix(const SwigType *t) { int nest = 1; d--; while ((d > c) && (nest)) { - if (*d == '>') nest++; - if (*d == '<') nest--; + if (*d == '>') + nest++; + if (*d == '<') + nest--; d--; } } @@ -957,17 +965,19 @@ SwigType_prefix(const SwigType *t) { int nparen = 1; d--; while ((d > c) && (nparen)) { - if (*d == ')') nparen++; - if (*d == '(') nparen--; + if (*d == ')') + nparen++; + if (*d == '(') + nparen--; d--; } } if (*d == '.') { - char t = *(d+1); - *(d+1) = 0; + char t = *(d + 1); + *(d + 1) = 0; r = NewString(c); - *(d+1) = t; + *(d + 1) = t; return r; } } @@ -980,34 +990,34 @@ SwigType_prefix(const SwigType *t) { * Strip all qualifiers from a type and return a new type * ----------------------------------------------------------------------------- */ -SwigType * -SwigType_strip_qualifiers(SwigType *t) { +SwigType *SwigType_strip_qualifiers(SwigType *t) { static Hash *memoize_stripped = 0; SwigType *r; - List *l; - Iterator ei; + List *l; + Iterator ei; + + if (!memoize_stripped) + memoize_stripped = NewHash(); + r = Getattr(memoize_stripped, t); + if (r) + return Copy(r); - if (!memoize_stripped) memoize_stripped = NewHash(); - r = Getattr(memoize_stripped,t); - if (r) return Copy(r); - l = SwigType_split(t); r = NewStringEmpty(); - - for (ei = First(l);ei.item; ei = Next(ei)) { - if (SwigType_isqualifier(ei.item)) continue; - Append(r,ei.item); + + for (ei = First(l); ei.item; ei = Next(ei)) { + if (SwigType_isqualifier(ei.item)) + continue; + Append(r, ei.item); } Delete(l); { String *key, *value; key = Copy(t); value = Copy(r); - Setattr(memoize_stripped,key,value); + Setattr(memoize_stripped, key, value); Delete(key); Delete(value); } return r; } - - diff --git a/SWIG/Source/Swig/typesys.c b/SWIG/Source/Swig/typesys.c index 442142dd5..dcf8b8cf0 100644 --- a/SWIG/Source/Swig/typesys.c +++ b/SWIG/Source/Swig/typesys.c @@ -97,17 +97,17 @@ char cvsroot_typesys_c[] = "$Header$"; * *----------------------------------------------------------------------------- */ -static Typetab *current_scope = 0; /* Current type scope */ -static Hash *current_typetab = 0; /* Current type table */ -static Hash *current_symtab = 0; /* Current symbol table */ -static Typetab *global_scope = 0; /* The global scope */ -static Hash *scopes = 0; /* Hash table containing fully qualified scopes */ +static Typetab *current_scope = 0; /* Current type scope */ +static Hash *current_typetab = 0; /* Current type table */ +static Hash *current_symtab = 0; /* Current symbol table */ +static Typetab *global_scope = 0; /* The global scope */ +static Hash *scopes = 0; /* Hash table containing fully qualified scopes */ /* Performance optimization */ -#define SWIG_TYPEDEF_RESOLVE_CACHE -static Hash *typedef_resolve_cache = 0; -static Hash *typedef_all_cache = 0; -static Hash *typedef_qualified_cache = 0; +#define SWIG_TYPEDEF_RESOLVE_CACHE +static Hash *typedef_resolve_cache = 0; +static Hash *typedef_all_cache = 0; +static Hash *typedef_qualified_cache = 0; /* common attribute keys, to avoid calling find_key all the times */ @@ -122,8 +122,7 @@ static Hash *typedef_qualified_cache = 0; */ static int value_wrapper_mode = 0; -int Swig_value_wrapper_mode(int mode) -{ +int Swig_value_wrapper_mode(int mode) { value_wrapper_mode = mode; return mode; } @@ -138,19 +137,21 @@ static void flush_cache() { /* Initialize the scoping system */ void SwigType_typesystem_init() { - if (global_scope) Delete(global_scope); - if (scopes) Delete(scopes); + if (global_scope) + Delete(global_scope); + if (scopes) + Delete(scopes); current_scope = NewHash(); - global_scope = current_scope; + global_scope = current_scope; - Setattr(current_scope,k_name,""); /* No name for global scope */ + Setattr(current_scope, k_name, ""); /* No name for global scope */ current_typetab = NewHash(); - Setattr(current_scope,k_typetab, current_typetab); + Setattr(current_scope, k_typetab, current_typetab); current_symtab = 0; scopes = NewHash(); - Setattr(scopes,"",current_scope); + Setattr(scopes, "", current_scope); } @@ -163,23 +164,24 @@ void SwigType_typesystem_init() { int SwigType_typedef(SwigType *type, String_or_char *name) { Typetab *SwigType_find_scope(Typetab *, String *s); - if (Getattr(current_typetab, name)) return -1; /* Already defined */ - if (Strcmp(type,name) == 0) { /* Can't typedef a name to itself */ + if (Getattr(current_typetab, name)) + return -1; /* Already defined */ + if (Strcmp(type, name) == 0) { /* Can't typedef a name to itself */ return 0; } - + /* Check if 'type' is already a scope. If so, we create an alias in the type system for it. This is needed to make strange nested scoping problems work correctly. */ { - Typetab *t = SwigType_find_scope(current_scope,type); + Typetab *t = SwigType_find_scope(current_scope, type); if (t) { SwigType_new_scope(name); SwigType_inherit_scope(t); SwigType_pop_scope(); } } - Setattr(current_typetab,name,type); + Setattr(current_typetab, name, type); flush_cache(); return 0; } @@ -194,10 +196,11 @@ int SwigType_typedef(SwigType *type, String_or_char *name) { int SwigType_typedef_class(String_or_char *name) { String *cname; /* Printf(stdout,"class : '%s'\n", name); */ - if (Getattr(current_typetab, name)) return -1; /* Already defined */ + if (Getattr(current_typetab, name)) + return -1; /* Already defined */ cname = NewString(name); - Setmeta(cname,"class","1"); - Setattr(current_typetab,cname,cname); + Setmeta(cname, "class", "1"); + Setattr(current_typetab, cname, cname); Delete(cname); flush_cache(); return 0; @@ -209,20 +212,20 @@ int SwigType_typedef_class(String_or_char *name) { * Returns the qualified scope name of a type table * ----------------------------------------------------------------------------- */ -String * -SwigType_scope_name(Typetab *ttab) { - String *qname = NewString(Getattr(ttab,k_name)); - ttab = Getattr(ttab,k_parent); +String *SwigType_scope_name(Typetab *ttab) { + String *qname = NewString(Getattr(ttab, k_name)); + ttab = Getattr(ttab, k_parent); while (ttab) { - String *pname = Getattr(ttab,k_name); + String *pname = Getattr(ttab, k_name); if (Len(pname)) { - Insert(qname,0,"::"); - Insert(qname,0,pname); + Insert(qname, 0, "::"); + Insert(qname, 0, pname); } - ttab = Getattr(ttab,k_parent); + ttab = Getattr(ttab, k_parent); } return qname; } + /* ----------------------------------------------------------------------------- * SwigType_new_scope() * @@ -231,22 +234,22 @@ SwigType_scope_name(Typetab *ttab) { void SwigType_new_scope(const String_or_char *name) { Typetab *s; - Hash *ttab; - String *qname; + Hash *ttab; + String *qname; if (!name) { name = ""; } s = NewHash(); - Setattr(s,k_name, name); - Setattr(s,k_parent, current_scope); + Setattr(s, k_name, name); + Setattr(s, k_parent, current_scope); ttab = NewHash(); - Setattr(s,k_typetab, ttab); + Setattr(s, k_typetab, ttab); /* Build fully qualified name and */ qname = SwigType_scope_name(s); - Setattr(scopes,qname,s); - Setattr(s,k_qname,qname); + Setattr(scopes, qname, s); + Setattr(s, k_qname, qname); Delete(qname); current_scope = s; @@ -262,24 +265,24 @@ void SwigType_new_scope(const String_or_char *name) { * C++ class inheritance, namespaces, and namespace aliases. * ----------------------------------------------------------------------------- */ -void -SwigType_inherit_scope(Typetab *scope) { +void SwigType_inherit_scope(Typetab *scope) { List *inherits; - int i, len; - inherits = Getattr(current_scope,k_inherit); + int i, len; + inherits = Getattr(current_scope, k_inherit); if (!inherits) { inherits = NewList(); - Setattr(current_scope,k_inherit, inherits); + Setattr(current_scope, k_inherit, inherits); Delete(inherits); } assert(scope != current_scope); - + len = Len(inherits); for (i = 0; i < len; i++) { - Node *n = Getitem(inherits,i); - if (n == scope) return; + Node *n = Getitem(inherits, i); + if (n == scope) + return; } - Append(inherits,scope); + Append(inherits, scope); } /* ----------------------------------------------------------------------------- @@ -288,16 +291,15 @@ SwigType_inherit_scope(Typetab *scope) { * Creates a scope-alias. * ----------------------------------------------------------------------------- */ -void -SwigType_scope_alias(String *aliasname, Typetab *ttab) { +void SwigType_scope_alias(String *aliasname, Typetab *ttab) { String *q; - /* Printf(stdout,"alias: '%s' '%x'\n", aliasname, ttab);*/ + /* Printf(stdout,"alias: '%s' '%x'\n", aliasname, ttab); */ q = SwigType_scope_name(current_scope); if (Len(q)) { - Append(q,"::"); - } - Append(q,aliasname); - Setattr(scopes,q,ttab); + Append(q, "::"); + } + Append(q, aliasname); + Setattr(scopes, q, ttab); flush_cache(); } @@ -307,25 +309,25 @@ SwigType_scope_alias(String *aliasname, Typetab *ttab) { * Import another scope into this scope. * ----------------------------------------------------------------------------- */ -void -SwigType_using_scope(Typetab *scope) { +void SwigType_using_scope(Typetab *scope) { SwigType_inherit_scope(scope); { List *ulist; - int i, len; - ulist = Getattr(current_scope,k_using); + int i, len; + ulist = Getattr(current_scope, k_using); if (!ulist) { ulist = NewList(); - Setattr(current_scope,k_using, ulist); + Setattr(current_scope, k_using, ulist); Delete(ulist); } assert(scope != current_scope); len = Len(ulist); for (i = 0; i < len; i++) { - Typetab *n = Getitem(ulist,i); - if (n == scope) return; + Typetab *n = Getitem(ulist, i); + if (n == scope) + return; } - Append(ulist,scope); + Append(ulist, scope); } flush_cache(); } @@ -339,11 +341,12 @@ SwigType_using_scope(Typetab *scope) { Typetab *SwigType_pop_scope() { Typetab *t, *old = current_scope; - t = Getattr(current_scope,k_parent); - if (!t) t = global_scope; + t = Getattr(current_scope, k_parent); + if (!t) + t = global_scope; current_scope = t; - current_typetab = Getattr(t,k_typetab); - current_symtab = Getattr(t,k_symtab); + current_typetab = Getattr(t, k_typetab); + current_symtab = Getattr(t, k_symtab); flush_cache(); return old; } @@ -354,13 +357,13 @@ Typetab *SwigType_pop_scope() { * Set the scope. Returns the old scope. * ----------------------------------------------------------------------------- */ -Typetab * -SwigType_set_scope(Typetab *t) { +Typetab *SwigType_set_scope(Typetab *t) { Typetab *old = current_scope; - if (!t) t = global_scope; + if (!t) + t = global_scope; current_scope = t; - current_typetab = Getattr(t,k_typetab); - current_symtab = Getattr(t,k_symtab); + current_typetab = Getattr(t, k_typetab); + current_symtab = Getattr(t, k_symtab); flush_cache(); return old; } @@ -371,9 +374,8 @@ SwigType_set_scope(Typetab *t) { * Attaches a symbol table to a type scope * ----------------------------------------------------------------------------- */ -void -SwigType_attach_symtab(Symtab *sym) { - Setattr(current_scope,k_symtab,sym); +void SwigType_attach_symtab(Symtab *sym) { + Setattr(current_scope, k_symtab, sym); current_symtab = sym; } @@ -384,35 +386,34 @@ SwigType_attach_symtab(Symtab *sym) { * ----------------------------------------------------------------------------- */ void SwigType_print_scope(Typetab *t) { - Hash *ttab; - Iterator i,j; + Hash *ttab; + Iterator i, j; for (i = First(scopes); i.key; i = Next(i)) { t = i.item; - ttab = Getattr(i.item,k_typetab); - - Printf(stdout,"Type scope '%s' (%x)\n", i.key, i.item); + ttab = Getattr(i.item, k_typetab); + + Printf(stdout, "Type scope '%s' (%x)\n", i.key, i.item); { - List *inherit = Getattr(i.item,k_inherit); + List *inherit = Getattr(i.item, k_inherit); if (inherit) { Iterator j; for (j = First(inherit); j.item; j = Next(j)) { - Printf(stdout," Inherits from '%s' (%x)\n", Getattr(j.item,k_qname), j.item); + Printf(stdout, " Inherits from '%s' (%x)\n", Getattr(j.item, k_qname), j.item); } } } - Printf(stdout,"-------------------------------------------------------------\n"); + Printf(stdout, "-------------------------------------------------------------\n"); for (j = First(ttab); j.key; j = Next(j)) { - Printf(stdout,"%40s -> %s\n", j.key, j.item); + Printf(stdout, "%40s -> %s\n", j.key, j.item); } } } -Typetab * -SwigType_find_scope(Typetab *s, String *nameprefix) { +Typetab *SwigType_find_scope(Typetab *s, String *nameprefix) { Typetab *ss; - String *nnameprefix = 0; - static int check_parent = 1; + String *nnameprefix = 0; + static int check_parent = 1; /* Printf(stdout,"find_scope: %x(%s) '%s'\n", s, Getattr(s,"name"), nameprefix); */ @@ -424,47 +425,51 @@ SwigType_find_scope(Typetab *s, String *nameprefix) { ss = s; while (ss) { String *full; - String *qname = Getattr(ss,k_qname); + String *qname = Getattr(ss, k_qname); if (qname) { full = NewStringf("%s::%s", qname, nameprefix); } else { full = NewString(nameprefix); } - if (Getattr(scopes,full)) { - s = Getattr(scopes,full); + if (Getattr(scopes, full)) { + s = Getattr(scopes, full); } else { s = 0; } Delete(full); if (s) { - if (nnameprefix) Delete(nnameprefix); + if (nnameprefix) + Delete(nnameprefix); return s; } if (!s) { /* Check inheritance */ List *inherit; - inherit = Getattr(ss,k_using); + inherit = Getattr(ss, k_using); if (inherit) { Typetab *ttab; int i, len; len = Len(inherit); for (i = 0; i < len; i++) { int oldcp = check_parent; - ttab = Getitem(inherit,i); + ttab = Getitem(inherit, i); check_parent = 0; - s = SwigType_find_scope(ttab,nameprefix); + s = SwigType_find_scope(ttab, nameprefix); check_parent = oldcp; if (s) { - if (nnameprefix) Delete(nnameprefix); + if (nnameprefix) + Delete(nnameprefix); return s; } } } } - if (!check_parent) break; - ss = Getattr(ss,k_parent); + if (!check_parent) + break; + ss = Getattr(ss, k_parent); } - if (nnameprefix) Delete(nnameprefix); + if (nnameprefix) + Delete(nnameprefix); return 0; } @@ -476,38 +481,37 @@ SwigType_find_scope(Typetab *s, String *nameprefix) { * Internal function. * ----------------------------------------------------------------------------- */ -static Typetab *resolved_scope = 0; +static Typetab *resolved_scope = 0; /* Internal function */ -static SwigType * -_typedef_resolve(Typetab *s, String *base, int look_parent) { - Hash *ttab; +static SwigType *_typedef_resolve(Typetab *s, String *base, int look_parent) { + Hash *ttab; SwigType *type = 0; - List *inherit; - Typetab *parent; + List *inherit; + Typetab *parent; /* if (!s) return 0; *//* now is checked bellow */ /* Printf(stdout,"Typetab %s : %s\n", Getattr(s,"name"), base); */ if (!Getmark(s)) { - Setmark(s,1); + Setmark(s, 1); - ttab = Getattr(s,k_typetab); - type = Getattr(ttab,base); + ttab = Getattr(s, k_typetab); + type = Getattr(ttab, base); if (type) { resolved_scope = s; - Setmark(s,0); + Setmark(s, 0); } else { /* Hmmm. Not found in my scope. It could be in an inherited scope */ - inherit = Getattr(s,k_inherit); + inherit = Getattr(s, k_inherit); if (inherit) { - int i,len; + int i, len; len = Len(inherit); for (i = 0; i < len; i++) { - type = _typedef_resolve(Getitem(inherit,i), base, 0); + type = _typedef_resolve(Getitem(inherit, i), base, 0); if (type) { - Setmark(s,0); + Setmark(s, 0); break; } } @@ -515,18 +519,17 @@ _typedef_resolve(Typetab *s, String *base, int look_parent) { if (!type) { /* Hmmm. Not found in my scope. check parent */ if (look_parent) { - parent = Getattr(s,k_parent); + parent = Getattr(s, k_parent); type = parent ? _typedef_resolve(parent, base, 1) : 0; } } - Setmark(s,0); + Setmark(s, 0); } } return type; } -static SwigType * -typedef_resolve(Typetab *s, String *base) { +static SwigType *typedef_resolve(Typetab *s, String *base) { return _typedef_resolve(s, base, 1); } @@ -540,17 +543,17 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { String *base; String *type = 0; String *r = 0; - Typetab *s; - Hash *ttab; + Typetab *s; + Hash *ttab; String *namebase = 0; String *nameprefix = 0; - int newtype = 0; + int newtype = 0; /* - if (!noscope) { - noscope = NewStringEmpty(); - } - */ + if (!noscope) { + noscope = NewStringEmpty(); + } + */ resolved_scope = 0; @@ -558,9 +561,9 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { if (!typedef_resolve_cache) { typedef_resolve_cache = NewHash(); } - r = Getattr(typedef_resolve_cache,t); + r = Getattr(typedef_resolve_cache, t); if (r) { - resolved_scope = Getmeta(r,k_scope); + resolved_scope = Getmeta(r, k_scope); return Copy(r); } #endif @@ -568,20 +571,20 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { base = SwigType_base(t); #ifdef SWIG_DEBUG - Printf(stdout,"base = '%s' t='%s'\n", base, t); + Printf(stdout, "base = '%s' t='%s'\n", base, t); #endif if (SwigType_issimple(base)) { s = current_scope; ttab = current_typetab; - if (strncmp(Char(base),"::",2) == 0) { + if (strncmp(Char(base), "::", 2) == 0) { s = global_scope; - ttab = Getattr(s,k_typetab); - Delitem(base,0); - Delitem(base,0); + ttab = Getattr(s, k_typetab); + Delitem(base, 0); + Delitem(base, 0); } /* Do a quick check in the local scope */ - type = Getattr(ttab,base); + type = Getattr(ttab, base); if (type) { resolved_scope = s; } @@ -591,11 +594,11 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { /* A qualified name. */ Swig_scopename_split(base, &nameprefix, &namebase); #ifdef SWIG_DEBUG - Printf(stdout,"nameprefix = '%s'\n", nameprefix); + Printf(stdout, "nameprefix = '%s'\n", nameprefix); #endif if (nameprefix) { /* Name had a prefix on it. See if we can locate the proper scope for it */ - s = SwigType_find_scope(s,nameprefix); + s = SwigType_find_scope(s, nameprefix); /* Couldn't locate a scope for the type. */ if (!s) { @@ -607,47 +610,49 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { } /* Try to locate the name starting in the scope */ #ifdef SWIG_DEBUG - Printf(stdout,"namebase = '%s'\n", namebase); + Printf(stdout, "namebase = '%s'\n", namebase); #endif - type = typedef_resolve(s,namebase); + type = typedef_resolve(s, namebase); if (type) { /* we need to look for the resolved type, this will also fix the resolved_scope if 'type' and 'namebase' are declared in different scopes */ String *rtype = 0; - rtype = typedef_resolve(resolved_scope,type); - if (rtype) type = rtype; + rtype = typedef_resolve(resolved_scope, type); + if (rtype) + type = rtype; } #ifdef SWIG_DEBUG - Printf(stdout,"%s type = '%s'\n", Getattr(s,"name"), type); + Printf(stdout, "%s type = '%s'\n", Getattr(s, "name"), type); #endif if ((type) && (!Swig_scopename_check(type)) && resolved_scope) { Typetab *rtab = resolved_scope; - String *qname = Getattr(resolved_scope,k_qname); + String *qname = Getattr(resolved_scope, k_qname); /* If qualified *and* the typename is defined from the resolved scope, we qualify */ - if ((qname) && typedef_resolve(resolved_scope,type)) { + if ((qname) && typedef_resolve(resolved_scope, type)) { type = Copy(type); - Insert(type,0,"::"); - Insert(type,0,qname); + Insert(type, 0, "::"); + Insert(type, 0, qname); #ifdef SWIG_DEBUG - Printf(stdout,"qual %s \n", type); + Printf(stdout, "qual %s \n", type); #endif newtype = 1; - } + } resolved_scope = rtab; } } else { /* Name is unqualified. */ - type = typedef_resolve(s,base); + type = typedef_resolve(s, base); } } else { /* Name is unqualified. */ - type = typedef_resolve(s,base); + type = typedef_resolve(s, base); } } - - if (type && (StringEqual(base,type))) { - if (newtype) Delete(type); + + if (type && (StringEqual(base, type))) { + if (newtype) + Delete(type); Delete(base); Delete(namebase); Delete(nameprefix); @@ -656,17 +661,17 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { } /* If the type is a template, and no typedef was found, we need to check the - template arguments one by one to see if they can be resolved. */ + template arguments one by one to see if they can be resolved. */ if (!type && SwigType_istemplate(base)) { List *tparms; String *suffix; - int i,sz; + int i, sz; int rep = 0; type = SwigType_templateprefix(base); newtype = 1; suffix = SwigType_templatesuffix(base); - Append(type,"<("); + Append(type, "<("); tparms = SwigType_parmlist(base); sz = Len(tparms); for (i = 0; i < sz; i++) { @@ -678,16 +683,17 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { tpr = 0; } if (tpr) { - Append(type,tpr); + Append(type, tpr); Delete(tpr); rep = 1; } else { - Append(type,tp); + Append(type, tp); } - if ((i+1) < sz) Append(type,","); + if ((i + 1) < sz) + Append(type, ","); } - Append(type,")>"); - Append(type,suffix); + Append(type, ")>"); + Append(type, suffix); Delete(suffix); Delete(tparms); if (!rep) { @@ -695,12 +701,14 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { type = 0; } } - if (namebase) Delete(namebase); - if (nameprefix) Delete(nameprefix); + if (namebase) + Delete(namebase); + if (nameprefix) + Delete(nameprefix); } else { if (SwigType_isfunction(base)) { List *parms; - int i,sz; + int i, sz; int rep = 0; type = NewString("f("); newtype = 1; @@ -715,15 +723,16 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { tpr = 0; } if (tpr) { - Append(type,tpr); + Append(type, tpr); Delete(tpr); rep = 1; } else { - Append(type,tp); + Append(type, tp); } - if ((i+1) < sz) Append(type,","); + if ((i + 1) < sz) + Append(type, ","); } - Append(type,")."); + Append(type, ")."); Delete(parms); if (!rep) { Delete(type); @@ -747,11 +756,11 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { if (!type) { if (r && Len(r)) { char *cr = Char(r); - if ((strstr(cr,"f(") || (strstr(cr,"m(")))) { + if ((strstr(cr, "f(") || (strstr(cr, "m(")))) { SwigType *rt = SwigType_typedef_resolve(r); if (rt) { Delete(r); - Append(rt,base); + Append(rt, base); Delete(base); r = rt; goto return_result; @@ -764,19 +773,19 @@ SwigType *SwigType_typedef_resolve(SwigType *t) { goto return_result; } Delete(base); - Append(r,type); + Append(r, type); if (newtype) { Delete(type); } - return_result: +return_result: #ifdef SWIG_TYPEDEF_RESOLVE_CACHE { String *key = NewString(t); if (r) { SwigType *r1; - Setattr(typedef_resolve_cache,key,r); - Setmeta(r,k_scope,resolved_scope); + Setattr(typedef_resolve_cache, key, r); + Setmeta(r, k_scope, resolved_scope); r1 = Copy(r); Delete(r); r = r1; @@ -801,7 +810,7 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) { if (!typedef_all_cache) { typedef_all_cache = NewHash(); } - r = Getattr(typedef_all_cache,t); + r = Getattr(typedef_all_cache, t); if (r) { return Copy(r); } @@ -818,7 +827,7 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) { String *key; SwigType *rr = Copy(r); key = NewString(t); - Setattr(typedef_all_cache,key,rr); + Setattr(typedef_all_cache, key, rr); Delete(key); Delete(rr); } @@ -833,18 +842,18 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) { * typedef scope rules. * ----------------------------------------------------------------------------- */ -SwigType *SwigType_typedef_qualified(SwigType *t) -{ - List *elements; +SwigType *SwigType_typedef_qualified(SwigType *t) { + List *elements; String *result; - int i,len; + int i, len; - if (t && strncmp(Char(t),"::",2) == 0) { + if (t && strncmp(Char(t), "::", 2) == 0) { return Copy(t); } - - if (!typedef_qualified_cache) typedef_qualified_cache = NewHash(); - result = HashGetAttr(typedef_qualified_cache,t); + + if (!typedef_qualified_cache) + typedef_qualified_cache = NewHash(); + result = HashGetAttr(typedef_qualified_cache, t); if (result) { String *rc = Copy(result); return rc; @@ -855,22 +864,22 @@ SwigType *SwigType_typedef_qualified(SwigType *t) len = Len(elements); for (i = 0; i < len; i++) { String *ty = 0; - String *e = Getitem(elements,i); + String *e = Getitem(elements, i); if (SwigType_issimple(e)) { if (!SwigType_istemplate(e)) { String *isenum = 0; if (SwigType_isenum(e)) { isenum = NewString("enum "); - ty = NewString(Char(e)+5); + ty = NewString(Char(e) + 5); e = ty; } resolved_scope = 0; - if (typedef_resolve(current_scope,e)) { + if (typedef_resolve(current_scope, e)) { /* resolved_scope contains the scope that actually resolved the symbol */ - String *qname = Getattr(resolved_scope,k_qname); + String *qname = Getattr(resolved_scope, k_qname); if (qname) { - Insert(e,0,"::"); - Insert(e,0,qname); + Insert(e, 0, "::"); + Insert(e, 0, qname); } } else { if (Swig_scopename_check(e)) { @@ -880,7 +889,7 @@ SwigType *SwigType_typedef_qualified(SwigType *t) if (qname) { String *tqname = SwigType_typedef_qualified(qname); Clear(e); - Printf(e,"%s::%s", tqname, qlast); + Printf(e, "%s::%s", tqname, qlast); Delete(qname); Delete(tqname); } @@ -889,49 +898,49 @@ SwigType *SwigType_typedef_qualified(SwigType *t) /* Automatic template instantiation might go here??? */ } else { /* It's a bare name. It's entirely possible, that the - name is part of a namespace. We'll check this by unrolling - out of the current scope */ - + name is part of a namespace. We'll check this by unrolling + out of the current scope */ + Typetab *cs = current_scope; while (cs) { String *qs = SwigType_scope_name(cs); if (Len(qs)) { - Append(qs,"::"); + Append(qs, "::"); } - Append(qs,e); - if (Getattr(scopes,qs)) { + Append(qs, e); + if (Getattr(scopes, qs)) { Clear(e); - Append(e,qs); + Append(e, qs); Delete(qs); break; } Delete(qs); - cs = Getattr(cs,k_parent); + cs = Getattr(cs, k_parent); } } } if (isenum) { - Insert(e,0,isenum); + Insert(e, 0, isenum); Delete(isenum); - } + } } else { /* Template. We need to qualify template parameters as well as the template itself */ String *tprefix, *qprefix; String *tsuffix; Iterator pi; - Parm *p; + Parm *p; List *parms; - ty = Swig_symbol_template_deftype(e,current_symtab); + ty = Swig_symbol_template_deftype(e, current_symtab); e = ty; parms = SwigType_parmlist(e); tprefix = SwigType_templateprefix(e); tsuffix = SwigType_templatesuffix(e); qprefix = SwigType_typedef_qualified(tprefix); - Append(qprefix,"<("); + Append(qprefix, "<("); pi = First(parms); while ((p = pi.item)) { String *qt = SwigType_typedef_qualified(p); - if (StringEqual(qt,p)) { /* && (!Swig_scopename_check(qt))) */ + if (StringEqual(qt, p)) { /* && (!Swig_scopename_check(qt))) */ /* No change in value. It is entirely possible that the parameter is an integer value. If there is a symbol table associated with this scope, we're going to check for this */ @@ -939,17 +948,18 @@ SwigType *SwigType_typedef_qualified(SwigType *t) Node *lastnode = 0; String *value = Copy(p); while (1) { - Node *n = Swig_symbol_clookup(value,current_symtab); - if (n == lastnode) break; + Node *n = Swig_symbol_clookup(value, current_symtab); + if (n == lastnode) + break; lastnode = n; if (n) { - char *ntype = Char(Getattr(n,k_nodetype)); - if (strcmp(ntype,"enumitem") == 0) { + char *ntype = Char(Getattr(n, k_nodetype)); + if (strcmp(ntype, "enumitem") == 0) { /* An enum item. Generate a fully qualified name */ String *qn = Swig_symbol_qualified(n); if (Len(qn)) { - Append(qn,"::"); - Append(qn,Getattr(n,k_name)); + Append(qn, "::"); + Append(qn, Getattr(n, k_name)); Delete(value); value = qn; continue; @@ -957,42 +967,42 @@ SwigType *SwigType_typedef_qualified(SwigType *t) Delete(qn); break; } - } else if ((strcmp(ntype,"cdecl") == 0) && (Getattr(n,k_value))) { + } else if ((strcmp(ntype, "cdecl") == 0) && (Getattr(n, k_value))) { Delete(value); - value = Copy(Getattr(n,k_value)); + value = Copy(Getattr(n, k_value)); continue; } } break; } - Append(qprefix,value); + Append(qprefix, value); Delete(value); } else { - Append(qprefix,p); + Append(qprefix, p); } } else { - Append(qprefix,qt); + Append(qprefix, qt); } Delete(qt); - pi= Next(pi); + pi = Next(pi); if (pi.item) { - Append(qprefix,","); + Append(qprefix, ","); } } - Append(qprefix,")>"); - Append(qprefix,tsuffix); + Append(qprefix, ")>"); + Append(qprefix, tsuffix); Delete(tsuffix); Clear(e); - Append(e,qprefix); + Append(e, qprefix); Delete(tprefix); Delete(qprefix); Delete(parms); } - if (strncmp(Char(e),"::",2) == 0) { - Delitem(e,0); - Delitem(e,0); + if (strncmp(Char(e), "::", 2) == 0) { + Delitem(e, 0); + Delitem(e, 0); } - Append(result,e); + Append(result, e); Delete(ty); } else if (SwigType_isfunction(e)) { List *parms = SwigType_parmlist(e); @@ -1001,26 +1011,26 @@ SwigType *SwigType_typedef_qualified(SwigType *t) pi = First(parms); while (pi.item) { String *pq = SwigType_typedef_qualified(pi.item); - Append(s,pq); + Append(s, pq); Delete(pq); pi = Next(pi); if (pi.item) { - Append(s,","); + Append(s, ","); } } - Append(s,")."); - Append(result,s); + Append(s, ")."); + Append(result, s); Delete(s); Delete(parms); } else if (SwigType_isarray(e)) { String *ndim; String *dim = SwigType_parm(e); - ndim = Swig_symbol_string_qualify(dim,0); - Printf(result,"a(%s).",ndim); + ndim = Swig_symbol_string_qualify(dim, 0); + Printf(result, "a(%s).", ndim); Delete(dim); Delete(ndim); } else { - Append(result,e); + Append(result, e); } } Delete(elements); @@ -1028,7 +1038,7 @@ SwigType *SwigType_typedef_qualified(SwigType *t) String *key, *cresult; key = NewString(t); cresult = NewString(result); - Setattr(typedef_qualified_cache,key,cresult); + Setattr(typedef_qualified_cache, key, cresult); Delete(key); Delete(cresult); } @@ -1070,48 +1080,50 @@ int SwigType_typedef_using(String_or_char *name) { String *defined_name = 0; - /* Printf(stdout,"using %s\n", name);*/ + /* Printf(stdout,"using %s\n", name); */ - if (!Swig_scopename_check(name)) return -1; /* Not properly qualified */ - base = Swig_scopename_last(name); + if (!Swig_scopename_check(name)) + return -1; /* Not properly qualified */ + base = Swig_scopename_last(name); /* See if the base is already defined in this scope */ - if (Getattr(current_typetab,base)) { + if (Getattr(current_typetab, base)) { Delete(base); return -1; } /* See if the using name is a scope */ /* tt = SwigType_find_scope(current_scope,name); - Printf(stdout,"tt = %x, name = '%s'\n", tt, name); */ + Printf(stdout,"tt = %x, name = '%s'\n", tt, name); */ /* We set up a typedef B --> A::B */ - Setattr(current_typetab,base,name); + Setattr(current_typetab, base, name); /* Find the scope name where the symbol is defined */ td = SwigType_typedef_resolve(name); /* Printf(stdout,"td = '%s' %x\n", td, resolved_scope); */ if (resolved_scope) { - defined_name = Getattr(resolved_scope,k_qname); + defined_name = Getattr(resolved_scope, k_qname); if (defined_name) { defined_name = Copy(defined_name); - Append(defined_name,"::"); - Append(defined_name,base); - /* Printf(stdout,"defined_name = '%s'\n", defined_name);*/ - tt = SwigType_find_scope(current_scope,defined_name); + Append(defined_name, "::"); + Append(defined_name, base); + /* Printf(stdout,"defined_name = '%s'\n", defined_name); */ + tt = SwigType_find_scope(current_scope, defined_name); } } - if (td) Delete(td); + if (td) + Delete(td); /* Figure out the scope the using directive refers to */ { prefix = Swig_scopename_prefix(name); - s = SwigType_find_scope(current_scope,prefix); + s = SwigType_find_scope(current_scope, prefix); if (s) { - Hash *ttab = Getattr(s,k_typetab); - if (!Getattr(ttab,base) && defined_name) { - Setattr(ttab,base, defined_name); + Hash *ttab = Getattr(s, k_typetab); + if (!Getattr(ttab, base) && defined_name) { + Setattr(ttab, base, defined_name); } } } @@ -1123,7 +1135,8 @@ int SwigType_typedef_using(String_or_char *name) { SwigType_pop_scope(); } - if (defined_name) Delete(defined_name); + if (defined_name) + Delete(defined_name); Delete(prefix); Delete(base); return 0; @@ -1137,17 +1150,16 @@ int SwigType_typedef_using(String_or_char *name) { * a class. * ----------------------------------------------------------------------------- */ -int -SwigType_isclass(SwigType *t) { +int SwigType_isclass(SwigType *t) { SwigType *qty, *qtys; - int isclass = 0; + int isclass = 0; qty = SwigType_typedef_resolve_all(t); qtys = SwigType_strip_qualifiers(qty); if (SwigType_issimple(qtys)) { String *td = SwigType_typedef_resolve(qtys); if (td) { - Delete(td); + Delete(td); } if (resolved_scope) { isclass = 1; @@ -1155,7 +1167,7 @@ SwigType_isclass(SwigType *t) { /* Hmmm. Not a class. If a template, it might be uninstantiated */ if (!isclass && SwigType_istemplate(qtys)) { String *tp = SwigType_templateprefix(qtys); - if (Strcmp(tp,t) != 0) { + if (Strcmp(tp, t) != 0) { isclass = SwigType_isclass(tp); } Delete(tp); @@ -1174,50 +1186,79 @@ SwigType_isclass(SwigType *t) { * everything is based on typemaps. * ----------------------------------------------------------------------------- */ -int SwigType_type(SwigType *t) -{ +int SwigType_type(SwigType *t) { char *c; /* Check for the obvious stuff */ c = Char(t); - if (strncmp(c,"p.",2) == 0) { - if (SwigType_type(c+2) == T_CHAR) return T_STRING; - else return T_POINTER; + if (strncmp(c, "p.", 2) == 0) { + if (SwigType_type(c + 2) == T_CHAR) + return T_STRING; + else + return T_POINTER; } - if (strncmp(c,"a(",2) == 0) return T_ARRAY; - if (strncmp(c,"r.",2) == 0) return T_REFERENCE; - if (strncmp(c,"m(",2) == 0) return T_MPOINTER; - if (strncmp(c,"q(",2) == 0) { - while(*c && (*c != '.')) c++; - if (*c) return SwigType_type(c+1); + if (strncmp(c, "a(", 2) == 0) + return T_ARRAY; + if (strncmp(c, "r.", 2) == 0) + return T_REFERENCE; + if (strncmp(c, "m(", 2) == 0) + return T_MPOINTER; + if (strncmp(c, "q(", 2) == 0) { + while (*c && (*c != '.')) + c++; + if (*c) + return SwigType_type(c + 1); return T_ERROR; } - if (strncmp(c,"f(",2) == 0) return T_FUNCTION; - - /* Look for basic types */ - if (strcmp(c,"int") == 0) return T_INT; - if (strcmp(c,"long") == 0) return T_LONG; - if (strcmp(c,"short") == 0) return T_SHORT; - if (strcmp(c,"unsigned") == 0) return T_UINT; - if (strcmp(c,"unsigned short") == 0) return T_USHORT; - if (strcmp(c,"unsigned long") == 0) return T_ULONG; - if (strcmp(c,"unsigned int") == 0) return T_UINT; - if (strcmp(c,"char") == 0) return T_CHAR; - if (strcmp(c,"signed char") == 0) return T_SCHAR; - if (strcmp(c,"unsigned char") == 0) return T_UCHAR; - if (strcmp(c,"float") == 0) return T_FLOAT; - if (strcmp(c,"double") == 0) return T_DOUBLE; - if (strcmp(c,"long double") == 0) return T_LONGDOUBLE; - if (!cparse_cplusplus && (strcmp(c,"float complex") == 0)) return T_FLTCPLX; - if (!cparse_cplusplus && (strcmp(c,"double complex") == 0)) return T_DBLCPLX; - if (!cparse_cplusplus && (strcmp(c,"complex") == 0)) return T_COMPLEX; - if (strcmp(c,"void") == 0) return T_VOID; - if (strcmp(c,"bool") == 0) return T_BOOL; - if (strcmp(c,"long long") == 0) return T_LONGLONG; - if (strcmp(c,"unsigned long long") == 0) return T_ULONGLONG; - if (strncmp(c,"enum ",5) == 0) return T_INT; + if (strncmp(c, "f(", 2) == 0) + return T_FUNCTION; - if (strcmp(c,"v(...)") == 0) return T_VARARGS; + /* Look for basic types */ + if (strcmp(c, "int") == 0) + return T_INT; + if (strcmp(c, "long") == 0) + return T_LONG; + if (strcmp(c, "short") == 0) + return T_SHORT; + if (strcmp(c, "unsigned") == 0) + return T_UINT; + if (strcmp(c, "unsigned short") == 0) + return T_USHORT; + if (strcmp(c, "unsigned long") == 0) + return T_ULONG; + if (strcmp(c, "unsigned int") == 0) + return T_UINT; + if (strcmp(c, "char") == 0) + return T_CHAR; + if (strcmp(c, "signed char") == 0) + return T_SCHAR; + if (strcmp(c, "unsigned char") == 0) + return T_UCHAR; + if (strcmp(c, "float") == 0) + return T_FLOAT; + if (strcmp(c, "double") == 0) + return T_DOUBLE; + if (strcmp(c, "long double") == 0) + return T_LONGDOUBLE; + if (!cparse_cplusplus && (strcmp(c, "float complex") == 0)) + return T_FLTCPLX; + if (!cparse_cplusplus && (strcmp(c, "double complex") == 0)) + return T_DBLCPLX; + if (!cparse_cplusplus && (strcmp(c, "complex") == 0)) + return T_COMPLEX; + if (strcmp(c, "void") == 0) + return T_VOID; + if (strcmp(c, "bool") == 0) + return T_BOOL; + if (strcmp(c, "long long") == 0) + return T_LONGLONG; + if (strcmp(c, "unsigned long long") == 0) + return T_ULONGLONG; + if (strncmp(c, "enum ", 5) == 0) + return T_INT; + + if (strcmp(c, "v(...)") == 0) + return T_VARARGS; /* Hmmm. Unknown type */ if (SwigType_istypedef(t)) { int r; @@ -1225,7 +1266,7 @@ int SwigType_type(SwigType *t) r = SwigType_type(nt); Delete(nt); return r; - } + } return T_USER; } @@ -1255,38 +1296,40 @@ int SwigType_type(SwigType *t) * ----------------------------------------------------------------------------- */ SwigType *SwigType_alttype(SwigType *t, int local_tmap) { - if (!cparse_cplusplus) return 0; + if (!cparse_cplusplus) + return 0; if (value_wrapper_mode == 0) { /* old partial use of SwigValueTypes, it can fail for opaque types */ Node *n; SwigType *w = 0; int use_wrapper = 0; - if (local_tmap) return 0; + if (local_tmap) + return 0; if (!use_wrapper && SwigType_isclass(t)) { SwigType *ftd = SwigType_typedef_resolve_all(t); SwigType *td = SwigType_strip_qualifiers(ftd); Delete(ftd); - if ((n = Swig_symbol_clookup(td,0))) { - if (GetFlag(n,"feature:valuewrapper")) { + if ((n = Swig_symbol_clookup(td, 0))) { + if (GetFlag(n, "feature:valuewrapper")) { use_wrapper = 1; } else { - if (HashCheckAttr(n,k_nodetype,k_class) - && (!Getattr(n,"allocate:default_constructor") - || (Getattr(n,"allocate:noassign")))) { - use_wrapper = !GetFlag(n,"feature:novaluewrapper") || GetFlag(n,"feature:nodefault"); + if (HashCheckAttr(n, k_nodetype, k_class) + && (!Getattr(n, "allocate:default_constructor") + || (Getattr(n, "allocate:noassign")))) { + use_wrapper = !GetFlag(n, "feature:novaluewrapper") || GetFlag(n, "feature:nodefault"); } } } else { if (SwigType_issimple(td) && SwigType_istemplate(td)) { - use_wrapper = !n || !GetFlag(n,"feature:novaluewrapper"); + use_wrapper = !n || !GetFlag(n, "feature:novaluewrapper"); } } if (use_wrapper) { - String *str = SwigType_str(td,0); - w = NewStringf("SwigValueWrapper<%s >",str); + String *str = SwigType_str(td, 0); + w = NewStringf("SwigValueWrapper<%s >", str); Delete(str); } - + Delete(td); } return w; @@ -1298,23 +1341,23 @@ SwigType *SwigType_alttype(SwigType *t, int local_tmap) { SwigType *ftd = SwigType_typedef_resolve_all(t); SwigType *td = SwigType_strip_qualifiers(ftd); if (SwigType_type(td) == T_USER) { - if ((n = Swig_symbol_clookup(td,0))) { - if ((HashCheckAttr(n,k_nodetype,k_class) - && !Getattr(n,"allocate:noassign") - && (Getattr(n,"allocate:default_constructor"))) - || (GetFlag(n,"feature:novaluewrapper"))) { - use_wrapper = GetFlag(n,"feature:valuewrapper"); + if ((n = Swig_symbol_clookup(td, 0))) { + if ((HashCheckAttr(n, k_nodetype, k_class) + && !Getattr(n, "allocate:noassign") + && (Getattr(n, "allocate:default_constructor"))) + || (GetFlag(n, "feature:novaluewrapper"))) { + use_wrapper = GetFlag(n, "feature:valuewrapper"); } } } else { use_wrapper = 0; - } + } if (use_wrapper) { - w = NewStringf("SwigValueWrapper<%s >",td); + w = NewStringf("SwigValueWrapper<%s >", td); } Delete(ftd); Delete(td); - return w; + return w; } } @@ -1365,14 +1408,14 @@ SwigType *SwigType_alttype(SwigType *t, int local_tmap) { * compute the transitive closure. * ----------------------------------------------------------------------------- */ -static Hash *r_mangled = 0; /* Hash mapping mangled types to fully resolved types */ -static Hash *r_resolved = 0; /* Hash mapping resolved types to mangled types */ -static Hash *r_ltype = 0; /* Hash mapping mangled names to their local c type */ -static Hash *r_clientdata = 0; /* Hash mapping resolved types to client data */ -static Hash *r_mangleddata = 0; /* Hash mapping mangled types to client data */ -static Hash *r_remembered = 0; /* Hash of types we remembered already */ +static Hash *r_mangled = 0; /* Hash mapping mangled types to fully resolved types */ +static Hash *r_resolved = 0; /* Hash mapping resolved types to mangled types */ +static Hash *r_ltype = 0; /* Hash mapping mangled names to their local c type */ +static Hash *r_clientdata = 0; /* Hash mapping resolved types to client data */ +static Hash *r_mangleddata = 0; /* Hash mapping mangled types to client data */ +static Hash *r_remembered = 0; /* Hash of types we remembered already */ -static void (*r_tracefunc)(SwigType *t, String *mangled, String *clientdata) = 0; +static void (*r_tracefunc) (SwigType *t, String *mangled, String *clientdata) = 0; void SwigType_remember_mangleddata(String *mangled, const String_or_char *clientdata) { if (!r_mangleddata) { @@ -1385,11 +1428,11 @@ void SwigType_remember_mangleddata(String *mangled, const String_or_char *client void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) { String *mt; SwigType *lt; - Hash *h; + Hash *h; SwigType *fr; SwigType *qr; - String *tkey; - String *cd; + String *tkey; + String *cd; if (!r_mangled) { r_mangled = NewHash(); @@ -1401,8 +1444,9 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) { String *last; - last = Getattr(r_remembered,t); - if (last && (Cmp(last,clientdata) == 0)) return; + last = Getattr(r_remembered, t); + if (last && (Cmp(last, clientdata) == 0)) + return; } tkey = Copy(t); @@ -1411,10 +1455,10 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) Delete(tkey); Delete(cd); - mt = SwigType_manglestr(t); /* Create mangled string */ + mt = SwigType_manglestr(t); /* Create mangled string */ if (r_tracefunc) { - (*r_tracefunc)(t,mt, (String *) clientdata); + (*r_tracefunc) (t, mt, (String *) clientdata); } if (SwigType_istypedef(t)) { @@ -1424,7 +1468,7 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) } Setattr(r_ltype, mt, lt); Delete(lt); - fr = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ + fr = SwigType_typedef_resolve_all(t); /* Create fully resolved type */ qr = SwigType_typedef_qualified(fr); Delete(fr); @@ -1433,40 +1477,40 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) Delete(qr); /*Printf(stdout,"t = '%s'\n", t); - Printf(stdout,"fr= '%s'\n\n", fr); */ - + Printf(stdout,"fr= '%s'\n\n", fr); */ + if (t) { char *ct = Char(t); - if (strchr(ct,'<') && !(strstr(ct,"<("))) { - Printf(stdout,"Bad template type passed to SwigType_remember: %s\n", t); + if (strchr(ct, '<') && !(strstr(ct, "<("))) { + Printf(stdout, "Bad template type passed to SwigType_remember: %s\n", t); assert(0); } } - h = Getattr(r_mangled,mt); + h = Getattr(r_mangled, mt); if (!h) { h = NewHash(); - Setattr(r_mangled,mt,h); + Setattr(r_mangled, mt, h); Delete(h); } - Setattr(h,fr,mt); + Setattr(h, fr, mt); h = Getattr(r_resolved, fr); if (!h) { h = NewHash(); - Setattr(r_resolved,fr,h); + Setattr(r_resolved, fr, h); Delete(h); } - Setattr(h,mt,fr); + Setattr(h, mt, fr); if (clientdata) { - String *cd = Getattr(r_clientdata,fr); + String *cd = Getattr(r_clientdata, fr); if (cd) { - if (Strcmp(clientdata,cd) != 0) { - Printf(stderr,"*** Internal error. Inconsistent clientdata for type '%s'\n", SwigType_str(fr,0)); - Printf(stderr,"*** '%s' != '%s'\n", clientdata, cd); + if (Strcmp(clientdata, cd) != 0) { + Printf(stderr, "*** Internal error. Inconsistent clientdata for type '%s'\n", SwigType_str(fr, 0)); + Printf(stderr, "*** '%s' != '%s'\n", clientdata, cd); assert(0); - } + } } else { String *cstr = NewString(clientdata); Setattr(r_clientdata, fr, cstr); @@ -1482,17 +1526,16 @@ void SwigType_remember_clientdata(SwigType *t, const String_or_char *clientdata) SwigType *tt = Copy(t); SwigType_del_reference(tt); SwigType_add_pointer(tt); - SwigType_remember_clientdata(tt,clientdata); + SwigType_remember_clientdata(tt, clientdata); } } -void -SwigType_remember(SwigType *ty) { - SwigType_remember_clientdata(ty,0); +void SwigType_remember(SwigType *ty) { + SwigType_remember_clientdata(ty, 0); } -void (*SwigType_remember_trace(void (*tf)(SwigType *, String *, String *)))(SwigType *, String *, String *) { - void (*o)(SwigType *, String *, String *) = r_tracefunc; +void (*SwigType_remember_trace(void (*tf) (SwigType *, String *, String *))) (SwigType *, String *, String *) { + void (*o) (SwigType *, String *, String *) = r_tracefunc; r_tracefunc = tf; return o; } @@ -1522,34 +1565,35 @@ List *SwigType_equivalent_mangle(String *ms, Hash *checked, Hash *found) { } else { ch = NewHash(); } - if (Getattr(ch,ms)) goto check_exit; /* Already checked this type */ - Setattr(h,ms,"1"); + if (Getattr(ch, ms)) + goto check_exit; /* Already checked this type */ + Setattr(h, ms, "1"); Setattr(ch, ms, "1"); - mh = Getattr(r_mangled,ms); + mh = Getattr(r_mangled, ms); if (mh) { Iterator ki; ki = First(mh); while (ki.key) { Hash *rh; - if (Getattr(ch,ki.key)) { + if (Getattr(ch, ki.key)) { ki = Next(ki); continue; } - Setattr(ch,ki.key,"1"); - rh = Getattr(r_resolved,ki.key); + Setattr(ch, ki.key, "1"); + rh = Getattr(r_resolved, ki.key); if (rh) { Iterator rk; rk = First(rh); while (rk.key) { - Setattr(h,rk.key,"1"); - SwigType_equivalent_mangle(rk.key,ch,h); + Setattr(h, rk.key, "1"); + SwigType_equivalent_mangle(rk.key, ch, h); rk = Next(rk); } } ki = Next(ki); } } - check_exit: +check_exit: if (!found) { l = Keys(h); Delete(h); @@ -1572,17 +1616,19 @@ String *SwigType_clientdata_collect(String *ms) { String *clientdata = 0; if (r_mangleddata) { - clientdata = Getattr(r_mangleddata,ms); - if (clientdata) return clientdata; + clientdata = Getattr(r_mangleddata, ms); + if (clientdata) + return clientdata; } - mh = Getattr(r_mangled,ms); + mh = Getattr(r_mangled, ms); if (mh) { Iterator ki; ki = First(mh); while (ki.key) { - clientdata = Getattr(r_clientdata,ki.key); - if (clientdata) break; + clientdata = Getattr(r_clientdata, ki.key); + if (clientdata) + break; ki = Next(ki); } } @@ -1602,16 +1648,16 @@ String *SwigType_clientdata_collect(String *ms) { * subclass is a hash that maps base-classes to all of the classes derived from them. * ----------------------------------------------------------------------------- */ -static Hash *subclass = 0; -static Hash *conversions = 0; +static Hash *subclass = 0; +static Hash *conversions = 0; -void -SwigType_inherit(String *derived, String *base, String *cast) { +void SwigType_inherit(String *derived, String *base, String *cast) { Hash *h; String *dd = 0; String *bb = 0; - if (!subclass) subclass = NewHash(); - + if (!subclass) + subclass = NewHash(); + /* Printf(stdout,"'%s' --> '%s' '%s'\n", derived, base, cast); */ if (SwigType_istemplate(derived)) { @@ -1627,16 +1673,16 @@ SwigType_inherit(String *derived, String *base, String *cast) { Delete(ty); } - /* Printf(stdout,"'%s' --> '%s' '%s'\n", derived, base, cast);*/ + /* Printf(stdout,"'%s' --> '%s' '%s'\n", derived, base, cast); */ - h = Getattr(subclass,base); + h = Getattr(subclass, base); if (!h) { h = NewHash(); - Setattr(subclass,base,h); + Setattr(subclass, base, h); Delete(h); } - if (!Getattr(h,derived)) { - Setattr(h,derived, cast ? cast : (void *) ""); + if (!Getattr(h, derived)) { + Setattr(h, derived, cast ? cast : (void *) ""); } Delete(dd); @@ -1649,23 +1695,23 @@ SwigType_inherit(String *derived, String *base, String *cast) { * Determines if a t1 is a subtype of t2, ie, is t1 derived from t2 * ----------------------------------------------------------------------------- */ -int -SwigType_issubtype(SwigType *t1, SwigType *t2) { +int SwigType_issubtype(SwigType *t1, SwigType *t2) { SwigType *ft1, *ft2; - String *b1, *b2; - Hash *h; - int r = 0; + String *b1, *b2; + Hash *h; + int r = 0; - if (!subclass) return 0; + if (!subclass) + return 0; ft1 = SwigType_typedef_resolve_all(t1); ft2 = SwigType_typedef_resolve_all(t2); b1 = SwigType_base(ft1); b2 = SwigType_base(ft2); - - h = Getattr(subclass,b2); + + h = Getattr(subclass, b2); if (h) { - if (Getattr(h,b1)) { + if (Getattr(h, b1)) { r = 1; } } @@ -1687,20 +1733,22 @@ void SwigType_inherit_equiv(File *out) { String *ckey; String *prefix, *base; String *mprefix, *mkey; - Hash *sub; - Hash *rh; - List *rlist; + Hash *sub; + Hash *rh; + List *rlist; Iterator rk, bk, ck; - if (!conversions) conversions = NewHash(); - if (!subclass) subclass = NewHash(); + if (!conversions) + conversions = NewHash(); + if (!subclass) + subclass = NewHash(); rk = First(r_resolved); while (rk.key) { /* rkey is a fully qualified type. We strip all of the type constructors off of it just to get the base */ base = SwigType_base(rk.key); /* Check to see whether the base is recorded in the subclass table */ - sub = Getattr(subclass,base); + sub = Getattr(subclass, base); Delete(base); if (!sub) { rk = Next(rk); @@ -1712,29 +1760,29 @@ void SwigType_inherit_equiv(File *out) { rh = Getattr(r_resolved, rk.key); rlist = NewList(); for (ck = First(rh); ck.key; ck = Next(ck)) { - Append(rlist,ck.key); + Append(rlist, ck.key); } /* Printf(stdout,"rk.key = '%s'\n", rk.key); - Printf(stdout,"rh = %x '%s'\n", rh,rh); */ + Printf(stdout,"rh = %x '%s'\n", rh,rh); */ bk = First(sub); while (bk.key) { - prefix= SwigType_prefix(rk.key); - Append(prefix,bk.key); + prefix = SwigType_prefix(rk.key); + Append(prefix, bk.key); /* Printf(stdout,"set %x = '%s' : '%s'\n", rh, SwigType_manglestr(prefix),prefix); */ mprefix = SwigType_manglestr(prefix); - Setattr(rh,mprefix,prefix); + Setattr(rh, mprefix, prefix); mkey = SwigType_manglestr(rk.key); - ckey = NewStringf("%s+%s",mprefix, mkey); - if (!Getattr(conversions,ckey)) { + ckey = NewStringf("%s+%s", mprefix, mkey); + if (!Getattr(conversions, ckey)) { String *convname = NewStringf("%sTo%s", mprefix, mkey); - String *lkey = SwigType_lstr(rk.key,0); - String *lprefix = SwigType_lstr(prefix,0); - Printf(out,"static void *%s(void *x) {\n", convname); - Printf(out," return (void *)((%s) %s ((%s) x));\n", lkey, Getattr(sub,bk.key), lprefix); - Printf(out,"}\n"); - Setattr(conversions,ckey,convname); - Delete(ckey); + String *lkey = SwigType_lstr(rk.key, 0); + String *lprefix = SwigType_lstr(prefix, 0); + Printf(out, "static void *%s(void *x) {\n", convname); + Printf(out, " return (void *)((%s) %s ((%s) x));\n", lkey, Getattr(sub, bk.key), lprefix); + Printf(out, "}\n"); + Setattr(conversions, ckey, convname); + Delete(ckey); Delete(lkey); Delete(lprefix); @@ -1743,13 +1791,13 @@ void SwigType_inherit_equiv(File *out) { Hash *r = Getattr(r_resolved, prefix); if (r) { Iterator rrk; - rrk=First(r); + rrk = First(r); while (rrk.key) { Iterator rlk; String *rkeymangle; /* Make sure this name equivalence is not due to inheritance */ - if (Cmp(prefix, Getattr(r,rrk.key)) == 0) { + if (Cmp(prefix, Getattr(r, rrk.key)) == 0) { rkeymangle = Copy(mkey); ckey = NewStringf("%s+%s", rrk.key, rkeymangle); if (!Getattr(conversions, ckey)) { @@ -1763,8 +1811,8 @@ void SwigType_inherit_equiv(File *out) { } Delete(rkeymangle); /* This is needed to pick up other alternative names for the same type. - Needed to make templates work */ - Setattr(rh,rrk.key,rrk.item); + Needed to make templates work */ + Setattr(rh, rrk.key, rrk.item); } rrk = Next(rrk); } @@ -1784,7 +1832,7 @@ void SwigType_inherit_equiv(File *out) { /* Helper function to sort the mangled list */ static int SwigType_compare_mangled(const DOH *a, const DOH *b) { - return strcmp((char *)Data(a), (char *)Data(b)); + return strcmp((char *) Data(a), (char *) Data(b)); } /* ----------------------------------------------------------------------------- @@ -1798,7 +1846,7 @@ List *SwigType_get_sorted_mangled_list() { SortList(l, SwigType_compare_mangled); return l; } - + /* ----------------------------------------------------------------------------- * SwigType_type_table() @@ -1806,8 +1854,7 @@ List *SwigType_get_sorted_mangled_list() { * Generate the type-table for the type-checker. * ----------------------------------------------------------------------------- */ -void -SwigType_emit_type_table(File *f_forward, File *f_table) { +void SwigType_emit_type_table(File *f_forward, File *f_table) { Iterator ki; String *types, *table, *cast, *cast_init, *cast_temp; Hash *imported_types; @@ -1820,29 +1867,29 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { r_resolved = NewHash(); } - Printf(f_table,"\n/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */\n\n"); + Printf(f_table, "\n/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */\n\n"); SwigType_inherit_equiv(f_table); /* #define DEBUG 1 */ #ifdef DEBUG - Printf(stdout,"---r_mangled---\n"); - Printf(stdout,"%s\n", r_mangled); - - Printf(stdout,"---r_resolved---\n"); - Printf(stdout,"%s\n", r_resolved); + Printf(stdout, "---r_mangled---\n"); + Printf(stdout, "%s\n", r_mangled); - Printf(stdout,"---r_ltype---\n"); - Printf(stdout,"%s\n", r_ltype); + Printf(stdout, "---r_resolved---\n"); + Printf(stdout, "%s\n", r_resolved); - Printf(stdout,"---subclass---\n"); - Printf(stdout,"%s\n", subclass); + Printf(stdout, "---r_ltype---\n"); + Printf(stdout, "%s\n", r_ltype); - Printf(stdout,"---conversions---\n"); - Printf(stdout,"%s\n", conversions); + Printf(stdout, "---subclass---\n"); + Printf(stdout, "%s\n", subclass); - Printf(stdout,"---r_clientdata---\n"); - Printf(stdout,"%s\n", r_clientdata); + Printf(stdout, "---conversions---\n"); + Printf(stdout, "%s\n", conversions); + + Printf(stdout, "---r_clientdata---\n"); + Printf(stdout, "%s\n", r_clientdata); #endif table = NewStringEmpty(); @@ -1850,12 +1897,12 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { cast = NewStringEmpty(); cast_init = NewStringEmpty(); imported_types = NewHash(); - - Printf(table,"static swig_type_info *swig_type_initial[] = {\n"); + + Printf(table, "static swig_type_info *swig_type_initial[] = {\n"); Printf(cast_init, "static swig_cast_info *swig_cast_initial[] = {\n"); - - Printf(f_forward,"\n/* -------- TYPES TABLE (BEGIN) -------- */\n\n"); - + + Printf(f_forward, "\n/* -------- TYPES TABLE (BEGIN) -------- */\n\n"); + mangled_list = SwigType_get_sorted_mangled_list(); for (ki = First(mangled_list); ki.item; ki = Next(ki)) { List *el; @@ -1868,63 +1915,63 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { const String *cd; cast_temp = NewStringEmpty(); - - Printv(types,"static swig_type_info _swigt_", ki.item, " = {", NIL); + + Printv(types, "static swig_type_info _swigt_", ki.item, " = {", NIL); Append(table_list, ki.item); Printf(cast_temp, "static swig_cast_info _swigc_%s[] = {", ki.item); i++; - - cd = SwigType_clientdata_collect(ki.item); - if (!cd) cd = "0"; - lt = Getattr(r_ltype,ki.item); + cd = SwigType_clientdata_collect(ki.item); + if (!cd) + cd = "0"; + + lt = Getattr(r_ltype, ki.item); rt = SwigType_typedef_resolve_all(lt); /* we save the original type and the fully resolved version */ - ln = SwigType_lstr(lt,0); - rn = SwigType_lstr(rt,0); - if (Equal(ln,rn)) { + ln = SwigType_lstr(lt, 0); + rn = SwigType_lstr(rt, 0); + if (Equal(ln, rn)) { nt = NewString(ln); } else { nt = NewStringf("%s|%s", rn, ln); } if (SwigType_istemplate(rt)) { String *dt = Swig_symbol_template_deftype(rt, 0); - String *dn = SwigType_lstr(dt,0); - if (!Equal(dn,rn) && !Equal(dn,ln)) { - Printf(nt,"|%s",dn); + String *dn = SwigType_lstr(dt, 0); + if (!Equal(dn, rn) && !Equal(dn, ln)) { + Printf(nt, "|%s", dn); } Delete(dt); Delete(dn); } - + Printf(types, "\"%s\", \"%s\", 0, 0, (void*)%s, 0};\n", ki.item, nt, cd); - el = SwigType_equivalent_mangle(ki.item,0,0); + el = SwigType_equivalent_mangle(ki.item, 0, 0); for (ei = First(el); ei.item; ei = Next(ei)) { String *ckey; String *conv; ckey = NewStringf("%s+%s", ei.item, ki.item); - conv = Getattr(conversions,ckey); + conv = Getattr(conversions, ckey); if (conv) { - Printf(cast_temp," {&_swigt_%s, %s, 0, 0},", ei.item, conv); + Printf(cast_temp, " {&_swigt_%s, %s, 0, 0},", ei.item, conv); } else { - Printf(cast_temp," {&_swigt_%s, 0, 0, 0},", ei.item); + Printf(cast_temp, " {&_swigt_%s, 0, 0, 0},", ei.item); } Delete(ckey); if (!Getattr(r_mangled, ei.item) && !Getattr(imported_types, ei.item)) { - Printf(types, "static swig_type_info _swigt_%s = {\"%s\", 0, 0, 0, 0, 0};\n", ei.item, ei.item); + Printf(types, "static swig_type_info _swigt_%s = {\"%s\", 0, 0, 0, 0, 0};\n", ei.item, ei.item); Append(table_list, ei.item); - - Printf(cast, "static swig_cast_info _swigc_%s[] = {{&_swigt_%s, 0, 0, 0},{0, 0, 0, 0}};\n", - ei.item, ei.item); - i++; - Setattr(imported_types, ei.item, "1"); + Printf(cast, "static swig_cast_info _swigc_%s[] = {{&_swigt_%s, 0, 0, 0},{0, 0, 0, 0}};\n", ei.item, ei.item); + i++; + + Setattr(imported_types, ei.item, "1"); } } Delete(el); - Printf(cast,"%s{0, 0, 0, 0}};\n", cast_temp); + Printf(cast, "%s{0, 0, 0, 0}};\n", cast_temp); Delete(cast_temp); Delete(nt); Delete(rt); @@ -1933,11 +1980,11 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { SortList(table_list, SwigType_compare_mangled); i = 0; for (ki = First(table_list); ki.item; ki = Next(ki)) { - Printf(f_forward,"#define SWIGTYPE%s swig_types[%d]\n", ki.item, i++); + Printf(f_forward, "#define SWIGTYPE%s swig_types[%d]\n", ki.item, i++); Printf(table, " &_swigt_%s,\n", ki.item); Printf(cast_init, " _swigc_%s,\n", ki.item); } - if (i==0) { + if (i == 0) { /* empty arrays are not allowed by ISO C */ Printf(table, " NULL\n"); Printf(cast_init, " NULL\n"); @@ -1949,17 +1996,17 @@ SwigType_emit_type_table(File *f_forward, File *f_table) { Printf(table, "};\n"); Printf(cast_init, "};\n"); - Printf(f_table,"%s\n", types); - Printf(f_table,"%s\n", table); - Printf(f_table,"%s\n", cast); - Printf(f_table,"%s\n", cast_init); - Printf(f_table,"\n/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */\n\n"); + Printf(f_table, "%s\n", types); + Printf(f_table, "%s\n", table); + Printf(f_table, "%s\n", cast); + Printf(f_table, "%s\n", cast_init); + Printf(f_table, "\n/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */\n\n"); - Printf(f_forward,"static swig_type_info *swig_types[%d];\n", i + 1); - Printf(f_forward,"static swig_module_info swig_module = {swig_types, %d, 0, 0, 0, 0};\n", i); - Printf(f_forward,"#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)\n"); - Printf(f_forward,"#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)\n"); - Printf(f_forward,"\n/* -------- TYPES TABLE (END) -------- */\n\n"); + Printf(f_forward, "static swig_type_info *swig_types[%d];\n", i + 1); + Printf(f_forward, "static swig_module_info swig_module = {swig_types, %d, 0, 0, 0, 0};\n", i); + Printf(f_forward, "#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)\n"); + Printf(f_forward, "#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)\n"); + Printf(f_forward, "\n/* -------- TYPES TABLE (END) -------- */\n\n"); Delete(types); Delete(table); diff --git a/SWIG/Source/Swig/warn.c b/SWIG/Source/Swig/warn.c index ccb4c4f80..d9bcfea71 100644 --- a/SWIG/Source/Swig/warn.c +++ b/SWIG/Source/Swig/warn.c @@ -20,21 +20,15 @@ static Hash *warnings = 0; * Issue a warning * ----------------------------------------------------------------------------- */ -void -Swig_warn(const char *filename, int line, const char *msg) { +void Swig_warn(const char *filename, int line, const char *msg) { String *key; if (!warnings) { warnings = NewHash(); } - key = NewStringf("%s:%d", filename,line); - if (!Getattr(warnings,key)) { - Printf(stderr,"swig-dev warning:%s:%d:%s\n", filename, line, msg); - Setattr(warnings,key,key); + key = NewStringf("%s:%d", filename, line); + if (!Getattr(warnings, key)) { + Printf(stderr, "swig-dev warning:%s:%d:%s\n", filename, line, msg); + Setattr(warnings, key, key); } Delete(key); } - - - - - diff --git a/SWIG/Source/Swig/wrapfunc.c b/SWIG/Source/Swig/wrapfunc.c index 6799e7f87..9b1edddb5 100644 --- a/SWIG/Source/Swig/wrapfunc.c +++ b/SWIG/Source/Swig/wrapfunc.c @@ -14,7 +14,7 @@ char cvsroot_wrapfunc_c[] = "$Header$"; #include "swig.h" #include -static int Compact_mode = 0; /* set to 0 on default */ +static int Compact_mode = 0; /* set to 0 on default */ static int Max_line_size = 128; /* ----------------------------------------------------------------------------- @@ -23,8 +23,7 @@ static int Max_line_size = 128; * Create a new wrapper function object. * ----------------------------------------------------------------------------- */ -Wrapper * -NewWrapper() { +Wrapper *NewWrapper() { Wrapper *w; w = (Wrapper *) malloc(sizeof(Wrapper)); w->localh = NewHash(); @@ -40,8 +39,7 @@ NewWrapper() { * Delete a wrapper function object. * ----------------------------------------------------------------------------- */ -void -DelWrapper(Wrapper *w) { +void DelWrapper(Wrapper *w) { Delete(w->localh); Delete(w->locals); Delete(w->code); @@ -55,8 +53,7 @@ DelWrapper(Wrapper *w) { * Set compact_mode. * ----------------------------------------------------------------------------- */ -void -Wrapper_compact_print_mode_set(int flag) { +void Wrapper_compact_print_mode_set(int flag) { Compact_mode = flag; } @@ -66,8 +63,7 @@ Wrapper_compact_print_mode_set(int flag) { * Formats a wrapper function and fixes up the indentation. * ----------------------------------------------------------------------------- */ -void -Wrapper_pretty_print(String *str, File *f) { +void Wrapper_pretty_print(String *str, File *f) { String *ts; int level = 0; int c, i; @@ -77,127 +73,132 @@ Wrapper_pretty_print(String *str, File *f) { int label = 0; ts = NewStringEmpty(); - Seek(str,0, SEEK_SET); + Seek(str, 0, SEEK_SET); while ((c = Getc(str)) != EOF) { if (c == '\"') { - Putc(c,ts); + Putc(c, ts); while ((c = Getc(str)) != EOF) { if (c == '\\') { - Putc(c,ts); + Putc(c, ts); c = Getc(str); } - Putc(c,ts); - if (c == '\"') break; + Putc(c, ts); + if (c == '\"') + break; } empty = 0; } else if (c == '\'') { - Putc(c,ts); + Putc(c, ts); while ((c = Getc(str)) != EOF) { if (c == '\\') { - Putc(c,ts); + Putc(c, ts); c = Getc(str); } - Putc(c,ts); - if (c == '\'') break; + Putc(c, ts); + if (c == '\'') + break; } empty = 0; } else if (c == ':') { - Putc(c,ts); + Putc(c, ts); if ((c = Getc(str)) == '\n') { - if (!empty && !strchr(Char(ts),'?')) label = 1; + if (!empty && !strchr(Char(ts), '?')) + label = 1; } - Ungetc(c,str); + Ungetc(c, str); } else if (c == '(') { - Putc(c,ts); - plevel+=indent; + Putc(c, ts); + plevel += indent; empty = 0; } else if (c == ')') { - Putc(c,ts); - plevel-=indent; + Putc(c, ts); + plevel -= indent; empty = 0; } else if (c == '{') { - Putc(c,ts); - Putc('\n',ts); - for (i = 0; i < level; i++) - Putc(' ',f); - Printf(f,"%s", ts); + Putc(c, ts); + Putc('\n', ts); + for (i = 0; i < level; i++) + Putc(' ', f); + Printf(f, "%s", ts); Clear(ts); - level+=indent; + level += indent; while ((c = Getc(str)) != EOF) { if (!isspace(c)) { - Ungetc(c,str); + Ungetc(c, str); break; } } empty = 0; } else if (c == '}') { if (!empty) { - Putc('\n',ts); + Putc('\n', ts); for (i = 0; i < level; i++) - Putc(' ',f); - Printf(f,"%s",ts); + Putc(' ', f); + Printf(f, "%s", ts); Clear(ts); } - level-=indent; - Putc(c,ts); + level -= indent; + Putc(c, ts); empty = 0; } else if (c == '\n') { - Putc(c,ts); + Putc(c, ts); empty = 0; if (!empty) { int slevel = level; - if (label && (slevel >= indent)) slevel -= indent; + if (label && (slevel >= indent)) + slevel -= indent; if ((Char(ts))[0] != '#') { for (i = 0; i < slevel; i++) - Putc(' ',f); + Putc(' ', f); } - Printf(f,"%s",ts); + Printf(f, "%s", ts); for (i = 0; i < plevel; i++) - Putc(' ',f); + Putc(' ', f); } Clear(ts); label = 0; empty = 1; } else if (c == '/') { empty = 0; - Putc(c,ts); + Putc(c, ts); c = Getc(str); if (c != EOF) { - Putc(c,ts); - if (c == '/') { /* C++ comment */ + Putc(c, ts); + if (c == '/') { /* C++ comment */ while ((c = Getc(str)) != EOF) { if (c == '\n') { - Ungetc(c,str); + Ungetc(c, str); break; } - Putc(c,ts); + Putc(c, ts); } - } else if (c == '*') { /* C comment */ - int endstar = 0; + } else if (c == '*') { /* C comment */ + int endstar = 0; while ((c = Getc(str)) != EOF) { - if (endstar && c == '/') { /* end of C comment */ - Putc(c,ts); + if (endstar && c == '/') { /* end of C comment */ + Putc(c, ts); break; } - endstar = (c == '*'); - Putc(c,ts); - if (c == '\n') { /* multi-line C comment. Could be improved slightly. */ - for (i = 0; i < level; i++) - Putc(' ',ts); - } + endstar = (c == '*'); + Putc(c, ts); + if (c == '\n') { /* multi-line C comment. Could be improved slightly. */ + for (i = 0; i < level; i++) + Putc(' ', ts); + } } - } + } } } else { if (!empty || !isspace(c)) { - Putc(c,ts); + Putc(c, ts); empty = 0; } } } - if (!empty) Printf(f,"%s",ts); + if (!empty) + Printf(f, "%s", ts); Delete(ts); - Printf(f,"\n"); + Printf(f, "\n"); } /* ----------------------------------------------------------------------------- @@ -207,9 +208,8 @@ Wrapper_pretty_print(String *str, File *f) { * Print out in compact format, with Compact enabled. * ----------------------------------------------------------------------------- */ -void -Wrapper_compact_print(String *str, File *f) { - String *ts, *tf; /*temp string & temp file */ +void Wrapper_compact_print(String *str, File *f) { + String *ts, *tf; /*temp string & temp file */ int level = 0; int c, i; int empty = 1; @@ -217,163 +217,165 @@ Wrapper_compact_print(String *str, File *f) { ts = NewStringEmpty(); tf = NewStringEmpty(); - Seek(str,0, SEEK_SET); + Seek(str, 0, SEEK_SET); while ((c = Getc(str)) != EOF) { - if (c == '\"') { /* string 1 */ + if (c == '\"') { /* string 1 */ empty = 0; - Putc(c,ts); + Putc(c, ts); while ((c = Getc(str)) != EOF) { if (c == '\\') { - Putc(c,ts); + Putc(c, ts); c = Getc(str); } - Putc(c,ts); - if (c == '\"') break; + Putc(c, ts); + if (c == '\"') + break; } - } else if (c == '\'') { /* string 2 */ + } else if (c == '\'') { /* string 2 */ empty = 0; - Putc(c,ts); + Putc(c, ts); while ((c = Getc(str)) != EOF) { if (c == '\\') { - Putc(c,ts); + Putc(c, ts); c = Getc(str); } - Putc(c,ts); - if (c == '\'') break; + Putc(c, ts); + if (c == '\'') + break; } - } else if (c == '{') { /* start of {...} */ + } else if (c == '{') { /* start of {...} */ empty = 0; - Putc(c,ts); + Putc(c, ts); if (Len(tf) == 0) { - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } else if ((Len(tf) + Len(ts)) < Max_line_size) { - Putc(' ',tf); + Putc(' ', tf); } else { - Putc('\n',tf); - Printf(f,"%s", tf); + Putc('\n', tf); + Printf(f, "%s", tf); Clear(tf); - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } - Append(tf,ts); + Append(tf, ts); Clear(ts); - level+=indent; + level += indent; while ((c = Getc(str)) != EOF) { if (!isspace(c)) { - Ungetc(c,str); + Ungetc(c, str); break; } } - } else if (c == '}') { /* end of {...} */ + } else if (c == '}') { /* end of {...} */ empty = 0; if (Len(tf) == 0) { - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } else if ((Len(tf) + Len(ts)) < Max_line_size) { - Putc(' ',tf); + Putc(' ', tf); } else { - Putc('\n',tf); - Printf(f,"%s", tf); + Putc('\n', tf); + Printf(f, "%s", tf); Clear(tf); - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } Append(tf, ts); Putc(c, tf); Clear(ts); - level-=indent; - } else if (c == '\n') { /* line end */ + level -= indent; + } else if (c == '\n') { /* line end */ while ((c = Getc(str)) != EOF) { if (!isspace(c)) break; } - if (c == '#'){ - Putc('\n',ts); + if (c == '#') { + Putc('\n', ts); } else if (c == '}') { - Putc(' ',ts); - } else if ( (c != EOF) || (Len(ts)!=0) ){ + Putc(' ', ts); + } else if ((c != EOF) || (Len(ts) != 0)) { if (Len(tf) == 0) { - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } else if ((Len(tf) + Len(ts)) < Max_line_size) { - Putc(' ',tf); + Putc(' ', tf); } else { - Putc('\n',tf); - Printf(f,"%s", tf); + Putc('\n', tf); + Printf(f, "%s", tf); Clear(tf); - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); } - Append(tf,ts); + Append(tf, ts); Clear(ts); } - Ungetc(c,str); + Ungetc(c, str); empty = 1; - } else if (c == '/') { /* comment */ + } else if (c == '/') { /* comment */ empty = 0; c = Getc(str); if (c != EOF) { - if (c == '/') { /* C++ comment */ + if (c == '/') { /* C++ comment */ while ((c = Getc(str)) != EOF) { if (c == '\n') { - Ungetc(c,str); + Ungetc(c, str); break; } } - } else if (c == '*') { /* C comment */ + } else if (c == '*') { /* C comment */ int endstar = 0; while ((c = Getc(str)) != EOF) { - if (endstar && c == '/') { /* end of C comment */ + if (endstar && c == '/') { /* end of C comment */ break; } - endstar = (c == '*'); + endstar = (c == '*'); } - } else { - Putc('/',ts); - Putc(c,ts); + } else { + Putc('/', ts); + Putc(c, ts); } } - } else if (c == '#') { /* Preprocessor line */ + } else if (c == '#') { /* Preprocessor line */ Putc('#', ts); while ((c = Getc(str)) != EOF) { Putc(c, ts); - if (c == '\\') { /* Continued line of the same PP */ + if (c == '\\') { /* Continued line of the same PP */ c = Getc(str); if (c == '\n') Putc(c, ts); else Ungetc(c, str); - } else if (c == '\n') + } else if (c == '\n') break; } if (!empty) { - Append(tf,"\n"); + Append(tf, "\n"); } - Append(tf,ts); + Append(tf, ts); Printf(f, "%s", tf); Clear(tf); Clear(ts); - for (i = 0; i < level; i++) - Putc(' ',tf); + for (i = 0; i < level; i++) + Putc(' ', tf); empty = 1; } else { if (!empty || !isspace(c)) { - Putc(c,ts); + Putc(c, ts); empty = 0; } } } if (!empty) { - Append(tf,ts); + Append(tf, ts); } if (Len(tf) != 0) - Printf(f,"%s",tf); + Printf(f, "%s", tf); Delete(ts); Delete(tf); - Printf(f,"\n"); + Printf(f, "\n"); } /* ----------------------------------------------------------------------------- @@ -382,18 +384,17 @@ Wrapper_compact_print(String *str, File *f) { * Print out a wrapper function. Does pretty or compact printing as well. * ----------------------------------------------------------------------------- */ -void -Wrapper_print(Wrapper *w, File *f) { +void Wrapper_print(Wrapper *w, File *f) { String *str; str = NewStringEmpty(); - Printf(str,"%s\n", w->def); - Printf(str,"%s\n", w->locals); - Printf(str,"%s\n", w->code); + Printf(str, "%s\n", w->def); + Printf(str, "%s\n", w->locals); + Printf(str, "%s\n", w->code); if (Compact_mode == 1) - Wrapper_compact_print(str,f); + Wrapper_compact_print(str, f); else - Wrapper_pretty_print(str,f); + Wrapper_pretty_print(str, f); Delete(str); } @@ -405,14 +406,13 @@ Wrapper_print(Wrapper *w, File *f) { * present (which may or may not be okay to the caller). * ----------------------------------------------------------------------------- */ -int -Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { +int Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { /* See if the local has already been declared */ - if (Getattr(w->localh,name)) { + if (Getattr(w->localh, name)) { return -1; } - Setattr(w->localh,name,decl); - Printf(w->locals,"%s;\n", decl); + Setattr(w->localh, name, decl); + Printf(w->locals, "%s;\n", decl); return 0; } @@ -424,24 +424,23 @@ Wrapper_add_local(Wrapper *w, const String_or_char *name, const String_or_char * * to manually construct the 'decl' string before calling. * ----------------------------------------------------------------------------- */ -int -Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { +int Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { va_list ap; - int ret; + int ret; String *decl; - DOH *obj; + DOH *obj; decl = NewStringEmpty(); - va_start(ap,name); + va_start(ap, name); - obj = va_arg(ap,void *); + obj = va_arg(ap, void *); while (obj) { - Append(decl,obj); + Append(decl, obj); Putc(' ', decl); obj = va_arg(ap, void *); } va_end(ap); - ret = Wrapper_add_local(w,name,decl); + ret = Wrapper_add_local(w, name, decl); Delete(decl); return ret; } @@ -452,9 +451,8 @@ Wrapper_add_localv(Wrapper *w, const String_or_char *name, ...) { * Check to see if a local name has already been declared * ----------------------------------------------------------------------------- */ -int -Wrapper_check_local(Wrapper *w, const String_or_char *name) { - if (Getattr(w->localh,name)) { +int Wrapper_check_local(Wrapper *w, const String_or_char *name) { + if (Getattr(w->localh, name)) { return 1; } return 0; @@ -467,27 +465,26 @@ Wrapper_check_local(Wrapper *w, const String_or_char *name) { * used. Returns the name that was actually selected. * ----------------------------------------------------------------------------- */ -char * -Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { +char *Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char *decl) { int i; String *nname = NewString(name); String *ndecl = NewString(decl); - char *ret; + char *ret; i = 0; - while (Wrapper_check_local(w,nname)) { + while (Wrapper_check_local(w, nname)) { Clear(nname); - Printf(nname,"%s%d",name,i); + Printf(nname, "%s%d", name, i); i++; } Replace(ndecl, name, nname, DOH_REPLACE_ID); - Setattr(w->localh,nname,ndecl); - Printf(w->locals,"%s;\n", ndecl); + Setattr(w->localh, nname, ndecl); + Printf(w->locals, "%s;\n", ndecl); ret = Char(nname); Delete(nname); Delete(ndecl); - return ret; /* Note: nname should still exists in the w->localh hash */ + return ret; /* Note: nname should still exists in the w->localh hash */ } @@ -499,30 +496,23 @@ Wrapper_new_local(Wrapper *w, const String_or_char *name, const String_or_char * * to manually construct the 'decl' string before calling. * ----------------------------------------------------------------------------- */ -char * -Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) { +char *Wrapper_new_localv(Wrapper *w, const String_or_char *name, ...) { va_list ap; char *ret; String *decl; - DOH *obj; + DOH *obj; decl = NewStringEmpty(); - va_start(ap,name); + va_start(ap, name); - obj = va_arg(ap,void *); + obj = va_arg(ap, void *); while (obj) { - Append(decl,obj); - Putc(' ',decl); + Append(decl, obj); + Putc(' ', decl); obj = va_arg(ap, void *); } va_end(ap); - ret = Wrapper_new_local(w,name,decl); + ret = Wrapper_new_local(w, name, decl); Delete(decl); return ret; } - - - - - -